Compare commits

...

53 Commits

Author SHA1 Message Date
Matthias Clasen
2cf360cd65 window: Port to GtkMessageWindow 2022-10-30 16:45:03 -04:00
Matthias Clasen
68fa64d61e alertdialog: Port to GtkMessageWindow 2022-10-30 16:45:03 -04:00
Matthias Clasen
54ca75b529 Add GtkMessageWindow
This is a private reimplementation of GtkMessageDialog.
2022-10-30 16:45:03 -04:00
Matthias Clasen
d930998f2a gtk-demo: Partial port of dialog demo
Use GtkAlertDialog for the first dialog.
2022-10-30 16:45:03 -04:00
Matthias Clasen
ae3f7d3032 gtk-demo: Some updates to the picker demos 2022-10-30 14:34:07 -04:00
Matthias Clasen
5cb84afaa9 Add a test for POTFILES.in
Add a test that runs make-pot. This will only pass
if you've updated po/POTFILES.in and .skip after
moving source files around.

Unfortunately, it won't catch new source files that
are missing.
2022-10-30 08:52:02 -04:00
Matthias Clasen
a36bf22134 alertdialog: Small refactoring
Move the deprecated code out into its own function.
2022-10-30 08:52:02 -04:00
Piotr Drąg
8ef8514036 Update POTFILES.in 2022-10-30 12:34:21 +01:00
Matthias Clasen
c1b1e96a9a Merge branch 'deprecate-gtkdialog2' into 'main'
Deprecate GtkDialog

See merge request GNOME/gtk!5182
2022-10-29 20:39:18 +00:00
Matthias Clasen
9948053cd7 Deprecate GtkDialog
GtkDialog is too flexible in terms of UI (headerbars vs action bar,
etc), and has archaic APIs. It is time to retire it.
2022-10-29 15:27:53 -04:00
Matthias Clasen
f1af8046d0 Merge branch 'matthiasc/for-main' into 'main'
Docs updates

See merge request GNOME/gtk!5180
2022-10-29 19:22:50 +00:00
Matthias Clasen
8324a93c73 Update docs
Mention new deprecations in the future migration guide.
2022-10-29 14:14:59 -04:00
Matthias Clasen
251dcc2f86 Merge branch 'async-dialog-api2' into 'main'
Add new async APIs to replace chooser dialogs

See merge request GNOME/gtk!5174
2022-10-29 17:52:13 +00:00
Matthias Clasen
2ca168d680 NEWS: Updates 2022-10-29 13:31:41 -04:00
Matthias Clasen
f54ab91ff3 Deprecate GtkFileChooser and implementations
These are being replaced by GtkFileDialog.

This commit only moves the headers for GtkFileChooserWidget and
GtkFileChooserDialog to deprecated/, and keeps the implementations
in gtk/, since they will eventually be salvaged into a private
GtkFileChooserWindow.
2022-10-29 13:31:41 -04:00
Matthias Clasen
66b062a976 Deprecate GtkMessageDialog
It is getting replaced by GtkAlertDialog

This commit only moves the header to deprecated/,
and keeps the implementation in gtk/, since it will
eventually be salvaged into a private, dialog-free
widget.
2022-10-29 13:31:41 -04:00
Matthias Clasen
15572b0183 Deprecate GtkFontChooser and implementations
These are being replaced by GtkFontDialog
and GtkFontDialogButton

This commit only moves the headers for GtkFontChooserWidget and
GtkFontChooserDialog to deprecated/, and keeps the implementations
in gtk/, since they will eventually be salvaged into a private
GtkFontChooserWindow.
2022-10-29 13:31:41 -04:00
Matthias Clasen
a51a6a3ee2 Deprecate GtkColorChooser and implementations
These are being replaced by GtkColorDialog
and GtkColorDialogButton.

This commit only moves the headers for GtkColorChooserWidget
and GtkColorChooserDialog to deprecated/, and keeps the
implementations in gtk/, since they will eventually be
salvaged into a private GtkColorChooserWindow.
2022-10-29 13:31:41 -04:00
Matthias Clasen
8bee62dd36 examples: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
4248380538 print-editor: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
e7de4c1f99 node-editor: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
d620197ae1 constraint-editor: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
ad2552ee43 widget-factory: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
756888a53d gtk-demo: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
99e1643cdd gtk-demo: Rewrite the pickers demo
This needs some more work. For now, just have
very simple test cases for some of the new async
APIs.
2022-10-29 13:31:41 -04:00
Matthias Clasen
9839aca0bd inspector: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
9ab732ce2d gtk: Port to async dialog API 2022-10-29 13:31:41 -04:00
Matthias Clasen
6ed2d2b232 Add GtkFileDialog
Add an async API for picking a file, together with
a builder object for it. This is meant to replace direct
use of GtkFileChooserDialog.
2022-10-29 13:31:41 -04:00
Matthias Clasen
cccc74786f Add GtkAlertDialog
This is replacing GtkMessageDialog with an
async API for showing informational messages.
2022-10-29 13:31:41 -04:00
Matthias Clasen
aeacc8f3c5 Add GtkFontDialogButton
This is like GtkColorDialogButton, but for fonts.
2022-10-29 13:31:41 -04:00
Matthias Clasen
7d0ebe02db Add GtkFontDialog
This is similar to GtkColorDialog, but for fonts.
2022-10-29 13:31:41 -04:00
Matthias Clasen
655675e6a1 Add GtkColorDialogButton
This is a new color button implementation
built around GtkColorDialog.
2022-10-29 13:02:15 -04:00
Matthias Clasen
f877f33c19 Add GtkColorDialog
Add an async API for picking a color, together with
a builder object for it. This is meant to replace direct
use of GtkColorChooserDialog.
2022-10-29 10:18:37 -04:00
Matthias Clasen
2fce117d15 Add GtkDialogError
This error domain will be used by async apis
in future commits.
2022-10-29 10:18:37 -04:00
Matthias Clasen
bd5dedce12 fontchooser: Add a way to set a GtkFilter
We keep this private, since the chooser apis
are going away. This will be used in GtkFontDialog.
2022-10-29 10:18:37 -04:00
Matthias Clasen
bdc91c2339 messagedialog: Cosmetics 2022-10-28 22:23:04 -04:00
Matthias Clasen
8be7515610 Merge branch 'matthiasc/for-main' into 'main'
ci: Try to fix the macos build

See merge request GNOME/gtk!5179
2022-10-29 02:08:19 +00:00
Matthias Clasen
2cef677aef ci: Require macos to build again 2022-10-28 21:39:13 -04:00
Matthias Clasen
a2e2673809 ci: Try to fix the macos build
It seems that libjpeg-turbo first finds nasm,
and then doesn't find it. Turn off simd to keep
it from looking for it in the first place.
2022-10-28 21:07:58 -04:00
Matthias Clasen
2c844e961f Merge branch 'matthiasc/for-main' into 'main'
printeroptionwidget: Drop unused include

See merge request GNOME/gtk!5178
2022-10-28 23:41:03 +00:00
Matthias Clasen
5c9d68a550 printeroptionwidget: Drop unused include 2022-10-28 18:24:48 -04:00
Matthias Clasen
0248a7e43f Merge branch 'matthiasc/for-main' into 'main'
gtk4-demo: Avoid a critical from a11y code

See merge request GNOME/gtk!5177
2022-10-28 16:20:18 +00:00
Matthias Clasen
b972decf82 gtk4-demo: Avoid a critical from a11y code
Even though we want to be accessible,
we must not divide by zero.
2022-10-28 12:02:23 -04:00
Emmanuele Bassi
66ec091461 Merge branch 'bilelmoussaoui/file-chooser-gi' into 'main'
g-i: Add missing since annotation

See merge request GNOME/gtk!5175
2022-10-27 17:06:22 +00:00
Bilal Elmoussaoui
6ca33c639e g-i: Add missing since annotation 2022-10-27 15:38:14 +00:00
Matthias Clasen
a13a681910 Merge branch 'revert-9c919ffa462dd4511da0bfd19d36d2e15c51651b-main' into 'main'
Revert "treepopover: Do not propagate natural width of content"

See merge request GNOME/gtk!5171
2022-10-26 18:22:43 +00:00
Mat
f6eb84189f Revert "treepopover: Do not propagate natural width of content"
This reverts commit 9c919ffa46.
2022-10-26 13:58:10 +03:00
Matthias Clasen
114e2b607b Merge branch 'ebassi/glade-docs' into 'main'
docs: Remove mentions of Glade

See merge request GNOME/gtk!5168
2022-10-25 00:39:57 +00:00
Emmanuele Bassi
21bc2c5078 docs: Remove mentions of Glade
Glade does not support GTK4, so we should not link to it when discussing
developing GTK4 applications.
2022-10-24 20:11:50 +01:00
Мирослав Николић
a95cfb1c45 Update Serbian translation
(cherry picked from commit b760f57ae1)
2022-10-23 09:21:37 +00:00
Matthias Clasen
799fb41937 Merge branch 'deprecation-cleanups' into 'main'
gtk-demo: Replace combo boxes in font features

See merge request GNOME/gtk!5164
2022-10-22 19:23:45 +00:00
Matthias Clasen
e6f4c596fa gtk-demo: Use global style in font_features 2022-10-22 11:38:46 -04:00
Matthias Clasen
3d7fb26588 gtk-demo: Replace combo boxes in font features
This is a slightly more complicated combo box,
so we need an auxiliary object.
2022-10-22 11:35:35 -04:00
133 changed files with 7775 additions and 1686 deletions

View File

@@ -192,7 +192,6 @@ macos:
only:
- branches@GNOME/gtk
stage: build
allow_failure: true
tags:
- macos
needs: []
@@ -210,6 +209,7 @@ macos:
-Dintrospection=disabled
-Dcpp_std=c++11
-Dpixman:tests=disabled
-Dlibjpeg-turbo:simd=disabled
_build
- ninja -C _build
artifacts:

24
NEWS
View File

@@ -1,9 +1,11 @@
Overview of Changes in 4.9.1, dd-mm-yyyy
========================================
Note that deprecations are an early outlook
at changes that will appear in an eventual
GTK 5 release, which is still far away.
Note that deprecations are an early outlook at changes
that will appear in an eventual GTK 5 release, which is
still far away. We are introducing deprecations in 4.10
as a way to give users time to adapt, and to provide
feedback on our plans.
* GtkTreeView, GtkIconView, GtkComboBox and
auxiliary classes have been deprecated
@@ -15,7 +17,21 @@ GTK 5 release, which is still far away.
* gtk_render_ and gtk_snapshot_render_ APIs
have been deprecated
* GtkAppChooser widgets hae been deprecated
* GtkAppChooser widgets have been deprecated
* GtkMessageDialog has been deprecated and
replaced by a new async dialog API
* GtkDialog has been deprecated
* GtkColorChooser, GtkFontChooser, GtkFileChooser
interfaces and their implementations have been
deprecated. A new family of async dialog APIs
has been introduced to replace them
* GtkColorDialog, GtkFontDialog, GtkFileDialog
and GtkAlertDialog are new dialog classes with
a consistent and well-bindable API
* GtkMountOperation:
- Fix the dialog to look reasonable

View File

@@ -202,43 +202,36 @@ constraint_editor_window_load (ConstraintEditorWindow *self,
}
static void
open_response_cb (GtkNativeDialog *dialog,
int response,
ConstraintEditorWindow *self)
open_response_cb (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_native_dialog_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
ConstraintEditorWindow *self = user_data;
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
GFile *file;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
constraint_editor_window_load (self, file);
g_object_unref (file);
}
gtk_native_dialog_destroy (dialog);
}
static void
open_cb (GtkWidget *button,
ConstraintEditorWindow *self)
{
GtkFileChooserNative *dialog;
GtkFileDialog *dialog;
GFile *cwd;
dialog = gtk_file_chooser_native_new ("Open file",
GTK_WINDOW (self),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Load",
"_Cancel");
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
GFile *cwd = g_file_new_for_path (".");
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Open file");
cwd = g_file_new_for_path (".");
gtk_file_dialog_set_current_folder (dialog, cwd);
g_object_unref (cwd);
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), self);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
gtk_file_dialog_open (dialog, GTK_WINDOW (self), NULL, NULL, open_response_cb, self);
g_object_unref (dialog);
}
static void
@@ -294,22 +287,23 @@ serialize_model (GListModel *list)
static void
save_response_cb (GtkNativeDialog *dialog,
int response,
ConstraintEditorWindow *self)
save_response_cb (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_native_dialog_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
ConstraintEditorWindow *self = user_data;
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_save_finish (dialog, result, NULL);
if (file)
{
GListModel *model;
GFile *file;
char *text;
GError *error = NULL;
model = constraint_view_get_model (CONSTRAINT_VIEW (self->view));
text = serialize_model (model);
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
g_file_replace_contents (file, text, strlen (text),
NULL, FALSE,
G_FILE_CREATE_NONE,
@@ -318,46 +312,39 @@ save_response_cb (GtkNativeDialog *dialog,
&error);
if (error != NULL)
{
GtkWidget *message_dialog;
GtkAlertDialog *alert;
message_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))),
GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Saving failed");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog),
"%s", error->message);
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (message_dialog);
alert = gtk_alert_dialog_new ("Saving failed");
gtk_alert_dialog_set_detail (alert, error->message);
gtk_alert_dialog_show (alert,
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))));
g_object_unref (alert);
g_error_free (error);
}
g_free (text);
g_object_unref (file);
}
gtk_native_dialog_destroy (dialog);
}
static void
save_cb (GtkWidget *button,
ConstraintEditorWindow *self)
{
GtkFileChooserNative *dialog;
GtkFileDialog *dialog;
GFile *cwd;
dialog = gtk_file_chooser_native_new ("Save constraints",
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
GTK_FILE_CHOOSER_ACTION_SAVE,
"_Save",
"_Cancel");
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
GFile *cwd = g_file_new_for_path (".");
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Save constraints");
cwd = g_file_new_for_path (".");
gtk_file_dialog_set_current_folder (dialog, cwd);
g_object_unref (cwd);
g_signal_connect (dialog, "response", G_CALLBACK (save_response_cb), self);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
gtk_file_dialog_save (dialog,
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
NULL, NULL,
NULL,
save_response_cb, self);
g_object_unref (dialog);
}
static void

View File

@@ -33,22 +33,12 @@ static void create_window (GApplication *app, const char *contents);
static void
show_action_dialog (GSimpleAction *action)
{
const char *name;
GtkWidget *dialog;
GtkAlertDialog *dialog;
name = g_action_get_name (G_ACTION (action));
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"You activated action: \"%s\"",
name);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
dialog = gtk_alert_dialog_new ("You activated action: \"%s\n",
g_action_get_name (G_ACTION (action)));
gtk_alert_dialog_show (dialog, NULL);
g_object_unref (dialog);
}
static void
@@ -90,20 +80,19 @@ activate_new (GSimpleAction *action,
}
static void
open_response_cb (GtkNativeDialog *dialog,
int response_id,
gpointer user_data)
open_response_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GtkFileChooserNative *native = user_data;
GApplication *app = g_object_get_data (G_OBJECT (native), "app");
GtkWidget *message_dialog;
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GApplication *app = G_APPLICATION (user_data);
GFile *file;
char *contents;
GError *error = NULL;
if (response_id == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_save_finish (dialog, result, &error);
if (file)
{
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
char *contents;
if (g_file_load_contents (file, NULL, &contents, NULL, NULL, &error))
{
@@ -112,21 +101,16 @@ open_response_cb (GtkNativeDialog *dialog,
}
else
{
message_dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error loading file: \"%s\"",
error->message);
g_signal_connect (message_dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (message_dialog);
GtkAlertDialog *alert;
alert = gtk_alert_dialog_new ("Error loading file: \"%s\"", error->message);
gtk_alert_dialog_show (alert, NULL);
g_object_unref (alert);
g_error_free (error);
}
}
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
g_object_unref (native);
g_object_unref (app);
}
@@ -136,21 +120,11 @@ activate_open (GSimpleAction *action,
gpointer user_data)
{
GApplication *app = user_data;
GtkFileChooserNative *native;
GtkFileDialog *dialog;
native = gtk_file_chooser_native_new ("Open File",
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Open",
"_Cancel");
g_object_set_data_full (G_OBJECT (native), "app", g_object_ref (app), g_object_unref);
g_signal_connect (native,
"response",
G_CALLBACK (open_response_cb),
native);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
dialog = gtk_file_dialog_new ();
gtk_file_dialog_open (dialog, NULL, NULL, NULL, open_response_cb, g_object_ref (app));
g_object_unref (dialog);
}
static void

View File

@@ -50,10 +50,10 @@ copy_button_clicked (GtkStack *source_stack,
}
else if (strcmp (visible_child_name, "Color") == 0)
{
GdkRGBA color;
const GdkRGBA *color;
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (visible_child), &color);
gdk_clipboard_set (clipboard, GDK_TYPE_RGBA, &color);
color = gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (visible_child));
gdk_clipboard_set (clipboard, GDK_TYPE_RGBA, color);
}
else if (strcmp (visible_child_name, "File") == 0)
{
@@ -215,37 +215,36 @@ file_button_set_file (GtkButton *button,
}
static void
file_chooser_response (GtkNativeDialog *dialog,
int response,
GtkButton *button)
file_chooser_response (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
gtk_native_dialog_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GtkButton *button = GTK_BUTTON (user_data);
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
file_button_set_file (button, file);
g_object_unref (file);
update_copy_button_sensitivity (gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_STACK));
}
gtk_native_dialog_destroy (dialog);
}
static void
open_file_cb (GtkWidget *button)
{
GtkFileChooserNative *chooser;
GtkFileDialog *dialog;
chooser = gtk_file_chooser_native_new ("Choose a file",
GTK_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW)),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Open",
"_Cancel");
dialog = gtk_file_dialog_new ();
g_signal_connect (chooser, "response", G_CALLBACK (file_chooser_response), button);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser));
gtk_file_dialog_open (dialog,
GTK_WINDOW (gtk_widget_get_ancestor (button, GTK_TYPE_WINDOW)),
NULL,
NULL,
file_chooser_response, button);
}
static void

View File

@@ -64,7 +64,11 @@
<object class="GtkStackPage">
<property name="name">Color</property>
<property name="child">
<object class="GtkColorButton" id="source_color">
<object class="GtkColorDialogButton" id="source_color">
<property name="dialog">
<object class="GtkColorDialog">
</object>
</property>
<property name="valign">center</property>
<property name="rgba">purple</property>
</object>

View File

