Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenrichedit.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Applications Manager 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: base/applications/rapps/richedit.c 00005 * PURPOSE: RichEdit functions 00006 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org) 00007 */ 00008 00009 #include "rapps.h" 00010 00011 HWND hRichEdit; 00012 PWSTR pLink = NULL; 00013 00014 00015 VOID 00016 RichEditOnLink(HWND hwnd, ENLINK *Link) 00017 { 00018 switch (Link->msg) 00019 { 00020 case WM_LBUTTONUP: 00021 case WM_RBUTTONUP: 00022 { 00023 if (pLink) HeapFree(GetProcessHeap(), 0, pLink); 00024 00025 pLink = (PWSTR) HeapAlloc(GetProcessHeap(), 00026 0, 00027 (max(Link->chrg.cpMin, Link->chrg.cpMax) - 00028 min(Link->chrg.cpMin, Link->chrg.cpMax))*sizeof(WCHAR)); 00029 if (!pLink) 00030 { 00031 /* TODO: Error message */ 00032 return; 00033 } 00034 00035 SendMessageW(hRichEdit, EM_SETSEL, Link->chrg.cpMin, Link->chrg.cpMax); 00036 SendMessageW(hRichEdit, EM_GETSELTEXT, 0, (LPARAM)pLink); 00037 00038 ShowPopupMenu(hwnd, IDR_LINKMENU); 00039 } 00040 break; 00041 } 00042 } 00043 00044 static VOID 00045 SetRangeFormatting(LONG Start, LONG End, DWORD dwEffects) 00046 { 00047 CHARFORMAT2 CharFormat; 00048 00049 SendMessageW(hRichEdit, EM_SETSEL, Start, End); 00050 00051 ZeroMemory(&CharFormat, sizeof(CHARFORMAT2)); 00052 00053 CharFormat.cbSize = sizeof(CHARFORMAT2); 00054 CharFormat.dwMask = dwEffects; 00055 CharFormat.dwEffects = dwEffects; 00056 00057 SendMessageW(hRichEdit, EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM)&CharFormat); 00058 00059 SendMessageW(hRichEdit, EM_SETSEL, End, End + 1); 00060 } 00061 00062 static LONG 00063 GetRichEditTextLen(VOID) 00064 { 00065 GETTEXTLENGTHEX TxtLenStruct; 00066 00067 TxtLenStruct.flags = GTL_NUMCHARS; 00068 TxtLenStruct.codepage = 1200; 00069 00070 return (LONG) SendMessageW(hRichEdit, EM_GETTEXTLENGTHEX, (WPARAM)&TxtLenStruct, 0); 00071 } 00072 00073 /* 00074 * Insert text (without cleaning old text) 00075 * Supported effects: 00076 * - CFM_BOLD 00077 * - CFM_ITALIC 00078 * - CFM_UNDERLINE 00079 * - CFM_LINK 00080 */ 00081 VOID 00082 InsertRichEditText(LPCWSTR lpszText, DWORD dwEffects) 00083 { 00084 SETTEXTEX SetText; 00085 LONG Len = GetRichEditTextLen(); 00086 00087 /* Insert new text */ 00088 SetText.flags = ST_SELECTION; 00089 SetText.codepage = 1200; 00090 00091 SendMessageW(hRichEdit, EM_SETTEXTEX, (WPARAM)&SetText, (LPARAM)lpszText); 00092 00093 SetRangeFormatting(Len, Len + wcslen(lpszText), 00094 (dwEffects == CFM_LINK) ? (PathIsURLW(lpszText) ? dwEffects : 0) : dwEffects); 00095 } 00096 00097 /* 00098 * Clear old text and add new 00099 */ 00100 VOID 00101 NewRichEditText(LPCWSTR lpszText, DWORD dwEffects) 00102 { 00103 SetWindowTextW(hRichEdit, L""); 00104 InsertRichEditText(lpszText, dwEffects); 00105 } 00106 00107 BOOL 00108 CreateRichEdit(HWND hwnd) 00109 { 00110 LoadLibraryW(L"riched20.dll"); 00111 00112 hRichEdit = CreateWindowExW(0, 00113 L"RichEdit20W", 00114 NULL, 00115 WS_CHILD | WS_VISIBLE | ES_MULTILINE | 00116 ES_LEFT | ES_READONLY, 00117 205, 28, 465, 100, 00118 hwnd, 00119 NULL, 00120 hInst, 00121 NULL); 00122 00123 if (!hRichEdit) 00124 { 00125 /* TODO: Show error message */ 00126 return FALSE; 00127 } 00128 00129 SendMessageW(hRichEdit, EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE)); 00130 SendMessageW(hRichEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0); 00131 SendMessageW(hRichEdit, EM_SETEVENTMASK, 0, ENM_LINK | ENM_MOUSEEVENTS); 00132 SendMessageW(hRichEdit, EM_SHOWSCROLLBAR, SB_VERT, TRUE); 00133 00134 return TRUE; 00135 } Generated on Sun May 27 2012 04:17:23 for ReactOS by
1.7.6.1
|