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 : : #include "scitems.hxx"
30 : : #include <svl/smplhint.hxx>
31 : : #include <svl/zforlist.hxx>
32 : : #include <svx/numfmtsh.hxx>
33 : : #include <svx/numinf.hxx>
34 : : #include <svx/svxids.hrc>
35 : : #include <sfx2/dispatch.hxx>
36 : : #include <sfx2/objsh.hxx>
37 : :
38 : : #include "tabvwsh.hxx"
39 : : #include "sc.hrc"
40 : : #include "global.hxx"
41 : : #include "docsh.hxx"
42 : : #include "document.hxx"
43 : : #include "cell.hxx"
44 : : #include "globstr.hrc"
45 : : #include "scmod.hxx"
46 : : #include "uiitems.hxx"
47 : : #include "editsh.hxx"
48 : : #include "hints.hxx"
49 : :
50 : :
51 : : //==================================================================
52 : :
53 : 24895 : void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
54 : : {
55 [ + + ]: 24895 : if (rHint.ISA(SfxSimpleHint)) // ohne Parameter
56 : : {
57 : 15894 : sal_uLong nSlot = ((SfxSimpleHint&)rHint).GetId();
58 [ + - + + : 15894 : switch ( nSlot )
+ + + - -
+ ]
59 : : {
60 : : case FID_DATACHANGED:
61 : 3825 : UpdateFormulas();
62 : 3825 : break;
63 : :
64 : : case FID_REFMODECHANGED:
65 : : {
66 : 0 : sal_Bool bRefMode = SC_MOD()->IsFormulaMode();
67 [ # # ]: 0 : if (!bRefMode)
68 : 0 : StopRefMode();
69 : : else
70 : : {
71 : 0 : GetSelEngine()->Reset();
72 : 0 : GetFunctionSet()->SetAnchorFlag(sal_True);
73 : : // AnchorFlag, damit gleich mit Control angehaengt werden kann
74 : : }
75 : : }
76 : 0 : break;
77 : :
78 : : case FID_KILLEDITVIEW:
79 : : case FID_KILLEDITVIEW_NOPAINT:
80 : 1315 : StopEditShell();
81 : 1315 : KillEditView( nSlot == FID_KILLEDITVIEW_NOPAINT );
82 : 1315 : break;
83 : :
84 : : case SFX_HINT_DOCCHANGED:
85 : : {
86 : 4078 : ScDocument* pDoc = GetViewData()->GetDocument();
87 [ - + ]: 4078 : if (!pDoc->HasTable( GetViewData()->GetTabNo() ))
88 : : {
89 : 0 : SetTabNo(0);
90 : : }
91 : : }
92 : 4078 : break;
93 : :
94 : : case SC_HINT_DRWLAYER_NEW:
95 : 210 : MakeDrawView();
96 : 210 : break;
97 : :
98 : : case SC_HINT_DOC_SAVED:
99 : : {
100 : : // beim "Save as" kann ein vorher schreibgeschuetztes Dokument
101 : : // bearbeitbar werden, deshalb die Layer-Locks neu (#39884#)
102 : : // (Invalidate etc. passiert schon vom Sfx her)
103 : : // bei SID_EDITDOC kommt kein SFX_HINT_TITLECHANGED, darum
104 : : // der eigene Hint aus DoSaveCompleted
105 : : //! was ist mit SFX_HINT_SAVECOMPLETED ?
106 : :
107 : 4 : UpdateLayerLocks();
108 : :
109 : : // Design-Modus bei jedem Speichern anzupassen, waere zuviel
110 : : // (beim Speichern unter gleichem Namen soll er unveraendert bleiben)
111 : : // Darum nur bei SFX_HINT_MODECHANGED (vom ViewFrame)
112 : : }
113 : 4 : break;
114 : :
115 : : case SFX_HINT_MODECHANGED:
116 : : // Da man sich nicht mehr darauf verlassen kann, woher
117 : : // dieser Hint kommt, den Design-Modus immer dann umschalten, wenn der
118 : : // ReadOnly-Status sich wirklich geaendert hat:
119 : :
120 [ - + ]: 4 : if ( GetViewData()->GetSfxDocShell()->IsReadOnly() != bReadOnly )
121 : : {
122 [ # # ][ # # ]: 0 : bReadOnly = GetViewData()->GetSfxDocShell()->IsReadOnly();
123 : :
124 [ # # ]: 0 : SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadOnly);
125 [ # # ]: 0 : GetViewData()->GetDispatcher().Execute( SID_FM_DESIGN_MODE, SFX_CALLMODE_ASYNCHRON,
126 [ # # ]: 0 : &aItem, 0L );
127 : :
128 [ # # ][ # # ]: 0 : UpdateInputContext();
129 : : }
130 : 4 : break;
131 : :
132 : : case SC_HINT_SHOWRANGEFINDER:
133 : 0 : PaintRangeFinder();
134 : 0 : break;
135 : :
136 : : case SC_HINT_FORCESETTAB:
137 : 0 : SetTabNo( GetViewData()->GetTabNo(), sal_True );
138 : 0 : break;
139 : :
140 : : default:
141 : 15894 : break;
142 : : }
143 : : }
144 [ + + ]: 9001 : else if (rHint.ISA(ScPaintHint)) // neu zeichnen
145 : : {
146 : 4144 : ScPaintHint* pHint = (ScPaintHint*) &rHint;
147 : 4144 : sal_uInt16 nParts = pHint->GetParts();
148 : 4144 : SCTAB nTab = GetViewData()->GetTabNo();
149 [ + + ][ + + ]: 4144 : if (pHint->GetStartTab() <= nTab && pHint->GetEndTab() >= nTab)
[ + + ]
150 : : {
151 [ + + ]: 3672 : if (nParts & PAINT_EXTRAS) // zuerst, falls Tabelle weg ist !!!
152 [ - + ]: 83 : if (PaintExtras())
153 : 0 : nParts = PAINT_ALL;
154 : :
155 : : // if the current sheet has pending row height updates (sheet links refreshed),
156 : : // execute them before invalidating the window
157 : 3672 : GetViewData()->GetDocShell()->UpdatePendingRowHeights( GetViewData()->GetTabNo() );
158 : :
159 [ + + ]: 3672 : if (nParts & PAINT_SIZE)
160 : 20 : RepeatResize(); //! InvalidateBorder ???
161 [ + + ]: 3672 : if (nParts & PAINT_GRID)
162 : 3597 : PaintArea( pHint->GetStartCol(), pHint->GetStartRow(),
163 : 7194 : pHint->GetEndCol(), pHint->GetEndRow() );
164 [ - + ]: 3672 : if (nParts & PAINT_MARKS)
165 : 0 : PaintArea( pHint->GetStartCol(), pHint->GetStartRow(),
166 : 0 : pHint->GetEndCol(), pHint->GetEndRow(), SC_UPDATE_MARKS );
167 [ + + ]: 3672 : if (nParts & PAINT_LEFT)
168 : 145 : PaintLeftArea( pHint->GetStartRow(), pHint->GetEndRow() );
169 [ + + ]: 3672 : if (nParts & PAINT_TOP)
170 : 28 : PaintTopArea( pHint->GetStartCol(), pHint->GetEndCol() );
171 : :
172 : : // #i84689# call UpdateAllOverlays here instead of in ScTabView::PaintArea
173 [ + + ]: 3672 : if (nParts & ( PAINT_LEFT | PAINT_TOP )) // only if widths or heights changed
174 : 151 : UpdateAllOverlays();
175 : :
176 : 3672 : HideNoteMarker();
177 : : }
178 : : }
179 [ - + ]: 4857 : else if (rHint.ISA(ScEditViewHint)) // Edit-View anlegen
180 : : {
181 : : // ScEditViewHint kommt nur an aktiver View an
182 : :
183 : 0 : ScEditViewHint* pHint = (ScEditViewHint*) &rHint;
184 : 0 : SCTAB nTab = GetViewData()->GetTabNo();
185 [ # # ]: 0 : if ( pHint->GetTab() == nTab )
186 : : {
187 : 0 : SCCOL nCol = pHint->GetCol();
188 : 0 : SCROW nRow = pHint->GetRow();
189 : : {
190 : 0 : HideNoteMarker();
191 : :
192 : 0 : MakeEditView( pHint->GetEngine(), nCol, nRow );
193 : :
194 : 0 : StopEditShell(); // sollte nicht gesetzt sein
195 : :
196 : 0 : ScSplitPos eActive = GetViewData()->GetActivePart();
197 [ # # ]: 0 : if ( GetViewData()->HasEditView(eActive) )
198 : : {
199 : : // MakeEditView geht schief, wenn der Cursor ausserhalb des
200 : : // Bildschirms steht. GetEditView gibt dann eine nicht aktive
201 : : // View zurueck, darum die Abfrage HasEditView.
202 : :
203 : 0 : EditView* pView = GetViewData()->GetEditView(eActive); // ist nicht 0
204 : :
205 : 0 : SetEditShell(pView ,sal_True);
206 : : }
207 : : }
208 : : }
209 : : }
210 [ + + ]: 4857 : else if (rHint.ISA(ScTablesHint)) // Tabelle eingefuegt / geloescht
211 : : {
212 : : // aktuelle Tabelle zuerst holen (kann bei DeleteTab an ViewData geaendert werden)
213 : 64 : SCTAB nActiveTab = GetViewData()->GetTabNo();
214 : :
215 : 64 : const ScTablesHint& rTabHint = (const ScTablesHint&)rHint;
216 : 64 : SCTAB nTab1 = rTabHint.GetTab1();
217 : 64 : SCTAB nTab2 = rTabHint.GetTab2();
218 : 64 : sal_uInt16 nId = rTabHint.GetId();
219 [ + + - - : 64 : switch (nId)
+ - - - ]
220 : : {
221 : : case SC_TAB_INSERTED:
222 : 43 : GetViewData()->InsertTab( nTab1 );
223 : 43 : break;
224 : : case SC_TAB_DELETED:
225 : 19 : GetViewData()->DeleteTab( nTab1 );
226 : 19 : break;
227 : : case SC_TAB_MOVED:
228 : 0 : GetViewData()->MoveTab( nTab1, nTab2 );
229 : 0 : break;
230 : : case SC_TAB_COPIED:
231 : 0 : GetViewData()->CopyTab( nTab1, nTab2 );
232 : 0 : break;
233 : : case SC_TAB_HIDDEN:
234 : 2 : break;
235 : : case SC_TABS_INSERTED:
236 : 0 : GetViewData()->InsertTabs( nTab1, nTab2 );
237 : 0 : break;
238 : : case SC_TABS_DELETED:
239 : 0 : GetViewData()->DeleteTabs( nTab1, nTab2 );
240 : 0 : break;
241 : : default:
242 : : OSL_FAIL("unbekannter ScTablesHint");
243 : : }
244 : :
245 : : // hier keine Abfrage auf IsActive() mehr, weil die Aktion von Basic ausgehen
246 : : // kann und dann auch die aktive View umgeschaltet werden muss.
247 : :
248 : 64 : SCTAB nNewTab = nActiveTab;
249 : 64 : bool bStayOnActiveTab = true;
250 [ + + - - : 64 : switch (nId)
+ - - - ]
251 : : {
252 : : case SC_TAB_INSERTED:
253 [ + + ]: 43 : if ( nTab1 <= nNewTab ) // vorher eingefuegt
254 : 33 : ++nNewTab;
255 : 43 : break;
256 : : case SC_TAB_DELETED:
257 [ + + ]: 19 : if ( nTab1 < nNewTab ) // vorher geloescht
258 : 1 : --nNewTab;
259 [ + - ]: 18 : else if ( nTab1 == nNewTab ) // aktuelle geloescht
260 : 18 : bStayOnActiveTab = false;
261 : 19 : break;
262 : : case SC_TAB_MOVED:
263 [ # # ]: 0 : if ( nNewTab == nTab1 ) // verschobene Tabelle
264 : 0 : nNewTab = nTab2;
265 [ # # ]: 0 : else if ( nTab1 < nTab2 ) // nach hinten verschoben
266 : : {
267 [ # # ][ # # ]: 0 : if ( nNewTab > nTab1 && nNewTab <= nTab2 ) // nachrueckender Bereich
268 : 0 : --nNewTab;
269 : : }
270 : : else // nach vorne verschoben
271 : : {
272 [ # # ][ # # ]: 0 : if ( nNewTab >= nTab2 && nNewTab < nTab1 ) // nachrueckender Bereich
273 : 0 : ++nNewTab;
274 : : }
275 : 0 : break;
276 : : case SC_TAB_COPIED:
277 [ # # ]: 0 : if ( nNewTab >= nTab2 ) // vorher eingefuegt
278 : 0 : ++nNewTab;
279 : 0 : break;
280 : : case SC_TAB_HIDDEN:
281 [ + - ]: 2 : if ( nTab1 == nNewTab ) // aktuelle ausgeblendet
282 : 2 : bStayOnActiveTab = false;
283 : 2 : break;
284 : : case SC_TABS_INSERTED:
285 [ # # ]: 0 : if ( nTab1 <= nNewTab )
286 : 0 : nNewTab += nTab2;
287 : 0 : break;
288 : : case SC_TABS_DELETED:
289 [ # # ]: 0 : if ( nTab1 < nNewTab )
290 : 0 : nNewTab -= nTab2;
291 : 0 : break;
292 : : }
293 : :
294 : 64 : ScDocument* pDoc = GetViewData()->GetDocument();
295 [ - + ]: 64 : if ( nNewTab >= pDoc->GetTableCount() )
296 : 0 : nNewTab = pDoc->GetTableCount() - 1;
297 : :
298 : 64 : sal_Bool bForce = !bStayOnActiveTab;
299 : 64 : SetTabNo( nNewTab, bForce, false, bStayOnActiveTab );
300 : : }
301 [ - + ]: 4793 : else if (rHint.ISA(ScIndexHint))
302 : : {
303 : 0 : const ScIndexHint& rIndexHint = (const ScIndexHint&)rHint;
304 : 0 : sal_uInt16 nId = rIndexHint.GetId();
305 : 0 : sal_uInt16 nIndex = rIndexHint.GetIndex();
306 [ # # ]: 0 : switch (nId)
307 : : {
308 : : case SC_HINT_SHOWRANGEFINDER:
309 : 0 : PaintRangeFinder( nIndex );
310 : 0 : break;
311 : : }
312 : : }
313 : :
314 : 24895 : SfxViewShell::Notify( rBC, rHint );
315 : 24895 : }
316 : :
317 : : //------------------------------------------------------------------
318 : :
319 : 0 : void ScTabViewShell::MakeNumberInfoItem( ScDocument* pDoc,
320 : : ScViewData* pViewData,
321 : : SvxNumberInfoItem** ppItem )
322 : : {
323 : : //------------------------------
324 : : // NumberInfo-Item konstruieren:
325 : : //------------------------------
326 : 0 : ScBaseCell* pCell = NULL;
327 : 0 : SvxNumberValueType eValType = SVX_VALUE_TYPE_UNDEFINED;
328 : 0 : double nCellValue = 0;
329 [ # # ]: 0 : String aCellString;
330 : :
331 : 0 : pDoc->GetCell( pViewData->GetCurX(),
332 : : pViewData->GetCurY(),
333 : 0 : pViewData->GetTabNo(),
334 [ # # ]: 0 : pCell );
335 : :
336 [ # # ]: 0 : if ( pCell )
337 : : {
338 [ # # # # ]: 0 : switch ( pCell->GetCellType() )
339 : : {
340 : : case CELLTYPE_VALUE:
341 : : {
342 : 0 : nCellValue = ((ScValueCell*)pCell)->GetValue();
343 : 0 : eValType = SVX_VALUE_TYPE_NUMBER;
344 [ # # ]: 0 : aCellString.Erase();
345 : : }
346 : 0 : break;
347 : :
348 : : case CELLTYPE_STRING:
349 : : {
350 [ # # ]: 0 : aCellString = ((ScStringCell*)pCell)->GetString();
351 : 0 : eValType = SVX_VALUE_TYPE_STRING;
352 : : }
353 : 0 : break;
354 : :
355 : : case CELLTYPE_FORMULA:
356 : : {
357 [ # # ][ # # ]: 0 : if ( ((ScFormulaCell*)pCell)->IsValue() )
[ # # ]
358 : : {
359 [ # # ][ # # ]: 0 : nCellValue = ((ScFormulaCell*)pCell)->GetValue();
360 : 0 : eValType = SVX_VALUE_TYPE_NUMBER;
361 : : }
362 : : else
363 : : {
364 : 0 : nCellValue = 0;
365 : 0 : eValType = SVX_VALUE_TYPE_UNDEFINED;
366 : : }
367 [ # # ]: 0 : aCellString.Erase();
368 : : }
369 : 0 : break;
370 : :
371 : : default:
372 : 0 : nCellValue = 0;
373 : 0 : eValType = SVX_VALUE_TYPE_UNDEFINED;
374 [ # # ]: 0 : aCellString.Erase();
375 : : }
376 : : }
377 : : else // Zelle noch leer (== nicht erzeugt)
378 : : {
379 : 0 : nCellValue = 0;
380 : 0 : eValType = SVX_VALUE_TYPE_UNDEFINED;
381 [ # # ]: 0 : aCellString.Erase();
382 : : }
383 : :
384 [ # # # ]: 0 : switch ( eValType )
385 : : {
386 : : case SVX_VALUE_TYPE_STRING:
387 : : *ppItem = new SvxNumberInfoItem(
388 : : pDoc->GetFormatTable(),
389 : : aCellString,
390 [ # # ][ # # ]: 0 : SID_ATTR_NUMBERFORMAT_INFO );
[ # # ]
391 : 0 : break;
392 : :
393 : : case SVX_VALUE_TYPE_NUMBER:
394 : : *ppItem = new SvxNumberInfoItem(
395 : : pDoc->GetFormatTable(),
396 : : nCellValue,
397 [ # # ][ # # ]: 0 : SID_ATTR_NUMBERFORMAT_INFO );
[ # # ]
398 : 0 : break;
399 : :
400 : : case SVX_VALUE_TYPE_UNDEFINED:
401 : : default:
402 : : *ppItem = new SvxNumberInfoItem(
403 : : pDoc->GetFormatTable(),
404 : : (const sal_uInt16)
405 [ # # ][ # # ]: 0 : SID_ATTR_NUMBERFORMAT_INFO );
[ # # ]
406 [ # # ]: 0 : }
407 : 0 : }
408 : :
409 : : //------------------------------------------------------------------
410 : :
411 : 0 : void ScTabViewShell::UpdateNumberFormatter(
412 : : const SvxNumberInfoItem& rInfoItem )
413 : : {
414 : 0 : const sal_uInt32 nDelCount = rInfoItem.GetDelCount();
415 : :
416 [ # # ]: 0 : if ( nDelCount > 0 )
417 : : {
418 : 0 : const sal_uInt32* pDelArr = rInfoItem.GetDelArray();
419 : :
420 [ # # ]: 0 : for ( sal_uInt16 i=0; i<nDelCount; i++ )
421 : 0 : rInfoItem.GetNumberFormatter()->DeleteEntry( pDelArr[i] );
422 : : }
423 : 0 : }
424 : :
425 : :
426 : :
427 : :
428 : :
429 : :
430 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|