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
|
/************************************************************************/
/* */
/* A Page Layout tool. */
/* */
/************************************************************************/
# include "appFrameConfig.h"
# include <stdlib.h>
# include <stdio.h>
# include <limits.h>
# include <appDebugon.h>
# include <utilPropMask.h>
# include <appFrame.h>
# include "appMarginTool.h"
/************************************************************************/
/* */
/* Show the size of the paper in the Text. */
/* */
/************************************************************************/
void appMarginToolShowMargins( AppMarginTool * amt,
int unitInt,
const DocumentGeometry * dg )
{
char scratch[50];
appGeoLengthToString( scratch, dg->dgLeftMarginTwips, unitInt );
appStringToTextWidget( amt->amtLeftMarginText, scratch );
appGeoLengthToString( scratch, dg->dgTopMarginTwips, unitInt );
appStringToTextWidget( amt->amtTopMarginText, scratch );
appGeoLengthToString( scratch, dg->dgRightMarginTwips, unitInt );
appStringToTextWidget( amt->amtRightMarginText, scratch );
appGeoLengthToString( scratch, dg->dgBottomMarginTwips, unitInt );
appStringToTextWidget( amt->amtBottomMarginText, scratch );
return;
}
/************************************************************************/
/* */
/* Get one/all margins from the text widgets. */
/* */
/************************************************************************/
int appMarginToolGetMargins( PropertyMask * pUpdMask,
const PropertyMask * chgMask,
int unitType,
AppMarginTool * amt,
DocumentGeometry * dg )
{
int changed;
const int minValue= 1;
const int adaptToMin= 0;
const int maxValue= INT_MAX;
const int adaptToMax= 0;
PropertyMask updMask;
PROPmaskCLEAR( &updMask );
if ( PROPmaskISSET( chgMask, DGpropLEFT_MARGIN ) )
{
if ( appGetLengthFromTextWidget( amt->amtLeftMarginText,
&dg->dgLeftMarginTwips, &changed, unitType,
minValue, adaptToMin, maxValue, adaptToMax ) )
{ return -1; }
if ( changed )
{ PROPmaskADD( &updMask, DGpropLEFT_MARGIN ); }
}
if ( PROPmaskISSET( chgMask, DGpropTOP_MARGIN ) )
{
if ( appGetLengthFromTextWidget( amt->amtTopMarginText,
&dg->dgTopMarginTwips, &changed, unitType,
minValue, adaptToMin, maxValue, adaptToMax ) )
{ return -1; }
if ( changed )
{ PROPmaskADD( &updMask, DGpropTOP_MARGIN ); }
}
if ( PROPmaskISSET( chgMask, DGpropRIGHT_MARGIN ) )
{
if ( appGetLengthFromTextWidget( amt->amtRightMarginText,
&dg->dgRightMarginTwips, &changed, unitType,
minValue, adaptToMin, maxValue, adaptToMax ) )
{ return -1; }
if ( changed )
{ PROPmaskADD( &updMask, DGpropRIGHT_MARGIN ); }
}
if ( PROPmaskISSET( chgMask, DGpropBOTTOM_MARGIN ) )
{
if ( appGetLengthFromTextWidget( amt->amtBottomMarginText,
&dg->dgBottomMarginTwips, &changed, unitType,
minValue, adaptToMin, maxValue, adaptToMax ) )
{ return -1; }
if ( changed )
{ PROPmaskADD( &updMask, DGpropBOTTOM_MARGIN ); }
}
*pUpdMask= updMask; return 0;
}
/************************************************************************/
/* */
/* Check margins. */
/* */
/************************************************************************/
int appMarginToolCheckMargins( const DocumentGeometry * dg )
{
if ( dg->dgLeftMarginTwips+ dg->dgRightMarginTwips >=
dg->dgPageWideTwips )
{ return -1; }
if ( dg->dgTopMarginTwips+ dg->dgBottomMarginTwips >=
dg->dgPageWideTwips )
{ return -1; }
return 0;
}
/************************************************************************/
/* */
/* Make the frame for the margins. */
/* */
/************************************************************************/
void appMakeMarginToolWidgets( APP_WIDGET parent,
const MarginToolResources * mtr,
AppMarginTool * amt,
APP_TEXT_ACTIVATE_CALLBACK changed,
void * through )
{
APP_WIDGET label;
APP_WIDGET row;
const int textWidth= 7;
const int textEnabled= 1;
appMakeRowFrameInColumn( &(amt->amtMarginFrame), &(amt->amtInsideWidget),
parent, 2, mtr->mtrTitleText );
appMakeColumnInRow( &(amt->amtLeftColumn), amt->amtInsideWidget, 0 );
appMakeColumnInRow( &(amt->amtRightColumn), amt->amtInsideWidget, 1 );
/**********************/
appMakeLabelAndTextRow( &row, &label, &(amt->amtLeftMarginText),
amt->amtLeftColumn, mtr->mtrLeftMarginText,
textWidth, textEnabled );
appMakeLabelAndTextRow( &row, &label, &(amt->amtRightMarginText),
amt->amtLeftColumn, mtr->mtrRightMarginText,
textWidth, textEnabled );
appMakeLabelAndTextRow( &row, &label, &(amt->amtTopMarginText),
amt->amtRightColumn, mtr->mtrTopMarginText,
textWidth, textEnabled );
appMakeLabelAndTextRow( &row, &label, &(amt->amtBottomMarginText),
amt->amtRightColumn, mtr->mtrBottomMarginText,
textWidth, textEnabled );
if ( changed )
{
appGuiSetGotValueCallbackForText( amt->amtLeftMarginText,
changed, through );
appGuiSetGotValueCallbackForText( amt->amtTopMarginText,
changed, through );
appGuiSetGotValueCallbackForText( amt->amtRightMarginText,
changed, through );
appGuiSetGotValueCallbackForText( amt->amtBottomMarginText,
changed, through );
}
return;
}
|