Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.2 KiB

  1. // DictImpl.h : Declaration of the CDict
  2. #ifndef __DICT_H_
  3. #define __DICT_H_
  4. #include "resource.h" // main symbols
  5. #include <map>
  6. /////////////////////////////////////////////////////////////////////////////
  7. // CDict
  8. class CDict;
  9. struct TermInfo
  10. {
  11. const TS_ATTRID * pTermID;
  12. const TS_ATTRID * pParentID;
  13. WCHAR * pszMnemonic;
  14. ULONG idString;
  15. BSTR ( CDict::*mfpConvertToString ) ( const VARIANT &, LCID & );
  16. };
  17. struct GUIDLess
  18. {
  19. bool operator ()(const GUID& g1, const GUID& g2) const
  20. {
  21. const ULONG *lpGUID1 = (ULONG *)&g1;
  22. const ULONG *lpGUID2 = (ULONG *)&g2;
  23. for (int i = 0; i < 4; i++)
  24. {
  25. if (lpGUID1[i] < lpGUID2[i])
  26. return true;
  27. if (lpGUID1[i] > lpGUID2[i])
  28. return false;
  29. }
  30. return false;
  31. }
  32. };
  33. struct WCHARLess
  34. {
  35. bool operator ()(const WCHAR* s1, const WCHAR* s2) const
  36. {
  37. if (wcscmp(s1, s2) < 0)
  38. return true;
  39. else
  40. return false;
  41. }
  42. };
  43. typedef std::map<const TS_ATTRID, const TermInfo*, GUIDLess> DictMap;
  44. typedef std::map<const WCHAR *, const TermInfo*, WCHARLess> DictMnemonicMap;
  45. class ATL_NO_VTABLE CDict :
  46. public CComObjectRootEx<CComSingleThreadModel>,
  47. public CComCoClass<CDict, &CLSID_AccDictionary>,
  48. public IAccDictionary
  49. {
  50. public:
  51. DECLARE_REGISTRY_RESOURCEID(IDR_MSAADICT)
  52. DECLARE_PROTECT_FINAL_CONSTRUCT()
  53. BEGIN_COM_MAP(CDict)
  54. COM_INTERFACE_ENTRY(IAccDictionary)
  55. END_COM_MAP()
  56. HRESULT FinalConstruct()
  57. {
  58. #ifdef DEBUG
  59. m_hinstResDll = LoadLibraryEx( TEXT("C:\\tools\\OLEACCRC.DLL"), NULL, LOAD_LIBRARY_AS_DATAFILE );
  60. if( m_hinstResDll )
  61. {
  62. // load it from where I put it for debug purposes
  63. return S_OK;
  64. }
  65. #endif
  66. m_hinstResDll = LoadLibraryEx( TEXT("OLEACCRC.DLL"), NULL, LOAD_LIBRARY_AS_DATAFILE );
  67. if( ! m_hinstResDll )
  68. {
  69. return E_FAIL;
  70. }
  71. return S_OK;
  72. }
  73. CDict();
  74. ~CDict();
  75. // IAccDictionary
  76. HRESULT STDMETHODCALLTYPE GetLocalizedString (
  77. REFGUID Term,
  78. LCID lcid,
  79. BSTR * pResult,
  80. LCID * plcid
  81. );
  82. HRESULT STDMETHODCALLTYPE GetParentTerm (
  83. REFGUID Term,
  84. GUID * pParentTerm
  85. );
  86. HRESULT STDMETHODCALLTYPE GetMnemonicString (
  87. REFGUID Term,
  88. BSTR * pResult
  89. );
  90. HRESULT STDMETHODCALLTYPE LookupMnemonicTerm (
  91. BSTR bstrMnemonic,
  92. GUID * pTerm
  93. );
  94. HRESULT STDMETHODCALLTYPE ConvertValueToString (
  95. REFGUID Term,
  96. LCID lcid,
  97. VARIANT varValue,
  98. BSTR * pbstrResult,
  99. LCID * plcid
  100. );
  101. // The following convert member functions are called from ConvertValueToString
  102. // by accessing a member function pointer in the dictionary
  103. BSTR ConvertPtsToString( const VARIANT & value, LCID & lcid );
  104. BSTR ConvertBoolToString( const VARIANT & value, LCID & lcid );
  105. BSTR ConvertColorToString( const VARIANT & value, LCID & lcid );
  106. BSTR ConvertWeightToString( const VARIANT & value, LCID & lcid );
  107. BSTR ConvertLangIDToString( const VARIANT & value, LCID & lcid );
  108. BSTR ConvertBSTRToString( const VARIANT & value, LCID & lcid );
  109. private:
  110. double CDict::ColorDistance(COLORREF crColor1, COLORREF crColor2);
  111. private:
  112. DictMap m_mapDictionary;
  113. DictMnemonicMap m_mapMnemonicDictionary;
  114. HINSTANCE m_hinstResDll;
  115. };
  116. #endif //__DICT_H_