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