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 and Markus Holzem
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
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 // FIXME does anybody use those? they're unused by wxWindows...
42 // ---------------------------------------------------------------------------
43 // wxWindow declaration for MSW
44 // ---------------------------------------------------------------------------
46 class WXDLLEXPORT wxWindowMSW
: public wxWindowBase
49 wxWindowMSW() { Init(); }
51 wxWindowMSW(wxWindow
*parent
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
56 const wxString
& name
= wxPanelNameStr
)
59 Create(parent
, id
, pos
, size
, style
, name
);
62 virtual ~wxWindowMSW();
64 bool Create(wxWindow
*parent
,
66 const wxPoint
& pos
= wxDefaultPosition
,
67 const wxSize
& size
= wxDefaultSize
,
69 const wxString
& name
= wxPanelNameStr
);
71 // implement base class pure virtuals
72 virtual void SetTitle( const wxString
& title
);
73 virtual wxString
GetTitle() const;
78 virtual bool Show( bool show
= TRUE
);
79 virtual bool Enable( bool enable
= TRUE
);
81 virtual void SetFocus();
83 virtual bool Reparent(wxWindowBase
*newParent
);
85 virtual void WarpPointer(int x
, int y
);
86 virtual void CaptureMouse();
87 virtual void ReleaseMouse();
89 virtual void Refresh( bool eraseBackground
= TRUE
,
90 const wxRect
*rect
= (const wxRect
*) NULL
);
91 virtual void Update();
93 virtual void Freeze();
96 virtual bool SetCursor( const wxCursor
&cursor
);
97 virtual bool SetFont( const wxFont
&font
);
99 virtual int GetCharHeight() const;
100 virtual int GetCharWidth() const;
101 virtual void GetTextExtent(const wxString
& string
,
103 int *descent
= (int *) NULL
,
104 int *externalLeading
= (int *) NULL
,
105 const wxFont
*theFont
= (const wxFont
*) NULL
)
108 #if wxUSE_MENUS_NATIVE
109 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
110 #endif // wxUSE_MENUS_NATIVE
112 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
113 int range
, bool refresh
= TRUE
);
114 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
115 virtual int GetScrollPos( int orient
) const;
116 virtual int GetScrollThumb( int orient
) const;
117 virtual int GetScrollRange( int orient
) const;
118 virtual void ScrollWindow( int dx
, int dy
,
119 const wxRect
* rect
= (wxRect
*) NULL
);
121 #if wxUSE_DRAG_AND_DROP
122 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
123 #endif // wxUSE_DRAG_AND_DROP
125 // Accept files for dragging
126 virtual void DragAcceptFiles(bool accept
);
128 #if WXWIN_COMPATIBILITY
129 // Set/get scroll attributes
130 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
131 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
132 virtual int OldGetScrollRange(int orient
) const;
133 virtual int GetScrollPage(int orient
) const;
136 // Handle a control command
137 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
139 // Override to define new behaviour for default action (e.g. double
140 // clicking on a listbox)
141 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
142 #endif // WXWIN_COMPATIBILITY
144 #if wxUSE_CARET && WXWIN_COMPATIBILITY
145 // caret manipulation (old MSW only functions, see wxCaret class for the
147 void CreateCaret(int w
, int h
);
148 void CreateCaret(const wxBitmap
*bitmap
);
150 void ShowCaret(bool show
);
151 void SetCaretPos(int x
, int y
);
152 void GetCaretPos(int *x
, int *y
) const;
153 #endif // wxUSE_CARET
155 #ifndef __WXUNIVERSAL__
156 // Native resource loading (implemented in src/msw/nativdlg.cpp)
157 // FIXME: should they really be all virtual?
158 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
159 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
160 wxWindow
* GetWindowChild1(wxWindowID id
);
161 wxWindow
* GetWindowChild(wxWindowID id
);
162 #endif // __WXUNIVERSAL__
164 // a MSW only function which sends a size event to the window using its
165 // current size - this has an effect of refreshing the window layout
167 FUNCTION IS NOW A MEMBER OF wxFrame - gt
168 void SendSizeEvent();
171 // implementation from now on
172 // --------------------------
177 WXHWND
GetHWND() const { return m_hWnd
; }
178 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
179 virtual WXWidget
GetHandle() const { return GetHWND(); }
181 bool GetUseCtl3D() const { return m_useCtl3D
; }
182 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
183 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
188 void OnSetFocus(wxFocusEvent
& event
);
189 void OnEraseBackground(wxEraseEvent
& event
);
190 void OnIdle(wxIdleEvent
& event
);
191 void OnPaint(wxPaintEvent
& event
);
194 // For implementation purposes - sometimes decorations make the client area
196 virtual wxPoint
GetClientAreaOrigin() const;
198 // Makes an adjustment to the window position (for example, a frame that has
199 // a toolbar that it manages itself).
200 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
202 // Windows subclassing
203 void SubclassWin(WXHWND hWnd
);
204 void UnsubclassWin();
206 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
207 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
209 wxWindow
*FindItem(long id
) const;
210 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
212 // Make a Windows extended style from the given wxWindows window style
213 static WXDWORD
MakeExtendedStyle(long style
,
214 bool eliminateBorders
= FALSE
);
215 // Determine whether 3D effects are wanted
216 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
218 // MSW only: TRUE if this control is part of the main control
219 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
221 // returns TRUE if the window has been created
222 bool MSWCreate(int id
,
224 const wxChar
*wclass
,
227 int x
, int y
, int width
, int height
,
229 const wxChar
*dialog_template
= NULL
,
230 WXDWORD exendedStyle
= 0);
231 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
233 #if WXWIN_COMPATIBILITY
234 wxObject
*GetChild(int number
) const;
235 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
236 #endif // WXWIN_COMPATIBILITY
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 WXWORD
*nCtlColor
, 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 HandleGetMinMaxInfo(void *mmInfo
);
304 bool HandleShow(bool show
, int status
);
305 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
307 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
308 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
310 bool HandleCtlColor(WXHBRUSH
*hBrush
,
318 bool HandlePaletteChanged(WXHWND hWndPalChange
);
319 bool HandleQueryNewPalette();
320 bool HandleSysColorChange();
322 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
323 bool HandleEndSession(bool endSession
, long logOff
);
325 bool HandleSetFocus(WXHWND wnd
);
326 bool HandleKillFocus(WXHWND wnd
);
328 bool HandleDropFiles(WXWPARAM wParam
);
330 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
331 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
332 bool HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
);
334 bool HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
335 bool HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
);
336 bool HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
);
338 bool HandleQueryDragIcon(WXHICON
*hIcon
);
340 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
343 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
345 // Calls an appropriate default window procedure
346 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
347 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
348 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
349 virtual void MSWDestroyWindow();
351 // Detach "Window" menu from menu bar so it doesn't get deleted
352 void MSWDetachWindowMenu();
354 // this function should return the brush to paint the window background
355 // with or 0 for the default brush
356 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
363 #if WXWIN_COMPATIBILITY
364 void SetShowing(bool show
) { (void)Show(show
); }
365 bool IsUserEnabled() const { return IsEnabled(); }
366 #endif // WXWIN_COMPATIBILITY
368 // Responds to colour changes: passes event on to children.
369 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
371 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
372 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
374 // check if mouse is in the window
375 bool IsMouseInWindow() const;
381 // the old window proc (we subclass all windows)
382 WXFARPROC m_oldWndProc
;
384 // additional (MSW specific) flags
385 bool m_useCtl3D
:1; // Using CTL3D for this control
386 bool m_backgroundTransparent
:1;
387 bool m_mouseInWindow
:1;
388 bool m_doubleClickAllowed
:1;
390 // the size of one page for scrolling
394 #if wxUSE_MOUSEEVENT_HACK
395 // the coordinates of the last mouse event and the type of it
398 int m_lastMouseEvent
;
399 #endif // wxUSE_MOUSEEVENT_HACK
401 WXHMENU m_hMenu
; // Menu, if any
403 // the return value of WM_GETDLGCODE handler
406 // implement the base class pure virtuals
407 virtual void DoClientToScreen( int *x
, int *y
) const;
408 virtual void DoScreenToClient( int *x
, int *y
) const;
409 virtual void DoGetPosition( int *x
, int *y
) const;
410 virtual void DoGetSize( int *width
, int *height
) const;
411 virtual void DoGetClientSize( int *width
, int *height
) const;
412 virtual void DoSetSize(int x
, int y
,
413 int width
, int height
,
414 int sizeFlags
= wxSIZE_AUTO
);
415 virtual void DoSetClientSize(int width
, int height
);
417 // move the window to the specified location and resize it: this is called
418 // from both DoSetSize() and DoSetClientSize() and would usually just call
419 // ::MoveWindow() except for composite controls which will want to arrange
420 // themselves inside the given rectangle
421 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
424 virtual void DoSetToolTip( wxToolTip
*tip
);
425 #endif // wxUSE_TOOLTIPS
428 // common part of all ctors
431 // the (non-virtual) handlers for the events
432 bool HandleMove(int x
, int y
);
433 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
436 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
439 // the helper functions used by HandleChar/KeyXXX methods
440 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
442 DECLARE_DYNAMIC_CLASS(wxWindowMSW
);
443 DECLARE_NO_COPY_CLASS(wxWindowMSW
);
444 DECLARE_EVENT_TABLE()
447 // ---------------------------------------------------------------------------
449 // ---------------------------------------------------------------------------
451 // kbd code translation
452 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
453 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);