RulerRichEdit.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* ==========================================================================
  2. File : RuleRichEdit.cpp
  3. Class : CRulerRichEdit
  4. Author : Johan Rosengren, Abstrakt Mekanik AB
  5. Iain Clarke
  6. Date : 2004-04-17
  7. Purpose : "CRulerRichEdit" is derived from "CWnd".
  8. Description : The class, in addition to the normal "CWnd",
  9. handles horizontal scrollbar messages - forcing an
  10. update of the parent (to synchronize the ruler). The
  11. change notification is called for the same reason.
  12. "WM_GETDLGCODE" is handled, we want all keys in a
  13. dialog box instantiation.
  14. Usage : This class is only useful as a child of the
  15. "CRulerRichEditCtrl".
  16. ========================================================================*/
  17. #include "stdafx.h"
  18. #include "ids.h"
  19. #include "RulerRichEdit.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. #ifdef _UNICODE
  26. #define RTF_CLASS RICHEDIT_CLASSW
  27. #else
  28. #define RTF_CLASS RICHEDIT_CLASSA
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CRulerRichEdit
  32. CRulerRichEdit::CRulerRichEdit()
  33. /* ============================================================
  34. Function : CRulerRichEdit::CRulerRichEdit
  35. Description : constructor
  36. Access : Public
  37. Return : void
  38. Parameters : none
  39. Usage :
  40. ============================================================*/
  41. {
  42. }
  43. CRulerRichEdit::~CRulerRichEdit()
  44. /* ============================================================
  45. Function : CRulerRichEdit::~CRulerRichEdit
  46. Description : destructor
  47. Access : Public
  48. Return : void
  49. Parameters : none
  50. Usage :
  51. ============================================================*/
  52. {
  53. }
  54. BEGIN_MESSAGE_MAP(CRulerRichEdit, CRichEditCtrlEx)
  55. //{{AFX_MSG_MAP(CRulerRichEdit)
  56. ON_WM_HSCROLL()
  57. ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
  58. ON_WM_GETDLGCODE()
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. BOOL CRulerRichEdit::Create( DWORD style, CRect rect, CWnd* parent )
  62. /* ============================================================
  63. Function : CRulerRichEdit::~CRulerRichEdit
  64. Description : Creates the control
  65. Access : Public
  66. Return : BOOL - "TRUE" if created ok
  67. Parameters : DWORD - Style for the control
  68. CRect rect - Position of the control
  69. CWnd* parent - Parent of the control
  70. Usage : Call to create the control
  71. ============================================================*/
  72. {
  73. return CWnd::Create (L"RICHEDIT50W", NULL, style, rect, parent, RTF_CONTROL );
  74. };
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CRulerRichEdit message handlers
  77. void CRulerRichEdit::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  78. /* ============================================================
  79. Function : CRulerRichEdit::OnHScroll
  80. Description : Handles the "WM_HSCROLL" message.
  81. Access : Protected
  82. Return : void
  83. Parameters : UINT nSBCode - Type of operation
  84. UINT nPos - New position
  85. CScrollBar* pScrollBar - Pointer to scrollbar
  86. Usage : Called from MFC. Updates the ruler.
  87. ============================================================*/
  88. {
  89. CWnd::OnHScroll( nSBCode, nPos, pScrollBar );
  90. SCROLLINFO si;
  91. ZeroMemory( &si, sizeof( SCROLLINFO ) );
  92. si.cbSize = sizeof( SCROLLINFO );
  93. GetScrollInfo( SB_HORZ, &si );
  94. if ( nSBCode == SB_THUMBTRACK )
  95. {
  96. si.nPos = nPos;
  97. SetScrollInfo( SB_HORZ, &si );
  98. }
  99. UpdateRuler();
  100. }
  101. void CRulerRichEdit::OnChange()
  102. /* ============================================================
  103. Function : CRulerRichEdit::OnChange
  104. Description : Handles change-notifications.
  105. Access : Protected
  106. Return : void
  107. Parameters : none
  108. Usage : Called from MFC. Updates the ruler if text
  109. is deleted, for example.
  110. ============================================================*/
  111. {
  112. UpdateRuler();
  113. }
  114. UINT CRulerRichEdit::OnGetDlgCode()
  115. /* ============================================================
  116. Function : CRulerRichEdit::OnGetDlgCode
  117. Description : Handles the "WM_GETDLGCODE" message.
  118. Access : Protected
  119. Return : UINT - The keys we are interested in.
  120. Parameters : none
  121. Usage : Called from MFC. Handled to make sure
  122. keypresses stays with us.
  123. ============================================================*/
  124. {
  125. return DLGC_WANTALLKEYS;
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CRulerRichEdit private helpers
  129. void CRulerRichEdit::UpdateRuler()
  130. /* ============================================================
  131. Function : CRulerRichEdit::UpdateRuler
  132. Description : Updates the ruler.
  133. Access : Private
  134. Return : void
  135. Parameters : none
  136. Usage : Call to update the parent ruler field.
  137. ============================================================*/
  138. {
  139. CRect rect;
  140. GetClientRect( rect );
  141. rect.top = TOOLBAR_HEIGHT;
  142. rect.bottom = rect.top + TOP_HEIGHT;
  143. GetParent()->RedrawWindow( rect );
  144. }