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 // deleting the window
120 // -------------------
122 // ask the window to close itself, return TRUE if the event handler
123 // honoured our request
124 bool Close( bool force
= FALSE
);
126 // the following functions delete the C++ objects (the window itself
127 // or its children) as well as the GUI windows and normally should
128 // never be used directly
130 // delete window unconditionally (dangerous!), returns TRUE if ok
131 virtual bool Destroy();
132 // delete all children of this window, returns TRUE if ok
133 bool DestroyChildren();
135 // is the window being deleted?
136 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
141 // NB: in future versions of wxWindows Set/GetTitle() will only work
142 // with the top level windows (such as dialogs and frames) and
143 // Set/GetLabel() only with the other ones (i.e. all controls).
145 // the title (or label, see below) of the window: the text which the
147 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) {}
148 virtual wxString
GetTitle() const { return wxEmptyString
; }
150 // label is just the same as the title (but for, e.g., buttons it
151 // makes more sense to speak about labels)
152 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
153 virtual wxString
GetLabel() const { return GetTitle(); }
155 // the window name is used for ressource setting in X, it is not the
156 // same as the window title/label
157 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
158 virtual wxString
GetName() const { return m_windowName
; }
160 // window id uniquely identifies the window among its siblings unless
161 // it is -1 which means "don't care"
162 void SetId( wxWindowID winid
) { m_windowId
= winid
; }
163 wxWindowID
GetId() const { return m_windowId
; }
165 // generate a control id for the controls which were not given one by
167 static int NewControlId() { return --ms_lastControlId
; }
168 // get the id of the control following the one with the given
169 // (autogenerated) id
170 static int NextControlId(int winid
) { return winid
- 1; }
171 // get the id of the control preceding the one with the given
172 // (autogenerated) id
173 static int PrevControlId(int winid
) { return winid
+ 1; }
178 // set the window size and/or position
179 void SetSize( int x
, int y
, int width
, int height
,
180 int sizeFlags
= wxSIZE_AUTO
)
181 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
183 void SetSize( int width
, int height
)
184 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
186 void SetSize( const wxSize
& size
)
187 { SetSize( size
.x
, size
.y
); }
189 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
190 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
192 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
193 { DoSetSize(x
, y
, -1, -1, flags
); }
195 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
196 { Move(pt
.x
, pt
.y
, flags
); }
199 virtual void Raise() = 0;
200 virtual void Lower() = 0;
202 // client size is the size of area available for subwindows
203 void SetClientSize( int width
, int height
)
204 { DoSetClientSize(width
, height
); }
206 void SetClientSize( const wxSize
& size
)
207 { DoSetClientSize(size
.x
, size
.y
); }
209 void SetClientSize(const wxRect
& rect
)
210 { SetClientSize( rect
.width
, rect
.height
); }
212 // get the window position and/or size (pointers may be NULL)
213 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
214 wxPoint
GetPosition() const
217 DoGetPosition(&w
, &h
);
219 return wxPoint(w
, h
);
222 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
223 wxSize
GetSize() const
230 wxRect
GetRect() const
233 GetPosition(& x
, & y
);
236 return wxRect(x
, y
, w
, h
);
239 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
240 wxSize
GetClientSize() const
243 DoGetClientSize(& w
, & h
);
248 // get the origin of the client area of the window relative to the
249 // window top left corner (the client area may be shifted because of
250 // the borders, scrollbars, other decorations...)
251 virtual wxPoint
GetClientAreaOrigin() const;
253 // get the client rectangle in window (i.e. client) coordinates
254 wxRect
GetClientRect() const
256 return wxRect(GetClientAreaOrigin(), GetClientSize());
259 // get the size best suited for the window (in fact, minimal
260 // acceptable size using which it will still look "nice")
261 wxSize
GetBestSize() const { return DoGetBestSize(); }
262 void GetBestSize(int *w
, int *h
) const
264 wxSize s
= DoGetBestSize();
271 // There are times (and windows) where 'Best' size and 'Min' size
272 // are vastly out of sync. This should be remedied somehow, but in
273 // the meantime, this method will return the larger of BestSize
274 // (the window's smallest legible size), and any user specified
276 wxSize
GetAdjustedBestSize() const
278 wxSize
s( DoGetBestSize() );
279 return wxSize( wxMax( s
.x
, GetMinWidth() ), wxMax( s
.y
, GetMinHeight() ) );
282 // the generic centre function - centers the window on parent by`
283 // default or on screen if it doesn't have parent or
284 // wxCENTER_ON_SCREEN flag is given
285 void Centre( int direction
= wxBOTH
);
286 void Center( int direction
= wxBOTH
) { Centre(direction
); }
288 // centre on screen (only works for top level windows)
289 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
290 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
292 // centre with respect to the the parent window
293 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
294 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
296 // set window size to wrap around its children
299 // set virtual size to satisfy children
300 virtual void FitInside();
302 // set min/max size of the window
303 virtual void SetSizeHints( int minW
, int minH
,
304 int maxW
= -1, int maxH
= -1,
305 int incW
= -1, int incH
= -1 );
307 virtual void SetVirtualSizeHints( int minW
, int minH
,
308 int maxW
= -1, int maxH
= -1 );
310 virtual int GetMinWidth() const { return m_minWidth
; }
311 virtual int GetMinHeight() const { return m_minHeight
; }
312 int GetMaxWidth() const { return m_maxWidth
; }
313 int GetMaxHeight() const { return m_maxHeight
; }
315 // Override this method to control the values given to Sizers etc.
316 virtual wxSize
GetMaxSize() const { return wxSize( m_maxWidth
, m_maxHeight
); }
318 // Methods for accessing the virtual size of a window. For most
319 // windows this is just the client area of the window, but for
320 // some like scrolled windows it is more or less independent of
321 // the screen window size. You may override the DoXXXVirtual
322 // methods below for classes where that is is the case.
324 void SetVirtualSize( const wxSize
&size
) { DoSetVirtualSize( size
.x
, size
.y
); }
325 void SetVirtualSize( int x
, int y
) { DoSetVirtualSize( x
, y
); }
327 wxSize
GetVirtualSize() const { return DoGetVirtualSize(); }
328 void GetVirtualSize( int *x
, int *y
) const
330 wxSize
s( DoGetVirtualSize() );
338 // Override these methods for windows that have a virtual size
339 // independent of their client size. eg. the virtual area of a
340 // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
342 virtual void DoSetVirtualSize( int x
, int y
);
343 virtual wxSize
DoGetVirtualSize() const; // { return m_virtualSize; }
345 // Return the largest of ClientSize and BestSize (as determined
346 // by a sizer, interior children, or other means)
348 virtual wxSize
GetBestVirtualSize() const
350 wxSize
client( GetClientSize() );
351 wxSize
best( GetBestSize() );
353 return wxSize( wxMax( client
.x
, best
.x
), wxMax( client
.y
, best
.y
) );
359 // returns TRUE if window was shown/hidden, FALSE if the nothing was
360 // done (window was already shown/hidden)
361 virtual bool Show( bool show
= TRUE
);
362 bool Hide() { return Show(FALSE
); }
364 // returns TRUE if window was enabled/disabled, FALSE if nothing done
365 virtual bool Enable( bool enable
= TRUE
);
366 bool Disable() { return Enable(FALSE
); }
368 bool IsShown() const { return m_isShown
; }
369 bool IsEnabled() const { return m_isEnabled
; }
371 // get/set window style (setting style won't update the window and so
372 // is only useful for internal usage)
373 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
374 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
376 // just some (somewhat shorter) synonims
377 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
378 long GetWindowStyle() const { return GetWindowStyleFlag(); }
380 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
381 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
383 // extra style: the less often used style bits which can't be set with
384 // SetWindowStyleFlag()
385 virtual void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
386 long GetExtraStyle() const { return m_exStyle
; }
388 // make the window modal (all other windows unresponsive)
389 virtual void MakeModal(bool modal
= TRUE
);
391 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
392 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
394 // focus and keyboard handling
395 // ---------------------------
397 // set focus to this window
398 virtual void SetFocus() = 0;
400 // set focus to this window as the result of a keyboard action
401 virtual void SetFocusFromKbd() { SetFocus(); }
403 // return the window which currently has the focus or NULL
404 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
406 // can this window have focus?
407 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
409 // can this window be given focus by keyboard navigation? if not, the
410 // only way to give it focus (provided it accepts it at all) is to
412 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
414 // NB: these methods really don't belong here but with the current
415 // class hierarchy there is no other place for them :-(
417 // get the default child of this parent, i.e. the one which is
418 // activated by pressing <Enter>
419 virtual wxWindow
*GetDefaultItem() const { return NULL
; }
421 // set this child as default, return the old default
422 virtual wxWindow
*SetDefaultItem(wxWindow
* WXUNUSED(child
))
425 // set this child as temporary default
426 virtual void SetTmpDefaultItem(wxWindow
* WXUNUSED(win
)) { }
428 // parent/children relations
429 // -------------------------
431 // get the list of children
432 const wxWindowList
& GetChildren() const { return m_children
; }
433 wxWindowList
& GetChildren() { return m_children
; }
435 // get the parent or the parent of the parent
436 wxWindow
*GetParent() const { return m_parent
; }
437 inline wxWindow
*GetGrandParent() const;
439 // is this window a top level one?
440 virtual bool IsTopLevel() const;
442 // it doesn't really change parent, use ReParent() instead
443 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
444 // change the real parent of this window, return TRUE if the parent
445 // was changed, FALSE otherwise (error or newParent == oldParent)
446 virtual bool Reparent( wxWindowBase
*newParent
);
448 // implementation mostly
449 virtual void AddChild( wxWindowBase
*child
);
450 virtual void RemoveChild( wxWindowBase
*child
);
452 // looking for windows
453 // -------------------
455 // find window among the descendants of this one either by id or by
456 // name (return NULL if not found)
457 wxWindow
*FindWindow( long winid
);
458 wxWindow
*FindWindow( const wxString
& name
);
460 // Find a window among any window (all return NULL if not found)
461 static wxWindow
*FindWindowById( long winid
, const wxWindow
*parent
= NULL
);
462 static wxWindow
*FindWindowByName( const wxString
& name
,
463 const wxWindow
*parent
= NULL
);
464 static wxWindow
*FindWindowByLabel( const wxString
& label
,
465 const wxWindow
*parent
= NULL
);
467 // event handler stuff
468 // -------------------
470 // get the current event handler
471 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
473 // replace the event handler (allows to completely subclass the
475 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
477 // push/pop event handler: allows to chain a custom event handler to
478 // alreasy existing ones
479 void PushEventHandler( wxEvtHandler
*handler
);
480 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
482 // find the given handler in the event handler chain and remove (but
483 // not delete) it from the event handler chain, return TRUE if it was
484 // found and FALSE otherwise (this also results in an assert failure so
485 // this function should only be called when the handler is supposed to
487 bool RemoveEventHandler(wxEvtHandler
*handler
);
493 // a window may have an associated validator which is used to control
495 virtual void SetValidator( const wxValidator
&validator
);
496 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
497 #endif // wxUSE_VALIDATORS
500 // dialog oriented functions
501 // -------------------------
503 // validate the correctness of input, return TRUE if ok
504 virtual bool Validate();
506 // transfer data between internal and GUI representations
507 virtual bool TransferDataToWindow();
508 virtual bool TransferDataFromWindow();
510 virtual void InitDialog();
515 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
516 { m_acceleratorTable
= accel
; }
517 wxAcceleratorTable
*GetAcceleratorTable()
518 { return &m_acceleratorTable
; }
520 #endif // wxUSE_ACCEL
523 // hot keys (system wide accelerators)
524 // -----------------------------------
526 virtual bool RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
);
527 virtual bool UnregisterHotKey(int hotkeyId
);
528 #endif // wxUSE_HOTKEY
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 from the given flags: this is different from
694 // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to
695 // translate wxBORDER_DEFAULT to something reasonable
696 wxBorder
GetBorder(long flags
) const;
698 // get border for the flags of this window
699 wxBorder
GetBorder() const { return GetBorder(GetWindowStyleFlag()); }
701 // send wxUpdateUIEvents to this window, and children if recurse is TRUE
702 virtual void UpdateWindowUI(long flags
= wxUPDATE_UI_NONE
);
704 // do the window-specific processing after processing the update event
705 virtual void DoUpdateWindowUI(wxUpdateUIEvent
& event
) ;
708 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
709 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
710 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
711 { return DoPopupMenu(menu
, x
, y
); }
712 #endif // wxUSE_MENUS
717 // does the window have the scrollbar for this orientation?
718 bool HasScrollbar(int orient
) const
720 return (m_windowStyle
&
721 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
724 // configure the window scrollbars
725 virtual void SetScrollbar( int orient
,
729 bool refresh
= TRUE
) = 0;
730 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
731 virtual int GetScrollPos( int orient
) const = 0;
732 virtual int GetScrollThumb( int orient
) const = 0;
733 virtual int GetScrollRange( int orient
) const = 0;
735 // scroll window to the specified position
736 virtual void ScrollWindow( int dx
, int dy
,
737 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
739 // scrolls window by line/page: note that not all controls support this
741 // return TRUE if the position changed, FALSE otherwise
742 virtual bool ScrollLines(int WXUNUSED(lines
)) { return FALSE
; }
743 virtual bool ScrollPages(int WXUNUSED(pages
)) { return FALSE
; }
745 // convenient wrappers for ScrollLines/Pages
746 bool LineUp() { return ScrollLines(-1); }
747 bool LineDown() { return ScrollLines(1); }
748 bool PageUp() { return ScrollPages(-1); }
749 bool PageDown() { return ScrollPages(1); }
751 // context-sensitive help
752 // ----------------------
754 // these are the convenience functions wrapping wxHelpProvider methods
757 // associate this help text with this window
758 void SetHelpText(const wxString
& text
);
759 // associate this help text with all windows with the same id as this
761 void SetHelpTextForId(const wxString
& text
);
762 // get the help string associated with this window (may be empty)
763 wxString
GetHelpText() const;
770 // the easiest way to set a tooltip for a window is to use this method
771 void SetToolTip( const wxString
&tip
);
772 // attach a tooltip to the window
773 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
774 // get the associated tooltip or NULL if none
775 wxToolTip
* GetToolTip() const { return m_tooltip
; }
776 #endif // wxUSE_TOOLTIPS
780 #if wxUSE_DRAG_AND_DROP
781 // set/retrieve the drop target associated with this window (may be
782 // NULL; it's owned by the window and will be deleted by it)
783 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
784 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
785 #endif // wxUSE_DRAG_AND_DROP
787 // constraints and sizers
788 // ----------------------
789 #if wxUSE_CONSTRAINTS
790 // set the constraints for this window or retrieve them (may be NULL)
791 void SetConstraints( wxLayoutConstraints
*constraints
);
792 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
794 // implementation only
795 void UnsetConstraints(wxLayoutConstraints
*c
);
796 wxWindowList
*GetConstraintsInvolvedIn() const
797 { return m_constraintsInvolvedIn
; }
798 void AddConstraintReference(wxWindowBase
*otherWin
);
799 void RemoveConstraintReference(wxWindowBase
*otherWin
);
800 void DeleteRelatedConstraints();
801 void ResetConstraints();
803 // these methods may be overriden for special layout algorithms
804 virtual void SetConstraintSizes(bool recurse
= TRUE
);
805 virtual bool LayoutPhase1(int *noChanges
);
806 virtual bool LayoutPhase2(int *noChanges
);
807 virtual bool DoPhase(int phase
);
809 // these methods are virtual but normally won't be overridden
810 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
811 virtual void MoveConstraint(int x
, int y
);
812 virtual void GetSizeConstraint(int *w
, int *h
) const ;
813 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
814 virtual void GetPositionConstraint(int *x
, int *y
) const ;
816 #endif // wxUSE_CONSTRAINTS
818 // when using constraints or sizers, it makes sense to update
819 // children positions automatically whenever the window is resized
820 // - this is done if autoLayout is on
821 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
822 bool GetAutoLayout() const { return m_autoLayout
; }
824 // lay out the window and its children
825 virtual bool Layout();
828 void SetSizer(wxSizer
*sizer
, bool deleteOld
= TRUE
);
829 void SetSizerAndFit( wxSizer
*sizer
, bool deleteOld
= TRUE
);
831 wxSizer
*GetSizer() const { return m_windowSizer
; }
833 // Track if this window is a member of a sizer
834 void SetContainingSizer(wxSizer
* sizer
) { m_containingSizer
= sizer
; }
835 wxSizer
*GetContainingSizer() const { return m_containingSizer
; }
838 // ----------------------
839 #if wxUSE_ACCESSIBILITY
840 // Override to create a specific accessible object.
841 virtual wxAccessible
* CreateAccessible();
843 // Sets the accessible object.
844 void SetAccessible(wxAccessible
* accessible
) ;
846 // Returns the accessible object.
847 wxAccessible
* GetAccessible() { return m_accessible
; };
849 // Returns the accessible object, creating if necessary.
850 wxAccessible
* GetOrCreateAccessible() ;
853 // backward compatibility
854 // ----------------------
855 #if WXWIN_COMPATIBILITY
856 bool Enabled() const { return IsEnabled(); }
858 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
859 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
860 wxFont
& GetLabelFont() { return GetFont(); };
861 wxFont
& GetButtonFont() { return GetFont(); };
862 #endif // WXWIN_COMPATIBILITY
868 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
869 void OnInitDialog( wxInitDialogEvent
&event
);
870 void OnMiddleClick( wxMouseEvent
& event
);
872 void OnHelp(wxHelpEvent
& event
);
875 // virtual function for implementing internal idle
877 virtual void OnInternalIdle() {}
879 // call internal idle recursively
880 // void ProcessInternalIdle() ;
882 // get the handle of the window for the underlying window system: this
883 // is only used for wxWin itself or for user code which wants to call
884 // platform-specific APIs
885 virtual WXWidget
GetHandle() const = 0;
888 // Store the palette used by DCs in wxWindow so that the dcs can share
889 // a palette. And we can respond to palette messages.
890 wxPalette
GetPalette() const { return m_palette
; }
892 // When palette is changed tell the DC to set the system palette to the
894 void SetPalette(const wxPalette
& pal
);
896 // return true if we have a specific palette
897 bool HasCustomPalette() const { return m_hasCustomPalette
; }
899 // return the first parent window with a custom palette or NULL
900 wxWindow
*GetAncestorWithCustomPalette() const;
901 #endif // wxUSE_PALETTE
904 // event handling specific to wxWindow
906 virtual bool TryValidator(wxEvent
& event
);
907 #endif // wxUSE_VALIDATORS
908 virtual bool TryParent(wxEvent
& event
);
911 #if wxUSE_CONSTRAINTS
912 // satisfy the constraints for the windows but don't set the window sizes
913 void SatisfyConstraints();
914 #endif // wxUSE_CONSTRAINTS
916 // Send the wxWindowDestroyEvent
917 void SendDestroyEvent();
919 // the window id - a number which uniquely identifies a window among
920 // its siblings unless it is -1
921 wxWindowID m_windowId
;
923 // the parent window of this window (or NULL) and the list of the children
926 wxWindowList m_children
;
928 // the minimal allowed size for the window (no minimal size if variable(s)
935 // event handler for this window: usually is just 'this' but may be
936 // changed with SetEventHandler()
937 wxEvtHandler
*m_eventHandler
;
940 // associated validator or NULL if none
941 wxValidator
*m_windowValidator
;
942 #endif // wxUSE_VALIDATORS
944 #if wxUSE_DRAG_AND_DROP
945 wxDropTarget
*m_dropTarget
;
946 #endif // wxUSE_DRAG_AND_DROP
948 // visual window attributes
951 wxColour m_backgroundColour
, m_foregroundColour
;
955 #endif // wxUSE_CARET
957 // the region which should be repainted in response to paint event
958 wxRegion m_updateRegion
;
961 // the accelerator table for the window which translates key strokes into
963 wxAcceleratorTable m_acceleratorTable
;
964 #endif // wxUSE_ACCEL
966 // the tooltip for this window (may be NULL)
968 wxToolTip
*m_tooltip
;
969 #endif // wxUSE_TOOLTIPS
971 // constraints and sizers
972 #if wxUSE_CONSTRAINTS
973 // the constraints for this window or NULL
974 wxLayoutConstraints
*m_constraints
;
976 // constraints this window is involved in
977 wxWindowList
*m_constraintsInvolvedIn
;
978 #endif // wxUSE_CONSTRAINTS
980 // this window's sizer
981 wxSizer
*m_windowSizer
;
983 // The sizer this window is a member of, if any
984 wxSizer
*m_containingSizer
;
986 // Layout() window automatically when its size changes?
992 bool m_isBeingDeleted
:1;
994 // was the window colours/font explicitly changed by user?
1002 wxString m_windowName
;
1003 bool m_themeEnabled
;
1006 wxPalette m_palette
;
1007 bool m_hasCustomPalette
;
1008 #endif // wxUSE_PALETTE
1010 #if wxUSE_ACCESSIBILITY
1011 wxAccessible
* m_accessible
;
1013 // Virtual size (scrolling)
1014 wxSize m_virtualSize
;
1016 int m_minVirtualWidth
; // VirtualSizeHints
1017 int m_minVirtualHeight
;
1018 int m_maxVirtualWidth
;
1019 int m_maxVirtualHeight
;
1021 // common part of all ctors: it is not virtual because it is called from
1025 // override this to change the default (i.e. used when no style is
1026 // specified) border for the window class
1027 virtual wxBorder
GetDefaultBorder() const;
1029 // get the default size for the new window if no explicit size given
1030 // FIXME why 20 and not 30, 10 or ...?
1031 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
1032 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
1034 // set the best size for the control if the default size was given:
1035 // replaces the fields of size == -1 with the best values for them and
1036 // calls SetSize() if needed
1038 // This function is rather unfortunately named.. it's really just a
1039 // smarter SetSize / convenience function for expanding wxDefaultSize.
1040 // Note that it does not influence the value returned by GetBestSize
1042 void SetBestSize(const wxSize
& size
)
1044 // the size only needs to be changed if the current size is incomplete,
1045 // i.e. one of the components was specified as default -- so if both
1046 // were given, simply don't do anything
1047 if ( size
.x
== -1 || size
.y
== -1 )
1049 wxSize sizeBest
= DoGetBestSize();
1051 sizeBest
.x
= size
.x
;
1053 sizeBest
.y
= size
.y
;
1059 // more pure virtual functions
1060 // ---------------------------
1062 // NB: we must have DoSomething() function when Something() is an overloaded
1063 // method: indeed, we can't just have "virtual Something()" in case when
1064 // the function is overloaded because then we'd have to make virtual all
1065 // the variants (otherwise only the virtual function may be called on a
1066 // pointer to derived class according to C++ rules) which is, in
1067 // general, absolutely not needed. So instead we implement all
1068 // overloaded Something()s in terms of DoSomething() which will be the
1069 // only one to be virtual.
1071 // coordinates translation
1072 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
1073 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
1075 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
1077 // capture/release the mouse, used by Capture/ReleaseMouse()
1078 virtual void DoCaptureMouse() = 0;
1079 virtual void DoReleaseMouse() = 0;
1081 // retrieve the position/size of the window
1082 virtual void DoGetPosition( int *x
, int *y
) const = 0;
1083 virtual void DoGetSize( int *width
, int *height
) const = 0;
1084 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
1086 // get the size which best suits the window: for a control, it would be
1087 // the minimal size which doesn't truncate the control, for a panel - the
1088 // same size as it would have after a call to Fit()
1089 virtual wxSize
DoGetBestSize() const;
1091 // this is the virtual function to be overriden in any derived class which
1092 // wants to change how SetSize() or Move() works - it is called by all
1093 // versions of these functions in the base class
1094 virtual void DoSetSize(int x
, int y
,
1095 int width
, int height
,
1096 int sizeFlags
= wxSIZE_AUTO
) = 0;
1098 // same as DoSetSize() for the client size
1099 virtual void DoSetClientSize(int width
, int height
) = 0;
1101 // move the window to the specified location and resize it: this is called
1102 // from both DoSetSize() and DoSetClientSize() and would usually just
1103 // reposition this window except for composite controls which will want to
1104 // arrange themselves inside the given rectangle
1105 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
1108 virtual void DoSetToolTip( wxToolTip
*tip
);
1109 #endif // wxUSE_TOOLTIPS
1112 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
1113 #endif // wxUSE_MENUS
1115 // Makes an adjustment to the window position (for example, a frame that has
1116 // a toolbar that it manages itself).
1117 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const;
1122 // contains the last id generated by NewControlId
1123 static int ms_lastControlId
;
1125 // the stack of windows which have captured the mouse
1126 static struct WXDLLEXPORT wxWindowNext
*ms_winCaptureNext
;
1128 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
1129 DECLARE_NO_COPY_CLASS(wxWindowBase
)
1130 DECLARE_EVENT_TABLE()
1133 // ----------------------------------------------------------------------------
1134 // now include the declaration of wxWindow class
1135 // ----------------------------------------------------------------------------
1137 // include the declaration of the platform-specific class
1138 #if defined(__WXMSW__)
1139 #ifdef __WXUNIVERSAL__
1140 #define wxWindowNative wxWindowMSW
1142 #define wxWindowMSW wxWindow
1143 #define sm_classwxWindowMSW sm_classwxWindow
1144 #endif // wxUniv/!wxUniv
1145 #include "wx/msw/window.h"
1146 #elif defined(__WXMOTIF__)
1147 #include "wx/motif/window.h"
1148 #elif defined(__WXGTK__)
1149 #ifdef __WXUNIVERSAL__
1150 #define wxWindowNative wxWindowGTK
1152 #define wxWindowGTK wxWindow
1153 #define sm_classwxWindowGTK sm_classwxWindow
1155 #include "wx/gtk/window.h"
1156 #elif defined(__WXX11__)
1157 #ifdef __WXUNIVERSAL__
1158 #define wxWindowNative wxWindowX11
1160 #define wxWindowX11 wxWindow
1161 #define sm_classwxWindowX11 sm_classwxWindow
1163 #include "wx/x11/window.h"
1164 #elif defined(__WXMGL__)
1165 #ifdef __WXUNIVERSAL__
1166 #define wxWindowNative wxWindowMGL
1168 #define wxWindowMGL wxWindow
1169 #define sm_classwxWindowMGL sm_classwxWindow
1171 #include "wx/mgl/window.h"
1172 #elif defined(__WXMAC__)
1173 #ifdef __WXUNIVERSAL__
1174 #define wxWindowNative wxWindowMac
1176 #define wxWindowMac wxWindow
1177 #define sm_classwxWindowMac sm_classwxWindow
1179 #include "wx/mac/window.h"
1180 #elif defined(__WXCOCOA__)
1181 #ifdef __WXUNIVERSAL__
1182 #define wxWindowNative wxWindowCocoa
1184 #define wxWindowCocoa wxWindow
1185 #define sm_classwxWindowCocoa sm_classwxWindow
1187 #include "wx/cocoa/window.h"
1188 #elif defined(__WXPM__)
1189 #ifdef __WXUNIVERSAL__
1190 #define wxWindowNative wxWindowOS2
1192 #define wxWindowOS2 wxWindow
1193 #define sm_classwxWindowOS2 sm_classwxWindow
1194 #endif // wxUniv/!wxUniv
1195 #include "wx/os2/window.h"
1198 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1199 // for the native ports we already have defined it above
1200 #if defined(__WXUNIVERSAL__)
1201 #ifndef wxWindowNative
1202 #error "wxWindowNative must be defined above!"
1205 #include "wx/univ/window.h"
1208 // ----------------------------------------------------------------------------
1209 // inline functions which couldn't be declared in the class body because of
1210 // forward dependencies
1211 // ----------------------------------------------------------------------------
1213 inline wxWindow
*wxWindowBase::GetGrandParent() const
1215 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1218 // ----------------------------------------------------------------------------
1220 // ----------------------------------------------------------------------------
1222 // Find the wxWindow at the current mouse position, also returning the mouse
1224 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1226 // Get the current mouse position.
1227 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1229 // get the currently active window of this application or NULL
1230 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1232 // get the (first) top level parent window
1233 WXDLLEXPORT wxWindow
* wxGetTopLevelParent(wxWindow
*win
);
1235 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1236 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1238 #if wxUSE_ACCESSIBILITY
1239 // ----------------------------------------------------------------------------
1240 // accessible object for windows
1241 // ----------------------------------------------------------------------------
1243 class WXDLLEXPORT wxWindowAccessible
: public wxAccessible
1246 wxWindowAccessible(wxWindow
* win
): wxAccessible(win
) { if (win
) win
->SetAccessible(this); }
1247 virtual ~wxWindowAccessible() {};
1251 // Can return either a child object, or an integer
1252 // representing the child element, starting from 1.
1253 virtual wxAccStatus
HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
);
1255 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
1256 virtual wxAccStatus
GetLocation(wxRect
& rect
, int elementId
);
1258 // Navigates from fromId to toId/toObject.
1259 virtual wxAccStatus
Navigate(wxNavDir navDir
, int fromId
,
1260 int* toId
, wxAccessible
** toObject
);
1262 // Gets the name of the specified object.
1263 virtual wxAccStatus
GetName(int childId
, wxString
* name
);
1265 // Gets the number of children.
1266 virtual wxAccStatus
GetChildCount(int* childCount
);
1268 // Gets the specified child (starting from 1).
1269 // If *child is NULL and return value is wxACC_OK,
1270 // this means that the child is a simple element and
1271 // not an accessible object.
1272 virtual wxAccStatus
GetChild(int childId
, wxAccessible
** child
);
1274 // Gets the parent, or NULL.
1275 virtual wxAccStatus
GetParent(wxAccessible
** parent
);
1277 // Performs the default action. childId is 0 (the action for this object)
1278 // or > 0 (the action for a child).
1279 // Return wxACC_NOT_SUPPORTED if there is no default action for this
1280 // window (e.g. an edit control).
1281 virtual wxAccStatus
DoDefaultAction(int childId
);
1283 // Gets the default action for this object (0) or > 0 (the action for a child).
1284 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
1285 // string if there is no action.
1286 // The retrieved string describes the action that is performed on an object,
1287 // not what the object does as a result. For example, a toolbar button that prints
1288 // a document has a default action of "Press" rather than "Prints the current document."
1289 virtual wxAccStatus
GetDefaultAction(int childId
, wxString
* actionName
);
1291 // Returns the description for this object or a child.
1292 virtual wxAccStatus
GetDescription(int childId
, wxString
* description
);
1294 // Returns help text for this object or a child, similar to tooltip text.
1295 virtual wxAccStatus
GetHelpText(int childId
, wxString
* helpText
);
1297 // Returns the keyboard shortcut for this object or child.
1298 // Return e.g. ALT+K
1299 virtual wxAccStatus
GetKeyboardShortcut(int childId
, wxString
* shortcut
);
1301 // Returns a role constant.
1302 virtual wxAccStatus
GetRole(int childId
, wxAccRole
* role
);
1304 // Returns a state constant.
1305 virtual wxAccStatus
GetState(int childId
, long* state
);
1307 // Returns a localized string representing the value for the object
1309 virtual wxAccStatus
GetValue(int childId
, wxString
* strValue
);
1311 // Selects the object or child.
1312 virtual wxAccStatus
Select(int childId
, wxAccSelectionFlags selectFlags
);
1314 // Gets the window with the keyboard focus.
1315 // If childId is 0 and child is NULL, no object in
1316 // this subhierarchy has the focus.
1317 // If this object has the focus, child should be 'this'.
1318 virtual wxAccStatus
GetFocus(int* childId
, wxAccessible
** child
);
1320 // Gets a variant representing the selected children
1322 // Acceptable values:
1323 // - a null variant (IsNull() returns TRUE)
1324 // - a list variant (GetType() == wxT("list")
1325 // - an integer representing the selected child element,
1326 // or 0 if this object is selected (GetType() == wxT("long")
1327 // - a "void*" pointer to a wxAccessible child object
1328 virtual wxAccStatus
GetSelections(wxVariant
* selections
);
1331 #endif // wxUSE_ACCESSIBILITY
1335 // _WX_WINDOW_H_BASE_