diff options
author | iha/tbe <iha@openoffice.org> | 2012-08-02 12:13:32 +0200 |
---|---|---|
committer | Petr Mladek <pmladek@suse.cz> | 2012-08-02 12:13:32 +0200 |
commit | 0d2d24f7520308c64219eef7db42fb6471364878 (patch) | |
tree | ff60420914f38f3df656a129bb90e1a48eb336e8 | |
parent | binfilter: fix some warnings (diff) | |
download | binfilter-0d2d24f7520308c64219eef7db42fb6471364878.tar.gz binfilter-0d2d24f7520308c64219eef7db42fb6471364878.zip |
sds chart binfilter import
Signed-off-by: Petr Mladek <pmladek@suse.cz>
19 files changed, 817 insertions, 992 deletions
diff --git a/binfilter/bf_sch/source/core/sch_calculat.cxx b/binfilter/bf_sch/source/core/sch_calculat.cxx index f158821f3..401c02cb3 100644 --- a/binfilter/bf_sch/source/core/sch_calculat.cxx +++ b/binfilter/bf_sch/source/core/sch_calculat.cxx @@ -36,13 +36,6 @@ // for performance measurement #include <rtl/logfile.hxx> -// Note: Enable the following to skip points in the resulting spline -// poly-polygon, if they have equal x-values rather than identical points. -// Unitl now, I think there are situations where the output might differ, if you -// do so, so it's not enabled by default. - -// #define SPLINE_OPTIMIZE_POINTS - #include "calculat.hxx" #include <algorithm> @@ -196,11 +189,6 @@ using namespace ::std; // -------------------------------------------------------------------------------- -// Calculation of Splines - - -// ---------------------------------------- - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/binfilter/bf_sch/source/core/sch_chartdoc.cxx b/binfilter/bf_sch/source/core/sch_chartdoc.cxx index b334bc2bc..cb14a149f 100644 --- a/binfilter/bf_sch/source/core/sch_chartdoc.cxx +++ b/binfilter/bf_sch/source/core/sch_chartdoc.cxx @@ -242,6 +242,11 @@ namespace binfilter { /*N*/ /*N*/ rDoc.LoadAttributes(rIn); /*N*/ } + if( rIn.GetError() != 0 ) //read error + { + return rIn;//handle error occured maybe in rDoc.LoadAttributes e.g. if memchart could not be read correctly + } + /*N*/ // <- Basisaufruf /*N*/ /*N*/ rDoc.GetItemPool().LoadCompleted(); diff --git a/binfilter/bf_sch/source/core/sch_chaxis.cxx b/binfilter/bf_sch/source/core/sch_chaxis.cxx index da2498594..2b9c18631 100644 --- a/binfilter/bf_sch/source/core/sch_chaxis.cxx +++ b/binfilter/bf_sch/source/core/sch_chaxis.cxx @@ -58,6 +58,7 @@ #include <bf_svx/fhgtitem.hxx> #include <bf_svx/svxids.hrc> +#include "arrayhelper.hxx" #include "float.h" #include "chaxis.hxx" #include "pairs.hxx" @@ -133,17 +134,12 @@ namespace binfilter { /*N*/ }; /*N*/ ChartAxis::~ChartAxis() /*N*/ { -/*N*/ if(mpTotal) -/*N*/ delete [] mpTotal; -/*N*/ -/*N*/ if(mpColStack) -/*N*/ delete [] mpColStack; -/*N*/ +/*N*/ delete [] mpTotal; +/*N*/ delete [] mpColStack; /*N*/ delete mpAxisAttr; /*N*/ mpAxisAttr=NULL; /*N*/ mpModel=NULL; -/*N*/ if(mpTextAttr) -/*N*/ delete mpTextAttr; +/*N*/ delete mpTextAttr; /*N*/ } /*N*/ ChartAxis::ChartAxis(ChartModel* pModel,long nId,long nUId) @@ -279,14 +275,18 @@ namespace binfilter { /*N*/ { /*N*/ if(nSize!=mnTotalSize) /*N*/ { -/*N*/ if(mpTotal) -/*N*/ delete [] mpTotal; +/*N*/ delete [] mpTotal; /*N*/ mnTotalSize = nSize; -/*N*/ mpTotal = new double[mnTotalSize]; +/*N*/ mpTotal = ArrayHelper<double>::create_long_size(mnTotalSize); + if(!mpTotal) + mnTotalSize=0; /*N*/ } /*N*/ -/*N*/ while(nSize--) -/*N*/ mpTotal[nSize]=0.0; + if(mpTotal) + { +/*N*/ while(nSize--) +/*N*/ mpTotal[nSize]=0.0; + } /*N*/ } /*N*/ mbTotalAlloc=TRUE; /*N*/ }; @@ -301,7 +301,9 @@ namespace binfilter { /*N*/ if(!mbTotalActual) /*N*/ CreateTotal(); /*N*/ -/*N*/ return mpTotal[n]; + if( mpTotal && n>=0 && n<mnTotalSize ) +/*N*/ return mpTotal[n]; + return 10.0; /*N*/ } /*N*/ void ChartAxis::CreateTotal() /*N*/ { @@ -328,7 +330,7 @@ namespace binfilter { /*N*/ for(long nRow=0;nRow<nRowCnt;nRow++) /*N*/ { /*N*/ nId=((const SfxInt32Item &)(mpModel->GetDataRowAttr(nRow).Get(SCHATTR_AXIS))).GetValue(); -/*N*/ if(nId==mnUId) +/*N*/ if(nId==mnUId && mpTotal) /*N*/ { /*N*/ for(nCol=0;nCol<nColCnt;nCol++) /*N*/ { @@ -348,13 +350,13 @@ namespace binfilter { // Stapeln der Werte je Col (für Liniencharts) /*N*/ void ChartAxis::InitColStacking(long nColCnt) /*N*/ { -/*N*/ -/*N*/ -/*N*/ if(mpColStack) -/*N*/ delete [] mpColStack; -/*N*/ mpColStack=new double[nColCnt]; -/*N*/ while(nColCnt--) -/*N*/ mpColStack[nColCnt]=0.0;//mfOrigin ????; +/*N*/ delete [] mpColStack; +/*N*/ mpColStack = ArrayHelper<double>::create_long_size(nColCnt); + if(mpColStack) + { +/*N*/ while(nColCnt--) +/*N*/ mpColStack[nColCnt]=0.0;//mfOrigin ????; + } /*N*/ } //Stapeln der Werte je Column (Stapeln bei LinienCharts) /*N*/ double ChartAxis::StackColData(double fData,long nCol,long nColCnt) @@ -363,8 +365,12 @@ namespace binfilter { /*N*/ InitColStacking(nColCnt);//falls noch nicht geschehen /*N*/ mbColStackOK=TRUE;//wird bei Initialise auf FALSE gesetzt /*N*/ -/*N*/ mpColStack[nCol]+=fData; -/*N*/ return mpColStack[nCol]; + if(mpColStack) + { +/*N*/ mpColStack[nCol]+=fData; +/*N*/ return mpColStack[nCol]; + } + return fData; /*N*/ } //Dies Funktion wird u.A. von Initialise gerufen (sehr früh im Buildvorgang) //Attribute innerer Schleifen (CretaeMarks, etc.) können hier in Variablen diff --git a/binfilter/bf_sch/source/core/sch_chtmod2a.cxx b/binfilter/bf_sch/source/core/sch_chtmod2a.cxx index 6e61f29b1..148c3f7f0 100644 --- a/binfilter/bf_sch/source/core/sch_chtmod2a.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmod2a.cxx @@ -55,6 +55,7 @@ #include "pairs.hxx" #include "globfunc.hxx" +#include "arrayhelper.hxx" #include <bf_svx/xlineit.hxx> // header for Line @@ -286,9 +287,9 @@ namespace binfilter { /*N*/ long nColCnt = GetColCount() ; /*N*/ long nRowCnt = GetRowCount() ; /*N*/ -/*N*/ double *pTotal = new double [nColCnt]; -/*N*/ SdrObjList **pRowLists = new SdrObjList* [nRowCnt]; -/*N*/ SdrObjList **pDescrLists = new SdrObjList* [nRowCnt]; +/*N*/ double *pTotal = ArrayHelper<double>::create_long_size(nColCnt); +/*N*/ SdrObjList **pRowLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); +/*N*/ SdrObjList **pDescrLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); /*N*/ DataDescription* pDescription = NULL; /*N*/ Size aDescrOfs; /*N*/ @@ -297,7 +298,15 @@ namespace binfilter { /*N*/ bShowYAxisTitle = FALSE; /*N*/ bShowZAxisTitle = FALSE; /*N*/ -/*N*/ SchObjGroup** pDescrGroups=new SchObjGroup*[nRowCnt]; +/*N*/ SchObjGroup** pDescrGroups = ArrayHelper<SchObjGroup*>::create_long_size(nRowCnt); + if( !pTotal || !pRowLists || !pDescrLists || !pDescrGroups ) + { + delete[] pTotal; + delete[] pRowLists; + delete[] pDescrLists; + delete[] pDescrGroups; + return pGroup; + } /*N*/ for(nRow=0;nRow<nRowCnt;nRow++) /*N*/ pDescrGroups[nRow]=NULL; /*N*/ @@ -539,8 +548,14 @@ namespace binfilter { /*N*/ /*N*/ Create2DBackplane(aRect, *pList, TRUE,CHSTACK_NONE); /*N*/ -/*N*/ SdrObjList ** pRowLists = new SdrObjList*[nRowCnt]; -/*N*/ SdrObjList ** pStatLists = new SdrObjList*[nRowCnt]; +/*N*/ SdrObjList ** pRowLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); +/*N*/ SdrObjList ** pStatLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); + if( !pRowLists || !pStatLists ) + { + delete[] pRowLists; + delete[] pStatLists; + return pGroup; + } /*N*/ Size aLegendSize (((SvxFontWidthItem &) pLegendAttr->Get (EE_CHAR_FONTWIDTH)).GetWidth (), /*N*/ ((SvxFontHeightItem &) pLegendAttr->Get (EE_CHAR_FONTHEIGHT)).GetHeight ()); /*N*/ @@ -560,8 +575,6 @@ namespace binfilter { /*N*/ pStatLists [0] = 0; /*N*/ /*N*/ XPolygon aPolygon ((unsigned short)nColCnt); -/*N*/ ::std::vector< ::std::pair< double, double > > aSplinePoints; -/*N*/ bool bIsSplineChart = ( IsSplineChart() != FALSE ); /*N*/ /*N*/ SfxItemSet aLineAttr(*pItemPool, XATTR_LINE_FIRST, XATTR_LINE_LAST, 0); /*N*/ @@ -598,7 +611,6 @@ namespace binfilter { /*N*/ long nPoints = 0; /*N*/ pLineObject = NULL; /*N*/ -/*N*/ aSplinePoints.clear(); /*N*/ /*N*/ for (nCol = 0; nCol < nColCnt; nCol++) /*N*/ { @@ -626,13 +638,6 @@ namespace binfilter { /*N*/ } /*N*/ aPolygon [(USHORT) nPoints].X () = nXPos; /*N*/ aPolygon [(USHORT) nPoints].Y () = nYPos; -/*N*/ if( bIsSplineChart ) -/*N*/ { -/*N*/ aSplinePoints.push_back( -/*N*/ ::std::pair< double, double >( -/*N*/ static_cast< double >( nXPos ), -/*N*/ static_cast< double >( nYPos ))); -/*N*/ } /*N*/ nPoints ++; /*N*/ /*N*/ aPoint.X () = nXPos; @@ -673,28 +678,7 @@ namespace binfilter { /*N*/ { /*N*/ XPolyPolygon aSeriesPoly; /*N*/ -/*N*/ if( bIsSplineChart ) -/*N*/ { -/*?*/ if (!( (eChartStyle == CHSTYLE_2D_CUBIC_SPLINE_XY) - || (eChartStyle == CHSTYLE_2D_CUBIC_SPLINE_SYMBOL_XY) - ) - ) -/*?*/ { -/*?*/ XPolygon aMeshPoly; -/*?*/ approxMesh( nGranularity, aMeshPoly, aPolygon, nPoints - 1, nSplineDepth ); -/*?*/ SchCalculationHelper::IntersectPolygonWithRectangle( -/*?*/ aMeshPoly, aClipRect, aSeriesPoly ); -/*?*/ } -/*?*/ -/*?*/ if( pLineObject ) -/*?*/ pLineObject->NbcSetPathPoly( aSeriesPoly ); -/*?*/ else -/*?*/ { -/*?*/ pLineObject = new SdrPathObj( OBJ_PLIN, aSeriesPoly ); -/*?*/ pRowLists[ nRow ]->NbcInsertObject( pLineObject); -/*?*/ } -/*?*/ } -/*N*/ else // series consits of lines + // line (or stripped spline) /*N*/ { /*N*/ SchCalculationHelper::IntersectPolygonWithRectangle( aPolygon, aClipRect, aSeriesPoly ); /*N*/ @@ -759,8 +743,14 @@ namespace binfilter { /*N*/ USHORT eStackMode = bStacked ? CHSTACK_MINMAX : CHSTACK_NONE; /*N*/ /*N*/ Size aYDescrSize; -/*N*/ SdrObjList ** pRowLists = new SdrObjList*[nRowCnt]; -/*N*/ SdrObjList ** pDescrLists = new SdrObjList*[nRowCnt]; +/*N*/ SdrObjList ** pRowLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); +/*N*/ SdrObjList ** pDescrLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); + if( !pRowLists || !pDescrLists ) + { + delete[] pRowLists; + delete[] pDescrLists; + return pGroup; + } /*N*/ DataDescription* pDescription = NULL; /*N*/ SdrObjList *pYAxisList = pChartYAxis->IsVisible() /*N*/ ? CreateGroup (*pList, CHOBJID_DIAGRAM_Y_AXIS, 0) @@ -813,7 +803,7 @@ namespace binfilter { /*N*/ /*N*/ XPolygon aLine (2); /*N*/ double fSteps = pChartYAxis->GetMax(); -/*N*/ double* fOldData = new double[nColCnt]; +/*N*/ double* fOldData = ArrayHelper<double>::create_long_size(nColCnt); /*N*/ double fAngle = F_PI / 2; /*N*/ /*N*/ Size aLegendSize (((SvxFontWidthItem &) pLegendAttr->Get (EE_CHAR_FONTWIDTH)).GetWidth (), @@ -1035,11 +1025,13 @@ namespace binfilter { /*?*/ } /*N*/ } /*N*/ -/*N*/ if (bStacked && !nRow) fOldData[nCol] = pChartYAxis->GetOrigin(); +/*N*/ if (bStacked && !nRow && fOldData) + fOldData[nCol] = pChartYAxis->GetOrigin(); /*N*/ /*N*/ if (fData != DBL_MIN) /*N*/ { -/*N*/ if (bStacked && nRow) fData += fOldData[nCol]; +/*N*/ if (bStacked && nRow && fOldData) + fData += fOldData[nCol]; /*N*/ /*N*/ double fLength = nLength * pChartYAxis->CalcFact(fData); /*N*/ @@ -1065,7 +1057,8 @@ namespace binfilter { /*N*/ } /*N*/ } /*N*/ -/*N*/ fOldData [nCol] = fData; + if( fOldData ) +/*N*/ fOldData [nCol] = fData; /*N*/ } /*N*/ else /*N*/ { diff --git a/binfilter/bf_sch/source/core/sch_chtmod3d.cxx b/binfilter/bf_sch/source/core/sch_chtmod3d.cxx index 7bd40e99f..737b8d622 100644 --- a/binfilter/bf_sch/source/core/sch_chtmod3d.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmod3d.cxx @@ -62,6 +62,7 @@ #include <bf_svx/svdopath.hxx> #include <bf_svx/xlnwtit.hxx> +#include "arrayhelper.hxx" #include "pairs.hxx" #include "chmod3d.hxx" #include "chaxis.hxx" @@ -771,6 +772,8 @@ namespace binfilter { /*N*/ long nRowCnt = GetRowCount(); /*N*/ short nCol, nRow; /*N*/ + if( nColCnt<0 || (static_cast< unsigned long>(nColCnt) > static_cast<unsigned long>((std::numeric_limits<sal_uInt16>::max()-1)/2)) ) + return (SdrObjGroup*) pScene; /*N*/ Polygon aFrontExtrude(1+nColCnt*2); /*N*/ /*N*/ long nGapX = nW * nGapWidth / 1000; @@ -1276,7 +1279,9 @@ namespace binfilter { /*N*/ { /*N*/ DataDescription* pDescription = NULL; /*N*/ -/*N*/ double* fOldData = new double[nColCnt]; +/*N*/ double* fOldData = ArrayHelper<double>::create_long_size(nColCnt); + if( !fOldData ) + return (SdrObjGroup*) pScene; /*N*/ a3DPos.Z() += nBarWidthZ; /*N*/ /*N*/ for (nRow = 0; nRow < nRowCnt; nRow++) @@ -1394,7 +1399,9 @@ namespace binfilter { /*N*/ /*N*/ // #100288# same structure as all other charts (no stacked and special groups) /*N*/ // create groups for all series -/*N*/ E3dScene ** pDataGroup = new E3dScene * [ nRowCnt ]; +/*N*/ E3dScene ** pDataGroup = ArrayHelper<E3dScene*>::create_long_size( nRowCnt ); + if(!pDataGroup) + return (SdrObjGroup*) pScene; /*N*/ /*N*/ // create 3d sub-scenes for each data series. Insertion into the /*N*/ // main scene is done at the end of the for loop (#109628#) @@ -1950,10 +1957,7 @@ namespace binfilter { /*N*/ { /*N*/ // FG: Das ist eine Variable die in BuildChart gesetzt wird, kutz bevor /*N*/ // das Objekt zerstoert wird. -/*?*/ double fRelativeXPosition = ((double) aTitleXAxisPosition.X()) / aInitialSizefor3d.Width(); -/*?*/ double fRelativeYPosition = ((double) aTitleXAxisPosition.Y()) / aInitialSizefor3d.Height(); -/*?*/ aXAxesTitlePosition.X() = (long)(aPageSize.Width() * fRelativeXPosition); -/*?*/ aXAxesTitlePosition.Y() = (long)(aPageSize.Height() * fRelativeYPosition); +/*?*/ aXAxesTitlePosition = calcRelativePosition( aTitleXAxisPosition, aInitialSizefor3d, aPageSize ); /*N*/ } /*N*/ else /*N*/ { @@ -1982,10 +1986,7 @@ namespace binfilter { /*N*/ { /*N*/ // FG: Das ist eine Variable die in BuildChart gesetzt wird, kutz bevor /*N*/ // das Objekt zerstoert wird. -/*N*/ double fRelativeXPosition = ((double) aTitleYAxisPosition.X()) / aInitialSizefor3d.Width(); -/*N*/ double fRelativeYPosition = ((double) aTitleYAxisPosition.Y()) / aInitialSizefor3d.Height(); -/*N*/ aYAxesTitlePosition.X() = (long)(aPageSize.Width() * fRelativeXPosition); -/*N*/ aYAxesTitlePosition.Y() = (long)(aPageSize.Height() * fRelativeYPosition); +/*N*/ aYAxesTitlePosition = calcRelativePosition( aTitleYAxisPosition, aInitialSizefor3d, aPageSize ); /*N*/ } /*N*/ else /*N*/ { @@ -2019,10 +2020,7 @@ namespace binfilter { /*N*/ { /*N*/ // FG: Das ist eine Variable die in BuildChart gesetzt wird, kutz bevor /*N*/ // das Objekt zerstoert wird. -/*N*/ double fRelativeXPosition = ((double) aTitleZAxisPosition.X()) / aInitialSizefor3d.Width(); -/*N*/ double fRelativeYPosition = ((double) aTitleZAxisPosition.Y()) / aInitialSizefor3d.Height(); -/*N*/ aZAxesTitlePosition.X() = (long)(aPageSize.Width() * fRelativeXPosition); -/*N*/ aZAxesTitlePosition.Y() = (long)(aPageSize.Height() * fRelativeYPosition); +/*N*/ aZAxesTitlePosition = calcRelativePosition( aTitleZAxisPosition, aInitialSizefor3d, aPageSize ); /*N*/ } /*N*/ else if(aZAxesTitlePosition.Y()<aZAxisOutRect.GetHeight()/2) /*N*/ { diff --git a/binfilter/bf_sch/source/core/sch_chtmode1.cxx b/binfilter/bf_sch/source/core/sch_chtmode1.cxx index ae7d91309..e0da4ec85 100644 --- a/binfilter/bf_sch/source/core/sch_chtmode1.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmode1.cxx @@ -68,6 +68,7 @@ #include <bf_svx/xlnclit.hxx> #include <bf_svx/xlnwtit.hxx> +#include "arrayhelper.hxx" #include "pairs.hxx" #include "memchrt.hxx" #include "chaxis.hxx" @@ -484,22 +485,24 @@ namespace binfilter { /*N*/ /*N*/ if (nCnt != nPieSegCount) /*N*/ { -/*N*/ long *pOfs = new long[nCnt]; -/*N*/ -/*N*/ if (nPieSegCount > nCnt) -/*N*/ for (i = 0; i < nCnt; i++) -/*N*/ pOfs[i] = pPieSegOfs[i]; -/*N*/ else -/*N*/ { -/*N*/ for (i = 0; i < nPieSegCount; i++) -/*N*/ pOfs[i] = pPieSegOfs[i]; -/*N*/ for (; i < nCnt; i++) -/*N*/ pOfs[i] = 0; -/*N*/ } -/*N*/ -/*N*/ delete[] pPieSegOfs; -/*N*/ pPieSegOfs = pOfs; -/*N*/ nPieSegCount = nCnt; +/*N*/ long *pOfs = ArrayHelper<long>::create_short_size(nCnt); + if( pOfs ) + { +/*N*/ if (nPieSegCount > nCnt) +/*N*/ for (i = 0; i < nCnt; i++) +/*N*/ pOfs[i] = pPieSegOfs[i]; +/*N*/ else +/*N*/ { +/*N*/ for (i = 0; i < nPieSegCount; i++) +/*N*/ pOfs[i] = pPieSegOfs[i]; +/*N*/ for (; i < nCnt; i++) +/*N*/ pOfs[i] = 0; +/*N*/ } +/*N*/ +/*N*/ delete[] pPieSegOfs; +/*N*/ pPieSegOfs = pOfs; +/*N*/ nPieSegCount = nCnt; + } /*N*/ } /*N*/ /*N*/ @@ -789,13 +792,16 @@ namespace binfilter { /*N*/ { /*N*/ const SchColorTable& aDefCols = pOptions->GetDefaultColors(); /*N*/ nCount = aDefCols.Count(); -/*N*/ pDefaultCol = new ColorData[ nCount ]; +/*N*/ pDefaultCol = ArrayHelper<ColorData>::create_long_size( nCount ); /*N*/ DBG_ASSERT( nCount == ROW_COLOR_COUNT, "Chart: dynamic default color array size not supported yet" ); /*N*/ -/*N*/ for( size_t i=0; i<nCount; i++ ) -/*N*/ { -/*N*/ pDefaultCol[ i ] = aDefCols.GetColorData( i ); -/*N*/ } + if(pDefaultCol) + { +/*N*/ for( size_t i=0; i<nCount; i++ ) +/*N*/ { +/*N*/ pDefaultCol[ i ] = aDefCols.GetColorData( i ); +/*N*/ } + } /*N*/ } /*N*/ else /*N*/ { diff --git a/binfilter/bf_sch/source/core/sch_chtmode2.cxx b/binfilter/bf_sch/source/core/sch_chtmode2.cxx index 2bd471aea..8ce7acd2b 100644 --- a/binfilter/bf_sch/source/core/sch_chtmode2.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmode2.cxx @@ -76,6 +76,7 @@ #include "pairs.hxx" #include "chaxis.hxx" +#include "arrayhelper.hxx" #include <legacysmgr/legacy_binfilters_smgr.hxx> @@ -199,14 +200,17 @@ enum ChartStyleV0 /*N*/ /*N*/ long nLineMaxY = 0; //#50082# /*N*/ -/*N*/ long* pHeightOfEntry = new long[nCnt*2]; // FG: Wirkliche Hoehe der Zeilen -/*N*/ long* pWidthOfEntry = new long[nCnt*2]; // FG: Wirkliche Breite der Zeilen +/*N*/ long* pHeightOfEntry = ArrayHelper<long>::create_long_size(nCnt,long(2)); // FG: Wirkliche Hoehe der Zeilen +/*N*/ long* pWidthOfEntry = ArrayHelper<long>::create_long_size(nCnt,long(2)); // FG: Wirkliche Breite der Zeilen + if( !pHeightOfEntry || !pWidthOfEntry ) + { + delete[] pHeightOfEntry; + delete[] pWidthOfEntry; + return 0; + } /*N*/ long nLines = 0; // Anzahl Zeilen /*N*/ long nActualColumn = 1; // FG: Zaehlt die Anzahl Spalten /*N*/ -/*N*/ long* pRegressNr = new long [nCnt]; -/*N*/ memset (pRegressNr, 0, sizeof (long) * nCnt); -/*N*/ /*N*/ SfxItemSet aTextAttr(*pItemPool, nTextWhichPairs); /*N*/ /*N*/ aTextAttr.Put(*pLegendAttr); @@ -266,7 +270,6 @@ enum ChartStyleV0 /*?*/ nMaxX = Max (nMaxX, pWidthOfEntry[nLines+nCnt]); /*?*/ nMaxY = Max (nMaxY, pHeightOfEntry[nLines+nCnt]); /*?*/ -/*?*/ pRegressNr [nLines] = i; /*?*/ nLines ++; /*N*/ } /*N*/ } @@ -489,7 +492,6 @@ enum ChartStyleV0 /*N*/ TRUE, TRUE, pLegendAttr), 0); /*N*/ } /*N*/ -/*N*/ delete[] pRegressNr; /*N*/ delete[] pHeightOfEntry; /*N*/ delete[] pWidthOfEntry; /*N*/ } @@ -1178,16 +1180,18 @@ enum ChartStyleV0 /*N*/ switch ((ChartDataId)nInt16) /*N*/ { /*N*/ case CHDATAID_MEMCHART_PLUS : -/*?*/ pChartData = new SchMemChart (CHDATAID_MEMCHART_PLUS); -/*?*/ rIn >> *(SchMemChart*)pChartData; -/*?*/ pChartData->IncreaseRefCount(); -/*?*/ break; -/*?*/ /*?*/ case CHDATAID_DYNCHART: /*N*/ case CHDATAID_MEMCHART: -/*N*/ pChartData = new SchMemChart (CHDATAID_MEMCHART); + if( CHDATAID_MEMCHART_PLUS==(ChartDataId)nInt16) +/*?*/ pChartData = new SchMemChart (CHDATAID_MEMCHART_PLUS); + else +/*N*/ pChartData = new SchMemChart (CHDATAID_MEMCHART); /*N*/ rIn >> *(SchMemChart*)pChartData; /*N*/ pChartData->IncreaseRefCount(); + if( rIn.GetError() != 0 ) //read error + { + return; + } /*N*/ break; /*N*/ /*N*/ default : @@ -1199,8 +1203,8 @@ enum ChartStyleV0 /*N*/ if (nVersion >= 8) rIn >> fMinData; /*N*/ else if (pChartData) /*N*/ { -/*?*/ long nColCnt = GetColCount(); -/*?*/ long nRowCnt = GetRowCount(); +/*?*/ short nColCnt = GetColCount(); +/*?*/ short nRowCnt = GetRowCount(); /*?*/ /*?*/ for (short nCol = 0; nCol < nColCnt; nCol++) /*?*/ for (short nRow = 0; nRow < nRowCnt; nRow++) @@ -1325,16 +1329,26 @@ enum ChartStyleV0 /*N*/ /*N*/ if (nVersion >= 6) /*N*/ { -/*N*/ rIn >> nInt16; nPieSegCount = (short)nInt16; -/*N*/ pPieSegOfs = new long[nPieSegCount]; -/*N*/ -/*N*/ BOOL bNullify = (nVersion < 17) && eChartStyle == CHSTYLE_2D_PIE; -/*N*/ -/*N*/ for( i = 0; i < nPieSegCount; i++ ) -/*N*/ { -/*N*/ rIn >> nInt32; -/*N*/ pPieSegOfs[ i ] = bNullify? 0: (long)nInt32; -/*N*/ } + nInt16=0; +/*N*/ rIn >> nInt16; + nPieSegCount = static_cast<short>(nInt16); + delete[] pPieSegOfs; pPieSegOfs=0; + if( nPieSegCount!=0 ) + { + pPieSegOfs = ArrayHelper< long >::create_short_size( nPieSegCount ); + if(!pPieSegOfs) + { + nPieSegCount=0; + rIn.SetError( ERRCODE_IO_GENERAL ); + return; + } +/*N*/ BOOL bNullify = (nVersion < 17) && eChartStyle == CHSTYLE_2D_PIE; +/*N*/ for( i = 0; i < nPieSegCount; i++ ) +/*N*/ { +/*N*/ rIn >> nInt32; +/*N*/ pPieSegOfs[ i ] = bNullify? 0: (long)nInt32; +/*N*/ } + } /*N*/ } /*N*/ /*N*/ rIn >> nInt16; nXAngle = (short)nInt16; diff --git a/binfilter/bf_sch/source/core/sch_chtmode3.cxx b/binfilter/bf_sch/source/core/sch_chtmode3.cxx index 599d8a3c0..c82580bcd 100644 --- a/binfilter/bf_sch/source/core/sch_chtmode3.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmode3.cxx @@ -76,6 +76,9 @@ #include "chaxis.hxx" +#include <limits> +#include <algorithm> + namespace binfilter { /************************************************************************* @@ -279,20 +282,17 @@ namespace binfilter { /*N*/ const SfxItemSet& ChartModel::GetDataRowAttr( long nRow ) const /*N*/ { -/*N*/ if( nRow < (long)aDataRowAttrList.size() ) +/*N*/ if( nRow>=0 && nRow < (long)aDataRowAttrList.size() ) /*N*/ { /*N*/ SfxItemSet* pSet = aDataRowAttrList[ nRow ]; /*N*/ DBG_ASSERT( pSet, "Invalid ItemSet" ); -/*N*/ return *pSet; -/*N*/ } -/*N*/ else -/*N*/ { -/*N*/ OSL_FAIL( "Requested data row attribute is unavailable" ); -/*N*/ -/*N*/ // return something -/*?*/ DBG_ASSERT( pChartAttr, "Invalid Chart-ItemSet" ); -/*?*/ return *pChartAttr; + if( pSet ) +/*N*/ return *pSet; /*N*/ } +/*N*/ OSL_FAIL( "Requested data row attribute is unavailable" ); +/*N*/ // return something +/*?*/ DBG_ASSERT( pChartAttr, "Invalid Chart-ItemSet" ); +/*?*/ return *pChartAttr; /*N*/ } /************************************************************************* @@ -684,11 +684,25 @@ namespace binfilter { /*N*/ ? &aSwitchDataPointAttrList /*N*/ : &aDataPointAttrList; /*N*/ -/*N*/ SfxItemSet* pItemSet = (*pAttrList)[ nCol * GetRowCount() + nRow ]; + if( nCol < 0 || nRow < 0 ) + return; + const long nRowCount = GetRowCount(); + const long nColCount = GetColCount(); + if( nColCount <= 0 || nRowCount <= 0 ) + return; + if( nCol >= nColCount || nRow >= nRowCount ) + return; + if( nCol > ::std::numeric_limits<long>::max()/nRowCount ) //sal_uIntPtr is the type of the index parameter for method pAttrList->GetObject + return; + if( nRowCount*nCol > ::std::numeric_limits<long>::max() - nRow ) + return; + sal_uIntPtr nIndex = static_cast<sal_uIntPtr>(nCol) * nRowCount + nRow; + +/*N*/ SfxItemSet* pItemSet = (*pAttrList)[ nCol * GetRowCount() + nRow ]; /*N*/ if (pItemSet == NULL) /*N*/ { /*N*/ pItemSet = new SfxItemSet(*pItemPool, nRowWhichPairs); -/*N*/ (*pAttrList)[nCol * GetRowCount() + nRow] = pItemSet; +/*N*/ (*pAttrList)[nIndex] = pItemSet; /*N*/ } /*N*/ if(!bMerge) /*?*/ pItemSet->ClearItem(); @@ -783,10 +797,11 @@ namespace binfilter { /*N*/ SfxItemSet aAttr( GetDataRowAttr( nCol % nPieCount )); /*N*/ /*N*/ if( ( nCol >= nPieCount ) && -/*N*/ pDefaultColors ) +/*N*/ pDefaultColors && pDefaultColors->size()>0 ) /*N*/ { /*?*/ XColorEntry* pColEntry = (*pDefaultColors)[ nCol % pDefaultColors->size() ]; -/*?*/ aAttr.Put( XFillColorItem( pColEntry->GetName(), pColEntry->GetColor())); + if( pColEntry ) +/*?*/ aAttr.Put( XFillColorItem( pColEntry->GetName(), pColEntry->GetColor())); /*N*/ } /*N*/ /*N*/ // add description attributes of series diff --git a/binfilter/bf_sch/source/core/sch_chtmode4.cxx b/binfilter/bf_sch/source/core/sch_chtmode4.cxx index bee767a92..1a54c73ee 100644 --- a/binfilter/bf_sch/source/core/sch_chtmode4.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmode4.cxx @@ -164,11 +164,19 @@ namespace binfilter { /*N*/ void ChartModel::ResizeText (SfxItemSet *pTextAttr, Size aPageSize, BOOL bResizePage ) /*N*/ { -/*N*/ double fRatio; +/*N*/ double fRatio = 1.0; /*N*/ if( bResizePage ) -/*N*/ fRatio = (double)aPageSize.Height() / (double)aInitialSize.Height(); + { + double fDenominator = aInitialSize.Height(); + if( fDenominator != 0 ) +/*N*/ fRatio = (double)aPageSize.Height() / fDenominator; + } /*N*/ else -/*?*/ fRatio = (double)aDiagramRectangle.GetHeight() / (double)aLastDiagramRectangle.GetHeight(); + { + double fDenominator = aLastDiagramRectangle.GetHeight(); + if( fDenominator != 0 ) +/*?*/ fRatio = (double)aDiagramRectangle.GetHeight() / fDenominator; + } /*N*/ /*N*/ // resize all three fonts /*N*/ static const USHORT nWhichIds[ 3 ] = { @@ -652,6 +660,21 @@ namespace binfilter { /*N*/ } /*N*/ } +Point ChartModel::calcRelativePosition( const Point& rStartPoint, const Size& rInitialSize, const Size& rNewSize ) +{ + Point aRet( rStartPoint ); + double fX_Denominator = rInitialSize.Width(); + double fY_Denominator = rInitialSize.Height(); + if( fX_Denominator != 0.0 && fY_Denominator != 0.0 ) + { + double fRelativXPosition = rStartPoint.X() / fX_Denominator; + double fRelativYPosition = rStartPoint.Y() / fY_Denominator; + aRet.X() = static_cast<long>( rNewSize.Width() * fRelativXPosition ); + aRet.Y() = static_cast<long>( rNewSize.Height() * fRelativYPosition ); + } + return aRet; +} + /************************************************************************* |* |* Sub-Methode von BuildChart(), Anzeige des Haupttitels @@ -666,10 +689,7 @@ namespace binfilter { /*N*/ if (bUseRelativePositionsForChartGroups && (aTitleTopCenter.X() >= 0) && /*N*/ (aTitleTopCenter.Y() >= 0) && GetMainTitleHasBeenMoved()) /*N*/ { -/*N*/ double fRelativXPosition = ((double) aTitleTopCenter.X()) / aInitialSize.Width(); -/*N*/ double fRelativYPosition = ((double) aTitleTopCenter.Y()) / aInitialSize.Height(); -/*N*/ aTitlePosition.X() = (long)((double)rPageSize.Width() * fRelativXPosition ); -/*N*/ aTitlePosition.Y() = (long)((double)rPageSize.Height() * fRelativYPosition ); +/*N*/ aTitlePosition = calcRelativePosition( aTitleTopCenter, aInitialSize, rPageSize ); /*N*/ } /*N*/ else /*N*/ { @@ -685,7 +705,6 @@ namespace binfilter { /*N*/ pObj->SetResizeProtect(TRUE); /*N*/ pPage->NbcInsertObject(pObj, rIndex++); /*N*/ } - /************************************************************************* |* |* Sub-Methode von BuildChart(), man koennte vermutlich DoShowMainTitle und @@ -701,10 +720,7 @@ namespace binfilter { /*N*/ if (bUseRelativePositionsForChartGroups && (aSubTitleTopCenter.X() >= 0) && /*N*/ (aSubTitleTopCenter.Y() >= 0) && GetSubTitleHasBeenMoved()) /*N*/ { -/*N*/ double fRelativeXPosition = ((double) aSubTitleTopCenter.X()) / aInitialSize.Width(); -/*N*/ double fRelativeYPosition = ((double) aSubTitleTopCenter.Y()) / aInitialSize.Height(); -/*N*/ aSubTitlePosition.X() = (long)((double)rPageSize.Width() * fRelativeXPosition ); -/*N*/ aSubTitlePosition.Y() = (long)((double)rPageSize.Height() * fRelativeYPosition ); +/*N*/ aSubTitlePosition = calcRelativePosition( aSubTitleTopCenter, aInitialSize, rPageSize ); /*N*/ } /*N*/ else /*N*/ { @@ -747,17 +763,7 @@ namespace binfilter { /*N*/ if (bUseRelativePositionsForChartGroups && (aLegendTopLeft.X() >= 0) && /*N*/ (aLegendTopLeft.Y() >= 0) && GetLegendHasBeenMoved()) /*N*/ { -/*N*/ double fRatioX = -/*N*/ static_cast< double >( rPageSize.Width() ) / -/*N*/ static_cast< double >( aInitialSize.Width() ); -/*N*/ double fRatioY = -/*N*/ static_cast< double >( rPageSize.Height() ) / -/*N*/ static_cast< double >( aInitialSize.Height() ); -/*N*/ -/*N*/ aLegendPosition.X() = static_cast< long >( -/*N*/ static_cast< double >( aLegendTopLeft.X() ) * fRatioX ); -/*N*/ aLegendPosition.Y() = static_cast< long >( -/*N*/ static_cast< double >( aLegendTopLeft.Y() ) * fRatioY ); +/*N*/ aLegendPosition = calcRelativePosition( aLegendTopLeft, aInitialSize, rPageSize ); /*N*/ /*N*/ if( bAdjustMarginsForLegend ) /*N*/ { @@ -892,7 +898,9 @@ namespace binfilter { /*N*/ aSet.Put(pObj->GetItemSet()); /*N*/ /*N*/ aSet.ClearInvalidItems(); -/*N*/ aDataRowAttrList[ nRow ]->Put( aSet ); + SfxItemSet* pItemSet = aDataRowAttrList[ nRow ]; + if(pItemSet) +/*N*/ pItemSet->Put( aSet ); /*N*/ aSet.ClearItem(); /*N*/ } /*N*/ else if( pDataPoint ) @@ -1088,17 +1096,23 @@ namespace binfilter { // // Previously the constraints to fullfill have been tighter: // All four border lines had to lie inside the chart rectangle. + double fFactorX = 1.0; + double fFactorY = 1.0; + double fX_Denominator = aInitialSize.Width(); + double fY_Denominator = aInitialSize.Height(); + if( fX_Denominator != 0.0 && fY_Denominator != 0.0 ) + { + fFactorX = rPageSize.Width() / fX_Denominator; + fFactorY = rPageSize.Height() / fY_Denominator; + } + /*N*/ if ( (aDiagramRectangle.nLeft < aDiagramRectangle.nRight) /*N*/ && (aDiagramRectangle.nTop < aDiagramRectangle.nBottom) ) /*N*/ { -/*?*/ double fRelativeXPosition = ((double) aDiagramRectangle.Left()) / aInitialSize.Width(); -/*?*/ double fRelativeYPosition = ((double) aDiagramRectangle.Top()) / aInitialSize.Height(); -/*?*/ aChartRect.nLeft = (long)((double)rPageSize.Width() * fRelativeXPosition ); -/*?*/ aChartRect.nTop = (long)((double)rPageSize.Height() * fRelativeYPosition ); -/*?*/ fRelativeXPosition = ((double) aDiagramRectangle.Right()) / aInitialSize.Width(); -/*?*/ fRelativeYPosition = ((double) aDiagramRectangle.Bottom()) / aInitialSize.Height(); -/*?*/ aChartRect.nRight = (long)((double)rPageSize.Width() * fRelativeXPosition ); -/*?*/ aChartRect.nBottom = (long)((double)rPageSize.Height() * fRelativeYPosition ); +/*?*/ aChartRect.nLeft = static_cast<long>( aDiagramRectangle.Left() * fFactorX ); +/*?*/ aChartRect.nTop = static_cast<long>( aDiagramRectangle.Top() * fFactorY ); +/*?*/ aChartRect.nRight = static_cast<long>( aDiagramRectangle.Right() * fFactorX ); +/*?*/ aChartRect.nBottom = static_cast<long>( aDiagramRectangle.Bottom() * fFactorY ); /*?*/ } /*N*/ } /*N*/ } diff --git a/binfilter/bf_sch/source/core/sch_chtmode7.cxx b/binfilter/bf_sch/source/core/sch_chtmode7.cxx index 947e711f7..b6ed81a4f 100644 --- a/binfilter/bf_sch/source/core/sch_chtmode7.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmode7.cxx @@ -113,7 +113,7 @@ namespace binfilter { /*N*/ DBG_ASSERT( nCol < nPieSegCount, "pie segment requested is out of bounds" ); /*N*/ /*N*/ if( IsPieChart() && -/*N*/ nCol < nPieSegCount ) +/*N*/ nCol >= 0 && nCol < nPieSegCount ) /*N*/ { /*N*/ return pPieSegOfs[ nCol ]; /*N*/ } @@ -498,7 +498,7 @@ namespace binfilter { /*N*/ DBG_ASSERT( pPieSegOfs, "Invalid Array" ); /*N*/ DBG_ASSERT( nCol < nPieSegCount, "trying to set pie offset out of bounds" ); /*N*/ -/*N*/ if( nCol < nPieSegCount ) +/*N*/ if( nCol >= 0 && nCol < nPieSegCount ) /*N*/ pPieSegOfs[ nCol ] = nOfs; /*N*/ } diff --git a/binfilter/bf_sch/source/core/sch_chtmode9.cxx b/binfilter/bf_sch/source/core/sch_chtmode9.cxx index acd7c7cc2..49a3ca12e 100644 --- a/binfilter/bf_sch/source/core/sch_chtmode9.cxx +++ b/binfilter/bf_sch/source/core/sch_chtmode9.cxx @@ -71,6 +71,7 @@ #include <float.h> #include "glob.hrc" +#include "arrayhelper.hxx" #include "chaxis.hxx" #include "chdescr.hxx" #include "calculat.hxx" @@ -392,6 +393,16 @@ namespace binfilter { /*N*/ SdrPage *pPage = GetPage(0); /*N*/ Size aPageSize = pPage->GetSize(); /*N*/ + double fFactorX = 1.0; + double fFactorY = 1.0; + double fX_Denominator = aInitialSize.Width(); + double fY_Denominator = aInitialSize.Height(); + if( fX_Denominator != 0.0 && fY_Denominator != 0.0 ) + { + fFactorX = aPageSize.Width() / fX_Denominator; + fFactorY = aPageSize.Height() / fY_Denominator; + } + /*N*/ if(bShowXAxisTitle) /*N*/ { /*N*/ SdrObject *pXAxisTitleObj = GetObjWithId(CHOBJID_DIAGRAM_TITLE_X_AXIS,*pPage); @@ -407,10 +418,8 @@ namespace binfilter { /*N*/ { /*N*/ // FG: Das ist eine Variable die in BuildChart gesetzt wird, kurz bevor /*N*/ // das Objekt zerstoert wird. -/*N*/ double fRelativeXPosition = ((double) aTitleXAxisPosition.X()) / aInitialSize.Width(); -/*N*/ double fRelativeYPosition = ((double) aTitleXAxisPosition.Y()) / aInitialSize.Height(); -/*N*/ aXAxesTitlePosition.X() = (int) (aPageSize.Width() * fRelativeXPosition + 0.5); -/*N*/ aXAxesTitlePosition.Y() = (int) (aPageSize.Height() * fRelativeYPosition + 0.5); +/*N*/ aXAxesTitlePosition.X() = static_cast<int>( aTitleXAxisPosition.X() * fFactorX + 0.5 ); +/*N*/ aXAxesTitlePosition.Y() = static_cast<int>( aTitleXAxisPosition.Y() * fFactorY + 0.5 ); /*N*/ } /*N*/ else /*N*/ { @@ -438,10 +447,8 @@ namespace binfilter { /*N*/ { /*N*/ // FG: Das ist eine Variable die in BuildChart gesetzt wird, kurz bevor /*N*/ // das Objekt zerstoert wird. -/*N*/ double fRelativeXPosition = ((double) aTitleYAxisPosition.X()) / aInitialSize.Width(); -/*N*/ double fRelativeYPosition = ((double) aTitleYAxisPosition.Y()) / aInitialSize.Height(); -/*N*/ aYAxesTitlePosition.X() = (int) (aPageSize.Width() * fRelativeXPosition + 0.5); -/*N*/ aYAxesTitlePosition.Y() = (int) (aPageSize.Height() * fRelativeYPosition + 0.5); +/*N*/ aYAxesTitlePosition.X() = static_cast<int>( aTitleYAxisPosition.X() * fFactorX + 0.5); +/*N*/ aYAxesTitlePosition.Y() = static_cast<int>( aTitleYAxisPosition.Y() * fFactorY + 0.5); /*N*/ } /*N*/ else /*N*/ { @@ -528,19 +535,32 @@ namespace binfilter { /*N*/ aBarY2.Create(aRect,nColCnt,nR2); /*N*/ ChartBarDescriptor* pBar=&aBarY1; /*N*/ -/*N*/ SdrObjList **pRowLists = new SdrObjList*[nRowCnt]; -/*N*/ SdrObjList **pStatLists = new SdrObjList*[nRowCnt]; +/*N*/ SdrObjList **pRowLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); +/*N*/ SdrObjList **pStatLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); + if( !pRowLists || !pStatLists ) + { + delete[] pRowLists; + delete[] pStatLists; + return pGroup; + } /*N*/ /*N*/ ChartDataDescription aDescr(nColCnt,nRowCnt,pList,this,bShowDataDescr); /*N*/ /*N*/ Point *pTracePoint=0; /*N*/ if(m_nDefaultColorSet&CHSPECIAL_TRACELINES) /*N*/ { -/*?*/ pTracePoint = new Point[nRowCnt];//#50149# +/*?*/ pTracePoint = ArrayHelper<Point>::create_long_size(nRowCnt);//#50149# /*N*/ } /*N*/ /*N*/ -/*N*/ XPolygon *pLine = new XPolygon[nLines]; //#50149# +/*N*/ XPolygon *pLine = ArrayHelper<XPolygon>::create_long_size(nLines); //#50149# + if( !pLine ) + { + delete[] pRowLists; + delete[] pStatLists; + delete[] pTracePoint; + return pGroup; + } /*N*/ BOOL bStartPointIsValid(FALSE); // Indicates wether the first point of a line /*N*/ // segment is valid. /*N*/ @@ -1156,8 +1176,14 @@ namespace binfilter { /*N*/ long nPartWidth = aRect.GetWidth() / nBackColCnt; /*N*/ double fPartWidth = ((double) aRect.GetWidth() / (double) nBackColCnt); /*N*/ -/*N*/ SdrObjList** pRowLists = new SdrObjList*[nRowCnt]; -/*N*/ SdrObjList** pStatLists = new SdrObjList*[nRowCnt]; +/*N*/ SdrObjList** pRowLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); +/*N*/ SdrObjList** pStatLists = ArrayHelper<SdrObjList*>::create_long_size(nRowCnt); + if( !pRowLists || !pStatLists ) + { + delete[] pRowLists; + delete[] pStatLists; + return pGroup; + } /*N*/ /*N*/ ChartDataDescription aDescr(nColCnt,nRowCnt,pList,this,bShowDataDescr); /*N*/ @@ -1176,9 +1202,6 @@ namespace binfilter { /*N*/ /*N*/ Polygon aPolygon( nColCnt + 16 ); // +4 -> +16: let some more points be possible. Is set to exact size later /*N*/ -/*N*/ //Ab hier speziell fuer (Sp)Line-Charts: -/*N*/ XPolygon *pSpline = new XPolygon(nColCnt * nGranularity); -/*N*/ /*N*/ long nStartX=aRect.Left(); /*N*/ if(bPartDescr) /*N*/ nStartX+=nPartWidth/2; @@ -1292,32 +1315,6 @@ namespace binfilter { /*?*/ { /*?*/ if( nPoints > 1 ) /*?*/ { -/*?*/ if( IsSplineChart() ) -/*?*/ { -/*?*/ Polygon aNewPoly( nPoints ); -/*?*/ for( USHORT i = 0; i < nPoints; i++ ) -/*?*/ aNewPoly[ i ] = aPolygon[ i ]; -/*?*/ -/*?*/ XPolygon aXPoly( aNewPoly ); -/*?*/ if ((eChartStyle == CHSTYLE_2D_CUBIC_SPLINE) || -/*?*/ (eChartStyle == CHSTYLE_2D_CUBIC_SPLINE_SYMBOL)) -/*?*/ { -/*?*/ CubicSpline( aXPoly, nPoints - 1, nGranularity, *pSpline ); -/*?*/ } -/*?*/ else -/*?*/ { -/*?*/ approxMesh( nGranularity, *pSpline, aXPoly, nPoints - 1, nSplineDepth ); -/*?*/ } -/*?*/ -/*?*/ XPolygon aSplinePoly( *pSpline ); -/*?*/ aSplinePoly.SetSize( (nPoints - 1) * nGranularity ); -/*?*/ -/*?*/ // #67488# crop polygon -/*?*/ XPolyPolygon aResult; -/*?*/ SchCalculationHelper::IntersectPolygonWithRectangle( aSplinePoly, aClipRect, aResult ); -/*?*/ pObj = new SdrPathObj( OBJ_PLIN, aResult ); -/*?*/ } -/*?*/ else /*?*/ { /*?*/ Polygon aNewPoly( nPoints ); /*?*/ for( USHORT i = 0; i < nPoints; i++ ) @@ -1350,37 +1347,8 @@ namespace binfilter { /*N*/ { /*N*/ pObj = NULL; /*N*/ -/*N*/ if( IsSplineChart() ) -/*N*/ { -/*N*/ if( nPoints > 1 ) -/*N*/ { -/*N*/ Polygon aNewPoly( nPoints ); -/*N*/ for( USHORT i = 0; i < nPoints; i++ ) -/*N*/ aNewPoly[ i ] = aPolygon[ i ]; -/*N*/ -/*N*/ XPolygon aXPoly( aNewPoly ); -/*N*/ if ((eChartStyle == CHSTYLE_2D_CUBIC_SPLINE) || -/*N*/ (eChartStyle == CHSTYLE_2D_CUBIC_SPLINE_SYMBOL)) -/*N*/ { -/*N*/ CubicSpline( aXPoly, nPoints - 1,nGranularity, *pSpline ); -/*N*/ } -/*N*/ else -/*N*/ { -/*N*/ approxMesh( nGranularity, *pSpline, aXPoly, nPoints - 1, nSplineDepth ); -/*N*/ } -/*N*/ -/*N*/ XPolygon aSplinePoly( *pSpline ); -/*N*/ aSplinePoly.SetSize( (nPoints - 1) * nGranularity ); -/*N*/ -/*N*/ // #67488# crop polygon -/*N*/ XPolyPolygon aResult; -/*N*/ SchCalculationHelper::IntersectPolygonWithRectangle( aSplinePoly, aClipRect, aResult ); -/*N*/ pObj = new SdrPathObj( OBJ_PLIN, aResult ); -/*N*/ } -/*N*/ } -/*N*/ else /*N*/ { -/*N*/ if( bArea ) +/*N*/ if( bArea && !IsSplineChart() ) /*N*/ { /*N*/ Polygon aNewPoly( nPoints + 3 ); /*N*/ for( USHORT i = 0; i < nPoints + 3; i++ ) @@ -1400,7 +1368,7 @@ namespace binfilter { /*N*/ pObj->SetModel( this ); /*N*/ SetObjectAttr( pObj,CHOBJID_DIAGRAM_ROWS, TRUE, TRUE, (SfxItemSet *)&rDataRowAttr ); /*N*/ } -/*N*/ else if( nPoints > 1 ) // line +/*N*/ else if( nPoints > 1 ) // line (or stripped spline) /*N*/ { /*N*/ // #67488# crop polygon /*N*/ Polygon aNewPoly( nPoints ); @@ -1431,8 +1399,6 @@ namespace binfilter { /*N*/ } // if( nPoints ) /*N*/ } //for nRow /*N*/ -/*N*/ delete pSpline; -/*N*/ /*N*/ //Ab hier wieder wie in Create2DRow(Area)Chart: /*N*/ /*N*/ aDescr.Build(TRUE); @@ -1712,6 +1678,9 @@ namespace binfilter { /*N*/ break; /*N*/ } /*N*/ + if( nLastSeries<0 ) + return; + /*N*/ // #101164# map fill-/line colors /*N*/ if( nNumLinesInColChart > nOldNumLines ) /*N*/ { @@ -1721,7 +1690,8 @@ namespace binfilter { /*N*/ { /*N*/ SfxItemSet * pSet = aDataRowAttrList[ nLastSeries - i ]; /*N*/ OSL_ASSERT( pSet ); -/*N*/ pSet->Put( XLineColorItem( +/*N*/ if( pSet ) +/*N*/ pSet->Put( XLineColorItem( /*N*/ String(), /*N*/ static_cast< const XFillColorItem & >( /*N*/ pSet->Get( XATTR_FILLCOLOR )).GetValue() )); @@ -1735,11 +1705,14 @@ namespace binfilter { /*N*/ { /*?*/ SfxItemSet * pSet = aDataRowAttrList[ nLastSeries - i ]; /*?*/ OSL_ASSERT( pSet ); -/*?*/ pSet->Put( XFillColorItem( +/*?*/ if( pSet ) +/*?*/ { +/*?*/ pSet->Put( XFillColorItem( /*?*/ String(), /*?*/ static_cast< const XLineColorItem & >( /*?*/ pSet->Get( XATTR_LINECOLOR )).GetValue() )); -/*?*/ pSet->Put( XLineColorItem( String(), RGBColor( COL_BLACK ) )); +/*?*/ pSet->Put( XLineColorItem( String(), RGBColor( COL_BLACK ) )); +/*?*/ } /*N*/ } /*N*/ } /*N*/ } diff --git a/binfilter/bf_sch/source/core/sch_globfunc.cxx b/binfilter/bf_sch/source/core/sch_globfunc.cxx index ac8760808..c2dc3ebb3 100644 --- a/binfilter/bf_sch/source/core/sch_globfunc.cxx +++ b/binfilter/bf_sch/source/core/sch_globfunc.cxx @@ -138,250 +138,6 @@ namespace binfilter { /*N*/ return (SchObjGroup *) SetObjectAttr (new SchObjGroup, nID, bProtect, bResize, 0); /*N*/ } - -/************************************************************************* -|* -|* Berechne kub. Spline -|* -\************************************************************************/ - -/*N*/ void CubicSpline (XPolygon &pKnownPoints, -/*N*/ int n, -/*N*/ int splineSize, -/*N*/ XPolygon &pSplines) -/*N*/ { -/*N*/ double *h = new double [n + 1]; -/*N*/ double *m = new double [n + 1]; -/*N*/ double *q = new double [n + 1]; -/*N*/ double *u = new double [n + 1]; -/*N*/ -/*N*/ for (int k = 1; -/*N*/ k <= n; -/*N*/ k ++) -/*N*/ h [k] = pKnownPoints [k].X () - pKnownPoints [k - 1].X (); -/*N*/ -/*N*/ double p; -/*N*/ double lambda = 0.0; -/*N*/ double d = 0.0; -/*N*/ double mue; -/*N*/ -/*N*/ q [0] = -lambda / 2.0; -/*N*/ u [0] = d / 2.0; -/*N*/ -/*N*/ int j; -/*N*/ for (j = 1; -/*N*/ j <= n; -/*N*/ j ++) -/*N*/ { -/*N*/ mue = (j < n) -/*N*/ ? h[j] / (h [j] + h [j + 1]) -/*N*/ : 0.0; -/*N*/ p = mue * q [j - 1] + 2.0; -/*N*/ lambda = 1.0 - mue; -/*N*/ q [j] = -lambda / p; -/*N*/ d = (j < n) -/*N*/ ? 6.0 * ((pKnownPoints [j + 1].Y () - pKnownPoints [j].Y ()) / h [j + 1] - -/*N*/ (pKnownPoints [j].Y () - pKnownPoints [j - 1].Y ()) / h [j]) / (h [j] + h [j + 1]) -/*N*/ : 0.0; -/*N*/ u [j] = (d - mue * u [j - 1]) / p; -/*N*/ } -/*N*/ -/*N*/ m [n] = u [n]; -/*N*/ -/*N*/ for (j = n - 1; -/*N*/ j >= 0; -/*N*/ j --) -/*N*/ m [j] = q [j] * m [j + 1] + u [j]; -/*N*/ -/*N*/ for (j = 0; -/*N*/ j < n; -/*N*/ j ++) -/*N*/ { -/*N*/ double xStep = (pKnownPoints [j + 1].X () - pKnownPoints [j].X ()) / splineSize; -/*N*/ double x = pKnownPoints [j].X (); -/*N*/ -/*N*/ double alpha = pKnownPoints [j].Y (); -/*N*/ double gamma = m [j] / 2; -/*N*/ double beta = (pKnownPoints [j + 1].Y () - pKnownPoints [j].Y ()) / h [j + 1] - -/*N*/ ((2 * m [j] + m [j + 1]) * h [j + 1]) / 6; -/*N*/ double delta = (m [j + 1] - m [j]) / (6 * h [j + 1]); -/*N*/ -/*N*/ for (int i = 0; -/*N*/ i < splineSize; -/*N*/ i ++) -/*N*/ { -/*N*/ double xdiff = (x - pKnownPoints [j].X ()); -/*N*/ int index = j * splineSize + i; -/*N*/ -/*N*/ pSplines [(short) index].Y () = long(alpha + xdiff * (beta + xdiff * (gamma + xdiff * delta))); -/*N*/ pSplines [(short) index].X () = long(x); -/*N*/ x += xStep; -/*N*/ } -/*N*/ } -/*N*/ -/*N*/ pSplines [n * splineSize].Y () = pKnownPoints [n].Y (); -/*N*/ pSplines [n * splineSize].X () = pKnownPoints [n].X (); -/*N*/ -/*N*/ delete[] h; -/*N*/ delete[] m; -/*N*/ delete[] q; -/*N*/ delete[] u; -/*N*/ } - -/************************************************************************* -|* -|* Bestimme Knotenvektor fuer B-Spline -|* -\************************************************************************/ - -/*N*/ void TVector (int n, -/*N*/ int k, -/*N*/ double *t) -/*N*/ { -/*N*/ for (int i = 0; -/*N*/ i <= n + k; -/*N*/ i ++) -/*N*/ { -/*N*/ if (i < k) t [i] = 0; -/*N*/ else if (i <= n) t [i] = i - k + 1; -/*N*/ else t [i] = n - k + 2; -/*N*/ } -/*N*/ } - -/************************************************************************* -|* -|* Berechne linken Knotenvektor -|* -\************************************************************************/ - -/*N*/ double TLeft (double x, -/*N*/ int i, -/*N*/ int k, -/*N*/ double *t) -/*N*/ { -/*N*/ double deltaT = t [i + k - 1] - t [i]; -/*N*/ -/*N*/ return (deltaT == 0.0) -/*N*/ ? 0.0 -/*N*/ : (x - t [i]) / deltaT; -/*N*/ } - -/************************************************************************* -|* -|* Berechne rechten Knotenvektor -|* -\************************************************************************/ - -/*N*/ double TRight (double x, -/*N*/ int i, -/*N*/ int k, -/*N*/ double *t) -/*N*/ { -/*N*/ double deltaT = t [i + k] - t [i + 1]; -/*N*/ -/*N*/ return (deltaT == 0.0) -/*N*/ ? 0.0 -/*N*/ : (t [i + k] - x) / deltaT; -/*N*/ } - -/************************************************************************* -|* -|* Berechne Gewichtungsvektor -|* -\************************************************************************/ - -/*N*/ void BVector (double x, -/*N*/ int n, -/*N*/ int k, -/*N*/ double *b, -/*N*/ double *t) -/*N*/ { -/*N*/ for (int i = 0; -/*N*/ i <= n + k; -/*N*/ i ++) -/*N*/ b [i] = 0; -/*N*/ -/*N*/ int i0 = (int) floor (x) + k - 1; -/*N*/ b [i0] = 1; -/*N*/ -/*N*/ for (int j = 2; -/*N*/ j <= k; -/*N*/ j ++) -/*N*/ for (int i = 0; -/*N*/ i <= i0; -/*N*/ i ++) -/*N*/ b [i] = TLeft (x, i, j, t) * b [i] + TRight (x, i, j, t) * b [i + 1]; -/*N*/ } - -/************************************************************************* -|* -|* Berechne einzelnen Punkt -|* -\************************************************************************/ - -/*N*/ void BSPoint (int n, -/*N*/ Point &p1, -/*N*/ Point &p2, -/*N*/ XPolygon &pKnownPoints, -/*N*/ double *b) -/*N*/ { -/*N*/ for (int i = 0; -/*N*/ i <= n; -/*N*/ i ++) -/*N*/ { -/*N*/ p1.Y () = long(p1.Y () + b [i] * pKnownPoints [i].Y ()); -/*N*/ p2.Y () = long(p2.Y () + b [n - i] * pKnownPoints [i].Y ()); -/*N*/ } -/*N*/ } - -/************************************************************************* -|* -|* Berechne B-Spline -|* -\************************************************************************/ - -/*N*/ void approxMesh (int splineSize, -/*N*/ XPolygon &pSplines, -/*N*/ XPolygon &pKnownPoints, -/*N*/ int n, -/*N*/ int k) -/*N*/ { -/*N*/ int pCount = splineSize * n; -/*N*/ double *b = new double [n + k + 1]; -/*N*/ double *t = new double [n + k + 2]; -/*N*/ double xStep = ((double) n - (double) k + 2.0) / (double) pCount; -/*N*/ double dStep = ((double) pKnownPoints [n].X () - (double) pKnownPoints [0].X ()) / (double) pCount; -/*N*/ double dXUp = pKnownPoints [0].X (); -/*N*/ double dXDown = pKnownPoints [n].X (); -/*N*/ double x = 0.0; -/*N*/ int nEnd = pCount / 2 + 1; -/*N*/ -/*N*/ TVector (n, k, t); -/*N*/ -/*N*/ for (int j = 0; -/*N*/ j <= nEnd; -/*N*/ j ++) -/*N*/ { -/*N*/ Point aPoint1; -/*N*/ Point aPoint2; -/*N*/ -/*N*/ BVector (x, n, k, b, t); -/*N*/ BSPoint (n, aPoint1, aPoint2, pKnownPoints, b); -/*N*/ -/*N*/ pSplines [j].X () = (int)(floor(dXUp)+0.5); -/*N*/ pSplines [j].Y () = aPoint1.Y (); -/*N*/ pSplines [pCount - j].X () = (int)(floor(dXDown)+0.5); -/*N*/ pSplines [pCount - j].Y () = aPoint2.Y (); -/*N*/ -/*N*/ x += xStep; -/*N*/ dXUp += dStep; -/*N*/ dXDown -= dStep; -/*N*/ } -/*N*/ -/*N*/ delete[] t; -/*N*/ delete[] b; -/*N*/ } - /************************************************************************* |* |* Passe untere Grenze an den Wertebereich an diff --git a/binfilter/bf_sch/source/core/sch_memchrt.cxx b/binfilter/bf_sch/source/core/sch_memchrt.cxx index e0543602d..f9df334c8 100644 --- a/binfilter/bf_sch/source/core/sch_memchrt.cxx +++ b/binfilter/bf_sch/source/core/sch_memchrt.cxx @@ -45,6 +45,7 @@ #include <functional> #include <algorithm> + namespace binfilter { // ======================================== @@ -158,14 +159,14 @@ namespace binfilter { /*N*/ { /*N*/ nRowCnt = nRows; /*N*/ nColCnt = nCols; -/*N*/ pData = new double[nColCnt * nRowCnt]; -/*N*/ -/*N*/ pRowNumFmtId= new sal_Int32 [nRowCnt]; -/*N*/ pColNumFmtId= new sal_Int32 [nColCnt]; + pData = ArrayHelper< double >::create_short_size( nColCnt, nRowCnt ); + + pRowNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nRowCnt ); + pColNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nColCnt ); /*N*/ InitNumFmt(); -/*N*/ -/*N*/ pRowTable = new sal_Int32 [nRowCnt]; -/*N*/ pColTable = new sal_Int32 [nColCnt]; + + pRowTable = ArrayHelper< sal_Int32 >::create_short_size( nRowCnt ); + pColTable = ArrayHelper< sal_Int32 >::create_short_size( nColCnt ); /*N*/ ResetTranslation(pRowTable,nRowCnt); /*N*/ ResetTranslation(pColTable,nColCnt); /*N*/ @@ -178,8 +179,29 @@ namespace binfilter { /*N*/ *(pFill ++) = 0.0; /*N*/ } /*N*/ -/*N*/ pColText = new String[nColCnt]; -/*N*/ pRowText = new String[nRowCnt]; + pColText = ArrayHelper< String >::create_short_size( nColCnt ); + pRowText = ArrayHelper< String >::create_short_size( nRowCnt ); + + if ( !pData || !pRowNumFmtId || !pColNumFmtId || !pRowTable || !pColTable || !pColText || !pRowText ) + { + delete[] pData; + pData = 0; + delete[] pRowNumFmtId; + pRowNumFmtId = 0; + delete[] pColNumFmtId; + pColNumFmtId = 0; + delete[] pRowTable; + pRowTable = 0; + delete[] pColTable; + pColTable = 0; + delete[] pColText; + pColText = 0; + delete[] pRowText; + pRowText = 0; + + nRowCnt = 0; + nColCnt = 0; + } /*N*/ } /************************************************************************* |* @@ -203,10 +225,20 @@ namespace binfilter { /*N*/ long nRows=MIN(nRowCnt,rMemChart.nRowCnt); /*N*/ /*N*/ short i; -/*N*/ for (i = 0; i < nCols; i++) -/*N*/ pColText[i] = rMemChart.pColText[i]; -/*N*/ for (i = 0; i < nRows; i++) -/*N*/ pRowText[i] = rMemChart.pRowText[i]; + if ( pColText ) + { + for ( i = 0; i < nCols; i++ ) + { + pColText[i] = rMemChart.pColText[i]; + } + } + if ( pRowText ) + { + for ( i = 0; i < nRows; i++ ) + { + pRowText[i] = rMemChart.pRowText[i]; + } + } /*N*/ /*N*/ // copy chart range /*N*/ SetChartRange( rMemChart.GetChartRange()); @@ -241,27 +273,33 @@ namespace binfilter { /*N*/ aSomeData2 = ((SchMemChart&) rMemChart).SomeData2 (); /*N*/ aSomeData3 = ((SchMemChart&) rMemChart).SomeData3 (); /*N*/ aSomeData4 = ((SchMemChart&) rMemChart).SomeData4 (); -/*N*/ pData = new double[nColCnt * nRowCnt]; -/*N*/ -/*N*/ pRowNumFmtId= new sal_Int32 [nRowCnt]; -/*N*/ pColNumFmtId= new sal_Int32 [nColCnt]; -/*N*/ pRowTable = new sal_Int32 [nRowCnt]; -/*N*/ pColTable = new sal_Int32 [nColCnt]; + pData = ArrayHelper< double >::create_short_size( nColCnt, nRowCnt ); + + pRowNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nRowCnt ); + pColNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nColCnt ); + pRowTable = ArrayHelper< sal_Int32 >::create_short_size( nRowCnt ); + pColTable = ArrayHelper< sal_Int32 >::create_short_size( nColCnt ); /*N*/ /*N*/ aAppLink = rMemChart.aAppLink; /*N*/ nLastSelInfoReturn = rMemChart.nLastSelInfoReturn; /*N*/ /*N*/ nTranslated = rMemChart.nTranslated; -/*N*/ for(long i=0;i<nColCnt;i++) -/*N*/ { -/*N*/ pColTable[i] = rMemChart.pColTable[i]; -/*N*/ pColNumFmtId[i] = rMemChart.pColNumFmtId[i]; -/*N*/ } -/*N*/ for(long i=0;i<nRowCnt;i++) -/*N*/ { -/*N*/ pRowTable[i] = rMemChart.pRowTable[i]; -/*N*/ pRowNumFmtId[i] = rMemChart.pRowNumFmtId[i]; -/*N*/ } + if ( pColTable && pColNumFmtId ) + { + for (long i = 0; i < nColCnt; i++) + { + pColTable[i] = rMemChart.pColTable[i]; + pColNumFmtId[i] = rMemChart.pColNumFmtId[i]; + } + } + if ( pRowTable && pRowNumFmtId ) + { + for (long i = 0; i < nRowCnt; i++) + { + pRowTable[i] = rMemChart.pRowTable[i]; + pRowNumFmtId[i] = rMemChart.pRowNumFmtId[i]; + } + } /*N*/ mpNumFormatter=rMemChart.mpNumFormatter; /*N*/ /*N*/ if (pData) @@ -274,15 +312,23 @@ namespace binfilter { /*N*/ *(pDest ++) = *(pSource ++); /*N*/ } /*N*/ -/*N*/ pColText = new String[nColCnt]; -/*N*/ -/*N*/ for (long i = 0; i < nColCnt; i++) -/*N*/ pColText[i] = rMemChart.pColText[i]; -/*N*/ -/*N*/ pRowText = new String[nRowCnt]; -/*N*/ -/*N*/ for (long i = 0; i < nRowCnt; i++) -/*N*/ pRowText[i] = rMemChart.pRowText[i]; + pColText = ArrayHelper< String >::create_short_size( nColCnt ); + if ( pColText ) + { + for (long i = 0; i < nColCnt; i++) + { + pColText[i] = rMemChart.pColText[i]; + } + } + + pRowText = ArrayHelper< String >::create_short_size( nRowCnt ); + if ( pRowText ) + { + for (long i = 0; i < nRowCnt; i++) + { + pRowText[i] = rMemChart.pRowText[i]; + } + } /*N*/ /*N*/ bReadOnly = rMemChart.bReadOnly; // bm #69410# /*N*/ @@ -292,6 +338,27 @@ namespace binfilter { /*N*/ /*N*/ // copy chart range /*N*/ SetChartRange( rMemChart.GetChartRange()); + + if ( !pData || !pRowNumFmtId || !pColNumFmtId || !pRowTable || !pColTable || !pColText || !pRowText ) + { + delete[] pData; + pData = 0; + delete[] pRowNumFmtId; + pRowNumFmtId = 0; + delete[] pColNumFmtId; + pColNumFmtId = 0; + delete[] pRowTable; + pRowTable = 0; + delete[] pColTable; + pColTable = 0; + delete[] pColText; + pColText = 0; + delete[] pRowText; + pRowText = 0; + + nRowCnt = 0; + nColCnt = 0; + } /*N*/ } //Überprüft, ob die Umordnung/Translation OK ist, Fehlerfall, wenn : @@ -306,7 +373,7 @@ namespace binfilter { /*N*/ BOOL SchMemChart::VerifyTranslation() /*N*/ { /*N*/ //Fehler ? -/*N*/ if(nTranslated!=TRANS_COL) +/*N*/ if(nTranslated!=TRANS_COL && pColTable) /*N*/ { /*N*/ for(long nCol=0;nCol<nColCnt;nCol++) /*N*/ { @@ -326,7 +393,7 @@ namespace binfilter { /*N*/ } /*N*/ } /*N*/ } -/*N*/ if(nTranslated!=TRANS_ROW) +/*N*/ if(nTranslated!=TRANS_ROW && pRowTable) /*N*/ { /*N*/ for(long nRow=0;nRow<nRowCnt;nRow++) /*N*/ { @@ -348,7 +415,7 @@ namespace binfilter { /*N*/ } /*N*/ /*N*/ // Sortierung besteht noch ? -/*N*/ if(nTranslated==TRANS_ROW) +/*N*/ if(nTranslated==TRANS_ROW && pRowTable) /*N*/ { /*?*/ for(long nRow=0;nRow<nRowCnt;nRow++) /*?*/ { @@ -356,7 +423,7 @@ namespace binfilter { /*?*/ return TRUE; /*?*/ } /*N*/ } -/*N*/ if(nTranslated==TRANS_COL) +/*N*/ if(nTranslated==TRANS_COL && pColTable) /*N*/ { /*?*/ for(long nCol=0;nCol<nColCnt;nCol++) /*?*/ { @@ -378,32 +445,84 @@ namespace binfilter { /*N*/ double SchMemChart::GetTransData(long nCol,long nRow) /*N*/ { /*N*/ DBG_ASSERT(VerifyTranslation(), "Translation table corrupted in MemChart"); + if ( !pColTable || !pRowTable || !IsValidColumn( nCol ) || !IsValidRow( nRow ) ) + { + return DBL_MIN; + } /*N*/ return GetData( (short)pColTable[nCol], (short)pRowTable[nRow]); /*N*/ } /*N*/ double SchMemChart::GetTransDataInPercent(long nCol, long nRow, BOOL bRowData) const /*N*/ { /*N*/ DBG_ASSERT(((SchMemChart*)this)->VerifyTranslation(), "Translation table corrupted in MemChart"); + if ( !pColTable || !pRowTable || !IsValidColumn( nCol ) || !IsValidRow( nRow ) ) + { + return DBL_MIN; + } /*N*/ return GetDataInPercent( (short)pColTable[nCol], (short)pRowTable[nRow], bRowData); /*N*/ } /*N*/ const String& SchMemChart::GetTransColText(long nCol) const /*N*/ { /*N*/ DBG_ASSERT(((SchMemChart*)this)->VerifyTranslation(), "Translation table corrupted in MemChart"); + if ( !pColTable || !IsValidColumn( nCol ) ) + { + return String::EmptyString(); + } /*N*/ return GetColText( (short)pColTable[nCol] ); /*N*/ } /*N*/ const String& SchMemChart::GetTransRowText(long nRow) const /*N*/ { /*N*/ DBG_ASSERT(((SchMemChart*)this)->VerifyTranslation(), "Translation table corrupted in MemChart"); + if ( !pRowTable || !IsValidRow( nRow ) ) + { + return String::EmptyString(); + } /*N*/ return GetRowText( (short)pRowTable[nRow] ); /*N*/ } /*N*/ long SchMemChart::GetTransNumFormatIdRow(const long nRow) const /*N*/ { /*N*/ DBG_ASSERT(((SchMemChart*)this)->VerifyTranslation(), "Translation table corrupted in MemChart"); -/*N*/ return ( nTranslated == TRANS_ROW )? pRowNumFmtId[ pRowTable[ nRow ]]: pRowNumFmtId[ nRow ]; + if ( pRowNumFmtId && IsValidRow( nRow ) ) + { + if ( nTranslated == TRANS_ROW ) + { + if ( pRowTable ) + { + long nTransRow = pRowTable[ nRow ]; + if ( IsValidRow( nTransRow ) ) + { + return pRowNumFmtId[ nTransRow ]; + } + } + } + else + { + return pRowNumFmtId[ nRow ]; + } + } + return NUMBERFORMAT_UNDEFINED; /*N*/ } /*N*/ long SchMemChart::GetTransNumFormatIdCol(const long nCol) const /*N*/ { /*N*/ DBG_ASSERT(((SchMemChart*)this)->VerifyTranslation(), "Translation table corrupted in MemChart"); -/*N*/ return ( nTranslated == TRANS_COL ) ? pColNumFmtId[ pColTable[ nCol ]]: pColNumFmtId[ nCol ]; + if ( pColNumFmtId && IsValidColumn( nCol ) ) + { + if ( nTranslated == TRANS_COL ) + { + if ( pColTable ) + { + long nTransCol = pColTable[ nCol ]; + if ( IsValidColumn( nTransCol ) ) + { + return pColNumFmtId[ nTransCol ]; + } + } + } + else + { + return pColNumFmtId[ nCol ]; + } + } + return NUMBERFORMAT_UNDEFINED; /*N*/ } @@ -464,9 +583,16 @@ namespace binfilter { /*N*/ double *pOut = rMemChart.pData; /*N*/ /*N*/ short i; -/*N*/ for (i = 0; i < rMemChart.nColCnt; i++) -/*N*/ for (short j = 0; j < rMemChart.nRowCnt; j++) -/*N*/ rOut << *(pOut ++); + if ( pOut ) + { + for ( i = 0; i < rMemChart.nColCnt; i++ ) + { + for ( short j = 0; j < rMemChart.nRowCnt; j++ ) + { + rOut << *(pOut ++); + } + } + } /*N*/ /*N*/ rOut << (INT16)aSysCharSet; /*N*/ rOut.WriteUniOrByteString( rMemChart.aMainTitle, rOut.GetStreamCharSet() ); @@ -475,21 +601,41 @@ namespace binfilter { /*N*/ rOut.WriteUniOrByteString( rMemChart.aYAxisTitle, rOut.GetStreamCharSet() ); /*N*/ rOut.WriteUniOrByteString( rMemChart.aZAxisTitle, rOut.GetStreamCharSet() ); /*N*/ -/*N*/ for (i = 0; i < rMemChart.nColCnt; i++) -/*N*/ rOut.WriteUniOrByteString( rMemChart.pColText[ i ], rOut.GetStreamCharSet() ); -/*N*/ -/*N*/ for (i = 0; i < rMemChart.nRowCnt; i++) -/*N*/ rOut.WriteUniOrByteString( rMemChart.pRowText[ i ], rOut.GetStreamCharSet() ); + if ( rMemChart.pColText ) + { + for ( i = 0; i < rMemChart.nColCnt; i++ ) + { + rOut.WriteUniOrByteString( rMemChart.pColText[ i ], rOut.GetStreamCharSet() ); + } + } + + if ( rMemChart.pRowText ) + { + for ( i = 0; i < rMemChart.nRowCnt; i++ ) + { + rOut.WriteUniOrByteString( rMemChart.pRowText[ i ], rOut.GetStreamCharSet() ); + } + } /*N*/ /*N*/ rOut << (INT16)rMemChart.eDataType; /*N*/ /*N*/ //IOVersion = 1 /*N*/ long nIndex; -/*N*/ for (nIndex = 0; nIndex < rMemChart.nColCnt; nIndex++) -/*N*/ rOut << rMemChart.pColTable[nIndex]; -/*N*/ -/*N*/ for (nIndex = 0; nIndex < rMemChart.nRowCnt; nIndex++) -/*N*/ rOut << rMemChart.pRowTable[nIndex]; + if ( rMemChart.pColTable ) + { + for ( nIndex = 0; nIndex < rMemChart.nColCnt; nIndex++ ) + { + rOut << rMemChart.pColTable[nIndex]; + } + } + + if ( rMemChart.pRowTable ) + { + for ( nIndex = 0; nIndex < rMemChart.nRowCnt; nIndex++ ) + { + rOut << rMemChart.pRowTable[nIndex]; + } + } /*N*/ /*N*/ //IOVersion = 2 /*N*/ rOut << rMemChart.nTranslated; @@ -510,16 +656,35 @@ namespace binfilter { /*N*/ /*N*/ SchIOCompat aIO(rIn, STREAM_READ); /*N*/ -/*N*/ rIn >> nInt16; rMemChart.nColCnt = (short)nInt16; -/*N*/ rIn >> nInt16; rMemChart.nRowCnt = (short)nInt16; -/*N*/ -/*N*/ rMemChart.pData = new double[rMemChart.nColCnt * rMemChart.nRowCnt]; -/*N*/ -/*N*/ double *pIn = rMemChart.pData; -/*N*/ -/*N*/ for (short i = 0; i < rMemChart.nColCnt; i++) -/*N*/ for (short j = 0; j < rMemChart.nRowCnt; j++) -/*N*/ rIn >> *(pIn ++); + short nCols=0; + short nRows=0; +/*N*/ rIn >> nInt16; nCols = static_cast<short>(nInt16); +/*N*/ rIn >> nInt16; nRows = static_cast<short>(nInt16); +/*N*/ + double* pTmpData = ArrayHelper< double >::create_short_size( nCols, nRows ); + if ( !pTmpData ) + { + rIn.SetError( ERRCODE_IO_GENERAL ); + return rIn; + } + + rMemChart.nColCnt = nCols; + rMemChart.nRowCnt = nRows; + + delete[] rMemChart.pData; + rMemChart.pData = pTmpData; + + double *pIn = rMemChart.pData; + if ( pIn ) + { + for (short i = 0; i < rMemChart.nColCnt; i++) + { + for ( short j = 0; j < rMemChart.nRowCnt; j++ ) + { + rIn >> *(pIn ++); + } + } + } /*N*/ /*N*/ INT16 nCharSet; /*N*/ rIn >> nCharSet; @@ -533,34 +698,74 @@ namespace binfilter { /*N*/ rMemChart.aYAxisTitle = rIn.ReadUniOrByteString( rIn.GetStreamCharSet() ); /*N*/ rMemChart.aZAxisTitle = rIn.ReadUniOrByteString( rIn.GetStreamCharSet() ); /*N*/ -/*N*/ rMemChart.pColText = new String[rMemChart.nColCnt]; -/*N*/ -/*N*/ for (short i = 0; i < rMemChart.nColCnt; i++) -/*N*/ { -/*N*/ rMemChart.pColText[ i ] = rIn.ReadUniOrByteString( rIn.GetStreamCharSet() ); -/*N*/ } -/*N*/ -/*N*/ rMemChart.pRowText = new String[rMemChart.nRowCnt]; -/*N*/ -/*N*/ for (short i = 0; i < rMemChart.nRowCnt; i++) -/*N*/ { -/*N*/ rMemChart.pRowText[ i ] = rIn.ReadUniOrByteString( rIn.GetStreamCharSet() ); -/*N*/ } + delete[] rMemChart.pColText; + rMemChart.pColText = ArrayHelper< String >::create_short_size( rMemChart.nColCnt ); + if ( !rMemChart.pColText ) + { + rIn.SetError( ERRCODE_IO_GENERAL ); + return rIn; + } + for (short i = 0; i < rMemChart.nColCnt; i++ ) + { + rMemChart.pColText[ i ] = rIn.ReadUniOrByteString( rIn.GetStreamCharSet() ); + } + + delete[] rMemChart.pRowText; + rMemChart.pRowText = ArrayHelper< String >::create_short_size( rMemChart.nRowCnt ); + if ( !rMemChart.pRowText ) + { + rIn.SetError( ERRCODE_IO_GENERAL ); + return rIn; + } + for (short i = 0; i < rMemChart.nRowCnt; i++ ) + { + rMemChart.pRowText[ i ] = rIn.ReadUniOrByteString( rIn.GetStreamCharSet() ); + } /*N*/ /*N*/ rIn >> nInt16; rMemChart.eDataType = (short)nInt16; /*N*/ -/*N*/ rMemChart.pRowNumFmtId = new sal_Int32 [rMemChart.nRowCnt]; -/*N*/ rMemChart.pColNumFmtId = new sal_Int32 [rMemChart.nColCnt]; -/*N*/ rMemChart.pRowTable = new sal_Int32 [rMemChart.nRowCnt]; -/*N*/ rMemChart.pColTable = new sal_Int32 [rMemChart.nColCnt]; + delete[] rMemChart.pRowNumFmtId; + rMemChart.pRowNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( rMemChart.nRowCnt ); + if ( !rMemChart.pRowNumFmtId ) + { + rIn.SetError( ERRCODE_IO_GENERAL ); + return rIn; + } + + delete[] rMemChart.pColNumFmtId; + rMemChart.pColNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( rMemChart.nColCnt ); + if ( !rMemChart.pColNumFmtId ) + { + rIn.SetError( ERRCODE_IO_GENERAL ); + return rIn; + } + + delete[] rMemChart.pRowTable; + rMemChart.pRowTable = ArrayHelper< sal_Int32 >::create_short_size( rMemChart.nRowCnt ); + if ( !rMemChart.pRowTable ) + { + rIn.SetError( ERRCODE_IO_GENERAL ); + return rIn; + } + + delete[] rMemChart.pColTable; + rMemChart.pColTable = ArrayHelper< sal_Int32 >::create_short_size( rMemChart.nColCnt ); + if ( !rMemChart.pColTable ) + { + rIn.SetError( ERRCODE_IO_GENERAL ); + return rIn; + } /*N*/ /*N*/ if(aIO.GetVersion()>=1) /*N*/ { -/*N*/ for (long i = 0; i < rMemChart.nColCnt; i++) -/*N*/ rIn >> rMemChart.pColTable[i]; -/*N*/ -/*N*/ for (long i = 0; i < rMemChart.nRowCnt; i++) -/*N*/ rIn >> rMemChart.pRowTable[i]; + for (long i = 0; i < rMemChart.nColCnt; i++) + { + rIn >> rMemChart.pColTable[i]; + } + for (long i = 0; i < rMemChart.nRowCnt; i++) + { + rIn >> rMemChart.pRowTable[i]; + } /*N*/ /*N*/ if(aIO.GetVersion()>=2) /*N*/ rIn >> rMemChart.nTranslated; @@ -588,11 +793,21 @@ namespace binfilter { /*N*/ void SchMemChart::InitNumFmt() /*N*/ { /*N*/ long i; -/*N*/ for(i=0;i<nColCnt;i++) -/*N*/ pColNumFmtId[i]=-1; //uninitialised! -/*N*/ -/*N*/ for(i=0;i<nRowCnt;i++) -/*N*/ pRowNumFmtId[i]=-1; + if ( pColNumFmtId ) + { + for ( i = 0; i < nColCnt; i++ ) + { + pColNumFmtId[i] = -1; //uninitialised! + } + } + + if ( pRowNumFmtId ) + { + for ( i = 0; i < nRowCnt; i++ ) + { + pRowNumFmtId[i] = -1; + } + } /*N*/ } diff --git a/binfilter/inc/bf_sch/arrayhelper.hxx b/binfilter/inc/bf_sch/arrayhelper.hxx new file mode 100644 index 000000000..540e4480e --- /dev/null +++ b/binfilter/inc/bf_sch/arrayhelper.hxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _SCH_ARRAYHELPER_HXX +#define _SCH_ARRAYHELPER_HXX + +#include <limits> + +namespace binfilter { + +/** Helper class for creating an array of type T and size nSize. + The create methods are protected against integer overflow in + operator new[]. + */ +template< typename T > +class ArrayHelper +{ +public: + static T* create_short_size( short n ); + static T* create_short_size( short m, short n ); + static T* create_long_size( long n ); + static T* create_long_size( long m, long n ); +}; + +template< typename T > +T* ArrayHelper< T >::create_short_size( short n ) +{ + T* pRet = 0; + if ( n > 0 && + static_cast< unsigned short >( n ) <= ( ::std::numeric_limits< size_t >::max() / sizeof( T ) ) ) + { + pRet = new (std::nothrow) T[ n ]; + } + return pRet; +} + +template< typename T > +T* ArrayHelper< T >::create_short_size( short m, short n ) +{ + T* pRet = 0; + if ( m > 0 && n > 0 && + static_cast< unsigned short >( m ) <= ( ( ::std::numeric_limits< size_t >::max() / n ) / sizeof( T ) ) ) + { + pRet = new (std::nothrow) T[ static_cast< size_t >( m ) * n ]; + } + return pRet; +} + +template< typename T > +T* ArrayHelper< T >::create_long_size( long n ) +{ + T* pRet = 0; + if ( n > 0 && + static_cast< unsigned long >( n ) <= ( ::std::numeric_limits< size_t >::max() / sizeof( T ) ) ) + { + pRet = new (std::nothrow) T[ n ]; + } + return pRet; +} + +template< typename T > +T* ArrayHelper< T >::create_long_size( long m, long n ) +{ + T* pRet = 0; + if ( m > 0 && n > 0 && + static_cast< unsigned long >( m ) <= ( ( ::std::numeric_limits< size_t >::max() / n ) / sizeof( T ) ) ) + { + pRet = new (std::nothrow) T[ static_cast< size_t >( m ) * n ]; + } + return pRet; +} + +} //namespace binfilter +#endif diff --git a/binfilter/inc/bf_sch/calculat.hxx b/binfilter/inc/bf_sch/calculat.hxx index 58e54bb0b..c3bf79dc2 100644 --- a/binfilter/inc/bf_sch/calculat.hxx +++ b/binfilter/inc/bf_sch/calculat.hxx @@ -50,23 +50,6 @@ class XPolyPolygon; class SchCalculationHelper { public: - /** like Rectangle::IsInside, but the result is FALSE, if - the Point is on the Border of the Rectangle - */ -// static BOOL IsPointInsideRectangle( const Point& rPoint, const Rectangle& rRect ); - - /** @descr The line is clipped at the rectangle. If the line lies completely or partly - inside the clipping area then TRUE is returned and the line is modified accordingly. - If the line lies completely outside the clipping area then FALSE is returned and the - line remains unmodified. - The line may be degenerate in that both of it's end points have the same - coordinates. - @param aLine The line to be clipped. It is modified to a part that lies completely - inside the clipping area if such a part exists. - @param rRectangle The clipping area. - @return TRUE is returned if the line lies completely or partly inside the clipping area. - */ - /** @descr The intersection between an open polygon and a rectangle is calculated and the resulting lines are placed into the poly-polygon aResult. @param rPolygon The polygon is required to be open, ie. it's start and end point @@ -78,35 +61,6 @@ public: static void IntersectPolygonWithRectangle( const XPolygon& rPolygon, const Rectangle& rRectangle, XPolyPolygon& aResult ); - /** @descr Calculates the intersection between a set of open polygons and a - rectangle. This function iterates over all polygons contained in - rPolyPolygon and calls IntersectPolygonWithRectangle() for it. - The resulting XPolyPolygons are then put together into aResult. - @param rPolyPolygon A set of polygons that must be open. - @param rRectangle The clipping region - @param rOutResult The resulting lines representing rPolyPolygon clipped - at rRectangle. - */ - - /** @descr calculates natural cubic splines for the given set of points. - - @param rPoints is a vector of tuples containing x and y coordinate of - points that are to be interpolated. - @param nGranularity The number of interpolation points between two - x-values given in rPoints - - @param rOutResult A polygon (split up into more, if the number of points - is too high as to fit into a single XPolygon) that contains all - line segments between the interpolated points. It should contain - (rPoints.size() * nGranularity) points. - - @param nDPIX resolution in x-direction to reduce the number of points. - A value of 0 (default) means do not take into account. - - @param nDPIY resolution in y-direction to reduce the number of points. - A value of 0 (default) means do not take into account. - */ - private: /** @descr The line given by it's two endpoints rP0 and rP1 is clipped at the rectangle rRectangle. If there is at least a part of it visible then TRUE is returned and diff --git a/binfilter/inc/bf_sch/chtmodel.hxx b/binfilter/inc/bf_sch/chtmodel.hxx index 2ac07b887..9f3c5170f 100644 --- a/binfilter/inc/bf_sch/chtmodel.hxx +++ b/binfilter/inc/bf_sch/chtmodel.hxx @@ -73,7 +73,6 @@ class SvNumberFormatterIndexTable; class SdrObjGroup; class SdrRectObj; -class SchModelData; class SchObjectId; class ChartAxis; class SchItemPool; @@ -554,6 +553,8 @@ public: inline BOOL GetUseRelativePositions() { return bUseRelativePositionsForChartGroups; } void SetUseRelativePositions( BOOL value ); + static Point calcRelativePosition( const Point& rStartPoint, const Size& rInitialSize, const Size& rNewSize ); + void SetAdjustMarginsForLegend( BOOL value ) { bAdjustMarginsForLegend = value; } BOOL GetAdjustMarginsForLegend() { return bAdjustMarginsForLegend; } @@ -662,8 +663,6 @@ public: friend SvStream & operator << ( SvStream & rOut, const ChartModel & rDoc ); friend SvStream & operator >> ( SvStream & rIn, ChartModel & rDoc ); - friend class SchModelData; - // protected: // remark: currently there are no classes that are derived from ChartModel // and also the distinction between private and protected was not very diff --git a/binfilter/inc/bf_sch/globfunc.hxx b/binfilter/inc/bf_sch/globfunc.hxx index 55ef753a5..ea34093ad 100644 --- a/binfilter/inc/bf_sch/globfunc.hxx +++ b/binfilter/inc/bf_sch/globfunc.hxx @@ -79,44 +79,6 @@ SchObjGroup *CreateSimpleGroup (UINT16 nID, BOOL bProtect, BOOL bResize); - -void CubicSpline (XPolygon &pKnownPoints, - int n, - int splineSize, - XPolygon &pSplines); - -void TVector (int n, - int k, - double *t); - -double TLeft (double x, - int i, - int k, - double *t); - -double TRight (double x, - int i, - int k, - double *t); - -void BVector (double x, - int n, - int k, - double *b, - double *t); - -void BSPoint (int n, - Point &p1, - Point &p2, - XPolygon &pKnownPoints, - double *b); - -void approxMesh (int splineSize, - XPolygon &pSplines, - XPolygon &pKnownPoints, - int n, - int k); - double SizeBounds (double, double, BOOL); diff --git a/binfilter/inc/bf_sch/memchrt.hxx b/binfilter/inc/bf_sch/memchrt.hxx index 38da972b2..069d4c20e 100644 --- a/binfilter/inc/bf_sch/memchrt.hxx +++ b/binfilter/inc/bf_sch/memchrt.hxx @@ -40,6 +40,9 @@ #include <bf_sch/cellranges.hxx> #include <com/sun/star/chart/ChartSeriesAddress.hpp> + +#include "arrayhelper.hxx" + class SvStream; namespace binfilter { @@ -286,10 +289,10 @@ public: void SetNumberFormatter(SvNumberFormatter* pNumFormatter) { mpNumFormatter = pNumFormatter; } SvNumberFormatter* GetNumberFormatter() const { return mpNumFormatter; } - void SetNumFormatIdRow( const long nRow, const long nFmtId ) { if( pRowNumFmtId && nRow < nRowCnt ) pRowNumFmtId[ nRow ] = nFmtId; } - void SetNumFormatIdCol( const long nCol, const long nFmtId ) { if( pColNumFmtId && nCol < nColCnt ) pColNumFmtId[ nCol ] = nFmtId; } - long GetNumFormatIdRow( const long nRow ) const { return ( pRowNumFmtId && nRow < nRowCnt )? pRowNumFmtId[ nRow ]: -1; } - long GetNumFormatIdCol( const long nCol ) const { return ( pColNumFmtId && nCol < nColCnt )? pColNumFmtId[ nCol ]: -1; } + void SetNumFormatIdRow( const long nRow, const long nFmtId ) { if ( pRowNumFmtId && IsValidRow( nRow ) ) pRowNumFmtId[ nRow ] = nFmtId; } + void SetNumFormatIdCol( const long nCol, const long nFmtId ) { if ( pColNumFmtId && IsValidColumn( nCol ) ) pColNumFmtId[ nCol ] = nFmtId; } + long GetNumFormatIdRow( const long nRow ) const { return ( pRowNumFmtId && IsValidRow( nRow ) ) ? pRowNumFmtId[ nRow ] : -1; } + long GetNumFormatIdCol( const long nCol ) const { return ( pColNumFmtId && IsValidColumn( nCol ) ) ? pColNumFmtId[ nCol ] : -1; } long GetTransNumFormatIdRow( const long nRow ) const; long GetTransNumFormatIdCol( const long nCol ) const; @@ -320,11 +323,11 @@ public: friend SvStream& operator << (SvStream& rOut, const SchMemChart& rMemChart); friend SvStream& operator >> (SvStream& rIn, SchMemChart& rMemChart); - const String& GetColText(short nCol) const { return pColText[nCol]; } - const String& GetRowText(short nRow) const { return pRowText[nRow]; } + const String& GetColText(short nCol) const { return ( pColText && IsValidColumn( nCol ) ) ? pColText[ nCol ] : String::EmptyString(); } + const String& GetRowText(short nRow) const { return ( pRowText && IsValidRow( nRow ) ) ? pRowText[ nRow ] : String::EmptyString(); } ChartDataId GetId() const { return myID; } - double GetData(short nCol, short nRow) const { return pData[nCol * nRowCnt + nRow]; } + double GetData(short nCol, short nRow) const { return ( pData && IsValidColumn( nCol ) && IsValidRow( nRow ) ) ? pData[nCol * nRowCnt + nRow] : DBL_MIN; } double GetDataInPercent(const short nCol , const short nRow, const BOOL bRowData) const; inline void InsertCols(short nAtCol, short nCount); @@ -335,7 +338,7 @@ public: inline void SwapRows(int nAtRow1, int nAtRow2); void SetData(short nCol, short nRow, const double& rVal) - { pData[nCol * nRowCnt + nRow] = rVal; } + { if ( pData && IsValidColumn( nCol ) && IsValidRow( nRow ) ) pData[nCol * nRowCnt + nRow] = rVal; } String& SomeData1() { return aSomeData1; } String& SomeData2() { return aSomeData2; } @@ -347,8 +350,8 @@ public: const String& SomeData3() const { return aSomeData3; } const String& SomeData4() const { return aSomeData4; } - void SetColText(short nCol, const String& rText) { pColText[nCol] = rText; } - void SetRowText(short nRow, const String& rText) { pRowText[nRow] = rText; } + void SetColText(short nCol, const String& rText) { if ( pColText && IsValidColumn( nCol ) ) pColText[nCol] = rText; } + void SetRowText(short nRow, const String& rText) { if ( pRowText && IsValidRow( nRow ) ) pRowText[nRow] = rText; } @@ -419,6 +422,9 @@ public: for all table numbers to fit in */ void parseTableNumberList( const ::rtl::OUString& rList ); + + bool IsValidColumn( const long nCol ) const { return nCol >= 0 && nCol < nColCnt; } + bool IsValidRow( const long nRow ) const { return nRow >= 0 && nRow < nRowCnt; } }; // ==================== Inline Implementations ==================== @@ -495,11 +501,37 @@ inline void SchMemChart::UpdateTranslation(sal_Int32 *pTable,long nCnt) inline void SchMemChart::InsertCols(short nAtCol, short nCount) { - double* pOldData = pData; - + if ( nAtCol < 0 || nAtCol > nColCnt ) + { + return; + } + if ( nColCnt <= 0 || nCount < 0 || + nCount > ( ::std::numeric_limits< short >::max() - nColCnt ) ) + { + return; + } short nNewColCnt = nColCnt + nCount; - pData = new double[nNewColCnt * nRowCnt]; + double* pOldData = pData; + String* pOldColText = pColText; + sal_Int32* pOldColNumFmtId = pColNumFmtId; + sal_Int32* pOldColTable = pColTable; + pData = ArrayHelper< double >::create_short_size( nNewColCnt, nRowCnt ); + pColText = ArrayHelper< String >::create_short_size( nNewColCnt ); + pColNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nNewColCnt ); + pColTable = ArrayHelper< sal_Int32 >::create_short_size( nNewColCnt ); + if ( !pData || !pColText || !pColNumFmtId || !pColTable ) + { + delete[] pData; + pData = pOldData; + delete[] pColText; + pColText = pOldColText; + delete[] pColNumFmtId; + pColNumFmtId = pOldColNumFmtId; + delete[] pColTable; + pColTable = pOldColTable; + return; + } short i, j, nOld, nMax; @@ -530,14 +562,6 @@ inline void SchMemChart::InsertCols(short nAtCol, short nCount) } delete[] pOldData; - String *pOldColText = pColText; - sal_Int32 *pOldColNumFmtId = pColNumFmtId; - sal_Int32 *pOldColTable = pColTable; - - pColNumFmtId = new sal_Int32 [nNewColCnt]; - pColTable = new sal_Int32 [nNewColCnt]; - pColText = new String[nNewColCnt]; - long nC=nNewColCnt; while(nC--) { @@ -570,21 +594,40 @@ inline void SchMemChart::RemoveCols(short nAtCol, short nCount) { DBG_ASSERT( nAtCol < nColCnt, "column index overflow"); + if ( nAtCol < 0 || nAtCol >= nColCnt ) + { + return; + } + if ( nColCnt <= 0 || nCount < 0 || + nCount > ( ::std::numeric_limits< short >::max() - nAtCol ) ) + { + return; + } if (nAtCol + nCount > nColCnt) nCount = nColCnt - nAtCol; short nNewColCnt = nColCnt - nCount; double* pOldData = pData; - pData = new double[nNewColCnt * nRowCnt]; - - String* pOldColText = pColText; - sal_Int32* pOldColNumFmtId = pColNumFmtId; + String* pOldColText = pColText; + sal_Int32* pOldColNumFmtId = pColNumFmtId; sal_Int32* pOldColTable = pColTable; - - pColText = new String[nNewColCnt]; - pColNumFmtId = new sal_Int32 [nNewColCnt]; - pColTable = new sal_Int32 [nNewColCnt]; + pData = ArrayHelper< double >::create_short_size( nNewColCnt, nRowCnt ); + pColText = ArrayHelper< String >::create_short_size( nNewColCnt ); + pColNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nNewColCnt ); + pColTable = ArrayHelper< sal_Int32 >::create_short_size( nNewColCnt ); + if ( !pData || !pColText || !pColNumFmtId || !pColTable ) + { + delete[] pData; + pData = pOldData; + delete[] pColText; + pColText = pOldColText; + delete[] pColNumFmtId; + pColNumFmtId = pOldColNumFmtId; + delete[] pColTable; + pColTable = pOldColTable; + return; + } short i, j, nOld; @@ -615,11 +658,37 @@ inline void SchMemChart::RemoveCols(short nAtCol, short nCount) inline void SchMemChart::InsertRows(short nAtRow, short nCount) { - double* pOldData = pData; - + if ( nAtRow < 0 || nAtRow > nRowCnt ) + { + return; + } + if ( nRowCnt <= 0 || nCount < 0 || + nCount > ( ::std::numeric_limits< short >::max() - nRowCnt ) ) + { + return; + } short nNewRowCnt = nRowCnt + nCount; - pData = new double[nColCnt * nNewRowCnt]; + double* pOldData = pData; + String* pOldRowText = pRowText; + sal_Int32* pOldRowNumFmtId = pRowNumFmtId; + sal_Int32* pOldRowTable = pRowTable; + pData = ArrayHelper< double >::create_short_size( nColCnt, nNewRowCnt ); + pRowText = ArrayHelper< String >::create_short_size( nNewRowCnt ); + pRowNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nNewRowCnt ); + pRowTable = ArrayHelper< sal_Int32 >::create_short_size( nNewRowCnt ); + if ( !pData || !pRowText || !pRowNumFmtId || !pRowTable ) + { + delete[] pData; + pData = pOldData; + delete[] pRowText; + pRowText = pOldRowText; + delete[] pRowNumFmtId; + pRowNumFmtId = pOldRowNumFmtId; + delete[] pRowTable; + pRowTable = pOldRowTable; + return; + } short i, j, nOld, nMax, nGapEnd; @@ -652,14 +721,6 @@ inline void SchMemChart::InsertRows(short nAtRow, short nCount) } delete[] pOldData; - String *pOldRowText =pRowText; - sal_Int32 *pOldRowNumFmtId =pRowNumFmtId; - sal_Int32 *pOldRowTable =pRowTable; - - pRowNumFmtId = new sal_Int32 [nNewRowCnt]; - pRowTable = new sal_Int32 [nNewRowCnt]; - pRowText = new String[nNewRowCnt]; - long nC=nNewRowCnt; while(nC--) //init { @@ -692,13 +753,40 @@ inline void SchMemChart::RemoveRows(short nAtRow, short nCount) { DBG_ASSERT( nAtRow < nRowCnt, "row index overflow" ); + if ( nAtRow < 0 || nAtRow >= nRowCnt ) + { + return; + } + if ( nRowCnt <= 0 || nCount < 0 || + nCount > ( ::std::numeric_limits< short >::max() - nAtRow ) ) + { + return; + } if (nAtRow + nCount > nRowCnt) nCount = nRowCnt - nAtRow; short nNewRowCnt = nRowCnt - nCount; double* pOldData = pData; - pData = new double[nColCnt * nNewRowCnt]; + String* pOldRowText = pRowText; + sal_Int32* pOldRowNumFmtId = pRowNumFmtId; + sal_Int32* pOldRowTable = pRowTable; + pData = ArrayHelper< double >::create_short_size( nColCnt, nNewRowCnt ); + pRowText = ArrayHelper< String >::create_short_size( nNewRowCnt ); + pRowNumFmtId = ArrayHelper< sal_Int32 >::create_short_size( nNewRowCnt ); + pRowTable = ArrayHelper< sal_Int32 >::create_short_size( nNewRowCnt ); + if ( !pData || !pRowText || !pRowNumFmtId || !pRowTable ) + { + delete[] pData; + pData = pOldData; + delete[] pRowText; + pRowText = pOldRowText; + delete[] pRowNumFmtId; + pRowNumFmtId = pOldRowNumFmtId; + delete[] pRowTable; + pRowTable = pOldRowTable; + return; + } short i, j, nOld; @@ -715,14 +803,6 @@ inline void SchMemChart::RemoveRows(short nAtRow, short nCount) delete[] pOldData; - String* pOldRowText = pRowText; - sal_Int32* pOldRowNumFmtId = pRowNumFmtId; - sal_Int32* pOldRowTable = pRowTable; - - pRowText = new String[nNewRowCnt]; - pRowNumFmtId = new sal_Int32 [nNewRowCnt]; - pRowTable = new sal_Int32 [nNewRowCnt]; - for (i = 0, nOld = 0;; i++, nOld++) { if (nOld == nAtRow) diff --git a/binfilter/inc/bf_sch/modeldata.hxx b/binfilter/inc/bf_sch/modeldata.hxx deleted file mode 100644 index 97a2ab965..000000000 --- a/binfilter/inc/bf_sch/modeldata.hxx +++ /dev/null @@ -1,251 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef _SCH_MODELDATA_HXX -#define _SCH_MODELDATA_HXX - -#include <bf_svtools/bf_solar.h> - -#include "chtmodel.hxx" -namespace binfilter { - -/** This class contains all members of the ChartModel, that can be stored for - later for a complete undo. Some members were omitted, that cannot be copied - or must not be applied later. - - The original ChartModel from which is copied must stay alive until ApplyTo() - is called, because the SfxItemSets use its pool. - */ -class SchModelData -{ -public: - SchModelData( const ChartModel & ); - - /// sets the stored ChartModel members at the given ChartModel - void ApplyTo( ChartModel & ); - -private: - ChartBarDescriptor aBarY1; - ChartBarDescriptor aBarY2; - - DescrList aXDescrList; - DescrList aYDescrList; - DescrList aZDescrList; - - long nChartStatus; - - ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshable > mxChartAddIn; - - long nBarPercentWidth; // #50116# - long nNumLinesInColChart; - long m_nDefaultColorSet; // #50037# - - Rectangle aChartRect; - Size aInitialSize; - - ::std::auto_ptr< SchMemChart > m_apChartData; - - double fMinData; - double fMaxData; - double fAmbientIntensity; - Color aAmbientColor; - double fSpotIntensity; - Color aSpotColor; - SvxChartStyle eChartStyle; - SvxChartStyle eOldChartStyle; - - BOOL bTextScalable; - BOOL bIsCopied; - BOOL bLegendVisible; - BOOL bShowAverage; - SvxChartKindError eErrorKind; - SvxChartIndicate eIndicate; - SvxChartRegress eRegression; - double fIndicatePercent; - double fIndicateBigError; - double fIndicatePlus; - double fIndicateMinus; - int nSplineDepth; - int nGranularity; - - /** This member is a temporary storage. I don't understand the comment, so - I can't translate it into english, so I leave it in german, maybe an important hint someday: - - FG: Reiner Zwischenspeicher, wird in chtmod3d.cxx gesetzt und im selben - File in Position3DAxisTitles im selben File abgefragt, weil die - ChartScene::FitInSnapRect das nicht als Parameter bekommen kann, da - diese von der Polyscene gerufen wird. */ - BOOL bSwitch3DColRow; - - long nMarkLen; - long nPieHeight; - long* pPieSegOfs; - short nPieSegCount; - short nXAngle; - short nYAngle; - short nZAngle; - - BOOL bCanRebuild; - - BOOL bShowMainTitle; - BOOL bShowSubTitle; - BOOL bShowXAxisTitle; - BOOL bShowYAxisTitle; - BOOL bShowZAxisTitle; - - String aMainTitle; - String aSubTitle; - String aXAxisTitle; - String aYAxisTitle; - String aZAxisTitle; - - BOOL bShowXGridMain; - BOOL bShowXGridHelp; - BOOL bShowYGridMain; - BOOL bShowYGridHelp; - BOOL bShowZGridMain; - BOOL bShowZGridHelp; - - BOOL bShowDataDescr; // show description for all series (esp. important for auto pilot) - - ::std::auto_ptr< SfxItemSet > m_apTitleAttr; - ::std::auto_ptr< SfxItemSet > m_apMainTitleAttr; - ::std::auto_ptr< SfxItemSet > m_apSubTitleAttr; - ::std::auto_ptr< SfxItemSet > m_apXAxisTitleAttr; - ::std::auto_ptr< SfxItemSet > m_apYAxisTitleAttr; - ::std::auto_ptr< SfxItemSet > m_apZAxisTitleAttr; - ::std::auto_ptr< SfxItemSet > m_apAxisAttr; - - ::std::auto_ptr< SfxItemSet > m_apGridAttr; - ::std::auto_ptr< SfxItemSet > m_apXGridMainAttr; - ::std::auto_ptr< SfxItemSet > m_apYGridMainAttr; - ::std::auto_ptr< SfxItemSet > m_apZGridMainAttr; - ::std::auto_ptr< SfxItemSet > m_apXGridHelpAttr; - ::std::auto_ptr< SfxItemSet > m_apYGridHelpAttr; - ::std::auto_ptr< SfxItemSet > m_apZGridHelpAttr; - ::std::auto_ptr< SfxItemSet > m_apDiagramAreaAttr; - ::std::auto_ptr< SfxItemSet > m_apDiagramWallAttr; - ::std::auto_ptr< SfxItemSet > m_apDiagramFloorAttr; - ::std::auto_ptr< SfxItemSet > m_apLegendAttr; - ::std::auto_ptr< SfxItemSet > m_apDummyAttr; - - ::std::auto_ptr< SfxItemSet > m_apStockLineAttr; - ::std::auto_ptr< SfxItemSet > m_apStockLossAttr; - ::std::auto_ptr< SfxItemSet > m_apStockPlusAttr; - - ::std::auto_ptr< SfxItemSet > m_apChartAttr; - - ItemSetList aDataRowAttrList; - ItemSetList aDataPointAttrList; - ItemSetList aSwitchDataPointAttrList; - ItemSetList aRegressAttrList; - ItemSetList aAverageAttrList; - ItemSetList aErrorAttrList; - - SvxChartDataDescr eDataDescr; - BOOL bShowSym; - BOOL bSwitchData; - - BOOL bNoBuildChart; // BuildChart does nothing if this is true - BOOL bShouldBuildChart; // This is set when BuildChart was called and bNoBuildChart was TRUE - BOOL bReadError; - BOOL mbIsInitialized; - - /// short: textbreak enabled - BOOL bFormatXAxisTextInMultipleLinesIfNecessary; - BOOL bFormatYAxisTextInMultipleLinesIfNecessary; - BOOL bFormatZAxisTextInMultipleLinesIfNecessary; - BOOL bFormatLegendTextInMultipleLinesIfNecessary; - - /// maximum number of lines for textbreak - int nXAxisTextMaximumNumberOfLines; - int nYAxisTextMaximumNumberOfLines; - int nZAxisTextMaximumNumberOfLines; - - long nWidthOfFirstXAxisText; - long nWidthOfLastXAxisText; - - // positions of chart objects - Point aTitleTopCenter; - Point aSubTitleTopCenter; - Rectangle aDiagramRectangle; - Rectangle aLastDiagramRectangle; // ? - Point aLegendTopLeft; - - Point aTitleXAxisPosition; - Point aTitleYAxisPosition; - Point aTitleZAxisPosition; - - ChartAdjust eAdjustXAxesTitle; - ChartAdjust eAdjustYAxesTitle; - ChartAdjust eAdjustZAxesTitle; - - // FG: Falls dieser gesetzt ist so wird bei einem Resize (eigentlich bei jedem Buildchart) - // die relative Position der Gruppenobjekte zur Seite beachtet. - // Je nach Objekt bleibt die linke obere Ecke oder das Zentrum an der gleichen Stelle. - - /** On resize objects remember their position relatively to the page if - this member is TRUE. For some objects the upper left corner is - preserved for others the center position */ - BOOL bUseRelativePositionsForChartGroups; - - /// on manual move of chart objects the calculation of space left has to be changed - BOOL bAdjustMarginsForLegend; - BOOL bAdjustMarginsForMainTitle; - BOOL bAdjustMarginsForSubTitle; - BOOL bAdjustMarginsForXAxisTitle; - BOOL bAdjustMarginsForYAxisTitle; - BOOL bAdjustMarginsForZAxisTitle; - - /// keep track if objects have manually been repositioned - BOOL bDiagramHasBeenMovedOrResized; - BOOL bMainTitleHasBeenMoved; - BOOL bSubTitleHasBeenMoved; - BOOL bLegendHasBeenMoved; - BOOL bXAxisTitleHasBeenMoved; - BOOL bYAxisTitleHasBeenMoved; - BOOL bZAxisTitleHasBeenMoved; - - Size aInitialSizefor3d; - - INT32 nXLastNumFmt; - INT32 nYLastNumFmt; - INT32 nBLastNumFmt; - - /// document languages - LanguageType eLanguage; - LanguageType eLanguageCJK; - LanguageType eLanguageCTL; - - ProjectionType eProjection; -}; - -// _SCH_MODELDATA_HXX -} //namespace binfilter -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |