Rename LdDocument* to LdDiagram*.
My bad; this name is much more appropriate.
This commit is contained in:
		
							
								
								
									
										124
									
								
								src/ld-canvas.c
									
									
									
									
									
								
							
							
						
						
									
										124
									
								
								src/ld-canvas.c
									
									
									
									
									
								
							@@ -14,9 +14,9 @@
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-marshal.h"
 | 
			
		||||
#include "ld-document-object.h"
 | 
			
		||||
#include "ld-document-symbol.h"
 | 
			
		||||
#include "ld-document.h"
 | 
			
		||||
#include "ld-diagram-object.h"
 | 
			
		||||
#include "ld-diagram-symbol.h"
 | 
			
		||||
#include "ld-diagram.h"
 | 
			
		||||
#include "ld-symbol.h"
 | 
			
		||||
#include "ld-library.h"
 | 
			
		||||
#include "ld-canvas.h"
 | 
			
		||||
@@ -25,9 +25,9 @@
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-canvas
 | 
			
		||||
 * @short_description: A canvas.
 | 
			
		||||
 * @see_also: #LdDocument
 | 
			
		||||
 * @see_also: #LdDiagram
 | 
			
		||||
 *
 | 
			
		||||
 * #LdCanvas is used for displaying #LdDocument objects.
 | 
			
		||||
 * #LdCanvas is used for displaying #LdDiagram objects.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/* Milimetres per inch. */
 | 
			
		||||
@@ -38,7 +38,7 @@
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * LdCanvasPrivate:
 | 
			
		||||
 * @document: A document object assigned to this canvas as a model.
 | 
			
		||||
 * @diagram: A diagram object assigned to this canvas as a model.
 | 
			
		||||
 * @library: A library object assigned to this canvas as a model.
 | 
			
		||||
 * @adjustment_h: An adjustment object for the horizontal axis, if any.
 | 
			
		||||
 * @adjustment_v: An adjustment object for the vertical axis, if any.
 | 
			
		||||
@@ -48,7 +48,7 @@
 | 
			
		||||
 */
 | 
			
		||||
