Exemple #1
0
void
diagram_unselect_object(Diagram *diagram, DiaObject *obj)
{
  object_add_updates(obj, diagram);
  textedit_remove_focus(obj, diagram);
  data_unselect(DIA_DIAGRAM_DATA(diagram), obj);
}
Exemple #2
0
static void
_diagram_change (DiaApplication   *app,
                 Diagram          *dia,
		 guint             flags,
		 gpointer          object,
	         DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter = {0,};
  GtkTreeIter *iter = &_iter;
  
  NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA(dia);

  if (flags & DIAGRAM_CHANGE_NAME)
    /* nothing special */;
  if (flags & DIAGRAM_CHANGE_LAYER)
    NODE_LAYER(iter) = object;
  if (flags & DIAGRAM_CHANGE_OBJECT) {
    NODE_OBJECT(iter) = object;
    NODE_LAYER(iter) = dia_object_get_parent_layer (object);
  }

  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  gtk_tree_model_row_changed (GTK_TREE_MODEL (dtm), path, iter);
  gtk_tree_path_free (path);
}
Exemple #3
0
/** Connects a python function to a signal.
 *  @param self The PyDiaDiagramData this is a method of.
 *  @param args A tuple containing the arguments, a str for signal name
 *  and a callable object (like a function)
 */
static PyObject *
PyDiaDiagramData_ConnectAfter(PyDiaDiagramData *self, PyObject *args)
{
    PyObject *func;
    char *signal;

    /* Check arguments */
    if (!PyArg_ParseTuple(args, "sO:DiagramData.connect_after",&signal,&func))
        return NULL;

    /* Check that the arg is callable */
    if (!PyCallable_Check(func)) {
        PyErr_SetString(PyExc_TypeError, "Second parameter must be callable");
        return NULL;
    }

    /* check if the signals name is valid */
    if ( strcmp("object_remove",signal) == 0 || strcmp("object_add",signal) == 0) {

        Py_INCREF(func); /* stay alive, where to kill ?? */

        /* connect to signal */
        g_signal_connect_after(DIA_DIAGRAM_DATA(self->data),signal,G_CALLBACK(PyDiaDiagramData_CallbackObject), func);
        
        Py_INCREF(Py_None);
        return Py_None;
    }
    else {
            PyErr_SetString(PyExc_TypeError, "Wrong signal name");
            return NULL;
    }
}
Exemple #4
0
static void
_dtv_select_items (GtkAction *action,
                  DiagramTreeView *dtv)
{
  GtkTreeSelection *selection;
  GtkTreeModel     *model;
  GList            *rows, *r;
  gboolean          once = TRUE;

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dtv));
  rows = gtk_tree_selection_get_selected_rows (selection, &model);
  r = rows;
  while (r) {
    GtkTreeIter     iter;

    if (gtk_tree_model_get_iter (model, &iter, r->data)) {
      Diagram   *diagram;
      Layer     *layer;
      DiaObject *object;

      gtk_tree_model_get (model, &iter, DIAGRAM_COLUMN, &diagram, -1);
      gtk_tree_model_get (model, &iter, LAYER_COLUMN, &layer, -1);
      gtk_tree_model_get (model, &iter, OBJECT_COLUMN, &object, -1);

      if (once) { /* destroy previous selection in first iteration */
	diagram_remove_all_selected(diagram, TRUE);
	once = FALSE;
      }

      if (layer) /* fixme: layer dialog update missing */
        data_set_active_layer (DIA_DIAGRAM_DATA(diagram), layer);
      if (object)
        diagram_select (diagram, object);
      if (diagram) {
        diagram_add_update_all (diagram);
        diagram_flush(diagram);
        g_object_unref (diagram);
      }
    }
    r = g_list_next (r);
  }
  g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
  g_list_free (rows);
}
Exemple #5
0
/** Deallocate memory owned by a DiagramData object.
 * @param object A DiagramData object to finalize.
 */
