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