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 wxWindowList wxTopLevelWindows
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 extern wxWindow
* wxGetActiveWindow();
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 class wxLayoutConstraints
;
49 class wxVoidClientData
;
51 #if wxUSE_WX_RESOURCES
52 class wxResourceTable
;
55 #if wxUSE_DRAG_AND_DROP
60 //-----------------------------------------------------------------------------
61 // callback definition for inserting a window (internal)
62 //-----------------------------------------------------------------------------
64 typedef void (*wxInsertChildFunction
)( wxWindow
*, wxWindow
* );
66 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 extern const char *wxPanelNameStr
;
71 extern const wxSize wxDefaultSize
;
72 extern const wxPoint wxDefaultPosition
;
74 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
82 virtual ~wxClientData() { }
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
89 class wxStringClientData
: public wxClientData
92 wxStringClientData() { }
93 wxStringClientData( wxString
&data
) { m_data
= data
; }
94 void SetData( wxString
&data
) { m_data
= data
; }
95 wxString
GetData() const { return m_data
; }
101 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
105 class wxWindow
: public wxEvtHandler
107 DECLARE_DYNAMIC_CLASS(wxWindow
)
110 // creating the window
111 // -------------------
113 wxWindow(wxWindow
*parent
, wxWindowID id
,
114 const wxPoint
& pos
= wxDefaultPosition
,
115 const wxSize
& size
= wxDefaultSize
,
117 const wxString
& name
= wxPanelNameStr
);
118 bool Create(wxWindow
*parent
, wxWindowID id
,
119 const wxPoint
& pos
= wxDefaultPosition
,
120 const wxSize
& size
= wxDefaultSize
,
122 const wxString
& name
= wxPanelNameStr
);
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
134 // closing the window
135 // ------------------
136 bool Close( bool force
= FALSE
);
137 virtual bool Destroy();
138 virtual bool DestroyChildren();
140 bool IsBeingDeleted();
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
); }
150 void SetSize( int width
, int height
)
151 { DoSetSize( -1, -1, width
, height
, wxSIZE_USE_EXISTING
); }
153 void SetSize( const wxSize
& size
)
154 { SetSize( size
.x
, size
.y
); }
156 void SetSize(const wxRect
& rect
, int sizeFlags
= wxSIZE_AUTO
)
157 { DoSetSize(rect
.x
, rect
.y
, rect
.width
, rect
.height
, sizeFlags
); }
159 void Move( int x
, int y
)
160 { DoSetSize( x
, y
, -1, -1, wxSIZE_USE_EXISTING
); }
162 void Move(const wxPoint
& pt
)
163 { Move(pt
.x
, pt
.y
); }
165 // client size is the size of area available for subwindows
166 void SetClientSize( int width
, int height
)
167 { DoSetClientSize(width
, height
); }
169 void SetClientSize( const wxSize
& size
)
170 { DoSetClientSize(size
.x
, size
.y
); }
172 void SetClientSize(const wxRect
& rect
)
173 { SetClientSize( rect
.width
, rect
.height
); }
175 // get the window position and/or size
176 virtual void GetPosition( int *x
, int *y
) const;
177 wxPoint
GetPosition() const
180 GetPosition(& w
, & h
);
182 return wxPoint(w
, h
);
185 virtual void GetSize( int *width
, int *height
) const;
187 wxSize
GetSize() const
194 wxRect
GetRect() const
197 GetPosition(& x
, & y
);
200 return wxRect(x
, y
, w
, h
);
203 virtual void GetClientSize( int *width
, int *height
) const;
204 wxSize
GetClientSize() const
207 GetClientSize(& w
, & h
);
211 // position with respect to the the parent window
212 virtual void Centre( int direction
= wxHORIZONTAL
);
213 void Center(int direction
= wxHORIZONTAL
) { Centre(direction
); }
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 );
221 // Dialog units translations. Implemented in wincmn.cpp.
222 // -----------------------------------------------------
224 wxPoint
ConvertPixelsToDialog( const wxPoint
& pt
);
225 wxPoint
ConvertDialogToPixels( const wxPoint
& pt
);
226 wxSize
ConvertPixelsToDialog( const wxSize
& sz
)
228 wxPoint
pt(ConvertPixelsToDialog(wxPoint(sz
.x
, sz
.y
)));
230 return wxSize(pt
.x
, pt
.y
);
233 wxSize
ConvertDialogToPixels( const wxSize
& sz
)
235 wxPoint
pt(ConvertDialogToPixels(wxPoint(sz
.x
, sz
.y
)));
237 return wxSize(pt
.x
, pt
.y
);
240 void OnSize( wxSizeEvent
&event
);
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(); }
251 virtual void SetFocus();
252 static wxWindow
*FindFocus();
254 void SetReturnCode( int retCode
);
257 // parent/children relations
258 // -------------------------
260 virtual void AddChild( wxWindow
*child
);
261 wxList
& GetChildren() { return m_children
; }
263 virtual void RemoveChild( wxWindow
*child
);
265 wxWindow
*GetParent() const
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
);
273 // event handler stuff
274 // -------------------
276 wxEvtHandler
*GetEventHandler() const;
277 void SetEventHandler( wxEvtHandler
*handler
);
278 void PushEventHandler( wxEvtHandler
*handler
);
279 wxEvtHandler
*PopEventHandler( bool deleteHandler
= FALSE
);
281 // validators and client data
282 // --------------------------
284 virtual void SetValidator( const wxValidator
&validator
);
285 virtual wxValidator
*GetValidator();
287 virtual void SetClientObject( wxClientData
*data
);
288 virtual wxClientData
*GetClientObject();
290 virtual void SetClientData( void *data
);
291 virtual void *GetClientData();
295 virtual void SetAcceleratorTable( const wxAcceleratorTable
& accel
);
296 virtual wxAcceleratorTable
*GetAcceleratorTable() { return &m_acceleratorTable
; }
298 void SetId( wxWindowID id
);
299 wxWindowID
GetId() const;
301 void SetCursor( const wxCursor
&cursor
);
303 virtual void PrepareDC( wxDC
&dc
);
305 void WarpPointer(int x
, int y
);
308 void SetToolTip( const wxString
&tip
);
309 virtual void SetToolTip( wxToolTip
*tip
);
310 wxToolTip
* GetToolTip() const { return m_toolTip
; }
311 #endif // wxUSE_TOOLTIPS
313 virtual void Refresh( bool eraseBackground
= TRUE
, const wxRect
*rect
= (const wxRect
*) NULL
);
314 virtual void Clear();
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;
325 virtual wxColour
GetBackgroundColour() const;
326 virtual void SetBackgroundColour( const wxColour
&colour
);
327 virtual wxColour
GetForegroundColour() const;
328 virtual void SetForegroundColour( const wxColour
&colour
);
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;
340 virtual void SetFont( const wxFont
&font
);
341 virtual wxFont
& GetFont() { return m_font
; }
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(); };
349 virtual void SetWindowStyleFlag( long flag
);
350 virtual long GetWindowStyleFlag() const;
352 virtual void CaptureMouse();
353 virtual void ReleaseMouse();
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;
361 void OnSysColourChanged( wxSysColourChangedEvent
&WXUNUSED(event
) ) { }
362 void OnKeyDown( wxKeyEvent
&event
);
364 virtual bool IsShown() const;
366 virtual void Raise();
367 virtual void Lower();
369 virtual bool IsRetained();
370 virtual wxWindow
*FindWindow( long id
);
371 virtual wxWindow
*FindWindow( const wxString
& name
);
373 void AllowDoubleClick( bool WXUNUSED(allow
) ) { }
374 void SetDoubleClick( bool WXUNUSED(allow
) ) { }
376 virtual void ClientToScreen( int *x
, int *y
);
377 virtual void ScreenToClient( int *x
, int *y
);
379 virtual bool Validate();
380 virtual bool TransferDataToWindow();
381 virtual bool TransferDataFromWindow();
382 void OnInitDialog( wxInitDialogEvent
&event
);
383 virtual void InitDialog();
385 virtual bool PopupMenu( wxMenu
*menu
, int x
, int y
);
387 #if wxUSE_DRAG_AND_DROP
388 virtual void SetDropTarget( wxDropTarget
*dropTarget
);
389 virtual wxDropTarget
*GetDropTarget() const;
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
);
400 virtual bool AcceptsFocus() const;
402 void UpdateWindowUI();
408 /* I don't want users to override what's done in OnIdle */
409 virtual void OnInternalIdle();
411 /* For compatibility across platforms (not in event table) */
412 void OnIdle(wxIdleEvent
& WXUNUSED(event
)) {};
414 /* used by all classes in the widget creation process */
416 void PreCreation( wxWindow
*parent
, wxWindowID id
, const wxPoint
&pos
,
417 const wxSize
&size
, long style
, const wxString
&name
);
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. */
427 virtual GtkWidget
* GetConnectWidget();
428 virtual bool IsOwnGtkWindow( GdkWindow
*window
);
429 void ConnectWidget( GtkWidget
*widget
);
431 GtkStyle
*GetWidgetStyle();
432 void SetWidgetStyle();
433 virtual void ApplyWidgetStyle();
436 virtual void ApplyToolTip( GtkTooltips
*tips
, const char *tip
);
437 #endif // wxUSE_TOOLTIPS
439 /* private member variables */
444 int m_width
,m_height
;
445 int m_minWidth
,m_minHeight
;
446 int m_maxWidth
,m_maxHeight
;
448 wxEvtHandler
*m_eventHandler
;
449 wxValidator
*m_windowValidator
;
450 #if wxUSE_DRAG_AND_DROP
451 wxDropTarget
*m_dropTarget
;
453 wxWindowID m_windowId
;
456 wxColour m_backgroundColour
;
457 wxColour m_foregroundColour
;
458 wxRegion m_updateRegion
;
462 wxString m_windowName
;
463 wxAcceleratorTable m_acceleratorTable
;
464 wxClientData
*m_clientObject
;
468 wxToolTip
*m_toolTip
;
469 #endif // wxUSE_TOOLTIPS
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 ? */
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. */
488 wxInsertChildFunction m_insertCallback
;
492 wxLayoutConstraints
*m_constraints
;
493 wxList
*m_constraintsInvolvedIn
;
494 wxSizer
*m_windowSizer
;
495 wxWindow
*m_sizerParent
;
498 wxLayoutConstraints
*GetConstraints() const;
499 void SetConstraints( wxLayoutConstraints
*constraints
);
500 void SetAutoLayout( bool autoLayout
);
501 bool GetAutoLayout() const;
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 ;
527 // common part of all ctors
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
);
537 // same as DoSetSize() for the client size
538 virtual void DoSetClientSize(int width
, int height
);
541 DECLARE_EVENT_TABLE()
544 #endif // __GTKWINDOWH__