Constantin Kaplinsky | 729598c | 2006-05-25 05:12:25 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 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 | #include <windows.h> |
| 28 | #include <prsht.h> |
| 29 | #include <list> |
| 30 | #include <rfb_win32/TCharArray.h> |
| 31 | |
| 32 | namespace rfb { |
| 33 | |
| 34 | namespace win32 { |
| 35 | |
| 36 | // Dialog - A simple Win32 Dialog box. A derived class of Dialog overrides the |
| 37 | // initDialog(), command() and ok() methods to take appropriate action. A |
| 38 | // simple dialog box can be displayed by creating a Dialog object and calling |
| 39 | // show(). |
| 40 | |
| 41 | class Dialog { |
| 42 | public: |
| 43 | |
| 44 | Dialog(HINSTANCE inst); |
| 45 | virtual ~Dialog(); |
| 46 | |
| 47 | // showDialog() displays the dialog box. It returns when it has been dismissed, |
| 48 | // returning true if "OK" was pressed, false otherwise. The resource |
| 49 | // argument identifies the dialog resource (often a MAKEINTRESOURCE macro |
| 50 | // expansion), and owner is an optional window handle - the corresponding |
| 51 | // window is disabled while the dialog box is displayed. |
| 52 | |
| 53 | bool showDialog(const TCHAR* resource, HWND owner=0); |
| 54 | |
| 55 | // initDialog() is called upon receipt of the WM_INITDIALOG message. |
| 56 | |
| 57 | virtual void initDialog() {} |
| 58 | |
| 59 | // onCommand() is called upon receipt of a WM_COMMAND message item other than IDOK |
| 60 | // or IDCANCEL. It should return true if the command has been handled. |
| 61 | |
| 62 | virtual bool onCommand(int item, int cmd) { return false; } |
| 63 | |
| 64 | // onHelp() is called upon receipt of a WM_MENU message. This indicates that |
| 65 | // context-specific help should be displayed, for a dialog control, for example. |
| 66 | // It should return true if the command has been handled. |
| 67 | |
| 68 | virtual bool onHelp(int item) { return false; } |
| 69 | |
| 70 | // onOk() is called when the OK button is pressed. The hwnd argument is the |
| 71 | // dialog box's window handle. |
| 72 | |
| 73 | virtual bool onOk() { return true; } |
| 74 | |
| 75 | // Read the states of items |
| 76 | bool isItemChecked(int id); |
| 77 | int getItemInt(int id); |
| 78 | TCHAR* getItemString(int id); // Recipient owns string storage |
| 79 | |
| 80 | // Set the states of items |
| 81 | void setItemChecked(int id, bool state); |
| 82 | void setItemInt(int id, int value); |
| 83 | void setItemString(int id, const TCHAR* s); |
| 84 | |
| 85 | // enableItem is used to grey out an item, making it inaccessible, or to |
| 86 | // re-enable it. |
| 87 | void enableItem(int id, bool state); |
| 88 | |
| 89 | protected: |
| 90 | static BOOL CALLBACK staticDialogProc(HWND hwnd, UINT msg, |
| 91 | WPARAM wParam, LPARAM lParam); |
| 92 | virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
| 93 | HINSTANCE inst; |
| 94 | HWND handle; |
| 95 | bool alreadyShowing; |
| 96 | }; |
| 97 | |
| 98 | // PropertySheetPage |
| 99 | // Class used to define property pages within a PropertySheet. |
| 100 | // Each page is associated with a particular dialog resource, indicated by |
| 101 | // the "id" parameter supplied to the constructor. |
| 102 | |
| 103 | class PropSheetPage; |
| 104 | |
| 105 | class PropSheet { |
| 106 | public: |
| 107 | PropSheet(HINSTANCE inst, const TCHAR* title, std::list<PropSheetPage*> pages, HICON icon=0); |
| 108 | virtual ~PropSheet(); |
| 109 | |
| 110 | // Display the PropertySheet |
| 111 | bool showPropSheet(HWND owner, bool showApply = false, bool showCtxtHelp = false, bool capture=false); |
| 112 | |
| 113 | // Calls initDialog again for each page that has already had it called. |
| 114 | // Note: If a page hasn't been seen yet, it won't have been called. |
| 115 | // Note: This must only be called while the property sheet is visible. |
| 116 | void reInitPages(); |
| 117 | |
| 118 | // Calls onOk for each page that has had initDialog called, and returns |
| 119 | // false if any one of them returns false, or true otherwise. ALL the |
| 120 | // onOk() methods will be called, even if one of them fails. |
| 121 | // Note: If a page hasn't been seen yet, it won't have been called. |
| 122 | // Note: This must only be called while the property sheet is visible. |
| 123 | bool commitPages(); |
| 124 | |
| 125 | friend class PropSheetPage; |
| 126 | |
| 127 | protected: |
| 128 | HWND owner; |
| 129 | HICON icon; |
| 130 | std::list<PropSheetPage*> pages; |
| 131 | HINSTANCE inst; |
| 132 | TCharArray title; |
| 133 | HWND handle; |
| 134 | bool alreadyShowing; |
| 135 | }; |
| 136 | |
| 137 | class PropSheetPage : public Dialog { |
| 138 | public: |
| 139 | PropSheetPage(HINSTANCE inst, const TCHAR* id); |
| 140 | virtual ~PropSheetPage(); |
| 141 | |
| 142 | void setChanged(bool changed); |
| 143 | |
| 144 | friend class PropSheet; |
| 145 | |
| 146 | protected: |
| 147 | void setPropSheet(PropSheet* ps) {propSheet = ps;}; |
| 148 | static BOOL CALLBACK staticPageProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
| 149 | virtual BOOL dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); |
| 150 | PROPSHEETPAGE page; |
| 151 | PropSheet* propSheet; |
| 152 | }; |
| 153 | |
| 154 | }; |
| 155 | |
| 156 | }; |
| 157 | |
| 158 | #endif // __RFB_WIN32_DIALOG_H__ |