ViewMsgDlg.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. // ViewMsgDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "ViewMsgDlg.h"
  16. #include "ViewDetailDlg.h"
  17. #include "SendMsgDlg.h"
  18. #include "myicqDlg.h"
  19. #include "icqdb.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CViewMsgDlg dialog
  27. CViewMsgDlg::CViewMsgDlg(IcqContact *contact, CWnd* pParent /*=NULL*/)
  28. :CMyDlg(CViewMsgDlg::IDD, pParent), IcqWindow(WIN_VIEW_MESSAGE, contact->uin)
  29. {
  30. //{{AFX_DATA_INIT(CViewMsgDlg)
  31. // NOTE: the ClassWizard will add member initialization here
  32. //}}AFX_DATA_INIT
  33. this->contact = contact;
  34. expanded = FALSE;
  35. }
  36. CSendMsgDlg *CViewMsgDlg::createSendMsgDlg()
  37. {
  38. CSendMsgDlg *pDlg;
  39. IcqWindow *win = icqLink->findWindow(WIN_SEND_MESSAGE, uin);
  40. if (!win) {
  41. pDlg = new CSendMsgDlg(contact);
  42. pDlg->Create(IDD_SEND_MESSAGE);
  43. CRect rc;
  44. GetWindowRect(rc);
  45. pDlg->SetWindowPos(NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  46. } else {
  47. pDlg = (CSendMsgDlg *) win;
  48. pDlg->ShowWindow(SW_NORMAL);
  49. pDlg->BringWindowToTop();
  50. }
  51. return pDlg;
  52. }
  53. void CViewMsgDlg::expand()
  54. {
  55. SetWindowPos(NULL, 0, 0, wholeSize.cx, wholeSize.cy, SWP_NOZORDER | SWP_NOMOVE);
  56. expanded = TRUE;
  57. }
  58. void CViewMsgDlg::shrink()
  59. {
  60. CRect rc;
  61. GetDlgItem(IDC_LOWER)->GetWindowRect(rc);
  62. SetWindowPos(NULL, 0, 0, wholeSize.cx, wholeSize.cy - rc.Height(),
  63. SWP_NOZORDER | SWP_NOMOVE);
  64. expanded = FALSE;
  65. }
  66. void CViewMsgDlg::onRecvMessage()
  67. {
  68. GetDlgItem(IDC_NEXT_MSG)->EnableWindow();
  69. }
  70. void CViewMsgDlg::DoDataExchange(CDataExchange* pDX)
  71. {
  72. CMyDlg::DoDataExchange(pDX);
  73. //{{AFX_DATA_MAP(CViewMsgDlg)
  74. DDX_Control(pDX, IDC_MSG_HISTORY, m_lstHistory);
  75. DDX_Control(pDX, IDC_PIC, m_btnPic);
  76. //}}AFX_DATA_MAP
  77. }
  78. BEGIN_MESSAGE_MAP(CViewMsgDlg, CMyDlg)
  79. //{{AFX_MSG_MAP(CViewMsgDlg)
  80. ON_BN_CLICKED(IDC_NEXT_MSG, OnNextMsg)
  81. ON_BN_CLICKED(IDC_MENU_QUICK_REPLY, OnMenuQuickReply)
  82. ON_BN_CLICKED(IDC_QUICK_REPLY, OnQuickReply)
  83. ON_BN_CLICKED(IDC_PIC, OnPic)
  84. ON_BN_CLICKED(IDC_HISTORY, OnHistory)
  85. //}}AFX_MSG_MAP
  86. END_MESSAGE_MAP()
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CViewMsgDlg message handlers
  89. BOOL CViewMsgDlg::OnInitDialog() 
  90. {
  91. CMyDlg::OnInitDialog();
  92. int x = contact->winX;
  93. int y = contact->winY;
  94. if (x != -1 || y != -1)
  95. SetWindowPos(NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  96. CRect rc;
  97. GetWindowRect(rc);
  98. wholeSize = rc.Size();
  99. shrink();
  100. SetDlgItemText(IDC_NICK, contact->nick.c_str());
  101. SetDlgItemInt(IDC_UIN, contact->uin, FALSE);
  102. SetDlgItemText(IDC_EMAIL, contact->email.c_str());
  103. m_btnPic.SetIcon(getApp()->largeImageList.ExtractIcon(contact->face));
  104. in_addr addr;
  105. addr.s_addr = htonl(contact->ip);
  106. SetDlgItemText(IDC_ADDR, inet_ntoa(addr));
  107. SetDlgItemInt(IDC_PORT, contact->port, FALSE);
  108. OnNextMsg();
  109. return TRUE;  // return TRUE unless you set the focus to a control
  110.               // EXCEPTION: OCX Property Pages should return FALSE
  111. }
  112. void CViewMsgDlg::OnNextMsg() 
  113. {
  114. IcqMsg *msg = ((CIcqDlg *) AfxGetMainWnd())->fetchMsg(uin);
  115. if (msg->type == MSG_TCP_REQUEST) {
  116. /* CSendFileDlg *win = new CSendFileDlg(msg);
  117. win->Create(IDD_SEND_FILE);*/
  118. } else {
  119. CTime t(msg->when);
  120. SetDlgItemText(IDC_DATE, t.Format("%Y/%m/%d"));
  121. SetDlgItemText(IDC_TIME, t.Format("%H:%M:%S"));
  122. SetDlgItemText(IDC_MSG, msg->text.c_str());
  123. }
  124. delete msg;
  125. GetDlgItem(IDC_NEXT_MSG)->EnableWindow(icqLink->findPendingMsg(uin) != NULL);
  126. }
  127. void CViewMsgDlg::OnCancel() 
  128. {
  129. CRect rc;
  130. GetWindowRect(rc);
  131. contact->winX = rc.left;
  132. contact->winY = rc.top;
  133. DestroyWindow();
  134. }
  135. void CViewMsgDlg::PostNcDestroy() 
  136. {
  137. delete this;
  138. }
  139. void CViewMsgDlg::OnOK() 
  140. {
  141. createSendMsgDlg();
  142. DestroyWindow();
  143. }
  144. void CViewMsgDlg::OnMenuQuickReply() 
  145. {
  146. #define IDM_QUICK_REPLY 1000
  147. CMenu menu;
  148. menu.CreatePopupMenu();
  149. IcqOption &options = icqLink->options;
  150. StrList l;
  151. IcqDB::loadQuickReply(l);
  152. StrList::iterator it;
  153. UINT id = IDM_QUICK_REPLY;
  154. CString str;
  155. for (it = l.begin(); it != l.end(); ++it) {
  156. CString str = (*it).c_str();
  157. if (str.GetLength() > 20)
  158. str = str.Left(20) + "...";
  159. menu.AppendMenu(
  160. str == options.quickReplyText.c_str() ? MF_CHECKED : MF_UNCHECKED,
  161. id++, str);
  162. }
  163. str.LoadString(IDS_QUICK_REPLY_SETTING);
  164. menu.AppendMenu(MF_STRING, id++, str);
  165. CRect rc;
  166. GetDlgItem(IDC_MENU_QUICK_REPLY)->GetWindowRect(rc);
  167. id = menu.TrackPopupMenu(TPM_RETURNCMD, rc.left, rc.bottom, this);
  168. if (id == 0)
  169. return;
  170. id -= IDM_QUICK_REPLY;
  171. if (id == menu.GetMenuItemCount() - 1)
  172. ((CIcqDlg *) AfxGetMainWnd())->showOptions(1);
  173. else {
  174. int i = 0;
  175. for (it = l.begin(); it != l.end() && i < id; ++it, ++i)
  176. ;
  177. if (it != l.end()) {
  178. options.quickReplyText = *it;
  179. IcqDB::saveOptions(options);
  180. OnQuickReply();
  181. }
  182. }
  183. }
  184. void CViewMsgDlg::OnQuickReply() 
  185. {
  186. string &str = icqLink->options.quickReplyText;
  187. if (!str.empty()) {
  188. CSendMsgDlg *win = createSendMsgDlg();
  189. win->sendMessage(str.c_str());
  190. DestroyWindow();
  191. }
  192. }
  193. void CViewMsgDlg::OnPic() 
  194. {
  195. CViewDetailDlg *win = new CViewDetailDlg(uin);
  196. win->Create(this);
  197. }
  198. void CViewMsgDlg::OnHistory() 
  199. {
  200. if (!expanded) {
  201. expand();
  202. m_lstHistory.loadHistory(uin);
  203. } else {
  204. shrink();
  205. m_lstHistory.ResetContent();
  206. }
  207. }