2019-09-04 18:26:26 +02:00
|
|
|
#pragma once
|
2022-06-14 16:45:45 +02:00
|
|
|
|
|
|
|
|
#include <FancyZonesLib/FancyZonesDataTypes.h>
|
2022-10-31 13:44:25 +02:00
|
|
|
#include <FancyZonesLib/Layout.h>
|
|
|
|
|
#include <FancyZonesLib/LayoutAssignedWindows.h>
|
2022-06-14 16:45:45 +02:00
|
|
|
#include <FancyZonesLib/util.h>
|
|
|
|
|
|
|
|
|
|
class ZonesOverlay;
|
|
|
|
|
|
|
|
|
|
class WorkArea
|
2019-09-04 18:26:26 +02:00
|
|
|
{
|
2022-06-14 16:45:45 +02:00
|
|
|
public:
|
2023-01-23 20:13:05 +03:00
|
|
|
WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesUtils::Rect& workAreaRect);
|
2022-06-14 16:45:45 +02:00
|
|
|
~WorkArea();
|
|
|
|
|
|
|
|
|
|
public:
|
2022-11-09 14:41:14 +00:00
|
|
|
inline bool Init([[maybe_unused]] HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& parentUniqueId)
|
2022-08-15 16:40:10 +03:00
|
|
|
{
|
|
|
|
|
#ifndef UNIT_TESTS
|
|
|
|
|
if (!InitWindow(hinstance))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
InitLayout(parentUniqueId);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 17:29:02 +02:00
|
|
|
FancyZonesDataTypes::WorkAreaId UniqueId() const noexcept { return { m_uniqueId }; }
|
2022-10-31 13:44:25 +02:00
|
|
|
const std::unique_ptr<Layout>& GetLayout() const noexcept { return m_layout; }
|
|
|
|
|
const std::unique_ptr<LayoutAssignedWindows>& GetLayoutWindows() const noexcept { return m_layoutWindows; }
|
2023-01-30 19:39:46 +03:00
|
|
|
const HWND GetWorkAreaWindow() const noexcept { return m_window; }
|
2022-06-14 16:45:45 +02:00
|
|
|
|
|
|
|
|
ZoneIndexSet GetWindowZoneIndexes(HWND window) const noexcept;
|
2022-11-09 14:41:14 +00:00
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
void MoveWindowIntoZoneByIndex(HWND window, ZoneIndex index) noexcept;
|
2022-11-22 17:58:22 +01:00
|
|
|
void MoveWindowIntoZoneByIndexSet(HWND window, const ZoneIndexSet& indexSet, bool updatePosition = true) noexcept;
|
2022-06-14 16:45:45 +02:00
|
|
|
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;
|
2022-12-02 13:29:11 +03:00
|
|
|
bool UnsnapWindow(HWND window) noexcept;
|
2022-11-09 14:41:14 +00:00
|
|
|
|
2022-06-14 16:45:45 +02:00
|
|
|
void UpdateActiveZoneSet() noexcept;
|
|
|
|
|
|
2023-01-30 19:39:46 +03:00
|
|
|
void ShowZonesOverlay(const ZoneIndexSet& highlight, HWND draggedWindow = nullptr);
|
|
|
|
|
void HideZonesOverlay();
|
|
|
|
|
void FlashZones();
|
2022-06-14 16:45:45 +02:00
|
|
|
|
2022-10-31 13:44:25 +02:00
|
|
|
void CycleWindows(HWND window, bool reverse) noexcept;
|
2022-06-14 16:45:45 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
|
|
|
|
|
|
|
|
|
private:
|
2022-08-15 16:40:10 +03:00
|
|
|
bool InitWindow(HINSTANCE hinstance) noexcept;
|
|
|
|
|
void InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept;
|
2022-10-31 13:44:25 +02:00
|
|
|
void CalculateZoneSet() noexcept;
|
2022-06-14 16:45:45 +02:00
|
|
|
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
2023-01-30 19:39:46 +03:00
|
|
|
void SetWorkAreaWindowAsTopmost(HWND draggedWindow) noexcept;
|
2022-06-14 16:45:45 +02:00
|
|
|
|
2023-01-23 20:13:05 +03:00
|
|
|
const FancyZonesUtils::Rect m_workAreaRect{};
|
2022-08-15 16:40:10 +03:00
|
|
|
const FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
2022-06-14 16:45:45 +02:00
|
|
|
HWND m_window{}; // Hidden tool window used to represent current monitor desktop work area.
|
2022-10-31 13:44:25 +02:00
|
|
|
std::unique_ptr<Layout> m_layout;
|
|
|
|
|
std::unique_ptr<LayoutAssignedWindows> m_layoutWindows;
|
2022-06-14 16:45:45 +02:00
|
|
|
std::unique_ptr<ZonesOverlay> m_zonesOverlay;
|
2019-09-04 18:26:26 +02:00
|
|
|
};
|
|
|
|
|
|
2023-01-23 20:13:05 +03:00
|
|
|
inline std::shared_ptr<WorkArea> MakeWorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId, const FancyZonesUtils::Rect& workAreaRect)
|
2022-06-14 16:45:45 +02:00
|
|
|
{
|
2023-01-23 20:13:05 +03:00
|
|
|
auto self = std::make_shared<WorkArea>(hinstance, uniqueId, workAreaRect);
|
2022-08-15 16:40:10 +03:00
|
|
|
if (!self->Init(hinstance, parentUniqueId))
|
2022-06-14 16:45:45 +02:00
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|