1 /* Tools ... mostly a menu item.
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 /* Build a tree of these for each tool we make.
31  */
32 struct _Toolitem {
33 	/* The thing for which we are making an item. Eg. if the .def file
34 	 * has 'fred = class Menuitem "poop" "lots of poop" {}', this is the
35 	 * Compile for fred.
36 	 *
37 	 * compile is not always valid .. eg. for #dialog or #separator
38 	 */
39 	Compile *compile;
40 
41 	/* The top-level tool we come from.
42 	 */
43 	Tool *tool;
44 
45 	/* The symbol we perform the action with (eg. get nparam from this).
46 	 */
47 	Symbol *action_sym;
48 
49 	/* Set for a separator.
50 	 */
51 	gboolean is_separator;
52 
53 	/* Set if we decide during build that this item should be a pullright.
54 	 */
55 	gboolean is_pullright;
56 
57 	/* If this is a pullright, the children of this item. If we are a
58 	 * child, the parent.
59 	 */
60 	GSList *children;
61 	Toolitem *parent;
62 
63 	/* Set if we decide this should have an action.
64 	 */
65 	gboolean is_action;
66 
67 	char *label;		/* eg. "W_hite Balance" */
68 	char *name;		/* eg. "White Balance" */
69 	char *icon;		/* eg. "$VIPSHOME/icons/wb.png" */
70 	char *tooltip;		/* eg. "move whitepoint to region neutral" */
71 	char *help;		/* eg. "White Balance r: move ..." */
72 	char *action;		/* eg. "White_balance_widget._action" */
73 	char *path;		/* eg. "<mainw>/Toolkits/Image" */
74 	char *user_path;	/* eg. "Image / White Balance" */
75 };
76 
77 #define TYPE_TOOL (tool_get_type())
78 #define TOOL( obj ) \
79 	(G_TYPE_CHECK_INSTANCE_CAST( (obj), TYPE_TOOL, Tool ))
80 #define TOOL_CLASS( klass ) \
81 	(G_TYPE_CHECK_CLASS_CAST( (klass), TYPE_TOOL, ToolClass))
82 #define IS_TOOL( obj ) \
83 	(G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_TOOL ))
84 #define IS_TOOL_CLASS( klass ) \
85 	(G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_TOOL ))
86 #define TOOL_GET_CLASS( obj ) \
87 	(G_TYPE_INSTANCE_GET_CLASS( (obj), TYPE_TOOL, ToolClass ))
88 
89 /* Tool types: a def (sym points to symbol for this def), a dialog (keep
90  * filename and prompt name), or a separator.
91  */
92 typedef enum {
93 	TOOL_SYM,
94 	TOOL_DIA,
95 	TOOL_SEP
96 } Tooltype;
97 
98 /* What we hold for each tool.
99  */
100 struct _Tool {
101 	Filemodel parent_class;
102 
103 	Tooltype type;
104 	Symbol *sym;		/* For SYM tools: symbol this tool represents */
105 	guint new_value_sid;	/* Watch for new_value with this */
106 	Symbol *link_sym;	/* the sym we are watching (in case ->sym is
107 				   NULLed before we try to disconnect */
108 
109 	Toolkit *kit; 		/* Link back to toolkit */
110 	int lineno;		/* -1 for not known, or lineno in kit */
111 
112 	Toolitem *toolitem;	/* Items made by this tool */
113 
114 	/* The first line of the comment prior to the definition. Toolitem help
115 	 * and tooltip can be generated from the Menuitem members.
116 	 */
117 	char *help;		/* eg. "concat l: join a list of .." */
118 };
119 
120 typedef struct _ToolClass {
121 	FilemodelClass parent_class;
122 
123 	/* My methods.
124 	 */
125 } ToolClass;
126 
127 void tool_error( Tool *tool, VipsBuf *buf );
128 
129 void *tool_linkreport_tool( Tool *tool, VipsBuf *buf, gboolean *found );
130 
131 GType tool_get_type( void );
132 
133 Tool *tool_new_sym( Toolkit *kit, int pos, Symbol *sym );
134 Tool *tool_new_sep( Toolkit *kit, int pos );
135 Tool *tool_new_dia( Toolkit *kit, int pos,
136 	const char *filename, const char *name );
137 
138 Toolitem *toolitem_lookup( Toolkitgroup *kitg, Symbol *action );
139