]> git.saurik.com Git - wxWidgets.git/blob - include/wx/window.h
added wxWindow::ClientToWindowSize and WindowToClientSize helpers
[wxWidgets.git] / include / wx / window.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/window.h
3 // Purpose: wxWindowBase class - the interface of wxWindow
4 // Author: Vadim Zeitlin
5 // Modified by: Ron Lee
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
14
15 // ----------------------------------------------------------------------------
16 // headers which we must include here
17 // ----------------------------------------------------------------------------
18
19 #include "wx/event.h" // the base class
20
21 #include "wx/list.h" // defines wxWindowList
22
23 #include "wx/cursor.h" // we have member variables of these classes
24 #include "wx/font.h" // so we can't do without them
25 #include "wx/colour.h"
26 #include "wx/region.h"
27 #include "wx/utils.h"
28 #include "wx/intl.h"
29
30 #include "wx/validate.h" // for wxDefaultValidator (always include it)
31
32 #if wxUSE_PALETTE
33 #include "wx/palette.h"
34 #endif // wxUSE_PALETTE
35
36 #if wxUSE_ACCEL
37 #include "wx/accel.h"
38 #endif // wxUSE_ACCEL
39
40 #if wxUSE_ACCESSIBILITY
41 #include "wx/access.h"
42 #endif
43
44 // when building wxUniv/Foo we don't want the code for native menu use to be
45 // compiled in - it should only be used when building real wxFoo
46 #ifdef __WXUNIVERSAL__
47 #define wxUSE_MENUS_NATIVE 0
48 #else // !__WXUNIVERSAL__
49 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
50 #endif // __WXUNIVERSAL__/!__WXUNIVERSAL__
51
52
53 // Define this macro if the corresponding operating system handles the state
54 // of children windows automatically when the parent is enabled/disabled.
55 // Otherwise wx itself must ensure that when the parent is disabled its
56 // children are disabled too, and their initial state is restored when the
57 // parent is enabled back.
58 #if defined(__WXMSW__) || defined(__WXPM__)
59 // must do everything ourselves
60 #undef wxHAS_NATIVE_ENABLED_MANAGEMENT
61 #else
62 #define wxHAS_NATIVE_ENABLED_MANAGEMENT
63 #endif
64
65 // ----------------------------------------------------------------------------
66 // forward declarations
67 // ----------------------------------------------------------------------------
68
69 class WXDLLIMPEXP_FWD_CORE wxCaret;
70 class WXDLLIMPEXP_FWD_CORE wxControl;
71 class WXDLLIMPEXP_FWD_CORE wxCursor;
72 class WXDLLIMPEXP_FWD_CORE wxDC;
73 class WXDLLIMPEXP_FWD_CORE wxDropTarget;
74 class WXDLLIMPEXP_FWD_CORE wxLayoutConstraints;
75 class WXDLLIMPEXP_FWD_CORE wxSizer;
76 class WXDLLIMPEXP_FWD_CORE wxToolTip;
77 class WXDLLIMPEXP_FWD_CORE wxWindowBase;
78 class WXDLLIMPEXP_FWD_CORE wxWindow;
79 class WXDLLIMPEXP_FWD_CORE wxScrollHelper;
80
81 #if wxUSE_ACCESSIBILITY
82 class WXDLLIMPEXP_FWD_CORE wxAccessible;
83 #endif
84
85 // ----------------------------------------------------------------------------
86 // helper stuff used by wxWindow
87 // ----------------------------------------------------------------------------
88
89 // struct containing all the visual attributes of a control
90 struct WXDLLEXPORT wxVisualAttributes
91 {
92 // the font used for control label/text inside it
93 wxFont font;
94
95 // the foreground colour
96 wxColour colFg;
97
98 // the background colour, may be wxNullColour if the controls background
99 // colour is not solid
100 wxColour colBg;
101 };
102
103 // different window variants, on platforms like eg mac uses different
104 // rendering sizes
105 enum wxWindowVariant
106 {
107 wxWINDOW_VARIANT_NORMAL, // Normal size
108 wxWINDOW_VARIANT_SMALL, // Smaller size (about 25 % smaller than normal)
109 wxWINDOW_VARIANT_MINI, // Mini size (about 33 % smaller than normal)
110 wxWINDOW_VARIANT_LARGE, // Large size (about 25 % larger than normal)
111 wxWINDOW_VARIANT_MAX
112 };
113
114 #if wxUSE_SYSTEM_OPTIONS
115 #define wxWINDOW_DEFAULT_VARIANT wxT("window-default-variant")
116 #endif
117
118 // valid values for Show/HideWithEffect()
119 enum wxShowEffect
120 {
121 wxSHOW_EFFECT_ROLL,
122 wxSHOW_EFFECT_SLIDE,
123 wxSHOW_EFFECT_BLEND,
124 wxSHOW_EFFECT_EXPAND,
125 wxSHOW_EFFECT_MAX
126 };
127
128 // ----------------------------------------------------------------------------
129 // (pseudo)template list classes
130 // ----------------------------------------------------------------------------
131
132 WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT);
133
134 // ----------------------------------------------------------------------------
135 // global variables
136 // ----------------------------------------------------------------------------
137
138 extern WXDLLEXPORT_DATA(wxWindowList) wxTopLevelWindows;
139 extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete;
140
141 // ----------------------------------------------------------------------------
142 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
143 // interface of this class.
144 //
145 // Event handler: windows have themselves as their event handlers by default,
146 // but their event handlers could be set to another object entirely. This
147 // separation can reduce the amount of derivation required, and allow
148 // alteration of a window's functionality (e.g. by a resource editor that
149 // temporarily switches event handlers).
150 // ----------------------------------------------------------------------------
151
152 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
153 {
154 public:
155 // creating the window
156 // -------------------
157
158 // default ctor, initializes everything which can be initialized before
159 // Create()
160 wxWindowBase() ;
161
162 // pseudo ctor (can't be virtual, called from ctor)
163 bool CreateBase(wxWindowBase *parent,
164 wxWindowID winid,
165 const wxPoint& pos = wxDefaultPosition,
166 const wxSize& size = wxDefaultSize,
167 long style = 0,
168 const wxValidator& validator = wxDefaultValidator,
169 const wxString& name = wxPanelNameStr);
170
171 virtual ~wxWindowBase();
172
173 // deleting the window
174 // -------------------
175
176 // ask the window to close itself, return true if the event handler
177 // honoured our request
178 bool Close( bool force = false );
179
180 // the following functions delete the C++ objects (the window itself
181 // or its children) as well as the GUI windows and normally should
182 // never be used directly
183
184 // delete window unconditionally (dangerous!), returns true if ok
185 virtual bool Destroy();
186 // delete all children of this window, returns true if ok
187 bool DestroyChildren();
188
189 // is the window being deleted?
190 bool IsBeingDeleted() const { return m_isBeingDeleted; }
191
192 // window attributes
193 // -----------------
194
195 // label is just the same as the title (but for, e.g., buttons it
196 // makes more sense to speak about labels), title access
197 // is available from wxTLW classes only (frames, dialogs)
198 virtual void SetLabel(const wxString& label) = 0;
199 virtual wxString GetLabel() const = 0;
200
201 // the window name is used for ressource setting in X, it is not the
202 // same as the window title/label
203 virtual void SetName( const wxString &name ) { m_windowName = name; }
204 virtual wxString GetName() const { return m_windowName; }
205
206 // sets the window variant, calls internally DoSetVariant if variant
207 // has changed
208 void SetWindowVariant(wxWindowVariant variant);
209 wxWindowVariant GetWindowVariant() const { return m_windowVariant; }
210
211
212 // get or change the layout direction (LTR or RTL) for this window,
213 // wxLayout_Default is returned if layout direction is not supported
214 virtual wxLayoutDirection GetLayoutDirection() const
215 { return wxLayout_Default; }
216 virtual void SetLayoutDirection(wxLayoutDirection WXUNUSED(dir))
217 { }
218
219 // mirror coordinates for RTL layout if this window uses it and if the
220 // mirroring is not done automatically like Win32
221 virtual wxCoord AdjustForLayoutDirection(wxCoord x,
222 wxCoord width,
223 wxCoord widthTotal) const;
224
225
226 // window id uniquely identifies the window among its siblings unless
227 // it is wxID_ANY which means "don't care"
228 void SetId( wxWindowID winid ) { m_windowId = winid; }
229 wxWindowID GetId() const { return m_windowId; }
230
231 // generate a unique id (or count of them consecutively), returns a
232 // valid id in the auto-id range or wxID_NONE if failed. If using
233 // autoid management, it will mark the id as reserved until it is
234 // used (by assigning it to a wxWindowIDRef) or unreserved.
235 static wxWindowID NewControlId(int count = 1)
236 {
237 return wxIdManager::ReserveId(count);
238 }
239
240 // If an ID generated from NewControlId is not assigned to a wxWindowIDRef,
241 // it must be unreserved
242 static void UnreserveControlId(wxWindowID id, int count = 1)
243 {
244 wxIdManager::UnreserveId(id, count);
245 }
246
247
248 // moving/resizing
249 // ---------------
250
251 // set the window size and/or position
252 void SetSize( int x, int y, int width, int height,
253 int sizeFlags = wxSIZE_AUTO )
254 { DoSetSize(x, y, width, height, sizeFlags); }
255
256 void SetSize( int width, int height )
257 { DoSetSize( wxDefaultCoord, wxDefaultCoord, width, height, wxSIZE_USE_EXISTING ); }
258
259 void SetSize( const wxSize& size )
260 { SetSize( size.x, size.y); }
261
262 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
263 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
264
265 void Move(int x, int y, int flags = wxSIZE_USE_EXISTING)
266 { DoSetSize(x, y, wxDefaultCoord, wxDefaultCoord, flags); }
267
268 void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
269 { Move(pt.x, pt.y, flags); }
270
271 void SetPosition(const wxPoint& pt) { Move(pt); }
272
273 // Z-order
274 virtual void Raise() = 0;
275 virtual void Lower() = 0;
276
277 // client size is the size of area available for subwindows
278 void SetClientSize( int width, int height )
279 { DoSetClientSize(width, height); }
280
281 void SetClientSize( const wxSize& size )
282 { DoSetClientSize(size.x, size.y); }
283
284 void SetClientSize(const wxRect& rect)
285 { SetClientSize( rect.width, rect.height ); }
286
287 // get the window position (pointers may be NULL): notice that it is in
288 // client coordinates for child windows and screen coordinates for the
289 // top level ones, use GetScreenPosition() if you need screen
290 // coordinates for all kinds of windows
291 void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); }
292 wxPoint GetPosition() const
293 {
294 int x, y;
295 DoGetPosition(&x, &y);
296
297 return wxPoint(x, y);
298 }
299
300 // get the window position in screen coordinates
301 void GetScreenPosition(int *x, int *y) const { DoGetScreenPosition(x, y); }
302 wxPoint GetScreenPosition() const
303 {
304 int x, y;
305 DoGetScreenPosition(&x, &y);
306
307 return wxPoint(x, y);
308 }
309
310 // get the window size (pointers may be NULL)
311 void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
312 wxSize GetSize() const
313 {
314 int w, h;
315 DoGetSize(& w, & h);
316 return wxSize(w, h);
317 }
318
319 void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
320 wxSize GetClientSize() const
321 {
322 int w, h;
323 DoGetClientSize(&w, &h);
324
325 return wxSize(w, h);
326 }
327
328 // get the position and size at once
329 wxRect GetRect() const
330 {
331 int x, y, w, h;
332 GetPosition(&x, &y);
333 GetSize(&w, &h);
334
335 return wxRect(x, y, w, h);
336 }
337
338 wxRect GetScreenRect() const
339 {
340 int x, y, w, h;
341 GetScreenPosition(&x, &y);
342 GetSize(&w, &h);
343
344 return wxRect(x, y, w, h);
345 }
346
347 // get the origin of the client area of the window relative to the
348 // window top left corner (the client area may be shifted because of
349 // the borders, scrollbars, other decorations...)
350 virtual wxPoint GetClientAreaOrigin() const;
351
352 // get the client rectangle in window (i.e. client) coordinates
353 wxRect GetClientRect() const
354 {
355 return wxRect(GetClientAreaOrigin(), GetClientSize());
356 }
357
358 // client<->window size conversion
359 virtual wxSize ClientToWindowSize(const wxSize& size) const;
360 virtual wxSize WindowToClientSize(const wxSize& size) const;
361
362 // get the size best suited for the window (in fact, minimal
363 // acceptable size using which it will still look "nice" in
364 // most situations)
365 wxSize GetBestSize() const
366 {
367 if (m_bestSizeCache.IsFullySpecified())
368 return m_bestSizeCache;
369 return DoGetBestSize();
370 }
371 void GetBestSize(int *w, int *h) const
372 {
373 wxSize s = GetBestSize();
374 if ( w )
375 *w = s.x;
376 if ( h )
377 *h = s.y;
378 }
379
380 void SetScrollHelper( wxScrollHelper *sh ) { m_scrollHelper = sh; }
381 wxScrollHelper *GetScrollHelper() { return m_scrollHelper; }
382
383 // reset the cached best size value so it will be recalculated the
384 // next time it is needed.
385 void InvalidateBestSize();
386 void CacheBestSize(const wxSize& size) const
387 { wxConstCast(this, wxWindowBase)->m_bestSizeCache = size; }
388
389
390 // This function will merge the window's best size into the window's
391 // minimum size, giving priority to the min size components, and
392 // returns the results.
393 wxSize GetEffectiveMinSize() const;
394 wxDEPRECATED( wxSize GetBestFittingSize() const ); // replaced by GetEffectiveMinSize
395 wxDEPRECATED( wxSize GetAdjustedMinSize() const ); // replaced by GetEffectiveMinSize
396
397 // A 'Smart' SetSize that will fill in default size values with 'best'
398 // size. Sets the minsize to what was passed in.
399 void SetInitialSize(const wxSize& size=wxDefaultSize);
400 wxDEPRECATED( void SetBestFittingSize(const wxSize& size=wxDefaultSize) ); // replaced by SetInitialSize
401
402
403 // the generic centre function - centers the window on parent by`
404 // default or on screen if it doesn't have parent or
405 // wxCENTER_ON_SCREEN flag is given
406 void Centre(int dir = wxBOTH) { DoCentre(dir); }
407 void Center(int dir = wxBOTH) { DoCentre(dir); }
408
409 // centre with respect to the the parent window
410 void CentreOnParent(int dir = wxBOTH) { DoCentre(dir); }
411 void CenterOnParent(int dir = wxBOTH) { CentreOnParent(dir); }
412
413 // set window size to wrap around its children
414 virtual void Fit();
415
416 // set virtual size to satisfy children
417 virtual void FitInside();
418
419
420 // SetSizeHints is actually for setting the size hints
421 // for the wxTLW for a Window Manager - hence the name -
422 // and it is therefore overridden in wxTLW to do that.
423 // In wxWindow(Base), it has (unfortunately) been abused
424 // to mean the same as SetMinSize() and SetMaxSize().
425
426 virtual void SetSizeHints( int minW, int minH,
427 int maxW = wxDefaultCoord, int maxH = wxDefaultCoord,
428 int incW = wxDefaultCoord, int incH = wxDefaultCoord )
429 { DoSetSizeHints(minW, minH, maxW, maxH, incW, incH); }
430
431 void SetSizeHints( const wxSize& minSize,
432 const wxSize& maxSize=wxDefaultSize,
433 const wxSize& incSize=wxDefaultSize)
434 { DoSetSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y, incSize.x, incSize.y); }
435
436
437 #if WXWIN_COMPATIBILITY_2_8
438 // these are useless and do nothing since wxWidgets 2.9
439 wxDEPRECATED( virtual void SetVirtualSizeHints( int minW, int minH,
440 int maxW = wxDefaultCoord, int maxH = wxDefaultCoord ) );
441 wxDEPRECATED( void SetVirtualSizeHints( const wxSize& minSize,
442 const wxSize& maxSize=wxDefaultSize) );
443 #endif // WXWIN_COMPATIBILITY_2_8
444
445
446 // Call these to override what GetBestSize() returns. This
447 // method is only virtual because it is overriden in wxTLW
448 // as a different API for SetSizeHints().
449 virtual void SetMinSize(const wxSize& minSize) { m_minWidth = minSize.x; m_minHeight = minSize.y; }
450 virtual void SetMaxSize(const wxSize& maxSize) { m_maxWidth = maxSize.x; m_maxHeight = maxSize.y; }
451
452 // Override these methods to impose restrictions on min/max size.
453 // The easier way is to call SetMinSize() and SetMaxSize() which
454 // will have the same effect. Doing both is non-sense.
455 virtual wxSize GetMinSize() const { return wxSize(m_minWidth, m_minHeight); }
456 virtual wxSize GetMaxSize() const { return wxSize(m_maxWidth, m_maxHeight); }
457
458 // Get the min and max values one by one
459 int GetMinWidth() const { return GetMinSize().x; }
460 int GetMinHeight() const { return GetMinSize().y; }
461 int GetMaxWidth() const { return GetMaxSize().x; }
462 int GetMaxHeight() const { return GetMaxSize().y; }
463
464
465 // Methods for accessing the virtual size of a window. For most
466 // windows this is just the client area of the window, but for
467 // some like scrolled windows it is more or less independent of
468 // the screen window size. You may override the DoXXXVirtual
469 // methods below for classes where that is is the case.
470
471 void SetVirtualSize( const wxSize &size ) { DoSetVirtualSize( size.x, size.y ); }
472 void SetVirtualSize( int x, int y ) { DoSetVirtualSize( x, y ); }
473
474 wxSize GetVirtualSize() const { return DoGetVirtualSize(); }
475 void GetVirtualSize( int *x, int *y ) const
476 {
477 wxSize s( DoGetVirtualSize() );
478
479 if( x )
480 *x = s.GetWidth();
481 if( y )
482 *y = s.GetHeight();
483 }
484
485 // Override these methods for windows that have a virtual size
486 // independent of their client size. eg. the virtual area of a
487 // wxScrolledWindow.
488
489 virtual void DoSetVirtualSize( int x, int y );
490 virtual wxSize DoGetVirtualSize() const;
491
492 // Return the largest of ClientSize and BestSize (as determined
493 // by a sizer, interior children, or other means)
494
495 virtual wxSize GetBestVirtualSize() const
496 {
497 wxSize client( GetClientSize() );
498 wxSize best( GetBestSize() );
499
500 return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) );
501 }
502
503 // return the size of the left/right and top/bottom borders in x and y
504 // components of the result respectively
505 virtual wxSize GetWindowBorderSize() const;
506
507 // wxSizer and friends use this to give a chance to a component to recalc
508 // its min size once one of the final size components is known. Override
509 // this function when that is useful (such as for wxStaticText which can
510 // stretch over several lines). Parameter availableOtherDir
511 // tells the item how much more space there is available in the opposite
512 // direction (-1 if unknown).
513 virtual bool InformFirstDirection( int WXUNUSED(direction), int WXUNUSED(size), int WXUNUSED(availableOtherDir) )
514 { return false; }
515
516 // window state
517 // ------------
518
519 // returns true if window was shown/hidden, false if the nothing was
520 // done (window was already shown/hidden)
521 virtual bool Show( bool show = true );
522 bool Hide() { return Show(false); }
523
524 // show or hide the window with a special effect, not implemented on
525 // most platforms (where it is the same as Show()/Hide() respectively)
526 //
527 // timeout specifies how long the animation should take, in ms, the
528 // default value of 0 means to use the default (system-dependent) value
529 //
530 // direction is only used with wxSHOW_EFFECT_ROLL and SLIDE values
531 virtual bool ShowWithEffect(wxShowEffect effect,
532 unsigned timeout = 0,
533 wxDirection dir = wxBOTTOM)
534 {
535 wxUnusedVar(effect);
536 wxUnusedVar(timeout);
537 wxUnusedVar(dir);
538
539 return Show();
540 }
541
542 virtual bool HideWithEffect(wxShowEffect effect,
543 unsigned timeout = 0,
544 wxDirection dir = wxBOTTOM)
545 {
546 wxUnusedVar(effect);
547 wxUnusedVar(timeout);
548 wxUnusedVar(dir);
549
550 return Hide();
551 }
552
553 // returns true if window was enabled/disabled, false if nothing done
554 virtual bool Enable( bool enable = true );
555 bool Disable() { return Enable(false); }
556
557 virtual bool IsShown() const { return m_isShown; }
558 // returns true if the window is really enabled and false otherwise,
559 // whether because it had been explicitly disabled itself or because
560 // its parent is currently disabled -- then this method returns false
561 // whatever is the intrinsic state of this window, use IsThisEnabled(0
562 // to retrieve it. In other words, this relation always holds:
563 //
564 // IsEnabled() == IsThisEnabled() && parent.IsEnabled()
565 //
566 bool IsEnabled() const;
567
568 // returns the internal window state independently of the parent(s)
569 // state, i.e. the state in which the window would be if all its
570 // parents were enabled (use IsEnabled() above to get the effective
571 // window state)
572 bool IsThisEnabled() const { return m_isEnabled; }
573
574 // returns true if the window is visible, i.e. IsShown() returns true
575 // if called on it and all its parents up to the first TLW
576 virtual bool IsShownOnScreen() const;
577
578 // get/set window style (setting style won't update the window and so
579 // is only useful for internal usage)
580 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
581 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
582
583 // just some (somewhat shorter) synonims
584 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
585 long GetWindowStyle() const { return GetWindowStyleFlag(); }
586
587 // check if the flag is set
588 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
589 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
590
591 // turn the flag on if it had been turned off before and vice versa,
592 // return true if the flag is currently turned on
593 bool ToggleWindowStyle(int flag);
594
595 // extra style: the less often used style bits which can't be set with
596 // SetWindowStyleFlag()
597 virtual void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
598 long GetExtraStyle() const { return m_exStyle; }
599
600 bool HasExtraStyle(int exFlag) const { return (m_exStyle & exFlag) != 0; }
601
602 // make the window modal (all other windows unresponsive)
603 virtual void MakeModal(bool modal = true);
604
605
606 // (primitive) theming support
607 // ---------------------------
608
609 virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
610 virtual bool GetThemeEnabled() const { return m_themeEnabled; }
611
612
613 // focus and keyboard handling
614 // ---------------------------
615
616 // set focus to this window
617 virtual void SetFocus() = 0;
618
619 // set focus to this window as the result of a keyboard action
620 virtual void SetFocusFromKbd() { SetFocus(); }
621
622 // return the window which currently has the focus or NULL
623 static wxWindow *FindFocus();
624
625 static wxWindow *DoFindFocus() /* = 0: implement in derived classes */;
626
627 // return true if the window has focus (handles composite windows
628 // correctly - returns true if GetMainWindowOfCompositeControl()
629 // has focus)
630 virtual bool HasFocus() const;
631
632 // can this window have focus in principle?
633 //
634 // the difference between AcceptsFocus[FromKeyboard]() and CanAcceptFocus
635 // [FromKeyboard]() is that the former functions are meant to be
636 // overridden in the derived classes to simply return false if the
637 // control can't have focus, while the latter are meant to be used by
638 // this class clients and take into account the current window state
639 virtual bool AcceptsFocus() const { return true; }
640
641 // can this window or one of its children accept focus?
642 //
643 // usually it's the same as AcceptsFocus() but is overridden for
644 // container windows
645 virtual bool AcceptsFocusRecursively() const { return AcceptsFocus(); }
646
647 // can this window be given focus by keyboard navigation? if not, the
648 // only way to give it focus (provided it accepts it at all) is to
649 // click it
650 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
651
652
653 // this is mostly a helper for the various functions using it below
654 bool CanBeFocused() const { return IsShown() && IsEnabled(); }
655
656 // can this window itself have focus?
657 bool IsFocusable() const { return AcceptsFocus() && CanBeFocused(); }
658
659 // can this window have focus right now?
660 //
661 // if this method returns true, it means that calling SetFocus() will
662 // put focus either to this window or one of its children, if you need
663 // to know whether this window accepts focus itself, use IsFocusable()
664 bool CanAcceptFocus() const
665 { return AcceptsFocusRecursively() && CanBeFocused(); }
666
667 // can this window be assigned focus from keyboard right now?
668 bool CanAcceptFocusFromKeyboard() const
669 { return AcceptsFocusFromKeyboard() && CanBeFocused(); }
670
671 // call this when the return value of AcceptsFocus() changes
672 virtual void SetCanFocus(bool WXUNUSED(canFocus)) { }
673
674 // navigates inside this window
675 bool NavigateIn(int flags = wxNavigationKeyEvent::IsForward)
676 { return DoNavigateIn(flags); }
677
678 // navigates in the specified direction from this window, this is
679 // equivalent to GetParent()->NavigateIn()
680 bool Navigate(int flags = wxNavigationKeyEvent::IsForward)
681 { return m_parent && ((wxWindowBase *)m_parent)->DoNavigateIn(flags); }
682
683 // move this window just before/after the specified one in tab order
684 // (the other window must be our sibling!)
685 void MoveBeforeInTabOrder(wxWindow *win)
686 { DoMoveInTabOrder(win, OrderBefore); }
687 void MoveAfterInTabOrder(wxWindow *win)
688 { DoMoveInTabOrder(win, OrderAfter); }
689
690
691 // parent/children relations
692 // -------------------------
693
694 // get the list of children
695 const wxWindowList& GetChildren() const { return m_children; }
696 wxWindowList& GetChildren() { return m_children; }
697
698 // needed just for extended runtime
699 const wxWindowList& GetWindowChildren() const { return GetChildren() ; }
700
701 // get the window before/after this one in the parents children list,
702 // returns NULL if this is the first/last window
703 wxWindow *GetPrevSibling() const { return DoGetSibling(OrderBefore); }
704 wxWindow *GetNextSibling() const { return DoGetSibling(OrderAfter); }
705
706 // get the parent or the parent of the parent
707 wxWindow *GetParent() const { return m_parent; }
708 inline wxWindow *GetGrandParent() const;
709
710 // is this window a top level one?
711 virtual bool IsTopLevel() const;
712
713 // it doesn't really change parent, use Reparent() instead
714 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
715 // change the real parent of this window, return true if the parent
716 // was changed, false otherwise (error or newParent == oldParent)
717 virtual bool Reparent( wxWindowBase *newParent );
718
719 // implementation mostly
720 virtual void AddChild( wxWindowBase *child );
721 virtual void RemoveChild( wxWindowBase *child );
722
723 // returns true if the child is in the client area of the window, i.e. is
724 // not scrollbar, toolbar etc.
725 virtual bool IsClientAreaChild(const wxWindow *WXUNUSED(child)) const
726 { return true; }
727
728 // looking for windows
729 // -------------------
730
731 // find window among the descendants of this one either by id or by
732 // name (return NULL if not found)
733 wxWindow *FindWindow(long winid) const;
734 wxWindow *FindWindow(const wxString& name) const;
735
736 // Find a window among any window (all return NULL if not found)
737 static wxWindow *FindWindowById( long winid, const wxWindow *parent = NULL );
738 static wxWindow *FindWindowByName( const wxString& name,
739 const wxWindow *parent = NULL );
740 static wxWindow *FindWindowByLabel( const wxString& label,
741 const wxWindow *parent = NULL );
742
743 // event handler stuff
744 // -------------------
745
746 // get the current event handler
747 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
748
749 // replace the event handler (allows to completely subclass the
750 // window)
751 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
752
753 // push/pop event handler: allows to chain a custom event handler to
754 // alreasy existing ones
755 void PushEventHandler( wxEvtHandler *handler );
756 wxEvtHandler *PopEventHandler( bool deleteHandler = false );
757
758 // find the given handler in the event handler chain and remove (but
759 // not delete) it from the event handler chain, return true if it was
760 // found and false otherwise (this also results in an assert failure so
761 // this function should only be called when the handler is supposed to
762 // be there)
763 bool RemoveEventHandler(wxEvtHandler *handler);
764
765 // Process an event by calling GetEventHandler()->ProcessEvent() and
766 // handling any exceptions thrown by event handlers. It's mostly useful
767 // when processing wx events when called from C code (e.g. in GTK+
768 // callback) when the exception wouldn't correctly propagate to
769 // wxEventLoop.
770 bool HandleWindowEvent(wxEvent& event) const;
771
772 // validators
773 // ----------
774
775 #if wxUSE_VALIDATORS
776 // a window may have an associated validator which is used to control
777 // user input
778 virtual void SetValidator( const wxValidator &validator );
779 virtual wxValidator *GetValidator() { return m_windowValidator; }
780 #endif // wxUSE_VALIDATORS
781
782
783 // dialog oriented functions
784 // -------------------------
785
786 // validate the correctness of input, return true if ok
787 virtual bool Validate();
788
789 // transfer data between internal and GUI representations
790 virtual bool TransferDataToWindow();
791 virtual bool TransferDataFromWindow();
792
793 virtual void InitDialog();
794
795 #if wxUSE_ACCEL
796 // accelerators
797 // ------------
798 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
799 { m_acceleratorTable = accel; }
800 wxAcceleratorTable *GetAcceleratorTable()
801 { return &m_acceleratorTable; }
802
803 #endif // wxUSE_ACCEL
804
805 #if wxUSE_HOTKEY
806 // hot keys (system wide accelerators)
807 // -----------------------------------
808
809 virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode);
810 virtual bool UnregisterHotKey(int hotkeyId);
811 #endif // wxUSE_HOTKEY
812
813
814 // dialog units translations
815 // -------------------------
816
817 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
818 wxPoint ConvertDialogToPixels( const wxPoint& pt );
819 wxSize ConvertPixelsToDialog( const wxSize& sz )
820 {
821 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
822
823 return wxSize(pt.x, pt.y);
824 }
825
826 wxSize ConvertDialogToPixels( const wxSize& sz )
827 {
828 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
829
830 return wxSize(pt.x, pt.y);
831 }
832
833 // mouse functions
834 // ---------------
835
836 // move the mouse to the specified position
837 virtual void WarpPointer(int x, int y) = 0;
838
839 // start or end mouse capture, these functions maintain the stack of
840 // windows having captured the mouse and after calling ReleaseMouse()
841 // the mouse is not released but returns to the window which had had
842 // captured it previously (if any)
843 void CaptureMouse();
844 void ReleaseMouse();
845
846 // get the window which currently captures the mouse or NULL
847 static wxWindow *GetCapture();
848
849 // does this window have the capture?
850 virtual bool HasCapture() const
851 { return (wxWindow *)this == GetCapture(); }
852
853 // painting the window
854 // -------------------
855
856 // mark the specified rectangle (or the whole window) as "dirty" so it
857 // will be repainted
858 virtual void Refresh( bool eraseBackground = true,
859 const wxRect *rect = (const wxRect *) NULL ) = 0;
860
861 // a less awkward wrapper for Refresh
862 void RefreshRect(const wxRect& rect, bool eraseBackground = true)
863 {
864 Refresh(eraseBackground, &rect);
865 }
866
867 // repaint all invalid areas of the window immediately
868 virtual void Update() { }
869
870 // clear the window background
871 virtual void ClearBackground();
872
873 // freeze the window: don't redraw it until it is thawed
874 void Freeze() { if ( !m_freezeCount++ ) DoFreeze(); }
875
876 // thaw the window: redraw it after it had been frozen
877 void Thaw()
878 {
879 wxASSERT_MSG( m_freezeCount, "Thaw() without matching Freeze()" );
880
881 if ( !--m_freezeCount )
882 DoThaw();
883 }
884
885 // return true if window had been frozen and not unthawed yet
886 bool IsFrozen() const { return m_freezeCount != 0; }
887
888 // adjust DC for drawing on this window
889 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
890
891 // return true if the window contents is double buffered by the system
892 virtual bool IsDoubleBuffered() const { return false; }
893
894 // the update region of the window contains the areas which must be
895 // repainted by the program
896 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
897 wxRegion& GetUpdateRegion() { return m_updateRegion; }
898
899 // get the update rectangleregion bounding box in client coords
900 wxRect GetUpdateClientRect() const;
901
902 // these functions verify whether the given point/rectangle belongs to
903 // (or at least intersects with) the update region
904 virtual bool DoIsExposed( int x, int y ) const;
905 virtual bool DoIsExposed( int x, int y, int w, int h ) const;
906
907 bool IsExposed( int x, int y ) const
908 { return DoIsExposed(x, y); }
909 bool IsExposed( int x, int y, int w, int h ) const
910 { return DoIsExposed(x, y, w, h); }
911 bool IsExposed( const wxPoint& pt ) const
912 { return DoIsExposed(pt.x, pt.y); }
913 bool IsExposed( const wxRect& rect ) const
914 { return DoIsExposed(rect.x, rect.y, rect.width, rect.height); }
915
916 // colours, fonts and cursors
917 // --------------------------
918
919 // get the default attributes for the controls of this class: we
920 // provide a virtual function which can be used to query the default
921 // attributes of an existing control and a static function which can
922 // be used even when no existing object of the given class is
923 // available, but which won't return any styles specific to this
924 // particular control, of course (e.g. "Ok" button might have
925 // different -- bold for example -- font)
926 virtual wxVisualAttributes GetDefaultAttributes() const
927 {
928 return GetClassDefaultAttributes(GetWindowVariant());
929 }
930
931 static wxVisualAttributes
932 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
933
934 // set/retrieve the window colours (system defaults are used by
935 // default): SetXXX() functions return true if colour was changed,
936 // SetDefaultXXX() reset the "m_inheritXXX" flag after setting the
937 // value to prevent it from being inherited by our children
938 virtual bool SetBackgroundColour(const wxColour& colour);
939 void SetOwnBackgroundColour(const wxColour& colour)
940 {
941 if ( SetBackgroundColour(colour) )
942 m_inheritBgCol = false;
943 }
944 wxColour GetBackgroundColour() const;
945 bool InheritsBackgroundColour() const
946 {
947 return m_inheritBgCol;
948 }
949 bool UseBgCol() const
950 {
951 return m_hasBgCol;
952 }
953
954 virtual bool SetForegroundColour(const wxColour& colour);
955 void SetOwnForegroundColour(const wxColour& colour)
956 {
957 if ( SetForegroundColour(colour) )
958 m_inheritFgCol = false;
959 }
960 wxColour GetForegroundColour() const;
961
962 // Set/get the background style.
963 // Pass one of wxBG_STYLE_SYSTEM, wxBG_STYLE_COLOUR, wxBG_STYLE_CUSTOM
964 virtual bool SetBackgroundStyle(wxBackgroundStyle style) { m_backgroundStyle = style; return true; }
965 virtual wxBackgroundStyle GetBackgroundStyle() const { return m_backgroundStyle; }
966
967 // returns true if the control has "transparent" areas such as a
968 // wxStaticText and wxCheckBox and the background should be adapted
969 // from a parent window
970 virtual bool HasTransparentBackground() { return false; }
971
972 // set/retrieve the font for the window (SetFont() returns true if the
973 // font really changed)
974 virtual bool SetFont(const wxFont& font) = 0;
975 void SetOwnFont(const wxFont& font)
976 {
977 if ( SetFont(font) )
978 m_inheritFont = false;
979 }
980 wxFont GetFont() const;
981
982 // set/retrieve the cursor for this window (SetCursor() returns true
983 // if the cursor was really changed)
984 virtual bool SetCursor( const wxCursor &cursor );
985 const wxCursor& GetCursor() const { return m_cursor; }
986
987 #if wxUSE_CARET
988 // associate a caret with the window
989 void SetCaret(wxCaret *caret);
990 // get the current caret (may be NULL)
991 wxCaret *GetCaret() const { return m_caret; }
992 #endif // wxUSE_CARET
993
994 // get the (average) character size for the current font
995 virtual int GetCharHeight() const = 0;
996 virtual int GetCharWidth() const = 0;
997
998 // get the width/height/... of the text using current or specified
999 // font
1000 virtual void GetTextExtent(const wxString& string,
1001 int *x, int *y,
1002 int *descent = (int *) NULL,
1003 int *externalLeading = (int *) NULL,
1004 const wxFont *theFont = (const wxFont *) NULL)
1005 const = 0;
1006
1007 wxSize GetTextExtent(const wxString& string) const
1008 {
1009 wxCoord w, h;
1010 GetTextExtent(string, &w, &h);
1011 return wxSize(w, h);
1012 }
1013
1014 // client <-> screen coords
1015 // ------------------------
1016
1017 // translate to/from screen/client coordinates (pointers may be NULL)
1018 void ClientToScreen( int *x, int *y ) const
1019 { DoClientToScreen(x, y); }
1020 void ScreenToClient( int *x, int *y ) const
1021 { DoScreenToClient(x, y); }
1022
1023 // wxPoint interface to do the same thing
1024 wxPoint ClientToScreen(const wxPoint& pt) const
1025 {
1026 int x = pt.x, y = pt.y;
1027 DoClientToScreen(&x, &y);
1028
1029 return wxPoint(x, y);
1030 }
1031
1032 wxPoint ScreenToClient(const wxPoint& pt) const
1033 {
1034 int x = pt.x, y = pt.y;
1035 DoScreenToClient(&x, &y);
1036
1037 return wxPoint(x, y);
1038 }
1039
1040 // test where the given (in client coords) point lies
1041 wxHitTest HitTest(wxCoord x, wxCoord y) const
1042 { return DoHitTest(x, y); }
1043
1044 wxHitTest HitTest(const wxPoint& pt) const
1045 { return DoHitTest(pt.x, pt.y); }
1046
1047 // misc
1048 // ----
1049
1050 // get the window border style from the given flags: this is different from
1051 // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to
1052 // translate wxBORDER_DEFAULT to something reasonable
1053 wxBorder GetBorder(long flags) const;
1054
1055 // get border for the flags of this window
1056 wxBorder GetBorder() const { return GetBorder(GetWindowStyleFlag()); }
1057
1058 // send wxUpdateUIEvents to this window, and children if recurse is true
1059 virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
1060
1061 // do the window-specific processing after processing the update event
1062 virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
1063
1064 #if wxUSE_MENUS
1065 // show popup menu at the given position, generate events for the items
1066 // selected in it
1067 bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition)
1068 { return PopupMenu(menu, pos.x, pos.y); }
1069 bool PopupMenu(wxMenu *menu, int x, int y);
1070
1071 // simply return the id of the selected item or wxID_NONE without
1072 // generating any events
1073 int GetPopupMenuSelectionFromUser(wxMenu& menu, const wxPoint& pos)
1074 { return DoGetPopupMenuSelectionFromUser(menu, pos.x, pos.y); }
1075 int GetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y)
1076 { return DoGetPopupMenuSelectionFromUser(menu, x, y); }
1077 #endif // wxUSE_MENUS
1078
1079 // override this method to return true for controls having multiple pages
1080 virtual bool HasMultiplePages() const { return false; }
1081
1082
1083 // scrollbars
1084 // ----------
1085
1086 // does the window have the scrollbar for this orientation?
1087 bool HasScrollbar(int orient) const
1088 {
1089 return (m_windowStyle &
1090 (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0;
1091 }
1092
1093 // configure the window scrollbars
1094 virtual void SetScrollbar( int orient,
1095 int pos,
1096 int thumbvisible,
1097 int range,
1098 bool refresh = true ) = 0;
1099 virtual void SetScrollPos( int orient, int pos, bool refresh = true ) = 0;
1100 virtual int GetScrollPos( int orient ) const = 0;
1101 virtual int GetScrollThumb( int orient ) const = 0;
1102 virtual int GetScrollRange( int orient ) const = 0;
1103
1104 // scroll window to the specified position
1105 virtual void ScrollWindow( int dx, int dy,
1106 const wxRect* rect = (wxRect *) NULL ) = 0;
1107
1108 // scrolls window by line/page: note that not all controls support this
1109 //
1110 // return true if the position changed, false otherwise
1111 virtual bool ScrollLines(int WXUNUSED(lines)) { return false; }
1112 virtual bool ScrollPages(int WXUNUSED(pages)) { return false; }
1113
1114 // convenient wrappers for ScrollLines/Pages
1115 bool LineUp() { return ScrollLines(-1); }
1116 bool LineDown() { return ScrollLines(1); }
1117 bool PageUp() { return ScrollPages(-1); }
1118 bool PageDown() { return ScrollPages(1); }
1119
1120 // call this to always show one or both scrollbars, even if the window
1121 // is big enough to not require them
1122 virtual void AlwaysShowScrollbars(bool WXUNUSED(horz) = true,
1123 bool WXUNUSED(vert) = true)
1124 {
1125 }
1126
1127 // return true if AlwaysShowScrollbars() had been called before for the
1128 // corresponding orientation
1129 virtual bool IsScrollbarAlwaysShown(int WXUNUSED(orient)) const
1130 {
1131 return false;
1132 }
1133
1134 // context-sensitive help
1135 // ----------------------
1136
1137 // these are the convenience functions wrapping wxHelpProvider methods
1138
1139 #if wxUSE_HELP
1140 // associate this help text with this window
1141 void SetHelpText(const wxString& text);
1142 // associate this help text with all windows with the same id as this
1143 // one
1144 void SetHelpTextForId(const wxString& text);
1145 // get the help string associated with the given position in this window
1146 //
1147 // notice that pt may be invalid if event origin is keyboard or unknown
1148 // and this method should return the global window help text then
1149 virtual wxString GetHelpTextAtPoint(const wxPoint& pt,
1150 wxHelpEvent::Origin origin) const;
1151 // returns the position-independent help text
1152 wxString GetHelpText() const
1153 {
1154 return GetHelpTextAtPoint(wxDefaultPosition, wxHelpEvent::Origin_Unknown);
1155 }
1156
1157 #else // !wxUSE_HELP
1158 // silently ignore SetHelpText() calls
1159 void SetHelpText(const wxString& WXUNUSED(text)) { }
1160 void SetHelpTextForId(const wxString& WXUNUSED(text)) { }
1161 #endif // wxUSE_HELP
1162
1163 // tooltips
1164 // --------
1165
1166 #if wxUSE_TOOLTIPS
1167 // the easiest way to set a tooltip for a window is to use this method
1168 void SetToolTip( const wxString &tip );
1169 // attach a tooltip to the window
1170 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
1171 // get the associated tooltip or NULL if none
1172 wxToolTip* GetToolTip() const { return m_tooltip; }
1173 wxString GetToolTipText() const ;
1174 #else
1175 // make it much easier to compile apps in an environment
1176 // that doesn't support tooltips, such as PocketPC
1177 inline void SetToolTip( const wxString & WXUNUSED(tip) ) {}
1178 #endif // wxUSE_TOOLTIPS
1179
1180 // drag and drop
1181 // -------------
1182 #if wxUSE_DRAG_AND_DROP
1183 // set/retrieve the drop target associated with this window (may be
1184 // NULL; it's owned by the window and will be deleted by it)
1185 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
1186 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
1187 #endif // wxUSE_DRAG_AND_DROP
1188
1189 // constraints and sizers
1190 // ----------------------
1191 #if wxUSE_CONSTRAINTS
1192 // set the constraints for this window or retrieve them (may be NULL)
1193 void SetConstraints( wxLayoutConstraints *constraints );
1194 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
1195
1196 // implementation only
1197 void UnsetConstraints(wxLayoutConstraints *c);
1198 wxWindowList *GetConstraintsInvolvedIn() const
1199 { return m_constraintsInvolvedIn; }
1200 void AddConstraintReference(wxWindowBase *otherWin);
1201 void RemoveConstraintReference(wxWindowBase *otherWin);
1202 void DeleteRelatedConstraints();
1203 void ResetConstraints();
1204
1205 // these methods may be overridden for special layout algorithms
1206 virtual void SetConstraintSizes(bool recurse = true);
1207 virtual bool LayoutPhase1(int *noChanges);
1208 virtual bool LayoutPhase2(int *noChanges);
1209 virtual bool DoPhase(int phase);
1210
1211 // these methods are virtual but normally won't be overridden
1212 virtual void SetSizeConstraint(int x, int y, int w, int h);
1213 virtual void MoveConstraint(int x, int y);
1214 virtual void GetSizeConstraint(int *w, int *h) const ;
1215 virtual void GetClientSizeConstraint(int *w, int *h) const ;
1216 virtual void GetPositionConstraint(int *x, int *y) const ;
1217
1218 #endif // wxUSE_CONSTRAINTS
1219
1220 // when using constraints or sizers, it makes sense to update
1221 // children positions automatically whenever the window is resized
1222 // - this is done if autoLayout is on
1223 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
1224 bool GetAutoLayout() const { return m_autoLayout; }
1225
1226 // lay out the window and its children
1227 virtual bool Layout();
1228
1229 // sizers
1230 void SetSizer(wxSizer *sizer, bool deleteOld = true );
1231 void SetSizerAndFit( wxSizer *sizer, bool deleteOld = true );
1232
1233 wxSizer *GetSizer() const { return m_windowSizer; }
1234
1235 // Track if this window is a member of a sizer
1236 void SetContainingSizer(wxSizer* sizer);
1237 wxSizer *GetContainingSizer() const { return m_containingSizer; }
1238
1239 // accessibility
1240 // ----------------------
1241 #if wxUSE_ACCESSIBILITY
1242 // Override to create a specific accessible object.
1243 virtual wxAccessible* CreateAccessible();
1244
1245 // Sets the accessible object.
1246 void SetAccessible(wxAccessible* accessible) ;
1247
1248 // Returns the accessible object.
1249 wxAccessible* GetAccessible() { return m_accessible; }
1250
1251 // Returns the accessible object, creating if necessary.
1252 wxAccessible* GetOrCreateAccessible() ;
1253 #endif
1254
1255
1256 // Set window transparency if the platform supports it
1257 virtual bool SetTransparent(wxByte WXUNUSED(alpha)) { return false; }
1258 virtual bool CanSetTransparent() { return false; }
1259
1260
1261 // implementation
1262 // --------------
1263
1264 // event handlers
1265 void OnSysColourChanged( wxSysColourChangedEvent& event );
1266 void OnInitDialog( wxInitDialogEvent &event );
1267 void OnMiddleClick( wxMouseEvent& event );
1268 #if wxUSE_HELP
1269 void OnHelp(wxHelpEvent& event);
1270 #endif // wxUSE_HELP
1271
1272 // virtual function for implementing internal idle
1273 // behaviour
1274 virtual void OnInternalIdle() {}
1275
1276 // call internal idle recursively
1277 // void ProcessInternalIdle() ;
1278
1279 // get the handle of the window for the underlying window system: this
1280 // is only used for wxWin itself or for user code which wants to call
1281 // platform-specific APIs
1282 virtual WXWidget GetHandle() const = 0;
1283 // associate the window with a new native handle
1284 virtual void AssociateHandle(WXWidget WXUNUSED(handle)) { }
1285 // dissociate the current native handle from the window
1286 virtual void DissociateHandle() { }
1287
1288 #if wxUSE_PALETTE
1289 // Store the palette used by DCs in wxWindow so that the dcs can share
1290 // a palette. And we can respond to palette messages.
1291 wxPalette GetPalette() const { return m_palette; }
1292
1293 // When palette is changed tell the DC to set the system palette to the
1294 // new one.
1295 void SetPalette(const wxPalette& pal);
1296
1297 // return true if we have a specific palette
1298 bool HasCustomPalette() const { return m_hasCustomPalette; }
1299
1300 // return the first parent window with a custom palette or NULL
1301 wxWindow *GetAncestorWithCustomPalette() const;
1302 #endif // wxUSE_PALETTE
1303
1304 // inherit the parents visual attributes if they had been explicitly set
1305 // by the user (i.e. we don't inherit default attributes) and if we don't
1306 // have our own explicitly set
1307 virtual void InheritAttributes();
1308
1309 // returns false from here if this window doesn't want to inherit the
1310 // parents colours even if InheritAttributes() would normally do it
1311 //
1312 // this just provides a simple way to customize InheritAttributes()
1313 // behaviour in the most common case
1314 virtual bool ShouldInheritColours() const { return false; }
1315
1316 // returns true if the window can be positioned outside of parent's client
1317 // area (normal windows can't, but e.g. menubar or statusbar can):
1318 virtual bool CanBeOutsideClientArea() const { return false; }
1319
1320 // returns true if the platform should explicitly apply a theme border. Currently
1321 // used only by Windows
1322 virtual bool CanApplyThemeBorder() const { return true; }
1323
1324 protected:
1325 // event handling specific to wxWindow
1326 virtual bool TryValidator(wxEvent& event);
1327 virtual bool TryParent(wxEvent& event);
1328
1329 enum WindowOrder
1330 {
1331 OrderBefore, // insert before the given window
1332 OrderAfter // insert after the given window
1333 };
1334
1335 // common part of GetPrev/NextSibling()
1336 wxWindow *DoGetSibling(WindowOrder order) const;
1337
1338 // common part of MoveBefore/AfterInTabOrder()
1339 virtual void DoMoveInTabOrder(wxWindow *win, WindowOrder move);
1340
1341 // implementation of Navigate() and NavigateIn()
1342 virtual bool DoNavigateIn(int flags);
1343
1344 #if wxUSE_CONSTRAINTS
1345 // satisfy the constraints for the windows but don't set the window sizes
1346 void SatisfyConstraints();
1347 #endif // wxUSE_CONSTRAINTS
1348
1349 // Send the wxWindowDestroyEvent
1350 void SendDestroyEvent();
1351
1352 // returns the main window of composite control; this is the window
1353 // that FindFocus returns if the focus is in one of composite control's
1354 // windows
1355 virtual wxWindow *GetMainWindowOfCompositeControl()
1356 { return (wxWindow*)this; }
1357
1358 // this method should be implemented to use operating system specific code
1359 // to really enable/disable the widget, it will only be called when we
1360 // really need to enable/disable window and so no additional checks on the
1361 // widgets state are necessary
1362 virtual void DoEnable(bool WXUNUSED(enable)) { }
1363
1364 // called when the on-screen widget state changes and provides an
1365 // an opportunity for the widget to update its visual state (colours,
1366 // fonts, anything else) as necessary
1367 virtual void OnEnabled(bool WXUNUSED(enabled)) { }
1368
1369
1370 // the window id - a number which uniquely identifies a window among
1371 // its siblings unless it is wxID_ANY
1372 wxWindowIDRef m_windowId;
1373
1374 // the parent window of this window (or NULL) and the list of the children
1375 // of this window
1376 wxWindow *m_parent;
1377 wxWindowList m_children;
1378
1379 // the minimal allowed size for the window (no minimal size if variable(s)
1380 // contain(s) wxDefaultCoord)
1381 int m_minWidth,
1382 m_minHeight,
1383 m_maxWidth,
1384 m_maxHeight;
1385
1386 // event handler for this window: usually is just 'this' but may be
1387 // changed with SetEventHandler()
1388 wxEvtHandler *m_eventHandler;
1389
1390 #if wxUSE_VALIDATORS
1391 // associated validator or NULL if none
1392 wxValidator *m_windowValidator;
1393 #endif // wxUSE_VALIDATORS
1394
1395 #if wxUSE_DRAG_AND_DROP
1396 wxDropTarget *m_dropTarget;
1397 #endif // wxUSE_DRAG_AND_DROP
1398
1399 // visual window attributes
1400 wxCursor m_cursor;
1401 wxFont m_font; // see m_hasFont
1402 wxColour m_backgroundColour, // m_hasBgCol
1403 m_foregroundColour; // m_hasFgCol
1404
1405 #if wxUSE_CARET
1406 wxCaret *m_caret;
1407 #endif // wxUSE_CARET
1408
1409 // the region which should be repainted in response to paint event
1410 wxRegion m_updateRegion;
1411
1412 #if wxUSE_ACCEL
1413 // the accelerator table for the window which translates key strokes into
1414 // command events
1415 wxAcceleratorTable m_acceleratorTable;
1416 #endif // wxUSE_ACCEL
1417
1418 // the tooltip for this window (may be NULL)
1419 #if wxUSE_TOOLTIPS
1420 wxToolTip *m_tooltip;
1421 #endif // wxUSE_TOOLTIPS
1422
1423 // constraints and sizers
1424 #if wxUSE_CONSTRAINTS
1425 // the constraints for this window or NULL
1426 wxLayoutConstraints *m_constraints;
1427
1428 // constraints this window is involved in
1429 wxWindowList *m_constraintsInvolvedIn;
1430 #endif // wxUSE_CONSTRAINTS
1431
1432 // this window's sizer
1433 wxSizer *m_windowSizer;
1434
1435 // The sizer this window is a member of, if any
1436 wxSizer *m_containingSizer;
1437
1438 // Layout() window automatically when its size changes?
1439 bool m_autoLayout:1;
1440
1441 // window state
1442 bool m_isShown:1;
1443 bool m_isEnabled:1;
1444 bool m_isBeingDeleted:1;
1445
1446 // was the window colours/font explicitly changed by user?
1447 bool m_hasBgCol:1;
1448 bool m_hasFgCol:1;
1449 bool m_hasFont:1;
1450
1451 // and should it be inherited by children?
1452 bool m_inheritBgCol:1;
1453 bool m_inheritFgCol:1;
1454 bool m_inheritFont:1;
1455
1456 // window attributes
1457 long m_windowStyle,
1458 m_exStyle;
1459 wxString m_windowName;
1460 bool m_themeEnabled;
1461 wxBackgroundStyle m_backgroundStyle;
1462 #if wxUSE_PALETTE
1463 wxPalette m_palette;
1464 bool m_hasCustomPalette;
1465 #endif // wxUSE_PALETTE
1466
1467 #if wxUSE_ACCESSIBILITY
1468 wxAccessible* m_accessible;
1469 #endif
1470
1471 // Virtual size (scrolling)
1472 wxSize m_virtualSize;
1473
1474 wxScrollHelper *m_scrollHelper;
1475
1476 wxWindowVariant m_windowVariant ;
1477
1478 // override this to change the default (i.e. used when no style is
1479 // specified) border for the window class
1480 virtual wxBorder GetDefaultBorder() const;
1481
1482 // this allows you to implement standard control borders without
1483 // repeating the code in different classes that are not derived from
1484 // wxControl
1485 virtual wxBorder GetDefaultBorderForControl() const { return wxBORDER_THEME; }
1486
1487 // Get the default size for the new window if no explicit size given. TLWs
1488 // have their own default size so this is just for non top-level windows.
1489 static int WidthDefault(int w) { return w == wxDefaultCoord ? 20 : w; }
1490 static int HeightDefault(int h) { return h == wxDefaultCoord ? 20 : h; }
1491
1492
1493 // Used to save the results of DoGetBestSize so it doesn't need to be
1494 // recalculated each time the value is needed.
1495 wxSize m_bestSizeCache;
1496
1497 wxDEPRECATED( void SetBestSize(const wxSize& size) ); // use SetInitialSize
1498 wxDEPRECATED( virtual void SetInitialBestSize(const wxSize& size) ); // use SetInitialSize
1499
1500
1501
1502 // more pure virtual functions
1503 // ---------------------------
1504
1505 // NB: we must have DoSomething() function when Something() is an overloaded
1506 // method: indeed, we can't just have "virtual Something()" in case when
1507 // the function is overloaded because then we'd have to make virtual all
1508 // the variants (otherwise only the virtual function may be called on a
1509 // pointer to derived class according to C++ rules) which is, in
1510 // general, absolutely not needed. So instead we implement all
1511 // overloaded Something()s in terms of DoSomething() which will be the
1512 // only one to be virtual.
1513
1514 // coordinates translation
1515 virtual void DoClientToScreen( int *x, int *y ) const = 0;
1516 virtual void DoScreenToClient( int *x, int *y ) const = 0;
1517
1518 virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
1519
1520 // capture/release the mouse, used by Capture/ReleaseMouse()
1521 virtual void DoCaptureMouse() = 0;
1522 virtual void DoReleaseMouse() = 0;
1523
1524 // retrieve the position/size of the window
1525 virtual void DoGetPosition(int *x, int *y) const = 0;
1526 virtual void DoGetScreenPosition(int *x, int *y) const;
1527 virtual void DoGetSize(int *width, int *height) const = 0;
1528 virtual void DoGetClientSize(int *width, int *height) const = 0;
1529
1530 // get the size which best suits the window: for a control, it would be
1531 // the minimal size which doesn't truncate the control, for a panel - the
1532 // same size as it would have after a call to Fit()
1533 virtual wxSize DoGetBestSize() const;
1534
1535 // this is the virtual function to be overriden in any derived class which
1536 // wants to change how SetSize() or Move() works - it is called by all
1537 // versions of these functions in the base class
1538 virtual void DoSetSize(int x, int y,
1539 int width, int height,
1540 int sizeFlags = wxSIZE_AUTO) = 0;
1541
1542 // same as DoSetSize() for the client size
1543 virtual void DoSetClientSize(int width, int height) = 0;
1544
1545 virtual void DoSetSizeHints( int minW, int minH,
1546 int maxW, int maxH,
1547 int incW, int incH );
1548
1549 // move the window to the specified location and resize it: this is called
1550 // from both DoSetSize() and DoSetClientSize() and would usually just
1551 // reposition this window except for composite controls which will want to
1552 // arrange themselves inside the given rectangle
1553 //
1554 // Important note: the coordinates passed to this method are in parent's
1555 // *window* coordinates and not parent's client coordinates (as the values
1556 // passed to DoSetSize and returned by DoGetPosition are)!
1557 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
1558
1559 // centre the window in the specified direction on parent, note that
1560 // wxCENTRE_ON_SCREEN shouldn't be specified here, it only makes sense for
1561 // TLWs
1562 virtual void DoCentre(int dir);
1563
1564 #if wxUSE_TOOLTIPS
1565 virtual void DoSetToolTip( wxToolTip *tip );
1566 #endif // wxUSE_TOOLTIPS
1567
1568 #if wxUSE_MENUS
1569 virtual bool DoPopupMenu(wxMenu *menu, int x, int y) = 0;
1570 #endif // wxUSE_MENUS
1571
1572 // Makes an adjustment to the window position to make it relative to the
1573 // parents client area, e.g. if the parent is a frame with a toolbar, its
1574 // (0, 0) is just below the toolbar
1575 virtual void AdjustForParentClientOrigin(int& x, int& y,
1576 int sizeFlags = 0) const;
1577
1578 // implements the window variants
1579 virtual void DoSetWindowVariant( wxWindowVariant variant ) ;
1580
1581
1582 // really freeze/thaw the window (should have port-specific implementation)
1583 virtual void DoFreeze() { }
1584 virtual void DoThaw() { }
1585
1586
1587 // Must be called when mouse capture is lost to send
1588 // wxMouseCaptureLostEvent to windows on capture stack.
1589 static void NotifyCaptureLost();
1590
1591 private:
1592 // recursively call our own and our children OnEnabled() when the
1593 // enabled/disabled status changed because a parent window had been
1594 // enabled/disabled
1595 void NotifyWindowOnEnableChange(bool enabled);
1596
1597 #if wxUSE_MENUS
1598 // temporary event handler used by GetPopupMenuSelectionFromUser()
1599 void InternalOnPopupMenu(wxCommandEvent& event);
1600
1601 // implementation of the public GetPopupMenuSelectionFromUser() method
1602 int DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y);
1603 #endif // wxUSE_MENUS
1604
1605 // the stack of windows which have captured the mouse
1606 static struct WXDLLIMPEXP_FWD_CORE wxWindowNext *ms_winCaptureNext;
1607
1608 // the window that currently has mouse capture
1609 static wxWindow *ms_winCaptureCurrent;
1610
1611 // indicates if execution is inside CaptureMouse/ReleaseMouse
1612 static bool ms_winCaptureChanging;
1613
1614
1615 // number of Freeze() calls minus the number of Thaw() calls: we're frozen
1616 // (i.e. not being updated) if it is positive
1617 unsigned int m_freezeCount;
1618
1619
1620 DECLARE_ABSTRACT_CLASS(wxWindowBase)
1621 DECLARE_NO_COPY_CLASS(wxWindowBase)
1622 DECLARE_EVENT_TABLE()
1623 };
1624
1625
1626
1627 // Inlines for some deprecated methods
1628 inline wxSize wxWindowBase::GetBestFittingSize() const
1629 {
1630 return GetEffectiveMinSize();
1631 }
1632
1633 inline void wxWindowBase::SetBestFittingSize(const wxSize& size)
1634 {
1635 SetInitialSize(size);
1636 }
1637
1638 inline void wxWindowBase::SetBestSize(const wxSize& size)
1639 {
1640 SetInitialSize(size);
1641 }
1642
1643 inline void wxWindowBase::SetInitialBestSize(const wxSize& size)
1644 {
1645 SetInitialSize(size);
1646 }
1647
1648
1649 // ----------------------------------------------------------------------------
1650 // now include the declaration of wxWindow class
1651 // ----------------------------------------------------------------------------
1652
1653 // include the declaration of the platform-specific class
1654 #if defined(__WXPALMOS__)
1655 #ifdef __WXUNIVERSAL__
1656 #define wxWindowNative wxWindowPalm
1657 #else // !wxUniv
1658 #define wxWindowPalm wxWindow
1659 #endif // wxUniv/!wxUniv
1660 #include "wx/palmos/window.h"
1661 #elif defined(__WXMSW__)
1662 #ifdef __WXUNIVERSAL__
1663 #define wxWindowNative wxWindowMSW
1664 #else // !wxUniv
1665 #define wxWindowMSW wxWindow
1666 #endif // wxUniv/!wxUniv
1667 #include "wx/msw/window.h"
1668 #elif defined(__WXMOTIF__)
1669 #include "wx/motif/window.h"
1670 #elif defined(__WXGTK20__)
1671 #ifdef __WXUNIVERSAL__
1672 #define wxWindowNative wxWindowGTK
1673 #else // !wxUniv
1674 #define wxWindowGTK wxWindow
1675 #endif // wxUniv
1676 #include "wx/gtk/window.h"
1677 #elif defined(__WXGTK__)
1678 #ifdef __WXUNIVERSAL__
1679 #define wxWindowNative wxWindowGTK
1680 #else // !wxUniv
1681 #define wxWindowGTK wxWindow
1682 #endif // wxUniv
1683 #include "wx/gtk1/window.h"
1684 #elif defined(__WXX11__)
1685 #ifdef __WXUNIVERSAL__
1686 #define wxWindowNative wxWindowX11
1687 #else // !wxUniv
1688 #define wxWindowX11 wxWindow
1689 #endif // wxUniv
1690 #include "wx/x11/window.h"
1691 #elif defined(__WXMGL__)
1692 #define wxWindowNative wxWindowMGL
1693 #include "wx/mgl/window.h"
1694 #elif defined(__WXDFB__)
1695 #define wxWindowNative wxWindowDFB
1696 #include "wx/dfb/window.h"
1697 #elif defined(__WXMAC__)
1698 #ifdef __WXUNIVERSAL__
1699 #define wxWindowNative wxWindowMac
1700 #else // !wxUniv
1701 #define wxWindowMac wxWindow
1702 #endif // wxUniv
1703 #include "wx/mac/window.h"
1704 #elif defined(__WXCOCOA__)
1705 #ifdef __WXUNIVERSAL__
1706 #define wxWindowNative wxWindowCocoa
1707 #else // !wxUniv
1708 #define wxWindowCocoa wxWindow
1709 #endif // wxUniv
1710 #include "wx/cocoa/window.h"
1711 #elif defined(__WXPM__)
1712 #ifdef __WXUNIVERSAL__
1713 #define wxWindowNative wxWindowOS2
1714 #else // !wxUniv
1715 #define wxWindowOS2 wxWindow
1716 #endif // wxUniv/!wxUniv
1717 #include "wx/os2/window.h"
1718 #endif
1719
1720 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1721 // for the native ports we already have defined it above
1722 #if defined(__WXUNIVERSAL__)
1723 #ifndef wxWindowNative
1724 #error "wxWindowNative must be defined above!"
1725 #endif
1726
1727 #include "wx/univ/window.h"
1728 #endif // wxUniv
1729
1730 // ----------------------------------------------------------------------------
1731 // inline functions which couldn't be declared in the class body because of
1732 // forward dependencies
1733 // ----------------------------------------------------------------------------
1734
1735 inline wxWindow *wxWindowBase::GetGrandParent() const
1736 {
1737 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
1738 }
1739
1740 // ----------------------------------------------------------------------------
1741 // global functions
1742 // ----------------------------------------------------------------------------
1743
1744 // Find the wxWindow at the current mouse position, also returning the mouse
1745 // position.
1746 extern WXDLLEXPORT wxWindow* wxFindWindowAtPointer(wxPoint& pt);
1747
1748 // Get the current mouse position.
1749 extern WXDLLEXPORT wxPoint wxGetMousePosition();
1750
1751 // get the currently active window of this application or NULL
1752 extern WXDLLEXPORT wxWindow *wxGetActiveWindow();
1753
1754 // get the (first) top level parent window
1755 WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win);
1756
1757 #if WXWIN_COMPATIBILITY_2_6
1758 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1759 wxDEPRECATED( wxWindowID NewControlId() );
1760 inline wxWindowID NewControlId() { return wxWindowBase::NewControlId(); }
1761 #endif // WXWIN_COMPATIBILITY_2_6
1762
1763 #if wxUSE_ACCESSIBILITY
1764 // ----------------------------------------------------------------------------
1765 // accessible object for windows
1766 // ----------------------------------------------------------------------------
1767
1768 class WXDLLEXPORT wxWindowAccessible: public wxAccessible
1769 {
1770 public:
1771 wxWindowAccessible(wxWindow* win): wxAccessible(win) { if (win) win->SetAccessible(this); }
1772 virtual ~wxWindowAccessible() {}
1773
1774 // Overridables
1775
1776 // Can return either a child object, or an integer
1777 // representing the child element, starting from 1.
1778 virtual wxAccStatus HitTest(const wxPoint& pt, int* childId, wxAccessible** childObject);
1779
1780 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
1781 virtual wxAccStatus GetLocation(wxRect& rect, int elementId);
1782
1783 // Navigates from fromId to toId/toObject.
1784 virtual wxAccStatus Navigate(wxNavDir navDir, int fromId,
1785 int* toId, wxAccessible** toObject);
1786
1787 // Gets the name of the specified object.
1788 virtual wxAccStatus GetName(int childId, wxString* name);
1789
1790 // Gets the number of children.
1791 virtual wxAccStatus GetChildCount(int* childCount);
1792
1793 // Gets the specified child (starting from 1).
1794 // If *child is NULL and return value is wxACC_OK,
1795 // this means that the child is a simple element and
1796 // not an accessible object.
1797 virtual wxAccStatus GetChild(int childId, wxAccessible** child);
1798
1799 // Gets the parent, or NULL.
1800 virtual wxAccStatus GetParent(wxAccessible** parent);
1801
1802 // Performs the default action. childId is 0 (the action for this object)
1803 // or > 0 (the action for a child).
1804 // Return wxACC_NOT_SUPPORTED if there is no default action for this
1805 // window (e.g. an edit control).
1806 virtual wxAccStatus DoDefaultAction(int childId);
1807
1808 // Gets the default action for this object (0) or > 0 (the action for a child).
1809 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
1810 // string if there is no action.
1811 // The retrieved string describes the action that is performed on an object,
1812 // not what the object does as a result. For example, a toolbar button that prints
1813 // a document has a default action of "Press" rather than "Prints the current document."
1814 virtual wxAccStatus GetDefaultAction(int childId, wxString* actionName);
1815
1816 // Returns the description for this object or a child.
1817 virtual wxAccStatus GetDescription(int childId, wxString* description);
1818
1819 // Returns help text for this object or a child, similar to tooltip text.
1820 virtual wxAccStatus GetHelpText(int childId, wxString* helpText);
1821
1822 // Returns the keyboard shortcut for this object or child.
1823 // Return e.g. ALT+K
1824 virtual wxAccStatus GetKeyboardShortcut(int childId, wxString* shortcut);
1825
1826 // Returns a role constant.
1827 virtual wxAccStatus GetRole(int childId, wxAccRole* role);
1828
1829 // Returns a state constant.
1830 virtual wxAccStatus GetState(int childId, long* state);
1831
1832 // Returns a localized string representing the value for the object
1833 // or child.
1834 virtual wxAccStatus GetValue(int childId, wxString* strValue);
1835
1836 // Selects the object or child.
1837 virtual wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags);
1838
1839 // Gets the window with the keyboard focus.
1840 // If childId is 0 and child is NULL, no object in
1841 // this subhierarchy has the focus.
1842 // If this object has the focus, child should be 'this'.
1843 virtual wxAccStatus GetFocus(int* childId, wxAccessible** child);
1844
1845 #if wxUSE_VARIANT
1846 // Gets a variant representing the selected children
1847 // of this object.
1848 // Acceptable values:
1849 // - a null variant (IsNull() returns true)
1850 // - a list variant (GetType() == wxT("list")
1851 // - an integer representing the selected child element,
1852 // or 0 if this object is selected (GetType() == wxT("long")
1853 // - a "void*" pointer to a wxAccessible child object
1854 virtual wxAccStatus GetSelections(wxVariant* selections);
1855 #endif // wxUSE_VARIANT
1856 };
1857
1858 #endif // wxUSE_ACCESSIBILITY
1859
1860
1861 #endif // _WX_WINDOW_H_BASE_