Skip to content

Commit

Permalink
Make Notepad2 per monitor DPI aware.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Sep 13, 2017
1 parent f4984a5 commit 8d42f6f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion metapath/res/metapath.exe.manifest
Expand Up @@ -36,7 +36,7 @@
</compatibility>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/pm</dpiAware>
<dpiAware>true/PM</dpiAware>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<dpiAwareness>PerMonitorV2,PerMonitor</dpiAwareness>
Expand Down
4 changes: 2 additions & 2 deletions res/Notepad2.exe.manifest
Expand Up @@ -37,13 +37,13 @@
</compatibility>
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true/pm</dpiAware>
<dpiAware>true/PM</dpiAware>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<dpiAwareness>PerMonitorV2,PerMonitor</dpiAwareness>
</asmv3:windowsSettings>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">
<gdiScaling>true</gdiScaling>
<gdiScaling>false</gdiScaling>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
2 changes: 1 addition & 1 deletion scintilla/src/Editor.cxx
Expand Up @@ -993,7 +993,7 @@ void Editor::VerticalCentreCaret() {

// Avoid 64 bit compiler warnings.
// Scintilla does not support text buffers larger than 2**31
static int istrlen(const char *s) {
static inline int istrlen(const char *s) {
return static_cast<int>(s ? strlen(s) : 0);
}

Expand Down
8 changes: 8 additions & 0 deletions src/Dialogs.h
Expand Up @@ -34,6 +34,14 @@
*/
#define APPM_CENTER_MESSAGE_BOX (WM_APP + 1)

// https://msdn.microsoft.com/en-us/library/windows/desktop/dn312083(v=vs.85).aspx
#ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02E0
#endif
#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
#endif

int MsgBox(int iType, UINT uIdMsg, ...);
void DisplayCmdLineHelp(HWND hwnd);
BOOL GetDirectory(HWND hwndParent, int iTitle, LPWSTR pszFolder, LPCWSTR pszBase, BOOL bNewDialogStyle);
Expand Down
13 changes: 13 additions & 0 deletions src/Notepad2.c
Expand Up @@ -1348,6 +1348,19 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
}
break;

case WM_DPICHANGED: {
int dpi = HIWORD(wParam);
RECT* const rc = (RECT *)lParam;
#if 0
char buf[64];
sprintf(buf, "WM_DPICHANGED: dpi=%d\n", dpi);
SendMessage(hwndEdit, SCI_INSERTTEXT, 0, (LPARAM)buf);
#endif
SetWindowPos(hwnd, NULL, rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top, SWP_NOZORDER | SWP_NOACTIVATE);
Style_OnDPIChanged(hwndEdit, dpi);
}
break;

case APPM_CENTER_MESSAGE_BOX: {
HWND box = FindWindow(L"#32770", NULL);
HWND parent = GetParent(box);
Expand Down
9 changes: 9 additions & 0 deletions src/Styles.c
Expand Up @@ -190,6 +190,7 @@ BOOL bUse2ndDefaultStyle;
BOOL fStylesModified = FALSE;
BOOL fWarnedNoIniFile = FALSE;
int iBaseFontSize = 11;
int iCurrentDPI = USER_DEFAULT_SCREEN_DPI;
int iDefaultLexer;
BOOL bAutoSelect;
int cxStyleSelectDlg;
Expand Down Expand Up @@ -452,6 +453,13 @@ BOOL Style_Export(HWND hwnd) {
return FALSE;
}

void Style_OnDPIChanged(HWND hwnd, int dpi) {
if (iCurrentDPI != dpi) {
iCurrentDPI = dpi;
Style_SetLexer(hwnd, pLexCurrent);
}
}

// set folding style; braces are for scoping only
static const int iMarkerIDs[] = {
SC_MARKNUM_FOLDEROPEN,
Expand Down Expand Up @@ -2445,6 +2453,7 @@ void Style_SetStyles(HWND hwnd, int iStyle, LPCWSTR lpszStyle) {

// Size
if (Style_StrGetSize(lpszStyle, &iValue)) {
iValue = MulDiv(iValue, iCurrentDPI, USER_DEFAULT_SCREEN_DPI);
SendMessage(hwnd, SCI_STYLESETSIZE, iStyle, (LPARAM)iValue);
}

Expand Down
1 change: 1 addition & 0 deletions src/Styles.h
Expand Up @@ -56,6 +56,7 @@ void Style_Save(void);
BOOL Style_Import(HWND hwnd);
BOOL Style_Export(HWND hwnd);

void Style_OnDPIChanged(HWND hwnd, int dpi);
void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew);
void Style_SetLexerFromFile(HWND hwnd, LPCWSTR lpszFile);
void Style_SetLexerFromName(HWND hwnd, LPCWSTR lpszFile, LPCWSTR lpszName);
Expand Down

0 comments on commit 8d42f6f

Please sign in to comment.