]> git.saurik.com Git - wxWidgets.git/blame - include/wx/window.h
fixed multiple bugs in multiple selection wxCheckListBoxes
[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 4// Author: Vadim Zeitlin
566d84a7 5// Modified by: Ron Lee
f03fc89f
VZ
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 35#if wxUSE_PALETTE
d577d610
VZ
36 #include "wx/dcclient.h"
37 #include "wx/palette.h"
574c939e
KB
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
566d84a7
RL
296 virtual void SetVirtualSizeHints( int minW, int minH,
297 int maxW = -1, int maxH = -1 );
298
e7dda1ff
VS
299 virtual int GetMinWidth() const { return m_minWidth; }
300 virtual int GetMinHeight() const { return m_minHeight; }
738f9e5a
RR
301 int GetMaxWidth() const { return m_maxWidth; }
302 int GetMaxHeight() const { return m_maxHeight; }
57c4d796 303
34c3ffca
RL
304 // Override this method to control the values given to Sizers etc.
305 virtual wxSize GetMaxSize() const { return wxSize( m_maxWidth, m_maxHeight ); }
306
566d84a7
RL
307 // Methods for accessing the virtual size of a window. For most
308 // windows this is just the client area of the window, but for
309 // some like scrolled windows it is more or less independent of
310 // the screen window size. You may override the DoXXXVirtual
311 // methods below for classes where that is is the case.
312
313 void SetVirtualSize( const wxSize &size ) { DoSetVirtualSize( size.x, size.y ); }
314 void SetVirtualSize( int x, int y ) { DoSetVirtualSize( x, y ); }
315
316 wxSize GetVirtualSize() const { return DoGetVirtualSize(); }
317 void GetVirtualSize( int *x, int *y ) const
318 {
319 wxSize s( DoGetVirtualSize() );
320
321 if( x )
322 *x = s.GetWidth();
323 if( y )
324 *y = s.GetHeight();
325 }
326
327 // Override these methods for windows that have a virtual size
328 // independent of their client size. eg. the virtual area of a
329 // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
330
331 virtual void DoSetVirtualSize( int x, int y );
332 virtual wxSize DoGetVirtualSize() const; // { return m_virtualSize; }
333
f03fc89f
VZ
334 // window state
335 // ------------
336
337 // returns TRUE if window was shown/hidden, FALSE if the nothing was
338 // done (window was already shown/hidden)
339 virtual bool Show( bool show = TRUE );
340 bool Hide() { return Show(FALSE); }
341
342 // returns TRUE if window was enabled/disabled, FALSE if nothing done
343 virtual bool Enable( bool enable = TRUE );
344 bool Disable() { return Enable(FALSE); }
345
346 bool IsShown() const { return m_isShown; }
347 bool IsEnabled() const { return m_isEnabled; }
348
349 // get/set window style (setting style won't update the window and so
350 // is only useful for internal usage)
351 virtual void SetWindowStyleFlag( long style ) { m_windowStyle = style; }
352 virtual long GetWindowStyleFlag() const { return m_windowStyle; }
353
354 // just some (somewhat shorter) synonims
355 void SetWindowStyle( long style ) { SetWindowStyleFlag(style); }
356 long GetWindowStyle() const { return GetWindowStyleFlag(); }
357
358 bool HasFlag(int flag) const { return (m_windowStyle & flag) != 0; }
d80cd92a 359 virtual bool IsRetained() const { return HasFlag(wxRETAINED); }
f03fc89f 360
d80cd92a
VZ
361 // extra style: the less often used style bits which can't be set with
362 // SetWindowStyleFlag()
b2d5a7ee 363 virtual void SetExtraStyle(long exStyle) { m_exStyle = exStyle; }
d80cd92a 364 long GetExtraStyle() const { return m_exStyle; }
f03fc89f
VZ
365
366 // make the window modal (all other windows unresponsive)
367 virtual void MakeModal(bool modal = TRUE);
368
a2d93e73
JS
369 virtual void SetThemeEnabled(bool enableTheme) { m_themeEnabled = enableTheme; }
370 virtual bool GetThemeEnabled() const { return m_themeEnabled; }
371
456bc6d9
VZ
372 // focus and keyboard handling
373 // ---------------------------
f03fc89f
VZ
374
375 // set focus to this window
376 virtual void SetFocus() = 0;
377
d577d610
VZ
378 // set focus to this window as the result of a keyboard action
379 virtual void SetFocusFromKbd() { SetFocus(); }
380
f03fc89f
VZ
381 // return the window which currently has the focus or NULL
382 static wxWindow *FindFocus() /* = 0: implement in derived classes */;
383
384 // can this window have focus?
385 virtual bool AcceptsFocus() const { return IsShown() && IsEnabled(); }
386
1e6feb95
VZ
387 // can this window be given focus by keyboard navigation? if not, the
388 // only way to give it focus (provided it accepts it at all) is to
389 // click it
390 virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
391
456bc6d9
VZ
392 // NB: these methods really don't belong here but with the current
393 // class hierarchy there is no other place for them :-(
394
395 // get the default child of this parent, i.e. the one which is
396 // activated by pressing <Enter>
397 virtual wxWindow *GetDefaultItem() const { return NULL; }
398
399 // set this child as default, return the old default
400 virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child))
401 { return NULL; }
402
f03fc89f
VZ
403 // parent/children relations
404 // -------------------------
405
406 // get the list of children
407 const wxWindowList& GetChildren() const { return m_children; }
408 wxWindowList& GetChildren() { return m_children; }
409
410 // get the parent or the parent of the parent
411 wxWindow *GetParent() const { return m_parent; }
412 inline wxWindow *GetGrandParent() const;
413
414 // is this window a top level one?
8487f887 415 virtual bool IsTopLevel() const;
f03fc89f
VZ
416
417 // it doesn't really change parent, use ReParent() instead
418 void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
419 // change the real parent of this window, return TRUE if the parent
420 // was changed, FALSE otherwise (error or newParent == oldParent)
421 virtual bool Reparent( wxWindowBase *newParent );
422
423 // find window among the descendants of this one either by id or by
424 // name (return NULL if not found)
425 wxWindow *FindWindow( long id );
426 wxWindow *FindWindow( const wxString& name );
427
428 // implementation mostly
429 virtual void AddChild( wxWindowBase *child );
430 virtual void RemoveChild( wxWindowBase *child );
431
432 // event handler stuff
433 // -------------------
434
435 // get the current event handler
436 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
437
438 // replace the event handler (allows to completely subclass the
439 // window)
440 void SetEventHandler( wxEvtHandler *handler ) { m_eventHandler = handler; }
441
442 // push/pop event handler: allows to chain a custom event handler to
443 // alreasy existing ones
444 void PushEventHandler( wxEvtHandler *handler );
445 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
446
2e36d5cf
VZ
447 // find the given handler in the event handler chain and remove (but
448 // not delete) it from the event handler chain, return TRUE if it was
449 // found and FALSE otherwise (this also results in an assert failure so
450 // this function should only be called when the handler is supposed to
451 // be there)
452 bool RemoveEventHandler(wxEvtHandler *handler);
453
1e6feb95
VZ
454 // validators
455 // ----------
f03fc89f 456
88ac883a 457#if wxUSE_VALIDATORS
f03fc89f
VZ
458 // a window may have an associated validator which is used to control
459 // user input
460 virtual void SetValidator( const wxValidator &validator );
461 virtual wxValidator *GetValidator() { return m_windowValidator; }
88ac883a 462#endif // wxUSE_VALIDATORS
f03fc89f 463
f03fc89f
VZ
464
465 // dialog oriented functions
466 // -------------------------
467
468 // validate the correctness of input, return TRUE if ok
469 virtual bool Validate();
470
471 // transfer data between internal and GUI representations
472 virtual bool TransferDataToWindow();
473 virtual bool TransferDataFromWindow();
474
475 virtual void InitDialog();
476
88ac883a 477#if wxUSE_ACCEL
f03fc89f
VZ
478 // accelerators
479 // ------------
480 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel )
481 { m_acceleratorTable = accel; }
482 wxAcceleratorTable *GetAcceleratorTable()
483 { return &m_acceleratorTable; }
88ac883a 484#endif // wxUSE_ACCEL
f03fc89f
VZ
485
486 // dialog units translations
487 // -------------------------
488
489 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
490 wxPoint ConvertDialogToPixels( const wxPoint& pt );
491 wxSize ConvertPixelsToDialog( const wxSize& sz )
492 {
493 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
494
495 return wxSize(pt.x, pt.y);
496 }
497
498 wxSize ConvertDialogToPixels( const wxSize& sz )
499 {
500 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
501
502 return wxSize(pt.x, pt.y);
503 }
504
505 // mouse functions
506 // ---------------
507
508 // move the mouse to the specified position
509 virtual void WarpPointer(int x, int y) = 0;
510
94633ad9
VZ
511 // start or end mouse capture, these functions maintain the stack of
512 // windows having captured the mouse and after calling ReleaseMouse()
513 // the mouse is not released but returns to the window which had had
514 // captured it previously (if any)
515 void CaptureMouse();
516 void ReleaseMouse();
f03fc89f 517
1e6feb95
VZ
518 // get the window which currently captures the mouse or NULL
519 static wxWindow *GetCapture();
520
521 // does this window have the capture?
522 virtual bool HasCapture() const
523 { return (wxWindow *)this == GetCapture(); }
524
f03fc89f
VZ
525 // painting the window
526 // -------------------
527
528 // mark the specified rectangle (or the whole window) as "dirty" so it
529 // will be repainted
530 virtual void Refresh( bool eraseBackground = TRUE,
531 const wxRect *rect = (const wxRect *) NULL ) = 0;
1e6feb95
VZ
532
533 // a less awkward wrapper for Refresh
534 void RefreshRect(const wxRect& rect) { Refresh(TRUE, &rect); }
535
536 // repaint all invalid areas of the window immediately
537 virtual void Update() { }
538
f03fc89f
VZ
539 // clear the window entirely
540 virtual void Clear() = 0;
541
0cc7251e
VZ
542 // freeze the window: don't redraw it until it is thawed
543 virtual void Freeze() { }
544
545 // thaw the window: redraw it after it had been frozen
546 virtual void Thaw() { }
547
f03fc89f 548 // adjust DC for drawing on this window
f6147cfc 549 virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { }
f03fc89f
VZ
550
551 // the update region of the window contains the areas which must be
552 // repainted by the program
553 const wxRegion& GetUpdateRegion() const { return m_updateRegion; }
554 wxRegion& GetUpdateRegion() { return m_updateRegion; }
555
1e6feb95
VZ
556 // get the update rectangleregion bounding box in client coords
557 wxRect GetUpdateClientRect() const;
558
f03fc89f
VZ
559 // these functions verify whether the given point/rectangle belongs to
560 // (or at least intersects with) the update region
561 bool IsExposed( int x, int y ) const;
562 bool IsExposed( int x, int y, int w, int h ) const;
563
564 bool IsExposed( const wxPoint& pt ) const
565 { return IsExposed(pt.x, pt.y); }
566 bool IsExposed( const wxRect& rect ) const
567 { return IsExposed(rect.x, rect.y, rect.width, rect.height); }
568
569 // colours, fonts and cursors
570 // --------------------------
571
572 // set/retrieve the window colours (system defaults are used by
573 // default): Set functions return TRUE if colour was changed
574 virtual bool SetBackgroundColour( const wxColour &colour );
575 virtual bool SetForegroundColour( const wxColour &colour );
576
577 wxColour GetBackgroundColour() const { return m_backgroundColour; }
578 wxColour GetForegroundColour() const { return m_foregroundColour; }
579
580 // set/retrieve the cursor for this window (SetCursor() returns TRUE
581 // if the cursor was really changed)
582 virtual bool SetCursor( const wxCursor &cursor );
583 const wxCursor& GetCursor() const { return m_cursor; }
584 wxCursor& GetCursor() { return m_cursor; }
585
586 // set/retrieve the font for the window (SetFont() returns TRUE if the
587 // font really changed)
588 virtual bool SetFont( const wxFont &font ) = 0;
589 const wxFont& GetFont() const { return m_font; }
590 wxFont& GetFont() { return m_font; }
591
789295bf
VZ
592#if wxUSE_CARET
593 // associate a caret with the window
594 void SetCaret(wxCaret *caret);
595 // get the current caret (may be NULL)
596 wxCaret *GetCaret() const { return m_caret; }
597#endif // wxUSE_CARET
598
f03fc89f
VZ
599 // get the (average) character size for the current font
600 virtual int GetCharHeight() const = 0;
601 virtual int GetCharWidth() const = 0;
602
603 // get the width/height/... of the text using current or specified
604 // font
605 virtual void GetTextExtent(const wxString& string,
606 int *x, int *y,
607 int *descent = (int *) NULL,
608 int *externalLeading = (int *) NULL,
609 const wxFont *theFont = (const wxFont *) NULL)
610 const = 0;
611
1e6feb95
VZ
612 // client <-> screen coords
613 // ------------------------
614
f03fc89f 615 // translate to/from screen/client coordinates (pointers may be NULL)
dabc0cd5
VZ
616 void ClientToScreen( int *x, int *y ) const
617 { DoClientToScreen(x, y); }
618 void ScreenToClient( int *x, int *y ) const
619 { DoScreenToClient(x, y); }
1e6feb95
VZ
620
621 // wxPoint interface to do the same thing
dabc0cd5
VZ
622 wxPoint ClientToScreen(const wxPoint& pt) const
623 {
624 int x = pt.x, y = pt.y;
625 DoClientToScreen(&x, &y);
626
627 return wxPoint(x, y);
628 }
629
630 wxPoint ScreenToClient(const wxPoint& pt) const
631 {
632 int x = pt.x, y = pt.y;
633 DoScreenToClient(&x, &y);
634
635 return wxPoint(x, y);
636 }
f03fc89f 637
1e6feb95
VZ
638 // test where the given (in client coords) point lies
639 wxHitTest HitTest(wxCoord x, wxCoord y) const
640 { return DoHitTest(x, y); }
641
642 wxHitTest HitTest(const wxPoint& pt) const
643 { return DoHitTest(pt.x, pt.y); }
644
f03fc89f
VZ
645 // misc
646 // ----
647
1e6feb95
VZ
648 // get the window border style: uses the current style and falls back to
649 // the default style for this class otherwise (see GetDefaultBorder())
650 wxBorder GetBorder() const;
651
f03fc89f
VZ
652 void UpdateWindowUI();
653
1e6feb95 654#if wxUSE_MENUS
a1665b22
VZ
655 bool PopupMenu( wxMenu *menu, const wxPoint& pos )
656 { return DoPopupMenu(menu, pos.x, pos.y); }
657 bool PopupMenu( wxMenu *menu, int x, int y )
658 { return DoPopupMenu(menu, x, y); }
1e6feb95 659#endif // wxUSE_MENUS
f03fc89f
VZ
660
661 // scrollbars
662 // ----------
663
1e6feb95
VZ
664 // does the window have the scrollbar for this orientation?
665 bool HasScrollbar(int orient) const
666 {
667 return (m_windowStyle &
668 (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0;
669 }
670
f03fc89f
VZ
671 // configure the window scrollbars
672 virtual void SetScrollbar( int orient,
673 int pos,
1e6feb95 674 int thumbvisible,
f03fc89f
VZ
675 int range,
676 bool refresh = TRUE ) = 0;
677 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ) = 0;
678 virtual int GetScrollPos( int orient ) const = 0;
679 virtual int GetScrollThumb( int orient ) const = 0;
680 virtual int GetScrollRange( int orient ) const = 0;
681
682 // scroll window to the specified position
683 virtual void ScrollWindow( int dx, int dy,
684 const wxRect* rect = (wxRect *) NULL ) = 0;
685
b9b3393e 686 // scrolls window by line/page: note that not all controls support this
9cd6d737
VZ
687 //
688 // return TRUE if the position changed, FALSE otherwise
689 virtual bool ScrollLines(int WXUNUSED(lines)) { return FALSE; }
690 virtual bool ScrollPages(int WXUNUSED(pages)) { return FALSE; }
691
692 // convenient wrappers for ScrollLines/Pages
693 bool LineUp() { return ScrollLines(-1); }
694 bool LineDown() { return ScrollLines(1); }
695 bool PageUp() { return ScrollPages(-1); }
696 bool PageDown() { return ScrollPages(1); }
b9b3393e 697
bd83cb56
VZ
698 // context-sensitive help
699 // ----------------------
700
701 // these are the convenience functions wrapping wxHelpProvider methods
702
703#if wxUSE_HELP
704 // associate this help text with this window
705 void SetHelpText(const wxString& text);
706 // associate this help text with all windows with the same id as this
707 // one
708 void SetHelpTextForId(const wxString& text);
709 // get the help string associated with this window (may be empty)
710 wxString GetHelpText() const;
711#endif // wxUSE_HELP
712
f03fc89f
VZ
713 // tooltips
714 // --------
bd83cb56 715
f03fc89f
VZ
716#if wxUSE_TOOLTIPS
717 // the easiest way to set a tooltip for a window is to use this method
718 void SetToolTip( const wxString &tip );
719 // attach a tooltip to the window
720 void SetToolTip( wxToolTip *tip ) { DoSetToolTip(tip); }
721 // get the associated tooltip or NULL if none
722 wxToolTip* GetToolTip() const { return m_tooltip; }
723#endif // wxUSE_TOOLTIPS
724
725 // drag and drop
726 // -------------
727#if wxUSE_DRAG_AND_DROP
728 // set/retrieve the drop target associated with this window (may be
729 // NULL; it's owned by the window and will be deleted by it)
730 virtual void SetDropTarget( wxDropTarget *dropTarget ) = 0;
731 virtual wxDropTarget *GetDropTarget() const { return m_dropTarget; }
732#endif // wxUSE_DRAG_AND_DROP
733
734 // constraints and sizers
735 // ----------------------
736#if wxUSE_CONSTRAINTS
737 // set the constraints for this window or retrieve them (may be NULL)
738 void SetConstraints( wxLayoutConstraints *constraints );
739 wxLayoutConstraints *GetConstraints() const { return m_constraints; }
740
f03fc89f
VZ
741 // implementation only
742 void UnsetConstraints(wxLayoutConstraints *c);
743 wxWindowList *GetConstraintsInvolvedIn() const
744 { return m_constraintsInvolvedIn; }
745 void AddConstraintReference(wxWindowBase *otherWin);
746 void RemoveConstraintReference(wxWindowBase *otherWin);
747 void DeleteRelatedConstraints();
748 void ResetConstraints();
749
750 // these methods may be overriden for special layout algorithms
751 virtual void SetConstraintSizes(bool recurse = TRUE);
752 virtual bool LayoutPhase1(int *noChanges);
753 virtual bool LayoutPhase2(int *noChanges);
4b7f2165 754 virtual bool DoPhase(int phase);
f03fc89f
VZ
755
756 // these methods are virtual but normally won't be overridden
f03fc89f
VZ
757 virtual void SetSizeConstraint(int x, int y, int w, int h);
758 virtual void MoveConstraint(int x, int y);
759 virtual void GetSizeConstraint(int *w, int *h) const ;
760 virtual void GetClientSizeConstraint(int *w, int *h) const ;
761 virtual void GetPositionConstraint(int *x, int *y) const ;
762
461e93f9
JS
763#endif // wxUSE_CONSTRAINTS
764
765 // when using constraints or sizers, it makes sense to update
766 // children positions automatically whenever the window is resized
767 // - this is done if autoLayout is on
768 void SetAutoLayout( bool autoLayout ) { m_autoLayout = autoLayout; }
769 bool GetAutoLayout() const { return m_autoLayout; }
770
771 // lay out the window and its children
772 virtual bool Layout();
773
f03fc89f 774 // sizers
3aa5d532 775 void SetSizer(wxSizer *sizer, bool deleteOld = TRUE );
566d84a7
RL
776 void SetSizerAndFit( wxSizer *sizer, bool deleteOld = TRUE );
777
f03fc89f 778 wxSizer *GetSizer() const { return m_windowSizer; }
be90c029
RD
779
780 // Track if this window is a member of a sizer
781 void SetContainingSizer(wxSizer* sizer) { m_containingSizer = sizer; }
782 wxSizer *GetContainingSizer() const { return m_containingSizer; }
783
f03fc89f
VZ
784 // backward compatibility
785 // ----------------------
786#if WXWIN_COMPATIBILITY
787 bool Enabled() const { return IsEnabled(); }
788
789 void SetButtonFont(const wxFont& font) { SetFont(font); }
790 void SetLabelFont(const wxFont& font) { SetFont(font); }
791 wxFont& GetLabelFont() { return GetFont(); };
792 wxFont& GetButtonFont() { return GetFont(); };
793#endif // WXWIN_COMPATIBILITY
794
795 // implementation
796 // --------------
797
798 // event handlers
799 void OnSysColourChanged( wxSysColourChangedEvent& event );
800 void OnInitDialog( wxInitDialogEvent &event );
72fc5caf 801 void OnMiddleClick( wxMouseEvent& event );
bd83cb56
VZ
802#if wxUSE_HELP
803 void OnHelp(wxHelpEvent& event);
804#endif // wxUSE_HELP
f03fc89f 805
d7c24517
VZ
806 // get the haqndle of the window for the underlying window system: this
807 // is only used for wxWin itself or for user code which wants to call
808 // platform-specific APIs
d22699b5 809 virtual WXWidget GetHandle() const = 0;
cc2b7472 810
574c939e
KB
811#if wxUSE_PALETTE
812 // Store the palette used by DCs in wxWindow so that the dcs can share
813 // a palette. And we can respond to palette messages.
814 wxPalette GetPalette() const { return m_palette; }
b95edd47 815
574c939e
KB
816 // When palette is changed tell the DC to set the system palette to the
817 // new one.
b95edd47
VZ
818 void SetPalette(const wxPalette& pal);
819
820 // return true if we have a specific palette
821 bool HasCustomPalette() const { return m_hasCustomPalette; }
822
823 // return the first parent window with a custom palette or NULL
824 wxWindow *GetAncestorWithCustomPalette() const;
574c939e
KB
825#endif // wxUSE_PALETTE
826
739730ca 827protected:
566d84a7 828
7af6f327 829 // the window id - a number which uniquely identifies a window among
d7c24517 830 // its siblings unless it is -1
f03fc89f 831 wxWindowID m_windowId;
456bc6d9 832
f03fc89f
VZ
833 // the parent window of this window (or NULL) and the list of the children
834 // of this window
835 wxWindow *m_parent;
836 wxWindowList m_children;
837
838 // the minimal allowed size for the window (no minimal size if variable(s)
839 // contain(s) -1)
840 int m_minWidth, m_minHeight, m_maxWidth, m_maxHeight;
841
842 // event handler for this window: usually is just 'this' but may be
843 // changed with SetEventHandler()
844 wxEvtHandler *m_eventHandler;
845
88ac883a 846#if wxUSE_VALIDATORS
f03fc89f
VZ
847 // associated validator or NULL if none
848 wxValidator *m_windowValidator;
88ac883a 849#endif // wxUSE_VALIDATORS
f03fc89f
VZ
850
851#if wxUSE_DRAG_AND_DROP
852 wxDropTarget *m_dropTarget;
853#endif // wxUSE_DRAG_AND_DROP
854
855 // visual window attributes
856 wxCursor m_cursor;
857 wxFont m_font;
858 wxColour m_backgroundColour, m_foregroundColour;
859
789295bf
VZ
860#if wxUSE_CARET
861 wxCaret *m_caret;
862#endif // wxUSE_CARET
863
f03fc89f
VZ
864 // the region which should be repainted in response to paint event
865 wxRegion m_updateRegion;
866
88ac883a 867#if wxUSE_ACCEL
f03fc89f
VZ
868 // the accelerator table for the window which translates key strokes into
869 // command events
870 wxAcceleratorTable m_acceleratorTable;
88ac883a 871#endif // wxUSE_ACCEL
f03fc89f 872
f03fc89f
VZ
873 // the tooltip for this window (may be NULL)
874#if wxUSE_TOOLTIPS
875 wxToolTip *m_tooltip;
876#endif // wxUSE_TOOLTIPS
877
878 // constraints and sizers
879#if wxUSE_CONSTRAINTS
880 // the constraints for this window or NULL
881 wxLayoutConstraints *m_constraints;
882
883 // constraints this window is involved in
884 wxWindowList *m_constraintsInvolvedIn;
461e93f9 885#endif // wxUSE_CONSTRAINTS
f03fc89f 886
be90c029 887 // this window's sizer
f03fc89f 888 wxSizer *m_windowSizer;
be90c029
RD
889
890 // The sizer this window is a member of, if any
891 wxSizer *m_containingSizer;
f03fc89f
VZ
892
893 // Layout() window automatically when its size changes?
894 bool m_autoLayout:1;
f03fc89f
VZ
895
896 // window state
897 bool m_isShown:1;
898 bool m_isEnabled:1;
899 bool m_isBeingDeleted:1;
900
23895080
VZ
901 // was the window colours/font explicitly changed by user?
902 bool m_hasBgCol:1;
903 bool m_hasFgCol:1;
904 bool m_hasFont:1;
905
f03fc89f 906 // window attributes
d80cd92a
VZ
907 long m_windowStyle,
908 m_exStyle;
f03fc89f 909 wxString m_windowName;
a2d93e73 910 bool m_themeEnabled;
f03fc89f 911
071e5fd9 912#if wxUSE_PALETTE
574c939e 913 wxPalette m_palette;
b95edd47
VZ
914 bool m_hasCustomPalette;
915#endif // wxUSE_PALETTE
574c939e 916
566d84a7
RL
917 // Virtual size (scrolling)
918 wxSize m_virtualSize;
919
920 int m_minVirtualWidth; // VirtualSizeHints
921 int m_minVirtualHeight;
922 int m_maxVirtualWidth;
923 int m_maxVirtualHeight;
45e0dc94 924
f03fc89f
VZ
925 // common part of all ctors: it is not virtual because it is called from
926 // ctor
927 void InitBase();
928
1e6feb95
VZ
929 // override this to change the default (i.e. used when no style is
930 // specified) border for the window class
931 virtual wxBorder GetDefaultBorder() const;
932
f03fc89f
VZ
933 // get the default size for the new window if no explicit size given
934 // FIXME why 20 and not 30, 10 or ...?
935 static int WidthDefault(int w) { return w == -1 ? 20 : w; }
936 static int HeightDefault(int h) { return h == -1 ? 20 : h; }
937
1e6feb95
VZ
938 // set the best size for the control if the default size was given:
939 // replaces the fields of size == -1 with the best values for them and
940 // calls SetSize() if needed
941 void SetBestSize(const wxSize& size)
f68586e5
VZ
942 {
943 if ( size.x == -1 || size.y == -1 )
944 {
1e6feb95
VZ
945 wxSize sizeBest = DoGetBestSize();
946 if ( size.x != -1 )
947 sizeBest.x = size.x;
948 if ( size.y != -1 )
949 sizeBest.y = size.y;
950
951 SetSize(sizeBest);
f68586e5
VZ
952 }
953 }
954
f03fc89f
VZ
955 // more pure virtual functions
956 // ---------------------------
957
958 // NB: we must have DoSomething() function when Something() is an overloaded
959 // method: indeed, we can't just have "virtual Something()" in case when
960 // the function is overloaded because then we'd have to make virtual all
961 // the variants (otherwise only the virtual function may be called on a
962 // pointer to derived class according to C++ rules) which is, in
963 // general, absolutely not needed. So instead we implement all
964 // overloaded Something()s in terms of DoSomething() which will be the
965 // only one to be virtual.
966
dabc0cd5
VZ
967 // coordinates translation
968 virtual void DoClientToScreen( int *x, int *y ) const = 0;
969 virtual void DoScreenToClient( int *x, int *y ) const = 0;
970
1e6feb95
VZ
971 virtual wxHitTest DoHitTest(wxCoord x, wxCoord y) const;
972
94633ad9 973 // capture/release the mouse, used by Capture/ReleaseMouse()
a83e1475
VZ
974 virtual void DoCaptureMouse() = 0;
975 virtual void DoReleaseMouse() = 0;
be90c029 976
f03fc89f
VZ
977 // retrieve the position/size of the window
978 virtual void DoGetPosition( int *x, int *y ) const = 0;
979 virtual void DoGetSize( int *width, int *height ) const = 0;
980 virtual void DoGetClientSize( int *width, int *height ) const = 0;
981
f68586e5
VZ
982 // get the size which best suits the window: for a control, it would be
983 // the minimal size which doesn't truncate the control, for a panel - the
984 // same size as it would have after a call to Fit()
985 virtual wxSize DoGetBestSize() const;
986
f03fc89f
VZ
987 // this is the virtual function to be overriden in any derived class which
988 // wants to change how SetSize() or Move() works - it is called by all
989 // versions of these functions in the base class
990 virtual void DoSetSize(int x, int y,
991 int width, int height,
992 int sizeFlags = wxSIZE_AUTO) = 0;
993
994 // same as DoSetSize() for the client size
995 virtual void DoSetClientSize(int width, int height) = 0;
996
9d9b7755
VZ
997 // move the window to the specified location and resize it: this is called
998 // from both DoSetSize() and DoSetClientSize() and would usually just
999 // reposition this window except for composite controls which will want to
1000 // arrange themselves inside the given rectangle
1001 virtual void DoMoveWindow(int x, int y, int width, int height) = 0;
1002
f03fc89f
VZ
1003#if wxUSE_TOOLTIPS
1004 virtual void DoSetToolTip( wxToolTip *tip );
1005#endif // wxUSE_TOOLTIPS
1006
1e6feb95 1007#if wxUSE_MENUS
a1665b22 1008 virtual bool DoPopupMenu( wxMenu *menu, int x, int y ) = 0;
1e6feb95 1009#endif // wxUSE_MENUS
a1665b22 1010
a200c35e
VS
1011 // Makes an adjustment to the window position (for example, a frame that has
1012 // a toolbar that it manages itself).
20a1eea1 1013 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags) const;
8d99be5f 1014
45e0dc94 1015
f03fc89f 1016private:
45e0dc94 1017
f03fc89f
VZ
1018 // contains the last id generated by NewControlId
1019 static int ms_lastControlId;
1020
a83e1475
VZ
1021 // the stack of windows which have captured the mouse
1022 static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext;
1023
1e6feb95
VZ
1024 DECLARE_ABSTRACT_CLASS(wxWindowBase)
1025 DECLARE_NO_COPY_CLASS(wxWindowBase)
f03fc89f
VZ
1026 DECLARE_EVENT_TABLE()
1027};
1028
1029// ----------------------------------------------------------------------------
1030// now include the declaration of wxWindow class
1031// ----------------------------------------------------------------------------
1032
1e6feb95 1033// include the declaration of the platform-specific class
2049ba38 1034#if defined(__WXMSW__)
a5b3669d
VZ
1035 #ifdef __WXUNIVERSAL__
1036 #define wxWindowNative wxWindowMSW
1037 #else // !wxUniv
1e6feb95
VZ
1038 #define wxWindowMSW wxWindow
1039 #define sm_classwxWindowMSW sm_classwxWindow
a5b3669d 1040 #endif // wxUniv/!wxUniv
f03fc89f 1041 #include "wx/msw/window.h"
2049ba38 1042#elif defined(__WXMOTIF__)
f03fc89f 1043 #include "wx/motif/window.h"
2049ba38 1044#elif defined(__WXGTK__)
a5b3669d
VZ
1045 #ifdef __WXUNIVERSAL__
1046 #define wxWindowNative wxWindowGTK
1047 #else // !wxUniv
1e6feb95
VZ
1048 #define wxWindowGTK wxWindow
1049 #define sm_classwxWindowGTK sm_classwxWindow
1050 #endif // wxUniv
f03fc89f 1051 #include "wx/gtk/window.h"
83df96d6
JS
1052#elif defined(__WXX11__)
1053 #ifdef __WXUNIVERSAL__
1054 #define wxWindowNative wxWindowX11
1055 #else // !wxUniv
1056 #define wxWindowX11 wxWindow
1057 #define sm_classwxWindowX11 sm_classwxWindow
1058 #endif // wxUniv
1059 #include "wx/x11/window.h"
711c76db 1060#elif defined(__WXMGL__)
386c7058
VS
1061 #ifdef __WXUNIVERSAL__
1062 #define wxWindowNative wxWindowMGL
1063 #else // !wxUniv
1064 #define wxWindowMGL wxWindow
1065 #define sm_classwxWindowMGL sm_classwxWindow
1066 #endif // wxUniv
1067 #include "wx/mgl/window.h"
34138703 1068#elif defined(__WXMAC__)
e766c8a9
SC
1069 #ifdef __WXUNIVERSAL__
1070 #define wxWindowNative wxWindowMac
1071 #else // !wxUniv
1072 #define wxWindowMac wxWindow
1073 #define sm_classwxWindowMac sm_classwxWindow
1074 #endif // wxUniv
f03fc89f 1075 #include "wx/mac/window.h"
1777b9bb 1076#elif defined(__WXPM__)
210a651b
DW
1077 #ifdef __WXUNIVERSAL__
1078 #define wxWindowNative wxWindowOS2
1079 #else // !wxUniv
1080 #define wxWindowOS2 wxWindow
1081 #define sm_classwxWindowOS2 sm_classwxWindow
1082 #endif // wxUniv/!wxUniv
1777b9bb 1083 #include "wx/os2/window.h"
c801d85f
KB
1084#endif
1085
1e6feb95
VZ
1086// for wxUniversal, we now derive the real wxWindow from wxWindow<platform>,
1087// for the native ports we already have defined it above
1088#if defined(__WXUNIVERSAL__)
a5b3669d
VZ
1089 #ifndef wxWindowNative
1090 #error "wxWindowNative must be defined above!"
1091 #endif
1092
1e6feb95
VZ
1093 #include "wx/univ/window.h"
1094#endif // wxUniv
1095
f03fc89f
VZ
1096// ----------------------------------------------------------------------------
1097// inline functions which couldn't be declared in the class body because of
1098// forward dependencies
1099// ----------------------------------------------------------------------------
1100
bacd69f9 1101inline wxWindow *wxWindowBase::GetGrandParent() const
f03fc89f
VZ
1102{
1103 return m_parent ? m_parent->GetParent() : (wxWindow *)NULL;
1104}
1105
1106// ----------------------------------------------------------------------------
3723b7b1 1107// global functions
f03fc89f
VZ
1108// ----------------------------------------------------------------------------
1109
3723b7b1
JS
1110// Find the wxWindow at the current mouse position, also returning the mouse
1111// position.
1112WXDLLEXPORT extern wxWindow* wxFindWindowAtPointer(wxPoint& pt);
1113
1114// Get the current mouse position.
1115WXDLLEXPORT extern wxPoint wxGetMousePosition();
1116
1e6feb95
VZ
1117// get the currently active window of this application or NULL
1118WXDLLEXPORT extern wxWindow *wxGetActiveWindow();
1119
33b494d6
VZ
1120// get the (first) top level parent window
1121WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win);
1122
f68586e5 1123// deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId()
6d56eb5c 1124inline int NewControlId() { return wxWindowBase::NewControlId(); }
f03fc89f 1125
c801d85f 1126#endif
34138703 1127 // _WX_WINDOW_H_BASE_
34c3ffca 1128