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 
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14 
15 #include "wx/settings.h"        // solely for wxSystemColour
16 
17 class WXDLLIMPEXP_FWD_CORE wxButton;
18 
19 // if this is set to 1, we use deferred window sizing to reduce flicker when
20 // resizing complicated window hierarchies, but this can in theory result in
21 // different behaviour than the old code so we keep the possibility to use it
22 // by setting this to 0 (in the future this should be removed completely)
23 #define wxUSE_DEFERRED_SIZING 1
24 
25 // ---------------------------------------------------------------------------
26 // wxWindow declaration for MSW
27 // ---------------------------------------------------------------------------
28 
29 class WXDLLIMPEXP_CORE wxWindowMSW : public wxWindowBase
30 {
31     friend class wxSpinCtrl;
32     friend class wxSlider;
33     friend class wxRadioBox;
34 public:
wxWindowMSW()35     wxWindowMSW() { Init(); }
36 
37     wxWindowMSW(wxWindow *parent,
38                 wxWindowID id,
39                 const wxPoint& pos = wxDefaultPosition,
40                 const wxSize& size = wxDefaultSize,
41                 long style = 0,
42                 const wxString& name = wxASCII_STR(wxPanelNameStr))
43     {
44         Init();
45         Create(parent, id, pos, size, style, name);
46     }
47 
48     virtual ~wxWindowMSW();
49 
50     bool Create(wxWindow *parent,
51                 wxWindowID id,
52                 const wxPoint& pos = wxDefaultPosition,
53                 const wxSize& size = wxDefaultSize,
54                 long style = 0,
55                 const wxString& name = wxASCII_STR(wxPanelNameStr))
56     {
57         return CreateUsingMSWClass(GetMSWClassName(style),
58                                    parent, id, pos, size, style, name);
59     }
60 
61     // Non-portable, MSW-specific Create() variant allowing to create the
62     // window with a custom Windows class name. This can be useful to assign a
63     // custom Windows class, that can be recognized from the outside of the
64     // application, for windows of specific type.
65     bool CreateUsingMSWClass(const wxChar* classname,
66                              wxWindow *parent,
67                              wxWindowID id,
68                              const wxPoint& pos = wxDefaultPosition,
69                              const wxSize& size = wxDefaultSize,
70                              long style = 0,
71                              const wxString& name = wxASCII_STR(wxPanelNameStr));
72 
73     // implement base class pure virtuals
74     virtual void SetLabel(const wxString& label) wxOVERRIDE;
75     virtual wxString GetLabel() const wxOVERRIDE;
76 
77     virtual void Raise() wxOVERRIDE;
78     virtual void Lower() wxOVERRIDE;
79 
80 #if wxUSE_DEFERRED_SIZING
81     virtual bool BeginRepositioningChildren() wxOVERRIDE;
82     virtual void EndRepositioningChildren() wxOVERRIDE;
83 #endif // wxUSE_DEFERRED_SIZING
84 
85     virtual bool Show(bool show = true) wxOVERRIDE;
86     virtual bool ShowWithEffect(wxShowEffect effect,
87                                 unsigned timeout = 0) wxOVERRIDE
88     {
89         return MSWShowWithEffect(true, effect, timeout);
90     }
91     virtual bool HideWithEffect(wxShowEffect effect,
92                                 unsigned timeout = 0) wxOVERRIDE
93     {
94         return MSWShowWithEffect(false, effect, timeout);
95     }
96 
97     virtual void SetFocus() wxOVERRIDE;
98     virtual void SetFocusFromKbd() wxOVERRIDE;
99 
100     virtual bool Reparent(wxWindowBase *newParent) wxOVERRIDE;
101 
102     virtual wxSize GetDPI() const wxOVERRIDE;
103     virtual double GetDPIScaleFactor() const wxOVERRIDE;
104 
105 
106     virtual void WarpPointer(int x, int y) wxOVERRIDE;
107     virtual bool EnableTouchEvents(int eventsMask) wxOVERRIDE;
108 
109     virtual void Refresh( bool eraseBackground = true,
110                           const wxRect *rect = (const wxRect *) NULL ) wxOVERRIDE;
111     virtual void Update() wxOVERRIDE;
112 
113     virtual void SetWindowStyleFlag(long style) wxOVERRIDE;
114     virtual void SetExtraStyle(long exStyle) wxOVERRIDE;
115     virtual bool SetCursor( const wxCursor &cursor ) wxOVERRIDE;
116     virtual bool SetFont( const wxFont &font ) wxOVERRIDE;
117 
118     virtual int GetCharHeight() const wxOVERRIDE;
119     virtual int GetCharWidth() const wxOVERRIDE;
120 
121     virtual void SetScrollbar( int orient, int pos, int thumbVisible,
122                                int range, bool refresh = true ) wxOVERRIDE;
123     virtual void SetScrollPos( int orient, int pos, bool refresh = true ) wxOVERRIDE;
124     virtual int GetScrollPos( int orient ) const wxOVERRIDE;
125     virtual int GetScrollThumb( int orient ) const wxOVERRIDE;
126     virtual int GetScrollRange( int orient ) const wxOVERRIDE;
127     virtual void ScrollWindow( int dx, int dy,
128                                const wxRect* rect = NULL ) wxOVERRIDE;
129 
130     virtual bool ScrollLines(int lines) wxOVERRIDE;
131     virtual bool ScrollPages(int pages) wxOVERRIDE;
132 
133     virtual void SetLayoutDirection(wxLayoutDirection dir) wxOVERRIDE;
134     virtual wxLayoutDirection GetLayoutDirection() const wxOVERRIDE;
135     virtual wxCoord AdjustForLayoutDirection(wxCoord x,
136                                              wxCoord width,
137                                              wxCoord widthTotal) const wxOVERRIDE;
138 
139     virtual void SetId(wxWindowID winid) wxOVERRIDE;
140 
141 #if wxUSE_DRAG_AND_DROP
142     virtual void SetDropTarget( wxDropTarget *dropTarget ) wxOVERRIDE;
143 
144     // Accept files for dragging
145     virtual void DragAcceptFiles(bool accept) wxOVERRIDE;
146 #endif // wxUSE_DRAG_AND_DROP
147 
148 #ifndef __WXUNIVERSAL__
149     // Native resource loading (implemented in src/msw/nativdlg.cpp)
150     // FIXME: should they really be all virtual?
151     virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID id);
152     virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
153     wxWindow* GetWindowChild1(wxWindowID id);
154     wxWindow* GetWindowChild(wxWindowID id);
155 #endif // __WXUNIVERSAL__
156 
157 #if wxUSE_HOTKEY
158     // install and deinstall a system wide hotkey
159     virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode) wxOVERRIDE;
160     virtual bool UnregisterHotKey(int hotkeyId) wxOVERRIDE;
161 #endif // wxUSE_HOTKEY
162 
163     // window handle stuff
164     // -------------------
165 
GetHWND()166     WXHWND GetHWND() const { return m_hWnd; }
SetHWND(WXHWND hWnd)167     void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
GetHandle()168     virtual WXWidget GetHandle() const wxOVERRIDE { return GetHWND(); }
169 
170     void AssociateHandle(WXWidget handle) wxOVERRIDE;
171     void DissociateHandle() wxOVERRIDE;
172 
173     // returns the handle of the native window to focus when this wxWindow gets
174     // focus  (i.e. in composite windows: by default, this is just the HWND for
175     // this window itself, but it can be overridden to return something
176     // different for composite controls
MSWGetFocusHWND()177     virtual WXHWND MSWGetFocusHWND() const { return GetHWND(); }
178 
179     // does this window have deferred position and/or size?
180     bool IsSizeDeferred() const;
181 
182     // these functions allow to register a global handler for the given Windows
183     // message: it will be called from MSWWindowProc() of any window which gets
184     // this event if it's not processed before (i.e. unlike a hook procedure it
185     // does not override the normal processing)
186     //
187     // notice that if you want to process a message for a given window only you
188     // should override its MSWWindowProc() instead
189 
190     // type of the handler: it is called with the message parameters (except
191     // that the window object is passed instead of window handle) and should
192     // return true if it handled the message or false if it should be passed to
193     // DefWindowProc()
194     typedef bool (*MSWMessageHandler)(wxWindowMSW *win,
195                                       WXUINT nMsg,
196                                       WXWPARAM wParam,
197                                       WXLPARAM lParam);
198 
199     // install a handler, shouldn't be called more than one for the same message
200     static bool MSWRegisterMessageHandler(int msg, MSWMessageHandler handler);
201 
202     // unregister a previously registered handler
203     static void MSWUnregisterMessageHandler(int msg, MSWMessageHandler handler);
204 
205 
206     // implementation from now on
207     // ==========================
208 
209     // event handlers
210     // --------------
211 
212     void OnPaint(wxPaintEvent& event);
213 
214 public:
215     // Windows subclassing
216     void SubclassWin(WXHWND hWnd);
217     void UnsubclassWin();
218 
MSWGetOldWndProc()219     WXWNDPROC MSWGetOldWndProc() const { return m_oldWndProc; }
MSWSetOldWndProc(WXWNDPROC proc)220     void MSWSetOldWndProc(WXWNDPROC proc) { m_oldWndProc = proc; }
221 
222     // return true if the window is of a standard (i.e. not wxWidgets') class
223     //
224     // to understand why does it work, look at SubclassWin() code and comments
IsOfStandardClass()225     bool IsOfStandardClass() const { return m_oldWndProc != NULL; }
226 
227     wxWindow *FindItem(long id, WXHWND hWnd = NULL) const;
228     wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
229 
230     // MSW only: true if this control is part of the main control
ContainsHWND(WXHWND WXUNUSED (hWnd))231     virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; }
232 
233 #if wxUSE_TOOLTIPS
234     // MSW only: true if this window or any of its children have a tooltip
HasToolTips()235     virtual bool HasToolTips() const { return GetToolTip() != NULL; }
236 #endif // wxUSE_TOOLTIPS
237 
238     // translate wxWidgets style flags for this control into the Windows style
239     // and optional extended style for the corresponding native control
240     //
241     // this is the function that should be overridden in the derived classes,
242     // but you will mostly use MSWGetCreateWindowFlags() below
243     virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const ;
244 
245     // get the MSW window flags corresponding to wxWidgets ones
246     //
247     // the functions returns the flags (WS_XXX) directly and puts the ext
248     // (WS_EX_XXX) flags into the provided pointer if not NULL
249     WXDWORD MSWGetCreateWindowFlags(WXDWORD *exflags = NULL) const
250         { return MSWGetStyle(GetWindowStyle(), exflags); }
251 
252     // update the real underlying window style flags to correspond to the
253     // current wxWindow object style (safe to call even if window isn't fully
254     // created yet)
255     void MSWUpdateStyle(long flagsOld, long exflagsOld);
256 
257     // get the HWND to be used as parent of this window with CreateWindow()
258     virtual WXHWND MSWGetParent() const;
259 
260     // Return the name of the Win32 class that should be used by this wxWindow
261     // object, taking into account wxFULL_REPAINT_ON_RESIZE style (if it's not
262     // specified, the wxApp::GetNoRedrawClassSuffix()-suffixed version of the
263     // class is used).
264     static const wxChar *GetMSWClassName(long style);
265 
266     // creates the window of specified Windows class with given style, extended
267     // style, title and geometry (default values
268     //
269     // returns true if the window has been created, false if creation failed
270     bool MSWCreate(const wxChar *wclass,
271                    const wxChar *title = NULL,
272                    const wxPoint& pos = wxDefaultPosition,
273                    const wxSize& size = wxDefaultSize,
274                    WXDWORD style = 0,
275                    WXDWORD exendedStyle = 0);
276 
277     virtual bool MSWCommand(WXUINT param, WXWORD id);
278 
279 #ifndef __WXUNIVERSAL__
280     // Create an appropriate wxWindow from a HWND
281     virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
282 
283     // Make sure the window style reflects the HWND style (roughly)
284     virtual void AdoptAttributesFromHWND();
285 #endif // __WXUNIVERSAL__
286 
287     // Setup background and foreground colours correctly
288     virtual void SetupColours();
289 
290     // ------------------------------------------------------------------------
291     // helpers for message handlers: these perform the same function as the
292     // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
293     // the correct parameters
294     // ------------------------------------------------------------------------
295 
296     void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
297                        WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
298     void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
299                         WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
300     void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
301                       WXWORD *code, WXWORD *pos, WXHWND *hwnd);
302     void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
303                         WXHDC *hdc, WXHWND *hwnd);
304     void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
305                           WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
306 
307     // ------------------------------------------------------------------------
308     // internal handlers for MSW messages: all handlers return a boolean value:
309     // true means that the handler processed the event and false that it didn't
310     // ------------------------------------------------------------------------
311 
312     // there are several cases where we have virtual functions for Windows
313     // message processing: this is because these messages often require to be
314     // processed in a different manner in the derived classes. For all other
315     // messages, however, we do *not* have corresponding MSWOnXXX() function
316     // and if the derived class wants to process them, it should override
317     // MSWWindowProc() directly.
318 
319     // scroll event (both horizontal and vertical)
320     virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
321                              WXWORD pos, WXHWND control);
322 
323     // child control notifications
324     virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
325 
326     // owner-drawn controls need to process these messages
327     virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
328     virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
329 
330     // the rest are not virtual
331     bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
332     bool HandleInitDialog(WXHWND hWndFocus);
333     bool HandleDestroy();
334 
335     bool HandlePaint();
336     bool HandlePrintClient(WXHDC hDC);
337     bool HandleEraseBkgnd(WXHDC hDC);
338 
339     bool HandleMinimize();
340     bool HandleMaximize();
341     bool HandleSize(int x, int y, WXUINT flag);
342     bool HandleSizing(wxRect& rect);
343     bool HandleGetMinMaxInfo(void *mmInfo);
344     bool HandleEnterSizeMove();
345     bool HandleExitSizeMove();
346 
347     bool HandleShow(bool show, int status);
348     bool HandleActivate(int flag, bool minimized, WXHWND activate);
349 
350     bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
351 
352     bool HandleCtlColor(WXHBRUSH *hBrush, WXHDC hdc, WXHWND hWnd);
353 
354     bool HandlePaletteChanged(WXHWND hWndPalChange);
355     bool HandleQueryNewPalette();
356     bool HandleSysColorChange();
357     bool HandleDisplayChange();
358     bool HandleCaptureChanged(WXHWND gainedCapture);
359     virtual bool HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam);
360 
361     bool HandleQueryEndSession(long logOff, bool *mayEnd);
362     bool HandleEndSession(bool endSession, long logOff);
363 
364     bool HandleSetFocus(WXHWND wnd);
365     bool HandleKillFocus(WXHWND wnd);
366 
367     bool HandleDropFiles(WXWPARAM wParam);
368 
369     bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
370     bool HandleMouseMove(int x, int y, WXUINT flags);
371     bool HandleMouseWheel(wxMouseWheelAxis axis,
372                           WXWPARAM wParam, WXLPARAM lParam);
373 
374     // Common gesture event initialization, returns true if it is the initial
375     // event (GF_BEGIN set in flags), false otherwise.
376     bool InitGestureEvent(wxGestureEvent& event, const wxPoint& pt, WXDWORD flags);
377 
378     bool HandlePanGesture(const wxPoint& pt, WXDWORD flags);
379     bool HandleZoomGesture(const wxPoint& pt, WXDWORD fingerDistance, WXDWORD flags);
380     bool HandleRotateGesture(const wxPoint& pt, WXDWORD angleArgument, WXDWORD flags);
381     bool HandleTwoFingerTap(const wxPoint& pt, WXDWORD flags);
382     bool HandlePressAndTap(const wxPoint& pt, WXDWORD flags);
383 
384     bool HandleChar(WXWPARAM wParam, WXLPARAM lParam);
385     bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
386     bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
387 #if wxUSE_HOTKEY
388     bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam);
389 #endif
390     int HandleMenuChar(int chAccel, WXLPARAM lParam);
391     // Create and process a clipboard event specified by type.
392     bool HandleClipboardEvent( WXUINT nMsg );
393 
394     bool HandleQueryDragIcon(WXHICON *hIcon);
395 
396     bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
397 
398     bool HandlePower(WXWPARAM wParam, WXLPARAM lParam, bool *vetoed);
399 
400 
401     // The main body of common window proc for all wxWindow objects. It tries
402     // to handle the given message and returns true if it was handled (the
403     // appropriate return value is then put in result, which must be non-NULL)
404     // or false if it wasn't.
405     //
406     // This function should be overridden in any new code instead of
407     // MSWWindowProc() even if currently most of the code overrides
408     // MSWWindowProc() as it had been written before this function was added.
409     virtual bool MSWHandleMessage(WXLRESULT *result,
410                                   WXUINT message,
411                                   WXWPARAM wParam,
412                                   WXLPARAM lParam);
413 
414     // Common Window procedure for all wxWindow objects: forwards to
415     // MSWHandleMessage() and MSWDefWindowProc() if the message wasn't handled.
416     virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
417 
418     // Calls an appropriate default window procedure
419     virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
420 
421     // message processing helpers
422 
423     // return false if the message shouldn't be translated/preprocessed but
424     // dispatched normally
425     virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
426 
427     // return true if the message was preprocessed and shouldn't be dispatched
428     virtual bool MSWProcessMessage(WXMSG* pMsg);
429 
430     // return true if the message was translated and shouldn't be dispatched
431     virtual bool MSWTranslateMessage(WXMSG* pMsg);
432 
433     // called when the window is about to be destroyed
434     virtual void MSWDestroyWindow();
435 
436 
437     // Functions dealing with painting the window background. The derived
438     // classes should normally only need to reimplement MSWGetBgBrush() if they
439     // need to use a non-solid brush for erasing their background. This
440     // function is called by MSWGetBgBrushForChild() which only exists for the
441     // weird wxToolBar case and MSWGetBgBrushForChild() itself is used by
442     // MSWGetBgBrush() to actually find the right brush to use.
443 
444     // Adjust the origin for the brush returned by MSWGetBgBrushForChild().
445     //
446     // This needs to be overridden for scrolled windows to ensure that the
447     // scrolling of their associated DC is taken into account.
448     //
449     // Both parameters must be non-NULL.
MSWAdjustBrushOrg(int * WXUNUSED (xOrg),int * WXUNUSED (yOrg))450     virtual void MSWAdjustBrushOrg(int* WXUNUSED(xOrg),
451                                    int* WXUNUSED(yOrg)) const
452     {
453     }
454 
455     // The brush returned from here must remain valid at least until the next
456     // event loop iteration. Returning 0, as is done by default, indicates
457     // there is no custom background brush.
MSWGetCustomBgBrush()458     virtual WXHBRUSH MSWGetCustomBgBrush() { return NULL; }
459 
460     // this function should return the brush to paint the children controls
461     // background or 0 if this window doesn't impose any particular background
462     // on its children
463     //
464     // the hDC parameter is the DC background will be drawn on, it can be used
465     // to call SetBrushOrgEx() on it if the returned brush is a bitmap one
466     //
467     // child parameter is never NULL, it can be this window itself or one of
468     // its (grand)children
469     //
470     // the base class version returns a solid brush if we have a non default
471     // background colour or 0 otherwise
472     virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, wxWindowMSW *child);
473 
474     // return the background brush to use for painting the given window by
475     // querying the parent windows via MSWGetBgBrushForChild() recursively
476     WXHBRUSH MSWGetBgBrush(WXHDC hDC);
477 
478     enum MSWThemeColour
479     {
480         ThemeColourText = 0,
481         ThemeColourBackground,
482         ThemeColourBorder
483     };
484 
485     // returns a specific theme colour, or if that is not possible then
486     // wxSystemSettings::GetColour(fallback)
487     wxColour MSWGetThemeColour(const wchar_t *themeName,
488                                int themePart,
489                                int themeState,
490                                MSWThemeColour themeColour,
491                                wxSystemColour fallback) const;
492 
493     // gives the parent the possibility to draw its children background, e.g.
494     // this is used by wxNotebook to do it using DrawThemeBackground()
495     //
496     // return true if background was drawn, false otherwise
MSWPrintChild(WXHDC WXUNUSED (hDC),wxWindow * WXUNUSED (child))497     virtual bool MSWPrintChild(WXHDC WXUNUSED(hDC), wxWindow * WXUNUSED(child))
498     {
499         return false;
500     }
501 
502     // some controls (e.g. wxListBox) need to set the return value themselves
503     //
504     // return true to let parent handle it if we don't, false otherwise
MSWShouldPropagatePrintChild()505     virtual bool MSWShouldPropagatePrintChild()
506     {
507         return true;
508     }
509 
510     // This should be overridden to return true for the controls which have
511     // themed background that should through their children. Currently only
512     // wxNotebook uses this.
513     //
514     // The base class version already returns true if we have a solid
515     // background colour that should be propagated to our children.
MSWHasInheritableBackground()516     virtual bool MSWHasInheritableBackground() const
517     {
518         return InheritsBackgroundColour();
519     }
520 
521 #if !defined(__WXUNIVERSAL__)
522     #define wxHAS_MSW_BACKGROUND_ERASE_HOOK
523 #endif
524 
525 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
526     // allows the child to hook into its parent WM_ERASEBKGND processing: call
527     // MSWSetEraseBgHook() with a non-NULL window to make parent call
528     // MSWEraseBgHook() on this window (don't forget to reset it to NULL
529     // afterwards)
530     //
531     // this hack is used by wxToolBar, see comments there
532     void MSWSetEraseBgHook(wxWindow *child);
533 
534     // return true if WM_ERASEBKGND is currently hooked
535     bool MSWHasEraseBgHook() const;
536 
537     // called when the window on which MSWSetEraseBgHook() had been called
538     // receives WM_ERASEBKGND
MSWEraseBgHook(WXHDC WXUNUSED (hDC))539     virtual bool MSWEraseBgHook(WXHDC WXUNUSED(hDC)) { return false; }
540 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
541 
542     // common part of Show/HideWithEffect()
543     bool MSWShowWithEffect(bool show,
544                            wxShowEffect effect,
545                            unsigned timeout);
546 
547     // Responds to colour changes: passes event on to children.
548     void OnSysColourChanged(wxSysColourChangedEvent& event);
549 
550     // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
551     void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
552 
553     // check if mouse is in the window
554     bool IsMouseInWindow() const;
555 
556     virtual void SetDoubleBuffered(bool on) wxOVERRIDE;
557     virtual bool IsDoubleBuffered() const wxOVERRIDE;
558 
559     // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false
560     void GenerateMouseLeave();
561 
562     // virtual function for implementing internal idle
563     // behaviour
564     virtual void OnInternalIdle() wxOVERRIDE;
565 
566 #if wxUSE_MENUS && !defined(__WXUNIVERSAL__)
567     virtual bool HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu);
568 
569     // handle WM_(UN)INITMENUPOPUP message to generate wxEVT_MENU_OPEN/CLOSE
570     bool HandleMenuPopup(wxEventType evtType, WXHMENU hMenu);
571 
572     // Command part of HandleMenuPopup() and HandleExitMenuLoop().
573     virtual bool DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu);
574 
575     // Find the menu corresponding to the given handle.
576     virtual wxMenu* MSWFindMenuFromHMENU(WXHMENU hMenu);
577 #endif // wxUSE_MENUS && !__WXUNIVERSAL__
578 
579     // Return the default button for the TLW containing this window or NULL if
580     // none.
581     static wxButton* MSWGetDefaultButtonFor(wxWindow* win);
582 
583     // Simulate a click on the given button if it is non-null, enabled and
584     // shown.
585     //
586     // Return true if the button was clicked, false otherwise.
587     static bool MSWClickButtonIfPossible(wxButton* btn);
588 
589     // This method is used for handling wxRadioButton-related complications,
590     // see wxRadioButton::SetValue().
591     //
592     // It should be overridden by all classes storing the "last focused"
593     // window to avoid focusing an unset radio button when regaining focus.
WXSetPendingFocus(wxWindow * WXUNUSED (win))594     virtual void WXSetPendingFocus(wxWindow* WXUNUSED(win)) {}
595 
596     // Called from WM_DPICHANGED handler for all windows to let them update
597     // any sizes and fonts used internally when the DPI changes and generate
598     // wxDPIChangedEvent to let the user code do the same thing as well.
599     void MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI);
600 
601 protected:
602     virtual void WXAdjustFontToOwnPPI(wxFont& font) const wxOVERRIDE;
603 
604     // Called from MSWUpdateOnDPIChange() specifically to update the control
605     // font, as this may need to be done differently for some specific native
606     // controls. The default version updates m_font of this window.
607     virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI);
608 
609     // this allows you to implement standard control borders without
610     // repeating the code in different classes that are not derived from
611     // wxControl
612     virtual wxBorder GetDefaultBorderForControl() const wxOVERRIDE;
613 
614     // choose the default border for this window
615     virtual wxBorder GetDefaultBorder() const wxOVERRIDE;
616 
617     // Translate wxBORDER_THEME (and other border styles if necessary to the value
618     // that makes most sense for this Windows environment
619     virtual wxBorder TranslateBorder(wxBorder border) const;
620 
621 #if wxUSE_MENUS_NATIVE
622     virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) wxOVERRIDE;
623 #endif // wxUSE_MENUS_NATIVE
624 
625     // the window handle
626     WXHWND                m_hWnd;
627 
628     // the old window proc (we subclass all windows)
629     WXWNDPROC             m_oldWndProc;
630 
631     // additional (MSW specific) flags
632     bool                  m_mouseInWindow:1;
633     bool                  m_lastKeydownProcessed:1;
634 
635     // the size of one page for scrolling
636     int                   m_xThumbSize;
637     int                   m_yThumbSize;
638 
639     // implement the base class pure virtuals
640     virtual void DoGetTextExtent(const wxString& string,
641                                  int *x, int *y,
642                                  int *descent = NULL,
643                                  int *externalLeading = NULL,
644                                  const wxFont *font = NULL) const wxOVERRIDE;
645     static void MSWDoClientToScreen( WXHWND hWnd, int *x, int *y );
646     static void MSWDoScreenToClient( WXHWND hWnd, int *x, int *y );
647     virtual void DoClientToScreen( int *x, int *y ) const wxOVERRIDE;
648     virtual void DoScreenToClient( int *x, int *y ) const wxOVERRIDE;
649     virtual void DoGetPosition( int *x, int *y ) const wxOVERRIDE;
650     virtual void DoGetSize( int *width, int *height ) const wxOVERRIDE;
651     virtual void DoGetClientSize( int *width, int *height ) const wxOVERRIDE;
652     virtual void DoSetSize(int x, int y,
653                            int width, int height,
654                            int sizeFlags = wxSIZE_AUTO) wxOVERRIDE;
655     virtual void DoSetClientSize(int width, int height) wxOVERRIDE;
656 
657     virtual wxSize DoGetBorderSize() const wxOVERRIDE;
658 
659     virtual void DoCaptureMouse() wxOVERRIDE;
660     virtual void DoReleaseMouse() wxOVERRIDE;
661 
662     virtual void DoEnable(bool enable) wxOVERRIDE;
663 
664     virtual void DoFreeze() wxOVERRIDE;
665     virtual void DoThaw() wxOVERRIDE;
666 
667     // this simply moves/resizes the given HWND which is supposed to be our
668     // sibling (this is useful for controls which are composite at MSW level
669     // and for which DoMoveWindow() is not enough)
670     //
671     // returns true if the window move was deferred, false if it was moved
672     // immediately (no error return)
673     bool DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height);
674 
675     // move the window to the specified location and resize it: this is called
676     // from both DoSetSize() and DoSetClientSize() and would usually just call
677     // ::MoveWindow() except for composite controls which will want to arrange
678     // themselves inside the given rectangle
679     virtual void DoMoveWindow(int x, int y, int width, int height) wxOVERRIDE;
680 
681 #if wxUSE_TOOLTIPS
682     virtual void DoSetToolTip( wxToolTip *tip ) wxOVERRIDE;
683 
684     // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in
685     // comctl32.dll in our code -- see the function body for more info)
686     bool HandleTooltipNotify(WXUINT code,
687                              WXLPARAM lParam,
688                              const wxString& ttip);
689 #endif // wxUSE_TOOLTIPS
690 
691     // This is used by CreateKeyEvent() and also for wxEVT_CHAR[_HOOK] event
692     // creation. Notice that this method doesn't initialize wxKeyEvent
693     // m_keyCode and m_uniChar fields.
694     void InitAnyKeyEvent(wxKeyEvent& event,
695                          WXWPARAM wParam,
696                          WXLPARAM lParam) const;
697 
698     // Helper functions used by HandleKeyXXX() methods and some derived
699     // classes, wParam and lParam have the same meaning as in WM_KEY{DOWN,UP}.
700     //
701     // NB: evType here must be wxEVT_KEY_{DOWN,UP} as wParam here contains the
702     //     virtual key code, not character!
703     wxKeyEvent CreateKeyEvent(wxEventType evType,
704                               WXWPARAM wParam,
705                               WXLPARAM lParam = 0) const;
706 
707     // Another helper for creating wxKeyEvent for wxEVT_CHAR and related types.
708     //
709     // The wParam and lParam here must come from WM_CHAR event parameters, i.e.
710     // wParam must be a character and not a virtual code.
711     wxKeyEvent CreateCharEvent(wxEventType evType,
712                                WXWPARAM wParam,
713                                WXLPARAM lParam) const;
714 
715 
716     // default OnEraseBackground() implementation, return true if we did erase
717     // the background, false otherwise (i.e. the system should erase it)
718     bool DoEraseBackground(WXHDC hDC);
719 
720     // generate WM_CHANGEUISTATE if it's needed for the OS we're running under
721     //
722     // action should be one of the UIS_XXX constants
723     // state should be one or more of the UISF_XXX constants
724     // if action == UIS_INITIALIZE then it doesn't seem to matter what we use
725     // for state as the system will decide for us what needs to be set
726     void MSWUpdateUIState(int action, int state = 0);
727 
728     // translate wxWidgets coords into Windows ones suitable to be passed to
729     // ::CreateWindow(), called from MSWCreate()
730     virtual void MSWGetCreateWindowCoords(const wxPoint& pos,
731                                           const wxSize& size,
732                                           int& x, int& y,
733                                           int& w, int& h) const;
734 
735     bool MSWEnableHWND(WXHWND hWnd, bool enable);
736 
737     // Return the pointer to this window or one of its sub-controls if this ID
738     // and HWND combination belongs to one of them.
739     //
740     // This is used by FindItem() and is overridden in wxControl, see there.
MSWFindItem(long WXUNUSED (id),WXHWND WXUNUSED (hWnd))741     virtual wxWindow* MSWFindItem(long WXUNUSED(id), WXHWND WXUNUSED(hWnd)) const
742     {
743         return NULL;
744     }
745 
746 private:
747     // common part of all ctors
748     void Init();
749 
750     // the (non-virtual) handlers for the events
751     bool HandleMove(int x, int y);
752     bool HandleMoving(wxRect& rect);
753     bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
754     bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
755 
756 #ifndef __WXUNIVERSAL__
757     // Call ::IsDialogMessage() if it is safe to do it (i.e. if it's not going
758     // to hang or do something else stupid) with the given message, return true
759     // if the message was handled by it.
760     bool MSWSafeIsDialogMessage(WXMSG* msg);
761 #endif // __WXUNIVERSAL__
762 
MSWIsPositionDirectlySupported(int x,int y)763     static inline bool MSWIsPositionDirectlySupported(int x, int y)
764     {
765         // The supported coordinate intervals for various functions are:
766         // - MoveWindow, DeferWindowPos: [-32768, 32767] a.k.a. [SHRT_MIN, SHRT_MAX];
767         // - CreateWindow, CreateWindowEx: [-32768, 32554].
768         // CreateXXX will _sometimes_ manage to create the window at higher coordinates
769         // like 32580, 32684, 32710, but that was not consistent and the lowest common
770         // limit was 32554 (so far at least).
771         return (x >= SHRT_MIN && x <= 32554 && y >= SHRT_MIN && y <= 32554);
772     }
773 
774 protected:
775     WXHWND MSWCreateWindowAtAnyPosition(WXDWORD exStyle, const wxChar* clName,
776                                         const wxChar* title, WXDWORD style,
777                                         int x, int y, int width, int height,
778                                         WXHWND parent, wxWindowID id);
779 
780     void MSWMoveWindowToAnyPosition(WXHWND hwnd, int x, int y,
781                                     int width, int height, bool bRepaint);
782 
783 #if wxUSE_DEFERRED_SIZING
784     // this function is called after the window was resized to its new size
MSWEndDeferWindowPos()785     virtual void MSWEndDeferWindowPos()
786     {
787         m_pendingPosition = wxDefaultPosition;
788         m_pendingSize = wxDefaultSize;
789     }
790 
791     // current defer window position operation handle (may be NULL)
792     WXHANDLE m_hDWP;
793 
794     // When deferred positioning is done these hold the pending changes, and
795     // are used for the default values if another size/pos changes is done on
796     // this window before the group of deferred changes is completed.
797     wxPoint     m_pendingPosition;
798     wxSize      m_pendingSize;
799 #endif // wxUSE_DEFERRED_SIZING
800 
801 private:
802     wxDECLARE_DYNAMIC_CLASS(wxWindowMSW);
803     wxDECLARE_NO_COPY_CLASS(wxWindowMSW);
804     wxDECLARE_EVENT_TABLE();
805 };
806 
807 // window creation helper class: before creating a new HWND, instantiate an
808 // object of this class on stack - this allows to process the messages sent to
809 // the window even before CreateWindow() returns
810 class wxWindowCreationHook
811 {
812 public:
813     wxWindowCreationHook(wxWindowMSW *winBeingCreated);
814     ~wxWindowCreationHook();
815 };
816 
817 #endif // _WX_WINDOW_H_
818