Exemplo n.º 1
0
/* Accepts the text in the off-screen entry of an icon text item */
static void
iti_edition_accept (GnomeIconTextItem *iti)
{
	GnomeIconTextItemPrivate *priv;
	gboolean accept;

	priv = iti->_priv;
	accept = TRUE;

	g_signal_emit (iti, iti_signals [TEXT_CHANGED], 0, &accept);

	if (iti->editing){
		if (accept) {
			if (iti->is_text_allocated)
				g_free (iti->text);

			iti->text = g_strdup (gtk_entry_get_text (GTK_ENTRY(priv->entry)));
			iti->is_text_allocated = 1;
		}

		iti_stop_editing (iti);
	}
	update_pango_layout (iti);
	priv->need_text_update = TRUE;

	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
}
Exemplo n.º 2
0
/* Starts the selection state in the icon text item */
static void
iti_start_selecting (GnomeIconTextItem *iti, int idx, guint32 event_time)
{
	GnomeIconTextItemPrivate *priv;
	GtkEditable *e;
	GdkCursor *ibeam;

	priv = iti->_priv;
	e = GTK_EDITABLE (priv->entry);

	gtk_editable_select_region (e, idx, idx);
	gtk_editable_set_position (e, idx);
	ibeam = gdk_cursor_new (GDK_XTERM);
	gnome_canvas_item_grab (GNOME_CANVAS_ITEM (iti),
				GDK_BUTTON_RELEASE_MASK |
				GDK_POINTER_MOTION_MASK,
				ibeam, event_time);
	gdk_cursor_unref (ibeam);

	gtk_editable_select_region (e, idx, idx);
	priv->selecting = TRUE;
	priv->selection_start = idx;

	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));

	g_signal_emit (iti, iti_signals[SELECTION_STARTED], 0);
}
static void
etfci_reflow (GnomeCanvasItem *item,
              gint flags)
{
	ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item);
	gdouble old_height;
	gint i;
	gint count;
	gdouble height = 0;

	etfci_rebuild_combined (etfci);

	old_height = etfci->height;

	count = e_table_header_count (etfci->combined_header);
	for (i = 0; i < count; i++) {
		ETableCol *ecol;

		ecol = e_table_header_get_column (etfci->combined_header, i);
		if (ecol->spec->disabled)
			continue;
		height += e_table_header_compute_height (
			ecol, GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas));
	}

	etfci->height = height;

	if (old_height != etfci->height)
		e_canvas_item_request_parent_reflow (item);

	gnome_canvas_item_request_update (item);
}
Exemplo n.º 4
0
/* Stops the editing state of an icon text item */
static void
iti_stop_editing (GnomeIconTextItem *iti)
{
	iti->editing = FALSE;
	send_focus_event (iti, FALSE);
	update_pango_layout (iti);
	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
	g_signal_emit (iti, iti_signals[EDITING_STOPPED], 0);
}
Exemplo n.º 5
0
/* Virtual functions */
static void
e_reflow_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
	GnomeCanvasItem *item;
	EReflow *reflow;

	item = GNOME_CANVAS_ITEM (object);
	reflow = E_REFLOW (object);

	switch (prop_id){
	case PROP_HEIGHT:
		reflow->height = g_value_get_double (value);
		reflow->need_reflow_columns = TRUE;
		e_canvas_item_request_reflow(item);
		break;
	case PROP_MINIMUM_WIDTH:
		reflow->minimum_width = g_value_get_double (value);
		if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(object))
			set_empty(reflow);
		e_canvas_item_request_reflow(item);
		break;
	case PROP_EMPTY_MESSAGE:
		g_free(reflow->empty_message);
		reflow->empty_message = g_strdup(g_value_get_string (value));
		if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(object))
			set_empty(reflow);
		break;
	case PROP_MODEL:
		connect_model (reflow, (EReflowModel *) g_value_get_object (value));
		break;
	case PROP_COLUMN_WIDTH:
		if (reflow->column_width != g_value_get_double (value)) {
			GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
			double old_width = reflow->column_width;

			reflow->column_width = g_value_get_double (value);
			adjustment->step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
			adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
			gtk_adjustment_changed(adjustment);
			e_reflow_resize_children(item);
			e_canvas_item_request_reflow(item);

			reflow->need_column_resize = TRUE;
			gnome_canvas_item_request_update(item);

			if (old_width != reflow->column_width)
				column_width_changed (reflow);
		}
		break;
	}
}
Exemplo n.º 6
0
static void
etcta_set_property (GObject *object,
                    guint property_id,
                    const GValue *value,
                    GParamSpec *pspec)
{
	GnomeCanvasItem *item;
	ETableClickToAdd *etcta;

	item = GNOME_CANVAS_ITEM (object);
	etcta = E_TABLE_CLICK_TO_ADD (object);

	switch (property_id) {
	case PROP_HEADER:
		etcta_drop_table_header (etcta);
		etcta_add_table_header (etcta, E_TABLE_HEADER (g_value_get_object (value)));
		break;
	case PROP_MODEL:
		etcta_drop_model (etcta);
		etcta_add_model (etcta, E_TABLE_MODEL (g_value_get_object (value)));
		break;
	case PROP_MESSAGE:
		etcta_drop_message (etcta);
		etcta_add_message (etcta, g_value_get_string (value));
		break;
	case PROP_WIDTH:
		etcta->width = g_value_get_double (value);
		if (etcta->row)
			gnome_canvas_item_set (
				etcta->row,
				"minimum_width", etcta->width,
				NULL);
		if (etcta->text)
			gnome_canvas_item_set (
				etcta->text,
				"width", (etcta->width < 4 ? 4 : etcta->width) - 4,
				NULL);
		if (etcta->rect)
			gnome_canvas_item_set (
				etcta->rect,
				"x2", etcta->width,
				NULL);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		return;

	}
	gnome_canvas_item_request_update (item);
}
Exemplo n.º 7
0
static void
iti_entry_text_changed_by_clipboard (GtkObject *widget, gpointer data)
{
	GnomeIconTextItem *iti;
	GnomeCanvasItem *item;

        /* Update text item to reflect changes */
        iti = GNOME_ICON_TEXT_ITEM (data);

	update_pango_layout (iti);
	iti->_priv->need_text_update = TRUE;

        item = GNOME_CANVAS_ITEM (iti);
        gnome_canvas_item_request_update (item);
}
Exemplo n.º 8
0
/* Stops the selection state in the icon text item */
static void
iti_stop_selecting (GnomeIconTextItem *iti, guint32 event_time)
{
	GnomeIconTextItemPrivate *priv;
	GnomeCanvasItem *item;

	priv = iti->_priv;
	item = GNOME_CANVAS_ITEM (iti);

	gnome_canvas_item_ungrab (item, event_time);
	priv->selecting = FALSE;

	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
	g_signal_emit (iti, iti_signals[SELECTION_STOPPED], 0);
}
Exemplo n.º 9
0
/**
 * gnome_icon_text_item_setxy:
 * @iti:  An icon text item.
 * @x: X position.
 * @y: Y position.
 *
 * Sets the coordinates at which the icon text item should be placed.
 *
 * See also: gnome_icon_text_item_configure().
 */
