Last active
August 2, 2021 14:12
-
-
Save sredna/36045ecc4d9aa8ecb2008d7bdeeca4fa to your computer and use it in GitHub Desktop.
RichEdit editor statistics proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define EM_GETEDITORSTATISTICS (WM_USER + ?) // LPARAM=EDITORSTATISTICS*. Returns ESM_* successfully retrieved | |
#define ESM_IPPOS 0x01 // IP row/col | |
#define ESM_LINECOUNT 0x02 // LineCount & EndNL | |
#define ESM_CHARCOUNT 0x04 | |
#define ESM_SELLEN 0x08 | |
#define ESM_STATE 0x10 | |
#define ESM_LANGUAGE 0x20 | |
#define ESS_OVERSTRIKE 0x01 // Insert/overstrike mode | |
#define ESS_READONLY 0x02 | |
#define ESS_CANUNDO 0x04 | |
#define ESS_CANREDO 0x08 | |
#define ESS_WORDWRAP 0x10 | |
#define ESS_MODIFIED 0x20 | |
typedef struct { | |
DWORD Mask; // ESM_* | |
LONG IPRow; | |
LONG IPCol; | |
DWORD LineCount; // Line count, not including word wrapped lines! | |
DWORD CharCount; // Count of characters from all lines, excluding CR/LF. | |
BYTE EndNL; // Does the last line end with CR/LF? | |
BYTE Reserved[3]; | |
DWORD SelLen; | |
DWORD State; // ESS_* | |
LCID Language; // Language @ IP | |
} EDITORSTATISTICS; | |
/* Example: | |
EDITORSTATISTICS es = { ESM_LINECOUNT|ESM_CHARCOUNT|ESM_SELLEN }; | |
LRESULT ret = SendMessage(hEdit, EM_GETEDITORSTATISTICS, 0, (LPARAM) &es); | |
if (!ret) return Error(...); | |
DWORD nllen = g_crlf ? 2 : 1; | |
DWORD totcount = es.CharCount + ((es.LineCount - !es.EndNL) * nllen); | |
SetStatusbarInt(hStatus, PANEL_SELLEN, es.SelLen); | |
SetStatusbarInt(hStatus, PANEL_CHARCOUNT, totcount); | |
*/ | |
// Implementation: | |
DWORD CTxtEdit::GetEditorStatistics(EDITORSTATISTICS*pES) | |
{ | |
DWORD retVal = 0, lineCount, endNL; | |
if (pES->Mask & ESM_IPPOS) | |
{ | |
pES->IPCol = m_ippos_x, pES->IPRow = m_ippos_y; | |
retVal |= ESM_IPPOS; | |
} | |
if (pES->Mask & (ESM_LINECOUNT|ESM_CHARCOUNT)) | |
{ | |
lineCount = GetLineCount(); | |
endNL = ?; | |
} | |
if (pES->Mask & ESM_LINECOUNT) | |
{ | |
pES->LineCount = lineCount; | |
pES->EndNL = endNL; | |
retVal |= ESM_LINECOUNT; | |
} | |
if (pES->Mask & ESM_CHARCOUNT) | |
{ | |
DWORD txtLen = GetTextLength(); // Assumes CR and not CR/LF | |
pES->CharCount = txtLen - (lineCount - !endNL); | |
retVal |= ESM_CHARCOUNT; | |
} | |
if (pES->Mask & ESM_SELLEN) | |
{ | |
CHARRANGE cr; | |
GetSelectionRange(&cr); | |
pES->SelLen = cr.cpMax - cr.cpMin; | |
retVal |= ESM_SELLEN; | |
} | |
if (pES->Mask & ESM_STATE) | |
{ | |
pES->State = 0 | |
| (m_Overstrike ? ESS_OVERSTRIKE : 0) | |
| (m_ReadOnly ? ESS_READONLY : 0) | |
| (CanUndo() ? ESS_CANUNDO : 0) | |
| (CanRedo() ? ESS_CANREDO : 0) | |
| (m_WordWrap ? ESS_WORDWRAP : 0) | |
| (GetModified() ? ESS_MODIFIED : 0); | |
retVal |= ESM_STATE; | |
} | |
if (pES->Mask & ESM_LANGUAGE) | |
{ | |
pES->Language = GetCurrentLCID(); | |
retVal |= ESM_LANGUAGE; | |
} | |
return retVal; | |
} | |
... | |
case EM_GETEDITORSTATISTICS: | |
lResult = GetEditorStatistics((EDITORSTATISTICS*) lParam); | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment