merge the formfield patch from ooo-build
[ooovba.git] / binfilter / inc / bf_sch / memchrt.hxx
bloba492275ca0a4edd712e179e70d383214dbf2e439
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: memchrt.hxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SCH_MEMCHRT_HXX
32 #define _SCH_MEMCHRT_HXX
34 #ifndef _SFXDEFS_HXX
35 #include <bf_sfx2/sfxdefs.hxx>
36 #endif
37 #ifndef _SFXMODULE_HXX
38 #include <bf_sfx2/module.hxx>
39 #endif
40 #ifndef _COLOR_HXX
41 #include <tools/color.hxx>
42 #endif
43 #ifndef _LINK_HXX
44 #include <tools/link.hxx>
45 #endif
46 #ifndef _STRING_HXX
47 #include <tools/string.hxx>
48 #endif
49 #ifndef _RTL_USTRBUF_HXX_
50 #include <rtl/ustrbuf.hxx>
51 #endif
52 #include <bf_sch/cellranges.hxx>
54 #ifndef _COM_SUN_STAR_CHART_CHARTSERIESADDRESS_HPP_
55 #include <com/sun/star/chart/ChartSeriesAddress.hpp>
56 #endif
57 class SvStream;
59 namespace binfilter {
61 class SfxItemSet;
62 class SvNumberFormatter;
63 class ChartModel;
65 #define SCH_COPY_HACK
67 enum ChartDataId
69 CHDATAID_NONE,
70 CHDATAID_MEMCHART,
71 CHDATAID_DYNCHART,
72 CHDATAID_MEMCHART_PLUS
75 // This struct contains information about selection in the chart, so that
76 // other apps (esp. calc) know what is currently selected
78 struct ChartSelectionInfo
80 ChartSelectionInfo() : nRow(0), nCol(0), fValue(0.0), nValue(0), nSelection(0) {}
81 ChartSelectionInfo(long sel) : nRow(0), nCol(0), fValue(0.0), nValue(0), nSelection(sel) {}
82 BOOL operator == (const ChartSelectionInfo& s) const
84 return nRow == s.nRow
85 && nCol == s.nCol
86 && nSelection == s.nSelection
87 && fValue == s.fValue
88 && nValue == s.nValue
89 && aSelectionColor == s.aSelectionColor;
91 long nRow; // Datenzeilen-Koordinate
92 long nCol; // Datenspaltenkoordinate
93 double fValue; // neuer Wert fuer die Zelle (nCol,nRow)
94 long nValue; // reserviert, evtl. fuer Numberformat und andere Informationen
95 long nSelection; // s.u. , 31-Bit-Register (also besser Int32? -> return ist long)
96 Color aSelectionColor; // Farbe des Selektions-Rahmens
99 // Flags fuer nSelection UND den Rueckgabewert der CallBackFunktion
100 // long ChartSelectionCallback(struct ChartSelectionInfo *pInfo), die mittels
101 // SchMemChart::SetSelectionCallback(...) am Chart angemeldet wird
103 #define CHART_SEL_NONE 1 // bestehende Selektion aufheben (derzeit default, da im Chart keine Multiselektion besteht)
104 #define CHART_SEL_ALL 2 // den gesamten MemChart-Datenbereich selektieren
105 #define CHART_SEL_ROW 4 // die DatenReihe nRow selektieren
106 #define CHART_SEL_COL 8 // die DatenSpalte nCol Selektieren
107 #define CHART_SEL_POINT 16 // den Datenpunkt selektieren
108 #define CHART_SEL_SETCURSOR 32 // Cursor an die Stelle (nCol,nRow) setzen
109 #define CHART_SEL_CHANGEVALUE 64 // Wert in der Tabelle aendern (auf fValue)
110 #define CHART_SEL_COLOR 128 // Farbinformation für farbigen Rahmen um den Selektionsbereich herum ist gesetzt
111 #define CHART_SEL_QUERYSUPPORT 256
112 #define CHART_SEL_QUERYPOSSIBLE 512
115 In der Callback-routine soll wie folgt verfahren werden:
116 Kann eine Aktion (z.B. Aenderung des Wertes) ausgefuehrt werden, so MUSS das
117 entsprechende Flag im Rueckgabewert gesetzt werden, kann die Aktion nicht ausgefuehrt
118 werden, so DARF das Flag NICHT gesetzt werden.
120 Prioritaet der Aktionen:
122 Prio 0 : CHART_SEL_QUERYSUPPORT
123 Prio 1 : CHART_SEL_NONE ; wichtig fuer (spaetere) Multiselektion.
124 Prio 2 : CHART_SEL_BORDERONLY ; Selektionsmodus, wird vorerst immer gesetzt sein
125 Prio n : der Rest....
127 CHART_SEL_QUERYSUPPORT:
128 Ist dieses Flag gesetzt, DARF die Aktion NICHT ausgefuehrt werden, sondern nur
129 zurueckgegeben werden, ob es moeglich waere!
131 CHART_SEL_NONE:
133 Aufheben der Selektion, bei Multiselektion ist dieses Flag NICHT gesetzt, die neue Selektion
134 wird zusaetzlich angewand. (derzeit im Chart nicht implementiert, daher immer gesetzt)
138 // ============================================================
139 // ============================================================
141 // SchMemChart: class for chart data
143 // ============================================================
144 // ============================================================
146 #define TRANS_NONE 0
147 #define TRANS_COL 1
148 #define TRANS_ROW 2
149 #define TRANS_ERROR 3
151 class SchMemChart
153 private:
154 long nLastSelInfoReturn;
155 ULONG nRefCount;
156 mutable String* mpColNameBuffer;
157 mutable String* mpRowNameBuffer;
159 protected :
160 long nTranslated;
161 short nRowCnt;
162 short nColCnt;
163 String aMainTitle;
164 String aSubTitle;
165 String aXAxisTitle;
166 String aYAxisTitle;
167 String aZAxisTitle;
168 short eDataType;
169 String aSomeData1;
170 String aSomeData2;
171 String aSomeData3;
172 String aSomeData4;
173 double *pData;
174 String *pColText;
175 String *pRowText;
176 ChartDataId myID;
179 // number formatter and format id
180 SvNumberFormatter* mpNumFormatter;
181 sal_Int32 *pRowNumFmtId;
182 sal_Int32 *pColNumFmtId;
184 // translation table for row-/column reordering (internal)
185 sal_Int32 *pRowTable;
186 sal_Int32 *pColTable;
187 ChartSelectionInfo aSelectionInfo;
189 // is not copied in copy contrustor (?)
190 Link aAppLink;
191 BOOL bReadOnly;
193 ::rtl::OUString maCategoriesRangeAddress;
194 ::com::sun::star::uno::Sequence<
195 ::com::sun::star::chart::ChartSeriesAddress > maSeriesAddresses;
197 /// contains all information necessary to write the source data ranges
198 SchChartRange maChartRange;
200 ::rtl::OUStringBuffer getXMLStringForCellAddress( const SchCellAddress& rCell );
201 void getSingleCellAddressFromXMLString( const ::rtl::OUString& rXMLString,
202 sal_Int32 nStartPos, sal_Int32 nEndPos,
203 SchSingleCell& rSingleCell );
204 bool getCellAddressFromXMLString( const ::rtl::OUString& rXMLString,
205 sal_Int32 nStartPos, sal_Int32 nEndPos,
206 SchCellAddress& rOutCell,
207 ::rtl::OUString& rOutTableName );
208 bool getCellRangeAddressFromXMLString( const ::rtl::OUString& rXMLString,
209 sal_Int32 nStartPos, sal_Int32 nEndPos,
210 SchCellRangeAddress& rOutRange );
212 public:
214 inline void SetReadOnly( BOOL bNewValue );
215 BOOL IsReadOnly() { return bReadOnly; }
217 SchMemChart(ChartDataId myID);
218 SchMemChart(short nCols, short nRows);
219 SchMemChart(const SchMemChart& rMemChart);
220 ~SchMemChart()
222 delete[] pRowText;
223 delete[] pColText;
224 delete[] pData;
226 if( pRowNumFmtId )
227 delete[] pRowNumFmtId;
228 if( pColNumFmtId )
229 delete[] pColNumFmtId;
230 if( pRowTable )
231 delete[] pRowTable;
232 if( pColTable )
233 delete[] pColTable;
234 delete[] mpRowNameBuffer;
235 delete[] mpColNameBuffer;
238 // initialize number format, -1 means unset
239 void InitNumFmt();
241 // transfer chart selection to calc or writer
242 const ChartSelectionInfo& GetSelectionInfo() const { return aSelectionInfo; }
243 // methods for translation of data
244 inline void ResetTranslation(sal_Int32 *pTable,long nCnt);
245 #if OSL_DEBUG_LEVEL > 0
246 BOOL VerifyTranslation();
247 #endif
248 long GetTranslation() const { return nTranslated; }
249 inline void UpdateTranslation(sal_Int32 *pTable,long nCnt);
250 // for acces always use these Get-methods !
251 double GetTransData(long nCol,long nRow);
252 double GetTransDataInPercent(long nCol ,long nRow,BOOL bRowData) const;
253 const String& GetTransColText(long nCol) const;
254 const String& GetTransRowText(long nRow) const;
256 const sal_Int32 *GetRowTranslation() const { return pRowTable; }
257 const sal_Int32 *GetColTranslation() const { return pColTable; }
259 #ifdef SCH_COPY_HACK
260 const sal_Int32* GetRowNumFmtTable() const { return pRowNumFmtId; }
261 const sal_Int32* GetColNumFmtTable() const { return pColNumFmtId; }
263 // ********************
264 // BM: Fix for #68864#
265 // Use these four methods with care! The arrays MUST have the correct size!
266 // ********************
267 void SetRowTranslation( const sal_Int32* pTransTable )
269 if( !pRowTable ) return;
270 for( sal_Int32 i=0; i<nRowCnt; i++ )
271 pRowTable[ i ] = pTransTable[ i ];
273 void SetColTranslation( const sal_Int32* pTransTable )
275 if( !pColTable ) return;
276 for( sal_Int32 i=0; i<nColCnt; i++ )
277 pColTable[ i ] = pTransTable[ i ];
279 void SetRowNumFmtTable( const sal_Int32* pNumFmtTable )
281 if( !pRowNumFmtId ) return;
282 for( sal_Int32 i=0; i<nRowCnt; i++ )
283 pRowNumFmtId[ i ] = pNumFmtTable[ i ];
285 void SetColNumFmtTable( const sal_Int32* pNumFmtTable )
287 if( !pColNumFmtId ) return;
288 for( sal_Int32 i=0; i<nColCnt; i++ )
289 pColNumFmtId[ i ] = pNumFmtTable[ i ];
291 // this is only valid if the corresponding translation table was set correctly!
292 void SetTranslation( long nTrans ) { nTranslated = nTrans; }
293 // ********************
294 #endif
298 // number format
300 void SetNumberFormatter(SvNumberFormatter* pNumFormatter) { mpNumFormatter = pNumFormatter; }
301 SvNumberFormatter* GetNumberFormatter() const { return mpNumFormatter; }
303 void SetNumFormatIdRow( const long nRow, const long nFmtId ) { if( pRowNumFmtId && nRow < nRowCnt ) pRowNumFmtId[ nRow ] = nFmtId; }
304 void SetNumFormatIdCol( const long nCol, const long nFmtId ) { if( pColNumFmtId && nCol < nColCnt ) pColNumFmtId[ nCol ] = nFmtId; }
305 long GetNumFormatIdRow( const long nRow ) const { return ( pRowNumFmtId && nRow < nRowCnt )? pRowNumFmtId[ nRow ]: -1; }
306 long GetNumFormatIdCol( const long nCol ) const { return ( pColNumFmtId && nCol < nColCnt )? pColNumFmtId[ nCol ]: -1; }
307 long GetTransNumFormatIdRow( const long nRow ) const;
308 long GetTransNumFormatIdCol( const long nCol ) const;
310 void SetSelectionHdl(const Link& rLink) { aAppLink=rLink; }
312 void SetNonNumericData(const SchMemChart &rMemChart);
314 void SetDataType(short eType) { eDataType = eType; }
315 short GetDataType() const { return eDataType; }
317 short GetColCount() const { return nColCnt; }
318 short GetRowCount() const { return nRowCnt; }
320 const String& GetMainTitle() const { return aMainTitle; }
321 const String& GetSubTitle() const { return aSubTitle; }
323 void SetMainTitle(const String& rText) { aMainTitle = rText; }
324 void SetSubTitle(const String& rText) { aSubTitle = rText; }
326 const String& GetXAxisTitle() const { return aXAxisTitle; }
327 const String& GetYAxisTitle() const { return aYAxisTitle; }
328 const String& GetZAxisTitle() const { return aZAxisTitle; }
330 void SetXAxisTitle(const String& rText) { aXAxisTitle = rText; }
331 void SetYAxisTitle(const String& rText) { aYAxisTitle = rText; }
332 void SetZAxisTitle(const String& rText) { aZAxisTitle = rText; }
334 friend SvStream& operator << (SvStream& rOut, const SchMemChart& rMemChart);
335 friend SvStream& operator >> (SvStream& rIn, SchMemChart& rMemChart);
337 const String& GetColText(short nCol) const { return pColText[nCol]; }
338 const String& GetRowText(short nRow) const { return pRowText[nRow]; }
340 ChartDataId GetId() const { return myID; }
341 double GetData(short nCol, short nRow) const { return pData[nCol * nRowCnt + nRow]; }
342 double GetDataInPercent(const short nCol , const short nRow, const BOOL bRowData) const;
344 inline void InsertCols(short nAtCol, short nCount);
345 inline void RemoveCols(short nAtCol, short nCount);
346 inline void InsertRows(short nAtRow, short nCount);
347 inline void RemoveRows(short nAtRow, short nCount);
348 inline void SwapCols(int nAtCol1, int nAtCol2);
349 inline void SwapRows(int nAtRow1, int nAtRow2);
351 void SetData(short nCol, short nRow, const double& rVal)
352 { pData[nCol * nRowCnt + nRow] = rVal; }
354 String& SomeData1() { return aSomeData1; }
355 String& SomeData2() { return aSomeData2; }
356 String& SomeData3() { return aSomeData3; }
357 String& SomeData4() { return aSomeData4; }
359 const String& SomeData1() const { return aSomeData1; }
360 const String& SomeData2() const { return aSomeData2; }
361 const String& SomeData3() const { return aSomeData3; }
362 const String& SomeData4() const { return aSomeData4; }
364 void SetColText(short nCol, const String& rText) { pColText[nCol] = rText; }
365 void SetRowText(short nRow, const String& rText) { pRowText[nRow] = rText; }
371 friend class ChartModel;
373 void IncreaseRefCount() { nRefCount++; }
374 BOOL DecreaseRefCount()
376 DBG_ASSERT( nRefCount, "SchMemChart::DecreaseRefCount: illegal decrement of RefCount");
377 if(nRefCount) nRefCount--;
378 return (nRefCount==0); // true iff object can be deleted
381 // get a string for default (column|row) labels
382 // the indexes start at 0, but the text starts with "(Column|Row) 1"
383 String GetDefaultColumnText( sal_Int32 nCol ) const;
384 String GetDefaultRowText( sal_Int32 nRow ) const;
386 // ====================
388 /// @deprecated
389 void SetCategoriesRangeAddress( const ::rtl::OUString& rCellRangeAddress )
390 { maCategoriesRangeAddress = rCellRangeAddress; }
392 /// @deprecated
393 void SetSeriesAddresses( const ::com::sun::star::uno::Sequence< ::com::sun::star::chart::ChartSeriesAddress >& rCellRangeAddresses )
394 { maSeriesAddresses = rCellRangeAddresses; }
396 /// @deprecated
397 const ::rtl::OUString&
398 GetCategoriesRangeAddress()
399 { return maCategoriesRangeAddress; }
401 /// @deprecated
402 const ::com::sun::star::uno::Sequence< ::com::sun::star::chart::ChartSeriesAddress >&
403 GetSeriesAddresses()
404 { return maSeriesAddresses; }
406 // --------------------
408 /// get table ranges for entire chart
409 const SchChartRange& GetChartRange() const
410 { return maChartRange; }
411 /// set table ranges for entire chart
412 void SetChartRange( const SchChartRange& rRange )
413 { maChartRange = rRange; }
415 /** convert SomeData string(s) to SchChartRange and vice versa for Writer
416 @return <TRUE/>, iff the conversion was successfully done.
418 bool ConvertChartRangeForWriter( BOOL bOldToNew = TRUE );
420 /** convert SomeData string(s) to SchChartRange and vice versa for Calc
421 @return <TRUE/>, iff the conversion was successfully done.
423 bool ConvertChartRangeForCalc( BOOL bOldToNew = FALSE );
425 ::rtl::OUString getXMLStringForChartRange();
426 void getChartRangeForXMLString( const ::rtl::OUString& rXMLString );
428 /** create a string of form "1 2 3 4" containing a list of table numbers
429 in SchChartRange maChartRange to create SomeData for calc
431 ::rtl::OUString createTableNumberList();
432 /** prerequisite: maChartRange must be set and have the correct dimension
433 for all table numbers to fit in
435 void parseTableNumberList( const ::rtl::OUString& rList );
438 // ==================== Inline Implementations ====================
440 inline void SchMemChart::ResetTranslation(sal_Int32 *pTable,long nCnt)
442 long i;
443 if(pTable)
444 for(i=0;i<nCnt;i++)
445 pTable[i]=i;
447 if(pTable==pRowTable && nTranslated==TRANS_ROW)
448 nTranslated=TRANS_NONE;
449 if(pTable==pColTable && nTranslated==TRANS_COL)
450 nTranslated=TRANS_NONE;
453 inline void SchMemChart::UpdateTranslation(sal_Int32 *pTable,long nCnt)
455 if( (pTable==pRowTable && nTranslated==TRANS_ROW)
456 ||(pTable==pColTable && nTranslated==TRANS_COL))
458 long i;
459 sal_Int32 nMax=0;
460 for(i=0;i<nCnt;i++)
461 nMax=Max(nMax,pTable[i]);
463 if(nMax>=nCnt)//something added
465 long nStart=-1,nEnd=-1;
466 for(i=0;i<nCnt;i++)
468 if(pTable[i]==-1)//markierung gefunden
470 if(nStart!=-1)
471 nEnd=i;
472 else
473 nStart=i;
477 long nDiff=nEnd-nStart;//soviele sind neu
479 DBG_ASSERT( (nDiff>0) && ((nEnd-nStart) == (nCnt-nMax)),"MemChart::Something went wrong!");
481 if( (nDiff<=0) || ((nEnd-nStart)!=(nCnt-nMax)))
482 return;
484 long nNew = nStart;
486 for(i=0;i<nCnt;i++)
488 if(pTable[i]>nStart)
490 pTable[i]+=nDiff; //nach hinten verschieben
492 else if (pTable[i]==-1)
494 pTable[i]=nNew; //"einfuegen"
495 nNew++;
499 else //something removed
501 ResetTranslation(pTable,nCnt); //keine schoene Loesung....(ToDo:), Aufwand recht hoch...
504 else
506 ResetTranslation(pTable,nCnt); //Normale Reihenfolge, da nicht die Sortierte Tabelll geupdated wird
510 inline void SchMemChart::InsertCols(short nAtCol, short nCount)
512 double* pOldData = pData;
514 short nNewColCnt = nColCnt + nCount;
516 pData = new double[nNewColCnt * nRowCnt];
518 short i, j, nOld, nMax;
520 for (i = 0, nOld = 0; i < nAtCol; i++, nOld++)
522 for (j = 0; j < nRowCnt; j++)
524 pData[i * nRowCnt + j] = pOldData[nOld * nRowCnt + j];
528 nMax = nAtCol + nCount;
530 for (; i < nMax; i++)
532 for (j = 0; j < nRowCnt; j++)
534 pData[i * nRowCnt + j] = 0.0;
538 for (; i < nNewColCnt; i++, nOld++)
540 for (j = 0; j < nRowCnt; j++)
542 pData[i * nRowCnt + j] = pOldData[nOld * nRowCnt + j];
545 delete[] pOldData;
547 String *pOldColText = pColText;
548 sal_Int32 *pOldColNumFmtId = pColNumFmtId;
549 sal_Int32 *pOldColTable = pColTable;
551 pColNumFmtId = new sal_Int32 [nNewColCnt];
552 pColTable = new sal_Int32 [nNewColCnt];
553 pColText = new String[nNewColCnt];
555 long nC=nNewColCnt;
556 while(nC--)
558 pColTable[nC] = -1; //init
559 pColNumFmtId[nC] = -1;
562 for (i = 0, nOld = 0;; i++, nOld++)
564 if (i == nAtCol)
565 i += nCount;
566 if (i >= nNewColCnt)
567 break;
569 pColText[i] = pOldColText[nOld];
570 pColTable[i] = pOldColTable[nOld];
571 pColNumFmtId[i] = pOldColNumFmtId[nOld];
574 delete[] pOldColNumFmtId;
575 delete[] pOldColTable;
576 delete[] pOldColText;
578 nColCnt = nNewColCnt;
580 UpdateTranslation(pColTable,nColCnt);
583 inline void SchMemChart::RemoveCols(short nAtCol, short nCount)
585 DBG_ASSERT( nAtCol < nColCnt, "column index overflow");
587 if (nAtCol + nCount > nColCnt)
588 nCount = nColCnt - nAtCol;
590 short nNewColCnt = nColCnt - nCount;
592 double* pOldData = pData;
593 pData = new double[nNewColCnt * nRowCnt];
595 String* pOldColText = pColText;
596 sal_Int32* pOldColNumFmtId = pColNumFmtId;
597 sal_Int32* pOldColTable = pColTable;
599 pColText = new String[nNewColCnt];
600 pColNumFmtId = new sal_Int32 [nNewColCnt];
601 pColTable = new sal_Int32 [nNewColCnt];
603 short i, j, nOld;
605 for (i = 0, nOld = 0;; i++, nOld++)
607 if (nOld == nAtCol)
608 nOld += nCount;
609 if (nOld >= nColCnt)
610 break;
612 for (j = 0; j < nRowCnt; j++)
613 pData[i * nRowCnt + j] = pOldData[nOld * nRowCnt + j];
615 pColText[i] = pOldColText[nOld];
616 pColTable[i] = pOldColTable[nOld];
617 pColNumFmtId[i] = pOldColNumFmtId[nOld];
620 delete[] pOldData;
621 delete[] pOldColText;
622 delete[] pOldColTable;
623 delete[] pOldColNumFmtId;
625 nColCnt = nNewColCnt;
627 UpdateTranslation(pColTable,nColCnt);
630 inline void SchMemChart::InsertRows(short nAtRow, short nCount)
632 double* pOldData = pData;
634 short nNewRowCnt = nRowCnt + nCount;
636 pData = new double[nColCnt * nNewRowCnt];
638 short i, j, nOld, nMax, nGapEnd;
640 for (i = 0; i < nColCnt; i++)
642 for (j = 0, nOld= 0; j < nAtRow; j++, nOld++)
644 pData[i * nNewRowCnt + j] = pOldData[i * nRowCnt + nOld];
648 nMax = nAtRow + nCount;
650 for (i = 0; i < nColCnt; i++)
652 for (j = nAtRow; j < nMax; j++)
654 pData[i * nNewRowCnt + j] = 0.0;
658 nGapEnd = nMax;
660 for (i = 0; i < nColCnt; i++)
662 for (j = nGapEnd, nOld = nAtRow; j < nNewRowCnt; j++, nOld++)
664 pData[i * nNewRowCnt + j] = pOldData[i * nRowCnt + nOld];
667 delete[] pOldData;
669 String *pOldRowText =pRowText;
670 sal_Int32 *pOldRowNumFmtId =pRowNumFmtId;
671 sal_Int32 *pOldRowTable =pRowTable;
673 pRowNumFmtId = new sal_Int32 [nNewRowCnt];
674 pRowTable = new sal_Int32 [nNewRowCnt];
675 pRowText = new String[nNewRowCnt];
677 long nC=nNewRowCnt;
678 while(nC--) //init
680 pRowNumFmtId[nC] = -1;
681 pRowTable[nC] = -1;
684 for (i = 0, nOld = 0;; i++, nOld++)
686 if (i == nAtRow)
687 i += nCount;
688 if (i >= nNewRowCnt)
689 break;
691 pRowNumFmtId[i] = pOldRowNumFmtId[nOld];
692 pRowTable[i] = pOldRowTable[nOld];
693 pRowText[i] = pOldRowText[nOld];
696 delete[] pOldRowText;
697 delete[] pOldRowTable;
698 delete[] pOldRowNumFmtId;
700 nRowCnt = nNewRowCnt;
702 UpdateTranslation(pRowTable,nRowCnt);
705 inline void SchMemChart::RemoveRows(short nAtRow, short nCount)
707 DBG_ASSERT( nAtRow < nRowCnt, "row index overflow" );
709 if (nAtRow + nCount > nRowCnt)
710 nCount = nRowCnt - nAtRow;
712 short nNewRowCnt = nRowCnt - nCount;
714 double* pOldData = pData;
715 pData = new double[nColCnt * nNewRowCnt];
717 short i, j, nOld;
719 for (i = 0; i < nColCnt; i++)
720 for (j = 0, nOld = 0;; j++, nOld++)
722 if (nOld == nAtRow)
723 nOld += nCount;
724 if (nOld >= nRowCnt)
725 break;
727 pData[i * nNewRowCnt + j] = pOldData[i * nRowCnt + nOld];
730 delete[] pOldData;
732 String* pOldRowText = pRowText;
733 sal_Int32* pOldRowNumFmtId = pRowNumFmtId;
734 sal_Int32* pOldRowTable = pRowTable;
736 pRowText = new String[nNewRowCnt];
737 pRowNumFmtId = new sal_Int32 [nNewRowCnt];
738 pRowTable = new sal_Int32 [nNewRowCnt];
740 for (i = 0, nOld = 0;; i++, nOld++)
742 if (nOld == nAtRow)
743 nOld += nCount;
744 if (nOld >= nRowCnt)
745 break;
747 pRowText[i] = pOldRowText[nOld];
748 pRowTable[i] = pOldRowTable[nOld];
749 pRowNumFmtId[i] = pOldRowNumFmtId[nOld];
752 delete[] pOldRowText;
753 delete[] pOldRowTable;
754 delete[] pOldRowNumFmtId;
756 nRowCnt = nNewRowCnt;
758 UpdateTranslation(pRowTable,nRowCnt);
761 inline void SchMemChart::SwapCols(int nAtCol1, int nAtCol2)
763 // Wenn hier Aenderungen Stattfinden, mu?auch im Logbuch
764 // angepasst werden
765 if (nAtCol1 > nAtCol2)
767 long nTemp = nAtCol1;
769 nAtCol1 = nAtCol2;
770 nAtCol2 = nTemp;
773 if (nAtCol1 >= nColCnt - 1) nAtCol1 = nColCnt - 2;
774 if (nAtCol2 >= nColCnt) nAtCol2 = nColCnt - 1;
776 nAtCol1 = Max(nAtCol1, 0);
777 nAtCol2 = Max(nAtCol2, 0);
778 //Insbesondere bis hier,, da dieses Handling autokorrigierend ist
780 double *pSrc = pData + nAtCol1 * nRowCnt;
781 double *pDest = pData + nAtCol2 * nRowCnt;
783 for (long nSwaps = 0;
784 nSwaps < nRowCnt;
785 nSwaps ++)
787 double fSwap = *pSrc;
789 *pSrc = *pDest;
790 *pDest = fSwap;
792 pSrc ++;
793 pDest ++;
796 String aTemp = pColText [nAtCol1];
797 pColText [nAtCol1] = pColText [nAtCol2];
798 pColText [nAtCol2] = aTemp;
800 long nTmp = pColTable [nAtCol1];
801 pColTable [nAtCol1] = pColTable [nAtCol2];
802 pColTable [nAtCol2] = nTmp;
804 nTmp = pColNumFmtId[nAtCol1];
805 pColNumFmtId [nAtCol1] = pColNumFmtId [nAtCol2];
806 pColNumFmtId [nAtCol2] = nTmp;
808 ResetTranslation(pColTable,nColCnt); //ToDo:???
811 inline void SchMemChart::SwapRows(int nAtRow1,int nAtRow2)
814 // Wenn hier Aenderungen Stattfinden, mu?auch im Logbuch
815 // angepasst werden
816 if (nAtRow1 > nAtRow2)
818 long nTemp = nAtRow1;
820 nAtRow1 = nAtRow2;
821 nAtRow2 = nTemp;
824 if (nAtRow1 >= nRowCnt - 1) nAtRow1 = nRowCnt - 2;
825 if (nAtRow2 >= nRowCnt) nAtRow2 = nRowCnt - 1;
827 nAtRow1 = Max(nAtRow1, 0);
828 nAtRow2 = Max(nAtRow2, 0);
829 //Insbesondere bis hier,, da dieses Handling autokorrigierend ist
831 double *pSrc = pData + nAtRow1;
832 double *pDest = pData + nAtRow2;
834 for (long nSwaps = 0;
835 nSwaps < nColCnt;
836 nSwaps ++)
838 double fSwap = *pSrc;
840 *pSrc = *pDest;
841 *pDest = fSwap;
843 pSrc += nRowCnt;
844 pDest += nRowCnt;
847 String aTemp = pRowText [nAtRow1];
848 pRowText [nAtRow1] = pRowText [nAtRow2];
849 pRowText [nAtRow2] = aTemp;
851 long nTmp = pRowTable [nAtRow1];
852 pRowTable [nAtRow1] = pRowTable [nAtRow2];
853 pRowTable [nAtRow2] = nTmp;
855 nTmp = pRowNumFmtId[nAtRow1];
856 pRowNumFmtId [nAtRow1] = pRowNumFmtId [nAtRow2];
857 pRowNumFmtId [nAtRow2] = nTmp;
859 ResetTranslation(pRowTable,nRowCnt);//ToDo:???
862 inline void SchMemChart::SetReadOnly( BOOL bNewValue )
864 // do not set ReadOnly, if there is no external data set
865 if( bNewValue && maChartRange.maRanges.size() == 0 )
866 return;
867 else
868 bReadOnly = bNewValue;
871 } //namespace binfilter
872 #endif // _SCH_MEMCHRT_HXX