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 // windows.h #defines the following identifiers which are also used in wxWin
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
83 virtual bool Show( bool show
= TRUE
);
84 virtual bool Enable( bool enable
= TRUE
);
86 virtual void SetFocus();
88 virtual bool Reparent( wxWindow
*newParent
);
90 virtual void WarpPointer(int x
, int y
);
91 virtual void CaptureMouse();
92 virtual void ReleaseMouse();
94 virtual void Refresh( bool eraseBackground
= TRUE
,
95 const wxRect
*rect
= (const wxRect
*) NULL
);
98 virtual bool SetCursor( const wxCursor
&cursor
);
99 virtual bool SetFont( const wxFont
&font
);
101 virtual int GetCharHeight() const;
102 virtual int GetCharWidth() const;
103 virtual void GetTextExtent(const wxString
& string
,
105 int *descent
= (int *) NULL
,
106 int *externalLeading
= (int *) NULL
,
107 const wxFont
*theFont
= (const wxFont
*) NULL
)
110 virtual void ClientToScreen( int *x
, int *y
) const;
111 virtual void ScreenToClient( int *x
, int *y
) const;
113 virtual bool PopupMenu( 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;
137 #endif // WXWIN_COMPATIBILITY
139 // caret manipulation (MSW only)
140 virtual void CreateCaret(int w
, int h
);
141 virtual void CreateCaret(const wxBitmap
*bitmap
);
142 virtual void DestroyCaret();
143 virtual void ShowCaret(bool show
);
144 virtual void SetCaretPos(int x
, int y
);
145 virtual void GetCaretPos(int *x
, int *y
) const;
147 // event handlers (FIXME: shouldn't they be inside WXWIN_COMPATIBILITY?)
148 // Handle a control command
149 virtual void OnCommand(wxWindow
& win
, wxCommandEvent
& event
);
151 // Override to define new behaviour for default action (e.g. double
152 // clicking on a listbox)
153 virtual void OnDefaultAction(wxControl
*initiatingItem
);
155 // Native resource loading (implemented in src/msw/nativdlg.cpp)
156 // FIXME: should they really be all virtual?
157 virtual bool LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
);
158 virtual bool LoadNativeDialog(wxWindow
* parent
, const wxString
& name
);
159 virtual wxWindow
* GetWindowChild1(wxWindowID id
);
160 virtual wxWindow
* GetWindowChild(wxWindowID id
);
162 // implementation from now on
163 // --------------------------
168 WXHWND
GetHWND() const { return m_hWnd
; }
169 void SetHWND(WXHWND hWnd
) { m_hWnd
= hWnd
; }
170 virtual WXWidget
GetHandle() const { return GetHWND(); }
172 bool GetUseCtl3D() const { return m_useCtl3D
; }
173 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
174 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
178 void OnEraseBackground(wxEraseEvent
& event
);
179 void OnKeyDown(wxKeyEvent
& event
);
180 void OnKeyUp(wxKeyEvent
& event
);
181 void OnPaint(wxPaintEvent
& event
);
182 void OnChar(wxKeyEvent
& event
);
183 void OnIdle(wxIdleEvent
& event
);
185 // a window may have a default button
186 // TODO move into wxPanel and/or wxFrame
187 wxButton
*GetDefaultItem() const { return m_btnDefault
; }
188 void SetDefaultItem(wxButton
*btn
) { m_btnDefault
= btn
; }
191 // For implementation purposes - sometimes decorations make the client area
193 virtual wxPoint
GetClientAreaOrigin() const;
195 // Makes an adjustment to the window position (for example, a frame that has
196 // a toolbar that it manages itself).
197 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
199 // Windows subclassing
200 void SubclassWin(WXHWND hWnd
);
201 void UnsubclassWin();
202 virtual long Default();
203 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
205 // returns TRUE if the event was processed
206 virtual bool MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
, WXLPARAM
*result
);
208 virtual wxWindow
*FindItem(int id
) const;
209 virtual wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const ;
210 virtual void PreDelete(WXHDC dc
); // Allows system cleanup
212 // Make a Windows extended style from the given wxWindows window style
213 virtual WXDWORD
MakeExtendedStyle(long style
, bool eliminateBorders
= TRUE
);
214 // Determine whether 3D effects are wanted
215 virtual WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
);
217 // MSW only: TRUE if this control is part of the main control
218 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
220 wxObject
*GetChild(int number
) const ;
222 void MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
223 int x
, int y
, int width
, int height
,
224 WXDWORD style
, const char *dialog_template
= NULL
,
225 WXDWORD exendedStyle
= 0);
227 // Actually defined in wx_canvs.cc since requires wxCanvas declaration
228 virtual void MSWDeviceToLogical(float *x
, float *y
) const ;
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 // Saves the last message information before calling base version
240 virtual bool ProcessEvent(wxEvent
& event
);
243 virtual void MSWOnCreate(WXLPCREATESTRUCT cs
);
244 virtual bool MSWOnPaint();
245 virtual WXHICON
MSWOnQueryDragIcon() { return 0; }
246 virtual void MSWOnSize(int x
, int y
, WXUINT flag
);
247 virtual void MSWOnWindowPosChanging(void *lpPos
);
248 virtual void MSWOnHScroll(WXWORD nSBCode
, WXWORD pos
, WXHWND control
);
249 virtual void MSWOnVScroll(WXWORD nSBCode
, WXWORD pos
, WXHWND control
);
250 virtual bool MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
251 virtual long MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
252 virtual long MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
);
253 virtual WXHBRUSH
MSWOnCtlColor(WXHDC dc
, WXHWND pWnd
, WXUINT nCtlColor
,
254 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
255 virtual bool MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
256 virtual long MSWOnPaletteChanged(WXHWND hWndPalChange
);
257 virtual long MSWOnQueryNewPalette();
258 virtual bool MSWOnEraseBkgnd(WXHDC pDC
);
259 virtual void MSWOnMenuHighlight(WXWORD item
, WXWORD flags
, WXHMENU sysmenu
);
260 virtual void MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
);
261 virtual bool MSWOnClose();
262 // Return TRUE to end session, FALSE to veto end session.
263 virtual bool MSWOnQueryEndSession(long logOff
);
264 virtual bool MSWOnEndSession(bool endSession
, long logOff
);
265 virtual bool MSWOnDestroy();
266 virtual bool MSWOnSetFocus(WXHWND wnd
);
267 virtual bool MSWOnKillFocus(WXHWND wnd
);
268 virtual void MSWOnDropFiles(WXWPARAM wParam
);
269 virtual bool MSWOnInitDialog(WXHWND hWndFocus
);
270 virtual void MSWOnShow(bool show
, int status
);
272 // TODO: rationalise these functions into 1 or 2 which take the
273 // event type as argument.
274 virtual void MSWOnLButtonDown(int x
, int y
, WXUINT flags
);
275 virtual void MSWOnLButtonUp(int x
, int y
, WXUINT flags
);
276 virtual void MSWOnLButtonDClick(int x
, int y
, WXUINT flags
);
278 virtual void MSWOnMButtonDown(int x
, int y
, WXUINT flags
);
279 virtual void MSWOnMButtonUp(int x
, int y
, WXUINT flags
);
280 virtual void MSWOnMButtonDClick(int x
, int y
, WXUINT flags
);
282 virtual void MSWOnRButtonDown(int x
, int y
, WXUINT flags
);
283 virtual void MSWOnRButtonUp(int x
, int y
, WXUINT flags
);
284 virtual void MSWOnRButtonDClick(int x
, int y
, WXUINT flags
);
286 virtual void MSWOnMouseMove(int x
, int y
, WXUINT flags
);
287 virtual void MSWOnMouseEnter(int x
, int y
, WXUINT flags
);
288 virtual void MSWOnMouseLeave(int x
, int y
, WXUINT flags
);
290 // These return TRUE if an event handler was found, FALSE otherwise (not processed)
291 virtual bool MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
292 virtual bool MSWOnKeyDown(WXWORD wParam
, WXLPARAM lParam
);
293 virtual bool MSWOnKeyUp(WXWORD wParam
, WXLPARAM lParam
);
295 virtual bool MSWOnActivate(int flag
, bool minimized
, WXHWND activate
);
296 virtual long MSWOnMDIActivate(long flag
, WXHWND activate
, WXHWND deactivate
);
298 virtual bool MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
299 virtual bool MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
301 virtual void MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
);
302 virtual void MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
);
303 virtual void MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
);
304 virtual void MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
);
306 virtual long MSWGetDlgCode();
309 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
311 // Calls an appropriate default window procedure
312 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
313 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
314 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
315 virtual void MSWDestroyWindow();
317 // Detach "Window" menu from menu bar so it doesn't get deleted
318 void MSWDetachWindowMenu();
320 inline WXFARPROC
MSWGetOldWndProc() const;
321 inline void MSWSetOldWndProc(WXFARPROC proc
);
323 // Define for each class of dialog and control
324 virtual WXHBRUSH
OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
325 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
327 #if WXWIN_COMPATIBILITY
328 void SetShowing(bool show
) { (void)Show(show
); }
329 bool IsUserEnabled() const { return IsEnabled(); }
330 #endif // WXWIN_COMPATIBILITY
332 // Responds to colour changes: passes event on to children.
333 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
335 // remember the parameters of the last message
336 void PushLastMessage(WXUINT msg
, WXWPARAM wParam
, WXLPARAM lParam
)
339 m_lastWParam
= wParam
;
340 m_lastLParam
= lParam
;
347 // the old window proc (we subclass all windows)
348 WXFARPROC m_oldWndProc
;
350 // additional (MSW specific) flags
351 bool m_useCtl3D
:1; // Using CTL3D for this control
352 bool m_inOnSize
:1; // Protection against OnSize reentry
353 bool m_backgroundTransparent
:1;
354 bool m_mouseInWindow
:1;
355 bool m_doubleClickAllowed
:1;
356 bool m_winCaptured
:1;
359 bool m_caretEnabled
:1;
364 // the size of one page for scrolling
368 // the coordinates of the last mouse event and the typoe of it
371 int m_lastMouseEvent
;
373 // the parameters of the last message used in Default()
375 WXWPARAM m_lastWParam
;
376 WXLPARAM m_lastLParam
;
378 WXHMENU m_hMenu
; // Menu, if any
380 wxButton
*m_btnDefault
;
382 // implement the base class pure virtuals
383 virtual void DoGetPosition( int *x
, int *y
) const;
384 virtual void DoGetSize( int *width
, int *height
) const;
385 virtual void DoGetClientSize( int *width
, int *height
) const;
386 virtual void DoSetSize(int x
, int y
,
387 int width
, int height
,
388 int sizeFlags
= wxSIZE_AUTO
);
389 virtual void DoSetClientSize(int width
, int height
);
392 virtual void DoSetToolTip( wxToolTip
*tip
);
393 #endif // wxUSE_TOOLTIPS
396 // common part of all ctors
399 DECLARE_EVENT_TABLE()
402 // ---------------------------------------------------------------------------
404 // ---------------------------------------------------------------------------
406 // kbd code translation
407 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
408 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);