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