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