Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / doc / docvor.cxx
bloba1eded4f2b52adf71bf784354e6cd21348b48ce6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/embed/XStorage.hpp>
30 #include <com/sun/star/embed/ElementModes.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
34 #include <stdio.h>
36 #include <svtools/prnsetup.hxx>
37 #include <vcl/cmdevt.hxx>
38 #include <vcl/menubtn.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <vcl/print.hxx>
41 #include <svl/style.hxx>
42 #include <svl/stritem.hxx>
43 #include <svl/eitem.hxx>
44 #include <svtools/sfxecode.hxx>
45 #include <svtools/ehdl.hxx>
46 #include <svtools/imagemgr.hxx>
47 #include <vcl/waitobj.hxx>
48 #include <tools/urlobj.hxx>
49 #include <tools/color.hxx>
50 #include <unotools/pathoptions.hxx>
51 #include <unotools/moduleoptions.hxx>
52 #include <sot/exchange.hxx>
53 #include <comphelper/storagehelper.hxx>
55 #include "helpid.hrc"
56 #include "docvor.hxx"
57 #include <sfx2/docfac.hxx>
58 #include "orgmgr.hxx"
59 #include <sfx2/doctempl.hxx>
60 #include <sfx2/templdlg.hxx>
61 #include "sfxtypes.hxx"
62 #include <sfx2/app.hxx>
63 #include <sfx2/dispatch.hxx>
64 #include "sfx2/sfxresid.hxx"
65 #include "doc.hrc"
66 #include <sfx2/sfx.hrc>
67 #include "docvor.hrc"
68 #include <sfx2/docfilt.hxx>
69 #include <sfx2/filedlghelper.hxx>
70 #include <sfx2/fcontnr.hxx>
71 #include <svtools/localresaccess.hxx>
72 #include <svtools/addresstemplate.hxx>
73 #include <comphelper/processfactory.hxx>
74 #include <svl/svstdarr.hxx>
76 sal_Bool SfxOrganizeListBox_Impl::bDropMoveOk = sal_True;
78 using namespace ::com::sun::star;
80 //=========================================================================
82 class SuspendAccel
84 public:
85 Accelerator* pAccel;
87 SuspendAccel( Accelerator* pA )
89 pAccel=pA;
90 GetpApp()->RemoveAccel( pAccel );
92 ~SuspendAccel()
94 GetpApp()->InsertAccel( pAccel );
98 //=========================================================================
101 inline void SfxOrganizeListBox_Impl::SetBitmaps(
102 const Image &rOFolder, const Image &rCFolder, const Image &rODoc, const Image &rCDoc )
104 aOpenedFolderBmp = rOFolder;
105 aClosedFolderBmp = rCFolder;
106 aOpenedDocBmp = rODoc;
107 aClosedDocBmp = rCDoc;
111 //=========================================================================
113 #define NO_DROP_ACTION ((sal_Int8)-1)
115 class SfxOrganizeDlg_Impl
117 friend class SfxTemplateOrganizeDlg;
118 friend class SfxOrganizeListBox_Impl;
120 SuspendAccel* pSuspend;
121 SfxTemplateOrganizeDlg* pDialog;
123 SfxOrganizeListBox_Impl* pFocusBox;
124 Printer* pPrt;
126 // save pointer for asynchronous D&D
127 SvLBox* pSourceView;
128 SvLBoxEntry* pTargetEntry;
129 SfxOrganizeListBox_Impl* pFinishedBox;
130 sal_Int8 nDropAction;
131 bool bExecDropFinished;
133 // save some variables for the asynchronous file dialog
134 sal_uInt16 m_nRegion;
135 sal_uInt16 m_nIndex;
136 String m_sExtension4Save;
138 SfxOrganizeListBox_Impl aLeftLb;
139 ListBox aLeftTypLb;
141 SfxOrganizeListBox_Impl aRightLb;
142 ListBox aRightTypLb;
144 OKButton aOkBtn;
145 MenuButton aEditBtn;
146 HelpButton aHelpBtn;
147 PushButton aAddressTemplateBtn;
148 PushButton aFilesBtn;
150 Accelerator aEditAcc;
152 String aLastDir;
153 SfxOrganizeMgr aMgr;
154 sfx2::FileDialogHelper* pFileDlg;
156 std::vector<rtl::OUString> GetAllFactoryURLs_Impl() const;
157 sal_Bool GetServiceName_Impl( String& rFactoryURL, String& rFileURL ) const;
158 long Dispatch_Impl( sal_uInt16 nId, Menu* _pMenu );
159 String GetPath_Impl( sal_Bool bOpen, const String& rFileName );
160 ::com::sun::star::uno::Sequence< ::rtl::OUString >
161 GetPaths_Impl( const String& rFileName );
162 void InitBitmaps( void );
164 DECL_LINK( GetFocus_Impl, SfxOrganizeListBox_Impl * );
165 DECL_LINK( LeftListBoxSelect_Impl, ListBox * );
166 DECL_LINK( RightListBoxSelect_Impl, ListBox * );
167 DECL_LINK( AccelSelect_Impl, Accelerator * );
168 DECL_LINK( MenuSelect_Impl, Menu * );
169 DECL_LINK( MenuActivate_Impl, Menu * );
170 DECL_LINK( AddFiles_Impl, Button * );
171 DECL_LINK( OnAddressTemplateClicked, Button * );
173 DECL_LINK(ImportHdl, void *);
174 DECL_LINK(ExportHdl, void *);
175 DECL_LINK(AddFilesHdl, void *);
177 sal_Bool DontDelete_Impl( SvLBoxEntry* pEntry );
179 public:
180 SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent, SfxDocumentTemplates* pTempl );
181 ~SfxOrganizeDlg_Impl();
184 //-------------------------------------------------------------------------
186 SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent,
187 SfxDocumentTemplates* pTempl ) :
189 pSuspend ( NULL ),
190 pDialog ( pParent ),
191 pFocusBox ( NULL ),
192 pPrt ( NULL ),
193 pSourceView ( NULL ),
194 pTargetEntry ( NULL ),
195 pFinishedBox ( NULL ),
196 nDropAction ( NO_DROP_ACTION ),
197 bExecDropFinished ( true ),
199 aLeftLb ( this, pParent, WB_BORDER | WB_TABSTOP | WB_HSCROLL, SfxOrganizeListBox_Impl::VIEW_TEMPLATES ),
200 aLeftTypLb ( pParent, SfxResId( LB_LEFT_TYP ) ),
202 aRightLb ( this, pParent, WB_BORDER | WB_TABSTOP | WB_HSCROLL, SfxOrganizeListBox_Impl::VIEW_FILES ),
203 aRightTypLb ( pParent, SfxResId( LB_RIGHT_TYP ) ),
205 aOkBtn ( pParent, SfxResId( BTN_OK ) ),
206 aEditBtn ( pParent, SfxResId( BTN_EDIT ) ),
207 aHelpBtn ( pParent, SfxResId( BTN_HELP ) ),
208 aAddressTemplateBtn ( pParent, SfxResId( BTN_ADDRESSTEMPLATE ) ),
209 aFilesBtn ( pParent, SfxResId( BTN_FILES ) ),
211 aEditAcc ( SfxResId( ACC_EDIT ) ),
212 aMgr ( &aLeftLb, &aRightLb, pTempl ),
213 pFileDlg ( NULL )
216 // update the SfxDocumentTemplates the manager works with
217 if ( aMgr.GetTemplates() ) // should never fail, but who knows ....
219 // for this, show a wait cursor (it may take a while)
220 Window* pWaitObjectRange = pDialog ? pDialog->GetParent() : NULL;
221 if ( !pWaitObjectRange )
222 pWaitObjectRange = pDialog;
224 WaitObject aWaitCursor( pWaitObjectRange );
225 const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->Update( sal_True /* be smart */ );
226 // this const_cast is a hack - but the alternative would be to
227 // * have a method which returns the templates non-const
228 // * use a new SfxDocumentTemplates instance for the update
229 // (knowing that they all share the same implementation class)
230 // * always work with an own instance, even if we get only NULL in this ctor
233 aLeftLb.SetHelpId( HID_CTL_ORGANIZER_LEFT );
234 aRightLb.SetHelpId( HID_CTL_ORGANIZER_RIGHT );
236 String aWorkPath = SvtPathOptions().GetWorkPath();
237 if ( aWorkPath.Len() )
239 INetURLObject aObj( aWorkPath );
240 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
241 aObj.setFinalSlash();
242 aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
244 else
246 // fallback
247 String aProgURL = SvtPathOptions().SubstituteVariable( String::CreateFromAscii("$(PROGURL)") );
248 INetURLObject aObj( aProgURL );
249 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
250 aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
253 InitBitmaps();
255 aEditBtn.GetPopupMenu()->SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, MenuSelect_Impl ) );
256 aEditBtn.GetPopupMenu()->SetActivateHdl( LINK( this, SfxOrganizeDlg_Impl, MenuActivate_Impl ) );
257 aEditAcc.SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, AccelSelect_Impl ) );
258 GetpApp()->InsertAccel( &aEditAcc );
260 aFilesBtn.SetClickHdl(
261 LINK(this,SfxOrganizeDlg_Impl, AddFiles_Impl));
262 aAddressTemplateBtn.SetClickHdl(
263 LINK(this,SfxOrganizeDlg_Impl, OnAddressTemplateClicked));
264 aLeftTypLb.SetSelectHdl(
265 LINK(this, SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl));
266 aRightTypLb.SetSelectHdl(
267 LINK(this, SfxOrganizeDlg_Impl, RightListBoxSelect_Impl));
268 aLeftLb.SetGetFocusHdl(
269 LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
270 aRightLb.SetGetFocusHdl(
271 LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
272 aLeftLb.SetPosSizePixel(pParent->LogicToPixel(Point(3, 6), MAP_APPFONT),
273 pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
274 aRightLb.SetPosSizePixel(pParent->LogicToPixel(Point(103, 6), MAP_APPFONT),
275 pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
277 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE) )
278 aAddressTemplateBtn.Hide();
279 Font aFont(aLeftLb.GetFont());
280 aFont.SetWeight(WEIGHT_NORMAL);
281 aLeftLb.SetFont(aFont);
282 aRightLb.SetFont(aFont);
283 const long nIndent = aLeftLb.GetIndent() / 2;
284 aLeftLb.SetIndent( (short)nIndent );
285 aRightLb.SetIndent( (short)nIndent );
287 aLeftLb.SetMgr(&aMgr);
288 aRightLb.SetMgr(&aMgr);
289 aLeftLb.Reset();
290 aRightLb.Reset();//SetModel(aLeftLb.GetModel());
292 aLeftLb.Show();
293 aRightLb.Show();
295 aLeftLb.SelectAll( sal_False );
296 aRightLb.SelectAll( sal_False );
297 aRightLb.GrabFocus();
300 //-------------------------------------------------------------------------
302 SfxOrganizeDlg_Impl::~SfxOrganizeDlg_Impl()
304 delete pFileDlg;
307 //-------------------------------------------------------------------------
309 void SfxOrganizeDlg_Impl::InitBitmaps( void )
311 Image aOpenedFolderBmp( SfxResId( IMG_OPENED_FOLDER ) );
312 Image aClosedFolderBmp( SfxResId( IMG_CLOSED_FOLDER ) );
313 Image aOpenedDocBmp( SfxResId( IMG_OPENED_DOC ) );
314 Image aClosedDocBmp( SfxResId( IMG_CLOSED_DOC ) );
316 aLeftLb.SetBitmaps( aOpenedFolderBmp, aClosedFolderBmp, aOpenedDocBmp, aClosedDocBmp );
317 aRightLb.SetBitmaps( aOpenedFolderBmp, aClosedFolderBmp, aOpenedDocBmp, aClosedDocBmp );
320 //=========================================================================
322 sal_Bool QueryDelete_Impl(Window *pParent, // Parent to QueryBox
323 sal_uInt16 nId, // Resource Id
324 const String &rTemplateName) // Name of template to be deleted
325 /* [Description]
327 Delete Query
331 SfxResId aResId( nId );
332 String aEntryText( aResId );
333 aEntryText.SearchAndReplaceAscii( "$1", rTemplateName );
334 QueryBox aBox( pParent, WB_YES_NO | WB_DEF_NO, aEntryText );
335 return RET_NO != aBox.Execute();
338 //-------------------------------------------------------------------------
340 void ErrorDelete_Impl(Window *pParent, const String &rName, sal_Bool bFolder = sal_False )
342 /* [Description]
344 User information that the template rName could not be deleted.
347 if ( bFolder )
349 String aText( SfxResId( STR_ERROR_DELETE_TEMPLATE_DIR ) );
350 ErrorBox( pParent, WB_OK, aText ).Execute();
352 else
354 String aText( SfxResId( STR_ERROR_DELETE_TEMPLATE ) );
355 aText.SearchAndReplaceAscii( "$1", rName );
356 ErrorBox( pParent, WB_OK, aText ).Execute();
361 //=========================================================================
363 /* [Description]
365 Implementation class, the benchmark for sal_uInt16-Array
368 struct ImpPath_Impl
370 std::vector<sal_uInt16> aUS;
371 sal_uInt16 nRef;
373 ImpPath_Impl();
374 ImpPath_Impl( const ImpPath_Impl& rCopy );
377 //-------------------------------------------------------------------------
379 ImpPath_Impl::ImpPath_Impl() : nRef(1)
383 //-------------------------------------------------------------------------
385 ImpPath_Impl::ImpPath_Impl( const ImpPath_Impl& rCopy ) :
387 aUS(rCopy.aUS), nRef( 1 )
392 //==========================================================================
394 /* [Description]
396 Implementation class, presentation of a position in the Outline-
397 Listbox ass sal_uInt16-Array, this describes the position of each as
398 Postions relative to the parent entry
400 class Path
402 ImpPath_Impl *pData;
403 public:
404 Path(SvLBox *pBox, SvLBoxEntry *pEntry);
405 Path(const Path &rPath):
406 pData(rPath.pData)
408 ++pData->nRef;
410 const Path &operator=(const Path &rPath)
412 if(&rPath != this)
414 if(!--pData->nRef)
415 delete pData;
416 pData = rPath.pData;
417 pData->nRef++;
419 return *this;
421 ~Path()
423 if(!--pData->nRef)
424 delete pData;
426 sal_uInt16 Count() const { return pData->aUS.size(); }
427 sal_uInt16 operator[]( sal_uInt16 i ) const
429 return i < Count()? pData->aUS[i]: INDEX_IGNORE;
433 //-------------------------------------------------------------------------
435 Path::Path(SvLBox *pBox, SvLBoxEntry *pEntry) :
436 pData(new ImpPath_Impl)
438 DBG_ASSERT(pEntry != 0, "EntryPtr ist NULL");
439 if(!pEntry)
440 return;
441 SvLBoxEntry *pParent = pBox->GetParent(pEntry);
442 do {
443 pData->aUS.insert(pData->aUS.begin(),
444 (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry));
445 if(0 == pParent)
446 break;
447 pEntry = pParent;
448 pParent = pBox->GetParent(pEntry);
449 } while(1);
452 //-------------------------------------------------------------------------
454 SvLBoxEntry *GetIndices_Impl(SvLBox *pBox,
455 SvLBoxEntry *pEntry,
456 sal_uInt16 &rRegion,
457 sal_uInt16 &rOffset)
458 /* [Description]
460 Region and position within a range for a template is determined.
462 [Parameter]
464 SvLBox *pBox Listbox where the event occurred
465 SvLBoxEntry *pEntry Entry whose position is to be determined
466 sal_uInt16 &rRegion the region within the region of the
467 document template (Out-Parameter)
468 sal_uInt16 &rOffset the position within the region of the
469 document template (Out-Parameter)
472 [Cross-references]
474 <class Path> (in certain circumstances this function can also be
475 dispensed in favor of the Path)
479 if(!pEntry)
481 rRegion = rOffset = 0;
482 return pEntry;
484 if(0 == pBox->GetModel()->GetDepth(pEntry))
486 rRegion = (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry);
487 rOffset = USHRT_MAX;
488 return pEntry;
490 SvLBoxEntry *pParent = pBox->GetParent(pEntry);
491 rRegion = (sal_uInt16)pBox->GetModel()->GetRelPos(pParent);
492 rOffset = (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry);
493 return pEntry;
496 //-------------------------------------------------------------------------
498 sal_Bool SfxOrganizeListBox_Impl::Select( SvLBoxEntry* pEntry, sal_Bool bSelect )
500 if(!bSelect)
501 return SvTreeListBox::Select(pEntry,bSelect);
502 sal_uInt16 nLevel = GetDocLevel();
503 if(GetModel()->GetDepth(pEntry)+nLevel<3)
504 return SvTreeListBox::Select(pEntry,bSelect);
506 Path aPath(this, pEntry);
508 // it is ok to use the SfxObjectShellRef here since the object that
509 // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
510 GetObjectShell(aPath)->TriggerHelpPI(
511 aPath[nLevel+1], aPath[nLevel+2]);
512 return SvTreeListBox::Select(pEntry,bSelect);
515 //-------------------------------------------------------------------------
517 sal_Bool SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
518 SvLBoxEntry *pSource,
519 SvLBoxEntry* pTarget,
520 SvLBoxEntry *&pNewParent,
521 sal_uIntPtr &rIdx,
522 sal_Bool bCopy)
523 /* [Description]
525 Move or copy a document templates
527 [Parameter]
529 SvLBox *pSourceBox Source Listbox, at which the event occurred
530 SvLBoxEntry* pTarget Target entry, to where it will be moved
531 SvLBoxEntry *pSource Source entry, to be copied / moved
532 SvLBoxEntry *&pNewParent the parent of the target position generated
533 at entry (out parameter)
534 sal_uIntPtr &rIdx Index of the target entry
535 sal_Bool bCopy Flag for Copy / Move
538 [Return value] sal_Bool: Success or failure
540 [Cross-references]
542 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
543 SvLBoxEntry *pSource,
544 SvLBoxEntry* pTarget,
545 SvLBoxEntry *&pNewParent,
546 sal_uIntPtr &rIdx,
547 sal_Bool bCopy)>
548 <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
549 SvLBoxEntry* pSource,
550 SvLBoxEntry *&pNewParent,
551 sal_uIntPtr &rIdx)>
552 <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
553 SvLBoxEntry* pSource,
554 SvLBoxEntry *&pNewParent,
555 sal_uIntPtr &rIdx)>
559 sal_Bool bOk = sal_False;
561 if(pSource)
563 sal_uInt16 nTargetRegion = 0, nTargetIndex = 0;
564 GetIndices_Impl(this, pTarget, nTargetRegion, nTargetIndex);
566 sal_uInt16 nSourceRegion = 0, nSourceIndex = 0;
567 GetIndices_Impl(pSourceBox, pSource, nSourceRegion, nSourceIndex);
569 bOk = bCopy ?
570 pMgr->Copy(nTargetRegion, nTargetIndex+1,
571 nSourceRegion, nSourceIndex):
572 pMgr->Move(nTargetRegion, nTargetIndex+1,
573 nSourceRegion, nSourceIndex);
575 if(bOk)
577 if(pSourceBox->GetModel()->GetDepth(pSource) == GetModel()->GetDepth(pTarget))
579 pNewParent = GetParent(pTarget);
580 rIdx = GetModel()->GetRelPos(pTarget)+1;
582 else
584 if(nTargetIndex == USHRT_MAX)
586 pNewParent = pTarget;
587 rIdx = 0;
589 else
590 SvLBox::NotifyCopying(
591 pTarget, pSource, pNewParent, rIdx);
594 else if ( bCopy )
596 // the template organizer always tries copy after the move, so no error is required for move case
597 String aText( SfxResId( bCopy ? STR_ERROR_COPY_TEMPLATE : STR_ERROR_MOVE_TEMPLATE ) );
598 aText.SearchAndReplaceAscii( "$1",
599 ( (SvTreeListBox *)pSourceBox )->GetEntryText( pSource ) );
600 ErrorBox( this, WB_OK, aText ).Execute();
603 return bOk;
606 //-------------------------------------------------------------------------
608 sal_Bool SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
609 SvLBoxEntry *pSource,
610 SvLBoxEntry* pTarget,
611 SvLBoxEntry *&pNewParent,
612 sal_uIntPtr &rIdx,
613 sal_Bool bCopy)
614 /* [Description]
616 Move or copy document contents
618 [Parameter]
620 SvLBox *pSourceBox Source Listbox, at which the event occurred
621 SvLBoxEntry* pTarget Target entry, to where it will be moved
622 SvLBoxEntry *pSource Source entry, to be copied / moved
623 SvLBoxEntry *&pNewParent the parent of the target position generated
624 at entry (out parameter)
625 sal_uIntPtr &rIdx Index of the target entry
626 sal_Bool bCopy Flag for Copy / Move
629 [Return value] sal_Bool: Success or failure
631 [Cross-references]
633 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
634 SvLBoxEntry *pSource,
635 SvLBoxEntry* pTarget,
636 SvLBoxEntry *&pNewParent,
637 sal_uIntPtr &rIdx,
638 sal_Bool bCopy)>
639 <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
640 SvLBoxEntry* pSource,
641 SvLBoxEntry *&pNewParent,
642 sal_uIntPtr &rIdx)>
643 <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
644 SvLBoxEntry* pSource,
645 SvLBoxEntry *&pNewParent,
646 sal_uIntPtr &rIdx)>
650 SfxErrorContext aEc( ERRCTX_SFX_MOVEORCOPYCONTENTS, this);
651 sal_Bool bOk = sal_False, bKeepExpansion = sal_False;
652 sal_Bool bRemovedFromSource = sal_False;
653 Path aSource(pSourceBox, pSource);
654 Path aTarget(this, pTarget);
656 // it is ok to use the SfxObjectShellRef here since the object that
657 // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
658 SfxObjectShellRef aSourceDoc = ((SfxOrganizeListBox_Impl *)pSourceBox)->GetObjectShell(aSource);
659 SfxObjectShellRef aTargetDoc = GetObjectShell(aTarget);
661 const sal_uInt16 nSLevel =
662 ((SfxOrganizeListBox_Impl *)pSourceBox)->GetDocLevel();
663 const sal_uInt16 nTLevel = GetDocLevel();
665 if(aSourceDoc.Is() && aTargetDoc.Is())
667 if (aSourceDoc->GetStyleSheetPool())
668 aSourceDoc->GetStyleSheetPool()->SetSearchMask(
669 SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
671 if (aTargetDoc->GetStyleSheetPool())
672 aTargetDoc->GetStyleSheetPool()->SetSearchMask(
673 SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
674 sal_uInt16 p[3];
675 sal_uInt16 nIdxDeleted = INDEX_IGNORE;
676 p[0]=aTarget[nTLevel+1];
677 p[1]=aTarget[nTLevel+2];
678 if(p[1]!=INDEX_IGNORE)p[1]++;
679 p[2]=aTarget[nTLevel+3];
681 bOk = aTargetDoc->Insert(
682 *aSourceDoc, aSource[nSLevel+1],
683 aSource[nSLevel+2], aSource[nSLevel+3],
684 p[0], p[1], p[2], nIdxDeleted);
685 // Evaluate Position correction
686 // a = Document content
687 // b = Position Sub-content 1
688 // c = Position Sub-content 2
689 // Delete duplicate entries
690 if(bOk)
692 SvLBoxEntry *pParentIter = pTarget;
693 // Up to the document level as
694 // the general reference point
695 while(GetModel()->GetDepth(pParentIter) != nTLevel)
696 pParentIter = GetParent(pParentIter);
697 if(pParentIter->HasChildrenOnDemand() &&
698 !GetModel()->HasChildren(pParentIter))
699 RequestingChildren(pParentIter);
700 SvLBoxEntry *pChildIter = 0;
702 sal_uInt16 i = 0;
703 while(i < 2 && p[i+1] != INDEX_IGNORE)
705 pChildIter = FirstChild(pParentIter);
706 // To the index of the current level
707 for(sal_uInt16 j = 0; j < p[i]; ++j)
708 pChildIter = NextSibling(pChildIter);
709 // If possible, fill in Items onDemand
710 ++i;
711 if(i < 2 && p[i+1] != INDEX_IGNORE &&
712 pChildIter->HasChildrenOnDemand() &&
713 !GetModel()->HasChildren(pChildIter))
714 RequestingChildren(pChildIter);
715 pParentIter = pChildIter;
717 rIdx = p[i];
718 pNewParent = pParentIter;
719 if(!IsExpanded(pNewParent) &&
720 pNewParent->HasChildrenOnDemand() &&
721 !GetModel()->HasChildren(pNewParent))
723 bOk = sal_False;
724 if(!bCopy)
725 pSourceBox->GetModel()->Remove(pSource);
727 // Remove deleted items
728 // (can be done by overwriting)
729 if(nIdxDeleted != INDEX_IGNORE)
731 pChildIter = FirstChild(pParentIter);
732 for(sal_uInt16 j = 0; j < nIdxDeleted; ++j)
733 pChildIter = NextSibling(pChildIter);
734 if( pChildIter && pChildIter != pSource )
736 bKeepExpansion = IsExpanded(pParentIter);
737 GetModel()->Remove(pChildIter);
739 else
740 bOk = sal_False;
742 if(!bCopy && &aSourceDoc != &aTargetDoc)
744 //pool styles that are moved produce
745 //an rIdx == INDEX_IGNORE
746 //the method has to return true to keep the box content consistent
747 bRemovedFromSource = aSourceDoc->Remove(aSource[nSLevel+1],
748 aSource[nSLevel+2],
749 aSource[nSLevel+3]);
753 return (((rIdx != INDEX_IGNORE)|| bRemovedFromSource) && bOk )
754 ? bKeepExpansion? (sal_Bool)2: sal_True: sal_False;
757 //-------------------------------------------------------------------------
759 sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
760 SvLBoxEntry* pSource,
761 SvLBoxEntry *&pNewParent,
762 sal_uIntPtr &rIdx)
764 /* [Description]
766 Notification that an item will be moved.
767 (SV-Handler)
769 [Parameter]
771 SvLBoxEntry* pTarget Target entry, to where it will be moved
772 SvLBoxEntry *pSource Source entry, to be moved
773 SvLBoxEntry *&pNewParent the parent of the target position generated
774 at entry (out parameter)
775 sal_uIntPtr &rIdx Index of the target entry
778 [Return value] sal_Bool: Sucess or failure
780 [Cross-references]
782 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
783 SvLBoxEntry *pSource,
784 SvLBoxEntry* pTarget,
785 SvLBoxEntry *&pNewParent,
786 sal_uIntPtr &rIdx,
787 sal_Bool bCopy)>
788 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
789 SvLBoxEntry *pSource,
790 SvLBoxEntry* pTarget,
791 SvLBoxEntry *&pNewParent,
792 sal_uIntPtr &rIdx,
793 sal_Bool bCopy)>
794 <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
795 SvLBoxEntry* pSource,
796 SvLBoxEntry *&pNewParent,
797 sal_uIntPtr &rIdx)>
801 sal_Bool bOk = sal_False;
802 SvLBox* pSourceBox = GetSourceView();
803 if ( !pSourceBox )
804 pSourceBox = pDlg->pSourceView;
805 DBG_ASSERT( pSourceBox, "no source view" );
806 if ( !pTarget )
807 pTarget = pDlg->pTargetEntry;
809 if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
810 GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
811 bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_False );
812 else
813 bOk = MoveOrCopyContents(pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_False );
815 return bOk;
818 //-------------------------------------------------------------------------
820 sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
821 SvLBoxEntry* pSource,
822 SvLBoxEntry *&pNewParent,
823 sal_uIntPtr &rIdx)
824 /* [Description]
826 Notification that an item will be moved.
827 (SV-Handler)
829 [Parameter]
831 SvLBoxEntry* pTarget Target entry, to where it will be copied
832 SvLBoxEntry *pSource Source entry, to be copied
833 SvLBoxEntry *&pNewParent the parent of the target position generated
834 at entry (out parameter)
835 sal_uIntPtr &rIdx Index of the target entry
837 [Return value] sal_Bool: Sucess or failure
839 [Cross-references]
841 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
842 SvLBoxEntry *pSource,
843 SvLBoxEntry* pTarget,
844 SvLBoxEntry *&pNewParent,
845 sal_uIntPtr &rIdx,
846 sal_Bool bCopy)>
847 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
848 SvLBoxEntry *pSource,
849 SvLBoxEntry* pTarget,
850 SvLBoxEntry *&pNewParent,
851 sal_uIntPtr &rIdx,
852 sal_Bool bCopy)>
853 <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
854 SvLBoxEntry* pSource,
855 SvLBoxEntry *&pNewParent,
856 sal_uIntPtr &rIdx)>
859 sal_Bool bOk = sal_False;
860 SvLBox* pSourceBox = GetSourceView();
861 if ( !pSourceBox )
862 pSourceBox = pDlg->pSourceView;
863 DBG_ASSERT( pSourceBox, "no source view" );
864 if ( !pTarget )
865 pTarget = pDlg->pTargetEntry;
866 if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
867 GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
868 bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_True );
869 else
870 bOk = MoveOrCopyContents( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_True );
872 return bOk;
875 //-------------------------------------------------------------------------
877 sal_Bool SfxOrganizeListBox_Impl::EditingEntry( SvLBoxEntry* pEntry, Selection& )
879 /* [Description]
881 Check whether an item can be edited
882 (SV-Handler)
884 [Cross-references]
885 <SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry* pEntry, const rtl::OUString& rText)>
889 if( VIEW_TEMPLATES == eViewType &&
890 GetModel()->GetDepth(pEntry) < 2 )
892 pDlg->pSuspend = new SuspendAccel( &pDlg->aEditAcc );
893 return sal_True;
895 return sal_False;
898 //-------------------------------------------------------------------------
900 sal_Bool SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry* pEntry, const rtl::OUString& rText)
902 /* [Description]
904 The name of an entry has been processed, if the name you entered is a
905 valid name (length> 0) then the model is updated.
906 (SV-Handler)
908 [Return value]
910 sal_Bool sal_True: The name in the display should be changed
911 sal_False: The name should not be changed
913 [Cross-references]
914 <SfxOrganizeListBox_Impl::EditingEntry(SvLBoxEntry* pEntry, const String& rText)>
918 DBG_ASSERT(pEntry, "No Entry selected");
919 delete pDlg->pSuspend;
920 pDlg->pSuspend = NULL;
921 SvLBoxEntry* pParent = GetParent(pEntry);
922 if( rText.isEmpty() )
924 ErrorBox aBox( this, SfxResId( MSG_ERROR_EMPTY_NAME ) );
925 aBox.GrabFocus();
926 aBox.Execute();
927 return sal_False;
929 if ( !IsUniqName_Impl( rText, pParent, pEntry ) )
931 ErrorBox aBox( this, SfxResId( MSG_ERROR_UNIQ_NAME ) );
932 aBox.GrabFocus();
933 aBox.Execute();
934 return sal_False;
936 sal_uInt16 nRegion = 0, nIndex = 0;
937 GetIndices_Impl( this, pEntry, nRegion, nIndex );
938 String aOldName;
939 if ( USHRT_MAX != nIndex )
940 aOldName = pMgr->GetTemplates()->GetName( nRegion, nIndex );
941 else
942 aOldName = pMgr->GetTemplates()->GetRegionName( nRegion );
944 if ( !pMgr->SetName( rText, nRegion, nIndex ) )
946 SfxResId aResId( USHRT_MAX != nIndex ? MSG_ERROR_RENAME_TEMPLATE
947 : MSG_ERROR_RENAME_TEMPLATE_REGION );
948 ErrorBox( this, aResId ).Execute();
949 return sal_False;
952 return sal_True;
955 //-------------------------------------------------------------------------
957 DragDropMode SfxOrganizeListBox_Impl::NotifyStartDrag( TransferDataContainer&, SvLBoxEntry* pEntry )
959 sal_uInt16 nSourceLevel = GetModel()->GetDepth( pEntry );
960 if ( VIEW_FILES == GetViewType() )
961 ++nSourceLevel;
962 if ( nSourceLevel >= 2 )
963 bDropMoveOk = sal_False;
964 else
965 bDropMoveOk = sal_True;
967 return GetDragDropMode();
970 //-------------------------------------------------------------------------
972 sal_Bool SfxOrganizeListBox_Impl::NotifyAcceptDrop( SvLBoxEntry* pEntry )
974 if(!pEntry)
975 return sal_False;
976 SvLBox *pSource = GetSourceView();
977 SvLBoxEntry *pSourceEntry = pSource->FirstSelected();
978 if(pEntry == pSourceEntry)
979 return sal_False;
980 sal_uInt16 nSourceLevel = pSource->GetModel()->GetDepth(pSourceEntry);
981 if(VIEW_FILES == ((SfxOrganizeListBox_Impl *)pSource)->GetViewType())
982 ++nSourceLevel;
983 sal_uInt16 nTargetLevel = GetModel()->GetDepth(pEntry);
984 if(VIEW_FILES == GetViewType())
985 ++nTargetLevel;
986 Path aSource(pSource, pSourceEntry);
987 Path aTarget(this, pEntry);
988 const sal_uInt16 SL = ((SfxOrganizeListBox_Impl *)pSource)->GetDocLevel();
989 const sal_uInt16 TL = GetDocLevel();
991 return( (nSourceLevel == 1 && nTargetLevel == 0 &&
992 VIEW_TEMPLATES ==
993 ((SfxOrganizeListBox_Impl *)pSource)->GetViewType()) ||
994 (nSourceLevel == 1 && nTargetLevel == 1 &&
995 VIEW_TEMPLATES ==
996 ((SfxOrganizeListBox_Impl *)pSource)->GetViewType() &&
997 VIEW_TEMPLATES == GetViewType()) ||
998 (nSourceLevel == 3 && nTargetLevel == 1) ||
999 (nSourceLevel == 3 && nTargetLevel == 2 &&
1000 aSource[1+SL] == aTarget[1+TL]) ||
1001 (nSourceLevel == 3 && nTargetLevel == 3 &&
1002 aSource[1+SL] == aTarget[1+TL]) ||
1003 (nSourceLevel == 4 && nTargetLevel == 3 &&
1004 aSource[1+SL] == aTarget[1+TL] &&
1005 aSource[2+SL] == aTarget[2+TL]) ||
1006 (nSourceLevel == 4 && nTargetLevel == 4 &&
1007 aSource[1+SL] == aTarget[1+TL] &&
1008 aSource[2+SL] == aTarget[2+TL]));
1011 //-------------------------------------------------------------------------
1013 sal_Int8 SfxOrganizeListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
1015 sal_Bool bAccept = ( eViewType == VIEW_FILES && IsDropFormatSupported( SOT_FORMAT_FILE ) );
1016 if ( bAccept )
1017 return rEvt.mnAction;
1018 else
1019 return SvTreeListBox::AcceptDrop( rEvt );
1022 //-------------------------------------------------------------------------
1024 sal_Int8 SfxOrganizeListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
1026 TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
1027 sal_uInt32 nFormatCount = aHelper.GetFormatCount();
1028 sal_Bool bSuccess = sal_False;
1029 for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
1031 String aFileName;
1032 SotFormatStringId nId = aHelper.GetFormat(i);
1034 if ( SOT_FORMAT_FILE == nId && aHelper.GetString( nId, aFileName ) )
1036 INetURLObject aObj( aFileName, INET_PROT_FILE );
1037 bSuccess |= pMgr->InsertFile( this, aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
1040 bDropMoveOk = sal_True;
1041 sal_Int8 nRet = rEvt.mnAction;
1042 if ( !bSuccess )
1044 // asynchronous, because of MessBoxes
1045 pDlg->pSourceView = GetSourceView();
1046 pDlg->pTargetEntry = pTargetEntry;
1047 pDlg->pFinishedBox = NULL;
1048 pDlg->nDropAction = NO_DROP_ACTION;
1049 PostUserEvent( LINK( this, SfxOrganizeListBox_Impl, OnAsyncExecuteDrop ),
1050 new ExecuteDropEvent( rEvt ) );
1053 return nRet;
1056 //-------------------------------------------------------------------------
1058 void SfxOrganizeListBox_Impl::DragFinished( sal_Int8 nDropAction )
1060 if ( pDlg->bExecDropFinished )
1062 if ( pDlg->nDropAction != NO_DROP_ACTION )
1063 nDropAction = pDlg->nDropAction;
1064 SvTreeListBox::DragFinished( nDropAction );
1065 pDlg->nDropAction = NO_DROP_ACTION;
1067 else
1068 pDlg->pFinishedBox = this;
1071 //-------------------------------------------------------------------------
1073 inline sal_uInt16 SfxOrganizeListBox_Impl::GetDocLevel() const
1075 /* [Description]
1077 Determines on which level there are documents (in the template view or
1078 the document view)
1080 [Return value]
1082 sal_uInt16 Document level
1087 return eViewType == VIEW_FILES? 0: 1;
1090 //-------------------------------------------------------------------------
1092 SfxObjectShellRef SfxOrganizeListBox_Impl::GetObjectShell(const Path &rPath)
1094 /* [Description]
1096 Access to the ObjectShell to which the current entry is connected.
1098 [Parameter]
1100 const Path &rPath Description of the current entry
1102 [Return value]
1104 SfxObjectShellRef Reference to the ObjectShell
1106 [Cross-references]
1108 <class Path>
1113 SfxObjectShellRef aDoc;
1114 if(eViewType == VIEW_FILES)
1115 aDoc = pMgr->CreateObjectShell(rPath[0]);
1116 else
1117 aDoc = pMgr->CreateObjectShell(rPath[0], rPath[1]);
1118 return aDoc;
1121 //-------------------------------------------------------------------------
1123 void SfxOrganizeListBox_Impl::RequestingChildren( SvLBoxEntry* pEntry )
1125 /* [Description]
1127 Sent to the children of an entry that is going to be inserted.
1128 (SV-Handler)
1130 [Parameter]
1132 SvLBoxEntry* pEntry the entry whose children is requested
1136 if ( !GetModel()->HasChildren( pEntry ) )
1138 WaitObject aWaitCursor( this );
1140 // Choose the correct mask color dependent from eColorMode. This
1141 // must be adopted if we change the mask color for normal images, too!
1142 Color aMaskColor( COL_LIGHTMAGENTA );
1144 // Here are all the initial inserted
1145 SfxErrorContext aEc(ERRCTX_SFX_CREATEOBJSH, pDlg->pDialog);
1146 if(VIEW_TEMPLATES == GetViewType() && 0 == GetModel()->GetDepth(pEntry))
1148 sal_uInt16 i = (sal_uInt16)GetModel()->GetRelPos(pEntry);
1149 const sal_uInt16 nEntryCount = pMgr->GetTemplates()->GetCount(i);
1150 for(sal_uInt16 j = 0; j < nEntryCount; ++j)
1151 InsertEntryByBmpType( pMgr->GetTemplates()->GetName( i, j ), BMPTYPE_DOC, pEntry, sal_True );
1153 else
1155 const sal_uInt16 nDocLevel = GetDocLevel();
1156 Path aPath(this, pEntry);
1158 // it is ok to use the SfxObjectShellRef here since the object that
1159 // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
1160 SfxObjectShellRef aRef = GetObjectShell(aPath);
1161 if(aRef.Is())
1163 const sal_uInt16 nCount = aRef->GetContentCount(aPath[nDocLevel+1]);
1164 String aText;
1165 Bitmap aClosedBmp, aOpenedBmp;
1166 const bool bCanHaveChildren =
1167 aRef->CanHaveChildren(aPath[nDocLevel+1],
1168 aPath[nDocLevel+2]);
1169 for(sal_uInt16 i = 0; i < nCount; ++i)
1171 sal_Bool bDeletable;
1172 aRef->GetContent(
1173 aText, aClosedBmp, aOpenedBmp, bDeletable,
1174 i, aPath[nDocLevel+1]);
1176 // Create image with the correct mask color
1177 Image aClosedImage( aClosedBmp, aMaskColor );
1178 Image aOpenedImage( aOpenedBmp, aMaskColor );
1180 SvLBoxEntry *pNew = SvTreeListBox::InsertEntry(
1181 aText, aOpenedImage, aClosedImage,
1182 pEntry, bCanHaveChildren);
1183 pNew->SetUserData(bDeletable ? &bDeletable : 0);
1190 //-------------------------------------------------------------------------
1192 long SfxOrganizeListBox_Impl::ExpandingHdl()
1194 /* [Description]
1196 SV-handler, before and after the unfolding of an entry is called.
1197 Used if possibly to close the ObjectShell again, the entries with the
1198 contents of this shell are also removed.
1202 if ( !(nImpFlags & SVLBOX_IS_EXPANDING) )
1204 SvLBoxEntry* pEntry = GetHdlEntry();
1205 const sal_uInt16 nLevel = GetModel()->GetDepth(pEntry);
1206 if((eViewType == VIEW_FILES && nLevel == 0) ||
1207 (eViewType == VIEW_TEMPLATES && nLevel == 1))
1209 Path aPath(this, pEntry);
1210 // Release ObjectShell when closing the files
1211 if(eViewType == VIEW_FILES && nLevel == 0)
1212 pMgr->DeleteObjectShell(aPath[0]);
1213 else
1214 pMgr->DeleteObjectShell(aPath[0], aPath[1]);
1215 // Delete all SubEntries
1216 SvLBoxEntry *pToDel = SvLBox::GetEntry(pEntry, 0);
1217 while(pToDel)
1219 GetModel()->Remove(pToDel);
1220 pToDel = SvLBox::GetEntry(pEntry, 0);
1224 return sal_True;
1227 //-------------------------------------------------------------------------
1229 sal_Bool SfxOrganizeListBox_Impl::IsUniqName_Impl(const String &rText,
1230 SvLBoxEntry* pParent, SvLBoxEntry *pEntry) const
1232 /* [Description]
1234 Checks whether a name is unique at its level.
1236 [Parameter]
1238 const String & Name of the search entry
1239 SvLBoxEntry* pSibling Siblings (referred to the level)
1241 [Return value]
1243 sal_Bool sal_True, if the name is unique, otherwise sal_False
1247 SvLBoxEntry* pChild = FirstChild(pParent);
1248 while(pChild) {
1249 const String aEntryText(GetEntryText(pChild));
1250 if(COMPARE_EQUAL == aEntryText.CompareIgnoreCaseToAscii(rText)&&(!pEntry || pEntry!=pChild))
1251 return sal_False;
1252 pChild = NextSibling(pChild);
1254 return sal_True;
1257 //-------------------------------------------------------------------------
1259 sal_uInt16 SfxOrganizeListBox_Impl::GetLevelCount_Impl(SvLBoxEntry* pParent) const
1261 SvLBoxEntry* pChild = FirstChild(pParent);
1262 sal_uInt16 nCount = 0;
1263 while(pChild) {
1264 pChild = NextSibling(pChild);
1265 ++nCount;
1267 return nCount;
1270 //-------------------------------------------------------------------------
1272 SvLBoxEntry* SfxOrganizeListBox_Impl::InsertEntryByBmpType(
1273 const XubString& rText,
1274 BMPTYPE eBmpType,
1275 SvLBoxEntry* pParent,
1276 sal_Bool bChildrenOnDemand,
1277 sal_uIntPtr nPos,
1278 void* pUserData
1281 SvLBoxEntry* pEntry = NULL;
1282 const Image* pExp = NULL;
1283 const Image* pCol = NULL;
1285 switch( eBmpType )
1287 case BMPTYPE_FOLDER:
1288 pExp = &aOpenedFolderBmp;
1289 pCol = &aClosedFolderBmp;
1290 break;
1292 case BMPTYPE_DOC:
1293 pExp = &aOpenedDocBmp;
1294 pCol = &aClosedDocBmp;
1295 break;
1297 default:
1298 OSL_FAIL( "SfxOrganizeListBox_Impl::InsertEntryByBmpType(): something forgotten?!" );
1301 pEntry = SvTreeListBox::InsertEntry( rText, *pExp, *pCol, pParent, bChildrenOnDemand, nPos, pUserData );
1303 return pEntry;
1306 //-------------------------------------------------------------------------
1308 SfxOrganizeListBox_Impl::SfxOrganizeListBox_Impl
1310 SfxOrganizeDlg_Impl* pArgDlg,
1311 Window* pParent,
1312 WinBits nBits,
1313 DataEnum eType
1316 SvTreeListBox( pParent, nBits ),
1318 pMgr ( NULL ),
1319 pDlg ( pArgDlg ),
1320 eViewType ( eType )
1322 /* [Description]
1324 Constructor SfxOrganizeListBox
1329 SetDragDropMode(
1330 SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY |
1331 SV_DRAGDROP_APP_MOVE | SV_DRAGDROP_APP_COPY | SV_DRAGDROP_APP_DROP );
1332 SetEntryHeight( 16 );
1333 SetSelectionMode( SINGLE_SELECTION );
1334 GetModel()->SetSortMode( SortNone );
1336 EnableContextMenuHandling();
1339 //-------------------------------------------------------------------------
1341 IMPL_LINK( SfxOrganizeListBox_Impl, OnAsyncExecuteDrop, ExecuteDropEvent*, pEvent )
1343 DBG_ASSERT( pEvent, "invalid DropEvent" );
1344 if ( pEvent )
1346 SvLBox* pSourceView = GetSourceView();
1347 if ( !pSourceView )
1348 pSourceView = pDlg->pSourceView;
1349 pDlg->bExecDropFinished = false;
1350 // if a template can not be moved it should be copied
1351 if ( pEvent->mnAction == DND_ACTION_MOVE )
1352 pEvent->mnAction = DND_ACTION_COPYMOVE;
1353 pDlg->nDropAction = SvTreeListBox::ExecuteDrop( *pEvent, pSourceView );
1354 delete pEvent;
1355 pDlg->pSourceView = NULL;
1356 pDlg->pTargetEntry = NULL;
1357 pDlg->bExecDropFinished = true;
1358 if ( pDlg->pFinishedBox )
1360 pDlg->pFinishedBox->DragFinished( pDlg->nDropAction );
1361 pDlg->pFinishedBox = NULL;
1364 return 0;
1367 //-------------------------------------------------------------------------
1369 void SfxOrganizeListBox_Impl::Reset()
1371 /* [Description]
1373 Paste the items in the ListBox
1377 DBG_ASSERT( pMgr != 0, "No Manager" );
1378 // Delete contents
1379 SetUpdateMode(sal_False);
1380 Clear();
1381 if ( VIEW_TEMPLATES == eViewType )
1383 const sal_uInt16 nCount = pMgr->GetTemplates()->GetRegionCount();
1384 for ( sal_uInt16 i = 0; i < nCount; ++i )
1385 InsertEntryByBmpType( pMgr->GetTemplates()->GetFullRegionName(i), BMPTYPE_FOLDER, 0, sal_True );
1387 else
1389 const SfxObjectList& rList = pMgr->GetObjectList();
1390 const sal_uInt16 nCount = rList.Count();
1391 for ( sal_uInt16 i = 0; i < nCount; ++i )
1392 InsertEntryByBmpType( rList.GetBaseName(i), BMPTYPE_DOC, 0, sal_True );
1395 SetUpdateMode(sal_True);
1396 Invalidate();
1397 Update();
1400 //-------------------------------------------------------------------------
1402 const Image &SfxOrganizeListBox_Impl::GetClosedBmp(sal_uInt16 nLevel) const
1404 /* [Description]
1406 Access to the bitmap for a closed entry at each level
1408 [Parameter]
1410 sal_uInt16 nLevel Indicator of the level, 2 levels are allowed
1412 [Return value]
1414 const Image & The Image on level nLevel
1418 const Image* pRet = NULL;
1420 switch( nLevel )
1422 default: OSL_FAIL( "Bitmap index overflow" );
1424 case 0: pRet = &aClosedFolderBmp;
1425 break;
1426 case 1: pRet = &aClosedDocBmp;
1427 break;
1430 return *pRet;
1433 //-------------------------------------------------------------------------
1435 const Image &SfxOrganizeListBox_Impl::GetOpenedBmp(sal_uInt16 nLevel) const
1437 /* [Description]
1439 Access to the bitmap for an open entry at each level
1441 [Parameter]
1443 sal_uInt16 nLevel Indicator of the level, 2 levels are allowed
1445 [Return value]
1447 const Image & the image on the level nLevel
1452 const Image* pRet = NULL;
1454 switch( nLevel )
1456 case 0:
1457 pRet = &aOpenedFolderBmp; break;
1458 case 1:
1459 pRet = &aOpenedDocBmp; break;
1460 default:
1461 pRet = &aClosedFolderBmp; break;
1464 return *pRet;
1467 //-------------------------------------------------------------------------
1469 PopupMenu* SfxOrganizeListBox_Impl::CreateContextMenu()
1471 return new PopupMenu( *( pDlg->aEditBtn.GetPopupMenu() ) );
1474 //-------------------------------------------------------------------------
1476 String SfxOrganizeDlg_Impl::GetPath_Impl( sal_Bool bOpen, const String& rFileName )
1478 /* [Description]
1480 Get path from FileDialog, for Import / Export of Templates
1482 [Parameter]
1484 sal_Bool bOpen Flag: Open / Save
1485 const String& rFileName Current file name as default
1487 [Return value] File name with path or empty string if
1488 users has pressed 'Cancel'
1492 String aPath;
1493 m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
1494 sal_Int16 nDialogType = bOpen
1495 ? com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
1496 : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE;
1497 if ( pFileDlg )
1498 delete pFileDlg;
1499 pFileDlg = new sfx2::FileDialogHelper( nDialogType, 0L );
1501 // add "All" filter
1502 pFileDlg->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ),
1503 DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
1504 // add template filter
1505 String sFilterName( SfxResId( STR_TEMPLATE_FILTER ) );
1506 String sFilterExt;
1507 // add filters of modules which are installed
1508 SvtModuleOptions aModuleOpt;
1509 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1510 sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
1511 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
1513 if ( sFilterExt.Len() > 0 )
1514 sFilterExt += ';';
1515 sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1517 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
1519 if ( sFilterExt.Len() > 0 )
1520 sFilterExt += ';';
1521 sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1523 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
1525 if ( sFilterExt.Len() > 0 )
1526 sFilterExt += ';';
1527 sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
1529 if ( sFilterExt.Len() > 0 )
1530 sFilterExt += ';';
1531 sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
1533 sFilterName += DEFINE_CONST_UNICODE( " (" );
1534 sFilterName += sFilterExt;
1535 sFilterName += ')';
1536 pFileDlg->AddFilter( sFilterName, sFilterExt );
1537 pFileDlg->SetCurrentFilter( sFilterName );
1539 if ( aLastDir.Len() || rFileName.Len() )
1541 INetURLObject aObj;
1542 if ( aLastDir.Len() )
1544 aObj.SetURL( aLastDir );
1545 if ( rFileName.Len() )
1546 aObj.insertName( rFileName );
1548 else
1549 aObj.SetURL( rFileName );
1551 if ( aObj.hasExtension() )
1553 m_sExtension4Save = aObj.getExtension(
1554 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1555 aObj.removeExtension();
1558 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1559 pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1562 pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ImportHdl ) );
1564 return aPath;
1567 //-------------------------------------------------------------------------
1569 ::com::sun::star::uno::Sequence< ::rtl::OUString >
1570 SfxOrganizeDlg_Impl::GetPaths_Impl( const String& rFileName )
1572 /* [Description]
1574 Query plural paths by FileDialog, for Import / Export from document
1575 templates
1577 [Parameter]
1579 const String& rFileName The default file name when dialog executes
1581 [Return value] Empty sequence when users have clicked
1582 'Cancel', a sequence just containing one
1583 file name with path when they have
1584 choosed one file or a sequence containing
1585 path and file names without path
1589 ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
1590 m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
1591 if ( pFileDlg )
1592 delete pFileDlg;
1593 pFileDlg = new sfx2::FileDialogHelper(
1594 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, SFXWB_MULTISELECTION );
1596 // add "All" filter
1597 pFileDlg->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ),
1598 DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
1600 // add template filter
1601 String sFilterName( SfxResId( STR_TEMPLATE_FILTER ) );
1602 String sFilterExt;
1603 // add filters of modules which are installed
1604 SvtModuleOptions aModuleOpt;
1605 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1606 sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
1607 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
1609 if ( sFilterExt.Len() > 0 )
1610 sFilterExt += ';';
1611 sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1613 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
1615 if ( sFilterExt.Len() > 0 )
1616 sFilterExt += ';';
1617 sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1619 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
1621 if ( sFilterExt.Len() > 0 )
1622 sFilterExt += ';';
1623 sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
1625 if ( sFilterExt.Len() > 0 )
1626 sFilterExt += ';';
1627 sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
1629 sFilterName += DEFINE_CONST_UNICODE( " (" );
1630 sFilterName += sFilterExt;
1631 sFilterName += ')';
1632 pFileDlg->AddFilter( sFilterName, sFilterExt );
1633 pFileDlg->SetCurrentFilter( sFilterName );
1635 if ( aLastDir.Len() || rFileName.Len() )
1637 INetURLObject aObj;
1638 if ( aLastDir.Len() )
1640 aObj.SetURL( aLastDir );
1641 if ( rFileName.Len() )
1642 aObj.insertName( rFileName );
1644 else
1645 aObj.SetURL( rFileName );
1647 if ( aObj.hasExtension() )
1649 m_sExtension4Save = aObj.getExtension(
1650 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1651 aObj.removeExtension();
1654 DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1655 pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1658 pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ExportHdl ) );
1660 return aPaths;
1663 //-------------------------------------------------------------------------
1665 sal_Bool SfxOrganizeDlg_Impl::DontDelete_Impl( SvLBoxEntry* pEntry )
1667 sal_uInt16 nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
1668 if(SfxOrganizeListBox_Impl::VIEW_FILES ==
1669 pFocusBox->GetViewType())
1670 nDepth++;
1671 if( (nDepth > 2 && !pEntry->GetUserData()) ||
1672 //Delete using GetContent forbidden
1673 nDepth==2 || // Template / Not deleting config header
1674 (nDepth==1 && SfxOrganizeListBox_Impl::VIEW_FILES ==
1675 pFocusBox->GetViewType()) || //Not deleting Files
1676 (0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2))
1677 //At least keep one template
1679 return sal_True;
1682 //If delete is pressed on e.g. a style entry go up the chain to find the
1683 //owning template
1684 while (nDepth > 1)
1686 pEntry = pFocusBox->GetParent(pEntry);
1687 --nDepth;
1689 SvLBoxEntry *pTemplateEntry = pEntry;
1691 sal_uInt16 nRegion = 0, nIndex = 0;
1692 GetIndices_Impl( pFocusBox, pTemplateEntry, nRegion, nIndex );
1693 const SfxDocumentTemplates* pTemplates = aMgr.GetTemplates();
1694 if ( !pTemplates || !pTemplates->HasUserContents( nRegion, nIndex ) )
1695 return sal_True;
1697 return sal_False;
1700 std::vector<rtl::OUString> SfxOrganizeDlg_Impl::GetAllFactoryURLs_Impl( ) const
1702 SvtModuleOptions aModOpt;
1703 const ::com::sun::star::uno::Sequence < ::rtl::OUString >& aServiceNames = aModOpt.GetAllServiceNames() ;
1704 std::vector<rtl::OUString> aList;
1705 sal_Int32 nCount = aServiceNames.getLength();
1706 for( sal_Int32 i=0; i<nCount; ++i )
1708 if ( SfxObjectFactory::GetStandardTemplate( aServiceNames[i] ).Len() > 0 )
1710 SvtModuleOptions::EFactory eFac = SvtModuleOptions::E_WRITER;
1711 SvtModuleOptions::ClassifyFactoryByName( aServiceNames[i], eFac );
1712 aList.push_back(aModOpt.GetFactoryEmptyDocumentURL(eFac));
1716 return aList;
1719 sal_Bool SfxOrganizeDlg_Impl::GetServiceName_Impl( String& rName, String& rFileURL ) const
1721 sal_Bool bRet = sal_False;
1722 const SfxDocumentTemplates* pTemplates = aMgr.GetTemplates();
1723 SvLBoxEntry* pEntry = pFocusBox ? pFocusBox->FirstSelected() : NULL;
1724 sal_uInt16 nRegion = 0, nIndex = 0;
1725 GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
1726 rFileURL = pTemplates->GetPath( nRegion, nIndex );
1727 if ( rFileURL.Len() > 0 )
1731 uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
1732 rFileURL,
1733 embed::ElementModes::READ );
1734 sal_uIntPtr nFormat = SotStorage::GetFormatID( xStorage );
1735 const SfxFilter* pFilter =
1736 SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat );
1737 if ( pFilter )
1739 rName = pFilter->GetServiceName();
1740 bRet = sal_True;
1743 catch( uno::Exception& )
1747 return bRet;
1750 long SfxOrganizeDlg_Impl::Dispatch_Impl( sal_uInt16 nId, Menu* _pMenu )
1752 /* [Description]
1754 Processing the events from MenuButton or Accelerator
1756 [Parameter]
1758 sal_uInt16 nId Event ID
1760 [Return value] 1: Event has been processed,
1761 0: Event has not been processed (SV-Menu)
1765 SuspendAccel aTmp(&aEditAcc);
1766 SvLBoxEntry *pEntry = pFocusBox? pFocusBox->FirstSelected(): 0;
1767 sal_Bool bHandled = sal_True;
1768 switch(nId)
1770 case ID_NEW:
1772 if(!pEntry)
1773 return 1;
1774 if(pFocusBox->GetViewType() == SfxOrganizeListBox_Impl::VIEW_TEMPLATES)
1776 if(0 == pFocusBox->GetModel()->GetDepth(pEntry))
1778 const rtl::OUString aNoName(SFX2_RESSTR(STR_NONAME));
1779 SvLBoxEntry* pParent = pFocusBox->GetParent(pEntry);
1780 rtl::OUString aName(aNoName);
1781 sal_Int32 n = 1;
1782 while(!pFocusBox->IsUniqName_Impl(aName, pParent))
1784 aName = aNoName + rtl::OUString::valueOf(n++);
1786 aMgr.InsertDir( pFocusBox, aName,
1787 (sal_uInt16)pFocusBox->GetModel()->GetRelPos(pEntry)+1);
1790 break;
1793 case ID_DELETE:
1795 if(!pEntry || DontDelete_Impl(pEntry))
1796 return 1;
1797 const sal_uInt16 nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
1798 if(nDepth < 2)
1800 if(0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2) return 1;
1801 if(SfxOrganizeListBox_Impl::VIEW_TEMPLATES == pFocusBox->GetViewType())
1803 sal_uInt16 nResId = nDepth? STR_DELETE_TEMPLATE :
1804 STR_DELETE_REGION;
1805 if( !QueryDelete_Impl(
1806 pDialog, nResId, pFocusBox->GetEntryText(pEntry)))
1807 return 1;
1808 if ( STR_DELETE_REGION == nResId &&
1809 pFocusBox->GetChildCount(pEntry))
1811 QueryBox aQBox(pDialog, SfxResId(MSG_REGION_NOTEMPTY));
1812 if(RET_NO == aQBox.Execute())
1813 return 1;
1815 sal_uInt16 nRegion = 0, nIndex = 0;
1816 GetIndices_Impl(pFocusBox, pEntry, nRegion, nIndex);
1818 sal_uInt16 nDeleteInd = ( STR_DELETE_REGION == nResId? USHRT_MAX: nIndex );
1819 if ( !aMgr.Delete( pFocusBox, nRegion, nDeleteInd ) )
1820 ErrorDelete_Impl(
1821 pDialog,
1822 pFocusBox->GetEntryText(pEntry),
1823 ( nDeleteInd == USHRT_MAX && pFocusBox->GetChildCount(pEntry) ) );
1826 //Content Format
1827 else if(nDepth + pFocusBox->GetDocLevel() >= 2)
1829 if(!QueryDelete_Impl(pDialog, STR_DELETE_TEMPLATE, pFocusBox->GetEntryText(pEntry)))
1830 return 1;
1831 Path aPath(pFocusBox, pEntry);
1833 // it is ok to use the SfxObjectShellRef here since the object that
1834 // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
1835 SfxObjectShellRef aRef = pFocusBox->GetObjectShell(aPath);
1836 if(aRef.Is() &&
1837 aRef->Remove(aPath[1+pFocusBox->GetDocLevel()],
1838 aPath[2+pFocusBox->GetDocLevel()],
1839 aPath[3+pFocusBox->GetDocLevel()]))
1840 pFocusBox->GetModel()->Remove(pEntry);
1841 else
1842 ErrorDelete_Impl(pDialog, pFocusBox->GetEntryText(pEntry), sal_False );
1844 break;
1847 case ID_EDIT:
1849 if(!pEntry)
1850 return 1;
1851 sal_uInt16 nRegion = 0, nIndex = 0;
1852 GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
1853 const SfxStringItem aName( SID_FILE_NAME, aMgr.GetTemplates()->GetPath( nRegion, nIndex ) );
1854 const SfxStringItem aLongName( SID_FILE_LONGNAME, pFocusBox->GetEntryText( pEntry ) );
1855 const SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private:user" ) );
1856 const SfxStringItem aTargetName( SID_TARGETNAME, DEFINE_CONST_UNICODE( "_default" ) );
1857 const SfxBoolItem aTemplateIndicator( SID_TEMPLATE, sal_False );
1859 SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
1860 &aName, &aLongName, &aReferer, &aTargetName, &aTemplateIndicator, 0L );
1861 pDialog->EndDialog( RET_EDIT_STYLE );
1862 break;
1865 case ID_COPY_FROM:
1867 if ( !pEntry )
1868 return 1;
1869 m_nRegion = 0;
1870 m_nIndex = 0;
1871 GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
1872 GetPaths_Impl( String() );
1873 break;
1876 case ID_COPY_TO:
1878 if ( !pEntry )
1879 return 1;
1880 m_nRegion = 0;
1881 m_nIndex = 0;
1882 GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
1883 GetPath_Impl( sal_False, aMgr.GetTemplates()->GetFileName( m_nRegion, m_nIndex ) );
1884 break;
1887 case ID_RESCAN:
1888 if ( !aMgr.Rescan() )
1889 ErrorBox( pDialog, SfxResId( MSG_ERROR_RESCAN ) ).Execute();
1890 if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aLeftLb.GetViewType() )
1891 aLeftLb.Reset();
1892 if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aRightLb.GetViewType() )
1893 aRightLb.Reset();
1894 break;
1896 case ID_PRINT:
1898 if ( !pEntry )
1899 return 1;
1900 Path aPath( pFocusBox, pEntry );
1902 // it is ok to use the SfxObjectShellRef here since the object that
1903 // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
1904 SfxObjectShellRef aRef = pFocusBox->GetObjectShell( aPath );
1905 if ( aRef.Is() )
1907 const sal_uInt16 nDocLevel = pFocusBox->GetDocLevel();
1908 if ( !pPrt )
1909 pPrt = new Printer;
1910 SvLBoxEntry *pDocEntry = pEntry;
1911 while ( pFocusBox->GetModel()->GetDepth( pDocEntry ) > nDocLevel )
1912 pDocEntry = pFocusBox->GetParent( pDocEntry );
1913 const String aName(pFocusBox->GetEntryText(pDocEntry));
1914 if ( !aRef->Print( *pPrt, aPath[1+nDocLevel],
1915 aPath[2+nDocLevel], aPath[3+nDocLevel], &aName ) )
1916 ErrorBox( pDialog, SfxResId( MSG_PRINT_ERROR ) ).Execute();
1918 break;
1921 case ID_PRINTER_SETUP:
1923 PrinterSetupDialog* pDlg = new PrinterSetupDialog( pDialog );
1924 if ( !pPrt )
1925 pPrt = new Printer;
1926 pDlg->SetPrinter( pPrt );
1927 pDlg->Execute();
1928 delete pDlg;
1929 break;
1932 case ID_DEFAULT_TEMPLATE:
1934 String aServiceName, aFileURL;
1935 if ( GetServiceName_Impl( aServiceName, aFileURL ) )
1936 SfxObjectFactory::SetStandardTemplate( aServiceName, aFileURL );
1937 break;
1940 default:
1941 bHandled = sal_False;
1944 if ( !bHandled && ( nId > ID_RESET_DEFAULT_TEMPLATE && nId <= ID_RESET_DEFAULT_TEMPLATE_END ) )
1946 Menu* pSubMenu = _pMenu ? _pMenu : aEditBtn.GetPopupMenu()->GetPopupMenu( ID_RESET_DEFAULT_TEMPLATE );
1947 if ( pSubMenu )
1949 String aServiceName = SfxObjectShell::GetServiceNameFromFactory( pSubMenu->GetItemCommand( nId ) );
1950 SfxObjectFactory::SetStandardTemplate( aServiceName, String() );
1951 bHandled = sal_True;
1955 return bHandled ? 1 : 0;
1958 //-------------------------------------------------------------------------
1960 IMPL_LINK_INLINE_START( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
1962 /* [Description]
1964 SelectHandler of Menu and Menubuttons (SV)
1966 [Parameter]
1968 MenuButton *pBtn Button triggering the event
1970 [Return value] 1: Event has been processed,
1971 0: Event has not been processed (SV-Menu)
1974 return Dispatch_Impl( pMenu->GetCurItemId(), pMenu );
1976 IMPL_LINK_INLINE_END( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
1978 //-------------------------------------------------------------------------
1980 IMPL_LINK( SfxOrganizeDlg_Impl, AccelSelect_Impl, Accelerator *, pAccel )
1982 /* [Description]
1984 SelectHandler of Accelerators (SV)
1986 [Parameter]
1988 Accelerator *pAccel Accelerator triggering the event
1990 [Return value] 1: Event has been processed,
1991 0: Event has not been processed (SV)
1995 SvLBoxEntry* pEntry = pFocusBox && pFocusBox->GetSelectionCount() ?
1996 pFocusBox->FirstSelected() : NULL ;
1997 return pEntry && ( pAccel->GetCurItemId() == ID_NEW || !DontDelete_Impl( pEntry ) ) ?
1998 Dispatch_Impl( pAccel->GetCurItemId(), NULL ) : 0;
2001 IMPL_LINK( SfxOrganizeDlg_Impl, MenuActivate_Impl, Menu *, pMenu )
2003 /* [Description]
2005 ActivateHandler of Menu and Menubuttons (SV)
2007 [Parameter]
2009 Menu *pMenu Event triggering the Menu
2011 [Return value] 1: Event has been processed,
2012 0: Event has not been processed (SV-Menu)
2015 if ( pFocusBox && pFocusBox->IsEditingActive() )
2016 pFocusBox->EndEditing( sal_False );
2017 sal_Bool bEnable = ( pFocusBox && pFocusBox->GetSelectionCount() );
2018 SvLBoxEntry* pEntry = bEnable ? pFocusBox->FirstSelected() : NULL;
2019 const sal_uInt16 nDepth =
2020 ( bEnable && pFocusBox->GetSelectionCount() ) ? pFocusBox->GetModel()->GetDepth( pEntry ) : 0;
2021 const sal_uInt16 nDocLevel = bEnable ? pFocusBox->GetDocLevel() : 0;
2022 int eVT = pFocusBox ? pFocusBox->GetViewType() : 0;
2023 // Create only Template
2024 pMenu->EnableItem( ID_NEW, bEnable && 0 == nDepth && SfxOrganizeListBox_Impl::VIEW_TEMPLATES == eVT );
2025 // Template: Delete level 0,1,3ff
2026 // At least one region must be retained
2027 // Files: Delete level> 2
2029 pMenu->EnableItem( ID_DELETE, bEnable && !DontDelete_Impl( pEntry ) );
2030 pMenu->EnableItem( ID_EDIT,
2031 bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel
2032 && !DontDelete_Impl( pEntry ) );
2033 pMenu->EnableItem( ID_COPY_FROM,
2034 bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
2035 ( nDepth == nDocLevel || nDepth == nDocLevel - 1 ) );
2036 pMenu->EnableItem( ID_COPY_TO,
2037 bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
2038 nDepth == nDocLevel );
2039 pMenu->EnableItem( ID_RESCAN,
2040 SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aRightLb.GetViewType() ||
2041 SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aLeftLb.GetViewType() );
2042 sal_Bool bPrint = bEnable && nDepth > pFocusBox->GetDocLevel();
2043 if ( bPrint && pPrt )
2044 bPrint = !pPrt->IsPrinting() && !pPrt->IsJobActive();
2045 if ( bPrint && bEnable )
2047 // only styles printable
2048 Path aPath( pFocusBox, pFocusBox->FirstSelected() );
2049 sal_uInt16 nIndex = aPath[ nDocLevel + 1 ];
2050 bPrint = ( nIndex == CONTENT_STYLE );
2052 pMenu->EnableItem( ID_PRINT, bPrint );
2054 if ( bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel )
2056 String aFactoryURL, aFileURL;
2057 bEnable = GetServiceName_Impl( aFactoryURL, aFileURL );
2059 else if ( bEnable )
2060 bEnable = sal_False;
2061 pMenu->EnableItem( ID_DEFAULT_TEMPLATE, bEnable );
2063 bEnable = sal_True;
2064 std::vector<rtl::OUString> aList(GetAllFactoryURLs_Impl());
2065 if (!aList.empty())
2067 PopupMenu* pSubMenu = new PopupMenu;
2068 sal_uInt16 nItemId = ID_RESET_DEFAULT_TEMPLATE + 1;
2069 for(std::vector<rtl::OUString>::const_iterator i = aList.begin(); i != aList.end(); ++i)
2071 INetURLObject aObj(*i);
2072 String aTitle = SvFileInformationManager::GetDescription(aObj);
2073 pSubMenu->InsertItem(nItemId, aTitle, SvFileInformationManager::GetImage(aObj, false));
2074 pSubMenu->SetItemCommand(nItemId++, *i);
2075 DBG_ASSERT( nItemId <= ID_RESET_DEFAULT_TEMPLATE_END, "menu item id overflow" );
2077 pMenu->SetPopupMenu( ID_RESET_DEFAULT_TEMPLATE, pSubMenu );
2079 else
2080 bEnable = sal_False;
2082 pMenu->EnableItem( ID_RESET_DEFAULT_TEMPLATE, bEnable );
2084 return 1;
2087 //-------------------------------------------------------------------------
2089 IMPL_LINK( SfxOrganizeDlg_Impl, GetFocus_Impl, SfxOrganizeListBox_Impl *, pBox )
2091 /* [Description]
2093 GetFocus-Handler, is called from the Select-Handler of ListBox
2094 Used in the listBox that has the focus and to determine its condition.
2096 [Parameter]
2098 SfxOrganizeListBox *pBox The calling Box
2102 if(pFocusBox && pFocusBox != pBox)
2103 pFocusBox->SelectAll(sal_False);
2104 pFocusBox = pBox;
2105 aFilesBtn.Enable( SfxOrganizeListBox_Impl::VIEW_FILES ==
2106 pFocusBox->GetViewType() );
2107 return 0;
2110 //-------------------------------------------------------------------------
2112 IMPL_LINK( SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl, ListBox *, pBox )
2114 /* [Description]
2116 Select-Handler, is called from the Select-Handler of ListBox.
2117 If the mode of the Boxes are different (Document view or Template view)
2118 then the models are separated, otherwise joined together.
2120 [Parameter]
2122 ListBox *pBox The calling Box
2125 const SfxOrganizeListBox_Impl::DataEnum
2126 eViewType = pBox->GetSelectEntryPos() == 0 ?
2127 SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
2128 if(eViewType!= aLeftLb.GetViewType()) {
2129 aLeftLb.SetViewType(eViewType);
2130 if(aRightLb.GetViewType() == eViewType)
2131 aLeftLb.SetModel(aRightLb.GetModel());
2132 else {
2133 // Models trennen
2134 aLeftLb.DisconnectFromModel();
2135 aLeftLb.Reset();
2138 GetFocus_Impl(&aLeftLb);
2139 return 0;
2142 //-------------------------------------------------------------------------
2144 IMPL_LINK( SfxOrganizeDlg_Impl, RightListBoxSelect_Impl, ListBox *, pBox )
2146 /* [Description]
2148 Select-Handler, will be called by Select-Handler of the ListBox.
2149 If the mode of the Boxes are different (Document view or Template view)
2150 then the models are separated, otherwise joined together.
2152 [Parameter]
2154 ListBox *pBox The calling Box
2157 const SfxOrganizeListBox_Impl::DataEnum eViewType =
2158 pBox->GetSelectEntryPos() == 0 ?
2159 SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
2160 if(eViewType!= aRightLb.GetViewType())
2162 aRightLb.SetViewType(eViewType);
2163 if(aLeftLb.GetViewType() == eViewType)
2164 aRightLb.SetModel(aLeftLb.GetModel());
2165 else
2167 // Separate models
2168 aRightLb.DisconnectFromModel();
2169 aRightLb.Reset();
2172 aRightLb.GrabFocus();
2173 GetFocus_Impl(&aRightLb);
2174 return 0;
2177 //-------------------------------------------------------------------------
2179 IMPL_LINK( SfxOrganizeDlg_Impl, OnAddressTemplateClicked, Button *, pButton )
2181 (void)pButton; //unused
2182 svt::AddressBookSourceDialog aDialog(pDialog, ::comphelper::getProcessServiceFactory());
2183 aDialog.Execute();
2184 return 0L;
2187 //-------------------------------------------------------------------------
2189 IMPL_LINK( SfxOrganizeDlg_Impl, AddFiles_Impl, Button *, pButton )
2191 /* [Description]
2193 Handler of the button for adding files through Dialog.
2195 [Parameter]
2197 Button * Button, triggering this Event
2201 (void)pButton; //unused
2202 if ( pFileDlg )
2203 delete pFileDlg;
2204 pFileDlg = new sfx2::FileDialogHelper(
2205 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
2206 0, String() );
2208 // add config and basic filter
2209 static String sOpenBracket( DEFINE_CONST_UNICODE( " (" ) );
2210 static String sCloseBracket( DEFINE_CONST_UNICODE( ")" ) );
2211 static String sConfigExt( DEFINE_CONST_UNICODE( "*.cfg" ) );
2212 static String sBasicExt( DEFINE_CONST_UNICODE( "*.sbl" ) );
2214 String sFilterName( SfxResId( RID_STR_FILTCONFIG ) );
2215 sFilterName += sOpenBracket;
2216 sFilterName += sConfigExt;
2217 sFilterName += sCloseBracket;
2218 pFileDlg->AddFilter( sFilterName, sConfigExt );
2220 sFilterName = String( SfxResId( RID_STR_FILTBASIC ) );
2221 sFilterName += sOpenBracket;
2222 sFilterName += sBasicExt;
2223 sFilterName += sCloseBracket;
2224 pFileDlg->AddFilter( sFilterName, sBasicExt );
2226 // set "All" filter as current
2227 pFileDlg->SetCurrentFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ) );
2229 if ( aLastDir.Len() )
2230 pFileDlg->SetDisplayDirectory( aLastDir );
2232 pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, AddFilesHdl ) );
2234 return 0;
2237 //-------------------------------------------------------------------------
2239 IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, ImportHdl)
2241 DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
2243 if ( ERRCODE_NONE == pFileDlg->GetError() )
2245 String aPath = pFileDlg->GetPath();
2246 INetURLObject aObj( aPath );
2248 // we want to keep the original extension when exporting, the file open dialog
2249 // always sets the extension to *.vor
2250 if ( pFileDlg->GetDialogType() ==
2251 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE )
2253 if ( aObj.hasExtension() )
2254 aObj.removeExtension();
2256 aObj.setExtension( m_sExtension4Save );
2257 aPath = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2260 aObj.removeSegment();
2261 aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2263 if ( aPath.Len() && !aMgr.CopyTo( m_nRegion, m_nIndex, aPath ) )
2265 String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
2266 aText.SearchAndReplaceAscii( "$1", aPath );
2267 ErrorBox( pDialog, WB_OK, aText ).Execute();
2271 return 0L;
2274 //-------------------------------------------------------------------------
2276 IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, ExportHdl)
2278 DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
2279 ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
2281 if ( ERRCODE_NONE == pFileDlg->GetError() )
2283 aPaths = pFileDlg->GetMPath();
2284 sal_Int32 lastCount = aPaths.getLength() - 1;
2285 INetURLObject aObj( aPaths.getArray()[ lastCount ] );
2287 aObj.removeSegment();
2288 aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2291 sal_Int32 nCount = aPaths.getLength();
2292 if ( 1 == nCount )
2294 String aPath = String( aPaths.getArray()[0] );
2295 if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
2297 String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
2298 aText.SearchAndReplaceAscii( "$1", aPath );
2299 ErrorBox( pDialog, WB_OK, aText ).Execute();
2302 else if ( nCount > 1 )
2304 INetURLObject aPathObj( aPaths[0] );
2305 aPathObj.setFinalSlash();
2306 for ( sal_uInt16 i = 1; i < nCount; ++i )
2308 if ( 1 == i )
2309 aPathObj.Append( aPaths[i] );
2310 else
2311 aPathObj.setName( aPaths[i] );
2312 String aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE );
2313 if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
2315 String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
2316 aText.SearchAndReplaceAscii( "$1", aPath );
2317 ErrorBox( pDialog, WB_OK, aText ).Execute();
2322 return 0L;
2325 //-------------------------------------------------------------------------
2327 IMPL_LINK_NOARG(SfxOrganizeDlg_Impl, AddFilesHdl)
2329 if ( ERRCODE_NONE == pFileDlg->GetError() )
2331 String aPath = pFileDlg->GetPath();
2332 aMgr.InsertFile( pFocusBox, aPath );
2333 INetURLObject aObj( aPath );
2334 aObj.removeSegment();
2335 aObj.setFinalSlash();
2336 aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2339 return 0L;
2342 //-------------------------------------------------------------------------
2344 short SfxTemplateOrganizeDlg::Execute()
2346 /* [Description]
2348 Overloaded Execute method; stores changes to the document templates
2349 (SV-Methode)
2354 const short nRet = ModalDialog::Execute();
2355 if(RET_CANCEL != nRet)
2357 pImp->aMgr.SaveAll(this);
2358 SfxTemplateDialog* pTemplDlg = SFX_APP()->GetTemplateDialog();
2359 if(pTemplDlg)
2360 pTemplDlg->Update();
2362 return nRet;
2366 //-------------------------------------------------------------------------
2368 SfxTemplateOrganizeDlg::SfxTemplateOrganizeDlg(Window * pParent,
2369 SfxDocumentTemplates *pTempl)
2370 : ModalDialog( pParent, SfxResId(DLG_ORGANIZE)),
2371 pImp( new SfxOrganizeDlg_Impl(this, pTempl) )
2373 /* [Description]
2375 Constructor
2378 FreeResource();
2381 //-------------------------------------------------------------------------
2383 SfxTemplateOrganizeDlg::~SfxTemplateOrganizeDlg()
2385 GetpApp()->RemoveAccel(&pImp->aEditAcc);
2386 delete pImp->pPrt;
2387 delete pImp;
2390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */