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