Gtk_RenderingContext::fromGtkX(x), Gtk_RenderingContext::fromGtkY(y));
Gtk_RenderingContext::fromGtkX(-x), Gtk_RenderingContext::fromGtkY(-y));
static void gtk_math_view_destroy(GtkObject*);/* GtkWidget functions */static gboolean gtk_math_view_expose_event(GtkWidget*, GdkEventExpose*);static gboolean gtk_math_view_button_press_event(GtkWidget*, GdkEventButton*);static gboolean gtk_math_view_button_release_event(GtkWidget*, GdkEventButton*);static gboolean gtk_math_view_motion_notify_event(GtkWidget*, GdkEventMotion*);static void     gtk_math_view_realize(GtkWidget*);static void     gtk_math_view_size_request(GtkWidget*, GtkRequisition*);static void     gtk_math_view_size_allocate(GtkWidget*, GtkAllocation*);/* GtkMathView Signals */static void gtk_math_view_click(GtkMathView*, const GtkMathViewModelEvent*);static void gtk_math_view_select_begin(GtkMathView*, const GtkMathViewModelEvent*);static void gtk_math_view_select_over(GtkMathView*, const GtkMathViewModelEvent*);static void gtk_math_view_select_end(GtkMathView*, const GtkMathViewModelEvent*);static void gtk_math_view_select_abort(GtkMathView*);static void gtk_math_view_element_over(GtkMathView*, const GtkMathViewModelEvent*);/* auxiliary functions */static void setup_adjustment(GtkAdjustment*, gfloat, gfloat);static void setup_adjustments(GtkMathView*);/* Local data */static GtkWidgetClass* parent_class = NULL;static guint click_signal = 0;static guint select_begin_signal = 0;static guint select_over_signal = 0;static guint select_end_signal = 0;static guint select_abort_signal = 0;static guint element_over_signal = 0;static guint decorate_under_signal = 0;static guint decorate_over_signal = 0;/* auxiliary C++ functions */static SmartPtr<const Gtk_WrapperArea>findGtkWrapperArea(GtkMathView* math_view, GtkMathViewModelId node){  if (SmartPtr<Element> elem = math_view->view->elementOfModelElement(node))    if (SmartPtr<const Gtk_WrapperArea> area = smart_cast<const Gtk_WrapperArea>(elem->getArea()))      return area;  return 0;}#if 0static GtkMathViewModelIdfindAction(GtkMathView* math_view, GtkMathViewModelId node){  SmartPtr<Element> elem = math_view->view->elementOfModelElement(node);  while (elem && !is_a<MathMLActionElement>(elem) && !is_a<BoxMLActionElement>(elem))    elem = elem->getParent();  return elem ? math_view->view->modelElementOfElement(elem) : GtkMathViewModelId();}#endif/* auxiliary C functions */static voidfrom_view_coords(GtkMathView* math_view, GtkMathViewPoint* point){  g_return_if_fail(math_view != NULL);  g_return_if_fail(point != NULL);  point->x -= math_view->top_x;  point->y -= math_view->top_y - Gtk_RenderingContext::toGtkPixels(math_view->view->getBoundingBox().height);}static voidto_view_coords(GtkMathView* math_view, gint* x, gint* y){  g_return_if_fail(math_view != NULL);  g_return_if_fail(x != NULL);  g_return_if_fail(y != NULL);  *x += math_view->top_x;  *y += math_view->top_y - Gtk_RenderingContext::toGtkPixels(math_view->view->getBoundingBox().height);}/* GObject implementation */#if 0static extern "C" voidgtk_math_view_set_property (GObject* object,			    guint prop_id,			    GValue* value,			    GParamSpec* pspec){  GtkMathView *math_view = GTK_MATH_VIEW(object);    switch (prop_id)    {    case PROP_DEFAULT_FONT_SIZE:    case PROP_DEFAULT_FOREGROUND_COLOR:    case PROP_DEFAULT_BACKGROUND_COLOR:    case PROP_DEFAULT_SELECTED_FOREGROUND_COLOR:    case PROP_DEFAULT_SELECTED_BACKGROUND_COLOR:    case PROP_LOG_VERBOSITY:    default:      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);      break;    }}static extern "C" voidgtk_math_view_get_property (GObject* object,			    guint prop_id,			    const GValue* value,			    GParamSpec* pspec){ }#endif/* widget implementation */static voidgtk_math_view_update(GtkMathView* math_view, gint x0, gint y0, gint width, gint height){  GtkWidget* widget = GTK_WIDGET(math_view);  if (!GTK_WIDGET_MAPPED(GTK_WIDGET(math_view)) || math_view->freeze_counter > 0) return;  if (math_view->pixmap != NULL)    gdk_draw_pixmap(widget->window,		    widget->style->fg_gc[GTK_WIDGET_STATE(widget)],		    math_view->pixmap,		    x0, y0, x0, y0, width, height);  else    gdk_draw_rectangle(widget->window,		       widget->style->white_gc,		       TRUE,		       x0, y0, width, height);  g_signal_emit(GTK_OBJECT(math_view), decorate_over_signal, 0, widget->window);}static voidgtk_math_view_paint(GtkMathView* math_view){  g_return_if_fail(math_view != NULL);  GtkMathViewClass* math_view_class = GTK_MATH_VIEW_CLASS(G_OBJECT_GET_CLASS(G_OBJECT(math_view)));  g_return_if_fail(math_view_class != NULL);  if (!GTK_WIDGET_MAPPED(GTK_WIDGET(math_view)) || math_view->freeze_counter > 0) return;  GtkWidget* widget = GTK_WIDGET(math_view);    setup_adjustments(math_view);  const gint width = widget->allocation.width;  const gint height = widget->allocation.height;  Gtk_RenderingContext* rc = math_view->renderingContext;  g_return_if_fail(rc != 0);  if (math_view->pixmap == NULL)    {      math_view->pixmap = gdk_pixmap_new(widget->window, width, height, -1);      rc->setDrawable(math_view->pixmap);    }  rc->setStyle(Gtk_RenderingContext::SELECTED_STYLE);  rc->setForegroundColor(math_view_class->configuration->getSelectForeground());  rc->setBackgroundColor(math_view_class->configuration->getSelectBackground());  rc->setStyle(Gtk_RenderingContext::NORMAL_STYLE);  rc->setForegroundColor(math_view_class->configuration->getForeground());  rc->setBackgroundColor(math_view_class->configuration->getBackground());  gdk_draw_rectangle(math_view->pixmap, widget->style->white_gc, TRUE, 0, 0, width, height);  // WARNING: setAvailableWidth must be invoked BEFORE any coordinate conversion  math_view->view->setAvailableWidth(Gtk_RenderingContext::fromGtkX(width));  gint x = 0;  gint y = 0;  to_view_coords(math_view, &x, &y);  g_signal_emit(GTK_OBJECT(math_view), decorate_under_signal, 0, math_view->pixmap);  math_view->view->render(*rc,			  Gtk_RenderingContext::fromGtkX(x),			  Gtk_RenderingContext::fromGtkY(y));  gtk_math_view_update(math_view, 0, 0, width, height);}static voidhadjustment_value_changed(GtkAdjustment* adj, GtkMathView* math_view){  g_return_if_fail(adj != NULL);  g_return_if_fail(math_view != NULL);  if (adj->value > adj->upper - adj->page_size) adj->value = adj->upper - adj->page_size;  if (adj->value < adj->lower) adj->value = adj->lower;  math_view->old_top_x = math_view->top_x;  math_view->top_x = static_cast<int>(adj->value);  if (math_view->old_top_x != math_view->top_x)    gtk_math_view_paint(math_view);}static voidvadjustment_value_changed(GtkAdjustment* adj, GtkMathView* math_view){  g_return_if_fail(adj != NULL);  g_return_if_fail(math_view != NULL);  if (adj->value > adj->upper - adj->page_size) adj->value = adj->upper - adj->page_size;  if (adj->value < adj->lower) adj->value = adj->lower;  math_view->old_top_y = math_view->top_y;  math_view->top_y = static_cast<int>(adj->value);  if (math_view->old_top_y != math_view->top_y)    gtk_math_view_paint(math_view);}extern "C" GTypeGTKMATHVIEW_METHOD_NAME(get_type)(void){  static GType math_view_type = 0;  if (!math_view_type)    {      static const GTypeInfo math_view_info =	{	  sizeof(GtkMathViewClass),	  (GBaseInitFunc) gtk_math_view_base_class_init,	  (GBaseFinalizeFunc) gtk_math_view_base_class_finalize,	  (GClassInitFunc) gtk_math_view_class_init,	  NULL,	  NULL,	  sizeof(GtkMathView),	  0,	  (GInstanceInitFunc) gtk_math_view_init,	  NULL	};      math_view_type = g_type_register_static(GTK_TYPE_WIDGET, GTK_MATH_VIEW_WIDGET_NAME,					      &math_view_info, (GTypeFlags) 0);    }  return math_view_type;}static voidgtk_math_view_base_class_init(GtkMathViewClass* math_view_class){  g_return_if_fail(math_view_class != NULL);  SmartPtr<AbstractLogger> logger = Logger::create();  logger->ref();  math_view_class->logger = logger;  SmartPtr<Configuration> configuration = initConfiguration<MathView>(logger, getenv("GTKMATHVIEWCONF"));  configuration->ref();  math_view_class->configuration = configuration;  SmartPtr<MathMLOperatorDictionary> dictionary = initOperatorDictionary<MathView>(logger, configuration);  dictionary->ref();  math_view_class->dictionary = dictionary;  SmartPtr<Gtk_MathGraphicDevice> mathGraphicDevice = Gtk_MathGraphicDevice::create(logger, configuration);  mathGraphicDevice->ref();  math_view_class->math_graphic_device = mathGraphicDevice;#if defined(ENABLE_BOXML)  SmartPtr<Gtk_BoxGraphicDevice> boxGraphicDevice = Gtk_BoxGraphicDevice::create();  boxGraphicDevice->ref();  math_view_class->box_graphic_device = boxGraphicDevice;#endif // ENABLE_BOXML}static voidgtk_math_view_base_class_finalize(GtkMathViewClass* math_view_class){  g_return_if_fail(math_view_class != NULL);#if defined(ENABLE_BOXML)  if (math_view_class->box_graphic_device)    {      math_view_class->box_graphic_device->unref();      math_view_class->box_graphic_device = 0;    }#endif // ENABLE_BOXML  if (math_view_class->math_graphic_device)    {      math_view_class->math_graphic_device->unref();      math_view_class->math_graphic_device = 0;    }  if (math_view_class->dictionary)    {      math_view_class->dictionary->unref();      math_view_class->dictionary = 0;    }  if (math_view_class->configuration)    {      math_view_class->configuration->unref();      math_view_class->configuration = 0;    }  if (math_view_class->logger)    {      math_view_class->logger->unref();      math_view_class->logger = 0;    }}static voidgtk_math_view_class_init(GtkMathViewClass* math_view_class){  g_return_if_fail(math_view_class != NULL);#if 0  GObjectClass* gobject_class = G_OBJECT_CLASS(math_view_class);#endif  GtkObjectClass* object_class = (GtkObjectClass*) math_view_class;  GtkWidgetClass* widget_class = (GtkWidgetClass*) math_view_class;	  math_view_class->click = gtk_math_view_click;  math_view_class->select_begin = gtk_math_view_select_begin;  math_view_class->select_over = gtk_math_view_select_over;  math_view_class->select_end = gtk_math_view_select_end;  math_view_class->select_abort = gtk_math_view_select_abort;  math_view_class->element_over = gtk_math_view_element_over;  math_view_class->set_scroll_adjustments = gtk_math_view_set_adjustments;  parent_class = (GtkWidgetClass*) gtk_type_class(gtk_widget_get_type());#if 0  gobject_class->set_property = gtk_math_view_set_property;  gobject_class->get_property = gtk_math_view_get_property;#endif  object_class->destroy = gtk_math_view_destroy;  widget_class->realize = gtk_math_view_realize;  widget_class->expose_event = gtk_math_view_expose_event;  widget_class->size_request = gtk_math_view_size_request;  widget_class->size_allocate = gtk_math_view_size_allocate;  widget_class->button_press_event = gtk_math_view_button_press_event;  widget_class->button_release_event = gtk_math_view_button_release_event;  widget_class->motion_notify_event = gtk_math_view_motion_notify_event;  widget_class->set_scroll_adjustments_signal =     g_signal_new("set_scroll_adjustments",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_LAST,		 G_STRUCT_OFFSET(GtkMathViewClass,set_scroll_adjustments),		 NULL, NULL,		 gtk_marshal_NONE__POINTER_POINTER,		 G_TYPE_NONE , 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); 	  click_signal =     g_signal_new("click",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, click),		 NULL, NULL,		 gtk_marshal_NONE__POINTER,		 G_TYPE_NONE, 1, GTK_TYPE_POINTER);  select_begin_signal=    g_signal_new("select_begin",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, select_begin),		 NULL, NULL,		 gtk_marshal_NONE__POINTER,		 G_TYPE_NONE, 1, GTK_TYPE_POINTER);	  select_over_signal =     g_signal_new("select_over",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, select_over),		 NULL, NULL,		 gtk_marshal_NONE__POINTER,		 G_TYPE_NONE, 1, GTK_TYPE_POINTER);	  select_end_signal =     g_signal_new("select_end",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, select_end),		 NULL, NULL,		 gtk_marshal_NONE__POINTER,		 G_TYPE_NONE, 1, GTK_TYPE_POINTER);	  select_abort_signal =     g_signal_new("select_abort",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, select_abort),		 NULL, NULL,		 gtk_marshal_NONE__NONE,		 G_TYPE_NONE, 0);	  element_over_signal =     g_signal_new("element_over",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, element_over),		 NULL, NULL,		 gtk_marshal_NONE__POINTER,		 G_TYPE_NONE, 1, GTK_TYPE_POINTER);  decorate_under_signal =    g_signal_new("decorate_under",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, decorate_under),		 NULL, NULL,		 gtk_marshal_NONE__POINTER,		 G_TYPE_NONE, 1, GTK_TYPE_POINTER);  decorate_over_signal =    g_signal_new("decorate_over",		 G_OBJECT_CLASS_TYPE(object_class),		 G_SIGNAL_RUN_FIRST,		 G_STRUCT_OFFSET(GtkMathViewClass, decorate_over),		 NULL, NULL, 		 gtk_marshal_NONE__POINTER,		 G_TYPE_NONE, 1, GTK_TYPE_POINTER);#if 0	  g_object_class_install_property(gobject_class,				  PROP_DEFAULT_FONT_SIZE,				  g_param_spec_int("font_size",						   "Font Size",						   "The default font size",						   -1,						   100,						   -1,						   G_PARAM_READWRITE));  g_object_class_install_property(gobject_class,				  PROP_DEFAULT_FOREGROUND_COLOR,				  g_param_spec_string("foreground_color",						      "Foreground color",						      "The default foreground color",						      NULL,						      G_PARAM_READWRITE));  g_object_class_install_property(gobject_class,				  PROP_DEFAULT_BACKGROUND_COLOR,				  g_param_spec_string("background_color",						      "Background color",						      "The default background color",						      NULL,						      G_PARAM_READWRITE));  g_object_class_install_property(gobject_class,				  PROP_DEFAULT_SELECT_FOREGROUND_COLOR,				  g_param_spec_string("select_foreground_color",						      "Select foreground color",						      "The default foreground color for selected markup",						      NULL,						      G_PARAM_READWRITE));  g_object_class_install_property(gobject_class,				  PROP_DEFAULT_SELECT_BACKGROUND_COLOR,				  g_param_spec_string("select_background_color",						      "Select background color",						      "The default background color for selected markup",						      NULL,						      G_PARAM_READWRITE));  g_object_class_install_property(gobject_class,				  PROP_LOG_VERBOSITY,				  g_param_spec_int("log_verbosity",						   "Logger verbosity",						   "Verbosity level of the logger",						   LOG_ERROR,						   LOG_DEBUG,						   LOG_ERROR,						   G_PARAM_READWRITE));#endif}#if GTKMATHVIEW_USES_GMETADOMstatic voidgtk_math_view_release_document_resources(GtkMathView* math_view){  g_return_if_fail(math_view != NULL);  GdomeException exc = 0;  if (math_view->current_elem != NULL)    {      gdome_el_unref(math_view->current_elem, &exc);      g_assert(exc == 0);      math_view->current_elem = NULL;    }}#elsestatic voidgtk_math_view_release_document_resources(GtkMathView* math_view){  g_return_if_fail(math_view != NULL);  math_view->current_elem = NULL;}#endifstatic voidgtk_math_view_init(GtkMathView* math_view){  g_return_if_fail(math_view != NULL);  math_view->pixmap          = NULL;  math_view->view            = 0;  math_view->renderingContext = 0;  math_view->freeze_counter  = 0;  math_view->select_state    = SELECT_STATE_NO;  math_view->button_pressed  = FALSE;  math_view->current_elem    = NULL;  math_view->hadjustment = NULL;  math_view->vadjustment = NULL;  math_view->top_x = math_view->top_y = 0;  math_view->old_top_x = math_view->old_top_y = 0;#if 1  SmartPtr<MathView> view = MathView::create();  view->ref();  math_view->view = view;  GtkMathViewClass* math_view_class = GTK_MATH_VIEW_CLASS(G_OBJECT_GET_CLASS(G_OBJECT(math_view)));  g_assert(math_view_class != NULL);  view->setLogger(math_view_class->logger);  view->setOperatorDictionary(math_view_class->dictionary);  view->setMathMLNamespaceContext(MathMLNamespaceContext::create(view, math_view_class->math_graphic_device));#if ENABLE_BOXML  view->setBoxMLNamespaceContext(BoxMLNamespaceContext::create(view, math_view_class->box_graphic_device));#endif // ENABLE_BOXML  math_view->renderingContext = new Gtk_RenderingContext(math_view_class->logger);  math_view->renderingContext->setColorMap(gtk_widget_get_colormap(GTK_WIDGET(math_view)));#endif}extern "C" GtkWidget*GTKMATHVIEW_METHOD_NAME(new)(GtkAdjustment* hadj, GtkAdjustment* vadj){  GtkMathView* math_view = (GtkMathView*) gtk_type_new(GTKMATHVIEW_METHOD_NAME(get_type)());  g_return_val_if_fail(math_view != NULL, NULL);  GTKMATHVIEW_METHOD_NAME(set_adjustments)(math_view, hadj, vadj);  return GTK_WIDGET(math_view);}static voidgtk_math_view_destroy(GtkObject* object){  GtkMathView* math_view;  g_return_if_fail(object != NULL);  g_return_if_fail(GTK_IS_MATH_VIEW(object));  math_view = GTK_MATH_VIEW(object);  g_assert(math_view != NULL);  if (math_view->view)    {      math_view->view->resetRootElement();      math_view->view->unref();      math_view->view = 0;    }  if (math_view->renderingContext)    {      delete math_view->renderingContext;      math_view->renderingContext = 0;    }  if (math_view->hadjustment != NULL)    {      gtk_object_unref(GTK_OBJECT(math_view->hadjustment));      math_view->hadjustment = NULL;    }  if (math_view->vadjustment != NULL)    {      gtk_object_unref(GTK_OBJECT(math_view->vadjustment));      math_view->vadjustment = NULL;    }  if (math_view->pixmap != NULL)    {      g_object_unref(G_OBJECT(math_view->pixmap));      math_view->pixmap = NULL;    }  gtk_math_view_release_document_resources(math_view);  if (GTK_OBJECT_CLASS(parent_class)->destroy != NULL)    (*GTK_OBJECT_CLASS(parent_class)->destroy)(object);}