mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
[FancyZones] Improve code quality (part 5: work area initialization) (#23671)
This commit is contained in:
@@ -3,17 +3,27 @@
|
||||
#include <FancyZonesLib/FancyZonesDataTypes.h>
|
||||
#include <FancyZonesLib/Layout.h>
|
||||
#include <FancyZonesLib/LayoutAssignedWindows.h>
|
||||
#include <FancyZonesLib/util.h>
|
||||
|
||||
class ZonesOverlay;
|
||||
|
||||
class WorkArea
|
||||
{
|
||||
public:
|
||||
WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesUtils::Rect& workAreaRect);
|
||||
~WorkArea();
|
||||
|
||||
public:
|
||||
~WorkArea();
|
||||
|
||||
static std::unique_ptr<WorkArea> Create(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId, const FancyZonesUtils::Rect& workAreaRect)
|
||||
{
|
||||
auto self = std::unique_ptr<WorkArea>(new WorkArea(hinstance, uniqueId, workAreaRect));
|
||||
if (!self->Init(hinstance, parentUniqueId))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
inline bool Init([[maybe_unused]] HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& parentUniqueId)
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
@@ -23,42 +33,48 @@ public:
|
||||
}
|
||||
#endif
|
||||
InitLayout(parentUniqueId);
|
||||
InitSnappedWindows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
FancyZonesDataTypes::WorkAreaId UniqueId() const noexcept { return { m_uniqueId }; }
|
||||
const std::unique_ptr<Layout>& GetLayout() const noexcept { return m_layout; }
|
||||
const std::unique_ptr<LayoutAssignedWindows>& GetLayoutWindows() const noexcept { return m_layoutWindows; }
|
||||
const HWND GetWorkAreaWindow() const noexcept { return m_window; }
|
||||
|
||||
ZoneIndexSet GetWindowZoneIndexes(HWND window) const noexcept;
|
||||
ZoneIndexSet GetWindowZoneIndexes(HWND window) const;
|
||||
|
||||
void MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept;
|
||||
void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, bool updatePosition = true) noexcept;
|
||||
bool MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle) noexcept;
|
||||
bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle) noexcept;
|
||||
bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode) noexcept;
|
||||
void SaveWindowProcessToZoneIndex(HWND window) noexcept;
|
||||
bool UnsnapWindow(HWND window) noexcept;
|
||||
void MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index);
|
||||
void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, bool updatePosition = true);
|
||||
bool MoveWindowIntoZoneByDirectionAndIndex(HWND window, DWORD vkCode, bool cycle);
|
||||
bool MoveWindowIntoZoneByDirectionAndPosition(HWND window, DWORD vkCode, bool cycle);
|
||||
bool ExtendWindowByDirectionAndPosition(HWND window, DWORD vkCode);
|
||||
|
||||
void UpdateActiveZoneSet() noexcept;
|
||||
void SnapWindow(HWND window, const ZoneIndexSet& zones);
|
||||
void UnsnapWindow(HWND window);
|
||||
|
||||
void UpdateActiveZoneSet();
|
||||
|
||||
void ShowZonesOverlay(const ZoneIndexSet& highlight, HWND draggedWindow = nullptr);
|
||||
void HideZonesOverlay();
|
||||
void FlashZones();
|
||||
|
||||
void CycleWindows(HWND window, bool reverse) noexcept;
|
||||
void CycleWindows(HWND window, bool reverse);
|
||||
|
||||
protected:
|
||||
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||
|
||||
private:
|
||||
bool InitWindow(HINSTANCE hinstance) noexcept;
|
||||
void InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept;
|
||||
void CalculateZoneSet() noexcept;
|
||||
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||
bool InitWindow(HINSTANCE hinstance);
|
||||
void InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId);
|
||||
void InitSnappedWindows();
|
||||
|
||||
void CalculateZoneSet();
|
||||
void SetWorkAreaWindowAsTopmost(HWND draggedWindow) noexcept;
|
||||
|
||||
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||
|
||||
const FancyZonesUtils::Rect m_workAreaRect{};
|
||||
const FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
||||
HWND m_window{}; // Hidden tool window used to represent current monitor desktop work area.
|
||||
@@ -66,14 +82,3 @@ private:
|
||||
std::unique_ptr<LayoutAssignedWindows> m_layoutWindows;
|
||||
std::unique_ptr<ZonesOverlay> m_zonesOverlay;
|
||||
};
|
||||
|
||||
inline std::shared_ptr<WorkArea> MakeWorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId, const FancyZonesUtils::Rect& workAreaRect)
|
||||
{
|
||||
auto self = std::make_shared<WorkArea>(hinstance, uniqueId, workAreaRect);
|
||||
if (!self->Init(hinstance, parentUniqueId))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user