diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-11-14 19:35:45 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2024-11-14 19:35:45 +0100 |
commit | df5520aa2dae5b3ce7abf8733dcdd152898af163 (patch) | |
tree | 00d3047bfb14f682bfb5a21010c731ed649bfed7 /app/bin/dcustmgm.c | |
parent | df247efec654e512242e4f4f1b0212034f9e01fe (diff) | |
parent | ec3c0f6f6e7153fa797dc57a0e95779cbc63a23b (diff) |
Merge branch 'release/debian/1_5.3.0GA-1'HEADdebian/1_5.3.0GA-1master
Diffstat (limited to 'app/bin/dcustmgm.c')
-rw-r--r-- | app/bin/dcustmgm.c | 240 |
1 files changed, 127 insertions, 113 deletions
diff --git a/app/bin/dcustmgm.c b/app/bin/dcustmgm.c index 39bd085..871787f 100644 --- a/app/bin/dcustmgm.c +++ b/app/bin/dcustmgm.c @@ -17,32 +17,18 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <assert.h> -#include <errno.h> -#include <string.h> - -#ifdef WINDOWS -#include <io.h> -#define F_OK (0) -#define W_OK (2) -#define access _access -#else -#include <unistd.h> -#endif - #include "custom.h" #include "fileio.h" -#include "i18n.h" -#include "messages.h" #include "param.h" #include "paths.h" #include "track.h" -#include "wlib.h" #include "include/paramfilelist.h" -#ifdef WINDOWS +#include "common-ui.h" +#include "ctrain.h" +#ifdef UTFCONVERT #include "include/utf8convert.h" #endif @@ -55,57 +41,61 @@ static void CustomNewCar( void * action ); static const char * customTypes[] = { "Car Part", "Car Prototype", NULL }; static wIndex_t selectedType; -static wPos_t customListWidths[] = { 18, 100, 30, 80, 220 }; +static wWinPix_t customListWidths[] = { 18, 100, 30, 80, 220 }; static const char * customListTitles[] = { "", N_("Manufacturer"), - N_("Scale"), N_("Part No"), N_("Description") }; + N_("Scale"), N_("Part No"), N_("Description") + }; static paramListData_t customListData = { 10, 400, 5, customListWidths, customListTitles }; static paramData_t customPLs[] = { #define I_CUSTOMLIST (0) #define customSelL ((wList_p)customPLs[I_CUSTOMLIST].control) - { PD_LIST, NULL, "inx", PDO_DLGRESETMARGIN|PDO_DLGRESIZE|PDO_DLGBOXEND, &customListData, NULL, BL_MANY }, + { PD_LIST, NULL, "inx", PDO_DLGRESETMARGIN|PDO_DLGRESIZE|PDO_DLGBOXEND, &customListData, NULL, BL_MANY }, #define I_CUSTOMNEWTYPE (1) - { PD_DROPLIST, &selectedType, "newtype", PDO_DLGRESETMARGIN | PDO_LISTINDEX, (void*)150, N_("Create a new ") }, -#define I_CUSTOMNEW (2) - { PD_BUTTON, (void *)CustomNewCar, "newcar", PDO_DLGHORZ| PDO_DLGBOXEND, NULL, N_("Go") }, + { PD_DROPLIST, &selectedType, "newtype", PDO_DLGRESETMARGIN | PDO_LISTINDEX, I2VP(150), N_("Create a new ") }, +#define I_CUSTOMNEW (2) + { PD_BUTTON, CustomNewCar, "newcar", PDO_DLGHORZ| PDO_DLGBOXEND, NULL, N_("Go") }, #define I_CUSTOMEDIT (3) - { PD_BUTTON, (void*)CustomEdit, "edit", PDO_DLGCMDBUTTON, NULL, N_("Edit") }, + { PD_BUTTON, CustomEdit, "edit", PDO_DLGCMDBUTTON, NULL, N_("Edit") }, #define I_CUSTOMDEL (4) - { PD_BUTTON, (void*)CustomDelete, "delete", 0, NULL, N_("Delete") }, + { PD_BUTTON, CustomDelete, "delete", 0, NULL, N_("Delete") }, #define I_CUSTOMCOPYTO (5) - { PD_BUTTON, (void*)CustomExport, "export", 0, NULL, N_("Move To") }, - } ; -static paramGroup_t customPG = { "custmgm", 0, customPLs, sizeof customPLs/sizeof customPLs[0] }; + { PD_BUTTON, CustomExport, "export", 0, NULL, N_("Move To") }, +} ; +static paramGroup_t customPG = { "custmgm", 0, customPLs, COUNT( customPLs ) }; typedef struct { - custMgmCallBack_p proc; - void * data; - wIcon_p icon; - } custMgmContext_t, *custMgmContext_p; + custMgmCallBack_p proc; + void * data; + wIcon_p icon; +} custMgmContext_t, *custMgmContext_p; static void CustomDlgUpdate( - paramGroup_p pg, - int inx, - void *valueP ) + paramGroup_p pg, + int inx, + void *valueP ) { custMgmContext_p context = NULL; wIndex_t selcnt = wListGetSelectedCount( (wList_p)customPLs[0].control ); wIndex_t linx, lcnt; - if ( inx == I_CUSTOMNEW ) { - lcnt = wListGetCount( (wList_p)pg->paramPtr[I_CUSTOMNEWTYPE].control ); - } - - if ( inx != I_CUSTOMLIST ) return; + if ( inx == I_CUSTOMNEW ) { + lcnt = wListGetCount( (wList_p)pg->paramPtr[I_CUSTOMNEWTYPE].control ); + } + + if ( inx != I_CUSTOMLIST ) { return; } if ( selcnt == 1 ) { lcnt = wListGetCount( (wList_p)pg->paramPtr[inx].control ); for ( linx=0; - linx<lcnt && wListGetItemSelected( (wList_p)customPLs[0].control, linx ) != TRUE; - linx++ ); + linx<lcnt && wListGetItemSelected( (wList_p)customPLs[0].control, + linx ) != TRUE; + linx++ ); if ( linx < lcnt ) { - context = (custMgmContext_p)wListGetItemContext( (wList_p)pg->paramPtr[inx].control, linx ); - wButtonSetLabel( (wButton_p)customPLs[I_CUSTOMEDIT].control, context->proc( CUSTMGM_CAN_EDIT, context->data )?_("Edit"):_("Rename") ); + context = (custMgmContext_p)wListGetItemContext( (wList_p) + pg->paramPtr[inx].control, linx ); + wButtonSetLabel( (wButton_p)customPLs[I_CUSTOMEDIT].control, + context->proc( CUSTMGM_CAN_EDIT, context->data )?_("Edit"):_("Rename") ); ParamControlActive( &customPG, I_CUSTOMEDIT, TRUE ); } else { ParamControlActive( &customPG, I_CUSTOMEDIT, FALSE ); @@ -124,17 +114,20 @@ static void CustomEdit( void * action ) wIndex_t selcnt = wListGetSelectedCount( (wList_p)customPLs[0].control ); wIndex_t inx, cnt; - if ( selcnt != 1 ) + if ( selcnt != 1 ) { return; + } cnt = wListGetCount( (wList_p)customPLs[0].control ); for ( inx=0; - inx<cnt && wListGetItemSelected( (wList_p)customPLs[0].control, inx ) != TRUE; - inx++ ); - if ( inx >= cnt ) + inx<cnt && wListGetItemSelected( (wList_p)customPLs[0].control, inx ) != TRUE; + inx++ ); + if ( inx >= cnt ) { return; + } context = (custMgmContext_p)wListGetItemContext( customSelL, inx ); - if ( context == NULL ) + if ( context == NULL ) { return; + } context->proc( CUSTMGM_DO_EDIT, context->data ); #ifdef OBSOLETE context->proc( CUSTMGM_GET_TITLE, context->data ); @@ -145,16 +138,16 @@ static void CustomEdit( void * action ) static void CustomNewCar( void * action ) { - switch(selectedType) { - case 1: // car prototype - CarDlgAddProto(); - break; - case 0: // car part - CarDlgAddDesc(); - break; - default: - break; - } + switch(selectedType) { + case 1: // car prototype + CarDlgAddProto(); + break; + case 0: // car part + CarDlgAddDesc(); + break; + default: + break; + } } static void CustomDelete( void * action ) @@ -163,14 +156,18 @@ static void CustomDelete( void * action ) wIndex_t inx, cnt; custMgmContext_p context = NULL; - if ( selcnt <= 0 ) + if ( selcnt <= 0 ) { return; - if ( (!NoticeMessage2( 1, MSG_CUSTMGM_DELETE_CONFIRM, _("Yes"), _("No"), selcnt ) ) ) + } + if ( (!NoticeMessage2( 1, MSG_CUSTMGM_DELETE_CONFIRM, _("Yes"), _("No"), + selcnt ) ) ) { return; + } cnt = wListGetCount( (wList_p)customPLs[0].control ); for ( inx=0; inx<cnt; inx++ ) { - if ( !wListGetItemSelected( (wList_p)customPLs[0].control, inx ) ) + if ( !wListGetItemSelected( (wList_p)customPLs[0].control, inx ) ) { continue; + } context = (custMgmContext_p)wListGetItemContext( customSelL, inx ); context->proc( CUSTMGM_DO_DELETE, context->data ); MyFree( context ); @@ -186,8 +183,9 @@ EXPORT FILE * customMgmF; static char custMgmContentsStr[STR_SIZE]; static BOOL_T custMgmProceed; static paramData_t custMgmContentsPLs[] = { - { PD_STRING, custMgmContentsStr, "label", PDO_STRINGLIMITLENGTH, (void*)400, N_("Label"), 0, 0, sizeof(custMgmContentsStr)} }; -static paramGroup_t custMgmContentsPG = { "contents", 0, custMgmContentsPLs, sizeof custMgmContentsPLs/sizeof custMgmContentsPLs[0] }; + { PD_STRING, custMgmContentsStr, "label", PDO_NOTBLANK, I2VP(400), N_("Label"), 0, 0, sizeof(custMgmContentsStr)} +}; +static paramGroup_t custMgmContentsPG = { "contents", 0, custMgmContentsPLs, COUNT( custMgmContentsPLs ) }; static void CustMgmContentsOk( void * junk ) { @@ -197,22 +195,22 @@ static void CustMgmContentsOk( void * junk ) static int CustomDoExport( - int files, - char ** fileName, - void * data ) + int files, + char ** fileName, + void * data ) { int rc; wIndex_t selcnt = wListGetSelectedCount( (wList_p)customPLs[0].control ); wIndex_t inx, cnt; custMgmContext_p context = NULL; - char *oldLocale = NULL; - assert( fileName != NULL ); - assert( files == 1 ); + CHECK( fileName != NULL ); + CHECK( files == 1 ); - if ( selcnt <= 0 ) + if ( selcnt <= 0 ) { return FALSE; - + } + SetCurrentPath( PARAMETERPATHKEY, fileName[ 0 ] ); rc = access( fileName[ 0 ], F_OK ); if ( rc != -1 ) { @@ -224,43 +222,46 @@ static int CustomDoExport( custMgmProceed = TRUE; } else { if ( custMgmContentsPG.win == NULL ) { - ParamCreateDialog( &custMgmContentsPG, MakeWindowTitle(_("Contents Label")), _("Ok"), CustMgmContentsOk, wHide, TRUE, NULL, F_BLOCK, NULL ); + ParamCreateDialog( &custMgmContentsPG, MakeWindowTitle(_("Contents Label")), + _("Ok"), CustMgmContentsOk, wHide, TRUE, NULL, F_BLOCK, NULL ); } custMgmProceed = FALSE; wShow( custMgmContentsPG.win ); } - if ( !custMgmProceed ) + if ( !custMgmProceed ) { return FALSE; + } customMgmF = fopen( fileName[ 0 ], "a" ); if ( customMgmF == NULL ) { NoticeMessage( MSG_CUSTMGM_CANT_WRITE, _("Ok"), NULL, fileName[ 0 ] ); return FALSE; } - oldLocale = SaveLocale("C"); + SetCLocale(); - if (rc == -1) - { - #ifdef WINDOWS - char *contents = MyStrdup(custMgmContentsStr); - contents = Convert2UTF8(contents); - fprintf(customMgmF, "CONTENTS %s\n", contents); + if (rc == -1) { +#ifdef UTFCONVERT + char *contents = MyStrdup(custMgmContentsStr); + contents = Convert2UTF8(contents); + fprintf(customMgmF, "CONTENTS %s\n", contents); MyFree(contents); - #else - fprintf(customMgmF, "CONTENTS %s\n", custMgmContentsStr); - #endif // WINDOWS +#else + fprintf(customMgmF, "CONTENTS %s\n", custMgmContentsStr); +#endif // UTFCONVERT } cnt = wListGetCount( (wList_p)customPLs[0].control ); for ( inx=0; inx<cnt; inx++ ) { - if ( !wListGetItemSelected( (wList_p)customPLs[0].control, inx ) ) + if ( !wListGetItemSelected( (wList_p)customPLs[0].control, inx ) ) { continue; + } context = (custMgmContext_p)wListGetItemContext( customSelL, inx ); - if ( context == NULL ) continue; + if ( context == NULL ) { continue; } if (!context->proc( CUSTMGM_DO_COPYTO, context->data )) { - NoticeMessage( MSG_WRITE_FAILURE, _("Ok"), NULL, strerror(errno), fileName[ 0 ] ); + NoticeMessage( MSG_WRITE_FAILURE, _("Ok"), NULL, strerror(errno), + fileName[ 0 ] ); fclose( customMgmF ); - RestoreLocale(oldLocale); + SetUserLocale(); return FALSE; } context->proc( CUSTMGM_DO_DELETE, context->data ); @@ -270,7 +271,7 @@ static int CustomDoExport( cnt--; } fclose( customMgmF ); - RestoreLocale(oldLocale); + SetUserLocale(); LoadParamFile( 1, fileName, NULL ); DoChangeNotification( CHANGE_PARAMS ); return TRUE; @@ -281,33 +282,32 @@ static void CustomExport( void * junk ) { if ( customMgmExport_fs == NULL ) customMgmExport_fs = wFilSelCreate( mainW, FS_UPDATE, 0, _("Move To XTP"), - _("Parameter File (*.xtp)|*.xtp"), CustomDoExport, NULL ); + _("Parameter File (*.xtp)|*.xtp"), CustomDoExport, NULL ); wFilSelect( customMgmExport_fs, GetCurrentPath(CUSTOMPATHKEY)); } static void CustomDone( void * action ) { - char *oldLocale = NULL; FILE * f = OpenCustom("w"); if (f == NULL) { wHide( customPG.win ); return; } - oldLocale = SaveLocale("C"); + SetCLocale(); CompoundCustomSave(f); CarCustomSave(f); fclose(f); - RestoreLocale(oldLocale); + SetUserLocale(); wHide( customPG.win ); } EXPORT void CustMgmLoad( - wIcon_p icon, - custMgmCallBack_p proc, - void * data ) + wIcon_p icon, + custMgmCallBack_p proc, + void * data ) { custMgmContext_p context; context = MyMalloc( sizeof *context ); @@ -324,22 +324,30 @@ static void LoadCustomMgmList( void ) wIndex_t curInx, cnt=0; long tempL; custMgmContext_p context; +#ifdef LATER custMgmContext_t curContext; +#endif curInx = wListGetIndex( customSelL ); +#ifdef LATER curContext.proc = NULL; curContext.data = NULL; curContext.icon = NULL; +#endif if ( curInx >= 0 ) { context = (custMgmContext_p)wListGetItemContext( customSelL, curInx ); - if ( context != NULL ) +#ifdef LATER + if ( context != NULL ) { curContext = *context; + } +#endif } cnt = wListGetCount( customSelL ); for ( curInx=0; curInx<cnt; curInx++ ) { context = (custMgmContext_p)wListGetItemContext( customSelL, curInx ); - if ( context ) + if ( context ) { MyFree( context ); + } } curInx = wListGetIndex( customSelL ); wControlShow( (wControl_p)customSelL, FALSE ); @@ -355,13 +363,15 @@ static void LoadCustomMgmList( void ) for ( curInx=0; curInx<cnt; curInx++ ) { context = (custMgmContext_p)wListGetItemContext( customSelL, curInx ); if ( context && - context->proc == curContext.proc && - context->data == curContext.data ) + context->proc == curContext.proc && + context->data == curContext.data ) { break; + } } } - if ( curInx >= cnt ) + if ( curInx >= cnt ) { curInx = (cnt>0?0:-1); + } wListSetIndex( customSelL, curInx ); tempL = curInx; @@ -380,8 +390,9 @@ static void CustMgmChange( long changes ) } } if ((changes&CHANGE_PARAMS) == 0 || - customPG.win == NULL || !wWinIsVisible(customPG.win) ) + customPG.win == NULL || !wWinIsVisible(customPG.win) ) { return; + } LoadCustomMgmList(); } @@ -389,16 +400,19 @@ static void CustMgmChange( long changes ) static void DoCustomMgr( void * junk ) { - int i = 0; - + int i = 0; + if (customPG.win == NULL) { - ParamCreateDialog( &customPG, MakeWindowTitle(_("Manage custom designed parts")), _("Done"), CustomDone, wHide, TRUE, NULL, F_RESIZE|F_RECALLSIZE|F_BLOCK, CustomDlgUpdate ); - while(customTypes[ i ] != NULL) { - wListAddValue( ((wList_p)customPLs[I_CUSTOMNEWTYPE].control), customTypes[ i++ ], NULL, NULL ); - } - selectedType = 0; - wListSetIndex( ((wList_p)customPLs[I_CUSTOMNEWTYPE].control), selectedType); - + ParamCreateDialog( &customPG, + MakeWindowTitle(_("Manage custom designed parts")), _("Done"), CustomDone, + wHide, TRUE, NULL, F_RESIZE|F_RECALLSIZE|F_BLOCK, CustomDlgUpdate ); + while(customTypes[ i ] != NULL) { + wListAddValue( ((wList_p)customPLs[I_CUSTOMNEWTYPE].control), + customTypes[ i++ ], NULL, NULL ); + } + selectedType = 0; + wListSetIndex( ((wList_p)customPLs[I_CUSTOMNEWTYPE].control), selectedType); + } else { wListClear( customSelL ); } @@ -412,7 +426,7 @@ static void DoCustomMgr( void * junk ) EXPORT addButtonCallBack_t CustomMgrInit( void ) { - ParamRegister( &customPG ); + ParamRegister( &customPG ); ParamRegister( &custMgmContentsPG ); RegisterChangeNotification( CustMgmChange ); return &DoCustomMgr; |