]>
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 // use the apps top level window as parent if none given unless explicitly
117 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
119 wxWindow
* const parent
= GetParentForModalDialog();
120 if ( parent
&& parent
!= this )
122 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
123 GTK_WINDOW(parent
->m_widget
) );
127 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
131 m_modalShowing
= true;
135 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
136 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
138 wxGUIEventLoop().Run();
140 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
144 return GetReturnCode();
147 void wxDialog::EndModal( int retCode
)
149 SetReturnCode( retCode
);
153 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
157 m_modalShowing
= false;