void
gnome_icon_text_item_setxy (GnomeIconTextItem *iti, int x, int y)
{
	GnomeIconTextItemPrivate *priv;

	g_return_if_fail (GNOME_IS_ICON_TEXT_ITEM (iti));

	priv = iti->_priv;

	iti->x = x;
	iti->y = y;

	priv->need_pos_update = TRUE;
	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
}
Exemplo n.º 10
0
/**
 * gnome_icon_text_item_focus:
 * @iti:  An icon text item.
 * @focused: whether to set or unset the icon text item focus.
 *
 * Sets or unsets the focus on the icon text item depending on @focused.
 **/
void
gnome_icon_text_item_focus (GnomeIconTextItem *iti, gboolean focused)
{
	GnomeIconTextItemPrivate *priv;

	g_return_if_fail (GNOME_IS_ICON_TEXT_ITEM (iti));

	priv = iti->_priv;

	if (!iti->focused == !focused)
		return;

	iti->focused = focused ? TRUE : FALSE;

	priv->need_state_update = TRUE;
	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
}
Exemplo n.º 11
0
/**
 * gnome_icon_text_item_configure:
 * @iti: An icon text item.
 * @x: X position in which to place the item.
 * @y: Y position in which to place the item.
 * @width: Maximum width allowed for this item, to be used for word wrapping.
 * @fontname: Ignored.
 * @text: Text that is going to be displayed.
 * @is_editable: Deprecated.
 * @is_static: Whether @text points to a static string or not.
 *
 * This routine is used to configure a &GnomeIconTextItem.
 *
 * @x and @y specify the cordinates where the item is placed inside the canvas.
 * The @x coordinate should be the leftmost position that the icon text item can
 * assume at any one time, that is, the left margin of the column in which the
 * icon is to be placed.  The @y coordinate specifies the top of the icon text
 * item.
 *
 * @width is the maximum width allowed for this icon text item.  The coordinates
 * define the upper-left corner of an icon text item with maximum width; this may
 * actually be outside the bounding box of the item if the text is narrower than
 * the maximum width.
 *
 * If @is_static is true, it means that there is no need for the item to
 * allocate memory for the string (it is a guarantee that the text is allocated
 * by the caller and it will not be deallocated during the lifetime of this
 * item).  This is an optimization to reduce memory usage for large icon sets.
 */
void
gnome_icon_text_item_configure (GnomeIconTextItem *iti, int x, int y,
				int width, const char *fontname,
				const char *text,
				gboolean is_editable, gboolean is_static)
{
	GnomeIconTextItemPrivate *priv = iti->_priv;

	g_return_if_fail (GNOME_IS_ICON_TEXT_ITEM (iti));
	g_return_if_fail (width > 2 * MARGIN_X);
	g_return_if_fail (text != NULL);

	iti->x = x;
	iti->y = y;
	iti->width = width;
	iti->is_editable = is_editable != FALSE;

	if (iti->editing)
		iti_stop_editing (iti);

	if (iti->text && iti->is_text_allocated)
		g_free (iti->text);

	iti->is_text_allocated = !is_static;

	/* This cast is to shut up the compiler */
	if (is_static)
		iti->text = (char *) text;
	else
		iti->text = g_strdup (text);

	/* Create our new PangoLayout */
	if (priv->layout != NULL)
		g_object_unref (priv->layout);
	priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (GNOME_CANVAS_ITEM (iti)->canvas), iti->text);

	pango_layout_set_font_description (priv->layout, GTK_WIDGET (GNOME_CANVAS_ITEM (iti)->canvas)->style->font_desc);

	pango_layout_set_alignment (priv->layout, PANGO_ALIGN_CENTER);
	update_pango_layout (iti);

	priv->need_pos_update = TRUE;
	priv->need_font_update = TRUE;
	priv->need_text_update = TRUE;
	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
}
Exemplo n.º 12
0
/* Handles selection range changes on the icon text item */
static void
iti_selection_motion (GnomeIconTextItem *iti, int idx)
{
	GnomeIconTextItemPrivate *priv;
	GtkEditable *e;
	g_assert (idx >= 0);

	priv = iti->_priv;
	e = GTK_EDITABLE (priv->entry);

	if (idx < (int) priv->selection_start) {
		gtk_editable_select_region (e, idx, priv->selection_start);
	} else {
		gtk_editable_select_region (e, priv->selection_start, idx);
	}

	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
}
Exemplo n.º 13
0
/* Starts the editing state of an icon text item */
static void
iti_start_editing (GnomeIconTextItem *iti)
{
	GnomeIconTextItemPrivate *priv;

	priv = iti->_priv;

	if (iti->editing)
		return;

	/* We place an entry offscreen to handle events and selections.  */
	if (priv->entry_top == NULL) {
		priv->entry = gtk_entry_new ();
		g_signal_connect (priv->entry, "activate",
				  G_CALLBACK (iti_entry_activate), iti);


		if (GTK_WIDGET_REALIZED (GTK_WIDGET (GNOME_CANVAS_ITEM (iti)->canvas))) {
			realize_cursor_gc (iti);
		}

		/* Make clipboard functions cause an update, since clipboard
		 * functions will change the offscreen entry */
		g_signal_connect_after (priv->entry, "changed",
					G_CALLBACK (iti_entry_text_changed_by_clipboard),
					iti);
		priv->entry_top = gtk_window_new (GTK_WINDOW_POPUP);
		gtk_container_add (GTK_CONTAINER (priv->entry_top),
				   GTK_WIDGET (priv->entry));
		gtk_window_move (GTK_WINDOW (priv->entry_top), 20000, 20000);
		gtk_widget_show_all (priv->entry_top);
	}

	gtk_entry_set_text (GTK_ENTRY (priv->entry), iti->text);
	gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);

	iti->editing = TRUE;
	priv->need_state_update = TRUE;

	send_focus_event (iti, TRUE);
	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));

	g_signal_emit (iti, iti_signals[EDITING_STARTED], 0);
}
Exemplo n.º 14
0
/**
 * gnome_icon_text_item_select:
 * @iti: An icon text item
 * @sel: Whether the icon text item should be displayed as selected.
 *
 * This function is used to control whether an icon text item is displayed as
 * selected or not.  Mouse events are ignored by the item when it is unselected;
 * when the user clicks on a selected icon text item, it will start the text
 * editing process.
 */
