1 #if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
2 # include "config.h"
3 #endif
4
5 #include "geanypy.h"
6
7
8 static void
NotifyHeader_dealloc(NotifyHeader * self)9 NotifyHeader_dealloc(NotifyHeader *self)
10 {
11 self->ob_type->tp_free((PyObject *) self);
12 }
13
14
15 static int
NotifyHeader_init(NotifyHeader * self,PyObject * args,PyObject * kwds)16 NotifyHeader_init(NotifyHeader *self, PyObject *args, PyObject *kwds)
17 {
18 self->notif = NULL;
19 return 0;
20 }
21
22
23 static PyObject *
NotifyHeader_get_property(NotifyHeader * self,const gchar * prop_name)24 NotifyHeader_get_property(NotifyHeader *self, const gchar *prop_name)
25 {
26 g_return_val_if_fail(self != NULL, NULL);
27 g_return_val_if_fail(prop_name != NULL, NULL);
28
29 if (!self->notif)
30 {
31 PyErr_SetString(PyExc_RuntimeError,
32 "NotifyHeader instance not initialized properly");
33 return NULL;
34 }
35
36 if (g_str_equal(prop_name, "hwnd_from"))
37 return PyLong_FromVoidPtr(self->notif->nmhdr.hwndFrom);
38 else if (g_str_equal(prop_name, "id_from"))
39 return PyLong_FromLong(self->notif->nmhdr.idFrom);
40 else if (g_str_equal(prop_name, "code"))
41 return PyInt_FromLong((glong) self->notif->nmhdr.code);
42
43 Py_RETURN_NONE;
44 }
45 GEANYPY_PROPS_READONLY(NotifyHeader);
46
47
48 static PyGetSetDef NotifyHeader_getseters[] = {
49 GEANYPY_GETSETDEF(NotifyHeader, "hwnd_from", ""),
50 GEANYPY_GETSETDEF(NotifyHeader, "id_from", ""),
51 GEANYPY_GETSETDEF(NotifyHeader, "code", ""),
52 { NULL }
53 };
54
55
56 PyTypeObject NotifyHeaderType = {
57 PyObject_HEAD_INIT(NULL)
58 0, /* ob_size */
59 "geany.scintilla.NotifyHeader", /* tp_name */
60 sizeof(NotifyHeader), /* tp_basicsize */
61 0, /* tp_itemsize */
62 (destructor) NotifyHeader_dealloc, /* tp_dealloc */
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* tp_print - tp_as_buffer */
64 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
65 "Wrapper around a NotifyHeader structure.", /* tp_doc */
66 0, 0, 0, 0, 0, 0, 0, 0, /* tp_traverse - tp_members */
67 NotifyHeader_getseters, /* tp_getset */
68 0, 0, 0, 0, 0, /* tp_base - tp_dictoffset */
69 (initproc) NotifyHeader_init, /* tp_init */
70 0, 0, /* tp_alloc - tp_new */
71
72 };
73
74
NotifyHeader_create_new_from_scintilla_notification(SCNotification * notif)75 NotifyHeader *NotifyHeader_create_new_from_scintilla_notification(SCNotification *notif)
76 {
77 NotifyHeader *self;
78 self = (NotifyHeader *) PyObject_CallObject((PyObject *) &NotifyHeaderType, NULL);
79 self->notif = notif;
80 return self;
81 }
82