mirror of
https://github.com/flutter/flutter.git
synced 2026-01-20 20:55:29 +08:00
## What's new?
- Implement and test `_window_win32.dart`, the Win32 implementation of
`_window.dart` 🎉
- Wrote a bunch of tests in `window_win32_test.dart` which uses a mock
API barrier to mock the native Win32 layer
- Update `BaseWindowController` to extend `ChangeNotifier` and use it to
inform the `WindowScope` of when things change
- Made `RegularWindowController.empty()` a non-internal constructor, as
it is needed by implementations
- Added a _large_ example application for windowing where users can test
out different windowing concepts and see how they work!
To test, simply run the tests or try out the example app!
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "utils.h"
|
|
|
|
#include <flutter_windows.h>
|
|
#include <io.h>
|
|
#include <stdio.h>
|
|
#include <windows.h>
|
|
|
|
#include <iostream>
|
|
|
|
void CreateAndAttachConsole() {
|
|
if (::AllocConsole()) {
|
|
FILE *unused;
|
|
if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
|
|
_dup2(_fileno(stdout), 1);
|
|
}
|
|
if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
|
|
_dup2(_fileno(stdout), 2);
|
|
}
|
|
std::ios::sync_with_stdio();
|
|
FlutterDesktopResyncOutputStreams();
|
|
}
|
|
}
|
|
|
|
std::vector<std::string> GetCommandLineArguments() {
|
|
// Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
|
|
int argc;
|
|
wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
|
if (argv == nullptr) {
|
|
return std::vector<std::string>();
|
|
}
|
|
|
|
std::vector<std::string> command_line_arguments;
|
|
|
|
// Skip the first argument as it's the binary name.
|
|
for (int i = 1; i < argc; i++) {
|
|
command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
|
|
}
|
|
|
|
::LocalFree(argv);
|
|
|
|
return command_line_arguments;
|
|
}
|
|
|
|
std::string Utf8FromUtf16(const wchar_t* utf16_string) {
|
|
if (utf16_string == nullptr) {
|
|
return std::string();
|
|
}
|
|
unsigned int target_length = ::WideCharToMultiByte(
|
|
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
|
|
-1, nullptr, 0, nullptr, nullptr)
|
|
-1; // remove the trailing null character
|
|
std::string utf8_string;
|
|
if (target_length == 0 || target_length > utf8_string.max_size()) {
|
|
return utf8_string;
|
|
}
|
|
utf8_string.resize(target_length);
|
|
int converted_length = ::WideCharToMultiByte(
|
|
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
|
|
-1, utf8_string.data(), target_length, nullptr, nullptr);
|
|
if (converted_length == 0) {
|
|
return std::string();
|
|
}
|
|
return utf8_string;
|
|
}
|