void TBInlineSelect::SetLimits(double min, double max) { assert(min <= max); m_min = min; m_max = max; SetValueDouble(m_value); }
bool TBInlineSelect::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_KEY_DOWN) { if (ev.special_key == TB_KEY_UP || ev.special_key == TB_KEY_DOWN) { double dv = ev.special_key == TB_KEY_UP ? 1 : -1; SetValueDouble(GetValueDouble() + dv); return true; } } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("dec")) { SetValueDouble(GetValueDouble() - 1); if (!ev.target->IsCaptured()) { InvokeModifiedEvent(); } return true; } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("inc")) { SetValueDouble(GetValueDouble() + 1); if (!ev.target->IsCaptured()) { InvokeModifiedEvent(); } return true; } else if (ev.type == EVENT_TYPE_CHANGED && ev.target == &m_editfield) { TBStr text; m_editfield.GetText(text); SetValueInternal((double) atof(text), false); } else if (ev.type == EVENT_TYPE_CHANGED && ev.target == this) { return TBWidget::OnEvent(ev); } return false; }
void TBSlider::SetLimits(double min, double max) { min = MIN(min, max); if (min == m_min && max == m_max) return; m_min = min; m_max = max; SetValueDouble(m_value); UpdateHandle(); }
bool TBSlider::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_POINTER_MOVE && captured_widget == &m_handle) { if (m_to_pixel_factor > 0) { int dx = ev.target_x - pointer_down_widget_x; int dy = ev.target_y - pointer_down_widget_y; double delta_val = (m_axis == AXIS_X ? dx : -dy) / m_to_pixel_factor; SetValueDouble(m_value + delta_val); } return true; } else if (ev.type == EVENT_TYPE_WHEEL) { double old_val = m_value; double step = (m_axis == AXIS_X ? GetSmallStep() : -GetSmallStep()); SetValueDouble(m_value + step * ev.delta_y); return m_value != old_val; } else if (ev.type == EVENT_TYPE_KEY_DOWN) { double step = (m_axis == AXIS_X ? GetSmallStep() : -GetSmallStep()); if (ev.special_key == TB_KEY_LEFT || ev.special_key == TB_KEY_UP) SetValueDouble(GetValueDouble() - step); else if (ev.special_key == TB_KEY_RIGHT || ev.special_key == TB_KEY_DOWN) SetValueDouble(GetValueDouble() + step); else return false; return true; } else if (ev.type == EVENT_TYPE_KEY_UP) { if (ev.special_key == TB_KEY_LEFT || ev.special_key == TB_KEY_UP || ev.special_key == TB_KEY_RIGHT || ev.special_key == TB_KEY_DOWN) return true; } return false; }
void TBScrollBar::SetLimits(double min, double max, double visible) { max = MAX(min, max); visible = MAX(visible, 0.0); if (min == m_min && max == m_max && m_visible == visible) return; m_min = min; m_max = max; m_visible = visible; SetValueDouble(m_value); // If we're currently dragging the scrollbar handle, convert the down point // to root and then back after the applying the new limit. // This prevents sudden jumps to unexpected positions when scrolling. if (captured_widget == &m_handle) m_handle.ConvertToRoot(pointer_down_widget_x, pointer_down_widget_y); UpdateHandle(); if (captured_widget == &m_handle) m_handle.ConvertFromRoot(pointer_down_widget_x, pointer_down_widget_y); }
/* ExecLine function */ inline int ExecLine(struct ST_SUIM *pS, const char *pchLine) { if(pS->inFlgError== 1) return (ERR_NONE); if(pchLine[0]== 'i' && pchLine[1]== ':') { //if Calc(pS); if(pS->inErrCode!= SUCCESS) return (pS->inErrCode); if(pS->doCalcWork== 1.0) { return (pS->inLineNo + 1); } else { int inLineNo = pS->pinListJumpNo[pS->inLineNo]; return (inLineNo); } } else { if(pchLine[0]== 'g' && pchLine[1]== ':') { //goto int inLineNo = pS->pinListJumpNo[pS->inLineNo]; return (inLineNo); } else { if(pchLine[0]== 'c' && pchLine[1]== ':') { //call function if(pS->pchInArgs!= NULL) { free(pS->pchInArgs); pS->pchInArgs = NULL; } char pchFuncName[MAX_WORD] = ""; CallBack pclCallBack = NULL; char *pchIndex = strchr(&pchLine[2], ' '); if(pchIndex== NULL) { strcpy(pchFuncName, &pchLine[2]); pclCallBack = GetCallBack(pS, &pchLine[2]); } else { char *pchInArgs = pchIndex + 1; int inSize = pchIndex - &pchLine[2]; memset(pchFuncName, 0x00, MAX_WORD); strncpy(pchFuncName, &pchLine[2], inSize); pclCallBack = GetCallBack(pS, pchFuncName); if(pclCallBack!= NULL) { int inLength = strlen(pchInArgs); pS->pchInArgs = malloc(inLength + 1); strcpy(pS->pchInArgs, pchInArgs); } } if(pclCallBack!= NULL) { //exe side function int inErrCode = (*pclCallBack)((int *)pS); if(inErrCode!= SUCCESS) { SetError2(pS, inErrCode, "function call error."); return (inErrCode); } } else { //suim function if(pS->inStackBackNo>= MAX_STACK_FUNCTION) { SetError2(pS, ERR_OVERFLOW, "function stack overflow."); return (ERR_OVERFLOW); } pS->pinStackBackNo[pS->inStackBackNo] = pS->inLineNo; pS->inStackBackNo++; int inLineNo = GetFunctionDefine(pS, pchFuncName); if(inLineNo== 0) { SetError2(pS, ERR_FUNC_NAME, "can't find function name."); return (ERR_FUNC_NAME); } pS->inLineNo = inLineNo; } pS->inNoOut = 0; return (pS->inLineNo + 1); } else { if(pchLine[0]== 'o' && pchLine[1]== ':') { //setup out arg Calc(pS); if(pS->inErrCode!= SUCCESS) return (pS->inErrCode); if(pS->pchCalcWork== NULL) { int inErrCode = SetValueDouble(pS->ppstListOut, pS->inNoOut, pS->doCalcWork); if(inErrCode!= SUCCESS) return (inErrCode); } else { int inErrCode = SetValueString(pS->ppstListOut, pS->inNoOut, pS->pchCalcWork); if(inErrCode!= SUCCESS) return (inErrCode); } pS->inNoOut++; return (pS->inLineNo + 1); } else { if(pchLine[0]== '-' && pchLine[1]== '-') { //Separator return (ORDER_SEPARATOR); } else { if(pchLine[0]== 'r' && pchLine[1]== ':') { //return pS->inNoOut = 0; return (ORDER_RETURN); } else { if(pchLine[0]== 'e' && pchLine[1]== ':') { //function end if(pS->inStackBackNo>= 1) { pS->inLineNo = pS->pinStackBackNo[pS->inStackBackNo - 1]; pS->pinStackBackNo[pS->inStackBackNo - 1] = 0; pS->inStackBackNo--; return (pS->inLineNo + 1); } return (ORDER_END); } } } } } } } //calculation int inNo = CngKey2No(&pchLine[0]); if(inNo< 0) return (ERR_OVERFLOW); if(inNo>= pS->inCountVariable) return (ERR_OVERFLOW); Calc(pS); if(pS->inErrCode!= SUCCESS) return (pS->inErrCode); int inErrCode = SUCCESS; if(pS->pchCalcWork== NULL) { inErrCode = SetValueDouble(pS->ppstListVariable, inNo, pS->doCalcWork); } else { inErrCode = SetValueString(pS->ppstListVariable, inNo, pS->pchCalcWork); free(pS->pchCalcWork); pS->pchCalcWork = NULL; } if(inErrCode!= SUCCESS) return (inErrCode); return (pS->inLineNo + 1); }
/* SetBuffer function Setup suim code. */ SUIMLIB_API int SetBuffer(const int *S, const char *pchSuimName, const char *pchBuffer, const int inVarCount, const int inOutCount, int inCallBackCount) { if(S== NULL) return (ERR_S_NULL); int inFlag = IsNullOrEmpty(pchSuimName); if(inFlag!= 0) return (ERR_NAME); inFlag = IsNullOrEmpty(pchBuffer); if(inFlag!= 0) return (ERR_BUFFLER); if(inVarCount>= MAX_VARIABLE_COUNT) return (ERR_OVERFLOW); struct ST_SUIM *pS = (struct ST_SUIM *)S; if(pS->pchSuimName!= NULL) return (ERR_SET_NAME); if(pS->pchBuffer!= NULL) return (ERR_SET_BUFFER); size_t szLength = strlen(pchSuimName); pS->pchSuimName = malloc(szLength + 1); if(pS->pchSuimName== NULL) return (ERR_MEMORY); strcpy(pS->pchSuimName, pchSuimName); szLength = strlen(pchBuffer); pS->pchBuffer = malloc(szLength + 1); if(pS->pchBuffer== NULL) return (ERR_MEMORY); strcpy(pS->pchBuffer, pchBuffer); int inMaxLine = 0; int inCnt, inMax = strlen(pchBuffer); for(inCnt= 0;inCnt< inMax;inCnt++) { if(pchBuffer[inCnt]== '\n') inMaxLine++; } pS->inMaxLineNum = inMaxLine; pS->ppchLines = malloc(sizeof(char *) * (inMaxLine)); if(pS->ppchLines== NULL) return (ERR_MEMORY); memset(pS->ppchLines, 0x00, sizeof(char *) * (inMaxLine)); //split lines inCnt = 0; char *pchPos = strtok( pS->pchBuffer, "\n" ); while( pchPos != NULL && inCnt < inMaxLine ) { pS->ppchLines[inCnt] = pchPos; inCnt++; pchPos = strtok( NULL, "\n" ); } int inCountFunction = 0; for(inCnt= 0;inCnt< inMaxLine;inCnt++) { if(pS->ppchLines[inCnt][0]== 'f' && pS->ppchLines[inCnt][1]== '|') inCountFunction++; } //define setting pS->inCountVariable = inVarCount; if(inVarCount> 0) { pS->ppstListVariable = malloc(sizeof(struct ST_VALUE *) * inVarCount); memset(pS->ppstListVariable, 0x00, sizeof(struct ST_VALUE *) * inVarCount); for(inCnt= 0;inCnt< inVarCount;inCnt++) { SetValueDouble(pS->ppstListVariable, inCnt, 0.0); } for(inCnt= 0;inCnt< inMaxLine;inCnt++) { if(!(pS->ppchLines[inCnt][0]== 's' && pS->ppchLines[inCnt][1]== '|')) continue; char *pchKey = strtok(&pS->ppchLines[inCnt][2], ":"); char *pchValue = strtok(NULL, ":"); const int inNo = CngKey2No(pchKey); if(inNo< 0) return (ERR_OVERFLOW); if(inNo>= inMax) return (ERR_OVERFLOW); int inErrCode = SetValueString(pS->ppstListVariable, inNo, pchValue); if(inErrCode!= SUCCESS) return (inErrCode); } } //callback setting pS->inCountCallBack = inCallBackCount; if(inCallBackCount> 0) { pS->ppstListCallBack = malloc(sizeof(struct ST_VALUE_CALLBACK *) * inCallBackCount); memset(pS->ppstListCallBack, 0x00, sizeof(struct ST_VALUE_CALLBACK *) * inCallBackCount); } //out setting pS->pchInArgs = NULL; pS->inNoOut = 0; pS->inCountOut = inOutCount; if(inOutCount> 0) { pS->pchOutArgsType = malloc(inOutCount + 1); memset(pS->pchOutArgsType, 0x00, inOutCount + 1); pS->ppstListOut = malloc(sizeof(struct ST_VALUE *) * inOutCount); memset(pS->ppstListOut, 0x00, sizeof(struct ST_VALUE *) * inOutCount); for(inCnt= 0;inCnt< inOutCount;inCnt++) { SetValueDouble(pS->ppstListOut, inCnt, 0.0); } } //function setting pS->inCountFunction = inCountFunction; if(inCountFunction> 0) { pS->ppstListFunction = malloc(sizeof(struct ST_VALUE *) * inCountFunction); memset(pS->ppstListFunction, 0x00, sizeof(struct ST_VALUE *) * inCountFunction); for(inCnt= 0;inCnt< inMaxLine;inCnt++) { if(!(pS->ppchLines[inCnt][0]== 'f' && pS->ppchLines[inCnt][1]== '|')) continue; char *pchKey = strtok(&pS->ppchLines[inCnt][2], ":"); char *pchValue = strtok(NULL, ":"); int inLineNo = atoi(pchValue); int inRes = AddFunctionDefine(pS, pchKey, inLineNo); if(inRes!= SUCCESS) return (inRes); } } //set start position //set jump line no //create cmp string pS->pchListStartPos = malloc(sizeof(char) * inMaxLine); pS->pinListJumpNo = malloc(sizeof(int) * inMaxLine); pS->ppchListCmp = malloc(sizeof(char *) * inMaxLine); memset(pS->ppchListCmp, 0x00, sizeof(char *) * inMaxLine); for(inCnt= 0;inCnt< inMaxLine;inCnt++) { const char *pchLine = pS->ppchLines[inCnt]; pS->pchListStartPos[inCnt] = 0; pS->pinListJumpNo[inCnt] = 0; pS->ppchListCmp[inCnt] = NULL; if(pchLine[0]== '-' && pchLine[1]== '-') continue; if(pchLine[1]== '|') continue; char *pchIndex = strchr(pchLine, ':'); if(pchIndex== NULL) continue; pchIndex+= 1; pS->pchListStartPos[inCnt] = (char)(pchIndex - pchLine); if(pchIndex[0]== 'i' && pchIndex[1]== ':') { char *pchIndex2 = strstr(pchIndex, ")e"); if(pchIndex2!= NULL) { pS->pinListJumpNo[inCnt] = atoi(pchIndex2 + 2); int inSize = (int)(pchIndex2 - &pchIndex[3]); pS->ppchListCmp[inCnt] = malloc(inSize + 1); memset(pS->ppchListCmp[inCnt], 0x00, inSize + 1); strncpy(pS->ppchListCmp[inCnt], &pchIndex[3], inSize); } continue; } if(pchIndex[0]== 'g' && pchIndex[1]== ':') { pchIndex = strchr(pchIndex, ':'); if(pchIndex!= NULL) { pS->pinListJumpNo[inCnt] = atoi(pchIndex + 1); } continue; } } //memory allocate int inSize = sizeof(int) * inMaxLine; pS->pinListTokenNum = malloc(inSize); memset(pS->pinListTokenNum, 0x00, inSize); inSize = sizeof(int) * inMaxLine; pS->pinListTokenSt = malloc(inSize); memset(pS->pinListTokenSt, 0x00, inSize); //count token int inStToken = 0; int inMaxToken = 0; for(inCnt= 0;inCnt< inMaxLine;inCnt++) { const char *pchLine = pS->ppchLines[inCnt]; if(pchLine[0]== '-' && pchLine[1]== '-') continue; if(pchLine[1]== '|') continue; if(pS->pchListStartPos[inCnt]== 0) continue; char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]); if(pchIndex[0]== 'g' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'f' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'c' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'r' && pchIndex[1]== ':') continue; int inCntToken = 0; if(pchIndex[0]== 'o' && pchIndex[1]== ':') { inCntToken = CountToken(&pchIndex[2]); if(inMaxToken< inCntToken) inMaxToken = inCntToken; } /* if(pchIndex[0]== 's' && pchIndex[1]== ':') { inCntToken = CountToken(&pchIndex[5]); if(inMaxToken< inCntToken) inMaxToken = inCntToken; } if(pchIndex[0]== 'd' && pchIndex[1]== ':') { inCntToken = CountToken(&pchIndex[5]); if(inMaxToken< inCntToken) inMaxToken = inCntToken; } */ if(pchIndex[0]== 'i' && pchIndex[1]== ':') { inCntToken = CountToken(pS->ppchListCmp[inCnt]); if(inMaxToken< inCntToken) inMaxToken = inCntToken; } if(pchIndex[2]== '=') { inCntToken = CountToken(&pchIndex[3]); if(inMaxToken< inCntToken) inMaxToken = inCntToken; } pS->pinListTokenSt[inCnt] = inStToken; inStToken+= inCntToken; pS->pinListTokenNum[inCnt] = inCntToken; } //memory allocate pS->inMaxTokenNum = inMaxToken; inSize = sizeof(double) * inMaxToken * inMaxLine; pS->pdoListToken = malloc(inSize); memset(pS->pdoListToken, 0x00, inSize); inSize = sizeof(char) * inMaxToken * inMaxLine; pS->pchListTokenType = malloc(inSize); memset(pS->pchListTokenType, 0x00, inSize); inSize = sizeof(char) * MAX_WORD * inMaxToken * inMaxLine; pS->pchListTokenWord = malloc(inSize); memset(pS->pchListTokenWord, 0x00, inSize); //setup token data for(inCnt= 0;inCnt< inMaxLine;inCnt++) { const char *pchLine = pS->ppchLines[inCnt]; if(pchLine[0]== '-' && pchLine[1]== '-') continue; if(pchLine[1]== '|') continue; if(pS->pchListStartPos[inCnt]== 0) continue; char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]); if(pchIndex[0]== 'g' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'f' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'c' && pchIndex[1]== ':') continue; if(pchIndex[0]== 'r' && pchIndex[1]== ':') continue; int inStToken = pS->pinListTokenSt[inCnt]; if(pchIndex[0]== 'o' && pchIndex[1]== ':') { SetTokenData(pS, &pchIndex[2], inStToken); } /* if(pchIndex[0]== 's' && pchIndex[1]== ':') { SetTokenData(pS, &pchIndex[5], inStToken); } if(pchIndex[0]== 'd' && pchIndex[1]== ':') { SetTokenData(pS, &pchIndex[5], inStToken); } */ if(pchIndex[0]== 'i' && pchIndex[1]== ':') { SetTokenData(pS, pS->ppchListCmp[inCnt], inStToken); } if(pchIndex[2]== '=') { SetTokenData(pS, &pchIndex[3], inStToken); } } //global line execute int inFunc = 0; for(inCnt= 0;inCnt< inMaxLine;inCnt++) { const char *pchLine = pS->ppchLines[inCnt]; if(pchLine[0]== '-' && pchLine[1]== '-') { int inLength = strlen(pchLine); if(inLength<= 2) continue; int inVersion = atoi(&pchLine[2]); if(inVersion== VERSION) continue; return (ERR_VERSION); } if(pchLine[1]== '|') continue; pS->inLineNo = inCnt; char *pchIndex = (char *)(pchLine + pS->pchListStartPos[inCnt]); if(pchIndex[0]== 'f') inFunc = 1; if(pchIndex[0]== 'e') inFunc = 0; if(inFunc== 1) continue; if(pchIndex[0]== 'e' && pchIndex[1]== ':') continue; int inLineNo = ExecLine(pS, pchIndex); if(inLineNo< 0) return (inLineNo); } return (SUCCESS); }