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