]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dirdlg.cpp
Fix drawing of bitmaps with masks in mirrored wxDC.
[wxWidgets.git] / src / gtk / dirdlg.cpp
CommitLineData
b50747ea
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/dirdlg.cpp
ff3e84ff 3// Purpose: native implementation of wxDirDialog
b50747ea
RR
4// Author: Robert Roebling, Zbigniew Zagorski, Mart Raudsepp, Francesco Montorsi
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling, 2004 Zbigniew Zagorski, 2005 Mart Raudsepp
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13
14
15/*
ff3e84ff 16 NOTE: the GtkFileChooser interface can be used both for wxFileDialog and for wxDirDialog.
b50747ea
RR
17 Thus following code is very similar (even if not identic) to src/gtk/filedlg.cpp
18 If you find a problem in this code, remember to check also that file !
19*/
20
21
22
ff654490 23#if wxUSE_DIRDLG
b50747ea
RR
24
25#include "wx/dirdlg.h"
26
27#ifndef WX_PRECOMP
28 #include "wx/intl.h"
2f79f291 29 #include "wx/filedlg.h"
b50747ea
RR
30#endif
31
b50747ea
RR
32#include "wx/gtk/private.h"
33
b50747ea 34extern "C" {
5a7c1881 35static void gtk_dirdialog_response_callback(GtkWidget * WXUNUSED(w),
b50747ea 36 gint response,
ff3e84ff 37 wxDirDialog *dialog)
b50747ea 38{
b50747ea 39 if (response == GTK_RESPONSE_ACCEPT)
5a7c1881 40 dialog->GTKOnAccept();
a552d120 41 else // GTK_RESPONSE_CANCEL or GTK_RESPONSE_NONE
5a7c1881 42 dialog->GTKOnCancel();
b50747ea
RR
43}
44}
45
b50747ea 46//-----------------------------------------------------------------------------
ff3e84ff 47// wxDirDialog
b50747ea
RR
48//-----------------------------------------------------------------------------
49
ff654490 50IMPLEMENT_DYNAMIC_CLASS(wxDirDialog, wxDialog)
b50747ea 51
ff654490
VZ
52wxDirDialog::wxDirDialog(wxWindow* parent,
53 const wxString& title,
54 const wxString& defaultPath,
55 long style,
56 const wxPoint& pos,
57 const wxSize& WXUNUSED(sz),
58 const wxString& WXUNUSED(name))
e3f54c8f
VZ
59{
60 Create(parent, title, defaultPath, style, pos);
61}
62
63bool wxDirDialog::Create(wxWindow* parent,
64 const wxString& title,
65 const wxString& defaultPath,
66 long style,
67 const wxPoint& pos,
68 const wxSize& WXUNUSED(sz),
69 const wxString& WXUNUSED(name))
b50747ea 70{
ff654490
VZ
71 m_message = title;
72
cdc48273 73 parent = GetParentForModalDialog(parent, style);
ff654490
VZ
74
75 if (!PreCreation(parent, pos, wxDefaultSize) ||
76 !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
77 wxDefaultValidator, wxT("dirdialog")))
b50747ea 78 {
ff654490 79 wxFAIL_MSG( wxT("wxDirDialog creation failed") );
e3f54c8f 80 return false;
b50747ea 81 }
b50747ea 82
ff654490
VZ
83 GtkWindow* gtk_parent = NULL;
84 if (parent)
85 gtk_parent = GTK_WINDOW( gtk_widget_get_toplevel(parent->m_widget) );
86
87 m_widget = gtk_file_chooser_dialog_new(
88 wxGTK_CONV(m_message),
89 gtk_parent,
90 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
91 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
92 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
93 NULL);
9ff9d30c 94 g_object_ref(m_widget);
ff654490
VZ
95
96 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);
97
98 // gtk_widget_hide_on_delete is used here to avoid that Gtk automatically destroys
99 // the dialog when the user press ESC on the dialog: in that case a second call to
100 // ShowModal() would result in a bunch of Gtk-CRITICAL errors...
84f623f8 101 g_signal_connect (m_widget,
ff654490
VZ
102 "delete_event",
103 G_CALLBACK (gtk_widget_hide_on_delete),
104 (gpointer)this);
105
106 // local-only property could be set to false to allow non-local files to be loaded.
107 // In that case get/set_uri(s) should be used instead of get/set_filename(s) everywhere
108 // and the GtkFileChooserDialog should probably also be created with a backend,
d13b34d3 109 // e.g. "gnome-vfs", "default", ... (gtk_file_chooser_dialog_new_with_backend).
ff654490
VZ
110 // Currently local-only is kept as the default - true:
111 // gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(m_widget), true);
112
113 g_signal_connect (m_widget, "response",
114 G_CALLBACK (gtk_dirdialog_response_callback), this);
115
116 if ( !defaultPath.empty() )
5a7c1881 117 SetPath(defaultPath);
c282e47d 118
e3f54c8f 119 return true;
b50747ea
RR
120}
121
5a7c1881 122void wxDirDialog::GTKOnAccept()
b50747ea 123{
5a7c1881
VZ
124 wxGtkString str(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget)));
125 m_selectedDirectory = wxString::FromUTF8(str);
126
127 // change to the directory where the user went if asked
128 if (HasFlag(wxDD_CHANGE_DIR))
129 {
7c211441 130 wxSetWorkingDirectory(m_selectedDirectory);
5a7c1881
VZ
131 }
132
ff654490 133 EndDialog(wxID_OK);
b50747ea
RR
134}
135
5a7c1881
VZ
136void wxDirDialog::GTKOnCancel()
137{
138 EndDialog(wxID_CANCEL);
139}
140
ff3e84ff 141void wxDirDialog::DoSetSize(int x, int y, int width, int height, int sizeFlags)
b50747ea
RR
142{
143 if (!m_wxwindow)
144 return;
ff654490
VZ
145
146 wxDirDialogBase::DoSetSize( x, y, width, height, sizeFlags );
b50747ea
RR
147}
148
ff3e84ff 149void wxDirDialog::SetPath(const wxString& dir)
b50747ea 150{
ff654490 151 if (wxDirExists(dir))
b50747ea 152 {
ff654490 153 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget),
c282e47d 154 wxGTK_CONV_FN(dir));
b50747ea 155 }
b50747ea
RR
156}
157
ff3e84ff 158wxString wxDirDialog::GetPath() const
b50747ea 159{
5a7c1881 160 return m_selectedDirectory;
b50747ea
RR
161}
162
163#endif // wxUSE_DIRDLG