struct _LdCanvasPrivate
 | 
			
		||||
{
 | 
			
		||||
	LdDocument *document;
 | 
			
		||||
	LdDiagram *diagram;
 | 
			
		||||
	LdLibrary *library;
 | 
			
		||||
 | 
			
		||||
	GtkAdjustment *adjustment_h;
 | 
			
		||||
@@ -64,7 +64,7 @@ G_DEFINE_TYPE (LdCanvas, ld_canvas, GTK_TYPE_DRAWING_AREA);
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
	PROP_0,
 | 
			
		||||
	PROP_DOCUMENT,
 | 
			
		||||
	PROP_DIAGRAM,
 | 
			
		||||
	PROP_LIBRARY
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -75,7 +75,7 @@ typedef struct _DrawData DrawData;
 | 
			
		||||
 * @self: Our #LdCanvas.
 | 
			
		||||
 * @cr: A cairo context to draw on.
 | 
			
		||||
 * @exposed_rect: The area that is to be redrawn.
 | 
			
		||||
 * @scale: Computed size of one document unit in pixels.
 | 
			
		||||
 * @scale: Computed size of one diagram unit in pixels.
 | 
			
		||||
 */
 | 
			
		||||
struct _DrawData
 | 
			
		||||
{
 | 
			
		||||
@@ -104,9 +104,9 @@ static void on_size_allocate (GtkWidget *widget, GtkAllocation *allocation,
 | 
			
		||||
static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event,
 | 
			
		||||
	gpointer user_data);
 | 
			
		||||
static void draw_grid (GtkWidget *widget, DrawData *data);
 | 
			
		||||
static void draw_document (GtkWidget *widget, DrawData *data);
 | 
			
		||||
static void draw_document_cb (gpointer link_data, DrawData *data);
 | 
			
		||||
static void draw_symbol (LdDocumentSymbol *document_symbol, DrawData *data);
 | 
			
		||||
static void draw_diagram (GtkWidget *widget, DrawData *data);
 | 
			
		||||
static void draw_diagram_cb (gpointer link_data, DrawData *data);
 | 
			
		||||
static void draw_symbol (LdDiagramSymbol *diagram_symbol, DrawData *data);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
@@ -126,14 +126,14 @@ ld_canvas_class_init (LdCanvasClass *klass)
 | 
			
		||||
	klass->set_scroll_adjustments = ld_canvas_real_set_scroll_adjustments;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdCanvas:document:
 | 
			
		||||
 * LdCanvas:diagram:
 | 
			
		||||
 *
 | 
			
		||||
 * The underlying #LdDocument object of this canvas.
 | 
			
		||||
 * The underlying #LdDiagram object of this canvas.
 | 
			
		||||
 */
 | 
			
		||||
	pspec = g_param_spec_object ("document", "Document",
 | 
			
		||||
		"The underlying document object of this canvas.",
 | 
			
		||||
		LD_TYPE_DOCUMENT, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_DOCUMENT, pspec);
 | 
			
		||||
	pspec = g_param_spec_object ("diagram", "Diagram",
 | 
			
		||||
		"The underlying diagram object of this canvas.",
 | 
			
		||||
		LD_TYPE_DIAGRAM, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_DIAGRAM, pspec);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdCanvas:library:
 | 
			
		||||
@@ -143,7 +143,7 @@ ld_canvas_class_init (LdCanvasClass *klass)
 | 
			
		||||
	pspec = g_param_spec_object ("library", "Library",
 | 
			
		||||
		"The library that this canvas retrieves symbols from.",
 | 
			
		||||
		LD_TYPE_LIBRARY, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_DOCUMENT, pspec);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_DIAGRAM, pspec);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdCanvas::set-scroll-adjustments:
 | 
			
		||||
@@ -192,8 +192,8 @@ ld_canvas_finalize (GObject *gobject)
 | 
			
		||||
 | 
			
		||||
	ld_canvas_real_set_scroll_adjustments (self, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
	if (self->priv->document)
 | 
			
		||||
		g_object_unref (self->priv->document);
 | 
			
		||||
	if (self->priv->diagram)
 | 
			
		||||
		g_object_unref (self->priv->diagram);
 | 
			
		||||
	if (self->priv->library)
 | 
			
		||||
		g_object_unref (self->priv->library);
 | 
			
		||||
 | 
			
		||||
@@ -210,8 +210,8 @@ ld_canvas_get_property (GObject *object, guint property_id,
 | 
			
		||||
	self = LD_CANVAS (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_DOCUMENT:
 | 
			
		||||
		g_value_set_object (value, ld_canvas_get_document (self));
 | 
			
		||||
	case PROP_DIAGRAM:
 | 
			
		||||
		g_value_set_object (value, ld_canvas_get_diagram (self));
 | 
			
		||||
		break;
 | 
			
		||||
	case PROP_LIBRARY:
 | 
			
		||||
		g_value_set_object (value, ld_canvas_get_library (self));
 | 
			
		||||
@@ -230,8 +230,8 @@ ld_canvas_set_property (GObject *object, guint property_id,
 | 
			
		||||
	self = LD_CANVAS (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_DOCUMENT:
 | 
			
		||||
		ld_canvas_set_document (self, LD_DOCUMENT (g_value_get_object (value)));
 | 
			
		||||
	case PROP_DIAGRAM:
 | 
			
		||||
		ld_canvas_set_diagram (self, LD_DIAGRAM (g_value_get_object (value)));
 | 
			
		||||
		break;
 | 
			
		||||
	case PROP_LIBRARY:
 | 
			
		||||
		ld_canvas_set_library (self, LD_LIBRARY (g_value_get_object (value)));
 | 
			
		||||
@@ -375,39 +375,39 @@ ld_canvas_new (void)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_canvas_set_document:
 | 
			
		||||
 * ld_canvas_set_diagram:
 | 
			
		||||
 * @self: An #LdCanvas object.
 | 
			
		||||
 * @document: The #LdDocument to be assigned to the canvas.
 | 
			
		||||
 * @diagram: The #LdDiagram to be assigned to the canvas.
 | 
			
		||||
 *
 | 
			
		||||
 * Assign an #LdDocument object to the canvas.
 | 
			
		||||
 * Assign an #LdDiagram object to the canvas.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_canvas_set_document (LdCanvas *self, LdDocument *document)
 | 
			
		||||
ld_canvas_set_diagram (LdCanvas *self, LdDiagram *diagram)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_CANVAS (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (document));
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (diagram));
 | 
			
		||||
 | 
			
		||||
	if (self->priv->document)
 | 
			
		||||
		g_object_unref (self->priv->document);
 | 
			
		||||
	if (self->priv->diagram)
 | 
			
		||||
		g_object_unref (self->priv->diagram);
 | 
			
		||||
 | 
			
		||||
	self->priv->document = document;
 | 
			
		||||
	g_object_ref (document);
 | 
			
		||||
	self->priv->diagram = diagram;
 | 
			
		||||
	g_object_ref (diagram);
 | 
			
		||||
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "document");
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "diagram");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_canvas_get_document:
 | 
			
		||||
 * ld_canvas_get_diagram:
 | 
			
		||||
 * @self: An #LdCanvas object.
 | 
			
		||||
 *
 | 
			
		||||
 * Get the #LdDocument object assigned to this canvas.
 | 
			
		||||
 * The reference count on the document is not incremented.
 | 
			
		||||
 * Get the #LdDiagram object assigned to this canvas.
 | 
			
		||||
 * The reference count on the diagram is not incremented.
 | 
			
		||||
 */
 | 
			
		||||
LdDocument *
 | 
			
		||||
ld_canvas_get_document (LdCanvas *self)
 | 
			
		||||
LdDiagram *
 | 
			
		||||
ld_canvas_get_diagram (LdCanvas *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_CANVAS (self), NULL);
 | 
			
		||||
	return self->priv->document;
 | 
			
		||||
	return self->priv->diagram;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -484,7 +484,7 @@ ld_canvas_get_scale_in_px (LdCanvas *self)
 | 
			
		||||
 * @y: The Y coordinate to be translated.
 | 
			
		||||
 *
 | 
			
		||||
 * Translate coordinates located inside the canvas window
 | 
			
		||||
 * into document coordinates.
 | 
			
		||||
 * into diagram coordinates.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_canvas_translate_canvas_coordinates (LdCanvas *self, gdouble *x, gdouble *y)
 | 
			
		||||
@@ -497,7 +497,7 @@ ld_canvas_translate_canvas_coordinates (LdCanvas *self, gdouble *x, gdouble *y)
 | 
			
		||||
	widget = GTK_WIDGET (self);
 | 
			
		||||
	scale = ld_canvas_get_scale_in_px (self);
 | 
			
		||||
 | 
			
		||||
	/* We know document coordinates of the center of the canvas, so we may
 | 
			
		||||
	/* We know diagram coordinates of the center of the canvas, so we may
 | 
			
		||||
	 * translate the given X and Y coordinates to this center and then scale
 | 
			
		||||
	 * them by dividing them by the length of the base unit in pixels
 | 
			
		||||
	 * times zoom of the canvas.
 | 
			
		||||
@@ -507,15 +507,15 @@ ld_canvas_translate_canvas_coordinates (LdCanvas *self, gdouble *x, gdouble *y)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_canvas_translate_document_coordinates:
 | 
			
		||||
 * ld_canvas_translate_diagram_coordinates:
 | 
			
		||||
 * @self: An #LdCanvas object.
 | 
			
		||||
 * @x: The X coordinate to be translated.
 | 
			
		||||
 * @y: The Y coordinate to be translated.
 | 
			
		||||
 *
 | 
			
		||||
 * Translate document coordinates into canvas coordinates.
 | 
			
		||||
 * Translate diagram coordinates into canvas coordinates.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_canvas_translate_document_coordinates (LdCanvas *self,
 | 
			
		||||
ld_canvas_translate_diagram_coordinates (LdCanvas *self,
 | 
			
		||||
	gdouble *x, gdouble *y)
 | 
			
		||||
{
 | 
			
		||||
	GtkWidget *widget;
 | 
			
		||||
@@ -553,7 +553,7 @@ on_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 | 
			
		||||
	cairo_paint (data.cr);
 | 
			
		||||
 | 
			
		||||
	draw_grid (widget, &data);
 | 
			
		||||
	draw_document (widget, &data);
 | 
			
		||||
	draw_diagram (widget, &data);
 | 
			
		||||
 | 
			
		||||
	cairo_destroy (data.cr);
 | 
			
		||||
	return FALSE;
 | 
			
		||||
@@ -575,7 +575,7 @@ draw_grid (GtkWidget *widget, DrawData *data)
 | 
			
		||||
	ld_canvas_translate_canvas_coordinates (data->self, &x_top, &y_top);
 | 
			
		||||
	x_top = ceil (x_top);
 | 
			
		||||
	y_top = ceil (y_top);
 | 
			
		||||
	ld_canvas_translate_document_coordinates (data->self, &x_top, &y_top);
 | 
			
		||||
	ld_canvas_translate_diagram_coordinates (data->self, &x_top, &y_top);
 | 
			
		||||
 | 
			
		||||
	/* Iterate over all the points. */
 | 
			
		||||
	for     (x = x_top; x <= data->exposed_rect.x + data->exposed_rect.width;
 | 
			
		||||
@@ -592,11 +592,11 @@ draw_grid (GtkWidget *widget, DrawData *data)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
draw_document (GtkWidget *widget, DrawData *data)
 | 
			
		||||
draw_diagram (GtkWidget *widget, DrawData *data)
 | 
			
		||||
{
 | 
			
		||||
	GSList *objects;
 | 
			
		||||
 | 
			
		||||
	if (!data->self->priv->document)
 | 
			
		||||
	if (!data->self->priv->diagram)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	cairo_save (data->cr);
 | 
			
		||||
@@ -604,25 +604,25 @@ draw_document (GtkWidget *widget, DrawData *data)
 | 
			
		||||
	cairo_set_source_rgb (data->cr, 0, 0, 0);
 | 
			
		||||
	cairo_set_line_width (data->cr, 1 / data->scale);
 | 
			
		||||
 | 
			
		||||
	/* Draw objects from the document. */
 | 
			
		||||
	objects = ld_document_get_objects (data->self->priv->document);
 | 
			
		||||
	g_slist_foreach (objects, (GFunc) draw_document_cb, data);
 | 
			
		||||
	/* Draw objects from the diagram. */
 | 
			
		||||
	objects = ld_diagram_get_objects (data->self->priv->diagram);
 | 
			
		||||
	g_slist_foreach (objects, (GFunc) draw_diagram_cb, data);
 | 
			
		||||
 | 
			
		||||
	cairo_restore (data->cr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
draw_document_cb (gpointer link_data, DrawData *data)
 | 
			
		||||
draw_diagram_cb (gpointer link_data, DrawData *data)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (link_data != NULL);
 | 
			
		||||
	g_return_if_fail (data != NULL);
 | 
			
		||||
 | 
			
		||||
	if (LD_IS_DOCUMENT_SYMBOL (link_data))
 | 
			
		||||
		draw_symbol (LD_DOCUMENT_SYMBOL (link_data), data);
 | 
			
		||||
	if (LD_IS_DIAGRAM_SYMBOL (link_data))
 | 
			
		||||
		draw_symbol (LD_DIAGRAM_SYMBOL (link_data), data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
draw_symbol (LdDocumentSymbol *document_symbol, DrawData *data)
 | 
			
		||||
draw_symbol (LdDiagramSymbol *diagram_symbol, DrawData *data)
 | 
			
		||||
{
 | 
			
		||||
	LdSymbol *symbol;
 | 
			
		||||
	LdSymbolArea area;
 | 
			
		||||
@@ -631,19 +631,19 @@ draw_symbol (LdDocumentSymbol *document_symbol, DrawData *data)
 | 
			
		||||
	if (!data->self->priv->library)
 | 
			
		||||
		return;
 | 
			
		||||
	symbol = ld_library_find_symbol (data->self->priv->library,
 | 
			
		||||
		ld_document_symbol_get_class (document_symbol));
 | 
			
		||||
		ld_diagram_symbol_get_class (diagram_symbol));
 | 
			
		||||
 | 
			
		||||
	/* TODO: Resolve this better; draw a cross or whatever. */
 | 
			
		||||
	if (!symbol)
 | 
			
		||||
	{
 | 
			
		||||
		g_warning ("Cannot find symbol %s in the library.",
 | 
			
		||||
			ld_document_symbol_get_class (document_symbol));
 | 
			
		||||
			ld_diagram_symbol_get_class (diagram_symbol));
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	x = ld_document_object_get_x (LD_DOCUMENT_OBJECT (document_symbol));
 | 
			
		||||
	y = ld_document_object_get_y (LD_DOCUMENT_OBJECT (document_symbol));
 | 
			
		||||
	ld_canvas_translate_document_coordinates (data->self, &x, &y);
 | 
			
		||||
	x = ld_diagram_object_get_x (LD_DIAGRAM_OBJECT (diagram_symbol));
 | 
			
		||||
	y = ld_diagram_object_get_y (LD_DIAGRAM_OBJECT (diagram_symbol));
 | 
			
		||||
	ld_canvas_translate_diagram_coordinates (data->self, &x, &y);
 | 
			
		||||
 | 
			
		||||
	/* TODO: Rotate the space for other orientations. */
 | 
			
		||||
	cairo_save (data->cr);
 | 
			
		||||
 
 | 
			
		||||
@@ -65,14 +65,14 @@ GType ld_canvas_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
LdCanvas *ld_canvas_new (void);
 | 
			
		||||
 | 
			
		||||
void ld_canvas_set_document (LdCanvas *self, LdDocument *document);
 | 
			
		||||
LdDocument *ld_canvas_get_document (LdCanvas *self);
 | 
			
		||||
void ld_canvas_set_diagram (LdCanvas *self, LdDiagram *diagram);
 | 
			
		||||
LdDiagram *ld_canvas_get_diagram (LdCanvas *self);
 | 
			
		||||
void ld_canvas_set_library (LdCanvas *self, LdLibrary *library);
 | 
			
		||||
LdLibrary *ld_canvas_get_library (LdCanvas *self);
 | 
			
		||||
 | 
			
		||||
void ld_canvas_translate_canvas_coordinates (LdCanvas *self,
 | 
			
		||||
	gdouble *x, gdouble *y);
 | 
			
		||||
void ld_canvas_translate_document_coordinates (LdCanvas *self,
 | 
			
		||||
void ld_canvas_translate_diagram_coordinates (LdCanvas *self,
 | 
			
		||||
	gdouble *x, gdouble *y);
 | 
			
		||||
 | 
			
		||||
/* TODO: The rest of the interface. */
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										189
									
								
								src/ld-diagram-object.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										189
									
								
								src/ld-diagram-object.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,189 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-diagram-object.c
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <gtk/gtk.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-diagram-object.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-diagram-object
 | 
			
		||||
 * @short_description: A diagram object.
 | 
			
		||||
 * @see_also: #LdDiagram, #LdCanvas
 | 
			
		||||
 *
 | 
			
		||||
 * #LdDiagramObject represents an object in an #LdDiagram.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * LdDiagramObjectPrivate:
 | 
			
		||||
 * @x: The X coordinate of this object.
 | 
			
		||||
 * @y: The Y coordinate of this object.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagramObjectPrivate
 | 
			
		||||
{
 | 
			
		||||
	gdouble x;
 | 
			
		||||
	gdouble y;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_ABSTRACT_TYPE (LdDiagramObject, ld_diagram_object, G_TYPE_OBJECT);
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
	PROP_0,
 | 
			
		||||
	PROP_X,
 | 
			
		||||
	PROP_Y
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void ld_diagram_object_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec);
 | 
			
		||||
static void ld_diagram_object_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_object_class_init (LdDiagramObjectClass *klass)
 | 
			
		||||
{
 | 
			
		||||
	GObjectClass *object_class;
 | 
			
		||||
	GParamSpec *pspec;
 | 
			
		||||
 | 
			
		||||
	object_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
	object_class->get_property = ld_diagram_object_get_property;
 | 
			
		||||
	object_class->set_property = ld_diagram_object_set_property;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagramObject:x:
 | 
			
		||||
 *
 | 
			
		||||
 * The X coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
	pspec = g_param_spec_double ("x", "X",
 | 
			
		||||
		"The X coordinate of this object.",
 | 
			
		||||
		-G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_X, pspec);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagramObject:y:
 | 
			
		||||
 *
 | 
			
		||||
 * The Y coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
	pspec = g_param_spec_double ("y", "Y",
 | 
			
		||||
		"The Y coordinate of this object.",
 | 
			
		||||
		-G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_Y, pspec);
 | 
			
		||||
 | 
			
		||||
	g_type_class_add_private (klass, sizeof (LdDiagramObjectPrivate));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_object_init (LdDiagramObject *self)
 | 
			
		||||
{
 | 
			
		||||
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE
 | 
			
		||||
		(self, LD_TYPE_DIAGRAM_OBJECT, LdDiagramObjectPrivate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_object_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDiagramObject *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DIAGRAM_OBJECT (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_X:
 | 
			
		||||
		g_value_set_double (value, ld_diagram_object_get_x (self));
 | 
			
		||||
		break;
 | 
			
		||||
	case PROP_Y:
 | 
			
		||||
		g_value_set_double (value, ld_diagram_object_get_y (self));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_object_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDiagramObject *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DIAGRAM_OBJECT (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_X:
 | 
			
		||||
		ld_diagram_object_set_x (self, g_value_get_double (value));
 | 
			
		||||
		break;
 | 
			
		||||
	case PROP_Y:
 | 
			
		||||
		ld_diagram_object_set_y (self, g_value_get_double (value));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_object_get_x:
 | 
			
		||||
 * @self: An #LdDiagramObject object.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: The X coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
gdouble
 | 
			
		||||
ld_diagram_object_get_x (LdDiagramObject *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM_OBJECT (self), 0);
 | 
			
		||||
	return self->priv->x;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_object_get_y:
 | 
			
		||||
 * @self: An #LdDiagramObject object.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: The Y coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
gdouble
 | 
			
		||||
ld_diagram_object_get_y (LdDiagramObject *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM_OBJECT (self), 0);
 | 
			
		||||
	return self->priv->y;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_object_set_x:
 | 
			
		||||
 * @self: An #LdDiagramObject object.
 | 
			
		||||
 * @x: The new X coordinate.
 | 
			
		||||
 *
 | 
			
		||||
 * Set the X coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_object_set_x (LdDiagramObject *self, gdouble x)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM_OBJECT (self));
 | 
			
		||||
	self->priv->x = x;
 | 
			
		||||
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "x");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_object_set_y:
 | 
			
		||||
 * @self: An #LdDiagramObject object.
 | 
			
		||||
 * @y: The new Y coordinate.
 | 
			
		||||
 *
 | 
			
		||||
 * Set the Y coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_object_set_y (LdDiagramObject *self, gdouble y)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM_OBJECT (self));
 | 
			
		||||
	self->priv->y = y;
 | 
			
		||||
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "y");
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										65
									
								
								src/ld-diagram-object.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								src/ld-diagram-object.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,65 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-diagram-object.h
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __LD_DIAGRAM_OBJECT_H__
 | 
			
		||||
#define __LD_DIAGRAM_OBJECT_H__
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define LD_TYPE_DIAGRAM_OBJECT (ld_diagram_object_get_type ())
 | 
			
		||||
#define LD_DIAGRAM_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST \
 | 
			
		||||
	((obj), LD_TYPE_DIAGRAM_OBJECT, LdDiagramObject))
 | 
			
		||||
#define LD_DIAGRAM_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
 | 
			
		||||
	((klass), LD_TYPE_DIAGRAM_OBJECT, LdDiagramObjectClass))
 | 
			
		||||
#define LD_IS_DIAGRAM_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((obj), LD_TYPE_DIAGRAM_OBJECT))
 | 
			
		||||
#define LD_IS_DIAGRAM_OBJECT_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((klass), LD_TYPE_DIAGRAM_OBJECT))
 | 
			
		||||
#define LD_DIAGRAM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
 | 
			
		||||
	((obj), LD_DIAGRAM_OBJECT, LdDiagramObjectClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _LdDiagramObject LdDiagramObject;
 | 
			
		||||
typedef struct _LdDiagramObjectPrivate LdDiagramObjectPrivate;
 | 
			
		||||
typedef struct _LdDiagramObjectClass LdDiagramObjectClass;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagramObject:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagramObject
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObject parent_instance;
 | 
			
		||||
	LdDiagramObjectPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagramObjectClass:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagramObjectClass
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObjectClass parent_class;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GType ld_diagram_object_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
gdouble ld_diagram_object_get_x (LdDiagramObject *self);
 | 
			
		||||
gdouble ld_diagram_object_get_y (LdDiagramObject *self);
 | 
			
		||||
void ld_diagram_object_set_x (LdDiagramObject *self, gdouble x);
 | 
			
		||||
void ld_diagram_object_set_y (LdDiagramObject *self, gdouble y);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* ! __LD_DIAGRAM_OBJECT_H__ */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										109
									
								
								src/ld-diagram-symbol.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								src/ld-diagram-symbol.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,109 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-diagram-symbol.c
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <gtk/gtk.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-diagram-object.h"
 | 
			
		||||
#include "ld-diagram-symbol.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-diagram-symbol
 | 
			
		||||
 * @short_description: A symbol object.
 | 
			
		||||
 * @see_also: #LdDiagramObject
 | 
			
		||||
 *
 | 
			
		||||
 * #LdDiagramSymbol is an implementation of #LdDiagramObject.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * LdDiagramSymbolPrivate:
 | 
			
		||||
 * @klass: The class of this symbol.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagramSymbolPrivate
 | 
			
		||||
{
 | 
			
		||||
	gchar *klass;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (LdDiagramSymbol, ld_diagram_symbol, LD_TYPE_DIAGRAM_OBJECT);
 | 
			
		||||
 | 
			
		||||
static void ld_diagram_symbol_finalize (GObject *gobject);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_symbol_class_init (LdDiagramSymbolClass *klass)
 | 
			
		||||
{
 | 
			
		||||
	GObjectClass *object_class;
 | 
			
		||||
 | 
			
		||||
	object_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
	object_class->finalize = ld_diagram_symbol_finalize;
 | 
			
		||||
 | 
			
		||||
	/* TODO: A property for the class. */
 | 
			
		||||
 | 
			
		||||
	g_type_class_add_private (klass, sizeof (LdDiagramSymbolPrivate));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_symbol_init (LdDiagramSymbol *self)
 | 
			
		||||
{
 | 
			
		||||
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE
 | 
			
		||||
		(self, LD_TYPE_DIAGRAM_SYMBOL, LdDiagramSymbolPrivate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_symbol_finalize (GObject *gobject)
 | 
			
		||||
{
 | 
			
		||||
	LdDiagramSymbol *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DIAGRAM_SYMBOL (gobject);
 | 
			
		||||
 | 
			
		||||
	if (self->priv->klass)
 | 
			
		||||
		g_free (self->priv->klass);
 | 
			
		||||
 | 
			
		||||
	/* Chain up to the parent class. */
 | 
			
		||||
	G_OBJECT_CLASS (ld_diagram_symbol_parent_class)->finalize (gobject);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_symbol_new:
 | 
			
		||||
 * @klass: The class of the symbol (symbol identifier).
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: A new #LdDiagramSymbol object.
 | 
			
		||||
 */
 | 
			
		||||
LdDiagramSymbol *
 | 
			
		||||
ld_diagram_symbol_new (const gchar *klass)
 | 
			
		||||
{
 | 
			
		||||
	LdDiagramSymbol *self;
 | 
			
		||||
 | 
			
		||||
	self = g_object_new (LD_TYPE_DIAGRAM_SYMBOL, NULL);
 | 
			
		||||
	ld_diagram_symbol_set_class (self, klass);
 | 
			
		||||
	return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* TODO: gtk-doc comments. */
 | 
			
		||||
const gchar *
 | 
			
		||||
ld_diagram_symbol_get_class (LdDiagramSymbol *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM_SYMBOL (self), NULL);
 | 
			
		||||
	return self->priv->klass;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_symbol_set_class (LdDiagramSymbol *self, const gchar *klass)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM_SYMBOL (self));
 | 
			
		||||
 | 
			
		||||
	if (self->priv->klass)
 | 
			
		||||
		g_free (self->priv->klass);
 | 
			
		||||
	self->priv->klass = g_strdup (klass);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										64
									
								
								src/ld-diagram-symbol.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/ld-diagram-symbol.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-diagram-symbol.h
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __LD_DIAGRAM_SYMBOL_H__
 | 
			
		||||
#define __LD_DIAGRAM_SYMBOL_H__
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define LD_TYPE_DIAGRAM_SYMBOL (ld_diagram_symbol_get_type ())
 | 
			
		||||
#define LD_DIAGRAM_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST \
 | 
			
		||||
	((obj), LD_TYPE_DIAGRAM_SYMBOL, LdDiagramSymbol))
 | 
			
		||||
#define LD_DIAGRAM_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
 | 
			
		||||
	((klass), LD_TYPE_DIAGRAM_SYMBOL, LdDiagramSymbolClass))
 | 
			
		||||
#define LD_IS_DIAGRAM_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((obj), LD_TYPE_DIAGRAM_SYMBOL))
 | 
			
		||||
#define LD_IS_DIAGRAM_SYMBOL_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((klass), LD_TYPE_DIAGRAM_SYMBOL))
 | 
			
		||||
#define LD_DIAGRAM_SYMBOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
 | 
			
		||||
	((obj), LD_DIAGRAM_SYMBOL, LdDiagramSymbolClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _LdDiagramSymbol LdDiagramSymbol;
 | 
			
		||||
typedef struct _LdDiagramSymbolPrivate LdDiagramSymbolPrivate;
 | 
			
		||||
typedef struct _LdDiagramSymbolClass LdDiagramSymbolClass;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagramSymbol:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagramSymbol
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	LdDiagramObject parent_instance;
 | 
			
		||||
	LdDiagramSymbolPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagramSymbolClass:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagramSymbolClass
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	LdDiagramObjectClass parent_class;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GType ld_diagram_symbol_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
LdDiagramSymbol *ld_diagram_symbol_new (const gchar *klass);
 | 
			
		||||
const gchar *ld_diagram_symbol_get_class (LdDiagramSymbol *self);
 | 
			
		||||
void ld_diagram_symbol_set_class (LdDiagramSymbol *self, const gchar *klass);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* ! __LD_DIAGRAM_SYMBOL_H__ */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										455
									
								
								src/ld-diagram.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										455
									
								
								src/ld-diagram.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,455 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-diagram.c
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <gtk/gtk.h>
 | 
			
		||||
#include <json-glib/json-glib.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-diagram-object.h"
 | 
			
		||||
#include "ld-diagram.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-diagram
 | 
			
		||||
 * @short_description: A diagram object.
 | 
			
		||||
 * @see_also: #LdCanvas
 | 
			
		||||
 *
 | 
			
		||||
 * #LdDiagram is a model for storing diagrams.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * LdDiagramPrivate:
 | 
			
		||||
 * @modified: Whether the diagram has been modified.
 | 
			
		||||
 * @objects: All the objects in the diagram.
 | 
			
		||||
 * @selection: All currently selected objects.
 | 
			
		||||
 * @connections: Connections between objects.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagramPrivate
 | 
			
		||||
{
 | 
			
		||||
	gboolean modified;
 | 
			
		||||
 | 
			
		||||
	GSList *objects;
 | 
			
		||||
	GSList *selection;
 | 
			
		||||
	GSList *connections;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (LdDiagram, ld_diagram, G_TYPE_OBJECT);
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
	PROP_0,
 | 
			
		||||
	PROP_MODIFIED
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void ld_diagram_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec);
 | 
			
		||||
static void ld_diagram_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec);
 | 
			
		||||
static void ld_diagram_dispose (GObject *gobject);
 | 
			
		||||
static void ld_diagram_finalize (GObject *gobject);
 | 
			
		||||
 | 
			
		||||
static void ld_diagram_real_changed (LdDiagram *self);
 | 
			
		||||
static void ld_diagram_clear_internal (LdDiagram *self);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_class_init (LdDiagramClass *klass)
 | 
			
		||||
{
 | 
			
		||||
	GObjectClass *object_class;
 | 
			
		||||
	GParamSpec *pspec;
 | 
			
		||||
 | 
			
		||||
	object_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
	object_class->get_property = ld_diagram_get_property;
 | 
			
		||||
	object_class->set_property = ld_diagram_set_property;
 | 
			
		||||
	object_class->dispose = ld_diagram_dispose;
 | 
			
		||||
	object_class->finalize = ld_diagram_finalize;
 | 
			
		||||
 | 
			
		||||
	klass->changed = ld_diagram_real_changed;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagram:modified:
 | 
			
		||||
 *
 | 
			
		||||
 * Whether the diagram has been modified.
 | 
			
		||||
 */
 | 
			
		||||
	pspec = g_param_spec_boolean ("modified", "Modified",
 | 
			
		||||
		"Whether the diagram has been modified.",
 | 
			
		||||
		FALSE, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_MODIFIED, pspec);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagram::changed:
 | 
			
		||||
 * @diagram: The diagram object.
 | 
			
		||||
 *
 | 
			
		||||
 * Contents of the diagram have changed.
 | 
			
		||||
 */
 | 
			
		||||
	klass->changed_signal = g_signal_new
 | 
			
		||||
		("changed", G_TYPE_FROM_CLASS (klass),
 | 
			
		||||
		G_SIGNAL_RUN_LAST,
 | 
			
		||||
		G_STRUCT_OFFSET (LdDiagramClass, changed), NULL, NULL,
 | 
			
		||||
		g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 | 
			
		||||
 | 
			
		||||
	g_type_class_add_private (klass, sizeof (LdDiagramPrivate));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_init (LdDiagram *self)
 | 
			
		||||
{
 | 
			
		||||
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE
 | 
			
		||||
		(self, LD_TYPE_DIAGRAM, LdDiagramPrivate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDiagram *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DIAGRAM (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_MODIFIED:
 | 
			
		||||
		g_value_set_boolean (value, ld_diagram_get_modified (self));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDiagram *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DIAGRAM (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_MODIFIED:
 | 
			
		||||
		ld_diagram_set_modified (self, g_value_get_boolean (value));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_dispose (GObject *gobject)
 | 
			
		||||
{
 | 
			
		||||
	LdDiagram *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DIAGRAM (gobject);
 | 
			
		||||
	ld_diagram_clear_internal (self);
 | 
			
		||||
 | 
			
		||||
	/* Chain up to the parent class. */
 | 
			
		||||
	G_OBJECT_CLASS (ld_diagram_parent_class)->dispose (gobject);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_finalize (GObject *gobject)
 | 
			
		||||
{
 | 
			
		||||
	/* Chain up to the parent class. */
 | 
			
		||||
	G_OBJECT_CLASS (ld_diagram_parent_class)->finalize (gobject);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_real_changed (LdDiagram *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (self));
 | 
			
		||||
 | 
			
		||||
	ld_diagram_set_modified (self, TRUE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_new:
 | 
			
		||||
 *
 | 
			
		||||
 * Create an instance.
 | 
			
		||||
 */
 | 
			
		||||
LdDiagram *
 | 
			
		||||
ld_diagram_new (void)
 | 
			
		||||
{
 | 
			
		||||
	return g_object_new (LD_TYPE_DIAGRAM, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_clear:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 *
 | 
			
		||||
 * Clear the whole diagram with it's objects and selection.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_clear (LdDiagram *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (self));
 | 
			
		||||
 | 
			
		||||
	ld_diagram_clear_internal (self);
 | 
			
		||||
 | 
			
		||||
	g_signal_emit (self,
 | 
			
		||||
		LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * ld_diagram_clear_internal:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 *
 | 
			
		||||
 * Do the same what ld_diagram_clear() does but don't emit signals.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
ld_diagram_clear_internal (LdDiagram *self)
 | 
			
		||||
{
 | 
			
		||||
	g_slist_free (self->priv->connections);
 | 
			
		||||
	self->priv->connections = NULL;
 | 
			
		||||
 | 
			
		||||
	g_slist_foreach (self->priv->selection, (GFunc) g_object_unref, NULL);
 | 
			
		||||
	g_slist_free (self->priv->selection);
 | 
			
		||||
	self->priv->selection = NULL;
 | 
			
		||||
 | 
			
		||||
	g_slist_foreach (self->priv->objects, (GFunc) g_object_unref, NULL);
 | 
			
		||||
	g_slist_free (self->priv->objects);
 | 
			
		||||
	self->priv->objects = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_load_from_file:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 * @filename: A filename.
 | 
			
		||||
 * @error: Return location for a GError, or NULL.
 | 
			
		||||
 *
 | 
			
		||||
 * Load a file into the diagram.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: TRUE if the file could be loaded, FALSE otherwise.
 | 
			
		||||
 */
 | 
			
		||||
gboolean
 | 
			
		||||
ld_diagram_load_from_file (LdDiagram *self,
 | 
			
		||||
	const gchar *filename, GError **error)
 | 
			
		||||
{
 | 
			
		||||
	JsonParser *parser;
 | 
			
		||||
	GError *json_error;
 | 
			
		||||
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM (self), FALSE);
 | 
			
		||||
	g_return_val_if_fail (filename != NULL, FALSE);
 | 
			
		||||
 | 
			
		||||
	/* TODO: Implement loading for real. This is just a stub. */
 | 
			
		||||
	parser = json_parser_new ();
 | 
			
		||||
 | 
			
		||||
	json_error = NULL;
 | 
			
		||||
	json_parser_load_from_file (parser, filename, &json_error);
 | 
			
		||||
	if (json_error)
 | 
			
		||||
	{
 | 
			
		||||
		g_propagate_error (error, json_error);
 | 
			
		||||
		g_object_unref (parser);
 | 
			
		||||
		return FALSE;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ld_diagram_clear (self);
 | 
			
		||||
	g_object_unref (parser);
 | 
			
		||||
	return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_save_to_file:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 * @filename: A filename.
 | 
			
		||||
 * @error: Return location for a GError, or NULL.
 | 
			
		||||
 *
 | 
			
		||||
 * Save the diagram into a file.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: TRUE if the diagram could be saved, FALSE otherwise.
 | 
			
		||||
 */
 | 
			
		||||
gboolean
 | 
			
		||||
ld_diagram_save_to_file (LdDiagram *self,
 | 
			
		||||
	const gchar *filename, GError **error)
 | 
			
		||||
{
 | 
			
		||||
	JsonGenerator *generator;
 | 
			
		||||
	JsonNode *root;
 | 
			
		||||
	GError *json_error;
 | 
			
		||||
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM (self), FALSE);
 | 
			
		||||
	g_return_val_if_fail (filename != NULL, FALSE);
 | 
			
		||||
 | 
			
		||||
	/* TODO: Implement saving for real. This is just a stub. */
 | 
			
		||||
	generator = json_generator_new ();
 | 
			
		||||
	g_object_set (generator, "pretty", TRUE, NULL);
 | 
			
		||||
 | 
			
		||||
	/* XXX: json-glib dislikes empty objects. */
 | 
			
		||||
	root = json_node_new (JSON_NODE_OBJECT);
 | 
			
		||||
	json_generator_set_root (generator, root);
 | 
			
		||||
	json_node_free (root);
 | 
			
		||||
 | 
			
		||||
	json_error = NULL;
 | 
			
		||||
	json_generator_to_file (generator, filename, &json_error);
 | 
			
		||||
	if (json_error)
 | 
			
		||||
	{
 | 
			
		||||
		g_propagate_error (error, json_error);
 | 
			
		||||
		g_object_unref (generator);
 | 
			
		||||
		return FALSE;
 | 
			
		||||
	}
 | 
			
		||||
	g_object_unref (generator);
 | 
			
		||||
	return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_get_modified:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: The modification status of diagram.
 | 
			
		||||
 */
 | 
			
		||||
gboolean
 | 
			
		||||
ld_diagram_get_modified (LdDiagram *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM (self), FALSE);
 | 
			
		||||
	return self->priv->modified;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_set_modified:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 * @value: Whether the diagram has been modified.
 | 
			
		||||
 *
 | 
			
		||||
 * Set the modification status of diagram.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_set_modified (LdDiagram *self, gboolean value)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (self));
 | 
			
		||||
	self->priv->modified = value;
 | 
			
		||||
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "modified");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_get_objects:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 *
 | 
			
		||||
 * Get a list of objects in the diagram.
 | 
			
		||||
 * You mustn't make any changes to the list.
 | 
			
		||||
 */
 | 
			
		||||
GSList *
 | 
			
		||||
ld_diagram_get_objects (LdDiagram *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM (self), NULL);
 | 
			
		||||
	return self->priv->objects;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_insert_object:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 * @object: The object to be inserted.
 | 
			
		||||
 * @pos: The position at which the object is to be inserted.
 | 
			
		||||
 *       Negative values will append to the end.
 | 
			
		||||
 *
 | 
			
		||||
 * Insert an object into the diagram.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_insert_object (LdDiagram *self, LdDiagramObject *object, gint pos)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (!g_slist_find (self->priv->objects, object))
 | 
			
		||||
	{
 | 
			
		||||
		self->priv->objects =
 | 
			
		||||
			g_slist_insert (self->priv->objects, object, pos);
 | 
			
		||||
		g_object_ref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_remove_object:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 * @object: The object to be removed.
 | 
			
		||||
 *
 | 
			
		||||
 * Remove an object from the diagram.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_remove_object (LdDiagram *self, LdDiagramObject *object)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (g_slist_find (self->priv->objects, object))
 | 
			
		||||
	{
 | 
			
		||||
		ld_diagram_selection_remove (self, object);
 | 
			
		||||
 | 
			
		||||
		self->priv->objects = g_slist_remove (self->priv->objects, object);
 | 
			
		||||
		g_object_unref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_get_selection:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 *
 | 
			
		||||
 * Get a list of objects that are currently selected in the diagram.
 | 
			
		||||
 * You mustn't make any changes to the list.
 | 
			
		||||
 */
 | 
			
		||||
GSList *
 | 
			
		||||
ld_diagram_get_selection (LdDiagram *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DIAGRAM (self), NULL);
 | 
			
		||||
	return self->priv->selection;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_selection_add:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 * @object: The object to be added to the selection.
 | 
			
		||||
 * @pos: The position at which the object is to be inserted.
 | 
			
		||||
 *       Negative values will append to the end.
 | 
			
		||||
 *
 | 
			
		||||
 * Add an object to selection.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_selection_add (LdDiagram *self, LdDiagramObject *object, gint pos)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (!g_slist_find (self->priv->selection, object)
 | 
			
		||||
		&& g_slist_find (self->priv->objects, object))
 | 
			
		||||
	{
 | 
			
		||||
		self->priv->selection =
 | 
			
		||||
			g_slist_insert (self->priv->selection, object, pos);
 | 
			
		||||
		g_object_ref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_diagram_selection_remove:
 | 
			
		||||
 * @self: An #LdDiagram object.
 | 
			
		||||
 * @object: The object to be removed from the selection.
 | 
			
		||||
 *
 | 
			
		||||
 * Remove an object from the selection.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_diagram_selection_remove (LdDiagram *self, LdDiagramObject *object)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DIAGRAM_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (g_slist_find (self->priv->selection, object))
 | 
			
		||||
	{
 | 
			
		||||
		self->priv->selection = g_slist_remove (self->priv->selection, object);
 | 
			
		||||
		g_object_unref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DIAGRAM_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										94
									
								
								src/ld-diagram.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/ld-diagram.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,94 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-diagram.h
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __LD_DIAGRAM_H__
 | 
			
		||||
#define __LD_DIAGRAM_H__
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define LD_TYPE_DIAGRAM (ld_diagram_get_type ())
 | 
			
		||||
#define LD_DIAGRAM(obj) (G_TYPE_CHECK_INSTANCE_CAST \
 | 
			
		||||
	((obj), LD_TYPE_DIAGRAM, LdDiagram))
 | 
			
		||||
#define LD_DIAGRAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
 | 
			
		||||
	((klass), LD_TYPE_DIAGRAM, LdDiagramClass))
 | 
			
		||||
#define LD_IS_DIAGRAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((obj), LD_TYPE_DIAGRAM))
 | 
			
		||||
#define LD_IS_DIAGRAM_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((klass), LD_TYPE_DIAGRAM))
 | 
			
		||||
#define LD_DIAGRAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
 | 
			
		||||
	((obj), LD_DIAGRAM, LdDiagramClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _LdDiagram LdDiagram;
 | 
			
		||||
typedef struct _LdDiagramClass LdDiagramClass;
 | 
			
		||||
typedef struct _LdDiagramPrivate LdDiagramPrivate;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDiagram:
 | 
			
		||||
 *
 | 
			
		||||
 * A diagram object.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDiagram
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObject parent_instance;
 | 
			
		||||
	LdDiagramPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct _LdDiagramClass
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObjectClass parent_class;
 | 
			
		||||
 | 
			
		||||
	/* FIXME: Add a selection_changed signal? */
 | 
			
		||||
	guint changed_signal;
 | 
			
		||||
 | 
			
		||||
	void (*changed) (LdDiagram *self);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GType ld_diagram_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
LdDiagram *ld_diagram_new (void);
 | 
			
		||||
void ld_diagram_clear (LdDiagram *self);
 | 
			
		||||
gboolean ld_diagram_load_from_file (LdDiagram *self,
 | 
			
		||||
	const gchar *filename, GError **error);
 | 
			
		||||
gboolean ld_diagram_save_to_file (LdDiagram *self,
 | 
			
		||||
	const gchar *filename, GError **error);
 | 
			
		||||
 | 
			
		||||
gboolean ld_diagram_get_modified (LdDiagram *self);
 | 
			
		||||
void ld_diagram_set_modified (LdDiagram *self, gboolean value);
 | 
			
		||||
 | 
			
		||||
GSList *ld_diagram_get_objects (LdDiagram *self);
 | 
			
		||||
void ld_diagram_insert_object (LdDiagram *self,
 | 
			
		||||
	LdDiagramObject *object, gint pos);
 | 
			
		||||
void ld_diagram_remove_object (LdDiagram *self,
 | 
			
		||||
	LdDiagramObject *object);
 | 
			
		||||
 | 
			
		||||
GSList *ld_diagram_get_selection (LdDiagram *self);
 | 
			
		||||
void ld_diagram_selection_add (LdDiagram *self,
 | 
			
		||||
	LdDiagramObject *object, gint pos);
 | 
			
		||||
void ld_diagram_selection_remove (LdDiagram *self,
 | 
			
		||||
	LdDiagramObject *object);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
GSList *ld_diagram_get_connections (LdDiagram *self);
 | 
			
		||||
void ld_diagram_connection_add (LdDiagram *self,
 | 
			
		||||
	LdConnection *connection, gint pos);
 | 
			
		||||
void ld_diagram_connection_remove (LdDiagram *self,
 | 
			
		||||
	LdConnection *connection);
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* ! __LD_DIAGRAM_H__ */
 | 
			
		||||
 | 
			
		||||
@@ -1,189 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-document-object.c
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <gtk/gtk.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-document-object.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-document-object
 | 
			
		||||
 * @short_description: A document object.
 | 
			
		||||
 * @see_also: #LdDocument, #LdCanvas
 | 
			
		||||
 *
 | 
			
		||||
 * #LdDocumentObject represents an object in an #LdDocument.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * LdDocumentObjectPrivate:
 | 
			
		||||
 * @x: The X coordinate of this object.
 | 
			
		||||
 * @y: The Y coordinate of this object.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocumentObjectPrivate
 | 
			
		||||
{
 | 
			
		||||
	gdouble x;
 | 
			
		||||
	gdouble y;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_ABSTRACT_TYPE (LdDocumentObject, ld_document_object, G_TYPE_OBJECT);
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
	PROP_0,
 | 
			
		||||
	PROP_X,
 | 
			
		||||
	PROP_Y
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void ld_document_object_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec);
 | 
			
		||||
static void ld_document_object_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_object_class_init (LdDocumentObjectClass *klass)
 | 
			
		||||
{
 | 
			
		||||
	GObjectClass *object_class;
 | 
			
		||||
	GParamSpec *pspec;
 | 
			
		||||
 | 
			
		||||
	object_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
	object_class->get_property = ld_document_object_get_property;
 | 
			
		||||
	object_class->set_property = ld_document_object_set_property;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocumentObject:x:
 | 
			
		||||
 *
 | 
			
		||||
 * The X coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
	pspec = g_param_spec_double ("x", "X",
 | 
			
		||||
		"The X coordinate of this object.",
 | 
			
		||||
		-G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_X, pspec);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocumentObject:y:
 | 
			
		||||
 *
 | 
			
		||||
 * The Y coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
	pspec = g_param_spec_double ("y", "Y",
 | 
			
		||||
		"The Y coordinate of this object.",
 | 
			
		||||
		-G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_Y, pspec);
 | 
			
		||||
 | 
			
		||||
	g_type_class_add_private (klass, sizeof (LdDocumentObjectPrivate));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_object_init (LdDocumentObject *self)
 | 
			
		||||
{
 | 
			
		||||
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE
 | 
			
		||||
		(self, LD_TYPE_DOCUMENT_OBJECT, LdDocumentObjectPrivate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_object_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDocumentObject *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DOCUMENT_OBJECT (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_X:
 | 
			
		||||
		g_value_set_double (value, ld_document_object_get_x (self));
 | 
			
		||||
		break;
 | 
			
		||||
	case PROP_Y:
 | 
			
		||||
		g_value_set_double (value, ld_document_object_get_y (self));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_object_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDocumentObject *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DOCUMENT_OBJECT (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_X:
 | 
			
		||||
		ld_document_object_set_x (self, g_value_get_double (value));
 | 
			
		||||
		break;
 | 
			
		||||
	case PROP_Y:
 | 
			
		||||
		ld_document_object_set_y (self, g_value_get_double (value));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_object_get_x:
 | 
			
		||||
 * @self: An #LdDocumentObject object.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: The X coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
gdouble
 | 
			
		||||
ld_document_object_get_x (LdDocumentObject *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT_OBJECT (self), 0);
 | 
			
		||||
	return self->priv->x;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_object_get_y:
 | 
			
		||||
 * @self: An #LdDocumentObject object.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: The Y coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
gdouble
 | 
			
		||||
ld_document_object_get_y (LdDocumentObject *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT_OBJECT (self), 0);
 | 
			
		||||
	return self->priv->y;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_object_set_x:
 | 
			
		||||
 * @self: An #LdDocumentObject object.
 | 
			
		||||
 * @x: The new X coordinate.
 | 
			
		||||
 *
 | 
			
		||||
 * Set the X coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_object_set_x (LdDocumentObject *self, gdouble x)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT_OBJECT (self));
 | 
			
		||||
	self->priv->x = x;
 | 
			
		||||
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "x");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_object_set_y:
 | 
			
		||||
 * @self: An #LdDocumentObject object.
 | 
			
		||||
 * @y: The new Y coordinate.
 | 
			
		||||
 *
 | 
			
		||||
 * Set the Y coordinate of the object.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_object_set_y (LdDocumentObject *self, gdouble y)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT_OBJECT (self));
 | 
			
		||||
	self->priv->y = y;
 | 
			
		||||
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "y");
 | 
			
		||||
}
 | 
			
		||||
@@ -1,65 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-document-object.h
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __LD_DOCUMENT_OBJECT_H__
 | 
			
		||||
#define __LD_DOCUMENT_OBJECT_H__
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define LD_TYPE_DOCUMENT_OBJECT (ld_document_object_get_type ())
 | 
			
		||||
#define LD_DOCUMENT_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST \
 | 
			
		||||
	((obj), LD_TYPE_DOCUMENT_OBJECT, LdDocumentObject))
 | 
			
		||||
#define LD_DOCUMENT_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
 | 
			
		||||
	((klass), LD_TYPE_DOCUMENT_OBJECT, LdDocumentObjectClass))
 | 
			
		||||
#define LD_IS_DOCUMENT_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((obj), LD_TYPE_DOCUMENT_OBJECT))
 | 
			
		||||
#define LD_IS_DOCUMENT_OBJECT_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((klass), LD_TYPE_DOCUMENT_OBJECT))
 | 
			
		||||
#define LD_DOCUMENT_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
 | 
			
		||||
	((obj), LD_DOCUMENT_OBJECT, LdDocumentObjectClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _LdDocumentObject LdDocumentObject;
 | 
			
		||||
typedef struct _LdDocumentObjectPrivate LdDocumentObjectPrivate;
 | 
			
		||||
typedef struct _LdDocumentObjectClass LdDocumentObjectClass;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocumentObject:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocumentObject
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObject parent_instance;
 | 
			
		||||
	LdDocumentObjectPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocumentObjectClass:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocumentObjectClass
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObjectClass parent_class;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GType ld_document_object_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
gdouble ld_document_object_get_x (LdDocumentObject *self);
 | 
			
		||||
gdouble ld_document_object_get_y (LdDocumentObject *self);
 | 
			
		||||
void ld_document_object_set_x (LdDocumentObject *self, gdouble x);
 | 
			
		||||
void ld_document_object_set_y (LdDocumentObject *self, gdouble y);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* ! __LD_DOCUMENT_OBJECT_H__ */
 | 
			
		||||
 | 
			
		||||
@@ -1,108 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-document-symbol.c
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <gtk/gtk.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-document-object.h"
 | 
			
		||||
#include "ld-document-symbol.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-document-symbol
 | 
			
		||||
 * @short_description: A symbol object.
 | 
			
		||||
 * @see_also: #LdDocumentObject
 | 
			
		||||
 *
 | 
			
		||||
 * #LdDocumentSymbol is an implementation of #LdDocumentObject.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * LdDocumentSymbolPrivate:
 | 
			
		||||
 * @klass: The class of this symbol.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocumentSymbolPrivate
 | 
			
		||||
{
 | 
			
		||||
	gchar *klass;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (LdDocumentSymbol, ld_document_symbol, LD_TYPE_DOCUMENT_OBJECT);
 | 
			
		||||
 | 
			
		||||
static void ld_document_symbol_finalize (GObject *gobject);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_symbol_class_init (LdDocumentSymbolClass *klass)
 | 
			
		||||
{
 | 
			
		||||
	GObjectClass *object_class;
 | 
			
		||||
 | 
			
		||||
	object_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
	object_class->finalize = ld_document_symbol_finalize;
 | 
			
		||||
 | 
			
		||||
	/* TODO: A property for the class. */
 | 
			
		||||
 | 
			
		||||
	g_type_class_add_private (klass, sizeof (LdDocumentSymbolPrivate));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_symbol_init (LdDocumentSymbol *self)
 | 
			
		||||
{
 | 
			
		||||
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE
 | 
			
		||||
		(self, LD_TYPE_DOCUMENT_SYMBOL, LdDocumentSymbolPrivate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_symbol_finalize (GObject *gobject)
 | 
			
		||||
{
 | 
			
		||||
	LdDocumentSymbol *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DOCUMENT_SYMBOL (gobject);
 | 
			
		||||
 | 
			
		||||
	if (self->priv->klass)
 | 
			
		||||
		g_free (self->priv->klass);
 | 
			
		||||
 | 
			
		||||
	/* Chain up to the parent class. */
 | 
			
		||||
	G_OBJECT_CLASS (ld_document_symbol_parent_class)->finalize (gobject);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_symbol_new:
 | 
			
		||||
 * @klass: The class of the symbol (symbol identifier).
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: A new #LdDocumentSymbol object.
 | 
			
		||||
 */
 | 
			
		||||
LdDocumentSymbol *
 | 
			
		||||
ld_document_symbol_new (const gchar *klass)
 | 
			
		||||
{
 | 
			
		||||
	LdDocumentSymbol *self;
 | 
			
		||||
 | 
			
		||||
	self = g_object_new (LD_TYPE_DOCUMENT_SYMBOL, NULL);
 | 
			
		||||
	ld_document_symbol_set_class (self, klass);
 | 
			
		||||
	return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const gchar *
 | 
			
		||||
ld_document_symbol_get_class (LdDocumentSymbol *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT_SYMBOL (self), NULL);
 | 
			
		||||
	return self->priv->klass;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
ld_document_symbol_set_class (LdDocumentSymbol *self, const gchar *klass)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT_SYMBOL (self));
 | 
			
		||||
 | 
			
		||||
	if (self->priv->klass)
 | 
			
		||||
		g_free (self->priv->klass);
 | 
			
		||||
	self->priv->klass = g_strdup (klass);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,64 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-document-symbol.h
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __LD_DOCUMENT_SYMBOL_H__
 | 
			
		||||
#define __LD_DOCUMENT_SYMBOL_H__
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define LD_TYPE_DOCUMENT_SYMBOL (ld_document_symbol_get_type ())
 | 
			
		||||
#define LD_DOCUMENT_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST \
 | 
			
		||||
	((obj), LD_TYPE_DOCUMENT_SYMBOL, LdDocumentSymbol))
 | 
			
		||||
#define LD_DOCUMENT_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
 | 
			
		||||
	((klass), LD_TYPE_DOCUMENT_SYMBOL, LdDocumentSymbolClass))
 | 
			
		||||
#define LD_IS_DOCUMENT_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((obj), LD_TYPE_DOCUMENT_SYMBOL))
 | 
			
		||||
#define LD_IS_DOCUMENT_SYMBOL_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((klass), LD_TYPE_DOCUMENT_SYMBOL))
 | 
			
		||||
#define LD_DOCUMENT_SYMBOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
 | 
			
		||||
	((obj), LD_DOCUMENT_SYMBOL, LdDocumentSymbolClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _LdDocumentSymbol LdDocumentSymbol;
 | 
			
		||||
typedef struct _LdDocumentSymbolPrivate LdDocumentSymbolPrivate;
 | 
			
		||||
typedef struct _LdDocumentSymbolClass LdDocumentSymbolClass;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocumentSymbol:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocumentSymbol
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	LdDocumentObject parent_instance;
 | 
			
		||||
	LdDocumentSymbolPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocumentSymbolClass:
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocumentSymbolClass
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	LdDocumentObjectClass parent_class;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GType ld_document_symbol_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
LdDocumentSymbol *ld_document_symbol_new (const gchar *klass);
 | 
			
		||||
const gchar *ld_document_symbol_get_class (LdDocumentSymbol *self);
 | 
			
		||||
void ld_document_symbol_set_class (LdDocumentSymbol *self, const gchar *klass);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* ! __LD_DOCUMENT_SYMBOL_H__ */
 | 
			
		||||
 | 
			
		||||
@@ -1,455 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-document.c
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <gtk/gtk.h>
 | 
			
		||||
#include <json-glib/json-glib.h>
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-document-object.h"
 | 
			
		||||
#include "ld-document.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-document
 | 
			
		||||
 * @short_description: A document object.
 | 
			
		||||
 * @see_also: #LdCanvas
 | 
			
		||||
 *
 | 
			
		||||
 * #LdDocument is a model for storing documents.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * LdDocumentPrivate:
 | 
			
		||||
 * @modified: Whether the document has been modified.
 | 
			
		||||
 * @objects: All the objects in the document.
 | 
			
		||||
 * @selection: All currently selected objects.
 | 
			
		||||
 * @connections: Connections between objects.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocumentPrivate
 | 
			
		||||
{
 | 
			
		||||
	gboolean modified;
 | 
			
		||||
 | 
			
		||||
	GSList *objects;
 | 
			
		||||
	GSList *selection;
 | 
			
		||||
	GSList *connections;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (LdDocument, ld_document, G_TYPE_OBJECT);
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
	PROP_0,
 | 
			
		||||
	PROP_MODIFIED
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void ld_document_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec);
 | 
			
		||||
static void ld_document_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec);
 | 
			
		||||
static void ld_document_dispose (GObject *gobject);
 | 
			
		||||
static void ld_document_finalize (GObject *gobject);
 | 
			
		||||
 | 
			
		||||
static void ld_document_real_changed (LdDocument *self);
 | 
			
		||||
static void ld_document_clear_internal (LdDocument *self);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_class_init (LdDocumentClass *klass)
 | 
			
		||||
{
 | 
			
		||||
	GObjectClass *object_class;
 | 
			
		||||
	GParamSpec *pspec;
 | 
			
		||||
 | 
			
		||||
	object_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
	object_class->get_property = ld_document_get_property;
 | 
			
		||||
	object_class->set_property = ld_document_set_property;
 | 
			
		||||
	object_class->dispose = ld_document_dispose;
 | 
			
		||||
	object_class->finalize = ld_document_finalize;
 | 
			
		||||
 | 
			
		||||
	klass->changed = ld_document_real_changed;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocument:modified:
 | 
			
		||||
 *
 | 
			
		||||
 * Whether the document has been modified.
 | 
			
		||||
 */
 | 
			
		||||
	pspec = g_param_spec_boolean ("modified", "Modified",
 | 
			
		||||
		"Whether the document has been modified.",
 | 
			
		||||
		FALSE, G_PARAM_READWRITE);
 | 
			
		||||
	g_object_class_install_property (object_class, PROP_MODIFIED, pspec);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocument::changed:
 | 
			
		||||
 * @document: The document object.
 | 
			
		||||
 *
 | 
			
		||||
 * Contents of the document have changed.
 | 
			
		||||
 */
 | 
			
		||||
	klass->changed_signal = g_signal_new
 | 
			
		||||
		("changed", G_TYPE_FROM_CLASS (klass),
 | 
			
		||||
		G_SIGNAL_RUN_LAST,
 | 
			
		||||
		G_STRUCT_OFFSET (LdDocumentClass, changed), NULL, NULL,
 | 
			
		||||
		g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
 | 
			
		||||
 | 
			
		||||
	g_type_class_add_private (klass, sizeof (LdDocumentPrivate));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_init (LdDocument *self)
 | 
			
		||||
{
 | 
			
		||||
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE
 | 
			
		||||
		(self, LD_TYPE_DOCUMENT, LdDocumentPrivate);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_get_property (GObject *object, guint property_id,
 | 
			
		||||
	GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDocument *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DOCUMENT (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_MODIFIED:
 | 
			
		||||
		g_value_set_boolean (value, ld_document_get_modified (self));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_set_property (GObject *object, guint property_id,
 | 
			
		||||
	const GValue *value, GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
	LdDocument *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DOCUMENT (object);
 | 
			
		||||
	switch (property_id)
 | 
			
		||||
	{
 | 
			
		||||
	case PROP_MODIFIED:
 | 
			
		||||
		ld_document_set_modified (self, g_value_get_boolean (value));
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_dispose (GObject *gobject)
 | 
			
		||||
{
 | 
			
		||||
	LdDocument *self;
 | 
			
		||||
 | 
			
		||||
	self = LD_DOCUMENT (gobject);
 | 
			
		||||
	ld_document_clear_internal (self);
 | 
			
		||||
 | 
			
		||||
	/* Chain up to the parent class. */
 | 
			
		||||
	G_OBJECT_CLASS (ld_document_parent_class)->dispose (gobject);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_finalize (GObject *gobject)
 | 
			
		||||
{
 | 
			
		||||
	/* Chain up to the parent class. */
 | 
			
		||||
	G_OBJECT_CLASS (ld_document_parent_class)->finalize (gobject);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
ld_document_real_changed (LdDocument *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (self));
 | 
			
		||||
 | 
			
		||||
	ld_document_set_modified (self, TRUE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_new:
 | 
			
		||||
 *
 | 
			
		||||
 * Create an instance.
 | 
			
		||||
 */
 | 
			
		||||
LdDocument *
 | 
			
		||||
ld_document_new (void)
 | 
			
		||||
{
 | 
			
		||||
	return g_object_new (LD_TYPE_DOCUMENT, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_clear:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 *
 | 
			
		||||
 * Clear the whole document with it's objects and selection.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_clear (LdDocument *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (self));
 | 
			
		||||
 | 
			
		||||
	ld_document_clear_internal (self);
 | 
			
		||||
 | 
			
		||||
	g_signal_emit (self,
 | 
			
		||||
		LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * ld_document_clear_internal:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 *
 | 
			
		||||
 * Do the same what ld_document_clear() does but don't emit signals.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
ld_document_clear_internal (LdDocument *self)
 | 
			
		||||
{
 | 
			
		||||
	g_slist_free (self->priv->connections);
 | 
			
		||||
	self->priv->connections = NULL;
 | 
			
		||||
 | 
			
		||||
	g_slist_foreach (self->priv->selection, (GFunc) g_object_unref, NULL);
 | 
			
		||||
	g_slist_free (self->priv->selection);
 | 
			
		||||
	self->priv->selection = NULL;
 | 
			
		||||
 | 
			
		||||
	g_slist_foreach (self->priv->objects, (GFunc) g_object_unref, NULL);
 | 
			
		||||
	g_slist_free (self->priv->objects);
 | 
			
		||||
	self->priv->objects = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_load_from_file:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 * @filename: A filename.
 | 
			
		||||
 * @error: Return location for a GError, or NULL.
 | 
			
		||||
 *
 | 
			
		||||
 * Load a file into the document.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: TRUE if the file could be loaded, FALSE otherwise.
 | 
			
		||||
 */
 | 
			
		||||
gboolean
 | 
			
		||||
ld_document_load_from_file (LdDocument *self,
 | 
			
		||||
	const gchar *filename, GError **error)
 | 
			
		||||
{
 | 
			
		||||
	JsonParser *parser;
 | 
			
		||||
	GError *json_error;
 | 
			
		||||
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT (self), FALSE);
 | 
			
		||||
	g_return_val_if_fail (filename != NULL, FALSE);
 | 
			
		||||
 | 
			
		||||
	/* TODO: Implement loading for real. This is just a stub. */
 | 
			
		||||
	parser = json_parser_new ();
 | 
			
		||||
 | 
			
		||||
	json_error = NULL;
 | 
			
		||||
	json_parser_load_from_file (parser, filename, &json_error);
 | 
			
		||||
	if (json_error)
 | 
			
		||||
	{
 | 
			
		||||
		g_propagate_error (error, json_error);
 | 
			
		||||
		g_object_unref (parser);
 | 
			
		||||
		return FALSE;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ld_document_clear (self);
 | 
			
		||||
	g_object_unref (parser);
 | 
			
		||||
	return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_save_to_file:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 * @filename: A filename.
 | 
			
		||||
 * @error: Return location for a GError, or NULL.
 | 
			
		||||
 *
 | 
			
		||||
 * Save the document into a file.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: TRUE if the document could be saved, FALSE otherwise.
 | 
			
		||||
 */
 | 
			
		||||
gboolean
 | 
			
		||||
ld_document_save_to_file (LdDocument *self,
 | 
			
		||||
	const gchar *filename, GError **error)
 | 
			
		||||
{
 | 
			
		||||
	JsonGenerator *generator;
 | 
			
		||||
	JsonNode *root;
 | 
			
		||||
	GError *json_error;
 | 
			
		||||
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT (self), FALSE);
 | 
			
		||||
	g_return_val_if_fail (filename != NULL, FALSE);
 | 
			
		||||
 | 
			
		||||
	/* TODO: Implement saving for real. This is just a stub. */
 | 
			
		||||
	generator = json_generator_new ();
 | 
			
		||||
	g_object_set (generator, "pretty", TRUE, NULL);
 | 
			
		||||
 | 
			
		||||
	/* XXX: json-glib dislikes empty objects. */
 | 
			
		||||
	root = json_node_new (JSON_NODE_OBJECT);
 | 
			
		||||
	json_generator_set_root (generator, root);
 | 
			
		||||
	json_node_free (root);
 | 
			
		||||
 | 
			
		||||
	json_error = NULL;
 | 
			
		||||
	json_generator_to_file (generator, filename, &json_error);
 | 
			
		||||
	if (json_error)
 | 
			
		||||
	{
 | 
			
		||||
		g_propagate_error (error, json_error);
 | 
			
		||||
		g_object_unref (generator);
 | 
			
		||||
		return FALSE;
 | 
			
		||||
	}
 | 
			
		||||
	g_object_unref (generator);
 | 
			
		||||
	return TRUE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_get_modified:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 *
 | 
			
		||||
 * Return value: The modification status of document.
 | 
			
		||||
 */
 | 
			
		||||
gboolean
 | 
			
		||||
ld_document_get_modified (LdDocument *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT (self), FALSE);
 | 
			
		||||
	return self->priv->modified;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_set_modified:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 * @value: Whether the document has been modified.
 | 
			
		||||
 *
 | 
			
		||||
 * Set the modification status of document.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_set_modified (LdDocument *self, gboolean value)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (self));
 | 
			
		||||
	self->priv->modified = value;
 | 
			
		||||
 | 
			
		||||
	g_object_notify (G_OBJECT (self), "modified");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_get_objects:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 *
 | 
			
		||||
 * Get a list of objects in the document.
 | 
			
		||||
 * You mustn't make any changes to the list.
 | 
			
		||||
 */
 | 
			
		||||
GSList *
 | 
			
		||||
ld_document_get_objects (LdDocument *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT (self), NULL);
 | 
			
		||||
	return self->priv->objects;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_insert_object:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 * @object: The object to be inserted.
 | 
			
		||||
 * @pos: The position at which the object is to be inserted.
 | 
			
		||||
 *       Negative values will append to the end.
 | 
			
		||||
 *
 | 
			
		||||
 * Insert an object into the document.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_insert_object (LdDocument *self, LdDocumentObject *object, gint pos)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (!g_slist_find (self->priv->objects, object))
 | 
			
		||||
	{
 | 
			
		||||
		self->priv->objects =
 | 
			
		||||
			g_slist_insert (self->priv->objects, object, pos);
 | 
			
		||||
		g_object_ref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_remove_object:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 * @object: The object to be removed.
 | 
			
		||||
 *
 | 
			
		||||
 * Remove an object from the document.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_remove_object (LdDocument *self, LdDocumentObject *object)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (g_slist_find (self->priv->objects, object))
 | 
			
		||||
	{
 | 
			
		||||
		ld_document_selection_remove (self, object);
 | 
			
		||||
 | 
			
		||||
		self->priv->objects = g_slist_remove (self->priv->objects, object);
 | 
			
		||||
		g_object_unref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_get_selection:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 *
 | 
			
		||||
 * Get a list of objects that are currently selected in the document.
 | 
			
		||||
 * You mustn't make any changes to the list.
 | 
			
		||||
 */
 | 
			
		||||
GSList *
 | 
			
		||||
ld_document_get_selection (LdDocument *self)
 | 
			
		||||
{
 | 
			
		||||
	g_return_val_if_fail (LD_IS_DOCUMENT (self), NULL);
 | 
			
		||||
	return self->priv->selection;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_selection_add:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 * @object: The object to be added to the selection.
 | 
			
		||||
 * @pos: The position at which the object is to be inserted.
 | 
			
		||||
 *       Negative values will append to the end.
 | 
			
		||||
 *
 | 
			
		||||
 * Add an object to selection.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_selection_add (LdDocument *self, LdDocumentObject *object, gint pos)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (!g_slist_find (self->priv->selection, object)
 | 
			
		||||
		&& g_slist_find (self->priv->objects, object))
 | 
			
		||||
	{
 | 
			
		||||
		self->priv->selection =
 | 
			
		||||
			g_slist_insert (self->priv->selection, object, pos);
 | 
			
		||||
		g_object_ref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * ld_document_selection_remove:
 | 
			
		||||
 * @self: An #LdDocument object.
 | 
			
		||||
 * @object: The object to be removed from the selection.
 | 
			
		||||
 *
 | 
			
		||||
 * Remove an object from the selection.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
ld_document_selection_remove (LdDocument *self, LdDocumentObject *object)
 | 
			
		||||
{
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT (self));
 | 
			
		||||
	g_return_if_fail (LD_IS_DOCUMENT_OBJECT (object));
 | 
			
		||||
 | 
			
		||||
	if (g_slist_find (self->priv->selection, object))
 | 
			
		||||
	{
 | 
			
		||||
		self->priv->selection = g_slist_remove (self->priv->selection, object);
 | 
			
		||||
		g_object_unref (object);
 | 
			
		||||
 | 
			
		||||
		g_signal_emit (self,
 | 
			
		||||
			LD_DOCUMENT_GET_CLASS (self)->changed_signal, 0);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,94 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ld-document.h
 | 
			
		||||
 *
 | 
			
		||||
 * This file is a part of logdiag.
 | 
			
		||||
 * Copyright Přemysl Janouch 2010. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * See the file LICENSE for licensing information.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __LD_DOCUMENT_H__
 | 
			
		||||
#define __LD_DOCUMENT_H__
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define LD_TYPE_DOCUMENT (ld_document_get_type ())
 | 
			
		||||
#define LD_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST \
 | 
			
		||||
	((obj), LD_TYPE_DOCUMENT, LdDocument))
 | 
			
		||||
#define LD_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
 | 
			
		||||
	((klass), LD_TYPE_DOCUMENT, LdDocumentClass))
 | 
			
		||||
#define LD_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((obj), LD_TYPE_DOCUMENT))
 | 
			
		||||
#define LD_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \
 | 
			
		||||
	((klass), LD_TYPE_DOCUMENT))
 | 
			
		||||
#define LD_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \
 | 
			
		||||
	((obj), LD_DOCUMENT, LdDocumentClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _LdDocument LdDocument;
 | 
			
		||||
typedef struct _LdDocumentClass LdDocumentClass;
 | 
			
		||||
typedef struct _LdDocumentPrivate LdDocumentPrivate;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * LdDocument:
 | 
			
		||||
 *
 | 
			
		||||
 * A document object.
 | 
			
		||||
 */
 | 
			
		||||
struct _LdDocument
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObject parent_instance;
 | 
			
		||||
	LdDocumentPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct _LdDocumentClass
 | 
			
		||||
{
 | 
			
		||||
/*< private >*/
 | 
			
		||||
	GObjectClass parent_class;
 | 
			
		||||
 | 
			
		||||
	/* FIXME: Add a selection_changed signal? */
 | 
			
		||||
	guint changed_signal;
 | 
			
		||||
 | 
			
		||||
	void (*changed) (LdDocument *self);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GType ld_document_get_type (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
LdDocument *ld_document_new (void);
 | 
			
		||||
void ld_document_clear (LdDocument *self);
 | 
			
		||||
gboolean ld_document_load_from_file (LdDocument *self,
 | 
			
		||||
	const gchar *filename, GError **error);
 | 
			
		||||
gboolean ld_document_save_to_file (LdDocument *self,
 | 
			
		||||
	const gchar *filename, GError **error);
 | 
			
		||||
 | 
			
		||||
gboolean ld_document_get_modified (LdDocument *self);
 | 
			
		||||
void ld_document_set_modified (LdDocument *self, gboolean value);
 | 
			
		||||
 | 
			
		||||
GSList *ld_document_get_objects (LdDocument *self);
 | 
			
		||||
void ld_document_insert_object (LdDocument *self,
 | 
			
		||||
	LdDocumentObject *object, gint pos);
 | 
			
		||||
void ld_document_remove_object (LdDocument *self,
 | 
			
		||||
	LdDocumentObject *object);
 | 
			
		||||
 | 
			
		||||
GSList *ld_document_get_selection (LdDocument *self);
 | 
			
		||||
void ld_document_selection_add (LdDocument *self,
 | 
			
		||||
	LdDocumentObject *object, gint pos);
 | 
			
		||||
void ld_document_selection_remove (LdDocument *self,
 | 
			
		||||
	LdDocumentObject *object);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
GSList *ld_document_get_connections (LdDocument *self);
 | 
			
		||||
void ld_document_connection_add (LdDocument *self,
 | 
			
		||||
	LdConnection *connection, gint pos);
 | 
			
		||||
void ld_document_connection_remove (LdDocument *self,
 | 
			
		||||
	LdConnection *connection);
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif /* ! __LD_DOCUMENT_H__ */
 | 
			
		||||
 | 
			
		||||
@@ -69,9 +69,9 @@ ld_symbol_area_get_type (void)
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:ld-symbol
 | 
			
		||||
 * @short_description: A symbol.
 | 
			
		||||
 * @see_also: #LdDocument, #LdCanvas
 | 
			
		||||
 * @see_also: #LdDiagram, #LdCanvas
 | 
			
		||||
 *
 | 
			
		||||
 * #LdSymbol represents a symbol in the #LdDocument that is in turn
 | 
			
		||||
 * #LdSymbol represents a symbol in the #LdDiagram that is in turn
 | 
			
		||||
 * drawn onto the #LdCanvas.
 | 
			
		||||
 *
 | 
			
		||||
 * All implementations of this abstract class are required to use
 | 
			
		||||
 
 | 
			
		||||
@@ -18,9 +18,9 @@
 | 
			
		||||
#include "ld-symbol-category.h"
 | 
			
		||||
#include "ld-library.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-document-object.h"
 | 
			
		||||
#include "ld-document-symbol.h"
 | 
			
		||||
#include "ld-document.h"
 | 
			
		||||
#include "ld-diagram-object.h"
 | 
			
		||||
#include "ld-diagram-symbol.h"
 | 
			
		||||
#include "ld-diagram.h"
 | 
			
		||||
 | 
			
		||||
#include "ld-canvas.h"
 | 
			
		||||
 | 
			
		||||
@@ -86,7 +86,7 @@ struct _LdWindowMainPrivate
 | 
			
		||||
 | 
			
		||||
	LdLibrary *library;
 | 
			
		||||
 | 
			
		||||
	LdDocument *document;
 | 
			
		||||
	LdDiagram *diagram;
 | 
			
		||||
	gchar *filename;
 | 
			
		||||
 | 
			
		||||
	GtkWidget *canvas_window;
 | 
			
		||||
@@ -328,16 +328,16 @@ ld_window_main_init (LdWindowMain *self)
 | 
			
		||||
		priv->symbol_menu.button_release_handler);
 | 
			
		||||
 | 
			
		||||
	/* Initialize the backend. */
 | 
			
		||||
	priv->document = ld_document_new ();
 | 
			
		||||
	priv->diagram = ld_diagram_new ();
 | 
			
		||||
 | 
			
		||||
	g_signal_connect_data (priv->document, "changed",
 | 
			
		||||
	g_signal_connect_data (priv->diagram, "changed",
 | 
			
		||||
		G_CALLBACK (update_title), self,
 | 
			
		||||
		NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
 | 
			
		||||
 | 
			
		||||
	priv->library = ld_library_new ();
 | 
			
		||||
	ld_library_load (priv->library, PROJECT_SHARE_DIR "library");
 | 
			
		||||
 | 
			
		||||
	ld_canvas_set_document (priv->canvas, priv->document);
 | 
			
		||||
	ld_canvas_set_diagram (priv->canvas, priv->diagram);
 | 
			
		||||
	ld_canvas_set_library (priv->canvas, priv->library);
 | 
			
		||||
 | 
			
		||||
	load_library_toolbar (self);
 | 
			
		||||
@@ -367,7 +367,7 @@ ld_window_main_finalize (GObject *gobject)
 | 
			
		||||
	 * and gtk_object_destroy () should be used for it.
 | 
			
		||||
	 */
 | 
			
		||||
	g_object_unref (self->priv->library);
 | 
			
		||||
	g_object_unref (self->priv->document);
 | 
			
		||||
	g_object_unref (self->priv->diagram);
 | 
			
		||||
	g_object_unref (self->priv->ui_manager);
 | 
			
		||||
	g_object_unref (self->priv->action_group);
 | 
			
		||||
 | 
			
		||||
@@ -404,7 +404,7 @@ update_title (LdWindowMain *self)
 | 
			
		||||
 | 
			
		||||
	name = diagram_get_name (self);
 | 
			
		||||
	title = g_strdup_printf ("%s%s - %s",
 | 
			
		||||
		ld_document_get_modified (self->priv->document) ? "*" : "",
 | 
			
		||||
		ld_diagram_get_modified (self->priv->diagram) ? "*" : "",
 | 
			
		||||
		name, PROJECT_NAME);
 | 
			
		||||
	gtk_window_set_title (GTK_WINDOW (self), title);
 | 
			
		||||
 | 
			
		||||
@@ -808,7 +808,7 @@ diagram_get_name (LdWindowMain *self)
 | 
			
		||||
 * diagram_set_filename:
 | 
			
		||||
 * @filename: The new filename. May be NULL for a new, yet unsaved, file.
 | 
			
		||||
 *
 | 
			
		||||
 * Set the filename corresponding to the currently opened document.
 | 
			
		||||
 * Set the filename corresponding to the currently opened diagram.
 | 
			
		||||
 * The function takes ownership of the string.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
@@ -838,8 +838,8 @@ diagram_new (LdWindowMain *self)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	/* TODO: Reset canvas view to the center. */
 | 
			
		||||
	ld_document_clear (self->priv->document);
 | 
			
		||||
	ld_document_set_modified (self->priv->document, FALSE);
 | 
			
		||||
	ld_diagram_clear (self->priv->diagram);
 | 
			
		||||
	ld_diagram_set_modified (self->priv->diagram, FALSE);
 | 
			
		||||
 | 
			
		||||
	diagram_set_filename (self, NULL);
 | 
			
		||||
}
 | 
			
		||||
@@ -863,7 +863,7 @@ diagram_save (LdWindowMain *self)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	error = NULL;
 | 
			
		||||
	ld_document_save_to_file (self->priv->document,
 | 
			
		||||
	ld_diagram_save_to_file (self->priv->diagram,
 | 
			
		||||
		self->priv->filename, &error);
 | 
			
		||||
	if (error)
 | 
			
		||||
	{
 | 
			
		||||
@@ -883,7 +883,7 @@ diagram_save (LdWindowMain *self)
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		ld_document_set_modified (self->priv->document, FALSE);
 | 
			
		||||
		ld_diagram_set_modified (self->priv->diagram, FALSE);
 | 
			
		||||
		update_title (self);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -936,7 +936,7 @@ diagram_show_open_dialog (LdWindowMain *self)
 | 
			
		||||
		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
 | 
			
		||||
 | 
			
		||||
		error = NULL;
 | 
			
		||||
		ld_document_load_from_file (self->priv->document, filename, &error);
 | 
			
		||||
		ld_diagram_load_from_file (self->priv->diagram, filename, &error);
 | 
			
		||||
		if (error)
 | 
			
		||||
		{
 | 
			
		||||
			GtkWidget *message_dialog;
 | 
			
		||||
@@ -955,7 +955,7 @@ diagram_show_open_dialog (LdWindowMain *self)
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			ld_document_set_modified (self->priv->document, FALSE);
 | 
			
		||||
			ld_diagram_set_modified (self->priv->diagram, FALSE);
 | 
			
		||||
			diagram_set_filename (self, filename);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -1014,7 +1014,7 @@ may_close_diagram (LdWindowMain *self, const gchar *dialog_message)
 | 
			
		||||
	g_return_val_if_fail (LD_IS_WINDOW_MAIN (self), TRUE);
 | 
			
		||||
	g_return_val_if_fail (dialog_message != NULL, TRUE);
 | 
			
		||||
 | 
			
		||||
	if (!ld_document_get_modified (self->priv->document))
 | 
			
		||||
	if (!ld_diagram_get_modified (self->priv->diagram))
 | 
			
		||||
		return TRUE;
 | 
			
		||||
 | 
			
		||||
	name = diagram_get_name (self);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user