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