static void
diagram_data_finalize(GObject *object)
{
  DiagramData *data = DIA_DIAGRAM_DATA(object);

  guint i;

  g_free(data->paper.name);

  for (i=0;i<data->layers->len;i++) {
    layer_destroy(g_ptr_array_index(data->layers, i));
  }
  g_ptr_array_free(data->layers, TRUE);
  data->active_layer = NULL;

  g_list_free(data->selected);
  data->selected = NULL; /* for safety */
  data->selected_count_private = 0;
}
Exemple #6
0
static void
ddisplay_obj_render(DiaObject *obj, DiaRenderer *renderer,
		    int active_layer,
		    gpointer data)
{
  DDisplay *ddisp = (DDisplay *)data;
  DiaInteractiveRendererInterface *irenderer =
    DIA_GET_INTERACTIVE_RENDERER_INTERFACE (renderer);
  DiaHighlightType hltype = data_object_get_highlight(DIA_DIAGRAM_DATA(ddisp->diagram), obj);

  if (hltype != DIA_HIGHLIGHT_NONE && irenderer->draw_object_highlighted != NULL)
    irenderer->draw_object_highlighted(renderer, obj, hltype);
  else /* maybe the renderer does not support highlighting */
    DIA_RENDERER_GET_CLASS(renderer)->draw_object(renderer, obj, NULL);

  if (ddisp->show_cx_pts && 
      obj->parent_layer != NULL && obj->parent_layer->connectable) {
    object_draw_connectionpoints(obj, ddisp);
  }
}
Exemple #7
0
static void
_diagram_remove (DiaApplication   *app,
                 Diagram          *dia,
	         DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter = {0,};
  GtkTreeIter *iter = &_iter;
  
  NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA(dia);
  NODE_LAYER(iter)   = NULL;
  NODE_OBJECT(iter)  = NULL;

  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  gtk_tree_model_row_deleted (GTK_TREE_MODEL (dtm), path);
  gtk_tree_path_free (path);

  /* stop listening on this diagram */
  g_signal_handlers_disconnect_by_func (dia, _object_add, dtm);
  g_signal_handlers_disconnect_by_func (dia, _object_remove, dtm);
}
Exemple #8
0
/* listen to diagram creation */
static void
_diagram_add (DiaApplication   *app,
              Diagram          *dia,
	      DiagramTreeModel *dtm)
{
  GtkTreePath *path;
  GtkTreeIter _iter = {0,}; /* all null is our root */
  GtkTreeIter *iter = &_iter;

  NODE_DIAGRAM(iter) = DIA_DIAGRAM_DATA (dia);
  path = _dtm_get_path (GTK_TREE_MODEL (dtm), iter);
  /* we always get a path, but it may not be a valid one */
  if (path) {
    /* gtk_tree_model_row_changed is not 'strong' enough, lets try to re-add the root */
    gtk_tree_model_row_inserted (GTK_TREE_MODEL (dtm), path, iter);
    /* looks like the GtkTreeView is somewhat out of service */
    if (_recurse_row_inserted (GTK_TREE_MODEL (dtm), iter))
      gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (dtm), path, iter);
    gtk_tree_path_free (path);
  }
  _dtm_listen_on_diagram (dtm, dia);
}
Exemple #9
0
static DiaObject *
image_load(ObjectNode obj_node, int version, const char *filename)
{
  EImage *image;
  Element *elem;
  DiaObject *obj;
  int i;
  AttributeNode attr;
  char *diafile_dir;
  Diagram *dia;
  GList *list;
  
  image = g_malloc0(sizeof(EImage));
  elem = &image->element;
  obj = &elem->object;
  
  obj->type = &eimage_type;
  obj->ops = &eimage_ops;

  element_load(elem, obj_node);
  
  image->border_width = 0.1;
  attr = object_find_attribute(obj_node, "border_width");
  if (attr != NULL)
    image->border_width =  data_real( attribute_first_data(attr) );

  image->border_color = color_black;
  attr = object_find_attribute(obj_node, "border_color");
  if (attr != NULL)
    data_color(attribute_first_data(attr), &image->border_color);
  
  image->line_style = LINESTYLE_SOLID;
  attr = object_find_attribute(obj_node, "line_style");
  if (attr != NULL)
    image->line_style =  data_enum( attribute_first_data(attr) );

  image->dashlength = DEFAULT_LINESTYLE_DASHLEN;
  attr = object_find_attribute(obj_node, "dashlength");
  if (attr != NULL)
    image->dashlength = data_real(attribute_first_data(attr));

  image->draw_border = TRUE;
  attr = object_find_attribute(obj_node, "draw_border");
  if (attr != NULL)
    image->draw_border =  data_boolean( attribute_first_data(attr) );

  image->keep_aspect = TRUE;
  attr = object_find_attribute(obj_node, "keep_aspect");
  if (attr != NULL)
    image->keep_aspect =  data_boolean( attribute_first_data(attr) );

  image->keep_orig_aspect = TRUE;
  attr = object_find_attribute(obj_node, "keep_orig_aspect");
  if (attr != NULL)
    image->keep_orig_aspect =  data_boolean( attribute_first_data(attr) );

  attr = object_find_attribute(obj_node, "file");
  if (attr != NULL) {
    image->file =  data_filename( attribute_first_data(attr) );
  } else {
    image->file = g_strdup("");
  }

  attr = object_find_attribute(obj_node, "embed_id");
  if (attr) {
    image->embed_id = 
      dtree_conv_longname_from_xml(data_string(attribute_first_data(attr)));
  } else {
    image->embed_id = get_default_embed_id("embed_image");
  }
  register_embed_id(image->embed_id);

  element_init(elem, 8, NUM_CONNECTIONS);

  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &image->connections[i];
    image->connections[i].object = obj;
    image->connections[i].connected = NULL;
  }
  image->connections[8].flags = CP_FLAGS_MAIN;

  image->image = NULL;
  
  if (strcmp(image->file, "")!=0) {
    diafile_dir = get_directory(filename);

    if (g_path_is_absolute(image->file)) { /* Absolute pathname */
      image->image = dia_image_load(image->file);
      if (image->image == NULL) {
	/* Not found as abs path, try in same dir as diagram. */
	char *temp_string;
	const char *image_file_name = image->file;
	const char *psep;

	psep = strrchr(image->file, G_DIR_SEPARATOR);
	/* try the other G_OS as well */
	if (!psep)
	  psep =  strrchr(image->file, G_DIR_SEPARATOR == '/' ? '\\' : '/');
	if (psep)
	  image_file_name = psep + 1;

	temp_string = g_build_filename(diafile_dir, image_file_name, NULL);

	image->image = dia_image_load(temp_string);

	if (image->image != NULL) {
	  /* Found file in same dir as diagram. */
	  message_warning(_("The image file '%s' was not found in that directory.\n"
			  "Using the file '%s' instead\n"), image->file, temp_string);
	  g_free(image->file);
	  image->file = temp_string;
	} else {
	  g_free(temp_string);
	  
	  image->image = dia_image_load((char *)image_file_name);
	  if (image->image != NULL) {
	    char *tmp;
	    /* Found file in current dir. */
	    message_warning(_("The image file '%s' was not found in that directory.\n"
			    "Using the file '%s' instead\n"), image->file, image_file_name);
	    tmp = image->file;
	    image->file = g_strdup(image_file_name);
	    g_free(tmp);
	  } else {
	    message_warning(_("The image file '%s' was not found.\n"),
			    image_file_name);
	  }
	}
      }
    } else { /* Relative pathname: */
      char *temp_string;

      temp_string = g_build_filename (diafile_dir, image->file, NULL);

      image->image = dia_image_load(temp_string);

      if (image->image != NULL) {
	/* Found file in same dir as diagram. */
	g_free(image->file);
	image->file = temp_string;
      } else {
	g_free(temp_string);
	  
	image->image = dia_image_load(image->file);
	if (image->image == NULL) {
	  /* Didn't find file in current dir. */
	  message_warning(_("The image file '%s' was not found.\n"),
			  image->file);
	}
      }
    }
    g_free(diafile_dir);
  }

  /* update mtime */
  {
    struct stat st;
    if (g_stat (image->file, &st) != 0)
      st.st_mtime = 0;

    image->mtime = st.st_mtime;
  }
  image_update_data(image);

  obj->node = NULL;
  list = dia_open_diagrams();
  while (list != NULL) {
    dia = (Diagram *)list->data;
    if (!g_strcmp0(dia->filename,filename)) {
      obj->node = dtree_set_data_by_longname(DIA_DIAGRAM_DATA(dia)->dtree,
        image->embed_id,&image->element.object);
    }
    list = g_list_next(list);
  }
  
  return &image->element.object;
}
Exemple #10
0
static gboolean
_dtv_query_tooltip (GtkWidget  *widget,
                    gint        x,
                    gint        y,
                    gboolean    keyboard_mode,
                    GtkTooltip *tooltip)
{
  int                    bin_x, bin_y;
  GtkTreePath           *path = NULL;
  GtkTreeViewColumn     *column;
  GtkTreeIter            iter;
  GtkTreeModel          *model;
  GdkRectangle           cell_area;
  GString               *markup;
  gboolean               had_info = FALSE;

  gtk_tree_view_convert_widget_to_bin_window_coords (
	GTK_TREE_VIEW (widget), x, y, &bin_x, &bin_y);

  if (gtk_tree_view_get_path_at_pos
	(GTK_TREE_VIEW (widget), bin_x, bin_y, &path, &column, NULL, NULL)) {

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
    if (gtk_tree_model_get_iter (model, &iter, path)) {
      /* show some useful  information */
      Diagram   *diagram;
      Layer     *layer;
      DiaObject *object;


      gtk_tree_model_get (model, &iter, DIAGRAM_COLUMN, &diagram, -1);
      gtk_tree_model_get (model, &iter, LAYER_COLUMN, &layer, -1);
      gtk_tree_model_get (model, &iter, OBJECT_COLUMN, &object, -1);

      markup = g_string_new (NULL);

      if (diagram) {
        gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Diagram"), diagram->filename);
        g_string_append (markup, em);
        g_free (em);
      }

      if (layer) {
        gchar *name = layer_get_name (layer);
        gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Layer"), name);
        g_string_append (markup, em);
        g_free (em);
        g_free (name);
      } else if (diagram) {
	int layers = data_layer_count (DIA_DIAGRAM_DATA (diagram));
	g_string_append_printf (markup, g_dngettext (GETTEXT_PACKAGE, "%d Layer", "%d Layers",
			        layers), layers);
      }
      if (object) {
        gchar *em = g_markup_printf_escaped ("<b>%s</b>: %s\n", _("Type"), object->type->name);
        g_string_append (markup, em);
        g_free (em);
        g_string_append_printf (markup, "<b>%s</b>: %g,%g\n", Q_("object|Position"), 
			        object->position.x, object->position.y);
	g_string_append_printf (markup, "%d %s", 
	                        g_list_length (object->children), _("Children"));
        /* and some dia_object_get_meta ? */
      } else if (layer) {
	int objects = layer_object_count (layer);
	g_string_append_printf (markup, g_dngettext (GETTEXT_PACKAGE, "%d Object", "%d Objects",
	                        objects), objects);
      }

      if (markup->len > 0) {
        gtk_tree_view_get_cell_area (GTK_TREE_VIEW (widget), path, column, &cell_area);

        gtk_tree_view_convert_bin_window_to_widget_coords
			(GTK_TREE_VIEW (widget), cell_area.x, cell_area.y,
			 &cell_area.x, &cell_area.y);

        gtk_tooltip_set_tip_area (tooltip, &cell_area);
        gtk_tooltip_set_markup (tooltip, markup->str);
	had_info = TRUE;
      }

      /* drop references */
      if (diagram)
        g_object_unref (diagram);
      g_string_free (markup, TRUE);
    }
    gtk_tree_path_free (path);
    if (had_info)
      return TRUE;
  }

  return GTK_WIDGET_CLASS (_dtv_parent_class)->query_tooltip 
						(widget, x, y, keyboard_mode, tooltip);
}