diff options
Diffstat (limited to 'tools/glade/glade/gbwidgets')
85 files changed, 31908 insertions, 0 deletions
diff --git a/tools/glade/glade/gbwidgets/Makefile.am b/tools/glade/glade/gbwidgets/Makefile.am new file mode 100644 index 00000000..862d853a --- /dev/null +++ b/tools/glade/glade/gbwidgets/Makefile.am @@ -0,0 +1,93 @@ +## Process this file with automake to produce Makefile.in + +noinst_LIBRARIES = libgbwidgets.a + +# maybe this should be $(GLADE_GTK_CFLAGS) ? +INCLUDES = $(GLADE_GTK_CFLAGS) \ + $(GLADE_DEPRECATION_CFLAGS) + +libgbwidgets_a_SOURCES = \ + gbaboutdialog.c \ + gbaccellabel.c \ + gbalignment.c \ + gbarrow.c \ + gbaspectframe.c \ + gbbutton.c \ + gbcalendar.c \ + gbcellview.c \ + gbcheckbutton.c \ + gbcheckmenuitem.c \ + gbclist.c \ + gbcolorbutton.c \ + gbcolorselection.c \ + gbcolorselectiondialog.c \ + gbcombo.c \ + gbcombobox.c \ + gbcomboboxentry.c \ + gbctree.c \ + gbcustom.c \ + gbcurve.c \ + gbdialog.c \ + gbdrawingarea.c \ + gbentry.c \ + gbeventbox.c \ + gbexpander.c \ + gbfilechooserbutton.c \ + gbfilechooserwidget.c \ + gbfilechooserdialog.c \ + gbfileselection.c \ + gbfixed.c \ + gbfontbutton.c \ + gbfontselection.c \ + gbfontselectiondialog.c \ + gbframe.c \ + gbgammacurve.c \ + gbhandlebox.c \ + gbhbox.c \ + gbhbuttonbox.c \ + gbhpaned.c \ + gbhruler.c \ + gbhscale.c \ + gbhscrollbar.c \ + gbhseparator.c \ + gbiconview.c \ + gbimage.c \ + gbimagemenuitem.c \ + gbinputdialog.c \ + gblabel.c \ + gblayout.c \ + gblist.c \ + gblistitem.c \ + gbmenu.c \ + gbmenubar.c \ + gbmenuitem.c \ + gbmenutoolbutton.c \ + gbnotebook.c \ + gboptionmenu.c \ + gbpreview.c \ + gbprogressbar.c \ + gbradiobutton.c \ + gbradiomenuitem.c \ + gbradiotoolbutton.c \ + gbscrolledwindow.c \ + gbseparatormenuitem.c \ + gbseparatortoolitem.c \ + gbspinbutton.c \ + gbstatusbar.c \ + gbtable.c \ + gbtextview.c \ + gbtogglebutton.c \ + gbtoggletoolbutton.c \ + gbtoolbar.c \ + gbtoolbutton.c \ + gbtoolitem.c \ + gbtreeview.c \ + gbvbox.c \ + gbvbuttonbox.c \ + gbviewport.c \ + gbvpaned.c \ + gbvruler.c \ + gbvscale.c \ + gbvscrollbar.c \ + gbvseparator.c \ + gbwindow.c diff --git a/tools/glade/glade/gbwidgets/gbaboutdialog.c b/tools/glade/glade/gbwidgets/gbaboutdialog.c new file mode 100644 index 00000000..dd454986 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbaboutdialog.c @@ -0,0 +1,602 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/aboutdialog.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Name = "GtkAboutDialog::name"; +static gchar *Copyright = "GtkAboutDialog::copyright"; +static gchar *Comments = "GtkAboutDialog::comments"; +static gchar *License = "GtkAboutDialog::license"; +static gchar *WrapLicense = "GtkAboutDialog::wrap_license"; +static gchar *Website = "GtkAboutDialog::website"; +static gchar *WebsiteLabel = "GtkAboutDialog::website_label"; + +static gchar *Authors = "GtkAboutDialog::authors"; +static gchar *Documenters = "GtkAboutDialog::documenters"; +static gchar *Artists = "GtkAboutDialog::artists"; +static gchar *TranslatorCredits = "GtkAboutDialog::translator_credits"; + +static gchar *Logo = "GtkAboutDialog::logo"; + + +static gchar *DestroyWithParent = "GtkAboutDialog|GtkWindow::destroy_with_parent"; + +#define GLADE_TRANSLATORS_STRING "translator-credits" + +/* This is the old string we used for GnomeAbout, but translators don't like + it as the '_' character gets confused with an underlined accelerator key. */ +#define GLADE_TRANSLATORS_STRING2 "translator_credits" + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkAboutDialog, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_about_dialog_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + gchar *project_name; + + new_widget = gtk_about_dialog_new (); + + project_name = glade_project_get_name (data->project); + if (!project_name) + project_name = _("Application Name"); + gtk_about_dialog_set_name (GTK_ABOUT_DIALOG (new_widget), project_name); + + gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (new_widget), "1.0"); + + /* Now we connect our normal delete_event handler. */ + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + /* Set the default comment string for the translator credits. */ + glade_util_set_translation_properties (new_widget, TranslatorCredits, + TRUE, "TRANSLATORS: Replace this string with your names, one name per line.", FALSE); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_about_dialog_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_filename (Logo, _("Logo:"), _("The pixmap to use as the logo")); + + property_add_string (Name, _("Program Name:"), _("The name of the application")); + property_add_text (Comments, _("Comments:"), _("Additional information, such as a description of the application"), 3); + property_add_text (Copyright, _("Copyright:"), _("The copyright notice"), 2); + + property_add_string (Website, _("Website URL:"), _("The URL of the application's website")); + property_add_string (WebsiteLabel, _("Website Label:"), _("The label to display for the link to the website")); + + property_add_text (License, _("License:"), _("The license details of the application"), 3); + property_add_bool (WrapLicense, _("Wrap License:"), _("If the license text should be wrapped")); + + property_add_text (Authors, _("Authors:"), _("The authors of the package, one on each line"), 2); + property_add_text (Documenters, _("Documenters:"), _("The documenters of the package, one on each line"), 2); + property_add_text (Artists, _("Artists:"), _("The people who have created the artwork for the package, one on each line"), 2); + property_add_text (TranslatorCredits, _("Translators:"), _("The translators of the package. This should normally be left empty so that translators can add their names in the po files"), 2); + + /* We onlt need the common DestroyWithParent window property. The others + shouldn't really need to be changed on a simple About dialog. */ + gb_window_create_standard_properties (widget, data, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, + NULL, DestroyWithParent, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, NULL); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_about_dialog_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + const gchar *name, *copyright, *comments, *license, *website, *website_label; + const char *translator_credits, *translator_credits_output; + gboolean wrap_license; + + gb_window_get_standard_properties (widget, data, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, + NULL, DestroyWithParent, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, NULL); + + name = gtk_about_dialog_get_name (GTK_ABOUT_DIALOG (widget)); + gb_widget_output_translatable_string (data, Name, name); + + copyright = gtk_about_dialog_get_copyright (GTK_ABOUT_DIALOG (widget)); + gb_widget_output_translatable_text (data, Copyright, copyright); + + comments = gtk_about_dialog_get_comments (GTK_ABOUT_DIALOG (widget)); + gb_widget_output_translatable_text (data, Comments, comments); + + license = gtk_about_dialog_get_license (GTK_ABOUT_DIALOG (widget)); + gb_widget_output_translatable_text (data, License, license); + + wrap_license = gtk_about_dialog_get_wrap_license (GTK_ABOUT_DIALOG (widget)); + gb_widget_output_bool (data, WrapLicense, wrap_license); + + /* We store the Website & WebsiteURL in the object datalist, since the + widget does odd things when we set them. */ + website = g_object_get_data (G_OBJECT (widget), Website); + gb_widget_output_string (data, Website, website); + + website_label = g_object_get_data (G_OBJECT (widget), WebsiteLabel); + gb_widget_output_translatable_string (data, WebsiteLabel, website_label); + + gb_widget_output_text (data, Authors, + gtk_object_get_data (GTK_OBJECT (widget), Authors)); + gb_widget_output_text (data, Documenters, + gtk_object_get_data (GTK_OBJECT (widget), + Documenters)); + gb_widget_output_text (data, Artists, + gtk_object_get_data (GTK_OBJECT (widget), Artists)); + + /* If we are saving, and translator_credits isn't set but is translatable, + we save the string "translator-credits". Translators can then + replace this with their own names in the po files. */ + translator_credits = gtk_about_dialog_get_translator_credits (GTK_ABOUT_DIALOG (widget)); + translator_credits_output = translator_credits; + if (data->action == GB_SAVING + && (!translator_credits || *translator_credits == '\0')) + { + gchar *comments_text; + gboolean translatable, context; + + glade_util_get_translation_properties (widget, TranslatorCredits, + &translatable, + &comments_text, &context); + if (translatable) + translator_credits_output = GLADE_TRANSLATORS_STRING; + } + gb_widget_output_translatable_text (data, TranslatorCredits, + translator_credits_output); + + gb_widget_output_pixmap_filename (data, Logo, + gtk_object_get_data (GTK_OBJECT (widget), + Logo)); +} + + +static gchar** +strv_from_property (GbWidgetSetArgData *data, GtkWidget *widget, const char *key) +{ + gchar **retval = NULL; + char *str; + + str = gb_widget_input_text (data, key); + if (data->apply) + { + gtk_object_set_data_full (GTK_OBJECT (widget), key, g_strdup (str), + str ? g_free : NULL); + retval = g_strsplit (str, "\n", 0); + } + if (data->action == GB_APPLYING) + g_free (str); + + return retval; +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_about_dialog_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar **authors, **documenters, **artists; + gchar *name, *copyright, *comments, *license, *website, *website_label; + gchar *translators, *filename, *old_filename; + GdkPixbuf *logo = NULL; + GObject *object; + gboolean wrap_license; + + object = G_OBJECT (widget); + + gb_window_set_standard_properties (widget, data, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, + NULL, DestroyWithParent, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, NULL); + + name = gb_widget_input_string (data, Name); + if (data->apply) + gtk_about_dialog_set_name (GTK_ABOUT_DIALOG (widget), name); + + copyright = gb_widget_input_text (data, Copyright); + if (data->apply) + gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (widget), copyright); + if (data->action == GB_APPLYING) + g_free (copyright); + + comments = gb_widget_input_text (data, Comments); + if (data->apply) + gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (widget), comments); + if (data->action == GB_APPLYING) + g_free (comments); + + license = gb_widget_input_text (data, License); + if (data->apply) + gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (widget), license); + if (data->action == GB_APPLYING) + g_free (license); + + wrap_license = gb_widget_input_bool (data, WrapLicense); + if (data->apply) + gtk_about_dialog_set_wrap_license (GTK_ABOUT_DIALOG (widget), wrap_license); + + + website = gb_widget_input_string (data, Website); + if (data->apply) + g_object_set_data_full (G_OBJECT (widget), Website, g_strdup (website), + website ? g_free : NULL); + + website_label = gb_widget_input_string (data, WebsiteLabel); + if (data->apply) + g_object_set_data_full (G_OBJECT (widget), WebsiteLabel, + g_strdup (website_label), + website_label ? g_free : NULL); + + authors = strv_from_property (data, widget, Authors); + if (data->apply) + gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (widget), + (const gchar**) authors); + g_strfreev (authors); + + documenters = strv_from_property (data, widget, Documenters); + if (data->apply) + gtk_about_dialog_set_documenters (GTK_ABOUT_DIALOG (widget), + (const gchar**) documenters); + g_strfreev (documenters); + + artists = strv_from_property (data, widget, Artists); + if (data->apply) + gtk_about_dialog_set_artists (GTK_ABOUT_DIALOG (widget), + (const gchar**) artists); + g_strfreev (artists); + + translators = gb_widget_input_text (data, TranslatorCredits); + if (data->apply) + { + if (!strcmp (translators, GLADE_TRANSLATORS_STRING) + || !strcmp (translators, GLADE_TRANSLATORS_STRING2)) + g_object_set (object, "translator-credits", "", NULL); + else + g_object_set (object, "translator-credits", translators, NULL); + } + if (data->action == GB_APPLYING) + g_free (translators); + + filename = gb_widget_input_pixmap_filename (data, Logo); + if (data->apply) + { + if (filename && filename[0] == '\0') + filename = NULL; + + old_filename = gtk_object_get_data (GTK_OBJECT (widget), Logo); + glade_project_remove_pixmap (data->project, old_filename); + gtk_object_set_data_full (GTK_OBJECT (widget), Logo, + g_strdup (filename), filename ? g_free : NULL); + glade_project_add_pixmap (data->project, filename); + logo = filename ? gdk_pixbuf_new_from_file (filename, NULL) : NULL; + g_object_set (object, "logo", logo, NULL); + if (logo) + g_object_unref (logo); + } + if (data->action == GB_LOADING) + g_free (filename); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkAboutDialog, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_about_dialog_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + +static gboolean +output_creators_array (GtkWidget *widget, GbWidgetWriteSourceData *data, + gchar *array_name, gchar *property_name) +{ + gchar *string, **strv; + gint i; + + string = gtk_object_get_data (GTK_OBJECT (widget), property_name); + if (!string || *string == '\0') + return FALSE; + + source_add_decl (data, " const gchar *%s[] = {\n", array_name); + + strv = g_strsplit (string, "\n", 0); + for (i = 0; strv[i]; i++) + { + if (strv[i][0]) + source_add_decl (data, " %s,\n", + source_make_string (strv[i], FALSE)); + } + + source_add_decl (data, " NULL\n };\n"); + g_strfreev (strv); + + return TRUE; +} + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_about_dialog_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gboolean translatable, context, wrap_license; + gchar *comments; + const gchar *name, *copyright, *about_comments, *license; + const gchar *website, *website_label, *translators; + gchar *logo_filename; + char *pixbuf_name; + + if (data->create_widget) + { + source_add (data, " %s = gtk_about_dialog_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + gb_window_write_standard_source (widget, data, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, NULL, + NULL, DestroyWithParent, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, NULL); + + /* We set the version using the standard "VERSION" macro. */ + source_add (data, + " gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (%s), VERSION);\n", data->wname); + + name = gtk_about_dialog_get_name (GTK_ABOUT_DIALOG (widget)); + if (name && *name) + { + glade_util_get_translation_properties (widget, Name, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_about_dialog_set_name (GTK_ABOUT_DIALOG (%s), %s);\n", + data->wname, + source_make_string_full (name, + data->use_gettext && translatable, + context)); + } + + copyright = gtk_about_dialog_get_copyright (GTK_ABOUT_DIALOG (widget)); + if (copyright && *copyright) + { + glade_util_get_translation_properties (widget, Copyright, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (%s), %s);\n", + data->wname, + source_make_string_full (copyright, + data->use_gettext && translatable, + context)); + } + + about_comments = gtk_about_dialog_get_comments (GTK_ABOUT_DIALOG (widget)); + if (about_comments && *about_comments) + { + glade_util_get_translation_properties (widget, Comments, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (%s), %s);\n", + data->wname, + source_make_string_full (about_comments, + data->use_gettext && translatable, + context)); + } + + license = gtk_about_dialog_get_license (GTK_ABOUT_DIALOG (widget)); + if (license && *license) + { + glade_util_get_translation_properties (widget, License, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (%s), %s);\n", + data->wname, + source_make_string_full (license, + data->use_gettext && translatable, + context)); + } + + wrap_license = gtk_about_dialog_get_wrap_license (GTK_ABOUT_DIALOG (widget)); + if (wrap_license) + { + source_add (data, + " gtk_about_dialog_set_wrap_license (GTK_ABOUT_DIALOG (%s), TRUE);\n", + data->wname); + } + + + website = g_object_get_data (G_OBJECT (widget), Website); + if (website && *website) + { + source_add (data, + " gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (%s), %s);\n", + data->wname, + source_make_string (website, FALSE)); + } + + website_label = g_object_get_data (G_OBJECT (widget), WebsiteLabel); + if (website_label && *website_label) + { + glade_util_get_translation_properties (widget, WebsiteLabel, + &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_about_dialog_set_website_label (GTK_ABOUT_DIALOG (%s), %s);\n", + data->wname, + source_make_string_full (website_label, + data->use_gettext && translatable, + context)); + } + + + if (output_creators_array (widget, data, "authors", Authors)) + source_add (data, + " gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG (%s), authors);\n", data->wname); + + if (output_creators_array (widget, data, "documenters", Documenters)) + source_add (data, + " gtk_about_dialog_set_documenters (GTK_ABOUT_DIALOG (%s), documenters);\n", data->wname); + + if (output_creators_array (widget, data, "artists", Artists)) + source_add (data, + " gtk_about_dialog_set_artists (GTK_ABOUT_DIALOG (%s), artists);\n", data->wname); + + + /* If translators is set, then we use that specific string. + If it is not set, then if gettext support is enabled we output code + to call gettext to translate the special "translator_credits" string, + and use that if it is translated. */ + translators = gtk_about_dialog_get_translator_credits (GTK_ABOUT_DIALOG (widget)); + glade_util_get_translation_properties (widget, TranslatorCredits, + &translatable, &comments, &context); + if (translators && translators[0]) + { + source_add_translator_comments_to_buffer (data, GLADE_DECLARATIONS, translatable, comments); + source_add_decl (data, " gchar *translators = %s;\n", + source_make_string (translators, FALSE)); + + source_add (data, + " gtk_about_dialog_set_translator_credits (GTK_ABOUT_DIALOG (%s), translators);\n", data->wname); + } + else if (data->use_gettext && translatable) + { + if (!comments || comments[0] == '\0') + comments = "TRANSLATORS: Replace this string with your names, one name per line."; + + source_add_translator_comments_to_buffer (data, GLADE_DECLARATIONS, + translatable, comments); + source_add_decl (data, + " gchar *translators = _(\"%s\");\n", + GLADE_TRANSLATORS_STRING); + + source_add (data, + " gtk_about_dialog_set_translator_credits (GTK_ABOUT_DIALOG (%s), translators);\n", data->wname); + } + + + logo_filename = gtk_object_get_data (GTK_OBJECT (widget), Logo); + if (logo_filename && logo_filename[0]) + { + pixbuf_name = g_strdup_printf ("%s_logo_pixbuf", data->wname); + + source_add_decl (data, " GdkPixbuf *%s;\n", pixbuf_name); + source_create_pixbuf (data, pixbuf_name, logo_filename); + + source_add (data, + " gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (%s), %s);\n", + data->wname, pixbuf_name); + + g_free (pixbuf_name); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_about_dialog_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_about_dialog_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = aboutdialog_xpm; + gbwidget.tooltip = _("About Dialog"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_about_dialog_new; + gbwidget.gb_widget_create_properties = gb_about_dialog_create_properties; + gbwidget.gb_widget_get_properties = gb_about_dialog_get_properties; + gbwidget.gb_widget_set_properties = gb_about_dialog_set_properties; + gbwidget.gb_widget_write_source = gb_about_dialog_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_about_dialog_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbaccellabel.c b/tools/glade/glade/gbwidgets/gbaccellabel.c new file mode 100644 index 00000000..56519fd9 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbaccellabel.c @@ -0,0 +1,214 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <math.h> + +#include <gtk/gtkaccellabel.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/accellabel.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Label = "AccelLabel|GtkLabel::label"; +static gchar *UseUnderline = "AccelLabel|GtkLabel::use_underline"; +static gchar *UseMarkup = "AccelLabel|GtkLabel::use_markup"; +static gchar *Justify = "AccelLabel|GtkLabel::justify"; +static gchar *Wrap = "AccelLabel|GtkLabel::wrap"; +static gchar *XAlign = "AccelLabel|GtkMisc::xalign"; +static gchar *YAlign = "AccelLabel|GtkMisc::yalign"; +static gchar *XPad = "AccelLabel|GtkMisc::xpad"; +static gchar *YPad = "AccelLabel|GtkMisc::ypad"; +static gchar *Selectable = "AccelLabel|GtkLabel::selectable"; + +static gchar *Ellipsize = "AccelLabel|GtkLabel::ellipsize"; +static gchar *WidthChars = "AccelLabel|GtkLabel::width_chars"; +static gchar *SingleLineMode = "AccelLabel|GtkLabel::single_line_mode"; +static gchar *Angle = "AccelLabel|GtkLabel::angle"; + +static gchar *FocusTarget = "AccelLabel|GtkLabel::mnemonic_widget"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the funtion in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkAccelLabel, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_accel_label_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_accel_label_new (data->name); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_accel_label_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + gb_label_create_standard_properties (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_accel_label_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_label_get_standard_properties (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_accel_label_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gb_label_set_standard_properties (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkAccelLabel, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_accel_label_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_accel_label_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + const gchar *label_text = gtk_label_get_label (GTK_LABEL (widget)); + + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, " %s = gtk_accel_label_new (%s);\n", data->wname, + source_make_string_full (label_text, + data->use_gettext && translatable, + context)); + } + + gb_widget_write_standard_source (widget, data); + + if (gtk_label_get_use_underline (GTK_LABEL (widget))) + source_add (data, + " gtk_label_set_use_underline (GTK_LABEL (%s), TRUE);\n", + data->wname); + + gb_label_write_standard_source (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_accel_label_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_accel_label_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = accellabel_xpm; + gbwidget.tooltip = _("Label with Accelerator"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_accel_label_new; + gbwidget.gb_widget_create_properties = gb_accel_label_create_properties; + gbwidget.gb_widget_get_properties = gb_accel_label_get_properties; + gbwidget.gb_widget_set_properties = gb_accel_label_set_properties; + gbwidget.gb_widget_write_source = gb_accel_label_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_accel_label_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbalignment.c b/tools/glade/glade/gbwidgets/gbalignment.c new file mode 100644 index 00000000..78a7fe2a --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbalignment.c @@ -0,0 +1,268 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkalignment.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/alignment.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *XAlign = "GtkAlignment::xalign"; +static gchar *YAlign = "GtkAlignment::yalign"; +static gchar *XScale = "GtkAlignment::xscale"; +static gchar *YScale = "GtkAlignment::yscale"; + +static gchar *TopPadding = "GtkAlignment::top_padding"; +static gchar *BottomPadding = "GtkAlignment::bottom_padding"; +static gchar *LeftPadding = "GtkAlignment::left_padding"; +static gchar *RightPadding = "GtkAlignment::right_padding"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkAlignment, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_alignment_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); + if (data->action != GB_LOADING) + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_alignment_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_float_range (XAlign, _("X Align:"), + _("The horizontal alignment of the child widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (YAlign, _("Y Align:"), + _("The vertical alignment of the child widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (XScale, _("X Scale:"), + _("The horizontal scale of the child widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (YScale, _("Y Scale:"), + _("The vertical scale of the child widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + + property_add_int_range (TopPadding, + _("Top Padding:"), + _("Space to put above the child widget"), + 0, 1000, 1, 10, 1); + property_add_int_range (BottomPadding, + _("Bottom Padding:"), + _("Space to put below the child widget"), + 0, 1000, 1, 10, 1); + property_add_int_range (LeftPadding, + _("Left Padding:"), + _("Space to put to the left of the child widget"), + 0, 1000, 1, 10, 1); + property_add_int_range (RightPadding, + _("Right Padding:"), + _("Space to put to the right of the child widget"), + 0, 1000, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_alignment_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + guint padding_top, padding_bottom, padding_left, padding_right; + + gb_widget_output_float (data, XAlign, GTK_ALIGNMENT (widget)->xalign); + gb_widget_output_float (data, YAlign, GTK_ALIGNMENT (widget)->yalign); + gb_widget_output_float (data, XScale, GTK_ALIGNMENT (widget)->xscale); + gb_widget_output_float (data, YScale, GTK_ALIGNMENT (widget)->yscale); + + gtk_alignment_get_padding (GTK_ALIGNMENT (widget), + &padding_top, &padding_bottom, + &padding_left, &padding_right); + + gb_widget_output_int (data, TopPadding, padding_top); + gb_widget_output_int (data, BottomPadding, padding_bottom); + gb_widget_output_int (data, LeftPadding, padding_left); + gb_widget_output_int (data, RightPadding, padding_right); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_alignment_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gfloat xalign, yalign, xscale, yscale; + guint padding_top, padding_bottom, padding_left, padding_right; + gboolean set_alignment = FALSE, set_padding = FALSE; + + xalign = gb_widget_input_float (data, XAlign); + if (data->apply) + set_alignment = TRUE; + else + xalign = GTK_ALIGNMENT (widget)->xalign; + + yalign = gb_widget_input_float (data, YAlign); + if (data->apply) + set_alignment = TRUE; + else + yalign = GTK_ALIGNMENT (widget)->yalign; + + xscale = gb_widget_input_float (data, XScale); + if (data->apply) + set_alignment = TRUE; + else + xscale = GTK_ALIGNMENT (widget)->xscale; + + yscale = gb_widget_input_float (data, YScale); + if (data->apply) + set_alignment = TRUE; + else + yscale = GTK_ALIGNMENT (widget)->yscale; + + if (set_alignment) + gtk_alignment_set (GTK_ALIGNMENT (widget), xalign, yalign, xscale, yscale); + + gtk_alignment_get_padding (GTK_ALIGNMENT (widget), + &padding_top, &padding_bottom, + &padding_left, &padding_right); + + padding_top = gb_widget_input_int (data, TopPadding); + if (data->apply) + set_padding = TRUE; + + padding_bottom = gb_widget_input_int (data, BottomPadding); + if (data->apply) + set_padding = TRUE; + + padding_left = gb_widget_input_int (data, LeftPadding); + if (data->apply) + set_padding = TRUE; + + padding_right = gb_widget_input_int (data, RightPadding); + if (data->apply) + set_padding = TRUE; + + if (set_padding) + gtk_alignment_set_padding (GTK_ALIGNMENT (widget), + padding_top, padding_bottom, + padding_left, padding_right); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkAlignment, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_alignment_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + +static void +gb_alignment_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + guint padding_top, padding_bottom, padding_left, padding_right; + + if (data->create_widget) + { + source_add (data, " %s = gtk_alignment_new (%g, %g, %g, %g);\n", + data->wname, + GTK_ALIGNMENT (widget)->xalign, GTK_ALIGNMENT (widget)->yalign, + GTK_ALIGNMENT (widget)->xscale, GTK_ALIGNMENT (widget)->yscale); + } + gb_widget_write_standard_source (widget, data); + + gtk_alignment_get_padding (GTK_ALIGNMENT (widget), + &padding_top, &padding_bottom, + &padding_left, &padding_right); + + if (padding_top != 0 || padding_bottom != 0 + || padding_left != 0 || padding_right != 0) + { + source_add (data, + " gtk_alignment_set_padding (GTK_ALIGNMENT (%s), %i, %i, %i, %i);\n", + data->wname, + padding_top, padding_bottom, padding_left, padding_right); + + } +} + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_alignment_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_alignment_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = alignment_xpm; + gbwidget.tooltip = _("Alignment"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_alignment_new; + gbwidget.gb_widget_create_properties = gb_alignment_create_properties; + gbwidget.gb_widget_get_properties = gb_alignment_get_properties; + gbwidget.gb_widget_set_properties = gb_alignment_set_properties; +/* + gbwidget.gb_widget_create_popup_menu = gb_alignment_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_alignment_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbarrow.c b/tools/glade/glade/gbwidgets/gbarrow.c new file mode 100644 index 00000000..b539bedc --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbarrow.c @@ -0,0 +1,312 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkarrow.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/arrow.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Direction = "GtkArrow::arrow_type"; +static gchar *Shadow = "GtkArrow::shadow_type"; +static gchar *XAlign = "Arrow|GtkMisc::xalign"; +static gchar *YAlign = "Arrow|GtkMisc::yalign"; +static gchar *XPad = "Arrow|GtkMisc::xpad"; +static gchar *YPad = "Arrow|GtkMisc::ypad"; + +static const gchar *GbDirectionChoices[] = +{"Up", "Down", "Left", "Right", NULL}; +static const gint GbDirectionValues[] = +{ + GTK_ARROW_UP, + GTK_ARROW_DOWN, + GTK_ARROW_LEFT, + GTK_ARROW_RIGHT +}; +static const gchar *GbDirectionSymbols[] = +{ + "GTK_ARROW_UP", + "GTK_ARROW_DOWN", + "GTK_ARROW_LEFT", + "GTK_ARROW_RIGHT" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkArrow, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +/* + GtkWidget* + gb_arrow_new(GbWidgetNewData *data) + { + + } + */ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_arrow_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Direction, _("Direction:"), _("The direction of the arrow"), + GbDirectionChoices); + property_add_choice (Shadow, _("Shadow:"), _("The shadow type of the arrow"), + GladeShadowChoices); + property_add_float_range (XAlign, _("X Align:"), + _("The horizontal alignment of the arrow"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (YAlign, _("Y Align:"), + _("The vertical alignment of the arrow"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_int_range (XPad, _("X Pad:"), _("The horizontal padding"), + 0, 1000, 1, 10, 1); + property_add_int_range (YPad, _("Y Pad:"), _("The vertical padding"), + 0, 1000, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_arrow_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + for (i = 0; i < sizeof (GbDirectionValues) / sizeof (GbDirectionValues[0]); + i++) + { + if (GbDirectionValues[i] == GTK_ARROW (widget)->arrow_type) + gb_widget_output_choice (data, Direction, i, GbDirectionSymbols[i]); + } + + for (i = 0; i < GladeShadowChoicesSize; i++) + { + if (GladeShadowValues[i] == GTK_ARROW (widget)->shadow_type) + gb_widget_output_choice (data, Shadow, i, GladeShadowSymbols[i]); + } + gb_widget_output_float (data, XAlign, GTK_MISC (widget)->xalign); + gb_widget_output_float (data, YAlign, GTK_MISC (widget)->yalign); + gb_widget_output_int (data, XPad, GTK_MISC (widget)->xpad); + gb_widget_output_int (data, YPad, GTK_MISC (widget)->ypad); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_arrow_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *direction, *shadow; + gboolean set_arrow = FALSE, set_alignment = FALSE, set_padding = FALSE; + gfloat xalign, yalign; + gint xpad, ypad, i; + GtkArrowType arrow_type = GTK_ARROW_UP; + GtkShadowType shadow_type = GTK_SHADOW_NONE; + + direction = gb_widget_input_choice (data, Direction); + if (data->apply) + { + for (i = 0; + i < sizeof (GbDirectionValues) / sizeof (GbDirectionValues[0]); + i++) + { + if (!strcmp (direction, GbDirectionChoices[i]) + || !strcmp (direction, GbDirectionSymbols[i])) + { + arrow_type = GbDirectionValues[i]; + set_arrow = TRUE; + break; + } + } + } + else + arrow_type = GTK_ARROW (widget)->arrow_type; + + shadow = gb_widget_input_choice (data, Shadow); + if (data->apply) + { + for (i = 0; i < GladeShadowChoicesSize; i++) + { + if (!strcmp (shadow, GladeShadowChoices[i]) + || !strcmp (shadow, GladeShadowSymbols[i])) + { + shadow_type = GladeShadowValues[i]; + set_arrow = TRUE; + break; + } + } + } + else + shadow_type = GTK_ARROW (widget)->shadow_type; + + if (set_arrow) + gtk_arrow_set (GTK_ARROW (widget), arrow_type, shadow_type); + + xalign = gb_widget_input_float (data, XAlign); + if (data->apply) + set_alignment = TRUE; + else + xalign = GTK_MISC (widget)->xalign; + + yalign = gb_widget_input_float (data, YAlign); + if (data->apply) + set_alignment = TRUE; + else + yalign = GTK_MISC (widget)->yalign; + + if (set_alignment) + gtk_misc_set_alignment (GTK_MISC (widget), xalign, yalign); + + xpad = gb_widget_input_int (data, XPad); + if (data->apply) + set_padding = TRUE; + else + xpad = GTK_MISC (widget)->xpad; + + ypad = gb_widget_input_int (data, YPad); + if (data->apply) + set_padding = TRUE; + else + ypad = GTK_MISC (widget)->ypad; + + if (set_padding) + gtk_misc_set_padding (GTK_MISC (widget), xpad, ypad); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkArrow, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_arrow_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_arrow_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gfloat xalign, yalign; + gint xpad, ypad, arrow_type = 0, shadow_type = 0, i; + + for (i = 0; i < sizeof (GbDirectionValues) / sizeof (GbDirectionValues[0]); + i++) + if (GbDirectionValues[i] == GTK_ARROW (widget)->arrow_type) + { + arrow_type = i; + break; + } + for (i = 0; i < GladeShadowChoicesSize; i++) + if (GladeShadowValues[i] == GTK_ARROW (widget)->shadow_type) + { + shadow_type = i; + break; + } + if (data->create_widget) + { + source_add (data, " %s = gtk_arrow_new (%s, %s);\n", data->wname, + GbDirectionSymbols[arrow_type], GladeShadowSymbols[shadow_type]); + } + gb_widget_write_standard_source (widget, data); + + xalign = GTK_MISC (widget)->xalign; + yalign = GTK_MISC (widget)->yalign; + if (xalign != 0.5 || yalign != 0.5) + { + source_add (data, " gtk_misc_set_alignment (GTK_MISC (%s), %g, %g);\n", + data->wname, xalign, yalign); + } + xpad = GTK_MISC (widget)->xpad; + ypad = GTK_MISC (widget)->ypad; + if (xpad || ypad) + { + source_add (data, " gtk_misc_set_padding (GTK_MISC (%s), %d, %d);\n", + data->wname, xpad, ypad); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_arrow_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_arrow_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = arrow_xpm; + gbwidget.tooltip = _("Arrow"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_arrow_create_properties; + gbwidget.gb_widget_get_properties = gb_arrow_get_properties; + gbwidget.gb_widget_set_properties = gb_arrow_set_properties; +/* + gbwidget.gb_widget_new = gb_arrow_new; + gbwidget.gb_widget_create_popup_menu = gb_arrow_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_arrow_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbaspectframe.c b/tools/glade/glade/gbwidgets/gbaspectframe.c new file mode 100644 index 00000000..b0c3e181 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbaspectframe.c @@ -0,0 +1,335 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "../gb.h" +#include <math.h> +#include <gtk/gtkalignment.h> +#include <gtk/gtkaspectframe.h> +#include <gtk/gtklabel.h> + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/aspectframe.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *LabelXAlign = "AspectFrame|GtkFrame::label_xalign"; +static gchar *LabelYAlign = "AspectFrame|GtkFrame::label_yalign"; +static gchar *Shadow = "AspectFrame|GtkFrame::shadow_type"; +static gchar *XAlign = "GtkAspectFrame::xalign"; +static gchar *YAlign = "GtkAspectFrame::yalign"; +static gchar *Ratio = "GtkAspectFrame::ratio"; +static gchar *Obey = "GtkAspectFrame::obey_child"; + +/* We don't show this any more, as the label is a child widget now, but we + load this for compatability with old XML files. */ +static gchar *Label = "AspectFrame|GtkFrame::label"; + +static const gchar *GbShadowChoices[] = +{"None", "In", "Out", + "Etched In", "Etched Out", NULL}; +static const gint GbShadowValues[] = +{ + GTK_SHADOW_NONE, + GTK_SHADOW_IN, + GTK_SHADOW_OUT, + GTK_SHADOW_ETCHED_IN, + GTK_SHADOW_ETCHED_OUT +}; +static const gchar *GbShadowSymbols[] = +{ + "GTK_SHADOW_NONE", + "GTK_SHADOW_IN", + "GTK_SHADOW_OUT", + "GTK_SHADOW_ETCHED_IN", + "GTK_SHADOW_ETCHED_OUT" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkAspectFrame, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_aspect_frame_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_aspect_frame_new (NULL, 0.5, 0.5, 1.0, TRUE); + + if (data->action != GB_LOADING) + { + GtkWidget *label, *alignment; + gchar *label_markup; + + /* For HIG compliance, we create a frame with no shadow, with a label + of "<b>widget-name</b>", and with an alignment to add 12 pixels + padding on the left. */ + gtk_frame_set_shadow_type (GTK_FRAME (new_widget), GTK_SHADOW_NONE); + + label = gb_widget_new ("GtkLabel", NULL); + label_markup = g_strdup_printf ("<b>%s</b>", data->name); + gtk_label_set_markup (GTK_LABEL (label), label_markup); + g_free (label_markup); + gtk_object_set_data (GTK_OBJECT (label), "GtkLabel::use_markup", + GINT_TO_POINTER (TRUE)); + + gtk_frame_set_label_widget (GTK_FRAME (new_widget), label); + + alignment = gb_widget_new ("GtkAlignment", NULL); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0); + + gtk_container_add (GTK_CONTAINER (new_widget), alignment); + } + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_aspect_frame_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ + property_add_float_range (LabelXAlign, _("Label X Align:"), + _("The horizontal alignment of the frame's label widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (LabelYAlign, _("Label Y Align:"), + _("The vertical alignment of the frame's label widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_choice (Shadow, _("Shadow:"), _("The type of shadow of the frame"), + GbShadowChoices); + property_add_float_range (XAlign, _("X Align:"), + _("The horizontal alignment of the frame's child"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (YAlign, _("Y Align:"), + _("The horizontal alignment of the frame's child"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float (Ratio, _("Ratio:"), + _("The aspect ratio of the frame's child")); + property_add_bool (Obey, _("Obey Child:"), + _("If the aspect ratio should be determined by the child")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_aspect_frame_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + gb_widget_output_float (data, LabelXAlign, GTK_FRAME (widget)->label_xalign); + gb_widget_output_float (data, LabelYAlign, GTK_FRAME (widget)->label_yalign); + + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) + { + if (GbShadowValues[i] == GTK_FRAME (widget)->shadow_type) + gb_widget_output_choice (data, Shadow, i, GbShadowSymbols[i]); + } + + gb_widget_output_float (data, XAlign, GTK_ASPECT_FRAME (widget)->xalign); + gb_widget_output_float (data, YAlign, GTK_ASPECT_FRAME (widget)->yalign); + gb_widget_output_float (data, Ratio, GTK_ASPECT_FRAME (widget)->ratio); + gb_widget_output_bool (data, Obey, GTK_ASPECT_FRAME (widget)->obey_child); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_aspect_frame_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gfloat label_xalign, label_yalign; + gboolean apply_xalign, apply_yalign; + gfloat xalign, yalign, ratio; + gchar *shadow; + gboolean obey_child, set_aspect_frame = FALSE; + gint i; + + /* We load the 'label' property, but create a child GbWidget. */ + if (data->action == GB_LOADING) + { + gchar *label = gb_widget_input_string (data, Label); + if (data->apply && label && *label) + { + GtkWidget *label_widget = gb_widget_new ("GtkLabel", NULL); + gtk_label_set_text (GTK_LABEL (label_widget), label); + gtk_frame_set_label_widget (GTK_FRAME (widget), label_widget); + } + } + + label_xalign = gb_widget_input_float (data, LabelXAlign); + apply_xalign = data->apply; + if (!apply_xalign) + label_xalign = GTK_FRAME (widget)->label_xalign; + + label_yalign = gb_widget_input_float (data, LabelYAlign); + apply_yalign = data->apply; + if (!apply_yalign) + label_yalign = GTK_FRAME (widget)->label_yalign; + + if (apply_xalign || apply_yalign) + gtk_frame_set_label_align (GTK_FRAME (widget), label_xalign, label_yalign); + + shadow = gb_widget_input_choice (data, Shadow); + if (data->apply) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (!strcmp (shadow, GbShadowChoices[i]) + || !strcmp (shadow, GbShadowSymbols[i])) + { + gtk_frame_set_shadow_type (GTK_FRAME (widget), GbShadowValues[i]); + break; + } + } + } + + xalign = gb_widget_input_float (data, XAlign); + if (data->apply) + set_aspect_frame = TRUE; + else + xalign = GTK_ASPECT_FRAME (widget)->xalign; + + yalign = gb_widget_input_float (data, YAlign); + if (data->apply) + set_aspect_frame = TRUE; + else + yalign = GTK_ASPECT_FRAME (widget)->yalign; + + ratio = gb_widget_input_float (data, Ratio); + if (data->apply) + set_aspect_frame = TRUE; + else + ratio = GTK_ASPECT_FRAME (widget)->ratio; + + obey_child = gb_widget_input_bool (data, Obey); + if (data->apply) + set_aspect_frame = TRUE; + else + obey_child = GTK_ASPECT_FRAME (widget)->obey_child; + + if (set_aspect_frame) + gtk_aspect_frame_set (GTK_ASPECT_FRAME (widget), xalign, yalign, + ratio, obey_child); +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_aspect_frame_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gfloat xalign, yalign; + gint shadow = 0, i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_aspect_frame_new (NULL, %g, %g, %g, %s);\n", + data->wname, + GTK_ASPECT_FRAME (widget)->xalign, + GTK_ASPECT_FRAME (widget)->yalign, + GTK_ASPECT_FRAME (widget)->ratio, + GTK_ASPECT_FRAME (widget)->obey_child ? "TRUE" : "FALSE"); + } + gb_widget_write_standard_source (widget, data); + + xalign = GTK_FRAME (widget)->label_xalign; + yalign = GTK_FRAME (widget)->label_yalign; + if (xalign >= GLADE_EPSILON || fabs (yalign - 0.5) >= GLADE_EPSILON) + { + source_add (data, + " gtk_frame_set_label_align (GTK_FRAME (%s), %g, 0.5);\n", + data->wname, xalign); + } + + if (GTK_FRAME (widget)->shadow_type != GTK_SHADOW_ETCHED_IN) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + if (GbShadowValues[i] == GTK_FRAME (widget)->shadow_type) + { + shadow = i; + break; + } + source_add (data, " gtk_frame_set_shadow_type (GTK_FRAME (%s), %s);\n", + data->wname, GbShadowSymbols[shadow]); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_aspect_frame_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_aspect_frame_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = aspectframe_xpm; + gbwidget.tooltip = _("Aspect Frame"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_aspect_frame_new; + gbwidget.gb_widget_create_properties = gb_aspect_frame_create_properties; + gbwidget.gb_widget_get_properties = gb_aspect_frame_get_properties; + gbwidget.gb_widget_set_properties = gb_aspect_frame_set_properties; + gbwidget.gb_widget_write_source = gb_aspect_frame_write_source; + + /* We just use the GtkFrame functions for these. */ + gbwidget.gb_widget_create_popup_menu = gb_frame_create_popup_menu; + gbwidget.gb_widget_add_child = gb_frame_add_child; + gbwidget.gb_widget_get_child_properties = gb_frame_get_child_properties; + gbwidget.gb_widget_write_add_child_source = gb_frame_write_add_child_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbbutton.c b/tools/glade/glade/gbwidgets/gbbutton.c new file mode 100644 index 00000000..1738b51b --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbbutton.c @@ -0,0 +1,1612 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <string.h> + +#include <gtk/gtkalignment.h> +#include <gtk/gtkbbox.h> +#include <gtk/gtkbutton.h> +#include <gtk/gtkdialog.h> +#include <gtk/gtkradiobutton.h> +#include <gtk/gtkentry.h> +#include <gtk/gtkimage.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkstock.h> + +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/button.xpm" + +/* + * GtkButton widget - unfortunately this has been 'overloaded' a bit to cope + * with extra properties available in toolbar buttons and Gnome buttons. + * Standard toolbar buttons can have an icon as well as a label. + * Gnome buttons can be a stock button (which has a label and icon), or can + * have a stock pixmap as well as a label if they are in a toolbar or in a + * GnomeDialog/MessageBox. + */ + +typedef enum { + GLADE_BUTTON_NORMAL, + GLADE_BUTTON_DIALOG, + GLADE_BUTTON_GNOME_DIALOG +} GladeButtonType; + + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *StockButton = "GtkButton::stock_button"; +static gchar *Label = "GtkButton::label"; +static gchar *Icon = "GtkButton::icon"; +static gchar *FocusOnClick = "GtkButton::focus_on_click"; + +/* This is only used for normal/stock buttons, not special toolbar buttons, + as the toolbar has its own relief setting. */ +static gchar *Relief = "GtkButton::relief"; + +/* This is used for dialog buttons. It is a string, either one of the standard + GTK+ response strings, or a user-defined integer. */ +static gchar *ResponseID = "GtkButton::response_id"; + +/* This is used for dialog buttons, to set if it is a secondary button. + Buttons with ResponseID set to "GTK_RESPONSE_HELP" are always secondary. */ +/* FIXME: We don't worry about this for now. We may support it later. */ +/*static gchar *Secondary = "GtkButton::secondary";*/ + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_button_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_CREATING) + new_widget = gtk_button_new_with_label (data->name); + else + { + new_widget = gtk_button_new (); + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder()); + } + return new_widget; +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + GList *response_list = NULL; + gint i; + + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_BUTTON); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_BUTTON); + property_add_choice (Relief, _("Button Relief:"), + _("The relief style of the button"), + GladeReliefChoices); + + for (i = 0; i < GladeStockResponsesSize; i++) + response_list = g_list_append (response_list, GladeStockResponses[i].name); + property_add_combo (ResponseID, _("Response ID:"), + _("The response code returned when the button is pressed. " + "Select one of the standard responses or enter a positive integer value"), + response_list); + g_list_free (response_list); + + property_add_bool (FocusOnClick, _("Focus On Click:"), _("If the button grabs focus when it is clicked")); +} + + +/* Returns the type of the button - NORMAL, DIALOG or GNOME_DIALOG. */ +GladeButtonType +gb_button_get_button_type (GtkWidget *widget) +{ + gchar *child_name; + + if (widget->parent) + { + child_name = gb_widget_get_child_name (widget->parent); + if (child_name && !strcmp (child_name, GladeChildDialogActionArea)) + { + GtkWidget *toplevel = glade_util_get_toplevel (widget); + + if (GTK_IS_DIALOG (toplevel)) + return GLADE_BUTTON_DIALOG; + else + return GLADE_BUTTON_GNOME_DIALOG; + } + } + + return GLADE_BUTTON_NORMAL; +} + + +/* + * NORMAL BUTTONS. GtkButton/GtkToggleButton/GtkCheckButton/GtkRadioButton. + */ + +/* This tries to find the child label & icon of the button. If the button + contains other widgets it returns FALSE, i.e. if the user has added other + widgets instead. */ +static gboolean +gb_button_normal_find_child_widgets (GtkWidget *widget, + GtkWidget **label, + GtkWidget **icon) +{ + GtkWidget *child, *alignment_child; + + *label = *icon = NULL; + + /* Check it has a child. If it doesn't output a warning. */ + child = GTK_BIN (widget)->child; + g_return_val_if_fail (child != NULL, FALSE); + + /* Check if it has just a GtkLabel child. */ + if (GTK_IS_LABEL (child)) + { + /* If it is a GbWidget we don't handle its properties here. */ + if (GB_IS_GB_WIDGET (child)) + return FALSE; + + *label = child; + return TRUE; + } + + /* Check if it has just a GtkImage child. */ + if (GTK_IS_IMAGE (child)) + { + *icon = child; + return TRUE; + } + + /* If it contains an icon and a label it must be a GtkAlignment with a + GtkHBox in it. */ + if (!GTK_IS_ALIGNMENT (child)) + return FALSE; + + /* Now check for a hbox with a GtkImage and GtkLabel children. */ + alignment_child = GTK_BIN (child)->child; + if (alignment_child && GTK_IS_HBOX (alignment_child) + && g_list_length (GTK_BOX (alignment_child)->children) == 2) + { + GList *children; + GtkBoxChild *child1, *child2; + + children = GTK_BOX (alignment_child)->children; + child1 = children->data; + child2 = children->next->data; + + if (GTK_IS_IMAGE (child1->widget) && GTK_IS_LABEL (child2->widget)) + { + *icon = child1->widget; + *label = child2->widget; + return TRUE; + } + } + + return FALSE; +} + + +static void +gb_button_normal_get_properties (GtkWidget * widget, + GbWidgetGetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p) +{ + gchar *stock_id, *label_text; + gboolean label_sensitive = TRUE; + gboolean icon_sensitive = TRUE; + GtkWidget *label, *icon; + + /* We only allow the GTK_ICON_SIZE_BUTTON size for stock items & icons. */ + if (data->action == GB_SHOWING) + { + property_set_stock_item_icon_size (stock_id_p, GTK_ICON_SIZE_BUTTON); + property_set_icon_size (icon_p, GTK_ICON_SIZE_BUTTON); + } + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), GladeButtonStockIDKey); + /* In the XML the stock item name is actually saved as the label property, + and the use_stock property specifies that it is a stock item. + Also, use_underline needs to be set. */ + if (data->action == GB_SAVING) + { + if (stock_id) + { + gb_widget_output_stock_item (data, "label", stock_id); + gb_widget_output_bool (data, "use_stock", TRUE); + } + } + else + { + gb_widget_output_stock_item (data, stock_id_p, stock_id); + } + + + if (stock_id) + { + label_sensitive = FALSE; + icon_sensitive = FALSE; + } + else + { + if (gb_button_normal_find_child_widgets (widget, &label, &icon)) + { + gchar *icon_name = NULL; + + if (label) + label_text = (gchar*) gtk_label_get_label (GTK_LABEL (label)); + else + label_text = ""; + + /* This is a bit of a hack. The label has the real translation + properties, but we copy them to the button so everything works. */ + if (label) { + glade_util_copy_translation_properties (label, "GtkLabel::label", + widget, label_p); + } + + /* When saving we only output the label if the icon isn't set, + since if it is we will be saving as separate child widgets. */ + if (data->action != GB_SAVING || !icon) + gb_widget_output_translatable_text (data, label_p, label_text); + + /* We always save use_underline as TRUE, though we don't load it. */ + if (data->action == GB_SAVING && !icon) + gb_widget_output_bool (data, "use_underline", TRUE); + + if (icon) + icon_name = gtk_object_get_data (GTK_OBJECT (icon), GladeIconKey); + + /* We never output the icon when saving, as it will be saved as a + child widget. */ + if (data->action != GB_SAVING) + gb_widget_output_icon (data, icon_p, icon_name); + } + else + { + label_sensitive = FALSE; + icon_sensitive = FALSE; + } + } + + if (data->action == GB_SHOWING) + { + if (!label_sensitive) + gb_widget_output_translatable_text (data, label_p, ""); + property_set_sensitive (label_p, label_sensitive); + + if (!icon_sensitive) + gb_widget_output_pixmap_filename (data, icon_p, ""); + property_set_sensitive (icon_p, icon_sensitive); + } +} + + +static void +gb_button_normal_set_stock_id (GtkWidget *widget, + GbWidgetSetArgData * data, + gchar *stock_id, + gchar *label_p, + gchar *icon_p) +{ + gboolean is_stock_item = FALSE; + const gchar *label_text = ""; + + if (stock_id && stock_id[0]) + is_stock_item = TRUE; + + if (is_stock_item) + { + gtk_button_set_use_stock (GTK_BUTTON (widget), TRUE); + gtk_button_set_label (GTK_BUTTON (widget), stock_id); + gtk_object_set_data_full (GTK_OBJECT (widget), GladeButtonStockIDKey, + g_strdup (stock_id), g_free); + } + else + { + /* Change the button back to a normal button with a simple label. */ + gtk_button_set_use_stock (GTK_BUTTON (widget), FALSE); + label_text = gtk_widget_get_name (widget); + gtk_button_set_label (GTK_BUTTON (widget), label_text); + gtk_object_set_data (GTK_OBJECT (widget), GladeButtonStockIDKey, NULL); + } + + /* If the widget's properties are displayed, we update the sensitivity of + the label and icon, according to whether a stock item is selected. */ + if (data->action == GB_APPLYING && property_get_widget () == widget) + { + property_set_sensitive (label_p, !is_stock_item); + property_set_sensitive (icon_p, !is_stock_item); + + /* Turn off auto-apply, and set the label. */ + property_set_auto_apply (FALSE); + property_set_text (label_p, label_text); + property_set_filename (icon_p, ""); + property_set_auto_apply (TRUE); + } +} + + +static void +gb_button_normal_recreate_children (GtkWidget *widget, + GbWidgetSetArgData * data, + gchar *label, gchar *icon_name) +{ + GtkWidget *parent = widget; + + /* Remove any existing children. */ + if (GTK_BIN (widget)->child) + gtk_container_remove (GTK_CONTAINER (widget), GTK_BIN (widget)->child); + + /* If both label and icon are needed, we put them in a hbox, otherwise we + just add the label or icon to the button. */ + if (label && icon_name) + { + GtkWidget *alignment = gb_widget_new ("GtkAlignment", widget); + gtk_widget_show (alignment); + gtk_container_add (GTK_CONTAINER (widget), alignment); + gtk_alignment_set (GTK_ALIGNMENT (alignment), 0.5, 0.5, 0.0, 0.0); + if (GTK_BIN (alignment)->child) + gtk_container_remove (GTK_CONTAINER (alignment), + GTK_BIN (alignment)->child); + + /* We use gb_widget_new_full() and GB_LOADING since we don't want the + dialog to be shown asking for the number of columns. */ + parent = gb_widget_new_full ("GtkHBox", TRUE, alignment, NULL, 0, 0, + NULL, GB_LOADING, NULL); + gtk_widget_show (parent); + gtk_box_set_spacing (GTK_BOX (parent), 2); + gtk_container_add (GTK_CONTAINER (alignment), parent); + } + + if (icon_name) + { + GtkWidget *icon_widget; + + icon_widget = gb_widget_new ("GtkImage", parent); + + gtk_object_set_data_full (GTK_OBJECT (icon_widget), GladeIconKey, + g_strdup (icon_name), + icon_name ? g_free : NULL); + + if (glade_util_check_is_stock_id (icon_name)) + { + gtk_image_set_from_stock (GTK_IMAGE (icon_widget), icon_name, + GTK_ICON_SIZE_BUTTON); + } + else + { + gtk_image_set_from_file (GTK_IMAGE (icon_widget), icon_name); + glade_project_add_pixmap (data->project, icon_name); + } + gtk_widget_show (icon_widget); + + /* We pack them in the hbox just like GtkButton does. */ + if (GTK_IS_BOX (parent)) + gtk_box_pack_start (GTK_BOX (parent), icon_widget, FALSE, FALSE, 0); + else + gtk_container_add (GTK_CONTAINER (parent), icon_widget); + } + + if (label) + { + GtkWidget *label_widget; + + /* If we only have a label, we use a simple label widget, otherwise we + use a GbWidget. */ + if (icon_name) + { + label_widget = gb_widget_new ("GtkLabel", parent); + gtk_label_set_text_with_mnemonic (GTK_LABEL (label_widget), label); + } + else + { + label_widget = gtk_label_new_with_mnemonic (label); + } + + gtk_widget_show (label_widget); + + if (GTK_IS_BOX (parent)) + gtk_box_pack_start (GTK_BOX (parent), label_widget, FALSE, FALSE, 0); + else + gtk_container_add (GTK_CONTAINER (parent), label_widget); + } +} + + +void +gb_button_normal_set_properties (GtkWidget * widget, + GbWidgetSetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p) +{ + gchar *stock_id = NULL, *label, *icon_name = NULL; + gboolean apply_stock_id = FALSE, apply_label, apply_icon; + gboolean free_label = FALSE, free_icon_name = FALSE; + GtkWidget *label_widget, *icon_widget; + + label = gb_widget_input_text (data, label_p); + apply_label = data->apply; + if (data->action == GB_APPLYING) + free_label = TRUE; + + /* When loading, if "use_stock" is TRUE, then the label is the stock item. */ + if (data->action == GB_LOADING) + { + gboolean is_stock_item = gb_widget_input_bool (data, "use_stock"); + if (is_stock_item) + { + stock_id = label; + apply_stock_id = apply_label; + } + } + else + { + stock_id = gb_widget_input_stock_item (data, stock_id_p); + apply_stock_id = data->apply; + } + + if (apply_stock_id) + { + gb_button_normal_set_stock_id (widget, data, stock_id, label_p, icon_p); + goto out; + } + + icon_name = gb_widget_input_icon (data, icon_p); + apply_icon = data->apply; + + gb_button_normal_find_child_widgets (widget, &label_widget, + &icon_widget); + + /* This is a bit of a hack. The label has the real translation + properties, so we have to copy them back there. */ + if (apply_label && label_widget) + glade_util_copy_translation_properties (widget, label_p, + label_widget, "GtkLabel::label"); + + /* If neither icon nor label is set, we don't touch the button as it may + have other child widgets. */ + if (!apply_label && !apply_icon) + return; + + if (!apply_label) + { + if (label_widget) + { + label = g_strdup (gtk_label_get_label (GTK_LABEL (label_widget))); + free_label = TRUE; + } + else + label = NULL; + } + + if (!apply_icon) + { + if (icon_widget) + { + icon_name = gtk_object_get_data (GTK_OBJECT (icon_widget), + GladeIconKey); + if (icon_name && *icon_name) + { + icon_name = g_strdup (icon_name); + free_icon_name = TRUE; + } + else + icon_name = NULL; + } + else + icon_name = NULL; + } + + if (icon_name && !*icon_name) + icon_name = NULL; + + /* If we have an empty label and an icon, we set the label to NULL so it is + removed. */ + if (label && !*label && icon_name) + { + if (free_label) + g_free (label); + label = NULL; + } + + /* Check if we need to rearrange the child widgets, i.e. if we have a label + but no label widget or we don't have a label but we do have a label + widget. And the same for the icon. */ + if ((apply_label && ((label && !label_widget) || (!label && label_widget))) + || (apply_icon && ((icon_name && !icon_widget) || (!icon_name && icon_widget)))) + { + gb_button_normal_recreate_children (widget, data, label, icon_name); + + gb_button_normal_find_child_widgets (widget, &label_widget, + &icon_widget); + if (label_widget) + glade_util_copy_translation_properties (widget, label_p, + label_widget, "GtkLabel::label"); + + goto out; + } + + /* Just update the current label & icon widgets. */ + if (apply_label) + gtk_label_set_text_with_mnemonic (GTK_LABEL (label_widget), + label ? label : ""); + + if (apply_icon && icon_widget && icon_name) + { + gchar *old_icon_name; + + /* Remove the old icon_name stored in the widget data, and remove the + pixmap from the project, if necessary. */ + old_icon_name = gtk_object_get_data (GTK_OBJECT (icon_widget), + GladeIconKey); + glade_project_remove_pixmap (data->project, old_icon_name); + + if (glade_util_check_is_stock_id (icon_name)) + { + gtk_image_set_from_stock (GTK_IMAGE (icon_widget), icon_name, + GTK_ICON_SIZE_BUTTON); + } + else + { + gtk_image_set_from_file (GTK_IMAGE (icon_widget), icon_name); + glade_project_add_pixmap (data->project, icon_name); + } + + gtk_object_set_data_full (GTK_OBJECT (icon_widget), GladeIconKey, + g_strdup (icon_name), + icon_name ? g_free : NULL); + } + + out: + + if (free_label) + g_free (label); + if (free_icon_name) + g_free (icon_name); +} + + +static void +gb_button_normal_write_source (GtkWidget * widget, + GbWidgetWriteSourceData * data, + const gchar *label_p) +{ + GtkWidget *label_widget, *icon_widget; + gchar *group_string = "", *group_string2 = "", *type, *stock_id; + GType widget_type; + + widget_type = G_OBJECT_TYPE (widget); + if (widget_type == GTK_TYPE_BUTTON) + type = "button"; + else if (widget_type == GTK_TYPE_TOGGLE_BUTTON) + type = "toggle_button"; + else if (widget_type == GTK_TYPE_CHECK_BUTTON) + type = "check_button"; + else + { + type = "radio_button"; + group_string = "NULL, "; + group_string2 = "NULL"; + } + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), GladeButtonStockIDKey); + if (stock_id) + { + if (G_OBJECT_TYPE (widget) == GTK_TYPE_BUTTON) + { + source_add (data, + " %s = gtk_button_new_from_stock (%s);\n", + data->wname, source_make_string (stock_id, FALSE)); + } + else + { + source_add (data, + " %s = gtk_%s_new_with_mnemonic (%s%s);\n" + " gtk_button_set_use_stock (GTK_BUTTON (%s), TRUE);\n", + data->wname, type, group_string, + source_make_string (stock_id, FALSE), data->wname); + } + } + else + { + gb_button_normal_find_child_widgets (widget, &label_widget, + &icon_widget); + + if (label_widget && !icon_widget) + { + gchar *label_text, *comments; + gboolean translatable, context; + + label_text = glade_util_get_label_text (label_widget); + glade_util_get_translation_properties (label_widget, + "GtkLabel::label", + &translatable, &comments, + &context); + + source_add_translator_comments (data, translatable, comments); + source_add (data, " %s = gtk_%s_new_with_mnemonic (%s%s);\n", + data->wname, type, group_string, + source_make_string_full (label_text, data->use_gettext && translatable, context)); + g_free (label_text); + } + else + { + source_add (data, " %s = gtk_%s_new (%s);\n", data->wname, type, + group_string2); + } + } +} + + +void +gb_button_find_radio_group (GtkWidget *widget, GladeFindGroupData *find_data) +{ + if (find_data->found_widget) + return; + + if (GTK_IS_RADIO_BUTTON (widget) && GB_IS_GB_WIDGET (widget)) + { + if (gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)) == find_data->group) + { + find_data->found_widget = widget; + return; + } + } + + if (GTK_IS_CONTAINER (widget)) + gb_widget_children_foreach (widget, + (GtkCallback) gb_button_find_radio_group, + find_data); +} + + +/* + * GNOME DIALOG BUTTONS. GtkButton only. + */ + +/* This tries to find the child label & icon of the button. If the button + contains other widgets it returns FALSE, i.e. if the user has added other + widgets instead. */ +static gboolean +gb_button_gnome_find_child_widgets (GtkWidget *widget, + GtkWidget **label, + GtkWidget **icon) +{ + GtkWidget *child; + + *label = *icon = NULL; + + /* Check it has a child. If it doesn't output a warning. */ + child = GTK_BIN (widget)->child; + g_return_val_if_fail (child != NULL, FALSE); + + /* Check if it has just a GtkLabel child. */ + if (GTK_IS_LABEL (child)) + { + *label = child; + return TRUE; + } + + /* Check if it has just a GtkImage child. */ + if (GTK_IS_IMAGE (child)) + { + *icon = child; + return TRUE; + } + + /* If it contains an icon and a label it must be a GtkAlignment with a + GtkHBox in it. FIXME: GnomeDialog doesn't use a GtkAlignment at present, + but we check for it just in case. */ + if (GTK_IS_ALIGNMENT (child)) + child = GTK_BIN (child)->child; + + /* GNOME uses a hbox inside a hbox, so check for that. */ + if (child && GTK_IS_HBOX (child) + && g_list_length (GTK_BOX (child)->children) == 1) + { + GtkBoxChild *hbox_child; + hbox_child = GTK_BOX (child)->children->data; + child = hbox_child->widget; + } + + /* FIXME: Gnome may not show the icon and/or label according to config + settings. That may break Glade. */ + + /* Now check for a hbox with a GtkImage and GtkLabel children. */ + if (child && GTK_IS_HBOX (child) + && g_list_length (GTK_BOX (child)->children) <= 2) + { + GList *children; + GtkBoxChild *child1, *child2; + + children = GTK_BOX (child)->children; + child1 = children->data; + child2 = children->next ? children->next->data : NULL; + + if (child1 && child2) + { + if (GTK_IS_LABEL (child1->widget) && GTK_IS_IMAGE (child2->widget)) + { + *label = child1->widget; + *icon = child2->widget; + return TRUE; + } + } + else if (GTK_IS_LABEL (child1->widget)) + { + *label = child1->widget; + return TRUE; + } + else if (GTK_IS_IMAGE (child1->widget)) + { + *icon = child1->widget; + return TRUE; + } + } + + return FALSE; +} + + +static void +gb_button_gnome_get_properties (GtkWidget * widget, + GbWidgetGetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p) +{ + gchar *stock_id, *label_text; + gboolean label_sensitive = TRUE; + gboolean icon_sensitive = TRUE; + GtkWidget *label, *icon; + + /* We only allow the GTK_ICON_SIZE_BUTTON size for stock items & icons. */ + if (data->action == GB_SHOWING) + { + property_set_stock_item_icon_size (stock_id_p, GTK_ICON_SIZE_BUTTON); + property_set_icon_size (icon_p, GTK_ICON_SIZE_BUTTON); + } + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), GladeButtonStockIDKey); + /* In the XML the stock item name is actually saved as the label property, + and the use_stock property specifies that it is a stock item. + Also, use_underline needs to be set. */ + if (data->action == GB_SAVING) + { + if (stock_id) + { + gb_widget_output_stock_item (data, "label", stock_id); + gb_widget_output_bool (data, "use_stock", TRUE); + } + } + else + { + gb_widget_output_stock_item (data, stock_id_p, stock_id); + } + + + if (stock_id) + { + label_sensitive = FALSE; + icon_sensitive = FALSE; + } + else + { + if (gb_button_gnome_find_child_widgets (widget, &label, &icon)) + { + gchar *icon_name = NULL; + + if (label) + label_text = (gchar*) gtk_label_get_label (GTK_LABEL (label)); + else + label_text = ""; + + gb_widget_output_translatable_text (data, label_p, label_text); + + /* We always save use_underline as TRUE, though we don't load it. */ + if (data->action == GB_SAVING && !icon) + gb_widget_output_bool (data, "use_underline", TRUE); + + if (icon) + icon_name = gtk_object_get_data (GTK_OBJECT (icon), GladeIconKey); + + /* We never output the icon when saving, as it will be saved as a + child widget. */ + gb_widget_output_icon (data, icon_p, icon_name); + } + else + { + label_sensitive = FALSE; + icon_sensitive = FALSE; + } + } + + if (data->action == GB_SHOWING) + { + if (!label_sensitive) + gb_widget_output_translatable_text (data, label_p, ""); + property_set_sensitive (label_p, label_sensitive); + + if (!icon_sensitive) + gb_widget_output_pixmap_filename (data, icon_p, ""); + property_set_sensitive (icon_p, icon_sensitive); + } +} + + +static void +gb_button_gnome_set_stock_id (GtkWidget *widget, + GbWidgetSetArgData * data, + gchar *stock_id, + gchar *label_p, + gchar *icon_p) +{ + gboolean is_stock_item = FALSE; + const gchar *label_text = ""; + + if (stock_id && stock_id[0]) + is_stock_item = TRUE; + + if (is_stock_item) + { + gtk_button_set_use_stock (GTK_BUTTON (widget), TRUE); + gtk_button_set_label (GTK_BUTTON (widget), stock_id); + gtk_object_set_data_full (GTK_OBJECT (widget), GladeButtonStockIDKey, + g_strdup (stock_id), g_free); + } + else + { + /* Change the button back to a gnome button with a simple label. */ + gtk_button_set_use_stock (GTK_BUTTON (widget), FALSE); + label_text = gtk_widget_get_name (widget); + gtk_button_set_label (GTK_BUTTON (widget), label_text); + gtk_object_set_data (GTK_OBJECT (widget), GladeButtonStockIDKey, NULL); + } + + /* If the widget's properties are displayed, we update the sensitivity of + the label and icon, according to whether a stock item is selected. */ + if (data->action == GB_APPLYING && property_get_widget () == widget) + { + property_set_sensitive (label_p, !is_stock_item); + property_set_sensitive (icon_p, !is_stock_item); + + /* Turn off auto-apply, and set the label. */ + property_set_auto_apply (FALSE); + property_set_text (label_p, label_text); + property_set_filename (icon_p, ""); + property_set_auto_apply (TRUE); + } +} + + +static void +gb_button_gnome_recreate_children (GtkWidget *widget, + GbWidgetSetArgData * data, + gchar *label, gchar *icon_name) +{ + GtkWidget *parent = widget; + + /* Remove any existing children. */ + if (GTK_BIN (widget)->child) + gtk_container_remove (GTK_CONTAINER (widget), GTK_BIN (widget)->child); + + /* If both label and icon are needed, we put them in a hbox, otherwise we + just add the label or icon to the button. */ + if (label && icon_name) + { + GtkWidget *hbox; + + /* It uses a hbox in a hbox to keep the contents in the center, rather + than an alignment like GTK+ does. */ + hbox = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox); + gtk_container_add (GTK_CONTAINER (widget), hbox); + + parent = gtk_hbox_new (FALSE, 0); + gtk_widget_show (parent); + gtk_box_pack_start (GTK_BOX (hbox), parent, TRUE, FALSE, 2); + } + + if (label) + { + GtkWidget *label_widget; + + label_widget = gtk_label_new_with_mnemonic (label); + gtk_widget_show (label_widget); + + if (GTK_IS_BOX (parent)) + gtk_box_pack_end (GTK_BOX (parent), label_widget, FALSE, FALSE, 2); + else + gtk_container_add (GTK_CONTAINER (parent), label_widget); + } + + if (icon_name) + { + GtkWidget *icon_widget; + + icon_widget = gtk_image_new (); + + gtk_object_set_data_full (GTK_OBJECT (icon_widget), GladeIconKey, + g_strdup (icon_name), + icon_name ? g_free : NULL); + + if (glade_util_check_is_stock_id (icon_name)) + { + gtk_image_set_from_stock (GTK_IMAGE (icon_widget), icon_name, + GTK_ICON_SIZE_BUTTON); + } + else + { + gtk_image_set_from_file (GTK_IMAGE (icon_widget), icon_name); + glade_project_add_pixmap (data->project, icon_name); + } + gtk_widget_show (icon_widget); + + if (GTK_IS_BOX (parent)) + gtk_box_pack_start (GTK_BOX (parent), icon_widget, FALSE, FALSE, 0); + else + gtk_container_add (GTK_CONTAINER (parent), icon_widget); + } +} + + +void +gb_button_gnome_set_properties (GtkWidget * widget, + GbWidgetSetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p) +{ + gchar *stock_id = NULL, *label, *icon_name = NULL; + gboolean apply_stock_id = FALSE, apply_label, apply_icon; + gboolean free_label = FALSE, free_icon_name = FALSE; + GtkWidget *label_widget, *icon_widget; + + label = gb_widget_input_text (data, label_p); + apply_label = data->apply; + if (data->action == GB_APPLYING) + free_label = TRUE; + + /* When loading, if "use_stock" is TRUE, then the label is the stock item. */ + if (data->action == GB_LOADING) + { + gboolean is_stock_item = gb_widget_input_bool (data, "use_stock"); + if (is_stock_item) + { + stock_id = label; + apply_stock_id = apply_label; + } + } + else + { + stock_id = gb_widget_input_stock_item (data, stock_id_p); + apply_stock_id = data->apply; + } + + if (apply_stock_id) + { + gb_button_gnome_set_stock_id (widget, data, stock_id, label_p, icon_p); + goto out; + } + + icon_name = gb_widget_input_icon (data, icon_p); + apply_icon = data->apply; + + /* If neither icon nor label is set, we don't touch the button as it may + have other child widgets. */ + if (!apply_label && !apply_icon) + return; + + gb_button_gnome_find_child_widgets (widget, &label_widget, + &icon_widget); + + if (!apply_label) + { + if (label_widget) + { + label = g_strdup (gtk_label_get_label (GTK_LABEL (label_widget))); + free_label = TRUE; + } + else + label = NULL; + } + + if (!apply_icon) + { + if (icon_widget) + { + icon_name = gtk_object_get_data (GTK_OBJECT (icon_widget), + GladeIconKey); + if (icon_name && *icon_name) + { + icon_name = g_strdup (icon_name); + free_icon_name = TRUE; + } + else + icon_name = NULL; + } + else + icon_name = NULL; + } + + if (icon_name && !*icon_name) + icon_name = NULL; + + /* If we have an empty label and an icon, we set the label to NULL so it is + removed. */ + if (label && !*label && icon_name) + { + if (free_label) + g_free (label); + label = NULL; + } + + /* Check if we need to rearrange the child widgets, i.e. if we have a label + but no label widget or we don't have a label but we do have a label + widget. And the same for the icon. */ + if ((apply_label && ((label && !label_widget) || (!label && label_widget))) + || (apply_icon && ((icon_name && !icon_widget) || (!icon_name && icon_widget)))) + { + gb_button_gnome_recreate_children (widget, data, label, icon_name); + + goto out; + } + + /* Just update the current label & icon widgets. */ + if (apply_label) + gtk_label_set_text_with_mnemonic (GTK_LABEL (label_widget), + label ? label : ""); + + if (apply_icon && icon_widget && icon_name) + { + gchar *old_icon_name; + + /* Remove the old icon_name stored in the widget data, and remove the + pixmap from the project, if necessary. */ + old_icon_name = gtk_object_get_data (GTK_OBJECT (icon_widget), + GladeIconKey); + glade_project_remove_pixmap (data->project, old_icon_name); + + if (glade_util_check_is_stock_id (icon_name)) + { + gtk_image_set_from_stock (GTK_IMAGE (icon_widget), icon_name, + GTK_ICON_SIZE_BUTTON); + } + else + { + gtk_image_set_from_file (GTK_IMAGE (icon_widget), icon_name); + glade_project_add_pixmap (data->project, icon_name); + } + + gtk_object_set_data_full (GTK_OBJECT (icon_widget), GladeIconKey, + g_strdup (icon_name), + icon_name ? g_free : NULL); + } + + out: + + if (free_label) + g_free (label); + if (free_icon_name) + g_free (icon_name); +} + + +static void +gb_button_gnome_write_source (GtkWidget * widget, + GbWidgetWriteSourceData * data, + const gchar *label_p) +{ + gchar *stock_id; + gboolean translatable, context; + gchar *comments; + + glade_util_get_translation_properties (widget, label_p, &translatable, + &comments, &context); + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), GladeButtonStockIDKey); + if (stock_id) + { + source_add (data, + " gnome_dialog_append_button (GNOME_DIALOG (%s), %s);\n", + data->component_name, + source_make_string (stock_id, FALSE)); + } + else + { + GtkWidget *label, *icon; + gchar *label_text = NULL; + + gb_button_gnome_find_child_widgets (widget, &label, &icon); + + if (label) + label_text = glade_util_get_label_text (label); + + if (icon) + { + gchar *icon_id; + + icon_id = gtk_object_get_data (GTK_OBJECT (icon), GladeIconKey); + + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gnome_dialog_append_button_with_pixmap (GNOME_DIALOG (%s),\n" + " %s, ", + data->component_name, + label_text ? source_make_string_full (label_text, data->use_gettext && translatable, context) : ""); + + source_add (data, + "%s);\n", + source_make_string (icon_id, FALSE)); + } + else + { + source_add (data, + " gnome_dialog_append_button (GNOME_DIALOG (%s), %s);\n", + data->component_name, + label_text ? source_make_string (label_text, FALSE) : ""); + } + + g_free (label_text); + } + + /* We want to get a pointer to the widget so we can output the standard + source, in case handlers have been added to the buttons. + We can just get the last widget in the GnomeDialog's list of buttons. + Note that we have to make sure that the button isn't added to its + parent widget again elsewhere. */ + source_add (data, " %s = GTK_WIDGET (g_list_last (GNOME_DIALOG (%s)->buttons)->data);\n", + data->wname, data->component_name); + + /* We set this to FALSE, so the code to add it to its parent is skipped. */ + data->create_widget = FALSE; +} + + + + + + +/* + * GbButton functions. + */ + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +void +gb_button_get_standard_properties (GtkWidget * widget, + GbWidgetGetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p, + gchar *relief_p, + gchar *focus_on_click_p) +{ + GladeButtonType button_type; + gboolean relief_visible = TRUE, icon_file_selection = TRUE; + gint i; + + button_type = gb_button_get_button_type (widget); + + switch (button_type) + { + case GLADE_BUTTON_NORMAL: + gb_button_normal_get_properties (widget, data, stock_id_p, label_p, + icon_p); + break; + case GLADE_BUTTON_DIALOG: + gb_button_normal_get_properties (widget, data, stock_id_p, label_p, + icon_p); + break; + case GLADE_BUTTON_GNOME_DIALOG: + gb_button_gnome_get_properties (widget, data, stock_id_p, label_p, + icon_p); + /* Gnome dialog buttons can only have stock icons. */ + icon_file_selection = FALSE; + break; + } + + /* Handle the Relief property here, as it is simple. */ + if (data->action == GB_SHOWING) + { + property_set_visible (relief_p, relief_visible); + property_set_icon_filesel (icon_p, icon_file_selection); + } + + if (relief_visible) + { + for (i = 0; i < GladeReliefChoicesSize; i++) + { + if (GladeReliefValues[i] == GTK_BUTTON (widget)->relief) + gb_widget_output_choice (data, relief_p, i, GladeReliefSymbols[i]); + } + } + + if (focus_on_click_p) + gb_widget_output_bool (data, focus_on_click_p, + gtk_button_get_focus_on_click (GTK_BUTTON (widget))); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_button_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + GladeButtonType button_type; + gboolean response_id_visible = FALSE; + + gb_button_get_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + /* Handle the response id for dialog buttons here. */ + button_type = gb_button_get_button_type (widget); + if (button_type == GLADE_BUTTON_DIALOG) + { + gint response_id; + + response_id_visible = TRUE; + + response_id = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), GladeDialogResponseIDKey)); + /* We save as an int, but show as a string. */ + if (data->action == GB_SHOWING) + { + property_set_combo (ResponseID, + gb_dialog_response_id_to_string (response_id)); + } + else + { + save_int (data, ResponseID, response_id); + } + } + + if (data->action == GB_SHOWING) + property_set_visible (ResponseID, response_id_visible); +} + + +void +gb_button_set_standard_properties (GtkWidget * widget, + GbWidgetSetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p, + gchar *relief_p, + gchar *focus_on_click_p) +{ + GladeButtonType button_type; + gchar *relief; + gint i; + + button_type = gb_button_get_button_type (widget); + + switch (button_type) + { + case GLADE_BUTTON_NORMAL: + gb_button_normal_set_properties (widget, data, stock_id_p, label_p, + icon_p); + break; + case GLADE_BUTTON_DIALOG: + gb_button_normal_set_properties (widget, data, stock_id_p, label_p, + icon_p); + break; + case GLADE_BUTTON_GNOME_DIALOG: + gb_button_gnome_set_properties (widget, data, stock_id_p, label_p, + icon_p); + break; + } + + /* Handle the Relief property here, as it is simple. */ + relief = gb_widget_input_choice (data, relief_p); + if (data->apply) + { + for (i = 0; i < GladeReliefChoicesSize; i++) + { + if (!strcmp (relief, GladeReliefChoices[i]) + || !strcmp (relief, GladeReliefSymbols[i])) + { + gtk_button_set_relief (GTK_BUTTON (widget), + GladeReliefValues[i]); + break; + } + } + } + + if (focus_on_click_p) + { + gboolean focus_on_click; + + focus_on_click = gb_widget_input_bool (data, focus_on_click_p); + if (data->apply) + gtk_button_set_focus_on_click (GTK_BUTTON (widget), focus_on_click); + } +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + GladeButtonType button_type; + gchar *old_stock_id, *stock_id; + gboolean set_response_id = FALSE; + + /* Remember the old stock id. */ + old_stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeButtonStockIDKey); + + gb_button_set_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + /* Handle the response id for dialog buttons here. */ + button_type = gb_button_get_button_type (widget); + if (button_type == GLADE_BUTTON_DIALOG) + { + gint response_id = 0; + + /* See if the stock id has been changed. Note that we only compare the + pointers, since the old string will have been freed. If the stock id + has been changed and is set, we use the corresponding response id, + unless it is also being set. */ + stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeButtonStockIDKey); + if (data->action == GB_APPLYING && stock_id && stock_id != old_stock_id) + { + int i; + + for (i = 0; i < GladeStockResponsesSize; i++) + { + if (GladeStockResponses[i].stock_id + && !strcmp (GladeStockResponses[i].stock_id, stock_id)) + { + response_id = GladeStockResponses[i].response_id; + set_response_id = TRUE; + break; + } + } + } + + + /* We save as an int, but show as a string. */ + if (data->action == GB_LOADING) + { + response_id = gb_widget_input_int (data, ResponseID); + } + else + { + char *response_name = gb_widget_input_combo (data, ResponseID); + if (data->apply) + response_id = gb_dialog_response_id_from_string (response_name); + } + + if (data->apply || set_response_id) + { + gboolean secondary = FALSE; + + gtk_object_set_data (GTK_OBJECT (widget), GladeDialogResponseIDKey, + GINT_TO_POINTER (response_id)); + + if (response_id == GTK_RESPONSE_HELP) + secondary = TRUE; + gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (widget->parent), + widget, secondary); + } + + /* If we are setting the response id as a result of a change of stock + id, then we set the field in the property editor now. */ + if (property_get_widget () == widget && set_response_id) + { + char *old_response_id, *new_response_id; + + old_response_id = property_get_combo (ResponseID, NULL, NULL); + new_response_id = gb_dialog_response_id_to_string (response_id); + + if (strcmp (new_response_id, old_response_id)) + { + property_set_auto_apply (FALSE); + property_set_combo (ResponseID, new_response_id); + property_set_auto_apply (TRUE); + } + } + } +} + + +static void +gb_button_remove_contents (GtkWidget * menuitem, + GtkWidget * widget) +{ + GtkWidget *child; + + g_return_if_fail (GTK_IS_BIN (widget)); + + child = GTK_BIN (widget)->child; + if (child && !GB_IS_PLACEHOLDER (child)) + editor_delete_widget (child); + + /* Reset the stock_id key. */ + gtk_object_set_data (GTK_OBJECT (widget), GladeButtonStockIDKey, NULL); +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkButton, with signals pointing to + * other functions in this file. + */ +void +gb_button_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + GtkWidget *child; + + /* If the button's child isn't a placeholder, add a command to remove the + button's contents. */ + child = GTK_BIN (widget)->child; + if (child && !GB_IS_PLACEHOLDER (child)) + { + GtkWidget *menuitem; + + menuitem = gtk_menu_item_new_with_label (_("Remove Button Contents")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_button_remove_contents), widget); + } +} + + +void +gb_button_write_standard_source (GtkWidget * widget, + GbWidgetWriteSourceData * data, + const gchar *label_p) +{ + GladeButtonType button_type; + gboolean set_relief = TRUE; + gint i; + + if (data->create_widget) + { + button_type = gb_button_get_button_type (widget); + + switch (button_type) + { + case GLADE_BUTTON_NORMAL: + gb_button_normal_write_source (widget, data, label_p); + break; + case GLADE_BUTTON_DIALOG: + gb_button_normal_write_source (widget, data, label_p); + break; + case GLADE_BUTTON_GNOME_DIALOG: + gb_button_gnome_write_source (widget, data, label_p); + break; + } + } + + gb_widget_write_standard_source (widget, data); + + if (set_relief && GTK_BUTTON (widget)->relief != GTK_RELIEF_NORMAL) + { + for (i = 0; i < GladeReliefChoicesSize; i++) + { + if (GladeReliefValues[i] == GTK_BUTTON (widget)->relief) + source_add (data, + " gtk_button_set_relief (GTK_BUTTON (%s), %s);\n", + data->wname, GladeReliefSymbols[i]); + } + } + + if (!gtk_button_get_focus_on_click (GTK_BUTTON (widget))) + { + source_add (data, + " gtk_button_set_focus_on_click (GTK_BUTTON (%s), FALSE);\n", + data->wname); + } +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gb_button_write_standard_source (widget, data, Label); +} + + +/* Note that Check/Radio/Toggle buttons use this function as well. */ +void +gb_button_destroy (GtkWidget * widget, GbWidgetDestroyData * data) +{ + gchar *filename; + + filename = gtk_object_get_data (GTK_OBJECT (widget), GladeIconKey); + glade_project_remove_pixmap (data->project, filename); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_button_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = button_xpm; + gbwidget.tooltip = _("Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_button_new; + gbwidget.gb_widget_create_properties = gb_button_create_properties; + gbwidget.gb_widget_get_properties = gb_button_get_properties; + gbwidget.gb_widget_set_properties = gb_button_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_button_create_popup_menu; + gbwidget.gb_widget_write_source = gb_button_write_source; + gbwidget.gb_widget_destroy = gb_button_destroy; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbcalendar.c b/tools/glade/glade/gbwidgets/gbcalendar.c new file mode 100644 index 00000000..46763bb5 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcalendar.c @@ -0,0 +1,280 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999 Damon Chaplin + * + * calendar gbWidget Copyright (c) 1999 Jay Johnston + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkcalendar.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/calendar.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *ShowHeading = "GtkCalendar::show_heading"; +static gchar *ShowDayNames = "GtkCalendar::show_day_names"; +static gchar *NoMonthChange = "GtkCalendar::no_month_change"; +static gchar *ShowWeekNumbers = "GtkCalendar::show_week_numbers"; +static gchar *WeekStartMonday = "GtkCalendar::week_start_monday"; + +/* When saving, we save all 5 boolean flags in this property. */ +static gchar *DisplayOptions = "GtkCalendar::display_options"; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the funtion in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCalendar, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +static GtkWidget* +gb_calendar_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget = NULL; + + new_widget = gtk_calendar_new(); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ + +static void +gb_calendar_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (ShowHeading, _("Heading:"), + _("If the month and year should be shown at the top")); + property_add_bool (ShowDayNames, _("Day Names:"), + _("If the day names should be shown")); + property_add_bool (NoMonthChange, _("Fixed Month:"), + _("If the month and year shouldn't be changeable")); + property_add_bool (ShowWeekNumbers, _("Week Numbers:"), + _("If the number of the week should be shown")); + property_add_bool (WeekStartMonday, _("Monday First:"), + _("If the week should start on Monday")); +} + + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ + +static void +gb_calendar_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + GtkCalendarDisplayOptions options; + + options = GTK_CALENDAR (widget)->display_flags; + + /* We save all 5 boolean toggles as one property. */ + if (data->action == GB_SAVING) { + char *s = glade_util_string_from_flags (GTK_TYPE_CALENDAR_DISPLAY_OPTIONS, + options); + gb_widget_output_string (data, DisplayOptions, s); + g_free (s); + } else { + gb_widget_output_bool (data, ShowHeading, + options & GTK_CALENDAR_SHOW_HEADING); + gb_widget_output_bool (data, ShowDayNames, + options & GTK_CALENDAR_SHOW_DAY_NAMES); + gb_widget_output_bool (data, NoMonthChange, + options & GTK_CALENDAR_NO_MONTH_CHANGE); + gb_widget_output_bool (data, ShowWeekNumbers, + options & GTK_CALENDAR_SHOW_WEEK_NUMBERS); + gb_widget_output_bool (data, WeekStartMonday, + options & GTK_CALENDAR_WEEK_START_MONDAY); + } +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ + +static void +gb_calendar_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + GtkCalendarDisplayOptions options; + gboolean value; + + options = GTK_CALENDAR (widget)->display_flags; + + /* We load all 5 boolean toggles as one property. */ + if (data->action == GB_LOADING) { + char *s = gb_widget_input_string (data, DisplayOptions); + if (data->apply) + options = glade_util_flags_from_string (GTK_TYPE_CALENDAR_DISPLAY_OPTIONS, s); + } else { + value = gb_widget_input_bool (data, ShowHeading) + ? GTK_CALENDAR_SHOW_HEADING : 0; + if (data->apply) + options = (options & ~GTK_CALENDAR_SHOW_HEADING) | value; + + value = gb_widget_input_bool (data, ShowDayNames) + ? GTK_CALENDAR_SHOW_DAY_NAMES : 0; + if (data->apply) + options = (options & ~GTK_CALENDAR_SHOW_DAY_NAMES) | value; + + value = gb_widget_input_bool (data, NoMonthChange) + ? GTK_CALENDAR_NO_MONTH_CHANGE : 0; + if (data->apply) + options = (options & ~GTK_CALENDAR_NO_MONTH_CHANGE) | value; + + value = gb_widget_input_bool (data, ShowWeekNumbers) + ? GTK_CALENDAR_SHOW_WEEK_NUMBERS : 0; + if (data->apply) + options = (options & ~GTK_CALENDAR_SHOW_WEEK_NUMBERS) | value; + + value = gb_widget_input_bool (data, WeekStartMonday) + ? GTK_CALENDAR_WEEK_START_MONDAY : 0; + if (data->apply) + options = (options & ~GTK_CALENDAR_WEEK_START_MONDAY) | value; + } + + if (options != GTK_CALENDAR (widget)->display_flags) + gtk_calendar_display_options (GTK_CALENDAR (widget), options); +} + + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkCalendar, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_calendar_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) + { + + } +*/ + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ + +static void +gb_calendar_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkCalendarDisplayOptions options = 0; + const gchar *prefix = "\n "; + const gchar *prefix2 = "\n | "; + + if (data->create_widget) + { + source_add (data, " %s = gtk_calendar_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + source_add (data, " gtk_calendar_display_options (GTK_CALENDAR (%s),", + data->wname); + + options = GTK_CALENDAR (widget)->display_flags; + if (options) + { + if (options & GTK_CALENDAR_SHOW_HEADING) + { + source_add (data, "%sGTK_CALENDAR_SHOW_HEADING", prefix); + prefix = prefix2; + } + + if (options & GTK_CALENDAR_SHOW_DAY_NAMES) + { + source_add (data, "%sGTK_CALENDAR_SHOW_DAY_NAMES", prefix); + prefix = prefix2; + } + + if (options & GTK_CALENDAR_NO_MONTH_CHANGE) + { + source_add (data, "%sGTK_CALENDAR_NO_MONTH_CHANGE", prefix); + prefix = prefix2; + } + + if (options & GTK_CALENDAR_SHOW_WEEK_NUMBERS) + { + source_add (data, "%sGTK_CALENDAR_SHOW_WEEK_NUMBERS", prefix); + prefix = prefix2; + } + + if (options & GTK_CALENDAR_WEEK_START_MONDAY) + { + source_add (data, "%sGTK_CALENDAR_WEEK_START_MONDAY", prefix); + } + source_add (data, ");\n"); + } + else + source_add (data, " 0);\n"); +} + + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_calendar_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_calendar_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = calendar_xpm; + gbwidget.tooltip = _("Calendar"); + + /* Fill in any functions that this GbWidget has */ + + gbwidget.gb_widget_new = gb_calendar_new; + gbwidget.gb_widget_create_properties = gb_calendar_create_properties; + gbwidget.gb_widget_get_properties = gb_calendar_get_properties; + gbwidget.gb_widget_set_properties = gb_calendar_set_properties; + /* gbwidget.gb_widget_create_popup_menu = gb_calendar_create_popup_menu; */ + gbwidget.gb_widget_write_source = gb_calendar_write_source; + + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbcellview.c b/tools/glade/glade/gbwidgets/gbcellview.c new file mode 100644 index 00000000..6f4a09f3 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcellview.c @@ -0,0 +1,206 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/cellview.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *BackgroundColor = "GtkCellView::background"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCellView, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +/* +static GtkWidget* +gb_cell_view_new (GbWidgetNewData *data) +{ + +} +*/ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_cell_view_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_color (BackgroundColor, _("Back. Color:"), + _("The background color")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_cell_view_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gboolean background_set; + GdkColor *background_color; + + g_object_get (G_OBJECT (widget), + "background_set", &background_set, + "background_gdk", &background_color, + NULL); + + /* If the background color isn't currently set, set it to black just to + make sure we don't get a random color. */ + if (!background_set) { + background_color->red = 0; + background_color->green = 0; + background_color->blue = 0; + } + + if (data->action == GB_SHOWING || background_set) + gb_widget_output_color (data, BackgroundColor, background_color); + + gdk_color_free (background_color); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_cell_view_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + GdkColor *color; + + color = gb_widget_input_color (data, BackgroundColor); + if (data->apply) + { + gtk_cell_view_set_background_color (GTK_CELL_VIEW (widget), color); + gtk_widget_queue_draw (widget); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkCellView, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_cell_view_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_cell_view_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gboolean background_set; + GdkColor *background_color; + + if (data->create_widget) + { + source_add (data, " %s = gtk_cell_view_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + g_object_get (G_OBJECT (widget), + "background_set", &background_set, + "background_gdk", &background_color, + NULL); + + if (background_set) + { + source_add_decl (data, + " GdkColor %s_bg_color = { 0, %i, %i, %i };\n", + data->real_wname, + background_color->red, background_color->green, + background_color->blue); + + source_add (data, + " gtk_cell_view_set_background_color (GTK_CELL_VIEW (%s), &%s_bg_color);\n", + data->wname, data->wname); + } + + gdk_color_free (background_color); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_cell_view_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_cell_view_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = cellview_xpm; + gbwidget.tooltip = _("Cell View"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_cell_view_create_properties; + gbwidget.gb_widget_get_properties = gb_cell_view_get_properties; + gbwidget.gb_widget_set_properties = gb_cell_view_set_properties; + gbwidget.gb_widget_write_source = gb_cell_view_write_source; +/* + gbwidget.gb_widget_new = gb_cell_view_new; + gbwidget.gb_widget_create_popup_menu = gb_cell_view_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbcheckbutton.c b/tools/glade/glade/gbwidgets/gbcheckbutton.c new file mode 100644 index 00000000..05a30134 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcheckbutton.c @@ -0,0 +1,223 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtkcheckbutton.h> +#include <gtk/gtklabel.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/checkbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *StockButton = "CheckButton|GtkButton::stock_button"; +static gchar *Label = "CheckButton|GtkButton::label"; +static gchar *Icon = "CheckButton|GtkButton::icon"; +static gchar *FocusOnClick = "CheckButton|GtkButton::focus_on_click"; + +/* This is only used for normal/stock buttons, not special toolbar buttons, + as the toolbar has its own relief setting. */ +static gchar *Relief = "CheckButton|GtkButton::relief"; + +static gchar *State = "CheckButton|GtkToggleButton::active"; +static gchar *Inconsistent = "CheckButton|GtkToggleButton::inconsistent"; +static gchar *Indicator = "CheckButton|GtkToggleButton::draw_indicator"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCheckButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_check_button_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_CREATING) + new_widget = gtk_check_button_new_with_label (data->name); + else + { + new_widget = gtk_check_button_new (); + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder()); + } + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_check_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_BUTTON); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_BUTTON); + property_add_choice (Relief, _("Button Relief:"), + _("The relief style of the button"), + GladeReliefChoices); + + property_add_bool (State, _("Initially On:"), + _("If the check button is initially on")); + property_add_bool (Inconsistent, _("Inconsistent:"), + _("If the button is shown in an inconsistent state")); + property_add_bool (Indicator, _("Indicator:"), + _("If the indicator is always drawn")); + property_add_bool (FocusOnClick, _("Focus On Click:"), _("If the button grabs focus when it is clicked")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_check_button_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_button_get_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + gb_widget_output_bool (data, State, data->widget_data->flags & GLADE_ACTIVE); + gb_widget_output_bool (data, Inconsistent, + GTK_TOGGLE_BUTTON (widget)->inconsistent); + gb_widget_output_bool (data, Indicator, + GTK_TOGGLE_BUTTON (widget)->draw_indicator); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_check_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean state, indicator, inconsistent; + + gb_button_set_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + state = gb_widget_input_bool (data, State); + if (data->apply) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), state); + if (state) + data->widget_data->flags |= GLADE_ACTIVE; + else + data->widget_data->flags &= ~GLADE_ACTIVE; + } + + inconsistent = gb_widget_input_bool (data, Inconsistent); + if (data->apply) + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (widget), + inconsistent); + + indicator = gb_widget_input_bool (data, Indicator); + if (data->apply) + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget), indicator); +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_check_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gb_button_write_standard_source (widget, data, Label); + + if (data->widget_data->flags & GLADE_ACTIVE) + { + source_add (data, + " gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (GTK_TOGGLE_BUTTON (widget)->inconsistent) + { + source_add (data, + " gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (!GTK_TOGGLE_BUTTON (widget)->draw_indicator) + { + source_add (data, + " gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (%s), FALSE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_check_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_check_button_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = checkbutton_xpm; + gbwidget.tooltip = _("Check Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_check_button_new; + gbwidget.gb_widget_create_properties = gb_check_button_create_properties; + gbwidget.gb_widget_get_properties = gb_check_button_get_properties; + gbwidget.gb_widget_set_properties = gb_check_button_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_button_create_popup_menu; + gbwidget.gb_widget_write_source = gb_check_button_write_source; + gbwidget.gb_widget_destroy = gb_button_destroy; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbcheckmenuitem.c b/tools/glade/glade/gbwidgets/gbcheckmenuitem.c new file mode 100644 index 00000000..c58c0937 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcheckmenuitem.c @@ -0,0 +1,214 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtkcheckmenuitem.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmenu.h> +#include "../gb.h" +#include "../glade_gnome.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/checkmenuitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Label = "CheckMenuItem|GtkItem::label"; +static gchar *State = "GtkCheckMenuItem::active"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCheckMenuItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_check_menu_item_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_CREATING) + new_widget = gtk_check_menu_item_new_with_label (data->name); + else + new_widget = gtk_check_menu_item_new (); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_check_menu_item_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_bool (State, _("Initially On:"), + _("If the check menu item is initially on")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_check_menu_item_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_widget_output_child_label (widget, data, Label); + + gb_widget_output_bool (data, State, data->widget_data->flags & GLADE_ACTIVE); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_check_menu_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean state; + + gb_widget_input_child_label (widget, data, Label); + + state = gb_widget_input_bool (data, State); + if (data->apply) + { + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), state); + if (state) + data->widget_data->flags |= GLADE_ACTIVE; + else + data->widget_data->flags &= ~GLADE_ACTIVE; + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkCheckMenuItem, with signals pointing to + * other functions in this file. + */ +static void +gb_check_menu_item_create_popup_menu (GtkWidget * widget, + GbWidgetCreateMenuData * data) +{ + /* Add command to remove child label. */ +#if 0 + gb_widget_create_child_label_popup_menu (widget, data); +#endif +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_check_menu_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * + data) +{ + GtkWidget *child = GTK_BIN (widget)->child; + gchar *label_text; + gboolean translatable, context; + gchar *comments; + +#ifdef USE_GNOME + if (data->project->gnome_support) + { + glade_gnome_write_menu_item_source (GTK_MENU_ITEM (widget), data); + return; + } +#endif + + if (child && GTK_IS_LABEL (child) && !GB_IS_GB_WIDGET (child)) + { + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + label_text = glade_util_get_label_text (child); + source_add (data, + " %s = gtk_check_menu_item_new_with_mnemonic (%s);\n", + data->wname, + source_make_string_full (label_text, data->use_gettext && translatable, context)); + g_free (label_text); + } + else + { + source_add (data, " %s = gtk_check_menu_item_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (data->widget_data->flags & GLADE_ACTIVE) + { + source_add (data, + " gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_check_menu_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_check_menu_item_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = checkmenuitem_xpm; + gbwidget.tooltip = _("Check Menu Item"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_check_menu_item_new; + gbwidget.gb_widget_create_properties = gb_check_menu_item_create_properties; + gbwidget.gb_widget_get_properties = gb_check_menu_item_get_properties; + gbwidget.gb_widget_set_properties = gb_check_menu_item_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_check_menu_item_create_popup_menu; + gbwidget.gb_widget_write_source = gb_check_menu_item_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbclist.c b/tools/glade/glade/gbwidgets/gbclist.c new file mode 100644 index 00000000..d52ef9bc --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbclist.c @@ -0,0 +1,610 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtk.h> +#include <gtk/gtkclist.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkspinbutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/clist.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Mode = "GtkCList::selection_mode"; +static gchar *Titles = "GtkCList::show_titles"; +static gchar *Shadow = "GtkCList::shadow_type"; + +/* This is only used for loading & saving - it isn't displayed in the property + editor. */ +static gchar *Cols = "GtkCList::n_columns"; +static gchar *ColumnWidths = "GtkCList::column_widths"; + +static const gchar *GbModeChoices[] = +{"Single", "Browse", "Multiple", NULL}; +static const gint GbModeValues[] = +{ + GTK_SELECTION_SINGLE, + GTK_SELECTION_BROWSE, + GTK_SELECTION_MULTIPLE +}; +static const gchar *GbModeSymbols[] = +{ + "GTK_SELECTION_SINGLE", + "GTK_SELECTION_BROWSE", + "GTK_SELECTION_MULTIPLE" +}; + +static const gchar *GbShadowChoices[] = +{"None", "In", "Out", + "Etched In", "Etched Out", NULL}; +static const gint GbShadowValues[] = +{ + GTK_SHADOW_NONE, + GTK_SHADOW_IN, + GTK_SHADOW_OUT, + GTK_SHADOW_ETCHED_IN, + GTK_SHADOW_ETCHED_OUT +}; +static const gchar *GbShadowSymbols[] = +{ + "GTK_SHADOW_NONE", + "GTK_SHADOW_IN", + "GTK_SHADOW_OUT", + "GTK_SHADOW_ETCHED_IN", + "GTK_SHADOW_ETCHED_OUT" +}; + + +static void show_clist_dialog (GbWidgetNewData * data); +static void on_clist_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_clist_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); +static GtkWidget *new_label (GtkWidget * parent); +static GtkWidget *new_unnamed_label (GtkWidget * parent); + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCList, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_clist_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + gint cols = 0, i; + + if (data->action == GB_LOADING) + { + cols = load_int (data->loading_data, Cols); + if (cols == 0) + cols = 1; + new_widget = gtk_clist_new (cols); + + /* GtkCList has problems if the title buttons aren't created. */ + for (i = 0; i < cols; i++) + { + gtk_clist_set_column_widget (GTK_CLIST (new_widget), i, + new_unnamed_label (new_widget)); + gtk_clist_set_column_width (GTK_CLIST (new_widget), i, 80); + editor_add_mouse_signals_to_existing (GTK_CLIST (new_widget)->column[i].button); + } + + return new_widget; + } + else + { + show_clist_dialog (data); + return NULL; + } +} + + +static void +show_clist_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New columned list"), data->parent, + GTK_SIGNAL_FUNC (on_clist_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_clist_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of columns:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "cols", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_clist_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *dialog, *label; + gint cols, i; + + dialog = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (dialog), "cols"); + g_return_if_fail (spinbutton != NULL); + cols = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_clist_new (cols); + gtk_clist_column_titles_show (GTK_CLIST (new_widget)); + for (i = 0; i < cols; i++) + { + label = new_label (new_widget); + gtk_clist_set_column_widget (GTK_CLIST (new_widget), i, + label); + gtk_clist_set_column_width (GTK_CLIST (new_widget), i, 80); + } + + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (dialog); +} + + +static void +on_clist_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +GtkWidget * +new_label (GtkWidget * parent) +{ + GtkWidget *label; + + label = gb_widget_new ("GtkLabel", parent); + g_return_val_if_fail (label != NULL, NULL); + gb_widget_set_child_name (label, GladeChildCListTitle); + return label; +} + + +GtkWidget * +new_unnamed_label (GtkWidget * parent) +{ + GtkWidget *label; + + label = gb_widget_new_full ("GtkLabel", FALSE, parent, NULL, 0, 0, NULL, + GB_CREATING, NULL); + g_return_val_if_fail (label != NULL, NULL); + gb_widget_set_child_name (label, GladeChildCListTitle); + return label; +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_clist_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Mode, _("Select Mode:"), + _("The selection mode of the columned list"), + GbModeChoices); + property_add_bool (Titles, _("Show Titles:"), + _("If the column titles are shown")); + property_add_choice (Shadow, _("Shadow:"), + _("The type of shadow of the columned list's border"), + GbShadowChoices); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_clist_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gchar buffer[1024]; + gchar *pos; + gboolean buffer_overrun = FALSE; + gint i; + + if (data->action == GB_SAVING) + { + gb_widget_output_int (data, Cols, GTK_CLIST (widget)->columns); + + pos = buffer; + for (i = 0; i < GTK_CLIST (widget)->columns; i++) + { + if (i == 0) + sprintf (pos, "%i", GTK_CLIST (widget)->column[i].width); + else + sprintf (pos, ",%i", GTK_CLIST (widget)->column[i].width); + pos += strlen (pos); + + /* Extra check to make sure we don't overrun the buffer. */ + if (pos - buffer > 1000) + { + g_warning ("Buffer overflow"); + buffer_overrun = TRUE; + break; + } + } + if (!buffer_overrun) + gb_widget_output_string (data, ColumnWidths, buffer); + } + + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == GTK_CLIST (widget)->selection_mode) + gb_widget_output_choice (data, Mode, i, GbModeSymbols[i]); + } + + gb_widget_output_bool (data, Titles, GTK_CLIST_SHOW_TITLES (widget)); + + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) + { + if (GbShadowValues[i] == GTK_CLIST (widget)->shadow_type) + gb_widget_output_choice (data, Shadow, i, GbShadowSymbols[i]); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_clist_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *widths, *pos, *mode; + gchar *shadow; + gboolean titles; + gint col, w, i; + + if (data->action == GB_LOADING) + { + widths = gb_widget_input_string (data, ColumnWidths); + if (data->apply) + { + pos = widths; + for (col = 0; col < GTK_CLIST (widget)->columns; col++) + { + w = atoi (pos); + gtk_clist_set_column_width (GTK_CLIST (widget), col, w); + pos = strchr (pos, ','); + if (!pos) + break; + pos++; + } + } + } + + mode = gb_widget_input_choice (data, Mode); + if (data->apply) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (!strcmp (mode, GbModeChoices[i]) + || !strcmp (mode, GbModeSymbols[i])) + { + gtk_clist_set_selection_mode (GTK_CLIST (widget), GbModeValues[i]); + break; + } + } + } + + titles = gb_widget_input_bool (data, Titles); + if (data->apply) + { + if (titles) + gtk_clist_column_titles_show (GTK_CLIST (widget)); + else + gtk_clist_column_titles_hide (GTK_CLIST (widget)); + } + + shadow = gb_widget_input_choice (data, Shadow); + if (data->apply) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (!strcmp (shadow, GbShadowChoices[i]) + || !strcmp (shadow, GbShadowSymbols[i])) + { + gtk_clist_set_shadow_type (GTK_CLIST (widget), + GbShadowValues[i]); + break; + } + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkCList, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_clist_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + +void +gb_clist_add_child (GtkWidget *widget, GtkWidget *child, GbWidgetSetArgData *data) +{ + /* We store the last column title read in 'last_child' */ + gint col = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + "last_child")); + + if (col >= GTK_CLIST (widget)->columns) { + g_warning ("Too many column title widgets for GtkCList - skipping"); + return; + } + + gtk_clist_set_column_widget (GTK_CLIST (widget), col, child); + gtk_object_set_data (GTK_OBJECT (widget), "last_child", + GINT_TO_POINTER (col + 1)); + + /* We need to add signals to the clist button, just in case the + title widget has no window and so doesn't get signals itself. + Since Clist always creates 1 button initially, the signals would + be added to this button in gb_widget_new, so we could skip it, + but it doesn't hurt. */ + editor_add_mouse_signals_to_existing (GTK_CLIST (widget)->column[col].button); +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_clist_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint col, i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_clist_new (%i);\n", data->wname, + GTK_CLIST (widget)->columns); + } + + /* We reset the last_child index, so as the title widgets are written out + they will start at column 0. */ + gtk_object_set_data (GTK_OBJECT (widget), "last_child", + GINT_TO_POINTER (-1)); + + gb_widget_write_standard_source (widget, data); + + for (col = 0; col < GTK_CLIST (widget)->columns; col++) + { + source_add (data, + " gtk_clist_set_column_width (GTK_CLIST (%s), %i, %i);\n", + data->wname, col, GTK_CLIST (widget)->column[col].width); + } + + if (GTK_CLIST (widget)->selection_mode != GTK_SELECTION_SINGLE) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == GTK_CLIST (widget)->selection_mode) + source_add (data, + " gtk_clist_set_selection_mode (GTK_CLIST (%s), %s);\n", + data->wname, GbModeSymbols[i]); + } + } + + if (GTK_CLIST_SHOW_TITLES (widget)) + source_add (data, " gtk_clist_column_titles_show (GTK_CLIST (%s));\n", + data->wname); + else + source_add (data, " gtk_clist_column_titles_hide (GTK_CLIST (%s));\n", + data->wname); + + if (GTK_CLIST (widget)->shadow_type != GTK_SHADOW_IN) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (GbShadowValues[i] == GTK_CLIST (widget)->shadow_type) + source_add (data, + " gtk_clist_set_shadow_type (GTK_CLIST (%s), %s);\n", + data->wname, GbShadowSymbols[i]); + } + } +} + + +/* Outputs source to add a child widget to a CList. */ +static void +gb_clist_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + gchar *child_name; + + child_name = gb_widget_get_child_name (child); + + /* See if this is a title widget. */ + if (child_name && (!strcmp (child_name, GladeChildCListTitle))) + { + /* We store the last column title written in 'last_child' */ + gint col = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (parent), + "last_child")); + source_add (data, + " gtk_clist_set_column_widget (GTK_CLIST (%s), %i, %s);\n", + parent_name, col + 1, data->wname); + + gtk_object_set_data (GTK_OBJECT (parent), "last_child", + GINT_TO_POINTER (col + 1)); + } + else + { + g_warning ("Unknown CList child widgetL %s", data->wname); + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + } +} + + + +/* This just redraws the entire widget when it is scrolled, to make sure that + it isn't messed up due to our selection handles. */ +static void +gb_scroll_adjustment_changed (GtkAdjustment *adjustment, + GtkWidget *widget) +{ + /* We check that this is a widget in the interface being created rather + than part of Glade's interface. */ + if (GB_IS_GB_WIDGET (widget)) + gtk_widget_queue_clear (widget); +} + + +gboolean +gb_set_scroll_adjustments_hook (GSignalInvocationHint *ihint, + guint n_param_values, + const GValue *param_values, + gpointer data) +{ + GtkObject *object, *hadjustment, *vadjustment; + GtkObject *old_hadjustment, *old_vadjustment; + + object = g_value_get_object (param_values); + + hadjustment = g_value_get_object (param_values + 1); + vadjustment = g_value_get_object (param_values + 2); + + old_hadjustment = gtk_object_get_data (object, "scrollhadjustment"); + if (hadjustment != old_hadjustment) + { + gtk_object_set_data (object, "scrollhadjustment", hadjustment); + + if (hadjustment) + gtk_signal_connect (hadjustment, "value_changed", + (GtkSignalFunc) gb_scroll_adjustment_changed, + object); + } + + old_vadjustment = gtk_object_get_data (object, "scrollvadjustment"); + if (vadjustment != old_vadjustment) + { + gtk_object_set_data (object, "scrollvadjustment", vadjustment); + + if (vadjustment) + gtk_signal_connect (vadjustment, "value_changed", + (GtkSignalFunc) gb_scroll_adjustment_changed, + object); + } + + return TRUE; +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_clist_init () +{ + GtkWidgetClass *klass; + + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_clist_get_type (); + + /* Add a signal emission hook so we can connect signal handlers to the + scrollbar adjustments to redraw the clist when necessary. This will also + work for subclasses of GtkCList. */ + klass = gtk_type_class (gtk_clist_get_type ()); + g_signal_add_emission_hook (klass->set_scroll_adjustments_signal, 0, + gb_set_scroll_adjustments_hook, NULL, NULL); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = clist_xpm; + gbwidget.tooltip = _("Columned List"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_clist_new; + gbwidget.gb_widget_add_child = gb_clist_add_child; + gbwidget.gb_widget_create_properties = gb_clist_create_properties; + gbwidget.gb_widget_get_properties = gb_clist_get_properties; + gbwidget.gb_widget_set_properties = gb_clist_set_properties; + gbwidget.gb_widget_write_source = gb_clist_write_source; + gbwidget.gb_widget_write_add_child_source = gb_clist_write_add_child_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_clist_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbcolorbutton.c b/tools/glade/glade/gbwidgets/gbcolorbutton.c new file mode 100644 index 00000000..95f86b6b --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcolorbutton.c @@ -0,0 +1,225 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/colorbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *UseAlpha = "GtkColorButton::use_alpha"; +static gchar *Title = "GtkColorButton::title"; +static gchar *FocusOnClick = "GtkColorButton|GtkButton::focus_on_click"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkColorButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +/* +static GtkWidget* +gb_color_button_new (GbWidgetNewData *data) +{ + +} +*/ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_color_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (UseAlpha, _("Use Alpha:"), + _("If the alpha channel should be used")); + + property_add_string (Title, _("Title:"), + _("The title of the color selection dialog")); + property_add_bool (FocusOnClick, _("Focus On Click:"), _("If the button grabs focus when it is clicked")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_color_button_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + const gchar *title; + + gb_widget_output_bool (data, UseAlpha, + gtk_color_button_get_use_alpha (GTK_COLOR_BUTTON (widget))); + + /* Only save if the title is different to the default. */ + title = gtk_color_button_get_title (GTK_COLOR_BUTTON (widget)); + if (data->action == GB_SHOWING + || (title && strcmp (title, dgettext (GLADE_GTK_GETTEXT_PACKAGE, + "Pick a Color")))) + gb_widget_output_translatable_string (data, Title, title); + + gb_widget_output_bool (data, FocusOnClick, + gtk_button_get_focus_on_click (GTK_BUTTON (widget))); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_color_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean use_alpha, focus_on_click; + gchar *title; + + use_alpha = gb_widget_input_bool (data, UseAlpha); + if (data->apply) + gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (widget), use_alpha); + + title = gb_widget_input_string (data, Title); + if (data->apply) + gtk_color_button_set_title (GTK_COLOR_BUTTON (widget), + title && title[0] + ? title : dgettext (GLADE_GTK_GETTEXT_PACKAGE, + "Pick a Color")); + + focus_on_click = gb_widget_input_bool (data, FocusOnClick); + if (data->apply) + gtk_button_set_focus_on_click (GTK_BUTTON (widget), focus_on_click); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkColorButton, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_color_button_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_color_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + const gchar *title; + + if (data->create_widget) + { + source_add (data, " %s = gtk_color_button_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + title = gtk_color_button_get_title (GTK_COLOR_BUTTON (widget)); + if (title && title[0] + && strcmp (title, dgettext (GLADE_GTK_GETTEXT_PACKAGE, "Pick a Color"))) + { + gboolean translatable, context; + gchar *comments; + + glade_util_get_translation_properties (widget, Title, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " gtk_color_button_set_title (GTK_COLOR_BUTTON (%s), %s);\n", + data->wname, + source_make_string_full (title, data->use_gettext && translatable, context)); + } + + if (gtk_color_button_get_use_alpha (GTK_COLOR_BUTTON (widget))) + { + source_add (data, + " gtk_color_button_set_use_alpha (GTK_COLOR_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (!gtk_button_get_focus_on_click (GTK_BUTTON (widget))) + { + source_add (data, + " gtk_button_set_focus_on_click (GTK_BUTTON (%s), FALSE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_color_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_color_button_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = colorbutton_xpm; + gbwidget.tooltip = _("Color Chooser Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_color_button_create_properties; + gbwidget.gb_widget_get_properties = gb_color_button_get_properties; + gbwidget.gb_widget_set_properties = gb_color_button_set_properties; + gbwidget.gb_widget_write_source = gb_color_button_write_source; +/* + gbwidget.gb_widget_new = gb_color_button_new; + gbwidget.gb_widget_create_popup_menu = gb_color_button_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbcolorselection.c b/tools/glade/glade/gbwidgets/gbcolorselection.c new file mode 100644 index 00000000..cd629021 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcolorselection.c @@ -0,0 +1,186 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkcolorsel.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/colorselection.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *HasOpacity = "GtkColorSelection::has_opacity_control"; +static gchar *HasPalette = "GtkColorSelection::has_palette"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkColorSelection, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_color_selection_new(GbWidgetNewData *data) +{ + return gtk_color_selection_new (); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_color_selection_create_properties (GtkWidget * widget, GbWidgetCreateArgData + * data) +{ + property_add_bool (HasOpacity, _("Opacity Control:"), + _("If the opacity control is shown")); + property_add_bool (HasPalette, _("Palette:"), + _("If the palette is shown")); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_color_selection_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_widget_output_bool (data, HasOpacity, + gtk_color_selection_get_has_opacity_control (GTK_COLOR_SELECTION (widget))); + gb_widget_output_bool (data, HasPalette, + gtk_color_selection_get_has_palette (GTK_COLOR_SELECTION (widget))); +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_color_selection_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean has_opacity, has_palette; + + has_opacity = gb_widget_input_bool (data, HasOpacity); + if (data->apply) + { + gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (widget), has_opacity); + } + + has_palette = gb_widget_input_bool (data, HasPalette); + if (data->apply) + { + gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (widget), + has_palette); + } +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkColorSelection, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_color_selection_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_color_selection_write_source (GtkWidget * widget, + GbWidgetWriteSourceData * data) +{ + gboolean has_opacity_control; + + if (data->create_widget) + { + source_add (data, " %s = gtk_color_selection_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + /* Although the default is TRUE for the GtkColorSelection, it is FALSE in + the GtkColorSelectionDialog. So we always set it in the source code, since + this is used for both. */ + has_opacity_control = gtk_color_selection_get_has_opacity_control (GTK_COLOR_SELECTION (widget)); + source_add (data, " gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (%s), %s);\n", + data->wname, has_opacity_control ? "TRUE" : "FALSE"); + + if (gtk_color_selection_get_has_palette (GTK_COLOR_SELECTION (widget))) + { + source_add (data, " gtk_color_selection_set_has_palette (GTK_COLOR_SELECTION (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_color_selection_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_color_selection_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = colorselection_xpm; + gbwidget.tooltip = _("Color Selection"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_color_selection_new; + gbwidget.gb_widget_create_properties = gb_color_selection_create_properties; + gbwidget.gb_widget_get_properties = gb_color_selection_get_properties; + gbwidget.gb_widget_set_properties = gb_color_selection_set_properties; + gbwidget.gb_widget_write_source = gb_color_selection_write_source; + /* + gbwidget.gb_widget_create_popup_menu = gb_color_selection_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbcolorselectiondialog.c b/tools/glade/glade/gbwidgets/gbcolorselectiondialog.c new file mode 100644 index 00000000..bf5eacff --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcolorselectiondialog.c @@ -0,0 +1,331 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkcolorseldialog.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/colorseldialog.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "ColorSelDialog|GtkWindow::title"; +static gchar *Type = "ColorSelDialog|GtkWindow::type"; +static gchar *Position = "ColorSelDialog|GtkWindow::window_position"; +static gchar *Modal = "ColorSelDialog|GtkWindow::modal"; +static gchar *DefaultWidth = "ColorSel|GtkWindow::default_width"; +static gchar *DefaultHeight = "ColorSel|GtkWindow::default_height"; +static gchar *Shrink = "ColorSelDialog|GtkWindow::allow_shrink"; +static gchar *Grow = "ColorSelDialog|GtkWindow::allow_grow"; +static gchar *AutoShrink = "ColorSelDialog|GtkWindow::auto_shrink"; +static gchar *IconName = "ColorSelDialog|GtkWindow::icon_name"; +static gchar *FocusOnMap = "ColorSelDialog|GtkWindow::focus_on_map"; + +static gchar *Resizable = "ColorSelDialog|GtkWindow::resizable"; +static gchar *DestroyWithParent = "ColorSelDialog|GtkWindow::destroy_with_parent"; +static gchar *Icon = "ColorSelDialog|GtkWindow::icon"; + +static gchar *Role = "ColorSelDialog|GtkWindow::role"; +static gchar *TypeHint = "ColorSelDialog|GtkWindow::type_hint"; +static gchar *SkipTaskbar = "ColorSelDialog|GtkWindow::skip_taskbar_hint"; +static gchar *SkipPager = "ColorSelDialog|GtkWindow::skip_pager_hint"; +static gchar *Decorated = "ColorSelDialog|GtkWindow::decorated"; +static gchar *Gravity = "ColorSelDialog|GtkWindow::gravity"; +static gchar *Urgency = "ColorSelDialog|GtkWindow::urgency_hint"; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkColorSelectionDialog, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_color_selection_dialog_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_color_selection_dialog_new (_("Select Color")); + + GtkColorSelectionDialog *colorsel = GTK_COLOR_SELECTION_DIALOG (new_widget); + + /* We want it to be treated as a normal window. */ + gtk_window_set_type_hint (GTK_WINDOW (new_widget), + GDK_WINDOW_TYPE_HINT_NORMAL); + + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + gb_widget_create_from (colorsel->ok_button, + data->action == GB_CREATING ? "ok_button" : NULL); + gb_widget_set_child_name (colorsel->ok_button, GladeChildOKButton); + + gb_widget_create_from (colorsel->cancel_button, + data->action == GB_CREATING ? "cancel_button" : NULL); + gb_widget_set_child_name (colorsel->cancel_button, GladeChildCancelButton); + + gb_widget_create_from (colorsel->help_button, + data->action == GB_CREATING ? "help_button" : NULL); + gb_widget_set_child_name (colorsel->help_button, GladeChildHelpButton); + + gb_widget_create_from (colorsel->colorsel, + data->action == GB_CREATING ? "color_selection" : NULL); + gb_widget_set_child_name (colorsel->colorsel, GladeChildColorSelection); + + gtk_object_set_data (GTK_OBJECT (new_widget), TypeHint, + GINT_TO_POINTER (GLADE_TYPE_HINT_DIALOG_INDEX)); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_color_selection_dialog_create_properties (GtkWidget * widget, + GbWidgetCreateArgData * data) +{ + gb_window_create_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_color_selection_dialog_get_properties (GtkWidget * widget, + GbWidgetGetArgData * data) +{ + GtkColorSelectionDialog *colorseldlg; + GtkColorSelection *colorsel; + + colorseldlg = GTK_COLOR_SELECTION_DIALOG (widget); + colorsel = GTK_COLOR_SELECTION (colorseldlg->colorsel); + + gb_window_get_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_color_selection_dialog_set_properties (GtkWidget * widget, + GbWidgetSetArgData * data) +{ + GtkColorSelectionDialog *colorseldlg; + GtkColorSelection *colorsel; + + colorseldlg = GTK_COLOR_SELECTION_DIALOG (widget); + colorsel = GTK_COLOR_SELECTION (colorseldlg->colorsel); + + gb_window_set_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkColorSelectionDialog, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_color_selection_dialog_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_color_selection_dialog_write_source (GtkWidget * widget, + GbWidgetWriteSourceData * data) +{ + gchar *wname, *child_name; + const gchar *child_widget_name; + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + glade_util_get_translation_properties (widget, Title, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, " %s = gtk_color_selection_dialog_new (%s);\n", + data->wname, + source_make_string_full (GTK_WINDOW (widget)->title, + data->use_gettext && translatable, + context)); + } + + gb_widget_write_standard_source (widget, data); + + /* The title is already set above, so we pass NULL to skip it. */ + gb_window_write_standard_source (widget, data, + NULL, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + + + /* We output the source code for the buttons here, but we don't want them + to be created. We need to remember the dialog's name since data->wname + will be overwritten. */ + wname = g_strdup (data->wname); + + source_add (data, "\n"); + + child_widget_name = gtk_widget_get_name (GTK_COLOR_SELECTION_DIALOG (widget)->ok_button); + child_name = source_create_valid_identifier (child_widget_name); + source_add (data, " %s = GTK_COLOR_SELECTION_DIALOG (%s)->ok_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_COLOR_SELECTION_DIALOG (widget)->ok_button, + data); + + child_widget_name = gtk_widget_get_name (GTK_COLOR_SELECTION_DIALOG (widget)->cancel_button); + child_name = source_create_valid_identifier (child_widget_name); + source_add (data, " %s = GTK_COLOR_SELECTION_DIALOG (%s)->cancel_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_COLOR_SELECTION_DIALOG (widget)->cancel_button, + data); + + child_widget_name = gtk_widget_get_name (GTK_COLOR_SELECTION_DIALOG (widget)->help_button); + child_name = source_create_valid_identifier (child_widget_name); + source_add (data, " %s = GTK_COLOR_SELECTION_DIALOG (%s)->help_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_COLOR_SELECTION_DIALOG (widget)->help_button, + data); + + child_widget_name = gtk_widget_get_name (GTK_COLOR_SELECTION_DIALOG (widget)->colorsel); + child_name = source_create_valid_identifier (child_widget_name); + source_add (data, " %s = GTK_COLOR_SELECTION_DIALOG (%s)->colorsel;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_COLOR_SELECTION_DIALOG (widget)->colorsel, + data); + + g_free (wname); + + data->write_children = FALSE; +} + + + +static GtkWidget * +gb_color_selection_dialog_get_child (GtkWidget * widget, + const gchar * child_name) +{ + if (!strcmp (child_name, GladeChildOKButton)) + return GTK_COLOR_SELECTION_DIALOG (widget)->ok_button; + else if (!strcmp (child_name, GladeChildCancelButton)) + return GTK_COLOR_SELECTION_DIALOG (widget)->cancel_button; + else if (!strcmp (child_name, GladeChildHelpButton)) + return GTK_COLOR_SELECTION_DIALOG (widget)->help_button; + else if (!strcmp (child_name, GladeChildColorSelection)) + return GTK_COLOR_SELECTION_DIALOG (widget)->colorsel; + else + return NULL; +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_color_selection_dialog_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_color_selection_dialog_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = colorseldialog_xpm; + gbwidget.tooltip = _("Color Selection Dialog"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_color_selection_dialog_new; + gbwidget.gb_widget_create_properties = gb_color_selection_dialog_create_properties; + gbwidget.gb_widget_get_properties = gb_color_selection_dialog_get_properties; + gbwidget.gb_widget_set_properties = gb_color_selection_dialog_set_properties; + gbwidget.gb_widget_get_child = gb_color_selection_dialog_get_child; + gbwidget.gb_widget_write_source = gb_color_selection_dialog_write_source; + gbwidget.gb_widget_destroy = gb_window_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_color_selection_dialog_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbcombo.c b/tools/glade/glade/gbwidgets/gbcombo.c new file mode 100644 index 00000000..3ba0536a --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcombo.c @@ -0,0 +1,439 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtkcombo.h> +#include <gtk/gtklabel.h> +#include <gtk/gtklist.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/combo.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +/* These 2 are stored in the widget's datalist since otherwise GtkCombo starts + to grab the pointer if invalid values are entered which causes problems. */ +static gchar *ValueInList = "GtkCombo::value_in_list"; +static gchar *OKIfEmpty = "GtkCombo::allow_empty"; + +static gchar *Case = "GtkCombo::case_sensitive"; +static gchar *Arrows = "GtkCombo::enable_arrow_keys"; +static gchar *Always = "GtkCombo::enable_arrows_always"; +static gchar *Items = "GtkCombo::items"; + +static void add_label (GtkWidget * widget, GString * items); + +static gint is_simple_combo (GtkWidget * widget); +static void is_simple_combo_callback (GtkWidget * widget, + gint * num_children); +static void write_items_source_callback (GtkWidget * item, + GbWidgetWriteSourceData * data); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCombo, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_combo_new(GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_combo_new (); + + /* There is no way to move up from the popup list window to the combo, so + we have to add a pointer here. It is used in glade_util_get_parent (). + We don't add a ref to it, in case it messes up the normal widget code. */ + gtk_object_set_data (GTK_OBJECT (GTK_COMBO (new_widget)->popwin), + GladeParentKey, new_widget); + + gb_widget_create_from (GTK_COMBO (new_widget)->entry, + data->action == GB_CREATING ? "combo-entry" : NULL); + gb_widget_set_child_name (GTK_COMBO (new_widget)->entry, GladeChildComboEntry); + + gb_widget_create_from (GTK_COMBO (new_widget)->list, + data->action == GB_CREATING ? "combo-list" : NULL); + gb_widget_set_child_name (GTK_COMBO (new_widget)->list, GladeChildComboList); + + /* This defaults to TRUE. */ + gtk_object_set_data (GTK_OBJECT (new_widget), OKIfEmpty, "TRUE"); + + /* FIXME: GTK+ 1.3 temporary hack to workaround problems. */ + gtk_signal_handler_block (GTK_OBJECT (GTK_COMBO (new_widget)->entry), + GTK_COMBO (new_widget)->entry_change_id); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_combo_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (ValueInList, _("Value In List:"), + _("If the value must be in the list")); + property_add_bool (OKIfEmpty, _("OK If Empty:"), + _("If an empty value is acceptable, when 'Value In List' is set")); + property_add_bool (Case, _("Case Sensitive:"), + _("If the searching is case sensitive")); + property_add_bool (Arrows, _("Use Arrows:"), + _("If arrows can be used to change the value")); + property_add_bool (Always, _("Use Always:"), + _("If arrows work even if the value is not in the list")); + property_add_text (Items, _("Items:"), + _("The items in the combo list, one per line"), 5); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_combo_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_widget_output_bool (data, ValueInList, + gtk_object_get_data (GTK_OBJECT (widget), ValueInList) + != NULL ? TRUE : FALSE); + gb_widget_output_bool (data, OKIfEmpty, + gtk_object_get_data (GTK_OBJECT (widget), OKIfEmpty) + != NULL ? TRUE : FALSE); + gb_widget_output_bool (data, Case, GTK_COMBO (widget)->case_sensitive); + gb_widget_output_bool (data, Arrows, GTK_COMBO (widget)->use_arrows); + gb_widget_output_bool (data, Always, GTK_COMBO (widget)->use_arrows_always); + + if (data->action == GB_SHOWING && is_simple_combo (widget) >= 0) + { + GString *items; + + items = g_string_new (""); + gtk_container_foreach (GTK_CONTAINER (GTK_COMBO (widget)->list), + (GtkCallback) add_label, items); + gb_widget_output_translatable_text_in_lines (data, Items, items->str); + g_string_free (items, TRUE); + } +} + +/* Adds combo label text to buffer, or sets first char to -1 if it won't fit. + */ +static void +add_label (GtkWidget * widget, GString *items) +{ + const gchar *label_text; + + label_text = gtk_label_get_text (GTK_LABEL (GTK_BIN (widget)->child)); + g_string_append (items, label_text); + g_string_append_c (items, '\n'); +} + + +/* Returns number of items in combo list, or -1 if not a simple combo (not + all children are labels). */ +static gint +is_simple_combo (GtkWidget * widget) +{ + gint num_children = 0; + + gtk_container_foreach (GTK_CONTAINER (GTK_COMBO (widget)->list), + (GtkCallback) is_simple_combo_callback, &num_children); + return num_children; +} + + +/* Sets flag to FALSE if list item's child widget is not a label. */ +static void +is_simple_combo_callback (GtkWidget * widget, gint * num_children) +{ + /* If we've already found an item which isn't a simple label, just return. */ + if (*num_children == -1) + return; + + /* If the items isn't a simple label, set num_children to -1, else add 1. */ + if (!GTK_IS_LABEL (GTK_BIN (widget)->child)) + *num_children = -1; + else + *num_children += 1; +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_combo_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean value_in_list, ok_if_empty, case_sensitive, arrows, arrows_always; + gchar *items; + + value_in_list = gb_widget_input_bool (data, ValueInList); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), ValueInList, + value_in_list ? "TRUE" : NULL); + } + + ok_if_empty = gb_widget_input_bool (data, OKIfEmpty); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), OKIfEmpty, + ok_if_empty ? "TRUE" : NULL); + } + + case_sensitive = gb_widget_input_bool (data, Case); + if (data->apply) + gtk_combo_set_case_sensitive (GTK_COMBO (widget), case_sensitive); + arrows = gb_widget_input_bool (data, Arrows); + if (data->apply) + gtk_combo_set_use_arrows (GTK_COMBO (widget), arrows); + arrows_always = gb_widget_input_bool (data, Always); + if (data->apply) + gtk_combo_set_use_arrows_always (GTK_COMBO (widget), arrows_always); + + if (data->action == GB_APPLYING) + { + items = gb_widget_input_text (data, Items); + if (data->apply) + { + GtkWidget *list = GTK_COMBO (widget)->list; + GtkWidget *listitem; + gchar *pos = items; + gchar *items_end = &items[strlen (items)]; + + gtk_list_clear_items (GTK_LIST (list), 0, -1); + + while (pos < items_end) + { + gchar *item_end = strchr (pos, '\n'); + if (item_end == NULL) + item_end = items_end; + *item_end = '\0'; + + listitem = gb_widget_new ("GtkListItem", list); + gtk_label_set_text (GTK_LABEL (GTK_BIN (listitem)->child), pos); + gtk_widget_show (listitem); + gtk_container_add (GTK_CONTAINER (list), listitem); + + if (item_end != items_end) + *item_end = '\n'; + + pos = item_end + 1; + } + + g_free (items); + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkCombo, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_combo_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_combo_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *wname, *child_name; + gboolean value_in_list, ok_if_empty; + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + source_add (data, " %s = gtk_combo_new ();\n", data->wname); + } + + /* We store a pointer to the popup window's parent combo, so lookup_widget() + will still work when the popup window is passed as the first arg. */ + source_add (data, + " g_object_set_data (G_OBJECT (GTK_COMBO (%s)->popwin),\n" + " \"GladeParentKey\", %s);\n", + data->wname, data->wname); + + gb_widget_write_standard_source (widget, data); + + value_in_list = gtk_object_get_data (GTK_OBJECT (widget), ValueInList) + != NULL ? TRUE : FALSE; + if (value_in_list) + { + ok_if_empty = gtk_object_get_data (GTK_OBJECT (widget), OKIfEmpty) + != NULL ? TRUE : FALSE; + source_add (data, + " gtk_combo_set_value_in_list (GTK_COMBO (%s), %s, %s);\n", + data->wname, + value_in_list ? "TRUE" : "FALSE", + ok_if_empty ? "TRUE" : "FALSE"); + } + + + if (GTK_COMBO (widget)->case_sensitive) + { + source_add (data, + " gtk_combo_set_case_sensitive (GTK_COMBO (%s), TRUE);\n", + data->wname); + } + if (!GTK_COMBO (widget)->use_arrows) + { + source_add (data, + " gtk_combo_set_use_arrows (GTK_COMBO (%s), FALSE);\n", + data->wname); + } + if (GTK_COMBO (widget)->use_arrows_always) + { + source_add (data, + " gtk_combo_set_use_arrows_always (GTK_COMBO (%s), TRUE);\n", + data->wname); + } + + if (is_simple_combo (widget) > 0) + { + gboolean old_use_gettext; + + source_add_decl (data, " GList *%s_items = NULL;\n", data->real_wname); + + glade_util_get_translation_properties (widget, Items, &translatable, + &comments, &context); + + /* Temporarily set data->use_gettext to take the translatable flag for + this property into account, so our callback can use that. */ + old_use_gettext = data->use_gettext; + data->use_gettext = data->use_gettext && translatable ? TRUE : FALSE; + gtk_container_foreach (GTK_CONTAINER (GTK_COMBO (widget)->list), + (GtkCallback) write_items_source_callback, data); + data->use_gettext = old_use_gettext; + + source_add (data, + " gtk_combo_set_popdown_strings (GTK_COMBO (%s), %s_items);\n", + data->wname, data->real_wname); + source_add (data, " g_list_free (%s_items);\n", data->real_wname); + } + + + /* We output the source code for the children here, since the code should + not include calls to create the widgets. We need to specify that the + names used are like: "GTK_COMBO (<combo-name>)->entry". + We need to remember the dialog's name since data->wname + will be overwritten. */ + wname = g_strdup (data->wname); + + source_add (data, "\n"); + child_name = (gchar*) gtk_widget_get_name (GTK_COMBO (widget)->entry); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_COMBO (%s)->entry;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_COMBO (widget)->entry, data); + + g_free (wname); + data->write_children = FALSE; +} + + +static void +write_items_source_callback (GtkWidget * item, GbWidgetWriteSourceData * data) +{ + const gchar *label_text; + label_text = gtk_label_get_text (GTK_LABEL (GTK_BIN (item)->child)); + /* The (gpointer) cast is just to keep g++ happy. */ + source_add (data, " %s_items = g_list_append (%s_items, (gpointer) %s);\n", + data->real_wname, data->real_wname, + source_make_string (label_text, data->use_gettext)); +} + + +static GtkWidget * +gb_combo_get_child (GtkWidget * widget, + const gchar * child_name) +{ + if (!strcmp (child_name, GladeChildComboEntry)) + return GTK_COMBO (widget)->entry; + else if (!strcmp (child_name, GladeChildComboList)) + return GTK_COMBO (widget)->list; + else + return NULL; +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_combo_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_combo_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = combo_xpm; + gbwidget.tooltip = _("Combo Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_combo_new; + gbwidget.gb_widget_create_properties = gb_combo_create_properties; + gbwidget.gb_widget_get_properties = gb_combo_get_properties; + gbwidget.gb_widget_set_properties = gb_combo_set_properties; + gbwidget.gb_widget_get_child = gb_combo_get_child; + gbwidget.gb_widget_write_source = gb_combo_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_combo_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbcombobox.c b/tools/glade/glade/gbwidgets/gbcombobox.c new file mode 100644 index 00000000..d290822b --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcombobox.c @@ -0,0 +1,303 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/combobox.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +/* This isn't a real property, but since we can't set up a proper tree model + we just support simple text like we did for GtkCombo. */ +static gchar *Items = "GtkComboBox::items"; + +static gchar *AddTearoffs = "GtkComboBox::add_tearoffs"; +#if 0 +/* I don't think this is useful for GtkComboBox itself. */ +static gchar *HasFrame = "GtkComboBox::has_frame"; +#endif +static gchar *FocusOnClick = "GtkComboBox::focus_on_click"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkComboBox, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_combo_box_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_combo_box_new_text (); + + /* Force the combobox to create the child widgets, so that we can connect + to all the "event" signals so the user can select the widget. */ + gtk_widget_ensure_style (new_widget); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_combo_box_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_text (Items, _("Items:"), + _("The items in the combo list, one per line"), 5); + + property_add_bool (AddTearoffs, _("Add Tearoffs:"), + _("Whether dropdowns should have a tearoff menu item")); + property_add_bool (FocusOnClick, _("Focus On Click:"), + _("Whether the combo box grabs focus when it is clicked")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_combo_box_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gchar *items; + gboolean add_tearoffs, focus_on_click; + + items = gtk_object_get_data (GTK_OBJECT (widget), Items); + gb_widget_output_translatable_text_in_lines (data, Items, items); + + g_object_get (G_OBJECT (widget), + "add_tearoffs", &add_tearoffs, + "focus_on_click", &focus_on_click, + NULL); + + gb_widget_output_bool (data, AddTearoffs, add_tearoffs); + gb_widget_output_bool (data, FocusOnClick, focus_on_click); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_combo_box_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *items; + gboolean add_tearoffs, focus_on_click; + + items = gb_widget_input_text (data, Items); + if (data->apply) + { + GtkTreeModel *model; + gchar *pos = items; + gchar *items_end = &items[strlen (items)]; + + /* Save a copy so it is easy to get out later. */ + gtk_object_set_data_full (GTK_OBJECT (widget), Items, + g_strdup (items), g_free); + + /* Clear the list. */ + model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); + gtk_list_store_clear (GTK_LIST_STORE (model)); + + /* Now add the items one at a time. */ + while (pos < items_end) + { + gchar *item_end = strchr (pos, '\n'); + if (item_end == NULL) + item_end = items_end; + *item_end = '\0'; + + gtk_combo_box_append_text (GTK_COMBO_BOX (widget), pos); + + if (item_end != items_end) + *item_end = '\n'; + + pos = item_end + 1; + } + } + if (data->action == GB_APPLYING) + g_free (items); + + add_tearoffs = gb_widget_input_bool (data, AddTearoffs); + if (data->apply) + gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (widget), add_tearoffs); + + focus_on_click = gb_widget_input_bool (data, FocusOnClick); + if (data->apply) + gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (widget), focus_on_click); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkComboBox, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_combo_box_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_combo_box_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *items, *pos, *items_end; + gboolean translatable, context; + gchar *comments; + gboolean add_tearoffs, focus_on_click; + + items = pos = gtk_object_get_data (GTK_OBJECT (widget), Items); + + glade_util_get_translation_properties (widget, Items, &translatable, + &comments, &context); + + if (data->create_widget) + { + /* If any items have been entered, we create a simple text combo, + otherwise we create a bare combo without a model, so the user can + setup the model in their code. */ + /* NOTE: Creating it without a model causes problems so we always create + a model now. Users can still set the model to something else. */ +#if 0 + if (items && items[0]) + { + source_add (data, " %s = gtk_combo_box_new_text ();\n", + data->wname); + } + else + { + source_add (data, " %s = gtk_combo_box_new ();\n", + data->wname); + } +#endif + + source_add (data, " %s = gtk_combo_box_text_new ();\n", + data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (items && items[0]) + { + items_end = &items[strlen (items)]; + + while (pos < items_end) + { + gchar *item_end = strchr (pos, '\n'); + if (item_end == NULL) + item_end = items_end; + *item_end = '\0'; + + source_add (data, " gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (%s), %s);\n", + data->wname, + source_make_string (pos, + data->use_gettext && translatable)); + + if (item_end != items_end) + *item_end = '\n'; + + pos = item_end + 1; + } + } + + g_object_get (G_OBJECT (widget), + "add_tearoffs", &add_tearoffs, + "focus_on_click", &focus_on_click, + NULL); + + if (add_tearoffs) + { + source_add (data, + " gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (%s), TRUE);\n", + data->wname); + } + + if (!focus_on_click) + { + source_add (data, + " gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (%s), FALSE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_combo_box_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_combo_box_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = combobox_xpm; + gbwidget.tooltip = _("Combo Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_combo_box_new; + gbwidget.gb_widget_create_properties = gb_combo_box_create_properties; + gbwidget.gb_widget_get_properties = gb_combo_box_get_properties; + gbwidget.gb_widget_set_properties = gb_combo_box_set_properties; + gbwidget.gb_widget_write_source = gb_combo_box_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_combo_box_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbcomboboxentry.c b/tools/glade/glade/gbwidgets/gbcomboboxentry.c new file mode 100644 index 00000000..500a5ad5 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcomboboxentry.c @@ -0,0 +1,316 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/comboboxentry.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +/* This isn't a real property, but since we can't set up a proper tree model + we just support simple text like we did for GtkCombo. */ +static gchar *Items = "GtkComboBoxEntry::items"; + +static gchar *AddTearoffs = "GtkComboBoxEntry|GtkComboBox::add_tearoffs"; +static gchar *HasFrame = "GtkComboBoxEntry|GtkComboBox::has_frame"; +static gchar *FocusOnClick = "GtkComboBoxEntry|GtkComboBox::focus_on_click"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkComboBoxEntry, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_combo_box_entry_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_combo_box_entry_new_text (); + + /* Force the combobox to create the child widgets, so that we can connect + to all the "event" signals so the user can select the widget. */ + gtk_widget_ensure_style (new_widget); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_combo_box_entry_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_text (Items, _("Items:"), + _("The items in the combo list, one per line"), 5); + + property_add_bool (AddTearoffs, _("Add Tearoffs:"), + _("Whether dropdowns should have a tearoff menu item")); + property_add_bool (HasFrame, _("Has Frame:"), + _("Whether the combo box draws a frame around the child")); + property_add_bool (FocusOnClick, _("Focus On Click:"), + _("Whether the combo box grabs focus when it is clicked")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_combo_box_entry_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gchar *items; + gboolean add_tearoffs, has_frame, focus_on_click; + + items = gtk_object_get_data (GTK_OBJECT (widget), Items); + gb_widget_output_translatable_text_in_lines (data, Items, items); + + g_object_get (G_OBJECT (widget), + "add_tearoffs", &add_tearoffs, + "has_frame", &has_frame, + "focus_on_click", &focus_on_click, + NULL); + + gb_widget_output_bool (data, AddTearoffs, add_tearoffs); + gb_widget_output_bool (data, HasFrame, has_frame); + gb_widget_output_bool (data, FocusOnClick, focus_on_click); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_combo_box_entry_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *items; + gboolean add_tearoffs, has_frame, focus_on_click; + + items = gb_widget_input_text (data, Items); + if (data->apply) + { + GtkTreeModel *model; + gchar *pos = items; + gchar *items_end = &items[strlen (items)]; + + /* Save a copy so it is easy to get out later. */ + gtk_object_set_data_full (GTK_OBJECT (widget), Items, + g_strdup (items), g_free); + + /* Clear the list. */ + model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); + gtk_list_store_clear (GTK_LIST_STORE (model)); + + /* Now add the items one at a time. */ + while (pos < items_end) + { + gchar *item_end = strchr (pos, '\n'); + if (item_end == NULL) + item_end = items_end; + *item_end = '\0'; + + gtk_combo_box_append_text (GTK_COMBO_BOX (widget), pos); + + if (item_end != items_end) + *item_end = '\n'; + + pos = item_end + 1; + } + } + if (data->action == GB_APPLYING) + g_free (items); + + add_tearoffs = gb_widget_input_bool (data, AddTearoffs); + if (data->apply) + gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (widget), add_tearoffs); + + has_frame = gb_widget_input_bool (data, HasFrame); + if (data->apply) + g_object_set (widget, "has_frame", has_frame, NULL); + + focus_on_click = gb_widget_input_bool (data, FocusOnClick); + if (data->apply) + gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (widget), focus_on_click); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkComboBoxEntry, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_combo_box_entry_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_combo_box_entry_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *items, *pos, *items_end; + gboolean translatable, context; + gchar *comments; + gboolean add_tearoffs, has_frame, focus_on_click; + + items = pos = gtk_object_get_data (GTK_OBJECT (widget), Items); + + glade_util_get_translation_properties (widget, Items, &translatable, + &comments, &context); + + if (data->create_widget) + { + /* If any items have been entered, we create a simple text combo, + otherwise we create a bare combo without a model, so the user can + setup the model in their code. */ + /* NOTE: Creating it without a model causes problems so we always create + a model now. Users can still set the model to something else. */ +#if 0 + if (items && items[0]) + { + source_add (data, " %s = gtk_combo_box_entry_new_text ();\n", + data->wname); + } + else + { + source_add (data, " %s = gtk_combo_box_entry_new ();\n", + data->wname); + } +#endif + + source_add (data, " %s = gtk_combo_box_entry_new_text ();\n", + data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (items && items[0]) + { + items_end = &items[strlen (items)]; + + while (pos < items_end) + { + gchar *item_end = strchr (pos, '\n'); + if (item_end == NULL) + item_end = items_end; + *item_end = '\0'; + + source_add (data, " gtk_combo_box_append_text (GTK_COMBO_BOX (%s), %s);\n", + data->wname, + source_make_string (pos, + data->use_gettext && translatable)); + + if (item_end != items_end) + *item_end = '\n'; + + pos = item_end + 1; + } + } + + g_object_get (G_OBJECT (widget), + "add_tearoffs", &add_tearoffs, + "has_frame", &has_frame, + "focus_on_click", &focus_on_click, + NULL); + + if (add_tearoffs) + { + source_add (data, + " gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (%s), TRUE);\n", + data->wname); + } + + if (!has_frame) + { + source_add (data, + " g_object_set (%s, \"has_frame\", FALSE, NULL);\n", + data->wname); + } + + if (!focus_on_click) + { + source_add (data, + " gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (%s), FALSE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_combo_box_entry_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_combo_box_entry_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = comboboxentry_xpm; + gbwidget.tooltip = _("Combo Box Entry"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_combo_box_entry_new; + gbwidget.gb_widget_create_properties = gb_combo_box_entry_create_properties; + gbwidget.gb_widget_get_properties = gb_combo_box_entry_get_properties; + gbwidget.gb_widget_set_properties = gb_combo_box_entry_set_properties; + gbwidget.gb_widget_write_source = gb_combo_box_entry_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_combo_box_entry_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbctree.c b/tools/glade/glade/gbwidgets/gbctree.c new file mode 100644 index 00000000..50aafcbc --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbctree.c @@ -0,0 +1,554 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtkctree.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkspinbutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/ctree.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Mode = "CTree|GtkCList::selection_mode"; +static gchar *Titles = "CTree|GtkCList::show_titles"; +static gchar *Shadow = "CTree|GtkCList::shadow_type"; + +/* This is only used for loading & saving - it isn't displayed in the property + editor. */ +static gchar *Cols = "GtkCTree::n_columns"; +static gchar *ColumnWidths = "GtkCTree::column_widths"; + +static const gchar *GbModeChoices[] = +{"Single", "Browse", "Multiple", NULL}; +static const gint GbModeValues[] = +{ + GTK_SELECTION_SINGLE, + GTK_SELECTION_BROWSE, + GTK_SELECTION_MULTIPLE +}; +static const gchar *GbModeSymbols[] = +{ + "GTK_SELECTION_SINGLE", + "GTK_SELECTION_BROWSE", + "GTK_SELECTION_MULTIPLE" +}; + +static const gchar *GbShadowChoices[] = +{"None", "In", "Out", + "Etched In", "Etched Out", NULL}; +static const gint GbShadowValues[] = +{ + GTK_SHADOW_NONE, + GTK_SHADOW_IN, + GTK_SHADOW_OUT, + GTK_SHADOW_ETCHED_IN, + GTK_SHADOW_ETCHED_OUT +}; +static const gchar *GbShadowSymbols[] = +{ + "GTK_SHADOW_NONE", + "GTK_SHADOW_IN", + "GTK_SHADOW_OUT", + "GTK_SHADOW_ETCHED_IN", + "GTK_SHADOW_ETCHED_OUT" +}; + + +static void show_ctree_dialog (GbWidgetNewData * data); +static void on_ctree_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_ctree_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); +static GtkWidget *new_label (GtkWidget * parent); +static GtkWidget *new_unnamed_label (GtkWidget * parent); + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the funtion in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCTree, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_ctree_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + gint cols = 0, i; + + if (data->action == GB_LOADING) + { + cols = load_int (data->loading_data, Cols); + + /* For backwards compatability with 1.1.1. */ + if (cols == 0) + cols = load_int (data->loading_data, "columns"); + + if (cols == 0) + cols = 1; + /* FIXME: Allow setting of tree column - 2nd arg */ + new_widget = gtk_ctree_new (cols, 0); + + /* GtkCList has problems if the title buttons aren't created. */ + for (i = 0; i < cols; i++) + { + gtk_clist_set_column_widget (GTK_CLIST (new_widget), i, + new_unnamed_label (new_widget)); + gtk_clist_set_column_width (GTK_CLIST (new_widget), i, 80); + editor_add_mouse_signals_to_existing (GTK_CLIST (new_widget)->column[i].button); + } + + return new_widget; + } + else + { + show_ctree_dialog (data); + return NULL; + } +} + + +static void +show_ctree_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New columned tree"), data->parent, + GTK_SIGNAL_FUNC (on_ctree_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_ctree_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of columns:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "cols", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_ctree_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *dialog, *label; + gint cols, i; + + dialog = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (dialog), "cols"); + g_return_if_fail (spinbutton != NULL); + cols = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + /* FIXME: Allow setting of tree column - 2nd arg */ + new_widget = gtk_ctree_new (cols, 0); + gtk_clist_column_titles_show (GTK_CLIST (new_widget)); + for (i = 0; i < cols; i++) + { + label = new_label (new_widget); + gtk_clist_set_column_widget (GTK_CLIST (new_widget), i, + label); + gtk_clist_set_column_width (GTK_CLIST (new_widget), i, 80); + } + + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (dialog); +} + + +static void +on_ctree_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +GtkWidget * +new_label (GtkWidget * parent) +{ + GtkWidget *label; + + label = gb_widget_new ("GtkLabel", parent); + g_return_val_if_fail (label != NULL, NULL); + gb_widget_set_child_name (label, GladeChildCListTitle); + return label; +} + + +GtkWidget * +new_unnamed_label (GtkWidget * parent) +{ + GtkWidget *label; + + label = gb_widget_new_full ("GtkLabel", FALSE, parent, NULL, 0, 0, NULL, + GB_CREATING, NULL); + g_return_val_if_fail (label != NULL, NULL); + gb_widget_set_child_name (label, GladeChildCListTitle); + return label; +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_ctree_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Mode, _("Select Mode:"), + _("The selection mode of the columned tree"), + GbModeChoices); + property_add_bool (Titles, _("Show Titles:"), + _("If the column titles are shown")); + property_add_choice (Shadow, _("Shadow:"), + _("The type of shadow of the columned tree's border"), + GbShadowChoices); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_ctree_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gchar buffer[1024]; + gchar *pos; + gboolean buffer_overrun = FALSE; + gint i; + + if (data->action == GB_SAVING) + { + gb_widget_output_int (data, Cols, GTK_CLIST (widget)->columns); + + pos = buffer; + for (i = 0; i < GTK_CLIST (widget)->columns; i++) + { + if (i == 0) + sprintf (pos, "%i", GTK_CLIST (widget)->column[i].width); + else + sprintf (pos, ",%i", GTK_CLIST (widget)->column[i].width); + pos += strlen (pos); + + /* Extra check to make sure we don't overrun the buffer. */ + if (pos - buffer > 1000) + { + g_warning ("Buffer overflow"); + buffer_overrun = TRUE; + break; + } + } + if (!buffer_overrun) + gb_widget_output_string (data, ColumnWidths, buffer); + } + + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == GTK_CLIST (widget)->selection_mode) + gb_widget_output_choice (data, Mode, i, GbModeSymbols[i]); + } + + gb_widget_output_bool (data, Titles, GTK_CLIST_SHOW_TITLES (widget)); + + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) + { + if (GbShadowValues[i] == GTK_CLIST (widget)->shadow_type) + gb_widget_output_choice (data, Shadow, i, GbShadowSymbols[i]); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_ctree_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *widths, *pos, *mode; + gchar *shadow; + gboolean titles; + gint col, w, i; + + if (data->action == GB_LOADING) + { + widths = gb_widget_input_string (data, ColumnWidths); + if (data->apply) + { + pos = widths; + for (col = 0; col < GTK_CLIST (widget)->columns; col++) + { + w = atoi (pos); + gtk_clist_set_column_width (GTK_CLIST (widget), col, w); + pos = strchr (pos, ','); + if (!pos) + break; + pos++; + } + } + } + + mode = gb_widget_input_choice (data, Mode); + if (data->apply) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (!strcmp (mode, GbModeChoices[i]) + || !strcmp (mode, GbModeSymbols[i])) + { + gtk_clist_set_selection_mode (GTK_CLIST (widget), GbModeValues[i]); + break; + } + } + } + + titles = gb_widget_input_bool (data, Titles); + if (data->apply) + { + if (titles) + gtk_clist_column_titles_show (GTK_CLIST (widget)); + else + gtk_clist_column_titles_hide (GTK_CLIST (widget)); + } + + shadow = gb_widget_input_choice (data, Shadow); + if (data->apply) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (!strcmp (shadow, GbShadowChoices[i]) + || !strcmp (shadow, GbShadowSymbols[i])) + { + gtk_clist_set_shadow_type (GTK_CLIST (widget), + GbShadowValues[i]); + break; + } + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkCTree, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_ctree_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + +void +gb_ctree_add_child (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + /* We store the last column title read in 'last_child' */ + gint col = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + "last_child")); + + if (col >= GTK_CLIST (widget)->columns) { + g_warning ("Too many column title widgets for GtkCTree - skipping"); + return; + } + + gtk_clist_set_column_widget (GTK_CLIST (widget), col, child); + gtk_object_set_data (GTK_OBJECT (widget), "last_child", + GINT_TO_POINTER (col + 1)); + + /* We need to add signals to the clist button, just in case the + title widget has no window and so doesn't get signals itself. + Since Clist always creates 1 button initially, the signals would + be added to this button in gb_widget_new, so we could skip it, + but it doesn't hurt. */ + editor_add_mouse_signals_to_existing (GTK_CLIST (widget)->column[col].button); +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_ctree_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint col, i; + + if (data->create_widget) + { + /* FIXME: allow changing of 2nd arg - ctree column */ + source_add (data, " %s = gtk_ctree_new (%i, 0);\n", data->wname, + GTK_CLIST (widget)->columns); + } + + /* We reset the last_child index, so as the title widgets are written out + they will start at column 0. */ + gtk_object_set_data (GTK_OBJECT (widget), "last_child", GINT_TO_POINTER (-1)); + + gb_widget_write_standard_source (widget, data); + + for (col = 0; col < GTK_CLIST (widget)->columns; col++) + { + source_add (data, + " gtk_clist_set_column_width (GTK_CLIST (%s), %i, %i);\n", + data->wname, col, GTK_CLIST (widget)->column[col].width); + } + + if (GTK_CLIST (widget)->selection_mode != GTK_SELECTION_SINGLE) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == GTK_CLIST (widget)->selection_mode) + source_add (data, + " gtk_clist_set_selection_mode (GTK_CLIST (%s), %s);\n", + data->wname, GbModeSymbols[i]); + } + } + + if (GTK_CLIST_SHOW_TITLES (widget)) + source_add (data, " gtk_clist_column_titles_show (GTK_CLIST (%s));\n", + data->wname); + else + source_add (data, " gtk_clist_column_titles_hide (GTK_CLIST (%s));\n", + data->wname); + + if (GTK_CLIST (widget)->shadow_type != GTK_SHADOW_IN) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (GbShadowValues[i] == GTK_CLIST (widget)->shadow_type) + source_add (data, " gtk_clist_set_shadow_type (GTK_CLIST (%s), %s);\n", + data->wname, GbShadowSymbols[i]); + } + } +} + + +/* Outputs source to add a child widget to a CTree. */ +static void +gb_ctree_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + gchar *child_name; + + child_name = gb_widget_get_child_name (child); + + /* See if this is a title widget. */ + if (child_name && (!strcmp (child_name, GladeChildCListTitle))) + { + /* We store the last column title written in 'last_child' */ + gint col = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (parent), + "last_child")); + source_add (data, + " gtk_clist_set_column_widget (GTK_CLIST (%s), %i, %s);\n", + parent_name, col + 1, data->wname); + + gtk_object_set_data (GTK_OBJECT (parent), "last_child", + GINT_TO_POINTER (col + 1)); + } + else + { + g_warning ("Unknown CTree child widgetL %s", data->wname); + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_ctree_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_ctree_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = ctree_xpm; + gbwidget.tooltip = _("Columned Tree"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_ctree_new; + gbwidget.gb_widget_add_child = gb_ctree_add_child; + gbwidget.gb_widget_create_properties = gb_ctree_create_properties; + gbwidget.gb_widget_get_properties = gb_ctree_get_properties; + gbwidget.gb_widget_set_properties = gb_ctree_set_properties; + gbwidget.gb_widget_write_source = gb_ctree_write_source; + gbwidget.gb_widget_write_add_child_source = gb_ctree_write_add_child_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_ctree_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbcurve.c b/tools/glade/glade/gbwidgets/gbcurve.c new file mode 100644 index 00000000..7da60729 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcurve.c @@ -0,0 +1,263 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkcurve.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/curve.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +#if 0 +static gchar *Type = "GtkCurve::curve_type"; +#endif +static gchar *XMin = "GtkCurve::min_x"; +static gchar *XMax = "GtkCurve::max_x"; +static gchar *YMin = "GtkCurve::min_y"; +static gchar *YMax = "GtkCurve::max_y"; + +#if 0 +static const gchar *GbTypeChoices[] = +{"Linear", "Spline", "Free", NULL}; +static const gint GbTypeValues[] = +{ + GTK_CURVE_TYPE_LINEAR, /* linear interpolation */ + GTK_CURVE_TYPE_SPLINE, /* spline interpolation */ + GTK_CURVE_TYPE_FREE /* free form curve */ +}; +static const gchar *GbTypeSymbols[] = +{ + "GTK_CURVE_TYPE_LINEAR", + "GTK_CURVE_TYPE_SPLINE", + "GTK_CURVE_TYPE_FREE" +}; +#endif + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkCurve, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_curve_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_curve_new (); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_curve_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ +#if 0 + property_add_choice (Type, _("Type:"), _("The type of the curve"), GbTypeChoices); +#endif + property_add_float (XMin, _("X Min:"), _("The minimum horizontal value")); + property_add_float (XMax, _("X Max:"), _("The maximum horizontal value")); + property_add_float (YMin, _("Y Min:"), _("The minimum vertical value")); + property_add_float (YMax, _("Y Max:"), _("The maximum vertical value")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_curve_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ +#if 0 + gint i; + + for (i = 0; i < sizeof (GbTypeValues) / sizeof (GbTypeValues[0]); i++) + { + if (GbTypeValues[i] == GTK_CURVE (widget)->curve_type) + gb_widget_output_choice (data, Type, i, GbTypeSymbols[i]); + } +#endif + gb_widget_output_float (data, XMin, GTK_CURVE (widget)->min_x); + gb_widget_output_float (data, XMax, GTK_CURVE (widget)->max_x); + gb_widget_output_float (data, YMin, GTK_CURVE (widget)->min_y); + gb_widget_output_float (data, YMax, GTK_CURVE (widget)->max_y); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_curve_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gfloat min_x, max_x, min_y, max_y; + gboolean set_range = FALSE; + +#if 0 + gint i; + gchar *type; + + type = gb_widget_input_choice (data, Type); + if (data->apply) + { + for (i = 0; i < sizeof (GbTypeValues) / sizeof (GbTypeValues[0]); i++) + { + if (!strcmp (type, GbTypeChoices[i]) + || !strcmp (type, GbTypeSymbols[i])) + { + gtk_curve_set_curve_type (GTK_CURVE (widget), GbTypeValues[i]); + break; + } + } + } +#endif + + min_x = gb_widget_input_float (data, XMin); + if (data->apply) + set_range = TRUE; + else + min_x = GTK_CURVE (widget)->min_x; + + max_x = gb_widget_input_float (data, XMax); + if (data->apply) + set_range = TRUE; + else + max_x = GTK_CURVE (widget)->max_x; + + min_y = gb_widget_input_float (data, YMin); + if (data->apply) + set_range = TRUE; + else + min_y = GTK_CURVE (widget)->min_y; + + max_y = gb_widget_input_float (data, YMax); + if (data->apply) + set_range = TRUE; + else + max_y = GTK_CURVE (widget)->max_y; + + if (set_range) + gtk_curve_set_range (GTK_CURVE (widget), min_x, max_x, min_y, max_y); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkCurve, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_curve_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_curve_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkCurve *curve = GTK_CURVE (widget); +#if 0 + gint i; +#endif + + if (data->create_widget) + { + source_add (data, " %s = gtk_curve_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + +#if 0 + if (curve->curve_type != GTK_CURVE_TYPE_SPLINE) + { + for (i = 0; i < sizeof (GbTypeValues) / sizeof (GbTypeValues[0]); i++) + { + if (GbTypeValues[i] == curve->curve_type) + source_add (data, + " gtk_curve_set_curve_type (GTK_CURVE (%s), %s);\n", + data->wname, GbTypeSymbols[i]); + } + } +#endif + + source_add (data, " gtk_curve_set_range (GTK_CURVE (%s), %g, %g, %g, %g);\n", + data->wname, curve->min_x, curve->max_x, + curve->min_y, curve->max_y); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_curve_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_curve_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = curve_xpm; + gbwidget.tooltip = _("Curve"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_curve_new; + gbwidget.gb_widget_create_properties = gb_curve_create_properties; + gbwidget.gb_widget_get_properties = gb_curve_get_properties; + gbwidget.gb_widget_set_properties = gb_curve_set_properties; + gbwidget.gb_widget_write_source = gb_curve_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_curve_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbcustom.c b/tools/glade/glade/gbwidgets/gbcustom.c new file mode 100644 index 00000000..c9faff00 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbcustom.c @@ -0,0 +1,395 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtk.h> +#include "../gb.h" + +/* This custom GbWidget provides a simple way of allowing external widgets + to be used within an interface generated by Glade. + The 'Create Function' property specifies a function which will be called + to create the widget. 'String2', 'String2', 'Int1', 'Int2' are optional + arguments which will be passed to the creation function along with the + widget name. */ + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/custom.xpm" + +/* Include the background pixmap to use inside custom widgets. */ +#include "../graphics/custom_bg.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *CreationFunction = "Custom::creation_function"; +static gchar *LastModTime = "Custom::last_modification_time"; +static gchar *String1 = "Custom::string1"; +static gchar *String2 = "Custom::string2"; +static gchar *Int1 = "Custom::int1"; +static gchar *Int2 = "Custom::int2"; + +static time_t gb_custom_get_last_mod_time (GtkWidget *widget); +static void gb_custom_set_last_mod_time (GtkWidget *widget, + time_t last_mod_time); +static void gb_custom_on_widget_realize (GtkWidget *widget, gpointer data); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class Custom, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +static GtkWidget* +gb_custom_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_drawing_area_new (); + gtk_object_set_data (GTK_OBJECT (new_widget), GLADE_CUSTOM_KEY, "True"); + + gtk_signal_connect_after (GTK_OBJECT (new_widget), "realize", + GTK_SIGNAL_FUNC (gb_custom_on_widget_realize), + NULL); + + /* Set the initial last_mod_time. */ + gb_custom_set_last_mod_time (new_widget, -1); + + return new_widget; +} + + +/* We save the last modification time in the widget's datalist. */ +static time_t +gb_custom_get_last_mod_time (GtkWidget *widget) +{ + time_t *current; + + current = gtk_object_get_data (GTK_OBJECT (widget), LastModTime); + g_return_val_if_fail (current != NULL, 0); + return *current; +} + + +/* This sets the last modification time of the creation function name. + Use -1 to get the current time. */ +static void +gb_custom_set_last_mod_time (GtkWidget *widget, time_t last_mod_time) +{ + time_t *current; + + current = gtk_object_get_data (GTK_OBJECT (widget), LastModTime); + /* Create the time_t if it doesn't already exist. */ + if (current == NULL) + { + current = g_new (time_t, 1); + gtk_object_set_data (GTK_OBJECT (widget), LastModTime, current); + } + + if (last_mod_time == -1) + last_mod_time = time (NULL); + if (last_mod_time == (time_t) -1) + g_warning ("Can't get current time"); + + *current = last_mod_time; +} + + +static void +gb_custom_on_widget_realize (GtkWidget *widget, gpointer data) +{ + static GdkPixmap *background_pixmap = NULL; + +#if 0 + g_print ("In gb_custom_on_widget_realize widget:%s (%p)\n", + gtk_widget_get_name (widget), widget); +#endif + + /* Create the background pixmap if it hasn't already been created. */ + if (background_pixmap == NULL) + { + background_pixmap = gdk_pixmap_create_from_xpm_d (widget->window, + NULL, NULL, + custom_bg_xpm); + if (!background_pixmap) + { + g_warning ("Couldn't create background pixmap\n"); + /* FIXME: Use a color instead? */ + } + } + + if (background_pixmap != NULL) + gdk_window_set_back_pixmap (widget->window, background_pixmap, FALSE); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_custom_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_string (CreationFunction, _("Creation Function:"), + _("The function which creates the widget")); + + property_add_string (String1, _("String1:"), + _("The first string argument to pass to the function")); + property_add_string (String2, _("String2:"), + _("The second string argument to pass to the function")); + property_add_int (Int1, _("Int1:"), + _("The first integer argument to pass to the function")); + property_add_int (Int2, _("Int2:"), + _("The second integer argument to pass to the function")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_custom_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gchar *string1, *string2; + + gb_widget_output_string (data, CreationFunction, gtk_object_get_data (GTK_OBJECT (widget), CreationFunction)); + + string1 = gtk_object_get_data (GTK_OBJECT (widget), String1); + string2 = gtk_object_get_data (GTK_OBJECT (widget), String2); + + /* For empty strings output NULL (i.e. don't save in the XML). */ + if (string1 && *string1 == '\0') + string1 = NULL; + if (string2 && *string2 == '\0') + string2 = NULL; + + gb_widget_output_string (data, String1, string1); + gb_widget_output_string (data, String2, string2); + + gb_widget_output_int (data, Int1, GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Int1))); + gb_widget_output_int (data, Int2, GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Int2))); + + /* When saving we also save the last modification time. */ + if (data->action == GB_SAVING) + { + time_t last_mod_time; + + last_mod_time = gb_custom_get_last_mod_time (widget); + if (last_mod_time != 0) + { + save_date (data, LastModTime, last_mod_time); + } + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_custom_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *creation_function, *string1, *string2; + gint int1, int2; + + creation_function = gb_widget_input_string (data, CreationFunction); + if (data->apply) + { + g_free (gtk_object_get_data (GTK_OBJECT (widget), CreationFunction)); + gtk_object_set_data (GTK_OBJECT (widget), CreationFunction, + g_strdup (creation_function)); + + /* If we are applying the property, we set the last modification time. */ + if (data->action == GB_APPLYING) + { + gb_custom_set_last_mod_time (widget, -1); + } + } + + string1 = gb_widget_input_string (data, String1); + if (data->apply) + { + g_free (gtk_object_get_data (GTK_OBJECT (widget), String1)); + gtk_object_set_data (GTK_OBJECT (widget), String1, g_strdup (string1)); + } + + string2 = gb_widget_input_string (data, String2); + if (data->apply) + { + g_free (gtk_object_get_data (GTK_OBJECT (widget), String2)); + gtk_object_set_data (GTK_OBJECT (widget), String2, g_strdup (string2)); + } + + int1 = gb_widget_input_int (data, Int1); + if (data->apply) + gtk_object_set_data (GTK_OBJECT (widget), Int1, GINT_TO_POINTER (int1)); + + int2 = gb_widget_input_int (data, Int2); + if (data->apply) + gtk_object_set_data (GTK_OBJECT (widget), Int2, GINT_TO_POINTER (int2)); + + /* If we are loading, load the last modification time. */ + if (data->action == GB_LOADING) + { + time_t last_mod_time; + + last_mod_time = load_date (data, LastModTime); + if (data->apply) + { + gb_custom_set_last_mod_time (widget, last_mod_time); + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a Custom, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_custom_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_custom_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *creation_func, *string1, *string2; + gint int1, int2; + time_t last_mod_time; + + creation_func = gtk_object_get_data (GTK_OBJECT (widget), CreationFunction); + string1 = gtk_object_get_data (GTK_OBJECT (widget), String1); + string2 = gtk_object_get_data (GTK_OBJECT (widget), String2); + int1 = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Int1)); + int2 = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Int2)); + + /* If no creation function has been set, we skip the widget. */ + if (creation_func == NULL) + return; + + creation_func = source_create_valid_identifier (creation_func); + + /* Output "" if the strings are NULL, for consistency. */ + if (string1 == NULL) + string1 = ""; + if (string2 == NULL) + string2 = ""; + + if (string1) + string1 = g_strdup (source_make_string (string1, FALSE)); + if (string2) + string2 = g_strdup (source_make_string (string2, FALSE)); + /* Example output: + custom1 = create_custom1 ("custom1", "string1", "string2", 5, 10); + */ + source_add (data, " %s = %s (%s, %s, %s, %i, %i);\n", + data->wname, creation_func, + source_make_string (data->real_wname, FALSE), + string1 ? string1 : "NULL", string2 ? string2 : "NULL", + int1, int2); + gb_widget_write_standard_source (widget, data); + + /* Add declaration of creation function and empty function, just + like a signal handler. We need a last_modification_time property. */ + last_mod_time = gb_custom_get_last_mod_time (widget); + if (data->creating_callback_files + || (last_mod_time > data->last_write_time)) + { + source_add_to_buffer (data, GLADE_CALLBACK_DECLARATIONS, + "\nGtkWidget*\n" + "%s (gchar *widget_name, gchar *string1, gchar *string2,\n" + " gint int1, gint int2);\n", + creation_func); + + source_add_to_buffer (data, GLADE_CALLBACK_SOURCE, + "\nGtkWidget*\n" + "%s (gchar *widget_name, gchar *string1, gchar *string2,\n" + " gint int1, gint int2)\n" + "{\n\n}\n\n", + creation_func); + } + + g_free (creation_func); + g_free (string1); + g_free (string2); +} + + +static void +gb_custom_destroy (GtkWidget * widget, GbWidgetDestroyData * data) +{ + /* We need to free the LastModTime. */ + g_free (gtk_object_get_data (GTK_OBJECT (widget), LastModTime)); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_custom_init () +{ + /* Initialise the GTK type. We don't need this. */ + /* gtk_custom_get_type(); */ + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = custom_xpm; + gbwidget.tooltip = _("Custom Widget"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_custom_new; + gbwidget.gb_widget_create_properties = gb_custom_create_properties; + gbwidget.gb_widget_get_properties = gb_custom_get_properties; + gbwidget.gb_widget_set_properties = gb_custom_set_properties; + gbwidget.gb_widget_write_source = gb_custom_write_source; + gbwidget.gb_widget_destroy = gb_custom_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_custom_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbdialog.c b/tools/glade/glade/gbwidgets/gbdialog.c new file mode 100644 index 00000000..3d372804 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbdialog.c @@ -0,0 +1,621 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> +#include <gtk/gtkbbox.h> +#include <gtk/gtkdialog.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkradiobutton.h> +#include <gtk/gtkspinbutton.h> +#include <gtk/gtkstock.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/dialog.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "Dialog|GtkWindow::title"; +static gchar *Type = "Dialog|GtkWindow::type"; +static gchar *Position = "Dialog|GtkWindow::window_position"; +static gchar *Modal = "Dialog|GtkWindow::modal"; +static gchar *DefaultWidth = "Dialog|GtkWindow::default_width"; +static gchar *DefaultHeight = "Dialog|GtkWindow::default_height"; +static gchar *Shrink = "Dialog|GtkWindow::allow_shrink"; +static gchar *Grow = "Dialog|GtkWindow::allow_grow"; +static gchar *AutoShrink = "Dialog|GtkWindow::auto_shrink"; +static gchar *IconName = "Dialog|GtkWindow::icon_name"; +static gchar *FocusOnMap = "Dialog|GtkWindow::focus_on_map"; + +static gchar *Resizable = "Dialog|GtkWindow::resizable"; +static gchar *DestroyWithParent = "Dialog|GtkWindow::destroy_with_parent"; +static gchar *Icon = "Dialog|GtkWindow::icon"; + +static gchar *Role = "Dialog|GtkWindow::role"; +static gchar *TypeHint = "Dialog|GtkWindow::type_hint"; +static gchar *SkipTaskbar = "Dialog|GtkWindow::skip_taskbar_hint"; +static gchar *SkipPager = "Dialog|GtkWindow::skip_pager_hint"; +static gchar *Decorated = "Dialog|GtkWindow::decorated"; +static gchar *Gravity = "Dialog|GtkWindow::gravity"; + +static gchar *HasSeparator = "GtkDialog::has_separator"; + +static gchar *Urgency = "Dialog|GtkWindow::urgency_hint"; + +static void show_dialog_creation_dialog (GbWidgetNewData * data); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + + +/* Action is GB_LOADING or GB_CREATING. */ +static GtkWidget* +create_dialog (const gchar *title, GbWidgetAction action) +{ + GtkWidget *new_widget; + + new_widget = gtk_dialog_new (); + gtk_window_set_title (GTK_WINDOW (new_widget), title); + gtk_window_set_policy (GTK_WINDOW (new_widget), TRUE, TRUE, FALSE); + + /* We want it to be treated as a normal window. */ + gtk_window_set_type_hint (GTK_WINDOW (new_widget), + GDK_WINDOW_TYPE_HINT_NORMAL); + + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + /* We need to size the placeholders or the dialog is very small. */ + if (action == GB_CREATING) + { + GtkWidget *placeholder = editor_new_placeholder (); + gtk_widget_set_usize (placeholder, 300, 200); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (new_widget)->vbox), placeholder, + TRUE, TRUE, 0); + } + + gb_widget_create_from (GTK_DIALOG (new_widget)->vbox, + action == GB_CREATING ? "dialog-vbox" : NULL); + gb_widget_set_child_name (GTK_DIALOG (new_widget)->vbox, GladeChildDialogVBox); + + gb_widget_create_from (GTK_DIALOG (new_widget)->action_area, + action == GB_CREATING ? "dialog-action_area" : NULL); + gb_widget_set_child_name (GTK_DIALOG (new_widget)->action_area, + GladeChildDialogActionArea); + + gtk_object_set_data (GTK_OBJECT (new_widget), TypeHint, + GINT_TO_POINTER (GLADE_TYPE_HINT_DIALOG_INDEX)); + + return new_widget; +} + + +/* + * Creates a new GtkWidget of class GtkDialog, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_dialog_new (GbWidgetNewData * data) +{ + if (data->action == GB_LOADING) + { + return create_dialog (data->name, GB_LOADING); + } + else + { + show_dialog_creation_dialog (data); + return NULL; + } +} + + +static void +add_button (GtkDialog *dialog, + const gchar *stock_id, + gint response_id, + const gchar *name) +{ + GtkWidget *button; + + button = gtk_dialog_add_button (dialog, stock_id, -1); + gb_widget_create_from (button, name); + gtk_object_set_data (GTK_OBJECT (button), GladeButtonStockIDKey, + (gpointer) stock_id); + gtk_object_set_data (GTK_OBJECT (button), GladeDialogResponseIDKey, + GINT_TO_POINTER (response_id)); + if (response_id == GTK_RESPONSE_HELP) + gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (button->parent), + button, TRUE); +} + + +static void +on_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *window, *button; + GtkWidget *cancel_ok, *just_ok, *cancel_apply_ok, *just_close; + GtkWidget *standard_layout, *num_buttons, *show_help_button; + GtkDialog *dialog; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (!gb_widget_can_finish_new (data)) + { + gtk_widget_destroy (window); + return; + } + + new_widget = create_dialog (data->name, GB_CREATING); + dialog = GTK_DIALOG (new_widget); + + /* Get pointers to all the widgets in the creation dialog we need. */ + standard_layout = gtk_object_get_data (GTK_OBJECT (window), "standard_layout"); + cancel_ok = gtk_object_get_data (GTK_OBJECT (window), "cancel_ok"); + just_ok = gtk_object_get_data (GTK_OBJECT (window), "just_ok"); + cancel_apply_ok = gtk_object_get_data (GTK_OBJECT (window), "cancel_apply_ok"); + just_close = gtk_object_get_data (GTK_OBJECT (window), "just_close"); + num_buttons = gtk_object_get_data (GTK_OBJECT (window), "num_buttons"); + show_help_button = gtk_object_get_data (GTK_OBJECT (window), "show_help_button"); + + if (GTK_TOGGLE_BUTTON (show_help_button)->active) + { + add_button (dialog, GTK_STOCK_HELP, GTK_RESPONSE_HELP, "helpbutton"); + } + + if (GTK_TOGGLE_BUTTON (standard_layout)->active) + { + if (GTK_TOGGLE_BUTTON (cancel_ok)->active) + { + add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + "cancelbutton"); + add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK, + "okbutton"); + } + else if (GTK_TOGGLE_BUTTON (just_ok)->active) + { + add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK, + "okbutton"); + } + else if (GTK_TOGGLE_BUTTON (cancel_apply_ok)->active) + { + add_button (dialog, GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, + "applybutton"); + add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + "cancelbutton"); + add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK, + "okbutton"); + } + else if (GTK_TOGGLE_BUTTON (just_close)->active) + { + add_button (dialog, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, + "closebutton"); + } + } + else + { + gint buttons, i; + + buttons = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (num_buttons)); + /* We set the response_ids to 1,2,3 etc. */ + for (i = 1; i <= buttons; i++) + { + button = gb_widget_new ("GtkButton", NULL); + GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); + gtk_dialog_add_action_widget (GTK_DIALOG (new_widget), button, i); + } + } + + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + + gtk_widget_destroy (window); +} + + +static void +on_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +static void on_standard_layout_toggled (GtkWidget *radiobutton, + GtkWidget *dialog) +{ + GtkWidget *cancel_ok, *just_ok, *cancel_apply_ok, *just_close; + GtkWidget *num_buttons; + gboolean sens; + + cancel_ok = gtk_object_get_data (GTK_OBJECT (dialog), "cancel_ok"); + just_ok = gtk_object_get_data (GTK_OBJECT (dialog), "just_ok"); + cancel_apply_ok = gtk_object_get_data (GTK_OBJECT (dialog), "cancel_apply_ok"); + just_close = gtk_object_get_data (GTK_OBJECT (dialog), "just_close"); + + num_buttons = gtk_object_get_data (GTK_OBJECT (dialog), "num_buttons"); + + sens = (GTK_TOGGLE_BUTTON (radiobutton)->active) ? TRUE : FALSE; + + gtk_widget_set_sensitive (cancel_ok, sens); + gtk_widget_set_sensitive (just_ok, sens); + gtk_widget_set_sensitive (cancel_apply_ok, sens); + gtk_widget_set_sensitive (just_close, sens); + + gtk_widget_set_sensitive (num_buttons, !sens); +} + + +static void +show_dialog_creation_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox1; + GtkWidget *table1; + GtkWidget *cancel_ok; + GSList *layout_group_group = NULL; + GtkWidget *just_ok; + GtkWidget *cancel_apply_ok; + GtkWidget *just_close; + GtkWidget *standard_layout; + GSList *main_group_group = NULL; + GtkWidget *show_help_button; + GtkWidget *number_of_buttons; + GtkObject *num_buttons_adj; + GtkWidget *num_buttons; + + dialog = glade_util_create_dialog (_("New dialog"), data->parent, + GTK_SIGNAL_FUNC (on_dialog_ok), + data, &vbox1); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_dialog_destroy), data); + + table1 = gtk_table_new (7, 2, FALSE); + gtk_widget_show (table1); + gtk_box_pack_start (GTK_BOX (vbox1), table1, TRUE, TRUE, 0); + gtk_container_set_border_width (GTK_CONTAINER (table1), 8); + gtk_table_set_col_spacings (GTK_TABLE (table1), 8); + + cancel_ok = gtk_radio_button_new_with_mnemonic (NULL, _("Cancel, OK")); + gtk_object_set_data (GTK_OBJECT (dialog), "cancel_ok", cancel_ok); + gtk_widget_show (cancel_ok); + gtk_table_attach (GTK_TABLE (table1), cancel_ok, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (cancel_ok), layout_group_group); + layout_group_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (cancel_ok)); + + just_ok = gtk_radio_button_new_with_mnemonic (NULL, _("OK")); + gtk_object_set_data (GTK_OBJECT (dialog), "just_ok", just_ok); + gtk_widget_show (just_ok); + gtk_table_attach (GTK_TABLE (table1), just_ok, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (just_ok), layout_group_group); + layout_group_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (just_ok)); + + cancel_apply_ok = gtk_radio_button_new_with_mnemonic (NULL, _("Cancel, Apply, OK")); + gtk_object_set_data (GTK_OBJECT (dialog), "cancel_apply_ok", cancel_apply_ok); + gtk_widget_show (cancel_apply_ok); + gtk_table_attach (GTK_TABLE (table1), cancel_apply_ok, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (cancel_apply_ok), layout_group_group); + layout_group_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (cancel_apply_ok)); + + just_close = gtk_radio_button_new_with_mnemonic (NULL, _("Close")); + gtk_object_set_data (GTK_OBJECT (dialog), "just_close", just_close); + gtk_widget_show (just_close); + gtk_table_attach (GTK_TABLE (table1), just_close, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (just_close), layout_group_group); + layout_group_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (just_close)); + + standard_layout = gtk_radio_button_new_with_mnemonic (NULL, _("_Standard Button Layout:")); + gtk_object_set_data (GTK_OBJECT (dialog), "standard_layout", standard_layout); + gtk_widget_show (standard_layout); + gtk_table_attach (GTK_TABLE (table1), standard_layout, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (standard_layout), main_group_group); + main_group_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (standard_layout)); + + number_of_buttons = gtk_radio_button_new_with_mnemonic (NULL, _("_Number of Buttons:")); + gtk_widget_show (number_of_buttons); + gtk_table_attach (GTK_TABLE (table1), number_of_buttons, 0, 1, 5, 6, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (number_of_buttons), main_group_group); + main_group_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (number_of_buttons)); + + num_buttons_adj = gtk_adjustment_new (1, 0, 100, 1, 10, 10); + num_buttons = gtk_spin_button_new (GTK_ADJUSTMENT (num_buttons_adj), 1, 0); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (num_buttons), TRUE); + gtk_object_set_data (GTK_OBJECT (dialog), "num_buttons", num_buttons); + gtk_widget_show (num_buttons); + gtk_table_attach (GTK_TABLE (table1), num_buttons, 1, 2, 5, 6, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 4); + + show_help_button = gtk_check_button_new_with_mnemonic (_("Show Help Button")); + gtk_object_set_data (GTK_OBJECT (dialog), "show_help_button", show_help_button); + gtk_widget_show (show_help_button); + gtk_table_attach (GTK_TABLE (table1), show_help_button, 0, 2, 6, 7, + (GtkAttachOptions) (0), + (GtkAttachOptions) (0), 0, 6); + + gtk_widget_set_sensitive (num_buttons, FALSE); + + gtk_signal_connect (GTK_OBJECT (standard_layout), "toggled", + GTK_SIGNAL_FUNC (on_standard_layout_toggled), dialog); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_dialog_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + gb_window_create_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + property_add_bool (HasSeparator, _("Has Separator:"), + _("If the dialog has a horizontal separator above the buttons")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_dialog_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_window_get_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + gb_widget_output_bool (data, HasSeparator, + gtk_dialog_get_has_separator (GTK_DIALOG (widget))); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_dialog_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean has_separator; + + gb_window_set_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + has_separator = gb_widget_input_bool (data, HasSeparator); + if (data->apply) + { + gtk_dialog_set_has_separator (GTK_DIALOG (widget), has_separator); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkDialog, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_dialog_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_dialog_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *wname, *child_name; + + if (data->create_widget) + { + source_add (data, " %s = gtk_dialog_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + gb_window_write_standard_source (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + + if (!gtk_dialog_get_has_separator (GTK_DIALOG (widget))) + { + source_add (data, " gtk_dialog_set_has_separator (GTK_DIALOG (%s), FALSE);\n", + data->wname); + } + + + /* We output the source code for the children here, since the code should + not include calls to create the widgets. We need to specify that the + names used are like: "GTK_DIALOG (<dialog-name>)->vbox". + We need to remember the dialog's name since data->wname + will be overwritten. */ + wname = g_strdup (data->wname); + + source_add (data, "\n"); + child_name = (gchar*) gtk_widget_get_name (GTK_DIALOG (widget)->vbox); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = gtk_dialog_get_content_area (GTK_DIALOG (%s));\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_DIALOG (widget)->vbox, data); + + /* action_area is a child of vbox so I had to add a kludge to stop it + being written as a normal child - we need to do it here so that we + don't output code to create it. */ + child_name = (gchar*) gtk_widget_get_name (GTK_DIALOG (widget)->action_area); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = gtk_dialog_get_action_area (GTK_DIALOG (%s));\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_DIALOG (widget)->action_area, data); + + g_free (wname); + data->write_children = FALSE; +} + + + +static GtkWidget * +gb_dialog_get_child (GtkWidget * widget, + const gchar * child_name) +{ + if (!strcmp (child_name, GladeChildDialogVBox)) + return GTK_DIALOG (widget)->vbox; + else if (!strcmp (child_name, GladeChildDialogActionArea)) + return GTK_DIALOG (widget)->action_area; + else + return NULL; +} + + +/* Converts a response id to a string, either a standard GTK+ response string + such as "GTK_RESPONSE_OK" or an integer e.g. "1". Note that for integers + it uses a static buffer. */ +char* +gb_dialog_response_id_to_string (gint response_id) +{ + gint i; + + if (response_id >= 0) + { + static char buffer[16]; + + sprintf (buffer, "%i", response_id); + return buffer; + } + + for (i = 0; i < GladeStockResponsesSize; i++) + { + if (GladeStockResponses[i].response_id == response_id) + return GladeStockResponses[i].name; + } + + return "0"; +} + + +gint +gb_dialog_response_id_from_string (const gchar *response_id) +{ + gint i; + + if (!response_id || !*response_id) + return 0; + + for (i = 0; i < GladeStockResponsesSize; i++) + { + if (!strcmp (GladeStockResponses[i].name, response_id)) + return GladeStockResponses[i].response_id; + } + + return atoi (response_id); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_dialog_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_dialog_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = dialog_xpm; + gbwidget.tooltip = _("Dialog"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_dialog_new; + gbwidget.gb_widget_create_properties = gb_dialog_create_properties; + gbwidget.gb_widget_get_properties = gb_dialog_get_properties; + gbwidget.gb_widget_set_properties = gb_dialog_set_properties; + gbwidget.gb_widget_get_child = gb_dialog_get_child; + gbwidget.gb_widget_write_source = gb_dialog_write_source; + gbwidget.gb_widget_destroy = gb_window_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_dialog_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbdrawingarea.c b/tools/glade/glade/gbwidgets/gbdrawingarea.c new file mode 100644 index 00000000..3b93d69d --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbdrawingarea.c @@ -0,0 +1,159 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkdrawingarea.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/drawingarea.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkDrawingArea, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +/* + GtkWidget* + gb_drawing_area_new(GbWidgetNewData *data) + { + + } + */ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +/* + static void + gb_drawing_area_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) + { + + } + */ + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +/* + static void + gb_drawing_area_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) + { + + } + */ + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +/* + static void + gb_drawing_area_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) + { + + } + */ + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkDrawingArea, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_drawing_area_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_drawing_area_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_drawing_area_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_drawing_area_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_drawing_area_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = drawingarea_xpm; + gbwidget.tooltip = _("Drawing Area"); + + /* Fill in any functions that this GbWidget has */ +/* + gbwidget.gb_widget_new = gb_drawing_area_new; + gbwidget.gb_widget_create_properties = gb_drawing_area_create_properties; + gbwidget.gb_widget_get_properties = gb_drawing_area_get_properties; + gbwidget.gb_widget_set_properties = gb_drawing_area_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_drawing_area_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_drawing_area_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbentry.c b/tools/glade/glade/gbwidgets/gbentry.c new file mode 100644 index 00000000..528face1 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbentry.c @@ -0,0 +1,331 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> +#include <gtk/gtkentry.h> +#include <gtk/gtktogglebutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/entry.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Editable = "Entry|GtkEditable::editable"; +static gchar *Visible = "GtkEntry::visibility"; +static gchar *MaxLength = "GtkEntry::max_length"; +static gchar *Text = "GtkEntry::text"; + +static gchar *HasFrame = "GtkEntry::has_frame"; +static gchar *InvisibleChar = "GtkEntry::invisible_char"; +static gchar *ActivatesDefault = "GtkEntry::activates_default"; +static gchar *WidthChars = "GtkEntry::width_chars"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkEntry, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +/* + GtkWidget* + gb_entry_new(GbWidgetNewData *data) + { + + } + */ + + + +static void +on_toggle_width_chars (GtkWidget * widget, gpointer value) +{ + GtkWidget *property_widget; + gboolean value_set; + gint width = -1; + + property_widget = property_get_widget (); + if (property_widget == NULL) + return; + + value_set = GTK_TOGGLE_BUTTON (widget)->active ? TRUE : FALSE; + gtk_widget_set_sensitive (GTK_WIDGET (value), value_set); + if (value_set) + { + width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (property_widget), WidthChars)); + } + + gtk_entry_set_width_chars (GTK_ENTRY (property_widget), width); +} + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_entry_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (Editable, _("Editable:"), _("If the text can be edited")); + property_add_bool (Visible, _("Text Visible:"), + _("If the text entered by the user will be shown. When turned off, the text typed in is displayed as asterix characters, which is useful for entering passwords")); + property_add_int_range (MaxLength, _("Max Length:"), + _("The maximum length of the text"), + 0, 10000, 1, 10, 1); + property_add_string (Text, _("Text:"), _("The text to display")); + + property_add_bool (HasFrame, _("Has Frame:"), _("If the entry has a frame around it")); + property_add_string (InvisibleChar, _("Invisible Char:"), _("The character to use if the text should not visible, e.g. when entering passwords")); + property_add_bool (ActivatesDefault, _("Activates Default:"), _("If the default widget in the window is activated when Enter is pressed")); + property_add_optional_int_range (WidthChars, _("Width In Chars:"), _("The number of characters to leave space for in the entry"), + 0, 10000, 1, 10, 1, + on_toggle_width_chars); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_entry_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gchar buf[8]; + gint len, width; + const gchar *entry_text = gtk_entry_get_text (GTK_ENTRY (widget)); + gb_widget_output_bool (data, Editable, GTK_ENTRY (widget)->editable); + gb_widget_output_bool (data, Visible, GTK_ENTRY (widget)->visible); + gb_widget_output_int (data, MaxLength, GTK_ENTRY (widget)->text_max_length); + gb_widget_output_translatable_string (data, Text, entry_text); + + gb_widget_output_bool (data, HasFrame, + gtk_entry_get_has_frame (GTK_ENTRY (widget))); + len = g_unichar_to_utf8 (gtk_entry_get_invisible_char (GTK_ENTRY (widget)), + buf); + buf[len] = '\0'; + gb_widget_output_string (data, InvisibleChar, buf); + gb_widget_output_bool (data, ActivatesDefault, + gtk_entry_get_activates_default (GTK_ENTRY (widget))); + + width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + WidthChars)); + gb_widget_output_optional_int (data, WidthChars, width, + gtk_entry_get_width_chars (GTK_ENTRY (widget)) != -1); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_entry_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean editable, visible, has_frame, activates_default, is_set; + gint max_length, width_chars; + gchar *text, *invisible_char; + + editable = gb_widget_input_bool (data, Editable); + if (data->apply) + gtk_editable_set_editable (GTK_EDITABLE (widget), editable); + + visible = gb_widget_input_bool (data, Visible); + if (data->apply) + gtk_entry_set_visibility (GTK_ENTRY (widget), visible); + + max_length = gb_widget_input_int (data, MaxLength); + if (data->apply) + gtk_entry_set_max_length (GTK_ENTRY (widget), max_length); + + text = gb_widget_input_string (data, Text); + if (data->apply) + gtk_entry_set_text (GTK_ENTRY (widget), text); + + has_frame = gb_widget_input_bool (data, HasFrame); + if (data->apply) + gtk_entry_set_has_frame (GTK_ENTRY (widget), has_frame); + + invisible_char = gb_widget_input_string (data, InvisibleChar); + if (data->apply) + { + gunichar c = g_utf8_get_char_validated (invisible_char, -1); + if (c > 0) + gtk_entry_set_invisible_char (GTK_ENTRY (widget), c); + } + + activates_default = gb_widget_input_bool (data, ActivatesDefault); + if (data->apply) + gtk_entry_set_activates_default (GTK_ENTRY (widget), activates_default); + + width_chars = gb_widget_input_optional_int (data, WidthChars, &is_set); + if (data->apply) + { + if (is_set) + { + gtk_object_set_data (GTK_OBJECT (widget), WidthChars, + GINT_TO_POINTER (width_chars)); + gtk_entry_set_width_chars (GTK_ENTRY (widget), width_chars); + } + else + { + gtk_entry_set_width_chars (GTK_ENTRY (widget), -1); + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkEntry, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_entry_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_entry_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + guint16 max_len = GTK_ENTRY (widget)->text_max_length; + const gchar *entry_text = gtk_entry_get_text (GTK_ENTRY (widget)); + gunichar c; + gint width_chars; + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + source_add (data, " %s = gtk_entry_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + if (max_len) + { + source_add (data, " gtk_entry_set_max_length (GTK_ENTRY (%s), %d);\n", + data->wname, max_len); + } + if (!GTK_ENTRY (widget)->editable) + { + source_add (data, " gtk_editable_set_editable (GTK_EDITABLE (%s), FALSE);\n", + data->wname); + } + if (!GTK_ENTRY (widget)->visible) + { + source_add (data, " gtk_entry_set_visibility (GTK_ENTRY (%s), FALSE);\n", + data->wname); + } + if (entry_text && strlen (entry_text) > 0) + { + glade_util_get_translation_properties (widget, Text, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, " gtk_entry_set_text (GTK_ENTRY (%s), %s);\n", + data->wname, + source_make_string_full (entry_text, data->use_gettext && translatable, context)); + } + + if (!gtk_entry_get_has_frame (GTK_ENTRY (widget))) + { + source_add (data, " gtk_entry_set_has_frame (GTK_ENTRY (%s), FALSE);\n", + data->wname); + } + + c = gtk_entry_get_invisible_char (GTK_ENTRY (widget)); + if (c != '*') + { + /* We just output the integer Unicode character code. I think that is + OK. */ + source_add (data, + " gtk_entry_set_invisible_char (GTK_ENTRY (%s), %i);\n", + data->wname, c); + } + + if (gtk_entry_get_activates_default (GTK_ENTRY (widget))) + { + source_add (data, + " gtk_entry_set_activates_default (GTK_ENTRY (%s), TRUE);\n", + data->wname); + } + + width_chars = gtk_entry_get_width_chars (GTK_ENTRY (widget)); + if (width_chars != -1) + { + source_add (data, + " gtk_entry_set_width_chars (GTK_ENTRY (%s), %i);\n", + data->wname, width_chars); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_entry_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_entry_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = entry_xpm; + gbwidget.tooltip = _("Text Entry"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_entry_create_properties; + gbwidget.gb_widget_get_properties = gb_entry_get_properties; + gbwidget.gb_widget_set_properties = gb_entry_set_properties; +/* + gbwidget.gb_widget_new = gb_entry_new; + gbwidget.gb_widget_create_popup_menu = gb_entry_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_entry_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbeventbox.c b/tools/glade/glade/gbwidgets/gbeventbox.c new file mode 100644 index 00000000..b23d1f35 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbeventbox.c @@ -0,0 +1,180 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkeventbox.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/eventbox.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *VisibleWindow = "GtkEventBox::visible_window"; +static gchar *AboveChild = "GtkEventBox::above_child"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkEventBox, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_event_box_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_event_box_new (); + if (data->action != GB_LOADING) + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_event_box_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) +{ + property_add_bool (VisibleWindow, _("Visible Window:"), _("If the event box uses a visible window")); + property_add_bool (AboveChild, _("Above Child:"), _("If the event box window is above the child widget's window")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_event_box_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) +{ + gb_widget_output_bool (data, VisibleWindow, + gtk_event_box_get_visible_window (GTK_EVENT_BOX (widget))); + gb_widget_output_bool (data, AboveChild, + gtk_event_box_get_above_child (GTK_EVENT_BOX (widget))); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_event_box_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) +{ + gboolean visible_window, above_child; + + visible_window = gb_widget_input_bool (data, VisibleWindow); + if (data->apply) + gtk_event_box_set_visible_window (GTK_EVENT_BOX (widget), visible_window); + + above_child = gb_widget_input_bool (data, AboveChild); + if (data->apply) + gtk_event_box_set_above_child (GTK_EVENT_BOX (widget), above_child); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkEventBox, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_event_box_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_event_box_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_event_box_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + if (!gtk_event_box_get_visible_window (GTK_EVENT_BOX (widget))) + { + source_add (data, " gtk_event_box_set_visible_window (GTK_EVENT_BOX (%s), FALSE);\n", + data->wname); + } + + if (gtk_event_box_get_above_child (GTK_EVENT_BOX (widget))) + { + source_add (data, " gtk_event_box_set_above_child (GTK_EVENT_BOX (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_event_box_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_event_box_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = eventbox_xpm; + gbwidget.tooltip = _("Event Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_event_box_new; + gbwidget.gb_widget_create_properties = gb_event_box_create_properties; + gbwidget.gb_widget_get_properties = gb_event_box_get_properties; + gbwidget.gb_widget_set_properties = gb_event_box_set_properties; +/* + gbwidget.gb_widget_create_popup_menu = gb_event_box_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_event_box_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbexpander.c b/tools/glade/glade/gbwidgets/gbexpander.c new file mode 100644 index 00000000..ad9e90d5 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbexpander.c @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2003 Sun Microsystems, Inc. + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: + * Mark McLoughlin <mark@skynet.ie> + */ + +#include "../gb.h" +#include <gtk/gtkexpander.h> + +#include "../graphics/expander.xpm" + +#define PROPERTY_EXPANDED "GtkExpander::expanded" +#define PROPERTY_SPACING "GtkExpander::spacing" + +static GbWidget gb_expander; + +GtkWidget * +gb_expander_new (GbWidgetNewData *data) +{ + GtkWidget *expander = gtk_expander_new (NULL); + + if (data->action != GB_LOADING) + { + GtkWidget *label; + + gtk_container_add (GTK_CONTAINER (expander), editor_new_placeholder ()); + label = gb_widget_new ("GtkLabel", NULL); + gtk_expander_set_label_widget (GTK_EXPANDER (expander), label); + } + + return expander; +} + +static void +gb_expander_create_properties (GtkWidget *widget, + GbWidgetCreateArgData *data) +{ + property_add_bool (PROPERTY_EXPANDED, + _("Initially Expanded:"), + _("Whether the expander is initially opened to reveal the child widget")); + property_add_int_range (PROPERTY_SPACING, + _("Spacing:"), + _("Space to put between the label and the child"), + 0, 1000, 1, 10, 1); +} + +static void +gb_expander_get_properties (GtkWidget *widget, + GbWidgetGetArgData *data) +{ + gb_widget_output_bool (data, + PROPERTY_EXPANDED, + gtk_expander_get_expanded (GTK_EXPANDER (widget))); + gb_widget_output_int (data, + PROPERTY_SPACING, + gtk_expander_get_spacing (GTK_EXPANDER (widget))); +} + +static void +gb_expander_set_properties (GtkWidget *widget, + GbWidgetSetArgData *data) +{ + gboolean expanded; + int spacing; + + expanded = gb_widget_input_bool (data, PROPERTY_EXPANDED); + if (data->apply) + gtk_expander_set_expanded (GTK_EXPANDER (widget), expanded); + + spacing = gb_widget_input_int (data, PROPERTY_SPACING); + if (data->apply) + gtk_expander_set_spacing (GTK_EXPANDER (widget), spacing); +} + +static void +gb_expander_add_label_widget (GtkWidget *menuitem, + GtkExpander *expander) +{ + gtk_expander_set_label_widget (expander, editor_new_placeholder ()); +} + +void +gb_expander_create_popup_menu (GtkWidget *widget, + GbWidgetCreateMenuData *data) +{ + GtkWidget *menuitem; + + if (!gtk_expander_get_label_widget (GTK_EXPANDER (widget))) + { + menuitem = gtk_menu_item_new_with_label (_("Add Label Widget")); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + g_signal_connect (menuitem, "activate", + G_CALLBACK (gb_expander_add_label_widget), widget); + gtk_widget_show (menuitem); + } +} + +void +gb_expander_add_child (GtkWidget *widget, + GtkWidget *child, + GbWidgetSetArgData *data) +{ + gboolean is_label_item = FALSE; + + if (data->child_info) + { + int j; + + for (j = 0; j < data->child_info->n_properties; j++) + { + if (!strcmp (data->child_info->properties[j].name, "type") && + !strcmp (data->child_info->properties[j].value, "label_item")) + { + is_label_item = TRUE; + break; + } + } + } + + if (is_label_item) + gtk_expander_set_label_widget (GTK_EXPANDER (widget), child); + else + gtk_container_add (GTK_CONTAINER (widget), child); +} + +#if 0 +/* This is in gb_widget_replace_child() now. */ +static void +gb_expander_replace_child (GtkWidget *widget, + GtkWidget *current_child, + GtkWidget *new_child) +{ + /* If this is the expander's label widget, we replace that. */ + if (gtk_expander_get_label_widget (GTK_EXPANDER (widget)) == current_child) + { + gtk_expander_set_label_widget (GTK_EXPANDER (widget), new_child); + } + else + { + gtk_container_remove (GTK_CONTAINER (widget), current_child); + gtk_container_add (GTK_CONTAINER (widget), new_child); + } +} +#endif + +static void +gb_expander_write_source (GtkWidget *widget, + GbWidgetWriteSourceData *data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_expander_new (NULL);\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (gtk_expander_get_expanded (GTK_EXPANDER (widget))) + { + source_add (data, + " gtk_expander_set_expanded (GTK_EXPANDER (%s), %s);\n", + data->wname, + gtk_expander_get_expanded (GTK_EXPANDER (widget)) ? "TRUE" : "FALSE"); + } + + if (gtk_expander_get_spacing (GTK_EXPANDER (widget)) != 0) + { + source_add (data, + " gtk_expander_set_spacing (GTK_EXPANDER (%s), %d);\n", + data->wname, + gtk_expander_get_spacing (GTK_EXPANDER (widget))); + } +} + +void +gb_expander_get_child_properties (GtkWidget *widget, + GtkWidget *child, + GbWidgetGetArgData *data) +{ + if (data->action == GB_SAVING && + gtk_expander_get_label_widget (GTK_EXPANDER (widget)) == child) + { + save_start_tag (data, "packing"); + save_string (data, "type", "label_item"); + save_end_tag (data, "packing"); + } +} + +void +gb_expander_write_add_child_source (GtkWidget *parent, + const char *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData *data) +{ + if (gtk_expander_get_label_widget (GTK_EXPANDER (parent)) == child) + { + source_add (data, + " gtk_expander_set_label_widget (GTK_EXPANDER (%s), %s);\n", + parent_name, data->wname); + } + else + { + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + } +} + +GbWidget * +gb_expander_init () +{ + gb_widget_init_struct (&gb_expander); + + gb_expander.pixmap_struct = expander_xpm; + gb_expander.tooltip = _("Expander"); + + gb_expander.gb_widget_new = gb_expander_new; + gb_expander.gb_widget_create_properties = gb_expander_create_properties; + gb_expander.gb_widget_get_properties = gb_expander_get_properties; + gb_expander.gb_widget_set_properties = gb_expander_set_properties; + gb_expander.gb_widget_create_popup_menu = gb_expander_create_popup_menu; + gb_expander.gb_widget_write_source = gb_expander_write_source; + + gb_expander.gb_widget_add_child = gb_expander_add_child; + gb_expander.gb_widget_get_child_properties = gb_expander_get_child_properties; + gb_expander.gb_widget_write_add_child_source = gb_expander_write_add_child_source; + + return &gb_expander; +} diff --git a/tools/glade/glade/gbwidgets/gbfilechooserbutton.c b/tools/glade/glade/gbwidgets/gbfilechooserbutton.c new file mode 100644 index 00000000..f2330b6f --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfilechooserbutton.c @@ -0,0 +1,309 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/filechooserbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Action = "GtkFileChooserButton::action"; +static gchar *LocalOnly = "GtkFileChooserButton::local_only"; +static gchar *ShowHidden = "GtkFileChooserButton::show_hidden"; +static gchar *Confirm = "GtkFileChooserButton::do_overwrite_confirmation"; +static gchar *Title = "GtkFileChooserButton::title"; +static gchar *WidthChars = "GtkFileChooserButton::width_chars"; + + +/* Note that GtkFileChooserButton doesn't support "Save" or "Create Folder". */ +static const gchar *GbActionChoices[] = +{"Open", "Select Folder", NULL}; +static const gint GbActionValues[] = +{ + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER +}; +static const gchar *GbActionSymbols[] = +{ + "GTK_FILE_CHOOSER_ACTION_OPEN", + "GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFileChooser, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_file_chooser_button_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_file_chooser_button_new (NULL, + GTK_FILE_CHOOSER_ACTION_OPEN); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_file_chooser_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_string (Title, _("Title:"), + _("The window title of the file chooser dialog")); + property_add_choice (Action, _("Action:"), + _("The type of file operation being performed"), + GbActionChoices); + property_add_bool (LocalOnly, _("Local Only:"), + _("Whether the selected files should be limited to local files")); + property_add_bool (ShowHidden, _("Show Hidden:"), + _("Whether the hidden files and folders should be displayed")); + property_add_bool (Confirm, _("Confirm:"), + _("Whether a confirmation dialog will be displayed if a file will be overwritten")); + property_add_int_range (WidthChars, _("Width in Chars:"), + _("The width of the button in characters"), + -1, 1000, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_file_chooser_button_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gchar *title; + GtkFileChooserAction action; + gboolean local_only, show_hidden, confirm; + gint i, width_chars; + + g_object_get (widget, + "title", &title, + "action", &action, + "local_only", &local_only, + "show_hidden", &show_hidden, + "do_overwrite_confirmation", &confirm, + "width_chars", &width_chars, + NULL); + + gb_widget_output_translatable_string (data, Title, title); + g_free (title); + + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); i++) + { + if (GbActionValues[i] == action) + gb_widget_output_choice (data, Action, i, GbActionSymbols[i]); + } + + gb_widget_output_bool (data, LocalOnly, local_only); + gb_widget_output_bool (data, ShowHidden, show_hidden); + gb_widget_output_bool (data, Confirm, confirm); + gb_widget_output_int (data, WidthChars, width_chars); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_file_chooser_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *title, *action; + gboolean local_only, show_hidden, confirm; + gint i, width_chars; + + title = gb_widget_input_string (data, Title); + if (data->apply) + g_object_set (widget, "title", title, NULL); + + action = gb_widget_input_choice (data, Action); + if (data->apply) + { + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); + i++) + { + if (!strcmp (action, GbActionChoices[i]) + || !strcmp (action, GbActionSymbols[i])) + { + g_object_set (widget, "action", GbActionValues[i], NULL); + break; + } + } + } + + local_only = gb_widget_input_bool (data, LocalOnly); + if (data->apply) + g_object_set (widget, "local_only", local_only, NULL); + + show_hidden = gb_widget_input_bool (data, ShowHidden); + if (data->apply) + g_object_set (widget, "show_hidden", show_hidden, NULL); + + confirm = gb_widget_input_bool (data, Confirm); + if (data->apply) + g_object_set (widget, "do_overwrite_confirmation", confirm, NULL); + + width_chars = gb_widget_input_int (data, WidthChars); + if (data->apply) + g_object_set (widget, "width_chars", width_chars, NULL); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFileChooser, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_file_chooser_widget_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_file_chooser_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *title; + GtkFileChooserAction action; + gboolean local_only, show_hidden, confirm; + gint width_chars; + const gchar *action_symbol = GbActionSymbols[0]; + gint i; + + g_object_get (widget, + "title", &title, + "action", &action, + "local_only", &local_only, + "show_hidden", &show_hidden, + "do_overwrite_confirmation", &confirm, + "width_chars", &width_chars, + NULL); + + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); i++) + { + if (GbActionValues[i] == action) + action_symbol = GbActionSymbols[i]; + } + + if (data->create_widget) + { + gboolean translatable, context; + gchar *comments; + + glade_util_get_translation_properties (widget, Title, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " %s = gtk_file_chooser_button_new (%s, %s);\n", + data->wname, + source_make_string_full (title, data->use_gettext && translatable, context), + action_symbol); + } + + gb_widget_write_standard_source (widget, data); + + if (!local_only || show_hidden || width_chars != -1 || confirm) + { + source_add (data, " g_object_set (%s,\n", data->wname); + + if (!local_only) + source_add (data, " \"local-only\", FALSE,\n"); + + if (show_hidden) + source_add (data, " \"show-hidden\", TRUE,\n"); + + if (confirm) + source_add (data, " \"confirm\", TRUE,\n"); + + if (width_chars != -1) + source_add (data, " \"width-chars\", %i,\n", + width_chars); + + source_add (data, " NULL);\n"); + } + + g_free (title); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_file_chooser_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_file_chooser_button_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = filechooserbutton_xpm; + gbwidget.tooltip = _("File Chooser Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_file_chooser_button_new; + gbwidget.gb_widget_create_properties = gb_file_chooser_button_create_properties; + gbwidget.gb_widget_get_properties = gb_file_chooser_button_get_properties; + gbwidget.gb_widget_set_properties = gb_file_chooser_button_set_properties; + gbwidget.gb_widget_write_source = gb_file_chooser_button_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_file_chooser_widget_create_popup_menu; +*/ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbfilechooserdialog.c b/tools/glade/glade/gbwidgets/gbfilechooserdialog.c new file mode 100644 index 00000000..b80a5402 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfilechooserdialog.c @@ -0,0 +1,451 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/filechooserdialog.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "FileChooserDialog|GtkWindow::title"; +static gchar *Type = "FileChooserDialog|GtkWindow::type"; +static gchar *Position = "FileChooserDialog|GtkWindow::window_position"; +static gchar *Modal = "FileChooserDialog|GtkWindow::modal"; +static gchar *DefaultWidth = "FileChooserDialog|GtkWindow::default_width"; +static gchar *DefaultHeight = "FileChooserDialog|GtkWindow::default_height"; +static gchar *Shrink = "FileChooserDialog|GtkWindow::allow_shrink"; +static gchar *Grow = "FileChooserDialog|GtkWindow::allow_grow"; +static gchar *AutoShrink = "FileChooserDialog|GtkWindow::auto_shrink"; +static gchar *IconName = "FileChooserDialog|GtkWindow::icon_name"; +static gchar *FocusOnMap = "FileChooserDialog|GtkWindow::focus_on_map"; + +static gchar *Resizable = "FileChooserDialog|GtkWindow::resizable"; +static gchar *DestroyWithParent = "FileChooserDialog|GtkWindow::destroy_with_parent"; +static gchar *Icon = "FileChooserDialog|GtkWindow::icon"; + +static gchar *Role = "FileChooserDialog|GtkWindow::role"; +static gchar *TypeHint = "FileChooserDialog|GtkWindow::type_hint"; +static gchar *SkipTaskbar = "FileChooserDialog|GtkWindow::skip_taskbar_hint"; +static gchar *SkipPager = "FileChooserDialog|GtkWindow::skip_pager_hint"; +static gchar *Decorated = "FileChooserDialog|GtkWindow::decorated"; +static gchar *Gravity = "FileChooserDialog|GtkWindow::gravity"; + +static gchar *Action = "GtkFileChooserDialog::action"; +static gchar *LocalOnly = "GtkFileChooserDialog::local_only"; +static gchar *SelectMultiple = "GtkFileChooserDialog::select_multiple"; +static gchar *ShowHidden = "GtkFileChooserDialog::show_hidden"; +static gchar *Confirm = "GtkFileChooserDialog::do_overwrite_confirmation"; +static gchar *Urgency = "FileChooserDialog|GtkWindow::urgency_hint"; + + +static const gchar *GbActionChoices[] = +{"Open", "Save", "Select Folder", "Create Folder", NULL}; +static const gint GbActionValues[] = +{ + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER +}; +static const gchar *GbActionSymbols[] = +{ + "GTK_FILE_CHOOSER_ACTION_OPEN", + "GTK_FILE_CHOOSER_ACTION_SAVE", + "GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER", + "GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFileChooserDialog, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_file_chooser_dialog_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget, *button; + + new_widget = gtk_file_chooser_dialog_new (NULL, NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + NULL); + + /* We want it to be treated as a normal window. */ + gtk_window_set_type_hint (GTK_WINDOW (new_widget), + GDK_WINDOW_TYPE_HINT_NORMAL); + + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + + gb_widget_create_from (GTK_DIALOG (new_widget)->vbox, + data->action == GB_CREATING ? "dialog-content_area" : NULL); + gb_widget_set_child_name (GTK_DIALOG (new_widget)->vbox, GladeChildDialogVBox); + + gb_widget_create_from (GTK_DIALOG (new_widget)->action_area, + data->action == GB_CREATING ? "dialog-action_area" : NULL); + gb_widget_set_child_name (GTK_DIALOG (new_widget)->action_area, + GladeChildDialogActionArea); + + + if (data->action == GB_CREATING) + { + GladeWidgetData *wdata; + + button = gtk_dialog_add_button (GTK_DIALOG (new_widget), + GTK_STOCK_CANCEL, -1); + gb_widget_create_from (button, "button"); + gtk_object_set_data (GTK_OBJECT (button), GladeButtonStockIDKey, + (gpointer) GTK_STOCK_CANCEL); + gtk_object_set_data (GTK_OBJECT (button), GladeDialogResponseIDKey, + GINT_TO_POINTER (GTK_RESPONSE_CANCEL)); + + button = gtk_dialog_add_button (GTK_DIALOG (new_widget), + GTK_STOCK_OPEN, -1); + gb_widget_create_from (button, "button"); + gtk_object_set_data (GTK_OBJECT (button), GladeButtonStockIDKey, + (gpointer) GTK_STOCK_OPEN); + gtk_object_set_data (GTK_OBJECT (button), GladeDialogResponseIDKey, + GINT_TO_POINTER (GTK_RESPONSE_OK)); + /* Set this button as the default. */ + wdata = g_object_get_data (G_OBJECT (button), GB_WIDGET_DATA_KEY); + wdata->flags |= GLADE_GRAB_DEFAULT; + } + + gtk_object_set_data (GTK_OBJECT (new_widget), TypeHint, + GINT_TO_POINTER (GLADE_TYPE_HINT_DIALOG_INDEX)); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_file_chooser_dialog_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Action, _("Action:"), + _("The type of file operation being performed"), + GbActionChoices); + property_add_bool (LocalOnly, _("Local Only:"), + _("Whether the selected files should be limited to local files")); + property_add_bool (SelectMultiple, _("Select Multiple:"), + _("Whether to allow multiple files to be selected")); + property_add_bool (ShowHidden, _("Show Hidden:"), + _("Whether the hidden files and folders should be displayed")); + property_add_bool (Confirm, _("Confirm:"), + _("Whether a confirmation dialog will be displayed if a file will be overwritten")); + + gb_window_create_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_file_chooser_dialog_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + GtkFileChooserAction action; + gboolean local_only, select_multiple, show_hidden, confirm; + gint i; + + g_object_get (widget, + "action", &action, + "local_only", &local_only, + "select_multiple", &select_multiple, + "show_hidden", &show_hidden, + "do_overwrite_confirmation", &confirm, + NULL); + + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); i++) + { + if (GbActionValues[i] == action) + gb_widget_output_choice (data, Action, i, GbActionSymbols[i]); + } + + gb_widget_output_bool (data, LocalOnly, local_only); + gb_widget_output_bool (data, SelectMultiple, select_multiple); + gb_widget_output_bool (data, ShowHidden, show_hidden); + gb_widget_output_bool (data, Confirm, confirm); + + gb_window_get_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_file_chooser_dialog_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *action; + gboolean local_only, select_multiple, show_hidden, confirm; + gint i; + + action = gb_widget_input_choice (data, Action); + if (data->apply) + { + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); + i++) + { + if (!strcmp (action, GbActionChoices[i]) + || !strcmp (action, GbActionSymbols[i])) + { + g_object_set (widget, "action", GbActionValues[i], NULL); + break; + } + } + } + + local_only = gb_widget_input_bool (data, LocalOnly); + if (data->apply) + g_object_set (widget, "local_only", local_only, NULL); + + select_multiple = gb_widget_input_bool (data, SelectMultiple); + if (data->apply) + g_object_set (widget, "select_multiple", select_multiple, NULL); + + show_hidden = gb_widget_input_bool (data, ShowHidden); + if (data->apply) + g_object_set (widget, "show_hidden", show_hidden, NULL); + + confirm = gb_widget_input_bool (data, Confirm); + if (data->apply) + g_object_set (widget, "do_overwrite_confirmation", confirm, NULL); + + gb_window_set_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFileChooserDialog, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_file_chooser_dialog_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_file_chooser_dialog_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkFileChooserAction action; + gboolean local_only, select_multiple, show_hidden, confirm; + gchar *wname, *child_name; + gboolean translatable, context; + gchar *comments; + + g_object_get (widget, + "action", &action, + "local_only", &local_only, + "select_multiple", &select_multiple, + "show_hidden", &show_hidden, + "do_overwrite_confirmation", &confirm, + NULL); + + if (data->create_widget) + { + const gchar *action_symbol = GbActionSymbols[0]; + gint i; + + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); + i++) + { + if (GbActionValues[i] == action) + action_symbol = GbActionSymbols[i]; + } + + glade_util_get_translation_properties (widget, Title, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " %s = gtk_file_chooser_dialog_new (%s, NULL, %s, NULL);\n", + data->wname, + source_make_string_full (GTK_WINDOW (widget)->title, + data->use_gettext && translatable, + context), + action_symbol); + } + + gb_widget_write_standard_source (widget, data); + + if (!local_only || select_multiple || show_hidden || confirm) + { + source_add (data, " g_object_set (%s,\n", data->wname); + + if (!local_only) + source_add (data, " \"local-only\", FALSE,\n"); + + if (select_multiple) + source_add (data, " \"select-multiple\", TRUE,\n"); + + if (show_hidden) + source_add (data, " \"show-hidden\", TRUE,\n"); + + if (confirm) + source_add (data, " \"confirm\", TRUE,\n"); + + source_add (data, " NULL);\n"); + } + + gb_window_write_standard_source (widget, data, + NULL, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + + /* We output the source code for the children here, since the code should + not include calls to create the widgets. We need to specify that the + names used are like: "GTK_DIALOG (<dialog-name>)->vbox". + We need to remember the dialog's name since data->wname + will be overwritten. */ + wname = g_strdup (data->wname); + + source_add (data, "\n"); + child_name = (gchar*) gtk_widget_get_name (GTK_DIALOG (widget)->vbox); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = gtk_dialog_get_content_area (GTK_DIALOG (%s));\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_DIALOG (widget)->vbox, data); + + /* action_area is a child of vbox so I had to add a kludge to stop it + being written as a normal child - we need to do it here so that we + don't output code to create it. */ + child_name = (gchar*) gtk_widget_get_name (GTK_DIALOG (widget)->action_area); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = gtk_dialog_get_action_area (GTK_DIALOG (%s));\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_DIALOG (widget)->action_area, data); + + g_free (wname); + data->write_children = FALSE; +} + + +static GtkWidget * +gb_file_chooser_dialog_get_child (GtkWidget * widget, + const gchar * child_name) +{ + if (!strcmp (child_name, GladeChildDialogVBox)) + return GTK_DIALOG (widget)->vbox; + else if (!strcmp (child_name, GladeChildDialogActionArea)) + return GTK_DIALOG (widget)->action_area; + else + return NULL; +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_file_chooser_dialog_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_file_chooser_dialog_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = filechooserdialog_xpm; + gbwidget.tooltip = _("File Chooser Dialog"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_file_chooser_dialog_new; + gbwidget.gb_widget_create_properties = gb_file_chooser_dialog_create_properties; + gbwidget.gb_widget_get_properties = gb_file_chooser_dialog_get_properties; + gbwidget.gb_widget_set_properties = gb_file_chooser_dialog_set_properties; + gbwidget.gb_widget_get_child = gb_file_chooser_dialog_get_child; + gbwidget.gb_widget_write_source = gb_file_chooser_dialog_write_source; + gbwidget.gb_widget_destroy = gb_window_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_file_chooser_dialog_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbfilechooserwidget.c b/tools/glade/glade/gbwidgets/gbfilechooserwidget.c new file mode 100644 index 00000000..ea19174d --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfilechooserwidget.c @@ -0,0 +1,274 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/filechooserwidget.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Action = "GtkFileChooserWidget::action"; +static gchar *LocalOnly = "GtkFileChooserWidget::local_only"; +static gchar *SelectMultiple = "GtkFileChooserWidget::select_multiple"; +static gchar *ShowHidden = "GtkFileChooserWidget::show_hidden"; + + +static const gchar *GbActionChoices[] = +{"Open", "Save", "Select Folder", "Create Folder", NULL}; +static const gint GbActionValues[] = +{ + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER +}; +static const gchar *GbActionSymbols[] = +{ + "GTK_FILE_CHOOSER_ACTION_OPEN", + "GTK_FILE_CHOOSER_ACTION_SAVE", + "GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER", + "GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFileChooser, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_file_chooser_widget_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_file_chooser_widget_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Action, _("Action:"), + _("The type of file operation being performed"), + GbActionChoices); + property_add_bool (LocalOnly, _("Local Only:"), + _("Whether the selected files should be limited to local files")); + property_add_bool (SelectMultiple, _("Select Multiple:"), + _("Whether to allow multiple files to be selected")); + property_add_bool (ShowHidden, _("Show Hidden:"), + _("Whether the hidden files and folders should be displayed")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_file_chooser_widget_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + GtkFileChooserAction action; + gboolean local_only, select_multiple, show_hidden; + gint i; + + g_object_get (widget, + "action", &action, + "local_only", &local_only, + "select_multiple", &select_multiple, + "show_hidden", &show_hidden, + NULL); + + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); i++) + { + if (GbActionValues[i] == action) + gb_widget_output_choice (data, Action, i, GbActionSymbols[i]); + } + + gb_widget_output_bool (data, LocalOnly, local_only); + gb_widget_output_bool (data, SelectMultiple, select_multiple); + gb_widget_output_bool (data, ShowHidden, show_hidden); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_file_chooser_widget_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *action; + gboolean local_only, select_multiple, show_hidden; + gint i; + + action = gb_widget_input_choice (data, Action); + if (data->apply) + { + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); + i++) + { + if (!strcmp (action, GbActionChoices[i]) + || !strcmp (action, GbActionSymbols[i])) + { + g_object_set (widget, "action", GbActionValues[i], NULL); + break; + } + } + } + + local_only = gb_widget_input_bool (data, LocalOnly); + if (data->apply) + g_object_set (widget, "local_only", local_only, NULL); + + select_multiple = gb_widget_input_bool (data, SelectMultiple); + if (data->apply) + g_object_set (widget, "select_multiple", select_multiple, NULL); + + show_hidden = gb_widget_input_bool (data, ShowHidden); + if (data->apply) + g_object_set (widget, "show_hidden", show_hidden, NULL); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFileChooser, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_file_chooser_widget_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_file_chooser_widget_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkFileChooserAction action; + gboolean local_only, select_multiple, show_hidden; + + g_object_get (widget, + "action", &action, + "local_only", &local_only, + "select_multiple", &select_multiple, + "show_hidden", &show_hidden, + NULL); + + if (data->create_widget) + { + const gchar *action_symbol = GbActionSymbols[0]; + gint i; + + for (i = 0; i < sizeof (GbActionValues) / sizeof (GbActionValues[0]); + i++) + { + if (GbActionValues[i] == action) + action_symbol = GbActionSymbols[i]; + } + + source_add (data, + " %s = gtk_file_chooser_widget_new (%s);\n", + data->wname, + action_symbol); + } + + gb_widget_write_standard_source (widget, data); + + if (!local_only || select_multiple || show_hidden) + { + source_add (data, " g_object_set (%s,\n", data->wname); + + if (!local_only) + source_add (data, " \"local-only\", FALSE,\n"); + + if (select_multiple) + source_add (data, " \"select-multiple\", TRUE,\n"); + + if (show_hidden) + source_add (data, " \"show-hidden\", TRUE,\n"); + + source_add (data, " NULL);\n"); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_file_chooser_widget_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_file_chooser_widget_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = filechooserwidget_xpm; + gbwidget.tooltip = _("File Chooser"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_file_chooser_widget_new; + gbwidget.gb_widget_create_properties = gb_file_chooser_widget_create_properties; + gbwidget.gb_widget_get_properties = gb_file_chooser_widget_get_properties; + gbwidget.gb_widget_set_properties = gb_file_chooser_widget_set_properties; + gbwidget.gb_widget_write_source = gb_file_chooser_widget_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_file_chooser_widget_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbfileselection.c b/tools/glade/glade/gbwidgets/gbfileselection.c new file mode 100644 index 00000000..77e34333 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfileselection.c @@ -0,0 +1,308 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkfilesel.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/fileseldialog.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "FileSel|GtkWindow::title"; +static gchar *Type = "FileSel|GtkWindow::type"; +static gchar *Position = "FileSel|GtkWindow::window_position"; +static gchar *Modal = "FileSel|GtkWindow::modal"; +static gchar *DefaultWidth = "FileSel|GtkWindow::default_width"; +static gchar *DefaultHeight = "FileSel|GtkWindow::default_height"; +static gchar *FileOps = "GtkFileSelection::show_fileops"; +static gchar *Shrink = "FileSel|GtkWindow::allow_shrink"; +static gchar *Grow = "FileSel|GtkWindow::allow_grow"; +static gchar *AutoShrink = "FileSel|GtkWindow::auto_shrink"; +static gchar *IconName = "FileSel|GtkWindow::icon_name"; +static gchar *FocusOnMap = "FileSel|GtkWindow::focus_on_map"; + +static gchar *Resizable = "FileSel|GtkWindow::resizable"; +static gchar *DestroyWithParent = "FileSel|GtkWindow::destroy_with_parent"; +static gchar *Icon = "FileSel|GtkWindow::icon"; + +static gchar *Role = "FileSel|GtkWindow::role"; +static gchar *TypeHint = "FileSel|GtkWindow::type_hint"; +static gchar *SkipTaskbar = "FileSel|GtkWindow::skip_taskbar_hint"; +static gchar *SkipPager = "FileSel|GtkWindow::skip_pager_hint"; +static gchar *Decorated = "FileSel|GtkWindow::decorated"; +static gchar *Gravity = "FileSel|GtkWindow::gravity"; +static gchar *Urgency = "FileSel|GtkWindow::urgency_hint"; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFileSelection, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_file_selection_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_file_selection_new (_("Select File")); + + GtkFileSelection *filesel = GTK_FILE_SELECTION (new_widget); + + /* We want it to be treated as a normal window. */ + gtk_window_set_type_hint (GTK_WINDOW (new_widget), + GDK_WINDOW_TYPE_HINT_NORMAL); + + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + gb_widget_create_from (filesel->ok_button, + data->action == GB_CREATING ? "ok_button" : NULL); + gb_widget_set_child_name (filesel->ok_button, GladeChildOKButton); + + gb_widget_create_from (filesel->cancel_button, + data->action == GB_CREATING ? "cancel_button" : NULL); + gb_widget_set_child_name (filesel->cancel_button, GladeChildCancelButton); + + gtk_object_set_data (GTK_OBJECT (new_widget), TypeHint, + GINT_TO_POINTER (GLADE_TYPE_HINT_DIALOG_INDEX)); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_file_selection_create_properties (GtkWidget * widget, + GbWidgetCreateArgData * data) +{ + gb_window_create_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + property_add_bool (FileOps, _("File Ops.:"), + _("If the file operation buttons are shown")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_file_selection_get_properties (GtkWidget * widget, + GbWidgetGetArgData * data) +{ + gb_window_get_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + gb_widget_output_bool (data, FileOps, + GTK_FILE_SELECTION (widget)->fileop_c_dir != NULL); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_file_selection_set_properties (GtkWidget * widget, + GbWidgetSetArgData * data) +{ + gboolean show_fileops; + + gb_window_set_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + + show_fileops = gb_widget_input_bool (data, FileOps); + if (data->apply) + { + if (show_fileops) + gtk_file_selection_show_fileop_buttons (GTK_FILE_SELECTION (widget)); + else + gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (widget)); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFileSelection, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_file_selection_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_file_selection_write_source (GtkWidget * widget, + GbWidgetWriteSourceData *data) +{ + gchar *wname, *child_name; + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + glade_util_get_translation_properties (widget, Title, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, " %s = gtk_file_selection_new (%s);\n", + data->wname, + source_make_string_full (GTK_WINDOW (widget)->title, + data->use_gettext && translatable, + context)); + } + + gb_widget_write_standard_source (widget, data); + + /* The title is already set above, so we pass NULL to skip it. */ + gb_window_write_standard_source (widget, data, + NULL, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + + if (GTK_FILE_SELECTION (widget)->fileop_c_dir == NULL) + { + source_add (data, + " gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (%s));\n", + data->wname); + } + + + /* We output the source code for the buttons here, but we don't want them + to be created. We need to remember the dialog's name since data->wname + will be overwritten. */ + wname = g_strdup (data->wname); + + source_add (data, "\n"); + child_name = (gchar*) gtk_widget_get_name (GTK_FILE_SELECTION (widget)->ok_button); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_FILE_SELECTION (%s)->ok_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_FILE_SELECTION (widget)->ok_button, data); + + child_name = (gchar*) gtk_widget_get_name (GTK_FILE_SELECTION (widget)->cancel_button); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_FILE_SELECTION (%s)->cancel_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_FILE_SELECTION (widget)->cancel_button, data); + + g_free (wname); + + data->write_children = FALSE; +} + + + +static GtkWidget * +gb_file_selection_get_child (GtkWidget * widget, + const gchar * child_name) +{ + if (!strcmp (child_name, GladeChildOKButton)) + return GTK_FILE_SELECTION (widget)->ok_button; + else if (!strcmp (child_name, GladeChildCancelButton)) + return GTK_FILE_SELECTION (widget)->cancel_button; + else + return NULL; +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_file_selection_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_file_selection_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = fileseldialog_xpm; + gbwidget.tooltip = _("File Selection Dialog"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_file_selection_new; + gbwidget.gb_widget_create_properties = gb_file_selection_create_properties; + gbwidget.gb_widget_get_properties = gb_file_selection_get_properties; + gbwidget.gb_widget_set_properties = gb_file_selection_set_properties; + gbwidget.gb_widget_get_child = gb_file_selection_get_child; + gbwidget.gb_widget_write_source = gb_file_selection_write_source; + gbwidget.gb_widget_destroy = gb_window_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_file_selection_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbfixed.c b/tools/glade/glade/gbwidgets/gbfixed.c new file mode 100644 index 00000000..2fbcf653 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfixed.c @@ -0,0 +1,246 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkfixed.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/fixed.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +/* Child properties. */ +const gchar *GladeFixedChildX = "GtkFixed::x"; +const gchar *GladeFixedChildY = "GtkFixed::y"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFixed, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +/* + GtkWidget* + gb_fixed_new(GbWidgetNewData *data) + { + + } + */ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +/* + static void + gb_fixed_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) + { + + } + */ + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +/* + static void + gb_fixed_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) + { + + } + */ + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +/* + static void + gb_fixed_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) + { + + } + */ + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFixed, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_fixed_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_fixed_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_fixed_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); +} + + +/* + * Creates the child packing properties for children of this widget. + */ +void +gb_fixed_create_child_properties (GtkWidget * widget, + GbWidgetCreateChildArgData * data) +{ + property_add_int_range (GladeFixedChildX, _("X:"), + _("The X coordinate of the widget in the GtkFixed"), + 0, 10000, 1, 10, 1); + property_add_int_range (GladeFixedChildY, _("Y:"), + _("The Y coordinate of the widget in the GtkFixed"), + 0, 10000, 1, 10, 1); +} + + +/* Shows or saves the child properties of a child of a GtkFixed. */ +void +gb_fixed_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + gint x, y; + + if (data->action == GB_SAVING) + save_start_tag (data, "packing"); + + gtk_container_child_get (GTK_CONTAINER (widget), child, + "x", &x, + "y", &y, + NULL); + + gb_widget_output_int (data, GladeFixedChildX, x); + gb_widget_output_int (data, GladeFixedChildY, y); + + if (data->action == GB_SAVING) + save_end_tag (data, "packing"); +} + + +/* Applies or loads the child properties of a child of a GtkFixed. */ +void +gb_fixed_set_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + gint x, y; + + x = gb_widget_input_int (data, GladeFixedChildX); + if (data->apply) + gtk_container_child_set (GTK_CONTAINER (widget), child, + "x", x, + NULL); + + y = gb_widget_input_int (data, GladeFixedChildY); + if (data->apply) + gtk_container_child_set (GTK_CONTAINER (widget), child, + "y", y, + NULL); +} + + +/* Outputs source to add a child widget to a GtkFixed. */ +static void +gb_fixed_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + gint x, y; + + gtk_container_child_get (GTK_CONTAINER (parent), child, + "x", &x, + "y", &y, + NULL); + source_add (data, + " gtk_fixed_put (GTK_FIXED (%s), %s, %i, %i);\n", + parent_name, data->wname, x, y); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_fixed_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_fixed_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = fixed_xpm; + gbwidget.tooltip = _("Fixed Positions"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_write_source = gb_fixed_write_source; + gbwidget.gb_widget_create_child_properties = gb_fixed_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_fixed_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_fixed_set_child_properties; + gbwidget.gb_widget_write_add_child_source = gb_fixed_write_add_child_source; + +/* + gbwidget.gb_widget_new = gb_fixed_new; + gbwidget.gb_widget_create_properties = gb_fixed_create_properties; + gbwidget.gb_widget_get_properties = gb_fixed_get_properties; + gbwidget.gb_widget_set_properties = gb_fixed_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_fixed_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbfontbutton.c b/tools/glade/glade/gbwidgets/gbfontbutton.c new file mode 100644 index 00000000..79619e25 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfontbutton.c @@ -0,0 +1,282 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/fontbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "GtkFontButton::title"; +static gchar *ShowStyle = "GtkFontButton::show_style"; +static gchar *ShowSize = "GtkFontButton::show_size"; +static gchar *UseFont = "GtkFontButton::use_font"; +static gchar *UseFontSize = "GtkFontButton::use_size"; +static gchar *FocusOnClick = "GtkFontButton|GtkButton::focus_on_click"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFontButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +/* +static GtkWidget* +gb_font_button_new (GbWidgetNewData *data) +{ + +} +*/ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_font_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_string (Title, _("Title:"), + _("The title of the font selection dialog")); + property_add_bool (ShowStyle, _("Show Style:"), + _("If the font style is shown as part of the font information")); + property_add_bool (ShowSize, _("Show Size:"), + _("If the font size is shown as part of the font information")); + property_add_bool (UseFont, _("Use Font:"), + _("If the selected font is used when displaying the font information")); + property_add_bool (UseFontSize, _("Use Size:"), + _("if the selected font size is used when displaying the font information")); + property_add_bool (FocusOnClick, _("Focus On Click:"), _("If the button grabs focus when it is clicked")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_font_button_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gboolean show_style, show_size, use_font, use_size; + const gchar *title; + + /* Only save if the title is different to the default. */ + title = gtk_font_button_get_title (GTK_FONT_BUTTON (widget)); + if (data->action == GB_SHOWING + || (title && strcmp (title, dgettext (GLADE_GTK_GETTEXT_PACKAGE, + "Pick a Font")))) + gb_widget_output_translatable_string (data, Title, title); + + g_object_get (G_OBJECT (widget), + "show_style", &show_style, + "show_size", &show_size, + "use_font", &use_font, + "use_size", &use_size, + NULL); + + gb_widget_output_bool (data, ShowStyle, show_style); + gb_widget_output_bool (data, ShowSize, show_size); + gb_widget_output_bool (data, UseFont, use_font); + gb_widget_output_bool (data, UseFontSize, use_size); + + gb_widget_output_bool (data, FocusOnClick, + gtk_button_get_focus_on_click (GTK_BUTTON (widget))); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_font_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *title; + gboolean show_style, show_size, use_font, use_size, focus_on_click; + + title = gb_widget_input_string (data, Title); + if (data->apply) + gtk_font_button_set_title (GTK_FONT_BUTTON (widget), + title && title[0] + ? title : dgettext (GLADE_GTK_GETTEXT_PACKAGE, + "Pick a Font")); + + show_style = gb_widget_input_bool (data, ShowStyle); + if (data->apply) + gtk_font_button_set_show_style (GTK_FONT_BUTTON (widget), show_style); + + show_size = gb_widget_input_bool (data, ShowSize); + if (data->apply) + gtk_font_button_set_show_size (GTK_FONT_BUTTON (widget), show_size); + + use_font = gb_widget_input_bool (data, UseFont); + if (data->apply) + gtk_font_button_set_use_font (GTK_FONT_BUTTON (widget), use_font); + + use_size = gb_widget_input_bool (data, UseFontSize); + if (data->apply) + gtk_font_button_set_use_size (GTK_FONT_BUTTON (widget), use_size); + + focus_on_click = gb_widget_input_bool (data, FocusOnClick); + if (data->apply) + gtk_button_set_focus_on_click (GTK_BUTTON (widget), focus_on_click); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFontButton, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_font_button_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_font_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + const gchar *title; + gboolean show_style, show_size, use_font, use_size; + + if (data->create_widget) + source_add (data, " %s = gtk_font_button_new ();\n", data->wname); + + gb_widget_write_standard_source (widget, data); + + title = gtk_font_button_get_title (GTK_FONT_BUTTON (widget)); + if (title && title[0] + && strcmp (title, dgettext (GLADE_GTK_GETTEXT_PACKAGE, "Pick a Font"))) + { + gboolean translatable, context; + gchar *comments; + + glade_util_get_translation_properties (widget, Title, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " gtk_font_button_set_title (GTK_FONT_BUTTON (%s), %s);\n", + data->wname, + source_make_string_full (title, data->use_gettext && translatable, context)); + } + + g_object_get (G_OBJECT (widget), + "show_style", &show_style, + "show_size", &show_size, + "use_font", &use_font, + "use_size", &use_size, + NULL); + + if (!show_style) + { + source_add (data, + " gtk_font_button_set_show_style (GTK_FONT_BUTTON (%s), FALSE);\n", + data->wname); + } + + if (!show_size) + { + source_add (data, + " gtk_font_button_set_show_size (GTK_FONT_BUTTON (%s), FALSE);\n", + data->wname); + } + + if (use_font) + { + source_add (data, + " gtk_font_button_set_use_font (GTK_FONT_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (use_size) + { + source_add (data, + " gtk_font_button_set_use_size (GTK_FONT_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (!gtk_button_get_focus_on_click (GTK_BUTTON (widget))) + { + source_add (data, + " gtk_button_set_focus_on_click (GTK_BUTTON (%s), FALSE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_font_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_font_button_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = fontbutton_xpm; + gbwidget.tooltip = _("Font Chooser Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_font_button_create_properties; + gbwidget.gb_widget_get_properties = gb_font_button_get_properties; + gbwidget.gb_widget_set_properties = gb_font_button_set_properties; + gbwidget.gb_widget_write_source = gb_font_button_write_source; +/* + gbwidget.gb_widget_new = gb_font_button_new; + gbwidget.gb_widget_create_popup_menu = gb_font_button_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbfontselection.c b/tools/glade/glade/gbwidgets/gbfontselection.c new file mode 100644 index 00000000..11824004 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfontselection.c @@ -0,0 +1,184 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkfontsel.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/fontsel.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *PreviewText = "GtkFontSelection::preview_text"; + + +/* This is the default preview text, pinched from gtkfontsel.c. */ +#define DEFAULT_PREVIEW_TEXT "abcdefghijk ABCDEFGHIJK" + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the funtion in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFontSelection, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_font_selection_new (GbWidgetNewData *data) +{ + return gtk_font_selection_new (); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_font_selection_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_string (PreviewText, _("Preview Text:"), _("The preview text to display")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_font_selection_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + const gchar *preview_text; + + preview_text = gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (widget)); + gb_widget_output_translatable_string (data, PreviewText, preview_text); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_font_selection_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *preview_text; + + preview_text = gb_widget_input_string (data, PreviewText); + if (data->apply) + gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (widget), + preview_text); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFontSelection, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_font_selection_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_font_selection_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + const gchar *preview_text; + + if (data->create_widget) + { + source_add (data, " %s = gtk_font_selection_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + preview_text = gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (widget)); + if (strcmp (preview_text, DEFAULT_PREVIEW_TEXT)) + { + gboolean translatable, context; + gchar *comments; + + glade_util_get_translation_properties (widget, PreviewText, + &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (%s), %s);\n", + data->wname, + source_make_string_full (preview_text, data->use_gettext && translatable, context)); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_font_selection_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_font_selection_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = fontsel_xpm; + gbwidget.tooltip = _("Font Selection"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_font_selection_new; + gbwidget.gb_widget_create_properties = gb_font_selection_create_properties; + gbwidget.gb_widget_get_properties = gb_font_selection_get_properties; + gbwidget.gb_widget_set_properties = gb_font_selection_set_properties; +/* + gbwidget.gb_widget_create_popup_menu = gb_font_selection_create_popup_menu; +*/ + gbwidget.gb_widget_write_source = gb_font_selection_write_source; + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbfontselectiondialog.c b/tools/glade/glade/gbwidgets/gbfontselectiondialog.c new file mode 100644 index 00000000..7a7d198d --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbfontselectiondialog.c @@ -0,0 +1,317 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkfontsel.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/fontseldialog.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "FontSelDialog|GtkWindow::title"; +static gchar *Type = "FontSelDialog|GtkWindow::type"; +static gchar *Position = "FontSelDialog|GtkWindow::window_position"; +static gchar *Modal = "FontSelDialog|GtkWindow::modal"; +static gchar *DefaultWidth = "FontSel|GtkWindow::default_width"; +static gchar *DefaultHeight = "FontSel|GtkWindow::default_height"; +static gchar *Shrink = "FontSelDialog|GtkWindow::allow_shrink"; +static gchar *Grow = "FontSelDialog|GtkWindow::allow_grow"; +static gchar *AutoShrink = "FontSelDialog|GtkWindow::auto_shrink"; +static gchar *IconName = "FontSelDialog|GtkWindow::icon_name"; +static gchar *FocusOnMap = "FontSelDialog|GtkWindow::focus_on_map"; + +static gchar *Resizable = "FontSelDialog|GtkWindow::resizable"; +static gchar *DestroyWithParent = "FontSelDialog|GtkWindow::destroy_with_parent"; +static gchar *Icon = "FontSelDialog|GtkWindow::icon"; + +static gchar *Role = "FontSelDialog|GtkWindow::role"; +static gchar *TypeHint = "FontSelDialog|GtkWindow::type_hint"; +static gchar *SkipTaskbar = "FontSelDialog|GtkWindow::skip_taskbar_hint"; +static gchar *SkipPager = "FontSelDialog|GtkWindow::skip_pager_hint"; +static gchar *Decorated = "FontSelDialog|GtkWindow::decorated"; +static gchar *Gravity = "FontSelDialog|GtkWindow::gravity"; +static gchar *Urgency = "FontSelDialog|GtkWindow::urgency_hint"; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the funtion in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFontSelectionDialog, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_font_selection_dialog_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget = gtk_font_selection_dialog_new (_("Select Font")); + + GtkFontSelectionDialog *fontsel = GTK_FONT_SELECTION_DIALOG (new_widget); + + /* We want it to be treated as a normal window. */ + gtk_window_set_type_hint (GTK_WINDOW (new_widget), + GDK_WINDOW_TYPE_HINT_NORMAL); + + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + gb_widget_create_from (fontsel->ok_button, + data->action == GB_CREATING ? "ok_button" : NULL); + gb_widget_set_child_name (fontsel->ok_button, GladeChildOKButton); + + gb_widget_create_from (fontsel->cancel_button, + data->action == GB_CREATING ? "cancel_button" : NULL); + gb_widget_set_child_name (fontsel->cancel_button, GladeChildCancelButton); + + gb_widget_create_from (fontsel->apply_button, + data->action == GB_CREATING ? "apply_button" : NULL); + gb_widget_set_child_name (fontsel->apply_button, GladeChildApplyButton); + + gb_widget_create_from (fontsel->fontsel, + data->action == GB_CREATING ? "font_selection" : NULL); + gb_widget_set_child_name (fontsel->fontsel, GladeChildFontSelection); + + gtk_object_set_data (GTK_OBJECT (new_widget), TypeHint, + GINT_TO_POINTER (GLADE_TYPE_HINT_DIALOG_INDEX)); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_font_selection_dialog_create_properties (GtkWidget * widget, + GbWidgetCreateArgData * data) +{ + gb_window_create_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_font_selection_dialog_get_properties (GtkWidget *widget, + GbWidgetGetArgData * data) +{ + gb_window_get_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_font_selection_dialog_set_properties (GtkWidget * widget, + GbWidgetSetArgData * data) +{ + gb_window_set_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFontSelectionDialog, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_font_selection_dialog_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_font_selection_dialog_write_source (GtkWidget * widget, + GbWidgetWriteSourceData * data) +{ + gchar *wname, *child_name; + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + glade_util_get_translation_properties (widget, Title, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, " %s = gtk_font_selection_dialog_new (%s);\n", + data->wname, + source_make_string_full (GTK_WINDOW (widget)->title, + data->use_gettext && translatable, + context)); + } + + gb_widget_write_standard_source (widget, data); + + /* The title is already set above, so we pass NULL to skip it. */ + gb_window_write_standard_source (widget, data, + NULL, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + + + /* We output the source code for the buttons here, but we don't want them + to be created. We need to remember the dialog's name since data->wname + will be overwritten. */ + wname = g_strdup (data->wname); + + source_add (data, "\n"); + + child_name = (gchar*) gtk_widget_get_name (GTK_FONT_SELECTION_DIALOG (widget)->ok_button); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_FONT_SELECTION_DIALOG (%s)->ok_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_FONT_SELECTION_DIALOG (widget)->ok_button, + data); + + child_name = (gchar*) gtk_widget_get_name (GTK_FONT_SELECTION_DIALOG (widget)->cancel_button); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_FONT_SELECTION_DIALOG (%s)->cancel_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_FONT_SELECTION_DIALOG (widget)->cancel_button, + data); + + child_name = (gchar*) gtk_widget_get_name (GTK_FONT_SELECTION_DIALOG (widget)->apply_button); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_FONT_SELECTION_DIALOG (%s)->apply_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_FONT_SELECTION_DIALOG (widget)->apply_button, + data); + + child_name = (gchar*) gtk_widget_get_name (GTK_FONT_SELECTION_DIALOG (widget)->fontsel); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_FONT_SELECTION_DIALOG (%s)->fontsel;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_FONT_SELECTION_DIALOG (widget)->fontsel, + data); + + g_free (wname); + + data->write_children = FALSE; +} + + +static GtkWidget * +gb_font_selection_dialog_get_child (GtkWidget * widget, + const gchar * child_name) +{ + if (!strcmp (child_name, GladeChildOKButton)) + return GTK_FONT_SELECTION_DIALOG (widget)->ok_button; + else if (!strcmp (child_name, GladeChildApplyButton)) + return GTK_FONT_SELECTION_DIALOG (widget)->apply_button; + else if (!strcmp (child_name, GladeChildCancelButton)) + return GTK_FONT_SELECTION_DIALOG (widget)->cancel_button; + else if (!strcmp (child_name, GladeChildFontSelection)) + return GTK_FONT_SELECTION_DIALOG (widget)->fontsel; + else + return NULL; +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_font_selection_dialog_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_font_selection_dialog_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = fontseldialog_xpm; + gbwidget.tooltip = _("Font Selection Dialog"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_font_selection_dialog_new; + gbwidget.gb_widget_create_properties = gb_font_selection_dialog_create_properties; + gbwidget.gb_widget_get_properties = gb_font_selection_dialog_get_properties; + gbwidget.gb_widget_set_properties = gb_font_selection_dialog_set_properties; + gbwidget.gb_widget_get_child = gb_font_selection_dialog_get_child; + gbwidget.gb_widget_write_source = gb_font_selection_dialog_write_source; + gbwidget.gb_widget_destroy = gb_window_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_font_selection_dialog_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbframe.c b/tools/glade/glade/gbwidgets/gbframe.c new file mode 100644 index 00000000..39f9a55e --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbframe.c @@ -0,0 +1,375 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "../gb.h" +#include <math.h> +#include <gtk/gtkalignment.h> +#include <gtk/gtkframe.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmenuitem.h> + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/frame.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *LabelXAlign = "GtkFrame::label_xalign"; +static gchar *LabelYAlign = "GtkFrame::label_yalign"; +static gchar *Shadow = "GtkFrame::shadow_type"; + +/* We don't show this any more, as the label is a child widget now, but we + load this for compatability with old XML files. */ +static gchar *Label = "GtkFrame::label"; + +static const gchar *GbShadowChoices[] = +{"None", "In", "Out", + "Etched In", "Etched Out", NULL}; +static const gint GbShadowValues[] = +{ + GTK_SHADOW_NONE, + GTK_SHADOW_IN, + GTK_SHADOW_OUT, + GTK_SHADOW_ETCHED_IN, + GTK_SHADOW_ETCHED_OUT +}; +static const gchar *GbShadowSymbols[] = +{ + "GTK_SHADOW_NONE", + "GTK_SHADOW_IN", + "GTK_SHADOW_OUT", + "GTK_SHADOW_ETCHED_IN", + "GTK_SHADOW_ETCHED_OUT" +}; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkFrame, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_frame_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_frame_new (NULL); + + if (data->action != GB_LOADING) + { + GtkWidget *label, *alignment; + gchar *label_markup; + + /* For HIG compliance, we create a frame with no shadow, with a label + of "<b>widget-name</b>", and with an alignment to add 12 pixels + padding on the left. */ + gtk_frame_set_shadow_type (GTK_FRAME (new_widget), GTK_SHADOW_NONE); + + label = gb_widget_new ("GtkLabel", NULL); + label_markup = g_strdup_printf ("<b>%s</b>", data->name); + gtk_label_set_markup (GTK_LABEL (label), label_markup); + g_free (label_markup); + gtk_object_set_data (GTK_OBJECT (label), "GtkLabel::use_markup", + GINT_TO_POINTER (TRUE)); + + gtk_frame_set_label_widget (GTK_FRAME (new_widget), label); + + alignment = gb_widget_new ("GtkAlignment", NULL); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0); + + gtk_container_add (GTK_CONTAINER (new_widget), alignment); + } + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_frame_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_float_range (LabelXAlign, _("Label X Align:"), + _("The horizontal alignment of the frame's label widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (LabelYAlign, _("Label Y Align:"), + _("The vertical alignment of the frame's label widget"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_choice (Shadow, _("Shadow:"), _("The type of shadow of the frame"), + GbShadowChoices); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_frame_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + gb_widget_output_float (data, LabelXAlign, GTK_FRAME (widget)->label_xalign); + gb_widget_output_float (data, LabelYAlign, GTK_FRAME (widget)->label_yalign); + + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) + { + if (GbShadowValues[i] == GTK_FRAME (widget)->shadow_type) + gb_widget_output_choice (data, Shadow, i, GbShadowSymbols[i]); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_frame_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gfloat label_xalign, label_yalign; + gboolean apply_xalign, apply_yalign; + gchar *shadow; + gint i; + + /* We load the 'label' property, but create a child GbWidget. */ + if (data->action == GB_LOADING) + { + gchar *label = gb_widget_input_string (data, Label); + if (data->apply && label && *label) + { + GtkWidget *label_widget = gb_widget_new ("GtkLabel", NULL); + gtk_label_set_text (GTK_LABEL (label_widget), label); + gtk_frame_set_label_widget (GTK_FRAME (widget), label_widget); + } + } + + shadow = gb_widget_input_choice (data, Shadow); + if (data->apply) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (!strcmp (shadow, GbShadowChoices[i]) + || !strcmp (shadow, GbShadowSymbols[i])) + { + gtk_frame_set_shadow_type (GTK_FRAME (widget), GbShadowValues[i]); + break; + } + } + } + + label_xalign = gb_widget_input_float (data, LabelXAlign); + apply_xalign = data->apply; + if (!apply_xalign) + label_xalign = GTK_FRAME (widget)->label_xalign; + + label_yalign = gb_widget_input_float (data, LabelYAlign); + apply_yalign = data->apply; + if (!apply_yalign) + label_yalign = GTK_FRAME (widget)->label_yalign; + + if (apply_xalign || apply_yalign) + gtk_frame_set_label_align (GTK_FRAME (widget), label_xalign, label_yalign); +} + + + +static void +gb_frame_add_label_widget (GtkWidget * menuitem, GtkFrame * frame) +{ + gtk_frame_set_label_widget (frame, editor_new_placeholder ()); +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkFrame, with signals pointing to + * other functions in this file. + */ +void +gb_frame_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) +{ + GtkWidget *menuitem; + + /* If there is no label widget at present, we add a command to add one. */ + if (!gtk_frame_get_label_widget (GTK_FRAME (widget))) + { + menuitem = gtk_menu_item_new_with_label (_("Add Label Widget")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_frame_add_label_widget), widget); + } +} + + +void +gb_frame_add_child (GtkWidget *widget, GtkWidget *child, GbWidgetSetArgData *data) +{ + gboolean is_label_item = FALSE; + + /* See if this is a tab widget. We use a special "type" packing property set + to "label_item".*/ + if (data->child_info) + { + int j; + + for (j = 0; j < data->child_info->n_properties; j++) + { + if (!strcmp (data->child_info->properties[j].name, "type") + && !strcmp (data->child_info->properties[j].value, "label_item")) + { + is_label_item = TRUE; + break; + } + } + } + + if (is_label_item) + gtk_frame_set_label_widget (GTK_FRAME (widget), child); + else + gtk_container_add (GTK_CONTAINER (widget), child); +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_frame_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gfloat xalign, yalign; + gint shadow = 0, i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_frame_new (NULL);\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + xalign = GTK_FRAME (widget)->label_xalign; + yalign = GTK_FRAME (widget)->label_yalign; + if (xalign >= GLADE_EPSILON || fabs (yalign - 0.5) >= GLADE_EPSILON) + { + source_add (data, + " gtk_frame_set_label_align (GTK_FRAME (%s), %g, %g);\n", + data->wname, xalign, yalign); + } + + if (GTK_FRAME (widget)->shadow_type != GTK_SHADOW_ETCHED_IN) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + if (GbShadowValues[i] == GTK_FRAME (widget)->shadow_type) + { + shadow = i; + break; + } + source_add (data, " gtk_frame_set_shadow_type (GTK_FRAME (%s), %s);\n", + data->wname, GbShadowSymbols[shadow]); + } +} + + +void +gb_frame_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + + /* When saving the label widget, we save a "type" packing property set to + "label_item". */ + if (data->action != GB_SAVING + || gtk_frame_get_label_widget (GTK_FRAME (widget)) != child) + return; + + save_start_tag (data, "packing"); + save_string (data, "type", "label_item"); + save_end_tag (data, "packing"); +} + + +/* Outputs source to add a child widget to a GtkNotebook. */ +void +gb_frame_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + + if (gtk_frame_get_label_widget (GTK_FRAME (parent)) == child) + { + source_add (data, + " gtk_frame_set_label_widget (GTK_FRAME (%s), %s);\n", + parent_name, data->wname); + } + else + { + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_frame_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_frame_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = frame_xpm; + gbwidget.tooltip = _("Frame"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_frame_new; + gbwidget.gb_widget_create_properties = gb_frame_create_properties; + gbwidget.gb_widget_get_properties = gb_frame_get_properties; + gbwidget.gb_widget_set_properties = gb_frame_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_frame_create_popup_menu; + gbwidget.gb_widget_write_source = gb_frame_write_source; + + gbwidget.gb_widget_add_child = gb_frame_add_child; + gbwidget.gb_widget_get_child_properties = gb_frame_get_child_properties; + gbwidget.gb_widget_write_add_child_source = gb_frame_write_add_child_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbgammacurve.c b/tools/glade/glade/gbwidgets/gbgammacurve.c new file mode 100644 index 00000000..ac6a4c25 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbgammacurve.c @@ -0,0 +1,269 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkcurve.h> +#include <gtk/gtkgamma.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/gammacurve.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +#if 0 +static gchar *Type = "GammaCurve|GtkCurve::curve_type"; +#endif +static gchar *XMin = "GammaCurve|GtkCurve::min_x"; +static gchar *XMax = "GammaCurve|GtkCurve::max_x"; +static gchar *YMin = "GammaCurve|GtkCurve::min_y"; +static gchar *YMax = "GammaCurve|GtkCurve::max_y"; + +#if 0 +static const gchar *GbTypeChoices[] = +{"Linear", "Spline", "Free", NULL}; +static const gint GbTypeValues[] = +{ + GTK_CURVE_TYPE_LINEAR, /* linear interpolation */ + GTK_CURVE_TYPE_SPLINE, /* spline interpolation */ + GTK_CURVE_TYPE_FREE /* free form curve */ +}; +static const gchar *GbTypeSymbols[] = +{ + "GTK_CURVE_TYPE_LINEAR", + "GTK_CURVE_TYPE_SPLINE", + "GTK_CURVE_TYPE_FREE" +}; +#endif + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkGammaCurve, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +/* + GtkWidget* + gb_gamma_curve_new(GbWidgetNewData *data) + { + + } + */ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_gamma_curve_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ +#if 0 + property_add_choice (Type, _("Initial Type:"), _("The initial type of the curve"), + GbTypeChoices); +#endif + property_add_float (XMin, _("X Min:"), _("The minimum horizontal value")); + property_add_float (XMax, _("X Max:"), _("The maximum horizontal value")); + property_add_float (YMin, _("Y Min:"), _("The minimum vertical value")); + property_add_float (YMax, _("Y Max:"), _("The maximum vertical value")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_gamma_curve_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + GtkCurve *curve = GTK_CURVE (GTK_GAMMA_CURVE (widget)->curve); + +#if 0 + gint i; + + for (i = 0; i < sizeof (GbTypeValues) / sizeof (GbTypeValues[0]); i++) + { + if (GbTypeValues[i] == curve->curve_type) + gb_widget_output_choice (data, Type, i, GbTypeSymbols[i]); + } +#endif + gb_widget_output_float (data, XMin, curve->min_x); + gb_widget_output_float (data, XMax, curve->max_x); + gb_widget_output_float (data, YMin, curve->min_y); + gb_widget_output_float (data, YMax, curve->max_y); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_gamma_curve_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + GtkCurve *curve = GTK_CURVE (GTK_GAMMA_CURVE (widget)->curve); + gfloat min_x, max_x, min_y, max_y; + gboolean set_range = FALSE; + +#if 0 + gint i; + gchar *type; + + type = gb_widget_input_choice (data, Type); + if (data->apply) + { + for (i = 0; i < sizeof (GbTypeValues) / sizeof (GbTypeValues[0]); i++) + { + if (!strcmp (type, GbTypeChoices[i]) + || !strcmp (type, GbTypeSymbols[i])) + { + gtk_curve_set_curve_type (curve, GbTypeValues[i]); + break; + } + } + } +#endif + + min_x = gb_widget_input_float (data, XMin); + if (data->apply) + set_range = TRUE; + else + min_x = GTK_CURVE (widget)->min_x; + + max_x = gb_widget_input_float (data, XMax); + if (data->apply) + set_range = TRUE; + else + max_x = GTK_CURVE (widget)->max_x; + + min_y = gb_widget_input_float (data, YMin); + if (data->apply) + set_range = TRUE; + else + min_y = GTK_CURVE (widget)->min_y; + + max_y = gb_widget_input_float (data, YMax); + if (data->apply) + set_range = TRUE; + else + max_y = GTK_CURVE (widget)->max_y; + + if (set_range) + gtk_curve_set_range (curve, min_x, max_x, min_y, max_y); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkGammaCurve, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_gamma_curve_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_gamma_curve_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkCurve *curve = GTK_CURVE (GTK_GAMMA_CURVE (widget)->curve); +#if 0 + gint i; +#endif + + if (data->create_widget) + { + source_add (data, " %s = gtk_gamma_curve_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + +#if 0 + if (curve->curve_type != GTK_CURVE_TYPE_SPLINE) + { + for (i = 0; i < sizeof (GbTypeValues) / sizeof (GbTypeValues[0]); i++) + { + if (GbTypeValues[i] == curve->curve_type) + source_add (data, " gtk_curve_set_curve_type (GTK_CURVE (GTK_GAMMA_CURVE (%s)->curve), %s);\n", + data->wname, GbTypeSymbols[i]); + } + } +#endif + + source_add (data, " gtk_curve_set_range (GTK_CURVE (GTK_GAMMA_CURVE (%s)->curve), %g, %g, %g, %g);\n", + data->wname, curve->min_x, curve->max_x, + curve->min_y, curve->max_y); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_gamma_curve_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_gamma_curve_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = gammacurve_xpm; + gbwidget.tooltip = _("Gamma Curve"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_gamma_curve_create_properties; + gbwidget.gb_widget_get_properties = gb_gamma_curve_get_properties; + gbwidget.gb_widget_set_properties = gb_gamma_curve_set_properties; + gbwidget.gb_widget_write_source = gb_gamma_curve_write_source; +/* + gbwidget.gb_widget_new = gb_gamma_curve_new; + gbwidget.gb_widget_create_popup_menu = gb_gamma_curve_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhandlebox.c b/tools/glade/glade/gbwidgets/gbhandlebox.c new file mode 100644 index 00000000..fb9b2e21 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhandlebox.c @@ -0,0 +1,317 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhandlebox.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/handlebox.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Shadow = "GtkHandleBox::shadow_type"; +static gchar *Position = "GtkHandleBox::handle_position"; +static gchar *SnapEdge = "GtkHandleBox::snap_edge"; + + +static const gchar *GbShadowChoices[] = +{"None", "In", "Out", + "Etched In", "Etched Out", NULL}; +static const gint GbShadowValues[] = +{ + GTK_SHADOW_NONE, + GTK_SHADOW_IN, + GTK_SHADOW_OUT, + GTK_SHADOW_ETCHED_IN, + GTK_SHADOW_ETCHED_OUT +}; +static const gchar *GbShadowSymbols[] = +{ + "GTK_SHADOW_NONE", + "GTK_SHADOW_IN", + "GTK_SHADOW_OUT", + "GTK_SHADOW_ETCHED_IN", + "GTK_SHADOW_ETCHED_OUT" +}; + +static const gchar *GbPositionChoices[] = +{"Left", "Right", "Top", "Bottom", NULL}; +static const gint GbPositionValues[] = +{ + GTK_POS_LEFT, + GTK_POS_RIGHT, + GTK_POS_TOP, + GTK_POS_BOTTOM +}; +static const gchar *GbPositionSymbols[] = +{ + "GTK_POS_LEFT", + "GTK_POS_RIGHT", + "GTK_POS_TOP", + "GTK_POS_BOTTOM" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHandleBox, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_handle_box_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_handle_box_new (); + + /* We set the snap edge to top, which matches the default handle position, + since we don't support the default value of -1. */ + gtk_handle_box_set_snap_edge (GTK_HANDLE_BOX (new_widget), GTK_POS_TOP); + + if (data->action != GB_LOADING) + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_handle_box_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) +{ + property_add_choice (Shadow, _("Shadow:"), + _("The type of shadow around the handle box"), + GbShadowChoices); + + property_add_choice (Position, _("Handle Pos:"), + _("The position of the handle"), + GbPositionChoices); + property_add_choice (SnapEdge, _("Snap Edge:"), + _("The edge of the handle box which snaps into position"), + GbPositionChoices); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_handle_box_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) +{ + gint i; + + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) + { + if (GbShadowValues[i] == GTK_HANDLE_BOX (widget)->shadow_type) + gb_widget_output_choice (data, Shadow, i, GbShadowSymbols[i]); + } + + for (i = 0; i < sizeof (GbPositionValues) / sizeof (GbPositionValues[0]); + i++) + { + if (GbPositionValues[i] == GTK_HANDLE_BOX (widget)->handle_position) + gb_widget_output_choice (data, Position, i, GbPositionSymbols[i]); + } + + for (i = 0; i < sizeof (GbPositionValues) / sizeof (GbPositionValues[0]); + i++) + { + if (GbPositionValues[i] == GTK_HANDLE_BOX (widget)->snap_edge) + gb_widget_output_choice (data, SnapEdge, i, GbPositionSymbols[i]); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_handle_box_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) +{ + gchar *shadow, *position, *snap_edge; + gint i; + + shadow = gb_widget_input_choice (data, Shadow); + if (data->apply) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); + i++) + { + if (!strcmp (shadow, GbShadowChoices[i]) + || !strcmp (shadow, GbShadowSymbols[i])) + { + gtk_handle_box_set_shadow_type (GTK_HANDLE_BOX (widget), + GbShadowValues[i]); + break; + } + } + } + + position = gb_widget_input_choice (data, Position); + if (data->apply) + { + for (i = 0; i < sizeof (GbPositionValues) / sizeof (GbPositionValues[0]); + i++) + { + if (!strcmp (position, GbPositionChoices[i]) + || !strcmp (position, GbPositionSymbols[i])) + { + gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (widget), + GbPositionValues[i]); + break; + } + } + } + + snap_edge = gb_widget_input_choice (data, SnapEdge); + if (data->apply) + { + for (i = 0; i < sizeof (GbPositionValues) / sizeof (GbPositionValues[0]); + i++) + { + if (!strcmp (snap_edge, GbPositionChoices[i]) + || !strcmp (snap_edge, GbPositionSymbols[i])) + { + gtk_handle_box_set_snap_edge (GTK_HANDLE_BOX (widget), + GbPositionValues[i]); + break; + } + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHandleBox, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_handle_box_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_handle_box_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_handle_box_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + if (GTK_HANDLE_BOX (widget)->shadow_type != GTK_SHADOW_OUT) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); + i++) + if (GbShadowValues[i] == GTK_HANDLE_BOX (widget)->shadow_type) + { + source_add (data, + " gtk_handle_box_set_shadow_type (GTK_HANDLE_BOX (%s), %s);\n", + data->wname, GbShadowSymbols[i]); + break; + } + } + + if (GTK_HANDLE_BOX (widget)->handle_position != GTK_POS_LEFT) + { + for (i = 0; i < sizeof (GbPositionValues) / sizeof (GbPositionValues[0]); + i++) + { + if (GbPositionValues[i] == GTK_HANDLE_BOX (widget)->handle_position) + source_add (data, + " gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (%s), %s);\n", + data->wname, GbPositionSymbols[i]); + } + } + + if (GTK_HANDLE_BOX (widget)->snap_edge != GTK_POS_TOP) + { + for (i = 0; i < sizeof (GbPositionValues) / sizeof (GbPositionValues[0]); + i++) + { + if (GbPositionValues[i] == GTK_HANDLE_BOX (widget)->snap_edge) + source_add (data, + " gtk_handle_box_set_snap_edge (GTK_HANDLE_BOX (%s), %s);\n", + data->wname, GbPositionSymbols[i]); + } + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_handle_box_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_handle_box_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = handlebox_xpm; + gbwidget.tooltip = _("Handle Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_handle_box_new; + gbwidget.gb_widget_create_properties = gb_handle_box_create_properties; + gbwidget.gb_widget_get_properties = gb_handle_box_get_properties; + gbwidget.gb_widget_set_properties = gb_handle_box_set_properties; +/* + gbwidget.gb_widget_create_popup_menu = gb_handle_box_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_handle_box_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhbox.c b/tools/glade/glade/gbwidgets/gbhbox.c new file mode 100644 index 00000000..2205824d --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhbox.c @@ -0,0 +1,587 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkbbox.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkspinbutton.h> +#include "../gb.h" +#include "../tree.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/hbox.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +/* Size is not saved to the XML. */ +static const gchar *Size = "HBox|GtkBox::size"; +static const gchar *Homogeneous = "HBox|GtkBox::homogeneous"; +static const gchar *Spacing = "HBox|GtkBox::spacing"; + +/* For children of a box */ +static const gchar *GbPadding = "GtkBoxChild::padding"; +static const gchar *GbExpand = "GtkBoxChild::expand"; +static const gchar *GbFill = "GtkBoxChild::fill"; +static const gchar *GbPack = "GtkBoxChild::pack_type"; + +/* This is only used internally - it isn't save in the XML. */ +static const gchar *GbPosition = "GtkBoxChild::position"; + + +static void show_hbox_dialog (GbWidgetNewData * data); +static void on_hbox_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_hbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); + +static void gb_box_insert_before (GtkWidget * menuitem, GtkWidget * child); +static void gb_box_insert_after (GtkWidget * menuitem, GtkWidget * child); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHBox, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_hbox_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_LOADING) + { + new_widget = gtk_hbox_new (FALSE, 0); + return new_widget; + } + else + { + show_hbox_dialog (data); + return NULL; + } +} + + +static void +show_hbox_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New horizontal box"), data->parent, + GTK_SIGNAL_FUNC (on_hbox_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_hbox_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of columns:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "cols", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_hbox_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *window, *placeholder; + gint cols, i; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "cols"); + g_return_if_fail (spinbutton != NULL); + cols = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_hbox_new (FALSE, 0); + for (i = 0; i < cols; i++) + { + placeholder = editor_new_placeholder (); + /*gtk_widget_set_usize(placeholder, 60, 80); */ + gtk_box_pack_start (GTK_BOX (new_widget), placeholder, TRUE, TRUE, 0); + } + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (window); +} + + +static void +on_hbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_hbox_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_int_range (Size, _("Size:"), _("The number of widgets in the box"), + 0, 1000, 1, 10, 1); + property_add_bool (Homogeneous, _("Homogeneous:"), + _("If the children should be the same size")); + property_add_int_range (Spacing, _("Spacing:"), _("The space between each child"), + 0, 1000, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_hbox_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + if (data->action != GB_SAVING) + gb_widget_output_int (data, Size, g_list_length (GTK_BOX (widget)->children)); + gb_widget_output_bool (data, Homogeneous, GTK_BOX (widget)->homogeneous); + gb_widget_output_int (data, Spacing, GTK_BOX (widget)->spacing); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_hbox_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean homogeneous; + gint spacing, size; + + if (data->action != GB_LOADING) + { + size = gb_widget_input_int (data, Size); + if (data->apply) + gb_box_set_size (widget, size); + } + + homogeneous = gb_widget_input_bool (data, Homogeneous); + if (data->apply) + gtk_box_set_homogeneous (GTK_BOX (widget), homogeneous); + + spacing = gb_widget_input_int (data, Spacing); + if (data->apply) + gtk_box_set_spacing (GTK_BOX (widget), spacing); +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_hbox_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_hbox_new (%s, %i);\n", data->wname, + GTK_BOX (widget)->homogeneous ? "TRUE" : "FALSE", + GTK_BOX (widget)->spacing); + } + + gb_widget_write_standard_source (widget, data); +} + + +/* + * Functions common to GtkHBox & GtkVBox (and possibly GtkHButtonBox + * & GtkVButtonBox). + */ + + +/* This updates the box size to the given value, adding placeholders or + deleting widgets as necessary. */ +void +gb_box_set_size (GtkWidget * widget, gint size) +{ + GtkWidget *new_child; + gint current_size = g_list_length (GTK_BOX (widget)->children); + gint i; + + if (current_size < size) + { + /* This avoids any problems with redrawing the selection. */ + editor_clear_selection (NULL); + + for (i = 0; i < size - current_size; i++) + { + if (GTK_IS_BUTTON_BOX (widget)) + { + new_child = gb_widget_new ("GtkButton", widget); + GTK_WIDGET_SET_FLAGS (new_child, GTK_CAN_DEFAULT); + gtk_box_pack_start (GTK_BOX (widget), new_child, TRUE, TRUE, 0); + tree_add_widget (new_child); + } + else + { + new_child = editor_new_placeholder (); + gtk_box_pack_start (GTK_BOX (widget), new_child, TRUE, TRUE, 0); + } + } + } + else if (current_size > size) + { + GList *children, *elem; + GtkWidget *child; + gchar *error = NULL; + + /* Get a list of children in the order they appear in the box, start at + the end and move backwards until we find a widget that can be + destroyed. If we can't find any, show a message box. */ + children = gtk_container_get_children (GTK_CONTAINER (widget)); + elem = g_list_last (children); + + while (elem) + { + child = elem->data; + error = editor_can_delete_widget (child); + if (!error) + { + gtk_container_remove (GTK_CONTAINER (widget), child); + current_size--; + if (current_size == size) + break; + } + elem = elem->prev; + } + + g_list_free (children); + + /* If we show an error dialog it causes weird problems with the + spinbutton used to change the size. So we don't do this. */ +#if 0 + if (current_size > size) + { + glade_util_show_message_box (error ? error + : _("Can't delete any children."), + widget); + } +#endif + } +} + + +/* + * Creates the child packing properties for children of this widget. + */ +void +gb_box_create_child_properties (GtkWidget * widget, + GbWidgetCreateChildArgData * data) +{ + property_add_int_range (GbPosition, _("Position:"), + _("The widget's position relative to its siblings"), + 0, 10000, 1, 10, 1); + property_add_int_range (GbPadding, _("Padding:"), + _("The widget's padding"), + 0, 10000, 1, 10, 1); + property_add_bool (GbExpand, _("Expand:"), + _("Set True to let the widget expand")); + property_add_bool (GbFill, _("Fill:"), + _("Set True to let the widget fill its allocated area")); + property_add_bool (GbPack, _("Pack Start:"), + _("Set True to pack the widget at the start of the box")); +} + + +void +gb_box_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + gboolean expand, fill; + gint position; + guint padding; + GtkPackType pack_type; + + if (data->action == GB_SAVING) + save_start_tag (data, "packing"); + + if (data->action == GB_SHOWING) + { + position = glade_util_get_box_pos (GTK_BOX (widget), child); + gb_widget_output_int (data, GbPosition, position); + } + + gtk_box_query_child_packing (GTK_BOX (widget), child, + &expand, &fill, &padding, &pack_type); + gb_widget_output_int (data, GbPadding, padding); + gb_widget_output_bool (data, GbExpand, expand); + gb_widget_output_bool (data, GbFill, fill); + + if (data->action == GB_SAVING) + { + /* Save pack type as an enum symbol rather than a bool */ + if (pack_type == GTK_PACK_END) + { + gb_widget_output_string (data, GbPack, "GTK_PACK_END"); + } + } + else + { + gb_widget_output_bool (data, GbPack, pack_type == GTK_PACK_START); + } + + if (data->action == GB_SAVING) + save_end_tag (data, "packing"); +} + + +/* Applies or loads the child properties of a child of a hbox/vbox. */ +void +gb_box_set_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + gint position, padding; + guint old_padding; + gboolean expand, fill, pack, set_child_packing = FALSE; + gboolean old_expand, old_fill; + GtkPackType old_pack_type; + + position = gb_widget_input_int (data, GbPosition); + if (data->apply) + { + gtk_box_reorder_child (GTK_BOX (widget), child, position); + } + + gtk_box_query_child_packing (GTK_BOX (widget), child, + &old_expand, &old_fill, &old_padding, + &old_pack_type); + + padding = gb_widget_input_int (data, GbPadding); + if (data->apply) + set_child_packing = TRUE; + else + padding = old_padding; + + expand = gb_widget_input_bool (data, GbExpand); + if (data->apply) + set_child_packing = TRUE; + else + expand = old_expand; + + fill = gb_widget_input_bool (data, GbFill); + if (data->apply) + set_child_packing = TRUE; + else + fill = old_fill; + + if (data->action == GB_APPLYING) + { + pack = gb_widget_input_bool (data, GbPack); + } + else + { + gchar *pack_symbol = gb_widget_input_string (data, GbPack); + pack = pack_symbol && !strcmp (pack_symbol, "GTK_PACK_START"); + } + if (data->apply) + set_child_packing = TRUE; + else + pack = (old_pack_type == GTK_PACK_START) ? TRUE : FALSE; + + if (set_child_packing) + gtk_box_set_child_packing (GTK_BOX (widget), child, expand, fill, padding, + pack ? GTK_PACK_START : GTK_PACK_END); +} + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHBox, with signals pointing to + * other functions in this file. + */ +void +gb_box_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + GtkWidget *menuitem; + + if (data->child == NULL) + return; + + menuitem = gtk_menu_item_new_with_label (_("Insert Before")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_box_insert_before), data->child); + + menuitem = gtk_menu_item_new_with_label (_("Insert After")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_box_insert_after), data->child); +} + + +static void +gb_box_insert_before (GtkWidget * menuitem, GtkWidget * child) +{ + GtkWidget *box, *newchild; + guint pos; + gboolean expand, fill; + guint padding; + GtkPackType pack_type; + + box = child->parent; + pos = glade_util_get_box_pos (GTK_BOX (box), child); + g_return_if_fail (pos != -1); + newchild = editor_new_placeholder (); + gtk_box_query_child_packing (GTK_BOX (box), child, + &expand, &fill, &padding, &pack_type); + if (pack_type == GTK_PACK_START) + { + gtk_box_pack_start (GTK_BOX (box), newchild, TRUE, TRUE, 0); + gtk_box_reorder_child (GTK_BOX (box), newchild, pos); + } + else + { + gtk_box_pack_end (GTK_BOX (box), newchild, TRUE, TRUE, 0); + gtk_box_reorder_child (GTK_BOX (box), newchild, pos + 1); + } +} + +static void +gb_box_insert_after (GtkWidget * menuitem, GtkWidget * child) +{ + GtkWidget *box, *newchild; + guint pos; + gboolean expand, fill; + guint padding; + GtkPackType pack_type; + + box = child->parent; + pos = glade_util_get_box_pos (GTK_BOX (box), child); + g_return_if_fail (pos != -1); + newchild = editor_new_placeholder (); + gtk_box_query_child_packing (GTK_BOX (box), child, + &expand, &fill, &padding, &pack_type); + if (pack_type == GTK_PACK_START) + { + gtk_box_pack_start (GTK_BOX (box), newchild, TRUE, TRUE, 0); + gtk_box_reorder_child (GTK_BOX (box), newchild, pos + 1); + } + else + { + gtk_box_pack_end (GTK_BOX (box), newchild, TRUE, TRUE, 0); + gtk_box_reorder_child (GTK_BOX (box), newchild, pos); + } +} + + +/* Outputs source to add a child widget to a hbox/vbox. */ +void +gb_box_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + gboolean expand, fill; + guint padding; + GtkPackType pack_type; + + gtk_box_query_child_packing (GTK_BOX (parent), child, + &expand, &fill, &padding, &pack_type); + if (pack_type == GTK_PACK_START) + { + source_add (data, + " gtk_box_pack_start (GTK_BOX (%s), %s, %s, %s, %i);\n", + parent_name, data->wname, + expand ? "TRUE" : "FALSE", fill ? "TRUE" : "FALSE", padding); + } + else + { + source_add (data, + " gtk_box_pack_end (GTK_BOX (%s), %s, %s, %s, %i);\n", + parent_name, data->wname, + expand ? "TRUE" : "FALSE", fill ? "TRUE" : "FALSE", padding); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_hbox_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_hbox_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = hbox_xpm; + gbwidget.tooltip = _("Horizontal Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_hbox_new; + gbwidget.gb_widget_create_properties = gb_hbox_create_properties; + gbwidget.gb_widget_get_properties = gb_hbox_get_properties; + gbwidget.gb_widget_set_properties = gb_hbox_set_properties; + gbwidget.gb_widget_write_source = gb_hbox_write_source; + + gbwidget.gb_widget_create_child_properties = gb_box_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_box_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_box_set_child_properties; + gbwidget.gb_widget_create_popup_menu = gb_box_create_popup_menu; + gbwidget.gb_widget_write_add_child_source = gb_box_write_add_child_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhbuttonbox.c b/tools/glade/glade/gbwidgets/gbhbuttonbox.c new file mode 100644 index 00000000..b64f9383 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhbuttonbox.c @@ -0,0 +1,428 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#ifdef USE_GNOME +#include <gnome.h> +#include "../glade_gnome.h" +#else +#include <gtk/gtkbutton.h> +#include <gtk/gtkhbbox.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkspinbutton.h> +#endif + +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/hbuttonbox.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Size = "HBBox|GtkBox::size"; +static gchar *Layout = "HBBox|GtkButtonBox::layout_style"; +static gchar *Spacing = "HBBox|GtkButtonBox::spacing"; + +static const gchar *GbLayoutChoices[] = +{"Default", "Spread", "Edge", + "Start", "End", NULL}; +static const gint GbLayoutValues[] = +{ + GTK_BUTTONBOX_DEFAULT_STYLE, + GTK_BUTTONBOX_SPREAD, + GTK_BUTTONBOX_EDGE, + GTK_BUTTONBOX_START, + GTK_BUTTONBOX_END +}; +static const gchar *GbLayoutSymbols[] = +{ + "GTK_BUTTONBOX_DEFAULT_STYLE", + "GTK_BUTTONBOX_SPREAD", + "GTK_BUTTONBOX_EDGE", + "GTK_BUTTONBOX_START", + "GTK_BUTTONBOX_END" +}; + + +/* FIXME: Hack - copied from gtkbbox.c. Should use GParam query instead, + or use an optional int property instead. */ +#define DEFAULT_CHILD_MIN_WIDTH 85 +#define DEFAULT_CHILD_MIN_HEIGHT 27 +#define DEFAULT_CHILD_IPAD_X 4 +#define DEFAULT_CHILD_IPAD_Y 0 + + +static void show_hbbox_dialog (GbWidgetNewData * data); +static void on_hbbox_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_hbbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHButtonBox, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_hbutton_box_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_LOADING) + { + new_widget = gtk_hbutton_box_new (); + return new_widget; + } + else + { + show_hbbox_dialog (data); + return NULL; + } +} + + +static void +show_hbbox_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New horizontal button box"), + data->parent, + GTK_SIGNAL_FUNC (on_hbbox_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_hbbox_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of columns:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "cols", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_hbbox_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *window, *new_child; + gint cols, i; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "cols"); + g_return_if_fail (spinbutton != NULL); + cols = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_hbutton_box_new (); + for (i = 0; i < cols; i++) + { + new_child = gb_widget_new ("GtkButton", new_widget); + GTK_WIDGET_SET_FLAGS (new_child, GTK_CAN_DEFAULT); + gtk_container_add (GTK_CONTAINER (new_widget), new_child); + } + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (window); +} + + +static void +on_hbbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_hbutton_box_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ + property_add_int_range (Size, _("Size:"), _("The number of buttons"), + 0, 1000, 1, 10, 1); + property_add_choice (Layout, _("Layout:"), + _("The layout style of the buttons"), + GbLayoutChoices); + property_add_int_range (Spacing, _("Spacing:"), _("The space between the buttons"), + 0, 1000, 1, 10, 1); +} + + + +static gboolean +gb_hbutton_box_is_dialog_action_area (GtkWidget *widget) +{ + char *child_name = gb_widget_get_child_name (widget); + if (child_name && !strcmp (child_name, GladeChildDialogActionArea)) + return TRUE; + return FALSE; +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_hbutton_box_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + GtkButtonBoxStyle layout; + gint i, spacing; + gboolean spacing_visible = FALSE; + + if (data->action != GB_SAVING) + gb_widget_output_int (data, Size, g_list_length (GTK_BOX (widget)->children)); + + layout = gtk_button_box_get_layout (GTK_BUTTON_BOX (widget)); + for (i = 0; i < sizeof (GbLayoutValues) / sizeof (GbLayoutValues[0]); i++) + { + if (GbLayoutValues[i] == layout) + gb_widget_output_choice (data, Layout, i, GbLayoutSymbols[i]); + } + + if (!gb_hbutton_box_is_dialog_action_area (widget)) + { + spacing_visible = TRUE; + spacing = gtk_box_get_spacing (GTK_BOX (widget)); + gb_widget_output_int (data, Spacing, spacing); + } + + if (data->action == GB_SHOWING) + { + property_set_visible (Spacing, spacing_visible); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_hbutton_box_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gint size, i, spacing; + gchar *layout; + gboolean queue_resize = FALSE; + + if (data->action != GB_LOADING) + { + size = gb_widget_input_int (data, Size); + if (data->apply) + gb_box_set_size (widget, size); + } + + layout = gb_widget_input_choice (data, Layout); + if (data->apply) + { + for (i = 0; i < sizeof (GbLayoutValues) / sizeof (GbLayoutValues[0]); + i++) + { + if (!strcmp (layout, GbLayoutChoices[i]) + || !strcmp (layout, GbLayoutSymbols[i])) + { + gtk_button_box_set_layout (GTK_BUTTON_BOX (widget), GbLayoutValues + [i]); + queue_resize = TRUE; + break; + } + } + } + + if (!gb_hbutton_box_is_dialog_action_area (widget)) + { + spacing = gb_widget_input_int (data, Spacing); + if (data->apply) + { + gtk_box_set_spacing (GTK_BOX (widget), spacing); + queue_resize = TRUE; + } + } + + if (queue_resize) + gtk_widget_queue_resize (widget); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHButtonBox, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_hbutton_box_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_hbutton_box_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkButtonBoxStyle layout_style; + gint spacing, i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_hbutton_box_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + layout_style = GTK_BUTTON_BOX (widget)->layout_style; + if (layout_style != GTK_BUTTONBOX_DEFAULT_STYLE) + { + for (i = 0; i < sizeof (GbLayoutValues) / sizeof (GbLayoutValues[0]); i + ++) + { + if (GbLayoutValues[i] == layout_style) + source_add (data, + " gtk_button_box_set_layout (GTK_BUTTON_BOX (%s), %s);\n", + data->wname, GbLayoutSymbols[i]); + } + } + + if (!gb_hbutton_box_is_dialog_action_area (widget)) + { + spacing = gtk_box_get_spacing (GTK_BOX (widget)); + if (spacing != 0) + { + source_add (data, + " gtk_box_set_spacing (GTK_BOX (%s), %i);\n", + data->wname, spacing); + } + } +} + + +/* Outputs source to add a child widget to a hbuttonbox. We need to check if + the hbuttonbox is a GtkDialog action area, and if it is we use the special + gtk_dialog_add_action_widget() function to add it. */ +void +gb_hbutton_box_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + if (gb_hbutton_box_is_dialog_action_area (parent) + && G_OBJECT_TYPE (child) == GTK_TYPE_BUTTON) + { + gint response_id; + char *response_name, *dialog_name; + + response_id = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (child), GladeDialogResponseIDKey)); + response_name = gb_dialog_response_id_to_string (response_id); + + dialog_name = (char*) gtk_widget_get_name (parent->parent->parent); + dialog_name = source_create_valid_identifier (dialog_name); + + source_add (data, + " gtk_dialog_add_action_widget (GTK_DIALOG (%s), %s, %s);\n", + dialog_name, data->wname, response_name); + + g_free (dialog_name); + } + else + { + /* Use the standard gtk_container_add(). */ + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_hbutton_box_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_hbutton_box_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = hbuttonbox_xpm; + gbwidget.tooltip = _("Horizontal Button Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_hbutton_box_new; + gbwidget.gb_widget_create_properties = gb_hbutton_box_create_properties; + gbwidget.gb_widget_get_properties = gb_hbutton_box_get_properties; + gbwidget.gb_widget_set_properties = gb_hbutton_box_set_properties; + gbwidget.gb_widget_write_source = gb_hbutton_box_write_source; + gbwidget.gb_widget_write_add_child_source = gb_hbutton_box_write_add_child_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_hbutton_box_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhpaned.c b/tools/glade/glade/gbwidgets/gbhpaned.c new file mode 100644 index 00000000..c8438dcf --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhpaned.c @@ -0,0 +1,332 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhpaned.h> +#include <gtk/gtktogglebutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/hpaned.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Position = "HPaned|GtkPaned::position"; + +/* For children of a paned */ +static const gchar *Shrink = "GtkPanedChild::shrink"; +static const gchar *Resize = "GtkPanedChild::resize"; + +static void on_toggle_position (GtkWidget * widget, gpointer value); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHPaned, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_hpaned_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_hpaned_new (); + if (data->action != GB_LOADING) + { + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + } + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_hpaned_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_optional_int_range (Position, _("Position:"), + _("The position of the divider"), + 1, 1000, 1, 10, 1, + on_toggle_position); +} + + +static void +on_toggle_position (GtkWidget * button, gpointer value) +{ + GtkWidget *widget; + gboolean value_set; + gint position; + + widget = property_get_widget (); + if (widget == NULL) + return; + + value_set = GTK_TOGGLE_BUTTON (button)->active ? TRUE : FALSE; + gtk_widget_set_sensitive (GTK_WIDGET (value), value_set); + + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + Position)); + gtk_paned_set_position (GTK_PANED (widget), + value_set ? position : -1); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_hpaned_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint position; + + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + Position)); + gb_widget_output_optional_int (data, Position, position, + GTK_PANED (widget)->position_set); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_hpaned_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gint position; + + position = gb_widget_input_int (data, Position); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), Position, + GINT_TO_POINTER (position)); + gtk_paned_set_position (GTK_PANED (widget), position); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHPaned, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_hpaned_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_hpaned_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint position; + + if (data->create_widget) + { + source_add (data, " %s = gtk_hpaned_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + if (GTK_PANED (widget)->position_set) + { + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + Position)); + source_add (data, " gtk_paned_set_position (GTK_PANED (%s), %d);\n", + data->wname, position); + } +} + + +/* + * Creates the child packing properties for children of this widget. + */ +void +gb_paned_create_child_properties (GtkWidget * widget, + GbWidgetCreateChildArgData * data) +{ + property_add_bool (Shrink, _("Shrink:"), + _("Set True to let the widget shrink")); + property_add_bool (Resize, _("Resize:"), + _("Set True to let the widget resize")); +} + + +void +gb_paned_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + gboolean shrink, resize; + + if (child == GTK_PANED (widget)->child1) + { + shrink = GTK_PANED (widget)->child1_shrink; + resize = GTK_PANED (widget)->child1_resize; + } + else if (child == GTK_PANED (widget)->child2) + { + shrink = GTK_PANED (widget)->child2_shrink; + resize = GTK_PANED (widget)->child2_resize; + } + else + { + /* This shouldn't happen. */ + g_warning ("Couldn't find child of GtkPaned container"); + return; + } + + if (data->action == GB_SAVING) + save_start_tag (data, "packing"); + + gb_widget_output_bool (data, Shrink, shrink); + gb_widget_output_bool (data, Resize, resize); + + if (data->action == GB_SAVING) + save_end_tag (data, "packing"); +} + + +/* Applies or loads the child properties of a child of a hbox/vbox. */ +void +gb_paned_set_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + gboolean shrink, resize, is_child1, need_resize = FALSE; + + if (child == GTK_PANED (widget)->child1) + is_child1 = TRUE; + else if (child == GTK_PANED (widget)->child2) + is_child1 = FALSE; + else + { + /* This shouldn't happen. */ + g_warning ("Couldn't find child of GtkPaned container"); + return; + } + + shrink = gb_widget_input_bool (data, Shrink); + if (data->apply) + { + if (is_child1) + GTK_PANED (widget)->child1_shrink = shrink; + else + GTK_PANED (widget)->child2_shrink = shrink; + need_resize = TRUE; + } + + resize = gb_widget_input_bool (data, Resize); + if (data->apply) + { + if (is_child1) + GTK_PANED (widget)->child1_resize = resize; + else + GTK_PANED (widget)->child2_resize = resize; + need_resize = TRUE; + } + + if (need_resize) + gtk_widget_queue_resize (widget); +} + + +void +gb_paned_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + gint child_num; + gchar *resize, *shrink; + + if (child == GTK_PANED (parent)->child1) { + child_num = 1; + resize = GTK_PANED (parent)->child1_resize ? "TRUE" : "FALSE"; + shrink = GTK_PANED (parent)->child1_shrink ? "TRUE" : "FALSE"; + } else if (child == GTK_PANED (parent)->child2) { + child_num = 2; + resize = GTK_PANED (parent)->child2_resize ? "TRUE" : "FALSE"; + shrink = GTK_PANED (parent)->child2_shrink ? "TRUE" : "FALSE"; + } else { + g_warning ("Paned child not found"); + return; + } + + source_add (data, " gtk_paned_pack%i (GTK_PANED (%s), %s, %s, %s);\n", + child_num, parent_name, data->wname, resize, shrink); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_hpaned_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_hpaned_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = hpaned_xpm; + gbwidget.tooltip = _("Horizontal Panes"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_hpaned_new; + gbwidget.gb_widget_create_properties = gb_hpaned_create_properties; + gbwidget.gb_widget_get_properties = gb_hpaned_get_properties; + gbwidget.gb_widget_set_properties = gb_hpaned_set_properties; + gbwidget.gb_widget_create_child_properties = gb_paned_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_paned_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_paned_set_child_properties; +/* + gbwidget.gb_widget_create_popup_menu = gb_hpaned_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_hpaned_write_source; + gbwidget.gb_widget_write_add_child_source = gb_paned_write_add_child_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhruler.c b/tools/glade/glade/gbwidgets/gbhruler.c new file mode 100644 index 00000000..5a44611b --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhruler.c @@ -0,0 +1,260 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhruler.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/hruler.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Metric = "HRuler|GtkRuler::metric"; +static gchar *Lower = "HRuler|GtkRuler::lower"; +static gchar *Upper = "HRuler|GtkRuler::upper"; +static gchar *Pos = "HRuler|GtkRuler::position"; +static gchar *Max = "HRuler|GtkRuler::max_size"; + +static const gchar *GbMetricChoices[] = +{"Pixels", "Inches", "Centimeters", NULL}; +static const gint GbMetricValues[] = +{ + GTK_PIXELS, + GTK_INCHES, + GTK_CENTIMETERS +}; +static const gchar *GbMetricSymbols[] = +{ + "GTK_PIXELS", + "GTK_INCHES", + "GTK_CENTIMETERS" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHRuler, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_hruler_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_hruler_new (); + gtk_ruler_set_range (GTK_RULER (new_widget), 0, 10, 0, 10); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_hruler_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Metric, _("Metric:"), + _("The units of the ruler"), + GbMetricChoices); + property_add_float (Lower, _("Lower Value:"), + _("The low value of the ruler")); + property_add_float (Upper, _("Upper Value:"), + _("The high value of the ruler")); + property_add_float (Pos, _("Position:"), + _("The current position on the ruler")); + property_add_float (Max, _("Max:"), + _("The maximum value of the ruler")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_hruler_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gchar *metric_name; + gint i; + + metric_name = GTK_RULER (widget)->metric->metric_name; + for (i = 0; i < sizeof (GbMetricValues) / sizeof (GbMetricValues[0]); i++) + { + if (!strcmp (GbMetricChoices[i], metric_name)) + gb_widget_output_choice (data, Metric, i, GbMetricSymbols[i]); + } + + gb_widget_output_float (data, Lower, GTK_RULER (widget)->lower); + gb_widget_output_float (data, Upper, GTK_RULER (widget)->upper); + gb_widget_output_float (data, Pos, GTK_RULER (widget)->position); + gb_widget_output_float (data, Max, GTK_RULER (widget)->max_size); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_hruler_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *metric; + gint i; + gfloat lower, upper, pos, max; + gboolean set_range = FALSE; + + metric = gb_widget_input_choice (data, Metric); + if (data->apply) + { + for (i = 0; i < sizeof (GbMetricValues) / sizeof (GbMetricValues[0]); i + ++) + { + if (!strcmp (metric, GbMetricChoices[i]) + || !strcmp (metric, GbMetricSymbols[i])) + { + gtk_ruler_set_metric (GTK_RULER (widget), GbMetricValues[i]); + break; + } + } + } + + lower = gb_widget_input_float (data, Lower); + if (data->apply) + set_range = TRUE; + else + lower = GTK_RULER (widget)->lower; + + upper = gb_widget_input_float (data, Upper); + if (data->apply) + set_range = TRUE; + else + upper = GTK_RULER (widget)->upper; + + pos = gb_widget_input_float (data, Pos); + if (data->apply) + set_range = TRUE; + else + pos = GTK_RULER (widget)->position; + + max = gb_widget_input_float (data, Max); + if (data->apply) + set_range = TRUE; + else + max = GTK_RULER (widget)->max_size; + + if (set_range) + gtk_ruler_set_range (GTK_RULER (widget), lower, upper, pos, max); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHRuler, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_hruler_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_hruler_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *metric_name; + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_hruler_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + metric_name = GTK_RULER (widget)->metric->metric_name; + if (strcmp (metric_name, "Pixels")) + { + for (i = 0; i < sizeof (GbMetricValues) / sizeof (GbMetricValues[0]); i + ++) + { + if (!strcmp (GbMetricChoices[i], metric_name)) + source_add (data, " gtk_ruler_set_metric (GTK_RULER (%s), %s);\n", + data->wname, GbMetricSymbols[i]); + } + } + source_add (data, " gtk_ruler_set_range (GTK_RULER (%s), %g, %g, %g, %g);\n", + data->wname, GTK_RULER (widget)->lower, GTK_RULER (widget)->upper, + GTK_RULER (widget)->position, GTK_RULER (widget)->max_size); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_hruler_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_hruler_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = hruler_xpm; + gbwidget.tooltip = _("Horizontal Ruler"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_hruler_new; + gbwidget.gb_widget_create_properties = gb_hruler_create_properties; + gbwidget.gb_widget_get_properties = gb_hruler_get_properties; + gbwidget.gb_widget_set_properties = gb_hruler_set_properties; + gbwidget.gb_widget_write_source = gb_hruler_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_hruler_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhscale.c b/tools/glade/glade/gbwidgets/gbhscale.c new file mode 100644 index 00000000..d5c6d413 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhscale.c @@ -0,0 +1,332 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhscale.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/hscale.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *DrawValue = "HScale|GtkScale::draw_value"; +static gchar *ValuePos = "HScale|GtkScale::value_pos"; +static gchar *Digits = "HScale|GtkRange::digits"; +static gchar *Policy = "HScale|GtkRange::update_policy"; +static gchar *Inverted = "HScale|GtkRange::inverted"; + +static const gchar *Values[] = +{ + "GtkHScale::value", + "GtkHScale::lower", + "GtkHScale::upper", + "GtkHScale::step", + "GtkHScale::page", + "GtkHScale::page_size", +}; + +static const gchar *GbValuePosChoices[] = +{"Left", "Right", "Top", "Bottom", NULL}; +static const gint GbValuePosValues[] = +{ + GTK_POS_LEFT, + GTK_POS_RIGHT, + GTK_POS_TOP, + GTK_POS_BOTTOM +}; +static const gchar *GbValuePosSymbols[] = +{ + "GTK_POS_LEFT", + "GTK_POS_RIGHT", + "GTK_POS_TOP", + "GTK_POS_BOTTOM" +}; + +static const gchar *GbPolicyChoices[] = +{"Continuous", "Discontinuous", "Delayed", + NULL}; +static const gint GbPolicyValues[] = +{ + GTK_UPDATE_CONTINUOUS, + GTK_UPDATE_DISCONTINUOUS, + GTK_UPDATE_DELAYED +}; +static const gchar *GbPolicySymbols[] = +{ + "GTK_UPDATE_CONTINUOUS", + "GTK_UPDATE_DISCONTINUOUS", + "GTK_UPDATE_DELAYED" +}; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHScale, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_hscale_new (GbWidgetNewData * data) +{ + return gtk_hscale_new (NULL); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_hscale_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (DrawValue, _("Show Value:"), _("If the scale's value is shown")); + property_add_int_range (Digits, _("Digits:"), _("The number of digits to show"), + 0, 13, 1, 10, 1); + property_add_choice (ValuePos, _("Value Pos:"), + _("The position of the value"), + GbValuePosChoices); + property_add_choice (Policy, _("Policy:"), + _("The update policy of the scale"), + GbPolicyChoices); + property_add_bool (Inverted, _("Inverted:"), _("If the range values are inverted")); + property_add_adjustment (Values, GB_ADJUST_DEFAULT_LABELS); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_hscale_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + gb_widget_output_bool (data, DrawValue, GTK_SCALE (widget)->draw_value); + + for (i = 0; i < sizeof (GbValuePosValues) / sizeof (GbValuePosValues[0]); + i++) + { + if (GbValuePosValues[i] == GTK_SCALE (widget)->value_pos) + gb_widget_output_choice (data, ValuePos, i, GbValuePosSymbols[i]); + } + gb_widget_output_int (data, Digits, GTK_SCALE (widget)->digits); + + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + gb_widget_output_choice (data, Policy, i, GbPolicySymbols[i]); + } + + gb_widget_output_bool (data, Inverted, GTK_RANGE (widget)->inverted); + + gb_widget_output_adjustment (data, Values, GTK_RANGE (widget)->adjustment, + "adjustment"); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_hscale_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean draw_value, inverted; + gint digits, i; + gchar *valuepos, *policy; + GtkAdjustment *adj; + + draw_value = gb_widget_input_bool (data, DrawValue); + if (data->apply) + { + gtk_scale_set_draw_value (GTK_SCALE (widget), draw_value); + /* Shouldn't really need to do this */ + editor_refresh_widget (widget); + } + + valuepos = gb_widget_input_choice (data, ValuePos); + if (data->apply) + { + for (i = 0; i < sizeof (GbValuePosValues) / sizeof (GbValuePosValues[0]); + i++) + { + if (!strcmp (valuepos, GbValuePosChoices[i]) + || !strcmp (valuepos, GbValuePosSymbols[i])) + { + gtk_scale_set_value_pos (GTK_SCALE (widget), GbValuePosValues[i]); + break; + } + } + } + + digits = gb_widget_input_int (data, Digits); + if (data->apply) + gtk_scale_set_digits (GTK_SCALE (widget), digits); + + policy = gb_widget_input_choice (data, Policy); + if (data->apply) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i + ++) + { + if (!strcmp (policy, GbPolicyChoices[i]) + || !strcmp (policy, GbPolicySymbols[i])) + { + gtk_range_set_update_policy (GTK_RANGE (widget), GbPolicyValues + [i]); + break; + } + } + } + + inverted = gb_widget_input_bool (data, Inverted); + if (data->apply) + { + gtk_range_set_inverted (GTK_RANGE (widget), inverted); + } + + adj = GTK_RANGE (widget)->adjustment; + if (gb_widget_input_adjustment (data, Values, adj, "adjustment")) + { + gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHScale, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_hscale_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_hscale_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkAdjustment *adj = GTK_RANGE (widget)->adjustment; + gint i; + + if (data->create_widget) + { + source_add (data, + " %s = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (%g, %g, %g, %g, %g, %g)));\n", + data->wname, adj->value, adj->lower, adj->upper, + adj->step_increment, adj->page_increment, adj->page_size); + } + + gb_widget_write_standard_source (widget, data); + + if (!GTK_SCALE (widget)->draw_value) + source_add (data, " gtk_scale_set_draw_value (GTK_SCALE (%s), FALSE);\n", + data->wname); + + if (GTK_SCALE (widget)->value_pos != GTK_POS_TOP) + { + for (i = 0; i < sizeof (GbValuePosValues) / sizeof (GbValuePosValues[0]); + i++) + { + if (GbValuePosValues[i] == GTK_SCALE (widget)->value_pos) + source_add (data, " gtk_scale_set_value_pos (GTK_SCALE (%s), %s);\n", + data->wname, GbValuePosSymbols[i]); + } + } + if (GTK_SCALE (widget)->digits != 1) + source_add (data, " gtk_scale_set_digits (GTK_SCALE (%s), %i);\n", + data->wname, GTK_SCALE (widget)->digits); + + if (GTK_RANGE (widget)->update_policy != GTK_UPDATE_CONTINUOUS) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i + ++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + source_add (data, + " gtk_range_set_update_policy (GTK_RANGE (%s), %s);\n", + data->wname, GbPolicySymbols[i]); + } + } + + if (GTK_RANGE (widget)->inverted) + { + source_add (data, + " gtk_range_set_inverted (GTK_RANGE (%s), TRUE);\n", + data->wname); + + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_hscale_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_hscale_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = hscale_xpm; + gbwidget.tooltip = _("Horizontal Scale"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_hscale_new; + gbwidget.gb_widget_create_properties = gb_hscale_create_properties; + gbwidget.gb_widget_get_properties = gb_hscale_get_properties; + gbwidget.gb_widget_set_properties = gb_hscale_set_properties; + gbwidget.gb_widget_write_source = gb_hscale_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_hscale_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhscrollbar.c b/tools/glade/glade/gbwidgets/gbhscrollbar.c new file mode 100644 index 00000000..8ca4d2da --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhscrollbar.c @@ -0,0 +1,250 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhscrollbar.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/hscrollbar.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Policy = "HScrollbar|GtkRange::update_policy"; +static gchar *Inverted = "HScrollbar|GtkRange::inverted"; + +static const gchar *Values[] = +{ + "GtkHScrollbar::value", + "GtkHScrollbar::lower", + "GtkHScrollbar::upper", + "GtkHScrollbar::step", + "GtkHScrollbar::page", + "GtkHScrollbar::page_size", +}; + +static const gchar *GbPolicyChoices[] = +{"Continuous", "Discontinuous", "Delayed", + NULL}; +static const gint GbPolicyValues[] = +{ + GTK_UPDATE_CONTINUOUS, + GTK_UPDATE_DISCONTINUOUS, + GTK_UPDATE_DELAYED +}; +static const gchar *GbPolicySymbols[] = +{ + "GTK_UPDATE_CONTINUOUS", + "GTK_UPDATE_DISCONTINUOUS", + "GTK_UPDATE_DELAYED" +}; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHScrollbar, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_hscrollbar_new (GbWidgetNewData * data) +{ + return gtk_hscrollbar_new (NULL); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_hscrollbar_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Policy, _("Policy:"), + _("The update policy of the scrollbar"), + GbPolicyChoices); + property_add_bool (Inverted, _("Inverted:"), _("If the range values are inverted")); + property_add_adjustment (Values, GB_ADJUST_DEFAULT_LABELS); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_hscrollbar_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + gb_widget_output_choice (data, Policy, i, GbPolicySymbols[i]); + } + + gb_widget_output_bool (data, Inverted, GTK_RANGE (widget)->inverted); + + gb_widget_output_adjustment (data, Values, GTK_RANGE (widget)->adjustment, + "adjustment"); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_hscrollbar_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *policy; + gint i; + gboolean inverted; + GtkAdjustment *adj; + + policy = gb_widget_input_choice (data, Policy); + if (data->apply) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i + ++) + { + if (!strcmp (policy, GbPolicyChoices[i]) + || !strcmp (policy, GbPolicySymbols[i])) + { + gtk_range_set_update_policy (GTK_RANGE (widget), GbPolicyValues + [i]); + break; + } + } + } + + inverted = gb_widget_input_bool (data, Inverted); + if (data->apply) + { + gtk_range_set_inverted (GTK_RANGE (widget), inverted); + } + + adj = GTK_RANGE (widget)->adjustment; + if (gb_widget_input_adjustment (data, Values, adj, "adjustment")) + { + gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed"); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHScrollbar, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_hscrollbar_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_hscrollbar_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkAdjustment *adj = GTK_RANGE (widget)->adjustment; + gint i; + + if (data->create_widget) + { + source_add (data, + " %s = gtk_hscrollbar_new (GTK_ADJUSTMENT (gtk_adjustment_new (%g, %g, %g, %g, %g, %g)));\n", + data->wname, adj->value, adj->lower, adj->upper, + adj->step_increment, adj->page_increment, adj->page_size); + } + + gb_widget_write_standard_source (widget, data); + + if (GTK_RANGE (widget)->update_policy != GTK_UPDATE_CONTINUOUS) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i + ++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + source_add (data, + " gtk_range_set_update_policy (GTK_RANGE (%s), %s);\n", + data->wname, GbPolicySymbols[i]); + } + } + + if (GTK_RANGE (widget)->inverted) + { + source_add (data, + " gtk_range_set_inverted (GTK_RANGE (%s), TRUE);\n", + data->wname); + + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_hscrollbar_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_hscrollbar_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = hscrollbar_xpm; + gbwidget.tooltip = _("Horizontal Scrollbar"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_hscrollbar_new; + gbwidget.gb_widget_create_properties = gb_hscrollbar_create_properties; + gbwidget.gb_widget_get_properties = gb_hscrollbar_get_properties; + gbwidget.gb_widget_set_properties = gb_hscrollbar_set_properties; + gbwidget.gb_widget_write_source = gb_hscrollbar_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_hscrollbar_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbhseparator.c b/tools/glade/glade/gbwidgets/gbhseparator.c new file mode 100644 index 00000000..bcefcf28 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbhseparator.c @@ -0,0 +1,157 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhseparator.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/hseparator.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkHSeparator, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_hseparator_new(GbWidgetNewData *data) +{ + return gtk_hseparator_new (); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +/* + static void + gb_hseparator_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) + { + + } + */ + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +/* + static void + gb_hseparator_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) + { + + } + */ + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +/* + static void + gb_hseparator_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) + { + + } + */ + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkHSeparator, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_hseparator_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_hseparator_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_hseparator_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_hseparator_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_hseparator_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = hseparator_xpm; + gbwidget.tooltip = _("Horizonal Separator"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_hseparator_new; +/* + gbwidget.gb_widget_create_properties = gb_hseparator_create_properties; + gbwidget.gb_widget_get_properties = gb_hseparator_get_properties; + gbwidget.gb_widget_set_properties = gb_hseparator_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_hseparator_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_hseparator_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbiconview.c b/tools/glade/glade/gbwidgets/gbiconview.c new file mode 100644 index 00000000..1c8f4d56 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbiconview.c @@ -0,0 +1,322 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/iconview.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *SelectionMode = "GtkIconView::selection_mode"; +static gchar *Orientation = "GtkIconView::orientation"; +static gchar *Reorderable = "GtkIconView::reorderable"; + + +static const gchar *GbModeChoices[] = +{"None", "Single", "Browse", "Multiple", NULL}; +static const gint GbModeValues[] = +{ + GTK_SELECTION_NONE, + GTK_SELECTION_SINGLE, + GTK_SELECTION_BROWSE, + GTK_SELECTION_MULTIPLE +}; +static const gchar *GbModeSymbols[] = +{ + "GTK_SELECTION_NONE", + "GTK_SELECTION_SINGLE", + "GTK_SELECTION_BROWSE", + "GTK_SELECTION_MULTIPLE" +}; + + +static const gchar *GbOrientationChoices[] = +{"Horizontal", "Vertical", NULL}; +static const gint GbOrientationValues[] = +{ + GTK_ORIENTATION_HORIZONTAL, + GTK_ORIENTATION_VERTICAL +}; +static const gchar *GbOrientationSymbols[] = +{ + "GTK_ORIENTATION_HORIZONTAL", + "GTK_ORIENTATION_VERTICAL" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkIconView, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_icon_view_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + GtkListStore *store; + GtkTreeIter iter; + GbWidget *gbwidget; + GdkPixbuf *pixbuf; + char buf[256]; + gint i; + + new_widget = gtk_icon_view_new (); + + /* Set up a dummy model so the user sees something. */ + store = gtk_list_store_new (2, G_TYPE_STRING, GDK_TYPE_PIXBUF); + + gbwidget = gb_widget_lookup_class ("GtkImage"); + if (gbwidget->pixbuf == NULL && gbwidget->pixmap_struct) + { + gbwidget->pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**) gbwidget->pixmap_struct); + } + pixbuf = gbwidget->pixbuf; + + for (i = 1; i <= 8; i++) + { + gtk_list_store_append (store, &iter); + sprintf (buf, _("Icon %i"), i); + gtk_list_store_set (store, &iter, 0, buf, 1, pixbuf, -1); + } + + gtk_icon_view_set_model (GTK_ICON_VIEW (new_widget), GTK_TREE_MODEL (store)); + gtk_icon_view_set_text_column (GTK_ICON_VIEW (new_widget), 0); + gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (new_widget), 1); + + g_object_unref (G_OBJECT (store)); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_icon_view_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (SelectionMode, _("Select Mode:"), + _("The selection mode of the icon view"), + GbModeChoices); + property_add_choice (Orientation, _("Orientation:"), + _("The orientation of the icons"), + GbOrientationChoices); + property_add_bool (Reorderable, _("Reorderable:"), + _("If the view can be reordered using Drag and Drop")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_icon_view_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + GtkSelectionMode mode; + GtkOrientation orientation; + gboolean reorderable; + gint i; + + mode = gtk_icon_view_get_selection_mode (GTK_ICON_VIEW (widget)); + orientation = gtk_icon_view_get_orientation (GTK_ICON_VIEW (widget)); + + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == mode) + gb_widget_output_choice (data, SelectionMode, i, GbModeSymbols[i]); + } + + for (i = 0; i < sizeof (GbOrientationValues) / sizeof (GbOrientationValues[0]); i++) + { + if (GbOrientationValues[i] == orientation) + gb_widget_output_choice (data, Orientation, i, GbOrientationSymbols[i]); + } + + reorderable = gtk_icon_view_get_reorderable (GTK_ICON_VIEW (widget)); + gb_widget_output_bool (data, Reorderable, reorderable); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_icon_view_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *mode, *orientation; + gboolean reorderable; + gint i; + + mode = gb_widget_input_choice (data, SelectionMode); + if (data->apply) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (!strcmp (mode, GbModeChoices[i]) + || !strcmp (mode, GbModeSymbols[i])) + { + gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (widget), GbModeValues[i]); + break; + } + } + } + + orientation = gb_widget_input_choice (data, Orientation); + if (data->apply) + { + for (i = 0; i < sizeof (GbOrientationValues) / sizeof (GbOrientationValues[0]); i++) + { + if (!strcmp (orientation, GbOrientationChoices[i]) + || !strcmp (orientation, GbOrientationSymbols[i])) + { + gtk_icon_view_set_orientation (GTK_ICON_VIEW (widget), + GbOrientationValues[i]); + break; + } + } + } + + reorderable = gb_widget_input_bool (data, Reorderable); + if (data->apply) + gtk_icon_view_set_reorderable (GTK_ICON_VIEW (widget), reorderable); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkIconView, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_icon_view_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_icon_view_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkSelectionMode mode; + GtkOrientation orientation; + gboolean reorderable; + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_icon_view_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + mode = gtk_icon_view_get_selection_mode (GTK_ICON_VIEW (widget)); + orientation = gtk_icon_view_get_orientation (GTK_ICON_VIEW (widget)); + + if (mode != GTK_SELECTION_SINGLE) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == mode) + source_add (data, + " gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (%s), %s);\n", + data->wname, GbModeSymbols[i]); + } + } + + if (orientation != GTK_ORIENTATION_VERTICAL) + { + for (i = 0; i < sizeof (GbOrientationValues) / sizeof (GbOrientationValues[0]); i++) + { + if (GbOrientationValues[i] == orientation) + source_add (data, + " gtk_icon_view_set_orientation (GTK_ICON_VIEW (%s), %s);\n", + data->wname, GbOrientationSymbols[i]); + } + } + + reorderable = gtk_icon_view_get_reorderable (GTK_ICON_VIEW (widget)); + if (reorderable) + { + source_add (data, + " gtk_icon_view_set_reorderable (GTK_ICON_VIEW (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_icon_view_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_icon_view_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = iconview_xpm; + gbwidget.tooltip = _("Icon View"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_icon_view_new; + gbwidget.gb_widget_create_properties = gb_icon_view_create_properties; + gbwidget.gb_widget_get_properties = gb_icon_view_get_properties; + gbwidget.gb_widget_set_properties = gb_icon_view_set_properties; + gbwidget.gb_widget_write_source = gb_icon_view_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_icon_view_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbimage.c b/tools/glade/glade/gbwidgets/gbimage.c new file mode 100644 index 00000000..4906efbf --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbimage.c @@ -0,0 +1,662 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <math.h> + +#include <gtk/gtkiconfactory.h> +#include <gtk/gtkimage.h> +#include <gtk/gtkimagemenuitem.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkoptionmenu.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkradiobutton.h> +#include <gtk/gtkspinbutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/image.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +/* This could be a stock icon or a filename. */ +static gchar *Icon = "GtkImage::icon"; + +/* This is the stock icon size, and isn't relevant when a filename is used. */ +static gchar *IconSize = "GtkImage::icon_size"; + +static gchar *XAlign = "Image|GtkMisc::xalign"; +static gchar *YAlign = "Image|GtkMisc::yalign"; +static gchar *XPad = "Image|GtkMisc::xpad"; +static gchar *YPad = "Image|GtkMisc::ypad"; + +static gchar *IconName = "GtkImage::icon_name"; +static gchar *PixelSize = "GtkImage::pixel_size"; + + +static const gchar *GladeIconSizeChoices[] = +{"Menu", "Small Toolbar", "Large Toolbar", "Button", "Drag & Drop", + "Dialog", NULL}; +static const gint GladeIconSizeValues[] = +{ + GTK_ICON_SIZE_MENU, + GTK_ICON_SIZE_SMALL_TOOLBAR, + GTK_ICON_SIZE_LARGE_TOOLBAR, + GTK_ICON_SIZE_BUTTON, + GTK_ICON_SIZE_DND, + GTK_ICON_SIZE_DIALOG +}; +static const gchar *GladeIconSizeSymbols[] = +{ + "GTK_ICON_SIZE_MENU", + "GTK_ICON_SIZE_SMALL_TOOLBAR", + "GTK_ICON_SIZE_LARGE_TOOLBAR", + "GTK_ICON_SIZE_BUTTON", + "GTK_ICON_SIZE_DND", + "GTK_ICON_SIZE_DIALOG" +}; +const int GladeIconSizeChoicesSize = sizeof (GladeIconSizeValues) / sizeof (GladeIconSizeValues[0]); + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkImage, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_image_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + new_widget = gtk_image_new_from_pixmap (gbwidget.gdkpixmap, gbwidget.mask); + return new_widget; +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_image_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GLADE_ICON_SIZE_ANY); + property_add_named_icon (IconName, _("Named Icon:"), + _("The named icon to use")); + property_add_choice (IconSize, _("Icon Size:"), + _("The stock icon size"), + GladeIconSizeChoices); + property_add_int_range (PixelSize, _("Pixel Size:"), + _("The size of the named icon in pixels, or -1 to use the Icon Size property"), + -1, 1000, 1, 10, 1); + + property_add_float_range (XAlign, _("X Align:"), + _("The horizontal alignment"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (YAlign, _("Y Align:"), + _("The vertical alignment"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_int_range (XPad, _("X Pad:"), _("The horizontal padding"), + 0, 1000, 1, 10, 1); + property_add_int_range (YPad, _("Y Pad:"), _("The vertical padding"), + 0, 1000, 1, 10, 1); +} + + +static void +check_visible_sizes (const gchar *stock_id, gboolean show_all) +{ + GtkIconSet *icon_set; + GtkIconSize *sizes; + gint n_sizes, i, j; + GtkWidget *option_menu, *menu; + gboolean item_visible[G_N_ELEMENTS(GladeIconSizeValues)]; + GList *children; + + for (j = 0; j < GladeIconSizeChoicesSize; j++) + item_visible[j] = show_all; + + if (!show_all) + { + icon_set = gtk_icon_factory_lookup_default (stock_id); + if (icon_set) + { + gtk_icon_set_get_sizes (icon_set, &sizes, &n_sizes); + /* Figure out which of our choices should be visible. */ + for (i = 0; i < n_sizes; i++) + { + for (j = 0; j < GladeIconSizeChoicesSize; j++) + { + if (sizes[i] == GladeIconSizeValues[j]) + item_visible[j] = TRUE; + } + } + g_free (sizes); + } + } + + /* Show or Hide the items as appropriate. */ + option_menu = property_get_value_widget (IconSize); + g_return_if_fail (GTK_IS_OPTION_MENU (option_menu)); + + menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu)); + g_return_if_fail (GTK_IS_MENU (menu)); + + children = GTK_MENU_SHELL (menu)->children; + for (j = 0; j < GladeIconSizeChoicesSize; j++) + { + GtkWidget *item; + + item = children->data; + + if (item_visible[j]) + gtk_widget_show (item); + else + gtk_widget_hide (item); + + children = children->next; + } +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_image_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gchar *icon = gtk_object_get_data (GTK_OBJECT (widget), GladeIconKey); + gchar *icon_name = NULL; + gboolean is_stock_icon, is_named_icon = FALSE; + gint i, pixel_size; + GtkImageType storage_type; + + storage_type = gtk_image_get_storage_type (GTK_IMAGE (widget)); + pixel_size = gtk_image_get_pixel_size (GTK_IMAGE (widget)); + + is_stock_icon = glade_util_check_is_stock_id (icon); + + if (storage_type == GTK_IMAGE_ICON_NAME) + { + g_object_get (widget, + "icon_name", &icon_name, + NULL); + if (icon_name && *icon_name) + is_named_icon = TRUE; + } + + if (data->action == GB_SAVING) + { + /* When saving we want to use "stock" or "pixbuf", depending on whether + it is a stock icon or an oridinary pixmap file. */ + if (is_stock_icon) + gb_widget_output_icon (data, "stock", icon); + else + gb_widget_output_icon (data, "pixbuf", icon); + } + else + { + gb_widget_output_icon (data, Icon, icon); + } + + if (is_stock_icon || is_named_icon) + { + if (data->action == GB_SHOWING) + { + for (i = 0; i < GladeIconSizeChoicesSize; i++) + { + if (GladeIconSizeValues[i] == GTK_IMAGE (widget)->icon_size) + gb_widget_output_choice (data, IconSize, i, + GladeIconSizeSymbols[i]); + } + + check_visible_sizes (icon, is_named_icon); + } + else + { + /* We have to save the size as an integer, which sucks a bit. + The integer is the GtkIconSize enum value, not the actual size.*/ + if (is_stock_icon || pixel_size == -1) + gb_widget_output_int (data, IconSize, + GTK_IMAGE (widget)->icon_size); + } + } + + gb_widget_output_named_icon (data, IconName, icon_name); + + /* The icon size only applies to stock icons or named icons. + The pixel size only applies to named icons. */ + if (data->action == GB_SHOWING) + { + property_set_sensitive (IconSize, is_stock_icon || is_named_icon); + property_set_sensitive (PixelSize, is_named_icon); + } + + /* We only want to save the pixel size for named icons, and only if it is + not -1. */ + if (data->action == GB_SHOWING + || (storage_type == GTK_IMAGE_ICON_NAME && pixel_size != -1)) + gb_widget_output_int (data, PixelSize, pixel_size); + + gb_widget_output_float (data, XAlign, GTK_MISC (widget)->xalign); + gb_widget_output_float (data, YAlign, GTK_MISC (widget)->yalign); + gb_widget_output_int (data, XPad, GTK_MISC (widget)->xpad); + gb_widget_output_int (data, YPad, GTK_MISC (widget)->ypad); +} + + +/* Check the icon size is valid for the stock item, and if not pick + the first valid size. */ +static GtkIconSize +check_icon_size (const gchar *stock_id, GtkIconSize icon_size) +{ + GtkIconSet *icon_set; + GtkIconSize *sizes, retval = GTK_ICON_SIZE_BUTTON; + gint n_sizes, i; + + icon_set = gtk_icon_factory_lookup_default (stock_id); + if (icon_set) + { + gtk_icon_set_get_sizes (icon_set, &sizes, &n_sizes); + + for (i = 0; i < n_sizes; i++) + { + if (sizes[i] == icon_size) + return icon_size; + } + + retval = sizes[0]; + g_free (sizes); + } + + return retval; +} + + +static void +gb_image_clear_pixmap (GtkWidget *widget, GladeProject *project) +{ + gchar *old_icon; + + /* Remove the old icon stored in the widget data, and remove the + pixmap from the project, if necessary. */ + old_icon = gtk_object_get_data (GTK_OBJECT (widget), GladeIconKey); + glade_project_remove_pixmap (project, old_icon); + + gtk_object_set_data (GTK_OBJECT (widget), GladeIconKey, NULL); +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_image_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gfloat xalign, yalign; + gint xpad, ypad, i, pixel_size; + gboolean set_alignment = FALSE, set_padding = FALSE, apply_icon_size; + GtkIconSize icon_size = GTK_ICON_SIZE_BUTTON; + gchar *icon_size_string, *icon, *icon_name; + + icon_size = GTK_IMAGE (widget)->icon_size; + + if (data->action == GB_APPLYING) + { + icon_size_string = gb_widget_input_choice (data, IconSize); + apply_icon_size = data->apply; + if (data->apply) + { + for (i = 0; i < GladeIconSizeChoicesSize; i++) + { + if (!strcmp (icon_size_string, GladeIconSizeChoices[i]) + || !strcmp (icon_size_string, GladeIconSizeSymbols[i])) + { + icon_size = GladeIconSizeValues[i]; + break; + } + } + } + } + else + { + /* We have to save the size as an integer, which sucks a bit. + The integer is the GtkIconSize enum value, not the actual size.*/ + int new_size = gb_widget_input_int (data, IconSize); + apply_icon_size = data->apply; + if (data->apply) + icon_size = new_size; + } + + /* When loading we use different names. */ + if (data->action == GB_LOADING) + { + icon = gb_widget_input_icon (data, "stock"); + if (!data->apply) + icon = gb_widget_input_icon (data, "pixbuf"); + } + else + { + icon = gb_widget_input_icon (data, Icon); + } + + if (data->apply) + { + gboolean is_stock_icon = glade_util_check_is_stock_id (icon); + + /* Remove the old icon stored in the widget data, and remove the + pixmap from the project, if necessary. */ + gb_image_clear_pixmap (widget, data->project); + + gtk_object_set_data_full (GTK_OBJECT (widget), GladeIconKey, + g_strdup (icon), icon ? g_free : NULL); + + if (is_stock_icon) + { + GtkIconSize new_icon_size; + + new_icon_size = check_icon_size (icon, icon_size); + + /* If we are showing this widget's properties, we need to update + the sizes option menu. */ + if (property_get_widget () == widget) + { + /* We set it sensitive before changing the value, so the child + menu item is changed from insensitive to sensitive if needed. + Otherwise it may remain insensitive. */ + property_set_sensitive (IconSize, TRUE); + property_set_sensitive (PixelSize, FALSE); + + property_set_auto_apply (FALSE); + + check_visible_sizes (icon, FALSE); + + /* Check the icon size is valid for the stock item, and if not + pick the first valid size. */ + for (i = 0; i < GladeIconSizeChoicesSize; i++) + { + if (GladeIconSizeValues[i] == new_icon_size) + { + property_set_choice (IconSize, i); + } + } + + property_set_named_icon (IconName, NULL); + + property_set_auto_apply (TRUE); + } + + gtk_image_set_from_stock (GTK_IMAGE (widget), icon, + new_icon_size); + } + else + { + /* If an icon filename is set, use that, otherwise use the icon + we use for the palette. */ + if (icon) + { + gtk_image_set_from_file (GTK_IMAGE (widget), icon); + glade_project_add_pixmap (data->project, icon); + } + else + { + gtk_image_set_from_pixmap (GTK_IMAGE (widget), + gbwidget.gdkpixmap, gbwidget.mask); + } + + if (property_get_widget () == widget) + { + /* The icon size isn't relevant to non-stock icons. */ + property_set_sensitive (IconSize, FALSE); + property_set_sensitive (PixelSize, FALSE); + + property_set_auto_apply (FALSE); + property_set_named_icon (IconName, NULL); + property_set_auto_apply (TRUE); + } + } + + /* We've recreated the icon with the new size above, so we don't need + to apply the size again. */ + apply_icon_size = FALSE; + } + + /* This is for the named/themed icon. */ + icon_name = gb_widget_input_named_icon (data, IconName); + if (data->apply) + { + /* Clear any stock icon or icon from a file. */ + gb_image_clear_pixmap (widget, data->project); + + gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, + icon_size); + + if (property_get_widget () == widget) + { + property_set_sensitive (IconSize, TRUE); + property_set_sensitive (PixelSize, TRUE); + + /* Clear the Icon property. */ + property_set_auto_apply (FALSE); + property_set_icon (Icon, NULL); + property_set_auto_apply (TRUE); + } + + /* We've recreated the icon with the new size above, so we don't need + to apply the size again. */ + apply_icon_size = FALSE; + } + + /* When we set the icon size, we reset the pixel size to -1, otherwise it + overrides the icon size. */ + if (apply_icon_size) + { + gtk_image_set_pixel_size (GTK_IMAGE (widget), -1); + g_object_set (widget, "icon_size", icon_size, NULL); + + if (property_get_widget () == widget) + { + property_set_auto_apply (FALSE); + property_set_int (PixelSize, -1); + property_set_auto_apply (TRUE); + } + } + + /* GtkImage doesn't like a pixel size of 0 so we just skip that. */ + pixel_size = gb_widget_input_int (data, PixelSize); + if (data->apply && pixel_size != 0) + gtk_image_set_pixel_size (GTK_IMAGE (widget), pixel_size); + + xalign = gb_widget_input_float (data, XAlign); + if (data->apply) + set_alignment = TRUE; + else + xalign = GTK_MISC (widget)->xalign; + + yalign = gb_widget_input_float (data, YAlign); + if (data->apply) + set_alignment = TRUE; + else + yalign = GTK_MISC (widget)->yalign; + + if (set_alignment) + gtk_misc_set_alignment (GTK_MISC (widget), xalign, yalign); + + xpad = gb_widget_input_int (data, XPad); + if (data->apply) + set_padding = TRUE; + else + xpad = GTK_MISC (widget)->xpad; + + ypad = gb_widget_input_int (data, YPad); + if (data->apply) + set_padding = TRUE; + else + ypad = GTK_MISC (widget)->ypad; + + if (set_padding) + gtk_misc_set_padding (GTK_MISC (widget), xpad, ypad); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkImage, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_image_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_image_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + /* For GNOME projects menuitem images are handled by the GnomeUIInfo + structs, so we don't create source code here. */ + if (widget->parent && GTK_IS_IMAGE_MENU_ITEM (widget->parent) + && glade_project_get_gnome_support (data->project)) + return; + + if (data->create_widget) + { + gchar *icon = gtk_object_get_data (GTK_OBJECT (widget), GladeIconKey); + const gchar *icon_size = "GTK_ICON_SIZE_BUTTON"; + GtkImageType storage_type; + gint i; + + for (i = 0; i < GladeIconSizeChoicesSize; i++) + { + if (GladeIconSizeValues[i] == GTK_IMAGE (widget)->icon_size) + { + icon_size = GladeIconSizeSymbols[i]; + } + } + + storage_type = gtk_image_get_storage_type (GTK_IMAGE (widget)); + + if (storage_type == GTK_IMAGE_ICON_NAME) + { + gint pixel_size = gtk_image_get_pixel_size (GTK_IMAGE (widget)); + gchar *icon_name; + + g_object_get (widget, + "icon_name", &icon_name, + NULL); + + source_add (data, + " %s = gtk_image_new_from_icon_name (\"%s\", %s);\n", + data->wname, icon_name ? icon_name : "gtk-missing-image", + icon_size); + + if (pixel_size > 0) + { + source_add (data, + " gtk_image_set_pixel_size (%s, %i);\n", + data->wname, pixel_size); + } + } + else if (glade_util_check_is_stock_id (icon)) + { + + source_add (data, + " %s = gtk_image_new_from_stock (\"%s\", %s);\n", + data->wname, icon, icon_size); + } + else + { + source_create_pixmap (data, data->wname, icon); + } + } + + gb_widget_write_standard_source (widget, data); + + if (fabs (GTK_MISC (widget)->xalign - 0.5) > 0.0001 + || fabs (GTK_MISC (widget)->yalign - 0.5) > 0.0001) + source_add (data, " gtk_misc_set_alignment (GTK_MISC (%s), %g, %g);\n", + data->wname, GTK_MISC (widget)->xalign, GTK_MISC (widget)->yalign); + + if (GTK_MISC (widget)->xpad != 0 || GTK_MISC (widget)->ypad != 0) + source_add (data, " gtk_misc_set_padding (GTK_MISC (%s), %i, %i);\n", + data->wname, GTK_MISC (widget)->xpad, GTK_MISC (widget)->ypad); +} + + +void +gb_image_destroy (GtkWidget * widget, GbWidgetDestroyData * data) +{ + gb_image_clear_pixmap (widget, data->project); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_image_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_image_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = image_xpm; + gbwidget.tooltip = _("Image"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_image_new; + gbwidget.gb_widget_create_properties = gb_image_create_properties; + gbwidget.gb_widget_get_properties = gb_image_get_properties; + gbwidget.gb_widget_set_properties = gb_image_set_properties; + gbwidget.gb_widget_write_source = gb_image_write_source; + gbwidget.gb_widget_destroy = gb_image_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_image_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbimagemenuitem.c b/tools/glade/glade/gbwidgets/gbimagemenuitem.c new file mode 100644 index 00000000..0c63872d --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbimagemenuitem.c @@ -0,0 +1,486 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtkaccellabel.h> +#include <gtk/gtkimage.h> +#include <gtk/gtkimagemenuitem.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkstock.h> + +#include "../gb.h" +#include "../glade_gnome.h" +#include "../glade_keys_dialog.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/menuitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Label = "ImageMenuItem|GtkItem::label"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkPixmapMenuItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +static GtkWidget* +gb_image_menu_item_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + if (data->action == GB_CREATING) + new_widget = gtk_image_menu_item_new_with_label (data->name); + else + new_widget = gtk_image_menu_item_new (); + return new_widget; +} + + +void +gb_image_menu_item_add_child (GtkWidget * widget, GtkWidget * child, GbWidgetSetArgData *data) +{ + if (GTK_IS_MENU (child)) + { + MSG ("Trying to add a menu to a menu item"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), child); + } + else if (GTK_IS_IMAGE (child)) + { + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), child); + } +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_image_menu_item_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ +#if 0 + /* For now we don't support editing the menuitem properties in the property + editor. The menu editor has to be used instead. */ + property_add_text (Label, _("Label:"), _("The text to display"), 2); +#endif +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_image_menu_item_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gboolean output_label = TRUE; + + /* We only support saving the properties here. */ + if (data->action != GB_SAVING) + return; + + /* Check if it is a stock menu item, and if so, we just save that. */ + if (glade_project_get_gnome_support (data->project)) + { +#ifdef USE_GNOME + gint stock_item_index; + + stock_item_index = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), GladeMenuItemStockIndexKey)); + /* The 'New' item is special. If it has a child menu, it must be a + GNOMEUIINFO_MENU_NEW_SUBTREE. If not, it is a + GNOMEUIINFO_MENU_NEW_ITEM, in which case the label is also output. */ + if (stock_item_index == GladeStockMenuItemNew) + { + if (GTK_MENU_ITEM (widget)->submenu) + { + gb_widget_output_string (data, "stock_item", + "GNOMEUIINFO_MENU_NEW_SUBTREE"); + output_label = FALSE; + } + else + { + gb_widget_output_string (data, "stock_item", + "GNOMEUIINFO_MENU_NEW_ITEM"); + } + } + else if (stock_item_index != 0) + { + gb_widget_output_string (data, "stock_item", GladeStockMenuItemSymbols[stock_item_index]); + output_label = FALSE; + } +#endif + } + else + { + char *stock_id; + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), GladeMenuItemStockIDKey); + if (stock_id) + { + gb_widget_output_string (data, "label", stock_id); + gb_widget_output_bool (data, "use_stock", TRUE); + + /* The 'New' item isn't special for GTK+ apps. */ + output_label = FALSE; + } + } + + if (output_label) + gb_widget_output_child_label (widget, data, Label); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_image_menu_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean input_label = TRUE, input_rest = TRUE; + GtkAccelGroup *accel_group; + guint key; + GdkModifierType modifiers; + + /* We only support loading the properties here. */ + if (data->action != GB_LOADING) + return; + + /* Check for a stock menu item. */ + if (glade_project_get_gnome_support (data->project)) + { +#ifdef USE_GNOME + gchar *stock_item; + + stock_item = gb_widget_input_string (data, "stock_item"); + if (stock_item && stock_item[0]) + { + gint stock_item_index; + + /* Special case for the NEW_SUBTREE. */ + if (!strcmp (stock_item, "GNOMEUIINFO_MENU_NEW_SUBTREE")) + { + stock_item_index = GladeStockMenuItemNew; + } + else + { + stock_item_index = glade_util_string_array_index (GladeStockMenuItemSymbols, GladeStockMenuItemSize, stock_item); + } + + if (stock_item_index != -1) + { + GnomeUIInfo *uiinfo; + GtkWidget *pixmap = NULL, *label; + + uiinfo = &GladeStockMenuItemValues[stock_item_index]; + if (uiinfo->type == GNOME_APP_UI_ITEM_CONFIGURABLE) + gnome_app_ui_configure_configurable (uiinfo); + + if (uiinfo->pixmap_type == GNOME_APP_PIXMAP_STOCK) + pixmap = gtk_image_new_from_stock (uiinfo->pixmap_info, + GTK_ICON_SIZE_MENU); + + if (pixmap) + { + gtk_widget_show (pixmap); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), + pixmap); + } + + label = gtk_accel_label_new (""); + gtk_label_set_text_with_mnemonic (GTK_LABEL (label), + glade_gnome_gettext (uiinfo->label)); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_show (label); + gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), + widget); + gtk_container_add (GTK_CONTAINER (widget), label); + + /* Add the configured accelerator key. */ + if (uiinfo->accelerator_key != 0 && widget->parent + && GTK_IS_MENU (widget->parent)) + { + accel_group = GTK_MENU (widget->parent)->accel_group; + gtk_widget_add_accelerator (widget, "activate", accel_group, + uiinfo->accelerator_key, + uiinfo->ac_mods, + GTK_ACCEL_VISIBLE); + } + + /* Remember the index of the stock item. */ + gtk_object_set_data (GTK_OBJECT (widget), + GladeMenuItemStockIndexKey, + GINT_TO_POINTER (stock_item_index)); + + /* The 'New' item can have a label. The rest can't. */ + if (stock_item_index != GladeStockMenuItemNew) + input_label = FALSE; + input_rest = FALSE; + } + else + { +#ifdef FIXME + load_add_error_message_with_tag (data, + GLADE_LINE_PROPERTY, + _("Invalid stock menu item"), + "stock_item", stock_item); +#endif + } + } +#endif + } + else + { + gboolean is_stock_item; + gchar *stock_id; + + is_stock_item = gb_widget_input_bool (data, "use_stock"); + if (is_stock_item) + { + stock_id = gb_widget_input_string (data, "label"); + } + else + { + /* This is for backwards compatability with Glade 1.1.0. */ + stock_id = gb_widget_input_string (data, "stock"); + if (stock_id && stock_id[0]) + is_stock_item = TRUE; + } + + if (is_stock_item && stock_id && stock_id[0]) + { + GtkStockItem item; + GtkWidget *label, *image; + + if (gtk_stock_lookup (stock_id, &item)) + { + label = gtk_type_new (GTK_TYPE_ACCEL_LABEL); + gtk_label_set_text_with_mnemonic (GTK_LABEL (label), item.label); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_show (label); + + gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), + widget); + gtk_container_add (GTK_CONTAINER (widget), label); + + /* Add the configured accelerator key. */ + if (item.keyval && widget->parent + && GTK_IS_MENU (widget->parent)) + { + accel_group = GTK_MENU (widget->parent)->accel_group; + gtk_widget_add_accelerator (widget, "activate", accel_group, + item.keyval, + item.modifier, + GTK_ACCEL_VISIBLE); + } + + image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU); + if (image) + { + gtk_widget_show (image); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (widget), + image); + } + + + + /* Remember the stock ID. */ + gtk_object_set_data_full (GTK_OBJECT (widget), + GladeMenuItemStockIDKey, + g_strdup (stock_id), g_free); + + input_label = FALSE; + input_rest = FALSE; + } + else + { + g_warning ("Invalid stock menu item: %s", stock_id); + } + } + } + + if (input_label) + gb_widget_input_child_label (widget, data, Label); + + if (input_rest) + { + /* FIXME: should this be somewhere else? */ + /* If we are loading, install the 'activate' accelerator, if it has one, + so that is is visible. */ + if (data->action == GB_LOADING && widget->parent + && GTK_IS_MENU (widget->parent)) + { + int i; + + for (i = 0; i < data->widget_info->n_accels; i++) + { + if (!strcmp (data->widget_info->accels[i].signal, "activate")) + { + key = data->widget_info->accels[i].key; + modifiers = data->widget_info->accels[i].modifiers; + accel_group = GTK_MENU (widget->parent)->accel_group; + gtk_widget_add_accelerator (widget, "activate", accel_group, + key, modifiers, + GTK_ACCEL_VISIBLE); + break; + } + } + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkPixmapMenuItem, with signals pointing to + * other functions in this file. + */ +static void +gb_image_menu_item_create_popup_menu (GtkWidget * widget, + GbWidgetCreateMenuData * data) +{ + /* Add command to remove child label. */ +#if 0 + gb_widget_create_child_label_popup_menu (widget, data); +#endif +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_image_menu_item_write_source (GtkWidget * widget, + GbWidgetWriteSourceData * data) +{ + gchar *stock_id, *label_text; + gboolean translatable, context; + gchar *comments; + +#ifdef USE_GNOME + if (data->project->gnome_support) + { + glade_gnome_write_menu_item_source (GTK_MENU_ITEM (widget), data); + return; + } +#endif + + /* See if it is a stock item. */ + stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeMenuItemStockIDKey); + if (stock_id) + { + data->need_accel_group = TRUE; + source_add (data, " %s = gtk_image_menu_item_new_from_stock (\"%s\", accel_group);\n", + data->wname, stock_id); + } + else + { + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + label_text = glade_util_get_label_text (GTK_BIN (widget)->child); + source_add (data, " %s = gtk_image_menu_item_new_with_mnemonic (%s);\n", + data->wname, + source_make_string_full (label_text, data->use_gettext && translatable, context)); + } + + gb_widget_write_standard_source (widget, data); +} + + +/* Outputs source to add a child menu to a menu item. */ +static void +gb_image_menu_item_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + if (GTK_IS_MENU (child)) + { + source_add (data, + " gtk_menu_item_set_submenu (GTK_MENU_ITEM (%s), %s);\n", + parent_name, data->wname); + } + else if (GTK_IS_IMAGE (child)) + { + source_add (data, + " gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (%s), %s);\n", + parent_name, data->wname); + } + else + { + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_image_menu_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_image_menu_item_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = menuitem_xpm; + gbwidget.tooltip = _("Menu item with a pixmap"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_image_menu_item_new; + gbwidget.gb_widget_add_child = gb_image_menu_item_add_child; + gbwidget.gb_widget_create_properties = gb_image_menu_item_create_properties; + gbwidget.gb_widget_get_properties = gb_image_menu_item_get_properties; + gbwidget.gb_widget_set_properties = gb_image_menu_item_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_image_menu_item_create_popup_menu; + gbwidget.gb_widget_write_source = gb_image_menu_item_write_source; + gbwidget.gb_widget_write_add_child_source = gb_image_menu_item_write_add_child_source; + /*gbwidget.gb_widget_destroy = gb_image_menu_item_destroy;*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbinputdialog.c b/tools/glade/glade/gbwidgets/gbinputdialog.c new file mode 100644 index 00000000..4057cd23 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbinputdialog.c @@ -0,0 +1,273 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkinputdialog.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/inputdialog.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "InputDialog|GtkWindow::title"; +static gchar *Type = "InputDialog|GtkWindow::type"; +static gchar *Position = "InputDialog|GtkWindow::window_position"; +static gchar *Modal = "InputDialog|GtkWindow::modal"; +static gchar *DefaultWidth = "Input|GtkWindow::default_width"; +static gchar *DefaultHeight = "Input|GtkWindow::default_height"; +static gchar *Shrink = "InputDialog|GtkWindow::allow_shrink"; +static gchar *Grow = "InputDialog|GtkWindow::allow_grow"; +static gchar *AutoShrink = "InputDialog|GtkWindow::auto_shrink"; +static gchar *IconName = "InputDialog|GtkWindow::icon_name"; +static gchar *FocusOnMap = "InputDialog|GtkWindow::focus_on_map"; + +static gchar *Resizable = "InputDialog|GtkWindow::resizable"; +static gchar *DestroyWithParent = "InputDialog|GtkWindow::destroy_with_parent"; +static gchar *Icon = "InputDialog|GtkWindow::icon"; + +static gchar *Role = "InputDialog|GtkWindow::role"; +static gchar *TypeHint = "InputDialog|GtkWindow::type_hint"; +static gchar *SkipTaskbar = "InputDialog|GtkWindow::skip_taskbar_hint"; +static gchar *SkipPager = "InputDialog|GtkWindow::skip_pager_hint"; +static gchar *Decorated = "InputDialog|GtkWindow::decorated"; +static gchar *Gravity = "InputDialog|GtkWindow::gravity"; +static gchar *Urgency = "InputDialog|GtkWindow::urgency_hint"; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the funtion in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkInputDialog, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_input_dialog_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget = gtk_input_dialog_new (); + + GtkInputDialog *inputdlg = GTK_INPUT_DIALOG (new_widget); + + /* We want it to be treated as a normal window. */ + gtk_window_set_type_hint (GTK_WINDOW (new_widget), + GDK_WINDOW_TYPE_HINT_NORMAL); + + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + gb_widget_create_from (inputdlg->save_button, + data->action == GB_CREATING ? "save_button" : NULL); + gb_widget_set_child_name (inputdlg->save_button, GladeChildSaveButton); + /* We need to set it sensitive so the user can select it. */ + gtk_widget_set_sensitive (inputdlg->save_button, TRUE); + + gb_widget_create_from (inputdlg->close_button, + data->action == GB_CREATING ? "close_button" : NULL); + gb_widget_set_child_name (inputdlg->close_button, GladeChildCloseButton); + + gtk_object_set_data (GTK_OBJECT (new_widget), TypeHint, + GINT_TO_POINTER (GLADE_TYPE_HINT_DIALOG_INDEX)); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_input_dialog_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + gb_window_create_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_input_dialog_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_window_get_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_input_dialog_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gb_window_set_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkInputDialog, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_input_dialog_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_input_dialog_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *wname, *child_name; + + if (data->create_widget) + { + source_add (data, " %s = gtk_input_dialog_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + gb_window_write_standard_source (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, AutoShrink, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); + + /* We output the source code for the buttons here, but we don't want them + to be created. We need to remember the dialog's name since data->wname + will be overwritten. */ + wname = g_strdup (data->wname); + + source_add (data, "\n"); + + child_name = (gchar*) gtk_widget_get_name (GTK_INPUT_DIALOG (widget)->save_button); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_INPUT_DIALOG (%s)->save_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_INPUT_DIALOG (widget)->save_button, + data); + + child_name = (gchar*) gtk_widget_get_name (GTK_INPUT_DIALOG (widget)->close_button); + child_name = source_create_valid_identifier (child_name); + source_add (data, " %s = GTK_INPUT_DIALOG (%s)->close_button;\n", + child_name, wname); + g_free (child_name); + data->create_widget = FALSE; + gb_widget_write_source (GTK_INPUT_DIALOG (widget)->close_button, + data); + + g_free (wname); + + data->write_children = FALSE; +} + + +static GtkWidget * +gb_input_dialog_get_child (GtkWidget * widget, + const gchar * child_name) +{ + if (!strcmp (child_name, GladeChildSaveButton)) + return GTK_INPUT_DIALOG (widget)->save_button; + else if (!strcmp (child_name, GladeChildCloseButton)) + return GTK_INPUT_DIALOG (widget)->close_button; + else + return NULL; +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_input_dialog_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_input_dialog_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = inputdialog_xpm; + gbwidget.tooltip = _("Input Dialog"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_input_dialog_new; + gbwidget.gb_widget_get_child = gb_input_dialog_get_child; + gbwidget.gb_widget_create_properties = gb_input_dialog_create_properties; + gbwidget.gb_widget_get_properties = gb_input_dialog_get_properties; + gbwidget.gb_widget_set_properties = gb_input_dialog_set_properties; + gbwidget.gb_widget_write_source = gb_input_dialog_write_source; + gbwidget.gb_widget_destroy = gb_window_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_input_dialog_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gblabel.c b/tools/glade/glade/gbwidgets/gblabel.c new file mode 100644 index 00000000..dbfd9879 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gblabel.c @@ -0,0 +1,885 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <math.h> +#include <string.h> + +#include <gtk/gtkcombo.h> +#include <gtk/gtkcombobox.h> +#include <gtk/gtkentry.h> +#include <gtk/gtkexpander.h> +#include <gtk/gtkfilechooserbutton.h> +#include <gtk/gtklabel.h> +#include <gtk/gtklist.h> +#include <gtk/gtklistitem.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtknotebook.h> +#include <gtk/gtkeventbox.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/label.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Label = "GtkLabel::label"; +static gchar *UseUnderline = "GtkLabel::use_underline"; +static gchar *UseMarkup = "GtkLabel::use_markup"; +static gchar *Justify = "GtkLabel::justify"; +static gchar *Wrap = "GtkLabel::wrap"; +static gchar *XAlign = "Label|GtkMisc::xalign"; +static gchar *YAlign = "Label|GtkMisc::yalign"; +static gchar *XPad = "Label|GtkMisc::xpad"; +static gchar *YPad = "Label|GtkMisc::ypad"; +static gchar *Selectable = "GtkLabel::selectable"; + +static gchar *Ellipsize = "GtkLabel::ellipsize"; +static gchar *WidthChars = "GtkLabel::width_chars"; +static gchar *SingleLineMode = "GtkLabel::single_line_mode"; +static gchar *Angle = "GtkLabel::angle"; + +static gchar *FocusTarget = "GtkLabel::mnemonic_widget"; + + +static const gchar *GbJustifyChoices[] = +{ + "Left", + "Right", + "Center", + "Fill", + NULL +}; +static const gint GbJustifyValues[] = +{ + GTK_JUSTIFY_LEFT, + GTK_JUSTIFY_RIGHT, + GTK_JUSTIFY_CENTER, + GTK_JUSTIFY_FILL +}; +static const gchar *GbJustifySymbols[] = +{ + "GTK_JUSTIFY_LEFT", + "GTK_JUSTIFY_RIGHT", + "GTK_JUSTIFY_CENTER", + "GTK_JUSTIFY_FILL" +}; + +static const gchar *GbEllipsizeChoices[] = +{ + "None", + "Start", + "Middle", + "End", + NULL +}; +static const gint GbEllipsizeValues[] = +{ + PANGO_ELLIPSIZE_NONE, + PANGO_ELLIPSIZE_START, + PANGO_ELLIPSIZE_MIDDLE, + PANGO_ELLIPSIZE_END +}; +static const gchar *GbEllipsizeSymbols[] = +{ + "PANGO_ELLIPSIZE_NONE", + "PANGO_ELLIPSIZE_START", + "PANGO_ELLIPSIZE_MIDDLE", + "PANGO_ELLIPSIZE_END" +}; + + +static void gb_label_get_focus_targets (GtkWidget * widget, + GList ** focus_targets); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkLabel, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_label_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + new_widget = gtk_label_new (data->name); + + /* If we are creating a new label in a table or in an event box in a table + set it to left-aligned, since that is what is usually wanted. */ + if (data->action == GB_CREATING && data->parent + && (GTK_IS_TABLE (data->parent) + || (GTK_IS_EVENT_BOX (data->parent) && data->parent->parent + && GTK_IS_TABLE (data->parent->parent)))) + { + gtk_misc_set_alignment (GTK_MISC (new_widget), 0.0, 0.5); + } + + return new_widget; +} + + + +void +gb_label_create_standard_properties (GtkWidget * widget, + GbWidgetCreateArgData * data, + const char *label_p, + const char *use_underline_p, + const char *use_markup_p, + const char *justify_p, + const char *wrap_p, + const char *selectable_p, + const char *xalign_p, + const char *yalign_p, + const char *xpad_p, + const char *ypad_p, + const char *focus_target_p, + const char *ellipsize_p, + const char *width_chars_p, + const char *single_line_mode_p, + const char *angle_p) +{ + GtkWidget *combo; + + property_add_text (label_p, _("Label:"), _("The text to display"), 5); + property_add_bool (use_underline_p, _("Use Underline:"), + _("If the text includes an underlined access key")); + property_add_bool (use_markup_p, _("Use Markup:"), + _("If the text includes pango markup")); + property_add_choice (justify_p, _("Justify:"), + _("The justification of the lines of the label"), + GbJustifyChoices); + property_add_bool (wrap_p, _("Wrap Text:"), + _("If the text is wrapped to fit within the width of the label")); + property_add_bool (selectable_p, _("Selectable:"), + _("If the label text can be selected with the mouse")); + property_add_float_range (xalign_p, _("X Align:"), + _("The horizontal alignment of the entire label"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (yalign_p, _("Y Align:"), + _("The vertical alignment of the entire label"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_int_range (xpad_p, _("X Pad:"), _("The horizontal padding"), + 0, 1000, 1, 10, 1); + property_add_int_range (ypad_p, _("Y Pad:"), _("The vertical padding"), + 0, 1000, 1, 10, 1); + property_add_combo (focus_target_p, _("Focus Target:"), + _("The widget to set the keyboard focus to when the underlined access key is used"), + NULL); + combo = property_get_value_widget (focus_target_p); + gtk_editable_set_editable (GTK_EDITABLE (GTK_COMBO (combo)->entry), FALSE); + /*gtk_combo_set_value_in_list (GTK_COMBO (combo), TRUE, TRUE);*/ + + property_add_choice (ellipsize_p, _("Ellipsize:"), + _("How to ellipsize the string"), + GbEllipsizeChoices); + property_add_int_range (width_chars_p, _("Width in Chars:"), + _("The width of the label in characters"), + -1, 1000, 1, 10, 1); + property_add_bool (single_line_mode_p, _("Single Line Mode:"), + _("If the label is only given enough height for a single line")); + property_add_float_range (angle_p, _("Angle:"), + _("The angle of the label text"), + 0, 360, 1, 10, 1, 2); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_label_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + gb_label_create_standard_properties (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + + +/* This tries to find a parent widget of a label that would be used for + mnemonic activation, e.g. a button or a menuitem. If it finds one, it + returns TRUE. */ +static gboolean +gb_label_find_mnemonic_widget (GtkWidget *widget) +{ + GtkWidget *parent; + + parent = widget->parent; + + while (parent) + { + if (GTK_IS_EXPANDER (parent)) + { + if (gtk_expander_get_label_widget (GTK_EXPANDER (parent)) == widget) + return TRUE; + else + return FALSE; + } + if (GTK_WIDGET_GET_CLASS (parent)->activate_signal) + { + return TRUE; + } + if (GTK_IS_MENU_ITEM (parent)) + { + return TRUE; + } + + parent = parent->parent; + } + + return FALSE; +} + + +void +gb_label_get_standard_properties (GtkWidget * widget, + GbWidgetGetArgData * data, + const char *label_p, + const char *use_underline_p, + const char *use_markup_p, + const char *justify_p, + const char *wrap_p, + const char *selectable_p, + const char *xalign_p, + const char *yalign_p, + const char *xpad_p, + const char *ypad_p, + const char *focus_target_p, + const char *ellipsize_p, + const char *width_chars_p, + const char *single_line_mode_p, + const char *angle_p) +{ + const gchar *label_text; + PangoEllipsizeMode ellipsize_mode; + gint i, width_chars; + gboolean single_line_mode; + gfloat angle; + + label_text = gtk_label_get_label (GTK_LABEL (widget)); + gb_widget_output_translatable_text (data, label_p, label_text); + + gb_widget_output_bool (data, use_underline_p, + gtk_label_get_use_underline (GTK_LABEL (widget))); + gb_widget_output_bool (data, use_markup_p, + GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), use_markup_p))); + + for (i = 0; i < sizeof (GbJustifyValues) / sizeof (GbJustifyValues[0]); i++) + { + if (GbJustifyValues[i] == GTK_LABEL (widget)->jtype) + gb_widget_output_choice (data, justify_p, i, GbJustifySymbols[i]); + } + gb_widget_output_bool (data, wrap_p, GTK_LABEL (widget)->wrap); + gb_widget_output_bool (data, selectable_p, + gtk_label_get_selectable (GTK_LABEL (widget))); + gb_widget_output_float (data, xalign_p, GTK_MISC (widget)->xalign); + gb_widget_output_float (data, yalign_p, GTK_MISC (widget)->yalign); + gb_widget_output_int (data, xpad_p, GTK_MISC (widget)->xpad); + gb_widget_output_int (data, ypad_p, GTK_MISC (widget)->ypad); + + /* Labels not in buttons may have a focus target widget. */ + if (!gb_label_find_mnemonic_widget (widget)) + { + gchar *accel_target; + + accel_target = gtk_object_get_data (GTK_OBJECT (widget), focus_target_p); + + /* If we're showing we need to display the list of possible focus target + widgets. We walk the tree of widgets in this component, and if a + widget has CAN_FOCUS set, we add it to the list. */ + if (data->action == GB_SHOWING) + { + GList *focus_targets = NULL, *standard_items = NULL; + GtkWidget *item, *combo; + + property_set_visible (focus_target_p, TRUE); + + gb_label_get_focus_targets (gtk_widget_get_toplevel (widget), + &focus_targets); + property_set_combo_strings (focus_target_p, focus_targets); + g_list_free (focus_targets); + + combo = property_get_value_widget (focus_target_p); + + item = gtk_list_item_new_with_label (_("Auto")); + gtk_widget_show (item); + standard_items = g_list_append (standard_items, item); + + item = gtk_list_item_new (); + gtk_widget_set_sensitive (item, FALSE); + gtk_widget_show (item); + standard_items = g_list_append (standard_items, item); + gtk_combo_set_item_string (GTK_COMBO (combo), GTK_ITEM (item), ""); + + gtk_list_prepend_items (GTK_LIST (GTK_COMBO (combo)->list), + standard_items); + + if (!accel_target) + { + accel_target = _("Auto"); + } + gb_widget_output_combo (data, focus_target_p, accel_target); + } + else + { + /* When saving, we only save the property if it has been set. */ + if (accel_target) + { + /* First check that the widget is still there, and if it isn't + just skip it. */ + if (glade_util_find_widget (gtk_widget_get_toplevel (widget), + accel_target)) + { + gb_widget_output_combo (data, focus_target_p, accel_target); + } + } + else + { + /* If no target has been set, and the label has an underlined + key, we try to find a default target and save that. */ + if (gtk_label_get_use_underline (GTK_LABEL (widget))) + { + GtkWidget *accel_target; + + accel_target = glade_util_find_default_accelerator_target (widget); + if (accel_target) + { + gb_widget_output_string (data, focus_target_p, gtk_widget_get_name (accel_target)); + } + } + } + } + } + else + { + if (data->action == GB_SHOWING) + { + property_set_visible (focus_target_p, FALSE); + } + } + + ellipsize_mode = gtk_label_get_ellipsize (GTK_LABEL (widget)); + for (i = 0; i < sizeof (GbEllipsizeValues) / sizeof (GbEllipsizeValues[0]); i++) + { + if (GbEllipsizeValues[i] == ellipsize_mode) + gb_widget_output_choice (data, ellipsize_p, i, GbEllipsizeSymbols[i]); + } + + width_chars = gtk_label_get_width_chars (GTK_LABEL (widget)); + gb_widget_output_int (data, width_chars_p, width_chars); + + single_line_mode = gtk_label_get_single_line_mode (GTK_LABEL (widget)); + gb_widget_output_bool (data, single_line_mode_p, single_line_mode); + + angle = gtk_label_get_angle (GTK_LABEL (widget)); + gb_widget_output_float (data, angle_p, angle); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_label_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_label_get_standard_properties (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + +static void +gb_label_get_focus_targets (GtkWidget * widget, + GList ** focus_targets) +{ + /* GtkWidget now has a "mnemonic_activate" signal, which some widgets use + to set focus to themselves or a child. So it is difficult to know if + a widget can be a focus target. We can't just use CAN_FOCUS as before. + For now I've just added some specific widgets. */ + if (GB_IS_GB_WIDGET (widget) + && (GTK_WIDGET_CAN_FOCUS (widget) + || GTK_IS_COMBO_BOX (widget) || GTK_IS_FILE_CHOOSER_BUTTON (widget) + || GLADE_IS_CUSTOM_WIDGET (widget))) + { + *focus_targets = g_list_insert_sorted (*focus_targets, + (gchar*) gtk_widget_get_name (widget), + (GCompareFunc) g_utf8_collate); + } + + if (GTK_IS_CONTAINER (widget)) + { + gtk_container_forall (GTK_CONTAINER (widget), + (GtkCallback) gb_label_get_focus_targets, + focus_targets); + } +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +void +gb_label_set_standard_properties (GtkWidget * widget, + GbWidgetSetArgData * data, + const char *label_p, + const char *use_underline_p, + const char *use_markup_p, + const char *justify_p, + const char *wrap_p, + const char *selectable_p, + const char *xalign_p, + const char *yalign_p, + const char *xpad_p, + const char *ypad_p, + const char *focus_target_p, + const char *ellipsize_p, + const char *width_chars_p, + const char *single_line_mode_p, + const char *angle_p) +{ + gchar *label, *justify, *accel_target, *ellipsize_mode; + const gchar *label_text; + gfloat xalign, yalign, angle; + gint xpad, ypad, i, width_chars; + gboolean wrap, selectable, set_alignment = FALSE, set_padding = FALSE; + gboolean use_underline, use_markup, single_line_mode; + gboolean set_label = FALSE; + + use_underline = gb_widget_input_bool (data, use_underline_p); + if (data->apply) + gtk_label_set_use_underline (GTK_LABEL (widget), use_underline); + + use_markup = gb_widget_input_bool (data, use_markup_p); + if (data->apply) + { + set_label = TRUE; + gtk_object_set_data (GTK_OBJECT (widget), use_markup_p, + GINT_TO_POINTER (use_markup)); + } + + label = gb_widget_input_text (data, label_p); + if (data->apply) + { + set_label = TRUE; + label_text = label; + } + else + { + label_text = gtk_label_get_label (GTK_LABEL (widget)); + } + + if (set_label) + { + gboolean prev_use_markup; + + use_markup = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + use_markup_p)); + + /* We try to parse the markup here, and if it isn't valid, we will + turn use_markup off and show it as plain text. */ + if (use_markup) + { + GError *error = NULL; + gunichar accel_marker = 0; + PangoAttrList *attrs = NULL; + gunichar accel_char = 0; + gchar *text = NULL; + + if (gtk_label_get_use_underline (GTK_LABEL (widget))) + accel_marker = '_'; + + /* We check it is valid markup. If it isn't we will set "use_markup" + to FALSE. Note that we don't need attrs, text, or accel_char but + it seems to crash otherwise. */ + if (!pango_parse_markup (label_text, -1, accel_marker, &attrs, &text, + &accel_char, &error)) + { + use_markup = FALSE; + g_error_free (error); + } + else + { + if (attrs) + pango_attr_list_unref (attrs); + g_free (text); + } + } + + /* If we are turning use_markup off, we want to do that before setting + the text. If we are turning it on, we want to do it after. */ + prev_use_markup = gtk_label_get_use_markup (GTK_LABEL (widget)); + if (!use_markup && prev_use_markup) + gtk_label_set_use_markup (GTK_LABEL (widget), use_markup); + + gtk_label_set_label (GTK_LABEL (widget), label_text); + + if (use_markup && !prev_use_markup) + gtk_label_set_use_markup (GTK_LABEL (widget), use_markup); + } + + if (data->action == GB_APPLYING) + g_free (label); + + justify = gb_widget_input_choice (data, justify_p); + if (data->apply) + { + for (i = 0; i < sizeof (GbJustifyValues) / sizeof (GbJustifyValues[0]); + i++) + { + if (!strcmp (justify, GbJustifyChoices[i]) + || !strcmp (justify, GbJustifySymbols[i])) + { + gtk_label_set_justify (GTK_LABEL (widget), GbJustifyValues[i]); + break; + } + } + } + + wrap = gb_widget_input_bool (data, wrap_p); + if (data->apply) + gtk_label_set_line_wrap (GTK_LABEL (widget), wrap); + + selectable = gb_widget_input_bool (data, selectable_p); + if (data->apply) + gtk_label_set_selectable (GTK_LABEL (widget), selectable); + + xalign = gb_widget_input_float (data, xalign_p); + if (data->apply) + set_alignment = TRUE; + else + xalign = GTK_MISC (widget)->xalign; + + yalign = gb_widget_input_float (data, yalign_p); + if (data->apply) + set_alignment = TRUE; + else + yalign = GTK_MISC (widget)->yalign; + + if (set_alignment) + gtk_misc_set_alignment (GTK_MISC (widget), xalign, yalign); + + xpad = gb_widget_input_int (data, xpad_p); + if (data->apply) + set_padding = TRUE; + else + xpad = GTK_MISC (widget)->xpad; + + ypad = gb_widget_input_int (data, ypad_p); + if (data->apply) + set_padding = TRUE; + else + ypad = GTK_MISC (widget)->ypad; + + if (set_padding) + gtk_misc_set_padding (GTK_MISC (widget), xpad, ypad); + + /* Labels not in buttons may have a focus target widget. */ + accel_target = gb_widget_input_combo (data, focus_target_p); + if (data->apply) + { + if (!gb_label_find_mnemonic_widget (widget)) + { + if (!strcmp (accel_target, _("Auto"))) + accel_target = NULL; + + gtk_object_set_data_full (GTK_OBJECT (widget), focus_target_p, + g_strdup (accel_target), + accel_target ? g_free : NULL); + } + } + + ellipsize_mode = gb_widget_input_choice (data, ellipsize_p); + if (data->apply) + { + for (i = 0; i < sizeof (GbEllipsizeValues) / sizeof (GbEllipsizeValues[0]); + i++) + { + if (!strcmp (ellipsize_mode, GbEllipsizeChoices[i]) + || !strcmp (ellipsize_mode, GbEllipsizeSymbols[i])) + { + gtk_label_set_ellipsize (GTK_LABEL (widget), + GbEllipsizeValues[i]); + break; + } + } + } + + width_chars = gb_widget_input_int (data, width_chars_p); + if (data->apply) + gtk_label_set_width_chars (GTK_LABEL (widget), width_chars); + + single_line_mode = gb_widget_input_bool (data, single_line_mode_p); + if (data->apply) + gtk_label_set_single_line_mode (GTK_LABEL (widget), single_line_mode); + + angle = gb_widget_input_float (data, angle_p); + if (data->apply) + gtk_label_set_angle (GTK_LABEL (widget), angle); +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_label_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gb_label_set_standard_properties (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkLabel, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_label_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + +void +gb_label_write_standard_source (GtkWidget * widget, + GbWidgetWriteSourceData * data, + const char *label_p, + const char *use_underline_p, + const char *use_markup_p, + const char *justify_p, + const char *wrap_p, + const char *selectable_p, + const char *xalign_p, + const char *yalign_p, + const char *xpad_p, + const char *ypad_p, + const char *focus_target_p, + const char *ellipsize_p, + const char *width_chars_p, + const char *single_line_mode_p, + const char *angle_p) +{ + GtkWidget *accel_target = NULL; + PangoEllipsizeMode ellipsize_mode; + gint i, width_chars; + gboolean single_line_mode; + gfloat angle; + + if (gtk_object_get_data (GTK_OBJECT (widget), use_markup_p)) + source_add (data, " gtk_label_set_use_markup (GTK_LABEL (%s), TRUE);\n", + data->wname); + + /* If there is an underlined accelerator, set up the accel signal. + If the label is in a button or something similar, this is now setup + automatically by GTK+. If the accelerator is being used to set focus + to something like a GtkEntry, we need to set the mnemonic_widget. */ + if (gtk_label_get_use_underline (GTK_LABEL (widget)) + && !gb_label_find_mnemonic_widget (widget)) + { + gchar *target_name = gtk_object_get_data (GTK_OBJECT (widget), + focus_target_p); + if (target_name) + accel_target = glade_util_find_widget (gtk_widget_get_toplevel (widget), target_name); + + if (!accel_target) + accel_target = glade_util_find_default_accelerator_target (widget); + + if (accel_target) + { + target_name = (gchar*) gtk_widget_get_name (accel_target); + target_name = source_create_valid_identifier (target_name); + source_add_to_buffer (data, GLADE_ACCELERATORS, + " gtk_label_set_mnemonic_widget (GTK_LABEL (%s), %s);\n", + data->wname, target_name); + g_free (target_name); + } + } + + if (GTK_LABEL (widget)->jtype != GTK_JUSTIFY_LEFT) + { + for (i = 0; i < sizeof (GbJustifyValues) / sizeof (GbJustifyValues[0]); + i++) + { + if (GbJustifyValues[i] == GTK_LABEL (widget)->jtype) + source_add (data, + " gtk_label_set_justify (GTK_LABEL (%s), %s);\n", + data->wname, GbJustifySymbols[i]); + } + } + + if (GTK_LABEL (widget)->wrap) + source_add (data, " gtk_label_set_line_wrap (GTK_LABEL (%s), TRUE);\n", + data->wname); + + if (gtk_label_get_selectable (GTK_LABEL (widget))) + source_add (data, " gtk_label_set_selectable (GTK_LABEL (%s), TRUE);\n", + data->wname); + + + if (fabs (GTK_MISC (widget)->xalign - 0.5) > 0.0001 + || fabs (GTK_MISC (widget)->yalign - 0.5) > 0.0001) + source_add (data, " gtk_misc_set_alignment (GTK_MISC (%s), %g, %g);\n", + data->wname, GTK_MISC (widget)->xalign, GTK_MISC (widget)->yalign); + + if (GTK_MISC (widget)->xpad != 0 || GTK_MISC (widget)->ypad != 0) + source_add (data, " gtk_misc_set_padding (GTK_MISC (%s), %i, %i);\n", + data->wname, GTK_MISC (widget)->xpad, GTK_MISC (widget)->ypad); + + ellipsize_mode = gtk_label_get_ellipsize (GTK_LABEL (widget)); + if (ellipsize_mode != PANGO_ELLIPSIZE_NONE) + { + for (i = 0; + i < sizeof (GbEllipsizeValues) / sizeof (GbEllipsizeValues[0]); + i++) + { + if (GbEllipsizeValues[i] == ellipsize_mode) + source_add (data, + " gtk_label_set_ellipsize (GTK_LABEL (%s), %s);\n", + data->wname, GbEllipsizeSymbols[i]); + } + } + + width_chars = gtk_label_get_width_chars (GTK_LABEL (widget)); + if (width_chars != -1) + { + source_add (data, + " gtk_label_set_width_chars (GTK_LABEL (%s), %i);\n", + data->wname, width_chars); + } + + single_line_mode = gtk_label_get_single_line_mode (GTK_LABEL (widget)); + if (single_line_mode) + { + source_add (data, + " gtk_label_set_single_line_mode (GTK_LABEL (%s), TRUE);\n", + data->wname); + } + + angle = gtk_label_get_angle (GTK_LABEL (widget)); + if (angle > GLADE_EPSILON) + { + source_add (data, + " gtk_label_set_angle (GTK_LABEL (%s), %g);\n", + data->wname, angle); + } +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_label_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + const gchar *label_text = gtk_label_get_label (GTK_LABEL (widget)); + + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + if (gtk_label_get_use_underline (GTK_LABEL (widget))) + source_add (data, " %s = gtk_label_new_with_mnemonic (%s);\n", + data->wname, + source_make_string_full (label_text, + data->use_gettext && translatable, + context)); + else + source_add (data, " %s = gtk_label_new (%s);\n", + data->wname, + source_make_string_full (label_text, + data->use_gettext && translatable, + context)); + } + + gb_widget_write_standard_source (widget, data); + + gb_label_write_standard_source (widget, data, + Label, UseUnderline, UseMarkup, + Justify, Wrap, Selectable, + XAlign, YAlign, XPad, YPad, + FocusTarget, Ellipsize, WidthChars, + SingleLineMode, Angle); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_label_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_label_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = label_xpm; + gbwidget.tooltip = _("Label"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_label_new; + gbwidget.gb_widget_create_properties = gb_label_create_properties; + gbwidget.gb_widget_get_properties = gb_label_get_properties; + gbwidget.gb_widget_set_properties = gb_label_set_properties; + gbwidget.gb_widget_write_source = gb_label_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_label_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gblayout.c b/tools/glade/glade/gbwidgets/gblayout.c new file mode 100644 index 00000000..aa2b4157 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gblayout.c @@ -0,0 +1,399 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/layout.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *AreaWidth = "GtkLayout::width"; +static gchar *AreaHeight = "GtkLayout::height"; + +/* Child properties. */ +const gchar *GladeLayoutChildX = "GtkLayout::x"; +const gchar *GladeLayoutChildY = "GtkLayout::y"; + + + +/* The default step increment for new layouts. */ +#define GLADE_DEFAULT_STEP_INCREMENT 10 + +/* We only use the step increment property since the other are set + automatically by the GtkLayout, or aren't relevant. */ +static const gchar *HValues[] = { + NULL, NULL, NULL, "GtkLayout::hstep", NULL, NULL, +}; + +static const gchar *VValues[] = { + NULL, NULL, NULL, "GtkLayout::vstep", NULL, NULL, +}; + +static void gb_layout_adjustment_changed (GtkAdjustment *adjustment, + GtkWidget *widget); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkLayout, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_layout_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_layout_new (NULL, NULL); + gtk_layout_set_size (GTK_LAYOUT (new_widget), 400, 400); + + return new_widget; +} + + +static void +gb_layout_adjustment_changed (GtkAdjustment *adjustment, + GtkWidget *widget) +{ + /* We check that this is a widget in the interface being created rather + than part of Glade's interface. */ + if (GB_IS_GB_WIDGET (widget)) + gtk_widget_queue_clear (widget); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_layout_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_int_range (AreaWidth, _("Area Width:"), + _("The width of the layout area"), + 1, 1000, 1, 10, 1); + property_add_int_range (AreaHeight, _("Area Height:"), + _("The height of the layout area"), + 1, 1000, 1, 10, 1); + + property_add_adjustment (HValues, GB_ADJUST_H_LABELS); + property_add_adjustment (VValues, GB_ADJUST_V_LABELS); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_layout_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_widget_output_int (data, AreaWidth, GTK_LAYOUT (widget)->width); + gb_widget_output_int (data, AreaHeight, GTK_LAYOUT (widget)->height); + + gb_widget_output_adjustment (data, HValues, + GTK_LAYOUT (widget)->hadjustment, + "hadjustment"); + gb_widget_output_adjustment (data, VValues, + GTK_LAYOUT (widget)->vadjustment, + "vadjustment"); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_layout_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gint width, height; + gboolean set_size = FALSE; + + width = gb_widget_input_int (data, AreaWidth); + if (data->apply) + set_size = TRUE; + else + width = GTK_LAYOUT (widget)->width; + + height = gb_widget_input_int (data, AreaHeight); + if (data->apply) + set_size = TRUE; + else + height = GTK_LAYOUT (widget)->height; + + if (set_size) + gtk_layout_set_size (GTK_LAYOUT (widget), width, height); + + gb_widget_input_adjustment (data, HValues, GTK_LAYOUT (widget)->hadjustment, + "hadjustment"); + gb_widget_input_adjustment (data, VValues, GTK_LAYOUT (widget)->vadjustment, + "vadjustment"); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkLayout, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_layout_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + +void +gb_layout_add_child (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + gtk_layout_put (GTK_LAYOUT (widget), child, 0, 0); +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_layout_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_layout_new (NULL, NULL);\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + source_add (data, " gtk_layout_set_size (GTK_LAYOUT (%s), %i, %i);\n", + data->wname, + GTK_LAYOUT (widget)->width, + GTK_LAYOUT (widget)->height); + + source_add (data, + " GTK_ADJUSTMENT (GTK_LAYOUT (%s)->hadjustment)->step_increment = %g;\n", + data->wname, + GTK_ADJUSTMENT (GTK_LAYOUT (widget)->hadjustment)->step_increment); + source_add (data, + " GTK_ADJUSTMENT (GTK_LAYOUT (%s)->vadjustment)->step_increment = %g;\n", + data->wname, + GTK_ADJUSTMENT (GTK_LAYOUT (widget)->vadjustment)->step_increment); +} + + +/* + * Creates the child packing properties for children of this widget. + */ +void +gb_layout_create_child_properties (GtkWidget * widget, + GbWidgetCreateChildArgData * data) +{ + property_add_int_range (GladeLayoutChildX, _("X:"), + _("The X coordinate of the widget in the GtkLayout"), + 0, 10000, 1, 10, 1); + property_add_int_range (GladeLayoutChildY, _("Y:"), + _("The Y coordinate of the widget in the GtkLayout"), + 0, 10000, 1, 10, 1); +} + + +/* Shows or saves the child properties of a child of a layout. */ +void +gb_layout_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + gint x, y; + + if (data->action == GB_SAVING) + save_start_tag (data, "packing"); + + gtk_container_child_get (GTK_CONTAINER (widget), child, + "x", &x, + "y", &y, + NULL); + + gb_widget_output_int (data, GladeLayoutChildX, x); + gb_widget_output_int (data, GladeLayoutChildY, y); + + if (data->action == GB_SAVING) + save_end_tag (data, "packing"); +} + + +/* Applies or loads the child properties of a child of a layout. */ +void +gb_layout_set_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + gint x, y; + + x = gb_widget_input_int (data, GladeLayoutChildX); + if (data->apply) + gtk_container_child_set (GTK_CONTAINER (widget), child, + "x", x, + NULL); + + y = gb_widget_input_int (data, GladeLayoutChildY); + if (data->apply) + gtk_container_child_set (GTK_CONTAINER (widget), child, + "y", y, + NULL); +} + + +/* Outputs source to add a child widget to a layout. */ +static void +gb_layout_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + gint x, y; + + gtk_container_child_get (GTK_CONTAINER (parent), child, + "x", &x, + "y", &y, + NULL); + source_add (data, + " gtk_layout_put (GTK_LAYOUT (%s), %s, %i, %i);\n", + parent_name, data->wname, x, y); +} + + +static gboolean +gb_layout_emission_hook (GSignalInvocationHint *ihint, + guint n_param_values, + const GValue *param_values, + gpointer data) +{ + GtkObject *object, *hadjustment, *vadjustment; + GtkObject *old_hadjustment, *old_vadjustment; + + object = g_value_get_object (param_values); + g_return_val_if_fail (GTK_IS_LAYOUT (object), FALSE); + + hadjustment = g_value_get_object (param_values + 1); + vadjustment = g_value_get_object (param_values + 2); + + old_hadjustment = gtk_object_get_data (object, "scrollhadjustment"); + if (hadjustment != old_hadjustment) + { + gtk_object_set_data (object, "scrollhadjustment", hadjustment); + + if (hadjustment) + { + gtk_signal_connect (hadjustment, "value_changed", + (GtkSignalFunc) gb_layout_adjustment_changed, + object); + + GTK_ADJUSTMENT (hadjustment)->step_increment = GLADE_DEFAULT_STEP_INCREMENT; + if (property_get_widget () == GTK_WIDGET (object)) + { + property_set_auto_apply (FALSE); + property_set_float (HValues[3], GLADE_DEFAULT_STEP_INCREMENT); + property_set_auto_apply (TRUE); + } + } + } + + old_vadjustment = gtk_object_get_data (object, "scrollvadjustment"); + if (vadjustment != old_vadjustment) + { + gtk_object_set_data (object, "scrollvadjustment", vadjustment); + + if (vadjustment) + { + gtk_signal_connect (vadjustment, "value_changed", + (GtkSignalFunc) gb_layout_adjustment_changed, + object); + + GTK_ADJUSTMENT (vadjustment)->step_increment = GLADE_DEFAULT_STEP_INCREMENT; + if (property_get_widget () == GTK_WIDGET (object)) + { + property_set_auto_apply (FALSE); + property_set_float (VValues[3], GLADE_DEFAULT_STEP_INCREMENT); + property_set_auto_apply (TRUE); + } + } + } + + return TRUE; +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_layout_init () +{ + GtkWidgetClass *klass; + + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_layout_get_type(); + + /* Add a signal emission hook so we can connect signal handlers to the + scrollbar adjustments to redraw the layout when necessary. This will also + work for subclasses of GtkLayout. */ + klass = gtk_type_class (gtk_layout_get_type ()); + g_signal_add_emission_hook (klass->set_scroll_adjustments_signal, 0, + gb_layout_emission_hook, NULL, NULL); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = layout_xpm; + gbwidget.tooltip = _("Layout"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_layout_new; + gbwidget.gb_widget_create_properties = gb_layout_create_properties; + gbwidget.gb_widget_get_properties = gb_layout_get_properties; + gbwidget.gb_widget_set_properties = gb_layout_set_properties; + gbwidget.gb_widget_write_source = gb_layout_write_source; + gbwidget.gb_widget_create_child_properties = gb_layout_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_layout_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_layout_set_child_properties; + gbwidget.gb_widget_write_add_child_source = gb_layout_write_add_child_source; + gbwidget.gb_widget_add_child = gb_layout_add_child; +/* + gbwidget.gb_widget_create_popup_menu = gb_layout_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gblist.c b/tools/glade/glade/gbwidgets/gblist.c new file mode 100644 index 00000000..e333cd4c --- /dev/null +++ b/tools/glade/glade/gbwidgets/gblist.c @@ -0,0 +1,205 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtklist.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/list.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Mode = "GtkList::selection_mode"; + +static const gchar *GbModeChoices[] = +{"Single", "Browse", "Multiple", NULL}; +static const gint GbModeValues[] = +{ + GTK_SELECTION_SINGLE, + GTK_SELECTION_BROWSE, + GTK_SELECTION_MULTIPLE +}; +static const gchar *GbModeSymbols[] = +{ + "GTK_SELECTION_SINGLE", + "GTK_SELECTION_BROWSE", + "GTK_SELECTION_MULTIPLE" +}; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkList, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +/* + GtkWidget* + gb_list_new(GbWidgetNewData *data) + { + + } + */ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_list_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Mode, _("Select Mode:"), + _("The selection mode of the list"), + GbModeChoices); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_list_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == GTK_LIST (widget)->selection_mode) + gb_widget_output_choice (data, Mode, i, GbModeSymbols[i]); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_list_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *mode; + gint i; + + mode = gb_widget_input_choice (data, Mode); + if (data->apply) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (!strcmp (mode, GbModeChoices[i]) + || !strcmp (mode, GbModeSymbols[i])) + { + gtk_list_set_selection_mode (GTK_LIST (widget), GbModeValues[i]); + break; + } + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkList, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_list_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_list_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_list_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (GTK_LIST (widget)->selection_mode != GTK_SELECTION_SINGLE) + { + for (i = 0; i < sizeof (GbModeValues) / sizeof (GbModeValues[0]); i++) + { + if (GbModeValues[i] == GTK_LIST (widget)->selection_mode) + source_add (data, + " gtk_list_set_selection_mode (GTK_LIST (%s), %s);\n", + data->wname, GbModeSymbols[i]); + } + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_list_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_list_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = list_xpm; + gbwidget.tooltip = _("List"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_list_create_properties; + gbwidget.gb_widget_get_properties = gb_list_get_properties; + gbwidget.gb_widget_set_properties = gb_list_set_properties; + gbwidget.gb_widget_write_source = gb_list_write_source; +/* + gbwidget.gb_widget_new = gb_list_new; + gbwidget.gb_widget_create_popup_menu = gb_list_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gblistitem.c b/tools/glade/glade/gbwidgets/gblistitem.c new file mode 100644 index 00000000..70a0cd9f --- /dev/null +++ b/tools/glade/glade/gbwidgets/gblistitem.c @@ -0,0 +1,182 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtklabel.h> +#include <gtk/gtklistitem.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenuitem.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/listitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Label = "GtkListItem::label"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkListItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_list_item_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_CREATING) + new_widget = gtk_list_item_new_with_label (data->name); + else + { + new_widget = gtk_list_item_new (); + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder()); + } + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_list_item_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_text (Label, _("Label:"), _("The text to display"), 2); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_list_item_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_widget_output_child_label (widget, data, Label); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_list_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gb_widget_input_child_label (widget, data, Label); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkListItem, with signals pointing to + * other functions in this file. + */ +static void +gb_list_item_create_popup_menu (GtkWidget * widget, + GbWidgetCreateMenuData * data) +{ + /* Add command to remove child label. */ + gb_widget_create_child_label_popup_menu (widget, data); +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_list_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkWidget *child = GTK_BIN (widget)->child; + const gchar *label_text; + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + if (child && GTK_IS_LABEL (child) && !GB_IS_GB_WIDGET (child)) + { + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + label_text = gtk_label_get_text (GTK_LABEL (child)); + source_add (data, " %s = gtk_list_item_new_with_label (%s);\n", + data->wname, + source_make_string_full (label_text, data->use_gettext && translatable, context)); + } + else + { + source_add (data, " %s = gtk_list_item_new ();\n", data->wname); + } + } + + gb_widget_write_standard_source (widget, data); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_list_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_list_item_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = listitem_xpm; + gbwidget.tooltip = _("List Item"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_list_item_new; + gbwidget.gb_widget_create_properties = gb_list_item_create_properties; + gbwidget.gb_widget_get_properties = gb_list_item_get_properties; + gbwidget.gb_widget_set_properties = gb_list_item_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_list_item_create_popup_menu; + gbwidget.gb_widget_write_source = gb_list_item_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbmenu.c b/tools/glade/glade/gbwidgets/gbmenu.c new file mode 100644 index 00000000..4655228e --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbmenu.c @@ -0,0 +1,211 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkmenu.h> +#include "../gb.h" +#include "../glade_gnome.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/popupmenu.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkMenu, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_menu_new(GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_menu_new (); + + /* We create an accelerator table/group so that we can install accels + easily. */ + gtk_menu_set_accel_group (GTK_MENU (new_widget), gtk_accel_group_new ()); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +/* + static void + gb_menu_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) + { + + } + */ + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +/* + static void + gb_menu_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) + { + + } + */ + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +/* + static void + gb_menu_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) + { + + } + */ + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkMenu, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_menu_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_menu_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ +#ifdef USE_GNOME + /* For Gnome projects the menus are created using GnomeUIInfo structs, so + we just create the start of the struct here, and output code to fill + the menu from the GnomeUIInfo structs. */ + if (data->project->gnome_support) + { + GtkWidget *attach_widget; + + glade_gnome_start_menu_source (GTK_MENU_SHELL (widget), data); + + /* We only need to create the toplevel menu. */ + attach_widget = gtk_menu_get_attach_widget (GTK_MENU (widget)); + if (attach_widget == NULL || GTK_IS_OPTION_MENU (attach_widget)) + { + if (data->create_widget) + { + source_add (data, " %s = gtk_menu_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + data->need_accel_group = TRUE; + source_add (data, + " gnome_app_fill_menu (GTK_MENU_SHELL (%s), %s_uiinfo,\n" + " accel_group, FALSE, 0);\n", + data->wname, data->real_wname); + } + + return; + } +#endif + + if (data->create_widget) + { + source_add (data, " %s = gtk_menu_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + +#if 0 + gchar *accel_group_decl; + + /* I don't think we need this for GTK+ 2.0. */ + accel_group_decl = g_strdup_printf (" GtkAccelGroup *%s_accels;\n", + data->real_wname); + source_ensure_decl (data, accel_group_decl); + source_add (data, + " %s_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (%s));\n", + data->wname, data->wname); + g_free (accel_group_decl); +#endif +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_menu_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_menu_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = popupmenu_xpm; + gbwidget.tooltip = _("Popup Menu"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_menu_new; + gbwidget.gb_widget_write_source = gb_menu_write_source; +/* + gbwidget.gb_widget_create_properties = gb_menu_create_properties; + gbwidget.gb_widget_get_properties = gb_menu_get_properties; + gbwidget.gb_widget_set_properties = gb_menu_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_menu_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbmenubar.c b/tools/glade/glade/gbwidgets/gbmenubar.c new file mode 100644 index 00000000..c756094d --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbmenubar.c @@ -0,0 +1,552 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkbutton.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenubar.h> +#include <gtk/gtkimagemenuitem.h> +#include <gtk/gtkstock.h> +#include "../gb.h" +#include "../glade_gnome.h" +#include "../glade_menu_editor.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/menubar.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *PackDirection = "GtkMenuBar::pack_direction"; +static gchar *ChildPackDirection = "GtkMenuBar::child_pack_direction"; + + +static const gchar *GbPackDirectionChoices[] = +{ + "Left to Right", + "Right to Left", + "Top to Bottom", + "Bottom to Top", + NULL +}; +static const gint GbPackDirectionValues[] = +{ + GTK_PACK_DIRECTION_LTR, + GTK_PACK_DIRECTION_RTL, + GTK_PACK_DIRECTION_TTB, + GTK_PACK_DIRECTION_BTT +}; +static const gchar *GbPackDirectionSymbols[] = +{ + "GTK_PACK_DIRECTION_LTR", + "GTK_PACK_DIRECTION_RTL", + "GTK_PACK_DIRECTION_TTB", + "GTK_PACK_DIRECTION_BTT" +}; + +static void on_menu_bar_size_request (GtkWidget * widget, + GtkRequisition *requisition, + gpointer data); +static void gb_menu_bar_on_edit_menu (GtkWidget *button, + gpointer data); +static void gb_menu_bar_on_edit_menu_activate (GtkWidget *menuitem, + GtkWidget *menubar); + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + + +static GtkWidget* +gb_menu_bar_add_menu (GtkWidget *menu, const gchar *label) +{ + GtkWidget *menuitem, *child_menu; + + menuitem = gb_widget_new ("GtkMenuItem", NULL); + gtk_label_set_text_with_mnemonic (GTK_LABEL (GTK_BIN (menuitem)->child), + label); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (menu), menuitem); + + child_menu = gb_widget_new ("GtkMenu", NULL); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), child_menu); + + return child_menu; +} + + +/* This returns the name to use given the widget's label. Spaces are converted + to underscores, and '.' and '_' chars are ignore, e.g. '_Open...' -> 'Open'. + The returned string should be freed. */ +static char* +gb_menu_bar_generate_item_name (const gchar *label) +{ + char *name, *dest; + const char *src; + + /* We never add characters, so name is never longer than label. I think this + is OK for UTF-8. */ + name = g_malloc (strlen (label) + 1); + for (src = label, dest = name; *src; src++) + { + if (*src == ' ') + *dest++ = '_'; + else if (*src == '.') + continue; + else if (*src == '_') + continue; + else + *dest++ = *src; + } + *dest = '\0'; + + return name; +} + + +/* This adds an "activate" signal handler to the menuitem. */ +static void +gb_menu_bar_add_item_handler (GtkWidget *menuitem) +{ + GladeWidgetData *wdata; + GladeSignal *signal; + const char *name; + + wdata = (GladeWidgetData*) gtk_object_get_data (GTK_OBJECT(menuitem), + GB_WIDGET_DATA_KEY); + if (wdata == NULL) + { + g_warning ("Widget has no GladeWidgetData attached"); + return; + } + + + name = gtk_widget_get_name (menuitem); + + signal = g_new (GladeSignal, 1); + signal->name = g_strdup ("activate"); + signal->handler = g_strdup_printf ("on_%s_activate", name); + signal->object = NULL; + signal->after = FALSE; + signal->data = NULL; + signal->last_modification_time = time (NULL); + wdata->signals = g_list_append (wdata->signals, signal); +} + +static void +gb_menu_bar_add_stock_item (GtkWidget *menu, const gchar *stock_id) +{ + GtkWidget *menuitem; + char *label_text, *name; + + menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL); + label_text = glade_util_get_label_text (GTK_BIN (menuitem)->child); + name = gb_menu_bar_generate_item_name (label_text); + gb_widget_create_from (menuitem, name); + g_free (name); + g_free (label_text); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (menu), menuitem); + + /* For stock items we also have to store the stock_id. */ + gtk_object_set_data_full (GTK_OBJECT (menuitem), GladeMenuItemStockIDKey, + g_strdup (stock_id), g_free); + + gb_menu_bar_add_item_handler (menuitem); +} + + +static void +gb_menu_bar_add_item (GtkWidget *menu, const gchar *label) +{ + GtkWidget *menuitem; + char *name; + + menuitem = gtk_menu_item_new_with_mnemonic (label); + name = gb_menu_bar_generate_item_name (label); + gb_widget_create_from (menuitem, name); + g_free (name); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (menu), menuitem); + + gb_menu_bar_add_item_handler (menuitem); +} + + +static void +gb_menu_bar_add_separator (GtkWidget *menu) +{ + GtkWidget *menuitem; + + menuitem = gb_widget_new ("GtkSeparatorMenuItem", NULL); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (menu), menuitem); +} + + +static void +gb_menu_bar_setup_initial_menus (GtkWidget *widget) +{ + GtkWidget *menu; + + /* FIXME: I'm not sure if we should translate the non-stock labels or not. */ + menu = gb_menu_bar_add_menu (widget, _("_File")); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_NEW); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_OPEN); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_SAVE); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_SAVE_AS); + gb_menu_bar_add_separator (menu); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_QUIT); + + menu = gb_menu_bar_add_menu (widget, _("_Edit")); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_CUT); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_COPY); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_PASTE); + gb_menu_bar_add_stock_item (menu, GTK_STOCK_DELETE); + + menu = gb_menu_bar_add_menu (widget, _("_View")); + + menu = gb_menu_bar_add_menu (widget, _("_Help")); + gb_menu_bar_add_item (menu, _("_About")); +} + + +/* + * Creates a new GtkWidget of class GtkMenuBar, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_menu_bar_new(GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + new_widget = gtk_menu_bar_new (); + + gtk_signal_connect_after (GTK_OBJECT (new_widget), "size_request", + GTK_SIGNAL_FUNC (on_menu_bar_size_request), + NULL); + + if (data->action == GB_CREATING) + { +#ifdef USE_GNOME + if (glade_project_get_gnome_support (data->project)) + glade_gnome_setup_initial_menus (new_widget); + else + gb_menu_bar_setup_initial_menus (new_widget); +#else + gb_menu_bar_setup_initial_menus (new_widget); +#endif + } + + return new_widget; +} + + +static void +on_menu_bar_size_request (GtkWidget * widget, + GtkRequisition *requisition, + gpointer data) +{ + /* Make sure we request a decent size. If we don't do this, when a menubar + is created it appears about 3 pixels high which is not very good. */ + requisition->width = MAX (requisition->width, 32); + requisition->height = MAX (requisition->height, 24); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_menu_bar_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) +{ + GtkWidget *property_table, *button; + gint property_table_row; + + property_add_choice (PackDirection, _("Pack Direction:"), + _("The pack direction of the menubar"), + GbPackDirectionChoices); + property_add_choice (ChildPackDirection, _("Child Direction:"), + _("The child pack direction of the menubar"), + GbPackDirectionChoices); + + /* Add a button for editing the menubar. */ + property_table = property_get_table_position (&property_table_row); + button = gtk_button_new_with_label (_("Edit Menus...")); + gtk_widget_show (button); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (gb_menu_bar_on_edit_menu), NULL); + gtk_table_attach (GTK_TABLE (property_table), button, 0, 3, + property_table_row, property_table_row + 1, + GTK_FILL, GTK_FILL, 10, 10); +} + + +/* Make window behave like a dialog */ +static void +dialogize (GtkWidget *menued, GtkWidget *parent_widget) +{ + GtkWidget *transient_parent; + + gtk_signal_connect (GTK_OBJECT (menued), "key_press_event", + GTK_SIGNAL_FUNC (glade_util_check_key_is_esc), + GINT_TO_POINTER (GladeEscDestroys)); + transient_parent = glade_util_get_toplevel (parent_widget); + if (GTK_IS_WINDOW (transient_parent)) + { + gtk_window_set_transient_for (GTK_WINDOW (menued), + GTK_WINDOW (transient_parent)); + } +} + +static void +gb_menu_bar_on_edit_menu (GtkWidget *button, + gpointer data) +{ + GtkWidget *menubar, *menued; + + menubar = property_get_widget (); + g_return_if_fail (GTK_IS_MENU_BAR (menubar)); + + menued = glade_menu_editor_new (current_project, GTK_MENU_SHELL (menubar)); + dialogize (menued, button); + gtk_widget_show (GTK_WIDGET (menued)); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_menu_bar_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) +{ + GtkPackDirection pack_direction, child_pack_direction; + gint i; + + pack_direction = gtk_menu_bar_get_pack_direction (GTK_MENU_BAR (widget)); + child_pack_direction = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (widget)); + + for (i = 0; i < sizeof (GbPackDirectionValues) / sizeof (GbPackDirectionValues[0]); i++) + { + if (GbPackDirectionValues[i] == pack_direction) + gb_widget_output_choice (data, PackDirection, i, GbPackDirectionSymbols[i]); + + if (GbPackDirectionValues[i] == child_pack_direction) + gb_widget_output_choice (data, ChildPackDirection, i, GbPackDirectionSymbols[i]); + } +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_menu_bar_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) +{ + gchar *pack_direction, *child_pack_direction; + gint i; + + pack_direction = gb_widget_input_choice (data, PackDirection); + if (data->apply) + { + for (i = 0; i < sizeof (GbPackDirectionValues) / sizeof (GbPackDirectionValues[0]); i++) + { + if (!strcmp (pack_direction, GbPackDirectionChoices[i]) + || !strcmp (pack_direction, GbPackDirectionSymbols[i])) + { + gtk_menu_bar_set_pack_direction (GTK_MENU_BAR (widget), + GbPackDirectionValues[i]); + break; + } + } + } + + child_pack_direction = gb_widget_input_choice (data, ChildPackDirection); + if (data->apply) + { + for (i = 0; i < sizeof (GbPackDirectionValues) / sizeof (GbPackDirectionValues[0]); i++) + { + if (!strcmp (child_pack_direction, GbPackDirectionChoices[i]) + || !strcmp (child_pack_direction, GbPackDirectionSymbols[i])) + { + gtk_menu_bar_set_child_pack_direction (GTK_MENU_BAR (widget), + GbPackDirectionValues[i]); + break; + } + } + } +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkMenuBar, with signals pointing to + * other functions in this file. + */ +static void +gb_menu_bar_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) +{ + GtkWidget *menuitem; + + menuitem = gtk_menu_item_new_with_label (_("Edit Menus...")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_menu_bar_on_edit_menu_activate), + widget); +} + + +static void +gb_menu_bar_on_edit_menu_activate (GtkWidget *menuitem, + GtkWidget *menubar) +{ + GtkWidget *menued; + + menued = glade_menu_editor_new (current_project, GTK_MENU_SHELL (menubar)); + dialogize (menued, menubar); + gtk_widget_show (GTK_WIDGET (menued)); +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_menu_bar_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gboolean created_menu = FALSE; + GtkPackDirection pack_direction, child_pack_direction; + gint i; + + pack_direction = gtk_menu_bar_get_pack_direction (GTK_MENU_BAR (widget)); + child_pack_direction = gtk_menu_bar_get_child_pack_direction (GTK_MENU_BAR (widget)); + +#ifdef USE_GNOME + /* For Gnome projects the menus are created using GnomeUIInfo structs, so + we just create the start of the struct here. In a GnomeApp dock item, + the code to add the menu to the GnomeApp is in output in gnomedockitem.c. + If the menubar is not in a GnomeApp, we have to output the code to create + it here. */ + if (data->project->gnome_support) + { + glade_gnome_start_menu_source (GTK_MENU_SHELL (widget), data); + + if (widget->parent && glade_gnome_is_app_dock_item (widget->parent)) + { + /* FIXME: should we set some standard properties? */ + gb_widget_write_add_child_source (widget, data); + return; + } + else + { + if (data->create_widget) + { + source_add (data, " %s = gtk_menu_bar_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + data->need_accel_group = TRUE; + source_add (data, + " gnome_app_fill_menu (GTK_MENU_SHELL (%s), %s_uiinfo,\n" + " accel_group, FALSE, 0);\n", + data->wname, data->real_wname); + created_menu = TRUE; + } + } +#endif + + if (!created_menu) + { + if (data->create_widget) + { + source_add (data, " %s = gtk_menu_bar_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + } + + if (pack_direction != GTK_PACK_DIRECTION_LTR) + { + for (i = 0; i < sizeof (GbPackDirectionValues) / sizeof (GbPackDirectionValues[0]); i++) + { + if (GbPackDirectionValues[i] == pack_direction) + source_add (data, + " gtk_menu_bar_set_pack_direction (GTK_MENU_BAR (%s), %s);\n", + data->wname, GbPackDirectionSymbols[i]); + } + } + + if (child_pack_direction != GTK_PACK_DIRECTION_LTR) + { + for (i = 0; i < sizeof (GbPackDirectionValues) / sizeof (GbPackDirectionValues[0]); i++) + { + if (GbPackDirectionValues[i] == child_pack_direction) + source_add (data, + " gtk_menu_bar_set_child_pack_direction (GTK_MENU_BAR (%s), %s);\n", + data->wname, GbPackDirectionSymbols[i]); + } + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_menu_bar_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_menu_bar_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = menubar_xpm; + gbwidget.tooltip = _("Menu Bar"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_menu_bar_new; + gbwidget.gb_widget_create_properties = gb_menu_bar_create_properties; + gbwidget.gb_widget_get_properties = gb_menu_bar_get_properties; + gbwidget.gb_widget_set_properties = gb_menu_bar_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_menu_bar_create_popup_menu; + gbwidget.gb_widget_write_source = gb_menu_bar_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbmenuitem.c b/tools/glade/glade/gbwidgets/gbmenuitem.c new file mode 100644 index 00000000..eae44ac6 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbmenuitem.c @@ -0,0 +1,393 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenubar.h> +#include <gtk/gtkmenuitem.h> +#include "../gb.h" +#include "../glade_gnome.h" +#include "../glade_keys_dialog.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/menuitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Label = "MenuItem|GtkItem::label"; +static gchar *Icon = "GtkMenuItem::icon"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkMenuItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_menu_item_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_CREATING) + new_widget = gtk_menu_item_new_with_label (data->name); + else + new_widget = gtk_menu_item_new (); + return new_widget; +} + +void +gb_menu_item_add_child (GtkWidget * widget, GtkWidget * child, GbWidgetSetArgData *data) +{ + if (GTK_IS_MENU (child)) + { + MSG ("Trying to add a menu to a menu item"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), child); + } +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_menu_item_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ +#if 0 + /* For now we don't support editing the menuitem properties in the property + editor. The menu editor has to be used instead. */ + property_add_text (Label, _("Label:"), _("The text to display"), 2); +#endif +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_menu_item_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gboolean output_label = TRUE; + + /* We only support saving the properties here. */ + if (data->action != GB_SAVING) + return; + + /* If we are saving, we check for a stock Gnome menu item, and if so, we + just save that. GTK+ stock items are all GtkImageMenuItems, so we don't + have to worry about those here. */ +#ifdef USE_GNOME + if (glade_project_get_gnome_support (data->project)) + { + gint stock_item_index; + + stock_item_index = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), GladeMenuItemStockIndexKey)); + /* The 'New' item is special. If it has a child menu, it must be a + GNOMEUIINFO_MENU_NEW_SUBTREE. If not, it is a + GNOMEUIINFO_MENU_NEW_ITEM, in which case the label is also output. */ + if (stock_item_index == GladeStockMenuItemNew) + { + if (GTK_MENU_ITEM (widget)->submenu) + { + gb_widget_output_string (data, "stock_item", + "GNOMEUIINFO_MENU_NEW_SUBTREE"); + output_label = FALSE; + } + else + { + gb_widget_output_string (data, "stock_item", + "GNOMEUIINFO_MENU_NEW_ITEM"); + } + } + else if (stock_item_index != 0) + { + gb_widget_output_string (data, "stock_item", GladeStockMenuItemSymbols[stock_item_index]); + output_label = FALSE; + } + } +#endif + + if (output_label) + gb_widget_output_child_label (widget, data, Label); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_menu_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean input_label = TRUE, input_rest = TRUE; + GtkAccelGroup *accel_group; + guint key; + GdkModifierType modifiers; + + /* We only support loading the properties here. */ + if (data->action != GB_LOADING) + return; + +#ifdef USE_GNOME + /* Check for a stock menu item. */ + if (glade_project_get_gnome_support (data->project)) + { + GnomeUIInfo *uiinfo; + gchar *stock_item; + GtkWidget *label; + gint stock_item_index; + + stock_item = gb_widget_input_string (data, "stock_item"); + if (stock_item && stock_item[0]) + { + /* Special case for the NEW_SUBTREE. */ + if (!strcmp (stock_item, "GNOMEUIINFO_MENU_NEW_SUBTREE")) + { + stock_item_index = GladeStockMenuItemNew; + } + else + { + stock_item_index = glade_util_string_array_index (GladeStockMenuItemSymbols, GladeStockMenuItemSize, stock_item); + } + + if (stock_item_index != -1) + { + uiinfo = &GladeStockMenuItemValues[stock_item_index]; + if (uiinfo->type == GNOME_APP_UI_ITEM_CONFIGURABLE) + gnome_app_ui_configure_configurable (uiinfo); + + /* Note that we don't have to worry about the pixmap, since if + it had a pixmap it would be a GtkImageMenuItem. */ + + label = gtk_accel_label_new (""); + gtk_label_set_text_with_mnemonic (GTK_LABEL (label), + uiinfo->label); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_widget_show (label); + gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), + widget); + gtk_container_add (GTK_CONTAINER (widget), label); + + /* Add the configured accelerator key. */ + if (uiinfo->accelerator_key != 0 && widget->parent + && GTK_IS_MENU (widget->parent)) + { + accel_group = GTK_MENU (widget->parent)->accel_group; + gtk_widget_add_accelerator (widget, "activate", accel_group, + uiinfo->accelerator_key, + uiinfo->ac_mods, + GTK_ACCEL_VISIBLE); + } + + /* Remember the index of the stock item. */ + gtk_object_set_data (GTK_OBJECT (widget), + GladeMenuItemStockIndexKey, + GINT_TO_POINTER (stock_item_index)); + + /* The 'New' item can have a label. The rest can't. */ + if (stock_item_index != GladeStockMenuItemNew) + input_label = FALSE; + input_rest = FALSE; + } + else + { +#ifdef FIXME + load_add_error_message_with_tag (data, + GLADE_LINE_PROPERTY, + _("Invalid stock menu item"), + "stock_item", stock_item); +#endif + } + } + } +#endif + + if (input_label) + gb_widget_input_child_label (widget, data, Label); + + if (input_rest) + { + /* FIXME: should this be somewhere else? */ + /* If we are loading, install the 'activate' accelerator, if it has one, + so that is is visible. */ + if (data->action == GB_LOADING && widget->parent + && GTK_IS_MENU (widget->parent)) + { + int i; + + for (i = 0; i < data->widget_info->n_accels; i++) + { + if (!strcmp (data->widget_info->accels[i].signal, "activate")) + { + key = data->widget_info->accels[i].key; + modifiers = data->widget_info->accels[i].modifiers; + accel_group = GTK_MENU (widget->parent)->accel_group; + gtk_widget_add_accelerator (widget, "activate", accel_group, + key, modifiers, + GTK_ACCEL_VISIBLE); + break; + } + } + } + } +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkMenuItem, with signals pointing to + * other functions in this file. + */ +static void +gb_menu_item_create_popup_menu (GtkWidget * widget, + GbWidgetCreateMenuData * data) +{ + /* Add command to remove child label. */ +#if 0 + gb_widget_create_child_label_popup_menu (widget, data); +#endif +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_menu_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkWidget *child = GTK_BIN (widget)->child; + gchar *label_text; + gboolean translatable, context; + gchar *comments; + +#ifdef USE_GNOME + if (data->project->gnome_support) + { + glade_gnome_write_menu_item_source (GTK_MENU_ITEM (widget), data); + return; + } +#endif + + if (child && GTK_IS_LABEL (child) && !GB_IS_GB_WIDGET (child)) + { + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + label_text = glade_util_get_label_text (child); + source_add (data, " %s = gtk_menu_item_new_with_mnemonic (%s);\n", + data->wname, + source_make_string_full (label_text, data->use_gettext && translatable, context)); + g_free (label_text); + } + else + { + source_add (data, " %s = gtk_menu_item_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); +} + + +/* Outputs source to add a child menu to a menu item. */ +static void +gb_menu_item_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + if (GTK_IS_MENU (child)) + { + source_add (data, + " gtk_menu_item_set_submenu (GTK_MENU_ITEM (%s), %s);\n", + parent_name, data->wname); + } + else + { + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + } +} + + +static void +gb_menu_item_destroy (GtkWidget * widget, GbWidgetDestroyData * data) +{ + /* We need to remove the icon pixmap from the project. + Note that it may be a stock icon name, in which case it will be ignored + by glade_project_remove_pixmap. */ + gchar *filename = gtk_object_get_data (GTK_OBJECT (widget), Icon); + if (filename) + { + glade_project_remove_pixmap (data->project, filename); + g_free (filename); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_menu_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_menu_item_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = menuitem_xpm; + gbwidget.tooltip = _("Menu Item"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_menu_item_new; + gbwidget.gb_widget_add_child = gb_menu_item_add_child; + gbwidget.gb_widget_create_properties = gb_menu_item_create_properties; + gbwidget.gb_widget_get_properties = gb_menu_item_get_properties; + gbwidget.gb_widget_set_properties = gb_menu_item_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_menu_item_create_popup_menu; + gbwidget.gb_widget_write_source = gb_menu_item_write_source; + gbwidget.gb_widget_write_add_child_source = gb_menu_item_write_add_child_source; + gbwidget.gb_widget_destroy = gb_menu_item_destroy; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbmenutoolbutton.c b/tools/glade/glade/gbwidgets/gbmenutoolbutton.c new file mode 100644 index 00000000..c8f82ac3 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbmenutoolbutton.c @@ -0,0 +1,269 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/menutoolbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *StockButton = "GtkMenuToolButton|GtkToolButton::stock_id"; +static gchar *Label = "GtkMenuToolButton|GtkToolButton::label"; +static gchar *Icon = "GtkMenuToolButton|GtkToolButton::icon"; +static gchar *VisibleHorz = "GtkMenuToolButton|GtkToolItem::visible_horizontal"; +static gchar *VisibleVert = "GtkMenuToolButton|GtkToolItem::visible_vertical"; +static gchar *IsImportant = "GtkMenuToolButton|GtkToolItem::is_important"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkMenuToolButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_menu_tool_button_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget, *image; + GbWidget *pixmap_gbwidget; + + /* Place the pixmap icon in the button initially (even when loading). */ + pixmap_gbwidget = gb_widget_lookup_class ("GtkImage"); + if (pixmap_gbwidget) + { + image = gtk_image_new_from_pixmap (pixmap_gbwidget->gdkpixmap, + pixmap_gbwidget->mask); + } + else + { + image = gtk_image_new (); + g_warning ("Couldn't find GtkPixmap data"); + } + gtk_widget_show (image); + + new_widget = (GtkWidget*) gtk_menu_tool_button_new (image, ""); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_menu_tool_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + property_add_bool (VisibleHorz, _("Show Horizontal:"), + _("If the item is visible when the toolbar is horizontal")); + property_add_bool (VisibleVert, _("Show Vertical:"), + _("If the item is visible when the toolbar is vertical")); + property_add_bool (IsImportant, _("Is Important:"), + _("If the item's text should be shown when the toolbar's mode is GTK_TOOLBAR_BOTH_HORIZ")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_menu_tool_button_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_tool_button_get_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_menu_tool_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gb_tool_button_set_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkMenuToolButton, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_menu_tool_button_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_menu_tool_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *stock_id, *label, *icon_name; + gboolean translatable, context; + gchar *comments; + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonStockIDKey); + icon_name = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonIconKey); + label = (gchar*) gtk_tool_button_get_label (GTK_TOOL_BUTTON (widget)); + + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + + if (data->create_widget) + { + if (stock_id) + { + /* Stock Button */ + source_add (data, + " %s = (GtkWidget*) gtk_menu_tool_button_new_from_stock (%s);\n", + data->wname, source_make_string (stock_id, FALSE)); + } + else if (icon_name) + { + /* Icon and Label */ + source_ensure_decl (data, " GtkWidget *tmp_image;\n"); + + if (glade_util_check_is_stock_id (icon_name)) + { + source_add (data, + " tmp_image = gtk_image_new_from_stock (\"%s\", tmp_toolbar_icon_size);\n", + icon_name); + } + else + { + source_create_pixmap (data, "tmp_image", icon_name); + } + + source_add (data, " gtk_widget_show (tmp_image);\n"); + + source_add_translator_comments (data, translatable, comments); + source_add (data, + " %s = (GtkWidget*) gtk_menu_tool_button_new (tmp_image, %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + } + else + { + /* Just a Label */ + source_add_translator_comments (data, translatable, comments); + source_add (data, + " %s = (GtkWidget*) gtk_menu_tool_button_new (NULL, %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + } + } + + gb_widget_write_standard_source (widget, data); + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))) + { + source_add (data, + " gtk_tool_item_set_is_important (GTK_TOOL_ITEM (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_menu_tool_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_menu_tool_button_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = menutoolbutton_xpm; + gbwidget.tooltip = _("Toolbar Button with Menu"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_menu_tool_button_new; + gbwidget.gb_widget_create_properties = gb_menu_tool_button_create_properties; + gbwidget.gb_widget_get_properties = gb_menu_tool_button_get_properties; + gbwidget.gb_widget_set_properties = gb_menu_tool_button_set_properties; + gbwidget.gb_widget_write_source = gb_menu_tool_button_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_menu_tool_button_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbnotebook.c b/tools/glade/glade/gbwidgets/gbnotebook.c new file mode 100644 index 00000000..b4251ab3 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbnotebook.c @@ -0,0 +1,954 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhbox.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtknotebook.h> +#include <gtk/gtkspinbutton.h> +#include "../gb.h" +#include "../tree.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/notebook.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *ShowTabs = "GtkNotebook::show_tabs"; +static gchar *ShowBorder = "GtkNotebook::show_border"; +static gchar *TabPos = "GtkNotebook::tab_pos"; +static gchar *Scrollable = "GtkNotebook::scrollable"; +static gchar *Popups = "GtkNotebook::enable_popup"; + +#if 0 +/* These seem to be deprecated. */ +static gchar *TabHBorder = "GtkNotebook::tab_hborder"; +static gchar *TabVBorder = "GtkNotebook::tab_vborder"; +#endif + +/* This isn't save in the XML as it is implicit. */ +static gchar *NumPages = "GtkNotebook::num_pages"; + +/* This isn't save in the XML as it is implicit. */ +static gchar *ChildPosition = "GtkNotebook::position"; + +static gchar *ChildExpand = "GtkNotebook::tab_expand"; +static gchar *ChildFill = "GtkNotebook::tab_fill"; +static gchar *ChildPack = "GtkNotebook::tab_pack"; +static gchar *ChildMenuLabel = "GtkNotebook::menu_label"; + + +static const gchar *GbTabPosChoices[] = +{"Left", "Right", "Top", "Bottom", NULL}; +static const gint GbTabPosValues[] = +{ + GTK_POS_LEFT, + GTK_POS_RIGHT, + GTK_POS_TOP, + GTK_POS_BOTTOM +}; +static const gchar *GbTabPosSymbols[] = +{ + "GTK_POS_LEFT", + "GTK_POS_RIGHT", + "GTK_POS_TOP", + "GTK_POS_BOTTOM" +}; + + +static void show_notebook_dialog (GbWidgetNewData * data); +static void on_notebook_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_notebook_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); +static GtkWidget *gb_notebook_new_tab_label (); +static void gb_notebook_next_page (GtkWidget * menuitem, GtkNotebook * notebook); +static void gb_notebook_prev_page (GtkWidget * menuitem, GtkNotebook * notebook); +static void gb_notebook_update_num_pages (GtkNotebook *notebook); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkNotebook, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_notebook_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_LOADING) + { + new_widget = gtk_notebook_new (); + return new_widget; + } + else + { + show_notebook_dialog (data); + return NULL; + } +} + + +void +gb_notebook_add_child (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + gboolean is_tab = FALSE; + + /* See if this is a tab widget. We use a special "type" packing property set + to "tab".*/ + if (data->child_info) + { + int j; + + for (j = 0; j < data->child_info->n_properties; j++) + { + if (!strcmp (data->child_info->properties[j].name, "type") + && !strcmp (data->child_info->properties[j].value, "tab")) + { + is_tab = TRUE; + break; + } + } + } + + if (is_tab) + { + /* We store the last tab read in 'last_child' */ + GtkWidget *notebook_page; + gint pos = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + "last_child")); + + MSG1 ("Adding notebook tab: %i", pos); + /* SPECIAL CODE to replace the notebooks default tab label with the + loaded widget. We remove the page and add it with the new tab, + just like in gb_widget_replace_child(). */ + + notebook_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (widget), pos); + if (notebook_page) + { + gtk_notebook_set_tab_label (GTK_NOTEBOOK (widget), notebook_page, + child); + } + else + { + g_warning ("Notebook tab found for non-existent page"); + gtk_notebook_append_page (GTK_NOTEBOOK (widget), + editor_new_placeholder (), child); + } + gtk_object_set_data (GTK_OBJECT (widget), "last_child", + GINT_TO_POINTER (pos + 1)); + } + else + { + /* We create a label, in case it does not appear in the XML file, + or we are pasting into the notebook. */ + GtkWidget *label = gb_widget_new_full ("GtkLabel", FALSE, widget, + NULL, 0, 0, NULL, GB_CREATING, + NULL); + g_return_if_fail (label != NULL); + + gtk_notebook_append_page (GTK_NOTEBOOK (widget), child, label); + } +} + + +static void +show_notebook_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New notebook"), data->parent, + GTK_SIGNAL_FUNC (on_notebook_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_notebook_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of pages:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "pages", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_notebook_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *window; + gint pages, i; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "pages"); + g_return_if_fail (spinbutton != NULL); + pages = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_notebook_new (); + for (i = 0; i < pages; i++) + { + gtk_notebook_append_page (GTK_NOTEBOOK (new_widget), + editor_new_placeholder (), + gb_notebook_new_tab_label ()); + } + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (window); +} + + +static void +on_notebook_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +GtkWidget * +gb_notebook_new_tab_label () +{ + GtkWidget *label; + + label = gb_widget_new ("GtkLabel", NULL); + g_return_val_if_fail (label != NULL, NULL); + return label; +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_notebook_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (ShowTabs, _("Show Tabs:"), _("If the notebook tabs are shown")); + property_add_bool (ShowBorder, _("Show Border:"), + _("If the notebook border is shown, when the tabs are not shown")); + property_add_choice (TabPos, _("Tab Pos:"), + _("The position of the notebook tabs"), + GbTabPosChoices); + property_add_bool (Scrollable, _("Scrollable:"), + _("If the notebook tabs are scrollable")); +#if 0 +/* These seem to be deprecated. */ + property_add_int_range (TabHBorder, _("Tab Horz. Border:"), + _("The size of the notebook tabs' horizontal border"), + 0, 1000, 1, 10, 1); + property_add_int_range (TabVBorder, _("Tab Vert. Border:"), + _("The size of the notebook tabs' vertical border"), + 0, 1000, 1, 10, 1); +#endif + property_add_bool (Popups, _("Show Popup:"), _("If the popup menu is enabled")); + property_add_int_range (NumPages, _("Number of Pages:"), + _("The number of notebook pages"), + 1, 100, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_notebook_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint tab_pos, i; + + gb_widget_output_bool (data, ShowTabs, GTK_NOTEBOOK (widget)->show_tabs); + gb_widget_output_bool (data, ShowBorder, GTK_NOTEBOOK (widget)->show_border); + + tab_pos = GTK_NOTEBOOK (widget)->tab_pos; + for (i = 0; i < sizeof (GbTabPosValues) / sizeof (GbTabPosValues[0]); i++) + { + if (GbTabPosValues[i] == tab_pos) + gb_widget_output_choice (data, TabPos, i, GbTabPosSymbols[i]); + } + + gb_widget_output_bool (data, Scrollable, GTK_NOTEBOOK (widget)->scrollable); + +#if 0 +/* These seem to be deprecated. */ + gb_widget_output_int (data, TabHBorder, GTK_NOTEBOOK (widget)->tab_hborder); + gb_widget_output_int (data, TabVBorder, GTK_NOTEBOOK (widget)->tab_vborder); +#endif + + gb_widget_output_bool (data, Popups, + (GTK_NOTEBOOK (widget)->menu) ? TRUE : FALSE); + + /* Don't save the number of pages. */ + if (data->action != GB_SAVING) + gb_widget_output_int (data, NumPages, + g_list_length (GTK_NOTEBOOK (widget)->children)); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_notebook_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean show_tabs, show_border, scrollable, popups; + gchar *tab_pos; + gint i, num_pages; + GtkWidget *new_label; + + show_tabs = gb_widget_input_bool (data, ShowTabs); + if (data->apply) + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), show_tabs); + + show_border = gb_widget_input_bool (data, ShowBorder); + if (data->apply) + gtk_notebook_set_show_border (GTK_NOTEBOOK (widget), show_border); + + tab_pos = gb_widget_input_choice (data, TabPos); + if (data->apply) + { + for (i = 0; i < sizeof (GbTabPosValues) / sizeof (GbTabPosValues[0]); i + ++) + { + if (!strcmp (tab_pos, GbTabPosChoices[i]) + || !strcmp (tab_pos, GbTabPosSymbols[i])) + { + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (widget), GbTabPosValues + [i]); + break; + } + } + } + + scrollable = gb_widget_input_bool (data, Scrollable); + if (data->apply) + gtk_notebook_set_scrollable (GTK_NOTEBOOK (widget), scrollable); + +#if 0 +/* These seem to be deprecated. */ + tab_border = gb_widget_input_int (data, TabHBorder); + if (data->apply) + gtk_notebook_set_tab_hborder (GTK_NOTEBOOK (widget), tab_border); + + tab_border = gb_widget_input_int (data, TabVBorder); + if (data->apply) + gtk_notebook_set_tab_vborder (GTK_NOTEBOOK (widget), tab_border); +#endif + + popups = gb_widget_input_bool (data, Popups); + if (data->apply) + { + if (popups) + gtk_notebook_popup_enable (GTK_NOTEBOOK (widget)); + else + gtk_notebook_popup_disable (GTK_NOTEBOOK (widget)); + } + + /* Don't adjust the size of a notebook if loading a project + * as it is handled by other routines. */ + if (data->action != GB_LOADING) + { + num_pages = gb_widget_input_int (data, NumPages); + if (data->apply) + { + if (num_pages != g_list_length (GTK_NOTEBOOK (widget)->children)) + { + if (num_pages > g_list_length (GTK_NOTEBOOK (widget)->children)) + { + while (num_pages > g_list_length (GTK_NOTEBOOK (widget)->children)) + { + new_label = gb_notebook_new_tab_label (); + gtk_notebook_append_page (GTK_NOTEBOOK (widget), + editor_new_placeholder (), + new_label); + tree_add_widget (new_label); + } + } + else + { + while (num_pages < g_list_length (GTK_NOTEBOOK (widget)->children)) + { + gtk_notebook_remove_page (GTK_NOTEBOOK (widget), + num_pages); + } + } + } + } + } +} + + + +static void +gb_notebook_next_page (GtkWidget * menuitem, GtkNotebook * notebook) +{ + gtk_notebook_next_page (notebook); +} + +static void +gb_notebook_prev_page (GtkWidget * menuitem, GtkNotebook * notebook) +{ + gtk_notebook_prev_page (notebook); +} + +static void +gb_notebook_switch_prev (GtkWidget *menuitem, GtkNotebook *notebook) +{ + GtkWidget *child; + gint current_page; + + current_page = gtk_notebook_get_current_page (notebook); + child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), current_page); + + if (child) + { + gtk_notebook_reorder_child (notebook, child, current_page - 1); + } +} + +static void +gb_notebook_switch_next (GtkWidget *menuitem, GtkNotebook *notebook) +{ + GtkWidget *child; + gint current_page; + + current_page = gtk_notebook_get_current_page (notebook); + child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), current_page); + + if (child) + { + gtk_notebook_reorder_child (notebook, child, current_page + 1); + } +} + +static void +gb_notebook_insert_next (GtkWidget *menuitem, GtkNotebook *notebook) +{ + gint current_page; + GtkWidget *new_label; + + current_page = gtk_notebook_get_current_page (notebook); + + new_label = gb_notebook_new_tab_label (); + gtk_notebook_insert_page (notebook, editor_new_placeholder (), + new_label, current_page + 1); + tree_add_widget (new_label); + gb_notebook_update_num_pages (notebook); +} + +static void +gb_notebook_insert_prev (GtkWidget *menuitem, GtkNotebook *notebook) +{ + gint current_page; + GtkWidget *new_label; + + current_page = gtk_notebook_get_current_page (notebook); + + new_label = gb_notebook_new_tab_label (); + gtk_notebook_insert_page (notebook, editor_new_placeholder (), + new_label, current_page); + tree_add_widget (new_label); + gb_notebook_update_num_pages (notebook); +} + +static void +gb_notebook_delete_page (GtkWidget *menuitem, GtkNotebook *notebook) +{ + gtk_notebook_remove_page (notebook, + gtk_notebook_get_current_page (notebook)); + gb_notebook_update_num_pages (notebook); +} + + +/* This updates the number of pages property, if the notebook's properties are + currently shown. */ +static void +gb_notebook_update_num_pages (GtkNotebook *notebook) +{ + if (property_get_widget () == GTK_WIDGET (notebook)) + { + property_set_auto_apply (FALSE); + property_set_int (NumPages, g_list_length (notebook->children)); + property_set_auto_apply (TRUE); + } +} + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkNotebook, with signals pointing to + * other functions in this file. + */ +static void +gb_notebook_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + GtkWidget *menuitem; + gint current_page, num_pages; + + current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget)); + num_pages = g_list_length (GTK_NOTEBOOK (widget)->children); + + menuitem = gtk_menu_item_new_with_label (_("Previous Page")); + gtk_widget_show (menuitem); + if (current_page == 0) + gtk_widget_set_sensitive (menuitem, FALSE); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_notebook_prev_page), GTK_NOTEBOOK (widget)); + + menuitem = gtk_menu_item_new_with_label (_("Next Page")); + gtk_widget_show (menuitem); + if (current_page == num_pages - 1) + gtk_widget_set_sensitive (menuitem, FALSE); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_notebook_next_page), GTK_NOTEBOOK (widget)); + + menuitem = gtk_menu_item_new_with_label (_("Delete Page")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_notebook_delete_page), GTK_NOTEBOOK (widget)); + + menuitem = gtk_menu_item_new_with_label (_("Switch Next")); + gtk_widget_show (menuitem); + if (current_page == num_pages - 1) + gtk_widget_set_sensitive (menuitem, FALSE); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_notebook_switch_next), GTK_NOTEBOOK (widget)); + + menuitem = gtk_menu_item_new_with_label (_("Switch Previous")); + gtk_widget_show (menuitem); + if (current_page == 0) + gtk_widget_set_sensitive (menuitem, FALSE); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_notebook_switch_prev), GTK_NOTEBOOK (widget)); + + menuitem = gtk_menu_item_new_with_label (_("Insert Page After")); + gtk_widget_show (menuitem); + /* if (current_page == num_pages - 1) + gtk_widget_set_sensitive (menuitem, FALSE);*/ + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_notebook_insert_next), GTK_NOTEBOOK (widget)); + + menuitem = gtk_menu_item_new_with_label (_("Insert Page Before")); + gtk_widget_show (menuitem); + /*if (current_page == 0) + gtk_widget_set_sensitive (menuitem, FALSE);*/ + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_notebook_insert_prev), GTK_NOTEBOOK (widget)); +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_notebook_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_notebook_new ();\n", data->wname); + } + + /* We reset the last_child index, so as the tab widgets are written out + they will start at page 0. */ + gtk_object_set_data (GTK_OBJECT (widget), "last_child", + GINT_TO_POINTER (-1)); + + gb_widget_write_standard_source (widget, data); + + if (!GTK_NOTEBOOK (widget)->show_tabs) + source_add (data, + " gtk_notebook_set_show_tabs (GTK_NOTEBOOK (%s), FALSE);\n", + data->wname); + if (!GTK_NOTEBOOK (widget)->show_border) + source_add (data, + " gtk_notebook_set_show_border (GTK_NOTEBOOK (%s), FALSE);\n", + data->wname); + if (GTK_NOTEBOOK (widget)->tab_pos != GTK_POS_TOP) + { + for (i = 0; i < sizeof (GbTabPosValues) / sizeof (GbTabPosValues[0]); i + ++) + { + if (GbTabPosValues[i] == GTK_NOTEBOOK (widget)->tab_pos) + source_add (data, + " gtk_notebook_set_tab_pos (GTK_NOTEBOOK (%s), %s);\n", + data->wname, GbTabPosSymbols[i]); + } + } + if (GTK_NOTEBOOK (widget)->scrollable) + source_add (data, + " gtk_notebook_set_scrollable (GTK_NOTEBOOK (%s), TRUE);\n", + data->wname); + +#if 0 +/* These seem to be deprecated. */ + if (GTK_NOTEBOOK (widget)->tab_hborder != 2) + source_add (data, + " gtk_notebook_set_tab_hborder (GTK_NOTEBOOK (%s), %i);\n", + data->wname, GTK_NOTEBOOK (widget)->tab_hborder); + if (GTK_NOTEBOOK (widget)->tab_vborder != 2) + source_add (data, + " gtk_notebook_set_tab_vborder (GTK_NOTEBOOK (%s), %i);\n", + data->wname, GTK_NOTEBOOK (widget)->tab_vborder); +#endif + + if (GTK_NOTEBOOK (widget)->menu) + source_add (data, + " gtk_notebook_popup_enable (GTK_NOTEBOOK (%s));\n", + data->wname); +} + + +/* + * Creates the child packing properties for children of this widget. + */ +void +gb_notebook_create_child_properties (GtkWidget * widget, + GbWidgetCreateChildArgData * data) +{ + property_add_int_range (ChildPosition, _("Position:"), + _("The page's position in the list of pages"), + 0, 10000, 1, 10, 1); + property_add_bool (ChildExpand, _("Expand:"), + _("Set True to let the tab expand")); + property_add_bool (ChildFill, _("Fill:"), + _("Set True to let the tab fill its allocated area")); + property_add_bool (ChildPack, _("Pack Start:"), + _("Set True to pack the tab at the start of the notebook")); + property_add_string (ChildMenuLabel, _("Menu Label:"), + _("The text to display in the popup menu")); +} + + +static gboolean +gb_notebook_get_child_info (GtkNotebook *notebook, GtkWidget *child, + GtkWidget **notebook_child, + GtkWidget **notebook_tab, + gint *position, gboolean *expand, gboolean *fill, + GtkPackType *pack_type) +{ + gint nchildren, page; + + nchildren = g_list_length (notebook->children); + + for (page = 0; page < nchildren; page++) + { + *notebook_child = gtk_notebook_get_nth_page (notebook, page); + *notebook_tab = gtk_notebook_get_tab_label (notebook, *notebook_child); + + if (*notebook_child == child || *notebook_tab == child) + { + gtk_notebook_query_tab_label_packing (notebook, *notebook_child, + expand, fill, pack_type); + *position = page; + return TRUE; + } + } + + return FALSE; +} + + +void +gb_notebook_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + GtkWidget *notebook_child, *notebook_tab; + gboolean expand, fill; + gint position; + GtkPackType pack_type; + const gchar *menu_label; + + /* If we can't find the child, output a warning and return. */ + if (!gb_notebook_get_child_info (GTK_NOTEBOOK (widget), child, + ¬ebook_child, ¬ebook_tab, + &position, &expand, &fill, &pack_type)) + { + g_warning ("Notebook child not found"); + return; + } + + /* If we are saving, we save the packing properties with the main child + widget, and not with the tab label. But we show the packing properties + for the tab label as well, as that is easier for the user. + For the tab label we save the special "type" packing property. */ + if (data->action == GB_SAVING && child == notebook_tab) + { + save_start_tag (data, "packing"); + gb_widget_output_string (data, "type", "tab"); + save_end_tag (data, "packing"); + return; + } + + if (data->action == GB_SAVING) + save_start_tag (data, "packing"); + + if (data->action == GB_SHOWING) + gb_widget_output_int (data, ChildPosition, position); + + gb_widget_output_bool (data, ChildExpand, expand); + gb_widget_output_bool (data, ChildFill, fill); + + if (data->action == GB_SAVING) + { + /* Save pack type as an enum symbol rather than a bool */ + if (pack_type == GTK_PACK_END) + { + gb_widget_output_string (data, ChildPack, "GTK_PACK_END"); + } + } + else + { + gb_widget_output_bool (data, ChildPack, pack_type == GTK_PACK_START); + } + + menu_label = gtk_notebook_get_menu_label_text (GTK_NOTEBOOK (widget), + notebook_child); + gb_widget_output_translatable_string (data, ChildMenuLabel, menu_label); + + if (data->action == GB_SAVING) + save_end_tag (data, "packing"); +} + + +/* Applies or loads the child properties of a child of a hbox/vbox. */ +void +gb_notebook_set_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + GtkWidget *notebook_child, *notebook_tab; + gint position, old_position; + gboolean expand, fill, pack, set_child_packing = FALSE; + gboolean old_expand, old_fill; + GtkPackType old_pack_type; + char *menu_label; + + /* If we can't find the child, output a warning and return. */ + if (!gb_notebook_get_child_info (GTK_NOTEBOOK (widget), child, + ¬ebook_child, ¬ebook_tab, + &old_position, &old_expand, &old_fill, + &old_pack_type)) + { + g_warning ("Notebook child not found"); + return; + } + + /* If we are loading, don't set the packing properties for the tab. */ + if (data->action == GB_LOADING && child == notebook_tab) + return; + + position = gb_widget_input_int (data, ChildPosition); + if (data->apply) + { + gtk_notebook_reorder_child (GTK_NOTEBOOK (widget), notebook_child, + position); + } + + expand = gb_widget_input_bool (data, ChildExpand); + if (data->apply) + set_child_packing = TRUE; + else + expand = old_expand; + + fill = gb_widget_input_bool (data, ChildFill); + if (data->apply) + set_child_packing = TRUE; + else + fill = old_fill; + + if (data->action == GB_APPLYING) + { + pack = gb_widget_input_bool (data, ChildPack); + } + else + { + gchar *pack_symbol = gb_widget_input_string (data, ChildPack); + pack = pack_symbol && !strcmp (pack_symbol, "GTK_PACK_START"); + } + if (data->apply) + set_child_packing = TRUE; + else + pack = (old_pack_type == GTK_PACK_START) ? TRUE : FALSE; + + if (set_child_packing) + gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (widget), notebook_child, + expand, fill, + pack ? GTK_PACK_START : GTK_PACK_END); + + menu_label = gb_widget_input_string (data, ChildMenuLabel); + if (data->apply) + { + gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (widget), notebook_child, + menu_label); + } +} + +/* Outputs source to add a child widget to a GtkNotebook. */ +static void +gb_notebook_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + GtkWidget *notebook_child, *notebook_tab; + gboolean expand, fill; + gint position; + GtkPackType pack_type; + + if (!gb_notebook_get_child_info (GTK_NOTEBOOK (parent), child, + ¬ebook_child, ¬ebook_tab, + &position, &expand, &fill, &pack_type)) + { + g_warning ("Notebook child not found"); + return; + } + + /* See if this is a notebook tab widget. */ + if (child == notebook_tab) + { + /* We store the last tab written in 'last_child' */ + gint col = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (parent), + "last_child")); + /* We use the special function to add the tab to the notebook. */ + source_add (data, + " gtk_notebook_set_tab_label (GTK_NOTEBOOK (%s), gtk_notebook_get_nth_page (GTK_NOTEBOOK (%s), %i), %s);\n", + parent_name, parent_name, col + 1, data->wname); + + gtk_object_set_data (GTK_OBJECT (parent), "last_child", + GINT_TO_POINTER (col + 1)); + } + else + { + const gchar *menu_label; + + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); + + /* Set the packing properties, if different to the defaults. */ + if (expand || !fill || pack_type != GTK_PACK_START) + { + source_add (data, + " gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (%s), %s,\n" + " %s, %s, %s);\n", + parent_name, data->wname, + expand ? "TRUE" : "FALSE", + fill ? "TRUE" : "FALSE", + pack_type == GTK_PACK_START ? "GTK_PACK_START" : "GTK_PACK_END"); + } + + menu_label = gtk_notebook_get_menu_label_text (GTK_NOTEBOOK (parent), + notebook_child); + if (menu_label && *menu_label) + { + gboolean translatable, context; + gchar *comments; + + glade_util_get_translation_properties (notebook_child, + ChildMenuLabel, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (%s), %s, %s);\n", + parent_name, data->wname, + source_make_string_full (menu_label, data->use_gettext && translatable, context)); + } + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_notebook_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_notebook_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = notebook_xpm; + gbwidget.tooltip = _("Notebook"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_notebook_new; + gbwidget.gb_widget_add_child = gb_notebook_add_child; + + gbwidget.gb_widget_create_properties = gb_notebook_create_properties; + gbwidget.gb_widget_get_properties = gb_notebook_get_properties; + gbwidget.gb_widget_set_properties = gb_notebook_set_properties; + gbwidget.gb_widget_write_source = gb_notebook_write_source; + gbwidget.gb_widget_create_child_properties = gb_notebook_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_notebook_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_notebook_set_child_properties; + gbwidget.gb_widget_write_add_child_source = gb_notebook_write_add_child_source; + gbwidget.gb_widget_create_popup_menu = gb_notebook_create_popup_menu; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gboptionmenu.c b/tools/glade/glade/gbwidgets/gboptionmenu.c new file mode 100644 index 00000000..be5a695f --- /dev/null +++ b/tools/glade/glade/gbwidgets/gboptionmenu.c @@ -0,0 +1,285 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkoptionmenu.h> +#include "../gb.h" +#include "../glade_menu_editor.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/optionmenu.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static const char *History = "GtkOptionMenu::history"; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkOptionMenu, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_option_menu_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + new_widget = gtk_option_menu_new (); + return new_widget; +} + +/* Make window behave like a dialog */ +static void +dialogize (GtkWidget *menued, GtkWidget *parent_widget) +{ + GtkWidget *transient_parent; + + gtk_signal_connect (GTK_OBJECT (menued), "key_press_event", + GTK_SIGNAL_FUNC (glade_util_check_key_is_esc), + GINT_TO_POINTER (GladeEscDestroys)); + transient_parent = glade_util_get_toplevel (parent_widget); + if (GTK_IS_WINDOW (transient_parent)) + { + gtk_window_set_transient_for (GTK_WINDOW (menued), + GTK_WINDOW (transient_parent)); + } +} + +static void +set_menu (GladeMenuEditor *menued, GtkOptionMenu *option) +{ + int history; + + g_return_if_fail (GLADE_IS_MENU_EDITOR (menued)); + g_return_if_fail (GTK_IS_OPTION_MENU (option)); + + history = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (option), History)); + gtk_option_menu_set_menu (option, GTK_WIDGET (menued->menu)); + gtk_option_menu_set_history (option, history); +} + +static void +gb_menu_bar_on_edit_menu (GtkWidget *button, + gpointer data) +{ + GtkWidget *option, *menued, *menu; + + option = property_get_widget (); + g_return_if_fail (GTK_IS_OPTION_MENU (option)); + + /* + * we need to remove the menu from the option menu otherwise there + * will be a separator where the selected menu is + */ + g_object_set_data (G_OBJECT (option), + History, + GINT_TO_POINTER (gtk_option_menu_get_history (GTK_OPTION_MENU (option)))); + menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option)); + if (!menu) + menu = gb_widget_new ("GtkMenu", option); + g_object_ref (menu); + + gtk_option_menu_set_menu (GTK_OPTION_MENU (option), gtk_menu_new ()); + + menued = glade_menu_editor_new (current_project, GTK_MENU_SHELL (menu)); + g_signal_connect (menued, "destroy", G_CALLBACK (set_menu), option); + + /* I think this was hidden as it doesn't call set_menu() to reset the + history. */ + gtk_widget_hide (GLADE_MENU_EDITOR (menued)->apply_button); + + dialogize (menued, button); + gtk_widget_show (GTK_WIDGET (menued)); + + gtk_option_menu_set_menu (GTK_OPTION_MENU (option), menu); + g_object_unref (menu); +} + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_option_menu_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ + GtkWidget *property_table, *button; + gint property_table_row; + + /* Add a button for editing the menubar. */ + property_table = property_get_table_position (&property_table_row); + button = gtk_button_new_with_label (_("Edit Menus...")); + gtk_widget_show (button); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (gb_menu_bar_on_edit_menu), NULL); + gtk_table_attach (GTK_TABLE (property_table), button, 0, 3, + property_table_row, property_table_row + 1, + GTK_FILL, GTK_FILL, 10, 10); + +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_option_menu_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + if (data->action == GB_SAVING) + gb_widget_output_int (data, History, + gtk_option_menu_get_history (GTK_OPTION_MENU (widget))); +} + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_option_menu_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + int history; + + if (data->action == GB_LOADING) + { + history = gb_widget_input_int (data, History); + if (data->apply) + gtk_option_menu_set_history (GTK_OPTION_MENU (widget), history); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkOptionMenu, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_option_menu_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_option_menu_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint history; + + if (data->create_widget) + { + source_add (data, " %s = gtk_option_menu_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + history = gtk_option_menu_get_history (GTK_OPTION_MENU (widget)); + if (history > 0) + source_add (data, + " gtk_option_menu_set_history (GTK_OPTION_MENU (%s), %i);\n", + data->wname, history); +} + + +static void +gb_option_menu_add_child (GtkWidget *widget, + GtkWidget *child, + GbWidgetSetArgData *data) +{ + if (GTK_IS_MENU (child)) + gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), child); + else + g_warning (_("Cannot add a %s to a GtkOptionMenu."), + g_type_name (G_OBJECT_TYPE (child))); +} + + +/* Outputs source to add a child widget to a hbox/vbox. */ +void +gb_option_menu_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + /* We don't output anything here. The code to add the menu to the option + menu must be output after all the menuitems are added, so we have some + special code in gb_widget_write_source() to do that. */ +#if 0 + source_add (data, + " gtk_option_menu_set_menu (GTK_OPTION_MENU (%s), %s);\n", + parent_name, data->wname); +#endif +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_option_menu_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_option_menu_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = optionmenu_xpm; + gbwidget.tooltip = _("Option Menu"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_option_menu_new; + gbwidget.gb_widget_create_properties = gb_option_menu_create_properties; + gbwidget.gb_widget_get_properties = gb_option_menu_get_properties; + gbwidget.gb_widget_set_properties = gb_option_menu_set_properties; + gbwidget.gb_widget_add_child = gb_option_menu_add_child; + gbwidget.gb_widget_write_source = gb_option_menu_write_source; + gbwidget.gb_widget_write_add_child_source = gb_option_menu_write_add_child_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_option_menu_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbpreview.c b/tools/glade/glade/gbwidgets/gbpreview.c new file mode 100644 index 00000000..1879a2f9 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbpreview.c @@ -0,0 +1,175 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkpreview.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/preview.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Type = "GtkPreview::type"; +static gchar *Expand = "GtkPreview::expand"; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkPreview, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_preview_new (GbWidgetNewData * data) +{ + GtkWidget *preview; + preview = gtk_preview_new (GTK_PREVIEW_COLOR); + return preview; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_preview_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (Type, _("Color:"), + _("If the preview is color or grayscale")); + property_add_bool (Expand, _("Expand:"), + _("If the preview expands to fill its allocated area")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_preview_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_widget_output_bool (data, Type, GTK_PREVIEW (widget)->type == GTK_PREVIEW_COLOR); + gb_widget_output_bool (data, Expand, GTK_PREVIEW (widget)->expand); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_preview_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean type, expand; + + type = gb_widget_input_bool (data, Type); + /* We shouldn't really set the preview type after initialisation, but it + should be OK as we never use the preview */ + if (data->apply) + GTK_PREVIEW (widget)->type = type ? GTK_PREVIEW_COLOR + : GTK_PREVIEW_GRAYSCALE; + expand = gb_widget_input_bool (data, Expand); + if (data->apply) + gtk_preview_set_expand (GTK_PREVIEW (widget), expand); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkPreview, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_preview_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_preview_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_preview_new (%s);\n", data->wname, + GTK_PREVIEW (widget)->type == GTK_PREVIEW_COLOR + ? "GTK_PREVIEW_COLOR" : "GTK_PREVIEW_GRAYSCALE"); + } + + gb_widget_write_standard_source (widget, data); + + if (GTK_PREVIEW (widget)->expand) + source_add (data, " gtk_preview_set_expand (GTK_PREVIEW (%s), TRUE);\n", + data->wname); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_preview_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_preview_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = preview_xpm; + gbwidget.tooltip = _("Preview"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_preview_new; + gbwidget.gb_widget_create_properties = gb_preview_create_properties; + gbwidget.gb_widget_get_properties = gb_preview_get_properties; + gbwidget.gb_widget_set_properties = gb_preview_set_properties; + gbwidget.gb_widget_write_source = gb_preview_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_preview_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbprogressbar.c b/tools/glade/glade/gbwidgets/gbprogressbar.c new file mode 100644 index 00000000..e346bccc --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbprogressbar.c @@ -0,0 +1,433 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * Update 3/17/99 - Jay Johnston: + * - added property adjustments + * - style + * - orientation + * - activity mode + * - show text + * - added sample animation (most of that code was taken from the Gtk v1.2 + * tutorial by Tony Gale <gale@gtk.org> and Ian Main <imain@gtk.org> ) + * - added dynamic popup menus which change depending on whether the animation + * is active or not + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <math.h> +#include <gtk/gtkprogressbar.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/progressbar.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Orientation = "GtkProgressBar::orientation"; +static gchar *Fraction = "GtkProgressBar::fraction"; +static gchar *PulseStep = "GtkProgressBar::pulse_step"; +static gchar *Text = "GtkProgressBar::text"; +static gchar *Ellipsize = "GtkProgressBar::ellipsize"; + +#if 0 +static gchar *ShowText = "ProgressBar|GtkProgress::show_text"; +static gchar *ActivityMode = "ProgressBar|GtkProgress::activity_mode"; +static gchar *XAlign = "GtkProgressBar::text_xalign"; +static gchar *YAlign = "GtkProgressBar::text_yalign"; + +static gchar *Value = "ProgressBar|GtkProgress::value"; +static gchar *MinValue = "ProgressBar|GtkProgress::lower"; +static gchar *MaxValue = "ProgressBar|GtkProgress::upper"; +static gchar *Style = "GtkProgressBar::bar_style"; +#endif + + +static const gchar *GbOrientationChoices[] = +{"Left to Right", "Right to Left", "Bottom to Top", "Top to Bottom", NULL}; + +static const gint GbOrientationValues[] = +{ + GTK_PROGRESS_LEFT_TO_RIGHT, + GTK_PROGRESS_RIGHT_TO_LEFT, + GTK_PROGRESS_BOTTOM_TO_TOP, + GTK_PROGRESS_TOP_TO_BOTTOM +}; +static const gchar *GbOrientationSymbols[] = +{ + "GTK_PROGRESS_LEFT_TO_RIGHT", + "GTK_PROGRESS_RIGHT_TO_LEFT", + "GTK_PROGRESS_BOTTOM_TO_TOP", + "GTK_PROGRESS_TOP_TO_BOTTOM" +}; + +static const gchar *GbEllipsizeChoices[] = +{ + "None", + "Start", + "Middle", + "End", + NULL +}; +static const gint GbEllipsizeValues[] = +{ + PANGO_ELLIPSIZE_NONE, + PANGO_ELLIPSIZE_START, + PANGO_ELLIPSIZE_MIDDLE, + PANGO_ELLIPSIZE_END +}; +static const gchar *GbEllipsizeSymbols[] = +{ + "PANGO_ELLIPSIZE_NONE", + "PANGO_ELLIPSIZE_START", + "PANGO_ELLIPSIZE_MIDDLE", + "PANGO_ELLIPSIZE_END" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkProgressBar, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_progress_bar_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + new_widget = gtk_progress_bar_new (); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ + +static void +gb_progress_bar_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Orientation, _("Orientation:"), + _("The orientation of the progress bar's contents"), + GbOrientationChoices); + property_add_float_range (Fraction, _("Fraction:"), + _("The fraction of work that has been completed"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (PulseStep, _("Pulse Step:"), + _("The fraction of the progress bar length to move the bouncing block when pulsed"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_string (Text, _("Text:"), + _("The text to display over the progress bar")); + + property_add_choice (Ellipsize, _("Ellipsize:"), + _("How to ellipsize the string"), + GbEllipsizeChoices); + +#if 0 + /* ShowText is implicit now, if the Text property is set to anything. */ + property_add_bool (ShowText, _("Show Text:"), + _("If the text should be shown in the progress bar")); + + /* ActivityMode is deprecated and implicit now. The app just calls + gtk_progress_bar_pulse() and it automatically goes into activity mode. */ + property_add_bool (ActivityMode, _("Activity Mode:"), + _("If the progress bar should act like the front of Kit's car")); + + /* The GtkProgress interface is deprecated now, and GtkProgressBar doesn't + have functions to set these, so I suppose we shouldn't support them. */ + property_add_float_range (XAlign, _("X Align:"), + _("The horizontal alignment of the text"), + 0, 1, 0.01, 0.1, 0.01, 2); + property_add_float_range (YAlign, _("Y Align:"), + _("The vertical alignment of the text"), + 0, 1, 0.01, 0.1, 0.01, 2); +#endif +} + + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ + +static void +gb_progress_bar_get_properties(GtkWidget *widget, GbWidgetGetArgData * data) +{ + PangoEllipsizeMode ellipsize_mode; + gint i; + + for (i = 0; i < sizeof (GbOrientationValues) / sizeof (GbOrientationValues[0]); i++) + { + if (GbOrientationValues[i] == GTK_PROGRESS_BAR (widget)->orientation) + gb_widget_output_choice (data, Orientation, i, GbOrientationSymbols[i]); + } + + gb_widget_output_float (data, Fraction, gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (widget))); + gb_widget_output_float (data, PulseStep, gtk_progress_bar_get_pulse_step (GTK_PROGRESS_BAR (widget))); + gb_widget_output_translatable_string (data, Text, gtk_progress_bar_get_text (GTK_PROGRESS_BAR (widget))); + + ellipsize_mode = gtk_progress_bar_get_ellipsize (GTK_PROGRESS_BAR (widget)); + for (i = 0; i < sizeof (GbEllipsizeValues) / sizeof (GbEllipsizeValues[0]); i++) + { + if (GbEllipsizeValues[i] == ellipsize_mode) + gb_widget_output_choice (data, Ellipsize, i, GbEllipsizeSymbols[i]); + } + +#if 0 + gb_widget_output_bool (data, ShowText, GTK_PROGRESS (widget)->show_text); + gb_widget_output_bool (data, ActivityMode, GTK_PROGRESS (widget)->activity_mode); + + gb_widget_output_float (data, XAlign, GTK_PROGRESS (widget)->x_align); + gb_widget_output_float (data, YAlign, GTK_PROGRESS (widget)->y_align); +#endif +} + + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ + +static void +gb_progress_bar_set_properties(GtkWidget * widget, GbWidgetSetArgData * data) +{ + gfloat fraction, pulse_step; +#if 0 + gfloat activityMode, xalign, yalign; + gboolean set_alignment = FALSE; + gboolean showText; +#endif + gchar *orientation, *text, *ellipsize_mode; + gint i; + + orientation = gb_widget_input_choice (data, Orientation); + if (data->apply) + { + for (i = 0; + i < sizeof (GbOrientationValues) / sizeof (GbOrientationValues[0]); + i++) + { + if (!strcmp (orientation, GbOrientationChoices[i]) + || !strcmp (orientation, GbOrientationSymbols[i])) + { + gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (widget), + GbOrientationValues[i]); + break; + } + } + } + + fraction = gb_widget_input_float (data, Fraction); + if (data->apply) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (widget), fraction); + + pulse_step = gb_widget_input_float (data, PulseStep); + if (data->apply) + gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (widget), pulse_step); + + text = gb_widget_input_string (data, Text); + if (data->apply) + gtk_progress_bar_set_text (GTK_PROGRESS_BAR (widget), text); + + ellipsize_mode = gb_widget_input_choice (data, Ellipsize); + if (data->apply) + { + for (i = 0; i < sizeof (GbEllipsizeValues) / sizeof (GbEllipsizeValues[0]); + i++) + { + if (!strcmp (ellipsize_mode, GbEllipsizeChoices[i]) + || !strcmp (ellipsize_mode, GbEllipsizeSymbols[i])) + { + gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (widget), + GbEllipsizeValues[i]); + break; + } + } + } + +#if 0 + showText = gb_widget_input_bool (data, ShowText); + if (data->apply) + gtk_progress_set_show_text (GTK_PROGRESS (widget), showText); + + activityMode = gb_widget_input_bool (data, ActivityMode); + if (data->apply) + gtk_progress_set_activity_mode (GTK_PROGRESS (widget), activityMode); + + xalign = gb_widget_input_float (data, XAlign); + if (data->apply) + set_alignment = TRUE; + else + xalign = GTK_PROGRESS (widget)->x_align; + + yalign = gb_widget_input_float (data, YAlign); + if (data->apply) + set_alignment = TRUE; + else + yalign = GTK_PROGRESS (widget)->y_align; + + if (set_alignment) + gtk_progress_set_text_alignment (GTK_PROGRESS (widget), xalign, yalign); +#endif +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_progress_bar_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gfloat fraction, pulse_step; + const char *text; + PangoEllipsizeMode ellipsize_mode; + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_progress_bar_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + if (GTK_PROGRESS_BAR (widget)->orientation != GTK_PROGRESS_LEFT_TO_RIGHT) + { + for (i = 0; i < sizeof (GbOrientationValues) / sizeof (GbOrientationValues[0]); i++) + { + if (GbOrientationValues[i] == GTK_PROGRESS_BAR (widget)->orientation) + source_add (data, + " gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (%s), %s);\n", + data->wname, GbOrientationSymbols[i]); + } + } + + fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (widget)); + if (fraction >= GLADE_EPSILON) + source_add (data, + " gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (%s), %g);\n", + data->wname, fraction); + + pulse_step = gtk_progress_bar_get_pulse_step (GTK_PROGRESS_BAR (widget)); + if (fabs (pulse_step - 0.1) >= GLADE_EPSILON) + source_add (data, + " gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (%s), %g);\n", + data->wname, pulse_step); + + text = gtk_progress_bar_get_text (GTK_PROGRESS_BAR (widget)); + if (text && *text) + { + gboolean translatable, context; + gchar *comments; + + glade_util_get_translation_properties (widget, Text, + &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " gtk_progress_bar_set_text (GTK_PROGRESS_BAR (%s), %s);\n", + data->wname, + source_make_string_full (text, data->use_gettext && translatable, context)); + } + + ellipsize_mode = gtk_progress_bar_get_ellipsize (GTK_PROGRESS_BAR (widget)); + if (ellipsize_mode != PANGO_ELLIPSIZE_NONE) + { + for (i = 0; + i < sizeof (GbEllipsizeValues) / sizeof (GbEllipsizeValues[0]); + i++) + { + if (GbEllipsizeValues[i] == ellipsize_mode) + source_add (data, + " gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR (%s), %s);\n", + data->wname, GbEllipsizeSymbols[i]); + } + } + +#if 0 + if (GTK_PROGRESS (widget)->show_text) + { + source_add( data, + " gtk_progress_set_show_text (GTK_PROGRESS (%s), TRUE);\n", + data->wname); + } + + if (GTK_PROGRESS (widget)->activity_mode) + { + source_add( data, + " gtk_progress_set_activity_mode (GTK_PROGRESS (%s), TRUE);\n", + data->wname); + } + + if (GTK_PROGRESS (widget)->x_align != 0.5 + || GTK_PROGRESS (widget)->y_align != 0.5) + { + source_add( data, + " gtk_progress_set_text_alignment (GTK_PROGRESS (%s), %g, %g);\n", + data->wname, + GTK_PROGRESS (widget)->x_align, + GTK_PROGRESS (widget)->y_align); + } +#endif +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_progress_bar_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_progress_bar_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = progressbar_xpm; + gbwidget.tooltip = _("Progress Bar"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_progress_bar_new; + + gbwidget.gb_widget_create_properties = gb_progress_bar_create_properties; + gbwidget.gb_widget_get_properties = gb_progress_bar_get_properties; + gbwidget.gb_widget_set_properties = gb_progress_bar_set_properties; + /*gbwidget.gb_widget_create_popup_menu = gb_progress_bar_create_popup_menu;*/ + gbwidget.gb_widget_write_source = gb_progress_bar_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbradiobutton.c b/tools/glade/glade/gbwidgets/gbradiobutton.c new file mode 100644 index 00000000..458e3fd6 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbradiobutton.c @@ -0,0 +1,477 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtkentry.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkradiobutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/radiobutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *StockButton = "RadioButton|GtkButton::stock_button"; +static gchar *Label = "RadioButton|GtkButton::label"; +static gchar *Icon = "RadioButton|GtkButton::icon"; +static gchar *FocusOnClick = "RadioButton|GtkButton::focus_on_click"; + +/* This is only used for normal/stock buttons, not special toolbar buttons, + as the toolbar has its own relief setting. */ +static gchar *Relief = "RadioButton|GtkButton::relief"; + +static gchar *State = "RadioButton|GtkToggleButton::active"; +static gchar *Inconsistent = "RadioButton|GtkToggleButton::inconsistent"; +static gchar *Group = "GtkRadioButton::group"; +static gchar *Indicator = "RadioButton|GtkToggleButton::draw_indicator"; + +typedef struct _GladeFindGroupsData GladeFindGroupsData; +struct _GladeFindGroupsData { + GList *groups_found; + GList *group_names; +}; + + +typedef struct _GladeFindGroupWidgetData GladeFindGroupWidgetData; +struct _GladeFindGroupWidgetData { + gchar *name; + GtkWidget *found_widget; +}; + + +static void get_radio_button_groups (GtkWidget * widget, + GladeFindGroupsData *find_data); + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +static void +find_parents_group (GtkWidget * widget, GSList ** group) +{ + /* If a group has already been found, return. */ + if (*group) + return; + + if (GTK_IS_RADIO_BUTTON (widget)) + *group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); +} + + +/* + * Creates a new GtkWidget of class GtkRadioButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_radio_button_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + GSList *group_list = NULL; + + /* When creating a radiobutton we try to place it in the same group as other + radio buttons with the same parent. */ + if (data->parent && data->action == GB_CREATING) + gb_widget_children_foreach (data->parent, (GtkCallback) find_parents_group, + &group_list); + + if (data->action == GB_CREATING) + new_widget = gtk_radio_button_new_with_label (group_list, data->name); + else + { + new_widget = gtk_radio_button_new (group_list); + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder()); + } + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_radio_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ + GtkWidget *combo; + + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_BUTTON); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_BUTTON); + property_add_choice (Relief, _("Button Relief:"), + _("The relief style of the button"), + GladeReliefChoices); + + property_add_bool (State, _("Initially On:"), + _("If the radio button is initially on")); + property_add_bool (Inconsistent, _("Inconsistent:"), + _("If the button is shown in an inconsistent state")); + property_add_bool (Indicator, _("Indicator:"), + _("If the indicator is always drawn")); + property_add_combo (Group, _("Group:"), + _("The radio button group (the default is all radio buttons with the same parent)"), + NULL); + combo = property_get_value_widget (Group); + gtk_editable_set_editable (GTK_EDITABLE (GTK_COMBO (combo)->entry), FALSE); + property_add_bool (FocusOnClick, _("Focus On Click:"), _("If the button grabs focus when it is clicked")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_radio_button_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + GtkWidget *component; + GladeFindGroupData find_data; + + component = glade_util_get_toplevel (widget); + + gb_button_get_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + gb_widget_output_bool (data, State, data->widget_data->flags & GLADE_ACTIVE); + + gb_widget_output_bool (data, Inconsistent, + GTK_TOGGLE_BUTTON (widget)->inconsistent); + + gb_widget_output_bool (data, Indicator, + GTK_TOGGLE_BUTTON (widget)->draw_indicator); + + /* If we're showing we need to display the list of groups to choose from. + We walk the tree of widgets in this component, and if a widget is + a radio button, we see if it has a group and if it is already in the + list and if not we add it. */ + if (data->action == GB_SHOWING) + { + GladeFindGroupsData find_groups_data; + + find_groups_data.groups_found = NULL; + find_groups_data.group_names = NULL; + get_radio_button_groups (component, &find_groups_data); + + find_groups_data.group_names = g_list_prepend (find_groups_data.group_names, + _("New Group")); + property_set_combo_strings (Group, find_groups_data.group_names); + + g_list_free (find_groups_data.groups_found); + g_list_free (find_groups_data.group_names); + + /*property_set_visible (Indicator, !is_toolbar_button);*/ + } + + find_data.group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); + find_data.found_widget = NULL; + gb_button_find_radio_group (component, &find_data); + + if (find_data.found_widget) + { + /* If we are saving, we don't output the group if this widget is the + first widget in the group. */ + if (data->action == GB_SHOWING || find_data.found_widget != widget) + { + const char *name; + name = gtk_widget_get_name (find_data.found_widget); + gb_widget_output_combo (data, Group, name); + } + } + else + { + g_warning ("Radiobutton has no group"); + gb_widget_output_combo (data, Group, ""); + } +} + + +/* Note that this must walk the widget tree in exactly the same way that we + save the widgets, so we know which widget in the group will be the first + output. */ +static void +get_radio_button_groups (GtkWidget * widget, GladeFindGroupsData *find_data) +{ + if (GTK_IS_RADIO_BUTTON (widget) && GB_IS_GB_WIDGET (widget)) + { + GSList *group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); + + /* See if we've already found a widget in this group. */ + if (!g_list_find (find_data->groups_found, group)) + { + const char *name = gtk_widget_get_name (GTK_WIDGET (widget)); + + /* Remember that we've already seen this group. */ + find_data->groups_found = g_list_prepend (find_data->groups_found, + group); + + /* Add the widget's name to the list. */ + find_data->group_names = g_list_insert_sorted (find_data->group_names, (char*)name, (GCompareFunc) g_utf8_collate); + } + } + + if (GTK_IS_CONTAINER (widget)) + gb_widget_children_foreach (widget, (GtkCallback) get_radio_button_groups, + find_data); +} + + +/* This tries to ensure that one and only one radio button in the given + group is selected. It's used because GtkRadioButton doesn't handle this + when groups are changed. */ +void +gb_radio_button_update_radio_group (GSList * group) +{ + GtkRadioButton *button; + GSList *slist; + gboolean found_selected = FALSE; + + if (group == NULL) + return; + + for (slist = group; slist; slist = slist->next) + { + button = GTK_RADIO_BUTTON (slist->data); + if (GTK_TOGGLE_BUTTON (button)->active) + { + if (found_selected) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE); + else + found_selected = TRUE; + } + } + /* If none are currently selected, select the first. */ + if (!found_selected) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (group->data), TRUE); +} + + +/* This recursively steps though a complete component's hierarchy to find + a radio button with a particular group name set. When found the radio + button's group list is returned in find_group_data->group. */ +static void +find_group_widget (GtkWidget *widget, GladeFindGroupWidgetData *find_data) +{ + if (find_data->found_widget) + return; + + if (GTK_IS_RADIO_BUTTON (widget) && GB_IS_GB_WIDGET (widget)) + { + if (!strcmp (gtk_widget_get_name (widget), find_data->name)) + { +#if 0 + g_print ("Found widget: %s\n", find_data->name); +#endif + find_data->found_widget = widget; + return; + } + } + + if (GTK_IS_CONTAINER (widget)) + gb_widget_children_foreach (widget, (GtkCallback) find_group_widget, + find_data); +} + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_radio_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean state, indicator, inconsistent; + gchar *group_name; + + gb_button_set_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + state = gb_widget_input_bool (data, State); + if (data->apply) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), state); + if (state) + data->widget_data->flags |= GLADE_ACTIVE; + else + data->widget_data->flags &= ~GLADE_ACTIVE; + } + + inconsistent = gb_widget_input_bool (data, Inconsistent); + if (data->apply) + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (widget), + inconsistent); + + indicator = gb_widget_input_bool (data, Indicator); + if (data->apply) + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget), indicator); + + /* Find any widgets in given group and set this widgets group. + If group is NULL try to find radiobuttons with same parent and use + their group. If these don't succeed, set group to NULL. */ + group_name = gb_widget_input_combo (data, Group); + if (data->apply) + { + GSList *old_group, *new_group = NULL; + + old_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); + + if (group_name && (group_name[0] == '\0' + || !strcmp (group_name, _("New Group")))) + group_name = NULL; + + if (group_name) + { + GladeFindGroupWidgetData find_data; + GtkWidget *component; + + component = glade_util_get_toplevel (widget); + + find_data.name = group_name; + find_data.found_widget = NULL; + find_group_widget (component, &find_data); + + if (find_data.found_widget) + new_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (find_data.found_widget)); + else if (data->action == GB_LOADING) + g_warning ("Invalid radio group: %s\n (Note that forward references are not allowed in Glade files)", group_name); + } + +#if 0 + g_print ("New Group: %p Old Group: %p\n", new_group, old_group); +#endif + + if (new_group != old_group) + { +#if 0 + g_print ("##### setting radio group: %s\n", + group_name ? group_name : "NULL"); +#endif + gtk_radio_button_set_group (GTK_RADIO_BUTTON (widget), new_group); + } + } +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_radio_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GladeFindGroupData find_data; + GtkWidget *group_widget; + gchar buffer[256], *group_name; + + find_data.group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); + find_data.found_widget = NULL; + gb_button_find_radio_group (glade_util_get_toplevel (widget), &find_data); + + group_widget = find_data.found_widget; + if (!group_widget) + { + g_warning ("Radiobutton has no group"); + group_widget = widget; + } + + gb_button_write_standard_source (widget, data, Label); + + /* Make sure the temporary group list variable is declared. */ + group_name = (char*) gtk_widget_get_name (group_widget); + group_name = source_create_valid_identifier (group_name); + sprintf (buffer, " GSList *%s_group = NULL;\n", group_name); + source_ensure_decl (data, buffer); + + source_add (data, + " gtk_radio_button_set_group (GTK_RADIO_BUTTON (%s), %s_group);\n", + data->wname, group_name); + source_add (data, + " %s_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (%s));\n", + group_name, data->wname); + g_free (group_name); + + if (data->widget_data->flags & GLADE_ACTIVE) + { + source_add (data, + " gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (GTK_TOGGLE_BUTTON (widget)->inconsistent) + { + source_add (data, + " gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (!GTK_TOGGLE_BUTTON (widget)->draw_indicator) + { + source_add (data, + " gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (%s), FALSE);\n", + data->wname); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_radio_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_radio_button_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = radiobutton_xpm; + gbwidget.tooltip = _("Radio Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_radio_button_new; + gbwidget.gb_widget_create_properties = gb_radio_button_create_properties; + gbwidget.gb_widget_get_properties = gb_radio_button_get_properties; + gbwidget.gb_widget_set_properties = gb_radio_button_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_button_create_popup_menu; + gbwidget.gb_widget_write_source = gb_radio_button_write_source; + gbwidget.gb_widget_destroy = gb_button_destroy; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbradiomenuitem.c b/tools/glade/glade/gbwidgets/gbradiomenuitem.c new file mode 100644 index 00000000..7a9b4348 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbradiomenuitem.c @@ -0,0 +1,399 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkradiomenuitem.h> +#include "../gb.h" +#include "../glade_gnome.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/radiomenuitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Label = "RadioMenuItem|GtkItem::label"; +static gchar *State = "RadioMenuItem|GtkCheckMenuItem::active"; +static gchar *Group = "GtkRadioMenuItem::group"; + + +typedef struct _GladeFindGroupWidgetData GladeFindGroupWidgetData; +struct _GladeFindGroupWidgetData { + gchar *name; + GtkWidget *found_widget; +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +static void +find_parents_group (GtkWidget * widget, GSList ** group) +{ + /* If a group has already been found, return. */ + if (*group) + return; + + if (GTK_IS_RADIO_MENU_ITEM (widget)) + { + *group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (widget)); + } +} + + +/* + * Creates a new GtkWidget of class GtkRadioMenuItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_radio_menu_item_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + GSList *group_list = NULL; + + /* When creating a radiomenuitem we try to place it in the same group as + other radiomenuitems with the same parent. */ + if (data->parent && data->action == GB_CREATING) + gtk_container_foreach (GTK_CONTAINER (data->parent), + (GtkCallback) find_parents_group, &group_list); + + if (data->action == GB_CREATING) + new_widget = gtk_radio_menu_item_new_with_label (group_list, data->name); + else + new_widget = gtk_radio_menu_item_new (group_list); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_radio_menu_item_create_properties (GtkWidget * widget, GbWidgetCreateArgData + * data) +{ + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_bool (State, _("Initially On:"), + _("If the radio menu item is initially on")); + property_add_combo (Group, _("Group:"), + _("The radio menu item group (the default is all radio menu items with the same parent)"), + NULL); + /* The Group property is only used for loading and saving at present. */ + property_set_visible (Group, FALSE); +} + + + +void +gb_radio_menu_item_find_radio_group (GtkWidget *widget, + GladeFindGroupData *find_data) +{ + if (find_data->found_widget) + return; + + if (GTK_IS_RADIO_MENU_ITEM (widget) && GB_IS_GB_WIDGET (widget)) + { + if (gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (widget)) == find_data->group) + { + find_data->found_widget = widget; + return; + } + } + + if (GTK_IS_CONTAINER (widget)) + gb_widget_children_foreach (widget, + (GtkCallback) gb_radio_menu_item_find_radio_group, + find_data); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_radio_menu_item_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_widget_output_child_label (widget, data, Label); + + gb_widget_output_bool (data, State, data->widget_data->flags & GLADE_ACTIVE); + + /* We only output the group when saving, for now. */ + if (data->action == GB_SAVING) + { + GladeFindGroupData find_data; + GtkWidget *component; + + component = glade_util_get_toplevel (widget); + + find_data.group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (widget)); + find_data.found_widget = NULL; + gb_radio_menu_item_find_radio_group (component, &find_data); + + if (find_data.found_widget) + { + /* We don't output the group if this widget is the first widget in + the group. */ + if (find_data.found_widget != widget) + { + const char *name; + name = gtk_widget_get_name (find_data.found_widget); + gb_widget_output_combo (data, Group, name); + } + } + } +} + + +/* This recursively steps though a complete component's hierarchy to find + a radio button with a particular group name set. When found the radio + button's group list is returned in find_group_data->group. */ +static void +find_group_widget (GtkWidget *widget, GladeFindGroupWidgetData *find_data) +{ + if (find_data->found_widget) + return; + + if (GTK_IS_RADIO_MENU_ITEM (widget) && GB_IS_GB_WIDGET (widget)) + { + if (!strcmp (gtk_widget_get_name (widget), find_data->name)) + { +#if 0 + g_print ("Found widget: %s\n", find_data->name); +#endif + find_data->found_widget = widget; + return; + } + } + + if (GTK_IS_CONTAINER (widget)) + gb_widget_children_foreach (widget, (GtkCallback) find_group_widget, + find_data); +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_radio_menu_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean state; + + gb_widget_input_child_label (widget, data, Label); + + state = gb_widget_input_bool (data, State); + if (data->apply) + { + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), state); + if (state) + data->widget_data->flags |= GLADE_ACTIVE; + else + data->widget_data->flags &= ~GLADE_ACTIVE; + } + + /* We only set the group when loading, for now. */ + if (data->action == GB_LOADING) + { + gchar *group_name; + + /* Find any widgets in given group and set this widgets group. + If group is NULL try to find radiomenuitems with same parent and use + their group. If these don't succeed, set group to NULL. */ + group_name = gb_widget_input_combo (data, Group); + if (data->apply) + { + GSList *old_group, *new_group = NULL; + + old_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (widget)); + + if (group_name && group_name[0] == '\0') + group_name = NULL; + + if (group_name) + { + GladeFindGroupWidgetData find_data; + GtkWidget *component; + + component = glade_util_get_toplevel (widget); + + find_data.name = group_name; + find_data.found_widget = NULL; + find_group_widget (component, &find_data); + + if (find_data.found_widget) + new_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (find_data.found_widget)); + else if (data->action == GB_LOADING) + g_warning ("Invalid radio group: %s\n (Note that forward references are not allowed in Glade files)", group_name); + } + + if (new_group != old_group) + { +#if 0 + g_print ("##### setting radio group: %s\n", + group_name ? group_name : "NULL"); +#endif + gtk_radio_menu_item_set_group (GTK_RADIO_MENU_ITEM (widget), + new_group); + } + } + } +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkRadioMenuItem, with signals pointing to + * other functions in this file. + */ +static void +gb_radio_menu_item_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData + * data) +{ + /* Add command to remove child label. */ +#if 0 + gb_widget_create_child_label_popup_menu (widget, data); +#endif +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_radio_menu_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * + data) +{ + GladeFindGroupData find_data; + GtkWidget *group_widget; + GtkWidget *child = GTK_BIN (widget)->child; + gchar buffer[256], *group_name, *label_text; + gboolean translatable, context; + gchar *comments; + +#ifdef USE_GNOME + if (data->project->gnome_support) + { + glade_gnome_write_menu_item_source (GTK_MENU_ITEM (widget), data); + return; + } +#endif + + find_data.group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (widget)); + find_data.found_widget = NULL; + gb_radio_menu_item_find_radio_group (glade_util_get_toplevel (widget), + &find_data); + + group_widget = find_data.found_widget; + if (!group_widget) + { + g_warning ("Radiobutton has no group"); + group_widget = widget; + } + + if (data->create_widget) + { + /* Make sure the temporary group list variable is declared. */ + group_name = (char*) gtk_widget_get_name (group_widget); + group_name = source_create_valid_identifier (group_name); + sprintf (buffer, " GSList *%s_group = NULL;\n", group_name); + source_ensure_decl (data, buffer); + + if (child && GTK_IS_LABEL (child) && !GB_IS_GB_WIDGET (child)) + { + label_text = glade_util_get_label_text (child); + + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, + " %s = gtk_radio_menu_item_new_with_mnemonic (%s_group, %s);\n", + data->wname, group_name, + source_make_string_full (label_text, data->use_gettext && translatable, context)); + g_free (label_text); + } + else + { + source_add (data, " %s = gtk_radio_menu_item_new (%s_group);\n", + data->wname, group_name); + } + source_add (data, + " %s_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (%s));\n", + group_name, data->wname); + g_free (group_name); + } + + gb_widget_write_standard_source (widget, data); + + if (data->widget_data->flags & GLADE_ACTIVE) + { + source_add (data, + " gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_radio_menu_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_radio_menu_item_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = radiomenuitem_xpm; + gbwidget.tooltip = _("Radio Menu Item"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_radio_menu_item_new; + gbwidget.gb_widget_create_properties = gb_radio_menu_item_create_properties; + gbwidget.gb_widget_get_properties = gb_radio_menu_item_get_properties; + gbwidget.gb_widget_set_properties = gb_radio_menu_item_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_radio_menu_item_create_popup_menu; + gbwidget.gb_widget_write_source = gb_radio_menu_item_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbradiotoolbutton.c b/tools/glade/glade/gbwidgets/gbradiotoolbutton.c new file mode 100644 index 00000000..95faf681 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbradiotoolbutton.c @@ -0,0 +1,545 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/radiotoolbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *StockButton = "GtkRadioToolButton|GtkToolButton::stock_id"; +static gchar *Label = "GtkRadioToolButton|GtkToolButton::label"; +static gchar *Icon = "GtkRadioToolButton|GtkToolButton::icon"; +static gchar *VisibleHorz = "GtkRadioToolButton|GtkToolItem::visible_horizontal"; +static gchar *VisibleVert = "GtkRadioToolButton|GtkToolItem::visible_vertical"; +static gchar *IsImportant = "GtkRadioToolButton|GtkToolItem::is_important"; + +static gchar *Group = "GtkRadioToolButton::group"; +static gchar *Active = "GtkRadioToolButton|GtkToggleToolButton::active"; + + +typedef struct _GladeFindGroupsData GladeFindGroupsData; +struct _GladeFindGroupsData { + GList *groups_found; + GList *group_names; +}; + + +typedef struct _GladeFindGroupWidgetData GladeFindGroupWidgetData; +struct _GladeFindGroupWidgetData { + gchar *name; + GtkWidget *found_widget; +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +static void +find_parents_group (GtkWidget * widget, GSList ** group) +{ + /* If a group has already been found, return. */ + if (*group) + return; + + if (GTK_IS_RADIO_TOOL_BUTTON (widget)) + *group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (widget)); +} + + +/* + * Creates a new GtkWidget of class GtkRadioToolButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_radio_tool_button_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget, *image; + GbWidget *pixmap_gbwidget; + GSList *group_list = NULL; + + /* When creating a radiotoolbutton we try to place it in the same group + as other radiotoolbuttons in the same toolbar. */ + if (data->action == GB_CREATING) + { + GtkWidget *parent = data->parent; + while (parent && !GTK_IS_TOOLBAR (parent)) + parent = parent->parent; + if (parent) + gb_widget_children_foreach (parent, + (GtkCallback) find_parents_group, + &group_list); + } + + /* Place the pixmap icon in the button initially (even when loading). */ + pixmap_gbwidget = gb_widget_lookup_class ("GtkImage"); + if (pixmap_gbwidget) + { + image = gtk_image_new_from_pixmap (pixmap_gbwidget->gdkpixmap, + pixmap_gbwidget->mask); + } + else + { + image = gtk_image_new (); + g_warning ("Couldn't find GtkPixmap data"); + } + gtk_widget_show (image); + + new_widget = (GtkWidget*) gtk_radio_tool_button_new (group_list); + + gtk_tool_button_set_label (GTK_TOOL_BUTTON (new_widget), ""); + gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (new_widget), image); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_radio_tool_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + GtkWidget *combo; + + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + + property_add_combo (Group, _("Group:"), + _("The radio tool button group (the default is all radio tool buttons in the toolbar)"), + NULL); + combo = property_get_value_widget (Group); + gtk_editable_set_editable (GTK_EDITABLE (GTK_COMBO (combo)->entry), FALSE); + + property_add_bool (Active, _("Initially On:"), + _("If the radio button is initially on")); + + property_add_bool (VisibleHorz, _("Show Horizontal:"), + _("If the item is visible when the toolbar is horizontal")); + property_add_bool (VisibleVert, _("Show Vertical:"), + _("If the item is visible when the toolbar is vertical")); + property_add_bool (IsImportant, _("Is Important:"), + _("If the item's text should be shown when the toolbar's mode is GTK_TOOLBAR_BOTH_HORIZ")); +} + + +/* Note that this must walk the widget tree in exactly the same way that we + save the widgets, so we know which widget in the group will be the first + output. */ +static void +get_radio_button_groups (GtkWidget * widget, GladeFindGroupsData *find_data) +{ + if (GTK_IS_RADIO_TOOL_BUTTON (widget) && GB_IS_GB_WIDGET (widget)) + { + GSList *group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (widget)); + + /* See if we've already found a widget in this group. */ + if (!g_list_find (find_data->groups_found, group)) + { + const char *name = gtk_widget_get_name (GTK_WIDGET (widget)); + + /* Remember that we've already seen this group. */ + find_data->groups_found = g_list_prepend (find_data->groups_found, + group); + + /* Add the widget's name to the list. */ + find_data->group_names = g_list_insert_sorted (find_data->group_names, (char*)name, (GCompareFunc) g_utf8_collate); + } + } +} + + +static void +find_radio_group (GtkWidget *widget, GladeFindGroupData *find_data) +{ + if (find_data->found_widget) + return; + + if (GTK_IS_RADIO_TOOL_BUTTON (widget) && GB_IS_GB_WIDGET (widget)) + { + if (gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (widget)) == find_data->group) + { + find_data->found_widget = widget; + } + } +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_radio_tool_button_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + GladeFindGroupData find_data; + + gb_tool_button_get_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); + + gb_widget_output_bool (data, Active, + data->widget_data->flags & GLADE_ACTIVE); + + /* If we're showing we need to display the list of groups to choose from. + We walk the tree of widgets in this component, and if a widget is + a radio button, we see if it has a group and if it is already in the + list and if not we add it. */ + if (data->action == GB_SHOWING) + { + GladeFindGroupsData find_groups_data; + + find_groups_data.groups_found = NULL; + find_groups_data.group_names = NULL; + gb_widget_children_foreach (widget->parent, + (GtkCallback) get_radio_button_groups, + &find_groups_data); + + find_groups_data.group_names = g_list_prepend (find_groups_data.group_names, + _("New Group")); + property_set_combo_strings (Group, find_groups_data.group_names); + + g_list_free (find_groups_data.groups_found); + g_list_free (find_groups_data.group_names); + } + + find_data.group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (widget)); + find_data.found_widget = NULL; + gb_widget_children_foreach (widget->parent, + (GtkCallback) find_radio_group, + &find_data); + + if (find_data.found_widget) + { + /* If we are saving, we don't output the group if this widget is the + first widget in the group. */ + if (data->action == GB_SHOWING || find_data.found_widget != widget) + { + const char *name; + name = gtk_widget_get_name (find_data.found_widget); + gb_widget_output_combo (data, Group, name); + } + } + else + { + g_warning ("Radiotoolbutton has no group"); + gb_widget_output_combo (data, Group, ""); + } +} + + + +static void +find_group_widget (GtkWidget *widget, GladeFindGroupWidgetData *find_data) +{ + if (find_data->found_widget) + return; + + if (GTK_IS_RADIO_TOOL_BUTTON (widget) && GB_IS_GB_WIDGET (widget)) + { + if (!strcmp (gtk_widget_get_name (widget), find_data->name)) + { +#if 0 + g_print ("Found widget: %s\n", find_data->name); +#endif + find_data->found_widget = widget; + } + } +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_radio_tool_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean active; + gchar *group_name; + + gb_tool_button_set_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); + + active = gb_widget_input_bool (data, Active); + if (data->apply) + { + gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (widget), + active); + if (active) + data->widget_data->flags |= GLADE_ACTIVE; + else + data->widget_data->flags &= ~GLADE_ACTIVE; + } + + /* Find any widgets in given group and set this widgets group. + If group is NULL try to find radiobuttons with same parent and use + their group. If these don't succeed, set group to NULL. */ + group_name = gb_widget_input_combo (data, Group); + if (data->apply) + { + GSList *old_group, *new_group = NULL; + + old_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (widget)); + + if (group_name && (group_name[0] == '\0' + || !strcmp (group_name, _("New Group")))) + group_name = NULL; + + if (group_name) + { + GladeFindGroupWidgetData find_data; + + find_data.name = group_name; + find_data.found_widget = NULL; + gb_widget_children_foreach (widget->parent, + (GtkCallback) find_group_widget, + &find_data); + + if (find_data.found_widget) + new_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (find_data.found_widget)); + else if (data->action == GB_LOADING) + g_warning ("Invalid radio group: %s\n (Note that forward references are not allowed in Glade files)", group_name); + } + +#if 0 + g_print ("New Group: %p Old Group: %p\n", new_group, old_group); +#endif + + if (new_group != old_group) + { +#if 0 + g_print ("##### setting radio group: %s\n", + group_name ? group_name : "NULL"); +#endif + gtk_radio_tool_button_set_group (GTK_RADIO_TOOL_BUTTON (widget), + new_group); + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkRadioToolButton, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_radio_tool_button_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_radio_tool_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GladeFindGroupData find_data; + GtkWidget *group_widget; + gchar *stock_id, *label, *icon_name; + gchar buffer[256], *group_name; + gboolean translatable, context; + gchar *comments; + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonStockIDKey); + icon_name = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonIconKey); + label = (gchar*) gtk_tool_button_get_label (GTK_TOOL_BUTTON (widget)); + + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + + find_data.group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (widget)); + find_data.found_widget = NULL; + gb_widget_children_foreach (widget->parent, + (GtkCallback) find_radio_group, + &find_data); + + group_widget = find_data.found_widget; + if (!group_widget) + { + g_warning ("Radiotoolbutton has no group"); + group_widget = widget; + } + group_name = (char*) gtk_widget_get_name (group_widget); + group_name = source_create_valid_identifier (group_name); + sprintf (buffer, " GSList *%s_group = NULL;\n", group_name); + source_ensure_decl (data, buffer); + + if (data->create_widget) + { + if (stock_id) + { + /* Stock Button */ + source_add (data, + " %s = (GtkWidget*) gtk_radio_tool_button_new_from_stock (NULL, %s);\n", + data->wname, source_make_string (stock_id, FALSE)); + } + else if (icon_name) + { + /* Icon and Label */ + source_add (data, + " %s = (GtkWidget*) gtk_radio_tool_button_new (NULL);\n", + data->wname); + + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + + source_ensure_decl (data, " GtkWidget *tmp_image;\n"); + + if (glade_util_check_is_stock_id (icon_name)) + { + source_add (data, + " tmp_image = gtk_image_new_from_stock (\"%s\", tmp_toolbar_icon_size);\n", + icon_name); + } + else + { + source_create_pixmap (data, "tmp_image", icon_name); + } + + source_add (data, " gtk_widget_show (tmp_image);\n"); + + source_add (data, + " gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (%s), tmp_image);\n", + data->wname); + } + else + { + /* Just a Label */ + source_add (data, + " %s = (GtkWidget*) gtk_radio_tool_button_new (NULL);\n", + data->wname); + + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + } + } + + gb_widget_write_standard_source (widget, data); + + source_add (data, + " gtk_radio_tool_button_set_group (GTK_RADIO_TOOL_BUTTON (%s), %s_group);\n", + data->wname, group_name); + source_add (data, + " %s_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (%s));\n", + group_name, data->wname); + + if (data->widget_data->flags & GLADE_ACTIVE) + { + source_add (data, + " gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))) + { + source_add (data, + " gtk_tool_item_set_is_important (GTK_TOOL_ITEM (%s), TRUE);\n", + data->wname); + } + + g_free (group_name); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_radio_tool_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_radio_tool_button_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = radiotoolbutton_xpm; + gbwidget.tooltip = _("Toolbar Radio Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_radio_tool_button_new; + gbwidget.gb_widget_create_properties = gb_radio_tool_button_create_properties; + gbwidget.gb_widget_get_properties = gb_radio_tool_button_get_properties; + gbwidget.gb_widget_set_properties = gb_radio_tool_button_set_properties; + gbwidget.gb_widget_write_source = gb_radio_tool_button_write_source; + gbwidget.gb_widget_destroy = gb_tool_button_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_radio_tool_button_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbscrolledwindow.c b/tools/glade/glade/gbwidgets/gbscrolledwindow.c new file mode 100644 index 00000000..566a5120 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbscrolledwindow.c @@ -0,0 +1,366 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkscrolledwindow.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/scrolledwindow.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *HPolicy = "GtkScrolledWindow::hscrollbar_policy"; +static gchar *VPolicy = "GtkScrolledWindow::vscrollbar_policy"; + +static gchar *WindowPlacement = "GtkScrolledWindow::window_placement"; +static gchar *ShadowType = "GtkScrolledWindow::shadow_type"; + +/* I don't think there's any point in adding these. */ +/* + static gchar *HValues[] = { + "GtkScrolledWindow::hvalue", + "GtkScrolledWindow::hlower", + "GtkScrolledWindow::hupper", + "GtkScrolledWindow::hstep", + "GtkScrolledWindow::hpage", + "GtkScrolledWindow::hpage_size", + }; + + static gchar *VValues[] = { + "GtkScrolledWindow::vvalue", + "GtkScrolledWindow::vlower", + "GtkScrolledWindow::vupper", + "GtkScrolledWindow::vstep", + "GtkScrolledWindow::vpage", + "GtkScrolledWindow::vpage_size", + }; + */ + + +static const gchar *GbPolicyChoices[] = +{ + "Always", + "Automatic", + "Never", + NULL +}; +static const gint GbPolicyValues[] = +{ + GTK_POLICY_ALWAYS, + GTK_POLICY_AUTOMATIC, + GTK_POLICY_NEVER +}; +static const gchar *GbPolicySymbols[] = +{ + "GTK_POLICY_ALWAYS", + "GTK_POLICY_AUTOMATIC", + "GTK_POLICY_NEVER" +}; + +/* These aren't really useful so we'll remove them. They should be in the + scrollbar internal children anyway. */ +/* +static const gchar *GbUpdatePolicyChoices[] = +{"Continuous", "Discontinuous", + "Delayed", NULL}; +static const gint GbUpdatePolicyValues[] = +{ + GTK_UPDATE_CONTINUOUS, + GTK_UPDATE_DISCONTINUOUS, + GTK_UPDATE_DELAYED +}; +static const gchar *GbUpdatePolicySymbols[] = +{ + "GTK_UPDATE_CONTINUOUS", + "GTK_UPDATE_DISCONTINUOUS", + "GTK_UPDATE_DELAYED" +}; +*/ + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkScrolledWindow, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_scrolled_window_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_scrolled_window_new (NULL, NULL); + if (data->action != GB_LOADING) + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_scrolled_window_create_properties (GtkWidget * widget, GbWidgetCreateArgData + * data) +{ + property_add_choice (HPolicy, _("H Policy:"), + _("When the horizontal scrollbar will be shown"), + GbPolicyChoices); + property_add_choice (VPolicy, _("V Policy:"), + _("When the vertical scrollbar will be shown"), + GbPolicyChoices); + property_add_choice (WindowPlacement, _("Window Pos:"), + _("Where the child window is located with respect to the scrollbars"), + GladeCornerChoices); + property_add_choice (ShadowType, _("Shadow Type:"), + _("The update policy of the vertical scrollbar"), + GladeShadowChoices); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_scrolled_window_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == GTK_SCROLLED_WINDOW (widget)->hscrollbar_policy) + gb_widget_output_choice (data, HPolicy, i, GbPolicySymbols[i]); + } + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == GTK_SCROLLED_WINDOW (widget)->vscrollbar_policy) + gb_widget_output_choice (data, VPolicy, i, GbPolicySymbols[i]); + } + + for (i = 0; i < GladeShadowChoicesSize; i++) + { + if (GladeShadowValues[i] == GTK_SCROLLED_WINDOW (widget)->shadow_type) + gb_widget_output_choice (data, ShadowType, i, GladeShadowSymbols[i]); + } + + for (i = 0; i < GladeCornerChoicesSize; i++) + { + if (GladeCornerValues[i] == GTK_SCROLLED_WINDOW (widget)->window_placement) + gb_widget_output_choice (data, WindowPlacement, i, + GladeCornerSymbols[i]); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_scrolled_window_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gint i; + gchar *hpolicy, *vpolicy; + gboolean set_policy = FALSE; + GtkPolicyType hpolicy_value = GTK_POLICY_AUTOMATIC; + GtkPolicyType vpolicy_value = GTK_POLICY_AUTOMATIC; + gchar *shadow, *placement; + + hpolicy = gb_widget_input_choice (data, HPolicy); + if (data->apply) + { + set_policy = TRUE; + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); + i++) + { + if (!strcmp (hpolicy, GbPolicyChoices[i]) + || !strcmp (hpolicy, GbPolicySymbols[i])) + hpolicy_value = GbPolicyValues[i]; + } + } + else + hpolicy_value = GTK_SCROLLED_WINDOW (widget)->hscrollbar_policy; + + vpolicy = gb_widget_input_choice (data, VPolicy); + if (data->apply) + { + set_policy = TRUE; + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); + i++) + { + if (!strcmp (vpolicy, GbPolicyChoices[i]) + || !strcmp (vpolicy, GbPolicySymbols[i])) + vpolicy_value = GbPolicyValues[i]; + } + } + else + vpolicy_value = GTK_SCROLLED_WINDOW (widget)->vscrollbar_policy; + + if (set_policy) + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (widget), + hpolicy_value, vpolicy_value); + + shadow = gb_widget_input_choice (data, ShadowType); + if (data->apply) + { + for (i = 0; i < GladeShadowChoicesSize; i++) + { + if (!strcmp (shadow, GladeShadowChoices[i]) + || !strcmp (shadow, GladeShadowSymbols[i])) + { + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (widget), GladeShadowValues[i]); + break; + } + } + } + + placement = gb_widget_input_choice (data, WindowPlacement); + if (data->apply) + { + for (i = 0; i < GladeCornerChoicesSize; i++) + { + if (!strcmp (placement, GladeCornerChoices[i]) + || !strcmp (placement, GladeCornerSymbols[i])) + { + gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (widget), + GladeCornerValues[i]); + break; + } + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkScrolledWindow, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_scrolled_window_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_scrolled_window_write_source (GtkWidget * widget, GbWidgetWriteSourceData * + data) +{ + const gchar *hpolicy = GbPolicySymbols[0], *vpolicy = GbPolicySymbols[0]; + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_scrolled_window_new (NULL, NULL);\n", + data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (GTK_SCROLLED_WINDOW (widget)->hscrollbar_policy != GTK_POLICY_ALWAYS + || GTK_SCROLLED_WINDOW (widget)->vscrollbar_policy != GTK_POLICY_ALWAYS) + { + for (i = 0; i < sizeof (GbPolicyValues) + / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == GTK_SCROLLED_WINDOW (widget)->hscrollbar_policy) + hpolicy = GbPolicySymbols[i]; + if (GbPolicyValues[i] == GTK_SCROLLED_WINDOW (widget)->vscrollbar_policy) + vpolicy = GbPolicySymbols[i]; + } + source_add (data, " gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (%s), %s, %s);\n", + data->wname, hpolicy, vpolicy); + } + + if (GTK_SCROLLED_WINDOW (widget)->shadow_type != GTK_SHADOW_NONE) + { + for (i = 0; i < GladeShadowChoicesSize; i++) + { + if (GladeShadowValues[i] == GTK_SCROLLED_WINDOW (widget)->shadow_type) + source_add (data, " gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (%s), %s);\n", + data->wname, GladeShadowSymbols[i]); + } + } + + if (GTK_SCROLLED_WINDOW (widget)->window_placement != GTK_CORNER_TOP_LEFT) + { + for (i = 0; i < GladeCornerChoicesSize; i++) + { + if (GladeCornerValues[i] == GTK_SCROLLED_WINDOW (widget)->window_placement) + source_add (data, " gtk_scrolled_window_set_placement (GTK_SCROLLED_WINDOW (%s), %s);\n", + data->wname, GladeCornerSymbols[i]); + } + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_scrolled_window_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_scrolled_window_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = scrolledwindow_xpm; + gbwidget.tooltip = _("Scrolled Window"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_scrolled_window_new; + gbwidget.gb_widget_create_properties = gb_scrolled_window_create_properties; + gbwidget.gb_widget_get_properties = gb_scrolled_window_get_properties; + gbwidget.gb_widget_set_properties = gb_scrolled_window_set_properties; + gbwidget.gb_widget_write_source = gb_scrolled_window_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_scrolled_window_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbseparatormenuitem.c b/tools/glade/glade/gbwidgets/gbseparatormenuitem.c new file mode 100644 index 00000000..be4c1fbf --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbseparatormenuitem.c @@ -0,0 +1,166 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkseparatormenuitem.h> +#include "../gb.h" +#include "../glade_gnome.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/menuitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkSeparatorMenuItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_separator_menu_item_new(GbWidgetNewData *data) +{ + return gtk_separator_menu_item_new (); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +/* + static void + gb_separator_menu_item_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) + { + + } + */ + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +/* + static void + gb_separator_menu_item_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) + { + + } + */ + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +/* + static void + gb_separator_menu_item_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) + { + + } + */ + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkSeparatorMenuItem, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_separator_menu_item_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_separator_menu_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ +#ifdef USE_GNOME + if (data->project->gnome_support) + { + glade_gnome_write_menu_item_source (GTK_MENU_ITEM (widget), data); + return; + } +#endif + + if (data->create_widget) + { + source_add (data, " %s = gtk_separator_menu_item_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_separator_menu_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_separator_menu_item_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = menuitem_xpm; + gbwidget.tooltip = _("Separator for Menus"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_separator_menu_item_new; +/* + gbwidget.gb_widget_create_properties = gb_separator_menu_item_create_properties; + gbwidget.gb_widget_get_properties = gb_separator_menu_item_get_properties; + gbwidget.gb_widget_set_properties = gb_separator_menu_item_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_separator_menu_item_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_separator_menu_item_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbseparatortoolitem.c b/tools/glade/glade/gbwidgets/gbseparatortoolitem.c new file mode 100644 index 00000000..038eea37 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbseparatortoolitem.c @@ -0,0 +1,218 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/separatortoolitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Draw = "GtkSeparatorToolItem::draw"; +static gchar *VisibleHorz = "GtkSeparatorToolItem|GtkToolItem::visible_horizontal"; +static gchar *VisibleVert = "GtkSeparatorToolItem|GtkToolItem::visible_vertical"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkSeparatorToolItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +/* +static GtkWidget* +gb_separator_tool_item_new (GbWidgetNewData *data) +{ + +} +*/ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_separator_tool_item_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (Draw, _("Draw:"), + _("If the separator is drawn, or just blank")); + property_add_bool (VisibleHorz, _("Show Horizontal:"), + _("If the item is visible when the toolbar is horizontal")); + property_add_bool (VisibleVert, _("Show Vertical:"), + _("If the item is visible when the toolbar is vertical")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_separator_tool_item_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_widget_output_bool (data, Draw, + gtk_separator_tool_item_get_draw (GTK_SEPARATOR_TOOL_ITEM (widget))); + + gb_widget_output_bool (data, VisibleHorz, + gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) + != NULL ? FALSE : TRUE); + + gb_widget_output_bool (data, VisibleVert, + gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) + != NULL ? FALSE : TRUE); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_separator_tool_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean draw, visible_horz, visible_vert; + + draw = gb_widget_input_bool (data, Draw); + if (data->apply) + { + gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (widget), + draw); + } + + visible_horz = gb_widget_input_bool (data, VisibleHorz); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), VisibleHorz, + visible_horz ? NULL : "FALSE"); + } + + visible_vert = gb_widget_input_bool (data, VisibleVert); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), VisibleVert, + visible_vert ? NULL : "FALSE"); + } + +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkSeparatorToolItem, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_separator_tool_item_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_separator_tool_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, + " %s = (GtkWidget*) gtk_separator_tool_item_new ();\n", + data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (!gtk_separator_tool_item_get_draw (GTK_SEPARATOR_TOOL_ITEM (widget))) + { + source_add (data, + " gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_separator_tool_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_separator_tool_item_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = separatortoolitem_xpm; + gbwidget.tooltip = _("Toolbar Separator Item"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_separator_tool_item_create_properties; + gbwidget.gb_widget_get_properties = gb_separator_tool_item_get_properties; + gbwidget.gb_widget_set_properties = gb_separator_tool_item_set_properties; + gbwidget.gb_widget_write_source = gb_separator_tool_item_write_source; +/* + gbwidget.gb_widget_new = gb_separator_tool_item_new; + gbwidget.gb_widget_create_popup_menu = gb_separator_tool_item_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbspinbutton.c b/tools/glade/glade/gbwidgets/gbspinbutton.c new file mode 100644 index 00000000..38c986fc --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbspinbutton.c @@ -0,0 +1,297 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkspinbutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/spinbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *ClimbRate = "GtkSpinButton::climb_rate"; +static gchar *Digits = "GtkSpinButton::digits"; +static gchar *Numeric = "GtkSpinButton::numeric"; +static gchar *Policy = "GtkSpinButton::update_policy"; +static gchar *Snap = "GtkSpinButton::snap_to_ticks"; +static gchar *Wrap = "GtkSpinButton::wrap"; + + +static const gchar *Values[] = +{ + "GtkSpinButton::value", + "GtkSpinButton::lower", + "GtkSpinButton::upper", + "GtkSpinButton::step", + "GtkSpinButton::page", + "GtkSpinButton::page_size", +}; + +static const gchar *GbPolicyChoices[] = +{"Always", "If Valid", NULL}; +static const gint GbPolicyValues[] = +{ + GTK_UPDATE_ALWAYS, + GTK_UPDATE_IF_VALID +}; +static const gchar *GbPolicySymbols[] = +{ + "GTK_UPDATE_ALWAYS", + "GTK_UPDATE_IF_VALID" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkSpinButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_spin_button_new (GbWidgetNewData * data) +{ + GtkObject *adjustment = gtk_adjustment_new (1, 0, 100, 1, 10, 10); + return gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 1, 0); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_spin_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ + property_add_float (ClimbRate, _("Climb Rate:"), + _("The climb rate of the spinbutton, used in conjunction with the Page Increment")); + property_add_int_range (Digits, _("Digits:"), + _("The number of decimal digits to show"), + 0, 5, 1, 1, 0); + property_add_bool (Numeric, _("Numeric:"), + _("If only numeric entry is allowed")); + property_add_choice (Policy, _("Update Policy:"), + _("When value_changed signals are emitted"), + GbPolicyChoices); + property_add_bool (Snap, _("Snap:"), + _("If the value is snapped to multiples of the step increment")); + property_add_bool (Wrap, _("Wrap:"), + _("If the value is wrapped at the limits")); + property_add_adjustment (Values, GB_ADJUST_DEFAULT_LABELS); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_spin_button_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i, update_policy; + gb_widget_output_float (data, ClimbRate, GTK_SPIN_BUTTON (widget)->climb_rate); + gb_widget_output_int (data, Digits, GTK_SPIN_BUTTON (widget)->digits); + gb_widget_output_bool (data, Numeric, GTK_SPIN_BUTTON (widget)->numeric); + + /* This is a slight kludge since the spin_button's update policy is + a set of flags rather than integer values */ + update_policy = GTK_SPIN_BUTTON (widget)->update_policy + & (GTK_UPDATE_ALWAYS | GTK_UPDATE_IF_VALID); + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == update_policy) + gb_widget_output_choice (data, Policy, i, GbPolicySymbols[i]); + } + /* In GTK 1.1 snap_to_ticks is given its own variable. */ + gb_widget_output_bool (data, Snap, GTK_SPIN_BUTTON (widget)->snap_to_ticks); + + gb_widget_output_bool (data, Wrap, GTK_SPIN_BUTTON (widget)->wrap); + gb_widget_output_adjustment (data, Values, + GTK_SPIN_BUTTON (widget)->adjustment, + "adjustment"); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_spin_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gfloat climb_rate; + gint digits, policy_value = GTK_UPDATE_ALWAYS, i; + gchar *policy; + gboolean numeric, snap, wrap; + GtkAdjustment *adj; + + climb_rate = gb_widget_input_float (data, ClimbRate); + /* No set function for this */ + if (data->apply) + GTK_SPIN_BUTTON (widget)->climb_rate = climb_rate; + + digits = gb_widget_input_int (data, Digits); + if (data->apply) + gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), digits); + + numeric = gb_widget_input_bool (data, Numeric); + if (data->apply) + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (widget), numeric); + + snap = gb_widget_input_bool (data, Snap); + if (data->apply) + gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (widget), snap); + + policy = gb_widget_input_choice (data, Policy); + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (!strcmp (policy, GbPolicyChoices[i]) + || !strcmp (policy, GbPolicySymbols[i])) + { + policy_value = GbPolicyValues[i]; + break; + } + } + if (data->apply) + gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (widget), policy_value); + + wrap = gb_widget_input_bool (data, Wrap); + if (data->apply) + gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (widget), wrap); + + adj = GTK_SPIN_BUTTON (widget)->adjustment; + if (gb_widget_input_adjustment (data, Values, adj, "adjustment")) + { + gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkSpinButton, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_spin_button_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_spin_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint update_policy; + GtkAdjustment *adj = GTK_SPIN_BUTTON (widget)->adjustment; + + if (data->create_widget) + { + source_add_decl (data, " GObject *%s_adj;\n", data->real_wname); + source_add (data, + " %s_adj = G_OBJECT(gtk_adjustment_new (%.12g, %.12g, %.12g, %.12g, %.12g, %.12g));\n", + data->real_wname, adj->value, adj->lower, adj->upper, + adj->step_increment, adj->page_increment, adj->page_size); + source_add (data, + " %s = gtk_spin_button_new (GTK_ADJUSTMENT (%s_adj), %.12g, %d);\n", + data->wname, data->real_wname, + GTK_SPIN_BUTTON (widget)->climb_rate, + GTK_SPIN_BUTTON (widget)->digits); + } + gb_widget_write_standard_source (widget, data); + + if (GTK_SPIN_BUTTON (widget)->numeric) + { + source_add (data, + " gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (%s), TRUE);\n", + data->wname); + } + + update_policy = GTK_SPIN_BUTTON (widget)->update_policy; + if (update_policy != GTK_UPDATE_ALWAYS) + { + source_add (data, + " gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (%s), GTK_UPDATE_IF_VALID);\n", + data->wname); + } + + if (GTK_SPIN_BUTTON (widget)->snap_to_ticks) + source_add (data, + " gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (%s), TRUE);\n", + data->wname); + + if (GTK_SPIN_BUTTON (widget)->wrap) + source_add (data, + " gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (%s), TRUE);\n", + data->wname); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_spin_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_spin_button_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = spinbutton_xpm; + gbwidget.tooltip = _("Spin Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_spin_button_new; + gbwidget.gb_widget_create_properties = gb_spin_button_create_properties; + gbwidget.gb_widget_get_properties = gb_spin_button_get_properties; + gbwidget.gb_widget_set_properties = gb_spin_button_set_properties; +/* + gbwidget.gb_widget_create_popup_menu = gb_spin_button_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_spin_button_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbstatusbar.c b/tools/glade/glade/gbwidgets/gbstatusbar.c new file mode 100644 index 00000000..611c4c7e --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbstatusbar.c @@ -0,0 +1,169 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkstatusbar.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/statusbar.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *ResizeGrip = "GtkStatusbar::has_resize_grip"; + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkStatusbar, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +/* + GtkWidget* + gb_statusbar_new(GbWidgetNewData *data) + { + + } + */ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_statusbar_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) +{ + property_add_bool (ResizeGrip, _("Resize Grip:"), _("If the status bar has a resize grip to resize the window")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_statusbar_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) +{ + gb_widget_output_bool (data, ResizeGrip, + GTK_STATUSBAR (widget)->has_resize_grip); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_statusbar_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) +{ + gboolean resize_grip; + + resize_grip = gb_widget_input_bool (data, ResizeGrip); + if (data->apply) + { + gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (widget), resize_grip); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkStatusbar, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_statusbar_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_statusbar_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_statusbar_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + if (!GTK_STATUSBAR (widget)->has_resize_grip) + { + source_add (data, + " gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (%s), FALSE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_statusbar_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_statusbar_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = statusbar_xpm; + gbwidget.tooltip = _("Status Bar"); + + /* Fill in any functions that this GbWidget has */ +/* + gbwidget.gb_widget_new = gb_statusbar_new; + gbwidget.gb_widget_create_popup_menu = gb_statusbar_create_popup_menu; + */ + gbwidget.gb_widget_create_properties = gb_statusbar_create_properties; + gbwidget.gb_widget_get_properties = gb_statusbar_get_properties; + gbwidget.gb_widget_set_properties = gb_statusbar_set_properties; + gbwidget.gb_widget_write_source = gb_statusbar_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbtable.c b/tools/glade/glade/gbwidgets/gbtable.c new file mode 100644 index 00000000..b5c11afe --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtable.c @@ -0,0 +1,1223 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtkhbox.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkspinbutton.h> +#include <gtk/gtktable.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/table.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static const gchar *Rows = "GtkTable::n_rows"; +static const gchar *Columns = "GtkTable::n_columns"; +static const gchar *Homogeneous = "GtkTable::homogeneous"; +static const gchar *RowSpacing = "GtkTable::row_spacing"; +static const gchar *ColSpacing = "GtkTable::column_spacing"; + +/* For children of a table */ +static const gchar *GbCellX = "GtkTableChild::cell_x"; +static const gchar *GbCellY = "GtkTableChild::cell_y"; +static const gchar *GbColSpan = "GtkTableChild::col_span"; +static const gchar *GbRowSpan = "GtkTableChild::row_span"; +static const gchar *GbXPad = "GtkTableChild::x_padding"; +static const gchar *GbYPad = "GtkTableChild::y_padding"; +static const gchar *GbXExpand = "GtkTableChild::xexpand"; +static const gchar *GbYExpand = "GtkTableChild::yexpand"; +static const gchar *GbXShrink = "GtkTableChild::xshrink"; +static const gchar *GbYShrink = "GtkTableChild::yshrink"; +static const gchar *GbXFill = "GtkTableChild::xfill"; +static const gchar *GbYFill = "GtkTableChild::yfill"; + +/* The Expand, Shrink and Fill get merged into one property when saved. */ +static const gchar *GbXOptions = "GtkTableChild::x_options"; +static const gchar *GbYOptions = "GtkTableChild::y_options"; + +/* These are used to return what is in a table cell */ +#define GB_CELL_EMPTY 1 +#define GB_CELL_WIDGET 2 +#define GB_CELL_PLACEHOLDER 3 + +static void show_table_dialog (GbWidgetNewData * data); +static void on_table_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_table_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); + +static void update_table_size (GtkWidget * table, gint rows, gint cols); + +static void gb_table_insert_row_before (GtkWidget * menuitem, + GtkWidget * widget); +static void gb_table_insert_row_after (GtkWidget * menuitem, + GtkWidget * widget); +static void gb_table_insert_column_before (GtkWidget * menuitem, + GtkWidget * widget); +static void gb_table_insert_column_after (GtkWidget * menuitem, + GtkWidget * widget); +static void gb_table_insert_row_or_col (GtkWidget * table, gint row, gint col); +static void gb_table_delete_row (GtkWidget * menuitem, GtkWidget * widget); +static void gb_table_delete_column (GtkWidget * menuitem, GtkWidget * widget); + +static gint gb_table_is_cell_occupied (GtkWidget * table, gint row, gint col); +static void gb_table_remove_placeholders (GtkWidget * table, + gint row, gint col); +static void gb_table_split_placeholder (GtkWidget * table, + GtkWidget * placeholder, + gint left, gint right, + gint top, gint bottom, + gint skip_row, gint skip_col); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkTable, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_table_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + gint rows, cols; + + if (data->action == GB_LOADING) + { + rows = load_int (data->loading_data, Rows); + cols = load_int (data->loading_data, Columns); + new_widget = gtk_table_new (rows, cols, FALSE); + return new_widget; + } + else + { + show_table_dialog (data); + return NULL; + } +} + + +static void +show_table_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *table, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New table"), data->parent, + GTK_SIGNAL_FUNC (on_table_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_table_dialog_destroy), data); + + /* Rows label & entry */ + table = gtk_table_new (2, 2, FALSE); + gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (table), 4); + gtk_widget_show (table); + + label = gtk_label_new (_("Number of rows:")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, + 0, 0); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "rows", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_table_attach (GTK_TABLE (table), spinbutton, 1, 2, 0, 1, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 4, 4); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + /* Columns label & entry */ + label = gtk_label_new (_("Number of columns:")); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, + 0, 0); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "cols", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_table_attach (GTK_TABLE (table), spinbutton, 1, 2, 1, 2, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 4, 4); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_table_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *window; + gint rows, cols, row, col; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "rows"); + g_return_if_fail (spinbutton != NULL); + rows = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "cols"); + g_return_if_fail (spinbutton != NULL); + cols = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_table_new (rows, cols, FALSE); + for (row = 0; row < rows; row++) + { + for (col = 0; col < cols; col++) + { + gtk_table_attach (GTK_TABLE (new_widget), + editor_new_placeholder (), + col, col + 1, row, row + 1, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, + 0, 0); + } + } + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (window); +} + + +static void +on_table_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_table_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_int_range (Rows, _("Rows:"), + _("The number of rows in the table"), + 1, 1000, 1, 10, 1); + property_add_int_range (Columns, _("Columns:"), + _("The number of columns in the table"), + 1, 1000, 1, 10, 1); + property_add_bool (Homogeneous, _("Homogeneous:"), + _("If the children should all be the same size")); + property_add_int_range (RowSpacing, _("Row Spacing:"), + _("The space between each row"), + 0, 1000, 1, 10, 1); + property_add_int_range (ColSpacing, _("Col Spacing:"), + _("The space between each column"), + 0, 1000, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_table_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_widget_output_int (data, Rows, GTK_TABLE (widget)->nrows); + gb_widget_output_int (data, Columns, GTK_TABLE (widget)->ncols); + gb_widget_output_bool (data, Homogeneous, GTK_TABLE (widget)->homogeneous); + gb_widget_output_int (data, RowSpacing, GTK_TABLE (widget)->row_spacing); + gb_widget_output_int (data, ColSpacing, GTK_TABLE (widget)->column_spacing); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_table_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean homogeneous, update_size = FALSE; + gint rows, cols, row_spacing, column_spacing; + + rows = gb_widget_input_int (data, Rows); + if (data->apply) + update_size = TRUE; + else + rows = GTK_TABLE (widget)->nrows; + + cols = gb_widget_input_int (data, Columns); + if (data->apply) + update_size = TRUE; + else + cols = GTK_TABLE (widget)->ncols; + + if (update_size) + update_table_size (widget, rows, cols); + + homogeneous = gb_widget_input_bool (data, Homogeneous); + if (data->apply) + gtk_table_set_homogeneous (GTK_TABLE (widget), homogeneous); + + row_spacing = gb_widget_input_int (data, RowSpacing); + if (data->apply) + gtk_table_set_row_spacings (GTK_TABLE (widget), row_spacing); + + column_spacing = gb_widget_input_int (data, ColSpacing); + if (data->apply) + gtk_table_set_col_spacings (GTK_TABLE (widget), column_spacing); +} + + +/* This changes the size of the table to the given dimensions. Placeholders + are added in empty cells, and widgets are destroyed if they fall outside + the new dimensions. + NOTE: this changes the table data structures, which we would prefer not to + do, but there is no alternative. */ +static void +update_table_size (GtkWidget * table, gint rows, gint cols) +{ + GList *children; + GtkTableChild *child; + + g_return_if_fail (rows > 0); + g_return_if_fail (cols > 0); + + if (GTK_TABLE (table)->nrows == rows && GTK_TABLE (table)->ncols == cols) + return; + + children = GTK_TABLE (table)->children; + while (children) + { + child = children->data; + children = children->next; + + /* Remove the widget if it doesn't fit into the new dimensions, + or crop it if it extends past the edges. */ + if (child->left_attach >= cols || child->top_attach >= rows) + { + gtk_container_remove (GTK_CONTAINER (table), child->widget); + } + else + { + if (child->right_attach > cols) + child->right_attach = cols; + if (child->bottom_attach > rows) + child->bottom_attach = rows; + } + } + + /* This is in ../gbwidget.c. It will expand the dimensions if necessary. */ + gb_table_update_placeholders (table, rows, cols); + + /* This bit is especially naughty. It makes sure the table shrinks, + so we don't get extra spacings on the end. */ + GTK_TABLE (table)->nrows = rows; + GTK_TABLE (table)->ncols = cols; + + /* We clear the selection since it isn't displayed properly. */ + editor_clear_selection (NULL); +} + + +/* + * Creates the child packing properties for children of this widget. + */ +static void +gb_table_create_child_properties (GtkWidget * widget, + GbWidgetCreateChildArgData * data) +{ + property_add_int_range (GbCellX, _("Cell X:"), + _("The left edge of the widget in the table"), + 0, 10000, 1, 10, 1); + property_add_int_range (GbCellY, _("Cell Y:"), + _("The top edge of the widget in the table"), + 0, 10000, 1, 10, 1); + + property_add_int_range (GbColSpan, _("Col Span:"), + _("The number of columns spanned by the widget in the table"), + 1, 10000, 1, 10, 1); + property_add_int_range (GbRowSpan, _("Row Span:"), + _("The number of rows spanned by the widget in the table"), + 1, 10000, 1, 10, 1); + property_add_int_range (GbXPad, _("H Padding:"), + _("The horizontal padding"), + 0, 10000, 1, 10, 1); + property_add_int_range (GbYPad, _("V Padding:"), + _("The vertical padding"), + 0, 10000, 1, 10, 1); + property_add_bool (GbXExpand, _("X Expand:"), + _("Set True to let the widget expand horizontally")); + property_add_bool (GbYExpand, _("Y Expand:"), + _("Set True to let the widget expand vertically")); + property_add_bool (GbXShrink, _("X Shrink:"), + _("Set True to let the widget shrink horizontally")); + property_add_bool (GbYShrink, _("Y Shrink:"), + _("Set True to let the widget shrink vertically")); + property_add_bool (GbXFill, _("X Fill:"), + _("Set True to let the widget fill its horizontal allocated area")); + property_add_bool (GbYFill, _("Y Fill:"), + _("Set True to let the widget fill its vertical allocated area")); +} + + +static void +gb_table_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + GtkTableChild *table_child; + + table_child = glade_util_find_table_child (GTK_TABLE (widget), child); + g_return_if_fail (table_child != NULL); + + if (data->action == GB_SAVING) + save_start_tag (data, "packing"); + + if (data->action == GB_SAVING) + { + /* We use left/right/top/bottom_attach here as they are used in GTK */ + gb_widget_output_int (data, "GtkWidget::left_attach", + table_child->left_attach); + gb_widget_output_int (data, "GtkWidget::right_attach", + table_child->right_attach); + gb_widget_output_int (data, "GtkWidget::top_attach", + table_child->top_attach); + gb_widget_output_int (data, "GtkWidget::bottom_attach", + table_child->bottom_attach); + } + else + { + gb_widget_output_int (data, GbCellX, table_child->left_attach); + gb_widget_output_int (data, GbCellY, table_child->top_attach); + gb_widget_output_int (data, GbColSpan, + table_child->right_attach + - table_child->left_attach); + gb_widget_output_int (data, GbRowSpan, + table_child->bottom_attach + - table_child->top_attach); + } + + /* Default X & Y padding is 0. */ + if (data->action != GB_SAVING || table_child->xpadding) + gb_widget_output_int (data, GbXPad, table_child->xpadding); + if (data->action != GB_SAVING || table_child->ypadding) + gb_widget_output_int (data, GbYPad, table_child->ypadding); + + if (data->action == GB_SAVING) + { + char buffer[32]; + + /* Default packing is GTK_EXPAND | GTK_FILL. */ + if (!table_child->xexpand || !table_child->xfill || table_child->xshrink) + { + buffer[0] = '\0'; + if (table_child->xexpand) + strcat (buffer, "expand"); + if (table_child->xshrink) + { + if (buffer[0]) + strcat (buffer, "|"); + strcat (buffer, "shrink"); + } + if (table_child->xfill) + { + if (buffer[0]) + strcat (buffer, "|"); + strcat (buffer, "fill"); + } + gb_widget_output_string (data, GbXOptions, buffer); + } + + if (!table_child->yexpand || !table_child->yfill || table_child->yshrink) + { + buffer[0] = '\0'; + if (table_child->yexpand) + strcat (buffer, "expand"); + if (table_child->yshrink) + { + if (buffer[0]) + strcat (buffer, "|"); + strcat (buffer, "shrink"); + } + if (table_child->yfill) + { + if (buffer[0]) + strcat (buffer, "|"); + strcat (buffer, "fill"); + } + gb_widget_output_string (data, GbYOptions, buffer); + } + } + else + { + gb_widget_output_bool (data, GbXExpand, table_child->xexpand); + gb_widget_output_bool (data, GbYExpand, table_child->yexpand); + gb_widget_output_bool (data, GbXShrink, table_child->xshrink); + gb_widget_output_bool (data, GbYShrink, table_child->yshrink); + gb_widget_output_bool (data, GbXFill, table_child->xfill); + gb_widget_output_bool (data, GbYFill, table_child->yfill); + } + + if (data->action == GB_SAVING) + save_end_tag (data, "packing"); +} + + +static void +gb_table_set_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + GtkTableChild *tchild; + gint xpad, ypad, left_attach, right_attach, top_attach, bottom_attach; + gint xexpand, yexpand, xshrink, yshrink, xfill, yfill; + + tchild = glade_util_find_table_child (GTK_TABLE (widget), child); + g_return_if_fail (tchild != NULL); + + xpad = gb_widget_input_int (data, GbXPad); + if (!data->apply) + xpad = tchild->xpadding; + + ypad = gb_widget_input_int (data, GbYPad); + if (!data->apply) + ypad = tchild->ypadding; + + if (data->action == GB_APPLYING) + { + xexpand = (gb_widget_input_bool (data, GbXExpand)) ? GTK_EXPAND : 0; + if (!data->apply) + xexpand = tchild->xexpand ? GTK_EXPAND : 0; + + yexpand = (gb_widget_input_bool (data, GbYExpand)) ? GTK_EXPAND : 0; + if (!data->apply) + yexpand = tchild->yexpand ? GTK_EXPAND : 0; + + xshrink = (gb_widget_input_bool (data, GbXShrink)) ? GTK_SHRINK : 0; + if (!data->apply) + xshrink = tchild->xshrink ? GTK_SHRINK : 0; + + yshrink = (gb_widget_input_bool (data, GbYShrink)) ? GTK_SHRINK : 0; + if (!data->apply) + yshrink = tchild->yshrink ? GTK_SHRINK : 0; + + xfill = (gb_widget_input_bool (data, GbXFill)) ? GTK_FILL : 0; + if (!data->apply) + xfill = tchild->xfill ? GTK_FILL : 0; + + yfill = (gb_widget_input_bool (data, GbYFill)) ? GTK_FILL : 0; + if (!data->apply) + yfill = tchild->yfill ? GTK_FILL : 0; + } + else + { + char *xoptions, *yoptions; + + xoptions = gb_widget_input_string (data, GbXOptions); + if (data->apply) + { + xexpand = (strstr (xoptions, "expand")) ? GTK_EXPAND : 0; + xfill = (strstr (xoptions, "fill")) ? GTK_FILL : 0; + xshrink = (strstr (xoptions, "shrink")) ? GTK_SHRINK : 0; + } + else + { + xexpand = GTK_EXPAND; + xfill = GTK_FILL; + xshrink = 0; + } + + yoptions = gb_widget_input_string (data, GbYOptions); + if (data->apply) + { + yexpand = (strstr (yoptions, "expand")) ? GTK_EXPAND : 0; + yfill = (strstr (yoptions, "fill")) ? GTK_FILL : 0; + yshrink = (strstr (yoptions, "shrink")) ? GTK_SHRINK : 0; + } + else + { + yexpand = GTK_EXPAND; + yfill = GTK_FILL; + yshrink = 0; + } + } + + if (data->action == GB_APPLYING) + { + left_attach = gb_widget_input_int (data, GbCellX); + if (!data->apply) + left_attach = tchild->left_attach; + + top_attach = gb_widget_input_int (data, GbCellY); + if (!data->apply) + top_attach = tchild->top_attach; + + right_attach = gb_widget_input_int (data, GbColSpan) + left_attach; + if (!data->apply) + right_attach = left_attach + (tchild->right_attach + - tchild->left_attach); + + bottom_attach = gb_widget_input_int (data, GbRowSpan) + top_attach; + if (!data->apply) + bottom_attach = top_attach + (tchild->bottom_attach + - tchild->top_attach); + } + else + { + left_attach = gb_widget_input_int (data, "GtkWidget::left_attach"); + if (!data->apply) + left_attach = tchild->left_attach; + + top_attach = gb_widget_input_int (data, "GtkWidget::top_attach"); + if (!data->apply) + top_attach = tchild->top_attach; + + right_attach = gb_widget_input_int (data, "GtkWidget::right_attach"); + if (!data->apply) + right_attach = tchild->right_attach; + + bottom_attach = gb_widget_input_int (data, "GtkWidget::bottom_attach"); + if (!data->apply) + bottom_attach = tchild->bottom_attach; + } + + if (right_attach <= left_attach) + right_attach = left_attach + 1; + if (bottom_attach <= top_attach) + bottom_attach = top_attach + 1; + + if (xpad != tchild->xpadding || ypad != tchild->ypadding + || (xexpand && !tchild->xexpand) || (!xexpand && tchild->xexpand) + || (yexpand && !tchild->yexpand) || (!yexpand && tchild->yexpand) + || (xshrink && !tchild->xshrink) || (!xshrink && tchild->xshrink) + || (yshrink && !tchild->yshrink) || (!yshrink && tchild->yshrink) + || (xfill && !tchild->xfill) || (!xfill && tchild->xfill) + || (yfill && !tchild->yfill) || (!yfill && tchild->yfill) + || left_attach != tchild->left_attach + || right_attach != tchild->right_attach + || top_attach != tchild->top_attach + || bottom_attach != tchild->bottom_attach) + { + gtk_widget_ref (child); + gtk_container_remove (GTK_CONTAINER (widget), child); + gtk_table_attach (GTK_TABLE (widget), child, + left_attach, right_attach, top_attach, bottom_attach, + xexpand | xshrink | xfill, yexpand | yshrink | yfill, + xpad, ypad); + gtk_widget_unref (child); + if (data->action == GB_APPLYING) + gb_table_update_placeholders (widget, -1, -1); + } +} + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkTable, with signals pointing to + * other functions in this file. + */ +static void +gb_table_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + GtkWidget *menuitem; + + /* It is possible that the mouse button was clicked outside a child + (e.g. beneath all the children), in which case we return. We could + still support adding rows/cols. */ + if (data->child == NULL) + return; + + menuitem = gtk_menu_item_new_with_label (_("Insert Row Before")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_table_insert_row_before), + data->child); + + menuitem = gtk_menu_item_new_with_label (_("Insert Row After")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_table_insert_row_after), + data->child); + + menuitem = gtk_menu_item_new_with_label (_("Insert Column Before")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_table_insert_column_before), + data->child); + + menuitem = gtk_menu_item_new_with_label (_("Insert Column After")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_table_insert_column_after), + data->child); + + menuitem = gtk_menu_item_new_with_label (_("Delete Row")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_table_delete_row), data->child); + + menuitem = gtk_menu_item_new_with_label (_("Delete Column")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_table_delete_column), data->child); +} + + +static void +gb_table_insert_row_before (GtkWidget * menuitem, GtkWidget * widget) +{ + GtkWidget *table; + GtkTableChild *tchild; + + table = widget->parent; + g_return_if_fail (GTK_IS_TABLE (table)); + tchild = glade_util_find_table_child (GTK_TABLE (table), widget); + g_return_if_fail (tchild != NULL); + gb_table_insert_row_or_col (table, tchild->top_attach, -1); +} + + +static void +gb_table_insert_row_after (GtkWidget * menuitem, GtkWidget * widget) +{ + GtkWidget *table; + GtkTableChild *tchild; + + table = widget->parent; + g_return_if_fail (GTK_IS_TABLE (table)); + tchild = glade_util_find_table_child (GTK_TABLE (table), widget); + g_return_if_fail (tchild != NULL); + gb_table_insert_row_or_col (table, tchild->bottom_attach, -1); +} + + +static void +gb_table_insert_column_before (GtkWidget * menuitem, GtkWidget * widget) +{ + GtkWidget *table; + GtkTableChild *tchild; + + table = widget->parent; + g_return_if_fail (GTK_IS_TABLE (table)); + tchild = glade_util_find_table_child (GTK_TABLE (table), widget); + g_return_if_fail (tchild != NULL); + gb_table_insert_row_or_col (table, -1, tchild->left_attach); +} + + +static void +gb_table_insert_column_after (GtkWidget * menuitem, GtkWidget * widget) +{ + GtkWidget *table; + GtkTableChild *tchild; + + table = widget->parent; + g_return_if_fail (GTK_IS_TABLE (table)); + tchild = glade_util_find_table_child (GTK_TABLE (table), widget); + g_return_if_fail (tchild != NULL); + gb_table_insert_row_or_col (table, -1, tchild->right_attach); +} + + +/* This inserts a row or column into the table at the given position. + Use -1 for the other unused argument. */ +static void +gb_table_insert_row_or_col (GtkWidget * table, gint row, gint col) +{ + GtkTableChild *tchild; + GList *child; + GtkWidget *widget, *tmp_label; + gint rows, cols; + + /* This relies on knowing the internals of GtkTable, so it is fast. + First it adds a simple label at the bottom right of the new table size, + to ensure that the table grows. Then it removes the label, and moves + all the widgets down/right as appropriate, and adds any necessary + placeholders. */ + tmp_label = gtk_label_new (""); + rows = GTK_TABLE (table)->nrows + (row != -1 ? 1 : 0); + cols = GTK_TABLE (table)->ncols + (col != -1 ? 1 : 0); + gtk_table_attach_defaults (GTK_TABLE (table), tmp_label, + cols - 1, cols, rows - 1, rows); + + child = GTK_TABLE (table)->children; + while (child) + { + tchild = child->data; + child = child->next; + widget = tchild->widget; + + if ((row != -1 && tchild->top_attach >= row) + || (col != -1 && tchild->left_attach >= col)) + { + /* If we're inserting a row, we move the widget down. + If we're inserting a col, we move the widget right. */ + if (row != -1) + { + tchild->top_attach++; + tchild->bottom_attach++; + } + else + { + tchild->left_attach++; + tchild->right_attach++; + } + } + } + + /* Now remove the temporary label. */ + gtk_container_remove (GTK_CONTAINER (table), tmp_label); + + /* This fills any empty cells with placeholders. */ + gb_table_update_placeholders (table, -1, -1); + + /* If the tables properties are currently shown, update rows/cols. */ + if (property_get_widget () == table) + { + property_set_auto_apply (FALSE); + if (row != -1) + property_set_int (Rows, GTK_TABLE (table)->nrows); + else + property_set_int (Columns, GTK_TABLE (table)->ncols); + property_set_auto_apply (TRUE); + } +} + + +static void +gb_table_delete_row (GtkWidget * menuitem, GtkWidget * widget) +{ + GtkWidget *table; + GtkTableChild *tchild; + GList *children; + guint16 nrows, ncols, row; + + table = widget->parent; + nrows = GTK_TABLE (table)->nrows - 1; + if (nrows == 0) + return; + ncols = GTK_TABLE (table)->ncols; + tchild = glade_util_find_table_child (GTK_TABLE (table), widget); + g_return_if_fail (tchild != NULL); + row = tchild->top_attach; + + children = GTK_TABLE (table)->children; + while (children) + { + tchild = children->data; + children = children->next; + if (tchild->top_attach == row && tchild->bottom_attach == row + 1) + { + gtk_container_remove (GTK_CONTAINER (table), tchild->widget); + } + else if (tchild->top_attach <= row && tchild->bottom_attach > row) + { + tchild->bottom_attach -= 1; + } + else if (tchild->top_attach > row) + { + tchild->top_attach -= 1; + tchild->bottom_attach -= 1; + } + } + update_table_size (table, nrows, ncols); + + if (property_get_widget () == table) + { + property_set_auto_apply (FALSE); + property_set_int (Rows, nrows); + property_set_auto_apply (TRUE); + } +} + + +static void +gb_table_delete_column (GtkWidget * menuitem, GtkWidget * widget) +{ + GtkWidget *table; + GtkTableChild *tchild; + GList *children; + guint16 nrows, ncols, col; + + table = widget->parent; + nrows = GTK_TABLE (table)->nrows; + ncols = GTK_TABLE (table)->ncols - 1; + if (ncols == 0) + return; + tchild = glade_util_find_table_child (GTK_TABLE (table), widget); + g_return_if_fail (tchild != NULL); + col = tchild->left_attach; + + children = GTK_TABLE (table)->children; + while (children) + { + tchild = children->data; + children = children->next; + if (tchild->left_attach == col && tchild->right_attach == col + 1) + { + gtk_container_remove (GTK_CONTAINER (table), tchild->widget); + } + else if (tchild->left_attach <= col && tchild->right_attach > col) + { + tchild->right_attach -= 1; + } + else if (tchild->left_attach > col) + { + tchild->left_attach -= 1; + tchild->right_attach -= 1; + } + } + update_table_size (table, nrows, ncols); + + if (property_get_widget () == table) + { + property_set_auto_apply (FALSE); + property_set_int (Columns, ncols); + property_set_auto_apply (TRUE); + } +} + + +/* This ensures that placeholders are placed in every unoccupied cell. + If rows and cols are not -1, then they are the new dimensions of the table. + FIXME: This is very inefficient. + */ +void +gb_table_update_placeholders (GtkWidget * table, gint rows, gint cols) +{ + gint row, col, cell_contents; + guchar *rows_occupied, *cols_occupied; + GList *children; + GtkTableChild *child; + + if (rows == -1) + rows = GTK_TABLE (table)->nrows; + if (cols == -1) + cols = GTK_TABLE (table)->ncols; + + /* These hold flags to indicate which rows/cols have widgets in them. */ + rows_occupied = g_new0 (guchar, rows); + cols_occupied = g_new0 (guchar, cols); + + for (row = 0; row < rows; row++) + { + for (col = 0; col < cols; col++) + { + /* Find out what is in the cell */ + cell_contents = gb_table_is_cell_occupied (table, row, col); + if (cell_contents == GB_CELL_WIDGET) + { + /* If cell is occupied, delete any placeholders there. If a + placeholder occupies the cell but spans multiple rows/cols + split it into single cells but without a placeholder in this + cell */ + gb_table_remove_placeholders (table, row, col); + rows_occupied[row] = 1; + cols_occupied[col] = 1; + } + else if (cell_contents == GB_CELL_EMPTY) + { + /* If the cell is empty, put a placeholder in it */ + gtk_table_attach (GTK_TABLE (table), + editor_new_placeholder (), + col, col + 1, row, row + 1, + GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, + 0, 0); + } + } + } + + /* Now make sure that if a row/col is occupied, any placeholders in that + row/col do not expand, and vice versa. */ + children = GTK_TABLE (table)->children; + while (children) + { + child = children->data; + if (GB_IS_PLACEHOLDER (child->widget)) + { + gboolean xexpand = TRUE, yexpand = TRUE; + gint row, col; + + /* Check if any widgets are in the same rows as the placeholder. */ + for (row = child->top_attach; row < child->bottom_attach; row++) + { + if (rows_occupied[row]) + yexpand = FALSE; + } + child->yexpand = yexpand; + + /* Check if any widgets are in the same cols as the placeholder. */ + for (col = child->left_attach; col < child->right_attach; col++) + { + if (cols_occupied[col]) + xexpand = FALSE; + } + child->xexpand = xexpand; + + child->xfill = TRUE; + child->yfill = TRUE; + } + children = children->next; + } + + g_free (rows_occupied); + g_free (cols_occupied); + + gtk_widget_queue_resize (table); +} + + +/* Finds out if cell is occupied by a real widget. If not, returns whether + the cell is empty or whether a placeholder is in it */ +static gint +gb_table_is_cell_occupied (GtkWidget * table, gint row, gint col) +{ + GList *children; + GtkTableChild *child; + gint return_val = GB_CELL_EMPTY; + + children = GTK_TABLE (table)->children; + while (children) + { + child = children->data; + if (child->top_attach <= row && child->bottom_attach > row + && child->left_attach <= col && child->right_attach > col) + { + if (GB_IS_PLACEHOLDER (child->widget)) + return_val = GB_CELL_PLACEHOLDER; + else + return GB_CELL_WIDGET; + } + children = children->next; + } + return return_val; +} + + +static void +gb_table_remove_placeholders (GtkWidget * table, gint row, gint col) +{ + GList *children, *next; + GtkTableChild *child; + gint left, right, top, bottom; + + children = GTK_TABLE (table)->children; + while (children) + { + next = children->next; + child = children->data; + left = child->left_attach; + right = child->right_attach; + top = child->top_attach; + bottom = child->bottom_attach; + + if (top <= row && bottom > row && left <= col && right > col) + { + /* If the widget is a placeholder remove it */ + if (GB_IS_PLACEHOLDER (child->widget)) + { + if (bottom - top > 1 || right - left > 1) + { + gb_table_split_placeholder (table, child->widget, + left, right, top, bottom, + row, col); + } + else + { + gtk_container_remove (GTK_CONTAINER (table), child->widget); + } + } + } + children = next; + } +} + + +static void +gb_table_split_placeholder (GtkWidget * table, GtkWidget * placeholder, + gint left, gint right, gint top, gint bottom, + gint skip_row, gint skip_col) +{ + gint row, col; + + gtk_container_remove (GTK_CONTAINER (table), placeholder); + for (row = top; row < bottom; row++) + { + for (col = left; col < right; col++) + { + if (!(row == skip_row && col == skip_col)) + { + gtk_table_attach (GTK_TABLE (table), + editor_new_placeholder (), + col, col + 1, row, row + 1, + GTK_FILL, GTK_FILL, 0, 0); + } + } + } +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_table_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_table_new (%i, %i, %s);\n", data->wname, + GTK_TABLE (widget)->nrows, GTK_TABLE (widget)->ncols, + GTK_TABLE (widget)->homogeneous ? "TRUE" : "FALSE"); + } + + gb_widget_write_standard_source (widget, data); + + if (GTK_TABLE (widget)->row_spacing != 0) + { + source_add (data, " gtk_table_set_row_spacings (GTK_TABLE (%s), %i);\n", + data->wname, GTK_TABLE (widget)->row_spacing); + } + if (GTK_TABLE (widget)->column_spacing != 0) + { + source_add (data, " gtk_table_set_col_spacings (GTK_TABLE (%s), %i);\n", + data->wname, GTK_TABLE (widget)->column_spacing); + } +} + + +/* Outputs source to add a child widget to a table. */ +static void +gb_table_write_add_child_source (GtkWidget * parent, + const gchar *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData * data) +{ + gchar xoptions[48], yoptions[48]; + GtkTableChild *tchild = glade_util_find_table_child (GTK_TABLE (parent), + child); + g_return_if_fail (tchild != NULL); + + xoptions[0] = yoptions[0] = '\0'; + if (tchild->xexpand) + strcpy (xoptions, "GTK_EXPAND"); + if (tchild->xshrink) + { + if (xoptions[0] != '\0') + strcat (xoptions, " | "); + strcat (xoptions, "GTK_SHRINK"); + } + if (tchild->xfill) + { + if (xoptions[0] != '\0') + strcat (xoptions, " | "); + strcat (xoptions, "GTK_FILL"); + } + if (xoptions[0] == '\0') + strcpy (xoptions, "0"); + + if (tchild->yexpand) + strcpy (yoptions, "GTK_EXPAND"); + if (tchild->yshrink) + { + if (yoptions[0] != '\0') + strcat (yoptions, " | "); + strcat (yoptions, "GTK_SHRINK"); + } + if (tchild->yfill) + { + if (yoptions[0] != '\0') + strcat (yoptions, " | "); + strcat (yoptions, "GTK_FILL"); + } + if (yoptions[0] == '\0') + strcpy (yoptions, "0"); + + source_add (data, + " gtk_table_attach (GTK_TABLE (%s), %s, %i, %i, %i, %i,\n" + " (GtkAttachOptions) (%s),\n" + " (GtkAttachOptions) (%s), %i, %i);\n", + parent_name, data->wname, + tchild->left_attach, tchild->right_attach, + tchild->top_attach, tchild->bottom_attach, + xoptions, yoptions, tchild->xpadding, tchild->ypadding); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_table_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_table_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = table_xpm; + gbwidget.tooltip = _("Table"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_table_new; + gbwidget.gb_widget_create_properties = gb_table_create_properties; + gbwidget.gb_widget_get_properties = gb_table_get_properties; + gbwidget.gb_widget_set_properties = gb_table_set_properties; + gbwidget.gb_widget_create_child_properties = gb_table_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_table_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_table_set_child_properties; + gbwidget.gb_widget_write_source = gb_table_write_source; + gbwidget.gb_widget_write_add_child_source = gb_table_write_add_child_source; + gbwidget.gb_widget_create_popup_menu = gb_table_create_popup_menu; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbtextview.c b/tools/glade/glade/gbwidgets/gbtextview.c new file mode 100644 index 00000000..31cbe830 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtextview.c @@ -0,0 +1,479 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/text.xpm" + +static gchar *Editable = "GtkTextView::editable"; +static gchar *Text = "GtkTextView::text"; +static gchar *Justification = "GtkTextView::justification"; +static gchar *WrapMode = "GtkTextView::wrap_mode"; +static gchar *CursorVisible = "GtkTextView::cursor_visible"; +static gchar *PixelsAboveLines = "GtkTextView::pixels_above_lines"; +static gchar *PixelsBelowLines = "GtkTextView::pixels_below_lines"; +static gchar *PixelsInsideWrap = "GtkTextView::pixels_inside_wrap"; +static gchar *LeftMargin = "GtkTextView::left_margin"; +static gchar *RightMargin = "GtkTextView::right_margin"; +static gchar *Indent = "GtkTextView::indent"; + +static gchar *Overwrite = "GtkTextView::overwrite"; +static gchar *AcceptsTab = "GtkTextView::accepts_tab"; + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static const char *GbJustifyChoices[] = { + N_("Left"), + N_("Right"), + N_("Center"), + N_("Fill"), + NULL +}; + +static gint GbJustifyValues[] = { + GTK_JUSTIFY_LEFT, + GTK_JUSTIFY_RIGHT, + GTK_JUSTIFY_CENTER, + GTK_JUSTIFY_FILL +}; +static const gchar *GbJustifySymbols[] = +{ + "GTK_JUSTIFY_LEFT", + "GTK_JUSTIFY_RIGHT", + "GTK_JUSTIFY_CENTER", + "GTK_JUSTIFY_FILL" +}; + +static const char *GbWrapChoices[] = { + N_("None"), + N_("Character"), + N_("Word"), + NULL +}; + +static gint GbWrapValues[] = { + GTK_WRAP_NONE, + GTK_WRAP_CHAR, + GTK_WRAP_WORD +}; +static const char *GbWrapSymbols[] = { + "GTK_WRAP_NONE", + "GTK_WRAP_CHAR", + "GTK_WRAP_WORD" +}; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkTextView, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +/* +static GtkWidget* +gb_text_view_new (GbWidgetNewData *data) +{ + return gtk_text_view_new (); +} +*/ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_text_view_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (Editable, _("Editable:"), + _("If the text can be edited")); + property_add_bool (CursorVisible, _("Cursor Visible:"), + _("If the cursor is visible")); + property_add_bool (Overwrite, _("Overwrite:"), + _("If entered text overwrites the existing text")); + property_add_bool (AcceptsTab, _("Accepts Tab:"), + _("If tab characters can be entered")); + + property_add_text (Text, _("Text:"), _("The text to display"), 5); + + property_add_choice (Justification, _("Justification:"), + _("The justification of the text"), + GbJustifyChoices); + property_add_choice (WrapMode, _("Wrapping:"), + _("The wrapping of the text"), + GbWrapChoices); + + property_add_int_range (PixelsAboveLines, _("Space Above:"), + _("Pixels of blank space above paragraphs"), + 0, G_MAXINT, 1, 2, 10); + property_add_int_range (PixelsBelowLines, _("Space Below:"), + _("Pixels of blank space below paragraphs"), + 0, G_MAXINT, 1, 2, 10); + property_add_int_range (PixelsInsideWrap, _("Space Inside:"), + _("Pixels of blank space between wrapped lines in a paragraph"), + 0, G_MAXINT, 1, 2, 10); + + property_add_int_range (LeftMargin, _("Left Margin:"), + _("Width of the left margin in pixels"), + 0, G_MAXINT, 1, 2, 10); + property_add_int_range (RightMargin, _("Right Margin:"), + _("Width of the right margin in pixels"), + 0, G_MAXINT, 1, 2, 10); + property_add_int_range (Indent, _("Indent:"), + _("Amount of pixels to indent paragraphs"), + 0, G_MAXINT, 1, 2, 10); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_text_view_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + GtkTextBuffer *buffy; + GtkTextIter start, end; + gboolean editable, cursor_visible, overwrite, accepts_tab; + gint wrap_mode, justification; + gint pixels_above, pixels_below, pixels_inside; + gint left_margin, right_margin, indent; + char *text; + + g_object_get (widget, + "editable", &editable, + "overwrite", &overwrite, + "accepts_tab", &accepts_tab, + "justification", &justification, + "wrap-mode", &wrap_mode, + "cursor-visible", &cursor_visible, + "pixels-above-lines", &pixels_above, + "pixels-below-lines", &pixels_below, + "pixels-inside-wrap", &pixels_inside, + "left-margin", &left_margin, + "right-margin", &right_margin, + "indent", &indent, + NULL); + + + gb_widget_output_bool (data, Editable, editable); + gb_widget_output_bool (data, Overwrite, overwrite); + gb_widget_output_bool (data, AcceptsTab, accepts_tab); + gb_widget_output_enum (data, GTK_TYPE_JUSTIFICATION, + GbJustifyValues, + G_N_ELEMENTS (GbJustifyValues), + Justification, justification); + gb_widget_output_enum (data, GTK_TYPE_WRAP_MODE, + GbWrapValues, + G_N_ELEMENTS (GbWrapValues), + WrapMode, wrap_mode); + gb_widget_output_bool (data, CursorVisible, cursor_visible); + gb_widget_output_int (data, PixelsAboveLines, pixels_above); + gb_widget_output_int (data, PixelsBelowLines, pixels_below); + gb_widget_output_int (data, PixelsInsideWrap, pixels_inside); + gb_widget_output_int (data, LeftMargin, left_margin); + gb_widget_output_int (data, RightMargin, right_margin); + gb_widget_output_int (data, Indent, indent); + + buffy = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)); + gtk_text_buffer_get_bounds (buffy, &start, &end); + text = gtk_text_iter_get_text (&start, &end); + gb_widget_output_translatable_text (data, Text, text); + g_free (text); +} + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_text_view_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + int i; + char *s; + + i = gb_widget_input_bool (data, Editable); + if (data->apply) + g_object_set (widget, "editable", i, NULL); + + i = gb_widget_input_bool (data, Overwrite); + if (data->apply) + g_object_set (widget, "overwrite", i, NULL); + + i = gb_widget_input_bool (data, AcceptsTab); + if (data->apply) + g_object_set (widget, "accepts_tab", i, NULL); + + s = gb_widget_input_text (data, Text); + if (data->apply) { + GtkTextBuffer *buffy; + buffy = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)); + gtk_text_buffer_set_text (buffy, s, strlen (s)); + } + if (data->action == GB_APPLYING) + g_free (s); + + + i = gb_widget_input_enum (data, GTK_TYPE_JUSTIFICATION, + GbJustifyChoices, GbJustifyValues, + Justification); + if (data->apply) + g_object_set (widget, "justification", i, NULL); + + i = gb_widget_input_enum (data, GTK_TYPE_WRAP_MODE, + GbWrapChoices, GbWrapValues, + WrapMode); + if (data->apply) + g_object_set (widget, "wrap-mode", i, NULL); + + i = gb_widget_input_bool (data, CursorVisible); + if (data->apply) + g_object_set (widget, "cursor-visible", i, NULL); + + i = gb_widget_input_int (data, PixelsAboveLines); + if (data->apply) + g_object_set (widget, "pixels-above-lines", i, NULL); + + i = gb_widget_input_int (data, PixelsBelowLines); + if (data->apply) + g_object_set (widget, "pixels-below-lines", i, NULL); + + i = gb_widget_input_int (data, PixelsInsideWrap); + if (data->apply) + g_object_set (widget, "pixels-inside-wrap", i, NULL); + + i = gb_widget_input_int (data, LeftMargin); + if (data->apply) + g_object_set (widget, "left-margin", i, NULL); + + i = gb_widget_input_int (data, RightMargin); + if (data->apply) + g_object_set (widget, "right-margin", i, NULL); + + i = gb_widget_input_int (data, Indent); + if (data->apply) + g_object_set (widget, "indent", i, NULL); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkTextView, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_text_view_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_text_view_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkTextBuffer *buffy; + GtkTextIter start, end; + gboolean editable, cursor_visible, overwrite, accepts_tab; + gint wrap_mode, justification; + gint pixels_above, pixels_below, pixels_inside; + gint left_margin, right_margin, indent, i; + char *text; + gboolean translatable, context; + gchar *comments; + + if (data->create_widget) + { + source_add (data, " %s = gtk_text_view_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + g_object_get (widget, + "editable", &editable, + "overwrite", &overwrite, + "accepts_tab", &accepts_tab, + "justification", &justification, + "wrap-mode", &wrap_mode, + "cursor-visible", &cursor_visible, + "pixels-above-lines", &pixels_above, + "pixels-below-lines", &pixels_below, + "pixels-inside-wrap", &pixels_inside, + "left-margin", &left_margin, + "right-margin", &right_margin, + "indent", &indent, + NULL); + + if (!editable) + source_add (data, + " gtk_text_view_set_editable (GTK_TEXT_VIEW (%s), FALSE);\n", + data->wname); + + if (overwrite) + source_add (data, + " gtk_text_view_set_overwrite (GTK_TEXT_VIEW (%s), TRUE);\n", + data->wname); + + if (!accepts_tab) + source_add (data, + " gtk_text_view_set_accepts_tab (GTK_TEXT_VIEW (%s), FALSE);\n", + data->wname); + + if (justification != GTK_JUSTIFY_LEFT) + { + for (i = 0; i < sizeof (GbJustifyValues) / sizeof (GbJustifyValues[0]); + i++) + { + if (GbJustifyValues[i] == justification) + source_add (data, + " gtk_text_view_set_justification (GTK_TEXT_VIEW (%s), %s);\n", + data->wname, GbJustifySymbols[i]); + } + } + + if (wrap_mode != GTK_WRAP_NONE) + { + for (i = 0; i < sizeof (GbWrapValues) / sizeof (GbWrapValues[0]); i++) + { + if (GbWrapValues[i] == wrap_mode) + source_add (data, + " gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (%s), %s);\n", + data->wname, GbWrapSymbols[i]); + } + } + + if (!cursor_visible) + source_add (data, + " gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (%s), FALSE);\n", + data->wname); + + if (pixels_above != 0) + source_add (data, + " gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (%s), %i);\n", + data->wname, pixels_above); + + if (pixels_below != 0) + source_add (data, + " gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (%s), %i);\n", + data->wname, pixels_below); + + if (pixels_inside != 0) + source_add (data, + " gtk_text_view_set_pixels_inside_wrap (GTK_TEXT_VIEW (%s), %i);\n", + data->wname, pixels_inside); + + if (left_margin != 0) + source_add (data, + " gtk_text_view_set_left_margin (GTK_TEXT_VIEW (%s), %i);\n", + data->wname, left_margin); + + if (right_margin != 0) + source_add (data, + " gtk_text_view_set_right_margin (GTK_TEXT_VIEW (%s), %i);\n", + data->wname, right_margin); + + if (indent != 0) + source_add (data, + " gtk_text_view_set_indent (GTK_TEXT_VIEW (%s), %i);\n", + data->wname, indent); + + + buffy = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget)); + gtk_text_buffer_get_bounds (buffy, &start, &end); + text = gtk_text_iter_get_text (&start, &end); + if (text && *text) + { + glade_util_get_translation_properties (widget, Text, &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (%s)), %s, -1);\n", + data->wname, + source_make_string_full (text, + data->use_gettext && translatable, + context)); + } + g_free (text); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_text_view_init () +{ + GtkWidgetClass *klass; + + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_text_view_get_type(); + + /* Add a signal emission hook so we can connect signal handlers to the + scrollbar adjustments to redraw the clist when necessary. This will also + work for subclasses of GtkCList. */ + klass = gtk_type_class (gtk_text_view_get_type ()); + g_signal_add_emission_hook (klass->set_scroll_adjustments_signal, 0, + gb_set_scroll_adjustments_hook, NULL, NULL); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = text_xpm; + gbwidget.tooltip = _("Text View"); + + /* Fill in any functions that this GbWidget has */ +/* + gbwidget.gb_widget_new = gb_text_view_new; +*/ + gbwidget.gb_widget_create_properties = gb_text_view_create_properties; + gbwidget.gb_widget_get_properties = gb_text_view_get_properties; + gbwidget.gb_widget_set_properties = gb_text_view_set_properties; + gbwidget.gb_widget_write_source = gb_text_view_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_text_view_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbtogglebutton.c b/tools/glade/glade/gbwidgets/gbtogglebutton.c new file mode 100644 index 00000000..8007b985 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtogglebutton.c @@ -0,0 +1,211 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> + +#include <gtk/gtklabel.h> +#include <gtk/gtktogglebutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/togglebutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *StockButton = "ToggleButton|GtkButton::stock_button"; +static gchar *Label = "ToggleButton|GtkButton::label"; +static gchar *Icon = "ToggleButton|GtkButton::icon"; +static gchar *FocusOnClick = "ToggleButton|GtkButton::focus_on_click"; + +/* This is only used for normal/stock buttons, not special toolbar buttons, + as the toolbar has its own relief setting. */ +static gchar *Relief = "ToggleButton|GtkButton::relief"; + +static gchar *State = "GtkToggleButton::active"; +static gchar *Inconsistent = "GtkToggleButton::inconsistent"; + + +/* draw_indicator is not really useful for toggle buttons. I think its only + for radio/check buttons. */ +/*static gchar *Indicator = "GtkToggleButton::draw_indicator"; */ + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkToggleButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_toggle_button_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_CREATING) + new_widget = gtk_toggle_button_new_with_label (data->name); + else + { + new_widget = gtk_toggle_button_new (); + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder()); + } + return new_widget; +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_toggle_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData + * data) +{ + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_BUTTON); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_BUTTON); + property_add_choice (Relief, _("Button Relief:"), + _("The relief style of the button"), + GladeReliefChoices); + + property_add_bool (State, _("Initially On:"), + _("If the toggle button is initially on")); + property_add_bool (Inconsistent, _("Inconsistent:"), + _("If the button is shown in an inconsistent state")); + property_add_bool (FocusOnClick, _("Focus On Click:"), _("If the button grabs focus when it is clicked")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_toggle_button_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_button_get_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + gb_widget_output_bool (data, State, data->widget_data->flags & GLADE_ACTIVE); + + gb_widget_output_bool (data, Inconsistent, + GTK_TOGGLE_BUTTON (widget)->inconsistent); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_toggle_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean state, inconsistent; + + gb_button_set_standard_properties (widget, data, StockButton, Label, Icon, + Relief, FocusOnClick); + + state = gb_widget_input_bool (data, State); + if (data->apply) + { + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), state); + if (state) + data->widget_data->flags |= GLADE_ACTIVE; + else + data->widget_data->flags &= ~GLADE_ACTIVE; + } + + inconsistent = gb_widget_input_bool (data, Inconsistent); + if (data->apply) + gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (widget), + inconsistent); +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_toggle_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gb_button_write_standard_source (widget, data, Label); + + if (data->widget_data->flags & GLADE_ACTIVE) + { + source_add (data, + " gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (GTK_TOGGLE_BUTTON (widget)->inconsistent) + { + source_add (data, + " gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (%s), TRUE);\n", + data->wname); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_toggle_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_toggle_button_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = togglebutton_xpm; + gbwidget.tooltip = _("Toggle Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_toggle_button_new; + gbwidget.gb_widget_create_properties = gb_toggle_button_create_properties; + gbwidget.gb_widget_get_properties = gb_toggle_button_get_properties; + gbwidget.gb_widget_set_properties = gb_toggle_button_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_button_create_popup_menu; + gbwidget.gb_widget_write_source = gb_toggle_button_write_source; + gbwidget.gb_widget_destroy = gb_button_destroy; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbtoggletoolbutton.c b/tools/glade/glade/gbwidgets/gbtoggletoolbutton.c new file mode 100644 index 00000000..65036fdf --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtoggletoolbutton.c @@ -0,0 +1,312 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/toggletoolbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *StockButton = "GtkToggleToolButton|GtkToolButton::stock_id"; +static gchar *Label = "GtkToggleToolButton|GtkToolButton::label"; +static gchar *Icon = "GtkToggleToolButton|GtkToolButton::icon"; +static gchar *VisibleHorz = "GtkToggleToolButton|GtkToolItem::visible_horizontal"; +static gchar *VisibleVert = "GtkToggleToolButton|GtkToolItem::visible_vertical"; +static gchar *IsImportant = "GtkToggleToolButton|GtkToolItem::is_important"; + +static gchar *Active = "GtkToggleToolButton::active"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkToggleToolButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_toggle_tool_button_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget, *image; + GbWidget *pixmap_gbwidget; + + /* Place the pixmap icon in the button initially (even when loading). */ + pixmap_gbwidget = gb_widget_lookup_class ("GtkImage"); + if (pixmap_gbwidget) + { + image = gtk_image_new_from_pixmap (pixmap_gbwidget->gdkpixmap, + pixmap_gbwidget->mask); + } + else + { + image = gtk_image_new (); + g_warning ("Couldn't find GtkPixmap data"); + } + gtk_widget_show (image); + + new_widget = (GtkWidget*) gtk_toggle_tool_button_new (); + + gtk_tool_button_set_label (GTK_TOOL_BUTTON (new_widget), ""); + gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (new_widget), image); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_toggle_tool_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + property_add_bool (Active, _("Initially On:"), + _("If the toggle button is initially on")); + property_add_bool (VisibleHorz, _("Show Horizontal:"), + _("If the item is visible when the toolbar is horizontal")); + property_add_bool (VisibleVert, _("Show Vertical:"), + _("If the item is visible when the toolbar is vertical")); + property_add_bool (IsImportant, _("Is Important:"), + _("If the item's text should be shown when the toolbar's mode is GTK_TOOLBAR_BOTH_HORIZ")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_toggle_tool_button_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_tool_button_get_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); + + gb_widget_output_bool (data, Active, + data->widget_data->flags & GLADE_ACTIVE); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_toggle_tool_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean active; + + gb_tool_button_set_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); + + active = gb_widget_input_bool (data, Active); + if (data->apply) + { + gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (widget), + active); + if (active) + data->widget_data->flags |= GLADE_ACTIVE; + else + data->widget_data->flags &= ~GLADE_ACTIVE; + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkToggleToolButton, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_toggle_tool_button_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_toggle_tool_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *stock_id, *label, *icon_name; + gboolean translatable, context; + gchar *comments; + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonStockIDKey); + icon_name = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonIconKey); + label = (gchar*) gtk_tool_button_get_label (GTK_TOOL_BUTTON (widget)); + + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + + if (data->create_widget) + { + if (stock_id) + { + /* Stock Button */ + source_add (data, + " %s = (GtkWidget*) gtk_toggle_tool_button_new_from_stock (%s);\n", + data->wname, source_make_string (stock_id, FALSE)); + } + else if (icon_name) + { + /* Icon and Label */ + source_add (data, + " %s = (GtkWidget*) gtk_toggle_tool_button_new ();\n", + data->wname); + + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + + source_ensure_decl (data, " GtkWidget *tmp_image;\n"); + + if (glade_util_check_is_stock_id (icon_name)) + { + source_add (data, + " tmp_image = gtk_image_new_from_stock (\"%s\", tmp_toolbar_icon_size);\n", + icon_name); + } + else + { + source_create_pixmap (data, "tmp_image", icon_name); + } + + source_add (data, " gtk_widget_show (tmp_image);\n"); + + source_add (data, + " gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (%s), tmp_image);\n", + data->wname); + } + else + { + /* Just a Label */ + source_add (data, + " %s = (GtkWidget*) gtk_toggle_tool_button_new ();\n", + data->wname); + + source_add_translator_comments (data, translatable, comments); + source_add (data, + " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + } + } + + gb_widget_write_standard_source (widget, data); + + if (data->widget_data->flags & GLADE_ACTIVE) + { + source_add (data, + " gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (%s), TRUE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))) + { + source_add (data, + " gtk_tool_item_set_is_important (GTK_TOOL_ITEM (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_toggle_tool_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_toggle_tool_button_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = toggletoolbutton_xpm; + gbwidget.tooltip = _("Toolbar Toggle Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_toggle_tool_button_new; + gbwidget.gb_widget_create_properties = gb_toggle_tool_button_create_properties; + gbwidget.gb_widget_get_properties = gb_toggle_tool_button_get_properties; + gbwidget.gb_widget_set_properties = gb_toggle_tool_button_set_properties; + gbwidget.gb_widget_write_source = gb_toggle_tool_button_write_source; + gbwidget.gb_widget_destroy = gb_tool_button_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_toggle_tool_button_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbtoolbar.c b/tools/glade/glade/gbwidgets/gbtoolbar.c new file mode 100644 index 00000000..96b40260 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtoolbar.c @@ -0,0 +1,696 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +/* This is just for testing, to make sure we don't use deprecated calls. */ +#if 0 +#include <gdk/gdk.h> +#include <gtk/gtkcontainer.h> +#include <gtk/gtkenums.h> +#include <gtk/gtktooltips.h> +#include <gtk/gtktoolitem.h> +#define GTK_DISABLE_DEPRECATED +#include <gtk/gtktoolbar.h> +#undef GTK_DISABLE_DEPRECATED +#endif + +#ifdef USE_GNOME +#include <gnome.h> +#include "../glade_gnome.h" +#else +#include <gtk/gtkbutton.h> +#include <gtk/gtkimage.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkradiobutton.h> +#include <gtk/gtkspinbutton.h> +#include <gtk/gtktoolbar.h> +#include <gtk/gtktoolbutton.h> +#include <gtk/gtkvbox.h> +#endif + +#include "../gb.h" +#include "../tree.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/toolbar.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static const gchar *Size = "GtkToolbar::size"; +static const gchar *Orientation = "GtkToolbar::orientation"; +static const gchar *Style = "GtkToolbar::toolbar_style"; +static const gchar *Tooltips = "GtkToolbar::tooltips"; +static const gchar *ShowArrow = "GtkToolbar::show_arrow"; + +/* For children of a toolbar */ +static const gchar *Expand = "GtkToolbarChild::expand"; +static const gchar *Homogeneous = "GtkToolbarChild::homogeneous"; + + +static const gchar *GbOrientationChoices[] = +{"Horizontal", "Vertical", NULL}; +static const gint GbOrientationValues[] = +{ + GTK_ORIENTATION_HORIZONTAL, + GTK_ORIENTATION_VERTICAL +}; +static const gchar *GbOrientationSymbols[] = +{ + "GTK_ORIENTATION_HORIZONTAL", + "GTK_ORIENTATION_VERTICAL" +}; + +static const gchar *GbStyleChoices[] = +{"Icons", "Text", "Both", "Both Horizontal", NULL}; +static const gint GbStyleValues[] = +{ + GTK_TOOLBAR_ICONS, + GTK_TOOLBAR_TEXT, + GTK_TOOLBAR_BOTH, + GTK_TOOLBAR_BOTH_HORIZ +}; +static const gchar *GbStyleSymbols[] = +{ + "GTK_TOOLBAR_ICONS", + "GTK_TOOLBAR_TEXT", + "GTK_TOOLBAR_BOTH", + "GTK_TOOLBAR_BOTH_HORIZ" +}; + + +static void show_toolbar_dialog (GbWidgetNewData * data); +static void on_toolbar_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_toolbar_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); + +static void update_toolbar_size (GtkWidget * widget, gint size); + +static void gb_toolbar_insert_before (GtkWidget * menuitem, + GtkWidget * child); +static void gb_toolbar_insert_after (GtkWidget * menuitem, + GtkWidget * child); +static void gb_toolbar_insert (GtkWidget * child, + gint offset); + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkToolbar, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_toolbar_new(GbWidgetNewData *data) +{ + GtkWidget *new_widget; + + if (data->action == GB_LOADING) + { + new_widget = gtk_toolbar_new (); + return new_widget; + } + else + { + show_toolbar_dialog (data); + return NULL; + } +} + + +void +gb_toolbar_add_child (GtkWidget *widget, GtkWidget *child, GbWidgetSetArgData *data) +{ + /* If the child is a placeholder, we need to insert a GtkToolItem. */ + if (GB_IS_PLACEHOLDER (child)) + { + GtkWidget *toolitem = (GtkWidget*) gtk_tool_item_new (); + gtk_widget_show (toolitem); + gtk_container_add (GTK_CONTAINER (toolitem), child); + gtk_toolbar_insert (GTK_TOOLBAR (widget), + GTK_TOOL_ITEM (toolitem), -1); + } + /* GtkToolItems can just be added as they are. */ + else if (GTK_IS_TOOL_ITEM (child)) + { + gtk_toolbar_insert (GTK_TOOLBAR (widget), + GTK_TOOL_ITEM (child), -1); + } + /* Any other widgets are from the old GTK+ 2.2 files, and we need to insert + a GtkToolItem. */ + else + { + GtkWidget *toolitem = gb_widget_new_full ("GtkToolItem", FALSE, + NULL, NULL, 0, 0, NULL, + GB_LOADING, data); + gtk_toolbar_insert (GTK_TOOLBAR (widget), + GTK_TOOL_ITEM (toolitem), -1); + tree_add_widget (toolitem); + + gtk_container_add (GTK_CONTAINER (toolitem), child); + } +} + + +static void +show_toolbar_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New toolbar"), data->parent, + GTK_SIGNAL_FUNC (on_toolbar_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_toolbar_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of items:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "items", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_toolbar_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *window, *toolitem, *placeholder; + gint items, i; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "items"); + g_return_if_fail (spinbutton != NULL); + items = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_toolbar_new (); + for (i = 0; i < items; i++) + { + toolitem = (GtkWidget*) gtk_tool_item_new (); + gtk_widget_show (toolitem); + gtk_toolbar_insert (GTK_TOOLBAR (new_widget), + GTK_TOOL_ITEM (toolitem), -1); + + placeholder = editor_new_placeholder (); + gtk_container_add (GTK_CONTAINER (toolitem), placeholder); + } + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (window); +} + + +static void +on_toolbar_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_toolbar_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_int_range (Size, _("Size:"), + _("The number of items in the toolbar"), + 0, 1000, 1, 10, 1); + property_add_choice (Orientation, _("Orientation:"), + _("The toolbar orientation"), + GbOrientationChoices); + property_add_choice (Style, _("Style:"), + _("The toolbar style"), + GbStyleChoices); + property_add_bool (Tooltips, _("Tooltips:"), _("If tooltips are enabled")); + property_add_bool (ShowArrow, _("Show Arrow:"), _("If an arrow should be shown to popup a menu if the toolbar doesn't fit")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_toolbar_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + if (data->action != GB_SAVING) + gb_widget_output_int (data, Size, + gtk_toolbar_get_n_items (GTK_TOOLBAR (widget))); + + for (i = 0; i < sizeof (GbOrientationValues) + / sizeof (GbOrientationValues[0]); i++) + { + if (GbOrientationValues[i] == GTK_TOOLBAR (widget)->orientation) + gb_widget_output_choice (data, Orientation, i, GbOrientationSymbols[i]); + } + + for (i = 0; i < sizeof (GbStyleValues) / sizeof (GbStyleValues[0]); i++) + { + if (GbStyleValues[i] == GTK_TOOLBAR (widget)->style) + gb_widget_output_choice (data, Style, i, GbStyleSymbols[i]); + } + + gb_widget_output_bool (data, Tooltips, + GTK_TOOLTIPS (GTK_TOOLBAR (widget)->tooltips)->enabled); + + gb_widget_output_bool (data, ShowArrow, + gtk_toolbar_get_show_arrow (GTK_TOOLBAR (widget))); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_toolbar_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *orientation, *style; + gint i, size; + gboolean tooltips, show_arrow; + + size = gb_widget_input_int (data, Size); + if (data->apply) + update_toolbar_size (widget, size); + + orientation = gb_widget_input_choice (data, Orientation); + if (data->apply) + { + for (i = 0; i < sizeof (GbOrientationValues) + / sizeof (GbOrientationValues[0]); i++) + { + if (!strcmp (orientation, GbOrientationChoices[i]) + || !strcmp (orientation, GbOrientationSymbols[i])) + { + gtk_toolbar_set_orientation (GTK_TOOLBAR (widget), + GbOrientationValues[i]); + break; + } + } + } + + style = gb_widget_input_choice (data, Style); + if (data->apply) + { + for (i = 0; i < sizeof (GbStyleValues) / sizeof (GbStyleValues[0]); i++ + ) + { + if (!strcmp (style, GbStyleChoices[i]) + || !strcmp (style, GbStyleSymbols[i])) + { + /* This avoids any problems with redrawing the selection. */ + if (data->action == GB_APPLYING) + editor_clear_selection (NULL); + gtk_toolbar_set_style (GTK_TOOLBAR (widget), GbStyleValues[i]); + /*editor_refresh_widget (widget);*/ + break; + } + } + } + + tooltips = gb_widget_input_bool (data, Tooltips); + if (data->apply) + gtk_toolbar_set_tooltips (GTK_TOOLBAR (widget), tooltips); + + show_arrow = gb_widget_input_bool (data, ShowArrow); + if (data->apply) + gtk_toolbar_set_show_arrow (GTK_TOOLBAR (widget), show_arrow); +} + + +/* This updates the toolbar size to the given value, adding buttons or + deleting items as necessary. */ +static void +update_toolbar_size (GtkWidget * widget, gint size) +{ + gint current_size; + + current_size = gtk_toolbar_get_n_items (GTK_TOOLBAR (widget)); + + if (current_size < size) + { + /* FIXME: This avoids any problems with redrawing the selection. */ + editor_clear_selection (NULL); + + while (current_size < size) + { + GtkWidget *toolitem, *placeholder; + + toolitem = (GtkWidget*) gtk_tool_item_new (); + gtk_widget_show (toolitem); + gtk_toolbar_insert (GTK_TOOLBAR (widget), + GTK_TOOL_ITEM (toolitem), -1); + + placeholder = editor_new_placeholder (); + gtk_container_add (GTK_CONTAINER (toolitem), placeholder); + + current_size++; + } + } + else if (current_size > size) + { + while (current_size > size) + { + GtkToolItem *item; + + item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (widget), size); + gtk_container_remove (GTK_CONTAINER (widget), GTK_WIDGET (item)); + current_size--; + } + } +} + + +static void +gb_toolbar_create_child_properties (GtkWidget * widget, + GbWidgetCreateChildArgData * data) +{ + property_add_bool (Expand, _("Expand:"), + _("Set True to let the widget expand")); + property_add_bool (Homogeneous, _("Homogeneous:"), + _("If the item should be the same size as other homogeneous items")); +} + + +static void +gb_toolbar_get_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetGetArgData *data) +{ + if (data->action == GB_SAVING) + save_start_tag (data, "packing"); + + gb_widget_output_bool (data, Expand, + gtk_tool_item_get_expand (GTK_TOOL_ITEM (child))); + gb_widget_output_bool (data, Homogeneous, + gtk_tool_item_get_homogeneous (GTK_TOOL_ITEM (child))); + + if (data->action == GB_SAVING) + save_end_tag (data, "packing"); +} + + +/* Migrate old 2.0 XML files. We insert a separator tool item. */ +static void +gb_toolbar_set_new_group (GtkWidget *widget, GtkWidget *child) +{ + gint pos; + GtkWidget *separator; + + pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget), + GTK_TOOL_ITEM (child)); + + /* We use gb_widget_new_full() passing FALSE for create_default_name, + since we are loading and we don't want to create any names while loading + or they may clash. */ + separator = gb_widget_new_full ("GtkSeparatorToolItem", FALSE, + widget, NULL, 0, 0, NULL, + GB_LOADING, NULL); + + gtk_toolbar_insert (GTK_TOOLBAR (widget), GTK_TOOL_ITEM (separator), pos); +} + + +static void +gb_toolbar_set_child_properties (GtkWidget *widget, GtkWidget *child, + GbWidgetSetArgData *data) +{ + gboolean new_group, expand, homogeneous; + + /* Migrate old 2.0 XML files. */ + if (data->action == GB_LOADING) + { + new_group = gb_widget_input_bool (data, "new_group"); + if (data->apply && new_group) + gb_toolbar_set_new_group (widget, child); + } + + expand = gb_widget_input_bool (data, Expand); + if (data->apply) + gtk_tool_item_set_expand (GTK_TOOL_ITEM (child), expand); + + homogeneous = gb_widget_input_bool (data, Homogeneous); + if (data->apply) + gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (child), homogeneous); +} + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkToolbar, with signals pointing to + * other functions in this file. + */ +static void +gb_toolbar_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) +{ + GtkWidget *menuitem; + + if (data->child == NULL) + return; + + /* Commands for inserting new items. */ + menuitem = gtk_menu_item_new_with_label (_("Insert Item Before")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_toolbar_insert_before), + data->child); + + menuitem = gtk_menu_item_new_with_label (_("Insert Item After")); + gtk_widget_show (menuitem); + gtk_container_add (GTK_CONTAINER (data->menu), menuitem); + gtk_signal_connect (GTK_OBJECT (menuitem), "activate", + GTK_SIGNAL_FUNC (gb_toolbar_insert_after), + data->child); +} + + +static void +gb_toolbar_insert_before (GtkWidget * menuitem, GtkWidget * child) +{ + gb_toolbar_insert (child, -1); +} + + +static void +gb_toolbar_insert_after (GtkWidget * menuitem, GtkWidget * child) +{ + gb_toolbar_insert (child, 1); +} + + +static void +gb_toolbar_insert (GtkWidget * child, gint offset) +{ + GtkWidget *toolbar = child->parent, *toolitem, *placeholder; + gint pos; + + pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar), + GTK_TOOL_ITEM (child)); + + if (offset > 0) + pos++; + + toolitem = (GtkWidget*) gtk_tool_item_new (); + gtk_widget_show (toolitem); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), (GtkToolItem*) toolitem, pos); + + placeholder = editor_new_placeholder (); + gtk_container_add (GTK_CONTAINER (toolitem), placeholder); +} + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_toolbar_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + const gchar *orientation = GbOrientationSymbols[0]; + const gchar *style = GbStyleSymbols[0]; + gint i; + + for (i = 0; + i < sizeof (GbOrientationValues) / sizeof (GbOrientationValues[0]); i++) + { + if (GbOrientationValues[i] == GTK_TOOLBAR (widget)->orientation) + orientation = GbOrientationSymbols[i]; + } + + for (i = 0; i < sizeof (GbStyleValues) / sizeof (GbStyleValues[0]); i++) + { + if (GbStyleValues[i] == GTK_TOOLBAR (widget)->style) + style = GbStyleSymbols[i]; + } + + if (data->create_widget) + { + source_add (data, " %s = gtk_toolbar_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + /* We have to set the style explicitly for now, as the default style depends + on the user's theme settings. Ideally GTK+ should have a + GTK_TOOLBAR_DEFAULT style. */ + source_add (data, + " gtk_toolbar_set_style (GTK_TOOLBAR (%s), %s);\n", + data->wname, style); + + if (GTK_TOOLBAR (widget)->orientation != GTK_ORIENTATION_HORIZONTAL) + source_add (data, + " gtk_toolbar_set_orientation (GTK_TOOLBAR (%s), %s);\n", + data->wname, orientation); + + if (!GTK_TOOLTIPS (GTK_TOOLBAR (widget)->tooltips)->enabled) + source_add (data, + " gtk_toolbar_set_tooltips (GTK_TOOLBAR (%s), FALSE);\n", + data->wname); + + if (!gtk_toolbar_get_show_arrow (GTK_TOOLBAR (widget))) + source_add (data, + " gtk_toolbar_set_show_arrow (GTK_TOOLBAR (%s), FALSE);\n", + data->wname); + + /* We set up a tmp_toolbar_icon_size variable that we can use when creating + the tool items. */ + source_ensure_decl (data, " GtkIconSize tmp_toolbar_icon_size;\n"); + source_add (data, + " tmp_toolbar_icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (%s));\n", + data->wname); +} + + +static void +gb_toolbar_write_add_child_source (GtkWidget *parent, + const char *parent_name, + GtkWidget *child, + GbWidgetWriteSourceData *data) +{ + gboolean homogeneous, output_homogeneous = FALSE; + + if (gtk_tool_item_get_expand (GTK_TOOL_ITEM (child))) + { + source_add (data, + " gtk_tool_item_set_expand (GTK_TOOL_ITEM (%s), TRUE);\n", + data->wname); + } + + /* Homogeneous defaults to FALSE for GtkToolItem, but TRUE for + GtkToolButton and descendants. */ + homogeneous = gtk_tool_item_get_homogeneous (GTK_TOOL_ITEM (child)); + if (GTK_IS_TOOL_BUTTON (child)) + { + if (!homogeneous) + output_homogeneous = TRUE; + } + else + { + if (homogeneous) + output_homogeneous = TRUE; + } + + if (output_homogeneous) + { + source_add (data, + " gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (%s), %s);\n", + data->wname, + homogeneous ? "TRUE" : "FALSE"); + } + + source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", + parent_name, data->wname); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_toolbar_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_toolbar_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = toolbar_xpm; + gbwidget.tooltip = _("Toolbar"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_toolbar_new; + gbwidget.gb_widget_add_child = gb_toolbar_add_child; + gbwidget.gb_widget_create_properties = gb_toolbar_create_properties; + gbwidget.gb_widget_get_properties = gb_toolbar_get_properties; + gbwidget.gb_widget_set_properties = gb_toolbar_set_properties; + gbwidget.gb_widget_create_child_properties = gb_toolbar_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_toolbar_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_toolbar_set_child_properties; + gbwidget.gb_widget_create_popup_menu = gb_toolbar_create_popup_menu; + gbwidget.gb_widget_write_source = gb_toolbar_write_source; + gbwidget.gb_widget_write_add_child_source = gb_toolbar_write_add_child_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbtoolbutton.c b/tools/glade/glade/gbwidgets/gbtoolbutton.c new file mode 100644 index 00000000..471865ed --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtoolbutton.c @@ -0,0 +1,602 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/toolbutton.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +/* + * Our internal representation is slightly different to the saved XML, + * since it is awkward to support all the GtkToolButton properties. + * We only support stock buttons, or simple labels and icons. We don't + * support arbitrary label and icon widgets, partly because the Glade DTD + * can't handle them at present. + * + * If a stock_id is set within Glade, both the label and icon are set + * and these properties are made insensitive in the property editor. + * + * If no stock_id is set within Glade, the user can enter a label and use + * a stock icon or an icon from a file. Note that if a stock icon is used it + * will be saved as the "stock_id" property and the label will then override + * the stock label. So when loading if we find a "stock_id" property we check + * if a "label" property is present. If it isn't, we set Glade's "stock_id" + * property. If it is, we set Glade's "icon" property to the stock value + * instead. Phew. + */ +static gchar *StockButton = "GtkToolButton::stock_id"; +static gchar *Label = "GtkToolButton::label"; +static gchar *Icon = "GtkToolButton::icon"; +static gchar *VisibleHorz = "GtkToolButton|GtkToolItem::visible_horizontal"; +static gchar *VisibleVert = "GtkToolButton|GtkToolItem::visible_vertical"; +static gchar *IsImportant = "GtkToolButton|GtkToolItem::is_important"; + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkToolButton, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_tool_button_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget, *image; + GbWidget *pixmap_gbwidget; + + /* Place the pixmap icon in the button initially (even when loading). */ + pixmap_gbwidget = gb_widget_lookup_class ("GtkImage"); + if (pixmap_gbwidget) + { + image = gtk_image_new_from_pixmap (pixmap_gbwidget->gdkpixmap, + pixmap_gbwidget->mask); + } + else + { + image = gtk_image_new (); + g_warning ("Couldn't find GtkPixmap data"); + } + gtk_widget_show (image); + + new_widget = (GtkWidget*) gtk_tool_button_new (image, ""); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_tool_button_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_stock_item (StockButton, _("Stock Button:"), + _("The stock button to use"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + property_add_text (Label, _("Label:"), _("The text to display"), 2); + property_add_icon (Icon, _("Icon:"), + _("The icon to display"), + GTK_ICON_SIZE_LARGE_TOOLBAR); + property_add_bool (VisibleHorz, _("Show Horizontal:"), + _("If the item is visible when the toolbar is horizontal")); + property_add_bool (VisibleVert, _("Show Vertical:"), + _("If the item is visible when the toolbar is vertical")); + property_add_bool (IsImportant, _("Is Important:"), + _("If the item's text should be shown when the toolbar's mode is GTK_TOOLBAR_BOTH_HORIZ")); +} + + +void +gb_tool_button_get_standard_properties (GtkWidget *widget, + GbWidgetGetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p, + gchar *visible_horz_p, + gchar *visible_vert_p, + gchar *is_important_p) +{ + gchar *stock_id, *label, *icon_name; + gboolean label_sensitive = TRUE; + gboolean icon_sensitive = TRUE; + + /* We use the icon size from the parent toolbar. */ + if (data->action == GB_SHOWING) + { + GtkIconSize icon_size; + + icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (widget->parent)); + property_set_stock_item_icon_size (stock_id_p, icon_size); + property_set_icon_size (icon_p, icon_size); + } + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonStockIDKey); + gb_widget_output_stock_item (data, stock_id_p, stock_id); + if (stock_id) + { + label_sensitive = FALSE; + icon_sensitive = FALSE; + } + else + { + label = (gchar*) gtk_tool_button_get_label (GTK_TOOL_BUTTON (widget)); + gb_widget_output_translatable_text (data, label_p, label); + + /* We always save use_underline as TRUE, though we don't load it. */ + if (data->action == GB_SAVING) + gb_widget_output_bool (data, "use_underline", TRUE); + + icon_name = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonIconKey); + /* When saving, we save stock icons as "stock_id". */ + if (data->action == GB_SAVING + && glade_util_check_is_stock_id (icon_name)) + gb_widget_output_icon (data, "stock_id", icon_name); + else + gb_widget_output_icon (data, icon_p, icon_name); + } + + if (data->action == GB_SHOWING) + { + if (!label_sensitive) + gb_widget_output_translatable_text (data, label_p, ""); + property_set_sensitive (label_p, label_sensitive); + + if (!icon_sensitive) + gb_widget_output_pixmap_filename (data, icon_p, ""); + property_set_sensitive (icon_p, icon_sensitive); + } + + gb_widget_output_bool (data, visible_horz_p, + gtk_object_get_data (GTK_OBJECT (widget), visible_horz_p) + != NULL ? FALSE : TRUE); + + gb_widget_output_bool (data, visible_vert_p, + gtk_object_get_data (GTK_OBJECT (widget), visible_vert_p) + != NULL ? FALSE : TRUE); + + gb_widget_output_bool (data, is_important_p, + gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_tool_button_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_tool_button_get_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); +} + + + +static void +gb_tool_button_set_icon (GtkWidget *widget, + GbWidgetSetArgData * data, + gchar *icon_name) +{ + GtkWidget *image; + gchar *old_icon_name; + + if (icon_name && !*icon_name) + icon_name = NULL; + + /* Remove the old icon_name stored in the widget data, and remove the + pixmap from the project, if necessary. */ + old_icon_name = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonIconKey); + glade_project_remove_pixmap (data->project, old_icon_name); + + if (glade_util_check_is_stock_id (icon_name)) + { + GtkIconSize icon_size; + + icon_size = gtk_toolbar_get_icon_size (GTK_TOOLBAR (widget->parent)); + image = gtk_image_new_from_stock (icon_name, icon_size); + } + else if (icon_name) + { + image = gtk_image_new_from_file (icon_name); + glade_project_add_pixmap (data->project, icon_name); + } + else + { + GbWidget *pixmap_gbwidget; + + pixmap_gbwidget = gb_widget_lookup_class ("GtkImage"); + if (pixmap_gbwidget) + { + image = gtk_image_new_from_pixmap (pixmap_gbwidget->gdkpixmap, + pixmap_gbwidget->mask); + } + else + { + image = gtk_image_new (); + g_warning ("Couldn't find GtkPixmap data"); + } + } + + gtk_widget_show (image); + gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (widget), image); + + gtk_object_set_data_full (GTK_OBJECT (widget), GladeToolButtonIconKey, + g_strdup (icon_name), + icon_name ? g_free : NULL); +} + + +static void +gb_tool_button_set_stock_id (GtkWidget *widget, + GbWidgetSetArgData * data, + gchar *stock_id, + gboolean apply_label, + gchar *label_p, + gchar *icon_p) +{ + gboolean is_stock_item; + + is_stock_item = glade_util_check_is_stock_id (stock_id); + + if (is_stock_item) + { + gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (widget), stock_id); + gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (widget), NULL); + gtk_tool_button_set_label (GTK_TOOL_BUTTON (widget), NULL); + + /* If we are loading, and label is set, then this is a stock icon + rather than a stock button (at least within Glade). */ + if (data->action == GB_LOADING && apply_label) + { + gtk_object_set_data_full (GTK_OBJECT (widget), + GladeToolButtonIconKey, + g_strdup (stock_id), g_free); + } + else + { + gtk_object_set_data_full (GTK_OBJECT (widget), + GladeToolButtonStockIDKey, + g_strdup (stock_id), g_free); + gtk_object_set_data (GTK_OBJECT (widget), + GladeToolButtonIconKey, NULL); + } + } + else + { + /* It isn't a stock ID, so assume "None" has been selected and make + it a normal toolbar button. */ + GtkWidget *image; + GbWidget *pixmap_gbwidget; + + pixmap_gbwidget = gb_widget_lookup_class ("GtkImage"); + if (pixmap_gbwidget) + { + image = gtk_image_new_from_pixmap (pixmap_gbwidget->gdkpixmap, + pixmap_gbwidget->mask); + } + else + { + image = gtk_image_new (); + g_warning ("Couldn't find GtkPixmap data"); + } + gtk_widget_show (image); + gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (widget), image); + + gtk_tool_button_set_label (GTK_TOOL_BUTTON (widget), ""); + + gtk_object_set_data (GTK_OBJECT (widget), + GladeToolButtonStockIDKey, NULL); + gtk_object_set_data (GTK_OBJECT (widget), + GladeToolButtonIconKey, NULL); + } + + /* If the widget's properties are displayed, we update the sensitivity of + the label and icon, according to whether a stock item is selected. */ + if (data->action == GB_APPLYING && property_get_widget () == widget) + { + property_set_sensitive (label_p, !is_stock_item); + property_set_sensitive (icon_p, !is_stock_item); + + /* Turn off auto-apply, and set the label. */ + property_set_auto_apply (FALSE); + property_set_text (label_p, ""); + property_set_filename (icon_p, ""); + property_set_auto_apply (TRUE); + } +} + + +void +gb_tool_button_set_standard_properties (GtkWidget *widget, + GbWidgetSetArgData * data, + gchar *stock_id_p, + gchar *label_p, + gchar *icon_p, + gchar *visible_horz_p, + gchar *visible_vert_p, + gchar *is_important_p) +{ + gchar *label, *stock_id, *icon_name; + gboolean apply_label; + gboolean visible_horz, visible_vert, is_important; + + label = gb_widget_input_text (data, label_p); + apply_label = data->apply; + + stock_id = gb_widget_input_stock_item (data, stock_id_p); + if (data->apply) + { + gb_tool_button_set_stock_id (widget, data, stock_id, apply_label, + label_p, icon_p); + } + else if (data->action == GB_LOADING) + { + /* Migrate old 2.0 XML files. */ + gboolean use_stock = gb_widget_input_bool (data, "use_stock"); + if (data->apply && use_stock && apply_label) + { + gb_tool_button_set_stock_id (widget, data, label, FALSE, + label_p, icon_p); + apply_label = FALSE; + } + } + + icon_name = gb_widget_input_icon (data, icon_p); + if (data->apply) + { + gb_tool_button_set_icon (widget, data, icon_name); + } + else if (data->action == GB_LOADING) + { + /* Migrate old 2.0 XML files. */ + icon_name = gb_widget_input_icon (data, "stock_pixmap"); + if (data->apply) + { + gb_tool_button_set_icon (widget, data, icon_name); + } + else + { + icon_name = gb_widget_input_icon (data, "icon"); + if (data->apply) + { + gb_tool_button_set_icon (widget, data, icon_name); + } + } + } + + if (apply_label) + { + gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (widget), TRUE); + gtk_tool_button_set_label (GTK_TOOL_BUTTON (widget), label); + } + + if (data->action == GB_APPLYING) + g_free (label); + + + visible_horz = gb_widget_input_bool (data, visible_horz_p); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), visible_horz_p, + visible_horz ? NULL : "FALSE"); + } + + visible_vert = gb_widget_input_bool (data, visible_vert_p); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), visible_vert_p, + visible_vert ? NULL : "FALSE"); + } + + is_important = gb_widget_input_bool (data, is_important_p); + if (data->apply) + { + gtk_tool_item_set_is_important (GTK_TOOL_ITEM (widget), is_important); + } +} + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_tool_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gb_tool_button_set_standard_properties (widget, data, + StockButton, Label, Icon, + VisibleHorz, VisibleVert, + IsImportant); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkToolButton, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_tool_button_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_tool_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *stock_id, *label, *icon_name; + gboolean translatable, context; + gchar *comments; + + stock_id = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonStockIDKey); + icon_name = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonIconKey); + label = (gchar*) gtk_tool_button_get_label (GTK_TOOL_BUTTON (widget)); + + glade_util_get_translation_properties (widget, Label, &translatable, + &comments, &context); + + if (data->create_widget) + { + if (stock_id) + { + /* Stock Button */ + source_add (data, + " %s = (GtkWidget*) gtk_tool_button_new_from_stock (%s);\n", + data->wname, source_make_string (stock_id, FALSE)); + } + else if (icon_name) + { + /* Icon and Label */ + source_ensure_decl (data, " GtkWidget *tmp_image;\n"); + + if (glade_util_check_is_stock_id (icon_name)) + { + source_add (data, + " tmp_image = gtk_image_new_from_stock (\"%s\", tmp_toolbar_icon_size);\n", + icon_name); + } + else + { + source_create_pixmap (data, "tmp_image", icon_name); + } + + source_add (data, " gtk_widget_show (tmp_image);\n"); + + source_add_translator_comments (data, translatable, comments); + source_add (data, + " %s = (GtkWidget*) gtk_tool_button_new (tmp_image, %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + } + else + { + /* Just a Label */ + source_add_translator_comments (data, translatable, comments); + source_add (data, + " %s = (GtkWidget*) gtk_tool_button_new (NULL, %s);\n", + data->wname, + label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); + } + } + + gb_widget_write_standard_source (widget, data); + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))) + { + source_add (data, + " gtk_tool_item_set_is_important (GTK_TOOL_ITEM (%s), TRUE);\n", + data->wname); + } +} + + +/* Note that Radio/Toggle tool buttons use this function as well. */ +void +gb_tool_button_destroy (GtkWidget * widget, GbWidgetDestroyData * data) +{ + gchar *filename; + + /* This can be a stock id or a filename. But glade_project_remove_pixmap() + will just ignore it if it isn't a project pixmap file. */ + filename = gtk_object_get_data (GTK_OBJECT (widget), + GladeToolButtonIconKey); + glade_project_remove_pixmap (data->project, filename); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_tool_button_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_tool_button_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = toolbutton_xpm; + gbwidget.tooltip = _("Toolbar Button"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_tool_button_new; + gbwidget.gb_widget_create_properties = gb_tool_button_create_properties; + gbwidget.gb_widget_get_properties = gb_tool_button_get_properties; + gbwidget.gb_widget_set_properties = gb_tool_button_set_properties; + gbwidget.gb_widget_write_source = gb_tool_button_write_source; + gbwidget.gb_widget_destroy = gb_tool_button_destroy; + +/* + gbwidget.gb_widget_create_popup_menu = gb_tool_button_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbtoolitem.c b/tools/glade/glade/gbwidgets/gbtoolitem.c new file mode 100644 index 00000000..974a733f --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtoolitem.c @@ -0,0 +1,215 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999-2002 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/toolitem.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *VisibleHorz = "GtkToolItem::visible_horizontal"; +static gchar *VisibleVert = "GtkToolItem::visible_vertical"; +static gchar *IsImportant = "GtkToolItem::is_important"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkToolItem, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +/* +static GtkWidget* +gb_tool_item_new (GbWidgetNewData *data) +{ + +} +*/ + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_tool_item_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (VisibleHorz, _("Show Horizontal:"), + _("If the item is visible when the toolbar is horizontal")); + property_add_bool (VisibleVert, _("Show Vertical:"), + _("If the item is visible when the toolbar is vertical")); + property_add_bool (IsImportant, _("Is Important:"), + _("If the item's text should be shown when the toolbar's mode is GTK_TOOLBAR_BOTH_HORIZ")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_tool_item_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gb_widget_output_bool (data, VisibleHorz, + gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) + != NULL ? FALSE : TRUE); + + gb_widget_output_bool (data, VisibleVert, + gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) + != NULL ? FALSE : TRUE); + + gb_widget_output_bool (data, IsImportant, + gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_tool_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean visible_horz, visible_vert, is_important; + + visible_horz = gb_widget_input_bool (data, VisibleHorz); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), VisibleHorz, + visible_horz ? NULL : "FALSE"); + } + + visible_vert = gb_widget_input_bool (data, VisibleVert); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), VisibleVert, + visible_vert ? NULL : "FALSE"); + } + + is_important = gb_widget_input_bool (data, IsImportant); + if (data->apply) + { + gtk_tool_item_set_is_important (GTK_TOOL_ITEM (widget), is_important); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkToolItem, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_tool_item_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_tool_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, + " %s = (GtkWidget*) gtk_tool_item_new ();\n", + data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) + { + source_add (data, + " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", + data->wname); + } + + if (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))) + { + source_add (data, + " gtk_tool_item_set_is_important (GTK_TOOL_ITEM (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_tool_item_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_tool_item_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = toolitem_xpm; + gbwidget.tooltip = _("Toolbar Item"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_create_properties = gb_tool_item_create_properties; + gbwidget.gb_widget_get_properties = gb_tool_item_get_properties; + gbwidget.gb_widget_set_properties = gb_tool_item_set_properties; + gbwidget.gb_widget_write_source = gb_tool_item_write_source; +/* + gbwidget.gb_widget_new = gb_tool_item_new; + gbwidget.gb_widget_create_popup_menu = gb_tool_item_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbtreeview.c b/tools/glade/glade/gbwidgets/gbtreeview.c new file mode 100644 index 00000000..3baebab0 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbtreeview.c @@ -0,0 +1,331 @@ +/* Gtk+ User Interface Builder + * Copyright (C) 1999 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> + +#include <gtk/gtk.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/ctree.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *HeadersVisible = "GtkTreeView::headers_visible"; +static gchar *RulesHint = "GtkTreeView::rules_hint"; +static gchar *Reorderable = "GtkTreeView::reorderable"; +static gchar *EnableSearch = "GtkTreeView::enable_search"; + +static gchar *FixedHeightMode = "GtkTreeView::fixed_height_mode"; +static gchar *HoverSelection = "GtkTreeView::hover_selection"; +static gchar *HoverExpand = "GtkTreeView::hover_expand"; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkTreeView, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + */ +static GtkWidget* +gb_tree_view_new (GbWidgetNewData *data) +{ + GtkWidget *new_widget; + GtkListStore *store; + GtkTreeIter iter; + GtkTreeViewColumn *col; + GtkCellRenderer *rend; + char buf[256]; + gint i; + + store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + new_widget = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); + + /* We set the columns to a fixed size, since the "fixed_height_mode" + property requires that. */ + rend = gtk_cell_renderer_text_new (); + col = gtk_tree_view_column_new_with_attributes (_("Column 1"), rend, + "text", 0, + NULL); + gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED); + gtk_tree_view_column_set_fixed_width (col, 100); + gtk_tree_view_append_column (GTK_TREE_VIEW (new_widget), col); + + rend = gtk_cell_renderer_text_new (); + col = gtk_tree_view_column_new_with_attributes (_("Column 2"), rend, + "text", 1, + NULL); + gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED); + gtk_tree_view_column_set_fixed_width (col, 100); + gtk_tree_view_append_column (GTK_TREE_VIEW (new_widget), col); + + rend = gtk_cell_renderer_text_new (); + col = gtk_tree_view_column_new_with_attributes (_("Column 3"), rend, + "text", 2, + NULL); + gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED); + gtk_tree_view_column_set_fixed_width (col, 100); + gtk_tree_view_append_column (GTK_TREE_VIEW (new_widget), col); + + for (i = 1; i <= 8; i++) + { + gtk_list_store_append (store, &iter); + sprintf (buf, _("Row %i"), i); + gtk_list_store_set (store, &iter, 0, buf, 1, "...", 2, "...", -1); + } + + g_object_unref (G_OBJECT (store)); + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_tree_view_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (HeadersVisible, _("Headers Visible:"), + _("If the column header buttons are shown")); + property_add_bool (RulesHint, _("Rules Hint:"), + _("If a hint is set so the theme engine should draw rows in alternating colors")); + property_add_bool (Reorderable, _("Reorderable:"), + _("If the view is reorderable")); + property_add_bool (EnableSearch, _("Enable Search:"), + _("If the user can search through columns interactively")); + + property_add_bool (FixedHeightMode, _("Fixed Height Mode:"), + _("Sets all rows to the same height to improve performance")); + property_add_bool (HoverSelection, _("Hover Selection:"), + _("Whether the selection should follow the pointer")); + property_add_bool (HoverExpand, _("Hover Expand:"), + _("Whether rows should be expanded or collapsed when the pointer moves over them")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_tree_view_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) +{ + gboolean headers_visible, rules_hint, reorderable, enable_search; + gboolean fixed_height_mode, hover_selection, hover_expand; + + g_object_get (G_OBJECT (widget), + "headers_visible", &headers_visible, + "rules_hint", &rules_hint, + "reorderable", &reorderable, + "enable_search", &enable_search, + "fixed_height_mode", &fixed_height_mode, + "hover_selection", &hover_selection, + "hover_expand", &hover_expand, + NULL); + + gb_widget_output_bool (data, HeadersVisible, headers_visible); + gb_widget_output_bool (data, RulesHint, rules_hint); + gb_widget_output_bool (data, Reorderable, reorderable); + gb_widget_output_bool (data, EnableSearch, enable_search); + gb_widget_output_bool (data, FixedHeightMode, fixed_height_mode); + gb_widget_output_bool (data, HoverSelection, hover_selection); + gb_widget_output_bool (data, HoverExpand, hover_expand); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_tree_view_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean headers_visible, rules_hint, reorderable, enable_search; + gboolean fixed_height_mode, hover_selection, hover_expand; + + headers_visible = gb_widget_input_bool (data, HeadersVisible); + if (data->apply) + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (widget), headers_visible); + + rules_hint = gb_widget_input_bool (data, RulesHint); + if (data->apply) + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (widget), rules_hint); + + reorderable = gb_widget_input_bool (data, Reorderable); + if (data->apply) + gtk_tree_view_set_reorderable (GTK_TREE_VIEW (widget), reorderable); + + enable_search = gb_widget_input_bool (data, EnableSearch); + if (data->apply) + gtk_tree_view_set_enable_search (GTK_TREE_VIEW (widget), enable_search); + + fixed_height_mode = gb_widget_input_bool (data, FixedHeightMode); + if (data->apply) + gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (widget), fixed_height_mode); + + hover_selection = gb_widget_input_bool (data, HoverSelection); + if (data->apply) + gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (widget), hover_selection); + + hover_expand = gb_widget_input_bool (data, HoverExpand); + if (data->apply) + gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (widget), hover_expand); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkTreeView, with signals pointing to + * other functions in this file. + */ +/* +static void +gb_tree_view_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) +{ + +} +*/ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_tree_view_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gboolean headers_visible, rules_hint, reorderable, enable_search; + gboolean fixed_height_mode, hover_selection, hover_expand; + + if (data->create_widget) + { + source_add (data, " %s = gtk_tree_view_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + g_object_get (G_OBJECT (widget), + "headers_visible", &headers_visible, + "rules_hint", &rules_hint, + "reorderable", &reorderable, + "enable_search", &enable_search, + "fixed_height_mode", &fixed_height_mode, + "hover_selection", &hover_selection, + "hover_expand", &hover_expand, + NULL); + + if (!headers_visible) + { + source_add (data, + " gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (%s), FALSE);\n", + data->wname); + } + + if (rules_hint) + { + source_add (data, + " gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (%s), TRUE);\n", + data->wname); + } + + if (reorderable) + { + source_add (data, + " gtk_tree_view_set_reorderable (GTK_TREE_VIEW (%s), TRUE);\n", + data->wname); + } + + if (!enable_search) + { + source_add (data, + " gtk_tree_view_set_enable_search (GTK_TREE_VIEW (%s), FALSE);\n", + data->wname); + } + + if (fixed_height_mode) + { + source_add (data, + " gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (%s), TRUE);\n", + data->wname); + } + + if (hover_selection) + { + source_add (data, + " gtk_tree_view_set_hover_selection (GTK_TREE_VIEW (%s), TRUE);\n", + data->wname); + } + + if (hover_expand) + { + source_add (data, + " gtk_tree_view_set_hover_expand (GTK_TREE_VIEW (%s), TRUE);\n", + data->wname); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget* +gb_tree_view_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_tree_view_get_type(); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct(&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = ctree_xpm; + gbwidget.tooltip = _("List or Tree View"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_tree_view_new; + gbwidget.gb_widget_create_properties = gb_tree_view_create_properties; + gbwidget.gb_widget_get_properties = gb_tree_view_get_properties; + gbwidget.gb_widget_set_properties = gb_tree_view_set_properties; + gbwidget.gb_widget_write_source = gb_tree_view_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_tree_view_create_popup_menu; +*/ + + return &gbwidget; +} + diff --git a/tools/glade/glade/gbwidgets/gbvbox.c b/tools/glade/glade/gbwidgets/gbvbox.c new file mode 100644 index 00000000..fcdc580d --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbvbox.c @@ -0,0 +1,261 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkhbox.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkmenu.h> +#include <gtk/gtkmenuitem.h> +#include <gtk/gtkspinbutton.h> +#include <gtk/gtkvbox.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/vbox.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Size = "VBox|GtkBox::size"; +static gchar *Homogeneous = "VBox|GtkBox::homogeneous"; +static gchar *Spacing = "VBox|GtkBox::spacing"; + +static void show_vbox_dialog (GbWidgetNewData * data); +static void on_vbox_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_vbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkVBox, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_vbox_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_LOADING) + { + new_widget = gtk_vbox_new (FALSE, 0); + return new_widget; + } + else + { + show_vbox_dialog (data); + return NULL; + } +} + + +static void +show_vbox_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New vertical box"), data->parent, + GTK_SIGNAL_FUNC (on_vbox_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_vbox_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of rows:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "rows", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_vbox_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *window, *placeholder; + gint rows, i; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "rows"); + g_return_if_fail (spinbutton != NULL); + rows = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_vbox_new (FALSE, 0); + for (i = 0; i < rows; i++) + { + placeholder = editor_new_placeholder (); + /*gtk_widget_set_usize(placeholder, 80, 60); */ + gtk_box_pack_start (GTK_BOX (new_widget), placeholder, TRUE, TRUE, 0); + } + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (window); +} + + +static void +on_vbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_vbox_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_int_range (Size, _("Size:"), _("The number of widgets in the box"), + 0, 1000, 1, 10, 1); + property_add_bool (Homogeneous, _("Homogeneous:"), + _("If the children should be the same size")); + property_add_int_range (Spacing, _("Spacing:"), _("The space between each child"), + 0, 1000, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_vbox_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + if (data->action != GB_SAVING) + gb_widget_output_int (data, Size, g_list_length (GTK_BOX (widget)->children)); + gb_widget_output_bool (data, Homogeneous, GTK_BOX (widget)->homogeneous); + gb_widget_output_int (data, Spacing, GTK_BOX (widget)->spacing); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_vbox_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean homogeneous; + gint spacing, size; + + if (data->action != GB_LOADING) + { + size = gb_widget_input_int (data, Size); + if (data->apply) + gb_box_set_size (widget, size); + } + + homogeneous = gb_widget_input_bool (data, Homogeneous); + if (data->apply) + gtk_box_set_homogeneous (GTK_BOX (widget), homogeneous); + + spacing = gb_widget_input_int (data, Spacing); + if (data->apply) + gtk_box_set_spacing (GTK_BOX (widget), spacing); +} + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_vbox_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_vbox_new (%s, %i);\n", data->wname, + GTK_BOX (widget)->homogeneous ? "TRUE" : "FALSE", + GTK_BOX (widget)->spacing); + } + + gb_widget_write_standard_source (widget, data); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_vbox_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_vbox_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = vbox_xpm; + gbwidget.tooltip = _("Vertical Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_vbox_new; + gbwidget.gb_widget_create_properties = gb_vbox_create_properties; + gbwidget.gb_widget_get_properties = gb_vbox_get_properties; + gbwidget.gb_widget_set_properties = gb_vbox_set_properties; + gbwidget.gb_widget_write_source = gb_vbox_write_source; + + gbwidget.gb_widget_create_child_properties = gb_box_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_box_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_box_set_child_properties; + gbwidget.gb_widget_create_popup_menu = gb_box_create_popup_menu; + gbwidget.gb_widget_write_add_child_source = gb_box_write_add_child_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbvbuttonbox.c b/tools/glade/glade/gbwidgets/gbvbuttonbox.c new file mode 100644 index 00000000..2d581c76 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbvbuttonbox.c @@ -0,0 +1,357 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkvbbox.h> +#include <gtk/gtkhbox.h> +#include <gtk/gtklabel.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkspinbutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/vbuttonbox.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Size = "VBBox|GtkBox::size"; +static gchar *Layout = "VBBox|GtkButtonBox::layout_style"; +static gchar *Spacing = "VBBox|GtkButtonBox::spacing"; + +static const gchar *GbLayoutChoices[] = +{"Default", "Spread", "Edge", + "Start", "End", NULL}; +static const gint GbLayoutValues[] = +{ + GTK_BUTTONBOX_DEFAULT_STYLE, + GTK_BUTTONBOX_SPREAD, + GTK_BUTTONBOX_EDGE, + GTK_BUTTONBOX_START, + GTK_BUTTONBOX_END +}; +static const gchar *GbLayoutSymbols[] = +{ + "GTK_BUTTONBOX_DEFAULT_STYLE", + "GTK_BUTTONBOX_SPREAD", + "GTK_BUTTONBOX_EDGE", + "GTK_BUTTONBOX_START", + "GTK_BUTTONBOX_END" +}; + + +/* FIXME: Hack - copied from gtkbbox.c. Should use GParam query instead, + or use an optional int property instead. */ +#define DEFAULT_CHILD_MIN_WIDTH 85 +#define DEFAULT_CHILD_MIN_HEIGHT 27 +#define DEFAULT_CHILD_IPAD_X 4 +#define DEFAULT_CHILD_IPAD_Y 0 + + +static void show_vbbox_dialog (GbWidgetNewData * data); +static void on_vbbox_dialog_ok (GtkWidget * widget, + GbWidgetNewData * data); +static void on_vbbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkVButtonBox, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_vbutton_box_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget; + + if (data->action == GB_LOADING) + { + new_widget = gtk_vbutton_box_new (); + return new_widget; + } + else + { + show_vbbox_dialog (data); + return NULL; + } +} + + +static void +show_vbbox_dialog (GbWidgetNewData * data) +{ + GtkWidget *dialog, *vbox, *hbox, *label, *spinbutton; + GtkObject *adjustment; + + dialog = glade_util_create_dialog (_("New vertical button box"), + data->parent, + GTK_SIGNAL_FUNC (on_vbbox_dialog_ok), + data, &vbox); + gtk_signal_connect (GTK_OBJECT (dialog), "destroy", + GTK_SIGNAL_FUNC (on_vbbox_dialog_destroy), data); + + hbox = gtk_hbox_new (FALSE, 5); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 10); + gtk_widget_show (hbox); + + label = gtk_label_new (_("Number of rows:")); + gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 5); + gtk_widget_show (label); + + adjustment = gtk_adjustment_new (3, 1, 100, 1, 10, 10); + spinbutton = glade_util_spin_button_new (GTK_OBJECT (dialog), "rows", + GTK_ADJUSTMENT (adjustment), 1, 0); + gtk_box_pack_start (GTK_BOX (hbox), spinbutton, TRUE, TRUE, 5); + gtk_widget_set_usize (spinbutton, 50, -1); + gtk_widget_grab_focus (spinbutton); + gtk_widget_show (spinbutton); + + gtk_widget_show (dialog); + gtk_grab_add (dialog); +} + + +static void +on_vbbox_dialog_ok (GtkWidget * widget, GbWidgetNewData * data) +{ + GtkWidget *new_widget, *spinbutton, *window, *new_child; + gint rows, i; + + window = gtk_widget_get_toplevel (widget); + + /* Only call callback if placeholder/fixed widget is still there */ + if (gb_widget_can_finish_new (data)) + { + spinbutton = gtk_object_get_data (GTK_OBJECT (window), "rows"); + g_return_if_fail (spinbutton != NULL); + rows = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton)); + + new_widget = gtk_vbutton_box_new (); + for (i = 0; i < rows; i++) + { + new_child = gb_widget_new ("GtkButton", new_widget); + GTK_WIDGET_SET_FLAGS (new_child, GTK_CAN_DEFAULT); + gtk_container_add (GTK_CONTAINER (new_widget), new_child); + } + gb_widget_initialize (new_widget, data); + (*data->callback) (new_widget, data); + } + gtk_widget_destroy (window); +} + + +static void +on_vbbox_dialog_destroy (GtkWidget * widget, + GbWidgetNewData * data) +{ + gb_widget_free_new_data (data); + gtk_grab_remove (widget); +} + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_vbutton_box_create_properties (GtkWidget * widget, GbWidgetCreateArgData * + data) +{ + property_add_int_range (Size, "Size:", "The number of buttons", + 0, 1000, 1, 10, 1); + property_add_choice (Layout, "Layout:", + "The layout style of the buttons", + GbLayoutChoices); + property_add_int_range (Spacing, "Spacing:", "The space between the buttons", + 0, 1000, 1, 10, 1); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_vbutton_box_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + GtkButtonBoxStyle layout; + gint i, spacing; + + if (data->action != GB_SAVING) + gb_widget_output_int (data, Size, g_list_length (GTK_BOX (widget)->children)); + + layout = gtk_button_box_get_layout (GTK_BUTTON_BOX (widget)); + for (i = 0; i < sizeof (GbLayoutValues) / sizeof (GbLayoutValues[0]); i++) + { + if (GbLayoutValues[i] == layout) + gb_widget_output_choice (data, Layout, i, GbLayoutSymbols[i]); + } + + spacing = gtk_box_get_spacing (GTK_BOX (widget)); + gb_widget_output_int (data, Spacing, spacing); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_vbutton_box_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gint size, i, spacing; + gchar *layout; + gboolean queue_resize = FALSE; + + if (data->action != GB_LOADING) + { + size = gb_widget_input_int (data, Size); + if (data->apply) + gb_box_set_size (widget, size); + } + + layout = gb_widget_input_choice (data, Layout); + if (data->apply) + { + for (i = 0; i < sizeof (GbLayoutValues) / sizeof (GbLayoutValues[0]); i + ++) + { + if (!strcmp (layout, GbLayoutChoices[i]) + || !strcmp (layout, GbLayoutSymbols[i])) + { + gtk_button_box_set_layout (GTK_BUTTON_BOX (widget), GbLayoutValues + [i]); + queue_resize = TRUE; + break; + } + } + } + + spacing = gb_widget_input_int (data, Spacing); + if (data->apply) + { + gtk_box_set_spacing (GTK_BOX (widget), spacing); + queue_resize = TRUE; + } + + if (queue_resize) + gtk_widget_queue_resize (widget); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkVButtonBox, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_vbutton_box_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_vbutton_box_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkButtonBoxStyle layout_style; + gint spacing, i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_vbutton_box_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + layout_style = GTK_BUTTON_BOX (widget)->layout_style; + if (layout_style != GTK_BUTTONBOX_DEFAULT_STYLE) + { + for (i = 0; i < sizeof (GbLayoutValues) / sizeof (GbLayoutValues[0]); i + ++) + { + if (GbLayoutValues[i] == layout_style) + source_add (data, + " gtk_button_box_set_layout (GTK_BUTTON_BOX (%s), %s);\n", + data->wname, GbLayoutSymbols[i]); + } + } + + spacing = gtk_box_get_spacing (GTK_BOX (widget)); + if (spacing != 0) + { + source_add (data, + " gtk_box_set_spacing (GTK_BOX (%s), %i);\n", + data->wname, spacing); + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_vbutton_box_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_vbutton_box_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = vbuttonbox_xpm; + gbwidget.tooltip = _("Vertical Button Box"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_vbutton_box_new; + gbwidget.gb_widget_create_properties = gb_vbutton_box_create_properties; + gbwidget.gb_widget_get_properties = gb_vbutton_box_get_properties; + gbwidget.gb_widget_set_properties = gb_vbutton_box_set_properties; + gbwidget.gb_widget_write_source = gb_vbutton_box_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_vbutton_box_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbviewport.c b/tools/glade/glade/gbwidgets/gbviewport.c new file mode 100644 index 00000000..8fc8777e --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbviewport.c @@ -0,0 +1,253 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkviewport.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/viewport.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Shadow = "GtkViewport::shadow_type"; + +/* I don't think there's any point in adding these. */ +/* + static gchar *HValues[] = { + "GtkViewport::hvalue", + "GtkViewport::hlower", + "GtkViewport::hupper", + "GtkViewport::hstep", + "GtkViewport::hpage", + "GtkViewport::hpage_size", + }; + + static gchar *VValues[] = { + "GtkViewport::vvalue", + "GtkViewport::vlower", + "GtkViewport::vupper", + "GtkViewport::vstep", + "GtkViewport::vpage", + "GtkViewport::vpage_size", + }; + */ + +static const gchar *GbShadowChoices[] = +{"None", "In", "Out", + "Etched In", "Etched Out", NULL}; +static const gint GbShadowValues[] = +{ + GTK_SHADOW_NONE, + GTK_SHADOW_IN, + GTK_SHADOW_OUT, + GTK_SHADOW_ETCHED_IN, + GTK_SHADOW_ETCHED_OUT +}; +static const gchar *GbShadowSymbols[] = +{ + "GTK_SHADOW_NONE", + "GTK_SHADOW_IN", + "GTK_SHADOW_OUT", + "GTK_SHADOW_ETCHED_IN", + "GTK_SHADOW_ETCHED_OUT" +}; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkViewport, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_viewport_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_viewport_new (NULL, NULL); + if (data->action != GB_LOADING) + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_viewport_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Shadow, _("Shadow:"), _("The type of shadow of the viewport"), + GbShadowChoices); + /* + property_add_adjustment(HValues, GB_ADJUST_H_LABELS); + property_add_adjustment(VValues, GB_ADJUST_V_LABELS); + */ +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_viewport_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) + { + if (GbShadowValues[i] == GTK_VIEWPORT (widget)->shadow_type) + gb_widget_output_choice (data, Shadow, i, GbShadowSymbols[i]); + } + + /* + gb_widget_output_adjustment(data, HValues, GTK_VIEWPORT(widget)->hadjustment); + gb_widget_output_adjustment(data, VValues, GTK_VIEWPORT(widget)->vadjustment); + */ +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_viewport_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gint i; + gchar *shadow; + + shadow = gb_widget_input_choice (data, Shadow); + if (data->apply) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (!strcmp (shadow, GbShadowChoices[i]) + || !strcmp (shadow, GbShadowSymbols[i])) + { + gtk_viewport_set_shadow_type (GTK_VIEWPORT (widget), GbShadowValues + [i]); + break; + } + } + } + + /* + if (gb_widget_input_adjustment(data, HValues, + GTK_VIEWPORT(widget)->hadjustment)) + gtk_signal_emit_by_name (GTK_OBJECT (GTK_VIEWPORT(widget)->hadjustment), + "value_changed"); + if (gb_widget_input_adjustment(data, VValues, + GTK_VIEWPORT(widget)->vadjustment)) + gtk_signal_emit_by_name (GTK_OBJECT (GTK_VIEWPORT(widget)->vadjustment), + "value_changed"); + */ +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkViewport, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_viewport_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_viewport_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_viewport_new (NULL, NULL);\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + if (GTK_VIEWPORT (widget)->shadow_type != GTK_SHADOW_IN) + { + for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i + ++) + { + if (GbShadowValues[i] == GTK_VIEWPORT (widget)->shadow_type) + source_add (data, + " gtk_viewport_set_shadow_type (GTK_VIEWPORT (%s), %s);\n", + data->wname, GbShadowSymbols[i]); + } + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_viewport_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_viewport_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = viewport_xpm; + gbwidget.tooltip = _("Viewport"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_viewport_new; + gbwidget.gb_widget_create_properties = gb_viewport_create_properties; + gbwidget.gb_widget_get_properties = gb_viewport_get_properties; + gbwidget.gb_widget_set_properties = gb_viewport_set_properties; + gbwidget.gb_widget_write_source = gb_viewport_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_viewport_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbvpaned.c b/tools/glade/glade/gbwidgets/gbvpaned.c new file mode 100644 index 00000000..47a4d1b7 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbvpaned.c @@ -0,0 +1,209 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkvpaned.h> +#include <gtk/gtktogglebutton.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/vpaned.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Position = "VPaned|GtkPaned::position"; + +static void on_toggle_position (GtkWidget * widget, gpointer value); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkVPaned, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_vpaned_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_vpaned_new (); + if (data->action != GB_LOADING) + { + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + gtk_container_add (GTK_CONTAINER (new_widget), editor_new_placeholder ()); + } + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_vpaned_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_optional_int_range (Position, _("Position:"), + _("The position of the divider"), + 1, 1000, 1, 10, 1, + on_toggle_position); +} + + +static void +on_toggle_position (GtkWidget * button, gpointer value) +{ + GtkWidget *widget; + gboolean value_set; + gint position; + + widget = property_get_widget (); + if (widget == NULL) + return; + + value_set = GTK_TOGGLE_BUTTON (button)->active ? TRUE : FALSE; + gtk_widget_set_sensitive (GTK_WIDGET (value), value_set); + + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + Position)); + gtk_paned_set_position (GTK_PANED (widget), + value_set ? position : -1); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_vpaned_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint position; + + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + Position)); + gb_widget_output_optional_int (data, Position, position, + GTK_PANED (widget)->position_set); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_vpaned_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gint position; + + position = gb_widget_input_int (data, Position); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), Position, + GINT_TO_POINTER (position)); + gtk_paned_set_position (GTK_PANED (widget), position); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkVPaned, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_vpaned_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_vpaned_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint position; + + if (data->create_widget) + { + source_add (data, " %s = gtk_vpaned_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); + + if (GTK_PANED (widget)->position_set) + { + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + Position)); + source_add (data, " gtk_paned_set_position (GTK_PANED (%s), %d);\n", + data->wname, position); + } +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_vpaned_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_vpaned_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = vpaned_xpm; + gbwidget.tooltip = _("Vertical Panes"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_vpaned_new; + gbwidget.gb_widget_create_properties = gb_vpaned_create_properties; + gbwidget.gb_widget_get_properties = gb_vpaned_get_properties; + gbwidget.gb_widget_set_properties = gb_vpaned_set_properties; + gbwidget.gb_widget_create_child_properties = gb_paned_create_child_properties; + gbwidget.gb_widget_get_child_properties = gb_paned_get_child_properties; + gbwidget.gb_widget_set_child_properties = gb_paned_set_child_properties; +/* + gbwidget.gb_widget_create_popup_menu = gb_vpaned_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_vpaned_write_source; + gbwidget.gb_widget_write_add_child_source = gb_paned_write_add_child_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbvruler.c b/tools/glade/glade/gbwidgets/gbvruler.c new file mode 100644 index 00000000..f482df36 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbvruler.c @@ -0,0 +1,260 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkvruler.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/vruler.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Metric = "VRuler|GtkRuler::metric"; +static gchar *Lower = "VRuler|GtkRuler::lower"; +static gchar *Upper = "VRuler|GtkRuler::upper"; +static gchar *Pos = "VRuler|GtkRuler::position"; +static gchar *Max = "VRuler|GtkRuler::max_size"; + +static const gchar *GbMetricChoices[] = +{"Pixels", "Inches", "Centimeters", NULL}; +static const gint GbMetricValues[] = +{ + GTK_PIXELS, + GTK_INCHES, + GTK_CENTIMETERS +}; +static const gchar *GbMetricSymbols[] = +{ + "GTK_PIXELS", + "GTK_INCHES", + "GTK_CENTIMETERS" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkVRuler, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_vruler_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget = gtk_vruler_new (); + gtk_ruler_set_range (GTK_RULER (new_widget), 0, 10, 0, 10); + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_vruler_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Metric, _("Metric:"), + _("The units of the ruler"), + GbMetricChoices); + property_add_float (Lower, _("Lower Value:"), + _("The low value of the ruler")); + property_add_float (Upper, _("Upper Value:"), + _("The low value of the ruler")); + property_add_float (Pos, _("Position:"), + _("The current position on the ruler")); + property_add_float (Max, _("Max:"), + _("The maximum value of the ruler")); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_vruler_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gchar *metric_name; + gint i; + + metric_name = GTK_RULER (widget)->metric->metric_name; + for (i = 0; i < sizeof (GbMetricValues) / sizeof (GbMetricValues[0]); i++) + { + if (!strcmp (GbMetricChoices[i], metric_name)) + gb_widget_output_choice (data, Metric, i, GbMetricSymbols[i]); + } + + gb_widget_output_float (data, Lower, GTK_RULER (widget)->lower); + gb_widget_output_float (data, Upper, GTK_RULER (widget)->upper); + gb_widget_output_float (data, Pos, GTK_RULER (widget)->position); + gb_widget_output_float (data, Max, GTK_RULER (widget)->max_size); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_vruler_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *metric; + gint i; + gfloat lower, upper, pos, max; + gboolean set_range = FALSE; + + metric = gb_widget_input_choice (data, Metric); + if (data->apply) + { + for (i = 0; i < sizeof (GbMetricValues) / sizeof (GbMetricValues[0]); i + ++) + { + if (!strcmp (metric, GbMetricChoices[i]) + || !strcmp (metric, GbMetricSymbols[i])) + { + gtk_ruler_set_metric (GTK_RULER (widget), GbMetricValues[i]); + break; + } + } + } + + lower = gb_widget_input_float (data, Lower); + if (data->apply) + set_range = TRUE; + else + lower = GTK_RULER (widget)->lower; + + upper = gb_widget_input_float (data, Upper); + if (data->apply) + set_range = TRUE; + else + upper = GTK_RULER (widget)->upper; + + pos = gb_widget_input_float (data, Pos); + if (data->apply) + set_range = TRUE; + else + pos = GTK_RULER (widget)->position; + + max = gb_widget_input_float (data, Max); + if (data->apply) + set_range = TRUE; + else + max = GTK_RULER (widget)->max_size; + + if (set_range) + gtk_ruler_set_range (GTK_RULER (widget), lower, upper, pos, max); +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkVRuler, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_vruler_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_vruler_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gchar *metric_name; + gint i; + + if (data->create_widget) + { + source_add (data, " %s = gtk_vruler_new ();\n", data->wname); + } + + gb_widget_write_standard_source (widget, data); + + metric_name = GTK_RULER (widget)->metric->metric_name; + if (strcmp (metric_name, "Pixels")) + { + for (i = 0; i < sizeof (GbMetricValues) / sizeof (GbMetricValues[0]); i + ++) + { + if (!strcmp (GbMetricChoices[i], metric_name)) + source_add (data, " gtk_ruler_set_metric (GTK_RULER (%s), %s);\n", + data->wname, GbMetricSymbols[i]); + } + } + source_add (data, " gtk_ruler_set_range (GTK_RULER (%s), %g, %g, %g, %g);\n", + data->wname, GTK_RULER (widget)->lower, GTK_RULER (widget)->upper, + GTK_RULER (widget)->position, GTK_RULER (widget)->max_size); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_vruler_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_vruler_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = vruler_xpm; + gbwidget.tooltip = _("Vertical Ruler"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_vruler_new; + gbwidget.gb_widget_create_properties = gb_vruler_create_properties; + gbwidget.gb_widget_get_properties = gb_vruler_get_properties; + gbwidget.gb_widget_set_properties = gb_vruler_set_properties; + gbwidget.gb_widget_write_source = gb_vruler_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_vruler_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbvscale.c b/tools/glade/glade/gbwidgets/gbvscale.c new file mode 100644 index 00000000..0f8166c6 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbvscale.c @@ -0,0 +1,332 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkvscale.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/vscale.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *DrawValue = "VScale|GtkScale::draw_value"; +static gchar *ValuePos = "VScale|GtkScale::value_pos"; +static gchar *Digits = "VScale|GtkRange::digits"; +static gchar *Policy = "VScale|GtkRange::update_policy"; +static gchar *Inverted = "VScale|GtkRange::inverted"; + +static const gchar *Values[] = +{ + "GtkVScale::value", + "GtkVScale::lower", + "GtkVScale::upper", + "GtkVScale::step", + "GtkVScale::page", + "GtkVScale::page_size", +}; + +static const gchar *GbValuePosChoices[] = +{"Left", "Right", "Top", "Bottom", NULL}; +static const gint GbValuePosValues[] = +{ + GTK_POS_LEFT, + GTK_POS_RIGHT, + GTK_POS_TOP, + GTK_POS_BOTTOM +}; +static const gchar *GbValuePosSymbols[] = +{ + "GTK_POS_LEFT", + "GTK_POS_RIGHT", + "GTK_POS_TOP", + "GTK_POS_BOTTOM" +}; + +static const gchar *GbPolicyChoices[] = +{"Continuous", "Discontinuous", "Delayed", + NULL}; +static const gint GbPolicyValues[] = +{ + GTK_UPDATE_CONTINUOUS, + GTK_UPDATE_DISCONTINUOUS, + GTK_UPDATE_DELAYED +}; +static const gchar *GbPolicySymbols[] = +{ + "GTK_UPDATE_CONTINUOUS", + "GTK_UPDATE_DISCONTINUOUS", + "GTK_UPDATE_DELAYED" +}; + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkVScale, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_vscale_new (GbWidgetNewData * data) +{ + return gtk_vscale_new (NULL); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_vscale_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_bool (DrawValue, _("Show Value:"), _("If the scale's value is shown")); + property_add_int_range (Digits, _("Digits:"), _("The number of digits to show"), + 0, 13, 1, 10, 1); + property_add_choice (ValuePos, _("Value Pos:"), + _("The position of the value"), + GbValuePosChoices); + property_add_choice (Policy, _("Policy:"), + _("The update policy of the scale"), + GbPolicyChoices); + property_add_bool (Inverted, _("Inverted:"), _("If the range values are inverted")); + property_add_adjustment (Values, GB_ADJUST_DEFAULT_LABELS); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_vscale_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + + gb_widget_output_bool (data, DrawValue, GTK_SCALE (widget)->draw_value); + + for (i = 0; i < sizeof (GbValuePosValues) / sizeof (GbValuePosValues[0]); + i++) + { + if (GbValuePosValues[i] == GTK_SCALE (widget)->value_pos) + gb_widget_output_choice (data, ValuePos, i, GbValuePosSymbols[i]); + } + gb_widget_output_int (data, Digits, GTK_SCALE (widget)->digits); + + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + gb_widget_output_choice (data, Policy, i, GbPolicySymbols[i]); + } + + gb_widget_output_bool (data, Inverted, GTK_RANGE (widget)->inverted); + + gb_widget_output_adjustment (data, Values, GTK_RANGE (widget)->adjustment, + "adjustment"); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_vscale_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gboolean draw_value, inverted; + gint digits, i; + gchar *valuepos, *policy; + GtkAdjustment *adj; + + draw_value = gb_widget_input_bool (data, DrawValue); + if (data->apply) + { + gtk_scale_set_draw_value (GTK_SCALE (widget), draw_value); + /* Shouldn't really need to do this */ + editor_refresh_widget (widget); + } + + valuepos = gb_widget_input_choice (data, ValuePos); + if (data->apply) + { + for (i = 0; i < sizeof (GbValuePosValues) / sizeof (GbValuePosValues[0]); + i++) + { + if (!strcmp (valuepos, GbValuePosChoices[i]) + || !strcmp (valuepos, GbValuePosSymbols[i])) + { + gtk_scale_set_value_pos (GTK_SCALE (widget), GbValuePosValues[i]); + break; + } + } + } + + digits = gb_widget_input_int (data, Digits); + if (data->apply) + gtk_scale_set_digits (GTK_SCALE (widget), digits); + + policy = gb_widget_input_choice (data, Policy); + if (data->apply) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); + i++) + { + if (!strcmp (policy, GbPolicyChoices[i]) + || !strcmp (policy, GbPolicySymbols[i])) + { + gtk_range_set_update_policy (GTK_RANGE (widget), + GbPolicyValues[i]); + break; + } + } + } + + inverted = gb_widget_input_bool (data, Inverted); + if (data->apply) + { + gtk_range_set_inverted (GTK_RANGE (widget), inverted); + } + + adj = GTK_RANGE (widget)->adjustment; + if (gb_widget_input_adjustment (data, Values, adj, "adjustment")) + { + gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkVScale, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_vscale_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_vscale_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkAdjustment *adj = GTK_RANGE (widget)->adjustment; + gint i; + + if (data->create_widget) + { + source_add (data, + " %s = gtk_vscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (%g, %g, %g, %g, %g, %g)));\n", + data->wname, adj->value, adj->lower, adj->upper, + adj->step_increment, adj->page_increment, adj->page_size); + } + + gb_widget_write_standard_source (widget, data); + + if (!GTK_SCALE (widget)->draw_value) + source_add (data, " gtk_scale_set_draw_value (GTK_SCALE (%s), FALSE);\n", + data->wname); + + if (GTK_SCALE (widget)->value_pos != GTK_POS_TOP) + { + for (i = 0; i < sizeof (GbValuePosValues) / sizeof (GbValuePosValues[0]); + i++) + { + if (GbValuePosValues[i] == GTK_SCALE (widget)->value_pos) + source_add (data, " gtk_scale_set_value_pos (GTK_SCALE (%s), %s);\n", + data->wname, GbValuePosSymbols[i]); + } + } + if (GTK_SCALE (widget)->digits != 1) + source_add (data, " gtk_scale_set_digits (GTK_SCALE (%s), %i);\n", + data->wname, GTK_SCALE (widget)->digits); + + if (GTK_RANGE (widget)->update_policy != GTK_UPDATE_CONTINUOUS) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i + ++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + source_add (data, " gtk_range_set_update_policy (GTK_RANGE (%s), %s);\n", + data->wname, GbPolicySymbols[i]); + } + } + + if (GTK_RANGE (widget)->inverted) + { + source_add (data, + " gtk_range_set_inverted (GTK_RANGE (%s), TRUE);\n", + data->wname); + + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_vscale_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_vscale_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = vscale_xpm; + gbwidget.tooltip = _("Vertical Scale"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_vscale_new; + gbwidget.gb_widget_create_properties = gb_vscale_create_properties; + gbwidget.gb_widget_get_properties = gb_vscale_get_properties; + gbwidget.gb_widget_set_properties = gb_vscale_set_properties; + gbwidget.gb_widget_write_source = gb_vscale_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_vscale_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbvscrollbar.c b/tools/glade/glade/gbwidgets/gbvscrollbar.c new file mode 100644 index 00000000..de852f67 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbvscrollbar.c @@ -0,0 +1,249 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkvscrollbar.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/vscrollbar.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Policy = "VScrollbar|GtkRange::update_policy"; +static gchar *Inverted = "VScrollbar|GtkRange::inverted"; + +static const gchar *Values[] = +{ + "GtkVScrollbar::value", + "GtkVScrollbar::lower", + "GtkVScrollbar::upper", + "GtkVScrollbar::step", + "GtkVScrollbar::page", + "GtkVScrollbar::page_size", +}; + +static const gchar *GbPolicyChoices[] = +{"Continuous", "Discontinuous", "Delayed", + NULL}; +static const gint GbPolicyValues[] = +{ + GTK_UPDATE_CONTINUOUS, + GTK_UPDATE_DISCONTINUOUS, + GTK_UPDATE_DELAYED +}; +static const gchar *GbPolicySymbols[] = +{ + "GTK_UPDATE_CONTINUOUS", + "GTK_UPDATE_DISCONTINUOUS", + "GTK_UPDATE_DELAYED" +}; + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkVScrollbar, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_vscrollbar_new (GbWidgetNewData * data) +{ + return gtk_vscrollbar_new (NULL); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_vscrollbar_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + property_add_choice (Policy, _("Policy:"), + _("The update policy of the scrollbar"), + GbPolicyChoices); + property_add_bool (Inverted, _("Inverted:"), _("If the range values are inverted")); + property_add_adjustment (Values, GB_ADJUST_DEFAULT_LABELS); +} + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_vscrollbar_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gint i; + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + gb_widget_output_choice (data, Policy, i, GbPolicySymbols[i]); + } + + gb_widget_output_bool (data, Inverted, GTK_RANGE (widget)->inverted); + + gb_widget_output_adjustment (data, Values, GTK_RANGE (widget)->adjustment, + "adjustment"); +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_vscrollbar_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gchar *policy; + gint i; + gboolean inverted; + GtkAdjustment *adj; + + policy = gb_widget_input_choice (data, Policy); + if (data->apply) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i + ++) + { + if (!strcmp (policy, GbPolicyChoices[i]) + || !strcmp (policy, GbPolicySymbols[i])) + { + gtk_range_set_update_policy (GTK_RANGE (widget), GbPolicyValues + [i]); + break; + } + } + } + + inverted = gb_widget_input_bool (data, Inverted); + if (data->apply) + { + gtk_range_set_inverted (GTK_RANGE (widget), inverted); + } + + adj = GTK_RANGE (widget)->adjustment; + if (gb_widget_input_adjustment (data, Values, adj, "adjustment")) + { + gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed"); + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkVScrollbar, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_vscrollbar_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_vscrollbar_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + GtkAdjustment *adj = GTK_RANGE (widget)->adjustment; + gint i; + + if (data->create_widget) + { + source_add (data, + " %s = gtk_vscrollbar_new (GTK_ADJUSTMENT (gtk_adjustment_new (%g, %g, %g, %g, %g, %g)));\n", + data->wname, adj->value, adj->lower, adj->upper, + adj->step_increment, adj->page_increment, adj->page_size); + } + + gb_widget_write_standard_source (widget, data); + + if (GTK_RANGE (widget)->update_policy != GTK_UPDATE_CONTINUOUS) + { + for (i = 0; i < sizeof (GbPolicyValues) / sizeof (GbPolicyValues[0]); i + ++) + { + if (GbPolicyValues[i] == GTK_RANGE (widget)->update_policy) + source_add (data, " gtk_range_set_update_policy (GTK_RANGE (%s), %s);\n", + data->wname, GbPolicySymbols[i]); + } + } + + if (GTK_RANGE (widget)->inverted) + { + source_add (data, + " gtk_range_set_inverted (GTK_RANGE (%s), TRUE);\n", + data->wname); + + } +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_vscrollbar_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_vscrollbar_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = vscrollbar_xpm; + gbwidget.tooltip = _("Vertical Scrollbar"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_vscrollbar_new; + gbwidget.gb_widget_create_properties = gb_vscrollbar_create_properties; + gbwidget.gb_widget_get_properties = gb_vscrollbar_get_properties; + gbwidget.gb_widget_set_properties = gb_vscrollbar_set_properties; + gbwidget.gb_widget_write_source = gb_vscrollbar_write_source; +/* + gbwidget.gb_widget_create_popup_menu = gb_vscrollbar_create_popup_menu; + */ + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbvseparator.c b/tools/glade/glade/gbwidgets/gbvseparator.c new file mode 100644 index 00000000..ab068c48 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbvseparator.c @@ -0,0 +1,157 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <gtk/gtkvseparator.h> +#include "../gb.h" + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/vseparator.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + + + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkVSeparator, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget* +gb_vseparator_new(GbWidgetNewData *data) +{ + return gtk_vseparator_new (); +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +/* + static void + gb_vseparator_create_properties(GtkWidget *widget, GbWidgetCreateArgData *data) + { + + } + */ + + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +/* + static void + gb_vseparator_get_properties(GtkWidget *widget, GbWidgetGetArgData *data) + { + + } + */ + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +/* + static void + gb_vseparator_set_properties(GtkWidget *widget, GbWidgetSetArgData *data) + { + + } + */ + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkVSeparator, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_vseparator_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_vseparator_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + if (data->create_widget) + { + source_add (data, " %s = gtk_vseparator_new ();\n", data->wname); + } + gb_widget_write_standard_source (widget, data); +} + + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_vseparator_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_vseparator_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = vseparator_xpm; + gbwidget.tooltip = _("Vertical Separator"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_vseparator_new; +/* + gbwidget.gb_widget_create_properties = gb_vseparator_create_properties; + gbwidget.gb_widget_get_properties = gb_vseparator_get_properties; + gbwidget.gb_widget_set_properties = gb_vseparator_set_properties; + gbwidget.gb_widget_create_popup_menu = gb_vseparator_create_popup_menu; + */ + gbwidget.gb_widget_write_source = gb_vseparator_write_source; + + return &gbwidget; +} diff --git a/tools/glade/glade/gbwidgets/gbwindow.c b/tools/glade/glade/gbwidgets/gbwindow.c new file mode 100644 index 00000000..616825a1 --- /dev/null +++ b/tools/glade/glade/gbwidgets/gbwindow.c @@ -0,0 +1,1246 @@ + +/* Gtk+ User Interface Builder + * Copyright (C) 1998 Damon Chaplin + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <string.h> +#include <gtk/gtkspinbutton.h> +#include <gtk/gtktogglebutton.h> +#include <gtk/gtkwindow.h> +#include "../gb.h" + +/* This file includes some common routines for standard window properties + such as title, type, position, default width & height, shrink, grow, + auto_shrink & icon. Other widgets can call these functions just + by supplying the property names. Note that for most properties we use the + widget's own property names as keys when storing values in the objects + datalist, but for default width & height we use the windows own names since + we need to access the values in the on_toggle_default_xx() callbacks. */ + +/* Include the 21x21 icon pixmap for this widget, to be used in the palette */ +#include "../graphics/window.xpm" + +/* + * This is the GbWidget struct for this widget (see ../gbwidget.h). + * It is initialized in the init() function at the end of this file + */ +static GbWidget gbwidget; + +static gchar *Title = "GtkWindow::title"; +static gchar *Type = "GtkWindow::type"; +static gchar *Position = "GtkWindow::window_position"; +static gchar *Modal = "GtkWindow::modal"; +static gchar *DefaultWidth = "GtkWindow::default_width"; +static gchar *DefaultHeight = "GtkWindow::default_height"; +static gchar *IconName = "GtkWindow::icon_name"; +static gchar *FocusOnMap = "GtkWindow::focus_on_map"; +static gchar *Resizable = "GtkWindow::resizable"; +static gchar *DestroyWithParent = "GtkWindow::destroy_with_parent"; +static gchar *Icon = "GtkWindow::icon"; + +static gchar *Role = "GtkWindow::role"; +static gchar *TypeHint = "GtkWindow::type_hint"; +static gchar *SkipTaskbar = "GtkWindow::skip_taskbar_hint"; +static gchar *SkipPager = "GtkWindow::skip_pager_hint"; +static gchar *Decorated = "GtkWindow::decorated"; +static gchar *Gravity = "GtkWindow::gravity"; +static gchar *Urgency = "GtkWindow::urgency_hint"; + +/* These are deprecated. We don't show them any more. */ +static gchar *Shrink = "GtkWindow::allow_shrink"; +static gchar *Grow = "GtkWindow::allow_grow"; + + +/* The key to hold the icon filename. */ +static gchar *GladeWindowIconKey = "GladeWindowIconKey"; + +static const gchar *GbTypeChoices[] = +{"Top Level", "Popup", NULL}; +static const gint GbTypeValues[] = +{ + GTK_WINDOW_TOPLEVEL, + GTK_WINDOW_POPUP +}; +static const gchar *GbTypeSymbols[] = +{ + "GTK_WINDOW_TOPLEVEL", + "GTK_WINDOW_POPUP" +}; + +/* If you change these arrays be sure to make sure + GLADE_TYPE_HINT_DIALOG_INDEX is up to date in gb.h. */ +static const gchar *GbTypeHintChoices[] = +{"Normal", "Dialog", "Menu", "Toolbar", "Splash Screen", "Utility", + "Dock", "Desktop", NULL}; +static const gint GbTypeHintValues[] = +{ + GDK_WINDOW_TYPE_HINT_NORMAL, + GDK_WINDOW_TYPE_HINT_DIALOG, + GDK_WINDOW_TYPE_HINT_MENU, + GDK_WINDOW_TYPE_HINT_TOOLBAR, + GDK_WINDOW_TYPE_HINT_SPLASHSCREEN, + GDK_WINDOW_TYPE_HINT_UTILITY, + GDK_WINDOW_TYPE_HINT_DOCK, + GDK_WINDOW_TYPE_HINT_DESKTOP +}; +static const gchar *GbTypeHintSymbols[] = +{ + "GDK_WINDOW_TYPE_HINT_NORMAL", + "GDK_WINDOW_TYPE_HINT_DIALOG", + "GDK_WINDOW_TYPE_HINT_MENU", + "GDK_WINDOW_TYPE_HINT_TOOLBAR", + "GDK_WINDOW_TYPE_HINT_SPLASHSCREEN", + "GDK_WINDOW_TYPE_HINT_UTILITY", + "GDK_WINDOW_TYPE_HINT_DOCK", + "GDK_WINDOW_TYPE_HINT_DESKTOP" +}; + +static const gchar *GbPositionChoices[] = +{"None", "Center", "Mouse", "Center Always", "Center on Parent", NULL}; +static const gint GbPositionValues[] = +{ + GTK_WIN_POS_NONE, + GTK_WIN_POS_CENTER, + GTK_WIN_POS_MOUSE, + GTK_WIN_POS_CENTER_ALWAYS, + GTK_WIN_POS_CENTER_ON_PARENT +}; +static const gchar *GbPositionSymbols[] = +{ + "GTK_WIN_POS_NONE", + "GTK_WIN_POS_CENTER", + "GTK_WIN_POS_MOUSE", + "GTK_WIN_POS_CENTER_ALWAYS", + "GTK_WIN_POS_CENTER_ON_PARENT" +}; + +static const gchar *GbGravityChoices[] = +{"North West", "North", "North East", "West", "Center", "East", + "South West", "South", "South East", "Static", NULL}; +static const gint GbGravityValues[] = +{ + GDK_GRAVITY_NORTH_WEST, + GDK_GRAVITY_NORTH, + GDK_GRAVITY_NORTH_EAST, + GDK_GRAVITY_WEST, + GDK_GRAVITY_CENTER, + GDK_GRAVITY_EAST, + GDK_GRAVITY_SOUTH_WEST, + GDK_GRAVITY_SOUTH, + GDK_GRAVITY_SOUTH_EAST, + GDK_GRAVITY_STATIC +}; +static const gchar *GbGravitySymbols[] = +{ + "GDK_GRAVITY_NORTH_WEST", + "GDK_GRAVITY_NORTH", + "GDK_GRAVITY_NORTH_EAST", + "GDK_GRAVITY_WEST", + "GDK_GRAVITY_CENTER", + "GDK_GRAVITY_EAST", + "GDK_GRAVITY_SOUTH_WEST", + "GDK_GRAVITY_SOUTH", + "GDK_GRAVITY_SOUTH_EAST", + "GDK_GRAVITY_STATIC" +}; + + +static void on_toggle_default_width (GtkWidget * widget, gpointer value); +static void on_toggle_default_height (GtkWidget * widget, gpointer value); + +/****** + * NOTE: To use these functions you need to uncomment them AND add a pointer + * to the function in the GbWidget struct at the end of this file. + ******/ + +/* + * Creates a new GtkWidget of class GtkWindow, performing any specialized + * initialization needed for the widget to work correctly in this environment. + * If a dialog box is used to initialize the widget, return NULL from this + * function, and call data->callback with your new widget when it is done. + * If the widget needs a special destroy handler, add a signal here. + */ +GtkWidget * +gb_window_new (GbWidgetNewData * data) +{ + GtkWidget *new_widget, *placeholder; + + new_widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (new_widget), data->name); + gtk_window_set_policy (GTK_WINDOW (new_widget), FALSE, TRUE, FALSE); + gtk_signal_connect (GTK_OBJECT (new_widget), "delete_event", + GTK_SIGNAL_FUNC (editor_close_window), NULL); + + /* We need to size the placeholder or the window is very small. */ + if (data->action != GB_LOADING) + { + placeholder = editor_new_placeholder (); + gtk_widget_set_usize (placeholder, 400, 300); + gtk_container_add (GTK_CONTAINER (new_widget), placeholder); + } + + return new_widget; +} + + + +/* + * Creates the components needed to edit the extra properties of this widget. + */ +static void +gb_window_create_properties (GtkWidget * widget, GbWidgetCreateArgData * data) +{ + gb_window_create_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, NULL, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + +void +gb_window_create_standard_properties (GtkWidget * widget, + GbWidgetCreateArgData * data, + gchar *title_p, + gchar *type_p, + gchar *position_p, + gchar *modal_p, + gchar *default_width_p, + gchar *default_height_p, + gchar *shrink_p, + gchar *grow_p, + gchar *auto_shrink_p, + gchar *icon_name_p, + gchar *focus_on_map_p, + gchar *resizable_p, + gchar *destroy_with_parent_p, + gchar *icon_p, + gchar *role_p, + gchar *type_hint_p, + gchar *skip_taskbar_p, + gchar *skip_pager_p, + gchar *decorated_p, + gchar *gravity_p, + gchar *urgency_p) +{ + if (title_p) + property_add_string (title_p, _("Title:"), _("The title of the window")); + + if (type_p) + property_add_choice (type_p, _("Type:"), _("The type of the window"), + GbTypeChoices); + + if (type_hint_p) + property_add_choice (type_hint_p, _("Type Hint:"), + _("Tells the window manager how to treat the window"), + GbTypeHintChoices); + + if (position_p) + property_add_choice (position_p, _("Position:"), + _("The initial position of the window"), + GbPositionChoices); + + if (modal_p) + property_add_bool (modal_p, _("Modal:"), _("If the window is modal")); + + if (default_width_p && default_height_p) + { + property_add_optional_int_range (default_width_p, + _("Default Width:"), + _("The default width of the window"), + 0, 10000, 1, 10, 1, + on_toggle_default_width); + property_add_optional_int_range (default_height_p, + _("Default Height:"), + _("The default height of the window"), + 0, 10000, 1, 10, 1, + on_toggle_default_height); + } + + if (resizable_p) + property_add_bool (resizable_p, _("Resizable:"), + _("If the window can be resized")); + +#if 0 + /* These are deprecated. */ + if (shrink_p && grow_p) + { + property_add_bool (shrink_p, _("Shrink:"), + _("If the window can be shrunk")); + property_add_bool (grow_p, _("Grow:"), + _("If the window can be enlarged")); + } +#endif + + if (destroy_with_parent_p) + property_add_bool (destroy_with_parent_p, _("Auto-Destroy:"), + _("If the window is destroyed when its transient parent is destroyed")); + + if (icon_p) + property_add_filename (icon_p, _("Icon:"), + _("The icon for this window")); + + if (icon_name_p) + property_add_named_icon (icon_name_p, _("Named Icon:"), + _("The named icon to use")); + + if (role_p) + property_add_string (role_p, _("Role:"), _("A unique identifier for the window to be used when restoring a session")); + + if (decorated_p) + property_add_bool (decorated_p, _("Decorated:"), + _("If the window should be decorated by the window manager")); + + if (skip_taskbar_p) + property_add_bool (skip_taskbar_p, _("Skip Taskbar:"), + _("If the window should not appear in the task bar")); + + if (skip_pager_p) + property_add_bool (skip_pager_p, _("Skip Pager:"), + _("If the window should not appear in the pager")); + + if (gravity_p) + property_add_choice (gravity_p, _("Gravity:"), + _("The reference point to use when the window coordinates are set"), + GbGravityChoices); + + if (focus_on_map_p) + property_add_bool (focus_on_map_p, _("Focus On Map:"), _("If the window should receive the input focus when it is mapped")); + + if (urgency_p) + property_add_bool (urgency_p, _("Urgency Hint:"), _("If the window should be brought to the user's attention")); +} + + +static void +on_toggle_default_width (GtkWidget * widget, gpointer value) +{ + GtkWidget *property_widget; + gboolean value_set; + gint width, height; + + property_widget = property_get_widget (); + if (property_widget == NULL) + return; + + value_set = GTK_TOGGLE_BUTTON (widget)->active ? TRUE : FALSE; + gtk_widget_set_sensitive (GTK_WIDGET (value), value_set); + + if (value_set) + { + width = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (value)); + gtk_object_set_data (GTK_OBJECT (property_widget), DefaultWidth, + GINT_TO_POINTER (width)); + } + else + { + width = -1; + gtk_object_set_data (GTK_OBJECT (property_widget), DefaultWidth, + NULL); + } + + height = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (property_widget), + DefaultHeight)); + gtk_window_set_default_size (GTK_WINDOW (property_widget), + width, height != 0 ? height : -1); +} + + +static void +on_toggle_default_height (GtkWidget * widget, gpointer value) +{ + GtkWidget *property_widget; + gboolean value_set; + gint width, height; + + property_widget = property_get_widget (); + if (property_widget == NULL) + return; + + value_set = GTK_TOGGLE_BUTTON (widget)->active ? TRUE : FALSE; + gtk_widget_set_sensitive (GTK_WIDGET (value), value_set); + + if (value_set) + { + height = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (value)); + gtk_object_set_data (GTK_OBJECT (property_widget), DefaultHeight, + GINT_TO_POINTER (height)); + } + else + { + height = -1; + gtk_object_set_data (GTK_OBJECT (property_widget), DefaultHeight, + NULL); + } + + width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (property_widget), + DefaultWidth)); + gtk_window_set_default_size (GTK_WINDOW (property_widget), + width != 0 ? width : -1, height); +} + + +/* + * Gets the properties of the widget. This is used for both displaying the + * properties in the property editor, and also for saving the properties. + */ +static void +gb_window_get_properties (GtkWidget * widget, GbWidgetGetArgData * data) +{ + gb_window_get_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, NULL, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + +void +gb_window_get_standard_properties (GtkWidget * widget, + GbWidgetGetArgData * data, + gchar *title_p, + gchar *type_p, + gchar *position_p, + gchar *modal_p, + gchar *default_width_p, + gchar *default_height_p, + gchar *shrink_p, + gchar *grow_p, + gchar *auto_shrink_p, + gchar *icon_name_p, + gchar *focus_on_map_p, + gchar *resizable_p, + gchar *destroy_with_parent_p, + gchar *icon_p, + gchar *role_p, + gchar *type_hint_p, + gchar *skip_taskbar_p, + gchar *skip_pager_p, + gchar *decorated_p, + gchar *gravity_p, + gchar *urgency_p) +{ + gint type, position, default_width, default_height, type_hint, gravity; + + if (title_p) + gb_widget_output_translatable_string (data, title_p, + GTK_WINDOW (widget)->title); + + /* The type is stored in the object datalist as we can't change it after the + window is realized. It will default to 0, which is OK. */ + if (type_p) + { + type = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + type_p)); + gb_widget_output_choice (data, type_p, type, GbTypeSymbols[type]); + } + + /* The position is stored in the object datalist so that it doesn't affect + the displaying of the window within Glade. It will default to 0, i.e. + GTK_WIN_POS_NONE, which is OK. */ + if (position_p) + { + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + position_p)); + gb_widget_output_choice (data, position_p, position, + GbPositionSymbols[position]); + } + + if (modal_p) + { + gb_widget_output_bool (data, modal_p, + gtk_object_get_data (GTK_OBJECT (widget), modal_p) + != NULL ? TRUE : FALSE); + } + + if (default_width_p && default_height_p) + { + default_width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + DefaultWidth)); + gb_widget_output_optional_int (data, default_width_p, default_width, + default_width != 0 ? TRUE : FALSE); + + default_height = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + DefaultHeight)); + gb_widget_output_optional_int (data, default_height_p, default_height, + default_height != 0 ? TRUE : FALSE); + } + +#if 0 + /* These are deprecated. */ + if (grow_p && shrink_p) + { + gb_widget_output_bool (data, grow_p, + GTK_WINDOW (widget)->allow_grow); + gb_widget_output_bool (data, shrink_p, + GTK_WINDOW (widget)->allow_shrink); + } +#endif + + if (resizable_p) + gb_widget_output_bool (data, resizable_p, + gtk_window_get_resizable (GTK_WINDOW (widget))); + + if (destroy_with_parent_p) + gb_widget_output_bool (data, destroy_with_parent_p, + gtk_window_get_destroy_with_parent (GTK_WINDOW (widget))); + + if (icon_p) + gb_widget_output_pixmap_filename (data, icon_p, + gtk_object_get_data (GTK_OBJECT (widget), + GladeWindowIconKey)); + + if (icon_name_p) + gb_widget_output_named_icon (data, icon_name_p, + gtk_window_get_icon_name (GTK_WINDOW (widget))); + + if (role_p) + gb_widget_output_string (data, role_p, + gtk_window_get_role (GTK_WINDOW (widget))); + + /* We can't set the decorated property as that may make it awkward to + edit. The default (i.e. NULL value) is TRUE. */ + if (decorated_p) + gb_widget_output_bool (data, decorated_p, + gtk_object_get_data (GTK_OBJECT (widget), decorated_p) + == NULL ? TRUE : FALSE); + + /* The default (i.e. NULL value) is FALSE. */ + if (skip_taskbar_p) + gb_widget_output_bool (data, skip_taskbar_p, + gtk_object_get_data (GTK_OBJECT (widget), skip_taskbar_p) + != NULL ? TRUE : FALSE); + + /* The default (i.e. NULL value) is FALSE. */ + if (skip_pager_p) + gb_widget_output_bool (data, skip_pager_p, + gtk_object_get_data (GTK_OBJECT (widget), skip_pager_p) + != NULL ? TRUE : FALSE); + + /* We can't set the type hint within Glade as it may make the window + awkward to edit. It defaults to 0 which is GDK_WINDOW_TYPE_HINT_NORMAL + which is OK. */ + if (type_hint_p) + { + type_hint = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + type_hint_p)); + gb_widget_output_choice (data, type_hint_p, type_hint, + GbTypeHintSymbols[type_hint]); + } + + /* I'm not sure if we should set the gravity or not. + It defaults to 0, which is GDK_GRAVITY_NORTH_WEST which is OK. */ + if (gravity_p) + { + gravity = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + gravity_p)); + gb_widget_output_choice (data, gravity_p, gravity, + GbGravitySymbols[gravity]); + } + + if (focus_on_map_p) + { + gb_widget_output_bool (data, focus_on_map_p, + gtk_object_get_data (GTK_OBJECT (widget), focus_on_map_p) == NULL ? TRUE : FALSE); + } + + if (urgency_p) + { + gb_widget_output_bool (data, urgency_p, + gtk_object_get_data (GTK_OBJECT (widget), urgency_p) != NULL ? TRUE : FALSE); + } +} + + + +/* + * Sets the properties of the widget. This is used for both applying the + * properties changed in the property editor, and also for loading. + */ +static void +gb_window_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) +{ + gb_window_set_standard_properties (widget, data, + Title, Type, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, NULL, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + +static void +gb_window_clear_pixmap (GtkWidget *widget, GladeProject *project) +{ + gchar *old_icon; + + /* Remove the old icon stored in the widget data, and remove the + pixmap from the project, if necessary. */ + old_icon = gtk_object_get_data (GTK_OBJECT (widget), GladeWindowIconKey); + glade_project_remove_pixmap (project, old_icon); + + gtk_object_set_data (GTK_OBJECT (widget), GladeWindowIconKey, NULL); +} + + +void +gb_window_set_standard_properties (GtkWidget * widget, + GbWidgetSetArgData * data, + gchar *title_p, + gchar *type_p, + gchar *position_p, + gchar *modal_p, + gchar *default_width_p, + gchar *default_height_p, + gchar *shrink_p, + gchar *grow_p, + gchar *auto_shrink_p, + gchar *icon_name_p, + gchar *focus_on_map_p, + gchar *resizable_p, + gchar *destroy_with_parent_p, + gchar *icon_p, + gchar *role_p, + gchar *type_hint_p, + gchar *skip_taskbar_p, + gchar *skip_pager_p, + gchar *decorated_p, + gchar *gravity_p, + gchar *urgency_p) +{ + gchar *title, *type, *position, *role; + gint default_width, default_height, i; + gboolean modal, apply_default_width, apply_default_height; + gboolean resizable, destroy_with_parent; + gboolean decorated, skip_taskbar, skip_pager; + gchar *type_hint, *gravity; + + if (title_p) + { + title = gb_widget_input_string (data, title_p); + if (data->apply) + gtk_window_set_title (GTK_WINDOW (widget), title); + } + + if (type_p) + { + type = gb_widget_input_choice (data, type_p); + if (data->apply) + { + for (i = 0; i < sizeof (GbTypeValues) / sizeof (GbTypeValues[0]); + i++) + { + if (!strcmp (type, GbTypeChoices[i]) + || !strcmp (type, GbTypeSymbols[i])) + { + gtk_object_set_data (GTK_OBJECT (widget), type_p, + GINT_TO_POINTER (i)); + break; + } + } + } + } + + if (position_p) + { + position = gb_widget_input_choice (data, position_p); + if (data->apply) + { + for (i = 0; + i < sizeof (GbPositionValues) / sizeof (GbPositionValues[0]); + i++) + { + if (!strcmp (position, GbPositionChoices[i]) + || !strcmp (position, GbPositionSymbols[i])) + { + gtk_object_set_data (GTK_OBJECT (widget), position_p, + GINT_TO_POINTER (i)); + break; + } + } + } + } + + if (modal_p) + { + modal = gb_widget_input_bool (data, modal_p); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), modal_p, + modal ? "TRUE" : NULL); + } + } + + if (default_width_p && default_height_p) + { + default_width = gb_widget_input_int (data, default_width_p); + apply_default_width = data->apply; + if (apply_default_width) + { + gtk_object_set_data (GTK_OBJECT (widget), DefaultWidth, + GINT_TO_POINTER (default_width)); + } + + default_height = gb_widget_input_int (data, default_height_p); + apply_default_height = data->apply; + if (apply_default_height) + { + gtk_object_set_data (GTK_OBJECT (widget), DefaultHeight, + GINT_TO_POINTER (default_height)); + } + + if (apply_default_width || apply_default_height) + { + if (!apply_default_width) + default_width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + DefaultWidth)); + if (!apply_default_height) + default_height = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + DefaultHeight)); + gtk_window_set_default_size (GTK_WINDOW (widget), + default_width ? default_width : -1, + default_height ? default_height : -1); + } + } + +#if 0 + /* These are deprecated. */ + if (shrink_p && grow_p) + { + shrink = gb_widget_input_bool (data, shrink_p); + if (data->apply) + set_policy = TRUE; + else + shrink = GTK_WINDOW (widget)->allow_shrink; + + grow = gb_widget_input_bool (data, grow_p); + if (data->apply) + set_policy = TRUE; + else + grow = GTK_WINDOW (widget)->allow_grow; + + if (set_policy) + gtk_window_set_policy (GTK_WINDOW (widget), shrink, grow, FALSE); + } +#endif + + if (resizable_p) + { + resizable = gb_widget_input_bool (data, resizable_p); + if (data->apply) + gtk_window_set_resizable (GTK_WINDOW (widget), resizable); + } + + if (destroy_with_parent_p) + { + destroy_with_parent = gb_widget_input_bool (data, destroy_with_parent_p); + if (data->apply) + gtk_window_set_destroy_with_parent (GTK_WINDOW (widget), + destroy_with_parent); + } + + if (icon_p) + { + char *filename = gb_widget_input_pixmap_filename (data, icon_p); + if (data->apply) + { + if (filename && filename[0] == '\0') + filename = NULL; + + /* Remove the old icon stored in the widget data, and remove the + pixmap from the project, if necessary. */ + gb_window_clear_pixmap (widget, data->project); + + gtk_object_set_data_full (GTK_OBJECT (widget), GladeWindowIconKey, + g_strdup (filename), + filename ? g_free : NULL); + + glade_project_add_pixmap (data->project, filename); + + if (filename) + { + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (filename, NULL); + gtk_window_set_icon (GTK_WINDOW (widget), pixbuf); + if (pixbuf) + gdk_pixbuf_unref (pixbuf); + } + + if (property_get_widget () == widget && icon_name_p) + { + /* Clear the IconName property. */ + property_set_auto_apply (FALSE); + property_set_named_icon (icon_name_p, NULL); + property_set_auto_apply (TRUE); + } + } + if (data->action == GB_LOADING) + g_free (filename); + } + + if (icon_name_p) + { + gchar *icon_name = gb_widget_input_named_icon (data, icon_name_p); + + if (data->apply) + { + /* Clear any stock icon or icon from a file. */ + gb_window_clear_pixmap (widget, data->project); + + gtk_window_set_icon (GTK_WINDOW (widget), NULL); + gtk_window_set_icon_name (GTK_WINDOW (widget), icon_name); + + if (property_get_widget () == widget && icon_p) + { + /* Clear the Icon property. */ + property_set_auto_apply (FALSE); + property_set_filename (icon_p, NULL); + property_set_auto_apply (TRUE); + } + } + } + + if (role_p) + { + role = gb_widget_input_string (data, role_p); + if (data->apply) + gtk_window_set_role (GTK_WINDOW (widget), role); + } + + if (decorated_p) + { + decorated = gb_widget_input_bool (data, decorated_p); + if (data->apply) + gtk_object_set_data (GTK_OBJECT (widget), decorated_p, + decorated ? NULL : "FALSE"); + } + + if (skip_taskbar_p) + { + skip_taskbar = gb_widget_input_bool (data, skip_taskbar_p); + if (data->apply) + gtk_object_set_data (GTK_OBJECT (widget), skip_taskbar_p, + skip_taskbar ? "TRUE" : NULL); + } + + if (skip_pager_p) + { + skip_pager = gb_widget_input_bool (data, skip_pager_p); + if (data->apply) + gtk_object_set_data (GTK_OBJECT (widget), skip_pager_p, + skip_pager ? "TRUE" : NULL); + } + + if (type_hint_p) + { + type_hint = gb_widget_input_choice (data, type_hint_p); + if (data->apply) + { + for (i = 0; + i < sizeof (GbTypeHintValues) / sizeof (GbTypeHintValues[0]); + i++) + { + if (!strcmp (type_hint, GbTypeHintChoices[i]) + || !strcmp (type_hint, GbTypeHintSymbols[i])) + { + gtk_object_set_data (GTK_OBJECT (widget), type_hint_p, + GINT_TO_POINTER (i)); + break; + } + } + } + } + + if (gravity_p) + { + gravity = gb_widget_input_choice (data, gravity_p); + if (data->apply) + { + for (i = 0; + i < sizeof (GbGravityValues) / sizeof (GbGravityValues[0]); + i++) + { + if (!strcmp (gravity, GbGravityChoices[i]) + || !strcmp (gravity, GbGravitySymbols[i])) + { + gtk_object_set_data (GTK_OBJECT (widget), gravity_p, + GINT_TO_POINTER (i)); + break; + } + } + } + } + + if (focus_on_map_p) + { + gboolean focus_on_map = gb_widget_input_bool (data, focus_on_map_p); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), focus_on_map_p, + focus_on_map ? NULL : "FALSE"); + } + } + + if (urgency_p) + { + gboolean urgency = gb_widget_input_bool (data, urgency_p); + if (data->apply) + { + gtk_object_set_data (GTK_OBJECT (widget), urgency_p, + urgency ? "TRUE" : NULL); + } + } +} + + + +/* + * Adds menu items to a context menu which is just about to appear! + * Add commands to aid in editing a GtkWindow, with signals pointing to + * other functions in this file. + */ +/* + static void + gb_window_create_popup_menu(GtkWidget *widget, GbWidgetCreateMenuData *data) + { + + } + */ + + + +/* + * Writes the source code needed to create this widget. + * You have to output everything necessary to create the widget here, though + * there are some convenience functions to help. + */ +static void +gb_window_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) +{ + gint type; + + if (data->create_widget) + { + type = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Type)); + source_add (data, " %s = gtk_window_new (%s);\n", data->wname, + GbTypeSymbols[type]); + } + + gb_widget_write_standard_source (widget, data); + + /* The type is already set above, so we pass NULL to skip it. */ + gb_window_write_standard_source (widget, data, + Title, NULL, Position, Modal, + DefaultWidth, DefaultHeight, + Shrink, Grow, NULL, + IconName, FocusOnMap, + Resizable, DestroyWithParent, Icon, + Role, TypeHint, SkipTaskbar, + SkipPager, Decorated, Gravity, Urgency); +} + + +void +gb_window_write_standard_source (GtkWidget * widget, + GbWidgetWriteSourceData * data, + gchar *title_p, + gchar *type_p, + gchar *position_p, + gchar *modal_p, + gchar *default_width_p, + gchar *default_height_p, + gchar *shrink_p, + gchar *grow_p, + gchar *auto_shrink_p, + gchar *icon_name_p, + gchar *focus_on_map_p, + gchar *resizable_p, + gchar *destroy_with_parent_p, + gchar *icon_p, + gchar *role_p, + gchar *type_hint_p, + gchar *skip_taskbar_p, + gchar *skip_pager_p, + gchar *decorated_p, + gchar *gravity_p, + gchar *urgency_p) +{ + gint type, position, default_width, default_height, type_hint, gravity; + gboolean translatable, context; + gchar *comments; + + if (title_p) + { + if (GTK_WINDOW (widget)->title + && strlen (GTK_WINDOW (widget)->title) > 0) + { + glade_util_get_translation_properties (widget, title_p, + &translatable, + &comments, &context); + source_add_translator_comments (data, translatable, comments); + + source_add (data, " gtk_window_set_title (GTK_WINDOW (%s), %s);\n", + data->wname, + source_make_string_full (GTK_WINDOW (widget)->title, + data->use_gettext && translatable, + context)); + } + } + + if (type_p) + { + type = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + type_p)); + if (type != GTK_WINDOW_TOPLEVEL) + { + /* Note: there is no gtk_window_set_type () */ + source_add (data, " GTK_WINDOW (%s)->type = %s;\n", + data->wname, GbTypeSymbols[type]); + } + } + + if (position_p) + { + position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + position_p)); + if (GbPositionValues[position] != GTK_WIN_POS_NONE) + { + source_add (data, + " gtk_window_set_position (GTK_WINDOW (%s), %s);\n", + data->wname, GbPositionSymbols[position]); + } + } + + if (modal_p) + { + if (gtk_object_get_data (GTK_OBJECT (widget), modal_p)) + { + source_add (data, + " gtk_window_set_modal (GTK_WINDOW (%s), TRUE);\n", + data->wname); + } + } + + if (default_width_p && default_height_p) + { + default_width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + DefaultWidth)); + default_height = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + DefaultHeight)); + if (default_width || default_height ) + { + source_add (data, + " gtk_window_set_default_size (GTK_WINDOW (%s), %i, %i);\n", + data->wname, + default_width ? default_width : -1, + default_height ? default_height : -1); + } + } + +#if 0 + if (shrink_p && grow_p) + { + if (GTK_WINDOW (widget)->allow_grow != TRUE + || GTK_WINDOW (widget)->allow_shrink != FALSE) + source_add (data, + " gtk_window_set_policy (GTK_WINDOW (%s), %s, %s, %s);\n", + data->wname, + GTK_WINDOW (widget)->allow_shrink ? "TRUE" : "FALSE", + GTK_WINDOW (widget)->allow_grow ? "TRUE" : "FALSE", + "FALSE"); + } +#endif + + if (resizable_p) + { + if (!gtk_window_get_resizable (GTK_WINDOW (widget))) + source_add (data, + " gtk_window_set_resizable (GTK_WINDOW (%s), FALSE);\n", + data->wname); + } + + if (destroy_with_parent_p) + { + if (gtk_window_get_destroy_with_parent (GTK_WINDOW (widget))) + source_add (data, + " gtk_window_set_destroy_with_parent (GTK_WINDOW (%s), TRUE);\n", + data->wname); + } + + if (icon_p) + { + gchar *filename = gtk_object_get_data (GTK_OBJECT (widget), GladeWindowIconKey); + if (filename && *filename) + { + char *pixbuf_name = g_strdup_printf ("%s_icon_pixbuf", data->wname); + + source_add_decl (data, " GdkPixbuf *%s;\n", pixbuf_name); + source_create_pixbuf (data, pixbuf_name, filename); + source_add (data, + " if (%s)\n" + " {\n" + " gtk_window_set_icon (GTK_WINDOW (%s), %s);\n" + " gdk_pixbuf_unref (%s);\n" + " }\n", + pixbuf_name, + data->wname, pixbuf_name, + pixbuf_name); + + g_free (pixbuf_name); + } + } + + if (icon_p) + { + const gchar *icon_name = gtk_window_get_icon_name (GTK_WINDOW (widget)); + if (icon_name && *icon_name) + { + source_add (data, + " gtk_window_set_icon_name (GTK_WINDOW (%s), \"%s\");\n", + data->wname, icon_name); + } + } + + if (role_p) + { + const gchar *role = gtk_window_get_role (GTK_WINDOW (widget)); + + /* The role isn't translated. */ + if (role && *role) + source_add (data, " gtk_window_set_role (GTK_WINDOW (%s), %s);\n", + data->wname, + source_make_string (role, FALSE)); + } + + if (decorated_p) + { + if (gtk_object_get_data (GTK_OBJECT (widget), decorated_p) != NULL) + { + source_add (data, " gtk_window_set_decorated (GTK_WINDOW (%s), FALSE);\n", + data->wname); + } + } + + if (skip_taskbar_p) + { + if (gtk_object_get_data (GTK_OBJECT (widget), skip_taskbar_p) != NULL) + { + source_add (data, " gtk_window_set_skip_taskbar_hint (GTK_WINDOW (%s), TRUE);\n", + data->wname); + } + } + + if (skip_pager_p) + { + if (gtk_object_get_data (GTK_OBJECT (widget), skip_pager_p) != NULL) + { + source_add (data, " gtk_window_set_skip_pager_hint (GTK_WINDOW (%s), TRUE);\n", + data->wname); + } + } + + if (type_hint_p) + { + type_hint = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + type_hint_p)); + if (GbTypeHintValues[type_hint] != GDK_WINDOW_TYPE_HINT_NORMAL) + { + source_add (data, " gtk_window_set_type_hint (GTK_WINDOW (%s), %s);\n", + data->wname, GbTypeHintSymbols[type_hint]); + } + + } + + if (gravity_p) + { + gravity = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), + gravity_p)); + if (GbGravityValues[gravity] != GDK_GRAVITY_NORTH_WEST) + { + source_add (data, " gtk_window_set_gravity (GTK_WINDOW (%s), %s);\n", + data->wname, GbGravitySymbols[gravity]); + } + } + + if (focus_on_map_p) + { + if (gtk_object_get_data (GTK_OBJECT (widget), focus_on_map_p)) + { + source_add (data, + " gtk_window_set_focus_on_map (GTK_WINDOW (%s), FALSE);\n", + data->wname); + } + } + + if (urgency_p) + { + if (gtk_object_get_data (GTK_OBJECT (widget), urgency_p)) + { + source_add (data, + " gtk_window_set_urgency_hint (GTK_WINDOW (%s), TRUE);\n", + data->wname); + } + } +} + + +void +gb_window_destroy (GtkWidget * widget, GbWidgetDestroyData * data) +{ + gb_window_clear_pixmap (widget, data->project); +} + + +/* + * Initializes the GbWidget structure. + * I've placed this at the end of the file so we don't have to include + * declarations of all the functions. + */ +GbWidget * +gb_window_init () +{ + /* Initialise the GTK type */ + volatile GtkType type; + type = gtk_window_get_type (); + + /* Initialize the GbWidget structure */ + gb_widget_init_struct (&gbwidget); + + /* Fill in the pixmap struct & tooltip */ + gbwidget.pixmap_struct = window_xpm; + gbwidget.tooltip = _("Window"); + + /* Fill in any functions that this GbWidget has */ + gbwidget.gb_widget_new = gb_window_new; + gbwidget.gb_widget_create_properties = gb_window_create_properties; + gbwidget.gb_widget_get_properties = gb_window_get_properties; + gbwidget.gb_widget_set_properties = gb_window_set_properties; + gbwidget.gb_widget_write_source = gb_window_write_source; + gbwidget.gb_widget_destroy = gb_window_destroy; +/* + gbwidget.gb_widget_create_popup_menu = gb_window_create_popup_menu; + */ + + return &gbwidget; +} |