Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/chart/ChartDataRowSource.hpp>
31 : : #include <com/sun/star/chart2/data/XDataProvider.hpp>
32 : : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
33 : : #include <com/sun/star/beans/PropertyState.hpp>
34 : :
35 : : #include <sot/storage.hxx>
36 : : #include <sot/clsids.hxx>
37 : :
38 : : #include "edtwin.hxx"
39 : : #include "wrtsh.hxx"
40 : : #include "cmdid.h"
41 : : #include "frmatr.hxx"
42 : : #include "view.hxx"
43 : : #include "basesh.hxx"
44 : : #include "swundo.hxx"
45 : : #include "tablemgr.hxx"
46 : : #include "frmfmt.hxx"
47 : : #include "instable.hxx"
48 : : #include "swerror.h"
49 : : #include "table.hrc"
50 : : #include "swabstdlg.hxx"
51 : : #include "swcli.hxx"
52 : : #include "docsh.hxx"
53 : : #include "unotbl.hxx"
54 : : #include "unochart.hxx"
55 : :
56 : : using namespace ::com::sun::star;
57 : :
58 : : /*------------------------------------------------------------------------
59 : : Beschreibung: Zeilenhoehe einstellen (Dialog)
60 : : ------------------------------------------------------------------------*/
61 : :
62 : :
63 : 0 : void SwTableFUNC::ColWidthDlg( Window *pParent )
64 : : {
65 : 0 : InitTabCols();
66 : 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
67 : : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
68 : :
69 : 0 : VclAbstractDialog* pDlg = pFact->CreateSwTableWidthDlg( pParent, *this ,DLG_COL_WIDTH );
70 : : OSL_ENSURE(pDlg, "Dialogdiet fail!");
71 : 0 : pDlg->Execute();
72 [ # # ]: 0 : delete pDlg;
73 : 0 : }
74 : :
75 : : /*--------------------------------------------------------------------
76 : : Beschreibung: Breite ermitteln
77 : : --------------------------------------------------------------------*/
78 : :
79 : :
80 : 0 : SwTwips SwTableFUNC::GetColWidth(sal_uInt16 nNum) const
81 : : {
82 : 0 : SwTwips nWidth = 0;
83 : :
84 [ # # ]: 0 : if( aCols.Count() > 0 )
85 : : {
86 [ # # ]: 0 : if(aCols.Count() == GetColCount())
87 : : {
88 : 0 : nWidth = (SwTwips)((nNum == aCols.Count()) ?
89 : 0 : aCols.GetRight() - aCols[nNum-1] :
90 : 0 : nNum == 0 ? aCols[nNum] - aCols.GetLeft() :
91 [ # # ][ # # ]: 0 : aCols[nNum] - aCols[nNum-1]);
92 : : }
93 : : else
94 : : {
95 : 0 : SwTwips nRValid = nNum < GetColCount() ?
96 : 0 : aCols[(sal_uInt16)GetRightSeparator((int)nNum)]:
97 [ # # ]: 0 : aCols.GetRight();
98 : : SwTwips nLValid = nNum ?
99 : 0 : aCols[(sal_uInt16)GetRightSeparator((int)nNum - 1)]:
100 [ # # ]: 0 : aCols.GetLeft();
101 : 0 : nWidth = nRValid - nLValid;
102 : : }
103 : : }
104 : : else
105 : 0 : nWidth = aCols.GetRight();
106 : :
107 : 0 : return nWidth;
108 : : }
109 : :
110 : :
111 : :
112 : 0 : SwTwips SwTableFUNC::GetMaxColWidth( sal_uInt16 nNum ) const
113 : : {
114 : : OSL_ENSURE(nNum <= aCols.Count(), "Index out of Area");
115 : :
116 [ # # ]: 0 : if ( GetColCount() > 0 )
117 : : {
118 : : // Die max. Breite ergibt sich aus der eigenen Breite und
119 : : // der Breite der Nachbarzellen um je MINLAY verringert
120 : : SwTwips nMax = nNum == 0 ?
121 : 0 : GetColWidth(1) - MINLAY :
122 : 0 : nNum == GetColCount() ?
123 : 0 : GetColWidth( nNum-1 ) - MINLAY :
124 [ # # # # ]: 0 : GetColWidth(nNum - 1) + GetColWidth( nNum + 1 ) - 2 * MINLAY;
125 : :
126 : 0 : return nMax + GetColWidth(nNum) ;
127 : : }
128 : : else
129 : 0 : return GetColWidth(nNum);
130 : : }
131 : :
132 : :
133 : :
134 : 0 : void SwTableFUNC::SetColWidth(sal_uInt16 nNum, SwTwips nNewWidth )
135 : : {
136 : : // aktuelle Breite setzen
137 : : // alle folgenden Verschieben
138 : 0 : sal_Bool bCurrentOnly = sal_False;
139 : :
140 [ # # ]: 0 : if ( aCols.Count() > 0 )
141 : : {
142 [ # # ]: 0 : if(aCols.Count() != GetColCount())
143 : 0 : bCurrentOnly = sal_True;
144 : 0 : SwTwips nWidth = GetColWidth(nNum);
145 : :
146 : 0 : int nDiff = (int)(nNewWidth - nWidth);
147 [ # # ]: 0 : if( !nNum )
148 : 0 : aCols[ static_cast< sal_uInt16 >(GetRightSeparator(0)) ] += nDiff;
149 [ # # ]: 0 : else if( nNum < GetColCount() )
150 : : {
151 [ # # ]: 0 : if(nDiff < GetColWidth(nNum + 1) - MINLAY)
152 : 0 : aCols[ static_cast< sal_uInt16 >(GetRightSeparator(nNum)) ] += nDiff;
153 : : else
154 : : {
155 : 0 : int nDiffLeft = nDiff - (int)GetColWidth(nNum + 1) + (int)MINLAY;
156 : 0 : aCols[ static_cast< sal_uInt16 >(GetRightSeparator(nNum)) ] += (nDiff - nDiffLeft);
157 : 0 : aCols[ static_cast< sal_uInt16 >(GetRightSeparator(nNum - 1)) ] -= nDiffLeft;
158 : : }
159 : : }
160 : : else
161 : 0 : aCols[ static_cast< sal_uInt16 >(GetRightSeparator(nNum-1)) ] -= nDiff;
162 : : }
163 : : else
164 : 0 : aCols.SetRight( Min( nNewWidth, aCols.GetRightMax()) );
165 : :
166 : 0 : pSh->StartAllAction();
167 : 0 : pSh->SetTabCols( aCols, bCurrentOnly );
168 : 0 : pSh->EndAllAction();
169 : 0 : }
170 : :
171 : :
172 : :
173 : 0 : void SwTableFUNC::InitTabCols()
174 : : {
175 : : OSL_ENSURE(pSh, "no Shell");
176 : :
177 [ # # ][ # # ]: 0 : if( pFmt && pSh)
178 : 0 : pSh->GetTabCols( aCols );
179 : 0 : }
180 : :
181 : :
182 : :
183 : 0 : SwTableFUNC::SwTableFUNC(SwWrtShell *pShell, sal_Bool bCopyFmt)
184 : 0 : : pFmt(pShell->GetTableFmt()),
185 : : pSh(pShell),
186 : 0 : bCopy(bCopyFmt)
187 : : {
188 : : // gfs. das Format fuer die Bearbeitung kopieren
189 [ # # ][ # # ]: 0 : if( pFmt && bCopy )
190 [ # # ][ # # ]: 0 : pFmt = new SwFrmFmt( *pFmt );
191 : 0 : }
192 : :
193 : :
194 : :
195 : 0 : SwTableFUNC::~SwTableFUNC()
196 : : {
197 [ # # ]: 0 : if(bCopy)
198 [ # # ][ # # ]: 0 : delete pFmt;
199 : 0 : }
200 : :
201 : 0 : void SwTableFUNC::UpdateChart()
202 : : {
203 : : //Update der Felder in der Tabelle vom User ausgeloesst, alle
204 : : //Charts zu der Tabelle werden auf den neuesten Stand gebracht.
205 : 0 : SwFrmFmt *pFmt2 = pSh->GetTableFmt();
206 [ # # ][ # # ]: 0 : if ( pFmt2 && pSh->HasOLEObj( pFmt2->GetName() ) )
[ # # ]
207 : : {
208 : 0 : pSh->StartAllAction();
209 : 0 : pSh->UpdateCharts( pFmt2->GetName() );
210 : 0 : pSh->EndAllAction();
211 : : }
212 : 0 : }
213 : :
214 : 0 : uno::Reference< frame::XModel > SwTableFUNC::InsertChart(
215 : : uno::Reference< chart2::data::XDataProvider > &rxDataProvider,
216 : : sal_Bool bFillWithData,
217 : : const rtl::OUString &rCellRange,
218 : : SwFlyFrmFmt** ppFlyFrmFmt )
219 : : {
220 : 0 : uno::Reference< frame::XModel > xChartModel;
221 [ # # ]: 0 : pSh->StartUndo( UNDO_UI_INSERT_CHART );
222 [ # # ]: 0 : pSh->StartAllAction();
223 : :
224 [ # # ]: 0 : String aName;
225 [ # # ][ # # ]: 0 : if (pSh->IsCrsrInTbl())
226 : : {
227 [ # # ][ # # ]: 0 : aName = pSh->GetTableFmt()->GetName();
228 : : // insert node before table
229 [ # # ]: 0 : pSh->MoveTable( fnTableCurr, fnTableStart );
230 [ # # ]: 0 : pSh->Up( sal_False, 1, sal_False );
231 [ # # ][ # # ]: 0 : if ( pSh->IsCrsrInTbl() )
232 : : {
233 [ # # ][ # # ]: 0 : if ( aName != pSh->GetTableFmt()->GetName() )
[ # # ]
234 [ # # ]: 0 : pSh->Down( sal_False, 1, sal_False ); // two adjacent tables
235 : : }
236 [ # # ]: 0 : pSh->SplitNode();
237 : : }
238 : :
239 : : // insert chart
240 : 0 : ::rtl::OUString aObjName;
241 [ # # ]: 0 : comphelper::EmbeddedObjectContainer aCnt;
242 : : uno::Reference < embed::XEmbeddedObject > xObj =
243 [ # # ][ # # ]: 0 : aCnt.CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aObjName );
[ # # ][ # # ]
[ # # ]
244 : :
245 [ # # ]: 0 : ::svt::EmbeddedObjectRef aEmbObjRef( xObj, ::com::sun::star::embed::Aspects::MSOLE_CONTENT );
246 [ # # ]: 0 : if ( xObj.is() )
247 : : {
248 : :
249 : 0 : SwFlyFrmFmt* pTmp = 0;
250 [ # # ]: 0 : pSh->InsertOleObject( aEmbObjRef, &pTmp );
251 [ # # ]: 0 : if (ppFlyFrmFmt)
252 : 0 : *ppFlyFrmFmt = pTmp;
253 : :
254 [ # # ]: 0 : uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
255 [ # # ]: 0 : if( xCompSupp.is())
256 : : {
257 [ # # ][ # # ]: 0 : xChartModel.set( xCompSupp->getComponent(), uno::UNO_QUERY );
[ # # ]
258 [ # # ]: 0 : if( xChartModel.is() )
259 [ # # ][ # # ]: 0 : xChartModel->lockControllers(); //#i79578# don't request a new replacement image for charts to often - block change notifications
260 : : }
261 : :
262 : : // set the table name at the OLE-node
263 [ # # ]: 0 : if (aName.Len())
264 [ # # ]: 0 : pSh->SetChartName( aName );
265 : : }
266 [ # # ]: 0 : pSh->EndAllAction();
267 : :
268 [ # # ]: 0 : if ( xObj.is() )
269 : : {
270 : : // Let the chart be activated after the inserting
271 [ # # ]: 0 : SfxInPlaceClient* pClient = pSh->GetView().FindIPClient( xObj, &pSh->GetView().GetEditWin() );
272 [ # # ]: 0 : if ( !pClient )
273 : : {
274 [ # # ][ # # ]: 0 : pClient = new SwOleClient( &pSh->GetView(), &pSh->GetView().GetEditWin(), aEmbObjRef );
275 : 0 : pSh->SetCheckForOLEInCaption( sal_True );
276 : : }
277 [ # # ]: 0 : pSh->CalcAndSetScale( aEmbObjRef );
278 : : //#50270# Error brauchen wir nicht handeln, das erledigt das
279 : : //DoVerb in der SfxViewShell
280 [ # # ]: 0 : ErrCode nErr = pClient->DoVerb( SVVERB_SHOW );
281 : : (void) nErr;
282 : : }
283 : :
284 [ # # ]: 0 : uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xChartModel, uno::UNO_QUERY );
285 [ # # ][ # # ]: 0 : if (bFillWithData && xDataReceiver.is() && rxDataProvider.is())
[ # # ][ # # ]
286 : : {
287 [ # # ][ # # ]: 0 : xDataReceiver->attachDataProvider( rxDataProvider );
288 : :
289 [ # # ][ # # ]: 0 : uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pSh->GetView().GetDocShell()->GetModel(), uno::UNO_QUERY );
[ # # ]
290 [ # # ][ # # ]: 0 : xDataReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
291 : :
292 : : // default values for ranges that do not consist of a single row or column
293 : 0 : bool bHasCategories = true;
294 : 0 : bool bFirstCellAsLabel = true;
295 : 0 : chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
296 : :
297 : : SwRangeDescriptor aDesc;
298 [ # # ][ # # ]: 0 : FillRangeDescriptor( aDesc, rCellRange );
[ # # ]
299 [ # # ][ # # ]: 0 : bool bSingleRowCol = aDesc.nTop == aDesc.nBottom || aDesc.nLeft == aDesc.nRight;
300 [ # # ]: 0 : if (bSingleRowCol)
301 : : {
302 [ # # ]: 0 : aDesc.Normalize();
303 : 0 : sal_Int32 nRowLen = aDesc.nRight - aDesc.nLeft + 1;
304 : 0 : sal_Int32 nColLen = aDesc.nBottom - aDesc.nTop + 1;
305 : :
306 : 0 : bHasCategories = false;
307 [ # # ][ # # ]: 0 : if (nRowLen == 1 && nColLen == 1)
308 : 0 : bFirstCellAsLabel = false;
309 [ # # ]: 0 : else if (nRowLen > 1)
310 : 0 : eDataRowSource = chart::ChartDataRowSource_ROWS;
311 [ # # ]: 0 : else if (nColLen > 1)
312 : 0 : eDataRowSource = chart::ChartDataRowSource_COLUMNS;
313 : : else {
314 : : OSL_FAIL("unexpected state" );
315 : : }
316 : : }
317 : :
318 [ # # ]: 0 : uno::Sequence< beans::PropertyValue > aArgs( 4 );
319 [ # # ]: 0 : aArgs[0] = beans::PropertyValue(
320 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CellRangeRepresentation")), -1,
321 [ # # ][ # # ]: 0 : uno::makeAny( rCellRange ), beans::PropertyState_DIRECT_VALUE );
322 [ # # ]: 0 : aArgs[1] = beans::PropertyValue(
323 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasCategories")), -1,
324 [ # # ][ # # ]: 0 : uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
325 [ # # ]: 0 : aArgs[2] = beans::PropertyValue(
326 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FirstCellAsLabel")), -1,
327 [ # # ][ # # ]: 0 : uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
328 [ # # ]: 0 : aArgs[3] = beans::PropertyValue(
329 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataRowSource")), -1,
330 [ # # ][ # # ]: 0 : uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
331 [ # # ][ # # ]: 0 : xDataReceiver->setArguments( aArgs );
[ # # ]
332 : : }
333 : :
334 [ # # ]: 0 : pSh->EndUndo( UNDO_UI_INSERT_CHART );
335 : :
336 [ # # ]: 0 : if( xChartModel.is() )
337 [ # # ][ # # ]: 0 : xChartModel->unlockControllers(); //#i79578# don't request a new replacement image for charts to often
338 [ # # ][ # # ]: 0 : return xChartModel;
[ # # ]
339 : : }
340 : :
341 : 0 : sal_uInt16 SwTableFUNC::GetCurColNum() const
342 : : {
343 : 0 : sal_uInt16 nPos = pSh->GetCurTabColNum();
344 : 0 : sal_uInt16 nCount = 0;
345 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nPos; i++ )
346 [ # # ]: 0 : if(aCols.IsHidden(i))
347 : 0 : nCount ++;
348 : 0 : return nPos - nCount;
349 : : }
350 : :
351 : :
352 : :
353 : :
354 : 0 : sal_uInt16 SwTableFUNC::GetColCount() const
355 : : {
356 : 0 : sal_uInt16 nCount = 0;
357 [ # # ]: 0 : for(sal_uInt16 i = 0; i < aCols.Count(); i++ )
358 [ # # ]: 0 : if(aCols.IsHidden(i))
359 : 0 : nCount ++;
360 : 0 : return aCols.Count() - nCount;
361 : : }
362 : :
363 : :
364 : :
365 : 0 : int SwTableFUNC::GetRightSeparator(int nNum) const
366 : : {
367 : : OSL_ENSURE( nNum < (int)GetColCount() ,"Index out of range");
368 : 0 : int i = 0;
369 [ # # ]: 0 : while( nNum >= 0 )
370 : : {
371 [ # # ]: 0 : if( !aCols.IsHidden( static_cast< sal_uInt16 >(i)) )
372 : 0 : nNum--;
373 : 0 : i++;
374 : : }
375 : 0 : return i - 1;
376 : : }
377 : :
378 : :
379 : :
380 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|