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
|
/* Copyright (C) 2000-2005,
* Luca Padovani <lpadovan@cs.unibo.it>
* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
* Stefano Zacchiroli <zacchiro@cs.unibo.it>
*
* This file is part of lablgtkmathview, the Ocaml binding for the
* GtkMathView widget.
*
* lablgtkmathview 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 of the
* License, or (at your option) any later version.
*
* lablgtkmathview 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 lablgtkmathview; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* For details, send a mail to the authors.
*/
#include <assert.h>
#include <gtk/gtkmathview_gmetadom.h>
#include <gtk/gtk.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/callback.h>
#include <caml/fail.h>
#include <caml/custom.h>
#include <caml/callback.h>
#include <wrappers.h>
#include <ml_glib.h>
#include <ml_gdk.h>
#include <ml_gtk.h>
#include <ml_gobject.h>
#include <ml_gdkpixbuf.h>
#include <ml_pango.h>
#include <gtk_tags.h>
#include <gdk_tags.h>
#include <mlgdomevalue.h>
/* Init all */
CAMLprim value ml_gtk_mathview_init(value unit)
{
/* Since these are declared const, must force gcc to call them! */
GType t = gtk_math_view_get_type();
return Val_GType(t);
}
#define GtkMathView_val(val) check_cast(GTK_MATH_VIEW,val)
//#####################################
//
//#define FontManagerId_val(val) Int_val(val)
//#define Val_FontManagerId(val) Val_int(val)
//
///* As ML_1, but the result is optional */
//#define OML_1(cname, conv1, conv) \
//value ml_##cname (value arg1) { return Val_option_ptr((cname (conv1 (arg1))),conv); }
///* As ML_3, but the result is optional */
#define OML_3(cname, conv1, conv2, conv3, conv) \
value ml_##cname (value arg1, value arg2, value arg3) { return Val_option_ptr((cname (conv1 (arg1), conv2 (arg2), conv3 (arg3))),conv); }
///* As ML_2, but the second argument is optional */
//#define ML_2O(cname, conv1, conv2, conv) \
//value ml_##cname (value arg1, value arg2) \
//{ return conv (cname (conv1(arg1), ptr_val_option(arg2,conv2))); }
value Val_Element_ref(GdomeElement* elem)
{
if (elem != NULL)
{
GdomeException exc = 0;
gdome_el_ref(elem, &exc);
g_assert(exc == 0);
}
return Val_Element(elem);
}
ML_2 (gtk_math_view_structure_changed, GtkMathView_val, Element_val, Unit)
ML_3 (gtk_math_view_attribute_changed, GtkMathView_val, Element_val, DOMString_val, Unit)
/* OML_3 (gtk_math_view_get_element_at, GtkMathView_val, Int_val, Int_val, Val_Element) */
ML_1 (gtk_math_view_freeze, GtkMathView_val, Unit)
ML_1 (gtk_math_view_thaw, GtkMathView_val, Unit)
ML_2 (gtk_math_view_load_uri, GtkMathView_val, String_val, Val_bool)
ML_2 (gtk_math_view_load_root, GtkMathView_val, Element_val, Val_bool)
ML_1 (gtk_math_view_unload, GtkMathView_val, Unit)
ML_2 (gtk_math_view_select, GtkMathView_val, Element_val, Unit)
ML_2 (gtk_math_view_unselect, GtkMathView_val, Element_val, Unit)
ML_2 (gtk_math_view_is_selected, GtkMathView_val, Element_val, Val_bool)
/*
ML_2 (gtk_math_view_new,GtkAdjustment_val, GtkAdjustment_val, Val_GtkWidget_sink)
ML_1 (gtk_math_view_get_width, GtkMathView_val, Val_int)
ML_1 (gtk_math_view_get_height, GtkMathView_val, Val_int)
*/
ML_3 (gtk_math_view_set_top, GtkMathView_val, Int_val, Int_val, Unit)
ML_3 (gtk_math_view_set_adjustments, GtkMathView_val, GtkAdjustment_val, GtkAdjustment_val, Unit)
/*
ML_1 (gtk_math_view_get_hadjustment, GtkMathView_val, Val_GtkWidget)
ML_1 (gtk_math_view_get_vadjustment, GtkMathView_val, Val_GtkWidget)
*/
ML_1 (gtk_math_view_get_buffer, GtkMathView_val, Val_GdkPixmap)
ML_2 (gtk_math_view_set_font_size, GtkMathView_val, Int_val, Unit)
ML_1 (gtk_math_view_get_font_size, GtkMathView_val, Val_int)
ML_2 (gtk_math_view_set_log_verbosity, GtkMathView_val, Int_val, Unit)
ML_1 (gtk_math_view_get_log_verbosity, GtkMathView_val, Val_int)
ML_2 (gtk_math_view_set_t1_opaque_mode, GtkMathView_val, Bool_val, Unit)
ML_1 (gtk_math_view_get_t1_opaque_mode, GtkMathView_val, Val_bool)
ML_2 (gtk_math_view_set_t1_anti_aliased_mode, GtkMathView_val, Bool_val, Unit)
ML_1 (gtk_math_view_get_t1_anti_aliased_mode, GtkMathView_val, Val_bool)
ML_1 (gtk_math_view_add_configuration_path, String_val, Unit)
value ml_gtk_math_view_get_element_at (value arg1, value arg2, value arg3)
{
CAMLparam3(arg1, arg2, arg3);
CAMLlocal1 (result);
GdomeElement* el;
if (gtk_math_view_get_element_at(GtkMathView_val (arg1), Int_val(arg2), Int_val(arg3), &el, NULL, NULL))
result = Val_option_ptr(el, Val_Element);
else
result = Val_unit;
CAMLreturn (result);
}
value ml_gtk_math_view_get_document (value arg1)
{
CAMLparam1(arg1);
CAMLlocal1(result);
GdomeDocument* doc = gtk_math_view_get_document(GtkMathView_val (arg1));
if (doc == NULL)
result = Val_unit;
else
result = Val_option_ptr(doc, Val_Document);
CAMLreturn (result);
}
value ml_gtk_math_view_get_adjustments(value arg1)
{
CAMLparam1(arg1);
CAMLlocal1(result);
GtkAdjustment* hadj;
GtkAdjustment* vadj;
gtk_math_view_get_adjustments(GtkMathView_val (arg1), &hadj, &vadj);
result = alloc(2, 0);
Store_field(result, 0, Val_GtkWidget(hadj));
Store_field(result, 1, Val_GtkWidget(vadj));
CAMLreturn(result);
}
value ml_gtk_math_view_get_size (value arg1)
{
CAMLparam1(arg1);
CAMLlocal1(result);
int width, height;
gtk_math_view_get_size(GtkMathView_val (arg1), &width, &height);
result = alloc(1, 0);
Store_field(result, 0, Val_int(width));
Store_field(result, 1, Val_int(height));
CAMLreturn (result);
}
value ml_gtk_math_view_get_bounding_box (value arg1)
{
CAMLparam1(arg1);
CAMLlocal1(result);
int width, height, depth;
GtkMathViewBoundingBox gbox;
gtk_math_view_get_bounding_box(GtkMathView_val (arg1), &gbox);
result = alloc(3, 0);
Store_field(result, 0, Val_int(gbox.width));
Store_field(result, 1, Val_int(gbox.height));
Store_field(result, 2, Val_int(gbox.depth));
CAMLreturn (result);
}
value ml_gtk_math_view_get_top (value arg1)
{
CAMLparam1(arg1);
CAMLlocal1(result);
int x, y;
gtk_math_view_get_top(GtkMathView_val (arg1), &x, &y);
result = alloc(2, 0);
Store_field(result, 0, Val_int(x));
Store_field(result, 1, Val_int(y));
CAMLreturn (result);
}
/*
value ml_gtk_math_view_get_element_coords (value arg1, value arg2)
{
CAMLparam2(arg1, arg2);
CAMLlocal1 (result);
int x, y;
gtk_math_view_get_element_coords(GtkMathView_val (arg1), Element_val(arg2), &x, &y);
result = alloc(2, 0);
Store_field(result, 0, Val_int(x));
Store_field(result, 1, Val_int(y));
CAMLreturn (result);
}
*/
value ml_gtk_math_view_gdome_element_of_boxed_option (value arg1)
{
CAMLparam1(arg1);
GdomeException exc = 0;
GdomeElement* nr = NULL;
CAMLlocal1 (res);
if (arg1==Val_int(0)) {
assert(0);
} else {
nr = (GdomeElement*) Field(Field(arg1,0),1);
}
res = Val_Element_ref(nr);
if (res==Val_int(0)) {
assert(0);
}
CAMLreturn(res);
}
value ml_gtk_math_view_gdome_element_option_of_boxed_option (value arg1)
{
CAMLparam1(arg1);
GdomeElement* nr;
CAMLlocal1 (valnr);
CAMLlocal1 (res);
if (arg1==Val_int(0)) {
res=Val_unit;
} else {
GdomeException exc = 0;
GdomeElement* elem = (GdomeElement*) Field(Field(arg1,0),1);
assert(elem != NULL);
res = Val_option_ptr(elem, Val_Element_ref);
}
CAMLreturn(res);
}
value ml_gtk_math_view_model_event_of_boxed_option (value arg1)
{
CAMLparam1(arg1);
GdomeElement* nr;
CAMLlocal1 (valnr);
CAMLlocal1 (res);
assert(arg1 != Val_int(0));
GtkMathViewModelEvent* event = (GtkMathViewModelEvent*) Field(Field(arg1,0),1);
res = alloc(4, 0);
Store_field(res, 0, Val_option_ptr(event->id, Val_Element_ref));
Store_field(res, 1, Val_int(event->x));
Store_field(res, 2, Val_int(event->y));
Store_field(res, 3, Val_int(event->state));
CAMLreturn(res);
}
|