Counter Strike : Global Offensive Source Code
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.

474 lines
6.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #pragma warning(disable:4701 4702 4530)
  9. #include "RichEditCtrlEx.h"
  10. CRichEditCtrlEx::CRichEditCtrlEx()
  11. {
  12. }
  13. CRichEditCtrlEx::~CRichEditCtrlEx()
  14. {
  15. }
  16. BEGIN_MESSAGE_MAP(CRichEditCtrlEx, CRichEditCtrl)
  17. //{{AFX_MSG_MAP(CRichEditCtrlEx)
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. void CRichEditCtrlEx::PreSubclassWindow()
  21. {
  22. CRichEditCtrl::PreSubclassWindow();
  23. SetBackgroundColor(FALSE, ::GetSysColor(COLOR_BTNFACE));
  24. disable();
  25. readOnly();
  26. }
  27. CRTFBuilder &doWrite(CRTFBuilder &r, CRichEditCtrl &c) throw()
  28. {
  29. r.write(c);
  30. return r;
  31. }
  32. CRTFBuilder &doSize(CRTFBuilder &r, int n) throw()
  33. {
  34. r.size(n);
  35. return r;
  36. }
  37. CRTFBuilder &doBold(CRTFBuilder &r, bool b)
  38. {
  39. r.bold(b);
  40. return r;
  41. }
  42. CRTFBuilder &doStrike(CRTFBuilder &r, bool b)
  43. {
  44. r.strike(b);
  45. return r;
  46. }
  47. CRTFBuilder &doItalic(CRTFBuilder &r, bool b)
  48. {
  49. r.italic(b);
  50. return r;
  51. }
  52. CRTFBuilder &doUnderline(CRTFBuilder &r, bool b)
  53. {
  54. r.underline(b);
  55. return r;
  56. }
  57. CRTFBuilder &doColor(CRTFBuilder &r, int n)
  58. {
  59. r.color((COLORREF)n);
  60. return r;
  61. }
  62. CRTFBuilder &doBackColor(CRTFBuilder &r, int n)
  63. {
  64. r.backColor((COLORREF)n);
  65. return r;
  66. }
  67. CRTFBuilder &doAddColor(CRTFBuilder &r, int n)
  68. {
  69. r.addColor((COLORREF)n);
  70. return r;
  71. }
  72. CRTFBuilder &doFont(CRTFBuilder &r, CString &s)
  73. {
  74. r.font(s);
  75. return r;
  76. }
  77. CRTFBuilder &doAddFont(CRTFBuilder &r, CString &s)
  78. {
  79. r.addFont(s);
  80. return r;
  81. }
  82. CControlManip write(CRichEditCtrl &c) throw ()
  83. {
  84. return CControlManip(&doWrite, c);
  85. }
  86. CIntManip size(int n) throw()
  87. {
  88. return CIntManip(&doSize, n);
  89. }
  90. CIntManip color(int n) throw()
  91. {
  92. return CIntManip(&doColor, n);
  93. }
  94. CIntManip backColor(int n) throw()
  95. {
  96. return CIntManip(&doBackColor, n);
  97. }
  98. CIntManip addColor(int n) throw()
  99. {
  100. return CIntManip(&doAddColor, n);
  101. }
  102. CStringManip font(LPCTSTR s) throw()
  103. {
  104. return CStringManip(&doFont, s);
  105. }
  106. CStringManip addFont(LPCTSTR s) throw()
  107. {
  108. return CStringManip(&doAddFont, s);
  109. }
  110. CBoolManip bold(bool b) throw()
  111. {
  112. return CBoolManip(&doBold, b);
  113. }
  114. CBoolManip strike(bool b) throw()
  115. {
  116. return CBoolManip(&doStrike, b);
  117. }
  118. CBoolManip italic(bool b) throw()
  119. {
  120. return CBoolManip(&doItalic, b);
  121. }
  122. CBoolManip underline(bool b) throw()
  123. {
  124. return CBoolManip(&doUnderline, b);
  125. }
  126. CRTFBuilder &operator<<(CRTFBuilder &b, RTFSM_PFUNC f)
  127. {
  128. return f(b);
  129. }
  130. CRTFBuilder &operator<<(CRTFBuilder &b, CManip &f)
  131. {
  132. return f.go(b);
  133. }
  134. CRTFBuilder &normal(CRTFBuilder &b)
  135. {
  136. b.normal();
  137. return b;
  138. }
  139. CRTFBuilder &black(CRTFBuilder &b)
  140. {
  141. b.black();
  142. return b;
  143. }
  144. CRTFBuilder &push(CRTFBuilder &b)
  145. {
  146. b.push();
  147. return b;
  148. }
  149. CRTFBuilder &pop(CRTFBuilder &b)
  150. {
  151. b.pop();
  152. return b;
  153. }
  154. CRTFBuilder &red(CRTFBuilder &b)
  155. {
  156. b.red();
  157. return b;
  158. }
  159. CRTFBuilder &green(CRTFBuilder &b)
  160. {
  161. b.green();
  162. return b;
  163. }
  164. CRTFBuilder &blue(CRTFBuilder &b)
  165. {
  166. b.blue();
  167. return b;
  168. }
  169. CRTFBuilder &bold(CRTFBuilder &b)
  170. {
  171. b.bold();
  172. return b;
  173. }
  174. CRTFBuilder &strike(CRTFBuilder &b)
  175. {
  176. b.strike();
  177. return b;
  178. }
  179. CRTFBuilder &italic(CRTFBuilder &b)
  180. {
  181. b.italic();
  182. return b;
  183. }
  184. CRTFBuilder &underline(CRTFBuilder &b)
  185. {
  186. b.underline();
  187. return b;
  188. }
  189. CRTFBuilder::CRTFBuilder()
  190. {
  191. m_fontList.add("Arial");
  192. m_colorList.add(RGB(0,0,0) );
  193. m_colorList.add(RGB(255,0,0) );
  194. m_colorList.add(RGB(0,255,0) );
  195. m_colorList.add(RGB(0,0,255) );
  196. size(35);
  197. }
  198. CRTFBuilder::~CRTFBuilder()
  199. {
  200. }
  201. void CRTFBuilder::push()
  202. {
  203. m_attrStack.push(m_attr);
  204. }
  205. void CRTFBuilder::pop()
  206. {
  207. m_attr = m_attrStack.top();
  208. m_attrStack.pop();
  209. }
  210. void CRTFBuilder::color(COLORREF c)
  211. {
  212. int n (m_colorList.find(c) );
  213. m_attr.m_nColorFground= n<0 ? m_colorList.add(c) : n;
  214. }
  215. void CRTFBuilder::backColor(COLORREF c)
  216. {
  217. int n (m_colorList.find(c) ) ;
  218. m_attr.m_nColorBground= n<0 ? m_colorList.add(c) : n;
  219. }
  220. void CRTFBuilder::black()
  221. {
  222. m_attr.m_nColorFground = 0;
  223. }
  224. void CRTFBuilder::red()
  225. {
  226. m_attr.m_nColorFground = 1;
  227. }
  228. void CRTFBuilder::green()
  229. {
  230. m_attr.m_nColorFground = 2;
  231. }
  232. void CRTFBuilder::blue()
  233. {
  234. m_attr.m_nColorFground = 3;
  235. }
  236. void CRTFBuilder::size(int n)
  237. {
  238. m_attr.m_nFontSize = n;
  239. }
  240. void CRTFBuilder::font(const CString &strFont)
  241. {
  242. int nCount = 0;
  243. for (list<CString>::iterator i = m_fontList.begin(); i != m_fontList.end(); i++, nCount++)
  244. {
  245. if ((*i) == strFont)
  246. {
  247. m_attr.m_nFontNumber = nCount;
  248. return;
  249. }
  250. }
  251. //not there, lets add it
  252. m_fontList.add(strFont);
  253. m_attr.m_nFontNumber = nCount;
  254. }
  255. void CRTFBuilder::bold(bool b)
  256. {
  257. m_attr.m_bsBold= b;
  258. }
  259. void CRTFBuilder::strike(bool b)
  260. {
  261. m_attr.m_bsStrike= b;
  262. }
  263. void CRTFBuilder::italic(bool b)
  264. {
  265. m_attr.m_bsItalic = b;
  266. }
  267. void CRTFBuilder::underline(bool b)
  268. {
  269. m_attr.m_bsUnderline = b;
  270. }
  271. void CRTFBuilder::normal()
  272. {
  273. bold(false);
  274. italic(false);
  275. underline(false);
  276. strike(false);
  277. }
  278. static DWORD CALLBACK EditStreamCallBack(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
  279. {
  280. CString *pstr = (CString *)dwCookie;
  281. if (pstr->GetLength() < cb)
  282. {
  283. *pcb = pstr->GetLength();
  284. memcpy(pbBuff, (LPCSTR)*pstr, *pcb);
  285. pstr->Empty();
  286. }
  287. else
  288. {
  289. *pcb = cb;
  290. memcpy( pbBuff, (LPCSTR)*pstr, *pcb);
  291. *pstr = pstr->Right(pstr->GetLength() - cb);
  292. }
  293. return 0;
  294. }
  295. void CRTFBuilder::write(CRichEditCtrl &c)
  296. {
  297. m_string += '}';
  298. // CRtfStringDlg d(m_string);
  299. EDITSTREAM es = {(DWORD)&m_string, 0, EditStreamCallBack };
  300. // richEd is the rich edit control
  301. c.StreamIn(SF_RTF | SFF_SELECTION, es);
  302. m_string.Empty();
  303. }
  304. CRTFBuilder &CRTFBuilder::operator+=(LPCTSTR p)
  305. {
  306. CString s(p) , s2;
  307. for (int i = 0; i < s.GetLength(); i ++)
  308. {
  309. if (s[i]=='\n')
  310. {
  311. s2 += (CString)"\r\n" += "\\par ";//\\par ";
  312. }
  313. else
  314. {
  315. s2 += s[i];
  316. }
  317. }
  318. m_string +=
  319. (CString)"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deftab720" +=
  320. (CString)m_fontList +=
  321. (CString)m_colorList +=
  322. (CString)m_attr +=
  323. s2 ;
  324. return *this;
  325. }
  326. CRTFBuilder &CRTFBuilder::operator<<(LPCTSTR p)
  327. {
  328. *this+=p;
  329. return *this;
  330. }
  331. CRTFBuilder &CRTFBuilder::operator<<(int n)
  332. {
  333. CString s;
  334. s.Format("%d", n);
  335. *this += (LPCTSTR)s;
  336. return *this;
  337. }
  338. CRTFBuilder &CRTFBuilder::operator>>(CRichEditCtrl &e)
  339. {
  340. write(e);
  341. return *this;
  342. }