1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "filedlg.h"
14 #include "wx/filedlg.h"
17 #include "wx/generic/msgdlgg.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
26 bool gtk_filedialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
29 printf( "OnDelete from " );
30 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
31 printf( win->GetClassInfo()->GetClassName() );
40 //-----------------------------------------------------------------------------
41 // "clicked" for OK-button
42 //-----------------------------------------------------------------------------
45 void gtk_filedialog_ok_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
47 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
48 wxCommandEvent
event(wxEVT_NULL
);
51 style
= dialog
->GetStyle();
53 if((style
&wxSAVE
)&&(style
&wxOVERWRITE_PROMPT
))
55 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog
->m_widget
) )))
57 if(wxMessageBox(_("File exists. Overwrite?"),
58 _("Confirm"), wxYES_NO
) != wxYES
)
63 dialog
->OnOK( event
);
66 //-----------------------------------------------------------------------------
67 // "clicked" for Cancel-button
68 //-----------------------------------------------------------------------------
71 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
73 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
74 wxCommandEvent
event(wxEVT_NULL
);
75 dialog
->OnCancel( event
);
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
84 wxFileDialog::wxFileDialog( wxWindow
*parent
, const wxString
& message
,
85 const wxString
& defaultDir
, const wxString
& defaultFileName
,
86 const wxString
& wildCard
,
87 long style
, const wxPoint
& pos
)
91 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, "filedialog" );
94 m_fileName
= defaultFileName
;
96 m_wildCard
= wildCard
;
97 m_dialogStyle
= style
;
100 m_widget
= gtk_file_selection_new( m_message
);
102 int x
= (gdk_screen_width () - 400) / 2;
103 int y
= (gdk_screen_height () - 400) / 2;
104 gtk_widget_set_uposition( m_widget
, x
, y
);
106 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
108 m_path
.Append(m_dir
);
109 if(! m_path
.IsEmpty() && m_path
.Last()!='/') m_path
.Append('/');
110 m_path
.Append(m_fileName
);
112 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
);
114 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
115 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
117 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
118 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
120 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
121 GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback
), (gpointer
)this );
125 int wxFileDialog::ShowModal(void)
127 int ret
= wxDialog::ShowModal();
131 m_fileName
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
132 m_path
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
138 wxString
wxFileSelector( const char *title
,
139 const char *defaultDir
, const char *defaultFileName
,
140 const char *defaultExtension
, const char *filter
, int flags
,
141 wxWindow
*parent
, int x
, int y
)
143 wxString
filter2("");
144 if ( defaultExtension
&& !filter
)
145 filter2
= wxString("*.") + wxString(defaultExtension
) ;
149 wxString defaultDirString
;
151 defaultDirString
= defaultDir
;
153 defaultDirString
= "";
155 wxString defaultFilenameString
;
157 defaultFilenameString
= defaultFileName
;
159 defaultFilenameString
= "";
161 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
163 if ( fileDialog
.ShowModal() == wxID_OK
)
165 return fileDialog
.GetPath();
169 return wxEmptyString
;
173 wxString
wxLoadFileSelector( const char *what
, const char *extension
, const char *default_name
, wxWindow
*parent
)
175 char *ext
= (char *)extension
;
178 wxString str
= _("Load %s file");
179 sprintf(prompt
, str
, what
);
181 if (*ext
== '.') ext
++;
183 sprintf(wild
, "*.%s", ext
);
185 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);
188 wxString
wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
191 char *ext
= (char *)extension
;
194 wxString str
= _("Save %s file");
195 sprintf(prompt
, str
, what
);
197 if (*ext
== '.') ext
++;
199 sprintf(wild
, "*.%s", ext
);
201 return wxFileSelector (prompt
, (const char *) NULL
, default_name
, ext
, wild
, 0, parent
);