Allow resizing of PowerRename dialog

This commit is contained in:
Chris Davis 2019-10-31 23:57:42 -07:00
parent d9320b7c05
commit d4256dad30
4 changed files with 151 additions and 30 deletions

View File

@ -32,16 +32,48 @@ struct FlagCheckboxMap
FlagCheckboxMap g_flagCheckboxMap[] =
{
{ UseRegularExpressions, IDC_CHECK_USEREGEX },
{ ExcludeSubfolders, IDC_CHECK_EXCLUDESUBFOLDERS },
{ EnumerateItems, IDC_CHECK_ENUMITEMS },
{ ExcludeFiles, IDC_CHECK_EXCLUDEFILES },
{ CaseSensitive, IDC_CHECK_CASESENSITIVE },
{ MatchAllOccurences, IDC_CHECK_MATCHALLOCCRENCES },
{ ExcludeFolders, IDC_CHECK_EXCLUDEFOLDERS },
{ NameOnly, IDC_CHECK_NAMEONLY },
{ ExtensionOnly, IDC_CHECK_EXTENSIONONLY }
{ ExcludeSubfolders, IDC_CHECK_EXCLUDESUBFOLDERS },
{ EnumerateItems, IDC_CHECK_ENUMITEMS },
{ ExcludeFiles, IDC_CHECK_EXCLUDEFILES },
{ CaseSensitive, IDC_CHECK_CASESENSITIVE },
{ MatchAllOccurences, IDC_CHECK_MATCHALLOCCURENCES },
{ ExcludeFolders, IDC_CHECK_EXCLUDEFOLDERS },
{ NameOnly, IDC_CHECK_NAMEONLY },
{ ExtensionOnly, IDC_CHECK_EXTENSIONONLY }
};
struct RepositionMap
{
DWORD id;
DWORD flags;
};
enum
{
Reposition_None = 0,
Reposition_X = 0x1,
Reposition_Y = 0x2,
Reposition_Width = 0x4,
Reposition_Height = 0x8
};
RepositionMap g_repositionMap[] =
{
{ IDC_SEARCHREPLACEGROUP, Reposition_Width },
{ IDC_OPTIONSGROUP, Reposition_Width },
{ IDC_PREVIEWGROUP, Reposition_Width | Reposition_Height },
{ IDC_EDIT_SEARCHFOR, Reposition_Width },
{ IDC_EDIT_REPLACEWITH, Reposition_Width },
{ IDC_LIST_PREVIEW, Reposition_Width | Reposition_Height },
{ IDC_STATUS_MESSAGE, Reposition_Y },
{ ID_RENAME, Reposition_X | Reposition_Y },
{ ID_ABOUT, Reposition_X | Reposition_Y },
{ IDCANCEL, Reposition_X | Reposition_Y }
};
inline int RECT_WIDTH(RECT& r) { return r.right - r.left; }
inline int RECT_HEIGHT(RECT& r) { return r.bottom - r.top; }
// IUnknown
IFACEMETHODIMP CPowerRenameUI::QueryInterface(__in REFIID riid, __deref_out void** ppv)
{
@ -379,6 +411,14 @@ INT_PTR CPowerRenameUI::_DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
bRet = _OnNotify(wParam, lParam);
break;
case WM_SIZE:
_OnSize(wParam);
break;
case WM_GETMINMAXINFO:
_OnGetMinMaxInfo(lParam);
break;
case WM_CLOSE:
_OnCloseDlg();
break;
@ -429,6 +469,13 @@ void CPowerRenameUI::_OnInitDlg()
RegisterDragDrop(m_hwnd, this);
}
RECT rc = { 0 };
GetWindowRect(m_hwnd, &rc);
m_initialWidth = RECT_WIDTH(rc);
m_initialHeight = RECT_HEIGHT(rc);
m_lastWidth = m_initialWidth;
m_lastHeight = m_initialHeight;
// Disable rename button by default. It will be enabled in _UpdateCounts if
// there are tiems to be renamed
EnableWindow(GetDlgItem(m_hwnd, ID_RENAME), FALSE);
@ -469,7 +516,7 @@ void CPowerRenameUI::_OnCommand(_In_ WPARAM wParam, _In_ LPARAM lParam)
case IDC_CHECK_EXCLUDEFILES:
case IDC_CHECK_EXCLUDEFOLDERS:
case IDC_CHECK_EXCLUDESUBFOLDERS:
case IDC_CHECK_MATCHALLOCCRENCES:
case IDC_CHECK_MATCHALLOCCURENCES:
case IDC_CHECK_USEREGEX:
case IDC_CHECK_EXTENSIONONLY:
case IDC_CHECK_NAMEONLY:
@ -543,6 +590,86 @@ BOOL CPowerRenameUI::_OnNotify(_In_ WPARAM wParam, _In_ LPARAM lParam)
return ret;
}
void CPowerRenameUI::_OnGetMinMaxInfo(_In_ LPARAM lParam)
{
if (m_initialWidth)
{
// Prevent resizing the dialog less than the original size
MINMAXINFO* pMinMaxInfo = reinterpret_cast<MINMAXINFO*>(lParam);
pMinMaxInfo->ptMinTrackSize.x = m_initialWidth;
pMinMaxInfo->ptMinTrackSize.y = m_initialHeight;
}
}
void CPowerRenameUI::_OnSize(_In_ WPARAM wParam)
{
if ((wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED) && m_initialWidth)
{
// Calculate window size change delta
RECT rc = { 0 };
GetWindowRect(m_hwnd, &rc);
const int xDelta = RECT_WIDTH(rc) - m_lastWidth;
m_lastWidth += xDelta;
const int yDelta = RECT_HEIGHT(rc) - m_lastHeight;
m_lastHeight += yDelta;
for (UINT u = 0; u < ARRAYSIZE(g_repositionMap); u++)
{
_MoveControl(g_repositionMap[u].id, g_repositionMap[u].flags, xDelta, yDelta);
}
}
}
void CPowerRenameUI::_MoveControl(_In_ DWORD id, _In_ DWORD repositionFlags, _In_ int xDelta, _In_ int yDelta)
{
HWND hwnd = GetDlgItem(m_hwnd, id);
UINT flags = SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE;
if (!((repositionFlags & Reposition_X) || (repositionFlags & Reposition_Y)))
{
flags |= SWP_NOMOVE;
}
if (!((repositionFlags & Reposition_Width) || (repositionFlags & Reposition_Height)))
{
flags |= SWP_NOSIZE;
}
RECT rcWindow = { 0 };
GetWindowRect(hwnd, &rcWindow);
int cx = RECT_WIDTH(rcWindow);
int cy = RECT_HEIGHT(rcWindow);
MapWindowPoints(HWND_DESKTOP, GetParent(hwnd), (LPPOINT)&rcWindow, 2);
int x = rcWindow.left;
int y = rcWindow.top;
if (repositionFlags & Reposition_X)
{
x += xDelta;
}
if (repositionFlags & Reposition_Y)
{
y += yDelta;
}
if (repositionFlags & Reposition_Width)
{
cx += xDelta;
}
if (repositionFlags & Reposition_Height)
{
cy += yDelta;
}
SetWindowPos(hwnd, NULL, x, y, cx, cy, flags);
}
void CPowerRenameUI::_OnSearchReplaceChanged()
{
// Pass updated search and replace terms to the IPowerRenameRegEx handler

View File

@ -3,7 +3,6 @@
class CPowerRenameListView
{
public:
CPowerRenameListView() = default;
~CPowerRenameListView() = default;
@ -90,13 +89,14 @@ private:
return pDlg ? pDlg->_DlgProc(uMsg, wParam, lParam) : FALSE;
}
INT_PTR _DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
void _OnCommand(_In_ WPARAM wParam, _In_ LPARAM lParam);
BOOL _OnNotify(_In_ WPARAM wParam, _In_ LPARAM lParam);
HRESULT _Initialize(_In_ IPowerRenameManager* psrm, _In_opt_ IDataObject* pdo, _In_ bool enableDragDrop);
void _Cleanup();
INT_PTR _DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
void _OnCommand(_In_ WPARAM wParam, _In_ LPARAM lParam);
BOOL _OnNotify(_In_ WPARAM wParam, _In_ LPARAM lParam);
void _OnSize(_In_ WPARAM wParam);
void _OnGetMinMaxInfo(_In_ LPARAM lParam);
void _OnInitDlg();
void _OnRename();
void _OnAbout();
@ -104,6 +104,7 @@ private:
void _OnDestroyDlg();
void _OnClear();
void _OnSearchReplaceChanged();
void _MoveControl(_In_ DWORD id, _In_ DWORD repositionFlags, _In_ int xDelta, _In_ int yDelta);
HRESULT _ReadSettings();
HRESULT _WriteSettings();
@ -126,6 +127,10 @@ private:
DWORD m_currentRegExId = 0;
UINT m_selectedCount = 0;
UINT m_renamingCount = 0;
int m_initialWidth = 0;
int m_initialHeight = 0;
int m_lastWidth = 0;
int m_lastHeight = 0;
CComPtr<IPowerRenameManager> m_spsrm;
CComPtr<IDataObject> m_spdo;
CComPtr<IDropTargetHelper> m_spdth;

View File

@ -23,17 +23,6 @@
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
IDC_SMARTRENAME ACCELERATORS
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
END
/////////////////////////////////////////////////////////////////////////////
//
@ -41,7 +30,7 @@
//
IDD_MAIN DIALOGEX 0, 0, 351, 304
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "PowerRename"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
@ -49,7 +38,7 @@
EDITTEXT IDC_EDIT_REPLACEWITH,71,38,259,13,ES_AUTOHSCROLL
CONTROL "Use Regular Expressions",IDC_CHECK_USEREGEX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,83,93,10
CONTROL "Case Sensitive",IDC_CHECK_CASESENSITIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,95,61,10
CONTROL "Match All Occurences",IDC_CHECK_MATCHALLOCCRENCES,
CONTROL "Match All Occurences",IDC_CHECK_MATCHALLOCCURENCES,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,107,85,10
CONTROL "Exclude Files",IDC_CHECK_EXCLUDEFILES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,132,83,58,10
CONTROL "Exclude Folders",IDC_CHECK_EXCLUDEFOLDERS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,132,95,68,10
@ -65,9 +54,9 @@
RTEXT "Search for:",IDC_STATIC,25,23,39,8
LTEXT "Replace with:",IDC_STATIC,21,40,43,8
LTEXT "Items Selected: 0 | Renaming: 0",IDC_STATUS_MESSAGE,11,284,137,13
GROUPBOX "Options",IDC_STATIC,11,68,329,58
GROUPBOX "Preview",IDC_STATIC,11,133,329,142
GROUPBOX "Enter the criteria below to rename the items",IDC_STATIC,11,7,329,55
GROUPBOX "Options",IDC_OPTIONSGROUP,11,68,329,58
GROUPBOX "Preview",IDC_PREVIEWGROUP,11,133,329,142
GROUPBOX "Enter the criteria below to rename the items",IDC_SEARCHREPLACEGROUP,11,7,329,55
END