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