mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-11 21:03:05 +08:00
+ rfc: moving common methods to helper module
This commit is contained in:
parent
29125b8227
commit
bd5d443f2a
@ -2826,6 +2826,76 @@ void UrlUnescapeEx(LPWSTR lpURL, LPWSTR lpUnescaped, DWORD* pcchUnescaped)
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// ReadStrgsFromCSV()
|
||||
//
|
||||
//
|
||||
int ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int const iCount, int const iLen, LPCWSTR sDefault)
|
||||
{
|
||||
static WCHAR wchTmpBuff[MIDSZ_BUFFER];
|
||||
|
||||
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchCSVStrg);
|
||||
TrimString(wchTmpBuff);
|
||||
// separate values
|
||||
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (wchTmpBuff[i] == L',') { wchTmpBuff[i] = L'\0'; }
|
||||
}
|
||||
// fill default
|
||||
for (int i = 0; i < iCount; ++i) { StringCchCopyW(sMatrix[i], (size_t)iLen, sDefault); }
|
||||
// insert values
|
||||
int n = 0;
|
||||
WCHAR* p = wchTmpBuff;
|
||||
while (*p) {
|
||||
if (n < iCount) {
|
||||
StringCchCopyW(sMatrix[n++], (size_t)iLen, p);
|
||||
}
|
||||
p = StrEnd(p) + 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// ReadVectorFromString()
|
||||
//
|
||||
//
|
||||
int ReadVectorFromString(LPCWSTR wchStrg, int* iVector, int iCount, int iMin, int iMax, int iDefault)
|
||||
{
|
||||
static WCHAR wchTmpBuff[SMALL_BUFFER];
|
||||
|
||||
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchStrg);
|
||||
TrimString(wchTmpBuff);
|
||||
// ensure single spaces only
|
||||
WCHAR *p = StrStr(wchTmpBuff, L" ");
|
||||
while (p) {
|
||||
MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR));
|
||||
p = StrStr(wchTmpBuff, L" "); // next
|
||||
}
|
||||
// separate values
|
||||
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (wchTmpBuff[i] == L' ') { wchTmpBuff[i] = L'\0'; }
|
||||
}
|
||||
// fill default
|
||||
for (int i = 0; i < iCount; ++i) { iVector[i] = iDefault; }
|
||||
// insert values
|
||||
int n = 0;
|
||||
p = wchTmpBuff;
|
||||
while (*p) {
|
||||
int iValue;
|
||||
if (swscanf_s(p, L"%i", &iValue) == 1) {
|
||||
if ((n < iCount) && (iValue >= iMin) && (iValue <= iMax)) {
|
||||
iVector[n++] = iValue;
|
||||
}
|
||||
}
|
||||
p = StrEnd(p) + 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
@ -389,9 +389,11 @@ __forceinline int GetHexDigit(char ch) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UrlUnescapeEx(LPWSTR, LPWSTR, DWORD*);
|
||||
|
||||
int ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int const iCount, int const iLen, LPCWSTR sDefault);
|
||||
int ReadVectorFromString(LPCWSTR wchStrg, int* iVector, int iCount, int iMin, int iMax, int iDefault);
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// including <pathcch.h> and linking against pathcch.lib
|
||||
@ -402,6 +404,8 @@ __forceinline HRESULT PathCchCanonicalize(PWSTR p,size_t l,PCWSTR a) { UNUSED
|
||||
__forceinline HRESULT PathCchRenameExtension(PWSTR p,size_t l,PCWSTR a) { UNUSED(l); return (PathRenameExtension(p,a) ? S_OK : E_FAIL); }
|
||||
__forceinline HRESULT PathCchRemoveFileSpec(PWSTR p,size_t l) { UNUSED(l); return (PathRemoveFileSpec(p) ? S_OK : E_FAIL); }
|
||||
|
||||
|
||||
|
||||
// special Drag and Drop Handling
|
||||
|
||||
typedef struct tDROPDATA
|
||||
|
||||
@ -733,83 +733,10 @@ bool InitApplication(HINSTANCE hInstance)
|
||||
|
||||
}
|
||||
|
||||
|
||||
typedef WCHAR prefix_t[MICRO_BUFFER];
|
||||
static prefix_t g_mxStatusBarPrefix[STATUS_SECTOR_COUNT];
|
||||
static int g_vStatusbarSectionWidth[STATUS_SECTOR_COUNT];
|
||||
static int g_aSBSOrder[STATUS_SECTOR_COUNT];
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// _ReadVectorFromString()
|
||||
//
|
||||
//
|
||||
static int __fastcall _ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int const iCount, int const iLen, LPCWSTR sDefault)
|
||||
{
|
||||
static WCHAR wchTmpBuff[MIDSZ_BUFFER];
|
||||
|
||||
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchCSVStrg);
|
||||
TrimString(wchTmpBuff);
|
||||
// separate values
|
||||
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (wchTmpBuff[i] == L',') { wchTmpBuff[i] = L'\0'; }
|
||||
}
|
||||
// fill default
|
||||
for (int i = 0; i < iCount; ++i) { StringCchCopyW(sMatrix[i], (size_t)iLen, sDefault); }
|
||||
// insert values
|
||||
int n = 0;
|
||||
WCHAR* p = wchTmpBuff;
|
||||
while (*p) {
|
||||
if (n < iCount) {
|
||||
StringCchCopyW(sMatrix[n++], (size_t)iLen, p);
|
||||
}
|
||||
p = StrEnd(p) + 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// _ReadVectorFromString()
|
||||
//
|
||||
//
|
||||
static int __fastcall _ReadVectorFromString(LPCWSTR wchStrg, int* iVector, int iCount, int iMin, int iMax, int iDefault)
|
||||
{
|
||||
static WCHAR wchTmpBuff[SMALL_BUFFER];
|
||||
|
||||
StringCchCopyW(wchTmpBuff, COUNTOF(wchTmpBuff), wchStrg);
|
||||
TrimString(wchTmpBuff);
|
||||
// ensure single spaces only
|
||||
WCHAR *p = StrStr(wchTmpBuff, L" ");
|
||||
while (p) {
|
||||
MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR));
|
||||
p = StrStr(wchTmpBuff, L" "); // next
|
||||
}
|
||||
// separate values
|
||||
int const len = (int)StringCchLenW(wchTmpBuff, COUNTOF(wchTmpBuff));
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (wchTmpBuff[i] == L' ') { wchTmpBuff[i] = L'\0'; }
|
||||
}
|
||||
// fill default
|
||||
for (int i = 0; i < iCount; ++i) { iVector[i] = iDefault; }
|
||||
// insert values
|
||||
int n = 0;
|
||||
p = wchTmpBuff;
|
||||
while (*p) {
|
||||
int iValue;
|
||||
if (swscanf_s(p, L"%i", &iValue) == 1) {
|
||||
if ((n < iCount) && (iValue >= iMin) && (iValue <= iMax)) {
|
||||
iVector[n++] = iValue;
|
||||
}
|
||||
}
|
||||
p = StrEnd(p) + 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// _StatusbarSetSections()
|
||||
@ -827,10 +754,10 @@ static void __fastcall _StatusbarSetSections(int cx)
|
||||
}
|
||||
|
||||
int vSections[STATUS_SECTOR_COUNT];
|
||||
_ReadVectorFromString(g_tchStatusbarSections, vSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1);
|
||||
ReadVectorFromString(g_tchStatusbarSections, vSections, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), -1);
|
||||
|
||||
int vWeights[STATUS_SECTOR_COUNT];
|
||||
_ReadVectorFromString(g_tchStatusbarRelWidths, vWeights, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), 1);
|
||||
ReadVectorFromString(g_tchStatusbarRelWidths, vWeights, STATUS_SECTOR_COUNT, 0, (STATUS_SECTOR_COUNT - 1), 1);
|
||||
|
||||
int cnt = 0;
|
||||
int totalWeight = 0;
|
||||
@ -954,7 +881,7 @@ static void __fastcall _InitWindowPosition(HWND hwnd)
|
||||
}
|
||||
}
|
||||
|
||||
_ReadStrgsFromCSV(g_tchStatusbarPrefixes, g_mxStatusBarPrefix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"");
|
||||
ReadStrgsFromCSV(g_tchStatusbarPrefixes, g_mxStatusBarPrefix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"");
|
||||
|
||||
_StatusbarSetSections(g_WinInfo.cx);
|
||||
}
|
||||
|
||||
@ -80,6 +80,9 @@ typedef enum { MBINFO = 0, MBWARN, MBYESNO, MBYESNOWARN, MBYESNOCANCEL, MBOKCANC
|
||||
|
||||
|
||||
//==== Statusbar ==============================================================
|
||||
|
||||
typedef WCHAR prefix_t[MICRO_BUFFER];
|
||||
|
||||
typedef enum {
|
||||
STATUS_DOCLINE = 0, STATUS_DOCCOLUMN, STATUS_SELECTION, STATUS_SELCTLINES, STATUS_OCCURRENCE,
|
||||
STATUS_DOCSIZE, STATUS_CODEPAGE, STATUS_EOLMODE, STATUS_OVRMODE, STATUS_2ND_DEF, STATUS_LEXER,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user