void
gnome_icon_text_item_select (GnomeIconTextItem *iti, gboolean sel)
{
	GnomeIconTextItemPrivate *priv;

	g_return_if_fail (GNOME_IS_ICON_TEXT_ITEM (iti));

	priv = iti->_priv;

	if (!iti->selected == !sel)
		return;

	iti->selected = sel ? TRUE : FALSE;

#ifdef FIXME
	if (!iti->selected && iti->editing)
		iti_edition_accept (iti);
#endif
	priv->need_state_update = TRUE;
	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (iti));
}
static void
etfci_set_property (GObject *object,
                    guint property_id,
                    const GValue *value,
                    GParamSpec *pspec)
{
	GnomeCanvasItem *item;
	ETableFieldChooserItem *etfci;

	item = GNOME_CANVAS_ITEM (object);
	etfci = E_TABLE_FIELD_CHOOSER_ITEM (object);

	switch (property_id) {
	case PROP_FULL_HEADER:
		etfci_drop_full_header (etfci);
		if (g_value_get_object (value))
			etfci_add_full_header (
				etfci, E_TABLE_HEADER (
				g_value_get_object (value)));
		break;

	case PROP_HEADER:
		etfci_drop_table_header (etfci);
		if (g_value_get_object (value))
			etfci_add_table_header (
				etfci, E_TABLE_HEADER (
				g_value_get_object (value)));
		break;

	case PROP_DND_CODE:
		g_free (etfci->dnd_code);
		etfci->dnd_code = g_strdup (g_value_get_string (value));
		break;

	case PROP_WIDTH:
		etfci->width = g_value_get_double (value);
		gnome_canvas_item_request_update (item);
		break;
	}
}
Exemplo n.º 16
0
/* TODO I think I should update all links as well, so as not having
 * stale graphics if the diagram has been resized */
