]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/window.h
no message
[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 // classes
37 //-----------------------------------------------------------------------------
38
39 class wxLayoutConstraints;
40 class wxSizer;
41 class wxDC;
42 class wxClientData;
43 class wxVoidClientData;
44 class wxWindow;
45 #if wxUSE_WX_RESOURCES
46 class wxResourceTable;
47 class wxItemResource;
48 #endif
49 #if wxUSE_DRAG_AND_DROP
50 class wxDropTarget;
51 #endif
52
53 //-----------------------------------------------------------------------------
54 // callback definition for inserting a window (internal)
55 //-----------------------------------------------------------------------------
56
57 typedef void (*wxInsertChildFunction)( wxWindow*, wxWindow* );
58
59 //-----------------------------------------------------------------------------
60 // global data
61 //-----------------------------------------------------------------------------
62
63 extern const char *wxPanelNameStr;
64 extern const wxSize wxDefaultSize;
65 extern const wxPoint wxDefaultPosition;
66
67 //-----------------------------------------------------------------------------
68 // wxClientData
69 //-----------------------------------------------------------------------------
70
71 class wxClientData
72 {
73 public:
74 wxClientData() { }
75 virtual ~wxClientData() { }
76 };
77
78 //-----------------------------------------------------------------------------
79 // wxStringClientData
80 //-----------------------------------------------------------------------------
81
82 class wxStringClientData: public wxClientData
83 {
84 public:
85 wxStringClientData() { }
86 wxStringClientData( wxString &data ) { m_data = data; }
87 void SetData( wxString &data ) { m_data = data; }
88 wxString GetData() const { return m_data; }
89
90 private:
91 wxString m_data;
92 };
93
94 //-----------------------------------------------------------------------------
95 // (debug)
96 //-----------------------------------------------------------------------------
97
98 #ifdef __WXDEBUG__
99
100 void debug_focus_in( GtkWidget* widget, const char* name, const char* window );
101
102 #endif
103
104 //-----------------------------------------------------------------------------
105 // wxWindow
106 //-----------------------------------------------------------------------------
107
108 class wxWindow: public wxEvtHandler
109 {
110 DECLARE_DYNAMIC_CLASS(wxWindow)
111
112 public:
113 wxWindow();
114 wxWindow(wxWindow *parent, wxWindowID id,
115 const wxPoint& pos = wxDefaultPosition,
116 const wxSize& size = wxDefaultSize,
117 long style = 0,
118 const wxString& name = wxPanelNameStr);
119 bool Create(wxWindow *parent, wxWindowID id,
120 const wxPoint& pos = wxDefaultPosition,
121 const wxSize& size = wxDefaultSize,
122 long style = 0,
123 const wxString& name = wxPanelNameStr);
124 virtual ~wxWindow();
125
126 #if wxUSE_WX_RESOURCES
127 virtual bool LoadFromResource( wxWindow *parent, const wxString& resourceName,
128 const wxResourceTable *table = (const wxResourceTable *) NULL);
129 virtual wxControl *CreateItem(const wxItemResource* childResource, const wxItemResource* parentResource,
130 const wxResourceTable *table = (const wxResourceTable *) NULL);
131 #endif
132
133 bool Close( bool force = FALSE );
134 virtual bool Destroy();
135 virtual bool DestroyChildren();
136
137 virtual void PrepareDC( wxDC &dc );
138
139 virtual void SetSize( int x, int y, int width, int height,
140 int sizeFlags = wxSIZE_AUTO );
141 virtual void SetSize( int width, int height );
142
143 virtual void Move( int x, int y );
144
145 virtual void GetSize( int *width, int *height ) const;
146 wxSize GetSize() const { int w, h; GetSize(& w, & h); return wxSize(w, h); }
147
148 virtual void SetClientSize( int const width, int const height );
149
150 virtual void GetClientSize( int *width, int *height ) const;
151 wxSize GetClientSize() const { int w, h; GetClientSize(& w, & h); return wxSize(w, h); }
152
153 virtual void GetPosition( int *x, int *y ) const;
154 wxPoint GetPosition() const { int w, h; GetPosition(& w, & h); return wxPoint(w, h); }
155
156 wxRect GetRect() const
157 { int x, y, w, h; GetPosition(& x, & y); GetSize(& w, & h); return wxRect(x, y, w, h); }
158
159 virtual void Centre( int direction = wxHORIZONTAL );
160 inline void Center(int direction = wxHORIZONTAL) { Centre(direction); }
161 virtual void Fit();
162
163 virtual void SetSizeHints( int minW, int minH, int maxW = -1, int maxH = -1, int incW = -1, int incH = -1 );
164
165 // Dialog units translations. Implemented in wincmn.cpp.
166 wxPoint ConvertPixelsToDialog(const wxPoint& pt) ;
167 wxPoint ConvertDialogToPixels(const wxPoint& pt) ;
168 inline wxSize ConvertPixelsToDialog(const wxSize& sz)
169 { wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
170 inline wxSize ConvertDialogToPixels(const wxSize& sz)
171 { wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
172
173 void OnSize( wxSizeEvent &event );
174 void OnIdle( wxIdleEvent& event );
175
176 virtual bool Show( bool show );
177 virtual void Enable( bool enable );
178 virtual void MakeModal( bool modal );
179 virtual bool IsEnabled() const { return m_isEnabled; }
180 inline bool Enabled() const { return IsEnabled(); }
181 virtual bool OnClose();
182
183 virtual void SetFocus();
184 static wxWindow *FindFocus();
185
186 virtual void AddChild( wxWindow *child );
187 wxList& GetChildren() { return m_children; }
188
189 virtual void RemoveChild( wxWindow *child );
190 void SetReturnCode( int retCode );
191 int GetReturnCode();
192 wxWindow *GetParent() const
193 { return m_parent; }
194 wxWindow *GetGrandParent() const
195 { return (m_parent ? m_parent->m_parent : (wxWindow*)NULL); }
196 void SetParent( wxWindow *p )
197 { m_parent = p; }
198 virtual wxWindow *ReParent( wxWindow *newParent );
199
200 wxEvtHandler *GetEventHandler() const;
201 void SetEventHandler( wxEvtHandler *handler );
202 void PushEventHandler( wxEvtHandler *handler );
203 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
204
205 virtual wxValidator *GetValidator();
206 virtual void SetValidator( const wxValidator &validator );
207
208 virtual void SetClientObject( wxClientData *data );
209 virtual wxClientData *GetClientObject();
210
211 virtual void SetClientData( void *data );
212 virtual void *GetClientData();
213
214 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel );
215 virtual wxAcceleratorTable *GetAcceleratorTable() { return &m_acceleratorTable; }
216
217 bool IsBeingDeleted();
218
219 void SetId( wxWindowID id );
220 wxWindowID GetId() const;
221
222 void SetCursor( const wxCursor &cursor );
223
224 void WarpPointer(int x, int y);
225
226 virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL );
227 virtual void Clear();
228
229 virtual wxRegion GetUpdateRegion() const;
230 virtual bool IsExposed(int x, int y) const;
231 virtual bool IsExposed(int x, int y, int w, int h) const;
232 virtual bool IsExposed(const wxPoint& pt) const;
233 virtual bool IsExposed(const wxRect& rect) const;
234
235 virtual wxColour GetBackgroundColour() const;
236 virtual void SetBackgroundColour( const wxColour &colour );
237 virtual wxColour GetForegroundColour() const;
238 virtual void SetForegroundColour( const wxColour &colour );
239
240 virtual int GetCharHeight() const;
241 virtual int GetCharWidth() const;
242 virtual void GetTextExtent( const wxString& string, int *x, int *y,
243 int *descent = (int *) NULL,
244 int *externalLeading = (int *) NULL,
245 const wxFont *theFont = (const wxFont *) NULL, bool use16 = FALSE) const;
246
247 virtual void SetFont( const wxFont &font );
248 virtual wxFont& GetFont() { return m_font; }
249
250 // For backward compatibility
251 inline virtual void SetButtonFont(const wxFont& font) { SetFont(font); }
252 inline virtual void SetLabelFont(const wxFont& font) { SetFont(font); }
253 inline virtual wxFont& GetLabelFont() { return GetFont(); };
254 inline virtual wxFont& GetButtonFont() { return GetFont(); };
255
256 virtual void SetWindowStyleFlag( long flag );
257 virtual long GetWindowStyleFlag() const;
258
259 virtual void CaptureMouse();
260 virtual void ReleaseMouse();
261
262 virtual void SetTitle( const wxString &title );
263 virtual wxString GetTitle() const;
264 virtual void SetName( const wxString &name );
265 virtual wxString GetName() const;
266 virtual wxString GetLabel() const;
267
268 void OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) ) {};
269
270 virtual bool IsShown() const;
271
272 virtual void Raise();
273 virtual void Lower();
274
275 virtual bool IsRetained();
276 virtual wxWindow *FindWindow( long id );
277 virtual wxWindow *FindWindow( const wxString& name );
278
279 void AllowDoubleClick( bool WXUNUSED(allow) ) {};
280 void SetDoubleClick( bool WXUNUSED(allow) ) {};
281
282 virtual void ClientToScreen( int *x, int *y );
283 virtual void ScreenToClient( int *x, int *y );
284
285 virtual bool Validate();
286 virtual bool TransferDataToWindow();
287 virtual bool TransferDataFromWindow();
288 void OnInitDialog( wxInitDialogEvent &event );
289 virtual void InitDialog();
290
291 virtual bool PopupMenu( wxMenu *menu, int x, int y );
292
293 #if wxUSE_DRAG_AND_DROP
294 virtual void SetDropTarget( wxDropTarget *dropTarget );
295 virtual wxDropTarget *GetDropTarget() const;
296 #endif
297
298 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
299 int range, bool refresh = TRUE );
300 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
301 virtual int GetScrollPos( int orient ) const;
302 virtual int GetScrollThumb( int orient ) const;
303 virtual int GetScrollRange( int orient ) const;
304 virtual void ScrollWindow( int dx, int dy, const wxRect* rect = (wxRect *) NULL );
305
306 virtual bool AcceptsFocus() const;
307
308 void UpdateWindowUI();
309
310 // implementation
311
312 void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
313 const wxSize &size, long style, const wxString &name );
314 void PostCreation();
315 virtual GtkWidget *GetConnectWidget();
316 virtual bool IsOwnGtkWindow( GdkWindow *window );
317 void ConnectWidget( GtkWidget *widget );
318
319 bool HasVMT();
320
321 virtual wxPoint GetClientAreaOrigin() const;
322 virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags );
323
324 GtkStyle *GetWidgetStyle();
325 void SetWidgetStyle();
326 virtual void ApplyWidgetStyle();
327
328
329 wxWindow *m_parent;
330 wxList m_children;
331 int m_x,m_y;
332 int m_width,m_height;
333 int m_minWidth,m_minHeight;
334 int m_maxWidth,m_maxHeight;
335 int m_retCode;
336 wxEvtHandler *m_eventHandler;
337 wxValidator *m_windowValidator;
338 #if wxUSE_DRAG_AND_DROP
339 wxDropTarget *m_dropTarget;
340 #endif
341 wxWindowID m_windowId;
342 wxCursor *m_cursor;
343 wxFont m_font;
344 wxColour m_backgroundColour;
345 wxColour m_foregroundColour;
346 wxRegion m_updateRegion;
347 long m_windowStyle;
348 bool m_isShown;
349 bool m_isEnabled;
350 wxString m_windowName;
351 wxAcceleratorTable m_acceleratorTable;
352 wxClientData *m_clientObject;
353 void *m_clientData;
354
355 GtkWidget *m_widget;
356 GtkWidget *m_wxwindow;
357 GtkAdjustment *m_hAdjust,*m_vAdjust;
358 float m_oldHorizontalPos;
359 float m_oldVerticalPos;
360 bool m_needParent;
361 bool m_hasScrolling;
362 bool m_isScrolling;
363 bool m_hasVMT;
364 bool m_sizeSet;
365 bool m_resizing;
366 GdkGC *m_scrollGC;
367 GtkStyle *m_widgetStyle;
368 bool m_isStaticBox;
369 bool m_acceptsFocus;
370
371 wxInsertChildFunction m_insertCallback;
372
373 public:
374
375 wxLayoutConstraints *m_constraints;
376 wxList *m_constraintsInvolvedIn;
377 wxSizer *m_windowSizer;
378 wxWindow *m_sizerParent;
379 bool m_autoLayout;
380
381 wxLayoutConstraints *GetConstraints() const;
382 void SetConstraints( wxLayoutConstraints *constraints );
383 void SetAutoLayout( bool autoLayout );
384 bool GetAutoLayout() const;
385 bool Layout();
386 void SetSizer( wxSizer *sizer );
387 wxSizer *GetSizer() const;
388 void SetSizerParent( wxWindow *win );
389 wxWindow *GetSizerParent() const;
390 void UnsetConstraints(wxLayoutConstraints *c);
391 inline wxList *GetConstraintsInvolvedIn() const ;
392 void AddConstraintReference(wxWindow *otherWin);
393 void RemoveConstraintReference(wxWindow *otherWin);
394 void DeleteRelatedConstraints();
395 virtual void ResetConstraints();
396 virtual void SetConstraintSizes(bool recurse = TRUE);
397 virtual bool LayoutPhase1(int *noChanges);
398 virtual bool LayoutPhase2(int *noChanges);
399 virtual bool DoPhase(int);
400 virtual void TransformSizerToActual(int *x, int *y) const ;
401 virtual void SizerSetSize(int x, int y, int w, int h);
402 virtual void SizerMove(int x, int y);
403 virtual void SetSizeConstraint(int x, int y, int w, int h);
404 virtual void MoveConstraint(int x, int y);
405 virtual void GetSizeConstraint(int *w, int *h) const ;
406 virtual void GetClientSizeConstraint(int *w, int *h) const ;
407 virtual void GetPositionConstraint(int *x, int *y) const ;
408
409 private:
410 DECLARE_EVENT_TABLE()
411 };
412
413 #endif // __GTKWINDOWH__