aboutsummaryrefslogtreecommitdiff
path: root/include/cru/win/gui
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/win/gui')
-rw-r--r--include/cru/win/gui/GodWindow.hpp1
-rw-r--r--include/cru/win/gui/InputMethod.hpp6
-rw-r--r--include/cru/win/gui/UiApplication.hpp22
-rw-r--r--include/cru/win/gui/Window.hpp55
4 files changed, 63 insertions, 21 deletions
diff --git a/include/cru/win/gui/GodWindow.hpp b/include/cru/win/gui/GodWindow.hpp
index 0343b159..d9a128e6 100644
--- a/include/cru/win/gui/GodWindow.hpp
+++ b/include/cru/win/gui/GodWindow.hpp
@@ -3,6 +3,7 @@
#include "WindowNativeMessageEventArgs.hpp"
#include "cru/common/Event.hpp"
+#include "cru/common/String.hpp"
#include <memory>
diff --git a/include/cru/win/gui/InputMethod.hpp b/include/cru/win/gui/InputMethod.hpp
index 51a007d8..3784dcda 100644
--- a/include/cru/win/gui/InputMethod.hpp
+++ b/include/cru/win/gui/InputMethod.hpp
@@ -65,12 +65,12 @@ class WinInputMethodContext : public WinNativeResource,
IEvent<std::nullptr_t>* CompositionEvent() override;
- IEvent<std::u16string_view>* TextEvent() override;
+ IEvent<StringView>* TextEvent() override;
private:
void OnWindowNativeMessage(WindowNativeMessageEventArgs& args);
- std::u16string GetResultString();
+ String GetResultString();
AutoHIMC GetHIMC();
@@ -82,6 +82,6 @@ class WinInputMethodContext : public WinNativeResource,
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_;
+ Event<StringView> text_event_;
};
} // namespace cru::platform::gui::win
diff --git a/include/cru/win/gui/UiApplication.hpp b/include/cru/win/gui/UiApplication.hpp
index 4cf46858..4b972fee 100644
--- a/include/cru/win/gui/UiApplication.hpp
+++ b/include/cru/win/gui/UiApplication.hpp
@@ -7,7 +7,7 @@
#include <memory>
namespace cru::platform::graphics::win::direct {
-class DirectGraphFactory;
+class DirectGraphicsFactory;
}
namespace cru::platform::gui::win {
@@ -33,6 +33,13 @@ class WinUiApplication : public WinNativeResource,
void AddOnQuitHandler(std::function<void()> handler) override;
+ bool IsQuitOnAllWindowClosed() override {
+ return is_quit_on_all_window_closed_;
+ }
+ void SetQuitOnAllWindowClosed(bool quit_on_all_window_closed) override {
+ is_quit_on_all_window_closed_ = quit_on_all_window_closed;
+ }
+
long long SetImmediate(std::function<void()> action) override;
long long SetTimeout(std::chrono::milliseconds milliseconds,
std::function<void()> action) override;
@@ -41,16 +48,19 @@ class WinUiApplication : public WinNativeResource,
void CancelTimer(long long id) override;
std::vector<INativeWindow*> GetAllWindow() override;
- INativeWindow* CreateWindow(INativeWindow* parent, CreateWindowFlag flag) override;
+ INativeWindow* CreateWindow() override;
- cru::platform::graphics::IGraphFactory* GetGraphFactory() override;
+ cru::platform::graphics::IGraphicsFactory* GetGraphicsFactory() override;
- cru::platform::graphics::win::direct::DirectGraphFactory* GetDirectFactory() {
+ cru::platform::graphics::win::direct::DirectGraphicsFactory*
+ GetDirectFactory() {
return graph_factory_.get();
}
ICursorManager* GetCursorManager() override;
+ IClipboard* GetClipboard() override;
+
HINSTANCE GetInstanceHandle() const { return instance_handle_; }
GodWindow* GetGodWindow() const { return god_window_.get(); }
@@ -60,7 +70,9 @@ class WinUiApplication : public WinNativeResource,
private:
HINSTANCE instance_handle_;
- std::unique_ptr<cru::platform::graphics::win::direct::DirectGraphFactory>
+ bool is_quit_on_all_window_closed_ = true;
+
+ std::unique_ptr<cru::platform::graphics::win::direct::DirectGraphicsFactory>
graph_factory_;
std::unique_ptr<GodWindow> god_window_;
diff --git a/include/cru/win/gui/Window.hpp b/include/cru/win/gui/Window.hpp
index 97a74fa7..41eac5fa 100644
--- a/include/cru/win/gui/Window.hpp
+++ b/include/cru/win/gui/Window.hpp
@@ -2,7 +2,6 @@
#include "Resource.hpp"
#include "WindowNativeMessageEventArgs.hpp"
-#include "cru/platform/GraphBase.hpp"
#include "cru/platform/gui/Base.hpp"
#include "cru/platform/gui/Window.hpp"
#include "cru/win/graphics/direct/WindowRenderTarget.hpp"
@@ -14,8 +13,7 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
CRU_DEFINE_CLASS_LOG_TAG(u"cru::platform::gui::win::WinNativeWindow")
public:
- WinNativeWindow(WinUiApplication* application, WindowClass* window_class,
- DWORD window_style, WinNativeWindow* parent);
+ explicit WinNativeWindow(WinUiApplication* application);
CRU_DELETE_COPY(WinNativeWindow)
CRU_DELETE_MOVE(WinNativeWindow)
@@ -26,13 +24,20 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
void Close() override;
WinNativeWindow* GetParent() override { return parent_window_; }
+ void SetParent(INativeWindow* parent) override;
- bool IsVisible() override;
- void SetVisible(bool is_visible) override;
+ WindowStyleFlag GetStyleFlag() override { return style_flag_; }
+ void SetStyleFlag(WindowStyleFlag flag) override;
+
+ WindowVisibilityType GetVisibility() override { return visibility_; }
+ void SetVisibility(WindowVisibilityType visibility) override;
Size GetClientSize() override;
void SetClientSize(const Size& size) override;
+ Rect GetClientRect() override;
+ void SetClientRect(const Rect& rect) override;
+
// Get the rect of the window containing frame.
// The lefttop of the rect is relative to screen lefttop.
Rect GetWindowRect() override;
@@ -41,6 +46,8 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
// The lefttop of the rect is relative to screen lefttop.
void SetWindowRect(const Rect& rect) override;
+ bool RequestFocus() override;
+
Point GetMousePosition() override;
bool CaptureMouse() override;
@@ -51,8 +58,12 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
void SetCursor(std::shared_ptr<ICursor> cursor) override;
+ IEvent<std::nullptr_t>* CreateEvent() override { return &create_event_; }
IEvent<std::nullptr_t>* DestroyEvent() override { return &destroy_event_; }
IEvent<std::nullptr_t>* PaintEvent() override { return &paint_event_; }
+ IEvent<WindowVisibilityType>* VisibilityChangeEvent() override {
+ return &visibility_change_event_;
+ }
IEvent<Size>* ResizeEvent() override { return &resize_event_; }
IEvent<FocusChangeType>* FocusEvent() override { return &focus_event_; }
IEvent<MouseEnterLeaveType>* MouseEnterLeaveEvent() override {
@@ -106,6 +117,15 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
return result;
}
+ inline RECT DipToPixel(const Rect& dip_rect) {
+ RECT result;
+ result.left = DipToPixel(dip_rect.left);
+ result.top = DipToPixel(dip_rect.top);
+ result.right = DipToPixel(dip_rect.GetRight());
+ result.bottom = DipToPixel(dip_rect.GetBottom());
+ return result;
+ }
+
inline float PixelToDip(const int pixel) {
return static_cast<float>(pixel) * 96.0f / GetDpi();
}
@@ -114,14 +134,24 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
return Point(PixelToDip(pi_point.x), PixelToDip(pi_point.y));
}
+ inline Rect PixelToDip(const RECT& pi_rect) {
+ return Rect::FromVertices(PixelToDip(pi_rect.left), PixelToDip(pi_rect.top),
+ PixelToDip(pi_rect.right),
+ PixelToDip(pi_rect.bottom));
+ }
+
private:
// Get the client rect in pixel.
RECT GetClientRectPixel();
+ void RecreateWindow();
+
//*************** region: native messages ***************
+ void OnCreateInternal();
void OnDestroyInternal();
void OnPaintInternal();
+ void OnMoveInternal(int new_left, int new_top);
void OnResizeInternal(int new_width, int new_height);
void OnSetFocusInternal();
@@ -142,15 +172,12 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
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;
+ WindowStyleFlag style_flag_{};
+ WindowVisibilityType visibility_ = WindowVisibilityType::Hide;
+ Rect client_rect_{100, 100, 400, 300};
- HWND hwnd_;
- WinNativeWindow* parent_window_;
+ HWND hwnd_ = nullptr;
+ WinNativeWindow* parent_window_ = nullptr;
float dpi_;
@@ -164,9 +191,11 @@ class WinNativeWindow : public WinNativeResource, public virtual INativeWindow {
std::unique_ptr<WinInputMethodContext> input_method_context_;
+ Event<std::nullptr_t> create_event_;
Event<std::nullptr_t> destroy_event_;
Event<std::nullptr_t> paint_event_;
Event<Size> resize_event_;
+ Event<WindowVisibilityType> visibility_change_event_;
Event<FocusChangeType> focus_event_;
Event<MouseEnterLeaveType> mouse_enter_leave_event_;
Event<Point> mouse_move_event_;