]>
Commit | Line | Data |
---|---|---|
f03fc89f | 1 | /////////////////////////////////////////////////////////////////////////////// |
23895080 | 2 | // Name: wx/window.h |
789295bf | 3 | // Purpose: wxWindowBase class - the interface of wxWindow |
f03fc89f | 4 | // Author: Vadim Zeitlin |
566d84a7 | 5 | // Modified by: Ron Lee |
f03fc89f VZ |
6 | // Created: 01/02/97 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWindows team | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_WINDOW_H_BASE_ |
13 | #define _WX_WINDOW_H_BASE_ | |
c801d85f | 14 | |
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
58654ed0 VZ |
16 | #pragma interface "windowbase.h" |
17 | #endif | |
18 | ||
f03fc89f VZ |
19 | // ---------------------------------------------------------------------------- |
20 | // headers which we must include here | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | #include "wx/event.h" // the base class | |
24 | ||
25 | #include "wx/list.h" // defines wxWindowList | |
26 | ||
27 | #include "wx/cursor.h" // we have member variables of these classes | |
28 | #include "wx/font.h" // so we can't do without them | |
29 | #include "wx/colour.h" | |
30 | #include "wx/region.h" | |
5e4ff78a | 31 | #include "wx/utils.h" |
88ac883a | 32 | |
674ac8b9 | 33 | #include "wx/validate.h" // for wxDefaultValidator (always include it) |
8d99be5f | 34 | |
574c939e | 35 | #if wxUSE_PALETTE |
d577d610 | 36 | #include "wx/palette.h" |
574c939e KB |
37 | #endif // wxUSE_PALETTE |
38 | ||
88ac883a VZ |
39 | #if wxUSE_ACCEL |
40 | #include "wx/accel.h" | |
41 | #endif // wxUSE_ACCEL | |
f03fc89f | 42 | |
45a959a3 JS |
43 | #if wxUSE_ACCESSIBILITY |
44 | #include "wx/access.h" | |
45 | #endif | |
46 | ||
6522713c VZ |
47 | // when building wxUniv/Foo we don't want the code for native menu use to be |
48 | // compiled in - it should only be used when building real wxFoo | |
49 | #ifdef __WXUNIVERSAL__ | |
50 | #define wxUSE_MENUS_NATIVE 0 | |
51 | #else // __WXMSW__ | |
52 | #define wxUSE_MENUS_NATIVE wxUSE_MENUS | |
53 | #endif // __WXUNIVERSAL__/__WXMSW__ | |
54 | ||
f03fc89f VZ |
55 | // ---------------------------------------------------------------------------- |
56 | // forward declarations | |
57 | // ---------------------------------------------------------------------------- | |
58 | ||
789295bf | 59 | class WXDLLEXPORT wxCaret; |
f03fc89f VZ |
60 | class WXDLLEXPORT wxControl; |
61 | class WXDLLEXPORT wxCursor; | |
eb082a08 | 62 | class WXDLLEXPORT wxDC; |
f03fc89f VZ |
63 | class WXDLLEXPORT wxDropTarget; |
64 | class WXDLLEXPORT wxItemResource; | |
65 | class WXDLLEXPORT wxLayoutConstraints; | |
66 | class WXDLLEXPORT wxResourceTable; | |
67 | class WXDLLEXPORT wxSizer; | |
68 | class WXDLLEXPORT wxToolTip; | |
f03fc89f VZ |
69 | class WXDLLEXPORT wxWindowBase; |
70 | class WXDLLEXPORT wxWindow; | |
71 | ||
45a959a3 JS |
72 | #if wxUSE_ACCESSIBILITY |
73 | class WXDLLEXPORT wxAccessible; | |
74 | #endif | |
75 | ||
f03fc89f VZ |
76 | // ---------------------------------------------------------------------------- |
77 | // (pseudo)template list classes | |
78 | // ---------------------------------------------------------------------------- | |
79 | ||
f6bcfd97 | 80 | WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT); |
f03fc89f VZ |
81 | |
82 | // ---------------------------------------------------------------------------- | |
83 | // global variables | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows; | |
87 | ||
f03fc89f VZ |
88 | // ---------------------------------------------------------------------------- |
89 | // wxWindowBase is the base class for all GUI controls/widgets, this is the public | |
90 | // interface of this class. | |
91 | // | |
92 | // Event handler: windows have themselves as their event handlers by default, | |
93 | // but their event handlers could be set to another object entirely. This | |
94 | // separation can reduce the amount of derivation required, and allow | |
95 | // alteration of a window's functionality (e.g. by a resource editor that | |
96 | // temporarily switches event handlers). | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
99 | class WXDLLEXPORT wxWindowBase : public wxEvtHandler | |
100 | { | |
f03fc89f VZ |
101 | public: |
102 | // creating the window | |
103 | // ------------------- | |
104 | ||
105 | // default ctor | |
106 | wxWindowBase() { InitBase(); } | |
107 | ||
108 | // pseudo ctor (can't be virtual, called from ctor) | |
109 | bool CreateBase(wxWindowBase *parent, | |
d9e2e4c2 | 110 | wxWindowID winid, |
f03fc89f VZ |
111 | const wxPoint& pos = wxDefaultPosition, |
112 | const wxSize& size = wxDefaultSize, | |
113 | long style = 0, | |
8d99be5f | 114 | const wxValidator& validator = wxDefaultValidator, |
f03fc89f VZ |
115 | const wxString& name = wxPanelNameStr); |
116 | ||
117 | virtual ~wxWindowBase(); | |
118 | ||
f03fc89f VZ |
119 | // deleting the window |
120 | // ------------------- | |
121 | ||
122 | // ask the window to close itself, return TRUE if the event handler | |
123 | // honoured our request | |
124 | bool Close( bool force = FALSE ); | |
125 | ||
126 | // the following functions delete the C++ objects (the window itself | |
127 | // or its children) as well as the GUI windows and normally should | |
128 | // never be used directly | |
129 | ||
130 | // delete window unconditionally (dangerous!), returns TRUE if ok | |
131 | virtual bool Destroy(); | |
132 | // delete all children of this window, returns TRUE if ok | |
133 | bool DestroyChildren(); | |
134 | ||
135 | // is the window being deleted? | |
136 | bool IsBeingDeleted() const { return m_isBeingDeleted; } | |
137 | ||
138 | // window attributes | |
139 | // ----------------- | |
140 | ||
456bc6d9 VZ |
141 | // NB: in future versions of wxWindows Set/GetTitle() will only work |
142 | // with the top level windows (such as dialogs and frames) and | |
143 | // Set/GetLabel() only with the other ones (i.e. all controls). | |
144 | ||
f03fc89f VZ |
145 | // the title (or label, see below) of the window: the text which the |
146 | // window shows | |
fe6b43a3 VS |
147 | virtual void SetTitle( const wxString& WXUNUSED(title) ) {} |
148 | virtual wxString GetTitle() const { return wxEmptyString; } | |
f03fc89f VZ |
149 | |
150 | // label is just the same as the title (but for, e.g., buttons it | |
151 | // makes more sense to speak about labels) | |
eba0e4d4 RR |
152 | virtual void SetLabel(const wxString& label) { SetTitle(label); } |
153 | virtual wxString GetLabel() const { return GetTitle(); } | |
f03fc89f VZ |
154 | |
155 | // the window name is used for ressource setting in X, it is not the | |
156 | // same as the window title/label | |
157 | virtual void SetName( const wxString &name ) { m_windowName = name; } | |
158 | virtual wxString GetName() const { return m_windowName; } | |
159 | ||
160 | // window id uniquely identifies the window among its siblings unless | |
161 | // it is -1 which means "don't care" | |
d9e2e4c2 | 162 | void SetId( wxWindowID winid ) { m_windowId = winid; } |
f03fc89f VZ |
163 | wxWindowID GetId() const { return m_windowId; } |
164 | ||
165 | // generate a control id for the controls which were not given one by | |
166 | // user | |
69418a8e | 167 | static int NewControlId() { return --ms_lastControlId; } |
c539ab55 VZ |
168 | // get the id of the control following the one with the given |
169 | // (autogenerated) id | |
d9e2e4c2 | 170 | static int NextControlId(int winid) { return winid - 1; } |
c539ab55 VZ |
171 | // get the id of the control preceding the one with the given |
172 | // (autogenerated) id | |
d9e2e4c2 | 173 | static int PrevControlId(int winid) { return winid + 1; } |
f03fc89f VZ |
174 | |
175 | // moving/resizing | |
176 | // --------------- | |
177 | ||
178 | // set the window size and/or position | |
179 | void SetSize( int x, int y, int width, int height, | |
180 | int sizeFlags = wxSIZE_AUTO ) | |
181 | { DoSetSize(x, y, width, height, sizeFlags); } | |
182 | ||
183 | void SetSize( int width, int height ) | |
184 | { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); } | |
185 | ||
186 | void SetSize( const wxSize& size ) | |
187 | { SetSize( size.x, size.y); } | |
188 | ||
189 | void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO) | |
190 | { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); } | |
191 | ||
1e6feb95 VZ |
192 | void Move(int x, int y, int flags = wxSIZE_USE_EXISTING) |
193 | { DoSetSize(x, y, -1, -1, flags); } | |
f03fc89f | 194 | |
1e6feb95 VZ |
195 | void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING) |
196 | { Move(pt.x, pt.y, flags); } | |
f03fc89f VZ |
197 | |
198 | // Z-order | |
199 | virtual void Raise() = 0; | |
200 | virtual void Lower() = 0; | |
201 | ||
202 | // client size is the size of area available for subwindows | |
203 | void SetClientSize( int width, int height ) | |
204 | { DoSetClientSize(width, height); } | |
205 | ||
206 | void SetClientSize( const wxSize& size ) | |
207 | { DoSetClientSize(size.x, size.y); } | |
208 | ||
209 | void SetClientSize(const wxRect& rect) | |
210 | { SetClientSize( rect.width, rect.height ); } | |
211 | ||
212 | // get the window position and/or size (pointers may be NULL) | |
213 | void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); } | |
214 | wxPoint GetPosition() const | |
215 | { | |
216 | int w, h; | |
217 | DoGetPosition(&w, &h); | |
218 | ||
219 | return wxPoint(w, h); | |
220 | } | |
221 | ||
222 | void GetSize( int *w, int *h ) const { DoGetSize(w, h); } | |
223 | wxSize GetSize() const | |
224 | { | |
225 | int w, h; | |
226 | DoGetSize(& w, & h); | |
227 | return wxSize(w, h); | |
228 | } | |
229 | ||
230 | wxRect GetRect() const | |
231 | { | |
232 | int x, y, w, h; | |
233 | GetPosition(& x, & y); | |
234 | GetSize(& w, & h); | |
235 | ||
236 | return wxRect(x, y, w, h); | |
237 | } | |
238 | ||
239 | void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); } | |
240 | wxSize GetClientSize() const | |
241 | { | |
242 | int w, h; | |
243 | DoGetClientSize(& w, & h); | |
244 | ||
245 | return wxSize(w, h); | |
246 | } | |
247 | ||
1e6feb95 VZ |
248 | // get the origin of the client area of the window relative to the |
249 | // window top left corner (the client area may be shifted because of | |
250 | // the borders, scrollbars, other decorations...) | |
251 | virtual wxPoint GetClientAreaOrigin() const; | |
252 | ||
253 | // get the client rectangle in window (i.e. client) coordinates | |
254 | wxRect GetClientRect() const | |
255 | { | |
256 | return wxRect(GetClientAreaOrigin(), GetClientSize()); | |
257 | } | |
258 | ||
f68586e5 VZ |
259 | // get the size best suited for the window (in fact, minimal |
260 | // acceptable size using which it will still look "nice") | |
261 | wxSize GetBestSize() const { return DoGetBestSize(); } | |
262 | void GetBestSize(int *w, int *h) const | |
263 | { | |
264 | wxSize s = DoGetBestSize(); | |
265 | if ( w ) | |
266 | *w = s.x; | |
267 | if ( h ) | |
268 | *h = s.y; | |
269 | } | |
270 | ||
2b5f62a0 VZ |
271 | // There are times (and windows) where 'Best' size and 'Min' size |
272 | // are vastly out of sync. This should be remedied somehow, but in | |
273 | // the meantime, this method will return the larger of BestSize | |
274 | // (the window's smallest legible size), and any user specified | |
275 | // MinSize hint. | |
276 | wxSize GetAdjustedBestSize() const | |
277 | { | |
278 | wxSize s( DoGetBestSize() ); | |
279 | return wxSize( wxMax( s.x, GetMinWidth() ), wxMax( s.y, GetMinHeight() ) ); | |
280 | } | |
281 | ||
282 | // the generic centre function - centers the window on parent by` | |
7eb4e9cc VZ |
283 | // default or on screen if it doesn't have parent or |
284 | // wxCENTER_ON_SCREEN flag is given | |
c39eda94 VZ |
285 | void Centre( int direction = wxBOTH ); |
286 | void Center( int direction = wxBOTH ) { Centre(direction); } | |
7eb4e9cc VZ |
287 | |
288 | // centre on screen (only works for top level windows) | |
289 | void CentreOnScreen(int dir = wxBOTH) { Centre(dir | wxCENTER_ON_SCREEN); } | |
290 | void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); } | |
291 | ||
292 | // centre with respect to the the parent window | |
293 | void CentreOnParent(int dir = wxBOTH) { Centre(dir | wxCENTER_FRAME); } | |
294 | void CenterOnParent(int dir = wxBOTH) { CentreOnParent(dir); } | |
f03fc89f VZ |
295 | |
296 | // set window size to wrap around its children | |
297 | virtual void Fit(); | |
298 | ||
2b5f62a0 VZ |
299 | // set virtual size to satisfy children |
300 | virtual void FitInside(); | |
301 | ||
f03fc89f VZ |
302 | // set min/max size of the window |
303 | virtual void SetSizeHints( int minW, int minH, | |
304 | int maxW = -1, int maxH = -1, | |
305 | int incW = -1, int incH = -1 ); | |
306 | ||
566d84a7 RL |
307 | virtual void SetVirtualSizeHints( int minW, int minH, |
308 | int maxW = -1, int maxH = -1 ); | |
309 | ||
e7dda1ff VS |
310 | virtual int GetMinWidth() const { return m_minWidth; } |
311 | virtual int GetMinHeight() const { return m_minHeight; } | |
738f9e5a RR |
312 | int GetMaxWidth() const { return m_maxWidth; } |
313 | int GetMaxHeight() const { return m_maxHeight; } | |
57c4d796 | 314 | |
34c3ffca RL |
315 | // Override this method to control the values given to Sizers etc. |
316 | virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); } | |
317 | ||
566d84a7 RL |
318 | // Methods for accessing the virtual size of a window. For most |
319 | // windows this is just the client area of the window, but for | |
320 | // some like scrolled windows it is more or less independent of | |
321 | // the screen window size. You may override the DoXXXVirtual | |
322 | // methods below for classes where that is is the case. | |
323 | ||
324 | void SetVirtualSize( const wxSize &size ) { DoSetVirtualSize( size.x, size.y ); } | |
325 | void SetVirtualSize( int x, int y ) { DoSetVirtualSize( x, y ); } | |
326 | ||
327 | wxSize GetVirtualSize() const { return DoGetVirtualSize(); } | |
328 | void GetVirtualSize( int *x, int *y ) const | |
329 | { | |
330 | wxSize s( DoGetVirtualSize() ); | |
331 | ||
332 | if( x ) | |
333 | *x = s.GetWidth(); | |
334 | if( y ) | |
335 | *y = s.GetHeight(); | |
336 | } | |
337 | ||
338 | // Override these methods for windows that have a virtual size | |
339 | // independent of their client size. eg. the virtual area of a | |
340 | // wxScrolledWindow. Default is to alias VirtualSize to ClientSize. | |
341 | ||
342 | virtual void DoSetVirtualSize( int x, int y ); | |
343 | virtual wxSize DoGetVirtualSize() const; // { return m_virtualSize; } | |
344 | ||
2b5f62a0 VZ |
345 | // Return the largest of ClientSize and BestSize (as determined |
346 | // by a sizer, interior children, or other means) | |
347 | ||
348 | virtual wxSize GetBestVirtualSize() const | |
349 | { | |
350 | wxSize client( GetClientSize() ); | |
351 | wxSize best( GetBestSize() ); | |
352 | ||
353 | return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) ); | |
354 | } | |
355 | ||
f03fc89f VZ |
356 | // window state |
357 | // ------------ | |
358 | ||
359 | // returns TRUE if window was shown/hidden, FALSE if the nothing was | |
360 | // done (window was already shown/hidden) | |
361 | virtual bool Show( bool show = TRUE ); | |
362 | bool Hide() { return Show(FALSE); } | |
363 | ||
364 | // returns TRUE if window was enabled/disabled, FALSE if nothing done | |
365 | virtual bool Enable( bool enable = TRUE ); | |
366 | bool Disable() { return Enable(FALSE); } | |
367 | ||
368 | bool IsShown() const { return m_isShown; } | |
369 | bool IsEnabled() const { return m_isEnabled; } | |
370 | ||
371 | // get/set window style (setting style won't update the window and so | |
372 | // is only useful for internal usage) | |
373 | virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; } | |
374 | virtual long GetWindowStyleFlag() const { return m_windowStyle; } | |
375 | ||
376 | // just some (somewhat shorter) synonims | |
377 | void SetWindowStyle( long style ) { SetWindowStyleFlag(style); } | |
378 | long GetWindowStyle() const { return GetWindowStyleFlag(); } | |
379 | ||
380 | bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; } | |
d80cd92a | 381 | virtual bool IsRetained() const { return HasFlag(wxRETAINED); } |
f03fc89f | 382 | |
d80cd92a VZ |
383 | // extra style: the less often used style bits which can't be set with |
384 | // SetWindowStyleFlag() | |
b2d5a7ee | 385 | virtual void SetExtraStyle(long exStyle) { m_exStyle = exStyle; } |
d80cd92a | 386 | long GetExtraStyle() const { return m_exStyle; } |
f03fc89f VZ |
387 | |
388 | // make the window modal (all other windows unresponsive) | |
389 | virtual void MakeModal(bool modal = TRUE); | |
390 | ||
a2d93e73 JS |
391 | virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; } |
392 | virtual bool GetThemeEnabled() const { return m_themeEnabled; } | |
393 | ||
456bc6d9 VZ |
394 | // focus and keyboard handling |
395 | // --------------------------- | |
f03fc89f VZ |
396 | |
397 | // set focus to this window | |
398 | virtual void SetFocus() = 0; | |
399 | ||
d577d610 VZ |
400 | // set focus to this window as the result of a keyboard action |
401 | virtual void SetFocusFromKbd() { SetFocus(); } | |
402 | ||
f03fc89f VZ |
403 | // return the window which currently has the focus or NULL |
404 | static wxWindow *FindFocus() /* = 0: implement in derived classes */; | |
405 | ||
406 | // can this window have focus? | |
407 | virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); } | |
408 | ||
1e6feb95 VZ |
409 | // can this window be given focus by keyboard navigation? if not, the |
410 | // only way to give it focus (provided it accepts it at all) is to | |
411 | // click it | |
412 | virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); } | |
413 | ||
456bc6d9 VZ |
414 | // NB: these methods really don't belong here but with the current |
415 | // class hierarchy there is no other place for them :-( | |
416 | ||
417 | // get the default child of this parent, i.e. the one which is | |
418 | // activated by pressing <Enter> | |
419 | virtual wxWindow *GetDefaultItem() const { return NULL; } | |
420 | ||
421 | // set this child as default, return the old default | |
422 | virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child)) | |
423 | { return NULL; } | |
424 | ||
036da5e3 VZ |
425 | // set this child as temporary default |
426 | virtual void SetTmpDefaultItem(wxWindow * WXUNUSED(win)) { } | |
427 | ||
f03fc89f VZ |
428 | // parent/children relations |
429 | // ------------------------- | |
430 | ||
431 | // get the list of children | |
432 | const wxWindowList& GetChildren() const { return m_children; } | |
433 | wxWindowList& GetChildren() { return m_children; } | |
434 | ||
435 | // get the parent or the parent of the parent | |
436 | wxWindow *GetParent() const { return m_parent; } | |
437 | inline wxWindow *GetGrandParent() const; | |
438 | ||
439 | // is this window a top level one? | |
8487f887 | 440 | virtual bool IsTopLevel() const; |
f03fc89f VZ |
441 | |
442 | // it doesn't really change parent, use ReParent() instead | |
443 | void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; } | |
444 | // change the real parent of this window, return TRUE if the parent | |
445 | // was changed, FALSE otherwise (error or newParent == oldParent) | |
446 | virtual bool Reparent( wxWindowBase *newParent ); | |
447 | ||
146ba0fe VZ |
448 | // implementation mostly |
449 | virtual void AddChild( wxWindowBase *child ); | |
450 | virtual void RemoveChild( wxWindowBase *child ); | |
451 | ||
452 | // looking for windows | |
453 | // ------------------- | |
454 | ||
f03fc89f VZ |
455 | // find window among the descendants of this one either by id or by |
456 | // name (return NULL if not found) | |
d9e2e4c2 | 457 | wxWindow *FindWindow( long winid ); |
f03fc89f VZ |
458 | wxWindow *FindWindow( const wxString& name ); |
459 | ||
146ba0fe | 460 | // Find a window among any window (all return NULL if not found) |
d9e2e4c2 | 461 | static wxWindow *FindWindowById( long winid, const wxWindow *parent = NULL ); |
146ba0fe VZ |
462 | static wxWindow *FindWindowByName( const wxString& name, |
463 | const wxWindow *parent = NULL ); | |
464 | static wxWindow *FindWindowByLabel( const wxString& label, | |
465 | const wxWindow *parent = NULL ); | |
f03fc89f VZ |
466 | |
467 | // event handler stuff | |
468 | // ------------------- | |
469 | ||
470 | // get the current event handler | |
471 | wxEvtHandler *GetEventHandler() const { return m_eventHandler; } | |
472 | ||
473 | // replace the event handler (allows to completely subclass the | |
474 | // window) | |
475 | void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; } | |
476 | ||
477 | // push/pop event handler: allows to chain a custom event handler to | |
478 | // alreasy existing ones | |
479 | void PushEventHandler( wxEvtHandler *handler ); | |
480 | wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE ); | |
481 | ||
2e36d5cf VZ |
482 | // find the given handler in the event handler chain and remove (but |
483 | // not delete) it from the event handler chain, return TRUE if it was | |
484 | // found and FALSE otherwise (this also results in an assert failure so | |
485 | // this function should only be called when the handler is supposed to | |
486 | // be there) | |
487 | bool RemoveEventHandler(wxEvtHandler *handler); | |
488 | ||
1e6feb95 VZ |
489 | // validators |
490 | // ---------- | |
f03fc89f | 491 | |
88ac883a | 492 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
493 | // a window may have an associated validator which is used to control |
494 | // user input | |
495 | virtual void SetValidator( const wxValidator &validator ); | |
496 | virtual wxValidator *GetValidator() { return m_windowValidator; } | |
88ac883a | 497 | #endif // wxUSE_VALIDATORS |
f03fc89f | 498 | |
f03fc89f VZ |
499 | |
500 | // dialog oriented functions | |
501 | // ------------------------- | |
502 | ||
503 | // validate the correctness of input, return TRUE if ok | |
504 | virtual bool Validate(); | |
505 | ||
506 | // transfer data between internal and GUI representations | |
507 | virtual bool TransferDataToWindow(); | |
508 | virtual bool TransferDataFromWindow(); | |
509 | ||
510 | virtual void InitDialog(); | |
511 | ||
88ac883a | 512 | #if wxUSE_ACCEL |
f03fc89f VZ |
513 | // accelerators |
514 | // ------------ | |
515 | virtual void SetAcceleratorTable( const wxAcceleratorTable& accel ) | |
516 | { m_acceleratorTable = accel; } | |
517 | wxAcceleratorTable *GetAcceleratorTable() | |
518 | { return &m_acceleratorTable; } | |
88ac883a | 519 | #endif // wxUSE_ACCEL |
f03fc89f VZ |
520 | |
521 | // dialog units translations | |
522 | // ------------------------- | |
523 | ||
524 | wxPoint ConvertPixelsToDialog( const wxPoint& pt ); | |
525 | wxPoint ConvertDialogToPixels( const wxPoint& pt ); | |
526 | wxSize ConvertPixelsToDialog( const wxSize& sz ) | |
527 | { | |
528 | wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); | |
529 | ||
530 | return wxSize(pt.x, pt.y); | |
531 | } | |
532 | ||
533 | wxSize ConvertDialogToPixels( const wxSize& sz ) | |
534 | { | |
535 | wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); | |
536 | ||
537 | return wxSize(pt.x, pt.y); | |
538 | } | |
539 | ||
540 | // mouse functions | |
541 | // --------------- | |
542 | ||
543 | // move the mouse to the specified position | |
544 | virtual void WarpPointer(int x, int y) = 0; | |
545 | ||
94633ad9 VZ |
546 | // start or end mouse capture, these functions maintain the stack of |
547 | // windows having captured the mouse and after calling ReleaseMouse() | |
548 | // the mouse is not released but returns to the window which had had | |
549 | // captured it previously (if any) | |
550 | void CaptureMouse(); | |
551 | void ReleaseMouse(); | |
f03fc89f | 552 | |
1e6feb95 VZ |
553 | // get the window which currently captures the mouse or NULL |
554 | static wxWindow *GetCapture(); | |
555 | ||
556 | // does this window have the capture? | |
557 | virtual bool HasCapture() const | |
558 | { return (wxWindow *)this == GetCapture(); } | |
559 | ||
f03fc89f VZ |
560 | // painting the window |
561 | // ------------------- | |
562 | ||
563 | // mark the specified rectangle (or the whole window) as "dirty" so it | |
564 | // will be repainted | |
565 | virtual void Refresh( bool eraseBackground = TRUE, | |
566 | const wxRect *rect = (const wxRect *) NULL ) = 0; | |
1e6feb95 VZ |
567 | |
568 | // a less awkward wrapper for Refresh | |
569 | void RefreshRect(const wxRect& rect) { Refresh(TRUE, &rect); } | |
570 | ||
571 | // repaint all invalid areas of the window immediately | |
572 | virtual void Update() { } | |
573 | ||
f03fc89f VZ |
574 | // clear the window entirely |
575 | virtual void Clear() = 0; | |
576 | ||
0cc7251e VZ |
577 | // freeze the window: don't redraw it until it is thawed |
578 | virtual void Freeze() { } | |
579 | ||
580 | // thaw the window: redraw it after it had been frozen | |
581 | virtual void Thaw() { } | |
582 | ||
f03fc89f | 583 | // adjust DC for drawing on this window |
f6147cfc | 584 | virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { } |
f03fc89f VZ |
585 | |
586 | // the update region of the window contains the areas which must be | |
587 | // repainted by the program | |
588 | const wxRegion& GetUpdateRegion() const { return m_updateRegion; } | |
589 | wxRegion& GetUpdateRegion() { return m_updateRegion; } | |
590 | ||
1e6feb95 VZ |
591 | // get the update rectangleregion bounding box in client coords |
592 | wxRect GetUpdateClientRect() const; | |
593 | ||
f03fc89f VZ |
594 | // these functions verify whether the given point/rectangle belongs to |
595 | // (or at least intersects with) the update region | |
596 | bool IsExposed( int x, int y ) const; | |
597 | bool IsExposed( int x, int y, int w, int h ) const; | |
598 | ||
599 | bool IsExposed( const wxPoint& pt ) const | |
600 | { return IsExposed(pt.x, pt.y); } | |
601 | bool IsExposed( const wxRect& rect ) const | |
602 | { return IsExposed(rect.x, rect.y, rect.width, rect.height); } | |
603 | ||
604 | // colours, fonts and cursors | |
605 | // -------------------------- | |
606 | ||
607 | // set/retrieve the window colours (system defaults are used by | |
608 | // default): Set functions return TRUE if colour was changed | |
609 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
610 | virtual bool SetForegroundColour( const wxColour &colour ); | |
611 | ||
612 | wxColour GetBackgroundColour() const { return m_backgroundColour; } | |
613 | wxColour GetForegroundColour() const { return m_foregroundColour; } | |
614 | ||
615 | // set/retrieve the cursor for this window (SetCursor() returns TRUE | |
616 | // if the cursor was really changed) | |
617 | virtual bool SetCursor( const wxCursor &cursor ); | |
618 | const wxCursor& GetCursor() const { return m_cursor; } | |
619 | wxCursor& GetCursor() { return m_cursor; } | |
620 | ||
621 | // set/retrieve the font for the window (SetFont() returns TRUE if the | |
622 | // font really changed) | |
623 | virtual bool SetFont( const wxFont &font ) = 0; | |
624 | const wxFont& GetFont() const { return m_font; } | |
625 | wxFont& GetFont() { return m_font; } | |
626 | ||
789295bf VZ |
627 | #if wxUSE_CARET |
628 | // associate a caret with the window | |
629 | void SetCaret(wxCaret *caret); | |
630 | // get the current caret (may be NULL) | |
631 | wxCaret *GetCaret() const { return m_caret; } | |
632 | #endif // wxUSE_CARET | |
633 | ||
f03fc89f VZ |
634 | // get the (average) character size for the current font |
635 | virtual int GetCharHeight() const = 0; | |
636 | virtual int GetCharWidth() const = 0; | |
637 | ||
638 | // get the width/height/... of the text using current or specified | |
639 | // font | |
640 | virtual void GetTextExtent(const wxString& string, | |
641 | int *x, int *y, | |
642 | int *descent = (int *) NULL, | |
643 | int *externalLeading = (int *) NULL, | |
644 | const wxFont *theFont = (const wxFont *) NULL) | |
645 | const = 0; | |
646 | ||
1e6feb95 VZ |
647 | // client <-> screen coords |
648 | // ------------------------ | |
649 | ||
f03fc89f | 650 | // translate to/from screen/client coordinates (pointers may be NULL) |
dabc0cd5 VZ |
651 | void ClientToScreen( int *x, int *y ) const |
652 | { DoClientToScreen(x, y); } | |
653 | void ScreenToClient( int *x, int *y ) const | |
654 | { DoScreenToClient(x, y); } | |
1e6feb95 VZ |
655 | |
656 | // wxPoint interface to do the same thing | |
dabc0cd5 VZ |
657 | wxPoint ClientToScreen(const wxPoint& pt) const |
658 | { | |
659 | int x = pt.x, y = pt.y; | |
660 | DoClientToScreen(&x, &y); | |
661 | ||
662 | return wxPoint(x, y); | |
663 | } | |
664 | ||
665 | wxPoint ScreenToClient(const wxPoint& pt) const | |
666 | { | |
667 | int x = pt.x, y = pt.y; | |
668 | DoScreenToClient(&x, &y); | |
669 | ||
670 | return wxPoint(x, y); | |
671 | } | |
f03fc89f | 672 | |
1e6feb95 VZ |
673 | // test where the given (in client coords) point lies |
674 | wxHitTest HitTest(wxCoord x, wxCoord y) const | |
675 | { return DoHitTest(x, y); } | |
676 | ||
677 | wxHitTest HitTest(const wxPoint& pt) const | |
678 | { return DoHitTest(pt.x, pt.y); } | |
679 | ||
f03fc89f VZ |
680 | // misc |
681 | // ---- | |
682 | ||
aede4ebb VZ |
683 | // get the window border style from the given flags: this is different from |
684 | // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to | |
685 | // translate wxBORDER_DEFAULT to something reasonable | |
686 | wxBorder GetBorder(long flags) const; | |
687 | ||
688 | // get border for the flags of this window | |
689 | wxBorder GetBorder() const { return GetBorder(GetWindowStyleFlag()); } | |
1e6feb95 | 690 | |
f03fc89f VZ |
691 | void UpdateWindowUI(); |
692 | ||
1e6feb95 | 693 | #if wxUSE_MENUS |
a1665b22 VZ |
694 | bool PopupMenu( wxMenu *menu, const wxPoint& pos ) |
695 | { return DoPopupMenu(menu, pos.x, pos.y); } | |
696 | bool PopupMenu( wxMenu *menu, int x, int y ) | |
697 | { return DoPopupMenu(menu, x, y); } | |
1e6feb95 | 698 | #endif // wxUSE_MENUS |
f03fc89f VZ |
699 | |
700 | // scrollbars | |
701 | // ---------- | |
702 | ||
1e6feb95 VZ |
703 | // does the window have the scrollbar for this orientation? |
704 | bool HasScrollbar(int orient) const | |
705 | { | |
706 | return (m_windowStyle & | |
707 | (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0; | |
708 | } | |
709 | ||
f03fc89f VZ |
710 | // configure the window scrollbars |
711 | virtual void SetScrollbar( int orient, | |
712 | int pos, | |
1e6feb95 | 713 | int thumbvisible, |
f03fc89f VZ |
714 | int range, |
715 | bool refresh = TRUE ) = 0; | |
716 | virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0; | |
717 | virtual int GetScrollPos( int orient ) const = 0; | |
718 | virtual int GetScrollThumb( int orient ) const = 0; | |
719 | virtual int GetScrollRange( int orient ) const = 0; | |
720 | ||
721 | // scroll window to the specified position | |
722 | virtual void ScrollWindow( int dx, int dy, | |
723 | const wxRect* rect = (wxRect *) NULL ) = 0; | |
724 | ||
b9b3393e | 725 | // scrolls window by line/page: note that not all controls support this |
9cd6d737 VZ |
726 | // |
727 | // return TRUE if the position changed, FALSE otherwise | |
728 | virtual bool ScrollLines(int WXUNUSED(lines)) { return FALSE; } | |
729 | virtual bool ScrollPages(int WXUNUSED(pages)) { return FALSE; } | |
730 | ||
731 | // convenient wrappers for ScrollLines/Pages | |
732 | bool LineUp() { return ScrollLines(-1); } | |
733 | bool LineDown() { return ScrollLines(1); } | |
734 | bool PageUp() { return ScrollPages(-1); } | |
735 | bool PageDown() { return ScrollPages(1); } | |
b9b3393e | 736 | |
bd83cb56 VZ |
737 | // context-sensitive help |
738 | // ---------------------- | |
739 | ||
740 | // these are the convenience functions wrapping wxHelpProvider methods | |
741 | ||
742 | #if wxUSE_HELP | |
743 | // associate this help text with this window | |
744 | void SetHelpText(const wxString& text); | |
745 | // associate this help text with all windows with the same id as this | |
746 | // one | |
747 | void SetHelpTextForId(const wxString& text); | |
748 | // get the help string associated with this window (may be empty) | |
749 | wxString GetHelpText() const; | |
750 | #endif // wxUSE_HELP | |
751 | ||
f03fc89f VZ |
752 | // tooltips |
753 | // -------- | |
bd83cb56 | 754 | |
f03fc89f VZ |
755 | #if wxUSE_TOOLTIPS |
756 | // the easiest way to set a tooltip for a window is to use this method | |
757 | void SetToolTip( const wxString &tip ); | |
758 | // attach a tooltip to the window | |
759 | void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); } | |
760 | // get the associated tooltip or NULL if none | |
761 | wxToolTip* GetToolTip() const { return m_tooltip; } | |
762 | #endif // wxUSE_TOOLTIPS | |
763 | ||
764 | // drag and drop | |
765 | // ------------- | |
766 | #if wxUSE_DRAG_AND_DROP | |
767 | // set/retrieve the drop target associated with this window (may be | |
768 | // NULL; it's owned by the window and will be deleted by it) | |
769 | virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0; | |
770 | virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; } | |
771 | #endif // wxUSE_DRAG_AND_DROP | |
772 | ||
773 | // constraints and sizers | |
774 | // ---------------------- | |
775 | #if wxUSE_CONSTRAINTS | |
776 | // set the constraints for this window or retrieve them (may be NULL) | |
777 | void SetConstraints( wxLayoutConstraints *constraints ); | |
778 | wxLayoutConstraints *GetConstraints() const { return m_constraints; } | |
779 | ||
f03fc89f VZ |
780 | // implementation only |
781 | void UnsetConstraints(wxLayoutConstraints *c); | |
782 | wxWindowList *GetConstraintsInvolvedIn() const | |
783 | { return m_constraintsInvolvedIn; } | |
784 | void AddConstraintReference(wxWindowBase *otherWin); | |
785 | void RemoveConstraintReference(wxWindowBase *otherWin); | |
786 | void DeleteRelatedConstraints(); | |
787 | void ResetConstraints(); | |
788 | ||
789 | // these methods may be overriden for special layout algorithms | |
790 | virtual void SetConstraintSizes(bool recurse = TRUE); | |
791 | virtual bool LayoutPhase1(int *noChanges); | |
792 | virtual bool LayoutPhase2(int *noChanges); | |
4b7f2165 | 793 | virtual bool DoPhase(int phase); |
f03fc89f VZ |
794 | |
795 | // these methods are virtual but normally won't be overridden | |
f03fc89f VZ |
796 | virtual void SetSizeConstraint(int x, int y, int w, int h); |
797 | virtual void MoveConstraint(int x, int y); | |
798 | virtual void GetSizeConstraint(int *w, int *h) const ; | |
799 | virtual void GetClientSizeConstraint(int *w, int *h) const ; | |
800 | virtual void GetPositionConstraint(int *x, int *y) const ; | |
801 | ||
461e93f9 JS |
802 | #endif // wxUSE_CONSTRAINTS |
803 | ||
804 | // when using constraints or sizers, it makes sense to update | |
805 | // children positions automatically whenever the window is resized | |
806 | // - this is done if autoLayout is on | |
807 | void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; } | |
808 | bool GetAutoLayout() const { return m_autoLayout; } | |
809 | ||
810 | // lay out the window and its children | |
811 | virtual bool Layout(); | |
812 | ||
f03fc89f | 813 | // sizers |
3aa5d532 | 814 | void SetSizer(wxSizer *sizer, bool deleteOld = TRUE ); |
566d84a7 RL |
815 | void SetSizerAndFit( wxSizer *sizer, bool deleteOld = TRUE ); |
816 | ||
f03fc89f | 817 | wxSizer *GetSizer() const { return m_windowSizer; } |
be90c029 RD |
818 | |
819 | // Track if this window is a member of a sizer | |
820 | void SetContainingSizer(wxSizer* sizer) { m_containingSizer = sizer; } | |
821 | wxSizer *GetContainingSizer() const { return m_containingSizer; } | |
822 | ||
45a959a3 JS |
823 | // accessibility |
824 | // ---------------------- | |
825 | #if wxUSE_ACCESSIBILITY | |
826 | // Override to create a specific accessible object. | |
827 | virtual wxAccessible* CreateAccessible(); | |
828 | ||
829 | // Sets the accessible object. | |
830 | void SetAccessible(wxAccessible* accessible) ; | |
831 | ||
832 | // Returns the accessible object. | |
833 | wxAccessible* GetAccessible() { return m_accessible; }; | |
834 | ||
835 | // Returns the accessible object, creating if necessary. | |
836 | wxAccessible* GetOrCreateAccessible() ; | |
837 | #endif | |
838 | ||
f03fc89f VZ |
839 | // backward compatibility |
840 | // ---------------------- | |
841 | #if WXWIN_COMPATIBILITY | |
842 | bool Enabled() const { return IsEnabled(); } | |
843 | ||
844 | void SetButtonFont(const wxFont& font) { SetFont(font); } | |
845 | void SetLabelFont(const wxFont& font) { SetFont(font); } | |
846 | wxFont& GetLabelFont() { return GetFont(); }; | |
847 | wxFont& GetButtonFont() { return GetFont(); }; | |
848 | #endif // WXWIN_COMPATIBILITY | |
849 | ||
850 | // implementation | |
851 | // -------------- | |
852 | ||
853 | // event handlers | |
854 | void OnSysColourChanged( wxSysColourChangedEvent& event ); | |
855 | void OnInitDialog( wxInitDialogEvent &event ); | |
72fc5caf | 856 | void OnMiddleClick( wxMouseEvent& event ); |
bd83cb56 VZ |
857 | #if wxUSE_HELP |
858 | void OnHelp(wxHelpEvent& event); | |
859 | #endif // wxUSE_HELP | |
f03fc89f | 860 | |
d7c24517 VZ |
861 | // get the haqndle of the window for the underlying window system: this |
862 | // is only used for wxWin itself or for user code which wants to call | |
863 | // platform-specific APIs | |
d22699b5 | 864 | virtual WXWidget GetHandle() const = 0; |
cc2b7472 | 865 | |
574c939e KB |
866 | #if wxUSE_PALETTE |
867 | // Store the palette used by DCs in wxWindow so that the dcs can share | |
868 | // a palette. And we can respond to palette messages. | |
869 | wxPalette GetPalette() const { return m_palette; } | |
b95edd47 | 870 | |
574c939e KB |
871 | // When palette is changed tell the DC to set the system palette to the |
872 | // new one. | |
b95edd47 VZ |
873 | void SetPalette(const wxPalette& pal); |
874 | ||
875 | // return true if we have a specific palette | |
876 | bool HasCustomPalette() const { return m_hasCustomPalette; } | |
877 | ||
878 | // return the first parent window with a custom palette or NULL | |
879 | wxWindow *GetAncestorWithCustomPalette() const; | |
574c939e KB |
880 | #endif // wxUSE_PALETTE |
881 | ||
739730ca | 882 | protected: |
4caf847c VZ |
883 | // event handling specific to wxWindow |
884 | #if wxUSE_VALIDATORS | |
885 | virtual bool TryValidator(wxEvent& event); | |
886 | #endif // wxUSE_VALIDATORS | |
887 | virtual bool TryParent(wxEvent& event); | |
888 | ||
889 | ||
ec5bb70d VZ |
890 | #if wxUSE_CONSTRAINTS |
891 | // satisfy the constraints for the windows but don't set the window sizes | |
892 | void SatisfyConstraints(); | |
893 | #endif // wxUSE_CONSTRAINTS | |
566d84a7 | 894 | |
7de59551 RD |
895 | // Send the wxWindowDestroyEvent |
896 | void SendDestroyEvent(); | |
897 | ||
7af6f327 | 898 | // the window id - a number which uniquely identifies a window among |
d7c24517 | 899 | // its siblings unless it is -1 |
f03fc89f | 900 | wxWindowID m_windowId; |
456bc6d9 | 901 | |
f03fc89f VZ |
902 | // the parent window of this window (or NULL) and the list of the children |
903 | // of this window | |
904 | wxWindow *m_parent; | |
905 | wxWindowList m_children; | |
906 | ||
907 | // the minimal allowed size for the window (no minimal size if variable(s) | |
908 | // contain(s) -1) | |
ec5bb70d VZ |
909 | int m_minWidth, |
910 | m_minHeight, | |
911 | m_maxWidth, | |
912 | m_maxHeight; | |
f03fc89f VZ |
913 | |
914 | // event handler for this window: usually is just 'this' but may be | |
915 | // changed with SetEventHandler() | |
916 | wxEvtHandler *m_eventHandler; | |
917 | ||
88ac883a | 918 | #if wxUSE_VALIDATORS |
f03fc89f VZ |
919 | // associated validator or NULL if none |
920 | wxValidator *m_windowValidator; | |
88ac883a | 921 | #endif // wxUSE_VALIDATORS |
f03fc89f VZ |
922 | |
923 | #if wxUSE_DRAG_AND_DROP | |
924 | wxDropTarget *m_dropTarget; | |
925 | #endif // wxUSE_DRAG_AND_DROP | |
926 | ||
927 | // visual window attributes | |
928 | wxCursor m_cursor; | |
929 | wxFont m_font; | |
930 | wxColour m_backgroundColour, m_foregroundColour; | |
931 | ||
789295bf VZ |
932 | #if wxUSE_CARET |
933 | wxCaret *m_caret; | |
934 | #endif // wxUSE_CARET | |
935 | ||
f03fc89f VZ |
936 | // the region which should be repainted in response to paint event |
937 | wxRegion m_updateRegion; | |
938 | ||
88ac883a | 939 | #if wxUSE_ACCEL |
f03fc89f VZ |
940 | // the accelerator table for the window which translates key strokes into |
941 | // command events | |
942 | wxAcceleratorTable m_acceleratorTable; | |
88ac883a | 943 | #endif // wxUSE_ACCEL |
f03fc89f | 944 | |
f03fc89f VZ |
945 | // the tooltip for this window (may be NULL) |
946 | #if wxUSE_TOOLTIPS | |
947 | wxToolTip *m_tooltip; | |
948 | #endif // wxUSE_TOOLTIPS | |
949 | ||
950 | // constraints and sizers | |
951 | #if wxUSE_CONSTRAINTS | |
952 | // the constraints for this window or NULL | |
953 | wxLayoutConstraints *m_constraints; | |
954 | ||
955 | // constraints this window is involved in | |
956 | wxWindowList *m_constraintsInvolvedIn; | |
461e93f9 | 957 | #endif // wxUSE_CONSTRAINTS |
f03fc89f | 958 | |
be90c029 | 959 | // this window's sizer |
f03fc89f | 960 | wxSizer *m_windowSizer; |
be90c029 RD |
961 | |
962 | // The sizer this window is a member of, if any | |
963 | wxSizer *m_containingSizer; | |
f03fc89f VZ |
964 | |
965 | // Layout() window automatically when its size changes? | |
966 | bool m_autoLayout:1; | |
f03fc89f VZ |
967 | |
968 | // window state | |
969 | bool m_isShown:1; | |
970 | bool m_isEnabled:1; | |
971 | bool m_isBeingDeleted:1; | |
972 | ||
23895080 VZ |
973 | // was the window colours/font explicitly changed by user? |
974 | bool m_hasBgCol:1; | |
975 | bool m_hasFgCol:1; | |
976 | bool m_hasFont:1; | |
977 | ||
f03fc89f | 978 | // window attributes |
d80cd92a VZ |
979 | long m_windowStyle, |
980 | m_exStyle; | |
f03fc89f | 981 | wxString m_windowName; |
a2d93e73 | 982 | bool m_themeEnabled; |
f03fc89f | 983 | |
071e5fd9 | 984 | #if wxUSE_PALETTE |
574c939e | 985 | wxPalette m_palette; |
b95edd47 VZ |
986 | bool m_hasCustomPalette; |
987 | #endif // wxUSE_PALETTE | |
574c939e | 988 | |
45a959a3 JS |
989 | #if wxUSE_ACCESSIBILITY |
990 | wxAccessible* m_accessible; | |
991 | #endif | |
566d84a7 RL |
992 | // Virtual size (scrolling) |
993 | wxSize m_virtualSize; | |
994 | ||
995 | int m_minVirtualWidth; // VirtualSizeHints | |
996 | int m_minVirtualHeight; | |
997 | int m_maxVirtualWidth; | |
998 | int m_maxVirtualHeight; | |
45e0dc94 | 999 | |
f03fc89f VZ |
1000 | // common part of all ctors: it is not virtual because it is called from |
1001 | // ctor | |
1002 | void InitBase(); | |
1003 | ||
1e6feb95 VZ |
1004 | // override this to change the default (i.e. used when no style is |
1005 | // specified) border for the window class | |
1006 | virtual wxBorder GetDefaultBorder() const; | |
1007 | ||
f03fc89f | 1008 | // get the default size for the new window if no explicit size given |
1349f4f2 RR |
1009 | // FIXME why 20 and not 30, 10 or ...? |
1010 | static int WidthDefault(int w) { return w == -1 ? 20 : w; } | |
1011 | static int HeightDefault(int h) { return h == -1 ? 20 : h; } | |
f03fc89f | 1012 | |
1e6feb95 VZ |
1013 | // set the best size for the control if the default size was given: |
1014 | // replaces the fields of size == -1 with the best values for them and | |
1015 | // calls SetSize() if needed | |
2b5f62a0 VZ |
1016 | // |
1017 | // This function is rather unfortunately named.. it's really just a | |
1018 | // smarter SetSize / convenience function for expanding wxDefaultSize. | |
1019 | // Note that it does not influence the value returned by GetBestSize | |
1020 | // at all. | |
1e6feb95 | 1021 | void SetBestSize(const wxSize& size) |
f68586e5 | 1022 | { |
2b5f62a0 VZ |
1023 | // the size only needs to be changed if the current size is incomplete, |
1024 | // i.e. one of the components was specified as default -- so if both | |
1025 | // were given, simply don't do anything | |
f68586e5 VZ |
1026 | if ( size.x == -1 || size.y == -1 ) |
1027 | { | |
1e6feb95 VZ |
1028 | wxSize sizeBest = DoGetBestSize(); |
1029 | if ( size.x != -1 ) | |
1030 | sizeBest.x = size.x; | |
1031 | if ( size.y != -1 ) | |
1032 | sizeBest.y = size.y; | |
1033 | ||
1034 | SetSize(sizeBest); | |
f68586e5 VZ |
1035 | } |
1036 | } | |
1037 | ||
f03fc89f VZ |
1038 | // more pure virtual functions |
1039 | // --------------------------- | |
1040 | ||
1041 | // NB: we must have DoSomething() function when Something() is an overloaded | |
1042 | // method: indeed, we can't just have "virtual Something()" in case when | |
1043 | // the function is overloaded because then we'd have to make virtual all | |
1044 | // the variants (otherwise only the virtual function may be called on a | |
1045 | // pointer to derived class according to C++ rules) which is, in | |
1046 | // general, absolutely not needed. So instead we implement all | |
1047 | // overloaded Something()s in terms of DoSomething() which will be the | |
1048 | // only one to be virtual. | |
1049 | ||
dabc0cd5 VZ |
1050 | // coordinates translation |
1051 | virtual void DoClientToScreen( int *x, int *y ) const = 0; | |
1052 | virtual void DoScreenToClient( int *x, int *y ) const = 0; | |
1053 | ||
1e6feb95 VZ |
1054 | virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const; |
1055 | ||
94633ad9 | 1056 | // capture/release the mouse, used by Capture/ReleaseMouse() |
a83e1475 VZ |
1057 | virtual void DoCaptureMouse() = 0; |
1058 | virtual void DoReleaseMouse() = 0; | |
be90c029 | 1059 | |
f03fc89f VZ |
1060 | // retrieve the position/size of the window |
1061 | virtual void DoGetPosition( int *x, int *y ) const = 0; | |
1062 | virtual void DoGetSize( int *width, int *height ) const = 0; | |
1063 | virtual void DoGetClientSize( int *width, int *height ) const = 0; | |
1064 | ||
f68586e5 VZ |
1065 | // get the size which best suits the window: for a control, it would be |
1066 | // the minimal size which doesn't truncate the control, for a panel - the | |
1067 | // same size as it would have after a call to Fit() | |
1068 | virtual wxSize DoGetBestSize() const; | |
1069 | ||
f03fc89f VZ |
1070 | // this is the virtual function to be overriden in any derived class which |
1071 | // wants to change how SetSize() or Move() works - it is called by all | |
1072 | // versions of these functions in the base class | |
1073 | virtual void DoSetSize(int x, int y, | |
1074 | int width, int height, | |
1075 | int sizeFlags = wxSIZE_AUTO) = 0; | |
1076 | ||
1077 | // same as DoSetSize() for the client size | |
1078 | virtual void DoSetClientSize(int width, int height) = 0; | |
1079 | ||
9d9b7755 VZ |
1080 | // move the window to the specified location and resize it: this is called |
1081 | // from both DoSetSize() and DoSetClientSize() and would usually just | |
1082 | // reposition this window except for composite controls which will want to | |
1083 | // arrange themselves inside the given rectangle | |
1084 | virtual void DoMoveWindow(int x, int y, int width, int height) = 0; | |
1085 | ||
f03fc89f VZ |
1086 | #if wxUSE_TOOLTIPS |
1087 | virtual void DoSetToolTip( wxToolTip *tip ); | |
1088 | #endif // wxUSE_TOOLTIPS | |
1089 | ||
1e6feb95 | 1090 | #if wxUSE_MENUS |
a1665b22 | 1091 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0; |
1e6feb95 | 1092 | #endif // wxUSE_MENUS |
a1665b22 | 1093 | |
a200c35e VS |
1094 | // Makes an adjustment to the window position (for example, a frame that has |
1095 | // a toolbar that it manages itself). | |
20a1eea1 | 1096 | virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const; |
8d99be5f | 1097 | |
45e0dc94 | 1098 | |
f03fc89f | 1099 | private: |
45e0dc94 | 1100 | |
f03fc89f VZ |
1101 | // contains the last id generated by NewControlId |
1102 | static int ms_lastControlId; | |
1103 | ||
a83e1475 VZ |
1104 | // the stack of windows which have captured the mouse |
1105 | static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext; | |
1106 | ||
1e6feb95 VZ |
1107 | DECLARE_ABSTRACT_CLASS(wxWindowBase) |
1108 | DECLARE_NO_COPY_CLASS(wxWindowBase) | |
f03fc89f VZ |
1109 | DECLARE_EVENT_TABLE() |
1110 | }; | |
1111 | ||
1112 | // ---------------------------------------------------------------------------- | |
1113 | // now include the declaration of wxWindow class | |
1114 | // ---------------------------------------------------------------------------- | |
1115 | ||
1e6feb95 | 1116 | // include the declaration of the platform-specific class |
2049ba38 | 1117 | #if defined(__WXMSW__) |
a5b3669d VZ |
1118 | #ifdef __WXUNIVERSAL__ |
1119 | #define wxWindowNative wxWindowMSW | |
1120 | #else // !wxUniv | |
1e6feb95 VZ |
1121 | #define wxWindowMSW wxWindow |
1122 | #define sm_classwxWindowMSW sm_classwxWindow | |
a5b3669d | 1123 | #endif // wxUniv/!wxUniv |
f03fc89f | 1124 | #include "wx/msw/window.h" |
2049ba38 | 1125 | #elif defined(__WXMOTIF__) |
f03fc89f | 1126 | #include "wx/motif/window.h" |
2049ba38 | 1127 | #elif defined(__WXGTK__) |
a5b3669d VZ |
1128 | #ifdef __WXUNIVERSAL__ |
1129 | #define wxWindowNative wxWindowGTK | |
1130 | #else // !wxUniv | |
1e6feb95 VZ |
1131 | #define wxWindowGTK wxWindow |
1132 | #define sm_classwxWindowGTK sm_classwxWindow | |
1133 | #endif // wxUniv | |
f03fc89f | 1134 | #include "wx/gtk/window.h" |
83df96d6 JS |
1135 | #elif defined(__WXX11__) |
1136 | #ifdef __WXUNIVERSAL__ | |
1137 | #define wxWindowNative wxWindowX11 | |
1138 | #else // !wxUniv | |
1139 | #define wxWindowX11 wxWindow | |
1140 | #define sm_classwxWindowX11 sm_classwxWindow | |
1141 | #endif // wxUniv | |
1142 | #include "wx/x11/window.h" | |
711c76db | 1143 | #elif defined(__WXMGL__) |
386c7058 VS |
1144 | #ifdef __WXUNIVERSAL__ |
1145 | #define wxWindowNative wxWindowMGL | |
1146 | #else // !wxUniv | |
1147 | #define wxWindowMGL wxWindow | |
1148 | #define sm_classwxWindowMGL sm_classwxWindow | |
1149 | #endif // wxUniv | |
1150 | #include "wx/mgl/window.h" | |
34138703 | 1151 | #elif defined(__WXMAC__) |
e766c8a9 SC |
1152 | #ifdef __WXUNIVERSAL__ |
1153 | #define wxWindowNative wxWindowMac | |
1154 | #else // !wxUniv | |
1155 | #define wxWindowMac wxWindow | |
1156 | #define sm_classwxWindowMac sm_classwxWindow | |
1157 | #endif // wxUniv | |
f03fc89f | 1158 | #include "wx/mac/window.h" |
e64df9bc DE |
1159 | #elif defined(__WXCOCOA__) |
1160 | #ifdef __WXUNIVERSAL__ | |
1161 | #define wxWindowNative wxWindowCocoa | |
1162 | #else // !wxUniv | |
1163 | #define wxWindowCocoa wxWindow | |
1164 | #define sm_classwxWindowCocoa sm_classwxWindow | |
1165 | #endif // wxUniv | |
1166 | #include "wx/cocoa/window.h" | |
1777b9bb | 1167 | #elif defined(__WXPM__) |
210a651b DW |
1168 | #ifdef __WXUNIVERSAL__ |
1169 | #define wxWindowNative wxWindowOS2 | |
1170 | #else // !wxUniv | |
1171 | #define wxWindowOS2 wxWindow | |
1172 | #define sm_classwxWindowOS2 sm_classwxWindow | |
1173 | #endif // wxUniv/!wxUniv | |
1777b9bb | 1174 | #include "wx/os2/window.h" |
c801d85f KB |
1175 | #endif |
1176 | ||
1e6feb95 VZ |
1177 | // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>, |
1178 | // for the native ports we already have defined it above | |
1179 | #if defined(__WXUNIVERSAL__) | |
a5b3669d VZ |
1180 | #ifndef wxWindowNative |
1181 | #error "wxWindowNative must be defined above!" | |
1182 | #endif | |
1183 | ||
1e6feb95 VZ |
1184 | #include "wx/univ/window.h" |
1185 | #endif // wxUniv | |
1186 | ||
f03fc89f VZ |
1187 | // ---------------------------------------------------------------------------- |
1188 | // inline functions which couldn't be declared in the class body because of | |
1189 | // forward dependencies | |
1190 | // ---------------------------------------------------------------------------- | |
1191 | ||
bacd69f9 | 1192 | inline wxWindow *wxWindowBase::GetGrandParent() const |
f03fc89f VZ |
1193 | { |
1194 | return m_parent ? m_parent->GetParent() : (wxWindow *)NULL; | |
1195 | } | |
1196 | ||
1197 | // ---------------------------------------------------------------------------- | |
3723b7b1 | 1198 | // global functions |
f03fc89f VZ |
1199 | // ---------------------------------------------------------------------------- |
1200 | ||
3723b7b1 JS |
1201 | // Find the wxWindow at the current mouse position, also returning the mouse |
1202 | // position. | |
1203 | WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt); | |
1204 | ||
1205 | // Get the current mouse position. | |
1206 | WXDLLEXPORT extern wxPoint wxGetMousePosition(); | |
1207 | ||
1e6feb95 VZ |
1208 | // get the currently active window of this application or NULL |
1209 | WXDLLEXPORT extern wxWindow *wxGetActiveWindow(); | |
1210 | ||
33b494d6 VZ |
1211 | // get the (first) top level parent window |
1212 | WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win); | |
1213 | ||
f68586e5 | 1214 | // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId() |
6d56eb5c | 1215 | inline int NewControlId() { return wxWindowBase::NewControlId(); } |
f03fc89f | 1216 | |
45a959a3 JS |
1217 | #if wxUSE_ACCESSIBILITY |
1218 | // ---------------------------------------------------------------------------- | |
1219 | // accessible object for windows | |
1220 | // ---------------------------------------------------------------------------- | |
1221 | ||
1222 | class WXDLLEXPORT wxWindowAccessible: public wxAccessible | |
1223 | { | |
1224 | public: | |
f81387bd | 1225 | wxWindowAccessible(wxWindow* win): wxAccessible(win) { if (win) win->SetAccessible(this); } |
45a959a3 JS |
1226 | virtual ~wxWindowAccessible() {}; |
1227 | ||
1228 | // Overridables | |
1229 | ||
1230 | // Can return either a child object, or an integer | |
1231 | // representing the child element, starting from 1. | |
1232 | virtual wxAccStatus HitTest(const wxPoint& pt, int* childId, wxAccessible** childObject); | |
1233 | ||
1234 | // Returns the rectangle for this object (id = 0) or a child element (id > 0). | |
1235 | virtual wxAccStatus GetLocation(wxRect& rect, int elementId); | |
1236 | ||
1237 | // Navigates from fromId to toId/toObject. | |
1238 | virtual wxAccStatus Navigate(wxNavDir navDir, int fromId, | |
1239 | int* toId, wxAccessible** toObject); | |
1240 | ||
1241 | // Gets the name of the specified object. | |
1242 | virtual wxAccStatus GetName(int childId, wxString* name); | |
1243 | ||
1244 | // Gets the number of children. | |
a37e4a07 | 1245 | virtual wxAccStatus GetChildCount(int* childCount); |
45a959a3 JS |
1246 | |
1247 | // Gets the specified child (starting from 1). | |
1248 | // If *child is NULL and return value is wxACC_OK, | |
1249 | // this means that the child is a simple element and | |
1250 | // not an accessible object. | |
1251 | virtual wxAccStatus GetChild(int childId, wxAccessible** child); | |
1252 | ||
1253 | // Gets the parent, or NULL. | |
1254 | virtual wxAccStatus GetParent(wxAccessible** parent); | |
1255 | ||
1256 | // Performs the default action. childId is 0 (the action for this object) | |
1257 | // or > 0 (the action for a child). | |
1258 | // Return wxACC_NOT_SUPPORTED if there is no default action for this | |
1259 | // window (e.g. an edit control). | |
1260 | virtual wxAccStatus DoDefaultAction(int childId); | |
1261 | ||
1262 | // Gets the default action for this object (0) or > 0 (the action for a child). | |
1263 | // Return wxACC_OK even if there is no action. actionName is the action, or the empty | |
1264 | // string if there is no action. | |
1265 | // The retrieved string describes the action that is performed on an object, | |
1266 | // not what the object does as a result. For example, a toolbar button that prints | |
1267 | // a document has a default action of "Press" rather than "Prints the current document." | |
1268 | virtual wxAccStatus GetDefaultAction(int childId, wxString* actionName); | |
1269 | ||
1270 | // Returns the description for this object or a child. | |
1271 | virtual wxAccStatus GetDescription(int childId, wxString* description); | |
1272 | ||
1273 | // Returns help text for this object or a child, similar to tooltip text. | |
1274 | virtual wxAccStatus GetHelpText(int childId, wxString* helpText); | |
1275 | ||
1276 | // Returns the keyboard shortcut for this object or child. | |
1277 | // Return e.g. ALT+K | |
1278 | virtual wxAccStatus GetKeyboardShortcut(int childId, wxString* shortcut); | |
1279 | ||
1280 | // Returns a role constant. | |
1281 | virtual wxAccStatus GetRole(int childId, wxAccRole* role); | |
1282 | ||
1283 | // Returns a state constant. | |
1284 | virtual wxAccStatus GetState(int childId, long* state); | |
1285 | ||
1286 | // Returns a localized string representing the value for the object | |
1287 | // or child. | |
1288 | virtual wxAccStatus GetValue(int childId, wxString* strValue); | |
1289 | ||
1290 | // Selects the object or child. | |
1291 | virtual wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags); | |
1292 | ||
1293 | // Gets the window with the keyboard focus. | |
1294 | // If childId is 0 and child is NULL, no object in | |
1295 | // this subhierarchy has the focus. | |
1296 | // If this object has the focus, child should be 'this'. | |
1297 | virtual wxAccStatus GetFocus(int* childId, wxAccessible** child); | |
1298 | ||
1299 | // Gets a variant representing the selected children | |
1300 | // of this object. | |
1301 | // Acceptable values: | |
1302 | // - a null variant (IsNull() returns TRUE) | |
1303 | // - a list variant (GetType() == wxT("list") | |
1304 | // - an integer representing the selected child element, | |
1305 | // or 0 if this object is selected (GetType() == wxT("long") | |
1306 | // - a "void*" pointer to a wxAccessible child object | |
1307 | virtual wxAccStatus GetSelections(wxVariant* selections); | |
1308 | }; | |
1309 | ||
1310 | #endif // wxUSE_ACCESSIBILITY | |
1311 | ||
1312 | ||
c801d85f | 1313 | #endif |
34138703 | 1314 | // _WX_WINDOW_H_BASE_ |
34c3ffca | 1315 |