]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dialog.cpp
wxFrame::SetIcon()
[wxWidgets.git] / src / gtk1 / dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dialog.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "dialog.h"
13 #endif
14
15 #include "wx/dialog.h"
16 #include "wx/frame.h"
17 #include "wx/app.h"
18 #include "wx/gtk/win_gtk.h"
19
20 //-----------------------------------------------------------------------------
21
22 extern wxList wxPendingDelete;
23
24 //-----------------------------------------------------------------------------
25 // delete
26
27 bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
28 {
29 /*
30 printf( "OnDelete from " );
31 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
32 printf( win->GetClassInfo()->GetClassName() );
33 printf( ".\n" );
34 */
35
36 win->Close();
37
38 return TRUE;
39 };
40
41 //-----------------------------------------------------------------------------
42 // wxDialog
43 //-----------------------------------------------------------------------------
44
45 BEGIN_EVENT_TABLE(wxDialog,wxWindow)
46 EVT_BUTTON (wxID_OK, wxDialog::OnOk)
47 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
48 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
49 EVT_CLOSE (wxDialog::OnCloseWindow)
50 END_EVENT_TABLE()
51
52 IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxWindow)
53
54 wxDialog::wxDialog(void)
55 {
56 m_title = "";
57 m_modalShowing = FALSE;
58 wxTopLevelWindows.Insert( this );
59 };
60
61 wxDialog::wxDialog( wxWindow *parent,
62 wxWindowID id, const wxString &title,
63 const wxPoint &pos, const wxSize &size,
64 long style, const wxString &name )
65 {
66 m_modalShowing = FALSE;
67 wxTopLevelWindows.Insert( this );
68 Create( parent, id, title, pos, size, style, name );
69 };
70
71 bool wxDialog::Create( wxWindow *parent,
72 wxWindowID id, const wxString &title,
73 const wxPoint &pos, const wxSize &size,
74 long style, const wxString &name )
75 {
76 m_needParent = FALSE;
77
78 PreCreation( parent, id, pos, size, style, name );
79
80 m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL );
81 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
82
83 gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL);
84
85 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
86 GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this );
87
88 m_wxwindow = gtk_myfixed_new();
89 gtk_widget_show( m_wxwindow );
90 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
91
92 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
93
94 SetTitle( title );
95
96 PostCreation();
97
98 return TRUE;
99 };
100
101 wxDialog::~wxDialog(void)
102 {
103 wxTopLevelWindows.DeleteObject( this );
104 if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
105 };
106
107 void wxDialog::SetTitle(const wxString& title )
108 {
109 m_title = title;
110 gtk_window_set_title( GTK_WINDOW(m_widget), m_title );
111 };
112
113 wxString wxDialog::GetTitle(void) const
114 {
115 return (wxString&)m_title;
116 };
117
118 void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
119 {
120 if (Validate()) TransferDataFromWindow();
121 };
122
123 void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
124 {
125 if (IsModal())
126 {
127 EndModal(wxID_CANCEL);
128 }
129 else
130 {
131 SetReturnCode(wxID_CANCEL);
132 this->Show(FALSE);
133 };
134 };
135
136 void wxDialog::OnOk( wxCommandEvent &WXUNUSED(event) )
137 {
138 if ( Validate() && TransferDataFromWindow())
139 {
140 if (IsModal())
141 {
142 EndModal(wxID_OK);
143 }
144 else
145 {
146 SetReturnCode(wxID_OK);
147 this->Show(FALSE);
148 };
149 };
150 };
151
152 void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
153 {
154 // yes
155 };
156
157 bool wxDialog::OnClose(void)
158 {
159 static wxList closing;
160
161 if (closing.Member(this)) return FALSE; // no loops
162
163 closing.Append(this);
164
165 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
166 cancelEvent.SetEventObject( this );
167 GetEventHandler()->ProcessEvent(cancelEvent);
168 closing.DeleteObject(this);
169
170 return FALSE;
171 }
172
173 bool wxDialog::Destroy(void)
174 {
175 if (!wxPendingDelete.Member(this))
176 wxPendingDelete.Append(this);
177
178 return TRUE;
179 }
180
181 void wxDialog::OnCloseWindow(wxCloseEvent& event)
182 {
183 if (GetEventHandler()->OnClose() || event.GetForce())
184 {
185 this->Destroy();
186 };
187 };
188
189 bool wxDialog::Show( bool show )
190 {
191 if (!show && IsModal() && m_modalShowing)
192 {
193 EndModal( wxID_CANCEL );
194 };
195
196 wxWindow::Show( show );
197
198 if (show) InitDialog();
199
200 return TRUE;
201 };
202
203 int wxDialog::ShowModal(void)
204 {
205 if (m_modalShowing) return GetReturnCode();
206
207 Show( TRUE );
208
209 m_modalShowing = TRUE;
210
211 gtk_grab_add( m_widget );
212 gtk_main();
213 gtk_grab_remove( m_widget );
214
215 return GetReturnCode();
216 };
217
218 void wxDialog::EndModal( int retCode )
219 {
220 SetReturnCode( retCode );
221
222 if (!m_modalShowing) return;
223 m_modalShowing = FALSE;
224
225 gtk_main_quit();
226 };
227
228 void wxDialog::InitDialog(void)
229 {
230 wxWindow::InitDialog();
231 };
232