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 GetHandle(); }
169 void SetHWND(WXHWND hWnd
) { m_widget
= hWnd
; }
171 bool GetUseCtl3D() const { return m_useCtl3D
; }
172 bool GetTransparentBackground() const { return m_backgroundTransparent
; }
173 void SetTransparent(bool t
= TRUE
) { m_backgroundTransparent
= t
; }
177 void OnEraseBackground(wxEraseEvent
& event
);
178 void OnKeyDown(wxKeyEvent
& event
);
179 void OnKeyUp(wxKeyEvent
& event
);
180 void OnPaint(wxPaintEvent
& event
);
181 void OnChar(wxKeyEvent
& event
);
182 void OnIdle(wxIdleEvent
& event
);
184 // a window may have a default button
185 // TODO move into wxPanel and/or wxFrame
186 wxButton
*GetDefaultItem() const { return m_btnDefault
; }
187 void SetDefaultItem(wxButton
*btn
) { m_btnDefault
= btn
; }
190 // For implementation purposes - sometimes decorations make the client area
192 virtual wxPoint
GetClientAreaOrigin() const;
194 // Makes an adjustment to the window position (for example, a frame that has
195 // a toolbar that it manages itself).
196 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
198 // Windows subclassing
199 void SubclassWin(WXHWND hWnd
);
200 void UnsubclassWin();
201 virtual long Default();
202 virtual bool MSWCommand(WXUINT param
, WXWORD id
);
204 // returns TRUE if the event was processed
205 virtual bool MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
, WXLPARAM
*result
);
207 virtual wxWindow
*FindItem(int id
) const;
208 virtual wxWindow
*FindItemByHWND(WXHWND hWnd
, bool controlOnly
= FALSE
) const ;
209 virtual void PreDelete(WXHDC dc
); // Allows system cleanup
211 // Make a Windows extended style from the given wxWindows window style
212 virtual WXDWORD
MakeExtendedStyle(long style
, bool eliminateBorders
= TRUE
);
213 // Determine whether 3D effects are wanted
214 virtual WXDWORD
Determine3DEffects(WXDWORD defaultBorderStyle
, bool *want3D
);
216 // MSW only: TRUE if this control is part of the main control
217 virtual bool ContainsHWND(WXHWND
WXUNUSED(hWnd
)) const { return FALSE
; };
219 wxObject
*GetChild(int number
) const ;
221 void MSWCreate(int id
, wxWindow
*parent
, const char *wclass
, wxWindow
*wx_win
, const char *title
,
222 int x
, int y
, int width
, int height
,
223 WXDWORD style
, const char *dialog_template
= NULL
,
224 WXDWORD exendedStyle
= 0);
226 // Actually defined in wx_canvs.cc since requires wxCanvas declaration
227 virtual void MSWDeviceToLogical(float *x
, float *y
) const ;
229 // Create an appropriate wxWindow from a HWND
230 virtual wxWindow
* CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
);
232 // Make sure the window style reflects the HWND style (roughly)
233 virtual void AdoptAttributesFromHWND();
235 // Setup background and foreground colours correctly
236 virtual void SetupColours();
238 // Saves the last message information before calling base version
239 virtual bool ProcessEvent(wxEvent
& event
);
242 virtual void MSWOnCreate(WXLPCREATESTRUCT cs
);
243 virtual bool MSWOnPaint();
244 virtual WXHICON
MSWOnQueryDragIcon() { return 0; }
245 virtual void MSWOnSize(int x
, int y
, WXUINT flag
);
246 virtual void MSWOnWindowPosChanging(void *lpPos
);
247 virtual void MSWOnHScroll(WXWORD nSBCode
, WXWORD pos
, WXHWND control
);
248 virtual void MSWOnVScroll(WXWORD nSBCode
, WXWORD pos
, WXHWND control
);
249 virtual bool MSWOnCommand(WXWORD id
, WXWORD cmd
, WXHWND control
);
250 virtual long MSWOnSysCommand(WXWPARAM wParam
, WXLPARAM lParam
);
251 virtual long MSWOnNotify(WXWPARAM wParam
, WXLPARAM lParam
);
252 virtual WXHBRUSH
MSWOnCtlColor(WXHDC dc
, WXHWND pWnd
, WXUINT nCtlColor
,
253 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
254 virtual bool MSWOnColorChange(WXHWND hWnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
255 virtual long MSWOnPaletteChanged(WXHWND hWndPalChange
);
256 virtual long MSWOnQueryNewPalette();
257 virtual bool MSWOnEraseBkgnd(WXHDC pDC
);
258 virtual void MSWOnMenuHighlight(WXWORD item
, WXWORD flags
, WXHMENU sysmenu
);
259 virtual void MSWOnInitMenuPopup(WXHMENU menu
, int pos
, bool isSystem
);
260 virtual bool MSWOnClose();
261 // Return TRUE to end session, FALSE to veto end session.
262 virtual bool MSWOnQueryEndSession(long logOff
);
263 virtual bool MSWOnEndSession(bool endSession
, long logOff
);
264 virtual bool MSWOnDestroy();
265 virtual bool MSWOnSetFocus(WXHWND wnd
);
266 virtual bool MSWOnKillFocus(WXHWND wnd
);
267 virtual void MSWOnDropFiles(WXWPARAM wParam
);
268 virtual bool MSWOnInitDialog(WXHWND hWndFocus
);
269 virtual void MSWOnShow(bool show
, int status
);
271 // TODO: rationalise these functions into 1 or 2 which take the
272 // event type as argument.
273 virtual void MSWOnLButtonDown(int x
, int y
, WXUINT flags
);
274 virtual void MSWOnLButtonUp(int x
, int y
, WXUINT flags
);
275 virtual void MSWOnLButtonDClick(int x
, int y
, WXUINT flags
);
277 virtual void MSWOnMButtonDown(int x
, int y
, WXUINT flags
);
278 virtual void MSWOnMButtonUp(int x
, int y
, WXUINT flags
);
279 virtual void MSWOnMButtonDClick(int x
, int y
, WXUINT flags
);
281 virtual void MSWOnRButtonDown(int x
, int y
, WXUINT flags
);
282 virtual void MSWOnRButtonUp(int x
, int y
, WXUINT flags
);
283 virtual void MSWOnRButtonDClick(int x
, int y
, WXUINT flags
);
285 virtual void MSWOnMouseMove(int x
, int y
, WXUINT flags
);
286 virtual void MSWOnMouseEnter(int x
, int y
, WXUINT flags
);
287 virtual void MSWOnMouseLeave(int x
, int y
, WXUINT flags
);
289 // These return TRUE if an event handler was found, FALSE otherwise (not processed)
290 virtual bool MSWOnChar(WXWORD wParam
, WXLPARAM lParam
, bool isASCII
= FALSE
);
291 virtual bool MSWOnKeyDown(WXWORD wParam
, WXLPARAM lParam
);
292 virtual bool MSWOnKeyUp(WXWORD wParam
, WXLPARAM lParam
);
294 virtual bool MSWOnActivate(int flag
, bool minimized
, WXHWND activate
);
295 virtual long MSWOnMDIActivate(long flag
, WXHWND activate
, WXHWND deactivate
);
297 virtual bool MSWOnDrawItem(int id
, WXDRAWITEMSTRUCT
*item
);
298 virtual bool MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*item
);
300 virtual void MSWOnJoyDown(int joystick
, int x
, int y
, WXUINT flags
);
301 virtual void MSWOnJoyUp(int joystick
, int x
, int y
, WXUINT flags
);
302 virtual void MSWOnJoyMove(int joystick
, int x
, int y
, WXUINT flags
);
303 virtual void MSWOnJoyZMove(int joystick
, int z
, WXUINT flags
);
305 virtual long MSWGetDlgCode();
308 virtual long MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
310 // Calls an appropriate default window procedure
311 virtual long MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
);
312 virtual bool MSWProcessMessage(WXMSG
* pMsg
);
313 virtual bool MSWTranslateMessage(WXMSG
* pMsg
);
314 virtual void MSWDestroyWindow();
316 // Detach "Window" menu from menu bar so it doesn't get deleted
317 void MSWDetachWindowMenu();
319 inline WXFARPROC
MSWGetOldWndProc() const;
320 inline void MSWSetOldWndProc(WXFARPROC proc
);
322 // Define for each class of dialog and control
323 virtual WXHBRUSH
OnCtlColor(WXHDC pDC
, WXHWND pWnd
, WXUINT nCtlColor
,
324 WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
);
326 #if WXWIN_COMPATIBILITY
327 void SetShowing(bool show
) { (void)Show(show
); }
328 bool IsUserEnabled() const { return IsEnabled(); }
329 #endif // WXWIN_COMPATIBILITY
331 // Responds to colour changes: passes event on to children.
332 void OnSysColourChanged(wxSysColourChangedEvent
& event
);
334 // remember the parameters of the last message
335 void PushLastMessage(WXUINT msg
, WXWPARAM wParam
, WXLPARAM lParam
)
338 m_lastWParam
= wParam
;
339 m_lastLParam
= lParam
;
343 // the old window proc (we subclass all windows)
344 WXFARPROC m_oldWndProc
;
346 // additional (MSW specific) flags
347 bool m_useCtl3D
:1; // Using CTL3D for this control
348 bool m_inOnSize
:1; // Protection against OnSize reentry
349 bool m_backgroundTransparent
:1;
350 bool m_mouseInWindow
:1;
351 bool m_doubleClickAllowed
:1;
352 bool m_winCaptured
:1;
355 bool m_caretEnabled
:1;
360 // the size of one page for scrolling
364 // the coordinates of the last mouse event and the typoe of it
367 int m_lastMouseEvent
;
369 // the parameters of the last message used in Default()
371 WXWPARAM m_lastWParam
;
372 WXLPARAM m_lastLParam
;
374 WXHMENU m_hMenu
; // Menu, if any
376 wxButton
*m_btnDefault
;
378 // implement the base class pure virtuals
379 virtual void DoGetPosition( int *x
, int *y
) const;
380 virtual void DoGetSize( int *width
, int *height
) const;
381 virtual void DoGetClientSize( int *width
, int *height
) const;
382 virtual void DoSetSize(int x
, int y
,
383 int width
, int height
,
384 int sizeFlags
= wxSIZE_AUTO
);
385 virtual void DoSetClientSize(int width
, int height
);
388 virtual void DoSetToolTip( wxToolTip
*tip
);
389 #endif // wxUSE_TOOLTIPS
392 // common part of all ctors
395 DECLARE_EVENT_TABLE()
398 // ---------------------------------------------------------------------------
400 // ---------------------------------------------------------------------------
402 // kbd code translation
403 WXDLLEXPORT
int wxCharCodeMSWToWX(int keySym
);
404 WXDLLEXPORT
int wxCharCodeWXToMSW(int id
, bool *IsVirtual
);