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