xref: /AOO41X/main/sc/source/ui/navipi/content.cxx (revision d3553c6b68aef63d45d1605bdabbc6fea7b9e42f)
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         for ( sal_uInt16 i=0; i<nCount; i++ )
943         {
944             ScDBData* pData = (*pDbNames)[i];
945             String aStrName = pData->GetName();
946             if ( !pData->IsInternalUnnamed()
947                  && !pData->IsInternalForAutoFilter() )
948             {
949                 InsertContent( SC_CONTENT_DBAREA, aStrName );
950             }
951         }
952     }
953 }
954 
955 bool ScContentTree::IsPartOfType( sal_uInt16 nContentType, sal_uInt16 nObjIdentifier )  // static
956 {
957     bool bRet = false;
958     switch ( nContentType )
959     {
960         case SC_CONTENT_GRAPHIC:
961             bRet = ( nObjIdentifier == OBJ_GRAF );
962             break;
963         case SC_CONTENT_OLEOBJECT:
964             bRet = ( nObjIdentifier == OBJ_OLE2 );
965             break;
966         case SC_CONTENT_DRAWING:
967             bRet = ( nObjIdentifier != OBJ_GRAF && nObjIdentifier != OBJ_OLE2 );    // everything else
968             break;
969         default:
970             DBG_ERROR("unknown content type");
971     }
972     return bRet;
973 }
974 
975 void ScContentTree::GetDrawNames( sal_uInt16 nType )
976 {
977 	if ( nRootType && nRootType != nType )				// ausgeblendet ?
978 		return;
979 
980 	ScDocument* pDoc = GetSourceDocument();
981 	if (!pDoc)
982 		return;
983 
984 	// iterate in flat mode for groups
985 	SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
986 
987 	ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
988 	SfxObjectShell* pShell = pDoc->GetDocumentShell();
989 	if (pDrawLayer && pShell)
990 	{
991 		SCTAB nTabCount = pDoc->GetTableCount();
992 		for (SCTAB nTab=0; nTab<nTabCount; nTab++)
993 		{
994 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
995 			DBG_ASSERT(pPage,"Page ?");
996 			if (pPage)
997 			{
998 				SdrObjListIter aIter( *pPage, eIter );
999 				SdrObject* pObject = aIter.Next();
1000 				while (pObject)
1001 				{
1002                     if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
1003 					{
1004 						String aName = ScDrawLayer::GetVisibleName( pObject );
1005 						if (aName.Len())
1006 						{
1007 							//IAccessibility2 Implementation 2009-----
1008 							//InsertContent( nType, aName );
1009 							if( bisInNavigatoeDlg )
1010 							{
1011 								if (nType >= SC_CONTENT_COUNT)
1012 								{
1013 									DBG_ERROR("ScContentTree::InsertContent mit falschem Typ");
1014 									return;
1015 					}
1016 								SvLBoxEntry* pParent = pRootNodes[nType];
1017 								if (pParent)
1018 								{
1019 									SvLBoxEntry* pChild=InsertEntry( aName, pParent );
1020 									if(pChild)
1021 											pChild->SetMarked( sal_False);
1022 									Window* pWindow=NULL;
1023 									ScTabViewShell* pScTabViewShell=NULL;
1024 									ScDrawView* pScDrawView=NULL;
1025 									ScNavigatorDlg* pScNavigatorDlg=NULL;
1026 									if(pChild)
1027 										 pWindow=(Window*)GetParent(pChild);
1028 									if(pWindow)
1029 											pScNavigatorDlg = (ScNavigatorDlg*)pWindow;
1030 									if (pScNavigatorDlg!=NULL)
1031 										  pScTabViewShell=pScNavigatorDlg->GetTabViewShell();
1032 									if(pScTabViewShell !=NULL)
1033 										  pScDrawView =pScTabViewShell->GetViewData()->GetScDrawView();
1034 									if(pScDrawView!=NULL)
1035 									 {
1036 										 sal_Bool bMarked =pScDrawView->GetObjectIsMarked(pObject);
1037 										 pChild->SetMarked( bMarked );
1038 									  }
1039 								}//end if parent
1040 								else
1041 									DBG_ERROR("InsertContent ohne Parent");
1042 							}
1043 						}
1044 					}
1045 					//-----IAccessibility2 Implementation 2009
1046 					pObject = aIter.Next();
1047 				}
1048 			}
1049 		}
1050 	}
1051 }
1052 
1053 void ScContentTree::GetGraphicNames()
1054 {
1055 	GetDrawNames( SC_CONTENT_GRAPHIC );
1056 }
1057 
1058 void ScContentTree::GetOleNames()
1059 {
1060 	GetDrawNames( SC_CONTENT_OLEOBJECT );
1061 }
1062 
1063 void ScContentTree::GetDrawingNames()
1064 {
1065 	GetDrawNames( SC_CONTENT_DRAWING );
1066 }
1067 
1068 void ScContentTree::GetLinkNames()
1069 {
1070 	if ( nRootType && nRootType != SC_CONTENT_AREALINK )				// ausgeblendet ?
1071 		return;
1072 
1073 	ScDocument* pDoc = GetSourceDocument();
1074 	if (!pDoc)
1075 		return;
1076 
1077 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1078 	DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?");
1079 	const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1080 	sal_uInt16 nCount = rLinks.Count();
1081 	for (sal_uInt16 i=0; i<nCount; i++)
1082 	{
1083 		::sfx2::SvBaseLink* pBase = *rLinks[i];
1084 		if (pBase->ISA(ScAreaLink))
1085 			InsertContent( SC_CONTENT_AREALINK, ((ScAreaLink*)pBase)->GetSource() );
1086 
1087 			//	in der Liste die Namen der Quellbereiche
1088 	}
1089 }
1090 
1091 const ScAreaLink* ScContentTree::GetLink( sal_uLong nIndex )
1092 {
1093 	ScDocument* pDoc = GetSourceDocument();
1094 	if (!pDoc)
1095 		return NULL;
1096 
1097 	sal_uLong nFound = 0;
1098 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1099 	DBG_ASSERT(pLinkManager, "kein LinkManager am Dokument?");
1100 	const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1101 	sal_uInt16 nCount = rLinks.Count();
1102 	for (sal_uInt16 i=0; i<nCount; i++)
1103 	{
1104 		::sfx2::SvBaseLink* pBase = *rLinks[i];
1105 		if (pBase->ISA(ScAreaLink))
1106 		{
1107 			if (nFound == nIndex)
1108 				return (const ScAreaLink*) pBase;
1109 			++nFound;
1110 		}
1111 	}
1112 
1113 	DBG_ERROR("Link nicht gefunden");
1114 	return NULL;
1115 }
1116 
1117 String lcl_NoteString( const ScPostIt& rNote )
1118 {
1119     String aText = rNote.GetText();
1120 	xub_StrLen nAt;
1121     while ( (nAt = aText.Search( '\n' )) != STRING_NOTFOUND )
1122 		aText.SetChar( nAt, ' ' );
1123 	return aText;
1124 }
1125 
1126 void ScContentTree::GetNoteStrings()
1127 {
1128 	if ( nRootType && nRootType != SC_CONTENT_NOTE )		// ausgeblendet ?
1129 		return;
1130 
1131 	ScDocument* pDoc = GetSourceDocument();
1132 	if (!pDoc)
1133 		return;
1134 
1135 	SCTAB nTabCount = pDoc->GetTableCount();
1136 	for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1137 	{
1138 		ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab );
1139         for( ScBaseCell* pCell = aIter.GetFirst(); pCell; pCell = aIter.GetNext() )
1140             if( const ScPostIt* pNote = pCell->GetNote() )
1141                 InsertContent( SC_CONTENT_NOTE, lcl_NoteString( *pNote ) );
1142 	}
1143 }
1144 
1145 ScAddress ScContentTree::GetNotePos( sal_uLong nIndex )
1146 {
1147 	ScDocument* pDoc = GetSourceDocument();
1148 	if (!pDoc)
1149 		return ScAddress();
1150 
1151 	sal_uLong nFound = 0;
1152 	SCTAB nTabCount = pDoc->GetTableCount();
1153 	for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1154 	{
1155 		ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab );
1156 		ScBaseCell* pCell = aIter.GetFirst();
1157 		while (pCell)
1158 		{
1159             if( pCell->HasNote() )
1160 			{
1161 				if (nFound == nIndex)
1162 					return ScAddress( aIter.GetCol(), aIter.GetRow(), nTab );	// gefunden
1163 				++nFound;
1164 			}
1165 			pCell = aIter.GetNext();
1166 		}
1167 	}
1168 
1169 	DBG_ERROR("Notiz nicht gefunden");
1170 	return ScAddress();
1171 }
1172 
1173 sal_Bool ScContentTree::NoteStringsChanged()
1174 {
1175 	ScDocument* pDoc = GetSourceDocument();
1176 	if (!pDoc)
1177 		return sal_False;
1178 
1179 	SvLBoxEntry* pParent = pRootNodes[SC_CONTENT_NOTE];
1180 	if (!pParent)
1181 		return sal_False;
1182 
1183 	SvLBoxEntry* pEntry = FirstChild( pParent );
1184 
1185 	sal_Bool bEqual = sal_True;
1186 	SCTAB nTabCount = pDoc->GetTableCount();
1187 	for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++)
1188 	{
1189 		ScCellIterator aIter( pDoc, 0,0,nTab, MAXCOL,MAXROW,nTab );
1190 		ScBaseCell* pCell = aIter.GetFirst();
1191 		while (pCell && bEqual)
1192 		{
1193             if( const ScPostIt* pNote = pCell->GetNote() )
1194 			{
1195 				if ( !pEntry )
1196 					bEqual = sal_False;
1197 				else
1198 				{
1199                     if ( lcl_NoteString( *pNote ) != GetEntryText(pEntry) )
1200 						bEqual = sal_False;
1201 
1202 					pEntry = NextSibling( pEntry );
1203 				}
1204 			}
1205 			pCell = aIter.GetNext();
1206 		}
1207 	}
1208 
1209 	if ( pEntry )
1210 		bEqual = sal_False;				// kommt noch was
1211 
1212 	return !bEqual;
1213 }
1214 
1215 sal_Bool ScContentTree::DrawNamesChanged( sal_uInt16 nType )
1216 {
1217 	ScDocument* pDoc = GetSourceDocument();
1218 	if (!pDoc)
1219 		return sal_False;
1220 
1221 	SvLBoxEntry* pParent = pRootNodes[nType];
1222 	if (!pParent)
1223 		return sal_False;
1224 
1225 	SvLBoxEntry* pEntry = FirstChild( pParent );
1226 
1227 	// iterate in flat mode for groups
1228 	SdrIterMode eIter = ( nType == SC_CONTENT_DRAWING ) ? IM_FLAT : IM_DEEPNOGROUPS;
1229 
1230 	sal_Bool bEqual = sal_True;
1231 	ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1232 	SfxObjectShell* pShell = pDoc->GetDocumentShell();
1233 	if (pDrawLayer && pShell)
1234 	{
1235 		SCTAB nTabCount = pDoc->GetTableCount();
1236 		for (SCTAB nTab=0; nTab<nTabCount && bEqual; nTab++)
1237 		{
1238 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
1239 			DBG_ASSERT(pPage,"Page ?");
1240 			if (pPage)
1241 			{
1242 				SdrObjListIter aIter( *pPage, eIter );
1243 				SdrObject* pObject = aIter.Next();
1244 				while (pObject && bEqual)
1245 				{
1246                     if ( IsPartOfType( nType, pObject->GetObjIdentifier() ) )
1247 					{
1248 						if ( !pEntry )
1249 							bEqual = sal_False;
1250 						else
1251 						{
1252 							if ( ScDrawLayer::GetVisibleName( pObject ) != GetEntryText(pEntry) )
1253 								bEqual = sal_False;
1254 
1255 							pEntry = NextSibling( pEntry );
1256 						}
1257 					}
1258 					pObject = aIter.Next();
1259 				}
1260 			}
1261 		}
1262 	}
1263 
1264 	if ( pEntry )
1265 		bEqual = sal_False;				// kommt noch was
1266 
1267 	return !bEqual;
1268 }
1269 
1270 sal_Bool lcl_GetRange( ScDocument* pDoc, sal_uInt16 nType, const String& rName, ScRange& rRange )
1271 {
1272 	sal_Bool bFound = sal_False;
1273 	sal_uInt16 nPos;
1274 
1275 	if ( nType == SC_CONTENT_RANGENAME )
1276 	{
1277 		ScRangeName* pList = pDoc->GetRangeName();
1278 		if (pList)
1279 			if (pList->SearchName( rName, nPos ))
1280 				if ( (*pList)[nPos]->IsValidReference( rRange ) )
1281 					bFound = sal_True;
1282 	}
1283 	else if ( nType == SC_CONTENT_DBAREA )
1284 	{
1285 		ScDBCollection*	pList = pDoc->GetDBCollection();
1286 		if (pList)
1287 			if (pList->SearchName( rName, nPos ))
1288 			{
1289                 SCTAB nTab;
1290                 SCCOL nCol1, nCol2;
1291                 SCROW nRow1, nRow2;
1292                 (*pList)[nPos]->GetArea(nTab,nCol1,nRow1,nCol2,nRow2);
1293 				rRange = ScRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
1294 				bFound = sal_True;
1295 			}
1296 	}
1297 
1298 	return bFound;
1299 }
1300 
1301 void lcl_DoDragObject( ScDocShell* pSrcShell, const String& rName, sal_uInt16 nType, Window* pWin )
1302 {
1303 	ScDocument* pSrcDoc = pSrcShell->GetDocument();
1304 	ScDrawLayer* pModel = pSrcDoc->GetDrawLayer();
1305 	if (pModel)
1306 	{
1307 		sal_Bool bOle = ( nType == SC_CONTENT_OLEOBJECT );
1308 		sal_Bool bGraf = ( nType == SC_CONTENT_GRAPHIC );
1309         sal_uInt16 nDrawId = sal::static_int_cast<sal_uInt16>( bOle ? OBJ_OLE2 : ( bGraf ? OBJ_GRAF : OBJ_GRUP ) );
1310 		SCTAB nTab = 0;
1311 		SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab );
1312 		if (pObject)
1313 		{
1314 			SdrView aEditView( pModel );
1315 			aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab));
1316 			SdrPageView* pPV = aEditView.GetSdrPageView();
1317 			aEditView.MarkObj(pObject, pPV);
1318 
1319 			SdrModel* pDragModel = aEditView.GetAllMarkedModel();
1320 
1321 			TransferableObjectDescriptor aObjDesc;
1322 			pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1323 			aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1324 			// maSize is set in ScDrawTransferObj ctor
1325 
1326 			ScDrawTransferObj* pTransferObj = new ScDrawTransferObj( pDragModel, pSrcShell, aObjDesc );
1327 			uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1328 
1329 			pTransferObj->SetDragSourceObj( pObject, nTab );
1330 			pTransferObj->SetDragSourceFlags( SC_DROP_NAVIGATOR );
1331 
1332 			SC_MOD()->SetDragObject( NULL, pTransferObj );
1333 			pWin->ReleaseMouse();
1334 			pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1335 		}
1336 	}
1337 }
1338 
1339 void lcl_DoDragCells( ScDocShell* pSrcShell, const ScRange& rRange, sal_uInt16 nFlags, Window* pWin )
1340 {
1341 	ScMarkData aMark;
1342 	aMark.SelectTable( rRange.aStart.Tab(), sal_True );
1343 	aMark.SetMarkArea( rRange );
1344 
1345 	ScDocument* pSrcDoc = pSrcShell->GetDocument();
1346 	if ( !pSrcDoc->HasSelectedBlockMatrixFragment( rRange.aStart.Col(), rRange.aStart.Row(),
1347 												   rRange.aEnd.Col(),   rRange.aEnd.Row(),
1348 												   aMark ) )
1349 	{
1350 		ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
1351         ScClipParam aClipParam(rRange, false);
1352         pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aMark);
1353 		// pClipDoc->ExtendMerge( rRange, sal_True );
1354 
1355 		TransferableObjectDescriptor aObjDesc;
1356 		pSrcShell->FillTransferableObjectDescriptor( aObjDesc );
1357 		aObjDesc.maDisplayName = pSrcShell->GetMedium()->GetURLObject().GetURLNoPass();
1358 		// maSize is set in ScTransferObj ctor
1359 
1360 		ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
1361 		uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1362 
1363 		pTransferObj->SetDragSource( pSrcShell, aMark );
1364 		pTransferObj->SetDragSourceFlags( nFlags );
1365 
1366 		SC_MOD()->SetDragObject( pTransferObj, NULL );		// for internal D&D
1367 		pWin->ReleaseMouse();
1368 		pTransferObj->StartDrag( pWin, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1369 	}
1370 }
1371 
1372 void ScContentTree::DoDrag()
1373 {
1374 	ScDocumentLoader* pDocLoader = NULL;
1375 	bIsInDrag = sal_True;
1376 
1377 	ScModule* pScMod = SC_MOD();
1378 
1379     sal_uInt16 nType;
1380     sal_uLong nChild;
1381     SvLBoxEntry* pEntry = GetCurEntry();
1382     GetEntryIndexes( nType, nChild, pEntry );
1383 
1384     if( pEntry &&
1385         (nChild != SC_CONTENT_NOCHILD) &&
1386         (nType != SC_CONTENT_ROOT) &&
1387         (nType != SC_CONTENT_NOTE) &&
1388         (nType != SC_CONTENT_AREALINK) )
1389     {
1390         String aText( GetEntryText( pEntry ) );
1391 
1392 		ScDocument* pLocalDoc = NULL;					// fuer URL-Drop
1393 		String aDocName;
1394 		if (bHiddenDoc)
1395 			aDocName = aHiddenName;
1396 		else
1397 		{
1398 			ScDocShell* pDocSh = GetManualOrCurrent();
1399 			if (pDocSh)
1400 			{
1401 				if (pDocSh->HasName())
1402 					aDocName = pDocSh->GetMedium()->GetName();
1403 				else
1404 					pLocalDoc = pDocSh->GetDocument();		// Drop nur in dieses Dokument
1405 			}
1406 		}
1407 
1408 		sal_Bool bDoLinkTrans = sal_False;		// use ScLinkTransferObj
1409 		String aLinkURL;				// for ScLinkTransferObj
1410 		String aLinkText;
1411 
1412 		sal_uInt16 nDropMode = pParentWindow->GetDropMode();
1413 		switch ( nDropMode )
1414 		{
1415 			case SC_DROPMODE_URL:
1416 				{
1417 					String aUrl = aDocName;
1418 					aUrl += '#';
1419 					aUrl += aText;
1420 
1421 					pScMod->SetDragJump( pLocalDoc, aUrl, aText );
1422 
1423 					if (aDocName.Len())
1424 					{
1425 						//	provide URL to outside only if the document has a name
1426 						//	(without name, only internal D&D via SetDragJump)
1427 
1428 						aLinkURL = aUrl;
1429 						aLinkText = aText;
1430 					}
1431 					bDoLinkTrans = sal_True;
1432 				}
1433 				break;
1434 			case SC_DROPMODE_LINK:
1435 				{
1436 					if ( aDocName.Len() )			// link only to named documents
1437 					{
1438 						// for internal D&D, set flag to insert a link
1439 
1440 						switch ( nType )
1441 						{
1442 							case SC_CONTENT_TABLE:
1443 								pScMod->SetDragLink( aDocName, aText, EMPTY_STRING );
1444 								bDoLinkTrans = sal_True;
1445 								break;
1446 							case SC_CONTENT_RANGENAME:
1447 							case SC_CONTENT_DBAREA:
1448 								pScMod->SetDragLink( aDocName, EMPTY_STRING, aText );
1449 								bDoLinkTrans = sal_True;
1450 								break;
1451 
1452 							// other types cannot be linked
1453 						}
1454 					}
1455 				}
1456 				break;
1457 			case SC_DROPMODE_COPY:
1458 				{
1459 					ScDocShell* pSrcShell = NULL;
1460 					if ( bHiddenDoc )
1461 					{
1462 						String aFilter, aOptions;
1463 						pDocLoader = new ScDocumentLoader( aHiddenName, aFilter, aOptions );
1464 						if (!pDocLoader->IsError())
1465 							pSrcShell = pDocLoader->GetDocShell();
1466 					}
1467 					else
1468 						pSrcShell = GetManualOrCurrent();
1469 
1470 					if ( pSrcShell )
1471 					{
1472 						ScDocument* pSrcDoc = pSrcShell->GetDocument();
1473 						if ( nType == SC_CONTENT_RANGENAME || nType == SC_CONTENT_DBAREA )
1474 						{
1475 							ScRange aRange;
1476 							if ( lcl_GetRange( pSrcDoc, nType, aText, aRange ) )
1477 							{
1478 								lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR, this );
1479 							}
1480 						}
1481 						else if ( nType == SC_CONTENT_TABLE )
1482 						{
1483 							SCTAB nTab;
1484 							if ( pSrcDoc->GetTable( aText, nTab ) )
1485 							{
1486 								ScRange aRange( 0,0,nTab, MAXCOL,MAXROW,nTab );
1487 								lcl_DoDragCells( pSrcShell, aRange, SC_DROP_NAVIGATOR | SC_DROP_TABLE, this );
1488 							}
1489 						}
1490 						else if ( nType == SC_CONTENT_GRAPHIC || nType == SC_CONTENT_OLEOBJECT ||
1491 									nType == SC_CONTENT_DRAWING )
1492 						{
1493 							lcl_DoDragObject( pSrcShell, aText, nType, this );
1494 
1495 							//	in ExecuteDrag kann der Navigator geloescht worden sein
1496 							//	-> nicht mehr auf Member zugreifen !!!
1497 						}
1498 					}
1499 				}
1500 				break;
1501 		}
1502 
1503 		if (bDoLinkTrans)
1504 		{
1505 			ScLinkTransferObj* pTransferObj = new ScLinkTransferObj;
1506 			uno::Reference<datatransfer::XTransferable> xTransferable( pTransferObj );
1507 
1508 			if ( aLinkURL.Len() )
1509 				pTransferObj->SetLinkURL( aLinkURL, aLinkText );
1510 
1511 			//	SetDragJump / SetDragLink has been done above
1512 
1513 			ReleaseMouse();
1514 			pTransferObj->StartDrag( this, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
1515 		}
1516 	}
1517 
1518 	bIsInDrag = sal_False;				// static Member
1519 
1520 	delete pDocLoader;				// falls Dokument zum Draggen geladen wurde
1521 }
1522 
1523 IMPL_STATIC_LINK(ScContentTree, ExecDragHdl, void*, EMPTYARG)
1524 {
1525 	//	als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch der
1526 	//	Navigator geloescht werden darf
1527 
1528 	pThis->DoDrag();
1529 	return 0;
1530 }
1531 
1532 //UNUSED2008-05  void ScContentTree::AdjustTitle()
1533 //UNUSED2008-05  {
1534 //UNUSED2008-05      String aTitle = pParentWindow->aTitleBase;
1535 //UNUSED2008-05      if (bHiddenDoc)
1536 //UNUSED2008-05      {
1537 //UNUSED2008-05          aTitle.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " - " ));
1538 //UNUSED2008-05          aTitle += aHiddenTitle;
1539 //UNUSED2008-05      }
1540 //UNUSED2008-05      pParentWindow->SetText(aTitle);
1541 //UNUSED2008-05  }
1542 
1543 sal_Bool ScContentTree::LoadFile( const String& rUrl )
1544 {
1545 	String aDocName = rUrl;
1546 	xub_StrLen nPos = aDocName.Search('#');
1547 	if ( nPos != STRING_NOTFOUND )
1548 		aDocName.Erase(nPos);			// nur der Name, ohne #...
1549 
1550 	sal_Bool bReturn = sal_False;
1551 	String aFilter, aOptions;
1552 	ScDocumentLoader aLoader( aDocName, aFilter, aOptions );
1553 	if ( !aLoader.IsError() )
1554 	{
1555 		bHiddenDoc = sal_True;
1556 		aHiddenName = aDocName;
1557 		aHiddenTitle = aLoader.GetTitle();
1558 		pHiddenDocument = aLoader.GetDocument();
1559 
1560 		Refresh();						// Inhalte aus geladenem Dokument holen
1561 
1562 		pHiddenDocument = NULL;
1563 //		AdjustTitle();
1564 
1565 		pParentWindow->GetDocNames( &aHiddenTitle );			// Liste fuellen
1566 	}
1567 	else
1568 		Sound::Beep();			// Fehler beim Laden
1569 
1570 	//	Dokument wird im dtor von ScDocumentLoader wieder geschlossen
1571 
1572 	return bReturn;
1573 }
1574 
1575 void ScContentTree::InitWindowBits( sal_Bool bButtons )
1576 {
1577 	WinBits nFlags = GetStyle()|WB_CLIPCHILDREN|WB_HSCROLL;
1578 	if (bButtons)
1579 		nFlags |= WB_HASBUTTONS|WB_HASBUTTONSATROOT;
1580 
1581 	SetStyle( nFlags );
1582 }
1583 
1584 void ScContentTree::SetRootType( sal_uInt16 nNew )
1585 {
1586 	if ( nNew != nRootType )
1587 	{
1588 		nRootType = nNew;
1589 		InitWindowBits( nNew == 0 );
1590 		Refresh();
1591 
1592 		ScNavipiCfg& rCfg = SC_MOD()->GetNavipiCfg();
1593 		rCfg.SetRootType( nRootType );
1594 	}
1595 }
1596 
1597 void ScContentTree::ToggleRoot()		// nach Selektion
1598 {
1599 	sal_uInt16 nNew = SC_CONTENT_ROOT;
1600 	if ( nRootType == SC_CONTENT_ROOT )
1601 	{
1602 		SvLBoxEntry* pEntry = GetCurEntry();
1603 		if (pEntry)
1604 		{
1605 			SvLBoxEntry* pParent = GetParent(pEntry);
1606 			for (sal_uInt16 i=1; i<SC_CONTENT_COUNT; i++)
1607 				if ( pEntry == pRootNodes[i] || pParent == pRootNodes[i] )
1608 					nNew = i;
1609 		}
1610 	}
1611 
1612 	SetRootType( nNew );
1613 }
1614 
1615 void ScContentTree::ResetManualDoc()
1616 {
1617 	aManualDoc.Erase();
1618 	bHiddenDoc = sal_False;
1619 
1620 	ActiveDocChanged();
1621 }
1622 
1623 void ScContentTree::ActiveDocChanged()
1624 {
1625 	if ( !bHiddenDoc && !aManualDoc.Len() )
1626 		Refresh();									// Inhalte nur wenn automatisch
1627 
1628 		//	Listbox muss immer geupdated werden, wegen aktiv-Flag
1629 
1630 	String aCurrent;
1631 	if ( bHiddenDoc )
1632 		aCurrent = aHiddenTitle;
1633 	else
1634 	{
1635 		ScDocShell* pSh = GetManualOrCurrent();
1636 		if (pSh)
1637 			aCurrent = pSh->GetTitle();
1638 		else
1639 		{
1640 			//	eingestelltes Dokument existiert nicht mehr
1641 
1642 			aManualDoc.Erase();				// wieder automatisch
1643 			Refresh();
1644 			pSh = GetManualOrCurrent();		// sollte jetzt aktives sein
1645 			if (pSh)
1646 				aCurrent = pSh->GetTitle();
1647 		}
1648 	}
1649 	pParentWindow->GetDocNames( &aCurrent );		// selektieren
1650 }
1651 
1652 void ScContentTree::SetManualDoc(const String& rName)
1653 {
1654 	aManualDoc = rName;
1655 	if (!bHiddenDoc)
1656 	{
1657 		Refresh();
1658 		pParentWindow->GetDocNames( &aManualDoc );		// selektieren
1659 	}
1660 }
1661 
1662 void ScContentTree::SelectDoc(const String& rName)		// rName wie im Menue/Listbox angezeigt
1663 {
1664 	if ( rName == pParentWindow->aStrActiveWin )
1665 	{
1666 		ResetManualDoc();
1667 		return;
1668 	}
1669 
1670 	//	"aktiv" oder "inaktiv" weglassen
1671 
1672 	String aRealName = rName;
1673 	xub_StrLen nLen = rName.Len();
1674 	xub_StrLen nActiveStart = nLen - pParentWindow->aStrActive.Len();
1675 	if ( rName.Copy( nActiveStart ) == pParentWindow->aStrActive )
1676 		aRealName = rName.Copy( 0, nActiveStart );
1677 	xub_StrLen nNotActiveStart = nLen - pParentWindow->aStrNotActive.Len();
1678 	if ( rName.Copy( nNotActiveStart ) == pParentWindow->aStrNotActive )
1679 		aRealName = rName.Copy( 0, nNotActiveStart );
1680 
1681 	//
1682 
1683 	sal_Bool bLoaded = sal_False;
1684 
1685 		// ist es ein normal geladenes Doc ?
1686 
1687 	SfxObjectShell* pSh = SfxObjectShell::GetFirst();
1688 	while ( pSh && !bLoaded )
1689 	{
1690 		if ( pSh->ISA(ScDocShell) )
1691 			if ( pSh->GetTitle() == aRealName )
1692 				bLoaded = sal_True;
1693 		pSh = SfxObjectShell::GetNext( *pSh );
1694 	}
1695 
1696 	if (bLoaded)
1697 	{
1698 		bHiddenDoc = sal_False;
1699 		SetManualDoc(aRealName);
1700 	}
1701 	else if (aHiddenTitle.Len())				// verstecktes ausgewaehlt
1702 	{
1703 		if (!bHiddenDoc)
1704 			LoadFile(aHiddenName);
1705 	}
1706 	else
1707 	{
1708 		DBG_ERROR("SelectDoc: nicht gefunden");
1709 	}
1710 }
1711 
1712 void ScContentTree::ApplySettings()
1713 {
1714     const ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings();
1715     if( pSettings )
1716     {
1717         sal_uInt16 nRootSel = pSettings->GetRootSelected();
1718         sal_uLong nChildSel = pSettings->GetChildSelected();
1719 
1720         for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1721         {
1722             if( pRootNodes[ nEntry ] )
1723             {
1724                 // expand
1725                 sal_Bool bExp = pSettings->IsExpanded( nEntry );
1726                 if( bExp != IsExpanded( pRootNodes[ nEntry ] ) )
1727                 {
1728                     if( bExp )
1729                         Expand( pRootNodes[ nEntry ] );
1730                     else
1731                         Collapse( pRootNodes[ nEntry ] );
1732                 }
1733 
1734                 // select
1735                 if( nRootSel == nEntry )
1736                 {
1737                     SvLBoxEntry* pEntry = NULL;
1738                     if( bExp && (nChildSel != SC_CONTENT_NOCHILD) )
1739                         pEntry = GetEntry( pRootNodes[ nEntry ], nChildSel );
1740                     Select( pEntry ? pEntry : pRootNodes[ nEntry ] );
1741                 }
1742             }
1743         }
1744     }
1745 }
1746 
1747 void ScContentTree::StoreSettings() const
1748 {
1749     ScNavigatorSettings* pSettings = pParentWindow->GetNavigatorSettings();
1750     if( pSettings )
1751     {
1752         for( sal_uInt16 nEntry = 1; nEntry < SC_CONTENT_COUNT; ++nEntry )
1753         {
1754             sal_Bool bExp = pRootNodes[ nEntry ] && IsExpanded( pRootNodes[ nEntry ] );
1755             pSettings->SetExpanded( nEntry, bExp );
1756         }
1757         sal_uInt16 nRoot;
1758         sal_uLong nChild;
1759         GetEntryIndexes( nRoot, nChild, GetCurEntry() );
1760         pSettings->SetRootSelected( nRoot );
1761         pSettings->SetChildSelected( nChild );
1762     }
1763 }
1764 
1765 //IAccessibility2 Implementation 2009-----
1766 class ScContentLBoxString : public SvLBoxString
1767 {
1768 public:
1769 	ScContentLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags,
1770 		const String& rStr ) : SvLBoxString(pEntry,nFlags,rStr)	{}
1771 
1772 	virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
1773 		SvLBoxEntry* pEntry);
1774 };
1775 void ScContentTree::InitEntry(SvLBoxEntry* pEntry,
1776 		const XubString& rStr ,const Image& rImg1,const Image& rImg2, SvLBoxButtonKind eButtonKind)
1777 {
1778 	sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2"
1779 	SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
1780 	SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
1781 	ScContentLBoxString* pStr = new ScContentLBoxString( pEntry, 0, pCol->GetText() );
1782 	pEntry->ReplaceItem( pStr, nColToHilite );
1783 }
1784 void ScContentLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
1785 	SvLBoxEntry* pEntry )
1786 {
1787 	// IA2 CWS. MT: Removed for now (also in SvLBoxEntry) - only used in Sw/Sd/ScContentLBoxString, they should decide if they need this
1788 	/*
1789 	if (pEntry->IsMarked())
1790 	{
1791 			rDev.DrawText( rPos, GetText() );
1792 			XubString str;
1793 			str = XubString::CreateFromAscii("*");
1794 			Point rPosStar(rPos.X()-6,rPos.Y());
1795 			Font aOldFont( rDev.GetFont());
1796 			Font aFont(aOldFont);
1797 			Color aCol( aOldFont.GetColor() );
1798 			aCol.DecreaseLuminance( 200 );
1799 			aFont.SetColor( aCol );
1800 			rDev.SetFont( aFont );
1801 			rDev.DrawText( rPosStar, str);
1802 			rDev.SetFont( aOldFont );
1803 	}
1804 	else
1805 	*/
1806 		SvLBoxString::Paint( rPos, rDev, nFlags, pEntry);
1807 }
1808 //-----IAccessibility2 Implementation 2009
1809 //
1810 //------------------------------------------------------------------------
1811 //
1812 
1813 
1814 
1815 
1816 
1817