blob: d46133a0efc0843071d604481db3be06c298a785 [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- RegConfig.h
20
21// Class which monitors the registry and reads in the registry settings
22// whenever they change, or are added or removed.
23
24#ifndef __RFB_WIN32_DIALOG_H__
25#define __RFB_WIN32_DIALOG_H__
26
27#define WIN32_LEAN_AND_MEAN
28#include <windows.h>
29#include <prsht.h>
30#include <list>
31#include <rfb_win32/TCharArray.h>
32
33namespace rfb {
34
35 namespace win32 {
36
37 // Dialog - A simple Win32 Dialog box. A derived class of Dialog overrides the
38 // initDialog(), command() and ok() methods to take appropriate action. A
39 // simple dialog box can be displayed by creating a Dialog object and calling
40 // show().
41
42 class Dialog {
43 public:
44
45 Dialog(HINSTANCE inst);
46 virtual ~Dialog();
47
48 // showDialog() displays the dialog box. It returns when it has been dismissed,
49 // returning true if "OK" was pressed, false otherwise. The resource
50 // argument identifies the dialog resource (often a MAKEINTRESOURCE macro
51 // expansion), and owner is an optional window handle - the corresponding
52 // window is disabled while the dialog box is displayed.
53
54 bool showDialog(const TCHAR* resource, HWND owner=0);
55
56 // initDialog() is called upon receipt of the WM_INITDIALOG message.
57
58 virtual void initDialog() {}
59
60 // onCommand() is called upon receipt of a WM_COMMAND message item other than IDOK
61 // or IDCANCEL. It should return true if the command has been handled.
62
63 virtual bool onCommand(int item, int cmd) { return false; }
64
65 // onHelp() is called upon receipt of a WM_MENU message. This indicates that
66 // context-specific help should be displayed, for a dialog control, for example.
67 // It should return true if the command has been handled.
68
69 virtual bool onHelp(int item) { return false; }
70
71 // onOk() is called when the OK button is pressed. The hwnd argument is the
72 // dialog box's window handle.
73
74 virtual bool onOk() { return true; }
75
76 // Read the states of items
77 bool isItemChecked(int id);
78 int getItemInt(int id);
79 TCHAR* getItemString(int id); // Recipient owns string storage
80
81 // Set the states of items
82 void setItemChecked(int id, bool state);
83 void setItemInt(int id, int value);
84 void setItemString(int id, const TCHAR* s);
85
86 // enableItem is used to grey out an item, making it inaccessible, or to
87 // re-enable it.
88 void enableItem(int id, bool state);
89
90 protected:
91 static BOOL CALLBACK staticDialogProc(HWND hwnd, UINT msg,
92 WPARAM wParam, LPARAM lParam);
93 virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
94 HINSTANCE inst;
95 HWND handle;
96 bool alreadyShowing;
97 };
98
99 // PropertySheetPage
100 // Class used to define property pages within a PropertySheet.
101 // Each page is associated with a particular dialog resource, indicated by
102 // the "id" parameter supplied to the constructor.
103
104 class PropSheetPage;
105
106 class PropSheet {
107 public:
108 PropSheet(HINSTANCE inst, const TCHAR* title, std::list<PropSheetPage*> pages, HICON icon=0);
109 virtual ~PropSheet();
110
111 // Display the PropertySheet
112 bool showPropSheet(HWND owner, bool showApply = false, bool showCtxtHelp = false, bool capture=false);
113
114 // Calls initDialog again for each page that has already had it called.
115 // Note: If a page hasn't been seen yet, it won't have been called.
116 // Note: This must only be called while the property sheet is visible.
117 void reInitPages();
118
119 // Calls onOk for each page that has had initDialog called, and returns
120 // false if any one of them returns false, or true otherwise. ALL the
121 // onOk() methods will be called, even if one of them fails.
122 // Note: If a page hasn't been seen yet, it won't have been called.
123 // Note: This must only be called while the property sheet is visible.
124 bool commitPages();
125
126 friend class PropSheetPage;
127
128 protected:
129 HWND owner;
130 HICON icon;
131 std::list<PropSheetPage*> pages;
132 HINSTANCE inst;
133 TCharArray title;
134 HWND handle;
135 bool alreadyShowing;
136 };
137
138 class PropSheetPage : public Dialog {
139 public:
140 PropSheetPage(HINSTANCE inst, const TCHAR* id);
141 virtual ~PropSheetPage();
142
143 void setChanged(bool changed);
144
145 friend class PropSheet;
146
147 protected:
148 void setPropSheet(PropSheet* ps) {propSheet = ps;};
149 static BOOL CALLBACK staticPageProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
150 virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
151 PROPSHEETPAGE page;
152 PropSheet* propSheet;
153 };
154
155 };
156
157};
158
159#endif // __RFB_WIN32_DIALOG_H__