File: pp_units.cpp

package info (click to toggle)
photoprint 0.3.8b-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,396 kB
  • ctags: 3,472
  • sloc: cpp: 25,818; sh: 9,132; ansic: 4,778; makefile: 491; sed: 16
file content (174 lines) | stat: -rw-r--r-- 3,979 bytes parent folder | download | duplicates (4)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 *
 * Copyright (c) 2004 by Alastair M. Robinson
 * Distributed under the terms of the GNU General Public License -
 * see the file named "COPYING" for more details.
 *
 */

#include <string.h>

#include <gtk/gtk.h>
#include <gtk/gtkframe.h>
#include <gtk/gtksizegroup.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtkfilesel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkspinbutton.h>
#include <gtk/gtklabel.h>
#include <gtk/gtktable.h>
#include <gtk/gtkoptionmenu.h>
#include <gtk/gtkmenuitem.h>

#include "pp_units.h"
#include "dialogs.h"

#include "config.h"
#include "gettext.h"
#define _(x) gettext(x)

enum {
	CHANGED_SIGNAL,
	LAST_SIGNAL
};

static guint pp_units_signals[LAST_SIGNAL] = { 0 };

static void pp_units_class_init (pp_UnitsClass *klass);
static void pp_units_init (pp_Units *stpuicombo);


void pp_units_refresh(pp_Units *ob)
{

}


GtkWidget*
pp_units_new ()
{
	pp_Units *ob=PP_UNITS(g_object_new (pp_units_get_type (), NULL));
	gtk_box_set_spacing(GTK_BOX(ob),5);

	GtkWidget *label;
	GtkWidget *hbox;

	hbox=gtk_hbox_new(FALSE,0);
	gtk_box_pack_start(GTK_BOX(ob),hbox,TRUE,TRUE,0);
	gtk_widget_show(hbox);

	label=gtk_label_new(_("Units:"));
	gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,0);
	gtk_widget_show(label);

	ob->unitselector = gtk_option_menu_new ();      
	GtkWidget *menu, *menu_item;
	menu = gtk_menu_new ();

	menu_item = gtk_menu_item_new_with_label (_("Points"));
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	gtk_widget_show (menu_item);
	menu_item = gtk_menu_item_new_with_label (_("Inches"));
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	gtk_widget_show (menu_item);
	menu_item = gtk_menu_item_new_with_label (_("Millimeters"));
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	gtk_widget_show (menu_item);
	menu_item = gtk_menu_item_new_with_label (_("Centimeters"));
	gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
	gtk_widget_show (menu_item);
	
	gtk_option_menu_set_menu (GTK_OPTION_MENU (ob->unitselector), menu);
	
	gtk_box_pack_start(GTK_BOX(hbox),ob->unitselector,TRUE,TRUE,5);
	gtk_widget_show(ob->unitselector);

	pp_units_refresh(ob);

	return(GTK_WIDGET(ob));
}


GType
pp_units_get_type (void)
{
	static GType stpuic_type = 0;

	if (!stpuic_type)
	{
		static const GTypeInfo pp_units_info =
		{
			sizeof (pp_UnitsClass),
			NULL, /* base_init */
			NULL, /* base_finalize */
			(GClassInitFunc) pp_units_class_init,
			NULL, /* class_finalize */
			NULL, /* class_data */
			sizeof (pp_Units),
			0,
			(GInstanceInitFunc) pp_units_init,
		};
		stpuic_type = g_type_register_static (GTK_TYPE_VBOX, "pp_Units", &pp_units_info, (GTypeFlags)0);
	}
	return stpuic_type;
}


static void
pp_units_class_init (pp_UnitsClass *klass)
{
	pp_units_signals[CHANGED_SIGNAL] =
	g_signal_new ("changed",
		G_TYPE_FROM_CLASS (klass),
		GSignalFlags(G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
		G_STRUCT_OFFSET (pp_UnitsClass, changed),
		NULL, NULL,
		g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void
pp_units_init (pp_Units *ob)
{
}


void pp_units_set_unit(pp_Units *ob,enum Units unit)
{
	gtk_option_menu_set_history(GTK_OPTION_MENU(ob->unitselector),unit);
}


enum Units pp_units_get_unit(pp_Units *ob)
{
	int u=gtk_option_menu_get_history(GTK_OPTION_MENU(ob->unitselector));
	return(Units(u));
}


enum Units pp_units_run_dialog(enum Units unit,GtkWindow *parent)
{
	GtkWidget *dialog=gtk_dialog_new_with_buttons(_("Units"),
		parent,GtkDialogFlags(0),
		GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
		GTK_STOCK_OK,GTK_RESPONSE_OK,
		NULL);

	GtkWidget *uw=pp_units_new();
	pp_units_set_unit(PP_UNITS(uw),unit);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),uw,FALSE,FALSE,0);
	gtk_widget_show(uw);

	gtk_widget_show(dialog);
	gint result=gtk_dialog_run(GTK_DIALOG(dialog));
	switch(result)
	{
		case GTK_RESPONSE_CANCEL:
			break;
		case GTK_RESPONSE_OK:
			unit=pp_units_get_unit(PP_UNITS(uw));
			break;
	}
	gtk_widget_destroy(dialog);
	return(unit);
}