1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowBase class - the interface of wxWindow
4 // Author: Vadim Zeitlin
5 // Modified by: Ron Lee
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "windowbase.h"
19 // ----------------------------------------------------------------------------
20 // headers which we must include here
21 // ----------------------------------------------------------------------------
23 #include "wx/event.h" // the base class
25 #include "wx/list.h" // defines wxWindowList
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"
33 #include "wx/validate.h" // for wxDefaultValidator (always include it)
36 #include "wx/palette.h"
37 #endif // wxUSE_PALETTE
43 #if wxUSE_ACCESSIBILITY
44 #include "wx/access.h"
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
52 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
53 #endif // __WXUNIVERSAL__/__WXMSW__
55 // ----------------------------------------------------------------------------
56 // forward declarations
57 // ----------------------------------------------------------------------------
59 class WXDLLEXPORT wxCaret
;
60 class WXDLLEXPORT wxControl
;
61 class WXDLLEXPORT wxCursor
;
62 class WXDLLEXPORT wxDC
;
63 class WXDLLEXPORT wxDropTarget
;
64 class WXDLLEXPORT wxItemResource
;
65 class WXDLLEXPORT wxLayoutConstraints
;
66 class WXDLLEXPORT wxResourceTable
;
67 class WXDLLEXPORT wxSizer
;
68 class WXDLLEXPORT wxToolTip
;
69 class WXDLLEXPORT wxWindowBase
;
70 class WXDLLEXPORT wxWindow
;
72 #if wxUSE_ACCESSIBILITY
73 class WXDLLEXPORT wxAccessible
;
76 // ----------------------------------------------------------------------------
77 // (pseudo)template list classes
78 // ----------------------------------------------------------------------------
80 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
, class WXDLLEXPORT
);
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
88 // ----------------------------------------------------------------------------
89 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
90 // interface of this class.
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 // ----------------------------------------------------------------------------
99 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
102 // creating the window
103 // -------------------
106 wxWindowBase() { InitBase(); }
108 // pseudo ctor (can't be virtual, called from ctor)
109 bool CreateBase(wxWindowBase
*parent
,
111 const wxPoint
& pos
= wxDefaultPosition
,
112 const wxSize
& size
= wxDefaultSize
,
114 const wxValidator
& validator
= wxDefaultValidator
,
115 const wxString
& name
= wxPanelNameStr
);
117 virtual ~wxWindowBase();
119 #if wxUSE_WX_RESOURCES
120 // these functions are implemented in resource.cpp and resourc2.cpp
121 virtual bool LoadFromResource(wxWindow
*parent
,
122 const wxString
& resourceName
,
123 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
124 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
125 const wxItemResource
* parentResource
,
126 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
127 #endif // wxUSE_WX_RESOURCES
129 // deleting the window
130 // -------------------
132 // ask the window to close itself, return TRUE if the event handler
133 // honoured our request
134 bool Close( bool force
= FALSE
);
136 // the following functions delete the C++ objects (the window itself
137 // or its children) as well as the GUI windows and normally should
138 // never be used directly
140 // delete window unconditionally (dangerous!), returns TRUE if ok
141 virtual bool Destroy();
142 // delete all children of this window, returns TRUE if ok
143 bool DestroyChildren();
145 // is the window being deleted?
146 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
151 // NB: in future versions of wxWindows Set/GetTitle() will only work
152 // with the top level windows (such as dialogs and frames) and
153 // Set/GetLabel() only with the other ones (i.e. all controls).
155 // the title (or label, see below) of the window: the text which the
157 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) {}
158 virtual wxString
GetTitle() const { return wxEmptyString
; }
160 // label is just the same as the title (but for, e.g., buttons it
161 // makes more sense to speak about labels)
162 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
163 virtual wxString
GetLabel() const { return GetTitle(); }
165 // the window name is used for ressource setting in X, it is not the
166 // same as the window title/label
167 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
168 virtual wxString
GetName() const { return m_windowName
; }
170 // window id uniquely identifies the window among its siblings unless
171 // it is -1 which means "don't care"
172 void SetId( wxWindowID winid
) { m_windowId
= winid
; }
173 wxWindowID
GetId() const { return m_windowId
; }
175 // generate a control id for the controls which were not given one by
177 static int NewControlId() { return --ms_lastControlId
; }
178 // get the id of the control following the one with the given
179 // (autogenerated) id
180 static int NextControlId(int winid
) { return winid
- 1; }
181 // get the id of the control preceding the one with the given
182 // (autogenerated) id
183 static int PrevControlId(int winid
) { return winid
+ 1; }
188 // set the window size and/or position
189 void SetSize( int x
, int y
, int width
, int height
,
190 int sizeFlags
= wxSIZE_AUTO
)
191 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
193 void SetSize( int width
, int height
)
194 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
196 void SetSize( const wxSize
& size
)
197 { SetSize( size
.x
, size
.y
); }
199 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
200 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
202 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
203 { DoSetSize(x
, y
, -1, -1, flags
); }
205 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
206 { Move(pt
.x
, pt
.y
, flags
); }
209 virtual void Raise() = 0;
210 virtual void Lower() = 0;
212 // client size is the size of area available for subwindows
213 void SetClientSize( int width
, int height
)
214 { DoSetClientSize(width
, height
); }
216 void SetClientSize( const wxSize
& size
)
217 { DoSetClientSize(size
.x
, size
.y
); }
219 void SetClientSize(const wxRect
& rect
)
220 { SetClientSize( rect
.width
, rect
.height
); }
222 // get the window position and/or size (pointers may be NULL)
223 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
224 wxPoint
GetPosition() const
227 DoGetPosition(&w
, &h
);
229 return wxPoint(w
, h
);
232 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
233 wxSize
GetSize() const
240 wxRect
GetRect() const
243 GetPosition(& x
, & y
);
246 return wxRect(x
, y
, w
, h
);
249 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
250 wxSize
GetClientSize() const
253 DoGetClientSize(& w
, & h
);
258 // get the origin of the client area of the window relative to the
259 // window top left corner (the client area may be shifted because of
260 // the borders, scrollbars, other decorations...)
261 virtual wxPoint
GetClientAreaOrigin() const;
263 // get the client rectangle in window (i.e. client) coordinates
264 wxRect
GetClientRect() const
266 return wxRect(GetClientAreaOrigin(), GetClientSize());
269 // get the size best suited for the window (in fact, minimal
270 // acceptable size using which it will still look "nice")
271 wxSize
GetBestSize() const { return DoGetBestSize(); }
272 void GetBestSize(int *w
, int *h
) const
274 wxSize s
= DoGetBestSize();
281 // There are times (and windows) where 'Best' size and 'Min' size
282 // are vastly out of sync. This should be remedied somehow, but in
283 // the meantime, this method will return the larger of BestSize
284 // (the window's smallest legible size), and any user specified
286 wxSize
GetAdjustedBestSize() const
288 wxSize
s( DoGetBestSize() );
289 return wxSize( wxMax( s
.x
, GetMinWidth() ), wxMax( s
.y
, GetMinHeight() ) );
292 // the generic centre function - centers the window on parent by`
293 // default or on screen if it doesn't have parent or
294 // wxCENTER_ON_SCREEN flag is given
295 void Centre( int direction
= wxBOTH
);
296 void Center( int direction
= wxBOTH
) { Centre(direction
); }
298 // centre on screen (only works for top level windows)
299 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
300 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
302 // centre with respect to the the parent window
303 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
304 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
306 // set window size to wrap around its children
309 // set virtual size to satisfy children
310 virtual void FitInside();
312 // set min/max size of the window
313 virtual void SetSizeHints( int minW
, int minH
,
314 int maxW
= -1, int maxH
= -1,
315 int incW
= -1, int incH
= -1 );
317 virtual void SetVirtualSizeHints( int minW
, int minH
,
318 int maxW
= -1, int maxH
= -1 );
320 virtual int GetMinWidth() const { return m_minWidth
; }
321 virtual int GetMinHeight() const { return m_minHeight
; }
322 int GetMaxWidth() const { return m_maxWidth
; }
323 int GetMaxHeight() const { return m_maxHeight
; }
325 // Override this method to control the values given to Sizers etc.
326 virtual wxSize
GetMaxSize() const { return wxSize( m_maxWidth
, m_maxHeight
); }
328 // Methods for accessing the virtual size of a window. For most
329 // windows this is just the client area of the window, but for
330 // some like scrolled windows it is more or less independent of
331 // the screen window size. You may override the DoXXXVirtual
332 // methods below for classes where that is is the case.
334 void SetVirtualSize( const wxSize
&size
) { DoSetVirtualSize( size
.x
, size
.y
); }
335 void SetVirtualSize( int x
, int y
) { DoSetVirtualSize( x
, y
); }
337 wxSize
GetVirtualSize() const { return DoGetVirtualSize(); }
338 void GetVirtualSize( int *x
, int *y
) const
340 wxSize
s( DoGetVirtualSize() );
348 // Override these methods for windows that have a virtual size
349 // independent of their client size. eg. the virtual area of a
350 // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
352 virtual void DoSetVirtualSize( int x
, int y
);
353 virtual wxSize
DoGetVirtualSize() const; // { return m_virtualSize; }
355 // Return the largest of ClientSize and BestSize (as determined
356 // by a sizer, interior children, or other means)
358 virtual wxSize
GetBestVirtualSize() const
360 wxSize
client( GetClientSize() );
361 wxSize
best( GetBestSize() );
363 return wxSize( wxMax( client
.x
, best
.x
), wxMax( client
.y
, best
.y
) );
369 // returns TRUE if window was shown/hidden, FALSE if the nothing was
370 // done (window was already shown/hidden)
371 virtual bool Show( bool show
= TRUE
);
372 bool Hide() { return Show(FALSE
); }
374 // returns TRUE if window was enabled/disabled, FALSE if nothing done
375 virtual bool Enable( bool enable
= TRUE
);
376 bool Disable() { return Enable(FALSE
); }
378 bool IsShown() const { return m_isShown
; }
379 bool IsEnabled() const { return m_isEnabled
; }
381 // get/set window style (setting style won't update the window and so
382 // is only useful for internal usage)
383 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
384 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
386 // just some (somewhat shorter) synonims
387 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
388 long GetWindowStyle() const { return GetWindowStyleFlag(); }
390 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
391 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
393 // extra style: the less often used style bits which can't be set with
394 // SetWindowStyleFlag()
395 virtual void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
396 long GetExtraStyle() const { return m_exStyle
; }
398 // make the window modal (all other windows unresponsive)
399 virtual void MakeModal(bool modal
= TRUE
);
401 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
402 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
404 // focus and keyboard handling
405 // ---------------------------
407 // set focus to this window
408 virtual void SetFocus() = 0;
410 // set focus to this window as the result of a keyboard action
411 virtual void SetFocusFromKbd() { SetFocus(); }
413 // return the window which currently has the focus or NULL
414 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
416 // can this window have focus?
417 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
419 // can this window be given focus by keyboard navigation? if not, the
420 // only way to give it focus (provided it accepts it at all) is to
422 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
424 // NB: these methods really don't belong here but with the current
425 // class hierarchy there is no other place for them :-(
427 // get the default child of this parent, i.e. the one which is
428 // activated by pressing <Enter>
429 virtual wxWindow
*GetDefaultItem() const { return NULL
; }
431 // set this child as default, return the old default
432 virtual wxWindow
*SetDefaultItem(wxWindow
* WXUNUSED(child
))
435 // set this child as temporary default
436 virtual void SetTmpDefaultItem(wxWindow
* WXUNUSED(win
)) { }
438 // parent/children relations
439 // -------------------------
441 // get the list of children
442 const wxWindowList
& GetChildren() const { return m_children
; }
443 wxWindowList
& GetChildren() { return m_children
; }
445 // get the parent or the parent of the parent
446 wxWindow
*GetParent() const { return m_parent
; }
447 inline wxWindow
*GetGrandParent() const;
449 // is this window a top level one?
450 virtual bool IsTopLevel() const;
452 // it doesn't really change parent, use ReParent() instead
453 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
454 // change the real parent of this window, return TRUE if the parent
455 // was changed, FALSE otherwise (error or newParent == oldParent)
456 virtual bool Reparent( wxWindowBase
*newParent
);
458 // implementation mostly
459 virtual void AddChild( wxWindowBase
*child
);
460 virtual void RemoveChild( wxWindowBase
*child
);
462 // looking for windows
463 // -------------------
465 // find window among the descendants of this one either by id or by
466 // name (return NULL if not found)
467 wxWindow
*FindWindow( long winid
);
468 wxWindow
*FindWindow( const wxString
& name
);
470 // Find a window among any window (all return NULL if not found)
471 static wxWindow
*FindWindowById( long winid
, const wxWindow
*parent
= NULL
);
472 static wxWindow
*FindWindowByName( const wxString
& name
,
473 const wxWindow
*parent
= NULL
);
474 static wxWindow
*FindWindowByLabel( const wxString
& label
,
475 const wxWindow
*parent
= NULL
);
477 // event handler stuff
478 // -------------------
480 // get the current event handler
481 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
483 // replace the event handler (allows to completely subclass the
485 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
487 // push/pop event handler: allows to chain a custom event handler to
488 // alreasy existing ones
489 void PushEventHandler( wxEvtHandler
*handler
);
490 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
492 // find the given handler in the event handler chain and remove (but
493 // not delete) it from the event handler chain, return TRUE if it was
494 // found and FALSE otherwise (this also results in an assert failure so
495 // this function should only be called when the handler is supposed to
497 bool RemoveEventHandler(wxEvtHandler
*handler
);
503 // a window may have an associated validator which is used to control
505 virtual void SetValidator( const wxValidator
&validator
);
506 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
507 #endif // wxUSE_VALIDATORS
510 // dialog oriented functions
511 // -------------------------
513 // validate the correctness of input, return TRUE if ok
514 virtual bool Validate();
516 // transfer data between internal and GUI representations
517 virtual bool TransferDataToWindow();
518 virtual bool TransferDataFromWindow();
520 virtual void InitDialog();
525 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
526 { m_acceleratorTable
= accel
; }
527 wxAcceleratorTable
*GetAcceleratorTable()
528 { return &m_acceleratorTable
; }
529 #endif // wxUSE_ACCEL
531 // dialog units translations
532 // -------------------------
534 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
535 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
536 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
538 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
540 return wxSize(pt
.x
, pt
.y
);
543 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
545 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
547 return wxSize(pt
.x
, pt
.y
);
553 // move the mouse to the specified position
554 virtual void WarpPointer(int x
, int y
) = 0;
556 // start or end mouse capture, these functions maintain the stack of
557 // windows having captured the mouse and after calling ReleaseMouse()
558 // the mouse is not released but returns to the window which had had
559 // captured it previously (if any)
563 // get the window which currently captures the mouse or NULL
564 static wxWindow
*GetCapture();
566 // does this window have the capture?
567 virtual bool HasCapture() const
568 { return (wxWindow
*)this == GetCapture(); }
570 // painting the window
571 // -------------------
573 // mark the specified rectangle (or the whole window) as "dirty" so it
575 virtual void Refresh( bool eraseBackground
= TRUE
,
576 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
578 // a less awkward wrapper for Refresh
579 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
581 // repaint all invalid areas of the window immediately
582 virtual void Update() { }
584 // clear the window entirely
585 virtual void Clear() = 0;
587 // freeze the window: don't redraw it until it is thawed
588 virtual void Freeze() { }
590 // thaw the window: redraw it after it had been frozen
591 virtual void Thaw() { }
593 // adjust DC for drawing on this window
594 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
596 // the update region of the window contains the areas which must be
597 // repainted by the program
598 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
599 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
601 // get the update rectangleregion bounding box in client coords
602 wxRect
GetUpdateClientRect() const;
604 // these functions verify whether the given point/rectangle belongs to
605 // (or at least intersects with) the update region
606 bool IsExposed( int x
, int y
) const;
607 bool IsExposed( int x
, int y
, int w
, int h
) const;
609 bool IsExposed( const wxPoint
& pt
) const
610 { return IsExposed(pt
.x
, pt
.y
); }
611 bool IsExposed( const wxRect
& rect
) const
612 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
614 // colours, fonts and cursors
615 // --------------------------
617 // set/retrieve the window colours (system defaults are used by
618 // default): Set functions return TRUE if colour was changed
619 virtual bool SetBackgroundColour( const wxColour
&colour
);
620 virtual bool SetForegroundColour( const wxColour
&colour
);
622 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
623 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
625 // set/retrieve the cursor for this window (SetCursor() returns TRUE
626 // if the cursor was really changed)
627 virtual bool SetCursor( const wxCursor
&cursor
);
628 const wxCursor
& GetCursor() const { return m_cursor
; }
629 wxCursor
& GetCursor() { return m_cursor
; }
631 // set/retrieve the font for the window (SetFont() returns TRUE if the
632 // font really changed)
633 virtual bool SetFont( const wxFont
&font
) = 0;
634 const wxFont
& GetFont() const { return m_font
; }
635 wxFont
& GetFont() { return m_font
; }
638 // associate a caret with the window
639 void SetCaret(wxCaret
*caret
);
640 // get the current caret (may be NULL)
641 wxCaret
*GetCaret() const { return m_caret
; }
642 #endif // wxUSE_CARET
644 // get the (average) character size for the current font
645 virtual int GetCharHeight() const = 0;
646 virtual int GetCharWidth() const = 0;
648 // get the width/height/... of the text using current or specified
650 virtual void GetTextExtent(const wxString
& string
,
652 int *descent
= (int *) NULL
,
653 int *externalLeading
= (int *) NULL
,
654 const wxFont
*theFont
= (const wxFont
*) NULL
)
657 // client <-> screen coords
658 // ------------------------
660 // translate to/from screen/client coordinates (pointers may be NULL)
661 void ClientToScreen( int *x
, int *y
) const
662 { DoClientToScreen(x
, y
); }
663 void ScreenToClient( int *x
, int *y
) const
664 { DoScreenToClient(x
, y
); }
666 // wxPoint interface to do the same thing
667 wxPoint
ClientToScreen(const wxPoint
& pt
) const
669 int x
= pt
.x
, y
= pt
.y
;
670 DoClientToScreen(&x
, &y
);
672 return wxPoint(x
, y
);
675 wxPoint
ScreenToClient(const wxPoint
& pt
) const
677 int x
= pt
.x
, y
= pt
.y
;
678 DoScreenToClient(&x
, &y
);
680 return wxPoint(x
, y
);
683 // test where the given (in client coords) point lies
684 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
685 { return DoHitTest(x
, y
); }
687 wxHitTest
HitTest(const wxPoint
& pt
) const
688 { return DoHitTest(pt
.x
, pt
.y
); }
693 // get the window border style: uses the current style and falls back to
694 // the default style for this class otherwise (see GetDefaultBorder())
695 wxBorder
GetBorder() const;
697 void UpdateWindowUI();
700 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
701 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
702 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
703 { return DoPopupMenu(menu
, x
, y
); }
704 #endif // wxUSE_MENUS
709 // does the window have the scrollbar for this orientation?
710 bool HasScrollbar(int orient
) const
712 return (m_windowStyle
&
713 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
716 // configure the window scrollbars
717 virtual void SetScrollbar( int orient
,
721 bool refresh
= TRUE
) = 0;
722 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
723 virtual int GetScrollPos( int orient
) const = 0;
724 virtual int GetScrollThumb( int orient
) const = 0;
725 virtual int GetScrollRange( int orient
) const = 0;
727 // scroll window to the specified position
728 virtual void ScrollWindow( int dx
, int dy
,
729 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
731 // scrolls window by line/page: note that not all controls support this
733 // return TRUE if the position changed, FALSE otherwise
734 virtual bool ScrollLines(int WXUNUSED(lines
)) { return FALSE
; }
735 virtual bool ScrollPages(int WXUNUSED(pages
)) { return FALSE
; }
737 // convenient wrappers for ScrollLines/Pages
738 bool LineUp() { return ScrollLines(-1); }
739 bool LineDown() { return ScrollLines(1); }
740 bool PageUp() { return ScrollPages(-1); }
741 bool PageDown() { return ScrollPages(1); }
743 // context-sensitive help
744 // ----------------------
746 // these are the convenience functions wrapping wxHelpProvider methods
749 // associate this help text with this window
750 void SetHelpText(const wxString
& text
);
751 // associate this help text with all windows with the same id as this
753 void SetHelpTextForId(const wxString
& text
);
754 // get the help string associated with this window (may be empty)
755 wxString
GetHelpText() const;
762 // the easiest way to set a tooltip for a window is to use this method
763 void SetToolTip( const wxString
&tip
);
764 // attach a tooltip to the window
765 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
766 // get the associated tooltip or NULL if none
767 wxToolTip
* GetToolTip() const { return m_tooltip
; }
768 #endif // wxUSE_TOOLTIPS
772 #if wxUSE_DRAG_AND_DROP
773 // set/retrieve the drop target associated with this window (may be
774 // NULL; it's owned by the window and will be deleted by it)
775 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
776 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
777 #endif // wxUSE_DRAG_AND_DROP
779 // constraints and sizers
780 // ----------------------
781 #if wxUSE_CONSTRAINTS
782 // set the constraints for this window or retrieve them (may be NULL)
783 void SetConstraints( wxLayoutConstraints
*constraints
);
784 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
786 // implementation only
787 void UnsetConstraints(wxLayoutConstraints
*c
);
788 wxWindowList
*GetConstraintsInvolvedIn() const
789 { return m_constraintsInvolvedIn
; }
790 void AddConstraintReference(wxWindowBase
*otherWin
);
791 void RemoveConstraintReference(wxWindowBase
*otherWin
);
792 void DeleteRelatedConstraints();
793 void ResetConstraints();
795 // these methods may be overriden for special layout algorithms
796 virtual void SetConstraintSizes(bool recurse
= TRUE
);
797 virtual bool LayoutPhase1(int *noChanges
);
798 virtual bool LayoutPhase2(int *noChanges
);
799 virtual bool DoPhase(int phase
);
801 // these methods are virtual but normally won't be overridden
802 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
803 virtual void MoveConstraint(int x
, int y
);
804 virtual void GetSizeConstraint(int *w
, int *h
) const ;
805 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
806 virtual void GetPositionConstraint(int *x
, int *y
) const ;
808 #endif // wxUSE_CONSTRAINTS
810 // when using constraints or sizers, it makes sense to update
811 // children positions automatically whenever the window is resized
812 // - this is done if autoLayout is on
813 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
814 bool GetAutoLayout() const { return m_autoLayout
; }
816 // lay out the window and its children
817 virtual bool Layout();
820 void SetSizer(wxSizer
*sizer
, bool deleteOld
= TRUE
);
821 void SetSizerAndFit( wxSizer
*sizer
, bool deleteOld
= TRUE
);
823 wxSizer
*GetSizer() const { return m_windowSizer
; }
825 // Track if this window is a member of a sizer
826 void SetContainingSizer(wxSizer
* sizer
) { m_containingSizer
= sizer
; }
827 wxSizer
*GetContainingSizer() const { return m_containingSizer
; }
830 // ----------------------
831 #if wxUSE_ACCESSIBILITY
832 // Override to create a specific accessible object.
833 virtual wxAccessible
* CreateAccessible();
835 // Sets the accessible object.
836 void SetAccessible(wxAccessible
* accessible
) ;
838 // Returns the accessible object.
839 wxAccessible
* GetAccessible() { return m_accessible
; };
841 // Returns the accessible object, creating if necessary.
842 wxAccessible
* GetOrCreateAccessible() ;
845 // backward compatibility
846 // ----------------------
847 #if WXWIN_COMPATIBILITY
848 bool Enabled() const { return IsEnabled(); }
850 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
851 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
852 wxFont
& GetLabelFont() { return GetFont(); };
853 wxFont
& GetButtonFont() { return GetFont(); };
854 #endif // WXWIN_COMPATIBILITY
860 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
861 void OnInitDialog( wxInitDialogEvent
&event
);
862 void OnMiddleClick( wxMouseEvent
& event
);
864 void OnHelp(wxHelpEvent
& event
);
867 // get the haqndle of the window for the underlying window system: this
868 // is only used for wxWin itself or for user code which wants to call
869 // platform-specific APIs
870 virtual WXWidget
GetHandle() const = 0;
873 // Store the palette used by DCs in wxWindow so that the dcs can share
874 // a palette. And we can respond to palette messages.
875 wxPalette
GetPalette() const { return m_palette
; }
877 // When palette is changed tell the DC to set the system palette to the
879 void SetPalette(const wxPalette
& pal
);
881 // return true if we have a specific palette
882 bool HasCustomPalette() const { return m_hasCustomPalette
; }
884 // return the first parent window with a custom palette or NULL
885 wxWindow
*GetAncestorWithCustomPalette() const;
886 #endif // wxUSE_PALETTE
889 #if wxUSE_CONSTRAINTS
890 // satisfy the constraints for the windows but don't set the window sizes
891 void SatisfyConstraints();
892 #endif // wxUSE_CONSTRAINTS
894 // Send the wxWindowDestroyEvent
895 void SendDestroyEvent();
897 // the window id - a number which uniquely identifies a window among
898 // its siblings unless it is -1
899 wxWindowID m_windowId
;
901 // the parent window of this window (or NULL) and the list of the children
904 wxWindowList m_children
;
906 // the minimal allowed size for the window (no minimal size if variable(s)
913 // event handler for this window: usually is just 'this' but may be
914 // changed with SetEventHandler()
915 wxEvtHandler
*m_eventHandler
;
918 // associated validator or NULL if none
919 wxValidator
*m_windowValidator
;
920 #endif // wxUSE_VALIDATORS
922 #if wxUSE_DRAG_AND_DROP
923 wxDropTarget
*m_dropTarget
;
924 #endif // wxUSE_DRAG_AND_DROP
926 // visual window attributes
929 wxColour m_backgroundColour
, m_foregroundColour
;
933 #endif // wxUSE_CARET
935 // the region which should be repainted in response to paint event
936 wxRegion m_updateRegion
;
939 // the accelerator table for the window which translates key strokes into
941 wxAcceleratorTable m_acceleratorTable
;
942 #endif // wxUSE_ACCEL
944 // the tooltip for this window (may be NULL)
946 wxToolTip
*m_tooltip
;
947 #endif // wxUSE_TOOLTIPS
949 // constraints and sizers
950 #if wxUSE_CONSTRAINTS
951 // the constraints for this window or NULL
952 wxLayoutConstraints
*m_constraints
;
954 // constraints this window is involved in
955 wxWindowList
*m_constraintsInvolvedIn
;
956 #endif // wxUSE_CONSTRAINTS
958 // this window's sizer
959 wxSizer
*m_windowSizer
;
961 // The sizer this window is a member of, if any
962 wxSizer
*m_containingSizer
;
964 // Layout() window automatically when its size changes?
970 bool m_isBeingDeleted
:1;
972 // was the window colours/font explicitly changed by user?
980 wxString m_windowName
;
985 bool m_hasCustomPalette
;
986 #endif // wxUSE_PALETTE
988 #if wxUSE_ACCESSIBILITY
989 wxAccessible
* m_accessible
;
991 // Virtual size (scrolling)
992 wxSize m_virtualSize
;
994 int m_minVirtualWidth
; // VirtualSizeHints
995 int m_minVirtualHeight
;
996 int m_maxVirtualWidth
;
997 int m_maxVirtualHeight
;
999 // common part of all ctors: it is not virtual because it is called from
1003 // override this to change the default (i.e. used when no style is
1004 // specified) border for the window class
1005 virtual wxBorder
GetDefaultBorder() const;
1007 // get the default size for the new window if no explicit size given
1008 // FIXME why 20 and not 30, 10 or ...?
1009 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
1010 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
1012 // set the best size for the control if the default size was given:
1013 // replaces the fields of size == -1 with the best values for them and
1014 // calls SetSize() if needed
1016 // This function is rather unfortunately named.. it's really just a
1017 // smarter SetSize / convenience function for expanding wxDefaultSize.
1018 // Note that it does not influence the value returned by GetBestSize
1020 void SetBestSize(const wxSize
& size
)
1022 // the size only needs to be changed if the current size is incomplete,
1023 // i.e. one of the components was specified as default -- so if both
1024 // were given, simply don't do anything
1025 if ( size
.x
== -1 || size
.y
== -1 )
1027 wxSize sizeBest
= DoGetBestSize();
1029 sizeBest
.x
= size
.x
;
1031 sizeBest
.y
= size
.y
;
1037 // more pure virtual functions
1038 // ---------------------------
1040 // NB: we must have DoSomething() function when Something() is an overloaded
1041 // method: indeed, we can't just have "virtual Something()" in case when
1042 // the function is overloaded because then we'd have to make virtual all
1043 // the variants (otherwise only the virtual function may be called on a
1044 // pointer to derived class according to C++ rules) which is, in
1045 // general, absolutely not needed. So instead we implement all
1046 // overloaded Something()s in terms of DoSomething() which will be the
1047 // only one to be virtual.
1049 // coordinates translation
1050 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
1051 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
1053 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
1055 // capture/release the mouse, used by Capture/ReleaseMouse()
1056 virtual void DoCaptureMouse() = 0;
1057 virtual void DoReleaseMouse() = 0;
1059 // retrieve the position/size of the window
1060 virtual void DoGetPosition( int *x
, int *y
) const = 0;
1061 virtual void DoGetSize( int *width
, int *height
) const = 0;
1062 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
1064 // get the size which best suits the window: for a control, it would be
1065 // the minimal size which doesn't truncate the control, for a panel - the
1066 // same size as it would have after a call to Fit()
1067 virtual wxSize
DoGetBestSize() const;
1069 // this is the virtual function to be overriden in any derived class which
1070 // wants to change how SetSize() or Move() works - it is called by all
1071 // versions of these functions in the base class
1072 virtual void DoSetSize(int x
, int y
,
1073 int width
, int height
,
1074 int sizeFlags
= wxSIZE_AUTO
) = 0;
1076 // same as DoSetSize() for the client size
1077 virtual void DoSetClientSize(int width
, int height
) = 0;
1079 // move the window to the specified location and resize it: this is called
1080 // from both DoSetSize() and DoSetClientSize() and would usually just
1081 // reposition this window except for composite controls which will want to
1082 // arrange themselves inside the given rectangle
1083 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
1086 virtual void DoSetToolTip( wxToolTip
*tip
);
1087 #endif // wxUSE_TOOLTIPS
1090 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
1091 #endif // wxUSE_MENUS
1093 // Makes an adjustment to the window position (for example, a frame that has
1094 // a toolbar that it manages itself).
1095 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const;
1100 // contains the last id generated by NewControlId
1101 static int ms_lastControlId
;
1103 // the stack of windows which have captured the mouse
1104 static struct WXDLLEXPORT wxWindowNext
*ms_winCaptureNext
;
1106 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
1107 DECLARE_NO_COPY_CLASS(wxWindowBase
)
1108 DECLARE_EVENT_TABLE()
1111 // ----------------------------------------------------------------------------
1112 // now include the declaration of wxWindow class
1113 // ----------------------------------------------------------------------------
1115 // include the declaration of the platform-specific class
1116 #if defined(__WXMSW__)
1117 #ifdef __WXUNIVERSAL__
1118 #define wxWindowNative wxWindowMSW
1120 #define wxWindowMSW wxWindow
1121 #define sm_classwxWindowMSW sm_classwxWindow
1122 #endif // wxUniv/!wxUniv
1123 #include "wx/msw/window.h"
1124 #elif defined(__WXMOTIF__)
1125 #include "wx/motif/window.h"
1126 #elif defined(__WXGTK__)
1127 #ifdef __WXUNIVERSAL__
1128 #define wxWindowNative wxWindowGTK
1130 #define wxWindowGTK wxWindow
1131 #define sm_classwxWindowGTK sm_classwxWindow
1133 #include "wx/gtk/window.h"
1134 #elif defined(__WXX11__)
1135 #ifdef __WXUNIVERSAL__
1136 #define wxWindowNative wxWindowX11
1138 #define wxWindowX11 wxWindow
1139 #define sm_classwxWindowX11 sm_classwxWindow
1141 #include "wx/x11/window.h"
1142 #elif defined(__WXMGL__)
1143 #ifdef __WXUNIVERSAL__
1144 #define wxWindowNative wxWindowMGL
1146 #define wxWindowMGL wxWindow
1147 #define sm_classwxWindowMGL sm_classwxWindow
1149 #include "wx/mgl/window.h"
1150 #elif defined(__WXMAC__)
1151 #ifdef __WXUNIVERSAL__
1152 #define wxWindowNative wxWindowMac
1154 #define wxWindowMac wxWindow
1155 #define sm_classwxWindowMac sm_classwxWindow
1157 #include "wx/mac/window.h"
1158 #elif defined(__WXCOCOA__)
1159 #ifdef __WXUNIVERSAL__
1160 #define wxWindowNative wxWindowCocoa
1162 #define wxWindowCocoa wxWindow
1163 #define sm_classwxWindowCocoa sm_classwxWindow
1165 #include "wx/cocoa/window.h"
1166 #elif defined(__WXPM__)
1167 #ifdef __WXUNIVERSAL__
1168 #define wxWindowNative wxWindowOS2
1170 #define wxWindowOS2 wxWindow
1171 #define sm_classwxWindowOS2 sm_classwxWindow
1172 #endif // wxUniv/!wxUniv
1173 #include "wx/os2/window.h"
1176 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1177 // for the native ports we already have defined it above
1178 #if defined(__WXUNIVERSAL__)
1179 #ifndef wxWindowNative
1180 #error "wxWindowNative must be defined above!"
1183 #include "wx/univ/window.h"
1186 // ----------------------------------------------------------------------------
1187 // inline functions which couldn't be declared in the class body because of
1188 // forward dependencies
1189 // ----------------------------------------------------------------------------
1191 inline wxWindow
*wxWindowBase::GetGrandParent() const
1193 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1196 // ----------------------------------------------------------------------------
1198 // ----------------------------------------------------------------------------
1200 // Find the wxWindow at the current mouse position, also returning the mouse
1202 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1204 // Get the current mouse position.
1205 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1207 // get the currently active window of this application or NULL
1208 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1210 // get the (first) top level parent window
1211 WXDLLEXPORT wxWindow
* wxGetTopLevelParent(wxWindow
*win
);
1213 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1214 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1216 #if wxUSE_ACCESSIBILITY
1217 // ----------------------------------------------------------------------------
1218 // accessible object for windows
1219 // ----------------------------------------------------------------------------
1221 class WXDLLEXPORT wxWindowAccessible
: public wxAccessible
1224 wxWindowAccessible(wxWindow
* win
): wxAccessible(win
) { if (win
) win
->SetAccessible(this); }
1225 virtual ~wxWindowAccessible() {};
1229 // Can return either a child object, or an integer
1230 // representing the child element, starting from 1.
1231 virtual wxAccStatus
HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
);
1233 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
1234 virtual wxAccStatus
GetLocation(wxRect
& rect
, int elementId
);
1236 // Navigates from fromId to toId/toObject.
1237 virtual wxAccStatus
Navigate(wxNavDir navDir
, int fromId
,
1238 int* toId
, wxAccessible
** toObject
);
1240 // Gets the name of the specified object.
1241 virtual wxAccStatus
GetName(int childId
, wxString
* name
);
1243 // Gets the number of children.
1244 virtual wxAccStatus
GetChildCount(int* childId
);
1246 // Gets the specified child (starting from 1).
1247 // If *child is NULL and return value is wxACC_OK,
1248 // this means that the child is a simple element and
1249 // not an accessible object.
1250 virtual wxAccStatus
GetChild(int childId
, wxAccessible
** child
);
1252 // Gets the parent, or NULL.
1253 virtual wxAccStatus
GetParent(wxAccessible
** parent
);
1255 // Performs the default action. childId is 0 (the action for this object)
1256 // or > 0 (the action for a child).
1257 // Return wxACC_NOT_SUPPORTED if there is no default action for this
1258 // window (e.g. an edit control).
1259 virtual wxAccStatus
DoDefaultAction(int childId
);
1261 // Gets the default action for this object (0) or > 0 (the action for a child).
1262 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
1263 // string if there is no action.
1264 // The retrieved string describes the action that is performed on an object,
1265 // not what the object does as a result. For example, a toolbar button that prints
1266 // a document has a default action of "Press" rather than "Prints the current document."
1267 virtual wxAccStatus
GetDefaultAction(int childId
, wxString
* actionName
);
1269 // Returns the description for this object or a child.
1270 virtual wxAccStatus
GetDescription(int childId
, wxString
* description
);
1272 // Returns help text for this object or a child, similar to tooltip text.
1273 virtual wxAccStatus
GetHelpText(int childId
, wxString
* helpText
);
1275 // Returns the keyboard shortcut for this object or child.
1276 // Return e.g. ALT+K
1277 virtual wxAccStatus
GetKeyboardShortcut(int childId
, wxString
* shortcut
);
1279 // Returns a role constant.
1280 virtual wxAccStatus
GetRole(int childId
, wxAccRole
* role
);
1282 // Returns a state constant.
1283 virtual wxAccStatus
GetState(int childId
, long* state
);
1285 // Returns a localized string representing the value for the object
1287 virtual wxAccStatus
GetValue(int childId
, wxString
* strValue
);
1289 // Selects the object or child.
1290 virtual wxAccStatus
Select(int childId
, wxAccSelectionFlags selectFlags
);
1292 // Gets the window with the keyboard focus.
1293 // If childId is 0 and child is NULL, no object in
1294 // this subhierarchy has the focus.
1295 // If this object has the focus, child should be 'this'.
1296 virtual wxAccStatus
GetFocus(int* childId
, wxAccessible
** child
);
1298 // Gets a variant representing the selected children
1300 // Acceptable values:
1301 // - a null variant (IsNull() returns TRUE)
1302 // - a list variant (GetType() == wxT("list")
1303 // - an integer representing the selected child element,
1304 // or 0 if this object is selected (GetType() == wxT("long")
1305 // - a "void*" pointer to a wxAccessible child object
1306 virtual wxAccStatus
GetSelections(wxVariant
* selections
);
1309 #endif // wxUSE_ACCESSIBILITY
1313 // _WX_WINDOW_H_BASE_