1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWindowBase class - the interface of wxWindow
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
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/dcclient.h"
37 #include "wx/palette.h"
38 #endif // wxUSE_PALETTE
44 // when building wxUniv/Foo we don't want the code for native menu use to be
45 // compiled in - it should only be used when building real wxFoo
46 #ifdef __WXUNIVERSAL__
47 #define wxUSE_MENUS_NATIVE 0
49 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
50 #endif // __WXUNIVERSAL__/__WXMSW__
52 // ----------------------------------------------------------------------------
53 // forward declarations
54 // ----------------------------------------------------------------------------
56 class WXDLLEXPORT wxCaret
;
57 class WXDLLEXPORT wxControl
;
58 class WXDLLEXPORT wxCursor
;
59 class WXDLLEXPORT wxDC
;
60 class WXDLLEXPORT wxDropTarget
;
61 class WXDLLEXPORT wxItemResource
;
62 class WXDLLEXPORT wxLayoutConstraints
;
63 class WXDLLEXPORT wxResourceTable
;
64 class WXDLLEXPORT wxSizer
;
65 class WXDLLEXPORT wxToolTip
;
66 class WXDLLEXPORT wxWindowBase
;
67 class WXDLLEXPORT wxWindow
;
69 // ----------------------------------------------------------------------------
70 // (pseudo)template list classes
71 // ----------------------------------------------------------------------------
73 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
, class WXDLLEXPORT
);
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
81 // ----------------------------------------------------------------------------
82 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
83 // interface of this class.
85 // Event handler: windows have themselves as their event handlers by default,
86 // but their event handlers could be set to another object entirely. This
87 // separation can reduce the amount of derivation required, and allow
88 // alteration of a window's functionality (e.g. by a resource editor that
89 // temporarily switches event handlers).
90 // ----------------------------------------------------------------------------
92 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
95 // creating the window
96 // -------------------
99 wxWindowBase() { InitBase(); }
101 // pseudo ctor (can't be virtual, called from ctor)
102 bool CreateBase(wxWindowBase
*parent
,
104 const wxPoint
& pos
= wxDefaultPosition
,
105 const wxSize
& size
= wxDefaultSize
,
107 const wxValidator
& validator
= wxDefaultValidator
,
108 const wxString
& name
= wxPanelNameStr
);
110 virtual ~wxWindowBase();
112 #if wxUSE_WX_RESOURCES
113 // these functions are implemented in resource.cpp and resourc2.cpp
114 virtual bool LoadFromResource(wxWindow
*parent
,
115 const wxString
& resourceName
,
116 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
117 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
118 const wxItemResource
* parentResource
,
119 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
120 #endif // wxUSE_WX_RESOURCES
122 // deleting the window
123 // -------------------
125 // ask the window to close itself, return TRUE if the event handler
126 // honoured our request
127 bool Close( bool force
= FALSE
);
129 // the following functions delete the C++ objects (the window itself
130 // or its children) as well as the GUI windows and normally should
131 // never be used directly
133 // delete window unconditionally (dangerous!), returns TRUE if ok
134 virtual bool Destroy();
135 // delete all children of this window, returns TRUE if ok
136 bool DestroyChildren();
138 // is the window being deleted?
139 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
144 // NB: in future versions of wxWindows Set/GetTitle() will only work
145 // with the top level windows (such as dialogs and frames) and
146 // Set/GetLabel() only with the other ones (i.e. all controls).
148 // the title (or label, see below) of the window: the text which the
150 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) {}
151 virtual wxString
GetTitle() const { return wxEmptyString
; }
153 // label is just the same as the title (but for, e.g., buttons it
154 // makes more sense to speak about labels)
155 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
156 virtual wxString
GetLabel() const { return GetTitle(); }
158 // the window name is used for ressource setting in X, it is not the
159 // same as the window title/label
160 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
161 virtual wxString
GetName() const { return m_windowName
; }
163 // window id uniquely identifies the window among its siblings unless
164 // it is -1 which means "don't care"
165 void SetId( wxWindowID id
) { m_windowId
= id
; }
166 wxWindowID
GetId() const { return m_windowId
; }
168 // generate a control id for the controls which were not given one by
170 static int NewControlId() { return --ms_lastControlId
; }
171 // get the id of the control following the one with the given
172 // (autogenerated) id
173 static int NextControlId(int id
) { return id
- 1; }
174 // get the id of the control preceding the one with the given
175 // (autogenerated) id
176 static int PrevControlId(int id
) { return id
+ 1; }
181 // set the window size and/or position
182 void SetSize( int x
, int y
, int width
, int height
,
183 int sizeFlags
= wxSIZE_AUTO
)
184 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
186 void SetSize( int width
, int height
)
187 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
189 void SetSize( const wxSize
& size
)
190 { SetSize( size
.x
, size
.y
); }
192 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
193 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
195 void Move(int x
, int y
, int flags
= wxSIZE_USE_EXISTING
)
196 { DoSetSize(x
, y
, -1, -1, flags
); }
198 void Move(const wxPoint
& pt
, int flags
= wxSIZE_USE_EXISTING
)
199 { Move(pt
.x
, pt
.y
, flags
); }
202 virtual void Raise() = 0;
203 virtual void Lower() = 0;
205 // client size is the size of area available for subwindows
206 void SetClientSize( int width
, int height
)
207 { DoSetClientSize(width
, height
); }
209 void SetClientSize( const wxSize
& size
)
210 { DoSetClientSize(size
.x
, size
.y
); }
212 void SetClientSize(const wxRect
& rect
)
213 { SetClientSize( rect
.width
, rect
.height
); }
215 // get the window position and/or size (pointers may be NULL)
216 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
217 wxPoint
GetPosition() const
220 DoGetPosition(&w
, &h
);
222 return wxPoint(w
, h
);
225 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
226 wxSize
GetSize() const
233 wxRect
GetRect() const
236 GetPosition(& x
, & y
);
239 return wxRect(x
, y
, w
, h
);
242 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
243 wxSize
GetClientSize() const
246 DoGetClientSize(& w
, & h
);
251 // get the origin of the client area of the window relative to the
252 // window top left corner (the client area may be shifted because of
253 // the borders, scrollbars, other decorations...)
254 virtual wxPoint
GetClientAreaOrigin() const;
256 // get the client rectangle in window (i.e. client) coordinates
257 wxRect
GetClientRect() const
259 return wxRect(GetClientAreaOrigin(), GetClientSize());
262 // get the size best suited for the window (in fact, minimal
263 // acceptable size using which it will still look "nice")
264 wxSize
GetBestSize() const { return DoGetBestSize(); }
265 void GetBestSize(int *w
, int *h
) const
267 wxSize s
= DoGetBestSize();
274 // the generic centre function - centers the window on parent by
275 // default or on screen if it doesn't have parent or
276 // wxCENTER_ON_SCREEN flag is given
277 void Centre( int direction
= wxBOTH
);
278 void Center( int direction
= wxBOTH
) { Centre(direction
); }
280 // centre on screen (only works for top level windows)
281 void CentreOnScreen(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_ON_SCREEN
); }
282 void CenterOnScreen(int dir
= wxBOTH
) { CentreOnScreen(dir
); }
284 // centre with respect to the the parent window
285 void CentreOnParent(int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
286 void CenterOnParent(int dir
= wxBOTH
) { CentreOnParent(dir
); }
288 // set window size to wrap around its children
291 // set min/max size of the window
292 virtual void SetSizeHints( int minW
, int minH
,
293 int maxW
= -1, int maxH
= -1,
294 int incW
= -1, int incH
= -1 );
296 virtual int GetMinWidth() const { return m_minWidth
; }
297 virtual int GetMinHeight() const { return m_minHeight
; }
298 int GetMaxWidth() const { return m_maxWidth
; }
299 int GetMaxHeight() const { return m_maxHeight
; }
304 // returns TRUE if window was shown/hidden, FALSE if the nothing was
305 // done (window was already shown/hidden)
306 virtual bool Show( bool show
= TRUE
);
307 bool Hide() { return Show(FALSE
); }
309 // returns TRUE if window was enabled/disabled, FALSE if nothing done
310 virtual bool Enable( bool enable
= TRUE
);
311 bool Disable() { return Enable(FALSE
); }
313 bool IsShown() const { return m_isShown
; }
314 bool IsEnabled() const { return m_isEnabled
; }
316 // get/set window style (setting style won't update the window and so
317 // is only useful for internal usage)
318 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
319 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
321 // just some (somewhat shorter) synonims
322 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
323 long GetWindowStyle() const { return GetWindowStyleFlag(); }
325 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
326 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
328 // extra style: the less often used style bits which can't be set with
329 // SetWindowStyleFlag()
330 void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
331 long GetExtraStyle() const { return m_exStyle
; }
333 // make the window modal (all other windows unresponsive)
334 virtual void MakeModal(bool modal
= TRUE
);
336 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
337 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
339 // focus and keyboard handling
340 // ---------------------------
342 // set focus to this window
343 virtual void SetFocus() = 0;
345 // return the window which currently has the focus or NULL
346 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
348 // can this window have focus?
349 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
351 // can this window be given focus by keyboard navigation? if not, the
352 // only way to give it focus (provided it accepts it at all) is to
354 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
356 // NB: these methods really don't belong here but with the current
357 // class hierarchy there is no other place for them :-(
359 // get the default child of this parent, i.e. the one which is
360 // activated by pressing <Enter>
361 virtual wxWindow
*GetDefaultItem() const { return NULL
; }
363 // set this child as default, return the old default
364 virtual wxWindow
*SetDefaultItem(wxWindow
* WXUNUSED(child
))
367 // parent/children relations
368 // -------------------------
370 // get the list of children
371 const wxWindowList
& GetChildren() const { return m_children
; }
372 wxWindowList
& GetChildren() { return m_children
; }
374 // get the parent or the parent of the parent
375 wxWindow
*GetParent() const { return m_parent
; }
376 inline wxWindow
*GetGrandParent() const;
378 // is this window a top level one?
379 virtual bool IsTopLevel() const;
381 // it doesn't really change parent, use ReParent() instead
382 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
383 // change the real parent of this window, return TRUE if the parent
384 // was changed, FALSE otherwise (error or newParent == oldParent)
385 virtual bool Reparent( wxWindowBase
*newParent
);
387 // find window among the descendants of this one either by id or by
388 // name (return NULL if not found)
389 wxWindow
*FindWindow( long id
);
390 wxWindow
*FindWindow( const wxString
& name
);
392 // implementation mostly
393 virtual void AddChild( wxWindowBase
*child
);
394 virtual void RemoveChild( wxWindowBase
*child
);
396 // event handler stuff
397 // -------------------
399 // get the current event handler
400 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
402 // replace the event handler (allows to completely subclass the
404 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
406 // push/pop event handler: allows to chain a custom event handler to
407 // alreasy existing ones
408 void PushEventHandler( wxEvtHandler
*handler
);
409 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
411 // find the given handler in the event handler chain and remove (but
412 // not delete) it from the event handler chain, return TRUE if it was
413 // found and FALSE otherwise (this also results in an assert failure so
414 // this function should only be called when the handler is supposed to
416 bool RemoveEventHandler(wxEvtHandler
*handler
);
422 // a window may have an associated validator which is used to control
424 virtual void SetValidator( const wxValidator
&validator
);
425 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
426 #endif // wxUSE_VALIDATORS
429 // dialog oriented functions
430 // -------------------------
432 // validate the correctness of input, return TRUE if ok
433 virtual bool Validate();
435 // transfer data between internal and GUI representations
436 virtual bool TransferDataToWindow();
437 virtual bool TransferDataFromWindow();
439 virtual void InitDialog();
444 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
445 { m_acceleratorTable
= accel
; }
446 wxAcceleratorTable
*GetAcceleratorTable()
447 { return &m_acceleratorTable
; }
448 #endif // wxUSE_ACCEL
450 // dialog units translations
451 // -------------------------
453 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
454 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
455 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
457 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
459 return wxSize(pt
.x
, pt
.y
);
462 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
464 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
466 return wxSize(pt
.x
, pt
.y
);
472 // move the mouse to the specified position
473 virtual void WarpPointer(int x
, int y
) = 0;
475 // start or end mouse capture, these functions maintain the stack of
476 // windows having captured the mouse and after calling ReleaseMouse()
477 // the mouse is not released but returns to the window which had had
478 // captured it previously (if any)
482 // get the window which currently captures the mouse or NULL
483 static wxWindow
*GetCapture();
485 // does this window have the capture?
486 virtual bool HasCapture() const
487 { return (wxWindow
*)this == GetCapture(); }
489 // painting the window
490 // -------------------
492 // mark the specified rectangle (or the whole window) as "dirty" so it
494 virtual void Refresh( bool eraseBackground
= TRUE
,
495 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
497 // a less awkward wrapper for Refresh
498 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
500 // repaint all invalid areas of the window immediately
501 virtual void Update() { }
503 // clear the window entirely
504 virtual void Clear() = 0;
506 // freeze the window: don't redraw it until it is thawed
507 virtual void Freeze() { }
509 // thaw the window: redraw it after it had been frozen
510 virtual void Thaw() { }
512 // adjust DC for drawing on this window
513 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
515 // the update region of the window contains the areas which must be
516 // repainted by the program
517 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
518 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
520 // get the update rectangleregion bounding box in client coords
521 wxRect
GetUpdateClientRect() const;
523 // these functions verify whether the given point/rectangle belongs to
524 // (or at least intersects with) the update region
525 bool IsExposed( int x
, int y
) const;
526 bool IsExposed( int x
, int y
, int w
, int h
) const;
528 bool IsExposed( const wxPoint
& pt
) const
529 { return IsExposed(pt
.x
, pt
.y
); }
530 bool IsExposed( const wxRect
& rect
) const
531 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
533 // colours, fonts and cursors
534 // --------------------------
536 // set/retrieve the window colours (system defaults are used by
537 // default): Set functions return TRUE if colour was changed
538 virtual bool SetBackgroundColour( const wxColour
&colour
);
539 virtual bool SetForegroundColour( const wxColour
&colour
);
541 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
542 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
544 // set/retrieve the cursor for this window (SetCursor() returns TRUE
545 // if the cursor was really changed)
546 virtual bool SetCursor( const wxCursor
&cursor
);
547 const wxCursor
& GetCursor() const { return m_cursor
; }
548 wxCursor
& GetCursor() { return m_cursor
; }
550 // set/retrieve the font for the window (SetFont() returns TRUE if the
551 // font really changed)
552 virtual bool SetFont( const wxFont
&font
) = 0;
553 const wxFont
& GetFont() const { return m_font
; }
554 wxFont
& GetFont() { return m_font
; }
557 // associate a caret with the window
558 void SetCaret(wxCaret
*caret
);
559 // get the current caret (may be NULL)
560 wxCaret
*GetCaret() const { return m_caret
; }
561 #endif // wxUSE_CARET
563 // get the (average) character size for the current font
564 virtual int GetCharHeight() const = 0;
565 virtual int GetCharWidth() const = 0;
567 // get the width/height/... of the text using current or specified
569 virtual void GetTextExtent(const wxString
& string
,
571 int *descent
= (int *) NULL
,
572 int *externalLeading
= (int *) NULL
,
573 const wxFont
*theFont
= (const wxFont
*) NULL
)
576 // client <-> screen coords
577 // ------------------------
579 // translate to/from screen/client coordinates (pointers may be NULL)
580 void ClientToScreen( int *x
, int *y
) const
581 { DoClientToScreen(x
, y
); }
582 void ScreenToClient( int *x
, int *y
) const
583 { DoScreenToClient(x
, y
); }
585 // wxPoint interface to do the same thing
586 wxPoint
ClientToScreen(const wxPoint
& pt
) const
588 int x
= pt
.x
, y
= pt
.y
;
589 DoClientToScreen(&x
, &y
);
591 return wxPoint(x
, y
);
594 wxPoint
ScreenToClient(const wxPoint
& pt
) const
596 int x
= pt
.x
, y
= pt
.y
;
597 DoScreenToClient(&x
, &y
);
599 return wxPoint(x
, y
);
602 // test where the given (in client coords) point lies
603 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
604 { return DoHitTest(x
, y
); }
606 wxHitTest
HitTest(const wxPoint
& pt
) const
607 { return DoHitTest(pt
.x
, pt
.y
); }
612 // get the window border style: uses the current style and falls back to
613 // the default style for this class otherwise (see GetDefaultBorder())
614 wxBorder
GetBorder() const;
616 void UpdateWindowUI();
619 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
620 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
621 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
622 { return DoPopupMenu(menu
, x
, y
); }
623 #endif // wxUSE_MENUS
628 // does the window have the scrollbar for this orientation?
629 bool HasScrollbar(int orient
) const
631 return (m_windowStyle
&
632 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
635 // configure the window scrollbars
636 virtual void SetScrollbar( int orient
,
640 bool refresh
= TRUE
) = 0;
641 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
642 virtual int GetScrollPos( int orient
) const = 0;
643 virtual int GetScrollThumb( int orient
) const = 0;
644 virtual int GetScrollRange( int orient
) const = 0;
646 // scroll window to the specified position
647 virtual void ScrollWindow( int dx
, int dy
,
648 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
650 // scrolls window by line/page: note that not all controls support this
652 // return TRUE if the position changed, FALSE otherwise
653 virtual bool ScrollLines(int WXUNUSED(lines
)) { return FALSE
; }
654 virtual bool ScrollPages(int WXUNUSED(pages
)) { return FALSE
; }
656 // convenient wrappers for ScrollLines/Pages
657 bool LineUp() { return ScrollLines(-1); }
658 bool LineDown() { return ScrollLines(1); }
659 bool PageUp() { return ScrollPages(-1); }
660 bool PageDown() { return ScrollPages(1); }
662 // context-sensitive help
663 // ----------------------
665 // these are the convenience functions wrapping wxHelpProvider methods
668 // associate this help text with this window
669 void SetHelpText(const wxString
& text
);
670 // associate this help text with all windows with the same id as this
672 void SetHelpTextForId(const wxString
& text
);
673 // get the help string associated with this window (may be empty)
674 wxString
GetHelpText() const;
681 // the easiest way to set a tooltip for a window is to use this method
682 void SetToolTip( const wxString
&tip
);
683 // attach a tooltip to the window
684 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
685 // get the associated tooltip or NULL if none
686 wxToolTip
* GetToolTip() const { return m_tooltip
; }
687 #endif // wxUSE_TOOLTIPS
691 #if wxUSE_DRAG_AND_DROP
692 // set/retrieve the drop target associated with this window (may be
693 // NULL; it's owned by the window and will be deleted by it)
694 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
695 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
696 #endif // wxUSE_DRAG_AND_DROP
698 // constraints and sizers
699 // ----------------------
700 #if wxUSE_CONSTRAINTS
701 // set the constraints for this window or retrieve them (may be NULL)
702 void SetConstraints( wxLayoutConstraints
*constraints
);
703 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
705 // when using constraints, it makes sense to update children positions
706 // automatically whenever the window is resized - this is done if
708 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
709 bool GetAutoLayout() const { return m_autoLayout
; }
711 // do layout the window and its children
712 virtual bool Layout();
714 // implementation only
715 void UnsetConstraints(wxLayoutConstraints
*c
);
716 wxWindowList
*GetConstraintsInvolvedIn() const
717 { return m_constraintsInvolvedIn
; }
718 void AddConstraintReference(wxWindowBase
*otherWin
);
719 void RemoveConstraintReference(wxWindowBase
*otherWin
);
720 void DeleteRelatedConstraints();
721 void ResetConstraints();
723 // these methods may be overriden for special layout algorithms
724 virtual void SetConstraintSizes(bool recurse
= TRUE
);
725 virtual bool LayoutPhase1(int *noChanges
);
726 virtual bool LayoutPhase2(int *noChanges
);
727 virtual bool DoPhase(int phase
);
729 // these methods are virtual but normally won't be overridden
730 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
731 virtual void MoveConstraint(int x
, int y
);
732 virtual void GetSizeConstraint(int *w
, int *h
) const ;
733 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
734 virtual void GetPositionConstraint(int *x
, int *y
) const ;
737 void SetSizer( wxSizer
*sizer
);
738 wxSizer
*GetSizer() const { return m_windowSizer
; }
740 // Track if this window is a member of a sizer
741 void SetContainingSizer(wxSizer
* sizer
) { m_containingSizer
= sizer
; }
742 wxSizer
*GetContainingSizer() const { return m_containingSizer
; }
744 #endif // wxUSE_CONSTRAINTS
746 // backward compatibility
747 // ----------------------
748 #if WXWIN_COMPATIBILITY
749 bool Enabled() const { return IsEnabled(); }
751 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
752 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
753 wxFont
& GetLabelFont() { return GetFont(); };
754 wxFont
& GetButtonFont() { return GetFont(); };
755 #endif // WXWIN_COMPATIBILITY
761 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
762 void OnInitDialog( wxInitDialogEvent
&event
);
763 void OnMiddleClick( wxMouseEvent
& event
);
765 void OnHelp(wxHelpEvent
& event
);
768 // get the haqndle of the window for the underlying window system: this
769 // is only used for wxWin itself or for user code which wants to call
770 // platform-specific APIs
771 virtual WXWidget
GetHandle() const = 0;
774 // Store the palette used by DCs in wxWindow so that the dcs can share
775 // a palette. And we can respond to palette messages.
776 wxPalette
GetPalette() const { return m_palette
; }
778 // When palette is changed tell the DC to set the system palette to the
780 void SetPalette(const wxPalette
& pal
);
782 // return true if we have a specific palette
783 bool HasCustomPalette() const { return m_hasCustomPalette
; }
785 // return the first parent window with a custom palette or NULL
786 wxWindow
*GetAncestorWithCustomPalette() const;
787 #endif // wxUSE_PALETTE
790 // the window id - a number which uniquely identifies a window among
791 // its siblings unless it is -1
792 wxWindowID m_windowId
;
794 // the parent window of this window (or NULL) and the list of the children
797 wxWindowList m_children
;
799 // the minimal allowed size for the window (no minimal size if variable(s)
801 int m_minWidth
, m_minHeight
, m_maxWidth
, m_maxHeight
;
803 // event handler for this window: usually is just 'this' but may be
804 // changed with SetEventHandler()
805 wxEvtHandler
*m_eventHandler
;
808 // associated validator or NULL if none
809 wxValidator
*m_windowValidator
;
810 #endif // wxUSE_VALIDATORS
812 #if wxUSE_DRAG_AND_DROP
813 wxDropTarget
*m_dropTarget
;
814 #endif // wxUSE_DRAG_AND_DROP
816 // visual window attributes
819 wxColour m_backgroundColour
, m_foregroundColour
;
823 #endif // wxUSE_CARET
825 // the region which should be repainted in response to paint event
826 wxRegion m_updateRegion
;
829 // the accelerator table for the window which translates key strokes into
831 wxAcceleratorTable m_acceleratorTable
;
832 #endif // wxUSE_ACCEL
834 // the tooltip for this window (may be NULL)
836 wxToolTip
*m_tooltip
;
837 #endif // wxUSE_TOOLTIPS
839 // constraints and sizers
840 #if wxUSE_CONSTRAINTS
841 // the constraints for this window or NULL
842 wxLayoutConstraints
*m_constraints
;
844 // constraints this window is involved in
845 wxWindowList
*m_constraintsInvolvedIn
;
847 // this window's sizer
848 wxSizer
*m_windowSizer
;
850 // The sizer this window is a member of, if any
851 wxSizer
*m_containingSizer
;
853 // Layout() window automatically when its size changes?
855 #endif // wxUSE_CONSTRAINTS
860 bool m_isBeingDeleted
:1;
862 // was the window colours/font explicitly changed by user?
870 wxString m_windowName
;
875 bool m_hasCustomPalette
;
876 #endif // wxUSE_PALETTE
880 // common part of all ctors: it is not virtual because it is called from
884 // override this to change the default (i.e. used when no style is
885 // specified) border for the window class
886 virtual wxBorder
GetDefaultBorder() const;
888 // get the default size for the new window if no explicit size given
889 // FIXME why 20 and not 30, 10 or ...?
890 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
891 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
893 // set the best size for the control if the default size was given:
894 // replaces the fields of size == -1 with the best values for them and
895 // calls SetSize() if needed
896 void SetBestSize(const wxSize
& size
)
898 if ( size
.x
== -1 || size
.y
== -1 )
900 wxSize sizeBest
= DoGetBestSize();
910 // more pure virtual functions
911 // ---------------------------
913 // NB: we must have DoSomething() function when Something() is an overloaded
914 // method: indeed, we can't just have "virtual Something()" in case when
915 // the function is overloaded because then we'd have to make virtual all
916 // the variants (otherwise only the virtual function may be called on a
917 // pointer to derived class according to C++ rules) which is, in
918 // general, absolutely not needed. So instead we implement all
919 // overloaded Something()s in terms of DoSomething() which will be the
920 // only one to be virtual.
922 // coordinates translation
923 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
924 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
926 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
928 // capture/release the mouse, used by Capture/ReleaseMouse()
929 virtual void DoCaptureMouse() = 0;
930 virtual void DoReleaseMouse() = 0;
932 // retrieve the position/size of the window
933 virtual void DoGetPosition( int *x
, int *y
) const = 0;
934 virtual void DoGetSize( int *width
, int *height
) const = 0;
935 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
937 // get the size which best suits the window: for a control, it would be
938 // the minimal size which doesn't truncate the control, for a panel - the
939 // same size as it would have after a call to Fit()
940 virtual wxSize
DoGetBestSize() const;
942 // this is the virtual function to be overriden in any derived class which
943 // wants to change how SetSize() or Move() works - it is called by all
944 // versions of these functions in the base class
945 virtual void DoSetSize(int x
, int y
,
946 int width
, int height
,
947 int sizeFlags
= wxSIZE_AUTO
) = 0;
949 // same as DoSetSize() for the client size
950 virtual void DoSetClientSize(int width
, int height
) = 0;
952 // move the window to the specified location and resize it: this is called
953 // from both DoSetSize() and DoSetClientSize() and would usually just
954 // reposition this window except for composite controls which will want to
955 // arrange themselves inside the given rectangle
956 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
959 virtual void DoSetToolTip( wxToolTip
*tip
);
960 #endif // wxUSE_TOOLTIPS
963 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
964 #endif // wxUSE_MENUS
966 // Makes an adjustment to the window position (for example, a frame that has
967 // a toolbar that it manages itself).
968 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
);
973 // contains the last id generated by NewControlId
974 static int ms_lastControlId
;
976 // the stack of windows which have captured the mouse
977 static struct WXDLLEXPORT wxWindowNext
*ms_winCaptureNext
;
979 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
980 DECLARE_NO_COPY_CLASS(wxWindowBase
)
981 DECLARE_EVENT_TABLE()
984 // ----------------------------------------------------------------------------
985 // now include the declaration of wxWindow class
986 // ----------------------------------------------------------------------------
988 // include the declaration of the platform-specific class
989 #if defined(__WXMSW__)
990 #ifdef __WXUNIVERSAL__
991 #define wxWindowNative wxWindowMSW
993 #define wxWindowMSW wxWindow
994 #define sm_classwxWindowMSW sm_classwxWindow
995 #endif // wxUniv/!wxUniv
996 #include "wx/msw/window.h"
997 #elif defined(__WXMOTIF__)
998 #include "wx/motif/window.h"
999 #elif defined(__WXGTK__)
1000 #ifdef __WXUNIVERSAL__
1001 #define wxWindowNative wxWindowGTK
1003 #define wxWindowGTK wxWindow
1004 #define sm_classwxWindowGTK sm_classwxWindow
1006 #include "wx/gtk/window.h"
1007 #elif defined(__WXX11__)
1008 #ifdef __WXUNIVERSAL__
1009 #define wxWindowNative wxWindowX11
1011 #define wxWindowX11 wxWindow
1012 #define sm_classwxWindowX11 sm_classwxWindow
1014 #include "wx/x11/window.h"
1015 #elif defined(__WXMGL__)
1016 #ifdef __WXUNIVERSAL__
1017 #define wxWindowNative wxWindowMGL
1019 #define wxWindowMGL wxWindow
1020 #define sm_classwxWindowMGL sm_classwxWindow
1022 #include "wx/mgl/window.h"
1023 #elif defined(__WXMAC__)
1024 #ifdef __WXUNIVERSAL__
1025 #define wxWindowNative wxWindowMac
1027 #define wxWindowMac wxWindow
1028 #define sm_classwxWindowMac sm_classwxWindow
1030 #include "wx/mac/window.h"
1031 #elif defined(__WXPM__)
1032 #ifdef __WXUNIVERSAL__
1033 #define wxWindowNative wxWindowOS2
1035 #define wxWindowOS2 wxWindow
1036 #define sm_classwxWindowOS2 sm_classwxWindow
1037 #endif // wxUniv/!wxUniv
1038 #include "wx/os2/window.h"
1041 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1042 // for the native ports we already have defined it above
1043 #if defined(__WXUNIVERSAL__)
1044 #ifndef wxWindowNative
1045 #error "wxWindowNative must be defined above!"
1048 #include "wx/univ/window.h"
1051 // ----------------------------------------------------------------------------
1052 // inline functions which couldn't be declared in the class body because of
1053 // forward dependencies
1054 // ----------------------------------------------------------------------------
1056 inline wxWindow
*wxWindowBase::GetGrandParent() const
1058 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1061 // ----------------------------------------------------------------------------
1063 // ----------------------------------------------------------------------------
1065 // Find the wxWindow at the current mouse position, also returning the mouse
1067 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1069 // Get the current mouse position.
1070 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1072 // get the currently active window of this application or NULL
1073 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1075 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1076 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1079 // _WX_WINDOW_H_BASE_