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.

286 lines
9.0 KiB

  1. /******************************************************************************
  2. Header File: ICC Profile.H
  3. This defines the C++ class we encapsulate the profile in. It also defines
  4. the base class for device enumeration. All activity related to the profile,
  5. including installations, associations, and so forth, is encapsulated in the
  6. CProfile class. The UI classes themselves never call an ICM API, but are
  7. instead concerned with simply handling the interface.
  8. Copyright (c) 1996 by Microsoft Corporation
  9. A Pretty Penny Enterprises Production
  10. Change History:
  11. 10-31-96 A-RobKj (Pretty Penny Enterprises) began encapsulating
  12. 11-22-96 A-RobKj changed associations from string array to uint array to
  13. facilitate the spec'd device naming conventions, and
  14. filtering of lists for previously installed devices.
  15. 12-04-96 A-RobKj Added the CProfileArray class to make the Device
  16. management UI more efficient.
  17. 12-13-96 A-RobKj Moved the CDeviceList derived classes here, so I can use
  18. them elsewhere.
  19. ******************************************************************************/
  20. #if !defined(ICC_PROFILE_CLASS)
  21. #define ICC_PROFILE_CLASS
  22. #include "StringAr.H"
  23. #include "Dialog.H"
  24. // CDeviceList class
  25. /******************************************************************************
  26. Highlights:
  27. This is a base class for the enumeration and reporting of Device
  28. class-specific information. The spec is such that a device can be associated
  29. with a friendly name, but displayed in the UI with an enhanced name. Also,
  30. the method for enumerating a device can differ from class to class.
  31. This base class is usable for cases where there is no means of enumerating
  32. devices currently. It reports that there are no devices.
  33. To make overrides easier, the default display name returns the friendly name,
  34. so derived classes where this is the case do not need to override this
  35. method.
  36. ******************************************************************************/
  37. class CDeviceList { // Device-specific information- base class
  38. CString m_csDummy;
  39. public:
  40. CDeviceList() {}
  41. ~CDeviceList() {}
  42. virtual unsigned Count() { return 0; }
  43. virtual CString& DeviceName(unsigned u) { return m_csDummy; }
  44. virtual CString& DisplayName(unsigned u) { return DeviceName(u); }
  45. virtual void Enumerate() {}
  46. virtual BOOL IsValidDeviceName(LPCTSTR lpstr) { return FALSE; }
  47. };
  48. // Device Enumeration classes- these must all derive from CDeviceList
  49. // The CPrinterList class handles printers. Enumeration is via the Win32
  50. // spooler API.
  51. class CPrinterList : public CDeviceList {
  52. CStringArray m_csaDeviceNames;
  53. CStringArray m_csaDisplayNames;
  54. public:
  55. CPrinterList() {}
  56. ~CPrinterList() {}
  57. virtual unsigned Count() { return m_csaDeviceNames.Count(); }
  58. virtual CString& DeviceName(unsigned u) { return m_csaDeviceNames[u]; }
  59. virtual CString& DisplayName(unsigned u) { return m_csaDisplayNames[u]; }
  60. virtual void Enumerate();
  61. virtual BOOL IsValidDeviceName(LPCTSTR lpstr);
  62. };
  63. // The CMonitorList class handles monitors. Enumeration is via a private ICM
  64. // API.
  65. class CMonitorList : public CDeviceList {
  66. CStringArray m_csaDeviceNames;
  67. CStringArray m_csaDisplayNames;
  68. CString m_csPrimaryDeviceName;
  69. public:
  70. CMonitorList() {}
  71. ~CMonitorList() {}
  72. virtual unsigned Count() { return m_csaDeviceNames.Count(); }
  73. virtual CString& DeviceName(unsigned u) { return m_csaDeviceNames[u]; }
  74. virtual CString& DisplayName(unsigned u) { return m_csaDisplayNames[u]; }
  75. virtual CString& PrimaryDeviceName() { return m_csPrimaryDeviceName; }
  76. virtual void Enumerate();
  77. virtual BOOL IsValidDeviceName(LPCTSTR lpstr);
  78. virtual LPCSTR DeviceNameToDisplayName(LPCTSTR lpstr);
  79. };
  80. // The CScannerList class handles scanners. Enumeration is via the STI
  81. // interface.
  82. class CScannerList : public CDeviceList {
  83. CStringArray m_csaDeviceNames;
  84. CStringArray m_csaDisplayNames;
  85. public:
  86. CScannerList() {}
  87. ~CScannerList() {}
  88. virtual unsigned Count() { return m_csaDeviceNames.Count(); }
  89. virtual CString& DeviceName(unsigned u) { return m_csaDeviceNames[u]; }
  90. virtual CString& DisplayName(unsigned u) { return m_csaDisplayNames[u]; }
  91. virtual void Enumerate();
  92. virtual BOOL IsValidDeviceName(LPCTSTR lpstr);
  93. };
  94. // The CAllDeviceList class shows everything. We enumerate by combining the
  95. // results of enumerating all of the other classes.
  96. class CAllDeviceList : public CDeviceList {
  97. CStringArray m_csaDeviceNames;
  98. CStringArray m_csaDisplayNames;
  99. public:
  100. CAllDeviceList() {}
  101. ~CAllDeviceList() {}
  102. virtual unsigned Count() { return m_csaDeviceNames.Count(); }
  103. virtual CString& DeviceName(unsigned u) { return m_csaDeviceNames[u]; }
  104. virtual CString& DisplayName(unsigned u) { return m_csaDisplayNames[u]; }
  105. virtual void Enumerate();
  106. virtual BOOL IsValidDeviceName(LPCTSTR lpstr);
  107. };
  108. // CProfile class
  109. class CProfile {
  110. HPROFILE m_hprof; // Profile handle
  111. PROFILEHEADER m_phThis; // Profile header
  112. CString m_csName;
  113. BOOL m_bIsInstalled, m_bInstallChecked, m_bAssociationsChecked,
  114. m_bDevicesChecked;
  115. CDeviceList *m_pcdlClass; // Devices of this class
  116. CUintArray m_cuaAssociation; // Associated devices (indices)
  117. char m_acTag[MAX_PATH * 2];
  118. void InstallCheck();
  119. void AssociationCheck();
  120. void DeviceCheck();
  121. public:
  122. static void Enumerate(ENUMTYPE& et, CStringArray& csaList);
  123. static void Enumerate(ENUMTYPE& et, CStringArray& csaList, CStringArray& csaDesc);
  124. static void Enumerate(ENUMTYPE& et, class CProfileArray& cpaList);
  125. static const CString ColorDirectory();
  126. CProfile(LPCTSTR lpstr);
  127. ~CProfile();
  128. // Queries
  129. CString GetName() { return m_csName.NameOnly(); }
  130. DWORD GetType() { return m_hprof ? m_phThis.phClass : 0; }
  131. DWORD GetCMM() { return m_hprof ? m_phThis.phCMMType : 0; }
  132. // Inquire the color space information from the header
  133. DWORD GetColorSpace() {return m_hprof ? m_phThis.phDataColorSpace : 0;}
  134. BOOL IsInstalled() {
  135. if (!m_bInstallChecked)
  136. InstallCheck();
  137. return m_bIsInstalled;
  138. }
  139. BOOL IsValid() {
  140. BOOL bValid = FALSE;
  141. if (m_hprof)
  142. IsColorProfileValid(m_hprof, &bValid);
  143. return bValid;
  144. }
  145. unsigned DeviceCount() {
  146. if (m_pcdlClass) {
  147. if (!m_bDevicesChecked)
  148. DeviceCheck();
  149. return m_pcdlClass -> Count();
  150. } else {
  151. return 0; // low memory - m_pcdlClass allocation failed
  152. }
  153. }
  154. unsigned AssociationCount() {
  155. if (!m_bAssociationsChecked)
  156. AssociationCheck();
  157. return m_cuaAssociation.Count();
  158. }
  159. LPCTSTR DeviceName(unsigned u) {
  160. if (m_pcdlClass) {
  161. if (!m_bDevicesChecked)
  162. DeviceCheck();
  163. return m_pcdlClass -> DeviceName(u);
  164. } else {
  165. return TEXT(""); // low memory - m_pcdlClass allocation failed
  166. }
  167. }
  168. LPCTSTR DisplayName(unsigned u) {
  169. if (m_pcdlClass) {
  170. if (!m_bDevicesChecked)
  171. DeviceCheck();
  172. return m_pcdlClass -> DisplayName(u);
  173. } else {
  174. return TEXT(""); // low memory - m_pcdlClass allocation failed
  175. }
  176. }
  177. unsigned Association(unsigned u) {
  178. if (!m_bAssociationsChecked)
  179. AssociationCheck();
  180. return m_cuaAssociation[u];
  181. }
  182. LPCSTR TagContents(TAGTYPE tt, unsigned uOffset = 0);
  183. // Operations
  184. BOOL Install();
  185. void Uninstall(BOOL bDelete);
  186. void Associate(LPCTSTR lpstrNew);
  187. void Dissociate(LPCTSTR lpstrNew);
  188. };
  189. // CProfileArray class- this is a list of profiles- it is used by the Device
  190. // Management UI, so we only construct a CProfile object once per profile.
  191. class CProfileArray {
  192. CProfile *m_aStore[20];
  193. CProfileArray *m_pcpaNext;
  194. unsigned m_ucUsed;
  195. const unsigned ChunkSize() const {
  196. return sizeof m_aStore / sizeof m_aStore[0];
  197. }
  198. CProfile *Borrow();
  199. public:
  200. CProfileArray();
  201. ~CProfileArray();
  202. unsigned Count() const { return m_ucUsed; }
  203. // Add an item
  204. void Add(LPCTSTR lpstrNew);
  205. CProfile *operator [](unsigned u) const;
  206. void Remove(unsigned u);
  207. void Empty();
  208. };
  209. #endif