]>
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
51 wxWindowMSW() { Init(); }
53 wxWindowMSW(wxWindow
*parent
,
55 const wxPoint
& pos
= wxDefaultPosition
,
56 const wxSize
& size
= wxDefaultSize
,
58 const wxString
& name
= wxPanelNameStr
)
61 Create(parent
, id
, pos
, size
, style
, name
);
64 virtual ~wxWindowMSW();
66 bool Create(wxWindow
*parent
,
68 const wxPoint
& pos
= wxDefaultPosition
,
69 const wxSize
& size
= wxDefaultSize
,
71 const wxString
& name
= wxPanelNameStr
);
73 // implement base class pure virtuals
74 virtual void SetTitle( const wxString
& title
);
75 virtual wxString
GetTitle() const;
80 virtual bool Show( bool show
= true );
81 virtual bool Enable( bool enable
= true );
83 virtual void SetFocus();
84 virtual void SetFocusFromKbd();
86 virtual bool Reparent(wxWindowBase
*newParent
);
88 virtual void WarpPointer(int x
, int y
);
90 virtual void Refresh( bool eraseBackground
= true,
91 const wxRect
*rect
= (const wxRect
*) NULL
);
92 virtual void Update();
93 virtual void Freeze();
96 virtual void SetWindowStyleFlag( long style
);
97 virtual bool SetCursor( const wxCursor
&cursor
);
98 virtual bool SetFont( const wxFont
&font
);
100 virtual int GetCharHeight() const;
101 virtual int GetCharWidth() const;
102 virtual void GetTextExtent(const wxString
& string
,
104 int *descent
= (int *) NULL
,
105 int *externalLeading
= (int *) NULL
,
106 const wxFont
*theFont
= (const wxFont
*) NULL
)
109 #if wxUSE_MENUS_NATIVE
110 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
111 #endif // wxUSE_MENUS_NATIVE
113 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
114 int range
, bool refresh
= true );
115 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= true );
116 virtual int GetScrollPos( int orient
) const;
117 virtual int GetScrollThumb( int orient
) const;
118 virtual int GetScrollRange( int orient
) const;
119 virtual void ScrollWindow( int dx
, int dy
,
120 const wxRect
* rect
= (wxRect
*) NULL
);
122 virtual bool ScrollLines(int lines
);
123 virtual bool ScrollPages(int pages
);
125 #if wxUSE_DRAG_AND_DROP
126 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
127 #endif // wxUSE_DRAG_AND_DROP
129 // Accept files for dragging
130 virtual void DragAcceptFiles(bool accept
);
132 #if WXWIN_COMPATIBILITY_2_4
133 wxDEPRECATED( bool GetUseCtl3D() const );
134 wxDEPRECATED( bool GetTransparentBackground() const );
135 wxDEPRECATED( void SetTransparent(bool t
= true) );
136 #endif // WXWIN_COMPATIBILITY_2_4
138 #ifndef __WXUNIVERSAL__
139 // Native resource loading (implemented in src/msw/nativdlg.cpp)
140 // FIXME: should they really be all virtual?
141 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
142 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
143 wxWindow
* GetWindowChild1(wxWindowID id
);
144 wxWindow
* GetWindowChild(wxWindowID id
);
145 #endif // __WXUNIVERSAL__
148 // install and deinstall a system wide hotkey
149 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
150 virtual bool UnregisterHotKey(int hotkeyId
);
151 #endif // wxUSE_HOTKEY
153 // window handle stuff
154 // -------------------
156 WXHWND
GetHWND() const { return m_hWnd
; }
157 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
158 virtual WXWidget
GetHandle() const { return GetHWND(); }
160 void AssociateHandle(WXWidget handle
);
161 void DissociateHandle();
164 // implementation from now on
165 // ==========================
170 void OnPaint(wxPaintEvent
& event
);
171 void OnEraseBackground(wxEraseEvent
& event
);
173 void OnInitDialog(wxInitDialogEvent
& event
);
177 // For implementation purposes - sometimes decorations make the client area
179 virtual wxPoint
GetClientAreaOrigin() const;
181 // Windows subclassing
182 void SubclassWin(WXHWND hWnd
);
183 void UnsubclassWin();
185 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
186 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
188 // return true if the window is of a standard (i.e. not wxWidgets') class
190 // to understand why does it work, look at SubclassWin() code and comments
191 bool IsOfStandardClass() const { return m_oldWndProc
!= NULL
; }
193 wxWindow
*FindItem(long id
) const;
194 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
196 // MSW only: true if this control is part of the main control
197 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; };
199 // translate wxWidgets style flags for this control into the Windows style
200 // and optional extended style for the corresponding native control
202 // this is the function that should be overridden in the derived classes,
203 // but you will mostly use MSWGetCreateWindowFlags() below
204 virtual WXDWORD
MSWGetStyle(long flags
, WXDWORD
*exstyle
= NULL
) const ;
206 // get the MSW window flags corresponding to wxWidgets ones
208 // the functions returns the flags (WS_XXX) directly and puts the ext
209 // (WS_EX_XXX) flags into the provided pointer if not NULL
210 WXDWORD
MSWGetCreateWindowFlags(WXDWORD
*exflags
= NULL
) const
211 { return MSWGetStyle(GetWindowStyle(), exflags
); }
213 // translate wxWidgets coords into Windows ones suitable to be passed to
216 // returns true if non default coords are returned, false otherwise
217 bool MSWGetCreateWindowCoords(const wxPoint
& pos
,
220 int& w
, int& h
) const;
222 // get the HWND to be used as parent of this window with CreateWindow()
223 virtual WXHWND
MSWGetParent() const;
225 // creates the window of specified Windows class with given style, extended
226 // style, title and geometry (default values
228 // returns true if the window has been created, false if creation failed
229 bool MSWCreate(const wxChar
*wclass
,
230 const wxChar
*title
= NULL
,
231 const wxPoint
& pos
= wxDefaultPosition
,
232 const wxSize
& size
= wxDefaultSize
,
234 WXDWORD exendedStyle
= 0);
236 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
238 #ifndef __WXUNIVERSAL__
239 // Create an appropriate wxWindow from a HWND
240 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
242 // Make sure the window style reflects the HWND style (roughly)
243 virtual void AdoptAttributesFromHWND();
244 #endif // __WXUNIVERSAL__
246 // Setup background and foreground colours correctly
247 virtual void SetupColours();
249 // ------------------------------------------------------------------------
250 // helpers for message handlers: these perform the same function as the
251 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
252 // the correct parameters
253 // ------------------------------------------------------------------------
255 void UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
256 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
257 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
258 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
259 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
260 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
261 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
262 WXHDC
*hdc
, WXHWND
*hwnd
);
263 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
264 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
266 // ------------------------------------------------------------------------
267 // internal handlers for MSW messages: all handlers return a boolean value:
268 // true means that the handler processed the event and false that it didn't
269 // ------------------------------------------------------------------------
271 // there are several cases where we have virtual functions for Windows
272 // message processing: this is because these messages often require to be
273 // processed in a different manner in the derived classes. For all other
274 // messages, however, we do *not* have corresponding MSWOnXXX() function
275 // and if the derived class wants to process them, it should override
276 // MSWWindowProc() directly.
278 // scroll event (both horizontal and vertical)
279 virtual bool MSWOnScroll(int orientation
, WXWORD nSBCode
,
280 WXWORD pos
, WXHWND control
);
282 // child control notifications
284 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
287 // owner-drawn controls need to process these messages
288 virtual bool MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
289 virtual bool MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
291 // the rest are not virtual
292 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
293 bool HandleInitDialog(WXHWND hWndFocus
);
294 bool HandleDestroy();
297 bool HandleEraseBkgnd(WXHDC pDC
);
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();
365 // this function should return the brush to paint the window background
366 // with or 0 for the default brush
367 virtual WXHBRUSH
MSWControlColor(WXHDC hDC
);
369 // this function should return the brush to paint the children controls
370 // background or 0 if this window doesn't impose any particular background
373 // the base class version uses MSWGetBgColourForChild() and returns a solid
374 // brush if we have a non default background colour or 0 otherwise
375 virtual WXHBRUSH
MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), wxWindow
*child
)
377 return MSWGetSolidBgBrushForChild(child
);
380 // return the background colour of this window under the given child
381 // (possible grand child)
383 // this is a hack as if the background is themed, there is no single colour
384 // representing it, but sometimes we can't use the pattern brush returned
385 // by MSWGetBgBrushForChild() anyhow and then this function is used as
388 // the base class version returns bg colour if it had been explicitely set
389 // or wxNullColour otherwise
390 virtual wxColour
MSWGetBgColourForChild(wxWindow
*child
);
392 // convenience function: returns a solid brush of the colour returned by
393 // MSWGetBgColourForChild() or 0
394 WXHBRUSH
MSWGetSolidBgBrushForChild(wxWindow
*child
);
396 // normally just calls MSWGetBgBrushForChild() on the parent window but may
397 // be overridden if the default background brush is not suitable for some
398 // reason (e.g. wxStaticBox uses MSWGetSolidBgBrushForChild() instead)
399 virtual WXHBRUSH
MSWGetBgBrushForSelf(wxWindow
*parent
, WXHDC hDC
);
401 // return the background brush to use for this window by quering the parent
402 // windows via their MSWGetBgBrushForChild() recursively
403 WXHBRUSH
MSWGetBgBrush(WXHDC hDC
);
405 // Responds to colour changes: passes event on to children.
406 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
408 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
409 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
411 // check if mouse is in the window
412 bool IsMouseInWindow() const;
414 // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false
415 void GenerateMouseLeave();
417 // virtual function for implementing internal idle
419 virtual void OnInternalIdle() ;
425 // the old window proc (we subclass all windows)
426 WXFARPROC m_oldWndProc
;
428 // additional (MSW specific) flags
429 bool m_mouseInWindow
:1;
430 bool m_lastKeydownProcessed
:1;
432 // the size of one page for scrolling
436 #if wxUSE_MOUSEEVENT_HACK
437 // the coordinates of the last mouse event and the type of it
440 int m_lastMouseEvent
;
441 #endif // wxUSE_MOUSEEVENT_HACK
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
);
454 virtual void DoCaptureMouse();
455 virtual void DoReleaseMouse();
457 // has the window been frozen by Freeze()?
458 bool IsFrozen() const { return m_frozenness
> 0; }
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
);
467 virtual void DoSetToolTip( wxToolTip
*tip
);
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
,
473 const wxString
& ttip
);
474 #endif // wxUSE_TOOLTIPS
476 // the helper functions used by HandleChar/KeyXXX methods
477 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
,
478 WXLPARAM lParam
= 0, WXWPARAM wParam
= 0) const;
481 // default OnEraseBackground() implementation, return true if we did erase
482 // the background, false otherwise
483 bool DoEraseBackground(wxDC
& dc
);
486 // common part of all ctors
489 // the (non-virtual) handlers for the events
490 bool HandleMove(int x
, int y
);
491 bool HandleMoving(wxRect
& rect
);
492 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
495 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
498 // list of disabled children before last call to our Disable()
499 wxWindowList
*m_childrenDisabled
;
501 // number of calls to Freeze() minus number of calls to Thaw()
502 unsigned int m_frozenness
;
504 // current defer window position operation handle (may be NULL)
508 DECLARE_DYNAMIC_CLASS(wxWindowMSW
)
509 DECLARE_NO_COPY_CLASS(wxWindowMSW
)
510 DECLARE_EVENT_TABLE()
513 // ----------------------------------------------------------------------------
515 // ----------------------------------------------------------------------------
517 #if WXWIN_COMPATIBILITY_2_4
519 inline bool wxWindowMSW::GetUseCtl3D() const { return false; }
520 inline bool wxWindowMSW::GetTransparentBackground() const { return false; }
521 inline void wxWindowMSW::SetTransparent(bool WXUNUSED(t
)) { }
523 #endif // WXWIN_COMPATIBILITY_2_4
525 // ---------------------------------------------------------------------------
527 // ---------------------------------------------------------------------------
529 // kbd code translation
530 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
, WXLPARAM lParam
= 0);
531 WXDLLEXPORT WXWORD
wxCharCodeWXToMSW(int id
, bool *IsVirtual
);
533 // window creation helper class: before creating a new HWND, instantiate an
534 // object of this class on stack - this allows to process the messages sent to
535 // the window even before CreateWindow() returns
536 class wxWindowCreationHook
539 wxWindowCreationHook(wxWindowMSW
*winBeingCreated
);
540 ~wxWindowCreationHook();
543 // ----------------------------------------------------------------------------
545 // ----------------------------------------------------------------------------
547 // notice that this hash must be defined after wxWindow declaration as it
548 // needs to "see" its dtor and not just forward declaration
551 // pseudo-template HWND <-> wxWindow hash table
552 #if WXWIN_COMPATIBILITY_2_4
553 WX_DECLARE_HASH(wxWindow
, wxWindowList
, wxWinHashTable
);
555 WX_DECLARE_HASH(wxWindowMSW
, wxWindowList
, wxWinHashTable
);
558 extern wxWinHashTable
*wxWinHandleHash
;