1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/toplevel.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
22 #define XIconifyWindow XICONIFYWINDOW
25 #include "wx/toplevel.h"
34 #include "wx/gtk/private.h"
35 #include "wx/evtloop.h"
36 #include "wx/sysopt.h"
41 #include "wx/gtk/win_gtk.h"
43 #include "wx/unix/utilsx11.h"
46 #include <X11/Xatom.h>
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 extern int g_openDialogs
;
53 extern wxWindowGTK
*g_delayedFocus
;
55 // the frame that is currently active (i.e. its child has focus). It is
56 // used to generate wxActivateEvents
57 static wxTopLevelWindowGTK
*g_activeFrame
= (wxTopLevelWindowGTK
*) NULL
;
58 static wxTopLevelWindowGTK
*g_lastActiveFrame
= (wxTopLevelWindowGTK
*) NULL
;
60 // if we detect that the app has got/lost the focus, we set this variable to
61 // either TRUE or FALSE and an activate event will be sent during the next
62 // OnIdle() call and it is reset to -1: this value means that we shouldn't
63 // send any activate events at all
64 static int g_sendActivateEvent
= -1;
66 //-----------------------------------------------------------------------------
67 // RequestUserAttention related functions
68 //-----------------------------------------------------------------------------
71 static void wxgtk_window_set_urgency_hint (GtkWindow
*win
,
74 wxASSERT_MSG( GTK_WIDGET_REALIZED(win
), wxT("wxgtk_window_set_urgency_hint: GdkWindow not realized") );
75 GdkWindow
*window
= GTK_WIDGET(win
)->window
;
78 wm_hints
= XGetWMHints(GDK_WINDOW_XDISPLAY(window
), GDK_WINDOW_XWINDOW(window
));
81 wm_hints
= XAllocWMHints();
84 wm_hints
->flags
|= XUrgencyHint
;
86 wm_hints
->flags
&= ~XUrgencyHint
;
88 XSetWMHints(GDK_WINDOW_XDISPLAY(window
), GDK_WINDOW_XWINDOW(window
), wm_hints
);
92 static gboolean
gtk_frame_urgency_timer_callback( wxTopLevelWindowGTK
*win
)
94 #if GTK_CHECK_VERSION(2,7,0)
95 if(!gtk_check_version(2,7,0))
96 gtk_window_set_urgency_hint(GTK_WINDOW( win
->m_widget
), FALSE
);
99 wxgtk_window_set_urgency_hint(GTK_WINDOW( win
->m_widget
), FALSE
);
101 win
->m_urgency_hint
= -2;
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
111 static gboolean
gtk_frame_focus_in_callback( GtkWidget
*widget
,
112 GdkEvent
*WXUNUSED(event
),
113 wxTopLevelWindowGTK
*win
)
115 switch ( g_sendActivateEvent
)
118 // we've got focus from outside, synthetize wxActivateEvent
119 g_sendActivateEvent
= 1;
123 // another our window just lost focus, it was already ours before
124 // - don't send any wxActivateEvent
125 g_sendActivateEvent
= -1;
130 g_lastActiveFrame
= g_activeFrame
;
132 // wxPrintf( wxT("active: %s\n"), win->GetTitle().c_str() );
134 // MR: wxRequestUserAttention related block
135 switch( win
->m_urgency_hint
)
138 g_source_remove( win
->m_urgency_hint
);
139 // no break, fallthrough to remove hint too
141 #if GTK_CHECK_VERSION(2,7,0)
142 if(!gtk_check_version(2,7,0))
143 gtk_window_set_urgency_hint(GTK_WINDOW( widget
), FALSE
);
147 wxgtk_window_set_urgency_hint(GTK_WINDOW( widget
), FALSE
);
150 win
->m_urgency_hint
= -2;
156 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame
);
157 wxActivateEvent
event(wxEVT_ACTIVATE
, true, g_activeFrame
->GetId());
158 event
.SetEventObject(g_activeFrame
);
159 g_activeFrame
->GetEventHandler()->ProcessEvent(event
);
165 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
170 static gboolean
gtk_frame_focus_out_callback( GtkWidget
*widget
,
171 GdkEventFocus
*WXUNUSED(gdk_event
),
172 wxTopLevelWindowGTK
*win
)
174 // if the focus goes out of our app alltogether, OnIdle() will send
175 // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset
176 // g_sendActivateEvent to -1
177 g_sendActivateEvent
= 0;
179 // wxASSERT_MSG( (g_activeFrame == win), wxT("TLW deactivatd although it wasn't active") );
181 // wxPrintf( wxT("inactive: %s\n"), win->GetTitle().c_str() );
185 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame
);
186 wxActivateEvent
event(wxEVT_ACTIVATE
, false, g_activeFrame
->GetId());
187 event
.SetEventObject(g_activeFrame
);
188 g_activeFrame
->GetEventHandler()->ProcessEvent(event
);
190 g_activeFrame
= NULL
;
197 //-----------------------------------------------------------------------------
199 // Get cached size of WM decorations for given GdkWMDecoration.
200 static wxSize
& GetDecorSize(int decor
)
202 // In testing, only the title bar and GDK_DECOR_BORDER made a difference.
203 // 4 possible combinations of title bar and border
204 static wxSize size
[4];
208 if (decor
& (GDK_DECOR_MENU
| GDK_DECOR_MINIMIZE
| GDK_DECOR_MAXIMIZE
| GDK_DECOR_TITLE
))
211 if (decor
& GDK_DECOR_BORDER
)
216 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
221 static void gtk_frame_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxTopLevelWindowGTK
*win
)
227 if (!win
->IsFullScreen())
228 sizeDecor
= GetDecorSize(win
->m_gdkDecor
);
229 const int w
= alloc
->width
+ sizeDecor
.x
;
230 const int h
= alloc
->height
+ sizeDecor
.y
;
232 if (win
->m_width
!= w
|| win
->m_height
!= h
)
237 win
->GtkUpdateSize();
242 // ----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
248 void wxgtk_tlw_size_request_callback(GtkWidget
* WXUNUSED(widget
),
249 GtkRequisition
*requisition
,
250 wxTopLevelWindowGTK
*win
)
252 // we must return the size of the window without WM decorations, otherwise
253 // GTK+ gets confused, so don't call just GetSize() here
254 win
->GTKDoGetSize(&requisition
->width
, &requisition
->height
);
258 //-----------------------------------------------------------------------------
260 //-----------------------------------------------------------------------------
264 gtk_frame_delete_callback( GtkWidget
*WXUNUSED(widget
),
265 GdkEvent
*WXUNUSED(event
),
266 wxTopLevelWindowGTK
*win
)
268 if (win
->IsEnabled() &&
269 (g_openDialogs
== 0 || (win
->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) ||
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
284 gtk_frame_configure_callback( GtkWidget
* widget
,
285 GdkEventConfigure
*WXUNUSED(event
),
286 wxTopLevelWindowGTK
*win
)
288 if (!win
->m_hasVMT
|| !win
->IsShown())
292 gtk_window_get_position((GtkWindow
*)widget
, &point
.x
, &point
.y
);
296 wxMoveEvent
mevent(point
, win
->GetId());
297 mevent
.SetEventObject( win
);
298 win
->GetEventHandler()->ProcessEvent( mevent
);
304 //-----------------------------------------------------------------------------
305 // "realize" from m_widget
306 //-----------------------------------------------------------------------------
308 // we cannot MWM hints and icons before the widget has been realized,
309 // so we do this directly after realization
313 gtk_frame_realized_callback( GtkWidget
* WXUNUSED(widget
),
314 wxTopLevelWindowGTK
*win
)
316 // All this is for Motif Window Manager "hints" and is supposed to be
317 // recognized by other WM as well. Not tested.
318 gdk_window_set_decorations(win
->m_widget
->window
,
319 (GdkWMDecoration
)win
->m_gdkDecor
);
320 gdk_window_set_functions(win
->m_widget
->window
,
321 (GdkWMFunction
)win
->m_gdkFunc
);
323 // GTK's shrinking/growing policy
324 if ((win
->m_gdkFunc
& GDK_FUNC_RESIZE
) == 0)
325 gtk_window_set_resizable(GTK_WINDOW(win
->m_widget
), FALSE
);
327 gtk_window_set_policy(GTK_WINDOW(win
->m_widget
), 1, 1, 1);
330 wxIconBundle iconsOld
= win
->GetIcons();
331 if ( !iconsOld
.IsEmpty() )
333 win
->SetIcon( wxNullIcon
);
334 win
->SetIcons( iconsOld
);
339 //-----------------------------------------------------------------------------
340 // "map_event" from m_widget
341 //-----------------------------------------------------------------------------
345 gtk_frame_map_callback( GtkWidget
* widget
,
346 GdkEvent
* WXUNUSED(event
),
347 wxTopLevelWindow
*win
)
349 // Calculate size of WM decorations.
350 // Done here in case WM does not support the _NET_FRAME_EXTENTS property.
351 if (win
->IsDecorCacheable() && !win
->IsFullScreen())
354 gdk_window_get_frame_extents(widget
->window
, &rect
);
356 gdk_drawable_get_size(widget
->window
, &w
, &h
);
357 wxSize
& decorSize
= GetDecorSize(win
->m_gdkDecor
);
358 const wxSize size
= wxSize(rect
.width
- w
, rect
.height
- h
);
359 if (decorSize
.x
!= size
.x
|| decorSize
.y
!= size
.y
)
361 // Update window size and frame extents cache
362 win
->m_width
= rect
.width
;
363 win
->m_height
= rect
.height
;
364 win
->GtkUpdateSize();
369 win
->SetIconizeState(false);
374 //-----------------------------------------------------------------------------
375 // "unmap_event" from m_widget
376 //-----------------------------------------------------------------------------
380 gtk_frame_unmap_callback( GtkWidget
* WXUNUSED(widget
),
381 GdkEvent
* WXUNUSED(event
),
382 wxTopLevelWindow
*win
)
384 win
->SetIconizeState(true);
389 //-----------------------------------------------------------------------------
390 // "property_notify_event" from m_widget
391 //-----------------------------------------------------------------------------
394 static gboolean
property_notify_event(
395 GtkWidget
*, GdkEventProperty
* event
, wxTopLevelWindowGTK
* win
)
397 // Watch for changes to _NET_FRAME_EXTENTS property
398 static GdkAtom property
= gdk_atom_intern("_NET_FRAME_EXTENTS", false);
399 if (event
->state
== GDK_PROPERTY_NEW_VALUE
&& event
->atom
== property
&&
400 win
->IsDecorCacheable() && !win
->IsFullScreen())
403 #if GTK_CHECK_VERSION(2, 2, 0)
404 if (gtk_check_version(2, 2, 0) == NULL
)
406 xproperty
= gdk_x11_atom_to_xatom_for_display(
407 gdk_drawable_get_display(event
->window
), property
);
412 xproperty
= gdk_x11_atom_to_xatom(property
);
416 gulong nitems
, bytes_after
;
418 Status status
= XGetWindowProperty(
419 gdk_x11_drawable_get_xdisplay(event
->window
),
420 gdk_x11_drawable_get_xid(event
->window
),
422 0, 4, false, XA_CARDINAL
,
423 &type
, &format
, &nitems
, &bytes_after
, (guchar
**)&data
);
424 if (status
== Success
&& data
&& nitems
== 4)
426 wxSize
& decorSize
= GetDecorSize(win
->m_gdkDecor
);
428 wxSize(int(data
[0] + data
[1]), int(data
[2] + data
[3]));
429 if (decorSize
.x
!= size
.x
|| decorSize
.y
!= size
.y
)
431 // Update window size and frame extents cache
432 win
->m_width
+= size
.x
- decorSize
.x
;
433 win
->m_height
+= size
.y
- decorSize
.y
;
434 if (win
->m_width
< 0) win
->m_width
= 0;
435 if (win
->m_height
< 0) win
->m_height
= 0;
436 win
->GtkUpdateSize();
447 // ----------------------------------------------------------------------------
448 // wxTopLevelWindowGTK creation
449 // ----------------------------------------------------------------------------
451 void wxTopLevelWindowGTK::Init()
456 m_mainWidget
= (GtkWidget
*) NULL
;
457 m_isIconized
= false;
458 m_fsIsShowing
= false;
459 m_themeEnabled
= true;
460 m_gdkDecor
= m_gdkFunc
= 0;
466 bool wxTopLevelWindowGTK::Create( wxWindow
*parent
,
468 const wxString
& title
,
470 const wxSize
& sizeOrig
,
472 const wxString
&name
)
474 // always create a frame of some reasonable, even if arbitrary, size (at
475 // least for MSW compatibility)
476 wxSize size
= sizeOrig
;
477 size
.x
= WidthDefault(size
.x
);
478 size
.y
= HeightDefault(size
.y
);
480 wxTopLevelWindows
.Append( this );
482 if (!PreCreation( parent
, pos
, size
) ||
483 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
485 wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") );
491 // NB: m_widget may be !=NULL if it was created by derived class' Create,
492 // e.g. in wxTaskBarIconAreaGTK
493 if (m_widget
== NULL
)
495 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
497 m_widget
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
498 // Tell WM that this is a dialog window and make it center
499 // on parent by default (this is what GtkDialog ctor does):
500 gtk_window_set_type_hint(GTK_WINDOW(m_widget
),
501 GDK_WINDOW_TYPE_HINT_DIALOG
);
502 gtk_window_set_position(GTK_WINDOW(m_widget
),
503 GTK_WIN_POS_CENTER_ON_PARENT
);
507 m_widget
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
508 #if GTK_CHECK_VERSION(2,1,0)
509 if (!gtk_check_version(2,1,0))
511 if (style
& wxFRAME_TOOL_WINDOW
)
513 gtk_window_set_type_hint(GTK_WINDOW(m_widget
),
514 GDK_WINDOW_TYPE_HINT_UTILITY
);
516 // On some WMs, like KDE, a TOOL_WINDOW will still show
517 // on the taskbar, but on Gnome a TOOL_WINDOW will not.
518 // For consistency between WMs and with Windows, we
519 // should set the NO_TASKBAR flag which will apply
520 // the set_skip_taskbar_hint if it is available,
521 // ensuring no taskbar entry will appear.
522 style
|= wxFRAME_NO_TASKBAR
;
529 wxWindow
*topParent
= wxGetTopLevelParent(m_parent
);
530 if (topParent
&& (((GTK_IS_WINDOW(topParent
->m_widget
)) &&
531 (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)) ||
532 (style
& wxFRAME_FLOAT_ON_PARENT
)))
534 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
535 GTK_WINDOW(topParent
->m_widget
) );
538 #if GTK_CHECK_VERSION(2,2,0)
539 if (!gtk_check_version(2,2,0))
541 if (style
& wxFRAME_NO_TASKBAR
)
543 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget
), TRUE
);
549 if (!gtk_check_version(2,4,0))
551 if (style
& wxSTAY_ON_TOP
)
553 gtk_window_set_keep_above(GTK_WINDOW(m_widget
), TRUE
);
560 gtk_window_set_role( GTK_WINDOW(m_widget
), wxGTK_CONV( name
) );
563 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( title
) );
564 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
566 g_signal_connect (m_widget
, "delete_event",
567 G_CALLBACK (gtk_frame_delete_callback
), this);
569 // m_mainWidget holds the toolbar, the menubar and the client area
570 m_mainWidget
= gtk_pizza_new();
571 gtk_widget_show( m_mainWidget
);
572 GTK_WIDGET_UNSET_FLAGS( m_mainWidget
, GTK_CAN_FOCUS
);
573 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWidget
);
575 // m_wxwindow only represents the client area without toolbar and menubar
576 m_wxwindow
= gtk_pizza_new();
577 gtk_widget_show( m_wxwindow
);
578 gtk_container_add( GTK_CONTAINER(m_mainWidget
), m_wxwindow
);
580 // we donm't allow the frame to get the focus as otherwise
581 // the frame will grab it at arbitrary focus changes
582 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
584 if (m_parent
) m_parent
->AddChild( this );
586 // the user resized the frame by dragging etc.
587 g_signal_connect (m_widget
, "size_allocate",
588 G_CALLBACK (gtk_frame_size_callback
), this);
590 g_signal_connect (m_widget
, "size_request",
591 G_CALLBACK (wxgtk_tlw_size_request_callback
), this);
594 if ((m_x
!= -1) || (m_y
!= -1))
595 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
597 // we cannot set MWM hints and icons before the widget has
598 // been realized, so we do this directly after realization
599 g_signal_connect (m_widget
, "realize",
600 G_CALLBACK (gtk_frame_realized_callback
), this);
602 // map and unmap for iconized state
603 g_signal_connect (m_widget
, "map_event",
604 G_CALLBACK (gtk_frame_map_callback
), this);
605 g_signal_connect (m_widget
, "unmap_event",
606 G_CALLBACK (gtk_frame_unmap_callback
), this);
609 g_signal_connect (m_widget
, "configure_event",
610 G_CALLBACK (gtk_frame_configure_callback
), this);
613 g_signal_connect_after (m_widget
, "focus_in_event",
614 G_CALLBACK (gtk_frame_focus_in_callback
), this);
615 g_signal_connect_after (m_widget
, "focus_out_event",
616 G_CALLBACK (gtk_frame_focus_out_callback
), this);
618 gtk_widget_add_events(m_widget
, GDK_PROPERTY_CHANGE_MASK
);
619 g_signal_connect(m_widget
, "property_notify_event",
620 G_CALLBACK(property_notify_event
), this);
623 if ((style
& wxSIMPLE_BORDER
) || (style
& wxNO_BORDER
))
634 if ((style
& wxRESIZE_BORDER
) != 0)
635 m_gdkFunc
|= GDK_FUNC_RESIZE
;
639 m_gdkDecor
= GDK_DECOR_BORDER
;
640 m_gdkFunc
= GDK_FUNC_MOVE
;
642 // All this is for Motif Window Manager "hints" and is supposed to be
643 // recognized by other WMs as well.
644 if ((style
& wxCAPTION
) != 0)
646 m_gdkDecor
|= GDK_DECOR_TITLE
;
648 if ((style
& wxCLOSE_BOX
) != 0)
650 m_gdkFunc
|= GDK_FUNC_CLOSE
;
652 if ((style
& wxSYSTEM_MENU
) != 0)
654 m_gdkDecor
|= GDK_DECOR_MENU
;
656 if ((style
& wxMINIMIZE_BOX
) != 0)
658 m_gdkFunc
|= GDK_FUNC_MINIMIZE
;
659 m_gdkDecor
|= GDK_DECOR_MINIMIZE
;
661 if ((style
& wxMAXIMIZE_BOX
) != 0)
663 m_gdkFunc
|= GDK_FUNC_MAXIMIZE
;
664 m_gdkDecor
|= GDK_DECOR_MAXIMIZE
;
666 if ((style
& wxRESIZE_BORDER
) != 0)
668 m_gdkFunc
|= GDK_FUNC_RESIZE
;
669 m_gdkDecor
|= GDK_DECOR_RESIZEH
;
673 // m_gdkDecor needs to be set before calling GTKDoGetSize
675 GTKDoGetSize(&w
, &h
);
676 gtk_window_set_default_size(GTK_WINDOW(m_widget
), w
, h
);
681 wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
685 wxFAIL_MSG(_T("Window still grabbed"));
689 m_isBeingDeleted
= true;
691 // it may also be GtkScrolledWindow in the case of an MDI child
692 if (GTK_IS_WINDOW(m_widget
))
694 gtk_window_set_focus( GTK_WINDOW(m_widget
), NULL
);
697 if (g_activeFrame
== this)
698 g_activeFrame
= NULL
;
699 if (g_lastActiveFrame
== this)
700 g_lastActiveFrame
= NULL
;
703 bool wxTopLevelWindowGTK::EnableCloseButton( bool enable
)
706 m_gdkFunc
|= GDK_FUNC_CLOSE
;
708 m_gdkFunc
&= ~GDK_FUNC_CLOSE
;
710 if (GTK_WIDGET_REALIZED(m_widget
) && (m_widget
->window
))
711 gdk_window_set_functions( m_widget
->window
, (GdkWMFunction
)m_gdkFunc
);
716 bool wxTopLevelWindowGTK::ShowFullScreen(bool show
, long)
718 if (show
== m_fsIsShowing
)
719 return false; // return what?
721 m_fsIsShowing
= show
;
723 wxX11FullScreenMethod method
=
724 wxGetFullScreenMethodX11((WXDisplay
*)GDK_DISPLAY(),
725 (WXWindow
)GDK_ROOT_WINDOW());
727 #if GTK_CHECK_VERSION(2,2,0)
728 // NB: gtk_window_fullscreen() uses freedesktop.org's WMspec extensions
729 // to switch to fullscreen, which is not always available. We must
730 // check if WM supports the spec and use legacy methods if it
732 if ( (method
== wxX11_FS_WMSPEC
) && !gtk_check_version(2,2,0) )
735 gtk_window_fullscreen( GTK_WINDOW( m_widget
) );
737 gtk_window_unfullscreen( GTK_WINDOW( m_widget
) );
740 #endif // GTK+ >= 2.2.0
742 GdkWindow
*window
= m_widget
->window
;
746 GetPosition( &m_fsSaveFrame
.x
, &m_fsSaveFrame
.y
);
747 GetSize( &m_fsSaveFrame
.width
, &m_fsSaveFrame
.height
);
749 int screen_width
,screen_height
;
750 wxDisplaySize( &screen_width
, &screen_height
);
752 gint client_x
, client_y
, root_x
, root_y
;
755 if (method
!= wxX11_FS_WMSPEC
)
757 // don't do it always, Metacity hates it
758 m_fsSaveGdkFunc
= m_gdkFunc
;
759 m_fsSaveGdkDecor
= m_gdkDecor
;
760 m_gdkFunc
= m_gdkDecor
= 0;
761 gdk_window_set_decorations(window
, (GdkWMDecoration
)0);
762 gdk_window_set_functions(window
, (GdkWMFunction
)0);
765 gdk_window_get_origin (m_widget
->window
, &root_x
, &root_y
);
766 gdk_window_get_geometry (m_widget
->window
, &client_x
, &client_y
,
767 &width
, &height
, NULL
);
769 gdk_window_move_resize (m_widget
->window
, -client_x
, -client_y
,
770 screen_width
+ 1, screen_height
+ 1);
772 wxSetFullScreenStateX11((WXDisplay
*)GDK_DISPLAY(),
773 (WXWindow
)GDK_ROOT_WINDOW(),
774 (WXWindow
)GDK_WINDOW_XWINDOW(window
),
775 show
, &m_fsSaveFrame
, method
);
779 if (method
!= wxX11_FS_WMSPEC
)
781 // don't do it always, Metacity hates it
782 m_gdkFunc
= m_fsSaveGdkFunc
;
783 m_gdkDecor
= m_fsSaveGdkDecor
;
784 gdk_window_set_decorations(window
, (GdkWMDecoration
)m_gdkDecor
);
785 gdk_window_set_functions(window
, (GdkWMFunction
)m_gdkFunc
);
788 wxSetFullScreenStateX11((WXDisplay
*)GDK_DISPLAY(),
789 (WXWindow
)GDK_ROOT_WINDOW(),
790 (WXWindow
)GDK_WINDOW_XWINDOW(window
),
791 show
, &m_fsSaveFrame
, method
);
793 SetSize(m_fsSaveFrame
.x
, m_fsSaveFrame
.y
,
794 m_fsSaveFrame
.width
, m_fsSaveFrame
.height
);
798 // documented behaviour is to show the window if it's still hidden when
799 // showing it full screen
806 // ----------------------------------------------------------------------------
807 // overridden wxWindow methods
808 // ----------------------------------------------------------------------------
810 bool wxTopLevelWindowGTK::Show( bool show
)
812 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
814 if (show
== IsShown())
817 if (show
&& !m_sizeSet
)
819 /* by calling GtkOnSize here, we don't have to call
820 either after showing the frame, which would entail
821 much ugly flicker or from within the size_allocate
822 handler, because GTK 1.1.X forbids that. */
827 wxTopLevelWindowBase::Show(show
);
831 // make sure window has a non-default position, so when it is shown
832 // again, it won't be repositioned by WM as if it were a new window
833 // Note that this must be done _after_ the window is hidden.
834 gtk_window_move((GtkWindow
*)m_widget
, m_x
, m_y
);
840 void wxTopLevelWindowGTK::Raise()
842 gtk_window_present( GTK_WINDOW( m_widget
) );
845 void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x
), int WXUNUSED(y
), int WXUNUSED(width
), int WXUNUSED(height
) )
847 wxFAIL_MSG( wxT("DoMoveWindow called for wxTopLevelWindowGTK") );
850 // ----------------------------------------------------------------------------
852 // ----------------------------------------------------------------------------
854 void wxTopLevelWindowGTK::GTKDoGetSize(int *width
, int *height
) const
856 wxSize
size(m_width
, m_height
);
859 size
-= GetDecorSize(m_gdkDecor
);
860 if (size
.x
< 0) size
.x
= 0;
861 if (size
.y
< 0) size
.y
= 0;
863 if (width
) *width
= size
.x
;
864 if (height
) *height
= size
.y
;
867 void wxTopLevelWindowGTK::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
869 wxCHECK_RET( m_widget
, wxT("invalid frame") );
871 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
872 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
875 // deal with the position first
879 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
881 // -1 means "use existing" unless the flag above is specified
887 else // wxSIZE_ALLOW_MINUS_ONE
893 if ( m_x
!= old_x
|| m_y
!= old_y
)
895 gtk_window_move( GTK_WINDOW(m_widget
), m_x
, m_y
);
900 const wxSize
oldSize(m_width
, m_height
);
906 if (m_width
!= oldSize
.x
|| m_height
!= oldSize
.y
)
909 GTKDoGetSize(&w
, &h
);
910 gtk_window_resize(GTK_WINDOW(m_widget
), w
, h
);
916 void wxTopLevelWindowGTK::DoGetClientSize( int *width
, int *height
) const
920 // for consistency with wxMSW, client area is supposed to be empty for
921 // the iconized windows
930 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
933 GTKDoGetSize(&w
, &h
);
936 *width
= w
- 2 * m_miniEdge
;
942 *height
= h
- 2 * m_miniEdge
- m_miniTitle
;
948 void wxTopLevelWindowGTK::DoSetSizeHints( int minW
, int minH
,
952 wxTopLevelWindowBase::DoSetSizeHints( minW
, minH
, maxW
, maxH
, incW
, incH
);
954 const wxSize minSize
= GetMinSize();
955 const wxSize maxSize
= GetMaxSize();
958 const wxSize sizeDecor
= GetDecorSize(m_gdkDecor
);
959 if (minSize
.x
> 0 || minSize
.y
> 0)
961 hints_mask
|= GDK_HINT_MIN_SIZE
;
962 hints
.min_width
= minSize
.x
- sizeDecor
.x
;
963 if (hints
.min_width
< 0)
965 hints
.min_height
= minSize
.y
- sizeDecor
.y
;
966 if (hints
.min_height
< 0)
967 hints
.min_height
= 0;
969 if (maxSize
.x
> 0 || maxSize
.y
> 0)
971 hints_mask
|= GDK_HINT_MAX_SIZE
;
972 hints
.max_width
= maxSize
.x
- sizeDecor
.x
;
973 if (hints
.max_width
< 0)
974 hints
.max_width
= INT_MAX
;
975 hints
.max_height
= maxSize
.y
- sizeDecor
.y
;
976 if (hints
.max_height
< 0)
977 hints
.max_height
= INT_MAX
;
979 if (incW
> 0 || incH
> 0)
981 hints_mask
|= GDK_HINT_RESIZE_INC
;
982 hints
.width_inc
= incW
> 0 ? incW
: 1;
983 hints
.height_inc
= incH
> 0 ? incH
: 1;
985 gtk_window_set_geometry_hints(
986 (GtkWindow
*)m_widget
, NULL
, &hints
, (GdkWindowHints
)hints_mask
);
989 void wxTopLevelWindowGTK::GtkOnSize()
992 if (m_resizing
) return;
995 if ( m_wxwindow
== NULL
) return;
1002 GTKDoGetSize(&w
, &h
);
1003 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
1010 // send size event to frame
1011 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
1012 event
.SetEventObject( this );
1013 GetEventHandler()->ProcessEvent( event
);
1018 bool wxTopLevelWindowGTK::IsDecorCacheable() const
1023 void wxTopLevelWindowGTK::OnInternalIdle()
1025 if (!m_sizeSet
&& GTK_WIDGET_REALIZED(m_wxwindow
))
1029 // we'll come back later
1033 // set the focus if not done yet and if we can already do it
1034 if ( GTK_WIDGET_REALIZED(m_wxwindow
) )
1036 if ( g_delayedFocus
&&
1037 wxGetTopLevelParent((wxWindow
*)g_delayedFocus
) == this )
1039 wxLogTrace(_T("focus"),
1040 _T("Setting focus from wxTLW::OnIdle() to %s(%s)"),
1041 g_delayedFocus
->GetClassInfo()->GetClassName(),
1042 g_delayedFocus
->GetLabel().c_str());
1044 g_delayedFocus
->SetFocus();
1045 g_delayedFocus
= NULL
;
1049 wxWindow::OnInternalIdle();
1051 // Synthetize activate events.
1052 if ( g_sendActivateEvent
!= -1 )
1054 bool activate
= g_sendActivateEvent
!= 0;
1056 // if (!activate) wxPrintf( wxT("de") );
1057 // wxPrintf( wxT("activate\n") );
1060 g_sendActivateEvent
= -1;
1062 wxTheApp
->SetActive(activate
, (wxWindow
*)g_lastActiveFrame
);
1066 // ----------------------------------------------------------------------------
1068 // ----------------------------------------------------------------------------
1070 void wxTopLevelWindowGTK::SetTitle( const wxString
&title
)
1072 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1074 if ( title
== m_title
)
1079 gtk_window_set_title( GTK_WINDOW(m_widget
), wxGTK_CONV( title
) );
1082 void wxTopLevelWindowGTK::SetIcons( const wxIconBundle
&icons
)
1084 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1086 wxTopLevelWindowBase::SetIcons( icons
);
1090 const size_t numIcons
= icons
.GetIconCount();
1091 for ( size_t i
= 0; i
< numIcons
; i
++ )
1093 list
= g_list_prepend(list
, icons
.GetIconByIndex(i
).GetPixbuf());
1096 gtk_window_set_icon_list(GTK_WINDOW(m_widget
), list
);
1100 // ----------------------------------------------------------------------------
1101 // frame state: maximized/iconized/normal
1102 // ----------------------------------------------------------------------------
1104 void wxTopLevelWindowGTK::Maximize(bool maximize
)
1107 gtk_window_maximize( GTK_WINDOW( m_widget
) );
1109 gtk_window_unmaximize( GTK_WINDOW( m_widget
) );
1112 bool wxTopLevelWindowGTK::IsMaximized() const
1114 if(!m_widget
->window
)
1117 return gdk_window_get_state(m_widget
->window
) & GDK_WINDOW_STATE_MAXIMIZED
;
1120 void wxTopLevelWindowGTK::Restore()
1122 // "Present" seems similar enough to "restore"
1123 gtk_window_present( GTK_WINDOW( m_widget
) );
1126 void wxTopLevelWindowGTK::Iconize( bool iconize
)
1129 gtk_window_iconify( GTK_WINDOW( m_widget
) );
1131 gtk_window_deiconify( GTK_WINDOW( m_widget
) );
1134 bool wxTopLevelWindowGTK::IsIconized() const
1136 return m_isIconized
;
1139 void wxTopLevelWindowGTK::SetIconizeState(bool iconize
)
1141 if ( iconize
!= m_isIconized
)
1143 m_isIconized
= iconize
;
1144 (void)SendIconizeEvent(iconize
);
1148 void wxTopLevelWindowGTK::AddGrab()
1153 gtk_grab_add( m_widget
);
1154 wxGUIEventLoop().Run();
1155 gtk_grab_remove( m_widget
);
1159 void wxTopLevelWindowGTK::RemoveGrab()
1170 static bool do_shape_combine_region(GdkWindow
* window
, const wxRegion
& region
)
1174 if (region
.IsEmpty())
1176 gdk_window_shape_combine_mask(window
, NULL
, 0, 0);
1180 gdk_window_shape_combine_region(window
, region
.GetRegion(), 0, 0);
1188 bool wxTopLevelWindowGTK::SetShape(const wxRegion
& region
)
1190 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), false,
1191 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1193 GdkWindow
*window
= NULL
;
1196 window
= GTK_PIZZA(m_wxwindow
)->bin_window
;
1197 do_shape_combine_region(window
, region
);
1199 window
= m_widget
->window
;
1200 return do_shape_combine_region(window
, region
);
1203 bool wxTopLevelWindowGTK::IsActive()
1205 return (this == (wxTopLevelWindowGTK
*)g_activeFrame
);
1208 void wxTopLevelWindowGTK::RequestUserAttention(int flags
)
1210 bool new_hint_value
= false;
1212 // FIXME: This is a workaround to focus handling problem
1213 // If RequestUserAttention is called for example right after a wxSleep, OnInternalIdle hasn't
1214 // yet been processed, and the internal focus system is not up to date yet.
1215 // wxYieldIfNeeded ensures the processing of it, but can have unwanted side effects - MR
1216 ::wxYieldIfNeeded();
1218 if(m_urgency_hint
>= 0)
1219 g_source_remove(m_urgency_hint
);
1221 m_urgency_hint
= -2;
1223 if( GTK_WIDGET_REALIZED(m_widget
) && !IsActive() )
1225 new_hint_value
= true;
1227 if (flags
& wxUSER_ATTENTION_INFO
)
1229 m_urgency_hint
= g_timeout_add(5000, (GSourceFunc
)gtk_frame_urgency_timer_callback
, this);
1231 m_urgency_hint
= -1;
1235 #if GTK_CHECK_VERSION(2,7,0)
1236 if(!gtk_check_version(2,7,0))
1237 gtk_window_set_urgency_hint(GTK_WINDOW( m_widget
), new_hint_value
);
1240 wxgtk_window_set_urgency_hint(GTK_WINDOW( m_widget
), new_hint_value
);
1243 void wxTopLevelWindowGTK::SetWindowStyleFlag( long style
)
1245 #if defined(__WXGTK24__) || GTK_CHECK_VERSION(2,2,0)
1246 // Store which styles were changed
1247 long styleChanges
= style
^ m_windowStyle
;
1250 // Process wxWindow styles. This also updates the internal variable
1251 // Therefore m_windowStyle bits carry now the _new_ style values
1252 wxWindow::SetWindowStyleFlag(style
);
1254 // just return for now if widget does not exist yet
1259 if ( (styleChanges
& wxSTAY_ON_TOP
) && !gtk_check_version(2,4,0) )
1260 gtk_window_set_keep_above(GTK_WINDOW(m_widget
), m_windowStyle
& wxSTAY_ON_TOP
);
1262 #if GTK_CHECK_VERSION(2,2,0)
1263 if ( (styleChanges
& wxFRAME_NO_TASKBAR
) && !gtk_check_version(2,2,0) )
1265 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget
), m_windowStyle
& wxFRAME_NO_TASKBAR
);
1270 /* Get the X Window between child and the root window.
1271 This should usually be the WM managed XID */
1272 static Window
wxGetTopmostWindowX11(Display
*dpy
, Window child
)
1274 Window root
, parent
;
1276 unsigned int nchildren
;
1278 XQueryTree(dpy
, child
, &root
, &parent
, &children
, &nchildren
);
1281 while (parent
!= root
) {
1283 XQueryTree(dpy
, child
, &root
, &parent
, &children
, &nchildren
);
1290 bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha
)
1292 if (!m_widget
|| !m_widget
->window
)
1295 Display
* dpy
= GDK_WINDOW_XDISPLAY (m_widget
->window
);
1296 // We need to get the X Window that has the root window as the immediate parent
1297 // and m_widget->window as a child. This should be the X Window that the WM manages and
1298 // from which the opacity property is checked from.
1299 Window win
= wxGetTopmostWindowX11(dpy
, GDK_WINDOW_XID (m_widget
->window
));
1302 // Using pure Xlib to not have a GTK version check mess due to gtk2.0 not having GdkDisplay
1304 XDeleteProperty(dpy
, win
, XInternAtom(dpy
, "_NET_WM_WINDOW_OPACITY", False
));
1307 long opacity
= alpha
* 0x1010101L
;
1308 XChangeProperty(dpy
, win
, XInternAtom(dpy
, "_NET_WM_WINDOW_OPACITY", False
),
1309 XA_CARDINAL
, 32, PropModeReplace
,
1310 (unsigned char *) &opacity
, 1L);
1316 bool wxTopLevelWindowGTK::CanSetTransparent()
1318 // allow to override automatic detection as it's far from perfect
1319 static const wxChar
*SYSOPT_TRANSPARENT
= wxT("gtk.tlw.can-set-transparent");
1320 if ( wxSystemOptions::HasOption(SYSOPT_TRANSPARENT
) )
1322 return wxSystemOptions::GetOptionInt(SYSOPT_TRANSPARENT
) != 0;
1325 #if GTK_CHECK_VERSION(2,10,0)
1326 if (!gtk_check_version(2,10,0))
1328 return (gtk_widget_is_composited (m_widget
));
1331 #endif // In case of lower versions than gtk+-2.10.0 we could look for _NET_WM_CM_Sn ourselves
1336 #if 0 // Don't be optimistic here for the sake of wxAUI
1337 int opcode
, event
, error
;
1338 // Check for the existence of a RGBA visual instead?
1339 return XQueryExtension(gdk_x11_get_default_xdisplay (),
1340 "Composite", &opcode
, &event
, &error
);