File: toolbar.c

package info (click to toggle)
zapping 0.10~cvs6-16
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,008 kB
  • sloc: ansic: 110,600; asm: 11,770; sh: 9,809; xml: 3,186; makefile: 1,227; perl: 488
file content (284 lines) | stat: -rw-r--r-- 8,783 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
 *  Zapping TV viewer
 *
 *  Copyright (C) 2000, 2001, 2002 Iaki Garca Etxebarria
 *  Copyright (C) 2000, 2001, 2002, 2003, 2004 Michael H. Schimek
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* $Id: toolbar.c,v 1.3 2005/01/08 14:54:24 mschimek Exp $ */

#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gdk-pixdata.h>

#include "src/zmisc.h"
#include "src/remote.h"

#include "pixmaps/left.h"
#include "pixmaps/down.h"
#include "pixmaps/up.h"
#include "pixmaps/right.h"
#include "pixmaps/reveal.h"

#include "toolbar.h"

void
teletext_toolbar_set_url	(TeletextToolbar *	toolbar,
				 vbi3_pgno		pgno,
				 vbi3_subno		subno)
{
  gchar buffer[16];

  if ((guint) subno > 0x99)
    subno = 0; /* 0, VBI3_ANY_SUBNO, 0x2359, bug */

  snprintf (buffer, 16, "%3x.%02x", pgno & 0xFFF, subno);

  gtk_label_set_text (toolbar->url, buffer);
}

static void
on_hold_toggled			(GtkToggleButton *	button,
				 gpointer		user_data _unused_)
{
  python_command_printf (GTK_WIDGET (button),
			 "zapping.ttx_hold(%u)",
			 gtk_toggle_button_get_active (button));
}

static void
on_reveal_toggled		(GtkToggleToolButton *	button,
				 gpointer		user_data _unused_)
{
  python_command_printf (GTK_WIDGET (button),
			 "zapping.ttx_reveal(%u)",
			 gtk_toggle_tool_button_get_active (button));
}

static GtkWidget *
button_new_from_pixdata		(const GdkPixdata *	pixdata,
				 const gchar *		tooltip,
				 GtkReliefStyle		relief_style,
				 const gchar *		py_cmd)
{
  GtkWidget *button;
  GtkWidget *icon;

  icon = z_gtk_image_new_from_pixdata (pixdata);
  gtk_widget_show (icon);

  button = gtk_button_new ();
  gtk_widget_show (button);

  gtk_container_add (GTK_CONTAINER (button), icon);
  gtk_button_set_relief (GTK_BUTTON (button), relief_style);
  gtk_widget_set_tooltip_text (button, tooltip);

  z_signal_connect_python (G_OBJECT (button), "clicked", py_cmd);

  return button;
}

static void
cb_widget_destroy (GtkWidget *widget, gpointer data)
{
  gtk_widget_destroy (widget);
}

/* XXX How can we do this with GtkActions? */

static void
on_orientation_changed		(GtkToolbar *		toolbar,
				 GtkOrientation		orientation,
				 TeletextToolbar *	t)
{
  GtkReliefStyle button_relief;
  GtkWidget *up;
  GtkWidget *down;
  GtkWidget *left;
  GtkWidget *right;

  gtk_container_foreach (GTK_CONTAINER (t->box1), cb_widget_destroy, NULL);
  gtk_container_foreach (GTK_CONTAINER (t->box2), cb_widget_destroy, NULL);

  button_relief = GTK_RELIEF_NORMAL;
  gtk_widget_style_get (GTK_WIDGET (toolbar), "button_relief",
			&button_relief, NULL);

  up = button_new_from_pixdata
    (&up_png, _("Next page"),
     button_relief, "zapping.ttx_page_incr(1)");
  down = button_new_from_pixdata
    (&down_png, _("Previous page"),
     button_relief, "zapping.ttx_page_incr(-1)");
  left = button_new_from_pixdata
    (&left_png, _("Previous subpage"),
     button_relief, "zapping.ttx_subpage_incr(-1)");
  right = button_new_from_pixdata
    (&right_png, _("Next subpage"),
     button_relief, "zapping.ttx_subpage_incr(1)");

  switch (orientation)
    {
    case GTK_ORIENTATION_HORIZONTAL:
      SWAP (up, left);

      /* fall through */

    case GTK_ORIENTATION_VERTICAL:
      gtk_box_pack_start (t->box1, up,    FALSE, FALSE, 0);
      gtk_box_pack_start (t->box1, down,  FALSE, FALSE, 0);
      gtk_box_pack_start (t->box2, left,  FALSE, FALSE, 0);
      gtk_box_pack_start (t->box2, right, FALSE, FALSE, 0);

      break;
    }
}

static void
instance_init			(GTypeInstance *	instance _unused_,
				 gpointer		g_class _unused_)
{
  /*  TeletextToolbar *toolbar = (TeletextToolbar *) instance; */
}

