File: appInspector.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (459 lines) | stat: -rw-r--r-- 12,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/************************************************************************/
/*									*/
/*  Utility functionality for 'Inspector' like tools.			*/
/*									*/
/************************************************************************/

#   include	"appFrameConfig.h"

#   include	<stdlib.h>
#   include	<stdio.h>

#   include	<appFrame.h>

#   include	<appRgbChooserPage.h>

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Pull a particular subject of the inspector to front.		*/
/*									*/
/************************************************************************/

void appInspectorSelectSubject(	AppInspector *		ai,
				int			subject )
    {
    const int	andMenu= 1;

    appInspectorChoosePage( ai, andMenu, subject );

    ai->aiCurrentSubject= subject;
    }

/************************************************************************/
/*									*/
/*  An inspector tool must be destroyed.				*/
/*									*/
/************************************************************************/

static void appDestroyInspector(	AppInspector *	ai )
    {
    if  ( ai->aiDestroy )
	{ (*ai->aiDestroy)( ai->aiTarget );	}

    appDestroyShellWidget( ai->aiTopWidget );

    free( ai );

    return;
    }

static APP_CLOSE_CALLBACK_H( appCloseInspector, w, voidast )
    {
    AppInspector *	ast= (AppInspector *)voidast;

    appDestroyInspector( ast );

    return;
    }

/************************************************************************/
/*									*/
/*  Make the form with the two buttons.					*/
/*									*/
/************************************************************************/

void appInspectorMakeButtonRow(	APP_WIDGET *		pRow,
				APP_WIDGET		parent,
				APP_WIDGET *		pLeftButton,
				APP_WIDGET *		pRightButton,
				const char *		leftLabel,
				const char *		rightLabel,
				APP_BUTTON_CALLBACK_T	leftCallback,
				APP_BUTTON_CALLBACK_T	rightCallback,
				void *			through )
    {
    const int	heightResizable= 0;
    const int	showAsDefault= 0;

    APP_WIDGET	row= appMakeRowInColumn( parent, 2, heightResizable );

    APP_WIDGET	leftButton;
    APP_WIDGET	rightButton;

    appMakeButtonInRow( &leftButton, row, leftLabel, leftCallback, through,
							    0, showAsDefault );
    appMakeButtonInRow( &rightButton, row, rightLabel,rightCallback, through,
							    1, showAsDefault );

    *pRow= row;
    *pLeftButton= leftButton;
    *pRightButton= rightButton;

    return;
    }

void appInspectorMake3ButtonRow( APP_WIDGET *		pRow,
				APP_WIDGET		parent,
				APP_WIDGET *		pLeftButton,
				APP_WIDGET *		pMiddleButton,
				APP_WIDGET *		pRightButton,
				const char *		leftLabel,
				const char *		middleLabel,
				const char *		rightLabel,
				APP_BUTTON_CALLBACK_T	leftCallback,
				APP_BUTTON_CALLBACK_T	middleCallback,
				APP_BUTTON_CALLBACK_T	rightCallback,
				void *			through )
    {
    const int	heightResizable= 0;
    const int	showAsDefault= 0;

    APP_WIDGET	row= appMakeRowInColumn( parent, 3, heightResizable );

    APP_WIDGET	leftButton;
    APP_WIDGET	middleButton;
    APP_WIDGET	rightButton;

    appMakeButtonInRow( &leftButton, row, leftLabel, leftCallback, through,
							    0, showAsDefault );
    appMakeButtonInRow( &middleButton, row, middleLabel,middleCallback, through,
							    1, showAsDefault );
    appMakeButtonInRow( &rightButton, row, rightLabel,rightCallback, through,
							    2, showAsDefault );

    *pRow= row;
    *pLeftButton= leftButton;
    *pMiddleButton= middleButton;
    *pRightButton= rightButton;

    return;
    }

void appInspectorMakeToggleRow(		APP_WIDGET *		pRow,
					APP_WIDGET		parent,
					APP_WIDGET *		pLeftToggle,
					APP_WIDGET *		pRightToggle,
					const char *		leftText,
					const char *		rightText,
					APP_TOGGLE_CALLBACK_T	leftCallback,
					APP_TOGGLE_CALLBACK_T	rightCallback,
					void *			through )
    {
    const int	heightResizable= 0;
    APP_WIDGET	row= appMakeRowInColumn( parent, 2, heightResizable );

    APP_WIDGET	leftToggle;
    APP_WIDGET	rightToggle;

    const int	leftColumn= 0;
    const int	rightColumn= 1;

    leftToggle= appMakeToggleInRow( row, leftText, leftCallback,
						    through, leftColumn );
    rightToggle= appMakeToggleInRow( row, rightText, rightCallback,
						    through, rightColumn );

    *pRow= row;
    *pLeftToggle= leftToggle;
    *pRightToggle= rightToggle;

    return;
    }

