File: tedBorderTool.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 (610 lines) | stat: -rw-r--r-- 16,222 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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/************************************************************************/
/*									*/
/*  A Border Tool. Used on the pages of the format tool.		*/
/*									*/
/************************************************************************/

#   include	"tedConfig.h"

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

#   include	"tedApp.h"
#   include	"tedFormatTool.h"

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Show the border width in a border tool.				*/
/*									*/
/************************************************************************/

static void tedBorderToolShowWide(
				BorderTool *				bt,
				const ExpandedBorderProperties *	ebp )
    {
    appEnableText( bt->btWideText, ebp->ebpStyle != DOCbsNONE );

    if  ( ebp->ebpStyle != DOCbsNONE )
	{
	char	scratch[80];

	appGeoLengthToString( scratch, ebp->ebpPenWideTwips, UNITtyPOINTS );
	appStringToTextWidget( bt->btWideText, scratch );
	}
    else{ appStringToTextWidget( bt->btWideText, "" );	}

    return;
    }

/************************************************************************/
/*									*/
/*  Conform to border settings from the application.			*/
/*									*/
/************************************************************************/

void tedBorderToolSetProperties(	BorderTool *			bt,
					const DocumentProperties *	dp,
					const BorderProperties *	bpSet )
    {
    ExpandedBorderProperties *	ebp= &(bt->btPropertiesChosen);
    int				set= 0;

    const int			avoidZero= 1;

    docExpandBorderProperties( ebp, bpSet, dp->dpColors, dp->dpColorCount );

    if  ( ebp->ebpStyle != DOCbsNONE )
	{ set= 1;	}

    appGuiSetToggleState( bt->btOnOffToggle, set );
    tedBorderToolShowWide( bt, ebp );

    if  ( bt->btStyleRow )
	{
	appExposeRectangle( &(bt->btInplaceDrawingData), 0, 0, 0, 0 );
	}

    appColorChooserSuggestPalette( &(bt->btColorChooser),
				avoidZero, dp->dpColors, dp->dpColorCount );
    appColorChooserSetColor( &(bt->btColorChooser),
				    ebp->ebpColorExplicit,
				    &(ebp->ebpColor) );

    PROPmaskCLEAR( &(bt->btPropertiesChanged) );

    return;
    }

/************************************************************************/
/*									*/
/*  Draw the widgets of a border tool.					*/
/*									*/
/************************************************************************/

static void tedDrawBorderStyle(	AppDrawingData *		add,
				BorderTool *			bt,
				int				style,
				const DocumentRectangle *	drI )
    {
    if  ( style != DOCbsNONE )
	{
	const int	minThick= 1;

	tedDrawHorizontalBorderLine( add, style, minThick,
			    drI->drX0,
			    drI->drX1, ( drI->drY0+ drI->drY1 )/ 2 );
	}

    /*  NO.. Confuses
    appDrawDrawLine( add, drI->drX0, drI->drY0, drI->drX1, drI->drY0 );
    appDrawDrawLine( add, drI->drX1, drI->drY0, drI->drX1, drI->drY1 );
    appDrawDrawLine( add, drI->drX1, drI->drY1, drI->drX0, drI->drY1 );
    appDrawDrawLine( add, drI->drX0, drI->drY1, drI->drX0, drI->drY0 );
    */

    return;
    }

static APP_EVENT_HANDLER_H( tedBorderToolRedrawInplace, w, voidbt, exposeEvent )
    {
    BorderTool *	bt= (BorderTool *)voidbt;
    AppDrawingData *	add= &(bt->btInplaceDrawingData);

    int			wide;
    int			high;

    DocumentRectangle	drI;

    appDrawnPulldownDrawArrow( &wide, &high, w, add );

    drI.drX0= 3; drI.drX1= wide- 3;
    drI.drY0= 3; drI.drY1= high- 3;

    appDrawSetForegroundWhite( add );

    appDrawFillRectangle( add, 0, 0, wide, high );

    appDrawSetForegroundBlack( add );

    tedDrawBorderStyle( add, bt, bt->btPropertiesChosen.ebpStyle, &drI );

    return;
    }

