/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ // barsView.cpp : implementation of the CBarsView class // #include //For OleCurrencyType #include #include #include #include "stdafx.h" #include "bars.h" #include "barsdoc.h" #include "barsview.h" #include "Axis.h" #include "AxisCollection.h" #include "Bar.h" #include "Border.h" #include "Chart3DData.h" #include "ChartArea.h" #include "ChartGroup.h" #include "ChartGroupCollection.h" #include "ChartLabel.h" #include "ChartLabelCollection.h" #include "Coord.h" #include "DataColor.h" #include "DataColorCollection.h" #include "DerivedLong.h" #include "Elevation.h" #include "Font.h" #include "GridLines.h" #include "Interior.h" #include "Label.h" #include "Location.h" #include "PlotCube.h" #include "CubeFont.h" #include "Title.h" #include "LineStyle.h" #include "3dconst.h" #include "oc_color.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CBarsView IMPLEMENT_DYNCREATE(CBarsView, CFormView) BEGIN_MESSAGE_MAP(CBarsView, CFormView) //{{AFX_MSG_MAP(CBarsView) ON_WM_CREATE() ON_WM_DESTROY() ON_WM_SIZE() ON_WM_TIMER() ON_COMMAND(ID_FONT_STROKE, OnFontStroke) ON_UPDATE_COMMAND_UI(ID_FONT_STROKE, OnUpdateFontStroke) ON_COMMAND(ID_FONT_TRUETYPE, OnFontTruetype) ON_UPDATE_COMMAND_UI(ID_FONT_TRUETYPE, OnUpdateFontTruetype) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CBarsView construction/destruction CBarsView::CBarsView() : CFormView(CBarsView::IDD) { //{{AFX_DATA_INIT(CBarsView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // TODO: add construction code here } CBarsView::~CBarsView() { } void CBarsView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CBarsView) DDX_Control(pDX, IDC_CHART3D, m_chart); //}}AFX_DATA_MAP } BOOL CBarsView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CBarsView diagnostics #ifdef _DEBUG void CBarsView::AssertValid() const { CFormView::AssertValid(); } void CBarsView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CBarsDoc* CBarsView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBarsDoc))); return (CBarsDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CBarsView message handlers ///////////////////////////////////////////////////////////////////////////// // Do some eary setup ///////////////////////////////////////////////////////////////////////////// int CBarsView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFormView::OnCreate(lpCreateStruct) == -1) return -1; m_PickRow = 0; m_PickCol = 0; m_LastRow = 0; m_LastCol = 0; m_IsModifying = false; m_HiLiteColor = ocColorRosyBrown; m_BarHiLiteColor = ocColorLightSeaGreen; m_Interior = NULL; return 0; } ///////////////////////////////////////////////////////////////////////////// // Setup the Form and the Chart ///////////////////////////////////////////////////////////////////////////// void CBarsView::OnInitialUpdate() { CFormView::OnInitialUpdate(); // Pre-Define some variables for easier reference later m_cGroup = m_chart.GetChartGroups().GetItem(COleVariant(short(1))); m_AxisX = m_chart.GetChartArea().GetAxes().GetItem(COleVariant("x")); m_AxisY = m_chart.GetChartArea().GetAxes().GetItem(COleVariant("y")); m_AxisZ = m_chart.GetChartArea().GetAxes().GetItem(COleVariant("z")); COleCurrency hFontSize; // Batch all the updates to the Chart m_chart.SetIsBatched(true); // Set the Chart type to bar m_chart.GetChartGroups().GetItem(COleVariant((short)1)).SetChartType(oc3dTypeBar); // Setup some colors m_chart.GetInterior().SetBackgroundColor(ocColorLinen); m_chart.GetInterior().SetForegroundColor(ocColorBlack); // Setup the borders m_chart.GetBorder().SetType(oc3dBorder3DIn); m_chart.GetBorder().SetWidth(2); // Setup the ChartArea m_chart.GetChartArea().GetInterior().SetBackgroundColor(ocColorAntiqueWhite); m_chart.GetChartArea().GetBorder().SetType(oc3dBorderEtchedIn); m_chart.GetChartArea().GetBorder().SetWidth(4); m_chart.GetChartArea().GetPlotCube().GetInterior().SetBackgroundColor(ocColorLemonChiffon); // Setup the Data Group m_cGroup.GetElevationData().SetRowCount(3); m_cGroup.GetElevationData().SetColumnCount(5); m_cGroup.GetElevation().SetIsShaded(true); // Setup the scale m_chart.GetChartArea().GetPlotCube().SetXScale(200); m_chart.GetChartArea().GetPlotCube().SetYScale(200); // Setup the Axis m_AxisX.GetAnnotationFont().SetStroke(oc3dRomanSimplex); m_AxisX.GetAnnotationFont().SetSize(60); m_AxisX.GetTitle().SetText("Rows"); m_AxisY.GetTitle().SetText("Columns"); m_AxisX.GetTitleFont().SetStroke(oc3dRomanTriplex); m_AxisX.GetTitleFont().SetSize(100); // Turn on all the Axis grid lines m_AxisX.GetMajorGrid().SetIsOnXYPlane(true); m_AxisX.GetMajorGrid().SetIsOnXZPlane(true); m_AxisY.GetMajorGrid().SetIsOnXYPlane(true); m_AxisY.GetMajorGrid().SetIsOnYZPlane(true); m_AxisZ.GetMajorGrid().SetIsOnXZPlane(true); m_AxisZ.GetMajorGrid().SetIsOnYZPlane(true); // Set the gridline styles m_AxisX.GetMajorGrid().GetStyle().SetColor(ocColorCadetBlue); m_AxisY.GetMajorGrid().GetStyle().SetColor(ocColorCadetBlue); m_AxisZ.GetMajorGrid().GetStyle().SetColor(ocColorCadetBlue); m_AxisX.GetMajorGrid().GetStyle().SetWidth(2); m_AxisY.GetMajorGrid().GetStyle().SetWidth(2); m_AxisZ.GetMajorGrid().GetStyle().SetWidth(2); // Setup the header m_chart.GetHeader().GetText().SetText("Change the value of\nany bar by dragging it!"); m_chart.GetHeader().GetBorder().SetType(oc3dBorderEtchedOut); m_chart.GetHeader().GetBorder().SetWidth(4); m_chart.GetHeader().GetInterior().SetBackgroundColor(ocColorLightGoldenrod); m_chart.GetHeader().GetFont().SetName("Arial"); hFontSize.SetCurrency(14, 0); m_chart.GetHeader().GetFont().SetSize(hFontSize); m_chart.GetHeader().GetFont().SetBold(true); // Setup the footer m_chart.GetFooter().GetText().SetText("No Bar Selected"); m_chart.GetFooter().GetBorder().SetType(oc3dBorderShadow); m_chart.GetFooter().GetBorder().SetWidth(4); m_chart.GetFooter().GetInterior().SetBackgroundColor(ocColorBlanchedAlmond); m_chart.GetFooter().GetFont().SetName("Times New Roman"); hFontSize.SetCurrency(12, 0); m_chart.GetFooter().GetFont().SetSize(hFontSize); //Add colors to the bars and do the entire column for each row m_chart.GetChartArea().GetBar().GetColors().Add(COleVariant(short(1)), COleVariant(short(0)), ocColorBeige); m_chart.GetChartArea().GetBar().GetColors().Add(COleVariant(short(2)), COleVariant(short(0)), ocColorBlanchedAlmond); m_chart.GetChartArea().GetBar().GetColors().Add(COleVariant(short(3)), COleVariant(short(0)), ocColorTan); // Go back to normal Chart updates m_chart.SetIsBatched(false); m_HeaderColor = m_chart.GetHeader().GetInterior().GetBackgroundColor(); m_FooterColor = m_chart.GetFooter().GetInterior().GetBackgroundColor(); // Setup the ChartLabel now for easier use later m_chart.GetChartLabels().RemoveAll(); CChartLabel cLbl(m_chart.GetChartLabels().Add()); cLbl.SetIsBatched(true); cLbl.GetText().SetText(""); cLbl.SetName("Region"); cLbl.SetAttachMethod(oc3dAttachCoord); cLbl.GetAttachCoord().SetX(0); cLbl.GetAttachCoord().SetY(0); cLbl.SetVerticalOffset(0); cLbl.SetHorizontalOffset(0); cLbl.GetInterior().SetBackgroundColor(m_HiLiteColor); cLbl.GetBorder().SetType(oc3dBorderShadow); cLbl.GetBorder().SetWidth(4); cLbl.SetIsConnected(false); cLbl.SetIsShowing(false); cLbl.SetIsBatched(false); UpdateFooter(0, 0); } ///////////////////////////////////////////////////////////////////////////// // Release some variables before we exit the program ///////////////////////////////////////////////////////////////////////////// void CBarsView::OnDestroy() { CFormView::OnDestroy(); // Release the global variables m_cGroup.DetachDispatch(); m_AxisX.DetachDispatch(); m_AxisY.DetachDispatch(); m_AxisZ.DetachDispatch(); m_Interior.DetachDispatch(); } ///////////////////////////////////////////////////////////////////////////// // Remove the HiLite Label ///////////////////////////////////////////////////////////////////////////// void CBarsView::RemoveLabel() { if (m_chart.GetChartLabels().GetItem(COleVariant(short(1))).GetText().GetText() != "") { m_chart.GetChartLabels().GetItem(COleVariant(short(1))).SetIsConnected(false); m_chart.GetChartLabels().GetItem(COleVariant(short(1))).GetText().SetText(""); m_chart.GetChartLabels().GetItem(COleVariant(short(1))).SetIsShowing(false); } } ///////////////////////////////////////////////////////////////////////////// // Remove the HiLite ///////////////////////////////////////////////////////////////////////////// void CBarsView::RemoveHiLite() { m_chart.SetIsBatched(true); RemoveLabel(); KillTimer(1212); if (m_Interior != NULL) { TRACE0("Resetting the Background!\n"); m_Interior.SetBackgroundColor(m_RegionSaveColor); } UpdateFooter(0, 0); m_chart.SetIsBatched(false); } ///////////////////////////////////////////////////////////////////////////// // Add a HiLite to the Header/Footer ///////////////////////////////////////////////////////////////////////////// void CBarsView::AddHiLite(long x, long y) { m_Interior.SetBackgroundColor(m_HiLiteColor); CChartLabel cLbl(m_chart.GetChartLabels().GetItem(COleVariant(short(1)))); cLbl.SetIsBatched(true); switch (m_Region) { case oc3dRegionInHeader: cLbl.GetText().SetText("That's the Header!"); cLbl.GetAttachCoord().SetX(m_chart.GetHeader().GetLocation().GetLeft().GetValue() + m_chart.GetHeader().GetLocation().GetWidth().GetValue()); cLbl.GetAttachCoord().SetY(m_chart.GetHeader().GetLocation().GetTop().GetValue() + m_chart.GetHeader().GetLocation().GetHeight().GetValue()); cLbl.SetVerticalOffset(25); cLbl.SetHorizontalOffset(25); break; case oc3dRegionInFooter: cLbl.GetText().SetText("That's the Footer!"); cLbl.GetAttachCoord().SetX(m_chart.GetFooter().GetLocation().GetLeft().GetValue() + m_chart.GetFooter().GetLocation().GetWidth().GetValue()); cLbl.GetAttachCoord().SetY(m_chart.GetFooter().GetLocation().GetTop().GetValue()); cLbl.SetVerticalOffset(-25); cLbl.SetHorizontalOffset(25); break; } cLbl.SetIsShowing(true); cLbl.SetIsConnected(true); cLbl.SetIsBatched(false); SetTimer(1212, 1500, NULL); UpdateFooter(0, 0); } ///////////////////////////////////////////////////////////////////////////// // Update the information in the footer ///////////////////////////////////////////////////////////////////////////// void CBarsView::UpdateFooter(long Row, long Col) { char szBuffer[80]; double Value; if ((Row > 0) && (Col > 0)) { Value = m_cGroup.GetElevationData().GetValue(Row, Col); sprintf(szBuffer, "Bar Index(%d, %d) = %2.2f", Row, Col, Value); m_chart.GetFooter().GetText().SetText(szBuffer); } else { if (m_chart.GetFooter().GetText().GetText() != "No Bar Selected") { m_chart.GetFooter().GetText().SetText("No Bar Selected"); } } } BEGIN_EVENTSINK_MAP(CBarsView, CFormView) //{{AFX_EVENTSINK_MAP(CBarsView) ON_EVENT(CBarsView, IDC_CHART3D, -605 /* MouseDown */, Chart_OnMouseDown, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CBarsView, IDC_CHART3D, -606 /* MouseMove */, Chart_OnMouseMove, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CBarsView, IDC_CHART3D, -607 /* MouseUp */, Chart_OnMouseUp, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CBarsView, IDC_CHART3D, 1 /* ModifyEnd */, Chart_OnModifyEnd, VTS_NONE) ON_EVENT(CBarsView, IDC_CHART3D, 2 /* ModifyStart */, Chart_OnModifyStart, VTS_PBOOL) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() ///////////////////////////////////////////////////////////////////////////// // The user has pressed a Mouse-Button while over the Chart ///////////////////////////////////////////////////////////////////////////// void CBarsView::Chart_OnMouseDown(short Button, short Shift, long x, long y) { if (m_IsModifying) { return; } long Row, Col, Distance; if ((Button == 1) && (Shift == 0)) { m_Region = m_cGroup.CoordToDataIndex(x, y, &Row, &Col, &Distance); if ((m_Region == oc3dRegionInChartArea) && (Row > 0) && (Col > 0) && (Distance == 0)) { m_PickRow = Row; m_PickCol = Col; } } } ///////////////////////////////////////////////////////////////////////////// // The user is moving the mouse over the Chart ///////////////////////////////////////////////////////////////////////////// void CBarsView::Chart_OnMouseMove(short Button, short Shift, long x, long y) { if (m_IsModifying) { return; } long Row, Col, Distance; double Value; m_OldRegion = m_Region; // If we are dragging a bar, update it and the footer if ((m_PickRow != 0) && (m_PickCol != 0)) { m_chart.SetIsBatched(true); Value = m_cGroup.DragZValue(m_PickRow, m_PickCol, x, y); if (Value > 15) { Value = 15; } if (Value < -15) { Value = -15; } m_cGroup.GetElevationData().SetValue(m_PickRow, m_PickCol, Value); UpdateFooter(m_PickRow, m_PickCol); m_chart.SetIsBatched(false); } // If we are over the footer or header, highlight it for a short time else { m_Region = m_cGroup.CoordToDataIndex(x, y, &Row, &Col, &Distance); if (((m_Region == oc3dRegionInHeader) || (m_Region == oc3dRegionInFooter)) && (m_Region != m_OldRegion)) { switch (m_Region) { case oc3dRegionInHeader: RemoveHiLite(); m_RegionSaveColor = m_HeaderColor; m_Interior = m_chart.GetHeader().GetInterior(); AddHiLite(x, y); break; case oc3dRegionInFooter: RemoveHiLite(); m_RegionSaveColor = m_FooterColor; m_Interior = m_chart.GetFooter().GetInterior(); AddHiLite(x, y); break; } } // If the mouse has left the ChartArea, then remove the highlight off of the currently highlighted bar else { if ((m_Region != oc3dRegionInChartArea) || (Row <= 0) || (Col <= 0) || (Distance != 0)) { Row = 0; Col = 0; if ((m_LastRow > 0) && (m_LastCol > 0)) { m_chart.GetChartArea().GetBar().GetColors().Remove(COleVariant(short(m_LastRow)), COleVariant(short(m_LastCol))); } m_LastRow = 0; m_LastCol = 0; UpdateFooter(Row, Col); } // We have changed 'selected' bar, so remove the old highlight and add the new one else { if ((Row != m_LastRow) || (Col != m_LastCol)) { m_chart.SetIsBatched(true); if ((m_LastRow > 0) && (m_LastCol > 0)) { m_chart.GetChartArea().GetBar().GetColors().Remove(COleVariant(short(m_LastRow)), COleVariant(short(m_LastCol))); } if ((Row > 0) && (Col > 0)) { m_chart.GetChartArea().GetBar().GetColors().Add(COleVariant(short(Row)), COleVariant(short(Col)), m_BarHiLiteColor); } UpdateFooter(Row, Col); m_LastRow = Row; m_LastCol = Col; m_chart.SetIsBatched(false); } } } } } ///////////////////////////////////////////////////////////////////////////// // The user has let the mouse button go while over the Chart ///////////////////////////////////////////////////////////////////////////// void CBarsView::Chart_OnMouseUp(short Button, short Shift, long x, long y) { m_PickRow = 0; m_PickCol = 0; } ///////////////////////////////////////////////////////////////////////////// // Let the Chart know it can be modified ///////////////////////////////////////////////////////////////////////////// void CBarsView::Chart_OnModifyEnd() { m_IsModifying = false; } ///////////////////////////////////////////////////////////////////////////// // Let the Chart know it can't be modified ///////////////////////////////////////////////////////////////////////////// void CBarsView::Chart_OnModifyStart(BOOL FAR* IsOK) { m_IsModifying = true; } ///////////////////////////////////////////////////////////////////////////// // Resize the Chart to the size of the window ///////////////////////////////////////////////////////////////////////////// void CBarsView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); // size the chart to fit the window if ((cx > 0) && (cy > 0)) { if (IsWindow(m_chart.m_hWnd)) { m_chart.MoveWindow(0, 0, cx, cy, true); } } } ///////////////////////////////////////////////////////////////////////////// // Respond to the Timer ///////////////////////////////////////////////////////////////////////////// void CBarsView::OnTimer(UINT nIDEvent) { //Remove the HiLite from the Header/Footer RemoveHiLite(); CFormView::OnTimer(nIDEvent); } void CBarsView::OnFontStroke() { m_chart.SetUseTrueType(FALSE); } void CBarsView::OnUpdateFontStroke(CCmdUI* pCmdUI) { pCmdUI->SetCheck(!m_chart.GetUseTrueType()); } void CBarsView::OnFontTruetype() { m_chart.SetUseTrueType(TRUE); } void CBarsView::OnUpdateFontTruetype(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_chart.GetUseTrueType()); }