]>
Commit | Line | Data |
---|---|---|
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 | ||
25 | void 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 | |
46 | void 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 | |
53 | IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog) | |
54 | ||
83624f79 RR |
55 | wxFileDialog::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 | |
92 | int 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 | |
83624f79 RR |
105 | char *wxFileSelector( const char *title, |
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 | { | |
132 | strcpy(wxBuffer, (const char *)fileDialog.GetPath()); | |
133 | return wxBuffer; | |
134 | } | |
135 | else | |
136 | { | |
137 | return (char *) NULL; | |
138 | } | |
ff7b1510 | 139 | } |
c801d85f | 140 | |
83624f79 | 141 | char* wxLoadFileSelector( const char *what, const char *extension, const char *default_name, wxWindow *parent ) |
c801d85f | 142 | { |
83624f79 | 143 | char *ext = (char *)extension; |
a3622daa | 144 | |
83624f79 RR |
145 | char prompt[50]; |
146 | wxString str = _("Load %s file"); | |
147 | sprintf(prompt, str, what); | |
c801d85f | 148 | |
83624f79 RR |
149 | if (*ext == '.') ext++; |
150 | char wild[60]; | |
151 | sprintf(wild, "*.%s", ext); | |
c801d85f | 152 | |
83624f79 | 153 | return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent); |
ff7b1510 | 154 | } |
c801d85f | 155 | |
a3622daa | 156 | char* wxSaveFileSelector(const char *what, const char *extension, const char *default_name, |
c801d85f KB |
157 | wxWindow *parent ) |
158 | { | |
83624f79 | 159 | char *ext = (char *)extension; |
a3622daa | 160 | |
83624f79 RR |
161 | char prompt[50]; |
162 | wxString str = _("Save %s file"); | |
163 | sprintf(prompt, str, what); | |
c801d85f | 164 | |
83624f79 RR |
165 | if (*ext == '.') ext++; |
166 | char wild[60]; | |
167 | sprintf(wild, "*.%s", ext); | |
c801d85f | 168 | |
83624f79 | 169 | return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent); |
ff7b1510 | 170 | } |
c801d85f | 171 |