diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/parse/RecursiveDescentAlgorithm.cpp | 1 | ||||
-rw-r--r-- | src/parse/RecursiveDescentAlgorithmContext.cpp | 1 | ||||
-rw-r--r-- | src/platform/graphics/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/platform/graphics/ForDllExport.cpp | 7 | ||||
-rw-r--r-- | src/toml/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/ui/components/Menu.cpp | 2 | ||||
-rw-r--r-- | src/ui/controls/TextHostControlService.cpp | 4 | ||||
-rw-r--r-- | src/ui/render/TextRenderObject.cpp | 1 | ||||
-rw-r--r-- | src/win/Exception.cpp | 6 | ||||
-rw-r--r-- | src/win/graphics/direct/Geometry.cpp | 2 | ||||
-rw-r--r-- | src/win/graphics/direct/Painter.cpp | 2 | ||||
-rw-r--r-- | src/win/gui/Window.cpp | 62 | ||||
-rw-r--r-- | src/xml/CMakeLists.txt | 1 |
14 files changed, 79 insertions, 14 deletions
diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt index 72bac707..17b26a3a 100644 --- a/src/parse/CMakeLists.txt +++ b/src/parse/CMakeLists.txt @@ -13,4 +13,5 @@ add_library(cru_parse SHARED Token.cpp TokenType.cpp ) +target_compile_definitions(cru_parse PRIVATE CRU_PARSE_EXPORT_API) target_link_libraries(cru_parse PUBLIC cru_base) diff --git a/src/parse/RecursiveDescentAlgorithm.cpp b/src/parse/RecursiveDescentAlgorithm.cpp index a6549f8a..8ff2571d 100644 --- a/src/parse/RecursiveDescentAlgorithm.cpp +++ b/src/parse/RecursiveDescentAlgorithm.cpp @@ -4,6 +4,7 @@ namespace cru::parse { bool RecursiveDescentAlgorithm::CanHandle(Grammar *grammar) const { + CRU_UNUSED(grammar); return true; } diff --git a/src/parse/RecursiveDescentAlgorithmContext.cpp b/src/parse/RecursiveDescentAlgorithmContext.cpp index 8de0abc4..acfd9eee 100644 --- a/src/parse/RecursiveDescentAlgorithmContext.cpp +++ b/src/parse/RecursiveDescentAlgorithmContext.cpp @@ -10,6 +10,7 @@ RecursiveDescentAlgorithmContext::~RecursiveDescentAlgorithmContext() = default; ParsingTreeNode* RecursiveDescentAlgorithmContext::Parse( const std::vector<Terminal*>& input) { + CRU_UNUSED(input) // TODO: Implement this. return nullptr; } diff --git a/src/platform/graphics/CMakeLists.txt b/src/platform/graphics/CMakeLists.txt index 7d86db40..692f8e70 100644 --- a/src/platform/graphics/CMakeLists.txt +++ b/src/platform/graphics/CMakeLists.txt @@ -1,5 +1,6 @@ set(CRU_PLATFORM_GRAPHICS_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/platform/graphics) add_library(cru_platform_graphics SHARED + ForDllExport.cpp NullPainter.cpp ) target_sources(cru_platform_graphics PUBLIC @@ -14,4 +15,5 @@ target_sources(cru_platform_graphics PUBLIC ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/TextLayout.hpp ${CRU_PLATFORM_GRAPHICS_INCLUDE_DIR}/util/Painter.hpp ) +target_compile_definitions(cru_platform_graphics PRIVATE CRU_PLATFORM_GRAPHICS_EXPORT_API) target_link_libraries(cru_platform_graphics PUBLIC cru_platform_base) diff --git a/src/platform/graphics/ForDllExport.cpp b/src/platform/graphics/ForDllExport.cpp new file mode 100644 index 00000000..1a571365 --- /dev/null +++ b/src/platform/graphics/ForDllExport.cpp @@ -0,0 +1,7 @@ +#include "cru/platform/graphics/Brush.hpp" +#include "cru/platform/graphics/Factory.hpp" +#include "cru/platform/graphics/Font.hpp" +#include "cru/platform/graphics/Geometry.hpp" +#include "cru/platform/graphics/Painter.hpp" +#include "cru/platform/graphics/Resource.hpp" +#include "cru/platform/graphics/TextLayout.hpp" diff --git a/src/toml/CMakeLists.txt b/src/toml/CMakeLists.txt index 0285b454..be04ad79 100644 --- a/src/toml/CMakeLists.txt +++ b/src/toml/CMakeLists.txt @@ -2,4 +2,5 @@ add_library(cru_toml SHARED TomlDocument.cpp TomlParser.cpp ) +target_compile_definitions(cru_toml PRIVATE CRU_TOML_EXPORT_API) target_link_libraries(cru_toml PUBLIC cru_base) diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp index 681b44b7..05324865 100644 --- a/src/ui/components/Menu.cpp +++ b/src/ui/components/Menu.cpp @@ -92,7 +92,7 @@ PopupMenu::PopupMenu(controls::Control* attached_control) menu_ = new Menu(); - menu_->SetOnItemClick([this](Index _) { this->Close(); }); + menu_->SetOnItemClick([this](Index) { this->Close(); }); popup_->AddChild(menu_->GetRootControl(), 0); } diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index 7fcf70e9..0f136034 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -87,7 +87,7 @@ TextControlMovePattern TextControlMovePattern::kHome( gsl::index current_position) { CRU_UNUSED(service) return Utf16BackwardUntil(text, current_position, - [](char16_t c) { return c == u'\n'; }); + [](CodePoint c) { return c == u'\n'; }); }); TextControlMovePattern TextControlMovePattern::kEnd( u"End(Line End)", helper::ShortcutKeyBind(platform::gui::KeyCode::End), @@ -95,7 +95,7 @@ TextControlMovePattern TextControlMovePattern::kEnd( gsl::index current_position) { CRU_UNUSED(service) return Utf16ForwardUntil(text, current_position, - [](char16_t c) { return c == u'\n'; }); + [](CodePoint c) { return c == u'\n'; }); }); TextControlMovePattern TextControlMovePattern::kCtrlHome( u"Ctrl+Home(Document Begin)", diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index 0e65da92..f7665beb 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -147,7 +147,6 @@ Rect TextRenderObject::GetCaretRectInContent() { const auto caret_top_center = this->text_layout_->TextSinglePoint(caret_pos, false); - const auto font_height = this->font_->GetFontSize(); const auto caret_width = this->caret_width_; auto rect = Rect{caret_top_center.left - caret_width / 2.0f, diff --git a/src/win/Exception.cpp b/src/win/Exception.cpp index cf55c191..2664b092 100644 --- a/src/win/Exception.cpp +++ b/src/win/Exception.cpp @@ -7,9 +7,9 @@ namespace cru::platform::win { inline String HResultMakeMessage(HRESULT h_result, std::optional<String> message) { if (message.has_value()) - return Format(L"HRESULT: {}. Message: {}", h_result, message->WinCStr()); + return Format(u"HRESULT: {}. Message: {}", h_result, message->WinCStr()); else - return Format(L"HRESULT: {}.", h_result); + return Format(u"HRESULT: {}.", h_result); } HResultError::HResultError(HRESULT h_result) @@ -24,7 +24,7 @@ HResultError::HResultError(HRESULT h_result, h_result_(h_result) {} inline String Win32MakeMessage(DWORD error_code, String message) { - return Format(L"Last error code: {}.\nMessage: {}\n", error_code, + return Format(u"Last error code: {}.\nMessage: {}\n", error_code, message.WinCStr()); } diff --git a/src/win/graphics/direct/Geometry.cpp b/src/win/graphics/direct/Geometry.cpp index 2a544859..b37dd9f4 100644 --- a/src/win/graphics/direct/Geometry.cpp +++ b/src/win/graphics/direct/Geometry.cpp @@ -13,7 +13,7 @@ D2DGeometryBuilder::D2DGeometryBuilder(DirectGraphicsFactory* factory) void D2DGeometryBuilder::CheckValidation() { if (!IsValid()) - throw ReuseException(L"The geometry builder is already disposed."); + throw ReuseException(u"The geometry builder is already disposed."); } void D2DGeometryBuilder::BeginFigure(const Point& point) { diff --git a/src/win/graphics/direct/Painter.cpp b/src/win/graphics/direct/Painter.cpp index 5db60fd1..1a43d1d0 100644 --- a/src/win/graphics/direct/Painter.cpp +++ b/src/win/graphics/direct/Painter.cpp @@ -146,7 +146,7 @@ void D2DPainter::EndDraw() { void D2DPainter::CheckValidation() { if (!is_drawing_) { throw cru::platform::ReuseException( - L"Can't do that on painter after end drawing."); + u"Can't do that on painter after end drawing."); } } } // namespace cru::platform::graphics::win::direct diff --git a/src/win/gui/Window.cpp b/src/win/gui/Window.cpp index 20f86aff..827cc0a8 100644 --- a/src/win/gui/Window.cpp +++ b/src/win/gui/Window.cpp @@ -15,6 +15,7 @@ #include "cru/win/gui/WindowClass.hpp" #include <windowsx.h> +#include <winuser.h> namespace cru::platform::gui::win { namespace { @@ -47,6 +48,21 @@ Rect CalcWindowRectFromClient(const Rect& rect, WindowStyleFlag style_flag, return result; } +Rect CalcClientRectFromWindow(const Rect& rect, WindowStyleFlag style_flag, + float dpi) { + RECT o{100, 100, 500, 500}; + RECT s = o; + if (!AdjustWindowRectEx(&s, CalcWindowStyle(style_flag), FALSE, 0)) + throw Win32Error(::GetLastError(), "Failed to invoke AdjustWindowRectEx."); + + Rect result = rect; + result.Shrink(Thickness(PixelToDip(s.left - o.left, dpi), + PixelToDip(o.top - s.top, dpi), + PixelToDip(s.right - o.right, dpi), + PixelToDip(s.bottom - o.bottom, dpi))); + + return result; +} } // namespace WinNativeWindow::WinNativeWindow(WinUiApplication* application) @@ -60,6 +76,15 @@ void WinNativeWindow::Close() { if (hwnd_) ::DestroyWindow(hwnd_); } +void WinNativeWindow::SetParent(INativeWindow *parent) { + auto p = CheckPlatform<WinNativeWindow>(parent, GetPlatformId()); + parent_window_ = p; + + if (hwnd_) { + ::SetParent(hwnd_, parent_window_->hwnd_); + } +} + void WinNativeWindow::SetStyleFlag(WindowStyleFlag flag) { if (flag == style_flag_) return; @@ -108,11 +133,11 @@ void WinNativeWindow::SetClientRect(const Rect& rect) { client_rect_ = rect; if (hwnd_) { - RECT rect = + RECT r = DipToPixel(CalcWindowRectFromClient(client_rect_, style_flag_, dpi_)); - if (!SetWindowPos(hwnd_, nullptr, 0, 0, rect.right - rect.left, - rect.bottom - rect.top, SWP_NOZORDER | SWP_NOMOVE)) + if (!SetWindowPos(hwnd_, nullptr, 0, 0, r.right - r.left, r.bottom - r.top, + SWP_NOZORDER | SWP_NOMOVE)) throw Win32Error(::GetLastError(), "Failed to invoke SetWindowPos."); } } @@ -126,11 +151,13 @@ Rect WinNativeWindow::GetWindowRect() { return Rect::FromVertices(PixelToDip(rect.left), PixelToDip(rect.top), PixelToDip(rect.right), PixelToDip(rect.bottom)); } else { - return {}; + return CalcWindowRectFromClient(client_rect_, style_flag_, dpi_); } } void WinNativeWindow::SetWindowRect(const Rect& rect) { + client_rect_ = CalcClientRectFromWindow(rect, style_flag_, dpi_); + if (hwnd_) { if (!SetWindowPos(hwnd_, nullptr, DipToPixel(rect.left), DipToPixel(rect.top), DipToPixel(rect.GetRight()), @@ -139,6 +166,14 @@ void WinNativeWindow::SetWindowRect(const Rect& rect) { } } +bool WinNativeWindow::RequestFocus() { + if (hwnd_) { + SetFocus(hwnd_); + return true; + } + return false; +} + Point WinNativeWindow::GetMousePosition() { POINT p; if (!::GetCursorPos(&p)) @@ -193,7 +228,7 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) { if (GetVisibility() != WindowVisibilityType::Show) return; - auto lg = [](const std::u16string_view& reason) { + auto lg = [](StringView reason) { log::TagWarn( log_tag, u"Failed to set cursor because {} when window is visible. (We need to " @@ -348,6 +383,14 @@ bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg, return true; } return false; + case WM_CREATE: + OnCreateInternal(); + *result = 0; + return true; + case WM_MOVE: + OnMoveInternal(LOWORD(l_param), HIWORD(l_param)); + *result = 0; + return true; case WM_SIZE: OnResizeInternal(LOWORD(l_param), HIWORD(l_param)); *result = 0; @@ -427,6 +470,8 @@ void WinNativeWindow::RecreateWindow() { input_method_context_->DisableIME(); } +void WinNativeWindow::OnCreateInternal() { create_event_.Raise(nullptr); } + void WinNativeWindow::OnDestroyInternal() { destroy_event_.Raise(nullptr); application_->GetWindowManager()->UnregisterWindow(hwnd_); @@ -441,8 +486,15 @@ void WinNativeWindow::OnPaintInternal() { } } +void WinNativeWindow::OnMoveInternal(const int new_left, const int new_top) { + client_rect_.left = PixelToDip(new_left); + client_rect_.top = PixelToDip(new_top); +} + void WinNativeWindow::OnResizeInternal(const int new_width, const int new_height) { + client_rect_.width = PixelToDip(new_width); + client_rect_.height = PixelToDip(new_height); if (!(new_width == 0 && new_height == 0)) { window_render_target_->ResizeBuffer(new_width, new_height); resize_event_.Raise(Size{PixelToDip(new_width), PixelToDip(new_height)}); diff --git a/src/xml/CMakeLists.txt b/src/xml/CMakeLists.txt index 20e889ec..014e820c 100644 --- a/src/xml/CMakeLists.txt +++ b/src/xml/CMakeLists.txt @@ -2,4 +2,5 @@ add_library(cru_xml SHARED XmlNode.cpp XmlParser.cpp ) +target_compile_definitions(cru_xml PRIVATE CRU_XML_EXPORT_API) target_link_libraries(cru_xml PUBLIC cru_base) |