[dia/dia-next: 33/59] Rebuild toolbox with grids & boxes instead of a giant wrapbox



commit 5892f596afdddd70ba50e42947a32848e4328659
Author: Zander Brown <zbrown gnome org>
Date:   Fri Dec 28 12:53:56 2018 +0000

    Rebuild toolbox with grids & boxes instead of a giant wrapbox

 app/dia-colour-area.c         |   6 +
 app/dia-colour-area.h         |   4 +
 app/dia-line-width-area.c     |   1 +
 app/gtkhwrapbox.c             | 640 ------------------------------
 app/gtkhwrapbox.h             |  70 ----
 app/gtkvwrapbox.c             | 643 ------------------------------
 app/gtkvwrapbox.h             |  70 ----
 app/gtkwrapbox.c              | 895 ------------------------------------------
 app/gtkwrapbox.h              | 136 -------
 app/interface.c               |   4 +-
 app/interface.h               |   2 -
 app/sheets.c                  |  16 +-
 app/sheets.h                  |   2 +-
 app/sheets_dialog_callbacks.c |  59 +--
 app/toolbox.c                 | 322 ++++++++-------
 app/toolbox.h                 |  17 +-
 16 files changed, 208 insertions(+), 2679 deletions(-)
---
diff --git a/app/dia-colour-area.c b/app/dia-colour-area.c
index 5848608c..ba5026ed 100644
--- a/app/dia-colour-area.c
+++ b/app/dia-colour-area.c
@@ -263,6 +263,12 @@ dia_colour_area_init (DiaColourArea *self)
   self->color_select_active = 0;
 
   gtk_widget_set_events (GTK_WIDGET (self), GDK_BUTTON_PRESS_MASK);
+
+  gtk_widget_set_tooltip_text (GTK_WIDGET (self), 
+      _("Foreground & background colors for new objects.  "
+        "The small black and white squares reset colors.  "
+        "The small arrows swap colors.  Double-click to "
+        "change colors."));
 }
 
 GtkWidget *
diff --git a/app/dia-colour-area.h b/app/dia-colour-area.h
index 1be51757..364dc9ab 100644
--- a/app/dia-colour-area.h
+++ b/app/dia-colour-area.h
@@ -20,6 +20,8 @@
 
 #include <gtk/gtk.h>
 
+G_BEGIN_DECLS
+
 #define DIA_TYPE_COLOUR_AREA (dia_colour_area_get_type ())
 G_DECLARE_FINAL_TYPE (DiaColourArea, dia_colour_area, DIA, COLOUR_AREA, GtkEventBox)
 
@@ -40,4 +42,6 @@ struct _DiaColourArea
 
 GtkWidget *dia_colour_area_new (int width, int height);
 
+G_END_DECLS
+
 #endif /* COLOUR_AREA_H */
diff --git a/app/dia-line-width-area.c b/app/dia-line-width-area.c
index 6b0ee5af..dec70690 100644
--- a/app/dia-line-width-area.c
+++ b/app/dia-line-width-area.c
@@ -243,6 +243,7 @@ dia_line_width_area_init (DiaLineWidthArea *self)
   self->active = linewidth_number_from_width (attributes_get_default_linewidth ());
 
   gtk_widget_set_events (GTK_WIDGET (self), GDK_BUTTON_PRESS_MASK);
+  gtk_widget_set_tooltip_text (GTK_WIDGET (self), _("Line widths.  Click on a line to set the default line 
width for new objects.  Double-click to set the line width more precisely."));
 }
 
 
diff --git a/app/interface.c b/app/interface.c
index 02af1ff2..14c5329d 100644
--- a/app/interface.c
+++ b/app/interface.c
@@ -866,7 +866,7 @@ create_integrated_ui (void)
   gtk_widget_show (notebook);
 
   /* Toolbox widget */
-  wrapbox = toolbox_create();
+  wrapbox = dia_toolbox_new();
   gtk_box_pack_start (GTK_BOX (hbox), wrapbox, FALSE, TRUE, 0);
 
   g_signal_connect (G_OBJECT (wrapbox), "drag_data_received",
@@ -944,7 +944,7 @@ create_toolbox ()
   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 1);
   gtk_container_add (GTK_CONTAINER (window), main_vbox);
 
-  wrapbox = toolbox_create();
+  wrapbox = dia_toolbox_new();
   gtk_box_pack_end (GTK_BOX (main_vbox), wrapbox, TRUE, TRUE, 0);
   g_signal_connect (G_OBJECT (wrapbox), "drag_data_received",
                    G_CALLBACK (dia_dnd_file_drag_data_received),
diff --git a/app/interface.h b/app/interface.h
index a3b9cf30..3b891870 100644
--- a/app/interface.h
+++ b/app/interface.h
@@ -55,8 +55,6 @@ extern GtkWidget *modify_tool_button;
 
 void view_zoom_set (float zoom_factor); /* zoom_factor is 10 * percentage */
 
-void fill_sheet_menu(void);
-
 void close_notebook_page_callback (GtkButton *button, gpointer user_data);
 
 void dia_dnd_file_drag_data_received (GtkWidget        *widget,
diff --git a/app/sheets.c b/app/sheets.c
index cf03121f..35671f82 100644
--- a/app/sheets.c
+++ b/app/sheets.c
@@ -39,7 +39,6 @@
 #include "sheets.h"
 #include "sheets_dialog.h"
 #include "intl.h"
-#include "gtkhwrapbox.h"
 #include "preferences.h"
 #include "toolbox.h" /* just for interface_current_sheet_name */
 #include "commands.h" /* sheets_dialog_show_callback */
@@ -82,7 +81,7 @@ sheets_append_sheet_object_mod(SheetObject *so, SheetMod *sm)
 /* Given a Sheet, create a SheetMod wrapper for a list of SheetObjectMod's */
 
 SheetMod *
-sheets_append_sheet_mods(Sheet *sheet)
+sheets_append_sheet_mods(DiaSheet *sheet)
 {
   SheetMod *sheet_mod;
   GSList *sheet_objects_list;
@@ -123,8 +122,9 @@ menu_item_compare_labels(gconstpointer a, gconstpointer b)
 }
 
 void
-sheets_optionmenu_create(GtkWidget *option_menu, GtkWidget *wrapbox,
-                         gchar *sheet_name)
+sheets_optionmenu_create (GtkWidget *option_menu,
+                          GtkWidget *wrapbox,
+                          gchar     *sheet_name)
 {
   GSList *sheets_list;
   GList *menu_item_list;
@@ -274,12 +274,10 @@ sheets_dialog_create(void)
   wrapbox = gtk_bin_get_child (GTK_BIN(sw));
   if (wrapbox)
     gtk_container_remove(GTK_CONTAINER(sw), wrapbox);
-  wrapbox = gtk_hwrap_box_new(FALSE);
+  wrapbox = gtk_grid_new ();
   g_object_ref(wrapbox);
   g_object_set_data(G_OBJECT(sheets_dialog), "wrapbox_right", wrapbox);
   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), wrapbox);
-  gtk_wrap_box_set_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_TOP);
-  gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_LEFT);
   gtk_widget_show(wrapbox);
   g_object_set_data(G_OBJECT(wrapbox), "is_left", FALSE);
   option_menu = lookup_widget(sheets_dialog, "optionmenu_right");
