From d1a8285f818eb7e5c3d6a05709ea21a808490b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 19 Mar 2018 19:55:58 +0100 Subject: New upstream version 5.1.0 --- app/bin/param.c | 391 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 227 insertions(+), 164 deletions(-) (limited to 'app/bin/param.c') diff --git a/app/bin/param.c b/app/bin/param.c index 27c558f..e513bc3 100644 --- a/app/bin/param.c +++ b/app/bin/param.c @@ -21,6 +21,7 @@ */ #include +#include #include #ifndef WINDOWS #include @@ -45,12 +46,17 @@ #include #include #include -#include "track.h" + #include "common.h" -#include "utility.h" -#include "misc.h" #include "compound.h" +#include "custom.h" +#include "fileio.h" #include "i18n.h" +#include "messages.h" +#include "misc.h" +#include "param.h" +#include "track.h" +#include "utility.h" /* Bogus reg vars */ @@ -65,10 +71,6 @@ EXPORT char *PREFSECT = "DialogItem"; static int paramCheckErrorCount = 0; static BOOL_T paramCheckShowErrors = FALSE; -static int log_hotspot; -static int hotspotOffsetX = 5; -static int hotspotOffsetY = 19; - static int log_paramLayout; @@ -168,88 +170,119 @@ static int GetNumberStr( char ** cpp, FLOAT_T * numP, BOOL_T * hasFract ) } //extern wIndex_t distanceFormatInx; // distanceFormatInx -static BOOL_T GetDistance( char ** cpp, FLOAT_T * distP ) +static BOOL_T GetDistance(char ** cpp, FLOAT_T * distP) { - FLOAT_T n1, n2; - BOOL_T neg = FALSE; - BOOL_T hasFract; - BOOL_T expectInch = FALSE; - long distanceFormat; - - while ( isspace((unsigned char)**cpp) ) (*cpp)++; - if ( (*cpp)[0] == '\0' ) { - *distP = 0.0; - return TRUE; - } - if ( (*cpp)[0] == '-' ) { - neg = TRUE; - (*cpp)++; - } - if ( !GetNumberStr( cpp, &n1, &hasFract ) ) return FALSE; - - distanceFormat = GetDistanceFormat(); - - - if ( (*cpp)[0] == '\0' ) { /* EOL */ - if ( units==UNITS_METRIC ) - { - n1 = n1/2.54; - if ((distanceFormat & DISTFMT_FMT) == DISTFMT_FMT_MM) - n1 /= 10; - if ((distanceFormat & DISTFMT_FMT) == DISTFMT_FMT_M) - n1 *= 100; - } else { - if (((distanceFormat & DISTFMT_FMT) == DISTFMT_FMT_SHRT) || ((distanceFormat & DISTFMT_FMT) == DISTFMT_FMT_LONG)) - n1 *= 12; - } - if ( neg ) - n1 = -n1; - *distP = n1; - return TRUE; - } - if ( (*cpp)[0] == '\'' ) { - n1 *= 12.0; - (*cpp) += 1; - expectInch = !hasFract; - } else if ( tolower((unsigned char)(*cpp)[0]) == 'f' && tolower((unsigned char)(*cpp)[1]) == 't' ) { - n1 *= 12.0; - (*cpp) += 2; - expectInch = !hasFract; - } else if ( tolower((unsigned char)(*cpp)[0]) == 'c' && tolower((unsigned char)(*cpp)[1]) == 'm' ) { - n1 /= 2.54; - (*cpp) += 2; - } else if ( tolower((unsigned char)(*cpp)[0]) == 'm' && tolower((unsigned char)(*cpp)[1]) == 'm' ) { - n1 /= 25.4; - (*cpp) += 2; - } else if ( tolower((unsigned char)(*cpp)[0]) == 'm' ) { - n1 *= 100.0/2.54; - (*cpp) += 1; - } else if ( (*cpp)[0] == '"' ) { - (*cpp) += 1; - } else if ( tolower((unsigned char)(*cpp)[0]) == 'i' && tolower((unsigned char)(*cpp)[1]) == 'n' ) { - (*cpp) += 2; - } else { - getNumberError = N_("Invalid Units Indicator"); - return FALSE; - } - while ( isspace((unsigned char)**cpp) ) (*cpp)++; - if ( expectInch && isdigit( (unsigned char)**cpp ) ) { - if ( !GetNumberStr( cpp, &n2, &hasFract ) ) return FALSE; - n1 += n2; - if ( (*cpp)[0] == '"' ) - (*cpp) += 1; - else if ( tolower((unsigned char)(*cpp)[0]) == 'i' && tolower((unsigned char)(*cpp)[1]) == 'n' ) - (*cpp) += 2; - while ( isspace((unsigned char)**cpp) ) (*cpp)++; - } - if ( **cpp ) { - getNumberError = N_("Expected End Of String"); - return FALSE; - } - if ( neg ) - n1 = -n1; - *distP = n1; - return TRUE; + FLOAT_T n1, n2; + BOOL_T neg = FALSE; + BOOL_T hasFract; + BOOL_T expectInch = FALSE; + long distanceFormat; + + while (isspace((unsigned char)**cpp)) { + (*cpp)++; + } + + if ((*cpp)[0] == '\0') { + *distP = 0.0; + return TRUE; + } + + if ((*cpp)[0] == '-') { + neg = TRUE; + (*cpp)++; + } + + if (!GetNumberStr(cpp, &n1, &hasFract)) { + return FALSE; + } + + distanceFormat = GetDistanceFormat(); + + if ((*cpp)[0] == '\0') { /* EOL */ + if (units==UNITS_METRIC) { + n1 = n1/2.54; + + if ((distanceFormat & DISTFMT_FMT) == DISTFMT_FMT_MM) { + n1 /= 10; + } + + if ((distanceFormat & DISTFMT_FMT) == DISTFMT_FMT_M) { + n1 *= 100; + } + } + + if (neg) { + n1 = -n1; + } + + *distP = n1; + return TRUE; + } + + if ((*cpp)[0] == '\'') { + n1 *= 12.0; + (*cpp) += 1; + expectInch = !hasFract; + } else if (tolower((unsigned char)(*cpp)[0]) == 'f' && + tolower((unsigned char)(*cpp)[1]) == 't') { + n1 *= 12.0; + (*cpp) += 2; + expectInch = !hasFract; + } else if (tolower((unsigned char)(*cpp)[0]) == 'c' && + tolower((unsigned char)(*cpp)[1]) == 'm') { + n1 /= 2.54; + (*cpp) += 2; + } else if (tolower((unsigned char)(*cpp)[0]) == 'm' && + tolower((unsigned char)(*cpp)[1]) == 'm') { + n1 /= 25.4; + (*cpp) += 2; + } else if (tolower((unsigned char)(*cpp)[0]) == 'm') { + n1 *= 100.0/2.54; + (*cpp) += 1; + } else if ((*cpp)[0] == '"') { + (*cpp) += 1; + } else if (tolower((unsigned char)(*cpp)[0]) == 'i' && + tolower((unsigned char)(*cpp)[1]) == 'n') { + (*cpp) += 2; + } else { + getNumberError = N_("Invalid Units Indicator"); + return FALSE; + } + + while (isspace((unsigned char)**cpp)) { + (*cpp)++; + } + + if (expectInch && isdigit((unsigned char)**cpp)) { + if (!GetNumberStr(cpp, &n2, &hasFract)) { + return FALSE; + } + + n1 += n2; + + if ((*cpp)[0] == '"') { + (*cpp) += 1; + } else if (tolower((unsigned char)(*cpp)[0]) == 'i' && + tolower((unsigned char)(*cpp)[1]) == 'n') { + (*cpp) += 2; + } + + while (isspace((unsigned char)**cpp)) { + (*cpp)++; + } + } + + if (**cpp) { + getNumberError = N_("Expected End Of String"); + return FALSE; + } + + if (neg) { + n1 = -n1; + } + + *distP = n1; + return TRUE; } @@ -279,46 +312,57 @@ EXPORT FLOAT_T DecodeFloat( } -EXPORT FLOAT_T DecodeDistance( - wString_p strCtrl, - BOOL_T * validP ) +FLOAT_T DecodeDistance( + wString_p strCtrl, + BOOL_T * validP) { - FLOAT_T valF; - char *cp0, *cp1, *cpN, c1; - - cp0 = cp1 = cpN = CAST_AWAY_CONST wStringGetValue( strCtrl ); - cpN += strlen(cpN)-1; - while (cpN > cp1 && isspace((unsigned char)*cpN) ) cpN--; - c1 = *cpN; - switch ( c1 ) { - case '=': - case 's': - case 'S': - case 'p': - case 'P': - *cpN = '\0'; - break; - default: - cpN = NULL; - } - *validP = ( GetDistance( &cp1, &valF ) ); - if ( cpN ) - *cpN = c1; - if ( *validP ) { -/*fprintf( stderr, "gd=%0.6f\n", valF );*/ - if ( c1 == 's' || c1 == 'S' ) - valF *= curScaleRatio; - else if ( c1 == 'p' || c1 == 'P' ) - valF /= curScaleRatio; - if ( cpN ) - wStringSetValue( strCtrl, FormatDistance( valF ) ); - } else { -/*fprintf( stderr, "Gd( @%s ) error=%s\n", cp1, getNumberError );*/ - sprintf( decodeErrorStr, "%s @ %s", _(getNumberError), *cp1?cp1:_("End Of String") ); - /*wStringSetHilight( strCtrl, cp1-cp0, -1 ); */ - valF = 0.0; - } - return valF; + FLOAT_T valF; + char *cp0, *cp1, *cpN, c1; + cp0 = cp1 = cpN = CAST_AWAY_CONST wStringGetValue(strCtrl); + cpN += strlen(cpN)-1; + + while (cpN > cp1 && isspace((unsigned char)*cpN)) { + cpN--; + } + + c1 = *cpN; + + switch (c1) { + case '=': + case 's': + case 'S': + case 'p': + case 'P': + *cpN = '\0'; + break; + + default: + cpN = NULL; + } + + *validP = (GetDistance(&cp1, &valF)); + + if (cpN) { + *cpN = c1; + } + + if (*validP) { + if (c1 == 's' || c1 == 'S') { + valF *= curScaleRatio; + } else if (c1 == 'p' || c1 == 'P') { + valF /= curScaleRatio; + } + + if (cpN) { + wStringSetValue(strCtrl, FormatDistance(valF)); + } + } else { + sprintf(decodeErrorStr, "%s @ %s", _(getNumberError), + *cp1?cp1:_("End Of String")); + valF = 0.0; + } + + return valF; } @@ -542,10 +586,18 @@ EXPORT void ParamLoadControl( p->oldD.f = tmpR; break; case PD_STRING: - wStringSetValue( (wString_p)p->control, (char*)p->valueP ); if (p->oldD.s) MyFree( p->oldD.s ); - p->oldD.s = MyStrdup( (char*)p->valueP ); + if (p->context) { + p->oldD.s = MyMalloc((intptr_t)p->context); + strncpy(p->oldD.s, (char*)p->valueP, (intptr_t)p->context); + *(p->oldD.s + (intptr_t)p->context - 1) = '\0'; + wStringSetValue((wString_p)p->control, (char*)p->oldD.s); + } + else { + p->oldD.s = MyStrdup((char *)p->valueP); + wStringSetValue((wString_p)p->control, (char*)p->valueP); + } break; case PD_MESSAGE: wMessageSetValue( (wMessage_p)p->control, _((char*)p->valueP) ); @@ -558,6 +610,7 @@ EXPORT void ParamLoadControl( case PD_DRAW: case PD_MENU: case PD_MENUITEM: + case PD_BITMAP: break; } } @@ -677,8 +730,20 @@ EXPORT long ParamUpdate( if (p->oldD.s) MyFree( p->oldD.s ); p->oldD.s = MyStrdup( stringV ); - if ( /*(p->option&PDO_NOUPDUPD)==0 &&*/ p->valueP) - strcpy( (char*)p->valueP, stringV ); + if ( /*(p->option&PDO_NOUPDUPD)==0 &&*/ p->valueP) { + if (p->context) { + strncpy((char*)p->valueP, stringV, (intptr_t)p->context); + ((char *)p->valueP)[(intptr_t)p->context - 1] = '\0'; + if (strlen(stringV) > (uintptr_t)p->context) { + NoticeMessage2(0, MSG_ENTERED_STRING_TRUNCATED, _("Ok"), NULL, (intptr_t)p->context); + } + + } + else { + strcpy((char*)p->valueP, stringV); + } + } + if ( (p->option&PDO_NOUPDACT)==0 && pg->changeProc) pg->changeProc( pg, inx, CAST_AWAY_CONST stringV ); change |= (1L<option&PDO_LISTINDEX) ) { if (!wPrefGetInteger( PREFSECT, prefName1, &valL, *(wIndex_t*)p->valueP )) - wPrefGetInteger( prefSect2, prefName2, &valL, *(wIndex_t*)p->valueP ); + wPrefGetInteger( prefSect2, prefName2, &valL, valL ); if ( p->control ) wListSetIndex( (wList_p)p->control, (wIndex_t)valL ); *(wIndex_t*)p->valueP = (wIndex_t)valL; @@ -1185,6 +1254,7 @@ EXPORT void ParamGroupRecord( case PD_TEXT: case PD_MENU: case PD_MENUITEM: + case PD_BITMAP: break; } } @@ -1517,7 +1587,7 @@ EXPORT void ParamChange( paramData_p p ) case PD_DROPLIST: case PD_COMBOLIST: if (recordF && (p->option&PDO_NORECORD)==0 && p->group->nameStr && p->nameStr) { - fprintf( recordF, "PARAMETER %s %s %d %s\n", p->group->nameStr, p->nameStr, *(wIndex_t*)p->valueP, ??? ); + fprintf( recordF, "PARAMETER %s %s %d %s\n", p->group->nameStr, p->nameStr, *(wIndex_t*)p->valueP, "???" ); } #ifdef LATER if ( p->control && (p->option&PDO_NOCONTUPD) == 0 ) @@ -1776,6 +1846,7 @@ static void ParamPlayback( char * line ) case PD_MESSAGE: case PD_TEXT: case PD_MENU: + case PD_BITMAP: break; case PD_MENUITEM: if (p->valueP) { @@ -1926,6 +1997,7 @@ static void ParamCheck( char * line ) case PD_TEXT: case PD_MENU: case PD_MENUITEM: + case PD_BITMAP: break; } if ( hasError ) { @@ -1965,7 +2037,6 @@ static void ParamCreateControl( paramTextData_t * textDataP; paramListData_t * listDataP; wIcon_p iconP; - wDrawColor color = wDrawColorBlack; wWin_p win; wPos_t w; @@ -2049,8 +2120,8 @@ static void ParamCreateControl( listDataP->height = wControlGetHeight( pd->control ); break; case PD_COLORLIST: - pd->control = (wControl_p)wColorSelectButtonCreate( win, xx, yy, helpStr, _(pd->winLabel), pd->winOption, 0, &color, ParamColorSelectPush, pd ); - break; + pd->control = (wControl_p)wColorSelectButtonCreate( win, xx, yy, helpStr, _(pd->winLabel), pd->winOption, 0, NULL, ParamColorSelectPush, pd ); + break; case PD_MESSAGE: if ( pd->winData != 0 ) w = (wPos_t)(long)pd->winData; @@ -2312,10 +2383,6 @@ static void LayoutControls( char * cp; strcpy( message, pd->nameStr ); for ( cp=message; *cp; cp++ ) if ( *cp == '-' ) *cp = '_'; - LOG( log_hotspot, 1, ( "popup %d %d %d %d _%s_%s\n", - controlK.orig.x+hotspotOffsetX, controlK.orig.y+hotspotOffsetY, - controlSize_x, controlSize_y, - group->nameStr, message ) ) } /* * Set column term @@ -2437,9 +2504,21 @@ static void ParamDlgProc( } } +/** + * Create a dialog box from data definition. + * + * \param IN group data definition for the dialog + * \param IN title title of the new dialog + * \param IN okLabel text for the affirmative button + * \param IN okProc subroutine to call when ok is pressed + * \param IN cancelProc if not NULL a subroutine for Cancel event. If NULL no cancel button is created + * \param IN needHelpButton if TRUE a help button is created + * \param IN layoutProc ??? + * \param IN winOption ??? + * \param IN changeProc ??? + */ - -EXPORT wWin_p ParamCreateDialog( +wWin_p ParamCreateDialog( paramGroup_p group, char * title, char * okLabel, @@ -2452,7 +2531,6 @@ EXPORT wWin_p ParamCreateDialog( { char helpStr[STR_SHORT_SIZE]; wPos_t w0, h0; - wButton_p lastB = NULL; char * cancelLabel = (winOption&PD_F_ALT_CANCELLABEL?_("Close"):_("Cancel")); winOption &= ~PD_F_ALT_CANCELLABEL; @@ -2465,34 +2543,22 @@ EXPORT wWin_p ParamCreateDialog( if ( (winOption&F_RESIZE) != 0 ) winOption |= F_RECALLSIZE; - sprintf( helpStr, "cmd%s", group->nameStr ); - helpStr[3] = toupper((unsigned char)helpStr[3]); - group->win = wWinPopupCreate( mainW, DlgSepRight, DlgSepFrmBottom, helpStr, title, group->nameStr, F_AUTOSIZE|winOption, ParamDlgProc, group ); if ( okLabel && okProc ) { sprintf( helpStr, "%s-ok", group->nameStr ); - lastB = group->okB = wButtonCreate( group->win, 0, 0, helpStr, okLabel, BB_DEFAULT, 0, (wButtonCallBack_p)ParamButtonOk, group ); + group->okB = wButtonCreate( group->win, 0, 0, helpStr, okLabel, BB_DEFAULT, 0, (wButtonCallBack_p)ParamButtonOk, group ); } if ( group->cancelProc ) { - lastB = group->cancelB = wButtonCreate( group->win, 0, 0, NULL, cancelLabel, BB_CANCEL, 0, (wButtonCallBack_p)ParamButtonCancel, group ); + group->cancelB = wButtonCreate( group->win, 0, 0, NULL, cancelLabel, BB_CANCEL, 0, (wButtonCallBack_p)ParamButtonCancel, group ); } if ( needHelpButton ) { sprintf( helpStr, "cmd%s", group->nameStr ); helpStr[3] = toupper((unsigned char)helpStr[3]); - lastB = group->helpB = wButtonCreate( group->win, 0, 0, NULL, _("Help"), BB_HELP, 0, (wButtonCallBack_p)wHelp, MyStrdup(helpStr) ); + group->helpB = wButtonCreate( group->win, 0, 0, NULL, _("Help"), BB_HELP, 0, (wButtonCallBack_p)wHelp, MyStrdup(helpStr) ); } - LOG( log_hotspot, 1, ( "mkshg ${PNG2DIR}/%s.png ${SHGDIR}/%s.shg << EOF\n", group->nameStr, group->nameStr ) ) LayoutControls( group, ParamCreateControl, &group->origW, &group->origH ); - if ( group->okB ) - LOG( log_hotspot, 1, ( "popup %d %d %d %d _%s_%s\n", - wControlGetPosX((wControl_p)(group->okB))+hotspotOffsetX, - wControlGetPosY((wControl_p)(group->okB))+hotspotOffsetY, - wControlGetWidth((wControl_p)(group->okB)), - wControlGetHeight((wControl_p)(group->okB)), - group->nameStr, "ok" ) ) - LOG( log_hotspot, 1, ( "EOF\n" ) ) group->origW += DlgSepRight; group->origH += DlgSepBottom; @@ -2502,11 +2568,9 @@ EXPORT wWin_p ParamCreateDialog( group->origH != h0 ) { LayoutControls( group, ParamPositionControl, NULL, NULL ); } - } else if ( group->origW > w0 || group->origH > h0 ) { - if ( group->origW > w0 ) - w0 = group->origW; - if ( group->origH > h0 ) - h0 = group->origH; + } else { + w0 = max(group->origW, w0); + h0 = max(group->origH, h0); wWinSetSize( group->win, w0, h0 ); } @@ -2566,6 +2630,5 @@ EXPORT void ParamInit( void ) { AddPlaybackProc( "PARAMETER", ParamPlayback, NULL ); AddPlaybackProc( "PARAMCHECK", ParamCheck, NULL ); - log_hotspot = LogFindIndex( "hotspot" ); log_paramLayout = LogFindIndex( "paramlayout" ); } -- cgit v1.2.3