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