]> git.saurik.com Git - wxWidgets.git/blob - include/wx/window.h
maintaint the mouse capture stack in all ports, not just wxUniv
[wxWidgets.git] / include / wx / window.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/window.h
3 // Purpose: wxWindowBase class - the interface of wxWindow
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_BASE_
13 #define _WX_WINDOW_H_BASE_
14
15 #ifdef __GNUG__
16 #pragma interface "windowbase.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // headers which we must include here
21 // ----------------------------------------------------------------------------
22
23 #include "wx/event.h" // the base class
24
25 #include "wx/list.h" // defines wxWindowList
26
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"
31 #include "wx/utils.h"
32
33 #include "wx/validate.h" // for wxDefaultValidator (always include it)
34
35 #if wxUSE_ACCEL
36 #include "wx/accel.h"
37 #endif // wxUSE_ACCEL
38
39 // when building wxUniv/Foo we don't want the code for native menu use to be
40 // compiled in - it should only be used when building real wxFoo
41 #ifdef __WXUNIVERSAL__
42 #define wxUSE_MENUS_NATIVE 0
43 #else // __WXMSW__
44 #define wxUSE_MENUS_NATIVE wxUSE_MENUS
45 #endif // __WXUNIVERSAL__/__WXMSW__
46
47 // ----------------------------------------------------------------------------
48 // forward declarations
49 // ----------------------------------------------------------------------------
50
51 class WXDLLEXPORT wxCaret;
52 class WXDLLEXPORT wxControl;
53 class WXDLLEXPORT wxCursor;
54 class WXDLLEXPORT wxDC;
55 class WXDLLEXPORT wxDropTarget;
56 class WXDLLEXPORT wxItemResource;
57 class WXDLLEXPORT wxLayoutConstraints;
58 class WXDLLEXPORT wxResourceTable;
59 class WXDLLEXPORT wxSizer;
60 class WXDLLEXPORT wxToolTip;
61 class WXDLLEXPORT wxWindowBase;
62 class WXDLLEXPORT wxWindow;
63
64 // ----------------------------------------------------------------------------
65 // (pseudo)template list classes
66 // ----------------------------------------------------------------------------
67
68 WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT);
69
70 // ----------------------------------------------------------------------------
71 // global variables
72 // ----------------------------------------------------------------------------
73
74 WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
75
76 // ----------------------------------------------------------------------------
77 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
78 // interface of this class.
79 //
80 // Event handler: windows have themselves as their event handlers by default,
81 // but their event handlers could be set to another object entirely. This
82 // separation can reduce the amount of derivation required, and allow
83 // alteration of a window's functionality (e.g. by a resource editor that
84 // temporarily switches event handlers).
85 // ----------------------------------------------------------------------------
86
87 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
88 {
89 public:
90 // creating the window
91 // -------------------
92
93 // default ctor
94 wxWindowBase() { InitBase(); }
95
96 // pseudo ctor (can't be virtual, called from ctor)
97 bool CreateBase(wxWindowBase *parent,
98 wxWindowID id,
99 const wxPoint& pos = wxDefaultPosition,
100 const wxSize& size = wxDefaultSize,
101 long style = 0,
102 const wxValidator& validator = wxDefaultValidator,
103 const wxString& name = wxPanelNameStr);
104
105 virtual ~wxWindowBase();
106
107 #if wxUSE_WX_RESOURCES
108 // these functions are implemented in resource.cpp and resourc2.cpp
109 virtual bool LoadFromResource(wxWindow *parent,
110 const wxString& resourceName,
111 const wxResourceTable *table = (const wxResourceTable *) NULL);
112 virtual wxControl *CreateItem(const wxItemResource* childResource,
113 const wxItemResource* parentResource,
114 const wxResourceTable *table = (const wxResourceTable *) NULL);
115 #endif // wxUSE_WX_RESOURCES
116
117 // deleting the window
118 // -------------------
119
120 // ask the window to close itself, return TRUE if the event handler
121 // honoured our request
122 bool Close( bool force = FALSE );
123
124 // the following functions delete the C++ objects (the window itself
125 // or its children) as well as the GUI windows and normally should
126 // never be used directly
127
128 // delete window unconditionally (dangerous!), returns TRUE if ok
129 virtual bool Destroy();
130 // delete all children of this window, returns TRUE if ok
131 bool DestroyChildren();
132
133 // is the window being deleted?
134 bool IsBeingDeleted() const { return m_isBeingDeleted; }
135
136 // window attributes
137 // -----------------
138
139 // NB: in future versions of wxWindows Set/GetTitle() will only work
140 // with the top level windows (such as dialogs and frames) and
141 // Set/GetLabel() only with the other ones (i.e. all controls).
142
143 // the title (or label, see below) of the window: the text which the
144 // window shows
145 virtual void SetTitle( const wxString& WXUNUSED(title) ) {}
146 virtual wxString GetTitle() const { return wxEmptyString; }
147
148 // label is just the same as the title (but for, e.g., buttons it
149 // makes more sense to speak about labels)
150 virtual void SetLabel(const wxString& label) { SetTitle(label); }
151 virtual wxString GetLabel() const { return GetTitle(); }
152
153 // the window name is used for ressource setting in X, it is not the
154 // same as the window title/label
155 virtual void SetName( const wxString &name ) { m_windowName = name; }
156 virtual wxString GetName() const { return m_windowName; }
157
158 // window id uniquely identifies the window among its siblings unless
159 // it is -1 which means "don't care"
160 void SetId( wxWindowID id ) { m_windowId = id; }
161 wxWindowID GetId() const { return m_windowId; }
162
163 // generate a control id for the controls which were not given one by
164 // user
165 static int NewControlId() { return --ms_lastControlId; }
166 // get the id of the control following the one with the given
167 // (autogenerated) id
168 static int NextControlId(int id) { return id - 1; }
169 // get the id of the control preceding the one with the given
170 // (autogenerated) id
171 static int PrevControlId(int id) { return id + 1; }
172
173 // moving/resizing
174 // ---------------
175
176 // set the window size and/or position
177 void SetSize( int x, int y, int width, int height,
178 int sizeFlags = wxSIZE_AUTO )
179 { DoSetSize(x, y, width, height, sizeFlags); }
180
181 void SetSize( int width, int height )
182 { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); }
183
184 void SetSize( const wxSize& size )
185 { SetSize( size.x, size.y); }
186
187 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
188 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
189
190 void Move(int x, int y, int flags = wxSIZE_USE_EXISTING)
191 { DoSetSize(x, y, -1, -1, flags); }
192
193 void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING)
194 { Move(pt.x, pt.y, flags); }
195
196 // Z-order
197 virtual void Raise() = 0;
198 virtual void Lower() = 0;
199
200 // client size is the size of area available for subwindows
201 void SetClientSize( int width, int height )
202 { DoSetClientSize(width, height); }
203
204 void SetClientSize( const wxSize& size )
205 { DoSetClientSize(size.x, size.y); }
206
207 void SetClientSize(const wxRect& rect)
208 { SetClientSize( rect.width, rect.height ); }
209
210 // get the window position and/or size (pointers may be NULL)
211 void GetPosition( int *x, int *y ) const { DoGetPosition(x, y); }
212 wxPoint GetPosition() const
213 {
214 int w, h;
215 DoGetPosition(&w, &h);
216
217 return wxPoint(w, h);
218 }
219
220 void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
221 wxSize GetSize() const
222 {
223 int w, h;
224 DoGetSize(& w, & h);
225 return wxSize(w, h);
226 }
227
228 wxRect GetRect() const
229 {
230 int x, y, w, h;
231 GetPosition(& x, & y);
232 GetSize(& w, & h);
233
234 return wxRect(x, y, w, h);
235 }
236
237 void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
238 wxSize GetClientSize() const
239 {
240 int w, h;
241 DoGetClientSize(& w, & h);
242
243 return wxSize(w, h);
244 }
245
246 // get the origin of the client area of the window relative to the
247 // window top left corner (the client area may be shifted because of
248 // the borders, scrollbars, other decorations...)
249 virtual wxPoint GetClientAreaOrigin() const;
250
251 // get the client rectangle in window (i.e. client) coordinates
252 wxRect GetClientRect() const
253 {
254 return wxRect(GetClientAreaOrigin(), GetClientSize());
255 }
256
257 // get the size best suited for the window (in fact, minimal
258 // acceptable size using which it will still look "nice")
259 wxSize GetBestSize() const { return DoGetBestSize(); }
260 void GetBestSize(int *w, int *h) const
261 {
262 wxSize s = DoGetBestSize();
263 if ( w )
264 *w = s.x;
265 if ( h )
266 *h = s.y;
267 }
268
269 // the generic centre function - centers the window on parent by
270 // default or on screen if it doesn't have parent or
271 // wxCENTER_ON_SCREEN flag is given
272 void Centre( int direction = wxBOTH );
273 void Center( int direction = wxBOTH ) { Centre(direction); }
274
275 // centre on screen (only works for top level windows)
276 void CentreOnScreen(int dir = wxBOTH) { Centre(dir | wxCENTER_ON_SCREEN); }
277 void CenterOnScreen(int dir = wxBOTH) { CentreOnScreen(dir); }
278
279 // centre with respect to the the parent window
280 void CentreOnParent(int dir = wxBOTH) { Centre(dir | wxCENTER_FRAME); }
281 void CenterOnParent(int dir = wxBOTH) { CentreOnParent(dir); }
282
283 // set window size to wrap around its children
284 virtual void Fit();
285
286 // set min/max size of the window
287 virtual void SetSizeHints( int minW, int minH,
288 int maxW = -1, int maxH = -1,
289 int incW = -1, int incH = -1 );
290
291 int GetMinWidth() const { return m_minWidth; }
292 int GetMinHeight() const { return m_minHeight; }
293 int GetMaxWidth() const { return m_maxWidth; }
294 int GetMaxHeight() const { return m_maxHeight; }
295
296 // window state
297 // ------------
298
299 // returns TRUE if window was shown/hidden, FALSE if the nothing was
300 // done (window was already shown/hidden)
301 virtual bool Show( bool show = TRUE );
302 bool Hide() { return Show(FALSE); }
303
304 // returns TRUE if window was enabled/disabled, FALSE if nothing done
305 virtual bool Enable( bool enable = TRUE );
306 bool Disable() { return Enable(FALSE); }
307
308 bool IsShown() const { return m_isShown; }
309 bool IsEnabled() const { return m_isEnabled; }
310
311 // get/set window style (setting style won't update the window and so
312 // is only useful for internal usage)
313 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
314 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
315
316 // just some (somewhat shorter) synonims
317 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
318 long GetWindowStyle() const { return GetWindowStyleFlag(); }
319
320 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
321 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
322
323 // extra style: the less often used style bits which can't be set with
324 // SetWindowStyleFlag()
325 void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
326 long GetExtraStyle() const { return m_exStyle; }
327
328 // make the window modal (all other windows unresponsive)
329 virtual void MakeModal(bool modal = TRUE);
330
331 virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
332 virtual bool GetThemeEnabled() const { return m_themeEnabled; }
333
334 // focus and keyboard handling
335 // ---------------------------
336
337 // set focus to this window
338 virtual void SetFocus() = 0;
339
340 // return the window which currently has the focus or NULL
341 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
342
343 // can this window have focus?
344 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
345
346 // can this window be given focus by keyboard navigation? if not, the
347 // only way to give it focus (provided it accepts it at all) is to
348 // click it
349 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
350
351 // NB: these methods really don't belong here but with the current
352 // class hierarchy there is no other place for them :-(
353
354 // get the default child of this parent, i.e. the one which is
355 // activated by pressing <Enter>
356 virtual wxWindow *GetDefaultItem() const { return NULL; }
357
358 // set this child as default, return the old default
359 virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child))
360 { return NULL; }
361
362 // parent/children relations
363 // -------------------------
364
365 // get the list of children
366 const wxWindowList& GetChildren() const { return m_children; }
367 wxWindowList& GetChildren() { return m_children; }
368
369 // get the parent or the parent of the parent
370 wxWindow *GetParent() const { return m_parent; }
371 inline wxWindow *GetGrandParent() const;
372
373 // is this window a top level one?
374 virtual bool IsTopLevel() const;
375
376 // it doesn't really change parent, use ReParent() instead
377 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
378 // change the real parent of this window, return TRUE if the parent
379 // was changed, FALSE otherwise (error or newParent == oldParent)
380 virtual bool Reparent( wxWindowBase *newParent );
381
382 // find window among the descendants of this one either by id or by
383 // name (return NULL if not found)
384 wxWindow *FindWindow( long id );
385 wxWindow *FindWindow( const wxString& name );
386
387 // implementation mostly
388 virtual void AddChild( wxWindowBase *child );
389 virtual void RemoveChild( wxWindowBase *child );
390
391 // event handler stuff
392 // -------------------
393
394 // get the current event handler
395 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
396
397 // replace the event handler (allows to completely subclass the
398 // window)
399 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
400
401 // push/pop event handler: allows to chain a custom event handler to
402 // alreasy existing ones
403 void PushEventHandler( wxEvtHandler *handler );
404 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
405
406 // validators
407 // ----------
408
409 #if wxUSE_VALIDATORS
410 // a window may have an associated validator which is used to control
411 // user input
412 virtual void SetValidator( const wxValidator &validator );
413 virtual wxValidator *GetValidator() { return m_windowValidator; }
414 #endif // wxUSE_VALIDATORS
415
416
417 // dialog oriented functions
418 // -------------------------
419
420 // validate the correctness of input, return TRUE if ok
421 virtual bool Validate();
422
423 // transfer data between internal and GUI representations
424 virtual bool TransferDataToWindow();
425 virtual bool TransferDataFromWindow();
426
427 virtual void InitDialog();
428
429 #if wxUSE_ACCEL
430 // accelerators
431 // ------------
432 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
433 { m_acceleratorTable = accel; }
434 wxAcceleratorTable *GetAcceleratorTable()
435 { return &m_acceleratorTable; }
436 #endif // wxUSE_ACCEL
437
438 // dialog units translations
439 // -------------------------
440
441 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
442 wxPoint ConvertDialogToPixels( const wxPoint& pt );
443 wxSize ConvertPixelsToDialog( const wxSize& sz )
444 {
445 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
446
447 return wxSize(pt.x, pt.y);
448 }
449
450 wxSize ConvertDialogToPixels( const wxSize& sz )
451 {
452 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
453
454 return wxSize(pt.x, pt.y);
455 }
456
457 // mouse functions
458 // ---------------
459
460 // move the mouse to the specified position
461 virtual void WarpPointer(int x, int y) = 0;
462
463 // start or end mouse capture, these functions maintain the stack of
464 // windows having captured the mouse and after calling ReleaseMouse()
465 // the mouse is not released but returns to the window which had had
466 // captured it previously (if any)
467 void CaptureMouse();
468 void ReleaseMouse();
469
470 // get the window which currently captures the mouse or NULL
471 static wxWindow *GetCapture();
472
473 // does this window have the capture?
474 virtual bool HasCapture() const
475 { return (wxWindow *)this == GetCapture(); }
476
477 // painting the window
478 // -------------------
479
480 // mark the specified rectangle (or the whole window) as "dirty" so it
481 // will be repainted
482 virtual void Refresh( bool eraseBackground = TRUE,
483 const wxRect *rect = (const wxRect *) NULL ) = 0;
484
485 // a less awkward wrapper for Refresh
486 void RefreshRect(const wxRect& rect) { Refresh(TRUE, &rect); }
487
488 // repaint all invalid areas of the window immediately
489 virtual void Update() { }
490
491 // clear the window entirely
492 virtual void Clear() = 0;
493
494 // freeze the window: don't redraw it until it is thawed
495 virtual void Freeze() { }
496
497 // thaw the window: redraw it after it had been frozen
498 virtual void Thaw() { }
499
500 // adjust DC for drawing on this window
501 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
502
503 // the update region of the window contains the areas which must be
504 // repainted by the program
505 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
506 wxRegion& GetUpdateRegion() { return m_updateRegion; }
507
508 // get the update rectangleregion bounding box in client coords
509 wxRect GetUpdateClientRect() const;
510
511 // these functions verify whether the given point/rectangle belongs to
512 // (or at least intersects with) the update region
513 bool IsExposed( int x, int y ) const;
514 bool IsExposed( int x, int y, int w, int h ) const;
515
516 bool IsExposed( const wxPoint& pt ) const
517 { return IsExposed(pt.x, pt.y); }
518 bool IsExposed( const wxRect& rect ) const
519 { return IsExposed(rect.x, rect.y, rect.width, rect.height); }
520
521 // colours, fonts and cursors
522 // --------------------------
523
524 // set/retrieve the window colours (system defaults are used by
525 // default): Set functions return TRUE if colour was changed
526 virtual bool SetBackgroundColour( const wxColour &colour );
527 virtual bool SetForegroundColour( const wxColour &colour );
528
529 wxColour GetBackgroundColour() const { return m_backgroundColour; }
530 wxColour GetForegroundColour() const { return m_foregroundColour; }
531
532 // set/retrieve the cursor for this window (SetCursor() returns TRUE
533 // if the cursor was really changed)
534 virtual bool SetCursor( const wxCursor &cursor );
535 const wxCursor& GetCursor() const { return m_cursor; }
536 wxCursor& GetCursor() { return m_cursor; }
537
538 // set/retrieve the font for the window (SetFont() returns TRUE if the
539 // font really changed)
540 virtual bool SetFont( const wxFont &font ) = 0;
541 const wxFont& GetFont() const { return m_font; }
542 wxFont& GetFont() { return m_font; }
543
544 #if wxUSE_CARET
545 // associate a caret with the window
546 void SetCaret(wxCaret *caret);
547 // get the current caret (may be NULL)
548 wxCaret *GetCaret() const { return m_caret; }
549 #endif // wxUSE_CARET
550
551 // get the (average) character size for the current font
552 virtual int GetCharHeight() const = 0;
553 virtual int GetCharWidth() const = 0;
554
555 // get the width/height/... of the text using current or specified
556 // font
557 virtual void GetTextExtent(const wxString& string,
558 int *x, int *y,
559 int *descent = (int *) NULL,
560 int *externalLeading = (int *) NULL,
561 const wxFont *theFont = (const wxFont *) NULL)
562 const = 0;
563
564 // client <-> screen coords
565 // ------------------------
566
567 // translate to/from screen/client coordinates (pointers may be NULL)
568 void ClientToScreen( int *x, int *y ) const
569 { DoClientToScreen(x, y); }
570 void ScreenToClient( int *x, int *y ) const
571 { DoScreenToClient(x, y); }
572
573 // wxPoint interface to do the same thing
574 wxPoint ClientToScreen(const wxPoint& pt) const
575 {
576 int x = pt.x, y = pt.y;
577 DoClientToScreen(&x, &y);
578
579 return wxPoint(x, y);
580 }
581
582 wxPoint ScreenToClient(const wxPoint& pt) const
583 {
584 int x = pt.x, y = pt.y;
585 DoScreenToClient(&x, &y);
586
587 return wxPoint(x, y);
588 }
589
590 // test where the given (in client coords) point lies
591 wxHitTest HitTest(wxCoord x, wxCoord y) const
592 { return DoHitTest(x, y); }
593
594 wxHitTest HitTest(const wxPoint& pt) const
595 { return DoHitTest(pt.x, pt.y); }
596
597 // misc
598 // ----
599
600 // get the window border style: uses the current style and falls back to
601 // the default style for this class otherwise (see GetDefaultBorder())
602 wxBorder GetBorder() const;
603
604 void UpdateWindowUI();
605
606 #if wxUSE_MENUS
607 bool PopupMenu( wxMenu *menu, const wxPoint& pos )
608 { return DoPopupMenu(menu, pos.x, pos.y); }
609 bool PopupMenu( wxMenu *menu, int x, int y )
610 { return DoPopupMenu(menu, x, y); }
611 #endif // wxUSE_MENUS
612
613 // scrollbars
614 // ----------
615
616 // does the window have the scrollbar for this orientation?
617 bool HasScrollbar(int orient) const
618 {
619 return (m_windowStyle &
620 (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0;
621 }
622
623 // configure the window scrollbars
624 virtual void SetScrollbar( int orient,
625 int pos,
626 int thumbvisible,
627 int range,
628 bool refresh = TRUE ) = 0;
629 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0;
630 virtual int GetScrollPos( int orient ) const = 0;
631 virtual int GetScrollThumb( int orient ) const = 0;
632 virtual int GetScrollRange( int orient ) const = 0;
633
634 // scroll window to the specified position
635 virtual void ScrollWindow( int dx, int dy,
636 const wxRect* rect = (wxRect *) NULL ) = 0;
637
638 // scrolls window by line/page: note that not all controls support this
639 //
640 // return TRUE if the position changed, FALSE otherwise
641 virtual bool ScrollLines(int WXUNUSED(lines)) { return FALSE; }
642 virtual bool ScrollPages(int WXUNUSED(pages)) { return FALSE; }
643
644 // convenient wrappers for ScrollLines/Pages
645 bool LineUp() { return ScrollLines(-1); }
646 bool LineDown() { return ScrollLines(1); }
647 bool PageUp() { return ScrollPages(-1); }
648 bool PageDown() { return ScrollPages(1); }
649
650 // context-sensitive help
651 // ----------------------
652
653 // these are the convenience functions wrapping wxHelpProvider methods
654
655 #if wxUSE_HELP
656 // associate this help text with this window
657 void SetHelpText(const wxString& text);
658 // associate this help text with all windows with the same id as this
659 // one
660 void SetHelpTextForId(const wxString& text);
661 // get the help string associated with this window (may be empty)
662 wxString GetHelpText() const;
663 #endif // wxUSE_HELP
664
665 // tooltips
666 // --------
667
668 #if wxUSE_TOOLTIPS
669 // the easiest way to set a tooltip for a window is to use this method
670 void SetToolTip( const wxString &tip );
671 // attach a tooltip to the window
672 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
673 // get the associated tooltip or NULL if none
674 wxToolTip* GetToolTip() const { return m_tooltip; }
675 #endif // wxUSE_TOOLTIPS
676
677 // drag and drop
678 // -------------
679 #if wxUSE_DRAG_AND_DROP
680 // set/retrieve the drop target associated with this window (may be
681 // NULL; it's owned by the window and will be deleted by it)
682 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
683 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
684 #endif // wxUSE_DRAG_AND_DROP
685
686 // constraints and sizers
687 // ----------------------
688 #if wxUSE_CONSTRAINTS
689 // set the constraints for this window or retrieve them (may be NULL)
690 void SetConstraints( wxLayoutConstraints *constraints );
691 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
692
693 // when using constraints, it makes sense to update children positions
694 // automatically whenever the window is resized - this is done if
695 // autoLayout is on
696 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
697 bool GetAutoLayout() const { return m_autoLayout; }
698
699 // do layout the window and its children
700 virtual bool Layout();
701
702 // implementation only
703 void UnsetConstraints(wxLayoutConstraints *c);
704 wxWindowList *GetConstraintsInvolvedIn() const
705 { return m_constraintsInvolvedIn; }
706 void AddConstraintReference(wxWindowBase *otherWin);
707 void RemoveConstraintReference(wxWindowBase *otherWin);
708 void DeleteRelatedConstraints();
709 void ResetConstraints();
710
711 // these methods may be overriden for special layout algorithms
712 virtual void SetConstraintSizes(bool recurse = TRUE);
713 virtual bool LayoutPhase1(int *noChanges);
714 virtual bool LayoutPhase2(int *noChanges);
715 virtual bool DoPhase(int phase);
716
717 // these methods are virtual but normally won't be overridden
718 virtual void SetSizeConstraint(int x, int y, int w, int h);
719 virtual void MoveConstraint(int x, int y);
720 virtual void GetSizeConstraint(int *w, int *h) const ;
721 virtual void GetClientSizeConstraint(int *w, int *h) const ;
722 virtual void GetPositionConstraint(int *x, int *y) const ;
723
724 // sizers
725 // TODO: what are they and how do they work??
726 void SetSizer( wxSizer *sizer );
727 wxSizer *GetSizer() const { return m_windowSizer; }
728 #endif // wxUSE_CONSTRAINTS
729
730 // backward compatibility
731 // ----------------------
732 #if WXWIN_COMPATIBILITY
733 bool Enabled() const { return IsEnabled(); }
734
735 void SetButtonFont(const wxFont& font) { SetFont(font); }
736 void SetLabelFont(const wxFont& font) { SetFont(font); }
737 wxFont& GetLabelFont() { return GetFont(); };
738 wxFont& GetButtonFont() { return GetFont(); };
739 #endif // WXWIN_COMPATIBILITY
740
741 // implementation
742 // --------------
743
744 // event handlers
745 void OnSysColourChanged( wxSysColourChangedEvent& event );
746 void OnInitDialog( wxInitDialogEvent &event );
747 void OnMiddleClick( wxMouseEvent& event );
748 #if wxUSE_HELP
749 void OnHelp(wxHelpEvent& event);
750 #endif // wxUSE_HELP
751
752 // get the haqndle of the window for the underlying window system: this
753 // is only used for wxWin itself or for user code which wants to call
754 // platform-specific APIs
755 virtual WXWidget GetHandle() const = 0;
756
757 protected:
758 // the window id - a number which uniquely identifies a window among
759 // its siblings unless it is -1
760 wxWindowID m_windowId;
761
762 // the parent window of this window (or NULL) and the list of the children
763 // of this window
764 wxWindow *m_parent;
765 wxWindowList m_children;
766
767 // the minimal allowed size for the window (no minimal size if variable(s)
768 // contain(s) -1)
769 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
770
771 // event handler for this window: usually is just 'this' but may be
772 // changed with SetEventHandler()
773 wxEvtHandler *m_eventHandler;
774
775 #if wxUSE_VALIDATORS
776 // associated validator or NULL if none
777 wxValidator *m_windowValidator;
778 #endif // wxUSE_VALIDATORS
779
780 #if wxUSE_DRAG_AND_DROP
781 wxDropTarget *m_dropTarget;
782 #endif // wxUSE_DRAG_AND_DROP
783
784 // visual window attributes
785 wxCursor m_cursor;
786 wxFont m_font;
787 wxColour m_backgroundColour, m_foregroundColour;
788
789 #if wxUSE_CARET
790 wxCaret *m_caret;
791 #endif // wxUSE_CARET
792
793 // the region which should be repainted in response to paint event
794 wxRegion m_updateRegion;
795
796 #if wxUSE_ACCEL
797 // the accelerator table for the window which translates key strokes into
798 // command events
799 wxAcceleratorTable m_acceleratorTable;
800 #endif // wxUSE_ACCEL
801
802 // the tooltip for this window (may be NULL)
803 #if wxUSE_TOOLTIPS
804 wxToolTip *m_tooltip;
805 #endif // wxUSE_TOOLTIPS
806
807 // constraints and sizers
808 #if wxUSE_CONSTRAINTS
809 // the constraints for this window or NULL
810 wxLayoutConstraints *m_constraints;
811
812 // constraints this window is involved in
813 wxWindowList *m_constraintsInvolvedIn;
814
815 // top level and the parent sizers
816 // TODO what's this and how does it work?)
817 wxSizer *m_windowSizer;
818 wxWindowBase *m_sizerParent;
819
820 // Layout() window automatically when its size changes?
821 bool m_autoLayout:1;
822 #endif // wxUSE_CONSTRAINTS
823
824 // window state
825 bool m_isShown:1;
826 bool m_isEnabled:1;
827 bool m_isBeingDeleted:1;
828
829 // was the window colours/font explicitly changed by user?
830 bool m_hasBgCol:1;
831 bool m_hasFgCol:1;
832 bool m_hasFont:1;
833
834 // window attributes
835 long m_windowStyle,
836 m_exStyle;
837 wxString m_windowName;
838 bool m_themeEnabled;
839
840 protected:
841 // common part of all ctors: it is not virtual because it is called from
842 // ctor
843 void InitBase();
844
845 // override this to change the default (i.e. used when no style is
846 // specified) border for the window class
847 virtual wxBorder GetDefaultBorder() const;
848
849 // get the default size for the new window if no explicit size given
850 // FIXME why 20 and not 30, 10 or ...?
851 static int WidthDefault(int w) { return w == -1 ? 20 : w; }
852 static int HeightDefault(int h) { return h == -1 ? 20 : h; }
853
854 // set the best size for the control if the default size was given:
855 // replaces the fields of size == -1 with the best values for them and
856 // calls SetSize() if needed
857 void SetBestSize(const wxSize& size)
858 {
859 if ( size.x == -1 || size.y == -1 )
860 {
861 wxSize sizeBest = DoGetBestSize();
862 if ( size.x != -1 )
863 sizeBest.x = size.x;
864 if ( size.y != -1 )
865 sizeBest.y = size.y;
866
867 SetSize(sizeBest);
868 }
869 }
870
871 // more pure virtual functions
872 // ---------------------------
873
874 // NB: we must have DoSomething() function when Something() is an overloaded
875 // method: indeed, we can't just have "virtual Something()" in case when
876 // the function is overloaded because then we'd have to make virtual all
877 // the variants (otherwise only the virtual function may be called on a
878 // pointer to derived class according to C++ rules) which is, in
879 // general, absolutely not needed. So instead we implement all
880 // overloaded Something()s in terms of DoSomething() which will be the
881 // only one to be virtual.
882
883 // coordinates translation
884 virtual void DoClientToScreen( int *x, int *y ) const = 0;
885 virtual void DoScreenToClient( int *x, int *y ) const = 0;
886
887 virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
888
889 // capture/release the mouse, used by Capture/ReleaseMouse()
890 virtual void DoCaptureMouse();
891 virtual void DoReleaseMouse();
892
893 // retrieve the position/size of the window
894 virtual void DoGetPosition( int *x, int *y ) const = 0;
895 virtual void DoGetSize( int *width, int *height ) const = 0;
896 virtual void DoGetClientSize( int *width, int *height ) const = 0;
897
898 // get the size which best suits the window: for a control, it would be
899 // the minimal size which doesn't truncate the control, for a panel - the
900 // same size as it would have after a call to Fit()
901 virtual wxSize DoGetBestSize() const;
902
903 // this is the virtual function to be overriden in any derived class which
904 // wants to change how SetSize() or Move() works - it is called by all
905 // versions of these functions in the base class
906 virtual void DoSetSize(int x, int y,
907 int width, int height,
908 int sizeFlags = wxSIZE_AUTO) = 0;
909
910 // same as DoSetSize() for the client size
911 virtual void DoSetClientSize(int width, int height) = 0;
912
913 // move the window to the specified location and resize it: this is called
914 // from both DoSetSize() and DoSetClientSize() and would usually just
915 // reposition this window except for composite controls which will want to
916 // arrange themselves inside the given rectangle
917 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
918
919 #if wxUSE_TOOLTIPS
920 virtual void DoSetToolTip( wxToolTip *tip );
921 #endif // wxUSE_TOOLTIPS
922
923 #if wxUSE_MENUS
924 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
925 #endif // wxUSE_MENUS
926
927 // Makes an adjustment to the window position (for example, a frame that has
928 // a toolbar that it manages itself).
929 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
930
931 private:
932 // contains the last id generated by NewControlId
933 static int ms_lastControlId;
934
935 DECLARE_ABSTRACT_CLASS(wxWindowBase)
936 DECLARE_NO_COPY_CLASS(wxWindowBase)
937 DECLARE_EVENT_TABLE()
938 };
939
940 // ----------------------------------------------------------------------------
941 // now include the declaration of wxWindow class
942 // ----------------------------------------------------------------------------
943
944 // include the declaration of the platform-specific class
945 #if defined(__WXMSW__)
946 #ifdef __WXUNIVERSAL__
947 #define wxWindowNative wxWindowMSW
948 #else // !wxUniv
949 #define wxWindowMSW wxWindow
950 #define sm_classwxWindowMSW sm_classwxWindow
951 #endif // wxUniv/!wxUniv
952 #include "wx/msw/window.h"
953 #elif defined(__WXMOTIF__)
954 #include "wx/motif/window.h"
955 #elif defined(__WXGTK__)
956 #ifdef __WXUNIVERSAL__
957 #define wxWindowNative wxWindowGTK
958 #else // !wxUniv
959 #define wxWindowGTK wxWindow
960 #define sm_classwxWindowGTK sm_classwxWindow
961 #endif // wxUniv
962 #include "wx/gtk/window.h"
963 #elif defined(__WXMGL__)
964 #ifdef __WXUNIVERSAL__
965 #define wxWindowNative wxWindowMGL
966 #else // !wxUniv
967 #define wxWindowMGL wxWindow
968 #define sm_classwxWindowMGL sm_classwxWindow
969 #endif // wxUniv
970 #include "wx/mgl/window.h"
971 #elif defined(__WXMAC__)
972 #ifdef __WXUNIVERSAL__
973 #define wxWindowNative wxWindowMac
974 #else // !wxUniv
975 #define wxWindowMac wxWindow
976 #define sm_classwxWindowMac sm_classwxWindow
977 #endif // wxUniv
978 #include "wx/mac/window.h"
979 #elif defined(__WXPM__)
980 #ifdef __WXUNIVERSAL__
981 #define wxWindowNative wxWindowOS2
982 #else // !wxUniv
983 #define wxWindowOS2 wxWindow
984 #define sm_classwxWindowOS2 sm_classwxWindow
985 #endif // wxUniv/!wxUniv
986 #include "wx/os2/window.h"
987 #endif
988
989 // for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
990 // for the native ports we already have defined it above
991 #if defined(__WXUNIVERSAL__)
992 #ifndef wxWindowNative
993 #error "wxWindowNative must be defined above!"
994 #endif
995
996 #include "wx/univ/window.h"
997 #endif // wxUniv
998
999 // ----------------------------------------------------------------------------
1000 // inline functions which couldn't be declared in the class body because of
1001 // forward dependencies
1002 // ----------------------------------------------------------------------------
1003
1004 inline wxWindow *wxWindowBase::GetGrandParent() const
1005 {
1006 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
1007 }
1008
1009 // ----------------------------------------------------------------------------
1010 // global functions
1011 // ----------------------------------------------------------------------------
1012
1013 // Find the wxWindow at the current mouse position, also returning the mouse
1014 // position.
1015 WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt);
1016
1017 // Get the current mouse position.
1018 WXDLLEXPORT extern wxPoint wxGetMousePosition();
1019
1020 // get the currently active window of this application or NULL
1021 WXDLLEXPORT extern wxWindow *wxGetActiveWindow();
1022
1023 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
1024 inline int NewControlId() { return wxWindowBase::NewControlId(); }
1025
1026 #endif
1027 // _WX_WINDOW_H_BASE_