]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/filedlg.cpp
Font fixes and icons in report view for list control
[wxWidgets.git] / src / gtk1 / filedlg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: filedlg.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
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"
17#include "wx/generic/msgdlgg.h"
18
19//-----------------------------------------------------------------------------
20// wxFileDialog
21//-----------------------------------------------------------------------------
22
23void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), gpointer data )
24{
25 wxFileDialog *dialog = (wxFileDialog*)data;
26 wxCommandEvent event(wxEVT_NULL);
27 int style;
28
29 style=dialog->GetStyle();
30
31 if((style&wxSAVE)&&(style&wxOVERWRITE_PROMPT))
32 if(wxFileExists(gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog->m_widget) ))) {
33 if(wxMessageBox(_("File exists. Overwrite?"),
34 _("Confirm"), wxYES_NO) != wxYES)
35 return;
36 }
37
38 dialog->OnOK( event );
39}
40
41void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(widget), gpointer data )
42{
43 wxFileDialog *dialog = (wxFileDialog*)data;
44 wxCommandEvent event(wxEVT_NULL);
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
57 PreCreation( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, "filedialog" );
58 m_message = message;
59 m_path = "";
60 m_fileName = defaultFileName;
61 m_dir = defaultDir;
62 m_wildCard = wildCard;
63 m_dialogStyle = style;
64 m_filterIndex = 1;
65
66 m_widget = gtk_file_selection_new( m_message );
67
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
72 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
73
74 m_path.Append(m_dir);
75 if(! m_path.IsEmpty() && m_path.Last()!='/') m_path.Append('/');
76 m_path.Append(m_fileName);
77
78 if(m_path.Length()>1) gtk_file_selection_set_filename(sel,m_path);
79
80 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
81 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
82
83 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
84 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
85}
86
87int wxFileDialog::ShowModal(void)
88{
89 int ret = wxDialog::ShowModal();
90
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) );
95 }
96 return ret;
97}
98
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{
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
132 return (char *) NULL;
133}
134
135char* wxLoadFileSelector(const char *what, const char *extension, const char *default_name,
136 wxWindow *parent )
137{
138 char *ext = (char *)extension;
139
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
148 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
149}
150
151char* wxSaveFileSelector(const char *what, const char *extension, const char *default_name,
152 wxWindow *parent )
153{
154 char *ext = (char *)extension;
155
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
164 return wxFileSelector (prompt, (const char *) NULL, default_name, ext, wild, 0, parent);
165}
166