1 /* abstract base class for things which are loaded or saved from files
2  */
3 
4 /*
5 
6     Copyright (C) 1991-2003 The National Gallery
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License along
19     with this program; if not, write to the Free Software Foundation, Inc.,
20     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 
22  */
23 
24 /*
25 
26     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
27 
28  */
29 
30 #define FILEMODEL_LOAD_STATE( obj ) ((FilemodelLoadState *) obj)
31 
32 #define TYPE_FILEMODEL (filemodel_get_type())
33 #define FILEMODEL( obj ) \
34 	(G_TYPE_CHECK_INSTANCE_CAST( (obj), TYPE_FILEMODEL, Filemodel ))
35 #define FILEMODEL_CLASS( klass ) \
36 	(G_TYPE_CHECK_CLASS_CAST( (klass), TYPE_FILEMODEL, FilemodelClass))
37 #define IS_FILEMODEL( obj ) \
38 	(G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_FILEMODEL ))
39 #define IS_FILEMODEL_CLASS( klass ) \
40 	(G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_FILEMODEL ))
41 #define FILEMODEL_GET_CLASS( obj ) \
42 	(G_TYPE_INSTANCE_GET_CLASS( (obj), TYPE_FILEMODEL, FilemodelClass ))
43 
44 struct _Filemodel {
45 	Model model;
46 
47         char *filename;         /* File we read this thing from */
48 	gboolean modified;	/* Set if modified (and should be saved) */
49 	gboolean registered;	/* Set if on list of things to save on quit */
50 	gboolean auto_load;	/* TRUE if loaded from path_start */
51 
52 	int x_off, y_off;	/* Save offset for things below this */
53 
54 	/* When we loaded this filemodel, the version numbers we saw in the
55 	 * XML file.
56 	 */
57 	gboolean versioned;	/* Set means from a versioned file */
58 	int major;
59 	int minor;
60 	int micro;
61 
62 	iWindow *window_hint;	/* Our views set this as a hint */
63 };
64 
65 typedef struct _FilemodelClass {
66 	ModelClass parent_class;
67 
68 	/*
69 
70 		top_load	top level load function ... controls how the
71 				rest of the load happens ... eg. merge,
72 				rename, etc.
73 
74 		set_modified	set/clear the modified state
75 
76 		top_save	top level save ... intercept this to override
77 
78 	 */
79 
80 	gboolean (*top_load)( Filemodel *filemodel,
81 		ModelLoadState *state, Model *parent, xmlNode *xnode );
82 	void (*set_modified)( Filemodel *filemodel, gboolean modified );
83 	gboolean (*top_save)( Filemodel *filemodel, const char *filename );
84 
85 	FileselFileType **filetype;
86 	const char *filetype_pref;
87 } FilemodelClass;
88 
89 void filemodel_register( Filemodel *filemodel );
90 void filemodel_unregister( Filemodel *filemodel );
91 
92 void *filemodel_top_load( Filemodel *filemodel,
93 	ModelLoadState *state, Model *parent, xmlNode *xnode );
94 
95 void filemodel_set_filename( Filemodel *filemodel, const char *filename );
96 void filemodel_set_modified( Filemodel *filemodel, gboolean state );
97 void filemodel_set_window_hint( Filemodel *filemodel, iWindow *iwnd );
98 iWindow *filemodel_get_window_hint( Filemodel *filemodel );
99 
100 GType filemodel_get_type( void );
101 
102 void filemodel_set_offset( Filemodel *filemodel, int x_off, int y_off );
103 gboolean filemodel_top_save( Filemodel *filemodel, const char *filename );
104 gboolean filemodel_load_all( Filemodel *filemodel, Model *parent,
105 	const char *filename, const char *filename_user );
106 gboolean filemodel_load_all_openfile( Filemodel *filemodel,
107 	Model *parent, iOpenFile *of );
108 
109 void filemodel_inter_saveas( iWindow *parent, Filemodel *filemodel );
110 void filemodel_inter_save( iWindow *parent, Filemodel *filemodel );
111 void filemodel_inter_savenempty_cb( iWindow *iwnd, void *client,
112 	iWindowNotifyFn nfn, void *sys );
113 void filemodel_inter_savenempty( iWindow *parent, Filemodel *filemodel );
114 void filemodel_inter_savenclose_cb( iWindow *iwnd, void *client,
115 	iWindowNotifyFn nfn, void *sys );
116 void filemodel_inter_savenclose( iWindow *parent, Filemodel *filemodel );
117 void filemodel_inter_loadas( iWindow *parent, Filemodel *filemodel );
118 void filemodel_inter_replace( iWindow *parent, Filemodel *filemodel );
119 
120 void filemodel_inter_close_registered_cb( iWindow *iwnd, void *client,
121 	iWindowNotifyFn nfn, void *sys );
122 
123 void filemodel_set_auto_load( Filemodel *filemodel );
124