Index: app/preferences.c =================================================================== --- app/preferences.c (revision 3682) +++ app/preferences.c (working copy) @@ -77,6 +77,7 @@ static void update_floating_toolbox(DiaPrefData *pref, char *ptr); static void update_internal_prefs(DiaPrefData *pref, char *ptr); +static void update_ui_type_prefs(DiaPrefData *pref, char *ptr); static int default_true = 1; static int default_false = 0; @@ -150,8 +151,9 @@ get_units_name_list, update_internal_prefs }, { "use_integrated_ui", PREF_BOOLEAN, PREF_OFFSET(use_integrated_ui), - &default_false, 0, N_("Integrated UI") }, + &default_false, 0, N_("Integrated UI"), NULL, FALSE, NULL, update_ui_type_prefs }, + { NULL, PREF_NONE, 0, NULL, 1, N_("New diagram:") }, { "is_portrait", PREF_BOOLEAN, PREF_OFFSET(new_diagram.is_portrait), &default_true, 1, N_("Portrait") }, { "new_diagram_papertype", PREF_CHOICE, PREF_OFFSET(new_diagram.papertype), @@ -705,3 +707,9 @@ NULL); } } + +static void +update_ui_type_prefs(DiaPrefData *pref, char *ptr) +{ + message_notice(_("User Interface type settings change will take after restart")); +} Index: app/display.c =================================================================== --- app/display.c (revision 3682) +++ app/display.c (working copy) @@ -68,14 +68,25 @@ static void update_zoom_status(DDisplay *ddisp) { - GtkWidget *zoomcombo; gchar* zoom_text; - zoomcombo = ddisp->zoom_status; - zoom_text = g_strdup_printf("%.1f%%", + if (is_integrated_ui ()) + { + zoom_text = g_strdup_printf("%.0f%%", ddisp->zoom_factor * 100.0 / DDISPLAY_NORMAL_ZOOM); - gtk_entry_set_text(GTK_ENTRY(gtk_object_get_user_data(GTK_OBJECT(zoomcombo))), - zoom_text); + + 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(gtk_object_get_user_data(GTK_OBJECT(zoomcombo))), + zoom_text); + } + g_free(zoom_text); /* Copied by gtk_entry_set_text */ } @@ -797,12 +808,18 @@ GtkToggleAction *snap_to_grid; ddisp->grid.snap = snap; - if (ddisp->menu_bar == NULL) { - snap_to_grid = GTK_TOGGLE_ACTION (menus_get_action ("ViewSnaptogrid")); - } else { - snap_to_grid = GTK_TOGGLE_ACTION (gtk_action_group_get_action (ddisp->actions, "ViewSnaptogrid")); + if (is_integrated_ui ()) + { + snap_to_grid = GTK_TOGGLE_ACTION (menus_get_action ("ViewSnaptogrid")); } - + else + { + if (ddisp->menu_bar == NULL) { + snap_to_grid = GTK_TOGGLE_ACTION (menus_get_action ("ViewSnaptogrid")); + } else { + snap_to_grid = GTK_TOGGLE_ACTION (gtk_action_group_get_action (ddisp->actions, "ViewSnaptogrid")); + } + } /* Currently, this can cause double emit, but that's a small problem. */ gtk_toggle_action_set_active (snap_to_grid, ddisp->grid.snap); @@ -1000,6 +1017,7 @@ p.x = (r.left+r.right)/2; p.y = (r.top+r.bottom)/2; + display_set_active(ddisp); return ddisplay_scroll_center_point(ddisp, &p); } @@ -1079,7 +1097,10 @@ ddisplay_im_context_preedit_reset(ddisp, active_focus()); /* This calls ddisplay_really_destroy */ - gtk_widget_destroy (ddisp->shell); + if (ddisp->is_standalone_window) + gtk_widget_destroy (ddisp->shell); + else + gtk_widget_destroy (ddisp->container); } static void @@ -1263,7 +1284,27 @@ void ddisplay_set_title(DDisplay *ddisp, char *title) { - gtk_window_set_title (GTK_WINDOW (ddisp->shell), title); + if (ddisp->is_standalone_window) + gtk_window_set_title (GTK_WINDOW (ddisp->shell), title); + else + { + GtkNotebook *notebook = g_object_get_data (G_OBJECT (ddisp->shell), + DIA_MAIN_NOTEBOOK); + /* Find the page with ddisp then set the label on the tab */ + gint num_pages = gtk_notebook_get_n_pages (notebook); + gint num; + GtkWidget *page; + for (num = 0 ; num < num_pages ; num++) + { + page = gtk_notebook_get_nth_page (notebook,num); + if (g_object_get_data (G_OBJECT (page), "DDisplay") == ddisp) + { + GtkLabel *label = g_object_get_data (G_OBJECT (page), "tab-label"); + gtk_label_set_text(label,title); + break; + } + } + } } void @@ -1319,16 +1360,48 @@ diagram_properties_set_diagram(ddisp ? ddisp->diagram : NULL); if (ddisp) { - display_update_menu_state(ddisp); + if (ddisp->is_standalone_window) + { + display_update_menu_state(ddisp); - if (prefs.toolbox_on_top) { - gtk_window_set_transient_for(GTK_WINDOW(interface_get_toolbox_shell()), - GTK_WINDOW(ddisp->shell)); + if (prefs.toolbox_on_top) { + gtk_window_set_transient_for(GTK_WINDOW(interface_get_toolbox_shell()), + GTK_WINDOW(ddisp->shell)); + } else { + gtk_window_set_transient_for(GTK_WINDOW(interface_get_toolbox_shell()), + NULL); + } } else { - gtk_window_set_transient_for(GTK_WINDOW(interface_get_toolbox_shell()), - NULL); + GtkNotebook *notebook = g_object_get_data (G_OBJECT (ddisp->shell), + DIA_MAIN_NOTEBOOK); + /* Find the page with ddisp then set the label on the tab */ + gint num_pages = gtk_notebook_get_n_pages (notebook); + gint num; + GtkWidget *page; + for (num = 0 ; num < num_pages ; num++) + { + page = gtk_notebook_get_nth_page (notebook,num); + if (g_object_get_data (G_OBJECT (page), "DDisplay") == ddisp) + { + gtk_notebook_set_current_page (notebook,num); + break; + } + } + /* synchronize_ui_to_active_display (ddisp); */ + /* ZOOM */ + update_zoom_status (ddisp); + + /* Snap to grid */ + ddisplay_set_snap_to_grid (ddisp, ddisp->grid.snap); /* menus */ + integrated_ui_toolbar_grid_snap_synchronize_to_display (ddisp); + + /* Object snapping */ + ddisplay_set_snap_to_objects (ddisp, ddisp->mainpoint_magnetism); + integrated_ui_toolbar_object_snap_synchronize_to_display (ddisp); + } } else { + /* TODO: Prevent gtk_window_set_transient_for() in Integrated UI case */ gtk_window_set_transient_for(GTK_WINDOW(interface_get_toolbox_shell()), NULL); } Index: app/display.h =================================================================== --- app/display.h (revision 3682) +++ app/display.h (working copy) @@ -92,6 +92,16 @@ /* Preedit String */ gchar *preedit_string; PangoAttrList *preedit_attrs; + + /* Is there another case? Like I see embedded-dia modules, do these do something + * in addition??? */ + gboolean is_standalone_window; + + /* Points to Integrated UI Toolbar */ + GtkToolbar *common_toolbar; + + /* Points to widget containing the diagram if not standalone window */ + GtkWidget *container; }; extern GdkCursor *default_cursor; Index: app/app_procs.c =================================================================== --- app/app_procs.c (revision 3682) +++ app/app_procs.c (working copy) @@ -934,6 +934,7 @@ /* Set up autosave to check every 5 minutes */ gtk_timeout_add(5*60*1000, autosave_check_autosave, NULL); + /* Create Diagram Tree Window */ create_tree_window(); persistence_register_window_create("sheets_main_dialog", @@ -947,15 +948,34 @@ made_conversions = handle_all_diagrams(files, export_file_name, export_file_format, size, show_layers); if (dia_is_interactive && files == NULL && !nonew) { - gchar *filename = g_filename_from_utf8(_("Diagram1.dia"), -1, NULL, NULL, NULL); - Diagram *diagram = new_diagram (filename); - g_free(filename); + if (prefs.use_integrated_ui) + { + /* Use the same function call to create a new diagram as that used by + * the menu and toolbar */ + GList * list; + file_new_callback(NULL); + list = dia_open_diagrams(); + if (list) + { + Diagram * diagram = list->data; + diagram_update_extents(diagram); + diagram->is_default = TRUE; + } + } + else + { + gchar *filename = g_filename_from_utf8(_("Diagram1.dia"), -1, NULL, NULL, NULL); + Diagram *diagram = new_diagram (filename); + g_free(filename); - if (diagram != NULL) { - diagram_update_extents(diagram); - diagram->is_default = TRUE; - layer_dialog_set_diagram(diagram); - new_display(diagram); + if (diagram != NULL) { + diagram_update_extents(diagram); + diagram->is_default = TRUE; + /* I think this is done in diagram_init() with a call to + * layer_dialog_update_diagram_list() */ + layer_dialog_set_diagram(diagram); + new_display(diagram); + } } } g_slist_free(files); Index: app/filedlg.c =================================================================== --- app/filedlg.c (revision 3682) +++ app/filedlg.c (working copy) @@ -145,7 +145,7 @@ } /** - * Respond to the user finishing the Save Dialog either accept or cancel/destroy + * Respond to the user finishing the Open Dialog either accept or cancel/destroy */ static void file_open_response_callback(GtkWidget *fs, @@ -267,17 +267,17 @@ gtk_widget_show(options); g_signal_connect(GTK_OBJECT(opendlg), "response", G_CALLBACK(file_open_response_callback), omenu); - /* set up file filters */ - filter = gtk_file_filter_new (); - gtk_file_filter_set_name (filter, _("All Files")); - gtk_file_filter_add_pattern (filter, "*"); - gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (opendlg), filter); /* match the other selections extension */ filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("Supported Formats")); gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_FILENAME, matching_extensions_filter, filter_guess_import_filter, NULL); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (opendlg), filter); + /* set up file filters */ + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("All Files")); + gtk_file_filter_add_pattern (filter, "*"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (opendlg), filter); /* candidate for user prefs */ gtk_combo_box_set_active (GTK_COMBO_BOX (omenu), persistence_get_integer ("import-filter")); Index: app/interface.c =================================================================== --- app/interface.c (revision 3682) +++ app/interface.c (working copy) @@ -248,6 +248,17 @@ GtkWidget *modify_tool_button; +/** + * Used to determine if the current user interface is the integrated interface or + * the distributed interface. This cannot presently be determined by the preferences + * setting because changing that setting at run time does not change the interface. + * @return Non-zero if the integrated interface is present, else zero. + */ +int is_integrated_ui (void) +{ + return ui.main_window == NULL? 0 : 1; +} + static void grid_toggle_snap(GtkWidget *widget, gpointer data) { @@ -412,7 +423,45 @@ } /** + * Updates toolbar and menu items to reflect the active display + */ +void synchronize_ui_to_active_display (DDisplay *ddisp) +{ + /* TOOLBAR ITEM */ + + /* Zoom */ + + /* Snap-to-grid */ + + /* Object Snapping */ + +} + + +/** * @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 + * @param top_level_window + */ +void +close_notebook_page_callback (GtkButton *button, + gpointer user_data) +{ + GtkBox *page = user_data; + GtkNotebook *notebook = g_object_get_data (G_OBJECT (page), "GtkNotebook"); + gint page_num = gtk_notebook_page_num (notebook, GTK_WIDGET(page)); + DDisplay *ddisp = g_object_get_data (G_OBJECT (page), "DDisplay"); + + ddisplay_close (ddisp); + /*gtk_notebook_remove_page (notebook, page_num);*/ + /* gtk_widget_destroy( GTK_WIDGET (page)); */ +} + +/** + * @param ddisp The diagram display object that a window is created for * @param title */ static void @@ -425,23 +474,17 @@ GtkWidget *label; /* Text label for the notebook page */ GtkWidget *tab_label_container; /* Container to hold text label & close button */ int width, height; /* Width/Heigth of the diagram */ - GtkWidget *page; /* Container to hold the diagram */ GtkWidget *image; GtkWidget *close_button; /* Close button for the notebook page */ GtkWidget *widget; GtkRcStyle *rcstyle; - /* I think this is purposeless but I don't want to bother to figure it out at the moment */ - if (!tool_tips) /* needed here if we dont create_toolbox() */ - tool_tips = gtk_tooltips_new (); - - /* ddisp->shell = page; */ - /* ddisp->shell = gtk_event_box_new (); */ - /* ddisp->shell = gtk_window_new (GTK_WINDOW_TOPLEVEL); */ + ddisp->is_standalone_window = FALSE; + ddisp->shell = GTK_WIDGET (ui.main_window); /* Create a new tab page */ - page = gtk_vbox_new(FALSE, 0); + ddisp->container = gtk_vbox_new(FALSE, 0); tab_label_container = gtk_hbox_new(FALSE,3); label = gtk_label_new( title ); @@ -464,22 +507,23 @@ GTK_ICON_SIZE_MENU); gtk_container_add (GTK_CONTAINER(close_button), image); + gtk_signal_connect (GTK_OBJECT (close_button), "clicked", + GTK_SIGNAL_FUNC (close_notebook_page_callback), ddisp->container); /* */ gtk_box_pack_start( GTK_BOX(tab_label_container), close_button, FALSE, FALSE, 0 ); gtk_widget_show (close_button); gtk_widget_show (image); - /* TODO: Add close button to notebook label (and create close function) */ - gtk_notebook_append_page (GTK_NOTEBOOK(ui.diagram_notebook), - page, + ddisp->container, tab_label_container); - gtk_object_set_user_data (GTK_OBJECT (page), (gpointer) ddisp); - g_object_set_data (G_OBJECT (page), "window", ui.main_window); + g_object_set_data (G_OBJECT (ddisp->container), "DDisplay", ddisp); + g_object_set_data (G_OBJECT (ddisp->container), "tab-label", label); + g_object_set_data (G_OBJECT (ddisp->container), "window", ui.main_window); - gtk_widget_set_events (page, + gtk_widget_set_events (ddisp->container, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_FOCUS_CHANGE_MASK); @@ -492,22 +536,19 @@ gtk_table_set_row_spacing (GTK_TABLE (table), 1, 2); gtk_container_set_border_width (GTK_CONTAINER (table), 2); - /* TODO:Maybe assign ddisp->shell to page??? - gtk_container_add (GTK_CONTAINER (ddisp->shell), table); */ - gtk_box_pack_start( GTK_BOX(page), table, TRUE, TRUE, 0 ); - /*gtk_container_add (GTK_CONTAINER (ddisp->shell), table); */ + gtk_box_pack_start( GTK_BOX(ddisp->container), table, TRUE, TRUE, 0 ); /* scrollbars, rulers, canvas, menu popup button */ ddisp->origin = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (ddisp->origin), GTK_SHADOW_OUT); ddisp->hrule = gtk_hruler_new (); - g_signal_connect_swapped (GTK_OBJECT (page), "motion_notify_event", + g_signal_connect_swapped (GTK_OBJECT (ddisp->container), "motion_notify_event", G_CALLBACK(GTK_WIDGET_GET_CLASS (ddisp->hrule)->motion_notify_event), GTK_OBJECT (ddisp->hrule)); ddisp->vrule = gtk_vruler_new (); - g_signal_connect_swapped (GTK_OBJECT (page), "motion_notify_event", + g_signal_connect_swapped (GTK_OBJECT (ddisp->container), "motion_notify_event", G_CALLBACK(GTK_WIDGET_GET_CLASS (ddisp->vrule)->motion_notify_event), GTK_OBJECT (ddisp->vrule)); @@ -577,18 +618,15 @@ gtk_table_attach (GTK_TABLE (table), navigation_button, 2, 3, 2, 3, GTK_FILL, GTK_FILL, 0, 0); - /* TODO rob use per window accel */ - ddisp->accel_group = menus_get_display_accels (); - - /* TODO: Do this once! */ - gtk_window_add_accel_group(GTK_WINDOW(page), ddisp->accel_group); - /* the statusbars */ status_hbox = gtk_hbox_new (FALSE, 2); + ddisp->common_toolbar = ui.toolbar; + /* TODO: Migrate Zoom, Grid Status to main window toolbar */ /* Zoom status pseudo-optionmenu */ - ddisp->zoom_status = create_zoom_widget(ddisp); + ddisp->zoom_status = NULL; +/*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, @@ -597,18 +635,14 @@ 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); - + ddisp->grid_status = NULL; +/* g_signal_connect(G_OBJECT(ddisp->grid_status), "toggled", G_CALLBACK (grid_toggle_snap), ddisp); - gtk_tooltips_set_tip(tool_tips, ddisp->grid_status, - _("Toggles snap-to-grid for this window."), NULL); - 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); @@ -620,7 +654,7 @@ FALSE, FALSE, 0); /* Statusbar */ - ddisp->modified_status = GTK_WIDGET( ui.statusbar ); + ddisp->modified_status = GTK_WIDGET (ui.statusbar); /* gtk_box_pack_start (GTK_BOX (status_hbox), ddisp->modified_status, TRUE, TRUE, 0); @@ -637,15 +671,20 @@ 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); - gtk_widget_show (page); + gtk_widget_show (ddisp->container); gtk_widget_show (ddisp->canvas); + /* Ensure that the the new page is showing */ + gtk_notebook_set_current_page (ui.diagram_notebook, + gtk_notebook_get_n_pages (ui.diagram_notebook)-1); + + integrated_ui_toolbar_grid_snap_synchronize_to_display (ddisp); + + integrated_ui_toolbar_object_snap_synchronize_to_display (ddisp); + /* TODO: Figure out how to detect if anti-aliased renderer was set */ /** For the distributed display this is called when the ddisp->canvas is shown. * The show causes a GDK_CONFIGURE event but this is not happening here. If this @@ -677,12 +716,16 @@ GtkWidget *zoom_hbox, *zoom_label; int s_width, s_height; - if (prefs.use_integrated_ui) + if (app_is_interactive() && is_integrated_ui()) { use_integrated_ui_for_display_shell(ddisp, title); return; } + + ddisp->is_standalone_window = TRUE; + ddisp->container = NULL; + if (!tool_tips) /* needed here if we dont create_toolbox() */ tool_tips = gtk_tooltips_new (); @@ -1542,66 +1585,6 @@ } /** - * - */ -static gboolean -toolbar_callback (GtkWidget *toolbar, gpointer data) -{ - /* TODO: Implement Integrated UI Toolbar callback */ - return FALSE; -} - -static GtkWidget * -create_integrated_ui_toolbar (void) -{ - GtkToolbar *toolbar; - GtkToolItem *button; - GtkToolItem *sep; - GtkToolItem *tool_item; - GtkWidget *w; - - toolbar = GTK_TOOLBAR (gtk_toolbar_new ()); - - button = gtk_tool_button_new_from_stock (GTK_STOCK_NEW); - gtk_toolbar_insert (toolbar, button, -1); - gtk_widget_show (GTK_WIDGET (button)); - - button = gtk_tool_button_new_from_stock (GTK_STOCK_OPEN); - gtk_toolbar_insert (toolbar, button, -1); - gtk_widget_show (GTK_WIDGET (button)); - - button = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE); - gtk_toolbar_insert (toolbar, button, -1); - gtk_widget_show (GTK_WIDGET (button)); - - sep = gtk_separator_tool_item_new (); - gtk_toolbar_insert (toolbar, sep, -1); - gtk_widget_show (GTK_WIDGET (sep)); - - button = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_OUT); - gtk_toolbar_insert (toolbar, button, -1); - gtk_widget_show (GTK_WIDGET (button)); - - button = gtk_tool_button_new_from_stock (GTK_STOCK_ZOOM_IN); - gtk_toolbar_insert (toolbar, button, -1); - gtk_widget_show (GTK_WIDGET (button)); - - tool_item = gtk_tool_item_new (); - /* TODO: Create a Zoom Indicator for the toolbar */ - w = gtk_label_new ("100%"); - gtk_container_add (GTK_CONTAINER (tool_item), w); - gtk_toolbar_insert (toolbar, tool_item, -1); - gtk_widget_show (GTK_WIDGET (tool_item)); - gtk_widget_show (w); - - sep = gtk_separator_tool_item_new (); - gtk_toolbar_insert (toolbar, sep, -1); - gtk_widget_show (GTK_WIDGET (sep)); - - return GTK_WIDGET (toolbar); -} - -/** * Create integrated user interface */ void create_integrated_ui (void) @@ -1624,9 +1607,13 @@ gtk_widget_ref (window); gtk_window_set_title (GTK_WINDOW (window), "Dia v" VERSION); #endif - gtk_window_set_role (GTK_WINDOW (window), "main_window"); - gtk_window_set_default_size(GTK_WINDOW(window), 146, 349); + /* hint to window manager on X so the wm can put the window in the same + as it was when the application shut down */ + gtk_window_set_role (GTK_WINDOW (window), DIA_MAIN_WINDOW); + + gtk_window_set_default_size (GTK_WINDOW (window), 146, 349); + pixbuf = gdk_pixbuf_new_from_inline (-1, dia_app_icon, FALSE, NULL); if (pixbuf) { gtk_window_set_icon (GTK_WINDOW (window), pixbuf); @@ -1694,19 +1681,19 @@ /* menus -- initialised afterwards, because initing the display menus * uses the tool buttons*/ - menus_get_toolbox_menubar(&menubar, &accel_group); + menus_get_integrated_ui_menubar(&menubar, &toolbar, &accel_group); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); #ifdef GNOME gnome_app_set_menus (GNOME_APP (window), GTK_MENU_BAR (menubar)); #else gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0); + /* TODO: integrated-UI --> Figure out how to deal with updateable menu items!!! + menus_initialize_updatable_items (&ddisp->updatable_menu_items, ddisp->actions); */ gtk_widget_show (menubar); #endif /* Toolbar */ - toolbar = create_integrated_ui_toolbar (); - - /* TODO: delete set_style */ + /* TODO: maybe delete set_style(toolbar,ICONS) */ gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); gtk_box_pack_start (GTK_BOX (main_vbox), toolbar, FALSE, TRUE, 0); gtk_widget_show (toolbar); @@ -1718,6 +1705,9 @@ ui.diagram_notebook = GTK_NOTEBOOK (notebook); ui.statusbar = GTK_STATUSBAR (statusbar); + /* For access outside here: */ + g_object_set_data (G_OBJECT (ui.main_window), DIA_MAIN_NOTEBOOK, notebook); + /* TODO: Figure out what to do about toolbox_shell for integrated UI */ toolbox_shell = window; } @@ -1837,5 +1827,8 @@ GtkWidget * interface_get_toolbox_shell(void) { + if (is_integrated_ui ()) + return ui.main_window; + return toolbox_shell; } Index: app/interface.h =================================================================== --- app/interface.h (revision 3682) +++ app/interface.h (working copy) @@ -36,6 +36,19 @@ #include "linewidth_area.h" #include "attributes.h" +/* Integrated UI Constants */ +#define DIA_MAIN_WINDOW "dia-main-window" +#define DIA_MAIN_NOTEBOOK "dia-main-notebook" + +/* Distributed UI Constants */ +#define DIA_TOOLBOX "dia-toolbox" + +void create_integrated_ui (void); + +void synchronize_ui_to_active_display (DDisplay *ddisp); + +int is_integrated_ui (void); + void create_display_shell(DDisplay *ddisp, int width, int height, char *title, int use_mbar, int top_level_window); Index: app/diagram.c =================================================================== --- app/diagram.c (revision 3682) +++ app/diagram.c (working copy) @@ -297,6 +297,8 @@ if (diagram != NULL && was_default) { diagram_update_for_filename(diagram); diagram->is_default = FALSE; + if ( g_slist_length(diagram->displays) == 1 ) + display_set_active (diagram->displays->data); } return diagram; Index: app/menus.c =================================================================== --- app/menus.c (revision 3682) +++ app/menus.c (working copy) @@ -40,14 +40,27 @@ #include "object_ops.h" #include "sheets.h" #include "dia-app-icons.h" +#include "widgets.h" +#include "preferences.h" #define DIA_STOCK_GROUP "dia-stock-group" #define DIA_STOCK_UNGROUP "dia-stock-ungroup" #define DIA_SHOW_TEAROFFS TRUE +/* Integrated UI Toolbar Constants */ +#define DIA_INTEGRATED_TOOLBAR_ZOOM_TEXT "dia-integrated-toolbar-zoom_text" +#define DIA_INTEGRATED_TOOLBAR_SNAP_GRID "dia-integrated-toolbar-snap-grid" +#define DIA_INTEGRATED_TOOLBAR_OBJECT_SNAP "dia-integrated-toolbar-object-snap" + static void plugin_callback (GtkWidget *widget, gpointer data); +static GtkWidget * +create_integrated_ui_toolbar (void); + +static void +add_toolbox_plugin_actions (GtkUIManager *ui_manager); + /* Actions common to toolbox and diagram window */ static const GtkActionEntry common_entries[] = { @@ -238,6 +251,14 @@ /* need initialisation? */ static gboolean initialise = TRUE; +/* integrated ui */ +static GtkUIManager *integrated_ui_manager = NULL; +static GtkActionGroup *integrated_ui_actions = NULL; +static GtkActionGroup *integrated_ui_tool_actions = NULL; +static GtkAccelGroup *integrated_ui_accels = NULL; +static GtkWidget *integrated_ui_menubar = NULL; +static GtkWidget *integrated_ui_toolbar = NULL; + /* toolbox */ static GtkUIManager *toolbox_ui_manager = NULL; static GtkActionGroup *toolbox_actions = NULL; @@ -257,7 +278,7 @@ static gchar* _dia_translate (const gchar* term, gpointer data) { - gchar* trans = term; + gchar* trans = (gchar*) term; if (term && *term) { /* first try our own ... */ @@ -308,6 +329,212 @@ return TRUE; } +/** + * Temporary hack + */ +static gboolean +toolbar_callback (GtkWidget *toolbar, gpointer data) +{ + if (data) + { + void (*callback)(GtkAction *action); + + callback = data; + callback(NULL); + } + return FALSE; +} + +static void +integrated_ui_toolbar_grid_snap_set_state(int state) +{ + DDisplay *ddisp = ddisplay_active (); + if (ddisp) + { + ;/* Get the current state */ + } +} + +/** + * Synchronized the Object snap property button with the display. + * @param param Display to synchronize to. + */ +void +integrated_ui_toolbar_object_snap_synchronize_to_display(gpointer *param) +{ + DDisplay *ddisp = param; + if (ddisp && ddisp->common_toolbar) + { + GtkToggleButton *b = g_object_get_data (G_OBJECT (ddisp->common_toolbar), + DIA_INTEGRATED_TOOLBAR_OBJECT_SNAP); + gboolean active = ddisp->mainpoint_magnetism? TRUE : FALSE; + gtk_toggle_button_set_active (b, active); + } +} + +/** + * Sets the Object-snap property for the active display. + * @param b Object snap toggle button. + * @param not_used + */ +static void +integrated_ui_toolbar_object_snap_toggle(GtkToggleButton *b, gpointer *not_used) +{ + DDisplay *ddisp = ddisplay_active (); + if (ddisp) + { + ddisplay_set_snap_to_objects (ddisp, gtk_toggle_button_get_active (b)); + } +} + +/** + * Synchronizes the Snap-to-grid property button with the display. + * @param param Display to synchronize to. + */ +void +integrated_ui_toolbar_grid_snap_synchronize_to_display(gpointer *param) +{ + DDisplay *ddisp = param; + if (ddisp && ddisp->common_toolbar) + { + GtkToggleButton *b = g_object_get_data (G_OBJECT (ddisp->common_toolbar), + DIA_INTEGRATED_TOOLBAR_SNAP_GRID); + gboolean active = ddisp->grid.snap? TRUE : FALSE; + gtk_toggle_button_set_active (b, active); + } +} + +/** + * Sets the Snap-to-grid property for the active display. + * @param b Snap to grid toggle button. + * @param not_used + */ +static void +integrated_ui_toolbar_grid_snap_toggle(GtkToggleButton *b, gpointer *not_used) +{ + DDisplay *ddisp = ddisplay_active (); + if (ddisp) + { + ddisplay_set_snap_to_grid (ddisp, gtk_toggle_button_get_active (b)); + } +} + +/** + * Sets the zoom text for the toolbar + * @param toolbar Integrated UI toolbar. + * @param text Current zoom percentage for the active window + */ +void integrated_ui_toolbar_set_zoom_text (GtkToolbar *toolbar, const gchar * text) +{ + if (toolbar) + { + GtkLabel *label = g_object_get_data (G_OBJECT (toolbar), + DIA_INTEGRATED_TOOLBAR_ZOOM_TEXT); + gtk_label_set_text (label, text); + } +} + +/* Create the toolbar for the integrated UI */ +static GtkWidget * +create_integrated_ui_toolbar (void) +{ + GtkToolbar *toolbar; + GtkToolItem *button; + GtkToolItem *sep; + GtkToolItem *tool_item; + GtkWidget *w; + GtkAction *action; + int i; + + struct item_t { + const gchar * stock_id; + void (*callback)(GtkAction *); + } item[] = { + { GTK_STOCK_NEW, file_new_callback }, + { GTK_STOCK_OPEN, file_open_callback }, + { GTK_STOCK_SAVE, file_save_callback }, + { GTK_STOCK_SAVE_AS, file_save_as_callback }, + { 0 }, + { GTK_STOCK_ZOOM_IN, view_zoom_in_callback }, + { GTK_STOCK_ZOOM_OUT, view_zoom_out_callback }, + }; + size_t num_items = sizeof(item)/sizeof(struct item_t); + + toolbar = GTK_TOOLBAR (gtk_toolbar_new ()); + + for(i = 0 ; i < num_items ; i++) + { + if (item[i].stock_id) + { + button = gtk_tool_button_new_from_stock (item[i].stock_id); + gtk_toolbar_insert (toolbar, button, -1); + gtk_signal_connect (GTK_OBJECT (button),"clicked", + GTK_SIGNAL_FUNC (toolbar_callback), item[i].callback); + gtk_widget_show (GTK_WIDGET (button)); + } + else + { + sep = gtk_separator_tool_item_new (); + gtk_toolbar_insert (toolbar, sep, -1); + gtk_widget_show (GTK_WIDGET (sep)); + } + } + + tool_item = gtk_tool_item_new (); + w = gtk_label_new ("100%"); + gtk_container_add (GTK_CONTAINER (tool_item), w); + gtk_toolbar_insert (toolbar, tool_item, -1); + gtk_widget_show (GTK_WIDGET (tool_item)); + gtk_widget_show (w); + g_object_set_data (G_OBJECT (toolbar), + DIA_INTEGRATED_TOOLBAR_ZOOM_TEXT, + w); + + sep = gtk_separator_tool_item_new (); + gtk_toolbar_insert (toolbar, sep, -1); + gtk_widget_show (GTK_WIDGET (sep)); + + /* Snap to grid */ + /*action = menus_get_action ("ViewSnaptogrid"); + tool_item = gtk_action_create_tool_item (action);*/ + tool_item = gtk_tool_item_new (); + w = dia_toggle_button_new_with_icons (dia_on_grid_icon, + dia_off_grid_icon); + g_signal_connect (G_OBJECT (w), "toggled", + G_CALLBACK (integrated_ui_toolbar_grid_snap_toggle), toolbar); + gtk_tooltips_set_tip (tool_tips, w, + _("Toggles snap-to-grid."), NULL); + gtk_container_add (GTK_CONTAINER (tool_item), w); + gtk_toolbar_insert (toolbar, tool_item, -1); + gtk_widget_show (GTK_WIDGET (tool_item)); + gtk_widget_show (w); + g_object_set_data (G_OBJECT (toolbar), + DIA_INTEGRATED_TOOLBAR_SNAP_GRID, + w); + + /* Object Snapping */ + tool_item = gtk_tool_item_new (); + w = dia_toggle_button_new_with_icons (dia_mainpoints_on_icon, + dia_mainpoints_off_icon); + g_signal_connect (G_OBJECT (w), "toggled", + G_CALLBACK (integrated_ui_toolbar_object_snap_toggle), toolbar); + gtk_tooltips_set_tip (tool_tips, w, + _("Toggles object snapping."), NULL); + gtk_container_add (GTK_CONTAINER (tool_item), w); + gtk_toolbar_insert (toolbar, tool_item, -1); + gtk_widget_show (GTK_WIDGET (tool_item)); + gtk_widget_show (w); + g_object_set_data (G_OBJECT (toolbar), + DIA_INTEGRATED_TOOLBAR_OBJECT_SNAP, + w); + + sep = gtk_separator_tool_item_new (); + gtk_toolbar_insert (toolbar, sep, -1); + gtk_widget_show (GTK_WIDGET (sep)); + + return GTK_WIDGET (toolbar); +} + /* * Initialise tool actions. * The caller owns the return value. @@ -463,12 +690,7 @@ static void menus_init(void) { - DiaCallbackFilter *cbf; - GtkActionGroup *plugin_actions; - GtkAction *action; - gchar *accelfilename; - GList *cblist; - guint id; + gchar *accelfilename; GError *error = NULL; gchar *uifile; @@ -545,11 +767,37 @@ g_assert (display_menubar); + add_toolbox_plugin_actions (toolbox_ui_manager); + + add_plugin_actions (display_ui_manager); + + /* load accelerators and prepare to later save them */ + accelfilename = dia_config_filename("menurc"); + + if (accelfilename) { + gtk_accel_map_load(accelfilename); + g_free(accelfilename); + } + gtk_quit_add(1, save_accels, NULL); +} + +static void +add_toolbox_plugin_actions (GtkUIManager *ui_manager) +{ + GtkActionGroup *plugin_actions; + GtkActionGroup *actions; + GtkAction *action; + GList *cblist; + DiaCallbackFilter *cbf = NULL; + gchar *name; + guint id; + static guint cnt = 0; + /* plugin menu hooks */ plugin_actions = gtk_action_group_new ("toolbox-plugin-actions"); gtk_action_group_set_translation_domain (plugin_actions, NULL); gtk_action_group_set_translate_func (plugin_actions, _dia_translate, NULL, NULL); - gtk_ui_manager_insert_action_group (toolbox_ui_manager, + gtk_ui_manager_insert_action_group (ui_manager, plugin_actions, 5 /* "back" */); g_object_unref (plugin_actions); @@ -568,11 +816,6 @@ continue; } - if (0 != strncmp (cbf->menupath, TOOLBOX_MENU, strlen (TOOLBOX_MENU))) { - /* hook for display, skip */ - continue; - } - action = gtk_action_new (cbf->action, cbf->description, NULL, NULL); g_signal_connect (G_OBJECT (action), "activate", @@ -583,24 +826,77 @@ g_object_unref (G_OBJECT (action)); id = gtk_ui_manager_new_merge_id (toolbox_ui_manager); - gtk_ui_manager_add_ui (toolbox_ui_manager, id, + gtk_ui_manager_add_ui (ui_manager, id, cbf->menupath, cbf->description, cbf->action, GTK_UI_MANAGER_AUTO, FALSE); } +} - add_plugin_actions (display_ui_manager); +void +menus_get_integrated_ui_menubar (GtkWidget **menubar, + GtkWidget **toolbar, + GtkAccelGroup **accel_group) +{ + GError *error = NULL; + gchar *uifile; - /* load accelerators and prepare to later save them */ - accelfilename = dia_config_filename("menurc"); - - if (accelfilename) { - gtk_accel_map_load(accelfilename); - g_free(accelfilename); + if (initialise) + menus_init(); + + /* the integrated ui menu */ + integrated_ui_actions = gtk_action_group_new ("integrated-ui-actions"); + gtk_action_group_set_translation_domain (integrated_ui_actions, NULL); + gtk_action_group_set_translate_func (integrated_ui_actions, _dia_translate, NULL, NULL); + gtk_action_group_add_actions (integrated_ui_actions, common_entries, + G_N_ELEMENTS (common_entries), NULL); + gtk_action_group_add_actions (integrated_ui_actions, toolbox_entries, + G_N_ELEMENTS (toolbox_entries), NULL); + gtk_action_group_add_actions (integrated_ui_actions, display_entries, + G_N_ELEMENTS (display_entries), NULL); + gtk_action_group_add_toggle_actions (integrated_ui_actions, toolbox_toggle_entries, + G_N_ELEMENTS (toolbox_toggle_entries), + NULL); + gtk_action_group_add_toggle_actions (integrated_ui_actions, display_toggle_entries, + G_N_ELEMENTS (display_toggle_entries), + NULL); + gtk_action_group_add_radio_actions (integrated_ui_actions, + display_select_radio_entries, + G_N_ELEMENTS (display_select_radio_entries), + 1, + G_CALLBACK (select_style_callback), + NULL); + + integrated_ui_tool_actions = create_tool_actions (); + + integrated_ui_manager = gtk_ui_manager_new (); + gtk_ui_manager_set_add_tearoffs (integrated_ui_manager, DIA_SHOW_TEAROFFS); + gtk_ui_manager_insert_action_group (integrated_ui_manager, integrated_ui_actions, 0); + gtk_ui_manager_insert_action_group (integrated_ui_manager, integrated_ui_tool_actions, 0); + + uifile = build_ui_filename ("ui/integrated-ui.xml"); + if (!gtk_ui_manager_add_ui_from_file (integrated_ui_manager, uifile, &error)) { + g_warning ("building integrated ui menus failed: %s", error->message); + g_error_free (error); + error = NULL; } - gtk_quit_add(1, save_accels, NULL); + g_free (uifile); + + add_toolbox_plugin_actions (integrated_ui_manager); + add_plugin_actions (integrated_ui_manager); + + integrated_ui_accels = gtk_ui_manager_get_accel_group (integrated_ui_manager); + integrated_ui_menubar = gtk_ui_manager_get_widget (integrated_ui_manager, "/IntegratedUIMenu"); + integrated_ui_toolbar = create_integrated_ui_toolbar (); + + if (menubar) + *menubar = integrated_ui_menubar; + if (toolbar) + *toolbar = integrated_ui_toolbar; + if (accel_group) + *accel_group = integrated_ui_accels; } void @@ -631,6 +927,9 @@ if (initialise) menus_init(); + if (is_integrated_ui ()) + return integrated_ui_accels; + return display_accels; } @@ -687,13 +986,13 @@ GtkAccelGroup * menus_get_accel_group () { - return toolbox_accels; + return is_integrated_ui ()? integrated_ui_accels : toolbox_accels; } GtkActionGroup * menus_get_action_group () { - return toolbox_actions; + return is_integrated_ui ()? integrated_ui_actions : toolbox_actions; } GtkAction * @@ -701,10 +1000,17 @@ { GtkAction *action; - action = gtk_action_group_get_action (toolbox_actions, name); - if (action == NULL) { - action = gtk_action_group_get_action (display_actions, name); + if (is_integrated_ui ()) + { + action = gtk_action_group_get_action (integrated_ui_actions, name); } + else + { + action = gtk_action_group_get_action (toolbox_actions, name); + if (action == NULL) { + action = gtk_action_group_get_action (display_actions, name); + } + } return action; } @@ -714,7 +1020,20 @@ { GList *list; guint id; + GtkUIManager *ui_manager; + const char *recent_path; + if (is_integrated_ui ()) + { + ui_manager = integrated_ui_manager; + recent_path = "/IntegratedUIMenu/File/FileRecentEnd"; + } + else + { + ui_manager = toolbox_ui_manager; + recent_path = "/ToolboxMenu/File/FileRecentEnd"; + } + if (recent_actions) { menus_clear_recent (); } @@ -724,16 +1043,16 @@ recent_actions = actions; g_object_ref (G_OBJECT (recent_actions)); - gtk_ui_manager_insert_action_group (toolbox_ui_manager, + gtk_ui_manager_insert_action_group (ui_manager, recent_actions, 10 /* insert at back */ ); do { - id = gtk_ui_manager_new_merge_id (toolbox_ui_manager); + id = gtk_ui_manager_new_merge_id (ui_manager); recent_merge_ids = g_slist_prepend (recent_merge_ids, (gpointer) id); - gtk_ui_manager_add_ui (toolbox_ui_manager, id, - "/ToolboxMenu/File/FileRecentEnd", + gtk_ui_manager_add_ui (ui_manager, id, + recent_path, gtk_action_get_name (GTK_ACTION (list->data)), gtk_action_get_name (GTK_ACTION (list->data)), GTK_UI_MANAGER_AUTO, @@ -746,19 +1065,25 @@ menus_clear_recent (void) { GSList *id; + GtkUIManager *ui_manager; + if (is_integrated_ui ()) + ui_manager = integrated_ui_manager; + else + ui_manager = toolbox_ui_manager; + g_return_if_fail (recent_merge_ids); id = recent_merge_ids; do { - gtk_ui_manager_remove_ui (toolbox_ui_manager, (guint) id->data); + gtk_ui_manager_remove_ui (ui_manager, (guint) id->data); } while (NULL != (id = id->next)); g_slist_free (recent_merge_ids); recent_merge_ids = NULL; - gtk_ui_manager_remove_action_group (toolbox_ui_manager, recent_actions); + gtk_ui_manager_remove_action_group (ui_manager, recent_actions); g_object_unref (G_OBJECT (recent_actions)); recent_actions = NULL; } Index: app/menus.h =================================================================== --- app/menus.h (revision 3682) +++ app/menus.h (working copy) @@ -69,6 +69,18 @@ typedef struct _UpdatableMenuItems UpdatableMenuItems; +void +integrated_ui_toolbar_set_zoom_text (GtkToolbar *toolbar, const gchar * text); + +void +integrated_ui_toolbar_grid_snap_synchronize_to_display (gpointer *ddisp); + +void +integrated_ui_toolbar_object_snap_synchronize_to_display (gpointer *ddisp); + +/* TODO: rename: menus_get_integrated_ui_menubar() */ +void menus_get_integrated_ui_menubar (GtkWidget **menubar, GtkWidget **toolbar, + GtkAccelGroup **accel); void menus_get_toolbox_menubar (GtkWidget **menubar, GtkAccelGroup **accel); GtkWidget * menus_get_display_popup (void); GtkAccelGroup * menus_get_display_accels (void); Index: data/integrated-ui.xml =================================================================== --- data/integrated-ui.xml (revision 0) +++ data/integrated-ui.xml (revision 0) @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: data/toolbar.xml =================================================================== --- data/toolbar.xml (revision 0) +++ data/toolbar.xml (revision 0) @@ -0,0 +1,6 @@ + + + + + +