File: kz-rb-window.c

package info (click to toggle)
kazehakase 0.4.2-1etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,260 kB
  • ctags: 7,377
  • sloc: ansic: 62,697; cpp: 13,422; sh: 9,083; ruby: 1,588; makefile: 1,026; xml: 372
file content (371 lines) | stat: -rw-r--r-- 10,408 bytes parent folder | download | duplicates (2)
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */

/*
 *  Copyright (C) 2006 Eriko Sato
 *
 *  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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "kz-rb-ext.h"

#define _SELF(obj) RVAL2KZWIN(obj)
#define RVAL2GTKWIDGET(obj) (GTK_WIDGET(RVAL2GOBJ(obj)))
#define RVAL2GTKACTION(obj) (GTK_ACTION(RVAL2GOBJ(obj)))
#define RVAL2GNODE(obj) (GTK_GNODE(RVAL2GOBJ(obj)))
#define RVAL2KZBOOKMARK(obj) (KZ_BOOKMARK(RVAL2GOBJ(obj)))

static ID id_default;

static VALUE
rb_kz_window_new(int argc, VALUE *argv, VALUE self)
{
    VALUE url;
    GtkWidget *window;

    rb_scan_args(argc, argv, "01", &url);
    window = kz_window_new(NIL_P(url) ? NULL : RVAL2CSTR(url));
    RBGTK_INITIALIZE(self, window);
    return Qnil;
}

static VALUE
rb_kz_window_get_window_list(VALUE self)
{
    GList *list;
    list = (GList *)kz_window_get_window_list();
    return GLIST2ARY(list);
}

static VALUE
rb_kz_window_set_default(VALUE self, VALUE window)
{
    rb_cvar_set(self, id_default, window, Qfalse);
    return Qnil;
}

static VALUE
rb_kz_window_get_default(VALUE self)
{
    return rb_cvar_get(self, id_default);
}

static VALUE
rb_kz_window_open_new_tab(VALUE self, VALUE url)
{
    GtkWidget *widget;
    widget = kz_window_open_new_tab(_SELF(self), RVAL2CSTR(url));
    return GOBJ2RVAL(widget);
}

static VALUE
rb_kz_window_open_new_tab_at_tail(VALUE self, VALUE url)
{
    GtkWidget *widget;
    widget = kz_window_open_new_tab_at_tail(_SELF(self), RVAL2CSTR(url));
    return GOBJ2RVAL(widget);
}

static VALUE
rb_kz_window_open_new_tab_with_parent(VALUE self, VALUE url, VALUE parent)
{
    GtkWidget *widget;
    widget = kz_window_open_new_tab_with_parent(_SELF(self),
                                                RVAL2CSTR(url),
                                                RVAL2GTKWIDGET(parent));
    return GOBJ2RVAL(widget);
}

static VALUE
rb_kz_window_close_tab(VALUE self, VALUE widget)
{
    kz_window_close_tab(_SELF(self), RVAL2GTKWIDGET(widget));
    return self;
}

static VALUE
rb_kz_window_close_all_tab(VALUE self)
{
    kz_window_close_all_tab(_SELF(self));
    return self;
}

static VALUE
rb_kz_window_reorder_tab(VALUE self, VALUE widget, VALUE position)
{
    kz_window_reorder_tab(_SELF(self), RVAL2GTKWIDGET(widget),
                          NUM2INT(position));
    return self;
}

static VALUE
rb_kz_window_move_tab(VALUE self, VALUE widget)
{
    kz_window_move_tab(_SELF(self), RVAL2GTKWIDGET(widget));
    return self;
}

static VALUE
rb_kz_window_load_url(VALUE self, VALUE url)
{
    kz_window_load_url(_SELF(self), RVAL2CSTR(url));
    return self;
}

static VALUE
rb_kz_window_store_state(VALUE self)
{
    kz_window_store_state(_SELF(self));
    return self;
}

static VALUE
rb_kz_window_restore_state(VALUE self)
{
    kz_window_restore_state(_SELF(self));
    return self;
}

static VALUE
rb_kz_window_connect_action(VALUE self, VALUE action)
{
    kz_window_connect_action(_SELF(self), RVAL2GTKACTION(action));
    return Qnil;
}

static VALUE
rb_kz_window_disconnect_action(VALUE self, VALUE action)
{
    kz_window_disconnect_action(_SELF(self), RVAL2GTKACTION(action));
    return Qnil;
}

static VALUE
rb_kz_window_update_gesture_items(VALUE self)
{
  kz_window_update_gesture_items(_SELF(self));
  return self;
}

static VALUE
rb_kz_window_get_title(VALUE self)
{
    const gchar *title;
    title = kz_window_get_title(_SELF(self));
    return CSTR2RVAL(title);
}

static VALUE
rb_kz_window_get_uri(VALUE self)
{
    const gchar *uri;
    uri = kz_window_get_uri(_SELF(self));
    return CSTR2RVAL(uri);
}

static VALUE
rb_kz_window_get_tab_label(VALUE self, VALUE widget)
{
    GtkWidget *Widget;
    Widget = kz_window_get_tab_label(_SELF(self),
                                     RVAL2GTKWIDGET(widget));
    return GOBJ2RVAL(Widget);
}

static VALUE
rb_kz_window_get_tree(VALUE self)
{
    GNode *node;
    node = kz_window_get_tree(_SELF(self));
    return GOBJ2RVAL(node);
}

static VALUE
rb_kz_window_activate_action(VALUE self, VALUE name)
{
    return CBOOL2RVAL(kz_window_activate_action(_SELF(self), RVAL2CSTR(name)));
}

static VALUE
rb_kz_window_activate_popup_action(VALUE self, VALUE name)
{
    return CBOOL2RVAL(kz_window_activate_popup_action(_SELF(self),
                                                      RVAL2CSTR(name)));
}

static VALUE
rb_kz_window_activate_tabpop_action(VALUE self, VALUE name)
{
    return CBOOL2RVAL(kz_window_activate_tabpop_action(_SELF(self),
                                                       RVAL2CSTR(name)));
}

static VALUE
rb_kz_window_get_mouse_event_info(VALUE self)
{
    const KzEmbedEventMouse *event_mouse;
    event_mouse = kz_window_get_mouse_event_info(_SELF(self));
    return EVENTMOUSE2RVAL((KzEmbedEventMouse *)event_mouse);
}

static VALUE
rb_kz_window_append_closed_tab(VALUE self, VALUE bookmark)
{
    kz_window_append_closed_tab(_SELF(self), RVAL2KZBOOKMARK(bookmark));
    return self;
}


/* reader */
static VALUE
rb_kz_window_actions(VALUE self)
{
    VALUE actions = GOBJ2RVAL(_SELF(self)->actions);
    G_CHILD_ADD(self, actions);
    return actions;
}

