]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/window.h
EVT_TEXT_UPDATED bug fixed, text ctrl callbacks simplified
[wxWidgets.git] / include / wx / gtk / window.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: window.h
3// Purpose:
4// Author: Robert Roebling
58614078
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
aed8df38 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifndef __GTKWINDOWH__
12#define __GTKWINDOWH__
13
14#ifdef __GNUG__
bfc6fde4 15 #pragma interface
c801d85f
KB
16#endif
17
18#include "wx/defs.h"
19#include "wx/object.h"
20#include "wx/list.h"
21#include "wx/event.h"
22#include "wx/validate.h"
23#include "wx/cursor.h"
24#include "wx/font.h"
c801d85f 25#include "wx/region.h"
bcf1fa6b 26#include "wx/accel.h"
c801d85f
KB
27
28//-----------------------------------------------------------------------------
29// global data
30//-----------------------------------------------------------------------------
31
32extern const char *wxFrameNameStr;
33extern wxList wxTopLevelWindows;
34
bbe0af5b
RR
35//-----------------------------------------------------------------------------
36// global function
37//-----------------------------------------------------------------------------
38
bfc6fde4 39extern wxWindow* wxGetActiveWindow();
bbe0af5b 40
c801d85f
KB
41//-----------------------------------------------------------------------------
42// classes
43//-----------------------------------------------------------------------------
44
45class wxLayoutConstraints;
46class wxSizer;
ac57418f 47class wxDC;
fd0eed64
RR
48class wxClientData;
49class wxVoidClientData;
c801d85f 50class wxWindow;
06cfab17 51#if wxUSE_WX_RESOURCES
bfc6fde4
VZ
52 class wxResourceTable;
53 class wxItemResource;
ac57418f 54#endif
06cfab17 55#if wxUSE_DRAG_AND_DROP
bfc6fde4 56 class wxDropTarget;
ac57418f 57#endif
b1170810 58class wxToolTip;
c801d85f 59
6ca41e57 60//-----------------------------------------------------------------------------
fd0eed64 61// callback definition for inserting a window (internal)
6ca41e57
RR
62//-----------------------------------------------------------------------------
63
64typedef void (*wxInsertChildFunction)( wxWindow*, wxWindow* );
65
c801d85f
KB
66//-----------------------------------------------------------------------------
67// global data
68//-----------------------------------------------------------------------------
69
70extern const char *wxPanelNameStr;
71extern const wxSize wxDefaultSize;
72extern const wxPoint wxDefaultPosition;
73
fd0eed64
RR
74//-----------------------------------------------------------------------------
75// wxClientData
76//-----------------------------------------------------------------------------
77
78class wxClientData
79{
80public:
bfc6fde4
VZ
81 wxClientData() { }
82 virtual ~wxClientData() { }
fd0eed64
RR
83};
84
fd0eed64
RR
85//-----------------------------------------------------------------------------
86// wxStringClientData
87//-----------------------------------------------------------------------------
88
bfc6fde4 89class wxStringClientData : public wxClientData
fd0eed64
RR
90{
91public:
92 wxStringClientData() { }
93 wxStringClientData( wxString &data ) { m_data = data; }
94 void SetData( wxString &data ) { m_data = data; }
95 wxString GetData() const { return m_data; }
8bbe427f 96
fd0eed64
RR
97private:
98 wxString m_data;
99};
100
b292e2f5
RR
101//-----------------------------------------------------------------------------
102// (debug)
103//-----------------------------------------------------------------------------
104
105#ifdef __WXDEBUG__
106
107void debug_focus_in( GtkWidget* widget, const char* name, const char* window );
108
109#endif
110
c801d85f
KB
111//-----------------------------------------------------------------------------
112// wxWindow
113//-----------------------------------------------------------------------------
114
bfc6fde4 115class wxWindow : public wxEvtHandler
c801d85f 116{
bfc6fde4 117 DECLARE_DYNAMIC_CLASS(wxWindow)
8bbe427f 118
aed8df38 119public:
bfc6fde4
VZ
120 // creating the window
121 // -------------------
122 wxWindow();
123 wxWindow(wxWindow *parent, wxWindowID id,
124 const wxPoint& pos = wxDefaultPosition,
125 const wxSize& size = wxDefaultSize,
126 long style = 0,
127 const wxString& name = wxPanelNameStr);
128 bool Create(wxWindow *parent, wxWindowID id,
129 const wxPoint& pos = wxDefaultPosition,
130 const wxSize& size = wxDefaultSize,
131 long style = 0,
132 const wxString& name = wxPanelNameStr);
133 virtual ~wxWindow();
cd0183ca 134
f5abe911 135#if wxUSE_WX_RESOURCES
bfc6fde4
VZ
136 virtual bool LoadFromResource(wxWindow *parent,
137 const wxString& resourceName,
138 const wxResourceTable *table = (const wxResourceTable *) NULL);
139 virtual wxControl *CreateItem(const wxItemResource* childResource,
140 const wxItemResource* parentResource,
141 const wxResourceTable *table = (const wxResourceTable *) NULL);
142#endif // wxUSE_WX_RESOURCES
143
144 // closing the window
145 // ------------------
146 bool Close( bool force = FALSE );
147 virtual bool Destroy();
148 virtual bool DestroyChildren();
149
150 bool IsBeingDeleted();
151
152 // moving/resizing
153 // ---------------
154
155 // set the window size and/or position
156 void SetSize( int x, int y, int width, int height,
157 int sizeFlags = wxSIZE_AUTO )
158 { DoSetSize(x, y, width, height, sizeFlags); }
159
160 void SetSize( int width, int height )
161 { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); }
162
163 void SetSize( const wxSize& size )
164 { SetSize( size.x, size.y); }
165
166 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
167 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
168
169 void Move( int x, int y )
170 { DoSetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); }
171
172 void Move(const wxPoint& pt)
173 { Move(pt.x, pt.y); }
174
175 // client size is the size of area available for subwindows
176 void SetClientSize( int width, int height )
177 { DoSetClientSize(width, height); }
178
179 void SetClientSize( const wxSize& size )
180 { DoSetClientSize(size.x, size.y); }
181
182 void SetClientSize(const wxRect& rect)
183 { SetClientSize( rect.width, rect.height ); }
184
185 // get the window position and/or size
186 virtual void GetPosition( int *x, int *y ) const;
187 wxPoint GetPosition() const
188 {
189 int w, h;
190 GetPosition(& w, & h);
191
192 return wxPoint(w, h);
193 }
194
195 virtual void GetSize( int *width, int *height ) const;
196
197 wxSize GetSize() const
198 {
199 int w, h;
200 GetSize(& w, & h);
201 return wxSize(w, h);
202 }
203
204 wxRect GetRect() const
205 {
206 int x, y, w, h;
207 GetPosition(& x, & y);
208 GetSize(& w, & h);
209
210 return wxRect(x, y, w, h);
211 }
cd0183ca 212
bfc6fde4
VZ
213 virtual void GetClientSize( int *width, int *height ) const;
214 wxSize GetClientSize() const
215 {
216 int w, h;
217 GetClientSize(& w, & h);
218 return wxSize(w, h);
219 }
aed8df38 220
bfc6fde4
VZ
221 // position with respect to the the parent window
222 virtual void Centre( int direction = wxHORIZONTAL );
223 void Center(int direction = wxHORIZONTAL) { Centre(direction); }
224 virtual void Fit();
aed8df38 225
bfc6fde4
VZ
226 // set min/max size of the window
227 virtual void SetSizeHints( int minW, int minH,
228 int maxW = -1, int maxH = -1,
229 int incW = -1, int incH = -1 );
ff8bfdbb 230
bfc6fde4
VZ
231 // Dialog units translations. Implemented in wincmn.cpp.
232 // -----------------------------------------------------
ff8bfdbb 233
bfc6fde4
VZ
234 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
235 wxPoint ConvertDialogToPixels( const wxPoint& pt );
236 wxSize ConvertPixelsToDialog( const wxSize& sz )
237 {
238 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
239
240 return wxSize(pt.x, pt.y);
241 }
ff8bfdbb 242
bfc6fde4
VZ
243 wxSize ConvertDialogToPixels( const wxSize& sz )
244 {
245 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
ff8bfdbb 246
bfc6fde4
VZ
247 return wxSize(pt.x, pt.y);
248 }
ff8bfdbb 249
bfc6fde4 250 void OnSize( wxSizeEvent &event );
ff8bfdbb 251
bfc6fde4
VZ
252 // window state
253 // ------------
ff8bfdbb 254
bfc6fde4
VZ
255 virtual bool Show( bool show );
256 virtual void Enable( bool enable );
257 virtual void MakeModal( bool modal );
258 virtual bool IsEnabled() const { return m_isEnabled; }
259 inline bool Enabled() const { return IsEnabled(); }
2f2aa628 260
bfc6fde4
VZ
261 virtual void SetFocus();
262 static wxWindow *FindFocus();
aed8df38 263
bfc6fde4
VZ
264 void SetReturnCode( int retCode );
265 int GetReturnCode();
fd71308f 266
bfc6fde4
VZ
267 // parent/children relations
268 // -------------------------
aed8df38 269
bfc6fde4
VZ
270 virtual void AddChild( wxWindow *child );
271 wxList& GetChildren() { return m_children; }
aed8df38 272
bfc6fde4 273 virtual void RemoveChild( wxWindow *child );
ff8bfdbb 274
bfc6fde4
VZ
275 wxWindow *GetParent() const
276 { return m_parent; }
277 wxWindow *GetGrandParent() const
278 { return (m_parent ? m_parent->m_parent : (wxWindow*)NULL); }
279 void SetParent( wxWindow *parent )
280 { m_parent = parent; }
281 virtual wxWindow *ReParent( wxWindow *newParent );
8bbe427f 282
bfc6fde4
VZ
283 // event handler stuff
284 // -------------------
2b854a32 285
bfc6fde4
VZ
286 wxEvtHandler *GetEventHandler() const;
287 void SetEventHandler( wxEvtHandler *handler );
288 void PushEventHandler( wxEvtHandler *handler );
289 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
aed8df38 290
bfc6fde4
VZ
291 // validators and client data
292 // --------------------------
aed8df38 293
bfc6fde4
VZ
294 virtual void SetValidator( const wxValidator &validator );
295 virtual wxValidator *GetValidator();
aed8df38 296
bfc6fde4
VZ
297 virtual void SetClientObject( wxClientData *data );
298 virtual wxClientData *GetClientObject();
8bbe427f 299
bfc6fde4
VZ
300 virtual void SetClientData( void *data );
301 virtual void *GetClientData();
8bbe427f 302
bfc6fde4
VZ
303 // accelerators
304 // ------------
305 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel );
306 virtual wxAcceleratorTable *GetAcceleratorTable() { return &m_acceleratorTable; }
8bbe427f 307
bfc6fde4
VZ
308 void SetId( wxWindowID id );
309 wxWindowID GetId() const;
aed8df38 310
bfc6fde4 311 void SetCursor( const wxCursor &cursor );
aed8df38 312
bfc6fde4 313 virtual void PrepareDC( wxDC &dc );
ff8bfdbb 314
bfc6fde4 315 void WarpPointer(int x, int y);
ff8bfdbb
VZ
316
317#if wxUSE_TOOLTIPS
bfc6fde4
VZ
318 void SetToolTip( const wxString &tip );
319 virtual void SetToolTip( wxToolTip *tip );
320 wxToolTip* GetToolTip() const { return m_toolTip; }
ff8bfdbb 321#endif // wxUSE_TOOLTIPS
b1170810 322
bfc6fde4
VZ
323 virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL );
324 virtual void Clear();
325
326 virtual wxRegion GetUpdateRegion() const;
327 virtual bool IsExposed( int x, int y ) const;
328 virtual bool IsExposed( int x, int y, int w, int h ) const;
329 virtual bool IsExposed( const wxPoint& pt ) const;
330 virtual bool IsExposed( const wxRect& rect ) const;
331
332 // colours
333 // -------
8bbe427f 334
bfc6fde4
VZ
335 virtual wxColour GetBackgroundColour() const;
336 virtual void SetBackgroundColour( const wxColour &colour );
337 virtual wxColour GetForegroundColour() const;
338 virtual void SetForegroundColour( const wxColour &colour );
aed8df38 339
bfc6fde4
VZ
340 // fonts
341 // -----
cd0183ca 342
bfc6fde4
VZ
343 virtual int GetCharHeight() const;
344 virtual int GetCharWidth() const;
345 virtual void GetTextExtent( const wxString& string, int *x, int *y,
346 int *descent = (int *) NULL,
347 int *externalLeading = (int *) NULL,
348 const wxFont *theFont = (const wxFont *) NULL, bool use16 = FALSE) const;
aed8df38 349
bfc6fde4
VZ
350 virtual void SetFont( const wxFont &font );
351 virtual wxFont& GetFont() { return m_font; }
8bbe427f 352
fd0eed64 353 // For backward compatibility
bfc6fde4
VZ
354 virtual void SetButtonFont(const wxFont& font) { SetFont(font); }
355 virtual void SetLabelFont(const wxFont& font) { SetFont(font); }
356 virtual wxFont& GetLabelFont() { return GetFont(); };
357 virtual wxFont& GetButtonFont() { return GetFont(); };
8bbe427f 358
bfc6fde4
VZ
359 virtual void SetWindowStyleFlag( long flag );
360 virtual long GetWindowStyleFlag() const;
8bbe427f 361
bfc6fde4
VZ
362 virtual void CaptureMouse();
363 virtual void ReleaseMouse();
8bbe427f 364
bfc6fde4
VZ
365 virtual void SetTitle( const wxString &title );
366 virtual wxString GetTitle() const;
367 virtual void SetName( const wxString &name );
368 virtual wxString GetName() const;
369 virtual wxString GetLabel() const;
c801d85f 370
bfc6fde4
VZ
371 void OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) ) { }
372 void OnKeyDown( wxKeyEvent &event );
aed8df38 373
bfc6fde4 374 virtual bool IsShown() const;
e149aaeb 375
bfc6fde4
VZ
376 virtual void Raise();
377 virtual void Lower();
e149aaeb 378
bfc6fde4
VZ
379 virtual bool IsRetained();
380 virtual wxWindow *FindWindow( long id );
381 virtual wxWindow *FindWindow( const wxString& name );
8bbe427f 382
bfc6fde4
VZ
383 void AllowDoubleClick( bool WXUNUSED(allow) ) { }
384 void SetDoubleClick( bool WXUNUSED(allow) ) { }
8bbe427f 385
bfc6fde4
VZ
386 virtual void ClientToScreen( int *x, int *y );
387 virtual void ScreenToClient( int *x, int *y );
aed8df38 388
bfc6fde4
VZ
389 virtual bool Validate();
390 virtual bool TransferDataToWindow();
391 virtual bool TransferDataFromWindow();
392 void OnInitDialog( wxInitDialogEvent &event );
393 virtual void InitDialog();
cd0183ca 394
bfc6fde4 395 virtual bool PopupMenu( wxMenu *menu, int x, int y );
aed8df38 396
06cfab17 397#if wxUSE_DRAG_AND_DROP
bfc6fde4
VZ
398 virtual void SetDropTarget( wxDropTarget *dropTarget );
399 virtual wxDropTarget *GetDropTarget() const;
ac57418f 400#endif
cd0183ca 401
bfc6fde4
VZ
402 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
403 int range, bool refresh = TRUE );
404 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
405 virtual int GetScrollPos( int orient ) const;
406 virtual int GetScrollThumb( int orient ) const;
407 virtual int GetScrollRange( int orient ) const;
408 virtual void ScrollWindow( int dx, int dy, const wxRect* rect = (wxRect *) NULL );
aed8df38 409
bfc6fde4 410 virtual bool AcceptsFocus() const;
8bbe427f 411
bfc6fde4 412 void UpdateWindowUI();
aed8df38 413
bfc6fde4 414 // implementation
8bbe427f 415
bfc6fde4
VZ
416 virtual wxPoint GetClientAreaOrigin() const;
417 virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags );
301cd871 418
bfc6fde4 419 bool HasVMT();
301cd871 420
bfc6fde4 421 virtual void OnInternalIdle();
ff8bfdbb 422
20e85460
JS
423 // For compatibility across platforms (not in event table)
424 void OnIdle(wxIdleEvent& WXUNUSED(event)) {};
425
bfc6fde4 426 /* used by all classes in the widget creation process */
ff8bfdbb 427
bfc6fde4
VZ
428 void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
429 const wxSize &size, long style, const wxString &name );
430 void PostCreation();
ff8bfdbb 431
bfc6fde4
VZ
432 /* the methods below are required because many native widgets
433 are composed of several subwidgets and setting a style for
434 the widget means setting it for all subwidgets as well.
435 also, it is nor clear, which native widget is the top
436 widget where (most of) the input goes. even tooltips have
437 to be applied to all subwidgets. */
ff8bfdbb 438
bfc6fde4
VZ
439 virtual GtkWidget* GetConnectWidget();
440 virtual bool IsOwnGtkWindow( GdkWindow *window );
441 void ConnectWidget( GtkWidget *widget );
8bbe427f 442
bfc6fde4
VZ
443 GtkStyle *GetWidgetStyle();
444 void SetWidgetStyle();
445 virtual void ApplyWidgetStyle();
ff8bfdbb
VZ
446
447#if wxUSE_TOOLTIPS
bfc6fde4 448 virtual void ApplyToolTip( GtkTooltips *tips, const char *tip );
ff8bfdbb 449#endif // wxUSE_TOOLTIPS
301cd871 450
bfc6fde4
VZ
451 /* private member variables */
452
453 wxWindow *m_parent;
454 wxList m_children;
455 int m_x,m_y;
456 int m_width,m_height;
457 int m_minWidth,m_minHeight;
458 int m_maxWidth,m_maxHeight;
459 int m_retCode;
460 wxEvtHandler *m_eventHandler;
461 wxValidator *m_windowValidator;
06cfab17 462#if wxUSE_DRAG_AND_DROP
bfc6fde4 463 wxDropTarget *m_dropTarget;
ac57418f 464#endif
bfc6fde4
VZ
465 wxWindowID m_windowId;
466 wxCursor *m_cursor;
467 wxFont m_font;
468 wxColour m_backgroundColour;
469 wxColour m_foregroundColour;
470 wxRegion m_updateRegion;
471 long m_windowStyle;
472 bool m_isShown;
473 bool m_isEnabled;
474 wxString m_windowName;
475 wxAcceleratorTable m_acceleratorTable;
476 wxClientData *m_clientObject;
477 void *m_clientData;
ff8bfdbb
VZ
478
479#if wxUSE_TOOLTIPS
bfc6fde4 480 wxToolTip *m_toolTip;
ff8bfdbb 481#endif // wxUSE_TOOLTIPS
bcf1fa6b 482
bfc6fde4
VZ
483 GtkWidget *m_widget;
484 GtkWidget *m_wxwindow;
485 GtkAdjustment *m_hAdjust,*m_vAdjust;
486 float m_oldHorizontalPos;
487 float m_oldVerticalPos;
488 bool m_needParent;
489 bool m_hasScrolling;
490 bool m_isScrolling;
491 bool m_hasVMT;
492 bool m_sizeSet;
493 bool m_resizing;
494 GdkGC *m_scrollGC;
495 GtkStyle *m_widgetStyle;
496 bool m_isStaticBox;
497 bool m_acceptsFocus;
498
499 wxInsertChildFunction m_insertCallback;
bcf1fa6b
RR
500
501public:
502
bfc6fde4
VZ
503 wxLayoutConstraints *m_constraints;
504 wxList *m_constraintsInvolvedIn;
505 wxSizer *m_windowSizer;
506 wxWindow *m_sizerParent;
507 bool m_autoLayout;
508
509 wxLayoutConstraints *GetConstraints() const;
510 void SetConstraints( wxLayoutConstraints *constraints );
511 void SetAutoLayout( bool autoLayout );
512 bool GetAutoLayout() const;
513 bool Layout();
514 void SetSizer( wxSizer *sizer );
515 wxSizer *GetSizer() const;
516 void SetSizerParent( wxWindow *win );
517 wxWindow *GetSizerParent() const;
518 void UnsetConstraints(wxLayoutConstraints *c);
519 inline wxList *GetConstraintsInvolvedIn() const ;
520 void AddConstraintReference(wxWindow *otherWin);
521 void RemoveConstraintReference(wxWindow *otherWin);
522 void DeleteRelatedConstraints();
523 virtual void ResetConstraints();
524 virtual void SetConstraintSizes(bool recurse = TRUE);
525 virtual bool LayoutPhase1(int *noChanges);
526 virtual bool LayoutPhase2(int *noChanges);
527 virtual bool DoPhase(int);
528 virtual void TransformSizerToActual(int *x, int *y) const ;
529 virtual void SizerSetSize(int x, int y, int w, int h);
530 virtual void SizerMove(int x, int y);
531 virtual void SetSizeConstraint(int x, int y, int w, int h);
532 virtual void MoveConstraint(int x, int y);
533 virtual void GetSizeConstraint(int *w, int *h) const ;
534 virtual void GetClientSizeConstraint(int *w, int *h) const ;
535 virtual void GetPositionConstraint(int *x, int *y) const ;
536
537protected:
68995f26
VZ
538 // common part of all ctors
539 void Init();
540
bfc6fde4
VZ
541 // this is the virtual function to be overriden in any derived class which
542 // wants to change how SetSize() or Move() works - it is called by all
543 // versions of these functions in the base class
544 virtual void DoSetSize(int x, int y,
545 int width, int height,
546 int sizeFlags = wxSIZE_AUTO);
547
548 // same as DoSetSize() for the client size
549 virtual void DoSetClientSize(int width, int height);
aed8df38 550
68dda785 551private:
bfc6fde4 552 DECLARE_EVENT_TABLE()
c801d85f
KB
553};
554
555#endif // __GTKWINDOWH__