1 /* Dia -- an diagram creation/manipulation program -*- c -*-
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 #ifndef DIAGRAM_H
19 #define DIAGRAM_H
20 
21 #include <gtk/gtk.h>
22 
23 typedef struct _Diagram Diagram;
24 
25 #include "geometry.h"
26 #include "handle.h"
27 #include "connectionpoint.h"
28 #include "display.h"
29 #include "diagramdata.h"
30 #include "undo.h"
31 #include "filter.h"
32 #include "menus.h"
33 #include "diagrid.h"
34 
35 GType diagram_get_type (void) G_GNUC_CONST;
36 
37 #define DIA_TYPE_DIAGRAM           (diagram_get_type ())
38 #define DIA_DIAGRAM(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_DIAGRAM, Diagram))
39 #define DIA_DIAGRAM_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_DIAGRAM, DiagramClass))
40 #define DIA_IS_DIAGRAM(obj)        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_DIAGRAM))
41 #define DIA_DIAGRAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_DIAGRAM, DiagramClass))
42 
43 struct _Diagram {
44   DiagramData parent_instance;
45 
46   char *filename;
47   int unsaved;            /* True if diagram is created but not saved.*/
48   gboolean is_default;       /* True if the diagram was created as the default.*/
49   int mollified;
50   gboolean autosaved;     /* True if the diagram is autosaved since last mod */
51   char *autosavefilename;     /* Holds the name of the current autosave file
52 			       * for this diagram, or NULL.  */
53 
54   Color pagebreak_color; /*!< just to show page breaks */
55   DiaGrid     grid;      /*!< the display grid */
56 
57   /*! almost completely unused guides (load and save code is there) */
58   struct {
59     /* sorted arrays of the guides for the diagram */
60     real *hguides, *vguides;
61     guint nhguides, nvguides;
62   } guides;
63 
64   DiagramData *data;     /*! just for compatibility, now that the Diagram _is_ and not _has_ DiagramData */
65 
66   GSList *displays;       /* List of all displays showing this diagram */
67 
68   UndoStack *undo;
69 };
70 
71 typedef struct _DiagramClass {
72   DiagramDataClass parent_class;
73 
74   /* signals */
75   void (* removed)           (Diagram*);
76   void (* selection_changed) (Diagram*, int);
77 
78 } DiagramClass;
79 
80 GList *dia_open_diagrams(void); /* Read only! */
81 
82 Diagram *diagram_load(const char *filename, DiaImportFilter *ifilter);
83 int diagram_load_into (Diagram *dest, const char *filename, DiaImportFilter *ifilter);
84 Diagram *new_diagram(const char *filename); /*Note: filename is copied*/
85 /** Perform updates related to getting a new current diagram */
86 void diagram_set_current(Diagram *diagram);
87 void diagram_destroy(Diagram *dia);
88 gboolean diagram_is_modified(Diagram *dia);
89 void diagram_modified(Diagram *dia);
90 void diagram_set_modified(Diagram *dia, int modified);
91 void diagram_add_ddisplay(Diagram *dia, DDisplay *ddisp);
92 void diagram_remove_ddisplay(Diagram *dia, DDisplay *ddisp);
93 void diagram_add_object(Diagram *dia, DiaObject *obj);
94 void diagram_add_object_list(Diagram *dia, GList *list);
95 void diagram_selected_break_external(Diagram *dia);
96 void diagram_remove_all_selected(Diagram *diagram, int delete_empty);
97 void diagram_unselect_object(Diagram *dia, DiaObject *obj);
98 void diagram_unselect_objects(Diagram *dia, GList *obj_list);
99 void diagram_select(Diagram *diagram, DiaObject *obj);
100 void diagram_select_list(Diagram *diagram, GList *list);
101 int diagram_is_selected(Diagram *diagram, DiaObject *obj);
102 GList *diagram_get_sorted_selected(Diagram *dia);
103 /* Removes selected from objects list, NOT selected list: */
104 GList *diagram_get_sorted_selected_remove(Diagram *dia);
105 void diagram_add_update(Diagram *dia, Rectangle *update);
106 void diagram_add_update_with_border(Diagram *dia, Rectangle *update,
107 				    int pixel_border);
108 void diagram_add_update_all(Diagram *dia);
109 void diagram_add_update_all_all_and_flush();
110 void diagram_add_update_pixels(Diagram *dia, Point *point,
111 			       int pixel_width, int pixel_height);
112 void diagram_flush(Diagram *dia);
113 DiaObject *diagram_find_clicked_object(Diagram *dia,
114 				    Point *pos,
115 				    real maxdist);
116 DiaObject *diagram_find_clicked_object_except(Diagram *dia,
117 					   Point *pos,
118 					   real maxdist,
119 					   GList *avoid);
120 real diagram_find_closest_handle(Diagram *dia, Handle **handle,
121 				 DiaObject **obj, Point *pos);
122 real diagram_find_closest_connectionpoint(Diagram *dia,
123 					  ConnectionPoint **cp,
124 					  Point *pos,
125 					  DiaObject *notthis);
126 void diagram_update_extents(Diagram *dia);
127 
128 void diagram_update_menu_sensitivity (Diagram *dia);
129 
130 void diagram_place_under_selected(Diagram *dia);
131 void diagram_place_over_selected(Diagram *dia);
132 void diagram_place_down_selected(Diagram *dia);
133 void diagram_place_up_selected(Diagram *dia);
134 void diagram_group_selected(Diagram *dia);
135 void diagram_ungroup_selected(Diagram *dia);
136 void diagram_parent_selected(Diagram *dia);
137 void diagram_unparent_selected(Diagram *dia);
138 void diagram_unparent_children_selected(Diagram *dia);
139 
140 gboolean object_within_parent(DiaObject *obj, DiaObject *parent);
141 void diagram_set_filename(Diagram *dia, const char *filename);
142 gchar *diagram_get_name(Diagram *dia);
143 
144 int diagram_modified_exists(void);
145 
146 void diagram_redraw_all(void);
147 
148 void diagram_object_modified(Diagram *dia, DiaObject *object);
149 
150 #endif /* DIAGRAM_H */
151 
152 
153