/3rd_party/wtl/Include/atlribbon.h
https://code.google.com/p/softart/ · C++ Header · 3446 lines · 2686 code · 533 blank · 227 comment · 430 complexity · c9eaf028c94020793111b9ac5f0efb9e MD5 · raw file
Large files are truncated click here to view the full file
- // Windows Template Library - WTL version 8.1
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //
- // This file is a part of the Windows Template Library.
- // The use and distribution terms for this software are covered by the
- // Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
- // which can be found in the file CPL.TXT at the root of this distribution.
- // By using this software in any fashion, you are agreeing to be bound by
- // the terms of this license. You must not remove this notice, or
- // any other, from this software.
-
- #ifndef __ATLRIBBON_H__
- #define __ATLRIBBON_H__
-
- #pragma once
-
- #if (_MSC_VER < 1500)
- #error atlribbon.h requires Visual C++ 2008 compiler or higher
- #endif
-
- #ifndef _UNICODE
- #error atlribbon.h requires the Unicode character set
- #endif
-
- #if !defined(NTDDI_WIN7) || (NTDDI_VERSION < NTDDI_WIN7)
- #error atlribbon.h requires the Windows 7 SDK or higher
- #endif
-
- #ifdef _WIN32_WCE
- #error atlribbon.h is not supported on Windows CE
- #endif
-
- #ifndef __ATLAPP_H__
- #error atlribbon.h requires atlapp.h to be included first
- #endif
-
- #if (_ATL_VER < 0x0700)
- #include <shlwapi.h>
- #pragma comment(lib, "shlwapi.lib")
- #endif
-
- #include <atlmisc.h> // for RecentDocumentList classes
- #include <atlframe.h> // for Frame and UpdateUI classes
- #include <atlctrls.h> // required for atlctrlw.h
- #include <atlctrlw.h> // for CCommandBarCtrl
-
- #if !defined(_WTL_USE_CSTRING) && !defined(__ATLSTR_H__)
- #pragma warning(disable : 4530) // unwind semantics not enabled
- #include <string>
- #pragma warning(default : 4530)
- #endif
-
- #include <dwmapi.h>
- #pragma comment(lib, "dwmapi.lib")
-
- #include <UIRibbon.h>
- #include <UIRibbonPropertyHelpers.h>
- #pragma comment(lib, "propsys.lib")
-
- #include <Richedit.h> // for CHARFORMAT2
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // Classes in this file:
- //
- // CRibbonUpdateUI : Automatic mapping of ribbon UI elements
- //
- // RibbonUI::Text
- // RibbonUI::CharFormat
- // RibbonUI::ICtrl
- // RibbonUI::CtrlImpl
- // RibbonUI::CommandCtrlImpl
- // RibbonUI::ItemProperty
- // RibbonUI::CollectionImplBase
- // RibbonUI::CollectionImpl
- // RibbonUI::TextCollectionImpl
- // RibbonUI::ItemCollectionImpl
- // RibbonUI::ComboCollectionImpl
- // RibbonUI::CommandCollectionImpl
- // RibbonUI::ToolbarCollectionImpl
- // RibbonUI::SimpleCollectionImpl
- // RibbonUI::CollectionCtrlImpl
- // RibbonUI::ToolbarGalleryCtrlImpl
- // RibbonUI::SimpleCollectionCtrlImpl
- // RibbonUI::RecentItemsCtrlImpl
- // RibbonUI::FontCtrlImpl
- // RibbonUI::ColorCtrlImpl
- // RibbonUI::SpinnerCtrlImpl
- //
- // RibbonUI::CRibbonImpl
- // CRibbonImpl::CRibbonComboCtrl
- // CRibbonImpl::CRibbonItemGalleryCtrl
- // CRibbonImpl::CRibbonCommandGalleryCtrl
- // CRibbonImpl::CRibbonToolbarGalleryCtrl
- // CRibbonImpl::CRibbonSimpleComboCtrl
- // CRibbonImpl::CRibbonSimpleGalleryCtrl
- // CRibbonImpl::CRibbonRecentItemsCtrl
- // CRibbonImpl::CRibbonColorCtrl
- // CRibbonImpl::CRibbonFontCtrl
- // CRibbonImpl::CRibbonSpinnerCtrl
- // CRibbonImpl::CRibbonFloatSpinnerCtrl
- // CRibbonImpl::CRibbonCommandCtrl
- //
- // CRibbonFrameWindowImplBase
- // CRibbonFrameWindowImpl
- // CRibbonMDIFrameWindowImpl
- // CRibbonPersist
- //
- // Global functions:
- // RibbonUI::SetPropertyVal()
- // RibbonUI::GetImage()
-
-
- // Constants
-
- #ifndef RIBBONUI_MAX_TEXT
- #define RIBBONUI_MAX_TEXT 128
- #endif
-
- #define TWIPS_PER_POINT 20 // For font size
-
-
- namespace WTL
- {
-
- ///////////////////////////////////////////////////////////////////////////////
- // CRibbonUpdateUI : Automatic mapping of ribbon UI elements
-
- template <class T>
- class CRibbonUpdateUI : public CAutoUpdateUI<T>
- {
- public:
- enum
- {
- UPDUI_RIBBON = 0x0080,
- UPDUI_PERSIST = 0x0020
- };
-
- bool IsRibbonElement(const _AtlUpdateUIMap& UIMap)
- {
- return (UIMap.m_wType & UPDUI_RIBBON) != 0;
- }
-
- bool IsRibbonID(UINT nID)
- {
- for(int i = 0; i < m_arrUIMap.GetSize(); i++)
- {
- if(m_arrUIMap[i].m_nID == nID)
- return IsRibbonElement(m_arrUIMap[i]);
- }
-
- return false;
- }
-
- // Element
- bool UIAddRibbonElement(UINT nID)
- {
- return UIAddElement<UPDUI_RIBBON>(nID);
- }
-
- bool UIRemoveRibbonElement(UINT nID)
- {
- return UIRemoveElement<UPDUI_RIBBON>(nID);
- }
-
- bool UIPersistElement(UINT nID, bool bPersist = true)
- {
- return bPersist ?
- UIAddElement<UPDUI_PERSIST>(nID) :
- UIRemoveElement<UPDUI_PERSIST>(nID);
- }
-
- // methods for Ribbon elements
- BOOL UISetText(int nID, LPCWSTR sText, BOOL bForceUpdate = FALSE)
- {
- T* pT = static_cast<T*>(this);
- BOOL bRes = CUpdateUIBase::UISetText(nID, sText, bForceUpdate);
- if (pT->IsRibbonUI() && IsRibbonID(nID))
- bRes = SUCCEEDED(pT->InvalidateProperty(nID, UI_PKEY_Label));
- return bRes;
- }
-
- BOOL UISetText(int nID, UINT uIdResource, BOOL bForceUpdate = FALSE)
- {
- CTempBuffer<WCHAR> sText(RIBBONUI_MAX_TEXT);
- return AtlLoadString(uIdResource, sText, RIBBONUI_MAX_TEXT) ?
- UISetText(nID, sText, bForceUpdate) :
- E_FAIL;
- }
-
- LPCTSTR UIGetText(int nID)
- {
- T* pT = static_cast<T*>(this);
- LPCTSTR sUI = CAutoUpdateUI::UIGetText(nID);
-
- // replace 'tab' by 'space' for RibbonUI elements
- if (sUI && pT->IsRibbonUI() && IsRibbonID(nID) && wcschr(sUI, L'\t'))
- {
- static WCHAR sText[RIBBONUI_MAX_TEXT] = { 0 };
- wcscpy_s(sText, sUI);
- *wcschr(sText, L'\t') = L' ';
- return sText;
- }
- else
- {
- return sUI;
- }
- }
-
- BOOL UIEnable(int nID, BOOL bEnable, BOOL bForceUpdate = FALSE)
- {
- T* pT = static_cast<T*>(this);
- BOOL bRes = CUpdateUIBase::UIEnable(nID, bEnable, bForceUpdate);
- if (pT->IsRibbonUI() && IsRibbonID(nID))
- bRes = SUCCEEDED(pT->SetProperty((WORD)nID, UI_PKEY_Enabled, bEnable));
- return bRes;
- }
-
- BOOL UISetCheck(int nID, INT nCheck, BOOL bForceUpdate = FALSE)
- {
- if ((nCheck == 0) || (nCheck == 1))
- return UISetCheck(nID, nCheck != 0, bForceUpdate);
- else
- return CUpdateUIBase::UISetCheck(nID, nCheck, bForceUpdate);
- }
-
- BOOL UISetCheck(int nID, bool bCheck, BOOL bForceUpdate = FALSE)
- {
- T* pT = static_cast<T*>(this);
- BOOL bRes = CUpdateUIBase::UISetCheck(nID, bCheck, bForceUpdate);
- if (bRes && pT->IsRibbonUI() && IsRibbonID(nID))
- bRes = SUCCEEDED(pT->SetProperty((WORD)nID, UI_PKEY_BooleanValue, bCheck));
- return bRes;
- }
- };
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // RibbonUI namespace
- //
-
- namespace RibbonUI
- {
-
- // Minimal string allocation support for various PROPERTYKEY values
- #if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
- typedef _CSTRING_NS::CString Text;
- #else
- class Text : public std::wstring
- {
- public:
- Text(std::wstring& s) : std::wstring(s)
- { }
- Text(LPCWSTR s) : std::wstring(s)
- { }
- Text()
- { }
- bool IsEmpty()
- {
- return empty();
- }
- operator LPCWSTR()
- {
- return c_str();
- }
- Text& operator =(LPCWSTR s)
- {
- return static_cast<Text&>(std::wstring::operator =(s));
- }
- };
- #endif
-
- // PROPERTYKEY enum and helpers
- enum k_KEY
- {
- // state
- k_Enabled = 1, k_BooleanValue = 200,
- // text properties
- k_LabelDescription = 2, k_Keytip = 3, k_Label = 4, k_TooltipDescription = 5, k_TooltipTitle = 6,
- // image properties
- k_LargeImage = 7, k_LargeHighContrastImage = 8, k_SmallImage = 9, k_SmallHighContrastImage = 10,
- // collection properties
- k_ItemsSource = 101, k_Categories = 102, k_SelectedItem = 104,
- // collection item properties
- k_CommandId = 100, k_CategoryId = 103, k_CommandType = 105, k_ItemImage = 106,
- // combo control property
- k_StringValue = 202,
- // spinner control properties
- k_DecimalValue = 201, k_MaxValue = 203, k_MinValue, k_Increment, k_DecimalPlaces, k_FormatString, k_RepresentativeString = 208,
- // font control properties
- k_FontProperties = 300, k_FontProperties_Family, k_FontProperties_Size, k_FontProperties_Bold, k_FontProperties_Italic = 304,
- k_FontProperties_Underline = 305, k_FontProperties_Strikethrough, k_FontProperties_VerticalPositioning, k_FontProperties_ForegroundColor = 308,
- k_FontProperties_BackgroundColor = 309, k_FontProperties_ForegroundColorType, k_FontProperties_BackgroundColorType, k_FontProperties_ChangedProperties = 312,
- k_FontProperties_DeltaSize = 313,
- // recent items properties
- k_RecentItems = 350, k_Pinned = 351,
- // color control properties
- k_Color = 400, k_ColorType = 401, k_ColorMode,
- k_ThemeColorsCategoryLabel = 403, k_StandardColorsCategoryLabel, k_RecentColorsCategoryLabel = 405, k_AutomaticColorLabel = 406,
- k_NoColorLabel = 407, k_MoreColorsLabel = 408,
- k_ThemeColors = 409, k_StandardColors = 410, k_ThemeColorsTooltips = 411, k_StandardColorsTooltips = 412,
- // Ribbon state
- k_Viewable = 1000, k_Minimized = 1001, k_QuickAccessToolbarDock = 1002, k_ContextAvailable = 1100,
- // Ribbon UI colors
- k_GlobalBackgroundColor = 2000, k_GlobalHighlightColor, k_GlobalTextColor = 2002
- };
-
- inline k_KEY k_(REFPROPERTYKEY key)
- {
- return (k_KEY)key.fmtid.Data1;
- }
-
- // PROPERTYKEY value assignment and specializations
- //
- template <typename V>
- HRESULT SetPropertyVal(REFPROPERTYKEY key, V val, PROPVARIANT* ppv)
- {
- switch (k_(key))
- {
- case k_Enabled:
- case k_BooleanValue:
- return InitPropVariantFromBoolean(val, ppv);
- default:
- return UIInitPropertyFromUInt32(key, val, ppv);
- }
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, DOUBLE val, PROPVARIANT* ppv)
- {
- return SetPropertyVal(key, (LONG)val, ppv);
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, IUIImage* val, PROPVARIANT* ppv)
- {
- HRESULT hr = UIInitPropertyFromImage(key, val, ppv);
- ATLVERIFY(val->Release() == 1);
- return hr;
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, IUnknown* val, PROPVARIANT* ppv)
- {
- return UIInitPropertyFromInterface(key, val, ppv);
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, IPropertyStore* val, PROPVARIANT* ppv)
- {
- return UIInitPropertyFromInterface(key, val, ppv);
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, SAFEARRAY* val, PROPVARIANT* ppv)
- {
- return UIInitPropertyFromIUnknownArray(key, val, ppv);
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, DECIMAL* val, PROPVARIANT* ppv)
- {
- return UIInitPropertyFromDecimal(key, *val, ppv);
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, bool val, PROPVARIANT* ppv)
- {
- return UIInitPropertyFromBoolean(key, val, ppv);
- }
-
- inline HRESULT SetPropertyVal(REFPROPERTYKEY key, LPCWSTR val, PROPVARIANT* ppv)
- {
- return UIInitPropertyFromString(key, val, ppv);
- }
-
- // CharFormat helper struct for RibbonUI font control
- //
- struct CharFormat : CHARFORMAT2
- {
- // Default constructor
- CharFormat()
- {
- cbSize = sizeof CHARFORMAT2;
- Reset();
- }
-
- // Copy constructor
- CharFormat(const CharFormat& cf)
- {
- CopyMemory(this, &cf, sizeof CHARFORMAT2);
- }
-
- // Assign operator
- CharFormat& operator =(const CharFormat& cf)
- {
- CopyMemory(this, &cf, sizeof CHARFORMAT2);
- return (*this);
- }
-
- void Reset()
- {
- uValue = dwMask = dwEffects = 0;
- PropVariantInit(&propvar);
- }
-
- void operator <<(IPropertyStore* pStore)
- {
- if (pStore == NULL)
- {
- ATLASSERT(FALSE);
- return;
- }
-
- static void (CharFormat::*Getk_[])(IPropertyStore*) =
- {
- &CharFormat::Getk_Family,
- &CharFormat::Getk_FontProperties_Size,
- &CharFormat::Getk_MaskEffect<CFM_BOLD, CFE_BOLD, UI_PKEY_FontProperties_Bold>,
- &CharFormat::Getk_MaskEffect<CFM_ITALIC, CFE_ITALIC, UI_PKEY_FontProperties_Italic>,
- &CharFormat::Getk_MaskEffect<CFM_UNDERLINE, CFE_UNDERLINE, UI_PKEY_FontProperties_Underline>,
- &CharFormat::Getk_MaskEffect<CFM_STRIKEOUT, CFE_STRIKEOUT, UI_PKEY_FontProperties_Strikethrough>,
- &CharFormat::Getk_VerticalPositioning,
- &CharFormat::Getk_Color<CFM_COLOR, UI_PKEY_FontProperties_ForegroundColor>,
- &CharFormat::Getk_Color<CFM_BACKCOLOR, UI_PKEY_FontProperties_BackgroundColor>,
- &CharFormat::Getk_ColorType<CFM_COLOR, CFE_AUTOCOLOR, UI_SWATCHCOLORTYPE_AUTOMATIC, UI_PKEY_FontProperties_ForegroundColorType>,
- &CharFormat::Getk_ColorType<CFM_BACKCOLOR, CFE_AUTOBACKCOLOR, UI_SWATCHCOLORTYPE_NOCOLOR, UI_PKEY_FontProperties_BackgroundColorType>,
- };
-
- DWORD nProps = 0;
- Reset();
-
- ATLVERIFY(SUCCEEDED(pStore->GetCount(&nProps)));
- for (DWORD iProp = 0; iProp < nProps; iProp++)
- {
- PROPERTYKEY key;
- ATLVERIFY(SUCCEEDED(pStore->GetAt(iProp, &key)));
- ATLASSERT(k_(key) >= k_FontProperties_Family);
-
- if (k_(key) <= k_FontProperties_BackgroundColorType)
- (this->*Getk_[k_(key) - k_FontProperties_Family])(pStore);
- }
- }
-
- void operator >>(IPropertyStore* pStore)
- {
- if (pStore == NULL)
- {
- ATLASSERT(FALSE);
- return;
- }
-
- PutFace(pStore);
- PutSize(pStore);
- PutMaskEffect(CFM_BOLD, CFE_BOLD, UI_PKEY_FontProperties_Bold, pStore);
- PutMaskEffect(CFM_ITALIC, CFE_ITALIC, UI_PKEY_FontProperties_Italic, pStore);
- PutMaskEffect(CFM_UNDERLINE, CFE_UNDERLINE, UI_PKEY_FontProperties_Underline, pStore);
- PutMaskEffect(CFM_STRIKEOUT, CFE_STRIKEOUT, UI_PKEY_FontProperties_Strikethrough, pStore);
- PutVerticalPos(pStore);
- PutColor(pStore);
- PutBackColor(pStore);
- }
-
- private:
- PROPVARIANT propvar;
- UINT uValue;
-
- // Getk_ functions
- void Getk_Family(IPropertyStore* pStore)
- {
- if (SUCCEEDED(pStore->GetValue(UI_PKEY_FontProperties_Family, &propvar)))
- {
- PropVariantToString(propvar, szFaceName, LF_FACESIZE);
- if (*szFaceName)
- dwMask |= CFM_FACE;
- }
- }
-
- void Getk_FontProperties_Size(IPropertyStore* pStore)
- {
- if (SUCCEEDED(pStore->GetValue(UI_PKEY_FontProperties_Size, &propvar)))
- {
- DECIMAL decSize;
- UIPropertyToDecimal(UI_PKEY_FontProperties_Size, propvar, &decSize);
- DOUBLE dSize;
- VarR8FromDec(&decSize, &dSize);
- if (dSize > 0)
- {
- dwMask |= CFM_SIZE;
- yHeight = (LONG)(dSize * TWIPS_PER_POINT);
- }
- }
- }
-
- template <DWORD t_dwMask, DWORD t_dwEffects, REFPROPERTYKEY key>
- void Getk_MaskEffect(IPropertyStore* pStore)
- {
- if (SUCCEEDED(pStore->GetValue(key, &propvar)))
- {
- UIPropertyToUInt32(key, propvar, &uValue);
- if ((UI_FONTPROPERTIES)uValue != UI_FONTPROPERTIES_NOTAVAILABLE)
- {
- dwMask |= t_dwMask;
- dwEffects |= ((UI_FONTPROPERTIES) uValue == UI_FONTPROPERTIES_SET) ? t_dwEffects : 0;
- }
- }
- }
-
- void Getk_VerticalPositioning(IPropertyStore* pStore)
- {
- if (SUCCEEDED(pStore->GetValue(UI_PKEY_FontProperties_VerticalPositioning, &propvar)))
- {
- UIPropertyToUInt32(UI_PKEY_FontProperties_VerticalPositioning, propvar, &uValue);
- UI_FONTVERTICALPOSITION uVerticalPosition = (UI_FONTVERTICALPOSITION) uValue;
- if ((uVerticalPosition != UI_FONTVERTICALPOSITION_NOTAVAILABLE))
- {
- dwMask |= (CFM_SUPERSCRIPT | CFM_SUBSCRIPT);
- if (uVerticalPosition != UI_FONTVERTICALPOSITION_NOTSET)
- {
- dwEffects |= (uVerticalPosition == UI_FONTVERTICALPOSITION_SUPERSCRIPT) ? CFE_SUPERSCRIPT : CFE_SUBSCRIPT;
- }
- }
- }
- }
-
- template <DWORD t_dwMask, REFPROPERTYKEY key>
- void Getk_Color(IPropertyStore* pStore)
- {
- UINT32 color;
- if (SUCCEEDED(pStore->GetValue(key, &propvar)))
- {
- UIPropertyToUInt32(key, propvar, &color);
- dwMask |= t_dwMask;
-
- if (t_dwMask == CFM_COLOR)
- crTextColor = color;
- else
- crBackColor = color;
- }
- }
-
- template <DWORD t_dwMask, DWORD t_dwEffects, UI_SWATCHCOLORTYPE t_type, REFPROPERTYKEY key>
- void Getk_ColorType(IPropertyStore* pStore)
- {
- if (SUCCEEDED(pStore->GetValue(key, &propvar)))
- {
- UIPropertyToUInt32(key, propvar, &uValue);
- if (t_type == (UI_SWATCHCOLORTYPE)uValue)
- {
- dwMask |= t_dwMask;
- dwEffects |= t_dwEffects;
- }
- }
- }
-
- // Put functions
- void PutMaskEffect(WORD dwMaskVal, WORD dwEffectVal, REFPROPERTYKEY key, IPropertyStore* pStore)
- {
- PROPVARIANT propvar;
- UI_FONTPROPERTIES uProp = UI_FONTPROPERTIES_NOTAVAILABLE;
- if ((dwMask & dwMaskVal) != 0)
- uProp = dwEffects & dwEffectVal ? UI_FONTPROPERTIES_SET : UI_FONTPROPERTIES_NOTSET;
- SetPropertyVal(key, uProp, &propvar);
- pStore->SetValue(key, propvar);
- }
-
- void PutVerticalPos(IPropertyStore* pStore)
- {
- PROPVARIANT propvar;
- UI_FONTVERTICALPOSITION uProp = UI_FONTVERTICALPOSITION_NOTAVAILABLE;
-
- if ((dwMask & CFE_SUBSCRIPT) != 0)
- {
- if ((dwMask & CFM_SUBSCRIPT) && (dwEffects & CFE_SUBSCRIPT))
- uProp = UI_FONTVERTICALPOSITION_SUBSCRIPT;
- else
- uProp = UI_FONTVERTICALPOSITION_SUPERSCRIPT;
- }
- else if ((dwMask & CFM_OFFSET) != 0)
- {
- if (yOffset > 0)
- uProp = UI_FONTVERTICALPOSITION_SUPERSCRIPT;
- else if (yOffset < 0)
- uProp = UI_FONTVERTICALPOSITION_SUBSCRIPT;
- }
-
- SetPropertyVal(UI_PKEY_FontProperties_VerticalPositioning, uProp, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_VerticalPositioning, propvar);
- }
-
- void PutFace(IPropertyStore* pStore)
- {
- PROPVARIANT propvar;
- SetPropertyVal(UI_PKEY_FontProperties_Family,
- dwMask & CFM_FACE ? szFaceName : L"", &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_Family, propvar);
- }
-
- void PutSize(IPropertyStore* pStore)
- {
- PROPVARIANT propvar;
- DECIMAL decVal;
-
- if ((dwMask & CFM_SIZE) != 0)
- VarDecFromR8((DOUBLE)yHeight / TWIPS_PER_POINT, &decVal);
- else
- VarDecFromI4(0, &decVal);
-
- SetPropertyVal(UI_PKEY_FontProperties_Size, &decVal, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_Size, propvar);
- }
-
- void PutColor(IPropertyStore* pStore)
- {
- if ((dwMask & CFM_COLOR) != 0)
- if ((dwEffects & CFE_AUTOCOLOR) == 0)
- {
- SetPropertyVal(UI_PKEY_FontProperties_ForegroundColorType, UI_SWATCHCOLORTYPE_RGB, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_ForegroundColorType, propvar);
-
- SetPropertyVal(UI_PKEY_FontProperties_ForegroundColor, crTextColor, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_ForegroundColor, propvar);
- }
- else
- {
- SetPropertyVal(UI_PKEY_FontProperties_ForegroundColorType, UI_SWATCHCOLORTYPE_AUTOMATIC, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_ForegroundColorType, propvar);
- }
- }
-
- void PutBackColor(IPropertyStore* pStore)
- {
- if (((dwMask & CFM_BACKCOLOR) != 0) && ((dwEffects & CFE_AUTOBACKCOLOR) == 0))
- {
- SetPropertyVal(UI_PKEY_FontProperties_BackgroundColorType, UI_SWATCHCOLORTYPE_RGB, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_BackgroundColorType, propvar);
-
- SetPropertyVal(UI_PKEY_FontProperties_BackgroundColor, crBackColor, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_BackgroundColor, propvar);
- }
- else
- {
- SetPropertyVal(UI_PKEY_FontProperties_BackgroundColorType, UI_SWATCHCOLORTYPE_NOCOLOR, &propvar);
- pStore->SetValue(UI_PKEY_FontProperties_BackgroundColorType, propvar);
- }
- }
- };
-
- // IUIImage helper
- //
- inline IUIImage* GetImage(HBITMAP hbm, UI_OWNERSHIP owner)
- {
- ATLASSERT(hbm);
- IUIImage* pIUII = NULL;
- ATL::CComPtr<IUIImageFromBitmap> pIFB;
-
- if SUCCEEDED(pIFB.CoCreateInstance(CLSID_UIRibbonImageFromBitmapFactory))
- ATLVERIFY(SUCCEEDED(pIFB->CreateImage(hbm, owner, &pIUII)));
-
- return pIUII;
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // Ribbon control classes
-
- // RibbonUI::ICtrl abstract interface of RibbonUI::CRibbonImpl and all RibbonUI control classes
- //
- struct ICtrl
- {
- virtual HRESULT DoExecute(UINT nCmdID, UI_EXECUTIONVERB verb,
- const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue,
- IUISimplePropertySet* pCommandExecutionProperties) = 0;
-
- virtual HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue) = 0;
- };
-
- // RibbonUI::CtrlImpl base class for all ribbon controls
- //
- template <class T, UINT t_ID>
- class ATL_NO_VTABLE CtrlImpl : public ICtrl
- {
- protected:
- T* m_pWndRibbon;
-
- public:
- typedef T WndRibbon;
-
- CtrlImpl() : m_pWndRibbon(T::pWndRibbon)
- { }
-
- WndRibbon& GetWndRibbon()
- {
- return *m_pWndRibbon;
- }
-
- static WORD GetID()
- {
- return t_ID;
- }
-
- Text m_sTxt[5];
-
- // Operations
- HRESULT Invalidate()
- {
- return GetWndRibbon().InvalidateCtrl(GetID());
- }
-
- HRESULT Invalidate(REFPROPERTYKEY key, UI_INVALIDATIONS flags = UI_INVALIDATIONS_PROPERTY)
- {
- return GetWndRibbon().InvalidateProperty(GetID(), key, flags);
- }
-
- HRESULT SetText(REFPROPERTYKEY key, LPCWSTR sTxt, bool bUpdate = false)
- {
- ATLASSERT((k_(key) <= k_TooltipTitle) && (k_(key) >= k_LabelDescription));
-
- m_sTxt[k_(key) - k_LabelDescription] = sTxt;
-
- return bUpdate ?
- GetWndRibbon().InvalidateProperty(GetID(), key) :
- S_OK;
- }
-
- // Implementation
- template <typename V>
- HRESULT SetProperty(REFPROPERTYKEY key, V val)
- {
- return GetWndRibbon().SetProperty(GetID(), key, val);
- }
-
- HRESULT OnGetText(REFPROPERTYKEY key, PROPVARIANT* ppv)
- {
- ATLASSERT((k_(key) <= k_TooltipTitle) && (k_(key) >= k_LabelDescription));
-
- const INT iText = k_(key) - k_LabelDescription;
- if (m_sTxt[iText].IsEmpty())
- if (LPCWSTR sText = GetWndRibbon().OnRibbonQueryText(GetID(), key))
- m_sTxt[iText] = sText;
-
- return !m_sTxt[iText].IsEmpty() ?
- SetPropertyVal(key, (LPCWSTR)m_sTxt[iText], ppv) :
- S_OK;
- }
-
- virtual HRESULT DoExecute(UINT nCmdID, UI_EXECUTIONVERB verb,
- const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue,
- IUISimplePropertySet* pCommandExecutionProperties)
- {
- ATLASSERT(nCmdID == t_ID);
- return GetWndRibbon().DoExecute(nCmdID, verb, key, ppropvarValue, pCommandExecutionProperties);
- }
-
- virtual HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue)
- {
- ATLASSERT(nCmdID == t_ID);
-
- const INT iMax = k_TooltipTitle - k_LabelDescription;
- const INT iVal = k_(key) - k_LabelDescription;
-
- return (iVal <= iMax) && (iVal >= 0) ?
- OnGetText(key, ppropvarNewValue) :
- GetWndRibbon().DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
- }
- };
-
- // CommandCtrlImpl base class for most ribbon controls
- //
- template <class T, UINT t_ID>
- class CommandCtrlImpl : public CtrlImpl<T, t_ID>
- {
- public:
- CBitmap m_hbm[4];
-
- HRESULT SetImage(REFPROPERTYKEY key, HBITMAP hbm, bool bUpdate = false)
- {
- ATLASSERT((k_(key) <= k_SmallHighContrastImage) && (k_(key) >= k_LargeImage));
-
- m_hbm[k_(key) - k_LargeImage].Attach(hbm);
-
- return bUpdate ?
- GetWndRibbon().InvalidateProperty(GetID(), key) :
- S_OK;
- }
-
- HRESULT OnGetImage(REFPROPERTYKEY key, PROPVARIANT* ppv)
- {
- ATLASSERT((k_(key) <= k_SmallHighContrastImage) && (k_(key) >= k_LargeImage));
-
- const INT iImage = k_(key) - k_LargeImage;
-
- if (m_hbm[iImage].IsNull())
- m_hbm[iImage] = GetWndRibbon().OnRibbonQueryImage(GetID(), key);
-
- return m_hbm[iImage].IsNull() ?
- E_NOTIMPL :
- SetPropertyVal(key, GetImage(m_hbm[iImage], UI_OWNERSHIP_COPY), ppv);
- }
-
- virtual HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue)
- {
- ATLASSERT (nCmdID == GetID());
-
- return (k_(key) <= k_SmallHighContrastImage) && (k_(key) >= k_LargeImage) ?
- OnGetImage(key, ppropvarNewValue) :
- CtrlImpl::DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
- }
- };
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // Ribbon collection base classes
-
- // ItemProperty class: ribbon callback for each item in a collection
- //
- template <class TCollection>
- class ItemProperty : public IUISimplePropertySet
- {
- public:
- ItemProperty(UINT i, TCollection* pCollection) : m_Index(i), m_pCollection(pCollection)
- { }
-
- const UINT m_Index;
- TCollection* m_pCollection;
-
- // IUISimplePropertySet method.
- STDMETHODIMP GetValue(REFPROPERTYKEY key, PROPVARIANT *value)
- {
- return m_pCollection->OnGetItem(m_Index, key, value);
- }
-
- // IUnknown methods.
- STDMETHODIMP_(ULONG) AddRef()
- {
- return 1;
- }
-
- STDMETHODIMP_(ULONG) Release()
- {
- return 1;
- }
-
- STDMETHODIMP QueryInterface(REFIID iid, void** ppv)
- {
- if ((iid == __uuidof(IUnknown)) || (iid == __uuidof(IUISimplePropertySet)))
- {
- *ppv = this;
- return S_OK;
- }
- else
- {
- return E_NOINTERFACE;
- }
- }
- };
-
-
- // CollectionImplBase: base class for all RibbonUI collections
- //
- template <class TCollection, size_t t_size>
- class CollectionImplBase
- {
- typedef CollectionImplBase<TCollection, t_size> thisClass;
-
- public:
- CollectionImplBase()
- {
- for (int i = 0; i < t_size; i++)
- m_apItems[i] = new ItemProperty<TCollection>(i, static_cast<TCollection*>(this));
- }
-
- ~CollectionImplBase()
- {
- for (int i = 0; i < t_size; i++)
- delete m_apItems[i];
- }
-
- // Data members
- ItemProperty<TCollection>* m_apItems[t_size];
- };
-
- // CollectionImpl: handles categories and collecton resizing
- //
- template <class TCtrl, size_t t_items, size_t t_categories>
- class CollectionImpl : public CollectionImplBase<CollectionImpl<TCtrl, t_items, t_categories>, t_items + t_categories>
- {
- typedef CollectionImpl<TCtrl, t_items, t_categories> thisClass;
- public:
- typedef thisClass Collection;
-
- CollectionImpl() : m_size(t_items)
- {
- FillMemory(m_auItemCat, sizeof m_auItemCat, 0xff); // UI_COLLECTION_INVALIDINDEX
- }
-
- UINT32 m_auItemCat[t_items];
- Text m_asCatName[max(t_categories, 1)];
- size_t m_size;
-
- // Operations
- HRESULT SetItemCategory(UINT uItem, UINT uCat, bool bUpdate = false)
- {
- ATLASSERT((uItem < t_items) && (uCat < t_categories));
-
- m_auItemCat[uItem] = uCat;
-
- return bUpdate ? InvalidateItems() : S_OK;
- }
-
- HRESULT SetCategoryText(UINT uCat, LPCWSTR sText, bool bUpdate = false)
- {
- ATLASSERT(uCat < t_categories);
-
- m_asCatName[uCat] = sText;
-
- return bUpdate ? InvalidateCategories() : S_OK;
- }
-
- HRESULT Resize(size_t size, bool bUpdate = false)
- {
- ATLASSERT(size <= t_items);
-
- m_size = size;
-
- return bUpdate ? InvalidateItems() : S_OK;
- }
-
- // Implementation
- HRESULT OnGetItem(UINT uIndex, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT(uIndex < t_items + t_categories);
- TCtrl* pCtrl = static_cast<TCtrl*>(this);
-
- return uIndex < t_items ?
- pCtrl->DoGetItem(uIndex, key, value) :
- pCtrl->DoGetCategory(uIndex - t_items, key, value);
- }
-
- HRESULT DoGetItem(UINT uItem, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT(k_(key) == k_CategoryId);
- UINT32 uCat = UI_COLLECTION_INVALIDINDEX;
-
- if (t_categories != 0)
- {
- if (m_auItemCat[uItem] == UI_COLLECTION_INVALIDINDEX)
- {
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- m_auItemCat[uItem] = ribbon.OnRibbonQueryItemCategory(TCtrl::GetID(), uItem);
- }
- uCat = m_auItemCat[uItem];
- }
-
- return SetPropertyVal(key, uCat, value);
- }
-
- HRESULT DoGetCategory(UINT uCat, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- HRESULT hr = S_OK;
-
- switch (k_(key))
- {
- case k_Label:
- if (m_asCatName[uCat].IsEmpty())
- {
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- m_asCatName[uCat] = ribbon.OnRibbonQueryCategoryText(TCtrl::GetID(), uCat);
- }
- hr = SetPropertyVal(key, (LPCWSTR)m_asCatName[uCat], value);
- break;
- case k_CategoryId:
- hr = SetPropertyVal(key, uCat, value);
- break;
- default:
- ATLASSERT(FALSE);
- break;
- }
-
- return hr;
- }
-
- HRESULT InvalidateItems()
- {
- return static_cast<TCtrl*>(this)->Invalidate(UI_PKEY_ItemsSource);
- }
-
- HRESULT InvalidateCategories()
- {
- return static_cast<TCtrl*>(this)->Invalidate(UI_PKEY_Categories);
- }
-
- HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* /*ppropvarNewValue*/)
- {
- ATLASSERT(nCmdID == TCtrl::GetID());
- nCmdID; // avoid level 4 warning
-
- HRESULT hr = E_NOTIMPL;
- switch (k_(key))
- {
- case k_ItemsSource:
- {
- ATL::CComQIPtr<IUICollection> pIUICollection(ppropvarCurrentValue->punkVal);
- ATLASSERT(pIUICollection);
- hr = pIUICollection->Clear();
- for (UINT i = 0; i < m_size; i++)
- {
- if FAILED(hr = pIUICollection->Add(m_apItems[i]))
- break;
- }
- ATLASSERT(SUCCEEDED(hr));
- }
- break;
- case k_Categories:
- if (t_categories != 0)
- {
- ATL::CComQIPtr<IUICollection> pIUICategory(ppropvarCurrentValue->punkVal);
- ATLASSERT(pIUICategory.p);
- hr = pIUICategory->Clear();
- for (UINT i = t_items; i < t_items + t_categories; i++)
- {
- if FAILED(hr = pIUICategory->Add(m_apItems[i]))
- break;
- }
- ATLASSERT(SUCCEEDED(hr));
- }
- break;
- }
-
- return hr;
- }
- };
-
- // TextCollectionImpl: handles item labels and selection
- //
- template <class TCtrl, size_t t_items, size_t t_categories = 0>
- class TextCollectionImpl : public CollectionImpl<TCtrl, t_items, t_categories>
- {
- typedef TextCollectionImpl<TCtrl, t_items, t_categories> thisClass;
- public:
- typedef thisClass TextCollection;
-
- TextCollectionImpl() : m_uSelected(UI_COLLECTION_INVALIDINDEX)
- { }
-
- Text m_asText[t_items];
- UINT m_uSelected;
-
- // Operations
- HRESULT SetItemText(UINT uItem, LPCWSTR sText, bool bUpdate = false)
- {
- ATLASSERT(uItem < t_items);
-
- m_asText[uItem] = sText;
-
- return bUpdate ? InvalidateItems() : S_OK;
- }
-
- UINT GetSelected()
- {
- return m_uSelected;
- }
-
- HRESULT Select(UINT uItem, bool bUpdate = false)
- {
- ATLASSERT((uItem < t_items) || (uItem == UI_COLLECTION_INVALIDINDEX));
-
- m_uSelected = uItem;
-
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- return bUpdate ?
- ribbon.SetProperty(TCtrl::GetID(), UI_PKEY_SelectedItem, uItem) :
- S_OK;
- }
-
- // Implementation
- HRESULT DoGetItem(UINT uItem, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT(uItem < t_items);
-
- if (k_(key) == k_Label)
- {
- if (m_asText[uItem].IsEmpty())
- {
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- m_asText[uItem] = ribbon.OnRibbonQueryItemText(TCtrl::GetID(), uItem);
- }
- return SetPropertyVal(key, (LPCWSTR)m_asText[uItem], value);
- }
- else
- {
- return Collection::DoGetItem(uItem, key, value);
- }
- }
-
- HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue)
- {
- ATLASSERT(nCmdID == TCtrl::GetID());
-
- if (k_(key) == k_SelectedItem)
- {
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- UINT uSel = UI_COLLECTION_INVALIDINDEX;
- if ((m_uSelected == UI_COLLECTION_INVALIDINDEX) &&
- ribbon.OnRibbonQuerySelectedItem(TCtrl::GetID(), uSel))
- m_uSelected = uSel;
-
- return SetPropertyVal(key, m_uSelected, ppropvarNewValue);
- }
- else
- {
- return Collection::DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
- }
- }
- };
-
- // ItemCollectionImpl: handles item image
- //
- template <class TCtrl, size_t t_items, size_t t_categories = 0>
- class ItemCollectionImpl : public TextCollectionImpl<TCtrl, t_items, t_categories>
- {
- typedef ItemCollectionImpl<TCtrl, t_items, t_categories> thisClass;
- public:
- typedef thisClass ItemCollection;
-
- ItemCollectionImpl()
- {
- ZeroMemory(m_aBitmap, sizeof m_aBitmap);
- }
-
- CBitmap m_aBitmap[t_items];
-
- // Operations
- HRESULT SetItemImage(UINT uIndex, HBITMAP hbm, bool bUpdate = false)
- {
- ATLASSERT(uIndex < t_items);
-
- m_aBitmap[uIndex] = hbm;
-
- return bUpdate ? InvalidateItems() : S_OK;
- }
-
- // Implementation
- HRESULT DoGetItem(UINT uItem, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT(uItem < t_items);
-
- if (k_(key) == k_ItemImage)
- {
- if (m_aBitmap[uItem].IsNull())
- {
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- m_aBitmap[uItem] = ribbon.OnRibbonQueryItemImage(TCtrl::GetID(), uItem);
- }
- return m_aBitmap[uItem].IsNull() ?
- E_NOTIMPL :
- SetPropertyVal(key, GetImage(m_aBitmap[uItem], UI_OWNERSHIP_COPY), value);
- }
- else
- {
- return TextCollection::DoGetItem(uItem, key, value);
- }
- }
- };
-
- // ComboCollectionImpl: handles combo text
- //
- template <class TCtrl, size_t t_items, size_t t_categories = 0>
- class ComboCollectionImpl : public ItemCollectionImpl<TCtrl, t_items, t_categories>
- {
- typedef ComboCollectionImpl<TCtrl, t_items, t_categories> thisClass;
- public:
- typedef thisClass ComboCollection;
-
- // Operations
- HRESULT SetComboText(LPCWSTR sText)
- {
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- return ribbon.IsRibbonUI() ?
- ribbon.SetProperty(TCtrl::GetID(), UI_PKEY_StringValue, sText) :
- S_OK;
- }
-
- LPCWSTR GetComboText()
- {
- static WCHAR sCombo[RIBBONUI_MAX_TEXT] = { 0 };
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
- PROPVARIANT var;
- if (ribbon.IsRibbonUI())
- {
- HRESULT hr = ribbon.GetIUIFrameworkPtr()->GetUICommandProperty(TCtrl::GetID(), UI_PKEY_StringValue, &var);
- hr = PropVariantToString(var, sCombo, RIBBONUI_MAX_TEXT);
- return sCombo;
- }
- return NULL;
- }
- };
-
- // CommandCollectionImpl: handles RibbonUI command collection controls
- //
- template <class TCtrl, size_t t_items, size_t t_categories = 0>
- class CommandCollectionImpl : public CollectionImpl<TCtrl, t_items, t_categories>
- {
- typedef CommandCollectionImpl<TCtrl, t_items, t_categories> thisClass;
- public:
- typedef thisClass CommandCollection;
-
- CommandCollectionImpl()
- {
- ZeroMemory(m_auCmd, sizeof m_auCmd);
- ZeroMemory(m_aCmdType, sizeof m_aCmdType);
- }
-
- UINT32 m_auCmd[t_items];
- BYTE m_aCmdType[t_items];
-
- // Operations
- HRESULT SetItemCommand(UINT uItem, UINT32 uCommandID, bool bUpdate = false)
- {
- ATLASSERT(uItem < t_items);
-
- if (uCommandID == m_auCmd[uItem])
- return S_OK;
-
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
-
- m_auCmd[uItem] = uCommandID;
- if (uCommandID != 0)
- ribbon.UIAddRibbonElement(uCommandID);
-
- return bUpdate ? InvalidateItems() : S_OK;
- }
-
- HRESULT SetItemCommandType(UINT uItem, UI_COMMANDTYPE type, bool bUpdate = false)
- {
- ATLASSERT(uItem < t_items);
-
- m_aCmdType[uItem] = (BYTE)type;
-
- return bUpdate ? InvalidateItems() : S_OK;
- }
-
- // Implementation
- HRESULT DoGetItem(UINT uItem, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT(uItem < t_items);
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
-
- HRESULT hr = E_FAIL;
- switch (k_(key))
- {
- case k_CommandId:
- if (m_auCmd[uItem] == 0)
- SetItemCommand(uItem, ribbon.OnRibbonQueryItemCommand(TCtrl::GetID(), uItem));
- hr = SetPropertyVal(key, m_auCmd[uItem], value);
- break;
- case k_CommandType:
- if (m_aCmdType[uItem] == UI_COMMANDTYPE_UNKNOWN)
- SetItemCommandType(uItem, ribbon.OnRibbonQueryItemCommandType(TCtrl::GetID(), uItem));
- hr = SetPropertyVal(key, UINT32(m_aCmdType[uItem]), value);
- break;
- case k_CategoryId:
- default:
- hr = Collection::DoGetItem(uItem, key, value);
- break;
- }
-
- return hr;
- }
-
- HRESULT Select(UINT /*uItem*/, bool /*bUpdate*/ = false)
- {
- ATLASSERT(FALSE);
- return S_OK;
- }
- };
-
- // SimpleCollectionImpl: collection class for ribbon simple collection controls
- //
- template <class TCtrl, size_t t_size, UI_COMMANDTYPE t_CommandType = UI_COMMANDTYPE_ACTION>
- class SimpleCollectionImpl : public CollectionImplBase<SimpleCollectionImpl<TCtrl, t_size>, t_size>
- {
- typedef SimpleCollectionImpl<TCtrl, t_size, t_CommandType> thisClass;
- public:
- typedef CollectionImplBase<thisClass, t_size> CollectionBase;
- typedef thisClass SimpleCollection;
-
- // Implementation
- HRESULT OnGetItem(UINT uItem, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT(uItem < t_size);
- TCtrl::WndRibbon& ribbon = static_cast<TCtrl*>(this)->GetWndRibbon();
-
- HRESULT hr = E_NOTIMPL;
- switch (k_(key))
- {
- case k_ItemImage:
- if (HBITMAP hbm = ribbon.DefRibbonQueryItemImage(TCtrl::GetID(), uItem))
- hr = SetPropertyVal(key, GetImage(hbm, UI_OWNERSHIP_TRANSFER), value);
- break;
- case k_Label:
- if (LPCWSTR sText = ribbon.DefRibbonQueryItemText(TCtrl::GetID(), uItem))
- hr = SetPropertyVal(key, (LPCWSTR)sText, value);
- break;
- case k_CommandType:
- hr = SetPropertyVal(key, t_CommandType, value);
- break;
- case k_CommandId:
- hr = SetPropertyVal(key, ribbon.DefRibbonQueryItemCommand(TCtrl::GetID(), uItem), value);
- break;
- case k_CategoryId:
- hr = SetPropertyVal(key, UI_COLLECTION_INVALIDINDEX, value);
- break;
- default:
- ATLASSERT(FALSE);
- break;
- }
-
- return hr;
- }
- };
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // Ribbon collection control classes
-
- // CollectionCtrlImpl: specializable class for ribbon collection controls
- //
- template <class T, UINT t_ID, class TCollection>
- class CollectionCtrlImpl : public CommandCtrlImpl<T, t_ID>, public TCollection
- {
- typedef CollectionCtrlImpl<T, t_ID, TCollection> thisClass;
- public:
- typedef CommandCtrlImpl<T, t_ID> CommandCtrl;
- typedef TCollection Collection;
-
- // Implementation
- virtual HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue)
- {
- ATLASSERT(nCmdID == GetID());
- ATLASSERT(ppropvarNewValue);
-
- HRESULT hr = Collection::DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
- if FAILED(hr)
- hr = CommandCtrl::DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
-
- return hr;
- }
-
- virtual HRESULT DoExecute(UINT nCmdID, UI_EXECUTIONVERB verb,
- const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue,
- IUISimplePropertySet* /*pCommandExecutionProperties*/)
- {
- ATLASSERT (nCmdID == GetID());
- nCmdID; // avoid level4 warning
-
- if (key == NULL) // gallery button pressed
- {
- GetWndRibbon().OnRibbonItemSelected(GetID(), UI_EXECUTIONVERB_EXECUTE, UI_COLLECTION_INVALIDINDEX);
- return S_OK;
- }
-
- ATLASSERT(k_(*key) == k_SelectedItem);
- ATLASSERT(ppropvarValue);
-
- HRESULT hr = S_OK;
- UINT32 uSel = 0xffff;
- hr = UIPropertyToUInt32(*key, *ppropvarValue, &uSel);
-
- if (SUCCEEDED(hr))
- {
- if (GetWndRibbon().OnRibbonItemSelected(GetID(), verb, uSel))
- TCollection::Select(uSel);
- }
-
- return hr;
- }
- };
-
- // ToolbarGalleryCtrlImpl: base class for ribbon toolbar gallery controls
- //
- template <class T, UINT t_ID, UINT t_idTB, size_t t_size>
- class ToolbarGalleryCtrlImpl : public CollectionCtrlImpl<T, t_ID, CommandCollectionImpl<ToolbarGalleryCtrlImpl<T, t_ID, t_idTB, t_size>, t_size>>
- {
- public:
- ToolbarGalleryCtrlImpl()
- {
- CResource tbres;
- ATLVERIFY(tbres.Load(RT_TOOLBAR, t_idTB));
- _AtlToolBarData* pData = (_AtlToolBarData*)tbres.Lock();
- ATLASSERT(pData);
- ATLASSERT(pData->wVersion == 1);
-
- WORD* pItems = pData->items();
- INT j = 0;
- for (int i = 0; (i < pData->wItemCount) && (j < t_size); i++)
- {
- if (pItems[i] != 0)
- {
- m_aCmdType[j] = UI_COMMANDTYPE_ACTION;
- m_auCmd[j++] = pItems[i];
- }
- }
-
- if (j < t_size)
- Resize(j);
- }
-
- HRESULT DoGetItem(UINT uItem, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT(uItem < m_size);
- ATLASSERT(m_auCmd[uItem]);
-
- HRESULT hr = E_FAIL;
- switch (k_(key))
- {
- case k_CommandId:
- hr = SetPropertyVal(key, m_auCmd[uItem], value);
- break;
- case k_CommandType:
- hr = SetPropertyVal(key, UINT32(m_aCmdType[uItem]), value);
- break;
- case k_CategoryId:
- hr = SetPropertyVal(key, UI_COLLECTION_INVALIDINDEX, value);
- break;
- default:
- ATLASSERT(FALSE);
- break;
- }
-
- return hr;
- }
- };
-
-
- // SimpleCollectionCtrlImpl: base class for simple gallery and listbox controls
- //
- template <class T, UINT t_ID, size_t t_size, UI_COMMANDTYPE t_CommandType = UI_COMMANDTYPE_ACTION>
- class SimpleCollectionCtrlImpl :
- public CommandCtrlImpl<T, t_ID>,
- public SimpleCollectionImpl<SimpleCollectionCtrlImpl<T, t_ID, t_size, t_CommandType>, t_size, t_CommandType>
- {
- typedef SimpleCollectionCtrlImpl<T, t_ID, t_size, t_CommandType> thisClass;
- public:
- typedef thisClass SimpleCollection;
-
- SimpleCollectionCtrlImpl() : m_uSelected(0)
- { }
-
- UINT m_uSelected;
-
- HRESULT Select(UINT uItem, bool bUpdate = false)
- {
- ATLASSERT((uItem < t_size) || (uItem == UI_COLLECTION_INVALIDINDEX));
-
- m_uSelected = uItem;
-
- return bUpdate ?
- GetWndRibbon().SetProperty(GetID(), UI_PKEY_SelectedItem, uItem) :
- S_OK;
- }
-
- // Implementation
- virtual HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue)
- {
- ATLASSERT(nCmdID == GetID());
- ATLASSERT(ppropvarNewValue != NULL);
-
- HRESULT hr = S_OK;
- switch (k_(key))
- {
- case k_ItemsSource:
- {
- ATL::CComQIPtr<IUICollection> pIUICollection(ppropvarCurrentValue->punkVal);
- ATLASSERT(pIUICollection.p);
- hr = pIUICollection->Clear();
- for (UINT i = 0; i < t_size; i++)
- {
- if FAILED(hr = pIUICollection->Add(m_apItems[i]))
- break;
- }
- ATLASSERT(SUCCEEDED(hr));
- }
- break;
- case k_SelectedItem:
- hr = SetPropertyVal(UI_PKEY_SelectedItem, m_uSelected, ppropvarNewValue);
- break;
- default:
- hr = CommandCtrlImpl::DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
- break;
- }
-
- return hr;
- }
-
- virtual HRESULT DoExecute(UINT nCmdID, UI_EXECUTIONVERB verb,
- const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue,
- IUISimplePropertySet* /*pCommandExecutionProperties*/)
- {
- ATLASSERT (nCmdID == GetID());
- nCmdID; // avoid level 4 warning
-
- HRESULT hr = S_OK;
- if (key == NULL) // gallery button pressed
- {
- GetWndRibbon().OnRibbonItemSelected(GetID(), UI_EXECUTIONVERB_EXECUTE, UI_COLLECTION_INVALIDINDEX);
- return hr;
- }
- ATLASSERT(k_(*key) == k_SelectedItem);
- ATLASSERT(ppropvarValue);
-
- if SUCCEEDED(hr = UIPropertyToUInt32(*key, *ppropvarValue, &m_uSelected))
- GetWndRibbon().OnRibbonItemSelected(GetID(), verb, m_uSelected);
-
- return hr;
- }
- };
-
- // RecentItemsCtrlImpl
- //
- template <class T, UINT t_ID, class TDocList = CRecentDocumentList>
- class RecentItemsCtrlImpl :
- public CtrlImpl<T, t_ID>,
- public CollectionImplBase<RecentItemsCtrlImpl<T, t_ID, TDocList>, TDocList::m_nMaxEntries_Max>,
- public TDocList
- {
- typedef RecentItemsCtrlImpl<T, t_ID, TDocList> thisClass;
- public:
- typedef thisClass RecentItems;
-
- // Implementation
- HRESULT OnGetItem(UINT uItem, REFPROPERTYKEY key, PROPVARIANT *value)
- {
- ATLASSERT((INT)uItem < GetMaxEntries());
-
- LPCWSTR sPath = m_arrDocs[uItem].szDocName;
- HRESULT hr = E_NOTIMPL;
- switch (k_(key))
- {
- case k_Label:
- hr = SetPropertyVal(key, GetWndRibbon().OnRibbonQueryRecentItemName(sPath), value);
- break;
- case k_LabelDescription:
- hr = SetPropertyVal(key, sPath, value);
- break;
- default:
- ATLASSERT(FALSE);
- break;
- }
-
- return hr;
- }
-
- virtual HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue)
- {
- ATLASSERT(nCmdID == GetID());
- ATLASSERT(ppropvarNewValue);
-
- HRESULT hr = S_OK;
- switch (k_(key))
- {
- case k_RecentItems:
- if (SAFEARRAY* psa = SafeArrayCreateVector(VT_UNKNOWN, 0, m_arrDocs.GetSize()))
- {
- const int iLastIndex = m_arrDocs.GetSize() - 1;
- for (LONG i = 0; i <= iLastIndex; i++)
- SafeArrayPutElement(psa, &i, m_apItems[iLastIndex - i]); // reverse order
-
- hr = SetPropertyVal(key, psa, ppropvarNewValue);
- SafeArrayDestroy(psa);
- }
- break;
- default:
- hr = CtrlImpl::DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
- break;
- }
-
- return hr;
- }
-
- virtual HRESULT DoExecute(UINT nCmdID, UI_EXECUTIONVERB verb,
- const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue,
- IUISimplePropertySet* /*pCommandExecutionProperties*/)
- {
- ATLASSERT(nCmdID == GetID());
- nCmdID; // avoid level 4 warning
- ATLASSERT(verb == UI_EXECUTIONVERB_EXECUTE);
- verb; // avoid level 4 warning
- ATLASSERT((key) && (k_(*key) == k_SelectedItem));
- ATLASSERT(ppropvarValue);
-
- UINT32 uSel = 0xffff;
- HRESULT hr = UIPropertyToUInt32(*key, *ppropvarValue, &uSel);
- if SUCCEEDED(hr)
- {
- ATLASSERT(uSel < (UINT)GetMaxEntries());
- GetWndRibbon().DefCommandExecute(ID_FILE_MRU_FIRST + uSel);
- }
-
- return hr;
- }
- };
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // Ribbon stand-alone control classes
-
- // FontCtrlImpl
- //
- template <class T, UINT t_ID>
- class FontCtrlImpl : public CtrlImpl<T, t_ID>
- {
- public:
-
- CharFormat m_cf;
-
- // Implementation
- virtual HRESULT DoExecute(UINT nCmdID, UI_EXECUTIONVERB verb,
- const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue,
- IUISimplePropertySet* pCommandExecutionProperties)
- {
- ATLASSERT (nCmdID == GetID());
- nCmdID; // avoid level 4 warning
- ATLASSERT ((key) && (k_(*key) == k_FontProperties));
- key; // avoid level 4 warning
-
- HRESULT hr = E_INVALIDARG;
- switch (verb)
- {
- case UI_EXECUTIONVERB_PREVIEW:
- case UI_EXECUTIONVERB_EXECUTE:
- ATLASSERT(pCommandExecutionProperties);
- PROPVARIANT propvar;
-
- if (SUCCEEDED(hr = pCommandExecutionProperties->GetValue(UI_PKEY_FontProperties_ChangedProperties, &propvar)))
- m_cf << ATL::CComQIPtr<IPropertyStore>(propvar.punkVal);
- break;
-
- case UI_EXECUTIONVERB_CANCELPREVIEW:
- ATLASSERT(ppropvarValue);
- ATL::CComPtr<IPropertyStore> pStore;
-
- if (SUCCEEDED(hr = UIPropertyToInterface(UI_PKEY_FontProperties, *ppropvarValue, &pStore)))
- m_cf << pStore;
- break;
- }
-
- if (SUCCEEDED(hr))
- GetWndRibbon().OnRibbonFontCtrlExecute(GetID(), verb, &m_cf);
- else
- ATLASSERT(FALSE);
-
- return hr;
- }
-
- virtual HRESULT DoUpdateProperty(UINT nCmdID, REFPROPERTYKEY key,
- const PROPVARIANT* ppropvarCurrentValue, PROPVARIANT* ppropvarNewValue)
- {
- if ((k_(key) == k_FontProperties) && (GetWndRibbon().OnRibbonQueryFont(t_ID, m_cf)))
- {
- ATL::CComQIPtr<IPropertyStore> pStore(ppropvarCurrentValue->punkVal);
- m_cf >> pStore;
- return SetPropertyVal(key, pStore.p, ppropvarNewValue);
- }
- else
- {
- return CtrlImpl::DoUpdateProperty(nCmdID, key, ppropvarCurrentValue, ppropvarNewValue);
- }
- }
- };
-
- // ColorCtrlImpl
- //
- template <class T, UINT t_ID>
- class ColorCtrlImpl : public CommandCtrlImpl<T, t_ID>
- {
- public:
- ColorCtrlImpl() : m_colorType(UI_SWATCHCOLORTYPE_NOCOLOR), m_color(0x800080) /*MAGENTA*/
- { }
-
- COLORREF m_color;
- UINT32 m_colorType; // value in UI_SWATCHCOLORTYPE
- Text m_sLabels[6]; // k_MoreColorsLabel to k_ThemeColorsCategoryLabel
- ATL::CSimpleArray<COLORREF> m_aColors[2];
- ATL::CSimpleArray<LPCWSTR> m_aTooltips[2];
-
- // Operations
- HRESULT SetColor(COLORREF color, bool bUpdate = false)
- {
- if (m_colorType != UI_SWATCHCOLORTYPE_RGB)
- SetColorType(UI_SWATCHCOLORTYPE_RGB, bUpdate);
- m_color = color;
- return bUpdate ? SetProperty(UI_PKEY_Color, color) : S_OK;
- }
-
- HRESULT SetColorType(UI_SWATCHCOLORTYPE type, bool bUpdate = false)
- {
- m_colorType = type;
- return bUpdate ? SetProperty(UI_PKEY_ColorType, type) : S_OK;
- }
-
- HRESULT SetColorLabel(REFPROPERTYKEY key, LPCWSTR sLabel, bool bUpdate = false)
- {
- ATLASSERT((k_(key) >= k_ThemeColorsCategoryLabel) && (k_(key) <= k_MoreColorsLabel));
- m_sLabels[k_(key) - k_ThemeColorsCategoryLabel] = sLabel;
- return bUpdate ? SetProperty(key, sLabel) : S_OK;
- }
-
- HRESULT SetColorArray(REFPROPERTYKEY key, COLORREF* pColor, bool bUpdate = false)
- {
- ATLASSERT((k_(key) == k_ThemeColors) || (k_(key) == k_StandardColors));
-
- const INT ic = k_(key) - k_ThemeColors;
- m_aColors[ic].RemoveAll();
- while (*pColor != 0x800080) /*MAGENTA*/
- m_aColors[ic].Add(*pColor++);
-
- if (bUpdate)
- {
- PROPVARIANT var;
- if SUCCEEDED(InitPropVariantFromUInt32Vector(m_aColors[ic].GetData(), m_aColors[ic].GetSize(), &var))
- return SetProperty(key, var);
- else
- return E_INVALIDARG;
- }
- else
- {
- return S_OK;
- }
- }
-
- HRESULT SetColorTooltips(REFPROPERTYKEY key, LPCWSTR* ppsTT, bool bUpdate = false)
- {
- ATLASSERT((k_(key) == k_ThemeColorsTooltips) || (k_(key) == k_StandardColorsTooltips));
-
- const INT ic = k_(key) - k_ThemeColorsTooltips;
- m_aTooltips[ic].RemoveAll();
- while (*ppsTT)
- m_aTooltips[ic].Add(*ppsTT++);
-
- if (bUpdate)
- {
- PROPVARIANT var;
- if SUCCEEDED(InitPropVariantFromStringVector(m_aTooltips[ic].GetData(), m_aTooltips[ic].GetSize(), &var))
- return SetProperty(key, var);
- else
- return E_INVALIDARG;
- }
- else
- {
- return S_OK;
- }
- }
-
- // Implementation
- virtual HRESULT DoExecute(UINT nCmdID, UI_EXECUTIONVERB verb,
- const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue,
- IUISimplePropertySet* pCommandExecutionProperties)
- {
- ATLASSERT (nCmdID == GetID());
- nCmdID; // avoid level 4 warning
- ATLASSERT (key && (k_(*key) == k_ColorType));
- key; // avoid level 4 warning
- ATLASSERT (ppropvarValue);
-
- HRESULT hr = PropVariantToUInt32(*ppropvarValue, &m_colorType);
- ATLASSERT(SUCCEEDED(hr));
-
- if (SUCCEEDED(hr…