@@ -290,12 +288,10 @@ sheets_dialog_create(void)
   wrapbox = gtk_bin_get_child (GTK_BIN(sw));
   if (wrapbox)
     gtk_container_remove(GTK_CONTAINER(sw), wrapbox);
-  wrapbox = gtk_hwrap_box_new(FALSE);
+  wrapbox = gtk_grid_new ();
   g_object_ref(wrapbox);
   g_object_set_data(G_OBJECT(sheets_dialog), "wrapbox_left", wrapbox);
   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), wrapbox);
-  gtk_wrap_box_set_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_TOP);
-  gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_LEFT);
   gtk_widget_show(wrapbox);
   g_object_set_data(G_OBJECT(wrapbox), "is_left", (gpointer)TRUE);
   option_menu = lookup_widget(sheets_dialog, "optionmenu_left");
diff --git a/app/sheets.h b/app/sheets.h
index 14c8908c..d0fc3b5b 100644
--- a/app/sheets.h
+++ b/app/sheets.h
@@ -70,7 +70,7 @@ extern GtkWidget *sheets_dialog;
 extern GtkWidget *sheets_dialog_optionmenu_menu;
 
 SheetObjectMod *sheets_append_sheet_object_mod(SheetObject *so, SheetMod *sm);
-SheetMod *sheets_append_sheet_mods(Sheet *sheet);
+SheetMod *sheets_append_sheet_mods(DiaSheet *sheet);
 void sheets_optionmenu_create(GtkWidget *option_menu, GtkWidget *wrapbox,
                               gchar *sheet_name);
 void create_object_pixmap(SheetObject *so, GtkWidget *parent,
diff --git a/app/sheets_dialog_callbacks.c b/app/sheets_dialog_callbacks.c
index 9cde9384..d079fbb2 100644
--- a/app/sheets_dialog_callbacks.c
+++ b/app/sheets_dialog_callbacks.c
@@ -54,8 +54,6 @@
 #include <libxml/parser.h>
 #include <libxml/xmlmemory.h>
 
-#include "gtkwrapbox.h"
-
 #include "dia_dirs.h"
 #include "dia_xml_libxml.h"
 #include "plug-ins.h"
@@ -278,7 +276,7 @@ sheets_dialog_wrapbox_add_line_break(GtkWidget *wrapbox)
   gtk_container_add(GTK_CONTAINER(button), gtkpixmap);
   gtk_widget_show(gtkpixmap);
 
-  gtk_wrap_box_pack(GTK_WRAP_BOX(wrapbox), button, FALSE, TRUE, FALSE, TRUE);
+  /*gtk_wrap_box_pack(GTK_WRAP_BOX(wrapbox), button, FALSE, TRUE, FALSE, TRUE);*/
   gtk_widget_show(button);
 
   gtk_widget_set_tooltip_text(button, _("Line Break"));
@@ -346,7 +344,7 @@ on_sheets_dialog_optionmenu_activate   (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   GtkWidget *wrapbox;
-  Sheet *sheet;
+  DiaSheet *sheet;
   GtkWidget *optionmenu;
   GSList *object_mod_list;
   GtkWidget *hidden_button;
@@ -390,9 +388,6 @@ on_sheets_dialog_optionmenu_activate   (GtkMenuItem     *menuitem,
 
   radio_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(hidden_button));
 
-  gtk_wrap_box_set_aspect_ratio(GTK_WRAP_BOX(wrapbox), 4 * 1.0 / 9);
-                                                /* MCNFIXME: calculate this */
-
   g_object_set_data(G_OBJECT(wrapbox), "sheet_mod", user_data);
 
   for (object_mod_list = sheet->objects; object_mod_list;
@@ -410,8 +405,8 @@ on_sheets_dialog_optionmenu_activate   (GtkMenuItem     *menuitem,
 
     button = sheets_dialog_create_object_button(som, user_data, wrapbox);
    
-    gtk_wrap_box_pack_wrapped(GTK_WRAP_BOX(wrapbox), button,
-                     FALSE, TRUE, FALSE, TRUE, som->sheet_object.line_break);
+    /*gtk_wrap_box_pack_wrapped(GTK_WRAP_BOX(wrapbox), button,
+                     FALSE, TRUE, FALSE, TRUE, som->sheet_object.line_break);*/
 
     gtk_widget_show(button);
   }
@@ -450,17 +445,7 @@ SheetsDialogMoveDir;
 #define \
   SHEETS_DIALOG_MOVE_NONE   SHEETS_DIALOG_MOVE_UP
 
-static void
-_gtk_wrap_box_set_child_forced_break (GtkWrapBox* box, GtkWidget* child, 
-                                      gboolean wrapped)
-{
-  gboolean hexpand, hfill, vexpand, vfill, dummy;
 
-  gtk_wrap_box_query_child_packing (box, child, &hexpand, &hfill, 
-                                    &vexpand, &vfill, &dummy);
-  gtk_wrap_box_set_child_packing (box, child, hexpand, hfill, 
-                                  vexpand, vfill, wrapped);
-}
 static void
 sheets_dialog_normalize_line_breaks(GtkWidget *wrapbox, SheetsDialogMoveDir dir)
 {
@@ -491,8 +476,6 @@ sheets_dialog_normalize_line_breaks(GtkWidget *wrapbox, SheetsDialogMoveDir dir)
         }
 
         som->sheet_object.line_break = TRUE;
-        _gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(wrapbox),
-                                             GTK_WIDGET(iter_list->data), TRUE);
       }
       else
       {
@@ -504,8 +487,6 @@ sheets_dialog_normalize_line_breaks(GtkWidget *wrapbox, SheetsDialogMoveDir dir)
         }
 
         som->sheet_object.line_break = FALSE;
-        _gtk_wrap_box_set_child_forced_break(GTK_WRAP_BOX(wrapbox),
-                                            GTK_WIDGET(iter_list->data), FALSE);
       }
       is_line_break = FALSE;
     }
