RulerRichEditCtrl.cpp 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190
  1. /* ==========================================================================
  2. File : RuleRichEditCtrl.cpp
  3. Class : CRulerRichEditCtrl
  4. Author : Johan Rosengren, Abstrakt Mekanik AB
  5. Iain Clarke
  6. Date : 2004-04-17
  7. Purpose : "CRulerRichEditCtrl" is a "CWnd" derived class containing an
  8. embedded RTF-control, a ruler-control with dragable tab-
  9. positions and a formatting toolbar. The class can be used
  10. to - for example - add a complete mini-editor to a modal
  11. or modeless dialog box.
  12. Description : The class mainly handles mouse messages. The mouse
  13. messages are sent from the ruler control, and are
  14. button down, where the a check is made for the cursor
  15. located on one of the tab-markers, mouse move, where an
  16. XORed line is drawn across the RTF-control and button up,
  17. where a new tab position is set. The class also handles
  18. the toolbar buttons, setting styles as
  19. appropriate for the selected text.
  20. Usage : Add a "CRulerRichEditCtrl"-member to the parent class.
  21. Call Create to create the control. "GetRichEditCtrl" can
  22. be used to access the embedded RTF-control. Remember to
  23. call "AfxInitRichEdit(2)"!
  24. The contents can be saved to disk by calling "Save", and
  25. loaded from disk by calling "Load". The two functions
  26. will automatically display a file dialog if the file
  27. name parameter of the calls are left empty.
  28. "GetRTF" and "SetRTF" can be used to get and set the
  29. contents of the embedded RTF-control as RTF
  30. respectively.
  31. The ruler measures can be displayed as inches or
  32. centimeters, by calling "SetMode". "GetMode" will get the
  33. current mode.
  34. ========================================================================*/
  35. #include "stdafx.h"
  36. #include "StdGrfx.h"
  37. #include "RulerRichEditCtrl.h"
  38. #include "TextFile/TextFile.h"
  39. #include "..\Options.h"
  40. #include "..\Misc.h"
  41. #include "..\HyperLink.h"
  42. #include "ids.h"
  43. #include ".\rulerricheditctrl.h"
  44. #ifdef _DEBUG
  45. #define new DEBUG_NEW
  46. #undef THIS_FILE
  47. static char THIS_FILE[] = __FILE__;
  48. #endif
  49. /////////////////////////////////////////////////////////////////////////////
  50. // Registered messages for ruler/CRulerRichEditCtrl communication
  51. UINT urm_RULERACTION = ::RegisterWindowMessage( _T( "_RULERRICHEDITCTRL_RULER_TRACK_" ) );
  52. UINT urm_GETSCROLLPOS = ::RegisterWindowMessage( _T( "_RULERRICHEDITCTRL_GET_SCROLL_POS_" ) );
  53. UINT urm_SETCURRENTFONTNAME = ::RegisterWindowMessage( _T( "_RULERRICHEDITCTRL_SET_CURRENT_FONT_NAME" ) );
  54. UINT urm_SETCURRENTFONTSIZE = ::RegisterWindowMessage( _T( "_RULERRICHEDITCTRL_SET_CURRENT_FONT_SIZE" ) );
  55. UINT urm_SETCURRENTFONTCOLOR = ::RegisterWindowMessage( _T( "_RULERRICHEDITCTRL_SET_CURRENT_FONT_COLOR" ) );
  56. /////////////////////////////////////////////////////////////////////////////
  57. // Stream callback functions
  58. // Callbacks to the Save and Load functions.
  59. static DWORD CALLBACK StreamOut( DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb )
  60. {
  61. // Setting up temp buffer
  62. char* buff;
  63. buff = new char[cb + 1];
  64. buff[cb] = ( char ) 0;
  65. strncpy(buff, (LPCSTR)pbBuff, cb);
  66. int max = (int)strlen(buff);
  67. CString* str = (CString*) dwCookie;
  68. #ifdef _UNICODE
  69. // We want to convert the buff to wide chars
  70. int length = ::MultiByteToWideChar(CP_UTF8, 0, buff, max, NULL, 0);
  71. if(length)
  72. {
  73. TCHAR* wBuff = new TCHAR[length+1];
  74. ::MultiByteToWideChar(CP_UTF8, 0, buff, max, wBuff, length);
  75. wBuff[length] = 0;
  76. *str += wBuff;
  77. delete[] wBuff;
  78. }
  79. #else
  80. *str += buff;
  81. #endif
  82. delete[] buff;
  83. *pcb = max;
  84. return 0;
  85. }
  86. static DWORD CALLBACK StreamIn( DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb )
  87. {
  88. CString* str = ( ( CString* ) dwCookie );
  89. #ifdef _UNICODE
  90. // Unicode is only supported for SF_TEXT, so we need
  91. // to convert
  92. LPCTSTR ptr = str->GetBuffer( (*str).GetLength() );
  93. int length = ::WideCharToMultiByte( CP_UTF8, 0, ptr, -1, NULL, 0, NULL, NULL );
  94. int max = min( cb, length );
  95. if( length )
  96. {
  97. char* buff = new char[ length ];
  98. ::WideCharToMultiByte( CP_UTF8, 0, ptr, -1, buff, length + 1, NULL, NULL );
  99. strncpy( (LPSTR) pbBuff, buff, max );
  100. delete[] buff;
  101. }
  102. str->ReleaseBuffer();
  103. #else
  104. int max = min( cb, (*str).GetLength() );
  105. strncpy( ( LPSTR ) pbBuff, (*str) , max );
  106. #endif
  107. (*str) = (*str).Right( (*str).GetLength() - max );
  108. *pcb = max;
  109. return 0;
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CRulerRichEditCtrl
  113. CRulerRichEditCtrl::CRulerRichEditCtrl() : m_pen( PS_DOT, 0, RGB( 0, 0, 0 ) )
  114. /* ============================================================
  115. Function : CRulerRichEditCtrl::CRulerRichEditCtrl
  116. Description : constructor
  117. Access : Public
  118. Return : void
  119. Parameters : none
  120. Usage :
  121. ============================================================*/
  122. {
  123. m_rulerPosition = 0;
  124. m_margin = 0;
  125. m_movingtab = -1;
  126. m_offset = 0;
  127. m_readOnly = FALSE;
  128. m_bInWrapMode = g_Opt.GetEditWordWrap();
  129. ShowToolbar();
  130. ShowRuler();
  131. }
  132. CRulerRichEditCtrl::~CRulerRichEditCtrl()
  133. /* ============================================================
  134. Function : CRulerRichEditCtrl::~CRulerRichEditCtrl
  135. Description : destructor
  136. Access : Public
  137. Return : void
  138. Parameters : none
  139. Usage :
  140. ============================================================*/
  141. {
  142. m_pen.DeleteObject();
  143. }
  144. BOOL CRulerRichEditCtrl::Create( DWORD dwStyle, const RECT &rect, CWnd* pParentWnd, UINT nID, BOOL autohscroll )
  145. /* ============================================================
  146. Function : CRulerRichEditCtrl::Create
  147. Description : Creates the control and sub controls.
  148. Access : Public
  149. Return : BOOL - "TRUE" if created OK.
  150. Parameters : DWORD dwStyle - Style of the control,
  151. normally "WS_CHILD"
  152. and "WS_VISIBLE".
  153. const RECT &rect - Placement rectangle.
  154. CWnd* pParentWnd - Parent window.
  155. UINT nID - Control ID
  156. BOOL autohscroll - "TRUE" if the RTF-control
  157. should have the
  158. "ES_AUTOHSCROLL" style
  159. set.
  160. Usage : Call to create the control.
  161. ============================================================*/
  162. {
  163. BOOL result = CWnd::Create(NULL, _T( "" ), dwStyle, rect, pParentWnd, nID);
  164. if ( result )
  165. {
  166. result = FALSE;
  167. // Save screen resolution for
  168. // later on.
  169. CClientDC dc( this );
  170. m_physicalInch = dc.GetDeviceCaps( LOGPIXELSX );
  171. // Create sub-controls
  172. if( CreateRTFControl( autohscroll ) )
  173. {
  174. CreateMargins();
  175. if( CreateToolbar() )
  176. {
  177. if( CreateRuler() )
  178. {
  179. UpdateToolbarButtons();
  180. result = TRUE;
  181. }
  182. }
  183. //Do wrap will reverse the saved option so initially set it as opposite of what it's saved as
  184. m_bInWrapMode = !m_bInWrapMode;
  185. DoWrap();
  186. }
  187. }
  188. return result;
  189. }
  190. BOOL CRulerRichEditCtrl::CreateToolbar()
  191. /* ============================================================
  192. Function : CRulerRichEditCtrl::CreateToolbar
  193. Description : Creates the toolbar control
  194. Access : Private
  195. Return : BOOL - "TRUE" if the toolbar was created ok.
  196. Parameters : none
  197. Usage : Called during control creation
  198. ============================================================*/
  199. {
  200. CRect rect;
  201. GetClientRect( rect );
  202. CRect toolbarRect( 0, 0, rect.right, TOOLBAR_HEIGHT );
  203. return m_toolbar.Create( this, toolbarRect );
  204. }
  205. BOOL CRulerRichEditCtrl::CreateRuler()
  206. /* ============================================================
  207. Function : CRulerRichEditCtrl::CreateRuler
  208. Description : Creates the ruler control
  209. Access : Private
  210. Return : BOOL - "TRUE" if created ok.
  211. Parameters : none
  212. Usage : Called during control creation
  213. ============================================================*/
  214. {
  215. CRect rect;
  216. GetClientRect( rect );
  217. CRect rulerRect( 0, TOOLBAR_HEIGHT, rect.right, TOOLBAR_HEIGHT + RULER_HEIGHT );
  218. return m_ruler.Create( rulerRect, this, RULER_CONTROL );
  219. }
  220. BOOL CRulerRichEditCtrl::CreateRTFControl( BOOL autohscroll )
  221. /* ============================================================
  222. Function : CRulerRichEditCtrl::CreateRTFControl
  223. Description : Creates the embedded RTF-control.
  224. Access : Private
  225. Return : BOOL - "TRUE" if created ok.
  226. Parameters : BOOL autohscroll - "TRUE" if the RTF-control
  227. should have the
  228. "ES_AUTOHSCROLL" style
  229. set.
  230. Usage : Called during control creation
  231. ============================================================*/
  232. {
  233. BOOL result = FALSE;
  234. CRect rect;
  235. GetClientRect( rect );
  236. int top = TOOLBAR_HEIGHT + RULER_HEIGHT;
  237. CRect rtfRect( 0, top, rect.right, rect.bottom );
  238. DWORD style = ES_NOHIDESEL|WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_WANTRETURN|ES_MULTILINE;
  239. if( autohscroll )
  240. style |= ES_AUTOHSCROLL;
  241. if( m_rtf.Create( style, rtfRect, this ) )
  242. {
  243. // Setting up default tab stops
  244. ParaFormat para( PFM_TABSTOPS );
  245. para.cTabCount = MAX_TAB_STOPS;
  246. for( int t = 0; t < MAX_TAB_STOPS ; t++ )
  247. para.rgxTabs[ t ] = 640 * ( t + 1 );
  248. m_rtf.SetParaFormat( para );
  249. // Setting default character format
  250. CharFormat cf;
  251. cf.dwMask = CFM_SIZE | CFM_FACE | CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_LINK;
  252. cf.yHeight = CGetSetOptions::GetEditorDefaultFontSize() * 20;
  253. cf.dwEffects = 0;
  254. lstrcpy( cf.szFaceName, _T( "Segoe UI" ) );
  255. m_rtf.SendMessage(EM_SETCHARFORMAT, 0, (LPARAM)&cf);
  256. #ifndef SES_HYPERLINKTOOLTIPS
  257. #define SES_HYPERLINKTOOLTIPS 8
  258. #endif
  259. #ifndef SES_NOFOCUSLINKNOTIFY
  260. #define SES_NOFOCUSLINKNOTIFY 32
  261. #endif
  262. DWORD style = SES_HYPERLINKTOOLTIPS | SES_NOFOCUSLINKNOTIFY;
  263. m_rtf.SendMessage(EM_SETEDITSTYLE, style, style);
  264. m_rtf.SendMessage(EM_AUTOURLDETECT, TRUE, 0);
  265. // Set the internal tabs array
  266. SetTabStops( ( LPLONG ) ( para.rgxTabs ), MAX_TAB_STOPS );
  267. m_rtf.SetEventMask( m_rtf.GetEventMask() | ENM_SELCHANGE | ENM_SCROLL | ENM_CHANGE | ENM_LINK );
  268. SetReadOnly( GetReadOnly() );
  269. result = TRUE;
  270. }
  271. return result;
  272. }
  273. void CRulerRichEditCtrl::CreateMargins()
  274. /* ============================================================
  275. Function : CRulerRichEditCtrl::CreateMargins
  276. Description : Sets the margins for the subcontrols and
  277. the RTF-control edit rect.
  278. Access : Private
  279. Return : void
  280. Parameters : none
  281. Usage : Called during control creation.
  282. ============================================================*/
  283. {
  284. // Set up edit rect margins
  285. int scmargin = 4;
  286. CRect rc;
  287. m_rtf.GetClientRect( rc );
  288. rc.top = scmargin;
  289. rc.left = scmargin * 2;
  290. rc.right -= scmargin * 2;
  291. m_rtf.SetRect( rc );
  292. // Get the diff between the window- and client
  293. // rect of the RTF-control. This gives the actual
  294. // size of the RTF-control border.
  295. CRect r1;
  296. CRect r2;
  297. m_rtf.GetWindowRect( r1 );
  298. m_rtf.GetClientRect( r2 );
  299. m_rtf.ClientToScreen( r2 );
  300. // Create the margin for the toolbar
  301. // controls and the ruler.
  302. m_margin = scmargin * 2 + r2.left - r1.left;
  303. m_ruler.SetMargin( m_margin );
  304. }
  305. BEGIN_MESSAGE_MAP(CRulerRichEditCtrl, CWnd)
  306. //{{AFX_MSG_MAP(CRulerRichEditCtrl)
  307. ON_WM_PAINT()
  308. ON_WM_ERASEBKGND()
  309. ON_WM_SIZE()
  310. ON_MESSAGE( WM_SETTEXT, OnSetText )
  311. ON_MESSAGE( WM_GETTEXT, OnGetText )
  312. ON_MESSAGE( WM_GETTEXTLENGTH, OnGetTextLength )
  313. ON_BN_CLICKED(BUTTON_FONT, OnButtonFont)
  314. ON_BN_CLICKED(BUTTON_COLOR, OnButtonColor)
  315. ON_BN_CLICKED(BUTTON_BOLD, OnButtonBold)
  316. ON_BN_CLICKED(BUTTON_ITALIC, OnButtonItalic)
  317. ON_BN_CLICKED(BUTTON_UNDERLINE, OnButtonUnderline)
  318. ON_BN_CLICKED(BUTTON_LEFTALIGN, OnButtonLeftAlign)
  319. ON_BN_CLICKED(BUTTON_CENTERALIGN, OnButtonCenterAlign)
  320. ON_BN_CLICKED(BUTTON_RIGHTALIGN, OnButtonRightAlign)
  321. ON_BN_CLICKED(BUTTON_INDENT, OnButtonIndent)
  322. ON_BN_CLICKED(BUTTON_OUTDENT, OnButtonOutdent)
  323. ON_BN_CLICKED(BUTTON_BULLET, OnButtonBullet)
  324. ON_BN_CLICKED(ID_BUTTONWRAP, OnButtonWrap)
  325. ON_WM_SETFOCUS()
  326. ON_REGISTERED_MESSAGE(urm_RULERACTION, OnTrackRuler)
  327. ON_REGISTERED_MESSAGE(urm_GETSCROLLPOS, OnGetScrollPos)
  328. ON_REGISTERED_MESSAGE(urm_SETCURRENTFONTNAME, OnSetCurrentFontName)
  329. ON_REGISTERED_MESSAGE(urm_SETCURRENTFONTSIZE, OnSetCurrentFontSize)
  330. ON_NOTIFY(EN_LINK, RTF_CONTROL, OnLink)
  331. ON_REGISTERED_MESSAGE(urm_SETCURRENTFONTCOLOR, OnSetCurrentFontColor)
  332. //}}AFX_MSG_MAP
  333. ON_WM_KEYDOWN()
  334. END_MESSAGE_MAP()
  335. void CRulerRichEditCtrl::OnLink(NMHDR* pnm, LRESULT* pResult)
  336. {
  337. ENLINK* pnml = reinterpret_cast<ENLINK*>(pnm);
  338. if (pnml->msg == WM_LBUTTONDOWN ||
  339. (pnml->msg == WM_KEYDOWN && pnml->wParam == VK_RETURN))
  340. {
  341. CString url;
  342. m_rtf.GetTextRange(pnml->chrg.cpMin, pnml->chrg.cpMax, url);
  343. CHyperLink::GotoURL(url, SW_SHOW);
  344. *pResult = 1; // message handled
  345. }
  346. *pResult = 0; // enable default processing
  347. }
  348. /////////////////////////////////////////////////////////////////////////////
  349. // CRulerRichEditCtrl message handlers
  350. void CRulerRichEditCtrl::OnPaint()
  351. /* ============================================================
  352. Function : CRulerRichEditCtrl::OnPaint
  353. Description : Paints the ruler.
  354. Access : Protected
  355. Return : void
  356. Parameters : none
  357. Usage : Called from MFC.
  358. ============================================================*/
  359. {
  360. CPaintDC mainDC(this);
  361. UpdateTabStops();
  362. }
  363. BOOL CRulerRichEditCtrl::OnEraseBkgnd( CDC* /*pDC*/ )
  364. /* ============================================================
  365. Function : CRulerRichEditCtrl::OnEraseBkgnd
  366. Description : Returns "TRUE" to avoid flicker.
  367. Access : Protected
  368. Return : BOOL - Always "TRUE",
  369. Parameters : CDC* pDC - Not used
  370. Usage : Called from MFC.
  371. ============================================================*/
  372. {
  373. return TRUE;
  374. }
  375. BOOL CRulerRichEditCtrl::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult )
  376. /* ============================================================
  377. Function : CRulerRichEditCtrl::OnNotify
  378. Description : Called as the RTF-control is updated or
  379. the selection changes.
  380. Access : Protected
  381. Return : BOOL - From base class
  382. Parameters : WPARAM wParam - Control ID
  383. LPARAM lParam - Not interested
  384. LRESULT* pResult - Not interested
  385. Usage : Called from MFC. We must check the control
  386. every time the selection changes or the
  387. contents are changed, as the cursor might
  388. have entered a new paragraph, with new tab
  389. and/or font settings.
  390. ============================================================*/
  391. {
  392. if( wParam == RTF_CONTROL )
  393. {
  394. // Update the toolbar
  395. UpdateToolbarButtons();
  396. // Update ruler
  397. CRect rect;
  398. GetClientRect( rect );
  399. rect.top = TOOLBAR_HEIGHT;
  400. rect.bottom = rect.top + RULER_HEIGHT;
  401. RedrawWindow( rect );
  402. }
  403. return CWnd::OnNotify( wParam, lParam, pResult );
  404. }
  405. void CRulerRichEditCtrl::OnSize( UINT nType, int cx, int cy )
  406. /* ============================================================
  407. Function : CRulerRichEditCtrl::OnSize
  408. Description : We resize the embedded RTF-control.
  409. Access : Protected
  410. Return : void
  411. Parameters : UINT nType - Not interested
  412. int cx - New width
  413. int cy - New height
  414. Usage : Called from MFC.
  415. ============================================================*/
  416. {
  417. CWnd::OnSize( nType, cx, cy );
  418. if( m_rtf.m_hWnd )
  419. {
  420. LayoutControls( cx, cy );
  421. }
  422. }
  423. void CRulerRichEditCtrl::OnSetFocus( CWnd* pOldWnd )
  424. /* ============================================================
  425. Function : CRulerRichEditCtrl::OnSetFocus
  426. Description : We handle over the focus to the embedded
  427. RTF-control.
  428. Access : Protected
  429. Return : void
  430. Parameters : CWnd* pOldWnd - Not used
  431. Usage : Called from MFC.
  432. ============================================================*/
  433. {
  434. CWnd::OnSetFocus( pOldWnd );
  435. m_rtf.SetFocus();
  436. }
  437. LRESULT CRulerRichEditCtrl::OnGetScrollPos(WPARAM, LPARAM)
  438. /* ============================================================
  439. Function : CRulerRichEditCtrl::OnGetScrollPos
  440. Description : The function handles the registered message
  441. "urm_GETSCROLLPOS", that is sent from the
  442. ruler to get the current scroll position
  443. of the embedded RTF-control.
  444. Access : Protected
  445. Return : LRESULT - Current scroll pos
  446. Parameters : WPARAM mode - Not used
  447. LPARAM pt - Not used
  448. Usage : Called from MFC
  449. ============================================================*/
  450. {
  451. return m_rtf.GetScrollPos( SB_HORZ );
  452. }
  453. LRESULT CRulerRichEditCtrl::OnTrackRuler(WPARAM mode, LPARAM pt)
  454. /* ============================================================
  455. Function : CRulerRichEditCtrl::OnTrackRuler
  456. Description : The function handles the registered message
  457. "urm_RULERACTION", that is sent from the
  458. mouse handling mappings in the ruler control.
  459. The function handles dragging of tabulator
  460. points in the ruler.
  461. Access : Protected
  462. Return : LRESULT - Not used
  463. Parameters : WPARAM mode - The type of mouse operation,
  464. "DOWN", "MOVE" or "UP"
  465. LPARAM pt - Cursor point for the cursor.
  466. Usage : Called from MFC.
  467. ============================================================*/
  468. {
  469. CPoint* point = ( CPoint* ) pt;
  470. int toolbarHeight = 0;
  471. if( m_showToolbar )
  472. toolbarHeight = TOOLBAR_HEIGHT;
  473. switch( mode )
  474. {
  475. case DOWN:
  476. // The left mouse button is clicked
  477. {
  478. // Check if we clicked on a tab-marker.
  479. int pos = m_rtf.GetScrollPos( SB_HORZ );
  480. m_movingtab = -1;
  481. CRect hitRect;
  482. int y = RULER_HEIGHT - 9;
  483. for( int t = 0 ; t < MAX_TAB_STOPS ; t++ )
  484. {
  485. int x = m_tabs[ t ] + m_margin - pos;
  486. hitRect.SetRect( x - 2, y - 1, x + 3, y + 3 );
  487. if( hitRect.PtInRect( *point ) )
  488. {
  489. // Yes, we did.
  490. m_movingtab = t;
  491. // Calc offset, as the hit area is wider than
  492. // the 1 pixel tab line
  493. m_offset = point->x - ( m_tabs[ t ] + m_margin - pos );
  494. }
  495. }
  496. if( m_movingtab != -1 )
  497. {
  498. // We did click in a tab marker.
  499. // Start dragging
  500. // Find initial ruler position
  501. m_rulerPosition = point->x - m_offset;
  502. CRect rect;
  503. GetClientRect( rect );
  504. // Draw a new ruler line
  505. CClientDC dc( this );
  506. dc.SelectObject( &m_pen );
  507. dc.SetROP2( R2_XORPEN );
  508. dc.MoveTo( m_rulerPosition, toolbarHeight + 3 );
  509. dc.LineTo( m_rulerPosition, rect.Height() );
  510. dc.SelectStockObject( BLACK_PEN );
  511. }
  512. }
  513. break;
  514. case MOVE:
  515. // The mouse is moved
  516. {
  517. if( m_movingtab != -1 )
  518. {
  519. CRect rect;
  520. GetClientRect( rect );
  521. CClientDC dc( this );
  522. // Erase previous line
  523. dc.SelectObject( &m_pen );
  524. dc.SetROP2( R2_XORPEN );
  525. dc.MoveTo( m_rulerPosition, toolbarHeight + 3 );
  526. dc.LineTo( m_rulerPosition, rect.Height() );
  527. // Set up new line
  528. // Calc min and max. We can not place this marker
  529. // before the previous or after the next. Neither
  530. // can we move the marker outside the ruler.
  531. int pos = m_rtf.GetScrollPos( SB_HORZ );
  532. int min = m_margin + m_offset;
  533. if( m_movingtab > 0 )
  534. min = ( m_tabs[ m_movingtab - 1 ] + m_margin - pos ) + 3 + m_offset;
  535. int max = rect.Width() - 5 + m_offset;
  536. if( m_movingtab < m_tabs.GetUpperBound() )
  537. max = ( m_tabs[ m_movingtab + 1 ] + m_margin - pos ) - 3 + m_offset;
  538. max = min( max, rect.Width() - 5 + m_offset );
  539. // Set new positions
  540. m_rulerPosition = max( min, point->x - m_offset );
  541. m_rulerPosition = min( m_rulerPosition, max );
  542. // Draw the new line
  543. dc.MoveTo( m_rulerPosition, toolbarHeight + 3 );
  544. dc.LineTo( m_rulerPosition, rect.Height() );
  545. dc.SelectStockObject( BLACK_PEN );
  546. }
  547. }
  548. break;
  549. case UP:
  550. // The mouse button is released
  551. {
  552. if( m_movingtab != -1 )
  553. {
  554. // Set new value for tab position
  555. int pos = m_rtf.GetScrollPos( SB_HORZ );
  556. m_tabs[ m_movingtab ] = m_rulerPosition - m_margin + pos - m_offset;
  557. // Get the current tabstops, as we
  558. // must set all tabs in one operation
  559. ParaFormat para( PFM_TABSTOPS );
  560. para.cTabCount = MAX_TAB_STOPS;
  561. m_rtf.GetParaFormat( para );
  562. // Convert current position to twips
  563. double twip = ( double )m_physicalInch / 1440;
  564. int tabpos = m_tabs[ m_movingtab ];
  565. tabpos = ( int ) ( ( double ) tabpos / twip +.5 );
  566. para.rgxTabs[ m_movingtab ] = tabpos;
  567. // Set tabs to control
  568. m_rtf.SetParaFormat( para );
  569. // Erase the ruler
  570. m_ruler.RedrawWindow();
  571. m_rtf.RedrawWindow();
  572. m_movingtab = -1;
  573. m_rtf.SetFocus();
  574. }
  575. }
  576. break;
  577. }
  578. return 0;
  579. }
  580. LRESULT CRulerRichEditCtrl::OnSetText( WPARAM wParam, LPARAM lParam )
  581. /* ============================================================
  582. Function : CRulerRichEditCtrl::OnSetText
  583. Description : The function handles the "WM_SETTEXT"
  584. message. The handler sets the text in the
  585. RTF-control
  586. Access : Protected
  587. Return : LRESULT - From the control
  588. Parameters : WPARAM wParam - Passed on
  589. LPARAM lParam - Passed on
  590. Usage : Called from MFC.
  591. ============================================================*/
  592. {
  593. return m_rtf.SendMessage( WM_SETTEXT, wParam, lParam );
  594. }
  595. LRESULT CRulerRichEditCtrl::OnGetText( WPARAM wParam, LPARAM lParam )
  596. /* ============================================================
  597. Function : CRulerRichEditCtrl::OnGetText
  598. Description : The function handles the "WM_GETTEXT"
  599. message. The handler gets the text from the
  600. RTF-control
  601. Access : Protected
  602. Return : LRESULT - From the control
  603. Parameters : WPARAM wParam - Passed on
  604. LPARAM lParam - Passed on
  605. Usage : Called from MFC.
  606. ============================================================*/
  607. {
  608. return m_rtf.SendMessage( WM_GETTEXT, wParam, lParam );
  609. }
  610. LRESULT CRulerRichEditCtrl::OnGetTextLength( WPARAM wParam, LPARAM lParam )
  611. /* ============================================================
  612. Function : CRulerRichEditCtrl::OnGetTextLength
  613. Description : The function handles the "WM_GETTEXTLENGTH"
  614. message. The handler gets the length of
  615. the text in the RTF-control
  616. Access : Protected
  617. Return : LRESULT - From the control
  618. Parameters : WPARAM wParam - Passed on
  619. LPARAM lParam - Passed on
  620. Usage : Called from MFC.
  621. ============================================================*/
  622. {
  623. return m_rtf.GetTextLength();
  624. }
  625. /////////////////////////////////////////////////////////////////////////////
  626. // CRulerRichEditCtrl public implementation
  627. CString CRulerRichEditCtrl::GetRTF()
  628. /* ============================================================
  629. Function : CRulerRichEditCtrl::GetRTF
  630. Description : Returns the contents of the control as RTF.
  631. Access : Public
  632. Return : CString - The RTF-contents of the control.
  633. Parameters : none
  634. Usage : Call this function to get a char buffer
  635. with the contents of the embedded RTF-
  636. control.
  637. ============================================================*/
  638. {
  639. CString* str = new CString;
  640. EDITSTREAM es;
  641. es.dwCookie = (DWORD_PTR) str;
  642. es.pfnCallback = StreamOut;
  643. m_rtf.StreamOut( SF_RTF, es );
  644. CString output( *str );
  645. delete str;
  646. return output;
  647. }
  648. void CRulerRichEditCtrl::SetRTF( const CString& rtf )
  649. /* ============================================================
  650. Function : CRulerRichEditCtrl::SetRTF
  651. Description : Set the contents of the embedded RTF-
  652. control from rtf.
  653. Access : Public
  654. Return : void
  655. Parameters : const CString& rtf - The rtf-contents to
  656. set.
  657. Usage : Call this function to set the RTF-contents
  658. of the control.
  659. ============================================================*/
  660. {
  661. CString* str = new CString( rtf );
  662. EDITSTREAM es;
  663. es.dwCookie = (DWORD_PTR) str;
  664. es.pfnCallback = StreamIn;
  665. m_rtf.StreamIn( SF_RTF, es );
  666. delete str;
  667. }
  668. void CRulerRichEditCtrl::SetText(CString sText)
  669. {
  670. // Read the text in
  671. EDITSTREAM es;
  672. es.dwError = 0;
  673. // es.pfnCallback = StreamIn;
  674. #ifdef _UNICODE
  675. CString cs;
  676. es.dwCookie = (DWORD_PTR) &cs;
  677. #else
  678. es.dwCookie = (DWORD_PTR) &sText;
  679. m_rtf.StreamIn(SF_TEXT, es); // Do it.
  680. #endif
  681. #ifdef _UNICODE
  682. SETTEXTEX stex;
  683. stex.flags = ST_SELECTION | ST_KEEPUNDO;
  684. stex.codepage = 1200; // Unicode code page(set SETTEXTEX documentation)
  685. m_rtf.SendMessage(EM_SETTEXTEX, (WPARAM)&stex, (LPARAM)sText.GetBuffer(sText.GetLength()));
  686. sText.ReleaseBuffer();
  687. #endif
  688. }
  689. CString CRulerRichEditCtrl::GetText()
  690. {
  691. CString sText;
  692. #ifdef _UNICODE
  693. GETTEXTEX stex;
  694. stex.codepage = 1200; // Unicode code page(set SETTEXTEX documentation)
  695. stex.flags = GT_USECRLF;
  696. int nSize = m_rtf.GetTextLength();
  697. //increase the size incase of unicode text
  698. nSize += 50;
  699. nSize = nSize * sizeof(WCHAR);
  700. stex.cb = nSize;
  701. TCHAR *pText = new TCHAR[nSize];
  702. if(pText)
  703. {
  704. m_rtf.SendMessage(EM_GETTEXTEX, (WPARAM)&stex, (LPARAM)pText);
  705. sText = pText;
  706. delete []pText;
  707. pText = NULL;
  708. }
  709. #else
  710. // Stream out here.
  711. EDITSTREAM es;
  712. es.dwError = 0;
  713. es.pfnCallback = StreamOut; // Set the callback
  714. es.dwCookie = (DWORD_PTR) &sText; // so sRTF receives the string
  715. m_rtf.StreamOut(SF_TEXT, es); // Call CRichEditCtrl::StreamOut to get the string.
  716. #endif
  717. return sText;
  718. }
  719. BOOL CRulerRichEditCtrl::Save( CString& filename )
  720. /* ============================================================
  721. Function : CRulerRichEditCtrl::Save
  722. Description : Saves the contents to the file filename.
  723. If filename is empty, a file dialog will
  724. be displayed and the selected name will be
  725. returned in the "CString".
  726. Access : Public
  727. Return : BOOL - "TRUE" if the file
  728. was saved.
  729. Parameters : CString& filename - The file name to save
  730. to. Can be empty.
  731. Usage : Call to save the contents of the embedded
  732. RTF-control do a file.
  733. ============================================================*/
  734. {
  735. BOOL result = TRUE;
  736. CString* str = new CString;
  737. EDITSTREAM es;
  738. es.dwCookie = (DWORD_PTR) str;
  739. es.pfnCallback = StreamOut;
  740. m_rtf.StreamOut( SF_RTF, es );
  741. CTextFile f( _T( "rtf" ) );
  742. result = f.WriteTextFile( filename, *str );
  743. delete str;
  744. return result;
  745. }
  746. BOOL CRulerRichEditCtrl::Load( CString& filename )
  747. /* ============================================================
  748. Function : CRulerRichEditCtrl::Load
  749. Description : Loads the embedded RTF-control with the
  750. contents from the file filename.
  751. If filename is empty, a file dialog will
  752. be displayed and the selected name will be
  753. returned in the "CString".
  754. Access : Public
  755. Return : BOOL - "TRUE" if the file
  756. was loaded.
  757. Parameters : CString& filename - File name to load
  758. from. Can be empty.
  759. Usage : Call to load an RTF-file to the control.
  760. ============================================================*/
  761. {
  762. BOOL result = TRUE;
  763. CString* str = new CString;
  764. CTextFile f( _T( "rtf" ) );
  765. result = f.ReadTextFile( filename, *str );
  766. if( result )
  767. {
  768. EDITSTREAM es;
  769. es.dwCookie = (DWORD_PTR) str;
  770. // es.pfnCallback = StreamIn;
  771. m_rtf.StreamIn( SF_RTF, es );
  772. }
  773. delete str;
  774. return result;
  775. }
  776. void CRulerRichEditCtrl::SetMode( int mode )
  777. /* ============================================================
  778. Function : CRulerRichEditCtrl::SetMode
  779. Description : Sets the internal mode, that is, if the
  780. ruler should display inches or centimeters.
  781. Access : Public
  782. Return : void
  783. Parameters : int mode - Mode to use, "MODE_INCH" or
  784. "MODE_METRIC" (default)
  785. Usage : Call to change the mode.
  786. ============================================================*/
  787. {
  788. m_ruler.SetMode( mode );
  789. }
  790. int CRulerRichEditCtrl::GetMode() const
  791. /* ============================================================
  792. Function : CRulerRichEditCtrl::GetMode
  793. Description : Gets the mode, that is, either "MODE_INCH" or
  794. "MODE_METRIC", that is used to draw the ruler.
  795. Access : Public
  796. Return : int - The mode, either "MODE_INCH" or
  797. "MODE_METRIC"
  798. Parameters : none
  799. Usage : Call to get the current mode.
  800. ============================================================*/
  801. {
  802. return m_ruler.GetMode();
  803. }
  804. CRichEditCtrl& CRulerRichEditCtrl::GetRichEditCtrl()
  805. /* ============================================================
  806. Function : CRulerRichEditCtrl::GetRichEditCtrl
  807. Description : Returns an alias to the embedded RTF-control.
  808. Access : Public
  809. Return : CRichEditCtrl& - An alias to the rtf-control
  810. Parameters : none
  811. Usage : Call to access the RTF-control directly.
  812. ============================================================*/
  813. {
  814. return m_rtf;
  815. }
  816. /////////////////////////////////////////////////////////////////////////////
  817. // CRulerRichEditCtrl toolbar button handlers
  818. void CRulerRichEditCtrl::OnButtonFont()
  819. /* ============================================================
  820. Function : CRulerRichEditCtrl::OnButtonFont
  821. Description : Button handler for the Font button
  822. Access : Protected
  823. Return : void
  824. Parameters : none
  825. Usage : Called from MFC
  826. ============================================================*/
  827. {
  828. DoFont();
  829. }
  830. void CRulerRichEditCtrl::OnButtonColor()
  831. /* ============================================================
  832. Function : CRulerRichEditCtrl::OnButtonColor
  833. Description : Button handler for the Color button
  834. Access : Protected
  835. Return : void
  836. Parameters : none
  837. Usage : Called from MFC.
  838. ============================================================*/
  839. {
  840. DoColor();
  841. }
  842. void CRulerRichEditCtrl::OnButtonBold()
  843. /* ============================================================
  844. Function : CRulerRichEditCtrl::OnButtonBold
  845. Description : Button handler for the Bold button
  846. Access : Protected
  847. Return : void
  848. Parameters : none
  849. Usage : Called from MFC.
  850. ============================================================*/
  851. {
  852. DoBold();
  853. }
  854. void CRulerRichEditCtrl::OnButtonWrap()
  855. {
  856. DoWrap();
  857. }
  858. void CRulerRichEditCtrl::OnButtonItalic()
  859. /* ============================================================
  860. Function : CRulerRichEditCtrl::OnButtonItalic
  861. Description : Button handler for the Italic button
  862. Access : Protected
  863. Return : void
  864. Parameters : none
  865. Usage : Called from MFC.
  866. ============================================================*/
  867. {
  868. DoItalic();
  869. }
  870. void CRulerRichEditCtrl::OnButtonUnderline()
  871. /* ============================================================
  872. Function : CRulerRichEditCtrl::OnButtonUnderline
  873. Description : Button handler for the Underline button
  874. Access : Protected
  875. Return : void
  876. Parameters : none
  877. Usage : Called from MFC.
  878. ============================================================*/
  879. {
  880. DoUnderline();
  881. }
  882. void CRulerRichEditCtrl::OnButtonLeftAlign()
  883. /* ============================================================
  884. Function : CRulerRichEditCtrl::OnButtonLeftAlign
  885. Description : Button handler for the Left aligned button
  886. Access : Protected
  887. Return : void
  888. Parameters : none
  889. Usage : Called from MFC.
  890. ============================================================*/
  891. {
  892. DoLeftAlign();
  893. }
  894. void CRulerRichEditCtrl::OnButtonCenterAlign()
  895. /* ============================================================
  896. Function : CRulerRichEditCtrl::OnButtonCenterAlign
  897. Description : Button handler for the Center button
  898. Access : Protected
  899. Return : void
  900. Parameters : none
  901. Usage : Called from MFC.
  902. ============================================================*/
  903. {
  904. DoCenterAlign();
  905. }
  906. void CRulerRichEditCtrl::OnButtonRightAlign()
  907. /* ============================================================
  908. Function : CRulerRichEditCtrl::OnButtonRightAlign
  909. Description : Button handler for the Right-aligned button
  910. Access : Protected
  911. Return : void
  912. Parameters : none
  913. Usage : Called from MFC.
  914. ============================================================*/
  915. {
  916. DoRightAlign();
  917. }
  918. void CRulerRichEditCtrl::OnButtonIndent()
  919. /* ============================================================
  920. Function : CRulerRichEditCtrl::OnButtonIndent
  921. Description : Button handler for the Indent button
  922. Access : Protected
  923. Return : void
  924. Parameters : none
  925. Usage : Called from MFC.
  926. ============================================================*/
  927. {
  928. DoIndent();
  929. }
  930. void CRulerRichEditCtrl::OnButtonOutdent()
  931. /* ============================================================
  932. Function : CRulerRichEditCtrl::OnButtonOutdent
  933. Description : Button handler for the outdent button
  934. Access : Protected
  935. Return : void
  936. Parameters : none
  937. Usage : Called from MFC.
  938. ============================================================*/
  939. {
  940. DoOutdent();
  941. }
  942. void CRulerRichEditCtrl::OnButtonBullet()
  943. /* ============================================================
  944. Function : CRulerRichEditCtrl::OnButtonBullet
  945. Description : Button handler for the Bullet button
  946. Access : Protected
  947. Return : void
  948. Parameters : none
  949. Usage : Called from MFC.
  950. ============================================================*/
  951. {
  952. DoBullet();
  953. }
  954. /////////////////////////////////////////////////////////////////////////////
  955. // CRulerRichEditCtrl private helpers
  956. void CRulerRichEditCtrl::SetTabStops( LPLONG tabs, int size )
  957. /* ============================================================
  958. Function : CRulerRichEditCtrl::SetTabStops
  959. Description : Set the tab stops in the internal tab stop
  960. list from the RTF-control, converting the
  961. twip values to physical pixels.
  962. Access : Private
  963. Return : void
  964. Parameters : LPLONG tabs - A pointer to an array of
  965. "LONG" twip values.
  966. int size - The size of "tabs"
  967. Usage : Call to set the tab list.
  968. ============================================================*/
  969. {
  970. m_tabs.RemoveAll();
  971. double twip = ( double )m_physicalInch / 1440;
  972. for( int t = 0 ; t < size ; t++ )
  973. {
  974. // Convert from twips to pixels
  975. int tabpos = *( tabs + t );
  976. tabpos = ( int ) ( ( double ) tabpos * twip +.5 );
  977. m_tabs.Add( tabpos );
  978. }
  979. m_ruler.SetTabStops( m_tabs );
  980. }
  981. void CRulerRichEditCtrl::UpdateTabStops()
  982. /* ============================================================
  983. Function : CRulerRichEditCtrl::UpdateTabStops
  984. Description : Sets the tabs in the internal tab stop
  985. list, converting the twip physical (pixel)
  986. position to twip values.
  987. Access : Private
  988. Return : void
  989. Parameters : none
  990. Usage : Call to refresh the tab list from the RTF-
  991. control. Called from the "OnPaint" handler.
  992. ============================================================*/
  993. {
  994. ParaFormat para( PFM_TABSTOPS );
  995. m_rtf.GetParaFormat( para );
  996. SetTabStops( (LPLONG)(para.rgxTabs), MAX_TAB_STOPS );
  997. }
  998. void CRulerRichEditCtrl::UpdateToolbarButtons()
  999. /* ============================================================
  1000. Function : CRulerRichEditCtrl::UpdateToolbarButtons
  1001. Description : Updates the toolbar button, by getting
  1002. formatting information from the currently
  1003. selected text in the embedded RTF-control.
  1004. Access : Private
  1005. Return : void
  1006. Parameters : none
  1007. Usage : Call as the selection changes in the
  1008. RTF-control
  1009. ============================================================*/
  1010. {
  1011. if( m_showToolbar && m_toolbar.m_hWnd )
  1012. {
  1013. CharFormat cf;
  1014. cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE;
  1015. m_rtf.SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1016. ParaFormat para( PFM_ALIGNMENT | PFM_NUMBERING );
  1017. m_rtf.GetParaFormat( para );
  1018. // Style
  1019. m_toolbar.SetState( BUTTON_BOLD, TBSTATE_ENABLED | ( ( cf.dwEffects & CFE_BOLD ) ? TBSTATE_CHECKED : 0 ) );
  1020. m_toolbar.SetState( BUTTON_ITALIC, TBSTATE_ENABLED | ( ( cf.dwEffects & CFE_ITALIC ) ? TBSTATE_CHECKED : 0 ) );
  1021. m_toolbar.SetState( BUTTON_UNDERLINE, TBSTATE_ENABLED | ( ( cf.dwEffects & CFM_UNDERLINE ) ? TBSTATE_CHECKED : 0 ) );
  1022. m_toolbar.SetState( BUTTON_LEFTALIGN, TBSTATE_ENABLED | ( para.wAlignment == PFA_LEFT ? TBSTATE_CHECKED : 0 ) );
  1023. m_toolbar.SetState( BUTTON_CENTERALIGN, TBSTATE_ENABLED | ( para.wAlignment == PFA_CENTER ? TBSTATE_CHECKED : 0 ) );
  1024. m_toolbar.SetState( BUTTON_RIGHTALIGN, TBSTATE_ENABLED | ( para.wAlignment == PFA_RIGHT ? TBSTATE_CHECKED : 0 ) );
  1025. m_toolbar.SetState( BUTTON_BULLET, TBSTATE_ENABLED | ( para.wNumbering ? TBSTATE_CHECKED : 0 ) );
  1026. m_toolbar.SetState( ID_BUTTONWRAP, TBSTATE_ENABLED | ( m_bInWrapMode ? TBSTATE_CHECKED : 0 ));
  1027. if( cf.dwMask & CFM_FACE )
  1028. m_toolbar.SetFontName( CString( cf.szFaceName ) );
  1029. if( cf.dwMask & CFM_SIZE )
  1030. m_toolbar.SetFontSize( cf.yHeight / 20 );
  1031. if( cf.dwMask & CFM_COLOR )
  1032. m_toolbar.SetFontColor( cf.crTextColor );
  1033. }
  1034. }
  1035. void CRulerRichEditCtrl::SetEffect( int mask, int effect )
  1036. /* ============================================================
  1037. Function : CRulerRichEditCtrl::SetEffect
  1038. Description : Sets the effect (bold, italic and/or
  1039. underline) for the currently selected text
  1040. in the embedded RTF-control.
  1041. Access : Private
  1042. Return : void
  1043. Parameters : int mask - What effects are valid. See
  1044. the documentation for
  1045. "CHARFORMAT".
  1046. int effect - What effects to set. See the
  1047. documentation for "CHARFORMAT".
  1048. Usage : Called internally from button handlers
  1049. ============================================================*/
  1050. {
  1051. CharFormat cf;
  1052. cf.dwMask = mask;
  1053. cf.dwEffects = effect;
  1054. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1055. m_rtf.SetFocus();
  1056. }
  1057. void CRulerRichEditCtrl::SetAlignment( int alignment )
  1058. /* ============================================================
  1059. Function : CRulerRichEditCtrl::SetAlignment
  1060. Description : Sets the alignment for the currently
  1061. selected text in the embedded RTF-control.
  1062. Access : Private
  1063. Return : void
  1064. Parameters : int alignment - Alignment to set. See
  1065. documentation for
  1066. "PARAFORMAT"
  1067. Usage : Called internally from button handlers
  1068. ============================================================*/
  1069. {
  1070. ParaFormat para( PFM_ALIGNMENT );
  1071. para.wAlignment = ( WORD ) alignment;
  1072. m_rtf.SetParaFormat( para );
  1073. UpdateToolbarButtons();
  1074. m_rtf.SetFocus();
  1075. }
  1076. // Virtual interface
  1077. void CRulerRichEditCtrl::DoFont()
  1078. /* ============================================================
  1079. Function : CRulerRichEditCtrl::DoFont
  1080. Description : Externally accessible member to set the
  1081. font of the control
  1082. Access : Public
  1083. Return : void
  1084. Parameters : none
  1085. Usage : Call to set the font of the selected text.
  1086. ============================================================*/
  1087. {
  1088. // Get the current font
  1089. LOGFONT lf;
  1090. ZeroMemory( &lf, sizeof( LOGFONT ) );
  1091. CharFormat cf;
  1092. m_rtf.SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1093. int height;
  1094. // Creating a LOGFONT from the current font settings
  1095. // Font
  1096. if( cf.dwMask & CFM_FACE )
  1097. lstrcpy( lf.lfFaceName, cf.szFaceName );
  1098. if( cf.dwMask & CFM_SIZE )
  1099. {
  1100. double twip = ( double )m_physicalInch / 1440;
  1101. height = cf.yHeight;
  1102. height = -( int ) ( ( double ) height * twip +.5 );
  1103. lf.lfHeight = height;
  1104. }
  1105. // Effects
  1106. if( cf.dwMask & CFM_BOLD )
  1107. {
  1108. if( cf.dwEffects & CFE_BOLD )
  1109. lf.lfWeight = FW_BOLD;
  1110. else
  1111. lf.lfWeight = FW_NORMAL;
  1112. }
  1113. if( cf.dwMask & CFM_ITALIC )
  1114. if( cf.dwEffects & CFE_ITALIC )
  1115. lf.lfItalic = TRUE;
  1116. if( cf.dwMask & CFM_UNDERLINE )
  1117. if( cf.dwEffects & CFE_UNDERLINE )
  1118. lf.lfUnderline = TRUE;
  1119. // Show font dialog
  1120. CFontDialog dlg(&lf);
  1121. if(dlg.DoModal() == IDOK)
  1122. {
  1123. // Apply new font
  1124. cf.yHeight = dlg.GetSize() * 2;
  1125. lstrcpy(cf.szFaceName, dlg.GetFaceName());
  1126. cf.dwMask = CFM_FACE | CFM_SIZE;
  1127. cf.dwEffects = 0;
  1128. if( dlg.IsBold() )
  1129. {
  1130. cf.dwMask |= CFM_BOLD;
  1131. cf.dwEffects |= CFE_BOLD;
  1132. }
  1133. if( dlg.IsItalic() )
  1134. {
  1135. cf.dwMask |= CFM_ITALIC;
  1136. cf.dwEffects |= CFE_ITALIC;
  1137. }
  1138. if( dlg.IsUnderline() )
  1139. {
  1140. cf.dwMask |= CFM_UNDERLINE;
  1141. cf.dwEffects |= CFE_UNDERLINE;
  1142. }
  1143. m_rtf.SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
  1144. m_rtf.SetFocus();
  1145. }
  1146. }
  1147. void CRulerRichEditCtrl::SetCurrentFontName( const CString& font )
  1148. /* ============================================================
  1149. Function : CRulerRichEditCtrl::SetCurrentFontName
  1150. Description : Changes the font of the selected text in
  1151. the editor to "font".
  1152. Access : Public
  1153. Return : void
  1154. Parameters : const CString& font - Font name of font
  1155. to change to.
  1156. Usage : Call to set the font of the selected text
  1157. in the editor.
  1158. ============================================================*/
  1159. {
  1160. CharFormat cf;
  1161. cf.dwMask = CFM_FACE;
  1162. lstrcpy( cf.szFaceName, font );
  1163. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1164. }
  1165. void CRulerRichEditCtrl::SetCurrentFontSize( int size )
  1166. /* ============================================================
  1167. Function : CRulerRichEditCtrl::SetCurrentFontSize
  1168. Description : Changes the size of the selected text in
  1169. the editor to "size" (measured in
  1170. typographical points).
  1171. Access : Public
  1172. Return : void
  1173. Parameters : int size - New size in typographical
  1174. points
  1175. Usage : Call to change the size of the selected
  1176. text.
  1177. ============================================================*/
  1178. {
  1179. CharFormat cf;
  1180. cf.dwMask = CFM_SIZE;
  1181. cf.yHeight = size * 20;
  1182. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1183. }
  1184. void CRulerRichEditCtrl::SetCurrentFontColor( COLORREF color )
  1185. /* ============================================================
  1186. Function : CRulerRichEditCtrl::SetCurrentFontSize
  1187. Description : Changes the color of the selected text in
  1188. the editor to "color".
  1189. Access : Public
  1190. Return : void
  1191. Parameters : COLORREF color - New color
  1192. Usage : Call to change the color of the selected
  1193. text.
  1194. ============================================================*/
  1195. {
  1196. CharFormat cf;
  1197. cf.dwMask = CFM_COLOR;
  1198. cf.crTextColor = color;
  1199. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1200. }
  1201. LRESULT CRulerRichEditCtrl::OnSetCurrentFontName( WPARAM font, LPARAM )
  1202. /* ============================================================
  1203. Function : CRulerRichEditCtrl::OnSetCurrentFontName
  1204. Description : Handler for the registered message
  1205. "urm_SETCURRENTFONTNAME", called when the
  1206. font name is changed from the toolbar.
  1207. Access : Protected
  1208. Return : LRESULT - Not used
  1209. Parameters : WPARAM font - Pointer to the new font name
  1210. LPARAM - Not used
  1211. Usage : Called from MFC
  1212. ============================================================*/
  1213. {
  1214. CString fnt( ( LPCTSTR ) font );
  1215. SetCurrentFontName( fnt );
  1216. return 0;
  1217. }
  1218. LRESULT CRulerRichEditCtrl::OnSetCurrentFontSize(WPARAM, LPARAM size)
  1219. /* ============================================================
  1220. Function : CRulerRichEditCtrl::OnSetCurrentFontSize
  1221. Description : Handler for the registered message
  1222. "urm_SETCURRENTFONTSIZE", called when the
  1223. font size is changed from the toolbar.
  1224. Access : Protected
  1225. Return : LRESULT - Not used
  1226. Parameters : WPARAM - Not used
  1227. LPARAM size - New font size in typographical
  1228. points of the selected text
  1229. Usage : Called from MFC
  1230. ============================================================*/
  1231. {
  1232. SetCurrentFontSize((int)size);
  1233. return 0;
  1234. }
  1235. LRESULT CRulerRichEditCtrl::OnSetCurrentFontColor(WPARAM, LPARAM color)
  1236. /* ============================================================
  1237. Function : CRulerRichEditCtrl::OnSetCurrentFontColor
  1238. Description : Handler for the registered message
  1239. "urm_SETCURRENTFONTCOLOR", called when the
  1240. font color is changed from the toolbar.
  1241. Access : Protected
  1242. Return : LRESULT - Not used
  1243. Parameters : WPARAM - Not used
  1244. LPARAM - New color of the selected
  1245. text
  1246. Usage : Called from MFC
  1247. ============================================================*/
  1248. {
  1249. SetCurrentFontColor( ( COLORREF ) color );
  1250. return 0;
  1251. }
  1252. void CRulerRichEditCtrl::DoColor()
  1253. /* ============================================================
  1254. Function : CRulerRichEditCtrl::DoColor
  1255. Description : Externally accessible member to set the
  1256. color of the selected text
  1257. Access : Public
  1258. Return : void
  1259. Parameters : none
  1260. Usage : Call to set the color of the selected text.
  1261. ============================================================*/
  1262. {
  1263. // Get the current color
  1264. COLORREF clr( RGB( 0, 0, 0 ) );
  1265. CharFormat cf;
  1266. m_rtf.SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1267. if( cf.dwMask & CFM_COLOR )
  1268. clr = cf.crTextColor;
  1269. // Display color selection dialog
  1270. CColorDialog dlg( clr );
  1271. if( dlg.DoModal() == IDOK )
  1272. {
  1273. // Apply new color
  1274. cf.dwMask = CFM_COLOR;
  1275. cf.dwEffects = 0;
  1276. cf.crTextColor = dlg.GetColor();
  1277. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1278. }
  1279. m_rtf.SetFocus();
  1280. }
  1281. void CRulerRichEditCtrl::DoWrap()
  1282. {
  1283. if(m_bInWrapMode)
  1284. {
  1285. // Turn off word wrap.
  1286. m_rtf.SetTargetDevice(NULL, 1);
  1287. m_bInWrapMode = false;
  1288. }
  1289. else
  1290. {
  1291. // Turn on word wrap.
  1292. m_rtf.SetTargetDevice(NULL, 0);
  1293. m_bInWrapMode = true;
  1294. }
  1295. g_Opt.SetEditWordWrap(m_bInWrapMode);
  1296. m_toolbar.CheckButton(ID_BUTTONWRAP, m_bInWrapMode);
  1297. }
  1298. void CRulerRichEditCtrl::DoBold()
  1299. /* ============================================================
  1300. Function : CRulerRichEditCtrl::DoBold
  1301. Description : Externally accessible member to set/unset
  1302. the selected text to/from bold
  1303. Access : Public
  1304. Return : void
  1305. Parameters : none
  1306. Usage : Call to toggle the selected text to/from
  1307. bold.
  1308. ============================================================*/
  1309. {
  1310. m_toolbar.CheckButton( BUTTON_BOLD, !m_toolbar.IsButtonChecked( BUTTON_BOLD ) );
  1311. int effect = 0;
  1312. if( m_toolbar.IsButtonChecked( BUTTON_BOLD ) )
  1313. effect = CFE_BOLD;
  1314. SetEffect( CFM_BOLD, effect );
  1315. }
  1316. void CRulerRichEditCtrl::DoItalic()
  1317. /* ============================================================
  1318. Function : CRulerRichEditCtrl::DoItalic
  1319. Description : Externally accessible member to set/unset
  1320. the selected text to/from italic
  1321. Access : Public
  1322. Return : void
  1323. Parameters : none
  1324. Usage : Call to toggle the selected text to/from
  1325. italic.
  1326. =========================================================== =*/
  1327. {
  1328. m_toolbar.CheckButton( BUTTON_ITALIC, !m_toolbar.IsButtonChecked( BUTTON_ITALIC ) );
  1329. int effect = 0;
  1330. if( m_toolbar.IsButtonChecked( BUTTON_ITALIC ) )
  1331. effect = CFE_ITALIC;
  1332. SetEffect( CFM_ITALIC, effect );
  1333. }
  1334. void CRulerRichEditCtrl::DoUnderline()
  1335. /* ============================================================
  1336. Function : CRulerRichEditCtrl::DoUnderline
  1337. Description : Externally accessible member to set/unset
  1338. the selected text to/from underline
  1339. Access : Public
  1340. Return : void
  1341. Parameters : none
  1342. Usage : Call to toggle the selected text to/from
  1343. underlined.
  1344. ============================================================*/
  1345. {
  1346. m_toolbar.CheckButton( BUTTON_UNDERLINE, !m_toolbar.IsButtonChecked( BUTTON_UNDERLINE ) );
  1347. int effect = 0;
  1348. if( m_toolbar.IsButtonChecked( BUTTON_UNDERLINE ) )
  1349. effect = CFE_UNDERLINE;
  1350. SetEffect( CFM_UNDERLINE, effect );
  1351. }
  1352. void CRulerRichEditCtrl::DoLeftAlign()
  1353. /* ============================================================
  1354. Function : CRulerRichEditCtrl::DoLeftAlign
  1355. Description : Externally accessible member to set the
  1356. selected text to left aligned.
  1357. Access : Public
  1358. Return : void
  1359. Parameters : none
  1360. Usage : Call to left-align the selected text
  1361. ============================================================*/
  1362. {
  1363. if( !m_toolbar.IsButtonChecked( BUTTON_LEFTALIGN ) )
  1364. SetAlignment( PFA_LEFT );
  1365. }
  1366. void CRulerRichEditCtrl::DoCenterAlign()
  1367. /* ============================================================
  1368. Function : CRulerRichEditCtrl::DoCenterAlign
  1369. Description : Externally accessible member to set the
  1370. selected text to center aligned
  1371. Access : Public
  1372. Return : void
  1373. Parameters : none
  1374. Usage : Call to center-align the selected text
  1375. ============================================================*/
  1376. {
  1377. if( !m_toolbar.IsButtonChecked( BUTTON_CENTERALIGN ) )
  1378. SetAlignment( PFA_CENTER );
  1379. }
  1380. void CRulerRichEditCtrl::DoRightAlign()
  1381. /* ============================================================
  1382. Function : CRulerRichEditCtrl::DoRightAlign
  1383. Description : Externally accessible member to set the
  1384. selected text to right aligned
  1385. Access : Public
  1386. Return : void
  1387. Parameters : none
  1388. Usage : Call to right-align the selected text
  1389. ============================================================*/
  1390. {
  1391. if( !m_toolbar.IsButtonChecked( BUTTON_RIGHTALIGN ) )
  1392. SetAlignment( PFA_RIGHT );
  1393. }
  1394. void CRulerRichEditCtrl::DoIndent()
  1395. /* ============================================================
  1396. Function : CRulerRichEditCtrl::DoIndent
  1397. Description : Externally accessible member to indent the
  1398. selected text to the next tab position
  1399. Access : Public
  1400. Return : void
  1401. Parameters : none
  1402. Usage : Call to indent the selected text
  1403. ============================================================*/
  1404. {
  1405. // Get current indent
  1406. ParaFormat para( PFM_STARTINDENT | PFM_TABSTOPS );
  1407. m_rtf.GetParaFormat( para );
  1408. int newindent = para.dxStartIndent;
  1409. // Find next larger tab
  1410. for( int t = MAX_TAB_STOPS - 1 ; t >= 0 ; t-- )
  1411. {
  1412. if( para.rgxTabs[ t ] > para.dxStartIndent )
  1413. newindent = para.rgxTabs[ t ];
  1414. }
  1415. if( newindent != para.dxStartIndent )
  1416. {
  1417. // Set indent to this value
  1418. para.dwMask = PFM_STARTINDENT | PFM_OFFSET;
  1419. para.dxStartIndent = newindent;
  1420. para.dxOffset = newindent;
  1421. m_rtf.SetParaFormat( para );
  1422. }
  1423. m_rtf.SetFocus();
  1424. }
  1425. void CRulerRichEditCtrl::DoOutdent()
  1426. /* ============================================================
  1427. Function : CRulerRichEditCtrl::DoOutdent
  1428. Description : Externally accessible member to outdent the
  1429. selected text to the previous tab position
  1430. Access : Public
  1431. Return : void
  1432. Parameters : none
  1433. Usage : Call to outdent the selected text
  1434. ============================================================*/
  1435. {
  1436. // Get the current indent, if any
  1437. ParaFormat para( PFM_STARTINDENT | PFM_TABSTOPS );
  1438. m_rtf.GetParaFormat( para );
  1439. int newindent = 0;
  1440. // Find closest smaller tab
  1441. for( int t = 0 ; t < MAX_TAB_STOPS ; t++ )
  1442. if( para.rgxTabs[ t ] < para.dxStartIndent )
  1443. newindent = para.rgxTabs[ t ];
  1444. // Set indent to this value or 0 if none
  1445. para.dwMask = PFM_STARTINDENT | PFM_OFFSET;
  1446. para.dxStartIndent = newindent;
  1447. para.dxOffset = newindent;
  1448. m_rtf.SetParaFormat( para );
  1449. m_rtf.SetFocus();
  1450. }
  1451. void CRulerRichEditCtrl::DoBullet()
  1452. /* ============================================================
  1453. Function : CRulerRichEditCtrl::DoBullet
  1454. Description : Externally accessible member to set the
  1455. selected text to bulleted
  1456. Access : Public
  1457. Return : void
  1458. Parameters : none
  1459. Usage : Call to set the selected text to bulleted.
  1460. ============================================================*/
  1461. {
  1462. m_toolbar.CheckButton( BUTTON_BULLET, !m_toolbar.IsButtonChecked( BUTTON_BULLET ) );
  1463. ParaFormat para( PFM_NUMBERING );
  1464. if( m_toolbar.IsButtonChecked( BUTTON_BULLET ) )
  1465. para.wNumbering = PFN_BULLET;
  1466. else
  1467. para.wNumbering = 0;
  1468. m_rtf.SetParaFormat( para );
  1469. m_rtf.SetFocus();
  1470. }
  1471. void CRulerRichEditCtrl::ShowToolbar( BOOL show )
  1472. /* ============================================================
  1473. Function : CRulerRichEditCtrl::ShowToolbar
  1474. Description : Shows or hides the toolbar
  1475. Access : Public
  1476. Return : void
  1477. Parameters : BOOL show - "TRUE" to show
  1478. Usage : Call to show or hide the toolbar subcontrol
  1479. ============================================================*/
  1480. {
  1481. m_showToolbar = show;
  1482. if( m_hWnd )
  1483. {
  1484. if( show )
  1485. m_toolbar.ShowWindow( SW_SHOW );
  1486. else
  1487. m_toolbar.ShowWindow( SW_HIDE );
  1488. CRect rect;
  1489. GetClientRect( rect );
  1490. LayoutControls( rect.Width(), rect.Height() );
  1491. }
  1492. }
  1493. void CRulerRichEditCtrl::ShowRuler( BOOL show )
  1494. /* ============================================================
  1495. Function : CRulerRichEditCtrl::ShowRuler
  1496. Description : Shows or hides the ruler
  1497. Access : Public
  1498. Return : void
  1499. Parameters : BOOL show - "TRUE" to show
  1500. Usage : Call to show or hide the ruler subcontrol
  1501. ============================================================*/
  1502. {
  1503. m_showRuler = show;
  1504. if( m_hWnd )
  1505. {
  1506. if( show )
  1507. m_ruler.ShowWindow( SW_SHOW );
  1508. else
  1509. m_ruler.ShowWindow( SW_HIDE );
  1510. CRect rect;
  1511. GetClientRect( rect );
  1512. LayoutControls( rect.Width(), rect.Height() );
  1513. }
  1514. }
  1515. void CRulerRichEditCtrl::LayoutControls( int width, int height )
  1516. /* ============================================================
  1517. Function : CRulerRichEditCtrl::LayoutControls
  1518. Description : Lays out the sub-controls depending on
  1519. visibility.
  1520. Access : Private
  1521. Return : void
  1522. Parameters : int width - Width of control
  1523. int height - Height of control
  1524. Usage : Called internally to lay out the controls
  1525. ============================================================*/
  1526. {
  1527. int toolbarHeight = 0;
  1528. if( m_showToolbar )
  1529. toolbarHeight = TOOLBAR_HEIGHT;
  1530. int rulerHeight = 0;
  1531. if( m_showRuler )
  1532. rulerHeight = RULER_HEIGHT;
  1533. m_toolbar.MoveWindow( 0, 0, width, toolbarHeight );
  1534. m_ruler.MoveWindow( 0, toolbarHeight, width, rulerHeight );
  1535. int top = toolbarHeight + rulerHeight;
  1536. CRect rect( 0, top, width, height );
  1537. m_rtf.MoveWindow( rect );
  1538. }
  1539. BOOL CRulerRichEditCtrl::IsToolbarVisible() const
  1540. /* ============================================================
  1541. Function : CRulerRichEditCtrl::IsToolbarVisible
  1542. Description : Returns if the toolbar is visible or not
  1543. Access : Public
  1544. Return : BOOL - "TRUE" if visible
  1545. Parameters : none
  1546. Usage : Call to get the visibility of the toolbar
  1547. ============================================================*/
  1548. {
  1549. return m_showToolbar;
  1550. }
  1551. BOOL CRulerRichEditCtrl::IsRulerVisible() const
  1552. /* ============================================================
  1553. Function : CRulerRichEditCtrl::IsRulerVisible
  1554. Description : Returns if the ruler is visible or not
  1555. Access : Public
  1556. Return : BOOL - "TRUE" if visible
  1557. Parameters : none
  1558. Usage : Call to get the visibility of the ruler
  1559. ============================================================*/
  1560. {
  1561. return m_showRuler;
  1562. }
  1563. void CRulerRichEditCtrl::SetReadOnly( BOOL readOnly )
  1564. /* ============================================================
  1565. Function : CRulerRichEditCtrl::SetReadOnly
  1566. Description : Sets the control to read only or not.
  1567. Access : Public
  1568. Return : void
  1569. Parameters : BOOL readOnly - New read only state
  1570. Usage : Call to set the read only state of the
  1571. control
  1572. ============================================================*/
  1573. {
  1574. if( m_rtf.m_hWnd )
  1575. m_rtf.SetReadOnly( readOnly );
  1576. m_readOnly = readOnly;
  1577. }
  1578. BOOL CRulerRichEditCtrl::GetReadOnly() const
  1579. /* ============================================================
  1580. Function : CRulerRichEditCtrl::GetReadOnly
  1581. Description : Returns if the control is read only or not
  1582. Access : Public
  1583. Return : BOOL - "TRUE" if read only
  1584. Parameters : none
  1585. Usage : Call to get the read only-state of the
  1586. control
  1587. ============================================================*/
  1588. {
  1589. return m_readOnly;
  1590. }
  1591. BOOL CRulerRichEditCtrl::PreTranslateMessage(MSG* pMsg)
  1592. {
  1593. if(pMsg->message == WM_KEYDOWN)
  1594. {
  1595. switch(pMsg->wParam)
  1596. {
  1597. case 'X':
  1598. if(CONTROL_PRESSED)
  1599. {
  1600. m_rtf.Cut();
  1601. return TRUE;
  1602. }
  1603. break;
  1604. case 'C':
  1605. if(CONTROL_PRESSED)
  1606. {
  1607. m_rtf.Copy();
  1608. return TRUE;
  1609. }
  1610. break;
  1611. case 'V':
  1612. if(CONTROL_PRESSED)
  1613. {
  1614. m_rtf.Paste();
  1615. return TRUE;
  1616. }
  1617. break;
  1618. case 'I':
  1619. if(CONTROL_PRESSED)
  1620. {
  1621. DoItalic();
  1622. return TRUE;
  1623. }
  1624. break;
  1625. case 'B':
  1626. if(CONTROL_PRESSED)
  1627. {
  1628. DoBold();
  1629. return TRUE;
  1630. }
  1631. break;
  1632. case 'U':
  1633. if(CONTROL_PRESSED)
  1634. {
  1635. DoUnderline();
  1636. return TRUE;
  1637. }
  1638. break;
  1639. case 'Z':
  1640. if(CONTROL_PRESSED)
  1641. {
  1642. m_rtf.Undo();
  1643. return TRUE;
  1644. }
  1645. break;
  1646. case 'Y':
  1647. if(CONTROL_PRESSED)
  1648. {
  1649. m_rtf.Redo();
  1650. return TRUE;
  1651. }
  1652. break;
  1653. case 'W':
  1654. if(CONTROL_PRESSED)
  1655. {
  1656. DoWrap();
  1657. return TRUE;
  1658. }
  1659. break;
  1660. }
  1661. }
  1662. return CWnd::PreTranslateMessage(pMsg);
  1663. }