2019-09-04 18:26:26 +02:00
|
|
|
#pragma once
|
2022-06-14 16:45:45 +02:00
|
|
|
|
2022-10-31 13:44:25 +02:00
|
|
|
#include <FancyZonesLib/Layout.h>
|
|
|
|
|
#include <FancyZonesLib/LayoutAssignedWindows.h>
|
2022-06-14 16:45:45 +02:00
|
|
|
|
|
|
|
|
class ZonesOverlay;
|
|
|
|
|
|
|
|
|
|
class WorkArea
|
2019-09-04 18:26:26 +02:00
|
|
|
{
|
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
|
|
|
|
|
|
|
|
public:
|
2023-01-31 12:55:46 +03:00
|
|
|
~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;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2023-02-27 21:15:52 +01:00
|
|
|
|
2022-08-15 16:40:10 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
2023-01-31 12:55:46 +03:00
|
|
|
|
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; }
|
2023-08-22 15:57:45 +03:00
|
|
|
const LayoutAssignedWindows& GetLayoutWindows() const noexcept { return m_layoutWindows; }
|
2023-01-30 19:39:46 +03:00
|
|
|
const HWND GetWorkAreaWindow() const noexcept { return m_window; }
|
2023-02-27 21:15:52 +01:00
|
|
|
const GUID GetLayoutId() const noexcept;
|
2023-08-22 15:57:45 +03:00
|
|
|
const FancyZonesUtils::Rect& GetWorkAreaRect() const noexcept { return m_workAreaRect; }
|
2022-06-14 16:45:45 +02:00
|
|
|
|
2023-08-22 15:57:45 +03:00
|
|
|
void InitLayout();
|
|
|
|
|
void InitSnappedWindows();
|
2023-02-06 17:15:19 +01:00
|
|
|
void UpdateWindowPositions();
|
2022-06-14 16:45:45 +02:00
|
|
|
|
2023-08-22 15:57:45 +03:00
|
|
|
bool Snap(HWND window, const ZoneIndexSet& zones, bool updatePosition = true);
|
|
|
|
|
bool Unsnap(HWND window);
|
|
|
|
|
|
|
|
|
|
void ShowZones(const ZoneIndexSet& highlight, HWND draggedWindow = nullptr);
|
|
|
|
|
void HideZones();
|
2023-01-30 19:39:46 +03:00
|
|
|
void FlashZones();
|
2022-06-14 16:45:45 +02:00
|
|
|
|
2023-01-31 12:55:46 +03:00
|
|
|
void CycleWindows(HWND window, bool reverse);
|
2022-06-14 16:45:45 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
|
|
|
|
|
|
|
|
|
private:
|
2023-01-31 12:55:46 +03:00
|
|
|
bool InitWindow(HINSTANCE hinstance);
|
|
|
|
|
void InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId);
|
2023-02-27 21:15:52 +01:00
|
|
|
|
2023-01-31 12:55:46 +03:00
|
|
|
void CalculateZoneSet();
|
2023-01-30 19:39:46 +03:00
|
|
|
void SetWorkAreaWindowAsTopmost(HWND draggedWindow) noexcept;
|
2022-06-14 16:45:45 +02:00
|
|
|
|
2023-01-31 12:55:46 +03:00
|
|
|
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
|
|
|
|
|
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;
|
2023-08-22 15:57:45 +03:00
|
|
|
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
|
|
|
};
|