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 // when building wxUniv/Foo we don't want the code for native menu use to be
44 // compiled in - it should only be used when building real wxFoo
45 #ifdef __WXUNIVERSAL__
46 #define wxUSE_MENUS_NATIVE 0
48 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
49 #endif // __WXUNIVERSAL__/__WXMSW__
51 // ----------------------------------------------------------------------------
52 // forward declarations
53 // ----------------------------------------------------------------------------
55 class WXDLLEXPORT wxCaret
;
56 class WXDLLEXPORT wxControl
;
57 class WXDLLEXPORT wxCursor
;
58 class WXDLLEXPORT wxDC
;
59 class WXDLLEXPORT wxDropTarget
;
60 class WXDLLEXPORT wxItemResource
;
61 class WXDLLEXPORT wxLayoutConstraints
;
62 class WXDLLEXPORT wxResourceTable
;
63 class WXDLLEXPORT wxSizer
;
64 class WXDLLEXPORT wxToolTip
;
65 class WXDLLEXPORT wxWindowBase
;
66 class WXDLLEXPORT wxWindow
;
68 // ----------------------------------------------------------------------------
69 // (pseudo)template list classes
70 // ----------------------------------------------------------------------------
72 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
, class WXDLLEXPORT
);
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
80 // ----------------------------------------------------------------------------
81 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
82 // interface of this class.
84 // Event handler: windows have themselves as their event handlers by default,
85 // but their event handlers could be set to another object entirely. This
86 // separation can reduce the amount of derivation required, and allow
87 // alteration of a window's functionality (e.g. by a resource editor that
88 // temporarily switches event handlers).
89 // ----------------------------------------------------------------------------
91 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
94 // creating the window
95 // -------------------
98 wxWindowBase() { InitBase(); }
100 // pseudo ctor (can't be virtual, called from ctor)
101 bool CreateBase(wxWindowBase
*parent
,
103 const wxPoint
& pos
= wxDefaultPosition
,
104 const wxSize
& size
= wxDefaultSize
,
106 const wxValidator
& validator
= wxDefaultValidator
,
107 const wxString
& name
= wxPanelNameStr
);
109 virtual ~wxWindowBase();
111 #if wxUSE_WX_RESOURCES
112 // these functions are implemented in resource.cpp and resourc2.cpp
113 virtual bool LoadFromResource(wxWindow
*parent
,
114 const wxString
& resourceName
,
115 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
116 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
117 const wxItemResource
* parentResource
,
118 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
119 #endif // wxUSE_WX_RESOURCES
121 // deleting the window
122 // -------------------
124 // ask the window to close itself, return TRUE if the event handler
125 // honoured our request
126 bool Close( bool force
= FALSE
);
128 // the following functions delete the C++ objects (the window itself
129 // or its children) as well as the GUI windows and normally should
130 // never be used directly
132 // delete window unconditionally (dangerous!), returns TRUE if ok
133 virtual bool Destroy();
134 // delete all children of this window, returns TRUE if ok
135 bool DestroyChildren();
137 // is the window being deleted?
138 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
143 // NB: in future versions of wxWindows Set/GetTitle() will only work
144 // with the top level windows (such as dialogs and frames) and
145 // Set/GetLabel() only with the other ones (i.e. all controls).
147 // the title (or label, see below) of the window: the text which the
149 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) {}
150 virtual wxString
GetTitle() const { return wxEmptyString
; }
152 // label is just the same as the title (but for, e.g., buttons it
153 // makes more sense to speak about labels)
154 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
155 virtual wxString
GetLabel() const { return GetTitle(); }
157 // the window name is used for ressource setting in X, it is not the
158 // same as the window title/label
159 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
160 virtual wxString
GetName() const { return m_windowName
; }
162 // window id uniquely identifies the window among its siblings unless
163 // it is -1 which means "don't care"
164 void SetId( wxWindowID id
) { m_windowId
= id
; }
165 wxWindowID
GetId() const { return m_windowId
; }
167 // generate a control id for the controls which were not given one by
169 static int NewControlId() { return --ms_lastControlId
; }
170 // get the id of the control following the one with the given
171 // (autogenerated) id
172 static int NextControlId(int id
) { return id
- 1; }
173 // get the id of the control preceding the one with the given
174 // (autogenerated) id
175 static int PrevControlId(int id
) { return id
+ 1; }
180 // set the window size and/or position
181 void SetSize( int x
, int y
, int width
, int height
,
182 int sizeFlags
= wxSIZE_AUTO
)
183 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
185 void SetSize( int width
, int height
)
186 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
188 void SetSize( const wxSize
& size
)
189 { SetSize( size
.x
, size
.y
); }
191 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
192 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
194 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
195 { DoSetSize(x
, y
, -1, -1, flags
); }
197 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
198 { Move(pt
.x
, pt
.y
, flags
); }
201 virtual void Raise() = 0;
202 virtual void Lower() = 0;
204 // client size is the size of area available for subwindows
205 void SetClientSize( int width
, int height
)
206 { DoSetClientSize(width
, height
); }
208 void SetClientSize( const wxSize
& size
)
209 { DoSetClientSize(size
.x
, size
.y
); }
211 void SetClientSize(const wxRect
& rect
)
212 { SetClientSize( rect
.width
, rect
.height
); }
214 // get the window position and/or size (pointers may be NULL)
215 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
216 wxPoint
GetPosition() const
219 DoGetPosition(&w
, &h
);
221 return wxPoint(w
, h
);
224 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
225 wxSize
GetSize() const
232 wxRect
GetRect() const
235 GetPosition(& x
, & y
);
238 return wxRect(x
, y
, w
, h
);
241 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
242 wxSize
GetClientSize() const
245 DoGetClientSize(& w
, & h
);
250 // get the origin of the client area of the window relative to the
251 // window top left corner (the client area may be shifted because of
252 // the borders, scrollbars, other decorations...)
253 virtual wxPoint
GetClientAreaOrigin() const;
255 // get the client rectangle in window (i.e. client) coordinates
256 wxRect
GetClientRect() const
258 return wxRect(GetClientAreaOrigin(), GetClientSize());
261 // get the size best suited for the window (in fact, minimal
262 // acceptable size using which it will still look "nice")
263 wxSize
GetBestSize() const { return DoGetBestSize(); }
264 void GetBestSize(int *w
, int *h
) const
266 wxSize s
= DoGetBestSize();
273 // There are times (and windows) where 'Best' size and 'Min' size
274 // are vastly out of sync. This should be remedied somehow, but in
275 // the meantime, this method will return the larger of BestSize
276 // (the window's smallest legible size), and any user specified
278 wxSize
GetAdjustedBestSize() const
280 wxSize
s( DoGetBestSize() );
281 return wxSize( wxMax( s
.x
, GetMinWidth() ), wxMax( s
.y
, GetMinHeight() ) );
284 // the generic centre function - centers the window on parent by`
285 // default or on screen if it doesn't have parent or
286 // wxCENTER_ON_SCREEN flag is given
287 void Centre( int direction
= wxBOTH
);
288 void Center( int direction
= wxBOTH
) { Centre(direction
); }
290 // centre on screen (only works for top level windows)
291 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
292 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
294 // centre with respect to the the parent window
295 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
296 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
298 // set window size to wrap around its children
301 // set virtual size to satisfy children
302 virtual void FitInside();
304 // set min/max size of the window
305 virtual void SetSizeHints( int minW
, int minH
,
306 int maxW
= -1, int maxH
= -1,
307 int incW
= -1, int incH
= -1 );
309 virtual void SetVirtualSizeHints( int minW
, int minH
,
310 int maxW
= -1, int maxH
= -1 );
312 virtual int GetMinWidth() const { return m_minWidth
; }
313 virtual int GetMinHeight() const { return m_minHeight
; }
314 int GetMaxWidth() const { return m_maxWidth
; }
315 int GetMaxHeight() const { return m_maxHeight
; }
317 // Override this method to control the values given to Sizers etc.
318 virtual wxSize
GetMaxSize() const { return wxSize( m_maxWidth
, m_maxHeight
); }
320 // Methods for accessing the virtual size of a window. For most
321 // windows this is just the client area of the window, but for
322 // some like scrolled windows it is more or less independent of
323 // the screen window size. You may override the DoXXXVirtual
324 // methods below for classes where that is is the case.
326 void SetVirtualSize( const wxSize
&size
) { DoSetVirtualSize( size
.x
, size
.y
); }
327 void SetVirtualSize( int x
, int y
) { DoSetVirtualSize( x
, y
); }
329 wxSize
GetVirtualSize() const { return DoGetVirtualSize(); }
330 void GetVirtualSize( int *x
, int *y
) const
332 wxSize
s( DoGetVirtualSize() );
340 // Override these methods for windows that have a virtual size
341 // independent of their client size. eg. the virtual area of a
342 // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
344 virtual void DoSetVirtualSize( int x
, int y
);
345 virtual wxSize
DoGetVirtualSize() const; // { return m_virtualSize; }
347 // Return the largest of ClientSize and BestSize (as determined
348 // by a sizer, interior children, or other means)
350 virtual wxSize
GetBestVirtualSize() const
352 wxSize
client( GetClientSize() );
353 wxSize
best( GetBestSize() );
355 return wxSize( wxMax( client
.x
, best
.x
), wxMax( client
.y
, best
.y
) );
361 // returns TRUE if window was shown/hidden, FALSE if the nothing was
362 // done (window was already shown/hidden)
363 virtual bool Show( bool show
= TRUE
);
364 bool Hide() { return Show(FALSE
); }
366 // returns TRUE if window was enabled/disabled, FALSE if nothing done
367 virtual bool Enable( bool enable
= TRUE
);
368 bool Disable() { return Enable(FALSE
); }
370 bool IsShown() const { return m_isShown
; }
371 bool IsEnabled() const { return m_isEnabled
; }
373 // get/set window style (setting style won't update the window and so
374 // is only useful for internal usage)
375 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
376 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
378 // just some (somewhat shorter) synonims
379 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
380 long GetWindowStyle() const { return GetWindowStyleFlag(); }
382 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
383 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
385 // extra style: the less often used style bits which can't be set with
386 // SetWindowStyleFlag()
387 virtual void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
388 long GetExtraStyle() const { return m_exStyle
; }
390 // make the window modal (all other windows unresponsive)
391 virtual void MakeModal(bool modal
= TRUE
);
393 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
394 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
396 // focus and keyboard handling
397 // ---------------------------
399 // set focus to this window
400 virtual void SetFocus() = 0;
402 // set focus to this window as the result of a keyboard action
403 virtual void SetFocusFromKbd() { SetFocus(); }
405 // return the window which currently has the focus or NULL
406 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
408 // can this window have focus?
409 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
411 // can this window be given focus by keyboard navigation? if not, the
412 // only way to give it focus (provided it accepts it at all) is to
414 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
416 // NB: these methods really don't belong here but with the current
417 // class hierarchy there is no other place for them :-(
419 // get the default child of this parent, i.e. the one which is
420 // activated by pressing <Enter>
421 virtual wxWindow
*GetDefaultItem() const { return NULL
; }
423 // set this child as default, return the old default
424 virtual wxWindow
*SetDefaultItem(wxWindow
* WXUNUSED(child
))
427 // set this child as temporary default
428 virtual void SetTmpDefaultItem(wxWindow
* WXUNUSED(win
)) { }
430 // parent/children relations
431 // -------------------------
433 // get the list of children
434 const wxWindowList
& GetChildren() const { return m_children
; }
435 wxWindowList
& GetChildren() { return m_children
; }
437 // get the parent or the parent of the parent
438 wxWindow
*GetParent() const { return m_parent
; }
439 inline wxWindow
*GetGrandParent() const;
441 // is this window a top level one?
442 virtual bool IsTopLevel() const;
444 // it doesn't really change parent, use ReParent() instead
445 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
446 // change the real parent of this window, return TRUE if the parent
447 // was changed, FALSE otherwise (error or newParent == oldParent)
448 virtual bool Reparent( wxWindowBase
*newParent
);
450 // implementation mostly
451 virtual void AddChild( wxWindowBase
*child
);
452 virtual void RemoveChild( wxWindowBase
*child
);
454 // looking for windows
455 // -------------------
457 // find window among the descendants of this one either by id or by
458 // name (return NULL if not found)
459 wxWindow
*FindWindow( long id
);
460 wxWindow
*FindWindow( const wxString
& name
);
462 // Find a window among any window (all return NULL if not found)
463 static wxWindow
*FindWindowById( long id
, const wxWindow
*parent
= NULL
);
464 static wxWindow
*FindWindowByName( const wxString
& name
,
465 const wxWindow
*parent
= NULL
);
466 static wxWindow
*FindWindowByLabel( const wxString
& label
,
467 const wxWindow
*parent
= NULL
);
469 // event handler stuff
470 // -------------------
472 // get the current event handler
473 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
475 // replace the event handler (allows to completely subclass the
477 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
479 // push/pop event handler: allows to chain a custom event handler to
480 // alreasy existing ones
481 void PushEventHandler( wxEvtHandler
*handler
);
482 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
484 // find the given handler in the event handler chain and remove (but
485 // not delete) it from the event handler chain, return TRUE if it was
486 // found and FALSE otherwise (this also results in an assert failure so
487 // this function should only be called when the handler is supposed to
489 bool RemoveEventHandler(wxEvtHandler
*handler
);
495 // a window may have an associated validator which is used to control
497 virtual void SetValidator( const wxValidator
&validator
);
498 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
499 #endif // wxUSE_VALIDATORS
502 // dialog oriented functions
503 // -------------------------
505 // validate the correctness of input, return TRUE if ok
506 virtual bool Validate();
508 // transfer data between internal and GUI representations
509 virtual bool TransferDataToWindow();
510 virtual bool TransferDataFromWindow();
512 virtual void InitDialog();
517 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
518 { m_acceleratorTable
= accel
; }
519 wxAcceleratorTable
*GetAcceleratorTable()
520 { return &m_acceleratorTable
; }
521 #endif // wxUSE_ACCEL
523 // dialog units translations
524 // -------------------------
526 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
527 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
528 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
530 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
532 return wxSize(pt
.x
, pt
.y
);
535 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
537 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
539 return wxSize(pt
.x
, pt
.y
);
545 // move the mouse to the specified position
546 virtual void WarpPointer(int x
, int y
) = 0;
548 // start or end mouse capture, these functions maintain the stack of
549 // windows having captured the mouse and after calling ReleaseMouse()
550 // the mouse is not released but returns to the window which had had
551 // captured it previously (if any)
555 // get the window which currently captures the mouse or NULL
556 static wxWindow
*GetCapture();
558 // does this window have the capture?
559 virtual bool HasCapture() const
560 { return (wxWindow
*)this == GetCapture(); }
562 // painting the window
563 // -------------------
565 // mark the specified rectangle (or the whole window) as "dirty" so it
567 virtual void Refresh( bool eraseBackground
= TRUE
,
568 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
570 // a less awkward wrapper for Refresh
571 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
573 // repaint all invalid areas of the window immediately
574 virtual void Update() { }
576 // clear the window entirely
577 virtual void Clear() = 0;
579 // freeze the window: don't redraw it until it is thawed
580 virtual void Freeze() { }
582 // thaw the window: redraw it after it had been frozen
583 virtual void Thaw() { }
585 // adjust DC for drawing on this window
586 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
588 // the update region of the window contains the areas which must be
589 // repainted by the program
590 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
591 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
593 // get the update rectangleregion bounding box in client coords
594 wxRect
GetUpdateClientRect() const;
596 // these functions verify whether the given point/rectangle belongs to
597 // (or at least intersects with) the update region
598 bool IsExposed( int x
, int y
) const;
599 bool IsExposed( int x
, int y
, int w
, int h
) const;
601 bool IsExposed( const wxPoint
& pt
) const
602 { return IsExposed(pt
.x
, pt
.y
); }
603 bool IsExposed( const wxRect
& rect
) const
604 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
606 // colours, fonts and cursors
607 // --------------------------
609 // set/retrieve the window colours (system defaults are used by
610 // default): Set functions return TRUE if colour was changed
611 virtual bool SetBackgroundColour( const wxColour
&colour
);
612 virtual bool SetForegroundColour( const wxColour
&colour
);
614 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
615 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
617 // set/retrieve the cursor for this window (SetCursor() returns TRUE
618 // if the cursor was really changed)
619 virtual bool SetCursor( const wxCursor
&cursor
);
620 const wxCursor
& GetCursor() const { return m_cursor
; }
621 wxCursor
& GetCursor() { return m_cursor
; }
623 // set/retrieve the font for the window (SetFont() returns TRUE if the
624 // font really changed)
625 virtual bool SetFont( const wxFont
&font
) = 0;
626 const wxFont
& GetFont() const { return m_font
; }
627 wxFont
& GetFont() { return m_font
; }
630 // associate a caret with the window
631 void SetCaret(wxCaret
*caret
);
632 // get the current caret (may be NULL)
633 wxCaret
*GetCaret() const { return m_caret
; }
634 #endif // wxUSE_CARET
636 // get the (average) character size for the current font
637 virtual int GetCharHeight() const = 0;
638 virtual int GetCharWidth() const = 0;
640 // get the width/height/... of the text using current or specified
642 virtual void GetTextExtent(const wxString
& string
,
644 int *descent
= (int *) NULL
,
645 int *externalLeading
= (int *) NULL
,
646 const wxFont
*theFont
= (const wxFont
*) NULL
)
649 // client <-> screen coords
650 // ------------------------
652 // translate to/from screen/client coordinates (pointers may be NULL)
653 void ClientToScreen( int *x
, int *y
) const
654 { DoClientToScreen(x
, y
); }
655 void ScreenToClient( int *x
, int *y
) const
656 { DoScreenToClient(x
, y
); }
658 // wxPoint interface to do the same thing
659 wxPoint
ClientToScreen(const wxPoint
& pt
) const
661 int x
= pt
.x
, y
= pt
.y
;
662 DoClientToScreen(&x
, &y
);
664 return wxPoint(x
, y
);
667 wxPoint
ScreenToClient(const wxPoint
& pt
) const
669 int x
= pt
.x
, y
= pt
.y
;
670 DoScreenToClient(&x
, &y
);
672 return wxPoint(x
, y
);
675 // test where the given (in client coords) point lies
676 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
677 { return DoHitTest(x
, y
); }
679 wxHitTest
HitTest(const wxPoint
& pt
) const
680 { return DoHitTest(pt
.x
, pt
.y
); }
685 // get the window border style: uses the current style and falls back to
686 // the default style for this class otherwise (see GetDefaultBorder())
687 wxBorder
GetBorder() const;
689 void UpdateWindowUI();
692 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
693 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
694 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
695 { return DoPopupMenu(menu
, x
, y
); }
696 #endif // wxUSE_MENUS
701 // does the window have the scrollbar for this orientation?
702 bool HasScrollbar(int orient
) const
704 return (m_windowStyle
&
705 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
708 // configure the window scrollbars
709 virtual void SetScrollbar( int orient
,
713 bool refresh
= TRUE
) = 0;
714 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
715 virtual int GetScrollPos( int orient
) const = 0;
716 virtual int GetScrollThumb( int orient
) const = 0;
717 virtual int GetScrollRange( int orient
) const = 0;
719 // scroll window to the specified position
720 virtual void ScrollWindow( int dx
, int dy
,
721 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
723 // scrolls window by line/page: note that not all controls support this
725 // return TRUE if the position changed, FALSE otherwise
726 virtual bool ScrollLines(int WXUNUSED(lines
)) { return FALSE
; }
727 virtual bool ScrollPages(int WXUNUSED(pages
)) { return FALSE
; }
729 // convenient wrappers for ScrollLines/Pages
730 bool LineUp() { return ScrollLines(-1); }
731 bool LineDown() { return ScrollLines(1); }
732 bool PageUp() { return ScrollPages(-1); }
733 bool PageDown() { return ScrollPages(1); }
735 // context-sensitive help
736 // ----------------------
738 // these are the convenience functions wrapping wxHelpProvider methods
741 // associate this help text with this window
742 void SetHelpText(const wxString
& text
);
743 // associate this help text with all windows with the same id as this
745 void SetHelpTextForId(const wxString
& text
);
746 // get the help string associated with this window (may be empty)
747 wxString
GetHelpText() const;
754 // the easiest way to set a tooltip for a window is to use this method
755 void SetToolTip( const wxString
&tip
);
756 // attach a tooltip to the window
757 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
758 // get the associated tooltip or NULL if none
759 wxToolTip
* GetToolTip() const { return m_tooltip
; }
760 #endif // wxUSE_TOOLTIPS
764 #if wxUSE_DRAG_AND_DROP
765 // set/retrieve the drop target associated with this window (may be
766 // NULL; it's owned by the window and will be deleted by it)
767 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
768 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
769 #endif // wxUSE_DRAG_AND_DROP
771 // constraints and sizers
772 // ----------------------
773 #if wxUSE_CONSTRAINTS
774 // set the constraints for this window or retrieve them (may be NULL)
775 void SetConstraints( wxLayoutConstraints
*constraints
);
776 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
778 // implementation only
779 void UnsetConstraints(wxLayoutConstraints
*c
);
780 wxWindowList
*GetConstraintsInvolvedIn() const
781 { return m_constraintsInvolvedIn
; }
782 void AddConstraintReference(wxWindowBase
*otherWin
);
783 void RemoveConstraintReference(wxWindowBase
*otherWin
);
784 void DeleteRelatedConstraints();
785 void ResetConstraints();
787 // these methods may be overriden for special layout algorithms
788 virtual void SetConstraintSizes(bool recurse
= TRUE
);
789 virtual bool LayoutPhase1(int *noChanges
);
790 virtual bool LayoutPhase2(int *noChanges
);
791 virtual bool DoPhase(int phase
);
793 // these methods are virtual but normally won't be overridden
794 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
795 virtual void MoveConstraint(int x
, int y
);
796 virtual void GetSizeConstraint(int *w
, int *h
) const ;
797 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
798 virtual void GetPositionConstraint(int *x
, int *y
) const ;
800 #endif // wxUSE_CONSTRAINTS
802 // when using constraints or sizers, it makes sense to update
803 // children positions automatically whenever the window is resized
804 // - this is done if autoLayout is on
805 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
806 bool GetAutoLayout() const { return m_autoLayout
; }
808 // lay out the window and its children
809 virtual bool Layout();
812 void SetSizer(wxSizer
*sizer
, bool deleteOld
= TRUE
);
813 void SetSizerAndFit( wxSizer
*sizer
, bool deleteOld
= TRUE
);
815 wxSizer
*GetSizer() const { return m_windowSizer
; }
817 // Track if this window is a member of a sizer
818 void SetContainingSizer(wxSizer
* sizer
) { m_containingSizer
= sizer
; }
819 wxSizer
*GetContainingSizer() const { return m_containingSizer
; }
821 // backward compatibility
822 // ----------------------
823 #if WXWIN_COMPATIBILITY
824 bool Enabled() const { return IsEnabled(); }
826 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
827 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
828 wxFont
& GetLabelFont() { return GetFont(); };
829 wxFont
& GetButtonFont() { return GetFont(); };
830 #endif // WXWIN_COMPATIBILITY
836 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
837 void OnInitDialog( wxInitDialogEvent
&event
);
838 void OnMiddleClick( wxMouseEvent
& event
);
840 void OnHelp(wxHelpEvent
& event
);
843 // get the haqndle of the window for the underlying window system: this
844 // is only used for wxWin itself or for user code which wants to call
845 // platform-specific APIs
846 virtual WXWidget
GetHandle() const = 0;
849 // Store the palette used by DCs in wxWindow so that the dcs can share
850 // a palette. And we can respond to palette messages.
851 wxPalette
GetPalette() const { return m_palette
; }
853 // When palette is changed tell the DC to set the system palette to the
855 void SetPalette(const wxPalette
& pal
);
857 // return true if we have a specific palette
858 bool HasCustomPalette() const { return m_hasCustomPalette
; }
860 // return the first parent window with a custom palette or NULL
861 wxWindow
*GetAncestorWithCustomPalette() const;
862 #endif // wxUSE_PALETTE
865 #if wxUSE_CONSTRAINTS
866 // satisfy the constraints for the windows but don't set the window sizes
867 void SatisfyConstraints();
868 #endif // wxUSE_CONSTRAINTS
870 // the window id - a number which uniquely identifies a window among
871 // its siblings unless it is -1
872 wxWindowID m_windowId
;
874 // the parent window of this window (or NULL) and the list of the children
877 wxWindowList m_children
;
879 // the minimal allowed size for the window (no minimal size if variable(s)
886 // event handler for this window: usually is just 'this' but may be
887 // changed with SetEventHandler()
888 wxEvtHandler
*m_eventHandler
;
891 // associated validator or NULL if none
892 wxValidator
*m_windowValidator
;
893 #endif // wxUSE_VALIDATORS
895 #if wxUSE_DRAG_AND_DROP
896 wxDropTarget
*m_dropTarget
;
897 #endif // wxUSE_DRAG_AND_DROP
899 // visual window attributes
902 wxColour m_backgroundColour
, m_foregroundColour
;
906 #endif // wxUSE_CARET
908 // the region which should be repainted in response to paint event
909 wxRegion m_updateRegion
;
912 // the accelerator table for the window which translates key strokes into
914 wxAcceleratorTable m_acceleratorTable
;
915 #endif // wxUSE_ACCEL
917 // the tooltip for this window (may be NULL)
919 wxToolTip
*m_tooltip
;
920 #endif // wxUSE_TOOLTIPS
922 // constraints and sizers
923 #if wxUSE_CONSTRAINTS
924 // the constraints for this window or NULL
925 wxLayoutConstraints
*m_constraints
;
927 // constraints this window is involved in
928 wxWindowList
*m_constraintsInvolvedIn
;
929 #endif // wxUSE_CONSTRAINTS
931 // this window's sizer
932 wxSizer
*m_windowSizer
;
934 // The sizer this window is a member of, if any
935 wxSizer
*m_containingSizer
;
937 // Layout() window automatically when its size changes?
943 bool m_isBeingDeleted
:1;
945 // was the window colours/font explicitly changed by user?
953 wxString m_windowName
;
958 bool m_hasCustomPalette
;
959 #endif // wxUSE_PALETTE
961 // Virtual size (scrolling)
962 wxSize m_virtualSize
;
964 int m_minVirtualWidth
; // VirtualSizeHints
965 int m_minVirtualHeight
;
966 int m_maxVirtualWidth
;
967 int m_maxVirtualHeight
;
969 // common part of all ctors: it is not virtual because it is called from
973 // override this to change the default (i.e. used when no style is
974 // specified) border for the window class
975 virtual wxBorder
GetDefaultBorder() const;
977 // get the default size for the new window if no explicit size given
978 // FIXME why 20 and not 30, 10 or ...?
979 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
980 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
982 // set the best size for the control if the default size was given:
983 // replaces the fields of size == -1 with the best values for them and
984 // calls SetSize() if needed
986 // This function is rather unfortunately named.. it's really just a
987 // smarter SetSize / convenience function for expanding wxDefaultSize.
988 // Note that it does not influence the value returned by GetBestSize
990 void SetBestSize(const wxSize
& size
)
992 // the size only needs to be changed if the current size is incomplete,
993 // i.e. one of the components was specified as default -- so if both
994 // were given, simply don't do anything
995 if ( size
.x
== -1 || size
.y
== -1 )
997 wxSize sizeBest
= DoGetBestSize();
1001 sizeBest
.y
= size
.y
;
1007 // more pure virtual functions
1008 // ---------------------------
1010 // NB: we must have DoSomething() function when Something() is an overloaded
1011 // method: indeed, we can't just have "virtual Something()" in case when
1012 // the function is overloaded because then we'd have to make virtual all
1013 // the variants (otherwise only the virtual function may be called on a
1014 // pointer to derived class according to C++ rules) which is, in
1015 // general, absolutely not needed. So instead we implement all
1016 // overloaded Something()s in terms of DoSomething() which will be the
1017 // only one to be virtual.
1019 // coordinates translation
1020 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
1021 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
1023 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
1025 // capture/release the mouse, used by Capture/ReleaseMouse()
1026 virtual void DoCaptureMouse() = 0;
1027 virtual void DoReleaseMouse() = 0;
1029 // retrieve the position/size of the window
1030 virtual void DoGetPosition( int *x
, int *y
) const = 0;
1031 virtual void DoGetSize( int *width
, int *height
) const = 0;
1032 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
1034 // get the size which best suits the window: for a control, it would be
1035 // the minimal size which doesn't truncate the control, for a panel - the
1036 // same size as it would have after a call to Fit()
1037 virtual wxSize
DoGetBestSize() const;
1039 // this is the virtual function to be overriden in any derived class which
1040 // wants to change how SetSize() or Move() works - it is called by all
1041 // versions of these functions in the base class
1042 virtual void DoSetSize(int x
, int y
,
1043 int width
, int height
,
1044 int sizeFlags
= wxSIZE_AUTO
) = 0;
1046 // same as DoSetSize() for the client size
1047 virtual void DoSetClientSize(int width
, int height
) = 0;
1049 // move the window to the specified location and resize it: this is called
1050 // from both DoSetSize() and DoSetClientSize() and would usually just
1051 // reposition this window except for composite controls which will want to
1052 // arrange themselves inside the given rectangle
1053 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
1056 virtual void DoSetToolTip( wxToolTip
*tip
);
1057 #endif // wxUSE_TOOLTIPS
1060 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
1061 #endif // wxUSE_MENUS
1063 // Makes an adjustment to the window position (for example, a frame that has
1064 // a toolbar that it manages itself).
1065 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const;
1070 // contains the last id generated by NewControlId
1071 static int ms_lastControlId
;
1073 // the stack of windows which have captured the mouse
1074 static struct WXDLLEXPORT wxWindowNext
*ms_winCaptureNext
;
1076 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
1077 DECLARE_NO_COPY_CLASS(wxWindowBase
)
1078 DECLARE_EVENT_TABLE()
1081 // ----------------------------------------------------------------------------
1082 // now include the declaration of wxWindow class
1083 // ----------------------------------------------------------------------------
1085 // include the declaration of the platform-specific class
1086 #if defined(__WXMSW__)
1087 #ifdef __WXUNIVERSAL__
1088 #define wxWindowNative wxWindowMSW
1090 #define wxWindowMSW wxWindow
1091 #define sm_classwxWindowMSW sm_classwxWindow
1092 #endif // wxUniv/!wxUniv
1093 #include "wx/msw/window.h"
1094 #elif defined(__WXMOTIF__)
1095 #include "wx/motif/window.h"
1096 #elif defined(__WXGTK__)
1097 #ifdef __WXUNIVERSAL__
1098 #define wxWindowNative wxWindowGTK
1100 #define wxWindowGTK wxWindow
1101 #define sm_classwxWindowGTK sm_classwxWindow
1103 #include "wx/gtk/window.h"
1104 #elif defined(__WXX11__)
1105 #ifdef __WXUNIVERSAL__
1106 #define wxWindowNative wxWindowX11
1108 #define wxWindowX11 wxWindow
1109 #define sm_classwxWindowX11 sm_classwxWindow
1111 #include "wx/x11/window.h"
1112 #elif defined(__WXMGL__)
1113 #ifdef __WXUNIVERSAL__
1114 #define wxWindowNative wxWindowMGL
1116 #define wxWindowMGL wxWindow
1117 #define sm_classwxWindowMGL sm_classwxWindow
1119 #include "wx/mgl/window.h"
1120 #elif defined(__WXMAC__)
1121 #ifdef __WXUNIVERSAL__
1122 #define wxWindowNative wxWindowMac
1124 #define wxWindowMac wxWindow
1125 #define sm_classwxWindowMac sm_classwxWindow
1127 #include "wx/mac/window.h"
1128 #elif defined(__WXPM__)
1129 #ifdef __WXUNIVERSAL__
1130 #define wxWindowNative wxWindowOS2
1132 #define wxWindowOS2 wxWindow
1133 #define sm_classwxWindowOS2 sm_classwxWindow
1134 #endif // wxUniv/!wxUniv
1135 #include "wx/os2/window.h"
1138 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1139 // for the native ports we already have defined it above
1140 #if defined(__WXUNIVERSAL__)
1141 #ifndef wxWindowNative
1142 #error "wxWindowNative must be defined above!"
1145 #include "wx/univ/window.h"
1148 // ----------------------------------------------------------------------------
1149 // inline functions which couldn't be declared in the class body because of
1150 // forward dependencies
1151 // ----------------------------------------------------------------------------
1153 inline wxWindow
*wxWindowBase::GetGrandParent() const
1155 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1158 // ----------------------------------------------------------------------------
1160 // ----------------------------------------------------------------------------
1162 // Find the wxWindow at the current mouse position, also returning the mouse
1164 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1166 // Get the current mouse position.
1167 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1169 // get the currently active window of this application or NULL
1170 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1172 // get the (first) top level parent window
1173 WXDLLEXPORT wxWindow
* wxGetTopLevelParent(wxWindow
*win
);
1175 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1176 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1179 // _WX_WINDOW_H_BASE_