📄 ircchanneltabctrl.cpp
字号:
CRect rcItem;
GetItemRect(i, rcItem);
CRect rcCloseButton;
GetCloseButtonRect(rcItem, rcCloseButton);
rcCloseButton.top -= 2;
rcCloseButton.left -= 4;
rcCloseButton.right += 2;
rcCloseButton.bottom += 4;
if (rcCloseButton.PtInRect(point))
{
m_pParent->OnBnClickedClosechat( i );
return;
}
}
}
CTabCtrl::OnLButtonDown(nFlags, point);
}
void CIrcChannelTabCtrl::OnTcnSelchangeTab2(NMHDR *pNMHDR, LRESULT *pResult)
{
TCITEM item;
item.mask = TCIF_PARAM;
//What channel did we select?
int cur_sel = GetCurSel();
if (cur_sel == -1)
{
//No channel, abort..
return;
}
if (!GetItem(cur_sel, &item))
{
//We had no valid item here.. Something isn't right..
//TODO: this should never happen, so maybe we should remove this tab?
return;
}
Channel* update = (Channel*)item.lParam;
//Set our current channel to the new one for quick reference..
m_pCurrentChannel = update;
if (m_pCurrentChannel->type == 1)
m_pParent->titleWindow.SetWindowText(GetResString(IDS_STATUS));
if (m_pCurrentChannel->type == 2)
{
//Since some channels can have a LOT of nicks, hide the window then remove them to speed it up..
m_pParent->m_nicklist.ShowWindow(SW_HIDE);
m_pParent->m_nicklist.DeleteAllItems();
m_pParent->m_nicklist.UpdateNickCount();
m_pParent->m_nicklist.ShowWindow(SW_SHOW);
//Set title to ChanList
m_pParent->titleWindow.SetWindowText(GetResString(IDS_IRC_CHANNELLIST));
//Show our ChanList..
m_pParent->m_serverChannelList.ShowWindow(SW_SHOW);
TCITEM tci;
tci.mask = TCIF_PARAM;
//Go through the channel tabs and hide the channels..
//Maybe overkill? Maybe just remember our previous channel and hide it?
int i = 0;
while (GetItem(i++, &tci))
{
Channel* ch2 = (Channel*)tci.lParam;
if (ch2 != m_pCurrentChannel && ch2->log.m_hWnd != NULL)
ch2->log.ShowWindow(SW_HIDE);
}
return;
}
//We entered the channel, set activity flag off.
SetActivity( m_pCurrentChannel->name, false );
CRect rcChannel;
m_pParent->m_serverChannelList.GetWindowRect(&rcChannel);
m_pParent->ScreenToClient(&rcChannel);
//Show new current channel..
m_pCurrentChannel->log.SetWindowPos(NULL, rcChannel.left, rcChannel.top, rcChannel.Width(), rcChannel.Height(), SWP_NOZORDER);
m_pCurrentChannel->log.ShowWindow(SW_SHOW);
TCITEM tci;
tci.mask = TCIF_PARAM;
//Hide all channels not in focus..
//Maybe overkill? Maybe remember previous channel and hide?
int i = 0;
while (GetItem(i++, &tci))
{
Channel* ch2 = (Channel*)tci.lParam;
if (ch2 != m_pCurrentChannel && ch2->log.m_hWnd != NULL)
ch2->log.ShowWindow(SW_HIDE);
}
//Make sure channelList is hidden.
m_pParent->m_serverChannelList.ShowWindow(SW_HIDE);
//Update nicklist to the new channel..
m_pParent->m_nicklist.RefreshNickList( update->name );
//Set title to the new channel..
m_pParent->SetTitle( update->name, update->title );
//Push focus back to the input box..
m_pParent->GetDlgItem(IDC_INPUTWINDOW)->SetFocus();
if( pResult )
*pResult = 0;
}
void CIrcChannelTabCtrl::ScrollHistory(bool down)
{
CString buffer;
if ( (m_pCurrentChannel->history_pos==0 && !down) || (m_pCurrentChannel->history_pos==m_pCurrentChannel->history.GetCount() && down))
return;
if (down)
++m_pCurrentChannel->history_pos;
else
--m_pCurrentChannel->history_pos;
buffer= (m_pCurrentChannel->history_pos==m_pCurrentChannel->history.GetCount()) ? _T("") : m_pCurrentChannel->history.GetAt(m_pCurrentChannel->history_pos);
m_pParent->GetDlgItem(IDC_INPUTWINDOW)->SetWindowText(buffer);
m_pParent->inputWindow.SetSel(buffer.GetLength(),buffer.GetLength());
}
void CIrcChannelTabCtrl::SetActivity( CString channel, bool flag)
{
Channel* refresh = FindChannelByName( channel );
if( !refresh )
{
refresh = (Channel*)channelPtrList.GetHead();
if( !refresh )
return;
}
TCITEM item;
item.mask = TCIF_PARAM;
item.lParam = -1;
int i;
for (i = 0; i < GetItemCount();i++)
{
GetItem(i,&item);
if (((Channel*)item.lParam) == refresh)
break;
}
if (((Channel*)item.lParam) != refresh)
return;
if( flag )
{
item.mask = TCIF_IMAGE;
item.iImage = 2; // 'MessagePending'
SetItem( i, &item );
HighlightItem(i, TRUE);
}
else
{
item.mask = TCIF_IMAGE;
item.iImage = 1; // 'Message'
SetItem( i, &item );
HighlightItem(i, FALSE);
}
}
void CIrcChannelTabCtrl::Chatsend( CString send )
{
if (m_pCurrentChannel->history.GetCount()==thePrefs.GetMaxChatHistoryLines())
m_pCurrentChannel->history.RemoveAt(0);
m_pCurrentChannel->history.Add(send);
m_pCurrentChannel->history_pos=m_pCurrentChannel->history.GetCount();
if( send.IsEmpty() )
return;
if( !m_pParent->IsConnected() )
return;
if( send.Left(4) == _T("/hop") )
{
if( m_pCurrentChannel->name.Left(1) == _T("#") )
{
CString channel = m_pCurrentChannel->name;
m_pParent->m_pIrcMain->SendString( _T("PART ") + channel );
m_pParent->m_pIrcMain->SendString( _T("JOIN ") + channel );
return;
}
return;
}
if( send.Left(1) == _T("/") && send.Left(3).MakeLower() != _T("/me") && send.Left(6).MakeLower() != _T("/sound") )
{
if (send.Left(4) == _T("/msg"))
{
if( m_pCurrentChannel->type == 4 || m_pCurrentChannel->type == 5)
{
send.Replace( _T("%"), _T("\004") );
m_pParent->AddInfoMessage( m_pCurrentChannel->name ,CString(_T("* >> "))+send.Mid(5));
send.Replace( _T("\004"), _T("%") );
}
else
{
send.Replace( _T("%"), _T("\004") );
m_pParent->AddStatus( CString(_T("* >> "))+send.Mid(5));
send.Replace( _T("\004"), _T("%") );
}
send = CString(_T("/PRIVMSG")) + send.Mid(4);
}
if( ((CString)send.Left(17)).CompareNoCase( _T("/PRIVMSG nickserv") )== 0)
{
send = CString(_T("/ns")) + send.Mid(17);
}
else if( ((CString)send.Left(17)).CompareNoCase( _T("/PRIVMSG chanserv") )== 0)
{
send = CString(_T("/cs")) + send.Mid(17);
}
else if( ((CString)send.Left(8)).CompareNoCase( _T("/PRIVMSG") )== 0)
{
int index = send.Find(_T(" "), send.Find(_T(" "))+1);
send.Insert(index+1, _T(":"));
}
else if( ((CString)send.Left(6)).CompareNoCase( _T("/TOPIC") )== 0)
{
int index = send.Find(_T(" "), send.Find(_T(" "))+1);
send.Insert(index+1, _T(":"));
}
m_pParent->m_pIrcMain->SendString(send.Mid(1));
return;
}
if( m_pCurrentChannel->type < 4 )
{
m_pParent->m_pIrcMain->SendString(send);
return;
}
if( send.Left(3) == _T("/me") )
{
CString build;
build.Format( _T("PRIVMSG %s :\001ACTION %s\001"), m_pCurrentChannel->name, send.Mid(4) );
send.Replace( _T("%"), _T("\004") );
m_pParent->AddInfoMessage( m_pCurrentChannel->name, _T("* %s %s"), m_pParent->m_pIrcMain->GetNick(), send.Mid(4));
m_pParent->m_pIrcMain->SendString(build);
return;
}
if( send.Left(6) == _T("/sound") )
{
CString build, sound;
build.Format( _T("PRIVMSG %s :\001SOUND %s\001"), m_pCurrentChannel->name, send.Mid(7) );
m_pParent->m_pIrcMain->SendString(build);
send = send.Mid(7);
int soundlen = send.Find( _T(" ") );
send.Replace( _T("%"), _T("\004") );
if( soundlen != -1 )
{
build = send.Left(soundlen);
build.Replace(_T("\\"),_T(""));
send = send.Left(soundlen);
}
else
{
build = send;
send = _T("[SOUND]");
}
sound.Format(_T("%sSounds\\IRC\\%s"), thePrefs.GetAppDir(), build);
m_pParent->AddInfoMessage( m_pCurrentChannel->name, _T("* %s %s"), m_pParent->m_pIrcMain->GetNick(), send);
PlaySound(sound, NULL, SND_FILENAME | SND_NOSTOP | SND_NOWAIT | SND_ASYNC);
return;
}
CString build = _T("PRIVMSG ") + m_pCurrentChannel->name + _T(" :") + send;
m_pParent->m_pIrcMain->SendString(build);
send.Replace( _T("%"), _T("\004") );
m_pParent->AddMessage( m_pCurrentChannel->name, m_pParent->m_pIrcMain->GetNick(), send );
send.Replace( _T("\004"), _T("%") );
}
void CIrcChannelTabCtrl::Localize()
{
for (int i = 0; i < GetItemCount();i++)
{
TCITEM item;
item.mask = TCIF_PARAM;
item.lParam = -1;
GetItem(i,&item);
Channel* cur_chan = (Channel*)item.lParam;
if (cur_chan != NULL)
{
if( cur_chan->type == 1 )
{
cur_chan->title = GetResString(IDS_STATUS);
item.mask = TCIF_TEXT;
item.pszText = cur_chan->title.GetBuffer();
SetItem(i,&item);
cur_chan->title.ReleaseBuffer();
}
if( cur_chan->type == 2 )
{
cur_chan->title = GetResString(IDS_IRC_CHANNELLIST);
item.mask = TCIF_TEXT;
item.pszText = cur_chan->title.GetBuffer();
SetItem(i,&item);
cur_chan->title.ReleaseBuffer();
}
}
}
if (m_pCurrentChannel)
{
if( m_pCurrentChannel->type == 1 )
m_pParent->titleWindow.SetWindowText(GetResString(IDS_STATUS));
if( m_pCurrentChannel->type == 2 )
m_pParent->titleWindow.SetWindowText(GetResString(IDS_IRC_CHANNELLIST));
}
SetAllIcons();
}
BOOL CIrcChannelTabCtrl::OnCommand(WPARAM wParam,LPARAM lParam )
{
int chanItem = m_pParent->m_channelselect.GetCurSel();
switch( wParam )
{
case Irc_Close:
{
//Pressed the close button
m_pParent->OnBnClickedClosechat();
return true;
}
}
uint32 test = Irc_ChanCommands;
if( wParam >= test && wParam < test+50)
{
int index = wParam - test;
if( index < m_sChannelModeSettingsTypeA.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeA.Mid(index,1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s +%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
if( index < m_sChannelModeSettingsTypeA.GetLength()+m_sChannelModeSettingsTypeB.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeB.Mid(index-m_sChannelModeSettingsTypeA.GetLength(),1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s +%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
if( index < m_sChannelModeSettingsTypeA.GetLength()+m_sChannelModeSettingsTypeB.GetLength()+m_sChannelModeSettingsTypeC.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeC.Mid(index-m_sChannelModeSettingsTypeA.GetLength()-m_sChannelModeSettingsTypeB.GetLength(),1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s +%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
if( index < m_sChannelModeSettingsTypeA.GetLength()+m_sChannelModeSettingsTypeB.GetLength()+m_sChannelModeSettingsTypeC.GetLength()+m_sChannelModeSettingsTypeD.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeD.Mid(index-m_sChannelModeSettingsTypeA.GetLength()-m_sChannelModeSettingsTypeB.GetLength()-m_sChannelModeSettingsTypeC.GetLength(),1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s +%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
return true;
}
if( wParam >= test+50 && wParam < test+100)
{
int index = wParam - test - 50;
if( index < m_sChannelModeSettingsTypeA.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeA.Mid(index,1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s -%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
if( index < m_sChannelModeSettingsTypeA.GetLength()+m_sChannelModeSettingsTypeB.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeB.Mid(index-m_sChannelModeSettingsTypeA.GetLength(),1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s -%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
if( index < m_sChannelModeSettingsTypeA.GetLength()+m_sChannelModeSettingsTypeB.GetLength()+m_sChannelModeSettingsTypeC.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeC.Mid(index-m_sChannelModeSettingsTypeA.GetLength()-m_sChannelModeSettingsTypeB.GetLength(),1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s -%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
if( index < m_sChannelModeSettingsTypeA.GetLength()+m_sChannelModeSettingsTypeB.GetLength()+m_sChannelModeSettingsTypeC.GetLength()+m_sChannelModeSettingsTypeD.GetLength() )
{
CString mode = m_sChannelModeSettingsTypeD.Mid(index-m_sChannelModeSettingsTypeA.GetLength()-m_sChannelModeSettingsTypeB.GetLength()-m_sChannelModeSettingsTypeC.GetLength(),1);
TCITEM item;
item.mask = TCIF_PARAM;
GetItem(chanItem,&item);
Channel* chan = (Channel*)item.lParam;
if( chan )
{
//We have a chan, send the command.
CString send;
send.Format( _T("MODE %s -%s %s"), chan->name, mode );
m_pParent->m_pIrcMain->SendString(send);
}
return true;
}
return true;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -