xref: /trunk/main/sd/source/ui/dlg/dlgass.cxx (revision af7f2cbf3d6a5481a2f45e7fae5e85a32449c47d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #ifdef SD_DLLIMPLEMENTATION
28 #undef SD_DLLIMPLEMENTATION
29 #endif
30 #include <com/sun/star/presentation/ClickAction.hpp>
31 #include <vcl/svapp.hxx>
32 #include <vos/mutex.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <vcl/lstbox.hxx>
35 #include <vcl/combobox.hxx>
36 #include <sfx2/doctempl.hxx>
37 #include <svl/lstner.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <svtools/ehdl.hxx>
40 #include <svtools/sfxecode.hxx>
41 #include <tools/urlobj.hxx>
42 #include <com/sun/star/presentation/FadeEffect.hpp>
43 #include <fadedef.h>
44 #include <sfx2/sfxsids.hrc>
45 #include <svl/undo.hxx>
46 #include "DrawDocShell.hxx"
47 #include <vcl/gdimtf.hxx>
48 #include <tools/wintypes.hxx>
49 #include "docprev.hxx"
50 #include <sfx2/app.hxx>
51 #include <sfx2/docfile.hxx>
52 #include <sfx2/dispatch.hxx>
53 #include <sfx2/request.hxx>
54 #include <com/sun/star/sdbc/XResultSet.hpp>
55 #include <com/sun/star/lang/XComponent.hpp>
56 #include <com/sun/star/util/XCloseable.hpp>
57 #include <com/sun/star/uno/RuntimeException.hpp>
58 #include <com/sun/star/frame/XModuleManager.hpp>
59 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
60 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
61 #include <com/sun/star/ui/XImageManager.hpp>
62 #include <unotools/historyoptions.hxx>
63 #include <tools/urlobj.hxx>
64 #include <osl/file.hxx>
65 #include <sfx2/filedlghelper.hxx>
66 
67 #include "sdpage.hxx"
68 #include "helpids.h"
69 #include "assclass.hxx"
70 #include "dlgass.hrc"
71 #include "dlgass.hxx"
72 #include "dlgctrls.hxx"
73 #ifndef _SD_CFGID_HXX
74 #include "strings.hrc"
75 #endif
76 #ifndef _DATETIMEITEM_HXX
77 #include "dlgassim.hxx"
78 #endif
79 #include "TemplateScanner.hxx"
80 #include "WindowUpdater.hxx"
81 
82 #include <comphelper/processfactory.hxx>
83 
84 using namespace ::com::sun::star;
85 using namespace ::com::sun::star::uno;
86 using namespace ::sd;
87 
88 
89 void InterpolateFixedBitmap( FixedBitmap * pBitmap )
90 {
91     Bitmap aBmp( pBitmap->GetBitmap() );
92     Size aSize = pBitmap->GetSizePixel();
93     aBmp.Scale( aSize, BMP_SCALE_BESTQUALITY );
94     pBitmap->SetBitmap( aBmp );
95 }
96 
97 
98 // ====================================================================
99 // ====================================================================
100 
101 const char* PageHelpIds[] =
102 {
103     HID_SD_AUTOPILOT_PAGE1,
104     HID_SD_AUTOPILOT_PAGE2,
105     HID_SD_AUTOPILOT_PAGE3,
106     HID_SD_AUTOPILOT_PAGE4,
107     HID_SD_AUTOPILOT_PAGE5
108 };
109 
110 // ====================================================================
111 
112 class PasswordEntry
113 {
114 public:
115     String maPassword;
116     String maPath;
117 };
118 
119 DECLARE_LIST( PasswordEntryList, PasswordEntry * )
120 
121 // ====================================================================
122 
123 /** A simple wrapper that looks like a PushButton and is used to force the
124     broadcasting of focus events primarily for accessibility tools.
125     Forcing focus events is achieved by using two identical PushButtons
126     which, when the focus event is requested, are exchanged and play focus
127     ping-pong by moving the focus from one to the other.
128 */
129 class NextButton
130 {
131 public:
132     NextButton (::Window* pParent, const ResId& rResId);
133 
134     void ForceFocusEventBroadcast (void);
135     void SetClickHdl (const Link& rLink);
136     bool IsEnabled (void);
137     void Enable (bool bEnable);
138 
139 private:
140     PushButton maNextButton1;
141     PushButton maNextButton2;
142     bool mbIsFirstButtonActive;
143 };
144 
145 
146 
147 // ====================================================================
148 
149 class AssistentDlgImpl : public SfxListener
150 {
151 public:
152     AssistentDlgImpl( ::Window* pWindow, const Link& rFinishLink, sal_Bool bAutoPilot );
153     ~AssistentDlgImpl();
154 
155     // Local mutex used to serialize concurrent method calls.
156     ::osl::Mutex maMutex;
157 
158     SfxObjectShellLock GetDocument();
159 
160     /** closes the current preview docshell */
161     void CloseDocShell();
162 
163     /** Extract form the history list of recently used files the Impress
164         files and insert them into a listbox.
165     */
166     void    ScanDocmenu         (void);
167     /** Flag that is set to sal_True after the recently used files have been
168         scanned.
169     */
170     sal_Bool mbRecentDocumentsReady;
171 
172     /** When the list of templates has not been scanned already this is done
173         when this method is called. That includes requesting the whole list
174         of templates from UCB and extracting from that list the Impress
175         templates and layouts and storing them for later use in
176         <member>maPresentList</member>. Note that the first call to this
177         method after installing a new Office may take some time.
178     */
179     void ProvideTemplates (void);
180 
181     /** This method transfers the template folders from the template scanner
182         to the internal structures of this class. On termination it sets
183         the flag <member>mbTemplatesReady</member> to <TRUE/> to indicate
184         that the templates are available.
185         @param rTemplateFolders
186             This is a list of template folders. This method takes ownership
187             of the supplied entries by removing them from the list and
188             transferring them to an internal structure.
189     */
190     void TemplateScanDone (std::vector<TemplateDir*>& rTemplateFolders);
191 
192     /** Flag that is set to sal_True after the Impress templates have been
193         scanned.
194     */
195     sal_Bool mbTemplatesReady;
196 
197     /** Flag used to prevent nested or concurrent calls to the
198         <member>UpdatePreview</member> method. A <TRUE/> value indicates
199         that a preview update is currently active.
200     */
201     sal_Bool mbPreviewUpdating;
202 
203     ::Window* mpWindow;
204 
205     void SavePassword( SfxObjectShellLock xDoc, const String& rPath );
206     void RestorePassword( SfxItemSet* pSet, const String& rPath );
207     String GetPassword( const String rPath );
208     void DeletePassords();
209 
210     PasswordEntryList maPasswordList;
211 
212     String maDocFile;
213     String maLayoutFile;
214 
215     String GetDocFileName();
216     String GetLayoutFileName();
217 
218     // List of URLs of recently used Impress files.
219     std::vector<String*> maOpenFilesList;
220 
221     // List of folders containing data about Impress templates.
222     std::vector<TemplateDir*> maPresentList;
223 
224     // Currently selected template folder.
225     TemplateDir* mpTemplateRegion;
226 
227     // Currently selected layout folder.
228     TemplateDir* mpLayoutRegion;
229 
230     // preview
231     sal_Bool mbUserDataDirty;
232     Timer maPrevTimer;
233     Timer maEffectPrevTimer;
234     Timer maUpdatePageListTimer;
235     Timer maStartScanTimer;
236 
237     SfxObjectShellLock xDocShell;
238 
239     ::std::auto_ptr<WindowUpdater> mpWindowUpdater;
240 
241     sal_Bool mbPreview;
242     sal_uInt16 mnShowPage;
243     sal_Bool mbDocPreview;
244 
245     sal_uLong mnTemplate;
246 
247     String maPageListFile;
248 
249     void UpdatePreview( sal_Bool bDocPreview );
250     void UpdatePageList();
251     void UpdateUserData();
252 
253     sal_Bool IsOwnFormat( const String& rPath );
254 
255     // dlg status
256     void EndDialog( long nResult = 0 );
257 
258     void SetStartType( StartType eType );
259     StartType GetStartType();
260 
261     void SelectTemplateRegion( const String& rRegion );
262     void SelectLayoutRegion( const String& rRegion );
263 
264     void UpdatePage();
265     void ChangePage();
266     void LeavePage();
267 
268     String GetUiTextForCommand (const ::rtl::OUString& aCommandURL);
269     Image GetUiIconForCommand (const ::rtl::OUString& aCommandURL);
270 
271     DECL_LINK( StartScanHdl, void * );
272     DECL_LINK( SelectFileHdl, ListBox * );
273     DECL_LINK( SelectRegionHdl, ListBox * );
274     DECL_LINK( UpdatePreviewHdl, void * );
275     DECL_LINK( UpdatePageListHdl, void * );
276     DECL_LINK( StartTypeHdl, RadioButton * );
277     DECL_LINK( SelectTemplateHdl, ListBox * );
278     DECL_LINK( NextPageHdl, PushButton * );
279     DECL_LINK( LastPageHdl, PushButton * );
280     DECL_LINK( PreviewFlagHdl, CheckBox * );
281     DECL_LINK( EffectPreviewHdl, Button * );
282     DECL_LINK( SelectLayoutHdl, ListBox * );
283     DECL_LINK( PageSelectHdl, Control * );
284     DECL_LINK( PresTypeHdl, RadioButton * );
285     DECL_LINK( UpdateUserDataHdl, Edit* );
286     DECL_LINK( SelectEffectHdl, void* );
287     DECL_LINK( OpenButtonHdl, Button * );
288 
289     // Common
290     Assistent           maAssistentFunc;
291     CheckBox            maPreviewFlag;
292     CheckBox            maStartWithFlag;
293     HelpButton          maHelpButton;
294     CancelButton        maCancelButton;
295     PushButton          maLastPageButton;
296     NextButton          maNextPageButton;
297     OKButton            maFinishButton;
298     SdDocPreviewWin     maPreview;
299 
300     String              maCreateStr;
301     String              maOpenStr;
302 
303     // Page 1
304     FixedBitmap*        mpPage1FB;
305     FixedLine*          mpPage1ArtFL;
306     RadioButton*        mpPage1EmptyRB;
307     RadioButton*        mpPage1TemplateRB;
308     ListBox*            mpPage1RegionLB;
309     ListBox*            mpPage1TemplateLB;
310     RadioButton*        mpPage1OpenRB;
311     ListBox*            mpPage1OpenLB;
312     PushButton*         mpPage1OpenPB;
313 
314     // Page 2
315     FixedBitmap*        mpPage2FB;
316     FixedLine*          mpPage2LayoutFL;
317     ListBox*            mpPage2RegionLB;
318     ListBox*            mpPage2LayoutLB;
319     FixedLine*          mpPage2OutTypesFL;
320     RadioButton*        mpPage2Medium1RB;
321     RadioButton*        mpPage2Medium2RB;
322     RadioButton*        mpPage2Medium3RB;
323     RadioButton*        mpPage2Medium4RB;
324     RadioButton*        mpPage2Medium5RB;
325     RadioButton*        mpPage2Medium6RB;
326 
327     // Page 3
328     FixedBitmap*        mpPage3FB;
329     FixedLine*          mpPage3EffectFL;
330     FixedText*          mpPage3EffectFT;
331     FadeEffectLB*       mpPage3EffectLB;
332     FixedText*          mpPage3SpeedFT;
333     ListBox*            mpPage3SpeedLB;
334     FixedLine*          mpPage3PresTypeFL;
335     RadioButton*        mpPage3PresTypeLiveRB;
336     RadioButton*        mpPage3PresTypeKioskRB;
337     FixedText*          mpPage3PresTimeFT;
338     TimeField*          mpPage3PresTimeTMF;
339     FixedText*          mpPage3BreakFT;
340     TimeField*          mpPage3BreakTMF;
341     CheckBox*           mpPage3LogoCB;
342 
343     // Page 4
344     FixedBitmap*        mpPage4FB;
345     FixedLine*          mpPage4PersonalFL;
346     FixedText*          mpPage4AskNameFT;
347     Edit*               mpPage4AskNameEDT;
348     FixedText*          mpPage4AskTopicFT;
349     Edit*               mpPage4AskTopicEDT;
350     FixedText*          mpPage4AskInfoFT;
351     MultiLineEdit*      mpPage4AskInfoEDT;
352 
353     // Page 5
354     FixedBitmap*        mpPage5FB;
355     FixedText*          mpPage5PageListFT;
356     SdPageListControl*  mpPage5PageListCT;
357     CheckBox*           mpPage5SummaryCB;
358 
359 };
360 
361 
362 
363 // ====================================================================
364 
365 AssistentDlgImpl::AssistentDlgImpl( ::Window* pWindow, const Link& rFinishLink, sal_Bool bAutoPilot ) :
366     mpTemplateRegion(NULL),
367     mpLayoutRegion(NULL),
368     mbUserDataDirty(sal_False),
369     xDocShell (NULL),
370     mpWindowUpdater (new WindowUpdater()),
371     mbPreview(sal_True),
372     mnShowPage(0),
373     mbDocPreview(sal_False),
374     maAssistentFunc(5),
375     maPreviewFlag(pWindow,SdResId(CB_PREVIEW)),
376     maStartWithFlag(pWindow,SdResId(CB_STARTWITH)),
377     maHelpButton(pWindow,SdResId(BUT_HELP)),
378     maCancelButton(pWindow,SdResId(BUT_CANCEL)),
379     maLastPageButton(pWindow,SdResId(BUT_LAST)),
380     maNextPageButton(pWindow,SdResId(BUT_NEXT)),
381     maFinishButton(pWindow,SdResId(BUT_FINISH)),
382     maPreview(pWindow,SdResId(CT_PREVIEW)),
383     maCreateStr(SdResId(STR_CREATE)),
384     maOpenStr(SdResId(STR_OPEN))
385 {
386     maPageListFile += sal_Unicode('?'),
387     mbRecentDocumentsReady = sal_False;
388     mbTemplatesReady = sal_False;
389     mbPreviewUpdating = sal_False;
390 
391     mpWindow = pWindow;
392 
393     if(bAutoPilot)
394         maStartWithFlag.Hide();
395     else
396         maAssistentFunc.InsertControl(1, &maStartWithFlag );
397 
398     // Page1 wird initialisiert und an die Assistentenfunktionalitaet
399     // uebergeben
400     maAssistentFunc.InsertControl(1, &maPreview );
401     maAssistentFunc.InsertControl(1, &maPreviewFlag );
402     maAssistentFunc.InsertControl(1,
403         mpPage1FB = new FixedBitmap(pWindow,SdResId(FB_PAGE1)));
404     maAssistentFunc.InsertControl(1,
405         mpPage1ArtFL = new FixedLine(pWindow,SdResId(FL_PAGE1_ARTGROUP)));
406     maAssistentFunc.InsertControl(1,
407         mpPage1EmptyRB=new RadioButton(pWindow,SdResId(RB_PAGE1_EMPTY)));
408     maAssistentFunc.InsertControl(1,
409         mpPage1TemplateRB=new RadioButton(pWindow,SdResId(RB_PAGE1_TEMPLATE)));
410     maAssistentFunc.InsertControl(1,
411         mpPage1OpenRB=new RadioButton(pWindow,SdResId(RB_PAGE1_OPEN)));
412     maAssistentFunc.InsertControl(1,
413         mpPage1RegionLB = new ListBox(pWindow,SdResId(LB_PAGE1_REGION)));
414     maAssistentFunc.InsertControl(1,
415         mpPage1TemplateLB=new ListBox(pWindow,SdResId(LB_PAGE1_TEMPLATES)));
416     maAssistentFunc.InsertControl(1,
417         mpPage1OpenPB=new PushButton(pWindow,SdResId(PB_PAGE1_OPEN)));
418     maAssistentFunc.InsertControl(1,
419         mpPage1OpenLB=new ListBox(pWindow,SdResId(LB_PAGE1_OPEN)));
420 
421     // Align the button and list box displayed for the "open existing file"
422     // radio button with the text of that radio button.
423     {
424         RadioButton aEmptyRB (mpWindow);
425         sal_Int32 nIndent (aEmptyRB.CalcMinimumSize(0).Width());
426         sal_Int32 nLeft (mpPage1OpenRB->GetPosPixel().X() + nIndent);
427         sal_Int32 nWidth (mpPage1OpenRB->GetSizePixel().Width() - nIndent);
428         mpPage1OpenPB->SetPosSizePixel(
429             Point(nLeft, mpPage1OpenPB->GetPosPixel().Y()),
430             Size(mpPage1OpenPB->GetSizePixel()));
431         mpPage1OpenLB->SetPosSizePixel(
432             Point(nLeft, mpPage1OpenLB->GetPosPixel().Y()),
433             Size(nWidth, mpPage1OpenLB->GetSizePixel().Height()));
434     }
435 
436     // Set text and icon of the 'Open...' button.
437     {
438         String sText (GetUiTextForCommand(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Open"))));
439         // Remove the mnemonic and add a leading space so that icon and text
440         // are not too close together.
441         sText.SearchAndReplaceAll(String(RTL_CONSTASCII_STRINGPARAM("~")),String());
442         sText.Insert(String(RTL_CONSTASCII_STRINGPARAM(" ")),0);
443         mpPage1OpenPB->SetText(sText);
444         // Place icon left of text and both centered in the button.
445         mpPage1OpenPB->SetModeImage(
446             GetUiIconForCommand(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Open"))),
447             BMP_COLOR_NORMAL);
448         mpPage1OpenPB->EnableImageDisplay(sal_True);
449         mpPage1OpenPB->EnableTextDisplay(sal_True);
450         mpPage1OpenPB->SetImageAlign(IMAGEALIGN_LEFT);
451         mpPage1OpenPB->SetStyle(mpPage1OpenPB->GetStyle() | WB_CENTER);
452     }
453 
454     // links&handler
455     mpPage1RegionLB->SetSelectHdl(LINK(this,AssistentDlgImpl,SelectRegionHdl));
456     mpPage1RegionLB->SetDropDownLineCount( 6 );
457     mpPage1TemplateLB->SetSelectHdl(LINK(this,AssistentDlgImpl,SelectTemplateHdl));
458     mpPage1TemplateLB->InsertEntry(String(SdResId(STR_ISLOADING)));
459 
460     mpPage1EmptyRB->SetClickHdl(LINK(this,AssistentDlgImpl,StartTypeHdl));
461     mpPage1TemplateRB->SetClickHdl(LINK(this,AssistentDlgImpl,StartTypeHdl));
462     mpPage1OpenRB->SetClickHdl(LINK(this,AssistentDlgImpl,StartTypeHdl));
463     mpPage1OpenLB->SetSelectHdl(LINK(this,AssistentDlgImpl,SelectFileHdl));
464     mpPage1OpenLB->SetDoubleClickHdl(rFinishLink);
465     mpPage1OpenPB->SetClickHdl(LINK(this,AssistentDlgImpl,OpenButtonHdl));
466 //  mpPage1OpenLB->InsertEntry(String(SdResId(STR_WIZARD_POSITION)));
467 
468     // Page 2
469     maAssistentFunc.InsertControl(2, &maPreview );
470     maAssistentFunc.InsertControl(2, &maPreviewFlag );
471     maAssistentFunc.InsertControl(2,
472         mpPage2FB = new FixedBitmap(pWindow,SdResId(FB_PAGE2)));
473     maAssistentFunc.InsertControl(2,
474         mpPage2LayoutFL = new FixedLine( pWindow, SdResId(FL_PAGE2_LAYOUT) ));
475     maAssistentFunc.InsertControl(2,
476         mpPage2RegionLB = new ListBox(pWindow,SdResId(LB_PAGE2_REGION) ));
477     maAssistentFunc.InsertControl(2,
478         mpPage2LayoutLB = new ListBox(pWindow,SdResId(LB_PAGE2_LAYOUT) ));
479 
480     maAssistentFunc.InsertControl(2,
481         mpPage2OutTypesFL = new FixedLine( pWindow, SdResId(FL_PAGE2_OUTPUTTYPES) ));
482     maAssistentFunc.InsertControl(2,
483         mpPage2Medium5RB = new RadioButton( pWindow, SdResId(RB_PAGE2_MEDIUM5) ));
484     maAssistentFunc.InsertControl(2,
485         mpPage2Medium3RB = new RadioButton( pWindow, SdResId(RB_PAGE2_MEDIUM3) ));
486     maAssistentFunc.InsertControl(2,
487         mpPage2Medium4RB = new RadioButton( pWindow, SdResId(RB_PAGE2_MEDIUM4) ));
488     maAssistentFunc.InsertControl(2,
489         mpPage2Medium1RB = new RadioButton( pWindow, SdResId(RB_PAGE2_MEDIUM1) ));
490     maAssistentFunc.InsertControl(2,
491         mpPage2Medium2RB = new RadioButton( pWindow, SdResId(RB_PAGE2_MEDIUM2) ));
492     maAssistentFunc.InsertControl(2,
493         mpPage2Medium6RB = new RadioButton( pWindow, SdResId(RB_PAGE2_MEDIUM6) ));
494     mpPage2Medium5RB->Check();
495 
496     mpPage2RegionLB->SetSelectHdl(LINK(this,AssistentDlgImpl,SelectRegionHdl));
497     mpPage2RegionLB->SetDropDownLineCount( 6 );
498     mpPage2LayoutLB->SetSelectHdl(LINK(this,AssistentDlgImpl,SelectLayoutHdl));
499     mpPage2LayoutLB->InsertEntry(String(SdResId(STR_ISLOADING)));
500 
501     // Page 3
502     maAssistentFunc.InsertControl(3, &maPreview );
503     maAssistentFunc.InsertControl(3, &maPreviewFlag );
504     maAssistentFunc.InsertControl(3,
505         mpPage3FB = new FixedBitmap(pWindow,SdResId(FB_PAGE3)));
506     maAssistentFunc.InsertControl(3,
507         mpPage3EffectFL = new FixedLine( pWindow, SdResId(FL_PAGE3_EFFECT) ));
508     maAssistentFunc.InsertControl(3,
509         mpPage3EffectFT = new FixedText( pWindow, SdResId(FT_PAGE3_EFFECT) ));
510     maAssistentFunc.InsertControl(3,
511         mpPage3EffectLB = new FadeEffectLB( pWindow, SdResId(LB_PAGE3_EFFECT) ));
512     maAssistentFunc.InsertControl(3,
513         mpPage3SpeedFT = new FixedText( pWindow, SdResId(FT_PAGE3_SPEED) ));
514     maAssistentFunc.InsertControl(3,
515         mpPage3SpeedLB = new FadeEffectLB( pWindow, SdResId(LB_PAGE3_SPEED) ));
516     maAssistentFunc.InsertControl(3,
517         mpPage3PresTypeFL = new FixedLine( pWindow, SdResId(FL_PAGE3_PRESTYPE) ));
518     maAssistentFunc.InsertControl(3,
519         mpPage3PresTypeLiveRB = new RadioButton( pWindow, SdResId(RB_PAGE3_LIVE) ));
520     maAssistentFunc.InsertControl(3,
521         mpPage3PresTypeKioskRB = new RadioButton( pWindow, SdResId(RB_PAGE3_KIOSK) ));
522     maAssistentFunc.InsertControl(3,
523         mpPage3PresTimeFT = new FixedText( pWindow, SdResId( FT_PAGE3_TIME) ));
524     maAssistentFunc.InsertControl(3,
525         mpPage3PresTimeTMF = new TimeField( pWindow, SdResId( TMF_PAGE3_TIME) ));
526     maAssistentFunc.InsertControl(3,
527         mpPage3BreakFT = new FixedText( pWindow, SdResId( FT_PAGE3_BREAK) ));
528     maAssistentFunc.InsertControl(3,
529         mpPage3BreakTMF = new TimeField( pWindow, SdResId( TMF_PAGE3_BREAK) ));
530     maAssistentFunc.InsertControl(3,
531         mpPage3LogoCB = new CheckBox( pWindow, SdResId( CB_PAGE3_LOGO) ));
532 
533     mpPage3EffectLB->Fill();
534 //  mpPage3EffectLB->SelectEffect( presentation::FadeEffect_NONE );
535     mpPage3EffectLB->SetSelectHdl( LINK(this,AssistentDlgImpl,SelectEffectHdl ));
536     mpPage3EffectLB->SetDropDownLineCount( 12 );
537 
538     mpPage3SpeedLB->InsertEntry( String( SdResId(STR_SLOW) ));
539     mpPage3SpeedLB->InsertEntry( String( SdResId(STR_MEDIUM) ));
540     mpPage3SpeedLB->InsertEntry( String( SdResId(STR_FAST) ));
541     mpPage3SpeedLB->SetDropDownLineCount( 3 );
542     mpPage3SpeedLB->SetSelectHdl( LINK(this,AssistentDlgImpl,SelectEffectHdl ));
543     mpPage3SpeedLB->SelectEntryPos( 1 );
544 
545     mpPage3PresTypeLiveRB->Check();
546     mpPage3PresTypeLiveRB->SetClickHdl( LINK(this,AssistentDlgImpl, PresTypeHdl ));
547     mpPage3PresTypeKioskRB->SetClickHdl( LINK(this,AssistentDlgImpl, PresTypeHdl ));
548     mpPage3PresTimeTMF->SetFormat( TIMEF_SEC );
549     mpPage3PresTimeTMF->SetTime( Time( 0, 0, 10 ) );
550     mpPage3BreakTMF->SetFormat( TIMEF_SEC );
551     mpPage3BreakTMF->SetTime( Time( 0, 0, 10 ) );
552     mpPage3LogoCB->Check();
553 
554     // set cursor in timefield
555     Edit *pEditPage3PresTimeTMF = mpPage3PresTimeTMF->GetField();
556     Edit *pEditPage3BreakTMF = mpPage3BreakTMF->GetField();
557     Selection aSel1( pEditPage3PresTimeTMF->GetMaxTextLen(), pEditPage3PresTimeTMF->GetMaxTextLen() );
558     Selection aSel2( pEditPage3BreakTMF->GetMaxTextLen(), pEditPage3BreakTMF->GetMaxTextLen() );
559     pEditPage3PresTimeTMF->SetSelection( aSel1 );
560     pEditPage3BreakTMF->SetSelection( aSel2 );
561 
562     // Page 4
563     maAssistentFunc.InsertControl(4,
564         mpPage4FB = new FixedBitmap(pWindow,SdResId(FB_PAGE4)));
565     maAssistentFunc.InsertControl(4,
566         mpPage4PersonalFL = new FixedLine( pWindow, SdResId(FL_PAGE4_PERSONAL) ));
567     maAssistentFunc.InsertControl(4,
568         mpPage4AskNameFT   = new FixedText( pWindow, SdResId(FT_PAGE4_ASKNAME) ));
569     maAssistentFunc.InsertControl(4,
570         mpPage4AskNameEDT  = new Edit( pWindow, SdResId(EDT_PAGE4_ASKNAME) ));
571     maAssistentFunc.InsertControl(4,
572         mpPage4AskTopicFT= new FixedText( pWindow, SdResId(FT_PAGE4_ASKTOPIC) ));
573     maAssistentFunc.InsertControl(4,
574         mpPage4AskTopicEDT = new Edit( pWindow, SdResId(EDT_PAGE4_ASKTOPIC) ));
575     maAssistentFunc.InsertControl(4,
576         mpPage4AskInfoFT   = new FixedText( pWindow, SdResId(FT_PAGE4_ASKINFORMATION) ));
577     maAssistentFunc.InsertControl(4,
578         mpPage4AskInfoEDT  = new MultiLineEdit( pWindow, SdResId(EDT_PAGE4_ASKINFORMATION) ));
579 
580     mpPage4AskNameEDT->SetModifyHdl(LINK(this,AssistentDlgImpl,UpdateUserDataHdl));
581     mpPage4AskTopicEDT->SetModifyHdl(LINK(this,AssistentDlgImpl,UpdateUserDataHdl));
582     mpPage4AskInfoEDT->SetModifyHdl(LINK(this,AssistentDlgImpl,UpdateUserDataHdl));
583 
584     // Page 5
585     maAssistentFunc.InsertControl(5, &maPreview );
586     maAssistentFunc.InsertControl(5, &maPreviewFlag );
587     maAssistentFunc.InsertControl(5,
588         mpPage5FB = new FixedBitmap(pWindow,SdResId(FB_PAGE5)));
589     maAssistentFunc.InsertControl(5,
590         mpPage5PageListFT = new FixedText( pWindow, SdResId( FT_PAGE5_PAGELIST ) ));
591     maAssistentFunc.InsertControl(5,
592         mpPage5PageListCT = new SdPageListControl( pWindow, SdResId( CT_PAGE5_PAGELIST ) ));
593     maAssistentFunc.InsertControl(5,
594         mpPage5SummaryCB  = new CheckBox( pWindow, SdResId( CB_PAGE5_SUMMARY ) ));
595 
596     mpPage5PageListCT->SetSelectHdl(LINK(this,AssistentDlgImpl, PageSelectHdl));
597 
598 
599     // General
600     InterpolateFixedBitmap( mpPage1FB );
601     InterpolateFixedBitmap( mpPage2FB );
602     InterpolateFixedBitmap( mpPage3FB );
603     InterpolateFixedBitmap( mpPage4FB );
604     InterpolateFixedBitmap( mpPage5FB );
605 
606     maLastPageButton.SetClickHdl(LINK(this,AssistentDlgImpl, LastPageHdl ));
607     maNextPageButton.SetClickHdl(LINK(this,AssistentDlgImpl, NextPageHdl ));
608 
609     maPreviewFlag.Check( mbPreview );
610     maPreviewFlag.SetClickHdl(LINK(this, AssistentDlgImpl, PreviewFlagHdl ));
611     maPreview.SetClickHdl(LINK(this,AssistentDlgImpl, EffectPreviewHdl ));
612 
613     // setzt die Ausgangsseite
614     maAssistentFunc.GotoPage(1);
615     maLastPageButton.Disable();
616 
617     maPrevTimer.SetTimeout( 200 );
618     maPrevTimer.SetTimeoutHdl( LINK( this, AssistentDlgImpl, UpdatePreviewHdl));
619 
620     maEffectPrevTimer.SetTimeout( 50 );
621     maEffectPrevTimer.SetTimeoutHdl( LINK( this, AssistentDlgImpl, EffectPreviewHdl ));
622 
623     maUpdatePageListTimer.SetTimeout( 50 );
624     maUpdatePageListTimer.SetTimeoutHdl( LINK( this, AssistentDlgImpl, UpdatePageListHdl));
625 
626     SetStartType( ST_EMPTY );
627 
628     ChangePage();
629 
630     mpWindowUpdater->RegisterWindow (&maPreview);
631 
632     UpdatePreview( sal_True );
633 
634     // check whether we should start with a template document initially and preselect it
635     const ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) );
636     String aStandardTemplate( SfxObjectFactory::GetStandardTemplate( aServiceName ) );
637     if( aStandardTemplate.Len() )
638     {
639         ProvideTemplates();
640 
641         // find aStandardTemplate in maPresentList
642         TemplateDir*   pStandardTemplateDir = 0;
643         TemplateEntry* pStandardTemplateEntry = 0;
644 
645         std::vector<TemplateDir*>::iterator I;
646         for (I=maPresentList.begin(); I!=maPresentList.end(); I++)
647         {
648             TemplateDir* pDir = *I;
649             std::vector<TemplateEntry*>::iterator   J;
650             for (J=pDir->maEntries.begin(); J!=pDir->maEntries.end(); J++)
651             {
652                 TemplateEntry* pEntry = *J;
653                 if(pEntry->msPath == aStandardTemplate)
654                 {
655                     pStandardTemplateDir = pDir;
656                     pStandardTemplateEntry = pEntry;
657                     break;
658                 }
659             }
660             if(pStandardTemplateDir)
661                 break;
662         }
663 
664         // preselect template
665         if( pStandardTemplateDir && pStandardTemplateEntry )
666         {
667             mpPage1RegionLB->SelectEntry( pStandardTemplateDir->msRegion );
668             SelectTemplateRegion( pStandardTemplateDir->msRegion );
669             mpPage1TemplateLB->SelectEntry( pStandardTemplateEntry->msTitle );
670             SelectTemplateHdl(mpPage1TemplateLB);
671         }
672     }
673 }
674 
675 
676 
677 
678 AssistentDlgImpl::~AssistentDlgImpl()
679 {
680     CloseDocShell();
681 
682     DeletePassords();
683 
684     // Delete the template file infos.
685     std::vector<TemplateDir*>::iterator I;
686     std::vector<TemplateEntry*>::iterator   J;
687     for (I=maPresentList.begin(); I!=maPresentList.end(); I++)
688     {
689         for (J=(*I)->maEntries.begin(); J!=(*I)->maEntries.end(); J++)
690             delete (*J);
691         delete (*I);
692     }
693 
694     // Page 1
695     delete mpPage1FB;
696     delete mpPage1ArtFL;
697     delete mpPage1EmptyRB;
698     delete mpPage1TemplateRB;
699     delete mpPage1TemplateLB;
700     delete mpPage1RegionLB;
701     delete mpPage1OpenRB;
702     delete mpPage1OpenLB;
703     delete mpPage1OpenPB;
704 
705     // Page 2
706     delete mpPage2FB;
707     delete mpPage2LayoutFL;
708     delete mpPage2RegionLB;
709     delete mpPage2LayoutLB;
710     delete mpPage2OutTypesFL;
711     delete mpPage2Medium1RB;
712     delete mpPage2Medium2RB;
713     delete mpPage2Medium3RB;
714     delete mpPage2Medium4RB;
715     delete mpPage2Medium5RB;
716     delete mpPage2Medium6RB;
717 
718     // Page 3
719     delete mpPage3FB;
720     delete mpPage3EffectFL;
721     delete mpPage3EffectFT;
722     delete mpPage3EffectLB;
723     delete mpPage3SpeedFT;
724     delete mpPage3SpeedLB;
725     delete mpPage3PresTypeFL;
726     delete mpPage3PresTypeLiveRB;
727     delete mpPage3PresTypeKioskRB;
728     delete mpPage3PresTimeFT;
729     delete mpPage3PresTimeTMF;
730     delete mpPage3BreakFT;
731     delete mpPage3BreakTMF;
732     delete mpPage3LogoCB;
733 
734     // Page 4
735     delete mpPage4FB;
736     delete mpPage4PersonalFL;
737     delete mpPage4AskNameFT;
738     delete mpPage4AskNameEDT;
739     delete mpPage4AskTopicFT;
740     delete mpPage4AskTopicEDT;
741     delete mpPage4AskInfoFT;
742     delete mpPage4AskInfoEDT;
743 
744     // Page 5
745     delete mpPage5FB;
746     delete mpPage5PageListFT;
747     delete mpPage5PageListCT;
748     delete mpPage5SummaryCB;
749 
750     // Delete the file history list.
751     std::vector<String*>::iterator  I2;
752     for (I2=maOpenFilesList.begin(); I2!=maOpenFilesList.end(); I2++)
753         delete *I2;
754 }
755 
756 void AssistentDlgImpl::CloseDocShell()
757 {
758     if(xDocShell.Is())
759     {
760         //uno::Reference< lang::XComponent > xModel( xDocShell->GetModel(), uno::UNO_QUERY );
761         uno::Reference< util::XCloseable > xCloseable( xDocShell->GetModel(), uno::UNO_QUERY );
762         //if( xModel.is() )
763         if( xCloseable.is() )
764         {
765             xCloseable->close( sal_True );
766             xDocShell = NULL;
767             //xModel->dispose();
768         }
769         else
770         {
771             xDocShell->DoClose();
772             xDocShell = NULL;
773         }
774     }
775 }
776 
777 void AssistentDlgImpl::EndDialog( long )
778 {
779     mpWindow = NULL;
780 }
781 
782 
783 
784 
785 void    AssistentDlgImpl::ScanDocmenu   (void)
786 {
787     if( mbRecentDocumentsReady )
788         return;
789 
790     uno::Sequence<uno::Sequence<beans::PropertyValue> > aHistory =
791         SvtHistoryOptions().GetList (ePICKLIST);
792 
793     uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
794     uno::Reference< container::XNameAccess > xFilterFactory( xFactory->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.FilterFactory" ) ) ), uno::UNO_QUERY );
795 
796     Reference< ::com::sun::star::ucb::XSimpleFileAccess > xFileAccess(
797         xFactory->createInstance(
798             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess"))),
799         UNO_QUERY_THROW);
800 
801     sal_uInt32 nCount = aHistory.getLength();
802     for (sal_uInt32 nItem=0; nItem<nCount; ++nItem)
803     {
804         // Get the current history item's properties.
805         uno::Sequence<beans::PropertyValue> aPropertySet = aHistory[nItem];
806         rtl::OUString   sURL;
807         rtl::OUString   sFilter;
808         rtl::OUString   sTitle;
809         rtl::OUString   sPassword;
810         sal_uInt32 nPropertyCount = aPropertySet.getLength();
811         for (sal_uInt32 nProperty=0; nProperty<nPropertyCount; ++nProperty)
812             if (aPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_URL)
813                 aPropertySet[nProperty].Value >>= sURL;
814             else if (aPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_FILTER)
815                 aPropertySet[nProperty].Value >>= sFilter;
816             else if (aPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_TITLE)
817                 aPropertySet[nProperty].Value >>= sTitle;
818             else if (aPropertySet[nProperty].Name == HISTORY_PROPERTYNAME_PASSWORD)
819                 aPropertySet[nProperty].Value >>= sPassword;
820 
821         // If the entry is an Impress file then insert it into the
822         // history list and the list box.
823         uno::Sequence< beans::PropertyValue > lProps;
824         if (xFilterFactory->hasByName(sFilter))
825         {
826             uno::Any aFilterPropSet = xFilterFactory->getByName( sFilter );
827             aFilterPropSet >>= lProps;
828         }
829 
830         sal_Int32 nPropCount = lProps.getLength();
831         rtl::OUString sFactoryName;
832         for( sal_Int32 i=0; i<nPropCount; ++i )
833         {
834             if( lProps[i].Name.compareToAscii( "DocumentService" ) == 0 &&
835                 (lProps[i].Value >>= sFactoryName) &&
836                 sFactoryName.compareToAscii( "com.sun.star.presentation.PresentationDocument" ) == 0 )
837             {
838                 // yes, it's an Impress document
839                 INetURLObject aURL;
840 
841                 // Do not include the file if it does not exist.
842                 if (xFileAccess.is() && ! xFileAccess->exists(sURL))
843                     continue;
844 
845                 aURL.SetSmartURL (sURL);
846                 // The password is set only when it is not empty.
847                 if (sPassword.getLength() > 0)
848                     aURL.SetPass (sPassword);
849                 maOpenFilesList.push_back (new String (aURL.GetMainURL( INetURLObject::NO_DECODE )));
850                 mpPage1OpenLB->InsertEntry (sTitle);
851                 break;
852             }
853         }
854     }
855     mbRecentDocumentsReady = sal_True;
856     try
857     {
858         UpdatePreview(sal_True);
859     }
860     catch (uno::RuntimeException& )
861     {
862         // Ignore all exceptions.
863     }
864 }
865 
866 
867 
868 void AssistentDlgImpl::ProvideTemplates (void)
869 {
870     if ( ! mbTemplatesReady)
871     {
872         TemplateScanner aScanner;
873         aScanner.Scan ();
874         TemplateScanDone (aScanner.GetFolderList());
875 
876         try
877         {
878             UpdatePreview(sal_True);
879         }
880         catch (uno::RuntimeException& e)
881         {
882             // Ignore all exceptions.
883             (void) e;
884         }
885     }
886 }
887 
888 void AssistentDlgImpl::TemplateScanDone (
889     std::vector<TemplateDir*>& rTemplateFolder)
890 {
891     // This method is called from a thread. Therefore we get the solar mutex.
892     ::vos::OGuard aGuard (Application::GetSolarMutex());
893 
894     // Copy the contents of the given template folders to a local list.
895     maPresentList.swap (rTemplateFolder);
896 
897     // Fill in the list box on the first page.
898     int nFirstEntry = 0;
899     mpPage1RegionLB->Clear();
900     std::vector<TemplateDir*>::iterator I;
901     int i;
902     for (i=0,I=maPresentList.begin(); I!=maPresentList.end(); I++,i++)
903     {
904         TemplateDir* pDir = *I;
905         if (pDir == NULL)
906             continue;
907 
908         // HACK! present directory is always initially selected.
909         // We have to look at the first entry to get a URL.
910         if (!pDir->maEntries.empty() )
911         {
912             TemplateEntry* pEntry = pDir->maEntries.front();
913             if (pEntry != NULL)
914                 if (pEntry->msPath.SearchAscii("presnt") != STRING_NOTFOUND)
915                     nFirstEntry = i;
916         }
917 
918         mpPage1RegionLB->InsertEntry (pDir->msRegion);
919     }
920     mpPage1RegionLB->SelectEntryPos ((sal_uInt16)nFirstEntry);
921     mpPage1RegionLB->Update();
922     SelectTemplateRegion (mpPage1RegionLB->GetSelectEntry());
923 
924     // Fill in the list box on the second page.
925     nFirstEntry = 0;
926     mpPage2RegionLB->Clear();
927     for (i=0,I=maPresentList.begin(); I!=maPresentList.end(); I++,i++)
928     {
929         TemplateDir* pDir = *I;
930         if (pDir == NULL)
931             continue;
932 
933         // HACK! layout directory is always initially selected.
934         // We have to look at the first entry to get a URL.
935         if (!pDir->maEntries.empty() )
936         {
937             TemplateEntry* pEntry = pDir->maEntries.front();
938             if (pEntry != NULL)
939                 if (pEntry->msPath.SearchAscii("layout") != STRING_NOTFOUND)
940                     nFirstEntry = i;
941         }
942 
943         mpPage2RegionLB->InsertEntry (pDir->msRegion);
944     }
945     mpPage2RegionLB->SelectEntryPos ((sal_uInt16)nFirstEntry);
946     mpPage2RegionLB->Update();
947     SelectLayoutRegion (mpPage2RegionLB->GetSelectEntry());
948 
949     // Make the changes visible.
950     mbTemplatesReady = sal_True;
951     if (mpWindow)
952         UpdatePage();
953 }
954 
955 
956 
957 
958 // ********************************************************************
959 // Status methods
960 // ********************************************************************
961 
962 void AssistentDlgImpl::SetStartType( StartType eType )
963 {
964     mpPage1EmptyRB->SetState( eType == ST_EMPTY );
965     mpPage1TemplateRB->SetState( eType == ST_TEMPLATE );
966     mpPage1OpenRB->SetState( eType == ST_OPEN );
967     maNextPageButton.Enable( eType != ST_OPEN );
968 
969     mpPage1RegionLB->Show(eType == ST_TEMPLATE);
970     mpPage1TemplateLB->Show(eType == ST_TEMPLATE);
971     mpPage1OpenLB->Show(eType == ST_OPEN);
972     mpPage1OpenPB->Show(eType == ST_OPEN);
973 
974     if (eType == ST_OPEN)
975         maFinishButton.SetText(maOpenStr);
976     else
977         maFinishButton.SetText(maCreateStr);
978 }
979 
980 StartType AssistentDlgImpl::GetStartType()
981 {
982     if( mpPage1EmptyRB->IsChecked() )
983         return ST_EMPTY;
984     else if( mpPage1TemplateRB->IsChecked() )
985         return ST_TEMPLATE;
986     else
987         return ST_OPEN;
988 }
989 
990 String AssistentDlgImpl::GetDocFileName()
991 {
992     String aTitle;
993     if(mpWindow)
994     {
995         aTitle = mpWindow->GetText();
996         sal_uInt16 nPos = aTitle.Search(sal_Unicode('('));
997         if(nPos != STRING_NOTFOUND)
998             aTitle.Erase( nPos-1 );
999     }
1000 
1001     String aDocFile;
1002     if( GetStartType() == ST_TEMPLATE )
1003     {
1004         const sal_uInt16 nEntry = mpPage1TemplateLB->GetSelectEntryPos();
1005         TemplateEntry* pEntry = NULL;
1006         if(nEntry != (sal_uInt16)-1)
1007             pEntry = mpTemplateRegion->maEntries[nEntry];
1008 
1009         if(pEntry)
1010         {
1011             aDocFile = pEntry->msPath;
1012 
1013             aTitle.AppendAscii( RTL_CONSTASCII_STRINGPARAM(  " (" ) );
1014             aTitle.Append( pEntry->msTitle );
1015             aTitle.Append( sal_Unicode(')') );
1016         }
1017     }
1018     else if( GetStartType() == ST_OPEN )
1019     {
1020         const sal_uInt16 nEntry = mpPage1OpenLB->GetSelectEntryPos();
1021         if(nEntry != (sal_uInt16)-1 )
1022             aDocFile = *maOpenFilesList[nEntry];
1023     }
1024 
1025     if(mpWindow)
1026         mpWindow->SetText(aTitle);
1027 
1028     return aDocFile;
1029 }
1030 
1031 String AssistentDlgImpl::GetLayoutFileName()
1032 {
1033     String aFile;
1034     const sal_uInt16 nEntry = mpPage2LayoutLB->GetSelectEntryPos();
1035     TemplateEntry* pEntry = NULL;
1036     if(nEntry != (sal_uInt16)-1 && nEntry > 0)
1037         pEntry = mpLayoutRegion->maEntries[nEntry-1];
1038 
1039     if(pEntry)
1040         aFile = pEntry->msPath;
1041 
1042     return aFile;
1043 }
1044 
1045 SfxObjectShellLock AssistentDlgImpl::GetDocument()
1046 {
1047 // mbPreview = sal_False; // Document nicht anzeigen
1048     UpdatePreview(sal_False); // aber komplett laden
1049     UpdatePageList();
1050 
1051     SfxObjectShell* pShell = xDocShell;
1052     ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell,pShell);
1053     SdDrawDocument* pDoc = pDocShell?pDocShell->GetDoc():NULL;
1054 
1055     if(pDoc)
1056     {
1057         const sal_uInt16 nPageCount = pDoc->GetSdPageCount(PK_STANDARD);
1058         sal_Bool bKiosk = mpPage3PresTypeKioskRB->IsChecked();
1059         sal_uInt32 nNewTime = (sal_uInt32)mpPage3PresTimeTMF->GetTime().GetMSFromTime() / 1000;
1060         if(bKiosk)
1061         {
1062             PresentationSettings& rSettings = pDoc->getPresentationSettings();
1063             rSettings.mbEndless = bKiosk;
1064             rSettings.mnPauseTimeout = (sal_Int32)mpPage3BreakTMF->GetTime().GetMSFromTime() / 1000;
1065             rSettings.mbShowPauseLogo = mpPage3LogoCB->IsChecked();
1066         }
1067 
1068         sal_uInt16 nPgAbsNum = 0;
1069         sal_uInt16 nPgRelNum = 0;
1070         while( nPgAbsNum < nPageCount )
1071         {
1072             SdPage* pPage = pDoc->GetSdPage( nPgRelNum, PK_STANDARD );
1073             if( mpPage5PageListCT->IsPageChecked(nPgAbsNum) )
1074             {
1075                 mpPage3EffectLB->applySelected(pPage);
1076                 const sal_uInt16 nPos = mpPage3SpeedLB->GetSelectEntryPos();
1077                 pPage->setTransitionDuration( (nPos == 0) ? 3.0 : (nPos == 1) ? 2.0 : 1.0 );
1078                 if(bKiosk)
1079                 {
1080                     pPage->SetPresChange( PRESCHANGE_AUTO );
1081                     pPage->SetTime(nNewTime);
1082                 }
1083                 nPgRelNum++;
1084             }
1085             else
1086             {
1087                 // delete this page
1088                 pDoc->DeletePage( (nPgRelNum << 1) + 2 ); // NotizPage loeschen
1089                 pDoc->DeletePage( (nPgRelNum << 1) + 1 ); // delete page
1090             }
1091 
1092             nPgAbsNum++;
1093         }
1094     }
1095     else
1096     {
1097         DBG_ERROR("sd::AssistentDlgImpl::GetDocument(), no template?");
1098     }
1099 
1100     SfxObjectShellLock xRet = xDocShell;
1101     xDocShell = NULL;
1102 
1103     return xRet;
1104 }
1105 
1106 void AssistentDlgImpl::LeavePage()
1107 {
1108     int nPage = maAssistentFunc.GetCurrentPage();
1109 
1110     if( nPage == 4 && mbUserDataDirty )
1111         maPrevTimer.Start();
1112 }
1113 
1114 void AssistentDlgImpl::ChangePage()
1115 {
1116     maNextPageButton.Enable(!maAssistentFunc.IsLastPage());
1117     maLastPageButton.Enable(!maAssistentFunc.IsFirstPage());
1118 
1119     sal_uInt16 nPage = (sal_uInt16)maAssistentFunc.GetCurrentPage();
1120 
1121     if( mpWindow )
1122     {
1123         mpWindow->SetHelpId( PageHelpIds[nPage-1]);
1124     }
1125 
1126     UpdatePage();
1127 
1128     if( maNextPageButton.IsEnabled() )
1129     {
1130         maNextPageButton.ForceFocusEventBroadcast();
1131     }
1132     else
1133         maFinishButton.GrabFocus();
1134 }
1135 
1136 void AssistentDlgImpl::UpdatePage()
1137 {
1138     sal_uInt16 nPage = (sal_uInt16)maAssistentFunc.GetCurrentPage();
1139 
1140     switch(nPage)
1141     {
1142     case 1:
1143         {
1144             // Elemente auf der ersten Page abhaengig vom Starttype zeigen
1145             SetStartType( GetStartType() );
1146             mpPage1TemplateRB->Enable(sal_True /*mbTemplatesReady*/);
1147             break;
1148         }
1149 
1150     case 2:
1151         {
1152             mpPage2RegionLB->Enable(mbTemplatesReady);
1153             mpPage2LayoutLB->Enable(mbTemplatesReady);
1154 
1155             if( GetStartType() != ST_EMPTY )
1156             {
1157                 mpPage2Medium5RB->Enable( sal_True );
1158             }
1159             else
1160             {
1161                 mpPage2Medium5RB->Enable( sal_False );
1162                 if(mpPage2Medium5RB->IsChecked())
1163                     mpPage2Medium1RB->Check();
1164             }
1165 
1166             break;
1167         }
1168     case 5:
1169         {
1170             if(mbDocPreview || maPageListFile != maDocFile)
1171                 mpPage5PageListCT->Clear();
1172 
1173             maUpdatePageListTimer.Start();
1174             break;
1175         }
1176 
1177     case 3:
1178         {
1179             if(GetStartType() != ST_TEMPLATE)
1180                 maNextPageButton.Enable(false);
1181 
1182             sal_Bool bKiosk = mpPage3PresTypeKioskRB->IsChecked();
1183             mpPage3PresTimeFT->Enable(bKiosk);
1184             mpPage3BreakFT->Enable(bKiosk);
1185             mpPage3PresTimeTMF->Enable(bKiosk);
1186             mpPage3BreakTMF->Enable(bKiosk);
1187             mpPage3LogoCB->Enable(bKiosk);
1188             break;
1189         }
1190     }
1191 }
1192 
1193 // ********************************************************************
1194 // UI-Handler
1195 // ********************************************************************
1196 
1197 IMPL_LINK( AssistentDlgImpl, SelectRegionHdl, ListBox *, pLB )
1198 {
1199     if( pLB == mpPage1RegionLB )
1200     {
1201         SelectTemplateRegion( pLB->GetSelectEntry() );
1202         SetStartType( ST_TEMPLATE );
1203         mpPage2Medium5RB->Check();
1204     }
1205     else
1206     {
1207         SelectLayoutRegion( pLB->GetSelectEntry() );
1208     }
1209 
1210     return 0;
1211 }
1212 
1213 IMPL_LINK( AssistentDlgImpl, SelectEffectHdl, void*, EMPTYARG )
1214 {
1215     maEffectPrevTimer.Start();
1216     return 0;
1217 }
1218 
1219 IMPL_LINK( AssistentDlgImpl, OpenButtonHdl, Button*, pButton )
1220 {
1221     // Clear the selection and forward the call.
1222     mpPage1OpenLB->SetNoSelection();
1223     return mpPage1OpenLB->GetDoubleClickHdl().Call(pButton);
1224 }
1225 
1226 IMPL_LINK( AssistentDlgImpl, EffectPreviewHdl, Button *, EMPTYARG )
1227 {
1228     if(mbPreview && xDocShell.Is() )
1229     {
1230         SfxObjectShell* pShell = xDocShell;
1231         DrawDocShell* pDocShell = dynamic_cast< DrawDocShell * >(pShell);
1232         if( pDocShell )
1233         {
1234             SdDrawDocument* pDoc = pDocShell->GetDoc();
1235             if( pDoc )
1236             {
1237                 SdPage* pPage = pDoc->GetSdPage( mnShowPage, PK_STANDARD );
1238                 if( pPage )
1239                     mpPage3EffectLB->applySelected(pPage);
1240             }
1241         }
1242         maPreview.startPreview();
1243     }
1244     return 0;
1245 }
1246 
1247 IMPL_LINK( AssistentDlgImpl, PreviewFlagHdl, CheckBox *, EMPTYARG )
1248 
1249 {
1250     if( maPreviewFlag.IsChecked() != mbPreview )
1251     {
1252         mbPreview = maPreviewFlag.IsChecked();
1253         UpdatePreview(sal_True);
1254     }
1255     return 0;
1256 }
1257 
1258 IMPL_LINK( AssistentDlgImpl, SelectTemplateHdl, ListBox *, EMPTYARG )
1259 {
1260     SetStartType( ST_TEMPLATE );
1261     mpPage2Medium5RB->Check();
1262     mpPage2LayoutLB->SelectEntryPos(0);
1263     maPrevTimer.Start();
1264     return 0;
1265 }
1266 
1267 IMPL_LINK( AssistentDlgImpl, SelectLayoutHdl, ListBox *, EMPTYARG )
1268 {
1269     maPrevTimer.Start();
1270     return 0;
1271 }
1272 
1273 IMPL_LINK( AssistentDlgImpl, SelectFileHdl, ListBox *, EMPTYARG )
1274 {
1275     SetStartType( ST_OPEN );
1276     maPrevTimer.Start();
1277     return 0;
1278 }
1279 
1280 IMPL_LINK( AssistentDlgImpl, PageSelectHdl, Control *, EMPTYARG )
1281 {
1282     sal_uInt16 nPage = mpPage5PageListCT->GetSelectedPage();
1283     if( mnShowPage != nPage )
1284     {
1285         mnShowPage = nPage;
1286         UpdatePreview(sal_False);
1287     }
1288 
1289     return 0;
1290 }
1291 
1292 IMPL_LINK( AssistentDlgImpl, UpdatePageListHdl, void *, EMPTYARG )
1293 {
1294     UpdatePageList();
1295     return 0;
1296 }
1297 
1298 IMPL_LINK( AssistentDlgImpl, UpdatePreviewHdl, void *, EMPTYARG )
1299 {
1300     UpdatePreview( sal_True );
1301     return 0;
1302 }
1303 
1304 IMPL_LINK( AssistentDlgImpl, StartTypeHdl, RadioButton *, pButton )
1305 {
1306     StartType eType = pButton == mpPage1EmptyRB?ST_EMPTY:pButton == mpPage1TemplateRB?ST_TEMPLATE:ST_OPEN;
1307 
1308     if(eType == ST_TEMPLATE)
1309         ProvideTemplates();
1310     else if(eType == ST_OPEN)
1311         ScanDocmenu();
1312 
1313     SetStartType( eType );
1314 
1315     if(eType == ST_TEMPLATE)
1316     {
1317         mpPage1TemplateLB->SelectEntryPos(0);
1318         mpPage2Medium5RB->Check();
1319     }
1320     else if(eType == ST_OPEN)
1321         mpPage1OpenLB->SelectEntryPos(0);
1322 
1323     maPrevTimer.Start();
1324     return 0;
1325 }
1326 
1327 
1328 IMPL_LINK( AssistentDlgImpl, NextPageHdl, PushButton *, EMPTYARG )
1329 {
1330     // When changing from the first to the second page make sure that the
1331     // templates are present.
1332     if (maAssistentFunc.GetCurrentPage() == 1)
1333         ProvideTemplates();
1334 
1335     // Change to the next page.
1336     LeavePage();
1337     maAssistentFunc.NextPage();
1338     ChangePage();
1339     return 0;
1340 }
1341 
1342 IMPL_LINK( AssistentDlgImpl, LastPageHdl, PushButton *, EMPTYARG )
1343 {
1344     LeavePage();
1345     maAssistentFunc.PreviousPage();
1346     ChangePage();
1347     return 0;
1348 }
1349 
1350 IMPL_LINK( AssistentDlgImpl, PresTypeHdl, RadioButton*, EMPTYARG )
1351 {
1352     if(maDocFile.Len() == 0)
1353         {
1354             maNextPageButton.Enable(false);
1355         }
1356 
1357     sal_Bool bKiosk = mpPage3PresTypeKioskRB->IsChecked();
1358     mpPage3PresTimeFT->Enable(bKiosk);
1359     mpPage3BreakFT->Enable(bKiosk);
1360     mpPage3PresTimeTMF->Enable(bKiosk);
1361     mpPage3BreakTMF->Enable(bKiosk);
1362     mpPage3LogoCB->Enable(bKiosk);
1363     return 0;
1364 }
1365 
1366 IMPL_LINK( AssistentDlgImpl, UpdateUserDataHdl, Edit*, EMPTYARG )
1367 {
1368     mbUserDataDirty = sal_True;
1369     String aTopic = mpPage4AskTopicEDT->GetText();
1370     String aName  = mpPage4AskNameEDT->GetText();
1371     String aInfo  = mpPage4AskInfoEDT->GetText();
1372 
1373     if(aTopic.Len() == 0 && aName.Len() == 0 && aInfo.Len() == 0)
1374         maDocFile.Erase();
1375 
1376     return 0;
1377 }
1378 
1379 // ********************************************************************
1380 // ********************************************************************
1381 
1382 void AssistentDlgImpl::SelectTemplateRegion( const String& rRegion )
1383 {
1384     mpPage1TemplateLB->Clear();
1385     std::vector<TemplateDir*>::iterator I;
1386     for (I=maPresentList.begin(); I!=maPresentList.end(); I++)
1387     {
1388         TemplateDir * pDir = *I;
1389         mpTemplateRegion = *I;
1390         if (pDir->msRegion.Equals( rRegion ) )
1391         {
1392             std::vector<TemplateEntry*>::iterator   J;
1393             for (J=pDir->maEntries.begin(); J!=pDir->maEntries.end(); J++)
1394                 mpPage1TemplateLB->InsertEntry ((*J)->msTitle);
1395             mpPage1TemplateLB->Update();
1396             if(GetStartType() == ST_TEMPLATE)
1397             {
1398                 mpPage1TemplateLB->SelectEntryPos( 0 );
1399                 SelectTemplateHdl(NULL);
1400             }
1401             break;
1402         }
1403     }
1404 }
1405 
1406 void AssistentDlgImpl::SelectLayoutRegion( const String& rRegion )
1407 {
1408     mpPage2LayoutLB->Clear();
1409     mpPage2LayoutLB->InsertEntry(String(SdResId(STR_WIZARD_ORIGINAL)));
1410     std::vector<TemplateDir*>::iterator I;
1411     for (I=maPresentList.begin(); I!=maPresentList.end(); I++)
1412     {
1413         TemplateDir * pDir = *I;
1414         mpLayoutRegion = *I;
1415 
1416         if (pDir->msRegion.Equals (rRegion))
1417         {
1418             std::vector<TemplateEntry*>::iterator   J;
1419             for (J=pDir->maEntries.begin(); J!=pDir->maEntries.end(); J++)
1420                 mpPage2LayoutLB->InsertEntry ((*J)->msTitle);
1421             mpPage2LayoutLB->Update();
1422             break;
1423         }
1424     }
1425 }
1426 
1427 void AssistentDlgImpl::UpdateUserData()
1428 {
1429     String aTopic = mpPage4AskTopicEDT->GetText();
1430     String aName  = mpPage4AskNameEDT->GetText();
1431     String aInfo  = mpPage4AskInfoEDT->GetText();
1432 
1433     SfxObjectShell* pShell = xDocShell;
1434     DrawDocShell* pDocShell = PTR_CAST(DrawDocShell,pShell);
1435     SdDrawDocument* pDoc = pDocShell?pDocShell->GetDoc():NULL;
1436     SdPage* pPage = pDoc?pDoc->GetSdPage(0, PK_STANDARD):NULL;
1437 
1438     if(pPage && ( aTopic.Len() != 0 || aName.Len() != 0 || aInfo.Len() != 0 ) )
1439     {
1440         if( pPage->GetAutoLayout() == AUTOLAYOUT_NONE )
1441             pPage->SetAutoLayout(AUTOLAYOUT_TITLE, sal_True);
1442 
1443         SdrTextObj* pObj;
1444         String aEmptyString;
1445 
1446         if( aTopic.Len() )
1447         {
1448             pObj = dynamic_cast<SdrTextObj*>( pPage->GetPresObj( PRESOBJ_TITLE ) );
1449             if( pObj )
1450             {
1451                 pPage->SetObjText( pObj, NULL, PRESOBJ_TITLE, aTopic );
1452                 pObj->NbcSetStyleSheet( pPage->GetStyleSheetForPresObj( PRESOBJ_TITLE ), sal_True );
1453                 pObj->SetEmptyPresObj(sal_False);
1454             }
1455 
1456         }
1457 
1458         if ( aName.Len() || aInfo.Len() )
1459         {
1460             String aStrTmp( aName );
1461             if( aName.Len() )
1462                 aStrTmp.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\n\n" ) );
1463             aStrTmp.Append( aInfo );
1464 
1465             pObj = dynamic_cast<SdrTextObj*>( pPage->GetPresObj( PRESOBJ_OUTLINE ) );
1466             if( pObj )
1467             {
1468                 pPage->SetObjText( pObj, NULL, PRESOBJ_OUTLINE, aStrTmp );
1469                 pObj->NbcSetStyleSheet( pPage->GetStyleSheetForPresObj( PRESOBJ_OUTLINE ), sal_True );
1470                 pObj->SetEmptyPresObj(sal_False);
1471             }
1472             else
1473             {
1474                 pObj = dynamic_cast<SdrTextObj*>( pPage->GetPresObj( PRESOBJ_TEXT ) );
1475                 if( pObj )
1476                 {
1477                     pPage->SetObjText( pObj, NULL, PRESOBJ_TEXT, aStrTmp );
1478                     pObj->NbcSetStyleSheet( pPage->GetStyleSheetForPresObj( PRESOBJ_TEXT ), sal_True );
1479                     pObj->SetEmptyPresObj(sal_False);
1480                 }
1481             }
1482         }
1483     }
1484 
1485     mbUserDataDirty = sal_False;
1486 }
1487 
1488 void AssistentDlgImpl::UpdatePageList()
1489 {
1490     if(mbDocPreview || !mbPreview)
1491         UpdatePreview(sal_False);
1492     else if(maPageListFile == maDocFile)
1493         return;
1494 
1495     maPageListFile = maDocFile;
1496 
1497     SfxObjectShell* pShell = xDocShell;
1498     DrawDocShell* pDocShell = PTR_CAST(DrawDocShell,pShell);
1499     SdDrawDocument* pDoc = pDocShell?pDocShell->GetDoc():NULL;
1500 
1501     mpPage5PageListCT->Clear();
1502 
1503     if(pDoc)
1504         mpPage5PageListCT->Fill(pDoc);
1505 }
1506 
1507 void AssistentDlgImpl::UpdatePreview( sal_Bool bDocPreview )
1508 {
1509     // Guard against multiple concurrent execution to this method caused either
1510     // by calls from different threads or recursion.
1511     ::osl::MutexGuard aGuard (maMutex);
1512     if (mbPreviewUpdating)
1513         return;
1514     mbPreviewUpdating = sal_True;
1515 
1516     if(!mbPreview && bDocPreview)
1517     {
1518         maPreview.Invalidate();
1519         maPreview.SetObjectShell(0);
1520         mbPreviewUpdating = sal_False;
1521         return;
1522     }
1523 
1524     String aDocFile = GetDocFileName();
1525     String aLayoutFile = GetLayoutFileName();
1526     String aEmptyStr;
1527 
1528     SfxApplication *pSfxApp = SFX_APP();
1529     sal_uLong lErr;
1530     sal_Bool bChangeMaster = aLayoutFile.Len() != 0;
1531 
1532     if( aDocFile.Len() == 0 )
1533     {
1534         if( !xDocShell.Is() || maDocFile.Len() != 0 ||
1535             (maDocFile.Len() == 0 && maLayoutFile.Len() != 0 && aLayoutFile.Len() == 0 ))
1536         {
1537             CloseDocShell();
1538 
1539             DrawDocShell* pNewDocSh;
1540             xDocShell = pNewDocSh = new DrawDocShell(SFX_CREATE_MODE_STANDARD, sal_False);
1541             pNewDocSh->DoInitNew(NULL);
1542             SdDrawDocument* pDoc = pNewDocSh->GetDoc();
1543             pDoc->CreateFirstPages();
1544             pDoc->StopWorkStartupDelay();
1545             mbDocPreview = sal_False;
1546 
1547             maDocFile = aDocFile;
1548             mbUserDataDirty = sal_True;
1549         }
1550         else
1551             bChangeMaster = (aLayoutFile.Len() != 0) && (maLayoutFile != aLayoutFile);
1552     }
1553     else if( aDocFile == maDocFile && ( mbDocPreview == bDocPreview || bDocPreview ) )
1554     {
1555         if( aLayoutFile != maLayoutFile )
1556         {
1557             SfxObjectShell* pShell = xDocShell;
1558             DrawDocShell* pDocShell = PTR_CAST(DrawDocShell,pShell);
1559             ::svl::IUndoManager* pUndoMgr = pDocShell?pDocShell->GetUndoManager():NULL;
1560             if(pUndoMgr)
1561                 pUndoMgr->Undo();
1562             mbUserDataDirty = sal_True;
1563         }
1564         else
1565             bChangeMaster = sal_False;
1566     }
1567     else
1568     {
1569         CloseDocShell();
1570 
1571         ::Window *pParent = Application::GetDefDialogParent();
1572         Application::SetDefDialogParent( mpWindow );
1573 
1574         SfxErrorContext eEC(ERRCTX_SFX_LOADTEMPLATE,mpWindow);
1575 
1576         SfxItemSet* pSet = new SfxAllItemSet( pSfxApp->GetPool() );
1577         if(IsOwnFormat(aDocFile))
1578         {
1579             pSet->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
1580             if(bDocPreview)
1581                 pSet->Put( SfxBoolItem( SID_PREVIEW, sal_True ) );
1582             RestorePassword( pSet, aDocFile );
1583             if( (lErr = pSfxApp->LoadTemplate( xDocShell, aDocFile, sal_True, pSet )) != 0 )
1584                 ErrorHandler::HandleError(lErr);
1585             else
1586                 SavePassword( xDocShell, aDocFile );
1587         }
1588         else
1589         {
1590             const String aTargetStr( RTL_CONSTASCII_USTRINGPARAM("_default") );
1591 
1592             SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() );
1593             aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aDocFile ));
1594             aReq.AppendItem( SfxStringItem( SID_REFERER, aEmptyStr ) );
1595             aReq.AppendItem( SfxStringItem( SID_TARGETNAME, aTargetStr ) );
1596             aReq.AppendItem( SfxBoolItem( SID_HIDDEN, sal_True ) );
1597             aReq.AppendItem( SfxBoolItem( SID_PREVIEW, bDocPreview ) );
1598 
1599             const SfxViewFrameItem* pRet = PTR_CAST( SfxViewFrameItem, SFX_APP()->ExecuteSlot( aReq ) );
1600 
1601             if ( pRet && pRet->GetFrame() && pRet->GetFrame()->GetObjectShell() )
1602                 xDocShell = pRet->GetFrame()->GetObjectShell();
1603         }
1604 
1605 
1606         Application::SetDefDialogParent( pParent );
1607 
1608         mnShowPage = 0;
1609         mbDocPreview = bDocPreview;
1610         maDocFile = aDocFile;
1611         mbUserDataDirty = sal_True;
1612     }
1613 
1614     if(bChangeMaster && (aLayoutFile != maDocFile))
1615     {
1616         // Layoutvorlage laden
1617         SfxObjectShellLock xLayoutDocShell;
1618         SfxErrorContext eEC(ERRCTX_SFX_LOADTEMPLATE,mpWindow);
1619         SfxItemSet* pSet = new SfxAllItemSet( pSfxApp->GetPool() );
1620 
1621         ::Window *pParent = Application::GetDefDialogParent();
1622         Application::SetDefDialogParent( mpWindow );
1623 
1624         if(IsOwnFormat(aLayoutFile))
1625         {
1626             pSet->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
1627             pSet->Put( SfxBoolItem( SID_PREVIEW, sal_True ) );
1628 
1629             RestorePassword( pSet, aLayoutFile );
1630             if( (lErr = pSfxApp->LoadTemplate( xLayoutDocShell, aLayoutFile, sal_True, pSet )) != 0 )
1631                 ErrorHandler::HandleError(lErr);
1632             SavePassword( xLayoutDocShell, aLayoutFile );
1633         }
1634 
1635         Application::SetDefDialogParent( pParent );
1636 
1637         // die Implementierung ermitteln
1638         SfxObjectShell* pShell = xDocShell;
1639         DrawDocShell* pDocShell = PTR_CAST(DrawDocShell,pShell);
1640         SdDrawDocument* pDoc = pDocShell?pDocShell->GetDoc():NULL;
1641 
1642         pShell = xLayoutDocShell;
1643         pDocShell = PTR_CAST(DrawDocShell,pShell);
1644         SdDrawDocument* pLayoutDoc = pDocShell?pDocShell->GetDoc():NULL;
1645 
1646         if( pDoc && pLayoutDoc )
1647         {
1648             pDoc->SetMasterPage(0, aEmptyStr, pLayoutDoc, sal_True, sal_False );
1649         }
1650         else
1651         {
1652             DBG_ERROR("sd::AssistentDlgImpl::UpdatePreview(), no document for preview?");
1653         }
1654 
1655         mbUserDataDirty = sal_True;
1656     }
1657     maLayoutFile = aLayoutFile;
1658 
1659     if(mbUserDataDirty)
1660         UpdateUserData();
1661 
1662     if ( !xDocShell.Is() || !mbPreview )
1663         maPreview.SetObjectShell( 0 );
1664     else
1665     {
1666         maPreview.SetObjectShell( xDocShell, mnShowPage );
1667     }
1668 
1669     mbPreviewUpdating = sal_False;
1670 }
1671 
1672 void AssistentDlgImpl::SavePassword( SfxObjectShellLock xDoc, const String& rPath )
1673 {
1674     if(xDoc.Is())
1675     {
1676         SfxMedium * pMedium = xDoc->GetMedium();
1677         if(pMedium && pMedium->IsStorage())
1678         {
1679             SfxItemSet * pSet = pMedium->GetItemSet();
1680             const SfxPoolItem *pItem = 0;
1681             if( pSet->GetItemState(SID_PASSWORD, sal_True, &pItem) == SFX_ITEM_SET )
1682             {
1683                 // TODO/MBA: testing
1684                 String aPass( ((const SfxStringItem*)pItem)->GetValue());
1685                 if(aPass.Len() == 0)
1686                     return;
1687 
1688             PasswordEntry* pEntry = maPasswordList.First();
1689             while(pEntry)
1690             {
1691                 if(pEntry->maPath == rPath)
1692                     break;
1693 
1694                 pEntry = maPasswordList.Next();
1695 
1696             }
1697 
1698             if(pEntry == NULL)
1699             {
1700                 pEntry = new PasswordEntry();
1701                 pEntry->maPath = rPath;
1702                 maPasswordList.Insert( pEntry );
1703             }
1704 
1705             if(pEntry)
1706                 pEntry->maPassword = aPass;
1707             }
1708         }
1709     }
1710 }
1711 
1712 void AssistentDlgImpl::RestorePassword( SfxItemSet* pSet, const String& rPath )
1713 {
1714     String aPassword( GetPassword( rPath ) );
1715 
1716     if(aPassword.Len())
1717         pSet->Put( SfxStringItem( SID_PASSWORD, aPassword ) );
1718 }
1719 
1720 String AssistentDlgImpl::GetPassword( const String rPath )
1721 {
1722     PasswordEntry* pEntry = maPasswordList.First();
1723     while(pEntry)
1724     {
1725         if(pEntry->maPath == rPath)
1726             return pEntry->maPassword;
1727 
1728         pEntry = maPasswordList.Next();
1729     }
1730 
1731     return String();
1732 }
1733 
1734 void AssistentDlgImpl::DeletePassords()
1735 {
1736     PasswordEntry* pEntry = maPasswordList.First();
1737     while(pEntry)
1738     {
1739         delete pEntry;
1740         pEntry = maPasswordList.Next();
1741     }
1742 }
1743 
1744 sal_Bool AssistentDlgImpl::IsOwnFormat( const String& rPath )
1745 {
1746     INetURLObject   aURL( rPath );
1747     String          aExt( aURL.GetFileExtension() );
1748 
1749     DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
1750 
1751     return !aExt.EqualsIgnoreCaseAscii( "ppt" );
1752 }
1753 
1754 
1755 
1756 
1757 String AssistentDlgImpl::GetUiTextForCommand (const ::rtl::OUString& sCommandURL)
1758 {
1759     String sLabel;
1760     Reference<container::XNameAccess> xUICommandLabels;
1761 
1762     try
1763     {
1764         do
1765         {
1766             if (sCommandURL.getLength() == 0)
1767                 break;
1768 
1769             // Retrieve popup menu labels
1770             Reference<lang::XMultiServiceFactory> xFactory (
1771                 ::comphelper::getProcessServiceFactory ());
1772             if ( ! xFactory.is())
1773                 break;
1774 
1775             ::rtl::OUString sModuleIdentifier (
1776                 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"));
1777             Reference<container::XNameAccess> xNameAccess (
1778                 xFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1779                     "com.sun.star.frame.UICommandDescription"))),
1780                 UNO_QUERY);
1781             if ( ! xNameAccess.is())
1782                 break;
1783             Any a = xNameAccess->getByName(sModuleIdentifier);
1784             a >>= xUICommandLabels;
1785             if ( ! xUICommandLabels.is())
1786                 break;
1787 
1788             ::rtl::OUString sString;
1789             Sequence<beans::PropertyValue> aProperties;
1790             Any aAny (xUICommandLabels->getByName(sCommandURL));
1791             if (aAny >>= aProperties)
1792             {
1793                 sal_Int32 nCount (aProperties.getLength());
1794                 for (sal_Int32 i=0; i<nCount; i++)
1795                 {
1796                     ::rtl::OUString sPropertyName (aProperties[i].Name);
1797                     if (sPropertyName.equalsAscii("Label"))
1798                     {
1799                         aProperties[i].Value >>= sString;
1800                         break;
1801                     }
1802                 }
1803             }
1804             sLabel = sString;
1805         }
1806         while(false);
1807     }
1808     catch (com::sun::star::uno::Exception& rException)
1809     {
1810         (void)rException;
1811     }
1812 
1813     return sLabel;
1814 }
1815 
1816 
1817 
1818 
1819 Image AssistentDlgImpl::GetUiIconForCommand (const ::rtl::OUString& sCommandURL)
1820 {
1821     Image aIcon;
1822     Reference<container::XNameAccess> xUICommandLabels;
1823 
1824     try
1825     {
1826         do
1827         {
1828             if (sCommandURL.getLength() == 0)
1829                 break;
1830 
1831             // Retrieve popup menu labels
1832             Reference<lang::XMultiServiceFactory> xFactory (
1833                 ::comphelper::getProcessServiceFactory ());
1834             if ( ! xFactory.is())
1835                 break;
1836 
1837             ::rtl::OUString sModuleIdentifier (
1838                 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.PresentationDocument"));
1839 
1840             Reference<com::sun::star::ui::XModuleUIConfigurationManagerSupplier> xSupplier (
1841                 xFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
1842                     "com.sun.star.ui.ModuleUIConfigurationManagerSupplier"))),
1843                 UNO_QUERY_THROW);
1844 
1845             Reference<com::sun::star::ui::XUIConfigurationManager> xManager (
1846                 xSupplier->getUIConfigurationManager(sModuleIdentifier));
1847             if ( ! xManager.is())
1848                 break;
1849 
1850             Reference<com::sun::star::ui::XImageManager> xImageManager (
1851                 xManager->getImageManager(),
1852                 UNO_QUERY_THROW);
1853 
1854             Sequence<rtl::OUString> aCommandList(1);
1855             aCommandList[0] = sCommandURL;
1856             Sequence<Reference<graphic::XGraphic> > xIconList (
1857                 xImageManager->getImages(0,aCommandList));
1858             if ( ! xIconList.hasElements())
1859                 break;
1860 
1861             aIcon = Graphic(xIconList[0]).GetBitmapEx();
1862         }
1863         while(false);
1864     }
1865     catch (com::sun::star::uno::Exception& rException)
1866     {
1867         (void)rException;
1868     }
1869 
1870     return aIcon;
1871 }
1872 
1873 
1874 //////////////////////////////////////////////
1875 
1876 AssistentDlg::AssistentDlg(Window* pParent, sal_Bool bAutoPilot) :
1877     ModalDialog(pParent,SdResId(DLG_ASS))
1878 {
1879     Link aFinishLink = LINK(this,AssistentDlg, FinishHdl);
1880     mpImpl = new AssistentDlgImpl( this, aFinishLink, bAutoPilot );
1881 
1882     // Buttonbelegung
1883     mpImpl->maFinishButton.SetClickHdl(LINK(this,AssistentDlg,FinishHdl));
1884 
1885     FreeResource();
1886 }
1887 
1888 IMPL_LINK( AssistentDlg, FinishHdl, OKButton *, EMPTYARG )
1889 {
1890     if( GetStartType() == ST_OPEN )
1891     {
1892         // if we do not have a file here asked for one before ending the dialog
1893         String aFileToOpen = GetDocPath();
1894         if(aFileToOpen.Len() == 0)
1895         {
1896             sfx2::FileDialogHelper aFileDlg( WB_OPEN, ::String::CreateFromAscii("simpress") );
1897 
1898             if ( aFileDlg.Execute() == ERRCODE_NONE )
1899                 aFileToOpen = aFileDlg.GetPath();
1900             if( aFileToOpen.Len() == 0)
1901                 return 1;
1902             else
1903             {
1904                 //add the selected file to the recent-file-listbox and select the new entry
1905                 //this is necessary for 'GetDocPath()' returning the selected file after end of dialog
1906 
1907                 INetURLObject aURL;
1908                 aURL.SetSmartURL(aFileToOpen);
1909                 mpImpl->maOpenFilesList.push_back (new String (aURL.GetMainURL( INetURLObject::NO_DECODE )));
1910                 sal_uInt16 nNewPos = mpImpl->mpPage1OpenLB->InsertEntry(aURL.getName());
1911                 mpImpl->mpPage1OpenLB->SelectEntryPos(nNewPos);
1912             }
1913         }
1914     }
1915 
1916     // End
1917     mpImpl->EndDialog(RET_OK);
1918     EndDialog(RET_OK);
1919     return 0;
1920 }
1921 
1922 AssistentDlg::~AssistentDlg()
1923 {
1924     delete mpImpl;
1925 }
1926 
1927 
1928 SfxObjectShellLock AssistentDlg::GetDocument()
1929 {
1930     return mpImpl->GetDocument();
1931 }
1932 
1933 OutputType AssistentDlg::GetOutputMedium() const
1934 {
1935     if(mpImpl->mpPage2Medium1RB->IsChecked())
1936         return OUTPUT_SCREEN_4_BY_3;
1937     else if(mpImpl->mpPage2Medium2RB->IsChecked())
1938         return OUTPUT_SCREEN_16_BY_9;
1939     else if(mpImpl->mpPage2Medium6RB->IsChecked())
1940         return OUTPUT_SCREEN_16_BY_10;
1941     else if(mpImpl->mpPage2Medium3RB->IsChecked())
1942         return OUTPUT_OVERHEAD;
1943     else if(mpImpl->mpPage2Medium4RB->IsChecked())
1944         return OUTPUT_PAGE;
1945     else
1946         return OUTPUT_ORIGINAL;
1947 }
1948 
1949 sal_Bool AssistentDlg::IsSummary() const
1950 {
1951     return mpImpl->mpPage5SummaryCB->IsChecked();
1952 }
1953 
1954 StartType AssistentDlg::GetStartType() const
1955 {
1956     return mpImpl->GetStartType();
1957 }
1958 
1959 String AssistentDlg::GetDocPath() const
1960 {
1961     return mpImpl->GetDocFileName();
1962 }
1963 
1964 sal_Bool AssistentDlg::GetStartWithFlag() const
1965 {
1966     return !mpImpl->maStartWithFlag.IsChecked();
1967 }
1968 
1969 sal_Bool AssistentDlg::IsDocEmpty() const
1970 {
1971     return mpImpl->GetDocFileName().Len() == 0 &&
1972            mpImpl->GetLayoutFileName().Len() == 0;
1973 }
1974 
1975 String AssistentDlg::GetPassword()
1976 {
1977     return mpImpl->GetPassword( mpImpl->maDocFile );
1978 }
1979 
1980 
1981 
1982 
1983 //===== NextButton ============================================================
1984 
1985 NextButton::NextButton (::Window* pParent, const ResId& rResId)
1986     : maNextButton1(pParent, rResId),
1987       maNextButton2(pParent, rResId),
1988       mbIsFirstButtonActive(true)
1989 {
1990     // Hide the unused button.
1991     maNextButton2.Hide();
1992 }
1993 
1994 
1995 
1996 
1997 void NextButton::ForceFocusEventBroadcast (void)
1998 {
1999     // Hide the currently visible button and show and focus the other one.
2000     if (mbIsFirstButtonActive)
2001     {
2002         mbIsFirstButtonActive = false;
2003         maNextButton2.Show();
2004         maNextButton2.GrabFocus();
2005         maNextButton1.Hide();
2006     }
2007     else
2008     {
2009         mbIsFirstButtonActive = true;
2010         maNextButton1.Show();
2011         maNextButton1.GrabFocus();
2012         maNextButton2.Hide();
2013     }
2014 }
2015 
2016 
2017 
2018 
2019 void NextButton::SetClickHdl (const Link& rLink)
2020 {
2021     // Forward the setting of the click handler to the two buttons
2022     // regardless of which one is currently visible.
2023     maNextButton1.SetClickHdl(rLink);
2024     maNextButton2.SetClickHdl(rLink);
2025 }
2026 
2027 
2028 
2029 
2030 bool NextButton::IsEnabled (void)
2031 {
2032     // Because the buttons are both either enabled or disabled, it is
2033     // sufficient to ask one to determine the state.
2034     return maNextButton1.IsEnabled();
2035 }
2036 
2037 
2038 
2039 
2040 void NextButton::Enable (bool bEnable)
2041 {
2042     // Enable or disable both buttons but do not change visibility or focus.
2043     maNextButton1.Enable(bEnable);
2044     maNextButton2.Enable(bEnable);
2045 }
2046 
2047 /* vim: set noet sw=4 ts=4: */
2048