⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ircwnd.cpp

📁 非常出名开源客户端下载的程序emule
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	ON_NOTIFY(NM_RCLICK, IDC_NICKLIST, OnNMRclickNick)
	ON_NOTIFY(NM_RCLICK, IDC_SERVERCHANNELLIST, OnNMRclickChanL)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB2, OnTcnSelchangeTab2)

	ON_WM_SIZE()
	ON_WM_CREATE()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
// Channel List
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

void CIrcWnd::ResetServerChannelList(){
	POSITION pos1, pos2;
	for (pos1 = channelLPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;){
		channelLPtrList.GetNext(pos1);
		ChannelList* cur_channel =	(ChannelList*)channelLPtrList.GetAt(pos2);
		channelLPtrList.RemoveAt(pos2);
		delete cur_channel;
	}
	serverChannelList.DeleteAllItems();
}

void CIrcWnd::AddChannelToList( CString name, CString user, CString description ){
	CString ntemp = name;
	CString dtemp = description;
	int usertest = atoi(user);
	if( (theApp.glob_prefs->GetIRCChanNameFilter() || theApp.glob_prefs->GetIRCChannelUserFilter()) && theApp.glob_prefs->GetIRCUseChanFilter()){
		if( usertest < theApp.glob_prefs->GetIRCChannelUserFilter() )
			return;
		if( dtemp.MakeLower().Find(theApp.glob_prefs->GetIRCChanNameFilter().MakeLower()) == -1 && ntemp.MakeLower().Find(theApp.glob_prefs->GetIRCChanNameFilter().MakeLower()) == -1)
			return;
	}
	ChannelList* toadd = new ChannelList;
	toadd->name = name;
	toadd->users = user;
	toadd->desc = StripMessageOfFontCodes(description);
	channelLPtrList.AddTail( toadd);
	uint16 itemnr = serverChannelList.GetItemCount();
	itemnr = serverChannelList.InsertItem(LVIF_PARAM,itemnr,0,0,0,0,(LPARAM)toadd);
	serverChannelList.SetItemText(itemnr,0,toadd->name);
	serverChannelList.SetItemText(itemnr,1,toadd->users);
	serverChannelList.SetItemText(itemnr,2,toadd->desc);
}

int CIrcWnd::SortProcChanL(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort){
	ChannelList* item1 = (ChannelList*)lParam1;
	ChannelList* item2 = (ChannelList*)lParam2;
		switch(lParamSort){
		case 0: 
			return CString(item1->name).CompareNoCase(item2->name);
		case 10:
			return CString(item2->name).CompareNoCase(item1->name);
		case 1: 
			return atoi(item1->users) - atoi(item2->users);
		case 11:
			return atoi(item2->users) - atoi(item1->users);
		case 2: 
			return CString(item1->desc).CompareNoCase(item2->desc);
		case 12:
			return CString(item2->desc).CompareNoCase(item1->desc);
		default:
			return 0;
	}
}

void CIrcWnd::OnColumnClickChanL( NMHDR* pNMHDR, LRESULT* pResult){

	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	asc_sort[pNMListView->iSubItem] = !asc_sort[pNMListView->iSubItem];
	serverChannelList.SetSortArrow(pNMListView->iSubItem, asc_sort[pNMListView->iSubItem]);
	serverChannelList.SortItems(SortProcChanL, pNMListView->iSubItem+ ((asc_sort[pNMListView->iSubItem])? 0:10));
	*pResult = 0;
}

void CIrcWnd::OnNMRclickChanL(NMHDR *pNMHDR, LRESULT *pResult){
	POINT point; 
	::GetCursorPos(&point); 
	CPoint p = point; 
	ScreenToClient(&p); 
	CTitleMenu m_ChanLMenu;
	m_ChanLMenu.CreatePopupMenu();
	m_ChanLMenu.AddMenuTitle(GetResString(IDS_IRC_CHANNEL));
	m_ChanLMenu.AppendMenu(MF_STRING,Irc_Join,GetResString(IDS_IRC_JOIN)); 
	m_ChanLMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this); 
	m_ChanLMenu.DestroyMenu();
	*pResult = 0; 
}

void CIrcWnd::OnNMDblclkserverChannelList(NMHDR *pNMHDR, LRESULT *pResult){
	JoinChannels();
	*pResult = 0;
}

/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
// Nick List
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

Nick* CIrcWnd::FindNickByName(CString channel, CString name){
	Channel* curr_channel = FindChannelByName(channel);
	if( !curr_channel)
		return 0;
	POSITION pos1, pos2;
	for (pos1 = curr_channel->nicks.GetHeadPosition();( pos2 = pos1 ) != NULL;){
		curr_channel->nicks.GetNext(pos1);
		Nick* cur_nick = (Nick*)curr_channel->nicks.GetAt(pos2);
		if (cur_nick->nick == name)
			return cur_nick;
	}
	return 0;
}

Nick* CIrcWnd::NewNick( CString channel, CString nick ){
	Channel* toaddchan = FindChannelByName( channel );
	if( !toaddchan )
		return NULL;
	Nick* toaddnick;
	if(toaddchan){
		toaddnick = new Nick;
		if( nick.Left(1) == "@" ){
			toaddnick->mode = "@";
			toaddnick->nick = nick.Mid(1);
		}
		else if( nick.Left(1) == "%" ){
			toaddnick->mode = "%";
			toaddnick->nick = nick.Mid(1);
		}
		else if( nick.Left(1) == "+"){
			toaddnick->mode = "+";
			toaddnick->nick = nick.Mid(1);
		}
		else{
			toaddnick->nick = nick;
			toaddnick->mode = "";
		}
		toaddchan->nicks.AddTail(toaddnick);
		if( toaddchan == m_pCurrentChannel ){
			uint16 itemnr = nickList.GetItemCount();
			itemnr = nickList.InsertItem(LVIF_PARAM,itemnr,0,0,0,0,(LPARAM)toaddnick);
			nickList.SetItemText(itemnr,0,(LPCTSTR)toaddnick->nick);
			nickList.SetItemText(itemnr,1,(LPCTSTR)toaddnick->mode);
			UpdateNickCount();
		}
	}
	return toaddnick;
}

void CIrcWnd::RefreshNickList( CString channel ){
	nickList.DeleteAllItems();
	Channel* refresh = FindChannelByName( channel );
	if(!refresh )
		return;
	POSITION pos1, pos2;
	for (pos1 = refresh->nicks.GetHeadPosition();( pos2 = pos1 ) != NULL;){
		refresh->nicks.GetNext(pos1);
		Nick* curr_nick = (Nick*)refresh->nicks.GetAt(pos2);
		uint16 itemnr = nickList.GetItemCount();
		itemnr = nickList.InsertItem(LVIF_PARAM,itemnr,0,0,0,0,(LPARAM)curr_nick);
		nickList.SetItemText(itemnr,0,(LPCTSTR)curr_nick->nick);
		nickList.SetItemText(itemnr,1,(LPCTSTR)curr_nick->mode);
	}
	UpdateNickCount();
}

bool CIrcWnd::RemoveNick( CString channel, CString nick ){
	Channel* update = FindChannelByName( channel );
	if( !update )
		return false;
	POSITION pos1, pos2;
	for( pos1 = update->nicks.GetHeadPosition();(pos2=pos1)!=NULL;){
		update->nicks.GetNext(pos1);
		Nick* curr_nick = (Nick*)update->nicks.GetAt(pos2);
		if( curr_nick->nick == nick ){
			if( update == m_pCurrentChannel ){
				LVFINDINFO find;
				find.flags = LVFI_PARAM;
				find.lParam = (LPARAM)curr_nick;
				sint32 result = nickList.FindItem(&find);
				nickList.DeleteItem(result);
				UpdateNickCount();
			}
			update->nicks.RemoveAt(pos2);
			delete curr_nick;
			return true;
		}
	}
	return false;
}

void CIrcWnd::DeleteAllNick( CString channel ){
	Channel* curr_channel = FindChannelByName(channel);
	if( !curr_channel )
		return;
	POSITION pos3, pos4;
	for(pos3 = curr_channel->nicks.GetHeadPosition();( pos4 = pos3) != NULL;){
		curr_channel->nicks.GetNext(pos3);
		Nick* cur_nick = (Nick*)curr_channel->nicks.GetAt(pos4);
		curr_channel->nicks.RemoveAt(pos4);
		delete cur_nick;
	}
}

void CIrcWnd::DeleteNickInAll( CString nick, CString message ){
	POSITION pos1, pos2;
	for (pos1 = channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;){
		channelPtrList.GetNext(pos1);
		Channel* cur_channel = (Channel*)channelPtrList.GetAt(pos2);
		if(RemoveNick( cur_channel->name, nick )){
			if( !theApp.glob_prefs->GetIrcIgnoreInfoMessage() )
				AddInfoMessage( cur_channel->name, GetResString(IDS_IRC_HASQUIT), nick, message);
		}
	}
}

