diff --git a/proj/Release - Unicode/BuildLog.htm b/proj/Release - Unicode/BuildLog.htm new file mode 100644 index 0000000..6ba1c1b Binary files /dev/null and b/proj/Release - Unicode/BuildLog.htm differ diff --git a/proj/webLib.sln b/proj/webLib.sln index 8347a4e..a8d44c5 100644 --- a/proj/webLib.sln +++ b/proj/webLib.sln @@ -5,20 +5,26 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "webLib", "webLib.vcproj", " EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug - Unicode|Win32 = Debug - Unicode|Win32 Debug|Win32 = Debug|Win32 + Release - Unicode|Win32 = Release - Unicode|Win32 Release|Win32 = Release|Win32 UNICODE Debug|Win32 = UNICODE Debug|Win32 UNICODE Release|Win32 = UNICODE Release|Win32 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CF830BCD-9C8A-428E-8086-D8F46F247131}.Debug|Win32.ActiveCfg = Debug|Win32 - {CF830BCD-9C8A-428E-8086-D8F46F247131}.Debug|Win32.Build.0 = Debug|Win32 - {CF830BCD-9C8A-428E-8086-D8F46F247131}.Release|Win32.ActiveCfg = Release|Win32 - {CF830BCD-9C8A-428E-8086-D8F46F247131}.Release|Win32.Build.0 = Release|Win32 - {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Debug|Win32.ActiveCfg = Debug|Win32 - {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Debug|Win32.Build.0 = Debug|Win32 - {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Release|Win32.ActiveCfg = Release|Win32 - {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Release|Win32.Build.0 = Release|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Debug - Unicode|Win32.ActiveCfg = Debug - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Debug - Unicode|Win32.Build.0 = Debug - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Debug|Win32.ActiveCfg = Release - Non-Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Debug|Win32.Build.0 = Release - Non-Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Release - Unicode|Win32.ActiveCfg = Release - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Release - Unicode|Win32.Build.0 = Release - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Release|Win32.ActiveCfg = Release - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.Release|Win32.Build.0 = Release - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Debug|Win32.ActiveCfg = Release - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Debug|Win32.Build.0 = Release - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Release|Win32.ActiveCfg = Release - Unicode|Win32 + {CF830BCD-9C8A-428E-8086-D8F46F247131}.UNICODE Release|Win32.Build.0 = Release - Unicode|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/proj/webLib.suo b/proj/webLib.suo index 4259b1d..e06d6d4 100644 Binary files a/proj/webLib.suo and b/proj/webLib.suo differ diff --git a/proj/webLib.vcproj b/proj/webLib.vcproj index 81d487c..3308449 100644 --- a/proj/webLib.vcproj +++ b/proj/webLib.vcproj @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/OmnisTools.cpp b/src/OmnisTools.cpp index 773b1bd..3299e8a 100644 --- a/src/OmnisTools.cpp +++ b/src/OmnisTools.cpp @@ -43,8 +43,51 @@ #include +// Set an existing EXTfldval object from a std::string +#ifdef isunicode +qchar* OmnisTools::getQCharFromString(const std::string readString, qlong &retLength) { + qlong length = readString.size(); + + // Cast-away constness of c_str() pointer + char* cString = const_cast(readString.c_str()); + + // Feed into raw byte data + qbyte* utf8data = reinterpret_cast (cString); + + // Allocate new qchar* string + qchar* omnisString = new qchar[length]; + + // Convert to Omnis Character field + retLength = CHRunicode::utf8ToChar(utf8data, length, omnisString); // Convert characters into Omnis Char Field + + return omnisString; +} // 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; +} +#else +// Get a dynamically allocated qchar* array from a std::string +qchar* OmnisTools::getQCharFromString(const std::string readString, qlong &retLength) { + + // Get a dynamically allocated qchar* array from a std::string + qlong length = retLength = readString.size(); + qoschar* cString = const_cast(readString.c_str()); + qoschar* utf8data = reinterpret_cast(cString); + CHRconvFromOs test(utf8data,length); + + qchar* qcharData = new qchar[length+1]; + OMstrcpy(qcharData, test.dataPtr()); + return qcharData; +} + void OmnisTools::getEXTFldValFromString(EXTfldval& fVal, const std::string readString) { qlong length = readString.size(); @@ -57,8 +100,8 @@ void OmnisTools::getEXTFldValFromString(EXTfldval& fVal, const std::string readS // Clean-up delete [] qcharData; - } +#endif // Set an existing EXTfldval object from a std::wstring void OmnisTools::getEXTFldValFromChar(EXTfldval& fVal, const char* readChar) { @@ -71,35 +114,22 @@ void OmnisTools::getEXTFldValFromChar(EXTfldval& fVal, const char* readChar) { getEXTFldValFromString(fVal, readString); } -// Get a dynamically allocated qchar* array from a std::string -qchar* OmnisTools::getQCharFromString(const std::string readString, qlong &retLength) { - - // Get a dynamically allocated qchar* array from a std::string - qlong length = retLength = readString.size(); - qoschar* cString = const_cast(readString.c_str()); - qoschar* utf8data = reinterpret_cast(cString); - CHRconvFromOs test(utf8data,length); - - qchar* qcharData = new qchar[length+1]; - OMstrcpy(qcharData, test.dataPtr()); - return qcharData; -} - - - - // Get a std::string from an EXTfldval object +#ifdef isunicode std::string OmnisTools::getStringFromEXTFldVal(EXTfldval& fVal) { std::string retString; // Get a qchar* string - qlong maxLength = fVal.getBinLen()*2; // Use binary length as approximation of maximum size + 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); - - qoschar* utf8data = reinterpret_cast(omnisString); - stringLength = CHRconvToOs::convToOs(omnisString,length,utf8data); + + // Translate qchar* string into UTF8 binary + qbyte* utf8data = reinterpret_cast(omnisString); + stringLength = CHRunicode::charToUtf8(omnisString, length, utf8data); + + // Translate UTF8 binary into char* string char* cString = reinterpret_cast (utf8data); // Create standard string @@ -110,30 +140,46 @@ std::string OmnisTools::getStringFromEXTFldVal(EXTfldval& fVal) { return retString; } - -// Get a std::string from an EXTfldval object -Awesomium::WebString OmnisTools::getWebStringFromEXTFldVal(EXTfldval& fVal) { - std::string retString; +#else +std::string OmnisTools::getStringFromEXTFldVal(EXTfldval& fVal) { + std::string retString; // Get a qchar* string - qlong maxLength = fVal.getBinLen() + 5; // Use binary length as approximation of maximum size + qlong maxLength = fVal.getBinLen()*2; // Use binary length as approximation of maximum size qlong length = 0, stringLength = 0; qchar* omnisString = new qchar[maxLength]; fVal.getChar(maxLength, omnisString, length); - + qoschar* utf8data = reinterpret_cast(omnisString); stringLength = CHRconvToOs::convToOs(omnisString,length,utf8data); char* cString = reinterpret_cast (utf8data); - std::string input = std::string(cString,stringLength); - Awesomium::WebString webString = getWebStringFromStr(input); + // Create standard string + retString = std::string(cString,stringLength); + // Clean-up delete [] omnisString; + return retString; +} +#endif + + +// Get a std::string from an EXTfldval object +Awesomium::WebString OmnisTools::getWebStringFromEXTFldVal(EXTfldval& fVal) { + std::string retString; + std::string input = getStringFromEXTFldVal(fVal); + Awesomium::WebString webString = getWebStringFromStr(input); return webString; } // Get a std::string from an EXTfldval object +#ifdef isunicode +Awesomium::WebString OmnisTools::getWebStringFromStr(std::string& value) { + Awesomium::WebString webString = Awesomium::ToWebString(value); + return webString; +} +#else Awesomium::WebString OmnisTools::getWebStringFromStr(std::string& value) { Awesomium::WebString webString; if (value.length()<=0){ @@ -147,27 +193,15 @@ Awesomium::WebString OmnisTools::getWebStringFromStr(std::string& value) { return webString; } +#endif -// Get a std::string from an EXTfldval object -Awesomium::WebString OmnisTools::getWebStringFromStr255(str255& value) { - - // Get a qchar* string - qlong maxLength = value.length() + 5; - qlong stringLength = 0; - qchar* omnisString = value.cString(); - - qoschar* utf8data = reinterpret_cast(omnisString); - stringLength = CHRconvToOs::convToOs(omnisString,maxLength,utf8data); - char* cString = reinterpret_cast (utf8data); - - std::string input = std::string(cString,stringLength); - Awesomium::WebString webString = getWebStringFromStr(input); - return webString; +#ifdef isunicode +std::string OmnisTools::getStringFromWebString(const Awesomium::WebString& value) { + std::string output = Awesomium::ToString(value); + return output; } - - -// Get a std::string from an EXTfldval object +#else std::string OmnisTools::getStringFromWebString(const Awesomium::WebString& value) { std::string output; std::string input = Awesomium::ToString(value); @@ -179,6 +213,7 @@ std::string OmnisTools::getStringFromWebString(const Awesomium::WebString& value } return output; } +#endif // Return a C++ int from an EXTfldval @@ -217,10 +252,26 @@ void OmnisTools::getEXTFldValFromInt64(EXTfldval& fVal, int64 i) { } +// Get a str255 object for a character constant (No string if it doesn't correspond to the conditions) +#ifdef isunicode +str255 OmnisTools::initStr255(const char* in) { + str255 theString; + qshort length = strlen(in); + if (length > 0 && length <= 255) { + theString.setUtf8((qbyte*) in, strlen(in)); + } + return theString; +} +#else +str255 OmnisTools::initStr255(const char* in) { + return str255(in); +} +#endif -void OmnisTools::logToTrace(str255 msg) +void OmnisTools::logToTrace(const char* msg) { #if defined(IS_DEBUG) - ECOaddTraceLine(&msg); + str255 logString = initStr255(msg); + ECOaddTraceLine(&logString); #endif } diff --git a/src/OmnisTools.h b/src/OmnisTools.h index 90b727f..63ecc45 100644 --- a/src/OmnisTools.h +++ b/src/OmnisTools.h @@ -59,7 +59,6 @@ namespace OmnisTools { Awesomium::WebString getWebStringFromEXTFldVal(EXTfldval& fVal); Awesomium::WebString getWebStringFromStr(std::string& value); - Awesomium::WebString getWebStringFromStr255(str255& value); std::string getStringFromWebString(const Awesomium::WebString& value); int getIntFromEXTFldVal(EXTfldval& fVal); @@ -70,10 +69,11 @@ namespace OmnisTools { void getEXTFldValFromInt64(EXTfldval& fVal, int64); void getEXTFldValFromBool(EXTfldval& fVal, bool b); + str255 initStr255(const char*); // Allg Helpers qchar* getQCharFromString( const std::string readString, qlong &retLength ); - void logToTrace(str255 msg); + void logToTrace(const char* msg); } #endif // OMNIS_TOOLS_HE_ diff --git a/src/WebBrowser.cpp b/src/WebBrowser.cpp index 4158b98..0f33121 100644 --- a/src/WebBrowser.cpp +++ b/src/WebBrowser.cpp @@ -54,7 +54,7 @@ WebBrowser::WebBrowser(HWND pHWnd, Awesomium::WebSession* pWebSession) WebBrowser::~WebBrowser() { - OmnisTools::logToTrace(str255("destruct()")); + OmnisTools::logToTrace("destruct()"); // Cleanup if (mWndTimerSet){ @@ -110,20 +110,17 @@ Awesomium::WebSession* WebBrowser::getWebSession(){ qlong WebBrowser::initWebView() { - OmnisTools::logToTrace(str255("initWebView()")); + OmnisTools::logToTrace("initWebView()"); // Prüfen ob der WebCore bereits initialisiert wurde mWebCore = Awesomium::WebCore::instance(); if (!mWebCore){ - OmnisTools::logToTrace(str255("Webcore intializing")); - - qchar* cUserPath = mUserPath.cString(); - qchar* cBasePath = mBasePath.cString(); - + OmnisTools::logToTrace("Webcore intializing"); + // Setup path Vars - Awesomium::WebString _logfile = Awesomium::WSLit((const char*) cUserPath); - Awesomium::WebString _pluginPath = Awesomium::WSLit((const char*) cBasePath); - Awesomium::WebString _sysPath = Awesomium::WSLit((const char*) cBasePath); + Awesomium::WebString _logfile = Awesomium::ToWebString(mUserPath); + Awesomium::WebString _pluginPath = Awesomium::ToWebString(mBasePath); + Awesomium::WebString _sysPath = Awesomium::ToWebString(mBasePath); _logfile.Append(Awesomium::WSLit("\\debug.log")); _pluginPath.Append(Awesomium::WSLit("plugins\\")); @@ -179,23 +176,21 @@ qlong WebBrowser::initWebView() prefs.accept_language = Awesomium::WSLit("de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4"); prefs.default_encoding = Awesomium::WSLit("UTF-8"); - qchar* cUserPath = mUserPath.cString(); - Awesomium::WebString _sessionPath = Awesomium::WSLit((const char*) cUserPath); + Awesomium::WebString _sessionPath = Awesomium::ToWebString(mUserPath); _sessionPath.Append(Awesomium::WSLit("")); - if (cUserPath) { + if (mUserPath.length() > 0) { // Persitent - OmnisTools::logToTrace(str255("persitent-session")); + OmnisTools::logToTrace("persitent-session"); mWebSession = mWebCore->CreateWebSession(_sessionPath, prefs); }else { // In memory - OmnisTools::logToTrace(str255("in-memory-session")); + OmnisTools::logToTrace("in-memory-session"); mWebSession = mWebCore->CreateWebSession(Awesomium::WSLit(""), prefs); } - qchar* cBasePath = mBasePath.cString(); - Awesomium::WebString _pakPath = Awesomium::WSLit((const char*) cBasePath); + Awesomium::WebString _pakPath = Awesomium::ToWebString(mBasePath); _pakPath.Append(Awesomium::WSLit("paks\\weblib.pak")); Awesomium::DataSource* data_source = new Awesomium::DataPakSource(_pakPath); @@ -255,8 +250,8 @@ void WebBrowser::setupWebView(){ mMethodDispatcher.Bind(jsObj,Awesomium::WSLit("doCompInit"),JSDelegate(this, &WebBrowser::jsDoCompInit)); - jsObj.SetProperty(Awesomium::WSLit("basePath"),OmnisTools::getWebStringFromStr255(mBasePath)); - jsObj.SetProperty(Awesomium::WSLit("userPath"),OmnisTools::getWebStringFromStr255(mUserPath)); + jsObj.SetProperty(Awesomium::WSLit("basePath"), Awesomium::ToWebString(mBasePath)); + jsObj.SetProperty(Awesomium::WSLit("userPath"), Awesomium::ToWebString(mUserPath)); } else { // Event evOnJsInitFailed occurred. Send event to OMNIS @@ -536,7 +531,7 @@ qlong WebBrowser::startDownload(int downloadId,std::string downloadPath){ qlong WebBrowser::shutDownWebView() { int result = 0; - OmnisTools::logToTrace(str255("shutDown WebView()")); + OmnisTools::logToTrace("shutDown WebView()"); if (mWebView) { mWebView->Stop(); @@ -634,12 +629,12 @@ qlong WebBrowser::attributeSupport( LPARAM pMessage, WPARAM wParam, LPARAM lPara { case pBasePath: { - mBasePath = (str255)fval.getChar(); + mBasePath = OmnisTools::getStringFromEXTFldVal(fval); break; } case pUserPath: { - mUserPath = (str255)fval.getChar(); + mUserPath = OmnisTools::getStringFromEXTFldVal(fval); break; } } @@ -655,13 +650,13 @@ qlong WebBrowser::attributeSupport( LPARAM pMessage, WPARAM wParam, LPARAM lPara { // we are setting our color property case pBasePath: - { - fval.setChar((str255) mBasePath); + { + OmnisTools::getEXTFldValFromString(fval, mBasePath); break; } case pUserPath: { - fval.setChar((str255) mUserPath); + OmnisTools::getEXTFldValFromString(fval, mUserPath); break; } } diff --git a/src/WebBrowser.h b/src/WebBrowser.h index 0f35ddb..8425f4d 100644 --- a/src/WebBrowser.h +++ b/src/WebBrowser.h @@ -103,8 +103,8 @@ namespace WebLib { qbool mInitCompleted; // Omnis Props - str255 mBasePath; - str255 mUserPath; + std::string mBasePath; + std::string mUserPath; // Window Proc qbool mWndTimerSet; @@ -164,7 +164,7 @@ namespace WebLib { // Methoden Helper Methoden static WebBrowser *objectFromHwnd(HWND pHwnd, EXTCompInfo *eci); - static void logToTrace(str255 msg); + static void logToTrace(const char* msg); }; } // namespace WebLib