Beispiel #1
0
void MenuTestCase::CreateFrame()
{
    m_frame = new wxFrame(NULL, wxID_ANY, "test frame");

    wxMenu *fileMenu = new wxMenu;
    wxMenu *helpMenu = new wxMenu;
    wxMenu *subMenu = new wxMenu;
    wxMenu *subsubMenu = new wxMenu;

    size_t itemcount = 0;

    PopulateMenu(subsubMenu, "Subsubmenu item ", itemcount);

    // Store one of its IDs for later
    m_subsubmenuItemId = MenuTestCase_First + itemcount - 2;

    PopulateMenu(subMenu, "Submenu item ", itemcount);

    // Store one of its IDs for later
    m_submenuItemId = MenuTestCase_First + itemcount - 2;

    subMenu->AppendSubMenu(subsubMenu, "Subsubmen&u", "Test a subsubmenu");

    // Check GetTitle() returns the correct string _before_ appending to the bar
    fileMenu->SetTitle("&Foo\tCtrl-F");
    CPPUNIT_ASSERT_EQUAL( "&Foo\tCtrl-F", fileMenu->GetTitle() );

    PopulateMenu(fileMenu, "Filemenu item ", itemcount);

    fileMenu->Append(MenuTestCase_Foo, "&Foo\tCtrl-F", "Test item to be found");


    PopulateMenu(helpMenu, "Helpmenu item ", itemcount);
    helpMenu->Append(MenuTestCase_Bar, "Bar\tF1");
    m_menuWithBar = helpMenu;
    helpMenu->AppendSubMenu(subMenu, "Sub&menu", "Test a submenu");

    // +2 for "Foo" and "Bar", +2 for the 2 submenus
    m_itemCount = itemcount + 4;

    // Use an arraystring here, to help with future tests
    m_menuLabels.Add("&File");
    m_menuLabels.Add("&Help");

    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(fileMenu, m_menuLabels[0]);
    menuBar->Append(helpMenu, m_menuLabels[1]);
    m_frame->SetMenuBar(menuBar);
}
STDMETHODIMP CGitExtensionsShellEx::QueryContextMenu  (
    HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd,
    UINT uidLastCmd, UINT uFlags )
{
    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if ( uFlags & CMF_DEFAULTONLY )
        return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 );

    //InsertMenu (hmenu, uMenuIndex, MF_BYPOSITION, uidFirstCmd, _T("GitEx") );

    int id = 0;

    CString szCascadeContextMenu = GetRegistryValue(HKEY_CURRENT_USER, "SOFTWARE\\GitExtensions\\GitExtensions", "ShellCascadeContextMenu");

    CascadeContextMenu = !(szCascadeContextMenu == "False");

    if (CascadeContextMenu)
    {
        // show context menu cascaded in submenu
        HMENU popupMenu = CreateMenu();

        id = PopulateMenu(popupMenu, uidFirstCmd + id, true);

        //InsertMenu(hmenu, uMenuIndex++, MF_STRING | MF_BYPOSITION | MF_POPUP, (int)popupMenu, "Git Extensions");
        MENUITEMINFO info;

        info.cbSize = sizeof( MENUITEMINFO );
        info.fMask = MIIM_ID | MIIM_TYPE | MIIM_SUBMENU;
        info.fType = MFT_STRING;
        info.wID = uidFirstCmd + 1;
        info.dwTypeData = _T("Git Extensions");
        info.hSubMenu = popupMenu;
        InsertMenuItem(hmenu, 0, true, &info);
    }
    else
    {
        // show menu items directly
        id = PopulateMenu(hmenu, uidFirstCmd + id, false);
    }

    return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, id-uidFirstCmd );
}
STDMETHODIMP CGitExtensionsShellEx::QueryContextMenu  (
    HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd,
    UINT uidLastCmd, UINT uFlags )
{
    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if ( uFlags & CMF_DEFAULTONLY )
        return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 );

    int id = 0;

    CString szCascadeContextMenu = GetRegistryValue(HKEY_CURRENT_USER, "SOFTWARE\\GitExtensions\\GitExtensions", "ShellCascadeContextMenu");

    CascadeContextMenu = !(szCascadeContextMenu == "False");

    if (CascadeContextMenu)
    {
        // show context menu cascaded in submenu
        HMENU popupMenu = CreateMenu();

        id = PopulateMenu(popupMenu, uidFirstCmd, id, true);

        MENUITEMINFO info;

        info.cbSize = sizeof( MENUITEMINFO );
        info.fMask = MIIM_STRING | MIIM_ID | MIIM_BITMAP | MIIM_SUBMENU;
        info.wID = uidFirstCmd + 1;
        info.hbmpItem = IsVistaOrLater() ? IconToBitmapPARGB32(IDI_GITEXTENSIONS) : HBMMENU_CALLBACK;
        myIDMap[1] = IDI_GITEXTENSIONS;
        myIDMap[uidFirstCmd + 1] = IDI_GITEXTENSIONS;
        info.dwTypeData = _T("Git Extensions");
        info.hSubMenu = popupMenu;
        InsertMenuItem(hmenu, 0, true, &info);
    }
    else
    {
        // show menu items directly
        id = PopulateMenu(hmenu, uidFirstCmd, id, false);
    }

    return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, id );
}
Beispiel #4
0
/** \brief Populate a displayed menu
 *
 * This method peruses a property bag of arrays of menu items. It calls
 * PopulateMenu() to cause a displayed menu to be populated.
 *
 * \param[in] path Path to this menu
 * \param[in] propBag A set of property bag arrays to add to the menus
 *
 * \sa PopulateMenu
 */
