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