Merge pull request #2445 from RaiKoHoff/grepWin_Integration

Fixing multiple small issues
This commit is contained in:
Pairi Daiza 2020-06-18 18:09:11 +02:00 committed by GitHub
commit d89e84ee74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 104 additions and 95 deletions

View File

@ -215,6 +215,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mp_it_it", "minipath\langua
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Notepad3", "Notepad3", "{C3735E17-6EAE-4CC5-980E-30BCEF094862}"
ProjectSection(SolutionItems) = preProject
src\.clang-format = src\.clang-format
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MiniPath", "MiniPath", "{D21C1F85-6FA3-4695-82CD-DDC5690E2D66}"
ProjectSection(SolutionItems) = preProject

View File

@ -58,6 +58,7 @@ try
$Build = $Build + 1
# locally: we have no commit ID, create an arificial one
$CommitID = [string](Get-Content "Versions\commit_id.txt")
if (!$CommitID) { $CommitID = "---" }
if ($CommitID -eq "computername") {
$length = ([string]($env:computername)).length
$CommitID = ([string]($env:computername)).substring(0,[math]::min($length,8)).ToLower()
@ -68,6 +69,9 @@ try
}
}
if (!$CommitID) { $CommitID = "---" }
$CommitID = $CommitID -replace '"', ''
$CommitID = $CommitID -replace "'", ''
if (!$CommitID) { $CommitID = "---" }
$Build | Set-Content "Versions\build.txt"
$CompleteVer = "$Major.$Minor.$Revis.$Build"

View File

