[dia/dia-next: 30/59] Merge DiaListStyleSelector & DiaLineChooser to a single GtkMenuButton/GtkPopover based widget



commit d4c0d250af638419aa1ec1b756725167ad834940
Author: Zander Brown <zbrown gnome org>
Date:   Thu Dec 27 14:45:11 2018 +0000

    Merge DiaListStyleSelector & DiaLineChooser to a single GtkMenuButton/GtkPopover based widget

 .editorconfig                           |   3 +
 app/dia-canvas.c                        |   3 -
 app/toolbox.c                           |  14 +-
 data/dia-line-style-selector-popover.ui |  98 ++++++++++
 lib/Makefile.am                         |   5 +-
 lib/dia-line-style-selector-popover.c   | 164 ++++++++++++++++
 lib/dia-line-style-selector-popover.h   |  28 +++
 lib/dia-line-style-selector.c           | 241 +++++++++++++++++++++++
 lib/dia-line-style-selector.h           |  48 +++++
 lib/dialinechooser.c                    | 333 --------------------------------
 lib/dialinechooser.h                    |  98 ----------
 lib/dialinestyleselector.c              | 220 ---------------------
 lib/prop_attr.c                         |   8 +-
 lib/widgets.h                           |  15 +-
 14 files changed, 598 insertions(+), 680 deletions(-)
---
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..8c55b1a4
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,3 @@
+[*.{c, h}]
+indent_style = space
+indent_size = 2
\ No newline at end of file
diff --git a/app/dia-canvas.c b/app/dia-canvas.c
index 0b1975be..d81ba334 100644
--- a/app/dia-canvas.c
+++ b/app/dia-canvas.c
@@ -1,6 +1,3 @@
-/* Minimal reimplementation of GtkList, prototyped in Vala */
-
-
 #include <glib.h>
 #include <gtk/gtk.h>
 
diff --git a/app/toolbox.c b/app/toolbox.c
index 61a86941..ec1bc29f 100644
--- a/app/toolbox.c
+++ b/app/toolbox.c
@@ -23,7 +23,6 @@
 #include "gtkhwrapbox.h"
 
 #include "diaarrowchooser.h"
-#include "dialinechooser.h"
 #include "diadynamicmenu.h"
 #include "attributes.h"
 #include "sheet.h"
@@ -592,9 +591,12 @@ change_end_arrow_style(Arrow arrow, gpointer user_data)
   attributes_set_default_end_arrow(arrow);
 }
 static void
-change_line_style(LineStyle lstyle, real dash_length, gpointer user_data)
+change_line_style(DiaLineStyleSelector *selector, gpointer user_data)
 {
-  attributes_set_default_line_style(lstyle, dash_length);
+  LineStyle lstyle;
+  real dash_length;
+  dia_line_style_selector_get_line_style (selector, &lstyle, &dash_length);
+  attributes_set_default_line_style (lstyle, dash_length);
 }
 
 static void
@@ -618,12 +620,14 @@ create_lineprops_area(GtkWidget *parent)
   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_chooser_new(change_line_style, NULL);
+  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_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);
-  dia_line_chooser_set_line_style(DIA_LINE_CHOOSER(chooser), style, dash_length);
+  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);
diff --git a/data/dia-line-style-selector-popover.ui b/data/dia-line-style-selector-popover.ui
new file mode 100644
index 00000000..4e2e0780
--- /dev/null
+++ b/data/dia-line-style-selector-popover.ui
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="upper">10</property>
+    <property name="value">0.10000000000000001</property>
+    <property name="step_increment">0.10000000000000001</property>
+    <property name="page_increment">1</property>
+  </object>
+  <template class="DiaLineStyleSelectorPopover" parent="GtkPopover">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin_left">8</property>
+        <property name="margin_right">8</property>
+        <property name="margin_top">8</property>
+        <property name="margin_bottom">8</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">16</property>
+        <child>
+          <object class="GtkScrolledWindow">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">etched-in</property>
+            <property name="min_content_width">150</property>
+            <property name="max_content_width">150</property>
+            <property name="max_content_height">300</property>
+            <property name="propagate_natural_width">True</property>
+            <property name="propagate_natural_height">True</property>
+            <child>
+              <object class="GtkViewport">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkListBox" id="list">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="length_box">
+            <property name="visible">True</property>
+            <property name="sensitive">False</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">16</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Dash length</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSpinButton" id="length">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="adjustment">adjustment1</property>
+                <property name="climb_rate">1</property>
+                <property name="digits">2</property>
+                <property name="numeric">True</property>
+                <property name="wrap">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="pack_type">end</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 646c2ced..bd9692bb 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -193,9 +193,8 @@ libdia_la_SOURCES =  \
                diaarrowchooser.c \
                diaarrowselector.c \
                diacolorselector.c \