@@ -585,8 +566,6 @@ sheets_dialog_move_up_or_down(SheetsDialogMoveDir dir)
   active_button = g_object_get_data(G_OBJECT(wrapbox), "active_button");
 
   button_pos = g_list_index(button_list, active_button);
-  gtk_wrap_box_reorder_child(GTK_WRAP_BOX(wrapbox),
-                             GTK_WIDGET(active_button), button_pos + dir);
   g_list_free(button_list);
 
   sheets_dialog_normalize_line_breaks(wrapbox, dir);
@@ -751,7 +730,7 @@ on_sheets_new_dialog_button_ok_clicked (GtkButton       *button,
     SheetObjectMod *som;
     SheetMod *sm;
     SheetObject *sheet_obj;
-    Sheet *sheet;
+    DiaSheet *sheet;
     GtkWidget *optionmenu;
 
   case SHEETS_NEW_DIALOG_TYPE_SVG_SHAPE:
@@ -840,8 +819,8 @@ on_sheets_new_dialog_button_ok_clicked (GtkButton       *button,
       sm->mod = SHEETMOD_MOD_CHANGED;
 
     active_button = sheets_dialog_create_object_button(som, sm, wrapbox);
-    gtk_wrap_box_pack(GTK_WRAP_BOX(wrapbox), active_button,
-                      FALSE, TRUE, FALSE, TRUE);
+    /*gtk_wrap_box_pack(GTK_WRAP_BOX(wrapbox), active_button,
+                      FALSE, TRUE, FALSE, TRUE);*/
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(active_button), TRUE);
     gtk_widget_show(active_button);
 
@@ -856,8 +835,8 @@ on_sheets_new_dialog_button_ok_clicked (GtkButton       *button,
     pos = g_list_index(button_list, active_button);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_list_last(button_list)
                                                                  ->data), TRUE);
-    gtk_wrap_box_reorder_child(GTK_WRAP_BOX(wrapbox),
-                               g_list_last(button_list)->data, pos + 1);
+    /*gtk_wrap_box_reorder_child(GTK_WRAP_BOX(wrapbox),
+                               g_list_last(button_list)->data, pos + 1);*/
     
     sheets_dialog_normalize_line_breaks(wrapbox, SHEETS_DIALOG_MOVE_NONE);
 
@@ -1453,8 +1432,8 @@ sheets_dialog_copy_object(GtkWidget *active_button, GtkWidget *target_wrapbox)
     sm->mod = SHEETMOD_MOD_CHANGED;
 
   button = sheets_dialog_create_object_button(som_new, sm, target_wrapbox);
-  gtk_wrap_box_pack(GTK_WRAP_BOX(target_wrapbox), button,
-                    FALSE, TRUE, FALSE, TRUE);
+  /*gtk_wrap_box_pack(GTK_WRAP_BOX(target_wrapbox), button,
+                    FALSE, TRUE, FALSE, TRUE);*/
   gtk_widget_show(button);
 
   sheets_dialog_apply_revert_set_sensitive(TRUE);
@@ -1594,7 +1573,7 @@ copy_file(gchar *src, gchar *dst)
 
 /* write a sheet to ~/.dia/sheets */
 static gboolean
