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_
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 void SetVirtualSizeHints( int minW
, int minH
,
297 int maxW
= -1, int maxH
= -1 );
299 virtual int GetMinWidth() const { return m_minWidth
; }
300 virtual int GetMinHeight() const { return m_minHeight
; }
301 int GetMaxWidth() const { return m_maxWidth
; }
302 int GetMaxHeight() const { return m_maxHeight
; }
304 // Override this method to control the values given to Sizers etc.
305 virtual wxSize
GetMaxSize() const { return wxSize( m_maxWidth
, m_maxHeight
); }
307 // Methods for accessing the virtual size of a window. For most
308 // windows this is just the client area of the window, but for
309 // some like scrolled windows it is more or less independent of
310 // the screen window size. You may override the DoXXXVirtual
311 // methods below for classes where that is is the case.
313 void SetVirtualSize( const wxSize
&size
) { DoSetVirtualSize( size
.x
, size
.y
); }
314 void SetVirtualSize( int x
, int y
) { DoSetVirtualSize( x
, y
); }
316 wxSize
GetVirtualSize() const { return DoGetVirtualSize(); }
317 void GetVirtualSize( int *x
, int *y
) const
319 wxSize
s( DoGetVirtualSize() );
327 // Override these methods for windows that have a virtual size
328 // independent of their client size. eg. the virtual area of a
329 // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
331 virtual void DoSetVirtualSize( int x
, int y
);
332 virtual wxSize
DoGetVirtualSize() const; // { return m_virtualSize; }
337 // returns TRUE if window was shown/hidden, FALSE if the nothing was
338 // done (window was already shown/hidden)
339 virtual bool Show( bool show
= TRUE
);
340 bool Hide() { return Show(FALSE
); }
342 // returns TRUE if window was enabled/disabled, FALSE if nothing done
343 virtual bool Enable( bool enable
= TRUE
);
344 bool Disable() { return Enable(FALSE
); }
346 bool IsShown() const { return m_isShown
; }
347 bool IsEnabled() const { return m_isEnabled
; }
349 // get/set window style (setting style won't update the window and so
350 // is only useful for internal usage)
351 virtual void SetWindowStyleFlag( long style
) { m_windowStyle
= style
; }
352 virtual long GetWindowStyleFlag() const { return m_windowStyle
; }
354 // just some (somewhat shorter) synonims
355 void SetWindowStyle( long style
) { SetWindowStyleFlag(style
); }
356 long GetWindowStyle() const { return GetWindowStyleFlag(); }
358 bool HasFlag(int flag
) const { return (m_windowStyle
& flag
) != 0; }
359 virtual bool IsRetained() const { return HasFlag(wxRETAINED
); }
361 // extra style: the less often used style bits which can't be set with
362 // SetWindowStyleFlag()
363 virtual void SetExtraStyle(long exStyle
) { m_exStyle
= exStyle
; }
364 long GetExtraStyle() const { return m_exStyle
; }
366 // make the window modal (all other windows unresponsive)
367 virtual void MakeModal(bool modal
= TRUE
);
369 virtual void SetThemeEnabled(bool enableTheme
) { m_themeEnabled
= enableTheme
; }
370 virtual bool GetThemeEnabled() const { return m_themeEnabled
; }
372 // focus and keyboard handling
373 // ---------------------------
375 // set focus to this window
376 virtual void SetFocus() = 0;
378 // set focus to this window as the result of a keyboard action
379 virtual void SetFocusFromKbd() { SetFocus(); }
381 // return the window which currently has the focus or NULL
382 static wxWindow
*FindFocus() /* = 0: implement in derived classes */;
384 // can this window have focus?
385 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
387 // can this window be given focus by keyboard navigation? if not, the
388 // only way to give it focus (provided it accepts it at all) is to
390 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
392 // NB: these methods really don't belong here but with the current
393 // class hierarchy there is no other place for them :-(
395 // get the default child of this parent, i.e. the one which is
396 // activated by pressing <Enter>
397 virtual wxWindow
*GetDefaultItem() const { return NULL
; }
399 // set this child as default, return the old default
400 virtual wxWindow
*SetDefaultItem(wxWindow
* WXUNUSED(child
))
403 // set this child as temporary default
404 virtual void SetTmpDefaultItem(wxWindow
* WXUNUSED(win
)) { }
406 // parent/children relations
407 // -------------------------
409 // get the list of children
410 const wxWindowList
& GetChildren() const { return m_children
; }
411 wxWindowList
& GetChildren() { return m_children
; }
413 // get the parent or the parent of the parent
414 wxWindow
*GetParent() const { return m_parent
; }
415 inline wxWindow
*GetGrandParent() const;
417 // is this window a top level one?
418 virtual bool IsTopLevel() const;
420 // it doesn't really change parent, use ReParent() instead
421 void SetParent( wxWindowBase
*parent
) { m_parent
= (wxWindow
*)parent
; }
422 // change the real parent of this window, return TRUE if the parent
423 // was changed, FALSE otherwise (error or newParent == oldParent)
424 virtual bool Reparent( wxWindowBase
*newParent
);
426 // implementation mostly
427 virtual void AddChild( wxWindowBase
*child
);
428 virtual void RemoveChild( wxWindowBase
*child
);
430 // looking for windows
431 // -------------------
433 // find window among the descendants of this one either by id or by
434 // name (return NULL if not found)
435 wxWindow
*FindWindow( long id
);
436 wxWindow
*FindWindow( const wxString
& name
);
438 // Find a window among any window (all return NULL if not found)
439 static wxWindow
*FindWindowById( long id
, const wxWindow
*parent
= NULL
);
440 static wxWindow
*FindWindowByName( const wxString
& name
,
441 const wxWindow
*parent
= NULL
);
442 static wxWindow
*FindWindowByLabel( const wxString
& label
,
443 const wxWindow
*parent
= NULL
);
445 // event handler stuff
446 // -------------------
448 // get the current event handler
449 wxEvtHandler
*GetEventHandler() const { return m_eventHandler
; }
451 // replace the event handler (allows to completely subclass the
453 void SetEventHandler( wxEvtHandler
*handler
) { m_eventHandler
= handler
; }
455 // push/pop event handler: allows to chain a custom event handler to
456 // alreasy existing ones
457 void PushEventHandler( wxEvtHandler
*handler
);
458 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
460 // find the given handler in the event handler chain and remove (but
461 // not delete) it from the event handler chain, return TRUE if it was
462 // found and FALSE otherwise (this also results in an assert failure so
463 // this function should only be called when the handler is supposed to
465 bool RemoveEventHandler(wxEvtHandler
*handler
);
471 // a window may have an associated validator which is used to control
473 virtual void SetValidator( const wxValidator
&validator
);
474 virtual wxValidator
*GetValidator() { return m_windowValidator
; }
475 #endif // wxUSE_VALIDATORS
478 // dialog oriented functions
479 // -------------------------
481 // validate the correctness of input, return TRUE if ok
482 virtual bool Validate();
484 // transfer data between internal and GUI representations
485 virtual bool TransferDataToWindow();
486 virtual bool TransferDataFromWindow();
488 virtual void InitDialog();
493 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
)
494 { m_acceleratorTable
= accel
; }
495 wxAcceleratorTable
*GetAcceleratorTable()
496 { return &m_acceleratorTable
; }
497 #endif // wxUSE_ACCEL
499 // dialog units translations
500 // -------------------------
502 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
503 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
504 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
506 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
508 return wxSize(pt
.x
, pt
.y
);
511 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
513 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
515 return wxSize(pt
.x
, pt
.y
);
521 // move the mouse to the specified position
522 virtual void WarpPointer(int x
, int y
) = 0;
524 // start or end mouse capture, these functions maintain the stack of
525 // windows having captured the mouse and after calling ReleaseMouse()
526 // the mouse is not released but returns to the window which had had
527 // captured it previously (if any)
531 // get the window which currently captures the mouse or NULL
532 static wxWindow
*GetCapture();
534 // does this window have the capture?
535 virtual bool HasCapture() const
536 { return (wxWindow
*)this == GetCapture(); }
538 // painting the window
539 // -------------------
541 // mark the specified rectangle (or the whole window) as "dirty" so it
543 virtual void Refresh( bool eraseBackground
= TRUE
,
544 const wxRect
*rect
= (const wxRect
*) NULL
) = 0;
546 // a less awkward wrapper for Refresh
547 void RefreshRect(const wxRect
& rect
) { Refresh(TRUE
, &rect
); }
549 // repaint all invalid areas of the window immediately
550 virtual void Update() { }
552 // clear the window entirely
553 virtual void Clear() = 0;
555 // freeze the window: don't redraw it until it is thawed
556 virtual void Freeze() { }
558 // thaw the window: redraw it after it had been frozen
559 virtual void Thaw() { }
561 // adjust DC for drawing on this window
562 virtual void PrepareDC( wxDC
& WXUNUSED(dc
) ) { }
564 // the update region of the window contains the areas which must be
565 // repainted by the program
566 const wxRegion
& GetUpdateRegion() const { return m_updateRegion
; }
567 wxRegion
& GetUpdateRegion() { return m_updateRegion
; }
569 // get the update rectangleregion bounding box in client coords
570 wxRect
GetUpdateClientRect() const;
572 // these functions verify whether the given point/rectangle belongs to
573 // (or at least intersects with) the update region
574 bool IsExposed( int x
, int y
) const;
575 bool IsExposed( int x
, int y
, int w
, int h
) const;
577 bool IsExposed( const wxPoint
& pt
) const
578 { return IsExposed(pt
.x
, pt
.y
); }
579 bool IsExposed( const wxRect
& rect
) const
580 { return IsExposed(rect
.x
, rect
.y
, rect
.width
, rect
.height
); }
582 // colours, fonts and cursors
583 // --------------------------
585 // set/retrieve the window colours (system defaults are used by
586 // default): Set functions return TRUE if colour was changed
587 virtual bool SetBackgroundColour( const wxColour
&colour
);
588 virtual bool SetForegroundColour( const wxColour
&colour
);
590 wxColour
GetBackgroundColour() const { return m_backgroundColour
; }
591 wxColour
GetForegroundColour() const { return m_foregroundColour
; }
593 // set/retrieve the cursor for this window (SetCursor() returns TRUE
594 // if the cursor was really changed)
595 virtual bool SetCursor( const wxCursor
&cursor
);
596 const wxCursor
& GetCursor() const { return m_cursor
; }
597 wxCursor
& GetCursor() { return m_cursor
; }
599 // set/retrieve the font for the window (SetFont() returns TRUE if the
600 // font really changed)
601 virtual bool SetFont( const wxFont
&font
) = 0;
602 const wxFont
& GetFont() const { return m_font
; }
603 wxFont
& GetFont() { return m_font
; }
606 // associate a caret with the window
607 void SetCaret(wxCaret
*caret
);
608 // get the current caret (may be NULL)
609 wxCaret
*GetCaret() const { return m_caret
; }
610 #endif // wxUSE_CARET
612 // get the (average) character size for the current font
613 virtual int GetCharHeight() const = 0;
614 virtual int GetCharWidth() const = 0;
616 // get the width/height/... of the text using current or specified
618 virtual void GetTextExtent(const wxString
& string
,
620 int *descent
= (int *) NULL
,
621 int *externalLeading
= (int *) NULL
,
622 const wxFont
*theFont
= (const wxFont
*) NULL
)
625 // client <-> screen coords
626 // ------------------------
628 // translate to/from screen/client coordinates (pointers may be NULL)
629 void ClientToScreen( int *x
, int *y
) const
630 { DoClientToScreen(x
, y
); }
631 void ScreenToClient( int *x
, int *y
) const
632 { DoScreenToClient(x
, y
); }
634 // wxPoint interface to do the same thing
635 wxPoint
ClientToScreen(const wxPoint
& pt
) const
637 int x
= pt
.x
, y
= pt
.y
;
638 DoClientToScreen(&x
, &y
);
640 return wxPoint(x
, y
);
643 wxPoint
ScreenToClient(const wxPoint
& pt
) const
645 int x
= pt
.x
, y
= pt
.y
;
646 DoScreenToClient(&x
, &y
);
648 return wxPoint(x
, y
);
651 // test where the given (in client coords) point lies
652 wxHitTest
HitTest(wxCoord x
, wxCoord y
) const
653 { return DoHitTest(x
, y
); }
655 wxHitTest
HitTest(const wxPoint
& pt
) const
656 { return DoHitTest(pt
.x
, pt
.y
); }
661 // get the window border style: uses the current style and falls back to
662 // the default style for this class otherwise (see GetDefaultBorder())
663 wxBorder
GetBorder() const;
665 void UpdateWindowUI();
668 bool PopupMenu( wxMenu
*menu
, const wxPoint
& pos
)
669 { return DoPopupMenu(menu
, pos
.x
, pos
.y
); }
670 bool PopupMenu( wxMenu
*menu
, int x
, int y
)
671 { return DoPopupMenu(menu
, x
, y
); }
672 #endif // wxUSE_MENUS
677 // does the window have the scrollbar for this orientation?
678 bool HasScrollbar(int orient
) const
680 return (m_windowStyle
&
681 (orient
== wxHORIZONTAL
? wxHSCROLL
: wxVSCROLL
)) != 0;
684 // configure the window scrollbars
685 virtual void SetScrollbar( int orient
,
689 bool refresh
= TRUE
) = 0;
690 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
) = 0;
691 virtual int GetScrollPos( int orient
) const = 0;
692 virtual int GetScrollThumb( int orient
) const = 0;
693 virtual int GetScrollRange( int orient
) const = 0;
695 // scroll window to the specified position
696 virtual void ScrollWindow( int dx
, int dy
,
697 const wxRect
* rect
= (wxRect
*) NULL
) = 0;
699 // scrolls window by line/page: note that not all controls support this
701 // return TRUE if the position changed, FALSE otherwise
702 virtual bool ScrollLines(int WXUNUSED(lines
)) { return FALSE
; }
703 virtual bool ScrollPages(int WXUNUSED(pages
)) { return FALSE
; }
705 // convenient wrappers for ScrollLines/Pages
706 bool LineUp() { return ScrollLines(-1); }
707 bool LineDown() { return ScrollLines(1); }
708 bool PageUp() { return ScrollPages(-1); }
709 bool PageDown() { return ScrollPages(1); }
711 // context-sensitive help
712 // ----------------------
714 // these are the convenience functions wrapping wxHelpProvider methods
717 // associate this help text with this window
718 void SetHelpText(const wxString
& text
);
719 // associate this help text with all windows with the same id as this
721 void SetHelpTextForId(const wxString
& text
);
722 // get the help string associated with this window (may be empty)
723 wxString
GetHelpText() const;
730 // the easiest way to set a tooltip for a window is to use this method
731 void SetToolTip( const wxString
&tip
);
732 // attach a tooltip to the window
733 void SetToolTip( wxToolTip
*tip
) { DoSetToolTip(tip
); }
734 // get the associated tooltip or NULL if none
735 wxToolTip
* GetToolTip() const { return m_tooltip
; }
736 #endif // wxUSE_TOOLTIPS
740 #if wxUSE_DRAG_AND_DROP
741 // set/retrieve the drop target associated with this window (may be
742 // NULL; it's owned by the window and will be deleted by it)
743 virtual void SetDropTarget( wxDropTarget
*dropTarget
) = 0;
744 virtual wxDropTarget
*GetDropTarget() const { return m_dropTarget
; }
745 #endif // wxUSE_DRAG_AND_DROP
747 // constraints and sizers
748 // ----------------------
749 #if wxUSE_CONSTRAINTS
750 // set the constraints for this window or retrieve them (may be NULL)
751 void SetConstraints( wxLayoutConstraints
*constraints
);
752 wxLayoutConstraints
*GetConstraints() const { return m_constraints
; }
754 // implementation only
755 void UnsetConstraints(wxLayoutConstraints
*c
);
756 wxWindowList
*GetConstraintsInvolvedIn() const
757 { return m_constraintsInvolvedIn
; }
758 void AddConstraintReference(wxWindowBase
*otherWin
);
759 void RemoveConstraintReference(wxWindowBase
*otherWin
);
760 void DeleteRelatedConstraints();
761 void ResetConstraints();
763 // these methods may be overriden for special layout algorithms
764 virtual void SetConstraintSizes(bool recurse
= TRUE
);
765 virtual bool LayoutPhase1(int *noChanges
);
766 virtual bool LayoutPhase2(int *noChanges
);
767 virtual bool DoPhase(int phase
);
769 // these methods are virtual but normally won't be overridden
770 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
771 virtual void MoveConstraint(int x
, int y
);
772 virtual void GetSizeConstraint(int *w
, int *h
) const ;
773 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
774 virtual void GetPositionConstraint(int *x
, int *y
) const ;
776 #endif // wxUSE_CONSTRAINTS
778 // when using constraints or sizers, it makes sense to update
779 // children positions automatically whenever the window is resized
780 // - this is done if autoLayout is on
781 void SetAutoLayout( bool autoLayout
) { m_autoLayout
= autoLayout
; }
782 bool GetAutoLayout() const { return m_autoLayout
; }
784 // lay out the window and its children
785 virtual bool Layout();
788 void SetSizer(wxSizer
*sizer
, bool deleteOld
= TRUE
);
789 void SetSizerAndFit( wxSizer
*sizer
, bool deleteOld
= TRUE
);
791 wxSizer
*GetSizer() const { return m_windowSizer
; }
793 // Track if this window is a member of a sizer
794 void SetContainingSizer(wxSizer
* sizer
) { m_containingSizer
= sizer
; }
795 wxSizer
*GetContainingSizer() const { return m_containingSizer
; }
797 // backward compatibility
798 // ----------------------
799 #if WXWIN_COMPATIBILITY
800 bool Enabled() const { return IsEnabled(); }
802 void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
803 void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
804 wxFont
& GetLabelFont() { return GetFont(); };
805 wxFont
& GetButtonFont() { return GetFont(); };
806 #endif // WXWIN_COMPATIBILITY
812 void OnSysColourChanged( wxSysColourChangedEvent
& event
);
813 void OnInitDialog( wxInitDialogEvent
&event
);
814 void OnMiddleClick( wxMouseEvent
& event
);
816 void OnHelp(wxHelpEvent
& event
);
819 // get the haqndle of the window for the underlying window system: this
820 // is only used for wxWin itself or for user code which wants to call
821 // platform-specific APIs
822 virtual WXWidget
GetHandle() const = 0;
825 // Store the palette used by DCs in wxWindow so that the dcs can share
826 // a palette. And we can respond to palette messages.
827 wxPalette
GetPalette() const { return m_palette
; }
829 // When palette is changed tell the DC to set the system palette to the
831 void SetPalette(const wxPalette
& pal
);
833 // return true if we have a specific palette
834 bool HasCustomPalette() const { return m_hasCustomPalette
; }
836 // return the first parent window with a custom palette or NULL
837 wxWindow
*GetAncestorWithCustomPalette() const;
838 #endif // wxUSE_PALETTE
841 #if wxUSE_CONSTRAINTS
842 // satisfy the constraints for the windows but don't set the window sizes
843 void SatisfyConstraints();
844 #endif // wxUSE_CONSTRAINTS
846 // the window id - a number which uniquely identifies a window among
847 // its siblings unless it is -1
848 wxWindowID m_windowId
;
850 // the parent window of this window (or NULL) and the list of the children
853 wxWindowList m_children
;
855 // the minimal allowed size for the window (no minimal size if variable(s)
862 // event handler for this window: usually is just 'this' but may be
863 // changed with SetEventHandler()
864 wxEvtHandler
*m_eventHandler
;
867 // associated validator or NULL if none
868 wxValidator
*m_windowValidator
;
869 #endif // wxUSE_VALIDATORS
871 #if wxUSE_DRAG_AND_DROP
872 wxDropTarget
*m_dropTarget
;
873 #endif // wxUSE_DRAG_AND_DROP
875 // visual window attributes
878 wxColour m_backgroundColour
, m_foregroundColour
;
882 #endif // wxUSE_CARET
884 // the region which should be repainted in response to paint event
885 wxRegion m_updateRegion
;
888 // the accelerator table for the window which translates key strokes into
890 wxAcceleratorTable m_acceleratorTable
;
891 #endif // wxUSE_ACCEL
893 // the tooltip for this window (may be NULL)
895 wxToolTip
*m_tooltip
;
896 #endif // wxUSE_TOOLTIPS
898 // constraints and sizers
899 #if wxUSE_CONSTRAINTS
900 // the constraints for this window or NULL
901 wxLayoutConstraints
*m_constraints
;
903 // constraints this window is involved in
904 wxWindowList
*m_constraintsInvolvedIn
;
905 #endif // wxUSE_CONSTRAINTS
907 // this window's sizer
908 wxSizer
*m_windowSizer
;
910 // The sizer this window is a member of, if any
911 wxSizer
*m_containingSizer
;
913 // Layout() window automatically when its size changes?
919 bool m_isBeingDeleted
:1;
921 // was the window colours/font explicitly changed by user?
929 wxString m_windowName
;
934 bool m_hasCustomPalette
;
935 #endif // wxUSE_PALETTE
937 // Virtual size (scrolling)
938 wxSize m_virtualSize
;
940 int m_minVirtualWidth
; // VirtualSizeHints
941 int m_minVirtualHeight
;
942 int m_maxVirtualWidth
;
943 int m_maxVirtualHeight
;
945 // common part of all ctors: it is not virtual because it is called from
949 // override this to change the default (i.e. used when no style is
950 // specified) border for the window class
951 virtual wxBorder
GetDefaultBorder() const;
953 // get the default size for the new window if no explicit size given
954 // FIXME why 20 and not 30, 10 or ...?
955 static int WidthDefault(int w
) { return w
== -1 ? 20 : w
; }
956 static int HeightDefault(int h
) { return h
== -1 ? 20 : h
; }
958 // set the best size for the control if the default size was given:
959 // replaces the fields of size == -1 with the best values for them and
960 // calls SetSize() if needed
961 void SetBestSize(const wxSize
& size
)
963 if ( size
.x
== -1 || size
.y
== -1 )
965 wxSize sizeBest
= DoGetBestSize();
975 // more pure virtual functions
976 // ---------------------------
978 // NB: we must have DoSomething() function when Something() is an overloaded
979 // method: indeed, we can't just have "virtual Something()" in case when
980 // the function is overloaded because then we'd have to make virtual all
981 // the variants (otherwise only the virtual function may be called on a
982 // pointer to derived class according to C++ rules) which is, in
983 // general, absolutely not needed. So instead we implement all
984 // overloaded Something()s in terms of DoSomething() which will be the
985 // only one to be virtual.
987 // coordinates translation
988 virtual void DoClientToScreen( int *x
, int *y
) const = 0;
989 virtual void DoScreenToClient( int *x
, int *y
) const = 0;
991 virtual wxHitTest
DoHitTest(wxCoord x
, wxCoord y
) const;
993 // capture/release the mouse, used by Capture/ReleaseMouse()
994 virtual void DoCaptureMouse() = 0;
995 virtual void DoReleaseMouse() = 0;
997 // retrieve the position/size of the window
998 virtual void DoGetPosition( int *x
, int *y
) const = 0;
999 virtual void DoGetSize( int *width
, int *height
) const = 0;
1000 virtual void DoGetClientSize( int *width
, int *height
) const = 0;
1002 // get the size which best suits the window: for a control, it would be
1003 // the minimal size which doesn't truncate the control, for a panel - the
1004 // same size as it would have after a call to Fit()
1005 virtual wxSize
DoGetBestSize() const;
1007 // this is the virtual function to be overriden in any derived class which
1008 // wants to change how SetSize() or Move() works - it is called by all
1009 // versions of these functions in the base class
1010 virtual void DoSetSize(int x
, int y
,
1011 int width
, int height
,
1012 int sizeFlags
= wxSIZE_AUTO
) = 0;
1014 // same as DoSetSize() for the client size
1015 virtual void DoSetClientSize(int width
, int height
) = 0;
1017 // move the window to the specified location and resize it: this is called
1018 // from both DoSetSize() and DoSetClientSize() and would usually just
1019 // reposition this window except for composite controls which will want to
1020 // arrange themselves inside the given rectangle
1021 virtual void DoMoveWindow(int x
, int y
, int width
, int height
) = 0;
1024 virtual void DoSetToolTip( wxToolTip
*tip
);
1025 #endif // wxUSE_TOOLTIPS
1028 virtual bool DoPopupMenu( wxMenu
*menu
, int x
, int y
) = 0;
1029 #endif // wxUSE_MENUS
1031 // Makes an adjustment to the window position (for example, a frame that has
1032 // a toolbar that it manages itself).
1033 virtual void AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const;
1038 // contains the last id generated by NewControlId
1039 static int ms_lastControlId
;
1041 // the stack of windows which have captured the mouse
1042 static struct WXDLLEXPORT wxWindowNext
*ms_winCaptureNext
;
1044 DECLARE_ABSTRACT_CLASS(wxWindowBase
)
1045 DECLARE_NO_COPY_CLASS(wxWindowBase
)
1046 DECLARE_EVENT_TABLE()
1049 // ----------------------------------------------------------------------------
1050 // now include the declaration of wxWindow class
1051 // ----------------------------------------------------------------------------
1053 // include the declaration of the platform-specific class
1054 #if defined(__WXMSW__)
1055 #ifdef __WXUNIVERSAL__
1056 #define wxWindowNative wxWindowMSW
1058 #define wxWindowMSW wxWindow
1059 #define sm_classwxWindowMSW sm_classwxWindow
1060 #endif // wxUniv/!wxUniv
1061 #include "wx/msw/window.h"
1062 #elif defined(__WXMOTIF__)
1063 #include "wx/motif/window.h"
1064 #elif defined(__WXGTK__)
1065 #ifdef __WXUNIVERSAL__
1066 #define wxWindowNative wxWindowGTK
1068 #define wxWindowGTK wxWindow
1069 #define sm_classwxWindowGTK sm_classwxWindow
1071 #include "wx/gtk/window.h"
1072 #elif defined(__WXX11__)
1073 #ifdef __WXUNIVERSAL__
1074 #define wxWindowNative wxWindowX11
1076 #define wxWindowX11 wxWindow
1077 #define sm_classwxWindowX11 sm_classwxWindow
1079 #include "wx/x11/window.h"
1080 #elif defined(__WXMGL__)
1081 #ifdef __WXUNIVERSAL__
1082 #define wxWindowNative wxWindowMGL
1084 #define wxWindowMGL wxWindow
1085 #define sm_classwxWindowMGL sm_classwxWindow
1087 #include "wx/mgl/window.h"
1088 #elif defined(__WXMAC__)
1089 #ifdef __WXUNIVERSAL__
1090 #define wxWindowNative wxWindowMac
1092 #define wxWindowMac wxWindow
1093 #define sm_classwxWindowMac sm_classwxWindow
1095 #include "wx/mac/window.h"
1096 #elif defined(__WXPM__)
1097 #ifdef __WXUNIVERSAL__
1098 #define wxWindowNative wxWindowOS2
1100 #define wxWindowOS2 wxWindow
1101 #define sm_classwxWindowOS2 sm_classwxWindow
1102 #endif // wxUniv/!wxUniv
1103 #include "wx/os2/window.h"
1106 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1107 // for the native ports we already have defined it above
1108 #if defined(__WXUNIVERSAL__)
1109 #ifndef wxWindowNative
1110 #error "wxWindowNative must be defined above!"
1113 #include "wx/univ/window.h"
1116 // ----------------------------------------------------------------------------
1117 // inline functions which couldn't be declared in the class body because of
1118 // forward dependencies
1119 // ----------------------------------------------------------------------------
1121 inline wxWindow
*wxWindowBase::GetGrandParent() const
1123 return m_parent
? m_parent
->GetParent() : (wxWindow
*)NULL
;
1126 // ----------------------------------------------------------------------------
1128 // ----------------------------------------------------------------------------
1130 // Find the wxWindow at the current mouse position, also returning the mouse
1132 WXDLLEXPORT
extern wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
);
1134 // Get the current mouse position.
1135 WXDLLEXPORT
extern wxPoint
wxGetMousePosition();
1137 // get the currently active window of this application or NULL
1138 WXDLLEXPORT
extern wxWindow
*wxGetActiveWindow();
1140 // get the (first) top level parent window
1141 WXDLLEXPORT wxWindow
* wxGetTopLevelParent(wxWindow
*win
);
1143 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1144 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1147 // _WX_WINDOW_H_BASE_