static gint
reposition_canvas_nodes (guint8 * ether_addr, canvas_node_t * canvas_node,
			 GtkWidget * canvas)
{
  static gfloat angle = 0.0;
  static guint node_i = 0, n_nodes = 0;
  gdouble x = 0, y = 0, xmin, ymin, xmax, ymax, text_compensation = 50;
  gdouble x_rad_max, y_rad_max;
  gdouble oddAngle = angle;

  if (!canvas_node->shown)
    {
      gnome_canvas_item_hide (canvas_node->node_item);
      gnome_canvas_item_hide (canvas_node->text_item);
      return FALSE;
    }

  gnome_canvas_get_scroll_region (GNOME_CANVAS (canvas),
				  &xmin, &ymin, &xmax, &ymax);
  if (!n_nodes)
      n_nodes = node_i = displayed_nodes;

  xmin += text_compensation;
  xmax -= text_compensation;	/* Reduce the drawable area so that
				 * the node name is not lost
				 * TODO: Need a function to calculate
				 * text_compensation depending on font size */
  x_rad_max = 0.9 * (xmax - xmin) / 2;
  y_rad_max = 0.9 * (ymax - ymin) / 2;

  /* TODO I've done all the stationary changes in a hurry
   * I should review it an tidy up all this stuff */
  if (pref.stationary)
    {
      if (canvas_node->is_new)
	{
	  static guint count = 0, base = 1;
	  gdouble angle = 0;

	  if (count == 0)
	    {
	      angle = M_PI * 2.0f;
	      count++;
	    }
	  else
	    {

	      if (count > 2 * base)
		{
		  base *= 2;
		  count = 1;
		}
	      angle = M_PI * (gdouble) count / ((gdouble) base);
	      count += 2;
	    }
	  x = x_rad_max * cos (angle);
	  y = y_rad_max * sin (angle);
	}

    }
  else
    {

      if (n_nodes % 2 == 0)	/* spacing is better when n_nodes is odd and Y is linear */
	oddAngle = (angle * n_nodes) / (n_nodes + 1);
      if (n_nodes > 7)
	{
	  x = x_rad_max * cos (oddAngle);
	  y = y_rad_max * asin (sin (oddAngle)) / (M_PI / 2);
	}
      else
	{
	  x = x_rad_max * cos (angle);
	  y = y_rad_max * sin (angle);
	}
    }

  if (!pref.stationary || canvas_node->is_new)
    {
      gnome_canvas_item_set (GNOME_CANVAS_ITEM (canvas_node->group_item),
			     "x", x, "y", y, NULL);
      canvas_node->is_new = FALSE;
    }

  if (need_font_refresh)
    {
      /* We update the text font */
      gnome_canvas_item_set (canvas_node->text_item, 
                             "font", pref.fontname, 
                             "fill_color", pref.text_color, 
                             NULL);
    }
  
  if (pref.diagram_only)
    {
      gnome_canvas_item_hide (canvas_node->text_item);
    }
  else
    {
      gnome_canvas_item_show (canvas_node->text_item);
      gnome_canvas_item_request_update (canvas_node->text_item);
    }

  gnome_canvas_item_show (canvas_node->node_item);
  gnome_canvas_item_request_update (canvas_node->node_item);

  node_i--;

  if (node_i)
    angle += 2 * M_PI / n_nodes;
  else
    {
      angle = 0.0;
      n_nodes = 0;
    }

  return FALSE;
}				/* reposition_canvas_nodes */
Exemplo n.º 17
0
/* - updates sizes, names, etc */
static gint
canvas_node_update(node_id_t * node_id, canvas_node_t * canvas_node,
		     GList **delete_list)
{
  node_t *node;
  gdouble node_size;
  static clock_t start = 0;
  clock_t end;
  gdouble cpu_time_used;
  char *nametmp = NULL;

  node = nodes_catalog_find(node_id);

  /* Remove node if node is too old or if capture is stopped */
  if (!node || !display_node (node))
    {
      /* adds current to list of canvas nodes to delete */
      *delete_list = g_list_prepend( *delete_list, node_id);
      g_my_debug ("Queing canvas node to remove.");
      need_reposition = TRUE;
      return FALSE;
    }

  switch (pref.node_size_variable)
    {
    case INST_TOTAL:
      node_size = get_node_size (node->node_stats.stats.average);
      break;
    case INST_INBOUND:
      node_size = get_node_size (node->node_stats.stats_in.average);
      break;
    case INST_OUTBOUND:
      node_size = get_node_size (node->node_stats.stats_out.average);
      break;
    case INST_PACKETS:
      node_size = get_node_size (node->node_stats.pkt_list.length);
      break;
    case ACCU_TOTAL:
      node_size = get_node_size (node->node_stats.stats.accumulated);
      break;
    case ACCU_INBOUND:
      node_size = get_node_size (node->node_stats.stats_in.accumulated);
      break;
    case ACCU_OUTBOUND:
      node_size = get_node_size (node->node_stats.stats_out.accumulated);
      break;
    case ACCU_PACKETS:
      node_size = get_node_size (node->node_stats.stats.accu_packets);
      break;
    case ACCU_AVG_SIZE:
      node_size = get_node_size (node->node_stats.stats.avg_size);
      break;
    default:
      node_size = get_node_size (node->node_stats.stats_out.average);
      g_warning (_("Unknown value or node_size_variable"));
    }

  /* limit the maximum size to avoid overload */
  if (node_size > MAX_NODE_SIZE)
    node_size = MAX_NODE_SIZE; 

  if (node->main_prot[pref.stack_level])
    {
      canvas_node->color = protohash_color(node->main_prot[pref.stack_level]);

      gnome_canvas_item_set (canvas_node->node_item,
			     "x1", -node_size / 2,
			     "x2", node_size / 2,
			     "y1", -node_size / 2,
			     "y2", node_size / 2,
			     "fill_color_gdk", &(canvas_node->color), NULL);
    }
  else
    {
      guint32 black = 0x000000ff;
      gnome_canvas_item_set (canvas_node->node_item,
			     "x1", -node_size / 2,
			     "x2", node_size / 2,
			     "y1", -node_size / 2,
			     "y2", node_size / 2,
			     "fill_color_rgba", black, NULL);
    }

  /* We check the name of the node, and update the canvas node name
   * if it has changed (useful for non blocking dns resolving) */
  /*TODO why is it exactly that sometimes it is NULL? */
  if (canvas_node->text_item)
    {
      g_object_get (G_OBJECT (canvas_node->text_item), 
                    "text", &nametmp,
		    NULL);
      if (strcmp (nametmp, node->name->str))
	{
	  gnome_canvas_item_set (canvas_node->text_item,
				 "text", node->name->str, 
                                 NULL);
	  gnome_canvas_item_request_update (canvas_node->text_item);
	}
      g_free (nametmp);
    }

  /* Processor time check. If too much time has passed, update the GUI */
  end = clock ();
  cpu_time_used = ((gdouble) (end - start)) / CLOCKS_PER_SEC;
  if (cpu_time_used > 0.05)
    {
      /* Force redraw */
      while (gtk_events_pending ())
	gtk_main_iteration ();
      start = end;
    }
  return FALSE;			/* False means keep on calling the function */

}				/* update_canvas_nodes */
Exemplo n.º 18
0
static gboolean
e_reflow_event (GnomeCanvasItem *item, GdkEvent *event)
{
	EReflow *reflow;
	int return_val = FALSE;

	reflow = E_REFLOW (item);

	switch( event->type )
		{
		case GDK_KEY_PRESS:
			return_val = e_selection_model_key_press(reflow->selection, (GdkEventKey *) event);
			break;
#if 0
			if (event->key.keyval == GDK_Tab ||
			    event->key.keyval == GDK_KP_Tab ||
			    event->key.keyval == GDK_ISO_Left_Tab) {
				int i;
				int count;
				count = reflow->count;
				for (i = 0; i < count; i++) {
					int unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i);
					GnomeCanvasItem *item = reflow->items[unsorted];
					EFocus has_focus;
					if (item) {
						g_object_get(item,
							     "has_focus", &has_focus,
							     NULL);
						if (has_focus) {
							if (event->key.state & GDK_SHIFT_MASK) {
								if (i == 0)
									return FALSE;
								i--;
							} else {
								if (i == count - 1)
									return FALSE;
								i++;
							}

							unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i);
							if (reflow->items[unsorted] == NULL) {
								reflow->items[unsorted] = e_reflow_model_incarnate (reflow->model, unsorted, GNOME_CANVAS_GROUP (reflow));
							}

							item = reflow->items[unsorted];
							gnome_canvas_item_set(item,
									      "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START,
									      NULL);
							return TRUE;
						}
					}
				}
			}
