File: color_dialog.c

package info (click to toggle)
gentoo 0.11.10-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,116 kB
  • ctags: 2,901
  • sloc: ansic: 23,849; makefile: 195
file content (66 lines) | stat: -rw-r--r-- 1,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
** 1999-05-02 -	A little color dialog module. Really just a convenience wrapper around
**		the GTK+ GtkColorSelection widget. Saves a few uppercase keystrokes.
** 1999-06-19 -	Adapted for the new dialog module.
*/

#include "gentoo.h"

#include "dialog.h"
#include "color_dialog.h"

typedef struct {
	GtkWidget	*colsel;		/* The core widget. */
	ColChangedFunc	func;
	gpointer	user;
} ColDlg;

/* ----------------------------------------------------------------------------------------- */

/* 1999-05-02 -	This gets called as the user changes color controls in dialog. Call callback. */
static void evt_color_changed(GtkWidget *wid, gpointer user)
{
	ColDlg		*dlg = user;

	if(dlg->func != NULL)
	{
		gdouble		rgb[3];
		GdkColor	col;

		gtk_color_selection_get_color(GTK_COLOR_SELECTION(dlg->colsel), rgb);
		col.pixel = 0UL;
		col.red   = rgb[0] * 65535.0;
		col.green = rgb[1] * 65535.0;
		col.blue  = rgb[2] * 65535.0;
		dlg->func(&col, dlg->user);
	}
}

gint cdl_dialog_sync_new_wait(const gchar *label, ColChangedFunc func, GdkColor *initial, gpointer user)
{
	static ColDlg	dlg;
	Dialog		*d;
	gint		res = -1;

	dlg.func = func;
	dlg.user = user;

	dlg.colsel = gtk_color_selection_new();
	gtk_color_selection_set_update_policy(GTK_COLOR_SELECTION(dlg.colsel), GTK_UPDATE_CONTINUOUS);
	gtk_signal_connect(GTK_OBJECT(dlg.colsel), "color_changed", GTK_SIGNAL_FUNC(evt_color_changed), &dlg);
	if(initial != NULL)
	{
		gdouble	color[3];

		color[0] = initial->red   / 65535.0;
		color[1] = initial->green / 65535.0;
		color[2] = initial->blue  / 65535.0;
		gtk_color_selection_set_color(GTK_COLOR_SELECTION(dlg.colsel), color);
	}

	d = dlg_dialog_sync_new(dlg.colsel, label ? label : "Edit Color", "OK|Cancel");
	res = dlg_dialog_sync_wait(d);
	dlg_dialog_sync_destroy(d);

	return res;
}