//
//  FUNCTION: UpdateProperty()
//
//  PURPOSE: Called by the Ribbon framework when a command property (PKEY) needs to be updated.
//
//  COMMENTS:
//
//    This function is used to initialize the contents and selection of the gallery.
//
//
STDMETHODIMP CLayoutHandler::UpdateProperty(UINT nCmdID,
                              __in REFPROPERTYKEY key,
                              __in_opt const PROPVARIANT* ppropvarCurrentValue,
                              __out PROPVARIANT* ppropvarNewValue)
{
    UNREFERENCED_PARAMETER(nCmdID);

    HRESULT hr = E_FAIL;

    if (key == UI_PKEY_ItemsSource)
    {
        IUICollection* pCollection;
        hr = ppropvarCurrentValue->punkVal->QueryInterface(IID_PPV_ARGS(&pCollection));
        if (FAILED(hr))
        {
            pCollection->Release();
            return hr;
        }

        int labelIds[] = {IDS_LAYOUT_1, IDS_LAYOUT_2, IDS_LAYOUT_3};

        // Populate the combobox with the three layout options.
        for (int i=0; i<_countof(labelIds); i++)
        {
            // Create a new property set for each item.
            CPropertySet* pItem;
            hr = CPropertySet::CreateInstance(&pItem);
            if (FAILED(hr))
            {
                pCollection->Release();
                return hr;
            }
  
            // Load the label from the resource file.
            WCHAR wszLabel[MAX_RESOURCE_LENGTH];
            LoadString(GetModuleHandle(NULL), labelIds[i], wszLabel, MAX_RESOURCE_LENGTH);

            // Initialize the property set with no image, the label that was just loaded, and no category.
            pItem->InitializeItemProperties(NULL, wszLabel, UI_COLLECTION_INVALIDINDEX);

            pCollection->Add(pItem);
        }
        pCollection->Release();
        hr = S_OK;
    }
    else if (key == UI_PKEY_Categories)
    {
        // A return value of S_FALSE or E_NOTIMPL will result in a gallery with no categories.
        // If you return any error other than E_NOTIMPL, the contents of the gallery will not display.
        hr = S_FALSE;
    }
    else if (key == UI_PKEY_SelectedItem)
    {
        // Use the first layout as the default selection.
        hr = UIInitPropertyFromUInt32(UI_PKEY_SelectedItem, 0, ppropvarNewValue);
    }
    return hr;
}
Ejemplo n.º 2
0
//
//  FUNCTION: UpdateProperty()
//
//  PURPOSE: Called by the Ribbon framework when a command property (PKEY) needs to be updated.
//
//  COMMENTS:
//
//    This function is used to populate the gallery.
//
//
STDMETHODIMP CNewDocumentHandler::UpdateProperty(UINT nCmdID,
                              __in REFPROPERTYKEY key,
                              __in_opt const PROPVARIANT* ppropvarCurrentValue,
                              __out PROPVARIANT* ppropvarNewValue)
{
    HRESULT hr = S_FALSE;
	
    if (key == UI_PKEY_ItemsSource)
    {
		objectTypes.clear();
	    IUICollection* pCollection;
        hr = ppropvarCurrentValue->punkVal->QueryInterface( 
                                                      IID_PPV_ARGS(&pCollection));
        
		pCollection->Clear();

		Array docTypes = getAllConcreteDocumentTypes();
		for(int i=0; i<docTypes.size(); i++){
			Object doc = docTypes[i].getObject();
			objectTypes.push_back(doc);
			// Create a new property set for each item.
			CPropertySet* pItem;
			hr = CPropertySet::CreateInstance(&pItem);
        
			string key = doc["label"].getString();
			wstring wkey = s2ws(key);
		
			// Load the label from the resource file.
			WCHAR wszLabel[MAX_RESOURCE_LENGTH];
			wcscpy_s(wszLabel, MAX_RESOURCE_LENGTH, wkey.c_str());
            
			IUIImage* pImg;
			MAKEINTRESOURCE(IDR_SMALL_ADD_BITMAP);

			HRESULT a = CreateUIImageFromBitmapResource(MAKEINTRESOURCE(IDR_SMALL_ADD_BITMAP), &pImg);


			// Initialize the property set with no image, the label that was just
			// loaded, and no category.
			pItem->InitializeItemProperties(pImg, wszLabel, UI_COLLECTION_INVALIDINDEX);

			pCollection->Add(pItem);
        }
        
     
        pCollection->Release();
        hr = S_OK;
    }
    
    return hr;
}
//
//  FUNCTION: UpdateProperty()
//
//  PURPOSE: Called by the Ribbon framework when a command property (PKEY) needs to be updated.
//
//  COMMENTS:
//
//    This function is used to populate the gallery.
//
//
STDMETHODIMP CSizeAndColorHandler::UpdateProperty(UINT nCmdID,
                              __in REFPROPERTYKEY key,
                              __in_opt const PROPVARIANT* ppropvarCurrentValue,
                              __out PROPVARIANT* ppropvarNewValue)
{
    UNREFERENCED_PARAMETER(nCmdID);
    UNREFERENCED_PARAMETER(ppropvarNewValue);

    HRESULT hr = E_FAIL;

    if(key == UI_PKEY_Categories)
    {
        IUICollection* pCollection;
        hr = ppropvarCurrentValue->punkVal->QueryInterface(IID_PPV_ARGS(&pCollection));
        if (FAILED(hr))
        {
            return hr;
        }

        // Create a property set for the Size category.
        CPropertySet *pSize;
        hr = CPropertySet::CreateInstance(&pSize);
        if (FAILED(hr))
        {
            pCollection->Release();
            return hr;
        }

        // Load the label for the Size category from the resource file.
        WCHAR wszSizeLabel[MAX_RESOURCE_LENGTH];
        LoadString(GetModuleHandle(NULL), IDS_SIZE_CATEGORY, wszSizeLabel, MAX_RESOURCE_LENGTH);

        // Initialize the property set with the label that was just loaded and a category id of 0.
        pSize->InitializeCategoryProperties(wszSizeLabel, 0);

        // Add the newly-created property set to the collection supplied by the framework.
        pCollection->Add(pSize);

        pSize->Release();


        // Create a property set for the Color category.
        CPropertySet *pColor;
        hr = CPropertySet::CreateInstance(&pColor);
        if (FAILED(hr))
        {
            pCollection->Release();
            return hr;
        }

        // Load the label for the Color category from the resource file.
        WCHAR wszColorLabel[MAX_RESOURCE_LENGTH];
        LoadString(GetModuleHandle(NULL), IDS_COLOR_CATEGORY, wszColorLabel, MAX_RESOURCE_LENGTH);

        // Initialize the property set with the label that was just loaded and a category id of 1.
        pColor->InitializeCategoryProperties(wszColorLabel, 1);
        
        // Add the newly-created property set to the collection supplied by the framework.
        pCollection->Add(pColor);

        pColor->Release();
        pCollection->Release();

        hr = S_OK;
    }
    else if(key == UI_PKEY_ItemsSource)
    {
        IUICollection* pCollection;
        hr = ppropvarCurrentValue->punkVal->QueryInterface(IID_PPV_ARGS(&pCollection));
        if (FAILED(hr))
        {
            return hr;
        }

        int commandIds[] = {IDR_CMD_SMALL, IDR_CMD_MEDIUM, IDR_CMD_LARGE, IDR_CMD_RED, IDR_CMD_GREEN, IDR_CMD_BLUE};
        int categoryIds[] = {0, 0, 0, 1, 1, 1};

        // Populate the gallery with the three size and three colors in two separate categories.
        for (int i=0; i<_countof(commandIds); i++)
        {
            // Create a new property set for each item.
            CPropertySet* pCommand;
            hr = CPropertySet::CreateInstance(&pCommand);
            if (FAILED(hr))
            {
                pCollection->Release();
                return hr;
            }

            // Initialize the property set with the appropriate command id and category id and type Boolean (which makes these appear as ToggleButtons).
            pCommand->InitializeCommandProperties(categoryIds[i], commandIds[i], UI_COMMANDTYPE_BOOLEAN);

            // Add the newly-created property set to the collection supplied by the framework.
            pCollection->Add(pCommand);

            pCommand->Release();
        }
        pCollection->Release();
        hr = S_OK;
    }
    return hr;
}