1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/filedlg.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "filedlg.h"
14 #include "wx/filedlg.h"
17 #include "wx/generic/msgdlgg.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 extern void wxapp_install_idle_handler();
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
33 bool gtk_filedialog_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxDialog
*win
)
35 if (g_isIdle
) wxapp_install_idle_handler();
38 printf( "OnDelete from " );
39 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
40 printf( win->GetClassInfo()->GetClassName() );
49 //-----------------------------------------------------------------------------
50 // "clicked" for OK-button
51 //-----------------------------------------------------------------------------
54 void gtk_filedialog_ok_callback( GtkWidget
*WXUNUSED(widget
), wxFileDialog
*dialog
)
56 if (g_isIdle
) wxapp_install_idle_handler();
58 int style
= dialog
->GetStyle();
60 GtkFileSelection
*filedlg
= GTK_FILE_SELECTION(dialog
->m_widget
);
61 char *filename
= gtk_file_selection_get_filename(filedlg
);
63 if ( (style
& wxSAVE
) && ( style
& wxOVERWRITE_PROMPT
) )
65 if (wxFileExists( filename
))
68 msg
.Printf( _("File '%s' already exists, do you really want to "
69 "overwrite it?"), filename
);
71 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
75 else if ( (style
& wxOPEN
) && ( style
& wxFILE_MUST_EXIST
) )
77 if ( !wxFileExists( filename
) )
79 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK
);
85 // change to the directory where the user went if asked
86 if ( style
& wxCHANGE_DIR
)
89 wxSplitPath(filename
, &cwd
, NULL
, NULL
);
91 if ( cwd
!= wxGetWorkingDirectory() )
93 wxSetWorkingDirectory(cwd
);
97 dialog
->SetPath( filename
);
99 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
100 event
.SetEventObject( dialog
);
101 dialog
->GetEventHandler()->ProcessEvent( event
);
104 //-----------------------------------------------------------------------------
105 // "clicked" for Cancel-button
106 //-----------------------------------------------------------------------------
109 void gtk_filedialog_cancel_callback( GtkWidget
*WXUNUSED(w
), wxFileDialog
*dialog
)
111 if (g_isIdle
) wxapp_install_idle_handler();
113 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
);
114 event
.SetEventObject( dialog
);
115 dialog
->GetEventHandler()->ProcessEvent( event
);
118 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
122 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxFileDialogBase
)
124 wxFileDialog::wxFileDialog( wxWindow
*parent
, const wxString
& message
,
125 const wxString
& defaultDir
, const wxString
& defaultFileName
,
126 const wxString
& wildCard
,
127 long style
, const wxPoint
& pos
)
128 :wxFileDialogBase(parent
, message
, defaultDir
, defaultFileName
, wildCard
, style
, pos
)
130 m_needParent
= FALSE
;
132 if (!PreCreation( parent
, pos
, wxDefaultSize
) ||
133 !CreateBase( parent
, -1, pos
, wxDefaultSize
, style
| wxDIALOG_MODAL
, wxDefaultValidator
, wxT("filedialog") ))
135 wxFAIL_MSG( wxT("wxXX creation failed") );
139 m_widget
= gtk_file_selection_new( m_message
.mbc_str() );
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
);
145 GtkFileSelection
*sel
= GTK_FILE_SELECTION(m_widget
);
146 gtk_file_selection_hide_fileop_buttons( sel
); // they don't work anyway
148 m_path
.Append(m_dir
);
149 if( ! m_path
.IsEmpty() && m_path
.Last()!=wxT('/') )
151 m_path
.Append(m_fileName
);
153 if(m_path
.Length()>1) gtk_file_selection_set_filename(sel
,m_path
.mbc_str());
155 gtk_signal_connect( GTK_OBJECT(sel
->ok_button
), "clicked",
156 GTK_SIGNAL_FUNC(gtk_filedialog_ok_callback
), (gpointer
*)this );
158 // strange way to internationalize
159 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->ok_button
)->child
), wxConvCurrent
->cWX2MB(_("OK")) );
161 gtk_signal_connect( GTK_OBJECT(sel
->cancel_button
), "clicked",
162 GTK_SIGNAL_FUNC(gtk_filedialog_cancel_callback
), (gpointer
*)this );
164 // strange way to internationalize
165 gtk_label_set( GTK_LABEL( GTK_BUTTON(sel
->cancel_button
)->child
), wxConvCurrent
->cWX2MB(_("Cancel")) );
167 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
168 GTK_SIGNAL_FUNC(gtk_filedialog_delete_callback
), (gpointer
)this );
171 void wxFileDialog::SetPath(const wxString
& path
)
173 // not only set the full path but also update filename and dir
178 wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
);
181 m_fileName
+= wxT(".");