update dev300-m58
[ooovba.git] / sc / source / ui / view / viewfun6.cxx
blobe686cfccd596c9a240bd343b0227cb1ac3fab6bd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewfun6.cxx,v $
10 * $Revision: 1.11.128.4 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <svx/svdundo.hxx>
35 #include <svx/svdocapt.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <vcl/sound.hxx>
41 #include "viewfunc.hxx"
42 #include "detfunc.hxx"
43 #include "detdata.hxx"
44 #include "viewdata.hxx"
45 #include "drwlayer.hxx"
46 #include "docsh.hxx"
47 #include "undocell.hxx"
48 #include "futext.hxx"
49 #include "docfunc.hxx"
50 #include "globstr.hrc"
51 #include "sc.hrc"
52 #include "fusel.hxx"
53 #include "reftokenhelper.hxx"
54 #include "externalrefmgr.hxx"
56 #include <vector>
58 using ::rtl::OUStringBuffer;
59 using ::std::vector;
61 //==================================================================
63 void ScViewFunc::DetectiveAddPred()
65 ScDocShell* pDocSh = GetViewData()->GetDocShell();
66 BOOL bDone = pDocSh->GetDocFunc().
67 DetectiveAddPred( GetViewData()->GetCurPos() );
68 if (!bDone)
69 Sound::Beep();
71 RecalcPPT(); //! use broadcast in DocFunc instead?
74 void ScViewFunc::DetectiveDelPred()
76 ScDocShell* pDocSh = GetViewData()->GetDocShell();
77 BOOL bDone = pDocSh->GetDocFunc().
78 DetectiveDelPred( GetViewData()->GetCurPos() );
79 if (!bDone)
80 Sound::Beep();
82 RecalcPPT();
85 void ScViewFunc::DetectiveAddSucc()
87 ScDocShell* pDocSh = GetViewData()->GetDocShell();
88 BOOL bDone = pDocSh->GetDocFunc().
89 DetectiveAddSucc( GetViewData()->GetCurPos() );
90 if (!bDone)
91 Sound::Beep();
93 RecalcPPT();
96 void ScViewFunc::DetectiveDelSucc()
98 ScDocShell* pDocSh = GetViewData()->GetDocShell();
99 BOOL bDone = pDocSh->GetDocFunc().
100 DetectiveDelSucc( GetViewData()->GetCurPos() );
101 if (!bDone)
102 Sound::Beep();
104 RecalcPPT();
107 void ScViewFunc::DetectiveAddError()
109 ScDocShell* pDocSh = GetViewData()->GetDocShell();
110 BOOL bDone = pDocSh->GetDocFunc().
111 DetectiveAddError( GetViewData()->GetCurPos() );
112 if (!bDone)
113 Sound::Beep();
115 RecalcPPT();
118 void ScViewFunc::DetectiveDelAll()
120 ScDocShell* pDocSh = GetViewData()->GetDocShell();
121 BOOL bDone = pDocSh->GetDocFunc().
122 DetectiveDelAll( GetViewData()->GetTabNo() );
123 if (!bDone)
124 Sound::Beep();
126 RecalcPPT();
129 void ScViewFunc::DetectiveMarkInvalid()
131 ScDocShell* pDocSh = GetViewData()->GetDocShell();
132 BOOL bDone = pDocSh->GetDocFunc().
133 DetectiveMarkInvalid( GetViewData()->GetTabNo() );
134 if (!bDone)
135 Sound::Beep();
137 RecalcPPT();
140 void ScViewFunc::DetectiveRefresh()
142 ScDocShell* pDocSh = GetViewData()->GetDocShell();
143 BOOL bDone = pDocSh->GetDocFunc().DetectiveRefresh();
144 if (!bDone)
145 Sound::Beep();
147 RecalcPPT();
150 static void lcl_jumpToRange(const ScRange& rRange, ScViewData* pView, ScDocument* pDoc)
152 String aAddrText;
153 rRange.Format(aAddrText, SCR_ABS_3D, pDoc);
154 SfxStringItem aPosItem(SID_CURRENTCELL, aAddrText);
155 SfxBoolItem aUnmarkItem(FN_PARAM_1, TRUE); // remove existing selection
156 pView->GetDispatcher().Execute(
157 SID_CURRENTCELL, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD,
158 &aPosItem, &aUnmarkItem, 0L);
161 void ScViewFunc::MarkAndJumpToRanges(const ScRangeList& rRanges)
163 ScViewData* pView = GetViewData();
164 ScDocShell* pDocSh = pView->GetDocShell();
166 ScRangeList aRanges(rRanges);
167 ScRange* p = aRanges.First();
168 ScRangeList aRangesToMark;
169 ScAddress aCurPos = pView->GetCurPos();
170 for (; p; p = aRanges.Next())
172 // Collect only those ranges that are on the same sheet as the current
173 // cursor.
175 if (p->aStart.Tab() == aCurPos.Tab())
176 aRangesToMark.Append(*p);
179 if (!aRangesToMark.Count())
180 return;
182 // Jump to the first range of all precedent ranges.
183 p = aRangesToMark.First();
184 lcl_jumpToRange(*p, pView, pDocSh->GetDocument());
186 for (; p; p = aRangesToMark.Next())
187 MarkRange(*p, false, true);
190 void ScViewFunc::DetectiveMarkPred()
192 ScViewData* pView = GetViewData();
193 ScDocShell* pDocSh = pView->GetDocShell();
194 ScDocument* pDoc = pDocSh->GetDocument();
195 ScMarkData& rMarkData = pView->GetMarkData();
196 ScAddress aCurPos = pView->GetCurPos();
197 ScRangeList aRanges;
198 if (rMarkData.IsMarked() || rMarkData.IsMultiMarked())
199 rMarkData.FillRangeListWithMarks(&aRanges, false);
200 else
201 aRanges.Append(aCurPos);
203 vector<ScSharedTokenRef> aRefTokens;
204 pDocSh->GetDocFunc().DetectiveCollectAllPreds(aRanges, aRefTokens);
206 if (aRefTokens.empty())
207 // No precedents found. Nothing to do.
208 return;
210 ScSharedTokenRef p = aRefTokens.front();
211 if (ScRefTokenHelper::isExternalRef(p))
213 // This is external. Open the external document if available, and
214 // jump to the destination.
216 sal_uInt16 nFileId = p->GetIndex();
217 ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
218 const String* pPath = pRefMgr->getExternalFileName(nFileId);
220 ScRange aRange;
221 if (pPath && ScRefTokenHelper::getRangeFromToken(aRange, p, true))
223 const String& rTabName = p->GetString();
224 OUStringBuffer aBuf;
225 aBuf.append(*pPath);
226 aBuf.append(sal_Unicode('#'));
227 aBuf.append(rTabName);
228 aBuf.append(sal_Unicode('.'));
230 String aRangeStr;
231 aRange.Format(aRangeStr, SCA_VALID);
232 aBuf.append(aRangeStr);
234 ScGlobal::OpenURL(aBuf.makeStringAndClear(), String());
236 return;
238 else
240 ScRange aRange;
241 ScRefTokenHelper::getRangeFromToken(aRange, p, false);
242 if (aRange.aStart.Tab() != aCurPos.Tab())
244 // The first precedent range is on a different sheet. Jump to it
245 // immediately and forget the rest.
246 lcl_jumpToRange(aRange, pView, pDoc);
247 return;
251 ScRangeList aDestRanges;
252 ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens);
253 MarkAndJumpToRanges(aDestRanges);
256 void ScViewFunc::DetectiveMarkSucc()
258 ScViewData* pView = GetViewData();
259 ScDocShell* pDocSh = pView->GetDocShell();
260 ScMarkData& rMarkData = pView->GetMarkData();
261 ScAddress aCurPos = pView->GetCurPos();
262 ScRangeList aRanges;
263 if (rMarkData.IsMarked() || rMarkData.IsMultiMarked())
264 rMarkData.FillRangeListWithMarks(&aRanges, false);
265 else
266 aRanges.Append(aCurPos);
268 vector<ScSharedTokenRef> aRefTokens;
269 pDocSh->GetDocFunc().DetectiveCollectAllSuccs(aRanges, aRefTokens);
271 if (aRefTokens.empty())
272 // No dependants found. Nothing to do.
273 return;
275 ScRangeList aDestRanges;
276 ScRefTokenHelper::getRangeListFromTokens(aDestRanges, aRefTokens);
277 MarkAndJumpToRanges(aDestRanges);
280 //---------------------------------------------------------------------------
282 void ScViewFunc::ShowNote( bool bShow )
284 if( bShow )
285 HideNoteMarker();
286 const ScViewData& rViewData = *GetViewData();
287 ScAddress aPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
288 // show note moved to ScDocFunc, to be able to use it in notesuno.cxx
289 rViewData.GetDocShell()->GetDocFunc().ShowNote( aPos, bShow );
292 void ScViewFunc::EditNote()
294 // zum Editieren einblenden und aktivieren
296 ScDocShell* pDocSh = GetViewData()->GetDocShell();
297 ScDocument* pDoc = pDocSh->GetDocument();
298 SCCOL nCol = GetViewData()->GetCurX();
299 SCROW nRow = GetViewData()->GetCurY();
300 SCTAB nTab = GetViewData()->GetTabNo();
301 ScAddress aPos( nCol, nRow, nTab );
303 // start drawing undo to catch undo action for insertion of the caption object
304 pDocSh->MakeDrawLayer();
305 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
306 pDrawLayer->BeginCalcUndo();
307 // generated undo action is processed in FuText::StopEditMode
309 // get existing note or create a new note (including caption drawing object)
310 if( ScPostIt* pNote = pDoc->GetOrCreateNote( aPos ) )
312 // hide temporary note caption
313 HideNoteMarker();
314 // show caption object without changing internal visibility state
315 pNote->ShowCaptionTemp( aPos );
317 /* Drawing object has been created in ScDocument::GetOrCreateNote() or
318 in ScPostIt::ShowCaptionTemp(), so ScPostIt::GetCaption() should
319 return a caption object. */
320 if( SdrCaptionObj* pCaption = pNote->GetCaption() )
322 // #i33764# enable the resize handles before starting edit mode
323 if( FuPoor* pDraw = GetDrawFuncPtr() )
324 static_cast< FuSelection* >( pDraw )->ActivateNoteHandles( pCaption );
326 // activate object (as in FuSelection::TestComment)
327 GetViewData()->GetDispatcher().Execute( SID_DRAW_NOTEEDIT, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
328 // jetzt den erzeugten FuText holen und in den EditModus setzen
329 FuPoor* pPoor = GetDrawFuncPtr();
330 if ( pPoor && (pPoor->GetSlotID() == SID_DRAW_NOTEEDIT) ) // hat keine RTTI
332 ScrollToObject( pCaption ); // Objekt komplett sichtbar machen
333 static_cast< FuText* >( pPoor )->SetInEditMode( pCaption );