Esempio n. 1
0
GtkWidget *
interface_get_toolbox_shell(void)
{
  if (is_integrated_ui ())
    return GTK_WIDGET(ui.main_window);

  return toolbox_shell;
}
Esempio n. 2
0
void
layer_dialog_show()
{
  if (is_integrated_ui () == FALSE)
  {   
  if (layer_dialog == NULL || layer_dialog->dialog == NULL)
    create_layer_dialog();
  gtk_window_present(GTK_WINDOW(layer_dialog->dialog));
  }
}
Esempio n. 3
0
void
layer_dialog_show()
{
  if (is_integrated_ui () == FALSE)
  {   
  if (layer_dialog == NULL || layer_dialog->dialog == NULL)
    layer_dialog_create();
  g_assert(layer_dialog != NULL); /* must be valid now */
  gtk_window_present(GTK_WINDOW(layer_dialog->dialog));
  }
}
Esempio n. 4
0
File: menus.c Progetto: GNOME/dia
GtkAccelGroup *
menus_get_display_accels (void)
{
  /* for integrated-ui the accels are delivered by menus_get_integrated_ui_menubar() */
  g_return_val_if_fail (is_integrated_ui () == FALSE, NULL);

  if (initialise)
    menus_init();

  return display_accels;
}
Esempio n. 5
0
/** Set the display's mainpoint magnetism setting, updating menu and button
 * in the process */
void
ddisplay_set_snap_to_objects(DDisplay *ddisp, gboolean magnetic)
{
  GtkToggleAction *mainpoint_magnetism;
  ddisp->mainpoint_magnetism = magnetic;

  mainpoint_magnetism = GTK_TOGGLE_ACTION (menus_get_action ("ViewSnaptoobjects"));
  if (is_integrated_ui ())
    integrated_ui_toolbar_object_snap_synchronize_to_display (ddisp);
  /* Currently, this can cause double emit, but that's a small problem. */
  gtk_toggle_action_set_active (mainpoint_magnetism, ddisp->mainpoint_magnetism);
  ddisplay_update_statusbar(ddisp);
}
Esempio n. 6
0
/** Set the display's snap-to-grid setting, updating menu and button
 * in the process */
void
ddisplay_set_snap_to_grid(DDisplay *ddisp, gboolean snap)
{
  GtkToggleAction *snap_to_grid;
  ddisp->grid.snap = snap;

  snap_to_grid = GTK_TOGGLE_ACTION (menus_get_action ("ViewSnaptogrid"));
  if (is_integrated_ui ())
    integrated_ui_toolbar_grid_snap_synchronize_to_display (ddisp);
  /* Currently, this can cause double emit, but that's a small problem. */
  gtk_toggle_action_set_active (snap_to_grid, ddisp->grid.snap);
  ddisplay_update_statusbar(ddisp);
}
Esempio n. 7
0
File: menus.c Progetto: GNOME/dia
void
menus_set_recent (GtkActionGroup *actions)
{
  GList *list;
  guint id;
  const char   *recent_path;

  if (is_integrated_ui ())
    recent_path = INTEGRATED_MENU "/File/FileRecentEnd";
  else
    recent_path = TOOLBOX_MENU "/File/FileRecentEnd";

  if (recent_actions) {
    menus_clear_recent ();
  }

  list = gtk_action_group_list_actions (actions);
  g_return_if_fail (list);

  /* sort it by the action name to preserve out order */
  list = g_list_sort (list, cmp_action_names);

  recent_actions = actions;
  g_object_ref (G_OBJECT (recent_actions));
  gtk_ui_manager_insert_action_group (_ui_manager,
                    recent_actions,
                    10 /* insert at back */ );

  do {
    const gchar* aname = gtk_action_get_name (GTK_ACTION (list->data));

    id = gtk_ui_manager_new_merge_id (_ui_manager);
    recent_merge_ids = g_slist_prepend (recent_merge_ids, GUINT_TO_POINTER (id));

    gtk_ui_manager_add_ui (_ui_manager, id,
                 recent_path,
                 aname,
                 aname,
                 GTK_UI_MANAGER_AUTO,
                 TRUE);

  } while (NULL != (list = list->next));
}
Esempio n. 8
0
/*!
 * Called when the widget's window "size, position or stacking"
 * changes. Needs GDK_STRUCTURE_MASK set.
 */
