]> git.saurik.com Git - wxWidgets.git/blame - include/wx/window.h
Minor additions to make working with binary buffers easier.
[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
61WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode);
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
f03fc89f 274 // centre with respect to the the parent window
c39eda94
VZ
275 void Centre( int direction = wxBOTH );
276 void Center( int direction = wxBOTH ) { Centre(direction); }
277 void CentreOnParent( int dir = wxBOTH ) { Centre(dir | wxCENTER_FRAME); }
278 void CenterOnParent( int dir = wxBOTH ) { Centre(dir | wxCENTER_FRAME); }
f03fc89f
VZ
279
280 // set window size to wrap around its children
281 virtual void Fit();
282
283 // set min/max size of the window
284 virtual void SetSizeHints( int minW, int minH,
285 int maxW = -1, int maxH = -1,
286 int incW = -1, int incH = -1 );
287
738f9e5a
RR
288 int GetMinWidth() const { return m_minWidth; }
289 int GetMinHeight() const { return m_minHeight; }
290 int GetMaxWidth() const { return m_maxWidth; }
291 int GetMaxHeight() const { return m_maxHeight; }
57c4d796 292
f03fc89f
VZ
293 // window state
294 // ------------
295
296 // returns TRUE if window was shown/hidden, FALSE if the nothing was
297 // done (window was already shown/hidden)
298 virtual bool Show( bool show = TRUE );
299 bool Hide() { return Show(FALSE); }
300
301 // returns TRUE if window was enabled/disabled, FALSE if nothing done
302 virtual bool Enable( bool enable = TRUE );
303 bool Disable() { return Enable(FALSE); }
304
305 bool IsShown() const { return m_isShown; }
306 bool IsEnabled() const { return m_isEnabled; }
307
308 // get/set window style (setting style won't update the window and so
309 // is only useful for internal usage)
310 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
311 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
312
313 // just some (somewhat shorter) synonims
314 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
315 long GetWindowStyle() const { return GetWindowStyleFlag(); }
316
317 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
d80cd92a 318 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
f03fc89f 319
d80cd92a
VZ
320 // extra style: the less often used style bits which can't be set with
321 // SetWindowStyleFlag()
322 void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
323 long GetExtraStyle() const { return m_exStyle; }
f03fc89f
VZ
324
325 // make the window modal (all other windows unresponsive)
326 virtual void MakeModal(bool modal = TRUE);
327
328 // focus handling
329 // --------------
330
331 // set focus to this window
332 virtual void SetFocus() = 0;
333
334 // return the window which currently has the focus or NULL
335 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
336
337 // can this window have focus?
338 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
339
340 // parent/children relations
341 // -------------------------
342
343 // get the list of children
344 const wxWindowList& GetChildren() const { return m_children; }
345 wxWindowList& GetChildren() { return m_children; }
346
347 // get the parent or the parent of the parent
348 wxWindow *GetParent() const { return m_parent; }
349 inline wxWindow *GetGrandParent() const;
350
351 // is this window a top level one?
8487f887 352 virtual bool IsTopLevel() const;
f03fc89f
VZ
353
354 // it doesn't really change parent, use ReParent() instead
355 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
356 // change the real parent of this window, return TRUE if the parent
357 // was changed, FALSE otherwise (error or newParent == oldParent)
358 virtual bool Reparent( wxWindowBase *newParent );
359
360 // find window among the descendants of this one either by id or by
361 // name (return NULL if not found)
362 wxWindow *FindWindow( long id );
363 wxWindow *FindWindow( const wxString& name );
364
365 // implementation mostly
366 virtual void AddChild( wxWindowBase *child );
367 virtual void RemoveChild( wxWindowBase *child );
368
369 // event handler stuff
370 // -------------------
371
372 // get the current event handler
373 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
374
375 // replace the event handler (allows to completely subclass the
376 // window)
377 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
378
379 // push/pop event handler: allows to chain a custom event handler to
380 // alreasy existing ones
381 void PushEventHandler( wxEvtHandler *handler );
382 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
383
384 // validators and client data
385 // --------------------------
386
88ac883a 387#if wxUSE_VALIDATORS
f03fc89f
VZ
388 // a window may have an associated validator which is used to control
389 // user input
390 virtual void SetValidator( const wxValidator &validator );
391 virtual wxValidator *GetValidator() { return m_windowValidator; }
88ac883a 392#endif // wxUSE_VALIDATORS
f03fc89f
VZ
393
394 // each window may have associated client data: either a pointer to
395 // wxClientData object in which case it is managed by the window (i.e.
396 // it will delete the data when it's destroyed) or an untyped pointer
8d99be5f
VZ
397 // which won't be deleted by the window - but not both of them
398 void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
399 wxClientData *GetClientObject() const { return DoGetClientObject(); }
f03fc89f 400
8d99be5f
VZ
401 void SetClientData( void *data ) { DoSetClientData(data); }
402 void *GetClientData() const { return DoGetClientData(); }
f03fc89f
VZ
403
404 // dialog oriented functions
405 // -------------------------
406
407 // validate the correctness of input, return TRUE if ok
408 virtual bool Validate();
409
410 // transfer data between internal and GUI representations
411 virtual bool TransferDataToWindow();
412 virtual bool TransferDataFromWindow();
413
414 virtual void InitDialog();
415
88ac883a 416#if wxUSE_ACCEL
f03fc89f
VZ
417 // accelerators
418 // ------------
419 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
420 { m_acceleratorTable = accel; }
421 wxAcceleratorTable *GetAcceleratorTable()
422 { return &m_acceleratorTable; }
88ac883a 423#endif // wxUSE_ACCEL
f03fc89f
VZ
424
425 // dialog units translations
426 // -------------------------
427
428 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
429 wxPoint ConvertDialogToPixels( const wxPoint& pt );
430 wxSize ConvertPixelsToDialog( const wxSize& sz )
431 {
432 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
433
434 return wxSize(pt.x, pt.y);
435 }
436
437 wxSize ConvertDialogToPixels( const wxSize& sz )
438 {
439 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
440
441 return wxSize(pt.x, pt.y);
442 }
443
444 // mouse functions
445 // ---------------
446
447 // move the mouse to the specified position
448 virtual void WarpPointer(int x, int y) = 0;
449
450 // start or end mouse capture
451 virtual void CaptureMouse() = 0;
452 virtual void ReleaseMouse() = 0;
453
454 // painting the window
455 // -------------------
456
457 // mark the specified rectangle (or the whole window) as "dirty" so it
458 // will be repainted
459 virtual void Refresh( bool eraseBackground = TRUE,
460 const wxRect *rect = (const wxRect *) NULL ) = 0;
461 // clear the window entirely
462 virtual void Clear() = 0;
463
464 // adjust DC for drawing on this window
f6147cfc 465 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
f03fc89f
VZ
466
467 // the update region of the window contains the areas which must be
468 // repainted by the program
469 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
470 wxRegion& GetUpdateRegion() { return m_updateRegion; }
471
472 // these functions verify whether the given point/rectangle belongs to
473 // (or at least intersects with) the update region
474 bool IsExposed( int x, int y ) const;
475 bool IsExposed( int x, int y, int w, int h ) const;
476
477 bool IsExposed( const wxPoint& pt ) const
478 { return IsExposed(pt.x, pt.y); }
479 bool IsExposed( const wxRect& rect ) const
480 { return IsExposed(rect.x, rect.y, rect.width, rect.height); }
481
482 // colours, fonts and cursors
483 // --------------------------
484
485 // set/retrieve the window colours (system defaults are used by
486 // default): Set functions return TRUE if colour was changed
487 virtual bool SetBackgroundColour( const wxColour &colour );
488 virtual bool SetForegroundColour( const wxColour &colour );
489
490 wxColour GetBackgroundColour() const { return m_backgroundColour; }
491 wxColour GetForegroundColour() const { return m_foregroundColour; }
492
493 // set/retrieve the cursor for this window (SetCursor() returns TRUE
494 // if the cursor was really changed)
495 virtual bool SetCursor( const wxCursor &cursor );
496 const wxCursor& GetCursor() const { return m_cursor; }
497 wxCursor& GetCursor() { return m_cursor; }
498
499 // set/retrieve the font for the window (SetFont() returns TRUE if the
500 // font really changed)
501 virtual bool SetFont( const wxFont &font ) = 0;
502 const wxFont& GetFont() const { return m_font; }
503 wxFont& GetFont() { return m_font; }
504
789295bf
VZ
505#if wxUSE_CARET
506 // associate a caret with the window
507 void SetCaret(wxCaret *caret);
508 // get the current caret (may be NULL)
509 wxCaret *GetCaret() const { return m_caret; }
510#endif // wxUSE_CARET
511
f03fc89f
VZ
512 // get the (average) character size for the current font
513 virtual int GetCharHeight() const = 0;
514 virtual int GetCharWidth() const = 0;
515
516 // get the width/height/... of the text using current or specified
517 // font
518 virtual void GetTextExtent(const wxString& string,
519 int *x, int *y,
520 int *descent = (int *) NULL,
521 int *externalLeading = (int *) NULL,
522 const wxFont *theFont = (const wxFont *) NULL)
523 const = 0;
524
525 // translate to/from screen/client coordinates (pointers may be NULL)
dabc0cd5
VZ
526 void ClientToScreen( int *x, int *y ) const
527 { DoClientToScreen(x, y); }
528 void ScreenToClient( int *x, int *y ) const
529 { DoScreenToClient(x, y); }
530 wxPoint ClientToScreen(const wxPoint& pt) const
531 {
532 int x = pt.x, y = pt.y;
533 DoClientToScreen(&x, &y);
534
535 return wxPoint(x, y);
536 }
537
538 wxPoint ScreenToClient(const wxPoint& pt) const
539 {
540 int x = pt.x, y = pt.y;
541 DoScreenToClient(&x, &y);
542
543 return wxPoint(x, y);
544 }
f03fc89f
VZ
545
546 // misc
547 // ----
548
549 void UpdateWindowUI();
550
a1665b22
VZ
551 bool PopupMenu( wxMenu *menu, const wxPoint& pos )
552 { return DoPopupMenu(menu, pos.x, pos.y); }
553 bool PopupMenu( wxMenu *menu, int x, int y )
554 { return DoPopupMenu(menu, x, y); }
f03fc89f
VZ
555
556 // scrollbars
557 // ----------
558
559 // configure the window scrollbars
560 virtual void SetScrollbar( int orient,
561 int pos,
562 int thumbVisible,
563 int range,
564 bool refresh = TRUE ) = 0;
565 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0;
566 virtual int GetScrollPos( int orient ) const = 0;
567 virtual int GetScrollThumb( int orient ) const = 0;
568 virtual int GetScrollRange( int orient ) const = 0;
569
570 // scroll window to the specified position
571 virtual void ScrollWindow( int dx, int dy,
572 const wxRect* rect = (wxRect *) NULL ) = 0;
573
574 // tooltips
575 // --------
576#if wxUSE_TOOLTIPS
577 // the easiest way to set a tooltip for a window is to use this method
578 void SetToolTip( const wxString &tip );
579 // attach a tooltip to the window
580 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
581 // get the associated tooltip or NULL if none
582 wxToolTip* GetToolTip() const { return m_tooltip; }
583#endif // wxUSE_TOOLTIPS
584
585 // drag and drop
586 // -------------
587#if wxUSE_DRAG_AND_DROP
588 // set/retrieve the drop target associated with this window (may be
589 // NULL; it's owned by the window and will be deleted by it)
590 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
591 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
592#endif // wxUSE_DRAG_AND_DROP
593
594 // constraints and sizers
595 // ----------------------
596#if wxUSE_CONSTRAINTS
597 // set the constraints for this window or retrieve them (may be NULL)
598 void SetConstraints( wxLayoutConstraints *constraints );
599 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
600
601 // when using constraints, it makes sense to update children positions
602 // automatically whenever the window is resized - this is done if
603 // autoLayout is on
604 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
605 bool GetAutoLayout() const { return m_autoLayout; }
606
607 // do layout the window and its children
608 virtual bool Layout();
609
610 // implementation only
611 void UnsetConstraints(wxLayoutConstraints *c);
612 wxWindowList *GetConstraintsInvolvedIn() const
613 { return m_constraintsInvolvedIn; }
614 void AddConstraintReference(wxWindowBase *otherWin);
615 void RemoveConstraintReference(wxWindowBase *otherWin);
616 void DeleteRelatedConstraints();
617 void ResetConstraints();
618
619 // these methods may be overriden for special layout algorithms
620 virtual void SetConstraintSizes(bool recurse = TRUE);
621 virtual bool LayoutPhase1(int *noChanges);
622 virtual bool LayoutPhase2(int *noChanges);
4b7f2165 623 virtual bool DoPhase(int phase);
f03fc89f
VZ
624
625 // these methods are virtual but normally won't be overridden
f03fc89f
VZ
626 virtual void SetSizeConstraint(int x, int y, int w, int h);
627 virtual void MoveConstraint(int x, int y);
628 virtual void GetSizeConstraint(int *w, int *h) const ;
629 virtual void GetClientSizeConstraint(int *w, int *h) const ;
630 virtual void GetPositionConstraint(int *x, int *y) const ;
631
632 // sizers
633 // TODO: what are they and how do they work??
634 void SetSizer( wxSizer *sizer );
635 wxSizer *GetSizer() const { return m_windowSizer; }
f03fc89f
VZ
636#endif // wxUSE_CONSTRAINTS
637
638 // backward compatibility
639 // ----------------------
640#if WXWIN_COMPATIBILITY
641 bool Enabled() const { return IsEnabled(); }
642
643 void SetButtonFont(const wxFont& font) { SetFont(font); }
644 void SetLabelFont(const wxFont& font) { SetFont(font); }
645 wxFont& GetLabelFont() { return GetFont(); };
646 wxFont& GetButtonFont() { return GetFont(); };
647#endif // WXWIN_COMPATIBILITY
648
649 // implementation
650 // --------------
651
652 // event handlers
653 void OnSysColourChanged( wxSysColourChangedEvent& event );
654 void OnInitDialog( wxInitDialogEvent &event );
72fc5caf 655 void OnMiddleClick( wxMouseEvent& event );
f03fc89f 656
d7c24517
VZ
657 // get the haqndle of the window for the underlying window system: this
658 // is only used for wxWin itself or for user code which wants to call
659 // platform-specific APIs
d22699b5 660 virtual WXWidget GetHandle() const = 0;
cc2b7472 661
739730ca 662protected:
7af6f327 663 // the window id - a number which uniquely identifies a window among
d7c24517 664 // its siblings unless it is -1
f03fc89f
VZ
665 wxWindowID m_windowId;
666
667 // the parent window of this window (or NULL) and the list of the children
668 // of this window
669 wxWindow *m_parent;
670 wxWindowList m_children;
671
672 // the minimal allowed size for the window (no minimal size if variable(s)
673 // contain(s) -1)
674 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
675
676 // event handler for this window: usually is just 'this' but may be
677 // changed with SetEventHandler()
678 wxEvtHandler *m_eventHandler;
679
88ac883a 680#if wxUSE_VALIDATORS
f03fc89f
VZ
681 // associated validator or NULL if none
682 wxValidator *m_windowValidator;
88ac883a 683#endif // wxUSE_VALIDATORS
f03fc89f
VZ
684
685#if wxUSE_DRAG_AND_DROP
686 wxDropTarget *m_dropTarget;
687#endif // wxUSE_DRAG_AND_DROP
688
689 // visual window attributes
690 wxCursor m_cursor;
691 wxFont m_font;
692 wxColour m_backgroundColour, m_foregroundColour;
693
789295bf
VZ
694#if wxUSE_CARET
695 wxCaret *m_caret;
696#endif // wxUSE_CARET
697
f03fc89f
VZ
698 // the region which should be repainted in response to paint event
699 wxRegion m_updateRegion;
700
88ac883a 701#if wxUSE_ACCEL
f03fc89f
VZ
702 // the accelerator table for the window which translates key strokes into
703 // command events
704 wxAcceleratorTable m_acceleratorTable;
88ac883a 705#endif // wxUSE_ACCEL
f03fc89f
VZ
706
707 // user data associated with the window: either an object which will be
708 // deleted by the window when it's deleted or some raw pointer which we do
8d99be5f
VZ
709 // nothing with - only one type of data can be used with the given window
710 // (i.e. you cannot set the void data and then associate the window with
711 // wxClientData or vice versa)
712 union
713 {
714 wxClientData *m_clientObject;
715 void *m_clientData;
716 };
f03fc89f
VZ
717
718 // the tooltip for this window (may be NULL)
719#if wxUSE_TOOLTIPS
720 wxToolTip *m_tooltip;
721#endif // wxUSE_TOOLTIPS
722
723 // constraints and sizers
724#if wxUSE_CONSTRAINTS
725 // the constraints for this window or NULL
726 wxLayoutConstraints *m_constraints;
727
728 // constraints this window is involved in
729 wxWindowList *m_constraintsInvolvedIn;
730
731 // top level and the parent sizers
732 // TODO what's this and how does it work?)
733 wxSizer *m_windowSizer;
734 wxWindowBase *m_sizerParent;
735
736 // Layout() window automatically when its size changes?
737 bool m_autoLayout:1;
738#endif // wxUSE_CONSTRAINTS
739
740 // window state
741 bool m_isShown:1;
742 bool m_isEnabled:1;
743 bool m_isBeingDeleted:1;
744
745 // window attributes
d80cd92a
VZ
746 long m_windowStyle,
747 m_exStyle;
f03fc89f
VZ
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
9d9b7755
VZ
816 // move the window to the specified location and resize it: this is called
817 // from both DoSetSize() and DoSetClientSize() and would usually just
818 // reposition this window except for composite controls which will want to
819 // arrange themselves inside the given rectangle
820 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
821
f03fc89f
VZ
822#if wxUSE_TOOLTIPS
823 virtual void DoSetToolTip( wxToolTip *tip );
824#endif // wxUSE_TOOLTIPS
825
a1665b22
VZ
826 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
827
8d99be5f
VZ
828 // client data accessors
829 virtual void DoSetClientObject( wxClientData *data );
830 virtual wxClientData *DoGetClientObject() const;
831
832 virtual void DoSetClientData( void *data );
833 virtual void *DoGetClientData() const;
834
835 // what kind of data do we have?
836 enum wxClientDataType
837 {
838 ClientData_None, // we don't know yet because we don't have it at all
839 ClientData_Object, // our client data is typed and we own it
840 ClientData_Void // client data is untyped and we don't own it
841 } m_clientDataType;
842
f03fc89f
VZ
843private:
844 // contains the last id generated by NewControlId
845 static int ms_lastControlId;
846
a23fd0e1 847 DECLARE_NO_COPY_CLASS(wxWindowBase);
f03fc89f
VZ
848 DECLARE_EVENT_TABLE()
849};
850
851// ----------------------------------------------------------------------------
852// now include the declaration of wxWindow class
853// ----------------------------------------------------------------------------
854
2049ba38 855#if defined(__WXMSW__)
f03fc89f 856 #include "wx/msw/window.h"
2049ba38 857#elif defined(__WXMOTIF__)
f03fc89f 858 #include "wx/motif/window.h"
2049ba38 859#elif defined(__WXGTK__)
f03fc89f 860 #include "wx/gtk/window.h"
b4e76e0d 861#elif defined(__WXQT__)
f03fc89f 862 #include "wx/qt/window.h"
34138703 863#elif defined(__WXMAC__)
f03fc89f 864 #include "wx/mac/window.h"
1777b9bb
DW
865#elif defined(__WXPM__)
866 #include "wx/os2/window.h"
c801d85f
KB
867#endif
868
f03fc89f
VZ
869// ----------------------------------------------------------------------------
870// inline functions which couldn't be declared in the class body because of
871// forward dependencies
872// ----------------------------------------------------------------------------
873
bacd69f9 874inline wxWindow *wxWindowBase::GetGrandParent() const
f03fc89f
VZ
875{
876 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
877}
878
879// ----------------------------------------------------------------------------
880// global function
881// ----------------------------------------------------------------------------
882
7af6f327 883WXDLLEXPORT extern wxWindow* wxGetActiveWindow();
f68586e5
VZ
884
885// deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
7af6f327 886inline WXDLLEXPORT int NewControlId() { return wxWindowBase::NewControlId(); }
f03fc89f 887
c801d85f 888#endif
34138703 889 // _WX_WINDOW_H_BASE_