1 /************************************************************************/
2 /* */
3 /* Image page of the format tool. */
4 /* */
5 /************************************************************************/
6
7 # include "tedConfig.h"
8
9 # include <stdio.h>
10 # include <stddef.h>
11 # include <limits.h>
12
13 # include "tedImageTool.h"
14 # include "tedAppFront.h"
15 # include <guiToolUtil.h>
16 # include <guiTextUtil.h>
17 # include <docEditCommand.h>
18
19 # include <appDebugon.h>
20 # include <docObjectProperties.h>
21
22 /************************************************************************/
23 /* */
24 /* Get/Set absolute values for the dimensions by translating from/to */
25 /* the scale. */
26 /* */
27 /************************************************************************/
28
tedImageToolShowWideAbs(ImageTool * it)29 static void tedImageToolShowWideAbs( ImageTool * it )
30 {
31 EditApplication * ea= it->itApplication;
32 const PictureProperties * pip= &(it->itPropertiesChosen);
33
34 appLengthToTextWidget( it->itImageWideText,
35 ( pip->pipScaleXSet* pip->pipTwipsWide )/ 100, ea->eaUnitInt );
36
37 return;
38 }
39
tedImageToolShowHighAbs(ImageTool * it)40 static void tedImageToolShowHighAbs( ImageTool * it )
41 {
42 EditApplication * ea= it->itApplication;
43 const PictureProperties * pip= &(it->itPropertiesChosen);
44
45 appLengthToTextWidget( it->itImageHighText,
46 ( pip->pipScaleYSet* pip->pipTwipsHigh )/ 100, ea->eaUnitInt );
47
48 return;
49 }
50
tedImageToolGetWideAbs(ImageTool * it)51 static int tedImageToolGetWideAbs( ImageTool * it )
52 {
53 EditApplication * ea= it->itApplication;
54 PictureProperties * pip= &(it->itPropertiesChosen);
55
56 const int maxValue= INT_MAX;
57 const int adaptToMax= 0;
58 const int minSize= 1;
59 const int adaptToMin= 0;
60
61 int value= 0;
62 int changed= 0;
63
64 if ( appGetLengthFromTextWidget( it->itImageWideText,
65 &value, &changed, ea->eaUnitInt,
66 minSize, adaptToMin, maxValue, adaptToMax ) )
67 { return -1; }
68
69 pip->pipScaleXSet= ( 100* value )/ pip->pipTwipsWide;
70
71 return 0;
72 }
73
tedImageToolGetHighAbs(ImageTool * it)74 static int tedImageToolGetHighAbs( ImageTool * it )
75 {
76 EditApplication * ea= it->itApplication;
77 PictureProperties * pip= &(it->itPropertiesChosen);
78
79 const int maxValue= INT_MAX;
80 const int adaptToMax= 0;
81 const int minSize= 1;
82 const int adaptToMin= 0;
83
84 int value= 0;
85 int changed= 0;
86
87 if ( appGetLengthFromTextWidget( it->itImageHighText,
88 &value, &changed, ea->eaUnitInt,
89 minSize, adaptToMin, maxValue, adaptToMax ) )
90 { return -1; }
91
92 pip->pipScaleYSet= ( 100* value )/ pip->pipTwipsHigh;
93
94 return 0;
95 }
96
97 /************************************************************************/
98 /* */
99 /* Refresh the 'Image' page of the format tool. */
100 /* */
101 /************************************************************************/
102
tedFormatToolRefreshImagePage(ImageTool * it)103 static void tedFormatToolRefreshImagePage( ImageTool * it )
104 {
105 const PictureProperties * pip= &(it->itPropertiesChosen);
106 char scratch[50];
107
108 if ( it->itPictureHasBitmap )
109 {
110 const BitmapDescription * bd= &(it->itBitmapDescription);
111
112 sprintf( scratch, "%d x %d", bd->bdPixelsWide, bd->bdPixelsHigh );
113 appStringToTextWidget( it->itPixelsSizeText, scratch );
114 }
115 else{
116 appStringToTextWidget( it->itPixelsSizeText, "" );
117 }
118
119 if ( it->itObjectType >= 0 )
120 {
121 appStringToTextWidget( it->itObjectTypeText,
122 docObjectKindStr( it->itObjectType ) );
123 }
124 else{
125 appStringToTextWidget( it->itObjectTypeText, "" );
126 }
127
128 if ( it->itImageType >= 0 )
129 {
130 appStringToTextWidget( it->itImageTypeText,
131 docObjectKindStr( it->itImageType ) );
132 }
133 else{
134 appStringToTextWidget( it->itImageTypeText, "" );
135 }
136
137 appIntegerToTextWidget( it->itByteSizeText, it->itTotalBytes );
138
139 tedImageToolShowWideAbs( it );
140 tedImageToolShowHighAbs( it );
141
142 appIntegerToTextWidget( it->itXScaleText, pip->pipScaleXSet );
143 appIntegerToTextWidget( it->itYScaleText, pip->pipScaleYSet );
144 }
145
tedRefreshImageTool(ImageTool * it,int * pEnabled,int * pPref,InspectorSubject * is,const DocumentSelection * ds,const SelectionDescription * sd,BufferDocument * bd,const unsigned char * cmdEnabled)146 void tedRefreshImageTool( ImageTool * it,
147 int * pEnabled,
148 int * pPref,
149 InspectorSubject * is,
150 const DocumentSelection * ds,
151 const SelectionDescription * sd,
152 BufferDocument * bd,
153 const unsigned char * cmdEnabled )
154 {
155 int part;
156 DocumentPosition dpObject;
157 InsertedObject * io;
158 PictureProperties * pip;
159
160 if ( ! sd->sdIsObjectSelection )
161 { *pEnabled= 0; return; }
162
163 if ( docGetObjectSelection( ds, bd, &part, &dpObject, &io ) )
164 { *pEnabled= 0; return; }
165
166 it->itPropertiesSet= io->ioPictureProperties;
167 it->itPropertiesChosen= io->ioPictureProperties;
168 pip= &(it->itPropertiesChosen);
169
170 it->itTotalBytes= io->ioObjectData.mbSize;
171 if ( io->ioKind == DOCokOLEOBJECT &&
172 io->ioResultKind == DOCokPICTWMETAFILE )
173 { it->itTotalBytes= io->ioResultData.mbSize; }
174
175 it->itObjectType= io->ioKind;
176 if ( io->ioKind == DOCokOLEOBJECT )
177 { it->itImageType= io->ioResultKind; }
178 else{ it->itImageType= io->ioKind; }
179
180 if ( pip->pipType == DOCokDIBITMAP ||
181 pip->pipType == DOCokWBITMAP ||
182 pip->pipType == DOCokPICTPNGBLIP ||
183 pip->pipType == DOCokPICTJPEGBLIP ||
184 ( pip->pipType == DOCokPICTWMETAFILE &&
185 pip->pipMetafileIsBitmap ) )
186 {
187 if ( ! io->ioRasterImage.riBytes )
188 { XDEB(io->ioRasterImage.riBytes); *pEnabled= 0; return; }
189
190 bmCopyDescription( &(it->itBitmapDescription),
191 &(io->ioRasterImage.riDescription) );
192 it->itPictureHasBitmap= 1;
193 }
194 else{
195 bmCleanDescription( &(it->itBitmapDescription) );
196 bmInitDescription( &(it->itBitmapDescription) );
197
198 it->itPictureHasBitmap= 0;
199 }
200
201 tedFormatToolRefreshImagePage( it );
202
203 guiEnableWidget( it->itObjectTypeRow, cmdEnabled[EDITcmdUPD_OBJECT] );
204 guiEnableWidget( it->itImageTypeRow, cmdEnabled[EDITcmdUPD_OBJECT] );
205 guiEnableWidget( it->itPixelSizeRow, cmdEnabled[EDITcmdUPD_OBJECT] );
206 guiEnableWidget( it->itByteSizeRow, cmdEnabled[EDITcmdUPD_OBJECT] );
207
208 guiEnableWidget( it->itImageWideRow, cmdEnabled[EDITcmdUPD_OBJECT] );
209 guiEnableWidget( it->itImageHighRow, cmdEnabled[EDITcmdUPD_OBJECT] );
210 guiEnableWidget( it->itXScaleRow, cmdEnabled[EDITcmdUPD_OBJECT] );
211 guiEnableWidget( it->itYScaleRow, cmdEnabled[EDITcmdUPD_OBJECT] );
212
213 guiEnableWidget( is->isRevertButton, cmdEnabled[EDITcmdUPD_OBJECT] );
214 guiEnableWidget( is->isApplyButton, cmdEnabled[EDITcmdUPD_OBJECT] );
215
216 it->itImageHighAbsChanged= 0;
217 it->itImageWideAbsChanged= 0;
218
219 *pPref += 3;
220 *pEnabled= 1;
221 return;
222 }
223
224 /************************************************************************/
225
tedImageToolGetChosen(ImageTool * it)226 static int tedImageToolGetChosen( ImageTool * it )
227 {
228 PictureProperties * pipChosen= &(it->itPropertiesChosen);
229
230 int minValue= 1;
231 const int adaptToMin= 0;
232 int maxValue= 100000;
233 const int adaptToMax= 1;
234
235 if ( it->itImageWideAbsChanged )
236 {
237 if ( tedImageToolGetWideAbs( it ) )
238 { return -1; }
239 }
240 else{
241 if ( appGetIntegerFromTextWidget( it->itXScaleText,
242 &(pipChosen->pipScaleXSet),
243 minValue, adaptToMin, maxValue, adaptToMax ) )
244 { return -1; }
245 }
246
247 if ( it->itImageHighAbsChanged )
248 {
249 if ( tedImageToolGetHighAbs( it ) )
250 { return -1; }
251 }
252 else{
253 if ( appGetIntegerFromTextWidget( it->itYScaleText,
254 &(pipChosen->pipScaleYSet),
255 minValue, adaptToMin, maxValue, adaptToMax ) )
256 { return -1; }
257 }
258 return 0;
259 }
260
261 /************************************************************************/
262 /* */
263 /* Set/Revert buttons have been pushed. */
264 /* */
265 /************************************************************************/
266
APP_BUTTON_CALLBACK_H(tedFormatChangeImagePushed,w,voidit)267 static APP_BUTTON_CALLBACK_H( tedFormatChangeImagePushed, w, voidit )
268 {
269 ImageTool * it= (ImageTool *)voidit;
270 PictureProperties * pipChosen= &(it->itPropertiesChosen);
271 PictureProperties * pipSet= &(it->itPropertiesSet);
272
273 PropertyMask pipCmpMask;
274 PropertyMask pipDifMask;
275
276 if ( tedImageToolGetChosen( it ) )
277 { return; }
278
279 utilPropMaskClear( &pipCmpMask );
280 utilPropMaskClear( &pipDifMask );
281 PROPmaskADD( &pipCmpMask, PIPpropPICSCALE_X );
282 PROPmaskADD( &pipCmpMask, PIPpropPICSCALE_Y );
283
284 docPicturePropertyDifference( &pipDifMask, pipChosen, &pipCmpMask, pipSet );
285
286 tedAppSetImageProperties( it->itApplication, &pipDifMask, pipChosen );
287
288 return;
289 }
290
APP_BUTTON_CALLBACK_H(tedFormatRevertImagePushed,w,voidit)291 static APP_BUTTON_CALLBACK_H( tedFormatRevertImagePushed, w, voidit )
292 {
293 ImageTool * it= (ImageTool *)voidit;
294
295 it->itPropertiesChosen= it->itPropertiesSet;
296
297 tedFormatToolRefreshImagePage( it );
298
299 return;
300 }
301
302 /************************************************************************/
303 /* */
304 /* 1) User wants to validate the scale.. Get scale and display size. */
305 /* 2) User wants to set the image size.. Get size and display scale. */
306 /* 3) Keep track of whether size or scale was last manipulated. */
307 /* */
308 /************************************************************************/
309
310 /* 1 */
tedImageToolWideRelToAbs(ImageTool * it)311 static void tedImageToolWideRelToAbs( ImageTool * it )
312 {
313 PictureProperties * pip= &(it->itPropertiesChosen);
314
315 const int maxValue= INT_MAX;
316 const int adaptToMax= 0;
317 const int minScale= 1;
318 const int adaptToMin= 0;
319
320 if ( appGetIntegerFromTextWidget( it->itXScaleText,
321 &(pip->pipScaleXSet),
322 minScale, adaptToMin,
323 maxValue, adaptToMax ) )
324 { return; }
325
326 tedImageToolShowWideAbs( it );
327
328 return;
329 }
330
331 /* 1 */
tedImageToolHighRelToAbs(ImageTool * it)332 static void tedImageToolHighRelToAbs( ImageTool * it )
333 {
334 PictureProperties * pip= &(it->itPropertiesChosen);
335
336 const int maxValue= INT_MAX;
337 const int adaptToMax= 0;
338 const int minScale= 1;
339 const int adaptToMin= 0;
340
341 if ( appGetIntegerFromTextWidget( it->itYScaleText,
342 &(pip->pipScaleYSet),
343 minScale, adaptToMin,
344 maxValue, adaptToMax ) )
345 { return; }
346
347 tedImageToolShowHighAbs( it );
348
349 return;
350 }
351
352 /* 2 */
tedImageToolWideAbsToRel(ImageTool * it)353 static void tedImageToolWideAbsToRel( ImageTool * it )
354 {
355 PictureProperties * pip= &(it->itPropertiesChosen);
356
357 if ( tedImageToolGetWideAbs( it ) )
358 { return; }
359
360 appIntegerToTextWidget( it->itXScaleText, pip->pipScaleXSet );
361
362 return;
363 }
364
365 /* 2 */
tedImageToolHighAbsToRel(ImageTool * it)366 static void tedImageToolHighAbsToRel( ImageTool * it )
367 {
368 PictureProperties * pip= &(it->itPropertiesChosen);
369
370 if ( tedImageToolGetHighAbs( it ) )
371 { return; }
372
373 appIntegerToTextWidget( it->itYScaleText, pip->pipScaleYSet );
374
375 return;
376 }
377
378 /* 1 */
APP_TXACTIVATE_CALLBACK_H(tedImageXScaleChanged,w,voidit)379 static APP_TXACTIVATE_CALLBACK_H( tedImageXScaleChanged, w, voidit )
380 { tedImageToolWideRelToAbs( (ImageTool *)voidit ); }
381
382 /* 1 */
APP_TXACTIVATE_CALLBACK_H(tedImageYScaleChanged,w,voidit)383 static APP_TXACTIVATE_CALLBACK_H( tedImageYScaleChanged, w, voidit )
384 { tedImageToolHighRelToAbs( (ImageTool *)voidit ); }
385
386 /* 2 */
APP_TXACTIVATE_CALLBACK_H(tedImageWideChanged,w,voidit)387 static APP_TXACTIVATE_CALLBACK_H( tedImageWideChanged, w, voidit )
388 { tedImageToolWideAbsToRel( (ImageTool *)voidit ); }
389
390 /* 2 */
APP_TXACTIVATE_CALLBACK_H(tedImageHighChanged,w,voidit)391 static APP_TXACTIVATE_CALLBACK_H( tedImageHighChanged, w, voidit )
392 { tedImageToolHighAbsToRel( (ImageTool *)voidit ); }
393
394 /* 3 */
APP_TXTYPING_CALLBACK_H(tedImageToolWideAbsTyped,w,voidit)395 static APP_TXTYPING_CALLBACK_H( tedImageToolWideAbsTyped, w, voidit )
396 {
397 ImageTool * it= (ImageTool *)voidit;
398
399 it->itImageWideAbsChanged= 1;
400 return;
401 }
402
403 /* 3 */
APP_TXTYPING_CALLBACK_H(tedImageToolHighAbsTyped,w,voidit)404 static APP_TXTYPING_CALLBACK_H( tedImageToolHighAbsTyped, w, voidit )
405 {
406 ImageTool * it= (ImageTool *)voidit;
407
408 it->itImageHighAbsChanged= 1;
409 return;
410 }
411
412 /* 3 */
APP_TXTYPING_CALLBACK_H(tedImageToolWideRelTyped,w,voidit)413 static APP_TXTYPING_CALLBACK_H( tedImageToolWideRelTyped, w, voidit )
414 {
415 ImageTool * it= (ImageTool *)voidit;
416
417 it->itImageWideAbsChanged= 0;
418 return;
419 }
420
421 /* 3 */
APP_TXTYPING_CALLBACK_H(tedImageToolHighRelTyped,w,voidit)422 static APP_TXTYPING_CALLBACK_H( tedImageToolHighRelTyped, w, voidit )
423 {
424 ImageTool * it= (ImageTool *)voidit;
425
426 it->itImageHighAbsChanged= 0;
427 return;
428 }
429
430 /************************************************************************/
431 /* */
432 /* Make the 'Image' page of the format tool. */
433 /* */
434 /************************************************************************/
435
tedFormatFillImagePage(ImageTool * it,const ImagePageResources * ipr,InspectorSubject * is,APP_WIDGET pageWidget,const InspectorSubjectResources * isr)436 void tedFormatFillImagePage( ImageTool * it,
437 const ImagePageResources * ipr,
438 InspectorSubject * is,
439 APP_WIDGET pageWidget,
440 const InspectorSubjectResources * isr )
441 {
442 const int textColumns= 10;
443
444 /**/
445 it->itPageResources= ipr;
446
447 /**/
448 docInitPictureProperties( &(it->itPropertiesSet) );
449 docInitPictureProperties( &(it->itPropertiesChosen) );
450 bmInitDescription( &(it->itBitmapDescription) );
451 it->itPictureHasBitmap= 0;
452 it->itObjectType= -1;
453 it->itImageType= -1;
454
455 /**************/
456 guiToolMakeLabelAndTextRow( &(it->itObjectTypeRow),
457 &(it->itObjectTypeLabel), &(it->itObjectTypeText),
458 pageWidget, ipr->iprObjectType, textColumns, 0 );
459
460 guiToolMakeLabelAndTextRow( &(it->itImageTypeRow),
461 &(it->itImageTypeLabel), &(it->itImageTypeText),
462 pageWidget, ipr->iprImageType, textColumns, 0 );
463
464 guiToolMakeLabelAndTextRow( &(it->itPixelSizeRow),
465 &(it->itPixelsSizeLabel), &(it->itPixelsSizeText),
466 pageWidget, ipr->iprPixelSize, textColumns, 0 );
467
468 guiToolMakeLabelAndTextRow( &(it->itByteSizeRow),
469 &(it->itByteSizeLabel), &(it->itByteSizeText),
470 pageWidget, ipr->iprTotalBytes, textColumns, 0 );
471
472 guiToolMakeLabelAndTextRow( &(it->itImageWideRow),
473 &(it->itImageWideLabel), &(it->itImageWideText),
474 pageWidget, ipr->iprImageWide, textColumns, 1 );
475
476 guiToolMakeLabelAndTextRow( &(it->itImageHighRow),
477 &(it->itImageHighLabel), &(it->itImageHighText),
478 pageWidget, ipr->iprImageHigh, textColumns, 1 );
479
480 guiToolMakeLabelAndTextRow( &(it->itXScaleRow),
481 &(it->itXScaleLabel), &(it->itXScaleText),
482 pageWidget, ipr->iprXScale, textColumns, 1 );
483
484 guiToolMakeLabelAndTextRow( &(it->itYScaleRow),
485 &(it->itYScaleLabel), &(it->itYScaleText),
486 pageWidget, ipr->iprYScale, textColumns, 1 );
487
488 appGuiSetGotValueCallbackForText( it->itXScaleText,
489 tedImageXScaleChanged, (void *)it );
490 appGuiSetGotValueCallbackForText( it->itYScaleText,
491 tedImageYScaleChanged, (void *)it );
492 appGuiSetTypingCallbackForText( it->itXScaleText,
493 tedImageToolWideRelTyped, (void *)it );
494 appGuiSetTypingCallbackForText( it->itYScaleText,
495 tedImageToolHighRelTyped, (void *)it );
496
497 appGuiSetGotValueCallbackForText( it->itImageWideText,
498 tedImageWideChanged, (void *)it );
499 appGuiSetGotValueCallbackForText( it->itImageHighText,
500 tedImageHighChanged, (void *)it );
501 appGuiSetTypingCallbackForText( it->itImageWideText,
502 tedImageToolWideAbsTyped, (void *)it );
503 appGuiSetTypingCallbackForText( it->itImageHighText,
504 tedImageToolHighAbsTyped, (void *)it );
505
506 /**************/
507
508 guiToolMake2BottonRow( &(is->isApplyRow), pageWidget,
509 &(is->isRevertButton), &(is->isApplyButton),
510 isr->isrRevert, isr->isrApplyToSubject,
511 tedFormatRevertImagePushed, tedFormatChangeImagePushed,
512 (void *)it );
513
514 return;
515 }
516
517 /************************************************************************/
518 /* */
519 /* Clean the image tool. */
520 /* */
521 /************************************************************************/
522
tedInitImageTool(ImageTool * it)523 void tedInitImageTool( ImageTool * it )
524 {
525 docInitPictureProperties( &(it->itPropertiesSet) );
526 docInitPictureProperties( &(it->itPropertiesChosen) );
527 bmInitDescription( &(it->itBitmapDescription) );
528
529 it->itImageHighAbsChanged= 0;
530 it->itImageWideAbsChanged= 0;
531
532 it->itPictureHasBitmap= 0;
533 it->itObjectType= -1;
534 it->itImageType= -1;
535
536 return;
537 }
538
tedCleanImageTool(ImageTool * it)539 void tedCleanImageTool( ImageTool * it )
540 {
541 bmCleanDescription( &(it->itBitmapDescription) );
542
543 return;
544 }
545
546 /************************************************************************/
547 /* */
548 /* Get Image tool resources. */
549 /* */
550 /************************************************************************/
551
552 static AppConfigurableResource TED_TedImageSubjectResourceTable[]=
553 {
554 APP_RESOURCE( "imageToolImage",
555 offsetof(InspectorSubjectResources,isrSubjectName),
556 "Image" ),
557 APP_RESOURCE( "imageToolChangeImage",
558 offsetof(InspectorSubjectResources,isrApplyToSubject),
559 "Apply to Image" ),
560 APP_RESOURCE( "imageToolRevert",
561 offsetof(InspectorSubjectResources,isrRevert),
562 "Revert" ),
563 /* no Next Image */
564 /* no Prev Image */
565 /* no Select Image */
566 /* no Delete Image */
567 /* no Insert Image */
568 /* no Append Image */
569 };
570
571 static AppConfigurableResource TED_TedImageToolResourceTable[]=
572 {
573 APP_RESOURCE( "imageToolObjectType",
574 offsetof(ImagePageResources,iprObjectType),
575 "Object Type" ),
576 APP_RESOURCE( "imageToolImageType",
577 offsetof(ImagePageResources,iprImageType),
578 "Image Type" ),
579
580 APP_RESOURCE( "imageToolPixelSize",
581 offsetof(ImagePageResources,iprPixelSize),
582 "Pixel Size" ),
583 APP_RESOURCE( "imageToolTotalBytes",
584 offsetof(ImagePageResources,iprTotalBytes),
585 "Size in Bytes" ),
586
587 APP_RESOURCE( "imageToolImageWide",
588 offsetof(ImagePageResources,iprImageWide),
589 "Image Wide" ),
590 APP_RESOURCE( "imageToolImageHigh",
591 offsetof(ImagePageResources,iprImageHigh),
592 "Image High" ),
593
594 APP_RESOURCE( "imageToolXScale",
595 offsetof(ImagePageResources,iprXScale),
596 "Horizontal Scale (%)" ),
597 APP_RESOURCE( "imageToolYScale",
598 offsetof(ImagePageResources,iprYScale),
599 "Vertical Scale (%)" ),
600 };
601
tedImageToolGetResourceTable(EditApplication * ea,ImagePageResources * ipr,InspectorSubjectResources * isr)602 void tedImageToolGetResourceTable( EditApplication * ea,
603 ImagePageResources * ipr,
604 InspectorSubjectResources * isr )
605 {
606 static int gotToolResources= 0;
607 static int gotSubjectResources= 0;
608
609 if ( ! gotToolResources )
610 {
611 appGuiGetResourceValues( &gotToolResources, ea, (void *)ipr,
612 TED_TedImageToolResourceTable,
613 sizeof(TED_TedImageToolResourceTable)/
614 sizeof(AppConfigurableResource) );
615 }
616
617 if ( ! gotSubjectResources )
618 {
619 appGuiGetResourceValues( &gotSubjectResources, ea, (void *)isr,
620 TED_TedImageSubjectResourceTable,
621 sizeof(TED_TedImageSubjectResourceTable)/
622 sizeof(AppConfigurableResource) );
623 }
624
625 return;
626 }
627