static gboolean
canvas_configure_event (GtkWidget         *widget,
			GdkEventConfigure *cevent,
			DDisplay          *ddisp)
{
  gboolean new_size = FALSE;
  int width, height;

  g_return_val_if_fail (widget == ddisp->canvas, FALSE);


  if (ddisp->renderer) {
    width = dia_renderer_get_width_pixels (ddisp->renderer);
    height = dia_renderer_get_height_pixels (ddisp->renderer);
  } else {
    /* We can continue even without a renderer here because
     * ddisplay_resize_canvas () does the setup for us.
     */
    width = height = 0;
  }

  /* Only do this when size is really changing */
  if (width != cevent->width || height != cevent->height) {
    g_print ("Canvas size change...\n");
    ddisplay_resize_canvas (ddisp, cevent->width, cevent->height);
    ddisplay_update_scrollbars(ddisp);
    /* on resize stop further propagation - does not help */
    new_size = TRUE;
  }

  /* If the UI is not integrated, resizing should set the resized
   * window as active.  With integrated UI, there is only one window.
   */
  if (is_integrated_ui () == 0)
    display_set_active(ddisp);

  /* continue propagation with FALSE */
  return new_size;
}
Esempio n. 9
0
static void
update_zoom_status(DDisplay *ddisp)
{
  gchar* zoom_text;

  if (is_integrated_ui ())
  {
    zoom_text = g_strdup_printf("%.0f%%",
	   ddisp->zoom_factor * 100.0 / DDISPLAY_NORMAL_ZOOM);

    integrated_ui_toolbar_set_zoom_text (ddisp->common_toolbar, zoom_text);  
  }
  else
  {
    GtkWidget *zoomcombo;
    zoom_text = g_strdup_printf("%.1f%%",
	     ddisp->zoom_factor * 100.0 / DDISPLAY_NORMAL_ZOOM);
    zoomcombo = ddisp->zoom_status;
    gtk_entry_set_text(GTK_ENTRY (g_object_get_data (G_OBJECT(zoomcombo), "user_data")),
		       zoom_text);
  }

  g_free(zoom_text); /* Copied by gtk_entry_set_text */
}
Esempio n. 10
0
gboolean
app_exit(void)
{
  GList *list;
  GSList *slist;

  /*
   * The following "solves" a crash related to a second call of app_exit,
   * after gtk_main_quit was called. It may be a win32 gtk-1.3.x bug only
   * but the check shouldn't hurt on *ix either.          --hb
   */
  static gboolean app_exit_once = FALSE;

  if (app_exit_once) {
    g_error(_("This shouldn't happen.  Please file a bug report at bugzilla.gnome.org\n"
	      "describing how you caused this message to appear.\n"));
    return FALSE;
  }

  if (diagram_modified_exists()) {
    if (is_integrated_ui ())
    {
      GtkWidget                *dialog;
      int                       result;
      exit_dialog_item_array_t *items  = NULL;
      GList *                   list; 
      Diagram *                 diagram;
      
      dialog = exit_dialog_make (GTK_WINDOW (interface_get_toolbox_shell ()), 
                                _("Exiting Dia"));

      list = dia_open_diagrams();
      while (list)
      {
        diagram = list->data;

        if (diagram_is_modified (diagram))
        {
          const gchar * name = diagram_get_name (diagram);
          const gchar * path = diagram->filename;
          exit_dialog_add_item (dialog, name, path, diagram);
        }

        list = g_list_next (list);
      }

      result = exit_dialog_run (dialog, &items);
  
      gtk_widget_destroy (dialog);

      if (result == EXIT_DIALOG_EXIT_CANCEL)
      {
        return FALSE;
      }
      else if (result == EXIT_DIALOG_EXIT_SAVE_SELECTED)
      {
	    DiaContext *ctx = dia_context_new(_("Save"));
        int i;
        for (i = 0 ; i < items->array_size ; i++) {
	  gchar *filename;

	  diagram  = items->array[i].data;
	  filename = g_filename_from_utf8 (diagram->filename, -1, NULL, NULL, NULL);
	  diagram_update_extents (diagram);
	  dia_context_set_filename (ctx, filename);
	  if (!diagram_save (diagram, filename, ctx)) {
	    exit_dialog_free_items (items);
	    dia_context_release (ctx);
	    return FALSE;
	  } else {
	    dia_context_reset (ctx);
	  }
	  g_free (filename);
	}
	dia_context_release (ctx);
	exit_dialog_free_items (items);
      } 
      else if (result == EXIT_DIALOG_EXIT_NO_SAVE) 
      {
        list = dia_open_diagrams();
        while (list) {
          diagram = list->data;

	  /* slight hack: don't ask again */
          diagram_set_modified (diagram, FALSE);
	  undo_clear(diagram->undo);
          list = g_list_next (list);
	}
      }
    }
    else
    {
    GtkWidget *dialog;
    GtkWidget *button;
    dialog = gtk_message_dialog_new(
	       NULL, GTK_DIALOG_MODAL,
               GTK_MESSAGE_QUESTION,
               GTK_BUTTONS_NONE, /* no standard buttons */
	       _("Quitting without saving modified diagrams"));
    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
		 _("Modified diagrams exist. "
		 "Are you sure you want to quit Dia "
 		 "without saving them?"));

    gtk_window_set_title (GTK_WINDOW(dialog), _("Quit Dia"));
  
    button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
    gtk_dialog_add_action_widget (GTK_DIALOG(dialog), button, GTK_RESPONSE_CANCEL);
#if GTK_CHECK_VERSION(2,18,0)
    gtk_widget_set_can_default (GTK_WIDGET (button), TRUE);
#else
    GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
#endif
    gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);

    button = gtk_button_new_from_stock (GTK_STOCK_QUIT);
    gtk_dialog_add_action_widget (GTK_DIALOG(dialog), button, GTK_RESPONSE_OK);

    gtk_widget_show_all (dialog);

    if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
      gtk_widget_destroy(dialog);
      return FALSE;
    }
    gtk_widget_destroy(dialog);
    }
  }
  prefs_save();

  persistence_save();

  dynobj_refresh_finish();

  {
    DiaContext *ctx = dia_context_new (_("Exit"));
    dia_object_defaults_save (NULL, ctx);
    dia_context_release (ctx);
  }
  /* Free loads of stuff (toolbox) */

  list = dia_open_diagrams();
  while (list!=NULL) {
    Diagram *dia = (Diagram *)list->data;
    list = g_list_next(list);

    slist = dia->displays;
    while (slist!=NULL) {
      DDisplay *ddisp = (DDisplay *)slist->data;
      slist = g_slist_next(slist);

      gtk_widget_destroy(ddisp->shell);
    }
    /* The diagram is freed when the last display is destroyed */
  }
  
  /* save pluginrc */
  if (dia_is_interactive)
    dia_pluginrc_write();

  gtk_main_quit();

  /* This printf seems to prevent a race condition with unrefs. */
  /* Yuck.  -Lars */
  /* Trying to live without it. -Lars 10/8/07*/
  /* g_print(_("Thank you for using Dia.\n")); */
  app_exit_once = TRUE;

  return TRUE;
}
Esempio n. 11
0
/**
 * @param ddisp The diagram display object that a window is created for
 * @param width Diagram widgth
 * @param height Diagram Height
 * @param title Window title
 * @param use_mbar Flag to indicate whether to add a menubar to the window
 */
