]>
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 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 // Don't allow window closing if there are open dialogs
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
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 bool ret
= wxWindow::Show( show
);
75 if (show
) InitDialog();
80 bool wxDialog::IsModal() const
82 return m_modalShowing
;
85 void wxDialog::SetModal( bool WXUNUSED(flag
) )
87 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
90 int wxDialog::ShowModal()
94 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
95 return GetReturnCode();
98 // release the mouse if it's currently captured as the window having it
99 // will be disabled when this dialog is shown -- but will still keep the
100 // capture making it impossible to do anything in the modal dialog itself
101 wxWindow
* const win
= wxWindow::GetCapture();
103 win
->GTKReleaseMouseAndNotify();
105 // use the apps top level window as parent if none given unless explicitly
107 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
109 wxWindow
* const parent
= GetParentForModalDialog();
110 if ( parent
&& parent
!= this )
112 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
113 GTK_WINDOW(parent
->m_widget
) );
117 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
121 m_modalShowing
= true;
125 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
126 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
128 wxGUIEventLoop().Run();
130 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
134 return GetReturnCode();
137 void wxDialog::EndModal( int retCode
)
139 SetReturnCode( retCode
);
143 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
147 m_modalShowing
= false;