]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
d266161df162eab6357153fd74c02f8b5214fc7d
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"
25 #include "wx/msw/wrapwin.h"
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
31 // a better solution should be found later...
32 #define wxUSE_MOUSEEVENT_HACK 0
34 // ---------------------------------------------------------------------------
36 // ---------------------------------------------------------------------------
38 #if WXWIN_COMPATIBILITY_2_4
39 // they're unused by wxWidgets...
47 // ---------------------------------------------------------------------------
48 // wxWindow declaration for MSW
49 // ---------------------------------------------------------------------------
51 class WXDLLEXPORT wxWindowMSW
: public wxWindowBase
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 // For implementation purposes - sometimes decorations make the client area
182 virtual wxPoint
GetClientAreaOrigin() const;
184 // Windows subclassing
185 void SubclassWin(WXHWND hWnd
);
186 void UnsubclassWin();
188 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
189 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
191 // return true if the window is of a standard (i.e. not wxWidgets') class
193 // to understand why does it work, look at SubclassWin() code and comments
194 bool IsOfStandardClass() const { return m_oldWndProc
!= NULL
; }
196 wxWindow
*FindItem(long id
) const;
197 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= false) const;
199 // MSW only: true if this control is part of the main control
200 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return false; };
202 // translate wxWidgets style flags for this control into the Windows style
203 // and optional extended style for the corresponding native control
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 ;
209 // get the MSW window flags corresponding to wxWidgets ones
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
); }
216 // translate wxWidgets coords into Windows ones suitable to be passed to
219 // returns true if non default coords are returned, false otherwise
220 bool MSWGetCreateWindowCoords(const wxPoint
& pos
,
223 int& w
, int& h
) const;
225 // get the HWND to be used as parent of this window with CreateWindow()
226 virtual WXHWND
MSWGetParent() const;
228 // creates the window of specified Windows class with given style, extended
229 // style, title and geometry (default values
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
,
237 WXDWORD exendedStyle
= 0);
239 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
241 #ifndef __WXUNIVERSAL__
242 // Create an appropriate wxWindow from a HWND
243 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
245 // Make sure the window style reflects the HWND style (roughly)
246 virtual void AdoptAttributesFromHWND();
247 #endif // __WXUNIVERSAL__
249 // Setup background and foreground colours correctly
250 virtual void SetupColours();
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 // ------------------------------------------------------------------------
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
);
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 // ------------------------------------------------------------------------
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.
281 // scroll event (both horizontal and vertical)
282 virtual bool MSWOnScroll(int orientation
, WXWORD nSBCode
,
283 WXWORD pos
, WXHWND control
);
285 // child control notifications
287 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
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
);
294 // the rest are not virtual
295 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
296 bool HandleInitDialog(WXHWND hWndFocus
);
297 bool HandleDestroy();
300 bool HandleEraseBkgnd(WXHDC pDC
);
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
);
308 bool HandleShow(bool show
, int status
);
309 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
311 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
313 bool HandleCtlColor(WXHBRUSH
*hBrush
, WXHDC hdc
, WXHWND hWnd
);
315 bool HandlePaletteChanged(WXHWND hWndPalChange
);
316 bool HandleQueryNewPalette();
317 bool HandleSysColorChange();
318 bool HandleDisplayChange();
319 bool HandleCaptureChanged(WXHWND gainedCapture
);
321 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
322 bool HandleEndSession(bool endSession
, long logOff
);
324 bool HandleSetFocus(WXHWND wnd
);
325 bool HandleKillFocus(WXHWND wnd
);
327 bool HandleDropFiles(WXWPARAM wParam
);
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
);
333 bool HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
= false);
334 bool HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
);
335 bool HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
);
337 bool HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
);
340 int HandleMenuChar(int chAccel
, WXLPARAM lParam
);
343 bool HandleQueryDragIcon(WXHICON
*hIcon
);
345 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
348 virtual WXLRESULT
MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
350 // Calls an appropriate default window procedure
351 virtual WXLRESULT
MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
353 // message processing helpers
355 // return false if the message shouldn't be translated/preprocessed but
356 // dispatched normally
357 virtual bool MSWShouldPreProcessMessage(WXMSG
* pMsg
);
359 // return true if the message was preprocessed and shouldn't be dispatched
360 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
362 // return true if the message was translated and shouldn't be dispatched
363 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
365 // called when the window is about to be destroyed
366 virtual void MSWDestroyWindow();
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
);
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
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
)
380 return MSWGetSolidBgBrushForChild(child
);
383 // return the background colour of this window under the given child
384 // (possible grand child)
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
391 // the base class version returns bg colour if it had been explicitely set
392 // or wxNullColour otherwise
393 virtual wxColour
MSWGetBgColourForChild(wxWindow
*child
);
395 // convenience function: returns a solid brush of the colour returned by
396 // MSWGetBgColourForChild() or 0
397 WXHBRUSH
MSWGetSolidBgBrushForChild(wxWindow
*child
);
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
);
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
);
408 // Responds to colour changes: passes event on to children.
409 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
411 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
412 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
414 // check if mouse is in the window
415 bool IsMouseInWindow() const;
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 // common part of all ctors
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
);
490 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
493 // list of disabled children before last call to our Disable()
494 wxWindowList
*m_childrenDisabled
;
496 // number of calls to Freeze() minus number of calls to Thaw()
497 unsigned int m_frozenness
;
499 // current defer window position operation handle (may be NULL)
503 DECLARE_DYNAMIC_CLASS(wxWindowMSW
)
504 DECLARE_NO_COPY_CLASS(wxWindowMSW
)
505 DECLARE_EVENT_TABLE()
508 // ----------------------------------------------------------------------------
510 // ----------------------------------------------------------------------------
512 #if WXWIN_COMPATIBILITY_2_4
514 inline bool wxWindowMSW::GetUseCtl3D() const { return false; }
515 inline bool wxWindowMSW::GetTransparentBackground() const { return false; }
516 inline void wxWindowMSW::SetTransparent(bool WXUNUSED(t
)) { }
518 #endif // WXWIN_COMPATIBILITY_2_4
520 // ---------------------------------------------------------------------------
522 // ---------------------------------------------------------------------------
524 // kbd code translation
525 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
, WXLPARAM lParam
= 0);
526 WXDLLEXPORT WXWORD
wxCharCodeWXToMSW(int id
, bool *IsVirtual
);
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
534 wxWindowCreationHook(wxWindowMSW
*winBeingCreated
);
535 ~wxWindowCreationHook();
538 // ----------------------------------------------------------------------------
540 // ----------------------------------------------------------------------------
542 // notice that this hash must be defined after wxWindow declaration as it
543 // needs to "see" its dtor and not just forward declaration
546 // pseudo-template HWND <-> wxWindow hash table
547 #if WXWIN_COMPATIBILITY_2_4
548 WX_DECLARE_HASH(wxWindow
, wxWindowList
, wxWinHashTable
);
550 WX_DECLARE_HASH(wxWindowMSW
, wxWindowList
, wxWinHashTable
);
553 extern wxWinHashTable
*wxWinHandleHash
;