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