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