1
/////////////////////////////////////////////////////////////////////////////
2
// Name: wx/gtk/window.h
4
// Author: Robert Roebling
5
// Id: $Id: window.h 71894 2012-06-30 20:39:06Z PC $
6
// Copyright: (c) 1998 Robert Roebling
7
// Licence: wxWindows licence
8
/////////////////////////////////////////////////////////////////////////////
10
#ifndef _WX_GTK_WINDOW_H_
11
#define _WX_GTK_WINDOW_H_
13
#include "wx/dynarray.h"
16
typedef struct _cairo cairo_t;
17
#define WXUNUSED_IN_GTK3(x)
19
#define WXUNUSED_IN_GTK3(x) x
22
// helper structure that holds class that holds GtkIMContext object and
23
// some additional data needed for key events processing
26
WX_DEFINE_EXPORTED_ARRAY_PTR(GdkWindow *, wxArrayGdkWindows);
31
typedef void (*wxGTKCallback)();
35
//-----------------------------------------------------------------------------
37
//-----------------------------------------------------------------------------
39
class WXDLLIMPEXP_CORE wxWindowGTK : public wxWindowBase
42
// creating the window
43
// -------------------
45
wxWindowGTK(wxWindow *parent,
47
const wxPoint& pos = wxDefaultPosition,
48
const wxSize& size = wxDefaultSize,
50
const wxString& name = wxPanelNameStr);
51
bool Create(wxWindow *parent,
53
const wxPoint& pos = wxDefaultPosition,
54
const wxSize& size = wxDefaultSize,
56
const wxString& name = wxPanelNameStr);
57
virtual ~wxWindowGTK();
59
// implement base class (pure) virtual methods
60
// -------------------------------------------
62
virtual bool Destroy();
67
virtual bool Show( bool show = true );
69
virtual bool IsRetained() const;
71
virtual void SetFocus();
73
// hint from wx to native GTK+ tab traversal code
74
virtual void SetCanFocus(bool canFocus);
76
virtual bool Reparent( wxWindowBase *newParent );
78
virtual void WarpPointer(int x, int y);
80
virtual void Refresh( bool eraseBackground = true,
81
const wxRect *rect = (const wxRect *) NULL );
82
virtual void Update();
83
virtual void ClearBackground();
85
virtual bool SetBackgroundColour( const wxColour &colour );
86
virtual bool SetForegroundColour( const wxColour &colour );
87
virtual bool SetCursor( const wxCursor &cursor );
88
virtual bool SetFont( const wxFont &font );
90
virtual bool SetBackgroundStyle(wxBackgroundStyle style) ;
91
virtual bool IsTransparentBackgroundSupported(wxString* reason = NULL) const;
93
virtual int GetCharHeight() const;
94
virtual int GetCharWidth() const;
96
virtual void SetScrollbar( int orient, int pos, int thumbVisible,
97
int range, bool refresh = true );
98
virtual void SetScrollPos( int orient, int pos, bool refresh = true );
99
virtual int GetScrollPos( int orient ) const;
100
virtual int GetScrollThumb( int orient ) const;
101
virtual int GetScrollRange( int orient ) const;
102
virtual void ScrollWindow( int dx, int dy,
103
const wxRect* rect = NULL );
104
virtual bool ScrollLines(int lines);
105
virtual bool ScrollPages(int pages);
107
#if wxUSE_DRAG_AND_DROP
108
virtual void SetDropTarget( wxDropTarget *dropTarget );
109
#endif // wxUSE_DRAG_AND_DROP
111
virtual void AddChild( wxWindowBase *child );
112
virtual void RemoveChild( wxWindowBase *child );
114
virtual void SetLayoutDirection(wxLayoutDirection dir);
115
virtual wxLayoutDirection GetLayoutDirection() const;
116
virtual wxCoord AdjustForLayoutDirection(wxCoord x,
118
wxCoord widthTotal) const;
120
virtual bool DoIsExposed( int x, int y ) const;
121
virtual bool DoIsExposed( int x, int y, int w, int h ) const;
123
// currently wxGTK2-only
124
void SetDoubleBuffered(bool on);
125
virtual bool IsDoubleBuffered() const;
127
// SetLabel(), which does nothing in wxWindow
128
virtual void SetLabel(const wxString& label) { m_gtkLabel = label; }
129
virtual wxString GetLabel() const { return m_gtkLabel; }
134
virtual WXWidget GetHandle() const { return m_widget; }
136
// many important things are done here, this function must be called
138
virtual void OnInternalIdle();
140
// For compatibility across platforms (not in event table)
141
void OnIdle(wxIdleEvent& WXUNUSED(event)) {}
143
// Used by all window classes in the widget creation process.
144
bool PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size );
147
// Internal addition of child windows
148
void DoAddChild(wxWindowGTK *child);
150
// This method sends wxPaintEvents to the window.
151
// It is also responsible for background erase events.
153
void GTKSendPaintEvents(cairo_t* cr);
155
void GTKSendPaintEvents(const GdkRegion* region);
158
// The methods below are required because many native widgets
159
// are composed of several subwidgets and setting a style for
160
// the widget means setting it for all subwidgets as well.
161
// also, it is not clear which native widget is the top
162
// widget where (most of) the input goes. even tooltips have
163
// to be applied to all subwidgets.
164
virtual GtkWidget* GetConnectWidget();
165
void ConnectWidget( GtkWidget *widget );
167
// Called from several event handlers, if it returns true or false, the
168
// same value should be immediately returned by the handler without doing
169
// anything else. If it returns -1, the handler should continue as usual
170
int GTKCallbackCommonPrologue(struct _GdkEventAny *event) const;
172
// Simplified form of GTKCallbackCommonPrologue() which can be used from
173
// GTK callbacks without return value to check if the event should be
174
// ignored: if this returns true, the event shouldn't be handled
175
bool GTKShouldIgnoreEvent() const;
178
// override this if some events should never be consumed by wxWidgets but
179
// but have to be left for the native control
181
// base version just calls HandleWindowEvent()
182
virtual bool GTKProcessEvent(wxEvent& event) const;
184
// Map GTK widget direction of the given widget to/from wxLayoutDirection
185
static wxLayoutDirection GTKGetLayout(GtkWidget *widget);
186
static void GTKSetLayout(GtkWidget *widget, wxLayoutDirection dir);
188
// return true if this window must have a non-NULL parent, false if it can
189
// be created without parent (normally only top level windows but in wxGTK
190
// there is also the exception of wxMenuBar)
191
virtual bool GTKNeedsParent() const { return !IsTopLevel(); }
193
// This is called when capture is taken from the window. It will
194
// fire off capture lost events.
195
void GTKReleaseMouseAndNotify();
197
GdkWindow* GTKGetDrawingWindow() const;
199
bool GTKHandleFocusIn();
200
bool GTKHandleFocusOut();
201
void GTKHandleFocusOutNoDeferring();
202
static void GTKHandleDeferredFocusOut();
204
// Called when m_widget becomes realized. Derived classes must call the
205
// base class method if they override it.
206
virtual void GTKHandleRealized();
209
// for controls composed of multiple GTK widgets, return true to eliminate
210
// spurious focus events if the focus changes between GTK+ children within
212
virtual bool GTKNeedsToFilterSameWindowFocus() const { return false; }
214
// Override GTKWidgetNeedsMnemonic and return true if your
215
// needs to set its mnemonic widget, such as for a
216
// GtkLabel for wxStaticText, then do the actual
217
// setting of the widget inside GTKWidgetDoSetMnemonic
218
virtual bool GTKWidgetNeedsMnemonic() const;
219
virtual void GTKWidgetDoSetMnemonic(GtkWidget* w);
221
// Get the GdkWindows making part of this window: usually there will be
222
// only one of them in which case it should be returned directly by this
223
// function. If there is more than one GdkWindow (can be the case for
224
// composite widgets), return NULL and fill in the provided array
226
// This is not pure virtual for backwards compatibility but almost
227
// certainly must be overridden in any wxControl-derived class!
228
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
230
// Check if the given window makes part of this widget
231
bool GTKIsOwnWindow(GdkWindow *window) const;
234
// Returns the default context which usually is anti-aliased
235
PangoContext *GTKGetPangoDefaultContext();
238
// applies tooltip to the widget (tip must be UTF-8 encoded)
239
virtual void GTKApplyToolTip(const char* tip);
240
#endif // wxUSE_TOOLTIPS
242
// Called when a window should delay showing itself
243
// until idle time used in Reparent().
244
void GTKShowOnIdle() { m_showOnIdle = true; }
246
// This is called from the various OnInternalIdle methods
247
bool GTKShowFromOnIdle();
249
// is this window transparent for the mouse events (as wxStaticBox is)?
250
virtual bool GTKIsTransparentForMouse() const { return false; }
252
// Common scroll event handling code for wxWindow and wxScrollBar
253
wxEventType GTKGetScrollEventType(GtkRange* range);
255
// position and size of the window
257
int m_width, m_height;
258
int m_oldClientWidth,m_oldClientHeight;
260
// see the docs in src/gtk/window.cpp
261
GtkWidget *m_widget; // mostly the widget seen by the rest of GTK
262
GtkWidget *m_wxwindow; // mostly the client area as per wxWidgets
264
// label for use with GetLabelSetLabel
267
// return true if the window is of a standard (i.e. not wxWidgets') class
268
bool IsOfStandardClass() const { return m_wxwindow == NULL; }
270
// this widget will be queried for GTK's focus events
271
GtkWidget *m_focusWidget;
273
void GTKDisableFocusOutEvent();
274
void GTKEnableFocusOutEvent();
276
wxGtkIMData *m_imData;
278
// indices for the arrays below
279
enum ScrollDir { ScrollDir_Horz, ScrollDir_Vert, ScrollDir_Max };
281
// horizontal/vertical scroll bar
282
GtkRange* m_scrollBar[ScrollDir_Max];
284
// horizontal/vertical scroll position
285
double m_scrollPos[ScrollDir_Max];
287
// return the scroll direction index corresponding to the given orientation
288
// (which is wxVERTICAL or wxHORIZONTAL)
289
static ScrollDir ScrollDirFromOrient(int orient)
291
return orient == wxVERTICAL ? ScrollDir_Vert : ScrollDir_Horz;
294
// return the orientation for the given scrolling direction
295
static int OrientFromScrollDir(ScrollDir dir)
297
return dir == ScrollDir_Horz ? wxHORIZONTAL : wxVERTICAL;
300
// find the direction of the given scrollbar (must be one of ours)
301
ScrollDir ScrollDirFromRange(GtkRange *range) const;
303
// set the current cursor for all GdkWindows making part of this widget
304
// (see GTKGetWindow)
305
void GTKUpdateCursor(bool update_self = true, bool recurse = true);
307
// extra (wxGTK-specific) flags
308
bool m_noExpose:1; // wxGLCanvas has its own redrawing
309
bool m_nativeSizeEvent:1; // wxGLCanvas sends wxSizeEvent upon "alloc_size"
310
bool m_hasVMT:1; // set after PostCreation() is called
311
bool m_isScrolling:1; // dragging scrollbar thumb?
312
bool m_clipPaintRegion:1; // true after ScrollWindow()
313
wxRegion m_nativeUpdateRegion; // not transformed for RTL
314
bool m_dirtyTabOrder:1; // tab order changed, GTK focus
315
// chain needs update
316
bool m_needsStyleChange:1; // May not be able to change
317
// background style until OnIdle
318
bool m_mouseButtonDown:1;
320
bool m_showOnIdle:1; // postpone showing the window until idle
323
// implement the base class pure virtuals
324
virtual void DoGetTextExtent(const wxString& string,
327
int *externalLeading = NULL,
328
const wxFont *font = NULL) const;
329
virtual void DoClientToScreen( int *x, int *y ) const;
330
virtual void DoScreenToClient( int *x, int *y ) const;
331
virtual void DoGetPosition( int *x, int *y ) const;
332
virtual void DoGetSize( int *width, int *height ) const;
333
virtual void DoGetClientSize( int *width, int *height ) const;
334
virtual void DoSetSize(int x, int y,
335
int width, int height,
336
int sizeFlags = wxSIZE_AUTO);
337
virtual void DoSetClientSize(int width, int height);
338
virtual wxSize DoGetBorderSize() const;
339
virtual void DoMoveWindow(int x, int y, int width, int height);
340
virtual void DoEnable(bool enable);
342
#if wxUSE_MENUS_NATIVE
343
virtual bool DoPopupMenu( wxMenu *menu, int x, int y );
344
#endif // wxUSE_MENUS_NATIVE
346
virtual void DoCaptureMouse();
347
virtual void DoReleaseMouse();
349
virtual void DoFreeze();
350
virtual void DoThaw();
352
void GTKFreezeWidget(GtkWidget *w);
353
void GTKThawWidget(GtkWidget *w);
356
virtual void DoSetToolTip( wxToolTip *tip );
357
#endif // wxUSE_TOOLTIPS
359
// common part of all ctors (not virtual because called from ctor)
362
virtual void DoMoveInTabOrder(wxWindow *win, WindowOrder move);
363
virtual bool DoNavigateIn(int flags);
366
// Copies m_children tab order to GTK focus chain:
367
void RealizeTabOrder();
370
// Called by ApplyWidgetStyle (which is called by SetFont() and
371
// SetXXXColour etc to apply style changed to native widgets) to create
372
// modified GTK style with non-standard attributes. If forceStyle=true,
373
// creates empty GtkRcStyle if there are no modifications, otherwise
374
// returns NULL in such case.
375
GtkRcStyle *GTKCreateWidgetStyle(bool forceStyle = false);
378
void GTKApplyWidgetStyle(bool forceStyle = false);
380
// helper function to ease native widgets wrapping, called by
381
// ApplyWidgetStyle -- override this, not ApplyWidgetStyle
382
virtual void DoApplyWidgetStyle(GtkRcStyle *style);
384
void GTKApplyStyle(GtkWidget* widget, GtkRcStyle* style);
386
// sets the border of a given GtkScrolledWindow from a wx style
387
static void GTKScrolledWindowSetBorder(GtkWidget* w, int style);
389
// Connect the given function to the specified signal on m_widget.
391
// This is just a wrapper for g_signal_connect() and returns the handler id
393
unsigned long GTKConnectWidget(const char *signal, wxGTKCallback callback);
395
void ConstrainSize();
398
enum ScrollUnit { ScrollUnit_Line, ScrollUnit_Page, ScrollUnit_Max };
400
// common part of ScrollLines() and ScrollPages() and could be used, in the
401
// future, for horizontal scrolling as well
403
// return true if we scrolled, false otherwise (on error or simply if we
404
// are already at the end)
405
bool DoScrollByUnits(ScrollDir dir, ScrollUnit unit, int units);
406
virtual void AddChildGTK(wxWindowGTK* child);
409
// paint context is stashed here so wxPaintDC can use it
410
cairo_t* m_paintContext;
413
cairo_t* GTKPaintContext() const
415
return m_paintContext;
419
DECLARE_DYNAMIC_CLASS(wxWindowGTK)
420
wxDECLARE_NO_COPY_CLASS(wxWindowGTK);
423
#endif // _WX_GTK_WINDOW_H_