home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / WINCTRL4.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-15  |  6.7 KB  |  250 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 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.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_CMNCTL_SEG
  14. #pragma code_seg(AFX_CMNCTL_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. #ifndef _AFX_NO_RICHEDIT_SUPPORT
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // _AFX_RICHEDIT_STATE
  28.  
  29. _AFX_RICHEDIT_STATE::~_AFX_RICHEDIT_STATE()
  30. {
  31.     if (m_hInstRichEdit != NULL)
  32. #ifndef _MAC
  33.         ::FreeLibrary(m_hInstRichEdit);
  34. #else
  35.         REFreeLibrary(m_hInstRichEdit);
  36. #endif
  37. }
  38.  
  39. _AFX_RICHEDIT_STATE* AFX_CDECL AfxGetRichEditState()
  40. {
  41.     return _afxRichEditState.GetData();
  42. }
  43.  
  44. BOOL PASCAL AfxInitRichEdit()
  45. {
  46.     _AFX_RICHEDIT_STATE* pState = _afxRichEditState;
  47.     if (pState->m_hInstRichEdit == NULL)
  48. #ifndef _MAC
  49.         pState->m_hInstRichEdit = LoadLibraryA("RICHED32.DLL");
  50. #else
  51. #ifndef _AFXDLL
  52.         // Ordinarily the __gForceREInit reference would be produced by richedit.h, but
  53.         // MFC builds with _WLM_NOFORCE_LIBS, which prevents richedit.h from generating
  54.         // the reference.
  55.         pState->m_hInstRichEdit = ((HINSTANCE)__gForceREInit), RELoadLibrary();
  56. #else
  57.         pState->m_hInstRichEdit = RELoadLibrary();
  58. #endif
  59. #endif
  60.     ASSERT(pState->m_hInstRichEdit != NULL);
  61.     return (pState->m_hInstRichEdit != NULL && 
  62.         AfxDeferRegisterClass(AFX_WNDCOMMCTLS_REG));
  63. }
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CRichEdit
  67.  
  68. #ifdef _MAC
  69. extern "C" int __gForceREInit;
  70. #endif
  71.  
  72. BOOL CRichEditCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  73. {
  74.     if (!AfxInitRichEdit())
  75.         return FALSE;
  76.  
  77.     CWnd* pWnd = this;
  78.     return pWnd->Create(_T("RICHEDIT"), NULL, dwStyle, rect, pParentWnd, nID);
  79. }
  80.  
  81. int CRichEditCtrl::GetLine(int nIndex, LPTSTR lpszBuffer) const
  82. {
  83.     ASSERT(::IsWindow(m_hWnd));
  84.     return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex,
  85.         (LPARAM)lpszBuffer);
  86. }
  87.  
  88. int CRichEditCtrl::LineIndex(int nLine /* = -1 */) const
  89. {
  90.     ASSERT(::IsWindow(m_hWnd));
  91.     return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0);
  92. }
  93.  
  94. int CRichEditCtrl::LineLength(int nLine /* = -1 */) const
  95. {
  96.     ASSERT(::IsWindow(m_hWnd));
  97.     return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0);
  98. }
  99.  
  100. void CRichEditCtrl::LineScroll(int nLines, int nChars /* = 0 */)
  101. {
  102.     ASSERT(::IsWindow(m_hWnd));
  103.     ::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
  104. }
  105.  
  106. void CRichEditCtrl::SetSel(long nStartChar, long nEndChar)
  107. {
  108.     ASSERT(::IsWindow(m_hWnd));
  109.     CHARRANGE cr;
  110.     cr.cpMin = nStartChar;
  111.     cr.cpMax = nEndChar;
  112.     ::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
  113. }
  114.  
  115. BOOL CRichEditCtrl::CanPaste(UINT nFormat) const
  116. {
  117.     ASSERT(::IsWindow(m_hWnd));
  118.     COleMessageFilter* pFilter = AfxOleGetMessageFilter();
  119.     if (pFilter != NULL)
  120.         pFilter->BeginBusyState();
  121.     BOOL b = (BOOL)::SendMessage(m_hWnd, EM_CANPASTE, nFormat, 0L);
  122.     if (pFilter != NULL)
  123.         pFilter->EndBusyState();
  124.     return b;
  125. }
  126.  
  127. void CRichEditCtrl::PasteSpecial(UINT nClipFormat, DWORD dvAspect, HMETAFILE hMF)
  128. {
  129.     ASSERT(::IsWindow(m_hWnd));
  130.     REPASTESPECIAL reps;
  131.     reps.dwAspect = dvAspect;
  132.     reps.dwParam = (DWORD)hMF;
  133.     ::SendMessage(m_hWnd, EM_PASTESPECIAL, nClipFormat, (LPARAM)&reps);
  134. }
  135.  
  136. int CRichEditCtrl::GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
  137. {
  138.     ASSERT(::IsWindow(m_hWnd));
  139.     *(LPINT)lpszBuffer = nMaxLength;
  140.     return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
  141. }
  142.  
  143. void CRichEditCtrl::GetSel(long& nStartChar, long& nEndChar) const
  144. {
  145.     ASSERT(::IsWindow(m_hWnd));
  146.     CHARRANGE cr;
  147.     ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  148.     nStartChar = cr.cpMin;
  149.     nEndChar = cr.cpMax;
  150. }
  151.  
  152. CString CRichEditCtrl::GetSelText() const
  153. {
  154.     ASSERT(::IsWindow(m_hWnd));
  155.     CHARRANGE cr;
  156.     cr.cpMin = cr.cpMax = 0;
  157.     ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
  158.     LPSTR lpsz = (char*)_alloca((cr.cpMax - cr.cpMin + 1)*2);
  159.     lpsz[0] = NULL;
  160.     ::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpsz);
  161.     return lpsz;
  162. }
  163.  
  164. IRichEditOle* CRichEditCtrl::GetIRichEditOle() const
  165. {
  166.     ASSERT(::IsWindow(m_hWnd));
  167.     IRichEditOle *pRichItem = NULL;
  168.     ::SendMessage(m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichItem);
  169.     return pRichItem;
  170. }
  171.  
  172. BOOL CRichEditCtrl::SetDefaultCharFormat(CHARFORMAT &cf)
  173. {
  174.     ASSERT(::IsWindow(m_hWnd));
  175.     cf.cbSize = sizeof(CHARFORMAT);
  176.     return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  177. }
  178.  
  179. BOOL CRichEditCtrl::SetSelectionCharFormat(CHARFORMAT &cf)
  180. {
  181.     ASSERT(::IsWindow(m_hWnd));
  182.     cf.cbSize = sizeof(CHARFORMAT);
  183.     return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
  184. }
  185.  
  186. BOOL CRichEditCtrl::SetWordCharFormat(CHARFORMAT &cf)
  187. {
  188.     ASSERT(::IsWindow(m_hWnd));
  189.     cf.cbSize = sizeof(CHARFORMAT);
  190.     return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION|SCF_WORD, (LPARAM)&cf);
  191. }
  192.  
  193. DWORD CRichEditCtrl::GetDefaultCharFormat(CHARFORMAT &cf) const
  194. {
  195.     ASSERT(::IsWindow(m_hWnd));
  196.     cf.cbSize = sizeof(CHARFORMAT);
  197.     return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
  198. }
  199.  
  200. DWORD CRichEditCtrl::GetSelectionCharFormat(CHARFORMAT &cf) const
  201. {
  202.     ASSERT(::IsWindow(m_hWnd));
  203.     cf.cbSize = sizeof(CHARFORMAT);
  204.     return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
  205. }
  206.  
  207. DWORD CRichEditCtrl::GetParaFormat(PARAFORMAT &pf) const
  208. {
  209.     ASSERT(::IsWindow(m_hWnd));
  210.     pf.cbSize = sizeof(PARAFORMAT);
  211.     return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  212. }
  213.  
  214. BOOL CRichEditCtrl::SetParaFormat(PARAFORMAT &pf)
  215. {
  216.     ASSERT(::IsWindow(m_hWnd));
  217.     pf.cbSize = sizeof(PARAFORMAT);
  218.     return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  219. }
  220.  
  221. #endif //!_AFX_NO_RICHEDIT_SUPPORT
  222.  
  223. /////////////////////////////////////////////////////////////////////////////
  224.  
  225. #ifndef _AFX_NO_RICHEDIT_SUPPORT
  226. #if defined(_MAC) && !defined(_AFXDLL)
  227.     #ifdef _DEBUG
  228.         #pragma comment(lib, "richedd.lib")
  229.         #ifdef _68K_
  230.             #pragma comment(lib, "wlmoled.lib")
  231.         #endif
  232.     #else
  233.         #pragma comment(lib, "riched.lib")
  234.         #ifdef _68K_
  235.             #pragma comment(lib, "wlmole.lib")
  236.         #endif
  237.     #endif
  238.     #pragma comment(linker, "/macres:riched.rsc")
  239. #endif // _MAC && !_AFXDLL
  240. #endif // _AFX_NO_RICHEDIT_SUPPORT
  241.  
  242. #pragma warning(disable: 4074)
  243. #pragma init_seg(lib)
  244.  
  245. #ifndef _AFX_NO_RICHEDIT_SUPPORT
  246. PROCESS_LOCAL(_AFX_RICHEDIT_STATE, _afxRichEditState)
  247. #endif
  248.  
  249. /////////////////////////////////////////////////////////////////////////////
  250.