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