mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
[windows] Move to C++. Support unicode titles. Add test.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -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/
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -2,10 +2,13 @@
|
||||
#ifndef _FFENESTRI_WINDOWS_H
|
||||
#define _FFENESTRI_WINDOWS_H
|
||||
|
||||
#define UNICODE 1
|
||||
|
||||
#include "ffenestri.h"
|
||||
#include <windows.h>
|
||||
#include <wingdi.h>
|
||||
|
||||
void center(struct Application*);
|
||||
void setTitle(struct Application* app, const char *title);
|
||||
|
||||
#endif
|
||||
7
v2/internal/ffenestri/windows/test/CMakeLists.txt
Normal file
7
v2/internal/ffenestri/windows/test/CMakeLists.txt
Normal file
@@ -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)
|
||||
2
v2/internal/ffenestri/windows/test/compile.bat
Normal file
2
v2/internal/ffenestri/windows/test/compile.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
g++ main.c ..\..\ffenestri_windows.cpp -lgdi32
|
||||
a.exe
|
||||
10
v2/internal/ffenestri/windows/test/main.c
Normal file
10
v2/internal/ffenestri/windows/test/main.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
||||
21
v2/internal/ffenestri/windows/x64/LICENSE
Normal file
21
v2/internal/ffenestri/windows/x64/LICENSE
Normal file
@@ -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.
|
||||
2
v2/internal/ffenestri/windows/x64/README.md
Normal file
2
v2/internal/ffenestri/windows/x64/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
These files are from the webview_csharp project at [this commit](https://github.com/webview/webview_csharp/tree/116591c415acd1c966fa02abaed939a3bb76719c/libs)
|
||||
|
||||
Reference in New Issue
Block a user