@ -1813,10 +1813,10 @@ Sci::Position Editor::FormatRange(bool draw, const Sci_RangeToFormat *pfr) {
if (!pfr)
return 0;
AutoSurface surface(pfr->hdc, this, SC_TECHNOLOGY_DEFAULT);
AutoSurface surface(pfr->hdc, this, SC_TECHNOLOGY_DEFAULT, true);
if (!surface)
return 0;
AutoSurface surfaceMeasure(pfr->hdcTarget, this, SC_TECHNOLOGY_DEFAULT);
AutoSurface surfaceMeasure(pfr->hdcTarget, this, SC_TECHNOLOGY_DEFAULT, true);
if (!surfaceMeasure) {
return 0;
}

View File

@ -655,10 +655,10 @@ public:
surf->SetBidiR2L(ed->BidirectionalR2L());
}
}
AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) {
AutoSurface(SurfaceID sid, Editor *ed, int technology = -1, bool printing = false) {
if (ed->wMain.GetID()) {
surf.reset(Surface::Allocate(technology != -1 ? technology : ed->technology));
surf->Init(sid, ed->wMain.GetID());
surf->Init(sid, ed->wMain.GetID(), printing);
surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
//~surf->SetDBCSMode(ed->CodePage());
surf->SetBidiR2L(ed->BidirectionalR2L());

View File

@ -122,15 +122,17 @@ DPI_T GetWindowDPI(HWND hwnd) {
DPI_T _dpi;
_dpi.x = g_uSystemDPI;
_dpi.y = g_uSystemDPI;
if (fnGetDpiForWindow) {
_dpi.y = fnGetDpiForWindow(hwnd);
_dpi.x = _dpi.y;
}
else if (pfnGetDpiForMonitor) {
HMONITOR hMonitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (FAILED(pfnGetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &(_dpi.x), &(_dpi.y)))) {
_dpi.x = g_uSystemDPI;
_dpi.y = g_uSystemDPI;
if (hwnd) {
if (fnGetDpiForWindow) {
_dpi.y = fnGetDpiForWindow(hwnd);
_dpi.x = _dpi.y;
}
else if (pfnGetDpiForMonitor) {
HMONITOR hMonitor = ::MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (FAILED(pfnGetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &(_dpi.x), &(_dpi.y)))) {
_dpi.x = g_uSystemDPI;
_dpi.y = g_uSystemDPI;
}
}
}
return _dpi;
@ -571,7 +573,7 @@ public:
~SurfaceGDI() noexcept override;
void Init(WindowID wid) noexcept override;
void Init(SurfaceID sid, WindowID wid, bool printing) noexcept override;
void Init(SurfaceID sid, WindowID wid, bool printing = false) noexcept override;
void InitPixMap(int width, int height, Surface *surface_, WindowID wid) noexcept override;
void Release() noexcept override;
@ -666,7 +668,7 @@ void SurfaceGDI::Init(WindowID wid) noexcept {
::SetTextAlign(hdc, TA_BASELINE);
}
void SurfaceGDI::Init(SurfaceID sid, WindowID wid, bool printing) noexcept {
void SurfaceGDI::Init(SurfaceID sid, WindowID wid, bool printing /*=false*/) noexcept {
Release();
hdc = static_cast<HDC>(sid);
// Windows on screen are scaled but printers are not.
@ -1341,9 +1343,9 @@ void SurfaceD2D::Init(WindowID wid) noexcept {
logPixelsY = DpiYForWindow(wid);
}
void SurfaceD2D::Init(SurfaceID sid, WindowID wid, bool /*printing*/) noexcept {
void SurfaceD2D::Init(SurfaceID sid, WindowID wid, bool printing /*=false*/) noexcept {
Release();
// printing always using GDI
// printing always using GDI technology
logPixelsY = DpiYForWindow(wid);
pRenderTarget = static_cast<ID2D1RenderTarget *>(sid);
}

View File

@ -12,7 +12,7 @@ AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
@ -23,10 +23,10 @@ BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
@ -48,8 +48,8 @@ ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
@ -69,7 +69,7 @@ IncludeCategories:
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWidth: 2
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
@ -127,7 +127,7 @@ SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
TabWidth: 2
UseTab: Never
...

View File

@ -67,42 +67,54 @@
//
static HHOOK s_hCBThook = NULL;
static LRESULT CALLBACK CenterInParentHook(INT nCode, WPARAM wParam, LPARAM lParam)
static LRESULT CALLBACK SetPosRelatedToParent_Hook(INT nCode, WPARAM wParam, LPARAM lParam)
{
// notification that a window is about to be activated
if (nCode == HCBT_CREATEWND)
if (nCode == HCBT_CREATEWND)
{
// get window handles
LPCREATESTRUCT const pCreateStructure = ((LPCBT_CREATEWND)lParam)->lpcs;
HWND const hThisWnd = (HWND)wParam;
HWND const hParentWnd = pCreateStructure->hwndParent; // GetParent(hThisWnd);
if (hThisWnd) {
// set Notepad3 dialog icon
SET_NP3_DLG_ICON_SMALL(hThisWnd);
if (hParentWnd && hThisWnd)
{
RECT rcParent; GetWindowRect(hParentWnd, &rcParent);
// get window handles
LPCREATESTRUCT const pCreateStructure = ((LPCBT_CREATEWND)lParam)->lpcs;
HWND const hParentWnd = pCreateStructure->hwndParent; // GetParent(hThisWnd);
RECT rcDlg;
rcDlg.left = pCreateStructure->x;
rcDlg.top = pCreateStructure->y;
rcDlg.right = pCreateStructure->x + pCreateStructure->cx;
rcDlg.bottom = pCreateStructure->y + pCreateStructure->cy;
POINT ptTopLeft = GetCenterOfDlgInParent(&rcDlg, &rcParent);
if (hParentWnd) {
RECT rcParent;
GetWindowRect(hParentWnd, &rcParent);
// set new coordinates
pCreateStructure->x = ptTopLeft.x;
pCreateStructure->y = ptTopLeft.y;
// set new coordinates
DPI_T const dpi = Scintilla_GetWindowDPI(hParentWnd);
if (dpi.y == USER_DEFAULT_SCREEN_DPI) {
RECT rcDlg;
rcDlg.left = pCreateStructure->x;
rcDlg.top = pCreateStructure->y;
rcDlg.right = pCreateStructure->x + pCreateStructure->cx;
rcDlg.bottom = pCreateStructure->y + pCreateStructure->cy;
POINT const ptTL = GetCenterOfDlgInParent(&rcDlg, &rcParent);
pCreateStructure->x = ptTL.x;
pCreateStructure->y = ptTL.y;
}
else {
// don't know how to handle DPI Awareness
//pCreateStructure->x = rcParent.left + 20;
//pCreateStructure->y = rcParent.top + 20;
//pCreateStructure->x = MulDiv(rcParent.left + (rcParent.right - rcParent.left)/8, USER_DEFAULT_SCREEN_DPI, dpi.x);
//pCreateStructure->y = MulDiv(rcParent.top + (rcParent.bottom - rcParent.top)/2, USER_DEFAULT_SCREEN_DPI, dpi.y);
}
}
// we are done
if (s_hCBThook) {
UnhookWindowsHookEx(s_hCBThook);
s_hCBThook = NULL;
}
// set Notepad3 dialog icon
SET_NP3_DLG_ICON_SMALL(hThisWnd);
}
else if (s_hCBThook) {
// continue with any possible chained hooks
@ -134,7 +146,7 @@ int MessageBoxLng(HWND hwnd, UINT uType, UINT uidMsg, ...)
uType |= MB_SETFOREGROUND; //~ not MB_TOPMOST
// center message box to focus or main
s_hCBThook = SetWindowsHookEx(WH_CBT, &CenterInParentHook, 0, GetCurrentThreadId());
s_hCBThook = SetWindowsHookEx(WH_CBT, &SetPosRelatedToParent_Hook, 0, GetCurrentThreadId());
return MessageBoxEx(hwnd, szText, szTitle, uType, Globals.iPrefLANGID);
}
@ -174,7 +186,7 @@ DWORD MsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID)
// center message box to main
HWND focus = GetFocus();
HWND hwnd = focus ? focus : Globals.hwndMain;
s_hCBThook = SetWindowsHookEx(WH_CBT, &CenterInParentHook, 0, GetCurrentThreadId());
s_hCBThook = SetWindowsHookEx(WH_CBT, &SetPosRelatedToParent_Hook, 0, GetCurrentThreadId());
MessageBoxEx(hwnd, lpDisplayBuf, _W(SAPPNAME) L" - ERROR", MB_ICONERROR, Globals.iPrefLANGID);
@ -3836,31 +3848,19 @@ void SetWindowTransparentMode(HWND hwnd, bool bTransparentMode, int iOpacityLeve
POINT GetCenterOfDlgInParent(const RECT* rcDlg, const RECT* rcParent)
{
HMONITOR const hMonitor = MonitorFromRect(rcParent, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi; mi.cbSize = sizeof(MONITORINFO); GetMonitorInfo(hMonitor, &mi);
int const xMin = mi.rcWork.left;
int const yMin = mi.rcWork.top;
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 x;
if ((rcParent->right - rcParent->left) - (rcDlg->right - rcDlg->left) > 20) {
x = rcParent->left + (((rcParent->right - rcParent->left) - (rcDlg->right - rcDlg->left)) / 2);
}
else {
x = rcParent->left + 60;
}
int y;
if ((rcParent->bottom - rcParent->top) - (rcDlg->bottom - rcDlg->top) > 20) {
y = rcParent->top + (((rcParent->bottom - rcParent->top) - (rcDlg->bottom - rcDlg->top)) / 2);
}
else {
y = rcParent->top + 60;
}
int const x = rcParent->left + max_i(20, ((rcParent->right - rcParent->left) - (rcDlg->right - rcDlg->left)) / 2);
int const y = rcParent->top + max_i(20, ((rcParent->bottom - rcParent->top) - (rcDlg->bottom - rcDlg->top)) / 2);
POINT ptRet; ptRet.x = clampi(x, xMin, xMax); ptRet.y = clampi(y, yMin, yMax);
POINT ptRet;
ptRet.x = clampi(x, xMin, xMax);
ptRet.y = clampi(y, yMin, yMax);
return ptRet;
}
@ -3879,10 +3879,9 @@ void CenterDlgInParent(HWND hDlg, HWND hDlgParent)
RECT rcParent;
BOOL const bFoundRect = hParent ? GetWindowRect(hParent, &rcParent) :
GetWindowRect(GetDesktopWindow(), &rcParent);
if (bFoundRect)
{
if (bFoundRect) {
POINT const ptTopLeft = GetCenterOfDlgInParent(&rcDlg, &rcParent);
SetWindowPos(hDlg, NULL, ptTopLeft.x, ptTopLeft.y, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSIZE);
SetWindowPos(hDlg, NULL, ptTopLeft.x, ptTopLeft.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
//~SnapToDefaultButton(hDlg);
}
}
@ -4618,7 +4617,7 @@ void SetUACIcon(const HMENU hMenu, const UINT nItem)
//
void UpdateWindowLayoutForDPI(HWND hWnd, RECT* pRC, DPI_T* pDPI)
{
UINT const uWndFlags = SWP_NOZORDER | SWP_NOACTIVATE; //~ | SWP_NOMOVE | SWP_NOSIZE | SWP_NOREPOSITION | SWP_FRAMECHANGED
UINT const uWndFlags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED; //~ SWP_NOMOVE | SWP_NOSIZE | SWP_NOREPOSITION
if (pRC) {
SetWindowPos(hWnd, NULL, pRC->left, pRC->top, (pRC->right - pRC->left), (pRC->bottom - pRC->top), uWndFlags);
//~InvalidateRect(hWnd, NULL, TRUE);

View File

@ -5047,15 +5047,16 @@ void EditEnsureSelectionVisible()
//
void EditJumpTo(DocLn iNewLine, DocPos iNewCol)
{
// Line maximum is iMaxLine - 1 (doc line count starts with 0)
DocLn const iMaxLine = SciCall_GetLineCount() - 1;
// jump to end with line set to -1
if (iNewLine < 0) {
if ((iNewLine < 0) || (iNewLine > iMaxLine)) {
SciCall_DocumentEnd();
return;
}
if (iNewLine == 0) { iNewLine = 1; }
DocLn const iMaxLine = SciCall_GetLineCount();
// Line maximum is iMaxLine - 1 (doc line count starts with 0)
iNewLine = (min_ln(iNewLine, iMaxLine) - 1);
DocPos const iLineEndPos = SciCall_GetLineEndPosition(iNewLine);
@ -5065,7 +5066,6 @@ void EditJumpTo(DocLn iNewLine, DocPos iNewCol)
const DocPos iNewPos = SciCall_FindColumn(iNewLine, iNewCol);
SciCall_GotoPos(iNewPos);
EditEnsureSelectionVisible();
}
@ -6335,18 +6335,6 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
if (!s_bSwitchedFindReplace) {
SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(GetFocus()), 1);
}
bool bCloseDlg = false;
if (bIsFindDlg) {
bCloseDlg = sg_pefrData->bFindClose;
}
else if (LOWORD(wParam) != IDOK) {
bCloseDlg = sg_pefrData->bReplaceClose;
}
if (bCloseDlg) {
//EndDialog(hwnd,LOWORD(wParam));
DestroyWindow(hwnd);
}
switch (LOWORD(wParam)) {
case IDOK: // find next
@ -6388,13 +6376,22 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd,UINT umsg,WPARAM wParam
}
break;
}
if (bIsFindDlg && (sg_pefrData->bFindClose)) {
//~EndDialog(hwnd, LOWORD(wParam)); ~ not running own message loop
DestroyWindow(hwnd);
}
else if ((LOWORD(wParam) != IDOK) && sg_pefrData->bReplaceClose) {
//~EndDialog(hwnd, LOWORD(wParam)); ~ not running own message loop
DestroyWindow(hwnd);
}
}
_DelayMarkAll(hwnd, 50, s_InitialSearchStart);
break;
case IDCANCEL:
//EndDialog(hwnd,IDCANCEL);
//~EndDialog(hwnd, IDCANCEL); ~ not running own message loop
DestroyWindow(hwnd);
break;

View File

@ -7388,11 +7388,13 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
case TBN_RESET:
{
int i; int c = (int)SendMessage(Globals.hwndToolbar, TB_BUTTONCOUNT, 0, 0);
for (i = 0; i < c; i++) {
int const count = (int)SendMessage(Globals.hwndToolbar, TB_BUTTONCOUNT, 0, 0);
for (int i = 0; i < count; i++) {
SendMessage(Globals.hwndToolbar, TB_DELETEBUTTON, 0, 0);
}
SendMessage(Globals.hwndToolbar, TB_ADDBUTTONS, COUNTOF(s_tbbMainWnd), (LPARAM)s_tbbMainWnd);
if (Toolbar_SetButtons(Globals.hwndToolbar, IDT_FILE_NEW, Settings.ToolbarButtons, s_tbbMainWnd, COUNTOF(s_tbbMainWnd)) == 0) {
SendMessage(Globals.hwndToolbar, TB_ADDBUTTONS, COUNTOF(s_tbbMainWnd), (LPARAM)s_tbbMainWnd);
}
}
GUARD_RETURN(0);
@ -9717,15 +9719,15 @@ bool FileRevert(LPCWSTR szFileName, bool bIgnoreCmdLnEnc)
}
}
if (bPreserveView) {
EditJumpTo(curLineNum, 0);
}
SciCall_SetSavePoint();
UpdateToolbar();
UpdateStatusbar(true);
UpdateMarginWidth();
if (bPreserveView) {
EditJumpTo(curLineNum + 1, 0);
}
return true;
}

View File

@ -583,6 +583,7 @@
<None Include="..\uchardet\uchardet\src\JISFreq.tab" />
<None Include="..\Versions\Notepad3.exe.manifest.tpl" />
<None Include="..\Versions\VersionEx.h.tpl" />
<None Include=".clang-format" />
<None Include="Notepad3.ver" />
</ItemGroup>
<ItemGroup>

View File

@ -616,6 +616,7 @@
<None Include="..\uchardet\uchardet\src\JISFreq.tab">
<Filter>Source Files\uchardet\LangModels</Filter>
</None>
<None Include=".clang-format" />
</ItemGroup>
<ItemGroup>
<Image Include="..\res\Notepad3.ico">