]> git.saurik.com Git - wxWidgets.git/blame - include/wx/window.h
another GetInt/GetId bug fix
[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
674ac8b9 33#include "wx/validate.h" // for wxDefaultValidator (always include it)
8d99be5f 34
88ac883a
VZ
35#if wxUSE_ACCEL
36 #include "wx/accel.h"
37#endif // wxUSE_ACCEL
f03fc89f
VZ
38
39// ----------------------------------------------------------------------------
40// forward declarations
41// ----------------------------------------------------------------------------
42
789295bf 43class WXDLLEXPORT wxCaret;
f03fc89f
VZ
44class WXDLLEXPORT wxClientData;
45class WXDLLEXPORT wxControl;
46class WXDLLEXPORT wxCursor;
eb082a08 47class WXDLLEXPORT wxDC;
f03fc89f
VZ
48class WXDLLEXPORT wxDropTarget;
49class WXDLLEXPORT wxItemResource;
50class WXDLLEXPORT wxLayoutConstraints;
51class WXDLLEXPORT wxResourceTable;
52class WXDLLEXPORT wxSizer;
53class WXDLLEXPORT wxToolTip;
f03fc89f
VZ
54class WXDLLEXPORT wxWindowBase;
55class WXDLLEXPORT wxWindow;
56
57// ----------------------------------------------------------------------------
58// (pseudo)template list classes
59// ----------------------------------------------------------------------------
60
f6bcfd97 61WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT);
f03fc89f
VZ
62
63// ----------------------------------------------------------------------------
64// global variables
65// ----------------------------------------------------------------------------
66
67WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
68
69// ----------------------------------------------------------------------------
70// helper classes used by [SG]etClientObject/Data
71//
72// TODO move into a separate header?
73// ----------------------------------------------------------------------------
74
75class wxClientData
76{
77public:
78 wxClientData() { }
79 virtual ~wxClientData() { }
80};
81
82class wxStringClientData : public wxClientData
83{
84public:
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
90private:
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
105class WXDLLEXPORT wxWindowBase : public wxEvtHandler
106{
107 DECLARE_ABSTRACT_CLASS(wxWindowBase);
108
109public:
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,
8d99be5f 122 const wxValidator& validator = wxDefaultValidator,
f03fc89f
VZ
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)
eba0e4d4
RR
166 virtual void SetLabel(const wxString& label) { SetTitle(label); }
167 virtual wxString GetLabel() const { return GetTitle(); }
f03fc89f
VZ
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
69418a8e 181 static int NewControlId() { return --ms_lastControlId; }
c539ab55
VZ
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; }
f03fc89f
VZ
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
f68586e5
VZ
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
7eb4e9cc
VZ
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
c39eda94
VZ
277 void Centre( int direction = wxBOTH );
278 void Center( int direction = wxBOTH ) { Centre(direction); }
7eb4e9cc
VZ
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); }
f03fc89f
VZ
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
738f9e5a
RR
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; }
57c4d796 300
f03fc89f
VZ
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; }
d80cd92a 326 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
f03fc89f 327
d80cd92a
VZ
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; }
f03fc89f
VZ
332
333 // make the window modal (all other windows unresponsive)
334 virtual void MakeModal(bool modal = TRUE);
335
a2d93e73
JS
336 virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
337 virtual bool GetThemeEnabled() const { return m_themeEnabled; }
338
f03fc89f
VZ
339 // focus handling
340 // --------------
341
342 // set focus to this window
343 virtual void SetFocus() = 0;
344
345 // return the window which currently has the focus or NULL
346 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
347
348 // can this window have focus?
349 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
350
351 // parent/children relations
352 // -------------------------
353
354 // get the list of children
355 const wxWindowList& GetChildren() const { return m_children; }
356 wxWindowList& GetChildren() { return m_children; }
357
358 // get the parent or the parent of the parent
359 wxWindow *GetParent() const { return m_parent; }
360 inline wxWindow *GetGrandParent() const;
361
362 // is this window a top level one?
8487f887 363 virtual bool IsTopLevel() const;
f03fc89f
VZ
364
365 // it doesn't really change parent, use ReParent() instead
366 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
367 // change the real parent of this window, return TRUE if the parent
368 // was changed, FALSE otherwise (error or newParent == oldParent)
369 virtual bool Reparent( wxWindowBase *newParent );
370
371 // find window among the descendants of this one either by id or by
372 // name (return NULL if not found)
373 wxWindow *FindWindow( long id );
374 wxWindow *FindWindow( const wxString& name );
375
376 // implementation mostly
377 virtual void AddChild( wxWindowBase *child );
378 virtual void RemoveChild( wxWindowBase *child );
379
380 // event handler stuff
381 // -------------------
382
383 // get the current event handler
384 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
385
386 // replace the event handler (allows to completely subclass the
387 // window)
388 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
389
390 // push/pop event handler: allows to chain a custom event handler to
391 // alreasy existing ones
392 void PushEventHandler( wxEvtHandler *handler );
393 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
394
395 // validators and client data
396 // --------------------------
397
88ac883a 398#if wxUSE_VALIDATORS
f03fc89f
VZ
399 // a window may have an associated validator which is used to control
400 // user input
401 virtual void SetValidator( const wxValidator &validator );
402 virtual wxValidator *GetValidator() { return m_windowValidator; }
88ac883a 403#endif // wxUSE_VALIDATORS
f03fc89f
VZ
404
405 // each window may have associated client data: either a pointer to
406 // wxClientData object in which case it is managed by the window (i.e.
407 // it will delete the data when it's destroyed) or an untyped pointer
8d99be5f
VZ
408 // which won't be deleted by the window - but not both of them
409 void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
410 wxClientData *GetClientObject() const { return DoGetClientObject(); }
f03fc89f 411
8d99be5f
VZ
412 void SetClientData( void *data ) { DoSetClientData(data); }
413 void *GetClientData() const { return DoGetClientData(); }
f03fc89f
VZ
414
415 // dialog oriented functions
416 // -------------------------
417
418 // validate the correctness of input, return TRUE if ok
419 virtual bool Validate();
420
421 // transfer data between internal and GUI representations
422 virtual bool TransferDataToWindow();
423 virtual bool TransferDataFromWindow();
424
425 virtual void InitDialog();
426
88ac883a 427#if wxUSE_ACCEL
f03fc89f
VZ
428 // accelerators
429 // ------------
430 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
431 { m_acceleratorTable = accel; }
432 wxAcceleratorTable *GetAcceleratorTable()
433 { return &m_acceleratorTable; }
88ac883a 434#endif // wxUSE_ACCEL
f03fc89f
VZ
435
436 // dialog units translations
437 // -------------------------
438
439 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
440 wxPoint ConvertDialogToPixels( const wxPoint& pt );
441 wxSize ConvertPixelsToDialog( const wxSize& sz )
442 {
443 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
444
445 return wxSize(pt.x, pt.y);
446 }
447
448 wxSize ConvertDialogToPixels( const wxSize& sz )
449 {
450 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
451
452 return wxSize(pt.x, pt.y);
453 }
454
455 // mouse functions
456 // ---------------
457
458 // move the mouse to the specified position
459 virtual void WarpPointer(int x, int y) = 0;
460
461 // start or end mouse capture
462 virtual void CaptureMouse() = 0;
463 virtual void ReleaseMouse() = 0;
464
465 // painting the window
466 // -------------------
467
468 // mark the specified rectangle (or the whole window) as "dirty" so it
469 // will be repainted
470 virtual void Refresh( bool eraseBackground = TRUE,
471 const wxRect *rect = (const wxRect *) NULL ) = 0;
472 // clear the window entirely
473 virtual void Clear() = 0;
474
475 // adjust DC for drawing on this window
f6147cfc 476 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
f03fc89f
VZ
477
478 // the update region of the window contains the areas which must be
479 // repainted by the program
480 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
481 wxRegion& GetUpdateRegion() { return m_updateRegion; }
482
483 // these functions verify whether the given point/rectangle belongs to
484 // (or at least intersects with) the update region
485 bool IsExposed( int x, int y ) const;
486 bool IsExposed( int x, int y, int w, int h ) const;
487
488 bool IsExposed( const wxPoint& pt ) const
489 { return IsExposed(pt.x, pt.y); }
490 bool IsExposed( const wxRect& rect ) const
491 { return IsExposed(rect.x, rect.y, rect.width, rect.height); }
492
493 // colours, fonts and cursors
494 // --------------------------
495
496 // set/retrieve the window colours (system defaults are used by
497 // default): Set functions return TRUE if colour was changed
498 virtual bool SetBackgroundColour( const wxColour &colour );
499 virtual bool SetForegroundColour( const wxColour &colour );
500
501 wxColour GetBackgroundColour() const { return m_backgroundColour; }
502 wxColour GetForegroundColour() const { return m_foregroundColour; }
503
504 // set/retrieve the cursor for this window (SetCursor() returns TRUE
505 // if the cursor was really changed)
506 virtual bool SetCursor( const wxCursor &cursor );
507 const wxCursor& GetCursor() const { return m_cursor; }
508 wxCursor& GetCursor() { return m_cursor; }
509
510 // set/retrieve the font for the window (SetFont() returns TRUE if the
511 // font really changed)
512 virtual bool SetFont( const wxFont &font ) = 0;
513 const wxFont& GetFont() const { return m_font; }
514 wxFont& GetFont() { return m_font; }
515
789295bf
VZ
516#if wxUSE_CARET
517 // associate a caret with the window
518 void SetCaret(wxCaret *caret);
519 // get the current caret (may be NULL)
520 wxCaret *GetCaret() const { return m_caret; }
521#endif // wxUSE_CARET
522
f03fc89f
VZ
523 // get the (average) character size for the current font
524 virtual int GetCharHeight() const = 0;
525 virtual int GetCharWidth() const = 0;
526
527 // get the width/height/... of the text using current or specified
528 // font
529 virtual void GetTextExtent(const wxString& string,
530 int *x, int *y,
531 int *descent = (int *) NULL,
532 int *externalLeading = (int *) NULL,
533 const wxFont *theFont = (const wxFont *) NULL)
534 const = 0;
535
536 // translate to/from screen/client coordinates (pointers may be NULL)
dabc0cd5
VZ
537 void ClientToScreen( int *x, int *y ) const
538 { DoClientToScreen(x, y); }
539 void ScreenToClient( int *x, int *y ) const
540 { DoScreenToClient(x, y); }
541 wxPoint ClientToScreen(const wxPoint& pt) const
542 {
543 int x = pt.x, y = pt.y;
544 DoClientToScreen(&x, &y);
545
546 return wxPoint(x, y);
547 }
548
549 wxPoint ScreenToClient(const wxPoint& pt) const
550 {
551 int x = pt.x, y = pt.y;
552 DoScreenToClient(&x, &y);
553
554 return wxPoint(x, y);
555 }
f03fc89f
VZ
556
557 // misc
558 // ----
559
560 void UpdateWindowUI();
561
a1665b22
VZ
562 bool PopupMenu( wxMenu *menu, const wxPoint& pos )
563 { return DoPopupMenu(menu, pos.x, pos.y); }
564 bool PopupMenu( wxMenu *menu, int x, int y )
565 { return DoPopupMenu(menu, x, y); }
f03fc89f
VZ
566
567 // scrollbars
568 // ----------
569
570 // configure the window scrollbars
571 virtual void SetScrollbar( int orient,
572 int pos,
573 int thumbVisible,
574 int range,
575 bool refresh = TRUE ) = 0;
576 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0;
577 virtual int GetScrollPos( int orient ) const = 0;
578 virtual int GetScrollThumb( int orient ) const = 0;
579 virtual int GetScrollRange( int orient ) const = 0;
580
581 // scroll window to the specified position
582 virtual void ScrollWindow( int dx, int dy,
583 const wxRect* rect = (wxRect *) NULL ) = 0;
584
bd83cb56
VZ
585 // context-sensitive help
586 // ----------------------
587
588 // these are the convenience functions wrapping wxHelpProvider methods
589
590#if wxUSE_HELP
591 // associate this help text with this window
592 void SetHelpText(const wxString& text);
593 // associate this help text with all windows with the same id as this
594 // one
595 void SetHelpTextForId(const wxString& text);
596 // get the help string associated with this window (may be empty)
597 wxString GetHelpText() const;
598#endif // wxUSE_HELP
599
f03fc89f
VZ
600 // tooltips
601 // --------
bd83cb56 602
f03fc89f
VZ
603#if wxUSE_TOOLTIPS
604 // the easiest way to set a tooltip for a window is to use this method
605 void SetToolTip( const wxString &tip );
606 // attach a tooltip to the window
607 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
608 // get the associated tooltip or NULL if none
609 wxToolTip* GetToolTip() const { return m_tooltip; }
610#endif // wxUSE_TOOLTIPS
611
612 // drag and drop
613 // -------------
614#if wxUSE_DRAG_AND_DROP
615 // set/retrieve the drop target associated with this window (may be
616 // NULL; it's owned by the window and will be deleted by it)
617 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
618 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
619#endif // wxUSE_DRAG_AND_DROP
620
621 // constraints and sizers
622 // ----------------------
623#if wxUSE_CONSTRAINTS
624 // set the constraints for this window or retrieve them (may be NULL)
625 void SetConstraints( wxLayoutConstraints *constraints );
626 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
627
628 // when using constraints, it makes sense to update children positions
629 // automatically whenever the window is resized - this is done if
630 // autoLayout is on
631 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
632 bool GetAutoLayout() const { return m_autoLayout; }
633
634 // do layout the window and its children
635 virtual bool Layout();
636
637 // implementation only
638 void UnsetConstraints(wxLayoutConstraints *c);
639 wxWindowList *GetConstraintsInvolvedIn() const
640 { return m_constraintsInvolvedIn; }
641 void AddConstraintReference(wxWindowBase *otherWin);
642 void RemoveConstraintReference(wxWindowBase *otherWin);
643 void DeleteRelatedConstraints();
644 void ResetConstraints();
645
646 // these methods may be overriden for special layout algorithms
647 virtual void SetConstraintSizes(bool recurse = TRUE);
648 virtual bool LayoutPhase1(int *noChanges);
649 virtual bool LayoutPhase2(int *noChanges);
4b7f2165 650 virtual bool DoPhase(int phase);
f03fc89f
VZ
651
652 // these methods are virtual but normally won't be overridden
f03fc89f
VZ
653 virtual void SetSizeConstraint(int x, int y, int w, int h);
654 virtual void MoveConstraint(int x, int y);
655 virtual void GetSizeConstraint(int *w, int *h) const ;
656 virtual void GetClientSizeConstraint(int *w, int *h) const ;
657 virtual void GetPositionConstraint(int *x, int *y) const ;
658
659 // sizers
660 // TODO: what are they and how do they work??
661 void SetSizer( wxSizer *sizer );
662 wxSizer *GetSizer() const { return m_windowSizer; }
f03fc89f
VZ
663#endif // wxUSE_CONSTRAINTS
664
665 // backward compatibility
666 // ----------------------
667#if WXWIN_COMPATIBILITY
668 bool Enabled() const { return IsEnabled(); }
669
670 void SetButtonFont(const wxFont& font) { SetFont(font); }
671 void SetLabelFont(const wxFont& font) { SetFont(font); }
672 wxFont& GetLabelFont() { return GetFont(); };
673 wxFont& GetButtonFont() { return GetFont(); };
674#endif // WXWIN_COMPATIBILITY
675
676 // implementation
677 // --------------
678
679 // event handlers
680 void OnSysColourChanged( wxSysColourChangedEvent& event );
681 void OnInitDialog( wxInitDialogEvent &event );
72fc5caf 682 void OnMiddleClick( wxMouseEvent& event );
bd83cb56
VZ
683#if wxUSE_HELP
684 void OnHelp(wxHelpEvent& event);
685#endif // wxUSE_HELP
f03fc89f 686
d7c24517
VZ
687 // get the haqndle of the window for the underlying window system: this
688 // is only used for wxWin itself or for user code which wants to call
689 // platform-specific APIs
d22699b5 690 virtual WXWidget GetHandle() const = 0;
cc2b7472 691
739730ca 692protected:
7af6f327 693 // the window id - a number which uniquely identifies a window among
d7c24517 694 // its siblings unless it is -1
f03fc89f
VZ
695 wxWindowID m_windowId;
696
697 // the parent window of this window (or NULL) and the list of the children
698 // of this window
699 wxWindow *m_parent;
700 wxWindowList m_children;
701
702 // the minimal allowed size for the window (no minimal size if variable(s)
703 // contain(s) -1)
704 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
705
706 // event handler for this window: usually is just 'this' but may be
707 // changed with SetEventHandler()
708 wxEvtHandler *m_eventHandler;
709
88ac883a 710#if wxUSE_VALIDATORS
f03fc89f
VZ
711 // associated validator or NULL if none
712 wxValidator *m_windowValidator;
88ac883a 713#endif // wxUSE_VALIDATORS
f03fc89f
VZ
714
715#if wxUSE_DRAG_AND_DROP
716 wxDropTarget *m_dropTarget;
717#endif // wxUSE_DRAG_AND_DROP
718
719 // visual window attributes
720 wxCursor m_cursor;
721 wxFont m_font;
722 wxColour m_backgroundColour, m_foregroundColour;
723
789295bf
VZ
724#if wxUSE_CARET
725 wxCaret *m_caret;
726#endif // wxUSE_CARET
727
f03fc89f
VZ
728 // the region which should be repainted in response to paint event
729 wxRegion m_updateRegion;
730
88ac883a 731#if wxUSE_ACCEL
f03fc89f
VZ
732 // the accelerator table for the window which translates key strokes into
733 // command events
734 wxAcceleratorTable m_acceleratorTable;
88ac883a 735#endif // wxUSE_ACCEL
f03fc89f
VZ
736
737 // user data associated with the window: either an object which will be
738 // deleted by the window when it's deleted or some raw pointer which we do
8d99be5f
VZ
739 // nothing with - only one type of data can be used with the given window
740 // (i.e. you cannot set the void data and then associate the window with
741 // wxClientData or vice versa)
742 union
743 {
744 wxClientData *m_clientObject;
745 void *m_clientData;
746 };
f03fc89f
VZ
747
748 // the tooltip for this window (may be NULL)
749#if wxUSE_TOOLTIPS
750 wxToolTip *m_tooltip;
751#endif // wxUSE_TOOLTIPS
752
753 // constraints and sizers
754#if wxUSE_CONSTRAINTS
755 // the constraints for this window or NULL
756 wxLayoutConstraints *m_constraints;
757
758 // constraints this window is involved in
759 wxWindowList *m_constraintsInvolvedIn;
760
761 // top level and the parent sizers
762 // TODO what's this and how does it work?)
763 wxSizer *m_windowSizer;
764 wxWindowBase *m_sizerParent;
765
766 // Layout() window automatically when its size changes?
767 bool m_autoLayout:1;
768#endif // wxUSE_CONSTRAINTS
769
770 // window state
771 bool m_isShown:1;
772 bool m_isEnabled:1;
773 bool m_isBeingDeleted:1;
774
775 // window attributes
d80cd92a
VZ
776 long m_windowStyle,
777 m_exStyle;
f03fc89f 778 wxString m_windowName;
a2d93e73 779 bool m_themeEnabled;
f03fc89f
VZ
780
781protected:
782 // common part of all ctors: it is not virtual because it is called from
783 // ctor
784 void InitBase();
785
786 // get the default size for the new window if no explicit size given
787 // FIXME why 20 and not 30, 10 or ...?
788 static int WidthDefault(int w) { return w == -1 ? 20 : w; }
789 static int HeightDefault(int h) { return h == -1 ? 20 : h; }
790
f68586e5
VZ
791 // sets the size to be size but take width and/or height from
792 // DoGetBestSize() if width/height of size is -1
793 //
794 // NB: when calling this function from the ctor, the DoGetBestSize() of
795 // the class with the same name as the ctor, not the real (most
796 // derived) one - but this is what we usually want
797 void SetSizeOrDefault(const wxSize& size = wxDefaultSize)
798 {
799 if ( size.x == -1 || size.y == -1 )
800 {
801 wxSize sizeDef = GetBestSize();
802 SetSize( size.x == -1 ? sizeDef.x : size.x,
803 size.y == -1 ? sizeDef.y : size.y);
804 }
805 else
806 {
807 SetSize(size);
808 }
809 }
810
f03fc89f
VZ
811 // more pure virtual functions
812 // ---------------------------
813
814 // NB: we must have DoSomething() function when Something() is an overloaded
815 // method: indeed, we can't just have "virtual Something()" in case when
816 // the function is overloaded because then we'd have to make virtual all
817 // the variants (otherwise only the virtual function may be called on a
818 // pointer to derived class according to C++ rules) which is, in
819 // general, absolutely not needed. So instead we implement all
820 // overloaded Something()s in terms of DoSomething() which will be the
821 // only one to be virtual.
822
dabc0cd5
VZ
823 // coordinates translation
824 virtual void DoClientToScreen( int *x, int *y ) const = 0;
825 virtual void DoScreenToClient( int *x, int *y ) const = 0;
826
f03fc89f
VZ
827 // retrieve the position/size of the window
828 virtual void DoGetPosition( int *x, int *y ) const = 0;
829 virtual void DoGetSize( int *width, int *height ) const = 0;
830 virtual void DoGetClientSize( int *width, int *height ) const = 0;
831
f68586e5
VZ
832 // get the size which best suits the window: for a control, it would be
833 // the minimal size which doesn't truncate the control, for a panel - the
834 // same size as it would have after a call to Fit()
835 virtual wxSize DoGetBestSize() const;
836
f03fc89f
VZ
837 // this is the virtual function to be overriden in any derived class which
838 // wants to change how SetSize() or Move() works - it is called by all
839 // versions of these functions in the base class
840 virtual void DoSetSize(int x, int y,
841 int width, int height,
842 int sizeFlags = wxSIZE_AUTO) = 0;
843
844 // same as DoSetSize() for the client size
845 virtual void DoSetClientSize(int width, int height) = 0;
846
9d9b7755
VZ
847 // move the window to the specified location and resize it: this is called
848 // from both DoSetSize() and DoSetClientSize() and would usually just
849 // reposition this window except for composite controls which will want to
850 // arrange themselves inside the given rectangle
851 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
852
f03fc89f
VZ
853#if wxUSE_TOOLTIPS
854 virtual void DoSetToolTip( wxToolTip *tip );
855#endif // wxUSE_TOOLTIPS
856
a1665b22
VZ
857 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
858
8d99be5f
VZ
859 // client data accessors
860 virtual void DoSetClientObject( wxClientData *data );
861 virtual wxClientData *DoGetClientObject() const;
862
863 virtual void DoSetClientData( void *data );
864 virtual void *DoGetClientData() const;
865
866 // what kind of data do we have?
867 enum wxClientDataType
868 {
869 ClientData_None, // we don't know yet because we don't have it at all
870 ClientData_Object, // our client data is typed and we own it
871 ClientData_Void // client data is untyped and we don't own it
872 } m_clientDataType;
873
f03fc89f
VZ
874private:
875 // contains the last id generated by NewControlId
876 static int ms_lastControlId;
877
a23fd0e1 878 DECLARE_NO_COPY_CLASS(wxWindowBase);
f03fc89f
VZ
879 DECLARE_EVENT_TABLE()
880};
881
882// ----------------------------------------------------------------------------
883// now include the declaration of wxWindow class
884// ----------------------------------------------------------------------------
885
2049ba38 886#if defined(__WXMSW__)
f03fc89f 887 #include "wx/msw/window.h"
2049ba38 888#elif defined(__WXMOTIF__)
f03fc89f 889 #include "wx/motif/window.h"
2049ba38 890#elif defined(__WXGTK__)
f03fc89f 891 #include "wx/gtk/window.h"
b4e76e0d 892#elif defined(__WXQT__)
f03fc89f 893 #include "wx/qt/window.h"
34138703 894#elif defined(__WXMAC__)
f03fc89f 895 #include "wx/mac/window.h"
1777b9bb
DW
896#elif defined(__WXPM__)
897 #include "wx/os2/window.h"
c801d85f
KB
898#endif
899
f03fc89f
VZ
900// ----------------------------------------------------------------------------
901// inline functions which couldn't be declared in the class body because of
902// forward dependencies
903// ----------------------------------------------------------------------------
904
bacd69f9 905inline wxWindow *wxWindowBase::GetGrandParent() const
f03fc89f
VZ
906{
907 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
908}
909
910// ----------------------------------------------------------------------------
3723b7b1 911// global functions
f03fc89f
VZ
912// ----------------------------------------------------------------------------
913
7af6f327 914WXDLLEXPORT extern wxWindow* wxGetActiveWindow();
f68586e5 915
3723b7b1
JS
916// Find the wxWindow at the current mouse position, also returning the mouse
917// position.
918WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt);
919
920// Get the current mouse position.
921WXDLLEXPORT extern wxPoint wxGetMousePosition();
922
f68586e5 923// deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
7af6f327 924inline WXDLLEXPORT int NewControlId() { return wxWindowBase::NewControlId(); }
f03fc89f 925
c801d85f 926#endif
34138703 927 // _WX_WINDOW_H_BASE_