-write_user_sheet(Sheet *sheet)
+write_user_sheet(DiaSheet *sheet)
 {
   FILE *file;
   xmlDocPtr doc;
@@ -1784,7 +1763,7 @@ touch_file(gchar *filename)
 static gint
 sheets_find_sheet(gconstpointer a, gconstpointer b)
 {
-  if (!strcmp(((Sheet *)a)->name, ((Sheet *)b)->name))
+  if (!strcmp(((DiaSheet *)a)->name, ((DiaSheet *)b)->name))
     return 0;
   else
     return 1;
@@ -1810,7 +1789,7 @@ on_sheets_dialog_button_apply_clicked  (GtkButton       *button,
     {
       GSList *sheet_object_mods_list;
       GSList *list;
-      Sheet *new_sheet = NULL;
+      DiaSheet *new_sheet = NULL;
 
     case SHEETMOD_MOD_NEW:
       write_user_sheet(&sm->sheet);
@@ -1836,8 +1815,8 @@ on_sheets_dialog_button_apply_clicked  (GtkButton       *button,
         sheet_append_sheet_obj(new_sheet, new_object);
       }
 
-      dia_sort_sheets();      
-      fill_sheet_menu();
+      dia_sort_sheets();
+      /* TODO: Get ref to toolbox/avoid explicit call dia_toolbox_update_sheets (); */
       break;
 
     case SHEETMOD_MOD_CHANGED:
@@ -1849,7 +1828,7 @@ on_sheets_dialog_button_apply_clicked  (GtkButton       *button,
       sheets_list = g_slist_find_custom(sheets_list, &sm->sheet,
                                         sheets_find_sheet);
       g_assert(sheets_list);
-      ((Sheet *)(sheets_list->data))->objects = NULL;
+      ((DiaSheet *)(sheets_list->data))->objects = NULL;
 
       for (list = sheet_object_mods_list; list; list = g_slist_next(list))
       {
@@ -1864,7 +1843,7 @@ on_sheets_dialog_button_apply_clicked  (GtkButton       *button,
        *new_object = som->sheet_object;
         sheet_append_sheet_obj(sheets_list->data, new_object);
       }
-      fill_sheet_menu();
+      /* TODO: Get ref to toolbox/avoid explicit call dia_toolbox_update_sheets (); */
       break;
 
     case SHEETMOD_MOD_DELETED:
@@ -1881,7 +1860,7 @@ on_sheets_dialog_button_apply_clicked  (GtkButton       *button,
        g_warning ("No sheets left?");
 
       dia_sort_sheets();
-      fill_sheet_menu();
+      /* TODO: Get ref to toolbox/avoid explicit call dia_toolbox_update_sheets (); */
       break;
 
     case SHEETMOD_MOD_NONE:
diff --git a/app/toolbox.c b/app/toolbox.c
index 52d297bc..2657aa09 100644
--- a/app/toolbox.c
+++ b/app/toolbox.c
@@ -19,8 +19,6 @@
 #include <config.h>
 
 #include <gtk/gtk.h>
-#include "gtkwrapbox.h"
-#include "gtkhwrapbox.h"
 
 #include "diaarrowchooser.h"
 #include "diadynamicmenu.h"
@@ -43,6 +41,8 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include "dia-app-icons.h"
 
+G_DEFINE_TYPE (DiaToolbox, dia_toolbox, GTK_TYPE_BOX)
+
 /* HB: file dnd stuff lent by The Gimp, not fully understood but working ...
  */
 enum
@@ -175,12 +175,12 @@ const int num_tools = NUM_TOOLS;
 
 static GtkWidget *tool_widgets[NUM_TOOLS];
 
-static Sheet *
+static DiaSheet *
 get_sheet_by_name(const gchar *name)
 {
   GSList *tmp;
   for (tmp = get_sheets_list(); tmp != NULL; tmp = tmp->next) {
-    Sheet *sheet = tmp->data;
+    DiaSheet *sheet = tmp->data;
     /* There is something fishy with comparing both forms: the english and the localized one.
      * But we should be on the safe side here, especially when bug #328570 gets tackled.
      */
@@ -242,8 +242,9 @@ tool_setup_drag_source(GtkWidget *button, ToolButtonData *tooldata,
 }
 
 static void
-fill_sheet_wbox(Sheet *sheet)
+fill_sheet_wbox (DiaToolbox *self, DiaSheet *sheet)
 {
+  int i = 0;
   int rows;
   GSList *tmp;
   GtkWidget *first_button = NULL;
@@ -258,8 +259,6 @@ fill_sheet_wbox(Sheet *sheet)
   /* set the aspect ratio on the wbox */
   rows = ceil(g_slist_length(sheet->objects) / (double)COLUMNS);
   if (rows<1) rows = 1;
-  gtk_wrap_box_set_aspect_ratio(GTK_WRAP_BOX(sheet_wbox),
-                               COLUMNS * 1.0 / rows);
   for (tmp = sheet->objects; tmp != NULL; tmp = tmp->next) {
     SheetObject *sheet_obj = tmp->data;
     GdkPixbuf *pixbuf = NULL;
@@ -310,10 +309,14 @@ fill_sheet_wbox(Sheet *sheet)
     gtk_container_add (GTK_CONTAINER (button), image);
     gtk_widget_show(image);
 
-    gtk_wrap_box_pack_wrapped(GTK_WRAP_BOX(sheet_wbox), button,
-                     FALSE, TRUE, FALSE, TRUE, sheet_obj->line_break);
+    gtk_grid_attach (GTK_GRID (self->items), button, i % COLUMNS, i / COLUMNS, 1, 1);
     gtk_widget_show(button);
 
+    if (sheet_obj->line_break) {
+      g_message ("Got a line break!");
+      i += i % COLUMNS;
+    }
+
     data = g_new(ToolButtonData, 1);
     data->type = CREATE_OBJECT_TOOL;
     data->extra_data = sheet_obj->object_type;
@@ -331,6 +334,8 @@ fill_sheet_wbox(Sheet *sheet)
     g_object_unref(pixbuf);
 
     gtk_widget_set_tooltip_text (button, gettext(sheet_obj->description));
+
+    i++;
   }
   /* If the selection is in the old sheet, steal it */
   if (active_tool != NULL &&
@@ -343,23 +348,23 @@ fill_sheet_wbox(Sheet *sheet)
 static void
 sheet_option_menu_changed (GtkListBox    *box,
                            GtkListBoxRow *row,
-                           gpointer       user_data)
+                           DiaToolbox    *self)
 {
   char *string;
-  Sheet *sheet;
+  DiaSheet *sheet;
 
   g_return_if_fail (DIA_IS_LIST_ITEM (row));
 
   string = dia_list_item_get_value (DIA_LIST_ITEM (row));
-  sheet = get_sheet_by_name(string);
+  sheet = get_sheet_by_name (string);
 
   if (sheet == NULL) {
-    message_warning(_("No sheet named %s"), string);
+    message_warning (_("No sheet named %s"), string);
   } else {
-    persistence_set_string("last-sheet-selected", string);
-    fill_sheet_wbox(sheet);
+    persistence_set_string ("last-sheet-selected", string);
+    fill_sheet_wbox (self, sheet);
   }
-  g_free(string);
+  g_free (string);
 }
 
 static int
@@ -374,7 +379,7 @@ get_sheet_names()
   GSList *tmp;
   GList *names = NULL;
   for (tmp = get_sheets_list(); tmp != NULL; tmp = tmp->next) {
-    Sheet *sheet = tmp->data;
+    DiaSheet *sheet = tmp->data;
     names = g_list_append(names, sheet->name);
   }
   /* Already sorted in lib/ but here we sort by the localized (display-)name */
@@ -412,7 +417,7 @@ render_row (gpointer item, gpointer user_data)
 }
 
 static void
-create_sheet_dropdown_menu(GtkWidget *parent)
+create_sheet_dropdown_menu (DiaToolbox *self)
 {
   GListStore *sheets = g_list_store_new (DIA_TYPE_SHEET_META);
   GList *sheet_names = get_sheet_names();
@@ -424,7 +429,7 @@ create_sheet_dropdown_menu(GtkWidget *parent)
   GtkWidget *list;
 
   if (sheet_option_menu != NULL) {
-    gtk_container_remove(GTK_CONTAINER(parent), sheet_option_menu);
+    gtk_container_remove (GTK_CONTAINER (self), sheet_option_menu);
     sheet_option_menu = NULL;
   }
 
@@ -466,118 +471,78 @@ create_sheet_dropdown_menu(GtkWidget *parent)
   gtk_menu_button_set_popover (GTK_MENU_BUTTON (sheet_option_menu), popover);
 
   g_signal_connect (G_OBJECT (list), "row-selected",
-                  G_CALLBACK(sheet_option_menu_changed), sheet_option_menu);
-  /*    gtk_widget_set_size_request(sheet_option_menu, 20, -1);*/
-  gtk_wrap_box_pack_wrapped(GTK_WRAP_BOX(parent), sheet_option_menu,
-                           TRUE, TRUE, FALSE, FALSE, TRUE);    
-  /* 15 was a magic number that goes beyond the standard objects and the divider. */
-  gtk_wrap_box_reorder_child(GTK_WRAP_BOX(parent),
-                            sheet_option_menu, NUM_TOOLS+1);
+                    G_CALLBACK(sheet_option_menu_changed), self);
+  gtk_box_pack_start (GTK_BOX (self), sheet_option_menu, FALSE, FALSE, 0);
   gtk_widget_show(sheet_option_menu);
 }
 
-void
-fill_sheet_menu(void)
-{
-  /* TODO: gchar *selection = dia_dynamic_menu_get_entry(DIA_DYNAMIC_MENU(sheet_option_menu)); */
-  create_sheet_dropdown_menu(gtk_widget_get_parent(sheet_option_menu));
-  /* TODO: dia_dynamic_menu_select_entry(DIA_DYNAMIC_MENU(sheet_option_menu), selection);
-  g_free(selection); */
-}
-
 static void
-create_sheets(GtkWidget *parent)
+create_sheets (DiaToolbox *self)
 {
   GtkWidget *separator;
-  GtkWidget *label;
   GtkWidget *swin;
   gchar *sheetname;
-  Sheet *sheet;
+  DiaSheet *sheet;
   
-  separator = gtk_hseparator_new ();
-  /* add a bit of padding around the separator */
-  label = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
-  gtk_box_pack_start(GTK_BOX(label), separator, TRUE, TRUE, 3);
-  gtk_widget_show(label);
-
-  gtk_wrap_box_pack_wrapped (GTK_WRAP_BOX(parent), label, TRUE,TRUE, FALSE,FALSE, TRUE);
-  gtk_widget_show(separator);
-
-  create_sheet_dropdown_menu(parent);
-
-  swin = gtk_scrolled_window_new(NULL, NULL);
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
-                                GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-  gtk_wrap_box_pack_wrapped(GTK_WRAP_BOX(parent), swin, TRUE, TRUE, TRUE, TRUE, TRUE);
-  gtk_widget_show(swin);
-
-  sheet_wbox = gtk_hwrap_box_new(FALSE);
-  gtk_wrap_box_set_justify(GTK_WRAP_BOX(sheet_wbox), GTK_JUSTIFY_TOP);
-  gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(sheet_wbox), GTK_JUSTIFY_LEFT);
-  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), sheet_wbox);
-  gtk_widget_show(sheet_wbox);
-
-  sheetname = persistence_register_string("last-sheet-selected", _("Flowchart"));
-  sheet = get_sheet_by_name(sheetname);
+  separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+  gtk_box_pack_start (GTK_BOX (self), separator, FALSE, FALSE, 0);
+  gtk_widget_show (separator);
+
+  create_sheet_dropdown_menu (self);
+
+  swin = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
+                                  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+  gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (swin),
+                                                    TRUE);
+  gtk_box_pack_start (GTK_BOX (self), swin, FALSE, FALSE, 0);
+  gtk_widget_show (swin);
+
+  self->items = gtk_grid_new ();
+  gtk_container_add (GTK_CONTAINER (swin), self->items);
+  gtk_widget_show (self->items);
+
+  sheetname = persistence_register_string ("last-sheet-selected", _("Flowchart"));
+  sheet = get_sheet_by_name (sheetname);
   if (sheet == NULL) {
     /* Couldn't find it */
   } else {
-    fill_sheet_wbox(sheet);
+    fill_sheet_wbox (self, sheet);
     /* TODO: dia_dynamic_menu_select_entry(DIA_DYNAMIC_MENU(sheet_option_menu),
                                  sheetname); */
   }
-  g_free(sheetname);
+  g_free (sheetname);
+
+  separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+  gtk_box_pack_end (GTK_BOX (self), separator, FALSE, FALSE, 0);
+  gtk_widget_show (separator);
 }
 
 static void
-create_color_area (GtkWidget *parent)
+create_color_area (DiaToolbox *self)
 {
-  GtkWidget *frame;
-  GtkWidget *alignment;
   GtkWidget *col_area;
   GtkWidget *line_area;
   GtkWidget *hbox;
 
-  frame = gtk_frame_new (NULL);
-  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
-  gtk_wrap_box_pack_wrapped(GTK_WRAP_BOX(parent), frame, TRUE, TRUE, FALSE, FALSE, TRUE);
-
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 1);
-  gtk_container_set_border_width (GTK_CONTAINER (hbox), 0);
-  gtk_container_add (GTK_CONTAINER (frame), hbox);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
+  gtk_box_pack_end (GTK_BOX (self), hbox, FALSE, FALSE, 0);
   
   /* Color area: */
-  alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
-  gtk_container_set_border_width (GTK_CONTAINER (alignment), 3);
-  
   col_area = dia_colour_area_new (54, 42);
-  gtk_container_add (GTK_CONTAINER (alignment), col_area);
-
-
-  gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
-
-  gtk_widget_set_tooltip_text (col_area, 
-                       _("Foreground & background colors for new objects.  "
-                         "The small black and white squares reset colors.  "
-                         "The small arrows swap colors.  Double-click to "
-                         "change colors."));
-
-  gtk_widget_show (alignment);
+  gtk_widget_set_halign (col_area, GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (col_area, GTK_ALIGN_CENTER);
+  gtk_box_pack_start (GTK_BOX (hbox), col_area, TRUE, TRUE, 0);
   
   /* Linewidth area: */
-  alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
-  gtk_container_set_border_width (GTK_CONTAINER (alignment), 3);
-  
   line_area = dia_line_width_area_new ();
-  gtk_container_add (GTK_CONTAINER (alignment), line_area);
-  gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
-  gtk_widget_set_tooltip_text(line_area, _("Line widths.  Click on a line to set the default line width for 
new objects.  Double-click to set the line width more precisely."));
-  gtk_widget_show (alignment);
+  gtk_widget_set_halign (col_area, GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (col_area, GTK_ALIGN_CENTER);
+  gtk_box_pack_start (GTK_BOX (hbox), line_area, TRUE, TRUE, 0);
 
   gtk_widget_show (col_area);
   gtk_widget_show (line_area);
   gtk_widget_show (hbox);
-  gtk_widget_show (frame);
 }
 
 static void
@@ -600,48 +565,55 @@ change_line_style(DiaLineStyleSelector *selector, gpointer user_data)
 }
 
 static void
-create_lineprops_area(GtkWidget *parent)
+create_lineprops_area (DiaToolbox *self)
 {
+  GtkWidget *box;
   GtkWidget *chooser;
   Arrow arrow;
   real dash_length;
   LineStyle style;
   gchar *arrow_name;
 
-  chooser = dia_arrow_chooser_new(TRUE, change_start_arrow_style, NULL);
-  gtk_wrap_box_pack_wrapped(GTK_WRAP_BOX(parent), chooser, FALSE, TRUE, FALSE, TRUE, TRUE);
-  arrow.width = persistence_register_real("start-arrow-width", DEFAULT_ARROW_WIDTH);
-  arrow.length = persistence_register_real("start-arrow-length", DEFAULT_ARROW_LENGTH);
-  arrow_name = persistence_register_string("start-arrow-type", "None");
-  arrow.type = arrow_type_from_name(arrow_name);
-  g_free(arrow_name);
-  dia_arrow_chooser_set_arrow(DIA_ARROW_CHOOSER(chooser), &arrow);
-  attributes_set_default_start_arrow(arrow);
-  gtk_widget_set_tooltip_text(chooser, _("Arrow style at the beginning of new lines.  Click to pick an 
arrow, or set arrow parameters with Details\342\200\246"));
-  gtk_widget_show(chooser);
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
+  gtk_style_context_add_class (gtk_widget_get_style_context (box),
+                               GTK_STYLE_CLASS_LINKED);
+  gtk_box_pack_end (GTK_BOX (self), box, FALSE, FALSE, 0);
+  gtk_widget_show (box);
+
+  chooser = dia_arrow_chooser_new (TRUE, change_start_arrow_style, NULL);
+  gtk_container_add (GTK_CONTAINER (box), chooser);
+  arrow.width = persistence_register_real ("start-arrow-width", DEFAULT_ARROW_WIDTH);
+  arrow.length = persistence_register_real ("start-arrow-length", DEFAULT_ARROW_LENGTH);
+  arrow_name = persistence_register_string ("start-arrow-type", "None");
+  arrow.type = arrow_type_from_name (arrow_name);
+  g_free (arrow_name);
+  dia_arrow_chooser_set_arrow (DIA_ARROW_CHOOSER (chooser), &arrow);
+  attributes_set_default_start_arrow (arrow);
+  gtk_widget_set_tooltip_text (chooser, _("Arrow style at the beginning of new lines.  Click to pick an 
arrow, or set arrow parameters with Details\342\200\246"));
+  gtk_widget_show (chooser);
 
   chooser = dia_line_style_selector_new ();
   g_signal_connect (G_OBJECT (chooser), "value-changed",
                     G_CALLBACK (change_line_style), NULL);
-  gtk_wrap_box_pack(GTK_WRAP_BOX(parent), chooser, TRUE, TRUE, FALSE, TRUE);
+  gtk_container_add (GTK_CONTAINER (box), chooser);
   gtk_widget_set_tooltip_text (chooser, _("Line style for new lines.  Click to pick a line style, or set 
line style parameters with Details\342\200\246"));
-  style = persistence_register_integer("line-style", LINESTYLE_SOLID);
-  dash_length = persistence_register_real("dash-length", DEFAULT_LINESTYLE_DASHLEN);
+  style = persistence_register_integer ("line-style", LINESTYLE_SOLID);
+  dash_length = persistence_register_real ("dash-length", DEFAULT_LINESTYLE_DASHLEN);
   dia_line_style_selector_set_line_style (DIA_LINE_STYLE_SELECTOR (chooser), style, dash_length);
-  gtk_widget_show(chooser);
-
-  chooser = dia_arrow_chooser_new(FALSE, change_end_arrow_style, NULL);
-  arrow.width = persistence_register_real("end-arrow-width", DEFAULT_ARROW_WIDTH);
-  arrow.length = persistence_register_real("end-arrow-length", DEFAULT_ARROW_LENGTH);
-  arrow_name = persistence_register_string("end-arrow-type", "Filled Concave");
-  arrow.type = arrow_type_from_name(arrow_name);
-  g_free(arrow_name);
-  dia_arrow_chooser_set_arrow(DIA_ARROW_CHOOSER(chooser), &arrow);
-  attributes_set_default_end_arrow(arrow);
-
-  gtk_wrap_box_pack(GTK_WRAP_BOX(parent), chooser, FALSE, TRUE, FALSE, TRUE);
-  gtk_widget_set_tooltip_text(chooser, _("Arrow style at the end of new lines.  Click to pick an arrow, or 
set arrow parameters with Details\342\200\246"));
-  gtk_widget_show(chooser);
+  gtk_widget_show (chooser);
+
+  chooser = dia_arrow_chooser_new (FALSE, change_end_arrow_style, NULL);
+  gtk_container_add (GTK_CONTAINER (box), chooser);
+  arrow.width = persistence_register_real ("end-arrow-width", DEFAULT_ARROW_WIDTH);
+  arrow.length = persistence_register_real ("end-arrow-length", DEFAULT_ARROW_LENGTH);
+  arrow_name = persistence_register_string ("end-arrow-type", "Filled Concave");
+  arrow.type = arrow_type_from_name (arrow_name);
+  g_free (arrow_name);
+  dia_arrow_chooser_set_arrow (DIA_ARROW_CHOOSER (chooser), &arrow);
+  attributes_set_default_end_arrow (arrow);
+  gtk_widget_set_tooltip_text (chooser, _("Arrow style at the end of new lines.  Click to pick an arrow, or 
set arrow parameters with Details\342\200\246"));
+  gtk_widget_show (chooser);
 }
 
 void
@@ -715,7 +687,7 @@ create_widget_from_xpm_or_gdkp(const char **icon_data, GtkWidget *button, GdkPix
 }
 
 static void
-create_tools(GtkWidget *parent)
+create_tools (DiaToolbox *self)
 {
   GtkWidget *button;
   GdkPixbuf *pixbuf = NULL;
@@ -724,15 +696,28 @@ create_tools(GtkWidget *parent)
   const char **pixmap_data;
   int i;
 
+  self->tools = gtk_grid_new ();
+  gtk_widget_show (self->tools);
+  gtk_box_pack_start (GTK_BOX (self), self->tools, FALSE, FALSE, 0);
+
   for (i = 0; i < NUM_TOOLS; i++) {
     tool_widgets[i] = button = gtk_radio_button_new (tool_group);
-    gtk_container_set_border_width (GTK_CONTAINER (button), 0);
-    gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_HALF);
+    gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
     tool_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
     gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
 
-    gtk_wrap_box_pack(GTK_WRAP_BOX(parent), button,
-                     TRUE, TRUE, FALSE, TRUE);
+/*
+
+  0     1     2     3 
+  0, 0  0, 1  0, 2  0, 3
+  4     5     6     7 
+  1, 0  1, 1  1, 2  1, 3
+  8     9     10    11
+  2, 0  2, 1  2, 2  2, 3
+
+*/
+
+    gtk_grid_attach (GTK_GRID (self->tools), button, i % COLUMNS, i / COLUMNS, 1, 1);
 
     if (tool_data[i].callback_data.type == MODIFY_TOOL) {
       modify_tool_button = GTK_WIDGET(button);
@@ -740,12 +725,11 @@ create_tools(GtkWidget *parent)
     
     if (tool_data[i].icon_data==NULL) {
       DiaObjectType *type;
-      type =
-       object_get_type((char *)tool_data[i].callback_data.extra_data);
+      type = object_get_type((char *)tool_data[i].callback_data.extra_data);
       if (type == NULL)
-       pixmap_data = tool_data[0].icon_data;
+        pixmap_data = tool_data[0].icon_data;
       else
-       pixmap_data = type->pixmap;
+        pixmap_data = type->pixmap;
       image = create_widget_from_xpm_or_gdkp(pixmap_data, button, &pixbuf);
     } else {
       image = create_widget_from_xpm_or_gdkp(tool_data[i].icon_data, button, &pixbuf);
@@ -774,21 +758,19 @@ create_tools(GtkWidget *parent)
     tool_data[i].callback_data.widget = button;
 
     if (tool_data[i].tool_accelerator) {
-       guint key;
-       GdkModifierType mods;
-       gchar *alabel, *atip;
-
-       gtk_accelerator_parse (tool_data[i].tool_accelerator, &key, &mods);
+      guint key;
+      GdkModifierType mods;
+      gchar *alabel, *atip;
 
-       alabel = gtk_accelerator_get_label(key, mods);
-       atip = g_strconcat(gettext(tool_data[i].tool_desc), " (", alabel, ")", NULL);
-       gtk_widget_set_tooltip_text (button, atip);
-       g_free (atip);
-       g_free (alabel);
+      gtk_accelerator_parse (tool_data[i].tool_accelerator, &key, &mods);
 
+      alabel = gtk_accelerator_get_label(key, mods);
+      atip = g_strconcat(gettext(tool_data[i].tool_desc), " (", alabel, ")", NULL);
+      gtk_widget_set_tooltip_text (button, atip);
+      g_free (atip);
+      g_free (alabel);
     } else {
-       gtk_widget_set_tooltip_text (button,
-                               gettext(tool_data[i].tool_desc));
+      gtk_widget_set_tooltip_text (button, gettext(tool_data[i].tool_desc));
     }
     
     gtk_widget_show (image);
@@ -796,33 +778,37 @@ create_tools(GtkWidget *parent)
   }
 }
 
-GtkWidget *
-toolbox_create(void)
+static void
+dia_toolbox_class_init (DiaToolboxClass *class)
 {
-  GtkWidget *wrapbox;
-
-  wrapbox = gtk_hwrap_box_new(FALSE);
-  gtk_wrap_box_set_aspect_ratio(GTK_WRAP_BOX(wrapbox), 144.0 / 318.0);
-  gtk_wrap_box_set_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_TOP);
-  gtk_wrap_box_set_line_justify(GTK_WRAP_BOX(wrapbox), GTK_JUSTIFY_LEFT);
+  GtkWidgetClass *widget_class;
 
+  widget_class = GTK_WIDGET_CLASS (class);
+}
 
-  /* pack the rest of the stuff */
-  gtk_container_set_border_width (GTK_CONTAINER (wrapbox), 0);
-  gtk_widget_show (wrapbox);
+static void
+dia_toolbox_init (DiaToolbox *self)
+{
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
+  gtk_box_set_spacing (GTK_BOX (self), 9);
+  gtk_widget_show (GTK_WIDGET (self));
 
-  create_tools (wrapbox);
-  create_sheets (wrapbox);
-  create_color_area (wrapbox);
-  create_lineprops_area (wrapbox);
+  create_tools (self);
+  create_sheets (self);
+  create_lineprops_area (self);
+  create_color_area (self);
 
   /* Setup toolbox area as file drop destination */
-  gtk_drag_dest_set (wrapbox,
-                    GTK_DEST_DEFAULT_ALL,
-                    toolbox_target_table, toolbox_n_targets,
-                    GDK_ACTION_COPY);
+  gtk_drag_dest_set (GTK_WIDGET (self),
+                     GTK_DEST_DEFAULT_ALL,
+                     toolbox_target_table, toolbox_n_targets,
+                     GDK_ACTION_COPY);
+}
 
-  return wrapbox;
+GtkWidget *
+dia_toolbox_new ()
+{
+  return g_object_new (DIA_TYPE_TOOLBOX, NULL);
 }
 
 void
diff --git a/app/toolbox.h b/app/toolbox.h
index 089766b4..1b6bf966 100644
--- a/app/toolbox.h
+++ b/app/toolbox.h
@@ -1,5 +1,17 @@
 #include "tool.h"
 
+G_BEGIN_DECLS
+
+#define DIA_TYPE_TOOLBOX (dia_toolbox_get_type ())
+G_DECLARE_FINAL_TYPE (DiaToolbox, dia_toolbox, DIA, TOOLBOX, GtkBox)
+
+struct _DiaToolbox {
+  GtkBox parent;
+
+  GtkWidget *tools;
+  GtkWidget *items;
+};
+
 typedef struct _ToolButton ToolButton;
 
 typedef struct _ToolButtonData ToolButtonData;
@@ -30,7 +42,8 @@ GdkPixbuf *tool_get_pixbuf (ToolButton *tb);
 
 void toolbox_setup_drag_dest (GtkWidget *canvas);
 void canvas_setup_drag_dest (GtkWidget *canvas);
-GtkWidget *toolbox_create(void);
 
-void fill_sheet_menu(void);
+GtkWidget *dia_toolbox_new           ();
+void       dia_toolbox_update_sheets (DiaToolbox *self);
 
+G_END_DECLS
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]