]>
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"
18 #include "wx/cursor.h"
21 #include "wx/evtloop.h"
25 #include <gdk/gdkkeysyms.h>
27 #include "wx/gtk/win_gtk.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 // Don't allow window closing if there are open dialogs
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
)
46 m_modalShowing
= false;
47 m_themeEnabled
= true;
50 wxDialog::wxDialog( wxWindow
*parent
,
51 wxWindowID id
, const wxString
&title
,
52 const wxPoint
&pos
, const wxSize
&size
,
53 long style
, const wxString
&name
)
57 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
60 bool wxDialog::Create( wxWindow
*parent
,
61 wxWindowID id
, const wxString
&title
,
62 const wxPoint
&pos
, const wxSize
&size
,
63 long style
, const wxString
&name
)
65 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
67 // all dialogs should have tab traversal enabled
68 style
|= wxTAB_TRAVERSAL
;
70 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
73 bool wxDialog::Show( bool show
)
75 if (!show
&& IsModal())
77 EndModal( wxID_CANCEL
);
80 if (show
&& !m_sizeSet
)
82 /* by calling GtkOnSize here, we don't have to call
83 either after showing the frame, which would entail
84 much ugly flicker nor from within the size_allocate
85 handler, because GTK 1.1.X forbids that. */
90 bool ret
= wxWindow::Show( show
);
92 if (show
) InitDialog();
97 bool wxDialog::IsModal() const
99 return m_modalShowing
;
102 void wxDialog::SetModal( bool WXUNUSED(flag
) )
104 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
107 int wxDialog::ShowModal()
111 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
112 return GetReturnCode();
115 // release the mouse if it's currently captured as the window having it
116 // will be disabled when this dialog is shown -- but will still keep the
117 // capture making it impossible to do anything in the modal dialog itself
118 wxWindow
* const win
= wxWindow::GetCapture();
120 win
->GTKReleaseMouseAndNotify();
122 // use the apps top level window as parent if none given unless explicitly
124 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
126 wxWindow
* const parent
= GetParentForModalDialog();
127 if ( parent
&& parent
!= this )
129 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
130 GTK_WINDOW(parent
->m_widget
) );
134 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
138 m_modalShowing
= true;
142 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
143 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
145 wxGUIEventLoop().Run();
147 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
151 return GetReturnCode();
154 void wxDialog::EndModal( int retCode
)
156 SetReturnCode( retCode
);
160 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
164 m_modalShowing
= false;