Debian Codegraph @

gtk/src/filechoosernative.hg

raw
1 /* Copyright (C) 2017 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <gtkmm/nativedialog.h>
18 #include <gtkmm/filechooser.h>
19
20 _DEFS(gtkmm,gtk)
21 _PINCLUDE(gtkmm/private/nativedialog_p.h)
22
23 namespace Gtk
24 {
25 class GTKMM_API Window;
26
27 /** A native file chooser dialog, suitable for “File/Open” or “File/Save” commands.
28 *
29 * %FileChooserNative is an abstraction of a dialog box suitable
30 * for use with “File/Open” or “File/Save as” commands. By default, this
31 * just uses a Gtk::FileChooserDialog to implement the actual dialog.
32 * However, on certain platforms, such as Windows, the native platform
33 * file chooser is used instead. When the application is running in a
34 * sandboxed environment without direct filesystem access (such as Flatpak),
35 * %FileChooserNative may call the proper APIs (portals) to let the user
36 * choose a file and make it available to the application.
37 *
38 * While the API of %FileChooserNative closely mirrors FileChooserDialog, the main
39 * difference is that there is no access to any Gtk::Window or Gtk::Widget for the dialog.
40 * This is required, as there may not be one in the case of a platform native dialog.
41 * Showing, hiding and running the dialog is handled by the NativeDialog functions.
42 *
43 * <h2>Response Codes</h2>
44 *
45 * %FileChooserNative inherits from NativeDialog, which means it
46 * will return Gtk::ResponseType::ACCEPT if the user accepted, and
47 * Gtk::ResponseType::CANCEL if he pressed cancel. It can also return
48 * Gtk::ResponseType::DELETE_EVENT if the window was unexpectedly closed.
49 *
50 * <h2>Differences from FileChooserDialog</h2>
51 *
52 * There are a few things in the FileChooser API that are not
53 * possible to use with %FileChooserNative, as such use would
54 * prohibit the use of a native dialog.
55 *
56 * There is no support for the signals that are emitted when the user
57 * navigates in the dialog, including:
58 * * FileChooser::signal_current_folder_changed()
59 * * FileChooser::signal_selection_changed()
60 * * FileChooser::signal_file_activated()
61 * * FileChooser::signal_confirm_overwrite()
62 *
63 * You can also not use the methods that directly control user navigation:
64 * * FileChooser::unselect_filename()
65 * * FileChooser::select_all()
66 * * FileChooser::unselect_all()
67 *
68 * If you need any of the above you will have to use FileChooserDialog directly.
69 *
70 * No operations that change the dialog work while the dialog is
71 * visible. Set all the properties that are required before showing the dialog.
72 *
73 * <h2>Win32 details</h2>
74 *
75 * On windows the IFileDialog implementation (added in Windows Vista) is
76 * used. It supports many of the features that FileChooserDialog
77 * does, but there are some things it does not handle:
78 *
79 * * Extra widgets added with FileChooser::set_extra_widget().
80 *
81 * * Use of custom previews by connecting to FileChooser::signal_update_preview().
82 *
83 * * Any Gtk::FileFilter added using a mimetype or custom filter.
84 *
85 * If any of these features are used the regular FileChooserDialog
86 * will be used in place of the native one.
87 *
88 * <h2>Portal details</h2>
89 *
90 * When the org.freedesktop.portal.FileChooser portal is available on the
91 * session bus, it is used to bring up an out-of-process file chooser. Depending
92 * on the kind of session the application is running in, this may or may not
93 * be a GTK+ file chooser. In this situation, the following things are not
94 * supported and will be silently ignored:
95 *
96 * * Extra widgets added with FileChooser::set_extra_widget().
97 *
98 * * Use of custom previews by connecting to FileChooser::signal_update_preview().
99 *
100 * * Any Gtk::FileFilter added with a custom filter.
101 *
102 * @see Gtk::FileChooser, Gtk::NativeDialog, Gtk::FileChooserDialog
103 * @newin{3,24}
104 */
105 class GTKMM_API FileChooserNative : public NativeDialog, public FileChooser
106 {
107 _CLASS_GOBJECT(FileChooserNative, GtkFileChooserNative, GTK_FILE_CHOOSER_NATIVE, NativeDialog, GtkNativeDialog, , , GTKMM_API)
108 _IMPLEMENTS_INTERFACE(FileChooser)
109 _DO_NOT_DERIVE_GTYPE dnl// GtkFileChooserNative is a final type
110 _ABI_AS_WITH_DERIVED_GTYPE dnl// Remove when we can break ABI
111 _STRUCT_NOT_HIDDEN
112
113 protected:
114 /** There is no create() method that corresponds to this constructor,
115 * because this constructor shall only be used by derived classes.
116 */
117 _CTOR_DEFAULT
118
119 /** Constructs a %FileChooserNative.
120 */
121 FileChooserNative(const Glib::ustring& title, Window& parent, FileChooserAction action,
122 const Glib::ustring& accept_label, const Glib::ustring& cancel_label);
123
124 /** Constructs a %FileChooserNative.
125 */
126 FileChooserNative(const Glib::ustring& title, FileChooserAction action,
127 const Glib::ustring& accept_label, const Glib::ustring& cancel_label);
128 _IGNORE(gtk_file_chooser_native_new)
129
130 public:
131 /** Creates a %FileChooserNative.
132 *
133 * @newin{3,24}
134 *
135 * @param title Title of the native.
136 * @param parent Transient parent of the native.
137 * @param action Open or save mode for the dialog.
138 * @param accept_label Text to go in the accept button, or empty string for the default.
139 * @param cancel_label Text to go in the cancel button, or empty string for the default.
140 * @return A Glib::RefPtr to a new %FileChooserNative.
141 */
142 _WRAP_CREATE(const Glib::ustring& title, Window& parent{?},
143 FileChooserAction action, const Glib::ustring& accept_label = Glib::ustring(),
144 const Glib::ustring& cancel_label = Glib::ustring())
145
146 _WRAP_METHOD(Glib::ustring get_accept_label() const, gtk_file_chooser_native_get_accept_label, newin "3,24")
147 _WRAP_METHOD(void set_accept_label(const Glib::ustring& accept_label{NULL} = Glib::ustring()), gtk_file_chooser_native_set_accept_label, newin "3,24")
148 _WRAP_METHOD(Glib::ustring get_cancel_label() const, gtk_file_chooser_native_get_cancel_label, newin "3,24")
149 _WRAP_METHOD(void set_cancel_label(const Glib::ustring& cancel_label{NULL} = Glib::ustring()), gtk_file_chooser_native_set_cancel_label, newin "3,24")
150
151 _WRAP_PROPERTY("accept-label", Glib::ustring, newin "3,24")
152 _WRAP_PROPERTY("cancel-label", Glib::ustring, newin "3,24")
153
154 // FileChooserNative has no signals
155 };
156
157 } // namespace Gtk