toplevel.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/toplevel.h
  3. // Purpose: wxTopLevelWindowMSW is the MSW implementation of wxTLW
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 20.09.01
  7. // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_TOPLEVEL_H_
  11. #define _WX_MSW_TOPLEVEL_H_
  12. // ----------------------------------------------------------------------------
  13. // wxTopLevelWindowMSW
  14. // ----------------------------------------------------------------------------
  15. class WXDLLIMPEXP_CORE wxTopLevelWindowMSW : public wxTopLevelWindowBase
  16. {
  17. public:
  18. // constructors and such
  19. wxTopLevelWindowMSW() { Init(); }
  20. wxTopLevelWindowMSW(wxWindow *parent,
  21. wxWindowID id,
  22. const wxString& title,
  23. const wxPoint& pos = wxDefaultPosition,
  24. const wxSize& size = wxDefaultSize,
  25. long style = wxDEFAULT_FRAME_STYLE,
  26. const wxString& name = wxFrameNameStr)
  27. {
  28. Init();
  29. (void)Create(parent, id, title, pos, size, style, name);
  30. }
  31. bool Create(wxWindow *parent,
  32. wxWindowID id,
  33. const wxString& title,
  34. const wxPoint& pos = wxDefaultPosition,
  35. const wxSize& size = wxDefaultSize,
  36. long style = wxDEFAULT_FRAME_STYLE,
  37. const wxString& name = wxFrameNameStr);
  38. virtual ~wxTopLevelWindowMSW();
  39. // implement base class pure virtuals
  40. virtual void SetTitle( const wxString& title);
  41. virtual wxString GetTitle() const;
  42. virtual void Maximize(bool maximize = true);
  43. virtual bool IsMaximized() const;
  44. virtual void Iconize(bool iconize = true);
  45. virtual bool IsIconized() const;
  46. virtual void SetIcons(const wxIconBundle& icons );
  47. virtual void Restore();
  48. virtual void SetLayoutDirection(wxLayoutDirection dir);
  49. virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO);
  50. virtual bool Show(bool show = true);
  51. virtual void Raise();
  52. virtual void ShowWithoutActivating();
  53. virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL);
  54. virtual bool IsFullScreen() const { return m_fsIsShowing; }
  55. // wxMSW only: EnableCloseButton(false) may be used to remove the "Close"
  56. // button from the title bar
  57. virtual bool EnableCloseButton(bool enable = true);
  58. // Set window transparency if the platform supports it
  59. virtual bool SetTransparent(wxByte alpha);
  60. virtual bool CanSetTransparent();
  61. // MSW-specific methods
  62. // --------------------
  63. // Return the menu representing the "system" menu of the window. You can
  64. // call wxMenu::AppendWhatever() methods on it but removing items from it
  65. // is in general not a good idea.
  66. //
  67. // The pointer returned by this method belongs to the window and will be
  68. // deleted when the window itself is, do not delete it yourself. May return
  69. // NULL if getting the system menu failed.
  70. wxMenu *MSWGetSystemMenu() const;
  71. // implementation from now on
  72. // --------------------------
  73. // event handlers
  74. void OnActivate(wxActivateEvent& event);
  75. // called by wxWindow whenever it gets focus
  76. void SetLastFocus(wxWindow *win) { m_winLastFocused = win; }
  77. wxWindow *GetLastFocus() const { return m_winLastFocused; }
  78. #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
  79. virtual void SetLeftMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL);
  80. virtual void SetRightMenu(int id = wxID_ANY, const wxString& label = wxEmptyString, wxMenu *subMenu = NULL);
  81. bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
  82. virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
  83. #endif // __SMARTPHONE__ && __WXWINCE__
  84. #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
  85. // Soft Input Panel (SIP) change notification
  86. virtual bool HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam);
  87. #endif
  88. // translate wxWidgets flags to Windows ones
  89. virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle) const;
  90. // choose the right parent to use with CreateWindow()
  91. virtual WXHWND MSWGetParent() const;
  92. // window proc for the frames
  93. WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
  94. // returns true if the platform should explicitly apply a theme border
  95. virtual bool CanApplyThemeBorder() const { return false; }
  96. #if wxUSE_MENUS
  97. bool HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu);
  98. // handle WM_EXITMENULOOP message for Win95 only
  99. bool HandleExitMenuLoop(WXWORD isPopup);
  100. // handle WM_(UN)INITMENUPOPUP message to generate wxEVT_MENU_OPEN/CLOSE
  101. bool HandleMenuPopup(wxEventType evtType, WXHMENU hMenu);
  102. // Command part of HandleMenuPopup() and HandleExitMenuLoop().
  103. bool DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup);
  104. // Find the menu corresponding to the given handle.
  105. virtual wxMenu* MSWFindMenuFromHMENU(WXHMENU hMenu);
  106. #endif // wxUSE_MENUS
  107. protected:
  108. // common part of all ctors
  109. void Init();
  110. // create a new frame, return false if it couldn't be created
  111. bool CreateFrame(const wxString& title,
  112. const wxPoint& pos,
  113. const wxSize& size);
  114. // create a new dialog using the given dialog template from resources,
  115. // return false if it couldn't be created
  116. bool CreateDialog(const void *dlgTemplate,
  117. const wxString& title,
  118. const wxPoint& pos,
  119. const wxSize& size);
  120. // common part of Iconize(), Maximize() and Restore()
  121. void DoShowWindow(int nShowCmd);
  122. // override those to return the normal window coordinates even when the
  123. // window is minimized
  124. #ifndef __WXWINCE__
  125. virtual void DoGetPosition(int *x, int *y) const;
  126. virtual void DoGetSize(int *width, int *height) const;
  127. #endif // __WXWINCE__
  128. // Top level windows have different freeze semantics on Windows
  129. virtual void DoFreeze();
  130. virtual void DoThaw();
  131. // helper of SetIcons(): calls gets the icon with the size specified by the
  132. // given system metrics (SM_C{X|Y}[SM]ICON) from the bundle and sets it
  133. // using WM_SETICON with the specified wParam (ICOM_SMALL or ICON_BIG);
  134. // returns true if the icon was set
  135. bool DoSelectAndSetIcon(const wxIconBundle& icons, int smX, int smY, int i);
  136. // override wxWindow virtual method to use CW_USEDEFAULT if necessary
  137. virtual void MSWGetCreateWindowCoords(const wxPoint& pos,
  138. const wxSize& size,
  139. int& x, int& y,
  140. int& w, int& h) const;
  141. // is the window currently iconized?
  142. bool m_iconized;
  143. // should the frame be maximized when it will be shown? set by Maximize()
  144. // when it is called while the frame is hidden
  145. bool m_maximizeOnShow;
  146. // Data to save/restore when calling ShowFullScreen
  147. long m_fsStyle; // Passed to ShowFullScreen
  148. wxRect m_fsOldSize;
  149. long m_fsOldWindowStyle;
  150. bool m_fsIsMaximized;
  151. bool m_fsIsShowing;
  152. // Save the current focus to m_winLastFocused if we're not iconized (the
  153. // focus is always NULL when we're iconized).
  154. void DoSaveLastFocus();
  155. // Restore focus to m_winLastFocused if possible and needed.
  156. void DoRestoreLastFocus();
  157. // The last focused child: we remember it when we're deactivated and
  158. // restore focus to it when we're activated (this is done here) or restored
  159. // from iconic state (done by wxFrame).
  160. wxWindow *m_winLastFocused;
  161. #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
  162. class ButtonMenu
  163. {
  164. public:
  165. ButtonMenu();
  166. ~ButtonMenu();
  167. void SetButton(int id = wxID_ANY,
  168. const wxString& label = wxEmptyString,
  169. wxMenu *subMenu = NULL);
  170. bool IsAssigned() const {return m_assigned;}
  171. bool IsMenu() const {return m_menu!=NULL;}
  172. int GetId() const {return m_id;}
  173. wxMenu* GetMenu() const {return m_menu;}
  174. wxString GetLabel() {return m_label;}
  175. static wxMenu *DuplicateMenu(wxMenu *menu);
  176. protected:
  177. int m_id;
  178. wxString m_label;
  179. wxMenu *m_menu;
  180. bool m_assigned;
  181. };
  182. ButtonMenu m_LeftButton;
  183. ButtonMenu m_RightButton;
  184. HWND m_MenuBarHWND;
  185. void ReloadButton(ButtonMenu& button, UINT menuID);
  186. void ReloadAllButtons();
  187. #endif // __SMARTPHONE__ && __WXWINCE__
  188. private:
  189. #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
  190. void* m_activateInfo;
  191. #endif
  192. // The system menu: initially NULL but can be set (once) by
  193. // MSWGetSystemMenu(). Owned by this window.
  194. wxMenu *m_menuSystem;
  195. // The number of currently opened menus: 0 initially, 1 when a top level
  196. // menu is opened, 2 when its submenu is opened and so on.
  197. int m_menuDepth;
  198. DECLARE_EVENT_TABLE()
  199. wxDECLARE_NO_COPY_CLASS(wxTopLevelWindowMSW);
  200. };
  201. #endif // _WX_MSW_TOPLEVEL_H_