xref: /AOO41X/main/sfx2/source/doc/docvor.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
33*cdf0e10cSrcweir #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <stdio.h>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #ifndef _SV_PRNSETUP_HXX //autogen
38*cdf0e10cSrcweir #include <svtools/prnsetup.hxx>
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #include <vcl/cmdevt.hxx>
41*cdf0e10cSrcweir #include <vcl/menubtn.hxx>
42*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
43*cdf0e10cSrcweir #include <vcl/print.hxx>
44*cdf0e10cSrcweir #include <svl/style.hxx>
45*cdf0e10cSrcweir #include <svl/stritem.hxx>
46*cdf0e10cSrcweir #include <svl/eitem.hxx>
47*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
48*cdf0e10cSrcweir #include <svtools/ehdl.hxx>
49*cdf0e10cSrcweir #include <svtools/imagemgr.hxx>
50*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
51*cdf0e10cSrcweir #include <tools/urlobj.hxx>
52*cdf0e10cSrcweir #include <tools/color.hxx>
53*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
54*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
55*cdf0e10cSrcweir #include <sot/exchange.hxx>
56*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #include "helpid.hrc"
59*cdf0e10cSrcweir #include "docvor.hxx"
60*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
61*cdf0e10cSrcweir #include "orgmgr.hxx"
62*cdf0e10cSrcweir #include <sfx2/doctempl.hxx>
63*cdf0e10cSrcweir #include <sfx2/templdlg.hxx>
64*cdf0e10cSrcweir #include "sfxtypes.hxx"
65*cdf0e10cSrcweir #include <sfx2/app.hxx>
66*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
67*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
68*cdf0e10cSrcweir #include "doc.hrc"
69*cdf0e10cSrcweir #include <sfx2/sfx.hrc>
70*cdf0e10cSrcweir #include "docvor.hrc"
71*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
72*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
73*cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
74*cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
75*cdf0e10cSrcweir #include <svtools/localresaccess.hxx>
76*cdf0e10cSrcweir #ifndef _SVT_DOC_ADDRESSTEMPLATE_HXX_
77*cdf0e10cSrcweir #include <svtools/addresstemplate.hxx>
78*cdf0e10cSrcweir #endif
79*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
80*cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
81*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir static const char cDelim = ':';
84*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::bDropMoveOk = sal_True;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir using namespace ::com::sun::star;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir //=========================================================================
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir class SuspendAccel
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir public:
93*cdf0e10cSrcweir 	Accelerator*	pAccel;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 	SuspendAccel( Accelerator* pA )
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 		pAccel=pA;
98*cdf0e10cSrcweir 		GetpApp()->RemoveAccel( pAccel );
99*cdf0e10cSrcweir 	}
100*cdf0e10cSrcweir 	~SuspendAccel()
101*cdf0e10cSrcweir 	{
102*cdf0e10cSrcweir 		GetpApp()->InsertAccel( pAccel );
103*cdf0e10cSrcweir 	}
104*cdf0e10cSrcweir };
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir //=========================================================================
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir inline void SfxOrganizeListBox_Impl::SetBitmaps(
110*cdf0e10cSrcweir 	const Image &rOFolder, const Image &rCFolder, const Image &rODoc, const Image &rCDoc,
111*cdf0e10cSrcweir 	const Image &rOFolderHC, const Image &rCFolderHC, const Image &rODocHC, const Image &rCDocHC )
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	aOpenedFolderBmp = rOFolder;
114*cdf0e10cSrcweir 	aClosedFolderBmp = rCFolder;
115*cdf0e10cSrcweir 	aOpenedDocBmp = rODoc;
116*cdf0e10cSrcweir 	aClosedDocBmp = rCDoc;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	aOpenedFolderBmpHC = rOFolderHC;
119*cdf0e10cSrcweir 	aClosedFolderBmpHC = rCFolderHC;
120*cdf0e10cSrcweir 	aOpenedDocBmpHC = rODocHC;
121*cdf0e10cSrcweir 	aClosedDocBmpHC = rCDocHC;
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir //=========================================================================
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir #define NO_DROP_ACTION  ((sal_Int8)-1)
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir class SfxOrganizeDlg_Impl
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir friend class SfxTemplateOrganizeDlg;
132*cdf0e10cSrcweir friend class SfxOrganizeListBox_Impl;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	SuspendAccel*			pSuspend;
135*cdf0e10cSrcweir 	SfxTemplateOrganizeDlg* pDialog;
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	SfxOrganizeListBox_Impl* pFocusBox;
138*cdf0e10cSrcweir 	Printer*				 pPrt;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	// save pointer for asynchronous D&D
141*cdf0e10cSrcweir 	SvLBox*					pSourceView;
142*cdf0e10cSrcweir 	SvLBoxEntry*			pTargetEntry;
143*cdf0e10cSrcweir     SfxOrganizeListBox_Impl* pFinishedBox;
144*cdf0e10cSrcweir     sal_Int8                nDropAction;
145*cdf0e10cSrcweir     bool                    bExecDropFinished;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     // save some variables for the asynchronous file dialog
148*cdf0e10cSrcweir     sal_uInt16                  m_nRegion;
149*cdf0e10cSrcweir     sal_uInt16                  m_nIndex;
150*cdf0e10cSrcweir     String                  m_sExtension4Save;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	SfxOrganizeListBox_Impl aLeftLb;
153*cdf0e10cSrcweir 	ListBox                 aLeftTypLb;
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	SfxOrganizeListBox_Impl aRightLb;
156*cdf0e10cSrcweir 	ListBox                 aRightTypLb;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	OKButton                aOkBtn;
159*cdf0e10cSrcweir 	MenuButton              aEditBtn;
160*cdf0e10cSrcweir 	HelpButton              aHelpBtn;
161*cdf0e10cSrcweir 	PushButton              aAddressTemplateBtn;
162*cdf0e10cSrcweir 	PushButton              aFilesBtn;
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	Accelerator             aEditAcc;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	String                  aLastDir;
167*cdf0e10cSrcweir 	SfxOrganizeMgr          aMgr;
168*cdf0e10cSrcweir     sfx2::FileDialogHelper* pFileDlg;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	SvStringsDtor* 			GetAllFactoryURLs_Impl() const;
171*cdf0e10cSrcweir 	sal_Bool				GetServiceName_Impl( String& rFactoryURL, String& rFileURL ) const;
172*cdf0e10cSrcweir 	long                    Dispatch_Impl( sal_uInt16 nId, Menu* _pMenu );
173*cdf0e10cSrcweir 	String                  GetPath_Impl( sal_Bool bOpen, const String& rFileName );
174*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString >
175*cdf0e10cSrcweir                             GetPaths_Impl( const String& rFileName );
176*cdf0e10cSrcweir 	void					InitBitmaps( void );
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	DECL_LINK( GetFocus_Impl, SfxOrganizeListBox_Impl * );
179*cdf0e10cSrcweir 	DECL_LINK( LeftListBoxSelect_Impl, ListBox * );
180*cdf0e10cSrcweir 	DECL_LINK( RightListBoxSelect_Impl, ListBox * );
181*cdf0e10cSrcweir 	DECL_LINK( AccelSelect_Impl, Accelerator * );
182*cdf0e10cSrcweir 	DECL_LINK( MenuSelect_Impl, Menu * );
183*cdf0e10cSrcweir 	DECL_LINK( MenuActivate_Impl, Menu * );
184*cdf0e10cSrcweir 	DECL_LINK( AddFiles_Impl, Button * );
185*cdf0e10cSrcweir 	DECL_LINK( OnAddressTemplateClicked, Button * );
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     DECL_LINK( ImportHdl, sfx2::FileDialogHelper* );
188*cdf0e10cSrcweir     DECL_LINK( ExportHdl, sfx2::FileDialogHelper* );
189*cdf0e10cSrcweir     DECL_LINK( AddFilesHdl, sfx2::FileDialogHelper* );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     sal_Bool        DontDelete_Impl( SvLBoxEntry* pEntry );
192*cdf0e10cSrcweir     void        OkHdl( Button* );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir public:
195*cdf0e10cSrcweir     SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent, SfxDocumentTemplates* pTempl );
196*cdf0e10cSrcweir     ~SfxOrganizeDlg_Impl();
197*cdf0e10cSrcweir };
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir //-------------------------------------------------------------------------
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent,
202*cdf0e10cSrcweir 										  SfxDocumentTemplates* pTempl ) :
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     pSuspend            ( NULL ),
205*cdf0e10cSrcweir     pDialog             ( pParent ),
206*cdf0e10cSrcweir     pFocusBox           ( NULL ),
207*cdf0e10cSrcweir     pPrt                ( NULL ),
208*cdf0e10cSrcweir     pSourceView         ( NULL ),
209*cdf0e10cSrcweir     pTargetEntry        ( NULL ),
210*cdf0e10cSrcweir     pFinishedBox        ( NULL ),
211*cdf0e10cSrcweir     nDropAction         ( NO_DROP_ACTION ),
212*cdf0e10cSrcweir     bExecDropFinished   ( true ),
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	aLeftLb		( this, pParent, WB_BORDER | WB_TABSTOP | WB_HSCROLL, SfxOrganizeListBox_Impl::VIEW_TEMPLATES ),
215*cdf0e10cSrcweir 	aLeftTypLb	(  pParent, SfxResId( LB_LEFT_TYP ) ),
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	aRightLb	( this, pParent, WB_BORDER | WB_TABSTOP | WB_HSCROLL, SfxOrganizeListBox_Impl::VIEW_FILES ),
218*cdf0e10cSrcweir 	aRightTypLb	( pParent, SfxResId( LB_RIGHT_TYP ) ),
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	aOkBtn				( pParent, SfxResId( BTN_OK ) ),
221*cdf0e10cSrcweir 	aEditBtn			( pParent, SfxResId( BTN_EDIT ) ),
222*cdf0e10cSrcweir 	aHelpBtn			( pParent, SfxResId( BTN_HELP ) ),
223*cdf0e10cSrcweir 	aAddressTemplateBtn	( pParent, SfxResId( BTN_ADDRESSTEMPLATE ) ),
224*cdf0e10cSrcweir 	aFilesBtn			( pParent, SfxResId( BTN_FILES ) ),
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	aEditAcc	( SfxResId( ACC_EDIT ) ),
227*cdf0e10cSrcweir     aMgr        ( &aLeftLb, &aRightLb, pTempl ),
228*cdf0e10cSrcweir     pFileDlg    ( NULL )
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir 	// update the SfxDocumentTemplates the manager works with
232*cdf0e10cSrcweir 	if ( aMgr.GetTemplates() )	// should never fail, but who knows ....
233*cdf0e10cSrcweir 	{
234*cdf0e10cSrcweir 		// for this, show a wait cursor (it may take a while)
235*cdf0e10cSrcweir 		Window* pWaitObjectRange = pDialog ? pDialog->GetParent() : NULL;
236*cdf0e10cSrcweir 		if ( !pWaitObjectRange )
237*cdf0e10cSrcweir 			pWaitObjectRange = pDialog;
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 		WaitObject aWaitCursor( pWaitObjectRange );
240*cdf0e10cSrcweir 		const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->Update( sal_True /* be smart */ );
241*cdf0e10cSrcweir 			// this const_cast is a hack - but the alternative would be to
242*cdf0e10cSrcweir 			// * have a method which returns the templates non-const
243*cdf0e10cSrcweir 			// * use a new SfxDocumentTemplates instance for the update (knowing that they all share the same
244*cdf0e10cSrcweir 			//	 implementation class)
245*cdf0e10cSrcweir 			// * always work with an own instance, even if we get only NULL in this ctor
246*cdf0e10cSrcweir 	}
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 	aLeftLb.SetHelpId( HID_CTL_ORGANIZER_LEFT );
249*cdf0e10cSrcweir 	aRightLb.SetHelpId( HID_CTL_ORGANIZER_RIGHT );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	String aWorkPath = SvtPathOptions().GetWorkPath();
252*cdf0e10cSrcweir 	if ( aWorkPath.Len() )
253*cdf0e10cSrcweir 	{
254*cdf0e10cSrcweir         INetURLObject aObj( aWorkPath );
255*cdf0e10cSrcweir         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
256*cdf0e10cSrcweir 		aObj.setFinalSlash();
257*cdf0e10cSrcweir 		aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
258*cdf0e10cSrcweir 	}
259*cdf0e10cSrcweir 	else
260*cdf0e10cSrcweir 	{
261*cdf0e10cSrcweir 		// fallback
262*cdf0e10cSrcweir         String aProgURL = SvtPathOptions().SubstituteVariable( String::CreateFromAscii("$(PROGURL)") );
263*cdf0e10cSrcweir         INetURLObject aObj( aProgURL );
264*cdf0e10cSrcweir         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Illegal URL !" );
265*cdf0e10cSrcweir 		aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
266*cdf0e10cSrcweir 	}
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	InitBitmaps();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 	aEditBtn.GetPopupMenu()->SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, MenuSelect_Impl ) );
271*cdf0e10cSrcweir 	aEditBtn.GetPopupMenu()->SetActivateHdl( LINK( this, SfxOrganizeDlg_Impl, MenuActivate_Impl ) );
272*cdf0e10cSrcweir 	aEditAcc.SetSelectHdl( LINK( this, SfxOrganizeDlg_Impl, AccelSelect_Impl ) );
273*cdf0e10cSrcweir 	GetpApp()->InsertAccel( &aEditAcc );
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 	aFilesBtn.SetClickHdl(
276*cdf0e10cSrcweir 		LINK(this,SfxOrganizeDlg_Impl, AddFiles_Impl));
277*cdf0e10cSrcweir 	aAddressTemplateBtn.SetClickHdl(
278*cdf0e10cSrcweir 		LINK(this,SfxOrganizeDlg_Impl, OnAddressTemplateClicked));
279*cdf0e10cSrcweir 	aLeftTypLb.SetSelectHdl(
280*cdf0e10cSrcweir 		LINK(this, SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl));
281*cdf0e10cSrcweir 	aRightTypLb.SetSelectHdl(
282*cdf0e10cSrcweir 		LINK(this, SfxOrganizeDlg_Impl, RightListBoxSelect_Impl));
283*cdf0e10cSrcweir 	aLeftLb.SetGetFocusHdl(
284*cdf0e10cSrcweir 		LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
285*cdf0e10cSrcweir 	aRightLb.SetGetFocusHdl(
286*cdf0e10cSrcweir 		LINK(this, SfxOrganizeDlg_Impl, GetFocus_Impl));
287*cdf0e10cSrcweir 	aLeftLb.SetPosSizePixel(pParent->LogicToPixel(Point(3, 6), MAP_APPFONT),
288*cdf0e10cSrcweir 							pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
289*cdf0e10cSrcweir 	aRightLb.SetPosSizePixel(pParent->LogicToPixel(Point(103, 6), MAP_APPFONT),
290*cdf0e10cSrcweir 							 pParent->LogicToPixel(Size(94, 132), MAP_APPFONT));
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     if ( !SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE) )
293*cdf0e10cSrcweir         aAddressTemplateBtn.Hide();
294*cdf0e10cSrcweir 	Font aFont(aLeftLb.GetFont());
295*cdf0e10cSrcweir 	aFont.SetWeight(WEIGHT_NORMAL);
296*cdf0e10cSrcweir 	aLeftLb.SetFont(aFont);
297*cdf0e10cSrcweir 	aRightLb.SetFont(aFont);
298*cdf0e10cSrcweir 	const long nIndent = aLeftLb.GetIndent() / 2;
299*cdf0e10cSrcweir 	aLeftLb.SetIndent( (short)nIndent );
300*cdf0e10cSrcweir 	aRightLb.SetIndent( (short)nIndent );
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 	aLeftLb.SetMgr(&aMgr);
303*cdf0e10cSrcweir 	aRightLb.SetMgr(&aMgr);
304*cdf0e10cSrcweir 	aLeftLb.Reset();
305*cdf0e10cSrcweir 	aRightLb.Reset();//SetModel(aLeftLb.GetModel());
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	aLeftLb.Show();
308*cdf0e10cSrcweir 	aRightLb.Show();
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 	aLeftLb.SelectAll( sal_False );
311*cdf0e10cSrcweir 	aRightLb.SelectAll( sal_False );
312*cdf0e10cSrcweir 	aRightLb.GrabFocus();
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir //-------------------------------------------------------------------------
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir SfxOrganizeDlg_Impl::~SfxOrganizeDlg_Impl()
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir     delete pFileDlg;
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir //-------------------------------------------------------------------------
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir void SfxOrganizeDlg_Impl::InitBitmaps( void )
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir 	Image	aOpenedFolderBmp( SfxResId( IMG_OPENED_FOLDER ) );
327*cdf0e10cSrcweir 	Image	aClosedFolderBmp( SfxResId( IMG_CLOSED_FOLDER ) );
328*cdf0e10cSrcweir 	Image	aOpenedDocBmp( SfxResId( IMG_OPENED_DOC ) );
329*cdf0e10cSrcweir 	Image	aClosedDocBmp( SfxResId( IMG_CLOSED_DOC ) );
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	Image	aOpenedFolderBmpHC( SfxResId( IMG_OPENED_FOLDER_HC ) );
332*cdf0e10cSrcweir 	Image	aClosedFolderBmpHC( SfxResId( IMG_CLOSED_FOLDER_HC ) );
333*cdf0e10cSrcweir 	Image	aOpenedDocBmpHC( SfxResId( IMG_OPENED_DOC_HC ) );
334*cdf0e10cSrcweir 	Image	aClosedDocBmpHC( SfxResId( IMG_CLOSED_DOC_HC ) );
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	aLeftLb.SetBitmaps( aOpenedFolderBmp, aClosedFolderBmp, aOpenedDocBmp, aClosedDocBmp,
337*cdf0e10cSrcweir 						aOpenedFolderBmpHC, aClosedFolderBmpHC, aOpenedDocBmpHC, aClosedDocBmpHC );
338*cdf0e10cSrcweir 	aRightLb.SetBitmaps( aOpenedFolderBmp, aClosedFolderBmp, aOpenedDocBmp, aClosedDocBmp,
339*cdf0e10cSrcweir 						aOpenedFolderBmpHC, aClosedFolderBmpHC, aOpenedDocBmpHC, aClosedDocBmpHC );
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir //=========================================================================
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir sal_Bool QueryDelete_Impl(Window *pParent,      // Parent der QueryBox
345*cdf0e10cSrcweir 							 sal_uInt16 nId,            // Resource Id
346*cdf0e10cSrcweir 							 const String &rTemplateName)   // Name der zu l"oschenden Vorlage
347*cdf0e10cSrcweir /*  [Beschreibung]
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir 	"oschabfrage
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir */
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir 	SfxResId aResId( nId );
354*cdf0e10cSrcweir 	String aEntryText( aResId );
355*cdf0e10cSrcweir 	aEntryText.SearchAndReplaceAscii( "$1", rTemplateName );
356*cdf0e10cSrcweir 	QueryBox aBox( pParent, WB_YES_NO | WB_DEF_NO, aEntryText );
357*cdf0e10cSrcweir 	return RET_NO != aBox.Execute();
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir //-------------------------------------------------------------------------
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir void ErrorDelete_Impl(Window *pParent, const String &rName, sal_Bool bFolder = sal_False )
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir /*  [Beschreibung]
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir 	Benutzerinformation, da"s die Vorlage rName nicht gel"oscht werden konnte
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir */
369*cdf0e10cSrcweir {
370*cdf0e10cSrcweir 	if ( bFolder )
371*cdf0e10cSrcweir 	{
372*cdf0e10cSrcweir 		String aText( SfxResId( STR_ERROR_DELETE_TEMPLATE_DIR ) );
373*cdf0e10cSrcweir 		ErrorBox( pParent, WB_OK, aText ).Execute();
374*cdf0e10cSrcweir 	}
375*cdf0e10cSrcweir 	else
376*cdf0e10cSrcweir 	{
377*cdf0e10cSrcweir 		String aText( SfxResId( STR_ERROR_DELETE_TEMPLATE ) );
378*cdf0e10cSrcweir 		aText.SearchAndReplaceAscii( "$1", rName );
379*cdf0e10cSrcweir 		ErrorBox( pParent, WB_OK, aText ).Execute();
380*cdf0e10cSrcweir 	}
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir //=========================================================================
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir /*  [Beschreibung]
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 	Implementierungsklasse; Referenzklasse f"ur USHORT-Array
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir */
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir struct ImpPath_Impl
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir 	SvUShorts	aUS;
395*cdf0e10cSrcweir 	sal_uInt16		nRef;
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 	ImpPath_Impl();
398*cdf0e10cSrcweir 	ImpPath_Impl( const ImpPath_Impl& rCopy );
399*cdf0e10cSrcweir };
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir //-------------------------------------------------------------------------
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir ImpPath_Impl::ImpPath_Impl() : aUS(5), nRef(1)
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir //-------------------------------------------------------------------------
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir ImpPath_Impl::ImpPath_Impl( const ImpPath_Impl& rCopy ) :
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir 	aUS	( (sal_uInt8)rCopy.aUS.Count() ),
412*cdf0e10cSrcweir 	nRef( 1 )
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir 	const sal_uInt16 nCount = rCopy.aUS.Count();
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nCount; ++i )
418*cdf0e10cSrcweir 		aUS.Insert( rCopy.aUS[i], i );
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir //==========================================================================
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir /*  [Beschreibung]
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 	Implementierungsklasse; Darstellung einer Position in der Outline-
426*cdf0e10cSrcweir 	Listbox als sal_uInt16-Array; dieses beschreibt die Position jeweil
427*cdf0e10cSrcweir 	als relative Postion zum "ubergeordneten Eintrag
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir */
430*cdf0e10cSrcweir class Path
431*cdf0e10cSrcweir {
432*cdf0e10cSrcweir 	ImpPath_Impl *pData;
433*cdf0e10cSrcweir 	void NewImp();
434*cdf0e10cSrcweir public:
435*cdf0e10cSrcweir 	Path(SvLBox *pBox, SvLBoxEntry *pEntry);
436*cdf0e10cSrcweir 	Path(const Path &rPath):
437*cdf0e10cSrcweir 		pData(rPath.pData)
438*cdf0e10cSrcweir 	{
439*cdf0e10cSrcweir 		++pData->nRef;
440*cdf0e10cSrcweir 	}
441*cdf0e10cSrcweir 	const Path &operator=(const Path &rPath)
442*cdf0e10cSrcweir 	{
443*cdf0e10cSrcweir 		if(&rPath != this)
444*cdf0e10cSrcweir 		{
445*cdf0e10cSrcweir 			if(!--pData->nRef)
446*cdf0e10cSrcweir 				delete pData;
447*cdf0e10cSrcweir 			pData = rPath.pData;
448*cdf0e10cSrcweir 			pData->nRef++;
449*cdf0e10cSrcweir 		}
450*cdf0e10cSrcweir 		return *this;
451*cdf0e10cSrcweir 	}
452*cdf0e10cSrcweir 	~Path()
453*cdf0e10cSrcweir 	{
454*cdf0e10cSrcweir 		if(!--pData->nRef)
455*cdf0e10cSrcweir 			delete pData;
456*cdf0e10cSrcweir 	}
457*cdf0e10cSrcweir 	sal_uInt16 Count() const { return pData->aUS.Count(); }
458*cdf0e10cSrcweir 	sal_uInt16 operator[]( sal_uInt16 i ) const
459*cdf0e10cSrcweir 	{
460*cdf0e10cSrcweir 		return i < Count()? pData->aUS[i]: INDEX_IGNORE;
461*cdf0e10cSrcweir 	}
462*cdf0e10cSrcweir };
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir //-------------------------------------------------------------------------
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir Path::Path(SvLBox *pBox, SvLBoxEntry *pEntry) :
467*cdf0e10cSrcweir 	pData(new ImpPath_Impl)
468*cdf0e10cSrcweir {
469*cdf0e10cSrcweir 	DBG_ASSERT(pEntry != 0, "EntryPtr ist NULL");
470*cdf0e10cSrcweir 	if(!pEntry)
471*cdf0e10cSrcweir 		return;
472*cdf0e10cSrcweir 	SvLBoxEntry *pParent = pBox->GetParent(pEntry);
473*cdf0e10cSrcweir 	do {
474*cdf0e10cSrcweir 		pData->aUS.Insert((sal_uInt16)pBox->GetModel()->GetRelPos(pEntry), 0);
475*cdf0e10cSrcweir 		if(0 == pParent)
476*cdf0e10cSrcweir 			break;
477*cdf0e10cSrcweir 		pEntry = pParent;
478*cdf0e10cSrcweir 		pParent = pBox->GetParent(pEntry);
479*cdf0e10cSrcweir 	} while(1);
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir //-------------------------------------------------------------------------
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir void Path::NewImp()
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir 	if(pData->nRef != 1)
487*cdf0e10cSrcweir 	{
488*cdf0e10cSrcweir 		pData->nRef--;
489*cdf0e10cSrcweir 		pData = new ImpPath_Impl(*pData);
490*cdf0e10cSrcweir 	}
491*cdf0e10cSrcweir }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir //-------------------------------------------------------------------------
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir SvLBoxEntry *GetIndices_Impl(SvLBox *pBox,
496*cdf0e10cSrcweir 							   SvLBoxEntry *pEntry,
497*cdf0e10cSrcweir 							   sal_uInt16 &rRegion,
498*cdf0e10cSrcweir 							   sal_uInt16 &rOffset)
499*cdf0e10cSrcweir /*  [Beschreibung]
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir 	Bereich und Position innerhalb eines Bereiches f"ur eine
502*cdf0e10cSrcweir 	Dokumentvorlage wird ermittelt.
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 	[Parameter]
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir 	SvLBox *pBox            Listbox, an der das Ereignis auftrat
507*cdf0e10cSrcweir 	SvLBoxEntry *pEntry     Eintrag, dessen Position ermittelt werden soll
508*cdf0e10cSrcweir 	sal_uInt16 &rRegion         der Bereich innerhalb der Bereiche der
509*cdf0e10cSrcweir 							Dokumentvorlagen (Out-Parameter)
510*cdf0e10cSrcweir 	sal_uInt16 &rOffset         die Position innerhalb des Bereiches
511*cdf0e10cSrcweir 							Dokumentvorlagen (Out-Parameter)
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 	[Querverweise]
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 	<class Path>    (unter Umst"anden kann auf diese Funktion zugunsten
516*cdf0e10cSrcweir 					 von Path verzichtet werden.)
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir */
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir {
521*cdf0e10cSrcweir 	if(!pEntry)
522*cdf0e10cSrcweir 	{
523*cdf0e10cSrcweir 		rRegion = rOffset = 0;
524*cdf0e10cSrcweir 		return pEntry;
525*cdf0e10cSrcweir 	}
526*cdf0e10cSrcweir 	if(0 == pBox->GetModel()->GetDepth(pEntry))
527*cdf0e10cSrcweir 	{
528*cdf0e10cSrcweir 		rRegion = (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry);
529*cdf0e10cSrcweir 		rOffset = USHRT_MAX;
530*cdf0e10cSrcweir 		return pEntry;
531*cdf0e10cSrcweir 	}
532*cdf0e10cSrcweir 	SvLBoxEntry *pParent = pBox->GetParent(pEntry);
533*cdf0e10cSrcweir 	rRegion = (sal_uInt16)pBox->GetModel()->GetRelPos(pParent);
534*cdf0e10cSrcweir 	rOffset = (sal_uInt16)pBox->GetModel()->GetRelPos(pEntry);
535*cdf0e10cSrcweir 	return pEntry;
536*cdf0e10cSrcweir }
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir //-------------------------------------------------------------------------
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::Select( SvLBoxEntry* pEntry, sal_Bool bSelect )
541*cdf0e10cSrcweir {
542*cdf0e10cSrcweir 	if(!bSelect)
543*cdf0e10cSrcweir 		return SvTreeListBox::Select(pEntry,bSelect);
544*cdf0e10cSrcweir 	sal_uInt16 nLevel = GetDocLevel();
545*cdf0e10cSrcweir 	if(GetModel()->GetDepth(pEntry)+nLevel<3)
546*cdf0e10cSrcweir 		return SvTreeListBox::Select(pEntry,bSelect);
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir 	Path aPath(this, pEntry);
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir     // it is ok to use the SfxObjectShellRef here since the object that
551*cdf0e10cSrcweir     // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
552*cdf0e10cSrcweir 	GetObjectShell(aPath)->TriggerHelpPI(
553*cdf0e10cSrcweir 		aPath[nLevel+1], aPath[nLevel+2], aPath[nLevel+3]);
554*cdf0e10cSrcweir 	return SvTreeListBox::Select(pEntry,bSelect);
555*cdf0e10cSrcweir }
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir //-------------------------------------------------------------------------
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
560*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
561*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
562*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
563*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
564*cdf0e10cSrcweir 											sal_Bool bCopy)
565*cdf0e10cSrcweir /*  [Beschreibung]
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir 	Verschieben oder Kopieren von Dokumentvorlagen
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir 	[Parameter]
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 	SvLBox *pSourceBox          Quell-Listbox, an der das Ereignis auftrat
572*cdf0e10cSrcweir 	SvLBoxEntry *pSource        Quell-Eintrag, der kopiert / verschoben werden soll
573*cdf0e10cSrcweir 	SvLBoxEntry* pTarget        Ziel-Eintrag, auf den verschoben werden soll
574*cdf0e10cSrcweir 	SvLBoxEntry *&pNewParent    der Parent der an der Zielposition erzeugten
575*cdf0e10cSrcweir 								Eintrags (Out-Parameter)
576*cdf0e10cSrcweir 	sal_uIntPtr &rIdx                 Index des Zieleintrags
577*cdf0e10cSrcweir 	sal_Bool bCopy                  Flag f"ur Kopieren / Verschieben
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 	[Returnwert]                sal_Bool: Erfolg oder Mi"serfolg
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir 	[Querverweise]
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
585*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
586*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
587*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
588*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
589*cdf0e10cSrcweir 											sal_Bool bCopy)>
590*cdf0e10cSrcweir 	<sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
591*cdf0e10cSrcweir 											SvLBoxEntry* pSource,
592*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
593*cdf0e10cSrcweir 											sal_uIntPtr &rIdx)>
594*cdf0e10cSrcweir 	<sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
595*cdf0e10cSrcweir 											SvLBoxEntry* pSource,
596*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
597*cdf0e10cSrcweir 											sal_uIntPtr &rIdx)>
598*cdf0e10cSrcweir */
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir {
601*cdf0e10cSrcweir 	sal_Bool bOk = sal_False;
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 	if(pSource)
604*cdf0e10cSrcweir 	{
605*cdf0e10cSrcweir 		sal_uInt16 nTargetRegion = 0, nTargetIndex = 0;
606*cdf0e10cSrcweir 		GetIndices_Impl(this, pTarget, nTargetRegion, nTargetIndex);
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 		sal_uInt16 nSourceRegion = 0, nSourceIndex = 0;
609*cdf0e10cSrcweir 		GetIndices_Impl(pSourceBox, pSource, nSourceRegion, nSourceIndex);
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 		bOk =  bCopy ?
612*cdf0e10cSrcweir 			pMgr->Copy(nTargetRegion, nTargetIndex+1,
613*cdf0e10cSrcweir 					   nSourceRegion, nSourceIndex):
614*cdf0e10cSrcweir 			pMgr->Move(nTargetRegion, nTargetIndex+1,
615*cdf0e10cSrcweir 					   nSourceRegion, nSourceIndex);
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 		if(bOk)
618*cdf0e10cSrcweir 		{
619*cdf0e10cSrcweir 			if(pSourceBox->GetModel()->GetDepth(pSource) == GetModel()->GetDepth(pTarget))
620*cdf0e10cSrcweir 			{
621*cdf0e10cSrcweir 				pNewParent = GetParent(pTarget);
622*cdf0e10cSrcweir 				rIdx = GetModel()->GetRelPos(pTarget)+1;
623*cdf0e10cSrcweir 			}
624*cdf0e10cSrcweir 			else
625*cdf0e10cSrcweir 			{
626*cdf0e10cSrcweir 				if(nTargetIndex == USHRT_MAX)
627*cdf0e10cSrcweir 				{
628*cdf0e10cSrcweir 					pNewParent = pTarget;
629*cdf0e10cSrcweir 					rIdx = 0;
630*cdf0e10cSrcweir 				}
631*cdf0e10cSrcweir 				else
632*cdf0e10cSrcweir 					SvLBox::NotifyCopying(
633*cdf0e10cSrcweir 						pTarget, pSource, pNewParent, rIdx);
634*cdf0e10cSrcweir 			}
635*cdf0e10cSrcweir 		}
636*cdf0e10cSrcweir 		else if ( bCopy )
637*cdf0e10cSrcweir 		{
638*cdf0e10cSrcweir 			// the template organizer always tries copy after the move, so no error is required for move case
639*cdf0e10cSrcweir 			String aText( SfxResId( bCopy ? STR_ERROR_COPY_TEMPLATE : STR_ERROR_MOVE_TEMPLATE ) );
640*cdf0e10cSrcweir 			aText.SearchAndReplaceAscii( "$1",
641*cdf0e10cSrcweir 										 ( (SvTreeListBox *)pSourceBox )->GetEntryText( pSource ) );
642*cdf0e10cSrcweir 			ErrorBox( this, WB_OK, aText ).Execute();
643*cdf0e10cSrcweir 		}
644*cdf0e10cSrcweir 	}
645*cdf0e10cSrcweir 	return bOk;
646*cdf0e10cSrcweir }
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir //-------------------------------------------------------------------------
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
651*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
652*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
653*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
654*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
655*cdf0e10cSrcweir 											sal_Bool bCopy)
656*cdf0e10cSrcweir /*  [Beschreibung]
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir 	Verschieben oder Kopieren von Dokumentinhalten
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 	[Parameter]
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir 	SvLBox *pSourceBox          Quell-Listbox, an der das Ereignis auftrat
663*cdf0e10cSrcweir 	SvLBoxEntry *pSource        Quell-Eintrag, der kopiert / verschoben werden soll
664*cdf0e10cSrcweir 	SvLBoxEntry* pTarget        Ziel-Eintrag, auf den verschoben werden soll
665*cdf0e10cSrcweir 	SvLBoxEntry *&pNewParent    der Parent der an der Zielposition erzeugten
666*cdf0e10cSrcweir 								Eintrags (Out-Parameter)
667*cdf0e10cSrcweir 	sal_uIntPtr &rIdx                 Index des Zieleintrags
668*cdf0e10cSrcweir 	sal_Bool bCopy                  Flag f"ur Kopieren / Verschieben
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 	[Returnwert]                sal_Bool: Erfolg oder Mi"serfolg
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir 	[Querverweise]
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
676*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
677*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
678*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
679*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
680*cdf0e10cSrcweir 											sal_Bool bCopy)>
681*cdf0e10cSrcweir 	<sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
682*cdf0e10cSrcweir 											SvLBoxEntry* pSource,
683*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
684*cdf0e10cSrcweir 											sal_uIntPtr &rIdx)>
685*cdf0e10cSrcweir 	<sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
686*cdf0e10cSrcweir 											SvLBoxEntry* pSource,
687*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
688*cdf0e10cSrcweir 											sal_uIntPtr &rIdx)>
689*cdf0e10cSrcweir */
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir {
692*cdf0e10cSrcweir 	SfxErrorContext aEc( ERRCTX_SFX_MOVEORCOPYCONTENTS, this);
693*cdf0e10cSrcweir 	sal_Bool bOk = sal_False, bKeepExpansion = sal_False;
694*cdf0e10cSrcweir 	sal_Bool bRemovedFromSource = sal_False;
695*cdf0e10cSrcweir 	Path aSource(pSourceBox, pSource);
696*cdf0e10cSrcweir 	Path aTarget(this, pTarget);
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir     // it is ok to use the SfxObjectShellRef here since the object that
699*cdf0e10cSrcweir     // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
700*cdf0e10cSrcweir 	SfxObjectShellRef aSourceDoc = ((SfxOrganizeListBox_Impl *)pSourceBox)->GetObjectShell(aSource);
701*cdf0e10cSrcweir 	SfxObjectShellRef aTargetDoc = GetObjectShell(aTarget);
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir 	const sal_uInt16 nSLevel =
704*cdf0e10cSrcweir 		((SfxOrganizeListBox_Impl *)pSourceBox)->GetDocLevel();
705*cdf0e10cSrcweir 	const sal_uInt16 nTLevel = GetDocLevel();
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	if(aSourceDoc.Is() && aTargetDoc.Is())
708*cdf0e10cSrcweir 	{
709*cdf0e10cSrcweir 		if (aSourceDoc->GetStyleSheetPool())
710*cdf0e10cSrcweir 			aSourceDoc->GetStyleSheetPool()->SetSearchMask(
711*cdf0e10cSrcweir 				SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir 		if (aTargetDoc->GetStyleSheetPool())
714*cdf0e10cSrcweir 			aTargetDoc->GetStyleSheetPool()->SetSearchMask(
715*cdf0e10cSrcweir 				SFX_STYLE_FAMILY_ALL, SFXSTYLEBIT_USERDEF | SFXSTYLEBIT_USED);
716*cdf0e10cSrcweir 		sal_uInt16 p[3];
717*cdf0e10cSrcweir 		sal_uInt16 nIdxDeleted = INDEX_IGNORE;
718*cdf0e10cSrcweir 		p[0]=aTarget[nTLevel+1];
719*cdf0e10cSrcweir 		p[1]=aTarget[nTLevel+2];
720*cdf0e10cSrcweir 		if(p[1]!=INDEX_IGNORE)p[1]++;
721*cdf0e10cSrcweir 		p[2]=aTarget[nTLevel+3];
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir 		bOk = aTargetDoc->Insert(
724*cdf0e10cSrcweir 			*aSourceDoc, aSource[nSLevel+1],
725*cdf0e10cSrcweir 			aSource[nSLevel+2], aSource[nSLevel+3],
726*cdf0e10cSrcweir 			p[0], p[1], p[2],  nIdxDeleted);
727*cdf0e10cSrcweir 		// Positionskorrektur auswerten
728*cdf0e10cSrcweir 		// a = Dokumentinhalt
729*cdf0e10cSrcweir 		// b = Position Sub-Inhalt 1
730*cdf0e10cSrcweir 		// c = Position Sub-Inhalt 2
731*cdf0e10cSrcweir 		// doppelte Eintraege loeschen
732*cdf0e10cSrcweir 		if(bOk)
733*cdf0e10cSrcweir 		{
734*cdf0e10cSrcweir 			SvLBoxEntry *pParentIter = pTarget;
735*cdf0e10cSrcweir 			// bis auf die DokumentEbene nach oben als
736*cdf0e10cSrcweir 			// allgemeiner Bezugspunkt
737*cdf0e10cSrcweir 			while(GetModel()->GetDepth(pParentIter) != nTLevel)
738*cdf0e10cSrcweir 				pParentIter = GetParent(pParentIter);
739*cdf0e10cSrcweir 			if(pParentIter->HasChildsOnDemand() &&
740*cdf0e10cSrcweir 				!GetModel()->HasChilds(pParentIter))
741*cdf0e10cSrcweir 				RequestingChilds(pParentIter);
742*cdf0e10cSrcweir 			SvLBoxEntry *pChildIter = 0;
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir 			sal_uInt16 i = 0;
745*cdf0e10cSrcweir 			while(i < 2 && p[i+1] != INDEX_IGNORE)
746*cdf0e10cSrcweir 			{
747*cdf0e10cSrcweir 				pChildIter = FirstChild(pParentIter);
748*cdf0e10cSrcweir 				// bis zum Index der aktuellen Ebene
749*cdf0e10cSrcweir 				for(sal_uInt16 j = 0; j < p[i]; ++j)
750*cdf0e10cSrcweir 					pChildIter = NextSibling(pChildIter);
751*cdf0e10cSrcweir 				// gfs Fuellen bei Items onDemand
752*cdf0e10cSrcweir 				++i;
753*cdf0e10cSrcweir 				if(p[i+1] != INDEX_IGNORE &&
754*cdf0e10cSrcweir 				   pChildIter->HasChildsOnDemand() &&
755*cdf0e10cSrcweir 				   !GetModel()->HasChilds(pChildIter))
756*cdf0e10cSrcweir 					RequestingChilds(pChildIter);
757*cdf0e10cSrcweir 				pParentIter = pChildIter;
758*cdf0e10cSrcweir 			}
759*cdf0e10cSrcweir 			rIdx = p[i];
760*cdf0e10cSrcweir 			pNewParent = pParentIter;
761*cdf0e10cSrcweir 			if(!IsExpanded(pNewParent) &&
762*cdf0e10cSrcweir 			   pNewParent->HasChildsOnDemand() &&
763*cdf0e10cSrcweir 			   !GetModel()->HasChilds(pNewParent))
764*cdf0e10cSrcweir 			{
765*cdf0e10cSrcweir 				bOk = sal_False;
766*cdf0e10cSrcweir 				if(!bCopy)
767*cdf0e10cSrcweir 					pSourceBox->GetModel()->Remove(pSource);
768*cdf0e10cSrcweir 			}
769*cdf0e10cSrcweir 			// Geloeschte Eintraege entfernen
770*cdf0e10cSrcweir 			// (kann durch Ueberschreiben geschehen)
771*cdf0e10cSrcweir 			if(nIdxDeleted != INDEX_IGNORE)
772*cdf0e10cSrcweir 			{
773*cdf0e10cSrcweir 				pChildIter = FirstChild(pParentIter);
774*cdf0e10cSrcweir 				for(sal_uInt16 j = 0; j < nIdxDeleted; ++j)
775*cdf0e10cSrcweir 					pChildIter = NextSibling(pChildIter);
776*cdf0e10cSrcweir 				if( pChildIter && pChildIter != pSource )
777*cdf0e10cSrcweir 				{
778*cdf0e10cSrcweir 					bKeepExpansion = IsExpanded(pParentIter);
779*cdf0e10cSrcweir 					GetModel()->Remove(pChildIter);
780*cdf0e10cSrcweir 				}
781*cdf0e10cSrcweir 				else
782*cdf0e10cSrcweir 					bOk = sal_False;
783*cdf0e10cSrcweir 			}
784*cdf0e10cSrcweir 			if(!bCopy && &aSourceDoc != &aTargetDoc)
785*cdf0e10cSrcweir 			{
786*cdf0e10cSrcweir 				//#109566# pool styles that are moved produce
787*cdf0e10cSrcweir 				//an rIdx == INDEX_IGNORE
788*cdf0e10cSrcweir 				//the method has to return true to keep the box content consistent
789*cdf0e10cSrcweir 				bRemovedFromSource = aSourceDoc->Remove(aSource[nSLevel+1],
790*cdf0e10cSrcweir 									 aSource[nSLevel+2],
791*cdf0e10cSrcweir 									 aSource[nSLevel+3]);
792*cdf0e10cSrcweir 			}
793*cdf0e10cSrcweir 		}
794*cdf0e10cSrcweir 	}
795*cdf0e10cSrcweir //  rIdx++;
796*cdf0e10cSrcweir 	return (((rIdx != INDEX_IGNORE)|| bRemovedFromSource) && bOk )
797*cdf0e10cSrcweir 		? bKeepExpansion? (sal_Bool)2: sal_True: sal_False;
798*cdf0e10cSrcweir }
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir //-------------------------------------------------------------------------
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
803*cdf0e10cSrcweir 										SvLBoxEntry* pSource,
804*cdf0e10cSrcweir 										SvLBoxEntry *&pNewParent,
805*cdf0e10cSrcweir 										sal_uIntPtr &rIdx)
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir /*  [Beschreibung]
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir 	Benachrichtigung, da"s ein Eintrag verschoben werden soll
810*cdf0e10cSrcweir 	(SV-Handler)
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir 	[Parameter]
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 	SvLBoxEntry* pTarget        Ziel-Eintrag, auf den verschoben werden soll
815*cdf0e10cSrcweir 	SvLBoxEntry *pSource        Quell-Eintrag, der verschoben werden soll
816*cdf0e10cSrcweir 	SvLBoxEntry *&pNewParent    der Parent der an der Zielposition erzeugten
817*cdf0e10cSrcweir 								Eintrags (Out-Parameter)
818*cdf0e10cSrcweir 	sal_uIntPtr &rIdx                 Index des Zieleintrags
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir 	[Returnwert]                sal_Bool: Erfolg oder Mi"serfolg
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir 	[Querverweise]
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
826*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
827*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
828*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
829*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
830*cdf0e10cSrcweir 											sal_Bool bCopy)>
831*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
832*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
833*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
834*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
835*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
836*cdf0e10cSrcweir 											sal_Bool bCopy)>
837*cdf0e10cSrcweir 	<sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
838*cdf0e10cSrcweir 											SvLBoxEntry* pSource,
839*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
840*cdf0e10cSrcweir 											sal_uIntPtr &rIdx)>
841*cdf0e10cSrcweir */
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir {
844*cdf0e10cSrcweir 	sal_Bool bOk =  sal_False;
845*cdf0e10cSrcweir 	SvLBox* pSourceBox = GetSourceView();
846*cdf0e10cSrcweir 	if ( !pSourceBox )
847*cdf0e10cSrcweir 		pSourceBox = pDlg->pSourceView;
848*cdf0e10cSrcweir 	DBG_ASSERT( pSourceBox, "no source view" );
849*cdf0e10cSrcweir 	if ( !pTarget )
850*cdf0e10cSrcweir 		pTarget = pDlg->pTargetEntry;
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 	if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
853*cdf0e10cSrcweir 		 		     GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
854*cdf0e10cSrcweir 		bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_False );
855*cdf0e10cSrcweir 	else
856*cdf0e10cSrcweir 		bOk = MoveOrCopyContents(pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_False );
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir 	return bOk;
859*cdf0e10cSrcweir }
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir //-------------------------------------------------------------------------
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::NotifyCopying(SvLBoxEntry *pTarget,
864*cdf0e10cSrcweir 										SvLBoxEntry* pSource,
865*cdf0e10cSrcweir 										SvLBoxEntry *&pNewParent,
866*cdf0e10cSrcweir 										sal_uIntPtr &rIdx)
867*cdf0e10cSrcweir /*  [Beschreibung]
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir 	Benachrichtigung, da"s ein Eintrag kopiert werden soll
870*cdf0e10cSrcweir 	(SV-Handler)
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir 	[Parameter]
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir 	SvLBoxEntry* pTarget        Ziel-Eintrag, auf den kopiert werden soll
875*cdf0e10cSrcweir 	SvLBoxEntry *pSource        Quell-Eintrag, der kopiert werden soll
876*cdf0e10cSrcweir 	SvLBoxEntry *&pNewParent    der Parent der an der Zielposition erzeugten
877*cdf0e10cSrcweir 								Eintrags (Out-Parameter)
878*cdf0e10cSrcweir 	sal_uIntPtr &rIdx                 Index des Zieleintrags
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir 	[Returnwert]                sal_Bool: Erfolg oder Mi"serfolg
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 	[Querverweise]
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::MoveOrCopyTemplates(SvLBox *pSourceBox,
886*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
887*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
888*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
889*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
890*cdf0e10cSrcweir 											sal_Bool bCopy)>
891*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::MoveOrCopyContents(SvLBox *pSourceBox,
892*cdf0e10cSrcweir 											SvLBoxEntry *pSource,
893*cdf0e10cSrcweir 											SvLBoxEntry* pTarget,
894*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
895*cdf0e10cSrcweir 											sal_uIntPtr &rIdx,
896*cdf0e10cSrcweir 											sal_Bool bCopy)>
897*cdf0e10cSrcweir 	<sal_Bool SfxOrganizeListBox_Impl::NotifyMoving(SvLBoxEntry *pTarget,
898*cdf0e10cSrcweir 											SvLBoxEntry* pSource,
899*cdf0e10cSrcweir 											SvLBoxEntry *&pNewParent,
900*cdf0e10cSrcweir 											sal_uIntPtr &rIdx)>
901*cdf0e10cSrcweir */
902*cdf0e10cSrcweir {
903*cdf0e10cSrcweir 	sal_Bool bOk =  sal_False;
904*cdf0e10cSrcweir 	SvLBox* pSourceBox = GetSourceView();
905*cdf0e10cSrcweir 	if ( !pSourceBox )
906*cdf0e10cSrcweir 		pSourceBox = pDlg->pSourceView;
907*cdf0e10cSrcweir 	DBG_ASSERT( pSourceBox, "no source view" );
908*cdf0e10cSrcweir 	if ( !pTarget )
909*cdf0e10cSrcweir 		pTarget = pDlg->pTargetEntry;
910*cdf0e10cSrcweir 	if ( pSourceBox->GetModel()->GetDepth( pSource ) <= GetDocLevel() &&
911*cdf0e10cSrcweir 					 GetModel()->GetDepth( pTarget ) <= GetDocLevel() )
912*cdf0e10cSrcweir 		bOk = MoveOrCopyTemplates( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_True );
913*cdf0e10cSrcweir 	else
914*cdf0e10cSrcweir 		bOk = MoveOrCopyContents( pSourceBox, pSource, pTarget, pNewParent, rIdx, sal_True );
915*cdf0e10cSrcweir 
916*cdf0e10cSrcweir 	return bOk;
917*cdf0e10cSrcweir }
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir //-------------------------------------------------------------------------
920*cdf0e10cSrcweir 
921*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::EditingEntry( SvLBoxEntry* pEntry, Selection&  )
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir /*  [Beschreibung]
924*cdf0e10cSrcweir 
925*cdf0e10cSrcweir 	Nachfrage, ob ein Eintrag editierbar ist
926*cdf0e10cSrcweir 	(SV-Handler)
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir 	[Querverweise]
929*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry* pEntry, const String& rText)>
930*cdf0e10cSrcweir */
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir {
933*cdf0e10cSrcweir 	if( VIEW_TEMPLATES == eViewType &&
934*cdf0e10cSrcweir         GetModel()->GetDepth(pEntry) < 2 )
935*cdf0e10cSrcweir 	{
936*cdf0e10cSrcweir 		pDlg->pSuspend = new SuspendAccel( &pDlg->aEditAcc );
937*cdf0e10cSrcweir 		return sal_True;
938*cdf0e10cSrcweir 	}
939*cdf0e10cSrcweir 	return sal_False;
940*cdf0e10cSrcweir }
941*cdf0e10cSrcweir 
942*cdf0e10cSrcweir //-------------------------------------------------------------------------
943*cdf0e10cSrcweir 
944*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::EditedEntry(SvLBoxEntry* pEntry, const String& rText)
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir /*  [Beschreibung]
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir 	Der Name eines Eintrags wurde bearbeitet; ist der eingegebene Name
949*cdf0e10cSrcweir 	ein g"ultiger Name ("ange > 0), wird das Model aktualisiert.
950*cdf0e10cSrcweir 	(SV-Handler)
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir 	[Returnwert]
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir 	sal_Bool                sal_True: der Name soll in der Anzeige ge"andert werden
955*cdf0e10cSrcweir 						    sal_False:der Name soll nicht ge"andert werden
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir 	[Querverweise]
958*cdf0e10cSrcweir 	<SfxOrganizeListBox_Impl::EditingEntry(SvLBoxEntry* pEntry, const String& rText)>
959*cdf0e10cSrcweir */
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir {
962*cdf0e10cSrcweir 	DBG_ASSERT(pEntry, "kein Entry selektiert");
963*cdf0e10cSrcweir 	delete pDlg->pSuspend;
964*cdf0e10cSrcweir 	pDlg->pSuspend = NULL;
965*cdf0e10cSrcweir 	SvLBoxEntry* pParent = GetParent(pEntry);
966*cdf0e10cSrcweir 	if( !rText.Len() )
967*cdf0e10cSrcweir 	{
968*cdf0e10cSrcweir 		ErrorBox aBox( this, SfxResId( MSG_ERROR_EMPTY_NAME ) );
969*cdf0e10cSrcweir 		aBox.GrabFocus();
970*cdf0e10cSrcweir 		aBox.Execute();
971*cdf0e10cSrcweir 		return sal_False;
972*cdf0e10cSrcweir 	}
973*cdf0e10cSrcweir 	if ( !IsUniqName_Impl( rText, pParent, pEntry ) )
974*cdf0e10cSrcweir 	{
975*cdf0e10cSrcweir 		ErrorBox aBox( this, SfxResId( MSG_ERROR_UNIQ_NAME ) );
976*cdf0e10cSrcweir 		aBox.GrabFocus();
977*cdf0e10cSrcweir 		aBox.Execute();
978*cdf0e10cSrcweir 		return sal_False;
979*cdf0e10cSrcweir 	}
980*cdf0e10cSrcweir 	sal_uInt16 nRegion = 0, nIndex = 0;
981*cdf0e10cSrcweir 	GetIndices_Impl( this, pEntry, nRegion, nIndex );
982*cdf0e10cSrcweir 	String aOldName;
983*cdf0e10cSrcweir 	if ( USHRT_MAX != nIndex )
984*cdf0e10cSrcweir 		aOldName = pMgr->GetTemplates()->GetName( nRegion, nIndex );
985*cdf0e10cSrcweir 	else
986*cdf0e10cSrcweir 		aOldName = pMgr->GetTemplates()->GetRegionName( nRegion );
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir 	if ( !pMgr->SetName( rText, nRegion, nIndex ) )
989*cdf0e10cSrcweir 	{
990*cdf0e10cSrcweir 		SfxResId aResId( USHRT_MAX != nIndex ? MSG_ERROR_RENAME_TEMPLATE
991*cdf0e10cSrcweir 											 : MSG_ERROR_RENAME_TEMPLATE_REGION );
992*cdf0e10cSrcweir 		ErrorBox( this, aResId ).Execute();
993*cdf0e10cSrcweir 		return sal_False;
994*cdf0e10cSrcweir 	}
995*cdf0e10cSrcweir /*
996*cdf0e10cSrcweir 	else
997*cdf0e10cSrcweir 	{
998*cdf0e10cSrcweir 		SfxTemplateOrganizeDlg* pDlg = (SfxTemplateOrganizeDlg*)Window::GetParent();
999*cdf0e10cSrcweir 	}
1000*cdf0e10cSrcweir */
1001*cdf0e10cSrcweir 	return sal_True;
1002*cdf0e10cSrcweir }
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir //-------------------------------------------------------------------------
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir DragDropMode SfxOrganizeListBox_Impl::NotifyStartDrag( TransferDataContainer&, SvLBoxEntry* pEntry )
1007*cdf0e10cSrcweir {
1008*cdf0e10cSrcweir 	sal_uInt16 nSourceLevel = GetModel()->GetDepth( pEntry );
1009*cdf0e10cSrcweir 	if ( VIEW_FILES == GetViewType() )
1010*cdf0e10cSrcweir 		++nSourceLevel;
1011*cdf0e10cSrcweir 	if ( nSourceLevel >= 2 )
1012*cdf0e10cSrcweir 		bDropMoveOk = sal_False;
1013*cdf0e10cSrcweir 	else
1014*cdf0e10cSrcweir 		bDropMoveOk = sal_True;
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir 	return GetDragDropMode();
1017*cdf0e10cSrcweir }
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir //-------------------------------------------------------------------------
1020*cdf0e10cSrcweir 
1021*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::NotifyAcceptDrop( SvLBoxEntry* pEntry )
1022*cdf0e10cSrcweir {
1023*cdf0e10cSrcweir 	if(!pEntry)
1024*cdf0e10cSrcweir 		return sal_False;
1025*cdf0e10cSrcweir 	SvLBox *pSource = GetSourceView();
1026*cdf0e10cSrcweir 	SvLBoxEntry *pSourceEntry = pSource->FirstSelected();
1027*cdf0e10cSrcweir 	if(pEntry == pSourceEntry)
1028*cdf0e10cSrcweir 		return sal_False;
1029*cdf0e10cSrcweir 	sal_uInt16 nSourceLevel = pSource->GetModel()->GetDepth(pSourceEntry);
1030*cdf0e10cSrcweir 	if(VIEW_FILES == ((SfxOrganizeListBox_Impl *)pSource)->GetViewType())
1031*cdf0e10cSrcweir 		++nSourceLevel;
1032*cdf0e10cSrcweir 	sal_uInt16 nTargetLevel = GetModel()->GetDepth(pEntry);
1033*cdf0e10cSrcweir 	if(VIEW_FILES == GetViewType())
1034*cdf0e10cSrcweir 		++nTargetLevel;
1035*cdf0e10cSrcweir 	Path aSource(pSource, pSourceEntry);
1036*cdf0e10cSrcweir 	Path aTarget(this, pEntry);
1037*cdf0e10cSrcweir 	const sal_uInt16 SL = ((SfxOrganizeListBox_Impl *)pSource)->GetDocLevel();
1038*cdf0e10cSrcweir 	const sal_uInt16 TL = GetDocLevel();
1039*cdf0e10cSrcweir 
1040*cdf0e10cSrcweir 	return( (nSourceLevel == 1 && nTargetLevel == 0 &&
1041*cdf0e10cSrcweir 			VIEW_TEMPLATES ==
1042*cdf0e10cSrcweir 			((SfxOrganizeListBox_Impl *)pSource)->GetViewType()) ||
1043*cdf0e10cSrcweir 		   (nSourceLevel == 1 && nTargetLevel == 1 &&
1044*cdf0e10cSrcweir 			VIEW_TEMPLATES ==
1045*cdf0e10cSrcweir 			((SfxOrganizeListBox_Impl *)pSource)->GetViewType() &&
1046*cdf0e10cSrcweir 			VIEW_TEMPLATES == GetViewType()) ||
1047*cdf0e10cSrcweir 		   (nSourceLevel == 3 && nTargetLevel == 1) ||
1048*cdf0e10cSrcweir 		   (nSourceLevel == 3 && nTargetLevel == 2 &&
1049*cdf0e10cSrcweir 			aSource[1+SL] == aTarget[1+TL]) ||
1050*cdf0e10cSrcweir 		   (nSourceLevel == 3 && nTargetLevel == 3 &&
1051*cdf0e10cSrcweir 			aSource[1+SL] == aTarget[1+TL]) ||
1052*cdf0e10cSrcweir 		   (nSourceLevel == 4 && nTargetLevel == 3 &&
1053*cdf0e10cSrcweir 			aSource[1+SL] == aTarget[1+TL] &&
1054*cdf0e10cSrcweir 			aSource[2+SL] == aTarget[2+TL]) ||
1055*cdf0e10cSrcweir 		   (nSourceLevel == 4 && nTargetLevel == 4 &&
1056*cdf0e10cSrcweir 			aSource[1+SL] == aTarget[1+TL] &&
1057*cdf0e10cSrcweir 			aSource[2+SL] == aTarget[2+TL]));
1058*cdf0e10cSrcweir }
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir //-------------------------------------------------------------------------
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir sal_Int8 SfxOrganizeListBox_Impl::AcceptDrop( const AcceptDropEvent& rEvt )
1063*cdf0e10cSrcweir {
1064*cdf0e10cSrcweir 	sal_Bool bAccept = ( eViewType == VIEW_FILES && IsDropFormatSupported( SOT_FORMAT_FILE ) );
1065*cdf0e10cSrcweir 	if ( bAccept )
1066*cdf0e10cSrcweir 		return rEvt.mnAction;
1067*cdf0e10cSrcweir 	else
1068*cdf0e10cSrcweir 		return SvTreeListBox::AcceptDrop( rEvt );
1069*cdf0e10cSrcweir }
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir //-------------------------------------------------------------------------
1072*cdf0e10cSrcweir 
1073*cdf0e10cSrcweir sal_Int8 SfxOrganizeListBox_Impl::ExecuteDrop( const ExecuteDropEvent& rEvt )
1074*cdf0e10cSrcweir {
1075*cdf0e10cSrcweir 	TransferableDataHelper aHelper( rEvt.maDropEvent.Transferable );
1076*cdf0e10cSrcweir 	sal_uInt32 nFormatCount = aHelper.GetFormatCount();
1077*cdf0e10cSrcweir 	sal_Bool bSuccess = sal_False;
1078*cdf0e10cSrcweir 	for ( sal_uInt32 i = 0; i < nFormatCount; ++i )
1079*cdf0e10cSrcweir 	{
1080*cdf0e10cSrcweir 		String aFileName;
1081*cdf0e10cSrcweir 		SotFormatStringId nId = aHelper.GetFormat(i);
1082*cdf0e10cSrcweir 
1083*cdf0e10cSrcweir 		if ( SOT_FORMAT_FILE == nId && aHelper.GetString( nId, aFileName ) )
1084*cdf0e10cSrcweir 		{
1085*cdf0e10cSrcweir 			INetURLObject aObj( aFileName, INET_PROT_FILE );
1086*cdf0e10cSrcweir 			bSuccess |= pMgr->InsertFile( this, aObj.GetMainURL(INetURLObject::DECODE_TO_IURI) );
1087*cdf0e10cSrcweir 		}
1088*cdf0e10cSrcweir 	}
1089*cdf0e10cSrcweir 	bDropMoveOk = sal_True;
1090*cdf0e10cSrcweir 	sal_Int8 nRet = rEvt.mnAction;
1091*cdf0e10cSrcweir 	if ( !bSuccess )
1092*cdf0e10cSrcweir 	{
1093*cdf0e10cSrcweir 		// asynchronous, because of MessBoxes
1094*cdf0e10cSrcweir 		pDlg->pSourceView = GetSourceView();
1095*cdf0e10cSrcweir 		pDlg->pTargetEntry = pTargetEntry;
1096*cdf0e10cSrcweir         pDlg->pFinishedBox = NULL;
1097*cdf0e10cSrcweir         pDlg->nDropAction = NO_DROP_ACTION;
1098*cdf0e10cSrcweir 		PostUserEvent( LINK( this, SfxOrganizeListBox_Impl, OnAsyncExecuteDrop ),
1099*cdf0e10cSrcweir 					   new ExecuteDropEvent( rEvt ) );
1100*cdf0e10cSrcweir 	}
1101*cdf0e10cSrcweir 
1102*cdf0e10cSrcweir 	return nRet;
1103*cdf0e10cSrcweir }
1104*cdf0e10cSrcweir 
1105*cdf0e10cSrcweir //-------------------------------------------------------------------------
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir void SfxOrganizeListBox_Impl::DragFinished( sal_Int8 nDropAction )
1108*cdf0e10cSrcweir {
1109*cdf0e10cSrcweir     if ( pDlg->bExecDropFinished )
1110*cdf0e10cSrcweir     {
1111*cdf0e10cSrcweir         if ( pDlg->nDropAction != NO_DROP_ACTION )
1112*cdf0e10cSrcweir             nDropAction = pDlg->nDropAction;
1113*cdf0e10cSrcweir         SvTreeListBox::DragFinished( nDropAction );
1114*cdf0e10cSrcweir         pDlg->nDropAction = NO_DROP_ACTION;
1115*cdf0e10cSrcweir     }
1116*cdf0e10cSrcweir     else
1117*cdf0e10cSrcweir         pDlg->pFinishedBox = this;
1118*cdf0e10cSrcweir }
1119*cdf0e10cSrcweir 
1120*cdf0e10cSrcweir //-------------------------------------------------------------------------
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir inline sal_uInt16 SfxOrganizeListBox_Impl::GetDocLevel() const
1123*cdf0e10cSrcweir 
1124*cdf0e10cSrcweir /*  [Beschreibung]
1125*cdf0e10cSrcweir 
1126*cdf0e10cSrcweir 	Ermittelt, auf welche Ebene sich Dokumente befinden (unterschiedlich
1127*cdf0e10cSrcweir 	in der Dokumentvorlagensicht und der Dokumentensicht)
1128*cdf0e10cSrcweir 
1129*cdf0e10cSrcweir 	[Returnwert]
1130*cdf0e10cSrcweir 
1131*cdf0e10cSrcweir 	sal_uInt16              Die Ebene der Dokumente
1132*cdf0e10cSrcweir 
1133*cdf0e10cSrcweir */
1134*cdf0e10cSrcweir 
1135*cdf0e10cSrcweir {
1136*cdf0e10cSrcweir 	return eViewType == VIEW_FILES? 0: 1;
1137*cdf0e10cSrcweir }
1138*cdf0e10cSrcweir 
1139*cdf0e10cSrcweir //-------------------------------------------------------------------------
1140*cdf0e10cSrcweir 
1141*cdf0e10cSrcweir SfxObjectShellRef SfxOrganizeListBox_Impl::GetObjectShell(const Path &rPath)
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir /*  [Beschreibung]
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir 	Zugriff auf die ObjectShell, die dem aktuellen Eintrag zugeordnet
1146*cdf0e10cSrcweir 	ist.
1147*cdf0e10cSrcweir 
1148*cdf0e10cSrcweir 	[Parameter]
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir 	const Path &rPath       Beschreibung des aktuellen Eintrags
1151*cdf0e10cSrcweir 
1152*cdf0e10cSrcweir 	[Returnwert]
1153*cdf0e10cSrcweir 
1154*cdf0e10cSrcweir 	SfxObjectShellRef     Referenz auf die ObjectShell
1155*cdf0e10cSrcweir 
1156*cdf0e10cSrcweir 	[Querverweise]
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir 	<class Path>
1159*cdf0e10cSrcweir 
1160*cdf0e10cSrcweir */
1161*cdf0e10cSrcweir 
1162*cdf0e10cSrcweir {
1163*cdf0e10cSrcweir 	SfxObjectShellRef aDoc;
1164*cdf0e10cSrcweir 	if(eViewType == VIEW_FILES)
1165*cdf0e10cSrcweir 		aDoc = pMgr->CreateObjectShell(rPath[0]);
1166*cdf0e10cSrcweir 	else
1167*cdf0e10cSrcweir 		aDoc = pMgr->CreateObjectShell(rPath[0], rPath[1]);
1168*cdf0e10cSrcweir 	return aDoc;
1169*cdf0e10cSrcweir }
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir //-------------------------------------------------------------------------
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir void SfxOrganizeListBox_Impl::RequestingChilds( SvLBoxEntry* pEntry )
1174*cdf0e10cSrcweir 
1175*cdf0e10cSrcweir /*  [Beschreibung]
1176*cdf0e10cSrcweir 
1177*cdf0e10cSrcweir 	Aufforderung, der Childs eines Eintrags einzuf"ugen
1178*cdf0e10cSrcweir 	ist.
1179*cdf0e10cSrcweir 	(SV-Handler)
1180*cdf0e10cSrcweir 
1181*cdf0e10cSrcweir 	[Parameter]
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir 	SvLBoxEntry* pEntry     der Eintrag, dessen Childs erfragt werden
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir 
1186*cdf0e10cSrcweir */
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir {
1189*cdf0e10cSrcweir 	// wenn keine Childs vorhanden sind, gfs. Childs
1190*cdf0e10cSrcweir 	// einfuegen
1191*cdf0e10cSrcweir 	BmpColorMode eColorMode = BMP_COLOR_NORMAL;
1192*cdf0e10cSrcweir 
1193*cdf0e10cSrcweir 	if ( GetSettings().GetStyleSettings().GetHighContrastMode() )
1194*cdf0e10cSrcweir 		eColorMode = BMP_COLOR_HIGHCONTRAST;
1195*cdf0e10cSrcweir 
1196*cdf0e10cSrcweir 
1197*cdf0e10cSrcweir 	if ( !GetModel()->HasChilds( pEntry ) )
1198*cdf0e10cSrcweir 	{
1199*cdf0e10cSrcweir 		WaitObject aWaitCursor( this );
1200*cdf0e10cSrcweir 
1201*cdf0e10cSrcweir 		// Choose the correct mask color dependent from eColorMode. This must be adopted if
1202*cdf0e10cSrcweir 		// we change the mask color for normal images, too!
1203*cdf0e10cSrcweir 		Color aMaskColor( COL_LIGHTMAGENTA );
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir 		// hier sind alle initial eingefuegt
1206*cdf0e10cSrcweir 		SfxErrorContext aEc(ERRCTX_SFX_CREATEOBJSH, pDlg->pDialog);
1207*cdf0e10cSrcweir 		if(VIEW_TEMPLATES == GetViewType() && 0 == GetModel()->GetDepth(pEntry))
1208*cdf0e10cSrcweir 		{
1209*cdf0e10cSrcweir 			sal_uInt16 i = (sal_uInt16)GetModel()->GetRelPos(pEntry);
1210*cdf0e10cSrcweir 			const sal_uInt16 nEntryCount = pMgr->GetTemplates()->GetCount(i);
1211*cdf0e10cSrcweir 			for(sal_uInt16 j = 0; j < nEntryCount; ++j)
1212*cdf0e10cSrcweir 				InsertEntryByBmpType( pMgr->GetTemplates()->GetName( i, j ), BMPTYPE_DOC, pEntry, sal_True );
1213*cdf0e10cSrcweir 		}
1214*cdf0e10cSrcweir 		else
1215*cdf0e10cSrcweir 		{
1216*cdf0e10cSrcweir 			const sal_uInt16 nDocLevel = GetDocLevel();
1217*cdf0e10cSrcweir 			Path aPath(this, pEntry);
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir             // it is ok to use the SfxObjectShellRef here since the object that
1220*cdf0e10cSrcweir             // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
1221*cdf0e10cSrcweir 			SfxObjectShellRef aRef = GetObjectShell(aPath);
1222*cdf0e10cSrcweir 			if(aRef.Is())
1223*cdf0e10cSrcweir 			{
1224*cdf0e10cSrcweir 				const sal_uInt16 nCount = aRef->GetContentCount(
1225*cdf0e10cSrcweir 					aPath[nDocLevel+1], aPath[nDocLevel+2]);
1226*cdf0e10cSrcweir 				String aText;
1227*cdf0e10cSrcweir 				Bitmap aClosedBmp, aOpenedBmp;
1228*cdf0e10cSrcweir 				const sal_Bool bCanHaveChilds =
1229*cdf0e10cSrcweir 					aRef->CanHaveChilds(aPath[nDocLevel+1],
1230*cdf0e10cSrcweir 										aPath[nDocLevel+2]);
1231*cdf0e10cSrcweir 				for(sal_uInt16 i = 0; i < nCount; ++i)
1232*cdf0e10cSrcweir 				{
1233*cdf0e10cSrcweir 					sal_Bool bDeletable;
1234*cdf0e10cSrcweir 					aRef->GetContent(
1235*cdf0e10cSrcweir 						aText, aClosedBmp, aOpenedBmp, eColorMode, bDeletable,
1236*cdf0e10cSrcweir 						i, aPath[nDocLevel+1], aPath[nDocLevel+2]);
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir 					// Create image with the correct mask color
1239*cdf0e10cSrcweir 					Image aClosedImage( aClosedBmp, aMaskColor );
1240*cdf0e10cSrcweir 					Image aOpenedImage( aOpenedBmp, aMaskColor );
1241*cdf0e10cSrcweir 
1242*cdf0e10cSrcweir 					SvLBoxEntry *pNew = SvTreeListBox::InsertEntry(
1243*cdf0e10cSrcweir 						aText, aOpenedImage, aClosedImage,
1244*cdf0e10cSrcweir 						pEntry, bCanHaveChilds);
1245*cdf0e10cSrcweir 					pNew->SetUserData(bDeletable ? &bDeletable : 0);
1246*cdf0e10cSrcweir 				}
1247*cdf0e10cSrcweir 			}
1248*cdf0e10cSrcweir 		}
1249*cdf0e10cSrcweir 	}
1250*cdf0e10cSrcweir }
1251*cdf0e10cSrcweir 
1252*cdf0e10cSrcweir //-------------------------------------------------------------------------
1253*cdf0e10cSrcweir 
1254*cdf0e10cSrcweir long SfxOrganizeListBox_Impl::ExpandingHdl()
1255*cdf0e10cSrcweir 
1256*cdf0e10cSrcweir /*  [Beschreibung]
1257*cdf0e10cSrcweir 
1258*cdf0e10cSrcweir 	SV-Handler, der nach dem und vor dem Aufklappen eines Eintrags
1259*cdf0e10cSrcweir 	gerufen wird.
1260*cdf0e10cSrcweir 	Wird verwendet, um gfs. die ObjectShell wieder zu schlie"sen;
1261*cdf0e10cSrcweir 	die Eintr"age mit den Inhalten dieser Shell werden ebenfalls
1262*cdf0e10cSrcweir 	entfernt.
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir */
1265*cdf0e10cSrcweir 
1266*cdf0e10cSrcweir {
1267*cdf0e10cSrcweir 	if ( !(nImpFlags & SVLBOX_IS_EXPANDING) )
1268*cdf0e10cSrcweir 	{
1269*cdf0e10cSrcweir 		SvLBoxEntry* pEntry  = GetHdlEntry();
1270*cdf0e10cSrcweir 		const sal_uInt16 nLevel = GetModel()->GetDepth(pEntry);
1271*cdf0e10cSrcweir 		if((eViewType == VIEW_FILES && nLevel == 0) ||
1272*cdf0e10cSrcweir 		   (eViewType == VIEW_TEMPLATES && nLevel == 1))
1273*cdf0e10cSrcweir 		{
1274*cdf0e10cSrcweir 			Path aPath(this, pEntry);
1275*cdf0e10cSrcweir 			// Beim Schliessen des Files die ObjectShell freigeben
1276*cdf0e10cSrcweir 			if(eViewType == VIEW_FILES && nLevel == 0)
1277*cdf0e10cSrcweir 				pMgr->DeleteObjectShell(aPath[0]);
1278*cdf0e10cSrcweir 			else
1279*cdf0e10cSrcweir 				pMgr->DeleteObjectShell(aPath[0], aPath[1]);
1280*cdf0e10cSrcweir 			// alle SubEntries loeschen
1281*cdf0e10cSrcweir 			SvLBoxEntry *pToDel = SvLBox::GetEntry(pEntry, 0);
1282*cdf0e10cSrcweir 			while(pToDel)
1283*cdf0e10cSrcweir 			{
1284*cdf0e10cSrcweir 				GetModel()->Remove(pToDel);
1285*cdf0e10cSrcweir 				pToDel = SvLBox::GetEntry(pEntry, 0);
1286*cdf0e10cSrcweir 			}
1287*cdf0e10cSrcweir 		}
1288*cdf0e10cSrcweir 	}
1289*cdf0e10cSrcweir 	return sal_True;
1290*cdf0e10cSrcweir }
1291*cdf0e10cSrcweir 
1292*cdf0e10cSrcweir //-------------------------------------------------------------------------
1293*cdf0e10cSrcweir 
1294*cdf0e10cSrcweir sal_Bool SfxOrganizeListBox_Impl::IsUniqName_Impl(const String &rText,
1295*cdf0e10cSrcweir 										 SvLBoxEntry* pParent, SvLBoxEntry *pEntry) const
1296*cdf0e10cSrcweir 
1297*cdf0e10cSrcweir /*  [Beschreibung]
1298*cdf0e10cSrcweir 
1299*cdf0e10cSrcweir 	Pr"uft, ob eine Name auf seiner Ebene eindeutig ist.
1300*cdf0e10cSrcweir 
1301*cdf0e10cSrcweir 	[Parameter]
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir 	const String &         Name des zu suchenden Eintrags
1304*cdf0e10cSrcweir 	SvLBoxEntry* pSibling  Geschwister (bezeichnet die Ebene)
1305*cdf0e10cSrcweir 
1306*cdf0e10cSrcweir 	[Returnwert]
1307*cdf0e10cSrcweir 
1308*cdf0e10cSrcweir 	sal_Bool                     sal_True, wenn der Name eindeutig ist, sonst sal_False
1309*cdf0e10cSrcweir */
1310*cdf0e10cSrcweir 
1311*cdf0e10cSrcweir {
1312*cdf0e10cSrcweir 	SvLBoxEntry* pChild = FirstChild(pParent);
1313*cdf0e10cSrcweir 	while(pChild)  {
1314*cdf0e10cSrcweir 		const String aEntryText(GetEntryText(pChild));
1315*cdf0e10cSrcweir 		if(COMPARE_EQUAL == aEntryText.CompareIgnoreCaseToAscii(rText)&&(!pEntry || pEntry!=pChild))
1316*cdf0e10cSrcweir 			return sal_False;
1317*cdf0e10cSrcweir 		pChild = NextSibling(pChild);
1318*cdf0e10cSrcweir 	}
1319*cdf0e10cSrcweir 	return sal_True;
1320*cdf0e10cSrcweir }
1321*cdf0e10cSrcweir 
1322*cdf0e10cSrcweir //-------------------------------------------------------------------------
1323*cdf0e10cSrcweir 
1324*cdf0e10cSrcweir sal_uInt16 SfxOrganizeListBox_Impl::GetLevelCount_Impl(SvLBoxEntry* pParent) const
1325*cdf0e10cSrcweir {
1326*cdf0e10cSrcweir 	SvLBoxEntry* pChild = FirstChild(pParent);
1327*cdf0e10cSrcweir 	sal_uInt16 nCount = 0;
1328*cdf0e10cSrcweir 	while(pChild)  {
1329*cdf0e10cSrcweir 		pChild = NextSibling(pChild);
1330*cdf0e10cSrcweir 		++nCount;
1331*cdf0e10cSrcweir 	}
1332*cdf0e10cSrcweir 	return nCount;
1333*cdf0e10cSrcweir }
1334*cdf0e10cSrcweir 
1335*cdf0e10cSrcweir //-------------------------------------------------------------------------
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir SvLBoxEntry* SfxOrganizeListBox_Impl::InsertEntryByBmpType( const XubString& rText, BMPTYPE eBmpType,
1338*cdf0e10cSrcweir 	SvLBoxEntry* pParent, sal_Bool bChildsOnDemand, sal_uIntPtr nPos, void* pUserData )
1339*cdf0e10cSrcweir {
1340*cdf0e10cSrcweir 	SvLBoxEntry*	pEntry = NULL;
1341*cdf0e10cSrcweir 	const Image*	pExp = NULL;
1342*cdf0e10cSrcweir 	const Image*	pCol = NULL;
1343*cdf0e10cSrcweir 	const Image*	pExpHC = NULL;
1344*cdf0e10cSrcweir 	const Image*	pColHC = NULL;
1345*cdf0e10cSrcweir 
1346*cdf0e10cSrcweir 	switch( eBmpType )
1347*cdf0e10cSrcweir 	{
1348*cdf0e10cSrcweir 		case BMPTYPE_FOLDER:
1349*cdf0e10cSrcweir 			pExp = &aOpenedFolderBmp;
1350*cdf0e10cSrcweir 			pCol = &aClosedFolderBmp;
1351*cdf0e10cSrcweir 			pExpHC = &aOpenedFolderBmpHC;
1352*cdf0e10cSrcweir 			pColHC = &aClosedFolderBmpHC;
1353*cdf0e10cSrcweir 			break;
1354*cdf0e10cSrcweir 		default:
1355*cdf0e10cSrcweir 			DBG_ERROR( "SfxOrganizeListBox_Impl::InsertEntryByBmpType(): something forgotten?!" );
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir 		case BMPTYPE_DOC:
1358*cdf0e10cSrcweir 			pExp = &aOpenedDocBmp;
1359*cdf0e10cSrcweir 			pCol = &aClosedDocBmp;
1360*cdf0e10cSrcweir 			pExpHC = &aOpenedDocBmpHC;
1361*cdf0e10cSrcweir 			pColHC = &aClosedDocBmpHC;
1362*cdf0e10cSrcweir 			break;
1363*cdf0e10cSrcweir 	}
1364*cdf0e10cSrcweir 
1365*cdf0e10cSrcweir 	pEntry = SvTreeListBox::InsertEntry( rText, *pExp, *pCol, pParent, bChildsOnDemand, nPos, pUserData );
1366*cdf0e10cSrcweir 
1367*cdf0e10cSrcweir 	SetExpandedEntryBmp( pEntry, *pExpHC, BMP_COLOR_HIGHCONTRAST );
1368*cdf0e10cSrcweir 	SetCollapsedEntryBmp( pEntry, *pColHC, BMP_COLOR_HIGHCONTRAST );
1369*cdf0e10cSrcweir 
1370*cdf0e10cSrcweir 	return pEntry;
1371*cdf0e10cSrcweir }
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir //-------------------------------------------------------------------------
1374*cdf0e10cSrcweir 
1375*cdf0e10cSrcweir SfxOrganizeListBox_Impl::SfxOrganizeListBox_Impl
1376*cdf0e10cSrcweir (
1377*cdf0e10cSrcweir 	SfxOrganizeDlg_Impl* pArgDlg,
1378*cdf0e10cSrcweir 	Window* pParent,
1379*cdf0e10cSrcweir 	WinBits nBits,
1380*cdf0e10cSrcweir 	DataEnum eType
1381*cdf0e10cSrcweir ) :
1382*cdf0e10cSrcweir 
1383*cdf0e10cSrcweir 	SvTreeListBox( pParent, nBits ),
1384*cdf0e10cSrcweir 
1385*cdf0e10cSrcweir 	pMgr		( NULL ),
1386*cdf0e10cSrcweir 	pDlg		( pArgDlg ),
1387*cdf0e10cSrcweir 	eViewType	( eType )
1388*cdf0e10cSrcweir 
1389*cdf0e10cSrcweir /*  [Beschreibung]
1390*cdf0e10cSrcweir 
1391*cdf0e10cSrcweir 	Konstruktor SfxOrganizeListBox
1392*cdf0e10cSrcweir 
1393*cdf0e10cSrcweir */
1394*cdf0e10cSrcweir 
1395*cdf0e10cSrcweir {
1396*cdf0e10cSrcweir 	SetDragDropMode(
1397*cdf0e10cSrcweir 		SV_DRAGDROP_CTRL_MOVE | SV_DRAGDROP_CTRL_COPY |
1398*cdf0e10cSrcweir 		SV_DRAGDROP_APP_MOVE  | SV_DRAGDROP_APP_COPY  | SV_DRAGDROP_APP_DROP );
1399*cdf0e10cSrcweir 	SetEntryHeight( 16 );
1400*cdf0e10cSrcweir 	SetSelectionMode( SINGLE_SELECTION );
1401*cdf0e10cSrcweir     GetModel()->SetSortMode( SortNone );
1402*cdf0e10cSrcweir 
1403*cdf0e10cSrcweir 	EnableContextMenuHandling();
1404*cdf0e10cSrcweir }
1405*cdf0e10cSrcweir 
1406*cdf0e10cSrcweir //-------------------------------------------------------------------------
1407*cdf0e10cSrcweir 
1408*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeListBox_Impl, OnAsyncExecuteDrop, ExecuteDropEvent*, pEvent )
1409*cdf0e10cSrcweir {
1410*cdf0e10cSrcweir 	DBG_ASSERT( pEvent, "invalid DropEvent" );
1411*cdf0e10cSrcweir 	if ( pEvent )
1412*cdf0e10cSrcweir 	{
1413*cdf0e10cSrcweir 		SvLBox* pSourceView = GetSourceView();
1414*cdf0e10cSrcweir 		if ( !pSourceView )
1415*cdf0e10cSrcweir 			pSourceView = pDlg->pSourceView;
1416*cdf0e10cSrcweir         pDlg->bExecDropFinished = false;
1417*cdf0e10cSrcweir 		// if a template can not be moved it should be copied
1418*cdf0e10cSrcweir 		if ( pEvent->mnAction == DND_ACTION_MOVE )
1419*cdf0e10cSrcweir 			pEvent->mnAction = DND_ACTION_COPYMOVE;
1420*cdf0e10cSrcweir         pDlg->nDropAction = SvTreeListBox::ExecuteDrop( *pEvent, pSourceView );
1421*cdf0e10cSrcweir 		delete pEvent;
1422*cdf0e10cSrcweir 		pDlg->pSourceView = NULL;
1423*cdf0e10cSrcweir 		pDlg->pTargetEntry = NULL;
1424*cdf0e10cSrcweir         pDlg->bExecDropFinished = true;
1425*cdf0e10cSrcweir         if ( pDlg->pFinishedBox )
1426*cdf0e10cSrcweir         {
1427*cdf0e10cSrcweir             pDlg->pFinishedBox->DragFinished( pDlg->nDropAction );
1428*cdf0e10cSrcweir             pDlg->pFinishedBox = NULL;
1429*cdf0e10cSrcweir         }
1430*cdf0e10cSrcweir 	}
1431*cdf0e10cSrcweir 	return 0;
1432*cdf0e10cSrcweir }
1433*cdf0e10cSrcweir 
1434*cdf0e10cSrcweir //-------------------------------------------------------------------------
1435*cdf0e10cSrcweir 
1436*cdf0e10cSrcweir void SfxOrganizeListBox_Impl::Reset()
1437*cdf0e10cSrcweir 
1438*cdf0e10cSrcweir /*  [Beschreibung]
1439*cdf0e10cSrcweir 
1440*cdf0e10cSrcweir 	Einf"ugen der Elemente in die ListBox
1441*cdf0e10cSrcweir 
1442*cdf0e10cSrcweir */
1443*cdf0e10cSrcweir 
1444*cdf0e10cSrcweir {
1445*cdf0e10cSrcweir 	DBG_ASSERT( pMgr != 0, "kein Manager" );
1446*cdf0e10cSrcweir 	// Inhalte l"oschen
1447*cdf0e10cSrcweir 	SetUpdateMode(sal_False);
1448*cdf0e10cSrcweir 	Clear();
1449*cdf0e10cSrcweir 	if ( VIEW_TEMPLATES == eViewType )
1450*cdf0e10cSrcweir 	{
1451*cdf0e10cSrcweir 		const sal_uInt16 nCount = pMgr->GetTemplates()->GetRegionCount();
1452*cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < nCount; ++i )
1453*cdf0e10cSrcweir 			InsertEntryByBmpType( pMgr->GetTemplates()->GetFullRegionName(i), BMPTYPE_FOLDER, 0, sal_True );
1454*cdf0e10cSrcweir 	}
1455*cdf0e10cSrcweir 	else
1456*cdf0e10cSrcweir 	{
1457*cdf0e10cSrcweir 		const SfxObjectList& rList = pMgr->GetObjectList();
1458*cdf0e10cSrcweir 		const sal_uInt16 nCount = rList.Count();
1459*cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < nCount; ++i )
1460*cdf0e10cSrcweir 			InsertEntryByBmpType( rList.GetBaseName(i), BMPTYPE_DOC, 0, sal_True );
1461*cdf0e10cSrcweir 
1462*cdf0e10cSrcweir 	}
1463*cdf0e10cSrcweir 	SetUpdateMode(sal_True);
1464*cdf0e10cSrcweir 	Invalidate();
1465*cdf0e10cSrcweir 	Update();
1466*cdf0e10cSrcweir }
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir //-------------------------------------------------------------------------
1469*cdf0e10cSrcweir 
1470*cdf0e10cSrcweir const Image &SfxOrganizeListBox_Impl::GetClosedBmp(sal_uInt16 nLevel) const
1471*cdf0e10cSrcweir 
1472*cdf0e10cSrcweir /*  [Beschreibung]
1473*cdf0e10cSrcweir 
1474*cdf0e10cSrcweir 	Zugriff auf die Bitmap f"ur einen geschlossenen Eintrag
1475*cdf0e10cSrcweir 	der jeweiligen Ebene
1476*cdf0e10cSrcweir 
1477*cdf0e10cSrcweir 	[Parameter]
1478*cdf0e10cSrcweir 
1479*cdf0e10cSrcweir 	sal_uInt16 nLevel       Angabe der Ebene, 2 Ebenen sind erlaubt
1480*cdf0e10cSrcweir 
1481*cdf0e10cSrcweir 	[Returnwert]
1482*cdf0e10cSrcweir 
1483*cdf0e10cSrcweir 	const Image &       das Image auf der Ebenen nLevel
1484*cdf0e10cSrcweir 
1485*cdf0e10cSrcweir */
1486*cdf0e10cSrcweir 
1487*cdf0e10cSrcweir {
1488*cdf0e10cSrcweir 	sal_Bool			bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
1489*cdf0e10cSrcweir 	const Image*	pRet = NULL;
1490*cdf0e10cSrcweir 
1491*cdf0e10cSrcweir 	switch( nLevel )
1492*cdf0e10cSrcweir 	{
1493*cdf0e10cSrcweir 		default:	DBG_ERROR( "Bitmaps ueberindiziert" );
1494*cdf0e10cSrcweir 
1495*cdf0e10cSrcweir 		case 0:		pRet = bHC? &aClosedFolderBmpHC : &aClosedFolderBmp;		break;
1496*cdf0e10cSrcweir 		case 1:		pRet = bHC? &aClosedDocBmpHC : &aClosedDocBmp;				break;
1497*cdf0e10cSrcweir 	}
1498*cdf0e10cSrcweir 
1499*cdf0e10cSrcweir 	return *pRet;
1500*cdf0e10cSrcweir }
1501*cdf0e10cSrcweir 
1502*cdf0e10cSrcweir //-------------------------------------------------------------------------
1503*cdf0e10cSrcweir 
1504*cdf0e10cSrcweir const Image &SfxOrganizeListBox_Impl::GetOpenedBmp(sal_uInt16 nLevel) const
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir /*  [Beschreibung]
1507*cdf0e10cSrcweir 
1508*cdf0e10cSrcweir 	Zugriff auf die Bitmap f"ur einen ge"offneten Eintrag
1509*cdf0e10cSrcweir 	der jeweiligen Ebene
1510*cdf0e10cSrcweir 
1511*cdf0e10cSrcweir 	[Parameter]
1512*cdf0e10cSrcweir 
1513*cdf0e10cSrcweir 	sal_uInt16 nLevel       Angabe der Ebene, 2 Ebenen sind erlaubt
1514*cdf0e10cSrcweir 
1515*cdf0e10cSrcweir 	[Returnwert]
1516*cdf0e10cSrcweir 
1517*cdf0e10cSrcweir 	const Image &       das Image auf der Ebenen nLevel
1518*cdf0e10cSrcweir 
1519*cdf0e10cSrcweir */
1520*cdf0e10cSrcweir 
1521*cdf0e10cSrcweir {
1522*cdf0e10cSrcweir     sal_Bool         bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
1523*cdf0e10cSrcweir     const Image* pRet = NULL;
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir     switch( nLevel )
1526*cdf0e10cSrcweir     {
1527*cdf0e10cSrcweir         case 0:
1528*cdf0e10cSrcweir            pRet = bHC ? &aOpenedFolderBmpHC : &aOpenedFolderBmp; break;
1529*cdf0e10cSrcweir         case 1:
1530*cdf0e10cSrcweir            pRet = bHC ? &aOpenedDocBmpHC : &aOpenedDocBmp; break;
1531*cdf0e10cSrcweir         default:
1532*cdf0e10cSrcweir             pRet = bHC ? &aClosedFolderBmpHC : &aClosedFolderBmp; break;
1533*cdf0e10cSrcweir     }
1534*cdf0e10cSrcweir 
1535*cdf0e10cSrcweir     return *pRet;
1536*cdf0e10cSrcweir }
1537*cdf0e10cSrcweir 
1538*cdf0e10cSrcweir //-------------------------------------------------------------------------
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir PopupMenu* SfxOrganizeListBox_Impl::CreateContextMenu()
1541*cdf0e10cSrcweir {
1542*cdf0e10cSrcweir 	return new PopupMenu( *( pDlg->aEditBtn.GetPopupMenu() ) );
1543*cdf0e10cSrcweir }
1544*cdf0e10cSrcweir 
1545*cdf0e10cSrcweir //-------------------------------------------------------------------------
1546*cdf0e10cSrcweir 
1547*cdf0e10cSrcweir String SfxOrganizeDlg_Impl::GetPath_Impl( sal_Bool bOpen, const String& rFileName )
1548*cdf0e10cSrcweir 
1549*cdf0e10cSrcweir /*  [Beschreibung]
1550*cdf0e10cSrcweir 
1551*cdf0e10cSrcweir 	Pfad per FileDialog erfragen, f"ur Import / Export von
1552*cdf0e10cSrcweir 	Dokumentvorlagen
1553*cdf0e10cSrcweir 
1554*cdf0e10cSrcweir 	[Parameter]
1555*cdf0e10cSrcweir 
1556*cdf0e10cSrcweir 	sal_Bool bOpen                      Flag: "Offnen / Speichern
1557*cdf0e10cSrcweir 	const String& rFileName			aktueller Dateiname als Vorschlag
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir 	[R"uckgabewert]                 Dateiname mit Pfad oder Leerstring, wenn
1560*cdf0e10cSrcweir 									der Benutzer 'Abbrechen' gedr"uckt hat
1561*cdf0e10cSrcweir */
1562*cdf0e10cSrcweir 
1563*cdf0e10cSrcweir {
1564*cdf0e10cSrcweir     String aPath;
1565*cdf0e10cSrcweir     m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
1566*cdf0e10cSrcweir 	sal_Int16 nDialogType = bOpen
1567*cdf0e10cSrcweir         ? com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
1568*cdf0e10cSrcweir         : com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE;
1569*cdf0e10cSrcweir     if ( pFileDlg )
1570*cdf0e10cSrcweir         delete pFileDlg;
1571*cdf0e10cSrcweir     pFileDlg = new sfx2::FileDialogHelper( nDialogType, 0L );
1572*cdf0e10cSrcweir 
1573*cdf0e10cSrcweir 	// add "All" filter
1574*cdf0e10cSrcweir     pFileDlg->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ),
1575*cdf0e10cSrcweir                          DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
1576*cdf0e10cSrcweir 	// add template filter
1577*cdf0e10cSrcweir     String sFilterName( SfxResId( STR_TEMPLATE_FILTER ) );
1578*cdf0e10cSrcweir     String sFilterExt;
1579*cdf0e10cSrcweir     // add filters of modules which are installed
1580*cdf0e10cSrcweir     SvtModuleOptions aModuleOpt;
1581*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1582*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
1583*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
1584*cdf0e10cSrcweir     {
1585*cdf0e10cSrcweir         if ( sFilterExt.Len() > 0 )
1586*cdf0e10cSrcweir             sFilterExt += ';';
1587*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1588*cdf0e10cSrcweir     }
1589*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
1590*cdf0e10cSrcweir     {
1591*cdf0e10cSrcweir         if ( sFilterExt.Len() > 0 )
1592*cdf0e10cSrcweir             sFilterExt += ';';
1593*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1594*cdf0e10cSrcweir     }
1595*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
1596*cdf0e10cSrcweir     {
1597*cdf0e10cSrcweir         if ( sFilterExt.Len() > 0 )
1598*cdf0e10cSrcweir             sFilterExt += ';';
1599*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
1600*cdf0e10cSrcweir     }
1601*cdf0e10cSrcweir     if ( sFilterExt.Len() > 0 )
1602*cdf0e10cSrcweir         sFilterExt += ';';
1603*cdf0e10cSrcweir     sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir     sFilterName += DEFINE_CONST_UNICODE( " (" );
1606*cdf0e10cSrcweir 	sFilterName += sFilterExt;
1607*cdf0e10cSrcweir 	sFilterName += ')';
1608*cdf0e10cSrcweir     pFileDlg->AddFilter( sFilterName, sFilterExt );
1609*cdf0e10cSrcweir     pFileDlg->SetCurrentFilter( sFilterName );
1610*cdf0e10cSrcweir 
1611*cdf0e10cSrcweir     if ( aLastDir.Len() || rFileName.Len() )
1612*cdf0e10cSrcweir 	{
1613*cdf0e10cSrcweir 		INetURLObject aObj;
1614*cdf0e10cSrcweir 		if ( aLastDir.Len() )
1615*cdf0e10cSrcweir 		{
1616*cdf0e10cSrcweir             aObj.SetURL( aLastDir );
1617*cdf0e10cSrcweir 			if ( rFileName.Len() )
1618*cdf0e10cSrcweir 				aObj.insertName( rFileName );
1619*cdf0e10cSrcweir 		}
1620*cdf0e10cSrcweir 		else
1621*cdf0e10cSrcweir             aObj.SetURL( rFileName );
1622*cdf0e10cSrcweir 
1623*cdf0e10cSrcweir         if ( aObj.hasExtension() )
1624*cdf0e10cSrcweir 		{
1625*cdf0e10cSrcweir             m_sExtension4Save = aObj.getExtension(
1626*cdf0e10cSrcweir                 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1627*cdf0e10cSrcweir 			aObj.removeExtension();
1628*cdf0e10cSrcweir 		}
1629*cdf0e10cSrcweir 
1630*cdf0e10cSrcweir 		DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1631*cdf0e10cSrcweir         pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1632*cdf0e10cSrcweir 	}
1633*cdf0e10cSrcweir 
1634*cdf0e10cSrcweir     pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ImportHdl ) );
1635*cdf0e10cSrcweir 
1636*cdf0e10cSrcweir     return aPath;
1637*cdf0e10cSrcweir }
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir //-------------------------------------------------------------------------
1640*cdf0e10cSrcweir 
1641*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString >
1642*cdf0e10cSrcweir     SfxOrganizeDlg_Impl::GetPaths_Impl( const String& rFileName )
1643*cdf0e10cSrcweir 
1644*cdf0e10cSrcweir /*  [Description]
1645*cdf0e10cSrcweir 
1646*cdf0e10cSrcweir    Query plural paths by FileDialog, for Import / Export from document
1647*cdf0e10cSrcweir    templates
1648*cdf0e10cSrcweir 
1649*cdf0e10cSrcweir    [Parameter]
1650*cdf0e10cSrcweir 
1651*cdf0e10cSrcweir    const String& rFileName         The default file name when dialog executes
1652*cdf0e10cSrcweir 
1653*cdf0e10cSrcweir    [Return value]                 Empty sequence when users have clicked
1654*cdf0e10cSrcweir                                   'Cancel', a sequence just containing one
1655*cdf0e10cSrcweir                                   file name with path when they have
1656*cdf0e10cSrcweir                                   choosed one file or a sequence containing
1657*cdf0e10cSrcweir                                   path and file names without path
1658*cdf0e10cSrcweir */
1659*cdf0e10cSrcweir 
1660*cdf0e10cSrcweir {
1661*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
1662*cdf0e10cSrcweir     m_sExtension4Save = DEFINE_CONST_UNICODE( "vor" );
1663*cdf0e10cSrcweir     if ( pFileDlg )
1664*cdf0e10cSrcweir             delete pFileDlg;
1665*cdf0e10cSrcweir     pFileDlg = new sfx2::FileDialogHelper(
1666*cdf0e10cSrcweir 		com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, SFXWB_MULTISELECTION );
1667*cdf0e10cSrcweir 
1668*cdf0e10cSrcweir     // add "All" filter
1669*cdf0e10cSrcweir     pFileDlg->AddFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ),
1670*cdf0e10cSrcweir                          DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL ) );
1671*cdf0e10cSrcweir 
1672*cdf0e10cSrcweir     // add template filter
1673*cdf0e10cSrcweir     String sFilterName( SfxResId( STR_TEMPLATE_FILTER ) );
1674*cdf0e10cSrcweir     String sFilterExt;
1675*cdf0e10cSrcweir     // add filters of modules which are installed
1676*cdf0e10cSrcweir     SvtModuleOptions aModuleOpt;
1677*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1678*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.ott;*.stw;*.oth" );
1679*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
1680*cdf0e10cSrcweir     {
1681*cdf0e10cSrcweir         if ( sFilterExt.Len() > 0 )
1682*cdf0e10cSrcweir             sFilterExt += ';';
1683*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.ots;*.stc" );
1684*cdf0e10cSrcweir     }
1685*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
1686*cdf0e10cSrcweir     {
1687*cdf0e10cSrcweir         if ( sFilterExt.Len() > 0 )
1688*cdf0e10cSrcweir             sFilterExt += ';';
1689*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.otp;*.sti" );
1690*cdf0e10cSrcweir     }
1691*cdf0e10cSrcweir     if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
1692*cdf0e10cSrcweir     {
1693*cdf0e10cSrcweir         if ( sFilterExt.Len() > 0 )
1694*cdf0e10cSrcweir             sFilterExt += ';';
1695*cdf0e10cSrcweir         sFilterExt += DEFINE_CONST_UNICODE( "*.otg;*.std" );
1696*cdf0e10cSrcweir     }
1697*cdf0e10cSrcweir     if ( sFilterExt.Len() > 0 )
1698*cdf0e10cSrcweir         sFilterExt += ';';
1699*cdf0e10cSrcweir     sFilterExt += DEFINE_CONST_UNICODE( "*.vor" );
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir     sFilterName += DEFINE_CONST_UNICODE( " (" );
1702*cdf0e10cSrcweir     sFilterName += sFilterExt;
1703*cdf0e10cSrcweir     sFilterName += ')';
1704*cdf0e10cSrcweir     pFileDlg->AddFilter( sFilterName, sFilterExt );
1705*cdf0e10cSrcweir     pFileDlg->SetCurrentFilter( sFilterName );
1706*cdf0e10cSrcweir 
1707*cdf0e10cSrcweir     if ( aLastDir.Len() || rFileName.Len() )
1708*cdf0e10cSrcweir     {
1709*cdf0e10cSrcweir         INetURLObject aObj;
1710*cdf0e10cSrcweir         if ( aLastDir.Len() )
1711*cdf0e10cSrcweir         {
1712*cdf0e10cSrcweir             aObj.SetURL( aLastDir );
1713*cdf0e10cSrcweir             if ( rFileName.Len() )
1714*cdf0e10cSrcweir                 aObj.insertName( rFileName );
1715*cdf0e10cSrcweir         }
1716*cdf0e10cSrcweir         else
1717*cdf0e10cSrcweir             aObj.SetURL( rFileName );
1718*cdf0e10cSrcweir 
1719*cdf0e10cSrcweir         if ( aObj.hasExtension() )
1720*cdf0e10cSrcweir         {
1721*cdf0e10cSrcweir             m_sExtension4Save = aObj.getExtension(
1722*cdf0e10cSrcweir                  INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1723*cdf0e10cSrcweir             aObj.removeExtension();
1724*cdf0e10cSrcweir         }
1725*cdf0e10cSrcweir 
1726*cdf0e10cSrcweir         DBG_ASSERT( aObj.GetProtocol() != INET_PROT_NOT_VALID, "Invalid URL!" );
1727*cdf0e10cSrcweir         pFileDlg->SetDisplayDirectory( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
1728*cdf0e10cSrcweir     }
1729*cdf0e10cSrcweir 
1730*cdf0e10cSrcweir     pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, ExportHdl ) );
1731*cdf0e10cSrcweir 
1732*cdf0e10cSrcweir     return aPaths;
1733*cdf0e10cSrcweir }
1734*cdf0e10cSrcweir 
1735*cdf0e10cSrcweir //-------------------------------------------------------------------------
1736*cdf0e10cSrcweir 
1737*cdf0e10cSrcweir sal_Bool SfxOrganizeDlg_Impl::DontDelete_Impl( SvLBoxEntry* pEntry )
1738*cdf0e10cSrcweir {
1739*cdf0e10cSrcweir 	sal_uInt16 nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
1740*cdf0e10cSrcweir 	if(SfxOrganizeListBox_Impl::VIEW_FILES ==
1741*cdf0e10cSrcweir 	   pFocusBox->GetViewType())
1742*cdf0e10cSrcweir 		nDepth++;
1743*cdf0e10cSrcweir 	if( (nDepth > 2 && !pEntry->GetUserData()) ||
1744*cdf0e10cSrcweir 	   //Delete ueber GetContent verboten
1745*cdf0e10cSrcweir 	   nDepth==2 || //Vorlage / Konfigurtionsrubrik nicht loeshcen
1746*cdf0e10cSrcweir 	   (nDepth==1 && SfxOrganizeListBox_Impl::VIEW_FILES ==
1747*cdf0e10cSrcweir 		pFocusBox->GetViewType()) || //Files nicht loeschen
1748*cdf0e10cSrcweir 	   (0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2))
1749*cdf0e10cSrcweir 		//Mindestens eine Vorlage behalten
1750*cdf0e10cSrcweir 	{
1751*cdf0e10cSrcweir 		return sal_True;
1752*cdf0e10cSrcweir 	}
1753*cdf0e10cSrcweir 
1754*cdf0e10cSrcweir 	sal_uInt16 nRegion = 0, nIndex = 0;
1755*cdf0e10cSrcweir 	GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
1756*cdf0e10cSrcweir     const SfxDocumentTemplates* pTemplates = aMgr.GetTemplates();
1757*cdf0e10cSrcweir 	if ( !pTemplates || !pTemplates->HasUserContents( nRegion, nIndex ) )
1758*cdf0e10cSrcweir 		return sal_True;
1759*cdf0e10cSrcweir 
1760*cdf0e10cSrcweir 	return sal_False;
1761*cdf0e10cSrcweir }
1762*cdf0e10cSrcweir 
1763*cdf0e10cSrcweir SvStringsDtor* SfxOrganizeDlg_Impl::GetAllFactoryURLs_Impl( ) const
1764*cdf0e10cSrcweir {
1765*cdf0e10cSrcweir 	SvtModuleOptions aModOpt;
1766*cdf0e10cSrcweir 	const ::com::sun::star::uno::Sequence < ::rtl::OUString >& aServiceNames = aModOpt.GetAllServiceNames() ;
1767*cdf0e10cSrcweir     SvStringsDtor* pList = new SvStringsDtor;
1768*cdf0e10cSrcweir 	sal_Int32 nCount = aServiceNames.getLength();
1769*cdf0e10cSrcweir     for( sal_Int32 i=0; i<nCount; ++i )
1770*cdf0e10cSrcweir     {
1771*cdf0e10cSrcweir 		if ( SfxObjectFactory::GetStandardTemplate( aServiceNames[i] ).Len() > 0 )
1772*cdf0e10cSrcweir 		{
1773*cdf0e10cSrcweir 			SvtModuleOptions::EFactory eFac = SvtModuleOptions::E_WRITER;
1774*cdf0e10cSrcweir 			SvtModuleOptions::ClassifyFactoryByName( aServiceNames[i], eFac );
1775*cdf0e10cSrcweir 			String* pURL = new String( aModOpt.GetFactoryEmptyDocumentURL( eFac ) );
1776*cdf0e10cSrcweir 	        pList->Insert( pURL, pList->Count() );
1777*cdf0e10cSrcweir 		}
1778*cdf0e10cSrcweir     }
1779*cdf0e10cSrcweir 
1780*cdf0e10cSrcweir     return pList;
1781*cdf0e10cSrcweir }
1782*cdf0e10cSrcweir 
1783*cdf0e10cSrcweir sal_Bool SfxOrganizeDlg_Impl::GetServiceName_Impl( String& rName, String& rFileURL ) const
1784*cdf0e10cSrcweir {
1785*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1786*cdf0e10cSrcweir 	const SfxDocumentTemplates*	pTemplates = aMgr.GetTemplates();
1787*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pFocusBox ? pFocusBox->FirstSelected() : NULL;
1788*cdf0e10cSrcweir 	sal_uInt16 nRegion = 0, nIndex = 0;
1789*cdf0e10cSrcweir 	GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
1790*cdf0e10cSrcweir 	rFileURL = pTemplates->GetPath( nRegion, nIndex );
1791*cdf0e10cSrcweir 	if ( rFileURL.Len() > 0 )
1792*cdf0e10cSrcweir 	{
1793*cdf0e10cSrcweir         try
1794*cdf0e10cSrcweir         {
1795*cdf0e10cSrcweir             uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
1796*cdf0e10cSrcweir                                                     rFileURL,
1797*cdf0e10cSrcweir                                                     embed::ElementModes::READ );
1798*cdf0e10cSrcweir             sal_uIntPtr nFormat = SotStorage::GetFormatID( xStorage );
1799*cdf0e10cSrcweir             const SfxFilter* pFilter =
1800*cdf0e10cSrcweir                 SFX_APP()->GetFilterMatcher().GetFilter4ClipBoardId( nFormat );
1801*cdf0e10cSrcweir             if ( pFilter )
1802*cdf0e10cSrcweir             {
1803*cdf0e10cSrcweir                 rName = pFilter->GetServiceName();
1804*cdf0e10cSrcweir                 bRet = sal_True;
1805*cdf0e10cSrcweir             }
1806*cdf0e10cSrcweir 		}
1807*cdf0e10cSrcweir 		catch( uno::Exception& )
1808*cdf0e10cSrcweir 		{}
1809*cdf0e10cSrcweir 	}
1810*cdf0e10cSrcweir 
1811*cdf0e10cSrcweir 	return bRet;
1812*cdf0e10cSrcweir }
1813*cdf0e10cSrcweir 
1814*cdf0e10cSrcweir long SfxOrganizeDlg_Impl::Dispatch_Impl( sal_uInt16 nId, Menu* _pMenu )
1815*cdf0e10cSrcweir 
1816*cdf0e10cSrcweir /*  [Beschreibung]
1817*cdf0e10cSrcweir 
1818*cdf0e10cSrcweir 	Verarbeiten der Events aus MenuButton oder Accelerator
1819*cdf0e10cSrcweir 
1820*cdf0e10cSrcweir 	[Parameter]
1821*cdf0e10cSrcweir 
1822*cdf0e10cSrcweir 	sal_uInt16 nId                      ID des Events
1823*cdf0e10cSrcweir 
1824*cdf0e10cSrcweir 	[R"uckgabewert]                 1: Event wurde verarbeitet,
1825*cdf0e10cSrcweir 									0: Event wurde nicht verarbeitet (SV-Menu)
1826*cdf0e10cSrcweir 
1827*cdf0e10cSrcweir */
1828*cdf0e10cSrcweir 
1829*cdf0e10cSrcweir {
1830*cdf0e10cSrcweir 	SuspendAccel aTmp(&aEditAcc);
1831*cdf0e10cSrcweir 	SvLBoxEntry *pEntry = pFocusBox? pFocusBox->FirstSelected(): 0;
1832*cdf0e10cSrcweir 	sal_Bool bHandled = sal_True;
1833*cdf0e10cSrcweir 	switch(nId)
1834*cdf0e10cSrcweir 	{
1835*cdf0e10cSrcweir 		case ID_NEW:
1836*cdf0e10cSrcweir 		{
1837*cdf0e10cSrcweir 			if(!pEntry)
1838*cdf0e10cSrcweir 				return 1;
1839*cdf0e10cSrcweir 			if(pFocusBox->GetViewType() == SfxOrganizeListBox_Impl::VIEW_TEMPLATES)
1840*cdf0e10cSrcweir 			{
1841*cdf0e10cSrcweir 				if(0 == pFocusBox->GetModel()->GetDepth(pEntry))
1842*cdf0e10cSrcweir 				{
1843*cdf0e10cSrcweir 					const String aNoName( SfxResId(STR_NONAME) );
1844*cdf0e10cSrcweir 					SvLBoxEntry* pParent = pFocusBox->GetParent(pEntry);
1845*cdf0e10cSrcweir 					String aName(aNoName);
1846*cdf0e10cSrcweir 					sal_uInt16 n = 1;
1847*cdf0e10cSrcweir 					while(!pFocusBox->IsUniqName_Impl(aName, pParent))
1848*cdf0e10cSrcweir 					{
1849*cdf0e10cSrcweir 						aName = aNoName;
1850*cdf0e10cSrcweir 						aName += String::CreateFromInt32( n++ );
1851*cdf0e10cSrcweir 					}
1852*cdf0e10cSrcweir 					aMgr.InsertDir( pFocusBox, aName,
1853*cdf0e10cSrcweir 							(sal_uInt16)pFocusBox->GetModel()->GetRelPos(pEntry)+1);
1854*cdf0e10cSrcweir 				}
1855*cdf0e10cSrcweir 			}
1856*cdf0e10cSrcweir 			break;
1857*cdf0e10cSrcweir 		}
1858*cdf0e10cSrcweir 
1859*cdf0e10cSrcweir 		case ID_DELETE:
1860*cdf0e10cSrcweir 		{
1861*cdf0e10cSrcweir 			if(!pEntry || DontDelete_Impl(pEntry))
1862*cdf0e10cSrcweir 				return 1;
1863*cdf0e10cSrcweir 			const sal_uInt16 nDepth = pFocusBox->GetModel()->GetDepth(pEntry);
1864*cdf0e10cSrcweir 			if(nDepth < 2)
1865*cdf0e10cSrcweir 			{
1866*cdf0e10cSrcweir 				if(0 == nDepth && pFocusBox->GetLevelCount_Impl(0) < 2) return 1;
1867*cdf0e10cSrcweir                 if(SfxOrganizeListBox_Impl::VIEW_TEMPLATES == pFocusBox->GetViewType())
1868*cdf0e10cSrcweir 				{
1869*cdf0e10cSrcweir 					sal_uInt16 nResId = nDepth? STR_DELETE_TEMPLATE :
1870*cdf0e10cSrcweir 											STR_DELETE_REGION;
1871*cdf0e10cSrcweir 					if( !QueryDelete_Impl(
1872*cdf0e10cSrcweir 						pDialog, nResId, pFocusBox->GetEntryText(pEntry)))
1873*cdf0e10cSrcweir 						return 1;
1874*cdf0e10cSrcweir 					if ( STR_DELETE_REGION == nResId &&
1875*cdf0e10cSrcweir 						 pFocusBox->GetChildCount(pEntry))
1876*cdf0e10cSrcweir 					{
1877*cdf0e10cSrcweir 						QueryBox aQBox(pDialog, SfxResId(MSG_REGION_NOTEMPTY));
1878*cdf0e10cSrcweir 						if(RET_NO == aQBox.Execute())
1879*cdf0e10cSrcweir 							return 1;
1880*cdf0e10cSrcweir 					}
1881*cdf0e10cSrcweir 					sal_uInt16 nRegion = 0, nIndex = 0;
1882*cdf0e10cSrcweir 					GetIndices_Impl(pFocusBox, pEntry, nRegion, nIndex);
1883*cdf0e10cSrcweir 
1884*cdf0e10cSrcweir 					sal_uInt16 nDeleteInd = ( STR_DELETE_REGION == nResId? USHRT_MAX: nIndex );
1885*cdf0e10cSrcweir 					if ( !aMgr.Delete( pFocusBox, nRegion, nDeleteInd ) )
1886*cdf0e10cSrcweir 						ErrorDelete_Impl(
1887*cdf0e10cSrcweir 							pDialog,
1888*cdf0e10cSrcweir 							pFocusBox->GetEntryText(pEntry),
1889*cdf0e10cSrcweir 							( nDeleteInd == USHRT_MAX && pFocusBox->GetChildCount(pEntry) ) );
1890*cdf0e10cSrcweir 				}
1891*cdf0e10cSrcweir 			}
1892*cdf0e10cSrcweir 			// Inhaltsformen
1893*cdf0e10cSrcweir 			else if(nDepth + pFocusBox->GetDocLevel() >= 2)
1894*cdf0e10cSrcweir 			{
1895*cdf0e10cSrcweir 				if(!QueryDelete_Impl(pDialog, STR_DELETE_TEMPLATE, pFocusBox->GetEntryText(pEntry)))
1896*cdf0e10cSrcweir 					return 1;
1897*cdf0e10cSrcweir 				Path aPath(pFocusBox, pEntry);
1898*cdf0e10cSrcweir 
1899*cdf0e10cSrcweir                 // it is ok to use the SfxObjectShellRef here since the object that
1900*cdf0e10cSrcweir                 // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
1901*cdf0e10cSrcweir 				SfxObjectShellRef aRef = pFocusBox->GetObjectShell(aPath);
1902*cdf0e10cSrcweir 				if(aRef.Is() &&
1903*cdf0e10cSrcweir 					aRef->Remove(aPath[1+pFocusBox->GetDocLevel()],
1904*cdf0e10cSrcweir 								 aPath[2+pFocusBox->GetDocLevel()],
1905*cdf0e10cSrcweir 								 aPath[3+pFocusBox->GetDocLevel()]))
1906*cdf0e10cSrcweir 					pFocusBox->GetModel()->Remove(pEntry);
1907*cdf0e10cSrcweir 				else
1908*cdf0e10cSrcweir 					ErrorDelete_Impl(pDialog, pFocusBox->GetEntryText(pEntry), sal_False );
1909*cdf0e10cSrcweir 			}
1910*cdf0e10cSrcweir 			break;
1911*cdf0e10cSrcweir 		}
1912*cdf0e10cSrcweir 
1913*cdf0e10cSrcweir 		case ID_EDIT:
1914*cdf0e10cSrcweir 		{
1915*cdf0e10cSrcweir 			if(!pEntry)
1916*cdf0e10cSrcweir 				return 1;
1917*cdf0e10cSrcweir 			sal_uInt16 nRegion = 0, nIndex = 0;
1918*cdf0e10cSrcweir 			GetIndices_Impl( pFocusBox, pEntry, nRegion, nIndex );
1919*cdf0e10cSrcweir 			const SfxStringItem aName( SID_FILE_NAME, aMgr.GetTemplates()->GetPath( nRegion, nIndex ) );
1920*cdf0e10cSrcweir 			const SfxStringItem aLongName( SID_FILE_LONGNAME, pFocusBox->GetEntryText( pEntry ) );
1921*cdf0e10cSrcweir 			const SfxStringItem aReferer( SID_REFERER, DEFINE_CONST_UNICODE( "private:user" ) );
1922*cdf0e10cSrcweir 			const SfxStringItem aTargetName( SID_TARGETNAME, DEFINE_CONST_UNICODE( "_default" ) );
1923*cdf0e10cSrcweir 			const SfxBoolItem	aTemplateIndicator( SID_TEMPLATE, sal_False );
1924*cdf0e10cSrcweir 
1925*cdf0e10cSrcweir             SFX_APP()->GetAppDispatcher_Impl()->Execute( SID_OPENTEMPLATE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
1926*cdf0e10cSrcweir 									  &aName, &aLongName, &aReferer, &aTargetName, &aTemplateIndicator, 0L );
1927*cdf0e10cSrcweir 			pDialog->EndDialog( RET_EDIT_STYLE );
1928*cdf0e10cSrcweir 			break;
1929*cdf0e10cSrcweir 		}
1930*cdf0e10cSrcweir 
1931*cdf0e10cSrcweir 		case ID_COPY_FROM:
1932*cdf0e10cSrcweir 		{
1933*cdf0e10cSrcweir 			if ( !pEntry )
1934*cdf0e10cSrcweir 				return 1;
1935*cdf0e10cSrcweir             m_nRegion = 0;
1936*cdf0e10cSrcweir             m_nIndex = 0;
1937*cdf0e10cSrcweir             GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
1938*cdf0e10cSrcweir             GetPaths_Impl( String() );
1939*cdf0e10cSrcweir 			break;
1940*cdf0e10cSrcweir 		}
1941*cdf0e10cSrcweir 
1942*cdf0e10cSrcweir 		case ID_COPY_TO:
1943*cdf0e10cSrcweir 		{
1944*cdf0e10cSrcweir 			if ( !pEntry )
1945*cdf0e10cSrcweir 				return 1;
1946*cdf0e10cSrcweir             m_nRegion = 0;
1947*cdf0e10cSrcweir             m_nIndex = 0;
1948*cdf0e10cSrcweir             GetIndices_Impl( pFocusBox, pEntry, m_nRegion, m_nIndex );
1949*cdf0e10cSrcweir             GetPath_Impl( sal_False, aMgr.GetTemplates()->GetFileName( m_nRegion, m_nIndex ) );
1950*cdf0e10cSrcweir 			break;
1951*cdf0e10cSrcweir 		}
1952*cdf0e10cSrcweir 
1953*cdf0e10cSrcweir 		case ID_RESCAN:
1954*cdf0e10cSrcweir 			if ( !aMgr.Rescan() )
1955*cdf0e10cSrcweir 				ErrorBox( pDialog, SfxResId( MSG_ERROR_RESCAN ) ).Execute();
1956*cdf0e10cSrcweir 			if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aLeftLb.GetViewType() )
1957*cdf0e10cSrcweir 				aLeftLb.Reset();
1958*cdf0e10cSrcweir 			if ( SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aRightLb.GetViewType() )
1959*cdf0e10cSrcweir 				aRightLb.Reset();
1960*cdf0e10cSrcweir 			break;
1961*cdf0e10cSrcweir 
1962*cdf0e10cSrcweir 		case ID_PRINT:
1963*cdf0e10cSrcweir 		{
1964*cdf0e10cSrcweir 			if ( !pEntry )
1965*cdf0e10cSrcweir 				return 1;
1966*cdf0e10cSrcweir 			Path aPath( pFocusBox, pEntry );
1967*cdf0e10cSrcweir 
1968*cdf0e10cSrcweir             // it is ok to use the SfxObjectShellRef here since the object that
1969*cdf0e10cSrcweir             // provides it ( GetObjectShell() calls CreateObjectShell() ) has a lock on it
1970*cdf0e10cSrcweir 			SfxObjectShellRef aRef = pFocusBox->GetObjectShell( aPath );
1971*cdf0e10cSrcweir 			if ( aRef.Is() )
1972*cdf0e10cSrcweir 			{
1973*cdf0e10cSrcweir 				const sal_uInt16 nDocLevel = pFocusBox->GetDocLevel();
1974*cdf0e10cSrcweir 				if ( !pPrt )
1975*cdf0e10cSrcweir 					pPrt = new Printer;
1976*cdf0e10cSrcweir 				SvLBoxEntry *pDocEntry = pEntry;
1977*cdf0e10cSrcweir 				while ( pFocusBox->GetModel()->GetDepth( pDocEntry ) > nDocLevel )
1978*cdf0e10cSrcweir 					pDocEntry = pFocusBox->GetParent( pDocEntry );
1979*cdf0e10cSrcweir 				const String aName(pFocusBox->GetEntryText(pDocEntry));
1980*cdf0e10cSrcweir 				if ( !aRef->Print( *pPrt, aPath[1+nDocLevel],
1981*cdf0e10cSrcweir 								   aPath[2+nDocLevel], aPath[3+nDocLevel], &aName ) )
1982*cdf0e10cSrcweir 					ErrorBox( pDialog, SfxResId( MSG_PRINT_ERROR ) ).Execute();
1983*cdf0e10cSrcweir 			}
1984*cdf0e10cSrcweir 			break;
1985*cdf0e10cSrcweir 		}
1986*cdf0e10cSrcweir 
1987*cdf0e10cSrcweir 		case ID_PRINTER_SETUP:
1988*cdf0e10cSrcweir 		{
1989*cdf0e10cSrcweir 			PrinterSetupDialog* pDlg = new PrinterSetupDialog( pDialog );
1990*cdf0e10cSrcweir 			if ( !pPrt )
1991*cdf0e10cSrcweir 				pPrt = new Printer;
1992*cdf0e10cSrcweir 			pDlg->SetPrinter( pPrt );
1993*cdf0e10cSrcweir 			pDlg->Execute();
1994*cdf0e10cSrcweir 			delete pDlg;
1995*cdf0e10cSrcweir 			break;
1996*cdf0e10cSrcweir 		}
1997*cdf0e10cSrcweir 
1998*cdf0e10cSrcweir 		case ID_DEFAULT_TEMPLATE:
1999*cdf0e10cSrcweir 		{
2000*cdf0e10cSrcweir 			String aServiceName, aFileURL;
2001*cdf0e10cSrcweir 			if ( GetServiceName_Impl( aServiceName, aFileURL ) )
2002*cdf0e10cSrcweir 				SfxObjectFactory::SetStandardTemplate( aServiceName, aFileURL );
2003*cdf0e10cSrcweir 			break;
2004*cdf0e10cSrcweir 		}
2005*cdf0e10cSrcweir 
2006*cdf0e10cSrcweir 		default:
2007*cdf0e10cSrcweir 			bHandled = sal_False;
2008*cdf0e10cSrcweir 	}
2009*cdf0e10cSrcweir 
2010*cdf0e10cSrcweir 	if ( !bHandled && ( nId > ID_RESET_DEFAULT_TEMPLATE || nId <= ID_RESET_DEFAULT_TEMPLATE_END ) )
2011*cdf0e10cSrcweir 	{
2012*cdf0e10cSrcweir 		Menu* pSubMenu = _pMenu ? _pMenu : aEditBtn.GetPopupMenu()->GetPopupMenu( ID_RESET_DEFAULT_TEMPLATE );
2013*cdf0e10cSrcweir 		if ( pSubMenu )
2014*cdf0e10cSrcweir 		{
2015*cdf0e10cSrcweir 			String aServiceName = SfxObjectShell::GetServiceNameFromFactory( pSubMenu->GetItemCommand( nId ) );
2016*cdf0e10cSrcweir 			SfxObjectFactory::SetStandardTemplate( aServiceName, String() );
2017*cdf0e10cSrcweir 			bHandled = sal_True;
2018*cdf0e10cSrcweir 		}
2019*cdf0e10cSrcweir 	}
2020*cdf0e10cSrcweir 
2021*cdf0e10cSrcweir 	return bHandled ? 1 : 0;
2022*cdf0e10cSrcweir }
2023*cdf0e10cSrcweir 
2024*cdf0e10cSrcweir //-------------------------------------------------------------------------
2025*cdf0e10cSrcweir 
2026*cdf0e10cSrcweir IMPL_LINK_INLINE_START( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
2027*cdf0e10cSrcweir 
2028*cdf0e10cSrcweir /*  [Beschreibung]
2029*cdf0e10cSrcweir 
2030*cdf0e10cSrcweir 	SelectHandler des Men"us des Men"ubuttons (SV)
2031*cdf0e10cSrcweir 
2032*cdf0e10cSrcweir 	[Parameter]
2033*cdf0e10cSrcweir 
2034*cdf0e10cSrcweir 	MenuButton *pBtn                der das Event ausl"osende Button
2035*cdf0e10cSrcweir 
2036*cdf0e10cSrcweir 	[R"uckgabewert]                 1: Event wurde verarbeitet,
2037*cdf0e10cSrcweir 									0: Event wurde nicht verarbeitet (SV-Menu)
2038*cdf0e10cSrcweir 
2039*cdf0e10cSrcweir */
2040*cdf0e10cSrcweir {
2041*cdf0e10cSrcweir 	return Dispatch_Impl( pMenu->GetCurItemId(), pMenu );
2042*cdf0e10cSrcweir }
2043*cdf0e10cSrcweir IMPL_LINK_INLINE_END( SfxOrganizeDlg_Impl, MenuSelect_Impl, Menu *, pMenu )
2044*cdf0e10cSrcweir 
2045*cdf0e10cSrcweir //-------------------------------------------------------------------------
2046*cdf0e10cSrcweir 
2047*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, AccelSelect_Impl, Accelerator *, pAccel )
2048*cdf0e10cSrcweir 
2049*cdf0e10cSrcweir /*  [Beschreibung]
2050*cdf0e10cSrcweir 
2051*cdf0e10cSrcweir 	SelectHandler des Accelerators (SV)
2052*cdf0e10cSrcweir 
2053*cdf0e10cSrcweir 	[Parameter]
2054*cdf0e10cSrcweir 
2055*cdf0e10cSrcweir 	Accelerator *pAccel             der das Event ausl"osende Accelerator
2056*cdf0e10cSrcweir 
2057*cdf0e10cSrcweir 	[R"uckgabewert]                 1: Event wurde verarbeitet,
2058*cdf0e10cSrcweir 									0: Event wurde nicht verarbeitet (SV)
2059*cdf0e10cSrcweir 
2060*cdf0e10cSrcweir */
2061*cdf0e10cSrcweir 
2062*cdf0e10cSrcweir {
2063*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pFocusBox && pFocusBox->GetSelectionCount() ?
2064*cdf0e10cSrcweir 		pFocusBox->FirstSelected() : NULL ;
2065*cdf0e10cSrcweir 	return pEntry && ( pAccel->GetCurItemId() == ID_NEW  || !DontDelete_Impl( pEntry ) ) ?
2066*cdf0e10cSrcweir 		Dispatch_Impl( pAccel->GetCurItemId(), NULL ) : 0;
2067*cdf0e10cSrcweir }
2068*cdf0e10cSrcweir 
2069*cdf0e10cSrcweir //-------------------------------------------------------------------------
2070*cdf0e10cSrcweir 
2071*cdf0e10cSrcweir void SfxOrganizeDlg_Impl::OkHdl(Button *pButton)
2072*cdf0e10cSrcweir {
2073*cdf0e10cSrcweir 	if(pFocusBox && pFocusBox->IsEditingActive())
2074*cdf0e10cSrcweir 		pFocusBox->EndEditing(sal_False);
2075*cdf0e10cSrcweir 	pButton->Click();
2076*cdf0e10cSrcweir }
2077*cdf0e10cSrcweir 
2078*cdf0e10cSrcweir 
2079*cdf0e10cSrcweir 
2080*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, MenuActivate_Impl, Menu *, pMenu )
2081*cdf0e10cSrcweir 
2082*cdf0e10cSrcweir /*  [Beschreibung]
2083*cdf0e10cSrcweir 
2084*cdf0e10cSrcweir 	ActivateHandler des Men"us des Men"ubuttons (SV)
2085*cdf0e10cSrcweir 
2086*cdf0e10cSrcweir 	[Parameter]
2087*cdf0e10cSrcweir 
2088*cdf0e10cSrcweir 	Menu *pMenu                     das das Event ausl"osende Men"u
2089*cdf0e10cSrcweir 
2090*cdf0e10cSrcweir 	[R"uckgabewert]                 1: Event wurde verarbeitet,
2091*cdf0e10cSrcweir 									0: Event wurde nicht verarbeitet (SV-Menu)
2092*cdf0e10cSrcweir 
2093*cdf0e10cSrcweir */
2094*cdf0e10cSrcweir {
2095*cdf0e10cSrcweir 	if ( pFocusBox && pFocusBox->IsEditingActive() )
2096*cdf0e10cSrcweir 		pFocusBox->EndEditing( sal_False );
2097*cdf0e10cSrcweir 	sal_Bool bEnable = ( pFocusBox && pFocusBox->GetSelectionCount() );
2098*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = bEnable ? pFocusBox->FirstSelected() : NULL;
2099*cdf0e10cSrcweir 	const sal_uInt16 nDepth =
2100*cdf0e10cSrcweir 		( bEnable && pFocusBox->GetSelectionCount() ) ? pFocusBox->GetModel()->GetDepth( pEntry ) : 0;
2101*cdf0e10cSrcweir 	const sal_uInt16 nDocLevel = bEnable ? pFocusBox->GetDocLevel() : 0;
2102*cdf0e10cSrcweir 	int eVT = pFocusBox ? pFocusBox->GetViewType() : 0;
2103*cdf0e10cSrcweir 		// nur Vorlagen anlegen
2104*cdf0e10cSrcweir 	pMenu->EnableItem( ID_NEW, bEnable && 0 == nDepth && SfxOrganizeListBox_Impl::VIEW_TEMPLATES == eVT );
2105*cdf0e10cSrcweir 	// Vorlagen: Loeschen Ebene 0,1,3ff
2106*cdf0e10cSrcweir 	//           ein Bereich mu"s mindestens erhalten bleiben
2107*cdf0e10cSrcweir 	// Dateien : Loeschen Ebene > 2
2108*cdf0e10cSrcweir 
2109*cdf0e10cSrcweir 	pMenu->EnableItem( ID_DELETE, bEnable && !DontDelete_Impl( pEntry ) );
2110*cdf0e10cSrcweir 	pMenu->EnableItem( ID_EDIT,
2111*cdf0e10cSrcweir 					   bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel
2112*cdf0e10cSrcweir 					       && !DontDelete_Impl( pEntry ) );
2113*cdf0e10cSrcweir 	pMenu->EnableItem( ID_COPY_FROM,
2114*cdf0e10cSrcweir 					   bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
2115*cdf0e10cSrcweir 					   ( nDepth == nDocLevel || nDepth == nDocLevel - 1 ) );
2116*cdf0e10cSrcweir 	pMenu->EnableItem( ID_COPY_TO,
2117*cdf0e10cSrcweir 					   bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES &&
2118*cdf0e10cSrcweir 					   nDepth == nDocLevel );
2119*cdf0e10cSrcweir 	pMenu->EnableItem( ID_RESCAN,
2120*cdf0e10cSrcweir 					   SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aRightLb.GetViewType() ||
2121*cdf0e10cSrcweir 					   SfxOrganizeListBox_Impl::VIEW_TEMPLATES == aLeftLb.GetViewType() );
2122*cdf0e10cSrcweir 	sal_Bool bPrint = bEnable && nDepth > pFocusBox->GetDocLevel();
2123*cdf0e10cSrcweir 	if ( bPrint && pPrt )
2124*cdf0e10cSrcweir 		bPrint = !pPrt->IsPrinting() && !pPrt->IsJobActive();
2125*cdf0e10cSrcweir 	if ( bPrint && bEnable )
2126*cdf0e10cSrcweir 	{
2127*cdf0e10cSrcweir 		// only styles printable
2128*cdf0e10cSrcweir 		Path aPath( pFocusBox, pFocusBox->FirstSelected() );
2129*cdf0e10cSrcweir 		sal_uInt16 nIndex = aPath[ nDocLevel + 1 ];
2130*cdf0e10cSrcweir 		bPrint = ( nIndex == CONTENT_STYLE );
2131*cdf0e10cSrcweir 				}
2132*cdf0e10cSrcweir 	pMenu->EnableItem( ID_PRINT, bPrint );
2133*cdf0e10cSrcweir 
2134*cdf0e10cSrcweir 	if ( bEnable && eVT == SfxOrganizeListBox_Impl::VIEW_TEMPLATES && nDepth == nDocLevel )
2135*cdf0e10cSrcweir 	{
2136*cdf0e10cSrcweir 		String aFactoryURL, aFileURL;
2137*cdf0e10cSrcweir 		bEnable = GetServiceName_Impl( aFactoryURL, aFileURL );
2138*cdf0e10cSrcweir 	}
2139*cdf0e10cSrcweir 	else if ( bEnable )
2140*cdf0e10cSrcweir 		bEnable = sal_False;
2141*cdf0e10cSrcweir 	pMenu->EnableItem( ID_DEFAULT_TEMPLATE, bEnable );
2142*cdf0e10cSrcweir 
2143*cdf0e10cSrcweir 	bEnable = sal_True;
2144*cdf0e10cSrcweir 	SvStringsDtor* pList = GetAllFactoryURLs_Impl();
2145*cdf0e10cSrcweir 	sal_uInt16 nCount = pList->Count();
2146*cdf0e10cSrcweir 	if ( nCount > 0 )
2147*cdf0e10cSrcweir 	{
2148*cdf0e10cSrcweir 		PopupMenu* pSubMenu = new PopupMenu;
2149*cdf0e10cSrcweir 		sal_uInt16 nItemId = ID_RESET_DEFAULT_TEMPLATE + 1;
2150*cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < nCount; ++i )
2151*cdf0e10cSrcweir 		{
2152*cdf0e10cSrcweir 			String aObjFacURL( *pList->GetObject(i) );
2153*cdf0e10cSrcweir 			String aTitle = SvFileInformationManager::GetDescription(
2154*cdf0e10cSrcweir 				INetURLObject(aObjFacURL) );
2155*cdf0e10cSrcweir 			pSubMenu->InsertItem( nItemId, aTitle,
2156*cdf0e10cSrcweir 				SvFileInformationManager::GetImage(INetURLObject(aObjFacURL)) );
2157*cdf0e10cSrcweir 			pSubMenu->SetItemCommand( nItemId++, aObjFacURL );
2158*cdf0e10cSrcweir 			DBG_ASSERT( nItemId <= ID_RESET_DEFAULT_TEMPLATE_END, "menu item id overflow" );
2159*cdf0e10cSrcweir 		}
2160*cdf0e10cSrcweir 		pMenu->SetPopupMenu( ID_RESET_DEFAULT_TEMPLATE, pSubMenu );
2161*cdf0e10cSrcweir 	}
2162*cdf0e10cSrcweir 	else
2163*cdf0e10cSrcweir 		bEnable = sal_False;
2164*cdf0e10cSrcweir 
2165*cdf0e10cSrcweir 	delete pList;
2166*cdf0e10cSrcweir 	pMenu->EnableItem( ID_RESET_DEFAULT_TEMPLATE, bEnable );
2167*cdf0e10cSrcweir 
2168*cdf0e10cSrcweir 	return 1;
2169*cdf0e10cSrcweir }
2170*cdf0e10cSrcweir 
2171*cdf0e10cSrcweir //-------------------------------------------------------------------------
2172*cdf0e10cSrcweir 
2173*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, GetFocus_Impl, SfxOrganizeListBox_Impl *, pBox )
2174*cdf0e10cSrcweir 
2175*cdf0e10cSrcweir /*  [Beschreibung]
2176*cdf0e10cSrcweir 
2177*cdf0e10cSrcweir 	GetFocus-Handler, wird aus den Select-Handler der Listboxen
2178*cdf0e10cSrcweir 	gerufen.
2179*cdf0e10cSrcweir 	Wird verwendet, im die Listbox, die den Focus besitzt sowie
2180*cdf0e10cSrcweir 	deren Zustand zu ermitteln.
2181*cdf0e10cSrcweir 
2182*cdf0e10cSrcweir 	[Parameter]
2183*cdf0e10cSrcweir 
2184*cdf0e10cSrcweir 	SfxOrganizeListBox *pBox        die rufende Box
2185*cdf0e10cSrcweir 
2186*cdf0e10cSrcweir */
2187*cdf0e10cSrcweir 
2188*cdf0e10cSrcweir {
2189*cdf0e10cSrcweir 	if(pFocusBox && pFocusBox != pBox)
2190*cdf0e10cSrcweir 		pFocusBox->SelectAll(sal_False);
2191*cdf0e10cSrcweir 	pFocusBox = pBox;
2192*cdf0e10cSrcweir 	aFilesBtn.Enable( SfxOrganizeListBox_Impl::VIEW_FILES ==
2193*cdf0e10cSrcweir 					  pFocusBox->GetViewType() );
2194*cdf0e10cSrcweir 	return 0;
2195*cdf0e10cSrcweir }
2196*cdf0e10cSrcweir 
2197*cdf0e10cSrcweir //-------------------------------------------------------------------------
2198*cdf0e10cSrcweir 
2199*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, LeftListBoxSelect_Impl, ListBox *, pBox )
2200*cdf0e10cSrcweir 
2201*cdf0e10cSrcweir /*  [Beschreibung]
2202*cdf0e10cSrcweir 
2203*cdf0e10cSrcweir 	Select-Handler, wird aus den Select-Handler der Listboxen
2204*cdf0e10cSrcweir 	gerufen.
2205*cdf0e10cSrcweir 	Wenn sich der Modus der Boxen (Dokumentsicht, Dokumentvorlagensicht)
2206*cdf0e10cSrcweir 	unterscheiden, werden die Models getrennt; andernfalls zusammengefa"st.
2207*cdf0e10cSrcweir 
2208*cdf0e10cSrcweir 	[Parameter]
2209*cdf0e10cSrcweir 
2210*cdf0e10cSrcweir 	ListBox *pBox               die rufende Box
2211*cdf0e10cSrcweir 
2212*cdf0e10cSrcweir */
2213*cdf0e10cSrcweir {
2214*cdf0e10cSrcweir 	const SfxOrganizeListBox_Impl::DataEnum
2215*cdf0e10cSrcweir 		eViewType = pBox->GetSelectEntryPos() == 0 ?
2216*cdf0e10cSrcweir 		SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
2217*cdf0e10cSrcweir 	if(eViewType!= aLeftLb.GetViewType()) {
2218*cdf0e10cSrcweir 		aLeftLb.SetViewType(eViewType);
2219*cdf0e10cSrcweir 		if(aRightLb.GetViewType() == eViewType)
2220*cdf0e10cSrcweir 			aLeftLb.SetModel(aRightLb.GetModel());
2221*cdf0e10cSrcweir 		else {
2222*cdf0e10cSrcweir 			// Models trennen
2223*cdf0e10cSrcweir 			aLeftLb.DisconnectFromModel();
2224*cdf0e10cSrcweir 			aLeftLb.Reset();
2225*cdf0e10cSrcweir 		}
2226*cdf0e10cSrcweir 	}
2227*cdf0e10cSrcweir 	GetFocus_Impl(&aLeftLb);
2228*cdf0e10cSrcweir 	return 0;
2229*cdf0e10cSrcweir }
2230*cdf0e10cSrcweir 
2231*cdf0e10cSrcweir //-------------------------------------------------------------------------
2232*cdf0e10cSrcweir 
2233*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, RightListBoxSelect_Impl, ListBox *, pBox )
2234*cdf0e10cSrcweir 
2235*cdf0e10cSrcweir /*  [Beschreibung]
2236*cdf0e10cSrcweir 
2237*cdf0e10cSrcweir 	Select-Handler, wird aus den Select-Handler der Listboxen
2238*cdf0e10cSrcweir 	gerufen.
2239*cdf0e10cSrcweir 	Wenn sich der Modus der Boxen (Dokumentsicht, Dokumentvorlagensicht)
2240*cdf0e10cSrcweir 	unterscheiden, werden die Models getrennt; andernfalls zusammengefa"st.
2241*cdf0e10cSrcweir 
2242*cdf0e10cSrcweir 	[Parameter]
2243*cdf0e10cSrcweir 
2244*cdf0e10cSrcweir 	ListBox *pBox               die rufende Box
2245*cdf0e10cSrcweir 
2246*cdf0e10cSrcweir */
2247*cdf0e10cSrcweir {
2248*cdf0e10cSrcweir 	const SfxOrganizeListBox_Impl::DataEnum eViewType =
2249*cdf0e10cSrcweir 		pBox->GetSelectEntryPos() == 0 ?
2250*cdf0e10cSrcweir 		SfxOrganizeListBox_Impl::VIEW_TEMPLATES : SfxOrganizeListBox_Impl::VIEW_FILES;
2251*cdf0e10cSrcweir 	if(eViewType!= aRightLb.GetViewType())
2252*cdf0e10cSrcweir 	{
2253*cdf0e10cSrcweir 		aRightLb.SetViewType(eViewType);
2254*cdf0e10cSrcweir 		if(aLeftLb.GetViewType() == eViewType)
2255*cdf0e10cSrcweir 			aRightLb.SetModel(aLeftLb.GetModel());
2256*cdf0e10cSrcweir 		else
2257*cdf0e10cSrcweir 		{
2258*cdf0e10cSrcweir 			// Models trennen
2259*cdf0e10cSrcweir 			aRightLb.DisconnectFromModel();
2260*cdf0e10cSrcweir 			aRightLb.Reset();
2261*cdf0e10cSrcweir 		}
2262*cdf0e10cSrcweir 	}
2263*cdf0e10cSrcweir 	aRightLb.GrabFocus();
2264*cdf0e10cSrcweir 	GetFocus_Impl(&aRightLb);
2265*cdf0e10cSrcweir 	return 0;
2266*cdf0e10cSrcweir }
2267*cdf0e10cSrcweir 
2268*cdf0e10cSrcweir //-------------------------------------------------------------------------
2269*cdf0e10cSrcweir 
2270*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, OnAddressTemplateClicked, Button *, pButton )
2271*cdf0e10cSrcweir {
2272*cdf0e10cSrcweir     (void)pButton; //unused
2273*cdf0e10cSrcweir 	svt::AddressBookSourceDialog aDialog(pDialog, ::comphelper::getProcessServiceFactory());
2274*cdf0e10cSrcweir 	aDialog.Execute();
2275*cdf0e10cSrcweir 	return 0L;
2276*cdf0e10cSrcweir }
2277*cdf0e10cSrcweir 
2278*cdf0e10cSrcweir //-------------------------------------------------------------------------
2279*cdf0e10cSrcweir 
2280*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, AddFiles_Impl, Button *, pButton )
2281*cdf0e10cSrcweir 
2282*cdf0e10cSrcweir /*  [Beschreibung]
2283*cdf0e10cSrcweir 
2284*cdf0e10cSrcweir 	Handler des Buttons f"ur das Hinzuf"ugen von Dateien per Dialog.
2285*cdf0e10cSrcweir 
2286*cdf0e10cSrcweir 	[Parameter]
2287*cdf0e10cSrcweir 
2288*cdf0e10cSrcweir 	Button *                der Button, der dieses Events ausgel"ost hat.
2289*cdf0e10cSrcweir 
2290*cdf0e10cSrcweir */
2291*cdf0e10cSrcweir {
2292*cdf0e10cSrcweir     (void)pButton; //unused
2293*cdf0e10cSrcweir     if ( pFileDlg )
2294*cdf0e10cSrcweir         delete pFileDlg;
2295*cdf0e10cSrcweir     pFileDlg = new sfx2::FileDialogHelper( WB_OPEN, String() );
2296*cdf0e10cSrcweir 
2297*cdf0e10cSrcweir     // add config and basic filter
2298*cdf0e10cSrcweir 	static String sOpenBracket( DEFINE_CONST_UNICODE( " (" ) );
2299*cdf0e10cSrcweir 	static String sCloseBracket( DEFINE_CONST_UNICODE( ")" ) );
2300*cdf0e10cSrcweir 	static String sConfigExt( DEFINE_CONST_UNICODE( "*.cfg" ) );
2301*cdf0e10cSrcweir 	static String sBasicExt( DEFINE_CONST_UNICODE( "*.sbl" ) );
2302*cdf0e10cSrcweir 
2303*cdf0e10cSrcweir 	String sFilterName( SfxResId( RID_STR_FILTCONFIG ) );
2304*cdf0e10cSrcweir 	sFilterName += sOpenBracket;
2305*cdf0e10cSrcweir 	sFilterName += sConfigExt;
2306*cdf0e10cSrcweir 	sFilterName += sCloseBracket;
2307*cdf0e10cSrcweir     pFileDlg->AddFilter( sFilterName, sConfigExt );
2308*cdf0e10cSrcweir 
2309*cdf0e10cSrcweir 	sFilterName = String( SfxResId( RID_STR_FILTBASIC ) );
2310*cdf0e10cSrcweir 	sFilterName += sOpenBracket;
2311*cdf0e10cSrcweir 	sFilterName += sBasicExt;
2312*cdf0e10cSrcweir 	sFilterName += sCloseBracket;
2313*cdf0e10cSrcweir     pFileDlg->AddFilter( sFilterName, sBasicExt );
2314*cdf0e10cSrcweir 
2315*cdf0e10cSrcweir 	// set "All" filter as current
2316*cdf0e10cSrcweir     pFileDlg->SetCurrentFilter( String( SfxResId( STR_SFX_FILTERNAME_ALL ) ) );
2317*cdf0e10cSrcweir 
2318*cdf0e10cSrcweir 	if ( aLastDir.Len() )
2319*cdf0e10cSrcweir         pFileDlg->SetDisplayDirectory( aLastDir );
2320*cdf0e10cSrcweir 
2321*cdf0e10cSrcweir     pFileDlg->StartExecuteModal( LINK( this, SfxOrganizeDlg_Impl, AddFilesHdl ) );
2322*cdf0e10cSrcweir 
2323*cdf0e10cSrcweir     return 0;
2324*cdf0e10cSrcweir }
2325*cdf0e10cSrcweir 
2326*cdf0e10cSrcweir //-------------------------------------------------------------------------
2327*cdf0e10cSrcweir 
2328*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, ImportHdl, sfx2::FileDialogHelper *, EMPTYARG )
2329*cdf0e10cSrcweir {
2330*cdf0e10cSrcweir     DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
2331*cdf0e10cSrcweir 
2332*cdf0e10cSrcweir     if ( ERRCODE_NONE == pFileDlg->GetError() )
2333*cdf0e10cSrcweir     {
2334*cdf0e10cSrcweir         String aPath = pFileDlg->GetPath();
2335*cdf0e10cSrcweir         INetURLObject aObj( aPath );
2336*cdf0e10cSrcweir 
2337*cdf0e10cSrcweir         // we want to keep the original extension when exporting, the file open dialog
2338*cdf0e10cSrcweir         // always sets the extension to *.vor
2339*cdf0e10cSrcweir         if ( pFileDlg->GetDialogType() ==
2340*cdf0e10cSrcweir                 com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_SIMPLE )
2341*cdf0e10cSrcweir         {
2342*cdf0e10cSrcweir             if ( aObj.hasExtension() )
2343*cdf0e10cSrcweir                 aObj.removeExtension();
2344*cdf0e10cSrcweir 
2345*cdf0e10cSrcweir             aObj.setExtension( m_sExtension4Save );
2346*cdf0e10cSrcweir             aPath = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2347*cdf0e10cSrcweir         }
2348*cdf0e10cSrcweir 
2349*cdf0e10cSrcweir         aObj.removeSegment();
2350*cdf0e10cSrcweir         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2351*cdf0e10cSrcweir 
2352*cdf0e10cSrcweir         if ( aPath.Len() && !aMgr.CopyTo( m_nRegion, m_nIndex, aPath ) )
2353*cdf0e10cSrcweir         {
2354*cdf0e10cSrcweir             String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
2355*cdf0e10cSrcweir             aText.SearchAndReplaceAscii( "$1", aPath );
2356*cdf0e10cSrcweir             ErrorBox( pDialog, WB_OK, aText ).Execute();
2357*cdf0e10cSrcweir         }
2358*cdf0e10cSrcweir     }
2359*cdf0e10cSrcweir 
2360*cdf0e10cSrcweir     return 0L;
2361*cdf0e10cSrcweir }
2362*cdf0e10cSrcweir 
2363*cdf0e10cSrcweir //-------------------------------------------------------------------------
2364*cdf0e10cSrcweir 
2365*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, ExportHdl, sfx2::FileDialogHelper *, EMPTYARG )
2366*cdf0e10cSrcweir {
2367*cdf0e10cSrcweir     DBG_ASSERT( pFileDlg, "SfxOrganizeDlg_Impl::ImportHdl(): no file dialog" );
2368*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString > aPaths;
2369*cdf0e10cSrcweir 
2370*cdf0e10cSrcweir     if ( ERRCODE_NONE == pFileDlg->GetError() )
2371*cdf0e10cSrcweir     {
2372*cdf0e10cSrcweir         aPaths = pFileDlg->GetMPath();
2373*cdf0e10cSrcweir         sal_Int32 lastCount = aPaths.getLength() - 1;
2374*cdf0e10cSrcweir         INetURLObject aObj( aPaths.getArray()[ lastCount ] );
2375*cdf0e10cSrcweir 
2376*cdf0e10cSrcweir         aObj.removeSegment();
2377*cdf0e10cSrcweir         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2378*cdf0e10cSrcweir     }
2379*cdf0e10cSrcweir 
2380*cdf0e10cSrcweir     sal_Int32 nCount = aPaths.getLength();
2381*cdf0e10cSrcweir     if ( 1 == nCount )
2382*cdf0e10cSrcweir     {
2383*cdf0e10cSrcweir        String aPath = String( aPaths.getArray()[0] );
2384*cdf0e10cSrcweir        if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
2385*cdf0e10cSrcweir        {
2386*cdf0e10cSrcweir            String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
2387*cdf0e10cSrcweir            aText.SearchAndReplaceAscii( "$1", aPath );
2388*cdf0e10cSrcweir            ErrorBox( pDialog, WB_OK, aText ).Execute();
2389*cdf0e10cSrcweir        }
2390*cdf0e10cSrcweir     }
2391*cdf0e10cSrcweir     else if ( nCount > 1 )
2392*cdf0e10cSrcweir     {
2393*cdf0e10cSrcweir         INetURLObject aPathObj( aPaths[0] );
2394*cdf0e10cSrcweir         aPathObj.setFinalSlash();
2395*cdf0e10cSrcweir         for ( sal_uInt16 i = 1; i < nCount; ++i )
2396*cdf0e10cSrcweir         {
2397*cdf0e10cSrcweir             if ( 1 == i )
2398*cdf0e10cSrcweir                 aPathObj.Append( aPaths[i] );
2399*cdf0e10cSrcweir             else
2400*cdf0e10cSrcweir                 aPathObj.setName( aPaths[i] );
2401*cdf0e10cSrcweir             String aPath = aPathObj.GetMainURL( INetURLObject::NO_DECODE );
2402*cdf0e10cSrcweir             if ( aPath.Len() && !aMgr.CopyFrom( pFocusBox, m_nRegion, m_nIndex, aPath ) )
2403*cdf0e10cSrcweir             {
2404*cdf0e10cSrcweir                 String aText( SfxResId( STR_ERROR_COPY_TEMPLATE ) );
2405*cdf0e10cSrcweir                 aText.SearchAndReplaceAscii( "$1", aPath );
2406*cdf0e10cSrcweir                 ErrorBox( pDialog, WB_OK, aText ).Execute();
2407*cdf0e10cSrcweir             }
2408*cdf0e10cSrcweir         }
2409*cdf0e10cSrcweir     }
2410*cdf0e10cSrcweir 
2411*cdf0e10cSrcweir     return 0L;
2412*cdf0e10cSrcweir }
2413*cdf0e10cSrcweir 
2414*cdf0e10cSrcweir //-------------------------------------------------------------------------
2415*cdf0e10cSrcweir 
2416*cdf0e10cSrcweir IMPL_LINK( SfxOrganizeDlg_Impl, AddFilesHdl, sfx2::FileDialogHelper *, EMPTYARG )
2417*cdf0e10cSrcweir {
2418*cdf0e10cSrcweir     if ( ERRCODE_NONE == pFileDlg->GetError() )
2419*cdf0e10cSrcweir     {
2420*cdf0e10cSrcweir         String aPath = pFileDlg->GetPath();
2421*cdf0e10cSrcweir         aMgr.InsertFile( pFocusBox, aPath );
2422*cdf0e10cSrcweir         INetURLObject aObj( aPath );
2423*cdf0e10cSrcweir         aObj.removeSegment();
2424*cdf0e10cSrcweir         aObj.setFinalSlash();
2425*cdf0e10cSrcweir         aLastDir = aObj.GetMainURL( INetURLObject::DECODE_TO_IURI );
2426*cdf0e10cSrcweir     }
2427*cdf0e10cSrcweir 
2428*cdf0e10cSrcweir     return 0L;
2429*cdf0e10cSrcweir }
2430*cdf0e10cSrcweir 
2431*cdf0e10cSrcweir //-------------------------------------------------------------------------
2432*cdf0e10cSrcweir 
2433*cdf0e10cSrcweir short SfxTemplateOrganizeDlg::Execute()
2434*cdf0e10cSrcweir 
2435*cdf0e10cSrcweir /*  [Beschreibung]
2436*cdf0e10cSrcweir 
2437*cdf0e10cSrcweir 	"Uberladene Execute- Methode; speichert gfs. "Anderungen an den
2438*cdf0e10cSrcweir 	Dokumentvorlagen
2439*cdf0e10cSrcweir 	(SV-Methode)
2440*cdf0e10cSrcweir 
2441*cdf0e10cSrcweir */
2442*cdf0e10cSrcweir 
2443*cdf0e10cSrcweir {
2444*cdf0e10cSrcweir 	const short nRet = ModalDialog::Execute();
2445*cdf0e10cSrcweir 	if(RET_CANCEL != nRet)
2446*cdf0e10cSrcweir 	{
2447*cdf0e10cSrcweir 		pImp->aMgr.SaveAll(this);
2448*cdf0e10cSrcweir 		SfxTemplateDialog* pTemplDlg = SFX_APP()->GetTemplateDialog();
2449*cdf0e10cSrcweir 		if(pTemplDlg)
2450*cdf0e10cSrcweir 			pTemplDlg->Update();
2451*cdf0e10cSrcweir 	}
2452*cdf0e10cSrcweir 	return nRet;
2453*cdf0e10cSrcweir }
2454*cdf0e10cSrcweir 
2455*cdf0e10cSrcweir 
2456*cdf0e10cSrcweir //-------------------------------------------------------------------------
2457*cdf0e10cSrcweir 
2458*cdf0e10cSrcweir SfxTemplateOrganizeDlg::SfxTemplateOrganizeDlg(Window * pParent,
2459*cdf0e10cSrcweir 												SfxDocumentTemplates *pTempl)
2460*cdf0e10cSrcweir :   ModalDialog( pParent, SfxResId(DLG_ORGANIZE)),
2461*cdf0e10cSrcweir 	pImp( new SfxOrganizeDlg_Impl(this, pTempl) )
2462*cdf0e10cSrcweir 
2463*cdf0e10cSrcweir /*  [Beschreibung]
2464*cdf0e10cSrcweir 
2465*cdf0e10cSrcweir 	Konstruktor
2466*cdf0e10cSrcweir 
2467*cdf0e10cSrcweir */
2468*cdf0e10cSrcweir {
2469*cdf0e10cSrcweir 	FreeResource();
2470*cdf0e10cSrcweir }
2471*cdf0e10cSrcweir 
2472*cdf0e10cSrcweir //-------------------------------------------------------------------------
2473*cdf0e10cSrcweir 
2474*cdf0e10cSrcweir SfxTemplateOrganizeDlg::~SfxTemplateOrganizeDlg()
2475*cdf0e10cSrcweir {
2476*cdf0e10cSrcweir 	GetpApp()->RemoveAccel(&pImp->aEditAcc);
2477*cdf0e10cSrcweir 	delete pImp->pPrt;
2478*cdf0e10cSrcweir 	delete pImp;
2479*cdf0e10cSrcweir }
2480*cdf0e10cSrcweir 
2481