1 /* Dia -- an diagram creation/manipulation program
2  * Copyright (C) 1998 Alexander Larsson
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef DATABASE_H
20 #define DATABASE_H
21 
22 #include <gtk/gtk.h>
23 #include "widgets.h"
24 #include "element.h"
25 #include "connectionpoint.h"
26 #include "orth_conn.h"
27 
28 #define IS_NOT_EMPTY(str) (((str) != NULL) && ((str)[0] != '\0'))
29 
30 #define TABLE_CONNECTIONPOINTS 12
31 
32 typedef struct _Table Table;
33 typedef struct _TableAttribute TableAttribute;
34 typedef struct _TablePropDialog TablePropDialog;
35 typedef struct _TableReference TableReference;
36 typedef struct _TableState TableState;
37 typedef struct _TableChange TableChange;
38 typedef struct _Disconnect Disconnect;
39 
40 struct _Table {
41   Element element; /**< inheritance */
42 
43   /** static connection point storage */
44   ConnectionPoint connections[TABLE_CONNECTIONPOINTS];
45 
46   /* data */
47 
48   gchar * name;
49   gchar * comment;
50   gint visible_comment;
51   gint tagging_comment;
52   gint underline_primary_key;
53   gint bold_primary_key;
54   GList * attributes; /**< the attributes of this database table */
55 
56   /* fonts */
57 
58   real normal_font_height;
59   DiaFont * normal_font;
60 
61   real primary_key_font_height;
62   DiaFont * primary_key_font;
63 
64   real name_font_height;
65   DiaFont * name_font;
66 
67   real comment_font_height;
68   DiaFont * comment_font;
69 
70   /* colors */
71 
72   Color line_color;
73   Color fill_color;
74   Color text_color;
75 
76   real border_width;
77 
78   /* computed variables */
79 
80   gboolean destroyed;
81 
82   real namebox_height;
83   real attributesbox_height;
84   real maxwidth_attr_name;
85 
86   /* the property dialog pointer */
87 
88   TablePropDialog * prop_dialog;
89 };
90 
91 void table_dialog_free (TablePropDialog *dialog);
92 
93 struct _TableAttribute {
94   gchar * name; /* column name */
95   gchar * type; /* the type of the values in this column */
96   gchar * comment;
97   gint primary_key;
98   gint nullable;
99   gint unique;
100 
101   ConnectionPoint * left_connection;
102   ConnectionPoint * right_connection;
103 };
104 
105 struct _Disconnect {
106   ConnectionPoint *cp;
107   DiaObject *other_object;
108   Handle *other_handle;
109 };
110 
111 struct _TableState {
112   gchar * name;
113   gchar * comment;
114   gint visible_comment;
115   gint tagging_comment;
116   gint underline_primary_key;
117   gint bold_primary_key;
118   real border_width;
119 
120   GList * attributes;
121 };
122 
123 struct _TableChange {
124   ObjectChange obj_change;
125 
126   Table * obj;
127 
128   GList * added_cp;
129   GList * deleted_cp;
130   GList * disconnected;
131 
132   gint applied;
133 
134   TableState * saved_state;
135 };
136 
137 struct _TableReference {
138   OrthConn orth; /* inheritance */
139 
140   real line_width;
141   real dashlength;
142   LineStyle line_style;
143   Color line_color;
144   Color text_color;
145 
146   gchar * start_point_desc;
147   gchar * end_point_desc;
148   Arrow end_arrow;
149   real corner_radius;
150 
151   DiaFont * normal_font;
152   real normal_font_height;
153 
154   /* computed data */
155 
156   real sp_desc_width;           /* start-point */
157   Point sp_desc_pos;            /* start-point */
158   Alignment sp_desc_text_align; /* start-point */
159   real ep_desc_width;           /* end-point */
160   Point ep_desc_pos;            /* end-point */
161   Alignment ep_desc_text_align; /* end-point */
162 };
163 
164 /* in table_dialog.c */
165 extern GtkWidget * table_get_properties_dialog (Table *, gboolean);
166 /* in table_dialog.c */
167 extern ObjectChange * table_dialog_apply_changes (Table *, GtkWidget *);
168 
169 /* in table.c */
170 extern TableAttribute * table_attribute_new (void);
171 /* in table.c */
172 extern void table_attribute_free (TableAttribute *);
173 /* in table.c */
174 extern TableAttribute * table_attribute_copy (TableAttribute *);
175 /* in table.c */
176 extern void table_attribute_ensure_connection_points (TableAttribute *,
177                                                       DiaObject *);
178 /* in table.c */
179 extern void table_update_connectionpoints (Table *);
180 /* in table.c */
181 extern void table_update_positions (Table *);
182 /* in table.c */
183 extern void table_compute_width_height (Table *);
184 /* in table_dialog.c */
185 extern TableState * table_state_new (Table *);
186 /* in table_dialog.c */
187 extern TableChange * table_change_new (Table *, TableState *,
188                                        GList *, GList *, GList *);
189 /* in table.c */
190 extern void table_update_primary_key_font (Table *);
191 
192 #endif /* DATABASE_H */
193