]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dialog.cpp
wxWindow::OnSize() does _not_ call Layout() (it should only be done for
[wxWidgets.git] / src / gtk / dialog.cpp
CommitLineData
c801d85f
KB
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// delete
22
23bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
24{
25/*
26 printf( "OnDelete from " );
27 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
28 printf( win->GetClassInfo()->GetClassName() );
29 printf( ".\n" );
30*/
31
32 win->Close();
33
34 return TRUE;
35};
36
37//-----------------------------------------------------------------------------
38// wxDialog
39//-----------------------------------------------------------------------------
40
41BEGIN_EVENT_TABLE(wxDialog,wxWindow)
42 EVT_BUTTON (wxID_OK, wxDialog::OnOk)
43 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
44 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
45 EVT_CLOSE (wxDialog::OnCloseWindow)
46END_EVENT_TABLE()
47
48IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxWindow)
49
50wxDialog::wxDialog(void)
51{
52 m_title = "";
53 m_modalShowing = TRUE;
54 wxTopLevelWindows.Insert( this );
55};
56
57wxDialog::wxDialog( wxWindow *parent,
58 wxWindowID id, const wxString &title,
59 const wxPoint &pos, const wxSize &size,
debe6624 60 long style, const wxString &name )
c801d85f
KB
61{
62 wxTopLevelWindows.Insert( this );
63 Create( parent, id, title, pos, size, style, name );
64};
65
66bool wxDialog::Create( wxWindow *parent,
67 wxWindowID id, const wxString &title,
68 const wxPoint &pos, const wxSize &size,
debe6624 69 long style, const wxString &name )
c801d85f
KB
70{
71 m_needParent = FALSE;
72
73 PreCreation( parent, id, pos, size, style, name );
74
75 m_modalShowing = ((m_windowStyle & wxDIALOG_MODAL) == wxDIALOG_MODAL);
76
77 m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL );
78 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
79
80 gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL);
81
82 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
83 GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this );
84
85 m_wxwindow = gtk_myfixed_new();
86 gtk_widget_show( m_wxwindow );
87 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
88
89 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
90
91 SetTitle( title );
92
93 PostCreation();
94
95 return TRUE;
96};
97
98wxDialog::~wxDialog(void)
99{
100 wxTopLevelWindows.DeleteObject( this );
101 if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
102};
103
104void wxDialog::SetTitle(const wxString& title )
105{
106 m_title = title;
107 gtk_window_set_title( GTK_WINDOW(m_widget), m_title );
108};
109
110wxString wxDialog::GetTitle(void) const
111{
112 return (wxString&)m_title;
113};
114
115void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
116{
117 if (Validate()) TransferDataFromWindow();
118};
119
120void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
121{
122 if (IsModal())
123 EndModal(wxID_CANCEL);
124 else
125 {
126 SetReturnCode(wxID_CANCEL);
127 this->Show(FALSE);
128 };
129};
130
131void wxDialog::OnOk( wxCommandEvent &WXUNUSED(event) )
132{
133 if ( Validate() && TransferDataFromWindow())
134 {
135 if (IsModal())
136 EndModal(wxID_OK);
137 else
138 {
139 SetReturnCode(wxID_OK);
140 this->Show(FALSE);
141 };
142 };
143 EndModal( wxID_OK );
144};
145
146void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
147{
148 // yes
149};
150
151bool wxDialog::OnClose(void)
152{
153 static wxList closing;
154
155 if (closing.Member(this)) return FALSE; // no loops
156
157 closing.Append(this);
158
159 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
160 cancelEvent.SetEventObject( this );
161 GetEventHandler()->ProcessEvent(cancelEvent);
162 closing.DeleteObject(this);
163
164 return FALSE;
165}
166
167void wxDialog::OnCloseWindow(wxCloseEvent& event)
168{
169 if (GetEventHandler()->OnClose() || event.GetForce())
170 {
171 this->Destroy();
172 };
173};
174
debe6624 175bool wxDialog::Show( bool show )
c801d85f
KB
176{
177 if (!show && m_modalShowing)
178 {
179 EndModal( wxID_CANCEL );
180 };
181
182 wxWindow::Show( show );
183
184 if (show) InitDialog();
185
186 if (show && m_modalShowing)
187 {
188 gtk_grab_add( m_widget );
189 gtk_main();
190 gtk_grab_remove( m_widget );
191 };
192
193 return TRUE;
194};
195
196int wxDialog::ShowModal(void)
197{
198 Show( TRUE );
199 return GetReturnCode();
200};
201
202void wxDialog::EndModal( int retCode )
203{
204 gtk_main_quit();
205 SetReturnCode( retCode );
206};
207
208void wxDialog::InitDialog(void)
209{
210 wxWindow::InitDialog();
211};
212