Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.4 KiB

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1995 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #include "stdafx2.h"
  12. #include "wordpad.h"
  13. #ifdef AFX_CMNCTL_SEG
  14. #pragma code_seg(AFX_CMNCTL_SEG)
  15. #endif
  16. #ifdef _DEBUG
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. #define new DEBUG_NEW
  21. /////////////////////////////////////////////////////////////////////////////
  22. // _AFX_RICHEDIT2_STATE
  23. _AFX_RICHEDIT2_STATE::~_AFX_RICHEDIT2_STATE()
  24. {
  25. if (m_hInstRichEdit != NULL)
  26. #ifndef _MAC
  27. ::FreeLibrary(m_hInstRichEdit);
  28. #else
  29. REFreeLibrary(m_hInstRichEdit);
  30. #endif
  31. }
  32. _AFX_RICHEDIT2_STATE* AFX_CDECL AfxGetRichEdit2State()
  33. {
  34. return _afxRichEdit2State.GetData();
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CRichEdit2
  38. BOOL CRichEdit2Ctrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  39. {
  40. _AFX_RICHEDIT2_STATE* pState = _afxRichEdit2State;
  41. if (pState->m_hInstRichEdit == NULL)
  42. {
  43. pState->m_hInstRichEdit = LoadLibrary(L"RICHED20.DLL");
  44. if (pState->m_hInstRichEdit == NULL)
  45. return FALSE;
  46. }
  47. CWnd* pWnd = this;
  48. return pWnd->Create(_T("RICHEDIT"), NULL, dwStyle, rect, pParentWnd, nID);
  49. }
  50. int CRichEdit2Ctrl::GetLine(int nIndex, LPTSTR lpszBuffer) const
  51. {
  52. ASSERT(::IsWindow(m_hWnd));
  53. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex,
  54. (LPARAM)lpszBuffer);
  55. }
  56. int CRichEdit2Ctrl::LineIndex(int nLine /* = -1 */) const
  57. {
  58. ASSERT(::IsWindow(m_hWnd));
  59. return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0);
  60. }
  61. int CRichEdit2Ctrl::LineLength(int nLine /* = -1 */) const
  62. {
  63. ASSERT(::IsWindow(m_hWnd));
  64. return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0);
  65. }
  66. void CRichEdit2Ctrl::LineScroll(int nLines, int nChars /* = 0 */)
  67. {
  68. ASSERT(::IsWindow(m_hWnd));
  69. ::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
  70. }
  71. void CRichEdit2Ctrl::SetSel(long nStartChar, long nEndChar)
  72. {
  73. ASSERT(::IsWindow(m_hWnd));
  74. CHARRANGE cr;
  75. cr.cpMin = nStartChar;
  76. cr.cpMax = nEndChar;
  77. ::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  78. }
  79. BOOL CRichEdit2Ctrl::CanPaste(UINT nFormat) const
  80. {
  81. ASSERT(::IsWindow(m_hWnd));
  82. COleMessageFilter* pFilter = AfxOleGetMessageFilter();
  83. if (pFilter != NULL)
  84. pFilter->BeginBusyState();
  85. BOOL b = (BOOL)::SendMessage(m_hWnd, EM_CANPASTE, nFormat, 0L);
  86. if (pFilter != NULL)
  87. pFilter->EndBusyState();
  88. return b;
  89. }
  90. void CRichEdit2Ctrl::PasteSpecial(UINT nClipFormat, DWORD dvAspect, HMETAFILE hMF)
  91. {
  92. ASSERT(::IsWindow(m_hWnd));
  93. REPASTESPECIAL reps;
  94. reps.dwAspect = dvAspect;
  95. reps.dwParam = (DWORD_PTR)hMF;
  96. ::SendMessage(m_hWnd, EM_PASTESPECIAL, nClipFormat, (LPARAM)&reps);
  97. }
  98. int CRichEdit2Ctrl::GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  99. {
  100. ASSERT(::IsWindow(m_hWnd));
  101. *(LPINT)lpszBuffer = nMaxLength;
  102. return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  103. }
  104. void CRichEdit2Ctrl::GetSel(long& nStartChar, long& nEndChar) const
  105. {
  106. ASSERT(::IsWindow(m_hWnd));
  107. CHARRANGE cr;
  108. ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  109. nStartChar = cr.cpMin;
  110. nEndChar = cr.cpMax;
  111. }
  112. CString CRichEdit2Ctrl::GetSelText() const
  113. {
  114. ASSERT(::IsWindow(m_hWnd));
  115. CHARRANGE cr;
  116. LPTSTR lpsz;
  117. cr.cpMin = cr.cpMax = 0;
  118. ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  119. try
  120. {
  121. // Need to use sizeof(WCHAR) to include DBCS characters
  122. lpsz = (TCHAR*)_alloca((cr.cpMax - cr.cpMin + 1)*sizeof(WCHAR));
  123. // lpsz[0] = NULL;
  124. //
  125. // APPCOMPAT: The Ansi richedit2 control does not zero terminate the
  126. // returned string if the current selection contains nothing
  127. // but DBCS characters.
  128. //
  129. ZeroMemory(lpsz, (cr.cpMax - cr.cpMin + 1)*sizeof(WCHAR));
  130. ::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpsz);
  131. }
  132. catch(...)
  133. {
  134. //
  135. // If _alloca fails it will throw an exception. It's ok to return a
  136. // constant string here because it will immediately get copied into
  137. // a CString.
  138. //
  139. _resetstkoflw();
  140. lpsz = TEXT("");
  141. }
  142. return lpsz;
  143. }
  144. IRichEditOle* CRichEdit2Ctrl::GetIRichEditOle() const
  145. {
  146. ASSERT(::IsWindow(m_hWnd));
  147. IRichEditOle *pRichItem = NULL;
  148. ::SendMessage(m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichItem);
  149. return pRichItem;
  150. }
  151. BOOL CRichEdit2Ctrl::SetDefaultCharFormat(CHARFORMAT &cf)
  152. {
  153. ASSERT(::IsWindow(m_hWnd));
  154. cf.cbSize = sizeof(CHARFORMAT);
  155. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  156. }
  157. BOOL CRichEdit2Ctrl::SetSelectionCharFormat(CHARFORMAT &cf)
  158. {
  159. ASSERT(::IsWindow(m_hWnd));
  160. cf.cbSize = sizeof(CHARFORMAT);
  161. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  162. }
  163. BOOL CRichEdit2Ctrl::SetWordCharFormat(CHARFORMAT &cf)
  164. {
  165. ASSERT(::IsWindow(m_hWnd));
  166. cf.cbSize = sizeof(CHARFORMAT);
  167. return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION|SCF_WORD, (LPARAM)&cf);
  168. }
  169. DWORD CRichEdit2Ctrl::GetDefaultCharFormat(CHARFORMAT &cf) const
  170. {
  171. ASSERT(::IsWindow(m_hWnd));
  172. cf.cbSize = sizeof(CHARFORMAT);
  173. return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  174. }
  175. DWORD CRichEdit2Ctrl::GetSelectionCharFormat(CHARFORMAT &cf) const
  176. {
  177. ASSERT(::IsWindow(m_hWnd));
  178. cf.cbSize = sizeof(CHARFORMAT);
  179. return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  180. }
  181. DWORD CRichEdit2Ctrl::GetParaFormat(PARAFORMAT &pf) const
  182. {
  183. ASSERT(::IsWindow(m_hWnd));
  184. pf.cbSize = sizeof(PARAFORMAT);
  185. return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  186. }
  187. BOOL CRichEdit2Ctrl::SetParaFormat(PARAFORMAT &pf)
  188. {
  189. ASSERT(::IsWindow(m_hWnd));
  190. pf.cbSize = sizeof(PARAFORMAT);
  191. return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  192. }
  193. /////////////////////////////////////////////////////////////////////////////
  194. #pragma warning(disable: 4074)
  195. #pragma init_seg(lib)
  196. PROCESS_LOCAL(_AFX_RICHEDIT2_STATE, _afxRichEdit2State)
  197. /////////////////////////////////////////////////////////////////////////////