SPPropertyGridItemExt.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /********************************************
  2. ** 工作室:S&P工作室
  3. ** 作者 :张东斌
  4. ** 日期 :2007年6月
  5. *********************************************/
  6. #if !defined(__SPPROPERTYGRIDITEMEXT_H__)
  7. #define __SPPROPERTYGRIDITEMEXT_H__
  8. #if _MSC_VER > 1000
  9. #pragma once
  10. #endif // _MSC_VER > 1000
  11. #include "SPPropertyGridItem.h"
  12. class CSPPropertyGridItemDate;
  13. //===========================================================================
  14. // Summary:
  15. // Month calendar popup used for CSPPropertyGridItemDate item.
  16. //===========================================================================
  17. class CSPPropertyGridInplaceMonthCal : public CWnd
  18. {
  19. public:
  20. //-----------------------------------------------------------------------
  21. // Summary:
  22. // Constructs a CSPPropertyGridInplaceMonthCal object.
  23. // Parameters:
  24. // pItem - Parent item
  25. //-----------------------------------------------------------------------
  26. CSPPropertyGridInplaceMonthCal( CSPPropertyGridItemDate * pItem )
  27. {
  28. m_pItem = pItem;
  29. }
  30. //{{AFX_CODEJOCK_PRIVATE
  31. AFX_INLINE BOOL GetMinReqRect(RECT* pRect) const
  32. {
  33. ASSERT(m_hWnd != NULL); return (BOOL) ::SendMessage(m_hWnd, MCM_GETMINREQRECT, 0, (LPARAM) pRect);
  34. }
  35. protected:
  36. void OnAccept();
  37. virtual void PostNcDestroy();
  38. virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
  39. afx_msg void OnSelect(NMHDR* pNMHDR, LRESULT* pResult);
  40. DECLARE_MESSAGE_MAP()
  41. //}}AFX_CODEJOCK_PRIVATE
  42. protected:
  43. CSPPropertyGridItemDate * m_pItem; // Parent item
  44. };
  45. //===========================================================================
  46. // Summary:
  47. // CSPPropertyGridItemDate is a CSPPropertyGridItem derived class.
  48. // It is used to create Date item in a Property Grid control.
  49. //
  50. // Remarks:
  51. // When the in-place button for a date item is pressed, a
  52. // CSPPropertyGridInplaceMonthCal object is created, which is a
  53. // User Interface that allows the user to easily select a date.
  54. //
  55. // Example:
  56. // This sample illustrates how to add an item of type Date to your grid.
  57. // <code>
  58. // CSPPropertyGridItem* pStandard = m_wndPropertyGrid.AddCategory(_T("Appointments"));
  59. //
  60. // //Create a Date object with the date 12/26/2004. Note that no time information is entered
  61. // //because this information is ignored.
  62. // COleDateTime dates(2004, 12, 26, 0, 0, 0 );
  63. //
  64. // //Adds a date item to the property grid and set the date to the value stored in dates
  65. // CSPPropertyGridItemDate* pDate = (CSPPropertyGridItemDate*)(pStandard->AddChildItem(new CSPPropertyGridItemDate(_T("Date item"), dates)));
  66. //
  67. // //Set the date format to MM/DD/YYYY
  68. // pDate->SetDateFormat("%m/%d/%Y");
  69. //
  70. // //Changes the date to 3/22/2001
  71. // COleDateTime newDate(2003, 5, 12, 0, 0, 0 );
  72. //
  73. // //Changes the date of the Date item.
  74. // pDate->SetDate(newDate);
  75. //
  76. // //Gets the currently set date
  77. // TRACE(_T("Current Date= %d/%d/%d\n"), pDate->GetMonth(), pDate->GetDay(), pDate->GetYear());
  78. // </code>
  79. // See Also: SetDate, GetMonth, GetDay, GetYear, SetDateFormat
  80. //===========================================================================
  81. class CSPPropertyGridItemDate : public CSPPropertyGridItem
  82. {
  83. public:
  84. //-----------------------------------------------------------------------
  85. // Summary:
  86. // Constructs a CSPPropertyGridItemDate object.
  87. // Parameters:
  88. // strCaption - Caption of the item.
  89. // nID - Identifier of the item.
  90. // oleDate - COleDateTime object containing the initial
  91. // date of the item.
  92. //-----------------------------------------------------------------------
  93. CSPPropertyGridItemDate( CString strCaption , COleDateTime & oleDate );
  94. CSPPropertyGridItemDate( UINT nID , COleDateTime & oleDate ); // <COMBINE CSPPropertyGridItemDate::CSPPropertyGridItemDate@CString@COleDateTime&>
  95. public:
  96. //-----------------------------------------------------------------------
  97. // Summary:
  98. // Call this member to set the date of the item.
  99. // Parameters:
  100. // oleDate - COleDateTime containing a date. You must include
  101. // the month, day, and year. All time information
  102. // should be set to zero.
  103. // Example:
  104. // This sample illustrates how to set the currently selected
  105. // date in and item of type CSPPropertyGridItemDate.
  106. // <code>
  107. // CSPPropertyGridItem* pStandard = m_wndPropertyGrid.AddCategory(_T("Appointments"));
  108. //
  109. // //Create a Date object with the date 12/26/2004. Note that no time information is entered
  110. // //because this information is ignored.
  111. // COleDateTime dates(2004, 12, 26, 0, 0, 0 );
  112. //
  113. // //Adds a date item to the property grid and set the date to the value stored in dates
  114. // CSPPropertyGridItemDate* pDate = (CSPPropertyGridItemDate*)(pStandard->AddChildItem(new CSPPropertyGridItemDate(_T("Date item"), dates)));
  115. //
  116. // //Set the date format to MM/DD/YYYY
  117. // pDate->SetDateFormat("%m/%d/%Y");
  118. //
  119. // //Changes the date to 3/22/2001
  120. // COleDateTime newDate(2003, 5, 12, 0, 0, 0 );
  121. //
  122. // //Changes the date of the Date item.
  123. // pDate->SetDate(newDate);
  124. //
  125. // //Gets the currently set date
  126. // TRACE(_T("Current Date= %d/%d/%d\n"), pDate->GetMonth(), pDate->GetDay(), pDate->GetYear());
  127. // </code>
  128. //-----------------------------------------------------------------------
  129. void SetDate( const COleDateTime & oleDate );
  130. //-----------------------------------------------------------------------
  131. // Summary:
  132. // Call this member function to convert the time in the COleDateTime
  133. // object to be represented as a SYSTEMTIME data structure.
  134. // GetAsSystemTime stores the resulting time in the referenced
  135. // sysTime object. The SYSTEMTIME data structure initialized by
  136. // this function will have its wMilliseconds member set to zero.
  137. // Parameters:
  138. // sysTime - SYSTEMTIME object to hold date.
  139. // Returns:
  140. // TRUE if the COleDateTime date was successfully stored in the
  141. // sysTime object.
  142. // Example:
  143. // This sample code illustrates how to use the GetAsSystemTime member.
  144. // <code>
  145. // CSPPropertyGridItem* pStandard = m_wndPropertyGrid.AddCategory(_T("Appointments"));
  146. //
  147. // //Create a Date object with the date 12/26/2004. Note that no time information is entered
  148. // //because this information is ignored.
  149. // COleDateTime dates(2004, 12, 26, 0, 0, 0 );
  150. //
  151. // //Adds a date item to the property grid and set the date to the value stored in dates
  152. // CSPPropertyGridItemDate* pDate = (CSPPropertyGridItemDate*)(pStandard->AddChildItem(new CSPPropertyGridItemDate(_T("Date item"), dates)));
  153. //
  154. // //Creates a SYSTEMTIME object
  155. // SYSTEMTIME sysTime;
  156. //
  157. // //Stores the day, month, and year into the SYSTEMTIME structure, all other members will be 0.
  158. // if(pDate->GetAsSystemTime(sysTime))
  159. // TRACE(_T("SysTime Current Date= %d/%d/%d\n"), sysTime.wMonth, sysTime.wDay, sysTime.wYear);
  160. // </code>
  161. //-----------------------------------------------------------------------
  162. BOOL GetAsSystemTime( SYSTEMTIME & sysTime );
  163. //-----------------------------------------------------------------------
  164. // Summary:
  165. // Call this member to return the currently selected date.
  166. // Returns:
  167. // The currently selected date.
  168. //-----------------------------------------------------------------------
  169. const COleDateTime &GetDate();
  170. //-----------------------------------------------------------------------
  171. // Summary:
  172. // Call this member to get the Day of the currently selected date.
  173. // Returns:
  174. // Day of the currently set date.
  175. //-----------------------------------------------------------------------
  176. long GetDay();
  177. //-----------------------------------------------------------------------
  178. // Summary:
  179. // Call this member to set the Day of the date.
  180. // Parameters:
  181. // nDay - New Day of date.
  182. //-----------------------------------------------------------------------
  183. void SetDay( long nDay );
  184. //-----------------------------------------------------------------------
  185. // Summary:
  186. // Call this member to get the Month of the currently selected date.
  187. // Returns:
  188. // Month of the currently set date.
  189. //-----------------------------------------------------------------------
  190. long GetMonth();
  191. //-----------------------------------------------------------------------
  192. // Summary:
  193. // Call this member to set the Month of the date.
  194. // Parameters:
  195. // nMonth - New Month of date.
  196. //-----------------------------------------------------------------------
  197. void SetMonth( long nMonth );
  198. //-----------------------------------------------------------------------
  199. // Summary:
  200. // Call this member to get the Year of the currently selected date.
  201. // Returns:
  202. // Year of the currently set date.
  203. //-----------------------------------------------------------------------
  204. long GetYear();
  205. //-----------------------------------------------------------------------
  206. // Summary:
  207. // Call this member to set the Year of the date.
  208. // Parameters:
  209. // nYear - New year of date.
  210. //-----------------------------------------------------------------------
  211. void SetYear( long nYear );
  212. //-----------------------------------------------------------------------
  213. // Summary:
  214. // This member is called to parse the month, day, and year from
  215. // the COleDateTime object.
  216. // Parameters:
  217. // dt - COleDateTime object containing the month, day, and year
  218. // strValue - The date format.
  219. // Format Code:
  220. // <p> %m - Month as decimal number (01 ?12)
  221. // <p> %d - Day of month as decimal number (01 ?31)
  222. // <p> %Y - Year with century, as decimal number
  223. // Format string for 05/22/2004 is "%m%d%Y"
  224. // Returns:
  225. // TRUE if a valid date was extracted, FALSE if an invalid date
  226. // or NULL date was found.
  227. //-----------------------------------------------------------------------
  228. BOOL ParseDateTime( COleDateTime & dt , CString strValue );
  229. //-----------------------------------------------------------------------
  230. // Summary:
  231. // Call this member to change the date format.
  232. // Parameters:
  233. // strFormat - The date format.
  234. // <p> %m - Month as decimal number (01 ?12)
  235. // <p> %d - Day of month as decimal number (01 ?31)
  236. // <p> %Y - Year with century, as decimal number
  237. // Format string for 05/22/2004 is "%m%d%Y"
  238. // Example:
  239. // This sample code illustrates how to change the date format of
  240. // of type CSPPropertyGridItemDate.
  241. // <code>
  242. // CSPPropertyGridItem* pStandard = m_wndPropertyGrid.AddCategory(_T("Appointments"));
  243. //
  244. // //Create a Date object with the date 12/26/2004. Note that no time information is entered
  245. // //because this information is ignored.
  246. // COleDateTime dates(2004, 12, 26, 0, 0, 0 );
  247. //
  248. // //Adds a date item to the property grid and set the date to the value stored in dates
  249. // CSPPropertyGridItemDate* pDate = (CSPPropertyGridItemDate*)(pStandard->AddChildItem(new CSPPropertyGridItemDate(_T("Date item"), dates)));
  250. //
  251. // //Set the date format to MM/DD/YYYY
  252. // pDate->SetDateFormat("%m/%d/%Y");
  253. // </code>
  254. //-----------------------------------------------------------------------
  255. void SetDateFormat( CString strFormat );
  256. protected:
  257. //-------------------------------------------------------------------------
  258. // Summary:
  259. // This method is called when the user presses the in-place button.
  260. // Override the method to show an item-specific dialog.
  261. // Remarks:
  262. // The in-place button is the button that the user presses to
  263. // display date picker.
  264. //-------------------------------------------------------------------------
  265. virtual void OnInplaceButtonDown();
  266. //-----------------------------------------------------------------------
  267. // Summary:
  268. // Call this method to change an item's value.
  269. // Override this method to add new functionality.
  270. // You should call the base class version of this function from your
  271. // override.
  272. // Parameters:
  273. // strValue - New value of the item.
  274. //-----------------------------------------------------------------------
  275. virtual void SetValue( CString strValue );
  276. private:
  277. void Init( COleDateTime & oleDate );
  278. protected:
  279. COleDateTime m_oleDate; // Currently selected date. Only Month, Day, and Year are used.
  280. friend class CSPPropertyGridInplaceMonthCal;
  281. };
  282. AFX_INLINE const COleDateTime & CSPPropertyGridItemDate::GetDate()
  283. {
  284. return m_oleDate;
  285. }
  286. #ifdef __AFXCTL_H__
  287. //===========================================================================
  288. // Summary:
  289. // Picture item of ActiveX PropertyGrid
  290. //===========================================================================
  291. class CSPPropertyGridItemPicture : public CSPPropertyGridItem
  292. {
  293. public:
  294. //-----------------------------------------------------------------------
  295. // Summary:
  296. // Constructs a SPPropertyGridItemPicture object.
  297. // Parameters:
  298. // strCaption - Text caption of this item.
  299. // This is the text displayed in the left column of
  300. // the property grid.
  301. //-----------------------------------------------------------------------
  302. CSPPropertyGridItemPicture( CString strCaption );
  303. public:
  304. CPictureHolder &GetPicture();
  305. void SetPicturePath( LPCTSTR lpszPath );
  306. protected:
  307. //-------------------------------------------------------------------------
  308. // Summary:
  309. // This method is called when the user presses the in-place button.
  310. // Override the method to show an item-specific dialog.
  311. // Remarks:
  312. // The in-place button is the button that the user presses to
  313. // display browse folder dialog so they can select a picture.
  314. // See Also: SPPropertyGridItemFlags, CSPPropertyGridItem::SetFlags
  315. //-------------------------------------------------------------------------
  316. virtual void OnInplaceButtonDown();
  317. //-----------------------------------------------------------------------
  318. // Summary:
  319. // This method is called when an item is drawn. Override this function if
  320. // needed.
  321. // Parameters:
  322. // dc - Reference to the device context to be used for rendering an image
  323. // of the item.
  324. // rcValue - Bounding rectangle of the item.
  325. // Returns:
  326. // TRUE if item is self-drawn.
  327. //-----------------------------------------------------------------------
  328. virtual BOOL OnDrawItemValue( CDC & dc , CRect rcValue );
  329. protected:
  330. CPictureHolder m_olePicture;
  331. CString m_strPicturePath;
  332. };
  333. AFX_INLINE CPictureHolder & CSPPropertyGridItemPicture::GetPicture()
  334. {
  335. return m_olePicture;
  336. }
  337. //}}AFX_CODEJOCK_PRIVATE
  338. #endif
  339. #endif // #if !defined(__SPPROPERTYGRIDITEMEXT_H__)