void
create_display_shell(DDisplay *ddisp,
		     int width, int height,
		     char *title, int use_mbar)
{
  GtkWidget *table, *widget;
  GtkWidget *status_hbox;
  GtkWidget *root_vbox = NULL;
  GtkWidget *zoom_hbox, *zoom_label;
  int s_width, s_height;

  if (app_is_interactive() && is_integrated_ui())
  {
    use_integrated_ui_for_display_shell(ddisp, title);
    return;
  }
 
  ddisp->is_standalone_window = TRUE;
  ddisp->container            = NULL;

  s_width = gdk_screen_width ();
  s_height = gdk_screen_height ();
  if (width > s_width)
    width = s_width;
  if (height > s_height)
    height = s_height;

  /*  The toplevel shell */
  ddisp->shell = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (ddisp->shell), title);
  gtk_window_set_role (GTK_WINDOW (ddisp->shell), "diagram_window");
  gtk_window_set_icon_name (GTK_WINDOW (ddisp->shell), "dia");
  gtk_window_set_default_size(GTK_WINDOW (ddisp->shell), width, height);
  /* set_icon_name needs registered theme icons, not always available: provide fallback */
  if (!gtk_window_get_icon (GTK_WINDOW (ddisp->shell))) {
    static GdkPixbuf *pixbuf = NULL;

    if (!pixbuf)
      pixbuf = gdk_pixbuf_new_from_inline(-1, dia_diagram_icon, FALSE, NULL);
    if (pixbuf)
      gtk_window_set_icon (GTK_WINDOW (ddisp->shell), pixbuf);
  }

  g_object_set_data (G_OBJECT (ddisp->shell), "user_data", (gpointer) ddisp);

  _ddisplay_setup_events (ddisp, ddisp->shell);
  /* following two not shared with integrated UI */
  g_signal_connect (G_OBJECT (ddisp->shell), "delete_event",
		    G_CALLBACK (ddisplay_delete), ddisp);
  g_signal_connect (G_OBJECT (ddisp->shell), "destroy",
		    G_CALLBACK (ddisplay_destroy), ddisp);

  /*  the table containing all widgets  */
  table = gtk_table_new (4, 3, FALSE);
  gtk_table_set_col_spacing (GTK_TABLE (table), 0, 1);
  gtk_table_set_col_spacing (GTK_TABLE (table), 1, 2);
  gtk_table_set_row_spacing (GTK_TABLE (table), 0, 1);
  gtk_table_set_row_spacing (GTK_TABLE (table), 1, 2);
  gtk_container_set_border_width (GTK_CONTAINER (table), 2);
  if (use_mbar) 
  {
      root_vbox = gtk_vbox_new (FALSE, 1);
      gtk_container_add (GTK_CONTAINER (ddisp->shell), root_vbox);
      gtk_box_pack_end (GTK_BOX (root_vbox), table, TRUE, TRUE, 0);
  }
  else
  {
      gtk_container_add (GTK_CONTAINER (ddisp->shell), table);
  }
  

  /*  scrollbars, rulers, canvas, menu popup button  */
  if (!use_mbar) {
      ddisp->origin = gtk_button_new();
#if GTK_CHECK_VERSION(2,18,0)
      gtk_widget_set_can_focus (ddisp->origin, FALSE);
#else
      GTK_WIDGET_UNSET_FLAGS(ddisp->origin, GTK_CAN_FOCUS);
#endif
      widget = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
      gtk_container_add(GTK_CONTAINER(ddisp->origin), widget);
      gtk_widget_set_tooltip_text(widget, _("Diagram menu."));
      gtk_widget_show(widget);
      g_signal_connect(G_OBJECT(ddisp->origin), "button_press_event",
		     G_CALLBACK(origin_button_press), ddisp);
  }
  else {
      ddisp->origin = gtk_frame_new (NULL);
      gtk_frame_set_shadow_type (GTK_FRAME (ddisp->origin), GTK_SHADOW_OUT);
  }
  
  _ddisplay_setup_rulers (ddisp, ddisp->shell, table);
  _ddisplay_setup_scrollbars (ddisp, table, width, height);
  _ddisplay_setup_navigation (ddisp, table);

  ddisp->canvas = create_canvas (ddisp);

  /*  pack all remaining widgets  */
  gtk_table_attach (GTK_TABLE (table), ddisp->origin, 0, 1, 0, 1,
                    GTK_FILL, GTK_FILL, 0, 0);
  gtk_table_attach (GTK_TABLE (table), ddisp->canvas, 1, 2, 1, 2,
                    GTK_EXPAND | GTK_SHRINK | GTK_FILL,
                    GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);

  /* TODO rob use per window accel */
  ddisp->accel_group = menus_get_display_accels ();
  gtk_window_add_accel_group(GTK_WINDOW(ddisp->shell), ddisp->accel_group);

  if (use_mbar) 
  {
    ddisp->menu_bar = menus_create_display_menubar (&ddisp->ui_manager, &ddisp->actions);
    g_assert (ddisp->menu_bar);
    gtk_box_pack_start (GTK_BOX (root_vbox), ddisp->menu_bar, FALSE, TRUE, 0);
  }

  /* the statusbars */
  status_hbox = gtk_hbox_new (FALSE, 2);

  /* Zoom status pseudo-optionmenu */
  ddisp->zoom_status = create_zoom_widget(ddisp);
  zoom_hbox = gtk_hbox_new(FALSE, 0);
  zoom_label = gtk_label_new(_("Zoom"));
  gtk_box_pack_start (GTK_BOX(zoom_hbox), zoom_label,
		      FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX(zoom_hbox), ddisp->zoom_status,
		      FALSE, FALSE, 0);

  gtk_box_pack_start (GTK_BOX (status_hbox), zoom_hbox, FALSE, FALSE, 0);

  /* Grid on/off button */
  ddisp->grid_status = dia_toggle_button_new_with_icons(dia_on_grid_icon,
							dia_off_grid_icon);
  
  g_signal_connect(G_OBJECT(ddisp->grid_status), "toggled",
		   G_CALLBACK (grid_toggle_snap), ddisp);
  gtk_widget_set_tooltip_text(ddisp->grid_status,
		       _("Toggles snap-to-grid for this window."));
  gtk_box_pack_start (GTK_BOX (status_hbox), ddisp->grid_status,
		      FALSE, FALSE, 0);


  ddisp->mainpoint_status = dia_toggle_button_new_with_icons(dia_mainpoints_on_icon,
							dia_mainpoints_off_icon);
  
  g_signal_connect(G_OBJECT(ddisp->mainpoint_status), "toggled",
		   G_CALLBACK (interface_toggle_mainpoint_magnetism), ddisp);
  gtk_widget_set_tooltip_text(ddisp->mainpoint_status,
		       _("Toggles object snapping for this window."));
  gtk_box_pack_start (GTK_BOX (status_hbox), ddisp->mainpoint_status,
		      FALSE, FALSE, 0);


  /* Statusbar */
  ddisp->modified_status = gtk_statusbar_new ();

  gtk_box_pack_start (GTK_BOX (status_hbox), ddisp->modified_status,
		      TRUE, TRUE, 0);

  gtk_table_attach (GTK_TABLE (table), status_hbox, 0, 3, 3, 4,
                    GTK_FILL, GTK_FILL, 0, 0);

  display_rulers_show (ddisp);
  gtk_widget_show (ddisp->zoom_status);
  gtk_widget_show (zoom_hbox);
  gtk_widget_show (zoom_label);
  gtk_widget_show (ddisp->grid_status);
  gtk_widget_show (ddisp->mainpoint_status);
  gtk_widget_show (ddisp->modified_status);
  gtk_widget_show (status_hbox);
  gtk_widget_show (table);
  if (use_mbar) 
  {
      gtk_widget_show (ddisp->menu_bar);
      gtk_widget_show (root_vbox);
  }
  gtk_widget_show (ddisp->shell);

  /* before showing up, checking canvas's REAL size */
  if (use_mbar && ddisp->hrule->allocation.width > width) 
  {
    /* The menubar is not shrinkable, so the shell will have at least
     * the menubar's width. If the diagram's requested width is smaller,
     * the canvas will be enlarged to fit the place. In this case, we
     * need to adjust the horizontal scrollbar according to the size
     * that will be allocated, which the same as the hrule got.
     */

    width = ddisp->hrule->allocation.width;

    gtk_adjustment_set_upper (ddisp->hsbdata, width);
    gtk_adjustment_set_page_increment (ddisp->hsbdata, (width - 1) / 4);
    gtk_adjustment_set_page_size (ddisp->hsbdata, width - 1);

    gtk_adjustment_changed (GTK_ADJUSTMENT(ddisp->hsbdata));
  }
  gtk_widget_show (ddisp->canvas);

  /*  set the focus to the canvas area  */
  gtk_widget_grab_focus (ddisp->canvas);
}