static APP_EVENT_HANDLER_H( tedBorderToolRedrawPulldown, w, voidbt, exposeEvent )
    {
    BorderTool *	bt= (BorderTool *)voidbt;
    AppDrawingData *	add= &(bt->btPulldownDrawingData);

    int			inplaceWide;
    int			inplaceHigh;
    int			pulldownWide;
    int			pulldownHigh;

    const int		ox= 0;
    const int		oy= 0;
    DocumentRectangle	drClip;

    int			i;

    if  ( ! bt->btPulldownDrawingDataSet )
	{
	appSetDrawingDataForWidget( bt->btStylePulldown.adpPulldownDrawing,
					1.0, &(bt->btPulldownDrawingData) );

	bt->btPulldownDrawingDataSet= 1;
	}

    appDrawGetSizeOfWidget( &pulldownWide, &pulldownHigh, w );
    appDrawGetSizeOfWidget( &inplaceWide, &inplaceHigh,
					bt->btStylePulldown.adpInplaceDrawing );

    appCollectExposures( &drClip, add, ox, oy, exposeEvent );

    appDrawSetForegroundWhite( add );

    appDrawFillRectangle( add, drClip.drX0, drClip.drY0,
					    drClip.drX1- drClip.drX0+ 1,
					    drClip.drY1- drClip.drY0+ 1 );

    appDrawSetForegroundBlack( add );
    appDrawDrawRectangle( add, 0, 0, pulldownWide- 1, pulldownHigh- 1 );

    for ( i= DOCbsNONE+ 1; i < DOCbs_COUNT; i++ )
	{
	DocumentRectangle	drI;
	DocumentRectangle	drX;

	drI.drX0= 3;
	drI.drX1= pulldownWide- 3;
	drI.drY0= ( i+ 0 )* inplaceHigh+ 3;
	drI.drY1= ( i+ 1 )* inplaceHigh- 3;

	if  ( ! docIntersectRectangle( &drX, &drI, &drClip ) )
	    { continue;	}

	tedDrawBorderStyle( add, bt, i, &drI );
	}

    return;
    }


/************************************************************************/
/*									*/
/*  One of the border on/off toggles has been activated by a user.	*/
/*									*/
/************************************************************************/

static APP_TOGGLE_CALLBACK_H( tedBorderToolOnOffToggled, w, voidbt, voidtbcs )
    {
    BorderTool *		bt= (BorderTool *)voidbt;
    ExpandedBorderProperties *	ebp= &(bt->btPropertiesChosen);

    int			set;
    int			changed= 0;

    PropertyMask	bpSetMask;

    PROPmaskCLEAR( &bpSetMask );

    set= appGuiGetToggleStateFromCallback( w, voidtbcs );

    if  ( set )
	{
	if  ( ebp->ebpStyle == DOCbsNONE )
	    {
	    ebp->ebpStyle= DOCbsS;
	    PROPmaskADD( &bpSetMask, BRDRpropSTYLE );
	    PROPmaskADD( &(bt->btPropertiesChanged), BRDRpropSTYLE );
	    changed= 1;
	    }

	if  ( ebp->ebpPenWideTwips == 0 )
	    {
	    ebp->ebpPenWideTwips= 15;
	    PROPmaskADD( &bpSetMask, BRDRpropPEN_WIDE );
	    PROPmaskADD( &(bt->btPropertiesChanged), BRDRpropPEN_WIDE );
	    changed= 1;
	    }
	}
    else{
	if  ( ebp->ebpStyle != DOCbsNONE )
	    {
	    ebp->ebpStyle= DOCbsNONE;
	    PROPmaskADD( &bpSetMask, BRDRpropSTYLE );
	    PROPmaskADD( &(bt->btPropertiesChanged), BRDRpropSTYLE );
	    changed= 1;
	    }
	}

    /*
    if  ( changed && bt->btCallback )
	{ (*bt->btCallback)( bt, bt->btTarget, &bpSetMask, bp );	}
    */

    tedBorderToolShowWide( bt, ebp );

    return;
    }

