]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/window.h
wxGLCanvas works again
[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 wxChar *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 wxChar *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 bool HasVMT();
407
408 /* I don't want users to override what's done in idle so everything that
409 has to be done in idle time in order for wxGTK to work is done in
410 OnInternalIdle */
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 void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
418 const wxSize &size, long style, const wxString &name );
419 void PostCreation();
420
421 /* the methods below are required because many native widgets
422 are composed of several subwidgets and setting a style for
423 the widget means setting it for all subwidgets as well.
424 also, it is nor clear, which native widget is the top
425 widget where (most of) the input goes. even tooltips have
426 to be applied to all subwidgets. */
427
428 virtual GtkWidget* GetConnectWidget();
429 virtual bool IsOwnGtkWindow( GdkWindow *window );
430 void ConnectWidget( GtkWidget *widget );
431
432 GtkStyle *GetWidgetStyle();
433 void SetWidgetStyle();
434 virtual void ApplyWidgetStyle();
435
436 #if wxUSE_TOOLTIPS
437 virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip );
438 #endif // wxUSE_TOOLTIPS
439
440 /* private member variables */
441
442 wxWindow *m_parent;
443 wxList m_children;
444 int m_x,m_y;
445 int m_width,m_height;
446 int m_minWidth,m_minHeight;
447 int m_maxWidth,m_maxHeight;
448 int m_retCode;
449 wxEvtHandler *m_eventHandler;
450 wxValidator *m_windowValidator;
451 #if wxUSE_DRAG_AND_DROP
452 wxDropTarget *m_dropTarget;
453 #endif
454 wxWindowID m_windowId;
455 wxCursor *m_cursor;
456 wxFont m_font;
457 wxColour m_backgroundColour;
458 wxColour m_foregroundColour;
459 wxRegion m_updateRegion;
460 long m_windowStyle;
461 bool m_isShown;
462 bool m_isEnabled;
463 wxString m_windowName;
464 wxAcceleratorTable m_acceleratorTable;
465 wxClientData *m_clientObject;
466 void *m_clientData;
467
468 #if wxUSE_TOOLTIPS
469 wxToolTip *m_toolTip;
470 #endif // wxUSE_TOOLTIPS
471
472 GtkWidget *m_widget;
473 GtkWidget *m_wxwindow;
474 GtkAdjustment *m_hAdjust,*m_vAdjust;
475 float m_oldHorizontalPos;
476 float m_oldVerticalPos;
477 bool m_needParent; /* ! wxFrame, wxDialog, wxNotebookPage ? */
478 bool m_hasScrolling;
479 bool m_isScrolling;
480 bool m_hasVMT;
481 bool m_sizeSet;
482 bool m_resizing;
483 GdkGC *m_scrollGC;
484 GtkStyle *m_widgetStyle;
485 bool m_isStaticBox; /* faster than IS_KIND_OF */
486 bool m_isFrame; /* faster than IS_KIND_OF */
487 bool m_acceptsFocus; /* ! wxStaticBox etc. */
488
489 wxInsertChildFunction m_insertCallback;
490
491 public:
492
493 wxLayoutConstraints *m_constraints;
494 wxList *m_constraintsInvolvedIn;
495 wxSizer *m_windowSizer;
496 wxWindow *m_sizerParent;
497 bool m_autoLayout;
498
499 wxLayoutConstraints *GetConstraints() const;
500 void SetConstraints( wxLayoutConstraints *constraints );
501 void SetAutoLayout( bool autoLayout );
502 bool GetAutoLayout() const;
503 bool Layout();
504 void SetSizer( wxSizer *sizer );
505 wxSizer *GetSizer() const;
506 void SetSizerParent( wxWindow *win );
507 wxWindow *GetSizerParent() const;
508 void UnsetConstraints(wxLayoutConstraints *c);
509 inline wxList *GetConstraintsInvolvedIn() const ;
510 void AddConstraintReference(wxWindow *otherWin);
511 void RemoveConstraintReference(wxWindow *otherWin);
512 void DeleteRelatedConstraints();
513 virtual void ResetConstraints();
514 virtual void SetConstraintSizes(bool recurse = TRUE);
515 virtual bool LayoutPhase1(int *noChanges);
516 virtual bool LayoutPhase2(int *noChanges);
517 virtual bool DoPhase(int);
518 virtual void TransformSizerToActual(int *x, int *y) const ;
519 virtual void SizerSetSize(int x, int y, int w, int h);
520 virtual void SizerMove(int x, int y);
521 virtual void SetSizeConstraint(int x, int y, int w, int h);
522 virtual void MoveConstraint(int x, int y);
523 virtual void GetSizeConstraint(int *w, int *h) const ;
524 virtual void GetClientSizeConstraint(int *w, int *h) const ;
525 virtual void GetPositionConstraint(int *x, int *y) const ;
526
527 protected:
528 // common part of all ctors
529 void Init();
530
531 // this is the virtual function to be overriden in any derived class which
532 // wants to change how SetSize() or Move() works - it is called by all
533 // versions of these functions in the base class
534 virtual void DoSetSize(int x, int y,
535 int width, int height,
536 int sizeFlags = wxSIZE_AUTO);
537
538 // same as DoSetSize() for the client size
539 virtual void DoSetClientSize(int width, int height);
540
541 private:
542 DECLARE_EVENT_TABLE()
543 };
544
545 #endif // __GTKWINDOWH__