]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/filedlg.cpp
Committing wxUSE_DEBUG_NEW_ALWAYS
[wxWidgets.git] / src / gtk1 / filedlg.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: filedlg.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
a3622daa 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "filedlg.h"
12#endif
13
14#include "wx/filedlg.h"
15#include "wx/utils.h"
16#include "wx/intl.h"
035b704a 17#include "wx/generic/msgdlgg.h"
c801d85f 18
83624f79
RR
19#include "gtk/gtk.h"
20
c801d85f
KB
21//-----------------------------------------------------------------------------
22// wxFileDialog
23//-----------------------------------------------------------------------------
24
25void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), gpointer data )
26{
83624f79
RR
27 wxFileDialog *dialog = (wxFileDialog*)data;
28 wxCommandEvent event(wxEVT_NULL);
29 int style;
035b704a 30
83624f79 31 style = dialog->GetStyle();
99cc0288 32
83624f79
RR
33 if((style&wxSAVE)&&(style&wxOVERWRITE_PROMPT))
34 {
35 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog->m_widget) )))
36 {
1a5a8367
DP
37 if(wxMessageBox(_("File exists. Overwrite?"),
38 _("Confirm"), wxYES_NO) != wxYES)
035b704a
UM
39 return;
40 }
83624f79 41 }
035b704a 42
83624f79 43 dialog->OnOK( event );
ff7b1510 44}
c801d85f
KB
45
46void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(widget), gpointer data )
47{
83624f79
RR
48 wxFileDialog *dialog = (wxFileDialog*)data;
49 wxCommandEvent event(wxEVT_NULL);
50 dialog->OnCancel( event );
ff7b1510 51}
c801d85f
KB
52
53IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
54
83624f79
RR
55wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
56 const wxString& defaultDir, const wxString& defaultFileName,
57 const wxString& wildCard,
58 long style, const wxPoint& pos )
c801d85f 59{
83624f79
RR
60 m_needParent = FALSE;
61
62 PreCreation( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, "filedialog" );
63 m_message = message;
64 m_path = "";
65 m_fileName = defaultFileName;
66 m_dir = defaultDir;
67 m_wildCard = wildCard;
68 m_dialogStyle = style;
69 m_filterIndex = 1;
70
71 m_widget = gtk_file_selection_new( m_message );
c801d85f 72
83624f79
RR
73 int x = (gdk_screen_width () - 400) / 2;
74 int y = (gdk_screen_height () - 400) / 2;
75 gtk_widget_set_uposition( m_widget, x, y );
66bd6b93 76
83624f79 77 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
035b704a 78
83624f79
RR
79 m_path.Append(m_dir);
80 if(! m_path.IsEmpty() && m_path.Last()!='/') m_path.Append('/');
81 m_path.Append(m_fileName);
035b704a 82
83624f79 83 if(m_path.Length()>1) gtk_file_selection_set_filename(sel,m_path);
a3622daa 84
83624f79
RR
85 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
86 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
c801d85f 87
83624f79
RR
88 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
89 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
ff7b1510 90}
c801d85f
KB
91
92int wxFileDialog::ShowModal(void)
93{
83624f79
RR
94 int ret = wxDialog::ShowModal();
95
96 if (ret == wxID_OK)
97 {
98 m_fileName = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
99 m_path = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
100 }
101 return ret;
ff7b1510 102}
a3622daa 103
c801d85f 104
7482b220 105wxString wxFileSelector( const char *title,
83624f79
RR
106 const char *defaultDir, const char *defaultFileName,
107 const char *defaultExtension, const char *filter, int flags,
108 wxWindow *parent, int x, int y )
c801d85f 109{
83624f79
RR
110 wxString filter2("");
111 if ( defaultExtension && !filter )
112 filter2 = wxString("*.") + wxString(defaultExtension) ;
113 else if ( filter )
114 filter2 = filter;
115
116 wxString defaultDirString;
117 if (defaultDir)
118 defaultDirString = defaultDir;
119 else
120 defaultDirString = "";
121
122 wxString defaultFilenameString;
123 if (defaultFileName)
124 defaultFilenameString = defaultFileName;
125 else
126 defaultFilenameString = "";
127
128 wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) );
129
130 if ( fileDialog.ShowModal() == wxID_OK )
131 {
7482b220 132 return fileDialog.GetPath();
83624f79
RR
133 }
134 else
135 {
7482b220 136 return wxEmptyString;
83624f79 137 }
ff7b1510 138}
c801d85f 139
7482b220 140wxString wxLoadFileSelector( const char *what, const char *extension, const char *default_name, wxWindow *parent )
c801d85f 141{
83624f79 142 char *ext = (char *)extension;
a3622daa 143
83624f79
RR
144 char prompt[50];
145 wxString str = _("Load %s file");
146 sprintf(prompt, str, what);
c801d85f 147
83624f79
RR
148 if (*ext == '.') ext++;
149 char wild[60];
150 sprintf(wild, "*.%s", ext);
c801d85f 151
83624f79 152 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
ff7b1510 153}
c801d85f 154
7482b220 155wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name,
c801d85f
KB
156 wxWindow *parent )
157{
83624f79 158 char *ext = (char *)extension;
a3622daa 159
83624f79
RR
160 char prompt[50];
161 wxString str = _("Save %s file");
162 sprintf(prompt, str, what);
c801d85f 163
83624f79
RR
164 if (*ext == '.') ext++;
165 char wild[60];
166 sprintf(wild, "*.%s", ext);
c801d85f 167
83624f79 168 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
ff7b1510 169}
c801d85f 170