@@ -8,6 +8,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static GtkWidget *window = NULL;
static GtkWidget *entry1 = NULL;
static GtkWidget *entry2 = NULL;
@@ -16,19 +18,23 @@ static void
message_dialog_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *dialog;
static int i = 1;
GtkAlertDialog *dialog;
GtkWindow *parent;
static int count = 1;
char *detail;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK_CANCEL,
"Test message");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
ngettext ("Has been shown once", "Has been shown %d times", i), i);
g_signal_connect (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
i++;
parent = GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_WINDOW));
dialog = gtk_alert_dialog_new ("Test message");
detail = g_strdup_printf (ngettext ("Has been shown once", "Has been shown %d times", count), count);
gtk_alert_dialog_set_detail (dialog, detail);
g_free (detail);
gtk_alert_dialog_set_buttons (dialog, (const char *[]) {"_Cancel", "_OK", NULL });
gtk_alert_dialog_set_cancel_button (dialog, 0);
gtk_alert_dialog_set_default_button (dialog, 1);
gtk_alert_dialog_show (dialog, parent);
count++;
}
typedef struct {

View File

@@ -726,7 +726,9 @@ do_dnd (GtkWidget *do_widget)
GtkCssProvider *provider;
GString *css;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
button = gtk_color_button_new ();
G_GNUC_END_IGNORE_DEPRECATIONS
g_object_unref (g_object_ref_sink (button));
provider = gtk_css_provider_new ();

View File

@@ -10,6 +10,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static GtkWidget *window = NULL;
static void

View File

@@ -68,11 +68,13 @@ create_blurred_button (void)
return w;
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static GtkWidget *
create_font_button (void)
{
return gtk_font_button_new ();
}
G_GNUC_END_IGNORE_DEPRECATIONS
static GtkWidget *
create_level_bar (void)

View File

@@ -23,6 +23,76 @@
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/* {{{ ScriptLang object */
G_DECLARE_FINAL_TYPE (ScriptLang, script_lang, SCRIPT, LANG, GObject)
struct _ScriptLang
{
GObject parent;
char *langname;
unsigned int script_index;
unsigned int lang_index;
hb_tag_t lang_tag;
};
struct _ScriptLangClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE (ScriptLang, script_lang, G_TYPE_OBJECT)
static void
script_lang_init (ScriptLang *self)
{
}
static void
script_lang_finalize (GObject *object)
{
ScriptLang *self = SCRIPT_LANG (object);
g_free (self->langname);
G_OBJECT_CLASS (script_lang_parent_class)->finalize (object);
}
static void
script_lang_class_init (ScriptLangClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = script_lang_finalize;
}
static ScriptLang *
script_lang_new (const char *langname,
unsigned int script_index,
unsigned int lang_index,
hb_tag_t lang_tag)
{
ScriptLang *self;
self = g_object_new (script_lang_get_type (), NULL);
self->langname = g_strdup (langname);
self->script_index = script_index;
self->lang_index = lang_index;
self->lang_tag = lang_tag;
return self;
}
static char *
script_lang_get_langname (ScriptLang *self)
{
return g_strdup (self->langname);
}
/* }}} */
#define MAKE_TAG(a,b,c,d) (unsigned int)(((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
typedef struct {
@@ -95,6 +165,10 @@ demo_free (gpointer data)
g_clear_pointer (&demo->axes, g_hash_table_unref);
g_clear_pointer (&demo->text, g_free);
gtk_style_context_remove_provider_for_display (gdk_display_get_default (),
GTK_STYLE_PROVIDER (demo->provider));
g_object_unref (demo->provider);
g_free (demo);
}
@@ -184,10 +258,10 @@ swap_colors (void)
GdkRGBA fg;
GdkRGBA bg;
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->foreground), &fg);
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->background), &bg);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->foreground), &bg);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->background), &fg);
fg = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground));
bg = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background));
gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground), &bg);
gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background), &fg);
}
static void
@@ -196,8 +270,8 @@ font_features_reset_basic (void)
gtk_adjustment_set_value (demo->size_adjustment, 20);
gtk_adjustment_set_value (demo->letterspacing_adjustment, 0);
gtk_adjustment_set_value (demo->line_height_adjustment, 1);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->foreground), &(GdkRGBA){0.,0.,0.,1.});
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (demo->background), &(GdkRGBA){1.,1.,1.,1.});
gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground), &(GdkRGBA){0.,0.,0.,1.});
gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background), &(GdkRGBA){1.,1.,1.,1.});
}
static void
@@ -205,7 +279,7 @@ update_basic (void)
{
PangoFontDescription *desc;
desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (demo->font));
desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (demo->font));
gtk_adjustment_set_value (demo->size_adjustment,
pango_font_description_get_size (desc) / (double) PANGO_SCALE);
@@ -472,8 +546,6 @@ update_display (void)
GString *s;
char *text;
gboolean has_feature;
GtkTreeIter iter;
GtkTreeModel *model;
PangoFontDescription *desc;
GList *l;
PangoAttrList *attrs;
@@ -518,7 +590,7 @@ update_display (void)
end = PANGO_ATTR_INDEX_TO_TEXT_END;
}
desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (demo->font));
desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (demo->font));
value = gtk_adjustment_get_value (demo->size_adjustment);
pango_font_description_set_size (desc, value * PANGO_SCALE);
@@ -576,14 +648,13 @@ update_display (void)
features = g_string_free (s, FALSE);
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (demo->script_lang), &iter))
if (gtk_drop_down_get_selected (GTK_DROP_DOWN (demo->script_lang)) != 0)
{
hb_tag_t lang_tag;
ScriptLang *selected;
model = gtk_combo_box_get_model (GTK_COMBO_BOX (demo->script_lang));
gtk_tree_model_get (model, &iter, 3, &lang_tag, -1);
selected = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (demo->script_lang));
lang = pango_language_from_string (hb_language_to_string (hb_ot_tag_to_language (lang_tag)));
lang = pango_language_from_string (hb_language_to_string (hb_ot_tag_to_language (selected->lang_tag)));
}
else
lang = NULL;
@@ -610,7 +681,7 @@ update_display (void)
GdkRGBA rgba;
char *fg, *bg, *css;
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->foreground), &rgba);
rgba = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->foreground));
attr = pango_attr_foreground_new (65535 * rgba.red,
65535 * rgba.green,
65535 * rgba.blue);
@@ -623,7 +694,7 @@ update_display (void)
pango_attr_list_insert (attrs, attr);
fg = gdk_rgba_to_string (&rgba);
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (demo->background), &rgba);
rgba = *gtk_color_dialog_button_get_rgba (GTK_COLOR_DIALOG_BUTTON (demo->background));
bg = gdk_rgba_to_string (&rgba);
css = g_strdup_printf (".font_features_background { caret-color: %s; background-color: %s; }", fg, bg);
gtk_css_provider_load_from_data (demo->provider, css, strlen (css));
@@ -698,7 +769,6 @@ update_display (void)
gtk_label_set_attributes (GTK_LABEL (demo->the_label), attrs);
g_free (font_desc);
pango_font_description_free (desc);
g_free (features);
pango_attr_list_unref (attrs);
g_free (text);
@@ -710,7 +780,7 @@ get_pango_font (void)
PangoFontDescription *desc;
PangoContext *context;
desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (demo->font));
desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (demo->font));
context = gtk_widget_get_pango_context (demo->font);
return pango_context_load_font (context, desc);
@@ -740,50 +810,40 @@ tag_pair_equal (gconstpointer a, gconstpointer b)
return pair_a->script_tag == pair_b->script_tag && pair_a->lang_tag == pair_b->lang_tag;
}
static int
script_sort_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
static GtkOrdering
script_sort (const void *item1,
const void *item2,
void *data)
{
char *sa, *sb;
int ret;
ScriptLang *a = (ScriptLang *)item1;
ScriptLang *b = (ScriptLang *)item2;
gtk_tree_model_get (model, a, 0, &sa, -1);
gtk_tree_model_get (model, b, 0, &sb, -1);
ret = strcmp (sa, sb);
g_free (sa);
g_free (sb);
return ret;
return strcmp (a->langname, b->langname);
}
static void
update_script_combo (void)
{
GtkListStore *store;
GListStore *store;
GtkSortListModel *sortmodel;
hb_font_t *hb_font;
int i, j, k;
PangoFont *pango_font;
GHashTable *tags;
GHashTableIter iter;
TagPair *pair;
char *lang;
PangoLanguage *language;
const char *lang;
hb_tag_t active;
GtkTreeIter active_iter;
gboolean have_active = FALSE;
lang = gtk_font_chooser_get_language (GTK_FONT_CHOOSER (demo->font));
language = gtk_font_dialog_button_get_language (GTK_FONT_DIALOG_BUTTON (demo->font));
lang = pango_language_to_string (language);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
active = hb_ot_tag_from_language (hb_language_from_string (lang, -1));
G_GNUC_END_IGNORE_DEPRECATIONS
g_free (lang);
store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
store = g_list_store_new (script_lang_get_type ());
pango_font = get_pango_font ();
hb_font = pango_font_get_hb_font (pango_font);
@@ -807,19 +867,19 @@ update_script_combo (void)
hb_face = hb_font_get_face (hb_font);
for (i= 0; i < 2; i++)
for (guint i = 0; i < 2; i++)
{
hb_tag_t scripts[80];
unsigned int script_count = G_N_ELEMENTS (scripts);
hb_ot_layout_table_get_script_tags (hb_face, tables[i], 0, &script_count, scripts);
for (j = 0; j < script_count; j++)
for (guint j = 0; j < script_count; j++)
{
hb_tag_t languages[80];
unsigned int language_count = G_N_ELEMENTS (languages);
hb_ot_layout_script_get_language_tags (hb_face, tables[i], j, 0, &language_count, languages);
for (k = 0; k < language_count; k++)
for (guint k = 0; k < language_count; k++)
{
pair = g_new (TagPair, 1);
pair->script_tag = scripts[j];
@@ -839,7 +899,6 @@ update_script_combo (void)
{
const char *langname;
char langbuf[5];
GtkTreeIter tree_iter;
if (pair->lang_tag == 0 && pair->script_tag == 0)
langname = NC_("Language", "None");
@@ -856,31 +915,31 @@ update_script_combo (void)
}
}
gtk_list_store_insert_with_values (store, &tree_iter, -1,
0, langname,
1, pair->script_index,
2, pair->lang_index,
3, pair->lang_tag,
-1);
if (pair->lang_tag == active)
{
have_active = TRUE;
active_iter = tree_iter;
}
g_list_store_append (store, script_lang_new (langname,
pair->script_index,
pair->lang_index,
pair->lang_tag));
}
g_hash_table_destroy (tags);
gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
script_sort_func, NULL, NULL);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID,
GTK_SORT_ASCENDING);
gtk_combo_box_set_model (GTK_COMBO_BOX (demo->script_lang), GTK_TREE_MODEL (store));
if (have_active)
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (demo->script_lang), &active_iter);
else
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (demo->script_lang), 0);
sortmodel = gtk_sort_list_model_new (G_LIST_MODEL (store),
GTK_SORTER (gtk_custom_sorter_new (script_sort, NULL, NULL)));
gtk_drop_down_set_model (GTK_DROP_DOWN (demo->script_lang), G_LIST_MODEL (sortmodel));
for (guint i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (sortmodel)); i++)
{
ScriptLang *item = g_list_model_get_item (G_LIST_MODEL (sortmodel), i);
g_object_unref (item);
if (item->lang_tag == active)
{
gtk_drop_down_set_selected (GTK_DROP_DOWN (demo->script_lang), i);
break;
}
}
g_object_unref (sortmodel);
}
static char *
@@ -905,27 +964,19 @@ static void
update_features (void)
{
int i, j;
GtkTreeModel *model;
GtkTreeIter iter;
guint script_index, lang_index;
hb_tag_t lang_tag;
PangoFont *pango_font;
hb_font_t *hb_font;
GList *l;
ScriptLang *selected;
/* set feature presence checks from the font features */
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (demo->script_lang), &iter))
if (gtk_drop_down_get_selected (GTK_DROP_DOWN (demo->script_lang)) == 0)
return;
model = gtk_combo_box_get_model (GTK_COMBO_BOX (demo->script_lang));
gtk_tree_model_get (model, &iter,
1, &script_index,
2, &lang_index,
3, &lang_tag,
-1);
selected = gtk_drop_down_get_selected_item (GTK_DROP_DOWN (demo->script_lang));
if (lang_tag == 0) /* None is selected */
if (selected->lang_tag == 0) /* None is selected */
{
for (l = demo->feature_items; l; l = l->next)
{
@@ -955,7 +1006,7 @@ update_features (void)
{
hb_tag_t tables[2] = { HB_OT_TAG_GSUB, HB_OT_TAG_GPOS };
hb_face_t *hb_face;
char *feat;
const char *feat;
hb_face = hb_font_get_face (hb_font);
@@ -966,8 +1017,8 @@ update_features (void)
hb_ot_layout_language_get_feature_tags (hb_face,
tables[i],
script_index,
lang_index,
selected->script_index,
selected->lang_index,
0,
&count,
features);
@@ -989,8 +1040,8 @@ update_features (void)
hb_ot_layout_language_find_feature (hb_face,
tables[i],
script_index,
lang_index,
selected->script_index,
selected->lang_index,
features[j],
&feature_index);
@@ -1048,7 +1099,7 @@ update_features (void)
}
}
feat = gtk_font_chooser_get_font_features (GTK_FONT_CHOOSER (demo->font));
feat = gtk_font_dialog_button_get_font_features (GTK_FONT_DIALOG_BUTTON (demo->font));
if (feat)
{
for (l = demo->feature_items; l; l = l->next)
@@ -1074,8 +1125,6 @@ update_features (void)
}
}
}
g_free (feat);
}
}
@@ -1322,10 +1371,9 @@ free_instance (gpointer data)
}
static void
add_instance (hb_face_t *face,
unsigned int index,
GtkWidget *combo,
int pos)
add_instance (hb_face_t *face,
unsigned int index,
GtkStringList *strings)
{
Instance *instance;
hb_ot_name_id_t name_id;
@@ -1341,20 +1389,20 @@ add_instance (hb_face_t *face,
instance->index = index;
g_hash_table_add (demo->instances, instance);
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), instance->name);
gtk_string_list_append (GTK_STRING_LIST (strings), instance->name);
}
static void
unset_instance (GtkAdjustment *adjustment)
{
if (demo->instance_combo)
gtk_combo_box_set_active (GTK_COMBO_BOX (demo->instance_combo), 0);
gtk_drop_down_set_selected (GTK_DROP_DOWN (demo->instance_combo), 0);
}
static void
instance_changed (GtkComboBox *combo)
instance_changed (GtkDropDown *combo)
{
char *text;
const char *text;
Instance *instance;
Instance ikey;
int i;
@@ -1366,11 +1414,12 @@ instance_changed (GtkComboBox *combo)
hb_font_t *hb_font;
hb_face_t *hb_face;
text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (combo));
text = gtk_string_list_get_string (GTK_STRING_LIST (gtk_drop_down_get_model (combo)),
gtk_drop_down_get_selected (combo));
if (text[0] == '\0')
goto out;
ikey.name = text;
ikey.name = (char *) text;
instance = g_hash_table_lookup (demo->instances, &ikey);
if (!instance)
{
@@ -1411,7 +1460,6 @@ instance_changed (GtkComboBox *combo)
}
out:
g_free (text);
g_clear_object (&pango_font);
g_free (ai);
g_free (coords);
@@ -1521,6 +1569,7 @@ update_font_variations (void)
{
GtkWidget *label;
GtkWidget *combo;
GtkStringList *strings;
label = gtk_label_new ("Instance");
gtk_label_set_xalign (GTK_LABEL (label), 0);
@@ -1528,26 +1577,28 @@ update_font_variations (void)
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
gtk_grid_attach (GTK_GRID (demo->variations_grid), label, 0, -1, 1, 1);
combo = gtk_combo_box_text_new ();
strings = gtk_string_list_new (NULL);
combo = gtk_drop_down_new (G_LIST_MODEL (strings), NULL);
gtk_widget_set_halign (combo, GTK_ALIGN_START);
gtk_widget_set_valign (combo, GTK_ALIGN_BASELINE);
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "");
gtk_string_list_append (strings, "");
for (i = 0; i < hb_ot_var_get_named_instance_count (hb_face); i++)
add_instance (hb_face, i, combo, i);
add_instance (hb_face, i, strings);
for (i = 0; i < hb_ot_var_get_named_instance_count (hb_face); i++)
{
if (matches_instance (hb_face, i, n_axes, design_coords))
{
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i + 1);
gtk_drop_down_set_selected (GTK_DROP_DOWN (combo), i + 1);
break;
}
}
gtk_grid_attach (GTK_GRID (demo->variations_grid), combo, 1, -1, 3, 1);
g_signal_connect (combo, "changed", G_CALLBACK (instance_changed), NULL);
g_signal_connect (combo, "notify::selecte", G_CALLBACK (instance_changed), NULL);
demo->instance_combo = combo;
}
@@ -1694,6 +1745,7 @@ do_font_features (GtkWidget *do_widget)
GtkBuilder *builder;
GtkBuilderScope *scope;
GtkEventController *controller;
GtkExpression *expression;
builder = gtk_builder_new ();
@@ -1727,6 +1779,10 @@ do_font_features (GtkWidget *do_widget)
demo->description = GTK_WIDGET (gtk_builder_get_object (builder, "description"));
demo->font = GTK_WIDGET (gtk_builder_get_object (builder, "font"));
demo->script_lang = GTK_WIDGET (gtk_builder_get_object (builder, "script_lang"));
g_assert (GTK_IS_DROP_DOWN (demo->script_lang));
expression = gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL, G_CALLBACK (script_lang_get_langname), NULL, NULL);
gtk_drop_down_set_expression (GTK_DROP_DOWN (demo->script_lang), expression);
gtk_expression_unref (expression);
demo->feature_list = GTK_WIDGET (gtk_builder_get_object (builder, "feature_list"));
demo->stack = GTK_WIDGET (gtk_builder_get_object (builder, "stack"));
demo->entry = GTK_WIDGET (gtk_builder_get_object (builder, "entry"));
@@ -1745,8 +1801,8 @@ do_font_features (GtkWidget *do_widget)
demo->swin = GTK_WIDGET (gtk_builder_get_object (builder, "swin"));
demo->provider = gtk_css_provider_new ();
gtk_style_context_add_provider (gtk_widget_get_style_context (demo->swin),
GTK_STYLE_PROVIDER (demo->provider), 800);
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
GTK_STYLE_PROVIDER (demo->provider), 800);
basic_value_changed (demo->size_adjustment, demo->size_entry);
basic_value_changed (demo->letterspacing_adjustment, demo->letterspacing_entry);
@@ -1824,3 +1880,5 @@ do_font_features (GtkWidget *do_widget)
return window;
}
/* vim:set foldmethod=marker expandtab: */

View File

@@ -58,11 +58,14 @@
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkFontButton" id="font">
<object class="GtkFontDialogButton" id="font">
<property name="dialog">
<object class="GtkFontDialog">
</object>
</property>
<property name="receives-default">1</property>
<property name="font">Sans 12</property>
<property name="level">family|style</property>
<signal name="font-set" handler="font_features_font_changed" swapped="no"/>
<property name="level">face</property>
<signal name="notify::font-desc" handler="font_features_font_changed" swapped="no"/>
</object>
</child>
<child>
@@ -192,7 +195,11 @@
</object>
</child>
<child>
<object class="GtkColorButton" id="foreground">
<object class="GtkColorDialogButton" id="foreground">
<property name="dialog">
<object class="GtkColorDialog">
</object>
</property>
<property name="valign">baseline</property>
<property name="rgba">black</property>
<signal name="notify::rgba" handler="color_set_cb"/>
@@ -214,7 +221,11 @@
</object>
</child>
<child>
<object class="GtkColorButton" id="background">
<object class="GtkColorDialogButton" id="background">
<property name="dialog">
<object class="GtkColorDialog">
</object>
</property>
<property name="valign">baseline</property>
<property name="rgba">white</property>
<signal name="notify::rgba" handler="color_set_cb"/>
@@ -259,16 +270,10 @@
<object class="GtkBox" id="feature_list">
<property name="orientation">vertical</property>
<child>
<object class="GtkComboBox" id="script_lang">
<object class="GtkDropDown" id="script_lang">
<property name="tooltip-text" translatable="yes">Language System</property>
<property name="margin-top">10</property>
<signal name="changed" handler="font_features_script_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
<signal name="notify::selected" handler="font_features_script_changed" swapped="no"/>
</object>
</child>
</object>

View File

@@ -53,7 +53,7 @@ update_image (void)
context = gtk_widget_create_pango_context (image);
text = gtk_editable_get_text (GTK_EDITABLE (entry));
desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (font_button));
desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (font_button));
fopt = cairo_font_options_copy (pango_cairo_context_get_font_options (context));
@@ -287,8 +287,6 @@ retry:
gtk_picture_set_pixbuf (GTK_PICTURE (image), pixbuf2);
g_object_unref (pixbuf2);
pango_font_description_free (desc);
}
static gboolean fading = FALSE;

View File

@@ -74,7 +74,11 @@
</object>
</child>
<child>
<object class="GtkFontButton" id="font_button">
<object class="GtkFontDialogButton" id="font_button">
<property name="dialog">
<object class="GtkFontDialog">
</object>
</property>
<layout>
<property name="column">2</property>
<property name="row">1</property>

View File

@@ -83,24 +83,17 @@ progressive_timeout (gpointer data)
if (bytes_read < 0)
{
GtkWidget *dialog;
GtkAlertDialog *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failure reading image file 'alphatest.png': %s",
error->message);
dialog = gtk_alert_dialog_new ("Failure reading image file 'alphatest.png': %s",
error->message);
gtk_alert_dialog_show (dialog, NULL);
g_object_unref (dialog);
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
g_object_unref (image_stream);
image_stream = NULL;
gtk_widget_show (dialog);
load_timeout = 0;
return FALSE; /* uninstall the timeout */
@@ -110,25 +103,17 @@ progressive_timeout (gpointer data)
buf, bytes_read,
&error))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failed to load image: %s",
error->message);
GtkAlertDialog *dialog;
dialog = gtk_alert_dialog_new ("Failed to load image: %s",
error->message);
gtk_alert_dialog_show (dialog, NULL);
g_object_unref (dialog);
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
g_object_unref (image_stream);
image_stream = NULL;
gtk_widget_show (dialog);
load_timeout = 0;
return FALSE; /* uninstall the timeout */
@@ -143,22 +128,14 @@ progressive_timeout (gpointer data)
error = NULL;
if (!g_input_stream_close (image_stream, NULL, &error))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failed to load image: %s",
error->message);
GtkAlertDialog *dialog;
dialog = gtk_alert_dialog_new ("Failed to load image: %s",
error->message);
gtk_alert_dialog_show (dialog, NULL);
g_object_unref (dialog);
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
g_object_unref (image_stream);
image_stream = NULL;
g_object_unref (pixbuf_loader);
@@ -177,25 +154,16 @@ progressive_timeout (gpointer data)
* it was incomplete.
*/
error = NULL;
if (!gdk_pixbuf_loader_close (pixbuf_loader,
&error))
if (!gdk_pixbuf_loader_close (pixbuf_loader, &error))
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failed to load image: %s",
error->message);
GtkAlertDialog *dialog;
dialog = gtk_alert_dialog_new ("Failed to load image: %s",
error->message);
gtk_alert_dialog_show (dialog, NULL);
g_object_unref (dialog);
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
g_object_unref (pixbuf_loader);
pixbuf_loader = NULL;
@@ -216,20 +184,14 @@ progressive_timeout (gpointer data)
if (image_stream == NULL)
{
GtkWidget *dialog;
GtkAlertDialog *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s", error->message);
dialog = gtk_alert_dialog_new ("%s",
error->message);
gtk_alert_dialog_show (dialog, NULL);
g_object_unref (dialog);
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
load_timeout = 0;
return FALSE; /* uninstall the timeout */

View File

@@ -12,8 +12,8 @@ on_bar_response (GtkInfoBar *info_bar,
int response_id,
gpointer user_data)
{
GtkWidget *dialog;
GtkWidget *window;
GtkAlertDialog *dialog;
char *detail;
if (response_id == GTK_RESPONSE_CLOSE)
{
@@ -21,19 +21,12 @@ on_bar_response (GtkInfoBar *info_bar,
return;
}
window = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (info_bar)));
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"You clicked a button on an info bar");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"Your response has id %d", response_id);
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (gtk_window_destroy), dialog);
gtk_widget_show (dialog);
dialog = gtk_alert_dialog_new ("You clicked a button on an info bar");
detail = g_strdup_printf ("Your response has been %d", response_id);
gtk_alert_dialog_set_detail (dialog, detail);
g_free (detail);
gtk_alert_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (info_bar))));
g_object_unref (dialog);
}
GtkWidget *

View File

@@ -7,38 +7,22 @@
#include <gtk/gtk.h>
static void
response_cb (GtkWidget *dialog,
int response_id,
gpointer data)
{
gtk_window_destroy (GTK_WINDOW (dialog));
}
static gboolean
activate_link (GtkWidget *label,
activate_link (GtkWidget *label,
const char *uri,
gpointer data)
gpointer data)
{
if (g_strcmp0 (uri, "keynav") == 0)
{
GtkWidget *dialog;
GtkWidget *parent;
GtkAlertDialog *dialog;
parent = GTK_WIDGET (gtk_widget_get_root (label));
dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (parent),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Keyboard navigation");
gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
"The term <i>keynav</i> is a shorthand for "
"keyboard navigation and refers to the process of using "
"a program (exclusively) via keyboard input.");
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_window_present (GTK_WINDOW (dialog));
g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
dialog = gtk_alert_dialog_new ("Keyboard navigation");
gtk_alert_dialog_set_detail (dialog,
"The term keynav is a shorthand for "
"keyboard navigation and refers to the process of using "
"a program (exclusively) via keyboard input.");
gtk_alert_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_root (label)));
g_object_unref (dialog);
return TRUE;
}

View File

@@ -117,19 +117,16 @@ activate_cb (GtkListView *list,
G_APP_LAUNCH_CONTEXT (context),
&error))
{
GtkWidget *dialog;
GtkAlertDialog *dialog;
/* And because error handling is important, even a simple demo has it:
* We display an error dialog that something went wrong.
*/
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (list))),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Could not launch %s", g_app_info_get_display_name (app_info));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
dialog = gtk_alert_dialog_new ("Could not launch %s", g_app_info_get_display_name (app_info));
gtk_alert_dialog_set_detail (dialog, error->message);
gtk_alert_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (list))));
g_object_unref (dialog);
g_clear_error (&error);
gtk_widget_show (dialog);
}
g_object_unref (context);

View File

@@ -42,7 +42,7 @@ update_title_cb (GtkFilterListModel *model)
title = g_strdup_printf ("%u lines", g_list_model_get_n_items (G_LIST_MODEL (model)));
gtk_widget_set_visible (progress, pending != 0);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), (total - pending) / (double) total);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), total > 0 ? (total - pending) / (double) total : 0.);
gtk_window_set_title (GTK_WINDOW (window), title);
g_free (title);
}
@@ -141,39 +141,35 @@ load_file (GtkStringList *list,
}
static void
open_response_cb (GtkNativeDialog *dialog,
int response,
GtkStringList *stringlist)
open_response_cb (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_native_dialog_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GtkStringList *stringlist = GTK_STRING_LIST (user_data);
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
GFile *file;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
load_file (stringlist, file);
g_object_unref (file);
}
gtk_native_dialog_destroy (dialog);
}
static void
file_open_cb (GtkWidget *button,
GtkStringList *stringlist)
{
GtkFileChooserNative *dialog;
GtkFileDialog *dialog;
dialog = gtk_file_chooser_native_new ("Open file",
GTK_WINDOW (gtk_widget_get_root (button)),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Load",
"_Cancel");
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), stringlist);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
dialog = gtk_file_dialog_new ();
gtk_file_dialog_open (dialog,
GTK_WINDOW (gtk_widget_get_root (button)),
NULL,
NULL,
open_response_cb, stringlist);
g_object_unref (dialog);
}
GtkWidget *

View File

@@ -7,6 +7,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
enum {
COLOR_SET,
N_SIGNALS
@@ -51,8 +53,8 @@ static const char *pad_colors[] = {
static GType drawing_area_get_type (void);
G_DEFINE_TYPE (DrawingArea, drawing_area, GTK_TYPE_WIDGET)
static void drawing_area_set_color (DrawingArea *area,
GdkRGBA *color);
static void drawing_area_set_color (DrawingArea *area,
const GdkRGBA *color);
static void
drawing_area_ensure_surface (DrawingArea *area,
@@ -350,8 +352,8 @@ drawing_area_new (void)
}
static void
drawing_area_set_color (DrawingArea *area,
GdkRGBA *color)
drawing_area_set_color (DrawingArea *area,
const GdkRGBA *color)
{
if (gdk_rgba_equal (&area->draw_color, color))
return;
@@ -361,21 +363,22 @@ drawing_area_set_color (DrawingArea *area,
}
static void
color_button_color_set (GtkColorButton *button,
DrawingArea *draw_area)
color_button_color_set (GtkColorDialogButton *button,
GParamSpec *pspec,
DrawingArea *draw_area)
{
GdkRGBA color;
const GdkRGBA *color;
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &color);
drawing_area_set_color (draw_area, &color);
color = gtk_color_dialog_button_get_rgba (button);
drawing_area_set_color (draw_area, color);
}
static void
drawing_area_color_set (DrawingArea *area,
GdkRGBA *color,
GtkColorButton *button)
drawing_area_color_set (DrawingArea *area,
GdkRGBA *color,
GtkColorDialogButton *button)
{
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), color);
gtk_color_dialog_button_set_rgba (button, color);
}
GtkWidget *
@@ -394,13 +397,13 @@ do_paint (GtkWidget *toplevel)
headerbar = gtk_header_bar_new ();
colorbutton = gtk_color_button_new ();
g_signal_connect (colorbutton, "color-set",
colorbutton = gtk_color_dialog_button_new (gtk_color_dialog_new ());
g_signal_connect (colorbutton, "notify::rgba",
G_CALLBACK (color_button_color_set), draw_area);
g_signal_connect (draw_area, "color-set",
G_CALLBACK (drawing_area_color_set), colorbutton);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (colorbutton),
&(GdkRGBA) { 0, 0, 0, 1 });
gtk_color_dialog_button_set_rgba (GTK_COLOR_DIALOG_BUTTON (colorbutton),
&(GdkRGBA) { 0, 0, 0, 1 });
gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), colorbutton);
gtk_window_set_titlebar (GTK_WINDOW (window), headerbar);

View File

@@ -13,25 +13,24 @@
static void
open_response_cb (GtkNativeDialog *dialog,
int response,
GtkPicture *picture)
open_response_cb (GObject *source,
GAsyncResult *result,
void *data)
{
gtk_native_dialog_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GtkPicture *picture = data;
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
GFile *file;
GdkPaintable *paintable;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
paintable = svg_paintable_new (file);
gtk_picture_set_paintable (GTK_PICTURE (picture), paintable);
g_object_unref (paintable);
g_object_unref (file);
}
gtk_native_dialog_destroy (dialog);
}
static void
@@ -39,20 +38,25 @@ show_file_open (GtkWidget *button,
GtkPicture *picture)
{
GtkFileFilter *filter;
GtkFileChooserNative *dialog;
GtkFileDialog *dialog;
GListStore *filters;
dialog = gtk_file_chooser_native_new ("Open node file",
GTK_WINDOW (gtk_widget_get_root (button)),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Load",
"_Cancel");
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Open node file");
filter = gtk_file_filter_new ();
gtk_file_filter_add_mime_type (filter, "image/svg+xml");
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), picture);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
filters = g_list_store_new (GTK_TYPE_FILE_FILTER);
g_list_store_append (filters, filter);
g_object_unref (filter);
gtk_file_dialog_set_filters (dialog, G_LIST_MODEL (filters));
g_object_unref (filters);
gtk_file_dialog_open (dialog,
GTK_WINDOW (gtk_widget_get_root (button)),
NULL,
NULL,
open_response_cb, picture);
}
static GtkWidget *window;

View File

