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();
94 virtual bool SetCursor( const wxCursor
&cursor
);
95 virtual bool SetFont( const wxFont
&font
);
97 virtual int GetCharHeight() const;
98 virtual int GetCharWidth() const;
99 virtual void GetTextExtent(const wxString
& string
,
101 int *descent
= (int *) NULL
,
102 int *externalLeading
= (int *) NULL
,
103 const wxFont
*theFont
= (const wxFont
*) NULL
)
106 #if wxUSE_MENUS_NATIVE
107 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
108 #endif // wxUSE_MENUS_NATIVE
110 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
111 int range
, bool refresh
= TRUE
);
112 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
113 virtual int GetScrollPos( int orient
) const;
114 virtual int GetScrollThumb( int orient
) const;
115 virtual int GetScrollRange( int orient
) const;
116 virtual void ScrollWindow( int dx
, int dy
,
117 const wxRect
* rect
= (wxRect
*) NULL
);
119 #if wxUSE_DRAG_AND_DROP
120 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
121 #endif // wxUSE_DRAG_AND_DROP
123 // Accept files for dragging
124 virtual void DragAcceptFiles(bool accept
);
126 #if WXWIN_COMPATIBILITY
127 // Set/get scroll attributes
128 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
129 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
130 virtual int OldGetScrollRange(int orient
) const;
131 virtual int GetScrollPage(int orient
) const;
134 // Handle a control command
135 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
137 // Override to define new behaviour for default action (e.g. double
138 // clicking on a listbox)
139 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
140 #endif // WXWIN_COMPATIBILITY
142 #if wxUSE_CARET && WXWIN_COMPATIBILITY
143 // caret manipulation (old MSW only functions, see wxCaret class for the
145 void CreateCaret(int w
, int h
);
146 void CreateCaret(const wxBitmap
*bitmap
);
148 void ShowCaret(bool show
);
149 void SetCaretPos(int x
, int y
);
150 void GetCaretPos(int *x
, int *y
) const;
151 #endif // wxUSE_CARET
153 #ifndef __WXUNIVERSAL__
154 // Native resource loading (implemented in src/msw/nativdlg.cpp)
155 // FIXME: should they really be all virtual?
156 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
157 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
158 wxWindow
* GetWindowChild1(wxWindowID id
);
159 wxWindow
* GetWindowChild(wxWindowID id
);
160 #endif // __WXUNIVERSAL__
162 // a MSW only function which sends a size event to the window using its
163 // current size - this has an effect of refreshing the window layout
165 FUNCTION IS NOW A MEMBER OF wxFrame - gt
166 void SendSizeEvent();
169 // implementation from now on
170 // --------------------------
175 WXHWND
GetHWND() const { return m_hWnd
; }
176 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
177 virtual WXWidget
GetHandle() const { return GetHWND(); }
179 bool GetUseCtl3D() const { return m_useCtl3D
; }
180 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
181 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
186 void OnSetFocus(wxFocusEvent
& event
);
187 void OnEraseBackground(wxEraseEvent
& event
);
188 void OnIdle(wxIdleEvent
& event
);
189 void OnPaint(wxPaintEvent
& event
);
192 // For implementation purposes - sometimes decorations make the client area
194 virtual wxPoint
GetClientAreaOrigin() const;
196 // Makes an adjustment to the window position (for example, a frame that has
197 // a toolbar that it manages itself).
198 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
200 // Windows subclassing
201 void SubclassWin(WXHWND hWnd
);
202 void UnsubclassWin();
204 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
205 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
207 wxWindow
*FindItem(long id
) const;
208 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
210 // Make a Windows extended style from the given wxWindows window style
211 static WXDWORD
MakeExtendedStyle(long style
,
212 bool eliminateBorders
= FALSE
);
213 // Determine whether 3D effects are wanted
214 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
216 // MSW only: TRUE if this control is part of the main control
217 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
219 // returns TRUE if the window has been created
220 bool MSWCreate(int id
,
222 const wxChar
*wclass
,
225 int x
, int y
, int width
, int height
,
227 const wxChar
*dialog_template
= NULL
,
228 WXDWORD exendedStyle
= 0);
229 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
231 #if WXWIN_COMPATIBILITY
232 wxObject
*GetChild(int number
) const;
233 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
234 #endif // WXWIN_COMPATIBILITY
236 #ifndef __WXUNIVERSAL__
237 // Create an appropriate wxWindow from a HWND
238 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
240 // Make sure the window style reflects the HWND style (roughly)
241 virtual void AdoptAttributesFromHWND();
242 #endif // __WXUNIVERSAL__
244 // Setup background and foreground colours correctly
245 virtual void SetupColours();
247 // ------------------------------------------------------------------------
248 // helpers for message handlers: these perform the same function as the
249 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
250 // the correct parameters
251 // ------------------------------------------------------------------------
253 void UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
254 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
255 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
256 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
257 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
258 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
259 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
260 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
);
261 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
262 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
264 // ------------------------------------------------------------------------
265 // internal handlers for MSW messages: all handlers return a boolean value:
266 // TRUE means that the handler processed the event and FALSE that it didn't
267 // ------------------------------------------------------------------------
269 // there are several cases where we have virtual functions for Windows
270 // message processing: this is because these messages often require to be
271 // processed in a different manner in the derived classes. For all other
272 // messages, however, we do *not* have corresponding MSWOnXXX() function
273 // and if the derived class wants to process them, it should override
274 // MSWWindowProc() directly.
276 // scroll event (both horizontal and vertical)
277 virtual bool MSWOnScroll(int orientation
, WXWORD nSBCode
,
278 WXWORD pos
, WXHWND control
);
280 // child control notifications
282 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
285 // owner-drawn controls need to process these messages
286 virtual bool MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
287 virtual bool MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
289 // the rest are not virtual
290 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
291 bool HandleInitDialog(WXHWND hWndFocus
);
292 bool HandleDestroy();
295 bool HandleEraseBkgnd(WXHDC pDC
);
297 bool HandleMinimize();
298 bool HandleMaximize();
299 bool HandleSize(int x
, int y
, WXUINT flag
);
300 bool HandleGetMinMaxInfo(void *mmInfo
);
302 bool HandleShow(bool show
, int status
);
303 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
305 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
306 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
308 bool HandleCtlColor(WXHBRUSH
*hBrush
,
316 bool HandlePaletteChanged(WXHWND hWndPalChange
);
317 bool HandleQueryNewPalette();
318 bool HandleSysColorChange();
320 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
321 bool HandleEndSession(bool endSession
, long logOff
);
323 bool HandleSetFocus(WXHWND wnd
);
324 bool HandleKillFocus(WXHWND wnd
);
326 bool HandleDropFiles(WXWPARAM wParam
);
328 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
329 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
330 bool HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
);
332 bool HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
333 bool HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
);
334 bool HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
);
336 bool HandleQueryDragIcon(WXHICON
*hIcon
);
338 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
341 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
343 // Calls an appropriate default window procedure
344 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
345 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
346 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
347 virtual void MSWDestroyWindow();
349 // Detach "Window" menu from menu bar so it doesn't get deleted
350 void MSWDetachWindowMenu();
352 // this function should return the brush to paint the window background
353 // with or 0 for the default brush
354 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
361 #if WXWIN_COMPATIBILITY
362 void SetShowing(bool show
) { (void)Show(show
); }
363 bool IsUserEnabled() const { return IsEnabled(); }
364 #endif // WXWIN_COMPATIBILITY
366 // Responds to colour changes: passes event on to children.
367 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
369 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
370 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
372 // check if mouse is in the window
373 bool IsMouseInWindow() const;
379 // the old window proc (we subclass all windows)
380 WXFARPROC m_oldWndProc
;
382 // additional (MSW specific) flags
383 bool m_useCtl3D
:1; // Using CTL3D for this control
384 bool m_backgroundTransparent
:1;
385 bool m_mouseInWindow
:1;
386 bool m_doubleClickAllowed
:1;
388 // the size of one page for scrolling
392 #if wxUSE_MOUSEEVENT_HACK
393 // the coordinates of the last mouse event and the type of it
396 int m_lastMouseEvent
;
397 #endif // wxUSE_MOUSEEVENT_HACK
399 WXHMENU m_hMenu
; // Menu, if any
401 // the return value of WM_GETDLGCODE handler
404 // implement the base class pure virtuals
405 virtual void DoClientToScreen( int *x
, int *y
) const;
406 virtual void DoScreenToClient( int *x
, int *y
) const;
407 virtual void DoGetPosition( int *x
, int *y
) const;
408 virtual void DoGetSize( int *width
, int *height
) const;
409 virtual void DoGetClientSize( int *width
, int *height
) const;
410 virtual void DoSetSize(int x
, int y
,
411 int width
, int height
,
412 int sizeFlags
= wxSIZE_AUTO
);
413 virtual void DoSetClientSize(int width
, int height
);
415 // move the window to the specified location and resize it: this is called
416 // from both DoSetSize() and DoSetClientSize() and would usually just call
417 // ::MoveWindow() except for composite controls which will want to arrange
418 // themselves inside the given rectangle
419 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
422 virtual void DoSetToolTip( wxToolTip
*tip
);
423 #endif // wxUSE_TOOLTIPS
426 // common part of all ctors
429 // the (non-virtual) handlers for the events
430 bool HandleMove(int x
, int y
);
431 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
434 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
437 // the helper functions used by HandleChar/KeyXXX methods
438 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
440 DECLARE_DYNAMIC_CLASS(wxWindowMSW
);
441 DECLARE_NO_COPY_CLASS(wxWindowMSW
);
442 DECLARE_EVENT_TABLE()
445 // ---------------------------------------------------------------------------
447 // ---------------------------------------------------------------------------
449 // kbd code translation
450 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
451 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);