RulerRichEditCtrl.cpp 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  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 = 200;
  253. cf.dwEffects = 0;
  254. lstrcpy( cf.szFaceName, _T( "Times New Roman" ) );
  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. int nSize = m_rtf.GetTextLength();
  696. //increase the size incase of unicode text
  697. nSize += 50;
  698. nSize = nSize * sizeof(WCHAR);
  699. stex.cb = nSize;
  700. TCHAR *pText = new TCHAR[nSize];
  701. if(pText)
  702. {
  703. m_rtf.SendMessage(EM_GETTEXTEX, (WPARAM)&stex, (LPARAM)pText);
  704. sText = pText;
  705. delete []pText;
  706. pText = NULL;
  707. }
  708. #else
  709. // Stream out here.
  710. EDITSTREAM es;
  711. es.dwError = 0;
  712. es.pfnCallback = StreamOut; // Set the callback
  713. es.dwCookie = (DWORD_PTR) &sText; // so sRTF receives the string
  714. m_rtf.StreamOut(SF_TEXT, es); // Call CRichEditCtrl::StreamOut to get the string.
  715. #endif
  716. return sText;
  717. }
  718. BOOL CRulerRichEditCtrl::Save( CString& filename )
  719. /* ============================================================
  720. Function : CRulerRichEditCtrl::Save
  721. Description : Saves the contents to the file filename.
  722. If filename is empty, a file dialog will
  723. be displayed and the selected name will be
  724. returned in the "CString".
  725. Access : Public
  726. Return : BOOL - "TRUE" if the file
  727. was saved.
  728. Parameters : CString& filename - The file name to save
  729. to. Can be empty.
  730. Usage : Call to save the contents of the embedded
  731. RTF-control do a file.
  732. ============================================================*/
  733. {
  734. BOOL result = TRUE;
  735. CString* str = new CString;
  736. EDITSTREAM es;
  737. es.dwCookie = (DWORD_PTR) str;
  738. es.pfnCallback = StreamOut;
  739. m_rtf.StreamOut( SF_RTF, es );
  740. CTextFile f( _T( "rtf" ) );
  741. result = f.WriteTextFile( filename, *str );
  742. delete str;
  743. return result;
  744. }
  745. BOOL CRulerRichEditCtrl::Load( CString& filename )
  746. /* ============================================================
  747. Function : CRulerRichEditCtrl::Load
  748. Description : Loads the embedded RTF-control with the
  749. contents from the file filename.
  750. If filename is empty, a file dialog will
  751. be displayed and the selected name will be
  752. returned in the "CString".
  753. Access : Public
  754. Return : BOOL - "TRUE" if the file
  755. was loaded.
  756. Parameters : CString& filename - File name to load
  757. from. Can be empty.
  758. Usage : Call to load an RTF-file to the control.
  759. ============================================================*/
  760. {
  761. BOOL result = TRUE;
  762. CString* str = new CString;
  763. CTextFile f( _T( "rtf" ) );
  764. result = f.ReadTextFile( filename, *str );
  765. if( result )
  766. {
  767. EDITSTREAM es;
  768. es.dwCookie = (DWORD_PTR) str;
  769. // es.pfnCallback = StreamIn;
  770. m_rtf.StreamIn( SF_RTF, es );
  771. }
  772. delete str;
  773. return result;
  774. }
  775. void CRulerRichEditCtrl::SetMode( int mode )
  776. /* ============================================================
  777. Function : CRulerRichEditCtrl::SetMode
  778. Description : Sets the internal mode, that is, if the
  779. ruler should display inches or centimeters.
  780. Access : Public
  781. Return : void
  782. Parameters : int mode - Mode to use, "MODE_INCH" or
  783. "MODE_METRIC" (default)
  784. Usage : Call to change the mode.
  785. ============================================================*/
  786. {
  787. m_ruler.SetMode( mode );
  788. }
  789. int CRulerRichEditCtrl::GetMode() const
  790. /* ============================================================
  791. Function : CRulerRichEditCtrl::GetMode
  792. Description : Gets the mode, that is, either "MODE_INCH" or
  793. "MODE_METRIC", that is used to draw the ruler.
  794. Access : Public
  795. Return : int - The mode, either "MODE_INCH" or
  796. "MODE_METRIC"
  797. Parameters : none
  798. Usage : Call to get the current mode.
  799. ============================================================*/
  800. {
  801. return m_ruler.GetMode();
  802. }
  803. CRichEditCtrl& CRulerRichEditCtrl::GetRichEditCtrl()
  804. /* ============================================================
  805. Function : CRulerRichEditCtrl::GetRichEditCtrl
  806. Description : Returns an alias to the embedded RTF-control.
  807. Access : Public
  808. Return : CRichEditCtrl& - An alias to the rtf-control
  809. Parameters : none
  810. Usage : Call to access the RTF-control directly.
  811. ============================================================*/
  812. {
  813. return m_rtf;
  814. }
  815. /////////////////////////////////////////////////////////////////////////////
  816. // CRulerRichEditCtrl toolbar button handlers
  817. void CRulerRichEditCtrl::OnButtonFont()
  818. /* ============================================================
  819. Function : CRulerRichEditCtrl::OnButtonFont
  820. Description : Button handler for the Font button
  821. Access : Protected
  822. Return : void
  823. Parameters : none
  824. Usage : Called from MFC
  825. ============================================================*/
  826. {
  827. DoFont();
  828. }
  829. void CRulerRichEditCtrl::OnButtonColor()
  830. /* ============================================================
  831. Function : CRulerRichEditCtrl::OnButtonColor
  832. Description : Button handler for the Color button
  833. Access : Protected
  834. Return : void
  835. Parameters : none
  836. Usage : Called from MFC.
  837. ============================================================*/
  838. {
  839. DoColor();
  840. }
  841. void CRulerRichEditCtrl::OnButtonBold()
  842. /* ============================================================
  843. Function : CRulerRichEditCtrl::OnButtonBold
  844. Description : Button handler for the Bold button
  845. Access : Protected
  846. Return : void
  847. Parameters : none
  848. Usage : Called from MFC.
  849. ============================================================*/
  850. {
  851. DoBold();
  852. }
  853. void CRulerRichEditCtrl::OnButtonWrap()
  854. {
  855. DoWrap();
  856. }
  857. void CRulerRichEditCtrl::OnButtonItalic()
  858. /* ============================================================
  859. Function : CRulerRichEditCtrl::OnButtonItalic
  860. Description : Button handler for the Italic button
  861. Access : Protected
  862. Return : void
  863. Parameters : none
  864. Usage : Called from MFC.
  865. ============================================================*/
  866. {
  867. DoItalic();
  868. }
  869. void CRulerRichEditCtrl::OnButtonUnderline()
  870. /* ============================================================
  871. Function : CRulerRichEditCtrl::OnButtonUnderline
  872. Description : Button handler for the Underline button
  873. Access : Protected
  874. Return : void
  875. Parameters : none
  876. Usage : Called from MFC.
  877. ============================================================*/
  878. {
  879. DoUnderline();
  880. }
  881. void CRulerRichEditCtrl::OnButtonLeftAlign()
  882. /* ============================================================
  883. Function : CRulerRichEditCtrl::OnButtonLeftAlign
  884. Description : Button handler for the Left aligned button
  885. Access : Protected
  886. Return : void
  887. Parameters : none
  888. Usage : Called from MFC.
  889. ============================================================*/
  890. {
  891. DoLeftAlign();
  892. }
  893. void CRulerRichEditCtrl::OnButtonCenterAlign()
  894. /* ============================================================
  895. Function : CRulerRichEditCtrl::OnButtonCenterAlign
  896. Description : Button handler for the Center button
  897. Access : Protected
  898. Return : void
  899. Parameters : none
  900. Usage : Called from MFC.
  901. ============================================================*/
  902. {
  903. DoCenterAlign();
  904. }
  905. void CRulerRichEditCtrl::OnButtonRightAlign()
  906. /* ============================================================
  907. Function : CRulerRichEditCtrl::OnButtonRightAlign
  908. Description : Button handler for the Right-aligned button
  909. Access : Protected
  910. Return : void
  911. Parameters : none
  912. Usage : Called from MFC.
  913. ============================================================*/
  914. {
  915. DoRightAlign();
  916. }
  917. void CRulerRichEditCtrl::OnButtonIndent()
  918. /* ============================================================
  919. Function : CRulerRichEditCtrl::OnButtonIndent
  920. Description : Button handler for the Indent button
  921. Access : Protected
  922. Return : void
  923. Parameters : none
  924. Usage : Called from MFC.
  925. ============================================================*/
  926. {
  927. DoIndent();
  928. }
  929. void CRulerRichEditCtrl::OnButtonOutdent()
  930. /* ============================================================
  931. Function : CRulerRichEditCtrl::OnButtonOutdent
  932. Description : Button handler for the outdent button
  933. Access : Protected
  934. Return : void
  935. Parameters : none
  936. Usage : Called from MFC.
  937. ============================================================*/
  938. {
  939. DoOutdent();
  940. }
  941. void CRulerRichEditCtrl::OnButtonBullet()
  942. /* ============================================================
  943. Function : CRulerRichEditCtrl::OnButtonBullet
  944. Description : Button handler for the Bullet button
  945. Access : Protected
  946. Return : void
  947. Parameters : none
  948. Usage : Called from MFC.
  949. ============================================================*/
  950. {
  951. DoBullet();
  952. }
  953. /////////////////////////////////////////////////////////////////////////////
  954. // CRulerRichEditCtrl private helpers
  955. void CRulerRichEditCtrl::SetTabStops( LPLONG tabs, int size )
  956. /* ============================================================
  957. Function : CRulerRichEditCtrl::SetTabStops
  958. Description : Set the tab stops in the internal tab stop
  959. list from the RTF-control, converting the
  960. twip values to physical pixels.
  961. Access : Private
  962. Return : void
  963. Parameters : LPLONG tabs - A pointer to an array of
  964. "LONG" twip values.
  965. int size - The size of "tabs"
  966. Usage : Call to set the tab list.
  967. ============================================================*/
  968. {
  969. m_tabs.RemoveAll();
  970. double twip = ( double )m_physicalInch / 1440;
  971. for( int t = 0 ; t < size ; t++ )
  972. {
  973. // Convert from twips to pixels
  974. int tabpos = *( tabs + t );
  975. tabpos = ( int ) ( ( double ) tabpos * twip +.5 );
  976. m_tabs.Add( tabpos );
  977. }
  978. m_ruler.SetTabStops( m_tabs );
  979. }
  980. void CRulerRichEditCtrl::UpdateTabStops()
  981. /* ============================================================
  982. Function : CRulerRichEditCtrl::UpdateTabStops
  983. Description : Sets the tabs in the internal tab stop
  984. list, converting the twip physical (pixel)
  985. position to twip values.
  986. Access : Private
  987. Return : void
  988. Parameters : none
  989. Usage : Call to refresh the tab list from the RTF-
  990. control. Called from the "OnPaint" handler.
  991. ============================================================*/
  992. {
  993. ParaFormat para( PFM_TABSTOPS );
  994. m_rtf.GetParaFormat( para );
  995. SetTabStops( (LPLONG)(para.rgxTabs), MAX_TAB_STOPS );
  996. }
  997. void CRulerRichEditCtrl::UpdateToolbarButtons()
  998. /* ============================================================
  999. Function : CRulerRichEditCtrl::UpdateToolbarButtons
  1000. Description : Updates the toolbar button, by getting
  1001. formatting information from the currently
  1002. selected text in the embedded RTF-control.
  1003. Access : Private
  1004. Return : void
  1005. Parameters : none
  1006. Usage : Call as the selection changes in the
  1007. RTF-control
  1008. ============================================================*/
  1009. {
  1010. if( m_showToolbar && m_toolbar.m_hWnd )
  1011. {
  1012. CharFormat cf;
  1013. cf.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE;
  1014. m_rtf.SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1015. ParaFormat para( PFM_ALIGNMENT | PFM_NUMBERING );
  1016. m_rtf.GetParaFormat( para );
  1017. // Style
  1018. m_toolbar.SetState( BUTTON_BOLD, TBSTATE_ENABLED | ( ( cf.dwEffects & CFE_BOLD ) ? TBSTATE_CHECKED : 0 ) );
  1019. m_toolbar.SetState( BUTTON_ITALIC, TBSTATE_ENABLED | ( ( cf.dwEffects & CFE_ITALIC ) ? TBSTATE_CHECKED : 0 ) );
  1020. m_toolbar.SetState( BUTTON_UNDERLINE, TBSTATE_ENABLED | ( ( cf.dwEffects & CFM_UNDERLINE ) ? TBSTATE_CHECKED : 0 ) );
  1021. m_toolbar.SetState( BUTTON_LEFTALIGN, TBSTATE_ENABLED | ( para.wAlignment == PFA_LEFT ? TBSTATE_CHECKED : 0 ) );
  1022. m_toolbar.SetState( BUTTON_CENTERALIGN, TBSTATE_ENABLED | ( para.wAlignment == PFA_CENTER ? TBSTATE_CHECKED : 0 ) );
  1023. m_toolbar.SetState( BUTTON_RIGHTALIGN, TBSTATE_ENABLED | ( para.wAlignment == PFA_RIGHT ? TBSTATE_CHECKED : 0 ) );
  1024. m_toolbar.SetState( BUTTON_BULLET, TBSTATE_ENABLED | ( para.wNumbering ? TBSTATE_CHECKED : 0 ) );
  1025. m_toolbar.SetState( ID_BUTTONWRAP, TBSTATE_ENABLED | ( m_bInWrapMode ? TBSTATE_CHECKED : 0 ));
  1026. if( cf.dwMask & CFM_FACE )
  1027. m_toolbar.SetFontName( CString( cf.szFaceName ) );
  1028. if( cf.dwMask & CFM_SIZE )
  1029. m_toolbar.SetFontSize( cf.yHeight / 20 );
  1030. if( cf.dwMask & CFM_COLOR )
  1031. m_toolbar.SetFontColor( cf.crTextColor );
  1032. }
  1033. }
  1034. void CRulerRichEditCtrl::SetEffect( int mask, int effect )
  1035. /* ============================================================
  1036. Function : CRulerRichEditCtrl::SetEffect
  1037. Description : Sets the effect (bold, italic and/or
  1038. underline) for the currently selected text
  1039. in the embedded RTF-control.
  1040. Access : Private
  1041. Return : void
  1042. Parameters : int mask - What effects are valid. See
  1043. the documentation for
  1044. "CHARFORMAT".
  1045. int effect - What effects to set. See the
  1046. documentation for "CHARFORMAT".
  1047. Usage : Called internally from button handlers
  1048. ============================================================*/
  1049. {
  1050. CharFormat cf;
  1051. cf.dwMask = mask;
  1052. cf.dwEffects = effect;
  1053. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1054. m_rtf.SetFocus();
  1055. }
  1056. void CRulerRichEditCtrl::SetAlignment( int alignment )
  1057. /* ============================================================
  1058. Function : CRulerRichEditCtrl::SetAlignment
  1059. Description : Sets the alignment for the currently
  1060. selected text in the embedded RTF-control.
  1061. Access : Private
  1062. Return : void
  1063. Parameters : int alignment - Alignment to set. See
  1064. documentation for
  1065. "PARAFORMAT"
  1066. Usage : Called internally from button handlers
  1067. ============================================================*/
  1068. {
  1069. ParaFormat para( PFM_ALIGNMENT );
  1070. para.wAlignment = ( WORD ) alignment;
  1071. m_rtf.SetParaFormat( para );
  1072. UpdateToolbarButtons();
  1073. m_rtf.SetFocus();
  1074. }
  1075. // Virtual interface
  1076. void CRulerRichEditCtrl::DoFont()
  1077. /* ============================================================
  1078. Function : CRulerRichEditCtrl::DoFont
  1079. Description : Externally accessible member to set the
  1080. font of the control
  1081. Access : Public
  1082. Return : void
  1083. Parameters : none
  1084. Usage : Call to set the font of the selected text.
  1085. ============================================================*/
  1086. {
  1087. // Get the current font
  1088. LOGFONT lf;
  1089. ZeroMemory( &lf, sizeof( LOGFONT ) );
  1090. CharFormat cf;
  1091. m_rtf.SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1092. int height;
  1093. // Creating a LOGFONT from the current font settings
  1094. // Font
  1095. if( cf.dwMask & CFM_FACE )
  1096. lstrcpy( lf.lfFaceName, cf.szFaceName );
  1097. if( cf.dwMask & CFM_SIZE )
  1098. {
  1099. double twip = ( double )m_physicalInch / 1440;
  1100. height = cf.yHeight;
  1101. height = -( int ) ( ( double ) height * twip +.5 );
  1102. lf.lfHeight = height;
  1103. }
  1104. // Effects
  1105. if( cf.dwMask & CFM_BOLD )
  1106. {
  1107. if( cf.dwEffects & CFE_BOLD )
  1108. lf.lfWeight = FW_BOLD;
  1109. else
  1110. lf.lfWeight = FW_NORMAL;
  1111. }
  1112. if( cf.dwMask & CFM_ITALIC )
  1113. if( cf.dwEffects & CFE_ITALIC )
  1114. lf.lfItalic = TRUE;
  1115. if( cf.dwMask & CFM_UNDERLINE )
  1116. if( cf.dwEffects & CFE_UNDERLINE )
  1117. lf.lfUnderline = TRUE;
  1118. // Show font dialog
  1119. CFontDialog dlg(&lf);
  1120. if(dlg.DoModal() == IDOK)
  1121. {
  1122. // Apply new font
  1123. cf.yHeight = dlg.GetSize() * 2;
  1124. lstrcpy(cf.szFaceName, dlg.GetFaceName());
  1125. cf.dwMask = CFM_FACE | CFM_SIZE;
  1126. cf.dwEffects = 0;
  1127. if( dlg.IsBold() )
  1128. {
  1129. cf.dwMask |= CFM_BOLD;
  1130. cf.dwEffects |= CFE_BOLD;
  1131. }
  1132. if( dlg.IsItalic() )
  1133. {
  1134. cf.dwMask |= CFM_ITALIC;
  1135. cf.dwEffects |= CFE_ITALIC;
  1136. }
  1137. if( dlg.IsUnderline() )
  1138. {
  1139. cf.dwMask |= CFM_UNDERLINE;
  1140. cf.dwEffects |= CFE_UNDERLINE;
  1141. }
  1142. m_rtf.SendMessage(EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
  1143. m_rtf.SetFocus();
  1144. }
  1145. }
  1146. void CRulerRichEditCtrl::SetCurrentFontName( const CString& font )
  1147. /* ============================================================
  1148. Function : CRulerRichEditCtrl::SetCurrentFontName
  1149. Description : Changes the font of the selected text in
  1150. the editor to "font".
  1151. Access : Public
  1152. Return : void
  1153. Parameters : const CString& font - Font name of font
  1154. to change to.
  1155. Usage : Call to set the font of the selected text
  1156. in the editor.
  1157. ============================================================*/
  1158. {
  1159. CharFormat cf;
  1160. cf.dwMask = CFM_FACE;
  1161. lstrcpy( cf.szFaceName, font );
  1162. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1163. }
  1164. void CRulerRichEditCtrl::SetCurrentFontSize( int size )
  1165. /* ============================================================
  1166. Function : CRulerRichEditCtrl::SetCurrentFontSize
  1167. Description : Changes the size of the selected text in
  1168. the editor to "size" (measured in
  1169. typographical points).
  1170. Access : Public
  1171. Return : void
  1172. Parameters : int size - New size in typographical
  1173. points
  1174. Usage : Call to change the size of the selected
  1175. text.
  1176. ============================================================*/
  1177. {
  1178. CharFormat cf;
  1179. cf.dwMask = CFM_SIZE;
  1180. cf.yHeight = size * 20;
  1181. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1182. }
  1183. void CRulerRichEditCtrl::SetCurrentFontColor( COLORREF color )
  1184. /* ============================================================
  1185. Function : CRulerRichEditCtrl::SetCurrentFontSize
  1186. Description : Changes the color of the selected text in
  1187. the editor to "color".
  1188. Access : Public
  1189. Return : void
  1190. Parameters : COLORREF color - New color
  1191. Usage : Call to change the color of the selected
  1192. text.
  1193. ============================================================*/
  1194. {
  1195. CharFormat cf;
  1196. cf.dwMask = CFM_COLOR;
  1197. cf.crTextColor = color;
  1198. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1199. }
  1200. LRESULT CRulerRichEditCtrl::OnSetCurrentFontName( WPARAM font, LPARAM )
  1201. /* ============================================================
  1202. Function : CRulerRichEditCtrl::OnSetCurrentFontName
  1203. Description : Handler for the registered message
  1204. "urm_SETCURRENTFONTNAME", called when the
  1205. font name is changed from the toolbar.
  1206. Access : Protected
  1207. Return : LRESULT - Not used
  1208. Parameters : WPARAM font - Pointer to the new font name
  1209. LPARAM - Not used
  1210. Usage : Called from MFC
  1211. ============================================================*/
  1212. {
  1213. CString fnt( ( LPCTSTR ) font );
  1214. SetCurrentFontName( fnt );
  1215. return 0;
  1216. }
  1217. LRESULT CRulerRichEditCtrl::OnSetCurrentFontSize(WPARAM, LPARAM size)
  1218. /* ============================================================
  1219. Function : CRulerRichEditCtrl::OnSetCurrentFontSize
  1220. Description : Handler for the registered message
  1221. "urm_SETCURRENTFONTSIZE", called when the
  1222. font size is changed from the toolbar.
  1223. Access : Protected
  1224. Return : LRESULT - Not used
  1225. Parameters : WPARAM - Not used
  1226. LPARAM size - New font size in typographical
  1227. points of the selected text
  1228. Usage : Called from MFC
  1229. ============================================================*/
  1230. {
  1231. SetCurrentFontSize((int)size);
  1232. return 0;
  1233. }
  1234. LRESULT CRulerRichEditCtrl::OnSetCurrentFontColor(WPARAM, LPARAM color)
  1235. /* ============================================================
  1236. Function : CRulerRichEditCtrl::OnSetCurrentFontColor
  1237. Description : Handler for the registered message
  1238. "urm_SETCURRENTFONTCOLOR", called when the
  1239. font color is changed from the toolbar.
  1240. Access : Protected
  1241. Return : LRESULT - Not used
  1242. Parameters : WPARAM - Not used
  1243. LPARAM - New color of the selected
  1244. text
  1245. Usage : Called from MFC
  1246. ============================================================*/
  1247. {
  1248. SetCurrentFontColor( ( COLORREF ) color );
  1249. return 0;
  1250. }
  1251. void CRulerRichEditCtrl::DoColor()
  1252. /* ============================================================
  1253. Function : CRulerRichEditCtrl::DoColor
  1254. Description : Externally accessible member to set the
  1255. color of the selected text
  1256. Access : Public
  1257. Return : void
  1258. Parameters : none
  1259. Usage : Call to set the color of the selected text.
  1260. ============================================================*/
  1261. {
  1262. // Get the current color
  1263. COLORREF clr( RGB( 0, 0, 0 ) );
  1264. CharFormat cf;
  1265. m_rtf.SendMessage( EM_GETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1266. if( cf.dwMask & CFM_COLOR )
  1267. clr = cf.crTextColor;
  1268. // Display color selection dialog
  1269. CColorDialog dlg( clr );
  1270. if( dlg.DoModal() == IDOK )
  1271. {
  1272. // Apply new color
  1273. cf.dwMask = CFM_COLOR;
  1274. cf.dwEffects = 0;
  1275. cf.crTextColor = dlg.GetColor();
  1276. m_rtf.SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, ( LPARAM ) &cf );
  1277. }
  1278. m_rtf.SetFocus();
  1279. }
  1280. void CRulerRichEditCtrl::DoWrap()
  1281. {
  1282. if(m_bInWrapMode)
  1283. {
  1284. // Turn off word wrap.
  1285. m_rtf.SetTargetDevice(NULL, 1);
  1286. m_bInWrapMode = false;
  1287. }
  1288. else
  1289. {
  1290. // Turn on word wrap.
  1291. m_rtf.SetTargetDevice(NULL, 0);
  1292. m_bInWrapMode = true;
  1293. }
  1294. g_Opt.SetEditWordWrap(m_bInWrapMode);
  1295. m_toolbar.CheckButton(ID_BUTTONWRAP, m_bInWrapMode);
  1296. }
  1297. void CRulerRichEditCtrl::DoBold()
  1298. /* ============================================================
  1299. Function : CRulerRichEditCtrl::DoBold
  1300. Description : Externally accessible member to set/unset
  1301. the selected text to/from bold
  1302. Access : Public
  1303. Return : void
  1304. Parameters : none
  1305. Usage : Call to toggle the selected text to/from
  1306. bold.
  1307. ============================================================*/
  1308. {
  1309. m_toolbar.CheckButton( BUTTON_BOLD, !m_toolbar.IsButtonChecked( BUTTON_BOLD ) );
  1310. int effect = 0;
  1311. if( m_toolbar.IsButtonChecked( BUTTON_BOLD ) )
  1312. effect = CFE_BOLD;
  1313. SetEffect( CFM_BOLD, effect );
  1314. }
  1315. void CRulerRichEditCtrl::DoItalic()
  1316. /* ============================================================
  1317. Function : CRulerRichEditCtrl::DoItalic
  1318. Description : Externally accessible member to set/unset
  1319. the selected text to/from italic
  1320. Access : Public
  1321. Return : void
  1322. Parameters : none
  1323. Usage : Call to toggle the selected text to/from
  1324. italic.
  1325. =========================================================== =*/
  1326. {
  1327. m_toolbar.CheckButton( BUTTON_ITALIC, !m_toolbar.IsButtonChecked( BUTTON_ITALIC ) );
  1328. int effect = 0;
  1329. if( m_toolbar.IsButtonChecked( BUTTON_ITALIC ) )
  1330. effect = CFE_ITALIC;
  1331. SetEffect( CFM_ITALIC, effect );
  1332. }
  1333. void CRulerRichEditCtrl::DoUnderline()
  1334. /* ============================================================
  1335. Function : CRulerRichEditCtrl::DoUnderline
  1336. Description : Externally accessible member to set/unset
  1337. the selected text to/from underline
  1338. Access : Public
  1339. Return : void
  1340. Parameters : none
  1341. Usage : Call to toggle the selected text to/from
  1342. underlined.
  1343. ============================================================*/
  1344. {
  1345. m_toolbar.CheckButton( BUTTON_UNDERLINE, !m_toolbar.IsButtonChecked( BUTTON_UNDERLINE ) );
  1346. int effect = 0;
  1347. if( m_toolbar.IsButtonChecked( BUTTON_UNDERLINE ) )
  1348. effect = CFE_UNDERLINE;
  1349. SetEffect( CFM_UNDERLINE, effect );
  1350. }
  1351. void CRulerRichEditCtrl::DoLeftAlign()
  1352. /* ============================================================
  1353. Function : CRulerRichEditCtrl::DoLeftAlign
  1354. Description : Externally accessible member to set the
  1355. selected text to left aligned.
  1356. Access : Public
  1357. Return : void
  1358. Parameters : none
  1359. Usage : Call to left-align the selected text
  1360. ============================================================*/
  1361. {
  1362. if( !m_toolbar.IsButtonChecked( BUTTON_LEFTALIGN ) )
  1363. SetAlignment( PFA_LEFT );
  1364. }
  1365. void CRulerRichEditCtrl::DoCenterAlign()
  1366. /* ============================================================
  1367. Function : CRulerRichEditCtrl::DoCenterAlign
  1368. Description : Externally accessible member to set the
  1369. selected text to center aligned
  1370. Access : Public
  1371. Return : void
  1372. Parameters : none
  1373. Usage : Call to center-align the selected text
  1374. ============================================================*/
  1375. {
  1376. if( !m_toolbar.IsButtonChecked( BUTTON_CENTERALIGN ) )
  1377. SetAlignment( PFA_CENTER );
  1378. }
  1379. void CRulerRichEditCtrl::DoRightAlign()
  1380. /* ============================================================
  1381. Function : CRulerRichEditCtrl::DoRightAlign
  1382. Description : Externally accessible member to set the
  1383. selected text to right aligned
  1384. Access : Public
  1385. Return : void
  1386. Parameters : none
  1387. Usage : Call to right-align the selected text
  1388. ============================================================*/
  1389. {
  1390. if( !m_toolbar.IsButtonChecked( BUTTON_RIGHTALIGN ) )
  1391. SetAlignment( PFA_RIGHT );
  1392. }
  1393. void CRulerRichEditCtrl::DoIndent()
  1394. /* ============================================================
  1395. Function : CRulerRichEditCtrl::DoIndent
  1396. Description : Externally accessible member to indent the
  1397. selected text to the next tab position
  1398. Access : Public
  1399. Return : void
  1400. Parameters : none
  1401. Usage : Call to indent the selected text
  1402. ============================================================*/
  1403. {
  1404. // Get current indent
  1405. ParaFormat para( PFM_STARTINDENT | PFM_TABSTOPS );
  1406. m_rtf.GetParaFormat( para );
  1407. int newindent = para.dxStartIndent;
  1408. // Find next larger tab
  1409. for( int t = MAX_TAB_STOPS - 1 ; t >= 0 ; t-- )
  1410. {
  1411. if( para.rgxTabs[ t ] > para.dxStartIndent )
  1412. newindent = para.rgxTabs[ t ];
  1413. }
  1414. if( newindent != para.dxStartIndent )
  1415. {
  1416. // Set indent to this value
  1417. para.dwMask = PFM_STARTINDENT | PFM_OFFSET;
  1418. para.dxStartIndent = newindent;
  1419. para.dxOffset = newindent;
  1420. m_rtf.SetParaFormat( para );
  1421. }
  1422. m_rtf.SetFocus();
  1423. }
  1424. void CRulerRichEditCtrl::DoOutdent()
  1425. /* ============================================================
  1426. Function : CRulerRichEditCtrl::DoOutdent
  1427. Description : Externally accessible member to outdent the
  1428. selected text to the previous tab position
  1429. Access : Public
  1430. Return : void
  1431. Parameters : none
  1432. Usage : Call to outdent the selected text
  1433. ============================================================*/
  1434. {
  1435. // Get the current indent, if any
  1436. ParaFormat para( PFM_STARTINDENT | PFM_TABSTOPS );
  1437. m_rtf.GetParaFormat( para );
  1438. int newindent = 0;
  1439. // Find closest smaller tab
  1440. for( int t = 0 ; t < MAX_TAB_STOPS ; t++ )
  1441. if( para.rgxTabs[ t ] < para.dxStartIndent )
  1442. newindent = para.rgxTabs[ t ];
  1443. // Set indent to this value or 0 if none
  1444. para.dwMask = PFM_STARTINDENT | PFM_OFFSET;
  1445. para.dxStartIndent = newindent;
  1446. para.dxOffset = newindent;
  1447. m_rtf.SetParaFormat( para );
  1448. m_rtf.SetFocus();
  1449. }
  1450. void CRulerRichEditCtrl::DoBullet()
  1451. /* ============================================================
  1452. Function : CRulerRichEditCtrl::DoBullet
  1453. Description : Externally accessible member to set the
  1454. selected text to bulleted
  1455. Access : Public
  1456. Return : void
  1457. Parameters : none
  1458. Usage : Call to set the selected text to bulleted.
  1459. ============================================================*/
  1460. {
  1461. m_toolbar.CheckButton( BUTTON_BULLET, !m_toolbar.IsButtonChecked( BUTTON_BULLET ) );
  1462. ParaFormat para( PFM_NUMBERING );
  1463. if( m_toolbar.IsButtonChecked( BUTTON_BULLET ) )
  1464. para.wNumbering = PFN_BULLET;
  1465. else
  1466. para.wNumbering = 0;
  1467. m_rtf.SetParaFormat( para );
  1468. m_rtf.SetFocus();
  1469. }
  1470. void CRulerRichEditCtrl::ShowToolbar( BOOL show )
  1471. /* ============================================================
  1472. Function : CRulerRichEditCtrl::ShowToolbar
  1473. Description : Shows or hides the toolbar
  1474. Access : Public
  1475. Return : void
  1476. Parameters : BOOL show - "TRUE" to show
  1477. Usage : Call to show or hide the toolbar subcontrol
  1478. ============================================================*/
  1479. {
  1480. m_showToolbar = show;
  1481. if( m_hWnd )
  1482. {
  1483. if( show )
  1484. m_toolbar.ShowWindow( SW_SHOW );
  1485. else
  1486. m_toolbar.ShowWindow( SW_HIDE );
  1487. CRect rect;
  1488. GetClientRect( rect );
  1489. LayoutControls( rect.Width(), rect.Height() );
  1490. }
  1491. }
  1492. void CRulerRichEditCtrl::ShowRuler( BOOL show )
  1493. /* ============================================================
  1494. Function : CRulerRichEditCtrl::ShowRuler
  1495. Description : Shows or hides the ruler
  1496. Access : Public
  1497. Return : void
  1498. Parameters : BOOL show - "TRUE" to show
  1499. Usage : Call to show or hide the ruler subcontrol
  1500. ============================================================*/
  1501. {
  1502. m_showRuler = show;
  1503. if( m_hWnd )
  1504. {
  1505. if( show )
  1506. m_ruler.ShowWindow( SW_SHOW );
  1507. else
  1508. m_ruler.ShowWindow( SW_HIDE );
  1509. CRect rect;
  1510. GetClientRect( rect );
  1511. LayoutControls( rect.Width(), rect.Height() );
  1512. }
  1513. }
  1514. void CRulerRichEditCtrl::LayoutControls( int width, int height )
  1515. /* ============================================================
  1516. Function : CRulerRichEditCtrl::LayoutControls
  1517. Description : Lays out the sub-controls depending on
  1518. visibility.
  1519. Access : Private
  1520. Return : void
  1521. Parameters : int width - Width of control
  1522. int height - Height of control
  1523. Usage : Called internally to lay out the controls
  1524. ============================================================*/
  1525. {
  1526. int toolbarHeight = 0;
  1527. if( m_showToolbar )
  1528. toolbarHeight = TOOLBAR_HEIGHT;
  1529. int rulerHeight = 0;
  1530. if( m_showRuler )
  1531. rulerHeight = RULER_HEIGHT;
  1532. m_toolbar.MoveWindow( 0, 0, width, toolbarHeight );
  1533. m_ruler.MoveWindow( 0, toolbarHeight, width, rulerHeight );
  1534. int top = toolbarHeight + rulerHeight;
  1535. CRect rect( 0, top, width, height );
  1536. m_rtf.MoveWindow( rect );
  1537. }
  1538. BOOL CRulerRichEditCtrl::IsToolbarVisible() const
  1539. /* ============================================================
  1540. Function : CRulerRichEditCtrl::IsToolbarVisible
  1541. Description : Returns if the toolbar is visible or not
  1542. Access : Public
  1543. Return : BOOL - "TRUE" if visible
  1544. Parameters : none
  1545. Usage : Call to get the visibility of the toolbar
  1546. ============================================================*/
  1547. {
  1548. return m_showToolbar;
  1549. }
  1550. BOOL CRulerRichEditCtrl::IsRulerVisible() const
  1551. /* ============================================================
  1552. Function : CRulerRichEditCtrl::IsRulerVisible
  1553. Description : Returns if the ruler is visible or not
  1554. Access : Public
  1555. Return : BOOL - "TRUE" if visible
  1556. Parameters : none
  1557. Usage : Call to get the visibility of the ruler
  1558. ============================================================*/
  1559. {
  1560. return m_showRuler;
  1561. }
  1562. void CRulerRichEditCtrl::SetReadOnly( BOOL readOnly )
  1563. /* ============================================================
  1564. Function : CRulerRichEditCtrl::SetReadOnly
  1565. Description : Sets the control to read only or not.
  1566. Access : Public
  1567. Return : void
  1568. Parameters : BOOL readOnly - New read only state
  1569. Usage : Call to set the read only state of the
  1570. control
  1571. ============================================================*/
  1572. {
  1573. if( m_rtf.m_hWnd )
  1574. m_rtf.SetReadOnly( readOnly );
  1575. m_readOnly = readOnly;
  1576. }
  1577. BOOL CRulerRichEditCtrl::GetReadOnly() const
  1578. /* ============================================================
  1579. Function : CRulerRichEditCtrl::GetReadOnly
  1580. Description : Returns if the control is read only or not
  1581. Access : Public
  1582. Return : BOOL - "TRUE" if read only
  1583. Parameters : none
  1584. Usage : Call to get the read only-state of the
  1585. control
  1586. ============================================================*/
  1587. {
  1588. return m_readOnly;
  1589. }
  1590. BOOL CRulerRichEditCtrl::PreTranslateMessage(MSG* pMsg)
  1591. {
  1592. if(pMsg->message == WM_KEYDOWN)
  1593. {
  1594. switch(pMsg->wParam)
  1595. {
  1596. case 'X':
  1597. if(CONTROL_PRESSED)
  1598. {
  1599. m_rtf.Cut();
  1600. return TRUE;
  1601. }
  1602. break;
  1603. case 'C':
  1604. if(CONTROL_PRESSED)
  1605. {
  1606. m_rtf.Copy();
  1607. return TRUE;
  1608. }
  1609. break;
  1610. case 'V':
  1611. if(CONTROL_PRESSED)
  1612. {
  1613. m_rtf.Paste();
  1614. return TRUE;
  1615. }
  1616. break;
  1617. case 'I':
  1618. if(CONTROL_PRESSED)
  1619. {
  1620. DoItalic();
  1621. return TRUE;
  1622. }
  1623. break;
  1624. case 'B':
  1625. if(CONTROL_PRESSED)
  1626. {
  1627. DoBold();
  1628. return TRUE;
  1629. }
  1630. break;
  1631. case 'U':
  1632. if(CONTROL_PRESSED)
  1633. {
  1634. DoUnderline();
  1635. return TRUE;
  1636. }
  1637. break;
  1638. case 'Z':
  1639. if(CONTROL_PRESSED)
  1640. {
  1641. m_rtf.Undo();
  1642. return TRUE;
  1643. }
  1644. break;
  1645. case 'Y':
  1646. if(CONTROL_PRESSED)
  1647. {
  1648. m_rtf.Redo();
  1649. return TRUE;
  1650. }
  1651. break;
  1652. case 'W':
  1653. if(CONTROL_PRESSED)
  1654. {
  1655. DoWrap();
  1656. return TRUE;
  1657. }
  1658. break;
  1659. }
  1660. }
  1661. return CWnd::PreTranslateMessage(pMsg);
  1662. }