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