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

Graph program

Development Platform:

Visual C++

  1. /* ==========================================================================
  2. Class : CReportCreatorView
  3. Author : Johan Rosengren, Abstrakt Mekanik AB
  4. Date : 2004-07-25
  5. Purpose : "CReportCreatorView" derives from "CView" and is the main 
  6. view class of the application.
  7. Description : The member "m_editor" is the actual editor, and covers 
  8. all of the client area together with the rulers.
  9. Usage : Created by MFC
  10.    ========================================================================*/
  11. #include "stdafx.h"
  12. #include "Solidgraph.h"
  13. #include "ReportCreatorDoc.h"
  14. #include "ReportCreatorView.h"
  15. #include "ReportEditor/EditorSettingsDialog.h"
  16. #include "ReportEditor/ReportEntityBox.h"
  17. #include "ReportEditor/ReportEntityLine.h"
  18. #include "ReportEditor/ReportEntityLabel.h"
  19. #include "ReportEditor/ReportEntityPicture.h"
  20. #include "ReportEditor/ReportEntitySettings.h"
  21. #include "ReportEditor/UnitConversion.h"
  22. #include ".reportcreatorview.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. #define RULER_SIZE 24
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CReportCreatorView
  31. IMPLEMENT_DYNCREATE(CReportCreatorView, CView)
  32. BEGIN_MESSAGE_MAP(CReportCreatorView, CView)
  33. //{{AFX_MSG_MAP(CReportCreatorView)
  34. ON_WM_ERASEBKGND()
  35. ON_WM_SIZE()
  36. /* ON_COMMAND(ID_BUTTON_SETTINGS, OnButtonSettings)*/
  37. ON_COMMAND(ID_REPORT_GRID, OnButtonGrid)
  38. ON_UPDATE_COMMAND_UI(ID_REPORT_GRID, OnUpdateButtonGrid)
  39. /* ON_COMMAND(ID_BUTTON_MARGIN, OnButtonMargin)
  40. ON_UPDATE_COMMAND_UI(ID_BUTTON_MARGIN, OnUpdateButtonMargin)*/
  41. ON_COMMAND(ID_REPORT_SNAP_TO_GRID, OnButtonSnap)
  42. ON_UPDATE_COMMAND_UI(ID_REPORT_SNAP_TO_GRID, OnUpdateButtonSnap)
  43. ON_COMMAND(ID_REPORT_RECT, OnButtonAddBox)
  44. ON_COMMAND(ID_REPORT_LABEL, OnButtonAddLabel)
  45. ON_COMMAND(ID_REPORT_LINE, OnButtonAddLine)
  46. ON_COMMAND(ID_REPORT_COPY, OnEditCopy)
  47. ON_UPDATE_COMMAND_UI(ID_REPORT_COPY, OnUpdateEditCopy)
  48. ON_COMMAND(ID_REPORT_CUT, OnEditCut)
  49. ON_UPDATE_COMMAND_UI(ID_REPORT_CUT, OnUpdateEditCut)
  50. ON_COMMAND(ID_REPORT_PASTE, OnEditPaste)
  51. ON_UPDATE_COMMAND_UI(ID_REPORT_PASTE, OnUpdateEditPaste)
  52. ON_COMMAND(ID_REPORT_UNDO, OnEditUndo)
  53. ON_UPDATE_COMMAND_UI(ID_REPORT_UNDO, OnUpdateEditUndo)
  54. ON_COMMAND(ID_REPORT_ZOOM_IN, OnZoomIn)
  55. ON_COMMAND(ID_REPORT_ZOOM_OUT, OnZoomOut)
  56. ON_COMMAND(ID_REPORT_ALIGN_BOTTOM, OnButtonAlignBottom)
  57. ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_BOTTOM, OnUpdateButtonAlignBottom)
  58. ON_COMMAND(ID_REPORT_ALIGN_LEFT, OnButtonAlignLeft)
  59. ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_LEFT, OnUpdateButtonAlignLeft)
  60. ON_COMMAND(ID_REPORT_ALIGN_RIGHT, OnButtonAlignRight)
  61. ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_RIGHT, OnUpdateButtonAlignRight)
  62. ON_COMMAND(ID_REPORT_ALIGN_TOP, OnButtonAlignTop)
  63. ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_TOP, OnUpdateButtonAlignTop)
  64. ON_COMMAND(ID_REPORT_ALIGN_SIZES, OnButtonSameSize)
  65. ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_SIZES, OnUpdateButtonSameSize)
  66. /*ON_COMMAND(ID_BUTTON_ZOOM_TO_FIT, OnButtonZoomToFit)
  67. ON_COMMAND(ID_BUTTON_PROPERTIES, OnButtonProperties)*/
  68. ON_COMMAND(ID_REPORT_PICTURE, OnButtonAddPicture)
  69. ON_WM_DESTROY()
  70. /*ON_COMMAND(ID_DELETE, OnDelete)
  71. ON_COMMAND(ID_INSERT, OnInsert)*/
  72. //}}AFX_MSG_MAP
  73. // Standard printing commands
  74. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  75. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  76. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  77. ON_REGISTERED_MESSAGE(UWM_HSCROLL, OnEditorHScroll)
  78. ON_REGISTERED_MESSAGE(UWM_VSCROLL, OnEditorVScroll)
  79. ON_REGISTERED_MESSAGE(UWM_ZOOM, OnEditorZoom)
  80. ON_REGISTERED_MESSAGE(UWM_MOUSE, OnEditorMouse)
  81. ON_REGISTERED_MESSAGE(UWM_MEASUREMENTS, OnRulerMeasurements)
  82. ON_COMMAND(ID_REPORT_ADD_PAGE, OnReportAddPage)
  83. END_MESSAGE_MAP()
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CReportCreatorView construction/destruction
  86. CReportCreatorView::CReportCreatorView()
  87. /* ============================================================
  88. Function : CReportCreatorView::CReportCreatorView
  89. Description : Constructor
  90. Access : Public
  91. Return : void
  92. Parameters : none
  93. Usage :
  94.    ============================================================*/
  95. {
  96. m_screenResolutionX = 0;
  97. m_current_editor = -1;
  98. m_pages_preview_dlg = NULL;
  99. }
  100. CReportCreatorView::~CReportCreatorView()
  101. /* ============================================================
  102. Function : CReportCreatorView::~CReportCreatorView
  103. Description : Destructor
  104. Access : Public
  105. Return : void
  106. Parameters : none
  107. Usage :
  108.    ============================================================*/
  109. {
  110. }
  111. BOOL CReportCreatorView::PreCreateWindow(CREATESTRUCT& cs)
  112. /* ============================================================
  113. Function : CReportCreatorView::PreCreateWindow
  114. Description : Called befor the window is created
  115. Access : Public
  116. Return : BOOL - Not interested
  117. Parameters : CREATESTRUCT& cs - Not interested
  118. Usage : Called from MFC
  119.    ============================================================*/
  120. {
  121. return CView::PreCreateWindow(cs);
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CReportCreatorView drawing
  125. void CReportCreatorView::OnDraw(CDC* pDC)
  126. /* ============================================================
  127. Function : CReportCreatorView::OnDraw
  128. Description : Draws the view
  129. Access : Public
  130. Return : void
  131. Parameters : CDC* pDC - "CDC" to draw to
  132. Usage : Called from MFC
  133.    ============================================================*/
  134. {
  135. CReportCreatorDoc* pDoc = GetDocument();
  136. ASSERT_VALID(pDoc);
  137. /* if( pDC->IsPrinting() )
  138. {
  139. COLORREF col = m_editors[m_current_editor].editor->GetBackgroundColor();
  140. // Print zoom is the difference between screen- 
  141. // and printer resolution.
  142. double zoom = pDC->GetDeviceCaps( LOGPIXELSX ) / m_screenResolutionX;
  143. CRect rect( 0,0, 
  144. round( static_cast< double >( m_editors[m_current_editor].editor->GetVirtualSize().cx ) * zoom ), 
  145. round( static_cast< double >( m_editors[m_current_editor].editor->GetVirtualSize().cy ) * zoom ) );
  146. m_editors[m_current_editor].editor->SetRedraw( FALSE );
  147. m_editors[m_current_editor].editor->SetBackgroundColor( RGB( 255, 255, 255 ) );
  148. m_editors[m_current_editor].editor->Print( pDC, rect, zoom );
  149. m_editors[m_current_editor].editor->SetBackgroundColor( col );
  150. m_editors[m_current_editor].editor->SetRedraw( TRUE );
  151. }*/
  152. if( pDC->IsPrinting() )
  153. {
  154. // Print zoom is the difference between screen- 
  155. // and printer resolution.
  156. /* double zoom = pDC->GetDeviceCaps( LOGPIXELSX ) / m_screenResolutionX;
  157. size_t sz = m_editors.size();
  158. int shftX = 0;
  159. int shftY = 0;
  160. for (size_t i=0;i<sz;i++)
  161. {
  162. COLORREF col = m_editors[i]->GetBackgroundColor();
  163. CRect rect( shftX,shftY, 
  164. shftX+round( static_cast< double >( m_editors[i]->GetVirtualSize().cx ) * zoom ), 
  165. shftY+round( static_cast< double >( m_editors[i]->GetVirtualSize().cy ) * zoom ) );
  166. m_editors[i]->SetRedraw( FALSE );
  167. m_editors[i]->SetBackgroundColor( RGB( 255, 255, 255 ) );
  168. m_editors[i]->Print( pDC, rect, zoom );
  169. m_editors[i]->SetBackgroundColor( col );
  170. m_editors[i]->SetRedraw( TRUE );
  171. shftX+=round( static_cast< double >( m_editors[i]->GetVirtualSize().cx ) * zoom );
  172. shftY+=round( static_cast< double >( m_editors[i]->GetVirtualSize().cy)  * zoom) ;
  173. }
  174. */
  175. }
  176. else
  177. {
  178. CRect rct;
  179. GetClientRect(rct);
  180. pDC->FillSolidRect(rct,::GetSysColor(COLOR_3DSHADOW));
  181. }
  182. }
  183. static void SetPrinterMode(CDC* pDC,int Mode)
  184. {
  185. if(Mode !=DMORIENT_LANDSCAPE && Mode != DMORIENT_PORTRAIT)
  186. {
  187. ASSERT(0);
  188. return;
  189. }
  190. PRINTDLG* pPrintDlg = new PRINTDLG;
  191. AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg);
  192. DEVMODE* lpDevMode = (DEVMODE*)::GlobalLock(pPrintDlg->hDevMode);
  193. lpDevMode->dmOrientation = (short)Mode;
  194. pDC->ResetDC(lpDevMode);
  195. ::GlobalUnlock(pPrintDlg->hDevMode);
  196. delete pPrintDlg;
  197. }
  198. void CReportCreatorView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
  199. {
  200. CView::OnPrepareDC(pDC, pInfo);
  201. if (pDC->IsPrinting())
  202. SetPrinterMode(pDC,
  203. GetDocument()->GetData(pInfo->m_nCurPage-1)->GetPrinterMode());
  204. }
  205. void CReportCreatorView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  206. {
  207. if( pDC->IsPrinting() )
  208. {
  209. // Print zoom is the difference between screen- 
  210. // and printer resolution.
  211. double zoom = pDC->GetDeviceCaps( LOGPIXELSX ) / m_screenResolutionX;
  212. {
  213. COLORREF col = m_editors[pInfo->m_nCurPage-1].editor->GetBackgroundColor();
  214. CRect rect( 0,0, 
  215. round( static_cast< double >( m_editors[pInfo->m_nCurPage-1].editor->GetVirtualSize().cx ) * zoom ), 
  216. round( static_cast< double >( m_editors[pInfo->m_nCurPage-1].editor->GetVirtualSize().cy ) * zoom ) );
  217. m_editors[pInfo->m_nCurPage-1].editor->SetRedraw( FALSE );
  218. m_editors[pInfo->m_nCurPage-1].editor->SetBackgroundColor( RGB( 255, 255, 255 ) );
  219. m_editors[pInfo->m_nCurPage-1].editor->Print( pDC, /*rect*/pInfo->m_rectDraw, zoom );
  220. m_editors[pInfo->m_nCurPage-1].editor->SetBackgroundColor( col );
  221. m_editors[pInfo->m_nCurPage-1].editor->SetRedraw( TRUE );
  222. }
  223. }
  224. }
  225. /////////////////////////////////////////////////////////////////////////////
  226. // CReportCreatorView printing
  227. BOOL CReportCreatorView::OnPreparePrinting(CPrintInfo* pInfo)
  228. /* ============================================================
  229. Function : CReportCreatorView::OnPreparePrinting
  230. Description : Called before a printout
  231. Access : Public
  232. Return : BOOL - Not interested
  233. Parameters : CPrintInfo* pInfo - Not interested
  234. Usage : Called from MFC
  235.    ============================================================*/
  236. {
  237. pInfo->SetMaxPage(m_editors.size());
  238. return DoPreparePrinting(pInfo);
  239. }
  240. void CReportCreatorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  241. /* ============================================================
  242. Function : CReportCreatorView::OnBeginPrinting
  243. Description : Called before a printout
  244. Access : Public
  245. Return : void
  246. Parameters : CDC* - Not interested
  247. CPrintInfo* - Not interested
  248. Usage : Called from MFC
  249.    ============================================================*/
  250. {
  251. }
  252. void CReportCreatorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  253. /* ============================================================
  254. Function : CReportCreatorView::OnEndPrinting
  255. Description : Called after a printout
  256. Access : Public
  257. Return : void
  258. Parameters : CDC* - Not interested
  259. CPrintInfo* - Not interested
  260. Usage : Called from MFC
  261.    ============================================================*/
  262. {
  263. SetCurrentPage(m_current_editor);
  264. }
  265. /////////////////////////////////////////////////////////////////////////////
  266. // CReportCreatorView diagnostics
  267. #ifdef _DEBUG
  268. void CReportCreatorView::AssertValid() const
  269. /* ============================================================
  270. Function : CReportCreatorView::AssertValid
  271. Description : Checks object validity
  272. Access : Public
  273. Return : void
  274. Parameters : none
  275. Usage : Debug function
  276.    ============================================================*/
  277. {
  278. CView::AssertValid();
  279. }
  280. void CReportCreatorView::Dump(CDumpContext& dc) const
  281. /* ============================================================
  282. Function : CReportCreatorView::Dump
  283. Description : Dumps object data
  284. Access : Public
  285. Return : void
  286. Parameters : CDumpContext& dc - Dump context
  287. Usage : Debug function
  288.    ============================================================*/
  289. {
  290. CView::Dump(dc);
  291. }
  292. CReportCreatorDoc* CReportCreatorView::GetDocument()
  293. /* ============================================================
  294. Function : CReportCreatorView::GetDocument
  295. Description : Returns a pointer to the current document
  296. Access : Public
  297. Return : CReportCreatorDoc* - Current document
  298. Parameters : none
  299. Usage : Call to get a pointer to the view document.
  300.    ============================================================*/
  301. {
  302. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CReportCreatorDoc)));
  303. return (CReportCreatorDoc*)m_pDocument;
  304. }
  305. #endif //_DEBUG
  306. void CReportCreatorView::AddPage(CDiagramEntityContainer* cont, bool vertiacal, bool repaint/*=true*/)
  307. {
  308. //if( !m_editors[m_current_editor].editor->m_hWnd )
  309. //{
  310. int restraintMode = RESTRAINT_MARGIN;//theApp.GetProfileInt( _T( "Application" ), _T( "Restraint" ), 0 );
  311. int left = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Left" ), 0 );
  312. int right = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Right" ), 0 );
  313. int top = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Top" ), 0 );
  314. int bottom = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Bottom" ), 0 );
  315. int width = -1;//theApp.GetProfileInt( _T( "Application" ), _T( "Width" ), -1 );
  316. int height = -1;//theApp.GetProfileInt( _T( "Application" ), _T( "Height" ), -1 );
  317. COLORREF colorBg = RGB( 255, 255, 255 );//( COLORREF ) theApp.GetProfileInt( _T( "Application" ), _T( "ColorBg" ), RGB( 255, 255, 255 ) );
  318. COLORREF colorGrid = RGB( 222, 222, 222 );//( COLORREF ) theApp.GetProfileInt( _T( "Application" ), _T( "ColorGrid" ), RGB( 222, 222, 222 ) );
  319. COLORREF colorMargin = RGB( 0, 0, 255 );//( COLORREF ) theApp.GetProfileInt( _T( "Application" ), _T( "ColorMargin" ), RGB( 0, 0, 255 ) );
  320. BOOL margin = TRUE;//( BOOL ) theApp.GetProfileInt( _T( "Application" ), _T( "Margin" ), FALSE );
  321. BOOL grid = TRUE;//( BOOL ) theApp.GetProfileInt( _T( "Application" ), _T( "Grid" ), FALSE );
  322. BOOL snap = TRUE;//( BOOL ) theApp.GetProfileInt( _T( "Application" ), _T( "Snap" ), FALSE );
  323. int measurements = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Units" ), 0 );
  324. CReportEntitySettings::GetRESInstance()->SetMeasurementUnits( measurements );
  325. double zoom = 0.50;//static_cast< double >( theApp.GetProfileInt( _T( "Application" ), _T( "ZoomLevel" ), 100 ) ) / 100;
  326. double zoomfactor = 0.2;//static_cast< double >( theApp.GetProfileInt( _T( "Application" ), _T( "ZoomFactor" ), 1 ) ) / 100;
  327. CRect rect;
  328. GetClientRect( rect );
  329. rect.left = RULER_SIZE;
  330. rect.top = RULER_SIZE;
  331. CReportEditor* newEditor = new CReportEditor;
  332. int printer_mode = (vertiacal)?DMORIENT_PORTRAIT:DMORIENT_LANDSCAPE;
  333. CDiagramEntityContainer* Doc_data = (cont)?cont: 
  334. GetDocument()->CreateNewDiagramEntityContainer(NULL,printer_mode) ;
  335. if (!Doc_data)
  336. {
  337. ASSERT(Doc_data);
  338. delete newEditor;
  339. return;
  340. }
  341. newEditor->Create( WS_CHILD | WS_VISIBLE, rect, this,Doc_data);
  342. CHorzRuler*    newHorzRuler = new CHorzRuler;
  343. CVertRuler*    newVertRuler = new CVertRuler;
  344. CCornerBox*    newCornerBox = new CCornerBox;
  345. rect.top = 0;
  346. rect.bottom = RULER_SIZE;
  347. newHorzRuler->Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, 100 );
  348. GetClientRect( rect );
  349. rect.right = RULER_SIZE;
  350. rect.top = RULER_SIZE;
  351. newVertRuler->Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, 101 );
  352. rect.left = 0;
  353. rect.top = 0;
  354. rect.right = RULER_SIZE;
  355. rect.bottom = RULER_SIZE;
  356. newCornerBox->Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, 102 );
  357. newHorzRuler->SetMeasurements( measurements );
  358. newVertRuler->SetMeasurements( measurements );
  359. newCornerBox->SetMeasurements( measurements );
  360. CClientDC dc( this );
  361. m_screenResolutionX = dc.GetDeviceCaps( LOGPIXELSX );
  362. CUnitConversion::Init( m_screenResolutionX );
  363. int step = m_screenResolutionX / 6;
  364. int gridSize = step;//theApp.GetProfileInt( _T( "Application" ), _T( "GridSize" ), step );
  365. if( width == -1 )
  366. {
  367. CPrintDialog printer( TRUE, PD_RETURNDC );
  368. printer.GetDefaults();
  369. HDC hdc = printer.GetPrinterDC();
  370. if (cont==NULL)  // 漕徉怆