#endif
		case GDK_BUTTON_PRESS:
			switch(event->button.button)
				{
				case 1:
					{
						GdkEventButton *button = (GdkEventButton *) event;
						double n_x, max_x;
						n_x = button->x;
						n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
						n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));

						max_x = E_REFLOW_BORDER_WIDTH;
						max_x += (reflow->column_width + E_REFLOW_FULL_GUTTER) * reflow->column_count;
						if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > button->x ) {
							/* don't allow to drag the first line*/
							if (e_reflow_pick_line(reflow, button->x) == 0)
								return TRUE;
							reflow->which_column_dragged = e_reflow_pick_line(reflow, button->x);
							reflow->start_x = reflow->which_column_dragged * (reflow->column_width + E_REFLOW_FULL_GUTTER) - E_REFLOW_DIVIDER_WIDTH / 2;
							reflow->temp_column_width = reflow->column_width;
							reflow->column_drag = TRUE;

							gnome_canvas_item_grab (item,
										GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
										reflow->arrow_cursor,
										button->time);

							reflow->previous_temp_column_width = -1;
							reflow->need_column_resize = TRUE;
							gnome_canvas_item_request_update(item);
							return TRUE;
						}
					}
					break;
				case 4:
					{
						GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
						gdouble new_value = adjustment->value;
						new_value -= adjustment->step_increment;
						gtk_adjustment_set_value(adjustment, new_value);
					}
					break;
				case 5:
					{
						GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
						gdouble new_value = adjustment->value;
						new_value += adjustment->step_increment;
						if ( new_value > adjustment->upper - adjustment->page_size )
							new_value = adjustment->upper - adjustment->page_size;
						gtk_adjustment_set_value(adjustment, new_value);
					}
					break;
				}
			break;
		case GDK_BUTTON_RELEASE:
			if (reflow->column_drag) {
				gdouble old_width = reflow->column_width;
				GdkEventButton *button = (GdkEventButton *) event;
				GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
				reflow->temp_column_width = reflow->column_width +
					(button->x - reflow->start_x)/(reflow->which_column_dragged - e_reflow_pick_line(reflow, adjustment->value));
				if ( reflow->temp_column_width < 50 )
					reflow->temp_column_width = 50;
				reflow->column_drag = FALSE;
				if ( old_width != reflow->temp_column_width ) {
					gtk_adjustment_set_value(adjustment, adjustment->value + e_reflow_pick_line(reflow, adjustment->value) * (reflow->temp_column_width - reflow->column_width));
					reflow->column_width = reflow->temp_column_width;
					adjustment->step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
					adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
					gtk_adjustment_changed(adjustment);
					e_reflow_resize_children(item);
					e_canvas_item_request_reflow(item);
					gnome_canvas_request_redraw(item->canvas, 0, 0, reflow->width, reflow->height);
					column_width_changed (reflow);
				}
				reflow->need_column_resize = TRUE;
				gnome_canvas_item_request_update(item);
				gnome_canvas_item_ungrab (item, button->time);
				return TRUE;
			}
			break;
		case GDK_MOTION_NOTIFY:
			if (reflow->column_drag) {
				double old_width = reflow->temp_column_width;
				GdkEventMotion *motion = (GdkEventMotion *) event;
				GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
				reflow->temp_column_width = reflow->column_width +
					(motion->x - reflow->start_x)/(reflow->which_column_dragged - e_reflow_pick_line(reflow, adjustment->value));
				if (reflow->temp_column_width < 50)
					reflow->temp_column_width = 50;
				if (old_width != reflow->temp_column_width) {
					reflow->need_column_resize = TRUE;
					gnome_canvas_item_request_update(item);
				}
				return TRUE;
			} else {
				GdkEventMotion *motion = (GdkEventMotion *) event;
				double n_x, max_x;

				n_x = motion->x;
				n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
				n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));

				max_x = E_REFLOW_BORDER_WIDTH;
				max_x += (reflow->column_width + E_REFLOW_FULL_GUTTER) * reflow->column_count;

				if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > motion->x) {
					if ( reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->arrow_cursor);
						reflow->default_cursor_shown = FALSE;
					}
				} else
					if ( ! reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->default_cursor);
						reflow->default_cursor_shown = TRUE;
					}

			}
			break;
		case GDK_ENTER_NOTIFY:
			if (!reflow->column_drag) {
				GdkEventCrossing *crossing = (GdkEventCrossing *) event;
				double n_x, max_x;
				n_x = crossing->x;
				n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
				n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));

				max_x = E_REFLOW_BORDER_WIDTH;
				max_x += (reflow->column_width + E_REFLOW_FULL_GUTTER) * reflow->column_count;
				if ( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > crossing->x) {
					if ( reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->arrow_cursor);
						reflow->default_cursor_shown = FALSE;
					}
				}
			}
			break;
		case GDK_LEAVE_NOTIFY:
			if (!reflow->column_drag) {
				GdkEventCrossing *crossing = (GdkEventCrossing *) event;
				double n_x;
				n_x = crossing->x;
				n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
				n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));
				if ( !( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) ) {
					if ( ! reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->default_cursor);
						reflow->default_cursor_shown = TRUE;
					}
				}
			}
			break;
		default:
			break;
		}
	if (return_val)
		return return_val;
	else if (GNOME_CANVAS_ITEM_CLASS( e_reflow_parent_class )->event)
		return (* GNOME_CANVAS_ITEM_CLASS( e_reflow_parent_class )->event) (item, event);
	else
		return FALSE;
}
Exemplo n.º 19
0
static void
relation_arrow_update_line_segments (PlannerRelationArrow *arrow)
{
	PlannerRelationArrowPriv *priv;
	gdouble                   px1, py1, px2, py2;
	gdouble                   sx1, sy1, sx2, sy2;
	gdouble                   y;
	MrpRelationType           type;

	priv = arrow->priv;
	type = priv->type;

	planner_gantt_row_get_geometry (priv->predecessor,
					&px1,
					&py1,
					&px2,
					&py2);

	planner_gantt_row_get_geometry (priv->successor,
					&sx1,
					&sy1,
					&sx2,
					&sy2);
	if (type == MRP_RELATION_SS) {
		priv->num_points = 4;
		priv->arrow_dir = PLANNER_ARROW_RIGHT;

		/* LHS of pred */
		priv->points[0].x = px1;
		priv->points[0].y = py1 + (py2 - py1) / 2;

		/* Next two, a bit left of the most left */
		if (sx1 < px1) {
			priv->points[1].x = sx1 - MIN_SPACING - ARROW_SIZE;
			priv->points[1].y = py1 + (py2 - py1) / 2;
			priv->points[2].x = sx1 - MIN_SPACING - ARROW_SIZE;
			priv->points[2].y = sy1 + (sy2 - sy1) / 2;
		} else {
			priv->points[1].x = px1 - MIN_SPACING - ARROW_SIZE;
			priv->points[1].y = py1 + (py2 - py1) / 2;
			priv->points[2].x = px1 - MIN_SPACING - ARROW_SIZE;
			priv->points[2].y = sy1 + (sy2 - sy1) / 2;
		}

		priv->points[3].x = sx1;
		priv->points[3].y = sy1 + (sy2 - sy1) / 2;

	}
	else if (type == MRP_RELATION_FF) {

		priv->num_points = 4;
		priv->arrow_dir = PLANNER_ARROW_LEFT;

		/* LHS of pred */
		priv->points[0].x = px2;
		priv->points[0].y = py1 + (py2 - py1) / 2;

		/* Next two, a bit left of the most left */
		if (sx2 > px2) {
			priv->points[1].x = sx2 + MIN_SPACING + ARROW_SIZE;
			priv->points[1].y = py1 + (py2 - py1) / 2;
			priv->points[2].x = sx2 + MIN_SPACING + ARROW_SIZE;
			priv->points[2].y = sy1 + (sy2 - sy1) / 2;
		} else {
			priv->points[1].x = px2 + MIN_SPACING + ARROW_SIZE;
			priv->points[1].y = py1 + (py2 - py1) / 2;
			priv->points[2].x = px2 + MIN_SPACING + ARROW_SIZE;
			priv->points[2].y = sy1 + (sy2 - sy1) / 2;
		}

		priv->points[3].x = sx2;
		priv->points[3].y = sy1 + (sy2 - sy1) / 2;
	}
	else if (type == MRP_RELATION_SF) {
		/* Two cases for SF, as shown at the top of this file. */
		if (px1 >= sx2) {
			priv->num_points = 3;

			priv->points[0].x = px1;
			priv->points[0].y = py1 + (py2 - py1) / 2;

			priv->points[1].x = MIN (px1 - MIN_SPACING, sx2);
			priv->points[1].y = py1 + (py2 - py1) / 2;

			priv->points[2].x = MIN (px1 - MIN_SPACING, sx2);
			if (sy1 > py1) {
				priv->points[2].y = sy1;
				priv->arrow_dir = PLANNER_ARROW_DOWN;
			} else {
				priv->points[2].y = sy2;
				priv->arrow_dir = PLANNER_ARROW_UP;
			}


		} else {
			priv->num_points = 6;
			priv->arrow_dir = PLANNER_ARROW_LEFT;

			priv->points[0].x = px1;
			priv->points[0].y = py1 + (py2 - py1) / 2;

			priv->points[1].x = px1 - MIN_SPACING;
			priv->points[1].y = py1 + (py2 - py1) / 2;

	 		if (sy1 > py1) {
				y = py2 + (py2 - py1) / 2 - 1;
			} else {
				y = py1 - (py2 - py1) / 2 + 2;
			}

			priv->points[2].x = px1 - MIN_SPACING;
			priv->points[2].y = y;

			priv->points[3].x = sx2 + ARROW_SIZE + MIN_SPACING;
			priv->points[3].y = y;

			priv->points[4].x = sx2 + ARROW_SIZE + MIN_SPACING;
			priv->points[4].y = sy1 + (sy2 - sy1) / 2;

			priv->points[5].x = sx2;
			priv->points[5].y = sy1 + (sy2 - sy1) / 2;
		}


	} else {
	/* Two cases for FS, as shown at the top of this file. */
	if (px2 <= sx1) {
		priv->num_points = 3;

		priv->points[0].x = px2;
		priv->points[0].y = py1 + (py2 - py1) / 2;

		priv->points[1].x = MAX (px2 + MIN_SPACING, sx1);
		priv->points[1].y = py1 + (py2 - py1) / 2;

		priv->points[2].x = MAX (px2 + MIN_SPACING, sx1);
		if (sy1 > py1) {
			priv->points[2].y = sy1;
			priv->arrow_dir = PLANNER_ARROW_DOWN;
		} else {
			priv->points[2].y = sy2;
			priv->arrow_dir = PLANNER_ARROW_UP;
		}


	} else {
		priv->num_points = 6;
		priv->arrow_dir = PLANNER_ARROW_RIGHT;

		priv->points[0].x = px2;
		priv->points[0].y = py1 + (py2 - py1) / 2;

		priv->points[1].x = px2 + MIN_SPACING;
		priv->points[1].y = py1 + (py2 - py1) / 2;

 		if (sy1 > py1) {
			y = py2 + (py2 - py1) / 2 - 1;
		} else {
			y = py1 - (py2 - py1) / 2 + 2;
		}

		priv->points[2].x = px2 + MIN_SPACING;
		priv->points[2].y = y;

		priv->points[3].x = sx1 - ARROW_SIZE - MIN_SPACING;
		priv->points[3].y = y;

		priv->points[4].x = sx1 - ARROW_SIZE - MIN_SPACING;
		priv->points[4].y = sy1 + (sy2 - sy1) / 2;

		priv->points[5].x = sx1;
		priv->points[5].y = sy1 + (sy2 - sy1) / 2;
	}
	}

	gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (arrow));
}
Exemplo n.º 20
0
static gboolean
gnome_icon_text_item_event (GnomeCanvasItem *item, GdkEvent *event)
{
	GnomeIconTextItem *iti;
	GnomeIconTextItemPrivate *priv;
	int idx;
	double cx, cy;

	iti = GNOME_ICON_TEXT_ITEM (item);
	priv = iti->_priv;

	switch (event->type) {
	case GDK_KEY_PRESS:
		if (!iti->editing) {
			break;
		}

		switch(event->key.keyval) {

		/* Pass these events back to parent */
		case GDK_Escape:
		case GDK_Return:
		case GDK_KP_Enter:
			return FALSE;

		/* Handle up and down arrow keys.  GdkEntry does not know
		 * how to handle multi line items */
		case GDK_Up:
		case GDK_Down:
			iti_handle_arrow_key_event(iti, event);
			break;

		default:
			/* Check for control key operations */
			if (event->key.state & GDK_CONTROL_MASK) {
				return FALSE;
			}

			/* Handle any events that reach us */
			gtk_widget_event (GTK_WIDGET (priv->entry), event);
			break;
		}

		/* Update text item to reflect changes */
		update_pango_layout (iti);
		priv->need_text_update = TRUE;
		gnome_canvas_item_request_update (item);
		return TRUE;

	case GDK_BUTTON_PRESS:
		if (!iti->editing) {
			break;
		}

		if (event->button.button == 1) {
			gnome_canvas_w2c_d (item->canvas, event->button.x, event->button.y, &cx, &cy);
			idx = get_layout_index (iti,
						(cx - item->x1) + MARGIN_X,
						(cy - item->y1) + MARGIN_Y);
			iti_start_selecting (iti, idx, event->button.time);
		}
		return TRUE;
	case GDK_MOTION_NOTIFY:
		if (!priv->selecting)
			break;

		gtk_widget_event (GTK_WIDGET (priv->entry), event);
		gnome_canvas_w2c_d (item->canvas, event->button.x, event->button.y, &cx, &cy);
		idx = get_layout_index (iti,
					floor ((cx - (item->x1 + MARGIN_X)) + .5),
					floor ((cy - (item->y1 + MARGIN_Y)) + .5));

		iti_selection_motion (iti, idx);
		return TRUE;

	case GDK_BUTTON_RELEASE:
		if (priv->selecting && event->button.button == 1)
			iti_stop_selecting (iti, event->button.time);
		else
			break;
		return TRUE;
	default:
		break;
	}

	return FALSE;
}