📄 ircwnd.cpp
字号:
if(nickItem != -1) {
Nick* nick = (Nick*)nickList.GetItemData(nickItem);
if(nick)
AddInfoMessage( nick->nick, GetResString(IDS_IRC_PRIVATECHANSTART));
}
*pResult = 0;
}
void CIrcWnd::OnNMClickNicklist(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
// Messages
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void CIrcWnd::AddStatus( CString line,...){
va_list argptr;
va_start(argptr, line);
CString temp;
temp.FormatV(line, argptr);
va_end(argptr);
char osTime[30];
_strtime( osTime );
CString timestamp = "";
if( theApp.glob_prefs->GetIRCAddTimestamp() )
timestamp.Format("%s: ",osTime);
Channel* update_channel = (Channel*)channelPtrList.GetHead();
if( !update_channel ){
return;
}
line = StripMessageOfFontCodes( temp );
line += "\r\n";
line.Replace( "\004", "%" );
if (line.Mid(0,1) == "*"){
update_channel->log.AppendText(timestamp);
update_channel->log.AppendKeyWord(line.Left(2),RGB(255,0,0));
update_channel->log.AppendText(line.Mid(1) );
}
else if (line.Mid(0,1) == "-"){
int index = line.Find( "-", 1 );
update_channel->log.AppendText(timestamp);
update_channel->log.AppendKeyWord(line.Left(index),RGB(150,0,0));
update_channel->log.AppendText(line.Mid(index) );
}
else
update_channel->log.AppendText(timestamp + line);
if( m_pCurrentChannel == update_channel ){
statusWindow.SetHyperText(&update_channel->log,true);
return;
}
SetActivity( update_channel->name, true );
}
void CIrcWnd::AddInfoMessage( CString channelName, CString line,...){
if(channelName.IsEmpty())
return;
va_list argptr;
va_start(argptr, line);
CString temp;
temp.FormatV(line, argptr);
va_end(argptr);
char osTime[30];
_strtime( osTime );
CString timestamp = "";
if( theApp.glob_prefs->GetIRCAddTimestamp() )
timestamp.Format("%s: ",osTime);
Channel* update_channel = FindChannelByName(channelName);
if( !update_channel ){
if( channelName.Left(1) == "#" )
update_channel = NewChannel( channelName, 4);
else
update_channel = NewChannel( channelName, 5);
}
line = StripMessageOfFontCodes( temp );
line += "\r\n";
line.Replace( "\004", "%" );
if (line.Mid(0,1) == "*"){
update_channel->log.AppendText(timestamp);
update_channel->log.AppendKeyWord(line.Left(2),RGB(255,0,0));
update_channel->log.AppendText(line.Mid(1) );
}
else if (line.Mid(0,1) == "-"){
int index = line.Find( "-", 1 );
update_channel->log.AppendText(timestamp);
update_channel->log.AppendKeyWord(line.Left(index),RGB(150,0,0));
update_channel->log.AppendText(line.Mid(index) );
}
else
update_channel->log.AppendText(timestamp + line);
if( m_pCurrentChannel == update_channel ){
statusWindow.SetHyperText(&update_channel->log,true);
return;
}
SetActivity( update_channel->name, true );
}
void CIrcWnd::AddMessage( CString channelName, CString targetname, CString line,...){
if(channelName.IsEmpty() || targetname.IsEmpty())
return;
va_list argptr;
va_start(argptr, line);
CString temp;
temp.FormatV(line, argptr);
line = temp;
va_end(argptr);
char osTime[30];
_strtime( osTime );
CString timestamp = "";
if( theApp.glob_prefs->GetIRCAddTimestamp() )
timestamp.Format("%s: ",osTime);
Channel* update_channel = FindChannelByName(channelName);
if( !update_channel ){
if( channelName.Left(1) == "#" )
update_channel = NewChannel( channelName, 4);
else
update_channel = NewChannel( channelName, 5);
}
line = StripMessageOfFontCodes( line );
line += "\r\n";
line.Replace( "\004", "%" );
COLORREF color;
if (m_pIrcMain->GetNick() == targetname)
color = RGB(1,100,1);
else
color = RGB(1,20,130);
targetname = CString("<")+ targetname + CString(">");
update_channel->log.AppendText(timestamp);
update_channel->log.AppendKeyWord(targetname, color);
update_channel->log.AppendText(CString(" ")+line);
if( m_pCurrentChannel == update_channel ){
statusWindow.SetHyperText(&update_channel->log,true);
return;
}
SetActivity( update_channel->name, true );
}
void CIrcWnd::SetConnectStatus( bool flag ){
if(flag){
GetDlgItem(IDC_BN_IRCCONNECT)->SetWindowText(GetResString(IDS_IRC_DISCONNECT));
AddStatus( GetResString(IDS_CONNECTED));
m_bConnected = true;
}
else{
GetDlgItem(IDC_BN_IRCCONNECT)->SetWindowText(GetResString(IDS_IRC_CONNECT));
AddStatus( GetResString(IDS_DISCONNECTED));
m_bConnected = false;
m_bLoggedIn = false;
while( channelPtrList.GetCount() > 2 ){
Channel* todel = (Channel*)channelPtrList.GetTail();
RemoveChannel( todel->name );
}
}
}
void CIrcWnd::NoticeMessage( CString source, CString message ){
bool flag = false;
Channel* curr_channel = FindChannelByName( source );
if( curr_channel ){
AddInfoMessage( source, "-%s- %s", source, message);
flag = true;
}
POSITION pos1, pos2;
for (pos1 = channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;){
channelPtrList.GetNext(pos1);
curr_channel = (Channel*)channelPtrList.GetAt(pos2);
Nick* curr_nick = FindNickByName(curr_channel->name, source );
if( curr_nick){
AddInfoMessage( curr_channel->name, "-%s- %s", source, message);
flag = true;
}
}
if( flag == false ){
if( m_pCurrentChannel->type == 4 )
AddInfoMessage( m_pCurrentChannel->name, "-%s- %s", source, message);
else
AddStatus( "-%s- %s", source, message );
}
}
//We cannot support color within the text since HyperTextCtrl does not detect hyperlinks with color. So I will filter it.
CString CIrcWnd::StripMessageOfFontCodes( CString temp ){
temp = StripMessageOfColorCodes( temp );
CString temp1, temp2;
for( int i = 0; i < temp.GetLength(); i++ ){
int j = temp[i];
switch( j ){
case 2:
case 3:
case 15:
case 22:
case 31:{
temp1 = temp.Left( i );
temp2 = temp.Mid( i+1 );
temp = temp1+temp2;
i--;
}
}
}
return temp;
}
CString CIrcWnd::StripMessageOfColorCodes( CString temp ){
if( !temp.IsEmpty() )
{
CString temp1, temp2;
int test = temp.Find( 3 );
if( test != -1 ){
int testlength = temp.GetLength() - test;
if( testlength < 2 )
return temp;
temp1 = temp.Left( test );
temp2 = temp.Mid( test + 2);
if( testlength < 4 )
return temp1+temp2;
if( temp2[0] == 44 && temp2.GetLength() > 2){
temp2 = temp2.Mid(2);
for( int I = 48; I < 58; I++ ){
if( temp2[0] == I ){
temp2 = temp2.Mid(1);
}
}
}
else{
for( int I = 48; I < 58; I++ ){
if( temp2[0] == I ){
temp2 = temp2.Mid(1);
if( temp2[0] == 44 && temp2.GetLength() > 2){
temp2 = temp2.Mid(2);
for( int I = 48; I < 58; I++ ){
if( temp2[0] == I ){
temp2 = temp2.Mid(1);
}
}
}
}
}
}
temp = temp1 + temp2;
temp = StripMessageOfColorCodes(temp);
}
}
return temp;
}
void CIrcWnd::SetTitle( CString channel, CString title ){
Channel* curr_channel = FindChannelByName(channel);
if(!curr_channel)
return;
curr_channel->title = StripMessageOfFontCodes(title);
if( curr_channel == m_pCurrentChannel )
titleWindow.SetWindowText( curr_channel->title );
}
void CIrcWnd::SetActivity( CString channel, bool flag){
Channel* refresh = FindChannelByName( channel );
if( !refresh ){
refresh = (Channel*)channelPtrList.GetHead();
if( !refresh )
return;
}
TCITEM item;
item.mask = TCIF_PARAM;
int i;
for (i = 0; i != channelselect.GetItemCount();i++){
channelselect.GetItem(i,&item);
if (((Channel*)item.lParam) == refresh)
break;
}
if (((Channel*)item.lParam) != refresh)
return;
if( flag ){
item.mask = TCIF_IMAGE;
item.iImage = 2;
channelselect.SetItem( i, &item );
}
else{
item.mask = TCIF_IMAGE;
item.iImage = 1;
channelselect.SetItem( i, &item );
}
}
void CIrcWnd::OnBnClickedChatsend()
{
CString send;
GetDlgItem(IDC_INPUTWINDOW)->GetWindowText(send);
GetDlgItem(IDC_INPUTWINDOW)->SetWindowText("");
if( send.IsEmpty() )
return;
if( !this->m_bConnected )
return;
if( send.Left(1) == "/" && send.Left(3) != "/me"){
if (send.Left(4) == "/msg"){
if( m_pCurrentChannel->type == 4 || m_pCurrentChannel->type == 5){
send.Replace( "%", "\004" );
AddInfoMessage( m_pCurrentChannel->name ,CString("* >> ")+send.Mid(5));
send.Replace( "\004", "%" );
}
else{
send.Replace( "%", "\004" );
AddStatus( CString("* >> ")+send.Mid(5));
send.Replace( "\004", "%" );
}
send = CString("/PRIVMSG") + send.Mid(4);
}
if( ((CString)send.Left(17)).CompareNoCase( "/PRIVMSG nickserv" )== 0){
send = CString("/ns") + send.Mid(17);
}
if( ((CString)send.Left(17)).CompareNoCase( "/PRIVMSG chanserv" )== 0){
send = CString("/cs") + send.Mid(17);
}
m_pIrcMain->SendString(send.Mid(1));
return;
}
if( m_pCurrentChannel->type < 4 ){
m_pIrcMain->SendString(send);
return;
}
if( send.Left(3) == "/me" ){
CString build;
build.Format( "PRIVMSG %s :\001ACTION %s\001", m_pCurrentChannel->name, send.Mid(4) );
send.Replace( "%", "\004" );
AddInfoMessage( m_pCurrentChannel->name, "* %s %s", m_pIrcMain->GetNick(), send.Mid(4));
send.Replace( "\004", "%" );
m_pIrcMain->SendString(build);
return;
}
CString build = "PRIVMSG " + m_pCurrentChannel->name + " :" + send;
m_pIrcMain->SendString(build);
send.Replace( "%", "\004" );
AddMessage( m_pCurrentChannel->name, m_pIrcMain->GetNick(), send );
send.Replace( "\004", "%" );
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
// Channels
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
Channel* CIrcWnd::FindChannelByName(CString name){
POSITION pos1, pos2;
for (pos1 = channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;){
channelPtrList.GetNext(pos1);
Channel* cur_channel = (Channel*)channelPtrList.GetAt(pos2);
if (cur_channel->name.CompareNoCase(name.Trim()) == 0 && (cur_channel->type == 4 || cur_channel->type == 5))
return cur_channel;
}
return 0;
}
Channel* CIrcWnd::NewChannel( CString name, uint8 type ){
Channel* toadd = new Channel;
toadd->name = name;
toadd->title = name;
toadd->type = type;
channelPtrList.AddTail(toadd);
TCITEM newitem;
newitem.mask = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE;
newitem.lParam = (LPARAM)toadd;
newitem.pszText = name.GetBuffer();
newitem.cchTextMax = (int)name.GetLength()+1;
newitem.iImage = 1;
channelselect.InsertItem(channelselect.GetItemCount(),&newitem);
return toadd;
}
void CIrcWnd::RemoveChannel( CString channel ){
Channel* todel = FindChannelByName( channel );
if( !todel )
return;
TCITEM item;
item.mask = TCIF_PARAM;
int i;
for (i = 0; i != channelselect.GetItemCount();i++){
channelselect.GetItem(i,&item);
if (((Channel*)item.lParam) == todel)
break;
}
if (((Channel*)item.lParam) != todel)
return;
channelselect.DeleteItem(i);
if( todel == m_pCurrentChannel ){
nickList.DeleteAllItems();
statusWindow.SetWindowText("");
if( channelselect.GetItemCount() > 2 && i > 1 ) {
if ( i == 2 )
i++;
channelselect.SetCurSel(i-1);
channelselect.SetCurFocus(i-1);
OnTcnSelchangeTab2( NULL, NULL );
}
else {
channelselect.SetCurSel(0);
channelselect.SetCurFocus(0);
OnTcnSelchangeTab2( NULL, NULL );
}
}
DeleteAllNick(todel->name);
channelPtrList.RemoveAt(channelPtrList.Find(todel));
delete todel;
}
void CIrcWnd::DeleteAllChannel(){
POSITION pos1, pos2;
for (pos1 = channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;){
channelPtrList.GetNext(pos1);
Channel* cur_channel = (Channel*)channelPtrList.GetAt(pos2);
DeleteAllNick(cur_channel->name);
channelPtrList.RemoveAt(pos2);
delete cur_channel;
}
}
void CIrcWnd::JoinChannels(){
int index = -1;
POSITION pos = serverChannelList.GetFirstSelectedItemPosition();
while(pos != NULL)
{
index = serverChannelList.GetNextSelectedItem(pos);
if(index > -1){
CString join;
join = "JOIN " + serverChannelList.GetItemText(index, 0 );
m_pIrcMain->SendString( join );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -