Adds extra files for testing on Windows development enviornments.
This commit is contained in:
parent
d662faa6b7
commit
ee87a47672
34
windows/.gitignore
vendored
34
windows/.gitignore
vendored
@ -1,17 +1,17 @@
|
|||||||
flutter/ephemeral/
|
flutter/ephemeral/
|
||||||
|
|
||||||
# Visual Studio user-specific files.
|
# Visual Studio user-specific files.
|
||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
*.userosscache
|
*.userosscache
|
||||||
*.sln.docstates
|
*.sln.docstates
|
||||||
|
|
||||||
# Visual Studio build-related files.
|
# Visual Studio build-related files.
|
||||||
x64/
|
x64/
|
||||||
x86/
|
x86/
|
||||||
|
|
||||||
# Visual Studio cache files
|
# Visual Studio cache files
|
||||||
# files ending in .cache can be ignored
|
# files ending in .cache can be ignored
|
||||||
*.[Cc]ache
|
*.[Cc]ache
|
||||||
# but keep track of directories ending in .cache
|
# but keep track of directories ending in .cache
|
||||||
!*.[Cc]ache/
|
!*.[Cc]ache/
|
||||||
|
@ -1,95 +1,95 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
project(firo_runner LANGUAGES CXX)
|
project(firo_runner LANGUAGES CXX)
|
||||||
|
|
||||||
set(BINARY_NAME "firo_runner")
|
set(BINARY_NAME "firo_runner")
|
||||||
|
|
||||||
cmake_policy(SET CMP0063 NEW)
|
cmake_policy(SET CMP0063 NEW)
|
||||||
|
|
||||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
|
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
|
||||||
|
|
||||||
# Configure build options.
|
# Configure build options.
|
||||||
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||||
if(IS_MULTICONFIG)
|
if(IS_MULTICONFIG)
|
||||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
|
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
|
||||||
CACHE STRING "" FORCE)
|
CACHE STRING "" FORCE)
|
||||||
else()
|
else()
|
||||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||||
set(CMAKE_BUILD_TYPE "Debug" CACHE
|
set(CMAKE_BUILD_TYPE "Debug" CACHE
|
||||||
STRING "Flutter build mode" FORCE)
|
STRING "Flutter build mode" FORCE)
|
||||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
|
||||||
"Debug" "Profile" "Release")
|
"Debug" "Profile" "Release")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
||||||
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
|
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
|
||||||
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
|
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
|
||||||
|
|
||||||
# Use Unicode for all projects.
|
# Use Unicode for all projects.
|
||||||
add_definitions(-DUNICODE -D_UNICODE)
|
add_definitions(-DUNICODE -D_UNICODE)
|
||||||
|
|
||||||
# Compilation settings that should be applied to most targets.
|
# Compilation settings that should be applied to most targets.
|
||||||
function(APPLY_STANDARD_SETTINGS TARGET)
|
function(APPLY_STANDARD_SETTINGS TARGET)
|
||||||
target_compile_features(${TARGET} PUBLIC cxx_std_17)
|
target_compile_features(${TARGET} PUBLIC cxx_std_17)
|
||||||
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
|
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
|
||||||
target_compile_options(${TARGET} PRIVATE /EHsc)
|
target_compile_options(${TARGET} PRIVATE /EHsc)
|
||||||
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
|
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
|
||||||
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
|
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
|
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
|
||||||
|
|
||||||
# Flutter library and tool build rules.
|
# Flutter library and tool build rules.
|
||||||
add_subdirectory(${FLUTTER_MANAGED_DIR})
|
add_subdirectory(${FLUTTER_MANAGED_DIR})
|
||||||
|
|
||||||
# Application build
|
# Application build
|
||||||
add_subdirectory("runner")
|
add_subdirectory("runner")
|
||||||
|
|
||||||
# Generated plugin build rules, which manage building the plugins and adding
|
# Generated plugin build rules, which manage building the plugins and adding
|
||||||
# them to the application.
|
# them to the application.
|
||||||
include(flutter/generated_plugins.cmake)
|
include(flutter/generated_plugins.cmake)
|
||||||
|
|
||||||
|
|
||||||
# === Installation ===
|
# === Installation ===
|
||||||
# Support files are copied into place next to the executable, so that it can
|
# Support files are copied into place next to the executable, so that it can
|
||||||
# run in place. This is done instead of making a separate bundle (as on Linux)
|
# run in place. This is done instead of making a separate bundle (as on Linux)
|
||||||
# so that building and running from within Visual Studio will work.
|
# so that building and running from within Visual Studio will work.
|
||||||
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
|
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
|
||||||
# Make the "install" step default, as it's required to run.
|
# Make the "install" step default, as it's required to run.
|
||||||
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
|
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
|
||||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||||
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
|
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
|
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
|
||||||
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
|
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
|
||||||
|
|
||||||
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
||||||
COMPONENT Runtime)
|
COMPONENT Runtime)
|
||||||
|
|
||||||
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
|
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
|
||||||
COMPONENT Runtime)
|
COMPONENT Runtime)
|
||||||
|
|
||||||
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
||||||
COMPONENT Runtime)
|
COMPONENT Runtime)
|
||||||
|
|
||||||
if(PLUGIN_BUNDLED_LIBRARIES)
|
if(PLUGIN_BUNDLED_LIBRARIES)
|
||||||
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
|
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
|
||||||
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
||||||
COMPONENT Runtime)
|
COMPONENT Runtime)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Fully re-copy the assets directory on each build to avoid having stale files
|
# Fully re-copy the assets directory on each build to avoid having stale files
|
||||||
# from a previous install.
|
# from a previous install.
|
||||||
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
|
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
|
||||||
install(CODE "
|
install(CODE "
|
||||||
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
|
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
|
||||||
" COMPONENT Runtime)
|
" COMPONENT Runtime)
|
||||||
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
|
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
|
||||||
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
|
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
|
||||||
|
|
||||||
# Install the AOT library on non-Debug builds only.
|
# Install the AOT library on non-Debug builds only.
|
||||||
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
|
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
|
||||||
CONFIGURATIONS Profile;Release
|
CONFIGURATIONS Profile;Release
|
||||||
COMPONENT Runtime)
|
COMPONENT Runtime)
|
||||||
|
@ -1,103 +1,103 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
|
||||||
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
|
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
|
||||||
|
|
||||||
# Configuration provided via flutter tool.
|
# Configuration provided via flutter tool.
|
||||||
include(${EPHEMERAL_DIR}/generated_config.cmake)
|
include(${EPHEMERAL_DIR}/generated_config.cmake)
|
||||||
|
|
||||||
# TODO: Move the rest of this into files in ephemeral. See
|
# TODO: Move the rest of this into files in ephemeral. See
|
||||||
# https://github.com/flutter/flutter/issues/57146.
|
# https://github.com/flutter/flutter/issues/57146.
|
||||||
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
|
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
|
||||||
|
|
||||||
# === Flutter Library ===
|
# === Flutter Library ===
|
||||||
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
|
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
|
||||||
|
|
||||||
# Published to parent scope for install step.
|
# Published to parent scope for install step.
|
||||||
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
|
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
|
||||||
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
|
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
|
||||||
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
|
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
|
||||||
set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
|
set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
|
||||||
|
|
||||||
list(APPEND FLUTTER_LIBRARY_HEADERS
|
list(APPEND FLUTTER_LIBRARY_HEADERS
|
||||||
"flutter_export.h"
|
"flutter_export.h"
|
||||||
"flutter_windows.h"
|
"flutter_windows.h"
|
||||||
"flutter_messenger.h"
|
"flutter_messenger.h"
|
||||||
"flutter_plugin_registrar.h"
|
"flutter_plugin_registrar.h"
|
||||||
"flutter_texture_registrar.h"
|
"flutter_texture_registrar.h"
|
||||||
)
|
)
|
||||||
list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
|
list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
|
||||||
add_library(flutter INTERFACE)
|
add_library(flutter INTERFACE)
|
||||||
target_include_directories(flutter INTERFACE
|
target_include_directories(flutter INTERFACE
|
||||||
"${EPHEMERAL_DIR}"
|
"${EPHEMERAL_DIR}"
|
||||||
)
|
)
|
||||||
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
|
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
|
||||||
add_dependencies(flutter flutter_assemble)
|
add_dependencies(flutter flutter_assemble)
|
||||||
|
|
||||||
# === Wrapper ===
|
# === Wrapper ===
|
||||||
list(APPEND CPP_WRAPPER_SOURCES_CORE
|
list(APPEND CPP_WRAPPER_SOURCES_CORE
|
||||||
"core_implementations.cc"
|
"core_implementations.cc"
|
||||||
"standard_codec.cc"
|
"standard_codec.cc"
|
||||||
)
|
)
|
||||||
list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
|
list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
|
||||||
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
|
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
|
||||||
"plugin_registrar.cc"
|
"plugin_registrar.cc"
|
||||||
)
|
)
|
||||||
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
|
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
|
||||||
list(APPEND CPP_WRAPPER_SOURCES_APP
|
list(APPEND CPP_WRAPPER_SOURCES_APP
|
||||||
"flutter_engine.cc"
|
"flutter_engine.cc"
|
||||||
"flutter_view_controller.cc"
|
"flutter_view_controller.cc"
|
||||||
)
|
)
|
||||||
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
|
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
|
||||||
|
|
||||||
# Wrapper sources needed for a plugin.
|
# Wrapper sources needed for a plugin.
|
||||||
add_library(flutter_wrapper_plugin STATIC
|
add_library(flutter_wrapper_plugin STATIC
|
||||||
${CPP_WRAPPER_SOURCES_CORE}
|
${CPP_WRAPPER_SOURCES_CORE}
|
||||||
${CPP_WRAPPER_SOURCES_PLUGIN}
|
${CPP_WRAPPER_SOURCES_PLUGIN}
|
||||||
)
|
)
|
||||||
apply_standard_settings(flutter_wrapper_plugin)
|
apply_standard_settings(flutter_wrapper_plugin)
|
||||||
set_target_properties(flutter_wrapper_plugin PROPERTIES
|
set_target_properties(flutter_wrapper_plugin PROPERTIES
|
||||||
POSITION_INDEPENDENT_CODE ON)
|
POSITION_INDEPENDENT_CODE ON)
|
||||||
set_target_properties(flutter_wrapper_plugin PROPERTIES
|
set_target_properties(flutter_wrapper_plugin PROPERTIES
|
||||||
CXX_VISIBILITY_PRESET hidden)
|
CXX_VISIBILITY_PRESET hidden)
|
||||||
target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
|
target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
|
||||||
target_include_directories(flutter_wrapper_plugin PUBLIC
|
target_include_directories(flutter_wrapper_plugin PUBLIC
|
||||||
"${WRAPPER_ROOT}/include"
|
"${WRAPPER_ROOT}/include"
|
||||||
)
|
)
|
||||||
add_dependencies(flutter_wrapper_plugin flutter_assemble)
|
add_dependencies(flutter_wrapper_plugin flutter_assemble)
|
||||||
|
|
||||||
# Wrapper sources needed for the runner.
|
# Wrapper sources needed for the runner.
|
||||||
add_library(flutter_wrapper_app STATIC
|
add_library(flutter_wrapper_app STATIC
|
||||||
${CPP_WRAPPER_SOURCES_CORE}
|
${CPP_WRAPPER_SOURCES_CORE}
|
||||||
${CPP_WRAPPER_SOURCES_APP}
|
${CPP_WRAPPER_SOURCES_APP}
|
||||||
)
|
)
|
||||||
apply_standard_settings(flutter_wrapper_app)
|
apply_standard_settings(flutter_wrapper_app)
|
||||||
target_link_libraries(flutter_wrapper_app PUBLIC flutter)
|
target_link_libraries(flutter_wrapper_app PUBLIC flutter)
|
||||||
target_include_directories(flutter_wrapper_app PUBLIC
|
target_include_directories(flutter_wrapper_app PUBLIC
|
||||||
"${WRAPPER_ROOT}/include"
|
"${WRAPPER_ROOT}/include"
|
||||||
)
|
)
|
||||||
add_dependencies(flutter_wrapper_app flutter_assemble)
|
add_dependencies(flutter_wrapper_app flutter_assemble)
|
||||||
|
|
||||||
# === Flutter tool backend ===
|
# === Flutter tool backend ===
|
||||||
# _phony_ is a non-existent file to force this command to run every time,
|
# _phony_ is a non-existent file to force this command to run every time,
|
||||||
# since currently there's no way to get a full input/output list from the
|
# since currently there's no way to get a full input/output list from the
|
||||||
# flutter tool.
|
# flutter tool.
|
||||||
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
|
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
|
||||||
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
|
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
|
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
|
||||||
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
|
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
|
||||||
${CPP_WRAPPER_SOURCES_APP}
|
${CPP_WRAPPER_SOURCES_APP}
|
||||||
${PHONY_OUTPUT}
|
${PHONY_OUTPUT}
|
||||||
COMMAND ${CMAKE_COMMAND} -E env
|
COMMAND ${CMAKE_COMMAND} -E env
|
||||||
${FLUTTER_TOOL_ENVIRONMENT}
|
${FLUTTER_TOOL_ENVIRONMENT}
|
||||||
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
|
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
|
||||||
windows-x64 $<CONFIG>
|
windows-x64 $<CONFIG>
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
add_custom_target(flutter_assemble DEPENDS
|
add_custom_target(flutter_assemble DEPENDS
|
||||||
"${FLUTTER_LIBRARY}"
|
"${FLUTTER_LIBRARY}"
|
||||||
${FLUTTER_LIBRARY_HEADERS}
|
${FLUTTER_LIBRARY_HEADERS}
|
||||||
${CPP_WRAPPER_SOURCES_CORE}
|
${CPP_WRAPPER_SOURCES_CORE}
|
||||||
${CPP_WRAPPER_SOURCES_PLUGIN}
|
${CPP_WRAPPER_SOURCES_PLUGIN}
|
||||||
${CPP_WRAPPER_SOURCES_APP}
|
${CPP_WRAPPER_SOURCES_APP}
|
||||||
)
|
)
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
project(runner LANGUAGES CXX)
|
project(runner LANGUAGES CXX)
|
||||||
|
|
||||||
add_executable(${BINARY_NAME} WIN32
|
add_executable(${BINARY_NAME} WIN32
|
||||||
"flutter_window.cpp"
|
"flutter_window.cpp"
|
||||||
"main.cpp"
|
"main.cpp"
|
||||||
"utils.cpp"
|
"utils.cpp"
|
||||||
"win32_window.cpp"
|
"win32_window.cpp"
|
||||||
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
|
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
|
||||||
"Runner.rc"
|
"Runner.rc"
|
||||||
"runner.exe.manifest"
|
"runner.exe.manifest"
|
||||||
)
|
)
|
||||||
apply_standard_settings(${BINARY_NAME})
|
apply_standard_settings(${BINARY_NAME})
|
||||||
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
|
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
|
||||||
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
|
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
|
||||||
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
|
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
|
||||||
add_dependencies(${BINARY_NAME} flutter_assemble)
|
add_dependencies(${BINARY_NAME} flutter_assemble)
|
||||||
|
@ -1,121 +1,121 @@
|
|||||||
// Microsoft Visual C++ generated resource script.
|
// Microsoft Visual C++ generated resource script.
|
||||||
//
|
//
|
||||||
#pragma code_page(65001)
|
#pragma code_page(65001)
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
#define APSTUDIO_READONLY_SYMBOLS
|
#define APSTUDIO_READONLY_SYMBOLS
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Generated from the TEXTINCLUDE 2 resource.
|
// Generated from the TEXTINCLUDE 2 resource.
|
||||||
//
|
//
|
||||||
#include "winres.h"
|
#include "winres.h"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
#undef APSTUDIO_READONLY_SYMBOLS
|
#undef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// English (United States) resources
|
// English (United States) resources
|
||||||
|
|
||||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||||
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// TEXTINCLUDE
|
// TEXTINCLUDE
|
||||||
//
|
//
|
||||||
|
|
||||||
1 TEXTINCLUDE
|
1 TEXTINCLUDE
|
||||||
BEGIN
|
BEGIN
|
||||||
"resource.h\0"
|
"resource.h\0"
|
||||||
END
|
END
|
||||||
|
|
||||||
2 TEXTINCLUDE
|
2 TEXTINCLUDE
|
||||||
BEGIN
|
BEGIN
|
||||||
"#include ""winres.h""\r\n"
|
"#include ""winres.h""\r\n"
|
||||||
"\0"
|
"\0"
|
||||||
END
|
END
|
||||||
|
|
||||||
3 TEXTINCLUDE
|
3 TEXTINCLUDE
|
||||||
BEGIN
|
BEGIN
|
||||||
"\r\n"
|
"\r\n"
|
||||||
"\0"
|
"\0"
|
||||||
END
|
END
|
||||||
|
|
||||||
#endif // APSTUDIO_INVOKED
|
#endif // APSTUDIO_INVOKED
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Icon
|
// Icon
|
||||||
//
|
//
|
||||||
|
|
||||||
// Icon with lowest ID value placed first to ensure application icon
|
// Icon with lowest ID value placed first to ensure application icon
|
||||||
// remains consistent on all systems.
|
// remains consistent on all systems.
|
||||||
IDI_APP_ICON ICON "resources\\app_icon.ico"
|
IDI_APP_ICON ICON "resources\\app_icon.ico"
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Version
|
// Version
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifdef FLUTTER_BUILD_NUMBER
|
#ifdef FLUTTER_BUILD_NUMBER
|
||||||
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
|
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
|
||||||
#else
|
#else
|
||||||
#define VERSION_AS_NUMBER 1,0,0
|
#define VERSION_AS_NUMBER 1,0,0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FLUTTER_BUILD_NAME
|
#ifdef FLUTTER_BUILD_NAME
|
||||||
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
|
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
|
||||||
#else
|
#else
|
||||||
#define VERSION_AS_STRING "1.0.0"
|
#define VERSION_AS_STRING "1.0.0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION VERSION_AS_NUMBER
|
FILEVERSION VERSION_AS_NUMBER
|
||||||
PRODUCTVERSION VERSION_AS_NUMBER
|
PRODUCTVERSION VERSION_AS_NUMBER
|
||||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS VS_FF_DEBUG
|
FILEFLAGS VS_FF_DEBUG
|
||||||
#else
|
#else
|
||||||
FILEFLAGS 0x0L
|
FILEFLAGS 0x0L
|
||||||
#endif
|
#endif
|
||||||
FILEOS VOS__WINDOWS32
|
FILEOS VOS__WINDOWS32
|
||||||
FILETYPE VFT_APP
|
FILETYPE VFT_APP
|
||||||
FILESUBTYPE 0x0L
|
FILESUBTYPE 0x0L
|
||||||
BEGIN
|
BEGIN
|
||||||
BLOCK "StringFileInfo"
|
BLOCK "StringFileInfo"
|
||||||
BEGIN
|
BEGIN
|
||||||
BLOCK "040904e4"
|
BLOCK "040904e4"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "com.firogames" "\0"
|
VALUE "CompanyName", "com.firogames" "\0"
|
||||||
VALUE "FileDescription", "A new Flutter project." "\0"
|
VALUE "FileDescription", "A new Flutter project." "\0"
|
||||||
VALUE "FileVersion", VERSION_AS_STRING "\0"
|
VALUE "FileVersion", VERSION_AS_STRING "\0"
|
||||||
VALUE "InternalName", "firo_runner" "\0"
|
VALUE "InternalName", "firo_runner" "\0"
|
||||||
VALUE "LegalCopyright", "Copyright (C) 2021 com.firogames. All rights reserved." "\0"
|
VALUE "LegalCopyright", "Copyright (C) 2021 com.firogames. All rights reserved." "\0"
|
||||||
VALUE "OriginalFilename", "firo_runner.exe" "\0"
|
VALUE "OriginalFilename", "firo_runner.exe" "\0"
|
||||||
VALUE "ProductName", "firo_runner" "\0"
|
VALUE "ProductName", "firo_runner" "\0"
|
||||||
VALUE "ProductVersion", VERSION_AS_STRING "\0"
|
VALUE "ProductVersion", VERSION_AS_STRING "\0"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "Translation", 0x409, 1252
|
VALUE "Translation", 0x409, 1252
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
|
|
||||||
#endif // English (United States) resources
|
#endif // English (United States) resources
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef APSTUDIO_INVOKED
|
#ifndef APSTUDIO_INVOKED
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Generated from the TEXTINCLUDE 3 resource.
|
// Generated from the TEXTINCLUDE 3 resource.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
#endif // not APSTUDIO_INVOKED
|
#endif // not APSTUDIO_INVOKED
|
||||||
|
@ -1,61 +1,61 @@
|
|||||||
#include "flutter_window.h"
|
#include "flutter_window.h"
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "flutter/generated_plugin_registrant.h"
|
#include "flutter/generated_plugin_registrant.h"
|
||||||
|
|
||||||
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
|
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
|
||||||
: project_(project) {}
|
: project_(project) {}
|
||||||
|
|
||||||
FlutterWindow::~FlutterWindow() {}
|
FlutterWindow::~FlutterWindow() {}
|
||||||
|
|
||||||
bool FlutterWindow::OnCreate() {
|
bool FlutterWindow::OnCreate() {
|
||||||
if (!Win32Window::OnCreate()) {
|
if (!Win32Window::OnCreate()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT frame = GetClientArea();
|
RECT frame = GetClientArea();
|
||||||
|
|
||||||
// The size here must match the window dimensions to avoid unnecessary surface
|
// The size here must match the window dimensions to avoid unnecessary surface
|
||||||
// creation / destruction in the startup path.
|
// creation / destruction in the startup path.
|
||||||
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
|
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
|
||||||
frame.right - frame.left, frame.bottom - frame.top, project_);
|
frame.right - frame.left, frame.bottom - frame.top, project_);
|
||||||
// Ensure that basic setup of the controller was successful.
|
// Ensure that basic setup of the controller was successful.
|
||||||
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
|
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
RegisterPlugins(flutter_controller_->engine());
|
RegisterPlugins(flutter_controller_->engine());
|
||||||
SetChildContent(flutter_controller_->view()->GetNativeWindow());
|
SetChildContent(flutter_controller_->view()->GetNativeWindow());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlutterWindow::OnDestroy() {
|
void FlutterWindow::OnDestroy() {
|
||||||
if (flutter_controller_) {
|
if (flutter_controller_) {
|
||||||
flutter_controller_ = nullptr;
|
flutter_controller_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Window::OnDestroy();
|
Win32Window::OnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT
|
LRESULT
|
||||||
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
|
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
|
||||||
WPARAM const wparam,
|
WPARAM const wparam,
|
||||||
LPARAM const lparam) noexcept {
|
LPARAM const lparam) noexcept {
|
||||||
// Give Flutter, including plugins, an opportunity to handle window messages.
|
// Give Flutter, including plugins, an opportunity to handle window messages.
|
||||||
if (flutter_controller_) {
|
if (flutter_controller_) {
|
||||||
std::optional<LRESULT> result =
|
std::optional<LRESULT> result =
|
||||||
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
|
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
|
||||||
lparam);
|
lparam);
|
||||||
if (result) {
|
if (result) {
|
||||||
return *result;
|
return *result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_FONTCHANGE:
|
case WM_FONTCHANGE:
|
||||||
flutter_controller_->engine()->ReloadSystemFonts();
|
flutter_controller_->engine()->ReloadSystemFonts();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
|
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,33 @@
|
|||||||
#ifndef RUNNER_FLUTTER_WINDOW_H_
|
#ifndef RUNNER_FLUTTER_WINDOW_H_
|
||||||
#define RUNNER_FLUTTER_WINDOW_H_
|
#define RUNNER_FLUTTER_WINDOW_H_
|
||||||
|
|
||||||
#include <flutter/dart_project.h>
|
#include <flutter/dart_project.h>
|
||||||
#include <flutter/flutter_view_controller.h>
|
#include <flutter/flutter_view_controller.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "win32_window.h"
|
#include "win32_window.h"
|
||||||
|
|
||||||
// A window that does nothing but host a Flutter view.
|
// A window that does nothing but host a Flutter view.
|
||||||
class FlutterWindow : public Win32Window {
|
class FlutterWindow : public Win32Window {
|
||||||
public:
|
public:
|
||||||
// Creates a new FlutterWindow hosting a Flutter view running |project|.
|
// Creates a new FlutterWindow hosting a Flutter view running |project|.
|
||||||
explicit FlutterWindow(const flutter::DartProject& project);
|
explicit FlutterWindow(const flutter::DartProject& project);
|
||||||
virtual ~FlutterWindow();
|
virtual ~FlutterWindow();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Win32Window:
|
// Win32Window:
|
||||||
bool OnCreate() override;
|
bool OnCreate() override;
|
||||||
void OnDestroy() override;
|
void OnDestroy() override;
|
||||||
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
|
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
|
||||||
LPARAM const lparam) noexcept override;
|
LPARAM const lparam) noexcept override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The project to run.
|
// The project to run.
|
||||||
flutter::DartProject project_;
|
flutter::DartProject project_;
|
||||||
|
|
||||||
// The Flutter instance hosted by this window.
|
// The Flutter instance hosted by this window.
|
||||||
std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
|
std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RUNNER_FLUTTER_WINDOW_H_
|
#endif // RUNNER_FLUTTER_WINDOW_H_
|
||||||
|
@ -1,43 +1,43 @@
|
|||||||
#include <flutter/dart_project.h>
|
#include <flutter/dart_project.h>
|
||||||
#include <flutter/flutter_view_controller.h>
|
#include <flutter/flutter_view_controller.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include "flutter_window.h"
|
#include "flutter_window.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
||||||
_In_ wchar_t *command_line, _In_ int show_command) {
|
_In_ wchar_t *command_line, _In_ int show_command) {
|
||||||
// Attach to console when present (e.g., 'flutter run') or create a
|
// Attach to console when present (e.g., 'flutter run') or create a
|
||||||
// new console when running with a debugger.
|
// new console when running with a debugger.
|
||||||
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
|
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
|
||||||
CreateAndAttachConsole();
|
CreateAndAttachConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize COM, so that it is available for use in the library and/or
|
// Initialize COM, so that it is available for use in the library and/or
|
||||||
// plugins.
|
// plugins.
|
||||||
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||||
|
|
||||||
flutter::DartProject project(L"data");
|
flutter::DartProject project(L"data");
|
||||||
|
|
||||||
std::vector<std::string> command_line_arguments =
|
std::vector<std::string> command_line_arguments =
|
||||||
GetCommandLineArguments();
|
GetCommandLineArguments();
|
||||||
|
|
||||||
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
|
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
|
||||||
|
|
||||||
FlutterWindow window(project);
|
FlutterWindow window(project);
|
||||||
Win32Window::Point origin(10, 10);
|
Win32Window::Point origin(10, 10);
|
||||||
Win32Window::Size size(1280, 720);
|
Win32Window::Size size(1280, 720);
|
||||||
if (!window.CreateAndShow(L"firo_runner", origin, size)) {
|
if (!window.CreateAndShow(L"firo_runner", origin, size)) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
window.SetQuitOnClose(true);
|
window.SetQuitOnClose(true);
|
||||||
|
|
||||||
::MSG msg;
|
::MSG msg;
|
||||||
while (::GetMessage(&msg, nullptr, 0, 0)) {
|
while (::GetMessage(&msg, nullptr, 0, 0)) {
|
||||||
::TranslateMessage(&msg);
|
::TranslateMessage(&msg);
|
||||||
::DispatchMessage(&msg);
|
::DispatchMessage(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
::CoUninitialize();
|
::CoUninitialize();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
//{{NO_DEPENDENCIES}}
|
//{{NO_DEPENDENCIES}}
|
||||||
// Microsoft Visual C++ generated include file.
|
// Microsoft Visual C++ generated include file.
|
||||||
// Used by Runner.rc
|
// Used by Runner.rc
|
||||||
//
|
//
|
||||||
#define IDI_APP_ICON 101
|
#define IDI_APP_ICON 101
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
//
|
//
|
||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
<windowsSettings>
|
<windowsSettings>
|
||||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||||
</windowsSettings>
|
</windowsSettings>
|
||||||
</application>
|
</application>
|
||||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
<application>
|
<application>
|
||||||
<!-- Windows 10 -->
|
<!-- Windows 10 -->
|
||||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||||
<!-- Windows 8.1 -->
|
<!-- Windows 8.1 -->
|
||||||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
||||||
<!-- Windows 8 -->
|
<!-- Windows 8 -->
|
||||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
||||||
<!-- Windows 7 -->
|
<!-- Windows 7 -->
|
||||||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
|
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
|
||||||
</application>
|
</application>
|
||||||
</compatibility>
|
</compatibility>
|
||||||
</assembly>
|
</assembly>
|
||||||
|
@ -1,64 +1,64 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <flutter_windows.h>
|
#include <flutter_windows.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void CreateAndAttachConsole() {
|
void CreateAndAttachConsole() {
|
||||||
if (::AllocConsole()) {
|
if (::AllocConsole()) {
|
||||||
FILE *unused;
|
FILE *unused;
|
||||||
if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
|
if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
|
||||||
_dup2(_fileno(stdout), 1);
|
_dup2(_fileno(stdout), 1);
|
||||||
}
|
}
|
||||||
if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
|
if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
|
||||||
_dup2(_fileno(stdout), 2);
|
_dup2(_fileno(stdout), 2);
|
||||||
}
|
}
|
||||||
std::ios::sync_with_stdio();
|
std::ios::sync_with_stdio();
|
||||||
FlutterDesktopResyncOutputStreams();
|
FlutterDesktopResyncOutputStreams();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> GetCommandLineArguments() {
|
std::vector<std::string> GetCommandLineArguments() {
|
||||||
// Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
|
// Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
|
||||||
int argc;
|
int argc;
|
||||||
wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
||||||
if (argv == nullptr) {
|
if (argv == nullptr) {
|
||||||
return std::vector<std::string>();
|
return std::vector<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> command_line_arguments;
|
std::vector<std::string> command_line_arguments;
|
||||||
|
|
||||||
// Skip the first argument as it's the binary name.
|
// Skip the first argument as it's the binary name.
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
|
command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
::LocalFree(argv);
|
::LocalFree(argv);
|
||||||
|
|
||||||
return command_line_arguments;
|
return command_line_arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Utf8FromUtf16(const wchar_t* utf16_string) {
|
std::string Utf8FromUtf16(const wchar_t* utf16_string) {
|
||||||
if (utf16_string == nullptr) {
|
if (utf16_string == nullptr) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
int target_length = ::WideCharToMultiByte(
|
int target_length = ::WideCharToMultiByte(
|
||||||
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
|
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
|
||||||
-1, nullptr, 0, nullptr, nullptr);
|
-1, nullptr, 0, nullptr, nullptr);
|
||||||
if (target_length == 0) {
|
if (target_length == 0) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
std::string utf8_string;
|
std::string utf8_string;
|
||||||
utf8_string.resize(target_length);
|
utf8_string.resize(target_length);
|
||||||
int converted_length = ::WideCharToMultiByte(
|
int converted_length = ::WideCharToMultiByte(
|
||||||
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
|
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
|
||||||
-1, utf8_string.data(),
|
-1, utf8_string.data(),
|
||||||
target_length, nullptr, nullptr);
|
target_length, nullptr, nullptr);
|
||||||
if (converted_length == 0) {
|
if (converted_length == 0) {
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
return utf8_string;
|
return utf8_string;
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
#ifndef RUNNER_UTILS_H_
|
#ifndef RUNNER_UTILS_H_
|
||||||
#define RUNNER_UTILS_H_
|
#define RUNNER_UTILS_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Creates a console for the process, and redirects stdout and stderr to
|
// Creates a console for the process, and redirects stdout and stderr to
|
||||||
// it for both the runner and the Flutter library.
|
// it for both the runner and the Flutter library.
|
||||||
void CreateAndAttachConsole();
|
void CreateAndAttachConsole();
|
||||||
|
|
||||||
// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
|
// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
|
||||||
// encoded in UTF-8. Returns an empty std::string on failure.
|
// encoded in UTF-8. Returns an empty std::string on failure.
|
||||||
std::string Utf8FromUtf16(const wchar_t* utf16_string);
|
std::string Utf8FromUtf16(const wchar_t* utf16_string);
|
||||||
|
|
||||||
// Gets the command line arguments passed in as a std::vector<std::string>,
|
// Gets the command line arguments passed in as a std::vector<std::string>,
|
||||||
// encoded in UTF-8. Returns an empty std::vector<std::string> on failure.
|
// encoded in UTF-8. Returns an empty std::vector<std::string> on failure.
|
||||||
std::vector<std::string> GetCommandLineArguments();
|
std::vector<std::string> GetCommandLineArguments();
|
||||||
|
|
||||||
#endif // RUNNER_UTILS_H_
|
#endif // RUNNER_UTILS_H_
|
||||||
|
@ -1,245 +1,245 @@
|
|||||||
#include "win32_window.h"
|
#include "win32_window.h"
|
||||||
|
|
||||||
#include <flutter_windows.h>
|
#include <flutter_windows.h>
|
||||||
|
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
|
constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
|
||||||
|
|
||||||
// The number of Win32Window objects that currently exist.
|
// The number of Win32Window objects that currently exist.
|
||||||
static int g_active_window_count = 0;
|
static int g_active_window_count = 0;
|
||||||
|
|
||||||
using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
|
using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
|
||||||
|
|
||||||
// Scale helper to convert logical scaler values to physical using passed in
|
// Scale helper to convert logical scaler values to physical using passed in
|
||||||
// scale factor
|
// scale factor
|
||||||
int Scale(int source, double scale_factor) {
|
int Scale(int source, double scale_factor) {
|
||||||
return static_cast<int>(source * scale_factor);
|
return static_cast<int>(source * scale_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
|
// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
|
||||||
// This API is only needed for PerMonitor V1 awareness mode.
|
// This API is only needed for PerMonitor V1 awareness mode.
|
||||||
void EnableFullDpiSupportIfAvailable(HWND hwnd) {
|
void EnableFullDpiSupportIfAvailable(HWND hwnd) {
|
||||||
HMODULE user32_module = LoadLibraryA("User32.dll");
|
HMODULE user32_module = LoadLibraryA("User32.dll");
|
||||||
if (!user32_module) {
|
if (!user32_module) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto enable_non_client_dpi_scaling =
|
auto enable_non_client_dpi_scaling =
|
||||||
reinterpret_cast<EnableNonClientDpiScaling*>(
|
reinterpret_cast<EnableNonClientDpiScaling*>(
|
||||||
GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
|
GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
|
||||||
if (enable_non_client_dpi_scaling != nullptr) {
|
if (enable_non_client_dpi_scaling != nullptr) {
|
||||||
enable_non_client_dpi_scaling(hwnd);
|
enable_non_client_dpi_scaling(hwnd);
|
||||||
FreeLibrary(user32_module);
|
FreeLibrary(user32_module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// Manages the Win32Window's window class registration.
|
// Manages the Win32Window's window class registration.
|
||||||
class WindowClassRegistrar {
|
class WindowClassRegistrar {
|
||||||
public:
|
public:
|
||||||
~WindowClassRegistrar() = default;
|
~WindowClassRegistrar() = default;
|
||||||
|
|
||||||
// Returns the singleton registar instance.
|
// Returns the singleton registar instance.
|
||||||
static WindowClassRegistrar* GetInstance() {
|
static WindowClassRegistrar* GetInstance() {
|
||||||
if (!instance_) {
|
if (!instance_) {
|
||||||
instance_ = new WindowClassRegistrar();
|
instance_ = new WindowClassRegistrar();
|
||||||
}
|
}
|
||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the name of the window class, registering the class if it hasn't
|
// Returns the name of the window class, registering the class if it hasn't
|
||||||
// previously been registered.
|
// previously been registered.
|
||||||
const wchar_t* GetWindowClass();
|
const wchar_t* GetWindowClass();
|
||||||
|
|
||||||
// Unregisters the window class. Should only be called if there are no
|
// Unregisters the window class. Should only be called if there are no
|
||||||
// instances of the window.
|
// instances of the window.
|
||||||
void UnregisterWindowClass();
|
void UnregisterWindowClass();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WindowClassRegistrar() = default;
|
WindowClassRegistrar() = default;
|
||||||
|
|
||||||
static WindowClassRegistrar* instance_;
|
static WindowClassRegistrar* instance_;
|
||||||
|
|
||||||
bool class_registered_ = false;
|
bool class_registered_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
|
WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
|
||||||
|
|
||||||
const wchar_t* WindowClassRegistrar::GetWindowClass() {
|
const wchar_t* WindowClassRegistrar::GetWindowClass() {
|
||||||
if (!class_registered_) {
|
if (!class_registered_) {
|
||||||
WNDCLASS window_class{};
|
WNDCLASS window_class{};
|
||||||
window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||||
window_class.lpszClassName = kWindowClassName;
|
window_class.lpszClassName = kWindowClassName;
|
||||||
window_class.style = CS_HREDRAW | CS_VREDRAW;
|
window_class.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
window_class.cbClsExtra = 0;
|
window_class.cbClsExtra = 0;
|
||||||
window_class.cbWndExtra = 0;
|
window_class.cbWndExtra = 0;
|
||||||
window_class.hInstance = GetModuleHandle(nullptr);
|
window_class.hInstance = GetModuleHandle(nullptr);
|
||||||
window_class.hIcon =
|
window_class.hIcon =
|
||||||
LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
|
LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
|
||||||
window_class.hbrBackground = 0;
|
window_class.hbrBackground = 0;
|
||||||
window_class.lpszMenuName = nullptr;
|
window_class.lpszMenuName = nullptr;
|
||||||
window_class.lpfnWndProc = Win32Window::WndProc;
|
window_class.lpfnWndProc = Win32Window::WndProc;
|
||||||
RegisterClass(&window_class);
|
RegisterClass(&window_class);
|
||||||
class_registered_ = true;
|
class_registered_ = true;
|
||||||
}
|
}
|
||||||
return kWindowClassName;
|
return kWindowClassName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowClassRegistrar::UnregisterWindowClass() {
|
void WindowClassRegistrar::UnregisterWindowClass() {
|
||||||
UnregisterClass(kWindowClassName, nullptr);
|
UnregisterClass(kWindowClassName, nullptr);
|
||||||
class_registered_ = false;
|
class_registered_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Window::Win32Window() {
|
Win32Window::Win32Window() {
|
||||||
++g_active_window_count;
|
++g_active_window_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Window::~Win32Window() {
|
Win32Window::~Win32Window() {
|
||||||
--g_active_window_count;
|
--g_active_window_count;
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Window::CreateAndShow(const std::wstring& title,
|
bool Win32Window::CreateAndShow(const std::wstring& title,
|
||||||
const Point& origin,
|
const Point& origin,
|
||||||
const Size& size) {
|
const Size& size) {
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
const wchar_t* window_class =
|
const wchar_t* window_class =
|
||||||
WindowClassRegistrar::GetInstance()->GetWindowClass();
|
WindowClassRegistrar::GetInstance()->GetWindowClass();
|
||||||
|
|
||||||
const POINT target_point = {static_cast<LONG>(origin.x),
|
const POINT target_point = {static_cast<LONG>(origin.x),
|
||||||
static_cast<LONG>(origin.y)};
|
static_cast<LONG>(origin.y)};
|
||||||
HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
|
HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
|
||||||
UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
|
UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
|
||||||
double scale_factor = dpi / 96.0;
|
double scale_factor = dpi / 96.0;
|
||||||
|
|
||||||
HWND window = CreateWindow(
|
HWND window = CreateWindow(
|
||||||
window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||||
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
|
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
|
||||||
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
|
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
|
||||||
nullptr, nullptr, GetModuleHandle(nullptr), this);
|
nullptr, nullptr, GetModuleHandle(nullptr), this);
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OnCreate();
|
return OnCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
LRESULT CALLBACK Win32Window::WndProc(HWND const window,
|
LRESULT CALLBACK Win32Window::WndProc(HWND const window,
|
||||||
UINT const message,
|
UINT const message,
|
||||||
WPARAM const wparam,
|
WPARAM const wparam,
|
||||||
LPARAM const lparam) noexcept {
|
LPARAM const lparam) noexcept {
|
||||||
if (message == WM_NCCREATE) {
|
if (message == WM_NCCREATE) {
|
||||||
auto window_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
|
auto window_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
|
||||||
SetWindowLongPtr(window, GWLP_USERDATA,
|
SetWindowLongPtr(window, GWLP_USERDATA,
|
||||||
reinterpret_cast<LONG_PTR>(window_struct->lpCreateParams));
|
reinterpret_cast<LONG_PTR>(window_struct->lpCreateParams));
|
||||||
|
|
||||||
auto that = static_cast<Win32Window*>(window_struct->lpCreateParams);
|
auto that = static_cast<Win32Window*>(window_struct->lpCreateParams);
|
||||||
EnableFullDpiSupportIfAvailable(window);
|
EnableFullDpiSupportIfAvailable(window);
|
||||||
that->window_handle_ = window;
|
that->window_handle_ = window;
|
||||||
} else if (Win32Window* that = GetThisFromHandle(window)) {
|
} else if (Win32Window* that = GetThisFromHandle(window)) {
|
||||||
return that->MessageHandler(window, message, wparam, lparam);
|
return that->MessageHandler(window, message, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefWindowProc(window, message, wparam, lparam);
|
return DefWindowProc(window, message, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT
|
LRESULT
|
||||||
Win32Window::MessageHandler(HWND hwnd,
|
Win32Window::MessageHandler(HWND hwnd,
|
||||||
UINT const message,
|
UINT const message,
|
||||||
WPARAM const wparam,
|
WPARAM const wparam,
|
||||||
LPARAM const lparam) noexcept {
|
LPARAM const lparam) noexcept {
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
window_handle_ = nullptr;
|
window_handle_ = nullptr;
|
||||||
Destroy();
|
Destroy();
|
||||||
if (quit_on_close_) {
|
if (quit_on_close_) {
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WM_DPICHANGED: {
|
case WM_DPICHANGED: {
|
||||||
auto newRectSize = reinterpret_cast<RECT*>(lparam);
|
auto newRectSize = reinterpret_cast<RECT*>(lparam);
|
||||||
LONG newWidth = newRectSize->right - newRectSize->left;
|
LONG newWidth = newRectSize->right - newRectSize->left;
|
||||||
LONG newHeight = newRectSize->bottom - newRectSize->top;
|
LONG newHeight = newRectSize->bottom - newRectSize->top;
|
||||||
|
|
||||||
SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
|
SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
|
||||||
newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
|
newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case WM_SIZE: {
|
case WM_SIZE: {
|
||||||
RECT rect = GetClientArea();
|
RECT rect = GetClientArea();
|
||||||
if (child_content_ != nullptr) {
|
if (child_content_ != nullptr) {
|
||||||
// Size and position the child window.
|
// Size and position the child window.
|
||||||
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
|
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
|
||||||
rect.bottom - rect.top, TRUE);
|
rect.bottom - rect.top, TRUE);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_ACTIVATE:
|
case WM_ACTIVATE:
|
||||||
if (child_content_ != nullptr) {
|
if (child_content_ != nullptr) {
|
||||||
SetFocus(child_content_);
|
SetFocus(child_content_);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefWindowProc(window_handle_, message, wparam, lparam);
|
return DefWindowProc(window_handle_, message, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Window::Destroy() {
|
void Win32Window::Destroy() {
|
||||||
OnDestroy();
|
OnDestroy();
|
||||||
|
|
||||||
if (window_handle_) {
|
if (window_handle_) {
|
||||||
DestroyWindow(window_handle_);
|
DestroyWindow(window_handle_);
|
||||||
window_handle_ = nullptr;
|
window_handle_ = nullptr;
|
||||||
}
|
}
|
||||||
if (g_active_window_count == 0) {
|
if (g_active_window_count == 0) {
|
||||||
WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
|
WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
|
Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
|
||||||
return reinterpret_cast<Win32Window*>(
|
return reinterpret_cast<Win32Window*>(
|
||||||
GetWindowLongPtr(window, GWLP_USERDATA));
|
GetWindowLongPtr(window, GWLP_USERDATA));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Window::SetChildContent(HWND content) {
|
void Win32Window::SetChildContent(HWND content) {
|
||||||
child_content_ = content;
|
child_content_ = content;
|
||||||
SetParent(content, window_handle_);
|
SetParent(content, window_handle_);
|
||||||
RECT frame = GetClientArea();
|
RECT frame = GetClientArea();
|
||||||
|
|
||||||
MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
|
MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
|
||||||
frame.bottom - frame.top, true);
|
frame.bottom - frame.top, true);
|
||||||
|
|
||||||
SetFocus(child_content_);
|
SetFocus(child_content_);
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT Win32Window::GetClientArea() {
|
RECT Win32Window::GetClientArea() {
|
||||||
RECT frame;
|
RECT frame;
|
||||||
GetClientRect(window_handle_, &frame);
|
GetClientRect(window_handle_, &frame);
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
HWND Win32Window::GetHandle() {
|
HWND Win32Window::GetHandle() {
|
||||||
return window_handle_;
|
return window_handle_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Window::SetQuitOnClose(bool quit_on_close) {
|
void Win32Window::SetQuitOnClose(bool quit_on_close) {
|
||||||
quit_on_close_ = quit_on_close;
|
quit_on_close_ = quit_on_close;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Window::OnCreate() {
|
bool Win32Window::OnCreate() {
|
||||||
// No-op; provided for subclasses.
|
// No-op; provided for subclasses.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Window::OnDestroy() {
|
void Win32Window::OnDestroy() {
|
||||||
// No-op; provided for subclasses.
|
// No-op; provided for subclasses.
|
||||||
}
|
}
|
||||||
|
@ -1,98 +1,98 @@
|
|||||||
#ifndef RUNNER_WIN32_WINDOW_H_
|
#ifndef RUNNER_WIN32_WINDOW_H_
|
||||||
#define RUNNER_WIN32_WINDOW_H_
|
#define RUNNER_WIN32_WINDOW_H_
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// A class abstraction for a high DPI-aware Win32 Window. Intended to be
|
// A class abstraction for a high DPI-aware Win32 Window. Intended to be
|
||||||
// inherited from by classes that wish to specialize with custom
|
// inherited from by classes that wish to specialize with custom
|
||||||
// rendering and input handling
|
// rendering and input handling
|
||||||
class Win32Window {
|
class Win32Window {
|
||||||
public:
|
public:
|
||||||
struct Point {
|
struct Point {
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
unsigned int y;
|
unsigned int y;
|
||||||
Point(unsigned int x, unsigned int y) : x(x), y(y) {}
|
Point(unsigned int x, unsigned int y) : x(x), y(y) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Size {
|
struct Size {
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
Size(unsigned int width, unsigned int height)
|
Size(unsigned int width, unsigned int height)
|
||||||
: width(width), height(height) {}
|
: width(width), height(height) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Win32Window();
|
Win32Window();
|
||||||
virtual ~Win32Window();
|
virtual ~Win32Window();
|
||||||
|
|
||||||
// Creates and shows a win32 window with |title| and position and size using
|
// Creates and shows a win32 window with |title| and position and size using
|
||||||
// |origin| and |size|. New windows are created on the default monitor. Window
|
// |origin| and |size|. New windows are created on the default monitor. Window
|
||||||
// sizes are specified to the OS in physical pixels, hence to ensure a
|
// sizes are specified to the OS in physical pixels, hence to ensure a
|
||||||
// consistent size to will treat the width height passed in to this function
|
// consistent size to will treat the width height passed in to this function
|
||||||
// as logical pixels and scale to appropriate for the default monitor. Returns
|
// as logical pixels and scale to appropriate for the default monitor. Returns
|
||||||
// true if the window was created successfully.
|
// true if the window was created successfully.
|
||||||
bool CreateAndShow(const std::wstring& title,
|
bool CreateAndShow(const std::wstring& title,
|
||||||
const Point& origin,
|
const Point& origin,
|
||||||
const Size& size);
|
const Size& size);
|
||||||
|
|
||||||
// Release OS resources associated with window.
|
// Release OS resources associated with window.
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
// Inserts |content| into the window tree.
|
// Inserts |content| into the window tree.
|
||||||
void SetChildContent(HWND content);
|
void SetChildContent(HWND content);
|
||||||
|
|
||||||
// Returns the backing Window handle to enable clients to set icon and other
|
// Returns the backing Window handle to enable clients to set icon and other
|
||||||
// window properties. Returns nullptr if the window has been destroyed.
|
// window properties. Returns nullptr if the window has been destroyed.
|
||||||
HWND GetHandle();
|
HWND GetHandle();
|
||||||
|
|
||||||
// If true, closing this window will quit the application.
|
// If true, closing this window will quit the application.
|
||||||
void SetQuitOnClose(bool quit_on_close);
|
void SetQuitOnClose(bool quit_on_close);
|
||||||
|
|
||||||
// Return a RECT representing the bounds of the current client area.
|
// Return a RECT representing the bounds of the current client area.
|
||||||
RECT GetClientArea();
|
RECT GetClientArea();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Processes and route salient window messages for mouse handling,
|
// Processes and route salient window messages for mouse handling,
|
||||||
// size change and DPI. Delegates handling of these to member overloads that
|
// size change and DPI. Delegates handling of these to member overloads that
|
||||||
// inheriting classes can handle.
|
// inheriting classes can handle.
|
||||||
virtual LRESULT MessageHandler(HWND window,
|
virtual LRESULT MessageHandler(HWND window,
|
||||||
UINT const message,
|
UINT const message,
|
||||||
WPARAM const wparam,
|
WPARAM const wparam,
|
||||||
LPARAM const lparam) noexcept;
|
LPARAM const lparam) noexcept;
|
||||||
|
|
||||||
// Called when CreateAndShow is called, allowing subclass window-related
|
// Called when CreateAndShow is called, allowing subclass window-related
|
||||||
// setup. Subclasses should return false if setup fails.
|
// setup. Subclasses should return false if setup fails.
|
||||||
virtual bool OnCreate();
|
virtual bool OnCreate();
|
||||||
|
|
||||||
// Called when Destroy is called.
|
// Called when Destroy is called.
|
||||||
virtual void OnDestroy();
|
virtual void OnDestroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class WindowClassRegistrar;
|
friend class WindowClassRegistrar;
|
||||||
|
|
||||||
// OS callback called by message pump. Handles the WM_NCCREATE message which
|
// OS callback called by message pump. Handles the WM_NCCREATE message which
|
||||||
// is passed when the non-client area is being created and enables automatic
|
// is passed when the non-client area is being created and enables automatic
|
||||||
// non-client DPI scaling so that the non-client area automatically
|
// non-client DPI scaling so that the non-client area automatically
|
||||||
// responsponds to changes in DPI. All other messages are handled by
|
// responsponds to changes in DPI. All other messages are handled by
|
||||||
// MessageHandler.
|
// MessageHandler.
|
||||||
static LRESULT CALLBACK WndProc(HWND const window,
|
static LRESULT CALLBACK WndProc(HWND const window,
|
||||||
UINT const message,
|
UINT const message,
|
||||||
WPARAM const wparam,
|
WPARAM const wparam,
|
||||||
LPARAM const lparam) noexcept;
|
LPARAM const lparam) noexcept;
|
||||||
|
|
||||||
// Retrieves a class instance pointer for |window|
|
// Retrieves a class instance pointer for |window|
|
||||||
static Win32Window* GetThisFromHandle(HWND const window) noexcept;
|
static Win32Window* GetThisFromHandle(HWND const window) noexcept;
|
||||||
|
|
||||||
bool quit_on_close_ = false;
|
bool quit_on_close_ = false;
|
||||||
|
|
||||||
// window handle for top level window.
|
// window handle for top level window.
|
||||||
HWND window_handle_ = nullptr;
|
HWND window_handle_ = nullptr;
|
||||||
|
|
||||||
// window handle for hosted content.
|
// window handle for hosted content.
|
||||||
HWND child_content_ = nullptr;
|
HWND child_content_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RUNNER_WIN32_WINDOW_H_
|
#endif // RUNNER_WIN32_WINDOW_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user