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)
39 // ----------------------------------------------------------------------------
40 // forward declarations
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxCaret
;
44 class WXDLLEXPORT wxClientData
;
45 class WXDLLEXPORT wxControl
;
46 class WXDLLEXPORT wxCursor
;
47 class WXDLLEXPORT wxDC
;
48 class WXDLLEXPORT wxDropTarget
;
49 class WXDLLEXPORT wxItemResource
;
50 class WXDLLEXPORT wxLayoutConstraints
;
51 class WXDLLEXPORT wxResourceTable
;
52 class WXDLLEXPORT wxSizer
;
53 class WXDLLEXPORT wxToolTip
;
54 class WXDLLEXPORT wxWindowBase
;
55 class WXDLLEXPORT wxWindow
;
57 // ----------------------------------------------------------------------------
58 // (pseudo)template list classes
59 // ----------------------------------------------------------------------------
61 WX_DECLARE_LIST_3(wxWindow
, wxWindowBase
, wxWindowList
, wxWindowListNode
);
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 WXDLLEXPORT_DATA(extern wxWindowList
) wxTopLevelWindows
;
69 // ----------------------------------------------------------------------------
70 // helper classes used by [SG]etClientObject/Data
72 // TODO move into a separate header?
73 // ----------------------------------------------------------------------------
79 virtual ~wxClientData() { }
82 class wxStringClientData
: public wxClientData
85 wxStringClientData() { }
86 wxStringClientData( const wxString
&data
) : m_data(data
) { }
87 void SetData( const wxString
&data
) { m_data
= data
; }
88 const wxString
& GetData() const { return m_data
; }
94 // ----------------------------------------------------------------------------
95 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
96 // interface of this class.
98 // Event handler: windows have themselves as their event handlers by default,
99 // but their event handlers could be set to another object entirely. This
100 // separation can reduce the amount of derivation required, and allow
101 // alteration of a window's functionality (e.g. by a resource editor that
102 // temporarily switches event handlers).
103 // ----------------------------------------------------------------------------
105 class WXDLLEXPORT wxWindowBase
: public wxEvtHandler
107 DECLARE_ABSTRACT_CLASS(wxWindowBase
);
110 // creating the window
111 // -------------------
114 wxWindowBase() { InitBase(); }
116 // pseudo ctor (can't be virtual, called from ctor)
117 bool CreateBase(wxWindowBase
*parent
,
119 const wxPoint
& pos
= wxDefaultPosition
,
120 const wxSize
& size
= wxDefaultSize
,
122 const wxValidator
& validator
= wxDefaultValidator
,
123 const wxString
& name
= wxPanelNameStr
);
125 virtual ~wxWindowBase();
127 #if wxUSE_WX_RESOURCES
128 // these functions are implemented in resource.cpp and resourc2.cpp
129 virtual bool LoadFromResource(wxWindow
*parent
,
130 const wxString
& resourceName
,
131 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
132 virtual wxControl
*CreateItem(const wxItemResource
* childResource
,
133 const wxItemResource
* parentResource
,
134 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
135 #endif // wxUSE_WX_RESOURCES
137 // deleting the window
138 // -------------------
140 // ask the window to close itself, return TRUE if the event handler
141 // honoured our request
142 bool Close( bool force
= FALSE
);
144 // the following functions delete the C++ objects (the window itself
145 // or its children) as well as the GUI windows and normally should
146 // never be used directly
148 // delete window unconditionally (dangerous!), returns TRUE if ok
149 virtual bool Destroy();
150 // delete all children of this window, returns TRUE if ok
151 bool DestroyChildren();
153 // is the window being deleted?
154 bool IsBeingDeleted() const { return m_isBeingDeleted
; }
159 // the title (or label, see below) of the window: the text which the
161 virtual void SetTitle( const wxString
& WXUNUSED(title
) ) { }
162 virtual wxString
GetTitle() const { return ""; }
164 // label is just the same as the title (but for, e.g., buttons it
165 // makes more sense to speak about labels)
166 virtual void SetLabel(const wxString
& label
) { SetTitle(label
); }
167 virtual wxString
GetLabel() const { return GetTitle(); }
169 // the window name is used for ressource setting in X, it is not the
170 // same as the window title/label
171 virtual void SetName( const wxString
&name
) { m_windowName
= name
; }
172 virtual wxString
GetName() const { return m_windowName
; }
174 // window id uniquely identifies the window among its siblings unless
175 // it is -1 which means "don't care"
176 void SetId( wxWindowID id
) { m_windowId
= id
; }
177 wxWindowID
GetId() const { return m_windowId
; }
179 // generate a control id for the controls which were not given one by
181 static int NewControlId() { return --ms_lastControlId
; }
182 // get the id of the control following the one with the given
183 // (autogenerated) id
184 static int NextControlId(int id
) { return id
- 1; }
185 // get the id of the control preceding the one with the given
186 // (autogenerated) id
187 static int PrevControlId(int id
) { return id
+ 1; }
192 // set the window size and/or position
193 void SetSize( int x
, int y
, int width
, int height
,
194 int sizeFlags
= wxSIZE_AUTO
)
195 { DoSetSize(x
, y
, width
, height
, sizeFlags
); }
197 void SetSize( int width
, int height
)
198 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
200 void SetSize( const wxSize
& size
)
201 { SetSize( size
.x
, size
.y
); }
203 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
204 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
206 void Move( int x
, int y
)
207 { DoSetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
); }
209 void Move(const wxPoint
& pt
)
210 { Move(pt
.x
, pt
.y
); }
213 virtual void Raise() = 0;
214 virtual void Lower() = 0;
216 // client size is the size of area available for subwindows
217 void SetClientSize( int width
, int height
)
218 { DoSetClientSize(width
, height
); }
220 void SetClientSize( const wxSize
& size
)
221 { DoSetClientSize(size
.x
, size
.y
); }
223 void SetClientSize(const wxRect
& rect
)
224 { SetClientSize( rect
.width
, rect
.height
); }
226 // get the window position and/or size (pointers may be NULL)
227 void GetPosition( int *x
, int *y
) const { DoGetPosition(x
, y
); }
228 wxPoint
GetPosition() const
231 DoGetPosition(&w
, &h
);
233 return wxPoint(w
, h
);
236 void GetSize( int *w
, int *h
) const { DoGetSize(w
, h
); }
237 wxSize
GetSize() const
244 wxRect
GetRect() const
247 GetPosition(& x
, & y
);
250 return wxRect(x
, y
, w
, h
);
253 void GetClientSize( int *w
, int *h
) const { DoGetClientSize(w
, h
); }
254 wxSize
GetClientSize() const
257 DoGetClientSize(& w
, & h
);
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 // centre with respect to the the parent window
275 void Centre( int direction
= wxBOTH
);
276 void Center( int direction
= wxBOTH
) { Centre(direction
); }
277 void CentreOnParent( int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
278 void CenterOnParent( int dir
= wxBOTH
) { Centre(dir
| wxCENTER_FRAME
); }
280 // set window size to wrap around its children
283 // set min/max size of the window
284 virtual void SetSizeHints( int minW
, int minH
,
285 int maxW
= -1, int maxH
= -1,
286 int incW
= -1, int incH
= -1 );
288 int GetMinWidth() const { return m_minWidth
; }
289 int GetMinHeight() const { return m_minHeight
; }
290 int GetMaxWidth() const { return m_maxWidth
; }
291 int GetMaxHeight() const { return m_maxHeight
; }
296 // returns TRUE if window was shown/hidden, FALSE if the nothing was
297 // done (window was already shown/hidden)
298 virtual bool Show( bool show
= TRUE
);
299 bool Hide() { return Show(FALSE
); }
301 // returns TRUE if window was enabled/disabled, FALSE if nothing done
302 virtual bool Enable( bool enable
= TRUE
);
303 bool Disable() { return Enable(FALSE
); }
305 bool IsShown() const { return m_isShown
; }
306 bool IsEnabled() const { return m_isEnabled
; }
308 // get/set window style (setting style won't update the window and so
309 // is only useful for internal usage)
310 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
311 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
313 // just some (somewhat shorter) synonims
314 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
315 long GetWindowStyle() const { return GetWindowStyleFlag(); }
317 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
319 virtual bool IsRetained() const
320 { return (m_windowStyle
& wxRETAINED
) != 0; }
322 // make the window modal (all other windows unresponsive)
323 virtual void MakeModal(bool modal
= TRUE
);
328 // set focus to this window
329 virtual void SetFocus() = 0;
331 // return the window which currently has the focus or NULL
332 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
334 // can this window have focus?
335 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
337 // parent/children relations
338 // -------------------------
340 // get the list of children
341 const wxWindowList
& GetChildren() const { return m_children
; }
342 wxWindowList
& GetChildren() { return m_children
; }
344 // get the parent or the parent of the parent
345 wxWindow
*GetParent() const { return m_parent
; }
346 inline wxWindow
*GetGrandParent() const;
348 // is this window a top level one?
349 virtual bool IsTopLevel() const;
351 // it doesn't really change parent, use ReParent() instead
352 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
353 // change the real parent of this window, return TRUE if the parent
354 // was changed, FALSE otherwise (error or newParent == oldParent)
355 virtual bool Reparent( wxWindowBase
*newParent
);
357 // find window among the descendants of this one either by id or by
358 // name (return NULL if not found)
359 wxWindow
*FindWindow( long id
);
360 wxWindow
*FindWindow( const wxString
& name
);
362 // implementation mostly
363 virtual void AddChild( wxWindowBase
*child
);
364 virtual void RemoveChild( wxWindowBase
*child
);
366 // event handler stuff
367 // -------------------
369 // get the current event handler
370 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
372 // replace the event handler (allows to completely subclass the
374 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
376 // push/pop event handler: allows to chain a custom event handler to
377 // alreasy existing ones
378 void PushEventHandler( wxEvtHandler
*handler
);
379 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
381 // validators and client data
382 // --------------------------
385 // a window may have an associated validator which is used to control
387 virtual void SetValidator( const wxValidator
&validator
);
388 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
389 #endif // wxUSE_VALIDATORS
391 // each window may have associated client data: either a pointer to
392 // wxClientData object in which case it is managed by the window (i.e.
393 // it will delete the data when it's destroyed) or an untyped pointer
394 // which won't be deleted by the window - but not both of them
395 void SetClientObject( wxClientData
*data
) { DoSetClientObject(data
); }
396 wxClientData
*GetClientObject() const { return DoGetClientObject(); }
398 void SetClientData( void *data
) { DoSetClientData(data
); }
399 void *GetClientData() const { return DoGetClientData(); }
401 // dialog oriented functions
402 // -------------------------
404 // validate the correctness of input, return TRUE if ok
405 virtual bool Validate();
407 // transfer data between internal and GUI representations
408 virtual bool TransferDataToWindow();
409 virtual bool TransferDataFromWindow();
411 virtual void InitDialog();
416 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
417 { m_acceleratorTable
= accel
; }
418 wxAcceleratorTable
*GetAcceleratorTable()
419 { return &m_acceleratorTable
; }
420 #endif // wxUSE_ACCEL
422 // dialog units translations
423 // -------------------------
425 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
426 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
427 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
429 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
431 return wxSize(pt
.x
, pt
.y
);
434 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
436 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
438 return wxSize(pt
.x
, pt
.y
);
444 // move the mouse to the specified position
445 virtual void WarpPointer(int x
, int y
) = 0;
447 // start or end mouse capture
448 virtual void CaptureMouse() = 0;
449 virtual void ReleaseMouse() = 0;
451 // painting the window
452 // -------------------
454 // mark the specified rectangle (or the whole window) as "dirty" so it
456 virtual void Refresh( bool eraseBackground
= TRUE
,
457 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
458 // clear the window entirely
459 virtual void Clear() = 0;
461 // adjust DC for drawing on this window
462 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
464 // the update region of the window contains the areas which must be
465 // repainted by the program
466 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
467 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
469 // these functions verify whether the given point/rectangle belongs to
470 // (or at least intersects with) the update region
471 bool IsExposed( int x
, int y
) const;
472 bool IsExposed( int x
, int y
, int w
, int h
) const;
474 bool IsExposed( const wxPoint
& pt
) const
475 { return IsExposed(pt
.x
, pt
.y
); }
476 bool IsExposed( const wxRect
& rect
) const
477 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
479 // colours, fonts and cursors
480 // --------------------------
482 // set/retrieve the window colours (system defaults are used by
483 // default): Set functions return TRUE if colour was changed
484 virtual bool SetBackgroundColour( const wxColour
&colour
);
485 virtual bool SetForegroundColour( const wxColour
&colour
);
487 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
488 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
490 // set/retrieve the cursor for this window (SetCursor() returns TRUE
491 // if the cursor was really changed)
492 virtual bool SetCursor( const wxCursor
&cursor
);
493 const wxCursor
& GetCursor() const { return m_cursor
; }
494 wxCursor
& GetCursor() { return m_cursor
; }
496 // set/retrieve the font for the window (SetFont() returns TRUE if the
497 // font really changed)
498 virtual bool SetFont( const wxFont
&font
) = 0;
499 const wxFont
& GetFont() const { return m_font
; }
500 wxFont
& GetFont() { return m_font
; }
503 // associate a caret with the window
504 void SetCaret(wxCaret
*caret
);
505 // get the current caret (may be NULL)
506 wxCaret
*GetCaret() const { return m_caret
; }
507 #endif // wxUSE_CARET
509 // get the (average) character size for the current font
510 virtual int GetCharHeight() const = 0;
511 virtual int GetCharWidth() const = 0;
513 // get the width/height/... of the text using current or specified
515 virtual void GetTextExtent(const wxString
& string
,
517 int *descent
= (int *) NULL
,
518 int *externalLeading
= (int *) NULL
,
519 const wxFont
*theFont
= (const wxFont
*) NULL
)
522 // translate to/from screen/client coordinates (pointers may be NULL)
523 void ClientToScreen( int *x
, int *y
) const
524 { DoClientToScreen(x
, y
); }
525 void ScreenToClient( int *x
, int *y
) const
526 { DoScreenToClient(x
, y
); }
527 wxPoint
ClientToScreen(const wxPoint
& pt
) const
529 int x
= pt
.x
, y
= pt
.y
;
530 DoClientToScreen(&x
, &y
);
532 return wxPoint(x
, y
);
535 wxPoint
ScreenToClient(const wxPoint
& pt
) const
537 int x
= pt
.x
, y
= pt
.y
;
538 DoScreenToClient(&x
, &y
);
540 return wxPoint(x
, y
);
546 void UpdateWindowUI();
548 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
549 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
550 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
551 { return DoPopupMenu(menu
, x
, y
); }
556 // configure the window scrollbars
557 virtual void SetScrollbar( int orient
,
561 bool refresh
= TRUE
) = 0;
562 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
563 virtual int GetScrollPos( int orient
) const = 0;
564 virtual int GetScrollThumb( int orient
) const = 0;
565 virtual int GetScrollRange( int orient
) const = 0;
567 // scroll window to the specified position
568 virtual void ScrollWindow( int dx
, int dy
,
569 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
574 // the easiest way to set a tooltip for a window is to use this method
575 void SetToolTip( const wxString
&tip
);
576 // attach a tooltip to the window
577 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
578 // get the associated tooltip or NULL if none
579 wxToolTip
* GetToolTip() const { return m_tooltip
; }
580 #endif // wxUSE_TOOLTIPS
584 #if wxUSE_DRAG_AND_DROP
585 // set/retrieve the drop target associated with this window (may be
586 // NULL; it's owned by the window and will be deleted by it)
587 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
588 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
589 #endif // wxUSE_DRAG_AND_DROP
591 // constraints and sizers
592 // ----------------------
593 #if wxUSE_CONSTRAINTS
594 // set the constraints for this window or retrieve them (may be NULL)
595 void SetConstraints( wxLayoutConstraints
*constraints
);
596 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
598 // when using constraints, it makes sense to update children positions
599 // automatically whenever the window is resized - this is done if
601 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
602 bool GetAutoLayout() const { return m_autoLayout
; }
604 // do layout the window and its children
605 virtual bool Layout();
607 // implementation only
608 void UnsetConstraints(wxLayoutConstraints
*c
);
609 wxWindowList
*GetConstraintsInvolvedIn() const
610 { return m_constraintsInvolvedIn
; }
611 void AddConstraintReference(wxWindowBase
*otherWin
);
612 void RemoveConstraintReference(wxWindowBase
*otherWin
);
613 void DeleteRelatedConstraints();
614 void ResetConstraints();
616 // these methods may be overriden for special layout algorithms
617 virtual void SetConstraintSizes(bool recurse
= TRUE
);
618 virtual bool LayoutPhase1(int *noChanges
);
619 virtual bool LayoutPhase2(int *noChanges
);
620 virtual bool DoPhase(int);
622 // these methods are virtual but normally won't be overridden
623 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
624 virtual void MoveConstraint(int x
, int y
);
625 virtual void GetSizeConstraint(int *w
, int *h
) const ;
626 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
627 virtual void GetPositionConstraint(int *x
, int *y
) const ;
630 // TODO: what are they and how do they work??
631 void SetSizer( wxSizer
*sizer
);
632 wxSizer
*GetSizer() const { return m_windowSizer
; }
633 #endif // wxUSE_CONSTRAINTS
635 // backward compatibility
636 // ----------------------
637 #if WXWIN_COMPATIBILITY
638 bool Enabled() const { return IsEnabled(); }
640 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
641 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
642 wxFont
& GetLabelFont() { return GetFont(); };
643 wxFont
& GetButtonFont() { return GetFont(); };
644 #endif // WXWIN_COMPATIBILITY
650 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
651 void OnInitDialog( wxInitDialogEvent
&event
);
653 // get the haqndle of the window for the underlying window system: this
654 // is only used for wxWin itself or for user code which wants to call
655 // platform-specific APIs
656 virtual WXWidget
GetHandle() const = 0;
659 // the window id - a number which uniquely identifies a window among
660 // its siblings unless it is -1
661 wxWindowID m_windowId
;
663 // the parent window of this window (or NULL) and the list of the children
666 wxWindowList m_children
;
668 // the minimal allowed size for the window (no minimal size if variable(s)
670 int m_minWidth
, m_minHeight
, m_maxWidth
, m_maxHeight
;
672 // event handler for this window: usually is just 'this' but may be
673 // changed with SetEventHandler()
674 wxEvtHandler
*m_eventHandler
;
677 // associated validator or NULL if none
678 wxValidator
*m_windowValidator
;
679 #endif // wxUSE_VALIDATORS
681 #if wxUSE_DRAG_AND_DROP
682 wxDropTarget
*m_dropTarget
;
683 #endif // wxUSE_DRAG_AND_DROP
685 // visual window attributes
688 wxColour m_backgroundColour
, m_foregroundColour
;
692 #endif // wxUSE_CARET
694 // the region which should be repainted in response to paint event
695 wxRegion m_updateRegion
;
698 // the accelerator table for the window which translates key strokes into
700 wxAcceleratorTable m_acceleratorTable
;
701 #endif // wxUSE_ACCEL
703 // user data associated with the window: either an object which will be
704 // deleted by the window when it's deleted or some raw pointer which we do
705 // nothing with - only one type of data can be used with the given window
706 // (i.e. you cannot set the void data and then associate the window with
707 // wxClientData or vice versa)
710 wxClientData
*m_clientObject
;
714 // the tooltip for this window (may be NULL)
716 wxToolTip
*m_tooltip
;
717 #endif // wxUSE_TOOLTIPS
719 // constraints and sizers
720 #if wxUSE_CONSTRAINTS
721 // the constraints for this window or NULL
722 wxLayoutConstraints
*m_constraints
;
724 // constraints this window is involved in
725 wxWindowList
*m_constraintsInvolvedIn
;
727 // top level and the parent sizers
728 // TODO what's this and how does it work?)
729 wxSizer
*m_windowSizer
;
730 wxWindowBase
*m_sizerParent
;
732 // Layout() window automatically when its size changes?
734 #endif // wxUSE_CONSTRAINTS
739 bool m_isBeingDeleted
:1;
743 wxString m_windowName
;
746 // common part of all ctors: it is not virtual because it is called from
750 // get the default size for the new window if no explicit size given
751 // FIXME why 20 and not 30, 10 or ...?
752 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
753 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
755 // sets the size to be size but take width and/or height from
756 // DoGetBestSize() if width/height of size is -1
758 // NB: when calling this function from the ctor, the DoGetBestSize() of
759 // the class with the same name as the ctor, not the real (most
760 // derived) one - but this is what we usually want
761 void SetSizeOrDefault(const wxSize
& size
= wxDefaultSize
)
763 if ( size
.x
== -1 || size
.y
== -1 )
765 wxSize sizeDef
= GetBestSize();
766 SetSize( size
.x
== -1 ? sizeDef
.x
: size
.x
,
767 size
.y
== -1 ? sizeDef
.y
: size
.y
);
775 // more pure virtual functions
776 // ---------------------------
778 // NB: we must have DoSomething() function when Something() is an overloaded
779 // method: indeed, we can't just have "virtual Something()" in case when
780 // the function is overloaded because then we'd have to make virtual all
781 // the variants (otherwise only the virtual function may be called on a
782 // pointer to derived class according to C++ rules) which is, in
783 // general, absolutely not needed. So instead we implement all
784 // overloaded Something()s in terms of DoSomething() which will be the
785 // only one to be virtual.
787 // coordinates translation
788 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
789 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
791 // retrieve the position/size of the window
792 virtual void DoGetPosition( int *x
, int *y
) const = 0;
793 virtual void DoGetSize( int *width
, int *height
) const = 0;
794 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
796 // get the size which best suits the window: for a control, it would be
797 // the minimal size which doesn't truncate the control, for a panel - the
798 // same size as it would have after a call to Fit()
799 virtual wxSize
DoGetBestSize() const;
801 // this is the virtual function to be overriden in any derived class which
802 // wants to change how SetSize() or Move() works - it is called by all
803 // versions of these functions in the base class
804 virtual void DoSetSize(int x
, int y
,
805 int width
, int height
,
806 int sizeFlags
= wxSIZE_AUTO
) = 0;
808 // same as DoSetSize() for the client size
809 virtual void DoSetClientSize(int width
, int height
) = 0;
811 // move the window to the specified location and resize it: this is called
812 // from both DoSetSize() and DoSetClientSize() and would usually just
813 // reposition this window except for composite controls which will want to
814 // arrange themselves inside the given rectangle
815 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
818 virtual void DoSetToolTip( wxToolTip
*tip
);
819 #endif // wxUSE_TOOLTIPS
821 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
823 // client data accessors
824 virtual void DoSetClientObject( wxClientData
*data
);
825 virtual wxClientData
*DoGetClientObject() const;
827 virtual void DoSetClientData( void *data
);
828 virtual void *DoGetClientData() const;
830 // what kind of data do we have?
831 enum wxClientDataType
833 ClientData_None
, // we don't know yet because we don't have it at all
834 ClientData_Object
, // our client data is typed and we own it
835 ClientData_Void
// client data is untyped and we don't own it
839 // contains the last id generated by NewControlId
840 static int ms_lastControlId
;
842 DECLARE_NO_COPY_CLASS(wxWindowBase
);
843 DECLARE_EVENT_TABLE()
846 // ----------------------------------------------------------------------------
847 // now include the declaration of wxWindow class
848 // ----------------------------------------------------------------------------
850 #if defined(__WXMSW__)
851 #include "wx/msw/window.h"
852 #elif defined(__WXMOTIF__)
853 #include "wx/motif/window.h"
854 #elif defined(__WXGTK__)
855 #include "wx/gtk/window.h"
856 #elif defined(__WXQT__)
857 #include "wx/qt/window.h"
858 #elif defined(__WXMAC__)
859 #include "wx/mac/window.h"
860 #elif defined(__WXPM__)
861 #include "wx/os2/window.h"
864 // ----------------------------------------------------------------------------
865 // inline functions which couldn't be declared in the class body because of
866 // forward dependencies
867 // ----------------------------------------------------------------------------
869 inline wxWindow
*wxWindowBase::GetGrandParent() const
871 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
874 // ----------------------------------------------------------------------------
876 // ----------------------------------------------------------------------------
878 WXDLLEXPORT
extern wxWindow
* wxGetActiveWindow();
880 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
881 inline WXDLLEXPORT
int NewControlId() { return wxWindowBase::NewControlId(); }
884 // _WX_WINDOW_H_BASE_