]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dialog.cpp
ODBC compile (and link) fixes
[wxWidgets.git] / src / gtk1 / 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())
1a6944fd 123 {
c801d85f 124 EndModal(wxID_CANCEL);
1a6944fd 125 }
c801d85f
KB
126 else
127 {
128 SetReturnCode(wxID_CANCEL);
129 this->Show(FALSE);
130 };
131};
132
133void wxDialog::OnOk( wxCommandEvent &WXUNUSED(event) )
134{
135 if ( Validate() && TransferDataFromWindow())
136 {
137 if (IsModal())
1a6944fd 138 {
c801d85f 139 EndModal(wxID_OK);
1a6944fd 140 }
c801d85f
KB
141 else
142 {
143 SetReturnCode(wxID_OK);
144 this->Show(FALSE);
145 };
146 };
c801d85f
KB
147};
148
149void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
150{
151 // yes
152};
153
154bool wxDialog::OnClose(void)
155{
156 static wxList closing;
157
158 if (closing.Member(this)) return FALSE; // no loops
1a6944fd 159
c801d85f
KB
160 closing.Append(this);
161
162 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
163 cancelEvent.SetEventObject( this );
164 GetEventHandler()->ProcessEvent(cancelEvent);
165 closing.DeleteObject(this);
166
167 return FALSE;
168}
169
170void wxDialog::OnCloseWindow(wxCloseEvent& event)
171{
172 if (GetEventHandler()->OnClose() || event.GetForce())
173 {
174 this->Destroy();
175 };
176};
177
debe6624 178bool wxDialog::Show( bool show )
c801d85f
KB
179{
180 if (!show && m_modalShowing)
181 {
182 EndModal( wxID_CANCEL );
183 };
184
185 wxWindow::Show( show );
186
187 if (show) InitDialog();
188
189 if (show && m_modalShowing)
190 {
191 gtk_grab_add( m_widget );
192 gtk_main();
193 gtk_grab_remove( m_widget );
194 };
195
196 return TRUE;
197};
198
199int wxDialog::ShowModal(void)
200{
201 Show( TRUE );
202 return GetReturnCode();
203};
204
205void wxDialog::EndModal( int retCode )
206{
207 gtk_main_quit();
208 SetReturnCode( retCode );
209};
210
211void wxDialog::InitDialog(void)
212{
213 wxWindow::InitDialog();
214};
215