📄 conversation.cpp
字号:
// Conversation.cpp : implementation file
//
#include "stdafx.h"
#include "Netmsg.h"
#include "Conversation.h"
#include "Contact.h"
#include "ContactView.h"
#include "FileSend.h"
#include "ConvEdit.h"
#include "ResolverThread.h"
#include <direct.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//The conversation dialog
#define CHECK_WND(x) if (!::IsWindow(x.m_hWnd)) return;
#define CHECK_WND_P(x) if (!::IsWindow(x->m_hWnd)) return;
#define CHECK_WND_P0(x) if (!::IsWindow(x->m_hWnd)) return 0;
#define CHECK_WND0(x) if (!::IsWindow(x.m_hWnd)) return 0;
CConversation::CConversation(CWnd* pParent, CContact *With, char *DefaultMsg)
: CDialog(CConversation::IDD, pParent)
{
pszDefaultMessage = DefaultMsg;
Contact = With;
BrushWhite.CreateSolidBrush(RGB(255, 255, 255));
BrushNormal.CreateSolidBrush(GetColor(COL_LINEFRAMES));
BrushLight.CreateSolidBrush(GetColor(COL_LIGHTITEMS));
BrushDisabled.CreateSolidBrush(GetColor(COL_DISABLED));
FontBold.CreateFont(13, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, "Tahoma");
FontNormal.CreateFont(13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Tahoma");
m_iSendFile = AfxGetApp()->LoadIcon(IDI_SENDFILE);
m_iSendFileD = AfxGetApp()->LoadIcon(IDI_SENDFILED);
m_iBlock = AfxGetApp()->LoadIcon(IDI_BLOCK);
m_iUnblock = AfxGetApp()->LoadIcon(IDI_UNBLOCK);
HasMessage = false;
Enabled = true;
IsTransfering = false;
//{{AFX_DATA_INIT(CConversation)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
memset(&ufFontNormal, 0, sizeof(USERFONT));
ufFontNormal.lfFont.lfHeight = 16;
ufFontNormal.lfFont.lfWeight = FW_NORMAL;
ufFontNormal.lfFont.lfQuality = 1;
strcpy(ufFontNormal.lfFont.lfFaceName, "MS Sans Serif");
ufFontNormal.nPointSize = 100;
ufFontNormal.crColor = RGB(0, 0, 0);
m_SplitterPos = 0;
m_hIcon = AfxGetApp()->LoadIcon(IDR_CONVERSATION);
}
CConversation::~CConversation()
{
::FreeResource(m_iSendFile);
::FreeResource(m_iSendFileD);
::FreeResource(m_iBlock);
::FreeResource(m_iUnblock);
::FreeResource(m_hIcon);
}
void CConversation::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConversation)
DDX_Control(pDX, IDC_CANCEL, m_Cancel);
DDX_Control(pDX, IDC_SENDFILE, m_SendFile);
DDX_Control(pDX, IDC_BLOCK, m_Block);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConversation, CDialog)
//{{AFX_MSG_MAP(CConversation)
ON_WM_SIZE()
ON_WM_TIMER()
ON_EN_CHANGE(IDC_SENDMSG, OnChangeSendmsg)
ON_COMMAND(ID_IDRCONVERSATIONMENU_BLOCK, OnIdrconversationmenuBlock)
ON_COMMAND(ID_IDRCONVERSATIONMENU_SENDFILE, OnIdrconversationmenuSendfile)
ON_WM_CTLCOLOR()
ON_COMMAND(ID_IDRCONVERSATIONMENU_CHANGEFONT, OnIdrconversationmenuChangefont)
ON_WM_GETMINMAXINFO()
ON_WM_CLOSE()
ON_WM_PAINT()
ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
ON_BN_CLICKED(IDC_BLOCK, OnBlock)
ON_BN_CLICKED(IDC_SENDFILE, OnSendfile)
ON_BN_CLICKED(IDC_CANCEL, OnTransferCancel)
ON_COMMAND(ID_ACTIONS_CHOOSEADVANCEDCOLOR, OnActionsChooseadvancedcolor)
ON_BN_CLICKED(IDC_SENDBUTTON, OnSend)
ON_MESSAGE(WM_RECEIVEDMESSAGE, ReceivedMessage)
ON_MESSAGE(WM_TYPENOTIFY, OnTypeNotify)
ON_COMMAND(ID_HELP_EMOTICONSHELP, OnHelpEmoticonshelp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConversation message handlers
void CConversation::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
UpdateSizes();
RedrawEssential();
}
static UINT auIDStatusBar[] = {
ID_SEPARATOR
};
BOOL CConversation::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow(GetDesktopWindow());
CRect rcClientRect;
CRect rcEmptyRect;
GetClientRect(rcClientRect);
rcEmptyRect.SetRectEmpty();
m_bgWnd.Create(NULL, NULL, WS_VISIBLE | WS_CHILD, rcEmptyRect, this, 10021);
m_Chat.CreateEx((OSVER & WIN_WINNT && GetApp()->View->bmConvBack)
? WS_EX_TRANSPARENT : 0, NULL, NULL, WS_VISIBLE | WS_CHILD |
WS_CLIPCHILDREN | WS_VSCROLL | ES_MULTILINE | ES_READONLY |
ES_AUTOVSCROLL | ES_LEFT | ES_WANTRETURN, rcEmptyRect, &m_bgWnd, IDC_CHAT, NULL, this);
m_bgWnd.m_Chat = &m_Chat;
m_SendMsg.Create(NULL, NULL, WS_VISIBLE | WS_CHILD |
WS_CLIPCHILDREN | WS_VSCROLL | ES_MULTILINE | WS_TABSTOP |
ES_AUTOVSCROLL | ES_LEFT | ES_WANTRETURN, rcEmptyRect, this, IDC_SENDMSG, NULL, this);
m_Chat.AutoURLDetect(true);
m_Chat.SetEventMask(m_Chat.GetEventMask() | ENM_LINK);
m_SendMsg.LimitText(500);
if (m_statusBar.Create(this))
{
m_statusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar) / sizeof(unsigned int));
m_statusBar.SetPaneInfo(0, m_statusBar.GetItemID(0),
SBPS_STRETCH, NULL );
}
CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
0, reposQuery, rcClientNow);
CPoint ptOffset(rcClientNow.left - rcClientStart.left,
rcClientNow.top - rcClientStart.top);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
{
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
pwndChild = pwndChild->GetNextWindow();
}
Font.CreateFontIndirect(&GetApp()->View->Me.uFont.lfFont);
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_Chat.AppendWindowTextF(&ufFontNormal, 0,
AfxGetApp()->GetProfileString("Settings", "SecurityWarning",
"(M) Netmsg 1.2.2.0$CRLF $UL$CRLF"));
CString cstr;
if (pszDefaultMessage)
{
ReceivedMessage(0, (LPARAM)pszDefaultMessage);
}
cstr.Format("Conversation: %s", Contact->GetScreenName());
SetWindowText(cstr);
// position controls //
m_SendButton.SubclassDlgItem(IDC_SENDBUTTON, this);
m_SendButton.SetTextAlignment(CMSNButton::AlignCenter);
m_SendButton.SetFont(&FontNormal);
m_SendButton.EnableWindow(FALSE);
m_SendButton.SetCornerColor(RGB(255, 255, 255));
m_Message.Create("", WS_CHILD, rcEmptyRect, this);
m_Message.SetColors(GetColor(COL_NORMALTEXT), GetColor(COL_LIGHTITEMS));
m_Message.SetFont(&FontNormal);
m_To.Create("", WS_CHILD | SS_ENDELLIPSIS, rcEmptyRect, this);
m_To.SetColors(GetColor(COL_NOTIFYTEXT), GetColor(COL_LINEFRAMES));
m_To.ShowWindow(SW_SHOW);
m_To.SetFont(&FontBold);
m_Splitter.Create(NULL, WS_CHILD | SS_NOTIFY, rcEmptyRect, this, IDC_STATIC);
m_Splitter.ShowWindow(SW_SHOW);
// file transfer controls //
m_Progress.Create(WS_CHILD, rcEmptyRect, this, 0xFFFF);
m_Progress.SetGradientColors(RGB(171, 190, 239), RGB(88, 125, 222));
m_Progress.SetBkColor(GetColor(COL_LIGHTITEMS));
m_Progress.SetRubberBar(TRUE);
m_Progress.SetTextFormat("%d%%", PBS_SHOW_PERCENT);
m_Progress.SetFont(&FontNormal);
m_Progress.SetTextColor(GetColor(COL_NORMALTEXT));
m_FileStats.Create(NULL, WS_CHILD, rcEmptyRect, this, IDC_STATIC);
m_TransferStats.Create(NULL, WS_CHILD, rcEmptyRect, this, IDC_STATIC);
m_FileStats.SetColors(GetColor(COL_NORMALTEXT), GetColor(COL_LIGHTITEMS));
m_TransferStats.SetColors(GetColor(COL_NORMALTEXT), GetColor(COL_LIGHTITEMS));
m_TransferStats.SetFont(&FontNormal);
m_FileStats.SetFont(&FontNormal);
////////////////////////////
m_SendMsg.SetFont(&Font);
m_Block.SetTextAlignment(CTrackLookButton::AlignRight);
m_Block.SetIcons(m_iBlock);
m_Block.SetIconSize(24, 24);
m_Block.SetWindowText("Block");
m_SendFile.SetIcons(m_iSendFile, m_iSendFile, m_iSendFileD);
m_SendFile.SetWindowText("Send File");
m_SendFile.SetTextAlignment(CTrackLookButton::AlignRight);
m_SendFile.SetIconSize(24, 24);
m_SendButton.MoveWindow(rcClientRect.right - 60, rcClientRect.bottom - 72, 52, 45);
m_To.MoveWindow(6, 4, rcClientRect.right - 6, 18);
m_Block.MoveWindow(rcClientRect.right - 84, rcClientRect.bottom - 116, 80, 34);
m_SendFile.MoveWindow(rcClientRect.right - 169, rcClientRect.bottom - 116, 85, 34);
strcpy(Host, "Resolving host name...");
char buf[512];
sprintf(buf, "To: %s (%s) Resolving host name...",
Contact->GetTruncatedScreenName(32), Contact->GetHostName().Get());
m_To.SetWindowText(buf);
CResolverThread *Thread = new CResolverThread(Contact->GetHostName(), this);
Thread->CreateThread();
WINDOWPLACEMENT *wpl;
unsigned int sz = sizeof(WINDOWPLACEMENT);
if (AfxGetApp()->GetProfileBinary("Settings", "WindowPosChat", (LPBYTE *)&wpl, &sz))
{
SetWindowPlacement(wpl);
}
delete wpl;
UpdateWindow();
m_Block.Invalidate();
SetSplitterPos(AfxGetApp()->GetProfileInt("Settings", "SplitterPos", 0));
SetTimer(1, 1, 0);
UpdateSizes();
Contact->Flags |= CFL_DLGCREATED;
//NOW we're active :P
return TRUE;
}
void CConversation::OnSend()
{
MESSAGE *Msg = new MESSAGE;
m_SendMsg.GetWindowText(Msg->Message, m_SendMsg.GetWindowTextLength() + 1);
if (!strcmp(Msg->Message, "\r\n"))
{
m_SendMsg.SetWindowText("");
return;
}
if (!stricmp(Msg->Message, ""))
{
m_SendMsg.SetFocus();
return;
}
else
{
char buf[1024];
strcpy(buf, Msg->Message);
Msg->To = Contact;
Msg->CallingDialog = this;
PluginsMessageSent(Msg->To, buf);
ReceivedMessage(1, (LPARAM) nstrdup(buf));
strcpy(Msg->Message, buf);
::SendMessage(GetApp()->View->GetSafeHwnd(), WM_SENDTHISMESSAGE, 0, (LPARAM) Msg);
}
m_SendMsg.SetFocus();
m_SendMsg.SetWindowText("");
OnChangeSendmsg();
}
void CConversation::OnTimer(UINT nIDEvent)
{
switch (nIDEvent)
{
case 1:
m_SendMsg.SetFocus();
KillTimer(1);
break;
case 2:
m_Chat.SetFocus();
KillTimer(2);
break;
case 3:
RedrawWindow();
KillTimer(3);
break;
}
CDialog::OnTimer(nIDEvent);
}
void CConversation::OnChangeSendmsg()
{
static bool Sent = true;
char buf[512];
m_SendMsg.GetWindowText(buf, sizeof(buf));
if (!stricmp(buf, ""))
{
RECT rect;
GetClientRect(&rect);
rect.top = rect.bottom - 90;
rect.right = 20;
rect.bottom = rect.top + 40;
RedrawWindow(&rect);
m_SendButton.EnableWindow(FALSE);
}
else
{
m_SendButton.EnableWindow(TRUE);
}
if (!Sent && !stricmp(buf, ""))
{
if (Contact->IsOffline()) return;
Sent = true;
::SendMessage(GetApp()->View->GetSafeHwnd(), WM_TYPENOTIFY, 0, (LPARAM) Contact);
}
else if (Sent && stricmp(buf, ""))
{
if (Contact->IsOffline()) return;
Sent = false;
::SendMessage(GetApp()->View->GetSafeHwnd(), WM_TYPENOTIFY, 1, (LPARAM) Contact);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -