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 // when building wxUniv/MSW we don't want the code for native menu use to be
32 // compiled in - it should only be used when building real wxMSW
33 #ifdef __WXUNIVERSAL__
34 #define wxUSE_MENUS_NATIVE 0
36 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
37 #endif // __WXUNIVERSAL__/__WXMSW__
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 // FIXME does anybody use those? they're unused by wxWindows...
50 // ---------------------------------------------------------------------------
51 // wxWindow declaration for MSW
52 // ---------------------------------------------------------------------------
54 class WXDLLEXPORT wxWindowMSW
: public wxWindowBase
57 wxWindowMSW() { Init(); }
59 wxWindowMSW(wxWindow
*parent
,
61 const wxPoint
& pos
= wxDefaultPosition
,
62 const wxSize
& size
= wxDefaultSize
,
64 const wxString
& name
= wxPanelNameStr
)
67 Create(parent
, id
, pos
, size
, style
, name
);
70 virtual ~wxWindowMSW();
72 bool Create(wxWindow
*parent
,
74 const wxPoint
& pos
= wxDefaultPosition
,
75 const wxSize
& size
= wxDefaultSize
,
77 const wxString
& name
= wxPanelNameStr
);
79 // implement base class pure virtuals
80 virtual void SetTitle( const wxString
& title
);
81 virtual wxString
GetTitle() const;
86 virtual bool Show( bool show
= TRUE
);
87 virtual bool Enable( bool enable
= TRUE
);
89 virtual void SetFocus();
91 virtual bool Reparent(wxWindowBase
*newParent
);
93 virtual void WarpPointer(int x
, int y
);
94 virtual void CaptureMouse();
95 virtual void ReleaseMouse();
97 virtual void Refresh( bool eraseBackground
= TRUE
,
98 const wxRect
*rect
= (const wxRect
*) NULL
);
99 virtual void Update();
100 virtual void Clear();
102 virtual bool SetCursor( const wxCursor
&cursor
);
103 virtual bool SetFont( const wxFont
&font
);
105 virtual int GetCharHeight() const;
106 virtual int GetCharWidth() const;
107 virtual void GetTextExtent(const wxString
& string
,
109 int *descent
= (int *) NULL
,
110 int *externalLeading
= (int *) NULL
,
111 const wxFont
*theFont
= (const wxFont
*) NULL
)
114 #if wxUSE_MENUS_NATIVE
115 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
116 #endif // wxUSE_MENUS_NATIVE
118 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
119 int range
, bool refresh
= TRUE
);
120 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
121 virtual int GetScrollPos( int orient
) const;
122 virtual int GetScrollThumb( int orient
) const;
123 virtual int GetScrollRange( int orient
) const;
124 virtual void ScrollWindow( int dx
, int dy
,
125 const wxRect
* rect
= (wxRect
*) NULL
);
127 #if wxUSE_DRAG_AND_DROP
128 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
129 #endif // wxUSE_DRAG_AND_DROP
131 // Accept files for dragging
132 virtual void DragAcceptFiles(bool accept
);
134 #if WXWIN_COMPATIBILITY
135 // Set/get scroll attributes
136 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
137 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
138 virtual int OldGetScrollRange(int orient
) const;
139 virtual int GetScrollPage(int orient
) const;
142 // Handle a control command
143 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
145 // Override to define new behaviour for default action (e.g. double
146 // clicking on a listbox)
147 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
148 #endif // WXWIN_COMPATIBILITY
150 #if wxUSE_CARET && WXWIN_COMPATIBILITY
151 // caret manipulation (old MSW only functions, see wxCaret class for the
153 void CreateCaret(int w
, int h
);
154 void CreateCaret(const wxBitmap
*bitmap
);
156 void ShowCaret(bool show
);
157 void SetCaretPos(int x
, int y
);
158 void GetCaretPos(int *x
, int *y
) const;
159 #endif // wxUSE_CARET
161 #ifndef __WXUNIVERSAL__
162 // Native resource loading (implemented in src/msw/nativdlg.cpp)
163 // FIXME: should they really be all virtual?
164 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
165 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
166 wxWindow
* GetWindowChild1(wxWindowID id
);
167 wxWindow
* GetWindowChild(wxWindowID id
);
168 #endif // __WXUNIVERSAL__
170 // a MSW only function which sends a size event to the window using its
171 // current size - this has an effect of refreshing the window layout
173 FUNCTION IS NOW A MEMBER OF wxFrame - gt
174 void SendSizeEvent();
177 // implementation from now on
178 // --------------------------
183 WXHWND
GetHWND() const { return m_hWnd
; }
184 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
185 virtual WXWidget
GetHandle() const { return GetHWND(); }
187 bool GetUseCtl3D() const { return m_useCtl3D
; }
188 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
189 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
194 void OnSetFocus(wxFocusEvent
& event
);
195 void OnEraseBackground(wxEraseEvent
& event
);
196 void OnIdle(wxIdleEvent
& event
);
197 void OnPaint(wxPaintEvent
& event
);
200 // For implementation purposes - sometimes decorations make the client area
202 virtual wxPoint
GetClientAreaOrigin() const;
204 // Makes an adjustment to the window position (for example, a frame that has
205 // a toolbar that it manages itself).
206 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
208 // Windows subclassing
209 void SubclassWin(WXHWND hWnd
);
210 void UnsubclassWin();
212 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
213 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
215 wxWindow
*FindItem(long id
) const;
216 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
218 // Make a Windows extended style from the given wxWindows window style
219 static WXDWORD
MakeExtendedStyle(long style
,
220 bool eliminateBorders
= FALSE
);
221 // Determine whether 3D effects are wanted
222 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
224 // MSW only: TRUE if this control is part of the main control
225 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
227 // returns TRUE if the window has been created
228 bool MSWCreate(int id
,
230 const wxChar
*wclass
,
233 int x
, int y
, int width
, int height
,
235 const wxChar
*dialog_template
= NULL
,
236 WXDWORD exendedStyle
= 0);
237 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
239 #if WXWIN_COMPATIBILITY
240 wxObject
*GetChild(int number
) const;
241 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
242 #endif // WXWIN_COMPATIBILITY
244 #ifndef __WXUNIVERSAL__
245 // Create an appropriate wxWindow from a HWND
246 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
248 // Make sure the window style reflects the HWND style (roughly)
249 virtual void AdoptAttributesFromHWND();
250 #endif // __WXUNIVERSAL__
252 // Setup background and foreground colours correctly
253 virtual void SetupColours();
255 // ------------------------------------------------------------------------
256 // helpers for message handlers: these perform the same function as the
257 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
258 // the correct parameters
259 // ------------------------------------------------------------------------
261 void UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
262 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
263 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
264 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
265 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
266 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
267 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
268 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
);
269 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
270 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
272 // ------------------------------------------------------------------------
273 // internal handlers for MSW messages: all handlers return a boolean value:
274 // TRUE means that the handler processed the event and FALSE that it didn't
275 // ------------------------------------------------------------------------
277 // there are several cases where we have virtual functions for Windows
278 // message processing: this is because these messages often require to be
279 // processed in a different manner in the derived classes. For all other
280 // messages, however, we do *not* have corresponding MSWOnXXX() function
281 // and if the derived class wants to process them, it should override
282 // MSWWindowProc() directly.
284 // scroll event (both horizontal and vertical)
285 virtual bool MSWOnScroll(int orientation
, WXWORD nSBCode
,
286 WXWORD pos
, WXHWND control
);
288 // child control notifications
290 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
293 // owner-drawn controls need to process these messages
294 virtual bool MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
295 virtual bool MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
297 // the rest are not virtual
298 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
299 bool HandleInitDialog(WXHWND hWndFocus
);
300 bool HandleDestroy();
303 bool HandleEraseBkgnd(WXHDC pDC
);
305 bool HandleMinimize();
306 bool HandleMaximize();
307 bool HandleSize(int x
, int y
, WXUINT flag
);
308 bool HandleGetMinMaxInfo(void *mmInfo
);
310 bool HandleShow(bool show
, int status
);
311 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
313 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
314 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
316 bool HandleCtlColor(WXHBRUSH
*hBrush
,
324 bool HandlePaletteChanged(WXHWND hWndPalChange
);
325 bool HandleQueryNewPalette();
326 bool HandleSysColorChange();
328 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
329 bool HandleEndSession(bool endSession
, long logOff
);
331 bool HandleSetFocus(WXHWND wnd
);
332 bool HandleKillFocus(WXHWND wnd
);
334 bool HandleDropFiles(WXWPARAM wParam
);
336 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
337 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
338 bool HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
);
340 bool HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
341 bool HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
);
342 bool HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
);
344 bool HandleQueryDragIcon(WXHICON
*hIcon
);
346 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
349 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
351 // Calls an appropriate default window procedure
352 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
353 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
354 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
355 virtual void MSWDestroyWindow();
357 // Detach "Window" menu from menu bar so it doesn't get deleted
358 void MSWDetachWindowMenu();
360 // this function should return the brush to paint the window background
361 // with or 0 for the default brush
362 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
369 #if WXWIN_COMPATIBILITY
370 void SetShowing(bool show
) { (void)Show(show
); }
371 bool IsUserEnabled() const { return IsEnabled(); }
372 #endif // WXWIN_COMPATIBILITY
374 // Responds to colour changes: passes event on to children.
375 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
377 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
378 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
380 // check if mouse is in the window
381 bool IsMouseInWindow() const;
387 // the old window proc (we subclass all windows)
388 WXFARPROC m_oldWndProc
;
390 // additional (MSW specific) flags
391 bool m_useCtl3D
:1; // Using CTL3D for this control
392 bool m_backgroundTransparent
:1;
393 bool m_mouseInWindow
:1;
394 bool m_doubleClickAllowed
:1;
396 // the size of one page for scrolling
400 #if wxUSE_MOUSEEVENT_HACK
401 // the coordinates of the last mouse event and the type of it
404 int m_lastMouseEvent
;
405 #endif // wxUSE_MOUSEEVENT_HACK
407 WXHMENU m_hMenu
; // Menu, if any
409 // the return value of WM_GETDLGCODE handler
412 // implement the base class pure virtuals
413 virtual void DoClientToScreen( int *x
, int *y
) const;
414 virtual void DoScreenToClient( int *x
, int *y
) const;
415 virtual void DoGetPosition( int *x
, int *y
) const;
416 virtual void DoGetSize( int *width
, int *height
) const;
417 virtual void DoGetClientSize( int *width
, int *height
) const;
418 virtual void DoSetSize(int x
, int y
,
419 int width
, int height
,
420 int sizeFlags
= wxSIZE_AUTO
);
421 virtual void DoSetClientSize(int width
, int height
);
423 // move the window to the specified location and resize it: this is called
424 // from both DoSetSize() and DoSetClientSize() and would usually just call
425 // ::MoveWindow() except for composite controls which will want to arrange
426 // themselves inside the given rectangle
427 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
430 virtual void DoSetToolTip( wxToolTip
*tip
);
431 #endif // wxUSE_TOOLTIPS
434 // common part of all ctors
437 // the (non-virtual) handlers for the events
438 bool HandleMove(int x
, int y
);
439 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
442 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
445 // the helper functions used by HandleChar/KeyXXX methods
446 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
448 DECLARE_DYNAMIC_CLASS(wxWindowMSW
);
449 DECLARE_NO_COPY_CLASS(wxWindowMSW
);
450 DECLARE_EVENT_TABLE()
453 // ---------------------------------------------------------------------------
455 // ---------------------------------------------------------------------------
457 // kbd code translation
458 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
459 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);