-               dialinestyleselector.c \
-               dialinechooser.h \
-               dialinechooser.c \
+               dia-line-style-selector-popover.c \
+               dia-line-style-selector.c \
                diadynamicmenu.h \
                diadynamicmenu.c \
                diafontselector.h \
diff --git a/lib/dia-line-style-selector-popover.c b/lib/dia-line-style-selector-popover.c
new file mode 100644
index 00000000..a04cb049
--- /dev/null
+++ b/lib/dia-line-style-selector-popover.c
@@ -0,0 +1,164 @@
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "dia-line-style-selector.h"
+#include "dia-line-style-selector-popover.h"
+#include "dia_dirs.h"
+
+typedef struct _DiaLineStyleSelectorPopoverPrivate DiaLineStyleSelectorPopoverPrivate;
+
+struct _DiaLineStyleSelectorPopoverPrivate {
+ GtkWidget *list;
+ GtkWidget *length;
+ GtkWidget *length_box;
+};
+
+G_DEFINE_TYPE_WITH_CODE (DiaLineStyleSelectorPopover, dia_line_style_selector_popover, GTK_TYPE_POPOVER,
+                         G_ADD_PRIVATE (DiaLineStyleSelectorPopover))
+
+enum {
+  VALUE_CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static gchar*
+build_ui_filename (const gchar* name)
+{
+  gchar* uifile;
+
+  if (g_getenv ("DIA_BASE_PATH") != NULL) {
+    /* a small hack cause the final destination and the local path differ */
+    const gchar* p = strrchr (name, '/');
+    if (p != NULL)
+      name = p+1;
+    uifile = g_build_filename (g_getenv ("DIA_BASE_PATH"), "data", name, NULL);
+  } else
+    uifile = dia_get_data_directory (name);
+
+  return uifile;
+}
+
+GtkWidget *
+dia_line_style_selector_popover_new ()
+{
+  return g_object_new (DIA_TYPE_LINE_STYLE_SELECTOR_POPOVER, NULL);
+}
+
+LineStyle
+dia_line_style_selector_popover_get_line_style (DiaLineStyleSelectorPopover *self,
+                                                gdouble                     *length)
+{
+  DiaLineStyleSelectorPopoverPrivate *priv = dia_line_style_selector_popover_get_instance_private (self);
+  GtkListBoxRow *row;
+  GtkWidget *preview;
+  LineStyle style;
+
+  row = gtk_list_box_get_selected_row (GTK_LIST_BOX (priv->list));
+  preview = gtk_bin_get_child (GTK_BIN (row));
+  style = dia_line_preview_get_line_style (DIA_LINE_PREVIEW (preview));
+
+  /* Don't both getting this if we don't have somewhere to return it */
+  if (length) {
+    *length = gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->length));
+  }
+
+  return style;
+}
+
+void
+dia_line_style_selector_popover_set_line_style (DiaLineStyleSelectorPopover *self,
+                                                LineStyle                    line_style)
+{
+  DiaLineStyleSelectorPopoverPrivate *priv = dia_line_style_selector_popover_get_instance_private (self);
+  GtkListBoxRow *row;
+
+  row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (priv->list), line_style);
+  gtk_list_box_select_row (GTK_LIST_BOX (priv->list), row);
+}
+
+void
+dia_line_style_selector_popover_set_length (DiaLineStyleSelectorPopover *self,
+                                            gdouble                      length)
+{
+  DiaLineStyleSelectorPopoverPrivate *priv = dia_line_style_selector_popover_get_instance_private (self);
+
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->length), length);
+}
+
+static void
+dia_line_style_selector_popover_class_init (DiaLineStyleSelectorPopoverClass *klass)
+{
+  GFile *template_file;
+  GBytes *template;
+  GError *err = NULL;
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  signals[VALUE_CHANGED] = g_signal_new ("value-changed",
+                                         G_TYPE_FROM_CLASS (klass),
+                                         G_SIGNAL_RUN_FIRST,
+                                         0, NULL, NULL,
+                                         g_cclosure_marshal_VOID__VOID,
+                                         G_TYPE_NONE, 0);
+
+  /* TODO: Use GResource */
+  template_file = g_file_new_for_path (build_ui_filename ("ui/dia-line-style-selector-popover.ui"));
+  template = g_file_load_bytes (template_file, NULL, NULL, &err);
+
+  if (err)
+    g_critical ("Failed to load template: %s", err->message);
+
+  gtk_widget_class_set_template (widget_class, template);
+  gtk_widget_class_bind_template_child_private (widget_class, DiaLineStyleSelectorPopover, list);
+  gtk_widget_class_bind_template_child_private (widget_class, DiaLineStyleSelectorPopover, length);
+  gtk_widget_class_bind_template_child_private (widget_class, DiaLineStyleSelectorPopover, length_box);
+
+  g_object_unref (template_file);
+}
+
+static void
+spin_change (GtkSpinButton *sb, gpointer data)
+{
+  g_signal_emit (G_OBJECT (data),
+                 signals[VALUE_CHANGED], 0);
+}
+
+static void
+row_selected (GtkListBox                  *box,
+              GtkListBoxRow               *row,
+              DiaLineStyleSelectorPopover *self)
+{
+  DiaLineStyleSelectorPopoverPrivate *priv = dia_line_style_selector_popover_get_instance_private (self);
+
+  int state;
+  state = dia_line_style_selector_popover_get_line_style (self, NULL)
+     != LINESTYLE_SOLID;
+
+  gtk_widget_set_sensitive (priv->length_box, state);
+  g_signal_emit (G_OBJECT (self),
+                 signals[VALUE_CHANGED], 0);
+}
+
+static void
+dia_line_style_selector_popover_init (DiaLineStyleSelectorPopover *self)
+{
+  DiaLineStyleSelectorPopoverPrivate *priv = dia_line_style_selector_popover_get_instance_private (self);
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  g_object_set (G_OBJECT (priv->length),
+                "climb-rate", DEFAULT_LINESTYLE_DASHLEN,
+                NULL);
+  g_signal_connect (G_OBJECT (priv->length), "changed",
+                    G_CALLBACK (spin_change), self);
+
+  for (int i = 0; i <= LINESTYLE_DOTTED; i++) {
+    GtkWidget *style = dia_line_preview_new (i);
+    gtk_widget_show (style);
+    gtk_list_box_insert (GTK_LIST_BOX (priv->list), style, i);
+  }
+
+  g_signal_connect (G_OBJECT (priv->list), "row-selected",
+                    G_CALLBACK (row_selected), self);
+}
diff --git a/lib/dia-line-style-selector-popover.h b/lib/dia-line-style-selector-popover.h
new file mode 100644
index 00000000..c219bb9f
--- /dev/null
+++ b/lib/dia-line-style-selector-popover.h
@@ -0,0 +1,28 @@
+#ifndef __DIALSSPOPOVER_H__
+#define __DIALSSPOPOVER_H__
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "dia-enums.h"
+
+G_BEGIN_DECLS
+
+#define DIA_TYPE_LINE_STYLE_SELECTOR_POPOVER (dia_line_style_selector_popover_get_type ())
+G_DECLARE_DERIVABLE_TYPE (DiaLineStyleSelectorPopover, dia_line_style_selector_popover, DIA, 
LINE_STYLE_SELECTOR_POPOVER, GtkPopover)
+
+struct _DiaLineStyleSelectorPopoverClass {
+  GtkPopoverClass parent_class;
+};
+
+GtkWidget *dia_line_style_selector_popover_new                  ();
+LineStyle  dia_line_style_selector_popover_get_line_style       (DiaLineStyleSelectorPopover *self,
+                                                                 gdouble                     *length);
+void       dia_line_style_selector_popover_set_line_style       (DiaLineStyleSelectorPopover *self,
+                                                                 LineStyle                    line_style);
+void       dia_line_style_selector_popover_set_length           (DiaLineStyleSelectorPopover *self,
+                                                                 gdouble                      length);
+
+G_END_DECLS
+
+#endif
diff --git a/lib/dia-line-style-selector.c b/lib/dia-line-style-selector.c
new file mode 100644
index 00000000..77051d32
--- /dev/null
+++ b/lib/dia-line-style-selector.c
@@ -0,0 +1,241 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+
+#include "intl.h"
+#include "widgets.h"
+#include "diaoptionmenu.h"
+#include "dia-line-style-selector.h"
+#include "dia-line-style-selector-popover.h"
+
+/************* DiaLinePreview: ***************/
+
+G_DEFINE_TYPE (DiaLinePreview, dia_line_preview, GTK_TYPE_WIDGET)
+
+static gint
+dia_line_preview_draw (GtkWidget *widget, cairo_t *ctx)
+{
+  DiaLinePreview *line = DIA_LINE_PREVIEW (widget);
+  GtkAllocation alloc;
+  gint width, height;
+  double dash[6];
+  int length;
+
+  gtk_widget_get_allocation (widget, &alloc);
+
+  if (gtk_widget_is_drawable (widget)) {
+    width = alloc.width;
+    height = alloc.height;
+    length = line->length * 20;
+
+    cairo_set_line_cap (ctx, CAIRO_LINE_CAP_BUTT);
+    cairo_set_line_join (ctx, CAIRO_LINE_JOIN_MITER);
+
+    /* Adapted from DiaCairoRenderer, TODO: Avoid duplication */
+    switch (line->lstyle) {
+      case LINESTYLE_DEFAULT:
+      case LINESTYLE_SOLID:
+        cairo_set_dash (ctx, NULL, 0, 0);
+        break;
+      case LINESTYLE_DASHED:
+        dash[0] = length;
+        dash[1] = length;
+        cairo_set_dash (ctx, dash, 2, 0);
+        break;
+      case LINESTYLE_DASH_DOT:
+        dash[0] = length;
+        dash[1] = length * 0.45;
+        dash[2] = length * 0.1;
+        dash[3] = length * 0.45;
+        cairo_set_dash (ctx, dash, 4, 0);
+        break;
+      case LINESTYLE_DASH_DOT_DOT:
+        dash[0] = length;
+        dash[1] = length * (0.8/3);
+        dash[2] = length * 0.1;
+        dash[3] = length * (0.8/3);
+        dash[4] = length * 0.1;
+        dash[5] = length * (0.8/3);
+        cairo_set_dash (ctx, dash, 6, 0);
+        break;
+      case LINESTYLE_DOTTED:
+        dash[0] = length * 0.1;
+        dash[1] = length * 0.1;
+        cairo_set_dash (ctx, dash, 2, 0);
+        break;
+      default:
+        g_warning("DiaLinePreview : Unsupported line style specified!");
+    }
+
+    cairo_move_to (ctx, 0, height / 2);
+    cairo_line_to (ctx, width, height / 2);
+    cairo_stroke (ctx);
+  }
+  return TRUE;
+}
+
+static void
+dia_line_preview_class_init (DiaLinePreviewClass *class)
+{
+  GtkWidgetClass *widget_class;
+
+  widget_class = GTK_WIDGET_CLASS (class);
+  widget_class->draw = dia_line_preview_draw;
+}
+
+static void
+dia_line_preview_init (DiaLinePreview *self)
+{
+  gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+  gtk_widget_set_size_request (GTK_WIDGET (self), -1, 16);
+
+  self->lstyle = LINESTYLE_SOLID;
+  self->length = 1; /* For clarity we default quite big */
+}
+
+GtkWidget *
+dia_line_preview_new (LineStyle lstyle)
+{
+  DiaLinePreview *line = g_object_new (DIA_TYPE_LINE_PREVIEW, NULL);
+
+  line->lstyle = lstyle;
+
+  return GTK_WIDGET (line);
+}
+
+void
+dia_line_preview_set_line_style (DiaLinePreview *self,
+                                 LineStyle       lstyle,
+                                 gdouble         length)
+{
+  if (self->lstyle != lstyle || self->length != length) {
+    self->lstyle = lstyle;
+    self->length = length;
+    gtk_widget_queue_draw (GTK_WIDGET (self));
+  }
+}
+
+LineStyle
+dia_line_preview_get_line_style (DiaLinePreview *self)
+{
+  return self->lstyle;
+}
+
+/************* DiaLineStyleSelector: ***************/
+
+typedef struct _DiaLineStyleSelectorPrivate DiaLineStyleSelectorPrivate;
+
+struct _DiaLineStyleSelectorPrivate {
+  GtkWidget *popover;
+  GtkWidget *preview;
+};
+
+G_DEFINE_TYPE_WITH_CODE (DiaLineStyleSelector, dia_line_style_selector, GTK_TYPE_MENU_BUTTON,
+                         G_ADD_PRIVATE (DiaLineStyleSelector))
+
+enum {
+    DLS_VALUE_CHANGED,
+    DLS_LAST_SIGNAL
+};
+
+static guint dls_signals[DLS_LAST_SIGNAL] = { 0 };
+
+static void
+dia_line_style_selector_class_init (DiaLineStyleSelectorClass *class)
+{
+  dls_signals[DLS_VALUE_CHANGED]
+      = g_signal_new("value-changed",
+                    G_TYPE_FROM_CLASS(class),
+                    G_SIGNAL_RUN_FIRST,
+                    0, NULL, NULL,
+                    g_cclosure_marshal_VOID__VOID,
+                    G_TYPE_NONE, 0);
+}
+
+static void
+value_changed (GObject *src, DiaLineStyleSelector *self)
+{
+  DiaLineStyleSelectorPrivate *priv = dia_line_style_selector_get_instance_private (self);
+  gdouble length;
+  LineStyle style = dia_line_style_selector_popover_get_line_style (DIA_LINE_STYLE_SELECTOR_POPOVER 
(priv->popover),
+                                                                    &length);
+  dia_line_preview_set_line_style (DIA_LINE_PREVIEW (priv->preview), style, length);
+
+  g_signal_emit (G_OBJECT (self),
+                 dls_signals[DLS_VALUE_CHANGED], 0);
+}
+
+static void
+dia_line_style_selector_init (DiaLineStyleSelector *self)
+{
+  GtkWidget *box;
+  GtkWidget *arrow;
+  DiaLineStyleSelectorPrivate *priv = dia_line_style_selector_get_instance_private (self);
+
+  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 16);
+  gtk_widget_show (box);
+  gtk_container_add (GTK_CONTAINER (self), box);
+
+  priv->preview = dia_line_preview_new (DEFAULT_LINESTYLE);
+  gtk_widget_show (priv->preview);
+  gtk_box_pack_start (GTK_BOX (box), priv->preview, TRUE, TRUE, 0);
+
+  arrow = gtk_image_new_from_icon_name ("pan-down-symbolic", GTK_ICON_SIZE_BUTTON);
+  gtk_widget_show (arrow);
+  gtk_box_pack_end (GTK_BOX (box), arrow, FALSE, FALSE, 0);
+ 
+  priv->popover = dia_line_style_selector_popover_new ();
+  dia_line_style_selector_popover_set_line_style (DIA_LINE_STYLE_SELECTOR_POPOVER (priv->popover),
+                                                  DEFAULT_LINESTYLE);
+  g_signal_connect (G_OBJECT (priv->popover), "value-changed",
+                    G_CALLBACK (value_changed), self);
+  gtk_menu_button_set_popover (GTK_MENU_BUTTON (self), priv->popover);
+}
+
+GtkWidget *
+dia_line_style_selector_new ()
+{
+  return g_object_new (DIA_TYPE_LINE_STYLE_SELECTOR, NULL);
+}
+
+void 
+dia_line_style_selector_get_line_style (DiaLineStyleSelector *self,
+                                        LineStyle            *ls,
+                                        gdouble              *dl)
+{
+  DiaLineStyleSelectorPrivate *priv = dia_line_style_selector_get_instance_private (self);
+
+  *ls = dia_line_style_selector_popover_get_line_style (DIA_LINE_STYLE_SELECTOR_POPOVER (priv->popover),
+                                                        (gdouble *) dl);
+}
+
+void
+dia_line_style_selector_set_line_style (DiaLineStyleSelector *self,
+                                        LineStyle             linestyle,
+                                        gdouble               dashlength)
+{
+  DiaLineStyleSelectorPrivate *priv = dia_line_style_selector_get_instance_private (self);
+
+  dia_line_style_selector_popover_set_line_style (DIA_LINE_STYLE_SELECTOR_POPOVER (priv->popover),
+                                                  linestyle);
+  dia_line_style_selector_popover_set_length (DIA_LINE_STYLE_SELECTOR_POPOVER (priv->popover),
+                                              dashlength);
+}
diff --git a/lib/dia-line-style-selector.h b/lib/dia-line-style-selector.h
new file mode 100644
index 00000000..9ae41782
--- /dev/null
+++ b/lib/dia-line-style-selector.h
@@ -0,0 +1,48 @@
+#ifndef __DIALSS_H__
+#define __DIALSS_H__
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "dia-enums.h"
+
+G_BEGIN_DECLS
+
+/* --------------- DiaLinePreview -------------------------------- */
+
+#define DIA_TYPE_LINE_PREVIEW (dia_line_preview_get_type ())
+G_DECLARE_FINAL_TYPE (DiaLinePreview, dia_line_preview, DIA, LINE_PREVIEW, GtkWidget)
+
+struct _DiaLinePreview
+{
+  GtkWidget parent;
+  LineStyle lstyle;
+  gdouble   length;
+};
+
+GtkWidget *dia_line_preview_new            (LineStyle       lstyle);
+LineStyle  dia_line_preview_get_line_style (DiaLinePreview *self);
+void       dia_line_preview_set_line_style (DiaLinePreview *self,
+                                            LineStyle       lstyle,
+                                            gdouble         length);
+
+/* --------------- DiaLineStyleSelector -------------------------------- */
+
+#define DIA_TYPE_LINE_STYLE_SELECTOR (dia_line_style_selector_get_type ())
+G_DECLARE_DERIVABLE_TYPE (DiaLineStyleSelector, dia_line_style_selector, DIA, LINE_STYLE_SELECTOR, 
GtkMenuButton)
+
+struct _DiaLineStyleSelectorClass {
+  GtkMenuButtonClass parent_class;
+};
+
+GtkWidget *dia_line_style_selector_new            (void);
+void       dia_line_style_selector_get_line_style (DiaLineStyleSelector *as,
+                                                   LineStyle            *linestyle, 
+                                                   gdouble              *dashlength);
+void       dia_line_style_selector_set_line_style (DiaLineStyleSelector *as,
+                                                   LineStyle             linestyle,
+                                                   gdouble               dashlength);
+
+G_END_DECLS
+
+#endif
diff --git a/lib/prop_attr.c b/lib/prop_attr.c
index d94c3a6f..8f0369b2 100644
--- a/lib/prop_attr.c
+++ b/lib/prop_attr.c
@@ -72,15 +72,15 @@ linestyleprop_get_widget(LinestyleProperty *prop, PropDialog *dialog)
 static void 
 linestyleprop_reset_widget(LinestyleProperty *prop, WIDGET *widget)
 {
-  dia_line_style_selector_set_linestyle(DIALINESTYLESELECTOR(widget),
-                                        prop->style,
-                                        prop->dash);
+  dia_line_style_selector_set_line_style (DIA_LINE_STYLE_SELECTOR(widget),
+                                          prop->style,
+                                          prop->dash);
 }
 
 static void 
 linestyleprop_set_from_widget(LinestyleProperty *prop, WIDGET *widget) 
 {
-  dia_line_style_selector_get_linestyle(DIALINESTYLESELECTOR(widget),
+  dia_line_style_selector_get_line_style(DIA_LINE_STYLE_SELECTOR(widget),
                                         &prop->style,
                                         &prop->dash);
 }
diff --git a/lib/widgets.h b/lib/widgets.h
index 881ed4ee..e1517c27 100644
--- a/lib/widgets.h
+++ b/lib/widgets.h
@@ -25,26 +25,13 @@
 #include "font.h"
 #include "arrows.h"
 #include "units.h"
+#include "dia-line-style-selector.h"
 
 /* DiaAlignmentSelector: */
 GtkWidget* dia_alignment_selector_new           (void);
 Alignment  dia_alignment_selector_get_alignment (GtkWidget *as);
 void       dia_alignment_selector_set_alignment (GtkWidget *as, Alignment align);
 
-/* DiaLineStyleSelector: */
-#define DIALINESTYLESELECTOR(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, dia_line_style_selector_get_type 
(), DiaLineStyleSelector)
-#define DIALINESTYLESELECTOR_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, dia_line_style_selector_get_type 
(), DiaLineStyleSelectorClass)
-#define IS_DIALINESTYLESELECTOR(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, dia_line_style_selector_get_type 
())
-
-GType      dia_line_style_selector_get_type      (void);
-GtkWidget* dia_line_style_selector_new           (void);
-void       dia_line_style_selector_get_linestyle (DiaLineStyleSelector *as,
-                                                 LineStyle *linestyle, 
-                                                 real *dashlength);
-void       dia_line_style_selector_set_linestyle (DiaLineStyleSelector *as,
-                                                 LineStyle linestyle,
-                                                 real dashlength);
-
 /* DiaColorSelector: */
 #define DIACOLORSELECTOR(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, dia_color_selector_get_type (), 
DiaColorSelector)
 #define DIACOLORSELECTOR_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, dia_color_selector_get_type (), 
DiaColorSelectorClass)


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