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