@@ -1,34 +1,44 @@
/* Pickers
* #Keywords: GtkColorChooser, GtkFontChooser, GtkApplicationChooser
* #Keywords: GtkColorDialog, GtkFontDialog, GtkFileDialog, GtkColorDialogButton, GtkFontDialogButton, chooser, button
*
* These widgets are mainly intended for use in preference dialogs.
* They allow to select colors, fonts and applications.
*
* This demo shows both the default appearance for these dialogs,
* as well as some of the customizations that are possible.
* These widgets and async APIs are mainly intended for use in preference dialogs.
* They allow to select colors, fonts, files and applications.
*/
#include <gtk/gtk.h>
static gboolean
filter_font_cb (const PangoFontFamily *family,
const PangoFontFace *face,
gpointer data)
static void
file_opened (GObject *source,
GAsyncResult *result,
void *data)
{
const char *alias_families[] = {
"Cursive",
"Fantasy",
"Monospace",
"Sans",
"Serif",
"System-ui",
NULL
};
const char *family_name;
GFile *file;
family_name = pango_font_family_get_name (PANGO_FONT_FAMILY (family));
file = gtk_file_dialog_open_finish (GTK_FILE_DIALOG (source), result, NULL);
return g_strv_contains (alias_families, family_name);
if (file)
{
char *name = g_file_get_basename (file);
gtk_button_set_label (GTK_BUTTON (data), name);
g_object_set_data_full (G_OBJECT (data), "file", file, g_object_unref);
g_free (name);
}
}
static void
open_file (GtkButton *picker)
{
GtkWindow *parent = GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (picker)));
GtkFileDialog *dialog;
GFile *file;
dialog = gtk_file_dialog_new ();
file = (GFile *) g_object_get_data (G_OBJECT (picker), "file");
gtk_file_dialog_open (dialog, parent, file, NULL, file_opened, picker);
g_object_unref (dialog);
}
#define COLOR(r,g,b) { r/255., g/255., b/255., 1.0 }
@@ -38,27 +48,6 @@ do_pickers (GtkWidget *do_widget)
{
static GtkWidget *window = NULL;
GtkWidget *table, *label, *picker;
GdkRGBA solarized[] = {
COLOR (0xff, 0xff, 0xff),
COLOR (0x07, 0x36, 0x42),
COLOR (0xdc, 0x32, 0x2f),
COLOR (0x85, 0x99, 0x00),
COLOR (0xb5, 0x89, 0x00),
COLOR (0x26, 0x8b, 0xd2),
COLOR (0xd3, 0x36, 0x82),
COLOR (0x2a, 0xa1, 0x98),
COLOR (0xee, 0xe8, 0xd5),
COLOR (0x00, 0x00, 0x00),
COLOR (0x00, 0x2b, 0x36),
COLOR (0xcb, 0x4b, 0x16),
COLOR (0x58, 0x6e, 0x75),
COLOR (0x65, 0x7b, 0x83),
COLOR (0x83, 0x94, 0x96),
COLOR (0x6c, 0x71, 0xc4),
COLOR (0x93, 0xa1, 0xa1),
COLOR (0xfd, 0xf6, 0xe3),
};
if (!window)
{
@@ -77,55 +66,41 @@ do_pickers (GtkWidget *do_widget)
gtk_grid_set_column_spacing (GTK_GRID (table), 10);
gtk_window_set_child (GTK_WINDOW (window), table);
label = gtk_label_new ("Standard");
gtk_widget_add_css_class (label, "title-4");
gtk_grid_attach (GTK_GRID (table), label, 1, -1, 1, 1);
label = gtk_label_new ("Custom");
gtk_widget_add_css_class (label, "title-4");
gtk_grid_attach (GTK_GRID (table), label, 2, -1, 1, 1);
label = gtk_label_new ("Color:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (label, TRUE);
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
picker = gtk_color_button_new ();
picker = gtk_color_dialog_button_new (gtk_color_dialog_new ());
gtk_grid_attach (GTK_GRID (table), picker, 1, 0, 1, 1);
picker = gtk_color_button_new ();
gtk_color_button_set_title (GTK_COLOR_BUTTON (picker), "Solarized colors");
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (picker),
GTK_ORIENTATION_HORIZONTAL,
9,
18,
solarized);
gtk_grid_attach (GTK_GRID (table), picker, 2, 0, 1, 1);
label = gtk_label_new ("Font:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (label, TRUE);
gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
picker = gtk_font_button_new ();
picker = gtk_font_dialog_button_new (gtk_font_dialog_new ());
gtk_grid_attach (GTK_GRID (table), picker, 1, 1, 1, 1);
picker = gtk_font_button_new ();
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (picker),
GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_SIZE);
gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (picker), filter_font_cb, NULL, NULL);
label = gtk_label_new ("File:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (label, TRUE);
gtk_grid_attach (GTK_GRID (table), label, 0, 2, 1, 1);
gtk_grid_attach (GTK_GRID (table), picker, 2, 1, 1, 1);
picker = gtk_button_new_with_label ("None");
g_signal_connect (picker, "clicked", G_CALLBACK (open_file), NULL);
gtk_grid_attach (GTK_GRID (table), picker, 1, 2, 1, 1);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
label = gtk_label_new ("Mail:");
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (label, TRUE);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
picker = gtk_app_chooser_button_new ("x-scheme-handler/mailto");
gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON (picker), TRUE);

View File

@@ -177,19 +177,12 @@ do_printing (GtkWidget *do_widget)
if (error)
{
GtkWidget *dialog;
GtkAlertDialog *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (do_widget),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s", error->message);
dialog = gtk_alert_dialog_new ("%s", error->message);
gtk_alert_dialog_show (dialog, GTK_WINDOW (do_widget));
g_object_unref (dialog);
g_error_free (error);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (dialog);
}

View File

@@ -35,6 +35,7 @@ do_spinner (GtkWidget *do_widget)
if (!window)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
window = gtk_dialog_new_with_buttons ("Spinner",
GTK_WINDOW (do_widget),
0,
@@ -48,6 +49,7 @@ do_spinner (GtkWidget *do_widget)
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
G_GNUC_END_IGNORE_DEPRECATIONS
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_widget_set_margin_start (vbox, 5);

View File

@@ -10,60 +10,63 @@
static GtkWidget *window = NULL;
static void
open_dialog_response_cb (GtkNativeDialog *dialog,
int response,
GtkWidget *video)
open_dialog_response_cb (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_native_dialog_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GtkWidget *video = user_data;
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
GFile *file;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
gtk_video_set_file (GTK_VIDEO (video), file);
g_object_unref (file);
}
gtk_native_dialog_destroy (dialog);
}
static void
open_clicked_cb (GtkWidget *button,
GtkWidget *video)
{
GtkFileChooserNative *dialog;
GtkFileDialog *dialog;
GtkFileFilter *filter;
GListStore *filters;
dialog = gtk_file_chooser_native_new ("Select a video",
GTK_WINDOW (gtk_widget_get_root (button)),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Open",
"_Cancel");
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Select a video");
filters = g_list_store_new (GTK_TYPE_FILE_FILTER);
filter = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filter, "*");
gtk_file_filter_set_name (filter, "All Files");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
g_list_store_append (filters, filter);
g_object_unref (filter);
filter = gtk_file_filter_new ();
gtk_file_filter_add_mime_type (filter, "image/*");
gtk_file_filter_set_name (filter, "Images");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
g_list_store_append (filters, filter);
g_object_unref (filter);
filter = gtk_file_filter_new ();
gtk_file_filter_add_mime_type (filter, "video/*");
gtk_file_filter_set_name (filter, "Video");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
g_list_store_append (filters, filter);
gtk_file_dialog_set_current_filter (dialog, filter);
g_object_unref (filter);
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (dialog), TRUE);
g_signal_connect (dialog, "response", G_CALLBACK (open_dialog_response_cb), video);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog));
gtk_file_dialog_set_filters (dialog, G_LIST_MODEL (filters));
g_object_unref (filters);
gtk_file_dialog_open (dialog,
GTK_WINDOW (gtk_widget_get_root (button)),
NULL,
NULL,
open_dialog_response_cb, video);
}
static void

View File

@@ -548,45 +548,36 @@ node_editor_window_load (NodeEditorWindow *self,
}
static void
open_response_cb (GtkWidget *dialog,
int response,
NodeEditorWindow *self)
open_response_cb (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_widget_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
NodeEditorWindow *self = user_data;
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
GFile *file;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
node_editor_window_load (self, file);
g_object_unref (file);
}
gtk_window_destroy (GTK_WINDOW (dialog));
}
static void
show_open_filechooser (NodeEditorWindow *self)
{
GtkWidget *dialog;
GtkFileDialog *dialog;
GFile *cwd;
dialog = gtk_file_chooser_dialog_new ("Open node file",
GTK_WINDOW (self),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Load", GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
GFile *cwd = g_file_new_for_path (".");
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Open node file");
cwd = g_file_new_for_path (".");
gtk_file_dialog_set_current_folder (dialog, cwd);
g_object_unref (cwd);
g_signal_connect (dialog, "response", G_CALLBACK (open_response_cb), self);
gtk_widget_show (dialog);
gtk_file_dialog_open (dialog, GTK_WINDOW (self),
NULL, NULL, open_response_cb, self);
g_object_unref (dialog);
}
static void
@@ -597,21 +588,22 @@ open_cb (GtkWidget *button,
}
static void
save_response_cb (GtkWidget *dialog,
int response,
NodeEditorWindow *self)
save_response_cb (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_widget_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
NodeEditorWindow *self = user_data;
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_save_finish (dialog, result, NULL);
if (file)
{
GFile *file;
char *text;
GError *error = NULL;
text = get_current_text (self->text_buffer);
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
g_file_replace_contents (file, text, strlen (text),
NULL, FALSE,
G_FILE_CREATE_NONE,
@@ -620,49 +612,40 @@ save_response_cb (GtkWidget *dialog,
&error);
if (error != NULL)
{
GtkWidget *message_dialog;
GtkAlertDialog *alert;
message_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))),
GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Saving failed");
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog),
"%s", error->message);
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (message_dialog);
alert = gtk_alert_dialog_new ("Saving failed");
gtk_alert_dialog_set_detail (alert, error->message);
gtk_alert_dialog_show (alert,
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (self))));
g_object_unref (alert);
g_error_free (error);
}
g_free (text);
g_object_unref (file);
}
gtk_window_destroy (GTK_WINDOW (dialog));
}
static void
save_cb (GtkWidget *button,
NodeEditorWindow *self)
{
GtkWidget *dialog;
GtkFileDialog *dialog;
GFile *cwd;
dialog = gtk_file_chooser_dialog_new ("Save node",
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
GTK_FILE_CHOOSER_ACTION_SAVE,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Save", GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
GFile *cwd = g_file_new_for_path (".");
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), cwd, NULL);
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Save node");
cwd = g_file_new_for_path (".");
gtk_file_dialog_set_current_folder (dialog, cwd);
g_object_unref (cwd);
g_signal_connect (dialog, "response", G_CALLBACK (save_response_cb), self);
gtk_widget_show (dialog);
gtk_file_dialog_save (dialog,
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
NULL,
"demo.node",
NULL,
save_response_cb, self);
g_object_unref (dialog);
}
static GdkTexture *
@@ -724,34 +707,29 @@ create_cairo_texture (NodeEditorWindow *self)
}
static void
export_image_response_cb (GtkWidget *dialog,
int response,
GdkTexture *texture)
export_image_response_cb (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_widget_hide (dialog);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GdkTexture *texture = user_data;
GFile *file;
if (response == GTK_RESPONSE_ACCEPT)
file = gtk_file_dialog_save_finish (dialog, result, NULL);
if (file)
{
GFile *file;
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
if (!gdk_texture_save_to_png (texture, g_file_peek_path (file)))
{
GtkWidget *message_dialog;
GtkAlertDialog *alert;
message_dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_window_get_transient_for (GTK_WINDOW (dialog))),
GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Exporting to image failed");
g_signal_connect (message_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (message_dialog);
alert = gtk_alert_dialog_new ("Exporting to image failed");
gtk_alert_dialog_show (alert, GTK_WINDOW (gtk_window_get_transient_for (GTK_WINDOW (dialog))));
g_object_unref (alert);
}
g_object_unref (file);
}
gtk_window_destroy (GTK_WINDOW (dialog));
g_object_unref (texture);
}
@@ -760,25 +738,24 @@ export_image_cb (GtkWidget *button,
NodeEditorWindow *self)
{
GdkTexture *texture;
GtkWidget *dialog;
GtkFileDialog *dialog;
texture = create_texture (self);
if (texture == NULL)
return;
dialog = gtk_file_chooser_dialog_new ("",
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
GTK_FILE_CHOOSER_ACTION_SAVE,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Save", GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
g_signal_connect (dialog, "response", G_CALLBACK (export_image_response_cb), texture);
gtk_widget_show (dialog);
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "");
gtk_file_dialog_save (dialog,
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (button))),
NULL,
"example.png",
NULL,
export_image_response_cb, texture);
g_object_unref (dialog);
}
static void
clip_image_cb (GtkWidget *button,
NodeEditorWindow *self)

View File

@@ -96,12 +96,10 @@ set_text (const char *text,
static void
load_file (GFile *open_filename)
{
GtkWidget *error_dialog;
char *contents;
GError *error;
gsize len;
error_dialog = NULL;
error = NULL;
g_file_load_contents (open_filename, NULL, &contents, &len, NULL, &error);
if (error == NULL)
@@ -117,36 +115,28 @@ load_file (GFile *open_filename)
{
GFileInfo *info = g_file_query_info (open_filename, "standard::display-name", 0, NULL, &error);
const char *display_name = g_file_info_get_display_name (info);
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error loading file %s:\n%s",
display_name,
"Not valid utf8");
g_object_unref (info);
}
GtkAlertDialog *alert;
alert = gtk_alert_dialog_new ("Error loading file %s", display_name);
gtk_alert_dialog_set_detail (alert, "Not valid utf8");
gtk_alert_dialog_show (alert, GTK_WINDOW (main_window));
g_object_unref (alert);
g_object_unref (info);
}
}
else
{
GFileInfo *info = g_file_query_info (open_filename, "standard::display-name", 0, NULL, &error);
const char *display_name = g_file_info_get_display_name (info);
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error loading file %s:\n%s",
display_name,
error->message);
GtkAlertDialog *alert;
alert = gtk_alert_dialog_new ("Error loading file %s", display_name);
gtk_alert_dialog_set_detail (alert, error->message);
gtk_alert_dialog_show (alert, GTK_WINDOW (main_window));
g_object_unref (alert);
g_object_unref (info);
g_error_free (error);
}
if (error_dialog)
{
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (error_dialog);
}
}
@@ -154,7 +144,6 @@ static void
save_file (GFile *save_filename)
{
char *text = get_text ();
GtkWidget *error_dialog;
GError *error;
error = NULL;
@@ -180,18 +169,12 @@ save_file (GFile *save_filename)
{
GFileInfo *info = g_file_query_info (save_filename, "standard::display-name", 0, NULL, NULL);
const char *display_name = g_file_info_get_display_name (info);
GtkAlertDialog *alert;
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error saving to file %s:\n%s",
display_name,
error->message);
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (error_dialog);
alert = gtk_alert_dialog_new ("Error saving to file %s", display_name);
gtk_alert_dialog_set_detail (alert, error->message);
gtk_alert_dialog_show (alert, GTK_WINDOW (main_window));
g_object_unref (alert);
g_error_free (error);
g_object_unref (info);
}
@@ -340,21 +323,24 @@ create_custom_widget (GtkPrintOperation *operation,
PrintData *data)
{
GtkWidget *vbox, *hbox, *font, *label;
GtkFontDialog *dialog;
PangoFontDescription *desc;
gtk_print_operation_set_custom_tab_label (operation, "Other");
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
gtk_box_append (GTK_BOX (vbox), hbox);
gtk_widget_show (hbox);
label = gtk_label_new ("Font:");
gtk_box_append (GTK_BOX (hbox), label);
gtk_widget_show (label);
font = gtk_font_button_new_with_font (data->font);
dialog = gtk_font_dialog_new ();
font = gtk_font_dialog_button_new (dialog);
desc = pango_font_description_from_string (data->font);
gtk_font_dialog_button_set_font_desc (GTK_FONT_DIALOG_BUTTON (font), desc);
pango_font_description_free (desc);
gtk_box_append (GTK_BOX (hbox), font);
gtk_widget_show (font);
data->font_button = font;
return vbox;
@@ -365,11 +351,12 @@ custom_widget_apply (GtkPrintOperation *operation,
GtkWidget *widget,
PrintData *data)
{
const char *selected_font;
selected_font = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (data->font_button));
PangoFontDescription *desc;
desc = gtk_font_dialog_button_get_font_desc (GTK_FONT_DIALOG_BUTTON (data->font_button));
g_free (data->font);
data->font = g_strdup (selected_font);
data->font = pango_font_description_to_string (desc);
}
static void
@@ -377,23 +364,18 @@ print_done (GtkPrintOperation *op,
GtkPrintOperationResult res,
PrintData *print_data)
{
GError *error = NULL;
if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
{
GtkWidget *error_dialog;
GtkAlertDialog *alert;
GError *error = NULL;
gtk_print_operation_get_error (op, &error);
error_dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error printing file:\n%s",
error ? error->message : "no details");
g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
gtk_widget_show (error_dialog);
alert = gtk_alert_dialog_new ("Error printing file");
if (error)
gtk_alert_dialog_set_detail (alert, error->message);
gtk_alert_dialog_show (alert, GTK_WINDOW (main_window));
g_object_unref (alert);
}
else if (res == GTK_PRINT_OPERATION_RESULT_APPLY)
{
@@ -499,17 +481,19 @@ activate_preview (GSimpleAction *action,
}
static void
on_save_response (GtkWidget *dialog,
int response)
on_save_response (GObject *source,
GAsyncResult *result,
void *user_data)
{
if (response == GTK_RESPONSE_OK)
{
GFile *save_filename = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
save_file (save_filename);
g_object_unref (save_filename);
}
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GFile *file;
gtk_window_destroy (GTK_WINDOW (dialog));
file = gtk_file_dialog_save_finish (dialog, result, NULL);
if (file)
{
save_file (file);
g_object_unref (file);
}
}
static void
@@ -517,21 +501,17 @@ activate_save_as (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkWidget *dialog;
GtkFileDialog *dialog;
dialog = gtk_file_chooser_dialog_new ("Select file",
GTK_WINDOW (main_window),
GTK_FILE_CHOOSER_ACTION_SAVE,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Save", GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_widget_show (dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (on_save_response),
NULL);
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Select file");
gtk_file_dialog_save (dialog,
GTK_WINDOW (main_window),
NULL,
NULL,
NULL,
on_save_response, NULL);
g_object_unref (dialog);
}
static void
@@ -546,17 +526,19 @@ activate_save (GSimpleAction *action,
}
static void
on_open_response (GtkWidget *dialog,
int response)
on_open_response (GObject *source,
GAsyncResult *result,
void *user_data)
{
if (response == GTK_RESPONSE_OK)
{
GFile *open_filename = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
load_file (open_filename);
g_object_unref (open_filename);
}
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GFile *file;
gtk_window_destroy (GTK_WINDOW (dialog));
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
load_file (file);
g_object_unref (file);
}
}
static void
@@ -564,21 +546,16 @@ activate_open (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkWidget *dialog;
GtkFileDialog *dialog;
dialog = gtk_file_chooser_dialog_new ("Select file",
GTK_WINDOW (main_window),
GTK_FILE_CHOOSER_ACTION_OPEN,
"_Cancel", GTK_RESPONSE_CANCEL,
"_Open", GTK_RESPONSE_OK,
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
gtk_widget_show (dialog);
g_signal_connect (dialog, "response",
G_CALLBACK (on_open_response),
NULL);
dialog = gtk_file_dialog_new ();
gtk_file_dialog_set_title (dialog, "Select file");
gtk_file_dialog_open (dialog,
GTK_WINDOW (main_window),
NULL,
NULL,
on_open_response, NULL);
g_object_unref (dialog);
}
static void

View File

@@ -214,10 +214,19 @@ activate_background (GSimpleAction *action,
}
static void
file_chooser_response (GtkNativeDialog *self,
int response)
file_chooser_response (GObject *source,
GAsyncResult *result,
void *user_data)
{
gtk_native_dialog_destroy (self);
GtkFileDialog *dialog = GTK_FILE_DIALOG (source);
GFile *file;
file = gtk_file_dialog_open_finish (dialog, result, NULL);
if (file)
{
g_print ("File selected: %s", g_file_peek_path (file));
g_object_unref (file);
}
}
static void
@@ -225,17 +234,11 @@ activate_open_file (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkFileChooserNative *chooser;
GtkFileDialog *dialog;
chooser = gtk_file_chooser_native_new ("Open file",
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
"Open",
"Cancel");
g_signal_connect (chooser, "response", G_CALLBACK (file_chooser_response), NULL);
gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser));
dialog = gtk_file_dialog_new ();
gtk_file_dialog_open (dialog, NULL, NULL, NULL, file_chooser_response, NULL);
g_object_unref (dialog);
}
static void
@@ -1093,7 +1096,9 @@ set_color (GtkListBox *box, GtkListBoxRow *row, GtkColorChooser *chooser)
if (gdk_rgba_parse (&rgba, color))
{
g_signal_handlers_block_by_func (chooser, rgba_changed, box);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_color_chooser_set_rgba (chooser, &rgba);
G_GNUC_END_IGNORE_DEPRECATIONS
g_signal_handlers_unblock_by_func (chooser, rgba_changed, box);
}
}
@@ -1462,7 +1467,9 @@ close_selection_dialog (GtkWidget *dialog, int response, GtkWidget *tv)
if (response == GTK_RESPONSE_CANCEL)
return;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
box = gtk_widget_get_first_child (gtk_dialog_get_content_area (GTK_DIALOG (dialog)));
G_GNUC_END_IGNORE_DEPRECATIONS
g_assert (GTK_IS_FLOW_BOX (box));
children = gtk_flow_box_get_selected_children (GTK_FLOW_BOX (box));

View File

