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)
16 RichEditOnLink(HWND hwnd
, ENLINK
*Link
)
23 if (pLink
) HeapFree(GetProcessHeap(), 0, pLink
);
25 pLink
= (PWSTR
) HeapAlloc(GetProcessHeap(),
27 (max(Link
->chrg
.cpMin
, Link
->chrg
.cpMax
) -
28 min(Link
->chrg
.cpMin
, Link
->chrg
.cpMax
))*sizeof(WCHAR
));
31 /* TODO: Error message */
35 SendMessageW(hRichEdit
, EM_SETSEL
, Link
->chrg
.cpMin
, Link
->chrg
.cpMax
);
36 SendMessageW(hRichEdit
, EM_GETSELTEXT
, 0, (LPARAM
)pLink
);
38 ShowPopupMenu(hwnd
, IDR_LINKMENU
);
45 SetRangeFormatting(LONG Start
, LONG End
, DWORD dwEffects
)
47 CHARFORMAT2 CharFormat
;
49 SendMessageW(hRichEdit
, EM_SETSEL
, Start
, End
);
51 ZeroMemory(&CharFormat
, sizeof(CHARFORMAT2
));
53 CharFormat
.cbSize
= sizeof(CHARFORMAT2
);
54 CharFormat
.dwMask
= dwEffects
;
55 CharFormat
.dwEffects
= dwEffects
;
57 SendMessageW(hRichEdit
, EM_SETCHARFORMAT
, SCF_WORD
| SCF_SELECTION
, (LPARAM
)&CharFormat
);
59 SendMessageW(hRichEdit
, EM_SETSEL
, End
, End
+ 1);
63 GetRichEditTextLen(VOID
)
65 GETTEXTLENGTHEX TxtLenStruct
;
67 TxtLenStruct
.flags
= GTL_NUMCHARS
;
68 TxtLenStruct
.codepage
= 1200;
70 return (LONG
) SendMessageW(hRichEdit
, EM_GETTEXTLENGTHEX
, (WPARAM
)&TxtLenStruct
, 0);
74 * Insert text (without cleaning old text)
82 InsertRichEditText(LPCWSTR lpszText
, DWORD dwEffects
)
85 LONG Len
= GetRichEditTextLen();
88 SetText
.flags
= ST_SELECTION
;
89 SetText
.codepage
= 1200;
91 SendMessageW(hRichEdit
, EM_SETTEXTEX
, (WPARAM
)&SetText
, (LPARAM
)lpszText
);
93 SetRangeFormatting(Len
, Len
+ wcslen(lpszText
),
94 (dwEffects
== CFM_LINK
) ? (PathIsURLW(lpszText
) ? dwEffects
: 0) : dwEffects
);
98 * Clear old text and add new
101 NewRichEditText(LPCWSTR lpszText
, DWORD dwEffects
)
103 SetWindowTextW(hRichEdit
, L
"");
104 InsertRichEditText(lpszText
, dwEffects
);
108 CreateRichEdit(HWND hwnd
)
110 LoadLibraryW(L
"riched20.dll");
112 hRichEdit
= CreateWindowExW(0,
115 WS_CHILD
| WS_VISIBLE
| ES_MULTILINE
|
116 ES_LEFT
| ES_READONLY
,
125 /* TODO: Show error message */
129 SendMessageW(hRichEdit
, EM_SETBKGNDCOLOR
, 0, GetSysColor(COLOR_BTNFACE
));
130 SendMessageW(hRichEdit
, WM_SETFONT
, (WPARAM
)GetStockObject(DEFAULT_GUI_FONT
), 0);
131 SendMessageW(hRichEdit
, EM_SETEVENTMASK
, 0, ENM_LINK
| ENM_MOUSEEVENTS
);
132 SendMessageW(hRichEdit
, EM_SHOWSCROLLBAR
, SB_VERT
, TRUE
);