bool CIrcWnd::ChangeNick( CString channel, CString oldnick, CString newnick ){
	Channel* update = FindChannelByName( channel );
	if( !update )
		return false;
	POSITION pos1, pos2;
	for( pos1 = update->nicks.GetHeadPosition();(pos2=pos1)!=NULL;){
		update->nicks.GetNext(pos1);
		Nick* curr_nick = (Nick*)update->nicks.GetAt(pos2);
		if( curr_nick->nick == oldnick ){
			if( update = m_pCurrentChannel ){
				LVFINDINFO find;
				find.flags = LVFI_PARAM;
				find.lParam = (LPARAM)curr_nick;
				sint32 itemnr = nickList.FindItem(&find);
				if (itemnr != (-1))
					nickList.SetItemText(itemnr,0,(LPCTSTR)newnick);
			}
			curr_nick->nick = newnick;
			return true;
		}
	}
	return false;
}

bool CIrcWnd::ChangeMode( CString channel, CString nick, CString mode ){
	Channel* update = FindChannelByName( channel );
	if( !update )
		return false;
	POSITION pos1, pos2;
	for( pos1 = update->nicks.GetHeadPosition();(pos2=pos1)!=NULL;){
		update->nicks.GetNext(pos1);
		Nick* curr_nick = (Nick*)update->nicks.GetAt(pos2);
		if( curr_nick->nick == nick ){
			sint32 itemnr = -1;
			if( update = m_pCurrentChannel ){
				LVFINDINFO find;
				find.flags = LVFI_PARAM;
				find.lParam = (LPARAM)curr_nick;
				itemnr = nickList.FindItem(&find);
			}
			if( mode == "+v" ){
				if( curr_nick->mode == "@" || curr_nick->mode =="%" )
					return true;
				if( itemnr != (-1) )
					nickList.SetItemText(itemnr,1,(LPCTSTR)"+");
				curr_nick->mode = "+";
					return true;
			}
			else if(mode == "+h"){
				if( curr_nick->mode == "@" )
					return true;
				if( itemnr != (-1) )
					nickList.SetItemText(itemnr,1,(LPCTSTR)"%");
				curr_nick->mode = "%";
					return true;
			}
			else if(mode == "+o"){
				if( itemnr != (-1) )
					nickList.SetItemText(itemnr,1,(LPCTSTR)"@");
				curr_nick->mode = "@";
					return true;
			}
			if( mode == "-v" ){
				if( curr_nick->mode == "@" || curr_nick->mode =="%" )
					return true;
				if( itemnr != (-1) )
					nickList.SetItemText(itemnr,1,(LPCTSTR)"");
				curr_nick->mode = "";
					return true;
			}
			else if(mode == "-h"){
				if( curr_nick->mode == "@" )
					return true;
				if( itemnr != (-1) )
					nickList.SetItemText(itemnr,1,(LPCTSTR)"");
				curr_nick->mode = "";
					return true;
			}
			else if(mode == "-o"){
				if( itemnr != (-1) )
					nickList.SetItemText(itemnr,1,(LPCTSTR)"");
				curr_nick->mode = "";
					return true;
			}
			else{
				if( itemnr != (-1) )
					nickList.SetItemText(itemnr,1,(LPCTSTR)mode);
				curr_nick->mode = mode;
				return true;
			}
		}
	}
	return false;
}

void CIrcWnd::ParseChangeMode( CString channel, CString changer, CString commands, CString names ){
	if( commands.GetLength() == 2 ){
		if( ChangeMode( channel, names, commands ))
			if( !theApp.glob_prefs->GetIrcIgnoreInfoMessage() )
				AddInfoMessage( channel, GetResString(IDS_IRC_SETSMODE), changer, commands, names);
		return;
	}
	// Need to support multiple mode changes
	AddInfoMessage( channel, GetResString(IDS_IRC_NOTSUPPORTED));
}

void CIrcWnd::ChangeAllNick( CString oldnick, CString newnick ){
	Channel* currchannel = FindChannelByName( oldnick );
	if( currchannel ){
		currchannel->name = newnick;
		TCITEM item;
		item.mask = TCIF_PARAM;
		int i;
		for (i = 0; i != channelselect.GetItemCount();i++){
			channelselect.GetItem(i,&item);
			if (((Channel*)item.lParam) == currchannel)
				break;
		}
		if (((Channel*)item.lParam) != currchannel)
			return;
		item.mask = TCIF_TEXT;
		item.pszText = newnick.GetBuffer();
		item.cchTextMax = (int)newnick.GetLength()+1;
		channelselect.SetItem( i, &item);
	}
	POSITION pos1, pos2;
	for (pos1 = channelPtrList.GetHeadPosition();( pos2 = pos1 ) != NULL;){
		channelPtrList.GetNext(pos1);
		Channel* cur_channel = (Channel*)channelPtrList.GetAt(pos2);
		if(ChangeNick( cur_channel->name, oldnick, newnick )){
			if( !theApp.glob_prefs->GetIrcIgnoreInfoMessage() )
				AddInfoMessage( cur_channel->name, GetResString(IDS_IRC_NOWKNOWNAS), oldnick, newnick);
		}
	}
}

