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