]>
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/ptr_scpd.h"
25 // this is defined in src/gtk/toplevel.cpp
26 extern int wxOpenModalDialogsCount
;
28 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop
);
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
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 m_isBeingDeleted
= true;
90 // if the dialog is modal, this will end its event loop
92 EndModal(wxID_CANCEL
);
95 bool wxDialog::IsModal() const
97 return m_modalShowing
;
100 void wxDialog::SetModal( bool WXUNUSED(flag
) )
102 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
105 int wxDialog::ShowModal()
107 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
109 // release the mouse if it's currently captured as the window having it
110 // will be disabled when this dialog is shown -- but will still keep the
111 // capture making it impossible to do anything in the modal dialog itself
112 wxWindow
* const win
= wxWindow::GetCapture();
114 win
->GTKReleaseMouseAndNotify();
116 // use the apps top level window as parent if none given unless explicitly
118 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
120 wxWindow
* const parent
= GetParentForModalDialog();
121 if ( parent
&& parent
!= this )
123 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
124 GTK_WINDOW(parent
->m_widget
) );
128 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
132 m_modalShowing
= true;
134 wxOpenModalDialogsCount
++;
136 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
137 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
139 // Run modal dialog event loop.
141 wxGUIEventLoopTiedPtr
modal(&m_modalLoop
, new wxGUIEventLoop());
145 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
147 wxOpenModalDialogsCount
--;
149 return GetReturnCode();
152 void wxDialog::EndModal( int retCode
)
154 SetReturnCode( retCode
);
158 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
162 m_modalShowing
= false;
164 // Ensure Exit() is only called once. The dialog's event loop may be terminated
165 // externally due to an uncaught exception.
166 if (m_modalLoop
&& m_modalLoop
->IsRunning())