app: add preferences-dialog-utils.[ch]

with some code from preferences-dialog.c, the file was way too large
(it still is...)
This commit is contained in:
Michael Natterer 2016-09-22 19:13:33 +02:00
parent 1f9451b878
commit 7b0307d22d
4 changed files with 483 additions and 335 deletions

View File

@ -73,6 +73,8 @@ libappdialogs_a_sources = \
palette-import-dialog.h \
preferences-dialog.c \
preferences-dialog.h \
preferences-dialog-utils.c \
preferences-dialog-utils.h \
print-size-dialog.c \
print-size-dialog.h \
quit-dialog.c \

View File

@ -0,0 +1,360 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "dialogs-types.h"
#include "widgets/gimpcolorpanel.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpwidgets-constructors.h"
#include "preferences-dialog-utils.h"
GtkWidget *
prefs_frame_new (const gchar *label,
GtkContainer *parent,
gboolean expand)
{
GtkWidget *frame;
GtkWidget *vbox;
frame = gimp_frame_new (label);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
if (GTK_IS_BOX (parent))
gtk_box_pack_start (GTK_BOX (parent), frame, expand, expand, 0);
else
gtk_container_add (parent, frame);
gtk_widget_show (frame);
return vbox;
}
GtkWidget *
prefs_table_new (gint rows,
GtkContainer *parent)
{
GtkWidget *table;
table = gtk_table_new (rows, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
if (GTK_IS_BOX (parent))
gtk_box_pack_start (GTK_BOX (parent), table, FALSE, FALSE, 0);
else
gtk_container_add (parent, table);
gtk_widget_show (table);
return table;
}
GtkWidget *
prefs_hint_box_new (const gchar *icon_name,
const gchar *text)
{
GtkWidget *hbox;
GtkWidget *image;
GtkWidget *label;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
label = gtk_label_new (text);
gimp_label_set_attributes (GTK_LABEL (label),
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-1);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
gtk_widget_show (hbox);
return hbox;
}
GtkWidget *
prefs_button_add (const gchar *icon_name,
const gchar *label,
GtkBox *box)
{
GtkWidget *button;
button = gimp_icon_button_new (icon_name, label);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_widget_show (button);
return button;
}
GtkWidget *
prefs_check_button_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkBox *vbox)
{
GtkWidget *button;
button = gimp_prop_check_button_new (config, property_name, label);
if (button)
{
gtk_box_pack_start (vbox, button, FALSE, FALSE, 0);
gtk_widget_show (button);
}
return button;
}
GtkWidget *
prefs_check_button_add_with_icon (GObject *config,
const gchar *property_name,
const gchar *label,
const gchar *icon_name,
GtkBox *vbox,
GtkSizeGroup *group)
{
GtkWidget *button;
GtkWidget *hbox;
GtkWidget *image;
button = gimp_prop_check_button_new (config, property_name, label);
if (!button)
return NULL;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
gtk_misc_set_padding (GTK_MISC (image), 2, 2);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
if (group)
gtk_size_group_add_widget (group, image);
return button;
}
GtkWidget *
prefs_widget_add_aligned (GtkWidget *widget,
const gchar *text,
GtkTable *table,
gint table_row,
gboolean left_align,
GtkSizeGroup *group)
{
GtkWidget *label = gimp_table_attach_aligned (table, 0, table_row,
text, 0.0, 0.5,
widget, 1, left_align);
if (group)
gtk_size_group_add_widget (group, label);
return label;
}
GtkWidget *
prefs_color_button_add (GObject *config,
const gchar *property_name,
const gchar *label,
const gchar *title,
GtkTable *table,
gint table_row,
GtkSizeGroup *group,
GimpContext *context)
{
GtkWidget *button;
GParamSpec *pspec;
gboolean has_alpha;
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
property_name);
has_alpha = gimp_param_spec_rgb_has_alpha (pspec);
button = gimp_prop_color_button_new (config, property_name,
title,
PREFS_COLOR_BUTTON_WIDTH,
PREFS_COLOR_BUTTON_HEIGHT,
has_alpha ?
GIMP_COLOR_AREA_SMALL_CHECKS :
GIMP_COLOR_AREA_FLAT);
if (button)
{
if (context)
gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
prefs_widget_add_aligned (button, label, table, table_row, TRUE, group);
}
return button;
}
GtkWidget *
prefs_entry_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *entry = gimp_prop_entry_new (config, property_name, -1);
if (entry)
prefs_widget_add_aligned (entry, label, table, table_row, FALSE, group);
return entry;
}
GtkWidget *
prefs_spin_button_add (GObject *config,
const gchar *property_name,
gdouble step_increment,
gdouble page_increment,
gint digits,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *button = gimp_prop_spin_button_new (config, property_name,
step_increment,
page_increment,
digits);
if (button)
prefs_widget_add_aligned (button, label, table, table_row, TRUE, group);
return button;
}
GtkWidget *
prefs_memsize_entry_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *entry = gimp_prop_memsize_entry_new (config, property_name);
if (entry)
prefs_widget_add_aligned (entry, label, table, table_row, TRUE, group);
return entry;
}
GtkWidget *
prefs_enum_combo_box_add (GObject *config,
const gchar *property_name,
gint minimum,
gint maximum,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *combo = gimp_prop_enum_combo_box_new (config, property_name,
minimum, maximum);
if (combo)
prefs_widget_add_aligned (combo, label, table, table_row, FALSE, group);
return combo;
}
GtkWidget *
prefs_boolean_combo_box_add (GObject *config,
const gchar *property_name,
const gchar *true_text,
const gchar *false_text,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *combo = gimp_prop_boolean_combo_box_new (config, property_name,
true_text, false_text);
if (combo)
prefs_widget_add_aligned (combo, label, table, table_row, FALSE, group);
return combo;
}
#ifdef HAVE_ISO_CODES
GtkWidget *
prefs_language_combo_box_add (GObject *config,
const gchar *property_name,
GtkBox *vbox)
{
GtkWidget *combo = gimp_prop_language_combo_box_new (config, property_name);
if (combo)
{
gtk_box_pack_start (vbox, combo, FALSE, FALSE, 0);
gtk_widget_show (combo);
}
return combo;
}
#endif
GtkWidget *
prefs_profile_combo_box_add (GObject *config,
const gchar *property_name,
GtkListStore *profile_store,
const gchar *dialog_title,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *combo = gimp_prop_profile_combo_box_new (config,
property_name,
profile_store,
dialog_title);
if (combo)
prefs_widget_add_aligned (combo, label, table, table_row, FALSE, group);
return combo;
}

