refactor(new_editor): continue architecture closeout
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
#include "Platform/Win32/EditorWindowManager.h"
|
||||
#include "Platform/Win32/WindowManager/Internal.h"
|
||||
|
||||
#include "Platform/Win32/WindowManager/CrossWindowDropInternal.h"
|
||||
#include "State/EditorContext.h"
|
||||
#include "Platform/Win32/EditorWindow.h"
|
||||
|
||||
#include <XCEditor/Workspace/UIEditorWindowWorkspaceController.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
namespace XCEngine::UI::Editor::App::Internal {
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -35,16 +37,16 @@ float ResolveWindowDpiScale(HWND hwnd) {
|
||||
|
||||
} // namespace
|
||||
|
||||
bool EditorWindowManager::IsGlobalTabDragActive() const {
|
||||
bool EditorWindowWorkspaceCoordinator::IsGlobalTabDragActive() const {
|
||||
return m_globalTabDragSession.active;
|
||||
}
|
||||
|
||||
bool EditorWindowManager::OwnsActiveGlobalTabDrag(std::string_view windowId) const {
|
||||
bool EditorWindowWorkspaceCoordinator::OwnsActiveGlobalTabDrag(std::string_view windowId) const {
|
||||
return m_globalTabDragSession.active &&
|
||||
m_globalTabDragSession.panelWindowId == windowId;
|
||||
}
|
||||
|
||||
void EditorWindowManager::BeginGlobalTabDragSession(
|
||||
void EditorWindowWorkspaceCoordinator::BeginGlobalTabDragSession(
|
||||
std::string_view panelWindowId,
|
||||
std::string_view sourceNodeId,
|
||||
std::string_view panelId,
|
||||
@@ -58,7 +60,7 @@ void EditorWindowManager::BeginGlobalTabDragSession(
|
||||
m_globalTabDragSession.dragHotspot = dragHotspot;
|
||||
}
|
||||
|
||||
bool EditorWindowManager::TryResolveGlobalTabDragHotspot(
|
||||
bool EditorWindowWorkspaceCoordinator::TryResolveGlobalTabDragHotspot(
|
||||
const EditorWindow& sourceWindow,
|
||||
std::string_view nodeId,
|
||||
std::string_view panelId,
|
||||
@@ -105,12 +107,12 @@ bool EditorWindowManager::TryResolveGlobalTabDragHotspot(
|
||||
return false;
|
||||
}
|
||||
|
||||
void EditorWindowManager::UpdateGlobalTabDragOwnerWindowPosition() {
|
||||
void EditorWindowWorkspaceCoordinator::UpdateGlobalTabDragOwnerWindowPosition() {
|
||||
if (!m_globalTabDragSession.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
EditorWindow* ownerWindow = FindWindow(m_globalTabDragSession.panelWindowId);
|
||||
EditorWindow* ownerWindow = m_hostRuntime.FindWindow(m_globalTabDragSession.panelWindowId);
|
||||
if (ownerWindow == nullptr || ownerWindow->GetHwnd() == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -138,12 +140,12 @@ void EditorWindowManager::UpdateGlobalTabDragOwnerWindowPosition() {
|
||||
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
void EditorWindowManager::ClearGlobalTabDragDropPreview() {
|
||||
void EditorWindowWorkspaceCoordinator::ClearGlobalTabDragDropPreview() {
|
||||
if (m_globalTabDragSession.previewWindowId.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (EditorWindow* previewWindow = FindWindow(m_globalTabDragSession.previewWindowId);
|
||||
if (EditorWindow* previewWindow = m_hostRuntime.FindWindow(m_globalTabDragSession.previewWindowId);
|
||||
previewWindow != nullptr) {
|
||||
previewWindow->ClearExternalDockHostDropPreview();
|
||||
previewWindow->InvalidateHostWindow();
|
||||
@@ -151,7 +153,7 @@ void EditorWindowManager::ClearGlobalTabDragDropPreview() {
|
||||
m_globalTabDragSession.previewWindowId.clear();
|
||||
}
|
||||
|
||||
void EditorWindowManager::UpdateGlobalTabDragDropPreview() {
|
||||
void EditorWindowWorkspaceCoordinator::UpdateGlobalTabDragDropPreview() {
|
||||
if (!m_globalTabDragSession.active) {
|
||||
return;
|
||||
}
|
||||
@@ -192,14 +194,14 @@ void EditorWindowManager::UpdateGlobalTabDragDropPreview() {
|
||||
m_globalTabDragSession.previewWindowId = std::string(targetWindow->GetWindowId());
|
||||
}
|
||||
|
||||
void EditorWindowManager::EndGlobalTabDragSession() {
|
||||
void EditorWindowWorkspaceCoordinator::EndGlobalTabDragSession() {
|
||||
if (!m_globalTabDragSession.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClearGlobalTabDragDropPreview();
|
||||
|
||||
if (EditorWindow* ownerWindow = FindWindow(m_globalTabDragSession.panelWindowId);
|
||||
if (EditorWindow* ownerWindow = m_hostRuntime.FindWindow(m_globalTabDragSession.panelWindowId);
|
||||
ownerWindow != nullptr) {
|
||||
if (GetCapture() == ownerWindow->GetHwnd()) {
|
||||
ReleaseCapture();
|
||||
@@ -210,12 +212,12 @@ void EditorWindowManager::EndGlobalTabDragSession() {
|
||||
m_globalTabDragSession = {};
|
||||
}
|
||||
|
||||
bool EditorWindowManager::HandleGlobalTabDragPointerMove(HWND hwnd) {
|
||||
bool EditorWindowWorkspaceCoordinator::HandleGlobalTabDragPointerMove(HWND hwnd) {
|
||||
if (!m_globalTabDragSession.active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const EditorWindow* ownerWindow = FindWindow(m_globalTabDragSession.panelWindowId);
|
||||
const EditorWindow* ownerWindow = m_hostRuntime.FindWindow(m_globalTabDragSession.panelWindowId);
|
||||
if (ownerWindow == nullptr || ownerWindow->GetHwnd() != hwnd) {
|
||||
return false;
|
||||
}
|
||||
@@ -229,35 +231,15 @@ bool EditorWindowManager::HandleGlobalTabDragPointerMove(HWND hwnd) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void EditorWindowManager::ProcessPendingGlobalTabDragStarts() {
|
||||
if (m_globalTabDragSession.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const std::unique_ptr<EditorWindow>& window : m_windows) {
|
||||
if (window == nullptr || window->GetHwnd() == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TryStartGlobalTabDrag(*window)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorWindowManager::TryStartGlobalTabDrag(EditorWindow& sourceWindow) {
|
||||
const std::optional<EditorWindowPendingTabDragStart> pending =
|
||||
sourceWindow.ConsumePendingTabDragStart();
|
||||
if (!pending.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EditorWindowWorkspaceCoordinator::TryStartGlobalTabDrag(
|
||||
EditorWindow& sourceWindow,
|
||||
const EditorWindowPanelTransferRequest& request) {
|
||||
POINT dragHotspot = BuildFallbackGlobalTabDragHotspot();
|
||||
TryResolveGlobalTabDragHotspot(
|
||||
sourceWindow,
|
||||
pending->nodeId,
|
||||
pending->panelId,
|
||||
pending->screenPoint,
|
||||
request.nodeId,
|
||||
request.panelId,
|
||||
request.screenPoint,
|
||||
dragHotspot);
|
||||
|
||||
if (sourceWindow.IsPrimary()) {
|
||||
@@ -266,8 +248,8 @@ bool EditorWindowManager::TryStartGlobalTabDrag(EditorWindow& sourceWindow) {
|
||||
const UIEditorWindowWorkspaceOperationResult result =
|
||||
windowWorkspaceController.DetachPanelToNewWindow(
|
||||
sourceWindow.GetWindowId(),
|
||||
pending->nodeId,
|
||||
pending->panelId);
|
||||
request.nodeId,
|
||||
request.panelId);
|
||||
if (result.status != UIEditorWindowWorkspaceOperationStatus::Changed) {
|
||||
LogRuntimeTrace(
|
||||
"drag",
|
||||
@@ -278,12 +260,12 @@ bool EditorWindowManager::TryStartGlobalTabDrag(EditorWindow& sourceWindow) {
|
||||
if (!SynchronizeWindowsFromController(
|
||||
windowWorkspaceController,
|
||||
result.targetWindowId,
|
||||
pending->screenPoint)) {
|
||||
request.screenPoint)) {
|
||||
LogRuntimeTrace("drag", "failed to synchronize detached drag window state");
|
||||
return false;
|
||||
}
|
||||
|
||||
EditorWindow* detachedWindow = FindWindow(result.targetWindowId);
|
||||
EditorWindow* detachedWindow = m_hostRuntime.FindWindow(result.targetWindowId);
|
||||
if (detachedWindow == nullptr || detachedWindow->GetHwnd() == nullptr) {
|
||||
LogRuntimeTrace("drag", "detached drag window was not created.");
|
||||
return false;
|
||||
@@ -292,15 +274,15 @@ bool EditorWindowManager::TryStartGlobalTabDrag(EditorWindow& sourceWindow) {
|
||||
BeginGlobalTabDragSession(
|
||||
detachedWindow->GetWindowId(),
|
||||
detachedWindow->GetWorkspaceController().GetWorkspace().root.nodeId,
|
||||
pending->panelId,
|
||||
pending->screenPoint,
|
||||
request.panelId,
|
||||
request.screenPoint,
|
||||
dragHotspot);
|
||||
UpdateGlobalTabDragOwnerWindowPosition();
|
||||
SetCapture(detachedWindow->GetHwnd());
|
||||
SetForegroundWindow(detachedWindow->GetHwnd());
|
||||
LogRuntimeTrace(
|
||||
"drag",
|
||||
"started global tab drag by detaching panel '" + pending->panelId +
|
||||
"started global tab drag by detaching panel '" + request.panelId +
|
||||
"' into window '" + std::string(detachedWindow->GetWindowId()) + "'");
|
||||
return true;
|
||||
}
|
||||
@@ -308,9 +290,9 @@ bool EditorWindowManager::TryStartGlobalTabDrag(EditorWindow& sourceWindow) {
|
||||
sourceWindow.ResetInteractionState();
|
||||
BeginGlobalTabDragSession(
|
||||
sourceWindow.GetWindowId(),
|
||||
pending->nodeId,
|
||||
pending->panelId,
|
||||
pending->screenPoint,
|
||||
request.nodeId,
|
||||
request.panelId,
|
||||
request.screenPoint,
|
||||
dragHotspot);
|
||||
UpdateGlobalTabDragOwnerWindowPosition();
|
||||
if (sourceWindow.GetHwnd() != nullptr) {
|
||||
@@ -320,8 +302,55 @@ bool EditorWindowManager::TryStartGlobalTabDrag(EditorWindow& sourceWindow) {
|
||||
"drag",
|
||||
"started global tab drag from detached window '" +
|
||||
std::string(sourceWindow.GetWindowId()) +
|
||||
"' panel '" + pending->panelId + "'");
|
||||
"' panel '" + request.panelId + "'");
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
EditorWindow* EditorWindowWorkspaceCoordinator::FindTopmostWindowAtScreenPoint(
|
||||
const POINT& screenPoint,
|
||||
std::string_view excludedWindowId) {
|
||||
if (const HWND hitWindow = WindowFromPoint(screenPoint); hitWindow != nullptr) {
|
||||
const HWND rootWindow = GetAncestor(hitWindow, GA_ROOT);
|
||||
if (EditorWindow* window = m_hostRuntime.FindWindow(rootWindow);
|
||||
window != nullptr &&
|
||||
window->GetWindowId() != excludedWindowId) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = m_hostRuntime.GetWindows().rbegin(); it != m_hostRuntime.GetWindows().rend(); ++it) {
|
||||
EditorWindow* const window = it->get();
|
||||
if (window == nullptr ||
|
||||
window->GetHwnd() == nullptr ||
|
||||
window->GetWindowId() == excludedWindowId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RECT windowRect = {};
|
||||
if (GetWindowRect(window->GetHwnd(), &windowRect) &&
|
||||
screenPoint.x >= windowRect.left &&
|
||||
screenPoint.x < windowRect.right &&
|
||||
screenPoint.y >= windowRect.top &&
|
||||
screenPoint.y < windowRect.bottom) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const EditorWindow* EditorWindowWorkspaceCoordinator::FindTopmostWindowAtScreenPoint(
|
||||
const POINT& screenPoint,
|
||||
std::string_view excludedWindowId) const {
|
||||
return const_cast<EditorWindowWorkspaceCoordinator*>(this)->FindTopmostWindowAtScreenPoint(
|
||||
screenPoint,
|
||||
excludedWindowId);
|
||||
}
|
||||
|
||||
void EditorWindowWorkspaceCoordinator::LogRuntimeTrace(
|
||||
std::string_view channel,
|
||||
std::string_view message) const {
|
||||
m_hostRuntime.LogRuntimeTrace(channel, message);
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App::Internal
|
||||
|
||||
Reference in New Issue
Block a user