xref: /trunk/main/sc/source/ui/navipi/content.cxx (revision 3ea0c3d5)
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 "tabvwsh.hxx"
68 #include "drawview.hxx"
69 #include "clipparam.hxx"
70 
71 using namespace com::sun::star;
72 
73 //	Reihenfolge der Kategorien im Navigator -------------------------------------
74 
75 static sal_uInt16 pTypeList[SC_CONTENT_COUNT] =
76 {
77 	SC_CONTENT_ROOT,			// ROOT (0) muss vorne stehen
78 	SC_CONTENT_TABLE,
79 	SC_CONTENT_RANGENAME,
80 	SC_CONTENT_DBAREA,
81 	SC_CONTENT_AREALINK,
82 	SC_CONTENT_GRAPHIC,
83 	SC_CONTENT_OLEOBJECT,
84 	SC_CONTENT_NOTE,
85 	SC_CONTENT_DRAWING
86 };
87 
88 sal_Bool ScContentTree::bIsInDrag = sal_False;
89 
90 
91 ScDocShell* ScContentTree::GetManualOrCurrent()
92 {
93 	ScDocShell* pSh = NULL;
94 	if ( aManualDoc.Len() )
95 	{
96 		TypeId aScType = TYPE(ScDocShell);
97 		SfxObjectShell* pObjSh = SfxObjectShell::GetFirst( &aScType );
98 		while ( pObjSh && !pSh )
99 		{
100 			if ( pObjSh->GetTitle() == aManualDoc )
101 				pSh = PTR_CAST( ScDocShell, pObjSh );
102 			pObjSh = SfxObjectShell::GetNext( *pObjSh, &aScType );
103 		}
104 	}
105 	else
106 	{
107 		//	Current nur, wenn keine manuell eingestellt ist
108 		//	(damit erkannt wird, wenn das Dokument nicht mehr existiert)
109 
110 		SfxViewShell* pViewSh = SfxViewShell::Current();
111 		if ( pViewSh )
112 		{
113 			SfxObjectShell* pObjSh = pViewSh->GetViewFrame()->GetObjectShell();
114 			pSh = PTR_CAST( ScDocShell, pObjSh );
115 		}
116 	}
117 
118 	return pSh;
119 }
120 
121 //
122 //			ScContentTree
123 //
124 
125 ScContentTree::ScContentTree( Window* pParent, const ResId& rResId ) :
126 	SvTreeListBox	( pParent, rResId ),
127 	aEntryImages	( ScResId( RID_IMAGELIST_NAVCONT ) ),
128 	aHCEntryImages	( ScResId( RID_IMAGELIST_H_NAVCONT ) ),
129 	nRootType		( SC_CONTENT_ROOT ),
130 	bHiddenDoc		( sal_False ),
131 	pHiddenDocument	( NULL ),
132     bisInNavigatoeDlg  ( sal_False )
133 {
134 	sal_uInt16 i;
135 	for (i=0; i<SC_CONTENT_COUNT; i++)
136 		pPosList[pTypeList[i]] = i;			// invers zum suchen
137 
138 	pParentWindow = (ScNavigatorDlg*)pParent;
139 
140 	pRootNodes[0] = NULL;
141 	for (i=1; i<SC_CONTENT_COUNT; i++)
142 		InitRoot(i);
143 
144 	SetNodeDefaultImages();
145 
146     SetDoubleClickHdl( LINK( this, ScContentTree, ContentDoubleClickHdl ) );
147 
148 	pTmpEntry= NULL;
149 	m_bFirstPaint=true;
150 
151     SetStyle( GetStyle() | WB_QUICK_SEARCH );
152 }
153 
154 ScContentTree::~ScContentTree()
155 {
156 }
157 // helper function for 	GetEntryAltText and GetEntryLongDescription
158 String ScContentTree::getAltLongDescText( SvLBoxEntry* pEntry , sal_Bool isAltText) const
159 {
160 	SdrObject* pFound = NULL;
161 
162 	sal_uInt16 nType;
163 	sal_uLong nChild;
164 	GetEntryIndexes( nType, nChild, pEntry );
165 	switch( nType )
166 	{
167 	case SC_CONTENT_OLEOBJECT:
168 	case SC_CONTENT_GRAPHIC:
169 	case SC_CONTENT_DRAWING:
170 		{
171 			ScDocument* pDoc = ( const_cast< ScContentTree* >(this) )->GetSourceDocument();
172 			SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
173 			ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
174 			SfxObjectShell* pShell = pDoc->GetDocumentShell();
175 			if (pDrawLayer && pShell)
176 			{
177 				sal_uInt16 nTabCount = pDoc->GetTableCount();
178 				for (sal_uInt16 nTab=0; nTab<nTabCount; nTab++)
179 				{
180 					SdrPage* pPage = pDrawLayer->GetPage(nTab);
181 					DBG_ASSERT(pPage,"Page ?");
182 					if (pPage)
183 					{
184 						SdrObjListIter aIter( *pPage, eIter );
185 						SdrObject* pObject = aIter.Next();
186 						while (pObject)
187 						{
188 							if( ScDrawLayer::GetVisibleName( pObject ) == GetEntryText( pEntry ) )
189 							{
190 								pFound = pObject;
191 								break;
192 							}
193 							pObject = aIter.Next();
194 						}
195 					}
196 				}
197 			}
198 			 if( pFound )
199 			 {
200 			 	if( isAltText )
201 			 		return pFound->GetTitle();
202 				else
203 					return pFound->GetDescription();
204 			 }
205 		}
206 		break;
207 	}
208 	return String();
209 }
210 String  ScContentTree::GetEntryAltText( SvLBoxEntry* pEntry ) const
211 {
212 	return getAltLongDescText( pEntry, sal_True );
213 }
214 String ScContentTree::GetEntryLongDescription( SvLBoxEntry* pEntry ) const
215 {
216 	return getAltLongDescText( pEntry, sal_False);
217 }
218 
219 void ScContentTree::InitRoot( sal_uInt16 nType )
220 {
221 	if ( !nType )
222 		return;
223 
224 	if ( nRootType && nRootType != nType )				// ausgeblendet ?
225 	{
226 		pRootNodes[nType] = NULL;
227 		return;
228 	}
229 
230 	const Image& rImage = aEntryImages.GetImage( nType );
231 	String aName( ScResId( SCSTR_CONTENT_ROOT + nType ) );
232 	// wieder an die richtige Position:
233 	sal_uInt16 nPos = nRootType ? 0 : pPosList[nType]-1;
234 	SvLBoxEntry* pNew = InsertEntry( aName, rImage, rImage, NULL, sal_False, nPos );
235 
236 	const Image& rHCImage = aHCEntryImages.GetImage( nType );
237 	SetExpandedEntryBmp( pNew, rHCImage, BMP_COLOR_HIGHCONTRAST );
238 	SetCollapsedEntryBmp( pNew, rHCImage, BMP_COLOR_HIGHCONTRAST );
239 
240 	pRootNodes[nType] = pNew;
241 }
242 
243 void ScContentTree::ClearAll()
244 {
245     //There are one method in Control::SetUpdateMode(), and one override method SvTreeListBox::SetUpdateMode(). Here although
246     //SvTreeListBox::SetUpdateMode() is called in refresh method, it only call SvTreeListBox::SetUpdateMode(), not Control::SetUpdateMode().
247     //In SvTreeList::Clear(), Broadcast( LISTACTION_CLEARED ) will be called and finally, it will be trapped into the event yield() loop. And
248     //the InitRoot() method won't be called. Then if a user click or press key to update the navigator tree, crash happens.
249     //So the solution is to disable the UpdateMode of Control, then call Clear(), then recover the update mode
250     sal_Bool bOldUpdate = Control::IsUpdateMode();
251     Control::SetUpdateMode(sal_False);
252 	Clear();
253     Control::SetUpdateMode(bOldUpdate);
254 	for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++)
255 		InitRoot(i);
256 }
257 
258 void ScContentTree::ClearType(sal_uInt16 nType)
259 {
260 	if (!nType)
261 		ClearAll();
262 	else
263 	{
264 		SvLBoxEntry* pParent = pRootNodes[nType];
265 		if ( !pParent || GetChildCount(pParent) )		// nicht, wenn ohne Children schon da
266 		{
267 			if (pParent)
268 				GetModel()->Remove( pParent );			// mit allen Children
269 			InitRoot( nType );							// ggf. neu eintragen
270 		}
271 	}
272 }
273 
274 void ScContentTree::InsertContent( sal_uInt16 nType, const String& rValue )
275 {
276 	if (nType >= SC_CONTENT_COUNT)
277 	{
278 		DBG_ERROR("ScContentTree::InsertContent mit falschem Typ");
279 		return;
280 	}
281 
282 	SvLBoxEntry* pParent = pRootNodes[nType];
283 	if (pParent)
284 		InsertEntry( rValue, pParent );
285 	else
286 	{
287 		DBG_ERROR("InsertContent ohne Parent");
288 	}
289 }
290 
291 void ScContentTree::GetEntryIndexes( sal_uInt16& rnRootIndex, sal_uLong& rnChildIndex, SvLBoxEntry* pEntry ) const
292 {
293     rnRootIndex = SC_CONTENT_ROOT;
294     rnChildIndex = SC_CONTENT_NOCHILD;
295 
296     if( !pEntry )
297         return;
298 
299     SvLBoxEntry* pParent = GetParent( pEntry );
300     bool bFound = false;
301     for( sal_uInt16 nRoot = 1; !bFound && (nRoot < SC_CONTENT_COUNT); ++nRoot )
302     {
303         if( pEntry == pRootNodes[ nRoot ] )
304         {
305             rnRootIndex = nRoot;
306             rnChildIndex = ~0UL;
307             bFound = true;
308         }
309         else if( pParent && (pParent == pRootNodes[ nRoot ]) )
310         {
311             rnRootIndex = nRoot;
312 
313             // search the entry in all child entries of the parent
314             sal_uLong nEntry = 0;
315             SvLBoxEntry* pIterEntry = FirstChild( pParent );
316             while( !bFound && pIterEntry )
317             {
318                 if ( pEntry == pIterEntry )
319                 {
320                     rnChildIndex = nEntry;
321                     bFound = true;  // exit the while loop
322                 }
323                 pIterEntry = NextSibling( pIterEntry );
324                 ++nEntry;
325             }
326 
327             bFound = true;  // exit the for loop
328         }
329     }
330 }
331 
332 sal_uLong ScContentTree::GetChildIndex( SvLBoxEntry* pEntry ) const
333 {
334     sal_uInt16 nRoot;
335     sal_uLong nChild;
336     GetEntryIndexes( nRoot, nChild, pEntry );
337     return nChild;
338 }
339 
340 String lcl_GetDBAreaRange( ScDocument* pDoc, const String& rDBName )
341 {
342 	String aRet;
343 	if (pDoc)
344 	{
345 		ScDBCollection*	pDbNames = pDoc->GetDBCollection();
346 		sal_uInt16 nCount = pDbNames->GetCount();
347 		for ( sal_uInt16 i=0; i<nCount; i++ )
348 		{
349 			ScDBData* pData = (*pDbNames)[i];
350 			if ( pData->GetName() == rDBName )
351 			{
352 				ScRange aRange;
353 				pData->GetArea(aRange);
354 				aRange.Format( aRet, SCR_ABS_3D, pDoc );
355 				break;
356 			}
357 		}
358 	}
359 	return aRet;
360 }
361 
362 IMPL_LINK( ScContentTree, ContentDoubleClickHdl, ScContentTree *, EMPTYARG )
363 {
364     sal_uInt16 nType;
365     sal_uLong nChild;
366     SvLBoxEntry* pEntry = GetCurEntry();
367     GetEntryIndexes( nType, nChild, pEntry );
368 
369     if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) )
370 	{
371 		if ( bHiddenDoc )
372 			return 0;				//! spaeter...
373 
374         String aText( GetEntryText( pEntry ) );
375 
376 		if ( aManualDoc.Len() )
377 			pParentWindow->SetCurrentDoc( aManualDoc );
378 
379 		switch( nType )
380 		{
381 			case SC_CONTENT_TABLE:
382 				pParentWindow->SetCurrentTableStr( aText );
383             break;
384 
385             case SC_CONTENT_RANGENAME:
386 				pParentWindow->SetCurrentCellStr( aText );
387             break;
388 
389             case SC_CONTENT_DBAREA:
390             {
391                 //  #47905# Wenn gleiche Bereichs- und DB-Namen existieren, wird
392                 //  bei SID_CURRENTCELL der Bereichsname genommen.
393                 //  DB-Bereiche darum direkt ueber die Adresse anspringen.
394 
395                 String aRangeStr = lcl_GetDBAreaRange( GetSourceDocument(), aText );
396                 if (aRangeStr.Len())
397                     pParentWindow->SetCurrentCellStr( aRangeStr );
398             }
399             break;
400 
401             case SC_CONTENT_OLEOBJECT:
402 			case SC_CONTENT_GRAPHIC:
403 			case SC_CONTENT_DRAWING:
404 				pParentWindow->SetCurrentObject( aText );
405             break;
406 
407             case SC_CONTENT_NOTE:
408             {
409                 ScAddress aPos = GetNotePos( nChild );
410                 pParentWindow->SetCurrentTable( aPos.Tab() );
411                 pParentWindow->SetCurrentCell( aPos.Col(), aPos.Row() );
412             }
413             break;
414 
415             case SC_CONTENT_AREALINK:
416             {
417                 const ScAreaLink* pLink = GetLink( nChild );
418                 if( pLink )
419                 {
420                     ScRange aRange = pLink->GetDestArea();
421                     String aRangeStr;
422                     ScDocument* pSrcDoc = GetSourceDocument();
423                     aRange.Format( aRangeStr, SCR_ABS_3D, pSrcDoc, pSrcDoc->GetAddressConvention() );
424                     pParentWindow->SetCurrentCellStr( aRangeStr );
425                 }
426             }
427             break;
428 		}
429 
430 		ScNavigatorDlg::ReleaseFocus();		// set focus into document
431 	}
432 
433 	return 0;
434 }
435 
436 void ScContentTree::MouseButtonDown( const MouseEvent& rMEvt )
437 {
438     SvTreeListBox::MouseButtonDown( rMEvt );
439     StoreSettings();
440 }
441 
442 void ScContentTree::KeyInput( const KeyEvent& rKEvt )
443 {
444 	sal_Bool bUsed = sal_False;
445 
446 	const KeyCode aCode = rKEvt.GetKeyCode();
447 	if (aCode.GetCode() == KEY_RETURN)
448 	{
449 		switch (aCode.GetModifier())
450 		{
451 			case KEY_MOD1:
452 				ToggleRoot();		// toggle root mode (as in Writer)
453 				bUsed = sal_True;
454 				break;
455 			case 0:
456             {
457                 SvLBoxEntry* pEntry = GetCurEntry();
458                 if( pEntry )
459                 {
460                     sal_uInt16 nType;
461                     sal_uLong nChild;
462                     GetEntryIndexes( nType, nChild, pEntry );
463 
464                     if( (nType != SC_CONTENT_ROOT) && (nChild == SC_CONTENT_NOCHILD) )
465                     {
466                         String aText( GetEntryText( pEntry ) );
467                         if ( IsExpanded( pEntry ) )
468                             Collapse( pEntry );
469                         else
470                             Expand( pEntry );
471                     }
472                     else
473                         ContentDoubleClickHdl(0);      // select content as if double clicked
474                 }
475 
476                 bUsed = sal_True;
477             }
478             break;
479 		}
480 	}
481 	//Solution: Make KEY_SPACE has same function as DoubleClick
482 	if ( bisInNavigatoeDlg )
483 	{
484 		if(aCode.GetCode() == KEY_SPACE )
485 		{
486 			bUsed = sal_True;
487 		    sal_uInt16 nType;
488 		    sal_uLong nChild;
489 		    SvLBoxEntry* pEntry = GetCurEntry();
490 		    GetEntryIndexes( nType, nChild, pEntry );
491 		    if( pEntry && (nType != SC_CONTENT_ROOT) && (nChild != SC_CONTENT_NOCHILD) )
492 			{
493 				if ( bHiddenDoc )
494 					return ;				//! spaeter...
495 		              String aText( GetEntryText( pEntry ) );
496 				sKeyString = aText;
497 				if ( aManualDoc.Len() )
498 					pParentWindow->SetCurrentDoc( aManualDoc );
499 				switch( nType )
500 				{
501 				    case SC_CONTENT_OLEOBJECT:
502 					case SC_CONTENT_GRAPHIC:
503 					case SC_CONTENT_DRAWING:
504 					{
505 						Window* pWindow=(Window*)GetParent(pEntry);
506 						ScNavigatorDlg* pScNavigatorDlg = (ScNavigatorDlg*)pWindow;
507 						ScTabViewShell* pScTabViewShell = NULL;
508 						ScDrawView* pScDrawView = NULL;
509 						if (pScNavigatorDlg!=NULL)
510 							  pScTabViewShell=pScNavigatorDlg->GetTabViewShell();
511 						if(pScTabViewShell !=NULL)
512 							  pScDrawView =pScTabViewShell->GetViewData()->GetScDrawView();
513 						if(pScDrawView!=NULL)
514 						 {
515 							pScDrawView->SelectCurrentViewObject(aText );
516 							sal_Bool bHasMakredObject = sal_False;
517 							SvLBoxEntry* pParent = pRootNodes[nType];
518 							SvLBoxEntry* pBeginEntry = NULL;
519 							if( pParent )
520 								pBeginEntry = FirstChild(pParent);
521 							while( pBeginEntry )
522 							{
523 								String aTempText( GetEntryText( pBeginEntry ) );
524 								 if( pScDrawView->GetObjectIsMarked( pScDrawView->GetObjectByName( aTempText ) ) )
525 								 {
526 									bHasMakredObject = sal_True;
527 									break;
528 								  }
529 								pBeginEntry =  Next( pBeginEntry );
530 							}
531 							if(  !bHasMakredObject && pScTabViewShell)
532 								pScTabViewShell->SetDrawShell(sal_False);
533 							ObjectFresh( nType,pEntry );
534 						}
535 					}
536 		            break;
537 			     }
538 			}
539 		   }
540 	   }
541     //StoreSettings();
542 
543     if( !bUsed )
544 	{
545 		if(aCode.GetCode() == KEY_F5 )
546 		{
547 			StoreSettings();
548 		SvTreeListBox::KeyInput(rKEvt);
549 		}
550 		else
551 		{
552 			SvTreeListBox::KeyInput(rKEvt);
553 			StoreSettings();
554 		}
555 	}
556 }
557 
558 //sal_Bool __EXPORT ScContentTree::Drop( const DropEvent& rEvt )
559 //{
560 //	return pParentWindow->Drop(rEvt);			// Drop auf Navigator
561 //}
562 
563 //sal_Bool __EXPORT ScContentTree::QueryDrop( DropEvent& rEvt )
564 //{
565 //	return pParentWindow->QueryDrop(rEvt);		// Drop auf Navigator
566 //}
567 
568 sal_Int8 ScContentTree::AcceptDrop( const AcceptDropEvent& /* rEvt */ )
569 {
570 	return DND_ACTION_NONE;
571 }
572 
573 sal_Int8 ScContentTree::ExecuteDrop( const ExecuteDropEvent& /* rEvt */ )
574 {
575 	return DND_ACTION_NONE;
576 }
577 
578 void ScContentTree::StartDrag( sal_Int8 /* nAction */, const Point& /* rPosPixel */ )
579 {
580 	DoDrag();
581 }
582 
583 void ScContentTree::DragFinished( sal_Int8 /* nAction */ )
584 {
585 }
586 
587 void __EXPORT ScContentTree::Command( const CommandEvent& rCEvt )
588 {
589 	sal_Bool bDone = sal_False;
590 
591 	switch ( rCEvt.GetCommand() )
592 	{
593 		case COMMAND_STARTDRAG:
594 			//	Aus dem ExecuteDrag heraus kann der Navigator geloescht werden
595 			//	(beim Umschalten auf einen anderen Dokument-Typ), das wuerde aber
596 			//	den StarView MouseMove-Handler, der Command() aufruft, umbringen.
597 			//	Deshalb Drag&Drop asynchron:
598 
599 //			DoDrag();
600 
601 			Application::PostUserEvent( STATIC_LINK( this, ScContentTree, ExecDragHdl ) );
602 
603 			bDone = sal_True;
604 			break;
605 
606 		case COMMAND_CONTEXTMENU:
607 			{
608 				//	Drag-Drop Modus
609 
610 				PopupMenu aPop;
611 				ScPopupMenu aDropMenu( ScResId( RID_POPUP_DROPMODE ) );
612 				aDropMenu.CheckItem( RID_DROPMODE_URL + pParentWindow->GetDropMode() );
613 				aPop.InsertItem( 1, pParentWindow->GetStrDragMode() );
614 				aPop.SetPopupMenu( 1, &aDropMenu );
615 
616 				//	angezeigtes Dokument
617 
618 				ScPopupMenu aDocMenu;
619 				aDocMenu.SetMenuFlags( aDocMenu.GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
620 				sal_uInt16 i=0;
621 				sal_uInt16 nPos=0;
622 				//	geladene Dokumente
623 				ScDocShell* pCurrentSh = PTR_CAST( ScDocShell, SfxObjectShell::Current() );
624 				SfxObjectShell* pSh = SfxObjectShell::GetFirst();
625 				while ( pSh )
626 				{
627 					if ( pSh->ISA(ScDocShell) )
628 					{
629 						String aName = pSh->GetTitle();
630 						String aEntry = aName;
631 						if ( pSh == pCurrentSh )
632 							aEntry += pParentWindow->aStrActive;
633 						else
634 							aEntry += pParentWindow->aStrNotActive;
635 						aDocMenu.InsertItem( ++i, aEntry );
636 						if ( !bHiddenDoc && aName == aManualDoc )
637 							nPos = i;
638 					}
639 					pSh = SfxObjectShell::GetNext( *pSh );
640 				}
641 				//	"aktives Fenster"
642 				aDocMenu.InsertItem( ++i, pParentWindow->aStrActiveWin );
643 				if (!bHiddenDoc && !aManualDoc.Len())
644 					nPos = i;
645 				//	verstecktes Dokument
646 				if ( aHiddenTitle.Len() )
647 				{
648 					String aEntry = aHiddenTitle;
649 					aEntry += pParentWindow->aStrHidden;
650 					aDocMenu.InsertItem( ++i, aEntry );
651 					if (bHiddenDoc)
652 						nPos = i;
653 				}
654 				aDocMenu.CheckItem( nPos );
655 				aPop.InsertItem( 2, pParentWindow->GetStrDisplay() );
656 				aPop.SetPopupMenu( 2, &aDocMenu );
657 
658 				//	ausfuehren
659 
660 				aPop.Execute( this, rCEvt.GetMousePosPixel() );
661 
662 				if ( aDropMenu.WasHit() )				//	Drag-Drop Modus
663 				{
664 					sal_uInt16 nId = aDropMenu.GetSelected();
665 					if ( nId >= RID_DROPMODE_URL && nId <= RID_DROPMODE_COPY )
666 						pParentWindow->SetDropMode( nId - RID_DROPMODE_URL );
667 				}
668 				else if ( aDocMenu.WasHit() )			//	angezeigtes Dokument
669 				{
670 					sal_uInt16 nId = aDocMenu.GetSelected();
671 					String aName = aDocMenu.GetItemText(nId);
672 					SelectDoc( aName );
673 				}
674 			}
675 			break;
676 	}
677 
678 	if (!bDone)
679 		SvTreeListBox::Command(rCEvt);
680 }
681 
682 void __EXPORT ScContentTree::RequestHelp( const HelpEvent& rHEvt )
683 {
684 	sal_Bool bDone = sal_False;
685 	if( rHEvt.GetMode() & HELPMODE_QUICK )
686 	{
687 		Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
688 		SvLBoxEntry* pEntry = GetEntry( aPos );
689 		if ( pEntry )
690 		{
691 			sal_Bool bRet = sal_False;
692 			String aHelpText;
693 			SvLBoxEntry* pParent = GetParent(pEntry);
694 			if ( !pParent )									// Top-Level ?
695 			{
696 				aHelpText = String::CreateFromInt32( GetChildCount(pEntry) );
697 				aHelpText += ' ';
698 				aHelpText += GetEntryText(pEntry);
699 				bRet = sal_True;
700 			}
701 			else if ( pParent == pRootNodes[SC_CONTENT_NOTE] )
702 			{
703 				aHelpText = GetEntryText(pEntry);			// Notizen als Help-Text
704 				bRet = sal_True;
705 			}
706 			else if ( pParent == pRootNodes[SC_CONTENT_AREALINK] )
707 			{
708                 sal_uLong nIndex = GetChildIndex(pEntry);
709                 if( nIndex != SC_CONTENT_NOCHILD )
710                 {
711                     const ScAreaLink* pLink = GetLink(nIndex);
712                     if (pLink)
713                     {
714                         aHelpText = pLink->GetFile();           // Source-Datei als Help-Text
715                         bRet = sal_True;
716                     }
717                 }
718 			}
719 
720 			if (bRet)
721 			{
722 				SvLBoxTab* pTab;
723 				SvLBoxString* pItem = (SvLBoxString*)(GetItem( pEntry, aPos.X(), &pTab ));
724 				if( pItem )
725 				{
726 					aPos = GetEntryPosition( pEntry );
727 					aPos.X() = GetTabPos( pEntry, pTab );
728 					aPos = OutputToScreenPixel(aPos);
729 					Size aSize( pItem->GetSize( this, pEntry ) );
730 
731 					Rectangle aItemRect( aPos, aSize );
732 					Help::ShowQuickHelp( this, aItemRect, aHelpText );
733 					bDone = sal_True;
734 				}
735 			}
736 		}
737 	}
738 	if (!bDone)
739 		Window::RequestHelp( rHEvt );
740 }
741 
742 ScDocument* ScContentTree::GetSourceDocument()
743 {
744 	if (bHiddenDoc)
745 		return pHiddenDocument;
746 	else
747 	{
748 		ScDocShell* pSh = GetManualOrCurrent();
749 		if (pSh)
750 			return pSh->GetDocument();
751 
752 	}
753 	return NULL;
754 }
755 
756 //Solution: move along and draw "*" sign .
757 void ScContentTree::ObjectFresh( sal_uInt16 nType,SvLBoxEntry* pEntry )
758 {
759 	if ( bHiddenDoc && !pHiddenDocument )
760 		return;		// anderes Dokument angezeigt
761       if(nType ==SC_CONTENT_GRAPHIC||nType ==SC_CONTENT_OLEOBJECT||nType ==SC_CONTENT_DRAWING)
762       	{
763 		SetUpdateMode(sal_False);
764 		ClearType( nType );
765 		/*sal_uInt16 nId = OBJ_GRAF;
766 		switch( nType )
767 		{
768 			case SC_CONTENT_OLEOBJECT:
769 				nId = OBJ_OLE2;
770 				break;
771 			case SC_CONTENT_DRAWING:
772 				nId = OBJ_GRUP;
773 				break;
774 		}*/
775 		GetDrawNames( nType/*, nId*/ );
776 		if( !pEntry )
777 			ApplySettings();
778 		SetUpdateMode(sal_True);
779 		if( pEntry )
780 		{
781 			SvLBoxEntry* pParent = pRootNodes[nType];
782 			SvLBoxEntry* pBeginEntry = NULL;
783 			SvLBoxEntry* pOldEntry = NULL;
784 			if( pParent )
785 				pBeginEntry = FirstChild(pParent);
786 			while( pBeginEntry )
787 			{
788 				String aTempText( GetEntryText( pBeginEntry ) );
789 				 if( aTempText ==  sKeyString )
790 				 {
791 					pOldEntry = pBeginEntry;
792 					break;
793 				  }
794 				pBeginEntry =  Next( pBeginEntry );
795 			}
796 			if( pOldEntry )
797 			{
798 				Expand(pParent);
799 				Select( pOldEntry,sal_True);
800 			}
801 		}
802       	}
803 }
804 void ScContentTree::Refresh( sal_uInt16 nType )
805 {
806 	if ( bHiddenDoc && !pHiddenDocument )
807 		return;									// anderes Dokument angezeigt
808 
809 	//	wenn sich nichts geaendert hat, gleich abbrechen (gegen Geflacker)
810 
811 	if ( nType == SC_CONTENT_NOTE )
812 		if (!NoteStringsChanged())
813 			return;
814 	if ( nType == SC_CONTENT_GRAPHIC )
815 		if (!DrawNamesChanged(SC_CONTENT_GRAPHIC))
816 			return;
817 	if ( nType == SC_CONTENT_OLEOBJECT )
818 		if (!DrawNamesChanged(SC_CONTENT_OLEOBJECT))
819 			return;
820 	if ( nType == SC_CONTENT_DRAWING )
821 		if (!DrawNamesChanged(SC_CONTENT_DRAWING))
822 			return;
823 
824 	SetUpdateMode(sal_False);
825 
826 	ClearType( nType );
827 
828 	if ( !nType || nType == SC_CONTENT_TABLE )
829 		GetTableNames();
830 	if ( !nType || nType == SC_CONTENT_RANGENAME )
831 		GetAreaNames();
832 	if ( !nType || nType == SC_CONTENT_DBAREA )
833 		GetDbNames();
834 	if ( !nType || nType == SC_CONTENT_GRAPHIC )
835 		GetGraphicNames();
836 	if ( !nType || nType == SC_CONTENT_OLEOBJECT )
837 		GetOleNames();
838 	if ( !nType || nType == SC_CONTENT_DRAWING )
839 		GetDrawingNames();
840 	if ( !nType || nType == SC_CONTENT_NOTE )
841 		GetNoteStrings();
842 	if ( !nType || nType == SC_CONTENT_AREALINK )
843 		GetLinkNames();
844 
845     ApplySettings();
846 	SetUpdateMode(sal_True);
847 }
848 
849 void ScContentTree::GetTableNames()
850 {
851 	if ( nRootType && nRootType != SC_CONTENT_TABLE )		// ausgeblendet ?
852 		return;
853 
854 	ScDocument* pDoc = GetSourceDocument();
855 	if (!pDoc)
856 		return;
857 
858 	String aName;
859 	SCTAB nCount = pDoc->GetTableCount();
860 	for ( SCTAB i=0; i<nCount; i++ )
861 	{
862 		pDoc->GetName( i, aName );
863 		InsertContent( SC_CONTENT_TABLE, aName );
864 	}
865 }
866 
867 void ScContentTree::GetAreaNames()
868 {
869 	if ( nRootType && nRootType != SC_CONTENT_RANGENAME )		// ausgeblendet ?
870 		return;
871 
872 	ScDocument* pDoc = GetSourceDocument();
873 	if (!pDoc)
874 		return;
875 
876 	ScRangeName* pRangeNames = pDoc->GetRangeName();
877 	sal_uInt16 nCount = pRangeNames->GetCount();
878 	if ( nCount > 0 )
879 	{
880 		sal_uInt16 nValidCount = 0;
881 		ScRange aDummy;
882 		sal_uInt16 i;
883 		for ( i=0; i<nCount; i++ )
884 		{
885 			ScRangeData* pData = (*pRangeNames)[i];
886 			if (pData->IsValidReference(aDummy))
887 				nValidCount++;
888 		}
889 		if ( nValidCount )
890 		{
891 			ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ];
892 			sal_uInt16 j;
893 			for ( i=0, j=0; i<nCount; i++ )
894 			{
895 				ScRangeData* pData = (*pRangeNames)[i];
896 				if (pData->IsValidReference(aDummy))
897 					ppSortArray[j++] = pData;
898 			}
899 #ifndef ICC
900 			qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*),
901 				&ScRangeData_QsortNameCompare );
902 #else
903 			qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*),
904 				ICCQsortNameCompare );
905 #endif
906 			for ( j=0; j<nValidCount; j++ )
907 				InsertContent( SC_CONTENT_RANGENAME, ppSortArray[j]->GetName() );
908 			delete [] ppSortArray;
909 		}
910 	}
911 }
912 
913 void ScContentTree::GetDbNames()
914 {
915     if ( nRootType && nRootType != SC_CONTENT_DBAREA )		// ausgeblendet ?
916         return;
917 
918     ScDocument* pDoc = GetSourceDocument();
919     if (!pDoc)
920         return;
921 
922     ScDBCollection*	pDbNames = pDoc->GetDBCollection();
923     sal_uInt16 nCount = pDbNames->GetCount();
924     if ( nCount > 0 )
925     {
926         for ( sal_uInt16 i=0; i<nCount; i++ )
927         {
928             ScDBData* pData = (*pDbNames)[i];
929             String aStrName = pData->GetName();
930             if ( !pData->IsInternalUnnamed()
931                  && !pData->IsInternalForAutoFilter() )
932             {
933                 InsertContent( SC_CONTENT_DBAREA, aStrName );
934             }
935         }
936     }
937 }
938 
939 bool ScContentTree::IsPartOfType( sal_uInt16 nContentType, sal_uInt16 nObjIdentifier )  // static
940 {
941     bool bRet = false;
942     switch ( nContentType )
943     {
944         case SC_CONTENT_GRAPHIC:
945             bRet = ( nObjIdentifier == OBJ_GRAF );
946             break;
947         case SC_CONTENT_OLEOBJECT:
948             bRet = ( nObjIdentifier == OBJ_OLE2 );
949             break;
950         case SC_CONTENT_DRAWING:
951             bRet = ( nObjIdentifier != OBJ_GRAF && nObjIdentifier != OBJ_OLE2 );    // everything else
952             break;
953         default:
954             DBG_ERROR("unknown content type");
955     }
956     return bRet;
957 }
958 
959 void ScContentTree::GetDrawNames( sal_uInt16 nType )
960 {
961 	if ( nRootType && nRootType != nType )				// ausgeblendet ?
962 		return;
963 
964 	ScDocument* pDoc = GetSourceDocument();
965 	if (!pDoc)
966 		return;
967 
968 	// iterate in flat mode for groups
969 	SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
970 
971 	ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
972 	SfxObjectShell* pShell = pDoc->GetDocumentShell();
973 	if (pDrawLayer && pShell)
974 	{
975 		SCTAB nTabCount = pDoc->GetTableCount();
976 		for (SCTAB nTab=0; nTab<nTabCount; nTab++)
977 		{
978 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
979 			DBG_ASSERT(pPage,"Page ?");
980 			if (pPage)
981 			{
982 				SdrObjListIter aIter( *pPage, eIter );
983 				SdrObject* pObject = aIter.Next();
984 				while (pObject)
985 				{
986                     if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
987 					{
988 						String aName = ScDrawLayer::GetVisibleName( pObject );
989 						if (aName.Len())
990 						{
991 							if( bisInNavigatoeDlg )
992 							{
993 								if (nType >= SC_CONTENT_COUNT)
994 								{
995 									DBG_ERROR("ScContentTree::InsertContent mit falschem Typ");
996 									return;
997 					}
998 								SvLBoxEntry* pParent = pRootNodes[nType];
999 								if (pParent)
1000 								{
1001 									SvLBoxEntry* pChild=InsertEntry( aName, pParent );
1002 									if(pChild)
1003 											pChild->SetMarked( sal_False);
1004 									Window* pWindow=NULL;
1005 									ScTabViewShell* pScTabViewShell=NULL;
1006 									ScDrawView* pScDrawView=NULL;
1007 									ScNavigatorDlg* pScNavigatorDlg=NULL;
1008 									if(pChild)
1009 										 pWindow=(Window*)GetParent(pChild);
1010 									if(pWindow)
1011 											pScNavigatorDlg = (ScNavigatorDlg*)pWindow;
1012 									if (pScNavigatorDlg!=NULL)
1013 										  pScTabViewShell=pScNavigatorDlg->GetTabViewShell();
1014 									if(pScTabViewShell !=NULL)
1015 										  pScDrawView =pScTabViewShell->GetViewData()->GetScDrawView();
1016 									if(pScDrawView!=NULL)
1017 									 {
1018 										 sal_Bool bMarked =pScDrawView->GetObjectIsMarked(pObject);
1019 										 pChild->SetMarked( bMarked );
1020 									  }
1021 								}//end if parent
1022 								else
1023 									DBG_ERROR("InsertContent ohne Parent");
1024 							}
1025 						}
1026 					}
1027 					pObject = aIter.Next();
1028 				}
1029 			}
1030 		}
1031 	}
1032 }
1033 
1034 void ScContentTree::GetGraphicNames()
1035 {
1036 	GetDrawNames( SC_CONTENT_GRAPHIC );
1037 }
1038 
1039 void ScContentTree::GetOleNames()
1040 {
1041 	GetDrawNames( SC_CONTENT_OLEOBJECT );
1042 }
1043 
1044 void ScContentTree::GetDrawingNames()
1045 {
1046 	GetDrawNames( SC_CONTENT_DRAWING );
1047 }
1048 
1049 void ScContentTree::GetLinkNames()
1050 {
1051 	if ( nRootType && nRootType != SC_CONTENT_AREALINK )				// ausgeblendet ?
1052 		return;
1053 
1054 	ScDocument* pDoc = GetSourceDocument();
1055 	if (!pDoc)
1056 		return;
1057 
1058 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1059 	DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?");
1060 	const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1061 	sal_uInt16 nCount = rLinks.Count();
1062 	for (sal_uInt16 i=0; i<nCount; i++)
1063 	{
1064 		::sfx2::SvBaseLink* pBase = *rLinks[i];
1065 		if (pBase->ISA(ScAreaLink))
1066 			InsertContent( SC_CONTENT_AREALINK, ((ScAreaLink*)pBase)->GetSource() );
1067 
1068 			//	in der Liste die Namen der Quellbereiche
1069 	}
1070 }
1071 
1072 const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex )
1073 {
1074 	ScDocument* pDoc = GetSourceDocument();
1075 	if (!pDoc)
1076 		return NULL;
1077 
1078 	sal_uLong nFound = 0;
1079 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1080 	DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?");
1081 	const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1082 	sal_uInt16 nCount = rLinks.Count();
1083 	for (sal_uInt16 i=0; i<nCount; i++)
1084 	{
1085 		::sfx2::SvBaseLink* pBase = *rLinks[i];
1086 		if (pBase->ISA(ScAreaLink))
1087 		{
1088 			if (nFound == nIndex)
1089 				return (const ScAreaLink*) pBase;
1090 			++nFound;
1091 		}
1092 	}
1093 
1094 	DBG_ERROR("Link nicht gefunden");
1095 	return NULL;
1096 }
1097 
1098 String lcl_NoteString( const ScPostIt& rNote )
1099 {
1100     String aText = rNote.GetText();
1101 	xub_StrLen nAt;
1102     while ( (nAt = aText.Search( '\n' )) != STRING_NOTFOUND )
1103 		aText.SetChar( nAt, ' ' );
1104 	return aText;
1105 }
1106 
1107 void ScContentTree::GetNoteStrings()
1108 {
1109 	if ( nRootType && nRootType != SC_CONTENT_NOTE )		// ausgeblendet ?
1110 		return;
1111 
1112 	ScDocument* pDoc = GetSourceDocument();
1113 	if (!pDoc)
1114 		return;
1115 
1116 	SCTAB nTabCount = pDoc->GetTableCount();
1117 	for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1118 	{
1119 		ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab );
1120         for( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
1121             if( const ScPostIt* pNote = pCell->GetNote() )
1122                 InsertContent( SC_CONTENT_NOTE, lcl_NoteString( *pNote ) );
1123 	}
1124 }
1125 
1126 ScAddress ScContentTree::GetNotePos( sal_uLong nIndex )
1127 {
1128 	ScDocument* pDoc = GetSourceDocument();
1129 	if (!pDoc)
1130 		return ScAddress();
1131 
1132 	sal_uLong nFound = 0;
1133 	SCTAB nTabCount = pDoc->GetTableCount();
1134 	for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1135 	{
1136 		ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab );
1137 		ScBaseCell* pCell = aIter.GetFirst();
1138 		while (pCell)
1139 		{
1140             if( pCell->HasNote() )
1141 			{
1142 				if (nFound == nIndex)
1143 					return ScAddress( aIter.GetCol(), aIter.GetRow(), nTab );	// gefunden
1144 				++nFound;
1145 			}
1146 			pCell = aIter.GetNext();
1147 		}
1148 	}
1149 
1150 	DBG_ERROR("Notiz nicht gefunden");
1151 	return ScAddress();
1152 }
1153 
1154 sal_Bool ScContentTree::NoteStringsChanged()
1155 {
1156 	ScDocument* pDoc = GetSourceDocument();
1157 	if (!pDoc)
1158 		return sal_False;
1159 
1160 	SvLBoxEntry* pParent = pRootNodes[SC_CONTENT_NOTE];
1161 	if (!pParent)
1162 		return sal_False;
1163 
1164 	SvLBoxEntry* pEntry = FirstChild( pParent );
1165 
1166 	sal_Bool bEqual = sal_True;
1167 	SCTAB nTabCount = pDoc->GetTableCount();
1168 	for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++)
1169 	{
1170 		ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab );
1171 		ScBaseCell* pCell = aIter.GetFirst();
1172 		while (pCell && bEqual)
1173 		{
1174             if( const ScPostIt* pNote = pCell->GetNote() )
1175 			{
1176 				if ( !pEntry )
1177 					bEqual = sal_False;
1178 				else
1179 				{
1180                     if ( lcl_NoteString( *pNote ) != GetEntryText(pEntry) )
1181 						bEqual = sal_False;
1182 
1183 					pEntry = NextSibling( pEntry );
1184 				}
1185 			}
1186 			pCell = aIter.GetNext();
1187 		}
1188 	}
1189 
1190 	if ( pEntry )
1191 		bEqual = sal_False;				// kommt noch was
1192 
1193 	return !bEqual;
1194 }
1195 
1196 sal_Bool ScContentTree::DrawNamesChanged( sal_uInt16 nType )
1197 {
1198 	ScDocument* pDoc = GetSourceDocument();
1199 	if (!pDoc)
1200 		return sal_False;
1201 
1202 	SvLBoxEntry* pParent = pRootNodes[nType];
1203 	if (!pParent)
1204 		return sal_False;
1205 
1206 	SvLBoxEntry* pEntry = FirstChild( pParent );
1207 
1208 	// iterate in flat mode for groups
1209 	SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
1210 
1211 	sal_Bool bEqual = sal_True;
1212 	ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1213 	SfxObjectShell* pShell = pDoc->GetDocumentShell();
1214 	if (pDrawLayer && pShell)
1215 	{
1216 		SCTAB nTabCount = pDoc->GetTableCount();
1217 		for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++)
1218 		{
1219 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
1220 			DBG_ASSERT(pPage,"Page ?");
1221 			if (pPage)
1222 			{
1223 				SdrObjListIter aIter( *pPage, eIter );
1224 				SdrObject* pObject = aIter.Next();
1225 				while (pObject && bEqual)
1226 				{
1227                     if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
1228 					{
1229 						if ( !pEntry )
1230 							bEqual = sal_False;
1231 						else
1232 						{
1233 							if ( ScDrawLayer::GetVisibleName( pObject ) != GetEntryText(pEntry) )
1234 								bEqual = sal_False;
1235 
1236 							pEntry = NextSibling( pEntry );
1237 						}
1238 					}
1239 					pObject = aIter.Next();
1240 				}
1241 			}
1242 		}
1243 	}
1244 
1245 	if ( pEntry )
1246 		bEqual = sal_False;				// kommt noch was
1247 
1248 	return !bEqual;
1249 }
1250 
1251 sal_Bool lcl_GetRange( ScDocument* pDoc, sal_uInt16 nType, const String& rName, ScRange& rRange )
1252 {
1253 	sal_Bool bFound = sal_False;
1254 	sal_uInt16 nPos;
1255 
1256 	if ( nType == SC_CONTENT_RANGENAME )
1257 	{
1258 		ScRangeName* pList = pDoc->GetRangeName();
1259 		if (pList)
1260 			if (pList->SearchName( rName, nPos ))
1261 				if ( (*pList)[nPos]->IsValidReference( rRange ) )
1262 					bFound = sal_True;
1263 	}
1264 	else if ( nType == SC_CONTENT_DBAREA )
1265 	{
1266 		ScDBCollection*	pList = pDoc->GetDBCollection();
1267 		if (pList)
1268 			if (pList->SearchName( rName, nPos ))
1269 			{
1270                 SCTAB nTab;
1271                 SCCOL nCol1, nCol2;
1272                 SCROW nRow1, nRow2;
1273                 (*pList)[nPos]->GetArea(nTab,nCol1,nRow1,nCol2,nRow2);
1274 				rRange = ScRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
1275 				bFound = sal_True;
1276 			}
1277 	}
1278 
1279 	return bFound;
1280 }
1281 
1282 void lcl_DoDragObject( ScDocShell* pSrcShell, const String& rName, sal_uInt16 nType, Window* pWin )
1283 {
1284 	ScDocument* pSrcDoc = pSrcShell->GetDocument();
1285 	ScDrawLayer* pModel = pSrcDoc->GetDrawLayer();
1286 	if (pModel)
1287 	{
1288 		sal_Bool bOle = ( nType == SC_CONTENT_OLEOBJECT );
1289 		sal_Bool bGraf = ( nType == SC_CONTENT_GRAPHIC );
1290         sal_uInt16 nDrawId = sal::static_int_cast<sal_uInt16>( bOle ? OBJ_OLE2 : ( bGraf ? OBJ_GRAF : OBJ_GRUP ) );
1291 		SCTAB nTab = 0;
1292 		SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab );
1293 		if (pObject)
1294 		{
1295 			SdrView aEditView( pModel );
1296 			aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab));
1297 			SdrPageView* pPV = aEditView.GetSdrPageView();
1298 			aEditView.MarkObj(pObject, pPV);
1299 
1300 			SdrModel* pDragModel = aEditView.GetAllMarkedModel();
1301 
1302 			TransferableObjectDescriptor aObjDesc;
1303 			pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1304 			aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1305 			// maSize is set in ScDrawTransferObj ctor
1306 
1307 			ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pDragModel, pSrcShell, aObjDesc );
1308 			uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1309 
1310 			pTransferObj->SetDragSourceObj( pObject, nTab );
1311 			pTransferObj->SetDragSourceFlags( SC_DROP_NAVIGATOR );
1312 
1313 			SC_MOD()->SetDragObject( NULL, pTransferObj );
1314 			pWin->ReleaseMouse();
1315 			pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1316 		}
1317 	}
1318 }
1319 
1320 void lcl_DoDragCells( ScDocShell* pSrcShell, const ScRange& rRange, sal_uInt16 nFlags, Window* pWin )
1321 {
1322 	ScMarkData aMark;
1323 	aMark.SelectTable( rRange.aStart.Tab(), sal_True );
1324 	aMark.SetMarkArea( rRange );
1325 
1326 	ScDocument* pSrcDoc = pSrcShell->GetDocument();
1327 	if ( !pSrcDoc->HasSelectedBlockMatrixFragment( rRange.aStart.Col(), rRange.aStart.Row(),
1328 												   rRange.aEnd.Col(),   rRange.aEnd.Row(),
1329 												   aMark ) )
1330 	{
1331 		ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
1332         ScClipParam aClipParam(rRange, false);
1333         pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aMark);
1334 		// pClipDoc->ExtendMerge( rRange, sal_True );
1335 
1336 		TransferableObjectDescriptor aObjDesc;
1337 		pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1338 		aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1339 		// maSize is set in ScTransferObj ctor
1340 
1341 		ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
1342 		uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1343 
1344 		pTransferObj->SetDragSource( pSrcShell, aMark );
1345 		pTransferObj->SetDragSourceFlags( nFlags );
1346 
1347 		SC_MOD()->SetDragObject( pTransferObj, NULL );		// for internal D&D
1348 		pWin->ReleaseMouse();
1349 		pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1350 	}
1351 }
1352 
1353 void ScContentTree::DoDrag()
1354 {
1355 	ScDocumentLoader* pDocLoader = NULL;
1356 	bIsInDrag = sal_True;
1357 
1358 	ScModule* pScMod = SC_MOD();
1359 
1360     sal_uInt16 nType;
1361     sal_uLong nChild;
1362     SvLBoxEntry* pEntry = GetCurEntry();
1363     GetEntryIndexes( nType, nChild, pEntry );
1364 
1365     if( pEntry &&
1366         (nChild != SC_CONTENT_NOCHILD) &&
1367         (nType != SC_CONTENT_ROOT) &&
1368         (nType != SC_CONTENT_NOTE) &&
1369         (nType != SC_CONTENT_AREALINK) )
1370     {
1371         String aText( GetEntryText( pEntry ) );
1372 
1373 		ScDocument* pLocalDoc = NULL;					// fuer URL-Drop
1374 		String aDocName;
1375 		if (bHiddenDoc)
1376 			aDocName = aHiddenName;
1377 		else
1378 		{
1379 			ScDocShell* pDocSh = GetManualOrCurrent();
1380 			if (pDocSh)
1381 			{
1382 				if (pDocSh->HasName())
1383 					aDocName = pDocSh->GetMedium()->GetName();
1384 				else
1385 					pLocalDoc = pDocSh->GetDocument();		// Drop nur in dieses Dokument
1386 			}
1387 		}
1388 
1389 		sal_Bool bDoLinkTrans = sal_False;		// use ScLinkTransferObj
1390 		String aLinkURL;				// for ScLinkTransferObj
1391 		String aLinkText;
1392 
1393 		sal_uInt16 nDropMode = pParentWindow->GetDropMode();
1394 		switch ( nDropMode )
1395 		{
1396 			case SC_DROPMODE_URL:
1397 				{
1398 					String aUrl = aDocName;
1399 					aUrl += '#';
1400 					aUrl += aText;
1401 
1402 					pScMod->SetDragJump( pLocalDoc, aUrl, aText );
1403 
1404 					if (aDocName.Len())
1405 					{
1406 						//	provide URL to outside only if the document has a name
1407 						//	(without name, only internal D&D via SetDragJump)
1408 
1409 						aLinkURL = aUrl;
1410 						aLinkText = aText;
1411 					}
1412 					bDoLinkTrans = sal_True;
1413 				}
1414 				break;
1415 			case SC_DROPMODE_LINK:
1416 				{
1417 					if ( aDocName.Len() )			// link only to named documents
1418 					{
1419 						// for internal D&D, set flag to insert a link
1420 
1421 						switch ( nType )
1422 						{
1423 							case SC_CONTENT_TABLE:
1424 								pScMod->SetDragLink( aDocName, aText, EMPTY_STRING );
1425 								bDoLinkTrans = sal_True;
1426 								break;
1427 							case SC_CONTENT_RANGENAME:
1428 							case SC_CONTENT_DBAREA:
1429 								pScMod->SetDragLink( aDocName, EMPTY_STRING, aText );
1430 								bDoLinkTrans = sal_True;
1431 								break;
1432 
1433 							// other types cannot be linked
1434 						}
1435 					}
1436 				}
1437 				break;
1438 			case SC_DROPMODE_COPY:
1439 				{
1440 					ScDocShell* pSrcShell = NULL;
1441 					if ( bHiddenDoc )
1442 					{
1443 						String aFilter, aOptions;
1444 						pDocLoader = new ScDocumentLoader( aHiddenName, aFilter, aOptions );
1445 						if (!pDocLoader->IsError())
1446 							pSrcShell = pDocLoader->GetDocShell();
1447 					}
1448 					else
1449 						pSrcShell = GetManualOrCurrent();
1450 
1451 					if ( pSrcShell )
1452 					{
1453 						ScDocument* pSrcDoc = pSrcShell->GetDocument();
1454 						if ( nType == SC_CONTENT_RANGENAME || nType == SC_CONTENT_DBAREA )
1455 						{
1456 							ScRange aRange;
1457 							if ( lcl_GetRange( pSrcDoc, nType, aText, aRange ) )
1458 							{
1459 								lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR, this );
1460 							}
1461 						}
1462 						else if ( nType == SC_CONTENT_TABLE )
1463 						{
1464 							SCTAB nTab;
1465 							if ( pSrcDoc->GetTable( aText, nTab ) )
1466 							{
1467 								ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab );
1468 								lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR | SC_DROP_TABLE, this );
1469 							}
1470 						}
1471 						else if ( nType == SC_CONTENT_GRAPHIC || nType == SC_CONTENT_OLEOBJECT ||
1472 									nType == SC_CONTENT_DRAWING )
1473 						{
1474 							lcl_DoDragObject( pSrcShell, aText, nType, this );
1475 
1476 							//	in ExecuteDrag kann der Navigator geloescht worden sein
1477 							//	-> nicht mehr auf Member zugreifen !!!
1478 						}
1479 					}
1480 				}
1481 				break;
1482 		}
1483 
1484 		if (bDoLinkTrans)
1485 		{
1486 			ScLinkTransferObj* pTransferObj = new ScLinkTransferObj;
1487 			uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1488 
1489 			if ( aLinkURL.Len() )
1490 				pTransferObj->SetLinkURL( aLinkURL, aLinkText );
1491 
1492 			//	SetDragJump / SetDragLink has been done above
1493 
1494 			ReleaseMouse();
1495 			pTransferObj->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1496 		}
1497 	}
1498 
1499 	bIsInDrag = sal_False;				// static Member
1500 
1501 	delete pDocLoader;				// falls Dokument zum Draggen geladen wurde
1502 }
1503 
1504 IMPL_STATIC_LINK(ScContentTree, ExecDragHdl, void*, EMPTYARG)
1505 {
1506 	//	als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der
1507 	//	Navigator geloescht werden darf
1508 
1509 	pThis->DoDrag();
1510 	return 0;
1511 }
1512 
1513 //UNUSED2008-05  void ScContentTree::AdjustTitle()
1514 //UNUSED2008-05  {
1515 //UNUSED2008-05      String aTitle = pParentWindow->aTitleBase;
1516 //UNUSED2008-05      if (bHiddenDoc)
1517 //UNUSED2008-05      {
1518 //UNUSED2008-05          aTitle.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " ));
1519 //UNUSED2008-05          aTitle += aHiddenTitle;
1520 //UNUSED2008-05      }
1521 //UNUSED2008-05      pParentWindow->SetText(aTitle);
1522 //UNUSED2008-05  }
1523 
1524 sal_Bool ScContentTree::LoadFile( const String& rUrl )
1525 {
1526 	String aDocName = rUrl;
1527 	xub_StrLen nPos = aDocName.Search('#');
1528 	if ( nPos != STRING_NOTFOUND )
1529 		aDocName.Erase(nPos);			// nur der Name, ohne #...
1530 
1531 	sal_Bool bReturn = sal_False;
1532 	String aFilter, aOptions;
1533 	ScDocumentLoader aLoader( aDocName, aFilter, aOptions );
1534 	if ( !aLoader.IsError() )
1535 	{
1536 		bHiddenDoc = sal_True;
1537 		aHiddenName = aDocName;
1538 		aHiddenTitle = aLoader.GetTitle();
1539 		pHiddenDocument = aLoader.GetDocument();
1540 
1541 		Refresh();						// Inhalte aus geladenem Dokument holen
1542 
1543 		pHiddenDocument = NULL;
1544 //		AdjustTitle();
1545 
1546 		pParentWindow->GetDocNames( &aHiddenTitle );			// Liste fuellen
1547 	}
1548 	else
1549 		Sound::Beep();			// Fehler beim Laden
1550 
1551 	//	Dokument wird im dtor von ScDocumentLoader wieder geschlossen
1552 
1553 	return bReturn;
1554 }
1555 
1556 void ScContentTree::InitWindowBits( sal_Bool bButtons )
1557 {
1558 	WinBits nFlags = GetStyle()|WB_CLIPCHILDREN|WB_HSCROLL;
1559 	if (bButtons)
1560 		nFlags |= WB_HASBUTTONS|WB_HASBUTTONSATROOT;
1561 
1562 	SetStyle( nFlags );
1563 }
1564 
1565 void ScContentTree::SetRootType( sal_uInt16 nNew )
1566 {
1567 	if ( nNew != nRootType )
1568 	{
1569 		nRootType = nNew;
1570 		InitWindowBits( nNew == 0 );
1571 		Refresh();
1572 
1573 		ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg();
1574 		rCfg.SetRootType( nRootType );
1575 	}
1576 }
1577 
1578 void ScContentTree::ToggleRoot()		// nach Selektion
1579 {
1580 	sal_uInt16 nNew = SC_CONTENT_ROOT;
1581 	if ( nRootType == SC_CONTENT_ROOT )
1582 	{
1583 		SvLBoxEntry* pEntry = GetCurEntry();
1584 		if (pEntry)
1585 		{
1586 			SvLBoxEntry* pParent = GetParent(pEntry);
1587 			for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++)
1588 				if ( pEntry == pRootNodes[i] || pParent == pRootNodes[i] )
1589 					nNew = i;
1590 		}
1591 	}
1592 
1593 	SetRootType( nNew );
1594 }
1595 
1596 void ScContentTree::ResetManualDoc()
1597 {
1598 	aManualDoc.Erase();
1599 	bHiddenDoc = sal_False;
1600 
1601 	ActiveDocChanged();
1602 }
1603 
1604 void ScContentTree::ActiveDocChanged()
1605 {
1606 	if ( !bHiddenDoc && !aManualDoc.Len() )
1607 		Refresh();									// Inhalte nur wenn automatisch
1608 
1609 		//	Listbox muss immer geupdated werden, wegen aktiv-Flag
1610 
1611 	String aCurrent;
1612 	if ( bHiddenDoc )
1613 		aCurrent = aHiddenTitle;
1614 	else
1615 	{
1616 		ScDocShell* pSh = GetManualOrCurrent();
1617 		if (pSh)
1618 			aCurrent = pSh->GetTitle();
1619 		else
1620 		{
1621 			//	eingestelltes Dokument existiert nicht mehr
1622 
1623 			aManualDoc.Erase();				// wieder automatisch
1624 			Refresh();
1625 			pSh = GetManualOrCurrent();		// sollte jetzt aktives sein
1626 			if (pSh)
1627 				aCurrent = pSh->GetTitle();
1628 		}
1629 	}
1630 	pParentWindow->GetDocNames( &aCurrent );		// selektieren
1631 }
1632 
1633 void ScContentTree::SetManualDoc(const String& rName)
1634 {
1635 	aManualDoc = rName;
1636 	if (!bHiddenDoc)
1637 	{
1638 		Refresh();
1639 		pParentWindow->GetDocNames( &aManualDoc );		// selektieren
1640 	}
1641 }
1642 
1643 void ScContentTree::SelectDoc(const String& rName)		// rName wie im Menue/Listbox angezeigt
1644 {
1645 	if ( rName == pParentWindow->aStrActiveWin )
1646 	{
1647 		ResetManualDoc();
1648 		return;
1649 	}
1650 
1651 	//	"aktiv" oder "inaktiv" weglassen
1652 
1653 	String aRealName = rName;
1654 	xub_StrLen nLen = rName.Len();
1655 	xub_StrLen nActiveStart = nLen - pParentWindow->aStrActive.Len();
1656 	if ( rName.Copy( nActiveStart ) == pParentWindow->aStrActive )
1657 		aRealName = rName.Copy( 0, nActiveStart );
1658 	xub_StrLen nNotActiveStart = nLen - pParentWindow->aStrNotActive.Len();
1659 	if ( rName.Copy( nNotActiveStart ) == pParentWindow->aStrNotActive )
1660 		aRealName = rName.Copy( 0, nNotActiveStart );
1661 
1662 	//
1663 
1664 	sal_Bool bLoaded = sal_False;
1665 
1666 		// ist es ein normal geladenes Doc ?
1667 
1668 	SfxObjectShell* pSh = SfxObjectShell::GetFirst();
1669 	while ( pSh && !bLoaded )
1670 	{
1671 		if ( pSh->ISA(ScDocShell) )
1672 			if ( pSh->GetTitle() == aRealName )
1673 				bLoaded = sal_True;
1674 		pSh = SfxObjectShell::GetNext( *pSh );
1675 	}
1676 
1677 	if (bLoaded)
1678 	{
1679 		bHiddenDoc = sal_False;
1680 		SetManualDoc(aRealName);
1681 	}
1682 	else if (aHiddenTitle.Len())				// verstecktes ausgewaehlt
1683 	{
1684 		if (!bHiddenDoc)
1685 			LoadFile(aHiddenName);
1686 	}
1687 	else
1688 	{
1689 		DBG_ERROR("SelectDoc: nicht gefunden");
1690 	}
1691 }
1692 
1693 void ScContentTree::ApplySettings()
1694 {
1695     const ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings();
1696     if( pSettings )
1697     {
1698         sal_uInt16 nRootSel = pSettings->GetRootSelected();
1699         sal_uLong nChildSel = pSettings->GetChildSelected();
1700 
1701         for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1702         {
1703             if( pRootNodes[ nEntry ] )
1704             {
1705                 // expand
1706                 sal_Bool bExp = pSettings->IsExpanded( nEntry );
1707                 if( bExp != IsExpanded( pRootNodes[ nEntry ] ) )
1708                 {
1709                     if( bExp )
1710                         Expand( pRootNodes[ nEntry ] );
1711                     else
1712                         Collapse( pRootNodes[ nEntry ] );
1713                 }
1714 
1715                 // select
1716                 if( nRootSel == nEntry )
1717                 {
1718                     SvLBoxEntry* pEntry = NULL;
1719                     if( bExp && (nChildSel != SC_CONTENT_NOCHILD) )
1720                         pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel );
1721                     Select( pEntry ? pEntry : pRootNodes[ nEntry ] );
1722                 }
1723             }
1724         }
1725     }
1726 }
1727 
1728 void ScContentTree::StoreSettings() const
1729 {
1730     ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings();
1731     if( pSettings )
1732     {
1733         for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1734         {
1735             sal_Bool bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] );
1736             pSettings->SetExpanded( nEntry, bExp );
1737         }
1738         sal_uInt16 nRoot;
1739         sal_uLong nChild;
1740         GetEntryIndexes( nRoot, nChild, GetCurEntry() );
1741         pSettings->SetRootSelected( nRoot );
1742         pSettings->SetChildSelected( nChild );
1743     }
1744 }
1745 
1746 class ScContentLBoxString : public SvLBoxString
1747 {
1748 public:
1749 	ScContentLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags,
1750 		const String& rStr ) : SvLBoxString(pEntry,nFlags,rStr)	{}
1751 
1752 	virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
1753 		SvLBoxEntry* pEntry);
1754 };
1755 void ScContentTree::InitEntry(SvLBoxEntry* pEntry,
1756 		const XubString& rStr ,const Image& rImg1,const Image& rImg2, SvLBoxButtonKind eButtonKind)
1757 {
1758 	sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2"
1759 	SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
1760 	SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
1761 	ScContentLBoxString* pStr = new ScContentLBoxString( pEntry, 0, pCol->GetText() );
1762 	pEntry->ReplaceItem( pStr, nColToHilite );
1763 }
1764 void ScContentLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
1765 	SvLBoxEntry* pEntry )
1766 {
1767 	// IA2 CWS. MT: Removed for now (also in SvLBoxEntry) - only used in Sw/Sd/ScContentLBoxString, they should decide if they need this
1768 	/*
1769 	if (pEntry->IsMarked())
1770 	{
1771 			rDev.DrawText( rPos, GetText() );
1772 			XubString str;
1773 			str = XubString::CreateFromAscii("*");
1774 			Point rPosStar(rPos.X()-6,rPos.Y());
1775 			Font aOldFont( rDev.GetFont());
1776 			Font aFont(aOldFont);
1777 			Color aCol( aOldFont.GetColor() );
1778 			aCol.DecreaseLuminance( 200 );
1779 			aFont.SetColor( aCol );
1780 			rDev.SetFont( aFont );
1781 			rDev.DrawText( rPosStar, str);
1782 			rDev.SetFont( aOldFont );
1783 	}
1784 	else
1785 	*/
1786 		SvLBoxString::Paint( rPos, rDev, nFlags, pEntry);
1787 }
1788 //
1789 //------------------------------------------------------------------------
1790 //
1791 
1792 
1793 
1794 
1795 
1796