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