]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dialog.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 #include "wx/dialog.h"
16 #include "wx/cursor.h"
19 #include "wx/evtloop.h"
21 #include "wx/scopedptr.h"
22 #include "wx/testing.h"
25 #include "wx/gtk/private/gtk2-compat.h"
27 // this is defined in src/gtk/toplevel.cpp
28 extern int wxOpenModalDialogsCount
;
30 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop
)
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
41 m_modalShowing
= false;
42 m_themeEnabled
= true;
45 wxDialog::wxDialog( wxWindow
*parent
,
46 wxWindowID id
, const wxString
&title
,
47 const wxPoint
&pos
, const wxSize
&size
,
48 long style
, const wxString
&name
)
52 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
55 bool wxDialog::Create( wxWindow
*parent
,
56 wxWindowID id
, const wxString
&title
,
57 const wxPoint
&pos
, const wxSize
&size
,
58 long style
, const wxString
&name
)
60 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
62 // all dialogs should have tab traversal enabled
63 style
|= wxTAB_TRAVERSAL
;
65 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
68 bool wxDialog::Show( bool show
)
70 if (!show
&& IsModal())
72 EndModal( wxID_CANCEL
);
75 if (show
&& CanDoLayoutAdaptation())
78 bool ret
= wxDialogBase::Show(show
);
88 // if the dialog is modal, this will end its event loop
90 EndModal(wxID_CANCEL
);
93 bool wxDialog::IsModal() const
95 return m_modalShowing
;
98 void wxDialog::SetModal( bool WXUNUSED(flag
) )
100 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
103 // Workaround for Ubuntu overlay scrollbar, which adds our GtkWindow to a
104 // private window group in a GtkScrollbar realize handler. This breaks the grab
105 // done by gtk_window_set_modal(), and allows menus and toolbars in the parent
106 // frame to remain active. So, we install an emission hook on the "realize"
107 // signal while showing a modal dialog. For any realize on a GtkScrollbar,
108 // we check the top level parent to see if it has an explicitly set window
109 // group that is not the same as its transient parent. If we find this, we
110 // put the top level back in the same window group as its transient parent, and
112 // Ubuntu 12.04 and 12.10 are known to have this problem.
114 // need 2.10 for gtk_window_get_group()
115 #if GTK_CHECK_VERSION(2,10,0)
118 realize_hook(GSignalInvocationHint
*, unsigned, const GValue
* param_values
, void*)
120 void* p
= g_value_peek_pointer(param_values
);
121 if (GTK_IS_SCROLLBAR(p
))
123 GtkWindow
* toplevel
= GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(p
)));
124 GtkWindow
* transient_parent
= gtk_window_get_transient_for(toplevel
);
125 if (transient_parent
&& gtk_window_has_group(toplevel
))
127 GtkWindowGroup
* group
= gtk_window_get_group(toplevel
);
128 GtkWindowGroup
* group_parent
= gtk_window_get_group(transient_parent
);
129 if (group
!= group_parent
)
131 gtk_window_group_add_window(group_parent
, toplevel
);
132 gtk_grab_add(GTK_WIDGET(toplevel
));
141 int wxDialog::ShowModal()
143 WX_TESTING_SHOW_MODAL_HOOK();
145 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
147 // release the mouse if it's currently captured as the window having it
148 // will be disabled when this dialog is shown -- but will still keep the
149 // capture making it impossible to do anything in the modal dialog itself
150 wxWindow
* const win
= wxWindow::GetCapture();
152 win
->GTKReleaseMouseAndNotify();
154 wxWindow
* const parent
= GetParentForModalDialog();
157 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
158 GTK_WINDOW(parent
->m_widget
) );
161 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
163 #if GTK_CHECK_VERSION(2,10,0)
167 // Ubuntu overlay scrollbar uses at least GTK 2.24
168 if (gtk_check_version(2,24,0) == NULL
)
171 sigId
= g_signal_lookup("realize", GTK_TYPE_WIDGET
);
172 hookId
= g_signal_add_emission_hook(sigId
, 0, realize_hook
, NULL
, NULL
);
178 m_modalShowing
= true;
180 wxOpenModalDialogsCount
++;
182 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
183 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
185 // Run modal dialog event loop.
187 wxGUIEventLoopTiedPtr
modal(&m_modalLoop
, new wxGUIEventLoop());
191 #if GTK_CHECK_VERSION(2,10,0)
193 g_signal_remove_emission_hook(sigId
, hookId
);
196 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
198 wxOpenModalDialogsCount
--;
200 return GetReturnCode();
203 void wxDialog::EndModal( int retCode
)
205 SetReturnCode( retCode
);
209 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
213 m_modalShowing
= false;
215 // Ensure Exit() is only called once. The dialog's event loop may be terminated
216 // externally due to an uncaught exception.
217 if (m_modalLoop
&& m_modalLoop
->IsRunning())