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 virtual bool ScrollLines(int lines
);
122 virtual bool ScrollPages(int pages
);
124 #if wxUSE_DRAG_AND_DROP
125 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
126 #endif // wxUSE_DRAG_AND_DROP
128 // Accept files for dragging
129 virtual void DragAcceptFiles(bool accept
);
131 #if WXWIN_COMPATIBILITY
132 // Set/get scroll attributes
133 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
134 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
135 virtual int OldGetScrollRange(int orient
) const;
136 virtual int GetScrollPage(int orient
) const;
139 // Handle a control command
140 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
142 // Override to define new behaviour for default action (e.g. double
143 // clicking on a listbox)
144 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
145 #endif // WXWIN_COMPATIBILITY
147 #if wxUSE_CARET && WXWIN_COMPATIBILITY
148 // caret manipulation (old MSW only functions, see wxCaret class for the
150 void CreateCaret(int w
, int h
);
151 void CreateCaret(const wxBitmap
*bitmap
);
153 void ShowCaret(bool show
);
154 void SetCaretPos(int x
, int y
);
155 void GetCaretPos(int *x
, int *y
) const;
156 #endif // wxUSE_CARET
158 #ifndef __WXUNIVERSAL__
159 // Native resource loading (implemented in src/msw/nativdlg.cpp)
160 // FIXME: should they really be all virtual?
161 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
162 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
163 wxWindow
* GetWindowChild1(wxWindowID id
);
164 wxWindow
* GetWindowChild(wxWindowID id
);
165 #endif // __WXUNIVERSAL__
167 // a MSW only function which sends a size event to the window using its
168 // current size - this has an effect of refreshing the window layout
170 FUNCTION IS NOW A MEMBER OF wxFrame - gt
171 void SendSizeEvent();
174 // implementation from now on
175 // --------------------------
180 WXHWND
GetHWND() const { return m_hWnd
; }
181 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
182 virtual WXWidget
GetHandle() const { return GetHWND(); }
184 bool GetUseCtl3D() const { return m_useCtl3D
; }
185 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
186 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
191 void OnSetFocus(wxFocusEvent
& event
);
192 void OnEraseBackground(wxEraseEvent
& event
);
193 void OnIdle(wxIdleEvent
& event
);
194 void OnPaint(wxPaintEvent
& event
);
197 // For implementation purposes - sometimes decorations make the client area
199 virtual wxPoint
GetClientAreaOrigin() const;
201 // Windows subclassing
202 void SubclassWin(WXHWND hWnd
);
203 void UnsubclassWin();
205 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
206 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
208 wxWindow
*FindItem(long id
) const;
209 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
211 // Make a Windows extended style from the given wxWindows window style
212 static WXDWORD
MakeExtendedStyle(long style
,
213 bool eliminateBorders
= FALSE
);
214 // Determine whether 3D effects are wanted
215 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
217 // MSW only: TRUE if this control is part of the main control
218 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
220 // returns TRUE if the window has been created
221 bool MSWCreate(int id
,
223 const wxChar
*wclass
,
226 int x
, int y
, int width
, int height
,
228 const wxChar
*dialog_template
= NULL
,
229 WXDWORD exendedStyle
= 0);
230 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
232 #if WXWIN_COMPATIBILITY
233 wxObject
*GetChild(int number
) const;
234 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
235 #endif // WXWIN_COMPATIBILITY
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 WXWORD
*nCtlColor
, 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 HandleEraseBkgnd(WXHDC pDC
);
298 bool HandleMinimize();
299 bool HandleMaximize();
300 bool HandleSize(int x
, int y
, WXUINT flag
);
301 bool HandleGetMinMaxInfo(void *mmInfo
);
303 bool HandleShow(bool show
, int status
);
304 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
306 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
307 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
309 bool HandleCtlColor(WXHBRUSH
*hBrush
,
317 bool HandlePaletteChanged(WXHWND hWndPalChange
);
318 bool HandleQueryNewPalette();
319 bool HandleSysColorChange();
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 HandleQueryDragIcon(WXHICON
*hIcon
);
339 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
342 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
344 // Calls an appropriate default window procedure
345 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
347 // message processing helpers
349 // return FALSE if the message shouldn't be translated/preprocessed but
350 // dispatched normally
351 virtual bool MSWShouldPreProcessMessage(WXMSG
* pMsg
);
353 // return TRUE if the message was preprocessed and shouldn't be dispatched
354 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
356 // return TRUE if the message was translated and shouldn't be dispatched
357 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
359 // called when the window is about to be destroyed
360 virtual void MSWDestroyWindow();
362 // Detach "Window" menu from menu bar so it doesn't get deleted
363 void MSWDetachWindowMenu();
365 // this function should return the brush to paint the window background
366 // with or 0 for the default brush
367 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
374 #if WXWIN_COMPATIBILITY
375 void SetShowing(bool show
) { (void)Show(show
); }
376 bool IsUserEnabled() const { return IsEnabled(); }
377 #endif // WXWIN_COMPATIBILITY
379 // Responds to colour changes: passes event on to children.
380 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
382 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
383 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
385 // check if mouse is in the window
386 bool IsMouseInWindow() const;
392 // the old window proc (we subclass all windows)
393 WXFARPROC m_oldWndProc
;
395 // additional (MSW specific) flags
396 bool m_useCtl3D
:1; // Using CTL3D for this control
397 bool m_backgroundTransparent
:1;
398 bool m_mouseInWindow
:1;
399 bool m_doubleClickAllowed
:1;
401 // the size of one page for scrolling
405 #if wxUSE_MOUSEEVENT_HACK
406 // the coordinates of the last mouse event and the type of it
409 int m_lastMouseEvent
;
410 #endif // wxUSE_MOUSEEVENT_HACK
412 WXHMENU m_hMenu
; // Menu, if any
414 // the return value of WM_GETDLGCODE handler
417 // implement the base class pure virtuals
418 virtual void DoClientToScreen( int *x
, int *y
) const;
419 virtual void DoScreenToClient( int *x
, int *y
) const;
420 virtual void DoGetPosition( int *x
, int *y
) const;
421 virtual void DoGetSize( int *width
, int *height
) const;
422 virtual void DoGetClientSize( int *width
, int *height
) const;
423 virtual void DoSetSize(int x
, int y
,
424 int width
, int height
,
425 int sizeFlags
= wxSIZE_AUTO
);
426 virtual void DoSetClientSize(int width
, int height
);
428 // move the window to the specified location and resize it: this is called
429 // from both DoSetSize() and DoSetClientSize() and would usually just call
430 // ::MoveWindow() except for composite controls which will want to arrange
431 // themselves inside the given rectangle
432 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
435 virtual void DoSetToolTip( wxToolTip
*tip
);
436 #endif // wxUSE_TOOLTIPS
439 // common part of all ctors
442 // the (non-virtual) handlers for the events
443 bool HandleMove(int x
, int y
);
444 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
447 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
450 // the helper functions used by HandleChar/KeyXXX methods
451 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
453 DECLARE_DYNAMIC_CLASS(wxWindowMSW
)
454 DECLARE_NO_COPY_CLASS(wxWindowMSW
)
455 DECLARE_EVENT_TABLE()
458 // ---------------------------------------------------------------------------
460 // ---------------------------------------------------------------------------
462 // kbd code translation
463 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
464 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);