File: rbgtk-selection.c

package info (click to toggle)
ruby-gnome 3.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 29,112 kB
  • sloc: ansic: 97,029; ruby: 70,747; xml: 350; sh: 142; cpp: 45; makefile: 29
file content (168 lines) | stat: -rw-r--r-- 4,896 bytes parent folder | download | duplicates (6)
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
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/*
 *  Copyright (C) 2011  Ruby-GNOME2 Project Team
 *  Copyright (C) 2002,2003 Masao Mutoh
 *  Copyright (C) 1998-2000 Yukihiro Matsumoto,
 *                          Daisuke Kanda,
 *                          Hiroshi Igarashi
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *  MA  02110-1301  USA
 */

#include "rbgtk3private.h"

#define RG_TARGET_NAMESPACE mSelection

static VALUE
rg_s_owner_set(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
{
    gboolean ret;

    if (argc == 3){
        VALUE widget, selection, time;
        rb_scan_args(argc, argv, "30", &widget, &selection, &time);
        ret = gtk_selection_owner_set(RVAL2GTKWIDGET(widget), 
                                      RVAL2ATOM(selection), NUM2INT(time));
    } else {
        VALUE display, widget, selection, time;
        rb_scan_args(argc, argv, "40", &display, &widget, &selection, &time);
        ret = gtk_selection_owner_set_for_display(RVAL2GDKDISPLAYOBJECT(display),
                                                  RVAL2GTKWIDGET(widget), 
                                                  RVAL2ATOM(selection), NUM2INT(time));
    }
    return CBOOL2RVAL(ret);
}

static VALUE
rg_s_add_target(VALUE self, VALUE widget, VALUE selection, VALUE target, VALUE info)
{
    gtk_selection_add_target(RVAL2GTKWIDGET(widget), RVAL2ATOM(selection),
                             RVAL2ATOM(target), NUM2INT(info));
    return self;
}

static VALUE
rg_s_add_targets(VALUE self, VALUE rbwidget, VALUE rbselection, VALUE rbtargets)
{
    GtkWidget *widget = RVAL2GTKWIDGET(rbwidget);
    GdkAtom selection = RVAL2ATOM(rbselection);
    long n;
    GtkTargetEntry *targets = RVAL2GTKTARGETENTRIES(rbtargets, &n);

    gtk_selection_add_targets(widget, selection, targets, n);

    g_free(targets);

    return self;
}

static VALUE
rg_s_clear_targets(VALUE self, VALUE widget, VALUE selection)
{
    gtk_selection_clear_targets(RVAL2GTKWIDGET(widget), RVAL2ATOM(selection));
    return self;
}

static VALUE
rg_s_convert(G_GNUC_UNUSED VALUE self, VALUE widget, VALUE selection, VALUE target, VALUE time)
{
    gboolean ret = gtk_selection_convert(RVAL2GTKWIDGET(widget), 
                                         RVAL2ATOM(selection), RVAL2ATOM(target),
                                         NUM2INT(time));
    return CBOOL2RVAL(ret);
}

static VALUE
rg_s_remove_all(VALUE self, VALUE widget)
{
    gtk_selection_remove_all(RVAL2GTKWIDGET(widget));
    return self;
}

static VALUE
rg_s_include_image_p(G_GNUC_UNUSED VALUE self, VALUE rbtargets, VALUE rbwritable)
{
    gboolean writable = RVAL2CBOOL(rbwritable);
    long n;
    GdkAtom *targets = RVAL2GDKATOMS(rbtargets, &n);
    gboolean result;

    result = gtk_targets_include_image(targets, n, writable);

    g_free(targets);

    return result;
}

static VALUE
rg_s_include_text_p(G_GNUC_UNUSED VALUE self, VALUE rbtargets)
{
    long n;
    GdkAtom *targets = RVAL2GDKATOMS(rbtargets, &n);
    gboolean result;

    result = gtk_targets_include_text(targets, n);

    g_free(targets);

    return result;
}

static VALUE
rg_s_include_uri_p(G_GNUC_UNUSED VALUE self, VALUE rbtargets)
{
    long n;
    GdkAtom *targets = RVAL2GDKATOMS(rbtargets, &n);
    gboolean result;

    result = gtk_targets_include_uri(targets, n);

    g_free(targets);

    return result;
}

static VALUE
rg_s_include_rich_text_p(G_GNUC_UNUSED VALUE self, VALUE rbtargets, VALUE rbbuffer)
{
    GtkTextBuffer *buffer = RVAL2GTKTEXTBUFFER(rbbuffer);
    long n;
    GdkAtom *targets = RVAL2GDKATOMS(rbtargets, &n);
    gboolean result;

    result = gtk_targets_include_rich_text(targets, n, buffer);

    g_free(targets);

    return result;
}

void
Init_gtk_selection(VALUE mGtk)
{
    VALUE RG_TARGET_NAMESPACE =  rb_define_module_under(mGtk, "Selection");

    RG_DEF_SMETHOD(owner_set, 3);
    RG_DEF_SMETHOD(add_target, 4);
    RG_DEF_SMETHOD(add_targets, 3);
    RG_DEF_SMETHOD(clear_targets, 2);
    RG_DEF_SMETHOD(convert, 4);
    RG_DEF_SMETHOD(remove_all, 1);
    RG_DEF_SMETHOD_P(include_image, 2);
    RG_DEF_SMETHOD_P(include_text, 1);
    RG_DEF_SMETHOD_P(include_uri, 1);
    RG_DEF_SMETHOD_P(include_rich_text, 2);
}