1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/filedlg.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "filedlg.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
17 #include "wx/filedlg.h"
20 #include "wx/generic/msgdlgg.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 extern void wxapp_install_idle_handler();
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
36 bool gtk_filedialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
38 if (g_isIdle
) wxapp_install_idle_handler();
41 printf( "OnDelete from " );
42 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
43 printf( win->GetClassInfo()->GetClassName() );
52 //-----------------------------------------------------------------------------
53 // "clicked" for OK-button
54 //-----------------------------------------------------------------------------
57 void gtk_filedialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFileDialog
*dialog
)
59 if (g_isIdle
) wxapp_install_idle_handler();
61 int style
= dialog
->GetStyle();
63 GtkFileSelection
*filedlg
= GTK_FILE_SELECTION(dialog
->m_widget
);
64 char *filename
= gtk_file_selection_get_filename(filedlg
);
66 if ( (style
& wxSAVE
) && ( style
& wxOVERWRITE_PROMPT
) )
68 if (wxFileExists( filename
))
71 msg
.Printf( _("File '%s' already exists, do you really want to "
72 "overwrite it?"), filename
);
74 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
78 else if ( (style
& wxOPEN
) && ( style
& wxFILE_MUST_EXIST
) )
80 if ( !wxFileExists( filename
) )
82 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK
);
88 // change to the directory where the user went if asked
89 if ( style
& wxCHANGE_DIR
)
92 wxSplitPath(filename
, &cwd
, NULL
, NULL
);
94 if ( cwd
!= wxGetCwd() )
96 wxSetWorkingDirectory(cwd
);
100 dialog
->SetPath( filename
);
102 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
103 event
.SetEventObject( dialog
);
104 dialog
->GetEventHandler()->ProcessEvent( event
);
107 //-----------------------------------------------------------------------------
108 // "clicked" for Cancel-button
109 //-----------------------------------------------------------------------------
112 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFileDialog
*dialog
)
114 if (g_isIdle
) wxapp_install_idle_handler();
116 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
117 event
.SetEventObject( dialog
);
118 dialog
->GetEventHandler()->ProcessEvent( event
);
121 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
125 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxFileDialogBase
)
127 wxFileDialog::wxFileDialog( wxWindow
*parent
, const wxString
& message
,
128 const wxString
& defaultDir
, const wxString
& defaultFileName
,
129 const wxString
& wildCard
,
130 long style
, const wxPoint
& pos
)
131 :wxFileDialogBase(parent
, message
, defaultDir
, defaultFileName
, wildCard
, style
, pos
)
133 m_needParent
= FALSE
;
135 if (!PreCreation( parent
, pos
, wxDefaultSize
) ||
136 !CreateBase( parent
, wxID_ANY
, pos
, wxDefaultSize
, style
, wxDefaultValidator
, wxT("filedialog") ))
138 wxFAIL_MSG( wxT("wxXX creation failed") );
142 m_widget
= gtk_file_selection_new( m_message
.mbc_str() );
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
);
148 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
149 gtk_file_selection_hide_fileop_buttons( sel
); // they don't work anyway
151 m_path
.Append(m_dir
);
152 if( ! m_path
.IsEmpty() && m_path
.Last()!=wxT('/') )
154 m_path
.Append(m_fileName
);
156 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
.mbc_str());
158 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
159 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
161 // strange way to internationalize
162 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->ok_button
)->child
), wxConvCurrent
->cWX2MB(_("OK")) );
164 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
165 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
167 // strange way to internationalize
168 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->cancel_button
)->child
), wxConvCurrent
->cWX2MB(_("Cancel")) );
170 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
171 GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback
), (gpointer
)this );
174 void wxFileDialog::SetPath(const wxString
& path
)
176 // not only set the full path but also update filename and dir
181 wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
);
184 m_fileName
+= wxT(".");