Skip to content

Commit

Permalink
Merge pull request #139 from tryphotino/debug
Browse files Browse the repository at this point in the history
New 3.1.x release with UTF16 support removed.
  • Loading branch information
MikeYeager authored Sep 6, 2024
2 parents dc9e6f3 + 6c45119 commit 4690fdb
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 54 deletions.
9 changes: 6 additions & 3 deletions Photino.Native/Photino.Native.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\Debug\net8.0\</Command>
<PostBuildEvent>
<Message>
</Message>
<Command>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\</Command>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -195,6 +194,10 @@ COPY .\$(OutDir)WebView2Loader.dll ..\Photino.Test\bin\Debug\net8.0\</Command>
<SubSystem>Windows</SubSystem>
<AdditionalDependencies>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)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
Expand Down
21 changes: 16 additions & 5 deletions Photino.Native/Photino.Windows.Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<COMDLG_FILTERSPEC> 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;
Expand Down Expand Up @@ -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<IFileOpenDialog>(&hr, title, defaultPath);

if (SUCCEEDED(hr)) {
AddFilters(pfd, filters, filterCount);
AddFilters(pfd, filters, filterCount, _window);

DWORD dwOptions;
pfd->GetOptions(&dwOptions);
Expand All @@ -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<IFileOpenDialog>(&hr, title, defaultPath);

if (SUCCEEDED(hr)) {
Expand All @@ -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<IFileSaveDialog>(&hr, title, defaultPath);
if (SUCCEEDED(hr)) {
AddFilters(pfd, filters, filterCount);
AddFilters(pfd, filters, filterCount, _window);

DWORD dwOptions;
pfd->GetOptions(&dwOptions);
Expand Down Expand Up @@ -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 = {};
Expand Down
98 changes: 74 additions & 24 deletions Photino.Native/Photino.Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ void Photino::Register(HINSTANCE hInstance)
SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
}


Photino::Photino(PhotinoInitParams* initParams)
{
//wchar_t msg[50];
Expand All @@ -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);
}


Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -627,6 +636,7 @@ void Photino::Restore()

void Photino::SendWebMessage(AutoString message)
{
message = ToUTF16String(message);
_webviewWindow->PostWebMessageAsString(message);
}

Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
12 changes: 4 additions & 8 deletions Photino.Native/Photino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -84,7 +77,6 @@ struct PhotinoInitParams
MinimizedCallback *MinimizedHandler;
MovedCallback *MovedHandler;
WebMessageReceivedCallback *WebMessageReceivedHandler;
wchar_t *CustomSchemeNamesWide[16];
char *CustomSchemeNames[16];
WebResourceRequestedCallback *CustomSchemeHandler;

Expand Down Expand Up @@ -170,6 +162,8 @@ class Photino
bool EnsureWebViewIsInstalled();
bool InstallWebView2();
void AttachWebView();
bool ToWide(PhotinoInitParams* params);

#elif __linux__
// GtkWidget* _window;
GtkWidget *_webview;
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 5 additions & 14 deletions Photino.Test/Photino.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,10 @@
<DefineConstants>Linux</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishTrimmed>False</PublishTrimmed>
<PublishAot>False</PublishAot>
</PropertyGroup>

<ItemGroup>
Expand All @@ -61,7 +51,8 @@
</ItemGroup>

<Target Name="CopyNativeLibs" AfterTargets="Build">
<!-- <Copy SourceFiles="../lib/x64/Photino.Native.dll" DestinationFolder="$(TargetDir)" Condition="$(IsWindows) == 'true'" /> -->
<Copy SourceFiles="..\Photino.Native\x64\Debug\Photino.Native.dll" DestinationFolder="$(TargetDir)" Condition="$(IsWindows) == 'true'" />
<Copy SourceFiles="..\Photino.Native\x64\Debug\WebView2Loader.dll" DestinationFolder="$(TargetDir)" Condition="$(IsWindows) == 'true'" />
<Copy SourceFiles="../lib/x64/Photino.Native.dylib" DestinationFolder="$(TargetDir)" Condition="$(IsOSX) == 'true'" />
<Copy SourceFiles="../lib/x64/Photino.Native.so" DestinationFolder="$(TargetDir)" Condition="$(IsLinux) == 'true'" />
</Target>
Expand Down
Binary file modified manual-arm-release/linux-arm64/Photino.Native.so
Binary file not shown.

0 comments on commit 4690fdb

Please sign in to comment.