//****************************************************************************
CBCGPToolbarButton* CBCGPDropDownList::GetItem (int nIndex) const
{
	ASSERT_VALID (this);

	CBCGPPopupMenuBar* pMenuBar = ((CBCGPDropDownList*) this)->GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	int nCurrIndex = 0;

	for (int i = 0; i < pMenuBar->GetCount (); i++)
	{
		CBCGPToolbarButton* pItem = pMenuBar->GetButton (i);
		ASSERT_VALID (pItem);

		if (!(pItem->m_nStyle & TBBS_SEPARATOR))
		{
			if (nIndex == nCurrIndex)
			{
				return pItem;
			}
		}
	}

	return NULL;
}
//***************************************************************************
int CBCGPDropDownList::GetCurSel()
{
	ASSERT_VALID (this);

	if (GetSafeHwnd () == NULL)
	{
		return m_nCurSel;
	}

	CBCGPPopupMenuBar* pMenuBar = ((CBCGPDropDownList*) this)->GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	CBCGPToolbarButton* pSel = pMenuBar->GetHighlightedButton ();
	if (pSel == NULL)
	{
		return -1;
	}

	int nIndex = 0;

	for (int i = 0; i < pMenuBar->GetCount (); i++)
	{
		CBCGPToolbarButton* pItem = pMenuBar->GetButton (i);
		ASSERT_VALID (pItem);

		if (!(pItem->m_nStyle & TBBS_SEPARATOR))
		{
			if (pSel == pItem)
			{
				m_nCurSel = nIndex;
				return nIndex;
			}

			nIndex++;
		}
	}

	return -1;
}
//***************************************************************************
int CBCGPDropDownList::SetCurSel(int nSelect)
{
	ASSERT_VALID (this);

	const int nSelOld = GetCurSel ();

	if (GetSafeHwnd () == NULL)
	{
		m_nCurSel = nSelect;
		return nSelOld;
	}

	CBCGPPopupMenuBar* pMenuBar = ((CBCGPDropDownList*) this)->GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	int nIndex = 0;

	for (int i = 0; i < pMenuBar->GetCount (); i++)
	{
		CBCGPToolbarButton* pItem = pMenuBar->GetButton (i);
		ASSERT_VALID (pItem);

		if (!(pItem->m_nStyle & TBBS_SEPARATOR))
		{
			if (nIndex == nSelect)
			{
				HighlightItem (i);
				return nSelOld;
			}

			nIndex++;
		}
	}

	return -1;
}
예제 #4
0
파일: MainFrm.cpp 프로젝트: zxlooong/bcgexp
BOOL CMainFrame::OnShowPopupMenu (CBCGPPopupMenu* pMenuPopup)
{
    CBCGPMDIFrameWnd::OnShowPopupMenu (pMenuPopup);

    if (pMenuPopup == NULL)
    {
        return TRUE;
    }

    CBCGPPopupMenuBar* pMenuBar = pMenuPopup->GetMenuBar ();
    ASSERT_VALID (pMenuBar);

    for (int i = 0; i < pMenuBar->GetCount (); i ++)
    {
        CBCGPToolbarButton* pButton = pMenuBar->GetButton (i);
        ASSERT_VALID (pButton);

        if (pButton->m_nID == ID_FAVORITES_DUMMY)
        {
            pMenuBar->ImportFromMenu (m_menuFavotites);
            pMenuPopup->SetMaxWidth (300);

            return TRUE;
        }

        if (pButton->m_nID == ID_VIEW_HISTORY)
        {
            CMenu menuHistory;
            menuHistory.LoadMenu (IDR_HISTORY_POPUP);

            CMenu* subMenu = menuHistory.GetSubMenu (0);
            ASSERT_VALID (subMenu);

            CBCGPIE7DemoView* pView = DYNAMIC_DOWNCAST(CBCGPIE7DemoView, GetActiveHTML ());
            if (pView != NULL)
            {
                CBCGPIE7DemoDoc* pDoc = pView->GetDocument ();
                if (pDoc != NULL)
                {
                    _T_HistotyList lst;

                    int index = 0;
                    POSITION pos = NULL;

                    pDoc->GetBackList (lst);
                    for (pos = lst.GetHeadPosition (); pos != NULL;)
                    {
                        CHistoryObj* pObj = lst.GetNext (pos);
                        ASSERT (pObj != NULL);

                        subMenu->InsertMenu (index, MF_STRING | MF_BYPOSITION,
                                             pObj->GetCommand (), pObj->GetTitle ());
                        index++;
                    }

                    pDoc->GetFrwdList (lst);
                    for (pos = lst.GetHeadPosition (); pos != NULL;)
                    {
                        CHistoryObj* pObj = lst.GetNext (pos);
                        ASSERT (pObj != NULL);

                        subMenu->InsertMenu (index, MF_STRING | MF_BYPOSITION,
                                             pObj->GetCommand (), pObj->GetTitle ());
                        index++;
                    }

                    if (index > 0)
                    {
                        subMenu->InsertMenu (index, MF_SEPARATOR | MF_BYPOSITION, 0, (LPCTSTR)NULL);
                    }
                }
            }

            pMenuBar->ImportFromMenu (subMenu->GetSafeHmenu ());
            return TRUE;
        }
    }

    return TRUE;
}