update_widget(math_view, 0, 0, width, height);
gtk_math_view_update(math_view, 0, 0, width, height);
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*);static void reset_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;/* 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;}/* 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 voidupdate_widget(GtkMathView* math_view, gint x0, gint y0, gint width, gint height){  GtkWidget* widget = GTK_WIDGET(math_view);  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);  if (math_view->cursor_visible != GTKMATHVIEW_CURSOR_OFF && math_view->cursor_elem != NULL)    {      GtkMathViewPoint focus_orig;      GtkMathViewBoundingBox focus_box;      if (!GTKMATHVIEW_METHOD_NAME(get_element_extents)(math_view, math_view->cursor_elem, &focus_orig, &focus_box))	return;      if (math_view->cursor_visible != GTKMATHVIEW_CURSOR_CARET_ON)	{	  gtk_paint_focus(widget->style,			  widget->window,			  GTK_STATE_NORMAL,			  NULL,			  widget,			  "?",			  focus_orig.x,			  focus_orig.y - focus_box.height,			  focus_box.width,			  focus_box.height + focus_box.depth);	}       if (math_view->cursor_visible != GTKMATHVIEW_CURSOR_FOCUS_ON && math_view->cursor_index >= 0)	{	  GdkRectangle crect;	  GtkMathViewPoint char_orig;	  GtkMathViewBoundingBox char_box;	  if (GTKMATHVIEW_METHOD_NAME(get_char_extents)(math_view, math_view->cursor_elem, math_view->cursor_index,							&char_orig, &char_box))	    crect.x = char_orig.x;	  else	    {	      crect.x = focus_orig.x;	      if (math_view->cursor_index > 0) crect.x += focus_box.width;	    }	  crect.y = focus_orig.y - focus_box.height;	  crect.height = focus_box.height + focus_box.depth;	  gtk_draw_insertion_cursor(widget,				    widget->window,				    NULL,				    &crect,				    TRUE,				    GTK_TEXT_DIR_LTR,				    FALSE);	}    }}static voidupdate_widget(GtkMathView* math_view){  GtkWidget* widget = GTK_WIDGET(math_view);  update_widget(math_view, 0, 0, widget->allocation.width, widget->allocation.height);}static voidpaint_widget(GtkMathView* math_view){  g_return_if_fail(math_view != NULL);  g_return_if_fail(math_view->configuration != 0);  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;  assert(rc);  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->configuration->getSelectForeground());  rc->setBackgroundColor(math_view->configuration->getSelectBackground());  rc->setStyle(Gtk_RenderingContext::NORMAL_STYLE);  rc->setForegroundColor(math_view->configuration->getForeground());  rc->setBackgroundColor(math_view->configuration->getBackground());  gdk_draw_rectangle(math_view->pixmap, widget->style->white_gc, TRUE, 0, 0, width, height);  gint x = 0;  gint y = 0;  to_view_coords(math_view, &x, &y);  math_view->view->render(*rc,			  Gtk_RenderingContext::fromGtkX(x),			  Gtk_RenderingContext::fromGtkY(y));  update_widget(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)    paint_widget(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)    paint_widget(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),	  NULL,	  NULL,	  (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 SmartPtr<Configuration>initConfiguration(SmartPtr<AbstractLogger>& logger, const char* confPath){  SmartPtr<Configuration> configuration = Configuration::create();  bool res = false;  if (confPath != NULL) res = MathView::loadConfiguration(logger, configuration, confPath);  if (!res) res = MathView::loadConfiguration(logger, configuration, MathView::getDefaultConfigurationPath());  if (!res) res = MathView::loadConfiguration(logger, configuration, "config/gtkmathview.conf.xml");  if (!res)    {      logger->out(LOG_ERROR, "could not load configuration file");      exit(-1);    }  return configuration;}static SmartPtr<MathMLOperatorDictionary>initOperatorDictionary(const SmartPtr<AbstractLogger>& logger, const SmartPtr<Configuration> configuration){  SmartPtr<MathMLOperatorDictionary> dictionary = MathMLOperatorDictionary::create();  if (!configuration->getDictionaries().empty())    for (std::vector<std::string>::const_iterator dit = configuration->getDictionaries().begin();	 dit != configuration->getDictionaries().end();	 dit++)      {	logger->out(LOG_DEBUG, "loading dictionary `%s'", (*dit).c_str());	if (!MathView::loadOperatorDictionary(logger, dictionary, (*dit).c_str()))	  logger->out(LOG_WARNING, "could not load `%s'", (*dit).c_str());      }  else    {      const bool res = MathView::loadOperatorDictionary(logger, dictionary, "config/dictionary.xml");      if (!res) MathView::loadOperatorDictionary(logger, dictionary, MathView::getDefaultOperatorDictionaryPath());    }  return dictionary;}static voidgtk_math_view_class_init(GtkMathViewClass* klass){  GObjectClass* gobject_class = G_OBJECT_CLASS(klass);  GtkObjectClass* object_class = (GtkObjectClass*) klass;  GtkWidgetClass* widget_class = (GtkWidgetClass*) klass;	  klass->click = gtk_math_view_click;  klass->select_begin = gtk_math_view_select_begin;  klass->select_over = gtk_math_view_select_over;  klass->select_end = gtk_math_view_select_end;  klass->select_abort = gtk_math_view_select_abort;  klass->element_over = gtk_math_view_element_over;  klass->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);#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;    }  if (math_view->cursor_elem != NULL)    {      gdome_el_unref(math_view->cursor_elem, &exc);      g_assert(exc == 0);      math_view->cursor_elem = NULL;    }}#elsestatic voidgtk_math_view_release_document_resources(GtkMathView* math_view){  g_return_if_fail(math_view != NULL);  math_view->current_elem = NULL;  math_view->cursor_elem = NULL;}#endifstatic voidgtk_math_view_init(GtkMathView* math_view){  g_return_if_fail(math_view != NULL);  math_view->pixmap          = NULL;  math_view->configuration   = 0;  math_view->dictionary      = 0;  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->cursor_elem     = NULL;  math_view->cursor_index    = 0;  math_view->cursor_visible  = GTKMATHVIEW_CURSOR_OFF;  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;  SmartPtr<MathView> view = MathView::create();  view->ref();  math_view->view = view;  SmartPtr<AbstractLogger> logger = Logger::create();  view->setLogger(logger);  SmartPtr<Configuration> configuration = initConfiguration(logger, getenv("GTKMATHVIEWCONF"));  SmartPtr<MathMLOperatorDictionary> dictionary = initOperatorDictionary(logger, configuration);  configuration->ref();  math_view->configuration = configuration;  view->setOperatorDictionary(dictionary);  view->setMathMLNamespaceContext(MathMLNamespaceContext::create(view,								 Gtk_MathGraphicDevice::create(GTK_WIDGET(math_view))));#if ENABLE_BOXML  view->setBoxMLNamespaceContext(BoxMLNamespaceContext::create(view,							       Gtk_BoxGraphicDevice::create(GTK_WIDGET(math_view))));#endif // ENABLE_BOXML  math_view->renderingContext = new Gtk_RenderingContext;  math_view->renderingContext->setColorMap(gtk_widget_get_colormap(GTK_WIDGET(math_view)));}extern "C" GtkWidget*GTKMATHVIEW_METHOD_NAME(new)(GtkAdjustment*, GtkAdjustment*){  GtkMathView* math_view = (GtkMathView*) gtk_type_new(GTKMATHVIEW_METHOD_NAME(get_type)());  g_return_val_if_fail(math_view != NULL, NULL);  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->configuration)    {      math_view->configuration->unref();      math_view->configuration = 0;    }  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);}