+ chg: keep found initial common base default font in .ini

+ fix:  slow line-break switching
This commit is contained in:
Rainer Kottenhoff 2021-05-12 20:18:13 +02:00
parent 6ef7853192
commit 920ec7d4ac
7 changed files with 112 additions and 102 deletions

View File

@ -5372,7 +5372,10 @@ void EditSetSelectionEx(DocPos iAnchorPos, DocPos iCurrentPos, DocPos vSpcAnchor
//
void EditEnsureConsistentLineEndings(HWND hwnd)
{
IgnoreNotifyDocChangedEvent(true);
SciCall_ConvertEOLs(SciCall_GetEOLMode());
ObserveNotifyDocChangedEvent();
Globals.bDocHasInconsistentEOLs = false;
EditFixPositions(hwnd);
}

View File

@ -407,9 +407,12 @@ static __forceinline bool CheckNotifyDocChangedEvent()
return (InterlockedOr(&iNotifyChangeStackCounter, 0L) == 0L);
}
void IgnoreNotifyDocChangedEvent()
void IgnoreNotifyDocChangedEvent(const bool bStealthMode)
{
InterlockedIncrement(&iNotifyChangeStackCounter);
if (bStealthMode) {
SciCall_SetModEventMask(SCI_MODEVENTMASK_NONE);
}
}
void ObserveNotifyDocChangedEvent()
@ -418,6 +421,7 @@ void ObserveNotifyDocChangedEvent()
InterlockedDecrement(&iNotifyChangeStackCounter);
}
if (CheckNotifyDocChangedEvent()) {
SciCall_SetModEventMask(SCI_MODEVENTMASK_FULL);
EditUpdateVisibleIndicators();
UpdateStatusbar(false);
}
@ -1887,19 +1891,7 @@ static void _InitializeSciEditCtrl(HWND hwndEditCtrl)
//~~~SciCall_SetIdleStyling(SC_IDLESTYLING_AFTERVISIBLE);
SciCall_SetIdleStyling(SC_IDLESTYLING_ALL);
// The possible notification types are the same as the modificationType bit flags used by SCN_MODIFIED:
// SC_MOD_INSERTTEXT, SC_MOD_DELETETEXT, SC_MOD_CHANGESTYLE, SC_MOD_CHANGEFOLD, SC_PERFORMED_USER,
// SC_PERFORMED_UNDO, SC_PERFORMED_REDO, SC_MULTISTEPUNDOREDO, SC_LASTSTEPINUNDOREDO, SC_MOD_CHANGEMARKER,
// SC_MOD_BEFOREINSERT, SC_MOD_BEFOREDELETE, SC_MULTILINEUNDOREDO, and SC_MODEVENTMASKALL.
//
///~ int const evtMask = SC_MODEVENTMASKALL; (!) - don't listen to all events (SC_MOD_CHANGESTYLE) => RECURSON!
///~ SciCall_SetModEventMask(evtMask);
///~ Don't use: SC_PERFORMED_USER | SC_MOD_CHANGESTYLE;
/// SC_MOD_CHANGESTYLE and SC_MOD_CHANGEINDICATOR needs SCI_SETCOMMANDEVENTS=true
//
int const evtMask1 = SC_MOD_CONTAINER | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MULTILINEUNDOREDO;
int const evtMask2 = SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT | SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE;
SciCall_SetModEventMask(evtMask1 | evtMask2);
SciCall_SetModEventMask(SCI_MODEVENTMASK_FULL);
SciCall_SetCommandEvents(false); // speedup folding
SciCall_StyleSetCharacterSet(SC_CHARSET_DEFAULT);
@ -9686,6 +9678,7 @@ bool FileIO(bool fLoad, LPWSTR pszFileName, EditFileIOStatus *status,
WCHAR tch[MAX_PATH + 40];
FormatLngStringW(tch, COUNTOF(tch), (fLoad) ? IDS_MUI_LOADFILE : IDS_MUI_SAVEFILE, PathFindFileName(pszFileName));
BeginWaitCursor(true, tch);
if (fLoad) {
@ -10000,7 +9993,9 @@ bool FileLoad(LPCWSTR lpszFile, bool bDontSave, bool bNew, bool bReload,
if (bCheckEOL && !Style_MaybeBinaryFile(Globals.hwndEdit, szFilePath)) {
if (WarnLineEndingDlg(Globals.hwndMain, &fioStatus)) {
IgnoreNotifyDocChangedEvent(true);
SciCall_ConvertEOLs(fioStatus.iEOLMode);
ObserveNotifyDocChangedEvent();
Globals.bDocHasInconsistentEOLs = false;
}
SciCall_SetEOLMode(fioStatus.iEOLMode);

View File

@ -138,7 +138,7 @@ int BeginUndoAction();
void EndUndoAction(int token);
bool RestoreAction(int token, DoAction doAct);
#define UndoTransActionBegin() { int const _token_ = BeginUndoAction(); __try { IgnoreNotifyDocChangedEvent();
#define UndoTransActionBegin() { int const _token_ = BeginUndoAction(); __try { IgnoreNotifyDocChangedEvent(false);
#define EndUndoTransAction() } __finally { EndUndoAction(_token_); ObserveNotifyDocChangedEvent(); } }
void HandleDWellStartEnd(const DocPos position, const UINT uid);
@ -189,16 +189,17 @@ LRESULT MsgSysCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam);
// ----------------------------------------------------------------------------
void IgnoreNotifyDocChangedEvent();
void IgnoreNotifyDocChangedEvent(const bool bStealthMode);
void ObserveNotifyDocChangedEvent();
#define DocChangeTransactionBegin() __try { IgnoreNotifyDocChangedEvent();
#define DocChangeTransactionBegin() __try { IgnoreNotifyDocChangedEvent(false);
#define EndDocChangeTransaction() } __finally { ObserveNotifyDocChangedEvent(); }
// ----------------------------------------------------------------------------
#define BeginWaitCursor(cond, text) \
__try { \
IgnoreNotifyDocChangedEvent(); \
IgnoreNotifyDocChangedEvent(true); \
if (cond) { \
SciCall_SetCursor(SC_CURSORWAIT); \
StatusSetText(Globals.hwndStatus, STATUS_HELP, (text)); \
@ -206,7 +207,7 @@ void ObserveNotifyDocChangedEvent();
#define BeginWaitCursorUID(cond, uid) \
__try { \
IgnoreNotifyDocChangedEvent(); \
IgnoreNotifyDocChangedEvent(true); \
if (cond) { \
SciCall_SetCursor(SC_CURSORWAIT); \
StatusSetTextID(Globals.hwndStatus, STATUS_HELP, (uid)); \

View File

@ -8,7 +8,7 @@ EDITLEXER lexStandard =
{
SCLEX_NULL, "null", IDS_LEX_DEF_TXT, L"Common Base", L"", L"",
&KeyWords_NULL, {
/* 0 */ { {STYLE_DEFAULT}, IDS_LEX_STD_STYLE, L"Default Style", L"font:Default", L"" },
/* 0 */ { {STYLE_DEFAULT}, IDS_LEX_STD_STYLE, L"Default Style", L"font:$Code", L"" },
/* 1 */ { {STYLE_LINENUMBER}, IDS_LEX_STD_MARGIN, L"Margins and Line Numbers", L"size:-2; fore:#008080", L"" },
/* 2 */ { {STYLE_BRACELIGHT}, IDS_LEX_STD_BRACE, L"Matching Braces (Indicator)", L"fore:#00FF40; alpha:80; alpha2:80; indic_roundbox", L"" },
/* 3 */ { {STYLE_BRACEBAD}, IDS_LEX_STD_BRACE_FAIL, L"Matching Braces Error (Indicator)", L"fore:#FF0080; alpha:140; alpha2:140; indic_roundbox", L"" },
@ -62,8 +62,9 @@ EDITLEXER lexTEXT =
{
SCLEX_NULL, "null", IDS_LEX_TEXT_FILES, L"Text Files", L"txt; text; tmp; log; asc; doc; wtx", L"",
&KeyWords_NULL,{
//{ {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"font:$Text", L"" },
{ {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"", L"" },
{ {STYLE_LINENUMBER}, IDS_LEX_STD_MARGIN, L"Margins and Line Numbers", L"font:Lucida Console; size:-2", L"" },
{ {STYLE_LINENUMBER}, IDS_LEX_STD_MARGIN, L"Margins and Line Numbers", L"font:Consolas; size:-2", L"" },
{ {SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT}, IDS_LEX_STD_X_SPC, L"Extra Line Spacing (Size)", L"size:-1", L"" },
EDITLEXER_SENTINEL
}

View File

@ -918,17 +918,18 @@ void Style_FileExtToIniSection(bool bForceAll)
void Style_ToIniSection(bool bForceAll)
{
bool const bForceAllNotFromScratch = (bForceAll && !Globals.bIniFileFromScratch);
// Custom colors
const WCHAR* const CustomColors_Section = L"Custom Colors";
for (int i = 0; i < 16; i++) {
WCHAR tch[32] = { L'\0' };
StringCchPrintf(tch, COUNTOF(tch), L"%02i", i + 1);
if ((g_colorCustom[i] != s_colorDefault[i]) || (bForceAll && !Globals.bIniFileFromScratch)) {
if ((g_colorCustom[i] != s_colorDefault[i]) || bForceAllNotFromScratch) {
WCHAR wch[32] = { L'\0' };
StringCchPrintf(wch, COUNTOF(wch), L"#%02X%02X%02X",
(int)GetRValue(g_colorCustom[i]), (int)GetGValue(g_colorCustom[i]), (int)GetBValue(g_colorCustom[i]));
IniSectionSetString(CustomColors_Section, tch, wch);
} else {
IniSectionDelete(CustomColors_Section, tch, false);
@ -958,28 +959,30 @@ void Style_ToIniSection(bool bForceAll)
for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) {
IniSectionSetString(g_pLexArray[iLexer]->pszName, NULL, NULL);
}
bForceAll = !Globals.bIniFileFromScratch;
}
// ----------------------------------------------------------------
WCHAR szTmpStyle[BUFSIZE_STYLE_VALUE] = { L'\0' };
WCHAR wchCurrStyle[BUFSIZE_STYLE_VALUE] = { L'\0' };
for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); ++iLexer) {
LPCWSTR const Lexer_Section = g_pLexArray[iLexer]->pszName;
unsigned i = 0;
while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) {
// normalize defaults
szTmpStyle[0] = L'\0'; // clear
Style_CopyStyles_IfNotDefined(g_pLexArray[iLexer]->Styles[i].pszDefault, szTmpStyle, COUNTOF(szTmpStyle));
if (bForceAll || (StringCchCompareX(g_pLexArray[iLexer]->Styles[i].szValue, szTmpStyle) != 0)) {
// normalize value
szTmpStyle[0] = L'\0'; // clear
Style_CopyStyles_IfNotDefined(g_pLexArray[iLexer]->Styles[i].szValue, szTmpStyle, COUNTOF(szTmpStyle));
IniSectionSetString(Lexer_Section, g_pLexArray[iLexer]->Styles[i].pszName, szTmpStyle);
LPCWSTR const pszName = g_pLexArray[iLexer]->Styles[i].pszName;
LPCWSTR const pszValue = g_pLexArray[iLexer]->Styles[i].szValue;
LPCWSTR const pszDefault = g_pLexArray[iLexer]->Styles[i].pszDefault; // normalized by
// normalize value for comparison
wchCurrStyle[0] = L'\0'; // empty
Style_CopyStyles_IfNotDefined(pszValue, wchCurrStyle, COUNTOF(wchCurrStyle));
if (bForceAllNotFromScratch || (StringCchCompareX(wchCurrStyle, pszDefault) != 0)) {
IniSectionSetString(Lexer_Section, pszName, wchCurrStyle);
} else {
IniSectionDelete(Lexer_Section, g_pLexArray[iLexer]->Styles[i].pszName, false);
IniSectionDelete(Lexer_Section, pszName, false);
}
++i;
}
@ -2635,6 +2638,39 @@ bool Style_GetFileFilterStr(LPWSTR lpszFilter, int cchFilter, LPWSTR lpszDefExt,
return true;
}
//=============================================================================
static inline bool GetDefaultCodeFont(LPWSTR pwchFontName, int cchFont) {
LPCWSTR const FontNamePrioList[] = {
L"Cascadia Code",
L"Fira Code",
L"DejaVu Sans Mono",
L"Consolas",
L"Lucida Console"
};
bool found = false;
for (int i = 0; i < COUNTOF(FontNamePrioList); ++i) {
LPCWSTR const fontName = FontNamePrioList[i];
if (IsFontAvailable(fontName)) {
StringCchCopy(pwchFontName, cchFont, fontName);
found = true;
break;
}
}
if (!found) {
StringCchCopy(pwchFontName, cchFont, L"Courier New"); // fallback
}
return found;
}
static inline unsigned GetDefaultTextFont(LPWSTR pwchFontName) {
WORD wSize = (WORD)LF_FACESIZE;
GetThemedDialogFont(pwchFontName, &wSize);
return wSize;
}
//=============================================================================
//
@ -2654,47 +2690,22 @@ bool Style_StrGetFontName(LPCWSTR lpszStyle, LPWSTR lpszFont, int cchFont)
}
TrimSpcW(lpszFont);
if (StringCchCompareXI(lpszFont, L"Default") == 0) {
// Microsoft's Coding Fonts only
const WCHAR *const FontPrio[4] = { L"Cascadia Code", L"Cascadia Mono", L"Consolas", L"Lucida Console" };
bool found = false;
for (int i = 0; i < COUNTOF(FontPrio); ++i) {
if (IsFontAvailable(FontPrio[i])) {
StringCchCopy(lpszFont, cchFont, FontPrio[i]);
found = true;
break;
}
}
if (!found) {
StringCchCopy(lpszFont, cchFont, L"Courier New");
}
}
return true;
}
return false;
}
if ((StringCchCompareXI(lpszFont, L"$Code") == 0) || (StringCchCompareXI(lpszFont, L"Default") == 0)) {
GetDefaultCodeFont(lpszFont, cchFont);
} else if (StringCchCompareXI(lpszFont, L"$Text") == 0) {
GetDefaultTextFont(lpszFont);
} else if (!IsFontAvailable(lpszFont)) {
GetDefaultCodeFont(lpszFont, cchFont);
//=============================================================================
//
// Style_StrGetFontStyle()
//
bool Style_StrGetFontStyle(LPCWSTR lpszStyle, LPWSTR lpszFontStyle, int cchFontStyle)
{
WCHAR* p = StrStr(lpszStyle, L"fstyle:");
if (p) {
p += CONSTSTRGLEN(L"fstyle:");
while (*p == L' ') {
++p;
}
StringCchCopyN(lpszFontStyle, cchFontStyle, p, cchFontStyle);
if ((p = StrChr(lpszFontStyle, L';')) != NULL) {
*p = L'\0';
}
TrimSpcW(lpszFontStyle);
return true;
return true; // font: defined
}
return false;
return false; // font: not defined
}
@ -3095,34 +3106,21 @@ void Style_CopyStyles_IfNotDefined(LPCWSTR lpszStyleSrc, LPWSTR lpszStyleDest, i
// --------- Font settings ---------
WCHAR wchDefaultFontName[LF_FULLFACESIZE] = { L'\0' };
Style_StrGetFontName(L"font:Default", wchDefaultFontName, COUNTOF(wchDefaultFontName)); // resolve
//~WCHAR wchDefaultCodeFontName[LF_FACESIZE] = { L'\0' };
//~Style_StrGetFontName(L"font:$Code", wchDefaultCodeFontName, COUNTOF(wchDefaultCodeFontName)); // resolve
bool bIsFontDefInDestination = false;
if (Style_StrGetFontName(lpszStyleDest, tch, COUNTOF(tch))) {
bIsFontDefInDestination = true;
if ((StringCchCompareXI(tch, L"Default") == 0) || (StringCchCompareXI(tch, wchDefaultFontName) == 0)) {
AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"font:Default");
} else {
AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"font:");
StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch);
}
AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"font:");
StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch);
} else if (Style_StrGetFontName(lpszStyleSrc, tch, COUNTOF(tch))) {
if ((StringCchCompareXI(tch, L"Default") == 0) || (StringCchCompareXI(tch, wchDefaultFontName) == 0)) {
AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"font:Default");
} else {
AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"font:");
StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch);
}
AppendStyle(szTmpStyle, COUNTOF(szTmpStyle), L"font:");
StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch);
}
// --------- Font Style ---------
//~if (!StrStr(lpszStyleDest, L"fstyle:")) {
//~ if (Style_StrGetFontStyle(lpszStyleSrc, tch, COUNTOF(tch))) {
//~ StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), L"; fstyle:");
//~ StringCchCat(szTmpStyle, COUNTOF(szTmpStyle), tch);
//~ }
//~}
const WCHAR *pFontWeight = NULL;
for (int idx = FW_IDX_THIN; idx <= FW_IDX_ULTRADARK; ++idx) {
@ -3296,34 +3294,30 @@ bool Style_SelectFont(HWND hwnd, LPWSTR lpszStyle, int cchStyle, LPCWSTR sLexerN
LPCWSTR sStyleName, bool bGlobalDefaultStyle, bool bCurrentDefaultStyle) {
// Map lpszStyle to LOGFONT
const WCHAR *const defaultFontTemplate = L"font:Default";
WCHAR wchDefaultFontName[LF_FULLFACESIZE] = { L'\0' };
const WCHAR *const defaultFontTemplate = L"font:$Code";
WCHAR wchDefaultFontName[LF_FACESIZE] = { L'\0' };
Style_StrGetFontName(defaultFontTemplate, wchDefaultFontName, COUNTOF(wchDefaultFontName));
// current base style
const WCHAR *const lpszBaseStyleDefinition = GetCurrentStdLexer()->Styles[STY_DEFAULT].szValue;
// current common default font name setting
WCHAR wchCurrCommonFontName[LF_FULLFACESIZE] = { L'\0' };
WCHAR wchCurrCommonFontName[LF_FACESIZE] = { L'\0' };
if (!Style_StrGetFontName(lpszBaseStyleDefinition, wchCurrCommonFontName, COUNTOF(wchCurrCommonFontName))) {
StringCchCopy(wchCurrCommonFontName, COUNTOF(wchCurrCommonFontName), wchDefaultFontName);
}
// specified font name
WCHAR wchFontName[LF_FULLFACESIZE] = { L'\0' };
WCHAR wchFontName[LF_FACESIZE] = { L'\0' };
if (!Style_StrGetFontName(lpszStyle, wchFontName, COUNTOF(wchFontName))) {
StringCchCopy(wchFontName, COUNTOF(wchFontName), wchCurrCommonFontName);
}
// font style
DWORD const flagUseStyle = 0; // = CF_USESTYLE; ~ don't use
// NOTE: To globalize your application, you should specify the style by using
// the lfWeight and lfItalic members of the LOGFONT structure pointed to by lpLogFont.
// The style name may change depending on the system user interface language.
//~WCHAR szStyleStrg[LF_FULLFACESIZE] = { L'\0' };
//~if (flagUseStyle) {
//~ Style_StrGetFontStyle(lpszStyle, szStyleStrg, COUNTOF(szStyleStrg));
//~}
DWORD const flagUseStyle = 0; // = CF_USESTYLE; ~ don't use
// Font Weight
int iBaseFontWeight = FontWeights[FW_IDX_REGULAR].weight;
@ -3606,7 +3600,7 @@ void Style_SetStyles(HWND hwnd, const int iStyle, LPCWSTR lpszStyle)
SciCall_StyleSetFont(iStyle, chFontName);
}
} else if (bIsDefaultStyle) {
Style_StrGetFontName(L"font:Default", wchFontName, COUNTOF(wchFontName));
Style_StrGetFontName(L"font:$Code", wchFontName, COUNTOF(wchFontName));
assert(lstrlen(wchFontName) < LF_FACESIZE);
char chFontName[LF_FACESIZE] = { '\0' };
WideCharToMultiByte(CP_UTF8, 0, wchFontName, -1, chFontName, (int)COUNTOF(chFontName), NULL, NULL);

View File

@ -72,7 +72,6 @@ void Style_SetIndentGuides(HWND hwnd,bool);
void Style_SetExtraLineSpace(HWND hwnd, LPWSTR lpszStyle, int cch);
bool Style_GetFileFilterStr(LPWSTR lpszFilter, int cchFilter, LPWSTR lpszDefExt, int cchExt, bool bSaveAs);
bool Style_StrGetFontName(LPCWSTR lpszStyle,LPWSTR lpszFont,int cchFont);
bool Style_StrGetFontStyle(LPCWSTR lpszStyle,LPWSTR lpszFontStyle,int cchFontStyle);
bool Style_StrGetFontQuality(LPCWSTR lpszStyle, LPWSTR lpszQuality, int cchQuality, int *iSciQuality_out);
bool Style_StrGetCharSet(LPCWSTR lpszStyle,int* i);
bool Style_StrGetSizeInt(LPCWSTR lpszStyle, int* i);

View File

@ -732,6 +732,23 @@ typedef struct _themeFiles
// don't use 'SCVS_NOWRAPLINESTART'
#define NP3_VIRTUAL_SPACE_ACCESS_OPTIONS (Settings2.DenyVirtualSpaceAccess ? SCVS_NONE : SCVS_RECTANGULARSELECTION)
// The possible notification types are the same as the modificationType bit flags used by SCN_MODIFIED:
// SC_MOD_INSERTTEXT, SC_MOD_DELETETEXT, SC_MOD_CHANGESTYLE, SC_MOD_CHANGEFOLD, SC_PERFORMED_USER,
// SC_PERFORMED_UNDO, SC_PERFORMED_REDO, SC_MULTISTEPUNDOREDO, SC_LASTSTEPINUNDOREDO, SC_MOD_CHANGEMARKER,
// SC_MOD_BEFOREINSERT, SC_MOD_BEFOREDELETE, SC_MULTILINEUNDOREDO, and SC_MODEVENTMASKALL.
//
///~ int const evtMask = SC_MODEVENTMASKALL; (!) - don't listen to all events (SC_MOD_CHANGESTYLE) => RECURSON!
///~ SciCall_SetModEventMask(evtMask);
///~ Don't use: SC_PERFORMED_USER | SC_MOD_CHANGESTYLE;
/// SC_MOD_CHANGESTYLE and SC_MOD_CHANGEINDICATOR needs SCI_SETCOMMANDEVENTS=true
//
#define SCI_MODEVENTMASK_FULL (SC_MOD_CONTAINER | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MULTILINEUNDOREDO | \
SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT | SC_MOD_BEFOREINSERT | SC_MOD_BEFOREDELETE)
#define SCI_MODEVENTMASK_NONE (SC_MOD_NONE)
// from <wininet.h>
#define INTERNET_MAX_PATH_LENGTH 2048
#define INTERNET_MAX_SCHEME_LENGTH 32 // longest protocol name length