1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docvor.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <com/sun/star/embed/XStorage.hpp>
34 #include <com/sun/star/embed/ElementModes.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
40 #ifndef _SV_PRNSETUP_HXX //autogen
41 #include <svtools/prnsetup.hxx>
43 #include <vcl/cmdevt.hxx>
44 #include <vcl/menubtn.hxx>
45 #include <vcl/msgbox.hxx>
46 #include <vcl/print.hxx>
47 #include <svtools/style.hxx>
48 #include <svtools/stritem.hxx>
49 #include <svtools/eitem.hxx>
50 #include <svtools/sfxecode.hxx>
51 #include <svtools/ehdl.hxx>
52 #include <svtools/imagemgr.hxx>
53 #include <vcl/waitobj.hxx>
54 #include <tools/urlobj.hxx>
55 #include <tools/color.hxx>
56 #include <svtools/pathoptions.hxx>
57 #include <svtools/moduleoptions.hxx>
58 #include <sot/exchange.hxx>
59 #include <comphelper/storagehelper.hxx>
63 #include <sfx2/docfac.hxx>
65 #include <sfx2/doctempl.hxx>
66 #include <sfx2/templdlg.hxx>
67 #include "sfxtypes.hxx"
68 #include <sfx2/app.hxx>
69 #include <sfx2/dispatch.hxx>
70 #include "sfxresid.hxx"
72 #include <sfx2/sfx.hrc>
74 #include <sfx2/docfilt.hxx>
75 #include <sfx2/filedlghelper.hxx>
76 #include <sfx2/docfilt.hxx>
77 #include <sfx2/fcontnr.hxx>
78 #include <svtools/localresaccess.hxx>
79 #ifndef _SVT_DOC_ADDRESSTEMPLATE_HXX_
80 #include <svtools/addresstemplate.hxx>
82 #include <comphelper/processfactory.hxx>
83 #define _SVSTDARR_STRINGSDTOR
84 #include <svtools/svstdarr.hxx>
86 static const char cDelim
= ':';
87 BOOL
SfxOrganizeListBox_Impl::bDropMoveOk
= TRUE
;
89 using namespace ::com::sun::star
;
91 //=========================================================================
98 SuspendAccel( Accelerator
* pA
)
101 GetpApp()->RemoveAccel( pAccel
);
105 GetpApp()->InsertAccel( pAccel
);
109 //=========================================================================
112 inline void SfxOrganizeListBox_Impl::SetBitmaps(
113 const Image
&rOFolder
, const Image
&rCFolder
, const Image
&rODoc
, const Image
&rCDoc
,
114 const Image
&rOFolderHC
, const Image
&rCFolderHC
, const Image
&rODocHC
, const Image
&rCDocHC
)
116 aOpenedFolderBmp
= rOFolder
;
117 aClosedFolderBmp
= rCFolder
;
118 aOpenedDocBmp
= rODoc
;
119 aClosedDocBmp
= rCDoc
;
121 aOpenedFolderBmpHC
= rOFolderHC
;
122 aClosedFolderBmpHC
= rCFolderHC
;
123 aOpenedDocBmpHC
= rODocHC
;
124 aClosedDocBmpHC
= rCDocHC
;
128 //=========================================================================
130 #define NO_DROP_ACTION ((sal_Int8)-1)
132 class SfxOrganizeDlg_Impl
134 friend class SfxTemplateOrganizeDlg
;
135 friend class SfxOrganizeListBox_Impl
;
137 SuspendAccel
* pSuspend
;
138 SfxTemplateOrganizeDlg
* pDialog
;
140 SfxOrganizeListBox_Impl
* pFocusBox
;
143 // save pointer for asynchronous D&D
145 SvLBoxEntry
* pTargetEntry
;
146 SfxOrganizeListBox_Impl
* pFinishedBox
;
147 sal_Int8 nDropAction
;
148 bool bExecDropFinished
;
150 // save some variables for the asynchronous file dialog
153 String m_sExtension4Save
;
155 SfxOrganizeListBox_Impl aLeftLb
;
158 SfxOrganizeListBox_Impl aRightLb
;
164 PushButton aAddressTemplateBtn
;
165 PushButton aFilesBtn
;
167 Accelerator aEditAcc
;
171 sfx2::FileDialogHelper
* pFileDlg
;
173 SvStringsDtor
* GetAllFactoryURLs_Impl() const;
174 sal_Bool
GetServiceName_Impl( String
& rFactoryURL
, String
& rFileURL
) const;
175 long Dispatch_Impl( USHORT nId
, Menu
* _pMenu
);
176 String
GetPath_Impl( BOOL bOpen
, const String
& rFileName
);
177 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
178 GetPaths_Impl( const String
& rFileName
);
179 void InitBitmaps( void );
181 DECL_LINK( GetFocus_Impl
, SfxOrganizeListBox_Impl
* );
182 DECL_LINK( LeftListBoxSelect_Impl
, ListBox
* );
183 DECL_LINK( RightListBoxSelect_Impl
, ListBox
* );
184 DECL_LINK( AccelSelect_Impl
, Accelerator
* );
185 DECL_LINK( MenuSelect_Impl
, Menu
* );
186 DECL_LINK( MenuActivate_Impl
, Menu
* );
187 DECL_LINK( AddFiles_Impl
, Button
* );
188 DECL_LINK( OnAddressTemplateClicked
, Button
* );
190 DECL_LINK( ImportHdl
, sfx2::FileDialogHelper
* );
191 DECL_LINK( ExportHdl
, sfx2::FileDialogHelper
* );
192 DECL_LINK( AddFilesHdl
, sfx2::FileDialogHelper
* );
194 BOOL
DontDelete_Impl( SvLBoxEntry
* pEntry
);
195 void OkHdl( Button
* );
198 SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg
* pParent
, SfxDocumentTemplates
* pTempl
);
199 ~SfxOrganizeDlg_Impl();
202 //-------------------------------------------------------------------------
204 SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg
* pParent
,
205 SfxDocumentTemplates
* pTempl
) :
211 pSourceView ( NULL
),
212 pTargetEntry ( NULL
),
213 pFinishedBox ( NULL
),
214 nDropAction ( NO_DROP_ACTION
),
215 bExecDropFinished ( true ),
217 aLeftLb ( this, pParent
, WB_BORDER
| WB_TABSTOP
| WB_HSCROLL
, SfxOrganizeListBox_Impl::VIEW_TEMPLATES
),
218 aLeftTypLb ( pParent
, SfxResId( LB_LEFT_TYP
) ),
220 aRightLb ( this, pParent
, WB_BORDER
| WB_TABSTOP
| WB_HSCROLL
, SfxOrganizeListBox_Impl::VIEW_FILES
),
221 aRightTypLb ( pParent
, SfxResId( LB_RIGHT_TYP
) ),
223 aOkBtn ( pParent
, SfxResId( BTN_OK
) ),
224 aEditBtn ( pParent
, SfxResId( BTN_EDIT
) ),
225 aHelpBtn ( pParent
, SfxResId( BTN_HELP
) ),
226 aAddressTemplateBtn ( pParent
, SfxResId( BTN_ADDRESSTEMPLATE
) ),
227 aFilesBtn ( pParent
, SfxResId( BTN_FILES
) ),
229 aEditAcc ( SfxResId( ACC_EDIT
) ),
230 aMgr ( &aLeftLb
, &aRightLb
, pTempl
),
234 // update the SfxDocumentTemplates the manager works with
235 if ( aMgr
.GetTemplates() ) // should never fail, but who knows ....
237 // for this, show a wait cursor (it may take a while)
238 Window
* pWaitObjectRange
= pDialog
? pDialog
->GetParent() : NULL
;
239 if ( !pWaitObjectRange
)
240 pWaitObjectRange
= pDialog
;
242 WaitObject
aWaitCursor( pWaitObjectRange
);
243 const_cast< SfxDocumentTemplates
* >( aMgr
.GetTemplates() )->Update( sal_True
/* be smart */ );
244 // this const_cast is a hack - but the alternative would be to
245 // * have a method which returns the templates non-const
246 // * use a new SfxDocumentTemplates instance for the update (knowing that they all share the same
247 // implementation class)
248 // * always work with an own instance, even if we get only NULL in this ctor
251 aLeftLb
.SetHelpId( HID_CTL_ORGANIZER_LEFT
);
252 aRightLb
.SetHelpId( HID_CTL_ORGANIZER_RIGHT
);
254 String aWorkPath
= SvtPathOptions().GetWorkPath();
255 if ( aWorkPath
.Len() )
257 INetURLObject
aObj( aWorkPath
);
258 DBG_ASSERT( aObj
.GetProtocol() != INET_PROT_NOT_VALID
, "Illegal URL !" );
259 aObj
.setFinalSlash();
260 aLastDir
= aObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
265 String aProgURL
= SvtPathOptions().SubstituteVariable( String::CreateFromAscii("$(PROGURL)") );
266 INetURLObject
aObj( aProgURL
);
267 DBG_ASSERT( aObj
.GetProtocol() != INET_PROT_NOT_VALID
, "Illegal URL !" );
268 aLastDir
= aObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
273 aEditBtn
.GetPopupMenu()->SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl
, MenuSelect_Impl
) );
274 aEditBtn
.GetPopupMenu()->SetActivateHdl( LINK( this, SfxOrganizeDlg_Impl
, MenuActivate_Impl
) );
275 aEditAcc
.SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl
, AccelSelect_Impl
) );
276 GetpApp()->InsertAccel( &aEditAcc
);
278 aFilesBtn
.SetClickHdl(
279 LINK(this,SfxOrganizeDlg_Impl
, AddFiles_Impl
));
280 aAddressTemplateBtn
.SetClickHdl(
281 LINK(this,SfxOrganizeDlg_Impl
, OnAddressTemplateClicked
));
282 aLeftTypLb
.SetSelectHdl(
283 LINK(this, SfxOrganizeDlg_Impl
, LeftListBoxSelect_Impl
));
284 aRightTypLb
.SetSelectHdl(
285 LINK(this, SfxOrganizeDlg_Impl
, RightListBoxSelect_Impl
));
286 aLeftLb
.SetGetFocusHdl(
287 LINK(this, SfxOrganizeDlg_Impl
, GetFocus_Impl
));
288 aRightLb
.SetGetFocusHdl(
289 LINK(this, SfxOrganizeDlg_Impl
, GetFocus_Impl
));
290 aLeftLb
.SetPosSizePixel(pParent
->LogicToPixel(Point(3, 6), MAP_APPFONT
),
291 pParent
->LogicToPixel(Size(94, 132), MAP_APPFONT
));
292 aRightLb
.SetPosSizePixel(pParent
->LogicToPixel(Point(103, 6), MAP_APPFONT
),
293 pParent
->LogicToPixel(Size(94, 132), MAP_APPFONT
));
295 if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE
) )
296 aAddressTemplateBtn
.Hide();
297 Font
aFont(aLeftLb
.GetFont());
298 aFont
.SetWeight(WEIGHT_NORMAL
);
299 aLeftLb
.SetFont(aFont
);
300 aRightLb
.SetFont(aFont
);
301 const long nIndent
= aLeftLb
.GetIndent() / 2;
302 aLeftLb
.SetIndent( (short)nIndent
);
303 aRightLb
.SetIndent( (short)nIndent
);
305 aLeftLb
.SetMgr(&aMgr
);
306 aRightLb
.SetMgr(&aMgr
);
308 aRightLb
.Reset();//SetModel(aLeftLb.GetModel());
313 aLeftLb
.SelectAll( FALSE
);
314 aRightLb
.SelectAll( FALSE
);
315 aRightLb
.GrabFocus();
318 //-------------------------------------------------------------------------
320 SfxOrganizeDlg_Impl::~SfxOrganizeDlg_Impl()
325 //-------------------------------------------------------------------------
327 void SfxOrganizeDlg_Impl::InitBitmaps( void )
329 Image
aOpenedFolderBmp( SfxResId( IMG_OPENED_FOLDER
) );
330 Image
aClosedFolderBmp( SfxResId( IMG_CLOSED_FOLDER
) );
331 Image
aOpenedDocBmp( SfxResId( IMG_OPENED_DOC
) );
332 Image
aClosedDocBmp( SfxResId( IMG_CLOSED_DOC
) );
334 Image
aOpenedFolderBmpHC( SfxResId( IMG_OPENED_FOLDER_HC
) );
335 Image
aClosedFolderBmpHC( SfxResId( IMG_CLOSED_FOLDER_HC
) );
336 Image
aOpenedDocBmpHC( SfxResId( IMG_OPENED_DOC_HC
) );
337 Image
aClosedDocBmpHC( SfxResId( IMG_CLOSED_DOC_HC
) );
339 aLeftLb
.SetBitmaps( aOpenedFolderBmp
, aClosedFolderBmp
, aOpenedDocBmp
, aClosedDocBmp
,
340 aOpenedFolderBmpHC
, aClosedFolderBmpHC
, aOpenedDocBmpHC
, aClosedDocBmpHC
);
341 aRightLb
.SetBitmaps( aOpenedFolderBmp
, aClosedFolderBmp
, aOpenedDocBmp
, aClosedDocBmp
,
342 aOpenedFolderBmpHC
, aClosedFolderBmpHC
, aOpenedDocBmpHC
, aClosedDocBmpHC
);
345 //=========================================================================
347 BOOL
QueryDelete_Impl(Window
*pParent
, // Parent der QueryBox
348 USHORT nId
, // Resource Id
349 const String
&rTemplateName
) // Name der zu l"oschenden Vorlage
356 SfxResId
aResId( nId
);
357 String
aEntryText( aResId
);
358 aEntryText
.SearchAndReplaceAscii( "$1", rTemplateName
);
359 QueryBox
aBox( pParent
, WB_YES_NO
| WB_DEF_NO
, aEntryText
);
360 return RET_NO
!= aBox
.Execute();
363 //-------------------------------------------------------------------------
365 void ErrorDelete_Impl(Window
*pParent
, const String
&rName
, sal_Bool bFolder
= sal_False
)
369 Benutzerinformation, da"s die Vorlage rName nicht gel"oscht werden konnte
375 String
aText( SfxResId( STR_ERROR_DELETE_TEMPLATE_DIR
) );
376 ErrorBox( pParent
, WB_OK
, aText
).Execute();
380 String
aText( SfxResId( STR_ERROR_DELETE_TEMPLATE
) );
381 aText
.SearchAndReplaceAscii( "$1", rName
);
382 ErrorBox( pParent
, WB_OK
, aText
).Execute();
387 //=========================================================================
391 Implementierungsklasse; Referenzklasse f"ur USHORT-Array
401 ImpPath_Impl( const ImpPath_Impl
& rCopy
);
404 //-------------------------------------------------------------------------
406 ImpPath_Impl::ImpPath_Impl() : aUS(5), nRef(1)
410 //-------------------------------------------------------------------------
412 ImpPath_Impl::ImpPath_Impl( const ImpPath_Impl
& rCopy
) :
414 aUS ( (BYTE
)rCopy
.aUS
.Count() ),
418 const USHORT nCount
= rCopy
.aUS
.Count();
420 for ( USHORT i
= 0; i
< nCount
; ++i
)
421 aUS
.Insert( rCopy
.aUS
[i
], i
);
424 //==========================================================================
428 Implementierungsklasse; Darstellung einer Position in der Outline-
429 Listbox als USHORT-Array; dieses beschreibt die Position jeweil
430 als relative Postion zum "ubergeordneten Eintrag
438 Path(SvLBox
*pBox
, SvLBoxEntry
*pEntry
);
439 Path(const Path
&rPath
):
444 const Path
&operator=(const Path
&rPath
)
460 USHORT
Count() const { return pData
->aUS
.Count(); }
461 USHORT
operator[]( USHORT i
) const
463 return i
< Count()? pData
->aUS
[i
]: INDEX_IGNORE
;
467 //-------------------------------------------------------------------------
469 Path::Path(SvLBox
*pBox
, SvLBoxEntry
*pEntry
) :
470 pData(new ImpPath_Impl
)
472 DBG_ASSERT(pEntry
!= 0, "EntryPtr ist NULL");
475 SvLBoxEntry
*pParent
= pBox
->GetParent(pEntry
);
477 pData
->aUS
.Insert((USHORT
)pBox
->GetModel()->GetRelPos(pEntry
), 0);
481 pParent
= pBox
->GetParent(pEntry
);
485 //-------------------------------------------------------------------------
492 pData
= new ImpPath_Impl(*pData
);
496 //-------------------------------------------------------------------------
498 SvLBoxEntry
*GetIndices_Impl(SvLBox
*pBox
,
504 Bereich und Position innerhalb eines Bereiches f"ur eine
505 Dokumentvorlage wird ermittelt.
509 SvLBox *pBox Listbox, an der das Ereignis auftrat
510 SvLBoxEntry *pEntry Eintrag, dessen Position ermittelt werden soll
511 USHORT &rRegion der Bereich innerhalb der Bereiche der
512 Dokumentvorlagen (Out-Parameter)
513 USHORT &rOffset die Position innerhalb des Bereiches
514 Dokumentvorlagen (Out-Parameter)
518 <class Path> (unter Umst"anden kann auf diese Funktion zugunsten
519 von Path verzichtet werden.)
526 rRegion
= rOffset
= 0;
529 if(0 == pBox
->GetModel()->GetDepth(pEntry
))
531 rRegion
= (USHORT
)pBox
->GetModel()->GetRelPos(pEntry
);
535 SvLBoxEntry
*pParent
= pBox
->GetParent(pEntry
);
536 rRegion
= (USHORT
)pBox
->GetModel()->GetRelPos(pParent
);
537 rOffset
= (USHORT
)pBox
->GetModel()->GetRelPos(pEntry
);
541 //-------------------------------------------------------------------------
543 BOOL
SfxOrganizeListBox_Impl::Select( SvLBoxEntry
* pEntry
, BOOL bSelect
)
546 return SvTreeListBox::Select(pEntry
,bSelect
);
547 USHORT nLevel
= GetDocLevel();
548 if(GetModel()->GetDepth(pEntry
)+nLevel
<3)
549 return SvTreeListBox::Select(pEntry
,bSelect
);
551 Path
aPath(this, pEntry
);
552 GetObjectShell(aPath
)->TriggerHelpPI(
553 aPath
[nLevel
+1], aPath
[nLevel
+2], aPath
[nLevel
+3]);
554 return SvTreeListBox::Select(pEntry
,bSelect
);
557 //-------------------------------------------------------------------------
559 BOOL
SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox
*pSourceBox
,
560 SvLBoxEntry
*pSource
,
561 SvLBoxEntry
* pTarget
,
562 SvLBoxEntry
*&pNewParent
,
567 Verschieben oder Kopieren von Dokumentvorlagen
571 SvLBox *pSourceBox Quell-Listbox, an der das Ereignis auftrat
572 SvLBoxEntry *pSource Quell-Eintrag, der kopiert / verschoben werden soll
573 SvLBoxEntry* pTarget Ziel-Eintrag, auf den verschoben werden soll
574 SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
575 Eintrags (Out-Parameter)
576 ULONG &rIdx Index des Zieleintrags
577 BOOL bCopy Flag f"ur Kopieren / Verschieben
580 [Returnwert] BOOL: Erfolg oder Mi"serfolg
584 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
585 SvLBoxEntry *pSource,
586 SvLBoxEntry* pTarget,
587 SvLBoxEntry *&pNewParent,
590 <BOOL SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
591 SvLBoxEntry* pSource,
592 SvLBoxEntry *&pNewParent,
594 <BOOL SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
595 SvLBoxEntry* pSource,
596 SvLBoxEntry *&pNewParent,
605 USHORT nTargetRegion
= 0, nTargetIndex
= 0;
606 GetIndices_Impl(this, pTarget
, nTargetRegion
, nTargetIndex
);
608 USHORT nSourceRegion
= 0, nSourceIndex
= 0;
609 GetIndices_Impl(pSourceBox
, pSource
, nSourceRegion
, nSourceIndex
);
612 pMgr
->Copy(nTargetRegion
, nTargetIndex
+1,
613 nSourceRegion
, nSourceIndex
):
614 pMgr
->Move(nTargetRegion
, nTargetIndex
+1,
615 nSourceRegion
, nSourceIndex
);
619 if(pSourceBox
->GetModel()->GetDepth(pSource
) == GetModel()->GetDepth(pTarget
))
621 pNewParent
= GetParent(pTarget
);
622 rIdx
= GetModel()->GetRelPos(pTarget
)+1;
626 if(nTargetIndex
== USHRT_MAX
)
628 pNewParent
= pTarget
;
632 SvLBox::NotifyCopying(
633 pTarget
, pSource
, pNewParent
, rIdx
);
638 // the template organizer always tries copy after the move, so no error is required for move case
639 String
aText( SfxResId( bCopy
? STR_ERROR_COPY_TEMPLATE
: STR_ERROR_MOVE_TEMPLATE
) );
640 aText
.SearchAndReplaceAscii( "$1",
641 ( (SvTreeListBox
*)pSourceBox
)->GetEntryText( pSource
) );
642 ErrorBox( this, WB_OK
, aText
).Execute();
648 //-------------------------------------------------------------------------
650 BOOL
SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox
*pSourceBox
,
651 SvLBoxEntry
*pSource
,
652 SvLBoxEntry
* pTarget
,
653 SvLBoxEntry
*&pNewParent
,
658 Verschieben oder Kopieren von Dokumentinhalten
662 SvLBox *pSourceBox Quell-Listbox, an der das Ereignis auftrat
663 SvLBoxEntry *pSource Quell-Eintrag, der kopiert / verschoben werden soll
664 SvLBoxEntry* pTarget Ziel-Eintrag, auf den verschoben werden soll
665 SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
666 Eintrags (Out-Parameter)
667 ULONG &rIdx Index des Zieleintrags
668 BOOL bCopy Flag f"ur Kopieren / Verschieben
671 [Returnwert] BOOL: Erfolg oder Mi"serfolg
675 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
676 SvLBoxEntry *pSource,
677 SvLBoxEntry* pTarget,
678 SvLBoxEntry *&pNewParent,
681 <BOOL SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
682 SvLBoxEntry* pSource,
683 SvLBoxEntry *&pNewParent,
685 <BOOL SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
686 SvLBoxEntry* pSource,
687 SvLBoxEntry *&pNewParent,
692 SfxErrorContext
aEc( ERRCTX_SFX_MOVEORCOPYCONTENTS
, this);
693 BOOL bOk
= FALSE
, bKeepExpansion
= FALSE
;
694 BOOL bRemovedFromSource
= FALSE
;
695 Path
aSource(pSourceBox
, pSource
);
696 Path
aTarget(this, pTarget
);
697 SfxObjectShellRef aSourceDoc
=
698 ((SfxOrganizeListBox_Impl
*)pSourceBox
)->GetObjectShell(aSource
);
700 SfxObjectShellRef aTargetDoc
= GetObjectShell(aTarget
);
701 const USHORT nSLevel
=
702 ((SfxOrganizeListBox_Impl
*)pSourceBox
)->GetDocLevel();
703 const USHORT nTLevel
= GetDocLevel();
705 if(aSourceDoc
.Is() && aTargetDoc
.Is())
707 if (aSourceDoc
->GetStyleSheetPool())
708 aSourceDoc
->GetStyleSheetPool()->SetSearchMask(
709 SFX_STYLE_FAMILY_ALL
, SFXSTYLEBIT_USERDEF
| SFXSTYLEBIT_USED
);
711 if (aTargetDoc
->GetStyleSheetPool())
712 aTargetDoc
->GetStyleSheetPool()->SetSearchMask(
713 SFX_STYLE_FAMILY_ALL
, SFXSTYLEBIT_USERDEF
| SFXSTYLEBIT_USED
);
715 USHORT nIdxDeleted
= INDEX_IGNORE
;
716 p
[0]=aTarget
[nTLevel
+1];
717 p
[1]=aTarget
[nTLevel
+2];
718 if(p
[1]!=INDEX_IGNORE
)p
[1]++;
719 p
[2]=aTarget
[nTLevel
+3];
721 bOk
= aTargetDoc
->Insert(
722 *aSourceDoc
, aSource
[nSLevel
+1],
723 aSource
[nSLevel
+2], aSource
[nSLevel
+3],
724 p
[0], p
[1], p
[2], nIdxDeleted
);
725 // Positionskorrektur auswerten
726 // a = Dokumentinhalt
727 // b = Position Sub-Inhalt 1
728 // c = Position Sub-Inhalt 2
729 // doppelte Eintraege loeschen
732 SvLBoxEntry
*pParentIter
= pTarget
;
733 // bis auf die DokumentEbene nach oben als
734 // allgemeiner Bezugspunkt
735 while(GetModel()->GetDepth(pParentIter
) != nTLevel
)
736 pParentIter
= GetParent(pParentIter
);
737 if(pParentIter
->HasChildsOnDemand() &&
738 !GetModel()->HasChilds(pParentIter
))
739 RequestingChilds(pParentIter
);
740 SvLBoxEntry
*pChildIter
= 0;
743 while(i
< 2 && p
[i
+1] != INDEX_IGNORE
)
745 pChildIter
= FirstChild(pParentIter
);
746 // bis zum Index der aktuellen Ebene
747 for(USHORT j
= 0; j
< p
[i
]; ++j
)
748 pChildIter
= NextSibling(pChildIter
);
749 // gfs Fuellen bei Items onDemand
751 if(p
[i
+1] != INDEX_IGNORE
&&
752 pChildIter
->HasChildsOnDemand() &&
753 !GetModel()->HasChilds(pChildIter
))
754 RequestingChilds(pChildIter
);
755 pParentIter
= pChildIter
;
758 pNewParent
= pParentIter
;
759 if(!IsExpanded(pNewParent
) &&
760 pNewParent
->HasChildsOnDemand() &&
761 !GetModel()->HasChilds(pNewParent
))
765 pSourceBox
->GetModel()->Remove(pSource
);
767 // Geloeschte Eintraege entfernen
768 // (kann durch Ueberschreiben geschehen)
769 if(nIdxDeleted
!= INDEX_IGNORE
)
771 pChildIter
= FirstChild(pParentIter
);
772 for(USHORT j
= 0; j
< nIdxDeleted
; ++j
)
773 pChildIter
= NextSibling(pChildIter
);
774 if( pChildIter
&& pChildIter
!= pSource
)
776 bKeepExpansion
= IsExpanded(pParentIter
);
777 GetModel()->Remove(pChildIter
);
782 if(!bCopy
&& &aSourceDoc
!= &aTargetDoc
)
784 //#109566# pool styles that are moved produce
785 //an rIdx == INDEX_IGNORE
786 //the method has to return true to keep the box content consistent
787 bRemovedFromSource
= aSourceDoc
->Remove(aSource
[nSLevel
+1],
794 return (((rIdx
!= INDEX_IGNORE
)|| bRemovedFromSource
) && bOk
)
795 ? bKeepExpansion
? (BOOL
)2: TRUE
: FALSE
;
798 //-------------------------------------------------------------------------
800 BOOL
SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry
*pTarget
,
801 SvLBoxEntry
* pSource
,
802 SvLBoxEntry
*&pNewParent
,
807 Benachrichtigung, da"s ein Eintrag verschoben werden soll
812 SvLBoxEntry* pTarget Ziel-Eintrag, auf den verschoben werden soll
813 SvLBoxEntry *pSource Quell-Eintrag, der verschoben werden soll
814 SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
815 Eintrags (Out-Parameter)
816 ULONG &rIdx Index des Zieleintrags
819 [Returnwert] BOOL: Erfolg oder Mi"serfolg
823 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
824 SvLBoxEntry *pSource,
825 SvLBoxEntry* pTarget,
826 SvLBoxEntry *&pNewParent,
829 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
830 SvLBoxEntry *pSource,
831 SvLBoxEntry* pTarget,
832 SvLBoxEntry *&pNewParent,
835 <BOOL SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
836 SvLBoxEntry* pSource,
837 SvLBoxEntry *&pNewParent,
843 SvLBox
* pSourceBox
= GetSourceView();
845 pSourceBox
= pDlg
->pSourceView
;
846 DBG_ASSERT( pSourceBox
, "no source view" );
848 pTarget
= pDlg
->pTargetEntry
;
850 if ( pSourceBox
->GetModel()->GetDepth( pSource
) <= GetDocLevel() &&
851 GetModel()->GetDepth( pTarget
) <= GetDocLevel() )
852 bOk
= MoveOrCopyTemplates( pSourceBox
, pSource
, pTarget
, pNewParent
, rIdx
, FALSE
);
854 bOk
= MoveOrCopyContents(pSourceBox
, pSource
, pTarget
, pNewParent
, rIdx
, FALSE
);
859 //-------------------------------------------------------------------------
861 BOOL
SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry
*pTarget
,
862 SvLBoxEntry
* pSource
,
863 SvLBoxEntry
*&pNewParent
,
867 Benachrichtigung, da"s ein Eintrag kopiert werden soll
872 SvLBoxEntry* pTarget Ziel-Eintrag, auf den kopiert werden soll
873 SvLBoxEntry *pSource Quell-Eintrag, der kopiert werden soll
874 SvLBoxEntry *&pNewParent der Parent der an der Zielposition erzeugten
875 Eintrags (Out-Parameter)
876 ULONG &rIdx Index des Zieleintrags
879 [Returnwert] BOOL: Erfolg oder Mi"serfolg
883 <SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
884 SvLBoxEntry *pSource,
885 SvLBoxEntry* pTarget,
886 SvLBoxEntry *&pNewParent,
889 <SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
890 SvLBoxEntry *pSource,
891 SvLBoxEntry* pTarget,
892 SvLBoxEntry *&pNewParent,
895 <BOOL SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
896 SvLBoxEntry* pSource,
897 SvLBoxEntry *&pNewParent,
902 SvLBox
* pSourceBox
= GetSourceView();
904 pSourceBox
= pDlg
->pSourceView
;
905 DBG_ASSERT( pSourceBox
, "no source view" );
907 pTarget
= pDlg
->pTargetEntry
;
908 if ( pSourceBox
->GetModel()->GetDepth( pSource
) <= GetDocLevel() &&
909 GetModel()->GetDepth( pTarget
) <= GetDocLevel() )
910 bOk
= MoveOrCopyTemplates( pSourceBox
, pSource
, pTarget
, pNewParent
, rIdx
, TRUE
);
912 bOk
= MoveOrCopyContents( pSourceBox
, pSource
, pTarget
, pNewParent
, rIdx
, TRUE
);
917 //-------------------------------------------------------------------------
919 BOOL
SfxOrganizeListBox_Impl::EditingEntry( SvLBoxEntry
* pEntry
, Selection
& )
923 Nachfrage, ob ein Eintrag editierbar ist
927 <SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry* pEntry, const String& rText)>
931 if( VIEW_TEMPLATES
== eViewType
&&
932 GetModel()->GetDepth(pEntry
) < 2 )
934 pDlg
->pSuspend
= new SuspendAccel( &pDlg
->aEditAcc
);
940 //-------------------------------------------------------------------------
942 BOOL
SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry
* pEntry
, const String
& rText
)
946 Der Name eines Eintrags wurde bearbeitet; ist der eingegebene Name
947 ein g"ultiger Name ("ange > 0), wird das Model aktualisiert.
952 BOOL TRUE: der Name soll in der Anzeige ge"andert werden
953 FALSE:der Name soll nicht ge"andert werden
956 <SfxOrganizeListBox_Impl::EditingEntry(SvLBoxEntry* pEntry, const String& rText)>
960 DBG_ASSERT(pEntry
, "kein Entry selektiert");
961 delete pDlg
->pSuspend
;
962 pDlg
->pSuspend
= NULL
;
963 SvLBoxEntry
* pParent
= GetParent(pEntry
);
966 ErrorBox
aBox( this, SfxResId( MSG_ERROR_EMPTY_NAME
) );
971 if ( !IsUniqName_Impl( rText
, pParent
, pEntry
) )
973 ErrorBox
aBox( this, SfxResId( MSG_ERROR_UNIQ_NAME
) );
978 USHORT nRegion
= 0, nIndex
= 0;
979 GetIndices_Impl( this, pEntry
, nRegion
, nIndex
);
981 if ( USHRT_MAX
!= nIndex
)
982 aOldName
= pMgr
->GetTemplates()->GetName( nRegion
, nIndex
);
984 aOldName
= pMgr
->GetTemplates()->GetRegionName( nRegion
);
986 if ( !pMgr
->SetName( rText
, nRegion
, nIndex
) )
988 SfxResId
aResId( USHRT_MAX
!= nIndex
? MSG_ERROR_RENAME_TEMPLATE
989 : MSG_ERROR_RENAME_TEMPLATE_REGION
);
990 ErrorBox( this, aResId
).Execute();
996 SfxTemplateOrganizeDlg* pDlg = (SfxTemplateOrganizeDlg*)Window::GetParent();
1002 //-------------------------------------------------------------------------
1004 DragDropMode
SfxOrganizeListBox_Impl::NotifyStartDrag( TransferDataContainer
&, SvLBoxEntry
* pEntry
)
1006 USHORT nSourceLevel
= GetModel()->GetDepth( pEntry
);
1007 if ( VIEW_FILES
== GetViewType() )
1009 if ( nSourceLevel
>= 2 )
1010 bDropMoveOk
= FALSE
;
1014 return GetDragDropMode();
1017 //-------------------------------------------------------------------------
1019 BOOL
SfxOrganizeListBox_Impl::NotifyAcceptDrop( SvLBoxEntry
* pEntry
)
1023 SvLBox
*pSource
= GetSourceView();
1024 SvLBoxEntry
*pSourceEntry
= pSource
->FirstSelected();
1025 if(pEntry
== pSourceEntry
)
1027 USHORT nSourceLevel
= pSource
->GetModel()->GetDepth(pSourceEntry
);
1028 if(VIEW_FILES
== ((SfxOrganizeListBox_Impl
*)pSource
)->GetViewType())
1030 USHORT nTargetLevel
= GetModel()->GetDepth(pEntry
);
1031 if(VIEW_FILES
== GetViewType())
1033 Path
aSource(pSource
, pSourceEntry
);
1034 Path
aTarget(this, pEntry
);
1035 const USHORT SL
= ((SfxOrganizeListBox_Impl
*)pSource
)->GetDocLevel();
1036 const USHORT TL
= GetDocLevel();
1038 return( (nSourceLevel
== 1 && nTargetLevel
== 0 &&
1040 ((SfxOrganizeListBox_Impl
*)pSource
)->GetViewType()) ||
1041 (nSourceLevel
== 1 && nTargetLevel
== 1 &&
1043 ((SfxOrganizeListBox_Impl
*)pSource
)->GetViewType() &&
1044 VIEW_TEMPLATES
== GetViewType()) ||
1045 (nSourceLevel
== 3 && nTargetLevel
== 1) ||
1046 (nSourceLevel
== 3 && nTargetLevel
== 2 &&
1047 aSource
[1+SL
] == aTarget
[1+TL
]) ||
1048 (nSourceLevel
== 3 && nTargetLevel
== 3 &&
1049 aSource
[1+SL
] == aTarget
[1+TL
]) ||
1050 (nSourceLevel
== 4 && nTargetLevel
== 3 &&
1051 aSource
[1+SL
] == aTarget
[1+TL
] &&
1052 aSource
[2+SL
] == aTarget
[2+TL
]) ||
1053 (nSourceLevel
== 4 && nTargetLevel
== 4 &&
1054 aSource
[1+SL
] == aTarget
[1+TL
] &&
1055 aSource
[2+SL
] == aTarget
[2+TL
]));
1058 //-------------------------------------------------------------------------
1060 sal_Int8
SfxOrganizeListBox_Impl::AcceptDrop( const AcceptDropEvent
& rEvt
)
1062 sal_Bool bAccept
= ( eViewType
== VIEW_FILES
&& IsDropFormatSupported( SOT_FORMAT_FILE
) );
1064 return rEvt
.mnAction
;
1066 return SvTreeListBox::AcceptDrop( rEvt
);
1069 //-------------------------------------------------------------------------
1071 sal_Int8
SfxOrganizeListBox_Impl::ExecuteDrop( const ExecuteDropEvent
& rEvt
)
1073 TransferableDataHelper
aHelper( rEvt
.maDropEvent
.Transferable
);
1074 sal_uInt32 nFormatCount
= aHelper
.GetFormatCount();
1075 BOOL bSuccess
= FALSE
;
1076 for ( sal_uInt32 i
= 0; i
< nFormatCount
; ++i
)
1079 SotFormatStringId nId
= aHelper
.GetFormat(i
);
1081 if ( SOT_FORMAT_FILE
== nId
&& aHelper
.GetString( nId
, aFileName
) )
1083 INetURLObject
aObj( aFileName
, INET_PROT_FILE
);
1084 bSuccess
|= pMgr
->InsertFile( this, aObj
.GetMainURL(INetURLObject::DECODE_TO_IURI
) );
1088 sal_Int8 nRet
= rEvt
.mnAction
;
1091 // asynchronous, because of MessBoxes
1092 pDlg
->pSourceView
= GetSourceView();
1093 pDlg
->pTargetEntry
= pTargetEntry
;
1094 pDlg
->pFinishedBox
= NULL
;
1095 pDlg
->nDropAction
= NO_DROP_ACTION
;
1096 PostUserEvent( LINK( this, SfxOrganizeListBox_Impl
, OnAsyncExecuteDrop
),
1097 new ExecuteDropEvent( rEvt
) );
1103 //-------------------------------------------------------------------------
1105 void SfxOrganizeListBox_Impl::DragFinished( sal_Int8 nDropAction
)
1107 if ( pDlg
->bExecDropFinished
)
1109 if ( pDlg
->nDropAction
!= NO_DROP_ACTION
)
1110 nDropAction
= pDlg
->nDropAction
;
1111 SvTreeListBox::DragFinished( nDropAction
);
1112 pDlg
->nDropAction
= NO_DROP_ACTION
;
1115 pDlg
->pFinishedBox
= this;
1118 //-------------------------------------------------------------------------
1120 inline USHORT
SfxOrganizeListBox_Impl::GetDocLevel() const
1124 Ermittelt, auf welche Ebene sich Dokumente befinden (unterschiedlich
1125 in der Dokumentvorlagensicht und der Dokumentensicht)
1129 USHORT Die Ebene der Dokumente
1134 return eViewType
== VIEW_FILES
? 0: 1;
1137 //-------------------------------------------------------------------------
1139 SfxObjectShellRef
SfxOrganizeListBox_Impl::GetObjectShell(const Path
&rPath
)
1143 Zugriff auf die ObjectShell, die dem aktuellen Eintrag zugeordnet
1148 const Path &rPath Beschreibung des aktuellen Eintrags
1152 SfxObjectShellRef Referenz auf die ObjectShell
1161 SfxObjectShellRef aDoc
;
1162 if(eViewType
== VIEW_FILES
)
1163 aDoc
= pMgr
->CreateObjectShell(rPath
[0]);
1165 aDoc
= pMgr
->CreateObjectShell(rPath
[0], rPath
[1]);
1169 //-------------------------------------------------------------------------
1171 void SfxOrganizeListBox_Impl::RequestingChilds( SvLBoxEntry
* pEntry
)
1175 Aufforderung, der Childs eines Eintrags einzuf"ugen
1181 SvLBoxEntry* pEntry der Eintrag, dessen Childs erfragt werden
1187 // wenn keine Childs vorhanden sind, gfs. Childs
1189 BmpColorMode eColorMode
= BMP_COLOR_NORMAL
;
1191 if ( GetDisplayBackground().GetColor().IsDark() )
1192 eColorMode
= BMP_COLOR_HIGHCONTRAST
;
1195 if ( !GetModel()->HasChilds( pEntry
) )
1197 WaitObject
aWaitCursor( this );
1199 // Choose the correct mask color dependent from eColorMode. This must be adopted if
1200 // we change the mask color for normal images, too!
1201 Color
aMaskColor( COL_LIGHTMAGENTA
);
1203 // hier sind alle initial eingefuegt
1204 SfxErrorContext
aEc(ERRCTX_SFX_CREATEOBJSH
, pDlg
->pDialog
);
1205 if(VIEW_TEMPLATES
== GetViewType() && 0 == GetModel()->GetDepth(pEntry
))
1207 USHORT i
= (USHORT
)GetModel()->GetRelPos(pEntry
);
1208 const USHORT nEntryCount
= pMgr
->GetTemplates()->GetCount(i
);
1209 for(USHORT j
= 0; j
< nEntryCount
; ++j
)
1210 InsertEntryByBmpType( pMgr
->GetTemplates()->GetName( i
, j
), BMPTYPE_DOC
, pEntry
, TRUE
);
1214 const USHORT nDocLevel
= GetDocLevel();
1215 Path
aPath(this, pEntry
);
1216 SfxObjectShellRef aRef
= GetObjectShell(aPath
);
1219 const USHORT nCount
= aRef
->GetContentCount(
1220 aPath
[nDocLevel
+1], aPath
[nDocLevel
+2]);
1222 Bitmap aClosedBmp
, aOpenedBmp
;
1223 const BOOL bCanHaveChilds
=
1224 aRef
->CanHaveChilds(aPath
[nDocLevel
+1],
1225 aPath
[nDocLevel
+2]);
1226 for(USHORT i
= 0; i
< nCount
; ++i
)
1230 aText
, aClosedBmp
, aOpenedBmp
, eColorMode
, bDeletable
,
1231 i
, aPath
[nDocLevel
+1], aPath
[nDocLevel
+2]);
1233 // Create image with the correct mask color
1234 Image
aClosedImage( aClosedBmp
, aMaskColor
);
1235 Image
aOpenedImage( aOpenedBmp
, aMaskColor
);
1237 SvLBoxEntry
*pNew
= SvTreeListBox::InsertEntry(
1238 aText
, aOpenedImage
, aClosedImage
,
1239 pEntry
, bCanHaveChilds
);
1240 pNew
->SetUserData(bDeletable
? &bDeletable
: 0);
1247 //-------------------------------------------------------------------------
1249 long SfxOrganizeListBox_Impl::ExpandingHdl()
1253 SV-Handler, der nach dem und vor dem Aufklappen eines Eintrags
1255 Wird verwendet, um gfs. die ObjectShell wieder zu schlie"sen;
1256 die Eintr"age mit den Inhalten dieser Shell werden ebenfalls
1262 if ( !(nImpFlags
& SVLBOX_IS_EXPANDING
) )
1264 SvLBoxEntry
* pEntry
= GetHdlEntry();
1265 const USHORT nLevel
= GetModel()->GetDepth(pEntry
);
1266 if((eViewType
== VIEW_FILES
&& nLevel
== 0) ||
1267 (eViewType
== VIEW_TEMPLATES
&& nLevel
== 1))
1269 Path
aPath(this, pEntry
);
1270 // Beim Schliessen des Files die ObjectShell freigeben
1271 if(eViewType
== VIEW_FILES
&& nLevel
== 0)
1272 pMgr
->DeleteObjectShell(aPath
[0]);
1274 pMgr
->DeleteObjectShell(aPath
[0], aPath
[1]);
1275 // alle SubEntries loeschen
1276 SvLBoxEntry
*pToDel
= SvLBox::GetEntry(pEntry
, 0);
1279 GetModel()->Remove(pToDel
);
1280 pToDel
= SvLBox::GetEntry(pEntry
, 0);
1287 //-------------------------------------------------------------------------
1289 BOOL
SfxOrganizeListBox_Impl::IsUniqName_Impl(const String
&rText
,
1290 SvLBoxEntry
* pParent
, SvLBoxEntry
*pEntry
) const
1294 Pr"uft, ob eine Name auf seiner Ebene eindeutig ist.
1298 const String & Name des zu suchenden Eintrags
1299 SvLBoxEntry* pSibling Geschwister (bezeichnet die Ebene)
1303 BOOL TRUE, wenn der Name eindeutig ist, sonst FALSE
1307 SvLBoxEntry
* pChild
= FirstChild(pParent
);
1309 const String
aEntryText(GetEntryText(pChild
));
1310 if(COMPARE_EQUAL
== aEntryText
.CompareIgnoreCaseToAscii(rText
)&&(!pEntry
|| pEntry
!=pChild
))
1312 pChild
= NextSibling(pChild
);
1317 //-------------------------------------------------------------------------
1319 USHORT
SfxOrganizeListBox_Impl::GetLevelCount_Impl(SvLBoxEntry
* pParent
) const
1321 SvLBoxEntry
* pChild
= FirstChild(pParent
);
1324 pChild
= NextSibling(pChild
);
1330 //-------------------------------------------------------------------------
1332 SvLBoxEntry
* SfxOrganizeListBox_Impl::InsertEntryByBmpType( const XubString
& rText
, BMPTYPE eBmpType
,
1333 SvLBoxEntry
* pParent
, BOOL bChildsOnDemand
, ULONG nPos
, void* pUserData
)
1335 SvLBoxEntry
* pEntry
= NULL
;
1336 const Image
* pExp
= NULL
;
1337 const Image
* pCol
= NULL
;
1338 const Image
* pExpHC
= NULL
;
1339 const Image
* pColHC
= NULL
;
1343 case BMPTYPE_FOLDER
:
1344 pExp
= &aOpenedFolderBmp
;
1345 pCol
= &aClosedFolderBmp
;
1346 pExpHC
= &aOpenedFolderBmpHC
;
1347 pColHC
= &aClosedFolderBmpHC
;
1350 DBG_ERROR( "SfxOrganizeListBox_Impl::InsertEntryByBmpType(): something forgotten?!" );
1353 pExp
= &aOpenedDocBmp
;
1354 pCol
= &aClosedDocBmp
;
1355 pExpHC
= &aOpenedDocBmpHC
;
1356 pColHC
= &aClosedDocBmpHC
;
1360 pEntry
= SvTreeListBox::InsertEntry( rText
, *pExp
, *pCol
, pParent
, bChildsOnDemand
, nPos
, pUserData
);
1362 SetExpandedEntryBmp( pEntry
, *pExpHC
, BMP_COLOR_HIGHCONTRAST
);
1363 SetCollapsedEntryBmp( pEntry
, *pColHC
, BMP_COLOR_HIGHCONTRAST
);
1368 //-------------------------------------------------------------------------
1370 SfxOrganizeListBox_Impl::SfxOrganizeListBox_Impl
1372 SfxOrganizeDlg_Impl
* pArgDlg
,
1378 SvTreeListBox( pParent
, nBits
),
1386 Konstruktor SfxOrganizeListBox
1392 SV_DRAGDROP_CTRL_MOVE
| SV_DRAGDROP_CTRL_COPY
|
1393 SV_DRAGDROP_APP_MOVE
| SV_DRAGDROP_APP_COPY
| SV_DRAGDROP_APP_DROP
);
1394 SetEntryHeight( 16 );
1395 SetSelectionMode( SINGLE_SELECTION
);
1396 GetModel()->SetSortMode( SortNone
);
1398 EnableContextMenuHandling();
1401 //-------------------------------------------------------------------------
1403 IMPL_LINK( SfxOrganizeListBox_Impl
, OnAsyncExecuteDrop
, ExecuteDropEvent
*, pEvent
)
1405 DBG_ASSERT( pEvent
, "invalid DropEvent" );
1408 SvLBox
* pSourceView
= GetSourceView();
1410 pSourceView
= pDlg
->pSourceView
;
1411 pDlg
->bExecDropFinished
= false;
1412 // if a template can not be moved it should be copied
1413 if ( pEvent
->mnAction
== DND_ACTION_MOVE
)
1414 pEvent
->mnAction
= DND_ACTION_COPYMOVE
;
1415 pDlg
->nDropAction
= SvTreeListBox::ExecuteDrop( *pEvent
, pSourceView
);
1417 pDlg
->pSourceView
= NULL
;
1418 pDlg
->pTargetEntry
= NULL
;
1419 pDlg
->bExecDropFinished
= true;
1420 if ( pDlg
->pFinishedBox
)
1422 pDlg
->pFinishedBox
->DragFinished( pDlg
->nDropAction
);
1423 pDlg
->pFinishedBox
= NULL
;
1429 //-------------------------------------------------------------------------
1431 void SfxOrganizeListBox_Impl::Reset()
1435 Einf"ugen der Elemente in die ListBox
1440 DBG_ASSERT( pMgr
!= 0, "kein Manager" );
1442 SetUpdateMode(FALSE
);
1444 if ( VIEW_TEMPLATES
== eViewType
)
1446 const USHORT nCount
= pMgr
->GetTemplates()->GetRegionCount();
1447 for ( USHORT i
= 0; i
< nCount
; ++i
)
1448 InsertEntryByBmpType( pMgr
->GetTemplates()->GetFullRegionName(i
), BMPTYPE_FOLDER
, 0, TRUE
);
1452 const SfxObjectList
& rList
= pMgr
->GetObjectList();
1453 const USHORT nCount
= rList
.Count();
1454 for ( USHORT i
= 0; i
< nCount
; ++i
)
1455 InsertEntryByBmpType( rList
.GetBaseName(i
), BMPTYPE_DOC
, 0, TRUE
);
1458 SetUpdateMode(TRUE
);
1463 //-------------------------------------------------------------------------
1465 const Image
&SfxOrganizeListBox_Impl::GetClosedBmp(USHORT nLevel
) const
1469 Zugriff auf die Bitmap f"ur einen geschlossenen Eintrag
1470 der jeweiligen Ebene
1474 USHORT nLevel Angabe der Ebene, 2 Ebenen sind erlaubt
1478 const Image & das Image auf der Ebenen nLevel
1483 BOOL bHC
= GetBackground().GetColor().IsDark();
1484 const Image
* pRet
= NULL
;
1488 default: DBG_ERROR( "Bitmaps ueberindiziert" );
1490 case 0: pRet
= bHC
? &aClosedFolderBmpHC
: &aClosedFolderBmp
; break;
1491 case 1: pRet
= bHC
? &aClosedDocBmpHC
: &aClosedDocBmp
; break;
1497 //-------------------------------------------------------------------------
1499 const Image
&SfxOrganizeListBox_Impl::GetOpenedBmp(USHORT nLevel
) const
1503 Zugriff auf die Bitmap f"ur einen ge"offneten Eintrag
1504 der jeweiligen Ebene
1508 USHORT nLevel Angabe der Ebene, 2 Ebenen sind erlaubt
1512 const Image & das Image auf der Ebenen nLevel
1517 BOOL bHC
= GetBackground().GetColor().IsDark();
1518 const Image
* pRet
= NULL
;
1523 pRet
= bHC
? &aOpenedFolderBmpHC
: &aOpenedFolderBmp
; break;
1525 pRet
= bHC
? &aOpenedDocBmpHC
: &aOpenedDocBmp
; break;
1527 pRet
= bHC
? &aClosedFolderBmpHC
: &aClosedFolderBmp
; break;
1533 //-------------------------------------------------------------------------
1535 PopupMenu
* SfxOrganizeListBox_Impl::CreateContextMenu()
1537 return new PopupMenu( *( pDlg
->aEditBtn
.GetPopupMenu() ) );
1540 //-------------------------------------------------------------------------
1542 String
SfxOrganizeDlg_Impl::GetPath_Impl( BOOL bOpen
, const String
& rFileName
)
1546 Pfad per FileDialog erfragen, f"ur Import / Export von
1551 BOOL bOpen Flag: "Offnen / Speichern
1552 const String& rFileName aktueller Dateiname als Vorschlag
1554 [R"uckgabewert] Dateiname mit Pfad oder Leerstring, wenn
1555 der Benutzer 'Abbrechen' gedr"uckt hat
1560 m_sExtension4Save
= DEFINE_CONST_UNICODE( "vor" );
1561 sal_Int16 nDialogType
= bOpen
1562 ? com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
1563 : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
;
1566 pFileDlg
= new sfx2::FileDialogHelper( nDialogType
, 0L );
1569 pFileDlg
->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL
) ),
1570 DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL
) );
1571 // add template filter
1572 String
sFilterName( SfxResId( STR_TEMPLATE_FILTER
) );
1574 // add filters of modules which are installed
1575 SvtModuleOptions aModuleOpt
;
1576 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SWRITER
) )
1577 sFilterExt
+= DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
1578 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SCALC
) )
1580 if ( sFilterExt
.Len() > 0 )
1582 sFilterExt
+= DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1584 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS
) )
1586 if ( sFilterExt
.Len() > 0 )
1588 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1590 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SDRAW
) )
1592 if ( sFilterExt
.Len() > 0 )
1594 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otg;*.std" );
1596 if ( sFilterExt
.Len() > 0 )
1598 sFilterExt
+= DEFINE_CONST_UNICODE( "*.vor" );
1600 sFilterName
+= DEFINE_CONST_UNICODE( " (" );
1601 sFilterName
+= sFilterExt
;
1603 pFileDlg
->AddFilter( sFilterName
, sFilterExt
);
1604 pFileDlg
->SetCurrentFilter( sFilterName
);
1606 if ( aLastDir
.Len() || rFileName
.Len() )
1609 if ( aLastDir
.Len() )
1611 aObj
.SetURL( aLastDir
);
1612 if ( rFileName
.Len() )
1613 aObj
.insertName( rFileName
);
1616 aObj
.SetURL( rFileName
);
1618 if ( aObj
.hasExtension() )
1620 m_sExtension4Save
= aObj
.getExtension(
1621 INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
1622 aObj
.removeExtension();
1625 DBG_ASSERT( aObj
.GetProtocol() != INET_PROT_NOT_VALID
, "Invalid URL!" );
1626 pFileDlg
->SetDisplayDirectory( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1629 pFileDlg
->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl
, ImportHdl
) );
1634 //-------------------------------------------------------------------------
1636 ::com::sun::star::uno::Sequence
< ::rtl::OUString
>
1637 SfxOrganizeDlg_Impl::GetPaths_Impl( const String
& rFileName
)
1641 Query plural paths by FileDialog, for Import / Export from document
1646 const String& rFileName The default file name when dialog executes
1648 [Return value] Empty sequence when users have clicked
1649 'Cancel', a sequence just containing one
1650 file name with path when they have
1651 choosed one file or a sequence containing
1652 path and file names without path
1656 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aPaths
;
1657 m_sExtension4Save
= DEFINE_CONST_UNICODE( "vor" );
1660 pFileDlg
= new sfx2::FileDialogHelper(
1661 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, SFXWB_MULTISELECTION
);
1664 pFileDlg
->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL
) ),
1665 DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL
) );
1667 // add template filter
1668 String
sFilterName( SfxResId( STR_TEMPLATE_FILTER
) );
1670 // add filters of modules which are installed
1671 SvtModuleOptions aModuleOpt
;
1672 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SWRITER
) )
1673 sFilterExt
+= DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
1674 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SCALC
) )
1676 if ( sFilterExt
.Len() > 0 )
1678 sFilterExt
+= DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1680 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS
) )
1682 if ( sFilterExt
.Len() > 0 )
1684 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1686 if ( aModuleOpt
.IsModuleInstalled( SvtModuleOptions::E_SDRAW
) )
1688 if ( sFilterExt
.Len() > 0 )
1690 sFilterExt
+= DEFINE_CONST_UNICODE( "*.otg;*.std" );
1692 if ( sFilterExt
.Len() > 0 )
1694 sFilterExt
+= DEFINE_CONST_UNICODE( "*.vor" );
1696 sFilterName
+= DEFINE_CONST_UNICODE( " (" );
1697 sFilterName
+= sFilterExt
;
1699 pFileDlg
->AddFilter( sFilterName
, sFilterExt
);
1700 pFileDlg
->SetCurrentFilter( sFilterName
);
1702 if ( aLastDir
.Len() || rFileName
.Len() )
1705 if ( aLastDir
.Len() )
1707 aObj
.SetURL( aLastDir
);
1708 if ( rFileName
.Len() )
1709 aObj
.insertName( rFileName
);
1712 aObj
.SetURL( rFileName
);
1714 if ( aObj
.hasExtension() )
1716 m_sExtension4Save
= aObj
.getExtension(
1717 INetURLObject::LAST_SEGMENT
, true, INetURLObject::DECODE_WITH_CHARSET
);
1718 aObj
.removeExtension();
1721 DBG_ASSERT( aObj
.GetProtocol() != INET_PROT_NOT_VALID
, "Invalid URL!" );
1722 pFileDlg
->SetDisplayDirectory( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1725 pFileDlg
->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl
, ExportHdl
) );
1730 //-------------------------------------------------------------------------
1732 BOOL
SfxOrganizeDlg_Impl::DontDelete_Impl( SvLBoxEntry
* pEntry
)
1734 USHORT nDepth
= pFocusBox
->GetModel()->GetDepth(pEntry
);
1735 if(SfxOrganizeListBox_Impl::VIEW_FILES
==
1736 pFocusBox
->GetViewType())
1738 if( (nDepth
> 2 && !pEntry
->GetUserData()) ||
1739 //Delete ueber GetContent verboten
1740 nDepth
==2 || //Vorlage / Konfigurtionsrubrik nicht loeshcen
1741 (nDepth
==1 && SfxOrganizeListBox_Impl::VIEW_FILES
==
1742 pFocusBox
->GetViewType()) || //Files nicht loeschen
1743 (0 == nDepth
&& pFocusBox
->GetLevelCount_Impl(0) < 2))
1744 //Mindestens eine Vorlage behalten
1749 USHORT nRegion
= 0, nIndex
= 0;
1750 GetIndices_Impl( pFocusBox
, pEntry
, nRegion
, nIndex
);
1751 const SfxDocumentTemplates
* pTemplates
= aMgr
.GetTemplates();
1752 if ( !pTemplates
|| !pTemplates
->HasUserContents( nRegion
, nIndex
) )
1758 SvStringsDtor
* SfxOrganizeDlg_Impl::GetAllFactoryURLs_Impl( ) const
1760 SvtModuleOptions aModOpt
;
1761 const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& aServiceNames
= aModOpt
.GetAllServiceNames() ;
1762 SvStringsDtor
* pList
= new SvStringsDtor
;
1763 sal_Int32 nCount
= aServiceNames
.getLength();
1764 for( sal_Int32 i
=0; i
<nCount
; ++i
)
1766 if ( SfxObjectFactory::GetStandardTemplate( aServiceNames
[i
] ).Len() > 0 )
1768 SvtModuleOptions::EFactory eFac
= SvtModuleOptions::E_WRITER
;
1769 SvtModuleOptions::ClassifyFactoryByName( aServiceNames
[i
], eFac
);
1770 String
* pURL
= new String( aModOpt
.GetFactoryEmptyDocumentURL( eFac
) );
1771 pList
->Insert( pURL
, pList
->Count() );
1778 sal_Bool
SfxOrganizeDlg_Impl::GetServiceName_Impl( String
& rName
, String
& rFileURL
) const
1780 sal_Bool bRet
= sal_False
;
1781 const SfxDocumentTemplates
* pTemplates
= aMgr
.GetTemplates();
1782 SvLBoxEntry
* pEntry
= pFocusBox
? pFocusBox
->FirstSelected() : NULL
;
1783 USHORT nRegion
= 0, nIndex
= 0;
1784 GetIndices_Impl( pFocusBox
, pEntry
, nRegion
, nIndex
);
1785 rFileURL
= pTemplates
->GetPath( nRegion
, nIndex
);
1786 if ( rFileURL
.Len() > 0 )
1790 uno::Reference
< embed::XStorage
> xStorage
= ::comphelper::OStorageHelper::GetStorageFromURL(
1792 embed::ElementModes::READ
);
1793 ULONG nFormat
= SotStorage::GetFormatID( xStorage
);
1794 const SfxFilter
* pFilter
=
1795 SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat
);
1798 rName
= pFilter
->GetServiceName();
1802 catch( uno::Exception
& )
1809 long SfxOrganizeDlg_Impl::Dispatch_Impl( USHORT nId
, Menu
* _pMenu
)
1813 Verarbeiten der Events aus MenuButton oder Accelerator
1817 USHORT nId ID des Events
1819 [R"uckgabewert] 1: Event wurde verarbeitet,
1820 0: Event wurde nicht verarbeitet (SV-Menu)
1825 SuspendAccel
aTmp(&aEditAcc
);
1826 SvLBoxEntry
*pEntry
= pFocusBox
? pFocusBox
->FirstSelected(): 0;
1827 sal_Bool bHandled
= sal_True
;
1834 if(pFocusBox
->GetViewType() == SfxOrganizeListBox_Impl::VIEW_TEMPLATES
)
1836 if(0 == pFocusBox
->GetModel()->GetDepth(pEntry
))
1838 const String
aNoName( SfxResId(STR_NONAME
) );
1839 SvLBoxEntry
* pParent
= pFocusBox
->GetParent(pEntry
);
1840 String
aName(aNoName
);
1842 while(!pFocusBox
->IsUniqName_Impl(aName
, pParent
))
1845 aName
+= String::CreateFromInt32( n
++ );
1847 aMgr
.InsertDir( pFocusBox
, aName
,
1848 (USHORT
)pFocusBox
->GetModel()->GetRelPos(pEntry
)+1);
1856 if(!pEntry
|| DontDelete_Impl(pEntry
))
1858 const USHORT nDepth
= pFocusBox
->GetModel()->GetDepth(pEntry
);
1861 if(0 == nDepth
&& pFocusBox
->GetLevelCount_Impl(0) < 2) return 1;
1862 if(SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== pFocusBox
->GetViewType())
1864 USHORT nResId
= nDepth
? STR_DELETE_TEMPLATE
:
1866 if( !QueryDelete_Impl(
1867 pDialog
, nResId
, pFocusBox
->GetEntryText(pEntry
)))
1869 if ( STR_DELETE_REGION
== nResId
&&
1870 pFocusBox
->GetChildCount(pEntry
))
1872 QueryBox
aQBox(pDialog
, SfxResId(MSG_REGION_NOTEMPTY
));
1873 if(RET_NO
== aQBox
.Execute())
1876 USHORT nRegion
= 0, nIndex
= 0;
1877 GetIndices_Impl(pFocusBox
, pEntry
, nRegion
, nIndex
);
1879 USHORT nDeleteInd
= ( STR_DELETE_REGION
== nResId
? USHRT_MAX
: nIndex
);
1880 if ( !aMgr
.Delete( pFocusBox
, nRegion
, nDeleteInd
) )
1883 pFocusBox
->GetEntryText(pEntry
),
1884 ( nDeleteInd
== USHRT_MAX
&& pFocusBox
->GetChildCount(pEntry
) ) );
1888 else if(nDepth
+ pFocusBox
->GetDocLevel() >= 2)
1890 if(!QueryDelete_Impl(pDialog
, STR_DELETE_TEMPLATE
, pFocusBox
->GetEntryText(pEntry
)))
1892 Path
aPath(pFocusBox
, pEntry
);
1893 SfxObjectShellRef aRef
= pFocusBox
->GetObjectShell(aPath
);
1895 aRef
->Remove(aPath
[1+pFocusBox
->GetDocLevel()],
1896 aPath
[2+pFocusBox
->GetDocLevel()],
1897 aPath
[3+pFocusBox
->GetDocLevel()]))
1898 pFocusBox
->GetModel()->Remove(pEntry
);
1900 ErrorDelete_Impl(pDialog
, pFocusBox
->GetEntryText(pEntry
), sal_False
);
1909 USHORT nRegion
= 0, nIndex
= 0;
1910 GetIndices_Impl( pFocusBox
, pEntry
, nRegion
, nIndex
);
1911 const SfxStringItem
aName( SID_FILE_NAME
, aMgr
.GetTemplates()->GetPath( nRegion
, nIndex
) );
1912 const SfxStringItem
aLongName( SID_FILE_LONGNAME
, pFocusBox
->GetEntryText( pEntry
) );
1913 const SfxStringItem
aReferer( SID_REFERER
, DEFINE_CONST_UNICODE( "private:user" ) );
1914 const SfxStringItem
aTargetName( SID_TARGETNAME
, DEFINE_CONST_UNICODE( "_default" ) );
1915 const SfxBoolItem
aTemplateIndicator( SID_TEMPLATE
, sal_False
);
1917 SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
,
1918 &aName
, &aLongName
, &aReferer
, &aTargetName
, &aTemplateIndicator
, 0L );
1919 pDialog
->EndDialog( RET_EDIT_STYLE
);
1929 GetIndices_Impl( pFocusBox
, pEntry
, m_nRegion
, m_nIndex
);
1930 GetPaths_Impl( String() );
1940 GetIndices_Impl( pFocusBox
, pEntry
, m_nRegion
, m_nIndex
);
1941 GetPath_Impl( FALSE
, aMgr
.GetTemplates()->GetFileName( m_nRegion
, m_nIndex
) );
1946 if ( !aMgr
.Rescan() )
1947 ErrorBox( pDialog
, SfxResId( MSG_ERROR_RESCAN
) ).Execute();
1948 if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== aLeftLb
.GetViewType() )
1950 if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== aRightLb
.GetViewType() )
1958 Path
aPath( pFocusBox
, pEntry
);
1959 SfxObjectShellRef aRef
= pFocusBox
->GetObjectShell( aPath
);
1962 const USHORT nDocLevel
= pFocusBox
->GetDocLevel();
1965 SvLBoxEntry
*pDocEntry
= pEntry
;
1966 while ( pFocusBox
->GetModel()->GetDepth( pDocEntry
) > nDocLevel
)
1967 pDocEntry
= pFocusBox
->GetParent( pDocEntry
);
1968 const String
aName(pFocusBox
->GetEntryText(pDocEntry
));
1969 if ( !aRef
->Print( *pPrt
, aPath
[1+nDocLevel
],
1970 aPath
[2+nDocLevel
], aPath
[3+nDocLevel
], &aName
) )
1971 ErrorBox( pDialog
, SfxResId( MSG_PRINT_ERROR
) ).Execute();
1976 case ID_PRINTER_SETUP
:
1978 PrinterSetupDialog
* pDlg
= new PrinterSetupDialog( pDialog
);
1981 pDlg
->SetPrinter( pPrt
);
1987 case ID_DEFAULT_TEMPLATE
:
1989 String aServiceName
, aFileURL
;
1990 if ( GetServiceName_Impl( aServiceName
, aFileURL
) )
1991 SfxObjectFactory::SetStandardTemplate( aServiceName
, aFileURL
);
1996 bHandled
= sal_False
;
1999 if ( !bHandled
&& ( nId
> ID_RESET_DEFAULT_TEMPLATE
|| nId
<= ID_RESET_DEFAULT_TEMPLATE_END
) )
2001 Menu
* pSubMenu
= _pMenu
? _pMenu
: aEditBtn
.GetPopupMenu()->GetPopupMenu( ID_RESET_DEFAULT_TEMPLATE
);
2004 String aServiceName
= SfxObjectShell::GetServiceNameFromFactory( pSubMenu
->GetItemCommand( nId
) );
2005 SfxObjectFactory::SetStandardTemplate( aServiceName
, String() );
2006 bHandled
= sal_True
;
2010 return bHandled
? 1 : 0;
2013 //-------------------------------------------------------------------------
2015 IMPL_LINK_INLINE_START( SfxOrganizeDlg_Impl
, MenuSelect_Impl
, Menu
*, pMenu
)
2019 SelectHandler des Men"us des Men"ubuttons (SV)
2023 MenuButton *pBtn der das Event ausl"osende Button
2025 [R"uckgabewert] 1: Event wurde verarbeitet,
2026 0: Event wurde nicht verarbeitet (SV-Menu)
2030 return Dispatch_Impl( pMenu
->GetCurItemId(), pMenu
);
2032 IMPL_LINK_INLINE_END( SfxOrganizeDlg_Impl
, MenuSelect_Impl
, Menu
*, pMenu
)
2034 //-------------------------------------------------------------------------
2036 IMPL_LINK( SfxOrganizeDlg_Impl
, AccelSelect_Impl
, Accelerator
*, pAccel
)
2040 SelectHandler des Accelerators (SV)
2044 Accelerator *pAccel der das Event ausl"osende Accelerator
2046 [R"uckgabewert] 1: Event wurde verarbeitet,
2047 0: Event wurde nicht verarbeitet (SV)
2052 SvLBoxEntry
* pEntry
= pFocusBox
&& pFocusBox
->GetSelectionCount() ?
2053 pFocusBox
->FirstSelected() : NULL
;
2054 return pEntry
&& ( pAccel
->GetCurItemId() == ID_NEW
|| !DontDelete_Impl( pEntry
) ) ?
2055 Dispatch_Impl( pAccel
->GetCurItemId(), NULL
) : 0;
2058 //-------------------------------------------------------------------------
2060 void SfxOrganizeDlg_Impl::OkHdl(Button
*pButton
)
2062 if(pFocusBox
&& pFocusBox
->IsEditingActive())
2063 pFocusBox
->EndEditing(FALSE
);
2069 IMPL_LINK( SfxOrganizeDlg_Impl
, MenuActivate_Impl
, Menu
*, pMenu
)
2073 ActivateHandler des Men"us des Men"ubuttons (SV)
2077 Menu *pMenu das das Event ausl"osende Men"u
2079 [R"uckgabewert] 1: Event wurde verarbeitet,
2080 0: Event wurde nicht verarbeitet (SV-Menu)
2084 if ( pFocusBox
&& pFocusBox
->IsEditingActive() )
2085 pFocusBox
->EndEditing( FALSE
);
2086 BOOL bEnable
= ( pFocusBox
&& pFocusBox
->GetSelectionCount() );
2087 SvLBoxEntry
* pEntry
= bEnable
? pFocusBox
->FirstSelected() : NULL
;
2088 const USHORT nDepth
=
2089 ( bEnable
&& pFocusBox
->GetSelectionCount() ) ? pFocusBox
->GetModel()->GetDepth( pEntry
) : 0;
2090 const USHORT nDocLevel
= bEnable
? pFocusBox
->GetDocLevel() : 0;
2091 int eVT
= pFocusBox
? pFocusBox
->GetViewType() : 0;
2092 // nur Vorlagen anlegen
2093 pMenu
->EnableItem( ID_NEW
, bEnable
&& 0 == nDepth
&& SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== eVT
);
2094 // Vorlagen: Loeschen Ebene 0,1,3ff
2095 // ein Bereich mu"s mindestens erhalten bleiben
2096 // Dateien : Loeschen Ebene > 2
2098 pMenu
->EnableItem( ID_DELETE
, bEnable
&& !DontDelete_Impl( pEntry
) );
2099 pMenu
->EnableItem( ID_EDIT
,
2100 bEnable
&& eVT
== SfxOrganizeListBox_Impl::VIEW_TEMPLATES
&& nDepth
== nDocLevel
2101 && !DontDelete_Impl( pEntry
) );
2102 pMenu
->EnableItem( ID_COPY_FROM
,
2103 bEnable
&& eVT
== SfxOrganizeListBox_Impl::VIEW_TEMPLATES
&&
2104 ( nDepth
== nDocLevel
|| nDepth
== nDocLevel
- 1 ) );
2105 pMenu
->EnableItem( ID_COPY_TO
,
2106 bEnable
&& eVT
== SfxOrganizeListBox_Impl::VIEW_TEMPLATES
&&
2107 nDepth
== nDocLevel
);
2108 pMenu
->EnableItem( ID_RESCAN
,
2109 SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== aRightLb
.GetViewType() ||
2110 SfxOrganizeListBox_Impl::VIEW_TEMPLATES
== aLeftLb
.GetViewType() );
2111 BOOL bPrint
= bEnable
&& nDepth
> pFocusBox
->GetDocLevel();
2112 if ( bPrint
&& pPrt
)
2113 bPrint
= !pPrt
->IsPrinting() && !pPrt
->IsJobActive();
2114 if ( bPrint
&& bEnable
)
2116 // only styles printable
2117 Path
aPath( pFocusBox
, pFocusBox
->FirstSelected() );
2118 USHORT nIndex
= aPath
[ nDocLevel
+ 1 ];
2119 bPrint
= ( nIndex
== CONTENT_STYLE
);
2121 pMenu
->EnableItem( ID_PRINT
, bPrint
);
2123 if ( bEnable
&& eVT
== SfxOrganizeListBox_Impl::VIEW_TEMPLATES
&& nDepth
== nDocLevel
)
2125 String aFactoryURL
, aFileURL
;
2126 bEnable
= GetServiceName_Impl( aFactoryURL
, aFileURL
);
2130 pMenu
->EnableItem( ID_DEFAULT_TEMPLATE
, bEnable
);
2133 SvStringsDtor
* pList
= GetAllFactoryURLs_Impl();
2134 USHORT nCount
= pList
->Count();
2137 PopupMenu
* pSubMenu
= new PopupMenu
;
2138 USHORT nItemId
= ID_RESET_DEFAULT_TEMPLATE
+ 1;
2139 for ( USHORT i
= 0; i
< nCount
; ++i
)
2141 String
aObjFacURL( *pList
->GetObject(i
) );
2142 String aTitle
= SvFileInformationManager::GetDescription(
2143 INetURLObject(aObjFacURL
) );
2144 pSubMenu
->InsertItem( nItemId
, aTitle
,
2145 SvFileInformationManager::GetImage(INetURLObject(aObjFacURL
)) );
2146 pSubMenu
->SetItemCommand( nItemId
++, aObjFacURL
);
2147 DBG_ASSERT( nItemId
<= ID_RESET_DEFAULT_TEMPLATE_END
, "menu item id overflow" );
2149 pMenu
->SetPopupMenu( ID_RESET_DEFAULT_TEMPLATE
, pSubMenu
);
2152 bEnable
= sal_False
;
2155 pMenu
->EnableItem( ID_RESET_DEFAULT_TEMPLATE
, bEnable
);
2160 //-------------------------------------------------------------------------
2162 IMPL_LINK( SfxOrganizeDlg_Impl
, GetFocus_Impl
, SfxOrganizeListBox_Impl
*, pBox
)
2166 GetFocus-Handler, wird aus den Select-Handler der Listboxen
2168 Wird verwendet, im die Listbox, die den Focus besitzt sowie
2169 deren Zustand zu ermitteln.
2173 SfxOrganizeListBox *pBox die rufende Box
2178 if(pFocusBox
&& pFocusBox
!= pBox
)
2179 pFocusBox
->SelectAll(FALSE
);
2181 aFilesBtn
.Enable( SfxOrganizeListBox_Impl::VIEW_FILES
==
2182 pFocusBox
->GetViewType() );
2186 //-------------------------------------------------------------------------
2188 IMPL_LINK( SfxOrganizeDlg_Impl
, LeftListBoxSelect_Impl
, ListBox
*, pBox
)
2192 Select-Handler, wird aus den Select-Handler der Listboxen
2194 Wenn sich der Modus der Boxen (Dokumentsicht, Dokumentvorlagensicht)
2195 unterscheiden, werden die Models getrennt; andernfalls zusammengefa"st.
2199 ListBox *pBox die rufende Box
2203 const SfxOrganizeListBox_Impl::DataEnum
2204 eViewType
= pBox
->GetSelectEntryPos() == 0 ?
2205 SfxOrganizeListBox_Impl::VIEW_TEMPLATES
: SfxOrganizeListBox_Impl::VIEW_FILES
;
2206 if(eViewType
!= aLeftLb
.GetViewType()) {
2207 aLeftLb
.SetViewType(eViewType
);
2208 if(aRightLb
.GetViewType() == eViewType
)
2209 aLeftLb
.SetModel(aRightLb
.GetModel());
2212 aLeftLb
.DisconnectFromModel();
2216 GetFocus_Impl(&aLeftLb
);
2220 //-------------------------------------------------------------------------
2222 IMPL_LINK( SfxOrganizeDlg_Impl
, RightListBoxSelect_Impl
, ListBox
*, pBox
)
2226 Select-Handler, wird aus den Select-Handler der Listboxen
2228 Wenn sich der Modus der Boxen (Dokumentsicht, Dokumentvorlagensicht)
2229 unterscheiden, werden die Models getrennt; andernfalls zusammengefa"st.
2233 ListBox *pBox die rufende Box
2237 const SfxOrganizeListBox_Impl::DataEnum eViewType
=
2238 pBox
->GetSelectEntryPos() == 0 ?
2239 SfxOrganizeListBox_Impl::VIEW_TEMPLATES
: SfxOrganizeListBox_Impl::VIEW_FILES
;
2240 if(eViewType
!= aRightLb
.GetViewType())
2242 aRightLb
.SetViewType(eViewType
);
2243 if(aLeftLb
.GetViewType() == eViewType
)
2244 aRightLb
.SetModel(aLeftLb
.GetModel());
2248 aRightLb
.DisconnectFromModel();
2252 aRightLb
.GrabFocus();
2253 GetFocus_Impl(&aRightLb
);
2257 //-------------------------------------------------------------------------
2259 IMPL_LINK( SfxOrganizeDlg_Impl
, OnAddressTemplateClicked
, Button
*, pButton
)
2261 (void)pButton
; //unused
2262 svt::AddressBookSourceDialog
aDialog(pDialog
, ::comphelper::getProcessServiceFactory());
2267 //-------------------------------------------------------------------------
2269 IMPL_LINK( SfxOrganizeDlg_Impl
, AddFiles_Impl
, Button
*, pButton
)
2273 Handler des Buttons f"ur das Hinzuf"ugen von Dateien per Dialog.
2277 Button * der Button, der dieses Events ausgel"ost hat.
2281 (void)pButton
; //unused
2284 pFileDlg
= new sfx2::FileDialogHelper( WB_OPEN
, String() );
2286 // add config and basic filter
2287 static String
sOpenBracket( DEFINE_CONST_UNICODE( " (" ) );
2288 static String
sCloseBracket( DEFINE_CONST_UNICODE( ")" ) );
2289 static String
sConfigExt( DEFINE_CONST_UNICODE( "*.cfg" ) );
2290 static String
sBasicExt( DEFINE_CONST_UNICODE( "*.sbl" ) );
2292 String
sFilterName( SfxResId( RID_STR_FILTCONFIG
) );
2293 sFilterName
+= sOpenBracket
;
2294 sFilterName
+= sConfigExt
;
2295 sFilterName
+= sCloseBracket
;
2296 pFileDlg
->AddFilter( sFilterName
, sConfigExt
);
2298 sFilterName
= String( SfxResId( RID_STR_FILTBASIC
) );
2299 sFilterName
+= sOpenBracket
;
2300 sFilterName
+= sBasicExt
;
2301 sFilterName
+= sCloseBracket
;
2302 pFileDlg
->AddFilter( sFilterName
, sBasicExt
);
2304 // set "All" filter as current
2305 pFileDlg
->SetCurrentFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL
) ) );
2307 if ( aLastDir
.Len() )
2308 pFileDlg
->SetDisplayDirectory( aLastDir
);
2310 pFileDlg
->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl
, AddFilesHdl
) );
2315 //-------------------------------------------------------------------------
2317 IMPL_LINK( SfxOrganizeDlg_Impl
, ImportHdl
, sfx2::FileDialogHelper
*, EMPTYARG
)
2319 DBG_ASSERT( pFileDlg
, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
2321 if ( ERRCODE_NONE
== pFileDlg
->GetError() )
2323 String aPath
= pFileDlg
->GetPath();
2324 INetURLObject
aObj( aPath
);
2326 // we want to keep the original extension when exporting, the file open dialog
2327 // always sets the extension to *.vor
2328 if ( pFileDlg
->GetDialogType() ==
2329 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
)
2331 if ( aObj
.hasExtension() )
2332 aObj
.removeExtension();
2334 aObj
.setExtension( m_sExtension4Save
);
2335 aPath
= aObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
2338 aObj
.removeSegment();
2339 aLastDir
= aObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
2341 if ( aPath
.Len() && !aMgr
.CopyTo( m_nRegion
, m_nIndex
, aPath
) )
2343 String
aText( SfxResId( STR_ERROR_COPY_TEMPLATE
) );
2344 aText
.SearchAndReplaceAscii( "$1", aPath
);
2345 ErrorBox( pDialog
, WB_OK
, aText
).Execute();
2352 //-------------------------------------------------------------------------
2354 IMPL_LINK( SfxOrganizeDlg_Impl
, ExportHdl
, sfx2::FileDialogHelper
*, EMPTYARG
)
2356 DBG_ASSERT( pFileDlg
, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
2357 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aPaths
;
2359 if ( ERRCODE_NONE
== pFileDlg
->GetError() )
2361 aPaths
= pFileDlg
->GetMPath();
2362 sal_Int32 lastCount
= aPaths
.getLength() - 1;
2363 INetURLObject
aObj( aPaths
.getArray()[ lastCount
] );
2365 aObj
.removeSegment();
2366 aLastDir
= aObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
2369 sal_Int32 nCount
= aPaths
.getLength();
2372 String aPath
= String( aPaths
.getArray()[0] );
2373 if ( aPath
.Len() && !aMgr
.CopyFrom( pFocusBox
, m_nRegion
, m_nIndex
, aPath
) )
2375 String
aText( SfxResId( STR_ERROR_COPY_TEMPLATE
) );
2376 aText
.SearchAndReplaceAscii( "$1", aPath
);
2377 ErrorBox( pDialog
, WB_OK
, aText
).Execute();
2380 else if ( nCount
> 1 )
2382 INetURLObject
aPathObj( aPaths
[0] );
2383 aPathObj
.setFinalSlash();
2384 for ( USHORT i
= 1; i
< nCount
; ++i
)
2387 aPathObj
.Append( aPaths
[i
] );
2389 aPathObj
.setName( aPaths
[i
] );
2390 String aPath
= aPathObj
.GetMainURL( INetURLObject::NO_DECODE
);
2391 if ( aPath
.Len() && !aMgr
.CopyFrom( pFocusBox
, m_nRegion
, m_nIndex
, aPath
) )
2393 String
aText( SfxResId( STR_ERROR_COPY_TEMPLATE
) );
2394 aText
.SearchAndReplaceAscii( "$1", aPath
);
2395 ErrorBox( pDialog
, WB_OK
, aText
).Execute();
2403 //-------------------------------------------------------------------------
2405 IMPL_LINK( SfxOrganizeDlg_Impl
, AddFilesHdl
, sfx2::FileDialogHelper
*, EMPTYARG
)
2407 if ( ERRCODE_NONE
== pFileDlg
->GetError() )
2409 String aPath
= pFileDlg
->GetPath();
2410 aMgr
.InsertFile( pFocusBox
, aPath
);
2411 INetURLObject
aObj( aPath
);
2412 aObj
.removeSegment();
2413 aObj
.setFinalSlash();
2414 aLastDir
= aObj
.GetMainURL( INetURLObject::DECODE_TO_IURI
);
2420 //-------------------------------------------------------------------------
2422 short SfxTemplateOrganizeDlg::Execute()
2426 "Uberladene Execute- Methode; speichert gfs. "Anderungen an den
2433 const short nRet
= ModalDialog::Execute();
2434 if(RET_CANCEL
!= nRet
)
2436 pImp
->aMgr
.SaveAll(this);
2437 SfxTemplateDialog
* pTemplDlg
= SFX_APP()->GetTemplateDialog();
2439 pTemplDlg
->Update();
2445 //-------------------------------------------------------------------------
2447 SfxTemplateOrganizeDlg::SfxTemplateOrganizeDlg(Window
* pParent
,
2448 SfxDocumentTemplates
*pTempl
)
2449 : ModalDialog( pParent
, SfxResId(DLG_ORGANIZE
)),
2450 pImp( new SfxOrganizeDlg_Impl(this, pTempl
) )
2461 //-------------------------------------------------------------------------
2463 SfxTemplateOrganizeDlg::~SfxTemplateOrganizeDlg()
2465 GetpApp()->RemoveAccel(&pImp
->aEditAcc
);