void appInspectorMakeMenuRow(	APP_WIDGET *		pRow,
				AppOptionmenu *		aom,
				APP_WIDGET *		pLabel,
				APP_WIDGET		parent,
				const char *		labelText )
    {
    APP_WIDGET	row;
    APP_WIDGET	label;

    const int	labelColumn= 0;
    const int	labelColspan= 1;

    const int	menuColumn= labelColumn+ labelColspan;
    const int	menuColspan= 1;
    const int	heightResizable= 0;

    row= appMakeRowInColumn( parent, 2, heightResizable );

    /**************/
    appMakeLabelInRow( &label, row, labelColumn, labelColspan, labelText );

    /**************/
    appMakeOptionmenuInRow( aom, row, menuColumn, menuColspan );

    /**************/

    *pRow= row;
    *pLabel= label;

    return;
    }

/************************************************************************/
/*									*/
/*  Make the pages,							*/
/*  Fill the menu for the pages.					*/
/*									*/
/************************************************************************/

static void appInspectorFillSubjects(	InspectorSubjectResources *	isr,
					AppInspector *			ai )
    {
    int				subject;
    InspectorSubject *		is;

    is= ai->aiSubjects;
    for ( subject= 0; subject < ai->aiSubjectCount; is++, isr++, subject++ )
	{
	appMakeVerticalInspectorPage( &(is->isPage), &(is->isMenuitem),
						    ai, isr->isrSubjectName );
	is->isEnabled= 1;
	}
    }

/************************************************************************/
/*									*/
/*  Initialize an inspector subject.					*/
/*									*/
/************************************************************************/

static void appInitInspectorSubject(	InspectorSubject *	is )
    {
    is->isPage= (APP_WIDGET)0;
    is->isMenuitem= (APP_WIDGET)0;
    is->isPrivate= (void *)0;
    is->isEnabled= 1;

    is->isPrevButton= (APP_WIDGET)0;
    is->isNextButton= (APP_WIDGET)0;

    is->isSelectButton= (APP_WIDGET)0;
    is->isDeleteButton= (APP_WIDGET)0;

    is->isInsertButton= (APP_WIDGET)0;
    is->isAppendButton= (APP_WIDGET)0;

    is->isRevertButton= (APP_WIDGET)0;
    is->isApplyButton= (APP_WIDGET)0;

    is->isGotColor= (InspectorSubjectGotColor)0;
    }

/************************************************************************/
/*									*/
/*  Turn an inspector or one of its subjects on or off.			*/
/*									*/
/************************************************************************/

void appEnableInspector(	AppInspector *	ai,
				int		enabled )
    {
    appGuiEnableWidget( ai->aiPaned, enabled != 0 );

    return;
    }

void appEnableInspectorSubject(		AppInspector *		ai,
					int			subject ,
					int			enabled )
    {
    appInspectorEnablePage( ai, subject, enabled );

    ai->aiSubjects[subject].isEnabled= enabled != 0;

    return;
    }

/************************************************************************/
/*									*/
/*  Fill an inspector menu.						*/
/*									*/
/************************************************************************/

void appFillInspectorMenu(	int			count,
				int			current,
				APP_WIDGET *		items,
				char * const *		texts,
				AppOptionmenu *		aom,
				APP_OITEM_CALLBACK_T	callBack,
				void *			target )
    {
    int			i;

    appEmptyOptionmenu( aom );

    for ( i= 0; i < count; i++ )
	{
	items[i]= appAddItemToOptionmenu( aom, texts[i], callBack, target );
	}

    appSetOptionmenu( aom, current );

    appOptionmenuRefreshWidth( aom );

    return;
    }

AppInspector * appMakeInspector(    EditApplication *		ea,
				    APP_WIDGET			option,
				    const char *		pixmapName,
				    const char *		widgetName,
				    InspectorSubjectResources * isr,
				    int				subjectCount,
				    AppToolDestroy		destroy,
				    void *			through )
    {
    AppInspector *		ai;
    int				subject;
    InspectorSubject *		is;

    APP_BITMAP_IMAGE		iconPixmap;
    APP_BITMAP_MASK		iconMask;

    const int			userResizable= 0;

    if  ( appGetImagePixmap( ea, pixmapName, &iconPixmap, &iconMask )  )
	{ SDEB(pixmapName); return (AppInspector *)0; }

    ai= (AppInspector *)malloc( sizeof(AppInspector)+ 
				subjectCount* sizeof(InspectorSubject) );
    if  ( ! ai )
	{ LXDEB(subjectCount,ai); return ai;	}

    ai->aiCurrentSubject= -1;
    ai->aiSubjectCount= subjectCount;

    ai->aiDestroy= destroy;
    ai->aiTarget= through;
    ai->aiNotifySubject= (InspectorNotifySubject)0;

    ai->aiRgbSubjectNumber= -1;
    ai->aiRgbChooser= (void *)0; /* RgbChooserPage */

    is= ai->aiSubjects;
    for ( subject= 0; subject < ai->aiSubjectCount; is++, subject++ )
	{ appInitInspectorSubject( is );	}

    appMakeVerticalTool( &(ai->aiTopWidget), &(ai->aiPaned), ea,
				iconPixmap, iconMask,
				widgetName, userResizable,
				option, appCloseInspector, (void *)ai );

    appMakeOptionmenuInColumn( &(ai->aiSubjectOptionmenu), ai->aiPaned );

    appGuiInsertSeparatorInColumn( &(ai->aiSeparator), ai->aiPaned );

    appInspectorMakePageParent( ai );

    appInspectorFillSubjects( isr, ai );

    return ai;
    }

void appFinishInspector(	AppInspector *		ai )
    {
    appShowShellWidget( ai->aiTopWidget );

    appOptionmenuRefreshWidth( &(ai->aiSubjectOptionmenu) );

    return;
    }

/************************************************************************/
/*									*/
/*  Callback of a possible RGB chooser to an inspector.			*/
/*									*/
/************************************************************************/

void appInspectorGotColor(	AppInspector *			ai,
				int				subjectPage,
				int				property,
				const RGB8Color *		rgb8Set )
    {
    RgbChooserPage *	rcp;
    InspectorSubject *	is;

    if  ( ! ai->aiRgbChooser )
	{ XDEB(ai->aiRgbChooser); return;	}
    rcp= (RgbChooserPage *)ai->aiRgbChooser;

    if  ( ai->aiRgbSubjectNumber < 0			||
	  ai->aiRgbSubjectNumber >= ai->aiSubjectCount	)
	{ LLDEB(ai->aiRgbSubjectNumber,ai->aiSubjectCount); return;	}

    is= ai->aiSubjects+ subjectPage;

    if  ( subjectPage < 0 || subjectPage >= ai->aiSubjectCount )
	{ LLDEB(subjectPage,ai->aiSubjectCount); return;	}

    /**/
    if  ( rgb8Set )
	{
	if  ( ! is->isGotColor )
	    { XDEB(is->isGotColor);					}
	else{ (*is->isGotColor)( is->isPrivate, property, rgb8Set );	}
	}

    /**/
    appEnableInspectorSubject( ai, subjectPage, 1 );
    appInspectorSelectSubject( ai, subjectPage );

    /**/
    appEnableInspectorSubject( ai, ai->aiRgbSubjectNumber, 0 );
    appRgbChooserSetContext( rcp, -1, -1 );

    return;
    }

/************************************************************************/
/*									*/
/*  Switch to the RGB color chooser page.				*/
/*									*/
/************************************************************************/

void appInspectorSetRgbPage(		AppInspector *		ai,
					void *			vrcp,
					int			subjectNumber )
    {
    ai->aiRgbChooser= vrcp;
    ai->aiRgbSubjectNumber= subjectNumber;

    return;
    }

void appInspectorShowRgbPage(		AppInspector *		ai,
					int			fromSubject,
					int			fromProperty,
					const RGB8Color *	rgb8 )
    {
    RgbChooserPage *	rcp;
    InspectorSubject *	is;

    int			enabled= 1;

    if  ( ! ai->aiRgbChooser )
	{ XDEB(ai->aiRgbChooser); return;	}
    rcp= (RgbChooserPage *)ai->aiRgbChooser;

    if  ( ai->aiRgbSubjectNumber < 0			||
	  ai->aiRgbSubjectNumber >= ai->aiSubjectCount	)
	{ LLDEB(ai->aiRgbSubjectNumber,ai->aiSubjectCount); return;	}

    is= ai->aiSubjects+ ai->aiRgbSubjectNumber;

    appRgbChooserRefresh( rcp, &enabled, is, rgb8 );

    appRgbChooserSetContext( rcp, fromSubject, fromProperty );

    appEnableInspectorSubject( ai, ai->aiRgbSubjectNumber, 1 );

    appInspectorSelectSubject( ai, ai->aiRgbSubjectNumber );

    return;
    }