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 EditviewClass *parent_class = NULL;
37 
38 /* Re-read the text in a tally entry.
39  */
40 static void *
stringview_scan(View * view)41 stringview_scan( View *view )
42 {
43 	Stringview *stringview = STRINGVIEW( view );
44 	String *string = STRING( VOBJECT( stringview )->iobject );
45     	Expr *expr = HEAPMODEL( string )->row->expr;
46 	char value[MAX_STRSIZE];
47 	char value2[MAX_STRSIZE];
48 
49 #ifdef DEBUG
50 	Row *row = HEAPMODEL( string )->row;
51 
52 	printf( "stringview_scan: " );
53 	row_name_print( row );
54 	printf( "\n" );
55 #endif /*DEBUG*/
56 
57 	expr_error_clear( expr );
58 
59 	if( !get_geditable_string( EDITVIEW( stringview )->text,
60 		value, MAX_STRSIZE ) ) {
61 		expr_error_set( expr );
62 		return( view );
63 	}
64 	my_strccpy( value2, value );
65 
66 	if( strcmp( string->value, value2 ) != 0 ) {
67 		IM_SETSTR( string->value, value2 );
68 		classmodel_update( CLASSMODEL( string ) ) ;
69 	}
70 
71 	return( VIEW_CLASS( parent_class )->scan( view ) );
72 }
73 
74 static void
stringview_refresh(vObject * vobject)75 stringview_refresh( vObject *vobject )
76 {
77 	Stringview *stringview = STRINGVIEW( vobject );
78 	String *string = STRING( VOBJECT( stringview )->iobject );
79 
80 #ifdef DEBUG
81 	Row *row = HEAPMODEL( string )->row;
82 
83 	printf( "stringview_refresh: " );
84 	row_name_print( row );
85 	printf( " (%p)\n", vobject );
86 #endif /*DEBUG*/
87 
88 	if( string->value ) {
89 		char txt[MAX_STRSIZE];
90 		VipsBuf buf = VIPS_BUF_STATIC( txt );
91 
92 		vips_buf_appendsc( &buf, FALSE, string->value );
93 		editview_set_entry( EDITVIEW( stringview ),
94 			"%s", vips_buf_all( &buf ) );
95 	}
96 
97 	VOBJECT_CLASS( parent_class )->refresh( vobject );
98 }
99 
100 static void
stringview_class_init(StringviewClass * class)101 stringview_class_init( StringviewClass *class )
102 {
103 	vObjectClass *vobject_class = (vObjectClass *) class;
104 	ViewClass *view_class = (ViewClass *) class;
105 
106 	parent_class = g_type_class_peek_parent( class );
107 
108 	/* Create signals.
109 	 */
110 
111 	/* Init methods.
112 	 */
113 	vobject_class->refresh = stringview_refresh;
114 
115 	view_class->scan = stringview_scan;
116 }
117 
118 static void
stringview_init(Stringview * stringview)119 stringview_init( Stringview *stringview )
120 {
121 }
122 
123 GtkType
stringview_get_type(void)124 stringview_get_type( void )
125 {
126 	static GtkType type = 0;
127 
128 	if( !type ) {
129 		static const GtkTypeInfo info = {
130 			"Stringview",
131 			sizeof( Stringview ),
132 			sizeof( StringviewClass ),
133 			(GtkClassInitFunc) stringview_class_init,
134 			(GtkObjectInitFunc) stringview_init,
135 			/* reserved_1 */ NULL,
136 			/* reserved_2 */ NULL,
137 			(GtkClassInitFunc) NULL,
138 		};
139 
140 		type = gtk_type_unique( TYPE_EDITVIEW, &info );
141 	}
142 
143 	return( type );
144 }
145 
146 View *
stringview_new(void)147 stringview_new( void )
148 {
149 	Stringview *stringview = gtk_type_new( TYPE_STRINGVIEW );
150 
151 	return( VIEW( stringview ) );
152 }
153