You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Dialog.h 5.5KB

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