TextEdit.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // TextEdit.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "eastdraw.h"
  5. #include "TextEdit.h"
  6. #include "ReginSet.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CTextEdit
  14. CTextEdit::CTextEdit()
  15. {
  16. m_IsMoving=false;
  17. m_IsOnMoving=false;
  18. m_Font=new CFont;
  19. m_Font->CreatePointFont (100, _T ("Arial"));
  20. }
  21. CTextEdit::~CTextEdit()
  22. {
  23. }
  24. BEGIN_MESSAGE_MAP(CTextEdit, CEdit)
  25. //{{AFX_MSG_MAP(CTextEdit)
  26. ON_WM_CONTEXTMENU()
  27. ON_COMMAND(ID_UnDo, OnUnDo)
  28. ON_COMMAND(ID_Cut, OnCut)
  29. ON_COMMAND(ID_Copy, OnCopy)
  30. ON_COMMAND(ID_Past, OnPast)
  31. ON_COMMAND(ID_Delete, OnDelete)
  32. ON_COMMAND(ID_SelectAll, OnSelectAll)
  33. ON_COMMAND(ID_Move, OnMove)
  34. ON_WM_LBUTTONDOWN()
  35. ON_WM_MOUSEMOVE()
  36. ON_WM_LBUTTONUP()
  37. ON_COMMAND(ID_MENUITEM_Size, OnMENUITEMSize)
  38. ON_WM_CREATE()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CTextEdit message handlers
  43. void CTextEdit::OnContextMenu(CWnd* pWnd, CPoint point)
  44. {
  45. // TODO: Add your message handler code here
  46. CMenu menuTextEdit;
  47. menuTextEdit.LoadMenu(IDR_MENU_TextEdit);
  48. menuTextEdit.CheckMenuItem(ID_Move,m_IsMoving?MF_CHECKED:MF_UNCHECKED);
  49. menuTextEdit.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
  50. }
  51. void CTextEdit::OnUnDo()
  52. {
  53. // TODO: Add your command handler code here
  54. CEdit::Undo();
  55. }
  56. void CTextEdit::OnCut()
  57. {
  58. // TODO: Add your command handler code here
  59. CEdit::Cut();
  60. }
  61. void CTextEdit::OnCopy()
  62. {
  63. // TODO: Add your command handler code here
  64. CEdit::Copy();
  65. }
  66. void CTextEdit::OnPast()
  67. {
  68. // TODO: Add your command handler code here
  69. CEdit::Paste();
  70. }
  71. void CTextEdit::OnDelete()
  72. {
  73. // TODO: Add your command handler code here
  74. CEdit::Clear();
  75. }
  76. void CTextEdit::OnSelectAll()
  77. {
  78. // TODO: Add your command handler code here
  79. CEdit::SetSel(0,-1);
  80. }
  81. void CTextEdit::OnMove()
  82. {
  83. // TODO: Add your command handler code here
  84. m_IsMoving=!m_IsMoving;
  85. }
  86. void CTextEdit::OnLButtonDown(UINT nFlags, CPoint point)
  87. {
  88. // TODO: Add your message handler code here and/or call default
  89. m_FirstPoint=point;
  90. CEdit::OnLButtonDown(nFlags, point);
  91. }
  92. void CTextEdit::OnMouseMove(UINT nFlags, CPoint point)
  93. {
  94. // TODO: Add your message handler code here and/or call default
  95. /*if(m_IsOnMoving)
  96. {
  97. CRect rect;
  98. this->GetWindowRect(&rect);
  99. m_PositionPoint.Offset(point.x-m_FirstPoint.x,point.y-m_FirstPoint.y);
  100. this->MoveWindow(m_PositionPoint.x,m_PositionPoint.y,rect.Width(),rect.Height(),true);
  101. this->m_FirstPoint=point;
  102. }
  103. */
  104. CEdit::OnMouseMove(nFlags, point);
  105. }
  106. void CTextEdit::OnLButtonUp(UINT nFlags, CPoint point)
  107. {
  108. // TODO: Add your message handler code here and/or call default
  109. /* if(m_IsOnMoving)
  110. {
  111. CRect rect;
  112. this->GetWindowRect(&rect);
  113. m_PositionPoint.Offset(point.x-m_FirstPoint.x,point.y-m_FirstPoint.y);
  114. this->MoveWindow(m_PositionPoint.x,m_PositionPoint.y,rect.Width(),rect.Height(),true);
  115. this->m_FirstPoint=point;
  116. m_IsOnMoving=false;
  117. }
  118. */
  119. CEdit::OnLButtonUp(nFlags, point);
  120. }
  121. void CTextEdit::OnMENUITEMSize()
  122. {
  123. // TODO: Add your command handler code here
  124. CRect rect;
  125. GetWindowRect(&rect);
  126. CReginSet dRegDlg;
  127. dRegDlg.m_Length=rect.Width();
  128. dRegDlg.m_Width=rect.Height();
  129. if(dRegDlg.DoModal()==IDOK)
  130. {
  131. this->MoveWindow(m_PositionPoint.x,m_PositionPoint.y,dRegDlg.m_Length,dRegDlg.m_Width);
  132. }
  133. }
  134. void CTextEdit::SetMyFont(CFont *font)
  135. {
  136. LOGFONT lfFont;
  137. font->GetLogFont(&lfFont);
  138. m_Font->DeleteObject();
  139. m_Font->CreateFontIndirect(&lfFont);
  140. SetFont(m_Font);
  141. }
  142. int CTextEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
  143. {
  144. if (CEdit::OnCreate(lpCreateStruct) == -1)
  145. return -1;
  146. // TODO: Add your specialized creation code here
  147. this->SetFont(m_Font);
  148. return 0;
  149. }