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 611 612 613
|
/************************************************************************/
/* */
/* Choose a paper format common functionality. */
/* */
/************************************************************************/
# include "appFrameConfig.h"
# include <stdlib.h>
# include <string.h>
# include <appGeoString.h>
# include <appPaper.h>
# include "appPaperChooser.h"
# include <appDebugon.h>
/************************************************************************/
/* */
/* Update the text widget. */
/* */
/************************************************************************/
static void appPaperChooserShowWidthHeight(
PaperChooser * pc,
const DocumentGeometry * dg )
{
char scratch[50];
appGeoRectangleToString( scratch,
dg->dgPageWideTwips, dg->dgPageHighTwips, pc->pcUnitType );
pc->pcProgrammatic++;
appStringToTextWidget( pc->pcSizeText, scratch );
pc->pcProgrammatic--;
return;
}
/************************************************************************/
/* */
/* Extract a paper size from the Text widget. */
/* */
/************************************************************************/
int appPaperChooserGetSize( PropertyMask * pChgMask,
PaperChooser * pc,
DocumentGeometry * dg )
{
char * s;
DocumentGeometry dgHere;
PropertyMask updMask;
PropertyMask chgMask;
dgHere= *dg;
PROPmaskCLEAR( &updMask );
PROPmaskCLEAR( &chgMask );
PROPmaskADD( &updMask, DGpropPAGE_WIDTH );
PROPmaskADD( &updMask, DGpropPAGE_HEIGHT );
s= appGetStringFromTextWidget( pc->pcSizeText );
if ( appGeoRectangleFromString( s, pc->pcUnitType,
&(dgHere.dgPageWideTwips),
&(dgHere.dgPageHighTwips) ) ||
dgHere.dgPageWideTwips <= 0 ||
dgHere.dgPageHighTwips <= 0 )
{
appFreeStringFromTextWidget( s );
appRefuseTextValue( pc->pcSizeText );
return -1;
}
appFreeStringFromTextWidget( s );
appSetDocumentGeometry( dg, &dgHere, &chgMask, &updMask );
*pChgMask= chgMask;
return 0;
}
/************************************************************************/
/* */
/* Adapt to geometry. */
/* */
/* 1) Show the orientation in the radiogroup. */
/* 2) Derive the values to show in the radiogroup and the size menu */
/* from the rectangle. */
/* 3) Set the orientation buttons and the paper size menu. */
/* */
/************************************************************************/
/* 1 */
static void appPaperChooserShowOrientation( PaperChooser * pc )
{
if ( ! pc->pcPortraitRadio || ! pc->pcLandscapeRadio )
{ XXDEB(pc->pcPortraitRadio,pc->pcLandscapeRadio); return; }
pc->pcProgrammatic++;
if ( pc->pcLandscapeChosen )
{
appGuiSetToggleState( pc->pcPortraitRadio, 0 );
appGuiSetToggleState( pc->pcLandscapeRadio, 1 );
}
else{
appGuiSetToggleState( pc->pcPortraitRadio, 1 );
appGuiSetToggleState( pc->pcLandscapeRadio, 0 );
}
pc->pcProgrammatic--;
return;
}
/* 2 */
static void appPaperChooserWidgetSettings(
int * pLandscape,
int * pSizeNr,
int custom,
const DocumentGeometry * dg )
{
int sizeNr;
int landscape;
if ( dg->dgPageWideTwips > dg->dgPageHighTwips )
{
sizeNr= appPaperGetBySize( dg->dgPageHighTwips, dg->dgPageWideTwips );
landscape= 1;
}
else{
sizeNr= appPaperGetBySize( dg->dgPageWideTwips, dg->dgPageHighTwips );
landscape= 0;
}
if ( sizeNr < 0 )
{ sizeNr= custom; }
*pLandscape= landscape;
*pSizeNr= sizeNr;
return;
}
/* 3 */
static void appPaperChooserSetWidgets( PaperChooser * pc,
int sizeNr,
int landscape )
{
if ( pc->pcSizeChosen != sizeNr )
{
pc->pcSizeChosen= sizeNr;
pc->pcProgrammatic++;
appSetOptionmenu( &(pc->pcOptionmenu), pc->pcSizeChosen );
pc->pcProgrammatic--;
}
if ( pc->pcLandscapeChosen != landscape )
{
pc->pcLandscapeChosen= landscape;
if ( pc->pcPortraitRadio &&
pc->pcLandscapeRadio )
{ appPaperChooserShowOrientation( pc ); }
}
return;
}
void appPaperChooserAdaptToGeometry( PaperChooser * pc,
const DocumentGeometry * dg )
{
int sizeNr;
int landscape;
pc->pcGeometryChosen= *dg;
appPaperChooserShowWidthHeight( pc, &(pc->pcGeometryChosen) );
appPaperChooserWidgetSettings( &landscape, &sizeNr,
pc->pcCustomPaperSize, &(pc->pcGeometryChosen) );
appPaperChooserSetWidgets( pc, sizeNr, landscape );
return;
}
/************************************************************************/
/* */
/* A paper size was chosen in the menu. As far as the paper chooser */
/* is concerned no more needs to be done. */
/* */
/************************************************************************/
static APP_OITEM_CALLBACK_H( appPaperChooserSizeChosen, w, voidpc )
{
PaperChooser * pc= (PaperChooser *)voidpc;
int changed= 0;
int i= -1;
int width;
int height;
if ( pc->pcProgrammatic )
{ return; }
i= appGuiGetOptionmenuItemIndex( &(pc->pcOptionmenu), w );
if ( i < 0 || i >= pc->pcSizeOptionCount )
{ LLDEB(i,pc->pcSizeOptionCount); return; }
pc->pcSizeChosen= i;
if ( i == pc->pcCustomPaperSize )
{
PropertyMask updMask;
DocumentGeometry dgScratch;
PROPmaskCLEAR( &updMask );
if ( appPaperChooserGetSize( &updMask, pc, &dgScratch ) )
{ LDEB(1); return; }
width= dgScratch.dgPageWideTwips;
height= dgScratch.dgPageHighTwips;
if ( width > height )
{ pc->pcLandscapeChosen= 1; }
else{ pc->pcLandscapeChosen= 0; }
}
else{
if ( appPaperGetInformation( i, &width, &height, (const char **)0 ) )
{ return; }
if ( pc->pcLandscapeChosen )
{
int swap;
swap= height; height= width; width= swap;
}
}
if ( pc->pcGeometryChosen.dgPageWideTwips != width ||
pc->pcGeometryChosen.dgPageHighTwips != height )
{ changed= 1; }
pc->pcGeometryChosen.dgPageWideTwips= width;
pc->pcGeometryChosen.dgPageHighTwips= height;
appPaperChooserShowWidthHeight( pc, &(pc->pcGeometryChosen) );
if ( changed && pc->pcCallback )
{
(*pc->pcCallback)( pc, pc->pcCallbackThrough,
&(pc->pcGeometryChosen) );
}
return;
}
/************************************************************************/
/* */
/* Make the widgets for a paper chooser. */
/* */
/************************************************************************/
static APP_TXTYPING_CALLBACK_H( appPaperChooserTypingCallback, w, voidpc )
{
PaperChooser * pc= (PaperChooser *)voidpc;
char * s;
DocumentGeometry dgHere;
if ( pc->pcProgrammatic )
{ return; }
s= appGetStringFromTextWidget( pc->pcSizeText );
if ( ! appGeoRectangleFromString( s, pc->pcUnitType,
&(dgHere.dgPageWideTwips),
&(dgHere.dgPageHighTwips) ) &&
dgHere.dgPageWideTwips > 0 &&
dgHere.dgPageHighTwips > 0 )
{
int sizeNr;
int landscape;
appPaperChooserWidgetSettings( &landscape, &sizeNr,
pc->pcCustomPaperSize, &dgHere );
appPaperChooserSetWidgets( pc, sizeNr, landscape );
}
appFreeStringFromTextWidget( s );
return;
}
/************************************************************************/
/* */
/* Callback when the user pushes return in the edit. */
/* */
/************************************************************************/
static APP_TXACTIVATE_CALLBACK_H( appPaperChooserGotValueCallback, w, voidpc )
{
PaperChooser * pc= (PaperChooser *)voidpc;
PropertyMask updMask;
PROPmaskCLEAR( &updMask );
if ( pc->pcProgrammatic )
{ return; }
if ( appPaperChooserGetSize( &updMask, pc, &(pc->pcGeometryChosen) ) )
{ LDEB(1); return; }
if ( ! PROPmaskISEMPTY( &updMask ) )
{
appPaperChooserAdaptToGeometry( pc, &(pc->pcGeometryChosen) );
if ( pc->pcCallback )
{
(*pc->pcCallback)( pc, pc->pcCallbackThrough,
&(pc->pcGeometryChosen) );
}
}
return;
}
/************************************************************************/
/* */
/* One of the orientation toggles was activated. As far as the paper */
/* chooser is concerned no more needs to be done. */
/* */
/* The contorted logic of this function is dictated by the fact that */
/* GTK invokes callbacks for programmatic changes to the toggle */
/* buttons. This is a curse we have to live with. */
/* */
/************************************************************************/
static void appPaperChooserOrientationChanged( PaperChooser * pc )
{
int swap;
swap= pc->pcGeometryChosen.dgPageWideTwips;
pc->pcGeometryChosen.dgPageWideTwips=
pc->pcGeometryChosen.dgPageHighTwips;
pc->pcGeometryChosen.dgPageHighTwips= swap;
appPaperChooserShowWidthHeight( pc, &(pc->pcGeometryChosen) );
if ( pc->pcCallback )
{
(*pc->pcCallback)( pc, pc->pcCallbackThrough,
&(pc->pcGeometryChosen) );
}
return;
}
static APP_TOGGLE_CALLBACK_H( appPaperChooserLandscapeToggled, w, voidpc, e )
{
PaperChooser * pc= (PaperChooser *)voidpc;
int change= 0;
int set;
if ( pc->pcProgrammatic )
{ return; }
set= appGuiGetToggleStateFromCallback( w, e );
if ( pc->pcLandscapeChosen )
{
if ( ! set )
{
pc->pcProgrammatic++;
appGuiSetToggleState( pc->pcLandscapeRadio, 1 );
pc->pcProgrammatic--;
}
}
else{
if ( set )
{
pc->pcLandscapeChosen= 1;
pc->pcProgrammatic++;
appGuiSetToggleState( pc->pcPortraitRadio, 0 );
pc->pcProgrammatic--;
change= 1;
}
}
if ( change )
{ appPaperChooserOrientationChanged( pc ); }
return;
}
static APP_TOGGLE_CALLBACK_H( appPaperChooserPortraitToggled, w, voidpc, e )
{
PaperChooser * pc= (PaperChooser *)voidpc;
int change= 0;
int set;
if ( pc->pcProgrammatic )
{ return; }
set= appGuiGetToggleStateFromCallback( w, e );
if ( pc->pcLandscapeChosen )
{
if ( set )
{
pc->pcLandscapeChosen= 0;
pc->pcProgrammatic++;
appGuiSetToggleState( pc->pcLandscapeRadio, 0 );
pc->pcProgrammatic--;
change= 1;
}
}
else{
if ( ! set )
{
pc->pcProgrammatic++;
appGuiSetToggleState( pc->pcPortraitRadio, 1 );
pc->pcProgrammatic--;
}
}
if ( change )
{ appPaperChooserOrientationChanged( pc ); }
return;
}
/************************************************************************/
/* */
/* Make the widgets in a paper chooser and install the callback. */
/* */
/************************************************************************/
void appMakePaperChooserWidgets( APP_WIDGET parent,
const char * title,
int unitType,
PaperChooser * pc,
PaperChooserCallback callback,
void * through )
{
const int textEnabled= 1;
pc->pcUnitType= unitType;
pc->pcCallback= callback;
pc->pcCallbackThrough= through;
appMakeColumnFrameInColumn( &(pc->pcFrame),
&(pc->pcVerticalColumn), parent, title );
appMakeOptionmenuInColumn( &(pc->pcOptionmenu), pc->pcVerticalColumn );
appMakeTextInColumn( &(pc->pcSizeText), pc->pcVerticalColumn,
0, textEnabled );
appGuiSetGotValueCallbackForText( pc->pcSizeText,
appPaperChooserGotValueCallback, (void *)pc );
appGuiSetTypingCallbackForText( pc->pcSizeText,
appPaperChooserTypingCallback, (void *)pc );
return;
}
/************************************************************************/
/* */
/* Add Portrait/Landscape toggles to a paper chooser. */
/* */
/************************************************************************/
void appPaperChooserAddOrientationToggles( PaperChooser * pc,
const char * portrait,
const char * landscape )
{
const int heightResizable= 0;
pc->pcOrientationRow= appMakeRowInColumn( pc->pcVerticalColumn, 2,
heightResizable );
pc->pcPortraitRadio= appMakeToggleInRow( pc->pcOrientationRow,
portrait, appPaperChooserPortraitToggled, (void *)pc, 0 );
pc->pcLandscapeRadio= appMakeToggleInRow( pc->pcOrientationRow,
landscape, appPaperChooserLandscapeToggled, (void *)pc, 1 );
return;
}
/************************************************************************/
/* */
/* Fill the list of paper sizes. */
/* */
/************************************************************************/
void appPaperChooserFillMenu( PaperChooser * pc,
const char * customLabel )
{
const char * label;
int i;
int gotSome= 0;
if ( ! pc->pcSizeOptions )
{
i= 0;
while( ! appPaperGetInformation( i, (int *)0, (int *)0, &label ) )
{ i++; }
pc->pcCustomPaperSize= i++;
pc->pcSizeOptionCount= i;
pc->pcSizeOptions= realloc( pc->pcSizeOptions,
pc->pcSizeOptionCount* sizeof(APP_WIDGET) );
if ( ! pc->pcSizeOptions )
{ LXDEB(pc->pcSizeOptionCount,pc->pcSizeOptions); return; }
for ( i= 0; i < pc->pcSizeOptionCount; i++ )
{ pc->pcSizeOptions[i]= (APP_WIDGET)0; }
}
appEmptyOptionmenu( &(pc->pcOptionmenu) );
i= 0;
while( ! appPaperGetInformation( i, (int *)0, (int *)0, &label ) )
{
pc->pcSizeOptions[i]= appAddItemToOptionmenu( &(pc->pcOptionmenu),
label, appPaperChooserSizeChosen, (void *)pc );
if ( i == 0 )
{ gotSome= 1; }
i++;
}
pc->pcSizeOptions[i]= appAddItemToOptionmenu( &(pc->pcOptionmenu),
customLabel, appPaperChooserSizeChosen, (void *)pc );
if ( i == 0 )
{ gotSome= 1; }
if ( gotSome )
{
appSetOptionmenu( &(pc->pcOptionmenu), 0 );
pc->pcSizeChosen= 0;
}
else{
appSetOptionmenu( &(pc->pcOptionmenu), -1 );
}
appOptionmenuRefreshWidth( &(pc->pcOptionmenu) );
return;
}
/************************************************************************/
/* */
/* Initialize a fresh PaperChooser. */
/* */
/************************************************************************/
void appCleanPaperChooser( PaperChooser * pc )
{
if ( pc->pcSizeOptions )
{ free( pc->pcSizeOptions ); }
}
void appInitPaperChooser( PaperChooser * pc )
{
pc->pcFrame= (APP_WIDGET)0;
pc->pcVerticalColumn= (APP_WIDGET)0;
appInitOptionmenu( &(pc->pcOptionmenu) );
pc->pcSizeText= (APP_WIDGET)0;
pc->pcOrientationRow= (APP_WIDGET)0;
pc->pcPortraitRadio= (APP_WIDGET)0;
pc->pcLandscapeRadio= (APP_WIDGET)0;
pc->pcCustomPaperSize= -1;
pc->pcSizeChosen= -1;
pc->pcLandscapeChosen= -1;
appInitDocumentGeometry( &(pc->pcGeometryChosen) );
pc->pcSizeOptions= (APP_WIDGET *)0;
pc->pcSizeOptionCount= 0;
pc->pcCallback= (PaperChooserCallback)0;
pc->pcCallbackThrough= (void *)0;
pc->pcProgrammatic= 0;
return;
}
|