1 /* a view of a text thingy
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 /*
31 #define DEBUG
32 */
33
34 #include "ip.h"
35
36 static GraphicviewClass *parent_class = NULL;
37
38 /* Re-read the text in a tally entry.
39 */
40 static void *
expressionview_scan(View * view)41 expressionview_scan( View *view )
42 {
43 Expressionview *expressionview = EXPRESSIONVIEW( view );
44 Expression *expression = EXPRESSION(
45 VOBJECT( expressionview )->iobject );
46 iText *itext = expression_get_itext( expression );
47
48 #ifdef DEBUG
49 {
50 Row *row = HEAPMODEL( expression )->row;
51
52 printf( "expressionview_scan: " );
53 row_name_print( row );
54 printf( "\n" );
55 }
56 #endif /*DEBUG*/
57
58 if( itext &&
59 formula_scan( expressionview->formula ) &&
60 itext_set_formula( itext, expressionview->formula->expr ) ) {
61 itext_set_edited( itext, TRUE );
62
63 /* ... make sure MEMBER_VALUE gets marked dirty too.
64 */
65 expr_dirty( HEAPMODEL( itext )->row->expr,
66 link_serial_new() );
67 }
68
69 return( VIEW_CLASS( parent_class )->scan( view ) );
70 }
71
72 void
expressionview_activate_cb(GtkWidget * wid,Expressionview * expressionview)73 expressionview_activate_cb( GtkWidget *wid, Expressionview *expressionview )
74 {
75 Expression *expression =
76 EXPRESSION( VOBJECT( expressionview )->iobject );
77 Row *row = HEAPMODEL( expression )->row;
78
79 /* Reset edits on this row and all children.
80 */
81 (void) icontainer_map_all( ICONTAINER( row ),
82 (icontainer_map_fn) heapmodel_clear_edited, NULL );
83
84 /* Make sure we scan this text, even if it's not been edited.
85 */
86 view_scannable_register( VIEW( expressionview ) );
87
88 workspace_set_modified( row->ws, TRUE );
89
90 symbol_recalculate_all();
91 }
92
93 static void
expressionview_refresh(vObject * vobject)94 expressionview_refresh( vObject *vobject )
95 {
96 Expressionview *expressionview = EXPRESSIONVIEW( vobject );
97 Expression *expression =
98 EXPRESSION( VOBJECT( expressionview )->iobject );
99 iText *itext = expression_get_itext( expression );
100 Row *row = HEAPMODEL( expression )->row;
101
102 #ifdef DEBUG
103 printf( "expressionview_refresh: " );
104 row_name_print( row );
105 printf( " (%p)\n", vobject );
106 #endif /*DEBUG*/
107
108 formula_set_edit( expressionview->formula,
109 row->ws->mode == WORKSPACE_MODE_FORMULA );
110 if( itext )
111 formula_set_value_expr( expressionview->formula,
112 vips_buf_all( &itext->value ), itext->formula );
113 if( vobject->iobject->caption )
114 formula_set_caption( expressionview->formula,
115 vobject->iobject->caption );
116
117 VOBJECT_CLASS( parent_class )->refresh( vobject );
118 }
119
120 static void
expressionview_set_edit(Expressionview * expressionview,gboolean edit)121 expressionview_set_edit( Expressionview *expressionview, gboolean edit )
122 {
123 formula_set_edit( expressionview->formula, edit );
124
125 if( edit )
126 view_resettable_register( VIEW( expressionview ) );
127 }
128
129 static void
expressionview_link(View * view,Model * model,View * parent)130 expressionview_link( View *view, Model *model, View *parent )
131 {
132 Expressionview *expressionview = EXPRESSIONVIEW( view );
133 Expression *expression = EXPRESSION( model );
134 Row *row = HEAPMODEL( expression )->row;
135
136 #ifdef DEBUG
137 printf( "expressionview_link: " );
138 row_name_print( row );
139 printf( "\n" );
140 #endif /*DEBUG*/
141
142 VIEW_CLASS( parent_class )->link( view, model, parent );
143
144 if( GRAPHICVIEW( view )->sview )
145 gtk_size_group_add_widget( GRAPHICVIEW( view )->sview->group,
146 expressionview->formula->left_label );
147
148 /* Edit mode defaults to edit mode for workspace.
149 */
150 expressionview_set_edit( expressionview,
151 row->ws->mode == WORKSPACE_MODE_FORMULA );
152 }
153
154 /* Reset edit mode ... go back to whatever is set for this ws.
155 */
156 static void
expressionview_reset(View * view)157 expressionview_reset( View *view )
158 {
159 Expressionview *expressionview = EXPRESSIONVIEW( view );
160 Expression *expression =
161 EXPRESSION( VOBJECT( expressionview )->iobject );
162 Row *row = HEAPMODEL( expression )->row;
163
164 expressionview_set_edit( expressionview,
165 row->ws->mode == WORKSPACE_MODE_FORMULA );
166 }
167
168 static void
expressionview_class_init(ExpressionviewClass * class)169 expressionview_class_init( ExpressionviewClass *class )
170 {
171 vObjectClass *vobject_class = (vObjectClass *) class;
172 ViewClass *view_class = (ViewClass *) class;
173
174 parent_class = g_type_class_peek_parent( class );
175
176 /* Create signals.
177 */
178
179 /* Init methods.
180 */
181 vobject_class->refresh = expressionview_refresh;
182
183 view_class->link = expressionview_link;
184 view_class->reset = expressionview_reset;
185 view_class->scan = expressionview_scan;
186 }
187
188 static void
expressionview_init(Expressionview * expressionview)189 expressionview_init( Expressionview *expressionview )
190 {
191 expressionview->formula = formula_new();
192 gtk_signal_connect_object( GTK_OBJECT( expressionview->formula ),
193 "changed",
194 GTK_SIGNAL_FUNC( view_changed_cb ),
195 GTK_OBJECT( expressionview ) );
196 gtk_signal_connect( GTK_OBJECT( expressionview->formula ), "activate",
197 GTK_SIGNAL_FUNC( expressionview_activate_cb ), expressionview );
198 gtk_box_pack_start( GTK_BOX( expressionview ),
199 GTK_WIDGET( expressionview->formula ), TRUE, FALSE, 0 );
200 gtk_widget_show( GTK_WIDGET( expressionview->formula ) );
201 }
202
203 GtkType
expressionview_get_type(void)204 expressionview_get_type( void )
205 {
206 static GtkType expressionview_type = 0;
207
208 if( !expressionview_type ) {
209 static const GtkTypeInfo expressionview_info = {
210 "Expressionview",
211 sizeof( Expressionview ),
212 sizeof( ExpressionviewClass ),
213 (GtkClassInitFunc) expressionview_class_init,
214 (GtkObjectInitFunc) expressionview_init,
215 /* reserved_1 */ NULL,
216 /* reserved_2 */ NULL,
217 (GtkClassInitFunc) NULL,
218 };
219
220 expressionview_type = gtk_type_unique( TYPE_GRAPHICVIEW,
221 &expressionview_info );
222 }
223
224 return( expressionview_type );
225 }
226
227 View *
expressionview_new(void)228 expressionview_new( void )
229 {
230 Expressionview *expressionview = gtk_type_new( TYPE_EXPRESSIONVIEW );
231
232 return( VIEW( expressionview ) );
233 }
234