bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / utlui / content.cxx
blob8b9a053583306f78c0fb28bc695dc9aae5782970
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/string.hxx>
21 #include <svl/urlbmk.hxx>
22 #include <tools/urlobj.hxx>
23 #include <sfx2/docfile.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <vcl/help.hxx>
26 #include <sot/formats.hxx>
27 #include <uiitems.hxx>
28 #include <fmtinfmt.hxx>
29 #include <txtinet.hxx>
30 #include <fmtfld.hxx>
31 #include <swmodule.hxx>
32 #include <wrtsh.hxx>
33 #include <view.hxx>
34 #include <docsh.hxx>
35 #include <content.hxx>
36 #include <frmfmt.hxx>
37 #include <fldbas.hxx>
38 #include <txtatr.hxx>
39 #include <IMark.hxx>
40 #include <section.hxx>
41 #include <tox.hxx>
42 #include <navipi.hxx>
43 #include <navicont.hxx>
44 #include <navicfg.hxx>
45 #include <edtwin.hxx>
46 #include <doc.hxx>
47 #include <unotools.hxx>
48 #include <crsskip.hxx>
49 #include <cmdid.h>
50 #include <helpid.h>
51 #include <navipi.hrc>
52 #include <utlui.hrc>
53 #include <misc.hrc>
54 #include <comcore.hrc>
55 #include <com/sun/star/text/XTextSectionsSupplier.hpp>
56 #include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
57 #include <com/sun/star/text/XTextTablesSupplier.hpp>
58 #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
59 #include <com/sun/star/text/XDocumentIndex.hpp>
60 #include <com/sun/star/text/XBookmarksSupplier.hpp>
61 #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
62 #include <com/sun/star/text/XTextFramesSupplier.hpp>
63 #include <dcontact.hxx>
64 #include <svx/svdogrp.hxx>
65 #include <svx/svdmodel.hxx>
66 #include <svx/svdpage.hxx>
67 #include <svx/svdview.hxx>
68 #include <vcl/scrbar.hxx>
69 #include <SwRewriter.hxx>
70 #include <hints.hxx>
71 #include <numrule.hxx>
72 #include <swundo.hxx>
73 #include <ndtxt.hxx>
74 #include <PostItMgr.hxx>
75 #include <postithelper.hxx>
76 #include <redline.hxx>
77 #include <docary.hxx>
78 #include <o3tl/sorted_vector.hxx>
79 #include "svtools/treelistentry.hxx"
81 #include "swabstdlg.hxx"
82 #include "globals.hrc"
83 #include <unomid.h>
85 #include "navmgr.hxx"
87 #define CTYPE_CNT 0
88 #define CTYPE_CTT 1
90 using namespace ::std;
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::text;
93 using namespace ::com::sun::star::uno;
94 using namespace ::com::sun::star::container;
96 #define NAVI_BOOKMARK_DELIM (sal_Unicode)1
98 class SwContentArr
99 : public o3tl::sorted_vector<SwContent*, o3tl::less_ptr_to<SwContent>,
100 o3tl::find_partialorder_ptrequals>
102 public:
103 ~SwContentArr() { DeleteAndDestroyAll(); }
106 bool SwContentTree::bIsInDrag = false;
108 namespace
110 static bool lcl_IsContent(const SvTreeListEntry* pEntry)
112 return ((const SwTypeNumber*)pEntry->GetUserData())->GetTypeId() == CTYPE_CNT;
115 static bool lcl_IsContentType(const SvTreeListEntry* pEntry)
117 return ((const SwTypeNumber*)pEntry->GetUserData())->GetTypeId() == CTYPE_CTT;
120 static bool lcl_FindShell(SwWrtShell* pShell)
122 bool bFound = false;
123 SwView *pView = SwModule::GetFirstView();
124 while (pView)
126 if(pShell == &pView->GetWrtShell())
128 bFound = true;
129 break;
131 pView = SwModule::GetNextView(pView);
133 return bFound;
136 static bool lcl_IsUiVisibleBookmark(const IDocumentMarkAccess::pMark_t& rpMark)
138 return IDocumentMarkAccess::GetType(*rpMark) == IDocumentMarkAccess::BOOKMARK;
142 // Content, contains names and reference at the content type.
144 SwContent::SwContent(const SwContentType* pCnt, const String& rName, long nYPos) :
145 SwTypeNumber(CTYPE_CNT),
146 pParent(pCnt),
147 sContentName(rName),
148 nYPosition(nYPos),
149 bInvisible(sal_False)
153 sal_uInt8 SwTypeNumber::GetTypeId() const
155 return nTypeId;
158 SwTypeNumber::~SwTypeNumber()
162 sal_Bool SwContent::IsProtect() const
164 return sal_False;
167 sal_Bool SwPostItContent::IsProtect() const
169 if (mbPostIt)
170 return pFld->IsProtect();
171 else
172 return false;
175 sal_Bool SwURLFieldContent::IsProtect() const
177 return pINetAttr->IsProtect();
180 SwGraphicContent::~SwGraphicContent()
184 SwTOXBaseContent::~SwTOXBaseContent()
188 // Content type, knows it's contents and the WrtShell.
190 SwContentType::SwContentType(SwWrtShell* pShell, sal_uInt16 nType, sal_uInt8 nLevel) :
191 SwTypeNumber(CTYPE_CTT),
192 pWrtShell(pShell),
193 pMember(0),
194 sContentTypeName(SW_RES(STR_CONTENT_TYPE_FIRST + nType)),
195 sSingleContentTypeName(SW_RES(STR_CONTENT_TYPE_SINGLE_FIRST + nType)),
196 nMemberCount(0),
197 nContentType(nType),
198 nOutlineLevel(nLevel),
199 bDataValid(false),
200 bEdit(false),
201 bDelete(true)
203 Init();
206 // Init
208 void SwContentType::Init(sal_Bool* pbInvalidateWindow)
210 // if the MemberCount is changing ...
211 sal_uInt16 nOldMemberCount = nMemberCount;
212 nMemberCount = 0;
213 switch(nContentType)
215 case CONTENT_TYPE_OUTLINE :
217 sTypeToken = OUString::createFromAscii(pMarkToOutline);
218 sal_uInt16 nOutlineCount = nMemberCount =
219 static_cast<sal_uInt16>(pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineNodesCount());
220 if(nOutlineLevel < MAXLEVEL)
222 for(sal_uInt16 j = 0; j < nOutlineCount; j++)
224 if(pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineLevel(j) > nOutlineLevel )
225 nMemberCount --;
228 bDelete = false;
230 break;
232 case CONTENT_TYPE_TABLE :
233 sTypeToken = OUString::createFromAscii(pMarkToTable);
234 nMemberCount = pWrtShell->GetTblFrmFmtCount(true);
235 bEdit = true;
236 break;
238 case CONTENT_TYPE_FRAME :
239 case CONTENT_TYPE_GRAPHIC :
240 case CONTENT_TYPE_OLE :
242 FlyCntType eType = FLYCNTTYPE_FRM;
243 sTypeToken = OUString::createFromAscii(pMarkToFrame);
244 if(nContentType == CONTENT_TYPE_OLE)
246 eType = FLYCNTTYPE_OLE;
247 sTypeToken = OUString::createFromAscii(pMarkToOLE);
249 else if(nContentType == CONTENT_TYPE_GRAPHIC)
251 eType = FLYCNTTYPE_GRF;
252 sTypeToken = OUString::createFromAscii(pMarkToGraphic);
254 nMemberCount = pWrtShell->GetFlyCount(eType);
255 bEdit = true;
257 break;
258 case CONTENT_TYPE_BOOKMARK:
260 IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
261 nMemberCount = static_cast<sal_uInt16>(count_if(
262 pMarkAccess->getBookmarksBegin(),
263 pMarkAccess->getBookmarksEnd(),
264 &lcl_IsUiVisibleBookmark));
265 sTypeToken = aEmptyStr;
266 bEdit = true;
268 break;
269 case CONTENT_TYPE_REGION :
271 SwContentArr* pOldMember = 0;
272 sal_uInt16 nOldRegionCount = 0;
273 bool bInvalidate = false;
274 if(!pMember)
275 pMember = new SwContentArr;
276 else if(!pMember->empty())
278 pOldMember = pMember;
279 nOldRegionCount = pOldMember->size();
280 pMember = new SwContentArr;
282 const Point aNullPt;
283 nMemberCount = pWrtShell->GetSectionFmtCount();
284 for(sal_uInt16 i = 0; i < nMemberCount; i++)
286 const SwSectionFmt* pFmt;
287 SectionType eTmpType;
288 if( (pFmt = &pWrtShell->GetSectionFmt(i))->IsInNodesArr() &&
289 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
290 && TOX_HEADER_SECTION != eTmpType )
292 const String& rSectionName =
293 pFmt->GetSection()->GetSectionName();
294 sal_uInt8 nLevel = 0;
295 SwSectionFmt* pParentFmt = pFmt->GetParent();
296 while(pParentFmt)
298 nLevel++;
299 pParentFmt = pParentFmt->GetParent();
302 SwContent* pCnt = new SwRegionContent(this, rSectionName,
303 nLevel,
304 pFmt->FindLayoutRect( sal_False, &aNullPt ).Top());
306 SwPtrMsgPoolItem aAskItem( RES_CONTENT_VISIBLE, 0 );
307 if( !pFmt->GetInfo( aAskItem ) &&
308 !aAskItem.pObject ) // not visible
309 pCnt->SetInvisible();
310 pMember->insert(pCnt);
312 sal_uInt16 nPos = pMember->size() - 1;
313 if(nOldRegionCount > nPos &&
314 ((*pOldMember)[nPos])->IsInvisible()
315 != pCnt->IsInvisible())
316 bInvalidate = true;
319 nMemberCount = pMember->size();
320 sTypeToken = OUString::createFromAscii(pMarkToRegion);
321 bEdit = true;
322 bDelete = false;
323 if(pOldMember)
325 pOldMember->DeleteAndDestroyAll();
326 delete pOldMember;
327 if(pbInvalidateWindow && bInvalidate)
328 *pbInvalidateWindow = sal_True;
331 break;
332 case CONTENT_TYPE_INDEX:
334 nMemberCount = pWrtShell->GetTOXCount();
335 bEdit = true;
336 bDelete = false;
338 break;
339 case CONTENT_TYPE_REFERENCE:
341 nMemberCount = pWrtShell->GetRefMarks( 0 );
342 bDelete = false;
344 break;
345 case CONTENT_TYPE_URLFIELD:
347 nMemberCount = 0;
348 if(!pMember)
349 pMember = new SwContentArr;
350 else if(!pMember->empty())
351 pMember->DeleteAndDestroyAll();
353 SwGetINetAttrs aArr;
354 nMemberCount = pWrtShell->GetINetAttrs( aArr );
355 for( sal_uInt16 n = 0; n < nMemberCount; ++n )
357 SwGetINetAttr* p = &aArr[ n ];
358 SwURLFieldContent* pCnt = new SwURLFieldContent(
359 this,
360 p->sText,
361 INetURLObject::decode(
362 p->rINetAttr.GetINetFmt().GetValue(),
363 INET_HEX_ESCAPE,
364 INetURLObject::DECODE_UNAMBIGUOUS,
365 RTL_TEXTENCODING_UTF8 ),
366 &p->rINetAttr,
367 n );
368 pMember->insert( pCnt );
370 bEdit = true;
371 nOldMemberCount = nMemberCount;
372 bDelete = false;
374 break;
375 case CONTENT_TYPE_POSTIT:
377 nMemberCount = 0;
378 if(!pMember)
379 pMember = new SwContentArr;
380 else if(!pMember->empty())
381 pMember->DeleteAndDestroyAll();
383 SwPostItMgr* aMgr = pWrtShell->GetView().GetPostItMgr();
384 if (aMgr)
386 for(SwPostItMgr::const_iterator i = aMgr->begin(); i != aMgr->end(); ++i)
388 if ( (*i)->GetBroadCaster()->ISA(SwFmtFld)) // SwPostit
390 SwFmtFld* aFmtFld = static_cast<SwFmtFld*>((*i)->GetBroadCaster());
391 if (aFmtFld->GetTxtFld() && aFmtFld->IsFldInDoc() &&
392 (*i)->mLayoutStatus!=SwPostItHelper::INVISIBLE )
394 String sEntry = aFmtFld->GetFld()->GetPar2();
395 RemoveNewline(sEntry);
396 SwPostItContent* pCnt = new SwPostItContent(
397 this,
398 sEntry,
399 (const SwFmtFld*)aFmtFld,
400 nMemberCount);
401 pMember->insert(pCnt);
402 nMemberCount++;
407 sTypeToken = aEmptyStr;
408 bEdit = true;
409 nOldMemberCount = nMemberCount;
411 break;
412 case CONTENT_TYPE_DRAWOBJECT:
414 sTypeToken = aEmptyStr;
415 nMemberCount = 0;
416 SdrModel* pModel = pWrtShell->getIDocumentDrawModelAccess()->GetDrawModel();
417 if(pModel)
419 SdrPage* pPage = pModel->GetPage(0);
420 sal_uInt32 nCount = pPage->GetObjCount();
421 for( sal_uInt32 i=0; i< nCount; i++ )
423 SdrObject* pTemp = pPage->GetObj(i);
424 // #i51726# - all drawing objects can be named now
425 if (!pTemp->GetName().isEmpty())
426 nMemberCount++;
430 break;
432 // ... then, the data can also no longer be valid,
433 // apart from those which have already been corrected,
434 // then nOldMemberCount is nevertheless not so old.
435 if( nOldMemberCount != nMemberCount )
436 bDataValid = false;
439 SwContentType::~SwContentType()
441 delete pMember;
444 // Deliver content, for that if necessary fill the list
446 const SwContent* SwContentType::GetMember(sal_uInt16 nIndex)
448 if(!bDataValid || !pMember)
450 FillMemberList();
452 if(nIndex < pMember->size())
453 return (*pMember)[nIndex];
454 else
455 return 0;
459 void SwContentType::Invalidate()
461 bDataValid = false;
464 // Fill the List of contents
466 void SwContentType::FillMemberList(sal_Bool* pbLevelOrVisibilityChanged)
468 SwContentArr* pOldMember = 0;
469 int nOldMemberCount = -1;
470 SwPtrMsgPoolItem aAskItem( RES_CONTENT_VISIBLE, 0 );
471 if(pMember && pbLevelOrVisibilityChanged)
473 pOldMember = pMember;
474 nOldMemberCount = pOldMember->size();
475 pMember = new SwContentArr;
476 *pbLevelOrVisibilityChanged = sal_False;
478 else if(!pMember)
479 pMember = new SwContentArr;
480 else if(!pMember->empty())
481 pMember->DeleteAndDestroyAll();
482 switch(nContentType)
484 case CONTENT_TYPE_OUTLINE :
486 sal_uInt16 nOutlineCount = nMemberCount =
487 static_cast<sal_uInt16>(pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineNodesCount());
489 sal_uInt16 nPos = 0;
490 for (sal_uInt16 i = 0; i < nOutlineCount; ++i)
492 const sal_Int8 nLevel = (sal_Int8)pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineLevel(i);
493 if(nLevel >= nOutlineLevel )
494 nMemberCount--;
495 else
497 String aEntry(comphelper::string::stripStart(
498 pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineText(i), ' '));
499 SwNavigationPI::CleanEntry( aEntry );
500 SwOutlineContent* pCnt = new SwOutlineContent(this, aEntry, i, nLevel,
501 pWrtShell->IsOutlineMovable( i ), nPos );
502 pMember->insert(pCnt);//, nPos);
503 // with the same number and existing "pOldMember" the
504 // old one is compared with the new OutlinePos.
505 // cast for Win16
506 if(nOldMemberCount > (int)nPos &&
507 ((SwOutlineContent*)(*pOldMember)[nPos])->GetOutlineLevel() != nLevel)
508 *pbLevelOrVisibilityChanged = sal_True;
510 nPos++;
515 break;
517 case CONTENT_TYPE_TABLE :
519 OSL_ENSURE(nMemberCount == pWrtShell->GetTblFrmFmtCount(true),
520 "MemberCount differs");
521 Point aNullPt;
522 nMemberCount = pWrtShell->GetTblFrmFmtCount(true);
523 for(sal_uInt16 i = 0; i < nMemberCount; i++)
525 const SwFrmFmt& rTblFmt = pWrtShell->GetTblFrmFmt(i, true);
526 String sTblName( rTblFmt.GetName() );
528 SwContent* pCnt = new SwContent(this, sTblName,
529 rTblFmt.FindLayoutRect(sal_False, &aNullPt).Top() );
530 if( !rTblFmt.GetInfo( aAskItem ) &&
531 !aAskItem.pObject ) // not visible
532 pCnt->SetInvisible();
534 pMember->insert(pCnt);
536 if(nOldMemberCount > (int)i &&
537 (*pOldMember)[i]->IsInvisible() != pCnt->IsInvisible())
538 *pbLevelOrVisibilityChanged = sal_True;
541 break;
542 case CONTENT_TYPE_OLE :
543 case CONTENT_TYPE_FRAME :
544 case CONTENT_TYPE_GRAPHIC :
546 FlyCntType eType = FLYCNTTYPE_FRM;
547 if(nContentType == CONTENT_TYPE_OLE)
548 eType = FLYCNTTYPE_OLE;
549 else if(nContentType == CONTENT_TYPE_GRAPHIC)
550 eType = FLYCNTTYPE_GRF;
551 OSL_ENSURE(nMemberCount == pWrtShell->GetFlyCount(eType),
552 "MemberCount differs");
553 Point aNullPt;
554 nMemberCount = pWrtShell->GetFlyCount(eType);
555 for(sal_uInt16 i = 0; i < nMemberCount; i++)
557 const SwFrmFmt* pFrmFmt = pWrtShell->GetFlyNum(i,eType);
558 String sFrmName = pFrmFmt->GetName();
560 SwContent* pCnt;
561 if(CONTENT_TYPE_GRAPHIC == nContentType)
563 String sLink;
564 pWrtShell->GetGrfNms( &sLink, 0, (SwFlyFrmFmt*) pFrmFmt);
565 pCnt = new SwGraphicContent(this, sFrmName,
566 INetURLObject::decode( sLink, INET_HEX_ESCAPE,
567 INetURLObject::DECODE_UNAMBIGUOUS,
568 RTL_TEXTENCODING_UTF8 ),
569 pFrmFmt->FindLayoutRect(sal_False, &aNullPt).Top());
571 else
573 pCnt = new SwContent(this, sFrmName,
574 pFrmFmt->FindLayoutRect(sal_False, &aNullPt).Top() );
576 if( !pFrmFmt->GetInfo( aAskItem ) &&
577 !aAskItem.pObject ) // not visible
578 pCnt->SetInvisible();
579 pMember->insert(pCnt);
580 if(nOldMemberCount > (int)i &&
581 (*pOldMember)[i]->IsInvisible() != pCnt->IsInvisible())
582 *pbLevelOrVisibilityChanged = sal_True;
585 break;
586 case CONTENT_TYPE_BOOKMARK:
588 IDocumentMarkAccess* const pMarkAccess = pWrtShell->getIDocumentMarkAccess();
589 for(IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
590 ppBookmark != pMarkAccess->getBookmarksEnd();
591 ++ppBookmark)
593 if(lcl_IsUiVisibleBookmark(*ppBookmark))
595 const String& rBkmName = ppBookmark->get()->GetName();
596 //nYPos from 0 -> text::Bookmarks will be sorted alphabetically
597 SwContent* pCnt = new SwContent(this, rBkmName, 0);
598 pMember->insert(pCnt);
602 break;
603 case CONTENT_TYPE_REGION :
605 const Point aNullPt;
606 nMemberCount = pWrtShell->GetSectionFmtCount();
607 for(sal_uInt16 i = 0; i < nMemberCount; i++)
609 const SwSectionFmt* pFmt;
610 SectionType eTmpType;
611 if( (pFmt = &pWrtShell->GetSectionFmt(i))->IsInNodesArr() &&
612 (eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
613 && TOX_HEADER_SECTION != eTmpType )
615 String sSectionName = pFmt->GetSection()->GetSectionName();
617 sal_uInt8 nLevel = 0;
618 SwSectionFmt* pParentFmt = pFmt->GetParent();
619 while(pParentFmt)
621 nLevel++;
622 pParentFmt = pParentFmt->GetParent();
625 SwContent* pCnt = new SwRegionContent(this, sSectionName,
626 nLevel,
627 pFmt->FindLayoutRect( sal_False, &aNullPt ).Top());
628 if( !pFmt->GetInfo( aAskItem ) &&
629 !aAskItem.pObject ) // not visible
630 pCnt->SetInvisible();
631 pMember->insert(pCnt);
633 sal_uInt16 nPos = pMember->size() - 1;
634 if(nOldMemberCount > nPos &&
635 (*pOldMember)[nPos]->IsInvisible()
636 != pCnt->IsInvisible())
637 *pbLevelOrVisibilityChanged = sal_True;
640 nMemberCount = pMember->size();
642 break;
643 case CONTENT_TYPE_REFERENCE:
645 std::vector<OUString> aRefMarks;
646 nMemberCount = pWrtShell->GetRefMarks( &aRefMarks );
648 for(std::vector<OUString>::const_iterator i = aRefMarks.begin(); i != aRefMarks.end(); ++i)
650 // References sorted alphabetically
651 SwContent* pCnt = new SwContent(this, *i, 0);
652 pMember->insert(pCnt);
655 break;
656 case CONTENT_TYPE_URLFIELD:
658 SwGetINetAttrs aArr;
659 nMemberCount = pWrtShell->GetINetAttrs( aArr );
660 for( sal_uInt16 n = 0; n < nMemberCount; ++n )
662 SwGetINetAttr* p = &aArr[ n ];
663 SwURLFieldContent* pCnt = new SwURLFieldContent(
664 this,
665 p->sText,
666 INetURLObject::decode(
667 p->rINetAttr.GetINetFmt().GetValue(),
668 INET_HEX_ESCAPE,
669 INetURLObject::DECODE_UNAMBIGUOUS,
670 RTL_TEXTENCODING_UTF8 ),
671 &p->rINetAttr,
672 n );
673 pMember->insert( pCnt );
676 break;
677 case CONTENT_TYPE_INDEX:
680 sal_uInt16 nCount = nMemberCount = pWrtShell->GetTOXCount();
681 for ( sal_uInt16 nTox = 0; nTox < nCount; nTox++ )
683 const SwTOXBase* pBase = pWrtShell->GetTOX( nTox );
684 String sTOXNm( pBase->GetTOXName() );
686 SwContent* pCnt = new SwTOXBaseContent(
687 this, sTOXNm, nTox, *pBase);
689 if( !pBase->GetInfo( aAskItem ) &&
690 !aAskItem.pObject ) // not visible
691 pCnt->SetInvisible();
693 pMember->insert( pCnt );
694 sal_uInt16 nPos = pMember->size() - 1;
695 if(nOldMemberCount > nPos &&
696 (*pOldMember)[nPos]->IsInvisible()
697 != pCnt->IsInvisible())
698 *pbLevelOrVisibilityChanged = sal_True;
701 break;
702 case CONTENT_TYPE_POSTIT:
704 nMemberCount = 0;
705 if(!pMember)
706 pMember = new SwContentArr;
707 else if(!pMember->empty())
708 pMember->DeleteAndDestroyAll();
709 SwPostItMgr* aMgr = pWrtShell->GetView().GetPostItMgr();
710 if (aMgr)
712 for(SwPostItMgr::const_iterator i = aMgr->begin(); i != aMgr->end(); ++i)
714 if ( (*i)->GetBroadCaster()->ISA(SwFmtFld)) // SwPostit
716 SwFmtFld* aFmtFld = static_cast<SwFmtFld*>((*i)->GetBroadCaster());
717 if (aFmtFld->GetTxtFld() && aFmtFld->IsFldInDoc() &&
718 (*i)->mLayoutStatus!=SwPostItHelper::INVISIBLE )
720 String sEntry = aFmtFld->GetFld()->GetPar2();
721 RemoveNewline(sEntry);
722 SwPostItContent* pCnt = new SwPostItContent(
723 this,
724 sEntry,
725 (const SwFmtFld*)aFmtFld,
726 nMemberCount);
727 pMember->insert(pCnt);
728 nMemberCount++;
734 break;
735 case CONTENT_TYPE_DRAWOBJECT:
737 nMemberCount = 0;
738 if(!pMember)
739 pMember = new SwContentArr;
740 else if(!pMember->empty())
741 pMember->DeleteAndDestroyAll();
743 IDocumentDrawModelAccess* pIDDMA = pWrtShell->getIDocumentDrawModelAccess();
744 SdrModel* pModel = pIDDMA->GetDrawModel();
745 if(pModel)
747 SdrPage* pPage = pModel->GetPage(0);
748 sal_uInt32 nCount = pPage->GetObjCount();
749 for( sal_uInt32 i=0; i< nCount; i++ )
751 SdrObject* pTemp = pPage->GetObj(i);
752 // #i51726# - all drawing objects can be named now
753 if (!pTemp->GetName().isEmpty())
755 SwContact* pContact = (SwContact*)pTemp->GetUserCall();
756 long nYPos = 0;
757 const Point aNullPt;
758 if(pContact && pContact->GetFmt())
759 nYPos = pContact->GetFmt()->FindLayoutRect(sal_False, &aNullPt).Top();
760 SwContent* pCnt = new SwContent(
761 this,
762 pTemp->GetName(),
763 nYPos);
764 if(!pIDDMA->IsVisibleLayerId(pTemp->GetLayer()))
765 pCnt->SetInvisible();
766 pMember->insert(pCnt);
767 nMemberCount++;
768 if(nOldMemberCount > (int)i &&
769 (*pOldMember)[i]->IsInvisible() != pCnt->IsInvisible() )
770 *pbLevelOrVisibilityChanged = sal_True;
775 break;
777 bDataValid = true;
778 if(pOldMember)
779 pOldMember->DeleteAndDestroyAll();
783 // TreeListBox for content indicator
785 SwContentTree::SwContentTree(Window* pParent, const ResId& rResId) :
786 SvTreeListBox( pParent, rResId ),
788 sSpace(OUString(" ")),
790 sRemoveIdx(SW_RES(ST_REMOVE_INDEX)),
791 sUpdateIdx(SW_RES(ST_UPDATE)),
792 sUnprotTbl(SW_RES(ST_REMOVE_TBL_PROTECTION)),
793 sRename(SW_RES(ST_RENAME)),
794 sReadonlyIdx(SW_RES(ST_READONLY_IDX)),
795 sInvisible(SW_RES(ST_INVISIBLE)),
797 sPostItShow(SW_RES(ST_POSTIT_SHOW)),
798 sPostItHide(SW_RES(ST_POSTIT_HIDE)),
799 sPostItDelete(SW_RES(ST_POSTIT_DELETE)),
801 pHiddenShell(0),
802 pActiveShell(0),
803 pConfig(SW_MOD()->GetNavigationConfig()),
805 nActiveBlock(0),
806 nHiddenBlock(0),
808 nRootType(USHRT_MAX),
809 nLastSelType(USHRT_MAX),
810 nOutlineLevel(MAXLEVEL),
812 bIsActive(true),
813 bIsConstant(false),
814 bIsHidden(false),
815 bDocChgdInDragging(false),
816 bIsInternalDrag(false),
817 bIsRoot(false),
818 bIsIdleClear(false),
819 bIsLastReadOnly(sal_False),
820 bIsOutlineMoveable(true),
821 bViewHasChanged(false),
822 bIsImageListInitialized(false)
824 sal_uInt16 i;
826 SetHelpId(HID_NAVIGATOR_TREELIST);
828 SetNodeDefaultImages();
829 SetDoubleClickHdl(LINK(this, SwContentTree, ContentDoubleClickHdl));
830 SetDragDropMode(SV_DRAGDROP_APP_COPY);
831 for( i = 0; i < CONTENT_TYPE_MAX; i++)
833 aActiveContentArr[i] = 0;
834 aHiddenContentArr[i] = 0;
836 for( i = 0; i < CONTEXT_COUNT; i++ )
838 aContextStrings[i] = SW_RESSTR(i+ST_CONTEXT_FIRST);
840 nActiveBlock = pConfig->GetActiveBlock();
841 aUpdTimer.SetTimeoutHdl(LINK(this, SwContentTree, TimerUpdate));
842 aUpdTimer.SetTimeout(1000);
843 Clear();
844 EnableContextMenuHandling();
845 SetStyle( GetStyle() | WB_QUICK_SEARCH );
848 SwContentTree::~SwContentTree()
850 Clear(); // If applicable erase content types previously.
851 bIsInDrag = false;
854 // Drag&Drop methods
856 void SwContentTree::StartDrag( sal_Int8 nAction, const Point& rPosPixel )
858 if( !bIsRoot || nRootType != CONTENT_TYPE_OUTLINE )
860 ReleaseMouse();
862 TransferDataContainer* pContainer = new TransferDataContainer;
863 uno::Reference<
864 datatransfer::XTransferable > xRef( pContainer );
866 sal_Int8 nDragMode = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
867 if( FillTransferData( *pContainer, nDragMode ))
869 SwContentTree::SetInDrag(true);
870 pContainer->StartDrag( this, nDragMode, GetDragFinishedHdl() );
873 else
874 SvTreeListBox::StartDrag( nAction, rPosPixel );
877 void SwContentTree::DragFinished( sal_Int8 nAction )
879 // To prevent the removing of the selected entry in external drag and drop
880 // the drag action mustn't be MOVE.
881 SvTreeListBox::DragFinished( bIsInternalDrag ? nAction : DND_ACTION_COPY );
882 SwContentTree::SetInDrag(false);
883 bIsInternalDrag = false;
886 // QueryDrop will be executed in the navigator
888 sal_Int8 SwContentTree::AcceptDrop( const AcceptDropEvent& rEvt )
890 sal_Int8 nRet = DND_ACTION_NONE;
891 if( bIsRoot )
893 if( bIsOutlineMoveable )
894 nRet = SvTreeListBox::AcceptDrop( rEvt );
896 else if( !bIsInDrag )
897 nRet = GetParentWindow()->AcceptDrop( rEvt );
898 return nRet;
901 // Drop will be executed in the navigator
903 static void* lcl_GetOutlineKey( SwContentTree* pTree, SwOutlineContent* pContent)
905 void* key = 0;
906 if( pTree && pContent )
908 SwWrtShell* pShell = pTree->GetWrtShell();
909 sal_Int32 nPos = pContent->GetYPos();
910 if( nPos )
912 key = (void*)pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos );
915 return key;
918 sal_Int8 SwContentTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
920 SvTreeListEntry* pEntry = pTargetEntry;
921 if( pEntry && ( nRootType == CONTENT_TYPE_OUTLINE ) && lcl_IsContent( pEntry ) )
923 SwOutlineContent* pOutlineContent = ( SwOutlineContent* )( pEntry->GetUserData() );
924 if( pOutlineContent )
926 void* key = lcl_GetOutlineKey(this, pOutlineContent);
927 if( !mOutLineNodeMap[key] )
929 while( pEntry->HasChildren() )
931 SvTreeListEntry* pChildEntry = FirstChild( pEntry );
932 while( pChildEntry )
934 pEntry = pChildEntry;
935 pChildEntry = NextSibling( pChildEntry );
938 pTargetEntry = pEntry;
942 if( bIsRoot )
943 return SvTreeListBox::ExecuteDrop( rEvt );
944 return bIsInDrag ? DND_ACTION_NONE : GetParentWindow()->ExecuteDrop(rEvt);
947 // Handler for Dragging and ContextMenu
949 PopupMenu* SwContentTree::CreateContextMenu( void )
951 PopupMenu* pPop = new PopupMenu;
952 PopupMenu* pSubPop1 = new PopupMenu;
953 PopupMenu* pSubPop2 = new PopupMenu;
954 PopupMenu* pSubPop3 = new PopupMenu;
955 PopupMenu* pSubPop4 = new PopupMenu; // Edit
957 sal_uInt16 i;
958 for(i = 1; i <= MAXLEVEL; i++ )
960 pSubPop1->InsertItem( i + 100, OUString::number(i));
962 pSubPop1->CheckItem(100 + nOutlineLevel);
963 for(i=0; i < 3; i++ )
965 pSubPop2->InsertItem( i + 201, aContextStrings[
966 ST_HYPERLINK - ST_CONTEXT_FIRST + i]);
968 pSubPop2->CheckItem( 201 +
969 GetParentWindow()->GetRegionDropMode());
970 // Insert the list of the open files
971 sal_uInt16 nId = 301;
972 const SwView* pActiveView = ::GetActiveView();
973 SwView *pView = SwModule::GetFirstView();
974 while (pView)
976 String sInsert = pView->GetDocShell()->GetTitle();
977 if(pView == pActiveView)
979 sInsert += '(';
980 sInsert += aContextStrings[ ST_ACTIVE - ST_CONTEXT_FIRST];
981 sInsert += ')';
983 pSubPop3->InsertItem(nId, sInsert);
984 if(bIsConstant && pActiveShell == &pView->GetWrtShell())
985 pSubPop3->CheckItem(nId);
986 pView = SwModule::GetNextView(pView);
987 nId++;
989 pSubPop3->InsertItem(nId++, aContextStrings[ST_ACTIVE_VIEW - ST_CONTEXT_FIRST]);
990 if(pHiddenShell)
992 String sHiddenEntry = pHiddenShell->GetView().GetDocShell()->GetTitle();
993 sHiddenEntry += OUString(" ( ");
994 sHiddenEntry += aContextStrings[ ST_HIDDEN - ST_CONTEXT_FIRST];
995 sHiddenEntry += OUString(" )");
996 pSubPop3->InsertItem(nId, sHiddenEntry);
999 if(bIsActive)
1000 pSubPop3->CheckItem( --nId );
1001 else if(bIsHidden)
1002 pSubPop3->CheckItem( nId );
1004 pPop->InsertItem( 1, aContextStrings[ST_OUTLINE_LEVEL - ST_CONTEXT_FIRST]);
1005 pPop->InsertItem(2, aContextStrings[ST_DRAGMODE - ST_CONTEXT_FIRST]);
1006 pPop->InsertItem(3, aContextStrings[ST_DISPLAY - ST_CONTEXT_FIRST]);
1007 // Now edit
1008 SvTreeListEntry* pEntry = 0;
1009 // Edit only if the shown content is coming from the current view.
1010 if((bIsActive || pActiveShell == pActiveView->GetWrtShellPtr())
1011 && 0 != (pEntry = FirstSelected()) && lcl_IsContent(pEntry))
1013 const SwContentType* pContType = ((SwContent*)pEntry->GetUserData())->GetParent();
1014 const sal_uInt16 nContentType = pContType->GetType();
1015 sal_Bool bReadonly = pActiveShell->GetView().GetDocShell()->IsReadOnly();
1016 bool bVisible = !((SwContent*)pEntry->GetUserData())->IsInvisible();
1017 sal_Bool bProtected = ((SwContent*)pEntry->GetUserData())->IsProtect();
1018 bool bEditable = pContType->IsEditable() &&
1019 ((bVisible && !bProtected) ||CONTENT_TYPE_REGION == nContentType);
1020 bool bDeletable = pContType->IsDeletable() &&
1021 ((bVisible && !bProtected) ||CONTENT_TYPE_REGION == nContentType);
1022 bool bRenamable = bEditable && !bReadonly &&
1023 (CONTENT_TYPE_TABLE == nContentType ||
1024 CONTENT_TYPE_FRAME == nContentType ||
1025 CONTENT_TYPE_GRAPHIC == nContentType ||
1026 CONTENT_TYPE_OLE == nContentType ||
1027 CONTENT_TYPE_BOOKMARK == nContentType ||
1028 CONTENT_TYPE_REGION == nContentType||
1029 CONTENT_TYPE_INDEX == nContentType);
1031 if(!bReadonly && (bEditable || bDeletable))
1033 bool bSubPop4 = false;
1034 if(CONTENT_TYPE_INDEX == nContentType)
1036 bSubPop4 = true;
1037 pSubPop4->InsertItem(401, sRemoveIdx);
1038 pSubPop4->InsertItem(402, sUpdateIdx);
1040 const SwTOXBase* pBase = ((SwTOXBaseContent*)pEntry->GetUserData())->GetTOXBase();
1041 if(!pBase->IsTOXBaseInReadonly())
1042 pSubPop4->InsertItem(403, aContextStrings[ST_EDIT_ENTRY - ST_CONTEXT_FIRST]);
1043 pSubPop4->InsertItem(405, sReadonlyIdx);
1045 pSubPop4->CheckItem( 405, pActiveShell->IsTOXBaseReadonly(*pBase));
1046 pSubPop4->InsertItem(501, aContextStrings[ST_DELETE_ENTRY - ST_CONTEXT_FIRST]);
1048 else if(CONTENT_TYPE_TABLE == nContentType && !bReadonly)
1050 bSubPop4 = true;
1051 pSubPop4->InsertItem(403, aContextStrings[ST_EDIT_ENTRY - ST_CONTEXT_FIRST]);
1052 pSubPop4->InsertItem(404, sUnprotTbl);
1053 sal_Bool bFull = sal_False;
1054 String sTblName = ((SwContent*)pEntry->GetUserData())->GetName();
1055 sal_Bool bProt =pActiveShell->HasTblAnyProtection( &sTblName, &bFull );
1056 pSubPop4->EnableItem(403, !bFull );
1057 pSubPop4->EnableItem(404, bProt );
1058 pSubPop4->InsertItem(501, aContextStrings[ST_DELETE_ENTRY - ST_CONTEXT_FIRST]);
1060 else if(bEditable || bDeletable)
1063 if(bEditable && bDeletable)
1065 pSubPop4->InsertItem(403, aContextStrings[ST_EDIT_ENTRY - ST_CONTEXT_FIRST]);
1066 pSubPop4->InsertItem(501, aContextStrings[ST_DELETE_ENTRY - ST_CONTEXT_FIRST]);
1067 bSubPop4 = true;
1069 else if(bEditable)
1070 pPop->InsertItem(403, aContextStrings[ST_EDIT_ENTRY - ST_CONTEXT_FIRST]);
1071 else if(bDeletable)
1073 pSubPop4->InsertItem(501, aContextStrings[ST_DELETE_ENTRY - ST_CONTEXT_FIRST]);
1076 //Rename object
1077 if(bRenamable)
1079 if(bSubPop4)
1080 pSubPop4->InsertItem(502, sRename);
1081 else
1082 pPop->InsertItem(502, sRename);
1085 if(bSubPop4)
1087 pPop->InsertItem(4, pContType->GetSingleName());
1088 pPop->SetPopupMenu(4, pSubPop4);
1092 else if( pEntry )
1094 SwContentType* pType = (SwContentType*)pEntry->GetUserData();
1095 if ( (pType->GetType() == CONTENT_TYPE_POSTIT) && (!pActiveShell->GetView().GetDocShell()->IsReadOnly()) && ( pType->GetMemberCount() > 0) )
1097 pSubPop4->InsertItem(600, sPostItShow );
1098 pSubPop4->InsertItem(601, sPostItHide );
1099 pSubPop4->InsertItem(602, sPostItDelete );
1100 pPop->InsertItem(4, pType->GetSingleName());
1101 pPop->SetPopupMenu(4, pSubPop4);
1105 pPop->SetPopupMenu( 1, pSubPop1 );
1106 pPop->SetPopupMenu( 2, pSubPop2 );
1107 pPop->SetPopupMenu( 3, pSubPop3 );
1108 return pPop;
1112 // Indentation for outlines (and sections)
1114 long SwContentTree::GetTabPos( SvTreeListEntry* pEntry, SvLBoxTab* pTab)
1116 sal_uInt16 nLevel = 0;
1117 if(lcl_IsContent(pEntry))
1119 nLevel++;
1120 SwContent* pCnt = (SwContent *) pEntry->GetUserData();
1121 const SwContentType* pParent;
1122 if(pCnt && 0 != (pParent = pCnt->GetParent()))
1124 if(pParent->GetType() == CONTENT_TYPE_OUTLINE)
1125 nLevel = nLevel + ((SwOutlineContent*)pCnt)->GetOutlineLevel();
1126 else if(pParent->GetType() == CONTENT_TYPE_REGION)
1127 nLevel = nLevel + ((SwRegionContent*)pCnt)->GetRegionLevel();
1130 sal_uInt16 nBasis = bIsRoot ? 0 : 5;
1131 return nLevel * 10 + nBasis + pTab->GetPos(); //determined empirically
1134 // Content will be integrated into the Box only on demand.
1136 void SwContentTree::RequestingChildren( SvTreeListEntry* pParent )
1138 // Is this a content type?
1139 if(lcl_IsContentType(pParent))
1141 if(!pParent->HasChildren())
1143 OSL_ENSURE(pParent->GetUserData(), "no UserData?");
1144 SwContentType* pCntType = (SwContentType*)pParent->GetUserData();
1146 sal_uInt16 nCount = pCntType->GetMemberCount();
1147 // Add for outline plus/minus
1148 if(pCntType->GetType() == CONTENT_TYPE_OUTLINE)
1150 SvTreeListEntry* pChild = 0;
1151 for(sal_uInt16 i = 0; i < nCount; i++)
1153 const SwContent* pCnt = pCntType->GetMember(i);
1154 if(pCnt)
1156 sal_uInt16 nLevel = ((SwOutlineContent*)pCnt)->GetOutlineLevel();
1157 String sEntry = pCnt->GetName();
1158 if(!sEntry.Len())
1159 sEntry = sSpace;
1160 if(!pChild || (nLevel == 0))
1161 pChild = InsertEntry(sEntry, pParent,
1162 sal_False, LIST_APPEND,(void*)pCnt);
1163 else
1165 //back search parent.
1166 if(((SwOutlineContent*)pCntType->GetMember(i-1))->GetOutlineLevel() < nLevel)
1167 pChild = InsertEntry(sEntry, pChild,
1168 sal_False, LIST_APPEND, (void*)pCnt);
1169 else
1171 pChild = Prev(pChild);
1172 while(pChild &&
1173 lcl_IsContent(pChild) &&
1174 !(((SwOutlineContent*)pChild->GetUserData())->GetOutlineLevel() < nLevel)
1177 pChild = Prev(pChild);
1179 if(pChild)
1180 pChild = InsertEntry(sEntry, pChild,
1181 sal_False, LIST_APPEND, (void*)pCnt);
1187 else
1189 for(sal_uInt16 i = 0; i < nCount; i++)
1191 const SwContent* pCnt = pCntType->GetMember(i);
1192 if(pCnt)
1194 String sEntry = pCnt->GetName();
1195 if(!sEntry.Len())
1196 sEntry = sSpace;
1197 InsertEntry(sEntry, pParent,
1198 sal_False, LIST_APPEND, (void*)pCnt);
1206 // Expand - Remember the state for content types.
1208 sal_Bool SwContentTree::Expand( SvTreeListEntry* pParent )
1210 if(!bIsRoot || (((SwContentType*)pParent->GetUserData())->GetType() == CONTENT_TYPE_OUTLINE) ||
1211 (nRootType == CONTENT_TYPE_OUTLINE))
1213 if(lcl_IsContentType(pParent))
1215 SwContentType* pCntType = (SwContentType*)pParent->GetUserData();
1216 sal_uInt16 nOr = 1 << pCntType->GetType(); //linear -> Bitposition
1217 if(bIsActive || bIsConstant)
1219 nActiveBlock |= nOr;
1220 pConfig->SetActiveBlock(nActiveBlock);
1222 else
1223 nHiddenBlock |= nOr;
1224 if((pCntType->GetType() == CONTENT_TYPE_OUTLINE))
1226 std::map< void*, bool > mCurrOutLineNodeMap;
1228 SwWrtShell* pShell = GetWrtShell();
1229 sal_Bool bBool = SvTreeListBox::Expand(pParent);
1230 SvTreeListEntry* pChild = Next(pParent);
1231 while(pChild && lcl_IsContent(pChild) && pParent->HasChildren())
1233 if(pChild->HasChildren())
1235 sal_Int32 nPos = ((SwContent*)pChild->GetUserData())->GetYPos();
1236 void* key = (void*)pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos );
1237 mCurrOutLineNodeMap.insert(std::map<void*, bool>::value_type( key, false ) );
1238 std::map<void*, bool>::iterator iter = mOutLineNodeMap.find( key );
1239 if( iter != mOutLineNodeMap.end() && mOutLineNodeMap[key])
1241 mCurrOutLineNodeMap[key] = true;
1242 SvTreeListBox::Expand(pChild);
1245 pChild = Next(pChild);
1247 mOutLineNodeMap = mCurrOutLineNodeMap;
1248 return bBool;
1252 else if( lcl_IsContent(pParent) )
1254 SwWrtShell* pShell = GetWrtShell();
1255 sal_Int32 nPos = ((SwContent*)pParent->GetUserData())->GetYPos();
1256 void* key = (void*)pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos );
1257 mOutLineNodeMap[key] = true;
1260 return SvTreeListBox::Expand(pParent);
1263 // Collapse - Remember the state for content types.
1265 sal_Bool SwContentTree::Collapse( SvTreeListEntry* pParent )
1267 sal_Bool bRet;
1268 if(!bIsRoot || (((SwContentType*)pParent->GetUserData())->GetType() == CONTENT_TYPE_OUTLINE) ||
1269 (nRootType == CONTENT_TYPE_OUTLINE))
1271 if(lcl_IsContentType(pParent))
1273 if(bIsRoot)
1274 return bRet = sal_False;
1275 SwContentType* pCntType = (SwContentType*)pParent->GetUserData();
1276 sal_uInt16 nAnd = 1 << pCntType->GetType();
1277 nAnd = ~nAnd;
1278 if(bIsActive || bIsConstant)
1280 nActiveBlock &= nAnd;
1281 pConfig->SetActiveBlock(nActiveBlock);
1283 else
1284 nHiddenBlock &= nAnd;
1286 else if( lcl_IsContent(pParent) )
1288 SwWrtShell* pShell = GetWrtShell();
1289 sal_Int32 nPos = ((SwContent*)pParent->GetUserData())->GetYPos();
1290 void* key = (void*)pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos );
1291 mOutLineNodeMap[key] = false;
1293 bRet = SvTreeListBox::Collapse(pParent);
1295 else
1296 bRet = SvTreeListBox::Collapse(pParent);
1297 return bRet;
1300 // Also on double click will be initially opened only.
1302 IMPL_LINK_NOARG(SwContentTree, ContentDoubleClickHdl)
1304 SvTreeListEntry* pEntry = GetCurEntry();
1305 // Is it a content type?
1306 OSL_ENSURE(pEntry, "no current entry!");
1307 if(pEntry)
1309 if(lcl_IsContentType(pEntry) && !pEntry->HasChildren())
1310 RequestingChildren(pEntry);
1311 else if(!lcl_IsContentType(pEntry) && (bIsActive || bIsConstant))
1313 if(bIsConstant)
1315 pActiveShell->GetView().GetViewFrame()->GetWindow().ToTop();
1317 //Jump to content type:
1318 SwContent* pCnt = (SwContent*)pEntry->GetUserData();
1319 OSL_ENSURE( pCnt, "no UserData");
1320 GotoContent(pCnt);
1321 if(pCnt->GetParent()->GetType() == CONTENT_TYPE_FRAME)
1322 pActiveShell->EnterStdMode();
1325 return 0;
1328 // Show the file
1330 void SwContentTree::Display( bool bActive )
1332 if(!bIsImageListInitialized)
1334 aEntryImages = ImageList(SW_RES(IMG_NAVI_ENTRYBMP));
1335 bIsImageListInitialized = true;
1337 // First read the selected entry to select it later again if necessary
1338 // -> the user data here are no longer valid!
1339 SvTreeListEntry* pOldSelEntry = FirstSelected();
1340 String sEntryName; // Name of the entry
1341 sal_uInt16 nEntryRelPos = 0; // relative position to their parent
1342 sal_uInt32 nOldEntryCount = GetEntryCount();
1343 sal_Int32 nOldScrollPos = 0;
1344 if(pOldSelEntry)
1346 ScrollBar* pVScroll = GetVScroll();
1347 if(pVScroll && pVScroll->IsVisible())
1348 nOldScrollPos = pVScroll->GetThumbPos();
1350 sEntryName = GetEntryText(pOldSelEntry);
1351 SvTreeListEntry* pParantEntry = pOldSelEntry;
1352 while( GetParent(pParantEntry))
1354 pParantEntry = GetParent(pParantEntry);
1356 if(GetParent(pOldSelEntry))
1358 nEntryRelPos = (sal_uInt16)(GetModel()->GetAbsPos(pOldSelEntry) - GetModel()->GetAbsPos(pParantEntry));
1361 Clear();
1362 SetUpdateMode( sal_False );
1363 if(bActive && !bIsConstant && !bIsActive)
1364 bIsActive = bActive;
1365 bIsHidden = !bActive;
1366 SwWrtShell* pShell = GetWrtShell();
1367 sal_Bool bReadOnly = pShell ? pShell->GetView().GetDocShell()->IsReadOnly() : sal_True;
1368 if(bReadOnly != bIsLastReadOnly)
1370 bIsLastReadOnly = bReadOnly;
1371 bool bDisable = pShell == 0 || bReadOnly;
1372 SwNavigationPI* pNavi = GetParentWindow();
1373 pNavi->aContentToolBox.EnableItem(FN_ITEM_UP , !bDisable);
1374 pNavi->aContentToolBox.EnableItem(FN_ITEM_DOWN, !bDisable);
1375 pNavi->aContentToolBox.EnableItem(FN_ITEM_LEFT, !bDisable);
1376 pNavi->aContentToolBox.EnableItem(FN_ITEM_RIGHT, !bDisable);
1377 pNavi->aContentToolBox.EnableItem(FN_SELECT_SET_AUTO_BOOKMARK, !bDisable);
1379 if(pShell)
1381 SvTreeListEntry* pSelEntry = 0;
1382 if(nRootType == USHRT_MAX)
1384 for(sal_uInt16 nCntType = CONTENT_TYPE_OUTLINE;
1385 nCntType <= CONTENT_TYPE_DRAWOBJECT; nCntType++ )
1387 SwContentType** ppContentT = bActive ?
1388 &aActiveContentArr[nCntType] :
1389 &aHiddenContentArr[nCntType];
1390 if(!*ppContentT)
1391 (*ppContentT) = new SwContentType(pShell, nCntType, nOutlineLevel );
1393 String sEntry = (*ppContentT)->GetName();
1394 SvTreeListEntry* pEntry;
1395 const Image& rImage = aEntryImages.GetImage(SID_SW_START + nCntType);
1396 sal_Bool bChOnDemand = 0 != (*ppContentT)->GetMemberCount();
1397 pEntry = InsertEntry(sEntry, rImage, rImage,
1398 0, bChOnDemand, LIST_APPEND, (*ppContentT));
1399 if(nCntType == nLastSelType)
1400 pSelEntry = pEntry;
1401 sal_Int32 nExpandOptions = bIsActive || bIsConstant ?
1402 nActiveBlock :
1403 nHiddenBlock;
1404 if(nExpandOptions & (1 << nCntType))
1406 Expand(pEntry);
1407 if(nEntryRelPos && nCntType == nLastSelType)
1409 // Now maybe select a additional child
1410 SvTreeListEntry* pChild = pEntry;
1411 SvTreeListEntry* pTemp = 0;
1412 sal_uInt16 nPos = 1;
1413 while(0 != (pChild = Next(pChild)))
1415 // The old text will be slightly favored
1416 if(sEntryName == GetEntryText(pChild) ||
1417 nPos == nEntryRelPos )
1419 pSelEntry = pChild;
1420 break;
1422 pTemp = pChild;
1423 nPos++;
1425 if(!pSelEntry || lcl_IsContentType(pSelEntry))
1426 pSelEntry = pTemp;
1431 if(pSelEntry)
1433 MakeVisible(pSelEntry);
1434 Select(pSelEntry);
1436 else
1437 nOldScrollPos = 0;
1439 else
1441 SwContentType** ppRootContentT = bActive ?
1442 &aActiveContentArr[nRootType] :
1443 &aHiddenContentArr[nRootType];
1444 if(!(*ppRootContentT))
1445 (*ppRootContentT) = new SwContentType(pShell, nRootType, nOutlineLevel );
1446 const Image& rImage = aEntryImages.GetImage(20000 + nRootType);
1447 SvTreeListEntry* pParent = InsertEntry(
1448 (*ppRootContentT)->GetName(), rImage, rImage,
1449 0, sal_False, LIST_APPEND, *ppRootContentT);
1451 if(nRootType != CONTENT_TYPE_OUTLINE)
1453 for(sal_uInt16 i = 0; i < (*ppRootContentT)->GetMemberCount(); i++ )
1455 const SwContent* pCnt = (*ppRootContentT)->GetMember(i);
1456 if(pCnt)
1458 String sEntry = pCnt->GetName();
1459 if(!sEntry.Len())
1460 sEntry = sSpace;
1461 InsertEntry( sEntry, pParent,
1462 sal_False, LIST_APPEND, (void*)pCnt);
1466 else
1467 RequestingChildren(pParent);
1468 Expand(pParent);
1469 if( nRootType == CONTENT_TYPE_OUTLINE && bIsActive )
1471 // find out where the cursor is
1472 const sal_uInt16 nActPos = pShell->GetOutlinePos(MAXLEVEL);
1473 SvTreeListEntry* pEntry = First();
1475 while( 0 != (pEntry = Next(pEntry)) )
1477 if(((SwOutlineContent*)pEntry->GetUserData())->GetPos() == nActPos)
1479 MakeVisible(pEntry);
1480 Select(pEntry);
1485 else
1487 // Now maybe select a additional child
1488 SvTreeListEntry* pChild = pParent;
1489 SvTreeListEntry* pTemp = 0;
1490 sal_uInt16 nPos = 1;
1491 while(0 != (pChild = Next(pChild)))
1493 // The old text will be slightly favored
1494 if(sEntryName == GetEntryText(pChild) ||
1495 nPos == nEntryRelPos )
1497 pSelEntry = pChild;
1498 break;
1500 pTemp = pChild;
1501 nPos++;
1503 if(!pSelEntry)
1504 pSelEntry = pTemp;
1505 if(pSelEntry)
1507 MakeVisible(pSelEntry);
1508 Select(pSelEntry);
1513 SetUpdateMode( sal_True );
1514 ScrollBar* pVScroll = GetVScroll();
1515 if(GetEntryCount() == nOldEntryCount &&
1516 nOldScrollPos && pVScroll && pVScroll->IsVisible()
1517 && pVScroll->GetThumbPos() != nOldScrollPos)
1519 sal_Int32 nDelta = pVScroll->GetThumbPos() - nOldScrollPos;
1520 ScrollOutputArea( (short)nDelta );
1525 // In the Clear the content types have to be deleted, also.
1527 void SwContentTree::Clear()
1529 SetUpdateMode(sal_False);
1530 SvTreeListBox::Clear();
1531 SetUpdateMode(sal_True);
1534 bool SwContentTree::FillTransferData( TransferDataContainer& rTransfer,
1535 sal_Int8& rDragMode )
1537 SwWrtShell* pWrtShell = GetWrtShell();
1538 OSL_ENSURE(pWrtShell, "no Shell!");
1539 SvTreeListEntry* pEntry = GetCurEntry();
1540 if(!pEntry || lcl_IsContentType(pEntry) || !pWrtShell)
1541 return false;
1542 String sEntry;
1543 SwContent* pCnt = ((SwContent*)pEntry->GetUserData());
1545 sal_uInt16 nActType = pCnt->GetParent()->GetType();
1546 String sUrl;
1547 bool bOutline = false;
1548 String sOutlineText;
1549 switch( nActType )
1551 case CONTENT_TYPE_OUTLINE:
1553 sal_uInt16 nPos = ((SwOutlineContent*)pCnt)->GetPos();
1554 OSL_ENSURE(nPos < pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineNodesCount(),
1555 "outlinecnt changed");
1557 // make sure outline may actually be copied
1558 if( pWrtShell->IsOutlineCopyable( nPos ) )
1560 const SwNumRule* pOutlRule = pWrtShell->GetOutlineNumRule();
1561 const SwTxtNode* pTxtNd =
1562 pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineNode(nPos);
1563 if( pTxtNd && pOutlRule && pTxtNd->IsNumbered())
1565 SwNumberTree::tNumberVector aNumVector =
1566 pTxtNd->GetNumberVector();
1567 for( sal_Int8 nLevel = 0;
1568 nLevel <= pTxtNd->GetActualListLevel();
1569 nLevel++ )
1571 sal_uInt16 nVal = (sal_uInt16)aNumVector[nLevel];
1572 nVal ++;
1573 nVal = nVal - pOutlRule->Get(nLevel).GetStart();
1574 sEntry += OUString::number( nVal );
1575 sEntry += '.';
1578 sEntry += pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineText(nPos, false);
1579 sOutlineText = pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineText(nPos, true);
1580 bIsOutlineMoveable = ((SwOutlineContent*)pCnt)->IsMoveable();
1581 bOutline = true;
1584 break;
1585 case CONTENT_TYPE_POSTIT:
1586 case CONTENT_TYPE_INDEX:
1587 case CONTENT_TYPE_REFERENCE :
1588 // cannot inserted as URL or as koennen weder als URL noch als region
1589 break;
1590 case CONTENT_TYPE_URLFIELD:
1591 sUrl = ((SwURLFieldContent*)pCnt)->GetURL();
1592 // no break;
1593 case CONTENT_TYPE_OLE:
1594 case CONTENT_TYPE_GRAPHIC:
1595 if(GetParentWindow()->GetRegionDropMode() != REGION_MODE_NONE)
1596 break;
1597 else
1598 rDragMode &= ~( DND_ACTION_MOVE | DND_ACTION_LINK );
1599 default:
1600 sEntry = GetEntryText(pEntry);
1603 bool bRet = false;
1604 if(sEntry.Len())
1606 const SwDocShell* pDocShell = pWrtShell->GetView().GetDocShell();
1607 if(!sUrl.Len())
1609 if(pDocShell->HasName())
1611 SfxMedium* pMedium = pDocShell->GetMedium();
1612 sUrl = pMedium->GetURLObject().GetURLNoMark();
1613 // only if a primarily link shall be integrated.
1614 bRet = true;
1616 else if( nActType == CONTENT_TYPE_REGION ||
1617 nActType == CONTENT_TYPE_BOOKMARK )
1619 // For field and bookmarks a link is also allowed
1620 // without a filename into its own document.
1621 bRet = true;
1623 else if(bIsConstant &&
1624 ( !::GetActiveView() ||
1625 pActiveShell != ::GetActiveView()->GetWrtShellPtr()))
1627 // Urls of inactive views cannot dragged without
1628 // file names, also.
1629 bRet = false;
1631 else
1633 bRet = GetParentWindow()->GetRegionDropMode() == REGION_MODE_NONE;
1634 rDragMode = DND_ACTION_MOVE;
1637 const String& rToken = pCnt->GetParent()->GetTypeToken();
1638 sUrl += '#';
1639 sUrl += sEntry;
1640 if(rToken.Len())
1642 sUrl += cMarkSeparator;
1643 sUrl += rToken;
1646 else
1647 bRet = true;
1649 if( bRet )
1651 // In Outlines of heading text must match
1652 // the real number into the description.
1653 if(bOutline)
1654 sEntry = sOutlineText;
1657 NaviContentBookmark aBmk( sUrl, sEntry,
1658 GetParentWindow()->GetRegionDropMode(),
1659 pDocShell);
1660 aBmk.Copy( rTransfer );
1663 // An INetBookmark must a be delivered to foreign DocShells
1664 if( pDocShell->HasName() )
1666 INetBookmark aBkmk( sUrl, sEntry );
1667 rTransfer.CopyINetBookmark( aBkmk );
1671 return bRet;
1674 // Switch the display to Root
1676 bool SwContentTree::ToggleToRoot()
1678 if(!bIsRoot)
1680 SvTreeListEntry* pEntry = GetCurEntry();
1681 const SwContentType* pCntType;
1682 if(pEntry)
1684 if(lcl_IsContentType(pEntry))
1685 pCntType = (SwContentType*)pEntry->GetUserData();
1686 else
1687 pCntType = ((SwContent*)pEntry->GetUserData())->GetParent();
1688 nRootType = pCntType->GetType();
1689 bIsRoot = true;
1690 Display(bIsActive || bIsConstant);
1693 else
1695 nRootType = USHRT_MAX;
1696 bIsRoot = false;
1697 FindActiveTypeAndRemoveUserData();
1698 Display(bIsActive || bIsConstant);
1700 pConfig->SetRootType( nRootType );
1701 GetParentWindow()->aContentToolBox.CheckItem(FN_SHOW_ROOT, bIsRoot ? sal_True : sal_False);
1702 return bIsRoot;
1705 // Check if the displayed content is valid.
1707 bool SwContentTree::HasContentChanged()
1710 // - Run through the local array and the Treelistbox in parallel.
1711 // - Are the records not expanded, they are discarded only in the array
1712 // and the content type will be set as the new UserData.
1713 // - Is the root mode is active only this will be updated.
1715 // Valid for the displayed content types is:
1716 // the Memberlist will be erased and the membercount will be updated
1717 // If content will be checked, the memberlists will be replenished
1718 // at the same time. Once a difference occurs it will be only replenished
1719 // no longer checked. Finally, the box is filled again.
1721 bool bRepaint = false;
1722 sal_Bool bInvalidate = sal_False;
1724 if(!bIsActive && ! bIsConstant)
1726 for(sal_uInt16 i=0; i < CONTENT_TYPE_MAX; i++)
1728 if(aActiveContentArr[i])
1729 aActiveContentArr[i]->Invalidate();
1732 else if(bIsRoot)
1734 bool bOutline = false;
1735 SvTreeListEntry* pEntry = First();
1736 if(!pEntry)
1737 bRepaint = true;
1738 else
1740 sal_uInt16 nType = ((SwContentType*)pEntry->GetUserData())->GetType();
1741 bOutline = nRootType == CONTENT_TYPE_OUTLINE;
1742 SwContentType* pArrType = aActiveContentArr[nType];
1743 if(!pArrType)
1744 bRepaint = true;
1745 else
1747 sal_uInt16 nSelLevel = USHRT_MAX;
1749 SvTreeListEntry* pFirstSel;
1750 if(bOutline &&
1751 0 != ( pFirstSel = FirstSelected()) &&
1752 lcl_IsContent(pFirstSel))
1754 nSelLevel = ((SwOutlineContent*)pFirstSel->GetUserData())->GetOutlineLevel();
1755 SwWrtShell* pSh = GetWrtShell();
1756 sal_uInt16 nOutlinePos = pSh->GetOutlinePos(MAXLEVEL);
1757 if (nOutlinePos != USHRT_MAX &&
1758 pSh->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos) != nSelLevel)
1759 bRepaint = true;
1762 pArrType->Init(&bInvalidate);
1763 pArrType->FillMemberList();
1764 pEntry->SetUserData((void*)pArrType);
1765 if(!bRepaint)
1767 if(GetChildCount(pEntry) != pArrType->GetMemberCount())
1768 bRepaint = true;
1769 else
1771 sal_uInt16 nChildCount = (sal_uInt16)GetChildCount(pEntry);
1772 for(sal_uInt16 j = 0; j < nChildCount; j++)
1774 pEntry = Next(pEntry);
1775 const SwContent* pCnt = pArrType->GetMember(j);
1776 pEntry->SetUserData((void*)pCnt);
1777 String sEntryText = GetEntryText(pEntry);
1778 if( sEntryText != pCnt->GetName() &&
1779 !(sEntryText == sSpace && !pCnt->GetName().Len()))
1780 bRepaint = true;
1786 if( !bRepaint && bOutline )
1788 // find out where the cursor is
1789 const sal_uInt16 nActPos = GetWrtShell()->GetOutlinePos(MAXLEVEL);
1790 SvTreeListEntry* pFirstEntry = First();
1792 while( 0 != (pFirstEntry = Next(pFirstEntry)) )
1794 if(((SwOutlineContent*)pFirstEntry->GetUserData())->GetPos() == nActPos)
1796 if(FirstSelected() != pFirstEntry)
1798 Select(pFirstEntry);
1799 MakeVisible(pFirstEntry);
1807 else
1809 SvTreeListEntry* pEntry = First();
1810 while ( pEntry )
1812 bool bNext = true; // at least a next must be
1813 SwContentType* pTreeType = (SwContentType*)pEntry->GetUserData();
1814 sal_uInt16 nType = pTreeType->GetType();
1815 sal_uInt16 nTreeCount = pTreeType->GetMemberCount();
1816 SwContentType* pArrType = aActiveContentArr[nType];
1817 if(!pArrType)
1818 bRepaint = true;
1819 else
1821 pArrType->Init(&bInvalidate);
1822 pEntry->SetUserData((void*)pArrType);
1823 if(IsExpanded(pEntry))
1825 sal_Bool bLevelOrVisibiblityChanged = sal_False;
1826 // bLevelOrVisibiblityChanged is set if outlines have changed their level
1827 // or if the visibility of objects (frames, sections, tables) has changed
1828 // i.e. in header/footer
1829 pArrType->FillMemberList(&bLevelOrVisibiblityChanged);
1830 sal_uInt16 nChildCount = (sal_uInt16)GetChildCount(pEntry);
1831 if((nType == CONTENT_TYPE_OUTLINE) && bLevelOrVisibiblityChanged)
1832 bRepaint = true;
1833 if(bLevelOrVisibiblityChanged)
1834 bInvalidate = sal_True;
1836 if(nChildCount != pArrType->GetMemberCount())
1837 bRepaint = true;
1838 else
1840 for(sal_uInt16 j = 0; j < nChildCount; j++)
1842 pEntry = Next(pEntry);
1843 bNext = false;
1844 const SwContent* pCnt = pArrType->GetMember(j);
1845 pEntry->SetUserData((void*)pCnt);
1846 String sEntryText = GetEntryText(pEntry);
1847 if( sEntryText != pCnt->GetName() &&
1848 !(sEntryText == sSpace && !pCnt->GetName().Len()))
1849 bRepaint = true;
1854 else if(pEntry->HasChildren())
1856 // was the entry once opened, then must also the
1857 // invisible records be examined.
1858 // At least the user data must be updated.
1859 sal_Bool bLevelOrVisibiblityChanged = sal_False;
1860 // bLevelOrVisibiblityChanged is set if outlines have changed their level
1861 // or if the visibility of objects (frames, sections, tables) has changed
1862 // i.e. in header/footer
1863 pArrType->FillMemberList(&bLevelOrVisibiblityChanged);
1864 sal_Bool bRemoveChildren = sal_False;
1865 sal_uInt16 nChildCount = (sal_uInt16)GetChildCount(pEntry);
1866 if( nChildCount != pArrType->GetMemberCount() )
1868 bRemoveChildren = sal_True;
1870 else
1872 SvTreeListEntry* pChild = FirstChild(pEntry);
1873 for(sal_uInt16 j = 0; j < nChildCount; j++)
1875 const SwContent* pCnt = pArrType->GetMember(j);
1876 pChild->SetUserData((void*)pCnt);
1877 String sEntryText = GetEntryText(pChild);
1878 if( sEntryText != pCnt->GetName() &&
1879 !(sEntryText == sSpace && !pCnt->GetName().Len()))
1880 bRemoveChildren = sal_True;
1881 pChild = Next(pChild);
1884 if(bRemoveChildren)
1886 SvTreeListEntry* pChild = FirstChild(pEntry);
1887 SvTreeListEntry* pRemove = pChild;
1888 for(sal_uInt16 j = 0; j < nChildCount; j++)
1890 pChild = Next(pRemove);
1891 GetModel()->Remove(pRemove);
1892 pRemove = pChild;
1895 if(!nChildCount)
1897 pEntry->EnableChildrenOnDemand(sal_False);
1898 InvalidateEntry(pEntry);
1902 else if((nTreeCount != 0)
1903 != (pArrType->GetMemberCount()!=0))
1905 bRepaint = true;
1908 // The Root-Entry has to be found now
1909 while( pEntry && (bNext || GetParent(pEntry ) ))
1911 pEntry = Next(pEntry);
1912 bNext = false;
1916 if(!bRepaint && bInvalidate)
1917 Invalidate();
1918 return bRepaint;
1921 // Before any data will be deleted, the last active entry has to be found.
1922 // After this the UserData will be deleted
1924 void SwContentTree::FindActiveTypeAndRemoveUserData()
1926 SvTreeListEntry* pEntry = FirstSelected();
1927 if(pEntry)
1929 // If clear is called by TimerUpdate:
1930 // Only for root can the validity of the UserData be guaranteed.
1931 SvTreeListEntry* pParent;
1932 while(0 != (pParent = GetParent(pEntry)))
1933 pEntry = pParent;
1934 if(pEntry->GetUserData() && lcl_IsContentType(pEntry))
1935 nLastSelType = ((SwContentType*)pEntry->GetUserData())->GetType();
1937 pEntry = First();
1938 while(pEntry)
1940 pEntry->SetUserData(0);
1941 pEntry = Next(pEntry);
1945 // After a file is dropped on the Navigator,
1946 // the new shell will be set.
1948 void SwContentTree::SetHiddenShell(SwWrtShell* pSh)
1950 pHiddenShell = pSh;
1951 bIsHidden = true;
1952 bIsActive = bIsConstant = false;
1953 FindActiveTypeAndRemoveUserData();
1954 for(sal_uInt16 i=0; i < CONTENT_TYPE_MAX; i++)
1956 DELETEZ(aHiddenContentArr[i]);
1958 Display(bIsActive);
1960 GetParentWindow()->UpdateListBox();
1963 // Document change - set new Shell
1965 void SwContentTree::SetActiveShell(SwWrtShell* pSh)
1967 if(bIsInternalDrag)
1968 bDocChgdInDragging = true;
1969 bool bClear = pActiveShell != pSh;
1970 if(bIsActive && bClear)
1972 pActiveShell = pSh;
1973 FindActiveTypeAndRemoveUserData();
1974 Clear();
1976 else if(bIsConstant)
1978 if(!lcl_FindShell(pActiveShell))
1980 pActiveShell = pSh;
1981 bIsActive = true;
1982 bIsConstant = false;
1983 bClear = true;
1986 // Only if it is the active view, the array will be deleted and
1987 // the screen filled new.
1988 if(bIsActive && bClear)
1990 FindActiveTypeAndRemoveUserData();
1991 for(sal_uInt16 i=0; i < CONTENT_TYPE_MAX; i++)
1993 DELETEZ(aActiveContentArr[i]);
1995 Display(true);
1999 // Set an open view as active.
2001 void SwContentTree::SetConstantShell(SwWrtShell* pSh)
2003 pActiveShell = pSh;
2004 bIsActive = false;
2005 bIsConstant = true;
2006 FindActiveTypeAndRemoveUserData();
2007 for(sal_uInt16 i=0; i < CONTENT_TYPE_MAX; i++)
2009 DELETEZ(aActiveContentArr[i]);
2011 Display(true);
2014 // Execute commands of the Navigator
2016 void SwContentTree::ExecCommand(sal_uInt16 nCmd, sal_Bool bModifier)
2018 bool nMove = false;
2019 switch( nCmd )
2021 case FN_ITEM_DOWN:
2022 case FN_ITEM_UP: nMove = true;
2023 case FN_ITEM_LEFT:
2024 case FN_ITEM_RIGHT:
2025 if( !GetWrtShell()->GetView().GetDocShell()->IsReadOnly() &&
2026 (bIsActive ||
2027 (bIsConstant && pActiveShell == GetParentWindow()->GetCreateView()->GetWrtShellPtr())))
2029 SwWrtShell* pShell = GetWrtShell();
2030 sal_Int8 nActOutlineLevel = nOutlineLevel;
2031 sal_uInt16 nActPos = pShell->GetOutlinePos(nActOutlineLevel);
2032 SvTreeListEntry* pFirstEntry = FirstSelected();
2033 if (pFirstEntry && lcl_IsContent(pFirstEntry))
2035 if ( (bIsRoot && nRootType == CONTENT_TYPE_OUTLINE) ||
2036 ((SwContent*)pFirstEntry->GetUserData())->GetParent()->GetType()
2037 == CONTENT_TYPE_OUTLINE)
2039 nActPos = ((SwOutlineContent*)pFirstEntry->GetUserData())->GetPos();
2042 if ( nActPos < USHRT_MAX &&
2043 ( !nMove || pShell->IsOutlineMovable( nActPos )) )
2045 pShell->StartAllAction();
2046 pShell->GotoOutline( nActPos); // If text selection != box selection
2047 pShell->Push();
2048 pShell->MakeOutlineSel( nActPos, nActPos,
2049 bModifier);
2050 if( nMove )
2052 short nDir = nCmd == FN_ITEM_UP ? -1 : 1;
2053 if( !bModifier && ( (nDir == -1 && nActPos > 0) ||
2054 (nDir == 1 && nActPos < GetEntryCount() - 2) ) )
2056 pShell->MoveOutlinePara( nDir );
2057 // Set cursor back to the current position
2058 pShell->GotoOutline( nActPos + nDir);
2060 else if(bModifier)
2062 sal_uInt16 nActEndPos = nActPos;
2063 SvTreeListEntry* pEntry = pFirstEntry;
2064 sal_uInt16 nActLevel = ((SwOutlineContent*)
2065 pFirstEntry->GetUserData())->GetOutlineLevel();
2066 pEntry = Next(pEntry);
2067 while( pEntry && CONTENT_TYPE_OUTLINE ==
2068 ((SwTypeNumber*)pEntry->GetUserData())->GetTypeId() )
2070 if(nActLevel >= ((SwOutlineContent*)
2071 pEntry->GetUserData())->GetOutlineLevel())
2072 break;
2073 pEntry = Next(pEntry);
2074 nActEndPos++;
2076 sal_uInt16 nDest;
2077 if(nDir == 1)
2079 // If the last entry is to be moved it is over!
2080 if(pEntry && CONTENT_TYPE_OUTLINE ==
2081 ((SwTypeNumber*)pEntry->GetUserData())->GetTypeId())
2083 // pEntry now points to the following entry of the last
2084 // selected entry.
2085 nDest = nActEndPos;
2086 nDest++;
2087 // here needs to found the next record after next.
2088 // The selection must be inserted in front of.
2089 while(pEntry )
2091 pEntry = Next(pEntry);
2092 // nDest++ may only executed if pEntry != 0
2093 if(pEntry && nDest++ &&
2094 ( nActLevel >= ((SwOutlineContent*)pEntry->GetUserData())->GetOutlineLevel()||
2095 CONTENT_TYPE_OUTLINE != ((SwTypeNumber*)pEntry->GetUserData())->GetTypeId()))
2097 nDest--;
2098 break;
2101 nDir = nDest - nActEndPos;
2102 // If no entry was found which corresponds the condition
2103 // of the previously paste, it needs to be pushed slightly less.
2105 else
2106 nDir = 0;
2108 else
2110 nDest = nActPos;
2111 pEntry = pFirstEntry;
2112 while(pEntry && nDest )
2114 nDest--;
2115 pEntry = Prev(pEntry);
2116 if(pEntry &&
2117 (nActLevel >= ((SwOutlineContent*)pEntry->GetUserData())->GetOutlineLevel()||
2118 CONTENT_TYPE_OUTLINE !=
2119 ((SwTypeNumber*)pEntry->GetUserData())->GetTypeId()))
2121 break;
2124 nDir = nDest - nActPos;
2126 if(nDir)
2128 pShell->MoveOutlinePara( nDir );
2129 //Set cursor back to the current position
2130 pShell->GotoOutline( nActPos + nDir);
2134 else
2136 if( !pShell->IsProtectedOutlinePara() )
2137 pShell->OutlineUpDown( nCmd == FN_ITEM_LEFT ? -1 : 1 );
2140 pShell->ClearMark();
2141 pShell->Pop(sal_False); // Cursor is now back at the current superscription.
2142 pShell->EndAllAction();
2143 if(aActiveContentArr[CONTENT_TYPE_OUTLINE])
2144 aActiveContentArr[CONTENT_TYPE_OUTLINE]->Invalidate();
2145 Display(true);
2146 if(!bIsRoot)
2148 const sal_uInt16 nCurrPos = pShell->GetOutlinePos(MAXLEVEL);
2149 SvTreeListEntry* pFirst = First();
2151 while( 0 != (pFirst = Next(pFirst)) && lcl_IsContent(pFirst))
2153 if(((SwOutlineContent*)pFirst->GetUserData())->GetPos() == nCurrPos)
2155 Select(pFirst);
2156 MakeVisible(pFirst);
2165 void SwContentTree::ShowTree()
2167 aUpdTimer.Start();
2168 SvTreeListBox::Show();
2171 // folded together will not be geidled
2173 void SwContentTree::HideTree()
2175 aUpdTimer.Stop();
2176 SvTreeListBox::Hide();
2179 // No idle with focus or while dragging.
2181 IMPL_LINK_NOARG(SwContentTree, TimerUpdate)
2183 // No update while drag and drop.
2184 // Query view because the Navigator is cleared too late.
2185 SwView* pView = GetParentWindow()->GetCreateView();
2186 if( (!HasFocus() || bViewHasChanged) &&
2187 !bIsInDrag && !bIsInternalDrag && pView &&
2188 pView->GetWrtShellPtr() && !pView->GetWrtShellPtr()->ActionPend() )
2190 bViewHasChanged = false;
2191 bIsIdleClear = false;
2192 SwWrtShell* pActShell = pView->GetWrtShellPtr();
2193 if( bIsConstant && !lcl_FindShell( pActiveShell ) )
2195 SetActiveShell(pActShell);
2196 GetParentWindow()->UpdateListBox();
2199 if(bIsActive && pActShell != GetWrtShell())
2200 SetActiveShell(pActShell);
2201 else if( (bIsActive || (bIsConstant && pActShell == GetWrtShell())) &&
2202 HasContentChanged())
2204 FindActiveTypeAndRemoveUserData();
2205 Display(true);
2208 else if(!pView && bIsActive && !bIsIdleClear)
2210 if(pActiveShell)
2211 SetActiveShell(0);
2212 Clear();
2213 bIsIdleClear = true;
2215 return 0;
2218 DragDropMode SwContentTree::NotifyStartDrag(
2219 TransferDataContainer& rContainer,
2220 SvTreeListEntry* pEntry )
2222 DragDropMode eMode = (DragDropMode)0;
2223 if( bIsActive && nRootType == CONTENT_TYPE_OUTLINE &&
2224 GetModel()->GetAbsPos( pEntry ) > 0
2225 && !GetWrtShell()->GetView().GetDocShell()->IsReadOnly())
2226 eMode = GetDragDropMode();
2227 else if(!bIsActive && GetWrtShell()->GetView().GetDocShell()->HasName())
2228 eMode = SV_DRAGDROP_APP_COPY;
2230 sal_Int8 nDragMode;
2231 FillTransferData( rContainer, nDragMode );
2232 bDocChgdInDragging = false;
2233 bIsInternalDrag = true;
2234 return eMode;
2236 // After the drag the current paragraph will be moved w i t h the children.
2238 sal_Bool SwContentTree::NotifyMoving( SvTreeListEntry* pTarget,
2239 SvTreeListEntry* pEntry, SvTreeListEntry*& , sal_uLong& )
2241 if(!bDocChgdInDragging)
2243 sal_uInt16 nTargetPos = 0;
2244 sal_uInt16 nSourcePos = (( SwOutlineContent* )pEntry->GetUserData())->GetPos();
2245 if(!lcl_IsContent(pTarget))
2246 nTargetPos = USHRT_MAX;
2247 else
2248 nTargetPos = (( SwOutlineContent* )pTarget->GetUserData())->GetPos();
2249 if( MAXLEVEL > nOutlineLevel && // Not all layers are displayed.
2250 nTargetPos != USHRT_MAX)
2252 SvTreeListEntry* pNext = Next(pTarget);
2253 if(pNext)
2254 nTargetPos = (( SwOutlineContent* )pNext->GetUserData())->GetPos() -1;
2255 else
2256 nTargetPos = static_cast<sal_uInt16>(GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount())- 1;
2260 OSL_ENSURE( pEntry &&
2261 lcl_IsContent(pEntry),"Source == 0 or Source has no Content" );
2262 GetParentWindow()->MoveOutline( nSourcePos,
2263 nTargetPos,
2264 true);
2266 aActiveContentArr[CONTENT_TYPE_OUTLINE]->Invalidate();
2267 Display(true);
2269 //TreeListBox will be reloaded from the document
2270 return sal_False;
2273 // After the drag the current paragraph will be moved w i t h o u t the children.
2275 sal_Bool SwContentTree::NotifyCopying( SvTreeListEntry* pTarget,
2276 SvTreeListEntry* pEntry, SvTreeListEntry*& , sal_uLong& )
2278 if(!bDocChgdInDragging)
2280 sal_uInt16 nTargetPos = 0;
2281 sal_uInt16 nSourcePos = (( SwOutlineContent* )pEntry->GetUserData())->GetPos();
2282 if(!lcl_IsContent(pTarget))
2283 nTargetPos = USHRT_MAX;
2284 else
2285 nTargetPos = (( SwOutlineContent* )pTarget->GetUserData())->GetPos();
2287 if( MAXLEVEL > nOutlineLevel && // Not all layers are displayed.
2288 nTargetPos != USHRT_MAX)
2290 SvTreeListEntry* pNext = Next(pTarget);
2291 if(pNext)
2292 nTargetPos = (( SwOutlineContent* )pNext->GetUserData())->GetPos() - 1;
2293 else
2294 nTargetPos = static_cast<sal_uInt16>(GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount()) - 1;
2298 OSL_ENSURE( pEntry &&
2299 lcl_IsContent(pEntry),"Source == 0 or Source has no Content" );
2300 GetParentWindow()->MoveOutline( nSourcePos, nTargetPos, false);
2302 //TreeListBox will be reloaded from the document
2303 aActiveContentArr[CONTENT_TYPE_OUTLINE]->Invalidate();
2304 Display(true);
2306 return sal_False;
2309 // No drop before the first entry - it's a SwContentType
2311 sal_Bool SwContentTree::NotifyAcceptDrop( SvTreeListEntry* pEntry)
2313 return pEntry != 0;
2316 // If a Ctrl + DoubleClick are executed in an open area,
2317 // then the base function of the control is to be called.
2319 void SwContentTree::MouseButtonDown( const MouseEvent& rMEvt )
2321 Point aPos( rMEvt.GetPosPixel());
2322 SvTreeListEntry* pEntry = GetEntry( aPos, sal_True );
2323 if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
2324 Control::MouseButtonDown( rMEvt );
2325 else
2326 SvTreeListBox::MouseButtonDown( rMEvt );
2329 // Update immediately
2331 void SwContentTree::GetFocus()
2333 SwView* pActView = GetParentWindow()->GetCreateView();
2334 if(pActView)
2336 SwWrtShell* pActShell = pActView->GetWrtShellPtr();
2337 if(bIsConstant && !lcl_FindShell(pActiveShell))
2339 SetActiveShell(pActShell);
2342 if(bIsActive && pActShell != GetWrtShell())
2343 SetActiveShell(pActShell);
2344 else if( (bIsActive || (bIsConstant && pActShell == GetWrtShell())) &&
2345 HasContentChanged())
2347 Display(true);
2350 else if(bIsActive)
2351 Clear();
2352 SvTreeListBox::GetFocus();
2355 void SwContentTree::KeyInput(const KeyEvent& rEvent)
2357 const KeyCode aCode = rEvent.GetKeyCode();
2358 if(aCode.GetCode() == KEY_RETURN)
2360 SvTreeListEntry* pEntry = FirstSelected();
2361 if ( pEntry )
2363 switch(aCode.GetModifier())
2365 case KEY_MOD2:
2366 // Switch boxes
2367 GetParentWindow()->ToggleTree();
2368 break;
2369 case KEY_MOD1:
2370 // Switch RootMode
2371 ToggleToRoot();
2372 break;
2373 case 0:
2374 if(lcl_IsContentType(pEntry))
2376 IsExpanded(pEntry) ?
2377 Collapse(pEntry) :
2378 Expand(pEntry);
2380 else
2381 ContentDoubleClickHdl(0);
2382 break;
2386 else if(aCode.GetCode() == KEY_DELETE && 0 == aCode.GetModifier())
2388 SvTreeListEntry* pEntry = FirstSelected();
2389 if(pEntry &&
2390 lcl_IsContent(pEntry) &&
2391 ((SwContent*)pEntry->GetUserData())->GetParent()->IsDeletable() &&
2392 !pActiveShell->GetView().GetDocShell()->IsReadOnly())
2394 EditEntry(pEntry, EDIT_MODE_DELETE);
2395 bViewHasChanged = true;
2396 GetParentWindow()->UpdateListBox();
2397 TimerUpdate(&aUpdTimer);
2398 GrabFocus();
2401 else
2402 SvTreeListBox::KeyInput(rEvent);
2406 void SwContentTree::RequestHelp( const HelpEvent& rHEvt )
2408 bool bCallBase = true;
2409 if( rHEvt.GetMode() & HELPMODE_QUICK )
2411 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
2412 SvTreeListEntry* pEntry = GetEntry( aPos );
2413 if( pEntry )
2415 sal_uInt16 nType;
2416 bool bBalloon = false;
2417 bool bContent = false;
2418 void* pUserData = pEntry->GetUserData();
2419 if(lcl_IsContentType(pEntry))
2420 nType = ((SwContentType*)pUserData)->GetType();
2421 else
2423 nType = ((SwContent*)pUserData)->GetParent()->GetType();
2424 bContent = true;
2426 String sEntry;
2427 bool bRet = false;
2428 if(bContent)
2430 switch( nType )
2432 case CONTENT_TYPE_URLFIELD:
2433 sEntry = ((SwURLFieldContent*)pUserData)->GetURL();
2434 bRet = true;
2435 break;
2437 case CONTENT_TYPE_POSTIT:
2438 sEntry = ((SwPostItContent*)pUserData)->GetName();
2439 bRet = true;
2440 if(Help::IsBalloonHelpEnabled())
2441 bBalloon = true;
2442 break;
2443 case CONTENT_TYPE_OUTLINE:
2444 sEntry = ((SwOutlineContent*)pUserData)->GetName();
2445 bRet = true;
2446 break;
2447 case CONTENT_TYPE_GRAPHIC:
2448 sEntry = ((SwGraphicContent*)pUserData)->GetLink();
2449 #if OSL_DEBUG_LEVEL > 1
2450 sEntry += ' ';
2451 sEntry += OUString::number(
2452 ((SwGraphicContent*)pUserData)->GetYPos());
2453 #endif
2454 bRet = true;
2455 break;
2456 #if OSL_DEBUG_LEVEL > 1
2457 case CONTENT_TYPE_TABLE:
2458 case CONTENT_TYPE_FRAME:
2459 sEntry = OUString::number(
2460 ((SwContent*)pUserData)->GetYPos() );
2461 bRet = true;
2462 break;
2463 #endif
2465 if(((SwContent*)pUserData)->IsInvisible())
2467 if(sEntry.Len())
2468 sEntry += OUString(", ");
2469 sEntry += sInvisible;
2470 bRet = true;
2473 else
2475 sal_uInt16 nMemberCount = ((SwContentType*)pUserData)->GetMemberCount();
2476 sEntry = OUString::number(nMemberCount);
2477 sEntry += ' ';
2478 sEntry += nMemberCount == 1
2479 ? ((SwContentType*)pUserData)->GetSingleName()
2480 : ((SwContentType*)pUserData)->GetName();
2481 bRet = true;
2483 if(bRet)
2485 SvLBoxTab* pTab;
2486 SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
2487 if (pItem && SV_ITEM_ID_LBOXSTRING == pItem->GetType())
2489 aPos = GetEntryPosition( pEntry );
2491 aPos.X() = GetTabPos( pEntry, pTab );
2492 Size aSize( pItem->GetSize( this, pEntry ) );
2494 if((aPos.X() + aSize.Width()) > GetSizePixel().Width())
2495 aSize.Width() = GetSizePixel().Width() - aPos.X();
2497 aPos = OutputToScreenPixel(aPos);
2498 Rectangle aItemRect( aPos, aSize );
2499 if(bBalloon)
2501 aPos.X() += aSize.Width();
2502 Help::ShowBalloon( this, aPos, aItemRect, sEntry );
2504 else
2505 Help::ShowQuickHelp( this, aItemRect, sEntry,
2506 QUICKHELP_LEFT|QUICKHELP_VCENTER );
2507 bCallBase = false;
2510 else
2512 Help::ShowQuickHelp( this, Rectangle(), aEmptyStr, 0 );
2513 bCallBase = false;
2517 if( bCallBase )
2518 Window::RequestHelp( rHEvt );
2521 void SwContentTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
2523 SvTreeListEntry* pFirst = FirstSelected();
2524 switch( nSelectedPopupEntry )
2526 //Outlinelevel
2527 case 101:
2528 case 102:
2529 case 103:
2530 case 104:
2531 case 105:
2532 case 106:
2533 case 107:
2534 case 108:
2535 case 109:
2536 case 110:
2537 nSelectedPopupEntry -= 100;
2538 if(nOutlineLevel != nSelectedPopupEntry )
2539 SetOutlineLevel((sal_Int8)nSelectedPopupEntry);
2540 break;
2541 case 201:
2542 case 202:
2543 case 203:
2544 GetParentWindow()->SetRegionDropMode(nSelectedPopupEntry - 201);
2545 break;
2546 case 401:
2547 case 402:
2548 EditEntry(pFirst, nSelectedPopupEntry == 401 ? EDIT_MODE_RMV_IDX : EDIT_MODE_UPD_IDX);
2549 break;
2550 // Edit entry
2551 case 403:
2552 EditEntry(pFirst, EDIT_MODE_EDIT);
2553 break;
2554 case 404:
2555 EditEntry(pFirst, EDIT_UNPROTECT_TABLE);
2556 break;
2557 case 405 :
2559 const SwTOXBase* pBase = ((SwTOXBaseContent*)pFirst->GetUserData())
2560 ->GetTOXBase();
2561 pActiveShell->SetTOXBaseReadonly(*pBase, !pActiveShell->IsTOXBaseReadonly(*pBase));
2563 break;
2564 case 4:
2565 break;
2566 case 501:
2567 EditEntry(pFirst, EDIT_MODE_DELETE);
2568 break;
2569 case 502 :
2570 EditEntry(pFirst, EDIT_MODE_RENAME);
2571 break;
2572 case 600:
2573 pActiveShell->GetView().GetPostItMgr()->Show();
2574 break;
2575 case 601:
2576 pActiveShell->GetView().GetPostItMgr()->Hide();
2577 break;
2578 case 602:
2580 pActiveShell->GetView().GetPostItMgr()->SetActiveSidebarWin(0);
2581 pActiveShell->GetView().GetPostItMgr()->Delete();
2582 break;
2584 //Display
2585 default:
2586 if(nSelectedPopupEntry > 300 && nSelectedPopupEntry < 400)
2588 nSelectedPopupEntry -= 300;
2589 SwView *pView = SwModule::GetFirstView();
2590 while (pView)
2592 nSelectedPopupEntry --;
2593 if(nSelectedPopupEntry == 0)
2595 SetConstantShell(&pView->GetWrtShell());
2596 break;
2598 pView = SwModule::GetNextView(pView);
2600 if(nSelectedPopupEntry)
2602 bViewHasChanged = bIsActive = nSelectedPopupEntry == 1;
2603 bIsConstant = false;
2604 Display(nSelectedPopupEntry == 1);
2608 GetParentWindow()->UpdateListBox();
2611 void SwContentTree::SetOutlineLevel(sal_uInt8 nSet)
2613 nOutlineLevel = nSet;
2614 pConfig->SetOutlineLevel( nOutlineLevel );
2615 SwContentType** ppContentT = bIsActive ?
2616 &aActiveContentArr[CONTENT_TYPE_OUTLINE] :
2617 &aHiddenContentArr[CONTENT_TYPE_OUTLINE];
2618 if(*ppContentT)
2620 (*ppContentT)->SetOutlineLevel(nOutlineLevel);
2621 (*ppContentT)->Init();
2623 Display(bIsActive);
2626 // Mode Change: Show dropped Doc
2628 void SwContentTree::ShowHiddenShell()
2630 if(pHiddenShell)
2632 bIsConstant = false;
2633 bIsActive = false;
2634 Display(false);
2638 // Mode Change: Show active view
2640 void SwContentTree::ShowActualView()
2642 bIsActive = true;
2643 bIsConstant = false;
2644 Display(true);
2645 GetParentWindow()->UpdateListBox();
2648 // Here are the buttons for moving outlines are en-/disabled.
2650 sal_Bool SwContentTree::Select( SvTreeListEntry* pEntry, sal_Bool bSelect )
2652 if(!pEntry)
2653 return sal_False;
2654 sal_Bool bEnable = sal_False;
2655 SvTreeListEntry* pParentEntry = GetParent(pEntry);
2656 while(pParentEntry && (!lcl_IsContentType(pParentEntry)))
2658 pParentEntry = GetParent(pParentEntry);
2660 if(!bIsLastReadOnly && (!IsVisible() ||
2661 ( (bIsRoot && nRootType == CONTENT_TYPE_OUTLINE && pParentEntry) ||
2662 (lcl_IsContent(pEntry) && ((SwContentType*)pParentEntry->GetUserData())->GetType() == CONTENT_TYPE_OUTLINE)) ))
2663 bEnable = sal_True;
2664 SwNavigationPI* pNavi = GetParentWindow();
2665 pNavi->aContentToolBox.EnableItem(FN_ITEM_UP , bEnable);
2666 pNavi->aContentToolBox.EnableItem(FN_ITEM_DOWN, bEnable);
2667 pNavi->aContentToolBox.EnableItem(FN_ITEM_LEFT, bEnable);
2668 pNavi->aContentToolBox.EnableItem(FN_ITEM_RIGHT,bEnable);
2670 return SvTreeListBox::Select(pEntry, bSelect);
2673 void SwContentTree::SetRootType(sal_uInt16 nType)
2675 nRootType = nType;
2676 bIsRoot = true;
2677 pConfig->SetRootType( nRootType );
2680 void SwContentType::RemoveNewline(String& rEntry)
2682 sal_Unicode* pStr = rEntry.GetBufferAccess();
2683 for(xub_StrLen i = rEntry.Len(); i; --i, ++pStr )
2685 if( *pStr == 10 || *pStr == 13 )
2686 *pStr = 0x20;
2690 void SwContentTree::EditEntry(SvTreeListEntry* pEntry, sal_uInt8 nMode)
2692 SwContent* pCnt = (SwContent*)pEntry->GetUserData();
2693 GotoContent(pCnt);
2694 sal_uInt16 nType = pCnt->GetParent()->GetType();
2695 sal_uInt16 nSlot = 0;
2697 uno::Reference< container::XNameAccess > xNameAccess, xSecond, xThird;
2698 switch(nType)
2700 case CONTENT_TYPE_TABLE :
2701 if(nMode == EDIT_UNPROTECT_TABLE)
2703 pActiveShell->GetView().GetDocShell()->
2704 GetDoc()->UnProtectCells( pCnt->GetName());
2706 else if(nMode == EDIT_MODE_DELETE)
2708 pActiveShell->StartAction();
2709 String sTable = SW_RES(STR_TABLE_NAME);
2710 SwRewriter aRewriterTableName;
2711 aRewriterTableName.AddRule(UndoArg1, SW_RES(STR_START_QUOTE));
2712 aRewriterTableName.AddRule(UndoArg2, pCnt->GetName());
2713 aRewriterTableName.AddRule(UndoArg3, SW_RES(STR_END_QUOTE));
2714 sTable = aRewriterTableName.Apply(sTable);
2716 SwRewriter aRewriter;
2717 aRewriter.AddRule(UndoArg1, sTable);
2718 pActiveShell->StartUndo(UNDO_DELETE, &aRewriter);
2719 pActiveShell->GetView().GetViewFrame()->GetDispatcher()->Execute(FN_TABLE_SELECT_ALL);
2720 pActiveShell->DeleteRow();
2721 pActiveShell->EndUndo();
2722 pActiveShell->EndAction();
2724 else if(nMode == EDIT_MODE_RENAME)
2726 uno::Reference< frame::XModel > xModel = pActiveShell->GetView().GetDocShell()->GetBaseModel();
2727 uno::Reference< text::XTextTablesSupplier > xTables(xModel, uno::UNO_QUERY);
2728 xNameAccess = xTables->getTextTables();
2730 else
2731 nSlot = FN_FORMAT_TABLE_DLG;
2732 break;
2734 case CONTENT_TYPE_GRAPHIC :
2735 if(nMode == EDIT_MODE_DELETE)
2737 pActiveShell->DelRight();
2739 else if(nMode == EDIT_MODE_RENAME)
2741 uno::Reference< frame::XModel > xModel = pActiveShell->GetView().GetDocShell()->GetBaseModel();
2742 uno::Reference< text::XTextGraphicObjectsSupplier > xGraphics(xModel, uno::UNO_QUERY);
2743 xNameAccess = xGraphics->getGraphicObjects();
2744 uno::Reference< text::XTextFramesSupplier > xFrms(xModel, uno::UNO_QUERY);
2745 xSecond = xFrms->getTextFrames();
2746 uno::Reference< text::XTextEmbeddedObjectsSupplier > xObjs(xModel, uno::UNO_QUERY);
2747 xThird = xObjs->getEmbeddedObjects();
2749 else
2750 nSlot = FN_FORMAT_GRAFIC_DLG;
2751 break;
2753 case CONTENT_TYPE_FRAME :
2754 case CONTENT_TYPE_OLE :
2755 if(nMode == EDIT_MODE_DELETE)
2757 pActiveShell->DelRight();
2759 else if(nMode == EDIT_MODE_RENAME)
2761 uno::Reference< frame::XModel > xModel = pActiveShell->GetView().GetDocShell()->GetBaseModel();
2762 uno::Reference< text::XTextFramesSupplier > xFrms(xModel, uno::UNO_QUERY);
2763 uno::Reference< text::XTextEmbeddedObjectsSupplier > xObjs(xModel, uno::UNO_QUERY);
2764 if(CONTENT_TYPE_FRAME == nType)
2766 xNameAccess = xFrms->getTextFrames();
2767 xSecond = xObjs->getEmbeddedObjects();
2769 else
2771 xNameAccess = xObjs->getEmbeddedObjects();
2772 xSecond = xFrms->getTextFrames();
2774 uno::Reference< text::XTextGraphicObjectsSupplier > xGraphics(xModel, uno::UNO_QUERY);
2775 xThird = xGraphics->getGraphicObjects();
2777 else
2778 nSlot = FN_FORMAT_FRAME_DLG;
2779 break;
2780 case CONTENT_TYPE_BOOKMARK :
2781 if(nMode == EDIT_MODE_DELETE)
2783 IDocumentMarkAccess* const pMarkAccess = pActiveShell->getIDocumentMarkAccess();
2784 pMarkAccess->deleteMark( pMarkAccess->findMark(pCnt->GetName()) );
2786 else if(nMode == EDIT_MODE_RENAME)
2788 uno::Reference< frame::XModel > xModel = pActiveShell->GetView().GetDocShell()->GetBaseModel();
2789 uno::Reference< text::XBookmarksSupplier > xBkms(xModel, uno::UNO_QUERY);
2790 xNameAccess = xBkms->getBookmarks();
2792 else
2793 nSlot = FN_INSERT_BOOKMARK;
2794 break;
2796 case CONTENT_TYPE_REGION :
2797 if(nMode == EDIT_MODE_RENAME)
2799 uno::Reference< frame::XModel > xModel = pActiveShell->GetView().GetDocShell()->GetBaseModel();
2800 uno::Reference< text::XTextSectionsSupplier > xSects(xModel, uno::UNO_QUERY);
2801 xNameAccess = xSects->getTextSections();
2803 else
2804 nSlot = FN_EDIT_REGION;
2805 break;
2807 case CONTENT_TYPE_URLFIELD:
2808 nSlot = FN_EDIT_HYPERLINK;
2809 break;
2810 case CONTENT_TYPE_REFERENCE:
2811 nSlot = FN_EDIT_FIELD;
2812 break;
2814 case CONTENT_TYPE_POSTIT:
2815 pActiveShell->GetView().GetPostItMgr()->AssureStdModeAtShell();
2816 if(nMode == EDIT_MODE_DELETE)
2818 if (((SwPostItContent*)pCnt)->IsPostIt())
2820 pActiveShell->GetView().GetPostItMgr()->SetActiveSidebarWin(0);
2821 pActiveShell->DelRight();
2824 else
2826 if (((SwPostItContent*)pCnt)->IsPostIt())
2827 nSlot = FN_POSTIT;
2828 else
2829 nSlot = FN_REDLINE_COMMENT;
2831 break;
2832 case CONTENT_TYPE_INDEX:
2834 const SwTOXBase* pBase = ((SwTOXBaseContent*)pCnt)->GetTOXBase();
2835 switch(nMode)
2837 case EDIT_MODE_EDIT:
2838 if(pBase)
2840 SwPtrItem aPtrItem( FN_INSERT_MULTI_TOX, (void*)pBase);
2841 pActiveShell->GetView().GetViewFrame()->
2842 GetDispatcher()->Execute(FN_INSERT_MULTI_TOX,
2843 SFX_CALLMODE_ASYNCHRON, &aPtrItem, 0L);
2846 break;
2847 case EDIT_MODE_RMV_IDX:
2848 case EDIT_MODE_DELETE:
2850 if( pBase )
2851 pActiveShell->DeleteTOX(*pBase, EDIT_MODE_DELETE == nMode);
2853 break;
2854 case EDIT_MODE_UPD_IDX:
2855 case EDIT_MODE_RENAME:
2857 Reference< frame::XModel > xModel = pActiveShell->GetView().GetDocShell()->GetBaseModel();
2858 Reference< XDocumentIndexesSupplier > xIndexes(xModel, UNO_QUERY);
2859 Reference< XIndexAccess> xIdxAcc(xIndexes->getDocumentIndexes());
2860 Reference< XNameAccess >xLocalNameAccess(xIdxAcc, UNO_QUERY);
2861 if(EDIT_MODE_RENAME == nMode)
2862 xNameAccess = xLocalNameAccess;
2863 else if(xLocalNameAccess.is() && xLocalNameAccess->hasByName(pBase->GetTOXName()))
2865 Any aIdx = xLocalNameAccess->getByName(pBase->GetTOXName());
2866 Reference< XDocumentIndex> xIdx;
2867 if(aIdx >>= xIdx)
2868 xIdx->update();
2871 break;
2874 break;
2875 case CONTENT_TYPE_DRAWOBJECT :
2876 if(EDIT_MODE_DELETE == nMode)
2877 nSlot = SID_DELETE;
2878 break;
2880 if(nSlot)
2881 pActiveShell->GetView().GetViewFrame()->
2882 GetDispatcher()->Execute(nSlot, SFX_CALLMODE_ASYNCHRON);
2883 else if(xNameAccess.is())
2885 uno::Any aObj = xNameAccess->getByName(pCnt->GetName());
2886 uno::Reference< uno::XInterface > xTmp;
2887 aObj >>= xTmp;
2888 uno::Reference< container::XNamed > xNamed(xTmp, uno::UNO_QUERY);
2889 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2890 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
2892 AbstractSwRenameXNamedDlg* pDlg = pFact->CreateSwRenameXNamedDlg(this, xNamed, xNameAccess);
2893 OSL_ENSURE(pDlg, "Dialogdiet fail!");
2894 if(xSecond.is())
2895 pDlg->SetAlternativeAccess( xSecond, xThird);
2897 String sForbiddenChars;
2898 if(CONTENT_TYPE_BOOKMARK == nType)
2900 sForbiddenChars = OUString("/\\@:*?\";,.#");
2902 else if(CONTENT_TYPE_TABLE == nType)
2904 sForbiddenChars = OUString(" .<>");
2906 pDlg->SetForbiddenChars(sForbiddenChars);
2907 pDlg->Execute();
2908 delete pDlg;
2912 void SwContentTree::GotoContent(SwContent* pCnt)
2914 pActiveShell->EnterStdMode();
2916 bool bSel = false;
2917 sal_uInt16 nJumpType = pCnt->GetParent()->GetType();
2918 switch(nJumpType)
2920 case CONTENT_TYPE_OUTLINE :
2922 pActiveShell->GotoOutline(((SwOutlineContent*)pCnt)->GetPos());
2924 break;
2925 case CONTENT_TYPE_TABLE :
2927 pActiveShell->GotoTable(pCnt->GetName());
2929 break;
2930 case CONTENT_TYPE_FRAME :
2931 case CONTENT_TYPE_GRAPHIC :
2932 case CONTENT_TYPE_OLE :
2934 if(pActiveShell->GotoFly(pCnt->GetName()))
2935 bSel = true;
2937 break;
2938 case CONTENT_TYPE_BOOKMARK:
2940 pActiveShell->GotoMark(pCnt->GetName());
2942 break;
2943 case CONTENT_TYPE_REGION :
2945 pActiveShell->GotoRegion(pCnt->GetName());
2947 break;
2948 case CONTENT_TYPE_URLFIELD:
2950 if(pActiveShell->GotoINetAttr(
2951 *((SwURLFieldContent*)pCnt)->GetINetAttr() ))
2953 pActiveShell->Right( CRSR_SKIP_CHARS, sal_True, 1, sal_False);
2954 pActiveShell->SwCrsrShell::SelectTxtAttr( RES_TXTATR_INETFMT, sal_True );
2958 break;
2959 case CONTENT_TYPE_REFERENCE:
2961 pActiveShell->GotoRefMark(pCnt->GetName());
2963 break;
2964 case CONTENT_TYPE_INDEX:
2966 if (!pActiveShell->GotoNextTOXBase(&pCnt->GetName()))
2967 pActiveShell->GotoPrevTOXBase(&pCnt->GetName());
2969 break;
2970 case CONTENT_TYPE_POSTIT:
2971 pActiveShell->GetView().GetPostItMgr()->AssureStdModeAtShell();
2972 if (((SwPostItContent*)pCnt)->IsPostIt())
2973 pActiveShell->GotoFld(*((SwPostItContent*)pCnt)->GetPostIt());
2974 else
2975 pActiveShell->GetView().GetDocShell()->GetWrtShell()->GotoRedline(
2976 pActiveShell->GetView().GetDocShell()->GetWrtShell()->FindRedlineOfData(((SwPostItContent*)pCnt)->GetRedline()->GetRedlineData()));
2978 break;
2979 case CONTENT_TYPE_DRAWOBJECT:
2981 SwPosition aPos = *pActiveShell->GetCrsr()->GetPoint();
2982 SdrView* pDrawView = pActiveShell->GetDrawView();
2983 if (pDrawView)
2985 pDrawView->SdrEndTextEdit();
2986 pDrawView->UnmarkAll();
2987 SdrModel* _pModel = pActiveShell->getIDocumentDrawModelAccess()->GetDrawModel();
2988 SdrPage* pPage = _pModel->GetPage(0);
2989 sal_uInt32 nCount = pPage->GetObjCount();
2990 for( sal_uInt32 i=0; i< nCount; i++ )
2992 SdrObject* pTemp = pPage->GetObj(i);
2993 // #i51726# - all drawing objects can be named now
2994 if (pTemp->GetName().equals(pCnt->GetName()))
2996 SdrPageView* pPV = pDrawView->GetSdrPageView();
2997 if( pPV )
2999 pDrawView->MarkObj( pTemp, pPV );
3003 pActiveShell->GetNavigationMgr().addEntry(aPos);
3006 break;
3008 if(bSel)
3010 pActiveShell->HideCrsr();
3011 pActiveShell->EnterSelFrmMode();
3013 SwView& rView = pActiveShell->GetView();
3014 rView.StopShellTimer();
3015 rView.GetPostItMgr()->SetActiveSidebarWin(0);
3016 rView.GetEditWin().GrabFocus();
3019 // Now even the matching text::Bookmark
3020 NaviContentBookmark::NaviContentBookmark()
3022 nDocSh(0),
3023 nDefDrag( REGION_MODE_NONE )
3027 NaviContentBookmark::NaviContentBookmark( const String &rUrl,
3028 const String& rDesc,
3029 sal_uInt16 nDragType,
3030 const SwDocShell* pDocSh ) :
3031 aUrl( rUrl ),
3032 aDescr(rDesc),
3033 nDocSh((long)pDocSh),
3034 nDefDrag( nDragType )
3038 void NaviContentBookmark::Copy( TransferDataContainer& rData ) const
3040 rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding();
3042 OString sStrBuf(OUStringToOString(aUrl, eSysCSet) + OString(NAVI_BOOKMARK_DELIM) +
3043 OUStringToOString(aDescr, eSysCSet) + OString(NAVI_BOOKMARK_DELIM) +
3044 OString::number(nDefDrag) + OString(NAVI_BOOKMARK_DELIM) +
3045 OString::number(nDocSh));
3046 rData.CopyByteString(SOT_FORMATSTR_ID_SONLK, sStrBuf);
3049 sal_Bool NaviContentBookmark::Paste( TransferableDataHelper& rData )
3051 String sStr;
3052 sal_Bool bRet = rData.GetString( SOT_FORMATSTR_ID_SONLK, sStr );
3053 if( bRet )
3055 sal_Int32 nPos = 0;
3056 aUrl = sStr.GetToken(0, NAVI_BOOKMARK_DELIM, nPos );
3057 aDescr = sStr.GetToken(0, NAVI_BOOKMARK_DELIM, nPos );
3058 nDefDrag= (sal_uInt16)sStr.GetToken(0, NAVI_BOOKMARK_DELIM, nPos ).ToInt32();
3059 nDocSh = sStr.GetToken(0, NAVI_BOOKMARK_DELIM, nPos ).ToInt32();
3061 return bRet;
3064 class SwContentLBoxString : public SvLBoxString
3066 public:
3067 SwContentLBoxString( SvTreeListEntry* pEntry, sal_uInt16 nFlags,
3068 const String& rStr ) : SvLBoxString(pEntry,nFlags,rStr) {}
3070 virtual void Paint(
3071 const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView,
3072 const SvTreeListEntry* pEntry);
3075 void SwContentTree::InitEntry(SvTreeListEntry* pEntry,
3076 const OUString& rStr ,const Image& rImg1,const Image& rImg2,
3077 SvLBoxButtonKind eButtonKind)
3079 sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Column1";2=="Column2"
3080 SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
3081 SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
3082 SwContentLBoxString* pStr = new SwContentLBoxString( pEntry, 0, pCol->GetText() );
3083 pEntry->ReplaceItem( pStr, nColToHilite );
3086 void SwContentLBoxString::Paint(
3087 const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView,
3088 const SvTreeListEntry* pEntry)
3090 if(lcl_IsContent(pEntry) &&
3091 ((SwContent *)pEntry->GetUserData())->IsInvisible())
3093 Font aOldFont( rDev.GetFont());
3094 Font aFont(aOldFont);
3095 Color aCol( COL_LIGHTGRAY );
3096 aFont.SetColor( aCol );
3097 rDev.SetFont( aFont );
3098 rDev.DrawText( rPos, GetText() );
3099 rDev.SetFont( aOldFont );
3101 else
3102 SvLBoxString::Paint( rPos, rDev, pView, pEntry);
3105 void SwContentTree::DataChanged( const DataChangedEvent& rDCEvt )
3107 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
3108 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
3110 aEntryImages = ImageList(SW_RES(IMG_NAVI_ENTRYBMP));
3111 FindActiveTypeAndRemoveUserData();
3112 Display(true);
3114 SvTreeListBox::DataChanged( rDCEvt );
3117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */