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