1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindow class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
20 #pragma interface "window.h"
23 // #include "wx/msw/winundef.h"
25 // VZ: apparently some version of Windows send extra mouse move messages after
26 // a mouse click. My tests under NT 4.0 and 95 didn't show it so I'm
27 // tempted to think that it was just an effect of a poor mouse and so the
28 // code to work around this is currently disabled - just define this as 1
30 #define wxUSE_MOUSEEVENT_HACK 0
32 // ---------------------------------------------------------------------------
33 // forward declarations
34 // ---------------------------------------------------------------------------
36 class WXDLLEXPORT wxButton
;
38 // ---------------------------------------------------------------------------
40 // ---------------------------------------------------------------------------
42 // FIXME does anybody use those? they're unused by wxWindows...
49 // ---------------------------------------------------------------------------
50 // wxWindow declaration for MSW
51 // ---------------------------------------------------------------------------
52 class WXDLLEXPORT wxWindow
: public wxWindowBase
54 DECLARE_DYNAMIC_CLASS(wxWindow
);
57 wxWindow() { Init(); }
59 wxWindow(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
);
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( wxWindow
*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
);
101 virtual bool SetCursor( const wxCursor
&cursor
);
102 virtual bool SetFont( const wxFont
&font
);
104 virtual int GetCharHeight() const;
105 virtual int GetCharWidth() const;
106 virtual void GetTextExtent(const wxString
& string
,
108 int *descent
= (int *) NULL
,
109 int *externalLeading
= (int *) NULL
,
110 const wxFont
*theFont
= (const wxFont
*) NULL
)
113 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
115 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
116 int range
, bool refresh
= TRUE
);
117 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
118 virtual int GetScrollPos( int orient
) const;
119 virtual int GetScrollThumb( int orient
) const;
120 virtual int GetScrollRange( int orient
) const;
121 virtual void ScrollWindow( int dx
, int dy
,
122 const wxRect
* rect
= (wxRect
*) NULL
);
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 // Native resource loading (implemented in src/msw/nativdlg.cpp)
159 // FIXME: should they really be all virtual?
160 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
161 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
162 wxWindow
* GetWindowChild1(wxWindowID id
);
163 wxWindow
* GetWindowChild(wxWindowID id
);
165 // implementation from now on
166 // --------------------------
171 WXHWND
GetHWND() const { return m_hWnd
; }
172 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
173 virtual WXWidget
GetHandle() const { return GetHWND(); }
175 bool GetUseCtl3D() const { return m_useCtl3D
; }
176 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
177 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
181 void OnEraseBackground(wxEraseEvent
& event
);
182 void OnIdle(wxIdleEvent
& event
);
185 // For implementation purposes - sometimes decorations make the client area
187 virtual wxPoint
GetClientAreaOrigin() const;
189 // Makes an adjustment to the window position (for example, a frame that has
190 // a toolbar that it manages itself).
191 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
193 // Windows subclassing
194 void SubclassWin(WXHWND hWnd
);
195 void UnsubclassWin();
197 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
198 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
200 wxWindow
*FindItem(int id
) const;
201 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
203 // Make a Windows extended style from the given wxWindows window style
204 virtual WXDWORD
MakeExtendedStyle(long style
, bool eliminateBorders
= TRUE
);
205 // Determine whether 3D effects are wanted
206 virtual WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
);
208 // MSW only: TRUE if this control is part of the main control
209 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
211 // returns TRUE if the window has been created
212 bool MSWCreate(int id
,
214 const wxChar
*wclass
,
217 int x
, int y
, int width
, int height
,
219 const wxChar
*dialog_template
= NULL
,
220 WXDWORD exendedStyle
= 0);
221 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
223 #if WXWIN_COMPATIBILITY
224 wxObject
*GetChild(int number
) const;
225 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
226 #endif // WXWIN_COMPATIBILITY
228 // Create an appropriate wxWindow from a HWND
229 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
231 // Make sure the window style reflects the HWND style (roughly)
232 virtual void AdoptAttributesFromHWND();
234 // Setup background and foreground colours correctly
235 virtual void SetupColours();
237 // ------------------------------------------------------------------------
238 // helpers for message handlers: these perform the same function as the
239 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
240 // the correct parameters
241 // ------------------------------------------------------------------------
243 void UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
244 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
245 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
246 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
247 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
248 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
249 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
250 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
);
251 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
252 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
254 // ------------------------------------------------------------------------
255 // internal handlers for MSW messages: all handlers return a boolen value:
256 // TRUE means that the handler processed the event and FALSE that it didn't
257 // ------------------------------------------------------------------------
259 // there are several cases where we have virtual functions for Windows
260 // message processing: this is because these messages often require to be
261 // processed in a different manner in the derived classes. For all other
262 // messages, however, we do *not* have corresponding MSWOnXXX() function
263 // and if the derived class wants to process them, it should override
264 // MSWWindowProc() directly.
266 // scroll event (both horizontal and vertical)
267 virtual bool MSWOnScroll(int orientation
, WXWORD nSBCode
,
268 WXWORD pos
, WXHWND control
);
270 // child control notifications
272 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
275 // owner-drawn controls need to process these messages
276 virtual bool MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
277 virtual bool MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
279 // the rest are not virtual
280 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
281 bool HandleInitDialog(WXHWND hWndFocus
);
282 bool HandleDestroy();
285 bool HandleEraseBkgnd(WXHDC pDC
);
287 bool HandleMinimize();
288 bool HandleMaximize();
289 bool HandleSize(int x
, int y
, WXUINT flag
);
290 bool HandleGetMinMaxInfo(void *mmInfo
);
292 bool HandleShow(bool show
, int status
);
293 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
295 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
296 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
298 bool HandleCtlColor(WXHBRUSH
*hBrush
,
306 bool HandlePaletteChanged(WXHWND hWndPalChange
);
307 bool HandleQueryNewPalette();
308 bool HandleSysColorChange();
310 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
311 bool HandleEndSession(bool endSession
, long logOff
);
313 bool HandleSetFocus(WXHWND wnd
);
314 bool HandleKillFocus(WXHWND wnd
);
316 bool HandleDropFiles(WXWPARAM wParam
);
318 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
319 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
321 bool HandleChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
322 bool HandleKeyDown(WXWORD wParam
, WXLPARAM lParam
);
323 bool HandleKeyUp(WXWORD wParam
, WXLPARAM lParam
);
325 bool HandleQueryDragIcon(WXHICON
*hIcon
);
327 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
330 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
332 // Calls an appropriate default window procedure
333 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
334 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
335 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
336 virtual void MSWDestroyWindow();
338 // Detach "Window" menu from menu bar so it doesn't get deleted
339 void MSWDetachWindowMenu();
341 // this function should return the brush to paint the window background
342 // with or 0 for the default brush
343 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
350 #if WXWIN_COMPATIBILITY
351 void SetShowing(bool show
) { (void)Show(show
); }
352 bool IsUserEnabled() const { return IsEnabled(); }
353 #endif // WXWIN_COMPATIBILITY
355 // Responds to colour changes: passes event on to children.
356 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
358 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
359 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
365 // the old window proc (we subclass all windows)
366 WXFARPROC m_oldWndProc
;
368 // additional (MSW specific) flags
369 bool m_useCtl3D
:1; // Using CTL3D for this control
370 bool m_backgroundTransparent
:1;
371 bool m_mouseInWindow
:1;
372 bool m_doubleClickAllowed
:1;
373 bool m_winCaptured
:1;
375 // the size of one page for scrolling
379 #if wxUSE_MOUSEEVENT_HACK
380 // the coordinates of the last mouse event and the type of it
383 int m_lastMouseEvent
;
384 #endif // wxUSE_MOUSEEVENT_HACK
386 WXHMENU m_hMenu
; // Menu, if any
388 // the return value of WM_GETDLGCODE handler
391 // implement the base class pure virtuals
392 virtual void DoClientToScreen( int *x
, int *y
) const;
393 virtual void DoScreenToClient( int *x
, int *y
) const;
394 virtual void DoGetPosition( int *x
, int *y
) const;
395 virtual void DoGetSize( int *width
, int *height
) const;
396 virtual void DoGetClientSize( int *width
, int *height
) const;
397 virtual void DoSetSize(int x
, int y
,
398 int width
, int height
,
399 int sizeFlags
= wxSIZE_AUTO
);
400 virtual void DoSetClientSize(int width
, int height
);
402 // get the size which best suits the window: e.g., for a static text it
403 // will be the width and height of the text
404 virtual wxSize
DoGetBestSize();
407 virtual void DoSetToolTip( wxToolTip
*tip
);
408 #endif // wxUSE_TOOLTIPS
411 // common part of all ctors
414 // the (non-virtual) handlers for the events
415 bool HandleMove(int x
, int y
);
416 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
419 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
422 DECLARE_NO_COPY_CLASS(wxWindow
);
423 DECLARE_EVENT_TABLE()
426 // ---------------------------------------------------------------------------
428 // ---------------------------------------------------------------------------
430 // kbd code translation
431 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
432 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);