1/* -*- Mode: C; c-basic-offset: 4 -*-
2 * pygtk- Python bindings for the GTK toolkit.
3 * Copyright (C) 2007  Mariano Suárez-Alvarez
4 *
5 *   gtkborder.override: gtk.Border overrides
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22%%
23override gtk_border_new kwargs
24static int
25_wrap_gtk_border_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
26{
27    static char *kwlist[] = { "left", "right", "top", "bottom", NULL };
28    GtkBorder border = {0, 0, 0, 0};
29
30    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
31				     "|iiii:GdkRectangle.__init__",
32				     kwlist, &border.left, &border.right,
33				     &border.top, &border.bottom))
34	return -1;
35
36    self->boxed = g_boxed_copy(GTK_TYPE_BORDER, &border);
37    self->free_on_dealloc = TRUE;
38    self->gtype = GTK_TYPE_BORDER;
39
40    return 0;
41}
42%%
43override-slot GtkBorder.tp_as_sequence
44static Py_ssize_t
45_wrap_gtk_border_length(PyGBoxed *self)
46{
47    return 4;
48}
49static PyObject *
50_wrap_gtk_border_getitem(PyGBoxed *self, Py_ssize_t pos)
51{
52    GtkBorder *border;
53
54    if (pos < 0)
55        pos += 4;
56    if (pos < 0 || pos >= 4) {
57        PyErr_SetString(PyExc_IndexError, "index out of range");
58        return NULL;
59    }
60    border = pyg_boxed_get(self, GtkBorder);
61    switch (pos) {
62    case 0: return PyInt_FromLong(border->left);
63    case 1: return PyInt_FromLong(border->right);
64    case 2: return PyInt_FromLong(border->top);
65    case 3: return PyInt_FromLong(border->bottom);
66    default:
67        g_assert_not_reached();
68        return NULL;
69    }
70}
71static int
72_wrap_gtk_border_setitem(PyGBoxed *self, Py_ssize_t pos, PyObject *value)
73{
74    GtkBorder *border;
75    gint val;
76
77    if (pos < 0)
78        pos += 4;
79    if (pos < 0 || pos >= 4) {
80        PyErr_SetString(PyExc_IndexError, "index out of range");
81        return -1;
82    }
83    border = pyg_boxed_get(self, GtkBorder);
84    val = PyInt_AsLong(value);
85    if (PyErr_Occurred())
86        return -1;
87    switch(pos) {
88    case 0: border->left   = val; break;
89    case 1: border->right  = val; break;
90    case 2: border->top    = val; break;
91    case 3: border->bottom = val; break;
92    default:
93        g_assert_not_reached();
94        return -1;
95    }
96    return 0;
97}
98static PySequenceMethods _wrap_gtk_border_tp_as_sequence = {
99    (lenfunc)_wrap_gtk_border_length,
100    0,
101    0,
102    (ssizeargfunc)_wrap_gtk_border_getitem,
103    0,
104    (ssizeobjargproc)_wrap_gtk_border_setitem,
105    0,
106};
107%%
108override-attr GtkBorder.left
109static int
110_wrap_gtk_border__set_left(PyGBoxed *self, PyObject *value, void *closure)
111{
112    gint val;
113
114    val = PyInt_AsLong(value);
115    if (PyErr_Occurred())
116        return -1;
117    pyg_boxed_get(self, GtkBorder)->left = val;
118    return 0;
119}
120%%
121override-attr GtkBorder.right
122static int
123_wrap_gtk_border__set_right(PyGBoxed *self, PyObject *value, void *closure)
124{
125    gint val;
126
127    val = PyInt_AsLong(value);
128    if (PyErr_Occurred())
129        return -1;
130    pyg_boxed_get(self, GtkBorder)->right = val;
131    return 0;
132}
133%%
134override-attr GtkBorder.top
135static int
136_wrap_gtk_border__set_top(PyGBoxed *self, PyObject *value, void *closure)
137{
138    gint val;
139
140    val = PyInt_AsLong(value);
141    if (PyErr_Occurred())
142        return -1;
143    pyg_boxed_get(self, GtkBorder)->top = val;
144    return 0;
145}
146%%
147override-attr GtkBorder.bottom
148static int
149_wrap_gtk_border__set_bottom(PyGBoxed *self, PyObject *value, void *closure)
150{
151    gint val;
152
153    val = PyInt_AsLong(value);
154    if (PyErr_Occurred())
155        return -1;
156    pyg_boxed_get(self, GtkBorder)->bottom = val;
157    return 0;
158}
159
160