update dev300-m58
[ooovba.git] / sfx2 / source / doc / new.cxx
blob726e0bbfc5cad67af615a6533af69af79cb1a838
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: new.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <sfx2/new.hxx>
34 #include <vcl/gdimtf.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <vcl/morebtn.hxx>
37 #ifndef _SVMEDIT_HXX
38 #include <svtools/svmedit.hxx>
39 #endif
40 #include <svtools/itemset.hxx>
41 #include <svtools/eitem.hxx>
42 #include <svtools/sfxecode.hxx>
43 #include <svtools/ehdl.hxx>
44 #include <tools/urlobj.hxx>
45 #include <unotools/localfilehelper.hxx>
47 #include "new.hrc"
48 #ifndef _SFX_DOC_HRC
49 #include "doc.hrc"
50 #endif
51 #include <sfx2/sfx.hrc>
52 #include "helpid.hrc"
53 #include "sfxtypes.hxx"
54 #include <sfx2/app.hxx>
55 #include <sfx2/viewfrm.hxx>
56 #include <sfx2/docfac.hxx>
57 #include <sfx2/objsh.hxx>
58 #include "fltfnc.hxx"
59 #include <sfx2/viewsh.hxx>
60 #include "viewfac.hxx"
61 #include "sfxresid.hxx"
62 #include <sfx2/docfile.hxx>
63 #include "preview.hxx"
64 #include <sfx2/printer.hxx>
65 #include <vcl/waitobj.hxx>
66 #include <vcl/virdev.hxx>
67 #include <vcl/jobset.hxx>
68 #include <svtools/accessibilityoptions.hxx>
70 // Draw modes
71 #define OUTPUT_DRAWMODE_COLOR (DRAWMODE_DEFAULT)
72 #define OUTPUT_DRAWMODE_GRAYSCALE (DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_BLACKTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT)
73 #define OUTPUT_DRAWMODE_BLACKWHITE (DRAWMODE_BLACKLINE | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEFILL | DRAWMODE_GRAYBITMAP | DRAWMODE_WHITEGRADIENT)
74 #define OUTPUT_DRAWMODE_CONTRAST (DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT)
76 //========================================================================
78 #define MORE_BTN(x) pMoreBt->x
80 //========================================================================
82 void SfxPreviewBase_Impl::SetObjectShell( SfxObjectShell* pObj )
84 ::boost::shared_ptr<GDIMetaFile> pFile = pObj
85 ? pObj->GetPreviewMetaFile()
86 : ::boost::shared_ptr<GDIMetaFile>();
87 pMetaFile = pFile;
88 Invalidate();
91 SfxPreviewBase_Impl::SfxPreviewBase_Impl(
92 Window* pParent, const ResId& rResId )
93 : Window(pParent, rResId), pMetaFile()
97 SfxPreviewBase_Impl::SfxPreviewBase_Impl( Window* pParent )
98 : Window(pParent, 0 ), pMetaFile()
100 Resize();
101 Show();
104 SfxPreviewBase_Impl::~SfxPreviewBase_Impl()
108 void SfxPreviewBase_Impl::Resize()
110 Invalidate();
113 void SfxPreviewBase_Impl::SetGDIFile( ::boost::shared_ptr<GDIMetaFile> pFile )
115 pMetaFile = pFile;
116 Invalidate();
119 SfxFrameWindow* SfxPreviewWin_Impl::PreviewFactory(
120 SfxFrame* pFrame, const String& /*rName*/ )
122 return new SfxFrameWindow( new SfxPreviewWin_Impl(
123 &pFrame->GetCurrentViewFrame()->GetWindow() ) );
126 void SfxPreviewWin_Impl::ImpPaint(
127 const Rectangle&, GDIMetaFile* pFile, Window* pWindow )
129 Size aTmpSize = pFile ? pFile->GetPrefSize() : Size(1,1 );
130 DBG_ASSERT( aTmpSize.Height()*aTmpSize.Width(),
131 "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
132 #define FRAME 4
133 long nWidth = pWindow->GetOutputSize().Width() - 2*FRAME;
134 long nHeight = pWindow->GetOutputSize().Height() - 2*FRAME;
135 if( nWidth < 0 ) nWidth = 0;
136 if( nHeight < 0 ) nHeight = 0;
138 double dRatio=((double)aTmpSize.Width())/aTmpSize.Height();
139 double dRatioPreV=((double) nWidth ) / nHeight;
140 Size aSize;
141 Point aPoint;
142 if (dRatio>dRatioPreV)
144 aSize=Size(nWidth, (USHORT)(nWidth/dRatio));
145 aPoint=Point( 0, (USHORT)((nHeight-aSize.Height())/2));
147 else
149 aSize=Size((USHORT)(nHeight*dRatio), nHeight);
150 aPoint=Point((USHORT)((nWidth-aSize.Width())/2),0);
152 Point bPoint=Point(nWidth,nHeight)-aPoint;
155 pWindow->SetLineColor();
156 Color aLightGrayCol( COL_LIGHTGRAY );
157 pWindow->SetFillColor( aLightGrayCol );
158 pWindow->DrawRect( Rectangle( Point( 0,0 ), pWindow->GetOutputSize() ) );
159 if ( pFile )
161 Color aBlackCol( COL_BLACK );
162 Color aWhiteCol( COL_WHITE );
163 pWindow->SetLineColor( aBlackCol );
164 pWindow->SetFillColor( aWhiteCol );
165 pWindow->DrawRect( Rectangle( aPoint + Point( FRAME, FRAME ), bPoint + Point( FRAME, FRAME ) ) );
166 //! pFile->Move( Point( FRAME, FRAME ) );
167 //! pFile->Scale( Fraction( aTmpSize.Width(), aSize.Width() ),
168 //! Fraction( aTmpSize.Height(), aSize.Height() ) );
169 pFile->WindStart();
170 pFile->Play( pWindow, aPoint + Point( FRAME, FRAME ), aSize );
174 void SfxPreviewWin_Impl::Paint( const Rectangle& rRect )
176 ImpPaint( rRect, pMetaFile.get(), this );
179 SfxPreviewWin::SfxPreviewWin(
180 Window* pParent, const ResId& rResId, SfxObjectShellLock &rDocSh )
181 : Window(pParent, rResId), rDocShell( rDocSh )
183 SetHelpId( HID_PREVIEW_FRAME );
185 // adjust contrast mode initially
186 bool bUseContrast = UseHighContrastSetting();
187 SetDrawMode( bUseContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
189 // #107818# This preview window is for document previews. Therefore
190 // right-to-left mode should be off
191 EnableRTL( FALSE );
194 void SfxPreviewWin::Paint( const Rectangle& rRect )
196 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( &rDocShell );
197 if ( pFrame && pFrame->GetViewShell() &&
198 pFrame->GetViewShell()->GetPrinter() &&
199 pFrame->GetViewShell()->GetPrinter()->IsPrinting() )
201 return;
204 Size aTmpSize( rDocShell->GetFirstPageSize() );
205 GDIMetaFile aMtf;
206 VirtualDevice aDevice;
208 DBG_ASSERT( aTmpSize.Height() * aTmpSize.Width(), "size of first page is 0, overload GetFirstPageSize or set vis-area!" );
210 aMtf.SetPrefSize( aTmpSize );
211 aDevice.EnableOutput( FALSE );
212 aDevice.SetMapMode( rDocShell->GetMapUnit() );
213 aDevice.SetDrawMode( GetDrawMode() );
214 aMtf.Record( &aDevice );
215 rDocShell->DoDraw( &aDevice, Point(0,0), aTmpSize, JobSetup(), ASPECT_THUMBNAIL );
216 aMtf.Stop();
217 aMtf.WindStart();
218 SfxPreviewWin_Impl::ImpPaint( rRect, &aMtf, this );
221 void SfxPreviewWin::DataChanged( const DataChangedEvent& rDCEvt )
223 Window::DataChanged( rDCEvt );
225 if( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
226 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
228 // adjust contrast mode
229 bool bUseContrast = UseHighContrastSetting();
230 SetDrawMode( bUseContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR );
234 bool SfxPreviewWin::UseHighContrastSetting() const
236 return GetSettings().GetStyleSettings().GetHighContrastMode();
240 class SfxNewFileDialog_Impl
242 FixedText aRegionFt;
243 ListBox aRegionLb;
244 FixedText aTemplateFt;
245 ListBox aTemplateLb;
247 CheckBox aPreviewBtn;
248 SfxPreviewWin_Impl aPreviewWin;
250 FixedText aTitleFt;
251 Edit aTitleEd;
252 FixedText aThemaFt;
253 Edit aThemaEd;
254 FixedText aKeywordsFt;
255 Edit aKeywordsEd;
256 FixedText aDescFt;
257 MultiLineEdit aDescEd;
258 FixedLine aDocinfoGb;
260 CheckBox aTextStyleCB;
261 CheckBox aFrameStyleCB;
262 CheckBox aPageStyleCB;
263 CheckBox aNumStyleCB;
264 CheckBox aMergeStyleCB;
265 PushButton aLoadFilePB;
267 OKButton aOkBt;
268 CancelButton aCancelBt;
269 HelpButton aHelpBt;
270 MoreButton* pMoreBt;
271 Timer aPrevTimer;
272 String aNone;
273 String sLoadTemplate;
275 USHORT nFlags;
276 SfxDocumentTemplates aTemplates;
277 SfxObjectShellLock xDocShell;
278 SfxNewFileDialog* pAntiImpl;
280 void ClearInfo();
281 DECL_LINK( Update, void * );
283 DECL_LINK( RegionSelect, ListBox * );
284 DECL_LINK( TemplateSelect, ListBox * );
285 DECL_LINK( DoubleClick, ListBox * );
286 void TogglePreview(CheckBox *);
287 DECL_LINK( Expand, MoreButton * );
288 DECL_LINK( PreviewClick, CheckBox * );
289 DECL_LINK( LoadFile, PushButton* );
290 USHORT GetSelectedTemplatePos() const;
292 public:
294 SfxNewFileDialog_Impl( SfxNewFileDialog* pAntiImplP, USHORT nFlags );
295 ~SfxNewFileDialog_Impl();
297 // Liefert FALSE, wenn '- Keine -' als Vorlage eingestellt ist
298 // Nur wenn IsTemplate() TRUE liefert, koennen Vorlagennamen
299 // erfragt werden
300 BOOL IsTemplate() const;
301 String GetTemplateRegion() const;
302 String GetTemplateName() const;
303 String GetTemplateFileName() const;
305 USHORT GetTemplateFlags()const;
306 void SetTemplateFlags(USHORT nSet);
310 //-------------------------------------------------------------------------
312 void SfxNewFileDialog_Impl::ClearInfo()
314 const String aNo;
315 aTitleEd.SetText(aNo);
316 aThemaEd.SetText(aNo);
317 aKeywordsEd.SetText(aNo);
318 aDescEd.SetText(aNo);
321 //-------------------------------------------------------------------------
323 IMPL_LINK( SfxNewFileDialog_Impl, Update, void *, EMPTYARG )
325 if ( xDocShell.Is() )
327 if ( xDocShell->GetProgress() )
328 return FALSE;
329 xDocShell.Clear();
332 const USHORT nEntry = GetSelectedTemplatePos();
333 if(!nEntry)
335 ClearInfo();
336 aPreviewWin.Invalidate();
337 aPreviewWin.SetObjectShell( 0);
338 return 0;
341 if ( aPreviewBtn.IsChecked() && (nFlags & SFXWB_PREVIEW) == SFXWB_PREVIEW)
344 String aFileName = aTemplates.GetPath( aRegionLb.GetSelectEntryPos(), nEntry-1);
345 INetURLObject aTestObj( aFileName );
346 if( aTestObj.GetProtocol() == INET_PROT_NOT_VALID )
348 // temp. fix until Templates are managed by UCB compatible service
349 // does NOT work with locally cached components !
350 String aTemp;
351 utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aTemp );
352 aFileName = aTemp;
355 INetURLObject aObj( aFileName );
356 for ( SfxObjectShell* pTmp = SfxObjectShell::GetFirst();
357 pTmp;
358 pTmp = SfxObjectShell::GetNext(*pTmp) )
360 //! fsys bug op==
361 if ( pTmp->GetMedium())
362 // ??? HasName() MM
363 if( INetURLObject( pTmp->GetMedium()->GetName() ) == aObj )
365 xDocShell = pTmp;
366 break;
370 if ( !xDocShell.Is() )
372 Window *pParent = Application::GetDefDialogParent();
373 Application::SetDefDialogParent( pAntiImpl );
374 SfxErrorContext eEC(ERRCTX_SFX_LOADTEMPLATE,pAntiImpl);
375 SfxApplication *pSfxApp = SFX_APP();
376 ULONG lErr;
377 SfxItemSet* pSet = new SfxAllItemSet( pSfxApp->GetPool() );
378 pSet->Put( SfxBoolItem( SID_TEMPLATE, TRUE ) );
379 pSet->Put( SfxBoolItem( SID_PREVIEW, TRUE ) );
380 lErr = pSfxApp->LoadTemplate( xDocShell, aFileName, TRUE, pSet );
381 if( lErr )
382 ErrorHandler::HandleError(lErr);
383 Application::SetDefDialogParent( pParent );
384 if ( !xDocShell.Is() )
386 aPreviewWin.SetObjectShell( 0 );
387 return FALSE;
391 aPreviewWin.SetObjectShell( xDocShell );
393 return TRUE;
396 //-------------------------------------------------------------------------
398 IMPL_LINK( SfxNewFileDialog_Impl, RegionSelect, ListBox *, pBox )
400 if ( xDocShell.Is() && xDocShell->GetProgress() )
401 return 0;
403 const USHORT nRegion = pBox->GetSelectEntryPos();
404 const USHORT nCount = aTemplates.GetRegionCount()? aTemplates.GetCount(nRegion): 0;
405 aTemplateLb.SetUpdateMode(FALSE);
406 aTemplateLb.Clear();
407 String aSel=aRegionLb.GetSelectEntry();
408 USHORT nc=aSel.Search('(');
409 if (nc-1&&nc!=STRING_NOTFOUND)
410 aSel.Erase(nc-1);
411 if (aSel.CompareIgnoreCaseToAscii( String(SfxResId(STR_STANDARD)) )==COMPARE_EQUAL)
412 aTemplateLb.InsertEntry(aNone);
413 for (USHORT i = 0; i < nCount; ++i)
414 aTemplateLb.InsertEntry(aTemplates.GetName(nRegion, i));
415 aTemplateLb.SelectEntryPos(0);
416 aTemplateLb.SetUpdateMode(TRUE);
417 aTemplateLb.Invalidate();
418 aTemplateLb.Update();
419 return 0;
422 //-------------------------------------------------------------------------
424 IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, Expand, MoreButton *, EMPTYARG )
426 TemplateSelect(&aTemplateLb);
427 return 0;
429 IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, Expand, MoreButton *, pMoreButton )
431 //-------------------------------------------------------------------------
433 IMPL_LINK( SfxNewFileDialog_Impl, PreviewClick, CheckBox *, pBox )
435 if ( xDocShell.Is() && xDocShell->GetProgress() )
436 return 0;
438 USHORT nEntry = GetSelectedTemplatePos();
439 if ( nEntry && pBox->IsChecked() )
441 if(!Update(0))
442 aPreviewWin.Invalidate();
444 else
446 if (xDocShell.Is())
447 xDocShell.Clear();
448 aPreviewWin.SetObjectShell( 0 );
450 return 0;
453 //-------------------------------------------------------------------------
455 IMPL_LINK( SfxNewFileDialog_Impl, TemplateSelect, ListBox *, EMPTYARG )
457 // noch am Laden
458 if ( xDocShell && xDocShell->GetProgress() )
459 return 0;
461 if ( !MORE_BTN(GetState()) )
462 // Dialog nicht aufgeklappt
463 return 0;
465 aPrevTimer.Start();
466 return 0;
469 //-------------------------------------------------------------------------
471 IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, DoubleClick, ListBox *, pListBox )
473 (void)pListBox;
474 // noch am Laden
475 if ( !xDocShell.Is() || !xDocShell->GetProgress() )
476 pAntiImpl->EndDialog(RET_OK);
477 return 0;
479 IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, DoubleClick, ListBox *, pListBox )
481 //-------------------------------------------------------------------------
483 IMPL_LINK_INLINE_START( SfxNewFileDialog_Impl, LoadFile, PushButton *, EMPTYARG )
485 pAntiImpl->EndDialog(RET_TEMPLATE_LOAD);
486 return 0;
488 IMPL_LINK_INLINE_END( SfxNewFileDialog_Impl, LoadFile, PushButton *, EMPTYARG )
489 //-------------------------------------------------------------------------
491 USHORT SfxNewFileDialog_Impl::GetSelectedTemplatePos() const
493 USHORT nEntry=aTemplateLb.GetSelectEntryPos();
494 String aSel=aRegionLb.GetSelectEntry().Copy();
495 USHORT nc=aSel.Search('(');
496 if (nc-1&&nc!=STRING_NOTFOUND)
497 aSel.Erase(nc-1);
498 if (aSel.CompareIgnoreCaseToAscii(String(SfxResId(STR_STANDARD)))!=COMPARE_EQUAL)
499 nEntry++;
500 if (!aTemplateLb.GetSelectEntryCount())
501 nEntry=0;
502 return nEntry;
505 //-------------------------------------------------------------------------
507 BOOL SfxNewFileDialog_Impl::IsTemplate() const
509 return GetSelectedTemplatePos()!=0;
513 //-------------------------------------------------------------------------
515 String SfxNewFileDialog_Impl::GetTemplateFileName() const
517 if(!IsTemplate() || !aTemplates.GetRegionCount())
518 return String();
519 return aTemplates.GetPath(aRegionLb.GetSelectEntryPos(),
520 GetSelectedTemplatePos()-1);
523 //-------------------------------------------------------------------------
525 String SfxNewFileDialog_Impl::GetTemplateRegion() const
527 if(!IsTemplate() || !aTemplates.GetRegionCount())
528 return String();
529 return aRegionLb.GetSelectEntry();
532 //-------------------------------------------------------------------------
534 String SfxNewFileDialog_Impl::GetTemplateName() const
536 if(!IsTemplate() || !aTemplates.GetRegionCount())
537 return String();
538 return aTemplateLb.GetSelectEntry();
541 //-------------------------------------------------------------------------
543 void AdjustPosSize_Impl(Window *pWin, short nMoveOffset, short nSizeOffset)
545 Point aPos(pWin->GetPosPixel());
546 Size aSize(pWin->GetSizePixel());
547 aPos.X() -= nMoveOffset;
548 aSize.Width() += nSizeOffset;
549 pWin->SetPosSizePixel(aPos, aSize);
551 //-------------------------------------------------------------------------
552 USHORT SfxNewFileDialog_Impl::GetTemplateFlags()const
554 USHORT nRet = aTextStyleCB.IsChecked() ? SFX_LOAD_TEXT_STYLES : 0;
555 if(aFrameStyleCB.IsChecked())
556 nRet |= SFX_LOAD_FRAME_STYLES;
557 if(aPageStyleCB.IsChecked())
558 nRet |= SFX_LOAD_PAGE_STYLES;
559 if(aNumStyleCB.IsChecked())
560 nRet |= SFX_LOAD_NUM_STYLES;
561 if(aMergeStyleCB.IsChecked())
562 nRet |= SFX_MERGE_STYLES;
563 return nRet;
565 //-------------------------------------------------------------------------
566 void SfxNewFileDialog_Impl::SetTemplateFlags(USHORT nSet)
568 aTextStyleCB.Check( 0 != (nSet&SFX_LOAD_TEXT_STYLES ));
569 aFrameStyleCB.Check( 0 != (nSet&SFX_LOAD_FRAME_STYLES));
570 aPageStyleCB.Check( 0 != (nSet&SFX_LOAD_PAGE_STYLES ));
571 aNumStyleCB.Check( 0 != (nSet&SFX_LOAD_NUM_STYLES ));
572 aMergeStyleCB.Check( 0 != (nSet&SFX_MERGE_STYLES ));
575 //-------------------------------------------------------------------------
577 SfxNewFileDialog_Impl::SfxNewFileDialog_Impl(
578 SfxNewFileDialog* pAntiImplP, USHORT nFl)
579 : aRegionFt( pAntiImplP, SfxResId( FT_REGION ) ),
580 aRegionLb( pAntiImplP, SfxResId( LB_REGION ) ),
581 aTemplateFt( pAntiImplP, SfxResId( FT_TEMPLATE ) ),
582 aTemplateLb( pAntiImplP, SfxResId( LB_TEMPLATE ) ),
583 aPreviewBtn( pAntiImplP, SfxResId( BTN_PREVIEW ) ),
584 aPreviewWin( pAntiImplP, SfxResId( WIN_PREVIEW ) ),
585 aTitleFt( pAntiImplP, SfxResId( FT_TITLE ) ),
586 aTitleEd( pAntiImplP, SfxResId( ED_TITLE ) ),
587 aThemaFt( pAntiImplP, SfxResId( FT_THEMA ) ),
588 aThemaEd( pAntiImplP, SfxResId( ED_THEMA ) ),
589 aKeywordsFt( pAntiImplP, SfxResId( FT_KEYWORDS ) ),
590 aKeywordsEd( pAntiImplP, SfxResId( ED_KEYWORDS ) ),
591 aDescFt( pAntiImplP, SfxResId( FT_DESC ) ),
592 aDescEd( pAntiImplP, SfxResId( ED_DESC ) ),
593 aDocinfoGb( pAntiImplP, SfxResId( GB_DOCINFO ) ),
594 aTextStyleCB( pAntiImplP, SfxResId( CB_TEXT_STYLE )),
595 aFrameStyleCB( pAntiImplP, SfxResId( CB_FRAME_STYLE )),
596 aPageStyleCB( pAntiImplP, SfxResId( CB_PAGE_STYLE )),
597 aNumStyleCB( pAntiImplP, SfxResId( CB_NUM_STYLE )),
598 aMergeStyleCB( pAntiImplP, SfxResId( CB_MERGE_STYLE )),
599 aLoadFilePB( pAntiImplP, SfxResId( PB_LOAD_FILE )),
600 aOkBt( pAntiImplP, SfxResId( BT_OK ) ),
601 aCancelBt( pAntiImplP, SfxResId( BT_CANCEL ) ),
602 aHelpBt( pAntiImplP, SfxResId( BT_HELP ) ),
603 pMoreBt( new MoreButton( pAntiImplP, SfxResId( BT_MORE ) ) ),
604 aNone( SfxResId(STR_NONE) ),
605 sLoadTemplate( SfxResId(STR_LOAD_TEMPLATE)),
606 nFlags(nFl),
607 pAntiImpl( pAntiImplP )
609 short nMoveOffset = *(short *)pAntiImplP->GetClassRes();
610 pAntiImplP->IncrementRes(sizeof(short));
611 short nExpandSize= *(short *)pAntiImplP->GetClassRes();
612 pAntiImplP->IncrementRes(sizeof(short));
613 pAntiImplP->FreeResource();
615 if (!nFlags)
616 MORE_BTN(Hide());
617 else if(SFXWB_LOAD_TEMPLATE == nFlags)
619 aLoadFilePB.SetClickHdl(LINK(this, SfxNewFileDialog_Impl, LoadFile));
620 aLoadFilePB.Show();
621 aTextStyleCB.Show();
622 aFrameStyleCB.Show();
623 aPageStyleCB.Show();
624 aNumStyleCB.Show();
625 aMergeStyleCB.Show();
626 Size aSize(pAntiImplP->GetOutputSizePixel());
627 Size aTmp(pAntiImplP->LogicToPixel(Size(16, 16), MAP_APPFONT));
628 aSize.Height() += aTmp.Height();
629 pAntiImplP->SetOutputSizePixel(aSize);
630 pMoreBt->Hide();
631 aTextStyleCB.Check();
632 pAntiImplP->SetText(sLoadTemplate);
634 else
636 MORE_BTN(SetClickHdl(LINK(this, SfxNewFileDialog_Impl, Expand)));
637 if((nFlags & SFXWB_PREVIEW) == SFXWB_PREVIEW)
639 MORE_BTN(AddWindow(&aPreviewBtn));
640 MORE_BTN(AddWindow(&aPreviewWin));
641 aPreviewBtn.SetClickHdl(LINK(this, SfxNewFileDialog_Impl, PreviewClick));
643 else
645 aPreviewBtn.Hide();
646 aPreviewWin.Hide();
647 nMoveOffset = (short)pAntiImplP->LogicToPixel(
648 Size(nMoveOffset, nMoveOffset), MAP_APPFONT).Width();
649 nExpandSize = (short)pAntiImplP->LogicToPixel(
650 Size(nExpandSize, nExpandSize), MAP_APPFONT).Width();
651 AdjustPosSize_Impl(&aTitleFt, nMoveOffset, 0);
652 AdjustPosSize_Impl(&aTitleEd, nMoveOffset, nExpandSize);
653 AdjustPosSize_Impl(&aThemaFt, nMoveOffset, 0);
654 AdjustPosSize_Impl(&aThemaEd, nMoveOffset, nExpandSize);
655 AdjustPosSize_Impl(&aKeywordsFt, nMoveOffset, 0);
656 AdjustPosSize_Impl(&aKeywordsEd, nMoveOffset, nExpandSize);
657 AdjustPosSize_Impl(&aDescFt , nMoveOffset, 0);
658 AdjustPosSize_Impl(&aDescEd , nMoveOffset, nExpandSize);
659 AdjustPosSize_Impl(&aDocinfoGb, nMoveOffset, nExpandSize);
663 String &rExtra = pAntiImplP->GetExtraData();
664 USHORT nTokCount = rExtra.GetTokenCount( '|' );
665 if( nTokCount > 0 && nFlags )
666 MORE_BTN(SetState( rExtra.GetToken( 0, '|' ) == 'Y' ));
667 if( nTokCount > 1 && nFlags )
668 aPreviewBtn.Check( rExtra.GetToken( 1 ,'|' ) == 'Y' );
670 aTemplateLb.SetDoubleClickHdl(LINK(this, SfxNewFileDialog_Impl, DoubleClick));
672 // update the template configuration if necessary
674 WaitObject aWaitCursor( pAntiImplP->GetParent() );
675 aTemplates.Update( sal_True /* be smart */ );
677 // fill the list boxes
678 const USHORT nCount = aTemplates.GetRegionCount();
679 if (nCount)
681 for(USHORT i = 0; i < nCount; ++i)
682 aRegionLb.InsertEntry(aTemplates.GetFullRegionName(i));
683 aRegionLb.SetSelectHdl(LINK(this, SfxNewFileDialog_Impl, RegionSelect));
686 aPrevTimer.SetTimeout( 500 );
687 aPrevTimer.SetTimeoutHdl( LINK( this, SfxNewFileDialog_Impl, Update));
689 // else
690 // aRegionLb.InsertEntry(String(SfxResId(STR_STANDARD)));
691 aRegionLb.SelectEntryPos(0);
692 RegionSelect(&aRegionLb);
695 //-------------------------------------------------------------------------
697 SfxNewFileDialog_Impl::~SfxNewFileDialog_Impl()
699 String &rExtra = pAntiImpl->GetExtraData();
700 rExtra = MORE_BTN(GetState()) ? 'Y' : 'N';
701 rExtra += '|';
702 rExtra += aPreviewBtn.IsChecked() ? 'Y' : 'N';
704 delete pMoreBt;
706 //-------------------------------------------------------------------------
707 SfxNewFileDialog::SfxNewFileDialog(Window *pParent, USHORT nFlags)
708 : SfxModalDialog( pParent, SfxResId( DLG_NEW_FILE ) )
710 pImpl = new SfxNewFileDialog_Impl( this, nFlags );
712 //-------------------------------------------------------------------------
713 SfxNewFileDialog::~SfxNewFileDialog()
715 delete pImpl;
717 //-------------------------------------------------------------------------
718 BOOL SfxNewFileDialog::IsTemplate() const
720 return pImpl->IsTemplate();
722 //-------------------------------------------------------------------------
723 String SfxNewFileDialog::GetTemplateRegion() const
725 return pImpl->GetTemplateRegion();
727 //-------------------------------------------------------------------------
728 String SfxNewFileDialog::GetTemplateName() const
730 return pImpl->GetTemplateName();
732 //-------------------------------------------------------------------------
733 String SfxNewFileDialog::GetTemplateFileName() const
735 return pImpl->GetTemplateFileName();
737 //-------------------------------------------------------------------------
738 USHORT SfxNewFileDialog::GetTemplateFlags()const
740 return pImpl->GetTemplateFlags();
743 //-------------------------------------------------------------------------
744 void SfxNewFileDialog::SetTemplateFlags(USHORT nSet)
746 pImpl->SetTemplateFlags(nSet);