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