1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the GtkHTML library. |
---|
3 | |
---|
4 | Copyright (C) 2000 Jonas Borgström <jonas_b@bitsmart.com>. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | #include <gtk/gtkcheckbutton.h> |
---|
24 | #include <gtk/gtktogglebutton.h> |
---|
25 | #include "htmlcheckbox.h" |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | HTMLCheckBoxClass html_checkbox_class; |
---|
29 | static HTMLEmbeddedClass *parent_class = NULL; |
---|
30 | |
---|
31 | |
---|
32 | static void |
---|
33 | copy (HTMLObject *self, |
---|
34 | HTMLObject *dest) |
---|
35 | { |
---|
36 | (* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest); |
---|
37 | |
---|
38 | HTML_CHECKBOX (dest)->default_checked = HTML_CHECKBOX (self)->default_checked; |
---|
39 | } |
---|
40 | |
---|
41 | static gchar * |
---|
42 | encode (HTMLEmbedded *e) |
---|
43 | { |
---|
44 | GString *encoding = g_string_new (""); |
---|
45 | gchar *ptr; |
---|
46 | |
---|
47 | if(strlen (e->name) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (e->widget))) { |
---|
48 | |
---|
49 | ptr = html_embedded_encode_string (e->name); |
---|
50 | encoding = g_string_append (encoding, ptr); |
---|
51 | g_free (ptr); |
---|
52 | |
---|
53 | encoding = g_string_append_c (encoding, '='); |
---|
54 | |
---|
55 | ptr = html_embedded_encode_string (e->value); |
---|
56 | encoding = g_string_append (encoding, ptr); |
---|
57 | g_free (ptr); |
---|
58 | } |
---|
59 | |
---|
60 | ptr = encoding->str; |
---|
61 | g_string_free(encoding, FALSE); |
---|
62 | |
---|
63 | return ptr; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | static void |
---|
68 | reset (HTMLEmbedded *e) |
---|
69 | { |
---|
70 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e->widget), HTML_CHECKBOX(e)->default_checked); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | void |
---|
75 | html_checkbox_type_init (void) |
---|
76 | { |
---|
77 | html_checkbox_class_init (&html_checkbox_class, HTML_TYPE_CHECKBOX, sizeof (HTMLCheckBoxClass)); |
---|
78 | } |
---|
79 | |
---|
80 | void |
---|
81 | html_checkbox_class_init (HTMLCheckBoxClass *klass, |
---|
82 | HTMLType type, |
---|
83 | guint size) |
---|
84 | { |
---|
85 | HTMLEmbeddedClass *element_class; |
---|
86 | HTMLObjectClass *object_class; |
---|
87 | |
---|
88 | |
---|
89 | element_class = HTML_EMBEDDED_CLASS (klass); |
---|
90 | object_class = HTML_OBJECT_CLASS (klass); |
---|
91 | |
---|
92 | html_embedded_class_init (element_class, type, size); |
---|
93 | |
---|
94 | /* HTMLObject methods. */ |
---|
95 | object_class->copy = copy; |
---|
96 | |
---|
97 | /* HTMLEmbedded methods. */ |
---|
98 | element_class->reset = reset; |
---|
99 | element_class->encode = encode; |
---|
100 | |
---|
101 | parent_class = &html_embedded_class; |
---|
102 | } |
---|
103 | |
---|
104 | void |
---|
105 | html_checkbox_init (HTMLCheckBox *checkbox, |
---|
106 | HTMLCheckBoxClass *klass, |
---|
107 | GtkWidget *parent, |
---|
108 | gchar *name, |
---|
109 | gchar *value, |
---|
110 | gboolean checked) |
---|
111 | { |
---|
112 | HTMLEmbedded *element; |
---|
113 | HTMLObject *object; |
---|
114 | GtkWidget *check; |
---|
115 | |
---|
116 | element = HTML_EMBEDDED (checkbox); |
---|
117 | object = HTML_OBJECT (checkbox); |
---|
118 | |
---|
119 | if (value == NULL) |
---|
120 | value = g_strdup ("on"); |
---|
121 | |
---|
122 | html_embedded_init (element, HTML_EMBEDDED_CLASS (klass), parent, name, value); |
---|
123 | |
---|
124 | check = gtk_check_button_new(); |
---|
125 | html_embedded_set_widget (element, check); |
---|
126 | |
---|
127 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), checked); |
---|
128 | checkbox->default_checked = checked; |
---|
129 | |
---|
130 | /* gtk_widget_show(element->widget); |
---|
131 | gtk_layout_put(GTK_LAYOUT(parent), element->widget, 0, 0);*/ |
---|
132 | } |
---|
133 | |
---|
134 | HTMLObject * |
---|
135 | html_checkbox_new (GtkWidget *parent, |
---|
136 | gchar *name, |
---|
137 | gchar *value, |
---|
138 | gboolean checked) |
---|
139 | { |
---|
140 | HTMLCheckBox *checkbox; |
---|
141 | |
---|
142 | checkbox = g_new0 (HTMLCheckBox, 1); |
---|
143 | html_checkbox_init (checkbox, &html_checkbox_class, parent, name, value, checked); |
---|
144 | |
---|
145 | return HTML_OBJECT (checkbox); |
---|
146 | } |
---|