diff --git a/Photino.Native/Photino.Native.vcxproj b/Photino.Native/Photino.Native.vcxproj index 7749b71..ac5657a 100644 --- a/Photino.Native/Photino.Native.vcxproj +++ b/Photino.Native/Photino.Native.vcxproj @@ -172,9 +172,8 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\Debug\net8.0\ - COPY .\$(OutDir)Photino.Native.dll ..\Photino.Test\bin\Debug\net8.0\ -COPY .\$(OutDir)Photino.Native.pdb ..\Photino.Test\bin\Debug\net8.0\ -COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\Debug\net8.0\ + + @@ -195,6 +194,10 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\Debug\net8.0\ Windows kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;shlwapi.lib;%(AdditionalDependencies) + + + + diff --git a/Photino.Native/Photino.Windows.Dialog.cpp b/Photino.Native/Photino.Windows.Dialog.cpp index 8468dae..c06de10 100644 --- a/Photino.Native/Photino.Windows.Dialog.cpp +++ b/Photino.Native/Photino.Windows.Dialog.cpp @@ -119,12 +119,13 @@ T* Create(HRESULT* hResult, AutoString title, AutoString defaultPath) return nullptr; } -void AddFilters(IFileDialog* pfd, wchar_t** filters, const int filterCount) +void AddFilters(IFileDialog* pfd, wchar_t** filters, const int filterCount, Photino* wndInstance) { std::vector specs; for (int i = 0; i < filterCount; i++) { auto* filter = new wchar_t[MAX_PATH]; - wcscpy_s(filter, MAX_PATH, filters[i]); + AutoString wFilter = wndInstance->ToUTF16String(filters[i]); + wcscpy_s(filter, MAX_PATH, wFilter); const wchar_t* filterName = wcstok_s(filter, L"|", &filter); const wchar_t* filterPattern = filter; @@ -175,10 +176,13 @@ AutoString* GetResults(IFileOpenDialog* pfd, HRESULT* hr, int* resultCount) AutoString* PhotinoDialog::ShowOpenFile(AutoString title, AutoString defaultPath, bool multiSelect, AutoString* filters, int filterCount, int* resultCount) { HRESULT hr; + title = _window->ToUTF16String(title); + defaultPath = _window->ToUTF16String(defaultPath); + auto* pfd = Create(&hr, title, defaultPath); if (SUCCEEDED(hr)) { - AddFilters(pfd, filters, filterCount); + AddFilters(pfd, filters, filterCount, _window); DWORD dwOptions; pfd->GetOptions(&dwOptions); @@ -202,7 +206,10 @@ AutoString* PhotinoDialog::ShowOpenFile(AutoString title, AutoString defaultPath AutoString* PhotinoDialog::ShowOpenFolder(AutoString title, AutoString defaultPath, bool multiSelect, int* resultCount) { - HRESULT hr; + HRESULT hr; + title = _window->ToUTF16String(title); + defaultPath = _window->ToUTF16String(defaultPath); + auto* pfd = Create(&hr, title, defaultPath); if (SUCCEEDED(hr)) { @@ -229,9 +236,11 @@ AutoString* PhotinoDialog::ShowOpenFolder(AutoString title, AutoString defaultPa AutoString PhotinoDialog::ShowSaveFile(AutoString title, AutoString defaultPath, AutoString* filters, int filterCount) { HRESULT hr; + title = _window->ToUTF16String(title); + defaultPath = _window->ToUTF16String(defaultPath); auto* pfd = Create(&hr, title, defaultPath); if (SUCCEEDED(hr)) { - AddFilters(pfd, filters, filterCount); + AddFilters(pfd, filters, filterCount, _window); DWORD dwOptions; pfd->GetOptions(&dwOptions); @@ -264,6 +273,8 @@ AutoString PhotinoDialog::ShowSaveFile(AutoString title, AutoString defaultPath, DialogResult PhotinoDialog::ShowMessage(AutoString title, AutoString text, DialogButtons buttons, DialogIcon icon) { + title = _window->ToUTF16String(title); + text = _window->ToUTF16String(text); NewStyleContext ctx; UINT flags = {}; diff --git a/Photino.Native/Photino.Windows.cpp b/Photino.Native/Photino.Windows.cpp index ce43377..c4d2735 100644 --- a/Photino.Native/Photino.Windows.cpp +++ b/Photino.Native/Photino.Windows.cpp @@ -72,7 +72,6 @@ void Photino::Register(HINSTANCE hInstance) SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); } - Photino::Photino(PhotinoInitParams* initParams) { //wchar_t msg[50]; @@ -92,55 +91,60 @@ Photino::Photino(PhotinoInitParams* initParams) } _windowTitle = new wchar_t[256]; - - if (initParams->TitleWide != NULL) + if (initParams->Title != NULL) { - WinToast::instance()->setAppName(initParams->TitleWide); - WinToast::instance()->setAppUserModelId(initParams->TitleWide); - wcscpy(_windowTitle, initParams->TitleWide); + AutoString wTitle = ToUTF16String((AutoString)initParams->Title); + WinToast::instance()->setAppName(wTitle); + WinToast::instance()->setAppUserModelId(wTitle); + wcscpy(_windowTitle, wTitle); } else _windowTitle[0] = 0; _startUrl = NULL; - if (initParams->StartUrlWide != NULL) + if (initParams->StartUrl != NULL) { _startUrl = new wchar_t[2048]; if (_startUrl == NULL) exit(0); - wcscpy(_startUrl, initParams->StartUrlWide); + AutoString wStartUrl = ToUTF16String((AutoString)initParams->StartUrl); + wcscpy(_startUrl, wStartUrl); } _startString = NULL; - if (initParams->StartStringWide != NULL) + if (initParams->StartString != NULL) { - _startString = new wchar_t[wcslen(initParams->StartStringWide) + 1]; + AutoString wStartString = ToUTF16String((AutoString)initParams->StartString); + _startString = new wchar_t[wcslen(wStartString) + 1]; if (_startString == NULL) exit(0); - wcscpy(_startString, initParams->StartStringWide); + wcscpy(_startString, wStartString); } _temporaryFilesPath = NULL; - if (initParams->TemporaryFilesPathWide != NULL) + if (initParams->TemporaryFilesPath != NULL) { _temporaryFilesPath = new wchar_t[256]; if (_temporaryFilesPath == NULL) exit(0); - wcscpy(_temporaryFilesPath, initParams->TemporaryFilesPathWide); + AutoString wTemporaryFilesPath = ToUTF16String((AutoString)initParams->TemporaryFilesPath); + wcscpy(_temporaryFilesPath, wTemporaryFilesPath); } _userAgent = NULL; - if (initParams->UserAgentWide != NULL) + if (initParams->UserAgent != NULL) { - _userAgent = new wchar_t[wcslen(initParams->UserAgentWide) + 1]; + AutoString wUserAgent = ToUTF16String((AutoString)initParams->UserAgent); + _userAgent = new wchar_t[wcslen(wUserAgent) + 1]; if (_userAgent == NULL) exit(0); - wcscpy(_userAgent, initParams->UserAgentWide); + wcscpy(_userAgent, wUserAgent); } _browserControlInitParameters = NULL; - if (initParams->BrowserControlInitParametersWide != NULL) + if (initParams->BrowserControlInitParameters != NULL) { - _browserControlInitParameters = new wchar_t[wcslen(initParams->BrowserControlInitParametersWide) + 1]; + AutoString wBrowserControlInitParameters = ToUTF16String((AutoString)initParams->BrowserControlInitParameters); + _browserControlInitParameters = new wchar_t[wcslen(wBrowserControlInitParameters) + 1]; if (_browserControlInitParameters == NULL) exit(0); - wcscpy(_browserControlInitParameters, initParams->BrowserControlInitParametersWide); + wcscpy(_browserControlInitParameters, wBrowserControlInitParameters); } @@ -177,10 +181,11 @@ Photino::Photino(PhotinoInitParams* initParams) //copy strings from the fixed size array passed, but only if they have a value. for (int i = 0; i < 16; ++i) { - if (initParams->CustomSchemeNamesWide[i] != NULL) + if (initParams->CustomSchemeNames[i] != NULL) { wchar_t* name = new wchar_t[50]; - wcscpy(name, initParams->CustomSchemeNamesWide[i]); + AutoString wCustomSchemeNames = ToUTF16String((AutoString)initParams->CustomSchemeNames[i]); + wcscpy(name, wCustomSchemeNames); _customSchemeNames.push_back(name); } } @@ -236,7 +241,7 @@ Photino::Photino(PhotinoInitParams* initParams) _hWnd = CreateWindowEx( initParams->Transparent ? WS_EX_LAYERED : 0, //WS_EX_OVERLAPPEDWINDOW, //An optional extended window style. CLASS_NAME, //Window class - initParams->TitleWide, //Window text + _windowTitle, //Window text initParams->Chromeless || initParams->FullScreen ? WS_POPUP : WS_OVERLAPPEDWINDOW, //Window style // Size and position @@ -249,8 +254,12 @@ Photino::Photino(PhotinoInitParams* initParams) ); hwndToPhotino[_hWnd] = this; - if (initParams->WindowIconFileWide != NULL && initParams->WindowIconFileWide != L"") - Photino::SetIconFile(initParams->WindowIconFileWide); + if (initParams->WindowIconFile != NULL) + { + AutoString wWindowIconFile = ToUTF16String((AutoString)initParams->WindowIconFile); + Photino::SetIconFile(wWindowIconFile); + } + if (initParams->CenterOnInitialize) Photino::Center(); @@ -627,6 +636,7 @@ void Photino::Restore() void Photino::SendWebMessage(AutoString message) { + message = ToUTF16String(message); _webviewWindow->PostWebMessageAsString(message); } @@ -752,6 +762,7 @@ void Photino::SetSize(int width, int height) void Photino::SetTitle(AutoString title) { + title = ToUTF16String((AutoString)title); if (wcslen(title) > 255) { for (int i = 0; i < 256; i++) @@ -787,6 +798,8 @@ void Photino::SetZoom(int zoom) void Photino::ShowNotification(AutoString title, AutoString body) { + title = ToUTF16String(title); + body = ToUTF16String(body); if (WinToast::isCompatible()) { WinToastTemplate toast = WinToastTemplate(WinToastTemplate::ImageAndText02); @@ -863,6 +876,43 @@ void Photino::Invoke(ACTION callback) //private methods +AutoString Photino::ToUTF8String(AutoString source) +{ + AutoString response; + std::string* stringBuffer = new std::string(); + int inLen = (int)wcslen(source); + int result = WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)source, inLen, NULL, 0, NULL, 0); + if (result < 0) + { + response = (AutoString)"UTF8 to UTF16 convert failed"; + } + else + { + stringBuffer->resize(result, 0); + result = WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)source, inLen, &(*stringBuffer)[0], result, NULL, 0); + response = (AutoString)stringBuffer->c_str(); + } + return response; +} +AutoString Photino::ToUTF16String(AutoString source) +{ + AutoString response; + std::wstring* wideBuffer = new std::wstring(); + int inLen = (int)strlen((char*)source); + int result = MultiByteToWideChar(CP_UTF8, 0, (char*)source, inLen, NULL, 0); + if (result < 0) + { + response = (AutoString)"UTF8 to UTF16 convert failed"; + } + else + { + wideBuffer->resize(result, 0); + result = MultiByteToWideChar(CP_UTF8, 0, (char*)source, inLen, &(*wideBuffer)[0], result); + response = (AutoString)wideBuffer->c_str(); + } + return response; +} + void Photino::AttachWebView() { size_t runtimePathLen = wcsnlen(_webview2RuntimePath, _countof(_webview2RuntimePath)); diff --git a/Photino.Native/Photino.h b/Photino.Native/Photino.h index b87132f..ca9d016 100644 --- a/Photino.Native/Photino.h +++ b/Photino.Native/Photino.h @@ -58,19 +58,12 @@ class Photino; struct PhotinoInitParams { - wchar_t *StartStringWide; char *StartString; - wchar_t *StartUrlWide; char *StartUrl; - wchar_t *TitleWide; char *Title; - wchar_t *WindowIconFileWide; char *WindowIconFile; - wchar_t *TemporaryFilesPathWide; char *TemporaryFilesPath; - wchar_t* UserAgentWide; char * UserAgent; - wchar_t* BrowserControlInitParametersWide; char* BrowserControlInitParameters; Photino *ParentInstance; @@ -84,7 +77,6 @@ struct PhotinoInitParams MinimizedCallback *MinimizedHandler; MovedCallback *MovedHandler; WebMessageReceivedCallback *WebMessageReceivedHandler; - wchar_t *CustomSchemeNamesWide[16]; char *CustomSchemeNames[16]; WebResourceRequestedCallback *CustomSchemeHandler; @@ -170,6 +162,8 @@ class Photino bool EnsureWebViewIsInstalled(); bool InstallWebView2(); void AttachWebView(); + bool ToWide(PhotinoInitParams* params); + #elif __linux__ // GtkWidget* _window; GtkWidget *_webview; @@ -215,6 +209,8 @@ class Photino void RefitContent(); void FocusWebView2(); void NotifyWebView2WindowMove(); + AutoString ToUTF16String(AutoString source); + AutoString ToUTF8String(AutoString source); int _minWidth; int _minHeight; int _maxWidth; diff --git a/Photino.Test/Photino.Test.csproj b/Photino.Test/Photino.Test.csproj index 9fd712f..961288b 100644 --- a/Photino.Test/Photino.Test.csproj +++ b/Photino.Test/Photino.Test.csproj @@ -22,20 +22,10 @@ Linux - - true - - - - true - - - - true - - - + true + False + False @@ -61,7 +51,8 @@ - + + diff --git a/manual-arm-release/linux-arm64/Photino.Native.so b/manual-arm-release/linux-arm64/Photino.Native.so index 118d1ad..fb493c0 100755 Binary files a/manual-arm-release/linux-arm64/Photino.Native.so and b/manual-arm-release/linux-arm64/Photino.Native.so differ