]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/filedlg.cpp
Added bitmaps and icons to samples
[wxWidgets.git] / src / gtk / 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
8// Licence: wxWindows licence
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
UM
33 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog->m_widget) ))) {
34 if(wxMessageBox("File exists. Overwrite?","Confirm",wxYES_NO)!=wxYES)
35 return;
36 }
37
c801d85f
KB
38 dialog->OnOk( event );
39};
40
41void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(widget), gpointer data )
42{
43 wxFileDialog *dialog = (wxFileDialog*)data;
7798a18e 44 wxCommandEvent event(wxEVT_NULL);
c801d85f
KB
45 dialog->OnCancel( event );
46};
47
48IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
49
50wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
51 const wxString& defaultDir, const wxString& defaultFileName,
52 const wxString& wildCard,
53 long style, const wxPoint& pos )
54{
55 m_needParent = FALSE;
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
KB
64 m_filterIndex = 1;
65
66 m_widget = gtk_file_selection_new( "File selection" );
67
68 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
035b704a
UM
69
70 m_path.Append(m_dir);
8ffec97a 71 if(! m_path.IsEmpty() && m_path.Last()!='/') m_path.Append('/');
035b704a
UM
72 m_path.Append(m_fileName);
73
74 if(m_path.Length()>1) gtk_file_selection_set_filename(sel,m_path);
c801d85f
KB
75
76 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
77 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
78
79 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
80 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
81};
82
83int wxFileDialog::ShowModal(void)
84{
85 int ret = wxDialog::ShowModal();
035b704a 86
c801d85f
KB
87 if (ret == wxID_OK)
88 {
89 m_fileName = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
90 m_path = gtk_file_selection_get_filename( GTK_FILE_SELECTION(m_widget) );
91 };
92 return ret;
93};
94
95
96char *wxFileSelector(const char *title,
97 const char *defaultDir, const char *defaultFileName,
98 const char *defaultExtension, const char *filter, int flags,
99 wxWindow *parent, int x, int y)
100{
101 wxString filter2("");
102 if ( defaultExtension && !filter )
103 filter2 = wxString("*.") + wxString(defaultExtension) ;
104 else if ( filter )
105 filter2 = filter;
106
107 wxString defaultDirString;
108 if (defaultDir)
109 defaultDirString = defaultDir;
110 else
111 defaultDirString = "";
112
113 wxString defaultFilenameString;
114 if (defaultFileName)
115 defaultFilenameString = defaultFileName;
116 else
117 defaultFilenameString = "";
118
119 wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString,
120 filter2, flags, wxPoint(x, y));
121
122 if ( fileDialog.ShowModal() == wxID_OK )
123 {
124 strcpy(wxBuffer, (const char *)fileDialog.GetPath());
125 return wxBuffer;
126 }
127 else
128 return NULL;
129};
130
131char* wxLoadFileSelector(const char *what, const char *extension, const char *default_name,
132 wxWindow *parent )
133{
134 char *ext = (char *)extension;
135
136 char prompt[50];
137 wxString str = _("Load %s file");
138 sprintf(prompt, str, what);
139
140 if (*ext == '.') ext++;
141 char wild[60];
142 sprintf(wild, "*.%s", ext);
143
144 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
145};
146
147char* wxSaveFileSelector(const char *what, const char *extension, const char *default_name,
148 wxWindow *parent )
149{
150 char *ext = (char *)extension;
151
152 char prompt[50];
153 wxString str = _("Save %s file");
154 sprintf(prompt, str, what);
155
156 if (*ext == '.') ext++;
157 char wild[60];
158 sprintf(wild, "*.%s", ext);
159
160 return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent);
161};
162
163
164
165