Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svx/svditer.hxx>
21 : #include <svx/svdobj.hxx>
22 : #include <svx/svdpage.hxx>
23 : #include <svx/svdpagv.hxx>
24 : #include <svx/svdview.hxx>
25 : #include <svx/svdxcgv.hxx>
26 : #include <sfx2/linkmgr.hxx>
27 : #include <sfx2/docfile.hxx>
28 : #include <sfx2/viewfrm.hxx>
29 : #include <vcl/help.hxx>
30 : #include <vcl/svapp.hxx>
31 : #include <tools/urlobj.hxx>
32 : #include <svl/urlbmk.hxx>
33 : #include "svtools/svlbitm.hxx"
34 : #include <stdlib.h>
35 :
36 : #include "content.hxx"
37 : #include "navipi.hxx"
38 : #include "global.hxx"
39 : #include "docsh.hxx"
40 : #include "scmod.hxx"
41 : #include "rangenam.hxx"
42 : #include "dbdata.hxx"
43 : #include "tablink.hxx" // fuer Loader
44 : #include "popmenu.hxx"
45 : #include "drwlayer.hxx"
46 : #include "transobj.hxx"
47 : #include "drwtrans.hxx"
48 : #include "lnktrans.hxx"
49 : #include "formulacell.hxx"
50 : #include "dociter.hxx"
51 : #include "scresid.hxx"
52 : #include "globstr.hrc"
53 : #include "navipi.hrc"
54 : #include "arealink.hxx"
55 : #include "navicfg.hxx"
56 : #include "navsett.hxx"
57 : #include "postit.hxx"
58 : #include "clipparam.hxx"
59 : #include "markdata.hxx"
60 :
61 : using namespace com::sun::star;
62 :
63 : // Reihenfolge der Kategorien im Navigator -------------------------------------
64 :
65 : static sal_uInt16 pTypeList[SC_CONTENT_COUNT] =
66 : {
67 : SC_CONTENT_ROOT, // ROOT (0) muss vorne stehen
68 : SC_CONTENT_TABLE,
69 : SC_CONTENT_RANGENAME,
70 : SC_CONTENT_DBAREA,
71 : SC_CONTENT_AREALINK,
72 : SC_CONTENT_GRAPHIC,
73 : SC_CONTENT_OLEOBJECT,
74 : SC_CONTENT_NOTE,
75 : SC_CONTENT_DRAWING
76 : };
77 :
78 : sal_Bool ScContentTree::bIsInDrag = false;
79 :
80 :
81 0 : ScDocShell* ScContentTree::GetManualOrCurrent()
82 : {
83 0 : ScDocShell* pSh = NULL;
84 0 : if ( aManualDoc.Len() )
85 : {
86 0 : TypeId aScType = TYPE(ScDocShell);
87 0 : SfxObjectShell* pObjSh = SfxObjectShell::GetFirst( &aScType );
88 0 : while ( pObjSh && !pSh )
89 : {
90 0 : if ( pObjSh->GetTitle() == aManualDoc )
91 0 : pSh = PTR_CAST( ScDocShell, pObjSh );
92 0 : pObjSh = SfxObjectShell::GetNext( *pObjSh, &aScType );
93 : }
94 : }
95 : else
96 : {
97 : // Current nur, wenn keine manuell eingestellt ist
98 : // (damit erkannt wird, wenn das Dokument nicht mehr existiert)
99 :
100 0 : SfxViewShell* pViewSh = SfxViewShell::Current();
101 0 : if ( pViewSh )
102 : {
103 0 : SfxObjectShell* pObjSh = pViewSh->GetViewFrame()->GetObjectShell();
104 0 : pSh = PTR_CAST( ScDocShell, pObjSh );
105 : }
106 : }
107 :
108 0 : return pSh;
109 : }
110 :
111 : //
112 : // ScContentTree
113 : //
114 :
115 0 : ScContentTree::ScContentTree( Window* pParent, const ResId& rResId ) :
116 : SvTreeListBox ( pParent, rResId ),
117 : aEntryImages ( ScResId( RID_IMAGELIST_NAVCONT ) ),
118 : nRootType ( SC_CONTENT_ROOT ),
119 : bHiddenDoc ( false ),
120 0 : pHiddenDocument ( NULL )
121 : {
122 : sal_uInt16 i;
123 0 : for (i=0; i<SC_CONTENT_COUNT; i++)
124 0 : pPosList[pTypeList[i]] = i; // invers zum suchen
125 :
126 0 : pParentWindow = (ScNavigatorDlg*)pParent;
127 :
128 0 : pRootNodes[0] = NULL;
129 0 : for (i=1; i<SC_CONTENT_COUNT; i++)
130 0 : InitRoot(i);
131 :
132 0 : SetNodeDefaultImages();
133 :
134 0 : SetDoubleClickHdl( LINK( this, ScContentTree, ContentDoubleClickHdl ) );
135 :
136 0 : SetStyle( GetStyle() | WB_QUICK_SEARCH );
137 0 : }
138 :
139 0 : ScContentTree::~ScContentTree()
140 : {
141 0 : }
142 :
143 0 : void ScContentTree::InitRoot( sal_uInt16 nType )
144 : {
145 0 : if ( !nType )
146 0 : return;
147 :
148 0 : if ( nRootType && nRootType != nType ) // ausgeblendet ?
149 : {
150 0 : pRootNodes[nType] = NULL;
151 0 : return;
152 : }
153 :
154 0 : const Image& rImage = aEntryImages.GetImage( nType );
155 0 : String aName( ScResId( SCSTR_CONTENT_ROOT + nType ) );
156 : // wieder an die richtige Position:
157 0 : sal_uInt16 nPos = nRootType ? 0 : pPosList[nType]-1;
158 0 : SvTreeListEntry* pNew = InsertEntry( aName, rImage, rImage, NULL, false, nPos );
159 :
160 0 : pRootNodes[nType] = pNew;
161 : }
162 :
163 0 : void ScContentTree::ClearAll()
164 : {
165 0 : Clear();
166 0 : for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++)
167 0 : InitRoot(i);
168 0 : }
169 :
170 0 : void ScContentTree::ClearType(sal_uInt16 nType)
171 : {
172 0 : if (!nType)
173 0 : ClearAll();
174 : else
175 : {
176 0 : SvTreeListEntry* pParent = pRootNodes[nType];
177 0 : if ( !pParent || GetChildCount(pParent) ) // nicht, wenn ohne Children schon da
178 : {
179 0 : if (pParent)
180 0 : GetModel()->Remove( pParent ); // mit allen Children
181 0 : InitRoot( nType ); // ggf. neu eintragen
182 : }
183 : }
184 0 : }
185 :
186 0 : void ScContentTree::InsertContent( sal_uInt16 nType, const String& rValue )
187 : {
188 0 : if (nType >= SC_CONTENT_COUNT)
189 : {
190 : OSL_FAIL("ScContentTree::InsertContent mit falschem Typ");
191 0 : return;
192 : }
193 :
194 0 : SvTreeListEntry* pParent = pRootNodes[nType];
195 0 : if (pParent)
196 0 : InsertEntry( rValue, pParent );
197 : else
198 : {
199 : OSL_FAIL("InsertContent ohne Parent");
200 : }
201 : }
202 :
203 0 : void ScContentTree::GetEntryIndexes( sal_uInt16& rnRootIndex, sal_uLong& rnChildIndex, SvTreeListEntry* pEntry ) const
204 : {
205 0 : rnRootIndex = SC_CONTENT_ROOT;
206 0 : rnChildIndex = SC_CONTENT_NOCHILD;
207 :
208 0 : if( !pEntry )
209 0 : return;
210 :
211 0 : SvTreeListEntry* pParent = GetParent( pEntry );
212 0 : bool bFound = false;
213 0 : for( sal_uInt16 nRoot = 1; !bFound && (nRoot < SC_CONTENT_COUNT); ++nRoot )
214 : {
215 0 : if( pEntry == pRootNodes[ nRoot ] )
216 : {
217 0 : rnRootIndex = nRoot;
218 0 : rnChildIndex = ~0UL;
219 0 : bFound = true;
220 : }
221 0 : else if( pParent && (pParent == pRootNodes[ nRoot ]) )
222 : {
223 0 : rnRootIndex = nRoot;
224 :
225 : // search the entry in all child entries of the parent
226 0 : sal_uLong nEntry = 0;
227 0 : SvTreeListEntry* pIterEntry = FirstChild( pParent );
228 0 : while( !bFound && pIterEntry )
229 : {
230 0 : if ( pEntry == pIterEntry )
231 : {
232 0 : rnChildIndex = nEntry;
233 0 : bFound = true; // exit the while loop
234 : }
235 0 : pIterEntry = NextSibling( pIterEntry );
236 0 : ++nEntry;
237 : }
238 :
239 0 : bFound = true; // exit the for loop
240 : }
241 : }
242 : }
243 :
244 0 : sal_uLong ScContentTree::GetChildIndex( SvTreeListEntry* pEntry ) const
245 : {
246 : sal_uInt16 nRoot;
247 : sal_uLong nChild;
248 0 : GetEntryIndexes( nRoot, nChild, pEntry );
249 0 : return nChild;
250 : }
251 :
252 0 : static String lcl_GetDBAreaRange( ScDocument* pDoc, const String& rDBName )
253 : {
254 0 : String aRet;
255 0 : if (pDoc)
256 : {
257 0 : ScDBCollection* pDbNames = pDoc->GetDBCollection();
258 0 : const ScDBData* pData = pDbNames->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(rDBName));
259 0 : if (pData)
260 : {
261 0 : ScRange aRange;
262 0 : pData->GetArea(aRange);
263 0 : aRange.Format(aRet, SCR_ABS_3D, pDoc);
264 : }
265 : }
266 0 : return aRet;
267 : }
268 :
269 0 : IMPL_LINK_NOARG(ScContentTree, ContentDoubleClickHdl)
270 : {
271 : sal_uInt16 nType;
272 : sal_uLong nChild;
273 0 : SvTreeListEntry* pEntry = GetCurEntry();
274 0 : GetEntryIndexes( nType, nChild, pEntry );
275 :
276 0 : if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) )
277 : {
278 0 : if ( bHiddenDoc )
279 0 : return 0; //! spaeter...
280 :
281 0 : String aText( GetEntryText( pEntry ) );
282 :
283 0 : if ( aManualDoc.Len() )
284 0 : pParentWindow->SetCurrentDoc( aManualDoc );
285 :
286 0 : switch( nType )
287 : {
288 : case SC_CONTENT_TABLE:
289 0 : pParentWindow->SetCurrentTableStr( aText );
290 0 : break;
291 :
292 : case SC_CONTENT_RANGENAME:
293 0 : pParentWindow->SetCurrentCellStr( aText );
294 0 : break;
295 :
296 : case SC_CONTENT_DBAREA:
297 : {
298 : // Wenn gleiche Bereichs- und DB-Namen existieren, wird
299 : // bei SID_CURRENTCELL der Bereichsname genommen.
300 : // DB-Bereiche darum direkt ueber die Adresse anspringen.
301 :
302 0 : String aRangeStr = lcl_GetDBAreaRange( GetSourceDocument(), aText );
303 0 : if (aRangeStr.Len())
304 0 : pParentWindow->SetCurrentCellStr( aRangeStr );
305 : }
306 0 : break;
307 :
308 : case SC_CONTENT_OLEOBJECT:
309 : case SC_CONTENT_GRAPHIC:
310 : case SC_CONTENT_DRAWING:
311 0 : pParentWindow->SetCurrentObject( aText );
312 0 : break;
313 :
314 : case SC_CONTENT_NOTE:
315 : {
316 0 : ScAddress aPos = GetNotePos( nChild );
317 0 : pParentWindow->SetCurrentTable( aPos.Tab() );
318 0 : pParentWindow->SetCurrentCell( aPos.Col(), aPos.Row() );
319 : }
320 0 : break;
321 :
322 : case SC_CONTENT_AREALINK:
323 : {
324 0 : const ScAreaLink* pLink = GetLink( nChild );
325 0 : if( pLink )
326 : {
327 0 : ScRange aRange = pLink->GetDestArea();
328 0 : String aRangeStr;
329 0 : ScDocument* pSrcDoc = GetSourceDocument();
330 0 : aRange.Format( aRangeStr, SCR_ABS_3D, pSrcDoc, pSrcDoc->GetAddressConvention() );
331 0 : pParentWindow->SetCurrentCellStr( aRangeStr );
332 : }
333 : }
334 0 : break;
335 : }
336 :
337 0 : ScNavigatorDlg::ReleaseFocus(); // set focus into document
338 : }
339 :
340 0 : return 0;
341 : }
342 :
343 0 : void ScContentTree::MouseButtonDown( const MouseEvent& rMEvt )
344 : {
345 0 : SvTreeListBox::MouseButtonDown( rMEvt );
346 0 : StoreSettings();
347 0 : }
348 :
349 0 : void ScContentTree::KeyInput( const KeyEvent& rKEvt )
350 : {
351 0 : sal_Bool bUsed = false;
352 :
353 0 : const KeyCode aCode = rKEvt.GetKeyCode();
354 0 : if (aCode.GetCode() == KEY_RETURN)
355 : {
356 0 : switch (aCode.GetModifier())
357 : {
358 : case KEY_MOD1:
359 0 : ToggleRoot(); // toggle root mode (as in Writer)
360 0 : bUsed = sal_True;
361 0 : break;
362 : case 0:
363 : {
364 0 : SvTreeListEntry* pEntry = GetCurEntry();
365 0 : if( pEntry )
366 : {
367 : sal_uInt16 nType;
368 : sal_uLong nChild;
369 0 : GetEntryIndexes( nType, nChild, pEntry );
370 :
371 0 : if( (nType != SC_CONTENT_ROOT) && (nChild == SC_CONTENT_NOCHILD) )
372 : {
373 0 : if ( IsExpanded( pEntry ) )
374 0 : Collapse( pEntry );
375 : else
376 0 : Expand( pEntry );
377 : }
378 : else
379 0 : ContentDoubleClickHdl(0); // select content as if double clicked
380 : }
381 :
382 0 : bUsed = sal_True;
383 : }
384 0 : break;
385 : }
386 : }
387 0 : StoreSettings();
388 :
389 0 : if( !bUsed )
390 0 : SvTreeListBox::KeyInput(rKEvt);
391 0 : }
392 :
393 0 : sal_Int8 ScContentTree::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
394 : {
395 0 : return DND_ACTION_NONE;
396 : }
397 :
398 0 : sal_Int8 ScContentTree::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ )
399 : {
400 0 : return DND_ACTION_NONE;
401 : }
402 :
403 0 : void ScContentTree::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ )
404 : {
405 0 : DoDrag();
406 0 : }
407 :
408 0 : void ScContentTree::DragFinished( sal_Int8 /* nAction */ )
409 : {
410 0 : }
411 :
412 0 : void ScContentTree::Command( const CommandEvent& rCEvt )
413 : {
414 0 : sal_Bool bDone = false;
415 :
416 0 : switch ( rCEvt.GetCommand() )
417 : {
418 : case COMMAND_STARTDRAG:
419 : // Aus dem ExecuteDrag heraus kann der Navigator geloescht werden
420 : // (beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber
421 : // den StarView MouseMove-Handler, der Command() aufruft, umbringen.
422 : // Deshalb Drag&Drop asynchron:
423 :
424 0 : Application::PostUserEvent( STATIC_LINK( this, ScContentTree, ExecDragHdl ) );
425 :
426 0 : bDone = sal_True;
427 0 : break;
428 :
429 : case COMMAND_CONTEXTMENU:
430 : {
431 : // Drag-Drop Modus
432 :
433 0 : PopupMenu aPop;
434 0 : ScPopupMenu aDropMenu( ScResId( RID_POPUP_DROPMODE ) );
435 0 : aDropMenu.CheckItem( RID_DROPMODE_URL + pParentWindow->GetDropMode() );
436 0 : aPop.InsertItem( 1, pParentWindow->GetStrDragMode() );
437 0 : aPop.SetPopupMenu( 1, &aDropMenu );
438 :
439 : // angezeigtes Dokument
440 :
441 0 : ScPopupMenu aDocMenu;
442 0 : aDocMenu.SetMenuFlags( aDocMenu.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
443 0 : sal_uInt16 i=0;
444 0 : sal_uInt16 nPos=0;
445 : // geladene Dokumente
446 0 : ScDocShell* pCurrentSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() );
447 0 : SfxObjectShell* pSh = SfxObjectShell::GetFirst();
448 0 : while ( pSh )
449 : {
450 0 : if ( pSh->ISA(ScDocShell) )
451 : {
452 0 : String aName = pSh->GetTitle();
453 0 : String aEntry = aName;
454 0 : if ( pSh == pCurrentSh )
455 0 : aEntry += pParentWindow->aStrActive;
456 : else
457 0 : aEntry += pParentWindow->aStrNotActive;
458 0 : aDocMenu.InsertItem( ++i, aEntry );
459 0 : if ( !bHiddenDoc && aName == aManualDoc )
460 0 : nPos = i;
461 : }
462 0 : pSh = SfxObjectShell::GetNext( *pSh );
463 : }
464 : // "aktives Fenster"
465 0 : aDocMenu.InsertItem( ++i, pParentWindow->aStrActiveWin );
466 0 : if (!bHiddenDoc && !aManualDoc.Len())
467 0 : nPos = i;
468 : // verstecktes Dokument
469 0 : if ( aHiddenTitle.Len() )
470 : {
471 0 : String aEntry = aHiddenTitle;
472 0 : aEntry += pParentWindow->aStrHidden;
473 0 : aDocMenu.InsertItem( ++i, aEntry );
474 0 : if (bHiddenDoc)
475 0 : nPos = i;
476 : }
477 0 : aDocMenu.CheckItem( nPos );
478 0 : aPop.InsertItem( 2, pParentWindow->GetStrDisplay() );
479 0 : aPop.SetPopupMenu( 2, &aDocMenu );
480 :
481 : // ausfuehren
482 :
483 0 : aPop.Execute( this, rCEvt.GetMousePosPixel() );
484 :
485 0 : if ( aDropMenu.WasHit() ) // Drag-Drop Modus
486 : {
487 0 : sal_uInt16 nId = aDropMenu.GetSelected();
488 0 : if ( nId >= RID_DROPMODE_URL && nId <= RID_DROPMODE_COPY )
489 0 : pParentWindow->SetDropMode( nId - RID_DROPMODE_URL );
490 : }
491 0 : else if ( aDocMenu.WasHit() ) // angezeigtes Dokument
492 : {
493 0 : sal_uInt16 nId = aDocMenu.GetSelected();
494 0 : String aName = aDocMenu.GetItemText(nId);
495 0 : SelectDoc( aName );
496 0 : }
497 : }
498 0 : break;
499 : }
500 :
501 0 : if (!bDone)
502 0 : SvTreeListBox::Command(rCEvt);
503 0 : }
504 :
505 0 : void ScContentTree::RequestHelp( const HelpEvent& rHEvt )
506 : {
507 0 : bool bDone = false;
508 0 : if( rHEvt.GetMode() & HELPMODE_QUICK )
509 : {
510 0 : Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
511 0 : SvTreeListEntry* pEntry = GetEntry( aPos );
512 0 : if ( pEntry )
513 : {
514 0 : bool bRet = false;
515 0 : OUString aHelpText;
516 0 : SvTreeListEntry* pParent = GetParent(pEntry);
517 0 : if ( !pParent ) // Top-Level ?
518 : {
519 0 : aHelpText = OUString::number( GetChildCount(pEntry) ) +
520 0 : " " + GetEntryText(pEntry);
521 0 : bRet = true;
522 : }
523 0 : else if ( pParent == pRootNodes[SC_CONTENT_NOTE] )
524 : {
525 0 : aHelpText = GetEntryText(pEntry); // Notizen als Help-Text
526 0 : bRet = true;
527 : }
528 0 : else if ( pParent == pRootNodes[SC_CONTENT_AREALINK] )
529 : {
530 0 : sal_uLong nIndex = GetChildIndex(pEntry);
531 0 : if( nIndex != SC_CONTENT_NOCHILD )
532 : {
533 0 : const ScAreaLink* pLink = GetLink(nIndex);
534 0 : if (pLink)
535 : {
536 0 : aHelpText = pLink->GetFile(); // Source-Datei als Help-Text
537 0 : bRet = true;
538 : }
539 : }
540 : }
541 :
542 0 : if (bRet)
543 : {
544 : SvLBoxTab* pTab;
545 0 : SvLBoxString* pItem = (SvLBoxString*)(GetItem( pEntry, aPos.X(), &pTab ));
546 0 : if( pItem )
547 : {
548 0 : aPos = GetEntryPosition( pEntry );
549 0 : aPos.X() = GetTabPos( pEntry, pTab );
550 0 : aPos = OutputToScreenPixel(aPos);
551 0 : Size aSize( pItem->GetSize( this, pEntry ) );
552 :
553 0 : Rectangle aItemRect( aPos, aSize );
554 0 : Help::ShowQuickHelp( this, aItemRect, aHelpText );
555 0 : bDone = true;
556 : }
557 0 : }
558 : }
559 : }
560 0 : if (!bDone)
561 0 : Window::RequestHelp( rHEvt );
562 0 : }
563 :
564 0 : ScDocument* ScContentTree::GetSourceDocument()
565 : {
566 0 : if (bHiddenDoc)
567 0 : return pHiddenDocument;
568 : else
569 : {
570 0 : ScDocShell* pSh = GetManualOrCurrent();
571 0 : if (pSh)
572 0 : return pSh->GetDocument();
573 :
574 : }
575 0 : return NULL;
576 : }
577 :
578 0 : void ScContentTree::Refresh( sal_uInt16 nType )
579 : {
580 0 : if ( bHiddenDoc && !pHiddenDocument )
581 0 : return; // anderes Dokument angezeigt
582 :
583 : // wenn sich nichts geaendert hat, gleich abbrechen (gegen Geflacker)
584 :
585 0 : if ( nType == SC_CONTENT_NOTE )
586 0 : if (!NoteStringsChanged())
587 0 : return;
588 0 : if ( nType == SC_CONTENT_GRAPHIC )
589 0 : if (!DrawNamesChanged(SC_CONTENT_GRAPHIC))
590 0 : return;
591 0 : if ( nType == SC_CONTENT_OLEOBJECT )
592 0 : if (!DrawNamesChanged(SC_CONTENT_OLEOBJECT))
593 0 : return;
594 0 : if ( nType == SC_CONTENT_DRAWING )
595 0 : if (!DrawNamesChanged(SC_CONTENT_DRAWING))
596 0 : return;
597 :
598 0 : SetUpdateMode(false);
599 :
600 0 : ClearType( nType );
601 :
602 0 : if ( !nType || nType == SC_CONTENT_TABLE )
603 0 : GetTableNames();
604 0 : if ( !nType || nType == SC_CONTENT_RANGENAME )
605 0 : GetAreaNames();
606 0 : if ( !nType || nType == SC_CONTENT_DBAREA )
607 0 : GetDbNames();
608 0 : if ( !nType || nType == SC_CONTENT_GRAPHIC )
609 0 : GetGraphicNames();
610 0 : if ( !nType || nType == SC_CONTENT_OLEOBJECT )
611 0 : GetOleNames();
612 0 : if ( !nType || nType == SC_CONTENT_DRAWING )
613 0 : GetDrawingNames();
614 0 : if ( !nType || nType == SC_CONTENT_NOTE )
615 0 : GetNoteStrings();
616 0 : if ( !nType || nType == SC_CONTENT_AREALINK )
617 0 : GetLinkNames();
618 :
619 0 : ApplySettings();
620 0 : SetUpdateMode(sal_True);
621 : }
622 :
623 0 : void ScContentTree::GetTableNames()
624 : {
625 0 : if ( nRootType && nRootType != SC_CONTENT_TABLE ) // ausgeblendet ?
626 0 : return;
627 :
628 0 : ScDocument* pDoc = GetSourceDocument();
629 0 : if (!pDoc)
630 0 : return;
631 :
632 0 : OUString aName;
633 0 : SCTAB nCount = pDoc->GetTableCount();
634 0 : for ( SCTAB i=0; i<nCount; i++ )
635 : {
636 0 : pDoc->GetName( i, aName );
637 0 : InsertContent( SC_CONTENT_TABLE, aName );
638 0 : }
639 : }
640 :
641 : namespace {
642 :
643 0 : OUString createLocalRangeName(const OUString& rName, const OUString& rTableName)
644 : {
645 0 : OUStringBuffer aString (rName);
646 0 : aString.append(OUString(" ("));
647 0 : aString.append(rTableName);
648 0 : aString.append(OUString(")"));
649 0 : return aString.makeStringAndClear();
650 : }
651 : }
652 :
653 0 : void ScContentTree::GetAreaNames()
654 : {
655 0 : if ( nRootType && nRootType != SC_CONTENT_RANGENAME ) // ausgeblendet ?
656 0 : return;
657 :
658 0 : ScDocument* pDoc = GetSourceDocument();
659 0 : if (!pDoc)
660 0 : return;
661 :
662 0 : ScRange aDummy;
663 0 : std::set<OUString> aSet;
664 0 : ScRangeName* pRangeNames = pDoc->GetRangeName();
665 0 : if (!pRangeNames->empty())
666 : {
667 0 : ScRangeName::const_iterator itrBeg = pRangeNames->begin(), itrEnd = pRangeNames->end();
668 0 : for (ScRangeName::const_iterator itr = itrBeg; itr != itrEnd; ++itr)
669 : {
670 0 : if (itr->second->IsValidReference(aDummy))
671 0 : aSet.insert(itr->second->GetName());
672 : }
673 : }
674 0 : for (SCTAB i = 0; i < pDoc->GetTableCount(); ++i)
675 : {
676 0 : ScRangeName* pLocalRangeName = pDoc->GetRangeName(i);
677 0 : if (pLocalRangeName && !pLocalRangeName->empty())
678 : {
679 0 : OUString aTableName;
680 0 : pDoc->GetName(i, aTableName);
681 0 : for (ScRangeName::const_iterator itr = pLocalRangeName->begin(); itr != pLocalRangeName->end(); ++itr)
682 : {
683 0 : if (itr->second->IsValidReference(aDummy))
684 0 : aSet.insert(createLocalRangeName(itr->second->GetName(), aTableName));
685 0 : }
686 : }
687 : }
688 :
689 0 : if (!aSet.empty())
690 : {
691 0 : for (std::set<OUString>::iterator itr = aSet.begin();
692 0 : itr != aSet.end(); ++itr)
693 : {
694 0 : InsertContent(SC_CONTENT_RANGENAME, *itr);
695 : }
696 0 : }
697 : }
698 :
699 0 : void ScContentTree::GetDbNames()
700 : {
701 0 : if ( nRootType && nRootType != SC_CONTENT_DBAREA ) // ausgeblendet ?
702 0 : return;
703 :
704 0 : ScDocument* pDoc = GetSourceDocument();
705 0 : if (!pDoc)
706 0 : return;
707 :
708 0 : ScDBCollection* pDbNames = pDoc->GetDBCollection();
709 0 : const ScDBCollection::NamedDBs& rDBs = pDbNames->getNamedDBs();
710 0 : ScDBCollection::NamedDBs::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
711 0 : for (; itr != itrEnd; ++itr)
712 : {
713 0 : const OUString& aStrName = itr->GetName();
714 0 : InsertContent(SC_CONTENT_DBAREA, aStrName);
715 : }
716 : }
717 :
718 0 : bool ScContentTree::IsPartOfType( sal_uInt16 nContentType, sal_uInt16 nObjIdentifier )
719 : {
720 0 : bool bRet = false;
721 0 : switch ( nContentType )
722 : {
723 : case SC_CONTENT_GRAPHIC:
724 0 : bRet = ( nObjIdentifier == OBJ_GRAF );
725 0 : break;
726 : case SC_CONTENT_OLEOBJECT:
727 0 : bRet = ( nObjIdentifier == OBJ_OLE2 );
728 0 : break;
729 : case SC_CONTENT_DRAWING:
730 0 : bRet = ( nObjIdentifier != OBJ_GRAF && nObjIdentifier != OBJ_OLE2 ); // everything else
731 0 : break;
732 : default:
733 : OSL_FAIL("unknown content type");
734 : }
735 0 : return bRet;
736 : }
737 :
738 0 : void ScContentTree::GetDrawNames( sal_uInt16 nType )
739 : {
740 0 : if ( nRootType && nRootType != nType ) // ausgeblendet ?
741 0 : return;
742 :
743 0 : ScDocument* pDoc = GetSourceDocument();
744 0 : if (!pDoc)
745 0 : return;
746 :
747 : // iterate in flat mode for groups
748 0 : SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
749 :
750 0 : ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
751 0 : SfxObjectShell* pShell = pDoc->GetDocumentShell();
752 0 : if (pDrawLayer && pShell)
753 : {
754 0 : SCTAB nTabCount = pDoc->GetTableCount();
755 0 : for (SCTAB nTab=0; nTab<nTabCount; nTab++)
756 : {
757 0 : SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
758 : OSL_ENSURE(pPage,"Page ?");
759 0 : if (pPage)
760 : {
761 0 : SdrObjListIter aIter( *pPage, eIter );
762 0 : SdrObject* pObject = aIter.Next();
763 0 : while (pObject)
764 : {
765 0 : if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
766 : {
767 0 : String aName = ScDrawLayer::GetVisibleName( pObject );
768 0 : if (aName.Len())
769 0 : InsertContent( nType, aName );
770 : }
771 :
772 0 : pObject = aIter.Next();
773 0 : }
774 : }
775 : }
776 : }
777 : }
778 :
779 0 : void ScContentTree::GetGraphicNames()
780 : {
781 0 : GetDrawNames( SC_CONTENT_GRAPHIC );
782 0 : }
783 :
784 0 : void ScContentTree::GetOleNames()
785 : {
786 0 : GetDrawNames( SC_CONTENT_OLEOBJECT );
787 0 : }
788 :
789 0 : void ScContentTree::GetDrawingNames()
790 : {
791 0 : GetDrawNames( SC_CONTENT_DRAWING );
792 0 : }
793 :
794 0 : void ScContentTree::GetLinkNames()
795 : {
796 0 : if ( nRootType && nRootType != SC_CONTENT_AREALINK ) // ausgeblendet ?
797 0 : return;
798 :
799 0 : ScDocument* pDoc = GetSourceDocument();
800 0 : if (!pDoc)
801 0 : return;
802 :
803 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
804 : OSL_ENSURE(pLinkManager, "kein LinkManager am Dokument?");
805 0 : const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
806 0 : sal_uInt16 nCount = rLinks.size();
807 0 : for (sal_uInt16 i=0; i<nCount; i++)
808 : {
809 0 : ::sfx2::SvBaseLink* pBase = *rLinks[i];
810 0 : if (pBase->ISA(ScAreaLink))
811 0 : InsertContent( SC_CONTENT_AREALINK, ((ScAreaLink*)pBase)->GetSource() );
812 :
813 : // in der Liste die Namen der Quellbereiche
814 : }
815 : }
816 :
817 0 : const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex )
818 : {
819 0 : ScDocument* pDoc = GetSourceDocument();
820 0 : if (!pDoc)
821 0 : return NULL;
822 :
823 0 : sal_uLong nFound = 0;
824 0 : sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
825 : OSL_ENSURE(pLinkManager, "kein LinkManager am Dokument?");
826 0 : const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
827 0 : sal_uInt16 nCount = rLinks.size();
828 0 : for (sal_uInt16 i=0; i<nCount; i++)
829 : {
830 0 : ::sfx2::SvBaseLink* pBase = *rLinks[i];
831 0 : if (pBase->ISA(ScAreaLink))
832 : {
833 0 : if (nFound == nIndex)
834 0 : return (const ScAreaLink*) pBase;
835 0 : ++nFound;
836 : }
837 : }
838 :
839 : OSL_FAIL("link not found");
840 0 : return NULL;
841 : }
842 :
843 0 : static String lcl_NoteString( const ScPostIt& rNote )
844 : {
845 0 : String aText = rNote.GetText();
846 : xub_StrLen nAt;
847 0 : while ( (nAt = aText.Search( '\n' )) != STRING_NOTFOUND )
848 0 : aText.SetChar( nAt, ' ' );
849 0 : return aText;
850 : }
851 :
852 0 : void ScContentTree::GetNoteStrings()
853 : {
854 0 : if ( nRootType && nRootType != SC_CONTENT_NOTE ) // ausgeblendet ?
855 0 : return;
856 :
857 0 : ScDocument* pDoc = GetSourceDocument();
858 0 : if (!pDoc)
859 0 : return;
860 :
861 0 : SCTAB nTabCount = pDoc->GetTableCount();
862 0 : for (SCTAB nTab=0; nTab<nTabCount; nTab++)
863 : {
864 0 : ScNotes::iterator itr = pDoc->GetNotes(nTab)->begin();
865 0 : ScNotes::iterator itrEnd = pDoc->GetNotes(nTab)->end();
866 0 : for (; itr != itrEnd; ++itr)
867 : {
868 0 : InsertContent(SC_CONTENT_NOTE, lcl_NoteString(*itr->second));
869 : }
870 : }
871 : }
872 :
873 0 : ScAddress ScContentTree::GetNotePos( sal_uLong nIndex )
874 : {
875 0 : ScDocument* pDoc = GetSourceDocument();
876 0 : if (!pDoc)
877 0 : return ScAddress();
878 :
879 0 : sal_uLong nFound = 0;
880 0 : SCTAB nTabCount = pDoc->GetTableCount();
881 0 : for (SCTAB nTab=0; nTab<nTabCount; nTab++)
882 : {
883 0 : ScNotes* pNotes = pDoc->GetNotes(nTab);
884 0 : if (nFound + pNotes->size() >= nIndex)
885 : {
886 0 : for (ScNotes::const_iterator itr = pNotes->begin(); itr != pNotes->end(); ++itr)
887 : {
888 0 : if (nFound == nIndex)
889 0 : return ScAddress( itr->first.first, itr->first.second, nTab ); // gefunden
890 :
891 0 : ++nFound;
892 : }
893 : }
894 : else
895 0 : nFound += pNotes->size();
896 : }
897 :
898 : OSL_FAIL("note not found");
899 0 : return ScAddress();
900 : }
901 :
902 0 : sal_Bool ScContentTree::NoteStringsChanged()
903 : {
904 0 : ScDocument* pDoc = GetSourceDocument();
905 0 : if (!pDoc)
906 0 : return false;
907 :
908 0 : SvTreeListEntry* pParent = pRootNodes[SC_CONTENT_NOTE];
909 0 : if (!pParent)
910 0 : return false;
911 :
912 0 : SvTreeListEntry* pEntry = FirstChild( pParent );
913 :
914 0 : bool bEqual = true;
915 0 : SCTAB nTabCount = pDoc->GetTableCount();
916 0 : for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++)
917 : {
918 0 : ScNotes* pNotes = pDoc->GetNotes(nTab);
919 0 : for (ScNotes::const_iterator itr = pNotes->begin(); itr != pNotes->end(); ++itr)
920 : {
921 0 : if( const ScPostIt* pNote = itr->second )
922 : {
923 0 : if ( !pEntry )
924 0 : bEqual = false;
925 : else
926 : {
927 0 : if ( lcl_NoteString( *pNote ) != GetEntryText(pEntry) )
928 0 : bEqual = false;
929 :
930 0 : pEntry = NextSibling( pEntry );
931 : }
932 : }
933 : }
934 : }
935 :
936 0 : if ( pEntry )
937 0 : bEqual = false; // kommt noch was
938 :
939 0 : return !bEqual;
940 : }
941 :
942 0 : sal_Bool ScContentTree::DrawNamesChanged( sal_uInt16 nType )
943 : {
944 0 : ScDocument* pDoc = GetSourceDocument();
945 0 : if (!pDoc)
946 0 : return false;
947 :
948 0 : SvTreeListEntry* pParent = pRootNodes[nType];
949 0 : if (!pParent)
950 0 : return false;
951 :
952 0 : SvTreeListEntry* pEntry = FirstChild( pParent );
953 :
954 : // iterate in flat mode for groups
955 0 : SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
956 :
957 0 : sal_Bool bEqual = sal_True;
958 0 : ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
959 0 : SfxObjectShell* pShell = pDoc->GetDocumentShell();
960 0 : if (pDrawLayer && pShell)
961 : {
962 0 : SCTAB nTabCount = pDoc->GetTableCount();
963 0 : for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++)
964 : {
965 0 : SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
966 : OSL_ENSURE(pPage,"Page ?");
967 0 : if (pPage)
968 : {
969 0 : SdrObjListIter aIter( *pPage, eIter );
970 0 : SdrObject* pObject = aIter.Next();
971 0 : while (pObject && bEqual)
972 : {
973 0 : if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
974 : {
975 0 : if ( !pEntry )
976 0 : bEqual = false;
977 : else
978 : {
979 0 : if ( ScDrawLayer::GetVisibleName( pObject ) != GetEntryText(pEntry) )
980 0 : bEqual = false;
981 :
982 0 : pEntry = NextSibling( pEntry );
983 : }
984 : }
985 0 : pObject = aIter.Next();
986 0 : }
987 : }
988 : }
989 : }
990 :
991 0 : if ( pEntry )
992 0 : bEqual = false; // kommt noch was
993 :
994 0 : return !bEqual;
995 : }
996 :
997 0 : static bool lcl_GetRange( ScDocument* pDoc, sal_uInt16 nType, const String& rName, ScRange& rRange )
998 : {
999 0 : bool bFound = false;
1000 :
1001 0 : if ( nType == SC_CONTENT_RANGENAME )
1002 : {
1003 0 : ScRangeName* pList = pDoc->GetRangeName();
1004 0 : if (pList)
1005 : {
1006 0 : const ScRangeData* p = pList->findByUpperName(ScGlobal::pCharClass->uppercase(rName));
1007 0 : if (p && p->IsValidReference(rRange))
1008 0 : bFound = true;
1009 : }
1010 : }
1011 0 : else if ( nType == SC_CONTENT_DBAREA )
1012 : {
1013 0 : ScDBCollection* pList = pDoc->GetDBCollection();
1014 0 : if (pList)
1015 : {
1016 0 : const ScDBData* p = pList->getNamedDBs().findByUpperName(ScGlobal::pCharClass->uppercase(rName));
1017 0 : if (p)
1018 : {
1019 : SCTAB nTab;
1020 : SCCOL nCol1, nCol2;
1021 : SCROW nRow1, nRow2;
1022 0 : p->GetArea(nTab, nCol1, nRow1, nCol2, nRow2);
1023 0 : rRange = ScRange(nCol1, nRow1, nTab, nCol2, nRow2, nTab);
1024 0 : bFound = true;
1025 : }
1026 : }
1027 : }
1028 :
1029 0 : return bFound;
1030 : }
1031 :
1032 0 : static void lcl_DoDragObject( ScDocShell* pSrcShell, const String& rName, sal_uInt16 nType, Window* pWin )
1033 : {
1034 0 : ScDocument* pSrcDoc = pSrcShell->GetDocument();
1035 0 : ScDrawLayer* pModel = pSrcDoc->GetDrawLayer();
1036 0 : if (pModel)
1037 : {
1038 0 : sal_Bool bOle = ( nType == SC_CONTENT_OLEOBJECT );
1039 0 : sal_Bool bGraf = ( nType == SC_CONTENT_GRAPHIC );
1040 0 : sal_uInt16 nDrawId = sal::static_int_cast<sal_uInt16>( bOle ? OBJ_OLE2 : ( bGraf ? OBJ_GRAF : OBJ_GRUP ) );
1041 0 : SCTAB nTab = 0;
1042 0 : SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab );
1043 0 : if (pObject)
1044 : {
1045 0 : SdrView aEditView( pModel );
1046 0 : aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab));
1047 0 : SdrPageView* pPV = aEditView.GetSdrPageView();
1048 0 : aEditView.MarkObj(pObject, pPV);
1049 :
1050 0 : SdrModel* pDragModel = aEditView.GetMarkedObjModel();
1051 :
1052 0 : TransferableObjectDescriptor aObjDesc;
1053 0 : pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1054 0 : aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1055 : // maSize is set in ScDrawTransferObj ctor
1056 :
1057 0 : ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pDragModel, pSrcShell, aObjDesc );
1058 0 : uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1059 :
1060 0 : pTransferObj->SetDragSourceObj( pObject, nTab );
1061 0 : pTransferObj->SetDragSourceFlags( SC_DROP_NAVIGATOR );
1062 :
1063 0 : SC_MOD()->SetDragObject( NULL, pTransferObj );
1064 0 : pWin->ReleaseMouse();
1065 0 : pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1066 : }
1067 : }
1068 0 : }
1069 :
1070 0 : static void lcl_DoDragCells( ScDocShell* pSrcShell, const ScRange& rRange, sal_uInt16 nFlags, Window* pWin )
1071 : {
1072 0 : ScMarkData aMark;
1073 0 : aMark.SelectTable( rRange.aStart.Tab(), sal_True );
1074 0 : aMark.SetMarkArea( rRange );
1075 :
1076 0 : ScDocument* pSrcDoc = pSrcShell->GetDocument();
1077 0 : if ( !pSrcDoc->HasSelectedBlockMatrixFragment( rRange.aStart.Col(), rRange.aStart.Row(),
1078 0 : rRange.aEnd.Col(), rRange.aEnd.Row(),
1079 0 : aMark ) )
1080 : {
1081 0 : ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
1082 0 : ScClipParam aClipParam(rRange, false);
1083 0 : pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aMark);
1084 : // pClipDoc->ExtendMerge( rRange, sal_True );
1085 :
1086 0 : TransferableObjectDescriptor aObjDesc;
1087 0 : pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1088 0 : aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1089 : // maSize is set in ScTransferObj ctor
1090 :
1091 0 : ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
1092 0 : uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1093 :
1094 0 : pTransferObj->SetDragSource( pSrcShell, aMark );
1095 0 : pTransferObj->SetDragSourceFlags( nFlags );
1096 :
1097 0 : SC_MOD()->SetDragObject( pTransferObj, NULL ); // for internal D&D
1098 0 : pWin->ReleaseMouse();
1099 0 : pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1100 0 : }
1101 0 : }
1102 :
1103 0 : void ScContentTree::DoDrag()
1104 : {
1105 0 : ScDocumentLoader* pDocLoader = NULL;
1106 0 : bIsInDrag = sal_True;
1107 :
1108 0 : ScModule* pScMod = SC_MOD();
1109 :
1110 : sal_uInt16 nType;
1111 : sal_uLong nChild;
1112 0 : SvTreeListEntry* pEntry = GetCurEntry();
1113 0 : GetEntryIndexes( nType, nChild, pEntry );
1114 :
1115 0 : if( pEntry &&
1116 0 : (nChild != SC_CONTENT_NOCHILD) &&
1117 0 : (nType != SC_CONTENT_ROOT) &&
1118 0 : (nType != SC_CONTENT_NOTE) &&
1119 0 : (nType != SC_CONTENT_AREALINK) )
1120 : {
1121 0 : String aText( GetEntryText( pEntry ) );
1122 :
1123 0 : ScDocument* pLocalDoc = NULL; // fuer URL-Drop
1124 0 : String aDocName;
1125 0 : if (bHiddenDoc)
1126 0 : aDocName = aHiddenName;
1127 : else
1128 : {
1129 0 : ScDocShell* pDocSh = GetManualOrCurrent();
1130 0 : if (pDocSh)
1131 : {
1132 0 : if (pDocSh->HasName())
1133 0 : aDocName = pDocSh->GetMedium()->GetName();
1134 : else
1135 0 : pLocalDoc = pDocSh->GetDocument(); // Drop nur in dieses Dokument
1136 : }
1137 : }
1138 :
1139 0 : sal_Bool bDoLinkTrans = false; // use ScLinkTransferObj
1140 0 : String aLinkURL; // for ScLinkTransferObj
1141 0 : String aLinkText;
1142 :
1143 0 : sal_uInt16 nDropMode = pParentWindow->GetDropMode();
1144 0 : switch ( nDropMode )
1145 : {
1146 : case SC_DROPMODE_URL:
1147 : {
1148 0 : String aUrl = aDocName;
1149 0 : aUrl += '#';
1150 0 : aUrl += aText;
1151 :
1152 0 : pScMod->SetDragJump( pLocalDoc, aUrl, aText );
1153 :
1154 0 : if (aDocName.Len())
1155 : {
1156 : // provide URL to outside only if the document has a name
1157 : // (without name, only internal D&D via SetDragJump)
1158 :
1159 0 : aLinkURL = aUrl;
1160 0 : aLinkText = aText;
1161 : }
1162 0 : bDoLinkTrans = sal_True;
1163 : }
1164 0 : break;
1165 : case SC_DROPMODE_LINK:
1166 : {
1167 0 : if ( aDocName.Len() ) // link only to named documents
1168 : {
1169 : // for internal D&D, set flag to insert a link
1170 :
1171 0 : switch ( nType )
1172 : {
1173 : case SC_CONTENT_TABLE:
1174 0 : pScMod->SetDragLink( aDocName, aText, EMPTY_STRING );
1175 0 : bDoLinkTrans = sal_True;
1176 0 : break;
1177 : case SC_CONTENT_RANGENAME:
1178 : case SC_CONTENT_DBAREA:
1179 0 : pScMod->SetDragLink( aDocName, EMPTY_STRING, aText );
1180 0 : bDoLinkTrans = sal_True;
1181 0 : break;
1182 :
1183 : // other types cannot be linked
1184 : }
1185 : }
1186 : }
1187 0 : break;
1188 : case SC_DROPMODE_COPY:
1189 : {
1190 0 : ScDocShell* pSrcShell = NULL;
1191 0 : if ( bHiddenDoc )
1192 : {
1193 0 : OUString aFilter, aOptions;
1194 0 : OUString aURL = aHiddenName;
1195 0 : pDocLoader = new ScDocumentLoader( aURL, aFilter, aOptions );
1196 0 : if (!pDocLoader->IsError())
1197 0 : pSrcShell = pDocLoader->GetDocShell();
1198 : }
1199 : else
1200 0 : pSrcShell = GetManualOrCurrent();
1201 :
1202 0 : if ( pSrcShell )
1203 : {
1204 0 : ScDocument* pSrcDoc = pSrcShell->GetDocument();
1205 0 : if ( nType == SC_CONTENT_RANGENAME || nType == SC_CONTENT_DBAREA )
1206 : {
1207 0 : ScRange aRange;
1208 0 : if ( lcl_GetRange( pSrcDoc, nType, aText, aRange ) )
1209 : {
1210 0 : lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR, this );
1211 0 : }
1212 : }
1213 0 : else if ( nType == SC_CONTENT_TABLE )
1214 : {
1215 : SCTAB nTab;
1216 0 : if ( pSrcDoc->GetTable( aText, nTab ) )
1217 : {
1218 0 : ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab );
1219 0 : lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR | SC_DROP_TABLE, this );
1220 : }
1221 : }
1222 0 : else if ( nType == SC_CONTENT_GRAPHIC || nType == SC_CONTENT_OLEOBJECT ||
1223 0 : nType == SC_CONTENT_DRAWING )
1224 : {
1225 0 : lcl_DoDragObject( pSrcShell, aText, nType, this );
1226 :
1227 : // in ExecuteDrag kann der Navigator geloescht worden sein
1228 : // -> nicht mehr auf Member zugreifen !!!
1229 : }
1230 : }
1231 : }
1232 0 : break;
1233 : }
1234 :
1235 0 : if (bDoLinkTrans)
1236 : {
1237 0 : ScLinkTransferObj* pTransferObj = new ScLinkTransferObj;
1238 0 : uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1239 :
1240 0 : if ( aLinkURL.Len() )
1241 0 : pTransferObj->SetLinkURL( aLinkURL, aLinkText );
1242 :
1243 : // SetDragJump / SetDragLink has been done above
1244 :
1245 0 : ReleaseMouse();
1246 0 : pTransferObj->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1247 0 : }
1248 : }
1249 :
1250 0 : bIsInDrag = false; // static Member
1251 :
1252 0 : delete pDocLoader; // falls Dokument zum Draggen geladen wurde
1253 0 : }
1254 :
1255 0 : IMPL_STATIC_LINK(ScContentTree, ExecDragHdl, void*, EMPTYARG)
1256 : {
1257 : // als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der
1258 : // Navigator geloescht werden darf
1259 :
1260 0 : pThis->DoDrag();
1261 0 : return 0;
1262 : }
1263 :
1264 0 : sal_Bool ScContentTree::LoadFile( const String& rUrl )
1265 : {
1266 0 : String aDocName = rUrl;
1267 0 : xub_StrLen nPos = aDocName.Search('#');
1268 0 : if ( nPos != STRING_NOTFOUND )
1269 0 : aDocName.Erase(nPos); // nur der Name, ohne #...
1270 :
1271 0 : sal_Bool bReturn = false;
1272 0 : OUString aURL = aDocName;
1273 0 : OUString aFilter, aOptions;
1274 0 : ScDocumentLoader aLoader( aURL, aFilter, aOptions );
1275 0 : if ( !aLoader.IsError() )
1276 : {
1277 0 : bHiddenDoc = sal_True;
1278 0 : aHiddenName = aDocName;
1279 0 : aHiddenTitle = aLoader.GetTitle();
1280 0 : pHiddenDocument = aLoader.GetDocument();
1281 :
1282 0 : Refresh(); // Inhalte aus geladenem Dokument holen
1283 :
1284 0 : pHiddenDocument = NULL;
1285 :
1286 0 : pParentWindow->GetDocNames( &aHiddenTitle ); // Liste fuellen
1287 : }
1288 :
1289 : // Dokument wird im dtor von ScDocumentLoader wieder geschlossen
1290 :
1291 0 : return bReturn;
1292 : }
1293 :
1294 0 : void ScContentTree::InitWindowBits( sal_Bool bButtons )
1295 : {
1296 0 : WinBits nFlags = GetStyle()|WB_CLIPCHILDREN|WB_HSCROLL;
1297 0 : if (bButtons)
1298 0 : nFlags |= WB_HASBUTTONS|WB_HASBUTTONSATROOT;
1299 :
1300 0 : SetStyle( nFlags );
1301 0 : }
1302 :
1303 0 : void ScContentTree::SetRootType( sal_uInt16 nNew )
1304 : {
1305 0 : if ( nNew != nRootType )
1306 : {
1307 0 : nRootType = nNew;
1308 0 : InitWindowBits( nNew == 0 );
1309 0 : Refresh();
1310 :
1311 0 : ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg();
1312 0 : rCfg.SetRootType( nRootType );
1313 : }
1314 0 : }
1315 :
1316 0 : void ScContentTree::ToggleRoot() // nach Selektion
1317 : {
1318 0 : sal_uInt16 nNew = SC_CONTENT_ROOT;
1319 0 : if ( nRootType == SC_CONTENT_ROOT )
1320 : {
1321 0 : SvTreeListEntry* pEntry = GetCurEntry();
1322 0 : if (pEntry)
1323 : {
1324 0 : SvTreeListEntry* pParent = GetParent(pEntry);
1325 0 : for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++)
1326 0 : if ( pEntry == pRootNodes[i] || pParent == pRootNodes[i] )
1327 0 : nNew = i;
1328 : }
1329 : }
1330 :
1331 0 : SetRootType( nNew );
1332 0 : }
1333 :
1334 0 : void ScContentTree::ResetManualDoc()
1335 : {
1336 0 : aManualDoc.Erase();
1337 0 : bHiddenDoc = false;
1338 :
1339 0 : ActiveDocChanged();
1340 0 : }
1341 :
1342 0 : void ScContentTree::ActiveDocChanged()
1343 : {
1344 0 : if ( !bHiddenDoc && !aManualDoc.Len() )
1345 0 : Refresh(); // Inhalte nur wenn automatisch
1346 :
1347 : // Listbox muss immer geupdated werden, wegen aktiv-Flag
1348 :
1349 0 : String aCurrent;
1350 0 : if ( bHiddenDoc )
1351 0 : aCurrent = aHiddenTitle;
1352 : else
1353 : {
1354 0 : ScDocShell* pSh = GetManualOrCurrent();
1355 0 : if (pSh)
1356 0 : aCurrent = pSh->GetTitle();
1357 : else
1358 : {
1359 : // eingestelltes Dokument existiert nicht mehr
1360 :
1361 0 : aManualDoc.Erase(); // wieder automatisch
1362 0 : Refresh();
1363 0 : pSh = GetManualOrCurrent(); // sollte jetzt aktives sein
1364 0 : if (pSh)
1365 0 : aCurrent = pSh->GetTitle();
1366 : }
1367 : }
1368 0 : pParentWindow->GetDocNames( &aCurrent ); // selektieren
1369 0 : }
1370 :
1371 0 : void ScContentTree::SetManualDoc(const String& rName)
1372 : {
1373 0 : aManualDoc = rName;
1374 0 : if (!bHiddenDoc)
1375 : {
1376 0 : Refresh();
1377 0 : pParentWindow->GetDocNames( &aManualDoc ); // selektieren
1378 : }
1379 0 : }
1380 :
1381 0 : void ScContentTree::SelectDoc(const String& rName) // rName wie im Menue/Listbox angezeigt
1382 : {
1383 0 : if ( rName == pParentWindow->aStrActiveWin )
1384 : {
1385 0 : ResetManualDoc();
1386 0 : return;
1387 : }
1388 :
1389 : // "aktiv" oder "inaktiv" weglassen
1390 :
1391 0 : String aRealName = rName;
1392 0 : xub_StrLen nLen = rName.Len();
1393 0 : xub_StrLen nActiveStart = nLen - pParentWindow->aStrActive.Len();
1394 0 : if ( rName.Copy( nActiveStart ) == pParentWindow->aStrActive )
1395 0 : aRealName = rName.Copy( 0, nActiveStart );
1396 0 : xub_StrLen nNotActiveStart = nLen - pParentWindow->aStrNotActive.Len();
1397 0 : if ( rName.Copy( nNotActiveStart ) == pParentWindow->aStrNotActive )
1398 0 : aRealName = rName.Copy( 0, nNotActiveStart );
1399 :
1400 0 : sal_Bool bLoaded = false;
1401 :
1402 : // ist es ein normal geladenes Doc ?
1403 :
1404 0 : SfxObjectShell* pSh = SfxObjectShell::GetFirst();
1405 0 : while ( pSh && !bLoaded )
1406 : {
1407 0 : if ( pSh->ISA(ScDocShell) )
1408 0 : if ( pSh->GetTitle() == aRealName )
1409 0 : bLoaded = sal_True;
1410 0 : pSh = SfxObjectShell::GetNext( *pSh );
1411 : }
1412 :
1413 0 : if (bLoaded)
1414 : {
1415 0 : bHiddenDoc = false;
1416 0 : SetManualDoc(aRealName);
1417 : }
1418 0 : else if (aHiddenTitle.Len()) // verstecktes ausgewaehlt
1419 : {
1420 0 : if (!bHiddenDoc)
1421 0 : LoadFile(aHiddenName);
1422 : }
1423 : else
1424 : {
1425 : OSL_FAIL("SelectDoc: nicht gefunden");
1426 0 : }
1427 : }
1428 :
1429 0 : void ScContentTree::ApplySettings()
1430 : {
1431 0 : const ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings();
1432 0 : if( pSettings )
1433 : {
1434 0 : sal_uInt16 nRootSel = pSettings->GetRootSelected();
1435 0 : sal_uLong nChildSel = pSettings->GetChildSelected();
1436 :
1437 0 : for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1438 : {
1439 0 : if( pRootNodes[ nEntry ] )
1440 : {
1441 : // expand
1442 0 : sal_Bool bExp = pSettings->IsExpanded( nEntry );
1443 0 : if( bExp != IsExpanded( pRootNodes[ nEntry ] ) )
1444 : {
1445 0 : if( bExp )
1446 0 : Expand( pRootNodes[ nEntry ] );
1447 : else
1448 0 : Collapse( pRootNodes[ nEntry ] );
1449 : }
1450 :
1451 : // select
1452 0 : if( nRootSel == nEntry )
1453 : {
1454 0 : SvTreeListEntry* pEntry = NULL;
1455 0 : if( bExp && (nChildSel != SC_CONTENT_NOCHILD) )
1456 0 : pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel );
1457 0 : Select( pEntry ? pEntry : pRootNodes[ nEntry ] );
1458 : }
1459 : }
1460 : }
1461 : }
1462 0 : }
1463 :
1464 0 : void ScContentTree::StoreSettings() const
1465 : {
1466 0 : ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings();
1467 0 : if( pSettings )
1468 : {
1469 0 : for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1470 : {
1471 0 : sal_Bool bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] );
1472 0 : pSettings->SetExpanded( nEntry, bExp );
1473 : }
1474 : sal_uInt16 nRoot;
1475 : sal_uLong nChild;
1476 0 : GetEntryIndexes( nRoot, nChild, GetCurEntry() );
1477 0 : pSettings->SetRootSelected( nRoot );
1478 0 : pSettings->SetChildSelected( nChild );
1479 : }
1480 93 : }
1481 :
1482 :
1483 : //
1484 : //------------------------------------------------------------------------
1485 : //
1486 :
1487 :
1488 :
1489 :
1490 :
1491 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|