/* ugh that should take a TeletextView* */
GtkWidget *
teletext_toolbar_new		(GtkActionGroup *action_group)
{
  TeletextToolbar *toolbar;
  GtkWidget *widget;
  GtkReliefStyle button_relief;
  GtkToolItem *tool_item;

  toolbar = TELETEXT_TOOLBAR (g_object_new (TYPE_TELETEXT_TOOLBAR, NULL));

  widget = GTK_WIDGET (toolbar);
  button_relief = GTK_RELIEF_NORMAL;
  gtk_widget_ensure_style (widget);
  gtk_widget_style_get (widget, "button_relief", &button_relief, NULL);

  widget = gtk_action_create_tool_item
    (gtk_action_group_get_action (action_group, "HistoryBack"));
  gtk_toolbar_insert (&toolbar->toolbar, GTK_TOOL_ITEM (widget), APPEND);

  widget = gtk_action_create_tool_item
    (gtk_action_group_get_action (action_group, "HistoryForward"));
  gtk_toolbar_insert (&toolbar->toolbar, GTK_TOOL_ITEM (widget), APPEND);

  widget = gtk_action_create_tool_item
    (gtk_action_group_get_action (action_group, "Home"));
  gtk_toolbar_insert (&toolbar->toolbar, GTK_TOOL_ITEM (widget), APPEND);

  /* XXX should use NewTeletextView action. */
  tool_item = gtk_tool_button_new (NULL, "_New");
  gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (tool_item), "document-new");
  gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item),
                               _("Open new Teletext window"));
  z_signal_connect_python (tool_item, "clicked",
			   "zapping.ttx_open_new()");
  gtk_toolbar_insert (&toolbar->toolbar, tool_item, APPEND);

  widget = gtk_action_create_tool_item
    (gtk_action_group_get_action (action_group, "Search"));
  gtk_toolbar_insert (&toolbar->toolbar, GTK_TOOL_ITEM (widget), APPEND);

  widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  tool_item = gtk_tool_item_new ();
  gtk_container_add (GTK_CONTAINER (tool_item), widget);
  gtk_widget_show_all (GTK_WIDGET (tool_item));
  toolbar->box1 = GTK_BOX (widget);
  gtk_toolbar_insert (&toolbar->toolbar, tool_item, APPEND);

  {
    GtkWidget *frame;

    widget = gtk_toggle_button_new ();
    tool_item = gtk_tool_item_new ();
    gtk_container_add (GTK_CONTAINER (tool_item), widget);
    gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item),
                                 _("Hold the current subpage"));
    gtk_widget_show_all (GTK_WIDGET (tool_item));
    toolbar->hold = GTK_TOGGLE_BUTTON (widget);
    gtk_button_set_relief (GTK_BUTTON (widget), button_relief);
    gtk_toolbar_insert (&toolbar->toolbar, tool_item, APPEND);

    g_signal_connect (G_OBJECT (widget), "clicked",
		      G_CALLBACK (on_hold_toggled), toolbar);

    frame = gtk_frame_new (NULL);
    gtk_widget_show (frame);
    gtk_container_add (GTK_CONTAINER (widget), frame);

    widget = gtk_label_new ("888.88");
    gtk_widget_show (widget);
    toolbar->url = GTK_LABEL (widget);
    gtk_container_add (GTK_CONTAINER (frame), widget);
  }

  widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  tool_item = gtk_tool_item_new ();
  gtk_container_add (GTK_CONTAINER (tool_item), widget);
  gtk_widget_show_all (GTK_WIDGET (tool_item));
  toolbar->box2 = GTK_BOX (widget);
  gtk_toolbar_insert (&toolbar->toolbar, tool_item, APPEND);

  widget = z_gtk_image_new_from_pixdata (&reveal_png);
  tool_item = gtk_toggle_tool_button_new ();
  toolbar->reveal = GTK_TOGGLE_TOOL_BUTTON (tool_item);
  gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (tool_item), widget);
  gtk_tool_button_set_label (GTK_TOOL_BUTTON (tool_item), _("Reveal"));
  gtk_widget_set_tooltip_text (GTK_WIDGET (tool_item),
                               _("Reveal concealed text"));
  gtk_widget_show_all (GTK_WIDGET (tool_item));
  gtk_toggle_tool_button_set_active (toolbar->reveal, FALSE);
  gtk_toolbar_insert (&toolbar->toolbar, tool_item, APPEND);
  g_signal_connect (tool_item, "toggled",
		    G_CALLBACK (on_reveal_toggled), toolbar);

  g_signal_connect (G_OBJECT (&toolbar->toolbar), "orientation-changed",
		    G_CALLBACK (on_orientation_changed), toolbar);

  on_orientation_changed (&toolbar->toolbar,
			  gtk_orientable_get_orientation
			  (GTK_ORIENTABLE (&toolbar->toolbar)),
			  toolbar);

  return GTK_WIDGET (toolbar);
}

GType
teletext_toolbar_get_type		(void)
{
  static GType type = 0;
  
  if (!type)
    {
      GTypeInfo info;

      CLEAR (info);

      info.class_size = sizeof (TeletextToolbarClass);
      info.instance_size = sizeof (TeletextToolbar);
      info.instance_init = instance_init;

      type = g_type_register_static (GTK_TYPE_TOOLBAR,
				     "TeletextToolbar",
				     &info, (GTypeFlags) 0);
    }

  return type;
}