2
* Copyright (C) Pierre-Yves Luyten 2012 <py@luyten.fr>
4
* bijiben is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
9
* anjuta is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
19
/* This is mostly gtk-color-button.c
20
* Just overrides the dialog to choose specific palette
21
* But a dedicated dialog might be better */
23
#include <glib/gi18n.h>
25
#include "bjb-color-button.h"
27
// Bijiben probably wants something like 6 light colors
28
#define BJB_NUM_COLORS 4
30
static gchar *palette_str[BJB_NUM_COLORS] = {
31
"rgb(239, 242, 209)", // eff2d1 from the mockup
32
"rgb(210, 219, 230)", // d2dbe6 from the mockup
33
"rgb(229, 230, 210)", //
34
"rgb(235, 239, 244)", //
37
struct _BjbColorButtonPrivate
39
GdkRGBA palette [BJB_NUM_COLORS];
45
#define BJB_COLOR_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BJB_TYPE_COLOR_BUTTON, BjbColorButtonPrivate))
48
G_DEFINE_TYPE (BjbColorButton, bjb_color_button, GTK_TYPE_COLOR_BUTTON);
51
dialog_destroy (GtkWidget *widget,
54
BjbColorButton *button = BJB_COLOR_BUTTON (data);
56
button->priv->dialog = NULL;
62
dialog_response (GtkDialog *dialog,
66
BjbColorButton *button = BJB_COLOR_BUTTON (data);
67
BjbColorButtonPrivate *priv = button->priv;
69
if (response == GTK_RESPONSE_CANCEL)
70
gtk_widget_hide (GTK_WIDGET (dialog));
72
else if (response == GTK_RESPONSE_OK)
74
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog),
77
gtk_widget_hide (GTK_WIDGET (dialog));
78
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button), &priv->rgba);
79
g_signal_emit_by_name (button, "color-set");
84
bjb_color_button_clicked (GtkButton *b)
86
BjbColorButton *button = BJB_COLOR_BUTTON (b);
87
BjbColorButtonPrivate *priv = button->priv;
91
/* if dialog already exists, make sure it's shown and raised */
92
if (!button->priv->dialog)
94
/* Create the dialog and connects its buttons */
97
parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
99
button->priv->dialog = dialog = gtk_color_chooser_dialog_new (button->priv->title, NULL);
101
if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
103
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
104
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
106
gtk_window_set_modal (GTK_WINDOW (dialog),
107
gtk_window_get_modal (GTK_WINDOW (parent)));
110
for (i=0 ; i< BJB_NUM_COLORS ; i++)
114
if (gdk_rgba_parse (&color, palette_str[i]))
115
priv->palette [i] = color;
118
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (dialog),
119
GTK_ORIENTATION_HORIZONTAL,
125
g_signal_connect (dialog, "response",
126
G_CALLBACK (dialog_response), button);
127
g_signal_connect (dialog, "destroy",
128
G_CALLBACK (dialog_destroy), button);
131
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &priv->rgba);
132
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button->priv->dialog),
133
&button->priv->rgba);
135
gtk_window_present (GTK_WINDOW (button->priv->dialog));
141
bjb_color_button_init (BjbColorButton *self)
143
BjbColorButtonPrivate *priv = BJB_COLOR_BUTTON_GET_PRIVATE(self);
146
priv->title = _("Choose a color for note");
150
bjb_color_button_constructed (GObject *obj)
152
G_OBJECT_CLASS (bjb_color_button_parent_class)->constructed (obj);
156
bjb_color_button_finalize (GObject *object)
158
G_OBJECT_CLASS (bjb_color_button_parent_class)->finalize (object);
162
bjb_color_button_class_init (BjbColorButtonClass *klass)
164
GObjectClass *object_class = G_OBJECT_CLASS (klass);
165
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
167
g_type_class_add_private (klass, sizeof (BjbColorButtonPrivate));
169
object_class->constructed = bjb_color_button_constructed;
170
object_class->finalize = bjb_color_button_finalize;
172
/* Override std::gtk_color_button */
173
button_class->clicked = bjb_color_button_clicked;
177
bjb_color_button_new (void)
179
return g_object_new (BJB_TYPE_COLOR_BUTTON, NULL);