]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
d266161df162eab6357153fd74c02f8b5214fc7d
[wxWidgets.git] / include / wx / msw / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/window.h
3 // Purpose: wxWindow 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 // headers
18 // ---------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma interface "window.h"
22 #endif
23
24 // for HANDLE
25 #include "wx/msw/wrapwin.h"
26
27 // [at least] some version of Windows send extra mouse move messages after
28 // a mouse click or a key press - to temporarily fix this problem, set the
29 // define below to 1
30 //
31 // a better solution should be found later...
32 #define wxUSE_MOUSEEVENT_HACK 0
33
34 // ---------------------------------------------------------------------------
35 // constants
36 // ---------------------------------------------------------------------------
37
38 #if WXWIN_COMPATIBILITY_2_4
39 // they're unused by wxWidgets...
40 enum
41 {
42 wxKEY_SHIFT = 1,
43 wxKEY_CTRL = 2
44 };
45 #endif
46
47 // ---------------------------------------------------------------------------
48 // wxWindow declaration for MSW
49 // ---------------------------------------------------------------------------
50
51 class WXDLLEXPORT wxWindowMSW : public wxWindowBase
52 {
53 public:
54 wxWindowMSW() { Init(); }
55
56 wxWindowMSW(wxWindow *parent,
57 wxWindowID id,
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 long style = 0,
61 const wxString& name = wxPanelNameStr)
62 {
63 Init();
64 Create(parent, id, pos, size, style, name);
65 }
66
67 virtual ~wxWindowMSW();
68
69 bool Create(wxWindow *parent,
70 wxWindowID id,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
73 long style = 0,
74 const wxString& name = wxPanelNameStr);
75
76 // implement base class pure virtuals
77 virtual void SetTitle( const wxString& title);
78 virtual wxString GetTitle() const;
79
80 virtual void Raise();
81 virtual void Lower();
82
83 virtual bool Show( bool show = true );
84 virtual bool Enable( bool enable = true );
85
86 virtual void SetFocus();
87 virtual void SetFocusFromKbd();
88
89 virtual bool Reparent(wxWindowBase *newParent);
90
91 virtual void WarpPointer(int x, int y);
92
93 virtual void Refresh( bool eraseBackground = true,
94 const wxRect *rect = (const wxRect *) NULL );
95 virtual void Update();
96 virtual void Freeze();
97 virtual void Thaw();
98
99 virtual void SetWindowStyleFlag( long style );
100 virtual bool SetCursor( const wxCursor &cursor );
101 virtual bool SetFont( const wxFont &font );
102
103 virtual int GetCharHeight() const;
104 virtual int GetCharWidth() const;
105 virtual void GetTextExtent(const wxString& string,
106 int *x, int *y,
107 int *descent = (int *) NULL,
108 int *externalLeading = (int *) NULL,
109 const wxFont *theFont = (const wxFont *) NULL)
110 const;
111
112 #if wxUSE_MENUS_NATIVE
113 virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
114 #endif // wxUSE_MENUS_NATIVE
115
116 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
117 int range, bool refresh = true );
118 virtual void SetScrollPos( int orient, int pos, bool refresh = true );
119 virtual int GetScrollPos( int orient ) const;
120 virtual int GetScrollThumb( int orient ) const;
121 virtual int GetScrollRange( int orient ) const;
122 virtual void ScrollWindow( int dx, int dy,
123 const wxRect* rect = (wxRect *) NULL );
124
125 virtual bool ScrollLines(int lines);
126 virtual bool ScrollPages(int pages);
127
128 #if wxUSE_DRAG_AND_DROP
129 virtual void SetDropTarget( wxDropTarget *dropTarget );
130 #endif // wxUSE_DRAG_AND_DROP
131
132 // Accept files for dragging
133 virtual void DragAcceptFiles(bool accept);
134
135 #if WXWIN_COMPATIBILITY_2_4
136 wxDEPRECATED( bool GetUseCtl3D() const );
137 wxDEPRECATED( bool GetTransparentBackground() const );
138 wxDEPRECATED( void SetTransparent(bool t = true) );
139 #endif // WXWIN_COMPATIBILITY_2_4
140
141 #ifndef __WXUNIVERSAL__
142 // Native resource loading (implemented in src/msw/nativdlg.cpp)
143 // FIXME: should they really be all virtual?
144 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
145 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
146 wxWindow* GetWindowChild1(wxWindowID id);
147 wxWindow* GetWindowChild(wxWindowID id);
148 #endif // __WXUNIVERSAL__
149
150 #if wxUSE_HOTKEY
151 // install and deinstall a system wide hotkey
152 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
153 virtual bool UnregisterHotKey(int hotkeyId);
154 #endif // wxUSE_HOTKEY
155
156 // window handle stuff
157 // -------------------
158
159 WXHWND GetHWND() const { return m_hWnd; }
160 void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; }
161 virtual WXWidget GetHandle() const { return GetHWND(); }
162
163 void AssociateHandle(WXWidget handle);
164 void DissociateHandle();
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 // For implementation purposes - sometimes decorations make the client area
181 // smaller
182 virtual wxPoint GetClientAreaOrigin() const;
183
184 // Windows subclassing
185 void SubclassWin(WXHWND hWnd);
186 void UnsubclassWin();
187
188 WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; }
189 void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
190
191 // return true if the window is of a standard (i.e. not wxWidgets') class
192 //
193 // to understand why does it work, look at SubclassWin() code and comments
194 bool IsOfStandardClass() const { return m_oldWndProc != NULL; }
195
196 wxWindow *FindItem(long id) const;
197 wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const;
198
199 // MSW only: true if this control is part of the main control
200 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; };
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 // translate wxWidgets coords into Windows ones suitable to be passed to
217 // ::CreateWindow()
218 //
219 // returns true if non default coords are returned, false otherwise
220 bool MSWGetCreateWindowCoords(const wxPoint& pos,
221 const wxSize& size,
222 int& x, int& y,
223 int& w, int& h) const;
224
225 // get the HWND to be used as parent of this window with CreateWindow()
226 virtual WXHWND MSWGetParent() const;
227
228 // creates the window of specified Windows class with given style, extended
229 // style, title and geometry (default values
230 //
231 // returns true if the window has been created, false if creation failed
232 bool MSWCreate(const wxChar *wclass,
233 const wxChar *title = NULL,
234 const wxPoint& pos = wxDefaultPosition,
235 const wxSize& size = wxDefaultSize,
236 WXDWORD style = 0,
237 WXDWORD exendedStyle = 0);
238
239 virtual bool MSWCommand(WXUINT param, WXWORD id);
240
241 #ifndef __WXUNIVERSAL__
242 // Create an appropriate wxWindow from a HWND
243 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
244
245 // Make sure the window style reflects the HWND style (roughly)
246 virtual void AdoptAttributesFromHWND();
247 #endif // __WXUNIVERSAL__
248
249 // Setup background and foreground colours correctly
250 virtual void SetupColours();
251
252 // ------------------------------------------------------------------------
253 // helpers for message handlers: these perform the same function as the
254 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
255 // the correct parameters
256 // ------------------------------------------------------------------------
257
258 void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
259 WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
260 void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
261 WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
262 void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
263 WXWORD *code, WXWORD *pos, WXHWND *hwnd);
264 void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
265 WXHDC *hdc, WXHWND *hwnd);
266 void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
267 WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
268
269 // ------------------------------------------------------------------------
270 // internal handlers for MSW messages: all handlers return a boolean value:
271 // true means that the handler processed the event and false that it didn't
272 // ------------------------------------------------------------------------
273
274 // there are several cases where we have virtual functions for Windows
275 // message processing: this is because these messages often require to be
276 // processed in a different manner in the derived classes. For all other
277 // messages, however, we do *not* have corresponding MSWOnXXX() function
278 // and if the derived class wants to process them, it should override
279 // MSWWindowProc() directly.
280
281 // scroll event (both horizontal and vertical)
282 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
283 WXWORD pos, WXHWND control);
284
285 // child control notifications
286 #ifdef __WIN95__
287 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
288 #endif // __WIN95__
289
290 // owner-drawn controls need to process these messages
291 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
292 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
293
294 // the rest are not virtual
295 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
296 bool HandleInitDialog(WXHWND hWndFocus);
297 bool HandleDestroy();
298
299 bool HandlePaint();
300 bool HandleEraseBkgnd(WXHDC pDC);
301
302 bool HandleMinimize();
303 bool HandleMaximize();
304 bool HandleSize(int x, int y, WXUINT flag);
305 bool HandleSizing(wxRect& rect);
306 bool HandleGetMinMaxInfo(void *mmInfo);
307
308 bool HandleShow(bool show, int status);
309 bool HandleActivate(int flag, bool minimized, WXHWND activate);
310
311 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
312
313 bool HandleCtlColor(WXHBRUSH *hBrush, WXHDC hdc, WXHWND hWnd);
314
315 bool HandlePaletteChanged(WXHWND hWndPalChange);
316 bool HandleQueryNewPalette();
317 bool HandleSysColorChange();
318 bool HandleDisplayChange();
319 bool HandleCaptureChanged(WXHWND gainedCapture);
320
321 bool HandleQueryEndSession(long logOff, bool *mayEnd);
322 bool HandleEndSession(bool endSession, long logOff);
323
324 bool HandleSetFocus(WXHWND wnd);
325 bool HandleKillFocus(WXHWND wnd);
326
327 bool HandleDropFiles(WXWPARAM wParam);
328
329 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
330 bool HandleMouseMove(int x, int y, WXUINT flags);
331 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
332
333 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false);
334 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
335 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
336 #if wxUSE_ACCEL
337 bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam);
338 #endif
339 #ifdef __WIN32__
340 int HandleMenuChar(int chAccel, WXLPARAM lParam);
341 #endif
342
343 bool HandleQueryDragIcon(WXHICON *hIcon);
344
345 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
346
347 // Window procedure
348 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
349
350 // Calls an appropriate default window procedure
351 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
352
353 // message processing helpers
354
355 // return false if the message shouldn't be translated/preprocessed but
356 // dispatched normally
357 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
358
359 // return true if the message was preprocessed and shouldn't be dispatched
360 virtual bool MSWProcessMessage(WXMSG* pMsg);
361
362 // return true if the message was translated and shouldn't be dispatched
363 virtual bool MSWTranslateMessage(WXMSG* pMsg);
364
365 // called when the window is about to be destroyed
366 virtual void MSWDestroyWindow();
367
368 // this function should return the brush to paint the window background
369 // with or 0 for the default brush
370 virtual WXHBRUSH MSWControlColor(WXHDC hDC);
371
372 // this function should return the brush to paint the children controls
373 // background or 0 if this window doesn't impose any particular background
374 // on its children
375 //
376 // the base class version uses MSWGetBgColourForChild() and returns a solid
377 // brush if we have a non default background colour or 0 otherwise
378 virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), wxWindow *child)
379 {
380 return MSWGetSolidBgBrushForChild(child);
381 }
382
383 // return the background colour of this window under the given child
384 // (possible grand child)
385 //
386 // this is a hack as if the background is themed, there is no single colour
387 // representing it, but sometimes we can't use the pattern brush returned
388 // by MSWGetBgBrushForChild() anyhow and then this function is used as
389 // fallback
390 //
391 // the base class version returns bg colour if it had been explicitely set
392 // or wxNullColour otherwise
393 virtual wxColour MSWGetBgColourForChild(wxWindow *child);
394
395 // convenience function: returns a solid brush of the colour returned by
396 // MSWGetBgColourForChild() or 0
397 WXHBRUSH MSWGetSolidBgBrushForChild(wxWindow *child);
398
399 // normally just calls MSWGetBgBrushForChild() on the parent window but may
400 // be overridden if the default background brush is not suitable for some
401 // reason (e.g. wxStaticBox uses MSWGetSolidBgBrushForChild() instead)
402 virtual WXHBRUSH MSWGetBgBrushForSelf(wxWindow *parent, WXHDC hDC);
403
404 // return the background brush to use for this window by quering the parent
405 // windows via their MSWGetBgBrushForChild() recursively
406 WXHBRUSH MSWGetBgBrush(WXHDC hDC);
407
408 // Responds to colour changes: passes event on to children.
409 void OnSysColourChanged(wxSysColourChangedEvent& event);
410
411 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
412 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
413
414 // check if mouse is in the window
415 bool IsMouseInWindow() const;
416
417 // virtual function for implementing internal idle
418 // behaviour
419 virtual void OnInternalIdle() ;
420
421 protected:
422 // the window handle
423 WXHWND m_hWnd;
424
425 // the old window proc (we subclass all windows)
426 WXFARPROC m_oldWndProc;
427
428 // additional (MSW specific) flags
429 bool m_mouseInWindow:1;
430 bool m_lastKeydownProcessed:1;
431
432 // the size of one page for scrolling
433 int m_xThumbSize;
434 int m_yThumbSize;
435
436 #if wxUSE_MOUSEEVENT_HACK
437 // the coordinates of the last mouse event and the type of it
438 long m_lastMouseX,
439 m_lastMouseY;
440 int m_lastMouseEvent;
441 #endif // wxUSE_MOUSEEVENT_HACK
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 // move the window to the specified location and resize it: this is called
461 // from both DoSetSize() and DoSetClientSize() and would usually just call
462 // ::MoveWindow() except for composite controls which will want to arrange
463 // themselves inside the given rectangle
464 virtual void DoMoveWindow(int x, int y, int width, int height);
465
466 #if wxUSE_TOOLTIPS
467 virtual void DoSetToolTip( wxToolTip *tip );
468
469 // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in
470 // comctl32.dll in our code -- see the function body for more info)
471 bool HandleTooltipNotify(WXUINT code,
472 WXLPARAM lParam,
473 const wxString& ttip);
474 #endif // wxUSE_TOOLTIPS
475
476 // the helper functions used by HandleChar/KeyXXX methods
477 wxKeyEvent CreateKeyEvent(wxEventType evType, int id,
478 WXLPARAM lParam = 0, WXWPARAM wParam = 0) const;
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
489 #ifdef __WIN95__
490 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
491 #endif // __WIN95__
492
493 // list of disabled children before last call to our Disable()
494 wxWindowList *m_childrenDisabled;
495
496 // number of calls to Freeze() minus number of calls to Thaw()
497 unsigned int m_frozenness;
498
499 // current defer window position operation handle (may be NULL)
500 HANDLE m_hDWP;
501
502
503 DECLARE_DYNAMIC_CLASS(wxWindowMSW)
504 DECLARE_NO_COPY_CLASS(wxWindowMSW)
505 DECLARE_EVENT_TABLE()
506 };
507
508 // ----------------------------------------------------------------------------
509 // inline functions
510 // ----------------------------------------------------------------------------
511
512 #if WXWIN_COMPATIBILITY_2_4
513
514 inline bool wxWindowMSW::GetUseCtl3D() const { return false; }
515 inline bool wxWindowMSW::GetTransparentBackground() const { return false; }
516 inline void wxWindowMSW::SetTransparent(bool WXUNUSED(t)) { }
517
518 #endif // WXWIN_COMPATIBILITY_2_4
519
520 // ---------------------------------------------------------------------------
521 // global functions
522 // ---------------------------------------------------------------------------
523
524 // kbd code translation
525 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0);
526 WXDLLEXPORT WXWORD wxCharCodeWXToMSW(int id, bool *IsVirtual);
527
528 // window creation helper class: before creating a new HWND, instantiate an
529 // object of this class on stack - this allows to process the messages sent to
530 // the window even before CreateWindow() returns
531 class wxWindowCreationHook
532 {
533 public:
534 wxWindowCreationHook(wxWindowMSW *winBeingCreated);
535 ~wxWindowCreationHook();
536 };
537
538 // ----------------------------------------------------------------------------
539 // global objects
540 // ----------------------------------------------------------------------------
541
542 // notice that this hash must be defined after wxWindow declaration as it
543 // needs to "see" its dtor and not just forward declaration
544 #include "wx/hash.h"
545
546 // pseudo-template HWND <-> wxWindow hash table
547 #if WXWIN_COMPATIBILITY_2_4
548 WX_DECLARE_HASH(wxWindow, wxWindowList, wxWinHashTable);
549 #else
550 WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable);
551 #endif
552
553 extern wxWinHashTable *wxWinHandleHash;
554
555 #endif
556 // _WX_WINDOW_H_