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.

239 lines
10 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. //#include "NtlParse.h"
  11. //---------------------------------------------------------------------------
  12. // TMT_XXX ranges:
  13. // 1 - 49 SpecialPropVals (see below)
  14. // 50 - 60 Primitive Properties
  15. // 61 - xx enum definitions & regular Properties
  16. //---------------------------------------------------------------------------
  17. enum SpecialPropVals // strings not needed for these
  18. {
  19. TMT_THEMEMETRICS = 1, // THEMEMETRICS struct in shared data
  20. TMT_DIBDATA, // bitmap file converted to DIB data
  21. TMT_DIBDATA1, // bitmap file converted to DIB data
  22. TMT_DIBDATA2, // bitmap file converted to DIB data
  23. TMT_DIBDATA3, // bitmap file converted to DIB data
  24. TMT_DIBDATA4, // bitmap file converted to DIB data
  25. TMT_DIBDATA5, // bitmap file converted to DIB data
  26. TMT_GLYPHDIBDATA, // NTL pcode generated from NTL source file
  27. TMT_NTLDATA, // NTL pcode generated from NTL source file
  28. TMT_PARTJUMPTABLE, // seen if more than 1 part defined for class
  29. TMT_STATEJUMPTABLE, // seen if more than 1 state defined for part
  30. TMT_JUMPTOPARENT, // seen at end of every section (index=-1 means stop)
  31. TMT_ENUMDEF, // enum definition (not yet a property)
  32. TMT_ENUMVAL, // enum value definition
  33. TMT_ENUM, // enum property
  34. TMT_DRAWOBJ, // packed struct (CBorderFill and CImageFile objs)
  35. TMT_TEXTOBJ, // packed struct (CTextObj)
  36. TMT_RGNLIST, // state jump table to access custom region data entries
  37. TMT_RGNDATA, // custom region data for an imagefile/state
  38. TMT_STOCKBRUSHES, // stock brush values for bitmap(s)
  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. DWORD iBrushesOffset; // Offset to the stock brushes array for this bitmap
  95. UINT nBrushes; // Number of brushes in the array
  96. };
  97. // Pointer to the BITMAPINFOHEADER following the structure
  98. #define BITMAPDATA(p) (reinterpret_cast<BITMAPINFOHEADER*>((BYTE*) p + p->dwSize))
  99. // Size in bytes preceding the BITMAPINFOHEADER data
  100. #define TMBITMAPSIZE (sizeof(TMBITMAPHEADER))
  101. //---------------------------------------------------------------------------
  102. class INtlParserCallBack // Parser Caller must implement
  103. {
  104. public:
  105. virtual HRESULT GetStateNum(LPCWSTR pszStateName, BYTE *piNum) = 0;
  106. };
  107. //---------------------------------------------------------------------------
  108. class CThemeParser : public INtlParserCallBack
  109. {
  110. public:
  111. CThemeParser(BOOL fGlobalTheme = FALSE);
  112. HRESULT ParseThemeFile(LPCWSTR pszFileName, LPCWSTR pszColorParam,
  113. IParserCallBack *pCallBack, THEMEENUMPROC pNameCallBack=NULL,
  114. LPARAM lFnParam=NULL, DWORD dwParseFlags=0);
  115. HRESULT ParseThemeBuffer(LPCWSTR pszBuffer, LPCWSTR pszFileName,
  116. LPCWSTR pszColorParam, HINSTANCE hInstThemeDll, IParserCallBack *pCallBack,
  117. THEMEENUMPROC pNameCallBack=NULL, LPARAM lFnParam=NULL,
  118. DWORD dwParseFlags=0, LPCWSTR pszDocProperty=NULL, OUT LPWSTR pszResult=NULL,
  119. DWORD dwMaxResultChars=0);
  120. HRESULT GetEnumValue(LPCWSTR pszEnumName, LPCWSTR pszEnumValName,
  121. int *piValue);
  122. HRESULT GetPropertyNum(LPCWSTR pszName, int *piPropNum);
  123. HRESULT GetStateNum(LPCWSTR pszStateName, BYTE *piNum);
  124. void CleanupStockBitmaps();
  125. protected:
  126. //---- helpers ----
  127. HRESULT SourceError(int iMsgResId, LPCWSTR pszParam1=NULL, LPCWSTR pszParam2=NULL);
  128. HRESULT ParseDocSection();
  129. HRESULT ParseClassSection(LPCWSTR pszFirstName);
  130. HRESULT InitializeSymbols();
  131. PRIMVAL GetPrimVal(LPCWSTR pszName);
  132. HRESULT AddSymbol(LPCWSTR pszName, SHORT sTypeNum, PRIMVAL ePrimVal);
  133. HRESULT ParseClassSectionName(LPCWSTR pszFirstName, LPWSTR appsym);
  134. HRESULT ValidateEnumSymbol(LPCWSTR pszName, int iSymType, int *pIndex=NULL);
  135. HRESULT ParseClassLine(int *piSymType=NULL, int *piValue=NULL, LPWSTR pszBuff=NULL, DWORD dwMaxBuffChars=0);
  136. int GetSymbolIndex(LPCWSTR pszName);
  137. HRESULT ParseThemeScanner(IParserCallBack *pCallBack, THEMEENUMPROC pNameCallBack,
  138. LPARAM lFnParam, DWORD dwParseFlags);
  139. HRESULT ParseColorSchemeSection();
  140. COLORREF ApplyColorSubstitution(COLORREF crOld);
  141. HRESULT ParseSizeSection();
  142. HRESULT ParseFileSection();
  143. HRESULT ParseSubstSection();
  144. HRESULT BitmapColorReplacement(DWORD *pPixelBuff, UINT iWidth, UINT iHeight);
  145. HRESULT PackageImageData(LPCWSTR szFileNameR, LPCWSTR szFileNameG, LPCWSTR szFileNameB, int iDibPropNum);
  146. HRESULT PackageNtlCode(LPCWSTR szFileName);
  147. HRESULT LoadResourceProperties();
  148. void EmptyResourceProperties();
  149. HRESULT GetResourceProperty(LPCWSTR pszPropName, LPWSTR pszValueBuff,
  150. int cchMaxValueChars);
  151. //---- primitive value parsers ----
  152. HRESULT ParseEnumValue(int iSymType);
  153. HRESULT ParseStringValue(int iSymType, LPWSTR pszBuff=NULL, DWORD dwMaxBuffChars=0);
  154. HRESULT ParseIntValue(int iSymType, int *piValue=NULL);
  155. HRESULT ParseBoolValue(int iSymType, LPCWSTR pszPropertyName);
  156. HRESULT ParseColorValue(int iSymType, COLORREF *pcrValue=NULL, COLORREF *pcrValue2=NULL);
  157. HRESULT ParseMarginsValue(int iSymType);
  158. HRESULT ParseIntListValue(int iSymType);
  159. HRESULT ParseFileNameValue(int iSymType, LPWSTR pszBuff=NULL, DWORD dwMaxBuffChars=0);
  160. HRESULT ParseSizeValue(int iSymType);
  161. HRESULT ParsePositionValue(int iSymType);
  162. HRESULT ParseRectValue(int iSymType, LPCWSTR pszPropertyName);
  163. HRESULT ParseFontValue(int iSymType, LPCWSTR pszPropertyName);
  164. HRESULT AddThemeData(int iTypeNum, PRIMVAL ePrimVal, const void *pData, DWORD dwLen);
  165. HRESULT ParseSizeInfoUnits(int iVal, LPCWSTR pszDefaultUnits, int *piPixels);
  166. HRESULT GetIntList(int *pInts, LPCWSTR *pParts, int iCount,
  167. int iMin, int iMax);
  168. HRESULT ParseSysFont(LOGFONT *pFont);
  169. HRESULT ParseSysColor(LPCWSTR szId, COLORREF *pcrValue);
  170. HRESULT GenerateEmptySection(LPCWSTR pszSectionName, int iPartId, int iStateId);
  171. //---- private data ----
  172. CScanner _scan;
  173. CSimpleFile _outfile;
  174. int _iEnumCount;
  175. int _iTypeCount;
  176. int _iFontNumber; // for using resource-based strings as font values
  177. BOOL _fGlobalTheme;
  178. BOOL _fGlobalsDefined;
  179. BOOL _fClassSectionDefined;
  180. BOOL _fDefiningColorScheme;
  181. BOOL _fUsingResourceProperties;
  182. UCHAR _uCharSet;
  183. //---- current section info ----
  184. int _iPartId;
  185. int _iStateId;
  186. WCHAR _szClassName[MAX_PATH];
  187. WCHAR _szBaseSectionName[MAX_PATH]; // of current section
  188. WCHAR _szFullSectionName[MAX_PATH]; // of current section
  189. CSimpleArray<ENUMVAL> _EnumVals;
  190. CSimpleArray<SYMBOL> _Symbols;
  191. CSimpleArray<HBITMAP> _StockBitmapCleanupList;
  192. IParserCallBack *_pCallBackObj;
  193. THEMEENUMPROC _pNameCallBack;
  194. LPARAM _lNameParam;
  195. DWORD _dwParseFlags;
  196. WCHAR _ColorParam[MAX_PATH+1];
  197. HINSTANCE _hinstThemeDll;
  198. LPCWSTR _pszDocProperty;
  199. LPWSTR _pszResult; // for querying doc property
  200. DWORD _dwMaxResultChars;
  201. //---- color substitution table ----
  202. int _iColorCount;
  203. COLORREF _crFromColors[5];
  204. COLORREF _crToColors[5];
  205. COLORREF _crBlend;
  206. //---- hue substitution table ----
  207. int _iHueCount;
  208. BYTE _bFromHues[5];
  209. BYTE _bToHues[5];
  210. //---- theme metrics table ----
  211. BOOL _fDefiningMetrics;
  212. BOOL _fMetricsDefined;
  213. //---- resource properties ----
  214. CSimpleArray<CWideString> _PropertyNames;
  215. CSimpleArray<CWideString> _PropertyValues;
  216. CSimpleArray<int> _iPropertyIds;
  217. WCHAR _szResPropValue[2*MAX_PATH];
  218. int _iResPropId;
  219. };
  220. //---------------------------------------------------------------------------