remove wxGraphicsContext dependency for transparent background support
[wxWidgets.git] / src / gtk / toplevel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/toplevel.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 // ============================================================================
14 // declarations
15 // ============================================================================
16
17 // ----------------------------------------------------------------------------
18 // headers
19 // ----------------------------------------------------------------------------
20
21 #ifdef __VMS
22 #define XIconifyWindow XICONIFYWINDOW
23 #endif
24
25 #include "wx/toplevel.h"
26
27 #ifndef WX_PRECOMP
28 #include "wx/frame.h"
29 #include "wx/icon.h"
30 #include "wx/log.h"
31 #include "wx/app.h"
32 #endif
33
34 #include "wx/gtk/private.h"
35 #include "wx/evtloop.h"
36 #include "wx/sysopt.h"
37
38 #include <gtk/gtk.h>
39 #include <gdk/gdkx.h>
40
41 #include "wx/gtk/private/win_gtk.h"
42
43 #include "wx/unix/utilsx11.h"
44
45 // XA_CARDINAL
46 #include <X11/Xatom.h>
47
48 #if wxUSE_LIBHILDON
49 #include <hildon-widgets/hildon-program.h>
50 #include <hildon-widgets/hildon-window.h>
51 #endif // wxUSE_LIBHILDON
52
53 #if wxUSE_LIBHILDON2
54 #include <hildon/hildon.h>
55 #endif // wxUSE_LIBHILDON2
56
57 // ----------------------------------------------------------------------------
58 // data
59 // ----------------------------------------------------------------------------
60
61 // this is incremented while a modal dialog is shown
62 int wxOpenModalDialogsCount = 0;
63
64 // the frame that is currently active (i.e. its child has focus). It is
65 // used to generate wxActivateEvents
66 static wxTopLevelWindowGTK *g_activeFrame = NULL;
67 static wxTopLevelWindowGTK *g_lastActiveFrame = NULL;
68
69 // if we detect that the app has got/lost the focus, we set this variable to
70 // either TRUE or FALSE and an activate event will be sent during the next
71 // OnIdle() call and it is reset to -1: this value means that we shouldn't
72 // send any activate events at all
73 static int g_sendActivateEvent = -1;
74
75 // Whether _NET_REQUEST_FRAME_EXTENTS support is working
76 // 0 == not tested yet, 1 == working, 2 == broken
77 static int gs_requestFrameExtentsStatus;
78
79 //-----------------------------------------------------------------------------
80 // RequestUserAttention related functions
81 //-----------------------------------------------------------------------------
82
83 #ifndef __WXGTK30__
84 static void wxgtk_window_set_urgency_hint (GtkWindow *win,
85 gboolean setting)
86 {
87 #if GTK_CHECK_VERSION(2,7,0)
88 if (gtk_check_version(2,7,0) == NULL)
89 gtk_window_set_urgency_hint(win, setting);
90 else
91 #endif
92 {
93 GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(win));
94 wxCHECK_RET(window, "wxgtk_window_set_urgency_hint: GdkWindow not realized");
95
96 Display* dpy = GDK_WINDOW_XDISPLAY(window);
97 Window xid = GDK_WINDOW_XID(window);
98 XWMHints* wm_hints = XGetWMHints(dpy, xid);
99
100 if (!wm_hints)
101 wm_hints = XAllocWMHints();
102
103 if (setting)
104 wm_hints->flags |= XUrgencyHint;
105 else
106 wm_hints->flags &= ~XUrgencyHint;
107
108 XSetWMHints(dpy, xid, wm_hints);
109 XFree(wm_hints);
110 }
111 }
112 #define gtk_window_set_urgency_hint wxgtk_window_set_urgency_hint
113 #endif
114
115 extern "C" {
116 static gboolean gtk_frame_urgency_timer_callback( wxTopLevelWindowGTK *win )
117 {
118 gtk_window_set_urgency_hint(GTK_WINDOW(win->m_widget), false);
119
120 win->m_urgency_hint = -2;
121 return FALSE;
122 }
123 }
124
125 //-----------------------------------------------------------------------------
126 // "focus_in_event"
127 //-----------------------------------------------------------------------------
128
129 extern "C" {
130 static gboolean gtk_frame_focus_in_callback( GtkWidget *widget,
131 GdkEvent *WXUNUSED(event),
132 wxTopLevelWindowGTK *win )
133 {
134 switch ( g_sendActivateEvent )
135 {
136 case -1:
137 // we've got focus from outside, synthetize wxActivateEvent
138 g_sendActivateEvent = 1;
139 break;
140
141 case 0:
142 // another our window just lost focus, it was already ours before
143 // - don't send any wxActivateEvent
144 g_sendActivateEvent = -1;
145 break;
146 }
147
148 g_activeFrame = win;
149 g_lastActiveFrame = g_activeFrame;
150
151 // wxPrintf( wxT("active: %s\n"), win->GetTitle().c_str() );
152
153 // MR: wxRequestUserAttention related block
154 switch( win->m_urgency_hint )
155 {
156 default:
157 g_source_remove( win->m_urgency_hint );
158 // no break, fallthrough to remove hint too
159 case -1:
160 gtk_window_set_urgency_hint(GTK_WINDOW(widget), false);
161 win->m_urgency_hint = -2;
162 break;
163
164 case -2: break;
165 }
166
167 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame);
168 wxActivateEvent event(wxEVT_ACTIVATE, true, g_activeFrame->GetId());
169 event.SetEventObject(g_activeFrame);
170 g_activeFrame->HandleWindowEvent(event);
171
172 return FALSE;
173 }
174 }
175
176 //-----------------------------------------------------------------------------
177 // "focus_out_event"
178 //-----------------------------------------------------------------------------
179
180 extern "C" {
181 static
182 gboolean gtk_frame_focus_out_callback(GtkWidget * WXUNUSED(widget),
183 GdkEventFocus *WXUNUSED(gdk_event),
184 wxTopLevelWindowGTK * WXUNUSED(win))
185 {
186 // if the focus goes out of our app alltogether, OnIdle() will send
187 // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset
188 // g_sendActivateEvent to -1
189 g_sendActivateEvent = 0;
190
191 // wxASSERT_MSG( (g_activeFrame == win), wxT("TLW deactivatd although it wasn't active") );
192
193 // wxPrintf( wxT("inactive: %s\n"), win->GetTitle().c_str() );
194
195 if (g_activeFrame)
196 {
197 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame);
198 wxActivateEvent event(wxEVT_ACTIVATE, false, g_activeFrame->GetId());
199 event.SetEventObject(g_activeFrame);
200 g_activeFrame->HandleWindowEvent(event);
201
202 g_activeFrame = NULL;
203 }
204
205 return FALSE;
206 }
207 }
208
209 //-----------------------------------------------------------------------------
210 // "size_allocate" from m_wxwindow
211 //-----------------------------------------------------------------------------
212
213 extern "C" {
214 static void
215 size_allocate(GtkWidget*, GtkAllocation* alloc, wxTopLevelWindowGTK* win)
216 {
217 if (win->m_oldClientWidth != alloc->width ||
218 win->m_oldClientHeight != alloc->height)
219 {
220 win->m_oldClientWidth = alloc->width;
221 win->m_oldClientHeight = alloc->height;
222
223 GtkAllocation a;
224 gtk_widget_get_allocation(win->m_widget, &a);
225 wxSize size(a.width, a.height);
226 size += win->m_decorSize;
227 win->m_width = size.x;
228 win->m_height = size.y;
229
230 if (!win->IsIconized())
231 {
232 wxSizeEvent event(size, win->GetId());
233 event.SetEventObject(win);
234 win->HandleWindowEvent(event);
235 }
236 // else the window is currently unmapped, don't generate size events
237 }
238 }
239 }
240
241 // ----------------------------------------------------------------------------
242 // "size_request"
243 // ----------------------------------------------------------------------------
244
245 extern "C" {
246 static
247 void wxgtk_tlw_size_request_callback(GtkWidget * WXUNUSED(widget),
248 GtkRequisition *requisition,
249 wxTopLevelWindowGTK *win)
250 {
251 // we must return the size of the window without WM decorations, otherwise
252 // GTK+ gets confused, so don't call just GetSize() here
253 win->GTKDoGetSize(&requisition->width, &requisition->height);
254 }
255 }
256
257 //-----------------------------------------------------------------------------
258 // "delete_event"
259 //-----------------------------------------------------------------------------
260
261 extern "C" {
262 static gboolean
263 gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget),
264 GdkEvent *WXUNUSED(event),
265 wxTopLevelWindowGTK *win )
266 {
267 if (win->IsEnabled() &&
268 (wxOpenModalDialogsCount == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ||
269 win->IsGrabbed()))
270 win->Close();
271
272 return TRUE;
273 }
274 }
275
276 //-----------------------------------------------------------------------------
277 // "configure_event"
278 //-----------------------------------------------------------------------------
279
280 extern "C" {
281 static gboolean
282 gtk_frame_configure_callback( GtkWidget* widget,
283 GdkEventConfigure *WXUNUSED(event),
284 wxTopLevelWindowGTK *win )
285 {
286 if (!win->m_hasVMT || !win->IsShown())
287 return FALSE;
288
289 wxPoint point;
290 gtk_window_get_position((GtkWindow*)widget, &point.x, &point.y);
291
292 win->m_x = point.x;
293 win->m_y = point.y;
294 wxMoveEvent mevent(point, win->GetId());
295 mevent.SetEventObject( win );
296 win->HandleWindowEvent( mevent );
297
298 return FALSE;
299 }
300 }
301
302 //-----------------------------------------------------------------------------
303 // "realize" from m_widget
304 //-----------------------------------------------------------------------------
305
306 // we cannot the WM hints and icons before the widget has been realized,
307 // so we do this directly after realization
308
309 void wxTopLevelWindowGTK::GTKHandleRealized()
310 {
311 wxNonOwnedWindow::GTKHandleRealized();
312
313 gdk_window_set_decorations(gtk_widget_get_window(m_widget),
314 (GdkWMDecoration)m_gdkDecor);
315 gdk_window_set_functions(gtk_widget_get_window(m_widget),
316 (GdkWMFunction)m_gdkFunc);
317
318 // GTK's shrinking/growing policy
319 if ( !(m_gdkFunc & GDK_FUNC_RESIZE) )
320 gtk_window_set_resizable(GTK_WINDOW(m_widget), FALSE);
321 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
322 else
323 gtk_window_set_policy(GTK_WINDOW(m_widget), 1, 1, 1);
324 #endif
325
326 const wxIconBundle& icons = GetIcons();
327 if (icons.GetIconCount())
328 SetIcons(icons);
329 }
330
331 //-----------------------------------------------------------------------------
332 // "map_event" from m_widget
333 //-----------------------------------------------------------------------------
334
335 extern "C" {
336 static gboolean
337 gtk_frame_map_callback( GtkWidget*,
338 GdkEvent * WXUNUSED(event),
339 wxTopLevelWindow *win )
340 {
341 const bool wasIconized = win->IsIconized();
342 if (wasIconized)
343 {
344 // Because GetClientSize() returns (0,0) when IsIconized() is true,
345 // a size event must be generated, just in case GetClientSize() was
346 // called while iconized. This specifically happens when restoring a
347 // tlw that was "rolled up" with some WMs.
348 // Queue a resize rather than sending size event directly to allow
349 // children to be made visible first.
350 win->m_oldClientWidth = 0;
351 gtk_widget_queue_resize(win->m_wxwindow);
352 }
353 // it is possible for m_isShown to be false here, see bug #9909
354 if (win->wxWindowBase::Show(true))
355 {
356 wxShowEvent eventShow(win->GetId(), true);
357 eventShow.SetEventObject(win);
358 win->GetEventHandler()->ProcessEvent(eventShow);
359 }
360
361 #if GTK_CHECK_VERSION(2,6,0)
362 if (!gtk_check_version(2,6,0))
363 {
364 // restore focus-on-map setting in case ShowWithoutActivating() was called
365 gtk_window_set_focus_on_map(GTK_WINDOW(win->m_widget), true);
366 }
367 #endif // GTK+ 2.6+
368
369 return false;
370 }
371 }
372
373 //-----------------------------------------------------------------------------
374 // "window-state-event" from m_widget
375 //-----------------------------------------------------------------------------
376
377 extern "C" {
378 static gboolean
379 gtk_frame_window_state_callback( GtkWidget* WXUNUSED(widget),
380 GdkEventWindowState *event,
381 wxTopLevelWindow *win )
382 {
383 if (event->changed_mask & GDK_WINDOW_STATE_ICONIFIED)
384 win->SetIconizeState((event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) != 0);
385
386 // if maximized bit changed and it is now set
387 if (event->changed_mask & event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED)
388 {
389 wxMaximizeEvent event(win->GetId());
390 event.SetEventObject(win);
391 win->HandleWindowEvent(event);
392 }
393
394 return false;
395 }
396 }
397
398 //-----------------------------------------------------------------------------
399
400 bool wxGetFrameExtents(GdkWindow* window, int* left, int* right, int* top, int* bottom)
401 {
402 static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false);
403 Atom xproperty = gdk_x11_atom_to_xatom_for_display(
404 gdk_drawable_get_display(window), property);
405 Atom type;
406 int format;
407 gulong nitems, bytes_after;
408 guchar* data;
409 Status status = XGetWindowProperty(
410 gdk_x11_drawable_get_xdisplay(window),
411 gdk_x11_drawable_get_xid(window),
412 xproperty,
413 0, 4, false, XA_CARDINAL,
414 &type, &format, &nitems, &bytes_after, &data);
415 const bool success = status == Success && data && nitems == 4;
416 if (success)
417 {
418 long* p = (long*)data;
419 if (left) *left = int(p[0]);
420 if (right) *right = int(p[1]);
421 if (top) *top = int(p[2]);
422 if (bottom) *bottom = int(p[3]);
423 }
424 if (data)
425 XFree(data);
426 return success;
427 }
428
429 //-----------------------------------------------------------------------------
430 // "property_notify_event" from m_widget
431 //-----------------------------------------------------------------------------
432
433 extern "C" {
434 static gboolean property_notify_event(
435 GtkWidget*, GdkEventProperty* event, wxTopLevelWindowGTK* win)
436 {
437 // Watch for changes to _NET_FRAME_EXTENTS property
438 static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false);
439 if (event->state == GDK_PROPERTY_NEW_VALUE && event->atom == property)
440 {
441 if (win->m_netFrameExtentsTimerId)
442 {
443 // WM support for _NET_REQUEST_FRAME_EXTENTS is working
444 gs_requestFrameExtentsStatus = 1;
445 g_source_remove(win->m_netFrameExtentsTimerId);
446 win->m_netFrameExtentsTimerId = 0;
447 }
448
449 wxSize decorSize = win->m_decorSize;
450 int left, right, top, bottom;
451 if (wxGetFrameExtents(event->window, &left, &right, &top, &bottom))
452 decorSize.Set(left + right, top + bottom);
453
454 win->GTKUpdateDecorSize(decorSize);
455 }
456 return false;
457 }
458 }
459
460 extern "C" {
461 static gboolean request_frame_extents_timeout(void* data)
462 {
463 // WM support for _NET_REQUEST_FRAME_EXTENTS is broken
464 gs_requestFrameExtentsStatus = 2;
465 gdk_threads_enter();
466 wxTopLevelWindowGTK* win = static_cast<wxTopLevelWindowGTK*>(data);
467 win->m_netFrameExtentsTimerId = 0;
468 wxSize decorSize = win->m_decorSize;
469 int left, right, top, bottom;
470 if (wxGetFrameExtents(gtk_widget_get_window(win->m_widget), &left, &right, &top, &bottom))
471 decorSize.Set(left + right, top + bottom);
472 win->GTKUpdateDecorSize(decorSize);
473 gdk_threads_leave();
474 return false;
475 }
476 }
477
478 // ----------------------------------------------------------------------------
479 // wxTopLevelWindowGTK creation
480 // ----------------------------------------------------------------------------
481
482 void wxTopLevelWindowGTK::Init()
483 {
484 m_mainWidget = NULL;
485 m_isIconized = false;
486 m_fsIsShowing = false;
487 m_themeEnabled = true;
488 m_gdkDecor =
489 m_gdkFunc = 0;
490 m_grabbed = false;
491 m_deferShow = true;
492 m_deferShowAllowed = true;
493 m_updateDecorSize = true;
494 m_netFrameExtentsTimerId = 0;
495
496 m_urgency_hint = -2;
497 }
498
499 bool wxTopLevelWindowGTK::Create( wxWindow *parent,
500 wxWindowID id,
501 const wxString& title,
502 const wxPoint& pos,
503 const wxSize& sizeOrig,
504 long style,
505 const wxString &name )
506 {
507 // always create a frame of some reasonable, even if arbitrary, size (at
508 // least for MSW compatibility)
509 wxSize size = sizeOrig;
510 size.x = WidthDefault(size.x);
511 size.y = HeightDefault(size.y);
512
513 wxTopLevelWindows.Append( this );
514
515 if (!PreCreation( parent, pos, size ) ||
516 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
517 {
518 wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") );
519 return false;
520 }
521
522 m_title = title;
523
524 // NB: m_widget may be !=NULL if it was created by derived class' Create,
525 // e.g. in wxTaskBarIconAreaGTK
526 if (m_widget == NULL)
527 {
528 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
529 // we must create HildonWindow and not a normal GtkWindow as the latter
530 // doesn't look correctly in Maemo environment and it must also be
531 // registered with the main program object
532 m_widget = hildon_window_new();
533 hildon_program_add_window(wxTheApp->GetHildonProgram(),
534 HILDON_WINDOW(m_widget));
535 #else // !wxUSE_LIBHILDON || !wxUSE_LIBHILDON2
536 m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
537 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
538 {
539 // Tell WM that this is a dialog window and make it center
540 // on parent by default (this is what GtkDialog ctor does):
541 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
542 GDK_WINDOW_TYPE_HINT_DIALOG);
543 gtk_window_set_position(GTK_WINDOW(m_widget),
544 GTK_WIN_POS_CENTER_ON_PARENT);
545 }
546 else
547 {
548 if (style & wxFRAME_TOOL_WINDOW)
549 {
550 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
551 GDK_WINDOW_TYPE_HINT_UTILITY);
552
553 // On some WMs, like KDE, a TOOL_WINDOW will still show
554 // on the taskbar, but on Gnome a TOOL_WINDOW will not.
555 // For consistency between WMs and with Windows, we
556 // should set the NO_TASKBAR flag which will apply
557 // the set_skip_taskbar_hint if it is available,
558 // ensuring no taskbar entry will appear.
559 style |= wxFRAME_NO_TASKBAR;
560 }
561 }
562 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON || !wxUSE_LIBHILDON2
563
564 g_object_ref(m_widget);
565 }
566
567 wxWindow *topParent = wxGetTopLevelParent(m_parent);
568 if (topParent && (((GTK_IS_WINDOW(topParent->m_widget)) &&
569 (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)) ||
570 (style & wxFRAME_FLOAT_ON_PARENT)))
571 {
572 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
573 GTK_WINDOW(topParent->m_widget) );
574 }
575
576 if (style & wxFRAME_NO_TASKBAR)
577 {
578 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), TRUE);
579 }
580
581 if (style & wxSTAY_ON_TOP)
582 {
583 gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE);
584 }
585 if (style & wxMAXIMIZE)
586 gtk_window_maximize(GTK_WINDOW(m_widget));
587
588 #if 0
589 if (!name.empty())
590 gtk_window_set_role( GTK_WINDOW(m_widget), wxGTK_CONV( name ) );
591 #endif
592
593 gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) );
594 gtk_widget_set_can_focus(m_widget, false);
595
596 g_signal_connect (m_widget, "delete_event",
597 G_CALLBACK (gtk_frame_delete_callback), this);
598
599 // m_mainWidget is a GtkVBox, holding the bars and client area (m_wxwindow)
600 m_mainWidget = gtk_vbox_new(false, 0);
601 gtk_widget_show( m_mainWidget );
602 gtk_widget_set_can_focus(m_mainWidget, false);
603 gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget );
604
605 // m_wxwindow is the client area
606 m_wxwindow = wxPizza::New();
607 gtk_widget_show( m_wxwindow );
608 gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow );
609
610 // we donm't allow the frame to get the focus as otherwise
611 // the frame will grab it at arbitrary focus changes
612 gtk_widget_set_can_focus(m_wxwindow, false);
613
614 if (m_parent) m_parent->AddChild( this );
615
616 g_signal_connect(m_wxwindow, "size_allocate",
617 G_CALLBACK(size_allocate), this);
618
619 g_signal_connect (m_widget, "size_request",
620 G_CALLBACK (wxgtk_tlw_size_request_callback), this);
621 PostCreation();
622
623 #if !GTK_CHECK_VERSION(3,0,0) && !defined(GTK_DISABLE_DEPRECATED)
624 if ((m_x != -1) || (m_y != -1))
625 gtk_widget_set_uposition( m_widget, m_x, m_y );
626 #endif
627
628 // for some reported size corrections
629 g_signal_connect (m_widget, "map_event",
630 G_CALLBACK (gtk_frame_map_callback), this);
631
632 // for iconized state
633 g_signal_connect (m_widget, "window_state_event",
634 G_CALLBACK (gtk_frame_window_state_callback), this);
635
636
637 // for wxMoveEvent
638 g_signal_connect (m_widget, "configure_event",
639 G_CALLBACK (gtk_frame_configure_callback), this);
640
641 // activation
642 g_signal_connect_after (m_widget, "focus_in_event",
643 G_CALLBACK (gtk_frame_focus_in_callback), this);
644 g_signal_connect_after (m_widget, "focus_out_event",
645 G_CALLBACK (gtk_frame_focus_out_callback), this);
646
647 gtk_widget_add_events(m_widget, GDK_PROPERTY_CHANGE_MASK);
648 g_signal_connect(m_widget, "property_notify_event",
649 G_CALLBACK(property_notify_event), this);
650
651 // translate wx decorations styles into Motif WM hints (they are recognized
652 // by other WMs as well)
653
654 // always enable moving the window as we have no separate flag for enabling
655 // it
656 m_gdkFunc = GDK_FUNC_MOVE;
657
658 if ( style & wxCLOSE_BOX )
659 m_gdkFunc |= GDK_FUNC_CLOSE;
660
661 if ( style & wxMINIMIZE_BOX )
662 m_gdkFunc |= GDK_FUNC_MINIMIZE;
663
664 if ( style & wxMAXIMIZE_BOX )
665 m_gdkFunc |= GDK_FUNC_MAXIMIZE;
666
667 if ( (style & wxSIMPLE_BORDER) || (style & wxNO_BORDER) )
668 {
669 m_gdkDecor = 0;
670 }
671 else // have border
672 {
673 m_gdkDecor = GDK_DECOR_BORDER;
674
675 if ( style & wxCAPTION )
676 m_gdkDecor |= GDK_DECOR_TITLE;
677
678 if ( style & wxSYSTEM_MENU )
679 m_gdkDecor |= GDK_DECOR_MENU;
680
681 if ( style & wxMINIMIZE_BOX )
682 m_gdkDecor |= GDK_DECOR_MINIMIZE;
683
684 if ( style & wxMAXIMIZE_BOX )
685 m_gdkDecor |= GDK_DECOR_MAXIMIZE;
686
687 if ( style & wxRESIZE_BORDER )
688 {
689 m_gdkFunc |= GDK_FUNC_RESIZE;
690 m_gdkDecor |= GDK_DECOR_RESIZEH;
691 }
692 }
693
694 m_decorSize = GetCachedDecorSize();
695 int w, h;
696 GTKDoGetSize(&w, &h);
697 gtk_window_set_default_size(GTK_WINDOW(m_widget), w, h);
698
699 return true;
700 }
701
702 wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
703 {
704 if ( m_netFrameExtentsTimerId )
705 {
706 // Don't let the timer callback fire as the window pointer passed to it
707 // will become invalid very soon.
708 g_source_remove(m_netFrameExtentsTimerId);
709 }
710
711 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
712 // it can also be a (standard) dialog
713 if ( HILDON_IS_WINDOW(m_widget) )
714 {
715 hildon_program_remove_window(wxTheApp->GetHildonProgram(),
716 HILDON_WINDOW(m_widget));
717 }
718 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2
719
720 if (m_grabbed)
721 {
722 wxFAIL_MSG(wxT("Window still grabbed"));
723 RemoveGrab();
724 }
725
726 SendDestroyEvent();
727
728 // it may also be GtkScrolledWindow in the case of an MDI child
729 if (GTK_IS_WINDOW(m_widget))
730 {
731 gtk_window_set_focus( GTK_WINDOW(m_widget), NULL );
732 }
733
734 if (g_activeFrame == this)
735 g_activeFrame = NULL;
736 if (g_lastActiveFrame == this)
737 g_lastActiveFrame = NULL;
738 }
739
740 bool wxTopLevelWindowGTK::EnableCloseButton( bool enable )
741 {
742 if (enable)
743 m_gdkFunc |= GDK_FUNC_CLOSE;
744 else
745 m_gdkFunc &= ~GDK_FUNC_CLOSE;
746
747 GdkWindow* window = gtk_widget_get_window(m_widget);
748 if (window)
749 gdk_window_set_functions(window, (GdkWMFunction)m_gdkFunc);
750
751 return true;
752 }
753
754 bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long)
755 {
756 if (show == m_fsIsShowing)
757 return false; // return what?
758
759 m_fsIsShowing = show;
760
761 wxX11FullScreenMethod method =
762 wxGetFullScreenMethodX11((WXDisplay*)GDK_DISPLAY(),
763 (WXWindow)GDK_ROOT_WINDOW());
764
765 // NB: gtk_window_fullscreen() uses freedesktop.org's WMspec extensions
766 // to switch to fullscreen, which is not always available. We must
767 // check if WM supports the spec and use legacy methods if it
768 // doesn't.
769 if ( method == wxX11_FS_WMSPEC )
770 {
771 if (show)
772 gtk_window_fullscreen( GTK_WINDOW( m_widget ) );
773 else
774 gtk_window_unfullscreen( GTK_WINDOW( m_widget ) );
775 }
776 else
777 {
778 GdkWindow* window = gtk_widget_get_window(m_widget);
779
780 if (show)
781 {
782 GetPosition( &m_fsSaveFrame.x, &m_fsSaveFrame.y );
783 GetSize( &m_fsSaveFrame.width, &m_fsSaveFrame.height );
784
785 int screen_width,screen_height;
786 wxDisplaySize( &screen_width, &screen_height );
787
788 gint client_x, client_y, root_x, root_y;
789 gint width, height;
790
791 m_fsSaveGdkFunc = m_gdkFunc;
792 m_fsSaveGdkDecor = m_gdkDecor;
793 m_gdkFunc = m_gdkDecor = 0;
794 gdk_window_set_decorations(window, (GdkWMDecoration)0);
795 gdk_window_set_functions(window, (GdkWMFunction)0);
796
797 gdk_window_get_origin(window, &root_x, &root_y);
798 gdk_window_get_geometry(window, &client_x, &client_y, &width, &height, NULL);
799
800 gdk_window_move_resize(
801 window, -client_x, -client_y, screen_width + 1, screen_height + 1);
802
803 wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(),
804 (WXWindow)GDK_ROOT_WINDOW(),
805 (WXWindow)GDK_WINDOW_XWINDOW(window),
806 show, &m_fsSaveFrame, method);
807 }
808 else // hide
809 {
810 m_gdkFunc = m_fsSaveGdkFunc;
811 m_gdkDecor = m_fsSaveGdkDecor;
812 gdk_window_set_decorations(window, (GdkWMDecoration)m_gdkDecor);
813 gdk_window_set_functions(window, (GdkWMFunction)m_gdkFunc);
814
815 wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(),
816 (WXWindow)GDK_ROOT_WINDOW(),
817 (WXWindow)GDK_WINDOW_XWINDOW(window),
818 show, &m_fsSaveFrame, method);
819
820 SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y,
821 m_fsSaveFrame.width, m_fsSaveFrame.height);
822 }
823 }
824
825 // documented behaviour is to show the window if it's still hidden when
826 // showing it full screen
827 if (show)
828 Show();
829
830 return true;
831 }
832
833 // ----------------------------------------------------------------------------
834 // overridden wxWindow methods
835 // ----------------------------------------------------------------------------
836
837 void wxTopLevelWindowGTK::Refresh( bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect) )
838 {
839 wxCHECK_RET( m_widget, wxT("invalid frame") );
840
841 gtk_widget_queue_draw( m_widget );
842
843 GdkWindow* window = NULL;
844 if (m_wxwindow)
845 window = gtk_widget_get_window(m_wxwindow);
846 if (window)
847 gdk_window_invalidate_rect(window, NULL, true);
848 }
849
850 bool wxTopLevelWindowGTK::Show( bool show )
851 {
852 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
853
854 bool deferShow = show && !m_isShown && m_deferShow;
855 if (deferShow)
856 {
857 deferShow = gs_requestFrameExtentsStatus != 2 &&
858 m_deferShowAllowed && !gtk_widget_get_realized(m_widget);
859 if (deferShow)
860 {
861 deferShow = g_signal_handler_find(m_widget,
862 GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
863 g_signal_lookup("property_notify_event", GTK_TYPE_WIDGET),
864 0, NULL, NULL, this) != 0;
865 }
866 GdkScreen* screen = NULL;
867 if (deferShow)
868 {
869 screen = gtk_widget_get_screen(m_widget);
870 GdkAtom atom = gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false);
871 deferShow = gdk_x11_screen_supports_net_wm_hint(screen, atom) != 0;
872 // If _NET_REQUEST_FRAME_EXTENTS not supported, don't allow changes
873 // to m_decorSize, it breaks saving/restoring window size with
874 // GetSize()/SetSize() because it makes window bigger between each
875 // restore and save.
876 m_updateDecorSize = deferShow;
877 }
878
879 m_deferShow = deferShow;
880 }
881 if (deferShow)
882 {
883 // Initial show. If WM supports _NET_REQUEST_FRAME_EXTENTS, defer
884 // calling gtk_widget_show() until _NET_FRAME_EXTENTS property
885 // notification is received, so correct frame extents are known.
886 // This allows resizing m_widget to keep the overall size in sync with
887 // what wxWidgets expects it to be without an obvious change in the
888 // window size immediately after it becomes visible.
889
890 // Realize m_widget, so m_widget->window can be used. Realizing normally
891 // causes the widget tree to be size_allocated, which generates size
892 // events in the wrong order. However, the size_allocates will not be
893 // done if the allocation is not the default (1,1).
894 GtkAllocation alloc;
895 gtk_widget_get_allocation(m_widget, &alloc);
896 const int alloc_width = alloc.width;
897 if (alloc_width == 1)
898 {
899 alloc.width = 2;
900 gtk_widget_set_allocation(m_widget, &alloc);
901 }
902 gtk_widget_realize(m_widget);
903 if (alloc_width == 1)
904 {
905 alloc.width = 1;
906 gtk_widget_set_allocation(m_widget, &alloc);
907 }
908
909 // send _NET_REQUEST_FRAME_EXTENTS
910 XClientMessageEvent xevent;
911 memset(&xevent, 0, sizeof(xevent));
912 xevent.type = ClientMessage;
913 GdkWindow* window = gtk_widget_get_window(m_widget);
914 xevent.window = gdk_x11_drawable_get_xid(window);
915 xevent.message_type = gdk_x11_atom_to_xatom_for_display(
916 gdk_drawable_get_display(window),
917 gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false));
918 xevent.format = 32;
919 Display* display = gdk_x11_drawable_get_xdisplay(window);
920 XSendEvent(display, DefaultRootWindow(display), false,
921 SubstructureNotifyMask | SubstructureRedirectMask,
922 (XEvent*)&xevent);
923
924 if (gs_requestFrameExtentsStatus == 0)
925 {
926 // if WM does not respond to request within 1 second,
927 // we assume support for _NET_REQUEST_FRAME_EXTENTS is not working
928 m_netFrameExtentsTimerId =
929 g_timeout_add(1000, request_frame_extents_timeout, this);
930 }
931
932 // defer calling gtk_widget_show()
933 m_isShown = true;
934 return true;
935 }
936
937 if (show && !gtk_widget_get_realized(m_widget))
938 {
939 // size_allocate signals occur in reverse order (bottom to top).
940 // Things work better if the initial wxSizeEvents are sent (from the
941 // top down), before the initial size_allocate signals occur.
942 wxSizeEvent event(GetSize(), GetId());
943 event.SetEventObject(this);
944 HandleWindowEvent(event);
945 }
946
947 bool change = base_type::Show(show);
948
949 if (change && !show)
950 {
951 // make sure window has a non-default position, so when it is shown
952 // again, it won't be repositioned by WM as if it were a new window
953 // Note that this must be done _after_ the window is hidden.
954 gtk_window_move((GtkWindow*)m_widget, m_x, m_y);
955 }
956
957 return change;
958 }
959
960 void wxTopLevelWindowGTK::ShowWithoutActivating()
961 {
962 if (!m_isShown)
963 {
964 #if GTK_CHECK_VERSION(2,6,0)
965 if (!gtk_check_version(2,6,0))
966 gtk_window_set_focus_on_map(GTK_WINDOW(m_widget), false);
967 #endif // GTK+ 2.6+
968
969 Show(true);
970 }
971 }
972
973 void wxTopLevelWindowGTK::Raise()
974 {
975 gtk_window_present( GTK_WINDOW( m_widget ) );
976 }
977
978 void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) )
979 {
980 wxFAIL_MSG( wxT("DoMoveWindow called for wxTopLevelWindowGTK") );
981 }
982
983 // ----------------------------------------------------------------------------
984 // window geometry
985 // ----------------------------------------------------------------------------
986
987 void wxTopLevelWindowGTK::GTKDoGetSize(int *width, int *height) const
988 {
989 wxSize size(m_width, m_height);
990 size -= m_decorSize;
991 if (size.x < 0) size.x = 0;
992 if (size.y < 0) size.y = 0;
993 #if wxUSE_LIBHILDON2
994 if (width) {
995 if (size.x == 720)
996 *width = 696;
997 else
998 *width = size.x;
999 }
1000 if (height) {
1001 if (size.y == 420)
1002 *height = 396;
1003 else if (size.y == 270)
1004 *height = 246;
1005 else
1006 *height = size.y;
1007 }
1008 #else // wxUSE_LIBHILDON2
1009 if (width) *width = size.x;
1010 if (height) *height = size.y;
1011 #endif // wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON2
1012 }
1013
1014 void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags )
1015 {
1016 wxCHECK_RET( m_widget, wxT("invalid frame") );
1017
1018 m_deferShowAllowed = true;
1019
1020 // deal with the position first
1021 int old_x = m_x;
1022 int old_y = m_y;
1023
1024 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1025 {
1026 // -1 means "use existing" unless the flag above is specified
1027 if ( x != -1 )
1028 m_x = x;
1029 if ( y != -1 )
1030 m_y = y;
1031 }
1032 else // wxSIZE_ALLOW_MINUS_ONE
1033 {
1034 m_x = x;
1035 m_y = y;
1036 }
1037
1038 if ( m_x != old_x || m_y != old_y )
1039 {
1040 gtk_window_move( GTK_WINDOW(m_widget), m_x, m_y );
1041 }
1042
1043 const wxSize oldSize(m_width, m_height);
1044 if (width >= 0)
1045 m_width = width;
1046 if (height >= 0)
1047 m_height = height;
1048 ConstrainSize();
1049 if (m_width != oldSize.x || m_height != oldSize.y)
1050 {
1051 int w, h;
1052 GTKDoGetSize(&w, &h);
1053 gtk_window_resize(GTK_WINDOW(m_widget), w, h);
1054
1055 GetClientSize(&m_oldClientWidth, &m_oldClientHeight);
1056 wxSizeEvent event(GetSize(), GetId());
1057 event.SetEventObject(this);
1058 HandleWindowEvent(event);
1059 }
1060 }
1061
1062 void wxTopLevelWindowGTK::DoSetClientSize(int width, int height)
1063 {
1064 base_type::DoSetClientSize(width, height);
1065
1066 // Since client size is being explicitly set, don't change it later
1067 // Has to be done after calling base because it calls SetSize,
1068 // which sets this true
1069 m_deferShowAllowed = false;
1070 }
1071
1072 void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const
1073 {
1074 wxASSERT_MSG(m_widget, wxT("invalid frame"));
1075
1076 if ( IsIconized() )
1077 {
1078 // for consistency with wxMSW, client area is supposed to be empty for
1079 // the iconized windows
1080 if ( width )
1081 *width = 0;
1082 if ( height )
1083 *height = 0;
1084 }
1085 else
1086 {
1087 GTKDoGetSize(width, height);
1088 }
1089 }
1090
1091 void wxTopLevelWindowGTK::DoSetSizeHints( int minW, int minH,
1092 int maxW, int maxH,
1093 int incW, int incH )
1094 {
1095 base_type::DoSetSizeHints(minW, minH, maxW, maxH, incW, incH);
1096
1097 const wxSize minSize = GetMinSize();
1098 const wxSize maxSize = GetMaxSize();
1099 GdkGeometry hints;
1100 int hints_mask = 0;
1101 if (minSize.x > 0 || minSize.y > 0)
1102 {
1103 hints_mask |= GDK_HINT_MIN_SIZE;
1104 hints.min_width = minSize.x - m_decorSize.x;
1105 if (hints.min_width < 0)
1106 hints.min_width = 0;
1107 hints.min_height = minSize.y - m_decorSize.y;
1108 if (hints.min_height < 0)
1109 hints.min_height = 0;
1110 }
1111 if (maxSize.x > 0 || maxSize.y > 0)
1112 {
1113 hints_mask |= GDK_HINT_MAX_SIZE;
1114 hints.max_width = maxSize.x - m_decorSize.x;
1115 if (hints.max_width < 0)
1116 hints.max_width = INT_MAX;
1117 hints.max_height = maxSize.y - m_decorSize.y;
1118 if (hints.max_height < 0)
1119 hints.max_height = INT_MAX;
1120 }
1121 if (incW > 0 || incH > 0)
1122 {
1123 hints_mask |= GDK_HINT_RESIZE_INC;
1124 hints.width_inc = incW > 0 ? incW : 1;
1125 hints.height_inc = incH > 0 ? incH : 1;
1126 }
1127 gtk_window_set_geometry_hints(
1128 (GtkWindow*)m_widget, NULL, &hints, (GdkWindowHints)hints_mask);
1129 }
1130
1131 void wxTopLevelWindowGTK::GTKUpdateDecorSize(const wxSize& decorSize)
1132 {
1133 if (!IsMaximized() && !IsFullScreen())
1134 GetCachedDecorSize() = decorSize;
1135 if (m_updateDecorSize && m_decorSize != decorSize)
1136 {
1137 const wxSize diff = decorSize - m_decorSize;
1138 m_decorSize = decorSize;
1139 bool resized = false;
1140 if (m_deferShow)
1141 {
1142 // keep overall size unchanged by shrinking m_widget
1143 int w, h;
1144 GTKDoGetSize(&w, &h);
1145 // but not if size would be less than minimum, it won't take effect
1146 const wxSize minSize = GetMinSize();
1147 if (w >= minSize.x && h >= minSize.y)
1148 {
1149 gtk_window_resize(GTK_WINDOW(m_widget), w, h);
1150 resized = true;
1151 }
1152 }
1153 if (!resized)
1154 {
1155 // adjust overall size to match change in frame extents
1156 m_width += diff.x;
1157 m_height += diff.y;
1158 if (m_width < 0) m_width = 0;
1159 if (m_height < 0) m_height = 0;
1160 m_oldClientWidth = 0;
1161 gtk_widget_queue_resize(m_wxwindow);
1162 }
1163 }
1164 if (m_deferShow)
1165 {
1166 // gtk_widget_show() was deferred, do it now
1167 m_deferShow = false;
1168 GetClientSize(&m_oldClientWidth, &m_oldClientHeight);
1169 wxSizeEvent sizeEvent(GetSize(), GetId());
1170 sizeEvent.SetEventObject(this);
1171 HandleWindowEvent(sizeEvent);
1172
1173 gtk_widget_show(m_widget);
1174
1175 wxShowEvent showEvent(GetId(), true);
1176 showEvent.SetEventObject(this);
1177 HandleWindowEvent(showEvent);
1178 }
1179 }
1180
1181 wxSize& wxTopLevelWindowGTK::GetCachedDecorSize()
1182 {
1183 static wxSize size[8];
1184
1185 int index = 0;
1186 // title bar
1187 if (m_gdkDecor & (GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE | GDK_DECOR_TITLE))
1188 index = 1;
1189 // border
1190 if (m_gdkDecor & GDK_DECOR_BORDER)
1191 index |= 2;
1192 // utility window decor can be different
1193 if (m_windowStyle & wxFRAME_TOOL_WINDOW)
1194 index |= 4;
1195 return size[index];
1196 }
1197
1198 void wxTopLevelWindowGTK::OnInternalIdle()
1199 {
1200 wxTopLevelWindowBase::OnInternalIdle();
1201
1202 // Synthetize activate events.
1203 if ( g_sendActivateEvent != -1 )
1204 {
1205 bool activate = g_sendActivateEvent != 0;
1206
1207 // if (!activate) wxPrintf( wxT("de") );
1208 // wxPrintf( wxT("activate\n") );
1209
1210 // do it only once
1211 g_sendActivateEvent = -1;
1212
1213 wxTheApp->SetActive(activate, (wxWindow *)g_lastActiveFrame);
1214 }
1215 }
1216
1217 // ----------------------------------------------------------------------------
1218 // frame title/icon
1219 // ----------------------------------------------------------------------------
1220
1221 void wxTopLevelWindowGTK::SetTitle( const wxString &title )
1222 {
1223 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
1224
1225 if ( title == m_title )
1226 return;
1227
1228 m_title = title;
1229
1230 gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) );
1231 }
1232
1233 void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
1234 {
1235 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
1236
1237 base_type::SetIcons(icons);
1238
1239 // Setting icons before window is realized can cause a GTK assertion if
1240 // another TLW is realized before this one, and it has this one as it's
1241 // transient parent. The life demo exibits this problem.
1242 if (gtk_widget_get_realized(m_widget))
1243 {
1244 GList* list = NULL;
1245 for (size_t i = icons.GetIconCount(); i--;)
1246 list = g_list_prepend(list, icons.GetIconByIndex(i).GetPixbuf());
1247 gtk_window_set_icon_list(GTK_WINDOW(m_widget), list);
1248 g_list_free(list);
1249 }
1250 }
1251
1252 // ----------------------------------------------------------------------------
1253 // frame state: maximized/iconized/normal
1254 // ----------------------------------------------------------------------------
1255
1256 void wxTopLevelWindowGTK::Maximize(bool maximize)
1257 {
1258 if (maximize)
1259 gtk_window_maximize( GTK_WINDOW( m_widget ) );
1260 else
1261 gtk_window_unmaximize( GTK_WINDOW( m_widget ) );
1262 }
1263
1264 bool wxTopLevelWindowGTK::IsMaximized() const
1265 {
1266 GdkWindow* window = gtk_widget_get_window(m_widget);
1267 return window && (gdk_window_get_state(window) & GDK_WINDOW_STATE_MAXIMIZED);
1268 }
1269
1270 void wxTopLevelWindowGTK::Restore()
1271 {
1272 // "Present" seems similar enough to "restore"
1273 gtk_window_present( GTK_WINDOW( m_widget ) );
1274 }
1275
1276 void wxTopLevelWindowGTK::Iconize( bool iconize )
1277 {
1278 if (iconize)
1279 gtk_window_iconify( GTK_WINDOW( m_widget ) );
1280 else
1281 gtk_window_deiconify( GTK_WINDOW( m_widget ) );
1282 }
1283
1284 bool wxTopLevelWindowGTK::IsIconized() const
1285 {
1286 return m_isIconized;
1287 }
1288
1289 void wxTopLevelWindowGTK::SetIconizeState(bool iconize)
1290 {
1291 if ( iconize != m_isIconized )
1292 {
1293 m_isIconized = iconize;
1294 (void)SendIconizeEvent(iconize);
1295 }
1296 }
1297
1298 void wxTopLevelWindowGTK::AddGrab()
1299 {
1300 if (!m_grabbed)
1301 {
1302 m_grabbed = true;
1303 gtk_grab_add( m_widget );
1304 wxGUIEventLoop().Run();
1305 gtk_grab_remove( m_widget );
1306 }
1307 }
1308
1309 void wxTopLevelWindowGTK::RemoveGrab()
1310 {
1311 if (m_grabbed)
1312 {
1313 gtk_main_quit();
1314 m_grabbed = false;
1315 }
1316 }
1317
1318 bool wxTopLevelWindowGTK::IsActive()
1319 {
1320 return (this == (wxTopLevelWindowGTK*)g_activeFrame);
1321 }
1322
1323 void wxTopLevelWindowGTK::RequestUserAttention(int flags)
1324 {
1325 bool new_hint_value = false;
1326
1327 // FIXME: This is a workaround to focus handling problem
1328 // If RequestUserAttention is called for example right after a wxSleep, OnInternalIdle
1329 // hasn't yet been processed, and the internal focus system is not up to date yet.
1330 // YieldFor(wxEVT_CATEGORY_UI) ensures the processing of it (hopefully it
1331 // won't have side effects) - MR
1332 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
1333
1334 if(m_urgency_hint >= 0)
1335 g_source_remove(m_urgency_hint);
1336
1337 m_urgency_hint = -2;
1338
1339 if( gtk_widget_get_realized(m_widget) && !IsActive() )
1340 {
1341 new_hint_value = true;
1342
1343 if (flags & wxUSER_ATTENTION_INFO)
1344 {
1345 m_urgency_hint = g_timeout_add(5000, (GSourceFunc)gtk_frame_urgency_timer_callback, this);
1346 } else {
1347 m_urgency_hint = -1;
1348 }
1349 }
1350
1351 gtk_window_set_urgency_hint(GTK_WINDOW(m_widget), new_hint_value);
1352 }
1353
1354 void wxTopLevelWindowGTK::SetWindowStyleFlag( long style )
1355 {
1356 // Store which styles were changed
1357 long styleChanges = style ^ m_windowStyle;
1358
1359 // Process wxWindow styles. This also updates the internal variable
1360 // Therefore m_windowStyle bits carry now the _new_ style values
1361 wxWindow::SetWindowStyleFlag(style);
1362
1363 // just return for now if widget does not exist yet
1364 if (!m_widget)
1365 return;
1366
1367 if ( styleChanges & wxSTAY_ON_TOP )
1368 {
1369 gtk_window_set_keep_above(GTK_WINDOW(m_widget),
1370 m_windowStyle & wxSTAY_ON_TOP);
1371 }
1372
1373 if ( styleChanges & wxFRAME_NO_TASKBAR )
1374 {
1375 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget),
1376 m_windowStyle & wxFRAME_NO_TASKBAR);
1377 }
1378 }
1379
1380 /* Get the X Window between child and the root window.
1381 This should usually be the WM managed XID */
1382 static Window wxGetTopmostWindowX11(Display *dpy, Window child)
1383 {
1384 Window root, parent;
1385 Window* children;
1386 unsigned int nchildren;
1387
1388 XQueryTree(dpy, child, &root, &parent, &children, &nchildren);
1389 XFree(children);
1390
1391 while (parent != root) {
1392 child = parent;
1393 XQueryTree(dpy, child, &root, &parent, &children, &nchildren);
1394 XFree(children);
1395 }
1396
1397 return child;
1398 }
1399
1400 bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha)
1401 {
1402 GdkWindow* window = NULL;
1403 if (m_widget)
1404 window = gtk_widget_get_window(m_widget);
1405 if (window == NULL)
1406 return false;
1407
1408 Display* dpy = GDK_WINDOW_XDISPLAY(window);
1409 // We need to get the X Window that has the root window as the immediate parent
1410 // and m_widget->window as a child. This should be the X Window that the WM manages and
1411 // from which the opacity property is checked from.
1412 Window win = wxGetTopmostWindowX11(dpy, GDK_WINDOW_XID(window));
1413
1414
1415 // Using pure Xlib to not have a GTK version check mess due to gtk2.0 not having GdkDisplay
1416 if (alpha == 0xff)
1417 XDeleteProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False));
1418 else
1419 {
1420 long opacity = alpha * 0x1010101L;
1421 XChangeProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False),
1422 XA_CARDINAL, 32, PropModeReplace,
1423 (unsigned char *) &opacity, 1L);
1424 }
1425 XSync(dpy, False);
1426 return true;
1427 }
1428
1429 bool wxTopLevelWindowGTK::CanSetTransparent()
1430 {
1431 // allow to override automatic detection as it's far from perfect
1432 const wxString SYSOPT_TRANSPARENT = "gtk.tlw.can-set-transparent";
1433 if ( wxSystemOptions::HasOption(SYSOPT_TRANSPARENT) )
1434 {
1435 return wxSystemOptions::GetOptionInt(SYSOPT_TRANSPARENT) != 0;
1436 }
1437
1438 #if GTK_CHECK_VERSION(2,10,0)
1439 if (!gtk_check_version(2,10,0))
1440 {
1441 return (gtk_widget_is_composited (m_widget));
1442 }
1443 else
1444 #endif // In case of lower versions than gtk+-2.10.0 we could look for _NET_WM_CM_Sn ourselves
1445 {
1446 return false;
1447 }
1448
1449 #if 0 // Don't be optimistic here for the sake of wxAUI
1450 int opcode, event, error;
1451 // Check for the existence of a RGBA visual instead?
1452 return XQueryExtension(gdk_x11_get_default_xdisplay (),
1453 "Composite", &opcode, &event, &error);
1454 #endif
1455 }