/************************************************************************/
/*									*/
/*  A border style was chosen.						*/
/*									*/
/*  1)  Determine strip.						*/
/*  2)  Value in range?							*/
/*  3)  If the value changed..						*/
/*  4)  Remember new value						*/
/*  5)  Provoke a redraw of the image					*/
/*									*/
/************************************************************************/

static APP_EVENT_HANDLER_H( tedBorderToolClickedPulldown, w, voidbt, mouseEvent )
    {
    BorderTool *		bt= (BorderTool *)voidbt;
    ExpandedBorderProperties *	ebp= &(bt->btPropertiesChosen);

    int			style;

    /*  1  */
    if  ( appGuiDrawnPulldownGetStrip( &style,
				&(bt->btStylePulldown), w, mouseEvent ) )
	{ return;	}

    /*  2  */
    if  ( style < 0 || style >= DOCbs_COUNT )
	{ LLDEB(style,DOCbs_COUNT); return;	}

    /*  3  */
    if  ( ebp->ebpStyle != style )
	{
	/*  4  */
	ebp->ebpStyle= style;
	PROPmaskADD( &(bt->btPropertiesChanged), BRDRpropSTYLE );

	/*  5  */
	appExposeRectangle( &(bt->btInplaceDrawingData), 0, 0, 0, 0 );
	}

    return;
    }

/************************************************************************/
/*									*/
/*  1)  The user typed Something in the 'Width' text box.		*/
/*  2)  The user typed 'Enter' in the 'Width' text box.			*/
/*									*/
/************************************************************************/

/*  1  */
static APP_TXTYPING_CALLBACK_H( tedFormatBorderWidthTyped, w, voidbt )
    {
    BorderTool *	bt= (BorderTool *)voidbt;

    PROPmaskADD( &(bt->btPropertiesChanged), BRDRpropPEN_WIDE );

    return;
    }

/*  2  */
static APP_TXACTIVATE_CALLBACK_H( tedFormatBorderWidthChanged, w, voidbt )
    {
    BorderTool *		bt= (BorderTool *)voidbt;
    ExpandedBorderProperties *	ebp= &(bt->btPropertiesChosen);

    int			wide= 0;
    int			changed= 0;

    char		scratch[80];

    const int		minValue= 1;
    const int		adaptToMin= 0;
    const int		maxValue= 75;
    const int		adaptToMax= 0;

    PropertyMask	bpSetMask;

    PROPmaskCLEAR( &bpSetMask );

    wide= ebp->ebpPenWideTwips;
    if  ( appGetLengthFromTextWidget( bt->btWideText,
				&wide, &changed, UNITtyPOINTS,
				minValue, adaptToMin, maxValue, adaptToMax ) )
	{ return;	}

    appGeoLengthToString( scratch, wide, UNITtyPOINTS );
    appStringToTextWidget( bt->btWideText, scratch );

    if  ( changed )
	{
	ebp->ebpPenWideTwips= wide;
	PROPmaskADD( &bpSetMask, BRDRpropPEN_WIDE );
	PROPmaskADD( &(bt->btPropertiesChanged), BRDRpropPEN_WIDE );
	}

    /*
    if  ( changed && bt->btCallback )
	{ (*bt->btCallback)( bt, bt->btTarget, &bpSetMask, bp ); }
    */

    return;
    }

/************************************************************************/
/*									*/
/*  A color for the border was chosen.					*/
/*									*/
/*  1)  Actually.. No color was selected but the user wants to use a	*/
/*	more detailed tool.						*/
/*  2)  color chosen.							*/
/*									*/
/************************************************************************/