@@ -8,8 +8,7 @@ are organized in a hierarchy. The window widget is the main container.
The user interface is then built by adding buttons, drop-down menus, input
fields, and other widgets to the window. If you are creating complex user
interfaces it is recommended to use GtkBuilder and its GTK-specific markup
description language, instead of assembling the interface manually. You can
also use a visual user interface editor, like [Glade](https://glade.gnome.org/).
description language, instead of assembling the interface manually.
GTK is event-driven. The toolkit listens for events such as a click
on a button, and passes the event to your application.
@@ -712,11 +711,20 @@ A common location to install UI descriptions and similar data is
`/usr/share/appname`.
It is also possible to embed the UI description in the source code as a
string and use [`method@Gtk.Builder.add_from_string`] to load it. But keeping the
UI description in a separate file has several advantages: It is then possible
to make minor adjustments to the UI without recompiling your program, and,
more importantly, graphical UI editors such as [Glade](http://glade.gnome.org)
can load the file and allow you to create and modify your UI by point-and-click.
string and use [`method@Gtk.Builder.add_from_string`] to load it. But keeping
the UI description in a separate file has several advantages:
- it is possible to make minor adjustments to the UI without recompiling your
program
- it is easier to isolate the UI code from the business logic of your
application
- it is easier to restructure your UI into separate classes using composite
widget templates
Using [GResource](https://docs.gtk.org/gio/struct.Resource.html) it is possible
to combine the best of both worlds: you can keep the UI definition files
separate inside your source code repository, and then ship them embedded into
your application.
## Building applications

View File

@@ -72,3 +72,28 @@ added.
GTK 5 will no longer provide this functionality. The recommendations
is to use a global stylesheet (i.e. gtk_style_context_add_provider_for_display())
and rely on style classes to make your CSS apply only where desired.
## Chooser interfaces are going away
The GtkColorChooser, GtkFontChooser, GtkFileChooser and GtkAppChooser
interfaces and their implementations as dialogs, buttons and widgets
are phased out. The are being replaced by a new family of async APIs
that will be more convenient to use from language bindings, in particular
for languages that have concepts like promises. The new APIs are
[class@Gtk.ColorDialog], [class@Gtk.FontDialog] and [class@Gtk.FileDialog],
There are also equivalents for some of the 'button' widgets:
[class@Gtk.ColorDialogButton], [class@Gtk.FontDialogButton].
## GtkMessageDialog is going away
Like the Chooser interfaces, GtkMessageDialog has been replaced by
a new async API that will be more convenient, in particular for
language binding. The new API is [class@Gtk.AlertDialog].
## GtkDialog is going away
After gtk_dialog_run() was removed, the usefulness of GtkDialog
is much reduced, and it has awkward, archaice APIs. Therefore,
it is dropped. The recommended replacement is to just create
your own window and add buttons as required, either in the header
or elsewhere.

View File

@@ -6,19 +6,11 @@ action_activated (GSimpleAction *action,
gpointer user_data)
{
GtkWindow *parent = user_data;
GtkWidget *dialog;
GtkAlertDialog *dialog;
dialog = gtk_message_dialog_new (parent,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"Activated action `%s`",
g_action_get_name (G_ACTION (action)));
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (gtk_window_destroy), dialog);
gtk_widget_show (dialog);
dialog = gtk_alert_dialog_new ("Activated action `%s`", g_action_get_name (G_ACTION (action)));
gtk_alert_dialog_show (dialog, NULL);
g_object_unref (dialog);
}
static GActionEntry doc_entries[] = {

View File

@@ -1,6 +1,8 @@
#include <stdlib.h>
#include <gtk/gtk.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct
{
GtkApplication parent_instance;

View File

@@ -29,7 +29,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gio/gio.h>
G_BEGIN_DECLS

View File

@@ -46,6 +46,8 @@
#include "gtkwidgetprivate.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkColorButton:
*
@@ -67,6 +69,8 @@
* `GtkColorButton` has a single CSS node with name colorbutton which
* contains a button node. To differentiate it from a plain `GtkButton`,
* it gets the .color style class.
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialogButton] instead
*/
typedef struct _GtkColorButtonClass GtkColorButtonClass;
@@ -353,6 +357,8 @@ gtk_color_button_finalize (GObject *object)
* color when the user finishes.
*
* Returns: a new color button
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialogButton] instead
*/
GtkWidget *
gtk_color_button_new (void)
@@ -561,6 +567,8 @@ set_use_alpha (GtkColorButton *button,
* @title: String containing new window title
*
* Sets the title for the color chooser dialog.
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialogButton] instead
*/
void
gtk_color_button_set_title (GtkColorButton *button,
@@ -587,6 +595,8 @@ gtk_color_button_set_title (GtkColorButton *button,
* Gets the title of the color chooser dialog.
*
* Returns: An internal string, do not free the return value
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialogButton] instead
*/
const char *
gtk_color_button_get_title (GtkColorButton *button)
@@ -602,6 +612,8 @@ gtk_color_button_get_title (GtkColorButton *button)
* @modal: %TRUE to make the dialog modal
*
* Sets whether the dialog should be modal.
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialogButton] instead
*/
void
gtk_color_button_set_modal (GtkColorButton *button,
@@ -627,6 +639,8 @@ gtk_color_button_set_modal (GtkColorButton *button,
* Gets whether the dialog is modal.
*
* Returns: %TRUE if the dialog is modal
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialogButton] instead
*/
gboolean
gtk_color_button_get_modal (GtkColorButton *button)

View File

@@ -48,19 +48,19 @@ typedef struct _GtkColorButton GtkColorButton;
GDK_AVAILABLE_IN_ALL
GType gtk_color_button_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_color_button_new (void);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_color_button_new_with_rgba (const GdkRGBA *rgba);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_color_button_set_title (GtkColorButton *button,
const char *title);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
const char *gtk_color_button_get_title (GtkColorButton *button);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_color_button_get_modal (GtkColorButton *button);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_color_button_set_modal (GtkColorButton *button,
gboolean modal);

View File

@@ -36,6 +36,9 @@
* In GTK, the main widgets that implement this interface are
* [class@Gtk.ColorChooserWidget], [class@Gtk.ColorChooserDialog] and
* [class@Gtk.ColorButton].
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] and [class@Gtk.ColorDialogButton]
* instead of widgets implementing `GtkColorChooser`
*/
enum
@@ -116,6 +119,8 @@ _gtk_color_chooser_color_activated (GtkColorChooser *chooser,
* @color: (out): a `GdkRGBA` to fill in with the current color
*
* Gets the currently-selected color.
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] instead
*/
void
gtk_color_chooser_get_rgba (GtkColorChooser *chooser,
@@ -132,6 +137,8 @@ gtk_color_chooser_get_rgba (GtkColorChooser *chooser,
* @color: the new color
*
* Sets the color.
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] instead
*/
void
gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
@@ -151,6 +158,8 @@ gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
*
* Returns: %TRUE if the color chooser uses the alpha channel,
* %FALSE if not
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] instead
*/
gboolean
gtk_color_chooser_get_use_alpha (GtkColorChooser *chooser)
@@ -170,6 +179,8 @@ gtk_color_chooser_get_use_alpha (GtkColorChooser *chooser)
* @use_alpha: %TRUE if color chooser should use alpha channel, %FALSE if not
*
* Sets whether or not the color chooser should use the alpha channel.
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] instead
*/
void
gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser,
@@ -207,6 +218,8 @@ gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser,
* of removing the default color palette from the color chooser.
*
* If @colors is %NULL, removes all previously added palettes.
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] instead
*/
void
gtk_color_chooser_add_palette (GtkColorChooser *chooser,

View File

@@ -63,20 +63,20 @@ struct _GtkColorChooserInterface
GDK_AVAILABLE_IN_ALL
GType gtk_color_chooser_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_color_chooser_get_rgba (GtkColorChooser *chooser,
GdkRGBA *color);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_color_chooser_set_rgba (GtkColorChooser *chooser,
const GdkRGBA *color);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_color_chooser_get_use_alpha (GtkColorChooser *chooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_color_chooser_set_use_alpha (GtkColorChooser *chooser,
gboolean use_alpha);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_color_chooser_add_palette (GtkColorChooser *chooser,
GtkOrientation orientation,
int colors_per_line,

View File

@@ -22,7 +22,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
G_BEGIN_DECLS
@@ -35,7 +35,7 @@ typedef struct _GtkColorChooserDialog GtkColorChooserDialog;
GDK_AVAILABLE_IN_ALL
GType gtk_color_chooser_dialog_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_color_chooser_dialog_new (const char *title,
GtkWindow *parent);

View File

@@ -35,7 +35,7 @@ typedef struct _GtkColorChooserWidget GtkColorChooserWidget;
GDK_AVAILABLE_IN_ALL
GType gtk_color_chooser_widget_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_color_chooser_widget_new (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkColorChooserWidget, g_object_unref)

View File

@@ -43,6 +43,8 @@
#include "gtktypebuiltins.h"
#include "gtksizegroup.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkDialog:
*

View File

@@ -127,51 +127,51 @@ struct _GtkDialogClass
GDK_AVAILABLE_IN_ALL
GType gtk_dialog_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_new (void);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_new_with_buttons (const char *title,
GtkWindow *parent,
GtkDialogFlags flags,
const char *first_button_text,
...) G_GNUC_NULL_TERMINATED;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_add_action_widget (GtkDialog *dialog,
GtkWidget *child,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_add_button (GtkDialog *dialog,
const char *button_text,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_add_buttons (GtkDialog *dialog,
const char *first_button_text,
...) G_GNUC_NULL_TERMINATED;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_set_response_sensitive (GtkDialog *dialog,
int response_id,
gboolean setting);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_set_default_response (GtkDialog *dialog,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_dialog_get_widget_for_response (GtkDialog *dialog,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
int gtk_dialog_get_response_for_widget (GtkDialog *dialog,
GtkWidget *widget);
/* Emit response signal */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_dialog_response (GtkDialog *dialog,
int response_id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_dialog_get_content_area (GtkDialog *dialog);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget * gtk_dialog_get_header_bar (GtkDialog *dialog);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkDialog, g_object_unref)

View File

@@ -24,6 +24,8 @@
#include "gtkmarshalers.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkFileChooser:
*
@@ -67,6 +69,8 @@
* options. If a choice has no option, it will be rendered as a
* check button with the given label; if a choice has options, it will
* be rendered as a combo box.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
@@ -173,6 +177,8 @@ gtk_file_chooser_error_quark (void)
* For example, an option to create a new folder might be shown
* if the action is %GTK_FILE_CHOOSER_ACTION_SAVE but not if the
* action is %GTK_FILE_CHOOSER_ACTION_OPEN.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
**/
void
gtk_file_chooser_set_action (GtkFileChooser *chooser,
@@ -190,6 +196,8 @@ gtk_file_chooser_set_action (GtkFileChooser *chooser,
* Gets the type of operation that the file chooser is performing.
*
* Returns: the action that the file selector is performing
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GtkFileChooserAction
gtk_file_chooser_get_action (GtkFileChooser *chooser)
@@ -213,6 +221,8 @@ gtk_file_chooser_get_action (GtkFileChooser *chooser)
* This is only relevant if the action is set to be
* %GTK_FILE_CHOOSER_ACTION_OPEN or
* %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
@@ -231,6 +241,8 @@ gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
* chooser.
*
* Returns: %TRUE if multiple files can be selected.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
gboolean
gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
@@ -253,6 +265,8 @@ gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser)
*
* This is only relevant if the action is not set to be
* %GTK_FILE_CHOOSER_ACTION_OPEN.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_set_create_folders (GtkFileChooser *chooser,
@@ -270,6 +284,8 @@ gtk_file_chooser_set_create_folders (GtkFileChooser *chooser,
* Gets whether file chooser will offer to create new folders.
*
* Returns: %TRUE if the Create Folder button should be displayed.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
gboolean
gtk_file_chooser_get_create_folders (GtkFileChooser *chooser)
@@ -301,6 +317,8 @@ gtk_file_chooser_get_create_folders (GtkFileChooser *chooser)
*
* Please see the documentation for those functions for an example
* of using [method@Gtk.FileChooser.set_current_name] as well.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
**/
void
gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
@@ -326,6 +344,8 @@ gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
* whatever the contents of the entry are. Note also that this string is
* in UTF-8 encoding, which is not necessarily the systems encoding for
* filenames.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
char *
gtk_file_chooser_get_current_name (GtkFileChooser *chooser)
@@ -362,6 +382,8 @@ gtk_file_chooser_unselect_all (GtkFileChooser *chooser)
*
* Returns: %TRUE if the folder could be changed successfully, %FALSE
* otherwise.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
gboolean
gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
@@ -382,6 +404,8 @@ gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
* Gets the current folder of @chooser as `GFile`.
*
* Returns: (transfer full) (nullable): the `GFile` for the current folder.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GFile *
gtk_file_chooser_get_current_folder (GtkFileChooser *chooser)
@@ -423,6 +447,8 @@ gtk_file_chooser_unselect_file (GtkFileChooser *chooser,
* Returns: (transfer full): a list model containing a `GFile` for each
* selected file and subfolder in the current folder. Free the returned
* list with g_object_unref().
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GListModel *
gtk_file_chooser_get_files (GtkFileChooser *chooser)
@@ -482,6 +508,8 @@ gtk_file_chooser_get_files (GtkFileChooser *chooser)
* ```
*
* Returns: Not useful
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
gboolean
gtk_file_chooser_set_file (GtkFileChooser *chooser,
@@ -511,6 +539,8 @@ gtk_file_chooser_set_file (GtkFileChooser *chooser,
*
* Returns: (transfer full) (nullable): a selected `GFile`. You own the
* returned file; use g_object_unref() to release it.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GFile *
gtk_file_chooser_get_file (GtkFileChooser *chooser)
@@ -539,6 +569,8 @@ gtk_file_chooser_get_file (GtkFileChooser *chooser)
*
* Returns: %TRUE if the folder could be added successfully,
* %FALSE otherwise.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
gboolean
gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
@@ -561,6 +593,8 @@ gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
*
* Returns: %TRUE if the folder could be removed successfully,
* %FALSE otherwise.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
gboolean
gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
@@ -601,6 +635,8 @@ gtk_file_chooser_add_filter (GtkFileChooser *chooser,
* @filter: a `GtkFileFilter`
*
* Removes @filter from the list of filters that the user can select between.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
@@ -648,6 +684,8 @@ gtk_file_chooser_get_filters (GtkFileChooser *chooser)
* Setting the current filter when the list of filters is
* empty is useful if you want to restrict the displayed
* set of files without letting the user change it.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_set_filter (GtkFileChooser *chooser,
@@ -666,6 +704,8 @@ gtk_file_chooser_set_filter (GtkFileChooser *chooser,
* Gets the current filter.
*
* Returns: (nullable) (transfer none): the current filter
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GtkFileFilter *
gtk_file_chooser_get_filter (GtkFileChooser *chooser)
@@ -695,6 +735,8 @@ gtk_file_chooser_get_filter (GtkFileChooser *chooser)
* @chooser may or may not affect the returned model.
*
* Returns: (transfer full): A list model of `GFile`s
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GListModel *
gtk_file_chooser_get_shortcut_folders (GtkFileChooser *chooser)
@@ -720,6 +762,8 @@ gtk_file_chooser_get_shortcut_folders (GtkFileChooser *chooser)
* and you can obtain the user-selected value in the
* [signal@Gtk.Dialog::response] signal handler using
* [method@Gtk.FileChooser.get_choice].
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_add_choice (GtkFileChooser *chooser,
@@ -740,6 +784,8 @@ gtk_file_chooser_add_choice (GtkFileChooser *chooser,
* @id: the ID of the choice to remove
*
* Removes a 'choice' that has been added with gtk_file_chooser_add_choice().
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_remove_choice (GtkFileChooser *chooser,
@@ -761,6 +807,8 @@ gtk_file_chooser_remove_choice (GtkFileChooser *chooser,
* gtk_file_chooser_add_choice().
*
* For a boolean choice, the possible options are "true" and "false".
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_set_choice (GtkFileChooser *chooser,
@@ -781,6 +829,8 @@ gtk_file_chooser_set_choice (GtkFileChooser *chooser,
* Gets the currently selected option in the 'choice' with the given ID.
*
* Returns: (nullable): the ID of the currently selected option
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
const char *
gtk_file_chooser_get_choice (GtkFileChooser *chooser,

View File

@@ -85,101 +85,101 @@ typedef enum {
GTK_FILE_CHOOSER_ERROR_INCOMPLETE_HOSTNAME
} GtkFileChooserError;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GQuark gtk_file_chooser_error_quark (void);
/* Configuration */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_set_action (GtkFileChooser *chooser,
GtkFileChooserAction action);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkFileChooserAction gtk_file_chooser_get_action (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_set_select_multiple (GtkFileChooser *chooser,
gboolean select_multiple);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_file_chooser_get_select_multiple (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_set_create_folders (GtkFileChooser *chooser,
gboolean create_folders);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_file_chooser_get_create_folders (GtkFileChooser *chooser);
/* Suggested name for the Save-type actions */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_set_current_name (GtkFileChooser *chooser,
const char *name);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
char * gtk_file_chooser_get_current_name (GtkFileChooser *chooser);
/* GFile manipulation */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GFile * gtk_file_chooser_get_file (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_file_chooser_set_file (GtkFileChooser *chooser,
GFile *file,
GError **error);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GListModel * gtk_file_chooser_get_files (GtkFileChooser *chooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_file_chooser_set_current_folder (GtkFileChooser *chooser,
GFile *file,
GError **error);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GFile * gtk_file_chooser_get_current_folder (GtkFileChooser *chooser);
/* List of user selectable filters */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_add_filter (GtkFileChooser *chooser,
GtkFileFilter *filter);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_remove_filter (GtkFileChooser *chooser,
GtkFileFilter *filter);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GListModel * gtk_file_chooser_get_filters (GtkFileChooser *chooser);
/* Current filter */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_set_filter (GtkFileChooser *chooser,
GtkFileFilter *filter);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkFileFilter * gtk_file_chooser_get_filter (GtkFileChooser *chooser);
/* Per-application shortcut folders */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
GFile *folder,
GError **error);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_file_chooser_remove_shortcut_folder
(GtkFileChooser *chooser,
GFile *folder,
GError **error);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GListModel * gtk_file_chooser_get_shortcut_folders (GtkFileChooser *chooser);
/* Custom widgets */
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_add_choice (GtkFileChooser *chooser,
const char *id,
const char *label,
const char **options,
const char **option_labels);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_remove_choice (GtkFileChooser *chooser,
const char *id);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_set_choice (GtkFileChooser *chooser,
const char *id,
const char *option);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
const char * gtk_file_chooser_get_choice (GtkFileChooser *chooser,
const char *id);

View File

@@ -23,8 +23,8 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/gtkfilechooser.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gtk/deprecated/gtkfilechooser.h>
G_BEGIN_DECLS
@@ -36,7 +36,7 @@ typedef struct _GtkFileChooserDialog GtkFileChooserDialog;
GDK_AVAILABLE_IN_ALL
GType gtk_file_chooser_dialog_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget *gtk_file_chooser_dialog_new (const char *title,
GtkWindow *parent,
GtkFileChooserAction action,

View File

@@ -23,7 +23,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkfilechooser.h>
#include <gtk/deprecated/gtkfilechooser.h>
#include <gtk/gtknativedialog.h>
G_BEGIN_DECLS
@@ -33,21 +33,21 @@ G_BEGIN_DECLS
GDK_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (GtkFileChooserNative, gtk_file_chooser_native, GTK, FILE_CHOOSER_NATIVE, GtkNativeDialog)
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkFileChooserNative *gtk_file_chooser_native_new (const char *title,
GtkWindow *parent,
GtkFileChooserAction action,
const char *accept_label,
const char *cancel_label);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
const char *gtk_file_chooser_native_get_accept_label (GtkFileChooserNative *self);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_native_set_accept_label (GtkFileChooserNative *self,
const char *accept_label);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
const char *gtk_file_chooser_native_get_cancel_label (GtkFileChooserNative *self);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_file_chooser_native_set_cancel_label (GtkFileChooserNative *self,
const char *cancel_label);

View File

@@ -23,7 +23,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkfilechooser.h>
#include <gtk/deprecated/gtkfilechooser.h>
#include <gtk/gtkbox.h>
G_BEGIN_DECLS
@@ -36,7 +36,7 @@ typedef struct _GtkFileChooserWidget GtkFileChooserWidget;
GDK_AVAILABLE_IN_ALL
GType gtk_file_chooser_widget_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget *gtk_file_chooser_widget_new (GtkFileChooserAction action);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFileChooserWidget, g_object_unref)

View File

@@ -45,6 +45,8 @@
#include <stdio.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkFontButton:
*
@@ -65,6 +67,8 @@
*
* `GtkFontButton` has a single CSS node with name fontbutton which
* contains a button node with the .font style class.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
typedef struct _GtkFontButtonClass GtkFontButtonClass;
@@ -744,6 +748,8 @@ gtk_font_button_get_property (GObject *object,
* Creates a new font picker widget.
*
* Returns: a new font picker widget.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
GtkWidget *
gtk_font_button_new (void)
@@ -758,6 +764,8 @@ gtk_font_button_new (void)
* Creates a new font picker widget showing the given font.
*
* Returns: a new font picker widget.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
GtkWidget *
gtk_font_button_new_with_font (const char *fontname)
@@ -771,6 +779,8 @@ gtk_font_button_new_with_font (const char *fontname)
* @title: a string containing the font chooser dialog title
*
* Sets the title for the font chooser dialog.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
void
gtk_font_button_set_title (GtkFontButton *font_button,
@@ -797,6 +807,8 @@ gtk_font_button_set_title (GtkFontButton *font_button,
*
* Returns: an internal copy of the title string
* which must not be freed.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
const char *
gtk_font_button_get_title (GtkFontButton *font_button)
@@ -812,6 +824,8 @@ gtk_font_button_get_title (GtkFontButton *font_button)
* @modal: %TRUE to make the dialog modal
*
* Sets whether the dialog should be modal.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
void
gtk_font_button_set_modal (GtkFontButton *font_button,
@@ -837,6 +851,8 @@ gtk_font_button_set_modal (GtkFontButton *font_button,
* Gets whether the dialog is modal.
*
* Returns: %TRUE if the dialog is modal
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
gboolean
gtk_font_button_get_modal (GtkFontButton *font_button)
@@ -853,6 +869,8 @@ gtk_font_button_get_modal (GtkFontButton *font_button)
* Returns whether the selected font is used in the label.
*
* Returns: whether the selected font is used in the label.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
gboolean
gtk_font_button_get_use_font (GtkFontButton *font_button)
@@ -869,6 +887,8 @@ gtk_font_button_get_use_font (GtkFontButton *font_button)
*
* If @use_font is %TRUE, the font name will be written
* using the selected font.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
void
gtk_font_button_set_use_font (GtkFontButton *font_button,
@@ -896,6 +916,8 @@ gtk_font_button_set_use_font (GtkFontButton *font_button,
* Returns whether the selected size is used in the label.
*
* Returns: whether the selected size is used in the label.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
gboolean
gtk_font_button_get_use_size (GtkFontButton *font_button)
@@ -913,6 +935,8 @@ gtk_font_button_get_use_size (GtkFontButton *font_button)
*
* If @use_size is %TRUE, the font name will be written using
* the selected size.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialogButton] instead
*/
void
gtk_font_button_set_use_size (GtkFontButton *font_button,

View File

@@ -43,29 +43,29 @@ typedef struct _GtkFontButton GtkFontButton;
GDK_AVAILABLE_IN_ALL
GType gtk_font_button_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget *gtk_font_button_new (void);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget *gtk_font_button_new_with_font (const char *fontname);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
const char * gtk_font_button_get_title (GtkFontButton *font_button);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_button_set_title (GtkFontButton *font_button,
const char *title);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_font_button_get_modal (GtkFontButton *font_button);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_button_set_modal (GtkFontButton *font_button,
gboolean modal);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_font_button_get_use_font (GtkFontButton *font_button);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_button_set_use_font (GtkFontButton *font_button,
gboolean use_font);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_font_button_get_use_size (GtkFontButton *font_button);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_button_set_use_size (GtkFontButton *font_button,
gboolean use_size);

View File

@@ -25,6 +25,8 @@
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkFontChooser:
*
@@ -34,6 +36,9 @@
* In GTK, the main objects that implement this interface are
* [class@Gtk.FontChooserWidget], [class@Gtk.FontChooserDialog] and
* [class@Gtk.FontButton].
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
enum
@@ -167,6 +172,9 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
*
* Returns: (nullable) (transfer none): A `PangoFontFamily` representing the
* selected font family
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
PangoFontFamily *
gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser)
@@ -187,6 +195,9 @@ gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser)
*
* Returns: (nullable) (transfer none): A `PangoFontFace` representing the
* selected font group details
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
PangoFontFace *
gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser)
@@ -204,6 +215,9 @@ gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser)
*
* Returns: A n integer representing the selected font size,
* or -1 if no font size is selected.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
int
gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser)
@@ -230,6 +244,9 @@ gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser)
*
* Returns: (nullable) (transfer full): A string with the name
* of the current font
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
char *
gtk_font_chooser_get_font (GtkFontChooser *fontchooser)
@@ -250,6 +267,9 @@ gtk_font_chooser_get_font (GtkFontChooser *fontchooser)
* @fontname: a font name like Helvetica 12 or Times Bold 18
*
* Sets the currently-selected font.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
@@ -278,6 +298,9 @@ gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
*
* Returns: (nullable) (transfer full): A `PangoFontDescription` for the
* current font
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
PangoFontDescription *
gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser)
@@ -297,6 +320,9 @@ gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser)
* @font_desc: a `PangoFontDescription`
*
* Sets the currently-selected font from @font_desc.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser,
@@ -315,6 +341,9 @@ gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser,
* Gets the text displayed in the preview area.
*
* Returns: (transfer full): the text displayed in the preview area
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
char *
gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser)
@@ -336,6 +365,9 @@ gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser)
* Sets the text displayed in the preview area.
*
* The @text is used to show how the selected font looks.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser,
@@ -354,6 +386,9 @@ gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser,
* Returns whether the preview entry is shown or not.
*
* Returns: %TRUE if the preview entry is shown or %FALSE if it is hidden.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
gboolean
gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser)
@@ -373,6 +408,9 @@ gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser)
* @show_preview_entry: whether to show the editable preview entry or not
*
* Shows or hides the editable preview entry.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser,
@@ -393,6 +431,9 @@ gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser,
*
* Adds a filter function that decides which fonts to display
* in the font chooser.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser,
@@ -447,6 +488,9 @@ _gtk_font_chooser_font_activated (GtkFontChooser *chooser,
* context = gtk_widget_get_pango_context (label);
* pango_context_set_font_map (context, fontmap);
* ```
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser,
@@ -467,6 +511,9 @@ gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser,
* or %NULL if it does not have one.
*
* Returns: (nullable) (transfer full): a `PangoFontMap`
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
PangoFontMap *
gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser)
@@ -487,6 +534,9 @@ gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser)
* @level: the desired level of granularity
*
* Sets the desired level of granularity for selecting fonts.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_level (GtkFontChooser *fontchooser,
@@ -504,6 +554,9 @@ gtk_font_chooser_set_level (GtkFontChooser *fontchooser,
* Returns the current level of granularity for selecting fonts.
*
* Returns: the current granularity level
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
GtkFontChooserLevel
gtk_font_chooser_get_level (GtkFontChooser *fontchooser)
@@ -528,6 +581,9 @@ gtk_font_chooser_get_level (GtkFontChooser *fontchooser)
* It can be passed to [func@Pango.AttrFontFeatures.new].
*
* Returns: the currently selected font features
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
char *
gtk_font_chooser_get_font_features (GtkFontChooser *fontchooser)
@@ -548,6 +604,9 @@ gtk_font_chooser_get_font_features (GtkFontChooser *fontchooser)
* Gets the language that is used for font features.
*
* Returns: the currently selected language
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
char *
gtk_font_chooser_get_language (GtkFontChooser *fontchooser)
@@ -567,6 +626,9 @@ gtk_font_chooser_get_language (GtkFontChooser *fontchooser)
* @language: a language
*
* Sets the language to use for font features.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] and [class@GtkFontDialogButton]
* instead
*/
void
gtk_font_chooser_set_language (GtkFontChooser *fontchooser,

View File

@@ -107,57 +107,57 @@ struct _GtkFontChooserIface
GDK_AVAILABLE_IN_ALL
GType gtk_font_chooser_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
PangoFontFamily *gtk_font_chooser_get_font_family (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
PangoFontFace *gtk_font_chooser_get_font_face (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
int gtk_font_chooser_get_font_size (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
PangoFontDescription *
gtk_font_chooser_get_font_desc (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_font_desc (GtkFontChooser *fontchooser,
const PangoFontDescription *font_desc);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
char * gtk_font_chooser_get_font (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
const char *fontname);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
char * gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser,
const char *text);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
gboolean gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser,
gboolean show_preview_entry);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser,
GtkFontFilterFunc filter,
gpointer user_data,
GDestroyNotify destroy);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser,
PangoFontMap *fontmap);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
PangoFontMap * gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_level (GtkFontChooser *fontchooser,
GtkFontChooserLevel level);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkFontChooserLevel
gtk_font_chooser_get_level (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
char * gtk_font_chooser_get_font_features (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
char * gtk_font_chooser_get_language (GtkFontChooser *fontchooser);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_font_chooser_set_language (GtkFontChooser *fontchooser,
const char *language);

View File

@@ -22,7 +22,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
G_BEGIN_DECLS
@@ -34,7 +34,7 @@ typedef struct _GtkFontChooserDialog GtkFontChooserDialog;
GDK_AVAILABLE_IN_ALL
GType gtk_font_chooser_dialog_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_font_chooser_dialog_new (const char *title,
GtkWindow *parent);

View File

@@ -35,7 +35,7 @@ typedef struct _GtkFontChooserWidget GtkFontChooserWidget;
GDK_AVAILABLE_IN_ALL
GType gtk_font_chooser_widget_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_font_chooser_widget_new (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooserWidget, g_object_unref)

View File

@@ -29,7 +29,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gtk/gtkenums.h>
G_BEGIN_DECLS
@@ -78,7 +78,7 @@ typedef enum
GDK_AVAILABLE_IN_ALL
GType gtk_message_dialog_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_message_dialog_new (GtkWindow *parent,
GtkDialogFlags flags,
GtkMessageType type,
@@ -86,7 +86,7 @@ GtkWidget* gtk_message_dialog_new (GtkWindow *parent,
const char *message_format,
...) G_GNUC_PRINTF (5, 6);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget* gtk_message_dialog_new_with_markup (GtkWindow *parent,
GtkDialogFlags flags,
GtkMessageType type,
@@ -94,21 +94,21 @@ GtkWidget* gtk_message_dialog_new_with_markup (GtkWindow *parent,
const char *message_format,
...) G_GNUC_PRINTF (5, 6);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
const char *str);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
const char *message_format,
...) G_GNUC_PRINTF (2, 3);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
void gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
const char *message_format,
...) G_GNUC_PRINTF (2, 3);
GDK_AVAILABLE_IN_ALL
GDK_DEPRECATED_IN_4_10
GtkWidget *gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMessageDialog, g_object_unref)

View File

@@ -268,6 +268,7 @@ gtk_tree_popover_init (GtkTreePopover *popover)
sw = gtk_scrolled_window_new ();
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_popover_set_child (GTK_POPOVER (popover), sw);

View File

@@ -19,9 +19,15 @@ gtk_deprecated_sources = [
'deprecated/gtkcellrenderertext.c',
'deprecated/gtkcellrenderertoggle.c',
'deprecated/gtkcellview.c',
'deprecated/gtkcolorbutton.c',
'deprecated/gtkcolorchooser.c',
'deprecated/gtkcombobox.c',
'deprecated/gtkcomboboxtext.c',
'deprecated/gtkdialog.c',
'deprecated/gtkentrycompletion.c',
'deprecated/gtkfilechooser.c',
'deprecated/gtkfontbutton.c',
'deprecated/gtkfontchooser.c',
'deprecated/gtkiconview.c',
'deprecated/gtkliststore.c',
'deprecated/gtkrender.c',
@@ -60,11 +66,25 @@ gtk_deprecated_headers = [
'deprecated/gtkcellrenderertext.h',
'deprecated/gtkcellrenderertoggle.h',
'deprecated/gtkcellview.h',
'deprecated/gtkcolorbutton.h',
'deprecated/gtkcolorchooser.h',
'deprecated/gtkcolorchooserdialog.h',
'deprecated/gtkcolorchooserwidget.h',
'deprecated/gtkcombobox.h',
'deprecated/gtkcomboboxtext.h',
'deprecated/gtkdialog.h',
'deprecated/gtkentrycompletion.h',
'deprecated/gtkfilechooser.h',
'deprecated/gtkfilechooserdialog.h',
'deprecated/gtkfilechoosernative.h',
'deprecated/gtkfilechooserwidget.h',
'deprecated/gtkfontbutton.h',
'deprecated/gtkfontchooser.h',
'deprecated/gtkfontchooserdialog.h',
'deprecated/gtkfontchooserwidget.h',
'deprecated/gtkiconview.h',
'deprecated/gtkliststore.h',
'deprecated/gtkmessagedialog.h',
'deprecated/gtkrender.h',
'deprecated/gtkstylecontext.h',
'deprecated/gtktreednd.h',

View File

@@ -38,6 +38,7 @@
#include <gtk/gtkactionable.h>
#include <gtk/gtkactionbar.h>
#include <gtk/gtkadjustment.h>
#include <gtk/gtkalertdialog.h>
#include <gtk/deprecated/gtkappchooser.h>
#include <gtk/deprecated/gtkappchooserdialog.h>
#include <gtk/deprecated/gtkappchooserwidget.h>
@@ -78,10 +79,12 @@
#include <gtk/gtkcenterbox.h>
#include <gtk/gtkcenterlayout.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkcolorbutton.h>
#include <gtk/gtkcolorchooser.h>
#include <gtk/gtkcolorchooserdialog.h>
#include <gtk/gtkcolorchooserwidget.h>
#include <gtk/deprecated/gtkcolorbutton.h>
#include <gtk/deprecated/gtkcolorchooser.h>
#include <gtk/deprecated/gtkcolorchooserdialog.h>
#include <gtk/deprecated/gtkcolorchooserwidget.h>
#include <gtk/gtkcolordialog.h>
#include <gtk/gtkcolordialogbutton.h>
#include <gtk/gtkcolorutils.h>
#include <gtk/gtkcolumnview.h>
#include <gtk/gtkcolumnviewcolumn.h>
@@ -94,7 +97,8 @@
#include <gtk/gtkcustomlayout.h>
#include <gtk/gtkcustomsorter.h>
#include <gtk/gtkdebug.h>
#include <gtk/gtkdialog.h>
#include <gtk/deprecated/gtkdialog.h>
#include <gtk/gtkdialogerror.h>
#include <gtk/gtkdirectorylist.h>
#include <gtk/gtkdragicon.h>
#include <gtk/gtkdragsource.h>
@@ -120,20 +124,23 @@
#include <gtk/gtkexpression.h>
#include <gtk/gtkfixed.h>
#include <gtk/gtkfixedlayout.h>
#include <gtk/gtkfilechooser.h>
#include <gtk/gtkfilechooserdialog.h>
#include <gtk/gtkfilechoosernative.h>
#include <gtk/gtkfilechooserwidget.h>
#include <gtk/deprecated/gtkfilechooser.h>
#include <gtk/deprecated/gtkfilechooserdialog.h>
#include <gtk/deprecated/gtkfilechoosernative.h>
#include <gtk/deprecated/gtkfilechooserwidget.h>
#include <gtk/gtkfiledialog.h>
#include <gtk/gtkfilefilter.h>
#include <gtk/gtkfilter.h>
#include <gtk/gtkfilterlistmodel.h>
#include <gtk/gtkcustomfilter.h>
#include <gtk/gtkflattenlistmodel.h>
#include <gtk/gtkflowbox.h>
#include <gtk/gtkfontbutton.h>
#include <gtk/gtkfontchooser.h>
#include <gtk/gtkfontchooserdialog.h>
#include <gtk/gtkfontchooserwidget.h>
#include <gtk/deprecated/gtkfontbutton.h>
#include <gtk/deprecated/gtkfontchooser.h>
#include <gtk/deprecated/gtkfontchooserdialog.h>
#include <gtk/deprecated/gtkfontchooserwidget.h>
#include <gtk/gtkfontdialog.h>
#include <gtk/gtkfontdialogbutton.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkgesture.h>
#include <gtk/gtkgestureclick.h>
@@ -176,7 +183,7 @@
#include <gtk/gtkmediafile.h>
#include <gtk/gtkmediastream.h>
#include <gtk/gtkmenubutton.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/deprecated/gtkmessagedialog.h>
#include <gtk/gtkmountoperation.h>
#include <gtk/gtkmultifilter.h>
#include <gtk/gtkmultiselection.h>

772
gtk/gtkalertdialog.c Normal file
View File

@@ -0,0 +1,772 @@
/*
* GTK - The GIMP Toolkit
* Copyright (C) 2022 Red Hat, Inc.
* All rights reserved.
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkalertdialog.h"
#include "gtkbutton.h"
#include "gtkmessagewindowprivate.h"
#include <glib/gi18n-lib.h>
/**
* GtkAlertDialog:
*
* A `GtkAlertDialog` object collects the arguments that
* are needed to present a message to the user.
*
* The message is shown with the [method@Gtk.AlertDialog.choose]
* function. This API follows the GIO async pattern, and the result can
* be obtained by calling [method@Gtk.AlertDialog.choose_finish].
*
* If you don't need to wait for a button to be clicked, you can use
* [method@Gtk.AlertDialog.show].
*
* `GtkAlertDialog was added in GTK 4.10.
*/
/* {{{ GObject implementation */
struct _GtkAlertDialog
{
GObject parent_instance;
char *message;
char *detail;
char **buttons;
int cancel_button;
int default_button;
int cancel_return;
unsigned int modal : 1;
};
enum
{
PROP_MODAL = 1,
PROP_MESSAGE,
PROP_DETAIL,
PROP_BUTTONS,
PROP_CANCEL_BUTTON,
PROP_DEFAULT_BUTTON,
NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES];
G_DEFINE_TYPE (GtkAlertDialog, gtk_alert_dialog, G_TYPE_OBJECT)
static void
gtk_alert_dialog_init (GtkAlertDialog *self)
{
self->modal = TRUE;
self->cancel_button = -1;
self->default_button = -1;
}
static void
gtk_alert_dialog_finalize (GObject *object)
{
GtkAlertDialog *self = GTK_ALERT_DIALOG (object);
g_free (self->message);
g_free (self->detail);
g_strfreev (self->buttons);
G_OBJECT_CLASS (gtk_alert_dialog_parent_class)->finalize (object);
}
static void
gtk_alert_dialog_get_property (GObject *object,
unsigned int property_id,
GValue *value,
GParamSpec *pspec)
{
GtkAlertDialog *self = GTK_ALERT_DIALOG (object);
switch (property_id)
{
case PROP_MODAL:
g_value_set_boolean (value, self->modal);
break;
case PROP_MESSAGE:
g_value_set_string (value, self->message);
break;
case PROP_DETAIL:
g_value_set_string (value, self->detail);
break;
case PROP_BUTTONS:
g_value_set_boxed (value, self->buttons);
break;
case PROP_CANCEL_BUTTON:
g_value_set_int (value, self->cancel_button);
break;
case PROP_DEFAULT_BUTTON:
g_value_set_int (value, self->default_button);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_alert_dialog_set_property (GObject *object,
unsigned int prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkAlertDialog *self = GTK_ALERT_DIALOG (object);
switch (prop_id)
{
case PROP_MODAL:
gtk_alert_dialog_set_modal (self, g_value_get_boolean (value));
break;
case PROP_MESSAGE:
gtk_alert_dialog_set_message (self, g_value_get_string (value));
break;
case PROP_DETAIL:
gtk_alert_dialog_set_detail (self, g_value_get_string (value));
break;
case PROP_BUTTONS:
gtk_alert_dialog_set_buttons (self, g_value_get_boxed (value));
break;
case PROP_CANCEL_BUTTON:
gtk_alert_dialog_set_cancel_button (self, g_value_get_int (value));
break;
case PROP_DEFAULT_BUTTON:
gtk_alert_dialog_set_default_button (self, g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_alert_dialog_class_init (GtkAlertDialogClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = gtk_alert_dialog_finalize;
object_class->get_property = gtk_alert_dialog_get_property;
object_class->set_property = gtk_alert_dialog_set_property;
/**
* GtkAlertDialog:modal: (attributes org.gtk.Property.get=gtk_alert_dialog_get_modal org.gtk.Property.set=gtk_alert_dialog_set_modal)
*
* Whether the alert is modal.
*
* Since: 4.10
*/
properties[PROP_MODAL] =
g_param_spec_boolean ("modal", NULL, NULL,
TRUE,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkAlertDialog:message: (attributes org.gtk.Property.get=gtk_alert_dialog_get_message org.gtk.Property.set=gtk_alert_dialog_set_message)
*
* The message for the alert.
*
* Since: 4.10
*/
properties[PROP_MESSAGE] =
g_param_spec_string ("message", NULL, NULL,
NULL,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkAlertDialog:detail: (attributes org.gtk.Property.get=gtk_alert_dialog_get_detail org.gtk.Property.set=gtk_alert_dialog_set_detail)
*
* The detail text for the alert.
*
* Since: 4.10
*/
properties[PROP_DETAIL] =
g_param_spec_string ("detail", NULL, NULL,
NULL,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkAlertDialog:buttons: (attributes org.gtk.Property.get=gtk_alert_dialog_get_buttons org.gtk.Property.set=gtk_alert_dialog_set_buttons)
*
* Labels for buttons to show in the alert.
*
* The labels should be translated and may contain
* a _ to indicate the mnemonic character.
*
* If this property is not set, then a 'Close' button is
* automatically created.
*
* Since: 4.10
*/
properties[PROP_BUTTONS] =
g_param_spec_boxed ("buttons", NULL, NULL,
G_TYPE_STRV,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkAlertDialog:cancel-button: (attributes org.gtk.Property.get=gtk_alert_dialog_get_cancel_button org.gtk.Property.set=gtk_alert_dialog_set_cancel_button)
*
* This property determines what happens when the Escape key is
* pressed while the alert is shown.
*
* If this property holds the index of a button in [property@Gtk.AlertDialog:buttons],
* then pressing Escape is treated as if that button was pressed. If it is -1
* or not a valid index for the `buttons` array, then an error is returned.
*
* If `buttons` is `NULL`, then the automatically created 'Close' button
* is treated as both cancel and default button, so 0 is returned.
*
* Since: 4.10
*/
properties[PROP_CANCEL_BUTTON] =
g_param_spec_int ("cancel-button", NULL, NULL,
-1, G_MAXINT, -1,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkAlertDialog:default-button: (attributes org.gtk.Property.get=gtk_alert_dialog_get_default_button org.gtk.Property.set=gtk_alert_dialog_set_default_button)
*
* This property determines what happens when the Return key is
* pressed while the alert is shown.
*
* If this property holds the index of a button in [property@Gtk.AlertDialog:buttons],
* then pressing Return is treated as if that button was pressed. If it is -1
* or not a valid index for the `buttons` array, then nothing happens.
*
* If `buttons` is `NULL`, then the automatically created 'Close' button
* is treated as both cancel and default button, so 0 is returned.
*
* Since: 4.10
*/
properties[PROP_DEFAULT_BUTTON] =
g_param_spec_int ("default-button", NULL, NULL,
-1, G_MAXINT, -1,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
}
/* }}} */
/* {{{ API: Constructor */
/**
* gtk_alert_dialog_new:
* @format: printf()-style format string
* @...: arguments for @format
*
* Creates a new `GtkAlertDialog` object.
*
* The message will be set to the formatted string
* resulting from the arguments.
*
* Returns: the new `GtkAlertDialog`
*
* Since: 4.10
*/
GtkAlertDialog *
gtk_alert_dialog_new (const char *format,
...)
{
va_list args;
char *message;
GtkAlertDialog *dialog;
va_start (args, format);
message = g_strdup_vprintf (format, args);
va_end (args);
dialog = g_object_new (GTK_TYPE_ALERT_DIALOG,
"message", message,
NULL);
g_free (message);
return dialog;
}
/* }}} */
/* {{{ API: Getters and setters */
/**
* gtk_alert_dialog_get_modal:
* @self: a `GtkAlertDialog`
*
* Returns whether the alert blocks interaction
* with the parent window while it is presented.
*
* Returns: `TRUE` if the alert is modal
*
* Since: 4.10
*/
gboolean
gtk_alert_dialog_get_modal (GtkAlertDialog *self)
{
g_return_val_if_fail (GTK_IS_ALERT_DIALOG (self), TRUE);
return self->modal;
}
/**
* gtk_alert_dialog_set_modal:
* @self: a `GtkAlertDialog`
* @modal: the new value
*
* Sets whether the alert blocks interaction
* with the parent window while it is presented.
*
* Since: 4.10
*/
void
gtk_alert_dialog_set_modal (GtkAlertDialog *self,
gboolean modal)
{
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
if (self->modal == modal)
return;
self->modal = modal;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODAL]);
}
/**
* gtk_alert_dialog_get_message:
* @self: a `GtkAlertDialog`
*
* Returns the message that will be shown in the alert.
*
* Returns: the message
*
* Since: 4.10
*/
const char *
gtk_alert_dialog_get_message (GtkAlertDialog *self)
{
g_return_val_if_fail (GTK_IS_ALERT_DIALOG (self), NULL);
return self->message;
}
/**
* gtk_alert_dialog_set_message:
* @self: a `GtkAlertDialog`
* @message: the new message
*
* Sets the message that will be shown in the alert.
*
* Since: 4.10
*/
void
gtk_alert_dialog_set_message (GtkAlertDialog *self,
const char *message)
{
char *new_message;
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
g_return_if_fail (message != NULL);
if (g_strcmp0 (self->message, message) == 0)
return;
new_message = g_strdup (message);
g_free (self->message);
self->message = new_message;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MESSAGE]);
}
/**
* gtk_alert_dialog_get_detail:
* @self: a `GtkAlertDialog`
*
* Returns the detail text that will be shown in the alert.
*
* Returns: the detail text
*
* Since: 4.10
*/
const char *
gtk_alert_dialog_get_detail (GtkAlertDialog *self)
{
g_return_val_if_fail (GTK_IS_ALERT_DIALOG (self), NULL);
return self->detail;
}
/**
* gtk_alert_dialog_set_detail:
* @self: a `GtkAlertDialog`
* @detail: the new detail text
*
* Sets the detail text that will be shown in the alert.
*
* Since: 4.10
*/
void
gtk_alert_dialog_set_detail (GtkAlertDialog *self,
const char *detail)
{
char *new_detail;
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
g_return_if_fail (detail != NULL);
if (g_strcmp0 (self->detail, detail) == 0)
return;
new_detail = g_strdup (detail);
g_free (self->detail);
self->detail = new_detail;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DETAIL]);
}
/**
* gtk_alert_dialog_get_buttons:
* @self: a `GtkAlertDialog`
*
* Returns the button labels for the alert.
*
* Returns: (nullable) (transfer none): the button labels
*
* Since: 4.10
*/
const char * const *
gtk_alert_dialog_get_buttons (GtkAlertDialog *self)
{
g_return_val_if_fail (GTK_IS_ALERT_DIALOG (self), NULL);
return (const char * const *) self->buttons;
}
/**
* gtk_alert_dialog_set_buttons:
* @self: a `GtkAlertDialog`
* @labels: the new button labels
*
* Sets the button labels for the alert.
*
* Since: 4.10
*/
void
gtk_alert_dialog_set_buttons (GtkAlertDialog *self,
const char * const *labels)
{
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
g_return_if_fail (labels != NULL);
g_strfreev (self->buttons);
self->buttons = g_strdupv ((char **)labels);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BUTTONS]);
}
/**
* gtk_alert_dialog_get_cancel_button:
* @self: a `GtkAlertDialog`
*
* Returns the index of the cancel button.
*
* Returns: the index of the cancel button, or -1
*
* Since: 4.10
*/
int
gtk_alert_dialog_get_cancel_button (GtkAlertDialog *self)
{
g_return_val_if_fail (GTK_IS_ALERT_DIALOG (self), -1);
return self->cancel_button;
}
/**
* gtk_alert_dialog_set_cancel_button:
* @self: a `GtkAlertDialog`
* @button: the new cancel button
*
* Sets the index of the cancel button.
*
* See [property@Gtk.AlertDialog:cancel-button] for
* details of how this value is used.
*
* Since: 4.10
*/
void
gtk_alert_dialog_set_cancel_button (GtkAlertDialog *self,
int button)
{
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
if (self->cancel_button == button)
return;
self->cancel_button = button;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CANCEL_BUTTON]);
}
/**
* gtk_alert_dialog_get_default_button:
* @self: a `GtkAlertDialog`
*
* Returns the index of the default button.
*
* Returns: the index of the default button, or -1
*
* Since: 4.10
*/
int
gtk_alert_dialog_get_default_button (GtkAlertDialog *self)
{
g_return_val_if_fail (GTK_IS_ALERT_DIALOG (self), -1);
return self->default_button;
}
/**
* gtk_alert_dialog_set_default_button:
* @self: a `GtkAlertDialog`
* @button: the new default button
*
* Sets the index of the default button.
*
* See [property@Gtk.AlertDialog:default-button] for
* details of how this value is used.
*
* Since: 4.10
*/
void
gtk_alert_dialog_set_default_button (GtkAlertDialog *self,
int button)
{
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
if (self->default_button == button)
return;
self->default_button = button;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DEFAULT_BUTTON]);
}
/* }}} */
/* {{{ Async implementation */
static void response_cb (GTask *task,
int response);
static void
cancelled_cb (GCancellable *cancellable,
GTask *task)
{
response_cb (task, -1);
}
static void
response_cb (GTask *task,
int response)
{
GCancellable *cancellable;
GtkWindow *window;
cancellable = g_task_get_cancellable (task);
if (cancellable)
g_signal_handlers_disconnect_by_func (cancellable, cancelled_cb, task);
if (response >= 0)
{
g_task_return_int (task, response);
}
else
{
GtkAlertDialog *self = GTK_ALERT_DIALOG (g_task_get_source_object (task));
g_task_return_int (task, self->cancel_return);
}
g_object_unref (task);
}
static void
button_response (GtkButton *button,
GTask *task)
{
int response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "response"));
response_cb (task, response);
}
static GtkMessageWindow *
create_message_window (GtkAlertDialog *self,
GtkWindow *parent,
GTask *task)
{
GtkMessageWindow *window;
window = gtk_message_window_new ();
if (parent)
gtk_window_set_transient_for (GTK_WINDOW (window), parent);
gtk_window_set_modal (GTK_WINDOW (window), TRUE);
gtk_message_window_set_message (window, self->message);
gtk_message_window_set_detail (window, self->detail);
if (self->buttons && self->buttons[0])
{
self->cancel_return = -1;
for (int i = 0; self->buttons[i]; i++)
{
GtkWidget *button;
button = gtk_button_new_with_mnemonic (self->buttons[i]);
g_object_set_data (G_OBJECT (button), "response", GINT_TO_POINTER (i));
g_signal_connect (button, "clicked", G_CALLBACK (button_response), task);
gtk_message_window_add_button (window, button);
if (self->default_button == i)
gtk_window_set_default_widget (GTK_WINDOW (window), button);
if (self->cancel_button == i)
self->cancel_return = i;
}
}
else
{
GtkWidget *button;
button = gtk_button_new_with_mnemonic (_("_Close"));
g_signal_connect (button, "clicked", G_CALLBACK (button_response), task);
gtk_message_window_add_button (window, button);
gtk_window_set_default_widget (GTK_WINDOW (window), button);
self->cancel_return = 0;
}
return window;
}
/* }}} */
/* {{{ Async API */
/**
* gtk_alert_dialog_choose:
* @self: a `GtkAlertDialog`
* @parent: (nullable): the parent `GtkWindow`
* @cancellable: (nullable): a `GCancellable` to cancel the operation
* @callback: (nullable) (scope async): a callback to call when the operation is complete
* @user_data: (closure callback): data to pass to @callback
*
* This function shows the alert to the user.
*
* The @callback will be called when the alert is dismissed.
* It should call [method@Gtk.AlertDialog.choose_finish]
* to obtain the result.
*
* It is ok to pass `NULL` for the callback if the alert
* does not have more than one button. A simpler API for
* this case is [method@Gtk.AlertDialog.show].
*
* Since: 4.10
*/
void
gtk_alert_dialog_choose (GtkAlertDialog *self,
GtkWindow *parent,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GtkWidget *window;
GTask *task;
g_return_if_fail (GTK_IS_ALERT_DIALOG (self));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_alert_dialog_choose);
if (cancellable)
g_signal_connect (cancellable, "cancelled", G_CALLBACK (cancelled_cb), task);
window = GTK_WIDGET (create_message_window (self, parent, task));
g_task_set_task_data (task, window, (GDestroyNotify) gtk_window_destroy);
gtk_window_present (GTK_WINDOW (window));
}
/**
* gtk_alert_dialog_choose_finish:
* @self: a `GtkAlertDialog`
* @result: a `GAsyncResult`
*
* Finishes the [method@Gtk.AlertDialog.choose] call
* and returns the index of the button that was clicked.
*
* Returns: the index of the button that was clicked, or -1 if
* the dialog was cancelled and `[property@Gtk.AlertDialog:cancel-button]
* is not set
*
* Since: 4.10
*/
int
gtk_alert_dialog_choose_finish (GtkAlertDialog *self,
GAsyncResult *result)
{
GTask *task = G_TASK (result);
g_return_val_if_fail (g_task_get_source_tag (task) == gtk_alert_dialog_choose, -1);
return (int) g_task_propagate_int (task, NULL);
}
/**
* gtk_alert_dialog_show:
* @self: a `GtkAlertDialog`
* @parent: (nullable): the parent `GtkWindow`
*
* This function shows the alert to the user.
*
* If the alert has more than one button, you should use
* [method@Gtk.AlertDialog.choose] instead and provide
* a callback that can react to the button that was clicked.
*
* Since: 4.10
*/
void
gtk_alert_dialog_show (GtkAlertDialog *self,
GtkWindow *parent)
{
gtk_alert_dialog_choose (self, parent, NULL, NULL, NULL);
}
/* }}} */
/* vim:set foldmethod=marker expandtab: */

96
gtk/gtkalertdialog.h Normal file
View File

@@ -0,0 +1,96 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2022 Red Hat, Inc.
*
* 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 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/>.
*/
#pragma once
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
#include <gtk/gtkwindow.h>
G_BEGIN_DECLS
#define GTK_TYPE_ALERT_DIALOG (gtk_alert_dialog_get_type ())
GDK_AVAILABLE_IN_4_10
G_DECLARE_FINAL_TYPE (GtkAlertDialog, gtk_alert_dialog, GTK, ALERT_DIALOG, GObject)
GDK_AVAILABLE_IN_4_10
GtkAlertDialog *gtk_alert_dialog_new (const char *format,
...) G_GNUC_PRINTF (1, 2);
GDK_AVAILABLE_IN_4_10
gboolean gtk_alert_dialog_get_modal (GtkAlertDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_set_modal (GtkAlertDialog *self,
gboolean modal);
GDK_AVAILABLE_IN_4_10
const char * gtk_alert_dialog_get_message (GtkAlertDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_set_message (GtkAlertDialog *self,
const char *message);
GDK_AVAILABLE_IN_4_10
const char * gtk_alert_dialog_get_detail (GtkAlertDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_set_detail (GtkAlertDialog *self,
const char *detail);
GDK_AVAILABLE_IN_4_10
const char * const *
gtk_alert_dialog_get_buttons (GtkAlertDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_set_buttons (GtkAlertDialog *self,
const char * const *labels);
GDK_AVAILABLE_IN_4_10
int gtk_alert_dialog_get_cancel_button (GtkAlertDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_set_cancel_button (GtkAlertDialog *self,
int button);
GDK_AVAILABLE_IN_4_10
int gtk_alert_dialog_get_default_button (GtkAlertDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_set_default_button (GtkAlertDialog *self,
int button);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_choose (GtkAlertDialog *self,
GtkWindow *parent,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
int gtk_alert_dialog_choose_finish (GtkAlertDialog *self,
GAsyncResult *result);
GDK_AVAILABLE_IN_4_10
void gtk_alert_dialog_show (GtkAlertDialog *self,
GtkWindow *parent);
G_END_DECLS

View File

@@ -28,7 +28,9 @@
#include <glib/gi18n-lib.h>
#include "gtkbookmarksmanagerprivate.h"
#include "gtkfilechooser.h" /* for the GError types */
#include "deprecated/gtkfilechooser.h" /* for the GError types */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void
_gtk_bookmark_free (gpointer data)

View File

@@ -17,16 +17,18 @@
#include "config.h"
#include "gtkdialog.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialog.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtkbutton.h"
#include "gtkbox.h"
#include "gtkprivate.h"
#include "gtksettings.h"
#include "gtkcolorchooserprivate.h"
#include "gtkcolorchooserdialog.h"
#include "gtkcolorchooserwidget.h"
#include "deprecated/gtkcolorchooserprivate.h"
#include "deprecated/gtkcolorchooserdialog.h"
#include "deprecated/gtkcolorchooserwidget.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkColorChooserDialog:
@@ -43,6 +45,10 @@
* To change the initially selected color, use
* [method@Gtk.ColorChooser.set_rgba]. To get the selected color use
* [method@Gtk.ColorChooser.get_rgba].
*
* `GtkColorChooserDialog` has been deprecated in favor of [class@Gtk.ColorDialog].
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] instead
*/
typedef struct _GtkColorChooserDialogClass GtkColorChooserDialogClass;
@@ -281,6 +287,8 @@ gtk_color_chooser_dialog_iface_init (GtkColorChooserInterface *iface)
* Creates a new `GtkColorChooserDialog`.
*
* Returns: a new `GtkColorChooserDialog`
*
* Deprecated: 4.10: Use [class@Gtk.ColorDialog] instead
*/
GtkWidget *
gtk_color_chooser_dialog_new (const char *title,

View File

@@ -18,8 +18,8 @@
#include "config.h"
#include "gtkcolorchooserprivate.h"
#include "gtkcolorchooserwidget.h"
#include "deprecated/gtkcolorchooserprivate.h"
#include "deprecated/gtkcolorchooserwidget.h"
#include "gtkcoloreditorprivate.h"
#include "gtkcolorswatchprivate.h"
#include "gtkgrid.h"
@@ -34,6 +34,8 @@
#include <math.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkColorChooserWidget:
*
@@ -61,6 +63,8 @@
* # CSS names
*
* `GtkColorChooserWidget` has a single CSS node with name colorchooser.
*
* Deprecated: 4.10: Direct use of `GtkColorChooserWidget` is deprecated.
*/
typedef struct _GtkColorChooserWidgetClass GtkColorChooserWidgetClass;

497
gtk/gtkcolordialog.c Normal file
View File

@@ -0,0 +1,497 @@
/*
* GTK - The GIMP Toolkit
* Copyright (C) 2022 Red Hat, Inc.
* All rights reserved.
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkcolordialog.h"
#include "deprecated/gtkcolorchooserdialog.h"
#include "deprecated/gtkcolorchooser.h"
#include "gtkbutton.h"
#include "gtkdialogerror.h"
#include <glib/gi18n-lib.h>
/**
* GtkColorDialog:
*
* A `GtkColorDialog` object collects the arguments that
* are needed to present a color chooser dialog to the
* user, such as a title for the dialog and whether it
* should be modal.
*
* The dialog is shown with the [method@Gtk.ColorDialog.choose_rgba]
* function. This API follows the GIO async pattern, and the
* result can be obtained by calling
* [method@Gtk.ColorDialog.choose_rgba_finish].
*
* See [class@Gtk.ColorDialogButton] for a convenient control
* that uses `GtkColorDialog` and presents the results.
*
* `GtkColorDialog was added in GTK 4.10.
*/
/* {{{ GObject implementation */
struct _GtkColorDialog
{
GObject parent_instance;
char *title;
unsigned int modal : 1;
unsigned int with_alpha : 1;
};
enum
{
PROP_TITLE = 1,
PROP_MODAL,
PROP_WITH_ALPHA,
NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES];
G_DEFINE_TYPE (GtkColorDialog, gtk_color_dialog, G_TYPE_OBJECT)
static void
gtk_color_dialog_init (GtkColorDialog *self)
{
self->modal = TRUE;
self->with_alpha = TRUE;
}
static void
gtk_color_dialog_finalize (GObject *object)
{
GtkColorDialog *self = GTK_COLOR_DIALOG (object);
g_free (self->title);
G_OBJECT_CLASS (gtk_color_dialog_parent_class)->finalize (object);
}
static void
gtk_color_dialog_get_property (GObject *object,
unsigned int property_id,
GValue *value,
GParamSpec *pspec)
{
GtkColorDialog *self = GTK_COLOR_DIALOG (object);
switch (property_id)
{
case PROP_TITLE:
g_value_set_string (value, self->title);
break;
case PROP_MODAL:
g_value_set_boolean (value, self->modal);
break;
case PROP_WITH_ALPHA:
g_value_set_boolean (value, self->with_alpha);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_color_dialog_set_property (GObject *object,
unsigned int prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkColorDialog *self = GTK_COLOR_DIALOG (object);
switch (prop_id)
{
case PROP_TITLE:
gtk_color_dialog_set_title (self, g_value_get_string (value));
break;
case PROP_MODAL:
gtk_color_dialog_set_modal (self, g_value_get_boolean (value));
break;
case PROP_WITH_ALPHA:
gtk_color_dialog_set_with_alpha (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_color_dialog_class_init (GtkColorDialogClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = gtk_color_dialog_finalize;
object_class->get_property = gtk_color_dialog_get_property;
object_class->set_property = gtk_color_dialog_set_property;
/**
* GtkColorDialog:title: (attributes org.gtk.Property.get=gtk_color_dialog_get_title org.gtk.Property.set=gtk_color_dialog_set_title)
*
* A title that may be shown on the color chooser
* dialog that is presented by [method@Gtk.ColorDialog.choose_rgba].
*
* Since: 4.10
*/
properties[PROP_TITLE] =
g_param_spec_string ("title", NULL, NULL,
NULL,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkColorDialog:modal: (attributes org.gtk.Property.get=gtk_color_dialog_get_modal org.gtk.Property.set=gtk_color_dialog_set_modal)
*
* Whether the color chooser dialog is modal.
*
* Since: 4.10
*/
properties[PROP_MODAL] =
g_param_spec_boolean ("modal", NULL, NULL,
TRUE,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkColorDialog:with-alpha: (attributes org.gtk.Property.get=gtk_color_dialog_get_with_alpha org.gtk.Property.set=gtk_color_dialog_set_with_alpha)
*
* Whether colors may have alpha (translucency).
*
* When with-alpha is %FALSE, the color that is selected
* will be forced to have alpha == 1.
*
* Since: 4.10
*/
properties[PROP_WITH_ALPHA] =
g_param_spec_boolean ("with-alpha", NULL, NULL,
TRUE,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
}
/* }}} */
/* {{{ API: Constructor */
/**
* gtk_color_dialog_new:
*
* Creates a new `GtkColorDialog` object.
*
* Returns: the new `GtkColorDialog`
*
* Since: 4.10
*/
GtkColorDialog *
gtk_color_dialog_new (void)
{
return g_object_new (GTK_TYPE_COLOR_DIALOG, NULL);
}
/* }}} */
/* {{{ API: Getters and setters */
/**
* gtk_color_dialog_get_title:
* @self: a `GtkColorDialog`
*
* Returns the title that will be shown on the
* color chooser dialog.
*
* Returns: the title
*
* Since: 4.10
*/
const char *
gtk_color_dialog_get_title (GtkColorDialog *self)
{
g_return_val_if_fail (GTK_IS_COLOR_DIALOG (self), NULL);
return self->title;
}
/**
* gtk_color_dialog_set_title:
* @self: a `GtkColorDialog`
* @title: the new title
*
* Sets the title that will be shown on the
* color chooser dialog.
*
* Since: 4.10
*/
void
gtk_color_dialog_set_title (GtkColorDialog *self,
const char *title)
{
char *new_title;
g_return_if_fail (GTK_IS_COLOR_DIALOG (self));
g_return_if_fail (title != NULL);
if (g_strcmp0 (self->title, title) == 0)
return;
new_title = g_strdup (title);
g_free (self->title);
self->title = new_title;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
}
/**
* gtk_color_dialog_get_modal:
* @self: a `GtkColorDialog`
*
* Returns whether the color chooser dialog
* blocks interaction with the parent window
* while it is presented.
*
* Returns: `TRUE` if the color chooser dialog is modal
*
* Since: 4.10
*/
gboolean
gtk_color_dialog_get_modal (GtkColorDialog *self)
{
g_return_val_if_fail (GTK_IS_COLOR_DIALOG (self), TRUE);
return self->modal;
}
/**
* gtk_color_dialog_set_modal:
* @self: a `GtkColorDialog`
* @modal: the new value
*
* Sets whether the color chooser dialog
* blocks interaction with the parent window
* while it is presented.
*
* Since: 4.10
*/
void
gtk_color_dialog_set_modal (GtkColorDialog *self,
gboolean modal)
{
g_return_if_fail (GTK_IS_COLOR_DIALOG (self));
if (self->modal == modal)
return;
self->modal = modal;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODAL]);
}
/**
* gtk_color_dialog_get_with_alpha:
* @self: a `GtkColorDialog`
*
* Returns whether colors may have alpha.
*
* Returns: `TRUE` if colors may have alpha
*
* Since: 4.10
*/
gboolean
gtk_color_dialog_get_with_alpha (GtkColorDialog *self)
{
g_return_val_if_fail (GTK_IS_COLOR_DIALOG (self), TRUE);
return self->with_alpha;
}
/**
* gtk_color_dialog_set_with_alpha:
* @self: a `GtkColorDialog`
* @with_alpha: the new value
*
* Sets whether colors may have alpha.
*
* Since: 4.10
*/
void
gtk_color_dialog_set_with_alpha (GtkColorDialog *self,
gboolean with_alpha)
{
g_return_if_fail (GTK_IS_COLOR_DIALOG (self));
if (self->with_alpha == with_alpha)
return;
self->with_alpha = with_alpha;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WITH_ALPHA]);
}
/* }}} */
/* {{{ Async implementation */
static void response_cb (GTask *task,
int response);
static void
cancelled_cb (GCancellable *cancellable,
GTask *task)
{
response_cb (task, GTK_RESPONSE_CLOSE);
}
static void
response_cb (GTask *task,
int response)
{
GCancellable *cancellable;
cancellable = g_task_get_cancellable (task);
if (cancellable)
g_signal_handlers_disconnect_by_func (cancellable, cancelled_cb, task);
if (response == GTK_RESPONSE_OK)
{
GtkColorChooserDialog *window;
GdkRGBA color;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
window = GTK_COLOR_CHOOSER_DIALOG (g_task_get_task_data (task));
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (window), &color);
G_GNUC_END_IGNORE_DEPRECATIONS
g_task_return_pointer (task, gdk_rgba_copy (&color), (GDestroyNotify) gdk_rgba_free);
}
else if (response == GTK_RESPONSE_CLOSE)
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_ABORTED, "Aborted by application");
else if (response == GTK_RESPONSE_CANCEL)
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED, "Cancelled by user");
else
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_FAILED, "Unknown failure (%d)", response);
g_object_unref (task);
}
static GtkWidget *
create_color_chooser (GtkColorDialog *self,
GtkWindow *parent,
const GdkRGBA *initial_color)
{
GtkWidget *window;
char *title;
if (self->title)
title = self->title;
else
title = _("Pick a Color");
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
window = gtk_color_chooser_dialog_new (title, parent);
if (initial_color)
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (window), initial_color);
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (window), self->with_alpha);
gtk_window_set_modal (GTK_WINDOW (window), self->modal);
G_GNUC_END_IGNORE_DEPRECATIONS
return window;
}
/* }}} */
/* {{{ Async API */
/**
* gtk_color_dialog_choose_rgba:
* @self: a `GtkColorDialog`
* @parent: (nullable): the parent `GtkWindow`
* @initial_color: (nullable): the color to select initially
* @cancellable: (nullable): a `GCancellable` to cancel the operation
* @callback: (scope async): a callback to call when the operation is complete
* @user_data: (closure callback): data to pass to @callback
*
* This function initiates a color choice operation by
* presenting a color chooser dialog to the user.
*
* The @callback will be called when the dialog is dismissed.
* It should call [method@Gtk.ColorDialog.choose_rgba_finish]
* to obtain the result.
*
* Since: 4.10
*/
void
gtk_color_dialog_choose_rgba (GtkColorDialog *self,
GtkWindow *parent,
const GdkRGBA *initial_color,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GtkWidget *window;
GTask *task;
g_return_if_fail (GTK_IS_COLOR_DIALOG (self));
window = create_color_chooser (self, parent, initial_color);
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_color_dialog_choose_rgba);
g_task_set_task_data (task, window, (GDestroyNotify) gtk_window_destroy);
if (cancellable)
g_signal_connect (cancellable, "cancelled", G_CALLBACK (cancelled_cb), task);
g_signal_connect_swapped (window, "response", G_CALLBACK (response_cb), task);
gtk_window_present (GTK_WINDOW (window));
}
/**
* gtk_color_dialog_choose_rgba_finish:
* @self: a `GtkColorDialog`
* @result: a `GAsyncResult`
* @error: return location for an error
*
* Finishes the [method@Gtk.ColorDialog.choose_rgba] call and
* returns the resulting color.
*
* Returns: (nullable) (transfer full): the selected color, or
* `NULL` and @error is set
*
* Since: 4.10
*/
GdkRGBA *
gtk_color_dialog_choose_rgba_finish (GtkColorDialog *self,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (GTK_IS_COLOR_DIALOG (self), NULL);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_color_dialog_choose_rgba, NULL);
return g_task_propagate_pointer (G_TASK (result), error);
}
/* }}} */
/* vim:set foldmethod=marker expandtab: */

72
gtk/gtkcolordialog.h Normal file
View File

@@ -0,0 +1,72 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2022 Red Hat, Inc.
*
* 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 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/>.
*/
#pragma once
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
#include <gtk/gtkwindow.h>
G_BEGIN_DECLS
#define GTK_TYPE_COLOR_DIALOG (gtk_color_dialog_get_type ())
GDK_AVAILABLE_IN_4_10
G_DECLARE_FINAL_TYPE (GtkColorDialog, gtk_color_dialog, GTK, COLOR_DIALOG, GObject)
GDK_AVAILABLE_IN_4_10
GtkColorDialog *gtk_color_dialog_new (void);
GDK_AVAILABLE_IN_4_10
const char * gtk_color_dialog_get_title (GtkColorDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_color_dialog_set_title (GtkColorDialog *self,
const char *title);
GDK_AVAILABLE_IN_4_10
gboolean gtk_color_dialog_get_modal (GtkColorDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_color_dialog_set_modal (GtkColorDialog *self,
gboolean modal);
GDK_AVAILABLE_IN_4_10
gboolean gtk_color_dialog_get_with_alpha (GtkColorDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_color_dialog_set_with_alpha (GtkColorDialog *self,
gboolean with_alpha);
GDK_AVAILABLE_IN_4_10
void gtk_color_dialog_choose_rgba (GtkColorDialog *self,
GtkWindow *parent,
const GdkRGBA *initial_color,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
GdkRGBA * gtk_color_dialog_choose_rgba_finish (GtkColorDialog *self,
GAsyncResult *result,
GError **error);
G_END_DECLS

517
gtk/gtkcolordialogbutton.c Normal file
View File

@@ -0,0 +1,517 @@
/*
* GTK - The GIMP Toolkit
* Copyright (C) 2022 Red Hat, Inc.
* All rights reserved.
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkcolordialogbutton.h"
#include "gtkbinlayout.h"
#include "gtkbutton.h"
#include "gtkcolorswatchprivate.h"
#include "gtkdragsource.h"
#include "gtkdroptarget.h"
#include <glib/gi18n-lib.h>
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtksnapshot.h"
#include "gtkwidgetprivate.h"
#include "gdk/gdkrgbaprivate.h"
static gboolean drop (GtkDropTarget *dest,
const GValue *value,
double x,
double y,
GtkColorDialogButton *self);
static GdkContentProvider *
drag_prepare (GtkDragSource *source,
double x,
double y,
GtkColorDialogButton *self);
static void button_clicked (GtkColorDialogButton *self);
static void update_button_sensitivity
(GtkColorDialogButton *self);
/**
* GtkColorDialogButton:
*
* The `GtkColorDialogButton` is a wrapped around a [class@Gtk.ColorDialog]
* and allows to open a color chooser dialog to change the color.
*
* ![An example GtkColorDialogButton](color-button.png)
*
* It is suitable widget for selecting a color in a preference dialog.
*
* # CSS nodes
*
* ```
* colorbutton
* ╰── button.color
* ╰── [content]
* ```
*
* `GtkColorDialogButton` has a single CSS node with name colorbutton which
* contains a button node. To differentiate it from a plain `GtkButton`,
* it gets the .color style class.
*/
/* {{{ GObject implementation */
struct _GtkColorDialogButton
{
GtkWidget parent_instance;
GtkWidget *button;
GtkWidget *swatch;
GtkColorDialog *dialog;
GCancellable *cancellable;
GdkRGBA color;
};
/* Properties */
enum
{
PROP_DIALOG = 1,
PROP_RGBA,
NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES];
G_DEFINE_TYPE (GtkColorDialogButton, gtk_color_dialog_button, GTK_TYPE_WIDGET)
static void
gtk_color_dialog_button_init (GtkColorDialogButton *self)
{
PangoLayout *layout;
PangoRectangle rect;
GtkDragSource *source;
GtkDropTarget *dest;
self->color = GDK_RGBA ("00000000");
self->button = gtk_button_new ();
g_signal_connect_swapped (self->button, "clicked", G_CALLBACK (button_clicked), self);
gtk_widget_set_parent (self->button, GTK_WIDGET (self));
self->swatch = g_object_new (GTK_TYPE_COLOR_SWATCH,
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
"selectable", FALSE,
"has-menu", FALSE,
"can-drag", FALSE,
NULL);
gtk_widget_set_can_focus (self->swatch, FALSE);
gtk_widget_remove_css_class (self->swatch, "activatable");
layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), "Black");
pango_layout_get_pixel_extents (layout, NULL, &rect);
g_object_unref (layout);
gtk_widget_set_size_request (self->swatch, rect.width, rect.height);
gtk_button_set_child (GTK_BUTTON (self->button), self->swatch);
dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
g_signal_connect (dest, "drop", G_CALLBACK (drop), self);
gtk_widget_add_controller (GTK_WIDGET (self->button), GTK_EVENT_CONTROLLER (dest));
source = gtk_drag_source_new ();
g_signal_connect (source, "prepare", G_CALLBACK (drag_prepare), self);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (source),
GTK_PHASE_CAPTURE);
gtk_widget_add_controller (self->button, GTK_EVENT_CONTROLLER (source));
gtk_widget_add_css_class (self->button, "color");
}
static void
gtk_color_dialog_button_unroot (GtkWidget *widget)
{
GtkColorDialogButton *self = GTK_COLOR_DIALOG_BUTTON (widget);
if (self->cancellable)
{
g_cancellable_cancel (self->cancellable);
g_clear_object (&self->cancellable);
update_button_sensitivity (self);
}
GTK_WIDGET_CLASS (gtk_color_dialog_button_parent_class)->unroot (widget);
}
static void
gtk_color_dialog_button_set_property (GObject *object,
unsigned int param_id,
const GValue *value,
GParamSpec *pspec)
{
GtkColorDialogButton *self = GTK_COLOR_DIALOG_BUTTON (object);
switch (param_id)
{
case PROP_DIALOG:
gtk_color_dialog_button_set_dialog (self, g_value_get_object (value));
break;
case PROP_RGBA:
gtk_color_dialog_button_set_rgba (self, g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_color_dialog_button_get_property (GObject *object,
unsigned int param_id,
GValue *value,
GParamSpec *pspec)
{
GtkColorDialogButton *self = GTK_COLOR_DIALOG_BUTTON (object);
switch (param_id)
{
case PROP_DIALOG:
g_value_set_object (value, self->dialog);
break;
case PROP_RGBA:
g_value_set_boxed (value, &self->color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gtk_color_dialog_button_dispose (GObject *object)
{
GtkColorDialogButton *self = GTK_COLOR_DIALOG_BUTTON (object);
g_clear_pointer (&self->button, gtk_widget_unparent);
G_OBJECT_CLASS (gtk_color_dialog_button_parent_class)->dispose (object);
}
static void
gtk_color_dialog_button_finalize (GObject *object)
{
GtkColorDialogButton *self = GTK_COLOR_DIALOG_BUTTON (object);
g_assert (self->cancellable == NULL);
g_clear_object (&self->dialog);
G_OBJECT_CLASS (gtk_color_dialog_button_parent_class)->finalize (object);
}
static void
gtk_color_dialog_button_class_init (GtkColorDialogButtonClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
object_class->get_property = gtk_color_dialog_button_get_property;
object_class->set_property = gtk_color_dialog_button_set_property;
object_class->dispose = gtk_color_dialog_button_dispose;
object_class->finalize = gtk_color_dialog_button_finalize;
widget_class->grab_focus = gtk_widget_grab_focus_child;
widget_class->focus = gtk_widget_focus_child;
widget_class->unroot = gtk_color_dialog_button_unroot;
/**
* GtkColorDialogButton:dialog: (attributes org.gtk.Property.get=gtk_color_dialog_button_get_dialog org.gtk.Property.set=gtk_color_dialog_button_set_dialog)
*
* The `GtkColorDialog` that contains parameters for
* the color chooser dialog.
*
* Since: 4.10
*/
properties[PROP_DIALOG] =
g_param_spec_object ("dialog", NULL, NULL,
GTK_TYPE_COLOR_DIALOG,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkColorDialogButton:rgba: (attributes org.gtk.Property.get=gtk_color_dialog_button_get_rgba org.gtk.Property.set=gtk_color_dialog_button_set_rgba)
*
* The selected color.
*
* This property can be set to give the button its initial
* color, and it will be updated to reflect the users choice
* in the color chooser dialog.
*
* Listen to `notify::rgba` to get informed about changes
* to the buttons color.
*
* Since: 4.10
*/
properties[PROP_RGBA] =
g_param_spec_boxed ("rgba", NULL, NULL,
GDK_TYPE_RGBA,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, "colorbutton");
}
/* }}} */
/* {{{ Private API, callbacks */
static guint
scale_round (double value,
double scale)
{
value = floor (value * scale + 0.5);
value = CLAMP (value, 0, scale);
return (guint)value;
}
static char *
accessible_color_name (const GdkRGBA *color)
{
if (color->alpha < 1.0)
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"),
scale_round (color->red, 100),
scale_round (color->green, 100),
scale_round (color->blue, 100),
scale_round (color->alpha, 100));
else
return g_strdup_printf (_("Red %d%%, Green %d%%, Blue %d%%"),
scale_round (color->red, 100),
scale_round (color->green, 100),
scale_round (color->blue, 100));
}
static gboolean
drop (GtkDropTarget *dest,
const GValue *value,
double x,
double y,
GtkColorDialogButton *self)
{
GdkRGBA *color = g_value_get_boxed (value);
gtk_color_dialog_button_set_rgba (self, color);
return TRUE;
}
static GdkContentProvider *
drag_prepare (GtkDragSource *source,
double x,
double y,
GtkColorDialogButton *self)
{
GdkRGBA color;
gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (self->swatch), &color);
return gdk_content_provider_new_typed (GDK_TYPE_RGBA, &color);
}
static void
update_button_sensitivity (GtkColorDialogButton *self)
{
gtk_widget_set_sensitive (self->button,
self->dialog != NULL && self->cancellable == NULL);
}
static void
color_chosen (GObject *source,
GAsyncResult *result,
gpointer data)
{
GtkColorDialogButton *self = data;
GdkRGBA *color;
color = gtk_color_dialog_choose_rgba_finish (self->dialog, result, NULL);
if (color)
{
gtk_color_dialog_button_set_rgba (self, color);
gdk_rgba_free (color);
}
g_clear_object (&self->cancellable);
update_button_sensitivity (self);
}
static void
button_clicked (GtkColorDialogButton *self)
{
GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (self));
GtkWindow *parent = NULL;
g_assert (self->cancellable == NULL);
self->cancellable = g_cancellable_new ();
update_button_sensitivity (self);
if (GTK_IS_WINDOW (root))
parent = GTK_WINDOW (root);
gtk_color_dialog_choose_rgba (self->dialog, parent, &self->color,
self->cancellable, color_chosen, self);
}
/* }}} */
/* {{{ Constructor */
/**
* gtk_color_dialog_button_new:
* @dialog: (nullable) (transfer full): the `GtkColorDialog` to use
*
* Creates a new `GtkColorDialogButton` with the
* given `GtkColorDialog`.
*
* You can pass `NULL` to this function and set a `GtkColorDialog`
* later. The button will be insensitive until that happens.
*
* Returns: the new `GtkColorDialogButton`
*
* Since: 4.10
*/
GtkWidget *
gtk_color_dialog_button_new (GtkColorDialog *dialog)
{
GtkWidget *self;
g_return_val_if_fail (GTK_IS_COLOR_DIALOG (dialog), NULL);
self = g_object_new (GTK_TYPE_COLOR_DIALOG_BUTTON,
"dialog", dialog,
NULL);
g_clear_object (&dialog);
return self;
}
/* }}} */
/* {{{ Getters and setters */
/**
* gtk_color_dialog_button_get_dialog:
* @self: a `GtkColorDialogButton`
*
* Returns the `GtkColorDialog` of @self.
*
* Returns: (transfer none) (nullable): the `GtkColorDialog`
*
* Since: 4.10
*/
GtkColorDialog *
gtk_color_dialog_button_get_dialog (GtkColorDialogButton *self)
{
g_return_val_if_fail (GTK_IS_COLOR_DIALOG_BUTTON (self), NULL);
return self->dialog;
}
/**
* gtk_color_dialog_button_set_dialog:
* @self: a `GtkColorDialogButton`
* @dialog: the new `GtkColorDialog`
*
* Sets a `GtkColorDialog` object to use for
* creating the color chooser dialog that is
* presented when the user clicks the button.
*
* Since: 4.10
*/
void
gtk_color_dialog_button_set_dialog (GtkColorDialogButton *self,
GtkColorDialog *dialog)
{
g_return_if_fail (GTK_IS_COLOR_DIALOG_BUTTON (self));
g_return_if_fail (GTK_IS_COLOR_DIALOG (dialog));
if (!g_set_object (&self->dialog, dialog))
return;
update_button_sensitivity (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DIALOG]);
}
/**
* gtk_color_dialog_button_get_rgba:
* @self: a `GtkColorDialogButton`
*
* Returns the color of the button.
*
* This function is what should be used to obtain
* the color that was choosen by the user. To get
* informed about changes, listen to "notify::color".
*
* Returns: the color
*
* Since: 4.10
*/
const GdkRGBA *
gtk_color_dialog_button_get_rgba (GtkColorDialogButton *self)
{
g_return_val_if_fail (GTK_IS_COLOR_DIALOG_BUTTON (self), NULL);
return &self->color;
}
/**
* gtk_color_dialog_button_set_rgba:
* @self: a `GtkColorDialogButton`
* @color: the new color
*
* Sets the color of the button.
*
* Since: 4.10
*/
void
gtk_color_dialog_button_set_rgba (GtkColorDialogButton *self,
const GdkRGBA *color)
{
char *text;
g_return_if_fail (GTK_IS_COLOR_DIALOG_BUTTON (self));
g_return_if_fail (color != NULL);
if (gdk_rgba_equal (&self->color, color))
return;
self->color = *color;
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (self->swatch), color);
text = accessible_color_name (color);
gtk_accessible_update_property (GTK_ACCESSIBLE (self->swatch),
GTK_ACCESSIBLE_PROPERTY_LABEL, text,
-1);
g_free (text);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RGBA]);
}
/* }}} */
/* vim:set foldmethod=marker expandtab: */

View File

@@ -0,0 +1,53 @@
/*
* GTK - The GIMP Toolkit
* Copyright (C) 2022 Red Hat, Inc.
* All rights reserved.
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkbutton.h>
#include <gtk/gtkcolordialog.h>
G_BEGIN_DECLS
#define GTK_TYPE_COLOR_DIALOG_BUTTON (gtk_color_dialog_button_get_type ())
GDK_AVAILABLE_IN_4_10
G_DECLARE_FINAL_TYPE (GtkColorDialogButton, gtk_color_dialog_button, GTK, COLOR_DIALOG_BUTTON, GtkWidget)
GDK_AVAILABLE_IN_4_10
GtkWidget * gtk_color_dialog_button_new (GtkColorDialog *dialog);
GDK_AVAILABLE_IN_4_10
GtkColorDialog *gtk_color_dialog_button_get_dialog (GtkColorDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_color_dialog_button_set_dialog (GtkColorDialogButton *self,
GtkColorDialog *dialog);
GDK_AVAILABLE_IN_4_10
const GdkRGBA * gtk_color_dialog_button_get_rgba (GtkColorDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_color_dialog_button_set_rgba (GtkColorDialogButton *self,
const GdkRGBA *color);
G_END_DECLS

View File

@@ -19,7 +19,7 @@
#include "gtkcoloreditorprivate.h"
#include "gtkcolorchooserprivate.h"
#include "deprecated/gtkcolorchooserprivate.h"
#include "gtkcolorplaneprivate.h"
#include "gtkcolorscaleprivate.h"
#include "gtkcolorswatchprivate.h"
@@ -38,6 +38,8 @@
#include <math.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct _GtkColorEditorClass GtkColorEditorClass;
struct _GtkColorEditor

View File

@@ -19,7 +19,7 @@
#include "gtkcolorscaleprivate.h"
#include "gtkcolorchooserprivate.h"
#include "deprecated/gtkcolorchooserprivate.h"
#include "gtkgesturelongpress.h"
#include "gtkgestureclick.h"
#include "gtkcolorutils.h"

View File

@@ -20,7 +20,7 @@
#include "gtkcolorswatchprivate.h"
#include "gtkbox.h"
#include "gtkcolorchooserprivate.h"
#include "deprecated/gtkcolorchooserprivate.h"
#include "gtkdragsource.h"
#include "gtkdroptarget.h"
#include "gtkgesturelongpress.h"

View File

@@ -37,7 +37,7 @@
#include "gtkcustompaperunixdialog.h"
#include "gtkprintbackendprivate.h"
#include "gtkprintutils.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#define LEGACY_CUSTOM_PAPER_FILENAME ".gtk-custom-papers"
#define CUSTOM_PAPER_FILENAME "custom-papers"
@@ -283,7 +283,9 @@ gtk_custom_paper_unix_dialog_init (GtkCustomPaperUnixDialog *dialog)
GListModel *full_list;
GtkFilter *filter;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
dialog->print_backends = NULL;
@@ -318,6 +320,7 @@ gtk_custom_paper_unix_dialog_constructed (GObject *object)
G_OBJECT_CLASS (gtk_custom_paper_unix_dialog_parent_class)->constructed (object);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
g_object_get (object, "use-header-bar", &use_header, NULL);
if (!use_header)
{
@@ -326,6 +329,7 @@ gtk_custom_paper_unix_dialog_constructed (GObject *object)
NULL);
gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_CLOSE);
}
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
@@ -847,7 +851,10 @@ populate_dialog (GtkCustomPaperUnixDialog *dialog)
GtkSelectionModel *model;
GtkListItemFactory *factory;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
content_area = gtk_dialog_get_content_area (cpu_dialog);
G_GNUC_END_IGNORE_DEPRECATIONS
gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 18);

27
gtk/gtkdialogerror.c Normal file
View File

@@ -0,0 +1,27 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2022 Red Hat, Inc.
*
* 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 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 "config.h"
#include "gtk/gtkdialogerror.h"
GQuark
gtk_dialog_error_quark (void)
{
return g_quark_from_static_string ("gtk-dialog-error-quark");
}

62
gtk/gtkdialogerror.h Normal file
View File

@@ -0,0 +1,62 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2022 Red Hat, Inc.
*
* 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 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/>.
*/
#pragma once
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
G_BEGIN_DECLS
/**
* GTK_DIALOG_ERROR:
*
* The error domain for errors returned by async dialog functions.
*
* Since: 4.10
*/
#define GTK_DIALOG_ERROR (gtk_dialog_error_quark ())
/**
* GtkDialogError:
* @GTK_DIALOG_ERROR_FAILED: Generic error condition for when
* an operation fails and no more specific code is applicable
* @GTK_DIALOG_ERROR_ABORTED: The async function call was aborted
* programmatically (via its `GCancellable`)
* @GTK_DIALOG_ERROR_CANCELLED: The async operation was cancelled
* by the user (via a Close button)
*
* Error codes in the `GTK_DIALOG_ERROR` domain that can be returned
* by async dialog functions.
*
* Since: 4.10
*/
typedef enum
{
GTK_DIALOG_ERROR_FAILED,
GTK_DIALOG_ERROR_ABORTED,
GTK_DIALOG_ERROR_CANCELLED
} GtkDialogError;
GDK_AVAILABLE_IN_4_10
GQuark gtk_dialog_error_quark (void);
G_END_DECLS

View File

@@ -30,7 +30,6 @@
#include "gtklistitem.h"
#include "gtkselectionmodel.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserwidget.h"
#include "gtkfilechooserwidgetprivate.h"
struct _GtkFileChooserCell

View File

@@ -19,10 +19,10 @@
#include "config.h"
#include "gtkfilechooserdialog.h"
#include "deprecated/gtkfilechooserdialog.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserwidget.h"
#include "deprecated/gtkfilechooserwidget.h"
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtksizerequest.h"
@@ -31,7 +31,7 @@
#include "gtksettings.h"
#include "gtktogglebutton.h"
#include "gtkheaderbar.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtklabel.h"
#include "gtkfilechooserentry.h"
#include "gtkbox.h"
@@ -39,6 +39,8 @@
#include <stdarg.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkFileChooserDialog:
*
@@ -209,6 +211,8 @@
*
* To summarize, make sure you use a predefined response code
* when you use `GtkFileChooserDialog` to ensure proper operation.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
typedef struct _GtkFileChooserDialogPrivate GtkFileChooserDialogPrivate;
@@ -716,6 +720,8 @@ gtk_file_chooser_dialog_new_valist (const char *title,
* This function is analogous to [ctor@Gtk.Dialog.new_with_buttons].
*
* Returns: a new `GtkFileChooserDialog`
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GtkWidget *
gtk_file_chooser_dialog_new (const char *title,

View File

@@ -19,7 +19,7 @@
#ifndef __GTK_FILE_CHOOSER_ENTRY_H__
#define __GTK_FILE_CHOOSER_ENTRY_H__
#include "gtkfilechooser.h"
#include "deprecated/gtkfilechooser.h"
G_BEGIN_DECLS

View File

@@ -23,9 +23,8 @@
#include "gtknativedialogprivate.h"
#include "gtkprivate.h"
#include "gtkfilechooserdialog.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserwidget.h"
#include "deprecated/gtkfilechooserdialog.h"
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtksizerequest.h"
@@ -37,6 +36,8 @@
#include "gtklabel.h"
#include "gtkfilefilterprivate.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkFileChooserNative:
*
@@ -186,6 +187,8 @@
* are not supported:
*
* * Shortcut folders.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
enum {
@@ -218,6 +221,8 @@ G_DEFINE_TYPE_WITH_CODE (GtkFileChooserNative, gtk_file_chooser_native, GTK_TYPE
* Retrieves the custom label text for the accept button.
*
* Returns: (nullable): The custom label
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
const char *
gtk_file_chooser_native_get_accept_label (GtkFileChooserNative *self)
@@ -240,6 +245,8 @@ gtk_file_chooser_native_get_accept_label (GtkFileChooserNative *self)
* a keyboard accelerator called a mnemonic.
*
* Pressing Alt and that key should activate the button.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_native_set_accept_label (GtkFileChooserNative *self,
@@ -260,6 +267,8 @@ gtk_file_chooser_native_set_accept_label (GtkFileChooserNative *self,
* Retrieves the custom label text for the cancel button.
*
* Returns: (nullable): The custom label
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
const char *
gtk_file_chooser_native_get_cancel_label (GtkFileChooserNative *self)
@@ -282,6 +291,8 @@ gtk_file_chooser_native_get_cancel_label (GtkFileChooserNative *self)
* a keyboard accelerator called a mnemonic.
*
* Pressing Alt and that key should activate the button.
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
void
gtk_file_chooser_native_set_cancel_label (GtkFileChooserNative *self,
@@ -527,6 +538,8 @@ gtk_file_chooser_native_init (GtkFileChooserNative *self)
* Creates a new `GtkFileChooserNative`.
*
* Returns: a new `GtkFileChooserNative`
*
* Deprecated: 4.10: Use [class@Gtk.FileDialog] instead
*/
GtkFileChooserNative *
gtk_file_chooser_native_new (const char *title,

View File

@@ -23,11 +23,8 @@
#include "gtknativedialogprivate.h"
#include "gtkprivate.h"
#include "gtkfilechooserdialog.h"
#include "deprecated/gtkdialog.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserwidget.h"
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
#include "gtksettings.h"
@@ -39,6 +36,8 @@
#include "gtkwindowprivate.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct {
GtkFileChooserNative *self;

View File

@@ -19,7 +19,7 @@
#ifndef __GTK_FILE_CHOOSER_NATIVE_PRIVATE_H__
#define __GTK_FILE_CHOOSER_NATIVE_PRIVATE_H__
#include <gtk/gtkfilechoosernative.h>
#include <gtk/deprecated/gtkfilechoosernative.h>
G_BEGIN_DECLS

View File

@@ -24,9 +24,8 @@
#include <glib/gi18n-lib.h>
#include "gtkprivate.h"
#include "gtkfilechooserdialog.h"
#include "deprecated/gtkfilechooserdialog.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserwidget.h"
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtksizerequest.h"
@@ -42,6 +41,8 @@
#include "macos/gdkmacosdisplay-private.h"
#include "macos/gdkmacossurface-private.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct {
GtkFileChooserNative *self;

View File

@@ -29,9 +29,8 @@
#include "gtknativedialogprivate.h"
#include "gtkprivate.h"
#include "gtkfilechooserdialog.h"
#include "deprecated/gtkfilechooserdialog.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserwidget.h"
#include "gtkfilechooserwidgetprivate.h"
#include "gtkfilechooserutils.h"
#include "gtksizerequest.h"
@@ -48,6 +47,8 @@
#include <shlobj.h>
#include <windows.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct {
GtkFileChooserNative *self;

View File

@@ -19,7 +19,7 @@
#ifndef __GTK_FILE_CHOOSER_PRIVATE_H__
#define __GTK_FILE_CHOOSER_PRIVATE_H__
#include "gtkfilechooser.h"
#include "deprecated/gtkfilechooser.h"
#include "gtkfilesystemmodel.h"
#include "deprecated/gtkliststore.h"
#include "gtkrecentmanager.h"

View File

@@ -19,12 +19,14 @@
#include "config.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "deprecated/gtkfilechooser.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
#include <glib/gi18n-lib.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static gboolean delegate_set_current_folder (GtkFileChooser *chooser,
GFile *file,
GError **error);

View File

@@ -19,7 +19,7 @@
#include "config.h"
#include "gtkfilechooserwidget.h"
#include "deprecated/gtkfilechooserwidget.h"
#include "gtkfilechooserwidgetprivate.h"
#include "gtkbitset.h"
@@ -32,10 +32,10 @@
#include "gtkdroptarget.h"
#include "gtkentry.h"
#include "gtkfilechooserprivate.h"
#include "gtkfilechooserdialog.h"
#include "deprecated/gtkfilechooserdialog.h"
#include "deprecated/gtkfilechooser.h"
#include "gtkfilechooserentry.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "gtkfilesystemmodel.h"
#include "gtkfilethumbnail.h"
#include "gtkgestureclick.h"
@@ -44,7 +44,7 @@
#include "gtklabel.h"
#include "gtklistitem.h"
#include "gtkmarshalers.h"
#include "gtkmessagedialog.h"
#include "gtkalertdialog.h"
#include "gtkmountoperation.h"
#include "gtkmultiselection.h"
#include "gtkpaned.h"
@@ -107,6 +107,8 @@
#include <io.h>
#endif
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkFileChooserWidget:
*
@@ -119,6 +121,8 @@
* # CSS nodes
*
* `GtkFileChooserWidget` has a single CSS node with name filechooser.
*
* Deprecated: 4.10: Direct use of `GtkFileChooserWidget` is deprecated
*/
/* 150 mseconds of delay */
@@ -665,26 +669,12 @@ error_message (GtkFileChooserWidget *impl,
const char *detail)
{
GtkWindow *parent = get_toplevel (GTK_WIDGET (impl));
GtkWidget *dialog;
GtkAlertDialog *dialog;
dialog = gtk_message_dialog_new (parent,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"%s",
msg);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", detail);
if (parent && gtk_window_has_group (parent))
gtk_window_group_add_window (gtk_window_get_group (parent),
GTK_WINDOW (dialog));
gtk_window_present (GTK_WINDOW (dialog));
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_window_destroy),
NULL);
dialog = gtk_alert_dialog_new ("%s", msg);
gtk_alert_dialog_set_detail (dialog, detail);
gtk_alert_dialog_show (dialog, parent);
g_object_unref (dialog);
}
/* Shows a simple error dialog relative to a path. Frees the GError as well. */
@@ -1125,15 +1115,16 @@ typedef struct {
} ConfirmDeleteData;
static void
on_confirm_delete_response (GtkWidget *dialog,
int response,
gpointer user_data)
on_confirm_delete_response (GObject *source,
GAsyncResult *result,
void *user_data)
{
ConfirmDeleteData *data = user_data;
int button;
gtk_window_destroy (GTK_WINDOW (dialog));
button = gtk_alert_dialog_choose_finish (GTK_ALERT_DIALOG (source), result);
if (response == GTK_RESPONSE_ACCEPT)
if (button == 1)
{
GError *error = NULL;
@@ -1150,7 +1141,7 @@ confirm_delete (GtkFileChooserWidget *impl,
GFileInfo *info)
{
GtkWindow *toplevel;
GtkWidget *dialog;
GtkAlertDialog *dialog;
const char *name;
ConfirmDeleteData *data;
@@ -1158,30 +1149,16 @@ confirm_delete (GtkFileChooserWidget *impl,
toplevel = get_toplevel (GTK_WIDGET (impl));
dialog = gtk_message_dialog_new (toplevel,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
_("Are you sure you want to permanently delete “%s”?"),
name);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("If you delete an item, it will be permanently lost."));
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Delete"), GTK_RESPONSE_ACCEPT);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (gtk_window_has_group (toplevel))
gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (dialog));
gtk_widget_show (dialog);
data = g_new (ConfirmDeleteData, 1);
data->impl = impl;
data->file = file;
g_signal_connect (dialog, "response",
G_CALLBACK (on_confirm_delete_response),
data);
dialog = gtk_alert_dialog_new (_("Are you sure you want to permanently delete “%s”?"), name);
gtk_alert_dialog_set_detail (dialog, _("If you delete an item, it will be permanently lost."));
gtk_alert_dialog_set_buttons (dialog, (const char *[]) { _("_Cancel"), _("_Delete"), NULL });
gtk_alert_dialog_set_cancel_button (dialog, 0);
gtk_alert_dialog_set_default_button (dialog, 1);
gtk_alert_dialog_choose (dialog, toplevel, NULL, on_confirm_delete_response, data);
}
static void
@@ -4928,18 +4905,6 @@ get_display_name_from_file_list (GtkFileChooserWidget *impl)
return g_file_info_get_display_name (info);
}
static void
add_custom_button_to_dialog (GtkDialog *dialog,
const char *mnemonic_label,
int response_id)
{
GtkWidget *button;
button = gtk_button_new_with_mnemonic (mnemonic_label);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
}
/* Every time we request a response explicitly, we need to save the selection to
* the recently-used list, as requesting a response means, “the dialog is confirmed”.
*/
@@ -4951,13 +4916,16 @@ request_response_and_add_to_recent_list (GtkFileChooserWidget *impl)
}
static void
on_confirm_overwrite_response (GtkWidget *dialog,
int response,
gpointer user_data)
on_confirm_overwrite_response (GObject *source,
GAsyncResult *result,
void *user_data)
{
GtkFileChooserWidget *impl = user_data;
int button;
if (response == GTK_RESPONSE_ACCEPT)
button = gtk_alert_dialog_choose_finish (GTK_ALERT_DIALOG (source), result);
if (button == 1)
{
/* Dialog is now going to be closed, so prevent any button/key presses to
* file list (will be restablished on next map()). Fixes data loss bug #2288 */
@@ -4965,8 +4933,6 @@ on_confirm_overwrite_response (GtkWidget *dialog,
request_response_and_add_to_recent_list (impl);
}
gtk_window_destroy (GTK_WINDOW (dialog));
}
/* Presents an overwrite confirmation dialog */
@@ -4976,33 +4942,24 @@ confirm_dialog_should_accept_filename (GtkFileChooserWidget *impl,
const char *folder_display_name)
{
GtkWindow *toplevel;
GtkWidget *dialog;
GtkAlertDialog *dialog;
char *detail;
toplevel = get_toplevel (GTK_WIDGET (impl));
dialog = gtk_message_dialog_new (toplevel,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
_("A file named “%s” already exists. Do you want to replace it?"),
file_part);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
_("The file already exists in “%s”. Replacing it will "
"overwrite its contents."),
folder_display_name);
dialog = gtk_alert_dialog_new (_("A file named “%s” already exists. Do you want to replace it?"),
file_part);
detail = g_strdup_printf (_("The file already exists in “%s”. Replacing it will "
"overwrite its contents."),
folder_display_name);
gtk_alert_dialog_set_detail (dialog, detail);
g_free (detail);
gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"), GTK_RESPONSE_ACCEPT);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
if (gtk_window_has_group (toplevel))
gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (dialog));
gtk_window_present (GTK_WINDOW (dialog));
g_signal_connect (dialog, "response",
G_CALLBACK (on_confirm_overwrite_response),
impl);
gtk_alert_dialog_set_buttons (dialog, (const char *[]) { _("_Cancel"), _("_Replace"), NULL });
gtk_alert_dialog_set_cancel_button (dialog, 0);
gtk_alert_dialog_set_default_button (dialog, 1);
gtk_alert_dialog_choose (dialog, toplevel, NULL, on_confirm_overwrite_response, impl);
g_object_unref (dialog);
}
struct GetDisplayNameData
@@ -6714,6 +6671,13 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
"",
GTK_PARAM_READABLE));
/**
* GtkFileChooserWidget:show-time:
*
* Whether to show the time.
*
* Since: 4.10
*/
g_object_class_install_property (gobject_class, PROP_SHOW_TIME,
g_param_spec_boolean ("show-time", NULL, NULL,
FALSE,
@@ -7298,6 +7262,8 @@ gtk_file_chooser_widget_init (GtkFileChooserWidget *impl)
* `GtkFileChooserDialog`.
*
* Returns: a new `GtkFileChooserWidget`
*
* Deprecated: 4.10: Direct use of `GtkFileChooserWidget` is deprecated
*/
GtkWidget *
gtk_file_chooser_widget_new (GtkFileChooserAction action)

View File

@@ -22,7 +22,7 @@
#define __GTK_FILE_CHOOSER_WIDGET_PRIVATE_H__
#include <glib.h>
#include "gtkfilechooserwidget.h"
#include "deprecated/gtkfilechooserwidget.h"
#include "gtkselectionmodel.h"
G_BEGIN_DECLS

1118
gtk/gtkfiledialog.c Normal file

File diff suppressed because it is too large Load Diff

151
gtk/gtkfiledialog.h Normal file
View File

@@ -0,0 +1,151 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2022 Red Hat, Inc.
*
* 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 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/>.
*/
#pragma once
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkfilefilter.h>
G_BEGIN_DECLS
#define GTK_TYPE_FILE_DIALOG (gtk_file_dialog_get_type ())
GDK_AVAILABLE_IN_4_10
G_DECLARE_FINAL_TYPE (GtkFileDialog, gtk_file_dialog, GTK, FILE_DIALOG, GObject)
GDK_AVAILABLE_IN_4_10
GtkFileDialog * gtk_file_dialog_new (void);
GDK_AVAILABLE_IN_4_10
const char * gtk_file_dialog_get_title (GtkFileDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_set_title (GtkFileDialog *self,
const char *title);
GDK_AVAILABLE_IN_4_10
gboolean gtk_file_dialog_get_modal (GtkFileDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_set_modal (GtkFileDialog *self,
gboolean modal);
GDK_AVAILABLE_IN_4_10
GListModel * gtk_file_dialog_get_filters (GtkFileDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_set_filters (GtkFileDialog *self,
GListModel *filters);
GDK_AVAILABLE_IN_4_10
GtkFileFilter * gtk_file_dialog_get_current_filter (GtkFileDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_set_current_filter (GtkFileDialog *self,
GtkFileFilter *filter);
GDK_AVAILABLE_IN_4_10
GListModel * gtk_file_dialog_get_shortcut_folders
(GtkFileDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_set_shortcut_folders
(GtkFileDialog *self,
GListModel *shortcut_folders);
GDK_AVAILABLE_IN_4_10
GFile * gtk_file_dialog_get_current_folder (GtkFileDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_set_current_folder (GtkFileDialog *self,
GFile *folder);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_open (GtkFileDialog *self,
GtkWindow *parent,
GFile *current_file,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
GFile * gtk_file_dialog_open_finish (GtkFileDialog *self,
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_select_folder (GtkFileDialog *self,
GtkWindow *parent,
GFile *current_folder,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
GFile * gtk_file_dialog_select_folder_finish
(GtkFileDialog *self,
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_save (GtkFileDialog *self,
GtkWindow *parent,
GFile *current_file,
const char *current_name,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
GFile * gtk_file_dialog_save_finish (GtkFileDialog *self,
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_open_multiple (GtkFileDialog *self,
GtkWindow *parent,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
GListModel * gtk_file_dialog_open_multiple_finish
(GtkFileDialog *self,
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_4_10
void gtk_file_dialog_select_multiple_folders
(GtkFileDialog *self,
GtkWindow *parent,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
GListModel * gtk_file_dialog_select_multiple_folders_finish
(GtkFileDialog *self,
GAsyncResult *result,
GError **error);
G_END_DECLS

View File

@@ -21,9 +21,9 @@
#include <glib/gprintf.h>
#include <string.h>
#include "gtkfontchooserdialog.h"
#include "gtkfontchooser.h"
#include "gtkfontchooserwidget.h"
#include "gtkfontchooserdialogprivate.h"
#include "deprecated/gtkfontchooser.h"
#include "deprecated/gtkfontchooserwidget.h"
#include "gtkfontchooserwidgetprivate.h"
#include "gtkfontchooserutils.h"
#include "gtkbox.h"
@@ -32,12 +32,14 @@
#include "gtkprivate.h"
#include "gtkwidget.h"
#include "gtksettings.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include "gtktogglebutton.h"
#include "gtkheaderbar.h"
#include "gtkactionable.h"
#include "gtkeventcontrollerkey.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct _GtkFontChooserDialogClass GtkFontChooserDialogClass;
struct _GtkFontChooserDialog
@@ -72,6 +74,8 @@ struct _GtkFontChooserDialogClass
* The `GtkFontChooserDialog` implementation of the `GtkBuildable`
* interface exposes the buttons with the names “select_button”
* and “cancel_button”.
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] instead
*/
static void gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface);
@@ -288,6 +292,8 @@ gtk_font_chooser_dialog_init (GtkFontChooserDialog *dialog)
* Creates a new `GtkFontChooserDialog`.
*
* Returns: a new `GtkFontChooserDialog`
*
* Deprecated: 4.10: Use [class@Gtk.FontDialog] instead
*/
GtkWidget*
gtk_font_chooser_dialog_new (const char *title,
@@ -324,3 +330,10 @@ gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
return parent_buildable_iface->get_internal_child (buildable, builder, childname);
}
void
gtk_font_chooser_dialog_set_filter (GtkFontChooserDialog *dialog,
GtkFilter *filter)
{
gtk_font_chooser_widget_set_filter (GTK_FONT_CHOOSER_WIDGET (dialog->fontchooser), filter);
}

View File

@@ -0,0 +1,31 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2017 Red Hat, Inc.
*
* 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 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/>.
*/
#ifndef __GTK_FONT_CHOOSER_DIALOG_PRIVATE_H__
#define __GTK_FONT_CHOOSER_DIALOG_PRIVATE_H__
#include "deprecated/gtkfontchooserdialog.h"
#include "gtkfilter.h"
G_BEGIN_DECLS
void gtk_font_chooser_dialog_set_filter (GtkFontChooserDialog *dialog,
GtkFilter *filter);
G_END_DECLS
#endif /* __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__ */

View File

@@ -26,6 +26,8 @@
#include "gtkfontchooserutils.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static GtkFontChooser *
get_delegate (GtkFontChooser *receiver)
{

View File

@@ -25,7 +25,7 @@
#ifndef __GTK_FONT_CHOOSER_UTILS_H__
#define __GTK_FONT_CHOOSER_UTILS_H__
#include "gtkfontchooserprivate.h"
#include "deprecated/gtkfontchooserprivate.h"
G_BEGIN_DECLS

View File

@@ -21,7 +21,7 @@
#include <glib/gprintf.h>
#include <string.h>
#include "gtkfontchooserwidget.h"
#include "deprecated/gtkfontchooserwidget.h"
#include "gtkfontchooserwidgetprivate.h"
#include "gtkadjustment.h"
@@ -34,7 +34,7 @@
#include "gtkfilter.h"
#include "gtkframe.h"
#include "gtkgrid.h"
#include "gtkfontchooser.h"
#include "deprecated/gtkfontchooser.h"
#include "gtkfontchooserutils.h"
#include <glib/gi18n-lib.h>
#include "gtklabel.h"
@@ -48,7 +48,7 @@
#include "gtktextview.h"
#include "gtkwidgetprivate.h"
#include "gtksettings.h"
#include "gtkdialog.h"
#include "deprecated/gtkdialog.h"
#include "gtkgestureclick.h"
#include "gtkeventcontrollerscroll.h"
#include "gtkroot.h"
@@ -63,12 +63,15 @@
#include "gtksortlistmodel.h"
#include "gtkstringsorter.h"
#include "gtkdropdown.h"
#include "gtkmultifilter.h"
#include <hb-ot.h>
#include "language-names.h"
#include "open-type-layout.h"
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkFontChooserWidget:
*
@@ -89,6 +92,8 @@
* # CSS nodes
*
* `GtkFontChooserWidget` has a single CSS node with name fontchooser.
*
* Deprecated: 4.10: Direct use of `GtkFontChooserWidget` is deprecated.
*/
typedef struct _GtkFontChooserWidgetClass GtkFontChooserWidgetClass;
@@ -105,6 +110,7 @@ struct _GtkFontChooserWidget
GtkSingleSelection *selection;
GtkCustomFilter *custom_filter;
GtkCustomFilter *user_filter;
GtkCustomFilter *multi_filter;
GtkFilterListModel *filter_model;
GtkWidget *preview;
@@ -144,6 +150,8 @@ struct _GtkFontChooserWidget
gpointer filter_data;
GDestroyNotify filter_data_destroy;
GtkFilter *filter;
guint last_fontconfig_timestamp;
GtkFontChooserLevel level;
@@ -1295,6 +1303,8 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *self)
* Creates a new `GtkFontChooserWidget`.
*
* Returns: a new `GtkFontChooserWidget`
*
* Deprecated: 4.10: Direct use of `GtkFontChooserWidget` is deprecated.
*/
GtkWidget *
gtk_font_chooser_widget_new (void)
@@ -1325,6 +1335,8 @@ gtk_font_chooser_widget_finalize (GObject *object)
g_free (fontchooser->font_features);
g_clear_object (&fontchooser->filter);
G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->finalize (object);
}
@@ -2976,3 +2988,14 @@ gtk_font_chooser_widget_get_tweak_action (GtkWidget *widget)
return fontchooser->tweak_action;
}
void
gtk_font_chooser_widget_set_filter (GtkFontChooserWidget *widget,
GtkFilter *filter)
{
if (widget->filter)
gtk_multi_filter_remove (GTK_MULTI_FILTER (widget->multi_filter), 3);
g_set_object (&widget->filter, filter);
if (widget->filter)
gtk_multi_filter_append (GTK_MULTI_FILTER (widget->multi_filter), g_object_ref (filter));
}

View File

@@ -18,12 +18,16 @@
#ifndef __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__
#define __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__
#include "gtkfontchooserwidget.h"
#include "deprecated/gtkfontchooserwidget.h"
#include "gtkfilter.h"
G_BEGIN_DECLS
GAction *gtk_font_chooser_widget_get_tweak_action (GtkWidget *fontchooser);
void gtk_font_chooser_widget_set_filter (GtkFontChooserWidget *widget,
GtkFilter *filter);
G_END_DECLS
#endif /* __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__ */

951
gtk/gtkfontdialog.c Normal file
View File

@@ -0,0 +1,951 @@
/*
* GTK - The GIMP Toolkit
* Copyright (C) 2022 Red Hat, Inc.
* All rights reserved.
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkfontdialog.h"
#include "deprecated/gtkfontchooser.h"
#include "gtkfontchooserdialogprivate.h"
#include "gtkbutton.h"
#include "gtkdialogerror.h"
#include "gtktypebuiltins.h"
#include <glib/gi18n-lib.h>
/**
* GtkFontDialog:
*
* A `GtkFontDialog` object collects the arguments that
* are needed to present a font chooser dialog to the
* user, such as a title for the dialog and whether it
* should be modal.
*
* The dialog is shown with the [method@Gtk.FontDialog.choose_font]
* function or its variants. This API follows the GIO async pattern,
* and the result can be obtained by calling the corresponding
* finish function, such as [method@Gtk.FontDialog.choose_font_finish].
*
* See [class@Gtk.FontDialogButton] for a convenient control
* that uses `GtkFontDialog` and presents the results.
*
* `GtkFontDialog was added in GTK 4.10.
*/
/* {{{ GObject implementation */
struct _GtkFontDialog
{
GObject parent_instance;
char *title;
PangoLanguage *language;
PangoFontMap *fontmap;
unsigned int modal : 1;
GtkFilter *filter;
};
enum
{
PROP_TITLE = 1,
PROP_MODAL,
PROP_LANGUAGE,
PROP_FONT_MAP,
PROP_FILTER,
NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES];
G_DEFINE_TYPE (GtkFontDialog, gtk_font_dialog, G_TYPE_OBJECT)
static void
gtk_font_dialog_init (GtkFontDialog *self)
{
self->modal = TRUE;
self->language = pango_language_get_default ();
}
static void
gtk_font_dialog_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GtkFontDialog *self = GTK_FONT_DIALOG (object);
switch (property_id)
{
case PROP_TITLE:
g_value_set_string (value, self->title);
break;
case PROP_MODAL:
g_value_set_boolean (value, self->modal);
break;
case PROP_LANGUAGE:
g_value_set_boxed (value, self->language);
break;
case PROP_FONT_MAP:
g_value_set_object (value, self->fontmap);
break;
case PROP_FILTER:
g_value_set_object (value, self->filter);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_font_dialog_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GtkFontDialog *self = GTK_FONT_DIALOG (object);
switch (property_id)
{
case PROP_TITLE:
gtk_font_dialog_set_title (self, g_value_get_string (value));
break;
case PROP_MODAL:
gtk_font_dialog_set_modal (self, g_value_get_boolean (value));
break;
case PROP_LANGUAGE:
gtk_font_dialog_set_language (self, g_value_get_boxed (value));
break;
case PROP_FONT_MAP:
gtk_font_dialog_set_font_map (self, g_value_get_object (value));
break;
case PROP_FILTER:
gtk_font_dialog_set_filter (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_font_dialog_finalize (GObject *object)
{
GtkFontDialog *self = GTK_FONT_DIALOG (object);
g_free (self->title);
g_clear_object (&self->fontmap);
g_clear_object (&self->filter);
G_OBJECT_CLASS (gtk_font_dialog_parent_class)->finalize (object);
}
static void
gtk_font_dialog_class_init (GtkFontDialogClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->get_property = gtk_font_dialog_get_property;
object_class->set_property = gtk_font_dialog_set_property;
object_class->finalize = gtk_font_dialog_finalize;
/**
* GtkFontDialog:title: (attributes org.gtk.Property.get=gtk_font_dialog_get_title org.gtk.Property.set=gtk_font_dialog_set_title)
*
* A title that may be shown on the font chooser
* dialog that is presented by [method@Gtk.FontDialog.choose_font].
*
* Since: 4.10
*/
properties[PROP_TITLE] =
g_param_spec_string ("title", NULL, NULL,
NULL,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFontDialog:modal: (attributes org.gtk.Property.get=gtk_font_dialog_get_modal org.gtk.Property.set=gtk_font_dialog_set_modal)
*
* Whether the font chooser dialog is modal.
*
* Since: 4.10
*/
properties[PROP_MODAL] =
g_param_spec_boolean ("modal", NULL, NULL,
TRUE,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFontDialog:language: (attributes org.gtk.Property.get=gtk_font_dialog_get_language org.gtk.Property.set=gtk_font_dialog_set_language)
*
* The language for which the font features are selected.
*
* Since: 4.10
*/
properties[PROP_LANGUAGE] =
g_param_spec_boxed ("language", NULL, NULL,
PANGO_TYPE_LANGUAGE,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFontDialog:font-map: (attributes org.gtk.Property.get=gtk_font_dialog_get_font_map org.gtk.Property.set=gtk_font_dialog_set_font_map)
*
* Sets a custom font map to select fonts from.
*
* A custom font map can be used to present application-specific
* fonts instead of or in addition to the normal system fonts.
*
* Since: 4.10
*/
properties[PROP_FONT_MAP] =
g_param_spec_object ("font-map", NULL, NULL,
PANGO_TYPE_FONT_MAP,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkFontDialog:filter: (attributes org.gtk.Property.get=gtk_font_dialog_get_filter org.gtk.Property.set=gtk_font_dialog_set_filter)
*
* Sets a filter to restrict what fonts are shown
* in the font chooser dialog.
*
* Since: 4.10
*/
properties[PROP_FILTER] =
g_param_spec_object ("filter", NULL, NULL,
GTK_TYPE_FILTER,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
}
/* }}} */
/* {{{ API: Constructor */
/**
* gtk_font_dialog_new:
*
* Creates a new `GtkFontDialog` object.
*
* Returns: the new `GtkFontDialog`
*
* Since: 4.10
*/
GtkFontDialog *
gtk_font_dialog_new (void)
{
return g_object_new (GTK_TYPE_FONT_DIALOG, NULL);
}
/* }}} */
/* {{{ API: Getters and setters */
/**
* gtk_font_dialog_get_title:
* @self: a `GtkFontDialog`
*
* Returns the title that will be shown on the
* font chooser dialog.
*
* Returns: the title
*
* Since: 4.10
*/
const char *
gtk_font_dialog_get_title (GtkFontDialog *self)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), NULL);
return self->title;
}
/**
* gtk_font_dialog_set_title:
* @self: a `GtkFontDialog`
* @title: the new title
*
* Sets the title that will be shown on the
* font chooser dialog.
*
* Since: 4.10
*/
void
gtk_font_dialog_set_title (GtkFontDialog *self,
const char *title)
{
char *new_title;
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
g_return_if_fail (title != NULL);
if (g_strcmp0 (self->title, title) == 0)
return;
new_title = g_strdup (title);
g_free (self->title);
self->title = new_title;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]);
}
/**
* gtk_font_dialog_get_modal:
* @self: a `GtkFontDialog`
*
* Returns whether the font chooser dialog
* blocks interaction with the parent window
* while it is presented.
*
* Returns: `TRUE` if the font chooser dialog is modal
*
* Since: 4.10
*/
gboolean
gtk_font_dialog_get_modal (GtkFontDialog *self)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), TRUE);
return self->modal;
}
/**
* gtk_font_dialog_set_modal:
* @self: a `GtkFontDialog`
* @modal: the new value
*
* Sets whether the font chooser dialog
* blocks interaction with the parent window
* while it is presented.
*
* Since: 4.10
*/
void
gtk_font_dialog_set_modal (GtkFontDialog *self,
gboolean modal)
{
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
if (self->modal == modal)
return;
self->modal = modal;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODAL]);
}
/**
* gtk_font_dialog_get_language:
* @self: a `GtkFontDialog`
*
* Returns the language for which font features are applied.
*
* Returns: (nullable): the language for font features
*
* Since: 4.10
*/
PangoLanguage *
gtk_font_dialog_get_language (GtkFontDialog *self)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), NULL);
return self->language;
}
/**
* gtk_font_dialog_set_language:
* @self: a `GtkFontDialog`
* @language: the language for font features
*
* Sets the language for which font features are applied.
*
* Since: 4.10
*/
void
gtk_font_dialog_set_language (GtkFontDialog *self,
PangoLanguage *language)
{
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
if (self->language == language)
return;
self->language = language;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LANGUAGE]);
}
/**
* gtk_font_dialog_get_font_map:
* @self: a `GtkFontDialog`
*
* Returns the fontmap from which fonts are selected,
* or `NULL` for the default fontmap.
*
* Returns: (nullable) (transfer none): the fontmap
*
* Since: 4.10
*/
PangoFontMap *
gtk_font_dialog_get_font_map (GtkFontDialog *self)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), NULL);
return self->fontmap;
}
/**
* gtk_font_dialog_set_font_map:
* @self: a `GtkFontDialog`
* @fontmap: (nullable): the fontmap
*
* Sets the fontmap from which fonts are selected.
*
* If @fontmap is `NULL`, the default fontmap is used.
*
* Since: 4.10
*/
void
gtk_font_dialog_set_font_map (GtkFontDialog *self,
PangoFontMap *fontmap)
{
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
if (g_set_object (&self->fontmap, fontmap))
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FONT_MAP]);
}
/**
* gtk_font_dialog_get_filter:
* @self: a `GtkFontDialog`
*
* Returns the filter that decides which fonts to display
* in the font chooser dialog.
*
* Returns: (nullable) (transfer none): the filter
*
* Since: 4.10
*/
GtkFilter *
gtk_font_dialog_get_filter (GtkFontDialog *self)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), NULL);
return self->filter;
}
/**
* gtk_font_dialog_set_filter:
* @self: a `GtkFontDialog`
* @filter: (nullable): a `GtkFilter`
*
* Adds a filter that decides which fonts to display
* in the font chooser dialog.
*
* The `GtkFilter` must be able to handle both `PangoFontFamily`
* and `PangoFontFace` objects.
*
* Since: 4.10
*/
void
gtk_font_dialog_set_filter (GtkFontDialog *self,
GtkFilter *filter)
{
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
g_return_if_fail (filter == NULL || GTK_IS_FILTER (filter));
if (g_set_object (&self->filter, filter))
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FILTER]);
}
/* }}} */
/* {{{ Async implementation */
static void response_cb (GTask *task,
int response);
static void
cancelled_cb (GCancellable *cancellable,
GTask *task)
{
response_cb (task, GTK_RESPONSE_CLOSE);
}
typedef struct
{
PangoFontDescription *font_desc;
char *font_features;
PangoLanguage *language;
} FontResult;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static void
response_cb (GTask *task,
int response)
{
GCancellable *cancellable;
GtkFontChooserDialog *window;
GtkFontChooserLevel level;
cancellable = g_task_get_cancellable (task);
if (cancellable)
g_signal_handlers_disconnect_by_func (cancellable, cancelled_cb, task);
window = GTK_FONT_CHOOSER_DIALOG (g_task_get_task_data (task));
level = gtk_font_chooser_get_level (GTK_FONT_CHOOSER (window));
if (response == GTK_RESPONSE_OK)
{
if (level & GTK_FONT_CHOOSER_LEVEL_FEATURES)
{
FontResult font_result;
font_result.font_desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (window));
font_result.font_features = gtk_font_chooser_get_font_features (GTK_FONT_CHOOSER (window));
font_result.language = pango_language_from_string (gtk_font_chooser_get_language (GTK_FONT_CHOOSER (window)));
g_task_return_pointer (task, &font_result, NULL);
g_clear_pointer (&font_result.font_desc, pango_font_description_free);
g_clear_pointer (&font_result.font_features, g_free);
}
else if (level & GTK_FONT_CHOOSER_LEVEL_SIZE)
{
PangoFontDescription *font_desc;
font_desc = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (window));
g_task_return_pointer (task, font_desc, (GDestroyNotify) pango_font_description_free);
}
else if (level & GTK_FONT_CHOOSER_LEVEL_STYLE)
{
PangoFontFace *face;
face = gtk_font_chooser_get_font_face (GTK_FONT_CHOOSER (window));
g_task_return_pointer (task, g_object_ref (face), g_object_unref);
}
else
{
PangoFontFamily *family;
family = gtk_font_chooser_get_font_family (GTK_FONT_CHOOSER (window));
g_task_return_pointer (task, g_object_ref (family), g_object_unref);
}
}
else if (response == GTK_RESPONSE_CLOSE)
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_ABORTED, "Aborted by application");
else if (response == GTK_RESPONSE_CANCEL)
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED, "Cancelled by user");
else
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_FAILED, "Unknown failure (%d)", response);
g_object_unref (task);
}
G_GNUC_END_IGNORE_DEPRECATIONS
static void
dialog_response (GtkDialog *dialog,
int response,
GTask *task)
{
response_cb (task, response);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static GtkWidget *
create_font_chooser (GtkFontDialog *self,
GtkWindow *parent,
PangoFontDescription *initial_value,
GtkFontChooserLevel level)
{
GtkWidget *window;
const char *title;
if (self->title)
title = self->title;
else
title = _("Pick a Font");
window = gtk_font_chooser_dialog_new (title, parent);
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (window), level);
if (self->language)
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (window),
pango_language_to_string (self->language));
if (self->fontmap)
gtk_font_chooser_set_font_map (GTK_FONT_CHOOSER (window), self->fontmap);
if (self->filter)
gtk_font_chooser_dialog_set_filter (GTK_FONT_CHOOSER_DIALOG (window), self->filter);
if (initial_value)
gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (window), initial_value);
return window;
}
G_GNUC_END_IGNORE_DEPRECATIONS
/* }}} */
/* {{{ Async API */
/**
* gtk_font_dialog_choose_family:
* @self: a `GtkFontDialog`
* @parent: (nullable): the parent `GtkWindow`
* @initial_value: (nullable): the initial value
* @cancellable: (nullable): a `GCancellable` to cancel the operation
* @callback: (scope async): a callback to call when the operation is complete
* @user_data: (closure callback): data to pass to @callback
*
* This function initiates a font selection operation by
* presenting a dialog to the user for selecting a font family.
*
* The @callback will be called when the dialog is dismissed.
* It should call [method@Gtk.FontDialog.choose_family_finish]
* to obtain the result.
*
* Since: 4.10
*/
void
gtk_font_dialog_choose_family (GtkFontDialog *self,
GtkWindow *parent,
PangoFontFamily *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GtkWidget *window;
PangoFontDescription *desc = NULL;
GTask *task;
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
if (initial_value)
{
desc = pango_font_description_new ();
pango_font_description_set_family (desc, pango_font_family_get_name (initial_value));
}
window = create_font_chooser (self, parent, desc,
GTK_FONT_CHOOSER_LEVEL_FAMILY);
g_clear_pointer (&desc, pango_font_description_free);
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_font_dialog_choose_family);
g_task_set_task_data (task, window, (GDestroyNotify) gtk_window_destroy);
if (cancellable)
g_signal_connect (cancellable, "cancelled", G_CALLBACK (cancelled_cb), task);
g_signal_connect (window, "response", G_CALLBACK (dialog_response), task);
gtk_window_present (GTK_WINDOW (window));
}
/**
* gtk_font_dialog_choose_family_finish:
* @self: a `GtkFontDialog`
* @result: a `GAsyncResult`
* @error: return location for an error
*
* Finishes the [method@Gtk.FontDialog.choose_family] call
* and returns the resulting family.
*
* This function never returns an error. If the operation is
* not finished successfully, the value passed as @initial_value
* to [method@Gtk.FontDialog.choose_family] is returned.
* Returns: (nullable) (transfer full): the selected family
*
* Since: 4.10
*/
PangoFontFamily *
gtk_font_dialog_choose_family_finish (GtkFontDialog *self,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), NULL);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_family, NULL);
return g_task_propagate_pointer (G_TASK (result), error);
}
/**
* gtk_font_dialog_choose_face:
* @self: a `GtkFontDialog`
* @parent: (nullable): the parent `GtkWindow`
* @initial_value: (nullable): the initial value
* @cancellable: (nullable): a `GCancellable` to cancel the operation
* @callback: (scope async): a callback to call when the operation is complete
* @user_data: (closure callback): data to pass to @callback
*
* This function initiates a font selection operation by
* presenting a dialog to the user for selecting a font face
* (i.e. a font family and style, but not a specific font size).
*
* The @callback will be called when the dialog is dismissed.
* It should call [method@Gtk.FontDialog.choose_face_finish]
* to obtain the result.
*
* Since: 4.10
*/
void
gtk_font_dialog_choose_face (GtkFontDialog *self,
GtkWindow *parent,
PangoFontFace *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GtkWidget *window;
PangoFontDescription *desc = NULL;
GTask *task;
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
if (initial_value)
desc = pango_font_face_describe (initial_value);
window = create_font_chooser (self, parent, desc,
GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_STYLE);
g_clear_pointer (&desc, pango_font_description_free);
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_font_dialog_choose_face);
g_task_set_task_data (task, window, (GDestroyNotify) gtk_window_destroy);
if (cancellable)
g_signal_connect (cancellable, "cancelled", G_CALLBACK (cancelled_cb), task);
g_signal_connect (window, "response", G_CALLBACK (dialog_response), task);
gtk_window_present (GTK_WINDOW (window));
}
/**
* gtk_font_dialog_choose_face_finish:
* @self: a `GtkFontDialog`
* @result: a `GAsyncResult`
* @error: return location for an error
*
* Finishes the [method@Gtk.FontDialog.choose_face] call
* and returns the resulting font face.
*
* Returns: (nullable) (transfer full): the selected font face
*
* Since: 4.10
*/
PangoFontFace *
gtk_font_dialog_choose_face_finish (GtkFontDialog *self,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), NULL);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_face, NULL);
return g_task_propagate_pointer (G_TASK (result), NULL);
}
/**
* gtk_font_dialog_choose_font:
* @self: a `GtkFontDialog`
* @parent: (nullable): the parent `GtkWindow`
* @initial_value: (nullable): the font to select initially
* @cancellable: (nullable): a `GCancellable` to cancel the operation
* @callback: (scope async): a callback to call when the operation is complete
* @user_data: (closure callback): data to pass to @callback
*
* This function initiates a font selection operation by
* presenting a dialog to the user for selecting a font.
*
* The @callback will be called when the dialog is dismissed.
* It should call [method@Gtk.FontDialog.choose_font_finish]
* to obtain the result.
*
* If you want to let the user select font features as well,
* use [method@Gtk.FontDialog.choose_font_and_features] instead.
*
* Since: 4.10
*/
void
gtk_font_dialog_choose_font (GtkFontDialog *self,
GtkWindow *parent,
PangoFontDescription *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GtkWidget *window;
GTask *task;
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
window = create_font_chooser (self, parent, initial_value,
GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_STYLE |
GTK_FONT_CHOOSER_LEVEL_SIZE |
GTK_FONT_CHOOSER_LEVEL_VARIATIONS);
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_font_dialog_choose_font);
g_task_set_task_data (task, window, (GDestroyNotify) gtk_window_destroy);
if (cancellable)
g_signal_connect (cancellable, "cancelled", G_CALLBACK (cancelled_cb), task);
g_signal_connect (window, "response", G_CALLBACK (dialog_response), task);
gtk_window_present (GTK_WINDOW (window));
}
/**
* gtk_font_dialog_choose_font_finish:
* @self: a `GtkFontDialog`
* @result: a `GAsyncResult`
* @error: return location for an error
*
* Finishes the [method@Gtk.FontDialog.choose_font] call
* and returns the resulting font description.
*
* Returns: (nullable) (transfer full): the selected font
*
* Since: 4.10
*/
PangoFontDescription *
gtk_font_dialog_choose_font_finish (GtkFontDialog *self,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), NULL);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_font, NULL);
return g_task_propagate_pointer (G_TASK (result), NULL);
}
/**
* gtk_font_dialog_choose_font_and_features:
* @self: a `GtkFontDialog`
* @parent: (nullable): the parent `GtkWindow`
* @initial_value: (nullable): the font to select initially
* @cancellable: (nullable): a `GCancellable` to cancel the operation
* @callback: (scope async): a callback to call when the operation is complete
* @user_data: (closure callback): data to pass to @callback
*
* This function initiates a font selection operation by
* presenting a dialog to the user for selecting a font and
* font features.
*
* Font features affect how the font is rendered, for example
* enabling glyph variants or ligatures.
*
* The @callback will be called when the dialog is dismissed.
* It should call [method@Gtk.FontDialog.choose_font_and_features_finish]
* to obtain the result.
*
* Since: 4.10
*/
void
gtk_font_dialog_choose_font_and_features (GtkFontDialog *self,
GtkWindow *parent,
PangoFontDescription *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GtkWidget *window;
GTask *task;
g_return_if_fail (GTK_IS_FONT_DIALOG (self));
window = create_font_chooser (self, parent, initial_value,
GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_STYLE |
GTK_FONT_CHOOSER_LEVEL_SIZE |
GTK_FONT_CHOOSER_LEVEL_VARIATIONS |
GTK_FONT_CHOOSER_LEVEL_FEATURES);
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_font_dialog_choose_font_and_features);
g_task_set_task_data (task, window, (GDestroyNotify) gtk_window_destroy);
if (cancellable)
g_signal_connect (cancellable, "cancelled", G_CALLBACK (cancelled_cb), task);
g_signal_connect (window, "response", G_CALLBACK (dialog_response), task);
gtk_window_present (GTK_WINDOW (window));
}
/**
* gtk_font_dialog_choose_font_and_features_finish:
* @self: a `GtkFontDialog`
* @result: a `GAsyncResult`
* @font_desc: (out caller-allocates): return location for font description
* @font_features: (out caller-allocates): return location for font features
* @language: (out caller-allocates): return location for the language
* @error: return location for an error
*
* Finishes the [method@Gtk.FontDialog.choose_font_and_features]
* call and returns the resulting font description and font features.
*
* Returns: `TRUE` if a font was selected. Otherwise `FALSE` is returned
* and @error is set
*
* Since: 4.10
*/
gboolean
gtk_font_dialog_choose_font_and_features_finish (GtkFontDialog *self,
GAsyncResult *result,
PangoFontDescription **font_desc,
char **font_features,
PangoLanguage **language,
GError **error)
{
FontResult *font_result;
g_return_val_if_fail (GTK_IS_FONT_DIALOG (self), FALSE);
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_font_dialog_choose_font_and_features, FALSE);
font_result = g_task_propagate_pointer (G_TASK (result), error);
if (font_result)
{
*font_desc = g_steal_pointer (&font_result->font_desc);
*font_features = g_steal_pointer (&font_result->font_features);
*language = g_steal_pointer (&font_result->language);
}
return font_result != NULL;
}
/* }}} */
/* vim:set foldmethod=marker expandtab: */