static VALUE
rb_kz_window_popup_actions(VALUE self)
{
    VALUE popup_actions = GOBJ2RVAL(_SELF(self)->popup_actions);
    G_CHILD_ADD(self, popup_actions);
    return popup_actions;
}

static VALUE
rb_kz_window_tabpop_actions(VALUE self)
{
    VALUE tabpop_actions = GOBJ2RVAL(_SELF(self)->tabpop_actions);
    G_CHILD_ADD(self, tabpop_actions);
    return tabpop_actions;
}

static VALUE
rb_kz_window_menu_merge(VALUE self)
{
    VALUE menu_merge = GOBJ2RVAL(_SELF(self)->menu_merge);
    G_CHILD_ADD(self, menu_merge);
    return menu_merge;
}

static VALUE
rb_kz_window_sidebar(VALUE self)
{
    VALUE sidebar = GOBJ2RVAL(_SELF(self)->sidebar);
    G_CHILD_ADD(self, sidebar);
    return sidebar;
}

static VALUE
rb_kz_window_statusbar(VALUE self)
{
    VALUE statusbar = GOBJ2RVAL(_SELF(self)->statusbar);
    G_CHILD_ADD(self, statusbar);
    return statusbar;
}



static VALUE
rb_kz_window_nth_page(VALUE self, VALUE n)
{
  return GOBJ2RVAL(KZ_WINDOW_NTH_PAGE(_SELF(self), NUM2INT(n)));
}

