]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk1/window.h
Drag'n'Drop works in a basic form
[wxWidgets.git] / include / wx / gtk1 / window.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: window.h
3// Purpose:
4// Author: Robert Roebling
58614078
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
aed8df38 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifndef __GTKWINDOWH__
12#define __GTKWINDOWH__
13
14#ifdef __GNUG__
bfc6fde4 15 #pragma interface
c801d85f
KB
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"
c801d85f 25#include "wx/region.h"
bcf1fa6b 26#include "wx/accel.h"
c801d85f
KB
27
28//-----------------------------------------------------------------------------
29// global data
30//-----------------------------------------------------------------------------
31
32extern const char *wxFrameNameStr;
e146b8c8 33extern wxWindowList wxTopLevelWindows;
c801d85f 34
bbe0af5b
RR
35//-----------------------------------------------------------------------------
36// global function
37//-----------------------------------------------------------------------------
38
bfc6fde4 39extern wxWindow* wxGetActiveWindow();
bbe0af5b 40
c801d85f
KB
41//-----------------------------------------------------------------------------
42// classes
43//-----------------------------------------------------------------------------
44
45class wxLayoutConstraints;
46class wxSizer;
ac57418f 47class wxDC;
fd0eed64
RR
48class wxClientData;
49class wxVoidClientData;
c801d85f 50class wxWindow;
06cfab17 51#if wxUSE_WX_RESOURCES
bfc6fde4
VZ
52 class wxResourceTable;
53 class wxItemResource;
ac57418f 54#endif
06cfab17 55#if wxUSE_DRAG_AND_DROP
bfc6fde4 56 class wxDropTarget;
ac57418f 57#endif
b1170810 58class wxToolTip;
c801d85f 59
6ca41e57 60//-----------------------------------------------------------------------------
fd0eed64 61// callback definition for inserting a window (internal)
6ca41e57
RR
62//-----------------------------------------------------------------------------
63
64typedef void (*wxInsertChildFunction)( wxWindow*, wxWindow* );
65
c801d85f
KB
66//-----------------------------------------------------------------------------
67// global data
68//-----------------------------------------------------------------------------
69
70extern const char *wxPanelNameStr;
71extern const wxSize wxDefaultSize;
72extern const wxPoint wxDefaultPosition;
73
fd0eed64
RR
74//-----------------------------------------------------------------------------
75// wxClientData
76//-----------------------------------------------------------------------------
77
78class wxClientData
79{
80public:
bfc6fde4
VZ
81 wxClientData() { }
82 virtual ~wxClientData() { }
fd0eed64
RR
83};
84
fd0eed64
RR
85//-----------------------------------------------------------------------------
86// wxStringClientData
87//-----------------------------------------------------------------------------
88
bfc6fde4 89class wxStringClientData : public wxClientData
fd0eed64
RR
90{
91public:
92 wxStringClientData() { }
93 wxStringClientData( wxString &data ) { m_data = data; }
94 void SetData( wxString &data ) { m_data = data; }
95 wxString GetData() const { return m_data; }
8bbe427f 96
fd0eed64
RR
97private:
98 wxString m_data;
99};
100
c801d85f
KB
101//-----------------------------------------------------------------------------
102// wxWindow
103//-----------------------------------------------------------------------------
104
bfc6fde4 105class wxWindow : public wxEvtHandler
c801d85f 106{
bfc6fde4 107 DECLARE_DYNAMIC_CLASS(wxWindow)
8bbe427f 108
aed8df38 109public:
bfc6fde4
VZ
110 // creating the window
111 // -------------------
112 wxWindow();
113 wxWindow(wxWindow *parent, wxWindowID id,
114 const wxPoint& pos = wxDefaultPosition,
115 const wxSize& size = wxDefaultSize,
116 long style = 0,
117 const wxString& name = wxPanelNameStr);
118 bool Create(wxWindow *parent, wxWindowID id,
119 const wxPoint& pos = wxDefaultPosition,
120 const wxSize& size = wxDefaultSize,
121 long style = 0,
122 const wxString& name = wxPanelNameStr);
123 virtual ~wxWindow();
cd0183ca 124
f5abe911 125#if wxUSE_WX_RESOURCES
bfc6fde4
VZ
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
133
134 // closing the window
135 // ------------------
136 bool Close( bool force = FALSE );
137 virtual bool Destroy();
138 virtual bool DestroyChildren();
139
140 bool IsBeingDeleted();
141
142 // moving/resizing
143 // ---------------
144
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); }
149
150 void SetSize( int width, int height )
151 { DoSetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); }
152
153 void SetSize( const wxSize& size )
154 { SetSize( size.x, size.y); }
155
156 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
157 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
158
159 void Move( int x, int y )
160 { DoSetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); }
161
162 void Move(const wxPoint& pt)
163 { Move(pt.x, pt.y); }
164
165 // client size is the size of area available for subwindows
166 void SetClientSize( int width, int height )
167 { DoSetClientSize(width, height); }
168
169 void SetClientSize( const wxSize& size )
170 { DoSetClientSize(size.x, size.y); }
171
172 void SetClientSize(const wxRect& rect)
173 { SetClientSize( rect.width, rect.height ); }
174
175 // get the window position and/or size
176 virtual void GetPosition( int *x, int *y ) const;
177 wxPoint GetPosition() const
178 {
179 int w, h;
180 GetPosition(& w, & h);
181
182 return wxPoint(w, h);
183 }
184
185 virtual void GetSize( int *width, int *height ) const;
186
187 wxSize GetSize() const
188 {
189 int w, h;
190 GetSize(& w, & h);
191 return wxSize(w, h);
192 }
193
194 wxRect GetRect() const
195 {
196 int x, y, w, h;
197 GetPosition(& x, & y);
198 GetSize(& w, & h);
199
200 return wxRect(x, y, w, h);
201 }
cd0183ca 202
bfc6fde4
VZ
203 virtual void GetClientSize( int *width, int *height ) const;
204 wxSize GetClientSize() const
205 {
206 int w, h;
207 GetClientSize(& w, & h);
208 return wxSize(w, h);
209 }
aed8df38 210
bfc6fde4
VZ
211 // position with respect to the the parent window
212 virtual void Centre( int direction = wxHORIZONTAL );
213 void Center(int direction = wxHORIZONTAL) { Centre(direction); }
214 virtual void Fit();
aed8df38 215
bfc6fde4
VZ
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 );
ff8bfdbb 220
bfc6fde4
VZ
221 // Dialog units translations. Implemented in wincmn.cpp.
222 // -----------------------------------------------------
ff8bfdbb 223
bfc6fde4
VZ
224 wxPoint ConvertPixelsToDialog( const wxPoint& pt );
225 wxPoint ConvertDialogToPixels( const wxPoint& pt );
226 wxSize ConvertPixelsToDialog( const wxSize& sz )
227 {
228 wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y)));
229
230 return wxSize(pt.x, pt.y);
231 }
ff8bfdbb 232
bfc6fde4
VZ
233 wxSize ConvertDialogToPixels( const wxSize& sz )
234 {
235 wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y)));
ff8bfdbb 236
bfc6fde4
VZ
237 return wxSize(pt.x, pt.y);
238 }
ff8bfdbb 239
bfc6fde4 240 void OnSize( wxSizeEvent &event );
ff8bfdbb 241
bfc6fde4
VZ
242 // window state
243 // ------------
ff8bfdbb 244
bfc6fde4
VZ
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(); }
2f2aa628 250
bfc6fde4
VZ
251 virtual void SetFocus();
252 static wxWindow *FindFocus();
aed8df38 253
bfc6fde4
VZ
254 void SetReturnCode( int retCode );
255 int GetReturnCode();
fd71308f 256
bfc6fde4
VZ
257 // parent/children relations
258 // -------------------------
aed8df38 259
bfc6fde4
VZ
260 virtual void AddChild( wxWindow *child );
261 wxList& GetChildren() { return m_children; }
aed8df38 262
bfc6fde4 263 virtual void RemoveChild( wxWindow *child );
ff8bfdbb 264
bfc6fde4
VZ
265 wxWindow *GetParent() const
266 { return m_parent; }
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 );
8bbe427f 272
bfc6fde4
VZ
273 // event handler stuff
274 // -------------------
2b854a32 275
bfc6fde4
VZ
276 wxEvtHandler *GetEventHandler() const;
277 void SetEventHandler( wxEvtHandler *handler );
278 void PushEventHandler( wxEvtHandler *handler );
279 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
aed8df38 280
bfc6fde4
VZ
281 // validators and client data
282 // --------------------------
aed8df38 283
bfc6fde4
VZ
284 virtual void SetValidator( const wxValidator &validator );
285 virtual wxValidator *GetValidator();
aed8df38 286
bfc6fde4
VZ
287 virtual void SetClientObject( wxClientData *data );
288 virtual wxClientData *GetClientObject();
8bbe427f 289
bfc6fde4
VZ
290 virtual void SetClientData( void *data );
291 virtual void *GetClientData();
8bbe427f 292
bfc6fde4
VZ
293 // accelerators
294 // ------------
295 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel );
296 virtual wxAcceleratorTable *GetAcceleratorTable() { return &m_acceleratorTable; }
8bbe427f 297
bfc6fde4
VZ
298 void SetId( wxWindowID id );
299 wxWindowID GetId() const;
aed8df38 300
bfc6fde4 301 void SetCursor( const wxCursor &cursor );
aed8df38 302
bfc6fde4 303 virtual void PrepareDC( wxDC &dc );
ff8bfdbb 304
bfc6fde4 305 void WarpPointer(int x, int y);
ff8bfdbb
VZ
306
307#if wxUSE_TOOLTIPS
bfc6fde4
VZ
308 void SetToolTip( const wxString &tip );
309 virtual void SetToolTip( wxToolTip *tip );
310 wxToolTip* GetToolTip() const { return m_toolTip; }
ff8bfdbb 311#endif // wxUSE_TOOLTIPS
b1170810 312
bfc6fde4
VZ
313 virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL );
314 virtual void Clear();
315
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;
321
322 // colours
323 // -------
8bbe427f 324
bfc6fde4
VZ
325 virtual wxColour GetBackgroundColour() const;
326 virtual void SetBackgroundColour( const wxColour &colour );
327 virtual wxColour GetForegroundColour() const;
328 virtual void SetForegroundColour( const wxColour &colour );
aed8df38 329
bfc6fde4
VZ
330 // fonts
331 // -----
cd0183ca 332
bfc6fde4
VZ
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;
aed8df38 339
bfc6fde4
VZ
340 virtual void SetFont( const wxFont &font );
341 virtual wxFont& GetFont() { return m_font; }
8bbe427f 342
fd0eed64 343 // For backward compatibility
bfc6fde4
VZ
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(); };
8bbe427f 348
bfc6fde4
VZ
349 virtual void SetWindowStyleFlag( long flag );
350 virtual long GetWindowStyleFlag() const;
8bbe427f 351
bfc6fde4
VZ
352 virtual void CaptureMouse();
353 virtual void ReleaseMouse();
8bbe427f 354
bfc6fde4
VZ
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;
c801d85f 360
bfc6fde4
VZ
361 void OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) ) { }
362 void OnKeyDown( wxKeyEvent &event );
aed8df38 363
bfc6fde4 364 virtual bool IsShown() const;
e149aaeb 365
bfc6fde4
VZ
366 virtual void Raise();
367 virtual void Lower();
e149aaeb 368
bfc6fde4
VZ
369 virtual bool IsRetained();
370 virtual wxWindow *FindWindow( long id );
371 virtual wxWindow *FindWindow( const wxString& name );
8bbe427f 372
bfc6fde4
VZ
373 void AllowDoubleClick( bool WXUNUSED(allow) ) { }
374 void SetDoubleClick( bool WXUNUSED(allow) ) { }
8bbe427f 375
bfc6fde4
VZ
376 virtual void ClientToScreen( int *x, int *y );
377 virtual void ScreenToClient( int *x, int *y );
aed8df38 378
bfc6fde4
VZ
379 virtual bool Validate();
380 virtual bool TransferDataToWindow();
381 virtual bool TransferDataFromWindow();
382 void OnInitDialog( wxInitDialogEvent &event );
383 virtual void InitDialog();
cd0183ca 384
bfc6fde4 385 virtual bool PopupMenu( wxMenu *menu, int x, int y );
aed8df38 386
06cfab17 387#if wxUSE_DRAG_AND_DROP
bfc6fde4
VZ
388 virtual void SetDropTarget( wxDropTarget *dropTarget );
389 virtual wxDropTarget *GetDropTarget() const;
ac57418f 390#endif
cd0183ca 391
bfc6fde4
VZ
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 );
aed8df38 399
bfc6fde4 400 virtual bool AcceptsFocus() const;
8bbe427f 401
bfc6fde4 402 void UpdateWindowUI();
aed8df38 403
bfc6fde4 404 // implementation
8bbe427f 405
bfc6fde4 406 bool HasVMT();
301cd871 407
ab2b3dd4
RR
408 /* I don't want users to override what's done in idle so everything that
409 has to be done in idle time in order for wxGTK to work is done in
410 OnInternalIdle */
bfc6fde4 411 virtual void OnInternalIdle();
ff8bfdbb 412
f362b96d 413 /* For compatibility across platforms (not in event table) */
20e85460
JS
414 void OnIdle(wxIdleEvent& WXUNUSED(event)) {};
415
bfc6fde4 416 /* used by all classes in the widget creation process */
bfc6fde4
VZ
417 void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos,
418 const wxSize &size, long style, const wxString &name );
419 void PostCreation();
ff8bfdbb 420
bfc6fde4
VZ
421 /* the methods below are required because many native widgets
422 are composed of several subwidgets and setting a style for
423 the widget means setting it for all subwidgets as well.
424 also, it is nor clear, which native widget is the top
425 widget where (most of) the input goes. even tooltips have
426 to be applied to all subwidgets. */
ff8bfdbb 427
bfc6fde4
VZ
428 virtual GtkWidget* GetConnectWidget();
429 virtual bool IsOwnGtkWindow( GdkWindow *window );
430 void ConnectWidget( GtkWidget *widget );
8bbe427f 431
bfc6fde4
VZ
432 GtkStyle *GetWidgetStyle();
433 void SetWidgetStyle();
434 virtual void ApplyWidgetStyle();
ff8bfdbb
VZ
435
436#if wxUSE_TOOLTIPS
bfc6fde4 437 virtual void ApplyToolTip( GtkTooltips *tips, const char *tip );
ff8bfdbb 438#endif // wxUSE_TOOLTIPS
301cd871 439
bfc6fde4
VZ
440 /* private member variables */
441
442 wxWindow *m_parent;
443 wxList m_children;
444 int m_x,m_y;
445 int m_width,m_height;
446 int m_minWidth,m_minHeight;
447 int m_maxWidth,m_maxHeight;
448 int m_retCode;
449 wxEvtHandler *m_eventHandler;
450 wxValidator *m_windowValidator;
06cfab17 451#if wxUSE_DRAG_AND_DROP
bfc6fde4 452 wxDropTarget *m_dropTarget;
ac57418f 453#endif
bfc6fde4
VZ
454 wxWindowID m_windowId;
455 wxCursor *m_cursor;
456 wxFont m_font;
457 wxColour m_backgroundColour;
458 wxColour m_foregroundColour;
459 wxRegion m_updateRegion;
460 long m_windowStyle;
461 bool m_isShown;
462 bool m_isEnabled;
463 wxString m_windowName;
464 wxAcceleratorTable m_acceleratorTable;
465 wxClientData *m_clientObject;
466 void *m_clientData;
ff8bfdbb
VZ
467
468#if wxUSE_TOOLTIPS
bfc6fde4 469 wxToolTip *m_toolTip;
ff8bfdbb 470#endif // wxUSE_TOOLTIPS
bcf1fa6b 471
bfc6fde4
VZ
472 GtkWidget *m_widget;
473 GtkWidget *m_wxwindow;
474 GtkAdjustment *m_hAdjust,*m_vAdjust;
475 float m_oldHorizontalPos;
476 float m_oldVerticalPos;
034be888 477 bool m_needParent; /* ! wxFrame, wxDialog, wxNotebookPage ? */
bfc6fde4
VZ
478 bool m_hasScrolling;
479 bool m_isScrolling;
480 bool m_hasVMT;
481 bool m_sizeSet;
482 bool m_resizing;
483 GdkGC *m_scrollGC;
484 GtkStyle *m_widgetStyle;
034be888
RR
485 bool m_isStaticBox; /* faster than IS_KIND_OF */
486 bool m_isFrame; /* faster than IS_KIND_OF */
487 bool m_acceptsFocus; /* ! wxStaticBox etc. */
bfc6fde4
VZ
488
489 wxInsertChildFunction m_insertCallback;
bcf1fa6b
RR
490
491public:
492
bfc6fde4
VZ
493 wxLayoutConstraints *m_constraints;
494 wxList *m_constraintsInvolvedIn;
495 wxSizer *m_windowSizer;
496 wxWindow *m_sizerParent;
497 bool m_autoLayout;
498
499 wxLayoutConstraints *GetConstraints() const;
500 void SetConstraints( wxLayoutConstraints *constraints );
501 void SetAutoLayout( bool autoLayout );
502 bool GetAutoLayout() const;
503 bool Layout();
504 void SetSizer( wxSizer *sizer );
505 wxSizer *GetSizer() const;
506 void SetSizerParent( wxWindow *win );
507 wxWindow *GetSizerParent() const;
508 void UnsetConstraints(wxLayoutConstraints *c);
509 inline wxList *GetConstraintsInvolvedIn() const ;
510 void AddConstraintReference(wxWindow *otherWin);
511 void RemoveConstraintReference(wxWindow *otherWin);
512 void DeleteRelatedConstraints();
513 virtual void ResetConstraints();
514 virtual void SetConstraintSizes(bool recurse = TRUE);
515 virtual bool LayoutPhase1(int *noChanges);
516 virtual bool LayoutPhase2(int *noChanges);
517 virtual bool DoPhase(int);
518 virtual void TransformSizerToActual(int *x, int *y) const ;
519 virtual void SizerSetSize(int x, int y, int w, int h);
520 virtual void SizerMove(int x, int y);
521 virtual void SetSizeConstraint(int x, int y, int w, int h);
522 virtual void MoveConstraint(int x, int y);
523 virtual void GetSizeConstraint(int *w, int *h) const ;
524 virtual void GetClientSizeConstraint(int *w, int *h) const ;
525 virtual void GetPositionConstraint(int *x, int *y) const ;
526
527protected:
68995f26
VZ
528 // common part of all ctors
529 void Init();
530
bfc6fde4
VZ
531 // this is the virtual function to be overriden in any derived class which
532 // wants to change how SetSize() or Move() works - it is called by all
533 // versions of these functions in the base class
534 virtual void DoSetSize(int x, int y,
535 int width, int height,
536 int sizeFlags = wxSIZE_AUTO);
537
538 // same as DoSetSize() for the client size
539 virtual void DoSetClientSize(int width, int height);
aed8df38 540
68dda785 541private:
bfc6fde4 542 DECLARE_EVENT_TABLE()
c801d85f
KB
543};
544
545#endif // __GTKWINDOWH__