[gtkmm/gtkmm-3-24] Add Gtk::NativeDialog and Gtk::FileChooserNative
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm/gtkmm-3-24] Add Gtk::NativeDialog and Gtk::FileChooserNative
- Date: Wed, 7 Nov 2018 15:08:50 +0000 (UTC)
commit a5e8aaa32188b2d86cbab7ce7f0b21a017ea037f
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Wed Nov 7 16:02:50 2018 +0100
Add Gtk::NativeDialog and Gtk::FileChooserNative
Bug 783801
.gitignore | 4 ++
gtk/gtkmm.h | 1 +
gtk/src/filechoosernative.ccg | 45 ++++++++++++
gtk/src/filechoosernative.hg | 155 +++++++++++++++++++++++++++++++++++++++++
gtk/src/filelist.am | 2 +
gtk/src/gtk_extra_objects.defs | 6 ++
gtk/src/nativedialog.ccg | 29 ++++++++
gtk/src/nativedialog.hg | 89 +++++++++++++++++++++++
8 files changed, 331 insertions(+)
---
diff --git a/.gitignore b/.gitignore
index 1e360ac0..14749489 100644
--- a/.gitignore
+++ b/.gitignore
@@ -242,6 +242,8 @@ gtk/gtkmm/filechooserbutton.cc
gtk/gtkmm/filechooserbutton.h
gtk/gtkmm/filechooserdialog.cc
gtk/gtkmm/filechooserdialog.h
+gtk/gtkmm/filechoosernative.cc
+gtk/gtkmm/filechoosernative.h
gtk/gtkmm/filechooserwidget.cc
gtk/gtkmm/filechooserwidget.h
gtk/gtkmm/filefilter.cc
@@ -358,6 +360,8 @@ gtk/gtkmm/misc.cc
gtk/gtkmm/misc.h
gtk/gtkmm/modelbutton.cc
gtk/gtkmm/modelbutton.h
+gtk/gtkmm/nativedialog.cc
+gtk/gtkmm/nativedialog.h
gtk/gtkmm/notebook.cc
gtk/gtkmm/notebook.h
gtk/gtkmm/numerableicon.cc
diff --git a/gtk/gtkmm.h b/gtk/gtkmm.h
index ce58de7e..bc8dca75 100644
--- a/gtk/gtkmm.h
+++ b/gtk/gtkmm.h
@@ -154,6 +154,7 @@ extern const int gtkmm_micro_version;
#include <gtkmm/filechooser.h>
#include <gtkmm/filechooserbutton.h>
#include <gtkmm/filechooserdialog.h>
+#include <gtkmm/filechoosernative.h>
#include <gtkmm/filechooserwidget.h>
#include <gtkmm/filefilter.h>
#include <gtkmm/fixed.h>
diff --git a/gtk/src/filechoosernative.ccg b/gtk/src/filechoosernative.ccg
new file mode 100644
index 00000000..8ff8546e
--- /dev/null
+++ b/gtk/src/filechoosernative.ccg
@@ -0,0 +1,45 @@
+/* Copyright (C) 2017 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+#include <gtkmm/window.h>
+
+namespace Gtk
+{
+
+FileChooserNative::FileChooserNative(const Glib::ustring& title, Window& parent,
+ FileChooserAction action,
+ const Glib::ustring& accept_label, const Glib::ustring& cancel_label)
+:
+ _CONSTRUCT("title", title.c_str(), "transient-for", parent.gobj(),
+ "action", static_cast<GtkFileChooserAction>(action),
+ "accept_label", Glib::c_str_or_nullptr(accept_label),
+ "cancel_label", Glib::c_str_or_nullptr(cancel_label))
+{
+}
+
+FileChooserNative::FileChooserNative(const Glib::ustring& title,
+ FileChooserAction action,
+ const Glib::ustring& accept_label, const Glib::ustring& cancel_label)
+:
+ _CONSTRUCT("title", title.c_str(),
+ "action", static_cast<GtkFileChooserAction>(action),
+ "accept_label", Glib::c_str_or_nullptr(accept_label),
+ "cancel_label", Glib::c_str_or_nullptr(cancel_label))
+{
+}
+
+} // namespace Gtk
diff --git a/gtk/src/filechoosernative.hg b/gtk/src/filechoosernative.hg
new file mode 100644
index 00000000..eaf8845c
--- /dev/null
+++ b/gtk/src/filechoosernative.hg
@@ -0,0 +1,155 @@
+/* Copyright (C) 2017 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtkmm/nativedialog.h>
+#include <gtkmm/filechooser.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(gtkmm/private/nativedialog_p.h)
+
+namespace Gtk
+{
+class Window;
+
+/** A native file chooser dialog, suitable for “File/Open” or “File/Save” commands.
+ *
+ * %FileChooserNative is an abstraction of a dialog box suitable
+ * for use with “File/Open” or “File/Save as” commands. By default, this
+ * just uses a Gtk::FileChooserDialog to implement the actual dialog.
+ * However, on certain platforms, such as Windows, the native platform
+ * file chooser is used instead. When the application is running in a
+ * sandboxed environment without direct filesystem access (such as Flatpak),
+ * %FileChooserNative may call the proper APIs (portals) to let the user
+ * choose a file and make it available to the application.
+ *
+ * While the API of %FileChooserNative closely mirrors FileChooserDialog, the main
+ * difference is that there is no access to any Gtk::Window or Gtk::Widget for the dialog.
+ * This is required, as there may not be one in the case of a platform native dialog.
+ * Showing, hiding and running the dialog is handled by the NativeDialog functions.
+ *
+ * <h2>Response Codes</h2>
+ *
+ * %FileChooserNative inherits from NativeDialog, which means it
+ * will return Gtk::ResponseType::ACCEPT if the user accepted, and
+ * Gtk::ResponseType::CANCEL if he pressed cancel. It can also return
+ * Gtk::ResponseType::DELETE_EVENT if the window was unexpectedly closed.
+ *
+ * <h2>Differences from FileChooserDialog</h2>
+ *
+ * There are a few things in the FileChooser API that are not
+ * possible to use with %FileChooserNative, as such use would
+ * prohibit the use of a native dialog.
+ *
+ * There is no support for the signals that are emitted when the user
+ * navigates in the dialog, including:
+ * * FileChooser::signal_current_folder_changed()
+ * * FileChooser::signal_selection_changed()
+ * * FileChooser::signal_file_activated()
+ * * FileChooser::signal_confirm_overwrite()
+ *
+ * You can also not use the methods that directly control user navigation:
+ * * FileChooser::unselect_filename()
+ * * FileChooser::select_all()
+ * * FileChooser::unselect_all()
+ *
+ * If you need any of the above you will have to use FileChooserDialog directly.
+ *
+ * No operations that change the dialog work while the dialog is
+ * visible. Set all the properties that are required before showing the dialog.
+ *
+ * <h2>Win32 details</h2>
+ *
+ * On windows the IFileDialog implementation (added in Windows Vista) is
+ * used. It supports many of the features that FileChooserDialog
+ * does, but there are some things it does not handle:
+ *
+ * * Extra widgets added with FileChooser::set_extra_widget().
+ *
+ * * Use of custom previews by connecting to FileChooser::signal_update_preview().
+ *
+ * * Any Gtk::FileFilter added using a mimetype or custom filter.
+ *
+ * If any of these features are used the regular FileChooserDialog
+ * will be used in place of the native one.
+ *
+ * <h2>Portal details</h2>
+ *
+ * When the org.freedesktop.portal.FileChooser portal is available on the
+ * session bus, it is used to bring up an out-of-process file chooser. Depending
+ * on the kind of session the application is running in, this may or may not
+ * be a GTK+ file chooser. In this situation, the following things are not
+ * supported and will be silently ignored:
+ *
+ * * Extra widgets added with FileChooser::set_extra_widget().
+ *
+ * * Use of custom previews by connecting to FileChooser::signal_update_preview().
+ *
+ * * Any Gtk::FileFilter added with a custom filter.
+ *
+ * @see Gtk::FileChooser, Gtk::NativeDialog, Gtk::FileChooserDialog
+ * @newin{3,24}
+ */
+class FileChooserNative : public NativeDialog, public FileChooser
+{
+ _CLASS_GOBJECT(FileChooserNative, GtkFileChooserNative, GTK_FILE_CHOOSER_NATIVE, NativeDialog,
GtkNativeDialog)
+ _IMPLEMENTS_INTERFACE(FileChooser)
+ _STRUCT_NOT_HIDDEN
+
+protected:
+ /** There is no create() method that corresponds to this constructor,
+ * because this constructor shall only be used by derived classes.
+ */
+ _CTOR_DEFAULT
+
+ /** Constructs a %FileChooserNative.
+ */
+ FileChooserNative(const Glib::ustring& title, Window& parent, FileChooserAction action,
+ const Glib::ustring& accept_label, const Glib::ustring& cancel_label);
+
+ /** Constructs a %FileChooserNative.
+ */
+ FileChooserNative(const Glib::ustring& title, FileChooserAction action,
+ const Glib::ustring& accept_label, const Glib::ustring& cancel_label);
+ _IGNORE(gtk_file_chooser_native_new)
+
+public:
+ /** Creates a %FileChooserNative.
+ *
+ * @newin{3,24}
+ *
+ * @param title Title of the native.
+ * @param parent Transient parent of the native.
+ * @param action Open or save mode for the dialog.
+ * @param accept_label Text to go in the accept button, or empty string for the default.
+ * @param cancel_label Text to go in the cancel button, or empty string for the default.
+ * @return A Glib::RefPtr to a new %FileChooserNative.
+ */
+ _WRAP_CREATE(const Glib::ustring& title, Window& parent{?},
+ FileChooserAction action, const Glib::ustring& accept_label = Glib::ustring(),
+ const Glib::ustring& cancel_label = Glib::ustring())
+
+ _WRAP_METHOD(Glib::ustring get_accept_label() const, gtk_file_chooser_native_get_accept_label, newin
"3,24")
+ _WRAP_METHOD(void set_accept_label(const Glib::ustring& accept_label{NULL} = Glib::ustring()),
gtk_file_chooser_native_set_accept_label, newin "3,24")
+ _WRAP_METHOD(Glib::ustring get_cancel_label() const, gtk_file_chooser_native_get_cancel_label, newin
"3,24")
+ _WRAP_METHOD(void set_cancel_label(const Glib::ustring& cancel_label{NULL} = Glib::ustring()),
gtk_file_chooser_native_set_cancel_label, newin "3,24")
+
+ _WRAP_PROPERTY("accept-label", Glib::ustring, newin "3,24")
+ _WRAP_PROPERTY("cancel-label", Glib::ustring, newin "3,24")
+
+ // FileChooserNative has no signals
+};
+
+} // namespace Gtk
diff --git a/gtk/src/filelist.am b/gtk/src/filelist.am
index cf943314..4a153981 100644
--- a/gtk/src/filelist.am
+++ b/gtk/src/filelist.am
@@ -74,6 +74,7 @@ gtkmm_files_any_hg = \
filechooser.hg \
filechooserbutton.hg \
filechooserdialog.hg \
+ filechoosernative.hg \
filechooserwidget.hg \
filefilter.hg \
fixed.hg \
@@ -121,6 +122,7 @@ gtkmm_files_any_hg = \
messagedialog.hg \
misc.hg \
modelbutton.hg \
+ nativedialog.hg \
notebook.hg \
offscreenwindow.hg \
orientable.hg \
diff --git a/gtk/src/gtk_extra_objects.defs b/gtk/src/gtk_extra_objects.defs
index 68ebc802..ba16bce4 100644
--- a/gtk/src/gtk_extra_objects.defs
+++ b/gtk/src/gtk_extra_objects.defs
@@ -148,6 +148,12 @@
(gtype-id "GTK_TYPE_ICON_SOURCE")
)
+(define-object NativeDialog
+ (in-module "Gtk")
+ (c-name "GtkNativeDialog")
+ (gtype-id "GTK_TYPE_NATIVE_DIALOG")
+)
+
(define-object PageSetup
(in-module "Gtk")
(c-name "GtkPageSetup")
diff --git a/gtk/src/nativedialog.ccg b/gtk/src/nativedialog.ccg
new file mode 100644
index 00000000..3c34ecd7
--- /dev/null
+++ b/gtk/src/nativedialog.ccg
@@ -0,0 +1,29 @@
+/* Copyright (C) 2017 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+#include <gtkmm/window.h>
+
+namespace Gtk
+{
+
+void NativeDialog::unset_transient_for()
+{
+ gtk_native_dialog_set_transient_for(gobj(), nullptr);
+}
+
+} // namespace Gtk
+
diff --git a/gtk/src/nativedialog.hg b/gtk/src/nativedialog.hg
new file mode 100644
index 00000000..20b86a99
--- /dev/null
+++ b/gtk/src/nativedialog.hg
@@ -0,0 +1,89 @@
+/* Copyright (C) 2017 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glibmm/object.h>
+
+_DEFS(gtkmm,gtk)
+_PINCLUDE(glibmm/private/object_p.h)
+
+namespace Gtk
+{
+class Window;
+
+/** Integrate with native dialogs.
+ *
+ * Native dialogs are platform dialogs that don't use Gtk::Dialog or
+ * Gtk::Window. They are used in order to integrate better with a
+ * platform, by looking the same as other native applications and
+ * supporting platform specific features.
+ *
+ * The Gtk::Dialog functions cannot be used on such objects, but we
+ * need a similar API in order to drive them. The %NativeDialog
+ * object is an API that allows you to do this. It allows you to set
+ * various common properties on the dialog, as well as show and hide
+ * it and get a response signal when the user finished with the dialog.
+ *
+ * There is also a run() helper that makes it easy
+ * to run any native dialog in a modal way with a recursive mainloop,
+ * similar to Dialog::run().
+ *
+ * @see Gtk::FileChooserNative, Gtk::Dialog
+ * @newin{3,24}
+ */
+class NativeDialog : public Glib::Object
+{
+ _CLASS_GOBJECT(NativeDialog, GtkNativeDialog, GTK_NATIVE_DIALOG, Glib::Object, GObject)
+ _IGNORE(gtk_native_dialog_destroy)
+
+protected:
+ /** There is no create() method that corresponds to this constructor,
+ * because only derived classes shall be created.
+ */
+ _CTOR_DEFAULT
+
+public:
+ // No create() because only derived classes shall be instantiated.
+
+ _WRAP_METHOD(void show(), gtk_native_dialog_show, newin "3,24")
+ _WRAP_METHOD(void hide(), gtk_native_dialog_hide, newin "3,24")
+ _WRAP_METHOD(bool get_visible() const, gtk_native_dialog_get_visible, newin "3,24")
+ _WRAP_METHOD(void set_modal(bool modal = true), gtk_native_dialog_set_modal, newin "3,24")
+ _WRAP_METHOD(bool get_modal() const, gtk_native_dialog_get_modal, newin "3,24")
+ _WRAP_METHOD(void set_title(const Glib::ustring& title), gtk_native_dialog_set_title, newin "3,24")
+ _WRAP_METHOD(Glib::ustring get_title() const, gtk_native_dialog_get_title, newin "3,24")
+
+ _WRAP_METHOD(void set_transient_for(Window& parent), gtk_native_dialog_set_transient_for, newin "3,24")
+
+ /** Unsets the current transient window.
+ * @see set_transient_for().
+ * @newin{3,24}
+ */
+ void unset_transient_for();
+
+ _WRAP_METHOD(Window* get_transient_for(), gtk_native_dialog_get_transient_for, newin "3,24")
+ _WRAP_METHOD(const Window* get_transient_for() const, gtk_native_dialog_get_transient_for, constversion,
newin "3,24")
+
+ _WRAP_METHOD(int run(), gtk_native_dialog_run, newin "3,24")
+
+ _WRAP_PROPERTY("title", Glib::ustring, newin "3,24")
+ _WRAP_PROPERTY("modal", bool, newin "3,24")
+ _WRAP_PROPERTY("visible", bool, newin "3,24")
+ _WRAP_PROPERTY("transient_for", Window*, newin "3,24")
+
+ _WRAP_SIGNAL(void response(int response_id), "response", newin "3,24")
+};
+
+} // namespace Gtk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]