source: trunk/third/gtkhtml3/src/htmlbutton.c @ 19539

Revision 19539, 4.1 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r19538, which included commits to RCS files with non-trunk default branches.
Line 
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/gtkbutton.h>
24#include <gtk/gtksignal.h>
25#include "htmlbutton.h"
26#include "htmlform.h"
27#include <string.h>
28#include <libgnome/gnome-i18n.h>
29
30HTMLButtonClass html_button_class;
31
32static HTMLEmbeddedClass *parent_class = NULL;
33
34
35static void
36clicked_event (GtkWidget *widget, gpointer data)
37{
38        HTMLButton *b = HTML_BUTTON (data);
39        HTMLEmbedded *e = HTML_EMBEDDED (data);
40
41        switch (b->type) {
42        case BUTTON_SUBMIT:
43                b->successful = TRUE;
44                html_form_submit (HTML_FORM (e->form));
45                b->successful = FALSE;
46                break;
47
48        case BUTTON_RESET:
49                html_form_reset (HTML_FORM (e->form));
50                break;
51        default:
52                return;
53        }
54}
55
56
57static void
58copy (HTMLObject *self,
59      HTMLObject *dest)
60{
61        (* HTML_OBJECT_CLASS (parent_class)->copy) (self, dest);
62
63        HTML_BUTTON (dest)->type = HTML_BUTTON (self)->type;
64}
65
66
67static gchar *
68encode (HTMLEmbedded *e)
69{
70        GString *encoding = g_string_new ("");
71        gchar *ptr;
72
73        if(strlen (e->name) && (HTML_BUTTON(e)->successful)) {
74                ptr = html_embedded_encode_string (e->name);
75                encoding = g_string_append (encoding, ptr);
76                g_free (ptr);
77
78                encoding = g_string_append_c (encoding, '=');
79
80                ptr = html_embedded_encode_string (e->value);
81                encoding = g_string_append (encoding, ptr);
82                g_free (ptr);           
83        }
84
85        ptr = encoding->str;
86        g_string_free(encoding, FALSE);
87       
88        return ptr;
89}
90
91
92void
93html_button_type_init (void)
94{
95        html_button_class_init (&html_button_class, HTML_TYPE_BUTTON, sizeof (HTMLButton));
96}
97
98void
99html_button_class_init (HTMLButtonClass *klass,
100                        HTMLType type,
101                        guint object_size)
102{
103        HTMLEmbeddedClass *element_class;
104        HTMLObjectClass *object_class;
105
106        element_class = HTML_EMBEDDED_CLASS (klass);
107        object_class = HTML_OBJECT_CLASS (klass);
108
109        html_embedded_class_init (element_class, type, object_size);
110
111        object_class->copy = copy;
112        element_class->encode = encode;
113
114        parent_class = &html_embedded_class;
115}
116
117void
118html_button_init (HTMLButton *button,
119                  HTMLButtonClass *klass,
120                  GtkWidget *parent,
121                  gchar *name, gchar *value,
122                  HTMLButtonType type)
123{
124        HTMLEmbedded *element;
125        HTMLObject *object;
126        GtkWidget  *widget;
127
128        element = HTML_EMBEDDED (button);
129        object = HTML_OBJECT (button);
130        widget = NULL;
131
132        html_embedded_init (element, HTML_EMBEDDED_CLASS (klass), parent, name, value);
133       
134        if( strlen (element->value)) {
135                widget = gtk_button_new_with_label (element->value);
136        } else {
137                switch(type) {
138                case BUTTON_NORMAL:
139                        widget = gtk_button_new ();
140                        break;
141                case BUTTON_SUBMIT:
142                        widget = gtk_button_new_with_label (_("Submit Query"));
143                        break;
144                case BUTTON_RESET:
145                        widget = gtk_button_new_with_label (_("Reset"));
146                        break;
147                default:
148                        g_assert_not_reached ();
149                }
150        }
151
152        html_embedded_set_widget (element, widget);
153
154        g_signal_connect (widget, "clicked", G_CALLBACK (clicked_event), button);
155
156        button->type = type;
157        button->successful = FALSE;
158        /*      gtk_widget_show(element->widget);
159                gtk_layout_put(GTK_LAYOUT(parent), element->widget, 0, 0);*/
160}
161
162HTMLObject *
163html_button_new (GtkWidget *parent,
164                 gchar *name,
165                 gchar *value,
166                 HTMLButtonType type)
167{
168        HTMLButton *button;
169
170        button = g_new0 (HTMLButton, 1);
171        html_button_init (button, &html_button_class, parent, name, value, type);
172
173        return HTML_OBJECT (button);
174}
Note: See TracBrowser for help on using the repository browser.