/* * (c) Copyright Ascensio System SIA 2010-2014 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation. In accordance with * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * that Ascensio System SIA expressly excludes the warranty of non-infringement * of any third-party rights. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, * EU, LV-1021. * * The interactive user interfaces in modified source and object code versions * of the Program must display Appropriate Legal Notices, as required under * Section 5 of the GNU AGPL version 3. * * Pursuant to Section 7(b) of the License you must retain the original Product * logo when distributing the program. Pursuant to Section 7(e) we decline to * grant you any rights under trademark law for use of our trademarks. * * All the Product's GUI elements, including illustrations and icon sets, as * well as technical writing content are licensed under the terms of the * Creative Commons Attribution-ShareAlike 4.0 International. See the License * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ #pragma once #ifndef OOX_CHART_FILE_INCLUDE_H_ #define OOX_CHART_FILE_INCLUDE_H_ #include "../CommonInclude.h" #include "Title.h" #include "Legend.h" #include "PlotArea.h" #include "ChartStyle.h" #include "../../DocxFormat/Logic/AlternateContent.h" namespace OOX { namespace Spreadsheet { static TCHAR* gc_sChartArea = _T("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"); static TCHAR* gc_sChartLine = _T("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"); static TCHAR* gc_sChartPie = _T("%s%s%s%s%s%s%s%s"); static TCHAR* gc_sChartScatter = _T("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"); static TCHAR* gc_sChartBar = _T("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"); static TCHAR* gc_sChartStock = _T("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"); class CChart : public WritingElement { public: WritingElementSpreadsheet_AdditionConstructors(CChart) CChart() { } virtual ~CChart() { } public: virtual CString toXML() const { return _T(""); } virtual void toXML(CStringWriter& writer) const { } virtual void toXML2(CStringWriter& writer, nullable oChartStyle, CString& sSpPr) const { if(m_oPlotArea.IsInit() && m_oPlotArea->m_oBasicChart.IsInit()) { CString sChartPattern; bool bPie = false; bool bBar = false; bool bScatter = false; bool bLine = false; switch(m_oPlotArea->m_oBasicChart->m_eType) { case OOX::Spreadsheet::chartbasicBarChart: case OOX::Spreadsheet::chartbasicBar3DChart: sChartPattern = gc_sChartBar;bBar = true;break; case OOX::Spreadsheet::chartbasicRadarChart: case OOX::Spreadsheet::chartbasicAreaChart: sChartPattern = gc_sChartArea;break; case OOX::Spreadsheet::chartbasicLineChart: case OOX::Spreadsheet::chartbasicLine3DChart: sChartPattern = gc_sChartLine;bLine = true;break; case OOX::Spreadsheet::chartbasicPieChart: case OOX::Spreadsheet::chartbasicDoughnutChart: sChartPattern = gc_sChartPie;bPie = true;break; case OOX::Spreadsheet::chartbasicBubbleChart: case OOX::Spreadsheet::chartbasicScatterChart: sChartPattern = gc_sChartScatter;bScatter = true;break; case OOX::Spreadsheet::chartbasicStockChart: sChartPattern = gc_sChartStock;break; default:sChartPattern = gc_sChartLine; } CString title; if(m_oTitle.IsInit()) { CStringWriter sTempWriter; m_oTitle->toXML(sTempWriter); title = sTempWriter.GetCString(); } CString style; if(oChartStyle.IsInit()) style = oChartStyle->toXML(); else { CChartStyle oCChartStyle; style = oCChartStyle.toXML(); } CString sBarDir; CString sGrouping; CString sSeries; CString sDataLabels; CString sOverlap; CString sCatAxDelete; CString sCatAxMajorGrid; CString sCatAxTitle; CString sCatTxPr; CString sValAxDelete; CString sValAxMajorGrid; CString sValAxTitle; CString sValTxPr; m_oPlotArea->toXML2(bScatter, bLine, sBarDir, sGrouping, sSeries, sDataLabels, sOverlap, sCatAxDelete, sCatAxMajorGrid, sCatAxTitle, sCatTxPr, sValAxDelete, sValAxMajorGrid, sValAxTitle, sValTxPr); CStringWriter legend; if(m_oLegend.IsInit()) m_oLegend->toXML(legend); CString sChart; if(bPie) sChart.Format(sChartPattern, style, title, sBarDir, sGrouping, sSeries, sDataLabels, legend.GetCString(), sSpPr); else if(bBar) { CString sDLblPos = _T(""); if(m_oPlotArea->m_oBasicChart.IsInit() && m_oPlotArea->m_oBasicChart->m_oGrouping.IsInit() && m_oPlotArea->m_oBasicChart->m_oGrouping->m_oVal.IsInit()) { switch(m_oPlotArea->m_oBasicChart->m_oGrouping->m_oVal->GetValue()) { case SimpleTypes::Spreadsheet::chartbargroupingPercentStacked : sDLblPos = _T("");break; case SimpleTypes::Spreadsheet::chartbargroupingStacked : sDLblPos = _T("");break; } } sChart.Format(sChartPattern, style, title, sBarDir, sGrouping, sSeries, sDLblPos, sDataLabels, sOverlap, sCatAxDelete, sCatAxMajorGrid, sCatAxTitle, sCatTxPr, sValAxDelete, sValAxMajorGrid, sValAxTitle, sValTxPr, legend.GetCString(), sSpPr); } else sChart.Format(sChartPattern, style, title, sBarDir, sGrouping, sSeries, sDataLabels, sCatAxDelete, sCatAxMajorGrid, sCatAxTitle, sCatTxPr, sValAxDelete, sValAxMajorGrid, sValAxTitle, sValTxPr, legend.GetCString(), sSpPr); writer.WriteStringC(sChart); } } virtual void fromXML(XmlUtils::CXmlLiteReader& oReader) { ReadAttributes( oReader ); if ( oReader.IsEmptyNode() ) return; int nCurDepth = oReader.GetDepth(); while( oReader.ReadNextSiblingNode( nCurDepth ) ) { CWCharWrapper sName = oReader.GetName(); if ( _T("c:title") == sName ) m_oTitle = oReader; else if ( _T("c:legend") == sName ) m_oLegend = oReader; else if ( _T("c:plotArea") == sName ) m_oPlotArea = oReader; } } virtual EElementType getType () const { return et_c_Chart; } bool isValid() { if(m_oPlotArea.IsInit() && m_oPlotArea->m_oBasicChart.IsInit()) { return OOX::Spreadsheet::chartbasicBubbleChart != m_oPlotArea->m_oBasicChart->m_eType; } return false; } private: void ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { } public: nullable m_oTitle; nullable m_oLegend; nullable m_oPlotArea; }; class CChartSpace : public OOX::FileGlobalEnumerated, public OOX::Spreadsheet::IFileContainer { public: CChartSpace() { } CChartSpace(const CPath& oPath) { read( oPath ); } virtual ~CChartSpace() { } public: virtual void read(const CPath& oPath) { m_oReadPath = oPath; IFileContainer::Read( oPath ); XmlUtils::CXmlLiteReader oReader; if ( !oReader.FromFile( oPath.GetPath() ) ) return; if ( !oReader.ReadNextNode() ) return; CWCharWrapper sName = oReader.GetName(); if ( _T("c:chartSpace") == sName ) { ReadAttributes( oReader ); if ( !oReader.IsEmptyNode() ) { int nStylesDepth = oReader.GetDepth(); while ( oReader.ReadNextSiblingNode( nStylesDepth ) ) { sName = oReader.GetName(); if ( _T("c:chart") == sName ) m_oChart = oReader; else if ( _T("c:style") == sName ) m_oStyle = oReader; else if ( _T("mc:AlternateContent") == sName ) m_oAlternateContent = oReader; else if ( _T("c:spPr") == sName ) m_sSpPr = oReader.GetOuterXml(); } } } } virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const { if(isValid()) { write2(oPath.GetPath()); oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() ); IFileContainer::Write(oPath, oDirectory, oContent); } } bool write2(const CString& sFilename) const { bool bRes = false; if(isValid()) { CStringWriter sXml; toXML(sXml); CDirectory::SaveToFile( sFilename, sXml.GetCString() ); bRes = true; } return bRes; } bool isValid() const { return m_oChart.IsInit() && m_oChart->isValid(); } void toXML(CStringWriter& sXml) const { CString sSpPr; if(m_sSpPr.IsInit()) sSpPr = m_sSpPr.get(); m_oChart->toXML2(sXml, m_oStyle, sSpPr); } virtual const OOX::FileType type() const { return OOX::Spreadsheet::FileTypes::Charts; } virtual const CPath DefaultDirectory() const { return type().DefaultDirectory(); } virtual const CPath DefaultFileName() const { return type().DefaultFileName(); } const CPath& GetReadPath() { return m_oReadPath; } private: CPath m_oReadPath; void ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { } public: nullable m_oChart; nullable m_oStyle; nullable m_oAlternateContent; nullable m_sSpPr; }; } } #endif // OOX_CHART_FILE_INCLUDE_H_