]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
Permission for flood-fill code clarified
[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 // [at least] some version of Windows send extra mouse move messages after
25 // a mouse click or a key press - to temporarily fix this problem, set the
26 // define below to 1
27 //
28 // a better solution should be found later...
29 #define wxUSE_MOUSEEVENT_HACK 0
30
31 // ---------------------------------------------------------------------------
32 // constants
33 // ---------------------------------------------------------------------------
34
35 #if WXWIN_COMPATIBILITY_2_4
36 // they're unused by wxWidgets...
37 enum
38 {
39 wxKEY_SHIFT = 1,
40 wxKEY_CTRL = 2
41 };
42 #endif
43
44 // ---------------------------------------------------------------------------
45 // wxWindow declaration for MSW
46 // ---------------------------------------------------------------------------
47
48 class WXDLLEXPORT wxWindowMSW : public wxWindowBase
49 {
50 friend class wxSpinCtrl;
51 friend class wxSlider;
52 friend class wxRadioBox;
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 // 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 // translate wxWidgets style flags for this control into the Windows style
199 // and optional extended style for the corresponding native control
200 //
201 // this is the function that should be overridden in the derived classes,
202 // but you will mostly use MSWGetCreateWindowFlags() below
203 virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const ;
204
205 // get the MSW window flags corresponding to wxWidgets ones
206 //
207 // the functions returns the flags (WS_XXX) directly and puts the ext
208 // (WS_EX_XXX) flags into the provided pointer if not NULL
209 WXDWORD MSWGetCreateWindowFlags(WXDWORD *exflags = NULL) const
210 { return MSWGetStyle(GetWindowStyle(), exflags); }
211
212 // translate wxWidgets coords into Windows ones suitable to be passed to
213 // ::CreateWindow()
214 //
215 // returns true if non default coords are returned, false otherwise
216 bool MSWGetCreateWindowCoords(const wxPoint& pos,
217 const wxSize& size,
218 int& x, int& y,
219 int& w, int& h) const;
220
221 // get the HWND to be used as parent of this window with CreateWindow()
222 virtual WXHWND MSWGetParent() const;
223
224 // creates the window of specified Windows class with given style, extended
225 // style, title and geometry (default values
226 //
227 // returns true if the window has been created, false if creation failed
228 bool MSWCreate(const wxChar *wclass,
229 const wxChar *title = NULL,
230 const wxPoint& pos = wxDefaultPosition,
231 const wxSize& size = wxDefaultSize,
232 WXDWORD style = 0,
233 WXDWORD exendedStyle = 0);
234
235 virtual bool MSWCommand(WXUINT param, WXWORD id);
236
237 #ifndef __WXUNIVERSAL__
238 // Create an appropriate wxWindow from a HWND
239 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
240
241 // Make sure the window style reflects the HWND style (roughly)
242 virtual void AdoptAttributesFromHWND();
243 #endif // __WXUNIVERSAL__
244
245 // Setup background and foreground colours correctly
246 virtual void SetupColours();
247
248 // ------------------------------------------------------------------------
249 // helpers for message handlers: these perform the same function as the
250 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
251 // the correct parameters
252 // ------------------------------------------------------------------------
253
254 void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
255 WXWORD *id, WXHWND *hwnd, WXWORD *cmd);
256 void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
257 WXWORD *state, WXWORD *minimized, WXHWND *hwnd);
258 void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
259 WXWORD *code, WXWORD *pos, WXHWND *hwnd);
260 void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
261 WXHDC *hdc, WXHWND *hwnd);
262 void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
263 WXWORD *item, WXWORD *flags, WXHMENU *hmenu);
264
265 // ------------------------------------------------------------------------
266 // internal handlers for MSW messages: all handlers return a boolean value:
267 // true means that the handler processed the event and false that it didn't
268 // ------------------------------------------------------------------------
269
270 // there are several cases where we have virtual functions for Windows
271 // message processing: this is because these messages often require to be
272 // processed in a different manner in the derived classes. For all other
273 // messages, however, we do *not* have corresponding MSWOnXXX() function
274 // and if the derived class wants to process them, it should override
275 // MSWWindowProc() directly.
276
277 // scroll event (both horizontal and vertical)
278 virtual bool MSWOnScroll(int orientation, WXWORD nSBCode,
279 WXWORD pos, WXHWND control);
280
281 // child control notifications
282 #ifdef __WIN95__
283 virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
284 #endif // __WIN95__
285
286 // owner-drawn controls need to process these messages
287 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
288 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
289
290 // the rest are not virtual
291 bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate);
292 bool HandleInitDialog(WXHWND hWndFocus);
293 bool HandleDestroy();
294
295 bool HandlePaint();
296 bool HandlePrintClient(WXHDC hDC);
297 bool HandleEraseBkgnd(WXHDC hDC);
298
299 bool HandleMinimize();
300 bool HandleMaximize();
301 bool HandleSize(int x, int y, WXUINT flag);
302 bool HandleSizing(wxRect& rect);
303 bool HandleGetMinMaxInfo(void *mmInfo);
304
305 bool HandleShow(bool show, int status);
306 bool HandleActivate(int flag, bool minimized, WXHWND activate);
307
308 bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control);
309
310 bool HandleCtlColor(WXHBRUSH *hBrush, WXHDC hdc, WXHWND hWnd);
311
312 bool HandlePaletteChanged(WXHWND hWndPalChange);
313 bool HandleQueryNewPalette();
314 bool HandleSysColorChange();
315 bool HandleDisplayChange();
316 bool HandleCaptureChanged(WXHWND gainedCapture);
317
318 bool HandleQueryEndSession(long logOff, bool *mayEnd);
319 bool HandleEndSession(bool endSession, long logOff);
320
321 bool HandleSetFocus(WXHWND wnd);
322 bool HandleKillFocus(WXHWND wnd);
323
324 bool HandleDropFiles(WXWPARAM wParam);
325
326 bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
327 bool HandleMouseMove(int x, int y, WXUINT flags);
328 bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
329
330 bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false);
331 bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
332 bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
333 #if wxUSE_ACCEL
334 bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam);
335 #endif
336 #ifdef __WIN32__
337 int HandleMenuChar(int chAccel, WXLPARAM lParam);
338 #endif
339
340 bool HandleQueryDragIcon(WXHICON *hIcon);
341
342 bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg);
343
344 // Window procedure
345 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
346
347 // Calls an appropriate default window procedure
348 virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
349
350 // message processing helpers
351
352 // return false if the message shouldn't be translated/preprocessed but
353 // dispatched normally
354 virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg);
355
356 // return true if the message was preprocessed and shouldn't be dispatched
357 virtual bool MSWProcessMessage(WXMSG* pMsg);
358
359 // return true if the message was translated and shouldn't be dispatched
360 virtual bool MSWTranslateMessage(WXMSG* pMsg);
361
362 // called when the window is about to be destroyed
363 virtual void MSWDestroyWindow();
364
365
366 // this function should return the brush to paint the children controls
367 // background or 0 if this window doesn't impose any particular background
368 // on its children
369 //
370 // the base class version returns a solid brush if we have a non default
371 // background colour or 0 otherwise
372 virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, WXHWND hWnd);
373
374 // return the background brush to use for painting the given window by
375 // quering the parent windows via their MSWGetBgBrushForChild() recursively
376 //
377 // hWndToPaint is normally NULL meaning this window itself, but it can also
378 // be a child of this window which is used by the static box and could be
379 // potentially useful for other transparent controls
380 WXHBRUSH MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint = NULL);
381
382 // gives the parent the possibility to draw its children background, e.g.
383 // this is used by wxNotebook to do it using DrawThemeBackground()
384 //
385 // return true if background was drawn, false otherwise
386 virtual bool MSWPrintChild(WXHDC WXUNUSED(hDC), wxWindow * WXUNUSED(child))
387 {
388 return false;
389 }
390
391
392 // Responds to colour changes: passes event on to children.
393 void OnSysColourChanged(wxSysColourChangedEvent& event);
394
395 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
396 void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags);
397
398 // check if mouse is in the window
399 bool IsMouseInWindow() const;
400
401 // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false
402 void GenerateMouseLeave();
403
404 // virtual function for implementing internal idle
405 // behaviour
406 virtual void OnInternalIdle();
407
408 protected:
409 // the window handle
410 WXHWND m_hWnd;
411
412 // the old window proc (we subclass all windows)
413 WXFARPROC m_oldWndProc;
414
415 // additional (MSW specific) flags
416 bool m_mouseInWindow:1;
417 bool m_lastKeydownProcessed:1;
418
419 // the size of one page for scrolling
420 int m_xThumbSize;
421 int m_yThumbSize;
422
423 #if wxUSE_MOUSEEVENT_HACK
424 // the coordinates of the last mouse event and the type of it
425 long m_lastMouseX,
426 m_lastMouseY;
427 int m_lastMouseEvent;
428 #endif // wxUSE_MOUSEEVENT_HACK
429
430 // implement the base class pure virtuals
431 virtual void DoClientToScreen( int *x, int *y ) const;
432 virtual void DoScreenToClient( int *x, int *y ) const;
433 virtual void DoGetPosition( int *x, int *y ) const;
434 virtual void DoGetSize( int *width, int *height ) const;
435 virtual void DoGetClientSize( int *width, int *height ) const;
436 virtual void DoSetSize(int x, int y,
437 int width, int height,
438 int sizeFlags = wxSIZE_AUTO);
439 virtual void DoSetClientSize(int width, int height);
440
441 virtual void DoCaptureMouse();
442 virtual void DoReleaseMouse();
443
444 // has the window been frozen by Freeze()?
445 bool IsFrozen() const { return m_frozenness > 0; }
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 private:
473 // common part of all ctors
474 void Init();
475
476 // the (non-virtual) handlers for the events
477 bool HandleMove(int x, int y);
478 bool HandleMoving(wxRect& rect);
479 bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags);
480
481 #ifdef __WIN95__
482 bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
483 #endif // __WIN95__
484
485 // list of disabled children before last call to our Disable()
486 wxWindowList *m_childrenDisabled;
487
488 // number of calls to Freeze() minus number of calls to Thaw()
489 unsigned int m_frozenness;
490
491 // current defer window position operation handle (may be NULL)
492 WXHANDLE m_hDWP;
493
494
495 DECLARE_DYNAMIC_CLASS(wxWindowMSW)
496 DECLARE_NO_COPY_CLASS(wxWindowMSW)
497 DECLARE_EVENT_TABLE()
498 };
499
500 // ----------------------------------------------------------------------------
501 // inline functions
502 // ----------------------------------------------------------------------------
503
504 #if WXWIN_COMPATIBILITY_2_4
505
506 inline bool wxWindowMSW::GetUseCtl3D() const { return false; }
507 inline bool wxWindowMSW::GetTransparentBackground() const { return false; }
508 inline void wxWindowMSW::SetTransparent(bool WXUNUSED(t)) { }
509
510 #endif // WXWIN_COMPATIBILITY_2_4
511
512 // ---------------------------------------------------------------------------
513 // global functions
514 // ---------------------------------------------------------------------------
515
516 // kbd code translation
517 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0);
518 WXDLLEXPORT WXWORD wxCharCodeWXToMSW(int id, bool *IsVirtual);
519
520 // window creation helper class: before creating a new HWND, instantiate an
521 // object of this class on stack - this allows to process the messages sent to
522 // the window even before CreateWindow() returns
523 class wxWindowCreationHook
524 {
525 public:
526 wxWindowCreationHook(wxWindowMSW *winBeingCreated);
527 ~wxWindowCreationHook();
528 };
529
530 // ----------------------------------------------------------------------------
531 // global objects
532 // ----------------------------------------------------------------------------
533
534 // notice that this hash must be defined after wxWindow declaration as it
535 // needs to "see" its dtor and not just forward declaration
536 #include "wx/hash.h"
537
538 // pseudo-template HWND <-> wxWindow hash table
539 #if WXWIN_COMPATIBILITY_2_4
540 WX_DECLARE_HASH(wxWindow, wxWindowList, wxWinHashTable);
541 #else
542 WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable);
543 #endif
544
545 extern wxWinHashTable *wxWinHandleHash;
546
547 #endif
548 // _WX_WINDOW_H_