diff --git a/ChangeLog b/ChangeLog index 3831770a3c..b246e66213 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-10-29 Michael Natterer + + * libgimpwidgets/gimpcolornotebook.[ch]: made the color notebook + a GimpColorSelector subclass so they have the same API. + + * app/gui/color-notebook.c: changed accordingly. + 2002-10-29 Sven Neumann * libgimpmodule/gimpmodule.c diff --git a/app/dialogs/color-dialog.c b/app/dialogs/color-dialog.c index 8cc246ba70..960c875e52 100644 --- a/app/dialogs/color-dialog.c +++ b/app/dialogs/color-dialog.c @@ -108,11 +108,11 @@ static void color_notebook_reset_clicked (ColorNotebook *cnp); static void color_notebook_new_color_changed (GtkWidget *widget, ColorNotebook *cnp); -static void color_notebook_notebook_changed (GimpColorNotebook *notebook, +static void color_notebook_notebook_changed (GimpColorSelector *selector, const GimpRGB *rgb, const GimpHSV *hsv, ColorNotebook *cnp); -static void color_notebook_switch_page (GimpColorNotebook *notebook, +static void color_notebook_switch_page (GtkWidget *widget, GtkNotebookPage *page, guint page_num, ColorNotebook *cnp); @@ -366,21 +366,20 @@ color_notebook_new_internal (GimpViewable *viewable, gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0); gtk_widget_show (right_vbox); - cnp->notebook = gimp_color_notebook_new (); - gimp_color_notebook_set_channel (GIMP_COLOR_NOTEBOOK (cnp->notebook), - cnp->active_channel); - gimp_color_notebook_set_color (GIMP_COLOR_NOTEBOOK (cnp->notebook), - &cnp->rgb, &cnp->hsv); - gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook, - TRUE, TRUE, 0); + cnp->notebook = gimp_color_selector_new (GIMP_TYPE_COLOR_NOTEBOOK, + &cnp->rgb, + &cnp->hsv, + cnp->active_channel); + gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook, TRUE, TRUE, 0); gtk_widget_show (cnp->notebook); g_signal_connect (G_OBJECT (cnp->notebook), "color_changed", G_CALLBACK (color_notebook_notebook_changed), cnp); - g_signal_connect_after (G_OBJECT (cnp->notebook), "switch_page", - G_CALLBACK (color_notebook_switch_page), - cnp); + g_signal_connect (G_OBJECT (GIMP_COLOR_NOTEBOOK (cnp->notebook)->notebook), + "switch_page", + G_CALLBACK (color_notebook_switch_page), + cnp); /* The table for the color_areas */ table = gtk_table_new (2, 4, FALSE); @@ -587,12 +586,10 @@ color_notebook_ok_callback (GtkWidget *widget, color_history_add_clicked (NULL, cnp); if (cnp->callback) - { - (* cnp->callback) (cnp, - &cnp->rgb, - COLOR_NOTEBOOK_OK, - cnp->client_data); - } + cnp->callback (cnp, + &cnp->rgb, + COLOR_NOTEBOOK_OK, + cnp->client_data); } static void @@ -600,12 +597,10 @@ color_notebook_cancel_callback (GtkWidget *widget, ColorNotebook *cnp) { if (cnp->callback) - { - (* cnp->callback) (cnp, - &cnp->orig_rgb, - COLOR_NOTEBOOK_CANCEL, - cnp->client_data); - } + cnp->callback (cnp, + &cnp->orig_rgb, + COLOR_NOTEBOOK_CANCEL, + cnp->client_data); } static void @@ -616,12 +611,12 @@ color_notebook_update (ColorNotebook *cnp, return; if (update & UPDATE_NOTEBOOK) - gimp_color_notebook_set_color (GIMP_COLOR_NOTEBOOK (cnp->notebook), + gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (cnp->notebook), &cnp->rgb, &cnp->hsv); if (update & UPDATE_CHANNEL) - gimp_color_notebook_set_channel (GIMP_COLOR_NOTEBOOK (cnp->notebook), + gimp_color_selector_set_channel (GIMP_COLOR_SELECTOR (cnp->notebook), cnp->active_channel); if (update & UPDATE_SCALES) @@ -650,10 +645,10 @@ color_notebook_update (ColorNotebook *cnp, if (update & UPDATE_CALLER) { if (cnp->wants_updates && cnp->callback) - (* cnp->callback) (cnp, - &cnp->rgb, - COLOR_NOTEBOOK_UPDATE, - cnp->client_data); + cnp->callback (cnp, + &cnp->rgb, + COLOR_NOTEBOOK_UPDATE, + cnp->client_data); } } @@ -714,10 +709,10 @@ color_notebook_new_color_changed (GtkWidget *widget, } -/* color notebook callback */ +/* color notebook callbacks */ static void -color_notebook_notebook_changed (GimpColorNotebook *notebook, +color_notebook_notebook_changed (GimpColorSelector *selector, const GimpRGB *rgb, const GimpHSV *hsv, ColorNotebook *cnp) @@ -732,12 +727,15 @@ color_notebook_notebook_changed (GimpColorNotebook *notebook, } static void -color_notebook_switch_page (GimpColorNotebook *notebook, - GtkNotebookPage *page, - guint page_num, - ColorNotebook *cnp) +color_notebook_switch_page (GtkWidget *widget, + GtkNotebookPage *page, + guint page_num, + ColorNotebook *cnp) { - gboolean set_channel; + GimpColorNotebook *notebook; + gboolean set_channel; + + notebook = GIMP_COLOR_NOTEBOOK (cnp->notebook); set_channel = (GIMP_COLOR_SELECTOR_GET_CLASS (notebook->cur_page)->set_channel != NULL); diff --git a/app/gui/color-notebook.c b/app/gui/color-notebook.c index 8cc246ba70..960c875e52 100644 --- a/app/gui/color-notebook.c +++ b/app/gui/color-notebook.c @@ -108,11 +108,11 @@ static void color_notebook_reset_clicked (ColorNotebook *cnp); static void color_notebook_new_color_changed (GtkWidget *widget, ColorNotebook *cnp); -static void color_notebook_notebook_changed (GimpColorNotebook *notebook, +static void color_notebook_notebook_changed (GimpColorSelector *selector, const GimpRGB *rgb, const GimpHSV *hsv, ColorNotebook *cnp); -static void color_notebook_switch_page (GimpColorNotebook *notebook, +static void color_notebook_switch_page (GtkWidget *widget, GtkNotebookPage *page, guint page_num, ColorNotebook *cnp); @@ -366,21 +366,20 @@ color_notebook_new_internal (GimpViewable *viewable, gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0); gtk_widget_show (right_vbox); - cnp->notebook = gimp_color_notebook_new (); - gimp_color_notebook_set_channel (GIMP_COLOR_NOTEBOOK (cnp->notebook), - cnp->active_channel); - gimp_color_notebook_set_color (GIMP_COLOR_NOTEBOOK (cnp->notebook), - &cnp->rgb, &cnp->hsv); - gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook, - TRUE, TRUE, 0); + cnp->notebook = gimp_color_selector_new (GIMP_TYPE_COLOR_NOTEBOOK, + &cnp->rgb, + &cnp->hsv, + cnp->active_channel); + gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook, TRUE, TRUE, 0); gtk_widget_show (cnp->notebook); g_signal_connect (G_OBJECT (cnp->notebook), "color_changed", G_CALLBACK (color_notebook_notebook_changed), cnp); - g_signal_connect_after (G_OBJECT (cnp->notebook), "switch_page", - G_CALLBACK (color_notebook_switch_page), - cnp); + g_signal_connect (G_OBJECT (GIMP_COLOR_NOTEBOOK (cnp->notebook)->notebook), + "switch_page", + G_CALLBACK (color_notebook_switch_page), + cnp); /* The table for the color_areas */ table = gtk_table_new (2, 4, FALSE); @@ -587,12 +586,10 @@ color_notebook_ok_callback (GtkWidget *widget, color_history_add_clicked (NULL, cnp); if (cnp->callback) - { - (* cnp->callback) (cnp, - &cnp->rgb, - COLOR_NOTEBOOK_OK, - cnp->client_data); - } + cnp->callback (cnp, + &cnp->rgb, + COLOR_NOTEBOOK_OK, + cnp->client_data); } static void @@ -600,12 +597,10 @@ color_notebook_cancel_callback (GtkWidget *widget, ColorNotebook *cnp) { if (cnp->callback) - { - (* cnp->callback) (cnp, - &cnp->orig_rgb, - COLOR_NOTEBOOK_CANCEL, - cnp->client_data); - } + cnp->callback (cnp, + &cnp->orig_rgb, + COLOR_NOTEBOOK_CANCEL, + cnp->client_data); } static void @@ -616,12 +611,12 @@ color_notebook_update (ColorNotebook *cnp, return; if (update & UPDATE_NOTEBOOK) - gimp_color_notebook_set_color (GIMP_COLOR_NOTEBOOK (cnp->notebook), + gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (cnp->notebook), &cnp->rgb, &cnp->hsv); if (update & UPDATE_CHANNEL) - gimp_color_notebook_set_channel (GIMP_COLOR_NOTEBOOK (cnp->notebook), + gimp_color_selector_set_channel (GIMP_COLOR_SELECTOR (cnp->notebook), cnp->active_channel); if (update & UPDATE_SCALES) @@ -650,10 +645,10 @@ color_notebook_update (ColorNotebook *cnp, if (update & UPDATE_CALLER) { if (cnp->wants_updates && cnp->callback) - (* cnp->callback) (cnp, - &cnp->rgb, - COLOR_NOTEBOOK_UPDATE, - cnp->client_data); + cnp->callback (cnp, + &cnp->rgb, + COLOR_NOTEBOOK_UPDATE, + cnp->client_data); } } @@ -714,10 +709,10 @@ color_notebook_new_color_changed (GtkWidget *widget, } -/* color notebook callback */ +/* color notebook callbacks */ static void -color_notebook_notebook_changed (GimpColorNotebook *notebook, +color_notebook_notebook_changed (GimpColorSelector *selector, const GimpRGB *rgb, const GimpHSV *hsv, ColorNotebook *cnp) @@ -732,12 +727,15 @@ color_notebook_notebook_changed (GimpColorNotebook *notebook, } static void -color_notebook_switch_page (GimpColorNotebook *notebook, - GtkNotebookPage *page, - guint page_num, - ColorNotebook *cnp) +color_notebook_switch_page (GtkWidget *widget, + GtkNotebookPage *page, + guint page_num, + ColorNotebook *cnp) { - gboolean set_channel; + GimpColorNotebook *notebook; + gboolean set_channel; + + notebook = GIMP_COLOR_NOTEBOOK (cnp->notebook); set_channel = (GIMP_COLOR_SELECTOR_GET_CLASS (notebook->cur_page)->set_channel != NULL); diff --git a/app/widgets/gimpcolordialog.c b/app/widgets/gimpcolordialog.c index 8cc246ba70..960c875e52 100644 --- a/app/widgets/gimpcolordialog.c +++ b/app/widgets/gimpcolordialog.c @@ -108,11 +108,11 @@ static void color_notebook_reset_clicked (ColorNotebook *cnp); static void color_notebook_new_color_changed (GtkWidget *widget, ColorNotebook *cnp); -static void color_notebook_notebook_changed (GimpColorNotebook *notebook, +static void color_notebook_notebook_changed (GimpColorSelector *selector, const GimpRGB *rgb, const GimpHSV *hsv, ColorNotebook *cnp); -static void color_notebook_switch_page (GimpColorNotebook *notebook, +static void color_notebook_switch_page (GtkWidget *widget, GtkNotebookPage *page, guint page_num, ColorNotebook *cnp); @@ -366,21 +366,20 @@ color_notebook_new_internal (GimpViewable *viewable, gtk_box_pack_start (GTK_BOX (main_hbox), right_vbox, TRUE, TRUE, 0); gtk_widget_show (right_vbox); - cnp->notebook = gimp_color_notebook_new (); - gimp_color_notebook_set_channel (GIMP_COLOR_NOTEBOOK (cnp->notebook), - cnp->active_channel); - gimp_color_notebook_set_color (GIMP_COLOR_NOTEBOOK (cnp->notebook), - &cnp->rgb, &cnp->hsv); - gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook, - TRUE, TRUE, 0); + cnp->notebook = gimp_color_selector_new (GIMP_TYPE_COLOR_NOTEBOOK, + &cnp->rgb, + &cnp->hsv, + cnp->active_channel); + gtk_box_pack_start (GTK_BOX (left_vbox), cnp->notebook, TRUE, TRUE, 0); gtk_widget_show (cnp->notebook); g_signal_connect (G_OBJECT (cnp->notebook), "color_changed", G_CALLBACK (color_notebook_notebook_changed), cnp); - g_signal_connect_after (G_OBJECT (cnp->notebook), "switch_page", - G_CALLBACK (color_notebook_switch_page), - cnp); + g_signal_connect (G_OBJECT (GIMP_COLOR_NOTEBOOK (cnp->notebook)->notebook), + "switch_page", + G_CALLBACK (color_notebook_switch_page), + cnp); /* The table for the color_areas */ table = gtk_table_new (2, 4, FALSE); @@ -587,12 +586,10 @@ color_notebook_ok_callback (GtkWidget *widget, color_history_add_clicked (NULL, cnp); if (cnp->callback) - { - (* cnp->callback) (cnp, - &cnp->rgb, - COLOR_NOTEBOOK_OK, - cnp->client_data); - } + cnp->callback (cnp, + &cnp->rgb, + COLOR_NOTEBOOK_OK, + cnp->client_data); } static void @@ -600,12 +597,10 @@ color_notebook_cancel_callback (GtkWidget *widget, ColorNotebook *cnp) { if (cnp->callback) - { - (* cnp->callback) (cnp, - &cnp->orig_rgb, - COLOR_NOTEBOOK_CANCEL, - cnp->client_data); - } + cnp->callback (cnp, + &cnp->orig_rgb, + COLOR_NOTEBOOK_CANCEL, + cnp->client_data); } static void @@ -616,12 +611,12 @@ color_notebook_update (ColorNotebook *cnp, return; if (update & UPDATE_NOTEBOOK) - gimp_color_notebook_set_color (GIMP_COLOR_NOTEBOOK (cnp->notebook), + gimp_color_selector_set_color (GIMP_COLOR_SELECTOR (cnp->notebook), &cnp->rgb, &cnp->hsv); if (update & UPDATE_CHANNEL) - gimp_color_notebook_set_channel (GIMP_COLOR_NOTEBOOK (cnp->notebook), + gimp_color_selector_set_channel (GIMP_COLOR_SELECTOR (cnp->notebook), cnp->active_channel); if (update & UPDATE_SCALES) @@ -650,10 +645,10 @@ color_notebook_update (ColorNotebook *cnp, if (update & UPDATE_CALLER) { if (cnp->wants_updates && cnp->callback) - (* cnp->callback) (cnp, - &cnp->rgb, - COLOR_NOTEBOOK_UPDATE, - cnp->client_data); + cnp->callback (cnp, + &cnp->rgb, + COLOR_NOTEBOOK_UPDATE, + cnp->client_data); } } @@ -714,10 +709,10 @@ color_notebook_new_color_changed (GtkWidget *widget, } -/* color notebook callback */ +/* color notebook callbacks */ static void -color_notebook_notebook_changed (GimpColorNotebook *notebook, +color_notebook_notebook_changed (GimpColorSelector *selector, const GimpRGB *rgb, const GimpHSV *hsv, ColorNotebook *cnp) @@ -732,12 +727,15 @@ color_notebook_notebook_changed (GimpColorNotebook *notebook, } static void -color_notebook_switch_page (GimpColorNotebook *notebook, - GtkNotebookPage *page, - guint page_num, - ColorNotebook *cnp) +color_notebook_switch_page (GtkWidget *widget, + GtkNotebookPage *page, + guint page_num, + ColorNotebook *cnp) { - gboolean set_channel; + GimpColorNotebook *notebook; + gboolean set_channel; + + notebook = GIMP_COLOR_NOTEBOOK (cnp->notebook); set_channel = (GIMP_COLOR_SELECTOR_GET_CLASS (notebook->cur_page)->set_channel != NULL); diff --git a/libgimpwidgets/gimpcolornotebook.c b/libgimpwidgets/gimpcolornotebook.c index 3ec40bca72..8552723dff 100644 --- a/libgimpwidgets/gimpcolornotebook.c +++ b/libgimpwidgets/gimpcolornotebook.c @@ -33,34 +33,37 @@ #include "gimpcolornotebook.h" #include "gimpcolorscales.h" -#include "gimpcolorselector.h" #include "gimpwidgetsmarshal.h" -enum -{ - COLOR_CHANGED, - LAST_SIGNAL -}; - - static void gimp_color_notebook_class_init (GimpColorNotebookClass *klass); static void gimp_color_notebook_init (GimpColorNotebook *notebook); static void gimp_color_notebook_finalize (GObject *object); + +static void gimp_color_notebook_set_show_alpha (GimpColorSelector *selector, + gboolean show_alpha); +static void gimp_color_notebook_set_color (GimpColorSelector *selector, + const GimpRGB *rgb, + const GimpHSV *hsv); +static void gimp_color_notebook_set_channel (GimpColorSelector *selector, + GimpColorSelectorChannel channel); + static void gimp_color_notebook_switch_page (GtkNotebook *gtk_notebook, GtkNotebookPage *page, - guint page_num); + guint page_num, + GimpColorNotebook *notebook); -static void gimp_color_notebook_update_callback (GimpColorSelector *selector, +static void gimp_color_notebook_color_changed (GimpColorSelector *page, const GimpRGB *rgb, const GimpHSV *hsv, GimpColorNotebook *notebook); +static void gimp_color_notebook_channel_changed (GimpColorSelector *page, + GimpColorSelectorChannel channel, + GimpColorNotebook *notebook); -static GtkNotebookClass *parent_class = NULL; - -static guint notebook_signals[LAST_SIGNAL] = { 0 }; +static GimpColorSelectorClass *parent_class = NULL; GType @@ -83,7 +86,7 @@ gimp_color_notebook_get_type (void) (GInstanceInitFunc) gimp_color_notebook_init, }; - notebook_type = g_type_register_static (GTK_TYPE_NOTEBOOK, + notebook_type = g_type_register_static (GIMP_TYPE_COLOR_SELECTOR, "GimpColorNotebook", ¬ebook_info, 0); } @@ -94,83 +97,87 @@ gimp_color_notebook_get_type (void) static void gimp_color_notebook_class_init (GimpColorNotebookClass *klass) { - GObjectClass *object_class; - GtkNotebookClass *notebook_class; + GObjectClass *object_class; + GimpColorSelectorClass *selector_class; object_class = G_OBJECT_CLASS (klass); - notebook_class = GTK_NOTEBOOK_CLASS (klass); + selector_class = GIMP_COLOR_SELECTOR_CLASS (klass); parent_class = g_type_class_peek_parent (klass); - notebook_signals[COLOR_CHANGED] = - g_signal_new ("color_changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GimpColorNotebookClass, color_changed), - NULL, NULL, - _gimp_widgets_marshal_VOID__POINTER_POINTER, - G_TYPE_NONE, 2, - G_TYPE_POINTER, - G_TYPE_POINTER); + object_class->finalize = gimp_color_notebook_finalize; - object_class->finalize = gimp_color_notebook_finalize; - - notebook_class->switch_page = gimp_color_notebook_switch_page; - - klass->color_changed = NULL; + selector_class->name = "Notebook"; + selector_class->help_page = "notebook.html"; + selector_class->set_show_alpha = gimp_color_notebook_set_show_alpha; + selector_class->set_color = gimp_color_notebook_set_color; + selector_class->set_channel = gimp_color_notebook_set_channel; } static void gimp_color_notebook_init (GimpColorNotebook *notebook) { - GtkWidget *selector; - GtkWidget *label; - GType *selector_types; - gint n_selector_types; - gint i; + GimpColorSelector *selector; + GtkWidget *page; + GtkWidget *label; + GType *selector_types; + gint n_selector_types; + gint i; - gimp_rgba_set (¬ebook->rgb, 0.0, 0.0, 0.0, 1.0); - gimp_rgb_to_hsv (¬ebook->rgb, ¬ebook->hsv); + selector = GIMP_COLOR_SELECTOR (notebook); - notebook->channel = GIMP_COLOR_SELECTOR_HUE; + notebook->notebook = gtk_notebook_new (); + gtk_box_pack_start (GTK_BOX (notebook), notebook->notebook, TRUE, TRUE, 0); + gtk_widget_show (notebook->notebook); + + g_signal_connect (G_OBJECT (notebook->notebook), "switch_page", + G_CALLBACK (gimp_color_notebook_switch_page), + notebook); selector_types = g_type_children (GIMP_TYPE_COLOR_SELECTOR, &n_selector_types); - if (n_selector_types == 1) + if (n_selector_types == 2) { - gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); - gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); + gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook->notebook), FALSE); + gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook->notebook), FALSE); } for (i = 0; i < n_selector_types; i++) { + /* skip ourselves */ + if (g_type_is_a (selector_types[i], GIMP_TYPE_COLOR_NOTEBOOK)) + continue; + /* skip the "Scales" color selector */ if (g_type_is_a (selector_types[i], GIMP_TYPE_COLOR_SCALES)) continue; - selector = gimp_color_selector_new (selector_types[i], - ¬ebook->rgb, - ¬ebook->hsv, - notebook->channel); + page = gimp_color_selector_new (selector_types[i], + &selector->rgb, + &selector->hsv, + selector->channel); - if (! selector) + if (! page) continue; - gimp_color_selector_set_show_alpha (GIMP_COLOR_SELECTOR (selector), FALSE); + gimp_color_selector_set_show_alpha (GIMP_COLOR_SELECTOR (page), FALSE); - label = gtk_label_new (GIMP_COLOR_SELECTOR_GET_CLASS (selector)->name); + label = gtk_label_new (GIMP_COLOR_SELECTOR_GET_CLASS (page)->name); - gtk_notebook_append_page (GTK_NOTEBOOK (notebook), selector, label); + gtk_notebook_append_page (GTK_NOTEBOOK (notebook->notebook), page, label); if (! notebook->cur_page) - notebook->cur_page = GIMP_COLOR_SELECTOR (selector); + notebook->cur_page = GIMP_COLOR_SELECTOR (page); - notebook->selectors = g_list_append (notebook->selectors, selector); + notebook->selectors = g_list_append (notebook->selectors, page); - gtk_widget_show (selector); + gtk_widget_show (page); - g_signal_connect (G_OBJECT (selector), "color_changed", - G_CALLBACK (gimp_color_notebook_update_callback), + g_signal_connect (G_OBJECT (page), "color_changed", + G_CALLBACK (gimp_color_notebook_color_changed), + notebook); + g_signal_connect (G_OBJECT (page), "channel_changed", + G_CALLBACK (gimp_color_notebook_channel_changed), notebook); } @@ -194,122 +201,124 @@ gimp_color_notebook_finalize (GObject *object) } static void -gimp_color_notebook_switch_page (GtkNotebook *gtk_notebook, - GtkNotebookPage *page, - guint page_num) +gimp_color_notebook_set_show_alpha (GimpColorSelector *selector, + gboolean show_alpha) { GimpColorNotebook *notebook; + GimpColorSelector *child; + GList *list; + + notebook = GIMP_COLOR_NOTEBOOK (selector); + + for (list = notebook->selectors; list; list = g_list_next (list)) + { + child = (GimpColorSelector *) list->data; + + gimp_color_selector_set_show_alpha (child, show_alpha); + } +} + +static void +gimp_color_notebook_set_color (GimpColorSelector *selector, + const GimpRGB *rgb, + const GimpHSV *hsv) +{ + GimpColorNotebook *notebook; + + notebook = GIMP_COLOR_NOTEBOOK (selector); + + g_signal_handlers_block_by_func (G_OBJECT (notebook->cur_page), + gimp_color_notebook_color_changed, + notebook); + + gimp_color_selector_set_color (notebook->cur_page, rgb, hsv); + + g_signal_handlers_unblock_by_func (G_OBJECT (notebook->cur_page), + gimp_color_notebook_color_changed, + notebook); +} + +static void +gimp_color_notebook_set_channel (GimpColorSelector *selector, + GimpColorSelectorChannel channel) +{ + GimpColorNotebook *notebook; + + notebook = GIMP_COLOR_NOTEBOOK (selector); + + g_signal_handlers_block_by_func (G_OBJECT (notebook->cur_page), + gimp_color_notebook_channel_changed, + notebook); + + gimp_color_selector_set_channel (notebook->cur_page, channel); + + g_signal_handlers_unblock_by_func (G_OBJECT (notebook->cur_page), + gimp_color_notebook_channel_changed, + notebook); +} + +static void +gimp_color_notebook_switch_page (GtkNotebook *gtk_notebook, + GtkNotebookPage *page, + guint page_num, + GimpColorNotebook *notebook) +{ + GimpColorSelector *selector; GtkWidget *page_widget; - notebook = GIMP_COLOR_NOTEBOOK (gtk_notebook); - - GTK_NOTEBOOK_CLASS (parent_class)->switch_page (gtk_notebook, page, page_num); + selector = GIMP_COLOR_SELECTOR (notebook); page_widget = gtk_notebook_get_nth_page (gtk_notebook, page_num); notebook->cur_page = GIMP_COLOR_SELECTOR (page_widget); g_signal_handlers_block_by_func (G_OBJECT (notebook->cur_page), - gimp_color_notebook_update_callback, + gimp_color_notebook_color_changed, notebook); - - gimp_color_selector_set_channel (notebook->cur_page, - notebook->channel); - gimp_color_selector_set_color (notebook->cur_page, - ¬ebook->rgb, - ¬ebook->hsv); - - g_signal_handlers_unblock_by_func (G_OBJECT (notebook->cur_page), - gimp_color_notebook_update_callback, - notebook); -} - - -/* public functions */ - -GtkWidget * -gimp_color_notebook_new (void) -{ - GimpColorNotebook *notebook; - - notebook = g_object_new (GIMP_TYPE_COLOR_NOTEBOOK, NULL); - - return GTK_WIDGET (notebook); -} - -void -gimp_color_notebook_set_color (GimpColorNotebook *notebook, - const GimpRGB *rgb, - const GimpHSV *hsv) -{ - g_return_if_fail (GIMP_IS_COLOR_NOTEBOOK (notebook)); - g_return_if_fail (rgb != NULL); - g_return_if_fail (hsv != NULL); - - notebook->rgb = *rgb; - notebook->hsv = *hsv; - g_signal_handlers_block_by_func (G_OBJECT (notebook->cur_page), - gimp_color_notebook_update_callback, + gimp_color_notebook_channel_changed, notebook); gimp_color_selector_set_color (notebook->cur_page, - ¬ebook->rgb, - ¬ebook->hsv); + &selector->rgb, + &selector->hsv); + gimp_color_selector_set_channel (notebook->cur_page, + selector->channel); g_signal_handlers_unblock_by_func (G_OBJECT (notebook->cur_page), - gimp_color_notebook_update_callback, + gimp_color_notebook_color_changed, + notebook); + g_signal_handlers_unblock_by_func (G_OBJECT (notebook->cur_page), + gimp_color_notebook_channel_changed, notebook); } -void -gimp_color_notebook_get_color (GimpColorNotebook *notebook, - GimpRGB *rgb, - GimpHSV *hsv) -{ - g_return_if_fail (GIMP_IS_COLOR_NOTEBOOK (notebook)); - g_return_if_fail (rgb != NULL); - g_return_if_fail (hsv != NULL); - - *rgb = notebook->rgb; - *hsv = notebook->hsv; -} - -void -gimp_color_notebook_color_changed (GimpColorNotebook *notebook) -{ - g_return_if_fail (GIMP_IS_COLOR_NOTEBOOK (notebook)); - - g_signal_emit (G_OBJECT (notebook), notebook_signals[COLOR_CHANGED], 0, - ¬ebook->rgb, ¬ebook->hsv); -} - -void -gimp_color_notebook_set_channel (GimpColorNotebook *notebook, - GimpColorSelectorChannel channel) -{ - g_return_if_fail (GIMP_IS_COLOR_NOTEBOOK (notebook)); - - if (channel != notebook->channel) - { - notebook->channel = channel; - - gimp_color_selector_set_channel (notebook->cur_page, - notebook->channel); - } -} - - -/* private functions */ - static void -gimp_color_notebook_update_callback (GimpColorSelector *selector, - const GimpRGB *rgb, - const GimpHSV *hsv, - GimpColorNotebook *notebook) +gimp_color_notebook_color_changed (GimpColorSelector *page, + const GimpRGB *rgb, + const GimpHSV *hsv, + GimpColorNotebook *notebook) { - notebook->rgb = *rgb; - notebook->hsv = *hsv; + GimpColorSelector *selector; - gimp_color_notebook_color_changed (notebook); + selector = GIMP_COLOR_SELECTOR (notebook); + + selector->rgb = *rgb; + selector->hsv = *hsv; + + gimp_color_selector_color_changed (selector); +} + +static void +gimp_color_notebook_channel_changed (GimpColorSelector *page, + GimpColorSelectorChannel channel, + GimpColorNotebook *notebook) +{ + GimpColorSelector *selector; + + selector = GIMP_COLOR_SELECTOR (notebook); + + selector->channel = channel; + + gimp_color_selector_channel_changed (selector); } diff --git a/libgimpwidgets/gimpcolornotebook.h b/libgimpwidgets/gimpcolornotebook.h index 3226159a03..7a3540b3e8 100644 --- a/libgimpwidgets/gimpcolornotebook.h +++ b/libgimpwidgets/gimpcolornotebook.h @@ -26,6 +26,8 @@ #ifndef __GIMP_COLOR_NOTEBOOK_H__ #define __GIMP_COLOR_NOTEBOOK_H__ +#include + G_BEGIN_DECLS @@ -41,42 +43,21 @@ typedef struct _GimpColorNotebookClass GimpColorNotebookClass; struct _GimpColorNotebook { - GtkNotebook parent_instance; + GimpColorSelector parent_instance; - GimpRGB rgb; - GimpHSV hsv; + GtkWidget *notebook; - GimpColorSelectorChannel channel; - - GList *selectors; - GimpColorSelector *cur_page; + GList *selectors; + GimpColorSelector *cur_page; }; struct _GimpColorNotebookClass { - GtkNotebookClass parent_class; - - /* signals */ - void (* color_changed) (GimpColorNotebook *notebook, - const GimpRGB *rgb, - const GimpHSV *hsv); + GimpColorSelectorClass parent_class; }; -GType gimp_color_notebook_get_type (void) G_GNUC_CONST; - -GtkWidget * gimp_color_notebook_new (void); - -void gimp_color_notebook_set_color (GimpColorNotebook *notebook, - const GimpRGB *rgb, - const GimpHSV *hsv); -void gimp_color_notebook_get_color (GimpColorNotebook *notebook, - GimpRGB *rgb, - GimpHSV *hsv); -void gimp_color_notebook_color_changed (GimpColorNotebook *notebook); - -void gimp_color_notebook_set_channel (GimpColorNotebook *notebook, - GimpColorSelectorChannel channel); +GType gimp_color_notebook_get_type (void) G_GNUC_CONST; G_END_DECLS