]>
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"
23 // this is defined in src/gtk/toplevel.cpp
24 extern int wxOpenModalDialogsCount
;
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
35 m_modalShowing
= false;
36 m_themeEnabled
= true;
39 wxDialog::wxDialog( wxWindow
*parent
,
40 wxWindowID id
, const wxString
&title
,
41 const wxPoint
&pos
, const wxSize
&size
,
42 long style
, const wxString
&name
)
46 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
49 bool wxDialog::Create( wxWindow
*parent
,
50 wxWindowID id
, const wxString
&title
,
51 const wxPoint
&pos
, const wxSize
&size
,
52 long style
, const wxString
&name
)
54 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
56 // all dialogs should have tab traversal enabled
57 style
|= wxTAB_TRAVERSAL
;
59 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
62 bool wxDialog::Show( bool show
)
64 if (!show
&& IsModal())
66 EndModal( wxID_CANCEL
);
69 if (show
&& CanDoLayoutAdaptation())
72 bool ret
= wxDialogBase::Show(show
);
82 m_isBeingDeleted
= true;
84 // if the dialog is modal, this will end its event loop
86 EndModal(wxID_CANCEL
);
89 bool wxDialog::IsModal() const
91 return m_modalShowing
;
94 void wxDialog::SetModal( bool WXUNUSED(flag
) )
96 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
99 int wxDialog::ShowModal()
101 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
103 // release the mouse if it's currently captured as the window having it
104 // will be disabled when this dialog is shown -- but will still keep the
105 // capture making it impossible to do anything in the modal dialog itself
106 wxWindow
* const win
= wxWindow::GetCapture();
108 win
->GTKReleaseMouseAndNotify();
110 // use the apps top level window as parent if none given unless explicitly
112 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
114 wxWindow
* const parent
= GetParentForModalDialog();
115 if ( parent
&& parent
!= this )
117 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
118 GTK_WINDOW(parent
->m_widget
) );
122 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
126 m_modalShowing
= true;
128 wxOpenModalDialogsCount
++;
130 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
131 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
133 wxGUIEventLoop().Run();
135 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
137 wxOpenModalDialogsCount
--;
139 return GetReturnCode();
142 void wxDialog::EndModal( int retCode
)
144 SetReturnCode( retCode
);
148 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
152 m_modalShowing
= false;