1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "filedlg.h"
15 #include "wx/filedlg.h"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 void gtk_filedialog_ok_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
25 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
26 wxCommandEvent
event(wxEVT_NULL
);
27 dialog
->OnOk( event
);
30 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(widget
), gpointer data
)
32 wxFileDialog
*dialog
= (wxFileDialog
*)data
;
33 wxCommandEvent
event(wxEVT_NULL
);
34 dialog
->OnCancel( event
);
37 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
39 wxFileDialog::wxFileDialog(wxWindow
*parent
, const wxString
& message
,
40 const wxString
& defaultDir
, const wxString
& defaultFileName
,
41 const wxString
& wildCard
,
42 long style
, const wxPoint
& pos
)
46 PreCreation( parent
, -1, pos
, wxDefaultSize
, style
, "filedialog" );
49 m_fileName
= defaultFileName
;
51 m_wildCard
= wildCard
;
54 m_widget
= gtk_file_selection_new( "File selection" );
56 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
58 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
59 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
61 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
62 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
65 int wxFileDialog::ShowModal(void)
67 int ret
= wxDialog::ShowModal();
70 m_fileName
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
71 m_path
= gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget
) );
77 char *wxFileSelector(const char *title
,
78 const char *defaultDir
, const char *defaultFileName
,
79 const char *defaultExtension
, const char *filter
, int flags
,
80 wxWindow
*parent
, int x
, int y
)
83 if ( defaultExtension
&& !filter
)
84 filter2
= wxString("*.") + wxString(defaultExtension
) ;
88 wxString defaultDirString
;
90 defaultDirString
= defaultDir
;
92 defaultDirString
= "";
94 wxString defaultFilenameString
;
96 defaultFilenameString
= defaultFileName
;
98 defaultFilenameString
= "";
100 wxFileDialog
fileDialog(parent
, title
, defaultDirString
, defaultFilenameString
,
101 filter2
, flags
, wxPoint(x
, y
));
103 if ( fileDialog
.ShowModal() == wxID_OK
)
105 strcpy(wxBuffer
, (const char *)fileDialog
.GetPath());
112 char* wxLoadFileSelector(const char *what
, const char *extension
, const char *default_name
,
115 char *ext
= (char *)extension
;
118 wxString str
= _("Load %s file");
119 sprintf(prompt
, str
, what
);
121 if (*ext
== '.') ext
++;
123 sprintf(wild
, "*.%s", ext
);
125 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);
128 char* wxSaveFileSelector(const char *what
, const char *extension
, const char *default_name
,
131 char *ext
= (char *)extension
;
134 wxString str
= _("Save %s file");
135 sprintf(prompt
, str
, what
);
137 if (*ext
== '.') ext
++;
139 sprintf(wild
, "*.%s", ext
);
141 return wxFileSelector (prompt
, NULL
, default_name
, ext
, wild
, 0, parent
);