Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
ReportCreatorView.cpp
Package: solidgraph_sources.zip [view]
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 58k
Category:
Graph program
Development Platform:
Visual C++
- /* ==========================================================================
- Class : CReportCreatorView
- Author : Johan Rosengren, Abstrakt Mekanik AB
- Date : 2004-07-25
- Purpose : "CReportCreatorView" derives from "CView" and is the main
- view class of the application.
- Description : The member "m_editor" is the actual editor, and covers
- all of the client area together with the rulers.
- Usage : Created by MFC
- ========================================================================*/
- #include "stdafx.h"
- #include "Solidgraph.h"
- #include "ReportCreatorDoc.h"
- #include "ReportCreatorView.h"
- #include "ReportEditor/EditorSettingsDialog.h"
- #include "ReportEditor/ReportEntityBox.h"
- #include "ReportEditor/ReportEntityLine.h"
- #include "ReportEditor/ReportEntityLabel.h"
- #include "ReportEditor/ReportEntityPicture.h"
- #include "ReportEditor/ReportEntitySettings.h"
- #include "ReportEditor/UnitConversion.h"
- #include ".reportcreatorview.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define RULER_SIZE 24
- /////////////////////////////////////////////////////////////////////////////
- // CReportCreatorView
- IMPLEMENT_DYNCREATE(CReportCreatorView, CView)
- BEGIN_MESSAGE_MAP(CReportCreatorView, CView)
- //{{AFX_MSG_MAP(CReportCreatorView)
- ON_WM_ERASEBKGND()
- ON_WM_SIZE()
- /* ON_COMMAND(ID_BUTTON_SETTINGS, OnButtonSettings)*/
- ON_COMMAND(ID_REPORT_GRID, OnButtonGrid)
- ON_UPDATE_COMMAND_UI(ID_REPORT_GRID, OnUpdateButtonGrid)
- /* ON_COMMAND(ID_BUTTON_MARGIN, OnButtonMargin)
- ON_UPDATE_COMMAND_UI(ID_BUTTON_MARGIN, OnUpdateButtonMargin)*/
- ON_COMMAND(ID_REPORT_SNAP_TO_GRID, OnButtonSnap)
- ON_UPDATE_COMMAND_UI(ID_REPORT_SNAP_TO_GRID, OnUpdateButtonSnap)
- ON_COMMAND(ID_REPORT_RECT, OnButtonAddBox)
- ON_COMMAND(ID_REPORT_LABEL, OnButtonAddLabel)
- ON_COMMAND(ID_REPORT_LINE, OnButtonAddLine)
- ON_COMMAND(ID_REPORT_COPY, OnEditCopy)
- ON_UPDATE_COMMAND_UI(ID_REPORT_COPY, OnUpdateEditCopy)
- ON_COMMAND(ID_REPORT_CUT, OnEditCut)
- ON_UPDATE_COMMAND_UI(ID_REPORT_CUT, OnUpdateEditCut)
- ON_COMMAND(ID_REPORT_PASTE, OnEditPaste)
- ON_UPDATE_COMMAND_UI(ID_REPORT_PASTE, OnUpdateEditPaste)
- ON_COMMAND(ID_REPORT_UNDO, OnEditUndo)
- ON_UPDATE_COMMAND_UI(ID_REPORT_UNDO, OnUpdateEditUndo)
- ON_COMMAND(ID_REPORT_ZOOM_IN, OnZoomIn)
- ON_COMMAND(ID_REPORT_ZOOM_OUT, OnZoomOut)
- ON_COMMAND(ID_REPORT_ALIGN_BOTTOM, OnButtonAlignBottom)
- ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_BOTTOM, OnUpdateButtonAlignBottom)
- ON_COMMAND(ID_REPORT_ALIGN_LEFT, OnButtonAlignLeft)
- ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_LEFT, OnUpdateButtonAlignLeft)
- ON_COMMAND(ID_REPORT_ALIGN_RIGHT, OnButtonAlignRight)
- ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_RIGHT, OnUpdateButtonAlignRight)
- ON_COMMAND(ID_REPORT_ALIGN_TOP, OnButtonAlignTop)
- ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_TOP, OnUpdateButtonAlignTop)
- ON_COMMAND(ID_REPORT_ALIGN_SIZES, OnButtonSameSize)
- ON_UPDATE_COMMAND_UI(ID_REPORT_ALIGN_SIZES, OnUpdateButtonSameSize)
- /*ON_COMMAND(ID_BUTTON_ZOOM_TO_FIT, OnButtonZoomToFit)
- ON_COMMAND(ID_BUTTON_PROPERTIES, OnButtonProperties)*/
- ON_COMMAND(ID_REPORT_PICTURE, OnButtonAddPicture)
- ON_WM_DESTROY()
- /*ON_COMMAND(ID_DELETE, OnDelete)
- ON_COMMAND(ID_INSERT, OnInsert)*/
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- ON_REGISTERED_MESSAGE(UWM_HSCROLL, OnEditorHScroll)
- ON_REGISTERED_MESSAGE(UWM_VSCROLL, OnEditorVScroll)
- ON_REGISTERED_MESSAGE(UWM_ZOOM, OnEditorZoom)
- ON_REGISTERED_MESSAGE(UWM_MOUSE, OnEditorMouse)
- ON_REGISTERED_MESSAGE(UWM_MEASUREMENTS, OnRulerMeasurements)
- ON_COMMAND(ID_REPORT_ADD_PAGE, OnReportAddPage)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CReportCreatorView construction/destruction
- CReportCreatorView::CReportCreatorView()
- /* ============================================================
- Function : CReportCreatorView::CReportCreatorView
- Description : Constructor
- Access : Public
- Return : void
- Parameters : none
- Usage :
- ============================================================*/
- {
- m_screenResolutionX = 0;
- m_current_editor = -1;
- m_pages_preview_dlg = NULL;
- }
- CReportCreatorView::~CReportCreatorView()
- /* ============================================================
- Function : CReportCreatorView::~CReportCreatorView
- Description : Destructor
- Access : Public
- Return : void
- Parameters : none
- Usage :
- ============================================================*/
- {
- }
- BOOL CReportCreatorView::PreCreateWindow(CREATESTRUCT& cs)
- /* ============================================================
- Function : CReportCreatorView::PreCreateWindow
- Description : Called befor the window is created
- Access : Public
- Return : BOOL - Not interested
- Parameters : CREATESTRUCT& cs - Not interested
- Usage : Called from MFC
- ============================================================*/
- {
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CReportCreatorView drawing
- void CReportCreatorView::OnDraw(CDC* pDC)
- /* ============================================================
- Function : CReportCreatorView::OnDraw
- Description : Draws the view
- Access : Public
- Return : void
- Parameters : CDC* pDC - "CDC" to draw to
- Usage : Called from MFC
- ============================================================*/
- {
- CReportCreatorDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- /* if( pDC->IsPrinting() )
- {
- COLORREF col = m_editors[m_current_editor].editor->GetBackgroundColor();
- // Print zoom is the difference between screen-
- // and printer resolution.
- double zoom = pDC->GetDeviceCaps( LOGPIXELSX ) / m_screenResolutionX;
- CRect rect( 0,0,
- round( static_cast< double >( m_editors[m_current_editor].editor->GetVirtualSize().cx ) * zoom ),
- round( static_cast< double >( m_editors[m_current_editor].editor->GetVirtualSize().cy ) * zoom ) );
- m_editors[m_current_editor].editor->SetRedraw( FALSE );
- m_editors[m_current_editor].editor->SetBackgroundColor( RGB( 255, 255, 255 ) );
- m_editors[m_current_editor].editor->Print( pDC, rect, zoom );
- m_editors[m_current_editor].editor->SetBackgroundColor( col );
- m_editors[m_current_editor].editor->SetRedraw( TRUE );
- }*/
- if( pDC->IsPrinting() )
- {
- // Print zoom is the difference between screen-
- // and printer resolution.
- /* double zoom = pDC->GetDeviceCaps( LOGPIXELSX ) / m_screenResolutionX;
- size_t sz = m_editors.size();
- int shftX = 0;
- int shftY = 0;
- for (size_t i=0;i<sz;i++)
- {
- COLORREF col = m_editors[i]->GetBackgroundColor();
- CRect rect( shftX,shftY,
- shftX+round( static_cast< double >( m_editors[i]->GetVirtualSize().cx ) * zoom ),
- shftY+round( static_cast< double >( m_editors[i]->GetVirtualSize().cy ) * zoom ) );
- m_editors[i]->SetRedraw( FALSE );
- m_editors[i]->SetBackgroundColor( RGB( 255, 255, 255 ) );
- m_editors[i]->Print( pDC, rect, zoom );
- m_editors[i]->SetBackgroundColor( col );
- m_editors[i]->SetRedraw( TRUE );
- shftX+=round( static_cast< double >( m_editors[i]->GetVirtualSize().cx ) * zoom );
- shftY+=round( static_cast< double >( m_editors[i]->GetVirtualSize().cy) * zoom) ;
- }
- */
- }
- else
- {
- CRect rct;
- GetClientRect(rct);
- pDC->FillSolidRect(rct,::GetSysColor(COLOR_3DSHADOW));
- }
- }
- static void SetPrinterMode(CDC* pDC,int Mode)
- {
- if(Mode !=DMORIENT_LANDSCAPE && Mode != DMORIENT_PORTRAIT)
- {
- ASSERT(0);
- return;
- }
- PRINTDLG* pPrintDlg = new PRINTDLG;
- AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg);
- DEVMODE* lpDevMode = (DEVMODE*)::GlobalLock(pPrintDlg->hDevMode);
- lpDevMode->dmOrientation = (short)Mode;
- pDC->ResetDC(lpDevMode);
- ::GlobalUnlock(pPrintDlg->hDevMode);
- delete pPrintDlg;
- }
- void CReportCreatorView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
- {
- CView::OnPrepareDC(pDC, pInfo);
- if (pDC->IsPrinting())
- SetPrinterMode(pDC,
- GetDocument()->GetData(pInfo->m_nCurPage-1)->GetPrinterMode());
- }
- void CReportCreatorView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
- {
- if( pDC->IsPrinting() )
- {
- // Print zoom is the difference between screen-
- // and printer resolution.
- double zoom = pDC->GetDeviceCaps( LOGPIXELSX ) / m_screenResolutionX;
- {
- COLORREF col = m_editors[pInfo->m_nCurPage-1].editor->GetBackgroundColor();
- CRect rect( 0,0,
- round( static_cast< double >( m_editors[pInfo->m_nCurPage-1].editor->GetVirtualSize().cx ) * zoom ),
- round( static_cast< double >( m_editors[pInfo->m_nCurPage-1].editor->GetVirtualSize().cy ) * zoom ) );
- m_editors[pInfo->m_nCurPage-1].editor->SetRedraw( FALSE );
- m_editors[pInfo->m_nCurPage-1].editor->SetBackgroundColor( RGB( 255, 255, 255 ) );
- m_editors[pInfo->m_nCurPage-1].editor->Print( pDC, /*rect*/pInfo->m_rectDraw, zoom );
- m_editors[pInfo->m_nCurPage-1].editor->SetBackgroundColor( col );
- m_editors[pInfo->m_nCurPage-1].editor->SetRedraw( TRUE );
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CReportCreatorView printing
- BOOL CReportCreatorView::OnPreparePrinting(CPrintInfo* pInfo)
- /* ============================================================
- Function : CReportCreatorView::OnPreparePrinting
- Description : Called before a printout
- Access : Public
- Return : BOOL - Not interested
- Parameters : CPrintInfo* pInfo - Not interested
- Usage : Called from MFC
- ============================================================*/
- {
- pInfo->SetMaxPage(m_editors.size());
- return DoPreparePrinting(pInfo);
- }
- void CReportCreatorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- /* ============================================================
- Function : CReportCreatorView::OnBeginPrinting
- Description : Called before a printout
- Access : Public
- Return : void
- Parameters : CDC* - Not interested
- CPrintInfo* - Not interested
- Usage : Called from MFC
- ============================================================*/
- {
- }
- void CReportCreatorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- /* ============================================================
- Function : CReportCreatorView::OnEndPrinting
- Description : Called after a printout
- Access : Public
- Return : void
- Parameters : CDC* - Not interested
- CPrintInfo* - Not interested
- Usage : Called from MFC
- ============================================================*/
- {
- SetCurrentPage(m_current_editor);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CReportCreatorView diagnostics
- #ifdef _DEBUG
- void CReportCreatorView::AssertValid() const
- /* ============================================================
- Function : CReportCreatorView::AssertValid
- Description : Checks object validity
- Access : Public
- Return : void
- Parameters : none
- Usage : Debug function
- ============================================================*/
- {
- CView::AssertValid();
- }
- void CReportCreatorView::Dump(CDumpContext& dc) const
- /* ============================================================
- Function : CReportCreatorView::Dump
- Description : Dumps object data
- Access : Public
- Return : void
- Parameters : CDumpContext& dc - Dump context
- Usage : Debug function
- ============================================================*/
- {
- CView::Dump(dc);
- }
- CReportCreatorDoc* CReportCreatorView::GetDocument()
- /* ============================================================
- Function : CReportCreatorView::GetDocument
- Description : Returns a pointer to the current document
- Access : Public
- Return : CReportCreatorDoc* - Current document
- Parameters : none
- Usage : Call to get a pointer to the view document.
- ============================================================*/
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CReportCreatorDoc)));
- return (CReportCreatorDoc*)m_pDocument;
- }
- #endif //_DEBUG
- void CReportCreatorView::AddPage(CDiagramEntityContainer* cont, bool vertiacal, bool repaint/*=true*/)
- {
- //if( !m_editors[m_current_editor].editor->m_hWnd )
- //{
- int restraintMode = RESTRAINT_MARGIN;//theApp.GetProfileInt( _T( "Application" ), _T( "Restraint" ), 0 );
- int left = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Left" ), 0 );
- int right = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Right" ), 0 );
- int top = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Top" ), 0 );
- int bottom = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Bottom" ), 0 );
- int width = -1;//theApp.GetProfileInt( _T( "Application" ), _T( "Width" ), -1 );
- int height = -1;//theApp.GetProfileInt( _T( "Application" ), _T( "Height" ), -1 );
- COLORREF colorBg = RGB( 255, 255, 255 );//( COLORREF ) theApp.GetProfileInt( _T( "Application" ), _T( "ColorBg" ), RGB( 255, 255, 255 ) );
- COLORREF colorGrid = RGB( 222, 222, 222 );//( COLORREF ) theApp.GetProfileInt( _T( "Application" ), _T( "ColorGrid" ), RGB( 222, 222, 222 ) );
- COLORREF colorMargin = RGB( 0, 0, 255 );//( COLORREF ) theApp.GetProfileInt( _T( "Application" ), _T( "ColorMargin" ), RGB( 0, 0, 255 ) );
- BOOL margin = TRUE;//( BOOL ) theApp.GetProfileInt( _T( "Application" ), _T( "Margin" ), FALSE );
- BOOL grid = TRUE;//( BOOL ) theApp.GetProfileInt( _T( "Application" ), _T( "Grid" ), FALSE );
- BOOL snap = TRUE;//( BOOL ) theApp.GetProfileInt( _T( "Application" ), _T( "Snap" ), FALSE );
- int measurements = 0;//theApp.GetProfileInt( _T( "Application" ), _T( "Units" ), 0 );
- CReportEntitySettings::GetRESInstance()->SetMeasurementUnits( measurements );
- double zoom = 0.50;//static_cast< double >( theApp.GetProfileInt( _T( "Application" ), _T( "ZoomLevel" ), 100 ) ) / 100;
- double zoomfactor = 0.2;//static_cast< double >( theApp.GetProfileInt( _T( "Application" ), _T( "ZoomFactor" ), 1 ) ) / 100;
- CRect rect;
- GetClientRect( rect );
- rect.left = RULER_SIZE;
- rect.top = RULER_SIZE;
- CReportEditor* newEditor = new CReportEditor;
- int printer_mode = (vertiacal)?DMORIENT_PORTRAIT:DMORIENT_LANDSCAPE;
- CDiagramEntityContainer* Doc_data = (cont)?cont:
- GetDocument()->CreateNewDiagramEntityContainer(NULL,printer_mode) ;
- if (!Doc_data)
- {
- ASSERT(Doc_data);
- delete newEditor;
- return;
- }
- newEditor->Create( WS_CHILD | WS_VISIBLE, rect, this,Doc_data);
- CHorzRuler* newHorzRuler = new CHorzRuler;
- CVertRuler* newVertRuler = new CVertRuler;
- CCornerBox* newCornerBox = new CCornerBox;
- rect.top = 0;
- rect.bottom = RULER_SIZE;
- newHorzRuler->Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, 100 );
- GetClientRect( rect );
- rect.right = RULER_SIZE;
- rect.top = RULER_SIZE;
- newVertRuler->Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, 101 );
- rect.left = 0;
- rect.top = 0;
- rect.right = RULER_SIZE;
- rect.bottom = RULER_SIZE;
- newCornerBox->Create( NULL, NULL, WS_CHILD | WS_VISIBLE, rect, this, 102 );
- newHorzRuler->SetMeasurements( measurements );
- newVertRuler->SetMeasurements( measurements );
- newCornerBox->SetMeasurements( measurements );
- CClientDC dc( this );
- m_screenResolutionX = dc.GetDeviceCaps( LOGPIXELSX );
- CUnitConversion::Init( m_screenResolutionX );
- int step = m_screenResolutionX / 6;
- int gridSize = step;//theApp.GetProfileInt( _T( "Application" ), _T( "GridSize" ), step );
- if( width == -1 )
- {
- CPrintDialog printer( TRUE, PD_RETURNDC );
- printer.GetDefaults();
- HDC hdc = printer.GetPrinterDC();
- if (cont==NULL) // 漕徉怆