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