1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #ifndef __GTKWINDOWH__
12 #define __GTKWINDOWH__
19 #include "wx/object.h"
22 #include "wx/validate.h"
23 #include "wx/cursor.h"
25 #include "wx/region.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 extern const char *wxFrameNameStr
;
33 extern wxList wxTopLevelWindows
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 wxWindow
* wxGetActiveWindow();
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 class wxLayoutConstraints
;
49 class wxVoidClientData
;
51 #if wxUSE_WX_RESOURCES
52 class wxResourceTable
;
55 #if wxUSE_DRAG_AND_DROP
59 //-----------------------------------------------------------------------------
60 // callback definition for inserting a window (internal)
61 //-----------------------------------------------------------------------------
63 typedef void (*wxInsertChildFunction
)( wxWindow
*, wxWindow
* );
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 extern const char *wxPanelNameStr
;
70 extern const wxSize wxDefaultSize
;
71 extern const wxPoint wxDefaultPosition
;
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
81 virtual ~wxClientData() { }
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 class wxStringClientData
: public wxClientData
91 wxStringClientData() { }
92 wxStringClientData( wxString
&data
) { m_data
= data
; }
93 void SetData( wxString
&data
) { m_data
= data
; }
94 wxString
GetData() const { return m_data
; }
100 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
106 void debug_focus_in( GtkWidget
* widget
, const char* name
, const char* window
);
110 //-----------------------------------------------------------------------------
112 //-----------------------------------------------------------------------------
114 class wxWindow
: public wxEvtHandler
116 DECLARE_DYNAMIC_CLASS(wxWindow
)
120 wxWindow(wxWindow
*parent
, wxWindowID id
,
121 const wxPoint
& pos
= wxDefaultPosition
,
122 const wxSize
& size
= wxDefaultSize
,
124 const wxString
& name
= wxPanelNameStr
);
125 bool Create(wxWindow
*parent
, wxWindowID id
,
126 const wxPoint
& pos
= wxDefaultPosition
,
127 const wxSize
& size
= wxDefaultSize
,
129 const wxString
& name
= wxPanelNameStr
);
132 #if wxUSE_WX_RESOURCES
133 virtual bool LoadFromResource( wxWindow
*parent
, const wxString
& resourceName
,
134 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
135 virtual wxControl
*CreateItem(const wxItemResource
* childResource
, const wxItemResource
* parentResource
,
136 const wxResourceTable
*table
= (const wxResourceTable
*) NULL
);
139 bool Close( bool force
= FALSE
);
140 virtual bool Destroy();
141 virtual bool DestroyChildren();
143 virtual void PrepareDC( wxDC
&dc
);
145 virtual void SetSize( int x
, int y
, int width
, int height
,
146 int sizeFlags
= wxSIZE_AUTO
);
147 virtual void SetSize( int width
, int height
);
149 virtual void Move( int x
, int y
);
151 virtual void GetSize( int *width
, int *height
) const;
152 wxSize
GetSize() const { int w
, h
; GetSize(& w
, & h
); return wxSize(w
, h
); }
154 virtual void SetClientSize( int const width
, int const height
);
156 virtual void GetClientSize( int *width
, int *height
) const;
157 wxSize
GetClientSize() const { int w
, h
; GetClientSize(& w
, & h
); return wxSize(w
, h
); }
159 virtual void GetPosition( int *x
, int *y
) const;
160 wxPoint
GetPosition() const { int w
, h
; GetPosition(& w
, & h
); return wxPoint(w
, h
); }
162 wxRect
GetRect() const
163 { int x
, y
, w
, h
; GetPosition(& x
, & y
); GetSize(& w
, & h
); return wxRect(x
, y
, w
, h
); }
165 virtual void Centre( int direction
= wxHORIZONTAL
);
166 inline void Center(int direction
= wxHORIZONTAL
) { Centre(direction
); }
169 virtual void SetSizeHints( int minW
, int minH
, int maxW
= -1, int maxH
= -1, int incW
= -1, int incH
= -1 );
171 /* Dialog units translations. Implemented in wincmn.cpp. */
172 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
173 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
174 inline wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
175 { wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
))); return wxSize(pt
.x
, pt
.y
); }
176 inline wxSize
ConvertDialogToPixels( const wxSize
& sz
)
177 { wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
))); return wxSize(pt
.x
, pt
.y
); }
179 void OnSize( wxSizeEvent
&event
);
181 virtual bool Show( bool show
);
182 virtual void Enable( bool enable
);
183 virtual void MakeModal( bool modal
);
184 virtual bool IsEnabled() const { return m_isEnabled
; }
185 inline bool Enabled() const { return IsEnabled(); }
186 virtual bool OnClose();
188 virtual void SetFocus();
189 static wxWindow
*FindFocus();
191 virtual void AddChild( wxWindow
*child
);
192 wxList
& GetChildren() { return m_children
; }
194 virtual void RemoveChild( wxWindow
*child
);
195 void SetReturnCode( int retCode
);
197 wxWindow
*GetParent() const
199 wxWindow
*GetGrandParent() const
200 { return (m_parent
? m_parent
->m_parent
: (wxWindow
*)NULL
); }
201 void SetParent( wxWindow
*parent
)
202 { m_parent
= parent
; }
203 virtual wxWindow
*ReParent( wxWindow
*newParent
);
205 wxEvtHandler
*GetEventHandler() const;
206 void SetEventHandler( wxEvtHandler
*handler
);
207 void PushEventHandler( wxEvtHandler
*handler
);
208 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
210 virtual wxValidator
*GetValidator();
211 virtual void SetValidator( const wxValidator
&validator
);
213 virtual void SetClientObject( wxClientData
*data
);
214 virtual wxClientData
*GetClientObject();
216 virtual void SetClientData( void *data
);
217 virtual void *GetClientData();
219 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
);
220 virtual wxAcceleratorTable
*GetAcceleratorTable() { return &m_acceleratorTable
; }
222 bool IsBeingDeleted();
224 void SetId( wxWindowID id
);
225 wxWindowID
GetId() const;
227 void SetCursor( const wxCursor
&cursor
);
229 void WarpPointer(int x
, int y
);
231 virtual void Refresh( bool eraseBackground
= TRUE
, const wxRect
*rect
= (const wxRect
*) NULL
);
232 virtual void Clear();
234 virtual wxRegion
GetUpdateRegion() const;
235 virtual bool IsExposed(int x
, int y
) const;
236 virtual bool IsExposed(int x
, int y
, int w
, int h
) const;
237 virtual bool IsExposed(const wxPoint
& pt
) const;
238 virtual bool IsExposed(const wxRect
& rect
) const;
240 virtual wxColour
GetBackgroundColour() const;
241 virtual void SetBackgroundColour( const wxColour
&colour
);
242 virtual wxColour
GetForegroundColour() const;
243 virtual void SetForegroundColour( const wxColour
&colour
);
245 virtual int GetCharHeight() const;
246 virtual int GetCharWidth() const;
247 virtual void GetTextExtent( const wxString
& string
, int *x
, int *y
,
248 int *descent
= (int *) NULL
,
249 int *externalLeading
= (int *) NULL
,
250 const wxFont
*theFont
= (const wxFont
*) NULL
, bool use16
= FALSE
) const;
252 virtual void SetFont( const wxFont
&font
);
253 virtual wxFont
& GetFont() { return m_font
; }
255 // For backward compatibility
256 inline virtual void SetButtonFont(const wxFont
& font
) { SetFont(font
); }
257 inline virtual void SetLabelFont(const wxFont
& font
) { SetFont(font
); }
258 inline virtual wxFont
& GetLabelFont() { return GetFont(); };
259 inline virtual wxFont
& GetButtonFont() { return GetFont(); };
261 virtual void SetWindowStyleFlag( long flag
);
262 virtual long GetWindowStyleFlag() const;
264 virtual void CaptureMouse();
265 virtual void ReleaseMouse();
267 virtual void SetTitle( const wxString
&title
);
268 virtual wxString
GetTitle() const;
269 virtual void SetName( const wxString
&name
);
270 virtual wxString
GetName() const;
271 virtual wxString
GetLabel() const;
273 void OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) ) {};
274 void OnKeyDown( wxKeyEvent
&event
);
276 virtual bool IsShown() const;
278 virtual void Raise();
279 virtual void Lower();
281 virtual bool IsRetained();
282 virtual wxWindow
*FindWindow( long id
);
283 virtual wxWindow
*FindWindow( const wxString
& name
);
285 void AllowDoubleClick( bool WXUNUSED(allow
) ) {};
286 void SetDoubleClick( bool WXUNUSED(allow
) ) {};
288 virtual void ClientToScreen( int *x
, int *y
);
289 virtual void ScreenToClient( int *x
, int *y
);
291 virtual bool Validate();
292 virtual bool TransferDataToWindow();
293 virtual bool TransferDataFromWindow();
294 void OnInitDialog( wxInitDialogEvent
&event
);
295 virtual void InitDialog();
297 virtual bool PopupMenu( wxMenu
*menu
, int x
, int y
);
299 #if wxUSE_DRAG_AND_DROP
300 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
301 virtual wxDropTarget
*GetDropTarget() const;
304 virtual void SetScrollbar( int orient
, int pos
, int thumbVisible
,
305 int range
, bool refresh
= TRUE
);
306 virtual void SetScrollPos( int orient
, int pos
, bool refresh
= TRUE
);
307 virtual int GetScrollPos( int orient
) const;
308 virtual int GetScrollThumb( int orient
) const;
309 virtual int GetScrollRange( int orient
) const;
310 virtual void ScrollWindow( int dx
, int dy
, const wxRect
* rect
= (wxRect
*) NULL
);
312 virtual bool AcceptsFocus() const;
314 void UpdateWindowUI();
318 void PreCreation( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
,
319 const wxSize
&size
, long style
, const wxString
&name
);
322 virtual GtkWidget
* GetConnectWidget();
323 virtual bool IsOwnGtkWindow( GdkWindow
*window
);
324 void ConnectWidget( GtkWidget
*widget
);
328 virtual wxPoint
GetClientAreaOrigin() const;
329 virtual void AdjustForParentClientOrigin( int& x
, int& y
, int sizeFlags
);
331 GtkStyle
*GetWidgetStyle();
332 void SetWidgetStyle();
333 virtual void ApplyWidgetStyle();
335 virtual void OnInternalIdle();
340 int m_width
,m_height
;
341 int m_minWidth
,m_minHeight
;
342 int m_maxWidth
,m_maxHeight
;
344 wxEvtHandler
*m_eventHandler
;
345 wxValidator
*m_windowValidator
;
346 #if wxUSE_DRAG_AND_DROP
347 wxDropTarget
*m_dropTarget
;
349 wxWindowID m_windowId
;
352 wxColour m_backgroundColour
;
353 wxColour m_foregroundColour
;
354 wxRegion m_updateRegion
;
358 wxString m_windowName
;
359 wxAcceleratorTable m_acceleratorTable
;
360 wxClientData
*m_clientObject
;
364 GtkWidget
*m_wxwindow
;
365 GtkAdjustment
*m_hAdjust
,*m_vAdjust
;
366 float m_oldHorizontalPos
;
367 float m_oldVerticalPos
;
375 GtkStyle
*m_widgetStyle
;
379 wxInsertChildFunction m_insertCallback
;
383 wxLayoutConstraints
*m_constraints
;
384 wxList
*m_constraintsInvolvedIn
;
385 wxSizer
*m_windowSizer
;
386 wxWindow
*m_sizerParent
;
389 wxLayoutConstraints
*GetConstraints() const;
390 void SetConstraints( wxLayoutConstraints
*constraints
);
391 void SetAutoLayout( bool autoLayout
);
392 bool GetAutoLayout() const;
394 void SetSizer( wxSizer
*sizer
);
395 wxSizer
*GetSizer() const;
396 void SetSizerParent( wxWindow
*win
);
397 wxWindow
*GetSizerParent() const;
398 void UnsetConstraints(wxLayoutConstraints
*c
);
399 inline wxList
*GetConstraintsInvolvedIn() const ;
400 void AddConstraintReference(wxWindow
*otherWin
);
401 void RemoveConstraintReference(wxWindow
*otherWin
);
402 void DeleteRelatedConstraints();
403 virtual void ResetConstraints();
404 virtual void SetConstraintSizes(bool recurse
= TRUE
);
405 virtual bool LayoutPhase1(int *noChanges
);
406 virtual bool LayoutPhase2(int *noChanges
);
407 virtual bool DoPhase(int);
408 virtual void TransformSizerToActual(int *x
, int *y
) const ;
409 virtual void SizerSetSize(int x
, int y
, int w
, int h
);
410 virtual void SizerMove(int x
, int y
);
411 virtual void SetSizeConstraint(int x
, int y
, int w
, int h
);
412 virtual void MoveConstraint(int x
, int y
);
413 virtual void GetSizeConstraint(int *w
, int *h
) const ;
414 virtual void GetClientSizeConstraint(int *w
, int *h
) const ;
415 virtual void GetPositionConstraint(int *x
, int *y
) const ;
418 DECLARE_EVENT_TABLE()
421 #endif // __GTKWINDOWH__