/*
void CIrcWnd::SetNick( CString in_nick ){
	theApp.glob_prefs->SetIRCNick( in_nick.GetBuffer() );
	//Need to also update the preference window for this to work right..
}
*/

int CIrcWnd::SortProcNick(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort){
	Nick* item1 = (Nick*)lParam1;
	Nick* item2 = (Nick*)lParam2;
		switch(lParamSort){
		case 0: 
			if( item1->mode == item2->mode )
				return CString(item1->nick).CompareNoCase(item2->nick);
			if( item1->mode == "@" )
				return -1;
			if( item2->mode == "@" )
				return 1;
			if( item1->mode == "%" )
				return -1;
			if( item2->mode == "%" )
				return 1;
			if( item1->mode == "+" )
				return -1;
			return 0;
		case 10:
			if( item1->mode == item2->mode )
				return CString(item1->nick).CompareNoCase(item2->nick);
			if( item1->mode == "@" )
				return -1;
			if( item2->mode == "@" )
				return 1;
			if( item1->mode == "%" )
				return -1;
			if( item2->mode == "%" )
				return 1;
			if( item1->mode == "+" )
				return -1;
			return 0;
		default:
			return 0;
	}
}

void CIrcWnd::OnColumnClickNick( NMHDR* pNMHDR, LRESULT* pResult){

	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	asc_sort[pNMListView->iSubItem] = !asc_sort[pNMListView->iSubItem];
//	nickList.SetSortArrow(pNMListView->iSubItem, asc_sort[pNMListView->iSubItem]);
	nickList.SortItems(SortProcNick, pNMListView->iSubItem+ ((asc_sort[pNMListView->iSubItem])? 0:10));
	*pResult = 0;
}

void CIrcWnd::OnNMRclickNick(NMHDR *pNMHDR, LRESULT *pResult) 
{ 
	
	if (nickList.GetSelectionMark() != (-1) ){
		POINT point; 
		::GetCursorPos(&point); 
		CPoint p = point; 
		ScreenToClient(&p); 
		CTitleMenu m_NickMenu;
		m_NickMenu.CreatePopupMenu(); 
		m_NickMenu.AddMenuTitle(GetResString(IDS_IRC_NICK));
		m_NickMenu.AppendMenu(MF_STRING,Irc_Priv,GetResString(IDS_IRC_PRIVMESSAGE));
		m_NickMenu.AppendMenu(MF_STRING,Irc_AddFriend,GetResString(IDS_IRC_ADDTOFRIENDLIST));
//		if( !GetSendFileString().IsEmpty() )
//			m_NickMenu.AppendMenu(MF_STRING,Irc_SendLink, (CString)GetResString(IDS_IRC_SENDLINK) + GetSendFileString() );
		m_NickMenu.AppendMenu(MF_STRING,Irc_Slap,GetResString(IDS_IRC_SLAP));
		m_NickMenu.AppendMenu(MF_STRING,Irc_Op,GetResString(IDS_IRC_OP));
		m_NickMenu.AppendMenu(MF_STRING,Irc_DeOp,GetResString(IDS_IRC_DEOP));
		m_NickMenu.AppendMenu(MF_STRING,Irc_HalfOp,GetResString(IDS_IRC_HALFOP));
		m_NickMenu.AppendMenu(MF_STRING,Irc_DeHalfOp,GetResString(IDS_IRC_DEHALFOP));
		m_NickMenu.AppendMenu(MF_STRING,Irc_Voice,GetResString(IDS_IRC_VOICE));
		m_NickMenu.AppendMenu(MF_STRING,Irc_DeVoice,GetResString(IDS_IRC_DEVOICE));
		m_NickMenu.AppendMenu(MF_STRING,Irc_Kick,GetResString(IDS_IRC_KICK));
		m_NickMenu.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, point.y, this); 
		m_NickMenu.DestroyMenu();
	}
   *pResult = 0; 
}

void CIrcWnd::OnNMDblclkNickList(NMHDR *pNMHDR, LRESULT *pResult){
	int nickItem= nickList.GetSelectionMark();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -