mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Merge remote-tracking branch 'upstream/master' into locPowerRename
This commit is contained in:
@@ -558,22 +558,23 @@ namespace FancyZonesEditor
|
||||
|
||||
Settings settings = ((App)Application.Current).ZoneSettings;
|
||||
|
||||
int spacing = settings.ShowSpacing ? settings.Spacing : 0;
|
||||
int spacing, gutter;
|
||||
spacing = gutter = settings.ShowSpacing ? settings.Spacing : 0;
|
||||
|
||||
int cols = model.Columns;
|
||||
int rows = model.Rows;
|
||||
|
||||
double totalWidth = arrangeSize.Width - (spacing * (cols + 1));
|
||||
double totalHeight = arrangeSize.Height - (spacing * (rows + 1));
|
||||
double totalWidth = arrangeSize.Width - (gutter * 2) - (spacing * (cols - 1));
|
||||
double totalHeight = arrangeSize.Height - (gutter * 2) - (spacing * (rows - 1));
|
||||
|
||||
double top = spacing;
|
||||
double top = gutter;
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
double cellHeight = _rowInfo[row].Recalculate(top, totalHeight);
|
||||
top += cellHeight + spacing;
|
||||
}
|
||||
|
||||
double left = spacing;
|
||||
double left = gutter;
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
double cellWidth = _colInfo[col].Recalculate(left, totalWidth);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
mc:Ignorable="d"
|
||||
Background="LightGray"
|
||||
BorderThickness="1"
|
||||
BorderBrush="DarkGray"
|
||||
BorderBrush="SlateGray"
|
||||
Opacity="0.5"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid x:Name="Frame" Visibility="Collapsed">
|
||||
|
||||
@@ -98,98 +98,9 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderActualScalePriview(GridLayoutModel grid)
|
||||
{
|
||||
int rows = grid.Rows;
|
||||
int cols = grid.Columns;
|
||||
|
||||
RowColInfo[] rowInfo = new RowColInfo[rows];
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
rowInfo[row] = new RowColInfo(grid.RowPercents[row]);
|
||||
}
|
||||
|
||||
RowColInfo[] colInfo = new RowColInfo[cols];
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
colInfo[col] = new RowColInfo(grid.ColumnPercents[col]);
|
||||
}
|
||||
|
||||
Settings settings = ((App)Application.Current).ZoneSettings;
|
||||
|
||||
int spacing = settings.ShowSpacing ? settings.Spacing : 0;
|
||||
|
||||
int width = (int)SystemParameters.WorkArea.Width;
|
||||
int height = (int)SystemParameters.WorkArea.Height;
|
||||
|
||||
double totalWidth = width - (spacing * (cols + 1));
|
||||
double totalHeight = height - (spacing * (rows + 1));
|
||||
|
||||
double top = spacing;
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
double cellHeight = rowInfo[row].Recalculate(top, totalHeight);
|
||||
top += cellHeight + spacing;
|
||||
}
|
||||
|
||||
double left = spacing;
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
double cellWidth = colInfo[col].Recalculate(left, totalWidth);
|
||||
left += cellWidth + spacing;
|
||||
}
|
||||
|
||||
Viewbox viewbox = new Viewbox
|
||||
{
|
||||
Stretch = Stretch.Uniform,
|
||||
};
|
||||
Body.Children.Add(viewbox);
|
||||
Canvas frame = new Canvas
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
};
|
||||
viewbox.Child = frame;
|
||||
|
||||
for (int row = 0; row < rows; row++)
|
||||
{
|
||||
for (int col = 0; col < cols; col++)
|
||||
{
|
||||
int i = grid.CellChildMap[row, col];
|
||||
if (((row == 0) || (grid.CellChildMap[row - 1, col] != i)) &&
|
||||
((col == 0) || (grid.CellChildMap[row, col - 1] != i)))
|
||||
{
|
||||
Rectangle rect = new Rectangle();
|
||||
left = colInfo[col].Start;
|
||||
top = rowInfo[row].Start;
|
||||
Canvas.SetTop(rect, top);
|
||||
Canvas.SetLeft(rect, left);
|
||||
|
||||
int maxRow = row;
|
||||
while (((maxRow + 1) < rows) && (grid.CellChildMap[maxRow + 1, col] == i))
|
||||
{
|
||||
maxRow++;
|
||||
}
|
||||
|
||||
int maxCol = col;
|
||||
while (((maxCol + 1) < cols) && (grid.CellChildMap[row, maxCol + 1] == i))
|
||||
{
|
||||
maxCol++;
|
||||
}
|
||||
|
||||
rect.Width = colInfo[maxCol].End - left;
|
||||
rect.Height = rowInfo[maxRow].End - top;
|
||||
rect.StrokeThickness = 1;
|
||||
rect.Stroke = Brushes.DarkGray;
|
||||
rect.Fill = Brushes.LightGray;
|
||||
frame.Children.Add(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderSmallScalePriview(GridLayoutModel grid)
|
||||
private void RenderGridPreview(GridLayoutModel grid)
|
||||
{
|
||||
Body.RowDefinitions.Clear();
|
||||
foreach (int percent in grid.RowPercents)
|
||||
{
|
||||
RowDefinition def = new RowDefinition
|
||||
@@ -199,6 +110,7 @@ namespace FancyZonesEditor
|
||||
Body.RowDefinitions.Add(def);
|
||||
}
|
||||
|
||||
Body.ColumnDefinitions.Clear();
|
||||
foreach (int percent in grid.ColumnPercents)
|
||||
{
|
||||
ColumnDefinition def = new ColumnDefinition
|
||||
@@ -209,7 +121,8 @@ namespace FancyZonesEditor
|
||||
}
|
||||
|
||||
Settings settings = ((App)Application.Current).ZoneSettings;
|
||||
Thickness margin = new Thickness(settings.ShowSpacing ? settings.Spacing / 20 : 0);
|
||||
int divisor = IsActualSize ? 2 : 20;
|
||||
Thickness margin = new Thickness(settings.ShowSpacing ? settings.Spacing / divisor : 0);
|
||||
|
||||
List<int> visited = new List<int>();
|
||||
|
||||
@@ -224,25 +137,25 @@ namespace FancyZonesEditor
|
||||
Rectangle rect = new Rectangle();
|
||||
Grid.SetRow(rect, row);
|
||||
Grid.SetColumn(rect, col);
|
||||
int rowSpan = 1;
|
||||
int span = 1;
|
||||
int walk = row + 1;
|
||||
while ((walk < grid.Rows) && grid.CellChildMap[walk, col] == childIndex)
|
||||
{
|
||||
rowSpan++;
|
||||
span++;
|
||||
walk++;
|
||||
}
|
||||
|
||||
Grid.SetRowSpan(rect, rowSpan);
|
||||
Grid.SetRowSpan(rect, span);
|
||||
|
||||
int columnSpan = 1;
|
||||
span = 1;
|
||||
walk = col + 1;
|
||||
while ((walk < grid.Columns) && grid.CellChildMap[row, walk] == childIndex)
|
||||
{
|
||||
columnSpan++;
|
||||
span++;
|
||||
walk++;
|
||||
}
|
||||
|
||||
Grid.SetColumnSpan(rect, columnSpan);
|
||||
Grid.SetColumnSpan(rect, span);
|
||||
|
||||
rect.Margin = margin;
|
||||
rect.StrokeThickness = 1;
|
||||
@@ -254,20 +167,6 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderGridPreview(GridLayoutModel grid)
|
||||
{
|
||||
Body.RowDefinitions.Clear();
|
||||
Body.ColumnDefinitions.Clear();
|
||||
if (IsActualSize)
|
||||
{
|
||||
RenderActualScalePriview(grid);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSmallScalePriview(grid);
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderCanvasPreview(CanvasLayoutModel canvas)
|
||||
{
|
||||
Body.RowDefinitions.Clear();
|
||||
|
||||
@@ -49,7 +49,7 @@ IFACEMETHODIMP_(winrt::com_ptr<IZone>) ZoneSet::ZoneFromPoint(POINT pt) noexcept
|
||||
winrt::com_ptr<IZone> smallestKnownZone = nullptr;
|
||||
// To reduce redundant calculations, we will store the last known zones area.
|
||||
int smallestKnownZoneArea = INT32_MAX;
|
||||
for (auto iter = m_zones.begin(); iter != m_zones.end(); iter++)
|
||||
for (auto iter = m_zones.rbegin(); iter != m_zones.rend(); iter++)
|
||||
{
|
||||
if (winrt::com_ptr<IZone> zone = iter->try_as<IZone>())
|
||||
{
|
||||
|
||||
@@ -553,7 +553,7 @@ void ZoneWindow::DrawActiveZoneSet(wil::unique_hdc& hdc, RECT const& clientRect)
|
||||
auto zones = m_activeZoneSet->GetZones();
|
||||
const size_t maxColorIndex = min(size(zones) - 1, size(colors) - 1);
|
||||
size_t colorIndex = maxColorIndex;
|
||||
for (auto iter = zones.rbegin(); iter != zones.rend(); iter++)
|
||||
for (auto iter = zones.begin(); iter != zones.end(); iter++)
|
||||
{
|
||||
winrt::com_ptr<IZone> zone = iter->try_as<IZone>();
|
||||
if (!zone)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <trace.h>
|
||||
#include <common.h>
|
||||
#include <Helpers.h>
|
||||
#include <icon_helpers.h>
|
||||
#include <Settings.h>
|
||||
#include "resource.h"
|
||||
|
||||
|
||||
@@ -2,94 +2,6 @@
|
||||
#include "Helpers.h"
|
||||
#include <ShlGuid.h>
|
||||
|
||||
HRESULT GetIconIndexFromPath(_In_ PCWSTR path, _Out_ int* index)
|
||||
{
|
||||
*index = 0;
|
||||
|
||||
HRESULT hr = E_FAIL;
|
||||
|
||||
SHFILEINFO shFileInfo = { 0 };
|
||||
|
||||
if (!PathIsRelative(path))
|
||||
{
|
||||
DWORD attrib = GetFileAttributes(path);
|
||||
HIMAGELIST himl = (HIMAGELIST)SHGetFileInfo(path, attrib, &shFileInfo, sizeof(shFileInfo), (SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES));
|
||||
if (himl)
|
||||
{
|
||||
*index = shFileInfo.iIcon;
|
||||
// We shouldn't free the HIMAGELIST.
|
||||
hr = S_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
HBITMAP CreateBitmapFromIcon(_In_ HICON hIcon, _In_opt_ UINT width, _In_opt_ UINT height)
|
||||
{
|
||||
HBITMAP hBitmapResult = NULL;
|
||||
|
||||
// Create compatible DC
|
||||
HDC hDC = CreateCompatibleDC(NULL);
|
||||
if (hDC != NULL)
|
||||
{
|
||||
// Get bitmap rectangle size
|
||||
RECT rc = { 0 };
|
||||
rc.left = 0;
|
||||
rc.right = (width != 0) ? width : GetSystemMetrics(SM_CXSMICON);
|
||||
rc.top = 0;
|
||||
rc.bottom = (height != 0) ? height : GetSystemMetrics(SM_CYSMICON);
|
||||
|
||||
// Create bitmap compatible with DC
|
||||
BITMAPINFO BitmapInfo;
|
||||
ZeroMemory(&BitmapInfo, sizeof(BITMAPINFO));
|
||||
|
||||
BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
BitmapInfo.bmiHeader.biWidth = rc.right;
|
||||
BitmapInfo.bmiHeader.biHeight = rc.bottom;
|
||||
BitmapInfo.bmiHeader.biPlanes = 1;
|
||||
BitmapInfo.bmiHeader.biBitCount = 32;
|
||||
BitmapInfo.bmiHeader.biCompression = BI_RGB;
|
||||
|
||||
HDC hDCBitmap = GetDC(NULL);
|
||||
|
||||
HBITMAP hBitmap = CreateDIBSection(hDCBitmap, &BitmapInfo, DIB_RGB_COLORS, NULL, NULL, 0);
|
||||
|
||||
ReleaseDC(NULL, hDCBitmap);
|
||||
|
||||
if (hBitmap != NULL)
|
||||
{
|
||||
// Select bitmap into DC
|
||||
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap);
|
||||
if (hBitmapOld != NULL)
|
||||
{
|
||||
// Draw icon into DC
|
||||
if (DrawIconEx(hDC, 0, 0, hIcon, rc.right, rc.bottom, 0, NULL, DI_NORMAL))
|
||||
{
|
||||
// Restore original bitmap in DC
|
||||
hBitmapResult = (HBITMAP)SelectObject(hDC, hBitmapOld);
|
||||
hBitmapOld = NULL;
|
||||
hBitmap = NULL;
|
||||
}
|
||||
|
||||
if (hBitmapOld != NULL)
|
||||
{
|
||||
SelectObject(hDC, hBitmapOld);
|
||||
}
|
||||
}
|
||||
|
||||
if (hBitmap != NULL)
|
||||
{
|
||||
DeleteObject(hBitmap);
|
||||
}
|
||||
}
|
||||
|
||||
DeleteDC(hDC);
|
||||
}
|
||||
|
||||
return hBitmapResult;
|
||||
}
|
||||
|
||||
HRESULT _ParseEnumItems(_In_ IEnumShellItems* pesi, _In_ IPowerRenameManager* psrm, _In_ int depth = 0)
|
||||
{
|
||||
HRESULT hr = E_INVALIDARG;
|
||||
@@ -167,33 +79,6 @@ HRESULT EnumerateDataObject(_In_ IUnknown* dataSource, _In_ IPowerRenameManager*
|
||||
return hr;
|
||||
}
|
||||
|
||||
HWND CreateMsgWindow(_In_ HINSTANCE hInst, _In_ WNDPROC pfnWndProc, _In_ void* p)
|
||||
{
|
||||
WNDCLASS wc = { 0 };
|
||||
PWSTR wndClassName = L"MsgWindow";
|
||||
|
||||
wc.lpfnWndProc = DefWindowProc;
|
||||
wc.cbWndExtra = sizeof(void*);
|
||||
wc.hInstance = hInst;
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
||||
wc.lpszClassName = wndClassName;
|
||||
|
||||
RegisterClass(&wc);
|
||||
|
||||
HWND hwnd = CreateWindowEx(
|
||||
0, wndClassName, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInst, nullptr);
|
||||
if (hwnd)
|
||||
{
|
||||
SetWindowLongPtr(hwnd, 0, (LONG_PTR)p);
|
||||
if (pfnWndProc)
|
||||
{
|
||||
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)pfnWndProc);
|
||||
}
|
||||
}
|
||||
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
BOOL GetEnumeratedFileName(__out_ecount(cchMax) PWSTR pszUniqueName, UINT cchMax, __in PCWSTR pszTemplate, __in_opt PCWSTR pszDir, unsigned long ulMinLong, __inout unsigned long* pulNumUsed)
|
||||
{
|
||||
PWSTR pszName = nullptr;
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
#include <lib/PowerRenameInterfaces.h>
|
||||
|
||||
HRESULT EnumerateDataObject(_In_ IUnknown* pdo, _In_ IPowerRenameManager* psrm);
|
||||
HRESULT GetIconIndexFromPath(_In_ PCWSTR path, _Out_ int* index);
|
||||
HBITMAP CreateBitmapFromIcon(_In_ HICON hIcon, _In_opt_ UINT width = 0, _In_opt_ UINT height = 0);
|
||||
HWND CreateMsgWindow(_In_ HINSTANCE hInst, _In_ WNDPROC pfnWndProc, _In_ void* p);
|
||||
BOOL GetEnumeratedFileName(
|
||||
__out_ecount(cchMax) PWSTR pszUniqueName,
|
||||
UINT cchMax,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "PowerRenameItem.h"
|
||||
#include "helpers.h"
|
||||
#include "icon_helpers.h"
|
||||
|
||||
int CPowerRenameItem::s_id = 0;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <algorithm>
|
||||
#include <shlobj.h>
|
||||
#include "helpers.h"
|
||||
#include "window_helpers.h"
|
||||
#include <filesystem>
|
||||
#include "trace.h"
|
||||
|
||||
|
||||
@@ -192,6 +192,11 @@
|
||||
<ClCompile Include="PowerRenameRegExTests.cpp" />
|
||||
<ClCompile Include="TestFileHelper.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\common\common.vcxproj">
|
||||
<Project>{74485049-c722-400f-abe5-86ac52d929b3}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
||||
Reference in New Issue
Block a user