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