97 lines
2.7 KiB
C++
97 lines
2.7 KiB
C++
#include "Platform/Win32/EditorWindowManager.h"
|
|
|
|
#include "State/EditorContext.h"
|
|
#include "Platform/Win32/EditorWindow.h"
|
|
|
|
#include <XCEditor/Foundation/UIEditorRuntimeTrace.h>
|
|
|
|
namespace XCEngine::UI::Editor::App {
|
|
|
|
EditorWindowManager::EditorWindowManager(
|
|
EditorWindowHostConfig hostConfig,
|
|
std::filesystem::path repoRoot,
|
|
EditorContext& editorContext)
|
|
: m_hostConfig(hostConfig),
|
|
m_repoRoot(std::move(repoRoot)),
|
|
m_editorContext(editorContext) {}
|
|
|
|
EditorWindowManager::~EditorWindowManager() = default;
|
|
|
|
void EditorWindowManager::Shutdown() {
|
|
for (const std::unique_ptr<EditorWindow>& window : m_windows) {
|
|
if (window != nullptr) {
|
|
DestroyEditorWindow(*window);
|
|
}
|
|
}
|
|
m_windows.clear();
|
|
m_pendingCreateWindow = nullptr;
|
|
m_globalTabDragSession = {};
|
|
}
|
|
|
|
bool EditorWindowManager::HasWindows() const {
|
|
return !m_windows.empty();
|
|
}
|
|
|
|
void EditorWindowManager::DestroyEditorWindow(EditorWindow& window) {
|
|
const HWND hwnd = window.GetHwnd();
|
|
if (GetCapture() == hwnd) {
|
|
ReleaseCapture();
|
|
}
|
|
|
|
window.Shutdown();
|
|
if (hwnd != nullptr && IsWindow(hwnd)) {
|
|
DestroyWindow(hwnd);
|
|
}
|
|
window.MarkDestroyed();
|
|
}
|
|
|
|
void EditorWindowManager::DestroyClosedWindows() {
|
|
for (auto it = m_windows.begin(); it != m_windows.end();) {
|
|
EditorWindow* const window = it->get();
|
|
if (window == nullptr || window->GetHwnd() != nullptr) {
|
|
++it;
|
|
continue;
|
|
}
|
|
|
|
if (m_pendingCreateWindow == window) {
|
|
m_pendingCreateWindow = nullptr;
|
|
}
|
|
|
|
window->Shutdown();
|
|
it = m_windows.erase(it);
|
|
}
|
|
}
|
|
|
|
void EditorWindowManager::RenderAllWindows() {
|
|
for (const std::unique_ptr<EditorWindow>& window : m_windows) {
|
|
if (window == nullptr || window->GetHwnd() == nullptr) {
|
|
continue;
|
|
}
|
|
|
|
window->RenderFrame(m_editorContext, IsGlobalTabDragActive());
|
|
}
|
|
}
|
|
|
|
void EditorWindowManager::HandleDestroyedWindow(HWND hwnd) {
|
|
if (EditorWindow* window = FindWindow(hwnd); window != nullptr) {
|
|
window->MarkDestroyed();
|
|
if (window->IsPrimary()) {
|
|
for (const std::unique_ptr<EditorWindow>& otherWindow : m_windows) {
|
|
if (otherWindow != nullptr &&
|
|
otherWindow.get() != window &&
|
|
otherWindow->GetHwnd() != nullptr) {
|
|
PostMessageW(otherWindow->GetHwnd(), WM_CLOSE, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void EditorWindowManager::LogRuntimeTrace(
|
|
std::string_view channel,
|
|
std::string_view message) const {
|
|
AppendUIEditorRuntimeTrace(channel, message);
|
|
}
|
|
|
|
} // namespace XCEngine::UI::Editor::App
|