// Do our list line drawing here (for cObjType_List or cObjType_DropList) bool oFontDropDown::drawListLine(EXTListLineInfo *pInfo, EXTCompInfo* pECI) { // draw our text qstring * text = newStringFromParam(1, pECI); // first parameter contains our calculated text :) if (text!=NULL) { GDItextSpecStruct textSpec = mCanvas->textSpec(); str255 fontName; qpoint leftTop(pInfo->mLineRect.left+20, pInfo->mLineRect.top); #ifndef iswin32 leftTop.h += 2; #endif // get our font name EXTfldval fontNameFld; str255 fontNameStr; pInfo->mListPtr->getColVal(pInfo->mLine, mFontColumn, fftCharacter, 0, fontNameFld); fontNameFld.getChar(fontNameStr); GDIsetFontName(&textSpec.mFnt, fontNameStr.cString(), fontNameStr.length()); // and draw our text mCanvas->drawText(text->cString(), leftTop, textSpec); delete text; }; return true; // we have drawn this... };
// Get an EXTfldval for a defined constant void OmnisTools::getEXTFldValFromConstant(EXTfldval& fVal, qlong constID, qlong prefixID) { // Check for prefix str80 prefixRead; str255 constantValue; if (prefixID > 0) { // Read string from resource, and assign it to return parameter RESloadString(gInstLib,prefixID,prefixRead); constantValue.concat(prefixRead); } // Read complete resource string str255 resourceValue; RESloadString(gInstLib,constID,resourceValue); // Translate into std::wstring for easy substring EXTfldval convVar; convVar.setChar(resourceValue, dpDefault); std::wstring resourceString = getWStringFromEXTFldVal(convVar); // Get substring between tilde (sometimes used for categories) and first colon. int tildePos = resourceString.find(L"~") + 1; int colonPos = resourceString.find(L":"); std::wstring constantString = resourceString.substr(tildePos,colonPos-tildePos); getEXTFldValFromWString(convVar, constantString); // Add constant to EXTfldval constantValue.concat(convVar.getChar()); fVal.setConstant(constantValue); }
void oImgBitmap::setContents(EXTfldval &pContents) { if (mImage == NULL) { // really? } else { // We get the binary as is, we assume the contents is raw picture data in any format supported by STB qlong bitmapLen = pContents.getBinLen(); if (bitmapLen > 0) { qbyte * bitmapData = (qbyte *)MEMmalloc(sizeof(qbyte) * (bitmapLen+1)); if (bitmapData != NULL) { qlong reallen; pContents.getBinary(bitmapLen, bitmapData, reallen); // and assign it to our image mImage->copy(bitmapData, reallen); // and free our memory MEMfree(bitmapData); } else { oBaseComponent::addToTraceLog("setContents: Couldn't allocate memory for pixel buffer"); }; } else { oBaseComponent::addToTraceLog("setContents: No image specified"); }; }; };
// get the value of a property qbool oDateTime::getProperty(qlong pPropID,EXTfldval &pGetValue,EXTCompInfo* pECI) { // most anum properties are managed by Omnis but some we need to do ourselves... switch (pPropID) { case oDT_localtime: { struct tm * timestruct = localtime(&mTimestamp); datestamptype omnisstamp; TimeStampToOmnis(*timestruct,omnisstamp); pGetValue.setDate(omnisstamp, dpFdtimeC); return true; }; break; case oDT_utctime: { struct tm * timestruct = gmtime(&mTimestamp); datestamptype omnisstamp; TimeStampToOmnis(*timestruct,omnisstamp); pGetValue.setDate(omnisstamp, dpFdtimeC); return true; }; break; default: return oBaseNVComponent::getProperty(pPropID, pGetValue, pECI); break; }; };
int OmnisTools::getIntFromEXTFldVal(EXTfldval& fVal, qlong firstID, qlong lastID) { if (getType(fVal).valType == fftInteger) { return getIntFromEXTFldVal(fVal); } else if (getType(fVal).valType == fftConstant) { return getIntFromEXTFldVal(fVal); } int retNum = -1; // Get string that needs to be matched std::wstring matchString = getWStringFromEXTFldVal(fVal); // Get map iterator for searching std::map<std::wstring,int>::iterator it; it = constCache.find(matchString); if (it != constCache.end()) { retNum = it->second; } else { // Unable to find match, must loop constants in range and look for it int tildePos, colonPos, numPos, constNum; EXTfldval convVar; str255 resourceValue; std::wstring resourceMatch, resourceString; std::wstring numString = L""; for( int i = firstID; i <= lastID; ++i) { // Load resource and put into std::wstring for easy substr RESloadString(gInstLib,i,resourceValue); convVar.setChar(resourceValue, dpDefault); resourceString = getWStringFromEXTFldVal(convVar); tildePos = resourceString.find(L"~") + 1; colonPos = resourceString.find(L":"); if (colonPos != -1) { // All constants should have colons. If it doesn't then don't interpret the line resourceMatch = resourceString.substr(tildePos, colonPos-tildePos); // While looping add items to the const cache numPos = colonPos + 1; numString.clear(); while (resourceString[numPos] != L':' && numPos < static_cast<int>(resourceString.length())) { numString += resourceString[numPos++]; } try { constNum = lexical_cast<int>(numString); } catch(bad_lexical_cast &) { constNum = -1; } constCache[resourceMatch] = constNum; // Add constant to cache } } // Locate constant now that all the constants have been cached it = constCache.find(matchString); if (it != constCache.end()) { retNum = it->second; } } return retNum; }
static void convertResult(EXTfldval& row, OmnisTools::ParamMap& params) { OmnisTools::ParamMap::iterator it; str255 colName; EXTfldval colVal; EXTqlist* retList = new EXTqlist(listVlen); // Return row // Add all output columns colName = initStr255("Result"); retList->addCol(fftRow, dpDefault, 0, &colName); retList->insertRow(); // Look for output data it = params.find("Result"); if( it != params.end()) { retList->getColValRef(1,1,colVal,qtrue); try { boost::shared_ptr<EXTqlist> ptr = boost::any_cast<boost::shared_ptr<EXTqlist> >(it->second); colVal.setList(ptr.get(), qtrue); } catch( const boost::bad_any_cast& e ) { LOG_ERROR << "Unable to cast return value from PostgreSQL worker."; } } row.setList(retList,qtrue); }
// Get a std::string from an EXTfldval object std::string OmnisTools::getStringFromEXTFldVal(EXTfldval& fVal) { std::string retString; // Get a qchar* string qlong maxLength = fVal.getBinLen()+1; // Use binary length as approximation of maximum size qlong length = 0, stringLength = 0; qchar* omnisString = new qchar[maxLength]; fVal.getChar(maxLength, omnisString, length); #ifdef UNICODE // Translate qchar* string into UTF8 binary qbyte* utf8data = reinterpret_cast<qbyte*>(omnisString); stringLength = CHRunicode::charToUtf8(omnisString, length, utf8data); char* cString = reinterpret_cast<char*> (utf8data); #else stringLength = length; retString = std::string((char*)omnisString,stringLength); #endif // Clean-up if (omnisString != NULL){ delete [] omnisString; } return retString; }
// Initializes the time zone. tResult NVObjTimeZone::methodInitialize( tThreadData* pThreadData, qshort pParamCount ) { // Parameter 1: (Optional) Location of time zone to initialize with EXTfldval locationVal; SystemTimeZone curZone; std::string locationString; if ( getParamVar(pThreadData, 1, locationVal) == qtrue ) { locationString = getStringFromEXTFldVal(locationVal); if (boost::iequals(locationString,"UTC")) { timezone = icaltimezone_get_utc_timezone(); } else { timezone = icaltimezone_get_builtin_timezone(locationString.c_str()); } } else { timezone = icaltimezone_get_builtin_timezone(curZone.name().c_str()); } // Copy the object and return to the caller (this allows inline calls) NVObjTimeZone* thisCopy = createNVObj<NVObjTimeZone>(pThreadData); if(!thisCopy) { return ERR_METHOD_FAILED; } thisCopy->copy(this); // Move data into new object EXTfldval retVal; retVal.setObjInst(thisCopy->getInstance(), qtrue); ECOaddParam(pThreadData->mEci, &retVal); return METHOD_DONE_RETURN; }
// Get a pointer to the root of the current object void JsonValue::methodRoot( tThreadData* pThreadData, qshort pParamCount ) { JsonValue *newObj = createNVObj<JsonValue>(pThreadData); newObj->setJsonValue(document); EXTfldval retVal; retVal.setObjInst( newObj->getInstance(), qtrue ); ECOaddParam( pThreadData->mEci, &retVal ); }
// Create a copy of the pointer at the current position. This copied pointer is trimmed above the current position. void JsonValue::methodCopy( tThreadData* pThreadData, qshort pParamCount ) { shared_ptr<Json::Value> copyValue(new Json::Value(*jsonValue)); JsonValue *newObj = createNVObj<JsonValue>(pThreadData); newObj->setJsonValue(copyValue); EXTfldval retVal; retVal.setObjInst( newObj->getInstance(), qtrue ); ECOaddParam( pThreadData->mEci, &retVal ); }
// Helper method to initialize the jsonValue to a new value. void JsonValue::setValueFromParameter(tThreadData *pThreadData, qshort paramNumber) { EXTParamInfo* param = ECOfindParamNum( pThreadData->mEci, paramNumber ); if( param ) { // Interpret the parameter we have EXTfldval fVal; fVal.setFldVal((qfldval)param->mData); setValueFromEXTfldval(pThreadData, fVal); } }
// Get a parameter from the EXTCompInfo qbool OmnisTools::getParamVar( EXTCompInfo* pEci, qshort pParamNum, EXTfldval& pOutVar ) { EXTParamInfo* param = ECOfindParamNum( pEci, pParamNum ); if( !param ) return qfalse; pOutVar.setFldVal(reinterpret_cast<qfldval>(param->mData)); pOutVar.setReadOnly( qfalse ); return qtrue; }
// Return a C++ std::vector of unsigned char from an EXTfldval std::vector<unsigned char> OmnisTools::getBinaryVectorFromEXTFldVal(EXTfldval& fVal) { std::vector<unsigned char> v; qlong realLength, bufferSize; bufferSize = fVal.getBinLen(); v.resize(bufferSize); fVal.getBinary(v.size(), &v[0], realLength); return v; }
boost::any OmnisTools::getAnyFromEXTFldVal(EXTfldval& val) { // Get column definition type ffttype fft; qshort fdp; val.getType( fft, &fdp ); str255 colName; EXTqlist *listVal; EXTfldval colVal, colTitleVal; std::vector<ParamMap> listVector; boost::any ret; // Assign map based on definition switch (fft) { case fftCharacter: ret = getStringFromEXTFldVal(val); break; case fftInteger: ret = getIntFromEXTFldVal(val); break; case fftNumber: ret = getDoubleFromEXTFldVal(val); break; case fftBoolean: ret = getBoolFromEXTFldVal(val); break; case fftBinary: ret = getBinaryVectorFromEXTFldVal(val); break; case fftRow: case fftList: listVal = val.getList(qfalse); listVector.clear(); for( qlong curRow = 1; curRow < listVal->rowCnt(); ++curRow ) { ParamMap row; for( qlong curCol = 1; curCol < listVal->colCnt(); ++curCol ) { listVal->getCol(curCol, qfalse, colName); colTitleVal.setChar(colName); listVal->getColValRef(curRow, curCol, colVal, qfalse); row[getStringFromEXTFldVal(colTitleVal)] = getAnyFromEXTFldVal(colVal); } listVector.push_back(row); } ret = listVector; break; default: LOG_DEBUG << "Unknown column type when converting parameters."; break; } return ret; }
// Method to retrieve a property of the object qlong JsonFastWriter::getProperty( tThreadData* pThreadData ) { EXTfldval fValReturn; qlong propID = ECOgetId( pThreadData->mEci ); switch( propID ) { case cPropertyMyProperty: fValReturn.setLong(myProperty); // Put property into return value ECOaddParam(pThreadData->mEci, &fValReturn); // Return to caller break; } return 1L; }
// Helper method to set the jsonValue for a specific group void JsonValue::setValueFromEXTfldval(tThreadData* pThreadData, EXTfldval &fVal, std::string group) { (*jsonValue)[group] = Json::Value(); // Get the data type of the parameter ffttype valType; fVal.getType(valType); // Perform appropriate initialization for each type if (valType == fftCharacter) { (*jsonValue)[group] = getStringFromEXTFldVal(fVal); } else if (valType == fftInteger) { (*jsonValue)[group] = getIntFromEXTFldVal(fVal); } else if (valType == fftNumber) { (*jsonValue)[group] = getDoubleFromEXTFldVal(fVal); } else if (valType == fftBoolean) { (*jsonValue)[group] = getBoolFromEXTFldVal(fVal); } else if (valType == fftDate) { (*jsonValue)[group] = getISO8601DateStringFromEXTFldVal(fVal); } // If no parameters were passed or an object couldn't be found, then init to NULL if ( (*jsonValue)[group].isNull() ) { (*jsonValue)[group] = Json::Value(); } }
// Convenience method to return the type of an EXTfldval OmnisTools::FieldValType OmnisTools::getType( EXTfldval& fVal ) { OmnisTools::FieldValType retType; fVal.getType(retType.valType, &retType.valSubType); return retType; }
// Return the contents of this value to the caller void JsonValue::getPropertyContents(EXTfldval &retVal, tThreadData* pThreadData) { switch (jsonValue->type()) { case Json::nullValue: retVal.setNull(fftCharacter, dpFcharacter); break; case Json::intValue: getEXTFldValFromInt(retVal, jsonValue->asInt()); break; case Json::uintValue: getEXTFldValFromInt(retVal, jsonValue->asUInt()); break; case Json::realValue: getEXTFldValFromDouble(retVal, jsonValue->asDouble()); break; case Json::stringValue: // String can be a string or a date if (isISO8601Date(jsonValue ->asString())) { getEXTfldvalFromISO8601DateString(retVal, jsonValue->asString()); } else { getEXTFldValFromString(retVal,jsonValue->asString()); } break; case Json::booleanValue: getEXTFldValFromBool(retVal, jsonValue->asBool()); break; case Json::arrayValue: getEXTFldValFromString(retVal,"<JSON Array>"); break; case Json::objectValue: getEXTFldValFromString(retVal,"<JSON Object>"); break; default: break; } }
void oImgBitmap::getContents(EXTfldval &pContents) { if (mImage == NULL) { pContents.setEmpty(fftBinary, 0); } else { int len = 0; unsigned char * pngdata = mImage->asPNG(len); if (pngdata == NULL) { oBaseComponent::addToTraceLog("getContents: No image"); pContents.setEmpty(fftBinary, 0); } else { pContents.setBinary(fftBinary, pngdata, len); free(pngdata); }; }; };
// Return a C++ long from an EXTfldval double OmnisTools::getDoubleFromEXTFldVal(EXTfldval& fVal) { qreal omnReal; qshort dp; fVal.getNum(omnReal, dp); double retDbl = static_cast<double>(omnReal); return retDbl; }
// Method to set a property of the object qlong NVObjSimple::setProperty( tThreadData* pThreadData ) { // Retrieve value to set for property, always in first parameter EXTfldval fVal; if( getParamVar( pThreadData->mEci, 1, fVal) == qfalse ) return qfalse; // Assign to the appropriate property qlong propID = ECOgetId( pThreadData->mEci ); switch( propID ) { case cPropertyMyProperty: myProperty = fVal.getLong(); break; } return 1L; }
// Return a C++ long from an EXTfldval float OmnisTools::getFloatFromEXTFldVal(EXTfldval& fVal) { qreal omnReal; qshort dp; fVal.getNum(omnReal, dp); float retFloat = static_cast<float>(omnReal); return retFloat; }
// Get a std::wstring from an EXTfldval object std::wstring OmnisTools::getWStringFromEXTFldVal(EXTfldval& fVal) { std::wstring retString; // Get a qchar* string qlong maxLength = fVal.getBinLen()+1; // Use binary length as approximation of maximum size qlong length = 0, stringLength = 0; qchar* omnisString = new qchar[maxLength]; fVal.getChar(maxLength, omnisString, length); wchar_t* cString; #if MARKUP_SIZEOFWCHAR == 2 // For 2-Byte UTF16 wchar_t* (Typically Windows) // Convert from UTF8 to UTF16 and set new stringLength // Translate qchar* string into UTF8 binary qbyte* utf8data = reinterpret_cast<qbyte*>(omnisString); stringLength = CHRunicode::charToUtf8(omnisString, length, utf8data); // Translate UTF8 to UTF16 CHRconvToUtf16 utf16conv(utf8data, stringLength); UChar* utf16data = utf16conv.dataPtr(); stringLength = utf16conv.len(); // Translate UTF16 binary into char* string cString = reinterpret_cast<wchar_t*>(utf16data); #else // For 4-Byte UTF32 wchar_t* (Typically Mac and Linux) // Convert from UTF8 to UTF32 and set new stringLength stringLength = length; CHRconvToUtf32FromChar utf32conv(omnisString, stringLength, qfalse); U32Char* utf32data = utf32conv.dataPtr(); stringLength = utf32conv.len(); // Translate UTF16 binary into char* string cString = reinterpret_cast<wchar_t*>(utf32data); #endif // Create standard string retString = std::wstring(cString,stringLength); // Clean-up delete [] omnisString; return retString; }
// Return a C++ int from an EXTfldval int OmnisTools::getIntFromEXTFldVal(EXTfldval& fVal) { qlong omnInt = fVal.getLong(); if (omnInt < INT_MIN || omnInt > INT_MAX) { omnInt = 0; // zero out any numbers that exceed } return static_cast<int>( omnInt ); }
// Get an EXTfldval for a C++ bool void OmnisTools::getEXTFldValFromBool(EXTfldval& fVal, bool b) { qshort omBool; if (b==true) omBool = 2; else if (b==false) omBool = 1; fVal.setBool(omBool); }
// Set an existing EXTfldval object from a std::string void OmnisTools::getEXTFldValFromString(EXTfldval& fVal, const std::string readString) { qlong length; qchar* omnisString = getQCharFromString(readString, length); fVal.setChar(omnisString, length); // Set value of character field, but exclude the last character since it will be the null terminator from the C String // Clean-up delete [] omnisString; }
// Method to set a property of the object qlong JsonFastWriter::setProperty( tThreadData* pThreadData ) { // Setup the EXTfldval with the parameter data EXTfldval fVal; if( getParamVar( pThreadData->mEci, 1, fVal ) == qfalse ) return 0L; // Assign to the appropriate property qlong propID = ECOgetId( pThreadData->mEci ); switch( propID ) { case cPropertyMyProperty: myProperty = fVal.getLong(); break; } return 1L; }
qbool OmnisTools::ensurePosixPath(EXTfldval& pathVal) { #ifdef ismac str255 posixCheck, posixPath; qshort def = dpFcharacter; posixCheck = pathVal.getChar().cString(); qlong err; std::wstring path = getWStringFromEXTFldVal(pathVal); if (path[0] != L'/') { err = ECOconvertHFSToPosix(posixCheck, posixPath); if (err != 0) { return qfalse; } pathVal.setChar(posixPath, def); } #endif return qtrue; }
// set the value of a property qbool oDateTime::setProperty(qlong pPropID,EXTfldval &pNewValue,EXTCompInfo* pECI) { // most anum properties are managed by Omnis but some we need to do ourselves, no idea why... switch (pPropID) { case oDT_localtime: { datestamptype omnisstamp; qbool success; pNewValue.getDate(omnisstamp, dpFdtimeC, &success); if (success) { struct tm timestruct; OmnisToTimeStruct(omnisstamp, timestruct); setTimestamp(mktime(×truct)); }; return qtrue; }; break; case oDT_utctime: { datestamptype omnisstamp; qbool success; pNewValue.getDate(omnisstamp, dpFdtimeC, &success); if (success) { struct tm timestruct; OmnisToTimeStruct(omnisstamp, timestruct); #ifdef iswin32 setTimestamp(_mkgmtime(×truct)); #else setTimestamp(timegm(×truct)); #endif }; return qtrue; }; break; default: return oBaseNVComponent::setProperty(pPropID, pNewValue, pECI); break; }; };
// Return a C++ bool from an EXTfldval bool OmnisTools::getBoolFromEXTFldVal(EXTfldval& fVal) { qshort omnBool; omnBool = fVal.getBool(); switch (omnBool) { case 2: return true; case 1: return false; default: return false; } }