]> git.saurik.com Git - wxWidgets.git/blob - include/wx/window.h
1. added wxHelpProvider and (unfinished) wxSimpleHelpProvider
[wxWidgets.git] / include / wx / window.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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 // ----------------------------------------------------------------------------
40 // forward declarations
41 // ----------------------------------------------------------------------------
42
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;
56
57 // ----------------------------------------------------------------------------
58 // (pseudo)template list classes
59 // ----------------------------------------------------------------------------
60
61 WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT);
62
63 // ----------------------------------------------------------------------------
64 // global variables
65 // ----------------------------------------------------------------------------
66
67 WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
68
69 // ----------------------------------------------------------------------------
70 // helper classes used by [SG]etClientObject/Data
71 //
72 // TODO move into a separate header?
73 // ----------------------------------------------------------------------------
74
75 class wxClientData
76 {
77 public:
78 wxClientData() { }
79 virtual ~wxClientData() { }
80 };
81
82 class wxStringClientData : public wxClientData
83 {
84 public:
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; }
89
90 private:
91 wxString m_data;
92 };
93
94 // ----------------------------------------------------------------------------
95 // wxWindowBase is the base class for all GUI controls/widgets, this is the public
96 // interface of this class.
97 //
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 // ----------------------------------------------------------------------------
104
105 class WXDLLEXPORT wxWindowBase : public wxEvtHandler
106 {
107 DECLARE_ABSTRACT_CLASS(wxWindowBase);
108
109 public:
110 // creating the window
111 // -------------------
112
113 // default ctor
114 wxWindowBase() { InitBase(); }
115
116 // pseudo ctor (can't be virtual, called from ctor)
117 bool CreateBase(wxWindowBase *parent,
118 wxWindowID id,
119 const wxPoint& pos = wxDefaultPosition,
120 const wxSize& size = wxDefaultSize,
121 long style = 0,
122 const wxValidator& validator = wxDefaultValidator,
123 const wxString& name = wxPanelNameStr);
124
125 virtual ~wxWindowBase();
126
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
136
137 // deleting the window
138 // -------------------
139
140 // ask the window to close itself, return TRUE if the event handler
141 // honoured our request
142 bool Close( bool force = FALSE );
143
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
147
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();
152
153 // is the window being deleted?
154 bool IsBeingDeleted() const { return m_isBeingDeleted; }
155
156 // window attributes
157 // -----------------
158
159 // the title (or label, see below) of the window: the text which the
160 // window shows
161 virtual void SetTitle( const wxString & WXUNUSED(title) ) { }
162 virtual wxString GetTitle() const { return ""; }
163
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(); }
168
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; }
173
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; }
178
179 // generate a control id for the controls which were not given one by
180 // user
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; }
188
189 // moving/resizing
190 // ---------------
191
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); }
196
197 void SetSize( int width, int height )
198 { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); }
199
200 void SetSize( const wxSize& size )
201 { SetSize( size.x, size.y); }
202
203 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
204 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
205
206 void Move( int x, int y )
207 { DoSetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); }
208
209 void Move(const wxPoint& pt)
210 { Move(pt.x, pt.y); }
211
212 // Z-order
213 virtual void Raise() = 0;
214 virtual void Lower() = 0;
215
216 // client size is the size of area available for subwindows
217 void SetClientSize( int width, int height )
218 { DoSetClientSize(width, height); }
219
220 void SetClientSize( const wxSize& size )
221 { DoSetClientSize(size.x, size.y); }
222
223 void SetClientSize(const wxRect& rect)
224 { SetClientSize( rect.width, rect.height ); }
225
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
229 {
230 int w, h;
231 DoGetPosition(&w, &h);
232
233 return wxPoint(w, h);
234 }
235
236 void GetSize( int *w, int *h ) const { DoGetSize(w, h); }
237 wxSize GetSize() const
238 {
239 int w, h;
240 DoGetSize(& w, & h);
241 return wxSize(w, h);
242 }
243
244 wxRect GetRect() const
245 {
246 int x, y, w, h;
247 GetPosition(& x, & y);
248 GetSize(& w, & h);
249
250 return wxRect(x, y, w, h);
251 }
252
253 void GetClientSize( int *w, int *h ) const { DoGetClientSize(w, h); }
254 wxSize GetClientSize() const
255 {
256 int w, h;
257 DoGetClientSize(& w, & h);
258
259 return wxSize(w, h);
260 }
261
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
266 {
267 wxSize s = DoGetBestSize();
268 if ( w )
269 *w = s.x;
270 if ( h )
271 *h = s.y;
272 }
273
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); }
279
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); }
283
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); }
287
288 // set window size to wrap around its children
289 virtual void Fit();
290
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 );
295
296 int GetMinWidth() const { return m_minWidth; }
297 int GetMinHeight() const { return m_minHeight; }
298 int GetMaxWidth() const { return m_maxWidth; }
299 int GetMaxHeight() const { return m_maxHeight; }
300
301 // window state
302 // ------------
303
304 // returns TRUE if window was shown/hidden, FALSE if the nothing was
305 // done (window was already shown/hidden)
306 virtual bool Show( bool show = TRUE );
307 bool Hide() { return Show(FALSE); }
308
309 // returns TRUE if window was enabled/disabled, FALSE if nothing done
310 virtual bool Enable( bool enable = TRUE );
311 bool Disable() { return Enable(FALSE); }
312
313 bool IsShown() const { return m_isShown; }
314 bool IsEnabled() const { return m_isEnabled; }
315
316 // get/set window style (setting style won't update the window and so
317 // is only useful for internal usage)
318 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
319 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
320
321 // just some (somewhat shorter) synonims
322 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
323 long GetWindowStyle() const { return GetWindowStyleFlag(); }
324
325 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
326 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
327
328 // extra style: the less often used style bits which can't be set with
329 // SetWindowStyleFlag()
330 void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
331 long GetExtraStyle() const { return m_exStyle; }
332
333 // make the window modal (all other windows unresponsive)
334 virtual void MakeModal(bool modal = TRUE);
335
336 // focus handling
337 // --------------
338
339 // set focus to this window
340 virtual void SetFocus() = 0;
341
342 // return the window which currently has the focus or NULL
343 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
344
345 // can this window have focus?
346 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
347
348 // parent/children relations
349 // -------------------------
350
351 // get the list of children
352 const wxWindowList& GetChildren() const { return m_children; }
353 wxWindowList& GetChildren() { return m_children; }
354
355 // get the parent or the parent of the parent
356 wxWindow *GetParent() const { return m_parent; }
357 inline wxWindow *GetGrandParent() const;
358
359 // is this window a top level one?
360 virtual bool IsTopLevel() const;
361
362 // it doesn't really change parent, use ReParent() instead
363 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
364 // change the real parent of this window, return TRUE if the parent
365 // was changed, FALSE otherwise (error or newParent == oldParent)
366 virtual bool Reparent( wxWindowBase *newParent );
367
368 // find window among the descendants of this one either by id or by
369 // name (return NULL if not found)
370 wxWindow *FindWindow( long id );
371 wxWindow *FindWindow( const wxString& name );
372
373 // implementation mostly
374 virtual void AddChild( wxWindowBase *child );
375 virtual void RemoveChild( wxWindowBase *child );
376
377 // event handler stuff
378 // -------------------
379
380 // get the current event handler
381 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
382
383 // replace the event handler (allows to completely subclass the
384 // window)
385 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
386
387 // push/pop event handler: allows to chain a custom event handler to
388 // alreasy existing ones
389 void PushEventHandler( wxEvtHandler *handler );
390 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
391
392 // validators and client data
393 // --------------------------
394
395 #if wxUSE_VALIDATORS
396 // a window may have an associated validator which is used to control
397 // user input
398 virtual void SetValidator( const wxValidator &validator );
399 virtual wxValidator *GetValidator() { return m_windowValidator; }
400 #endif // wxUSE_VALIDATORS
401
402 // each window may have associated client data: either a pointer to
403 // wxClientData object in which case it is managed by the window (i.e.
404 // it will delete the data when it's destroyed) or an untyped pointer
405 // which won't be deleted by the window - but not both of them
406 void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
407 wxClientData *GetClientObject() const { return DoGetClientObject(); }
408
409 void SetClientData( void *data ) { DoSetClientData(data); }
410 void *GetClientData() const { return DoGetClientData(); }
411
412 // dialog oriented functions
413 // -------------------------
414
415 // validate the correctness of input, return TRUE if ok
416 virtual bool Validate();
417
418 // transfer data between internal and GUI representations
419 virtual bool TransferDataToWindow();
420 virtual bool TransferDataFromWindow();
421
422 virtual void InitDialog();
423
424 #if wxUSE_ACCEL
425 // accelerators
426 // ------------
427 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
428 { m_acceleratorTable = accel; }
429 wxAcceleratorTable *GetAcceleratorTable()
430 { return &m_acceleratorTable; }
431 #endif // wxUSE_ACCEL
432
433 // dialog units translations
434 // -------------------------
435
436 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
437 wxPoint ConvertDialogToPixels( const wxPoint& pt );
438 wxSize ConvertPixelsToDialog( const wxSize& sz )
439 {
440 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
441
442 return wxSize(pt.x, pt.y);
443 }
444
445 wxSize ConvertDialogToPixels( const wxSize& sz )
446 {
447 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
448
449 return wxSize(pt.x, pt.y);
450 }
451
452 // mouse functions
453 // ---------------
454
455 // move the mouse to the specified position
456 virtual void WarpPointer(int x, int y) = 0;
457
458 // start or end mouse capture
459 virtual void CaptureMouse() = 0;
460 virtual void ReleaseMouse() = 0;
461
462 // painting the window
463 // -------------------
464
465 // mark the specified rectangle (or the whole window) as "dirty" so it
466 // will be repainted
467 virtual void Refresh( bool eraseBackground = TRUE,
468 const wxRect *rect = (const wxRect *) NULL ) = 0;
469 // clear the window entirely
470 virtual void Clear() = 0;
471
472 // adjust DC for drawing on this window
473 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
474
475 // the update region of the window contains the areas which must be
476 // repainted by the program
477 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
478 wxRegion& GetUpdateRegion() { return m_updateRegion; }
479
480 // these functions verify whether the given point/rectangle belongs to
481 // (or at least intersects with) the update region
482 bool IsExposed( int x, int y ) const;
483 bool IsExposed( int x, int y, int w, int h ) const;
484
485 bool IsExposed( const wxPoint& pt ) const
486 { return IsExposed(pt.x, pt.y); }
487 bool IsExposed( const wxRect& rect ) const
488 { return IsExposed(rect.x, rect.y, rect.width, rect.height); }
489
490 // colours, fonts and cursors
491 // --------------------------
492
493 // set/retrieve the window colours (system defaults are used by
494 // default): Set functions return TRUE if colour was changed
495 virtual bool SetBackgroundColour( const wxColour &colour );
496 virtual bool SetForegroundColour( const wxColour &colour );
497
498 wxColour GetBackgroundColour() const { return m_backgroundColour; }
499 wxColour GetForegroundColour() const { return m_foregroundColour; }
500
501 // set/retrieve the cursor for this window (SetCursor() returns TRUE
502 // if the cursor was really changed)
503 virtual bool SetCursor( const wxCursor &cursor );
504 const wxCursor& GetCursor() const { return m_cursor; }
505 wxCursor& GetCursor() { return m_cursor; }
506
507 // set/retrieve the font for the window (SetFont() returns TRUE if the
508 // font really changed)
509 virtual bool SetFont( const wxFont &font ) = 0;
510 const wxFont& GetFont() const { return m_font; }
511 wxFont& GetFont() { return m_font; }
512
513 #if wxUSE_CARET
514 // associate a caret with the window
515 void SetCaret(wxCaret *caret);
516 // get the current caret (may be NULL)
517 wxCaret *GetCaret() const { return m_caret; }
518 #endif // wxUSE_CARET
519
520 // get the (average) character size for the current font
521 virtual int GetCharHeight() const = 0;
522 virtual int GetCharWidth() const = 0;
523
524 // get the width/height/... of the text using current or specified
525 // font
526 virtual void GetTextExtent(const wxString& string,
527 int *x, int *y,
528 int *descent = (int *) NULL,
529 int *externalLeading = (int *) NULL,
530 const wxFont *theFont = (const wxFont *) NULL)
531 const = 0;
532
533 // translate to/from screen/client coordinates (pointers may be NULL)
534 void ClientToScreen( int *x, int *y ) const
535 { DoClientToScreen(x, y); }
536 void ScreenToClient( int *x, int *y ) const
537 { DoScreenToClient(x, y); }
538 wxPoint ClientToScreen(const wxPoint& pt) const
539 {
540 int x = pt.x, y = pt.y;
541 DoClientToScreen(&x, &y);
542
543 return wxPoint(x, y);
544 }
545
546 wxPoint ScreenToClient(const wxPoint& pt) const
547 {
548 int x = pt.x, y = pt.y;
549 DoScreenToClient(&x, &y);
550
551 return wxPoint(x, y);
552 }
553
554 // misc
555 // ----
556
557 void UpdateWindowUI();
558
559 bool PopupMenu( wxMenu *menu, const wxPoint& pos )
560 { return DoPopupMenu(menu, pos.x, pos.y); }
561 bool PopupMenu( wxMenu *menu, int x, int y )
562 { return DoPopupMenu(menu, x, y); }
563
564 // scrollbars
565 // ----------
566
567 // configure the window scrollbars
568 virtual void SetScrollbar( int orient,
569 int pos,
570 int thumbVisible,
571 int range,
572 bool refresh = TRUE ) = 0;
573 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0;
574 virtual int GetScrollPos( int orient ) const = 0;
575 virtual int GetScrollThumb( int orient ) const = 0;
576 virtual int GetScrollRange( int orient ) const = 0;
577
578 // scroll window to the specified position
579 virtual void ScrollWindow( int dx, int dy,
580 const wxRect* rect = (wxRect *) NULL ) = 0;
581
582 // context-sensitive help
583 // ----------------------
584
585 // these are the convenience functions wrapping wxHelpProvider methods
586
587 #if wxUSE_HELP
588 // associate this help text with this window
589 void SetHelpText(const wxString& text);
590 // associate this help text with all windows with the same id as this
591 // one
592 void SetHelpTextForId(const wxString& text);
593 // get the help string associated with this window (may be empty)
594 wxString GetHelpText() const;
595 #endif // wxUSE_HELP
596
597 // tooltips
598 // --------
599
600 #if wxUSE_TOOLTIPS
601 // the easiest way to set a tooltip for a window is to use this method
602 void SetToolTip( const wxString &tip );
603 // attach a tooltip to the window
604 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
605 // get the associated tooltip or NULL if none
606 wxToolTip* GetToolTip() const { return m_tooltip; }
607 #endif // wxUSE_TOOLTIPS
608
609 // drag and drop
610 // -------------
611 #if wxUSE_DRAG_AND_DROP
612 // set/retrieve the drop target associated with this window (may be
613 // NULL; it's owned by the window and will be deleted by it)
614 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
615 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
616 #endif // wxUSE_DRAG_AND_DROP
617
618 // constraints and sizers
619 // ----------------------
620 #if wxUSE_CONSTRAINTS
621 // set the constraints for this window or retrieve them (may be NULL)
622 void SetConstraints( wxLayoutConstraints *constraints );
623 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
624
625 // when using constraints, it makes sense to update children positions
626 // automatically whenever the window is resized - this is done if
627 // autoLayout is on
628 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
629 bool GetAutoLayout() const { return m_autoLayout; }
630
631 // do layout the window and its children
632 virtual bool Layout();
633
634 // implementation only
635 void UnsetConstraints(wxLayoutConstraints *c);
636 wxWindowList *GetConstraintsInvolvedIn() const
637 { return m_constraintsInvolvedIn; }
638 void AddConstraintReference(wxWindowBase *otherWin);
639 void RemoveConstraintReference(wxWindowBase *otherWin);
640 void DeleteRelatedConstraints();
641 void ResetConstraints();
642
643 // these methods may be overriden for special layout algorithms
644 virtual void SetConstraintSizes(bool recurse = TRUE);
645 virtual bool LayoutPhase1(int *noChanges);
646 virtual bool LayoutPhase2(int *noChanges);
647 virtual bool DoPhase(int phase);
648
649 // these methods are virtual but normally won't be overridden
650 virtual void SetSizeConstraint(int x, int y, int w, int h);
651 virtual void MoveConstraint(int x, int y);
652 virtual void GetSizeConstraint(int *w, int *h) const ;
653 virtual void GetClientSizeConstraint(int *w, int *h) const ;
654 virtual void GetPositionConstraint(int *x, int *y) const ;
655
656 // sizers
657 // TODO: what are they and how do they work??
658 void SetSizer( wxSizer *sizer );
659 wxSizer *GetSizer() const { return m_windowSizer; }
660 #endif // wxUSE_CONSTRAINTS
661
662 // backward compatibility
663 // ----------------------
664 #if WXWIN_COMPATIBILITY
665 bool Enabled() const { return IsEnabled(); }
666
667 void SetButtonFont(const wxFont& font) { SetFont(font); }
668 void SetLabelFont(const wxFont& font) { SetFont(font); }
669 wxFont& GetLabelFont() { return GetFont(); };
670 wxFont& GetButtonFont() { return GetFont(); };
671 #endif // WXWIN_COMPATIBILITY
672
673 // implementation
674 // --------------
675
676 // event handlers
677 void OnSysColourChanged( wxSysColourChangedEvent& event );
678 void OnInitDialog( wxInitDialogEvent &event );
679 void OnMiddleClick( wxMouseEvent& event );
680 #if wxUSE_HELP
681 void OnHelp(wxHelpEvent& event);
682 #endif // wxUSE_HELP
683
684 // get the haqndle of the window for the underlying window system: this
685 // is only used for wxWin itself or for user code which wants to call
686 // platform-specific APIs
687 virtual WXWidget GetHandle() const = 0;
688
689 protected:
690 // the window id - a number which uniquely identifies a window among
691 // its siblings unless it is -1
692 wxWindowID m_windowId;
693
694 // the parent window of this window (or NULL) and the list of the children
695 // of this window
696 wxWindow *m_parent;
697 wxWindowList m_children;
698
699 // the minimal allowed size for the window (no minimal size if variable(s)
700 // contain(s) -1)
701 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
702
703 // event handler for this window: usually is just 'this' but may be
704 // changed with SetEventHandler()
705 wxEvtHandler *m_eventHandler;
706
707 #if wxUSE_VALIDATORS
708 // associated validator or NULL if none
709 wxValidator *m_windowValidator;
710 #endif // wxUSE_VALIDATORS
711
712 #if wxUSE_DRAG_AND_DROP
713 wxDropTarget *m_dropTarget;
714 #endif // wxUSE_DRAG_AND_DROP
715
716 // visual window attributes
717 wxCursor m_cursor;
718 wxFont m_font;
719 wxColour m_backgroundColour, m_foregroundColour;
720
721 #if wxUSE_CARET
722 wxCaret *m_caret;
723 #endif // wxUSE_CARET
724
725 // the region which should be repainted in response to paint event
726 wxRegion m_updateRegion;
727
728 #if wxUSE_ACCEL
729 // the accelerator table for the window which translates key strokes into
730 // command events
731 wxAcceleratorTable m_acceleratorTable;
732 #endif // wxUSE_ACCEL
733
734 // user data associated with the window: either an object which will be
735 // deleted by the window when it's deleted or some raw pointer which we do
736 // nothing with - only one type of data can be used with the given window
737 // (i.e. you cannot set the void data and then associate the window with
738 // wxClientData or vice versa)
739 union
740 {
741 wxClientData *m_clientObject;
742 void *m_clientData;
743 };
744
745 // the tooltip for this window (may be NULL)
746 #if wxUSE_TOOLTIPS
747 wxToolTip *m_tooltip;
748 #endif // wxUSE_TOOLTIPS
749
750 // constraints and sizers
751 #if wxUSE_CONSTRAINTS
752 // the constraints for this window or NULL
753 wxLayoutConstraints *m_constraints;
754
755 // constraints this window is involved in
756 wxWindowList *m_constraintsInvolvedIn;
757
758 // top level and the parent sizers
759 // TODO what's this and how does it work?)
760 wxSizer *m_windowSizer;
761 wxWindowBase *m_sizerParent;
762
763 // Layout() window automatically when its size changes?
764 bool m_autoLayout:1;
765 #endif // wxUSE_CONSTRAINTS
766
767 // window state
768 bool m_isShown:1;
769 bool m_isEnabled:1;
770 bool m_isBeingDeleted:1;
771
772 // window attributes
773 long m_windowStyle,
774 m_exStyle;
775 wxString m_windowName;
776
777 protected:
778 // common part of all ctors: it is not virtual because it is called from
779 // ctor
780 void InitBase();
781
782 // get the default size for the new window if no explicit size given
783 // FIXME why 20 and not 30, 10 or ...?
784 static int WidthDefault(int w) { return w == -1 ? 20 : w; }
785 static int HeightDefault(int h) { return h == -1 ? 20 : h; }
786
787 // sets the size to be size but take width and/or height from
788 // DoGetBestSize() if width/height of size is -1
789 //
790 // NB: when calling this function from the ctor, the DoGetBestSize() of
791 // the class with the same name as the ctor, not the real (most
792 // derived) one - but this is what we usually want
793 void SetSizeOrDefault(const wxSize& size = wxDefaultSize)
794 {
795 if ( size.x == -1 || size.y == -1 )
796 {
797 wxSize sizeDef = GetBestSize();
798 SetSize( size.x == -1 ? sizeDef.x : size.x,
799 size.y == -1 ? sizeDef.y : size.y);
800 }
801 else
802 {
803 SetSize(size);
804 }
805 }
806
807 // more pure virtual functions
808 // ---------------------------
809
810 // NB: we must have DoSomething() function when Something() is an overloaded
811 // method: indeed, we can't just have "virtual Something()" in case when
812 // the function is overloaded because then we'd have to make virtual all
813 // the variants (otherwise only the virtual function may be called on a
814 // pointer to derived class according to C++ rules) which is, in
815 // general, absolutely not needed. So instead we implement all
816 // overloaded Something()s in terms of DoSomething() which will be the
817 // only one to be virtual.
818
819 // coordinates translation
820 virtual void DoClientToScreen( int *x, int *y ) const = 0;
821 virtual void DoScreenToClient( int *x, int *y ) const = 0;
822
823 // retrieve the position/size of the window
824 virtual void DoGetPosition( int *x, int *y ) const = 0;
825 virtual void DoGetSize( int *width, int *height ) const = 0;
826 virtual void DoGetClientSize( int *width, int *height ) const = 0;
827
828 // get the size which best suits the window: for a control, it would be
829 // the minimal size which doesn't truncate the control, for a panel - the
830 // same size as it would have after a call to Fit()
831 virtual wxSize DoGetBestSize() const;
832
833 // this is the virtual function to be overriden in any derived class which
834 // wants to change how SetSize() or Move() works - it is called by all
835 // versions of these functions in the base class
836 virtual void DoSetSize(int x, int y,
837 int width, int height,
838 int sizeFlags = wxSIZE_AUTO) = 0;
839
840 // same as DoSetSize() for the client size
841 virtual void DoSetClientSize(int width, int height) = 0;
842
843 // move the window to the specified location and resize it: this is called
844 // from both DoSetSize() and DoSetClientSize() and would usually just
845 // reposition this window except for composite controls which will want to
846 // arrange themselves inside the given rectangle
847 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
848
849 #if wxUSE_TOOLTIPS
850 virtual void DoSetToolTip( wxToolTip *tip );
851 #endif // wxUSE_TOOLTIPS
852
853 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
854
855 // client data accessors
856 virtual void DoSetClientObject( wxClientData *data );
857 virtual wxClientData *DoGetClientObject() const;
858
859 virtual void DoSetClientData( void *data );
860 virtual void *DoGetClientData() const;
861
862 // what kind of data do we have?
863 enum wxClientDataType
864 {
865 ClientData_None, // we don't know yet because we don't have it at all
866 ClientData_Object, // our client data is typed and we own it
867 ClientData_Void // client data is untyped and we don't own it
868 } m_clientDataType;
869
870 private:
871 // contains the last id generated by NewControlId
872 static int ms_lastControlId;
873
874 DECLARE_NO_COPY_CLASS(wxWindowBase);
875 DECLARE_EVENT_TABLE()
876 };
877
878 // ----------------------------------------------------------------------------
879 // now include the declaration of wxWindow class
880 // ----------------------------------------------------------------------------
881
882 #if defined(__WXMSW__)
883 #include "wx/msw/window.h"
884 #elif defined(__WXMOTIF__)
885 #include "wx/motif/window.h"
886 #elif defined(__WXGTK__)
887 #include "wx/gtk/window.h"
888 #elif defined(__WXQT__)
889 #include "wx/qt/window.h"
890 #elif defined(__WXMAC__)
891 #include "wx/mac/window.h"
892 #elif defined(__WXPM__)
893 #include "wx/os2/window.h"
894 #endif
895
896 // ----------------------------------------------------------------------------
897 // inline functions which couldn't be declared in the class body because of
898 // forward dependencies
899 // ----------------------------------------------------------------------------
900
901 inline wxWindow *wxWindowBase::GetGrandParent() const
902 {
903 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
904 }
905
906 // ----------------------------------------------------------------------------
907 // global functions
908 // ----------------------------------------------------------------------------
909
910 WXDLLEXPORT extern wxWindow* wxGetActiveWindow();
911
912 // Find the wxWindow at the current mouse position, also returning the mouse
913 // position.
914 WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt);
915
916 // Get the current mouse position.
917 WXDLLEXPORT extern wxPoint wxGetMousePosition();
918
919 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
920 inline WXDLLEXPORT int NewControlId() { return wxWindowBase::NewControlId(); }
921
922 #endif
923 // _WX_WINDOW_H_BASE_