Esempio n. 1
0
BOOL CChatFrame::OnShowPopupMenu (CBCGPopupMenu* pMenuPopup)
{
	clearIdleTime();

	//---------------------------------------------------------
	// Replace ID_VIEW_TOOLBARS menu item to the toolbars list:
	//---------------------------------------------------------
    CFrameWnd::OnShowPopupMenu (pMenuPopup);

    if (pMenuPopup != NULL &&
		pMenuPopup->GetMenuBar ()->CommandToIndex (ID_VIEW_TOOLBARS) >= 0)
    {
		if (CBCGToolBar::IsCustomizeMode ())
		{
			//----------------------------------------------------
			// Don't show toolbars list in the cuztomization mode!
			//----------------------------------------------------
			return FALSE;
		}

		pMenuPopup->RemoveAllItems ();

		CMenu menu;
		VERIFY(menu.LoadMenu (IDR_POPUP_TOOLBAR));

		CMenu* pPopup = menu.GetSubMenu(0);
		ASSERT(pPopup != NULL);

		pMenuPopup->GetMenuBar ()->ImportFromMenu (*pPopup, TRUE);
    }
	
	if ( pMenuPopup != NULL && pMenuPopup->GetParentToolBar() == &m_wndTopChatBar )
	{
		if ( m_wndTopChatBar.GetButton( m_GameButton ) == pMenuPopup->GetParentButton() )
		{
			CWaitCursor wait;

			MetaClient & client = CGCQLApp::sm_MetaClient;
			if ( client.getGames( m_Games ) < 0 )
			{
				//MessageBox( "Failed to get game list." );
				return FALSE;
			}

			pMenuPopup->RemoveAllItems();

			CMenu gameMenu;
			gameMenu.CreatePopupMenu();

			for(int i=0;i<m_Games.size() && i < MAX_GAMES;i++)
				gameMenu.AppendMenu( MF_STRING, ID_GAMES_BEGIN + i, CString(m_Games[i].name) );

			pMenuPopup->GetMenuBar()->ImportFromMenu (gameMenu, TRUE);
		}
		if ( m_wndTopChatBar.GetButton( m_RoomsButton ) == pMenuPopup->GetParentButton() )
		{
			CWaitCursor wait;

			MetaClient & client = CGCQLApp::sm_MetaClient;
			if ( client.getRooms( m_Rooms ) < 0 )
				return FALSE;

			pMenuPopup->RemoveAllItems();

			CMenu roomMenu;
			roomMenu.CreatePopupMenu();
			roomMenu.AppendMenu( MF_STRING, ID_CHAT_CREATEROOM, _T("New Room") );
			roomMenu.AppendMenu( MF_SEPARATOR );

			for(int i=0;i<m_Rooms.size() && i < MAX_ROOMS;i++)
			{
				MetaClient::Room & room = m_Rooms[i];
				
				CString sName;
				sName.Format( _T("%s "), CString( room.name ) );
				if ( room.flags & MetaClient::FLAG_ROOM_MODERATED )
					sName += _T("[MODERATED]");
				if ( room.flags & MetaClient::FLAG_ROOM_PASSWORD )
					sName += _T("[PRIVATE]");
				if ( room.flags & MetaClient::FLAG_ROOM_PRIVATE )
					sName += _T("[HIDDEN]");

				CString sMembers;
				sMembers.Format( _T("\t%u"), room.members );

				sName += sMembers;

				roomMenu.AppendMenu( MF_STRING, ID_ROOM_BEGIN + i, sName );
			}

			pMenuPopup->GetMenuBar()->ImportFromMenu (roomMenu, TRUE);
		}
		if ( m_wndTopChatBar.GetButton( m_FriendsButton ) == pMenuPopup->GetParentButton() )
		{
			CWaitCursor wait;

			MetaClient & client = CGCQLApp::sm_MetaClient;
			if ( client.getFriends( m_Friends ) < 0 )
			{
				//MessageBox( "Failed to get room list." );
				return FALSE;
			}
			
			// let friends who are online appear on top of the list
			m_Friends.qsort( userOnlineSort );

			pMenuPopup->RemoveAllItems();

			CMenu friendsMenu;
			friendsMenu.CreatePopupMenu();

			for(int i=0;i<m_Friends.size() && i < MAX_FRIENDS;i++)
			{
				MetaClient::ShortProfile & profile = m_Friends[ i ];

				CString sFriend;
				sFriend.Format(_T("%s\t%s"), CString(profile.name), CString(profile.status) );

				CMenu friendMenu;
				friendMenu.CreateMenu();
				friendMenu.AppendMenu( MF_STRING, ID_FRIEND_MSG_BEGIN + i, _T("Message") );
				friendMenu.AppendMenu( MF_STRING, ID_FRIEND_DEL_BEGIN + i, _T("Delete") );
				friendsMenu.AppendMenu( MF_POPUP, (UINT)friendMenu.Detach(), sFriend );
			}

			pMenuPopup->GetMenuBar()->ImportFromMenu( friendsMenu, TRUE );
		}
		if ( m_wndTopChatBar.GetButton( m_StaffButton ) == pMenuPopup->GetParentButton() )
		{
			CWaitCursor wait;

			MetaClient & client = CGCQLApp::sm_MetaClient;
			if ( client.getStaffOnline( m_Staff ) < 0 )
				return FALSE;
			
			dword userId = client.profile().userId;
			for( int i = 0 ; i < m_Staff.size() ; i++ )
				if( m_Staff[ i ].userId == userId )
				{
					m_Staff.remove(i);
					break;
				}

			pMenuPopup->RemoveAllItems();

			CMenu staffMenu;
			staffMenu.CreatePopupMenu();

			for(int i=0;i<m_Staff.size() && i < MAX_STAFF;i++)
			{
				MetaClient::ShortProfile & profile = m_Staff[ i ];

				CString sType;
				if ( profile.flags & MetaClient::ADMINISTRATOR )
					sType = "[ADMIN]";
				else if ( profile.flags & MetaClient::MODERATOR )
					sType = "[MOD]";

				CString sName;
				sName = profile.name;
				CString sStaffMember;
				sStaffMember.Format( _T("%s: %s\t%s"), sType, sName, CString(profile.status) );

				CMenu stMenu;
				stMenu.CreateMenu();
				stMenu.AppendMenu( MF_STRING, ID_STAFF_MSG_BEGIN + i, _T("Message") );

				bool bInserted = false;
				for(unsigned int j=0;j<staffMenu.GetMenuItemCount() && !bInserted;j++)
				{
					CString sCompare;
					staffMenu.GetMenuString( j, sCompare, MF_BYPOSITION );

					if ( _tcscmp( sCompare, sName ) > 0 )
					{
						staffMenu.InsertMenu( j, MF_BYPOSITION|MF_POPUP, (UINT)stMenu.Detach(), sStaffMember ) ? true : false;
						bInserted = true;
					}
				}

				if (!bInserted )
					staffMenu.AppendMenu( MF_POPUP, (UINT)stMenu.Detach(), sStaffMember );
			}

			pMenuPopup->GetMenuBar()->ImportFromMenu( staffMenu, TRUE );
		}
		if ( m_wndTopChatBar.GetButton( m_ClanButton ) == pMenuPopup->GetParentButton() )
		{
			CWaitCursor wait;

			pMenuPopup->RemoveAllItems();

			MetaClient & client = CGCQLApp::sm_MetaClient;

			CMenu clanMenu;
			clanMenu.CreatePopupMenu();
			//clanMenu.AppendMenu( MF_STRING, ID_GAMEBAR_CLAN, _T("Fleet Home") );

			dword clanId = client.profile().clanId;
			if ( clanId != 0 )
			{
				clanMenu.AppendMenu( MF_SEPARATOR );
				if ( client.getClan( clanId, m_Clan ) < 0 )
				{
					//MessageBox( "Failed to get clan members" );
					return FALSE;
				}
				
				// Remove self from clanlist
				for( int i = 0 ; i < m_Clan.size() ; i++ )
					if( m_Clan[i].userId == client.profile().userId )
					{
						m_Clan.remove(i);
						break;
					}

				// let members who are online appear on top of the list
				m_Clan.qsort( userOnlineSort );

				for( int i = 0 ; i < m_Clan.size() && i < MAX_CLAN ; i++ )
				{
					MetaClient::ShortProfile & profile = m_Clan[ i ];

					CString sClanMember;
					sClanMember.Format( _T("%s\t%s"), CString(profile.name), CString(profile.status) );

					CMenu subMenu;
					subMenu.CreateMenu();
					subMenu.AppendMenu( MF_STRING, ID_CLAN_MSG_BEGIN + i, _T("Message") );

					clanMenu.AppendMenu( MF_POPUP, (UINT)subMenu.Detach(), sClanMember );
				}
			}

			pMenuPopup->GetMenuBar()->ImportFromMenu( clanMenu, TRUE );
		}

	}

	return TRUE;
}
Esempio n. 2
0
void CMuleToolbarCtrl::OnNmRClick(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{
	if (GetKeyState(VK_CONTROL) & 0x8000)
	{
		if (!thePrefs.GetToolbarBitmapSettings().IsEmpty())
			ChangeToolbarBitmap(thePrefs.GetToolbarBitmapSettings(), true);
		if (!thePrefs.GetSkinProfile().IsEmpty())
			theApp.ApplySkin(thePrefs.GetSkinProfile());

		*pResult = TRUE;
		return;
	}


	///////////////////////////////////////////////////////////////////////////
	// "Toolbar Bitmap" sub menu
	//
	CMenu menuBitmaps;
	menuBitmaps.CreateMenu();
	menuBitmaps.AppendMenu(MF_STRING, MP_SELECTTOOLBARBITMAP, GetResString(IDS_SELECTTOOLBARBITMAP));
	menuBitmaps.AppendMenu(MF_STRING, MP_SELECTTOOLBARBITMAPDIR, GetResString(IDS_SELECTTOOLBARBITMAPDIR));
	menuBitmaps.AppendMenu(MF_SEPARATOR);
	menuBitmaps.AppendMenu(MF_STRING, MP_TOOLBARBITMAP, GetResString(IDS_DEFAULT));
	
	m_astrToolbarPaths.RemoveAll();
	CString currentBitmapSettings = thePrefs.GetToolbarBitmapSettings();
	bool checked = false;
	if (currentBitmapSettings.IsEmpty())
	{
		menuBitmaps.CheckMenuItem(MP_TOOLBARBITMAP, MF_CHECKED);
		menuBitmaps.EnableMenuItem(MP_TOOLBARBITMAP, MF_DISABLED);
		checked = true;
	}
	m_astrToolbarPaths.Add(_T("")); // dummy entry for 'Default' menu item
	int i = 1;
	if (!thePrefs.GetMuleDirectory(EMULE_TOOLBARDIR).IsEmpty())
	{
		CStringArray astrToolbarFiles;
		for (int f = 0; f < _countof(s_apszTBFiles); f++)
		{
			WIN32_FIND_DATA FileData;
			HANDLE hSearch = FindFirstFile(thePrefs.GetMuleDirectory(EMULE_TOOLBARDIR) + CString(_T("\\")) + s_apszTBFiles[f], &FileData);
			if (hSearch != INVALID_HANDLE_VALUE)
			{
				do {
					astrToolbarFiles.Add(FileData.cFileName);
				}
				while (astrToolbarFiles.GetCount() < MAX_TOOLBAR_FILES && FindNextFile(hSearch, &FileData));
				FindClose(hSearch);
			}
		}

		if (astrToolbarFiles.GetCount() > 0)
		{
			Sort(astrToolbarFiles);
			for (int f = 0; f < astrToolbarFiles.GetCount(); f++)
			{
				const CString& bitmapFileName = astrToolbarFiles.GetAt(f);
				CString bitmapBaseName;
				LPCTSTR pszTbBaseExt = stristr(bitmapFileName, EMULTB_BASEEXT);
				if (pszTbBaseExt)
					bitmapBaseName = bitmapFileName.Left(pszTbBaseExt - (LPCTSTR)bitmapFileName - 1);
				else
					bitmapBaseName = bitmapFileName;
				menuBitmaps.AppendMenu(MF_STRING, MP_TOOLBARBITMAP + i, bitmapBaseName);
				m_astrToolbarPaths.Add(thePrefs.GetMuleDirectory(EMULE_TOOLBARDIR) + CString(_T("\\")) + bitmapFileName);
				if (!checked && currentBitmapSettings.CompareNoCase(m_astrToolbarPaths[i]) == 0)
				{
					menuBitmaps.CheckMenuItem(MP_TOOLBARBITMAP + i, MF_CHECKED);
					menuBitmaps.EnableMenuItem(MP_TOOLBARBITMAP + i, MF_DISABLED);
					checked = true;
				}
				i++;
			}
		}
		ASSERT( i-1 == astrToolbarFiles.GetCount() );
	}
	if (!checked)
	{
		menuBitmaps.AppendMenu(MF_STRING, MP_TOOLBARBITMAP + i, currentBitmapSettings);
		menuBitmaps.CheckMenuItem(MP_TOOLBARBITMAP + i, MF_CHECKED);
		menuBitmaps.EnableMenuItem(MP_TOOLBARBITMAP + i, MF_DISABLED);
		m_astrToolbarPaths.Add(currentBitmapSettings);
	}


	///////////////////////////////////////////////////////////////////////////
	// "Skin Profile" sub menu
	//
	CMenu menuSkins;
	menuSkins.CreateMenu();
	menuSkins.AppendMenu(MF_STRING, MP_SELECT_SKIN_FILE, GetResString(IDS_SEL_SKIN));
	menuSkins.AppendMenu(MF_STRING, MP_SELECT_SKIN_DIR, GetResString(IDS_SEL_SKINDIR));
	menuSkins.AppendMenu(MF_SEPARATOR);
	menuSkins.AppendMenu(MF_STRING, MP_SKIN_PROFILE,GetResString(IDS_DEFAULT));

	m_astrSkinPaths.RemoveAll();
	CString currentSkin = thePrefs.GetSkinProfile();
	checked = false;
	if (currentSkin.IsEmpty())
	{
		menuSkins.CheckMenuItem(MP_SKIN_PROFILE, MF_CHECKED);
		menuSkins.EnableMenuItem(MP_SKIN_PROFILE, MF_DISABLED);
		checked = true;
	}
	m_astrSkinPaths.Add(_T("")); // dummy entry for 'Default' menu item
	i = 1;
	if (!thePrefs.GetMuleDirectory(EMULE_SKINDIR, false).IsEmpty())
	{
		CStringArray astrSkinFiles;
		for (int f = 0; f < _countof(s_apszSkinFiles); f++)
		{
			WIN32_FIND_DATA FileData;
			HANDLE hSearch = FindFirstFile(thePrefs.GetMuleDirectory(EMULE_SKINDIR, false) + CString(_T("\\")) + s_apszSkinFiles[f], &FileData);
			if (hSearch != INVALID_HANDLE_VALUE)
			{
				do {
					astrSkinFiles.Add(FileData.cFileName);
				}
				while (astrSkinFiles.GetCount() < MAX_SKIN_FILES && FindNextFile(hSearch, &FileData));
				FindClose(hSearch);
			}
		}

		if (astrSkinFiles.GetCount() > 0)
		{
			Sort(astrSkinFiles);
			for (int f = 0; f < astrSkinFiles.GetCount(); f++)
			{
				const CString& skinFileName = astrSkinFiles.GetAt(f);
				CString skinBaseName;
				LPCTSTR pszSkinBaseExt = stristr(skinFileName, _T(".") EMULSKIN_BASEEXT _T(".ini"));
				if (pszSkinBaseExt)
					skinBaseName = skinFileName.Left(pszSkinBaseExt - (LPCTSTR)skinFileName);
				else
					skinBaseName = skinFileName;
				menuSkins.AppendMenu(MF_STRING, MP_SKIN_PROFILE + i, skinBaseName);
				m_astrSkinPaths.Add(thePrefs.GetMuleDirectory(EMULE_SKINDIR, false) + CString(_T("\\")) + skinFileName);
				if (!checked && currentSkin.CompareNoCase(m_astrSkinPaths[i]) == 0)
				{
					menuSkins.CheckMenuItem(MP_SKIN_PROFILE + i, MF_CHECKED);
					menuSkins.EnableMenuItem(MP_SKIN_PROFILE + i, MF_DISABLED);
					checked = true;
				}
				i++;
			}
		}
		ASSERT( i-1 == astrSkinFiles.GetCount() );
	}
	if (!checked)
	{
		menuSkins.AppendMenu(MF_STRING, MP_SKIN_PROFILE + i, currentSkin);
		menuSkins.CheckMenuItem(MP_SKIN_PROFILE + i, MF_CHECKED);
		menuSkins.EnableMenuItem(MP_SKIN_PROFILE + i, MF_DISABLED);
		m_astrSkinPaths.Add(currentSkin);
	}
	

	///////////////////////////////////////////////////////////////////////////
	// "Text Label" sub menu
	//
	CMenu menuTextLabels;
	menuTextLabels.CreateMenu();
	ASSERT( MP_NOTEXTLABELS == MP_TEXTLABELS-1 && MP_NOTEXTLABELS == MP_TEXTLABELSONRIGHT-2 );
	ASSERT( MP_NOTEXTLABELS + (int)NoLabels == MP_NOTEXTLABELS );
	ASSERT( MP_NOTEXTLABELS + (int)LabelsBelow == MP_TEXTLABELS );
	ASSERT( MP_NOTEXTLABELS + (int)LabelsRight == MP_TEXTLABELSONRIGHT );
	menuTextLabels.AppendMenu(MF_STRING | MF_ENABLED, MP_NOTEXTLABELS, GetResString(IDS_NOTEXTLABELS));
	menuTextLabels.AppendMenu(MF_STRING | MF_ENABLED, MP_TEXTLABELS, GetResString(IDS_ENABLETEXTLABELS));
	menuTextLabels.AppendMenu(MF_STRING | MF_ENABLED, MP_TEXTLABELSONRIGHT, GetResString(IDS_TEXTLABELSONRIGHT));
	menuTextLabels.CheckMenuRadioItem(MP_NOTEXTLABELS, MP_TEXTLABELSONRIGHT, MP_NOTEXTLABELS + (int)thePrefs.GetToolbarLabelSettings(), MF_BYCOMMAND);
	menuTextLabels.EnableMenuItem(MP_NOTEXTLABELS + (int)thePrefs.GetToolbarLabelSettings(), MF_BYCOMMAND | MF_DISABLED);

	menuTextLabels.AppendMenu(MF_SEPARATOR);
	menuTextLabels.AppendMenu(MF_STRING, MP_LARGEICONS, GetResString(IDS_LARGEICONS));
	menuTextLabels.AppendMenu(MF_STRING, MP_SMALLICONS, GetResString(IDS_SMALLICONS));
	ASSERT( MP_LARGEICONS == MP_SMALLICONS-1 );
	menuTextLabels.CheckMenuRadioItem(MP_LARGEICONS, MP_SMALLICONS, m_sizBtnBmp.cx == 16 ? MP_SMALLICONS : MP_LARGEICONS, MF_BYCOMMAND);
	menuTextLabels.EnableMenuItem(m_sizBtnBmp.cx == 16 ? MP_SMALLICONS : MP_LARGEICONS, MF_BYCOMMAND | MF_DISABLED);


	///////////////////////////////////////////////////////////////////////////
	// Toolbar context menu
	//
	CMenu menuToolbar;
	menuToolbar.CreatePopupMenu();
	menuToolbar.AppendMenu(MF_STRING | MF_POPUP, (UINT_PTR)menuBitmaps.m_hMenu, GetResString(IDS_TOOLBARSKINS));
	menuToolbar.AppendMenu(MF_STRING | MF_POPUP, (UINT_PTR)menuSkins.m_hMenu, GetResString(IDS_SKIN_PROF));
	menuToolbar.AppendMenu(MF_STRING | MF_POPUP, (UINT_PTR)menuTextLabels.m_hMenu, GetResString(IDS_TEXTLABELS));
	menuToolbar.AppendMenu(MF_STRING, MP_CUSTOMIZETOOLBAR, GetResString(IDS_CUSTOMIZETOOLBAR));
	CPoint point;
	GetCursorPos(&point);
	menuToolbar.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);

	*pResult = TRUE;
}