diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/misc/ChangeLog | 8 | ||||
-rw-r--r-- | widgets/misc/Makefile.am | 21 | ||||
-rw-r--r-- | widgets/misc/e-multi-config-dialog.c | 376 | ||||
-rw-r--r-- | widgets/misc/e-multi-config-dialog.h | 74 | ||||
-rw-r--r-- | widgets/misc/test-multi-config-dialog.c | 88 |
5 files changed, 563 insertions, 4 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index 670f34c6aa..aa93e38678 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,11 @@ +2002-03-05 Ettore Perazzoli <ettore@ximian.com> + + * test-multi-config-dialog.c: New. + * test-multi-config-dialog.h: New. + + * e-multi-config-dialog.c: New. + * e-multi-config-dialog.h: New. + 2002-02-24 Chris Toshok <toshok@ximian.com> * e-filter-bar.c (init): preserve behavior - hook search_activated diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 61b26a0327..5d0a474138 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -39,6 +39,8 @@ libemiscwidgets_a_SOURCES = \ e-map.h \ e-messagebox.c \ e-messagebox.h \ + e-multi-config-dialog.c \ + e-multi-config-dialog.h \ e-search-bar.c \ e-search-bar.h \ e-title-bar.c \ @@ -46,10 +48,11 @@ libemiscwidgets_a_SOURCES = \ e-url-entry.c \ e-url-entry.h -noinst_PROGRAMS = \ - test-calendar \ - test-dateedit \ - test-dropdown-button \ +noinst_PROGRAMS = \ + test-calendar \ + test-dateedit \ + test-dropdown-button \ + test-multi-config-dialog \ test-title-bar # test-calendar @@ -81,6 +84,15 @@ test_dropdown_button_LDADD = \ ./libemiscwidgets.a \ $(GNOME_FULL_LIBS) +# test-multi-config-dialog + +test_multi_config_dialog_SOURCES = \ + test-multi-config-dialog.c + +test_multi_config_dialog_LDADD = \ + ./libemiscwidgets.a \ + $(GNOME_FULL_LIBS) + # test-title-bar test_title_bar_SOURCES = \ @@ -90,3 +102,4 @@ test_title_bar_LDADD = \ ./libemiscwidgets.a \ $(GNOME_FULL_LIBS) + diff --git a/widgets/misc/e-multi-config-dialog.c b/widgets/misc/e-multi-config-dialog.c new file mode 100644 index 0000000000..74c0a883e8 --- /dev/null +++ b/widgets/misc/e-multi-config-dialog.c @@ -0,0 +1,376 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-multi-config-dialog.c + * + * Copyright (C) 2002 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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. + * + * Author: Ettore Perazzoli <ettore@ximian.com> + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "e-multi-config-dialog.h" + +#include "e-clipped-label.h" + +#include <gal/e-table/e-table-scrolled.h> +#include <gal/e-table/e-table-memory-callbacks.h> + +#include <gdk-pixbuf/gdk-pixbuf.h> + + +#define PARENT_TYPE gtk_window_get_type () +static GtkWindowClass *parent_class = NULL; + + +struct _Page { + char *title; + char *description; + GdkPixbuf *icon; + GtkWidget *widget; +}; +typedef struct _Page Page; + +struct _EMultiConfigDialogPrivate { + GSList *pages; + + GtkWidget *list_e_table; + ETableModel *list_e_table_model; + + GtkWidget *notebook; +}; + + +/* ETable stuff. */ + +static char *list_e_table_spec = + "<ETableSpecification cursor-mode=\"line\"" + " selection-mode=\"single\">" + " <ETableColumn model_col=\"0\"" + " expansion=\"1.0\"" + " minimum_width=\"32\"" + " resizable=\"true\"" + " cell=\"string\"" + " _title=\"blah\"" + " compare=\"string\"/>" + " <ETableState>" + " <column source=\"0\"/>" + " <grouping>" + " <leaf column=\"0\" ascending=\"true\"/>" + " </grouping>" + " </ETableState>" + "</ETableSpecification>"; + + +/* Page handling. */ + +static Page * +page_new (const char *title, + const char *description, + GdkPixbuf *icon, + GtkWidget *widget) +{ + Page *new; + + new = g_new (Page, 1); + new->title = g_strdup (title); + new->description = g_strdup (description); + new->icon = icon; + new->widget = widget; + + if (icon != NULL) + gdk_pixbuf_ref (icon); + + return new; +} + +static void +page_free (Page *page) +{ + g_free (page->title); + g_free (page->description); + + if (page->icon != NULL) + gdk_pixbuf_unref (page->icon); + + g_free (page); +} + +static GtkWidget * +create_page_widget (const char *description, + GtkWidget *widget) +{ + GtkWidget *vbox; + GtkWidget *label; + GtkWidget *separator; + + vbox = gtk_vbox_new (FALSE, 3); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); + + label = e_clipped_label_new (description); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0); + + separator = gtk_hseparator_new (); + gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0); + + gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0); + + gtk_widget_show (label); + gtk_widget_show (separator); + gtk_widget_show (widget); + gtk_widget_show (vbox); + + return vbox; +} + + +/* ETable mess. */ + +static int +table_model_column_count (ETableModel *etm, + void *data) +{ + return 1; +} + +static void * +table_model_value_at (ETableModel *etm, + int col, + int row, + void *model_data) +{ + EMultiConfigDialog *dialog; + EMultiConfigDialogPrivate *priv; + const Page *page; + GSList *p; + + dialog = E_MULTI_CONFIG_DIALOG (model_data); + priv = dialog->priv; + + p = g_slist_nth (priv->pages, row); + if (p == NULL) + return NULL; + + page = (const Page *) p->data; + return page->title; +} + +static gboolean +table_model_is_editable (ETableModel *etm, + int col, + int row, + void *model_data) +{ + return FALSE; +} + +static void * +table_model_duplicate_value (ETableModel *etm, + int col, + const void *value, + void *data) +{ + return g_strdup (value); +} + +static void +table_model_free_value (ETableModel *etm, + int col, + void *value, + void *data) +{ + g_free (value); +} + +static void * +table_model_initialize_value (ETableModel *etm, + int col, + void *data) +{ + return g_strdup (""); +} + +static gboolean +table_model_value_is_empty (ETableModel *etm, + int col, + const void *value, + void *data) +{ + return !(value && *(char *)value); +} + +static char * +table_model_value_to_string (ETableModel *etm, + int col, + const void *value, + void *data) +{ + return (char *)value; +} + + +/* ETable signals. */ + +static void +table_cursor_change_callback (ETable *etable, + int row, + void *data) +{ + EMultiConfigDialog *dialog; + EMultiConfigDialogPrivate *priv; + + dialog = E_MULTI_CONFIG_DIALOG (data); + priv = dialog->priv; + + gtk_notebook_set_page (GTK_NOTEBOOK (priv->notebook), row); +} + + +/* GtkObject methods. */ + +static void +impl_destroy (GtkObject *object) +{ + EMultiConfigDialog *dialog; + EMultiConfigDialogPrivate *priv; + GSList *p; + + dialog = E_MULTI_CONFIG_DIALOG (object); + priv = dialog->priv; + + for (p = priv->pages; p != NULL; p = p->next) + page_free ((Page *) p->data); + g_slist_free (priv->pages); + + g_free (priv); + + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + + +static void +class_init (GtkObjectClass *object_class) +{ + object_class->destroy = impl_destroy; + + parent_class = gtk_type_class (PARENT_TYPE); +} + +static void +init (EMultiConfigDialog *multi_config_dialog) +{ + EMultiConfigDialogPrivate *priv; + ETableModel *list_e_table_model; + GtkWidget *hbox; + GtkWidget *notebook; + GtkWidget *list_e_table; + + hbox = gtk_hbox_new (FALSE, 2); + gtk_container_add (GTK_CONTAINER (multi_config_dialog), hbox); + + list_e_table_model = e_table_memory_callbacks_new (table_model_column_count, + table_model_value_at, + NULL, /* set_value_at */ + table_model_is_editable, + table_model_duplicate_value, + table_model_free_value, + table_model_initialize_value, + table_model_value_is_empty, + table_model_value_to_string, + multi_config_dialog); + + list_e_table = e_table_scrolled_new (list_e_table_model, NULL, list_e_table_spec, NULL); + gtk_signal_connect (GTK_OBJECT (e_table_scrolled_get_table (E_TABLE_SCROLLED (list_e_table))), + "cursor_change", GTK_SIGNAL_FUNC (table_cursor_change_callback), + multi_config_dialog); + + gtk_widget_set_usize (list_e_table, 150, -1); + + gtk_box_pack_start (GTK_BOX (hbox), list_e_table, FALSE, TRUE, 0); + + notebook = gtk_notebook_new (); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); + gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0); + + gtk_widget_show (hbox); + gtk_widget_show (notebook); + gtk_widget_show (list_e_table); + + priv = g_new (EMultiConfigDialogPrivate, 1); + priv->pages = NULL; + priv->list_e_table = list_e_table; + priv->list_e_table_model = list_e_table_model; + priv->notebook = notebook; + + multi_config_dialog->priv = priv; +} + + +GtkWidget * +e_multi_config_dialog_new (void) +{ + EMultiConfigDialog *dialog; + + dialog = gtk_type_new (e_multi_config_dialog_get_type ()); + + return GTK_WIDGET (dialog); +} + + +void +e_multi_config_dialog_add_page (EMultiConfigDialog *dialog, + const char *title, + const char *description, + GdkPixbuf *icon, + GtkWidget *widget) +{ + EMultiConfigDialogPrivate *priv; + Page *new_page; + + g_return_if_fail (E_IS_MULTI_CONFIG_DIALOG (dialog)); + g_return_if_fail (title != NULL); + g_return_if_fail (description != NULL); + g_return_if_fail (GTK_IS_WIDGET (widget)); + + priv = dialog->priv; + + new_page = page_new (title, description, icon, widget); + + priv->pages = g_slist_append (priv->pages, new_page); + + if (priv->pages->next == NULL) { + ETable *table; + + /* FIXME: This is supposed to select the first entry by default + but it doesn't seem to work at all. */ + table = e_table_scrolled_get_table (E_TABLE_SCROLLED (priv->list_e_table)); + e_table_set_cursor_row (table, 0); + e_selection_model_select_all (e_table_get_selection_model (table)); + } + + e_table_memory_insert (E_TABLE_MEMORY (priv->list_e_table_model), -1, new_page->title); + + gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), + create_page_widget (new_page->description, widget), + NULL); +} + + +E_MAKE_TYPE (e_multi_config_dialog, "EMultiConfigDialog", EMultiConfigDialog, class_init, init, PARENT_TYPE) diff --git a/widgets/misc/e-multi-config-dialog.h b/widgets/misc/e-multi-config-dialog.h new file mode 100644 index 0000000000..dbcb17455a --- /dev/null +++ b/widgets/misc/e-multi-config-dialog.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-multi-config-dialog.h + * + * Copyright (C) 2002 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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. + * + * Author: Ettore Perazzoli <ettore@ximian.com> + */ + +#ifndef _E_MULTI_CONFIG_DIALOG_H_ +#define _E_MULTI_CONFIG_DIALOG_H_ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gtk/gtkwindow.h> + +#include <gdk-pixbuf/gdk-pixbuf.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +#define E_TYPE_MULTI_CONFIG_DIALOG (e_multi_config_dialog_get_type ()) +#define E_MULTI_CONFIG_DIALOG(obj) (GTK_CHECK_CAST ((obj), E_TYPE_MULTI_CONFIG_DIALOG, EMultiConfigDialog)) +#define E_MULTI_CONFIG_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_MULTI_CONFIG_DIALOG, EMultiConfigDialogClass)) +#define E_IS_MULTI_CONFIG_DIALOG(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_MULTI_CONFIG_DIALOG)) +#define E_IS_MULTI_CONFIG_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_MULTI_CONFIG_DIALOG)) + + +typedef struct _EMultiConfigDialog EMultiConfigDialog; +typedef struct _EMultiConfigDialogPrivate EMultiConfigDialogPrivate; +typedef struct _EMultiConfigDialogClass EMultiConfigDialogClass; + +struct _EMultiConfigDialog { + GtkWindow parent; + + EMultiConfigDialogPrivate *priv; +}; + +struct _EMultiConfigDialogClass { + GtkWindowClass parent_class; +}; + + +GtkType e_multi_config_dialog_get_type (void); +GtkWidget *e_multi_config_dialog_new (void); + +void e_multi_config_dialog_add_page (EMultiConfigDialog *dialog, + const char *title, + const char *description, + GdkPixbuf *icon, + GtkWidget *widget); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _E_MULTI_CONFIG_DIALOG_H_ */ diff --git a/widgets/misc/test-multi-config-dialog.c b/widgets/misc/test-multi-config-dialog.c new file mode 100644 index 0000000000..8882a627a3 --- /dev/null +++ b/widgets/misc/test-multi-config-dialog.c @@ -0,0 +1,88 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* test-multi-config-dialog.c + * + * Copyright (C) 2002 Ximian, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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: + * Ettore Perazzoli <ettore@ximian.com> + */ + +#include "e-multi-config-dialog.c" + +#include <gnome.h> + + +#define NUM_PAGES 10 + + +static void +add_pages (EMultiConfigDialog *multi_config_dialog) +{ + int i; + + for (i = 0; i < NUM_PAGES; i ++) { + GtkWidget *widget; + char *string; + char *title; + char *description; + + string = g_strdup_printf ("This is page %d", i); + description = g_strdup_printf ("Description of page %d", i); + title = g_strdup_printf ("Title of page %d", i); + + widget = gtk_label_new (string); + + e_multi_config_dialog_add_page (multi_config_dialog, title, description, NULL, widget); + + g_free (string); + g_free (title); + g_free (description); + } +} + +static int +delete_event_callback (GtkWidget *widget, + GdkEventAny *event, + void *data) +{ + gtk_main_quit (); + + return TRUE; +} + + +int +main (int argc, char **argv) +{ + GtkWidget *dialog; + + gnome_init ("test-multi-config-dialog", "0.0", argc, argv); + + dialog = e_multi_config_dialog_new (); + + gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300); + gtk_signal_connect (GTK_OBJECT (dialog), "delete_event", + GTK_SIGNAL_FUNC (delete_event_callback), NULL); + + add_pages (E_MULTI_CONFIG_DIALOG (dialog)); + + gtk_widget_show (dialog); + + gtk_main (); + + return 0; +} |