diff options
Diffstat (limited to 'include/cru/win/native')
-rw-r--r-- | include/cru/win/native/Base.hpp | 16 | ||||
-rw-r--r-- | include/cru/win/native/Cursor.hpp | 49 | ||||
-rw-r--r-- | include/cru/win/native/Exception.hpp | 7 | ||||
-rw-r--r-- | include/cru/win/native/GodWindow.hpp | 38 | ||||
-rw-r--r-- | include/cru/win/native/InputMethod.hpp | 87 | ||||
-rw-r--r-- | include/cru/win/native/Keyboard.hpp | 9 | ||||
-rw-r--r-- | include/cru/win/native/Resource.hpp | 23 | ||||
-rw-r--r-- | include/cru/win/native/UiApplication.hpp | 74 | ||||
-rw-r--r-- | include/cru/win/native/Window.hpp | 178 | ||||
-rw-r--r-- | include/cru/win/native/WindowClass.hpp | 24 | ||||
-rw-r--r-- | include/cru/win/native/WindowNativeMessageEventArgs.hpp | 40 |
11 files changed, 0 insertions, 545 deletions
diff --git a/include/cru/win/native/Base.hpp b/include/cru/win/native/Base.hpp deleted file mode 100644 index 881dd8b1..00000000 --- a/include/cru/win/native/Base.hpp +++ /dev/null @@ -1,16 +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 WinNativeWindow; -class WinUiApplication; -class WinInputMethodContext; -} // 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 93d1acad..00000000 --- a/include/cru/win/native/GodWindow.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once -#include "Base.hpp" - -#include "WindowNativeMessageEventArgs.hpp" -#include "cru/common/Event.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); - - IEvent<WindowNativeMessageEventArgs&>* MessageEvent() { - return &message_event_; - } - - private: - WinUiApplication* application_; - - std::unique_ptr<WindowClass> god_window_class_; - HWND hwnd_; - - Event<WindowNativeMessageEventArgs&> message_event_; -}; -} // 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 f3dc15c0..00000000 --- a/include/cru/win/native/InputMethod.hpp +++ /dev/null @@ -1,87 +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(); - - AutoHIMC GetHIMC(); - - private: - WinNativeWindow* native_window_; - - EventRevokerListGuard event_guard_; - - 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_; -}; -} // 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 170be532..00000000 --- a/include/cru/win/native/UiApplication.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once -#include "Resource.hpp" - -#include "cru/platform/native/Base.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; - - long long SetImmediate(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; - INativeWindow* CreateWindow(INativeWindow* parent) override; - - cru::platform::graph::IGraphFactory* GetGraphFactory() override; - - cru::platform::graph::win::direct::DirectGraphFactory* GetDirectFactory() { - return graph_factory_.get(); - } - - ICursorManager* GetCursorManager() 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::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 6bf71601..00000000 --- a/include/cru/win/native/Window.hpp +++ /dev/null @@ -1,178 +0,0 @@ -#pragma once -#include "Resource.hpp" - -#include "WindowNativeMessageEventArgs.hpp" -#include "cru/platform/GraphBase.hpp" -#include "cru/platform/native/Base.hpp" -#include "cru/platform/native/Window.hpp" -#include "cru/win/graph/direct/WindowRenderTarget.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: - 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_; - } - - IInputMethodContext* GetInputMethodContext() override; - - // 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); - - graph::win::direct::D2DWindowRenderTarget* GetWindowRenderTarget() const { - return window_render_target_.get(); - } - - //*************** region: dpi *************** - float GetDpi() const { return dpi_; } - - inline int DipToPixel(const float dip) { - return static_cast<int>(dip * GetDpi() / 96.0f); - } - - inline POINT DipToPixel(const Point& dip_point) { - POINT result; - result.x = DipToPixel(dip_point.x); - result.y = DipToPixel(dip_point.y); - return result; - } - - inline float PixelToDip(const int pixel) { - return static_cast<float>(pixel) * 96.0f / GetDpi(); - } - - inline Point PixelToDip(const POINT& pi_point) { - return Point(PixelToDip(pi_point.x), PixelToDip(pi_point.y)); - } - - 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; - - HWND hwnd_; - WinNativeWindow* parent_window_; - - float dpi_; - - bool has_focus_ = false; - bool is_mouse_in_ = false; - - std::unique_ptr<graph::win::direct::D2DWindowRenderTarget> - window_render_target_; - - std::shared_ptr<WinCursor> cursor_; - - std::unique_ptr<WinInputMethodContext> input_method_context_; - - 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_; -}; -} // 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 |