MsgView.cpp
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. // MsgView.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "MsgView.h"
  16. #include "icqlink.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CMsgView
  24. IMPLEMENT_DYNCREATE(CMsgView, CFormView)
  25. CMsgView::CMsgView()
  26. : CFormView(CMsgView::IDD)
  27. {
  28. //{{AFX_DATA_INIT(CMsgView)
  29. m_date = _T("");
  30. m_content = _T("");
  31. m_receiver = _T("");
  32. m_sender = _T("");
  33. m_time = _T("");
  34. //}}AFX_DATA_INIT
  35. }
  36. CMsgView::~CMsgView()
  37. {
  38. }
  39. void CMsgView::save(DBOutStream &out)
  40. {
  41. CHARFORMAT cf;
  42. cf.cbSize = sizeof(cf);
  43. cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE;
  44. m_msgEdit.GetDefaultCharFormat(cf);
  45. out << cf.szFaceName << (uint32) cf.yHeight << cf.crTextColor;
  46. }
  47. void CMsgView::load(DBInStream &in)
  48. {
  49. string faceName;
  50. uint32 size, color;
  51. in >> faceName >> size >> color;
  52. CHARFORMAT cf;
  53. cf.cbSize = sizeof(cf);
  54. cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE;
  55. lstrcpy(cf.szFaceName, faceName.c_str());
  56. cf.yHeight = size;
  57. cf.crTextColor = color;
  58. cf.dwEffects = 0;
  59. m_msgEdit.SetDefaultCharFormat(cf);
  60. }
  61. void CMsgView::showMsg(IcqMsg *msg)
  62. {
  63. if (msg) {
  64. int sendFace, recvFace;
  65. IcqContact *c = icqLink->findContact(msg->uin);
  66. if (c) {
  67. m_sender = c->nick.c_str();
  68. sendFace = c->face;
  69. } else {
  70. m_sender.Format("%lu", msg->uin);
  71. sendFace = -1;
  72. }
  73. m_receiver = icqLink->myInfo.nick.c_str();
  74. recvFace = icqLink->myInfo.face;
  75. if (!(msg->flags & MF_RECEIVED)) {
  76. CString tmp = m_sender;
  77. m_sender = m_receiver;
  78. m_receiver = tmp;
  79. int t = sendFace;
  80. sendFace = recvFace;
  81. recvFace = t;
  82. }
  83. CTime time((time_t) msg->when);
  84. m_date = time.Format("%Y-%m-%d");
  85. m_time = time.Format("%H:%M:%S");
  86. getMsgText(msg, m_content);
  87. if (sendFace >= 0) {
  88. int i = getApp()->getImageIndex(sendFace);
  89. m_sendFace.SetIcon(getApp()->largeImageList.ExtractIcon(i));
  90. GetDlgItem(IDC_FACE_SENDER)->ShowWindow(SW_SHOW);
  91. } else
  92. GetDlgItem(IDC_FACE_SENDER)->ShowWindow(SW_HIDE);
  93. if (recvFace >= 0) {
  94. int i = getApp()->getImageIndex(recvFace);
  95. m_recvFace.SetIcon(getApp()->largeImageList.ExtractIcon(i));
  96. GetDlgItem(IDC_FACE_RECEIVER)->ShowWindow(SW_SHOW);
  97. } else
  98. GetDlgItem(IDC_FACE_RECEIVER)->ShowWindow(SW_HIDE);
  99. } else {
  100. GetDlgItem(IDC_FACE_RECEIVER)->ShowWindow(SW_HIDE);
  101. GetDlgItem(IDC_FACE_SENDER)->ShowWindow(SW_HIDE);
  102. m_sender.Empty();
  103. m_receiver.Empty();
  104. m_date.Empty();
  105. m_time.Empty();
  106. m_content.Empty();
  107. }
  108. UpdateData(FALSE);
  109. }
  110. void CMsgView::DoDataExchange(CDataExchange* pDX)
  111. {
  112. CFormView::DoDataExchange(pDX);
  113. //{{AFX_DATA_MAP(CMsgView)
  114. DDX_Control(pDX, IDC_MSG_EDIT, m_msgEdit);
  115. DDX_Control(pDX, IDC_FACE_SENDER, m_sendFace);
  116. DDX_Control(pDX, IDC_FACE_RECEIVER, m_recvFace);
  117. DDX_Text(pDX, IDC_DATE, m_date);
  118. DDX_Text(pDX, IDC_MSG_EDIT, m_content);
  119. DDX_Text(pDX, IDC_RECEIVER, m_receiver);
  120. DDX_Text(pDX, IDC_SENDER, m_sender);
  121. DDX_Text(pDX, IDC_TIME, m_time);
  122. //}}AFX_DATA_MAP
  123. }
  124. BEGIN_MESSAGE_MAP(CMsgView, CFormView)
  125. //{{AFX_MSG_MAP(CMsgView)
  126. ON_WM_SIZE()
  127. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  128. ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  129. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  130. ON_UPDATE_COMMAND_UI(ID_VIEW_FONT, OnUpdateViewFont)
  131. //}}AFX_MSG_MAP
  132. ON_NOTIFY(EN_MSGFILTER, IDC_MSG_EDIT, OnRclickMsgEdit)
  133. END_MESSAGE_MAP()
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CMsgView diagnostics
  136. #ifdef _DEBUG
  137. void CMsgView::AssertValid() const
  138. {
  139. CFormView::AssertValid();
  140. }
  141. void CMsgView::Dump(CDumpContext& dc) const
  142. {
  143. CFormView::Dump(dc);
  144. }
  145. #endif //_DEBUG
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CMsgView message handlers
  148. void CMsgView::OnSize(UINT nType, int cx, int cy) 
  149. {
  150. CFormView::OnSize(nType, cx, cy);
  151. CWnd *pWnd = GetDlgItem(IDC_MSG_EDIT);
  152. if (pWnd) {
  153. CRect rc;
  154. pWnd->GetWindowRect(rc);
  155. ScreenToClient(rc);
  156. pWnd->SetWindowPos(NULL, 0, 0, cx, cy - rc.top, SWP_NOMOVE | SWP_NOZORDER);
  157. }
  158. }
  159. void CMsgView::OnRclickMsgEdit(NMHDR* pNMHDR, LRESULT* pResult) 
  160. {
  161. MSGFILTER *pMsgFilter = (MSGFILTER *) pNMHDR;
  162. if (pMsgFilter->msg == WM_RBUTTONDOWN) {
  163. CMenu menu;
  164. menu.LoadMenu(IDR_MSGVIEW_POPUP);
  165. CPoint pt;
  166. GetCursorPos(&pt);
  167. menu.GetSubMenu(0)->TrackPopupMenu(0, pt.x, pt.y, GetTopLevelFrame());
  168. }
  169. *pResult = 0;
  170. }
  171. void CMsgView::OnInitialUpdate() 
  172. {
  173. CFormView::OnInitialUpdate();
  174. m_msgEdit.SetEventMask(m_msgEdit.GetEventMask() | ENM_MOUSEEVENTS);
  175. }
  176. void CMsgView::OnUpdateEditCopy(CCmdUI* pCmdUI) 
  177. {
  178. long start, end;
  179. m_msgEdit.GetSel(start, end);
  180. pCmdUI->Enable(start != end);
  181. }
  182. void CMsgView::OnEditSelectAll() 
  183. {
  184. m_msgEdit.SetSel(0, -1);
  185. }
  186. void CMsgView::OnEditCopy() 
  187. {
  188. CString str = m_msgEdit.GetSelText();
  189. if (OpenClipboard()) {
  190. HANDLE hMem = GlobalAlloc(GMEM_MOVEABLE, str.GetLength() + 1);
  191. char *p = (char *) GlobalLock(hMem);
  192. if (p) {
  193. lstrcpy(p, str);
  194. GlobalUnlock(hMem);
  195. SetClipboardData(CF_TEXT, hMem);
  196. }
  197. CloseClipboard();
  198. }
  199. }
  200. void CMsgView::OnUpdateViewFont(CCmdUI* pCmdUI) 
  201. {
  202. CMenu *menu = pCmdUI->m_pMenu;
  203. if (menu && GetParentFrame()->GetActiveView() == this) {
  204. CString str;
  205. str.LoadString(IDS_VIEW_FONT);
  206. menu->ModifyMenu(pCmdUI->m_nID, 0, pCmdUI->m_nID, str);
  207. }
  208. }