]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/dialog.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
12 #include "wx/dialog.h"
17 #include "wx/cursor.h"
20 #include "wx/evtloop.h"
21 #include "wx/modalhook.h"
25 #include <gdk/gdkkeysyms.h>
27 #include "wx/gtk1/win_gtk.h"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 extern int g_openDialogs
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 BEGIN_EVENT_TABLE(wxDialog
,wxDialogBase
)
40 EVT_BUTTON (wxID_OK
, wxDialog::OnOK
)
41 EVT_BUTTON (wxID_CANCEL
, wxDialog::OnCancel
)
42 EVT_BUTTON (wxID_APPLY
, wxDialog::OnApply
)
43 EVT_CLOSE (wxDialog::OnCloseWindow
)
50 m_modalShowing
= false;
51 m_themeEnabled
= true;
54 wxDialog::wxDialog( wxWindow
*parent
,
55 wxWindowID id
, const wxString
&title
,
56 const wxPoint
&pos
, const wxSize
&size
,
57 long style
, const wxString
&name
)
61 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
64 bool wxDialog::Create( wxWindow
*parent
,
65 wxWindowID id
, const wxString
&title
,
66 const wxPoint
&pos
, const wxSize
&size
,
67 long style
, const wxString
&name
)
69 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
71 // all dialogs should have tab traversal enabled
72 style
|= wxTAB_TRAVERSAL
;
74 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
77 void wxDialog::OnApply( wxCommandEvent
&WXUNUSED(event
) )
80 TransferDataFromWindow();
83 void wxDialog::OnCancel( wxCommandEvent
&WXUNUSED(event
) )
87 EndModal(wxID_CANCEL
);
91 SetReturnCode(wxID_CANCEL
);
96 void wxDialog::OnOK( wxCommandEvent
&WXUNUSED(event
) )
98 if (Validate() && TransferDataFromWindow())
106 SetReturnCode(wxID_OK
);
112 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
117 void wxDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
119 // We'll send a Cancel message by default,
120 // which may close the dialog.
121 // Check for looping if the Cancel event handler calls Close().
123 // Note that if a cancel button and handler aren't present in the dialog,
124 // nothing will happen when you close the dialog via the window manager, or
126 // We wouldn't want to destroy the dialog by default, since the dialog may have been
127 // created on the stack.
128 // However, this does mean that calling dialog->Close() won't delete the dialog
129 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
130 // sure to destroy the dialog.
131 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
133 static wxList s_closing
;
135 if (s_closing
.Member(this))
138 s_closing
.Append(this);
140 wxCommandEvent
cancelEvent(wxEVT_BUTTON
, wxID_CANCEL
);
141 cancelEvent
.SetEventObject( this );
142 HandleWindowEvent(cancelEvent
);
143 s_closing
.DeleteObject(this);
146 bool wxDialog::Show( bool show
)
148 if (!show
&& IsModal())
150 EndModal( wxID_CANCEL
);
153 if (show
&& !m_sizeSet
)
155 /* by calling GtkOnSize here, we don't have to call
156 either after showing the frame, which would entail
157 much ugly flicker nor from within the size_allocate
158 handler, because GTK 1.1.X forbids that. */
160 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
163 if (show
&& CanDoLayoutAdaptation())
164 DoLayoutAdaptation();
166 bool ret
= wxWindow::Show( show
);
168 if (show
) InitDialog();
173 bool wxDialog::IsModal() const
175 return m_modalShowing
;
178 void wxDialog::SetModal( bool WXUNUSED(flag
) )
180 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
183 int wxDialog::ShowModal()
185 WX_HOOK_MODAL_DIALOG();
189 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
190 return GetReturnCode();
193 // use the apps top level window as parent if none given unless explicitly
195 wxWindow
* const parent
= GetParentForModalDialog();
199 gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(parent
->m_widget
) );
202 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
206 m_modalShowing
= true;
210 gtk_grab_add( m_widget
);
214 gtk_grab_remove( m_widget
);
218 return GetReturnCode();
221 void wxDialog::EndModal( int retCode
)
223 SetReturnCode( retCode
);
227 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
231 m_modalShowing
= false;