static VALUE
rb_kz_window_current_page(VALUE self)
{
  return GOBJ2RVAL(KZ_WINDOW_CURRENT_PAGE(_SELF(self)));
}

void
Init_kz_rb_window(VALUE mKz)
{
    VALUE cKzWindow;

    id_default = rb_intern("@@default");

    cKzWindow = G_DEF_CLASS(KZ_TYPE_WINDOW, "Window", mKz);

    rb_define_singleton_method(cKzWindow, "set_default",
                               rb_kz_window_set_default, 1);
    rb_alias(rb_singleton_class(cKzWindow),
             rb_intern("default="), rb_intern("set_default"));
    rb_define_singleton_method(cKzWindow, "default",
                               rb_kz_window_get_default, 0);

    rb_define_singleton_method(cKzWindow, "list",
                               rb_kz_window_get_window_list, 0);

    rb_define_method(cKzWindow, "initialize", rb_kz_window_new, -1);

    rb_define_method(cKzWindow, "open_new_tab",
                     rb_kz_window_open_new_tab, 1);
    rb_define_method(cKzWindow, "open_new_tab_at_tail",
                     rb_kz_window_open_new_tab_at_tail, 1);
    rb_define_method(cKzWindow, "open_new_tab_with_parent",
                     rb_kz_window_open_new_tab_with_parent, 2);
    rb_define_method(cKzWindow, "close_tab", rb_kz_window_close_tab, 1);
    rb_define_method(cKzWindow, "close_all_tab",
                     rb_kz_window_close_all_tab, 0);
    rb_define_method(cKzWindow, "reorder_tab",
                     rb_kz_window_reorder_tab, 2);
    rb_define_method(cKzWindow, "move_tab", rb_kz_window_move_tab, 1);
    rb_define_method(cKzWindow, "load_url", rb_kz_window_load_url, 1);
    rb_define_method(cKzWindow, "store_state",
                     rb_kz_window_store_state, 0);
    rb_define_method(cKzWindow, "restore_state",
                     rb_kz_window_restore_state, 0);
    rb_define_method(cKzWindow, "connect_action",
                     rb_kz_window_connect_action, 1);
    rb_define_method(cKzWindow, "disconnect_action",
                     rb_kz_window_disconnect_action, 1);
    rb_define_method(cKzWindow, "update_gesture_items",
                     rb_kz_window_update_gesture_items, 0);
    rb_define_method(cKzWindow, "title", rb_kz_window_get_title, 0);
    rb_define_method(cKzWindow, "uri", rb_kz_window_get_uri, 0);
    rb_define_method(cKzWindow, "get_tab_label",
                     rb_kz_window_get_tab_label, 1);
    rb_define_method(cKzWindow, "tree", rb_kz_window_get_tree, 0);

    rb_define_method(cKzWindow, "activate_action",
                     rb_kz_window_activate_action, 1);
    rb_define_method(cKzWindow, "activate_popup_action",
                     rb_kz_window_activate_popup_action, 1);
    rb_define_method(cKzWindow, "activate_tabpop_action",
                     rb_kz_window_activate_tabpop_action, 1);

    rb_define_method(cKzWindow, "mouse_event_info",
                     rb_kz_window_get_mouse_event_info, 0);
    rb_define_method(cKzWindow, "append_closed_tab",
                     rb_kz_window_append_closed_tab, 1);


    /* reader */
    rb_define_method(cKzWindow, "actions", rb_kz_window_actions, 0);
    rb_define_method(cKzWindow, "popup_actions",
                     rb_kz_window_popup_actions, 0);
    rb_define_method(cKzWindow, "tabpop_actions",
                     rb_kz_window_tabpop_actions, 0);
    rb_define_method(cKzWindow, "menu_merge", rb_kz_window_menu_merge, 0);
    rb_define_method(cKzWindow, "sidebar", rb_kz_window_sidebar, 0);
    rb_define_method(cKzWindow, "statusbar", rb_kz_window_statusbar, 0);

    rb_define_method(cKzWindow, "current_page", rb_kz_window_current_page, 0);
    rb_define_method(cKzWindow, "nth_page", rb_kz_window_nth_page, 1);


    G_DEF_SETTERS(cKzWindow);
}