63c5b626d881bab0c18ad374a4b2f63b2f23ad5d
[reactos.git] / reactos / base / applications / rapps / crichedit.h
1 #pragma once
2
3 class CRichEdit :
4 public CWindow
5 {
6 public:
7 VOID SetRangeFormatting(LONG Start, LONG End, DWORD dwEffects)
8 {
9 CHARFORMAT2 CharFormat;
10
11 SendMessageW(EM_SETSEL, Start, End);
12
13 ZeroMemory(&CharFormat, sizeof(CharFormat));
14
15 CharFormat.cbSize = sizeof(CharFormat);
16 CharFormat.dwMask = dwEffects;
17 CharFormat.dwEffects = dwEffects;
18
19 SendMessageW(EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM) &CharFormat);
20
21 SendMessageW(EM_SETSEL, End, End + 1);
22 }
23
24 LONG GetTextLen(VOID)
25 {
26 GETTEXTLENGTHEX TxtLenStruct;
27
28 TxtLenStruct.flags = GTL_NUMCHARS;
29 TxtLenStruct.codepage = 1200;
30
31 return (LONG) SendMessageW(EM_GETTEXTLENGTHEX, (WPARAM) &TxtLenStruct, 0);
32 }
33
34 /*
35 * Insert text (without cleaning old text)
36 * Supported effects:
37 * - CFM_BOLD
38 * - CFM_ITALIC
39 * - CFM_UNDERLINE
40 * - CFM_LINK
41 */
42 VOID InsertText(LPCWSTR lpszText, DWORD dwEffects)
43 {
44 SETTEXTEX SetText;
45 LONG Len = GetTextLen();
46
47 /* Insert new text */
48 SetText.flags = ST_SELECTION;
49 SetText.codepage = 1200;
50
51 SendMessageW(EM_SETTEXTEX, (WPARAM) &SetText, (LPARAM) lpszText);
52
53 SetRangeFormatting(Len, Len + wcslen(lpszText),
54 (dwEffects == CFM_LINK) ? (PathIsURLW(lpszText) ? dwEffects : 0) : dwEffects);
55 }
56
57 /*
58 * Clear old text and add new
59 */
60 VOID SetText(LPCWSTR lpszText, DWORD dwEffects)
61 {
62 SetWindowTextW(L"");
63 InsertText(lpszText, dwEffects);
64 }
65
66 HWND Create(HWND hwndParent)
67 {
68 // TODO: FreeLibrary when the window is destroyed
69 LoadLibraryW(L"riched20.dll");
70
71 m_hWnd = CreateWindowExW(0,
72 L"RichEdit20W",
73 NULL,
74 WS_CHILD | WS_VISIBLE | ES_MULTILINE |
75 ES_LEFT | ES_READONLY,
76 205, 28, 465, 100,
77 hwndParent,
78 NULL,
79 _AtlBaseModule.GetModuleInstance(),
80 NULL);
81
82 if (m_hWnd)
83 {
84 SendMessageW(EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE));
85 SendMessageW(WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
86 SendMessageW(EM_SETEVENTMASK, 0, ENM_LINK | ENM_MOUSEEVENTS);
87 SendMessageW(EM_SHOWSCROLLBAR, SB_VERT, TRUE);
88 }
89
90 return m_hWnd;
91 }
92
93 virtual VOID OnLink(ENLINK *Link)
94 {
95 }
96
97 };