View File

@ -0,0 +1,118 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PREFERENCES_DIALOG_UTILS_H__
#define __PREFERENCES_DIALOG_UTILS_H__
#define PREFS_COLOR_BUTTON_WIDTH 40
#define PREFS_COLOR_BUTTON_HEIGHT 24
GtkWidget * prefs_frame_new (const gchar *label,
GtkContainer *parent,
gboolean expand);
GtkWidget * prefs_table_new (gint rows,
GtkContainer *parent);
GtkWidget * prefs_hint_box_new (const gchar *icon_name,
const gchar *text);
GtkWidget * prefs_button_add (const gchar *icon_name,
const gchar *label,
GtkBox *box);
GtkWidget * prefs_check_button_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkBox *box);
GtkWidget * prefs_check_button_add_with_icon (GObject *config,
const gchar *property_name,
const gchar *label,
const gchar *icon_name,
GtkBox *box,
GtkSizeGroup *group);
GtkWidget * prefs_widget_add_aligned (GtkWidget *widget,
const gchar *text,
GtkTable *table,
gint table_row,
gboolean left_align,
GtkSizeGroup *group);
GtkWidget * prefs_color_button_add (GObject *config,
const gchar *property_name,
const gchar *label,
const gchar *title,
GtkTable *table,
gint table_row,
GtkSizeGroup *group,
GimpContext *context);
GtkWidget * prefs_entry_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group);
GtkWidget * prefs_spin_button_add (GObject *config,
const gchar *property_name,
gdouble step_increment,
gdouble page_increment,
gint digits,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group);
GtkWidget * prefs_memsize_entry_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group);
GtkWidget * prefs_enum_combo_box_add (GObject *config,
const gchar *property_name,
gint minimum,
gint maximum,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group);
GtkWidget * prefs_boolean_combo_box_add (GObject *config,
const gchar *property_name,
const gchar *true_text,
const gchar *false_text,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group);
#ifdef HAVE_ISO_CODES
GtkWidget * prefs_language_combo_box_add (GObject *config,
const gchar *property_name,
GtkBox *vbox);
#endif
GtkWidget * prefs_profile_combo_box_add (GObject *config,
const gchar *property_name,
GtkListStore *profile_store,
const gchar *dialog_title,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group);
#endif /* __PREFERENCES_DIALOG_H__ */

View File

@ -24,7 +24,6 @@
#include "libgimpmath/gimpmath.h"
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "libgimpconfig/gimpconfig.h"
#include "libgimpwidgets/gimpwidgets.h"
@ -33,7 +32,6 @@
#include "config/gimprc.h"
#include "core/gimp.h"
#include "core/gimplist.h"
#include "core/gimptemplate.h"
#include "widgets/gimpaction-history.h"
@ -53,7 +51,6 @@
#include "widgets/gimpstrokeeditor.h"
#include "widgets/gimptemplateeditor.h"
#include "widgets/gimptooleditor.h"
#include "widgets/gimpwidgets-constructors.h"
#include "widgets/gimpwidgets-utils.h"
#include "menus/menus.h"
@ -65,6 +62,7 @@
#include "gui/themes.h"
#include "preferences-dialog.h"
#include "preferences-dialog-utils.h"
#include "resolution-calibrate-dialog.h"
#include "gimp-intl.h"
@ -72,9 +70,6 @@
#define RESPONSE_RESET 1
#define COLOR_BUTTON_WIDTH 40
#define COLOR_BUTTON_HEIGHT 24
/* preferences local functions */
@ -800,333 +795,6 @@ prefs_icon_theme_select_callback (GtkTreeSelection *sel,
}
}
static GtkWidget *
prefs_frame_new (const gchar *label,
GtkContainer *parent,
gboolean expand)
{
GtkWidget *frame;
GtkWidget *vbox;
frame = gimp_frame_new (label);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
if (GTK_IS_BOX (parent))
gtk_box_pack_start (GTK_BOX (parent), frame, expand, expand, 0);
else
gtk_container_add (parent, frame);
gtk_widget_show (frame);
return vbox;
}
static GtkWidget *
prefs_table_new (gint rows,
GtkContainer *parent)
{
GtkWidget *table;
table = gtk_table_new (rows, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
if (GTK_IS_BOX (parent))
gtk_box_pack_start (GTK_BOX (parent), table, FALSE, FALSE, 0);
else
gtk_container_add (parent, table);
gtk_widget_show (table);
return table;
}
static GtkWidget *
prefs_hint_box_new (const gchar *icon_name,
const gchar *text)
{
GtkWidget *hbox;
GtkWidget *image;
GtkWidget *label;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
label = gtk_label_new (text);
gimp_label_set_attributes (GTK_LABEL (label),
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-1);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
gtk_widget_show (label);
gtk_widget_show (hbox);
return hbox;
}
static GtkWidget *
prefs_button_add (const gchar *icon_name,
const gchar *label,
GtkBox *box)
{
GtkWidget *button;
button = gimp_icon_button_new (icon_name, label);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_widget_show (button);
return button;
}
static GtkWidget *
prefs_check_button_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkBox *vbox)
{
GtkWidget *button;
button = gimp_prop_check_button_new (config, property_name, label);
if (button)
{
gtk_box_pack_start (vbox, button, FALSE, FALSE, 0);
gtk_widget_show (button);
}
return button;
}
static GtkWidget *
prefs_check_button_add_with_icon (GObject *config,
const gchar *property_name,
const gchar *label,
const gchar *icon_name,
GtkBox *vbox,
GtkSizeGroup *group)
{
GtkWidget *button;
GtkWidget *hbox;
GtkWidget *image;
button = gimp_prop_check_button_new (config, property_name, label);
if (!button)
return NULL;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_box_pack_start (vbox, hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
gtk_misc_set_padding (GTK_MISC (image), 2, 2);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_widget_show (image);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gtk_widget_show (button);
if (group)
gtk_size_group_add_widget (group, image);
return button;
}
static GtkWidget *
prefs_widget_add_aligned (GtkWidget *widget,
const gchar *text,
GtkTable *table,
gint table_row,
gboolean left_align,
GtkSizeGroup *group)
{
GtkWidget *label = gimp_table_attach_aligned (table, 0, table_row,
text, 0.0, 0.5,
widget, 1, left_align);
if (group)
gtk_size_group_add_widget (group, label);
return label;
}
static GtkWidget *
prefs_color_button_add (GObject *config,
const gchar *property_name,
const gchar *label,
const gchar *title,
GtkTable *table,
gint table_row,
GtkSizeGroup *group,
GimpContext *context)
{
GtkWidget *button;
GParamSpec *pspec;
gboolean has_alpha;
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (config),
property_name);
has_alpha = gimp_param_spec_rgb_has_alpha (pspec);
button = gimp_prop_color_button_new (config, property_name,
title,
COLOR_BUTTON_WIDTH,
COLOR_BUTTON_HEIGHT,
has_alpha ?
GIMP_COLOR_AREA_SMALL_CHECKS :
GIMP_COLOR_AREA_FLAT);
if (button)
{
if (context)
gimp_color_panel_set_context (GIMP_COLOR_PANEL (button), context);
prefs_widget_add_aligned (button, label, table, table_row, TRUE, group);
}
return button;
}
static GtkWidget *
prefs_entry_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *entry = gimp_prop_entry_new (config, property_name, -1);
if (entry)
prefs_widget_add_aligned (entry, label, table, table_row, FALSE, group);
return entry;
}
static GtkWidget *
prefs_enum_combo_box_add (GObject *config,
const gchar *property_name,
gint minimum,
gint maximum,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *combo = gimp_prop_enum_combo_box_new (config, property_name,
minimum, maximum);
if (combo)
prefs_widget_add_aligned (combo, label, table, table_row, FALSE, group);
return combo;
}
static GtkWidget *
prefs_boolean_combo_box_add (GObject *config,
const gchar *property_name,
const gchar *true_text,
const gchar *false_text,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *combo = gimp_prop_boolean_combo_box_new (config, property_name,
true_text, false_text);
if (combo)
prefs_widget_add_aligned (combo, label, table, table_row, FALSE, group);
return combo;
}
#ifdef HAVE_ISO_CODES
static GtkWidget *
prefs_language_combo_box_add (GObject *config,
const gchar *property_name,
GtkBox *vbox)
{
GtkWidget *combo = gimp_prop_language_combo_box_new (config, property_name);
if (combo)
{
gtk_box_pack_start (vbox, combo, FALSE, FALSE, 0);
gtk_widget_show (combo);
}
return combo;
}
#endif
static GtkWidget *
prefs_profile_combo_box_add (GObject *config,
const gchar *property_name,
GtkListStore *profile_store,
const gchar *dialog_title,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *combo = gimp_prop_profile_combo_box_new (config,
property_name,
profile_store,
dialog_title);
if (combo)
prefs_widget_add_aligned (combo, label, table, table_row, FALSE, group);
return combo;
}
static GtkWidget *
prefs_spin_button_add (GObject *config,
const gchar *property_name,
gdouble step_increment,
gdouble page_increment,
gint digits,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *button = gimp_prop_spin_button_new (config, property_name,
step_increment,
page_increment,
digits);
if (button)
prefs_widget_add_aligned (button, label, table, table_row, TRUE, group);
return button;
}
static GtkWidget *
prefs_memsize_entry_add (GObject *config,
const gchar *property_name,
const gchar *label,
GtkTable *table,
gint table_row,
GtkSizeGroup *group)
{
GtkWidget *entry = gimp_prop_memsize_entry_new (config, property_name);
if (entry)
prefs_widget_add_aligned (entry, label, table, table_row, TRUE, group);
return entry;
}
static void
prefs_canvas_padding_color_changed (GtkWidget *button,
GtkWidget *combo)
@ -1553,8 +1221,8 @@ prefs_dialog_new (Gimp *gimp,
button = gimp_prop_color_button_new (color_config, "out-of-gamut-color",
_("Select Warning Color"),
COLOR_BUTTON_WIDTH,
COLOR_BUTTON_HEIGHT,
PREFS_COLOR_BUTTON_WIDTH,
PREFS_COLOR_BUTTON_HEIGHT,
GIMP_COLOR_AREA_FLAT);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);