From e7d20cf352688bf717a01f4e6d9e6f497c2bea4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 20 Sep 2025 19:19:34 +0200 Subject: New upstream version 5.3.1Beta2 --- app/bin/command.c | 305 ++++++++++++++---------------------------------------- 1 file changed, 79 insertions(+), 226 deletions(-) (limited to 'app/bin/command.c') diff --git a/app/bin/command.c b/app/bin/command.c index bf628f8..5e4d968 100644 --- a/app/bin/command.c +++ b/app/bin/command.c @@ -31,6 +31,7 @@ #include "track.h" #include "common-ui.h" #include "menu.h" +#include "include/toolbar.h" /***************************************************************************** * @@ -39,17 +40,6 @@ */ #define COMMAND_MAX (250) -#define BUTTON_MAX (250) - -static struct { - wControl_p control; - wBool_t enabled; - wWinPix_t x, y; - long options; - int group; - wIndex_t cmdInx; -} buttonList[BUTTON_MAX]; -EXPORT int buttonCnt = 0; // TODO-misc-refactor static struct { procCommand_t cmdProc; @@ -71,14 +61,9 @@ EXPORT int commandCnt = 0; static wIndex_t curCommand = 0; -EXPORT int cmdGroup; - static int log_command; -#define TOOLBARSET_INIT (0xFFFF) -EXPORT long toolbarSet = TOOLBARSET_INIT; -EXPORT wWinPix_t toolbarHeight = 0; -static wWinPix_t toolbarWidth = 0; + EXPORT long preSelect = 0; /**< default command 0 = Describe 1 = Select */ EXPORT long rightClickMode = 0; EXPORT void * commandContext; @@ -90,6 +75,42 @@ EXPORT const char* GetCurCommandName() return commandList[curCommand].helpKey; } +/** + * Decide whether command is available in the current application mode. + * Basically track modifications are not available in Train Mode, file + * operations are always available and train control ops are available in + * train mode only. + * The specific logic was developed with the help of Wolfram Alpha: + * CNF | ((NOT m) OR o OR t) AND(m OR (NOT o) OR t) + * + * \param mode application mode + * \param options availability options + * \return true for enabled, false if disabled + */ + +EXPORT bool IsCommandEnabled(long mode, long options) +{ + /* + if (((mode == MODE_DESIGN) || (options & IC_MODETRAIN_ONLY) || + (options & IC_MODETRAIN_TOO)) && + ((mode == MODE_TRAIN) || !(options & IC_MODETRAIN_ONLY)) || + (options & IC_MODETRAIN_TOO)) { + */ + if ( + ((mode == MODE_DESIGN) || + (options & IC_MODETRAIN_ONLY) || + (options & IC_MODETRAIN_TOO)) + && + ((mode == MODE_TRAIN) || + !(options & IC_MODETRAIN_ONLY) || + (options & IC_MODETRAIN_TOO)) + ) { + return true; + } + + return false; +} + EXPORT void EnableCommands(void) { int inx, minx; @@ -102,20 +123,15 @@ EXPORT void EnableCommands(void) if ((commandList[inx].options & IC_SELECTED) && selectedTrackCount <= 0) { enable = FALSE; - } else if ((programMode == MODE_TRAIN - && (commandList[inx].options - & (IC_MODETRAIN_TOO | IC_MODETRAIN_ONLY)) == 0) - || (programMode != MODE_TRAIN - && (commandList[inx].options & IC_MODETRAIN_ONLY) - != 0)) { - enable = FALSE; - } else { + } else if (IsCommandEnabled(programMode, commandList[inx].options )) { enable = TRUE; + } else { + enable = FALSE; } if (commandList[inx].enabled != enable) { - if (commandList[inx].buttInx >= 0) - wControlActive(buttonList[commandList[inx].buttInx].control, - enable); + if (commandList[inx].buttInx >= 0) { + ToolbarButtonEnable(commandList[inx].buttInx, enable ); + } for (minx = 0; minx < NUM_CMDMENUS; minx++) if (commandList[inx].menu[minx]) { wMenuPushEnable(commandList[inx].menu[minx], enable); @@ -127,12 +143,7 @@ EXPORT void EnableCommands(void) EnableMenus(); - for (inx = 0; inx < buttonCnt; inx++) { - if (buttonList[inx].cmdInx < 0 - && (buttonList[inx].options & IC_SELECTED)) { - wControlActive(buttonList[inx].control, selectedTrackCount > 0); - } - } + ToolbarButtonEnableIfSelect(selectedTrackCount > 0); } EXPORT wIndex_t GetCurrentCommand() @@ -149,17 +160,16 @@ EXPORT void Reset(void) LOG(log_command, 2, ( "COMMAND CANCEL %s\n", commandList[curCommand].helpKey )) commandList[curCommand].cmdProc( C_CANCEL, zero); - if (commandList[curCommand].buttInx >= 0) - wButtonSetBusy( - (wButton_p) buttonList[commandList[curCommand].buttInx].control, - FALSE); + if (commandList[curCommand].buttInx >= 0) { + ToolbarButtonBusy(commandList[curCommand].buttInx, FALSE); + } curCommand = (preSelect ? selectCmdInx : describeCmdInx); wSetCursor(mainD.d, preSelect ? defaultCursor : wCursorQuestion); commandContext = commandList[curCommand].context; - if (commandList[curCommand].buttInx >= 0) - wButtonSetBusy( - (wButton_p) buttonList[commandList[curCommand].buttInx].control, - TRUE); + if (commandList[curCommand].buttInx >= 0) { + ToolbarButtonBusy(commandList[curCommand].buttInx, TRUE); + } + DYNARR_RESET( trkSeg_t, tempSegs_da ); TryCheckPoint(); @@ -335,7 +345,7 @@ EXPORT wBool_t DoCurCommand(wAction_t action, coOrd pos) default: break; } - if ((rc == C_TERMINATE || rc == C_INFO) + if ((rc == C_TERMINATE ) && (commandList[curCommand].options & IC_STICKY) && (commandList[curCommand].stickyMask & stickySet)) { DYNARR_RESET( trkSeg_t, tempSegs_da ); @@ -361,7 +371,6 @@ EXPORT wBool_t DoCurCommand(wAction_t action, coOrd pos) break; case C_TERMINATE: InfoMessage(""); - case C_INFO: Reset(); break; } @@ -401,7 +410,7 @@ EXPORT int ConfirmReset(BOOL_T retry) commandList[curCommand].cmdProc( C_OK, zero); return C_OK; } else if (rc == -1) { - return C_CANCEL; + return C_ERROR; } } else if (rc == C_TERMINATE) { return C_TERMINATE; @@ -424,7 +433,6 @@ EXPORT void DoCommandB(void * data) STATUS_T rc; static coOrd pos = { 0, 0 }; static int inDoCommandB = FALSE; - wIndex_t buttInx; if (inDoCommandB) { return; @@ -472,10 +480,9 @@ EXPORT void DoCommandB(void * data) ( "COMMAND FINISH %s\n", commandList[curCommand].helpKey )) rc = commandList[curCommand].cmdProc( C_FINISH, zero); } - if (commandList[curCommand].buttInx >= 0) - wButtonSetBusy( - (wButton_p) buttonList[commandList[curCommand].buttInx].control, - FALSE); + if (commandList[curCommand].buttInx >= 0) { + ToolbarButtonBusy(commandList[curCommand].buttInx, FALSE); + } if (recordF) { fprintf(recordF, "COMMAND %s\n", commandList[inx].helpKey + 3); @@ -484,22 +491,18 @@ EXPORT void DoCommandB(void * data) curCommand = inx; commandContext = commandList[curCommand].context; - if ((buttInx = commandList[curCommand].buttInx) >= 0) { - if (buttonList[buttInx].cmdInx != curCommand) { - wButtonSetLabel((wButton_p) buttonList[buttInx].control, - (char*) commandList[curCommand].icon); - wControlSetHelp(buttonList[buttInx].control, - GetBalloonHelpStr(commandList[curCommand].helpKey)); - wControlSetContext(buttonList[buttInx].control, - I2VP(curCommand)); - buttonList[buttInx].cmdInx = curCommand; - } - wButtonSetBusy( - (wButton_p) buttonList[commandList[curCommand].buttInx].control, - TRUE); + // update the toolbar icon when a sub-command is selected (eg. circle + // vs. filled circle) + + if (commandList[curCommand].buttInx >= 0) { + ToolbarUpdateButton(commandList[curCommand].buttInx, + curCommand, (char *)commandList[curCommand].icon, + commandList[curCommand].helpKey, I2VP(curCommand)); + ToolbarButtonBusy(commandList[curCommand].buttInx, TRUE); } + LOG(log_command, 1, - ( "COMMAND START %s\n", commandList[curCommand].helpKey )) + ("COMMAND START %s\n", commandList[curCommand].helpKey)); wSetCursor(mainD.d,defaultCursor); rc = commandList[curCommand].cmdProc( C_START, pos); LOG(log_command, 4, ( " COMMAND returns %d\n", rc )) @@ -514,7 +517,6 @@ EXPORT void DoCommandB(void * data) #endif break; case C_TERMINATE: - case C_INFO: if (rc == C_TERMINATE) { InfoMessage(""); } @@ -524,107 +526,6 @@ EXPORT void DoCommandB(void * data) inDoCommandB = FALSE; } -static void LayoutSetPos(wIndex_t inx) -{ - wWinPix_t w, h, offset; - static wWinPix_t toolbarRowHeight = 0; - static wWinPix_t width; - static int lastGroup; - static wWinPix_t gap; - static int layerButtCnt; - static int layerButtNumber; - int currGroup; - - if (inx == 0) { - lastGroup = 0; - wWinGetSize(mainW, &width, &h); - gap = 5; - toolbarWidth = width - 20 + 5; - layerButtCnt = 0; - layerButtNumber = 0; - toolbarHeight = 0; - } - - if (buttonList[inx].control) { - if (toolbarRowHeight <= 0) { - toolbarRowHeight = wControlGetHeight(buttonList[inx].control); - } - - currGroup = buttonList[inx].group & ~BG_BIGGAP; - if (currGroup != lastGroup && (buttonList[inx].group & BG_BIGGAP)) { - gap = 15; - } - if ((toolbarSet & (1 << currGroup)) - && (programMode != MODE_TRAIN - || (buttonList[inx].options - & (IC_MODETRAIN_TOO | IC_MODETRAIN_ONLY))) - && (programMode == MODE_TRAIN - || (buttonList[inx].options & IC_MODETRAIN_ONLY) == 0) - && ((buttonList[inx].group & ~BG_BIGGAP) != BG_LAYER - || layerButtCnt < layerCount)) { - if (currGroup != lastGroup) { - toolbarWidth += gap; - lastGroup = currGroup; - gap = 5; - } - w = wControlGetWidth(buttonList[inx].control); - h = wControlGetHeight(buttonList[inx].control); - if (h width - 20) { - toolbarWidth = 0; - toolbarHeight += h + 5; - } - if ((currGroup == BG_LAYER) && layerButtNumber>1 - && GetLayerHidden(layerButtNumber-2) ) { - wControlShow(buttonList[inx].control, FALSE); - layerButtNumber++; - } else { - if (currGroup == BG_LAYER ) { - if (layerButtNumber>1) { layerButtCnt++; } // Ignore List and Background - layerButtNumber++; - } - wControlSetPos(buttonList[inx].control, toolbarWidth, - toolbarHeight - (h + 5 +offset)); - buttonList[inx].x = toolbarWidth; - buttonList[inx].y = toolbarHeight - (h + 5 + offset); - toolbarWidth += wControlGetWidth(buttonList[inx].control); - wControlShow(buttonList[inx].control, TRUE); - } - } else { - wControlShow(buttonList[inx].control, FALSE); - } - } -} - -EXPORT void LayoutToolBar( void * data ) -{ - int inx; - - for (inx = 0; inx < buttonCnt; inx++) { - LayoutSetPos(inx); - } - if (toolbarSet&(1<= 0 && buttonList[buttInx].cmdInx == -1 ) { - // set button back-link - buttonList[buttInx].cmdInx = commandCnt; - } + + ToolbarButtonCommandLink(buttInx, commandCnt); + commandCnt++; return commandCnt - 1; } -EXPORT void AddToolbarControl(wControl_p control, long options) -{ - CHECK( buttonCnt < COMMAND_MAX - 1 ); - buttonList[buttonCnt].enabled = TRUE; - buttonList[buttonCnt].options = options; - buttonList[buttonCnt].group = cmdGroup; - buttonList[buttonCnt].x = 0; - buttonList[buttonCnt].y = 0; - buttonList[buttonCnt].control = control; - buttonList[buttonCnt].cmdInx = -1; - LayoutSetPos(buttonCnt); - buttonCnt++; -} - - -/*--------------------------------------------------------------------*/ -EXPORT void PlaybackButtonMouse(wIndex_t buttInx) -{ - wWinPix_t cmdX, cmdY; - coOrd pos; - - if (buttInx < 0 || buttInx >= buttonCnt) { - return; - } - if (buttonList[buttInx].control == NULL) { - return; - } - cmdX = buttonList[buttInx].x + 17; - cmdY = toolbarHeight - (buttonList[buttInx].y + 17) - + (wWinPix_t) (mainD.size.y / mainD.scale * mainD.dpi) + 30; - - mainD.Pix2CoOrd( &mainD, cmdX, cmdY, &pos ); - MovePlaybackCursor(&mainD, pos, TRUE, buttonList[buttInx].control); - if (playbackTimer == 0) { - wButtonSetBusy((wButton_p) buttonList[buttInx].control, TRUE); - wFlush(); - wPause(500); - wButtonSetBusy((wButton_p) buttonList[buttInx].control, FALSE); - wFlush(); - } -} EXPORT void PlaybackCommand(const char * line, wIndex_t lineNum) @@ -728,39 +587,34 @@ EXPORT void PlaybackCommand(const char * line, wIndex_t lineNum) fprintf(stderr, "Unknown playback COMMAND command %d : %s\n", lineNum, line); } else { - wWinPix_t cmdX, cmdY; - coOrd pos; - if ((buttInx = commandList[inx].buttInx) >= 0) { - cmdX = buttonList[buttInx].x + 17; - cmdY = toolbarHeight - (buttonList[buttInx].y + 17) - + (wWinPix_t) (mainD.size.y / mainD.scale * mainD.dpi) + 30; - mainD.Pix2CoOrd( &mainD, cmdX, cmdY, &pos ); - MovePlaybackCursor(&mainD, pos,TRUE,buttonList[buttInx].control); + buttInx = commandList[inx].buttInx; + if ((commandList[inx].buttInx) >= 0) { + ToolbarButtonPlayback(commandList[inx].buttInx); } if (strcmp(line + 8, "Undo") == 0) { if (buttInx > 0 && playbackTimer == 0) { - wButtonSetBusy((wButton_p) buttonList[buttInx].control, TRUE); + ToolbarButtonBusy(buttInx, TRUE); wFlush(); wPause(500); - wButtonSetBusy((wButton_p) buttonList[buttInx].control, FALSE); + ToolbarButtonBusy(buttInx, FALSE); wFlush(); } UndoUndo(NULL); } else if (strcmp(line + 8, "Redo") == 0) { if (buttInx >= 0 && playbackTimer == 0) { - wButtonSetBusy((wButton_p) buttonList[buttInx].control, TRUE); + ToolbarButtonBusy(buttInx, TRUE); wFlush(); wPause(500); - wButtonSetBusy((wButton_p) buttonList[buttInx].control, FALSE); + ToolbarButtonBusy(buttInx, FALSE); wFlush(); } UndoRedo(NULL); } else { if (buttInx >= 0 && playbackTimer == 0) { - wButtonSetBusy((wButton_p) buttonList[buttInx].control, TRUE); + ToolbarButtonBusy(buttInx, TRUE); wFlush(); wPause(500); - wButtonSetBusy((wButton_p) buttonList[buttInx].control, FALSE); + ToolbarButtonBusy(buttInx, FALSE); wFlush(); } DoCommandB(I2VP(inx)); @@ -795,6 +649,5 @@ EXPORT void CommandInit( void ) curCommand = describeCmdInx; commandContext = commandList[curCommand].context; log_command = LogFindIndex( "command" ); - RegisterChangeNotification(ToolbarChange); } -- cgit v1.2.3