Example #1
0
GtkWidget *
dia_layer_widget_new(Diagram *dia, Layer *layer)
{
  GtkWidget *widget;
  
  widget = GTK_WIDGET ( gtk_type_new (dia_layer_widget_get_type ()));
  dia_layer_set_layer(DIA_LAYER_WIDGET(widget), dia, layer);

  /* These may get toggled when the button is set without the widget being
   * selected first. */
  DIA_LAYER_WIDGET(widget)->connect_on = FALSE;
  DIA_LAYER_WIDGET(widget)->connect_off = FALSE;

  return widget;
}
Example #2
0
static void
dia_layer_widget_connectable_toggled(GtkToggleButton *widget,
				     gpointer userdata)
{
  DiaLayerWidget *lw = DIA_LAYER_WIDGET(userdata);
  if (!lw->layer)
    return;
  if (shifted) {
    shifted = FALSE;
    internal_call = TRUE;
    dia_layer_widget_exclusive_connectable(lw);
    internal_call = FALSE;
  } else {
    lw->layer->connectable = gtk_toggle_button_get_active(widget);
  }
  if (lw->layer == lw->dia->data->active_layer) {
    lw->connect_off = !gtk_toggle_button_get_active(widget);
    if (lw->connect_off) lw->connect_on = FALSE;
  } else {
    lw->connect_on = gtk_toggle_button_get_active(widget);
    if (lw->connect_on) lw->connect_off = FALSE;
  }
  gtk_widget_queue_draw(GTK_WIDGET(lw));
  if (!internal_call) {
    diagram_add_update_all(lw->dia);
    diagram_flush(lw->dia);
  }
}
Example #3
0
static void
dia_layer_widget_exclusive_connectable(DiaLayerWidget *layer_widget)
{
  GList *list;
  DiaLayerWidget *lw;
  Layer *layer;
  int connectable = FALSE;
  int i;

  /*  First determine if _any_ other layer widgets are set to connectable  */
  for (i=0;i<layer_widget->dia->data->layers->len;i++) {
    layer = g_ptr_array_index(layer_widget->dia->data->layers, i);
    if (layer_widget->layer != layer) {
	connectable |= layer->connectable;
    }
  }

  /*  Now, toggle the connectability for all layers except the specified one  */
  list = GTK_LIST(layer_dialog->layer_list)->children;
  while (list) {
    lw = DIA_LAYER_WIDGET(list->data);
    if (lw != layer_widget) 
      dia_layer_widget_set_connectable(lw, !connectable);
    else {
      dia_layer_widget_set_connectable(lw, TRUE);
    }
    gtk_widget_queue_draw(GTK_WIDGET(lw));
    
    list = g_list_next(list);
  }
}
Example #4
0
static GtkWidget *
dia_layer_widget_new(Diagram *dia, Layer *layer)
{
  GtkWidget *widget;
  
  widget = GTK_WIDGET ( gtk_type_new (dia_layer_widget_get_type ()));
  dia_layer_set_layer(DIA_LAYER_WIDGET(widget), dia, layer);

  /* These may get toggled when the button is set without the widget being
   * selected first.
   * The connect_on state gets also used to restore with just a deselect
   * of the active layer.
   */
  DIA_LAYER_WIDGET(widget)->connect_on = layer->connectable;
  DIA_LAYER_WIDGET(widget)->connect_off = FALSE;

  return widget;
}
Example #5
0
static void
layer_dialog_rename_callback(GtkWidget *widget, gpointer gdata)
{
  GtkWidget *selected;
  Diagram *dia;
  Layer *layer;
  dia = layer_dialog->diagram;
  selected = GTK_LIST(layer_dialog->layer_list)->selection->data;
  layer = dia->data->active_layer;
  layer_dialog_edit_layer (DIA_LAYER_WIDGET (selected), dia, layer);
}
Example #6
0
static gboolean
dia_layer_widget_button_event(GtkWidget *widget,
			      GdkEventButton *event,
			      gpointer userdata)
{
  DiaLayerWidget *lw = DIA_LAYER_WIDGET(userdata);

  shifted = event->state & GDK_SHIFT_MASK;
  internal_call = FALSE;
  /* Redraw the label? */
  gtk_widget_queue_draw(GTK_WIDGET(lw));
  return FALSE;
}
Example #7
0
static void
dia_layer_widget_unrealize(GtkWidget *widget)
{
  DiaLayerWidget *lw = DIA_LAYER_WIDGET(widget);

  if (lw->edit_dialog != NULL) {
    gtk_widget_destroy(lw->edit_dialog->dialog);
    g_free(lw->edit_dialog);
    lw->edit_dialog = NULL;
  }

  (* GTK_WIDGET_CLASS (gtk_type_class(gtk_list_item_get_type ()))->unrealize) (widget);
}
Example #8
0
static void
dia_layer_deselect_callback(GtkWidget *widget, gpointer data)
{
  DiaLayerWidget *lw = DIA_LAYER_WIDGET(widget);

  /** If layer dialog or diagram is missing, we are so dead. */
  if (layer_dialog == NULL || layer_dialog->diagram == NULL) return;

  internal_call = TRUE;
  /** Set to on if the user has requested so. */
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lw->connectable), 
			       lw->connect_on);
  internal_call = FALSE;
}
Example #9
0
static gint
layer_list_events (GtkWidget *widget,
		   GdkEvent  *event)
{
  GdkEventKey *kevent;
  GdkEventButton *bevent;
  GtkWidget *event_widget;
  DiaLayerWidget *layer_widget;

  event_widget = gtk_get_event_widget (event);

  if (GTK_IS_LIST_ITEM (event_widget)) {
    layer_widget = DIA_LAYER_WIDGET(event_widget);

    switch (event->type) {
    case GDK_BUTTON_PRESS:
      bevent = (GdkEventButton *) event;
      break;

    case GDK_2BUTTON_PRESS:
      bevent = (GdkEventButton *) event;
      layer_dialog_edit_layer(layer_widget, NULL, NULL);
      return TRUE;

    case GDK_KEY_PRESS:
      kevent = (GdkEventKey *) event;
      switch (kevent->keyval) {
      case GDK_Up:
	/* printf ("up arrow\n"); */
	break;
      case GDK_Down:
	/* printf ("down arrow\n"); */
	break;
      default:
	return FALSE;
      }
      return TRUE;

    default:
      break;
    }
  }

  return FALSE;
}
Example #10
0
static void
dia_layer_widget_visible_clicked(GtkToggleButton *widget,
				 gpointer userdata)
{
  DiaLayerWidget *lw = DIA_LAYER_WIDGET(userdata);
  struct LayerVisibilityChange *change;

  /* Have to use this internal_call hack 'cause there's no way to switch
   * a toggle button without causing the 'clicked' event:(
   */
  if (!internal_call) {
    Diagram *dia = lw->dia;
    change = undo_layer_visibility(dia, lw->layer, shifted);
    /** This apply kills 'lw', thus we have to hold onto 'lw->dia' */
    layer_visibility_change_apply(change, dia);
    undo_set_transactionpoint(dia->undo);   
  }
}
Example #11
0
static void
layer_dialog_lower_callback(GtkWidget *widget, gpointer gdata)
{
  Layer *layer;
  Diagram *dia;
  GtkWidget *selected;
  GList *list = NULL;
  int pos;

  dia = layer_dialog->diagram;

  if ((dia != NULL) && (dia->data->layers->len>1)) {
    assert(GTK_LIST(layer_dialog->layer_list)->selection != NULL);
    selected = GTK_LIST(layer_dialog->layer_list)->selection->data;

    pos = gtk_list_child_position(GTK_LIST(layer_dialog->layer_list), selected);

    if (pos < dia->data->layers->len-1) {
      layer = DIA_LAYER_WIDGET(selected)->layer;
      data_lower_layer(dia->data, layer);
      
      list = g_list_prepend(list, selected);

      g_object_ref(selected);
      
      gtk_list_remove_items(GTK_LIST(layer_dialog->layer_list),
			    list);
      
      gtk_list_insert_items(GTK_LIST(layer_dialog->layer_list),
			    list, pos + 1);

      g_object_unref(selected);

      gtk_list_select_item(GTK_LIST(layer_dialog->layer_list), pos+1);
      
      diagram_add_update_all(dia);
      diagram_flush(dia);

      undo_layer(dia, layer, TYPE_LOWER_LAYER, 0);
      undo_set_transactionpoint(dia->undo);
    }

  }
}
Example #12
0
static void
dia_layer_select_callback(GtkWidget *widget, gpointer data)
{
  DiaLayerWidget *lw;
  lw = DIA_LAYER_WIDGET(widget);

  /* Don't deselect if we're selected the active layer.  This can happen
   * if the window has been defocused. */
  if (lw->dia->data->active_layer != lw->layer) {
    diagram_remove_all_selected(lw->dia, TRUE);
  }
  diagram_update_extents(lw->dia);
  data_set_active_layer(lw->dia->data, lw->layer);
  diagram_add_update_all(lw->dia);
  diagram_flush(lw->dia);

  internal_call = TRUE;
  if (lw->connect_off) { /* If the user wants this off, it becomes so */
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lw->connectable), FALSE);
  } else {
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lw->connectable), TRUE);
  }
  internal_call = FALSE;
}
Example #13
0
/*
 * Used to avoid writing to possibly already deleted layer in
 * dia_layer_widget_connectable_toggled(). Must be called before
 * e.g. gtk_list_clear_items() cause that will emit the toggled
 * signal to last focus widget. See bug #329096
 */
static void
_layer_widget_clear_layer (GtkWidget *widget, gpointer user_data)
{
  DiaLayerWidget *lw = DIA_LAYER_WIDGET(widget);
  lw->layer = NULL;
}