Commit b083ef1f authored by Hans Breuer's avatar Hans Breuer Committed by Hans Breuer

new database table relation shapes by Petr Novotnik - bug #397688 -

2007-10-20  Hans Breuer  <hans@breuer.org>

	* configure.in lib/libdia.def objects/Database 
	  objects/Database/compound.c objects/Database/database.c
	  objects/Database/database.h objects/Database/Makefile.am
	  objects/Database/pixmaps/compound.xpm
	  objects/Database/pixmaps/reference.xpm
	  objects/Database/pixmaps/table.xpm
	  objects/Database/reference.c objects/Database/table.c
	  objects/Database/table_dialog.c objects/Makefile.am
	  objects/makefile.msc po/POTFILES.in sheets/Database.sheet.in
	  sheets/Makefile.am : new database table relation shapes by
	Petr Novotnik - bug #397688 - slightly modified to work with current
	SVN and build on windoze. Although derived from the UML class object
	the 'Table' object looks like a much better playground for a generic
	property list widget.

	* app/textedit.c(textedit_activate_first) had an endless loop when
	none of the selected objects are text editable
	
	* app/properties.c : resets current_obj when the dialog is closed
	(Sameer D. Sahasrabuddhe, fixes bug #30430)

	* objects/Misc/tree.c : added object_apply_props stuff


svn path=/trunk/; revision=3822
parent 72dbd2e8
2007-10-20 Hans Breuer <hans@breuer.org>
* configure.in lib/libdia.def objects/Database
objects/Database/compound.c objects/Database/database.c
objects/Database/database.h objects/Database/Makefile.am
objects/Database/pixmaps/compound.xpm
objects/Database/pixmaps/reference.xpm
objects/Database/pixmaps/table.xpm
objects/Database/reference.c objects/Database/table.c
objects/Database/table_dialog.c objects/Makefile.am
objects/makefile.msc po/POTFILES.in sheets/Database.sheet.in
sheets/Makefile.am : new database table relation shapes by
Petr Novotnik - bug #397688 - slightly modified to work with current
SVN and build on windoze. Although derived from the UML class object
the 'Table' object looks like a much better playground for a generic
property list widget.
* app/textedit.c(textedit_activate_first) had an endless loop when
none of the selected objects are text editable
* app/properties.c : resets current_obj when the dialog is closed
(Sameer D. Sahasrabuddhe, fixes bug #30430)
* objects/Misc/tree.c : added object_apply_props stuff
* app/properties.c lib/group.c lib/newgroup.c lib/objchange.h
lib/object.h lib/propobject.c objects/AADL/aadlbox.c
objects/AADL/aadlbus.c objects/AADL/aadldata.c
......
......@@ -45,6 +45,7 @@ static gint properties_respond(GtkWidget *widget,
static gboolean properties_key_event(GtkWidget *widget,
GdkEventKey *event,
gpointer data);
static void properties_dialog_hide();
static void create_dialog()
{
......@@ -69,7 +70,7 @@ static void create_dialog()
g_signal_connect(G_OBJECT (dialog), "response",
G_CALLBACK (properties_respond), NULL);
g_signal_connect(G_OBJECT (dialog), "delete_event",
G_CALLBACK(gtk_widget_hide), NULL);
G_CALLBACK(properties_dialog_hide), NULL);
g_signal_connect(G_OBJECT (dialog), "destroy",
G_CALLBACK(gtk_widget_destroyed), &dialog);
g_signal_connect(G_OBJECT (dialog), "destroy",
......@@ -158,8 +159,9 @@ properties_respond(GtkWidget *widget,
}
}
if (response_id != GTK_RESPONSE_APPLY)
gtk_widget_hide(widget);
if (response_id != GTK_RESPONSE_APPLY) {
properties_dialog_hide();
}
return 0;
}
......@@ -192,7 +194,7 @@ properties_show(Diagram *dia, DiaObject *obj)
if (obj==NULL) {
/* Hide dialog when no object is selected */
gtk_widget_hide(dialog);
properties_dialog_hide();
return;
}
......@@ -242,6 +244,13 @@ properties_show(Diagram *dia, DiaObject *obj)
current_dia = dia;
}
void properties_dialog_hide()
{
if (dialog)
gtk_widget_hide(dialog);
current_obj = NULL;
}
void
properties_hide_if_shown(Diagram *dia, DiaObject *obj)
{
......
......@@ -194,16 +194,19 @@ void
textedit_activate_first(DDisplay *ddisp)
{
Focus *new_focus = NULL;
GList *selected = diagram_get_sorted_selected(ddisp->diagram);
GList *tmp, *selected = diagram_get_sorted_selected(ddisp->diagram);
if (active_focus()) {
Focus *focus = active_focus();
textedit_end_edit(ddisp, focus);
}
while (new_focus == NULL && selected != NULL) {
tmp = selected;
while (new_focus == NULL && tmp != NULL) {
DiaObject *obj = (DiaObject*) selected->data;
new_focus = focus_get_first_on_object(obj);
tmp = g_list_next(tmp);
}
g_list_free (selected);
if (new_focus != NULL) {
textedit_enter(ddisp);
give_focus(new_focus);
......
......@@ -508,6 +508,7 @@ objects/SADT/Makefile
objects/SISSI/Makefile
objects/standard/Makefile
objects/UML/Makefile
objects/Database/Makefile
shapes/Makefile
shapes/Assorted/Makefile
shapes/BPMN/Makefile
......
......@@ -682,3 +682,8 @@ EXPORTS
xmlDiaParseFile
xmlDiaSaveFile
xmlDoParseFile
prop_get_data_from_widgets
prop_dialog_from_widget
find_prop_by_name
dia_object_get_enclosing_box
## Process this file with automake to produce Makefile.in
pkglib_LTLIBRARIES = libdb_objects.la
libdb_objects_la_SOURCES = \
database.c \
table.c \
table_dialog.c \
reference.c \
compound.c
libdb_objects_la_LDFLAGS = -export-dynamic -module -avoid-version
INCLUDES = -I$(top_srcdir)/intl -I$(srcdir)/../../lib $(GTK_CFLAGS) $(GNOME_CFLAGS) $(PANGOFT2_CFLAGS) $(UNICODE_CFLAGS)
EXTRA_DIST = \
pixmaps/table.xpm \
pixmaps/reference.xpm \
pixmaps/compound.xpm
This diff is collapsed.
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "intl.h"
#include "object.h"
#include "sheet.h"
#include "plug-ins.h"
#include "intl.h"
extern DiaObjectType table_type;
extern DiaObjectType reference_type;
extern DiaObjectType compound_type;
DIA_PLUGIN_CHECK_INIT
PluginInitResult
dia_plugin_init(PluginInfo *info)
{
if (!dia_plugin_info_init(info, "ERT",
_("Entity/Relationship table diagram objects"),
NULL, NULL))
return DIA_PLUGIN_INIT_ERROR;
object_register_type(&table_type);
object_register_type(&reference_type);
object_register_type(&compound_type);
return DIA_PLUGIN_INIT_OK;
}
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef DATABASE_H
#define DATABASE_H
#include <gtk/gtk.h>
#include "widgets.h"
#include "element.h"
#include "connectionpoint.h"
#include "orth_conn.h"
#define IS_NOT_EMPTY(str) (((str) != NULL) && ((str)[0] != '\0'))
#define TABLE_CONNECTIONPOINTS 12
typedef struct _Table Table;
typedef struct _TableAttribute TableAttribute;
typedef struct _TablePropDialog TablePropDialog;
typedef struct _TableReference TableReference;
typedef struct _TableState TableState;
typedef struct _TableChange TableChange;
typedef struct _Disconnect Disconnect;
struct _Table {
Element element; /**< inheritance */
/** static connection point storage */
ConnectionPoint connections[TABLE_CONNECTIONPOINTS];
/* data */
gchar * name;
gchar * comment;
gint visible_comment;
gint tagging_comment;
gint underline_primary_key;
gint bold_primary_key;
GList * attributes; /**< the attributes of this database table */
/* fonts */
real normal_font_height;
DiaFont * normal_font;
real primary_key_font_height;
DiaFont * primary_key_font;
real name_font_height;
DiaFont * name_font;
real comment_font_height;
DiaFont * comment_font;
/* colors */
Color line_color;
Color fill_color;
Color text_color;
real border_width;
/* computed variables */
gboolean destroyed;
real namebox_height;
real attributesbox_height;
real maxwidth_attr_name;
/* the property dialog pointer */
TablePropDialog * prop_dialog;
};
struct _TableAttribute {
gchar * name; /* column name */
gchar * type; /* the type of the values in this column */
gchar * comment;
gint primary_key;
gint nullable;
gint unique;
ConnectionPoint * left_connection;
ConnectionPoint * right_connection;
};
struct _Disconnect {
ConnectionPoint *cp;
DiaObject *other_object;
Handle *other_handle;
};
struct _TableState {
gchar * name;
gchar * comment;
gint visible_comment;
gint tagging_comment;
gint underline_primary_key;
gint bold_primary_key;
real border_width;
GList * attributes;
};
struct _TableChange {
ObjectChange obj_change;
Table * obj;
GList * added_cp;
GList * deleted_cp;
GList * disconnected;
gint applied;
TableState * saved_state;
};
struct _TablePropDialog {
GtkWidget * dialog;
/* general page */
GtkEntry * table_name;
GtkTextView * table_comment;
GtkToggleButton * comment_visible;
GtkToggleButton * comment_tagging;
GtkToggleButton * underline_primary_key;
GtkToggleButton * bold_primary_key;
DiaColorSelector * text_color;
DiaColorSelector * line_color;
DiaColorSelector * fill_color;
DiaFontSelector *normal_font;
GtkSpinButton *normal_font_height;
DiaFontSelector *name_font;
GtkSpinButton *name_font_height;
DiaFontSelector *comment_font;
GtkSpinButton *comment_font_height;
GtkSpinButton * border_width;
/* attributes page */
GtkList * attributes_list;
GtkEntry * attribute_name;
GtkEntry * attribute_type;
GtkTextView * attribute_comment;
GtkToggleButton * attribute_primary_key;
GtkToggleButton * attribute_nullable;
GtkToggleButton * attribute_unique;
GtkListItem * cur_attr_list_item;
GList * added_connections;
GList * deleted_connections;
GList * disconnected_connections;
};
struct _TableReference {
OrthConn orth; /* inheritance */
real line_width;
real dashlength;
LineStyle line_style;
Color line_color;
Color text_color;
gchar * start_point_desc;
gchar * end_point_desc;
Arrow end_arrow;
real corner_radius;
DiaFont * normal_font;
real normal_font_height;
/* computed data */
real sp_desc_width; /* start-point */
Point sp_desc_pos; /* start-point */
Alignment sp_desc_text_align; /* start-point */
real ep_desc_width; /* end-point */
Point ep_desc_pos; /* end-point */
Alignment ep_desc_text_align; /* end-point */
};
/* in table_dialog.c */
extern GtkWidget * table_get_properties_dialog (Table *, gboolean);
/* in table_dialog.c */
extern ObjectChange * table_dialog_apply_changes (Table *, GtkWidget *);
/* in table.c */
extern TableAttribute * table_attribute_new (void);
/* in table.c */
extern void table_attribute_free (TableAttribute *);
/* in table.c */
extern TableAttribute * table_attribute_copy (TableAttribute *);
/* in table.c */
extern void table_attribute_ensure_connection_points (TableAttribute *,
DiaObject *);
/* in table.c */
extern void table_update_connectionpoints (Table *);
/* in table.c */
extern void table_update_positions (Table *);
/* in table.c */
extern void table_compute_width_height (Table *);
/* in table_dialog.c */
extern TableState * table_state_new (Table *);
/* in table_dialog.c */
extern TableChange * table_change_new (Table *, TableState *,
GList *, GList *, GList *);
/* in table.c */
extern void table_update_primary_key_font (Table *);
#endif /* DATABASE_H */
/* XPM */
static char * compound_xpm[] = {
"22 22 2 1",
" c None",
". c #000000",
" ",
" ",
" ",
" ",
" ",
" ... ",
" ... ",
" ... ",
" ... ",
" ... ",
" ... ",
" .............. ",
" ... ",
" ... ",
" ... ",
" ... ",
" ... ",
" ... ",
" ",
" ",
" ",
" "};
/* XPM */
static char * reference_xpm[] = {
"22 22 2 1",
" c None",
". c #000000",
" ",
" . . . ",
" .. . . ",
" . . . ",
" . . . ",
" ",
" ......... ",
" . ",
" . ",
" . ",
" . ",
" . ",
" . ",
" . . . ",
" .. . . ",
" . . . ",
" . . . ",
" . ",
" .......... ",
" ",
" ",
" "};
/* XPM */
static char * table_xpm[] = {
"22 22 3 1",
" c None",
". c #000000",
"+ c #FFFFFF",
" ",
" .................. ",
" .++++++++++++++++. ",
" .++.+.+.+.+.+.+++. ",
" .+++.+++.+++.++++. ",
" .++.+.+.+.+.+.+++. ",
" .++++++++++++++++. ",
" .................. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .++++++++++++++++. ",
" .................. ",
" ",
" "};
/* Dia -- an diagram creation/manipulation program
* Copyright (C) 1998 Alexander Larsson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* File: reference.c
*
* Purpose: This file contains implementation of the database "reference"
* code.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "database.h"
#include "arrows.h"
#include "attributes.h"
#include "diarenderer.h"
#include "pixmaps/reference.xpm"
/* ------------------------------------------------------------------------ */
static DiaObject * reference_create (Point *, void *, Handle **, Handle **);
static void reference_destroy (TableReference *);
static void reference_draw (TableReference *, DiaRenderer *);
static real reference_distance_from (TableReference *, Point *);
static void reference_select (TableReference *, Point *, DiaRenderer *);
static ObjectChange * reference_move (TableReference *, Point *);
static ObjectChange * reference_move_handle (TableReference *, Handle *,
Point *, ConnectionPoint *,
HandleMoveReason,
ModifierKeys);
static PropDescription * reference_describe_props (TableReference *);
static void reference_get_props (TableReference *, GPtrArray *);
static void reference_set_props (TableReference *, GPtrArray *);
static void reference_update_data (TableReference *);
static DiaObject * reference_load (ObjectNode, int, const char *);
static void update_desc_data (Point *, Alignment *,
Point *, Point *, Orientation, real, real);
static void get_desc_bbox (Rectangle *, gchar *, real, Point *, Alignment,
DiaFont *, real);
static ObjectChange * reference_add_segment_cb(DiaObject *, Point *, gpointer);
static ObjectChange * reference_del_segment_cb(DiaObject *, Point *, gpointer);
static DiaMenu * reference_object_menu(TableReference *, Point *);
/* ------------------------------------------------------------------------ */
static ObjectTypeOps reference_type_ops =
{
(CreateFunc) reference_create,
(LoadFunc) reference_load,
(SaveFunc) object_save_using_properties,
(GetDefaultsFunc) NULL,
(ApplyDefaultsFunc) NULL
};
DiaObjectType reference_type =
{
"Database - Reference", /* name */
0, /* version */
(char **) reference_xpm, /* pixmap */
&reference_type_ops, /* ops */
NULL, /* pixmap_file */
NULL /* default_user_data */
};
static ObjectOps reference_ops = {
(DestroyFunc) reference_destroy,
(DrawFunc) reference_draw,
(DistanceFunc) reference_distance_from,
(SelectFunc) reference_select,
(CopyFunc) object_copy_using_properties,
(MoveFunc) reference_move,
(MoveHandleFunc) reference_move_handle,
(GetPropertiesFunc) object_create_props_dialog,
(ApplyPropertiesDialogFunc) object_apply_props_from_dialog,
(ObjectMenuFunc) reference_object_menu,
(DescribePropsFunc) reference_describe_props,
(GetPropsFunc) reference_get_props,
(SetPropsFunc) reference_set_props,
(TextEditFunc) 0,
(ApplyPropertiesListFunc) object_apply_props,
};
static PropNumData reference_corner_radius_data = { 0.0, 10.0, 0.1 };
static PropDescription reference_props[] =
{
ORTHCONN_COMMON_PROPERTIES,
PROP_STD_TEXT_COLOUR_OPTIONS(PROP_FLAG_VISIBLE|PROP_FLAG_STANDARD|PROP_FLAG_OPTIONAL),
PROP_STD_LINE_COLOUR_OPTIONAL,
PROP_STD_LINE_WIDTH_OPTIONAL,
PROP_STD_LINE_STYLE_OPTIONAL,
{ "corner_radius", PROP_TYPE_REAL, PROP_FLAG_VISIBLE,
N_("Corner radius"), NULL, &reference_corner_radius_data },
PROP_STD_END_ARROW,
{ "start_point_desc", PROP_TYPE_STRING, PROP_FLAG_VISIBLE,
N_("Start description"), NULL, NULL },
{ "end_point_desc", PROP_TYPE_STRING, PROP_FLAG_VISIBLE,
N_("End description"), NULL, NULL },
PROP_STD_MULTICOL_BEGIN,
PROP_MULTICOL_COLUMN("font"),
{ "normal_font", PROP_TYPE_FONT, PROP_FLAG_VISIBLE | PROP_FLAG_OPTIONAL,
N_("Font"), NULL, NULL },
PROP_MULTICOL_COLUMN("height"),
{ "normal_font_height", PROP_TYPE_REAL, PROP_FLAG_VISIBLE | PROP_FLAG_OPTIONAL,
N_(" "), NULL, NULL },
PROP_STD_MULTICOL_END,
PROP_DESC_END
};
static PropOffset reference_offsets[] =
{
ORTHCONN_COMMON_PROPERTIES_OFFSETS,
{ "text_colour", PROP_TYPE_COLOUR, offsetof(TableReference, text_color) },
{ "line_colour", PROP_TYPE_COLOUR, offsetof(TableReference, line_color) },
{ "line_width", PROP_TYPE_REAL, offsetof(TableReference, line_width) },
{ "line_style", PROP_TYPE_LINESTYLE, offsetof(TableReference, line_style),
offsetof(TableReference, dashlength) },
{ "end_arrow", PROP_TYPE_ARROW, offsetof(TableReference, end_arrow) },
{ "corner_radius", PROP_TYPE_REAL, offsetof(TableReference, corner_radius) },
{ "normal_font", PROP_TYPE_FONT, offsetof(TableReference, normal_font) },
{ "normal_font_height", PROP_TYPE_REAL, offsetof(TableReference, normal_font_height) },
{ "start_point_desc", PROP_TYPE_STRING, offsetof(TableReference, start_point_desc) },
{ "end_point_desc", PROP_TYPE_STRING, offsetof(TableReference, end_point_desc) },
{ NULL, 0, 0 }
};
static DiaMenuItem reference_menu_items[] =
{
{ N_("Add segment"), reference_add_segment_cb, NULL, DIAMENU_ACTIVE },
{ N_("Delete segement"), reference_del_segment_cb, NULL, DIAMENU_ACTIVE },
ORTHCONN_COMMON_MENUS
};
static DiaMenu reference_menu =
{
N_("Reference"),
sizeof (reference_menu_items) / sizeof (DiaMenuItem),
reference_menu_items,
NULL
};
/* ------------------------------------------------------------------------ */
static DiaObject *
reference_create (Point *startpoint,
void *user_data,
Handle **handle1,
Handle **handle2)
{
TableReference * ref;
OrthConn * orth;
DiaObject * obj;
ref = g_new0 (TableReference, 1);
orth = &ref->orth;
obj = &orth->object;
obj->type = &reference_type;
obj->ops = &reference_ops;
orthconn_init (orth, startpoint);
ref->normal_font =
dia_font_new_from_style(DIA_FONT_MONOSPACE, 0.6);
ref->normal_font_height = 0.6;
ref->line_width = attributes_get_default_linewidth ();
attributes_get_default_line_style (&ref->line_style, &ref->dashlength);
ref->text_color = color_black;
ref->line_color = attributes_get_foreground ();
ref->end_arrow = attributes_get_default_end_arrow ();
ref->corner_radius = 0.0;
ref->start_point_desc = g_strdup ("1");
ref->end_point_desc = g_strdup ("n");
*handle1 = orth->handles[0];
*handle2 = orth->handles[orth->numpoints-2];
reference_update_data (ref);
return &ref->orth.object;
}
static void
reference_destroy (TableReference * ref)
{
orthconn_destroy (&ref->orth);
g_free (ref->start_point_desc);
g_free (ref->end_point_desc);
}
static DiaObject *
reference_load (ObjectNode obj_node, int version, const char *filename)
{
DiaObject * obj = object_load_using_properties (&reference_type,
obj_node, version, filename);
return obj;
}
static void
reference_draw (TableReference *ref, DiaRenderer *renderer)
{
DiaRendererClass * renderer_ops = DIA_RENDERER_GET_CLASS (renderer);
OrthConn * orth = &ref->orth;
Point * points;
gint num_points;
points = &orth->points[0];
num_points = orth->numpoints;
renderer_ops->set_linewidth (renderer, ref->line_width);
renderer_ops->set_linestyle (renderer, ref->line_style);
renderer_ops->set_dashlength (renderer, ref->dashlength);
renderer_ops->set_linejoin (renderer, LINEJOIN_MITER);
renderer_ops->set_linecaps (renderer, LINECAPS_BUTT);
renderer_ops->draw_rounded_polyline_with_arrows
(renderer, points, num_points, ref->line_width,