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