static void tedBorderColorChosen(
				ColorChooser *			cc,
				int				which,
				void *				voidbt,
				int				choice,
				const RGB8Color *		rgb8Set )
    {
    BorderTool *		bt= (BorderTool *)voidbt;
    ExpandedBorderProperties *	ebp= &(bt->btPropertiesChosen);
    int				changed= 0;

    /*  1  */
    if  ( choice == CHOICEccMORE )
	{
	appInspectorShowRgbPage( bt->btInspector,
			    bt->btSubjectPage, which, &(ebp->ebpColor) );
	return;
	}

    /*  2  */
    appColorChooserColorChosen( &(bt->btPropertiesChanged), &changed,
			&(ebp->ebpColor), &(ebp->ebpColorExplicit),
			rgb8Set, choice != CHOICEccDEFAULT, BRDRpropCOLOR );

    return;
    }

void tedBorderSetExplicitColorChoice(	BorderTool *		bt,
					const RGB8Color *	rgb8Set )
    {
    const int			explicit= 1;
    ExpandedBorderProperties *	ebp= &(bt->btPropertiesChosen);
    int				changed= 0;

    appColorChooserColorChosen( &(bt->btPropertiesChanged), &changed,
				&(ebp->ebpColor), &(ebp->ebpColorExplicit),
				rgb8Set, explicit, BRDRpropCOLOR );

    if  ( changed )
	{
	appColorChooserSetColor( &(bt->btColorChooser),
				    ebp->ebpColorExplicit, &(ebp->ebpColor) );
	}

    return;
    }

/************************************************************************/
/*									*/
/*  Make a BorderTool.							*/
/*									*/
/************************************************************************/

void tedInitBorderTool(		BorderTool *		bt )
    {
    bt->btInspector= (AppInspector *)0;
    bt->btSubjectPage= -1;
    bt->btWhich= -1;

    bt->btFrame= (APP_WIDGET)0;
    bt->btPaned= (APP_WIDGET)0;
    bt->btOnOffToggle= (APP_WIDGET)0;
    bt->btWideText= (APP_WIDGET)0;

    bt->btStyleRow= (APP_WIDGET)0;
    bt->btStyleLabel= (APP_WIDGET)0;
    appInitDrawnPulldown( &(bt->btStylePulldown) );

    appInitDrawingData( &(bt->btInplaceDrawingData) );
    appInitDrawingData( &(bt->btPulldownDrawingData) );

    bt->btColorRow= (APP_WIDGET)0;
    bt->btColorLabel= (APP_WIDGET)0;
    appInitColorChooser( &(bt->btColorChooser) );

    docInitExpandedBorderProperties( &(bt->btPropertiesChosen) );
    PROPmaskCLEAR( &(bt->btPropertiesChanged) );

    return;
    }

void tedCleanBorderTool(		BorderTool *		bt )
    {
    appCleanDrawingData( &(bt->btInplaceDrawingData) );
    appCleanDrawingData( &(bt->btPulldownDrawingData) );

    return;
    }

