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
56 wxWindow() { Init(); }
58 wxWindow(wxWindow
*parent
,
60 const wxPoint
& pos
= wxDefaultPosition
,
61 const wxSize
& size
= wxDefaultSize
,
63 const wxString
& name
= wxPanelNameStr
)
66 Create(parent
, id
, pos
, size
, style
, name
);
71 bool Create(wxWindow
*parent
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
,
76 const wxString
& name
= wxPanelNameStr
);
78 // implement base class pure virtuals
79 virtual void SetTitle( const wxString
& title
);
80 virtual wxString
GetTitle() const;
85 virtual bool Show( bool show
= TRUE
);
86 virtual bool Enable( bool enable
= TRUE
);
88 virtual void SetFocus();
90 virtual bool Reparent( wxWindowBase
*newParent
);
92 virtual void WarpPointer(int x
, int y
);
93 virtual void CaptureMouse();
94 virtual void ReleaseMouse();
96 virtual void Refresh( bool eraseBackground
= TRUE
,
97 const wxRect
*rect
= (const wxRect
*) NULL
);
100 virtual bool SetCursor( const wxCursor
&cursor
);
101 virtual bool SetFont( const wxFont
&font
);
103 virtual int GetCharHeight() const;
104 virtual int GetCharWidth() const;
105 virtual void GetTextExtent(const wxString
& string
,
107 int *descent
= (int *) NULL
,
108 int *externalLeading
= (int *) NULL
,
109 const wxFont
*theFont
= (const wxFont
*) NULL
)
112 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
);
114 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
115 int range
, bool refresh
= TRUE
);
116 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
117 virtual int GetScrollPos( int orient
) const;
118 virtual int GetScrollThumb( int orient
) const;
119 virtual int GetScrollRange( int orient
) const;
120 virtual void ScrollWindow( int dx
, int dy
,
121 const wxRect
* rect
= (wxRect
*) NULL
);
123 #if wxUSE_DRAG_AND_DROP
124 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
125 #endif // wxUSE_DRAG_AND_DROP
127 // Accept files for dragging
128 virtual void DragAcceptFiles(bool accept
);
130 #if WXWIN_COMPATIBILITY
131 // Set/get scroll attributes
132 virtual void SetScrollRange(int orient
, int range
, bool refresh
= TRUE
);
133 virtual void SetScrollPage(int orient
, int page
, bool refresh
= TRUE
);
134 virtual int OldGetScrollRange(int orient
) const;
135 virtual int GetScrollPage(int orient
) const;
138 // Handle a control command
139 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
141 // Override to define new behaviour for default action (e.g. double
142 // clicking on a listbox)
143 virtual void OnDefaultAction(wxControl
* WXUNUSED(initiatingItem
)) { }
144 #endif // WXWIN_COMPATIBILITY
146 #if wxUSE_CARET && WXWIN_COMPATIBILITY
147 // caret manipulation (old MSW only functions, see wxCaret class for the
149 void CreateCaret(int w
, int h
);
150 void CreateCaret(const wxBitmap
*bitmap
);
152 void ShowCaret(bool show
);
153 void SetCaretPos(int x
, int y
);
154 void GetCaretPos(int *x
, int *y
) const;
155 #endif // wxUSE_CARET
157 // Native resource loading (implemented in src/msw/nativdlg.cpp)
158 // FIXME: should they really be all virtual?
159 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
160 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
161 wxWindow
* GetWindowChild1(wxWindowID id
);
162 wxWindow
* GetWindowChild(wxWindowID id
);
164 // a MSW only function which sends a size event to the window using its
165 // current size - this has an effect of refreshing the window layout
167 FUNCTION IS NOW A MEMBER OF wxFrame - gt
168 void SendSizeEvent();
171 // implementation from now on
172 // --------------------------
177 WXHWND
GetHWND() const { return m_hWnd
; }
178 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
179 virtual WXWidget
GetHandle() const { return GetHWND(); }
181 bool GetUseCtl3D() const { return m_useCtl3D
; }
182 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
183 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
188 void OnSetFocus(wxFocusEvent
& event
);
189 void OnEraseBackground(wxEraseEvent
& event
);
190 void OnIdle(wxIdleEvent
& event
);
191 void OnPaint(wxPaintEvent
& event
);
194 // For implementation purposes - sometimes decorations make the client area
196 virtual wxPoint
GetClientAreaOrigin() const;
198 // Makes an adjustment to the window position (for example, a frame that has
199 // a toolbar that it manages itself).
200 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
202 // Windows subclassing
203 void SubclassWin(WXHWND hWnd
);
204 void UnsubclassWin();
206 WXFARPROC
MSWGetOldWndProc() const { return m_oldWndProc
; }
207 void MSWSetOldWndProc(WXFARPROC proc
) { m_oldWndProc
= proc
; }
209 wxWindow
*FindItem(long id
) const;
210 wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const;
212 // Make a Windows extended style from the given wxWindows window style
213 static WXDWORD
MakeExtendedStyle(long style
,
214 bool eliminateBorders
= FALSE
);
215 // Determine whether 3D effects are wanted
216 WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
) const;
218 // MSW only: TRUE if this control is part of the main control
219 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
221 // returns TRUE if the window has been created
222 bool MSWCreate(int id
,
224 const wxChar
*wclass
,
227 int x
, int y
, int width
, int height
,
229 const wxChar
*dialog_template
= NULL
,
230 WXDWORD exendedStyle
= 0);
231 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
233 #if WXWIN_COMPATIBILITY
234 wxObject
*GetChild(int number
) const;
235 virtual void MSWDeviceToLogical(float *x
, float *y
) const;
236 #endif // WXWIN_COMPATIBILITY
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();
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
);
376 // the old window proc (we subclass all windows)
377 WXFARPROC m_oldWndProc
;
379 // additional (MSW specific) flags
380 bool m_useCtl3D
:1; // Using CTL3D for this control
381 bool m_backgroundTransparent
:1;
382 bool m_mouseInWindow
:1;
383 bool m_doubleClickAllowed
:1;
384 bool m_winCaptured
:1;
386 // the size of one page for scrolling
390 #if wxUSE_MOUSEEVENT_HACK
391 // the coordinates of the last mouse event and the type of it
394 int m_lastMouseEvent
;
395 #endif // wxUSE_MOUSEEVENT_HACK
397 WXHMENU m_hMenu
; // Menu, if any
399 // the return value of WM_GETDLGCODE handler
402 // implement the base class pure virtuals
403 virtual void DoClientToScreen( int *x
, int *y
) const;
404 virtual void DoScreenToClient( int *x
, int *y
) const;
405 virtual void DoGetPosition( int *x
, int *y
) const;
406 virtual void DoGetSize( int *width
, int *height
) const;
407 virtual void DoGetClientSize( int *width
, int *height
) const;
408 virtual void DoSetSize(int x
, int y
,
409 int width
, int height
,
410 int sizeFlags
= wxSIZE_AUTO
);
411 virtual void DoSetClientSize(int width
, int height
);
413 // move the window to the specified location and resize it: this is called
414 // from both DoSetSize() and DoSetClientSize() and would usually just call
415 // ::MoveWindow() except for composite controls which will want to arrange
416 // themselves inside the given rectangle
417 virtual void DoMoveWindow(int x
, int y
, int width
, int height
);
420 virtual void DoSetToolTip( wxToolTip
*tip
);
421 #endif // wxUSE_TOOLTIPS
424 // common part of all ctors
427 // the (non-virtual) handlers for the events
428 bool HandleMove(int x
, int y
);
429 bool HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
);
432 bool HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
);
435 // the helper functions used by HandleChar/KeyXXX methods
436 wxKeyEvent
CreateKeyEvent(wxEventType evType
, int id
, WXLPARAM lp
) const;
438 DECLARE_DYNAMIC_CLASS(wxWindow
);
439 DECLARE_NO_COPY_CLASS(wxWindow
);
440 DECLARE_EVENT_TABLE()
443 // ---------------------------------------------------------------------------
445 // ---------------------------------------------------------------------------
447 // kbd code translation
448 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
449 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);