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"
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>
57 #include <sfx2/docfac.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"
66 #include <sfx2/sfx.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 //=========================================================================
87 SuspendAccel( Accelerator
* pA
)
90 GetpApp()->RemoveAccel( pAccel
);
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
;
126 // save pointer for asynchronous D&D
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
;
136 String m_sExtension4Save
;
138 SfxOrganizeListBox_Impl aLeftLb
;
141 SfxOrganizeListBox_Impl aRightLb
;
147 PushButton aAddressTemplateBtn
;
148 PushButton aFilesBtn
;
150 Accelerator aEditAcc
;
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
);
180 SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg
* pParent
, SfxDocumentTemplates
* pTempl
);
181 ~SfxOrganizeDlg_Impl();
184 //-------------------------------------------------------------------------
186 SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg
* pParent
,
187 SfxDocumentTemplates
* pTempl
) :
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
),
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
);
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
);
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
);
290 aRightLb
.Reset();//SetModel(aLeftLb.GetModel());
295 aLeftLb
.SelectAll( sal_False
);
296 aRightLb
.SelectAll( sal_False
);
297 aRightLb
.GrabFocus();
300 //-------------------------------------------------------------------------
302 SfxOrganizeDlg_Impl::~SfxOrganizeDlg_Impl()
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
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
)
344 User information that the template rName could not be deleted.
349 String
aText( SfxResId( STR_ERROR_DELETE_TEMPLATE_DIR
) );
350 ErrorBox( pParent
, WB_OK
, aText
).Execute();
354 String
aText( SfxResId( STR_ERROR_DELETE_TEMPLATE
) );
355 aText
.SearchAndReplaceAscii( "$1", rName
);
356 ErrorBox( pParent
, WB_OK
, aText
).Execute();
361 //=========================================================================
365 Implementation class, the benchmark for sal_uInt16-Array
370 std::vector
<sal_uInt16
> aUS
;
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 //==========================================================================
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
404 Path(SvLBox
*pBox
, SvLBoxEntry
*pEntry
);
405 Path(const Path
&rPath
):
410 const Path
&operator=(const Path
&rPath
)
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");
441 SvLBoxEntry
*pParent
= pBox
->GetParent(pEntry
);
443 pData
->aUS
.insert(pData
->aUS
.begin(),
444 (sal_uInt16
)pBox
->GetModel()->GetRelPos(pEntry
));
448 pParent
= pBox
->GetParent(pEntry
);
452 //-------------------------------------------------------------------------
454 SvLBoxEntry
*GetIndices_Impl(SvLBox
*pBox
,
460 Region and position within a range for a template is determined.
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)
474 <class Path> (in certain circumstances this function can also be
475 dispensed in favor of the Path)
481 rRegion
= rOffset
= 0;
484 if(0 == pBox
->GetModel()->GetDepth(pEntry
))
486 rRegion
= (sal_uInt16
)pBox
->GetModel()->GetRelPos(pEntry
);
490 SvLBoxEntry
*pParent
= pBox
->GetParent(pEntry
);
491 rRegion
= (sal_uInt16
)pBox
->GetModel()->GetRelPos(pParent
);
492 rOffset
= (sal_uInt16
)pBox
->GetModel()->GetRelPos(pEntry
);
496 //-------------------------------------------------------------------------
498 sal_Bool
SfxOrganizeListBox_Impl::Select( SvLBoxEntry
* pEntry
, sal_Bool 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
,
525 Move or copy a document templates
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
542 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
543 SvLBoxEntry *pSource,
544 SvLBoxEntry* pTarget,
545 SvLBoxEntry *&pNewParent,
548 <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
549 SvLBoxEntry* pSource,
550 SvLBoxEntry *&pNewParent,
552 <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
553 SvLBoxEntry* pSource,
554 SvLBoxEntry *&pNewParent,
559 sal_Bool bOk
= sal_False
;
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
);
570 pMgr
->Copy(nTargetRegion
, nTargetIndex
+1,
571 nSourceRegion
, nSourceIndex
):
572 pMgr
->Move(nTargetRegion
, nTargetIndex
+1,
573 nSourceRegion
, nSourceIndex
);
577 if(pSourceBox
->GetModel()->GetDepth(pSource
) == GetModel()->GetDepth(pTarget
))
579 pNewParent
= GetParent(pTarget
);
580 rIdx
= GetModel()->GetRelPos(pTarget
)+1;
584 if(nTargetIndex
== USHRT_MAX
)
586 pNewParent
= pTarget
;
590 SvLBox::NotifyCopying(
591 pTarget
, pSource
, pNewParent
, rIdx
);
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();
606 //-------------------------------------------------------------------------
608 sal_Bool
SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox
*pSourceBox
,
609 SvLBoxEntry
*pSource
,
610 SvLBoxEntry
* pTarget
,
611 SvLBoxEntry
*&pNewParent
,
616 Move or copy document contents
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
633 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
634 SvLBoxEntry *pSource,
635 SvLBoxEntry* pTarget,
636 SvLBoxEntry *&pNewParent,
639 <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
640 SvLBoxEntry* pSource,
641 SvLBoxEntry *&pNewParent,
643 <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
644 SvLBoxEntry* pSource,
645 SvLBoxEntry *&pNewParent,
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
);
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
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;
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
711 if(i
< 2 && p
[i
+1] != INDEX_IGNORE
&&
712 pChildIter
->HasChildrenOnDemand() &&
713 !GetModel()->HasChildren(pChildIter
))
714 RequestingChildren(pChildIter
);
715 pParentIter
= pChildIter
;
718 pNewParent
= pParentIter
;
719 if(!IsExpanded(pNewParent
) &&
720 pNewParent
->HasChildrenOnDemand() &&
721 !GetModel()->HasChildren(pNewParent
))
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
);
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],
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
,
766 Notification that an item will be moved.
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
782 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
783 SvLBoxEntry *pSource,
784 SvLBoxEntry* pTarget,
785 SvLBoxEntry *&pNewParent,
788 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
789 SvLBoxEntry *pSource,
790 SvLBoxEntry* pTarget,
791 SvLBoxEntry *&pNewParent,
794 <sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
795 SvLBoxEntry* pSource,
796 SvLBoxEntry *&pNewParent,
801 sal_Bool bOk
= sal_False
;
802 SvLBox
* pSourceBox
= GetSourceView();
804 pSourceBox
= pDlg
->pSourceView
;
805 DBG_ASSERT( pSourceBox
, "no source view" );
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
);
813 bOk
= MoveOrCopyContents(pSourceBox
, pSource
, pTarget
, pNewParent
, rIdx
, sal_False
);
818 //-------------------------------------------------------------------------
820 sal_Bool
SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry
*pTarget
,
821 SvLBoxEntry
* pSource
,
822 SvLBoxEntry
*&pNewParent
,
826 Notification that an item will be moved.
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
841 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
842 SvLBoxEntry *pSource,
843 SvLBoxEntry* pTarget,
844 SvLBoxEntry *&pNewParent,
847 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
848 SvLBoxEntry *pSource,
849 SvLBoxEntry* pTarget,
850 SvLBoxEntry *&pNewParent,
853 <sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
854 SvLBoxEntry* pSource,
855 SvLBoxEntry *&pNewParent,
859 sal_Bool bOk
= sal_False
;
860 SvLBox
* pSourceBox
= GetSourceView();
862 pSourceBox
= pDlg
->pSourceView
;
863 DBG_ASSERT( pSourceBox
, "no source view" );
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
);
870 bOk
= MoveOrCopyContents( pSourceBox
, pSource
, pTarget
, pNewParent
, rIdx
, sal_True
);
875 //-------------------------------------------------------------------------
877 sal_Bool
SfxOrganizeListBox_Impl::EditingEntry( SvLBoxEntry
* pEntry
, Selection
& )
881 Check whether an item can be edited
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
);
898 //-------------------------------------------------------------------------
900 sal_Bool
SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry
* pEntry
, const rtl::OUString
& rText
)
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.
910 sal_Bool sal_True: The name in the display should be changed
911 sal_False: The name should not be changed
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
) );
929 if ( !IsUniqName_Impl( rText
, pParent
, pEntry
) )
931 ErrorBox
aBox( this, SfxResId( MSG_ERROR_UNIQ_NAME
) );
936 sal_uInt16 nRegion
= 0, nIndex
= 0;
937 GetIndices_Impl( this, pEntry
, nRegion
, nIndex
);
939 if ( USHRT_MAX
!= nIndex
)
940 aOldName
= pMgr
->GetTemplates()->GetName( nRegion
, nIndex
);
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();
955 //-------------------------------------------------------------------------
957 DragDropMode
SfxOrganizeListBox_Impl::NotifyStartDrag( TransferDataContainer
&, SvLBoxEntry
* pEntry
)
959 sal_uInt16 nSourceLevel
= GetModel()->GetDepth( pEntry
);
960 if ( VIEW_FILES
== GetViewType() )
962 if ( nSourceLevel
>= 2 )
963 bDropMoveOk
= sal_False
;
965 bDropMoveOk
= sal_True
;
967 return GetDragDropMode();
970 //-------------------------------------------------------------------------
972 sal_Bool
SfxOrganizeListBox_Impl::NotifyAcceptDrop( SvLBoxEntry
* pEntry
)
976 SvLBox
*pSource
= GetSourceView();
977 SvLBoxEntry
*pSourceEntry
= pSource
->FirstSelected();
978 if(pEntry
== pSourceEntry
)
980 sal_uInt16 nSourceLevel
= pSource
->GetModel()->GetDepth(pSourceEntry
);
981 if(VIEW_FILES
== ((SfxOrganizeListBox_Impl
*)pSource
)->GetViewType())
983 sal_uInt16 nTargetLevel
= GetModel()->GetDepth(pEntry
);
984 if(VIEW_FILES
== GetViewType())
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 &&
993 ((SfxOrganizeListBox_Impl
*)pSource
)->GetViewType()) ||
994 (nSourceLevel
== 1 && nTargetLevel
== 1 &&
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
) );
1017 return rEvt
.mnAction
;
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
)
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
;
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
) );
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
;
1068 pDlg
->pFinishedBox
= this;
1071 //-------------------------------------------------------------------------
1073 inline sal_uInt16
SfxOrganizeListBox_Impl::GetDocLevel() const
1077 Determines on which level there are documents (in the template view or
1082 sal_uInt16 Document level
1087 return eViewType
== VIEW_FILES
? 0: 1;
1090 //-------------------------------------------------------------------------
1092 SfxObjectShellRef
SfxOrganizeListBox_Impl::GetObjectShell(const Path
&rPath
)
1096 Access to the ObjectShell to which the current entry is connected.
1100 const Path &rPath Description of the current entry
1104 SfxObjectShellRef Reference to the ObjectShell
1113 SfxObjectShellRef aDoc
;
1114 if(eViewType
== VIEW_FILES
)
1115 aDoc
= pMgr
->CreateObjectShell(rPath
[0]);
1117 aDoc
= pMgr
->CreateObjectShell(rPath
[0], rPath
[1]);
1121 //-------------------------------------------------------------------------
1123 void SfxOrganizeListBox_Impl::RequestingChildren( SvLBoxEntry
* pEntry
)
1127 Sent to the children of an entry that is going to be inserted.
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
);
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
);
1163 const sal_uInt16 nCount
= aRef
->GetContentCount(aPath
[nDocLevel
+1]);
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
;
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()
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]);
1214 pMgr
->DeleteObjectShell(aPath
[0], aPath
[1]);
1215 // Delete all SubEntries
1216 SvLBoxEntry
*pToDel
= SvLBox::GetEntry(pEntry
, 0);
1219 GetModel()->Remove(pToDel
);
1220 pToDel
= SvLBox::GetEntry(pEntry
, 0);
1227 //-------------------------------------------------------------------------
1229 sal_Bool
SfxOrganizeListBox_Impl::IsUniqName_Impl(const String
&rText
,
1230 SvLBoxEntry
* pParent
, SvLBoxEntry
*pEntry
) const
1234 Checks whether a name is unique at its level.
1238 const String & Name of the search entry
1239 SvLBoxEntry* pSibling Siblings (referred to the level)
1243 sal_Bool sal_True, if the name is unique, otherwise sal_False
1247 SvLBoxEntry
* pChild
= FirstChild(pParent
);
1249 const String
aEntryText(GetEntryText(pChild
));
1250 if(COMPARE_EQUAL
== aEntryText
.CompareIgnoreCaseToAscii(rText
)&&(!pEntry
|| pEntry
!=pChild
))
1252 pChild
= NextSibling(pChild
);
1257 //-------------------------------------------------------------------------
1259 sal_uInt16
SfxOrganizeListBox_Impl::GetLevelCount_Impl(SvLBoxEntry
* pParent
) const
1261 SvLBoxEntry
* pChild
= FirstChild(pParent
);
1262 sal_uInt16 nCount
= 0;
1264 pChild
= NextSibling(pChild
);
1270 //-------------------------------------------------------------------------
1272 SvLBoxEntry
* SfxOrganizeListBox_Impl::InsertEntryByBmpType(
1273 const XubString
& rText
,
1275 SvLBoxEntry
* pParent
,
1276 sal_Bool bChildrenOnDemand
,
1281 SvLBoxEntry
* pEntry
= NULL
;
1282 const Image
* pExp
= NULL
;
1283 const Image
* pCol
= NULL
;
1287 case BMPTYPE_FOLDER
:
1288 pExp
= &aOpenedFolderBmp
;
1289 pCol
= &aClosedFolderBmp
;
1293 pExp
= &aOpenedDocBmp
;
1294 pCol
= &aClosedDocBmp
;
1298 OSL_FAIL( "SfxOrganizeListBox_Impl::InsertEntryByBmpType(): something forgotten?!" );
1301 pEntry
= SvTreeListBox::InsertEntry( rText
, *pExp
, *pCol
, pParent
, bChildrenOnDemand
, nPos
, pUserData
);
1306 //-------------------------------------------------------------------------
1308 SfxOrganizeListBox_Impl::SfxOrganizeListBox_Impl
1310 SfxOrganizeDlg_Impl
* pArgDlg
,
1316 SvTreeListBox( pParent
, nBits
),
1324 Constructor SfxOrganizeListBox
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" );
1346 SvLBox
* pSourceView
= GetSourceView();
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
);
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
;
1367 //-------------------------------------------------------------------------
1369 void SfxOrganizeListBox_Impl::Reset()
1373 Paste the items in the ListBox
1377 DBG_ASSERT( pMgr
!= 0, "No Manager" );
1379 SetUpdateMode(sal_False
);
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
);
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
);
1400 //-------------------------------------------------------------------------
1402 const Image
&SfxOrganizeListBox_Impl::GetClosedBmp(sal_uInt16 nLevel
) const
1406 Access to the bitmap for a closed entry at each level
1410 sal_uInt16 nLevel Indicator of the level, 2 levels are allowed
1414 const Image & The Image on level nLevel
1418 const Image
* pRet
= NULL
;
1422 default: OSL_FAIL( "Bitmap index overflow" );
1424 case 0: pRet
= &aClosedFolderBmp
;
1426 case 1: pRet
= &aClosedDocBmp
;
1433 //-------------------------------------------------------------------------
1435 const Image
&SfxOrganizeListBox_Impl::GetOpenedBmp(sal_uInt16 nLevel
) const
1439 Access to the bitmap for an open entry at each level
1443 sal_uInt16 nLevel Indicator of the level, 2 levels are allowed
1447 const Image & the image on the level nLevel
1452 const Image
* pRet
= NULL
;
1457 pRet
= &aOpenedFolderBmp
; break;
1459 pRet
= &aOpenedDocBmp
; break;
1461 pRet
= &aClosedFolderBmp
; break;
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
)
1480 Get path from FileDialog, for Import / Export of Templates
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'
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
;
1499 pFileDlg
= new sfx2::FileDialogHelper( nDialogType
, 0L );
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
) );
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 )
1515 sFilterExt
+= DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1517 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS
) )
1519 if ( sFilterExt
.Len() > 0 )
1521 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1523 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SDRAW
) )
1525 if ( sFilterExt
.Len() > 0 )
1527 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otg;*.std" );
1529 if ( sFilterExt
.Len() > 0 )
1531 sFilterExt
+= DEFINE_CONST_UNICODE( "*.vor" );
1533 sFilterName
+= DEFINE_CONST_UNICODE( " (" );
1534 sFilterName
+= sFilterExt
;
1536 pFileDlg
->AddFilter( sFilterName
, sFilterExt
);
1537 pFileDlg
->SetCurrentFilter( sFilterName
);
1539 if ( aLastDir
.Len() || rFileName
.Len() )
1542 if ( aLastDir
.Len() )
1544 aObj
.SetURL( aLastDir
);
1545 if ( rFileName
.Len() )
1546 aObj
.insertName( rFileName
);
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
) );
1567 //-------------------------------------------------------------------------
1569 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
1570 SfxOrganizeDlg_Impl::GetPaths_Impl( const String
& rFileName
)
1574 Query plural paths by FileDialog, for Import / Export from document
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" );
1593 pFileDlg
= new sfx2::FileDialogHelper(
1594 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, SFXWB_MULTISELECTION
);
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
) );
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 )
1611 sFilterExt
+= DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1613 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS
) )
1615 if ( sFilterExt
.Len() > 0 )
1617 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1619 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SDRAW
) )
1621 if ( sFilterExt
.Len() > 0 )
1623 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otg;*.std" );
1625 if ( sFilterExt
.Len() > 0 )
1627 sFilterExt
+= DEFINE_CONST_UNICODE( "*.vor" );
1629 sFilterName
+= DEFINE_CONST_UNICODE( " (" );
1630 sFilterName
+= sFilterExt
;
1632 pFileDlg
->AddFilter( sFilterName
, sFilterExt
);
1633 pFileDlg
->SetCurrentFilter( sFilterName
);
1635 if ( aLastDir
.Len() || rFileName
.Len() )
1638 if ( aLastDir
.Len() )
1640 aObj
.SetURL( aLastDir
);
1641 if ( rFileName
.Len() )
1642 aObj
.insertName( rFileName
);
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
) );
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())
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
1682 //If delete is pressed on e.g. a style entry go up the chain to find the
1686 pEntry
= pFocusBox
->GetParent(pEntry
);
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
) )
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
));
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(
1733 embed::ElementModes::READ
);
1734 sal_uIntPtr nFormat
= SotStorage::GetFormatID( xStorage
);
1735 const SfxFilter
* pFilter
=
1736 SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat
);
1739 rName
= pFilter
->GetServiceName();
1743 catch( uno::Exception
& )
1750 long SfxOrganizeDlg_Impl::Dispatch_Impl( sal_uInt16 nId
, Menu
* _pMenu
)
1754 Processing the events from MenuButton or Accelerator
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
;
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
);
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);
1795 if(!pEntry
|| DontDelete_Impl(pEntry
))
1797 const sal_uInt16 nDepth
= pFocusBox
->GetModel()->GetDepth(pEntry
);
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
:
1805 if( !QueryDelete_Impl(
1806 pDialog
, nResId
, pFocusBox
->GetEntryText(pEntry
)))
1808 if ( STR_DELETE_REGION
== nResId
&&
1809 pFocusBox
->GetChildCount(pEntry
))
1811 QueryBox
aQBox(pDialog
, SfxResId(MSG_REGION_NOTEMPTY
));
1812 if(RET_NO
== aQBox
.Execute())
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
) )
1822 pFocusBox
->GetEntryText(pEntry
),
1823 ( nDeleteInd
== USHRT_MAX
&& pFocusBox
->GetChildCount(pEntry
) ) );
1827 else if(nDepth
+ pFocusBox
->GetDocLevel() >= 2)
1829 if(!QueryDelete_Impl(pDialog
, STR_DELETE_TEMPLATE
, pFocusBox
->GetEntryText(pEntry
)))
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
);
1837 aRef
->Remove(aPath
[1+pFocusBox
->GetDocLevel()],
1838 aPath
[2+pFocusBox
->GetDocLevel()],
1839 aPath
[3+pFocusBox
->GetDocLevel()]))
1840 pFocusBox
->GetModel()->Remove(pEntry
);
1842 ErrorDelete_Impl(pDialog
, pFocusBox
->GetEntryText(pEntry
), sal_False
);
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
);
1871 GetIndices_Impl( pFocusBox
, pEntry
, m_nRegion
, m_nIndex
);
1872 GetPaths_Impl( String() );
1882 GetIndices_Impl( pFocusBox
, pEntry
, m_nRegion
, m_nIndex
);
1883 GetPath_Impl( sal_False
, aMgr
.GetTemplates()->GetFileName( m_nRegion
, m_nIndex
) );
1888 if ( !aMgr
.Rescan() )
1889 ErrorBox( pDialog
, SfxResId( MSG_ERROR_RESCAN
) ).Execute();
1890 if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== aLeftLb
.GetViewType() )
1892 if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== aRightLb
.GetViewType() )
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
);
1907 const sal_uInt16 nDocLevel
= pFocusBox
->GetDocLevel();
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();
1921 case ID_PRINTER_SETUP
:
1923 PrinterSetupDialog
* pDlg
= new PrinterSetupDialog( pDialog
);
1926 pDlg
->SetPrinter( pPrt
);
1932 case ID_DEFAULT_TEMPLATE
:
1934 String aServiceName
, aFileURL
;
1935 if ( GetServiceName_Impl( aServiceName
, aFileURL
) )
1936 SfxObjectFactory::SetStandardTemplate( aServiceName
, aFileURL
);
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
);
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
)
1964 SelectHandler of Menu and Menubuttons (SV)
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
)
1984 SelectHandler of Accelerators (SV)
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
)
2005 ActivateHandler of Menu and Menubuttons (SV)
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
);
2060 bEnable
= sal_False
;
2061 pMenu
->EnableItem( ID_DEFAULT_TEMPLATE
, bEnable
);
2064 std::vector
<rtl::OUString
> aList(GetAllFactoryURLs_Impl());
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
);
2080 bEnable
= sal_False
;
2082 pMenu
->EnableItem( ID_RESET_DEFAULT_TEMPLATE
, bEnable
);
2087 //-------------------------------------------------------------------------
2089 IMPL_LINK( SfxOrganizeDlg_Impl
, GetFocus_Impl
, SfxOrganizeListBox_Impl
*, pBox
)
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.
2098 SfxOrganizeListBox *pBox The calling Box
2102 if(pFocusBox
&& pFocusBox
!= pBox
)
2103 pFocusBox
->SelectAll(sal_False
);
2105 aFilesBtn
.Enable( SfxOrganizeListBox_Impl::VIEW_FILES
==
2106 pFocusBox
->GetViewType() );
2110 //-------------------------------------------------------------------------
2112 IMPL_LINK( SfxOrganizeDlg_Impl
, LeftListBoxSelect_Impl
, ListBox
*, pBox
)
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.
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());
2134 aLeftLb
.DisconnectFromModel();
2138 GetFocus_Impl(&aLeftLb
);
2142 //-------------------------------------------------------------------------
2144 IMPL_LINK( SfxOrganizeDlg_Impl
, RightListBoxSelect_Impl
, ListBox
*, pBox
)
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.
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());
2168 aRightLb
.DisconnectFromModel();
2172 aRightLb
.GrabFocus();
2173 GetFocus_Impl(&aRightLb
);
2177 //-------------------------------------------------------------------------
2179 IMPL_LINK( SfxOrganizeDlg_Impl
, OnAddressTemplateClicked
, Button
*, pButton
)
2181 (void)pButton
; //unused
2182 svt::AddressBookSourceDialog
aDialog(pDialog
, ::comphelper::getProcessServiceFactory());
2187 //-------------------------------------------------------------------------
2189 IMPL_LINK( SfxOrganizeDlg_Impl
, AddFiles_Impl
, Button
*, pButton
)
2193 Handler of the button for adding files through Dialog.
2197 Button * Button, triggering this Event
2201 (void)pButton
; //unused
2204 pFileDlg
= new sfx2::FileDialogHelper(
2205 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION
,
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
) );
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();
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();
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
)
2309 aPathObj
.Append( aPaths
[i
] );
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();
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
);
2342 //-------------------------------------------------------------------------
2344 short SfxTemplateOrganizeDlg::Execute()
2348 Overloaded Execute method; stores changes to the document templates
2354 const short nRet
= ModalDialog::Execute();
2355 if(RET_CANCEL
!= nRet
)
2357 pImp
->aMgr
.SaveAll(this);
2358 SfxTemplateDialog
* pTemplDlg
= SFX_APP()->GetTemplateDialog();
2360 pTemplDlg
->Update();
2366 //-------------------------------------------------------------------------
2368 SfxTemplateOrganizeDlg::SfxTemplateOrganizeDlg(Window
* pParent
,
2369 SfxDocumentTemplates
*pTempl
)
2370 : ModalDialog( pParent
, SfxResId(DLG_ORGANIZE
)),
2371 pImp( new SfxOrganizeDlg_Impl(this, pTempl
) )
2381 //-------------------------------------------------------------------------
2383 SfxTemplateOrganizeDlg::~SfxTemplateOrganizeDlg()
2385 GetpApp()->RemoveAccel(&pImp
->aEditAcc
);
2390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */