]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/filedlg.cpp
minor changes to eliminate unused parameter warning + some cleanup
[wxWidgets.git] / src / gtk1 / filedlg.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
3f6638b8 2// Name: gtk/filedlg.cpp
c801d85f
KB
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
071a2d78 19#include <gtk/gtk.h>
83624f79 20
acfd422a
RR
21//-----------------------------------------------------------------------------
22// idle system
23//-----------------------------------------------------------------------------
24
25extern void wxapp_install_idle_handler();
26extern bool g_isIdle;
27
c801d85f 28//-----------------------------------------------------------------------------
291a8f20
RR
29// "delete_event"
30//-----------------------------------------------------------------------------
31
0e1399b3 32static
291a8f20 33bool gtk_filedialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
0e1399b3 34{
acfd422a
RR
35 if (g_isIdle) wxapp_install_idle_handler();
36
291a8f20
RR
37/*
38 printf( "OnDelete from " );
39 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
40 printf( win->GetClassInfo()->GetClassName() );
41 printf( ".\n" );
42*/
0e1399b3 43
291a8f20
RR
44 win->Close();
45
46 return TRUE;
47}
48
49//-----------------------------------------------------------------------------
50// "clicked" for OK-button
c801d85f
KB
51//-----------------------------------------------------------------------------
52
0e1399b3 53static
2748d251 54void gtk_filedialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFileDialog *dialog )
c801d85f 55{
acfd422a
RR
56 if (g_isIdle) wxapp_install_idle_handler();
57
2748d251 58 int style = dialog->GetStyle();
035b704a 59
a2053b27 60 GtkFileSelection *filedlg = GTK_FILE_SELECTION(dialog->m_widget);
bfc6fde4 61 char *filename = gtk_file_selection_get_filename(filedlg);
0e1399b3 62
bfc6fde4
VZ
63 if ( (style & wxSAVE) && ( style & wxOVERWRITE_PROMPT ) )
64 {
2748d251 65 if (wxFileExists( filename ))
0e1399b3
VZ
66 {
67 wxString msg;
2748d251 68 msg.Printf( _("File '%s' already exists, do you really want to "
0e1399b3
VZ
69 "overwrite it?"), filename);
70
2748d251 71 if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
0e1399b3
VZ
72 return;
73 }
83624f79 74 }
bfc6fde4
VZ
75 else if ( (style & wxOPEN) && ( style & wxFILE_MUST_EXIST) )
76 {
77 if ( !wxFileExists( filename ) )
78 {
79 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK);
80
81 return;
82 }
83 }
035b704a 84
3f6638b8
VZ
85 // change to the directory where the user went if asked
86 if ( style & wxCHANGE_DIR )
87 {
88 wxString cwd;
89 wxSplitPath(filename, &cwd, NULL, NULL);
90
91 if ( cwd != wxGetWorkingDirectory() )
92 {
93 wxSetWorkingDirectory(cwd);
94 }
95 }
96
bfc6fde4 97 dialog->SetPath( filename );
b7f4714a 98
bfc6fde4 99 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
2748d251
RR
100 event.SetEventObject( dialog );
101 dialog->GetEventHandler()->ProcessEvent( event );
ff7b1510 102}
c801d85f 103
291a8f20
RR
104//-----------------------------------------------------------------------------
105// "clicked" for Cancel-button
106//-----------------------------------------------------------------------------
107
0e1399b3 108static
b7f4714a 109void gtk_filedialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFileDialog *dialog )
c801d85f 110{
acfd422a
RR
111 if (g_isIdle) wxapp_install_idle_handler();
112
bfc6fde4 113 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
2748d251
RR
114 event.SetEventObject( dialog );
115 dialog->GetEventHandler()->ProcessEvent( event );
ff7b1510 116}
c801d85f 117
291a8f20
RR
118//-----------------------------------------------------------------------------
119// wxFileDialog
120//-----------------------------------------------------------------------------
121
f74172ab 122IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxFileDialogBase)
c801d85f 123
83624f79
RR
124wxFileDialog::wxFileDialog( wxWindow *parent, const wxString& message,
125 const wxString& defaultDir, const wxString& defaultFileName,
126 const wxString& wildCard,
127 long style, const wxPoint& pos )
f74172ab 128 :wxFileDialogBase(parent, message, defaultDir, defaultFileName, wildCard, style, pos)
c801d85f 129{
83624f79
RR
130 m_needParent = FALSE;
131
4dcaf11a 132 if (!PreCreation( parent, pos, wxDefaultSize ) ||
223d09f6 133 !CreateBase( parent, -1, pos, wxDefaultSize, style | wxDIALOG_MODAL, wxDefaultValidator, wxT("filedialog") ))
4dcaf11a 134 {
223d09f6 135 wxFAIL_MSG( wxT("wxXX creation failed") );
3f6638b8 136 return;
4dcaf11a 137 }
3f6638b8 138
ed9b9841 139 m_widget = gtk_file_selection_new( m_message.mbc_str() );
0e1399b3 140
83624f79
RR
141 int x = (gdk_screen_width () - 400) / 2;
142 int y = (gdk_screen_height () - 400) / 2;
143 gtk_widget_set_uposition( m_widget, x, y );
0e1399b3 144
83624f79 145 GtkFileSelection *sel = GTK_FILE_SELECTION(m_widget);
3502e687 146 gtk_file_selection_hide_fileop_buttons( sel ); // they don't work anyway
035b704a 147
83624f79 148 m_path.Append(m_dir);
223d09f6 149 if( ! m_path.IsEmpty() && m_path.Last()!=wxT('/') )
3218cf58 150 m_path.Append('/');
83624f79 151 m_path.Append(m_fileName);
035b704a 152
ed9b9841 153 if(m_path.Length()>1) gtk_file_selection_set_filename(sel,m_path.mbc_str());
a3622daa 154
83624f79
RR
155 gtk_signal_connect( GTK_OBJECT(sel->ok_button), "clicked",
156 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback), (gpointer*)this );
c801d85f 157
3502e687 158 // strange way to internationalize
dcf924a3 159 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->ok_button)->child ), wxConvCurrent->cWX2MB(_("OK")) );
3502e687 160
83624f79
RR
161 gtk_signal_connect( GTK_OBJECT(sel->cancel_button), "clicked",
162 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback), (gpointer*)this );
3f6638b8 163
3502e687 164 // strange way to internationalize
dcf924a3 165 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel->cancel_button)->child ), wxConvCurrent->cWX2MB(_("Cancel")) );
3f6638b8 166
0e1399b3 167 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
291a8f20 168 GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback), (gpointer)this );
ff7b1510 169}
c801d85f 170
3218cf58
VZ
171void wxFileDialog::SetPath(const wxString& path)
172{
173 // not only set the full path but also update filename and dir
174 m_path = path;
175 if ( !!path )
176 {
177 wxString ext;
178 wxSplitPath(path, &m_dir, &m_fileName, &ext);
3f6638b8
VZ
179 if (!ext.IsEmpty())
180 {
181 m_fileName += wxT(".");
53daeada 182 m_fileName += ext;
3f6638b8 183 }
3218cf58
VZ
184 }
185}
186