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