]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dialog.cpp
7fcfd47c56e7eb9304bb486c0e4903542753ff48
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"
25 // this is defined in src/gtk/toplevel.cpp
26 extern int wxOpenModalDialogsCount
;
28 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop
)
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
39 m_modalShowing
= false;
40 m_themeEnabled
= true;
43 wxDialog::wxDialog( wxWindow
*parent
,
44 wxWindowID id
, const wxString
&title
,
45 const wxPoint
&pos
, const wxSize
&size
,
46 long style
, const wxString
&name
)
50 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
53 bool wxDialog::Create( wxWindow
*parent
,
54 wxWindowID id
, const wxString
&title
,
55 const wxPoint
&pos
, const wxSize
&size
,
56 long style
, const wxString
&name
)
58 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
60 // all dialogs should have tab traversal enabled
61 style
|= wxTAB_TRAVERSAL
;
63 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
66 bool wxDialog::Show( bool show
)
68 if (!show
&& IsModal())
70 EndModal( wxID_CANCEL
);
73 if (show
&& CanDoLayoutAdaptation())
76 bool ret
= wxDialogBase::Show(show
);
86 // if the dialog is modal, this will end its event loop
88 EndModal(wxID_CANCEL
);
91 bool wxDialog::IsModal() const
93 return m_modalShowing
;
96 void wxDialog::SetModal( bool WXUNUSED(flag
) )
98 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
101 int wxDialog::ShowModal()
103 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
105 // release the mouse if it's currently captured as the window having it
106 // will be disabled when this dialog is shown -- but will still keep the
107 // capture making it impossible to do anything in the modal dialog itself
108 wxWindow
* const win
= wxWindow::GetCapture();
110 win
->GTKReleaseMouseAndNotify();
112 wxWindow
* const parent
= GetParentForModalDialog();
115 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
116 GTK_WINDOW(parent
->m_widget
) );
119 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
123 m_modalShowing
= true;
125 wxOpenModalDialogsCount
++;
127 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
128 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
130 // Run modal dialog event loop.
132 wxGUIEventLoopTiedPtr
modal(&m_modalLoop
, new wxGUIEventLoop());
136 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
138 wxOpenModalDialogsCount
--;
140 return GetReturnCode();
143 void wxDialog::EndModal( int retCode
)
145 SetReturnCode( retCode
);
149 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
153 m_modalShowing
= false;
155 // Ensure Exit() is only called once. The dialog's event loop may be terminated
156 // externally due to an uncaught exception.
157 if (m_modalLoop
&& m_modalLoop
->IsRunning())