]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/window.h
added wxTextCtrl::AppendText, used by TextCtrl operator <<
[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 wxList wxTopLevelWindows;
34
35 //-----------------------------------------------------------------------------
36 // global function
37 //-----------------------------------------------------------------------------
38
39 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 // (debug)
103 //-----------------------------------------------------------------------------
104
105 #ifdef __WXDEBUG__
106
107 void debug_focus_in( GtkWidget* widget, const char* name, const char* window );
108
109 #endif
110
111 //-----------------------------------------------------------------------------
112 // wxWindow
113 //-----------------------------------------------------------------------------
114
115 class wxWindow: public wxEvtHandler
116 {
117 DECLARE_DYNAMIC_CLASS(wxWindow)
118
119 public:
120 wxWindow();
121 wxWindow(wxWindow *parent, wxWindowID id,
122 const wxPoint& pos = wxDefaultPosition,
123 const wxSize& size = wxDefaultSize,
124 long style = 0,
125 const wxString& name = wxPanelNameStr);
126 bool Create(wxWindow *parent, wxWindowID id,
127 const wxPoint& pos = wxDefaultPosition,
128 const wxSize& size = wxDefaultSize,
129 long style = 0,
130 const wxString& name = wxPanelNameStr);
131 virtual ~wxWindow();
132
133 #if wxUSE_WX_RESOURCES
134 virtual bool LoadFromResource( wxWindow *parent, const wxString& resourceName,
135 const wxResourceTable *table = (const wxResourceTable *) NULL);
136 virtual wxControl *CreateItem(const wxItemResource* childResource, const wxItemResource* parentResource,
137 const wxResourceTable *table = (const wxResourceTable *) NULL);
138 #endif
139
140 bool Close( bool force = FALSE );
141 virtual bool Destroy();
142 virtual bool DestroyChildren();
143
144 virtual void PrepareDC( wxDC &dc );
145
146 virtual void SetSize( int x, int y, int width, int height,
147 int sizeFlags = wxSIZE_AUTO );
148 virtual void SetSize( int width, int height );
149
150 virtual void Move( int x, int y );
151
152 virtual void GetSize( int *width, int *height ) const;
153 wxSize GetSize() const { int w, h; GetSize(& w, & h); return wxSize(w, h); }
154
155 virtual void SetClientSize( int const width, int const height );
156
157 virtual void GetClientSize( int *width, int *height ) const;
158 wxSize GetClientSize() const { int w, h; GetClientSize(& w, & h); return wxSize(w, h); }
159
160 virtual void GetPosition( int *x, int *y ) const;
161 wxPoint GetPosition() const { int w, h; GetPosition(& w, & h); return wxPoint(w, h); }
162
163 wxRect GetRect() const
164 { int x, y, w, h; GetPosition(& x, & y); GetSize(& w, & h); return wxRect(x, y, w, h); }
165
166 virtual void Centre( int direction = wxHORIZONTAL );
167 inline void Center(int direction = wxHORIZONTAL) { Centre(direction); }
168 virtual void Fit();
169
170 virtual void SetSizeHints( int minW, int minH, int maxW = -1, int maxH = -1, int incW = -1, int incH = -1 );
171
172 /* Dialog units translations. Implemented in wincmn.cpp. */
173 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
174 wxPoint ConvertDialogToPixels( const wxPoint& pt );
175 inline wxSize ConvertPixelsToDialog( const wxSize& sz )
176 { wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
177 inline wxSize ConvertDialogToPixels( const wxSize& sz )
178 { wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
179
180 void OnSize( wxSizeEvent &event );
181
182 virtual bool Show( bool show );
183 virtual void Enable( bool enable );
184 virtual void MakeModal( bool modal );
185 virtual bool IsEnabled() const { return m_isEnabled; }
186 inline bool Enabled() const { return IsEnabled(); }
187 virtual bool OnClose();
188
189 virtual void SetFocus();
190 static wxWindow *FindFocus();
191
192 virtual void AddChild( wxWindow *child );
193 wxList& GetChildren() { return m_children; }
194
195 virtual void RemoveChild( wxWindow *child );
196 void SetReturnCode( int retCode );
197 int GetReturnCode();
198 wxWindow *GetParent() const
199 { return m_parent; }
200 wxWindow *GetGrandParent() const
201 { return (m_parent ? m_parent->m_parent : (wxWindow*)NULL); }
202 void SetParent( wxWindow *parent )
203 { m_parent = parent; }
204 virtual wxWindow *ReParent( wxWindow *newParent );
205
206 wxEvtHandler *GetEventHandler() const;
207 void SetEventHandler( wxEvtHandler *handler );
208 void PushEventHandler( wxEvtHandler *handler );
209 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
210
211 virtual void SetValidator( const wxValidator &validator );
212 virtual wxValidator *GetValidator();
213
214 virtual void SetClientObject( wxClientData *data );
215 virtual wxClientData *GetClientObject();
216
217 virtual void SetClientData( void *data );
218 virtual void *GetClientData();
219
220 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel );
221 virtual wxAcceleratorTable *GetAcceleratorTable() { return &m_acceleratorTable; }
222
223 bool IsBeingDeleted();
224
225 void SetId( wxWindowID id );
226 wxWindowID GetId() const;
227
228 void SetCursor( const wxCursor &cursor );
229
230 void WarpPointer(int x, int y);
231
232 #if wxUSE_TOOLTIPS
233 void SetToolTip( const wxString &tip );
234 virtual void SetToolTip( wxToolTip *tip );
235 wxToolTip* GetToolTip() const { return m_toolTip; }
236 #endif // wxUSE_TOOLTIPS
237
238 virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL );
239 virtual void Clear();
240
241 virtual wxRegion GetUpdateRegion() const;
242 virtual bool IsExposed( int x, int y ) const;
243 virtual bool IsExposed( int x, int y, int w, int h ) const;
244 virtual bool IsExposed( const wxPoint& pt ) const;
245 virtual bool IsExposed( const wxRect& rect ) const;
246
247 virtual wxColour GetBackgroundColour() const;
248 virtual void SetBackgroundColour( const wxColour &colour );
249 virtual wxColour GetForegroundColour() const;
250 virtual void SetForegroundColour( const wxColour &colour );
251
252 virtual int GetCharHeight() const;
253 virtual int GetCharWidth() const;
254 virtual void GetTextExtent( const wxString& string, int *x, int *y,
255 int *descent = (int *) NULL,
256 int *externalLeading = (int *) NULL,
257 const wxFont *theFont = (const wxFont *) NULL, bool use16 = FALSE) const;
258
259 virtual void SetFont( const wxFont &font );
260 virtual wxFont& GetFont() { return m_font; }
261
262 // For backward compatibility
263 inline virtual void SetButtonFont(const wxFont& font) { SetFont(font); }
264 inline virtual void SetLabelFont(const wxFont& font) { SetFont(font); }
265 inline virtual wxFont& GetLabelFont() { return GetFont(); };
266 inline virtual wxFont& GetButtonFont() { return GetFont(); };
267
268 virtual void SetWindowStyleFlag( long flag );
269 virtual long GetWindowStyleFlag() const;
270
271 virtual void CaptureMouse();
272 virtual void ReleaseMouse();
273
274 virtual void SetTitle( const wxString &title );
275 virtual wxString GetTitle() const;
276 virtual void SetName( const wxString &name );
277 virtual wxString GetName() const;
278 virtual wxString GetLabel() const;
279
280 void OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) ) {};
281 void OnKeyDown( wxKeyEvent &event );
282
283 virtual bool IsShown() const;
284
285 virtual void Raise();
286 virtual void Lower();
287
288 virtual bool IsRetained();
289 virtual wxWindow *FindWindow( long id );
290 virtual wxWindow *FindWindow( const wxString& name );
291
292 void AllowDoubleClick( bool WXUNUSED(allow) ) {};
293 void SetDoubleClick( bool WXUNUSED(allow) ) {};
294
295 virtual void ClientToScreen( int *x, int *y );
296 virtual void ScreenToClient( int *x, int *y );
297
298 virtual bool Validate();
299 virtual bool TransferDataToWindow();
300 virtual bool TransferDataFromWindow();
301 void OnInitDialog( wxInitDialogEvent &event );
302 virtual void InitDialog();
303
304 virtual bool PopupMenu( wxMenu *menu, int x, int y );
305
306 #if wxUSE_DRAG_AND_DROP
307 virtual void SetDropTarget( wxDropTarget *dropTarget );
308 virtual wxDropTarget *GetDropTarget() const;
309 #endif
310
311 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
312 int range, bool refresh = TRUE );
313 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
314 virtual int GetScrollPos( int orient ) const;
315 virtual int GetScrollThumb( int orient ) const;
316 virtual int GetScrollRange( int orient ) const;
317 virtual void ScrollWindow( int dx, int dy, const wxRect* rect = (wxRect *) NULL );
318
319 virtual bool AcceptsFocus() const;
320
321 void UpdateWindowUI();
322
323 // implementation
324
325 virtual wxPoint GetClientAreaOrigin() const;
326 virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags );
327
328 bool HasVMT();
329
330 virtual void OnInternalIdle();
331
332 /* used by all classes in the widget creation process */
333
334 void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
335 const wxSize &size, long style, const wxString &name );
336 void PostCreation();
337
338 /* the methods below are required because many native widgets
339 are composed of several subwidgets and setting a style for
340 the widget means setting it for all subwidgets as well.
341 also, it is nor clear, which native widget is the top
342 widget where (most of) the input goes. even tooltips have
343 to be applied to all subwidgets. */
344
345 virtual GtkWidget* GetConnectWidget();
346 virtual bool IsOwnGtkWindow( GdkWindow *window );
347 void ConnectWidget( GtkWidget *widget );
348
349 GtkStyle *GetWidgetStyle();
350 void SetWidgetStyle();
351 virtual void ApplyWidgetStyle();
352
353 #if wxUSE_TOOLTIPS
354 virtual void ApplyToolTip( GtkTooltips *tips, const char *tip );
355 #endif // wxUSE_TOOLTIPS
356
357 /* private member variables */
358
359 wxWindow *m_parent;
360 wxList m_children;
361 int m_x,m_y;
362 int m_width,m_height;
363 int m_minWidth,m_minHeight;
364 int m_maxWidth,m_maxHeight;
365 int m_retCode;
366 wxEvtHandler *m_eventHandler;
367 wxValidator *m_windowValidator;
368 #if wxUSE_DRAG_AND_DROP
369 wxDropTarget *m_dropTarget;
370 #endif
371 wxWindowID m_windowId;
372 wxCursor *m_cursor;
373 wxFont m_font;
374 wxColour m_backgroundColour;
375 wxColour m_foregroundColour;
376 wxRegion m_updateRegion;
377 long m_windowStyle;
378 bool m_isShown;
379 bool m_isEnabled;
380 wxString m_windowName;
381 wxAcceleratorTable m_acceleratorTable;
382 wxClientData *m_clientObject;
383 void *m_clientData;
384
385 #if wxUSE_TOOLTIPS
386 wxToolTip *m_toolTip;
387 #endif // wxUSE_TOOLTIPS
388
389 GtkWidget *m_widget;
390 GtkWidget *m_wxwindow;
391 GtkAdjustment *m_hAdjust,*m_vAdjust;
392 float m_oldHorizontalPos;
393 float m_oldVerticalPos;
394 bool m_needParent;
395 bool m_hasScrolling;
396 bool m_isScrolling;
397 bool m_hasVMT;
398 bool m_sizeSet;
399 bool m_resizing;
400 GdkGC *m_scrollGC;
401 GtkStyle *m_widgetStyle;
402 bool m_isStaticBox;
403 bool m_acceptsFocus;
404
405 wxInsertChildFunction m_insertCallback;
406
407 public:
408
409 wxLayoutConstraints *m_constraints;
410 wxList *m_constraintsInvolvedIn;
411 wxSizer *m_windowSizer;
412 wxWindow *m_sizerParent;
413 bool m_autoLayout;
414
415 wxLayoutConstraints *GetConstraints() const;
416 void SetConstraints( wxLayoutConstraints *constraints );
417 void SetAutoLayout( bool autoLayout );
418 bool GetAutoLayout() const;
419 bool Layout();
420 void SetSizer( wxSizer *sizer );
421 wxSizer *GetSizer() const;
422 void SetSizerParent( wxWindow *win );
423 wxWindow *GetSizerParent() const;
424 void UnsetConstraints(wxLayoutConstraints *c);
425 inline wxList *GetConstraintsInvolvedIn() const ;
426 void AddConstraintReference(wxWindow *otherWin);
427 void RemoveConstraintReference(wxWindow *otherWin);
428 void DeleteRelatedConstraints();
429 virtual void ResetConstraints();
430 virtual void SetConstraintSizes(bool recurse = TRUE);
431 virtual bool LayoutPhase1(int *noChanges);
432 virtual bool LayoutPhase2(int *noChanges);
433 virtual bool DoPhase(int);
434 virtual void TransformSizerToActual(int *x, int *y) const ;
435 virtual void SizerSetSize(int x, int y, int w, int h);
436 virtual void SizerMove(int x, int y);
437 virtual void SetSizeConstraint(int x, int y, int w, int h);
438 virtual void MoveConstraint(int x, int y);
439 virtual void GetSizeConstraint(int *w, int *h) const ;
440 virtual void GetClientSizeConstraint(int *w, int *h) const ;
441 virtual void GetPositionConstraint(int *x, int *y) const ;
442
443 private:
444 DECLARE_EVENT_TABLE()
445 };
446
447 #endif // __GTKWINDOWH__