ReportEntityBox.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 14k
Category:

Graph program

Development Platform:

Visual C++

  1. /* ==========================================================================
  2. File : ReportEntityBox.cpp
  3. Class : CReportEntityBox
  4. Date : 07/14/04
  5. Purpose : "CReportEntityBox" derives from "CDiagramEntity" and 
  6. is a class representing a simple box.
  7. Description : The class implements the necessary ovverides and adds 
  8. attributes to draw a box.
  9. Usage : Use as any "CDiagramEntity" object.
  10.    ========================================================================*/
  11. #include "stdafx.h"
  12. #include "ReportEntityBox.h"
  13. #include "DiagramEditor/Tokenizer.h"
  14. #include "ReportEntitySettings.h"
  15. #include "UnitConversion.h"
  16. ////////////////////////////////////////////////////////////////////
  17. // Public functions
  18. //
  19. CReportEntityBox::CReportEntityBox()
  20. /* ============================================================
  21. Function : CReportEntityBox::CReportEntityBox
  22. Description : Constructor.
  23. Access : Public
  24. Return : void
  25. Parameters : none
  26. Usage :
  27.    ============================================================*/
  28. {
  29. SetType( _T( "report_box" ) );
  30. CReportEntitySettings::GetRESInstance()->GetBorderSettings( this );
  31. CReportEntitySettings::GetRESInstance()->GetFillSettings( this );
  32. SetAttributeDialog( &m_dlg, IDD_REPORT_DIALOG_BOX_PROPERTIES );
  33. SetMinimumSize( CSize( 0, 0 ) );
  34. }
  35. CReportEntityBox::~CReportEntityBox()
  36. /* ============================================================
  37. Function : CReportEntityBox::~CReportEntityBox
  38. Description : Destructor.
  39. Access : Public
  40. Return : void
  41. Parameters : none
  42. Usage :
  43.    ============================================================*/
  44. {
  45. if( m_dlg.m_hWnd )
  46. m_dlg.DestroyWindow();
  47. }
  48. unsigned int CReportEntityBox::GetBorderThickness() const
  49. /* ============================================================
  50. Function : CReportEntityBox::GetBorderThickness
  51. Description : Accessor. Getter for "m_borderThickness".
  52. Access : Public
  53. Return : int - Current thickness
  54. Parameters : none
  55. Usage : Call to get the value of "m_borderThickness".
  56.    ============================================================*/
  57. {
  58. return m_borderThickness;
  59. }
  60. void CReportEntityBox::SetBorderThickness( unsigned int value )
  61. /* ============================================================
  62. Function : CReportEntityBox::SetBorderThickness
  63. Description : Accessor. Setter for "m_borderThickness".
  64. Access : Public
  65. Return : void
  66. Parameters : int value - New thickness
  67. Usage : Call to set the value of "m_borderThickness".
  68.    ============================================================*/
  69. {
  70. m_borderThickness = value;
  71. }
  72. unsigned int CReportEntityBox::GetBorderStyle() const
  73. /* ============================================================
  74. Function : CReportEntityBox::GetBorderStyle
  75. Description : Accessor. Getter for "m_borderStyle".
  76. Access : Public
  77. Return : int - Current style
  78. Parameters : none
  79. Usage : Call to get the value of "m_borderStyle". 
  80. Can be one of the styles for "CreatePen"
  81.    ============================================================*/
  82. {
  83. return m_borderStyle;
  84. }
  85. void CReportEntityBox::SetBorderStyle( unsigned int value )
  86. /* ============================================================
  87. Function : CReportEntityBox::SetBorderStyle
  88. Description : Accessor. Setter for "m_borderStyle".
  89. Access : Public
  90. Return : void
  91. Parameters : int value - New style
  92. Usage : Call to set the value of "m_borderStyle". 
  93. Can be one of the styles from "CreatePen".
  94.    ============================================================*/
  95. {
  96. m_borderStyle = value;
  97. }
  98. unsigned int CReportEntityBox::GetBorderColor() const
  99. /* ============================================================
  100. Function : CReportEntityBox::GetBorderColor
  101. Description : Accessor. Getter for "m_borderColor".
  102. Access : Public
  103. Return : COLORREF - Current border color
  104. Parameters : none
  105. Usage : Call to get the value of "m_borderColor".
  106.    ============================================================*/
  107. {
  108. return m_borderColor;
  109. }
  110. void CReportEntityBox::SetBorderColor( unsigned int value )
  111. /* ============================================================
  112. Function : CReportEntityBox::SetBorderColor
  113. Description : Accessor. Setter for "m_borderColor".
  114. Access : Public
  115. Return : void
  116. Parameters : COLORREF value - New border color
  117. Usage : Call to set the value of "m_borderColor".
  118.    ============================================================*/
  119. {
  120. m_borderColor = value;
  121. }
  122. BOOL CReportEntityBox::GetFill() const
  123. /* ============================================================
  124. Function : CReportEntityBox::GetFill
  125. Description : Accessor. Getter for "m_fill".
  126. Access : Public
  127. Return : BOOL - "TRUE" if the object should 
  128. be filled.
  129. Parameters : none
  130. Usage : Call to get the value of "m_fill".
  131.    ============================================================*/
  132. {
  133. return m_fill;
  134. }
  135. void CReportEntityBox::SetFill( BOOL value )
  136. /* ============================================================
  137. Function : CReportEntityBox::SetFill
  138. Description : Accessor. Setter for "m_fill".
  139. Access : Public
  140. Return : void
  141. Parameters : BOOL value - "TRUE" if the object should 
  142. be filled.
  143. Usage : Call to set the value of "m_fill".
  144.    ============================================================*/
  145. {
  146. m_fill = value;
  147. }
  148. unsigned int CReportEntityBox::GetFillColor() const
  149. /* ============================================================
  150. Function : CReportEntityBox::GetFillColor
  151. Description : Accessor. Getter for "m_fillColor".
  152. Access : Public
  153. Return : COLORREF - Current fill color.
  154. Parameters : none
  155. Usage : Call to get the value of "m_fillColor".
  156.    ============================================================*/
  157. {
  158. return m_fillColor;
  159. }
  160. void CReportEntityBox::SetFillColor( unsigned int value )
  161. /* ============================================================
  162. Function : CReportEntityBox::SetFillColor
  163. Description : Accessor. Setter for "m_fillColor".
  164. Access : Public
  165. Return : void
  166. Parameters : COLORREF value - New fill color.
  167. Usage : Call to set the value of "m_fillColor".
  168.    ============================================================*/
  169. {
  170. m_fillColor = value;
  171. }
  172. CDiagramEntity* CReportEntityBox::Clone()
  173. /* ============================================================
  174. Function : CReportEntityBox::Clone
  175. Description : Clones the current object to a new one.
  176. Access : Public
  177. Return : CDiagramEntity* - A clone of this object
  178. Parameters : none
  179. Usage : Call to clone the current object.
  180.    ============================================================*/
  181. {
  182. CReportEntityBox* obj = new CReportEntityBox;
  183. obj->Copy( this );
  184. return obj;
  185. }
  186. void CReportEntityBox::Copy( CDiagramEntity * obj )
  187. /* ============================================================
  188. Function : CReportEntityBox::Copy
  189. Description : Copies the data from "obj" to this object.
  190. Access : Public
  191. Return : void
  192. Parameters : CDiagramEntity * obj - Object to copy from
  193. Usage : Call to copy data from "obj"
  194.    ============================================================*/
  195. {
  196. CDiagramEntity::Copy( obj );
  197. CReportEntityBox* copy = static_cast< CReportEntityBox* >( obj );
  198. SetBorderThickness( copy->GetBorderThickness() );
  199. SetBorderStyle( copy->GetBorderStyle() );
  200. SetBorderColor( copy->GetBorderColor() );
  201. SetFill( copy->GetFill() );
  202. SetFillColor( copy->GetFillColor() );
  203. }
  204. BOOL CReportEntityBox::FromString( const CString& str )
  205. /* ============================================================
  206. Function : CReportEntityBox::FromString
  207. Description : Sets the data of the object from "str".
  208. Access : Public
  209. Return : BOOL - "TRUE" if the string
  210. represents an object 
  211. of this type.
  212. Parameters : const CString& str - String to parse
  213. Usage : Call to load objects from a file.
  214.    ============================================================*/
  215. {
  216. BOOL result = FALSE;
  217. CString data( str );
  218. if( LoadFromString( data ) )
  219. {
  220. CTokenizer tok( data );
  221. double borderthickness;
  222. unsigned int borderstyle;
  223. unsigned int bordercolor;
  224. BOOL fill;
  225. unsigned int fillcolor;
  226. int count = 0;
  227. DWORD tmpW;
  228. tok.GetAt( count++, tmpW );
  229. borderthickness=tmpW;
  230. tok.GetAt( count++, tmpW );
  231. borderstyle=tmpW;
  232. tok.GetAt( count++, tmpW );
  233. bordercolor = tmpW;
  234. tok.GetAt( count++, fill );
  235. tok.GetAt( count++, tmpW );
  236. fillcolor =tmpW;
  237. int bt = CUnitConversion::InchesToPixels( borderthickness );
  238. SetBorderThickness( bt );
  239. SetBorderStyle( borderstyle );
  240. SetBorderColor( bordercolor );
  241. SetFill( fill );
  242. SetFillColor( fillcolor );
  243. int left = CUnitConversion::InchesToPixels( GetLeft() );
  244. int right = CUnitConversion::InchesToPixels( GetRight() );
  245. int top = CUnitConversion::InchesToPixels( GetTop() );
  246. int bottom = CUnitConversion::InchesToPixels( GetBottom() );
  247. CRect rect( left, top, right, bottom );
  248. SetRect( rect );
  249. result = TRUE;
  250. }
  251. return result;
  252. }
  253. CString CReportEntityBox::GetString() const
  254. /* ============================================================
  255. Function : CReportEntityBox::GetString
  256. Description : Creates a string representing this object.
  257. Access : Public
  258. Return : CString - Resulting string
  259. Parameters : none
  260. Usage : Call to save this object to file.
  261.    ============================================================*/
  262. {
  263. CRect rect = GetRect();
  264. double oldleft = GetLeft();
  265. double oldright = GetRight();
  266. double oldtop = GetTop();
  267. double oldbottom = GetBottom();
  268. double left = CUnitConversion::PixelsToInches( rect.left );
  269. double right = CUnitConversion::PixelsToInches( rect.right );
  270. double top = CUnitConversion::PixelsToInches( rect.top );
  271. double bottom = CUnitConversion::PixelsToInches( rect.bottom );
  272. CReportEntityBox* const local = const_cast< CReportEntityBox* const >( this );
  273. local->SetLeft( left );
  274. local->SetRight( right );
  275. local->SetTop( top );
  276. local->SetBottom( bottom );
  277. CString str;
  278. double thickness = CUnitConversion::PixelsToInches( GetBorderThickness() );
  279. str.Format( _T( ",%f,%i,%i,%i,%i" ),
  280. thickness,
  281. GetBorderStyle( ),
  282. GetBorderColor( ),
  283. GetFill( ),
  284. GetFillColor( ) );
  285. str += _T( ";" );
  286. str = GetDefaultGetString() + str;
  287. local->SetLeft( oldleft );
  288. local->SetRight( oldright );
  289. local->SetTop( oldtop );
  290. local->SetBottom( oldbottom );
  291. return str;
  292. }
  293. CDiagramEntity* CReportEntityBox::CreateFromString( const CString & str )
  294. /* ============================================================
  295. Function : CReportEntityBox::CreateFromString
  296. Description : Creates and returns an object of this 
  297. type from "str"
  298. Access : Public
  299. Return : CDiagramEntity* - Object created from "str"
  300. Parameters : const CString & str - String to create object from
  301. Usage : Call from a factory class to create 
  302. instances of this object.
  303.    ============================================================*/
  304. {
  305. CReportEntityBox* obj = new CReportEntityBox;
  306. if(!obj->FromString( str ) )
  307. {
  308. delete obj;
  309. obj = NULL;
  310. }
  311. return obj;
  312. }
  313. void  CReportEntityBox::Serialize(CArchive& ar)
  314. {
  315. typedef struct
  316. {
  317. int a_f;
  318. int b_f;
  319. } BOX_RESERVE_FIELDS;
  320. BOX_RESERVE_FIELDS box_reserve;
  321. memset(&box_reserve,0,sizeof(BOX_RESERVE_FIELDS));
  322. CDiagramEntity::Serialize(ar);
  323. if (ar.IsStoring())
  324. {
  325. // 杨躔囗