void moMenuManager::PopulateMenu( const moWCString& path, moPropBagRef propBag )
{
	unsigned long idx = 0;
	const unsigned long end = propBag.Count();

	for( ; idx < end; idx++ )
	{
		moPropRef		prop		= propBag[idx];
		moProp::prop_type_t	type		= prop.GetType();

		if( type == moProp::MO_PROP_TYPE_ARRAY )
		{
			moPropArrayRef	array = prop;
			PopulateMenu( path, array );
		}
	}
}
STDMETHODIMP CSimpleShlExt::QueryContextMenu  (
    HMENU hmenu, UINT uMenuIndex, UINT uidFirstCmd,
    UINT uidLastCmd, UINT uFlags )
{
    // If the flags include CMF_DEFAULTONLY then we shouldn't do anything.
    if ( uFlags & CMF_DEFAULTONLY )
        return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 );

    //InsertMenu (hmenu, uMenuIndex, MF_BYPOSITION, uidFirstCmd, _T("GitEx") );

	int id = 1;

	HMENU popupMenu = CreateMenu();

	id = PopulateMenu(popupMenu, uidFirstCmd + id);

	InsertMenu(hmenu, uMenuIndex++, MF_STRING | MF_BYPOSITION | MF_POPUP, (int)popupMenu, "Git Extensions");	
    return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, id-uidFirstCmd );
}
Beispiel #6
0
/** \brief Populate the top-level menu
 *
 * This method populates the top-level menu
 *
 */
void moMenuManager::PopulateMenus()
{
	PopulateMenu( "$/", f_mainPropBag );
}
Beispiel #7
0
/** \brief Populate a displayed menu
 *
 * This method peruses an array of menu items, calling the pure virtual methods
 * which the derived class should build a displayed menu.
 *
 * \param[in] path Path to this menu
 * \param[in] array An array of menu items
 *
 * \sa PopulateMenu
 */
void moMenuManager::PopulateMenu( const moWCString& path, moPropArrayRef array )
{
	const moNamePool& pool   = moNamePool::GetNamePool();
	const mo_name_t	menuName = pool.Get("Menu");
	const mo_name_t	itemName = pool.Get("Item");
	const mo_name_t sepName  = pool.Get("Separator");
	//const mo_name_t tbName   = pool.Get("Toolbar");

	unsigned long idx = 0;
	const unsigned long end = array.CountIndexes();

	for( ; idx < end; idx++ )
	{
		moPropSPtr		itemProp	= array.GetAtIndex( idx );
		moProp::prop_type_t	type		= itemProp->GetType();
		moName			name		= itemProp->GetName();
		mo_name_t		name_t		= (mo_name_t) name;

		switch( type )
		{
		case moProp::MO_PROP_TYPE_PROP_BAG:
		    {
			moPropBagRef	itemRef(name);
			itemRef.NewProp();
			itemRef.GetProperty()->Copy(*itemProp);

			moMenuItemSPtr	menu_item = new moMenuItem( itemRef );

			if( name_t == menuName )
			{
				// Signal menu start
				//
				Menu( path, menu_item );

				// Populate the menu
				//
				moWCString	item_name( menu_item->Value("Name") );
				moWCString	p = path + "/" + item_name;
				PopulateMenu( p, itemRef );

				// Signal menu finish
				//
				EndMenu( path, menu_item );
			}
			else if( name_t == itemName )
			{
				Item( path, menu_item );
			}
			else if( name_t == sepName )
			{
				menu_item->IsSeparator( true );
				Separator( path, menu_item );
			}
		    }
		    break;

		default:
		    std::cerr << "PopulateMenu(): Unsupported property type for this structure!" << std::endl;
		}
	}

}