void tedMakeBorderTool(		BorderTool *			bt,
				AppInspector *			ai,
				APP_WIDGET			pageWidget,
				const char *			title,
				const BorderToolResources *	btr,
				int				subjectPage,
				int				which )
    {
    const int	heightResizable= 0;

    const int	toggleColumn= 0;
    const int	textColumn= toggleColumn+ 1;
    const int	textColspan= 1;

    const int	textColumns= 8;
    const int	textEnabled= 0;

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

    const int	valueColumn= 1;
    const int	valueColspan= 1;

    APP_WIDGET	row;

    /**/
    bt->btInspector= ai;
    bt->btSubjectPage= subjectPage;
    bt->btWhich= which;

    /**/
    docInitExpandedBorderProperties( &(bt->btPropertiesChosen) );

    appInitDrawingData( &(bt->btInplaceDrawingData) );
    appInitDrawingData( &(bt->btPulldownDrawingData) );
    bt->btPulldownDrawingDataSet= 0;

    /**/
    appMakeColumnFrameInColumn( &(bt->btFrame),
				&(bt->btPaned), pageWidget, (const char *)0 );
				/*
				&(bt->btPaned), pageWidget, title );
				*/

    /**/
    row= appMakeRowInColumn( bt->btPaned, 2, heightResizable );

    bt->btOnOffToggle= appMakeToggleInRow( row, title,
				    tedBorderToolOnOffToggled, (void *)bt, 0 );

    appMakeTextInRow( &(bt->btWideText), row, textColumn, textColspan,
						    textColumns, textEnabled );

    appGuiSetGotValueCallbackForText( bt->btWideText,
				    tedFormatBorderWidthChanged, (void *)bt );
    appGuiSetTypingCallbackForText( bt->btWideText,
				tedFormatBorderWidthTyped, (void *)bt );

    /**/
#   if 0
    bt->btStyleRow= appMakeRowInColumn( bt->btPaned, 2, heightResizable );
#   else
    bt->btStyleRow= (APP_WIDGET)0;
#   endif

    if  ( bt->btStyleRow )
	{
	appMakeLabelInRow( &(bt->btStyleLabel), bt->btStyleRow,
				labelColumn, labelColspan, btr->btrStyle );

	appMakeDrawnPulldownInRow( &(bt->btStylePulldown),
				    tedBorderToolRedrawInplace,
				    tedBorderToolRedrawPulldown,
				    tedBorderToolClickedPulldown,
				    bt->btStyleRow, valueColumn, valueColspan,
				    (void *)bt );
	}

    /****/
    appMakeLabelAndColorChooserRow( &(bt->btColorRow), &(bt->btColorLabel),
			    &(bt->btColorChooser),
			    bt->btPaned, btr->btrColor,
			    &(btr->btrColorChooserResources),
			    tedBorderColorChosen, which, (void *)bt );

    return;
    }

void tedFinishBorderTool(	BorderTool *		bt )
    {
    if  ( bt->btStyleRow )
	{
	appSetDrawingDataForWidget( bt->btStylePulldown.adpInplaceDrawing, 1.0,
						&(bt->btInplaceDrawingData) );

	appGuiSetDrawnPulldownStrips( &(bt->btStylePulldown), DOCbs_COUNT );
	}

    appFinishColorChooser( &(bt->btColorChooser),
				    appGuiGetLabelFont( bt->btColorLabel ) );

    return;
    }

/************************************************************************/
/*									*/
/*  Retrieve the border properties from the border tool.		*/
/*									*/
/*  The properties managed by the toggle and the various option menus	*/
/*  or pulldowns are already stored in bt->btPropertiesChosen.		*/
/*  The typing callback sets the changed flag for the pen width.	*/
/*									*/
/*  Retrieve the pen width if its changed flag is set.			*/
/*									*/
/************************************************************************/

int tedBorderToolGetProperties(	BorderProperties *	bpSet,
				PropertyMask *		pSetMask,
				const BorderTool *	bt,
				DocumentProperties *	dp )
    {
    const ExpandedBorderProperties *	ebpChosen= &(bt->btPropertiesChosen);

    int				changed= 0;

    const int			minValue= 1;
    const int			adaptToMin= 0;
    const int			maxValue= 75;
    const int			adaptToMax= 0;

    int				wide= ebpChosen->ebpPenWideTwips;

    PropertyMask		bpDoneMask;

    if  ( PROPmaskISSET( &(bt->btPropertiesChanged), BRDRpropPEN_WIDE )	&&
	  ebpChosen->ebpStyle != DOCbsNONE				)
	{
	if  ( appGetLengthFromTextWidget( bt->btWideText,
			    &wide, &changed, UNITtyPOINTS,
			    minValue, adaptToMin, maxValue, adaptToMax ) )
	    { return -1;	}
	}

    docIndirectBorderProperties( &bpDoneMask, bpSet,
				    &(bt->btPropertiesChanged), ebpChosen,
				    &(dp->dpColors), &(dp->dpColorCount) );
    if  ( PROPmaskISSET( &(bt->btPropertiesChanged), BRDRpropPEN_WIDE )	&&
	  changed							)
	{ bpSet->bpPenWideTwips= wide; }

    *pSetMask= bt->btPropertiesChanged;

    return 0;
    }