Skip to content

Commit

Permalink
Merge pull request rizonesoft#5190 from RaiKoHoff/Dev_Master
Browse files Browse the repository at this point in the history
Fix: center popup dialogs and show current line on word-wrap toggle
  • Loading branch information
RaiKoHoff committed May 25, 2024
2 parents 29586cb + 1c09290 commit e99d387
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 49 deletions.
99 changes: 66 additions & 33 deletions src/Dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ static LRESULT CALLBACK SetPosRelatedToParent_Hook(INT nCode, WPARAM wParam, LPA
rcDlg.right = pCreateStruct->x + pCreateStruct->cx;
rcDlg.bottom = pCreateStruct->y + pCreateStruct->cy;

RECT rcParent = { 0 };
GetWindowRectEx(hParentWnd, &rcParent);

POINT const ptTopLeft = GetCenterOfDlgInParent(&rcDlg, &rcParent);
POINT const ptTopLeft = GetCenterOfDlgInParent(&rcDlg, hParentWnd);

pCreateStruct->x = ptTopLeft.x;
pCreateStruct->y = ptTopLeft.y;
Expand Down Expand Up @@ -284,6 +281,32 @@ static INT_PTR CALLBACK _InfoBoxLngDlgProc(HWND hwnd, UINT umsg, WPARAM wParam,

//UINT const tabStopDist[3] = { 4, 4, 8 };
//SendMessage(GetDlgItem(hwnd, IDC_INFOBOXTEXT), EM_SETTABSTOPS, 3, (LPARAM)tabStopDist);

#if 0
// Resize dialog to fit text - TODO: move buttons dynamically too
HWND const hWndText = GetDlgItem(hwnd, IDC_INFOBOXTEXT);
RECT rectText = { 0 };
GetWindowRectEx(hWndText, &rectText);

RECT rectNew = { 0 };
rectNew.left = 0;
rectNew.top = 0;
rectNew.right = rectText.right - rectText.left; // max as specified
rectNew.bottom = rectNew.right; // max quadratic size

HDC hdc = GetDC(hWndText);
DrawText(hdc, lpMsgBox->lpstrMessage, -1, &rectNew, DT_CALCRECT | DT_WORDBREAK); // calc size
ReleaseDC(hWndText, hdc);

// Change size of text field
SetWindowPos(hWndText, NULL, 0, 0, rectNew.right - rectNew.left, rectNew.bottom - rectNew.top, SWP_NOMOVE | SWP_NOZORDER);
//GetWindowRect(hWndText, &rectText);

int const width = (rectNew.right - rectNew.left) + 100;
int const height = (rectNew.bottom - rectNew.top) + 200;
SetWindowPos(hwnd, NULL, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
#endif

SetDlgItemText(hwnd, IDC_INFOBOXTEXT, lpMsgBox->lpstrMessage);

if (lpMsgBox->bDisableCheckBox) {
Expand All @@ -294,7 +317,7 @@ static INT_PTR CALLBACK _InfoBoxLngDlgProc(HWND hwnd, UINT umsg, WPARAM wParam,
FreeMem(lpMsgBox->lpstrMessage);
lpMsgBox->lpstrMessage = NULL;

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, true);
AttentionBeep(lpMsgBox->uType);
}
return TRUE;
Expand Down Expand Up @@ -811,7 +834,7 @@ static INT_PTR CALLBACK CmdLineHelpProc(HWND hwnd, UINT umsg, WPARAM wParam, LPA
WCHAR szText[4096] = { L'\0' };
GetLngString(IDS_MUI_CMDLINEHELP, szText, COUNTOF(szText));
SetDlgItemText(hwnd, IDC_CMDLINEHELP, szText);
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -1042,7 +1065,7 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam
StringCchCatA(pAboutResource, COUNTOF(pAboutResource), pAboutRes);
//~}

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);

HFONT const hFont = (HFONT)SendDlgItemMessage(hwnd, IDC_SCI_VERSION, WM_GETFONT, 0, 0);
if (hFont) {
Expand Down Expand Up @@ -1365,7 +1388,7 @@ static INT_PTR CALLBACK RunDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM l
SetDlgItemText(hwnd, IDC_COMMANDLINE, (LPCWSTR)lParam);
SHAutoComplete(GetDlgItem(hwnd, IDC_COMMANDLINE), SHACF_FILESYSTEM);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -1622,7 +1645,7 @@ static INT_PTR CALLBACK OpenWithDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM

MakeBitmapButton(hwnd,IDC_GETOPENWITHDIR,IDB_OPEN, -1, -1);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -1882,7 +1905,7 @@ static INT_PTR CALLBACK FavoritesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARA

MakeBitmapButton(hwnd,IDC_GETFAVORITESDIR,IDB_OPEN, -1, -1);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -2100,7 +2123,7 @@ static INT_PTR CALLBACK AddToFavDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPA
SendDlgItemMessage(hwnd, IDC_ADDFAV_FILES, EM_LIMITTEXT, INTERNET_MAX_URL_LENGTH, 0); // max
SetDlgItemTextW(hwnd, IDC_ADDFAV_FILES, wchNamePth);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -2376,7 +2399,7 @@ static INT_PTR CALLBACK FileMRUDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPAR

DialogEnableControl(hwnd, IDC_PRESERVECARET, Settings.SaveRecentFiles);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -2722,7 +2745,7 @@ static INT_PTR CALLBACK ChangeNotifyDlgProc(HWND hwnd, UINT umsg, WPARAM wParam,

SetDlgItemInt(hwnd, IDC_FILE_CHECK_INTERVAL, (UINT)FileWatching.FileCheckInterval, FALSE);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -2910,7 +2933,7 @@ static INT_PTR CALLBACK ColumnWrapDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, L
UINT const uiNumber = *((UINT*)lParam);
SetDlgItemInt(hwnd, IDC_COLUMNWRAP, uiNumber, false);
SendDlgItemMessage(hwnd, IDC_COLUMNWRAP, EM_LIMITTEXT, 15, 0);
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -3054,7 +3077,7 @@ static INT_PTR CALLBACK WordWrapSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wPa
SendDlgItemMessage(hwnd, 102, CB_SETCURSEL, (WPARAM)(Settings.ShowWordWrapSymbols ? ((Settings.WordWrapSymbols % 100) - (Settings.WordWrapSymbols % 10)) / 10 : 0), 0);
SendDlgItemMessage(hwnd, 103, CB_SETCURSEL, (WPARAM)Settings.WordWrapMode, 0);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -3194,7 +3217,7 @@ static INT_PTR CALLBACK LongLineSettingsDlgProc(HWND hwnd, UINT umsg, WPARAM wPa
DialogEnableControl(hwnd, IDC_SHOWEDGELINE, false);
DialogEnableControl(hwnd, IDC_BACKGRDCOLOR, false);
}
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -3352,7 +3375,7 @@ static INT_PTR CALLBACK TabSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPA
CheckDlgButton(hwnd,IDC_WARN_INCONSISTENT_INDENTS, SetBtn(Settings.WarnInconsistentIndents));
CheckDlgButton(hwnd,IDC_AUTO_DETECT_INDENTS, SetBtn(Settings.AutoDetectIndentSettings));

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -3523,7 +3546,7 @@ static INT_PTR CALLBACK SelectDefEncodingDlgProc(HWND hwnd, UINT umsg, WPARAM wP
CheckDlgButton(hwnd, IDC_NOUNICODEDETECTION, SetBtn(!Settings.SkipUnicodeDetection));
CheckDlgButton(hwnd, IDC_NOANSICPDETECTION, SetBtn(!Settings.SkipANSICodePageDetection));

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -3719,7 +3742,7 @@ static INT_PTR CALLBACK SelectEncodingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,

ListView_SetColumnWidth(hwndLV,0,LVSCW_AUTOSIZE_USEHEADER);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -3926,7 +3949,7 @@ static INT_PTR CALLBACK SelectDefLineEndingDlgProc(HWND hwnd,UINT umsg,WPARAM wP
CheckDlgButton(hwnd,IDC_CONSISTENT_EOLS, SetBtn(Settings.FixLineEndings));
CheckDlgButton(hwnd,IDC_AUTOSTRIPBLANKS, SetBtn(Settings.FixTrailingBlanks));

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -4053,7 +4076,7 @@ static INT_PTR CALLBACK WarnLineEndingDlgProc(HWND hwnd, UINT umsg, WPARAM wPara
}

CheckDlgButton(hwnd, IDC_WARN_INCONSISTENT_EOLS, SetBtn(Settings.WarnInconsistEOLs));
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);

AttentionBeep(MB_ICONEXCLAMATION);
}
Expand Down Expand Up @@ -4200,7 +4223,7 @@ static INT_PTR CALLBACK WarnIndentationDlgProc(HWND hwnd, UINT umsg, WPARAM wPar

CheckDlgButton(hwnd, Globals.fvCurFile.bTabsAsSpaces ? IDC_INDENT_BY_SPCS : IDC_INDENT_BY_TABS, true);
CheckDlgButton(hwnd, IDC_WARN_INCONSISTENT_INDENTS, SetBtn(Settings.WarnInconsistentIndents));
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);

AttentionBeep(MB_ICONEXCLAMATION);
}
Expand Down Expand Up @@ -4332,7 +4355,7 @@ static INT_PTR CALLBACK AutoSaveBackupSettingsDlgProc(HWND hwnd, UINT umsg, WPAR
}
SetDlgItemText(hwnd, IDC_AUTOSAVE_INTERVAL, wch);

CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -5508,19 +5531,28 @@ void ComboBox_AddStringMB2W(HWND hDlg, int nIDDlgItem, LPCSTR lpString)
//
// GetCenterOfDlgInParent()
//
POINT GetCenterOfDlgInParent(const RECT* rcDlg, const RECT* rcParent)
POINT GetCenterOfDlgInParent(const RECT* rcDlg, const HWND hwndParent)
{
RECT rcParent = { 0 };

HMONITOR const hMonitor = MonitorFromRect(rcParent, MONITOR_DEFAULTTONEAREST);
WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) };
if (GetWindowPlacement(hwndParent, &wp)) {
rcParent = wp.rcNormalPosition;
}
else {
GetWindowRectEx(hwndParent, &rcParent);
}

HMONITOR const hMonitor = MonitorFromRect(&rcParent, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi = { sizeof(MONITORINFO) };
GetMonitorInfo(hMonitor, &mi);
int const xMin = mi.rcWork.left;
int const xMax = (mi.rcWork.right) - (rcDlg->right - rcDlg->left);
int const yMin = mi.rcWork.top;
int const yMax = (mi.rcWork.bottom) - (rcDlg->bottom - rcDlg->top);

int const x = rcParent->left + (((rcParent->right - rcParent->left) - (rcDlg->right - rcDlg->left)) >> 1);
int const y = rcParent->top + (((rcParent->bottom - rcParent->top) - (rcDlg->bottom - rcDlg->top)) >> 1);
int const x = rcParent.left + (((rcParent.right - rcParent.left) - (rcDlg->right - rcDlg->left)) >> 1);
int const y = rcParent.top + (((rcParent.bottom - rcParent.top) - (rcDlg->bottom - rcDlg->top)) >> 1);

POINT ptRet = { 0, 0 };
ptRet.x = clampi(x, xMin, xMax);
Expand All @@ -5544,21 +5576,22 @@ HWND GetParentOrDesktop(HWND hDlg)
//
// CenterDlgInParent()
//
void CenterDlgInParent(HWND hDlg, HWND hDlgParent)
void CenterDlgInParent(HWND hDlg, HWND hDlgParent, bool bLock)
{
if (!hDlg) { return; }

RECT rcDlg = { 0 };
GetWindowRect(hDlg, &rcDlg);

HWND const hParentWnd = hDlgParent ? hDlgParent : GetParentOrDesktop(hDlg);
RECT rcParent = { 0 };
GetWindowRectEx(hParentWnd, &rcParent);

POINT const ptTopLeft = GetCenterOfDlgInParent(&rcDlg, &rcParent);
POINT const ptTopLeft = GetCenterOfDlgInParent(&rcDlg, hParentWnd);

SetWindowPos(hDlg, NULL, ptTopLeft.x, ptTopLeft.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
SetForegroundWindow(hDlg);
if (bLock) {
LockSetForegroundWindow(LSFW_LOCK);
}
}


Expand Down Expand Up @@ -6676,7 +6709,7 @@ INT_PTR CALLBACK FontDialogHookProc(
//~ PostMessage(hdlg, WM_CLOSE, 0, 0);
//~}

CenterDlgInParent(hdlg, NULL);
CenterDlgInParent(hdlg, NULL, false);

PostMessage(hdlg, WM_THEMECHANGED, 0, 0);
} break;
Expand Down Expand Up @@ -6777,7 +6810,7 @@ INT_PTR CALLBACK ColorDialogHookProc(
SetWindowPos(hdlg, NULL, wi.x, wi.y, wi.cx, wi.cy, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
SetForegroundWindow(hdlg);
} else {
CenterDlgInParent(hdlg, NULL);
CenterDlgInParent(hdlg, NULL, false);
}

PostMessage(hdlg, WM_THEMECHANGED, 0, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/Dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ void ComboBox_SetTextHW(HWND hDlg, int nIDDlgItem, const HSTRINGW hstr);
void ComboBox_SetTextMB2W(HWND hDlg, int nIDDlgItem, LPCSTR lpString);
//void ComboBox_AddStringMB2W(HWND hDlg, int nIDDlgItem, LPCSTR lpString);

POINT GetCenterOfDlgInParent(const RECT* rcDlg, const RECT* rcParent);
POINT GetCenterOfDlgInParent(const RECT* rcDlg, const HWND hwndParent);
HWND GetParentOrDesktop(HWND hDlg);
void CenterDlgInParent(HWND hDlg, HWND hDlgParent);
void CenterDlgInParent(HWND hDlg, HWND hDlgParent, bool bLock);
void GetDlgPos(HWND hDlg, LPINT xDlg, LPINT yDlg);
void SetDlgPos(HWND hDlg, int xDlg, int yDlg);

Expand Down
16 changes: 8 additions & 8 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6377,7 +6377,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
}
else {
if (Settings.FindReplaceDlgPosX == CW_USEDEFAULT || Settings.FindReplaceDlgPosY == CW_USEDEFAULT) {
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
else {
SetDlgPos(hwnd, Settings.FindReplaceDlgPosX, Settings.FindReplaceDlgPosY);
Expand Down Expand Up @@ -7028,7 +7028,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
break;

case IDACC_RESETPOS:
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
Settings.FindReplaceDlgPosX = Settings.FindReplaceDlgPosY = CW_USEDEFAULT;
break;

Expand Down Expand Up @@ -8503,7 +8503,7 @@ static INT_PTR CALLBACK EditLinenumDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPA
SetDlgItemInt(hwnd, IDC_COLNUM, (int)clampp(iCurColumn, 0, INT_MAX), false);
SendDlgItemMessage(hwnd,IDC_LINENUM,EM_LIMITTEXT,80,0);
SendDlgItemMessage(hwnd,IDC_COLNUM,EM_LIMITTEXT,80,0);
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return true;

Expand Down Expand Up @@ -8680,7 +8680,7 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
SendDlgItemMessage(hwnd,IDC_MODLNS_ED_PREPEND, EM_LIMITTEXT, ENCLDATA_SIZE - 1, 0);
SetDlgItemTextW(hwnd,IDC_MODLNS_ED_APPEND, pData->pwsz2);
SendDlgItemMessage(hwnd,IDC_MODLNS_ED_APPEND, EM_LIMITTEXT, ENCLDATA_SIZE - 1, 0);
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return true;

Expand Down Expand Up @@ -8898,7 +8898,7 @@ static INT_PTR CALLBACK EditAlignDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
}
#endif
CheckRadioButton(hwnd,100,104,*piAlignMode+100);
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return true;

Expand Down Expand Up @@ -9010,7 +9010,7 @@ static INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd, UINT umsg, WPARAM
SetDlgItemTextW(hwnd, 100, pData->pwsz1);
SendDlgItemMessage(hwnd, 101, EM_LIMITTEXT, ENCLDATA_SIZE - 1, 0);
SetDlgItemTextW(hwnd, 101, pData->pwsz2);
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down Expand Up @@ -9129,7 +9129,7 @@ static INT_PTR CALLBACK EditInsertTagDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,L
SetDlgItemInt(hwnd, 102, pData->repeat, FALSE);
SetFocus(GetDlgItem(hwnd,100));
PostMessageW(GetDlgItem(hwnd, 100), EM_SETSEL, 1, (LPARAM)(StringCchLen(pData->pwsz1, 0) - 1));
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return FALSE;

Expand Down Expand Up @@ -9350,7 +9350,7 @@ static INT_PTR CALLBACK EditSortDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM
*piSortFlags |= SORT_COLUMN;
CheckDlgButton(hwnd,112,BST_CHECKED);
}
CenterDlgInParent(hwnd, NULL);
CenterDlgInParent(hwnd, NULL, false);
}
return TRUE;

Expand Down
3 changes: 2 additions & 1 deletion src/Notepad3.c
Original file line number Diff line number Diff line change
Expand Up @@ -5981,7 +5981,8 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case IDM_VIEW_WORDWRAP:
Globals.fvCurFile.bWordWrap = Settings.WordWrap = !Settings.WordWrap;
_SetWrapIndentMode(Globals.hwndEdit);
Sci_ScrollSelectionToView();
//~Sci_ScrollSelectionToView(); // does not work here bug ?
SciCall_SetFirstVisibleLine(max_ln(0, Sci_GetCurrentLineNumber() - Settings2.CurrentLineVerticalSlop));
UpdateToolbar();
break;

Expand Down
Loading

0 comments on commit e99d387

Please sign in to comment.