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 // ---------------------------------------------------------------------------
53 class WXDLLEXPORT wxWindow
: public wxWindowBase
55 DECLARE_DYNAMIC_CLASS(wxWindow
);
58 wxWindow() { Init(); }
60 wxWindow(wxWindow
*parent
,
62 const wxPoint
& pos
= wxDefaultPosition
,
63 const wxSize
& size
= wxDefaultSize
,
65 const wxString
& name
= wxPanelNameStr
)
68 Create(parent
, id
, pos
, size
, style
, name
);
73 bool Create(wxWindow
*parent
,
75 const wxPoint
& pos
= wxDefaultPosition
,
76 const wxSize
& size
= wxDefaultSize
,
78 const wxString
& name
= wxPanelNameStr
);
80 // implement base class pure virtuals
81 virtual void SetTitle( const wxString
& title
);
82 virtual wxString
GetTitle() const;
87 virtual bool Show( bool show
= TRUE
);
88 virtual bool Enable( bool enable
= TRUE
);
90 virtual void SetFocus();
92 virtual bool Reparent( wxWindow
*newParent
);
94 virtual void WarpPointer(int x
, int y
);
95 virtual void CaptureMouse();
96 virtual void ReleaseMouse();
98 virtual void Refresh( bool eraseBackground
= TRUE
,
99 const wxRect
*rect
= (const wxRect
*) NULL
);
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 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
116 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
117 int range
, bool refresh
= TRUE
);
118 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
119 virtual int GetScrollPos( int orient
) const;
120 virtual int GetScrollThumb( int orient
) const;
121 virtual int GetScrollRange( int orient
) const;
122 virtual void ScrollWindow( int dx
, int dy
,
123 const wxRect
* rect
= (wxRect
*) NULL
);
125 #if wxUSE_DRAG_AND_DROP
126 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
127 #endif // wxUSE_DRAG_AND_DROP
129 // Accept files for dragging
130 virtual void DragAcceptFiles(bool accept
);
132 #if WXWIN_COMPATIBILITY
133 // Set/get scroll attributes
134 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
135 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
136 virtual int OldGetScrollRange(int orient
) const;
137 virtual int GetScrollPage(int orient
) const;
140 // Handle a control command
141 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
143 // Override to define new behaviour for default action (e.g. double
144 // clicking on a listbox)
145 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
146 #endif // WXWIN_COMPATIBILITY
148 #if wxUSE_CARET && WXWIN_COMPATIBILITY
149 // caret manipulation (old MSW only functions, see wxCaret class for the
151 void CreateCaret(int w
, int h
);
152 void CreateCaret(const wxBitmap
*bitmap
);
154 void ShowCaret(bool show
);
155 void SetCaretPos(int x
, int y
);
156 void GetCaretPos(int *x
, int *y
) const;
157 #endif // wxUSE_CARET
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
);
166 // implementation from now on
167 // --------------------------
172 WXHWND
GetHWND() const { return m_hWnd
; }
173 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
174 virtual WXWidget
GetHandle() const { return GetHWND(); }
176 bool GetUseCtl3D() const { return m_useCtl3D
; }
177 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
178 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
182 void OnEraseBackground(wxEraseEvent
& event
);
183 void OnIdle(wxIdleEvent
& event
);
186 // For implementation purposes - sometimes decorations make the client area
188 virtual wxPoint
GetClientAreaOrigin() const;
190 // Makes an adjustment to the window position (for example, a frame that has
191 // a toolbar that it manages itself).
192 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
194 // Windows subclassing
195 void SubclassWin(WXHWND hWnd
);
196 void UnsubclassWin();
198 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
199 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
201 wxWindow
*FindItem(long id
) const;
202 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
204 // Make a Windows extended style from the given wxWindows window style
205 static WXDWORD
MakeExtendedStyle(long style
,
206 bool eliminateBorders
= TRUE
);
207 // Determine whether 3D effects are wanted
208 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
210 // MSW only: TRUE if this control is part of the main control
211 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
213 // returns TRUE if the window has been created
214 bool MSWCreate(int id
,
216 const wxChar
*wclass
,
219 int x
, int y
, int width
, int height
,
221 const wxChar
*dialog_template
= NULL
,
222 WXDWORD exendedStyle
= 0);
223 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
225 #if WXWIN_COMPATIBILITY
226 wxObject
*GetChild(int number
) const;
227 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
228 #endif // WXWIN_COMPATIBILITY
230 // Create an appropriate wxWindow from a HWND
231 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
233 // Make sure the window style reflects the HWND style (roughly)
234 virtual void AdoptAttributesFromHWND();
236 // Setup background and foreground colours correctly
237 virtual void SetupColours();
239 // ------------------------------------------------------------------------
240 // helpers for message handlers: these perform the same function as the
241 // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into
242 // the correct parameters
243 // ------------------------------------------------------------------------
245 void UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
246 WXWORD
*id
, WXHWND
*hwnd
, WXWORD
*cmd
);
247 void UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
248 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
);
249 void UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
250 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
);
251 void UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
252 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
);
253 void UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
254 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
);
256 // ------------------------------------------------------------------------
257 // internal handlers for MSW messages: all handlers return a boolen value:
258 // TRUE means that the handler processed the event and FALSE that it didn't
259 // ------------------------------------------------------------------------
261 // there are several cases where we have virtual functions for Windows
262 // message processing: this is because these messages often require to be
263 // processed in a different manner in the derived classes. For all other
264 // messages, however, we do *not* have corresponding MSWOnXXX() function
265 // and if the derived class wants to process them, it should override
266 // MSWWindowProc() directly.
268 // scroll event (both horizontal and vertical)
269 virtual bool MSWOnScroll(int orientation
, WXWORD nSBCode
,
270 WXWORD pos
, WXHWND control
);
272 // child control notifications
274 virtual bool MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
277 // owner-drawn controls need to process these messages
278 virtual bool MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
279 virtual bool MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
281 // the rest are not virtual
282 bool HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
);
283 bool HandleInitDialog(WXHWND hWndFocus
);
284 bool HandleDestroy();
287 bool HandleEraseBkgnd(WXHDC pDC
);
289 bool HandleMinimize();
290 bool HandleMaximize();
291 bool HandleSize(int x
, int y
, WXUINT flag
);
292 bool HandleGetMinMaxInfo(void *mmInfo
);
294 bool HandleShow(bool show
, int status
);
295 bool HandleActivate(int flag
, bool minimized
, WXHWND activate
);
297 bool HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
298 bool HandleSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
300 bool HandleCtlColor(WXHBRUSH
*hBrush
,
308 bool HandlePaletteChanged(WXHWND hWndPalChange
);
309 bool HandleQueryNewPalette();
310 bool HandleSysColorChange();
312 bool HandleQueryEndSession(long logOff
, bool *mayEnd
);
313 bool HandleEndSession(bool endSession
, long logOff
);
315 bool HandleSetFocus(WXHWND wnd
);
316 bool HandleKillFocus(WXHWND wnd
);
318 bool HandleDropFiles(WXWPARAM wParam
);
320 bool HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
321 bool HandleMouseMove(int x
, int y
, WXUINT flags
);
323 bool HandleChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
324 bool HandleKeyDown(WXWORD wParam
, WXLPARAM lParam
);
325 bool HandleKeyUp(WXWORD wParam
, WXLPARAM lParam
);
327 bool HandleQueryDragIcon(WXHICON
*hIcon
);
329 bool HandleSetCursor(WXHWND hWnd
, short nHitTest
, int mouseMsg
);
332 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
334 // Calls an appropriate default window procedure
335 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
336 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
337 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
338 virtual void MSWDestroyWindow();
340 // Detach "Window" menu from menu bar so it doesn't get deleted
341 void MSWDetachWindowMenu();
343 // this function should return the brush to paint the window background
344 // with or 0 for the default brush
345 virtual WXHBRUSH
OnCtlColor(WXHDC hDC
,
352 #if WXWIN_COMPATIBILITY
353 void SetShowing(bool show
) { (void)Show(show
); }
354 bool IsUserEnabled() const { return IsEnabled(); }
355 #endif // WXWIN_COMPATIBILITY
357 // Responds to colour changes: passes event on to children.
358 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
360 // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX)
361 void InitMouseEvent(wxMouseEvent
& event
, int x
, int y
, WXUINT flags
);
367 // the old window proc (we subclass all windows)
368 WXFARPROC m_oldWndProc
;
370 // additional (MSW specific) flags
371 bool m_useCtl3D
:1; // Using CTL3D for this control
372 bool m_backgroundTransparent
:1;
373 bool m_mouseInWindow
:1;
374 bool m_doubleClickAllowed
:1;
375 bool m_winCaptured
:1;
377 // the size of one page for scrolling
381 #if wxUSE_MOUSEEVENT_HACK
382 // the coordinates of the last mouse event and the type of it
385 int m_lastMouseEvent
;
386 #endif // wxUSE_MOUSEEVENT_HACK
388 WXHMENU m_hMenu
; // Menu, if any
390 // the return value of WM_GETDLGCODE handler
393 // implement the base class pure virtuals
394 virtual void DoClientToScreen( int *x
, int *y
) const;
395 virtual void DoScreenToClient( int *x
, int *y
) const;
396 virtual void DoGetPosition( int *x
, int *y
) const;
397 virtual void DoGetSize( int *width
, int *height
) const;
398 virtual void DoGetClientSize( int *width
, int *height
) const;
399 virtual void DoSetSize(int x
, int y
,
400 int width
, int height
,
401 int sizeFlags
= wxSIZE_AUTO
);
402 virtual void DoSetClientSize(int width
, int height
);
404 // get the size which best suits the window: e.g., for a static text it
405 // will be the width and height of the text
406 virtual wxSize
DoGetBestSize();
408 // move the window to the specified location and resize it: this is called
409 // from both DoSetSize() and DoSetClientSize() and would usually just call
410 // ::MoveWindow() except for composite controls which will want to arrange
411 // themselves inside the given rectangle
412 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
415 virtual void DoSetToolTip( wxToolTip
*tip
);
416 #endif // wxUSE_TOOLTIPS
419 // common part of all ctors
422 // the (non-virtual) handlers for the events
423 bool HandleMove(int x
, int y
);
424 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
427 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
430 DECLARE_NO_COPY_CLASS(wxWindow
);
431 DECLARE_EVENT_TABLE()
434 // ---------------------------------------------------------------------------
436 // ---------------------------------------------------------------------------
438 // kbd code translation
439 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
440 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);