aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win/native
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
committercrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
commit7f15a1ff9a2007e119798053083a0a87d042990a (patch)
treecb35c01a7eaee867376d959b96c9bbd15df939e5 /include/cru/win/native
parent74956951ee663012df0c3fe4ebe29799cb2f7732 (diff)
parent7703063a5816b089483e78ccd74bb9902ccfbea8 (diff)
downloadcru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.gz
cru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.bz2
cru-7f15a1ff9a2007e119798053083a0a87d042990a.zip
Merge branch 'master' of https://github.com/crupest/CruUI
Diffstat (limited to 'include/cru/win/native')
-rw-r--r--include/cru/win/native/Base.hpp19
-rw-r--r--include/cru/win/native/Cursor.hpp49
-rw-r--r--include/cru/win/native/Exception.hpp7
-rw-r--r--include/cru/win/native/GodWindow.hpp29
-rw-r--r--include/cru/win/native/InputMethod.hpp102
-rw-r--r--include/cru/win/native/Keyboard.hpp9
-rw-r--r--include/cru/win/native/Resource.hpp23
-rw-r--r--include/cru/win/native/UiApplication.hpp76
-rw-r--r--include/cru/win/native/Window.hpp176
-rw-r--r--include/cru/win/native/WindowClass.hpp24
-rw-r--r--include/cru/win/native/WindowNativeMessageEventArgs.hpp40
-rw-r--r--include/cru/win/native/WindowRenderTarget.hpp47
12 files changed, 0 insertions, 601 deletions
diff --git a/include/cru/win/native/Base.hpp b/include/cru/win/native/Base.hpp
deleted file mode 100644
index a50c6dd1..00000000
--- a/include/cru/win/native/Base.hpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-#include "../WinPreConfig.hpp"
-
-#include "cru/common/Base.hpp"
-
-namespace cru::platform::native::win {
-class GodWindow;
-class TimerManager;
-class WinCursor;
-class WinCursorManager;
-class WindowClass;
-class WindowManager;
-class WindowRenderTarget;
-class WinNativeWindow;
-class WinNativeWindowResolver;
-class WinUiApplication;
-class WinInputMethodManager;
-class WinInputMethodContextRef;
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/Cursor.hpp b/include/cru/win/native/Cursor.hpp
deleted file mode 100644
index 373b9170..00000000
--- a/include/cru/win/native/Cursor.hpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#pragma once
-#include "Resource.hpp"
-
-#include "cru/platform/native/Cursor.hpp"
-
-#include <memory>
-
-namespace cru::platform::native::win {
-class WinCursor : public WinNativeResource, public virtual ICursor {
- CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::WinCursor")
-
- public:
- WinCursor(HCURSOR handle, bool auto_destroy);
-
- CRU_DELETE_COPY(WinCursor)
- CRU_DELETE_MOVE(WinCursor)
-
- ~WinCursor() override;
-
- public:
- HCURSOR GetHandle() const { return handle_; }
-
- private:
- HCURSOR handle_;
- bool auto_destroy_;
-};
-
-class WinCursorManager : public WinNativeResource,
- public virtual ICursorManager {
- public:
- WinCursorManager();
-
- CRU_DELETE_COPY(WinCursorManager)
- CRU_DELETE_MOVE(WinCursorManager)
-
- ~WinCursorManager() override = default;
-
- public:
- std::shared_ptr<WinCursor> GetSystemWinCursor(SystemCursorType type);
-
- std::shared_ptr<ICursor> GetSystemCursor(SystemCursorType type) override {
- return std::static_pointer_cast<ICursor>(GetSystemWinCursor(type));
- }
-
- private:
- std::shared_ptr<WinCursor> sys_arrow_;
- std::shared_ptr<WinCursor> sys_hand_;
-};
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/Exception.hpp b/include/cru/win/native/Exception.hpp
deleted file mode 100644
index 6a5265c1..00000000
--- a/include/cru/win/native/Exception.hpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-#include "../Exception.hpp"
-
-namespace cru::platform::native::win {
-using platform::win::Win32Error;
-using platform::win::HResultError;
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/GodWindow.hpp b/include/cru/win/native/GodWindow.hpp
deleted file mode 100644
index 8b20e01f..00000000
--- a/include/cru/win/native/GodWindow.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#pragma once
-#include "Base.hpp"
-
-#include <memory>
-
-namespace cru::platform::native::win {
-class GodWindow : public Object {
- CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::GodWindow")
-
- public:
- explicit GodWindow(WinUiApplication* application);
-
- CRU_DELETE_COPY(GodWindow)
- CRU_DELETE_MOVE(GodWindow)
-
- ~GodWindow() override;
-
- HWND GetHandle() const { return hwnd_; }
-
- bool HandleGodWindowMessage(HWND hwnd, UINT msg, WPARAM w_param,
- LPARAM l_param, LRESULT* result);
-
- private:
- WinUiApplication* application_;
-
- std::unique_ptr<WindowClass> god_window_class_;
- HWND hwnd_;
-};
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/InputMethod.hpp b/include/cru/win/native/InputMethod.hpp
deleted file mode 100644
index 113f460d..00000000
--- a/include/cru/win/native/InputMethod.hpp
+++ /dev/null
@@ -1,102 +0,0 @@
-// Some useful information can be found from chromium code:
-// https://chromium.googlesource.com/chromium/chromium/+/refs/heads/master/ui/base/win/ime_input.h
-// https://chromium.googlesource.com/chromium/chromium/+/refs/heads/master/ui/base/win/ime_input.cc
-
-#pragma once
-#include "Resource.hpp"
-
-#include "WindowNativeMessageEventArgs.hpp"
-#include "cru/platform/native/InputMethod.hpp"
-
-#include <imm.h>
-
-namespace cru::platform::native::win {
-class AutoHIMC : public Object {
- CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::AutoHIMC")
-
- public:
- explicit AutoHIMC(HWND hwnd);
-
- CRU_DELETE_COPY(AutoHIMC)
-
- AutoHIMC(AutoHIMC&& other);
- AutoHIMC& operator=(AutoHIMC&& other);
-
- ~AutoHIMC() override;
-
- HWND GetHwnd() const { return hwnd_; }
-
- HIMC Get() const { return handle_; }
-
- private:
- HWND hwnd_;
- HIMC handle_;
-};
-
-class WinInputMethodContext : public WinNativeResource,
- public virtual IInputMethodContext {
- CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::WinInputMethodContext")
-
- public:
- WinInputMethodContext(gsl::not_null<WinNativeWindow*> window);
-
- CRU_DELETE_COPY(WinInputMethodContext)
- CRU_DELETE_MOVE(WinInputMethodContext)
-
- ~WinInputMethodContext() override;
-
- bool ShouldManuallyDrawCompositionText() override { return true; }
-
- void EnableIME() override;
-
- void DisableIME() override;
-
- void CompleteComposition() override;
-
- void CancelComposition() override;
-
- CompositionText GetCompositionText() override;
-
- void SetCandidateWindowPosition(const Point& point) override;
-
- IEvent<std::nullptr_t>* CompositionStartEvent() override;
-
- IEvent<std::nullptr_t>* CompositionEndEvent() override;
-
- IEvent<std::nullptr_t>* CompositionEvent() override;
-
- IEvent<std::u16string_view>* TextEvent() override;
-
- private:
- void OnWindowNativeMessage(WindowNativeMessageEventArgs& args);
-
- std::u16string GetResultString();
-
- std::optional<AutoHIMC> TryGetHIMC();
-
- private:
- std::shared_ptr<INativeWindowResolver> native_window_resolver_;
-
- std::vector<EventRevokerGuard> event_revoker_guards_;
-
- Event<std::nullptr_t> composition_start_event_;
- Event<std::nullptr_t> composition_end_event_;
- Event<std::nullptr_t> composition_event_;
- Event<std::u16string_view> text_event_;
-};
-
-class WinInputMethodManager : public WinNativeResource,
- public virtual IInputMethodManager {
- public:
- WinInputMethodManager(WinUiApplication* application);
-
- CRU_DELETE_COPY(WinInputMethodManager)
- CRU_DELETE_MOVE(WinInputMethodManager)
-
- ~WinInputMethodManager() override;
-
- public:
- std::unique_ptr<IInputMethodContext> GetContext(
- INativeWindow* window) override;
-};
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/Keyboard.hpp b/include/cru/win/native/Keyboard.hpp
deleted file mode 100644
index 790e0015..00000000
--- a/include/cru/win/native/Keyboard.hpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-#include "Base.hpp"
-
-#include "cru/platform/native/Keyboard.hpp"
-
-namespace cru::platform::native::win {
-KeyCode VirtualKeyToKeyCode(int virtual_key);
-KeyModifier RetrieveKeyMofifier();
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/Resource.hpp b/include/cru/win/native/Resource.hpp
deleted file mode 100644
index 0de0e1a8..00000000
--- a/include/cru/win/native/Resource.hpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-#include "Base.hpp"
-
-#include "cru/platform/Resource.hpp"
-
-namespace cru::platform::native::win {
-class WinNativeResource : public Object, public virtual INativeResource {
- public:
- static constexpr std::u16string_view k_platform_id = u"Windows";
-
- protected:
- WinNativeResource() = default;
-
- public:
- CRU_DELETE_COPY(WinNativeResource)
- CRU_DELETE_MOVE(WinNativeResource)
-
- ~WinNativeResource() override = default;
-
- public:
- std::u16string_view GetPlatformId() const final { return k_platform_id; }
-};
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/UiApplication.hpp b/include/cru/win/native/UiApplication.hpp
deleted file mode 100644
index cbc08af7..00000000
--- a/include/cru/win/native/UiApplication.hpp
+++ /dev/null
@@ -1,76 +0,0 @@
-#pragma once
-#include "Resource.hpp"
-
-#include "cru/platform/native/UiApplication.hpp"
-
-#include <memory>
-
-namespace cru::platform::graph::win::direct {
-class DirectGraphFactory;
-}
-
-namespace cru::platform::native::win {
-class WinUiApplication : public WinNativeResource,
- public virtual IUiApplication {
- public:
- static WinUiApplication* GetInstance() { return instance; }
-
- private:
- static WinUiApplication* instance;
-
- public:
- WinUiApplication();
-
- CRU_DELETE_COPY(WinUiApplication)
- CRU_DELETE_MOVE(WinUiApplication)
-
- ~WinUiApplication() override;
-
- public:
- int Run() override;
- void RequestQuit(int quit_code) override;
-
- void AddOnQuitHandler(std::function<void()> handler) override;
-
- void InvokeLater(std::function<void()> action) override;
- long long SetTimeout(std::chrono::milliseconds milliseconds,
- std::function<void()> action) override;
- long long SetInterval(std::chrono::milliseconds milliseconds,
- std::function<void()> action) override;
- void CancelTimer(long long id) override;
-
- std::vector<INativeWindow*> GetAllWindow() override;
- std::shared_ptr<INativeWindowResolver> CreateWindow(
- INativeWindow* parent) override;
-
- cru::platform::graph::IGraphFactory* GetGraphFactory() override;
-
- cru::platform::graph::win::direct::DirectGraphFactory* GetDirectFactory() {
- return graph_factory_.get();
- }
-
- ICursorManager* GetCursorManager() override;
- IInputMethodManager* GetInputMethodManager() override;
-
- HINSTANCE GetInstanceHandle() const { return instance_handle_; }
-
- GodWindow* GetGodWindow() const { return god_window_.get(); }
- TimerManager* GetTimerManager() const { return timer_manager_.get(); }
- WindowManager* GetWindowManager() const { return window_manager_.get(); }
-
- private:
- HINSTANCE instance_handle_;
-
- std::unique_ptr<cru::platform::graph::win::direct::DirectGraphFactory>
- graph_factory_;
-
- std::unique_ptr<GodWindow> god_window_;
- std::unique_ptr<TimerManager> timer_manager_;
- std::unique_ptr<WindowManager> window_manager_;
-
- std::unique_ptr<WinCursorManager> cursor_manager_;
- std::unique_ptr<WinInputMethodManager> input_method_manager_;
-
- std::vector<std::function<void()>> quit_handlers_;
-};
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/Window.hpp b/include/cru/win/native/Window.hpp
deleted file mode 100644
index 3e0b11cd..00000000
--- a/include/cru/win/native/Window.hpp
+++ /dev/null
@@ -1,176 +0,0 @@
-#pragma once
-#include "Resource.hpp"
-
-#include "WindowNativeMessageEventArgs.hpp"
-#include "cru/platform/native/Window.hpp"
-
-#include <memory>
-
-namespace cru::platform::native::win {
-class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
- CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::native::win::WinNativeWindow")
-
- public:
- WinNativeWindow(WinUiApplication* application, WindowClass* window_class,
- DWORD window_style, WinNativeWindow* parent);
-
- CRU_DELETE_COPY(WinNativeWindow)
- CRU_DELETE_MOVE(WinNativeWindow)
-
- ~WinNativeWindow() override;
-
- public:
- std::shared_ptr<INativeWindowResolver> GetResolver() override {
- return std::static_pointer_cast<INativeWindowResolver>(resolver_);
- }
-
- void Close() override;
-
- WinNativeWindow* GetParent() override { return parent_window_; }
-
- bool IsVisible() override;
- void SetVisible(bool is_visible) override;
-
- Size GetClientSize() override;
- void SetClientSize(const Size& size) override;
-
- // Get the rect of the window containing frame.
- // The lefttop of the rect is relative to screen lefttop.
- Rect GetWindowRect() override;
-
- // Set the rect of the window containing frame.
- // The lefttop of the rect is relative to screen lefttop.
- void SetWindowRect(const Rect& rect) override;
-
- Point GetMousePosition() override;
-
- bool CaptureMouse() override;
- bool ReleaseMouse() override;
-
- void RequestRepaint() override;
- std::unique_ptr<graph::IPainter> BeginPaint() override;
-
- void SetCursor(std::shared_ptr<ICursor> cursor) override;
-
- IEvent<std::nullptr_t>* DestroyEvent() override { return &destroy_event_; }
- IEvent<std::nullptr_t>* PaintEvent() override { return &paint_event_; }
- IEvent<Size>* ResizeEvent() override { return &resize_event_; }
- IEvent<FocusChangeType>* FocusEvent() override { return &focus_event_; }
- IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override {
- return &mouse_enter_leave_event_;
- }
- IEvent<Point>* MouseMoveEvent() override { return &mouse_move_event_; }
- IEvent<platform::native::NativeMouseButtonEventArgs>* MouseDownEvent()
- override {
- return &mouse_down_event_;
- }
- IEvent<platform::native::NativeMouseButtonEventArgs>* MouseUpEvent()
- override {
- return &mouse_up_event_;
- }
- IEvent<platform::native::NativeKeyEventArgs>* KeyDownEvent() override {
- return &key_down_event_;
- }
- IEvent<platform::native::NativeKeyEventArgs>* KeyUpEvent() override {
- return &key_up_event_;
- }
-
- IEvent<WindowNativeMessageEventArgs&>* NativeMessageEvent() {
- return &native_message_event_;
- }
-
- // Get the handle of the window. Return null if window is invalid.
- HWND GetWindowHandle() const { return hwnd_; }
-
- bool HandleNativeWindowMessage(HWND hwnd, UINT msg, WPARAM w_param,
- LPARAM l_param, LRESULT* result);
-
- WindowRenderTarget* GetWindowRenderTarget() const {
- return window_render_target_.get();
- }
-
- private:
- // Get the client rect in pixel.
- RECT GetClientRectPixel();
-
- //*************** region: native messages ***************
-
- void OnDestroyInternal();
- void OnPaintInternal();
- void OnResizeInternal(int new_width, int new_height);
-
- void OnSetFocusInternal();
- void OnKillFocusInternal();
-
- void OnMouseMoveInternal(POINT point);
- void OnMouseLeaveInternal();
- void OnMouseDownInternal(platform::native::MouseButton button, POINT point);
- void OnMouseUpInternal(platform::native::MouseButton button, POINT point);
-
- void OnMouseWheelInternal(short delta, POINT point);
- void OnKeyDownInternal(int virtual_code);
- void OnKeyUpInternal(int virtual_code);
-
- void OnActivatedInternal();
- void OnDeactivatedInternal();
-
- private:
- WinUiApplication* application_;
-
- // when delete is called first, it set this to true to indicate
- // destroy message handler not to double delete this instance;
- // when destroy handler is called first (by user action or method
- // Close), it set this to true to indicate delete not call Close
- // again.
- bool sync_flag_ = false;
-
- std::shared_ptr<WinNativeWindowResolver> resolver_;
-
- HWND hwnd_;
- WinNativeWindow* parent_window_;
-
- bool has_focus_ = false;
- bool is_mouse_in_ = false;
-
- std::unique_ptr<WindowRenderTarget> window_render_target_;
-
- std::shared_ptr<WinCursor> cursor_;
-
- Event<std::nullptr_t> destroy_event_;
- Event<std::nullptr_t> paint_event_;
- Event<Size> resize_event_;
- Event<FocusChangeType> focus_event_;
- Event<MouseEnterLeaveType> mouse_enter_leave_event_;
- Event<Point> mouse_move_event_;
- Event<platform::native::NativeMouseButtonEventArgs> mouse_down_event_;
- Event<platform::native::NativeMouseButtonEventArgs> mouse_up_event_;
- Event<platform::native::NativeKeyEventArgs> key_down_event_;
- Event<platform::native::NativeKeyEventArgs> key_up_event_;
-
- Event<WindowNativeMessageEventArgs&> native_message_event_;
-};
-
-class WinNativeWindowResolver : public WinNativeResource,
- public virtual INativeWindowResolver {
- friend WinNativeWindow::~WinNativeWindow();
-
- public:
- WinNativeWindowResolver(WinNativeWindow* window) : window_(window) {}
-
- CRU_DELETE_COPY(WinNativeWindowResolver)
- CRU_DELETE_MOVE(WinNativeWindowResolver)
-
- ~WinNativeWindowResolver() override = default;
-
- public:
- INativeWindow* Resolve() override { return window_; }
-
- private:
- void Reset();
-
- private:
- WinNativeWindow* window_;
-};
-
-WinNativeWindow* Resolve(gsl::not_null<INativeWindowResolver*> resolver);
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/WindowClass.hpp b/include/cru/win/native/WindowClass.hpp
deleted file mode 100644
index fdd55065..00000000
--- a/include/cru/win/native/WindowClass.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-#include "Base.hpp"
-
-#include <string>
-
-namespace cru::platform::native::win {
-class WindowClass : public Object {
- public:
- WindowClass(std::wstring name, WNDPROC window_proc, HINSTANCE h_instance);
-
- CRU_DELETE_COPY(WindowClass)
- CRU_DELETE_MOVE(WindowClass)
-
- ~WindowClass() override = default;
-
- const wchar_t* GetName() const { return name_.c_str(); }
-
- ATOM GetAtom() const { return atom_; }
-
- private:
- std::wstring name_;
- ATOM atom_;
-};
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/WindowNativeMessageEventArgs.hpp b/include/cru/win/native/WindowNativeMessageEventArgs.hpp
deleted file mode 100644
index 84a7a123..00000000
--- a/include/cru/win/native/WindowNativeMessageEventArgs.hpp
+++ /dev/null
@@ -1,40 +0,0 @@
-#pragma once
-#include "../WinPreConfig.hpp"
-
-#include "cru/common/Base.hpp"
-
-namespace cru::platform::native::win {
-struct WindowNativeMessage {
- HWND hwnd;
- UINT msg;
- WPARAM w_param;
- LPARAM l_param;
-};
-
-class WindowNativeMessageEventArgs : public Object {
- public:
- WindowNativeMessageEventArgs(const WindowNativeMessage& message)
- : message_(message) {}
- CRU_DEFAULT_COPY(WindowNativeMessageEventArgs)
- CRU_DEFAULT_MOVE(WindowNativeMessageEventArgs)
- ~WindowNativeMessageEventArgs() override = default;
-
- const WindowNativeMessage& GetWindowMessage() const { return message_; }
-
- LRESULT GetResult() const { return result_; }
- void SetResult(LRESULT result) { result_ = result; }
-
- bool IsHandled() const { return handled_; }
- void SetHandled(bool handled) { handled_ = handled; }
-
- void HandleWithResult(LRESULT result) {
- handled_ = true;
- result_ = result;
- }
-
- private:
- WindowNativeMessage message_;
- LRESULT result_;
- bool handled_ = false;
-};
-} // namespace cru::platform::native::win
diff --git a/include/cru/win/native/WindowRenderTarget.hpp b/include/cru/win/native/WindowRenderTarget.hpp
deleted file mode 100644
index 83ac1e03..00000000
--- a/include/cru/win/native/WindowRenderTarget.hpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#pragma once
-#include "Base.hpp"
-
-namespace cru::platform::graph::win::direct {
-class DirectGraphFactory;
-}
-
-namespace cru::platform::native::win {
-// Represents a window render target.
-class WindowRenderTarget : public Object {
- public:
- WindowRenderTarget(graph::win::direct::DirectGraphFactory* factory,
- HWND hwnd);
-
- CRU_DELETE_COPY(WindowRenderTarget)
- CRU_DELETE_MOVE(WindowRenderTarget)
-
- ~WindowRenderTarget() override = default;
-
- public:
- graph::win::direct::DirectGraphFactory* GetDirectFactory() const {
- return factory_;
- }
-
- ID2D1DeviceContext* GetD2D1DeviceContext() {
- return d2d1_device_context_.Get();
- }
-
- // Resize the underlying buffer.
- void ResizeBuffer(int width, int height);
-
- // Set this render target as the d2d device context's target.
- void SetAsTarget();
-
- // Present the data of the underlying buffer to the window.
- void Present();
-
- private:
- void CreateTargetBitmap();
-
- private:
- graph::win::direct::DirectGraphFactory* factory_;
- Microsoft::WRL::ComPtr<ID2D1DeviceContext> d2d1_device_context_;
- Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgi_swap_chain_;
- Microsoft::WRL::ComPtr<ID2D1Bitmap1> target_bitmap_;
-};
-} // namespace cru::platform::native::win