2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/richedit.c
5 * PURPOSE: RichEdit functions
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
17 RichEditOnLink(HWND hwnd
, ENLINK
*Link
)
24 if (pLink
) HeapFree(GetProcessHeap(), 0, pLink
);
26 pLink
= HeapAlloc(GetProcessHeap(),
28 (max(Link
->chrg
.cpMin
, Link
->chrg
.cpMax
) -
29 min(Link
->chrg
.cpMin
, Link
->chrg
.cpMax
) + 1) * sizeof(WCHAR
));
32 /* TODO: Error message */
36 SendMessageW(hRichEdit
, EM_SETSEL
, Link
->chrg
.cpMin
, Link
->chrg
.cpMax
);
37 SendMessageW(hRichEdit
, EM_GETSELTEXT
, 0, (LPARAM
)pLink
);
39 ShowPopupMenu(hwnd
, IDR_LINKMENU
, -1);
46 SetRangeFormatting(LONG Start
, LONG End
, DWORD dwEffects
)
48 CHARFORMAT2 CharFormat
;
50 SendMessageW(hRichEdit
, EM_SETSEL
, Start
, End
);
52 ZeroMemory(&CharFormat
, sizeof(CharFormat
));
54 CharFormat
.cbSize
= sizeof(CharFormat
);
55 CharFormat
.dwMask
= dwEffects
;
56 CharFormat
.dwEffects
= dwEffects
;
58 SendMessageW(hRichEdit
, EM_SETCHARFORMAT
, SCF_WORD
| SCF_SELECTION
, (LPARAM
)&CharFormat
);
60 SendMessageW(hRichEdit
, EM_SETSEL
, End
, End
+ 1);
64 GetRichEditTextLen(VOID
)
66 GETTEXTLENGTHEX TxtLenStruct
;
68 TxtLenStruct
.flags
= GTL_NUMCHARS
;
69 TxtLenStruct
.codepage
= 1200;
71 return (LONG
) SendMessageW(hRichEdit
, EM_GETTEXTLENGTHEX
, (WPARAM
)&TxtLenStruct
, 0);
75 * Insert text (without cleaning old text)
83 InsertRichEditText(LPCWSTR lpszText
, DWORD dwEffects
)
86 LONG Len
= GetRichEditTextLen();
89 SetText
.flags
= ST_SELECTION
;
90 SetText
.codepage
= 1200;
92 SendMessageW(hRichEdit
, EM_SETTEXTEX
, (WPARAM
)&SetText
, (LPARAM
)lpszText
);
94 SetRangeFormatting(Len
, Len
+ wcslen(lpszText
),
95 (dwEffects
== CFM_LINK
) ? (PathIsURLW(lpszText
) ? dwEffects
: 0) : dwEffects
);
99 * Clear old text and add new
102 NewRichEditText(LPCWSTR lpszText
, DWORD dwEffects
)
104 SetWindowTextW(hRichEdit
, L
"");
105 InsertRichEditText(lpszText
, dwEffects
);
109 CreateRichEdit(HWND hwnd
)
111 LoadLibraryW(L
"riched20.dll");
113 hRichEdit
= CreateWindowExW(0,
116 WS_CHILD
| WS_VISIBLE
| ES_MULTILINE
|
117 ES_LEFT
| ES_READONLY
,
126 /* TODO: Show error message */
130 SendMessageW(hRichEdit
, EM_SETBKGNDCOLOR
, 0, GetSysColor(COLOR_BTNFACE
));
131 SendMessageW(hRichEdit
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), 0);
132 SendMessageW(hRichEdit
, EM_SETEVENTMASK
, 0, ENM_LINK
| ENM_MOUSEEVENTS
);
133 SendMessageW(hRichEdit
, EM_SHOWSCROLLBAR
, SB_VERT
, TRUE
);