diff --git a/.gitignore b/.gitignore index 87db40c4..c6fb8433 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ v2/pkg/parser/testproject/frontend/wails v2/test/kitchensink/frontend/public v2/test/kitchensink/build/darwin/desktop/kitchensink v2/test/kitchensink/frontend/package.json.md5 +/v2/internal/ffenestri/windows/test/cmake-build-debug/ +.idea/ diff --git a/v2/internal/ffenestri/ffenestri.go b/v2/internal/ffenestri/ffenestri.go index 7202e28d..96061443 100644 --- a/v2/internal/ffenestri/ffenestri.go +++ b/v2/internal/ffenestri/ffenestri.go @@ -173,7 +173,7 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string, debug // Oh no! We couldn't initialise the application a.logger.Fatal("Cannot initialise Application.") } - + //println("\n\n\n\n\n\nhererererer\n\n\n\n") a.freeMemory() return nil } diff --git a/v2/internal/ffenestri/ffenestri_windows.c b/v2/internal/ffenestri/ffenestri_windows.cpp similarity index 90% rename from v2/internal/ffenestri/ffenestri_windows.c rename to v2/internal/ffenestri/ffenestri_windows.cpp index 8c727a07..c534b9ff 100644 --- a/v2/internal/ffenestri/ffenestri_windows.c +++ b/v2/internal/ffenestri/ffenestri_windows.cpp @@ -15,7 +15,7 @@ typedef struct { } dispatchFunction; dispatchFunction* NewDispatchFunction(void *func) { - dispatchFunction *result = malloc(sizeof(dispatchFunction)); + dispatchFunction *result = (dispatchFunction *)malloc(sizeof(dispatchFunction)); result->func = func; result->argc = 0; return result; @@ -52,7 +52,7 @@ struct Application{ struct Application *NewApplication(const char *title, int width, int height, int resizable, int devtools, int fullscreen, int startHidden, int logLevel, int hideWindowOnClose) { // Create application - struct Application *result = malloc(sizeof(struct Application)); + struct Application *result = (struct Application*)malloc(sizeof(struct Application)); result->title = title; result->width = width; @@ -97,7 +97,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { case WM_DESTROY: { DestroyApplication(app); - break; + return 0; } case WM_GETMINMAXINFO: { // Exit early if this is called before the window is created. @@ -135,6 +135,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { default: return DefWindowProc(hwnd, msg, wParam, lParam); } + } void Run(struct Application* app, int argc, char **argv) { @@ -144,7 +145,7 @@ void Run(struct Application* app, int argc, char **argv) { ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.hInstance = hInstance; - wc.lpszClassName = "ffenestri"; + wc.lpszClassName = (LPCWSTR)"ffenestri"; wc.lpfnWndProc = WndProc; @@ -159,11 +160,12 @@ void Run(struct Application* app, int argc, char **argv) { } RegisterClassEx(&wc); - app->window = CreateWindow("ffenestri", "", windowStyle, CW_USEDEFAULT, + app->window = CreateWindow((LPCWSTR)"ffenestri", (LPCWSTR)"", windowStyle, CW_USEDEFAULT, CW_USEDEFAULT, app->width, app->height, NULL, NULL, GetModuleHandle(NULL), NULL); // Set Title - SetWindowText(app->window, app->title); + setTitle(app, app->title); + // Store application pointer in window handle SetWindowLongPtr(app->window, GWLP_USERDATA, (LONG_PTR)app); @@ -224,7 +226,7 @@ void hide(struct Application* app) { } void Hide(struct Application* app) { - dispatchFunction *f = NewDispatchFunction(hide); + dispatchFunction *f = NewDispatchFunction((void*)hide); f->args[0] = app; f->argc = 1; dispatch(f); @@ -235,7 +237,7 @@ void show(struct Application* app) { } void Show(struct Application* app) { - dispatchFunction *f = NewDispatchFunction(show); + dispatchFunction *f = NewDispatchFunction((void*)show); f->args[0] = app; f->argc = 1; dispatch(f); @@ -266,7 +268,7 @@ void center(struct Application* app) { } void Center(struct Application* app) { - dispatchFunction *f = NewDispatchFunction(center); + dispatchFunction *f = NewDispatchFunction((void*)center); f->args[0] = app; f->argc = 1; dispatch(f); @@ -292,7 +294,7 @@ void maximise(struct Application* app) { } void Maximise(struct Application* app) { - dispatchFunction *f = NewDispatchFunction(maximise); + dispatchFunction *f = NewDispatchFunction((void*)maximise); f->args[0] = app; f->argc = 1; dispatch(f); @@ -303,7 +305,7 @@ void unmaximise(struct Application* app) { } void Unmaximise(struct Application* app) { - dispatchFunction *f = NewDispatchFunction(unmaximise); + dispatchFunction *f = NewDispatchFunction((void*)unmaximise); f->args[0] = app; f->argc = 1; dispatch(f); @@ -326,7 +328,7 @@ void minimise(struct Application* app) { } void Minimise(struct Application* app) { - dispatchFunction *f = NewDispatchFunction(minimise); + dispatchFunction *f = NewDispatchFunction((void*)minimise); f->args[0] = app; f->argc = 1; dispatch(f); @@ -337,7 +339,7 @@ void unminimise(struct Application* app) { } void Unminimise(struct Application* app) { - dispatchFunction *f = NewDispatchFunction(unminimise); + dispatchFunction *f = NewDispatchFunction((void*)unminimise); f->args[0] = app; f->argc = 1; dispatch(f); @@ -361,12 +363,17 @@ void SetPosition(struct Application* app, int x, int y) { void Quit(struct Application* app) { } +// Credit: https://stackoverflow.com/a/6693107 void setTitle(struct Application* app, const char *title) { - SetWindowText(app->window, title); + int wchars_num = MultiByteToWideChar( CP_UTF8 , 0 , title , -1, NULL , 0 ); + wchar_t* wstr = new wchar_t[wchars_num]; + MultiByteToWideChar( CP_UTF8 , 0 , title , -1, wstr , wchars_num ); + SetWindowText(app->window, wstr); + delete[] wstr; } void SetTitle(struct Application* app, const char *title) { - dispatchFunction *f = NewDispatchFunction(setTitle); + dispatchFunction *f = NewDispatchFunction((void*)setTitle); f->args[0] = app; f->args[1] = (void*)title; f->argc = 2; diff --git a/v2/internal/ffenestri/ffenestri_windows.h b/v2/internal/ffenestri/ffenestri_windows.h index dbe507e1..c70db19b 100644 --- a/v2/internal/ffenestri/ffenestri_windows.h +++ b/v2/internal/ffenestri/ffenestri_windows.h @@ -2,10 +2,13 @@ #ifndef _FFENESTRI_WINDOWS_H #define _FFENESTRI_WINDOWS_H +#define UNICODE 1 + #include "ffenestri.h" #include #include void center(struct Application*); +void setTitle(struct Application* app, const char *title); #endif \ No newline at end of file diff --git a/v2/internal/ffenestri/windows/test/CMakeLists.txt b/v2/internal/ffenestri/windows/test/CMakeLists.txt new file mode 100644 index 00000000..fd324685 --- /dev/null +++ b/v2/internal/ffenestri/windows/test/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.19) +project(test C) + +set(CMAKE_C_STANDARD 99) +set(SOURCES ../../ffenestri_windows.cpp) + +add_executable(test ${SOURCES} main.c) \ No newline at end of file diff --git a/v2/internal/ffenestri/windows/test/compile.bat b/v2/internal/ffenestri/windows/test/compile.bat new file mode 100644 index 00000000..5340e6d8 --- /dev/null +++ b/v2/internal/ffenestri/windows/test/compile.bat @@ -0,0 +1,2 @@ +g++ main.c ..\..\ffenestri_windows.cpp -lgdi32 +a.exe \ No newline at end of file diff --git a/v2/internal/ffenestri/windows/test/main.c b/v2/internal/ffenestri/windows/test/main.c new file mode 100644 index 00000000..2deee540 --- /dev/null +++ b/v2/internal/ffenestri/windows/test/main.c @@ -0,0 +1,10 @@ +#include +#include "../../ffenestri_windows.h" + +int main() { + struct Application *app = NewApplication("Wails ❤️ Unicode", 800, 600, 1, 1, 0, 0, 1, 0); + SetMinWindowSize(app, 100, 100); + SetMaxWindowSize(app, 800, 800); + Run(app,0, NULL); + return 0; +} diff --git a/v2/internal/ffenestri/windows/x64/LICENSE b/v2/internal/ffenestri/windows/x64/LICENSE new file mode 100644 index 00000000..a2083304 --- /dev/null +++ b/v2/internal/ffenestri/windows/x64/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Josh Turpen, Will Speak + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/v2/internal/ffenestri/windows/x64/README.md b/v2/internal/ffenestri/windows/x64/README.md new file mode 100644 index 00000000..87ac7a34 --- /dev/null +++ b/v2/internal/ffenestri/windows/x64/README.md @@ -0,0 +1,2 @@ +These files are from the webview_csharp project at [this commit](https://github.com/webview/webview_csharp/tree/116591c415acd1c966fa02abaed939a3bb76719c/libs) +