aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui/win
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/gui/win')
-rw-r--r--src/platform/gui/win/Clipboard.cpp16
-rw-r--r--src/platform/gui/win/Cursor.cpp4
-rw-r--r--src/platform/gui/win/InputMethod.cpp27
-rw-r--r--src/platform/gui/win/Window.cpp39
4 files changed, 44 insertions, 42 deletions
diff --git a/src/platform/gui/win/Clipboard.cpp b/src/platform/gui/win/Clipboard.cpp
index 2a41a1eb..a269822d 100644
--- a/src/platform/gui/win/Clipboard.cpp
+++ b/src/platform/gui/win/Clipboard.cpp
@@ -11,25 +11,25 @@ WinClipboard::~WinClipboard() {}
std::string WinClipboard::GetText() {
if (!::OpenClipboard(nullptr)) {
- CRU_LOG_TAG_WARN("Failed to open clipboard.");
+ CruLogWarn(kLogTag, "Failed to open clipboard.");
return {};
}
if (!::IsClipboardFormatAvailable(CF_UNICODETEXT)) {
- CRU_LOG_TAG_WARN("Clipboard format for text is not available.");
+ CruLogWarn(kLogTag, "Clipboard format for text is not available.");
return {};
}
auto handle = ::GetClipboardData(CF_UNICODETEXT);
if (handle == nullptr) {
- CRU_LOG_TAG_WARN("Failed to get clipboard data.");
+ CruLogWarn(kLogTag, "Failed to get clipboard data.");
return {};
}
auto ptr = ::GlobalLock(handle);
if (ptr == nullptr) {
- CRU_LOG_TAG_WARN("Failed to lock clipboard data.");
+ CruLogWarn(kLogTag, "Failed to lock clipboard data.");
::CloseClipboard();
return {};
}
@@ -46,21 +46,21 @@ void WinClipboard::SetText(std::string utf8_text) {
auto text = string::ToUtf16WString(utf8_text);
if (!::OpenClipboard(nullptr)) {
- CRU_LOG_TAG_WARN("Failed to open clipboard.");
+ CruLogWarn(kLogTag, "Failed to open clipboard.");
return;
}
auto handle = GlobalAlloc(GMEM_MOVEABLE, (text.size() + 1) * sizeof(wchar_t));
if (handle == nullptr) {
- CRU_LOG_TAG_WARN("Failed to allocate clipboard data.");
+ CruLogWarn(kLogTag, "Failed to allocate clipboard data.");
::CloseClipboard();
return;
}
auto ptr = ::GlobalLock(handle);
if (ptr == nullptr) {
- CRU_LOG_TAG_WARN("Failed to lock clipboard data.");
+ CruLogWarn(kLogTag, "Failed to lock clipboard data.");
::GlobalFree(handle);
::CloseClipboard();
return;
@@ -71,7 +71,7 @@ void WinClipboard::SetText(std::string utf8_text) {
::GlobalUnlock(handle);
if (::SetClipboardData(CF_UNICODETEXT, handle) == nullptr) {
- CRU_LOG_TAG_WARN("Failed to set clipboard data.");
+ CruLogWarn(kLogTag, "Failed to set clipboard data.");
}
::CloseClipboard();
diff --git a/src/platform/gui/win/Cursor.cpp b/src/platform/gui/win/Cursor.cpp
index 0ed40416..b789c47b 100644
--- a/src/platform/gui/win/Cursor.cpp
+++ b/src/platform/gui/win/Cursor.cpp
@@ -14,8 +14,8 @@ WinCursor::~WinCursor() {
if (!::DestroyCursor(handle_)) {
// This is not a fetal error but might still need notice because it may
// cause leak.
- CRU_LOG_TAG_WARN("Failed to destroy a cursor. Last error code: {}",
- ::GetLastError());
+ CruLogWarn(kLogTag, "Failed to destroy a cursor. Last error code: {}",
+ ::GetLastError());
}
}
}
diff --git a/src/platform/gui/win/InputMethod.cpp b/src/platform/gui/win/InputMethod.cpp
index 3439df32..12f30297 100644
--- a/src/platform/gui/win/InputMethod.cpp
+++ b/src/platform/gui/win/InputMethod.cpp
@@ -30,7 +30,7 @@ AutoHIMC& AutoHIMC::operator=(AutoHIMC&& other) {
AutoHIMC::~AutoHIMC() {
if (handle_) {
if (!::ImmReleaseContext(hwnd_, handle_))
- CRU_LOG_TAG_WARN("Failed to release HIMC.");
+ CruLogWarn(kLogTag, "Failed to release HIMC.");
}
}
@@ -161,7 +161,7 @@ WinInputMethodContext::~WinInputMethodContext() {}
void WinInputMethodContext::EnableIME() {
const auto hwnd = native_window_->GetWindowHandle();
if (::ImmAssociateContextEx(hwnd, nullptr, IACE_DEFAULT) == FALSE) {
- CRU_LOG_TAG_WARN("Failed to enable ime.");
+ CruLogWarn(kLogTag, "Failed to enable ime.");
}
}
@@ -172,21 +172,21 @@ void WinInputMethodContext::DisableIME() {
::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
if (::ImmAssociateContextEx(hwnd, nullptr, 0) == FALSE) {
- CRU_LOG_TAG_WARN("Failed to disable ime.");
+ CruLogWarn(kLogTag, "Failed to disable ime.");
}
}
void WinInputMethodContext::CompleteComposition() {
auto himc = GetHIMC();
if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0)) {
- CRU_LOG_TAG_WARN("Failed to complete composition.");
+ CruLogWarn(kLogTag, "Failed to complete composition.");
}
}
void WinInputMethodContext::CancelComposition() {
auto himc = GetHIMC();
if (!::ImmNotifyIME(himc.Get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0)) {
- CRU_LOG_TAG_WARN("Failed to complete composition.");
+ CruLogWarn(kLogTag, "Failed to complete composition.");
}
}
@@ -205,7 +205,8 @@ void WinInputMethodContext::SetCandidateWindowPosition(const Point& point) {
form.ptCurrentPos = native_window_->DipToPixel(point);
if (!::ImmSetCandidateWindow(himc.Get(), &form))
- CRU_LOG_TAG_DEBUG("Failed to set input method candidate window position.");
+ CruLogDebug(kLogTag,
+ "Failed to set input method candidate window position.");
}
IEvent<std::nullptr_t>* WinInputMethodContext::CompositionStartEvent() {
@@ -234,9 +235,9 @@ void WinInputMethodContext::OnWindowNativeMessage(
// I don't think this will happen because normal key strike without ime
// should only trigger ascci character. If it is a charater from
// supplementary planes, it should be handled with ime messages.
- CRU_LOG_TAG_WARN(
- "A WM_CHAR message for character from supplementary "
- "planes is ignored.");
+ CruLogWarn(kLogTag,
+ "A WM_CHAR message for character from supplementary "
+ "planes is ignored.");
} else {
if (c != '\b') { // ignore backspace
if (c == '\r') c = '\n'; // Change \r to \n
@@ -249,8 +250,8 @@ void WinInputMethodContext::OnWindowNativeMessage(
case WM_IME_COMPOSITION: {
composition_event_.Raise(nullptr);
auto composition_text = GetCompositionText();
- CRU_LOG_TAG_DEBUG("WM_IME_COMPOSITION composition text: {}",
- composition_text.text);
+ CruLogDebug(kLogTag, "WM_IME_COMPOSITION composition text: {}",
+ composition_text.text);
if (message.l_param & GCS_RESULTSTR) {
auto result_string = GetResultString();
text_event_.Raise(result_string);
@@ -258,12 +259,12 @@ void WinInputMethodContext::OnWindowNativeMessage(
break;
}
case WM_IME_STARTCOMPOSITION: {
- CRU_LOG_TAG_DEBUG("WM_IME_STARTCOMPOSITION received.");
+ CruLogDebug(kLogTag, "WM_IME_STARTCOMPOSITION received.");
composition_start_event_.Raise(nullptr);
break;
}
case WM_IME_ENDCOMPOSITION: {
- CRU_LOG_TAG_DEBUG("WM_IME_ENDCOMPOSITION received.");
+ CruLogDebug(kLogTag, "WM_IME_ENDCOMPOSITION received.");
composition_end_event_.Raise(nullptr);
break;
}
diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp
index fb2ce024..f1138a78 100644
--- a/src/platform/gui/win/Window.cpp
+++ b/src/platform/gui/win/Window.cpp
@@ -136,8 +136,8 @@ void WinNativeWindow::SetVisibility(WindowVisibilityType visibility) {
Size WinNativeWindow::GetClientSize() { return GetClientRect().GetSize(); }
void WinNativeWindow::SetClientSize(const Size& size) {
- CRU_LOG_TAG_DEBUG("{} set client size to {}.",
- static_cast<void*>(GetWindowHandle()), size);
+ CruLogDebug(kLogTag, "{} set client size to {}.",
+ static_cast<void*>(GetWindowHandle()), size);
client_rect_.SetSize(size);
@@ -154,8 +154,8 @@ void WinNativeWindow::SetClientSize(const Size& size) {
Rect WinNativeWindow::GetClientRect() { return client_rect_; }
void WinNativeWindow::SetClientRect(const Rect& rect) {
- CRU_LOG_TAG_DEBUG("{} set client rect to {}.",
- static_cast<void*>(GetWindowHandle()), rect);
+ CruLogDebug(kLogTag, "{} set client rect to {}.",
+ static_cast<void*>(GetWindowHandle()), rect);
client_rect_ = rect;
@@ -183,8 +183,8 @@ Rect WinNativeWindow::GetWindowRect() {
}
void WinNativeWindow::SetWindowRect(const Rect& rect) {
- CRU_LOG_TAG_DEBUG("{} set window rect to {}.",
- static_cast<void*>(GetWindowHandle()), rect);
+ CruLogDebug(kLogTag, "{} set window rect to {}.",
+ static_cast<void*>(GetWindowHandle()), rect);
client_rect_ = CalcClientRectFromWindow(rect, style_flag_, dpi_);
@@ -223,7 +223,7 @@ bool WinNativeWindow::ReleaseMouse() {
}
void WinNativeWindow::RequestRepaint() {
- CRU_LOG_TAG_DEBUG("A repaint is requested.");
+ CruLogDebug(kLogTag, "A repaint is requested.");
if (!hwnd_) return;
if (!::InvalidateRect(hwnd_, nullptr, FALSE))
throw Win32Error(::GetLastError(), "Failed to invalidate window.");
@@ -250,17 +250,18 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) {
if (!::SetClassLongPtrW(hwnd_, GCLP_HCURSOR,
reinterpret_cast<LONG_PTR>(cursor_->GetHandle()))) {
- CRU_LOG_TAG_WARN(
- "Failed to set cursor because failed to set class long. Last "
- "error code: {}.",
- ::GetLastError());
+ CruLogWarn(kLogTag,
+ "Failed to set cursor because failed to set class long. Last "
+ "error code: {}.",
+ ::GetLastError());
return;
}
if (GetVisibility() != WindowVisibilityType::Show) return;
auto lg = [](std::string_view reason) {
- CRU_LOG_TAG_WARN(
+ CruLogWarn(
+ kLogTag,
"Failed to set cursor because {} when window is visible. (We need to "
"update cursor if it is inside the window.) Last error code: {}.",
reason, ::GetLastError());
@@ -488,8 +489,8 @@ void WinNativeWindow::RecreateWindow() {
if (dpi == 0)
throw Win32Error(::GetLastError(), "Failed to get dpi of window.");
dpi_ = static_cast<float>(dpi);
- CRU_LOG_TAG_DEBUG("Dpi of window {} is {}.",
- static_cast<void*>(GetWindowHandle()), dpi_);
+ CruLogDebug(kLogTag, "Dpi of window {} is {}.",
+ static_cast<void*>(GetWindowHandle()), dpi_);
application_->RegisterWindow(this);
@@ -508,14 +509,14 @@ void WinNativeWindow::RecreateWindow() {
}
void WinNativeWindow::OnCreateInternal() {
- CRU_LOG_TAG_DEBUG("A native window is created, hwnd {}.",
- static_cast<void*>(GetWindowHandle()));
+ CruLogDebug(kLogTag, "A native window is created, hwnd {}.",
+ static_cast<void*>(GetWindowHandle()));
CreateEvent_.Raise(nullptr);
}
void WinNativeWindow::OnDestroyInternal() {
- CRU_LOG_TAG_DEBUG("A native window is destroying, hwnd {}.",
- static_cast<void*>(GetWindowHandle()));
+ CruLogDebug(kLogTag, "A native window is destroying, hwnd {}.",
+ static_cast<void*>(GetWindowHandle()));
DestroyEvent_.Raise(nullptr);
hwnd_ = nullptr;
@@ -537,7 +538,7 @@ void WinNativeWindow::OnPaintInternal() {
}
Paint1Event_.Raise(args);
::ValidateRect(hwnd_, nullptr);
- CRU_LOG_TAG_DEBUG("A repaint is finished.");
+ CruLogDebug(kLogTag, "A repaint is finished.");
}
void WinNativeWindow::OnMoveInternal(const int new_left, const int new_top) {