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