| 1 | #include "flutter_window.h" |
| 2 | |
| 3 | #include <optional> |
| 4 | |
| 5 | #include "flutter/generated_plugin_registrant.h" |
| 6 | |
| 7 | FlutterWindow::FlutterWindow(const |
| 8 | : project_(project) {} |
| 9 | |
| 10 | FlutterWindow::~FlutterWindow() {} |
| 11 | |
| 12 | bool FlutterWindow::OnCreate |
| 13 | if (!Win32Window::OnCreate |
| 14 | return false; |
| 15 | } |
| 16 | |
| 17 | RECT frame |
| 18 | |
| 19 | // The size here must match the window dimensions to avoid unnecessary surface |
| 20 | // creation / destruction in the startup path. |
| 21 | flutter_controller_ = std:: |
| 22 | frame.right - |
| 23 | // Ensure that basic setup of the controller was successful. |
| 24 | if (!flutter_controller_->engine |
| 25 | return false; |
| 26 | } |
| 27 | RegisterPlugins(flutter_controller_->engine |
| 28 | SetChildContent(flutter_controller_->view |
| 29 | |
| 30 | flutter_controller_->engine()->SetNextFrameCallback |
| 31 | this->Show(); |
| 32 | }); |
| 33 | |
| 34 | // Flutter can complete the first frame before the "show window" callback is |
| 35 | // registered. The following call ensures a frame is pending to ensure the |
| 36 | // window is shown. It is a no-op if the first frame hasn't completed yet. |
| 37 | flutter_controller_->ForceRedraw(); |
| 38 | |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | void FlutterWindow::OnDestroy |
| 43 | if (flutter_controller_) { |
| 44 | flutter_controller_ = nullptr; |
| 45 | } |
| 46 | |
| 47 | Win32Window::OnDestroy(); |
| 48 | } |
| 49 | |
| 50 | LRESULT |
| 51 | FlutterWindow::MessageHandler(HWND |
| 52 | WPARAM const wparam |
| 53 | LPARAM const lparam |
| 54 | // Give Flutter, including plugins, an opportunity to handle window messages. |
| 55 | if (flutter_controller_) { |
| 56 | std::optional< |
| 57 | flutter_controller_->HandleTopLevelWindowProc(hwnd |
| 58 | lparam); |
| 59 | if (result) { |
| 60 | return *result; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | switch (message) { |
| 65 | case WM_FONTCHANGE: |
| 66 | flutter_controller_->engine()->ReloadSystemFonts |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | return Win32Window::MessageHandler |
| 71 | } |