]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/gtk/window.h | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_GTK_WINDOW_H_ | |
11 | #define _WX_GTK_WINDOW_H_ | |
12 | ||
13 | #include "wx/dynarray.h" | |
14 | ||
15 | #ifdef __WXGTK3__ | |
16 | typedef struct _cairo cairo_t; | |
17 | typedef struct _GtkStyleProvider GtkStyleProvider; | |
18 | #define WXUNUSED_IN_GTK3(x) | |
19 | #else | |
20 | #define WXUNUSED_IN_GTK3(x) x | |
21 | #endif | |
22 | ||
23 | // helper structure that holds class that holds GtkIMContext object and | |
24 | // some additional data needed for key events processing | |
25 | struct wxGtkIMData; | |
26 | ||
27 | WX_DEFINE_EXPORTED_ARRAY_PTR(GdkWindow *, wxArrayGdkWindows); | |
28 | ||
29 | extern "C" | |
30 | { | |
31 | ||
32 | typedef void (*wxGTKCallback)(); | |
33 | ||
34 | } | |
35 | ||
36 | //----------------------------------------------------------------------------- | |
37 | // wxWindowGTK | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
40 | class WXDLLIMPEXP_CORE wxWindowGTK : public wxWindowBase | |
41 | { | |
42 | public: | |
43 | // creating the window | |
44 | // ------------------- | |
45 | wxWindowGTK(); | |
46 | wxWindowGTK(wxWindow *parent, | |
47 | wxWindowID id, | |
48 | const wxPoint& pos = wxDefaultPosition, | |
49 | const wxSize& size = wxDefaultSize, | |
50 | long style = 0, | |
51 | const wxString& name = wxPanelNameStr); | |
52 | bool Create(wxWindow *parent, | |
53 | wxWindowID id, | |
54 | const wxPoint& pos = wxDefaultPosition, | |
55 | const wxSize& size = wxDefaultSize, | |
56 | long style = 0, | |
57 | const wxString& name = wxPanelNameStr); | |
58 | virtual ~wxWindowGTK(); | |
59 | ||
60 | // implement base class (pure) virtual methods | |
61 | // ------------------------------------------- | |
62 | ||
63 | virtual void Raise(); | |
64 | virtual void Lower(); | |
65 | ||
66 | virtual bool Show( bool show = true ); | |
67 | ||
68 | virtual bool IsRetained() const; | |
69 | ||
70 | virtual void SetFocus(); | |
71 | ||
72 | // hint from wx to native GTK+ tab traversal code | |
73 | virtual void SetCanFocus(bool canFocus); | |
74 | ||
75 | virtual bool Reparent( wxWindowBase *newParent ); | |
76 | ||
77 | virtual void WarpPointer(int x, int y); | |
78 | ||
79 | virtual void Refresh( bool eraseBackground = true, | |
80 | const wxRect *rect = (const wxRect *) NULL ); | |
81 | virtual void Update(); | |
82 | virtual void ClearBackground(); | |
83 | ||
84 | virtual bool SetBackgroundColour( const wxColour &colour ); | |
85 | virtual bool SetForegroundColour( const wxColour &colour ); | |
86 | virtual bool SetCursor( const wxCursor &cursor ); | |
87 | virtual bool SetFont( const wxFont &font ); | |
88 | ||
89 | virtual bool SetBackgroundStyle(wxBackgroundStyle style) ; | |
90 | virtual bool IsTransparentBackgroundSupported(wxString* reason = NULL) const; | |
91 | ||
92 | virtual int GetCharHeight() const; | |
93 | virtual int GetCharWidth() const; | |
94 | ||
95 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, | |
96 | int range, bool refresh = true ); | |
97 | virtual void SetScrollPos( int orient, int pos, bool refresh = true ); | |
98 | virtual int GetScrollPos( int orient ) const; | |
99 | virtual int GetScrollThumb( int orient ) const; | |
100 | virtual int GetScrollRange( int orient ) const; | |
101 | virtual void ScrollWindow( int dx, int dy, | |
102 | const wxRect* rect = NULL ); | |
103 | virtual bool ScrollLines(int lines); | |
104 | virtual bool ScrollPages(int pages); | |
105 | ||
106 | #if wxUSE_DRAG_AND_DROP | |
107 | virtual void SetDropTarget( wxDropTarget *dropTarget ); | |
108 | #endif // wxUSE_DRAG_AND_DROP | |
109 | ||
110 | virtual void AddChild( wxWindowBase *child ); | |
111 | virtual void RemoveChild( wxWindowBase *child ); | |
112 | ||
113 | virtual void SetLayoutDirection(wxLayoutDirection dir); | |
114 | virtual wxLayoutDirection GetLayoutDirection() const; | |
115 | virtual wxCoord AdjustForLayoutDirection(wxCoord x, | |
116 | wxCoord width, | |
117 | wxCoord widthTotal) const; | |
118 | ||
119 | virtual bool DoIsExposed( int x, int y ) const; | |
120 | virtual bool DoIsExposed( int x, int y, int w, int h ) const; | |
121 | ||
122 | // currently wxGTK2-only | |
123 | void SetDoubleBuffered(bool on); | |
124 | virtual bool IsDoubleBuffered() const; | |
125 | ||
126 | // SetLabel(), which does nothing in wxWindow | |
127 | virtual void SetLabel(const wxString& label) { m_gtkLabel = label; } | |
128 | virtual wxString GetLabel() const { return m_gtkLabel; } | |
129 | ||
130 | // implementation | |
131 | // -------------- | |
132 | ||
133 | virtual WXWidget GetHandle() const { return m_widget; } | |
134 | ||
135 | // many important things are done here, this function must be called | |
136 | // regularly | |
137 | virtual void OnInternalIdle(); | |
138 | ||
139 | // For compatibility across platforms (not in event table) | |
140 | void OnIdle(wxIdleEvent& WXUNUSED(event)) {} | |
141 | ||
142 | // Used by all window classes in the widget creation process. | |
143 | bool PreCreation( wxWindowGTK *parent, const wxPoint &pos, const wxSize &size ); | |
144 | void PostCreation(); | |
145 | ||
146 | // Internal addition of child windows | |
147 | void DoAddChild(wxWindowGTK *child); | |
148 | ||
149 | // This method sends wxPaintEvents to the window. | |
150 | // It is also responsible for background erase events. | |
151 | #ifdef __WXGTK3__ | |
152 | void GTKSendPaintEvents(cairo_t* cr); | |
153 | #else | |
154 | void GTKSendPaintEvents(const GdkRegion* region); | |
155 | #endif | |
156 | ||
157 | // The methods below are required because many native widgets | |
158 | // are composed of several subwidgets and setting a style for | |
159 | // the widget means setting it for all subwidgets as well. | |
160 | // also, it is not clear which native widget is the top | |
161 | // widget where (most of) the input goes. even tooltips have | |
162 | // to be applied to all subwidgets. | |
163 | virtual GtkWidget* GetConnectWidget(); | |
164 | void ConnectWidget( GtkWidget *widget ); | |
165 | ||
166 | // Called from several event handlers, if it returns true or false, the | |
167 | // same value should be immediately returned by the handler without doing | |
168 | // anything else. If it returns -1, the handler should continue as usual | |
169 | int GTKCallbackCommonPrologue(struct _GdkEventAny *event) const; | |
170 | ||
171 | // Simplified form of GTKCallbackCommonPrologue() which can be used from | |
172 | // GTK callbacks without return value to check if the event should be | |
173 | // ignored: if this returns true, the event shouldn't be handled | |
174 | bool GTKShouldIgnoreEvent() const; | |
175 | ||
176 | ||
177 | // override this if some events should never be consumed by wxWidgets but | |
178 | // but have to be left for the native control | |
179 | // | |
180 | // base version just calls HandleWindowEvent() | |
181 | virtual bool GTKProcessEvent(wxEvent& event) const; | |
182 | ||
183 | // Map GTK widget direction of the given widget to/from wxLayoutDirection | |
184 | static wxLayoutDirection GTKGetLayout(GtkWidget *widget); | |
185 | static void GTKSetLayout(GtkWidget *widget, wxLayoutDirection dir); | |
186 | ||
187 | // This is called when capture is taken from the window. It will | |
188 | // fire off capture lost events. | |
189 | void GTKReleaseMouseAndNotify(); | |
190 | ||
191 | GdkWindow* GTKGetDrawingWindow() const; | |
192 | ||
193 | bool GTKHandleFocusIn(); | |
194 | bool GTKHandleFocusOut(); | |
195 | void GTKHandleFocusOutNoDeferring(); | |
196 | static void GTKHandleDeferredFocusOut(); | |
197 | ||
198 | // Called when m_widget becomes realized. Derived classes must call the | |
199 | // base class method if they override it. | |
200 | virtual void GTKHandleRealized(); | |
201 | void GTKHandleUnrealize(); | |
202 | ||
203 | protected: | |
204 | // for controls composed of multiple GTK widgets, return true to eliminate | |
205 | // spurious focus events if the focus changes between GTK+ children within | |
206 | // the same wxWindow | |
207 | virtual bool GTKNeedsToFilterSameWindowFocus() const { return false; } | |
208 | ||
209 | // Override GTKWidgetNeedsMnemonic and return true if your | |
210 | // needs to set its mnemonic widget, such as for a | |
211 | // GtkLabel for wxStaticText, then do the actual | |
212 | // setting of the widget inside GTKWidgetDoSetMnemonic | |
213 | virtual bool GTKWidgetNeedsMnemonic() const; | |
214 | virtual void GTKWidgetDoSetMnemonic(GtkWidget* w); | |
215 | ||
216 | // Get the GdkWindows making part of this window: usually there will be | |
217 | // only one of them in which case it should be returned directly by this | |
218 | // function. If there is more than one GdkWindow (can be the case for | |
219 | // composite widgets), return NULL and fill in the provided array | |
220 | // | |
221 | // This is not pure virtual for backwards compatibility but almost | |
222 | // certainly must be overridden in any wxControl-derived class! | |
223 | virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const; | |
224 | ||
225 | // Check if the given window makes part of this widget | |
226 | bool GTKIsOwnWindow(GdkWindow *window) const; | |
227 | ||
228 | public: | |
229 | // Returns the default context which usually is anti-aliased | |
230 | PangoContext *GTKGetPangoDefaultContext(); | |
231 | ||
232 | #if wxUSE_TOOLTIPS | |
233 | // applies tooltip to the widget (tip must be UTF-8 encoded) | |
234 | virtual void GTKApplyToolTip(const char* tip); | |
235 | #endif // wxUSE_TOOLTIPS | |
236 | ||
237 | // Called when a window should delay showing itself | |
238 | // until idle time used in Reparent(). | |
239 | void GTKShowOnIdle() { m_showOnIdle = true; } | |
240 | ||
241 | // This is called from the various OnInternalIdle methods | |
242 | bool GTKShowFromOnIdle(); | |
243 | ||
244 | // is this window transparent for the mouse events (as wxStaticBox is)? | |
245 | virtual bool GTKIsTransparentForMouse() const { return false; } | |
246 | ||
247 | // Common scroll event handling code for wxWindow and wxScrollBar | |
248 | wxEventType GTKGetScrollEventType(GtkRange* range); | |
249 | ||
250 | // position and size of the window | |
251 | int m_x, m_y; | |
252 | int m_width, m_height; | |
253 | int m_clientWidth, m_clientHeight; | |
254 | // Whether the client size variables above are known to be correct | |
255 | // (because they have been validated by a size-allocate) and should | |
256 | // be used to report client size | |
257 | bool m_useCachedClientSize; | |
258 | ||
259 | // see the docs in src/gtk/window.cpp | |
260 | GtkWidget *m_widget; // mostly the widget seen by the rest of GTK | |
261 | GtkWidget *m_wxwindow; // mostly the client area as per wxWidgets | |
262 | ||
263 | // label for use with GetLabelSetLabel | |
264 | wxString m_gtkLabel; | |
265 | ||
266 | // return true if the window is of a standard (i.e. not wxWidgets') class | |
267 | bool IsOfStandardClass() const { return m_wxwindow == NULL; } | |
268 | ||
269 | // this widget will be queried for GTK's focus events | |
270 | GtkWidget *m_focusWidget; | |
271 | ||
272 | void GTKDisableFocusOutEvent(); | |
273 | void GTKEnableFocusOutEvent(); | |
274 | ||
275 | wxGtkIMData *m_imData; | |
276 | ||
277 | // indices for the arrays below | |
278 | enum ScrollDir { ScrollDir_Horz, ScrollDir_Vert, ScrollDir_Max }; | |
279 | ||
280 | // horizontal/vertical scroll bar | |
281 | GtkRange* m_scrollBar[ScrollDir_Max]; | |
282 | ||
283 | // horizontal/vertical scroll position | |
284 | double m_scrollPos[ScrollDir_Max]; | |
285 | ||
286 | // return the scroll direction index corresponding to the given orientation | |
287 | // (which is wxVERTICAL or wxHORIZONTAL) | |
288 | static ScrollDir ScrollDirFromOrient(int orient) | |
289 | { | |
290 | return orient == wxVERTICAL ? ScrollDir_Vert : ScrollDir_Horz; | |
291 | } | |
292 | ||
293 | // return the orientation for the given scrolling direction | |
294 | static int OrientFromScrollDir(ScrollDir dir) | |
295 | { | |
296 | return dir == ScrollDir_Horz ? wxHORIZONTAL : wxVERTICAL; | |
297 | } | |
298 | ||
299 | // find the direction of the given scrollbar (must be one of ours) | |
300 | ScrollDir ScrollDirFromRange(GtkRange *range) const; | |
301 | ||
302 | // set the current cursor for all GdkWindows making part of this widget | |
303 | // (see GTKGetWindow) | |
304 | void GTKUpdateCursor(bool update_self = true, bool recurse = true); | |
305 | ||
306 | // extra (wxGTK-specific) flags | |
307 | bool m_noExpose:1; // wxGLCanvas has its own redrawing | |
308 | bool m_nativeSizeEvent:1; // wxGLCanvas sends wxSizeEvent upon "alloc_size" | |
309 | bool m_isScrolling:1; // dragging scrollbar thumb? | |
310 | bool m_clipPaintRegion:1; // true after ScrollWindow() | |
311 | wxRegion m_nativeUpdateRegion; // not transformed for RTL | |
312 | bool m_dirtyTabOrder:1; // tab order changed, GTK focus | |
313 | // chain needs update | |
314 | bool m_mouseButtonDown:1; | |
315 | ||
316 | bool m_showOnIdle:1; // postpone showing the window until idle | |
317 | ||
318 | protected: | |
319 | // implement the base class pure virtuals | |
320 | virtual void DoGetTextExtent(const wxString& string, | |
321 | int *x, int *y, | |
322 | int *descent = NULL, | |
323 | int *externalLeading = NULL, | |
324 | const wxFont *font = NULL) const; | |
325 | virtual void DoClientToScreen( int *x, int *y ) const; | |
326 | virtual void DoScreenToClient( int *x, int *y ) const; | |
327 | virtual void DoGetPosition( int *x, int *y ) const; | |
328 | virtual void DoGetSize( int *width, int *height ) const; | |
329 | virtual void DoGetClientSize( int *width, int *height ) const; | |
330 | virtual void DoSetSize(int x, int y, | |
331 | int width, int height, | |
332 | int sizeFlags = wxSIZE_AUTO); | |
333 | virtual void DoSetClientSize(int width, int height); | |
334 | virtual wxSize DoGetBorderSize() const; | |
335 | virtual void DoMoveWindow(int x, int y, int width, int height); | |
336 | virtual void DoEnable(bool enable); | |
337 | ||
338 | #if wxUSE_MENUS_NATIVE | |
339 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); | |
340 | #endif // wxUSE_MENUS_NATIVE | |
341 | ||
342 | virtual void DoCaptureMouse(); | |
343 | virtual void DoReleaseMouse(); | |
344 | ||
345 | virtual void DoFreeze(); | |
346 | virtual void DoThaw(); | |
347 | ||
348 | void GTKFreezeWidget(GtkWidget *w); | |
349 | void GTKThawWidget(GtkWidget *w); | |
350 | void GTKDisconnect(void* instance); | |
351 | ||
352 | #if wxUSE_TOOLTIPS | |
353 | virtual void DoSetToolTip( wxToolTip *tip ); | |
354 | #endif // wxUSE_TOOLTIPS | |
355 | ||
356 | // Create a GtkScrolledWindow containing the given widget (usually | |
357 | // m_wxwindow but not necessarily) and assigns it to m_widget. Also shows | |
358 | // the widget passed to it. | |
359 | // | |
360 | // Can be only called if we have either wxHSCROLL or wxVSCROLL in our | |
361 | // style. | |
362 | void GTKCreateScrolledWindowWith(GtkWidget* view); | |
363 | ||
364 | virtual void DoMoveInTabOrder(wxWindow *win, WindowOrder move); | |
365 | virtual bool DoNavigateIn(int flags); | |
366 | ||
367 | ||
368 | // Copies m_children tab order to GTK focus chain: | |
369 | void RealizeTabOrder(); | |
370 | ||
371 | #ifndef __WXGTK3__ | |
372 | // Called by ApplyWidgetStyle (which is called by SetFont() and | |
373 | // SetXXXColour etc to apply style changed to native widgets) to create | |
374 | // modified GTK style with non-standard attributes. | |
375 | GtkRcStyle* GTKCreateWidgetStyle(); | |
376 | #endif | |
377 | ||
378 | void GTKApplyWidgetStyle(bool forceStyle = false); | |
379 | ||
380 | // helper function to ease native widgets wrapping, called by | |
381 | // ApplyWidgetStyle -- override this, not ApplyWidgetStyle | |
382 | virtual void DoApplyWidgetStyle(GtkRcStyle *style); | |
383 | ||
384 | void GTKApplyStyle(GtkWidget* widget, GtkRcStyle* style); | |
385 | ||
386 | // sets the border of a given GtkScrolledWindow from a wx style | |
387 | static void GTKScrolledWindowSetBorder(GtkWidget* w, int style); | |
388 | ||
389 | // Connect the given function to the specified signal on m_widget. | |
390 | // | |
391 | // This is just a wrapper for g_signal_connect() and returns the handler id | |
392 | // just as it does. | |
393 | unsigned long GTKConnectWidget(const char *signal, wxGTKCallback callback); | |
394 | ||
395 | void ConstrainSize(); | |
396 | ||
397 | private: | |
398 | void Init(); | |
399 | ||
400 | // return true if this window must have a non-NULL parent, false if it can | |
401 | // be created without parent (normally only top level windows but in wxGTK | |
402 | // there is also the exception of wxMenuBar) | |
403 | virtual bool GTKNeedsParent() const { return !IsTopLevel(); } | |
404 | ||
405 | enum ScrollUnit { ScrollUnit_Line, ScrollUnit_Page, ScrollUnit_Max }; | |
406 | ||
407 | // common part of ScrollLines() and ScrollPages() and could be used, in the | |
408 | // future, for horizontal scrolling as well | |
409 | // | |
410 | // return true if we scrolled, false otherwise (on error or simply if we | |
411 | // are already at the end) | |
412 | bool DoScrollByUnits(ScrollDir dir, ScrollUnit unit, int units); | |
413 | virtual void AddChildGTK(wxWindowGTK* child); | |
414 | ||
415 | #ifdef __WXGTK3__ | |
416 | // paint context is stashed here so wxPaintDC can use it | |
417 | cairo_t* m_paintContext; | |
418 | // style provider for "background-image" | |
419 | GtkStyleProvider* m_styleProvider; | |
420 | ||
421 | public: | |
422 | cairo_t* GTKPaintContext() const | |
423 | { | |
424 | return m_paintContext; | |
425 | } | |
426 | #endif | |
427 | ||
428 | DECLARE_DYNAMIC_CLASS(wxWindowGTK) | |
429 | wxDECLARE_NO_COPY_CLASS(wxWindowGTK); | |
430 | }; | |
431 | ||
432 | #endif // _WX_GTK_WINDOW_H_ |