Leaked source code of windows server 2003
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.

223 lines
9.7 KiB

  1. //---------------------------------------------------------------------------
  2. // Parser.h - parses a "themes.ini" file and builds the ThemeInfo entries
  3. //---------------------------------------------------------------------------
  4. #pragma once
  5. //---------------------------------------------------------------------------
  6. #include "Scanner.h"
  7. #include "Utils.h"
  8. #include "CFile.h"
  9. #include "SimpStr.h"
  10. //---------------------------------------------------------------------------
  11. // TMT_XXX ranges:
  12. // 1 - 49 SpecialPropVals (see below)
  13. // 50 - 60 Primitive Properties
  14. // 61 - xx enum definitions & regular Properties
  15. //---------------------------------------------------------------------------
  16. enum SpecialPropVals // strings not needed for these
  17. {
  18. TMT_THEMEMETRICS = 1, // THEMEMETRICS struct in shared data
  19. TMT_DIBDATA, // bitmap file converted to DIB data
  20. TMT_DIBDATA1, // bitmap file converted to DIB data
  21. TMT_DIBDATA2, // bitmap file converted to DIB data
  22. TMT_DIBDATA3, // bitmap file converted to DIB data
  23. TMT_DIBDATA4, // bitmap file converted to DIB data
  24. TMT_DIBDATA5, // bitmap file converted to DIB data
  25. TMT_GLYPHDIBDATA, // NTL pcode generated from NTL source file
  26. TMT_NTLDATA, // NTL pcode generated from NTL source file
  27. TMT_PARTJUMPTABLE, // seen if more than 1 part defined for class
  28. TMT_STATEJUMPTABLE, // seen if more than 1 state defined for part
  29. TMT_JUMPTOPARENT, // seen at end of every section (index=-1 means stop)
  30. // THE FOLLOWING THREE PROPERTIES ARE PERSISTED; FOR BACKWARD COMPAT,
  31. // DO NOT UPSET THEIR VALUES!
  32. TMT_ENUMDEF, // enum definition (not yet a property)
  33. TMT_ENUMVAL, // enum value definition
  34. TMT_ENUM, // enum property
  35. TMT_DRAWOBJ, // packed struct (CBorderFill and CImageFile objs)
  36. TMT_TEXTOBJ, // packed struct (CTextObj)
  37. TMT_RGNLIST, // state jump table to access custom region data entries
  38. TMT_RGNDATA, // custom region data for an imagefile/state
  39. TMT_ENDOFCLASS, // end of data for a class section
  40. TMT_STOCKDIBDATA,
  41. TMT_UNKNOWN,
  42. };
  43. //---------------------------------------------------------------------------
  44. #define HUE_SUBCNT 5
  45. #define COLOR_SUBCNT 5
  46. //---------------------------------------------------------------------------
  47. #define MAX_PROPERTY_VALUE 1024
  48. //---------------------------------------------------------------------------
  49. #define ENUM_SECTION_NAME L"enums"
  50. #define TYPE_SECTION_NAME L"types"
  51. #define INI_MACRO_SYMBOL L'#'
  52. #define SUBST_TABLE_INCLUDE L"Include"
  53. #define GLOBALS_SECTION_NAME L"globals"
  54. #define SYSMETRICS_SECTION_NAME L"SysMetrics"
  55. #define MYAPP_NAME L"ThemeSel"
  56. #define OUTFILE_NAME L"tmdefs.h"
  57. #define PREDEFINES_NAME L"themes.inc"
  58. //---------------------------------------------------------------------------
  59. typedef BYTE PRIMVAL; // first 10 TMT_XXX defines
  60. //---------------------------------------------------------------------------
  61. class IParserCallBack // Parser Caller must implement
  62. {
  63. public:
  64. virtual HRESULT AddIndex(LPCWSTR pszAppName, LPCWSTR pszClassName,
  65. int iPartNum, int iStateNum, int iIndex, int iLen) = 0;
  66. virtual HRESULT AddData(SHORT sTypeNum, PRIMVAL ePrimVal, const void *pData,
  67. DWORD dwLen) = 0;
  68. virtual int GetNextDataIndex() = 0;
  69. };
  70. //---------------------------------------------------------------------------
  71. struct ENUMVAL
  72. {
  73. CWideString csName;
  74. int iValue;
  75. int iSymbolIndex;
  76. };
  77. //---------------------------------------------------------------------------
  78. struct SYMBOL
  79. {
  80. CWideString csName;
  81. SHORT sTypeNum; // the property number of this property
  82. PRIMVAL ePrimVal; // all enums = ENUM_PRIMNUM
  83. };
  84. //---------------------------------------------------------------------------
  85. // Stock objects data
  86. //---------------------------------------------------------------------------
  87. struct TMBITMAPHEADER // Stock bitmap info, can be followed with a BITMAPINFOHEADER struct
  88. {
  89. DWORD dwSize; // Size of the structure
  90. BOOL fFlipped; // TRUE if the bitmap is flipped (stock or not)
  91. HBITMAP hBitmap; // Stock bitmap handle, if NULL then a BITMAPINFOHEADER follows
  92. DWORD dwColorDepth; // Bitmap color depth
  93. BOOL fTrueAlpha; // TRUE if the bitmap has a non-empty alpha chanel
  94. };
  95. // Pointer to the BITMAPINFOHEADER following the structure
  96. #define BITMAPDATA(p) (reinterpret_cast<BITMAPINFOHEADER*>((BYTE*) p + p->dwSize))
  97. // Size in bytes preceding the BITMAPINFOHEADER data
  98. #define TMBITMAPSIZE (sizeof(TMBITMAPHEADER))
  99. //---------------------------------------------------------------------------
  100. class CThemeParser
  101. {
  102. public:
  103. CThemeParser(BOOL fGlobalTheme = FALSE);
  104. HRESULT ParseThemeFile(LPCWSTR pszFileName, LPCWSTR pszColorParam,
  105. IParserCallBack *pCallBack, THEMEENUMPROC pNameCallBack=NULL,
  106. LPARAM lFnParam=NULL, DWORD dwParseFlags=0);
  107. HRESULT ParseThemeBuffer(LPCWSTR pszBuffer, LPCWSTR pszFileName,
  108. LPCWSTR pszColorParam, HINSTANCE hInstThemeDll, IParserCallBack *pCallBack,
  109. THEMEENUMPROC pNameCallBack=NULL, LPARAM lFnParam=NULL,
  110. DWORD dwParseFlags=0, LPCWSTR pszDocProperty=NULL, OUT LPWSTR pszResult=NULL,
  111. DWORD dwMaxResultChars=0);
  112. HRESULT GetPropertyNum(LPCWSTR pszName, int *piPropNum);
  113. void CleanupStockBitmaps();
  114. protected:
  115. //---- helpers ----
  116. HRESULT SourceError(int iMsgResId, LPCWSTR pszParam1=NULL, LPCWSTR pszParam2=NULL);
  117. HRESULT ParseDocSection();
  118. HRESULT ParseClassSection(LPCWSTR pszFirstName);
  119. HRESULT InitializeSymbols();
  120. HRESULT AddSymbol(LPCWSTR pszName, SHORT sTypeNum, PRIMVAL ePrimVal);
  121. HRESULT ParseClassSectionName(LPCWSTR pszFirstName, LPWSTR szAppSym, ULONG cchAppSym);
  122. HRESULT ValidateEnumSymbol(LPCWSTR pszName, int iSymType, int *pIndex=NULL);
  123. HRESULT ParseClassLine(int *piSymType=NULL, int *piValue=NULL, LPWSTR pszBuff=NULL, DWORD dwMaxBuffChars=0);
  124. int GetSymbolIndex(LPCWSTR pszName);
  125. HRESULT ParseThemeScanner(IParserCallBack *pCallBack, THEMEENUMPROC pNameCallBack,
  126. LPARAM lFnParam, DWORD dwParseFlags);
  127. HRESULT ParseColorSchemeSection();
  128. COLORREF ApplyColorSubstitution(COLORREF crOld);
  129. HRESULT ParseSizeSection();
  130. HRESULT ParseFileSection();
  131. HRESULT ParseSubstSection();
  132. HRESULT PackageImageData(LPCWSTR szFileNameR, LPCWSTR szFileNameG, LPCWSTR szFileNameB, int iDibPropNum);
  133. HRESULT LoadResourceProperties();
  134. void EmptyResourceProperties();
  135. HRESULT GetResourceProperty(LPCWSTR pszPropName, LPWSTR pszValueBuff,
  136. int cchMaxValueChars);
  137. //---- primitive value parsers ----
  138. HRESULT ParseEnumValue(int iSymType);
  139. HRESULT ParseStringValue(int iSymType, LPWSTR pszBuff=NULL, DWORD dwMaxBuffChars=0);
  140. HRESULT ParseIntValue(int iSymType, int *piValue=NULL);
  141. HRESULT ParseBoolValue(int iSymType, LPCWSTR pszPropertyName);
  142. HRESULT ParseColorValue(int iSymType, COLORREF *pcrValue=NULL, COLORREF *pcrValue2=NULL);
  143. HRESULT ParseMarginsValue(int iSymType);
  144. HRESULT ParseIntListValue(int iSymType);
  145. HRESULT ParseFileNameValue(int iSymType, LPWSTR pszBuff=NULL, DWORD dwMaxBuffChars=0);
  146. HRESULT ParseSizeValue(int iSymType);
  147. HRESULT ParsePositionValue(int iSymType);
  148. HRESULT ParseRectValue(int iSymType, LPCWSTR pszPropertyName);
  149. HRESULT ParseFontValue(int iSymType, LPCWSTR pszPropertyName);
  150. HRESULT AddThemeData(int iTypeNum, PRIMVAL ePrimVal, const void *pData, DWORD dwLen);
  151. HRESULT ParseSizeInfoUnits(int iVal, LPCWSTR pszDefaultUnits, int *piPixels);
  152. HRESULT GetIntList(int *pInts, LPCWSTR *pParts, int iCount,
  153. int iMin, int iMax);
  154. HRESULT GenerateEmptySection(LPCWSTR pszSectionName, int iPartId, int iStateId);
  155. //---- private data ----
  156. CScanner _scan;
  157. CSimpleFile _outfile;
  158. int _iEnumCount;
  159. int _iTypeCount;
  160. int _iFontNumber; // for using resource-based strings as font values
  161. BOOL _fGlobalTheme;
  162. BOOL _fGlobalsDefined;
  163. BOOL _fClassSectionDefined;
  164. BOOL _fDefiningColorScheme;
  165. BOOL _fUsingResourceProperties;
  166. UCHAR _uCharSet;
  167. //---- current section info ----
  168. int _iPartId;
  169. int _iStateId;
  170. WCHAR _szClassName[MAX_PATH];
  171. WCHAR _szBaseSectionName[MAX_PATH]; // of current section
  172. WCHAR _szFullSectionName[MAX_PATH]; // of current section
  173. CSimpleArray<ENUMVAL> _EnumVals;
  174. CSimpleArray<SYMBOL> _Symbols;
  175. CSimpleArray<HBITMAP> _StockBitmapCleanupList;
  176. IParserCallBack *_pCallBackObj;
  177. THEMEENUMPROC _pNameCallBack;
  178. LPARAM _lNameParam;
  179. DWORD _dwParseFlags;
  180. WCHAR _ColorParam[MAX_PATH+1];
  181. HINSTANCE _hinstThemeDll;
  182. LPCWSTR _pszDocProperty;
  183. LPWSTR _pszResult; // for querying doc property
  184. DWORD _dwMaxResultChars;
  185. //---- color substitution table ----
  186. int _iColorCount;
  187. COLORREF _crFromColors[5];
  188. COLORREF _crToColors[5];
  189. COLORREF _crBlend;
  190. //---- hue substitution table ----
  191. int _iHueCount;
  192. BYTE _bFromHues[5];
  193. BYTE _bToHues[5];
  194. //---- theme metrics table ----
  195. BOOL _fDefiningMetrics;
  196. BOOL _fMetricsDefined;
  197. //---- resource properties ----
  198. CSimpleArray<CWideString> _PropertyNames;
  199. CSimpleArray<CWideString> _PropertyValues;
  200. CSimpleArray<int> _iPropertyIds;
  201. WCHAR _szResPropValue[2*MAX_PATH];
  202. int _iResPropId;
  203. };
  204. //---------------------------------------------------------------------------