136
gtk/gtkfontdialog.h Normal file
View File

@@ -0,0 +1,136 @@
/* GTK - The GIMP Toolkit
*
* Copyright (C) 2022 Red Hat, Inc.
*
* 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 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/>.
*/
#pragma once
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk/gdk.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkfilter.h>
G_BEGIN_DECLS
#define GTK_TYPE_FONT_DIALOG (gtk_font_dialog_get_type ())
GDK_AVAILABLE_IN_4_10
G_DECLARE_FINAL_TYPE (GtkFontDialog, gtk_font_dialog, GTK, FONT_DIALOG, GObject)
GDK_AVAILABLE_IN_4_10
GtkFontDialog * gtk_font_dialog_new (void);
GDK_AVAILABLE_IN_4_10
const char * gtk_font_dialog_get_title (GtkFontDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_set_title (GtkFontDialog *self,
const char *title);
GDK_AVAILABLE_IN_4_10
gboolean gtk_font_dialog_get_modal (GtkFontDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_set_modal (GtkFontDialog *self,
gboolean modal);
GDK_AVAILABLE_IN_4_10
PangoLanguage * gtk_font_dialog_get_language (GtkFontDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_set_language (GtkFontDialog *self,
PangoLanguage *language);
GDK_AVAILABLE_IN_4_10
PangoFontMap * gtk_font_dialog_get_font_map (GtkFontDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_set_font_map (GtkFontDialog *self,
PangoFontMap *fontmap);
GDK_AVAILABLE_IN_4_10
GtkFilter * gtk_font_dialog_get_filter (GtkFontDialog *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_set_filter (GtkFontDialog *self,
GtkFilter *filter);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_choose_family (GtkFontDialog *self,
GtkWindow *parent,
PangoFontFamily *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
PangoFontFamily *
gtk_font_dialog_choose_family_finish
(GtkFontDialog *self,
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_choose_face (GtkFontDialog *self,
GtkWindow *parent,
PangoFontFace *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
PangoFontFace * gtk_font_dialog_choose_face_finish
(GtkFontDialog *self,
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_choose_font (GtkFontDialog *self,
GtkWindow *parent,
PangoFontDescription *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
PangoFontDescription *
gtk_font_dialog_choose_font_finish
(GtkFontDialog *self,
GAsyncResult *result,
GError **error);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_choose_font_and_features
(GtkFontDialog *self,
GtkWindow *parent,
PangoFontDescription *initial_value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_4_10
gboolean gtk_font_dialog_choose_font_and_features_finish
(GtkFontDialog *self,
GAsyncResult *result,
PangoFontDescription **font_desc,
char **font_features,
PangoLanguage **language,
GError **error);
G_END_DECLS

1047
gtk/gtkfontdialogbutton.c Normal file

File diff suppressed because it is too large Load Diff

112
gtk/gtkfontdialogbutton.h Normal file
View File

@@ -0,0 +1,112 @@
/*
* GTK - The GIMP Toolkit
* Copyright (C) 2022 Red Hat, Inc.
* All rights reserved.
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkbutton.h>
#include <gtk/gtkfontdialog.h>
G_BEGIN_DECLS
#define GTK_TYPE_FONT_DIALOG_BUTTON (gtk_font_dialog_button_get_type ())
GDK_AVAILABLE_IN_4_10
G_DECLARE_FINAL_TYPE (GtkFontDialogButton, gtk_font_dialog_button, GTK, FONT_DIALOG_BUTTON, GtkWidget)
GDK_AVAILABLE_IN_4_10
GtkWidget * gtk_font_dialog_button_new (GtkFontDialog *dialog);
GDK_AVAILABLE_IN_4_10
GtkFontDialog * gtk_font_dialog_button_get_dialog (GtkFontDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_button_set_dialog (GtkFontDialogButton *self,
GtkFontDialog *dialog);
/**
* GtkFontLevel:
* @GTK_FONT_LEVEL_FAMILY: Select a font family
* @GTK_FONT_LEVEL_FACE: Select a font face (i.e. a family and a style)
* @GTK_FONT_LEVEL_FONT: Select a font (i.e. a face with a size, and possibly font variations)
* @GTK_FONT_LEVEL_FEATURES: Select a font and font features
*
* The level of granularity for the font selection.
*
* Depending on this value, the `PangoFontDescription` that
* is returned by [method@Gtk.FontDialogButton.get_font_desc]
* will have more or less fields set.
*/
typedef enum
{
GTK_FONT_LEVEL_FAMILY,
GTK_FONT_LEVEL_FACE,
GTK_FONT_LEVEL_FONT,
GTK_FONT_LEVEL_FEATURES
} GtkFontLevel;
GDK_AVAILABLE_IN_4_10
GtkFontLevel gtk_font_dialog_button_get_level (GtkFontDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_button_set_level (GtkFontDialogButton *self,
GtkFontLevel level);
GDK_AVAILABLE_IN_4_10
PangoFontDescription *
gtk_font_dialog_button_get_font_desc (GtkFontDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_button_set_font_desc (GtkFontDialogButton *self,
const PangoFontDescription *font_desc);
GDK_AVAILABLE_IN_4_10
const char * gtk_font_dialog_button_get_font_features
(GtkFontDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_button_set_font_features
(GtkFontDialogButton *self,
const char *font_features);
GDK_AVAILABLE_IN_4_10
PangoLanguage * gtk_font_dialog_button_get_language (GtkFontDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_button_set_language (GtkFontDialogButton *self,
PangoLanguage *language);
GDK_AVAILABLE_IN_4_10
gboolean gtk_font_dialog_button_get_use_font (GtkFontDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_button_set_use_font (GtkFontDialogButton *self,
gboolean use_font);
GDK_AVAILABLE_IN_4_10
gboolean gtk_font_dialog_button_get_use_size (GtkFontDialogButton *self);
GDK_AVAILABLE_IN_4_10
void gtk_font_dialog_button_set_use_size (GtkFontDialogButton *self,
gboolean use_size);
G_END_DECLS

View File

@@ -38,7 +38,7 @@
#include "gtklabel.h"
#include "gtkbutton.h"
#include "gtkenums.h"
#include "gtkdialog.h"
#include "deprecated/gtkdialog.h"
#include "gtkrevealer.h"
#include "gtkprivate.h"
#include "gtktypebuiltins.h"

View File

@@ -25,11 +25,11 @@
#include "config.h"
#include "gtkmessagedialog.h"
#include "deprecated/gtkmessagedialog.h"
#include "gtkbox.h"
#include "gtkbuildable.h"
#include "gtkdialogprivate.h"
#include "deprecated/gtkdialogprivate.h"
#include <glib/gi18n-lib.h>
#include "gtklabel.h"
#include "gtkprivate.h"
@@ -37,6 +37,8 @@
#include <string.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
* GtkMessageDialog:
*
@@ -96,6 +98,8 @@
*
* The `GtkMessageDialog` implementation of the `GtkBuildable` interface exposes
* the message area as an internal child with the name “message_area”.
*
* Deprecated: 4.10: Use [class@Gtk.AlertDialog] instead
*/
typedef struct
@@ -227,13 +231,13 @@ gtk_message_dialog_set_property (GObject *object,
if (txt)
{
priv->has_secondary_text = TRUE;
gtk_widget_add_css_class (priv->label, "title");
gtk_widget_add_css_class (priv->label, "title");
gtk_widget_show (priv->secondary_label);
}
else
{
priv->has_secondary_text = FALSE;
gtk_widget_remove_css_class (priv->label, "title");
gtk_widget_remove_css_class (priv->label, "title");
gtk_widget_hide (priv->secondary_label);
}
}
@@ -479,6 +483,8 @@ gtk_message_dialog_init (GtkMessageDialog *dialog)
* for more details.
*
* Returns: (transfer none): a new `GtkMessageDialog`
*
* Deprecated: 4.10: Use [class@Gtk.AlertDialog] instead
*/
GtkWidget*
gtk_message_dialog_new (GtkWindow *parent,
@@ -565,6 +571,8 @@ gtk_message_dialog_new (GtkWindow *parent,
* ```
*
* Returns: a new `GtkMessageDialog`
*
* Deprecated: 4.10: Use [class@Gtk.AlertDialog] instead
**/
GtkWidget*
gtk_message_dialog_new_with_markup (GtkWindow *parent,
@@ -602,6 +610,8 @@ gtk_message_dialog_new_with_markup (GtkWindow *parent,
* @str: string with Pango markup
*
* Sets the text of the message dialog.
*
* Deprecated: 4.10: Use [class@Gtk.AlertDialog] instead
*/
void
gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
@@ -622,6 +632,8 @@ gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog,
* @...: arguments for @message_format
*
* Sets the secondary text of the message dialog.
*
* Deprecated: 4.10: Use [class@Gtk.AlertDialog] instead
*/
void
gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
@@ -679,6 +691,8 @@ gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog,
* "%s", msg);
* g_free (msg);
* ```
*
* Deprecated: 4.10: Use [class@Gtk.AlertDialog] instead
*/
void
gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
@@ -726,6 +740,8 @@ gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog,
*
* Returns: (transfer none): A `GtkBox` corresponding to the
* “message area” in the @message_dialog
*
* Deprecated: 4.10: Use [class@Gtk.AlertDialog] instead
*/
GtkWidget *
gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog)

Some files were not shown because too many files have changed in this diff Show More