File: kz-rb-sidebar.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 (101 lines) | stat: -rw-r--r-- 2,885 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
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */

/*
 *  Copyright (C) 2006 Kouhei Sutou <kou@cozmixng.org>
 *
 *  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"

#include "kz-sidebar.h"

#define _SELF(obj) (KZ_SIDEBAR(RVAL2GOBJ(obj)))
#define RVAL2GTKWIDGET(obj) (GTK_WIDGET(RVAL2GOBJ(obj)))

static VALUE mKzSidebarFactory;

static VALUE
rb_kz_sidebar_new(VALUE self, VALUE kz)
{
    GtkWidget *sidebar;

    sidebar = kz_sidebar_new(RVAL2KZWIN(kz));
    RBGTK_INITIALIZE(self, sidebar);

    return Qnil;
}

static VALUE
rb_kz_sidebar_get_current(VALUE self)
{
    return CSTR2RVAL(kz_sidebar_get_current(_SELF(self)));
}

static VALUE
rb_kz_sidebar_set_current(VALUE self, VALUE label)
{
    return RVAL2CBOOL(kz_sidebar_set_current(_SELF(self), RVAL2CSTR(label)));
}

static GtkWidget *
rb_kz_sidebar_entry_create (KzSidebarEntry *entry, KzSidebar *sidebar)
{
    VALUE widget;

    widget = rb_funcall(mKzSidebarFactory, rb_intern("create"),
                        2, CSTR2RVAL(entry->label), GOBJ2RVAL(sidebar));

    return NIL_P(widget) ? NULL : RVAL2GTKWIDGET(widget);
}

void
kz_rb_setup_sidebar(KzWindow *kz)
{
    int i, len;
    VALUE entries;

    entries = rb_funcall(mKzSidebarFactory, rb_intern("entries"), 0);

    len = RARRAY(entries)->len;
    for (i = 0; i < len; i++) {
        VALUE entry_info;
        KzSidebarEntry *entry;

        entry_info = RARRAY(entries)->ptr[i];
        entry = g_new0(KzSidebarEntry, 1);
        entry->priority_hint = NUM2INT(RARRAY(entry_info)->ptr[0]);
        entry->label = RVAL2CSTR(RARRAY(entry_info)->ptr[1]);
        entry->icon = RVAL2CSTR2(RARRAY(entry_info)->ptr[2]);
        entry->create = rb_kz_sidebar_entry_create;
        kz_sidebar_append_entry(entry);
    }
}

void
Init_kz_rb_sidebar(VALUE mKz)
{
    VALUE cKzSidebar;

    cKzSidebar = G_DEF_CLASS(KZ_TYPE_SIDEBAR, "Sidebar", mKz);
    mKzSidebarFactory = rb_define_module_under(mKz, "SidebarFactory");

    rb_define_method(cKzSidebar, "initialize", rb_kz_sidebar_new, 1);

    rb_define_method(cKzSidebar, "current", rb_kz_sidebar_get_current, 0);
    rb_define_method(cKzSidebar, "set_current", rb_kz_sidebar_set_current, 1);

    G_DEF_SETTERS(cKzSidebar);
}