window.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/window.h
  3. // Purpose: wxWindowMSW class
  4. // Author: Julian Smart
  5. // Modified by: Vadim Zeitlin on 13.05.99: complete refont of message handling,
  6. // elimination of Default(), ...
  7. // Created: 01/02/97
  8. // Copyright: (c) Julian Smart
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_WINDOW_H_
  12. #define _WX_WINDOW_H_
  13. #include "wx/settings.h" // solely for wxSystemColour
  14. // if this is set to 1, we use deferred window sizing to reduce flicker when
  15. // resizing complicated window hierarchies, but this can in theory result in
  16. // different behaviour than the old code so we keep the possibility to use it
  17. // by setting this to 0 (in the future this should be removed completely)
  18. #ifdef __WXWINCE__
  19. #define wxUSE_DEFERRED_SIZING 0
  20. #else
  21. #define wxUSE_DEFERRED_SIZING 1
  22. #endif
  23. // ---------------------------------------------------------------------------
  24. // wxWindow declaration for MSW
  25. // ---------------------------------------------------------------------------
  26. class WXDLLIMPEXP_CORE wxWindowMSW : public wxWindowBase
  27. {
  28. friend class wxSpinCtrl;
  29. friend class wxSlider;
  30. friend class wxRadioBox;
  31. #if defined __VISUALC__ && __VISUALC__ <= 1200
  32. friend class wxWindowMSW;
  33. #endif
  34. public:
  35. wxWindowMSW() { Init(); }
  36. wxWindowMSW(wxWindow *parent,
  37. wxWindowID id,
  38. const wxPoint& pos = wxDefaultPosition,
  39. const wxSize& size = wxDefaultSize,
  40. long style = 0,
  41. const wxString& name = wxPanelNameStr)
  42. {
  43. Init();
  44. Create(parent, id, pos, size, style, name);
  45. }
  46. virtual ~wxWindowMSW();
  47. bool Create(wxWindow *parent,
  48. wxWindowID id,
  49. const wxPoint& pos = wxDefaultPosition,
  50. const wxSize& size = wxDefaultSize,
  51. long style = 0,
  52. const wxString& name = wxPanelNameStr);
  53. // implement base class pure virtuals
  54. virtual void SetLabel(const wxString& label);
  55. virtual wxString GetLabel() const;
  56. virtual void Raise();
  57. virtual void Lower();
  58. virtual bool BeginRepositioningChildren();
  59. virtual void EndRepositioningChildren();
  60. virtual bool Show(bool show = true);
  61. virtual bool ShowWithEffect(wxShowEffect effect,
  62. unsigned timeout = 0)
  63. {
  64. return MSWShowWithEffect(true, effect, timeout);
  65. }
  66. virtual bool HideWithEffect(wxShowEffect effect,
  67. unsigned timeout = 0)
  68. {
  69. return MSWShowWithEffect(false, effect, timeout);
  70. }
  71. virtual void SetFocus();
  72. virtual void SetFocusFromKbd();
  73. virtual bool Reparent(wxWindowBase *newParent);
  74. virtual void WarpPointer(int x, int y);
  75. virtual void Refresh( bool eraseBackground = true,
  76. const wxRect *rect = (const wxRect *) NULL );
  77. virtual void Update();
  78. virtual void SetWindowStyleFlag(long style);
  79. virtual void SetExtraStyle(long exStyle);
  80. virtual bool SetCursor( const wxCursor &cursor );
  81. virtual bool SetFont( const wxFont &font );
  82. virtual int GetCharHeight() const;
  83. virtual int GetCharWidth() const;
  84. virtual void SetScrollbar( int orient, int pos, int thumbVisible,
  85. int range, bool refresh = true );
  86. virtual void SetScrollPos( int orient, int pos, bool refresh = true );
  87. virtual int GetScrollPos( int orient ) const;
  88. virtual int GetScrollThumb( int orient ) const;
  89. virtual int GetScrollRange( int orient ) const;
  90. virtual void ScrollWindow( int dx, int dy,
  91. const wxRect* rect = NULL );
  92. virtual bool ScrollLines(int lines);
  93. virtual bool ScrollPages(int pages);
  94. virtual void SetLayoutDirection(wxLayoutDirection dir);
  95. virtual wxLayoutDirection GetLayoutDirection() const;
  96. virtual wxCoord AdjustForLayoutDirection(wxCoord x,
  97. wxCoord width,
  98. wxCoord widthTotal) const;
  99. #if wxUSE_DRAG_AND_DROP
  100. virtual void SetDropTarget( wxDropTarget *dropTarget );
  101. #endif // wxUSE_DRAG_AND_DROP
  102. // Accept files for dragging
  103. virtual void DragAcceptFiles(bool accept);
  104. #ifndef __WXUNIVERSAL__
  105. // Native resource loading (implemented in src/msw/nativdlg.cpp)
  106. // FIXME: should they really be all virtual?
  107. virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
  108. virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
  109. wxWindow* GetWindowChild1(wxWindowID id);
  110. wxWindow* GetWindowChild(wxWindowID id);
  111. #endif // __WXUNIVERSAL__
  112. #if wxUSE_HOTKEY
  113. // install and deinstall a system wide hotkey
  114. virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
  115. virtual bool UnregisterHotKey(int hotkeyId);
  116. #endif // wxUSE_HOTKEY
  117. #ifdef __POCKETPC__
  118. bool IsContextMenuEnabled() const { return m_contextMenuEnabled; }
  119. void EnableContextMenu(bool enable = true) { m_contextMenuEnabled = enable; }
  120. #endif
  121. // window handle stuff
  122. // -------------------
  123. WXHWND GetHWND() const { return m_hWnd; }
  124. void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
  125. virtual WXWidget GetHandle() const { return GetHWND(); }
  126. void AssociateHandle(WXWidget handle);
  127. void DissociateHandle();
  128. // does this window have deferred position and/or size?
  129. bool IsSizeDeferred() const;
  130. // these functions allow to register a global handler for the given Windows
  131. // message: it will be called from MSWWindowProc() of any window which gets
  132. // this event if it's not processed before (i.e. unlike a hook procedure it
  133. // does not override the normal processing)
  134. //
  135. // notice that if you want to process a message for a given window only you
  136. // should override its MSWWindowProc() instead
  137. // type of the handler: it is called with the message parameters (except
  138. // that the window object is passed instead of window handle) and should
  139. // return true if it handled the message or false if it should be passed to
  140. // DefWindowProc()
  141. typedef bool (*MSWMessageHandler)(wxWindowMSW *win,
  142. WXUINT nMsg,
  143. WXWPARAM wParam,
  144. WXLPARAM lParam);
  145. // install a handler, shouldn't be called more than one for the same message
  146. static bool MSWRegisterMessageHandler(int msg, MSWMessageHandler handler);
  147. // unregister a previously registered handler
  148. static void MSWUnregisterMessageHandler(int msg, MSWMessageHandler handler);
  149. // implementation from now on
  150. // ==========================
  151. // event handlers
  152. // --------------
  153. void OnPaint(wxPaintEvent& event);
  154. #ifdef __WXWINCE__
  155. void OnInitDialog(wxInitDialogEvent& event);
  156. #endif
  157. public:
  158. // Windows subclassing
  159. void SubclassWin(WXHWND hWnd);
  160. void UnsubclassWin();
  161. WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
  162. void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
  163. // return true if the window is of a standard (i.e. not wxWidgets') class
  164. //
  165. // to understand why does it work, look at SubclassWin() code and comments
  166. bool IsOfStandardClass() const { return m_oldWndProc != NULL; }
  167. wxWindow *FindItem(long id, WXHWND hWnd = NULL) const;
  168. wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
  169. // MSW only: true if this control is part of the main control
  170. virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; }
  171. #if wxUSE_TOOLTIPS
  172. // MSW only: true if this window or any of its children have a tooltip
  173. virtual bool HasToolTips() const { return GetToolTip() != NULL; }
  174. #endif // wxUSE_TOOLTIPS
  175. // translate wxWidgets style flags for this control into the Windows style
  176. // and optional extended style for the corresponding native control
  177. //
  178. // this is the function that should be overridden in the derived classes,
  179. // but you will mostly use MSWGetCreateWindowFlags() below
  180. virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const ;
  181. // get the MSW window flags corresponding to wxWidgets ones
  182. //
  183. // the functions returns the flags (WS_XXX) directly and puts the ext
  184. // (WS_EX_XXX) flags into the provided pointer if not NULL
  185. WXDWORD MSWGetCreateWindowFlags(WXDWORD *exflags = NULL) const
  186. { return MSWGetStyle(GetWindowStyle(), exflags); }
  187. // update the real underlying window style flags to correspond to the
  188. // current wxWindow object style (safe to call even if window isn't fully
  189. // created yet)
  190. void MSWUpdateStyle(long flagsOld, long exflagsOld);
  191. // get the HWND to be used as parent of this window with CreateWindow()
  192. virtual WXHWND MSWGetParent() const;
  193. // get the Win32 window class name used by all wxWindow objects by default
  194. static const wxChar *MSWGetRegisteredClassName();
  195. // creates the window of specified Windows class with given style, extended
  196. // style, title and geometry (default values
  197. //
  198. // returns true if the window has been created, false if creation failed
  199. bool MSWCreate(const wxChar *wclass,
  200. const wxChar *title = NULL,
  201. const wxPoint& pos = wxDefaultPosition,
  202. const wxSize& size = wxDefaultSize,
  203. WXDWORD style = 0,
  204. WXDWORD exendedStyle = 0);
  205. virtual bool MSWCommand(WXUINT param, WXWORD id);
  206. #ifndef __WXUNIVERSAL__
  207. // Create an appropriate wxWindow from a HWND
  208. virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
  209. // Make sure the window style reflects the HWND style (roughly)
  210. virtual void AdoptAttributesFromHWND();
  211. #endif // __WXUNIVERSAL__
  212. // Setup background and foreground colours correctly
  213. virtual void SetupColours();
  214. // ------------------------------------------------------------------------
  215. // helpers for message handlers: these perform the same function as the
  216. // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
  217. // the correct parameters
  218. // ------------------------------------------------------------------------
  219. void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
  220. WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
  221. void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
  222. WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
  223. void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
  224. WXWORD *code, WXWORD *pos, WXHWND *hwnd);
  225. void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
  226. WXHDC *hdc, WXHWND *hwnd);
  227. void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
  228. WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
  229. // ------------------------------------------------------------------------
  230. // internal handlers for MSW messages: all handlers return a boolean value:
  231. // true means that the handler processed the event and false that it didn't
  232. // ------------------------------------------------------------------------
  233. // there are several cases where we have virtual functions for Windows
  234. // message processing: this is because these messages often require to be
  235. // processed in a different manner in the derived classes. For all other
  236. // messages, however, we do *not* have corresponding MSWOnXXX() function
  237. // and if the derived class wants to process them, it should override
  238. // MSWWindowProc() directly.
  239. // scroll event (both horizontal and vertical)
  240. virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
  241. WXWORD pos, WXHWND control);
  242. // child control notifications
  243. virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
  244. // owner-drawn controls need to process these messages
  245. virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
  246. virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
  247. // the rest are not virtual
  248. bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
  249. bool HandleInitDialog(WXHWND hWndFocus);
  250. bool HandleDestroy();
  251. bool HandlePaint();
  252. bool HandlePrintClient(WXHDC hDC);
  253. bool HandleEraseBkgnd(WXHDC hDC);
  254. bool HandleMinimize();
  255. bool HandleMaximize();
  256. bool HandleSize(int x, int y, WXUINT flag);
  257. bool HandleSizing(wxRect& rect);
  258. bool HandleGetMinMaxInfo(void *mmInfo);
  259. bool HandleEnterSizeMove();
  260. bool HandleExitSizeMove();
  261. bool HandleShow(bool show, int status);
  262. bool HandleActivate(int flag, bool minimized, WXHWND activate);
  263. bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
  264. bool HandleCtlColor(WXHBRUSH *hBrush, WXHDC hdc, WXHWND hWnd);
  265. bool HandlePaletteChanged(WXHWND hWndPalChange);
  266. bool HandleQueryNewPalette();
  267. bool HandleSysColorChange();
  268. bool HandleDisplayChange();
  269. bool HandleCaptureChanged(WXHWND gainedCapture);
  270. virtual bool HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam);
  271. bool HandleQueryEndSession(long logOff, bool *mayEnd);
  272. bool HandleEndSession(bool endSession, long logOff);
  273. bool HandleSetFocus(WXHWND wnd);
  274. bool HandleKillFocus(WXHWND wnd);
  275. bool HandleDropFiles(WXWPARAM wParam);
  276. bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
  277. bool HandleMouseMove(int x, int y, WXUINT flags);
  278. bool HandleMouseWheel(wxMouseWheelAxis axis,
  279. WXWPARAM wParam, WXLPARAM lParam);
  280. bool HandleChar(WXWPARAM wParam, WXLPARAM lParam);
  281. bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
  282. bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
  283. #if wxUSE_HOTKEY
  284. bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam);
  285. #endif
  286. #ifdef __WIN32__
  287. int HandleMenuChar(int chAccel, WXLPARAM lParam);
  288. #endif
  289. // Create and process a clipboard event specified by type.
  290. bool HandleClipboardEvent( WXUINT nMsg );
  291. bool HandleQueryDragIcon(WXHICON *hIcon);
  292. bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
  293. bool HandlePower(WXWPARAM wParam, WXLPARAM lParam, bool *vetoed);
  294. // The main body of common window proc for all wxWindow objects. It tries
  295. // to handle the given message and returns true if it was handled (the
  296. // appropriate return value is then put in result, which must be non-NULL)
  297. // or false if it wasn't.
  298. //
  299. // This function should be overridden in any new code instead of
  300. // MSWWindowProc() even if currently most of the code overrides
  301. // MSWWindowProc() as it had been written before this function was added.
  302. virtual bool MSWHandleMessage(WXLRESULT *result,
  303. WXUINT message,
  304. WXWPARAM wParam,
  305. WXLPARAM lParam);
  306. // Common Window procedure for all wxWindow objects: forwards to
  307. // MSWHandleMessage() and MSWDefWindowProc() if the message wasn't handled.
  308. virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  309. // Calls an appropriate default window procedure
  310. virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  311. // message processing helpers
  312. // return false if the message shouldn't be translated/preprocessed but
  313. // dispatched normally
  314. virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
  315. // return true if the message was preprocessed and shouldn't be dispatched
  316. virtual bool MSWProcessMessage(WXMSG* pMsg);
  317. // return true if the message was translated and shouldn't be dispatched
  318. virtual bool MSWTranslateMessage(WXMSG* pMsg);
  319. // called when the window is about to be destroyed
  320. virtual void MSWDestroyWindow();
  321. // Functions dealing with painting the window background. The derived
  322. // classes should normally only need to reimplement MSWGetBgBrush() if they
  323. // need to use a non-solid brush for erasing their background. This
  324. // function is called by MSWGetBgBrushForChild() which only exists for the
  325. // weird wxToolBar case and MSWGetBgBrushForChild() itself is used by
  326. // MSWGetBgBrush() to actually find the right brush to use.
  327. // Adjust the origin for the brush returned by MSWGetBgBrushForChild().
  328. //
  329. // This needs to be overridden for scrolled windows to ensure that the
  330. // scrolling of their associated DC is taken into account.
  331. //
  332. // Both parameters must be non-NULL.
  333. virtual void MSWAdjustBrushOrg(int* WXUNUSED(xOrg),
  334. int* WXUNUSED(yOrg)) const
  335. {
  336. }
  337. // The brush returned from here must remain valid at least until the next
  338. // event loop iteration. Returning 0, as is done by default, indicates
  339. // there is no custom background brush.
  340. virtual WXHBRUSH MSWGetCustomBgBrush() { return 0; }
  341. // this function should return the brush to paint the children controls
  342. // background or 0 if this window doesn't impose any particular background
  343. // on its children
  344. //
  345. // the hDC parameter is the DC background will be drawn on, it can be used
  346. // to call SetBrushOrgEx() on it if the returned brush is a bitmap one
  347. //
  348. // child parameter is never NULL, it can be this window itself or one of
  349. // its (grand)children
  350. //
  351. // the base class version returns a solid brush if we have a non default
  352. // background colour or 0 otherwise
  353. virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, wxWindowMSW *child);
  354. // return the background brush to use for painting the given window by
  355. // querying the parent windows via MSWGetBgBrushForChild() recursively
  356. WXHBRUSH MSWGetBgBrush(WXHDC hDC);
  357. enum MSWThemeColour
  358. {
  359. ThemeColourText = 0,
  360. ThemeColourBackground,
  361. ThemeColourBorder
  362. };
  363. // returns a specific theme colour, or if that is not possible then
  364. // wxSystemSettings::GetColour(fallback)
  365. wxColour MSWGetThemeColour(const wchar_t *themeName,
  366. int themePart,
  367. int themeState,
  368. MSWThemeColour themeColour,
  369. wxSystemColour fallback) const;
  370. // gives the parent the possibility to draw its children background, e.g.
  371. // this is used by wxNotebook to do it using DrawThemeBackground()
  372. //
  373. // return true if background was drawn, false otherwise
  374. virtual bool MSWPrintChild(WXHDC WXUNUSED(hDC), wxWindow * WXUNUSED(child))
  375. {
  376. return false;
  377. }
  378. // some controls (e.g. wxListBox) need to set the return value themselves
  379. //
  380. // return true to let parent handle it if we don't, false otherwise
  381. virtual bool MSWShouldPropagatePrintChild()
  382. {
  383. return true;
  384. }
  385. // This should be overridden to return true for the controls which have
  386. // themed background that should through their children. Currently only
  387. // wxNotebook uses this.
  388. //
  389. // The base class version already returns true if we have a solid
  390. // background colour that should be propagated to our children.
  391. virtual bool MSWHasInheritableBackground() const
  392. {
  393. return InheritsBackgroundColour();
  394. }
  395. #if !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
  396. #define wxHAS_MSW_BACKGROUND_ERASE_HOOK
  397. #endif
  398. #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
  399. // allows the child to hook into its parent WM_ERASEBKGND processing: call
  400. // MSWSetEraseBgHook() with a non-NULL window to make parent call
  401. // MSWEraseBgHook() on this window (don't forget to reset it to NULL
  402. // afterwards)
  403. //
  404. // this hack is used by wxToolBar, see comments there
  405. void MSWSetEraseBgHook(wxWindow *child);
  406. // return true if WM_ERASEBKGND is currently hooked
  407. bool MSWHasEraseBgHook() const;
  408. // called when the window on which MSWSetEraseBgHook() had been called
  409. // receives WM_ERASEBKGND
  410. virtual bool MSWEraseBgHook(WXHDC WXUNUSED(hDC)) { return false; }
  411. #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
  412. // common part of Show/HideWithEffect()
  413. bool MSWShowWithEffect(bool show,
  414. wxShowEffect effect,
  415. unsigned timeout);
  416. // Responds to colour changes: passes event on to children.
  417. void OnSysColourChanged(wxSysColourChangedEvent& event);
  418. // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
  419. void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
  420. // check if mouse is in the window
  421. bool IsMouseInWindow() const;
  422. // check if a native double-buffering applies for this window
  423. virtual bool IsDoubleBuffered() const;
  424. void SetDoubleBuffered(bool on);
  425. // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false
  426. void GenerateMouseLeave();
  427. // virtual function for implementing internal idle
  428. // behaviour
  429. virtual void OnInternalIdle();
  430. protected:
  431. // this allows you to implement standard control borders without
  432. // repeating the code in different classes that are not derived from
  433. // wxControl
  434. virtual wxBorder GetDefaultBorderForControl() const;
  435. // choose the default border for this window
  436. virtual wxBorder GetDefaultBorder() const;
  437. // Translate wxBORDER_THEME (and other border styles if necessary to the value
  438. // that makes most sense for this Windows environment
  439. virtual wxBorder TranslateBorder(wxBorder border) const;
  440. #if wxUSE_MENUS_NATIVE
  441. virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
  442. #endif // wxUSE_MENUS_NATIVE
  443. // the window handle
  444. WXHWND m_hWnd;
  445. // the old window proc (we subclass all windows)
  446. WXFARPROC m_oldWndProc;
  447. // additional (MSW specific) flags
  448. bool m_mouseInWindow:1;
  449. bool m_lastKeydownProcessed:1;
  450. // the size of one page for scrolling
  451. int m_xThumbSize;
  452. int m_yThumbSize;
  453. // implement the base class pure virtuals
  454. virtual void DoGetTextExtent(const wxString& string,
  455. int *x, int *y,
  456. int *descent = NULL,
  457. int *externalLeading = NULL,
  458. const wxFont *font = NULL) const;
  459. virtual void DoClientToScreen( int *x, int *y ) const;
  460. virtual void DoScreenToClient( int *x, int *y ) const;
  461. virtual void DoGetPosition( int *x, int *y ) const;
  462. virtual void DoGetSize( int *width, int *height ) const;
  463. virtual void DoGetClientSize( int *width, int *height ) const;
  464. virtual void DoSetSize(int x, int y,
  465. int width, int height,
  466. int sizeFlags = wxSIZE_AUTO);
  467. virtual void DoSetClientSize(int width, int height);
  468. virtual wxSize DoGetBorderSize() const;
  469. virtual void DoCaptureMouse();
  470. virtual void DoReleaseMouse();
  471. virtual void DoEnable(bool enable);
  472. virtual void DoFreeze();
  473. virtual void DoThaw();
  474. // this simply moves/resizes the given HWND which is supposed to be our
  475. // sibling (this is useful for controls which are composite at MSW level
  476. // and for which DoMoveWindow() is not enough)
  477. //
  478. // returns true if the window move was deferred, false if it was moved
  479. // immediately (no error return)
  480. bool DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height);
  481. // move the window to the specified location and resize it: this is called
  482. // from both DoSetSize() and DoSetClientSize() and would usually just call
  483. // ::MoveWindow() except for composite controls which will want to arrange
  484. // themselves inside the given rectangle
  485. virtual void DoMoveWindow(int x, int y, int width, int height);
  486. #if wxUSE_TOOLTIPS
  487. virtual void DoSetToolTip( wxToolTip *tip );
  488. // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in
  489. // comctl32.dll in our code -- see the function body for more info)
  490. bool HandleTooltipNotify(WXUINT code,
  491. WXLPARAM lParam,
  492. const wxString& ttip);
  493. #endif // wxUSE_TOOLTIPS
  494. // This is used by CreateKeyEvent() and also for wxEVT_CHAR[_HOOK] event
  495. // creation. Notice that this method doesn't initialize wxKeyEvent
  496. // m_keyCode and m_uniChar fields.
  497. void InitAnyKeyEvent(wxKeyEvent& event,
  498. WXWPARAM wParam,
  499. WXLPARAM lParam) const;
  500. // Helper functions used by HandleKeyXXX() methods and some derived
  501. // classes, wParam and lParam have the same meaning as in WM_KEY{DOWN,UP}.
  502. //
  503. // NB: evType here must be wxEVT_KEY_{DOWN,UP} as wParam here contains the
  504. // virtual key code, not character!
  505. wxKeyEvent CreateKeyEvent(wxEventType evType,
  506. WXWPARAM wParam,
  507. WXLPARAM lParam = 0) const;
  508. // Another helper for creating wxKeyEvent for wxEVT_CHAR and related types.
  509. //
  510. // The wParam and lParam here must come from WM_CHAR event parameters, i.e.
  511. // wParam must be a character and not a virtual code.
  512. wxKeyEvent CreateCharEvent(wxEventType evType,
  513. WXWPARAM wParam,
  514. WXLPARAM lParam) const;
  515. // default OnEraseBackground() implementation, return true if we did erase
  516. // the background, false otherwise (i.e. the system should erase it)
  517. bool DoEraseBackground(WXHDC hDC);
  518. // generate WM_CHANGEUISTATE if it's needed for the OS we're running under
  519. //
  520. // action should be one of the UIS_XXX constants
  521. // state should be one or more of the UISF_XXX constants
  522. // if action == UIS_INITIALIZE then it doesn't seem to matter what we use
  523. // for state as the system will decide for us what needs to be set
  524. void MSWUpdateUIState(int action, int state = 0);
  525. // translate wxWidgets coords into Windows ones suitable to be passed to
  526. // ::CreateWindow(), called from MSWCreate()
  527. virtual void MSWGetCreateWindowCoords(const wxPoint& pos,
  528. const wxSize& size,
  529. int& x, int& y,
  530. int& w, int& h) const;
  531. bool MSWEnableHWND(WXHWND hWnd, bool enable);
  532. // Return the pointer to this window or one of its sub-controls if this ID
  533. // and HWND combination belongs to one of them.
  534. //
  535. // This is used by FindItem() and is overridden in wxControl, see there.
  536. virtual wxWindow* MSWFindItem(long WXUNUSED(id), WXHWND WXUNUSED(hWnd)) const
  537. {
  538. return NULL;
  539. }
  540. private:
  541. // common part of all ctors
  542. void Init();
  543. // the (non-virtual) handlers for the events
  544. bool HandleMove(int x, int y);
  545. bool HandleMoving(wxRect& rect);
  546. bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
  547. bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
  548. #ifndef __WXUNIVERSAL__
  549. // Call ::IsDialogMessage() if it is safe to do it (i.e. if it's not going
  550. // to hang or do something else stupid) with the given message, return true
  551. // if the message was handled by it.
  552. bool MSWSafeIsDialogMessage(WXMSG* msg);
  553. #endif // __WXUNIVERSAL__
  554. #if wxUSE_DEFERRED_SIZING
  555. protected:
  556. // this function is called after the window was resized to its new size
  557. virtual void MSWEndDeferWindowPos()
  558. {
  559. m_pendingPosition = wxDefaultPosition;
  560. m_pendingSize = wxDefaultSize;
  561. }
  562. // current defer window position operation handle (may be NULL)
  563. WXHANDLE m_hDWP;
  564. // When deferred positioning is done these hold the pending changes, and
  565. // are used for the default values if another size/pos changes is done on
  566. // this window before the group of deferred changes is completed.
  567. wxPoint m_pendingPosition;
  568. wxSize m_pendingSize;
  569. #endif // wxUSE_DEFERRED_SIZING
  570. private:
  571. #ifdef __POCKETPC__
  572. bool m_contextMenuEnabled;
  573. #endif
  574. DECLARE_DYNAMIC_CLASS(wxWindowMSW)
  575. wxDECLARE_NO_COPY_CLASS(wxWindowMSW);
  576. DECLARE_EVENT_TABLE()
  577. };
  578. // window creation helper class: before creating a new HWND, instantiate an
  579. // object of this class on stack - this allows to process the messages sent to
  580. // the window even before CreateWindow() returns
  581. class wxWindowCreationHook
  582. {
  583. public:
  584. wxWindowCreationHook(wxWindowMSW *winBeingCreated);
  585. ~wxWindowCreationHook();
  586. };
  587. #endif // _WX_WINDOW_H_