xref: /trunk/main/sfx2/source/doc/new.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 <sfx2/new.hxx>
31 #include <vcl/gdimtf.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <vcl/morebtn.hxx>
34 #include <svtools/svmedit.hxx>
35 #include <svl/itemset.hxx>
36 #include <svl/eitem.hxx>
37 #include <svtools/sfxecode.hxx>
38 #include <svtools/ehdl.hxx>
39 #include <tools/urlobj.hxx>
40 #include <unotools/localfilehelper.hxx>
41 
42 #include "new.hrc"
43 #include "doc.hrc"
44 #include <sfx2/sfx.hrc>
45 #include "helpid.hrc"
46 #include "sfxtypes.hxx"
47 #include <sfx2/app.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <sfx2/docfac.hxx>
50 #include <sfx2/objsh.hxx>
51 #include "fltfnc.hxx"
52 #include <sfx2/viewsh.hxx>
53 #include "sfx2/viewfac.hxx"
54 #include "sfx2/sfxresid.hxx"
55 #include <sfx2/docfile.hxx>
56 #include "preview.hxx"
57 #include <sfx2/printer.hxx>
58 #include <vcl/waitobj.hxx>
59 #include <vcl/virdev.hxx>
60 #include <vcl/jobset.hxx>
61 #include <svtools/accessibilityoptions.hxx>
62 
63 // Draw modes
64 #define OUTPUT_DRAWMODE_COLOR       (DRAWMODE_DEFAULT)
65 #define OUTPUT_DRAWMODE_GRAYSCALE   (DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_BLACKTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT)
66 #define OUTPUT_DRAWMODE_BLACKWHITE  (DRAWMODE_BLACKLINE | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEFILL | DRAWMODE_GRAYBITMAP | DRAWMODE_WHITEGRADIENT)
67 #define OUTPUT_DRAWMODE_CONTRAST    (DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT)
68 
69 //========================================================================
70 
71 #define MORE_BTN(x) pMoreBt->x
72 
73 //========================================================================
74 
75 void SfxPreviewBase_Impl::SetObjectShell( SfxObjectShell* pObj )
76 {
77     ::boost::shared_ptr<GDIMetaFile> pFile = pObj
78         ? pObj->GetPreviewMetaFile()
79         : ::boost::shared_ptr<GDIMetaFile>();
80     pMetaFile = pFile;
81     Invalidate();
82 }
83 
84 SfxPreviewBase_Impl::SfxPreviewBase_Impl(
85     Window* pParent, const ResId& rResId )
86     : Window(pParent, rResId), pMetaFile()
87 {
88 }
89 
90 SfxPreviewBase_Impl::SfxPreviewBase_Impl( Window* pParent )
91     : Window(pParent, 0 ), pMetaFile()
92 {
93     Resize();
94     Show();
95 }
96 
97 SfxPreviewBase_Impl::~SfxPreviewBase_Impl()
98 {
99 }
100 
101 void SfxPreviewBase_Impl::Resize()
102 {
103     Invalidate();
104 }
105 
106 void SfxPreviewBase_Impl::SetGDIFile( ::boost::shared_ptr<GDIMetaFile> pFile )
107 {
108     pMetaFile = pFile;
109     Invalidate();
110 }
111 
112 SfxFrameWindow* SfxPreviewWin_Impl::PreviewFactory(
113     SfxFrame* pFrame, const String& /*rName*/ )
114 {
115     return new SfxFrameWindow( new SfxPreviewWin_Impl(
116         &pFrame->GetCurrentViewFrame()->GetWindow()  ) );
117 }
118 
119 void SfxPreviewWin_Impl::ImpPaint(
120     const Rectangle&, GDIMetaFile* pFile, Window* pWindow )
121 {
122     Size aTmpSize = pFile ? pFile->GetPrefSize() : Size(1,1 );
123     DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
124                 "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
125 #define FRAME 4
126     long nWidth = pWindow->GetOutputSize().Width() - 2*FRAME;
127     long nHeight = pWindow->GetOutputSize().Height() - 2*FRAME;
128     if( nWidth < 0 ) nWidth = 0;
129     if( nHeight < 0 ) nHeight = 0;
130 
131     double dRatio=((double)aTmpSize.Width())/aTmpSize.Height();
132     double dRatioPreV=((double) nWidth ) / nHeight;
133     Size aSize;
134     Point aPoint;
135     if (dRatio>dRatioPreV)
136     {
137         aSize=Size(nWidth, (sal_uInt16)(nWidth/dRatio));
138         aPoint=Point( 0, (sal_uInt16)((nHeight-aSize.Height())/2));
139     }
140     else
141     {
142         aSize=Size((sal_uInt16)(nHeight*dRatio), nHeight);
143         aPoint=Point((sal_uInt16)((nWidth-aSize.Width())/2),0);
144     }
145     Point bPoint=Point(nWidth,nHeight)-aPoint;
146 
147 
148     pWindow->SetLineColor();
149     Color aLightGrayCol( COL_LIGHTGRAY );
150     pWindow->SetFillColor( aLightGrayCol );
151     pWindow->DrawRect( Rectangle( Point( 0,0 ), pWindow->GetOutputSize() ) );
152     if ( pFile )
153     {
154         Color aBlackCol( COL_BLACK );
155         Color aWhiteCol( COL_WHITE );
156         pWindow->SetLineColor( aBlackCol );
157         pWindow->SetFillColor( aWhiteCol );
158         pWindow->DrawRect( Rectangle( aPoint + Point( FRAME, FRAME ), bPoint + Point( FRAME, FRAME ) ) );
159 //!     pFile->Move( Point( FRAME, FRAME ) );
160 //!     pFile->Scale( Fraction( aTmpSize.Width(), aSize.Width() ),
161 //!                   Fraction( aTmpSize.Height(), aSize.Height() ) );
162         pFile->WindStart();
163         pFile->Play( pWindow, aPoint + Point( FRAME, FRAME ), aSize  );
164     }
165 }
166 
167 void SfxPreviewWin_Impl::Paint( const Rectangle& rRect )
168 {
169     ImpPaint( rRect, pMetaFile.get(), this );
170 }
171 
172 SfxPreviewWin::SfxPreviewWin(
173     Window* pParent, const ResId& rResId, SfxObjectShellLock &rDocSh )
174     : Window(pParent, rResId), rDocShell( rDocSh )
175 {
176     SetHelpId( HID_PREVIEW_FRAME );
177 
178     // adjust contrast mode initially
179     bool bUseContrast = UseHighContrastSetting();
180     SetDrawMode( bUseContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
181 
182     // #107818# This preview window is for document previews.  Therefore
183     // right-to-left mode should be off
184     EnableRTL( sal_False );
185 }
186 
187 void SfxPreviewWin::Paint( const Rectangle& rRect )
188 {
189     SfxViewFrame *pFrame = SfxViewFrame::GetFirst( &rDocShell );
190     if ( pFrame && pFrame->GetViewShell() &&
191          pFrame->GetViewShell()->GetPrinter() &&
192          pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
193     {
194         return;
195     }
196 
197     Size            aTmpSize( rDocShell->GetFirstPageSize() );
198     GDIMetaFile     aMtf;
199     VirtualDevice   aDevice;
200 
201     DBG_ASSERT( aTmpSize.Height() * aTmpSize.Width(), "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
202 
203     aMtf.SetPrefSize( aTmpSize );
204     aDevice.EnableOutput( sal_False );
205     aDevice.SetMapMode( rDocShell->GetMapUnit() );
206     aDevice.SetDrawMode( GetDrawMode() );
207     aMtf.Record( &aDevice );
208     rDocShell->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), ASPECT_THUMBNAIL );
209     aMtf.Stop();
210     aMtf.WindStart();
211     SfxPreviewWin_Impl::ImpPaint( rRect, &aMtf, this );
212 }
213 
214 void SfxPreviewWin::DataChanged( const DataChangedEvent& rDCEvt )
215 {
216     Window::DataChanged( rDCEvt );
217 
218     if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
219         (rDCEvt.GetFlags() & SETTINGS_STYLE) )
220     {
221         // adjust contrast mode
222         bool bUseContrast = UseHighContrastSetting();
223         SetDrawMode( bUseContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
224     }
225 }
226 
227 bool SfxPreviewWin::UseHighContrastSetting() const
228 {
229     return GetSettings().GetStyleSettings().GetHighContrastMode();
230 }
231 
232 
233 class SfxNewFileDialog_Impl
234 {
235     FixedText aRegionFt;
236     ListBox aRegionLb;
237     FixedText aTemplateFt;
238     ListBox aTemplateLb;
239 
240     CheckBox aPreviewBtn;
241     SfxPreviewWin_Impl aPreviewWin;
242 
243     FixedText aTitleFt;
244     Edit aTitleEd;
245     FixedText aThemaFt;
246     Edit aThemaEd;
247     FixedText aKeywordsFt;
248     Edit aKeywordsEd;
249     FixedText aDescFt;
250     MultiLineEdit aDescEd;
251     FixedLine aDocinfoGb;
252 
253     CheckBox aTextStyleCB;
254     CheckBox aFrameStyleCB;
255     CheckBox aPageStyleCB;
256     CheckBox aNumStyleCB;
257     CheckBox aMergeStyleCB;
258     PushButton aLoadFilePB;
259 
260     OKButton aOkBt;
261     CancelButton aCancelBt;
262     HelpButton aHelpBt;
263     MoreButton* pMoreBt;
264     Timer aPrevTimer;
265     String aNone;
266     String sLoadTemplate;
267 
268     sal_uInt16 nFlags;
269     SfxDocumentTemplates aTemplates;
270     SfxObjectShellLock xDocShell;
271     SfxNewFileDialog* pAntiImpl;
272 
273     void ClearInfo();
274     DECL_LINK( Update, void * );
275 
276     DECL_LINK( RegionSelect, ListBox * );
277     DECL_LINK( TemplateSelect, ListBox * );
278     DECL_LINK( DoubleClick, ListBox * );
279     void TogglePreview(CheckBox *);
280     DECL_LINK( Expand, MoreButton * );
281     DECL_LINK( PreviewClick, CheckBox * );
282     DECL_LINK( LoadFile, PushButton* );
283     sal_uInt16  GetSelectedTemplatePos() const;
284 
285 public:
286 
287     SfxNewFileDialog_Impl( SfxNewFileDialog* pAntiImplP, sal_uInt16 nFlags );
288     ~SfxNewFileDialog_Impl();
289 
290         // Liefert sal_False, wenn '- Keine -' als Vorlage eingestellt ist
291         // Nur wenn IsTemplate() sal_True liefert, koennen Vorlagennamen
292         // erfragt werden
293     sal_Bool IsTemplate() const;
294     String GetTemplateRegion() const;
295     String GetTemplateName() const;
296     String GetTemplateFileName() const;
297 
298     sal_uInt16  GetTemplateFlags()const;
299     void    SetTemplateFlags(sal_uInt16 nSet);
300 };
301 
302 
303 //-------------------------------------------------------------------------
304 
305 void SfxNewFileDialog_Impl::ClearInfo()
306 {
307     const String aNo;
308     aTitleEd.SetText(aNo);
309     aThemaEd.SetText(aNo);
310     aKeywordsEd.SetText(aNo);
311     aDescEd.SetText(aNo);
312 }
313 
314 //-------------------------------------------------------------------------
315 
316 IMPL_LINK( SfxNewFileDialog_Impl, Update, void *, EMPTYARG )
317 {
318     if ( xDocShell.Is() )
319     {
320         if ( xDocShell->GetProgress() )
321             return sal_False;
322         xDocShell.Clear();
323     }
324 
325     const sal_uInt16 nEntry = GetSelectedTemplatePos();
326     if(!nEntry)
327     {
328         ClearInfo();
329         aPreviewWin.Invalidate();
330         aPreviewWin.SetObjectShell( 0);
331         return 0;
332     }
333 
334     if ( aPreviewBtn.IsChecked() && (nFlags & SFXWB_PREVIEW) == SFXWB_PREVIEW)
335     {
336 
337         String aFileName = aTemplates.GetPath( aRegionLb.GetSelectEntryPos(), nEntry-1);
338         INetURLObject aTestObj( aFileName );
339         if( aTestObj.GetProtocol() == INET_PROT_NOT_VALID )
340         {
341             // temp. fix until Templates are managed by UCB compatible service
342             // does NOT work with locally cached components !
343             String aTemp;
344             utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aTemp );
345             aFileName = aTemp;
346         }
347 
348         INetURLObject aObj( aFileName );
349         for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst();
350               pTmp;
351               pTmp = SfxObjectShell::GetNext(*pTmp) )
352         {
353             //! fsys bug op==
354             if ( pTmp->GetMedium())
355                 // ??? HasName() MM
356                 if( INetURLObject( pTmp->GetMedium()->GetName() ) == aObj )
357                 {
358                     xDocShell = pTmp;
359                     break;
360                 }
361         }
362 
363         if ( !xDocShell.Is() )
364         {
365             Window *pParent = Application::GetDefDialogParent();
366             Application::SetDefDialogParent( pAntiImpl );
367             SfxErrorContext eEC(ERRCTX_SFX_LOADTEMPLATE,pAntiImpl);
368             SfxApplication *pSfxApp = SFX_APP();
369             sal_uIntPtr lErr;
370             SfxItemSet* pSet = new SfxAllItemSet( pSfxApp->GetPool() );
371             pSet->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
372             pSet->Put( SfxBoolItem( SID_PREVIEW, sal_True ) );
373             lErr = pSfxApp->LoadTemplate( xDocShell, aFileName, sal_True, pSet );
374             if( lErr )
375                 ErrorHandler::HandleError(lErr);
376             Application::SetDefDialogParent( pParent );
377             if ( !xDocShell.Is() )
378             {
379                 aPreviewWin.SetObjectShell( 0 );
380                 return sal_False;
381             }
382         }
383 
384         aPreviewWin.SetObjectShell( xDocShell );
385     }
386     return sal_True;
387 }
388 
389 //-------------------------------------------------------------------------
390 
391 IMPL_LINK( SfxNewFileDialog_Impl, RegionSelect, ListBox *, pBox )
392 {
393     if ( xDocShell.Is() && xDocShell->GetProgress() )
394         return 0;
395 
396     const sal_uInt16 nRegion = pBox->GetSelectEntryPos();
397     const sal_uInt16 nCount = aTemplates.GetRegionCount()? aTemplates.GetCount(nRegion): 0;
398     aTemplateLb.SetUpdateMode(sal_False);
399     aTemplateLb.Clear();
400     String aSel=aRegionLb.GetSelectEntry();
401     sal_uInt16 nc=aSel.Search('(');
402     if (nc-1&&nc!=STRING_NOTFOUND)
403         aSel.Erase(nc-1);
404     if (aSel.CompareIgnoreCaseToAscii( String(SfxResId(STR_STANDARD)) )==COMPARE_EQUAL)
405         aTemplateLb.InsertEntry(aNone);
406     for (sal_uInt16 i = 0; i < nCount; ++i)
407         aTemplateLb.InsertEntry(aTemplates.GetName(nRegion, i));
408     aTemplateLb.SelectEntryPos(0);
409     aTemplateLb.SetUpdateMode(sal_True);
410     aTemplateLb.Invalidate();
411     aTemplateLb.Update();
412     return 0;
413 }
414 
415 //-------------------------------------------------------------------------
416 
417 IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, Expand, MoreButton *, EMPTYARG )
418 {
419     TemplateSelect(&aTemplateLb);
420     return 0;
421 }
422 IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, Expand, MoreButton *, pMoreButton )
423 
424 //-------------------------------------------------------------------------
425 
426 IMPL_LINK( SfxNewFileDialog_Impl, PreviewClick, CheckBox *, pBox )
427 {
428     if ( xDocShell.Is() && xDocShell->GetProgress() )
429         return 0;
430 
431     sal_uInt16 nEntry = GetSelectedTemplatePos();
432     if ( nEntry && pBox->IsChecked() )
433     {
434         if(!Update(0))
435             aPreviewWin.Invalidate();
436     }
437     else
438     {
439         if (xDocShell.Is())
440             xDocShell.Clear();
441         aPreviewWin.SetObjectShell( 0 );
442     }
443     return 0;
444 }
445 
446 //-------------------------------------------------------------------------
447 
448 IMPL_LINK( SfxNewFileDialog_Impl, TemplateSelect, ListBox *, EMPTYARG )
449 {
450     // noch am Laden
451     if ( xDocShell && xDocShell->GetProgress() )
452         return 0;
453 
454     if ( !MORE_BTN(GetState()) )
455         // Dialog nicht aufgeklappt
456         return 0;
457 
458     aPrevTimer.Start();
459     return 0;
460 }
461 
462 //-------------------------------------------------------------------------
463 
464 IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, DoubleClick, ListBox *, pListBox )
465 {
466     (void)pListBox;
467     // noch am Laden
468     if ( !xDocShell.Is() || !xDocShell->GetProgress() )
469         pAntiImpl->EndDialog(RET_OK);
470     return 0;
471 }
472 IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, DoubleClick, ListBox *, pListBox )
473 
474 //-------------------------------------------------------------------------
475 
476 IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, LoadFile, PushButton *, EMPTYARG )
477 {
478     pAntiImpl->EndDialog(RET_TEMPLATE_LOAD);
479     return 0;
480 }
481 IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, LoadFile, PushButton *, EMPTYARG )
482 //-------------------------------------------------------------------------
483 
484 sal_uInt16  SfxNewFileDialog_Impl::GetSelectedTemplatePos() const
485 {
486     sal_uInt16 nEntry=aTemplateLb.GetSelectEntryPos();
487     String aSel=aRegionLb.GetSelectEntry().Copy();
488     sal_uInt16 nc=aSel.Search('(');
489     if (nc-1&&nc!=STRING_NOTFOUND)
490         aSel.Erase(nc-1);
491     if (aSel.CompareIgnoreCaseToAscii(String(SfxResId(STR_STANDARD)))!=COMPARE_EQUAL)
492         nEntry++;
493     if (!aTemplateLb.GetSelectEntryCount())
494         nEntry=0;
495     return nEntry;
496 }
497 
498 //-------------------------------------------------------------------------
499 
500 sal_Bool SfxNewFileDialog_Impl::IsTemplate() const
501 {
502     return GetSelectedTemplatePos()!=0;
503 
504 }
505 
506 //-------------------------------------------------------------------------
507 
508 String SfxNewFileDialog_Impl::GetTemplateFileName() const
509 {
510     if(!IsTemplate() || !aTemplates.GetRegionCount())
511         return String();
512     return aTemplates.GetPath(aRegionLb.GetSelectEntryPos(),
513                               GetSelectedTemplatePos()-1);
514 }
515 
516 //-------------------------------------------------------------------------
517 
518 String SfxNewFileDialog_Impl::GetTemplateRegion() const
519 {
520     if(!IsTemplate() || !aTemplates.GetRegionCount())
521         return String();
522     return aRegionLb.GetSelectEntry();
523 }
524 
525 //-------------------------------------------------------------------------
526 
527 String SfxNewFileDialog_Impl::GetTemplateName() const
528 {
529     if(!IsTemplate() || !aTemplates.GetRegionCount())
530         return String();
531     return aTemplateLb.GetSelectEntry();
532 }
533 
534 //-------------------------------------------------------------------------
535 
536 void AdjustPosSize_Impl(Window *pWin, short nMoveOffset, short nSizeOffset)
537 {
538     Point aPos(pWin->GetPosPixel());
539     Size aSize(pWin->GetSizePixel());
540     aPos.X() -= nMoveOffset;
541     aSize.Width() += nSizeOffset;
542     pWin->SetPosSizePixel(aPos, aSize);
543 }
544 //-------------------------------------------------------------------------
545 sal_uInt16  SfxNewFileDialog_Impl::GetTemplateFlags()const
546 {
547     sal_uInt16 nRet = aTextStyleCB.IsChecked() ? SFX_LOAD_TEXT_STYLES : 0;
548     if(aFrameStyleCB.IsChecked())
549         nRet |= SFX_LOAD_FRAME_STYLES;
550     if(aPageStyleCB.IsChecked())
551         nRet |= SFX_LOAD_PAGE_STYLES;
552     if(aNumStyleCB.IsChecked())
553         nRet |= SFX_LOAD_NUM_STYLES;
554     if(aMergeStyleCB.IsChecked())
555         nRet |= SFX_MERGE_STYLES;
556     return nRet;
557 }
558 //-------------------------------------------------------------------------
559 void    SfxNewFileDialog_Impl::SetTemplateFlags(sal_uInt16 nSet)
560 {
561     aTextStyleCB.Check(  0 != (nSet&SFX_LOAD_TEXT_STYLES ));
562     aFrameStyleCB.Check( 0 != (nSet&SFX_LOAD_FRAME_STYLES));
563     aPageStyleCB.Check(  0 != (nSet&SFX_LOAD_PAGE_STYLES ));
564     aNumStyleCB.Check(   0 != (nSet&SFX_LOAD_NUM_STYLES  ));
565     aMergeStyleCB.Check( 0 != (nSet&SFX_MERGE_STYLES     ));
566 }
567 
568 //-------------------------------------------------------------------------
569 
570 SfxNewFileDialog_Impl::SfxNewFileDialog_Impl(
571     SfxNewFileDialog* pAntiImplP, sal_uInt16 nFl)
572     :   aRegionFt( pAntiImplP, SfxResId( FT_REGION ) ),
573         aRegionLb( pAntiImplP, SfxResId( LB_REGION ) ),
574         aTemplateFt( pAntiImplP, SfxResId( FT_TEMPLATE ) ),
575         aTemplateLb( pAntiImplP, SfxResId( LB_TEMPLATE ) ),
576         aPreviewBtn( pAntiImplP, SfxResId( BTN_PREVIEW ) ),
577         aPreviewWin( pAntiImplP, SfxResId( WIN_PREVIEW ) ),
578         aTitleFt( pAntiImplP, SfxResId( FT_TITLE ) ),
579         aTitleEd( pAntiImplP, SfxResId( ED_TITLE ) ),
580         aThemaFt( pAntiImplP, SfxResId( FT_THEMA ) ),
581         aThemaEd( pAntiImplP, SfxResId( ED_THEMA ) ),
582         aKeywordsFt( pAntiImplP, SfxResId( FT_KEYWORDS ) ),
583         aKeywordsEd( pAntiImplP, SfxResId( ED_KEYWORDS ) ),
584         aDescFt( pAntiImplP, SfxResId( FT_DESC ) ),
585         aDescEd( pAntiImplP, SfxResId( ED_DESC ) ),
586         aDocinfoGb( pAntiImplP, SfxResId( GB_DOCINFO ) ),
587         aTextStyleCB( pAntiImplP, SfxResId(  CB_TEXT_STYLE )),
588         aFrameStyleCB( pAntiImplP, SfxResId( CB_FRAME_STYLE )),
589         aPageStyleCB( pAntiImplP, SfxResId(  CB_PAGE_STYLE )),
590         aNumStyleCB( pAntiImplP, SfxResId(   CB_NUM_STYLE  )),
591         aMergeStyleCB( pAntiImplP, SfxResId( CB_MERGE_STYLE )),
592         aLoadFilePB( pAntiImplP, SfxResId(   PB_LOAD_FILE )),
593         aOkBt( pAntiImplP, SfxResId( BT_OK ) ),
594         aCancelBt( pAntiImplP, SfxResId( BT_CANCEL ) ),
595         aHelpBt( pAntiImplP, SfxResId( BT_HELP ) ),
596         pMoreBt( new MoreButton( pAntiImplP, SfxResId( BT_MORE ) ) ),
597         aNone( SfxResId(STR_NONE) ),
598         sLoadTemplate( SfxResId(STR_LOAD_TEMPLATE)),
599         nFlags(nFl),
600         pAntiImpl( pAntiImplP )
601 {
602     short nMoveOffset = *(short *)pAntiImplP->GetClassRes();
603     pAntiImplP->IncrementRes(sizeof(short));
604     short nExpandSize= *(short *)pAntiImplP->GetClassRes();
605     pAntiImplP->IncrementRes(sizeof(short));
606     pAntiImplP->FreeResource();
607 
608     if (!nFlags)
609         MORE_BTN(Hide());
610     else if(SFXWB_LOAD_TEMPLATE == nFlags)
611     {
612         aLoadFilePB.SetClickHdl(LINK(this, SfxNewFileDialog_Impl, LoadFile));
613         aLoadFilePB.Show();
614         aTextStyleCB.Show();
615         aFrameStyleCB.Show();
616         aPageStyleCB.Show();
617         aNumStyleCB.Show();
618         aMergeStyleCB.Show();
619         Size aSize(pAntiImplP->GetOutputSizePixel());
620         Size aTmp(pAntiImplP->LogicToPixel(Size(16, 16), MAP_APPFONT));
621         aSize.Height() += aTmp.Height();
622         pAntiImplP->SetOutputSizePixel(aSize);
623         pMoreBt->Hide();
624         aTextStyleCB.Check();
625         pAntiImplP->SetText(sLoadTemplate);
626     }
627     else
628     {
629         MORE_BTN(SetClickHdl(LINK(this, SfxNewFileDialog_Impl, Expand)));
630         if((nFlags & SFXWB_PREVIEW) == SFXWB_PREVIEW)
631         {
632             MORE_BTN(AddWindow(&aPreviewBtn));
633             MORE_BTN(AddWindow(&aPreviewWin));
634             aPreviewBtn.SetClickHdl(LINK(this, SfxNewFileDialog_Impl, PreviewClick));
635         }
636         else
637         {
638             aPreviewBtn.Hide();
639             aPreviewWin.Hide();
640             nMoveOffset = (short)pAntiImplP->LogicToPixel(
641                 Size(nMoveOffset, nMoveOffset), MAP_APPFONT).Width();
642             nExpandSize = (short)pAntiImplP->LogicToPixel(
643                 Size(nExpandSize, nExpandSize), MAP_APPFONT).Width();
644             AdjustPosSize_Impl(&aTitleFt, nMoveOffset, 0);
645             AdjustPosSize_Impl(&aTitleEd, nMoveOffset, nExpandSize);
646             AdjustPosSize_Impl(&aThemaFt, nMoveOffset, 0);
647             AdjustPosSize_Impl(&aThemaEd, nMoveOffset, nExpandSize);
648             AdjustPosSize_Impl(&aKeywordsFt, nMoveOffset, 0);
649             AdjustPosSize_Impl(&aKeywordsEd, nMoveOffset, nExpandSize);
650             AdjustPosSize_Impl(&aDescFt , nMoveOffset, 0);
651             AdjustPosSize_Impl(&aDescEd , nMoveOffset, nExpandSize);
652             AdjustPosSize_Impl(&aDocinfoGb, nMoveOffset, nExpandSize);
653         }
654     }
655 
656     String &rExtra = pAntiImplP->GetExtraData();
657     sal_uInt16 nTokCount = rExtra.GetTokenCount( '|' );
658     if( nTokCount > 0 && nFlags )
659         MORE_BTN(SetState( rExtra.GetToken( 0, '|' ) == 'Y' ));
660     if( nTokCount > 1 && nFlags )
661         aPreviewBtn.Check( rExtra.GetToken( 1 ,'|' ) == 'Y' );
662 
663     aTemplateLb.SetDoubleClickHdl(LINK(this, SfxNewFileDialog_Impl, DoubleClick));
664 
665     // update the template configuration if necessary
666     {
667         WaitObject aWaitCursor( pAntiImplP->GetParent() );
668         aTemplates.Update( sal_True /* be smart */ );
669     }
670     // fill the list boxes
671     const sal_uInt16 nCount = aTemplates.GetRegionCount();
672     if (nCount)
673     {
674         for(sal_uInt16 i = 0; i < nCount; ++i)
675             aRegionLb.InsertEntry(aTemplates.GetFullRegionName(i));
676         aRegionLb.SetSelectHdl(LINK(this, SfxNewFileDialog_Impl, RegionSelect));
677     }
678 
679     aPrevTimer.SetTimeout( 500 );
680     aPrevTimer.SetTimeoutHdl( LINK( this, SfxNewFileDialog_Impl, Update));
681 
682 //   else
683 //        aRegionLb.InsertEntry(String(SfxResId(STR_STANDARD)));
684     aRegionLb.SelectEntryPos(0);
685     RegionSelect(&aRegionLb);
686 }
687 
688 //-------------------------------------------------------------------------
689 
690 SfxNewFileDialog_Impl::~SfxNewFileDialog_Impl()
691 {
692     String &rExtra = pAntiImpl->GetExtraData();
693     rExtra = MORE_BTN(GetState()) ? 'Y' : 'N';
694     rExtra += '|';
695     rExtra += aPreviewBtn.IsChecked() ? 'Y' : 'N';
696 
697     delete pMoreBt;
698 }
699 //-------------------------------------------------------------------------
700 SfxNewFileDialog::SfxNewFileDialog(Window *pParent, sal_uInt16 nFlags)
701     : SfxModalDialog( pParent, SfxResId( DLG_NEW_FILE ) )
702 {
703     pImpl = new SfxNewFileDialog_Impl( this, nFlags );
704 }
705 //-------------------------------------------------------------------------
706 SfxNewFileDialog::~SfxNewFileDialog()
707 {
708     delete pImpl;
709 }
710 //-------------------------------------------------------------------------
711 sal_Bool SfxNewFileDialog::IsTemplate() const
712 {
713     return pImpl->IsTemplate();
714 }
715 //-------------------------------------------------------------------------
716 String SfxNewFileDialog::GetTemplateRegion() const
717 {
718     return pImpl->GetTemplateRegion();
719 }
720 //-------------------------------------------------------------------------
721 String SfxNewFileDialog::GetTemplateName() const
722 {
723     return pImpl->GetTemplateName();
724 }
725 //-------------------------------------------------------------------------
726 String SfxNewFileDialog::GetTemplateFileName() const
727 {
728     return pImpl->GetTemplateFileName();
729 }
730 //-------------------------------------------------------------------------
731 sal_uInt16 SfxNewFileDialog::GetTemplateFlags()const
732 {
733     return pImpl->GetTemplateFlags();
734 
735 }
736 //-------------------------------------------------------------------------
737 void    SfxNewFileDialog::SetTemplateFlags(sal_uInt16 nSet)
738 {
739     pImpl->SetTemplateFlags(nSet);
740 }
741 
742