[dia] guides: cleanup and add docs
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] guides: cleanup and add docs
- Date: Sun, 6 Oct 2019 18:05:58 +0000 (UTC)
commit 1ee17cbc64be2be1b096e1fadea83c50c7fb7ab6
Author: Zander Brown <zbrown gnome org>
Date: Sun Oct 6 19:05:45 2019 +0100
guides: cleanup and add docs
app/commands.c | 8 +-
app/dia-guide-dialog.c | 208 +++++++++++++++++++++++++
app/{new_guide_dialog.h => dia-guide-dialog.h} | 22 ++-
app/{guide_tool.c => dia-guide-tool.c} | 14 +-
app/{guide_tool.h => dia-guide-tool.h} | 14 +-
app/diagram.c | 148 ++++++++++++++----
app/diagram.h | 69 ++++----
app/grid.c | 18 +--
app/interface.c | 2 +-
app/layer-editor/dia-layer-editor-dialog.h | 2 +-
app/load_save.c | 4 +-
app/meson.build | 8 +-
app/modify_tool.c | 8 +-
app/new_guide_dialog.c | 149 ------------------
app/tool.c | 2 +-
app/undo.c | 35 +++--
app/undo.h | 8 +-
docs/dia-app/dia-app-docs.xml | 25 +--
docs/dia/dia-docs.xml | 1 +
lib/dia-guide.c | 58 +++++++
lib/{guide.h => dia-guide.h} | 19 ++-
lib/guide.c | 1 -
lib/meson.build | 4 +-
po/POTFILES.in | 1 +
24 files changed, 520 insertions(+), 308 deletions(-)
---
diff --git a/app/commands.c b/app/commands.c
index 95d2c6a3..6cbe5b9f 100644
--- a/app/commands.c
+++ b/app/commands.c
@@ -90,7 +90,7 @@ ShellExecuteA (long hwnd,
#include "dia-props.h"
#include "authors.h" /* master contributors data */
#include "object.h"
-#include "new_guide_dialog.h"
+#include "dia-guide-dialog.h"
void
@@ -1433,13 +1433,15 @@ void
view_new_guide_callback (GtkAction *action)
{
DDisplay *ddisp;
+ GtkWidget *dlg;
ddisp = ddisplay_active ();
if (!ddisp) {
return;
}
- dialog_new_guide_show ();
+ dlg = dia_guide_dialog_new (GTK_WINDOW (ddisp->shell), ddisp->diagram);
+ gtk_widget_show (dlg);
}
@@ -1488,7 +1490,7 @@ view_remove_all_guides_callback (GtkAction *action)
return;
}
- diagram_remove_all_guides (dia);
+ dia_diagram_remove_all_guides (dia);
diagram_add_update_all (dia);
diagram_flush (dia);
}
diff --git a/app/dia-guide-dialog.c b/app/dia-guide-dialog.c
new file mode 100644
index 00000000..c9ff7278
--- /dev/null
+++ b/app/dia-guide-dialog.c
@@ -0,0 +1,208 @@
+/* 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 <gtk/gtk.h>
+
+#include "dia-guide-dialog.h"
+#include "diaoptionmenu.h"
+#include "intl.h"
+
+
+typedef struct _DiaGuideDialogPrivate DiaGuideDialogPrivate;
+struct _DiaGuideDialogPrivate {
+ Diagram *diagram;
+ GtkWidget *position_entry;
+ GtkWidget *orientation_menu;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (DiaGuideDialog, dia_guide_dialog, GTK_TYPE_DIALOG)
+
+enum {
+ PROP_0,
+ PROP_DIAGRAM,
+ LAST_PROP
+};
+
+static GParamSpec *pspecs[LAST_PROP] = { NULL, };
+
+
+static void
+dia_guide_dialog_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ DiaGuideDialog *self = DIA_GUIDE_DIALOG (object);
+ DiaGuideDialogPrivate *priv = dia_guide_dialog_get_instance_private (self);
+
+ switch (property_id) {
+ case PROP_DIAGRAM:
+ g_clear_object (&priv->diagram);
+ priv->diagram = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
+dia_guide_dialog_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ DiaGuideDialog *self = DIA_GUIDE_DIALOG (object);
+ DiaGuideDialogPrivate *priv = dia_guide_dialog_get_instance_private (self);
+
+ switch (property_id) {
+ case PROP_DIAGRAM:
+ g_value_set_object (value, priv->diagram);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
+dia_guide_dialog_finalize (GObject *object)
+{
+ DiaGuideDialog *self = DIA_GUIDE_DIALOG (object);
+ DiaGuideDialogPrivate *priv = dia_guide_dialog_get_instance_private (self);
+
+ g_clear_object (&priv->diagram);
+
+ G_OBJECT_CLASS (dia_guide_dialog_parent_class)->finalize (object);
+}
+
+
+static void
+dia_guide_dialog_response (GtkDialog *dialog,
+ gint response_id)
+{
+ DiaGuideDialog *self = DIA_GUIDE_DIALOG (dialog);
+ DiaGuideDialogPrivate *priv = dia_guide_dialog_get_instance_private (self);
+
+ if (response_id == GTK_RESPONSE_OK) {
+ real position = gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->position_entry));
+ int orientation = dia_option_menu_get_active (priv->orientation_menu);
+ dia_diagram_add_guide (priv->diagram, position, orientation, TRUE);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+
+static void
+dia_guide_dialog_class_init (DiaGuideDialogClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
+
+ object_class->set_property = dia_guide_dialog_set_property;
+ object_class->get_property = dia_guide_dialog_get_property;
+ object_class->finalize = dia_guide_dialog_finalize;
+
+ dialog_class->response = dia_guide_dialog_response;
+
+ /**
+ * DiaGuideDialog:diagram:
+ *
+ * Since: 0.98
+ */
+ pspecs[PROP_DIAGRAM] =
+ g_param_spec_object ("diagram",
+ "Diagram",
+ "The current diagram",
+ DIA_TYPE_DIAGRAM,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, LAST_PROP, pspecs);
+}
+
+static void
+dia_guide_dialog_init (DiaGuideDialog *self)
+{
+ DiaGuideDialogPrivate *priv = dia_guide_dialog_get_instance_private (self);
+ GtkWidget *dialog_vbox;
+ GtkWidget *label;
+ GtkAdjustment *adj;
+ GtkWidget *table;
+ const gdouble UPPER_LIMIT = G_MAXDOUBLE;
+
+ gtk_window_set_title (GTK_WINDOW (self), _("Add New Guide"));
+ gtk_window_set_role (GTK_WINDOW (self), "new_guide");
+
+ gtk_dialog_add_buttons (GTK_DIALOG (self),
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_OK"), GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
+
+ dialog_vbox = gtk_dialog_get_content_area (GTK_DIALOG (self));
+
+ table = gtk_table_new (3, 3, FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (table), 6);
+ gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+ gtk_table_set_col_spacings (GTK_TABLE (table), 6);
+
+ label = gtk_label_new (_("Orientation"));
+ g_object_set (label, "xalign", 1.0, NULL);
+ gtk_table_attach (GTK_TABLE (table), label, 0,1, 0,1,
+ GTK_FILL, GTK_FILL, 0, 0);
+ gtk_widget_show (label);
+
+ priv->orientation_menu = dia_option_menu_new ();
+ gtk_table_attach (GTK_TABLE (table), priv->orientation_menu, 1,2, 0,1,
+ GTK_FILL, GTK_FILL, 0, 0);
+ dia_option_menu_add_item (priv->orientation_menu, "Horizontal", GTK_ORIENTATION_HORIZONTAL);
+ dia_option_menu_add_item (priv->orientation_menu, "Vertical", GTK_ORIENTATION_VERTICAL);
+ dia_option_menu_set_active (priv->orientation_menu, GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_show (priv->orientation_menu);
+
+ label = gtk_label_new (_("Position"));
+ g_object_set (label, "xalign", 1.0, NULL);
+ gtk_table_attach (GTK_TABLE (table), label, 0,1, 1,2,
+ GTK_FILL, GTK_FILL, 0, 0);
+ gtk_widget_show (label);
+
+ adj = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 0.0, UPPER_LIMIT, 0.1, 10.0, 0));
+ priv->position_entry = gtk_spin_button_new (adj, 1.0, 3);
+ gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (priv->position_entry), TRUE);
+ gtk_table_attach (GTK_TABLE (table), priv->position_entry, 1,2, 1,2,
+ GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
+ gtk_widget_show (priv->position_entry);
+
+ gtk_widget_show (table);
+
+ gtk_box_pack_start (GTK_BOX (dialog_vbox), table, TRUE, TRUE, 0);
+ gtk_widget_show (dialog_vbox);
+}
+
+GtkWidget *
+dia_guide_dialog_new (GtkWindow *parent, Diagram *dia)
+{
+ return g_object_new (DIA_TYPE_GUIDE_DIALOG,
+ "transient-for", parent,
+ "diagram", dia,
+ NULL);
+}
diff --git a/app/new_guide_dialog.h b/app/dia-guide-dialog.h
similarity index 66%
rename from app/new_guide_dialog.h
rename to app/dia-guide-dialog.h
index e8799b76..d1a9e1d1 100644
--- a/app/new_guide_dialog.h
+++ b/app/dia-guide-dialog.h
@@ -15,12 +15,24 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef NEW_GUIDE_DIALOG_H
-#define NEW_GUIDE_DIALOG_H
-#include "diatypes.h"
+#pragma once
+
+#include <gtk/gtk.h>
+
#include "diagram.h"
+#include "layer-editor/dia-layer-editor-dialog.h"
+
+G_BEGIN_DECLS
+
+#define DIA_TYPE_GUIDE_DIALOG dia_guide_dialog_get_type ()
+G_DECLARE_DERIVABLE_TYPE (DiaGuideDialog, dia_guide_dialog, DIA, GUIDE_DIALOG, GtkDialog)
+
+struct _DiaGuideDialogClass {
+ GtkDialogClass parent;
+};
-void dialog_new_guide_show (void);
+GtkWidget *dia_guide_dialog_new (GtkWindow *parent,
+ Diagram *dia);
-#endif /* NEW_GUIDE_DIALOG_H */
+G_END_DECLS
diff --git a/app/guide_tool.c b/app/dia-guide-tool.c
similarity index 94%
rename from app/guide_tool.c
rename to app/dia-guide-tool.c
index 4abadce8..01ac2c1e 100644
--- a/app/guide_tool.c
+++ b/app/dia-guide-tool.c
@@ -20,7 +20,7 @@
#include <gdk/gdk.h>
#include "cursor.h"
-#include "guide_tool.h"
+#include "dia-guide-tool.h"
#include "undo.h"
#include "diainteractiverenderer.h"
@@ -34,7 +34,7 @@ static real guide_original_pos = 0;
struct _GuideTool {
Tool tool;
- Guide *guide;
+ DiaGuide *guide;
real position;
GtkOrientation orientation;
int ruler_height;
@@ -58,7 +58,7 @@ void _guide_tool_start_new (DDisplay *display,
void _guide_tool_start (DDisplay *display,
GtkOrientation orientation,
- Guide *guide)
+ DiaGuide *guide)
{
tool_select(GUIDE_TOOL, guide, GINT_TO_POINTER(orientation), NULL, 0);
display->dragged_new_guideline_orientation = orientation;
@@ -99,7 +99,7 @@ guide_button_release(GuideTool *tool, GdkEventButton *event,
/* Dragged out of bounds, so remove the guide. */
if (tool->guide) {
tool->guide->position = guide_original_pos; /* So that when we undo, it goes back to original
position. */
- diagram_remove_guide (ddisp->diagram, tool->guide, TRUE);
+ dia_diagram_remove_guide (ddisp->diagram, tool->guide, TRUE);
tool->guide = NULL;
}
}
@@ -107,7 +107,7 @@ guide_button_release(GuideTool *tool, GdkEventButton *event,
{
if (!tool->guide) {
/* Add a new guide. */
- diagram_add_guide (ddisp->diagram, tool->position, tool->orientation, TRUE);
+ dia_diagram_add_guide (ddisp->diagram, tool->position, tool->orientation, TRUE);
}
else
{
@@ -197,7 +197,7 @@ void guide_tool_set_ruler_height(Tool *tool, int height)
}
void guide_tool_start_edit (DDisplay *display,
- Guide *guide)
+ DiaGuide *guide)
{
_guide_tool_start (display, guide->orientation, guide);
@@ -208,7 +208,7 @@ void guide_tool_start_edit (DDisplay *display,
}
}
-void guide_tool_set_guide(Tool *tool, Guide *guide)
+void guide_tool_set_guide(Tool *tool, DiaGuide *guide)
{
GuideTool *gtool = (GuideTool *)tool;
gtool->guide = guide;
diff --git a/app/guide_tool.h b/app/dia-guide-tool.h
similarity index 88%
rename from app/guide_tool.h
rename to app/dia-guide-tool.h
index 1e003514..8f5a47e1 100644
--- a/app/guide_tool.h
+++ b/app/dia-guide-tool.h
@@ -15,10 +15,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef GUIDE_TOOL_H
-#define GUIDE_TOOL_H
-#include "guide.h"
+#pragma once
+
+#include "dia-guide.h"
#include "tool.h"
typedef struct _GuideTool GuideTool;
@@ -32,23 +32,21 @@ void _guide_tool_start_new (DDisplay *display,
/** Start editing (i.e. moving) an existing guide. */
void guide_tool_start_edit (DDisplay *display,
- Guide *guide);
+ DiaGuide *guide);
/** Start using the guide tool.
* If guide is not NULL, then start editing that guide.
* If guide is NULL, then start adding a new guide. */
void _guide_tool_start (DDisplay *display,
GtkOrientation orientation,
- Guide *guide);
+ DiaGuide *guide);
/** Inform the tool of the ruler height. Required to calculate
* the position of the guide on the page. */
void guide_tool_set_ruler_height(Tool *tool, int height);
/** Set the guide to edit. */
-void guide_tool_set_guide(Tool *tool, Guide *guide);
+void guide_tool_set_guide(Tool *tool, DiaGuide *guide);
/** Set the orientation of the tool. */
void guide_tool_set_orientation(Tool *tool, GtkOrientation orientation);
-
-#endif /* GUIDE_TOOL_H */
diff --git a/app/diagram.c b/app/diagram.c
index 8e034980..b870beaa 100644
--- a/app/diagram.c
+++ b/app/diagram.c
@@ -1599,6 +1599,7 @@ dia_diagram_set_file (Diagram *self,
g_object_notify_by_pspec (G_OBJECT (self), pspecs[PROP_FILE]);
}
+
GFile *
dia_diagram_get_file (Diagram *self)
{
@@ -1610,15 +1611,30 @@ dia_diagram_get_file (Diagram *self)
}
-Guide *
-diagram_add_guide (Diagram *dia, real position, GtkOrientation orientation, gboolean push_undo)
+/**
+ * dia_diagram_add_guide:
+ * @dia: the #Diagram
+ * @position: when (relative to origin) to place the #DiaGuide
+ * @orientation: which axis the guide is for
+ * @push_undo: Update the undo stack if %TRUE
+ *
+ * Add a guide to the diagram at the given position and orientation.
+ *
+ * Returns: the new #DiaGuide
+ *
+ * Since: 0.98
+ */
+DiaGuide *
+dia_diagram_add_guide (Diagram *dia,
+ real position,
+ GtkOrientation orientation,
+ gboolean push_undo)
{
- Guide *guide = g_new0 (Guide, 1);
- guide->position = position;
- guide->orientation = orientation;
+ DiaGuide *guide = dia_guide_new (orientation, position);
+
dia->guides = g_list_append (dia->guides, guide);
- if(push_undo) {
+ if (push_undo) {
dia_add_guide_change_new (dia, guide, TRUE); /* Update undo stack. */
undo_set_transactionpoint (dia->undo);
}
@@ -1630,15 +1646,30 @@ diagram_add_guide (Diagram *dia, real position, GtkOrientation orientation, gboo
return guide;
}
-Guide *
-diagram_pick_guide (Diagram *dia,
- gdouble x,
- gdouble y,
- gdouble epsilon_x,
- gdouble epsilon_y)
+
+/**
+ * dia_diagram_pick_guide:
+ * @dia: #the #Diagram
+ * @x: horizontal position
+ * @y: vertical position
+ * @epsilon_x: margin of error for @x
+ * @epsilon_y: margin of error for @y
+ *
+ * Rick a guide within (@epsilon_x, @epsilon_y) distance of (@x, @y).
+ *
+ * Returns: %NULL if no such guide exists.
+ *
+ * Since: 0.98
+ */
+DiaGuide *
+dia_diagram_pick_guide (Diagram *dia,
+ gdouble x,
+ gdouble y,
+ gdouble epsilon_x,
+ gdouble epsilon_y)
{
GList *list;
- Guide *ret = NULL;
+ DiaGuide *ret = NULL;
gdouble mindist = G_MAXDOUBLE;
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
@@ -1646,7 +1677,7 @@ diagram_pick_guide (Diagram *dia,
for (list = dia->guides;
list;
list = g_list_next (list)) {
- Guide *guide = list->data;
+ DiaGuide *guide = list->data;
real position = guide->position;
gdouble dist;
@@ -1675,15 +1706,31 @@ diagram_pick_guide (Diagram *dia,
return ret;
}
-Guide *
-diagram_pick_guide_h (Diagram *dia,
- gdouble x,
- gdouble y,
- gdouble epsilon_x,
- gdouble epsilon_y)
+
+/**
+ * dia_diagram_pick_guide_h:
+ * @dia: #the #Diagram
+ * @x: horizontal position
+ * @y: vertical position
+ * @epsilon_x: margin of error for @x
+ * @epsilon_y: margin of error for @y
+ *
+ * Rick a %GTK_ORIENTATION_HORIZONTAL guide
+ * within (@epsilon_x, @epsilon_y) distance of (@x, @y).
+ *
+ * Returns: %NULL if no such guide exists.
+ *
+ * Since: 0.98
+ */
+DiaGuide *
+dia_diagram_pick_guide_h (Diagram *dia,
+ gdouble x,
+ gdouble y,
+ gdouble epsilon_x,
+ gdouble epsilon_y)
{
GList *list;
- Guide *ret = NULL;
+ DiaGuide *ret = NULL;
gdouble mindist = G_MAXDOUBLE;
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
@@ -1691,7 +1738,7 @@ diagram_pick_guide_h (Diagram *dia,
for (list = dia->guides;
list;
list = g_list_next (list)) {
- Guide *guide = list->data;
+ DiaGuide *guide = list->data;
real position = guide->position;
gdouble dist;
@@ -1713,15 +1760,30 @@ diagram_pick_guide_h (Diagram *dia,
}
-Guide *
-diagram_pick_guide_v (Diagram *dia,
- gdouble x,
- gdouble y,
- gdouble epsilon_x,
- gdouble epsilon_y)
+/**
+ * dia_diagram_pick_guide_v:
+ * @dia: #the #Diagram
+ * @x: horizontal position
+ * @y: vertical position
+ * @epsilon_x: margin of error for @x
+ * @epsilon_y: margin of error for @y
+ *
+ * Rick a %GTK_ORIENTATION_VERTICAL guide
+ * within (@epsilon_x, @epsilon_y) distance of (@x, @y).
+ *
+ * Returns: %NULL if no such guide exists.
+ *
+ * Since: 0.98
+ */
+DiaGuide *
+dia_diagram_pick_guide_v (Diagram *dia,
+ gdouble x,
+ gdouble y,
+ gdouble epsilon_x,
+ gdouble epsilon_y)
{
GList *list;
- Guide *ret = NULL;
+ DiaGuide *ret = NULL;
gdouble mindist = G_MAXDOUBLE;
g_return_val_if_fail (epsilon_x > 0 && epsilon_y > 0, NULL);
@@ -1729,7 +1791,7 @@ diagram_pick_guide_v (Diagram *dia,
for (list = dia->guides;
list;
list = g_list_next (list)) {
- Guide *guide = list->data;
+ DiaGuide *guide = list->data;
real position = guide->position;
gdouble dist;
@@ -1751,8 +1813,18 @@ diagram_pick_guide_v (Diagram *dia,
}
+/**
+ * dia_diagram_remove_guide:
+ * @dia: the #Diagram
+ * @guide: the #DiaGuide
+ * @push_undo: Update the undo stack if %TRUE
+ *
+ * Remove the given guide from the diagram.
+ *
+ * Since: 0.98
+ */
void
-diagram_remove_guide (Diagram *dia, Guide *guide, gboolean push_undo)
+dia_diagram_remove_guide (Diagram *dia, DiaGuide *guide, gboolean push_undo)
{
if (push_undo) {
dia_delete_guide_change_new (dia, guide, TRUE); /* Update undo stack. */
@@ -1762,13 +1834,21 @@ diagram_remove_guide (Diagram *dia, Guide *guide, gboolean push_undo)
}
+/**
+ * dia_diagram_remove_all_guides:
+ * @dia: the #Diagram
+ *
+ * Remove all guides from the diagram.
+ *
+ * Updates undo stack.
+ */
void
-diagram_remove_all_guides (Diagram *dia)
+dia_diagram_remove_all_guides (Diagram *dia)
{
GList *list;
- for(list = g_list_copy (dia->guides); list; list = g_list_next(list)) {
- diagram_remove_guide (dia, list->data, TRUE);
+ for (list = g_list_copy (dia->guides); list; list = g_list_next (list)) {
+ dia_diagram_remove_guide (dia, list->data, TRUE);
}
undo_set_transactionpoint (dia->undo);
diff --git a/app/diagram.h b/app/diagram.h
index 735205cb..ef981312 100644
--- a/app/diagram.h
+++ b/app/diagram.h
@@ -26,7 +26,7 @@ typedef struct _Diagram Diagram;
#include "diagramdata.h"
#include "undo.h"
#include "diagrid.h"
-#include "guide.h"
+#include "dia-guide.h"
G_BEGIN_DECLS
@@ -133,46 +133,33 @@ void diagram_redraw_all(void);
void diagram_object_modified(Diagram *dia, DiaObject *object);
-Diagram *dia_diagram_new (GFile *file);
-void dia_diagram_set_file (Diagram *self,
- GFile *file);
-GFile *dia_diagram_get_file (Diagram *self);
-
-/** Add a guide to the diagram at the given position and orientation.
- * Update the undo stack if "push_undo" is true. */
-Guide *diagram_add_guide (Diagram *dia, real position, GtkOrientation orientation, gboolean push_undo);
-
-/** Pick a guide within (epsilon_x, epsilon_y) distance of (x, y).
- * Return NULL if no such guide exists. */
-Guide *diagram_pick_guide (Diagram *dia,
- gdouble x,
- gdouble y,
- gdouble epsilon_x,
- gdouble epsilon_y);
-
-
-/** Pick a *horizontal* guide within (epsilon_x, epsilon_y) distance of (x, y).
- * Return NULL if no such guide exists. */
-Guide *diagram_pick_guide_h (Diagram *dia,
- gdouble x,
- gdouble y,
- gdouble epsilon_x,
- gdouble epsilon_y);
-
-/** Pick a *vertical* guide within (epsilon_x, epsilon_y) distance of (x, y).
- * Return NULL if no such guide exists. */
-Guide *diagram_pick_guide_v (Diagram *dia,
- gdouble x,
- gdouble y,
- gdouble epsilon_x,
- gdouble epsilon_y);
-
-/** Remove the given guide from the diagram.
- * Update the undo stack if "push_undo" is true. */
-void diagram_remove_guide (Diagram *dia, Guide *guide, gboolean push_undo);
-
-/** Remove all guides from the diagram. Updates undo stack. */
-void diagram_remove_all_guides (Diagram *dia);
+Diagram *dia_diagram_new (GFile *file);
+void dia_diagram_set_file (Diagram *self,
+ GFile *file);
+GFile *dia_diagram_get_file (Diagram *self);
+DiaGuide *dia_diagram_add_guide (Diagram *dia,
+ real position,
+ GtkOrientation orientation,
+ gboolean push_undo);
+DiaGuide *dia_diagram_pick_guide (Diagram *dia,
+ gdouble x,
+ gdouble y,
+ gdouble epsilon_x,
+ gdouble epsilon_y);
+DiaGuide *dia_diagram_pick_guide_h (Diagram *dia,
+ gdouble x,
+ gdouble y,
+ gdouble epsilon_x,
+ gdouble epsilon_y);
+DiaGuide *dia_diagram_pick_guide_v (Diagram *dia,
+ gdouble x,
+ gdouble y,
+ gdouble epsilon_x,
+ gdouble epsilon_y);
+void dia_diagram_remove_guide (Diagram *dia,
+ DiaGuide *guide,
+ gboolean push_undo);
+void dia_diagram_remove_all_guides (Diagram *dia);
G_END_DECLS
diff --git a/app/grid.c b/app/grid.c
index 516667b7..9011e4ee 100644
--- a/app/grid.c
+++ b/app/grid.c
@@ -406,7 +406,7 @@ guidelines_draw (DDisplay *ddisp, DiaRectangle *update)
while (list) {
int x;
int y;
- Guide *guide = list->data;
+ DiaGuide *guide = list->data;
switch (guide->orientation) {
case GTK_ORIENTATION_HORIZONTAL:
@@ -468,17 +468,17 @@ snap_to_grid (DDisplay *ddisp, coord *x, coord *y)
/* First snap to guides - only if they are visible and the setting is
* turned on. */
if (ddisp->guides_snap && ddisp->guides_visible) {
- Guide *guide_h;
- Guide *guide_v;
+ DiaGuide *guide_h;
+ DiaGuide *guide_v;
const gint snap_distance = prefs.snap_distance;
- guide_h = diagram_pick_guide_h (ddisp->diagram, *x, *y,
- FUNSCALEX (ddisp, snap_distance),
- FUNSCALEY (ddisp, snap_distance));
+ guide_h = dia_diagram_pick_guide_h (ddisp->diagram, *x, *y,
+ FUNSCALEX (ddisp, snap_distance),
+ FUNSCALEY (ddisp, snap_distance));
- guide_v = diagram_pick_guide_v (ddisp->diagram, *x, *y,
- FUNSCALEX (ddisp, snap_distance),
- FUNSCALEY (ddisp, snap_distance));
+ guide_v = dia_diagram_pick_guide_v (ddisp->diagram, *x, *y,
+ FUNSCALEX (ddisp, snap_distance),
+ FUNSCALEY (ddisp, snap_distance));
if (guide_h) {
*y = guide_h->position;
diff --git a/app/interface.c b/app/interface.c
index a1918b06..18f33a59 100644
--- a/app/interface.c
+++ b/app/interface.c
@@ -50,7 +50,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
-#include "guide_tool.h"
+#include "dia-guide-tool.h"
#include <glib/gprintf.h>
diff --git a/app/layer-editor/dia-layer-editor-dialog.h b/app/layer-editor/dia-layer-editor-dialog.h
index b5c22e05..3832203f 100644
--- a/app/layer-editor/dia-layer-editor-dialog.h
+++ b/app/layer-editor/dia-layer-editor-dialog.h
@@ -20,12 +20,12 @@
#include <gtk/gtk.h>
#include "diagram.h"
+#include "dia-props.h"
G_BEGIN_DECLS
#define DIA_TYPE_LAYER_EDITOR_DIALOG dia_layer_editor_dialog_get_type ()
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (GtkDialog, g_object_unref)
G_DECLARE_DERIVABLE_TYPE (DiaLayerEditorDialog, dia_layer_editor_dialog, DIA, LAYER_EDITOR_DIALOG, GtkDialog)
diff --git a/app/load_save.c b/app/load_save.c
index 79fd40d2..e27a7783 100644
--- a/app/load_save.c
+++ b/app/load_save.c
@@ -590,7 +590,7 @@ diagram_data_load(const gchar *filename, DiagramData *data, DiaContext *ctx, voi
orientation = data_int (attribute_first_data (attr), ctx);
}
- diagram_add_guide (diagram, position, orientation, FALSE);
+ dia_diagram_add_guide (diagram, position, orientation, FALSE);
guides_data = data_next (guides_data);
}
@@ -976,7 +976,7 @@ diagram_data_write_doc(DiagramData *data, const char *filename, DiaContext *ctx)
attr = new_attribute ((ObjectNode) tree, "guides");
list = diagram->guides;
while (list) {
- Guide *guide = list->data;
+ DiaGuide *guide = list->data;
guideinfo = data_add_composite (attr, "guide", ctx);
diff --git a/app/meson.build b/app/meson.build
index 308a440a..6690a247 100644
--- a/app/meson.build
+++ b/app/meson.build
@@ -22,10 +22,10 @@ dia_sources = [
'layer-editor/layer_dialog.c',
'layer-editor/layer_dialog.h',
- 'guide_tool.c',
- 'guide_tool.h',
- 'new_guide_dialog.c',
- 'new_guide_dialog.h',
+ 'dia-guide-tool.c',
+ 'dia-guide-tool.h',
+ 'dia-guide-dialog.c',
+ 'dia-guide-dialog.h',
'commands.c',
'app_procs.c',
diff --git a/app/modify_tool.c b/app/modify_tool.c
index 1f218250..2cd0d36d 100644
--- a/app/modify_tool.c
+++ b/app/modify_tool.c
@@ -42,7 +42,7 @@
#include "prop_text.h"
#include "object.h"
-#include "guide_tool.h"
+#include "dia-guide-tool.h"
static DiaObject *click_select_object(DDisplay *ddisp, Point *clickedpoint,
GdkEventButton *event);
@@ -82,7 +82,7 @@ struct _ModifyTool {
Point *orig_pos;
/* Guide info: */
- Guide *guide;
+ DiaGuide *guide;
};
@@ -273,7 +273,7 @@ modify_button_press(ModifyTool *tool, GdkEventButton *event,
Point clickedpoint;
DiaObject *clicked_obj;
gboolean some_selected;
- Guide *guide;
+ DiaGuide *guide;
const gint pick_guide_snap_distance = 20; /* Margin of error for selecting a guide. */
ddisplay_untransform_coords(ddisp,
@@ -308,7 +308,7 @@ modify_button_press(ModifyTool *tool, GdkEventButton *event,
/* If there is a guide nearby, then drag it.
* Note: We can only drag guides if they are visible (like in GIMP). */
if (ddisp->guides_visible) {
- guide = diagram_pick_guide (ddisp->diagram, clickedpoint.x, clickedpoint.y,
+ guide = dia_diagram_pick_guide (ddisp->diagram, clickedpoint.x, clickedpoint.y,
FUNSCALEX (ddisp, pick_guide_snap_distance ),
FUNSCALEY (ddisp, pick_guide_snap_distance ));
diff --git a/app/tool.c b/app/tool.c
index 8ec24d7f..dd432a36 100644
--- a/app/tool.c
+++ b/app/tool.c
@@ -26,7 +26,7 @@
#include "interface.h"
#include "defaults.h"
#include "object.h"
-#include "guide_tool.h"
+#include "dia-guide-tool.h"
Tool *active_tool = NULL;
Tool *transient_tool = NULL;
diff --git a/app/undo.c b/app/undo.c
index c714541b..5afeecfe 100644
--- a/app/undo.c
+++ b/app/undo.c
@@ -1650,7 +1650,7 @@ struct _DiaMoveGuideChange {
real orig_pos;
real dest_pos;
- Guide *guide;
+ DiaGuide *guide;
};
DIA_DEFINE_CHANGE (DiaMoveGuideChange, dia_move_guide_change)
@@ -1692,7 +1692,7 @@ dia_move_guide_change_free (DiaChange *change)
DiaChange *
-dia_move_guide_change_new (Diagram *dia, Guide *guide, real orig_pos, real dest_pos)
+dia_move_guide_change_new (Diagram *dia, DiaGuide *guide, real orig_pos, real dest_pos)
{
DiaMoveGuideChange *change = dia_change_new (DIA_TYPE_MOVE_GUIDE_CHANGE);
@@ -1710,7 +1710,7 @@ dia_move_guide_change_new (Diagram *dia, Guide *guide, real orig_pos, real dest_
struct _DiaAddGuideChange {
DiaChange parent;
- Guide *guide;
+ DiaGuide *guide;
int applied;
};
@@ -1721,11 +1721,11 @@ static void
dia_add_guide_change_apply (DiaChange *self, Diagram *dia)
{
DiaAddGuideChange *change = DIA_ADD_GUIDE_CHANGE (self);
- Guide *new_guide;
+ DiaGuide *new_guide;
g_debug ("add_guide_apply()");
- new_guide = diagram_add_guide (dia, change->guide->position, change->guide->orientation, FALSE);
+ new_guide = dia_diagram_add_guide (dia, change->guide->position, change->guide->orientation, FALSE);
g_free (change->guide);
change->guide = new_guide;
@@ -1746,7 +1746,7 @@ dia_add_guide_change_revert (DiaChange *self, Diagram *dia)
g_debug ("add_guide_revert()");
- diagram_remove_guide (dia, change->guide, FALSE);
+ dia_diagram_remove_guide (dia, change->guide, FALSE);
/* Force redraw. */
diagram_add_update_all (dia);
@@ -1772,7 +1772,7 @@ dia_add_guide_change_free (DiaChange *self)
DiaChange *
-dia_add_guide_change_new (Diagram *dia, Guide *guide, int applied)
+dia_add_guide_change_new (Diagram *dia, DiaGuide *guide, int applied)
{
DiaAddGuideChange *change = dia_change_new (DIA_TYPE_ADD_GUIDE_CHANGE);
@@ -1789,7 +1789,7 @@ dia_add_guide_change_new (Diagram *dia, Guide *guide, int applied)
struct _DiaDeleteGuideChange {
DiaChange parent;
- Guide *guide;
+ DiaGuide *guide;
int applied;
};
@@ -1803,7 +1803,7 @@ dia_delete_guide_change_apply (DiaChange *self, Diagram *dia)
g_debug ("delete_guide_apply()");
- diagram_remove_guide (dia, change->guide, FALSE);
+ dia_diagram_remove_guide (dia, change->guide, FALSE);
/* Force redraw. */
diagram_add_update_all (dia);
@@ -1821,22 +1821,25 @@ dia_delete_guide_change_revert (DiaChange *self, Diagram *dia)
DiaDeleteGuideChange *change = DIA_DELETE_GUIDE_CHANGE (self);
/* Declare variable. */
- Guide *new_guide;
+ DiaGuide *new_guide;
/* Log message. */
g_debug ("delete_guide_revert()");
/* Add it again. */
- new_guide = diagram_add_guide(dia, change->guide->position, change->guide->orientation, FALSE);
+ new_guide = dia_diagram_add_guide (dia,
+ change->guide->position,
+ change->guide->orientation,
+ FALSE);
/* Reassign. */
- g_free(change->guide);
+ g_free (change->guide);
change->guide = new_guide;
/* Force redraw. */
- diagram_add_update_all(dia);
- diagram_modified(dia);
- diagram_flush(dia);
+ diagram_add_update_all (dia);
+ diagram_modified (dia);
+ diagram_flush (dia);
/* Set flag. */
change->applied = 0;
@@ -1857,7 +1860,7 @@ dia_delete_guide_change_free (DiaChange *self)
DiaChange *
-dia_delete_guide_change_new (Diagram *dia, Guide *guide, int applied)
+dia_delete_guide_change_new (Diagram *dia, DiaGuide *guide, int applied)
{
DiaDeleteGuideChange *change = dia_change_new (DIA_TYPE_DELETE_GUIDE_CHANGE);
diff --git a/app/undo.h b/app/undo.h
index caad9ec1..59e5a2d8 100644
--- a/app/undo.h
+++ b/app/undo.h
@@ -22,7 +22,7 @@
typedef struct _UndoStack UndoStack;
#include "diagram.h"
-#include "guide.h"
+#include "dia-guide.h"
#include "dia-change.h"
@@ -179,7 +179,7 @@ DiaChange *dia_mem_swap_change_new (Diagram *dia,
G_DECLARE_FINAL_TYPE (DiaMoveGuideChange, dia_move_guide_change, DIA, MOVE_GUIDE_CHANGE, DiaChange)
DiaChange *dia_move_guide_change_new (Diagram *dia,
- Guide *guide,
+ DiaGuide *guide,
real orig_pos,
real dest_pos);
@@ -188,7 +188,7 @@ DiaChange *dia_move_guide_change_new (Diagram *dia,
G_DECLARE_FINAL_TYPE (DiaAddGuideChange, dia_add_guide_change, DIA, ADD_GUIDE_CHANGE, DiaChange)
DiaChange *dia_add_guide_change_new (Diagram *dia,
- Guide *guide,
+ DiaGuide *guide,
int applied);
@@ -196,7 +196,7 @@ DiaChange *dia_add_guide_change_new (Diagram *dia,
G_DECLARE_FINAL_TYPE (DiaDeleteGuideChange, dia_delete_guide_change, DIA, DELETE_GUIDE_CHANGE, DiaChange)
DiaChange *dia_delete_guide_change_new (Diagram *dia,
- Guide *guide,
+ DiaGuide *guide,
int applied);
#endif /* UNDO_H */
diff --git a/docs/dia-app/dia-app-docs.xml b/docs/dia-app/dia-app-docs.xml
index 795b215e..3e2d48ee 100644
--- a/docs/dia-app/dia-app-docs.xml
+++ b/docs/dia-app/dia-app-docs.xml
@@ -30,7 +30,6 @@
<xi:include href="xml/commands.xml" />
<xi:include href="xml/confirm.xml" />
<xi:include href="xml/connectionpoint_ops.xml" />
- <xi:include href="xml/create_object.xml" />
<xi:include href="xml/cursor.xml" />
<xi:include href="xml/cut_n_paste.xml" />
<xi:include href="xml/defaults.xml" />
@@ -64,9 +63,7 @@
<xi:include href="xml/layer_dialog.xml" />
</chapter>
<xi:include href="xml/load_save.xml" />
- <xi:include href="xml/magnify.xml" />
<xi:include href="xml/menus.xml" />
- <xi:include href="xml/modify_tool.xml" />
<xi:include href="xml/navigation.xml" />
<xi:include href="xml/object_index.sgml" />
<xi:include href="xml/object_ops.xml" />
@@ -76,19 +73,29 @@
<xi:include href="xml/properties-dialog.xml" />
<xi:include href="xml/recent_files.xml" />
<xi:include href="xml/ruler.xml" />
- <xi:include href="xml/scroll_tool.xml" />
<xi:include href="xml/select.xml" />
+ <xi:include href="xml/dia-guide-dialog.xml" />
<xi:include href="xml/sheets_dialog_callbacks.xml" />
<xi:include href="xml/sheets_dialog.xml" />
<xi:include href="xml/sheets.xml" />
- <xi:include href="xml/textedit_tool.xml" />
<xi:include href="xml/textedit.xml" />
<xi:include href="xml/toolbox.xml" />
- <xi:include href="xml/tool.xml" />
+
+ <chapter id="tools-api">
+ <title>Tools</title>
+ <xi:include href="xml/tool.xml" />
+ <xi:include href="xml/create_object.xml" />
+ <xi:include href="xml/modify_tool.xml" />
+ <xi:include href="xml/textedit_tool.xml" />
+ <xi:include href="xml/scroll_tool.xml" />
+ <xi:include href="xml/magnify.xml" />
+ <xi:include href="xml/dia-guide-tool.xml" />
+ </chapter>
+
<chapter id="undo-api">
- <title>Undo</title>
- <xi:include href="xml/dia-change.xml" />
- <xi:include href="xml/undo.xml" />
+ <title>Undo</title>
+ <xi:include href="xml/dia-change.xml" />
+ <xi:include href="xml/undo.xml" />
</chapter>
</part>
diff --git a/docs/dia/dia-docs.xml b/docs/dia/dia-docs.xml
index 9b052a57..9b696ed8 100644
--- a/docs/dia/dia-docs.xml
+++ b/docs/dia/dia-docs.xml
@@ -83,6 +83,7 @@
<xi:include href="xml/dia_xml_libxml.xml"/>
<xi:include href="xml/orth_conn.xml"/>
<xi:include href="xml/textattr.xml"/>
+ <xi:include href="xml/dia-guide.xml"/>
<xi:include href="xml/dia_xml.xml"/>
<xi:include href="xml/diaarrowchooser.xml"/>
<xi:include href="xml/parent.xml"/>
diff --git a/lib/dia-guide.c b/lib/dia-guide.c
new file mode 100644
index 00000000..99160129
--- /dev/null
+++ b/lib/dia-guide.c
@@ -0,0 +1,58 @@
+/* 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 "dia-guide.h"
+
+G_DEFINE_BOXED_TYPE (DiaGuide, dia_guide, dia_guide_copy, dia_guide_free)
+
+
+DiaGuide *
+dia_guide_copy (DiaGuide * self)
+{
+ DiaGuide *new;
+
+
+ g_return_val_if_fail (self != NULL, NULL);
+
+ new = g_new0 (DiaGuide, 1);
+
+ new->orientation = self->orientation;
+ new->position = self->position;
+
+ return new;
+}
+
+
+void
+dia_guide_free (DiaGuide * self)
+{
+ g_free (self);
+}
+
+
+DiaGuide *
+dia_guide_new (GtkOrientation orientation,
+ double position)
+{
+ DiaGuide *self = g_new0 (DiaGuide, 1);
+
+ self->orientation = orientation;
+ self->position = position;
+
+ return self;
+}
diff --git a/lib/guide.h b/lib/dia-guide.h
similarity index 68%
rename from lib/guide.h
rename to lib/dia-guide.h
index 1be5669d..725570be 100644
--- a/lib/guide.h
+++ b/lib/dia-guide.h
@@ -15,17 +15,22 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef GUIDE_H
-#define GUIDE_H
-#include "diatypes.h"
+#pragma once
+
#include <gtk/gtk.h>
-typedef struct _Guide Guide;
+#define DIA_TYPE_GUIDE (dia_guide_get_type ())
+
+typedef struct _DiaGuide DiaGuide;
-struct _Guide {
- real position;
+struct _DiaGuide {
+ double position;
GtkOrientation orientation;
};
-#endif /* GUIDE_H */
+DiaGuide *dia_guide_copy (DiaGuide *self);
+void dia_guide_free (DiaGuide *self);
+DiaGuide *dia_guide_new (GtkOrientation orientation,
+ double position);
+GType dia_guide_get_type (void);
diff --git a/lib/meson.build b/lib/meson.build
index 19519980..c8d53c87 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -136,8 +136,8 @@ libdia_sources = stdprop_sources + [
'dia_svg.c',
'autoroute.c',
'parent.c',
- 'guide.c',
- 'guide.h',
+ 'dia-guide.c',
+ 'dia-guide.h',
'diaarrowchooser.c',
'diaarrowselector.c',
'diacolorselector.c',
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c400e85b..123526dc 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -13,6 +13,7 @@ app/diapagelayout.c
app/dia-colour-area.c
app/dia-line-width-area.c
app/dia-props.c
+app/dia-guide-dialog.c
app/disp_callbacks.c
app/display.c
app/exit_dialog.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]