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/gtkradiobutton.h> |
---|
24 | #include "htmlform.h" |
---|
25 | #include "htmlradio.h" |
---|
26 | #include <string.h> |
---|
27 | |
---|
28 | |
---|
29 | HTMLRadioClass html_radio_class; |
---|
30 | static HTMLEmbeddedClass *parent_class = NULL; |
---|
31 | |
---|
32 | |
---|
33 | /* HTMLObject methods. */ |
---|
34 | static void |
---|
35 | copy (HTMLObject *self, |
---|
36 | HTMLObject *dest) |
---|
37 | { |
---|
38 | (* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest); |
---|
39 | |
---|
40 | HTML_RADIO (dest)->default_checked = HTML_RADIO (self)->default_checked; |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | /* HTMLEmbedded methods. */ |
---|
45 | static void |
---|
46 | reset (HTMLEmbedded *e) |
---|
47 | { |
---|
48 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(e->widget), HTML_RADIO(e)->default_checked); |
---|
49 | } |
---|
50 | |
---|
51 | static gchar * |
---|
52 | encode (HTMLEmbedded *e) |
---|
53 | { |
---|
54 | GString *encoding = g_string_new (""); |
---|
55 | gchar *ptr; |
---|
56 | |
---|
57 | if(strlen (e->name) && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (e->widget))) { |
---|
58 | |
---|
59 | ptr = html_embedded_encode_string (e->name); |
---|
60 | encoding = g_string_append (encoding, ptr); |
---|
61 | g_free (ptr); |
---|
62 | |
---|
63 | encoding = g_string_append_c (encoding, '='); |
---|
64 | |
---|
65 | ptr = html_embedded_encode_string (e->value); |
---|
66 | encoding = g_string_append (encoding, ptr); |
---|
67 | g_free (ptr); |
---|
68 | } |
---|
69 | |
---|
70 | ptr = encoding->str; |
---|
71 | g_string_free(encoding, FALSE); |
---|
72 | |
---|
73 | return ptr; |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | void |
---|
78 | html_radio_type_init (void) |
---|
79 | { |
---|
80 | html_radio_class_init (&html_radio_class, HTML_TYPE_RADIO, sizeof (HTMLRadio)); |
---|
81 | } |
---|
82 | |
---|
83 | void |
---|
84 | html_radio_class_init (HTMLRadioClass *klass, |
---|
85 | HTMLType type, |
---|
86 | guint object_size) |
---|
87 | { |
---|
88 | HTMLEmbeddedClass *element_class; |
---|
89 | HTMLObjectClass *object_class; |
---|
90 | |
---|
91 | element_class = HTML_EMBEDDED_CLASS (klass); |
---|
92 | object_class = HTML_OBJECT_CLASS (klass); |
---|
93 | |
---|
94 | html_embedded_class_init (element_class, type, object_size); |
---|
95 | |
---|
96 | /* HTMLObject methods. */ |
---|
97 | object_class->copy = copy; |
---|
98 | |
---|
99 | /* HTMLEmbedded methods. */ |
---|
100 | element_class->reset = reset; |
---|
101 | element_class->encode = encode; |
---|
102 | |
---|
103 | parent_class = &html_embedded_class; |
---|
104 | } |
---|
105 | |
---|
106 | void |
---|
107 | html_radio_init (HTMLRadio *radio, |
---|
108 | HTMLRadioClass *klass, |
---|
109 | GtkWidget *parent, |
---|
110 | gchar *name, |
---|
111 | gchar *value, |
---|
112 | gboolean checked, |
---|
113 | HTMLForm *form) |
---|
114 | { |
---|
115 | HTMLEmbedded *element; |
---|
116 | HTMLObject *object; |
---|
117 | GtkWidget *widget; |
---|
118 | |
---|
119 | element = HTML_EMBEDDED (radio); |
---|
120 | object = HTML_OBJECT (radio); |
---|
121 | |
---|
122 | if (value == NULL) |
---|
123 | value = g_strdup ("on"); |
---|
124 | |
---|
125 | html_embedded_init (element, HTML_EMBEDDED_CLASS (klass), parent, name, value); |
---|
126 | |
---|
127 | widget = gtk_radio_button_new (NULL); |
---|
128 | html_embedded_set_widget (element, widget); |
---|
129 | html_form_add_radio (form, name, GTK_RADIO_BUTTON (widget)); |
---|
130 | |
---|
131 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), checked); |
---|
132 | radio->default_checked = checked; |
---|
133 | } |
---|
134 | |
---|
135 | HTMLObject * |
---|
136 | html_radio_new (GtkWidget *parent, |
---|
137 | gchar *name, |
---|
138 | gchar *value, |
---|
139 | gboolean checked, |
---|
140 | HTMLForm *form) |
---|
141 | { |
---|
142 | HTMLRadio *radio; |
---|
143 | |
---|
144 | radio = g_new0 (HTMLRadio, 1); |
---|
145 | html_radio_init (radio, &html_radio_class, parent, name, value, checked, form); |
---|
146 | |
---|
147 | return HTML_OBJECT (radio); |
---|
148 | } |
---|