]>
Commit | Line | Data |
---|---|---|
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 | extern 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 | // creating the window | |
121 | // ------------------- | |
122 | wxWindow(); | |
123 | wxWindow(wxWindow *parent, wxWindowID id, | |
124 | const wxPoint& pos = wxDefaultPosition, | |
125 | const wxSize& size = wxDefaultSize, | |
126 | long style = 0, | |
127 | const wxString& name = wxPanelNameStr); | |
128 | bool Create(wxWindow *parent, wxWindowID id, | |
129 | const wxPoint& pos = wxDefaultPosition, | |
130 | const wxSize& size = wxDefaultSize, | |
131 | long style = 0, | |
132 | const wxString& name = wxPanelNameStr); | |
133 | virtual ~wxWindow(); | |
134 | ||
135 | #if wxUSE_WX_RESOURCES | |
136 | virtual bool LoadFromResource(wxWindow *parent, | |
137 | const wxString& resourceName, | |
138 | const wxResourceTable *table = (const wxResourceTable *) NULL); | |
139 | virtual wxControl *CreateItem(const wxItemResource* childResource, | |
140 | const wxItemResource* parentResource, | |
141 | const wxResourceTable *table = (const wxResourceTable *) NULL); | |
142 | #endif // wxUSE_WX_RESOURCES | |
143 | ||
144 | // closing the window | |
145 | // ------------------ | |
146 | bool Close( bool force = FALSE ); | |
147 | virtual bool Destroy(); | |
148 | virtual bool DestroyChildren(); | |
149 | ||
150 | bool IsBeingDeleted(); | |
151 | ||
152 | // moving/resizing | |
153 | // --------------- | |
154 | ||
155 | // set the window size and/or position | |
156 | void SetSize( int x, int y, int width, int height, | |
157 | int sizeFlags = wxSIZE_AUTO ) | |
158 | { DoSetSize(x, y, width, height, sizeFlags); } | |
159 | ||
160 | void SetSize( int width, int height ) | |
161 | { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); } | |
162 | ||
163 | void SetSize( const wxSize& size ) | |
164 | { SetSize( size.x, size.y); } | |
165 | ||
166 | void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO) | |
167 | { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); } | |
168 | ||
169 | void Move( int x, int y ) | |
170 | { DoSetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); } | |
171 | ||
172 | void Move(const wxPoint& pt) | |
173 | { Move(pt.x, pt.y); } | |
174 | ||
175 | // client size is the size of area available for subwindows | |
176 | void SetClientSize( int width, int height ) | |
177 | { DoSetClientSize(width, height); } | |
178 | ||
179 | void SetClientSize( const wxSize& size ) | |
180 | { DoSetClientSize(size.x, size.y); } | |
181 | ||
182 | void SetClientSize(const wxRect& rect) | |
183 | { SetClientSize( rect.width, rect.height ); } | |
184 | ||
185 | // get the window position and/or size | |
186 | virtual void GetPosition( int *x, int *y ) const; | |
187 | wxPoint GetPosition() const | |
188 | { | |
189 | int w, h; | |
190 | GetPosition(& w, & h); | |
191 | ||
192 | return wxPoint(w, h); | |
193 | } | |
194 | ||
195 | virtual void GetSize( int *width, int *height ) const; | |
196 | ||
197 | wxSize GetSize() const | |
198 | { | |
199 | int w, h; | |
200 | GetSize(& w, & h); | |
201 | return wxSize(w, h); | |
202 | } | |
203 | ||
204 | wxRect GetRect() const | |
205 | { | |
206 | int x, y, w, h; | |
207 | GetPosition(& x, & y); | |
208 | GetSize(& w, & h); | |
209 | ||
210 | return wxRect(x, y, w, h); | |
211 | } | |
212 | ||
213 | virtual void GetClientSize( int *width, int *height ) const; | |
214 | wxSize GetClientSize() const | |
215 | { | |
216 | int w, h; | |
217 | GetClientSize(& w, & h); | |
218 | return wxSize(w, h); | |
219 | } | |
220 | ||
221 | // position with respect to the the parent window | |
222 | virtual void Centre( int direction = wxHORIZONTAL ); | |
223 | void Center(int direction = wxHORIZONTAL) { Centre(direction); } | |
224 | virtual void Fit(); | |
225 | ||
226 | // set min/max size of the window | |
227 | virtual void SetSizeHints( int minW, int minH, | |
228 | int maxW = -1, int maxH = -1, | |
229 | int incW = -1, int incH = -1 ); | |
230 | ||
231 | // Dialog units translations. Implemented in wincmn.cpp. | |
232 | // ----------------------------------------------------- | |
233 | ||
234 | wxPoint ConvertPixelsToDialog( const wxPoint& pt ); | |
235 | wxPoint ConvertDialogToPixels( const wxPoint& pt ); | |
236 | wxSize ConvertPixelsToDialog( const wxSize& sz ) | |
237 | { | |
238 | wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); | |
239 | ||
240 | return wxSize(pt.x, pt.y); | |
241 | } | |
242 | ||
243 | wxSize ConvertDialogToPixels( const wxSize& sz ) | |
244 | { | |
245 | wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); | |
246 | ||
247 | return wxSize(pt.x, pt.y); | |
248 | } | |
249 | ||
250 | void OnSize( wxSizeEvent &event ); | |
251 | ||
252 | // window state | |
253 | // ------------ | |
254 | ||
255 | virtual bool Show( bool show ); | |
256 | virtual void Enable( bool enable ); | |
257 | virtual void MakeModal( bool modal ); | |
258 | virtual bool IsEnabled() const { return m_isEnabled; } | |
259 | inline bool Enabled() const { return IsEnabled(); } | |
260 | ||
261 | virtual void SetFocus(); | |
262 | static wxWindow *FindFocus(); | |
263 | ||
264 | void SetReturnCode( int retCode ); | |
265 | int GetReturnCode(); | |
266 | ||
267 | // parent/children relations | |
268 | // ------------------------- | |
269 | ||
270 | virtual void AddChild( wxWindow *child ); | |
271 | wxList& GetChildren() { return m_children; } | |
272 | ||
273 | virtual void RemoveChild( wxWindow *child ); | |
274 | ||
275 | wxWindow *GetParent() const | |
276 | { return m_parent; } | |
277 | wxWindow *GetGrandParent() const | |
278 | { return (m_parent ? m_parent->m_parent : (wxWindow*)NULL); } | |
279 | void SetParent( wxWindow *parent ) | |
280 | { m_parent = parent; } | |
281 | virtual wxWindow *ReParent( wxWindow *newParent ); | |
282 | ||
283 | // event handler stuff | |
284 | // ------------------- | |
285 | ||
286 | wxEvtHandler *GetEventHandler() const; | |
287 | void SetEventHandler( wxEvtHandler *handler ); | |
288 | void PushEventHandler( wxEvtHandler *handler ); | |
289 | wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE ); | |
290 | ||
291 | // validators and client data | |
292 | // -------------------------- | |
293 | ||
294 | virtual void SetValidator( const wxValidator &validator ); | |
295 | virtual wxValidator *GetValidator(); | |
296 | ||
297 | virtual void SetClientObject( wxClientData *data ); | |
298 | virtual wxClientData *GetClientObject(); | |
299 | ||
300 | virtual void SetClientData( void *data ); | |
301 | virtual void *GetClientData(); | |
302 | ||
303 | // accelerators | |
304 | // ------------ | |
305 | virtual void SetAcceleratorTable( const wxAcceleratorTable& accel ); | |
306 | virtual wxAcceleratorTable *GetAcceleratorTable() { return &m_acceleratorTable; } | |
307 | ||
308 | void SetId( wxWindowID id ); | |
309 | wxWindowID GetId() const; | |
310 | ||
311 | void SetCursor( const wxCursor &cursor ); | |
312 | ||
313 | virtual void PrepareDC( wxDC &dc ); | |
314 | ||
315 | void WarpPointer(int x, int y); | |
316 | ||
317 | #if wxUSE_TOOLTIPS | |
318 | void SetToolTip( const wxString &tip ); | |
319 | virtual void SetToolTip( wxToolTip *tip ); | |
320 | wxToolTip* GetToolTip() const { return m_toolTip; } | |
321 | #endif // wxUSE_TOOLTIPS | |
322 | ||
323 | virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL ); | |
324 | virtual void Clear(); | |
325 | ||
326 | virtual wxRegion GetUpdateRegion() const; | |
327 | virtual bool IsExposed( int x, int y ) const; | |
328 | virtual bool IsExposed( int x, int y, int w, int h ) const; | |
329 | virtual bool IsExposed( const wxPoint& pt ) const; | |
330 | virtual bool IsExposed( const wxRect& rect ) const; | |
331 | ||
332 | // colours | |
333 | // ------- | |
334 | ||
335 | virtual wxColour GetBackgroundColour() const; | |
336 | virtual void SetBackgroundColour( const wxColour &colour ); | |
337 | virtual wxColour GetForegroundColour() const; | |
338 | virtual void SetForegroundColour( const wxColour &colour ); | |
339 | ||
340 | // fonts | |
341 | // ----- | |
342 | ||
343 | virtual int GetCharHeight() const; | |
344 | virtual int GetCharWidth() const; | |
345 | virtual void GetTextExtent( const wxString& string, int *x, int *y, | |
346 | int *descent = (int *) NULL, | |
347 | int *externalLeading = (int *) NULL, | |
348 | const wxFont *theFont = (const wxFont *) NULL, bool use16 = FALSE) const; | |
349 | ||
350 | virtual void SetFont( const wxFont &font ); | |
351 | virtual wxFont& GetFont() { return m_font; } | |
352 | ||
353 | // For backward compatibility | |
354 | virtual void SetButtonFont(const wxFont& font) { SetFont(font); } | |
355 | virtual void SetLabelFont(const wxFont& font) { SetFont(font); } | |
356 | virtual wxFont& GetLabelFont() { return GetFont(); }; | |
357 | virtual wxFont& GetButtonFont() { return GetFont(); }; | |
358 | ||
359 | virtual void SetWindowStyleFlag( long flag ); | |
360 | virtual long GetWindowStyleFlag() const; | |
361 | ||
362 | virtual void CaptureMouse(); | |
363 | virtual void ReleaseMouse(); | |
364 | ||
365 | virtual void SetTitle( const wxString &title ); | |
366 | virtual wxString GetTitle() const; | |
367 | virtual void SetName( const wxString &name ); | |
368 | virtual wxString GetName() const; | |
369 | virtual wxString GetLabel() const; | |
370 | ||
371 | void OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) ) { } | |
372 | void OnKeyDown( wxKeyEvent &event ); | |
373 | ||
374 | virtual bool IsShown() const; | |
375 | ||
376 | virtual void Raise(); | |
377 | virtual void Lower(); | |
378 | ||
379 | virtual bool IsRetained(); | |
380 | virtual wxWindow *FindWindow( long id ); | |
381 | virtual wxWindow *FindWindow( const wxString& name ); | |
382 | ||
383 | void AllowDoubleClick( bool WXUNUSED(allow) ) { } | |
384 | void SetDoubleClick( bool WXUNUSED(allow) ) { } | |
385 | ||
386 | virtual void ClientToScreen( int *x, int *y ); | |
387 | virtual void ScreenToClient( int *x, int *y ); | |
388 | ||
389 | virtual bool Validate(); | |
390 | virtual bool TransferDataToWindow(); | |
391 | virtual bool TransferDataFromWindow(); | |
392 | void OnInitDialog( wxInitDialogEvent &event ); | |
393 | virtual void InitDialog(); | |
394 | ||
395 | virtual bool PopupMenu( wxMenu *menu, int x, int y ); | |
396 | ||
397 | #if wxUSE_DRAG_AND_DROP | |
398 | virtual void SetDropTarget( wxDropTarget *dropTarget ); | |
399 | virtual wxDropTarget *GetDropTarget() const; | |
400 | #endif | |
401 | ||
402 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, | |
403 | int range, bool refresh = TRUE ); | |
404 | virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ); | |
405 | virtual int GetScrollPos( int orient ) const; | |
406 | virtual int GetScrollThumb( int orient ) const; | |
407 | virtual int GetScrollRange( int orient ) const; | |
408 | virtual void ScrollWindow( int dx, int dy, const wxRect* rect = (wxRect *) NULL ); | |
409 | ||
410 | virtual bool AcceptsFocus() const; | |
411 | ||
412 | void UpdateWindowUI(); | |
413 | ||
414 | // implementation | |
415 | ||
416 | virtual wxPoint GetClientAreaOrigin() const; | |
417 | virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ); | |
418 | ||
419 | bool HasVMT(); | |
420 | ||
421 | virtual void OnInternalIdle(); | |
422 | ||
423 | /* used by all classes in the widget creation process */ | |
424 | ||
425 | void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, | |
426 | const wxSize &size, long style, const wxString &name ); | |
427 | void PostCreation(); | |
428 | ||
429 | /* the methods below are required because many native widgets | |
430 | are composed of several subwidgets and setting a style for | |
431 | the widget means setting it for all subwidgets as well. | |
432 | also, it is nor clear, which native widget is the top | |
433 | widget where (most of) the input goes. even tooltips have | |
434 | to be applied to all subwidgets. */ | |
435 | ||
436 | virtual GtkWidget* GetConnectWidget(); | |
437 | virtual bool IsOwnGtkWindow( GdkWindow *window ); | |
438 | void ConnectWidget( GtkWidget *widget ); | |
439 | ||
440 | GtkStyle *GetWidgetStyle(); | |
441 | void SetWidgetStyle(); | |
442 | virtual void ApplyWidgetStyle(); | |
443 | ||
444 | #if wxUSE_TOOLTIPS | |
445 | virtual void ApplyToolTip( GtkTooltips *tips, const char *tip ); | |
446 | #endif // wxUSE_TOOLTIPS | |
447 | ||
448 | /* private member variables */ | |
449 | ||
450 | wxWindow *m_parent; | |
451 | wxList m_children; | |
452 | int m_x,m_y; | |
453 | int m_width,m_height; | |
454 | int m_minWidth,m_minHeight; | |
455 | int m_maxWidth,m_maxHeight; | |
456 | int m_retCode; | |
457 | wxEvtHandler *m_eventHandler; | |
458 | wxValidator *m_windowValidator; | |
459 | #if wxUSE_DRAG_AND_DROP | |
460 | wxDropTarget *m_dropTarget; | |
461 | #endif | |
462 | wxWindowID m_windowId; | |
463 | wxCursor *m_cursor; | |
464 | wxFont m_font; | |
465 | wxColour m_backgroundColour; | |
466 | wxColour m_foregroundColour; | |
467 | wxRegion m_updateRegion; | |
468 | long m_windowStyle; | |
469 | bool m_isShown; | |
470 | bool m_isEnabled; | |
471 | wxString m_windowName; | |
472 | wxAcceleratorTable m_acceleratorTable; | |
473 | wxClientData *m_clientObject; | |
474 | void *m_clientData; | |
475 | ||
476 | #if wxUSE_TOOLTIPS | |
477 | wxToolTip *m_toolTip; | |
478 | #endif // wxUSE_TOOLTIPS | |
479 | ||
480 | GtkWidget *m_widget; | |
481 | GtkWidget *m_wxwindow; | |
482 | GtkAdjustment *m_hAdjust,*m_vAdjust; | |
483 | float m_oldHorizontalPos; | |
484 | float m_oldVerticalPos; | |
485 | bool m_needParent; | |
486 | bool m_hasScrolling; | |
487 | bool m_isScrolling; | |
488 | bool m_hasVMT; | |
489 | bool m_sizeSet; | |
490 | bool m_resizing; | |
491 | GdkGC *m_scrollGC; | |
492 | GtkStyle *m_widgetStyle; | |
493 | bool m_isStaticBox; | |
494 | bool m_acceptsFocus; | |
495 | ||
496 | wxInsertChildFunction m_insertCallback; | |
497 | ||
498 | public: | |
499 | ||
500 | wxLayoutConstraints *m_constraints; | |
501 | wxList *m_constraintsInvolvedIn; | |
502 | wxSizer *m_windowSizer; | |
503 | wxWindow *m_sizerParent; | |
504 | bool m_autoLayout; | |
505 | ||
506 | wxLayoutConstraints *GetConstraints() const; | |
507 | void SetConstraints( wxLayoutConstraints *constraints ); | |
508 | void SetAutoLayout( bool autoLayout ); | |
509 | bool GetAutoLayout() const; | |
510 | bool Layout(); | |
511 | void SetSizer( wxSizer *sizer ); | |
512 | wxSizer *GetSizer() const; | |
513 | void SetSizerParent( wxWindow *win ); | |
514 | wxWindow *GetSizerParent() const; | |
515 | void UnsetConstraints(wxLayoutConstraints *c); | |
516 | inline wxList *GetConstraintsInvolvedIn() const ; | |
517 | void AddConstraintReference(wxWindow *otherWin); | |
518 | void RemoveConstraintReference(wxWindow *otherWin); | |
519 | void DeleteRelatedConstraints(); | |
520 | virtual void ResetConstraints(); | |
521 | virtual void SetConstraintSizes(bool recurse = TRUE); | |
522 | virtual bool LayoutPhase1(int *noChanges); | |
523 | virtual bool LayoutPhase2(int *noChanges); | |
524 | virtual bool DoPhase(int); | |
525 | virtual void TransformSizerToActual(int *x, int *y) const ; | |
526 | virtual void SizerSetSize(int x, int y, int w, int h); | |
527 | virtual void SizerMove(int x, int y); | |
528 | virtual void SetSizeConstraint(int x, int y, int w, int h); | |
529 | virtual void MoveConstraint(int x, int y); | |
530 | virtual void GetSizeConstraint(int *w, int *h) const ; | |
531 | virtual void GetClientSizeConstraint(int *w, int *h) const ; | |
532 | virtual void GetPositionConstraint(int *x, int *y) const ; | |
533 | ||
534 | protected: | |
535 | // common part of all ctors | |
536 | void Init(); | |
537 | ||
538 | // this is the virtual function to be overriden in any derived class which | |
539 | // wants to change how SetSize() or Move() works - it is called by all | |
540 | // versions of these functions in the base class | |
541 | virtual void DoSetSize(int x, int y, | |
542 | int width, int height, | |
543 | int sizeFlags = wxSIZE_AUTO); | |
544 | ||
545 | // same as DoSetSize() for the client size | |
546 | virtual void DoSetClientSize(int width, int height); | |
547 | ||
548 | private: | |
549 | DECLARE_EVENT_TABLE() | |
550 | }; | |
551 | ||
552 | #endif // __GTKWINDOWH__ |