]>
git.saurik.com Git - wxWidgets.git/blob - 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(), ...
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma interface "window.h"
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
28 // a better solution should be found later...
29 #define wxUSE_MOUSEEVENT_HACK 0
31 // ---------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------
35 #if WXWIN_COMPATIBILITY_2_4
36 // they're unused by wxWidgets...
44 // ---------------------------------------------------------------------------
45 // wxWindow declaration for MSW
46 // ---------------------------------------------------------------------------
48 class WXDLLEXPORT wxWindowMSW
: public wxWindowBase
50 friend class wxSpinCtrl
;
51 friend class wxSlider
;
52 friend class wxRadioBox
;
54 wxWindowMSW() { Init(); }
56 wxWindowMSW(wxWindow
*parent
,
58 const wxPoint
& pos
= wxDefaultPosition
,
59 const wxSize
& size
= wxDefaultSize
,
61 const wxString
& name
= wxPanelNameStr
)
64 Create(parent
, id
, pos
, size
, style
, name
);
67 virtual ~wxWindowMSW();
69 bool Create(wxWindow
*parent
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxString
& name
= wxPanelNameStr
);
76 // implement base class pure virtuals
77 virtual void SetTitle( const wxString
& title
);
78 virtual wxString
GetTitle() const;
83 virtual bool Show( bool show
= true );
84 virtual bool Enable( bool enable
= true );
86 virtual void SetFocus();
87 virtual void SetFocusFromKbd();
89 virtual bool Reparent(wxWindowBase
*newParent
);
91 virtual void WarpPointer(int x
, int y
);
93 virtual void Refresh( bool eraseBackground
= true,
94 const wxRect
*rect
= (const wxRect
*) NULL
);
95 virtual void Update();
96 virtual void Freeze();
99 virtual void SetWindowStyleFlag( long style
);
100 virtual bool SetCursor( const wxCursor
&cursor
);
101 virtual bool SetFont( const wxFont
&font
);
103 virtual int GetCharHeight() const;
104 virtual int GetCharWidth() const;
105 virtual void GetTextExtent(const wxString
& string
,
107 int *descent
= (int *) NULL
,
108 int *externalLeading
= (int *) NULL
,
109 const wxFont
*theFont
= (const wxFont
*) NULL
)
112 #if wxUSE_MENUS_NATIVE
113 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
114 #endif // wxUSE_MENUS_NATIVE
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
);
125 virtual bool ScrollLines(int lines
);
126 virtual bool ScrollPages(int pages
);
128 #if wxUSE_DRAG_AND_DROP
129 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
130 #endif // wxUSE_DRAG_AND_DROP
132 // Accept files for dragging
133 virtual void DragAcceptFiles(bool accept
);
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
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__
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
156 // window handle stuff
157 // -------------------
159 WXHWND
GetHWND() const { return m_hWnd
; }
160 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
161 virtual WXWidget
GetHandle() const { return GetHWND(); }
163 void AssociateHandle(WXWidget handle
);
164 void DissociateHandle();
167 // implementation from now on
168 // ==========================
173 void OnPaint(wxPaintEvent
& event
);
174 void OnEraseBackground(wxEraseEvent
& event
);
176 void OnInitDialog(wxInitDialogEvent
& event
);
180 // Windows subclassing
181 void SubclassWin(WXHWND hWnd
);
182 void UnsubclassWin();
184 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
185 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
187 // return true if the window is of a standard (i.e. not wxWidgets') class
189 // to understand why does it work, look at SubclassWin() code and comments
190 bool IsOfStandardClass() const { return m_oldWndProc
!= NULL
; }
192 wxWindow
*FindItem(long id
) const;
193 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
195 // MSW only: true if this control is part of the main control
196 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; };
198 // translate wxWidgets style flags for this control into the Windows style
199 // and optional extended style for the corresponding native control
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 ;
205 // get the MSW window flags corresponding to wxWidgets ones
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
); }
212 // translate wxWidgets coords into Windows ones suitable to be passed to
215 // returns true if non default coords are returned, false otherwise
216 bool MSWGetCreateWindowCoords(const wxPoint
& pos
,
219 int& w
, int& h
) const;
221 // get the HWND to be used as parent of this window with CreateWindow()
222 virtual WXHWND
MSWGetParent() const;
224 // creates the window of specified Windows class with given style, extended
225 // style, title and geometry (default values
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
,
233 WXDWORD exendedStyle
= 0);
235 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
237 #ifndef __WXUNIVERSAL__
238 // Create an appropriate wxWindow from a HWND
239 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
241 // Make sure the window style reflects the HWND style (roughly)
242 virtual void AdoptAttributesFromHWND();
243 #endif // __WXUNIVERSAL__
245 // Setup background and foreground colours correctly
246 virtual void SetupColours();
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 // ------------------------------------------------------------------------
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
);
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 // ------------------------------------------------------------------------
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.
277 // scroll event (both horizontal and vertical)
278 virtual bool MSWOnScroll(int orientation
, WXWORD nSBCode
,
279 WXWORD pos
, WXHWND control
);
281 // child control notifications
283 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
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
);
290 // the rest are not virtual
291 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
292 bool HandleInitDialog(WXHWND hWndFocus
);
293 bool HandleDestroy();
296 bool HandlePrintClient(WXHDC hDC
);
297 bool HandleEraseBkgnd(WXHDC hDC
);
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
);
305 bool HandleShow(bool show
, int status
);
306 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
308 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
310 bool HandleCtlColor(WXHBRUSH
*hBrush
, WXHDC hdc
, WXHWND hWnd
);
312 bool HandlePaletteChanged(WXHWND hWndPalChange
);
313 bool HandleQueryNewPalette();
314 bool HandleSysColorChange();
315 bool HandleDisplayChange();
316 bool HandleCaptureChanged(WXHWND gainedCapture
);
318 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
319 bool HandleEndSession(bool endSession
, long logOff
);
321 bool HandleSetFocus(WXHWND wnd
);
322 bool HandleKillFocus(WXHWND wnd
);
324 bool HandleDropFiles(WXWPARAM wParam
);
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
);
330 bool HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
= false);
331 bool HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
);
332 bool HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
);
334 bool HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
);
337 int HandleMenuChar(int chAccel
, WXLPARAM lParam
);
340 bool HandleQueryDragIcon(WXHICON
*hIcon
);
342 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
345 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
347 // Calls an appropriate default window procedure
348 virtual WXLRESULT
MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
350 // message processing helpers
352 // return false if the message shouldn't be translated/preprocessed but
353 // dispatched normally
354 virtual bool MSWShouldPreProcessMessage(WXMSG
* pMsg
);
356 // return true if the message was preprocessed and shouldn't be dispatched
357 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
359 // return true if the message was translated and shouldn't be dispatched
360 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
362 // called when the window is about to be destroyed
363 virtual void MSWDestroyWindow();
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
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
);
374 // return the background brush to use for painting the given window by
375 // quering the parent windows via their MSWGetBgBrushForChild() recursively
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
);
382 // gives the parent the possibility to draw its children background, e.g.
383 // this is used by wxNotebook to do it using DrawThemeBackground()
385 // return true if background was drawn, false otherwise
386 virtual bool MSWPrintChild(WXHDC
WXUNUSED(hDC
), wxWindow
* WXUNUSED(child
))
392 // Responds to colour changes: passes event on to children.
393 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
395 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
396 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
398 // check if mouse is in the window
399 bool IsMouseInWindow() const;
401 // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false
402 void GenerateMouseLeave();
404 // virtual function for implementing internal idle
406 virtual void OnInternalIdle();
412 // the old window proc (we subclass all windows)
413 WXFARPROC m_oldWndProc
;
415 // additional (MSW specific) flags
416 bool m_mouseInWindow
:1;
417 bool m_lastKeydownProcessed
:1;
419 // the size of one page for scrolling
423 #if wxUSE_MOUSEEVENT_HACK
424 // the coordinates of the last mouse event and the type of it
427 int m_lastMouseEvent
;
428 #endif // wxUSE_MOUSEEVENT_HACK
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
);
441 virtual void DoCaptureMouse();
442 virtual void DoReleaseMouse();
444 // has the window been frozen by Freeze()?
445 bool IsFrozen() const { return m_frozenness
> 0; }
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
);
454 virtual void DoSetToolTip( wxToolTip
*tip
);
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
,
460 const wxString
& ttip
);
461 #endif // wxUSE_TOOLTIPS
463 // the helper functions used by HandleChar/KeyXXX methods
464 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
,
465 WXLPARAM lParam
= 0, WXWPARAM wParam
= 0) const;
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
);
473 // common part of all ctors
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
);
482 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
485 // list of disabled children before last call to our Disable()
486 wxWindowList
*m_childrenDisabled
;
488 // number of calls to Freeze() minus number of calls to Thaw()
489 unsigned int m_frozenness
;
491 // current defer window position operation handle (may be NULL)
495 DECLARE_DYNAMIC_CLASS(wxWindowMSW
)
496 DECLARE_NO_COPY_CLASS(wxWindowMSW
)
497 DECLARE_EVENT_TABLE()
500 // ----------------------------------------------------------------------------
502 // ----------------------------------------------------------------------------
504 #if WXWIN_COMPATIBILITY_2_4
506 inline bool wxWindowMSW::GetUseCtl3D() const { return false; }
507 inline bool wxWindowMSW::GetTransparentBackground() const { return false; }
508 inline void wxWindowMSW::SetTransparent(bool WXUNUSED(t
)) { }
510 #endif // WXWIN_COMPATIBILITY_2_4
512 // ---------------------------------------------------------------------------
514 // ---------------------------------------------------------------------------
516 // kbd code translation
517 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
, WXLPARAM lParam
= 0);
518 WXDLLEXPORT WXWORD
wxCharCodeWXToMSW(int id
, bool *IsVirtual
);
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
526 wxWindowCreationHook(wxWindowMSW
*winBeingCreated
);
527 ~wxWindowCreationHook();
530 // ----------------------------------------------------------------------------
532 // ----------------------------------------------------------------------------
534 // notice that this hash must be defined after wxWindow declaration as it
535 // needs to "see" its dtor and not just forward declaration
538 // pseudo-template HWND <-> wxWindow hash table
539 #if WXWIN_COMPATIBILITY_2_4
540 WX_DECLARE_HASH(wxWindow
, wxWindowList
, wxWinHashTable
);
542 WX_DECLARE_HASH(wxWindowMSW
, wxWindowList
, wxWinHashTable
);
545 extern wxWinHashTable
*wxWinHandleHash
;