STDMETHODIMP CMainFrame::UpdateProperty(UINT32 nCmdID, __in REFPROPERTYKEY key, __in_opt const PROPVARIANT *currentValue, __out PROPVARIANT *newValue) { // This function is called when a ribbon button is updated. // Refer to IUICommandHandler::UpdateProperty in the Windows 7 SDK documentation UNREFERENCED_PARAMETER(currentValue); HRESULT hr = E_NOTIMPL; if(UI_PKEY_Enabled == key) { return UIInitPropertyFromBoolean(UI_PKEY_Enabled, TRUE, newValue); } switch(nCmdID) { case IDC_MRULIST: // Set up the Most Recently Used (MRU) menu if (UI_PKEY_Label == key) { WCHAR label[MAX_PATH] = L"Recent Files"; hr = UIInitPropertyFromString(UI_PKEY_Label, label, newValue); } else if (UI_PKEY_RecentItems == key) { hr = PopulateRibbonRecentItems(newValue); } break; case IDC_PEN_COLOR: // Set the initial pen color hr = UIInitPropertyFromUInt32(key, RGB(1, 1, 1), newValue); break; } 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 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; }
IFACEMETHODIMP touchmind::ribbon::handler::LineColorCommandHandler::UpdateProperty( UINT cmdID, REFPROPERTYKEY key, const PROPVARIANT *pPropvarCurrentValue, PROPVARIANT *pPropvarNewValue) { LOG_ENTER; UNREFERENCED_PARAMETER(cmdID); UNREFERENCED_PARAMETER(key); UNREFERENCED_PARAMETER(pPropvarCurrentValue); UNREFERENCED_PARAMETER(pPropvarNewValue); HRESULT hr = E_FAIL; if (key == UI_PKEY_Enabled) { BOOL enabled = m_pRibbonRequestDispatcher->UpdateProperty_IsLineColorChangeable() ? TRUE : FALSE; m_pRibbonFramework->GetFramework()->InvalidateUICommand(cmdLineColor, UI_INVALIDATIONS_PROPERTY, &UI_PKEY_ColorType); m_pRibbonFramework->GetFramework()->InvalidateUICommand(cmdLineColor, UI_INVALIDATIONS_PROPERTY, &UI_PKEY_Color); m_pRibbonFramework->GetFramework()->InvalidateUICommand(cmdLineColor, UI_INVALIDATIONS_PROPERTY, &UI_PKEY_LargeImage); hr = UIInitPropertyFromBoolean(UI_PKEY_BooleanValue, enabled, pPropvarNewValue); } else if (key == UI_PKEY_ColorType) { hr = UIInitPropertyFromUInt32(key, UI_SWATCHCOLORTYPE_RGB, pPropvarNewValue); } else if (key == UI_PKEY_Color) { if (pPropvarCurrentValue == nullptr) { hr = UIInitPropertyFromUInt32(key, RGB(0, 0, 0), pPropvarNewValue); } else { D2D1_COLOR_F colorF = m_pRibbonRequestDispatcher->UpdateProperty_GetLineColor(); COLORREF colorref = touchmind::util::ColorUtil::ToColorref(colorF); hr = UIInitPropertyFromUInt32(key, colorref, pPropvarNewValue); } } else if (key == UI_PKEY_LargeImage) { if (pPropvarCurrentValue != nullptr) { CComPtr<IUIImage> uiImage = nullptr; D2D1_COLOR_F colorF = m_pRibbonRequestDispatcher->UpdateProperty_GetLineColor(); hr = _CreateUIImage(colorF, &uiImage); CHK_RES(uiImage, S_OK); if (SUCCEEDED(hr)) { hr = UIInitPropertyFromImage(key, uiImage, pPropvarNewValue); } } } LOG_LEAVE; return hr; }
STDMETHODIMP CNativeRibbonApp::UpdateProperty(UINT32 commandId, REFPROPERTYKEY key, const PROPVARIANT* /*currentValue*/, PROPVARIANT* newValue) { if (key == UI_PKEY_TooltipTitle) { CString str; if (!str.LoadString(commandId)) return S_FALSE; int nIndex = str.Find(L'\n'); if (nIndex <= 0) return S_FALSE; str = str.Mid(nIndex + 1); CString strLabel; if (m_pFrame != NULL && (CKeyboardManager::FindDefaultAccelerator(commandId, strLabel, m_pFrame, TRUE) || CKeyboardManager::FindDefaultAccelerator(commandId, strLabel, m_pFrame->GetActiveFrame(), FALSE))) { str += _T(" ("); str += strLabel; str += _T(')'); } return UIInitPropertyFromString(UI_PKEY_TooltipTitle, str, newValue); } else if (key == UI_PKEY_TooltipDescription) { CString str; if (!str.LoadString(commandId)) return S_FALSE; int nIndex = str.Find(L'\n'); if (nIndex <= 0) return S_FALSE; str = str.Left(nIndex); return UIInitPropertyFromString(UI_PKEY_TooltipDescription, str, newValue); } else if (key == UI_PKEY_Enabled) { CRibbonCmdUI ui(commandId); ui.DoUpdate(m_pFrame, TRUE); return UIInitPropertyFromBoolean(UI_PKEY_Enabled, ui.m_bOn, newValue); } else if (key == UI_PKEY_BooleanValue) { CRibbonCmdUI ui(commandId); ui.DoUpdate(m_pFrame, TRUE); return UIInitPropertyFromBoolean(UI_PKEY_BooleanValue, ui.m_nCheck, newValue); } else if (key == UI_PKEY_SelectedItem) { CComPtr<IUICollection> items = GetUICommandItemsSource(commandId); if (!items) return E_FAIL; UINT32 count; items->GetCount(&count); for (UINT32 idx = 0; idx < count; idx++) { CComPtr<IUnknown> item; items->GetItem(idx, &item); CComQIPtr<IUISimplePropertySet> simplePropertySet(item); if (simplePropertySet) { PROPVARIANT var = { 0 }; UINT32 uiVal; simplePropertySet->GetValue(UI_PKEY_CommandId, &var); UIPropertyToUInt32(UI_PKEY_CommandId, var, &uiVal); CRibbonCmdUI ui(uiVal); ui.DoUpdate(m_pFrame, TRUE); if (ui.m_nCheck) { UIInitPropertyFromUInt32(UI_PKEY_SelectedItem, idx, newValue); return S_OK; } } } // No selected item. UIInitPropertyFromUInt32(UI_PKEY_SelectedItem, static_cast<UINT>(-1), newValue); return S_OK; } return E_NOTIMPL; }