aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/base/Guard.h112
-rw-r--r--include/cru/base/platform/win/Base.h73
-rw-r--r--include/cru/platform/gui/TimerHelper.h69
-rw-r--r--include/cru/platform/gui/UiApplication.h9
-rw-r--r--include/cru/platform/gui/xcb/Window.h2
-rw-r--r--include/cru/ui/controls/TextHostControlService.h1
-rw-r--r--include/cru/ui/host/LayoutPaintCycler.h1
-rw-r--r--include/cru/ui/render/ScrollBar.h1
-rw-r--r--src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp6
-rw-r--r--src/base/platform/unix/EventLoop.cpp2
-rw-r--r--src/platform/gui/osx/Window.mm1
-rw-r--r--src/platform/gui/osx/WindowPrivate.h2
-rw-r--r--src/platform/gui/xcb/Input.cpp6
-rw-r--r--src/platform/gui/xcb/UiApplication.cpp2
-rw-r--r--src/platform/gui/xcb/Window.cpp133
-rw-r--r--src/ui/render/TextRenderObject.cpp3
16 files changed, 192 insertions, 231 deletions
diff --git a/include/cru/base/Guard.h b/include/cru/base/Guard.h
index 6b6cf851..65e2dee4 100644
--- a/include/cru/base/Guard.h
+++ b/include/cru/base/Guard.h
@@ -1,7 +1,11 @@
#pragma once
+#include "Base.h"
+#include "cru/base/Base.h"
+
#include <cstdlib>
#include <functional>
+#include <optional>
namespace cru {
struct Guard {
@@ -25,18 +29,23 @@ struct Guard {
ExitFunc on_exit;
};
-template <typename T>
-struct FreeLater {
- FreeLater(T* ptr) : ptr(ptr) {}
- ~FreeLater() { ::free(ptr); }
+/**
+ * FreeFunc must handle nullptr correctly.
+ */
+template <typename T, void (*FreeFunc)(T*) noexcept>
+struct TAutoFreePtr {
+ TAutoFreePtr(T* ptr) : ptr(ptr) {}
+ ~TAutoFreePtr() { FreeFunc(ptr); }
- FreeLater(const FreeLater& other) = delete;
- FreeLater& operator=(const FreeLater& other) = delete;
+ CRU_DELETE_COPY(TAutoFreePtr)
- FreeLater(FreeLater&& other) : ptr(other.ptr) { other.ptr = nullptr; }
- FreeLater& operator=(FreeLater&& other) {
+ TAutoFreePtr(TAutoFreePtr&& other) noexcept : ptr(other.ptr) {
+ other.ptr = nullptr;
+ }
+
+ TAutoFreePtr& operator=(TAutoFreePtr&& other) noexcept {
if (this != &other) {
- ::free(ptr);
+ FreeFunc(ptr);
ptr = other.ptr;
other.ptr = nullptr;
}
@@ -49,4 +58,89 @@ struct FreeLater {
T* ptr;
};
+namespace details {
+template <typename T>
+inline void MyFree(T* p) noexcept {
+ ::free(p);
+}
+} // namespace details
+
+template <typename T>
+using AutoFreePtr = TAutoFreePtr<T, details::MyFree<T>>;
+
+template <typename T, void (*DestructFunc)(T value) noexcept>
+class AutoDestruct {
+ public:
+ AutoDestruct() : value_(std::nullopt), auto_destruct_(false) {}
+
+ AutoDestruct(T value, bool auto_destruct = true)
+ : value_(std::move(value)), auto_destruct_(auto_destruct) {}
+
+ CRU_DELETE_COPY(AutoDestruct)
+
+ AutoDestruct(AutoDestruct&& other) noexcept
+ : value_(std::move(other.value_)), auto_destruct_(other.auto_destruct_) {
+ other.value_ = std::nullopt;
+ other.auto_destruct_ = false;
+ }
+
+ AutoDestruct& operator=(AutoDestruct&& other) noexcept {
+ if (this != &other) {
+ DoDestruct();
+ value_ = other.value_;
+ auto_destruct_ = other.auto_destruct_;
+ other.value_ = std::nullopt;
+ other.auto_destruct_ = false;
+ }
+ return *this;
+ }
+
+ ~AutoDestruct() { DoDestruct(); }
+
+ public:
+ bool IsValid() const { return value_.has_value(); }
+
+ void CheckValid(
+ std::optional<std::string_view> additional_message = std::nullopt) const {
+ if (!IsValid()) {
+ std::string message("AutoDestruct contains no object.");
+ if (additional_message) {
+ message += " ";
+ message += *additional_message;
+ }
+ throw Exception(std::move(message));
+ }
+ }
+
+ const T& Get() const {
+ CheckValid();
+ return *value_;
+ }
+
+ T Release() {
+ CheckValid();
+ auto value = std::move(*value_);
+ value_ = std::nullopt;
+ auto_destruct_ = false;
+ return value;
+ }
+
+ void Reset(std::optional<T> value = std::nullopt) {
+ DoDestruct();
+ value_ = std::move(value);
+ }
+
+ explicit operator bool() const { return value_.has_value(); }
+
+ private:
+ void DoDestruct() {
+ if (auto_destruct_ && value_) {
+ DestructFunc(*value_);
+ }
+ }
+
+ private:
+ std::optional<T> value_;
+ bool auto_destruct_;
+};
} // namespace cru
diff --git a/include/cru/base/platform/win/Base.h b/include/cru/base/platform/win/Base.h
index 8d221c83..cdd92541 100644
--- a/include/cru/base/platform/win/Base.h
+++ b/include/cru/base/platform/win/Base.h
@@ -6,8 +6,8 @@
#include "../../Base.h"
#include "../../Bitmask.h"
+#include "../../Guard.h"
-#include <optional>
#include <string_view>
#define NOMINMAX
@@ -54,80 +54,11 @@ inline void CheckWinReturn(BOOL r, std::string_view message = "") {
}
}
-template <typename H, void (*CloseFunc)(H handle) noexcept>
-class CRU_BASE_API TWin32Handle {
- public:
- TWin32Handle() : handle_(std::nullopt), auto_close_(false) {}
-
- TWin32Handle(H handle, bool auto_close)
- : handle_(handle), auto_close_(auto_close) {}
-
- CRU_DELETE_COPY(TWin32Handle)
-
- TWin32Handle(TWin32Handle&& other) noexcept
- : handle_(other.handle_), auto_close_(other.auto_close_) {
- other.handle_ = std::nullopt;
- other.auto_close_ = false;
- }
-
- TWin32Handle& operator=(TWin32Handle&& other) noexcept {
- if (this != &other) {
- DoClose();
- handle_ = other.handle_;
- auto_close_ = other.auto_close_;
- other.handle_ = std::nullopt;
- other.auto_close_ = false;
- }
- return *this;
- }
-
- ~TWin32Handle() { DoClose(); }
-
- public:
- bool IsValid() const { return handle_.has_value(); }
-
- void CheckValid(
- std::optional<std::string_view> additional_message = std::nullopt) const {
- if (!IsValid()) {
- std::string message("The win32 handle is invalid.");
- if (additional_message) {
- message += " ";
- message += *additional_message;
- }
- throw Exception(std::move(message));
- }
- }
-
- H Get() const {
- CheckValid();
- return *handle_;
- }
-
- H Release() {
- CheckValid();
- auto handle = *handle_;
- handle_ = std::nullopt;
- auto_close_ = false;
- return handle;
- }
-
- private:
- void DoClose() {
- if (auto_close_ && handle_) {
- CloseFunc(*handle_);
- }
- }
-
- private:
- std::optional<H> handle_;
- bool auto_close_;
-};
-
namespace details {
inline void MyCloseHandle(HANDLE handle) noexcept { ::CloseHandle(handle); }
} // namespace details
-using Win32Handle = TWin32Handle<HANDLE, details::MyCloseHandle>;
+using Win32Handle = AutoDestruct<HANDLE, details::MyCloseHandle>;
struct UniDirectionalWin32PipeResult {
Win32Handle read;
diff --git a/include/cru/platform/gui/TimerHelper.h b/include/cru/platform/gui/TimerHelper.h
deleted file mode 100644
index 91d436a4..00000000
--- a/include/cru/platform/gui/TimerHelper.h
+++ /dev/null
@@ -1,69 +0,0 @@
-#pragma once
-#include "UiApplication.h"
-
-namespace cru::platform::gui {
-
-class TimerAutoCanceler {
- public:
- TimerAutoCanceler() : id_(0) {}
- explicit TimerAutoCanceler(long long id) : id_(id) {}
-
- CRU_DELETE_COPY(TimerAutoCanceler)
-
- TimerAutoCanceler(TimerAutoCanceler&& other) : id_(other.id_) {
- other.id_ = 0;
- }
-
- TimerAutoCanceler& operator=(TimerAutoCanceler&& other) {
- if (&other == this) {
- return *this;
- }
- Reset(other.id_);
- other.id_ = 0;
- return *this;
- }
-
- TimerAutoCanceler& operator=(long long other) {
- return this->operator=(TimerAutoCanceler(other));
- }
-
- ~TimerAutoCanceler() { Reset(); }
-
- long long Release() {
- auto temp = id_;
- id_ = 0;
- return temp;
- }
-
- void Reset(long long id = 0) {
- if (id_ > 0) IUiApplication::GetInstance()->CancelTimer(id_);
- id_ = id;
- }
-
- explicit operator bool() const { return id_; }
-
- private:
- long long id_;
-};
-
-class TimerListAutoCanceler {
- public:
- TimerListAutoCanceler() = default;
- CRU_DELETE_COPY(TimerListAutoCanceler)
- CRU_DEFAULT_MOVE(TimerListAutoCanceler)
- ~TimerListAutoCanceler() = default;
-
- TimerListAutoCanceler& operator+=(long long id) {
- list_.push_back(TimerAutoCanceler(id));
- return *this;
- }
-
- void Clear() { list_.clear(); }
-
- bool IsEmpty() const { return list_.empty(); }
-
- private:
- std::vector<TimerAutoCanceler> list_;
-};
-
-} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/UiApplication.h b/include/cru/platform/gui/UiApplication.h
index d15a3c72..84011275 100644
--- a/include/cru/platform/gui/UiApplication.h
+++ b/include/cru/platform/gui/UiApplication.h
@@ -3,6 +3,7 @@
#include "Menu.h"
#include "SaveOpenDialogOptions.h"
+#include <cru/base/Guard.h>
#include <cru/platform/graphics/Factory.h>
#include <chrono>
@@ -74,4 +75,12 @@ struct CRU_PLATFORM_GUI_API IUiApplication : public virtual IPlatformResource {
virtual std::optional<std::vector<std::string>> ShowOpenDialog(
OpenDialogOptions options);
};
+
+namespace details {
+inline void CancelTimer(long long id) noexcept {
+ IUiApplication::GetInstance()->CancelTimer(id);
+}
+} // namespace details
+
+using TimerAutoCanceler = AutoDestruct<long long, details::CancelTimer>;
} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h
index 4cb5f6da..293732c5 100644
--- a/include/cru/platform/gui/xcb/Window.h
+++ b/include/cru/platform/gui/xcb/Window.h
@@ -2,7 +2,7 @@
#pragma once
#include "Base.h"
-#include <cru/platform/gui/TimerHelper.h>
+#include <cru/platform/gui/UiApplication.h>
#include <cru/platform/gui/Window.h>
#include <cairo.h>
diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h
index a9f4f22b..d4a1218f 100644
--- a/include/cru/ui/controls/TextHostControlService.h
+++ b/include/cru/ui/controls/TextHostControlService.h
@@ -1,7 +1,6 @@
#pragma once
#include "../render/TextRenderObject.h"
#include "cru/platform/gui/InputMethod.h"
-#include "cru/platform/gui/TimerHelper.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/DeleteLater.h"
#include "cru/ui/controls/Control.h"
diff --git a/include/cru/ui/host/LayoutPaintCycler.h b/include/cru/ui/host/LayoutPaintCycler.h
index e95ed81d..e4ff7aa8 100644
--- a/include/cru/ui/host/LayoutPaintCycler.h
+++ b/include/cru/ui/host/LayoutPaintCycler.h
@@ -1,7 +1,6 @@
#pragma once
#include "../Base.h"
-#include "cru/platform/gui/TimerHelper.h"
#include "cru/platform/gui/UiApplication.h"
#include <chrono>
diff --git a/include/cru/ui/render/ScrollBar.h b/include/cru/ui/render/ScrollBar.h
index 50b21386..13c7d8b0 100644
--- a/include/cru/ui/render/ScrollBar.h
+++ b/include/cru/ui/render/ScrollBar.h
@@ -6,7 +6,6 @@
#include "cru/platform/graphics/Geometry.h"
#include "cru/platform/graphics/Painter.h"
#include "cru/platform/gui/Cursor.h"
-#include "cru/platform/gui/TimerHelper.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/Base.h"
#include "cru/ui/controls/Control.h"
diff --git a/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp b/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp
index 5f046a44..c44b4723 100644
--- a/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp
@@ -67,7 +67,7 @@ void BorderStylerEditor::SetValue(ui::style::BorderStyler* styler,
if (border_style.border_brush.has_value()) {
brush_editor_.GetEditor()->SetValue(
std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
- border_style.border_brush.value())
+ *border_style.border_brush)
->GetColor(),
false);
}
@@ -77,7 +77,7 @@ void BorderStylerEditor::SetValue(ui::style::BorderStyler* styler,
if (border_style.foreground_brush.has_value()) {
foreground_brush_editor_.GetEditor()->SetValue(
std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
- border_style.foreground_brush.value())
+ *border_style.foreground_brush)
->GetColor(),
false);
}
@@ -87,7 +87,7 @@ void BorderStylerEditor::SetValue(ui::style::BorderStyler* styler,
if (border_style.background_brush.has_value()) {
background_brush_editor_.GetEditor()->SetValue(
std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
- border_style.background_brush.value())
+ *border_style.background_brush)
->GetColor(),
false);
}
diff --git a/src/base/platform/unix/EventLoop.cpp b/src/base/platform/unix/EventLoop.cpp
index 200f6abb..6c43213f 100644
--- a/src/base/platform/unix/EventLoop.cpp
+++ b/src/base/platform/unix/EventLoop.cpp
@@ -57,7 +57,7 @@ int UnixEventLoop::Run() {
}
}
- return exit_code_.value();
+ return *exit_code_;
}
void UnixEventLoop::RequestQuit(int exit_code) {
diff --git a/src/platform/gui/osx/Window.mm b/src/platform/gui/osx/Window.mm
index 5f655185..167adfc5 100644
--- a/src/platform/gui/osx/Window.mm
+++ b/src/platform/gui/osx/Window.mm
@@ -9,7 +9,6 @@
#include "cru/platform/graphics/NullPainter.h"
#include "cru/platform/graphics/quartz/Painter.h"
#include "cru/platform/gui/Input.h"
-#include "cru/platform/gui/TimerHelper.h"
#include "cru/platform/gui/osx/Cursor.h"
#include "cru/platform/gui/osx/InputMethod.h"
#include "cru/platform/gui/osx/Keyboard.h"
diff --git a/src/platform/gui/osx/WindowPrivate.h b/src/platform/gui/osx/WindowPrivate.h
index 94b7e948..c16a2b02 100644
--- a/src/platform/gui/osx/WindowPrivate.h
+++ b/src/platform/gui/osx/WindowPrivate.h
@@ -2,7 +2,7 @@
#include "cru/platform/gui/osx/Window.h"
#include "cru/base/Event.h"
-#include "cru/platform/gui/TimerHelper.h"
+#include "cru/platform/gui/UiApplication.h"
#include "cru/platform/gui/osx/Cursor.h"
#import <AppKit/AppKit.h>
diff --git a/src/platform/gui/xcb/Input.cpp b/src/platform/gui/xcb/Input.cpp
index 3482d3ab..a07697ae 100644
--- a/src/platform/gui/xcb/Input.cpp
+++ b/src/platform/gui/xcb/Input.cpp
@@ -84,7 +84,7 @@ std::vector<xcb_keysym_t> XorgKeycodeToKeysyms(XcbUiApplication *application,
// Get keyboard mapping
auto mapping_cookie = xcb_get_keyboard_mapping(connection, keycode, 1);
- auto mapping_reply = FreeLater(
+ auto mapping_reply = AutoFreePtr(
xcb_get_keyboard_mapping_reply(connection, mapping_cookie, NULL));
if (!mapping_reply) {
@@ -121,7 +121,7 @@ using KeymapBitset =
KeymapBitset GetXorgKeymap(xcb_connection_t *connection) {
auto keymap_cookie = xcb_query_keymap(connection);
auto keymap_reply =
- FreeLater(xcb_query_keymap_reply(connection, keymap_cookie, NULL));
+ AutoFreePtr(xcb_query_keymap_reply(connection, keymap_cookie, NULL));
if (!keymap_reply) {
throw XcbException("Cannot get keymap.");
@@ -150,7 +150,7 @@ std::unordered_map<KeyCode, bool> GetKeyboardState(
// Get keyboard mapping
auto mapping_cookie = xcb_get_keyboard_mapping(connection, min_keycode,
max_keycode - min_keycode + 1);
- auto mapping_reply = FreeLater(
+ auto mapping_reply = AutoFreePtr(
xcb_get_keyboard_mapping_reply(connection, mapping_cookie, NULL));
if (!mapping_reply) {
diff --git a/src/platform/gui/xcb/UiApplication.cpp b/src/platform/gui/xcb/UiApplication.cpp
index 436bb335..4c6afb23 100644
--- a/src/platform/gui/xcb/UiApplication.cpp
+++ b/src/platform/gui/xcb/UiApplication.cpp
@@ -87,7 +87,7 @@ xcb_atom_t XcbUiApplication::GetOrCreateXcbAtom(std::string name) {
auto cookie =
xcb_intern_atom(xcb_connection_, false, name.size(), name.data());
auto reply =
- FreeLater(xcb_intern_atom_reply(xcb_connection_, cookie, nullptr));
+ AutoFreePtr(xcb_intern_atom_reply(xcb_connection_, cookie, nullptr));
auto atom = reply->atom;
xcb_atom_.emplace(std::move(name), atom);
return atom;
diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp
index 44db5af3..9e1089c9 100644
--- a/src/platform/gui/xcb/Window.cpp
+++ b/src/platform/gui/xcb/Window.cpp
@@ -37,7 +37,7 @@ MouseButton ConvertMouseButton(xcb_button_t button) {
}
} // namespace
-XcbWindow::XcbWindow(XcbUiApplication *application)
+XcbWindow::XcbWindow(XcbUiApplication* application)
: application_(application),
xcb_window_(std::nullopt),
cairo_surface_(nullptr),
@@ -66,9 +66,9 @@ void XcbWindow::Close() {
}
}
-INativeWindow *XcbWindow::GetParent() { return parent_; }
+INativeWindow* XcbWindow::GetParent() { return parent_; }
-void XcbWindow::SetParent(INativeWindow *parent) {
+void XcbWindow::SetParent(INativeWindow* parent) {
parent_ = CheckPlatform<XcbWindow>(parent, GetPlatformId());
if (xcb_window_) {
DoSetParent(*xcb_window_);
@@ -104,7 +104,7 @@ constexpr int IconicState = 3;
WindowVisibilityType XcbWindow::GetVisibility() {
if (!xcb_window_) return WindowVisibilityType::Hide;
- auto value = static_cast<std::uint32_t *>(
+ auto value = static_cast<std::uint32_t*>(
XcbGetProperty(*xcb_window_, application_->GetXcbAtomWM_STATE(),
application_->GetXcbAtomWM_STATE(), 0, 1));
if (value != nullptr && *value == IconicState) {
@@ -134,7 +134,7 @@ void XcbWindow::SetVisibility(WindowVisibilityType visibility) {
UnreachableCode();
}
- auto old_value = static_cast<std::uint32_t *>(
+ auto old_value = static_cast<std::uint32_t*>(
XcbGetProperty(*xcb_window_, atom, atom, 0, 2));
if (old_value) value[1] = old_value[1];
@@ -177,7 +177,7 @@ void XcbWindow::SetVisibility(WindowVisibilityType visibility) {
Size XcbWindow::GetClientSize() { return GetClientRect().GetSize(); }
-void XcbWindow::SetClientSize(const Size &size) {
+void XcbWindow::SetClientSize(const Size& size) {
auto rect = GetClientRect();
SetClientRect(Rect(rect.GetLeftTop(), size));
}
@@ -190,14 +190,14 @@ Rect XcbWindow::GetClientRect() {
auto window = *xcb_window_;
auto cookie = xcb_get_geometry(application_->GetXcbConnection(), window);
- auto reply = FreeLater(xcb_get_geometry_reply(
+ auto reply = AutoFreePtr(xcb_get_geometry_reply(
application_->GetXcbConnection(), cookie, nullptr));
auto position = GetXcbWindowPosition(window);
return Rect(position.x, position.y, reply->width, reply->height);
}
-void XcbWindow::SetClientRect(const Rect &rect) {
+void XcbWindow::SetClientRect(const Rect& rect) {
if (!xcb_window_) return;
DoSetClientRect(*xcb_window_, rect);
application_->XcbFlush();
@@ -216,7 +216,7 @@ Rect XcbWindow::GetWindowRect() {
return client_rect;
}
-void XcbWindow::SetWindowRect(const Rect &rect) {
+void XcbWindow::SetWindowRect(const Rect& rect) {
if (!xcb_window_) return;
auto real_rect = rect;
@@ -240,7 +240,7 @@ bool XcbWindow::RequestFocus() {
Point XcbWindow::GetMousePosition() {
auto window = xcb_window_.value_or(application_->GetFirstXcbScreen()->root);
auto cookie = xcb_query_pointer(application_->GetXcbConnection(), window);
- auto reply = FreeLater(xcb_query_pointer_reply(
+ auto reply = AutoFreePtr(xcb_query_pointer_reply(
application_->GetXcbConnection(), cookie, nullptr));
return Point(reply->win_x, reply->win_y);
}
@@ -295,57 +295,59 @@ std::unique_ptr<graphics::IPainter> XcbWindow::BeginPaint() {
}
auto factory = application_->GetCairoFactory();
- cairo_t *cairo = cairo_create(cairo_surface_);
+ cairo_t* cairo = cairo_create(cairo_surface_);
auto painter =
new graphics::cairo::CairoPainter(factory, cairo, true, cairo_surface_);
return std::unique_ptr<graphics::IPainter>(painter);
}
-IEvent<std::nullptr_t> *XcbWindow::CreateEvent() { return &create_event_; }
+IEvent<std::nullptr_t>* XcbWindow::CreateEvent() { return &create_event_; }
-IEvent<std::nullptr_t> *XcbWindow::DestroyEvent() { return &destroy_event_; }
+IEvent<std::nullptr_t>* XcbWindow::DestroyEvent() { return &destroy_event_; }
-IEvent<std::nullptr_t> *XcbWindow::PaintEvent() { return &paint_event_; }
+IEvent<std::nullptr_t>* XcbWindow::PaintEvent() { return &paint_event_; }
-IEvent<WindowVisibilityType> *XcbWindow::VisibilityChangeEvent() {
+IEvent<WindowVisibilityType>* XcbWindow::VisibilityChangeEvent() {
return &visibility_change_event_;
}
-IEvent<const Size&> *XcbWindow::ResizeEvent() { return &resize_event_; }
+IEvent<const Size&>* XcbWindow::ResizeEvent() { return &resize_event_; }
-IEvent<FocusChangeType> *XcbWindow::FocusEvent() { return &focus_event_; }
+IEvent<FocusChangeType>* XcbWindow::FocusEvent() { return &focus_event_; }
-IEvent<MouseEnterLeaveType> *XcbWindow::MouseEnterLeaveEvent() {
+IEvent<MouseEnterLeaveType>* XcbWindow::MouseEnterLeaveEvent() {
return &mouse_enter_leave_event_;
}
-IEvent<const Point&> *XcbWindow::MouseMoveEvent() { return &mouse_move_event_; }
+IEvent<const Point&>* XcbWindow::MouseMoveEvent() { return &mouse_move_event_; }
-IEvent<const NativeMouseButtonEventArgs&> *XcbWindow::MouseDownEvent() {
+IEvent<const NativeMouseButtonEventArgs&>* XcbWindow::MouseDownEvent() {
return &mouse_down_event_;
}
-IEvent<const NativeMouseButtonEventArgs&> *XcbWindow::MouseUpEvent() {
+IEvent<const NativeMouseButtonEventArgs&>* XcbWindow::MouseUpEvent() {
return &mouse_up_event_;
}
-IEvent<const NativeMouseWheelEventArgs&> *XcbWindow::MouseWheelEvent() {
+IEvent<const NativeMouseWheelEventArgs&>* XcbWindow::MouseWheelEvent() {
return &mouse_wheel_event_;
}
-IEvent<const NativeKeyEventArgs&> *XcbWindow::KeyDownEvent() {
+IEvent<const NativeKeyEventArgs&>* XcbWindow::KeyDownEvent() {
return &key_down_event_;
}
-IEvent<const NativeKeyEventArgs&> *XcbWindow::KeyUpEvent() { return &key_up_event_; }
+IEvent<const NativeKeyEventArgs&>* XcbWindow::KeyUpEvent() {
+ return &key_up_event_;
+}
-IInputMethodContext *XcbWindow::GetInputMethodContext() {
+IInputMethodContext* XcbWindow::GetInputMethodContext() {
return input_method_;
}
std::optional<xcb_window_t> XcbWindow::GetXcbWindow() { return xcb_window_; }
-XcbUiApplication *XcbWindow::GetXcbUiApplication() { return application_; }
+XcbUiApplication* XcbWindow::GetXcbUiApplication() { return application_; }
bool XcbWindow::HasFocus() {
if (!xcb_window_) return false;
@@ -392,7 +394,7 @@ xcb_window_t XcbWindow::DoCreateWindow() {
DoSetParent(window);
DoSetCursor(window, cursor_.get());
- xcb_visualtype_t *visual_type;
+ xcb_visualtype_t* visual_type;
for (xcb_depth_iterator_t depth_iter =
xcb_screen_allowed_depths_iterator(screen);
@@ -417,7 +419,7 @@ xcb_window_t XcbWindow::DoCreateWindow() {
return window;
}
-void XcbWindow::HandleEvent(xcb_generic_event_t *event) {
+void XcbWindow::HandleEvent(xcb_generic_event_t* event) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE: {
RequestRepaint();
@@ -433,15 +435,15 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) {
if (application_->IsQuitOnAllWindowClosed() &&
std::ranges::none_of(
application_->GetAllWindow(),
- [](INativeWindow *window) { return window->IsCreated(); })) {
+ [](INativeWindow* window) { return window->IsCreated(); })) {
application_->RequestQuit(0);
}
break;
}
case XCB_CONFIGURE_NOTIFY: {
- xcb_configure_notify_event_t *configure =
- (xcb_configure_notify_event_t *)event;
+ xcb_configure_notify_event_t* configure =
+ (xcb_configure_notify_event_t*)event;
auto width = configure->width, height = configure->height;
if (width != current_size_.width || height != current_size_.height) {
CRU_LOG_TAG_DEBUG("{:#x} Size changed {} x {}.", *xcb_window_, width,
@@ -472,7 +474,7 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) {
break;
}
case XCB_BUTTON_PRESS: {
- xcb_button_press_event_t *bp = (xcb_button_press_event_t *)event;
+ xcb_button_press_event_t* bp = (xcb_button_press_event_t*)event;
if (bp->detail >= 4 && bp->detail <= 7) {
NativeMouseWheelEventArgs args(30, Point(bp->event_x, bp->event_y),
@@ -495,7 +497,7 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) {
break;
}
case XCB_BUTTON_RELEASE: {
- xcb_button_release_event_t *br = (xcb_button_release_event_t *)event;
+ xcb_button_release_event_t* br = (xcb_button_release_event_t*)event;
NativeMouseButtonEventArgs args(ConvertMouseButton(br->detail),
Point(br->event_x, br->event_y),
ConvertModifiersOfEvent(br->state));
@@ -503,13 +505,13 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) {
break;
}
case XCB_MOTION_NOTIFY: {
- xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)event;
+ xcb_motion_notify_event_t* motion = (xcb_motion_notify_event_t*)event;
Point point(motion->event_x, motion->event_y);
mouse_move_event_.Raise(point);
break;
}
case XCB_ENTER_NOTIFY: {
- xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *)event;
+ xcb_enter_notify_event_t* enter = (xcb_enter_notify_event_t*)event;
mouse_enter_leave_event_.Raise(MouseEnterLeaveType::Enter);
Point point(enter->event_x, enter->event_y);
mouse_move_event_.Raise(point);
@@ -524,25 +526,24 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) {
break;
}
case XCB_KEY_PRESS: {
- xcb_key_press_event_t *kp = (xcb_key_press_event_t *)event;
+ xcb_key_press_event_t* kp = (xcb_key_press_event_t*)event;
NativeKeyEventArgs args(XorgKeycodeToCruKeyCode(application_, kp->detail),
ConvertModifiersOfEvent(kp->state));
key_down_event_.Raise(std::move(args));
break;
}
case XCB_KEY_RELEASE: {
- xcb_key_release_event_t *kr = (xcb_key_release_event_t *)event;
+ xcb_key_release_event_t* kr = (xcb_key_release_event_t*)event;
NativeKeyEventArgs args(XorgKeycodeToCruKeyCode(application_, kr->detail),
ConvertModifiersOfEvent(kr->state));
key_up_event_.Raise(std::move(args));
break;
}
case XCB_CLIENT_MESSAGE: {
- xcb_client_message_event_t *cm = (xcb_client_message_event_t *)event;
+ xcb_client_message_event_t* cm = (xcb_client_message_event_t*)event;
if (cm->data.data32[0] == application_->GetXcbAtomWM_DELETE_WINDOW() &&
xcb_window_.has_value()) {
- xcb_destroy_window(application_->GetXcbConnection(),
- xcb_window_.value());
+ xcb_destroy_window(application_->GetXcbConnection(), *xcb_window_);
xcb_flush(application_->GetXcbConnection());
}
break;
@@ -553,67 +554,67 @@ void XcbWindow::HandleEvent(xcb_generic_event_t *event) {
}
std::optional<xcb_window_t> XcbWindow::GetEventWindow(
- xcb_generic_event_t *event) {
+ xcb_generic_event_t* event) {
switch (event->response_type & ~0x80) {
case XCB_EXPOSE: {
- xcb_expose_event_t *expose = (xcb_expose_event_t *)event;
+ xcb_expose_event_t* expose = (xcb_expose_event_t*)event;
return expose->window;
}
case XCB_DESTROY_NOTIFY: {
- xcb_destroy_notify_event_t *destroy = (xcb_destroy_notify_event_t *)event;
+ xcb_destroy_notify_event_t* destroy = (xcb_destroy_notify_event_t*)event;
return destroy->window;
}
case XCB_CONFIGURE_NOTIFY: {
- xcb_configure_notify_event_t *configure =
- (xcb_configure_notify_event_t *)event;
+ xcb_configure_notify_event_t* configure =
+ (xcb_configure_notify_event_t*)event;
return configure->window;
}
case XCB_MAP_NOTIFY: {
- xcb_map_notify_event_t *map = (xcb_map_notify_event_t *)event;
+ xcb_map_notify_event_t* map = (xcb_map_notify_event_t*)event;
return map->window;
}
case XCB_UNMAP_NOTIFY: {
- xcb_unmap_notify_event_t *unmap = (xcb_unmap_notify_event_t *)event;
+ xcb_unmap_notify_event_t* unmap = (xcb_unmap_notify_event_t*)event;
return unmap->window;
}
case XCB_FOCUS_IN: {
- xcb_focus_in_event_t *fi = (xcb_focus_in_event_t *)event;
+ xcb_focus_in_event_t* fi = (xcb_focus_in_event_t*)event;
return fi->event;
}
case XCB_FOCUS_OUT: {
- xcb_focus_out_event_t *fo = (xcb_focus_out_event_t *)event;
+ xcb_focus_out_event_t* fo = (xcb_focus_out_event_t*)event;
return fo->event;
}
case XCB_BUTTON_PRESS: {
- xcb_button_press_event_t *bp = (xcb_button_press_event_t *)event;
+ xcb_button_press_event_t* bp = (xcb_button_press_event_t*)event;
return bp->event;
}
case XCB_BUTTON_RELEASE: {
- xcb_button_release_event_t *br = (xcb_button_release_event_t *)event;
+ xcb_button_release_event_t* br = (xcb_button_release_event_t*)event;
return br->event;
}
case XCB_MOTION_NOTIFY: {
- xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)event;
+ xcb_motion_notify_event_t* motion = (xcb_motion_notify_event_t*)event;
return motion->event;
}
case XCB_ENTER_NOTIFY: {
- xcb_enter_notify_event_t *enter = (xcb_enter_notify_event_t *)event;
+ xcb_enter_notify_event_t* enter = (xcb_enter_notify_event_t*)event;
return enter->event;
}
case XCB_LEAVE_NOTIFY: {
- xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *)event;
+ xcb_leave_notify_event_t* leave = (xcb_leave_notify_event_t*)event;
return leave->event;
}
case XCB_KEY_PRESS: {
- xcb_key_press_event_t *kp = (xcb_key_press_event_t *)event;
+ xcb_key_press_event_t* kp = (xcb_key_press_event_t*)event;
return kp->event;
}
case XCB_KEY_RELEASE: {
- xcb_key_release_event_t *kr = (xcb_key_release_event_t *)event;
+ xcb_key_release_event_t* kr = (xcb_key_release_event_t*)event;
return kr->event;
}
case XCB_CLIENT_MESSAGE: {
- xcb_client_message_event_t *cm = (xcb_client_message_event_t *)event;
+ xcb_client_message_event_t* cm = (xcb_client_message_event_t*)event;
return cm->window;
}
default:
@@ -654,9 +655,9 @@ void XcbWindow::DoSetTitle(xcb_window_t window) {
}
}
-void XcbWindow::DoSetClientRect(xcb_window_t window, const Rect &rect) {
+void XcbWindow::DoSetClientRect(xcb_window_t window, const Rect& rect) {
auto tree_cookie = xcb_query_tree(application_->GetXcbConnection(), window);
- auto tree_reply = FreeLater(xcb_query_tree_reply(
+ auto tree_reply = AutoFreePtr(xcb_query_tree_reply(
application_->GetXcbConnection(), tree_cookie, nullptr));
auto parent_position = GetXcbWindowPosition(tree_reply->parent);
@@ -671,20 +672,20 @@ void XcbWindow::DoSetClientRect(xcb_window_t window, const Rect &rect) {
values);
}
-void XcbWindow::DoSetCursor(xcb_window_t window, XcbCursor *cursor) {
+void XcbWindow::DoSetCursor(xcb_window_t window, XcbCursor* cursor) {
std::uint32_t values[]{cursor ? cursor->GetXcbCursor() : XCB_CURSOR_NONE};
xcb_change_window_attributes(application_->GetXcbConnection(), window,
XCB_CW_CURSOR, values);
application_->XcbFlush();
}
-void *XcbWindow::XcbGetProperty(xcb_window_t window, xcb_atom_t property,
+void* XcbWindow::XcbGetProperty(xcb_window_t window, xcb_atom_t property,
xcb_atom_t type, std::uint32_t offset,
std::uint32_t length,
- std::uint32_t *out_length) {
+ std::uint32_t* out_length) {
auto cookie = xcb_get_property(application_->GetXcbConnection(), false,
window, property, type, offset, length);
- auto reply = FreeLater(
+ auto reply = AutoFreePtr(
xcb_get_property_reply(application_->GetXcbConnection(), cookie, NULL));
if (reply->type == XCB_ATOM_NONE) {
return nullptr;
@@ -696,7 +697,7 @@ void *XcbWindow::XcbGetProperty(xcb_window_t window, xcb_atom_t property,
}
std::optional<Thickness> XcbWindow::Get_NET_FRAME_EXTENTS(xcb_window_t window) {
- auto frame_properties = static_cast<std::uint32_t *>(
+ auto frame_properties = static_cast<std::uint32_t*>(
XcbGetProperty(window, application_->GetXcbAtom_NET_FRAME_EXTENTS(),
XCB_ATOM_CARDINAL, 0, 4));
@@ -713,13 +714,13 @@ Point XcbWindow::GetXcbWindowPosition(xcb_window_t window) {
while (true) {
auto cookie = xcb_get_geometry(application_->GetXcbConnection(), window);
- auto reply = FreeLater(xcb_get_geometry_reply(
+ auto reply = AutoFreePtr(xcb_get_geometry_reply(
application_->GetXcbConnection(), cookie, nullptr));
result.x += reply->x;
result.y += reply->y;
auto tree_cookie = xcb_query_tree(application_->GetXcbConnection(), window);
- auto tree_reply = FreeLater(xcb_query_tree_reply(
+ auto tree_reply = AutoFreePtr(xcb_query_tree_reply(
application_->GetXcbConnection(), tree_cookie, nullptr));
window = tree_reply->parent;
// TODO: Multi-screen offset?
diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp
index 18020032..c7803383 100644
--- a/src/ui/render/TextRenderObject.cpp
+++ b/src/ui/render/TextRenderObject.cpp
@@ -187,8 +187,7 @@ void TextRenderObject::Draw(platform::graphics::IPainter* painter) {
}
if (this->selection_range_.has_value()) {
- const auto&& rects =
- text_layout_->TextRangeRect(this->selection_range_.value());
+ const auto&& rects = text_layout_->TextRangeRect(*this->selection_range_);
for (const auto& rect : rects)
painter->FillRectangle(rect, this->GetSelectionBrush().get());
}