xref: /trunk/main/filter/source/pdf/impdialog.cxx (revision 0deba7fb)
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_filter.hxx"
26 
27 #include "impdialog.hxx"
28 #include "impdialog.hrc"
29 #include "vcl/svapp.hxx"
30 #include "vcl/msgbox.hxx"
31 #include "sfx2/passwd.hxx"
32 
33 #include "comphelper/storagehelper.hxx"
34 
35 #include "com/sun/star/text/XTextRange.hpp"
36 #include "com/sun/star/drawing/XShapes.hpp"
37 #include "com/sun/star/container/XIndexAccess.hpp"
38 #include "com/sun/star/frame/XController.hpp"
39 #include "com/sun/star/view/XSelectionSupplier.hpp"
40 
41 #include <boost/shared_ptr.hpp>
42 
getPDFFilterResMgr()43 static ResMgr& getPDFFilterResMgr()
44 {
45     static ResMgr *pRes = ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILocale());
46     return *pRes;
47 }
48 
PDFFilterResId(sal_uInt32 nId)49 PDFFilterResId::PDFFilterResId( sal_uInt32 nId ) : ResId( nId, getPDFFilterResMgr() )
50 {
51 }
52 
53 // ----------------
54 // - ImpPDFDialog -
55 // ----------------
56 
57 using namespace ::com::sun::star;
58 
59 //////////////////////////////////////////////////////////////////////////////////////////////////////
60 // tabbed PDF dialog implementation
61 // please note: the default used here are the same as per specification,
62 // they should be the same in  PDFFilter::implExport and  in PDFExport::PDFExport
63 // -----------------------------------------------------------------------------
ImpPDFTabDialog(Window * pParent,Sequence<PropertyValue> & rFilterData,const Reference<XComponent> & rxDoc,const Reference<lang::XMultiServiceFactory> & xFact)64 ImpPDFTabDialog::ImpPDFTabDialog( Window* pParent,
65                                   Sequence< PropertyValue >& rFilterData,
66                                   const Reference< XComponent >& rxDoc,
67                                   const Reference< lang::XMultiServiceFactory >& xFact
68                                   ) :
69     SfxTabDialog( pParent, PDFFilterResId( RID_PDF_EXPORT_DLG ), 0, sal_False, 0 ),
70     mxMSF( xFact ),
71     maConfigItem( String( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/PDF/Export/" ) ), &rFilterData ),
72     maConfigI18N( String( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/I18N/CTL/" ) ) ),
73     mbIsPresentation( sal_False ),
74     mbIsWriter( sal_False ),
75 
76     mbSelectionPresent( sal_False ),
77     mbUseCTLFont( sal_False ),
78     mbUseLosslessCompression( sal_True ),
79     mnQuality( 90 ),
80     mbReduceImageResolution( sal_False ),
81     mnMaxImageResolution( 300 ),
82     mbUseTaggedPDF( sal_False ),
83     mbExportNotes( sal_True ),
84 	mbExportNotesPages( sal_False ),
85     mbUseTransitionEffects( sal_False ),
86     mbIsSkipEmptyPages( sal_True ),
87     mbAddStream( sal_False ),
88     mbEmbedStandardFonts( sal_False ),
89     mnFormsType( 0 ),
90     mbExportFormFields( sal_True ),
91     mbAllowDuplicateFieldNames( sal_False ),
92     mbExportBookmarks( sal_True ),
93     mnOpenBookmarkLevels( -1 ),
94 
95     mbHideViewerToolbar( sal_False ),
96     mbHideViewerMenubar( sal_False ),
97     mbHideViewerWindowControls( sal_False ),
98     mbResizeWinToInit( sal_False ),
99     mbCenterWindow( sal_False ),
100     mbOpenInFullScreenMode( sal_False ),
101     mbDisplayPDFDocumentTitle( sal_False ),
102     mnMagnification( 0 ),
103     mnInitialView( 0 ),
104     mnZoom( 0 ),
105     mnInitialPage( 1 ),
106     mnPageLayout( 0 ),
107     mbFirstPageLeft( sal_False ),
108 
109     mbEncrypt( false ),
110 	mbRestrictPermissions( false ),
111     mnPrint( 0 ),
112     mnChangesAllowed( 0 ),
113     mbCanCopyOrExtract( false ),
114     mbCanExtractForAccessibility( true ),
115 
116     mbIsRangeChecked( sal_False ),
117     msPageRange( ' ' ),
118 
119     mbSelectionIsChecked( sal_False ),
120     mbExportRelativeFsysLinks( sal_False ),
121     mnViewPDFMode( 0 ),
122     mbConvertOOoTargets( sal_False ),
123     mbExportBmkToPDFDestination( sal_False )
124 {
125     FreeResource();
126 // check for selection
127     try
128     {
129         Reference< frame::XController > xController( Reference< frame::XModel >( rxDoc, UNO_QUERY )->getCurrentController() );
130         if( xController.is() )
131         {
132             Reference< view::XSelectionSupplier > xView( xController, UNO_QUERY );
133             if( xView.is() )
134                 xView->getSelection() >>= maSelection;
135         }
136     }
137     catch( RuntimeException )
138     {
139     }
140     mbSelectionPresent = maSelection.hasValue();
141     if ( mbSelectionPresent )
142     {
143         Reference< drawing::XShapes > xShapes;
144         if ( ( maSelection >>= xShapes ) == sal_False )	// XShapes is always a selection
145         {
146             // even if nothing is selected in writer the selection is not empty
147             Reference< container::XIndexAccess > xIndexAccess;
148             if ( maSelection >>= xIndexAccess )
149             {
150                 sal_Int32 nLen = xIndexAccess->getCount();
151                 if ( !nLen )
152                     mbSelectionPresent = sal_False;
153                 else if ( nLen == 1 )
154                 {
155                     Reference< text::XTextRange > xTextRange( xIndexAccess->getByIndex( 0 ), UNO_QUERY );
156                     if ( xTextRange.is() && ( xTextRange->getString().getLength() == 0 ) )
157                         mbSelectionPresent = sal_False;
158                 }
159             }
160         }
161     }
162 
163 // check if source document is a presentation
164     try
165     {
166         Reference< XServiceInfo > xInfo( rxDoc, UNO_QUERY );
167         if ( xInfo.is() )
168         {
169             if ( xInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
170                 mbIsPresentation = sal_True;
171             if ( xInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.GenericTextDocument" ) ) ) )
172                 mbIsWriter = sal_True;
173         }
174     }
175     catch( RuntimeException )
176     {
177     }
178 
179 //get the CTL (Complex Text Layout) from general options, returns sal_True if we have a CTL font on our hands.
180     mbUseCTLFont = maConfigI18N.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "CTLFont" ) ), sal_False );
181 
182     mbUseLosslessCompression = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "UseLosslessCompression" ) ), sal_False );
183     mnQuality = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 90 );
184     mbReduceImageResolution = maConfigItem.ReadBool(  OUString( RTL_CONSTASCII_USTRINGPARAM( "ReduceImageResolution" ) ), sal_False );
185     mnMaxImageResolution = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxImageResolution" ) ), 300 );
186 
187     mbUseTaggedPDF = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "UseTaggedPDF" ) ), sal_False );
188     mnPDFTypeSelection =  maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectPdfVersion" ) ), 0 );
189     if ( mbIsPresentation )
190         mbExportNotesPages = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportNotesPages"  ) ), sal_False );
191 	mbExportNotes = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportNotes"  ) ), sal_False );
192 
193     mbExportBookmarks = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarks" ) ), sal_True );
194     mnOpenBookmarkLevels = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenBookmarkLevels" ) ), -1 );
195     mbUseTransitionEffects = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "UseTransitionEffects"  ) ), sal_True );
196     mbIsSkipEmptyPages = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsSkipEmptyPages"  ) ), sal_False );
197     mbAddStream = maConfigItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "IsAddStream" ) ), sal_False );
198     mbEmbedStandardFonts = maConfigItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "EmbedStandardFonts" ) ), sal_False );
199 
200     mnFormsType = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "FormsType" ) ), 0 );
201     mbExportFormFields = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportFormFields" ) ), sal_True );
202     if ( ( mnFormsType < 0 ) || ( mnFormsType > 3 ) )
203         mnFormsType = 0;
204     mbAllowDuplicateFieldNames = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowDuplicateFieldNames" ) ), sal_False );
205 
206 //prepare values for the Viewer tab page
207     mbHideViewerToolbar = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "HideViewerToolbar" ) ), sal_False );
208     mbHideViewerMenubar = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "HideViewerMenubar" ) ), sal_False );
209     mbHideViewerWindowControls = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "HideViewerWindowControls" ) ), sal_False );
210     mbResizeWinToInit = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ResizeWindowToInitialPage" ) ), sal_False );
211     mbCenterWindow = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "CenterWindow" ) ), sal_False );
212     mbOpenInFullScreenMode = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenInFullScreenMode" ) ), sal_False );
213     mbDisplayPDFDocumentTitle = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "DisplayPDFDocumentTitle" ) ), sal_True );
214 
215     mnInitialView = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "InitialView" ) ), 0 );
216     mnMagnification = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Magnification" ) ), 0 );
217     mnZoom = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Zoom" ) ), 100 );
218     mnPageLayout = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "PageLayout" ) ), 0 );
219     mbFirstPageLeft = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "FirstPageOnLeft" ) ), sal_False );
220     mnInitialPage = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "InitialPage" ) ), 1 );
221     if( mnInitialPage < 1 )
222         mnInitialPage = 1;
223 
224 //prepare values for the security tab page
225     mnPrint = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Printing" ) ), 2 );
226     mnChangesAllowed = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Changes" ) ), 4 );
227     mbCanCopyOrExtract = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableCopyingOfContent" ) ), sal_True );
228     mbCanExtractForAccessibility = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableTextAccessForAccessibilityTools" ) ), sal_True );
229 
230 //prepare values for relative links
231 	mbExportRelativeFsysLinks = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportLinksRelativeFsys" ) ), sal_False );
232 
233 	mnViewPDFMode = maConfigItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "PDFViewSelection" ) ), 0 );
234 
235     mbConvertOOoTargets = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ConvertOOoTargetToPDFTarget" ) ), sal_False );
236     mbExportBmkToPDFDestination = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarksToPDFDestination" ) ), sal_False );
237 
238 //queue the tab pages for later creation (created when first shown)
239     AddTabPage( RID_PDF_TAB_SECURITY, ImpPDFTabSecurityPage::Create, 0 );
240 	AddTabPage( RID_PDF_TAB_LINKS, ImpPDFTabLinksPage::Create, 0 );
241     AddTabPage( RID_PDF_TAB_VPREFER, ImpPDFTabViewerPage::Create, 0 );
242     AddTabPage( RID_PDF_TAB_OPNFTR, ImpPDFTabOpnFtrPage::Create, 0 );
243 
244 //last queued is the first to be displayed (or so it seems..)
245     AddTabPage( RID_PDF_TAB_GENER, ImpPDFTabGeneralPage::Create, 0 );
246 
247 //get the string property value (from sfx2/source/dialog/mailmodel.cxx) to overwrite the text for the Ok button
248     ::rtl::OUString sOkButtonText = maConfigItem.ReadString( OUString( RTL_CONSTASCII_USTRINGPARAM( "_OkButtonString" ) ), OUString() );
249 
250 //change text on the Ok button: get the relevant string from resources, update it on the button
251 //according to the exported pdf file destination: send as e-mail or write to file?
252     GetOKButton().SetText( ( sOkButtonText.getLength() > 0 ) ?
253                             sOkButtonText : OUString( String( PDFFilterResId( STR_PDF_EXPORT ) ) ));
254 
255 //remove the reset button, not needed in this tabbed dialog
256     RemoveResetButton();
257 /////////////////
258 }
259 
260 // -----------------------------------------------------------------------------
~ImpPDFTabDialog()261 ImpPDFTabDialog::~ImpPDFTabDialog()
262 {
263 //delete the pages, needed because otherwise the child tab pages
264 //don't get destroyed
265     RemoveTabPage( RID_PDF_TAB_GENER );
266     RemoveTabPage( RID_PDF_TAB_VPREFER );
267     RemoveTabPage( RID_PDF_TAB_OPNFTR );
268     RemoveTabPage( RID_PDF_TAB_LINKS );
269     RemoveTabPage( RID_PDF_TAB_SECURITY );
270 }
271 
272 // -----------------------------------------------------------------------------
PageCreated(sal_uInt16 _nId,SfxTabPage & _rPage)273 void ImpPDFTabDialog::PageCreated( sal_uInt16 _nId,
274                                    SfxTabPage& _rPage )
275 {
276     switch( _nId )
277     {
278     case RID_PDF_TAB_GENER:
279         ( ( ImpPDFTabGeneralPage* )&_rPage )->SetFilterConfigItem( this );
280         break;
281     case RID_PDF_TAB_VPREFER:
282         ( ( ImpPDFTabViewerPage* )&_rPage )->SetFilterConfigItem( this );
283         break;
284     case RID_PDF_TAB_OPNFTR:
285         ( ( ImpPDFTabOpnFtrPage* )&_rPage )->SetFilterConfigItem( this );
286         break;
287     case RID_PDF_TAB_LINKS:
288         ( ( ImpPDFTabLinksPage* )&_rPage )->SetFilterConfigItem( this );
289         break;
290     case RID_PDF_TAB_SECURITY:
291         ( ( ImpPDFTabSecurityPage* )&_rPage )->SetFilterConfigItem( this );
292         break;
293     }
294 }
295 
296 // -----------------------------------------------------------------------------
Ok()297 short ImpPDFTabDialog::Ok( )
298 {
299 //here the whole mechanism of the base class is not used
300 //when Ok is hit, the user means 'convert to PDF', so simply close with ok
301     return RET_OK;
302 }
303 
304 // -----------------------------------------------------------------------------
GetFilterData()305 Sequence< PropertyValue > ImpPDFTabDialog::GetFilterData()
306 {
307 // updating the FilterData sequence and storing FilterData to configuration
308     if( GetTabPage( RID_PDF_TAB_GENER ) )
309         ( ( ImpPDFTabGeneralPage* )GetTabPage( RID_PDF_TAB_GENER ) )->GetFilterConfigItem( this );
310     if( GetTabPage( RID_PDF_TAB_VPREFER ) )
311         ( ( ImpPDFTabViewerPage* )GetTabPage( RID_PDF_TAB_VPREFER ) )->GetFilterConfigItem( this );
312     if( GetTabPage( RID_PDF_TAB_OPNFTR ) )
313         ( ( ImpPDFTabOpnFtrPage* )GetTabPage( RID_PDF_TAB_OPNFTR ) )->GetFilterConfigItem( this );
314     if( GetTabPage( RID_PDF_TAB_LINKS ) )
315         ( ( ImpPDFTabLinksPage* )GetTabPage( RID_PDF_TAB_LINKS ) )->GetFilterConfigItem( this );
316     if( GetTabPage( RID_PDF_TAB_SECURITY ) )
317         ( ( ImpPDFTabSecurityPage* )GetTabPage( RID_PDF_TAB_SECURITY ) )->GetFilterConfigItem( this );
318 
319 //prepare the items to be returned
320     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "UseLosslessCompression" ) ), mbUseLosslessCompression );
321     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), mnQuality );
322     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ReduceImageResolution" ) ), mbReduceImageResolution );
323     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxImageResolution" ) ), mnMaxImageResolution );
324 
325     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "UseTaggedPDF" ) ), mbUseTaggedPDF );
326     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectPdfVersion" ) ), mnPDFTypeSelection );
327 
328     if ( mbIsPresentation )
329         maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportNotesPages" ) ), mbExportNotesPages );
330 	maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportNotes" ) ), mbExportNotes );
331 
332     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarks" ) ), mbExportBookmarks );
333     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "UseTransitionEffects" ) ), mbUseTransitionEffects );
334     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsSkipEmptyPages" ) ), mbIsSkipEmptyPages );
335     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "IsAddStream" ) ), mbAddStream );
336     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "EmbedStandardFonts" ) ), mbEmbedStandardFonts );
337 
338     /*
339     * FIXME: the entries are only implicitly defined by the resource file. Should there
340     * ever be an additional form submit format this could get invalid.
341     */
342     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "FormsType" ) ), mnFormsType );
343     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportFormFields" ) ), mbExportFormFields );
344     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowDuplicateFieldNames" ) ), mbAllowDuplicateFieldNames );
345 
346     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "HideViewerToolbar" ) ), mbHideViewerToolbar );
347     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "HideViewerMenubar" ) ), mbHideViewerMenubar );
348     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "HideViewerWindowControls" ) ), mbHideViewerWindowControls );
349     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ResizeWindowToInitialPage" ) ), mbResizeWinToInit );
350     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "CenterWindow" ) ), mbCenterWindow );
351     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenInFullScreenMode" ) ), mbOpenInFullScreenMode );
352     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "DisplayPDFDocumentTitle" ) ), mbDisplayPDFDocumentTitle );
353     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "InitialView" ) ), mnInitialView );
354     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Magnification" ) ), mnMagnification);
355     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Zoom" ) ), mnZoom );
356     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "InitialPage" ) ), mnInitialPage );
357     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "PageLayout" ) ), mnPageLayout );
358     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "FirstPageOnLeft" ) ), mbFirstPageLeft );
359     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenBookmarkLevels" ) ), mnOpenBookmarkLevels );
360 
361     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportLinksRelativeFsys" ) ), mbExportRelativeFsysLinks );
362 	maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "PDFViewSelection" ) ), mnViewPDFMode );
363 	maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ConvertOOoTargetToPDFTarget" ) ), mbConvertOOoTargets );
364 	maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarksToPDFDestination" ) ), mbExportBmkToPDFDestination );
365 
366     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Printing" ) ), mnPrint );
367     maConfigItem.WriteInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "Changes" ) ), mnChangesAllowed );
368     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableCopyingOfContent" ) ), mbCanCopyOrExtract );
369     maConfigItem.WriteBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableTextAccessForAccessibilityTools" ) ), mbCanExtractForAccessibility );
370 
371     Sequence< PropertyValue > aRet( maConfigItem.GetFilterData() );
372 
373 	int nElementAdded = 5;
374 
375     aRet.realloc( aRet.getLength() + nElementAdded );
376 
377 // add the encryption enable flag
378 	aRet[ aRet.getLength() - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptFile" ) );
379 	aRet[ aRet.getLength() - nElementAdded ].Value <<= mbEncrypt;
380 	nElementAdded--;
381 
382 // add the open password
383 	aRet[ aRet.getLength() - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PreparedPasswords" ) );
384 	aRet[ aRet.getLength() - nElementAdded ].Value <<= mxPreparedPasswords;
385 	nElementAdded--;
386 
387 //the restrict permission flag (needed to have the scripting consistent with the dialog)
388 	aRet[ aRet.getLength() - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "RestrictPermissions" ) );
389 	aRet[ aRet.getLength() - nElementAdded ].Value <<= mbRestrictPermissions;
390 	nElementAdded--;
391 
392 //add the permission password
393 	aRet[ aRet.getLength() - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PreparedPermissionPassword" ) );
394 	aRet[ aRet.getLength() - nElementAdded ].Value <<= maPreparedOwnerPassword;
395 	nElementAdded--;
396 
397 // this should be the last added...
398     if( mbIsRangeChecked )
399     {
400         aRet[ aRet.getLength() - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageRange" ) );
401         aRet[ aRet.getLength() - nElementAdded ].Value <<= OUString( msPageRange );
402     }
403     else if( mbSelectionIsChecked )
404     {
405         aRet[ aRet.getLength() - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Selection" ) );
406         aRet[ aRet.getLength() - nElementAdded ].Value <<= maSelection;
407     }
408 
409     return aRet;
410 }
411 
412 // -----------------------------------------------------------------------------
ImpPDFTabGeneralPage(Window * pParent,const SfxItemSet & rCoreSet)413 ImpPDFTabGeneralPage::ImpPDFTabGeneralPage( Window* pParent,
414                                             const SfxItemSet& rCoreSet
415                                             ) :
416     SfxTabPage( pParent, PDFFilterResId( RID_PDF_TAB_GENER ), rCoreSet ),
417 
418     maFlPages( this, PDFFilterResId( FL_PAGES ) ),
419     maRbAll( this, PDFFilterResId( RB_ALL ) ),
420     maRbRange( this, PDFFilterResId( RB_RANGE ) ),
421     maRbSelection( this, PDFFilterResId( RB_SELECTION ) ),
422     maEdPages( this, PDFFilterResId( ED_PAGES ) ),
423 
424     maFlCompression( this, PDFFilterResId( FL_IMAGES ) ),
425     maRbLosslessCompression( this, PDFFilterResId( RB_LOSSLESSCOMPRESSION ) ),
426     maRbJPEGCompression( this, PDFFilterResId( RB_JPEGCOMPRESSION ) ),
427     maFtQuality( this, PDFFilterResId( FT_QUALITY ) ),
428     maNfQuality( this, PDFFilterResId( NF_QUALITY ) ),
429     maCbReduceImageResolution( this, PDFFilterResId( CB_REDUCEIMAGERESOLUTION ) ),
430     maCoReduceImageResolution( this, PDFFilterResId( CO_REDUCEIMAGERESOLUTION ) ),
431 
432     maFlGeneral( this, PDFFilterResId( FL_GENERAL ) ),
433     maCbPDFA1b( this, PDFFilterResId( CB_PDFA_1B_SELECT ) ),
434 
435     maCbTaggedPDF( this, PDFFilterResId( CB_TAGGEDPDF ) ),
436     mbTaggedPDFUserSelection( sal_False ),
437 
438     maCbExportFormFields( this, PDFFilterResId( CB_EXPORTFORMFIELDS ) ),
439     mbExportFormFieldsUserSelection( sal_False ),
440     mbEmbedStandardFontsUserSelection( sal_False ),
441     maFtFormsFormat( this, PDFFilterResId( FT_FORMSFORMAT ) ),
442     maLbFormsFormat( this, PDFFilterResId( LB_FORMSFORMAT ) ),
443     maCbAllowDuplicateFieldNames( this, PDFFilterResId( CB_ALLOWDUPLICATEFIELDNAMES ) ),
444 
445     maCbExportBookmarks( this, PDFFilterResId( CB_EXPORTBOOKMARKS ) ),
446     maCbExportNotes( this, PDFFilterResId( CB_EXPORTNOTES ) ),
447     maCbExportNotesPages( this, PDFFilterResId( CB_EXPORTNOTESPAGES ) ),
448     maCbExportEmptyPages( this, PDFFilterResId( CB_EXPORTEMPTYPAGES ) ),
449     maCbAddStream( this, PDFFilterResId( CB_ADDSTREAM ) ),
450     maCbEmbedStandardFonts( this, PDFFilterResId( CB_EMBEDSTANDARDFONTS ) ),
451     mbIsPresentation( sal_False ),
452 	mbIsWriter( sal_False),
453     mpaParent( 0 )
454 {
455     FreeResource();
456 
457     // pb: #i91991# maCbExportEmptyPages double-spaced if necessary
458     Size aSize = maCbExportEmptyPages.GetSizePixel();
459     Size aMinSize = maCbExportEmptyPages.CalcMinimumSize();
460     if ( aSize.Width() > aMinSize.Width() )
461     {
462         Size aNewSize = maCbExportNotes.GetSizePixel();
463         long nDelta = aSize.Height() - aNewSize.Height();
464         maCbExportEmptyPages.SetSizePixel( aNewSize );
465         Point aNewPos = maCbAddStream.GetPosPixel();
466         aNewPos.Y() -= nDelta;
467         maCbAddStream.SetPosPixel( aNewPos );
468         aNewPos = maCbEmbedStandardFonts.GetPosPixel();
469         aNewPos.Y() -= nDelta;
470         maCbEmbedStandardFonts.SetPosPixel( aNewPos );
471     }
472 
473 	maEdPages.SetAccessibleName(maRbRange.GetText());
474 	maEdPages.SetAccessibleRelationLabeledBy(&maRbRange);
475 
476     maCbExportEmptyPages.SetStyle( maCbExportEmptyPages.GetStyle() | WB_VCENTER );
477 }
478 
479 // -----------------------------------------------------------------------------
~ImpPDFTabGeneralPage()480 ImpPDFTabGeneralPage::~ImpPDFTabGeneralPage()
481 {
482 }
483 
484 // -----------------------------------------------------------------------------
SetFilterConfigItem(const ImpPDFTabDialog * paParent)485 void ImpPDFTabGeneralPage::SetFilterConfigItem( const ImpPDFTabDialog* paParent )
486 {
487     mpaParent = paParent;
488 
489 //init this class data
490     maRbRange.SetToggleHdl( LINK( this, ImpPDFTabGeneralPage, TogglePagesHdl ) );
491 
492     maRbAll.Check();
493     TogglePagesHdl( NULL );
494 
495     maNfQuality.SetUnit( FUNIT_PERCENT );
496     maNfQuality.SetMin( 1, FUNIT_PERCENT );
497     maNfQuality.SetMax( 100, FUNIT_PERCENT );
498 
499     maRbSelection.Enable( paParent->mbSelectionPresent );
500     mbIsPresentation = paParent->mbIsPresentation;
501     mbIsWriter = paParent->mbIsWriter;
502 
503     maCbExportEmptyPages.Enable( mbIsWriter );
504 
505     maRbLosslessCompression.SetToggleHdl( LINK( this, ImpPDFTabGeneralPage, ToggleCompressionHdl ) );
506     const sal_Bool bUseLosslessCompression = paParent->mbUseLosslessCompression;
507     if ( bUseLosslessCompression )
508         maRbLosslessCompression.Check();
509 	else
510         maRbJPEGCompression.Check();
511 
512     maNfQuality.SetValue( paParent->mnQuality, FUNIT_PERCENT );
513     maNfQuality.Enable( bUseLosslessCompression == sal_False );
514 
515     maCbReduceImageResolution.SetToggleHdl( LINK( this, ImpPDFTabGeneralPage, ToggleReduceImageResolutionHdl ) );
516     const sal_Bool	bReduceImageResolution = paParent->mbReduceImageResolution;
517     maCbReduceImageResolution.Check( bReduceImageResolution );
518     String aStrRes( String::CreateFromInt32( paParent->mnMaxImageResolution ) );
519     aStrRes.Append( String( RTL_CONSTASCII_USTRINGPARAM( " DPI" ) ) );
520     maCoReduceImageResolution.SetText( aStrRes );
521     maCoReduceImageResolution.Enable( bReduceImageResolution );
522 
523     maCbPDFA1b.SetToggleHdl( LINK( this, ImpPDFTabGeneralPage, ToggleExportPDFAHdl) );
524     switch( paParent->mnPDFTypeSelection )
525     {
526     default:
527     case 0: maCbPDFA1b.Check( sal_False ); // PDF 1.4
528         break;
529     case 1: maCbPDFA1b.Check(); // PDF/A-1a
530         break;
531     }
532     ToggleExportPDFAHdl( NULL );
533 
534     maCbExportFormFields.SetToggleHdl( LINK( this, ImpPDFTabGeneralPage, ToggleExportFormFieldsHdl ) );
535 
536 // get the form values, for use with PDF/A-1 selection interface
537     mbTaggedPDFUserSelection = paParent->mbUseTaggedPDF;
538     mbExportFormFieldsUserSelection = paParent->mbExportFormFields;
539     mbEmbedStandardFontsUserSelection = paParent->mbEmbedStandardFonts;
540 
541     if( !maCbPDFA1b.IsChecked() )
542     {// the value for PDF/A set by the ToggleExportPDFAHdl method called before
543         maCbTaggedPDF.Check( mbTaggedPDFUserSelection  );
544         maCbExportFormFields.Check( mbExportFormFieldsUserSelection );
545         maCbEmbedStandardFonts.Check( mbEmbedStandardFontsUserSelection );
546     }
547 
548     maLbFormsFormat.SelectEntryPos( (sal_uInt16)paParent->mnFormsType );
549     maLbFormsFormat.Enable( paParent->mbExportFormFields );
550     maCbAllowDuplicateFieldNames.Check( paParent->mbAllowDuplicateFieldNames );
551     maCbAllowDuplicateFieldNames.Enable( paParent->mbExportFormFields );
552 
553 	maCbExportBookmarks.Check( paParent->mbExportBookmarks );
554 
555 	maCbExportNotes.Check( paParent->mbExportNotes );
556 
557 	if ( mbIsPresentation )
558 	{
559 		maCbExportNotesPages.Show( sal_True );
560         maCbExportNotesPages.Check( paParent->mbExportNotesPages );
561 	}
562 	else
563 	{
564 	    long nCheckBoxHeight =
565 		    maCbExportNotesPages.LogicToPixel( Size( 13, 13 ), MAP_APPFONT ).Height();
566 
567 		Point aPos = maCbExportEmptyPages.GetPosPixel();
568 		maCbExportEmptyPages.SetPosPixel( Point( aPos.X(), aPos.Y() - nCheckBoxHeight ) );
569 		aPos = maCbAddStream.GetPosPixel();
570 		maCbAddStream.SetPosPixel( Point( aPos.X(), aPos.Y() - nCheckBoxHeight ) );
571 		aPos = maCbEmbedStandardFonts.GetPosPixel();
572 		maCbEmbedStandardFonts.SetPosPixel( Point( aPos.X(), aPos.Y() - nCheckBoxHeight ) );
573 		maCbExportNotesPages.Show( sal_False );
574 		maCbExportNotesPages.Check( sal_False );
575 	}
576 
577     maCbExportEmptyPages.Check( !paParent->mbIsSkipEmptyPages );
578 
579     maCbAddStream.Check( paParent->mbAddStream );
580     maCbAddStream.SetToggleHdl( LINK( this, ImpPDFTabGeneralPage, ToggleAddStreamHdl ) );
581     // init addstream dependencies
582     ToggleAddStreamHdl( NULL );
583 }
584 
585 // -----------------------------------------------------------------------------
GetFilterConfigItem(ImpPDFTabDialog * paParent)586 void ImpPDFTabGeneralPage::GetFilterConfigItem( ImpPDFTabDialog* paParent )
587 {
588 // updating the FilterData sequence and storing FilterData to configuration
589     paParent->mbUseLosslessCompression = maRbLosslessCompression.IsChecked();
590     paParent->mnQuality = static_cast<sal_Int32>(maNfQuality.GetValue());
591     paParent->mbReduceImageResolution = maCbReduceImageResolution.IsChecked();
592     paParent->mnMaxImageResolution = maCoReduceImageResolution.GetText().ToInt32();
593     paParent->mbExportNotes = maCbExportNotes.IsChecked();
594 	if ( mbIsPresentation )
595 		paParent->mbExportNotesPages = maCbExportNotesPages.IsChecked();
596     paParent->mbExportBookmarks = maCbExportBookmarks.IsChecked();
597 
598     paParent->mbIsSkipEmptyPages =  !maCbExportEmptyPages.IsChecked();
599     paParent->mbAddStream = maCbAddStream.IsChecked();
600 
601     paParent->mbIsRangeChecked = sal_False;
602     if( maRbRange.IsChecked() )
603     {
604         paParent->mbIsRangeChecked = sal_True;
605         paParent->msPageRange = String( maEdPages.GetText() ); //FIXME all right on other languages ?
606     }
607     else if( maRbSelection.IsChecked() )
608     {
609         paParent->mbSelectionIsChecked = maRbSelection.IsChecked();
610     }
611 
612     paParent->mnPDFTypeSelection = 0;
613     if( maCbPDFA1b.IsChecked() )
614     {
615         paParent->mnPDFTypeSelection = 1;
616         paParent->mbUseTaggedPDF =  mbTaggedPDFUserSelection;
617         paParent->mbExportFormFields = mbExportFormFieldsUserSelection;
618         paParent->mbEmbedStandardFonts = mbEmbedStandardFontsUserSelection;
619     }
620     else
621     {
622         paParent->mbUseTaggedPDF =  maCbTaggedPDF.IsChecked();
623         paParent->mbExportFormFields = maCbExportFormFields.IsChecked();
624         paParent->mbEmbedStandardFonts = maCbEmbedStandardFonts.IsChecked();
625     }
626 
627     /*
628     * FIXME: the entries are only implicitly defined by the resource file. Should there
629     * ever be an additional form submit format this could get invalid.
630     */
631     paParent->mnFormsType = (sal_Int32) maLbFormsFormat.GetSelectEntryPos();
632     paParent->mbAllowDuplicateFieldNames = maCbAllowDuplicateFieldNames.IsChecked();
633 }
634 
635 // -----------------------------------------------------------------------------
Create(Window * pParent,const SfxItemSet & rAttrSet)636 SfxTabPage*  ImpPDFTabGeneralPage::Create( Window* pParent,
637                                            const SfxItemSet& rAttrSet)
638 {
639 	return ( new  ImpPDFTabGeneralPage( pParent, rAttrSet ) );
640 }
641 
642 // -----------------------------------------------------------------------------
IMPL_LINK(ImpPDFTabGeneralPage,TogglePagesHdl,void *,EMPTYARG)643 IMPL_LINK( ImpPDFTabGeneralPage, TogglePagesHdl, void*, EMPTYARG )
644 {
645     maEdPages.Enable( maRbRange.IsChecked() );
646     //When the control is disabled, it is also readonly. So here, it is not necessary to set it as readonly.
647     //maEdPages.SetReadOnly( !maRbRange.IsChecked() );
648     return 0;
649 }
650 
651 // -----------------------------------------------------------------------------
IMPL_LINK(ImpPDFTabGeneralPage,ToggleExportFormFieldsHdl,void *,EMPTYARG)652 IMPL_LINK( ImpPDFTabGeneralPage, ToggleExportFormFieldsHdl, void*, EMPTYARG )
653 {
654     maLbFormsFormat.Enable( maCbExportFormFields.IsChecked() );
655     maCbAllowDuplicateFieldNames.Enable( maCbExportFormFields.IsChecked() );
656     return 0;
657 }
658 
659 // -----------------------------------------------------------------------------
IMPL_LINK(ImpPDFTabGeneralPage,ToggleCompressionHdl,void *,EMPTYARG)660 IMPL_LINK( ImpPDFTabGeneralPage, ToggleCompressionHdl, void*, EMPTYARG )
661 {
662     maNfQuality.Enable( maRbJPEGCompression.IsChecked() );
663     return 0;
664 }
665 
666 // -----------------------------------------------------------------------------
IMPL_LINK(ImpPDFTabGeneralPage,ToggleReduceImageResolutionHdl,void *,EMPTYARG)667 IMPL_LINK( ImpPDFTabGeneralPage, ToggleReduceImageResolutionHdl, void*, EMPTYARG )
668 {
669     maCoReduceImageResolution.Enable( maCbReduceImageResolution.IsChecked() );
670     return 0;
671 }
672 
673 // -----------------------------------------------------------------------------
IMPL_LINK(ImpPDFTabGeneralPage,ToggleAddStreamHdl,void *,EMPTYARG)674 IMPL_LINK( ImpPDFTabGeneralPage, ToggleAddStreamHdl, void*, EMPTYARG )
675 {
676     if( maCbAddStream.IsChecked() )
677     {
678         maRbAll.Check();
679         maRbRange.Enable( sal_False );
680         maRbSelection.Enable( sal_False );
681         maEdPages.Enable( sal_False );
682         maRbAll.Enable( sal_False );
683     }
684     else
685     {
686         maRbAll.Enable( sal_True );
687         maRbRange.Enable( sal_True );
688         maRbSelection.Enable( sal_True );
689     }
690 
691     return 0;
692 }
693 
694 // -----------------------------------------------------------------------------
IMPL_LINK(ImpPDFTabGeneralPage,ToggleExportPDFAHdl,void *,EMPTYARG)695 IMPL_LINK( ImpPDFTabGeneralPage, ToggleExportPDFAHdl, void*, EMPTYARG )
696 {
697     ImpPDFTabSecurityPage* pSecPage = NULL;
698 //set the security page status (and its controls as well)
699     if( mpaParent && mpaParent->GetTabPage( RID_PDF_TAB_SECURITY ) )
700     {
701         pSecPage = static_cast<ImpPDFTabSecurityPage*>(mpaParent->GetTabPage( RID_PDF_TAB_SECURITY ));
702         pSecPage->ImplPDFASecurityControl( !maCbPDFA1b.IsChecked() );
703     }
704 
705 //PDF/A-1 needs tagged PDF, so  force disable the control, will be forced in pdfexport.
706     sal_Bool bPDFA1Sel = maCbPDFA1b.IsChecked();
707     maFtFormsFormat.Enable( !bPDFA1Sel );
708     maLbFormsFormat.Enable( !bPDFA1Sel );
709     maCbAllowDuplicateFieldNames.Enable( !bPDFA1Sel );
710     if(bPDFA1Sel)
711     {
712 //store the values of subordinate controls
713         mbTaggedPDFUserSelection = maCbTaggedPDF.IsChecked();
714         maCbTaggedPDF.Check();
715         maCbTaggedPDF.Enable( sal_False );
716         mbExportFormFieldsUserSelection = maCbExportFormFields.IsChecked();
717         maCbExportFormFields.Check( sal_False );
718         maCbExportFormFields.Enable( sal_False );
719         mbEmbedStandardFontsUserSelection = maCbEmbedStandardFonts.IsChecked();
720         maCbEmbedStandardFonts.Check( sal_True );
721         maCbEmbedStandardFonts.Enable( sal_False );
722     }
723     else
724     {
725 //retrieve the values of subordinate controls
726         maCbTaggedPDF.Enable();
727         maCbTaggedPDF.Check( mbTaggedPDFUserSelection );
728         maCbExportFormFields.Check( mbExportFormFieldsUserSelection );
729         maCbExportFormFields.Enable();
730         maCbEmbedStandardFonts.Check( mbEmbedStandardFontsUserSelection );
731         maCbEmbedStandardFonts.Enable();
732     }
733 // PDF/A-1 doesn't allow launch action, so enable/disable the selection on
734 // Link page
735     if( mpaParent && mpaParent->GetTabPage( RID_PDF_TAB_LINKS ) )
736         ( ( ImpPDFTabLinksPage* )mpaParent->GetTabPage( RID_PDF_TAB_LINKS ) )->ImplPDFALinkControl( !maCbPDFA1b.IsChecked() );
737 
738     // if a password was set, inform the user that this will not be used in PDF/A case
739     if( maCbPDFA1b.IsChecked() && pSecPage && pSecPage->hasPassword() )
740     {
741         WarningBox aBox( this, PDFFilterResId( RID_PDF_WARNPDFAPASSWORD ) );
742         aBox.Execute();
743     }
744 
745     return 0;
746 }
747 
748 /////////////////////////////////////////////////////////////////
749 // the option features tab page
750 // -----------------------------------------------------------------------------
ImpPDFTabOpnFtrPage(Window * pParent,const SfxItemSet & rCoreSet)751 ImpPDFTabOpnFtrPage::ImpPDFTabOpnFtrPage( Window* pParent,
752                                           const SfxItemSet& rCoreSet ) :
753     SfxTabPage( pParent, PDFFilterResId( RID_PDF_TAB_OPNFTR ), rCoreSet ),
754 
755     maFlInitialView( this, PDFFilterResId( FL_INITVIEW ) ),
756     maRbOpnPageOnly( this, PDFFilterResId( RB_OPNMODE_PAGEONLY ) ),
757     maRbOpnOutline( this, PDFFilterResId( RB_OPNMODE_OUTLINE ) ),
758     maRbOpnThumbs( this, PDFFilterResId( RB_OPNMODE_THUMBS ) ),
759     maFtInitialPage( this, PDFFilterResId( FT_MAGNF_INITIAL_PAGE ) ),
760     maNumInitialPage( this, PDFFilterResId( NUM_MAGNF_INITIAL_PAGE ) ),
761 
762     maFlMagnification( this, PDFFilterResId( FL_MAGNIFICATION ) ),
763     maRbMagnDefault( this, PDFFilterResId( RB_MAGNF_DEFAULT ) ),
764     maRbMagnFitWin( this, PDFFilterResId( RB_MAGNF_WIND ) ),
765     maRbMagnFitWidth( this, PDFFilterResId( RB_MAGNF_WIDTH ) ),
766     maRbMagnFitVisible( this, PDFFilterResId( RB_MAGNF_VISIBLE ) ),
767     maRbMagnZoom( this, PDFFilterResId( RB_MAGNF_ZOOM ) ),
768     maNumZoom( this, PDFFilterResId( NUM_MAGNF_ZOOM ) ),
769 
770     maFlPageLayout( this, PDFFilterResId( FL_PAGE_LAYOUT ) ),
771     maRbPgLyDefault( this, PDFFilterResId( RB_PGLY_DEFAULT ) ),
772     maRbPgLySinglePage( this, PDFFilterResId( RB_PGLY_SINGPG ) ),
773     maRbPgLyContinue( this, PDFFilterResId( RB_PGLY_CONT ) ),
774     maRbPgLyContinueFacing( this, PDFFilterResId( RB_PGLY_CONTFAC ) ),
775     maCbPgLyFirstOnLeft( this, PDFFilterResId( CB_PGLY_FIRSTLEFT ) ),
776     mbUseCTLFont( sal_False )
777 {
778     FreeResource();
779 
780     maRbMagnDefault.SetToggleHdl( LINK( this, ImpPDFTabOpnFtrPage, ToggleRbMagnHdl ) );
781     maRbMagnFitWin.SetToggleHdl( LINK( this, ImpPDFTabOpnFtrPage, ToggleRbMagnHdl ) );
782     maRbMagnFitWidth.SetToggleHdl( LINK( this, ImpPDFTabOpnFtrPage, ToggleRbMagnHdl ) );
783     maRbMagnFitVisible.SetToggleHdl( LINK( this, ImpPDFTabOpnFtrPage, ToggleRbMagnHdl ) );
784     maRbMagnZoom.SetToggleHdl( LINK( this, ImpPDFTabOpnFtrPage, ToggleRbMagnHdl ) );
785 	maNumZoom.SetAccessibleName(maRbMagnZoom.GetText());
786 	maNumZoom.SetAccessibleRelationLabeledBy(&maRbMagnZoom);
787 }
788 
789 // -----------------------------------------------------------------------------
~ImpPDFTabOpnFtrPage()790 ImpPDFTabOpnFtrPage::~ImpPDFTabOpnFtrPage()
791 {
792 }
793 
794 // -----------------------------------------------------------------------------
Create(Window * pParent,const SfxItemSet & rAttrSet)795 SfxTabPage*  ImpPDFTabOpnFtrPage::Create( Window* pParent,
796                                           const SfxItemSet& rAttrSet)
797 {
798     return ( new  ImpPDFTabOpnFtrPage( pParent, rAttrSet ) );
799 }
800 
801 // -----------------------------------------------------------------------------
GetFilterConfigItem(ImpPDFTabDialog * paParent)802 void ImpPDFTabOpnFtrPage::GetFilterConfigItem( ImpPDFTabDialog* paParent  )
803 {
804     paParent->mnInitialView = 0;
805     if( maRbOpnOutline.IsChecked() )
806         paParent->mnInitialView = 1;
807     else if( maRbOpnThumbs.IsChecked() )
808         paParent->mnInitialView = 2;
809 
810     paParent->mnMagnification = 0;
811     if( maRbMagnFitWin.IsChecked() )
812         paParent->mnMagnification = 1;
813     else if( maRbMagnFitWidth.IsChecked() )
814         paParent->mnMagnification = 2;
815     else if( maRbMagnFitVisible.IsChecked() )
816         paParent->mnMagnification = 3;
817     else if( maRbMagnZoom.IsChecked() )
818     {
819         paParent->mnMagnification = 4;
820         paParent->mnZoom = static_cast<sal_Int32>(maNumZoom.GetValue());
821     }
822 
823     paParent->mnInitialPage = static_cast<sal_Int32>(maNumInitialPage.GetValue());
824 
825     paParent->mnPageLayout = 0;
826     if( maRbPgLySinglePage.IsChecked() )
827         paParent->mnPageLayout = 1;
828     else if( maRbPgLyContinue.IsChecked() )
829         paParent->mnPageLayout = 2;
830     else if( maRbPgLyContinueFacing.IsChecked() )
831         paParent->mnPageLayout = 3;
832 
833     paParent->mbFirstPageLeft = ( mbUseCTLFont ) ? maCbPgLyFirstOnLeft.IsChecked() : sal_False;
834 }
835 
836 // -----------------------------------------------------------------------------
SetFilterConfigItem(const ImpPDFTabDialog * paParent)837 void ImpPDFTabOpnFtrPage::SetFilterConfigItem( const  ImpPDFTabDialog* paParent )
838 {
839     mbUseCTLFont = paParent->mbUseCTLFont;
840     switch( paParent->mnPageLayout )
841     {
842     default:
843     case 0:
844         maRbPgLyDefault.Check();
845         break;
846     case 1:
847         maRbPgLySinglePage.Check();
848         break;
849     case 2:
850         maRbPgLyContinue.Check();
851         break;
852     case 3:
853         maRbPgLyContinueFacing.Check();
854         break;
855     };
856 
857     switch( paParent->mnInitialView )
858     {
859     default:
860     case 0:
861         maRbOpnPageOnly.Check();
862         break;
863     case 1:
864         maRbOpnOutline.Check();
865         break;
866     case 2:
867         maRbOpnThumbs.Check();
868         break;
869     };
870 
871     switch( paParent->mnMagnification )
872     {
873     default:
874     case 0:
875         maRbMagnDefault.Check();
876         maNumZoom.Enable( sal_False );
877         break;
878     case 1:
879         maRbMagnFitWin.Check();
880         maNumZoom.Enable( sal_False );
881         break;
882     case 2:
883         maRbMagnFitWidth.Check();
884         maNumZoom.Enable( sal_False );
885         break;
886     case 3:
887         maRbMagnFitVisible.Check();
888         maNumZoom.Enable( sal_False );
889         break;
890     case 4:
891         maRbMagnZoom.Check();
892         maNumZoom.Enable( sal_True );
893         break;
894     };
895 
896     maNumZoom.SetValue( paParent->mnZoom );
897     maNumInitialPage.SetValue( paParent->mnInitialPage );
898 
899     if( !mbUseCTLFont )
900         maCbPgLyFirstOnLeft.Hide( );
901     else
902     {
903         maRbPgLyContinueFacing.SetToggleHdl( LINK( this, ImpPDFTabOpnFtrPage, ToggleRbPgLyContinueFacingHdl ) );
904         maCbPgLyFirstOnLeft.Check( paParent->mbFirstPageLeft );
905         ToggleRbPgLyContinueFacingHdl( NULL );
906     }
907 }
908 
IMPL_LINK(ImpPDFTabOpnFtrPage,ToggleRbPgLyContinueFacingHdl,void *,EMPTYARG)909 IMPL_LINK( ImpPDFTabOpnFtrPage, ToggleRbPgLyContinueFacingHdl, void*, EMPTYARG )
910 {
911     maCbPgLyFirstOnLeft.Enable( maRbPgLyContinueFacing.IsChecked() );
912     return 0;
913 }
914 
915 IMPL_LINK( ImpPDFTabOpnFtrPage, ToggleRbMagnHdl, void*, )
916 {
917     maNumZoom.Enable( maRbMagnZoom.IsChecked() );
918     return 0;
919 }
920 
921 ////////////////////////////////////////////////////////
922 // The Viewer preferences tab page
923 // -----------------------------------------------------------------------------
ImpPDFTabViewerPage(Window * pParent,const SfxItemSet & rCoreSet)924 ImpPDFTabViewerPage::ImpPDFTabViewerPage( Window* pParent,
925                                           const SfxItemSet& rCoreSet ) :
926     SfxTabPage( pParent, PDFFilterResId( RID_PDF_TAB_VPREFER ), rCoreSet ),
927 
928     maFlWindowOptions( this, PDFFilterResId( FL_WINOPT ) ),
929     maCbResWinInit( this, PDFFilterResId( CB_WNDOPT_RESINIT ) ),
930     maCbCenterWindow( this, PDFFilterResId( CB_WNDOPT_CNTRWIN ) ),
931     maCbOpenFullScreen( this, PDFFilterResId( CB_WNDOPT_OPNFULL ) ),
932     maCbDispDocTitle( this, PDFFilterResId( CB_DISPDOCTITLE ) ),
933 
934     maFlUIOptions( this, PDFFilterResId( FL_USRIFOPT ) ),
935     maCbHideViewerMenubar( this, PDFFilterResId( CB_UOP_HIDEVMENUBAR ) ),
936     maCbHideViewerToolbar( this, PDFFilterResId( CB_UOP_HIDEVTOOLBAR ) ),
937     maCbHideViewerWindowControls( this, PDFFilterResId( CB_UOP_HIDEVWINCTRL ) ),
938     maFlTransitions( this, PDFFilterResId( FL_TRANSITIONS ) ),
939     maCbTransitionEffects( this, PDFFilterResId( CB_TRANSITIONEFFECTS ) ),
940     mbIsPresentation( sal_True ),
941     maFlBookmarks( this, PDFFilterResId( FL_BOOKMARKS ) ),
942     maRbAllBookmarkLevels( this, PDFFilterResId( RB_ALLBOOKMARKLEVELS ) ),
943     maRbVisibleBookmarkLevels( this, PDFFilterResId( RB_VISIBLEBOOKMARKLEVELS ) ),
944     maNumBookmarkLevels( this, PDFFilterResId( NUM_BOOKMARKLEVELS ) )
945 {
946     FreeResource();
947     maRbAllBookmarkLevels.SetToggleHdl( LINK( this, ImpPDFTabViewerPage, ToggleRbBookmarksHdl ) );
948     maRbVisibleBookmarkLevels.SetToggleHdl( LINK( this, ImpPDFTabViewerPage, ToggleRbBookmarksHdl ) );
949     maNumBookmarkLevels.SetAccessibleName(maRbVisibleBookmarkLevels.GetText());
950     maNumBookmarkLevels.SetAccessibleRelationLabeledBy(&maRbVisibleBookmarkLevels);
951 }
952 
953 // -----------------------------------------------------------------------------
~ImpPDFTabViewerPage()954 ImpPDFTabViewerPage::~ImpPDFTabViewerPage()
955 {
956 }
957 
958 // -----------------------------------------------------------------------------
959 IMPL_LINK( ImpPDFTabViewerPage, ToggleRbBookmarksHdl, void*, )
960 {
961     maNumBookmarkLevels.Enable( maRbVisibleBookmarkLevels.IsChecked() );
962     return 0;
963 }
964 // -----------------------------------------------------------------------------
Create(Window * pParent,const SfxItemSet & rAttrSet)965 SfxTabPage*  ImpPDFTabViewerPage::Create( Window* pParent,
966                                           const SfxItemSet& rAttrSet)
967 {
968     return ( new  ImpPDFTabViewerPage( pParent, rAttrSet ) );
969 }
970 
971 // -----------------------------------------------------------------------------
GetFilterConfigItem(ImpPDFTabDialog * paParent)972 void ImpPDFTabViewerPage::GetFilterConfigItem( ImpPDFTabDialog* paParent  )
973 {
974     paParent->mbHideViewerMenubar = maCbHideViewerMenubar.IsChecked();
975     paParent->mbHideViewerToolbar = maCbHideViewerToolbar.IsChecked( );
976     paParent->mbHideViewerWindowControls = maCbHideViewerWindowControls.IsChecked();
977     paParent->mbResizeWinToInit = maCbResWinInit.IsChecked();
978     paParent->mbOpenInFullScreenMode = maCbOpenFullScreen.IsChecked();
979     paParent->mbCenterWindow = maCbCenterWindow.IsChecked();
980     paParent->mbDisplayPDFDocumentTitle = maCbDispDocTitle.IsChecked();
981     paParent->mbUseTransitionEffects = maCbTransitionEffects.IsChecked();
982     paParent->mnOpenBookmarkLevels = maRbAllBookmarkLevels.IsChecked() ?
983                                      -1 : static_cast<sal_Int32>(maNumBookmarkLevels.GetValue());
984 }
985 
986 // -----------------------------------------------------------------------------
SetFilterConfigItem(const ImpPDFTabDialog * paParent)987 void ImpPDFTabViewerPage::SetFilterConfigItem( const  ImpPDFTabDialog* paParent )
988 {
989     maCbHideViewerMenubar.Check( paParent->mbHideViewerMenubar );
990     maCbHideViewerToolbar.Check( paParent->mbHideViewerToolbar );
991     maCbHideViewerWindowControls.Check( paParent->mbHideViewerWindowControls );
992 
993     maCbResWinInit.Check( paParent->mbResizeWinToInit );
994     maCbOpenFullScreen.Check( paParent->mbOpenInFullScreenMode );
995     maCbCenterWindow.Check( paParent->mbCenterWindow );
996     maCbDispDocTitle.Check( paParent->mbDisplayPDFDocumentTitle );
997     mbIsPresentation = paParent->mbIsPresentation;
998     maCbTransitionEffects.Check( paParent->mbUseTransitionEffects );
999     maCbTransitionEffects.Enable( mbIsPresentation );
1000     if( paParent->mnOpenBookmarkLevels < 0 )
1001     {
1002         maRbAllBookmarkLevels.Check( sal_True );
1003         maNumBookmarkLevels.Enable( sal_False );
1004     }
1005     else
1006     {
1007         maRbVisibleBookmarkLevels.Check( sal_True );
1008         maNumBookmarkLevels.Enable( sal_True );
1009         maNumBookmarkLevels.SetValue( paParent->mnOpenBookmarkLevels );
1010     }
1011 }
1012 
1013 ////////////////////////////////////////////////////////
1014 // The Security preferences tab page
1015 // -----------------------------------------------------------------------------
ImpPDFTabSecurityPage(Window * i_pParent,const SfxItemSet & i_rCoreSet)1016 ImpPDFTabSecurityPage::ImpPDFTabSecurityPage( Window* i_pParent,
1017 											  const SfxItemSet& i_rCoreSet ) :
1018 	SfxTabPage( i_pParent, PDFFilterResId( RID_PDF_TAB_SECURITY ), i_rCoreSet ),
1019 	maFlGroup( this, PDFFilterResId( FL_PWD_GROUP ) ),
1020 	maPbSetPwd( this, PDFFilterResId( BTN_SET_PWD ) ),
1021 	maFtUserPwd( this, PDFFilterResId( FT_USER_PWD ) ),
1022     maUserPwdSet( PDFFilterResId( STR_USER_PWD_SET ) ),
1023     maUserPwdUnset( PDFFilterResId( STR_USER_PWD_UNSET ) ),
1024     maUserPwdPdfa( PDFFilterResId( STR_USER_PWD_PDFA ) ),
1025 
1026     maStrSetPwd( PDFFilterResId( STR_SET_PWD ) ),
1027 	maFtOwnerPwd( this, PDFFilterResId( FT_OWNER_PWD ) ),
1028     maOwnerPwdSet( PDFFilterResId( STR_OWNER_PWD_SET ) ),
1029     maOwnerPwdUnset( PDFFilterResId( STR_OWNER_PWD_UNSET ) ),
1030     maOwnerPwdPdfa( PDFFilterResId( STR_OWNER_PWD_PDFA ) ),
1031 
1032 	maFlPrintPermissions( this, PDFFilterResId( FL_PRINT_PERMISSIONS ) ),
1033 	maRbPrintNone( this, PDFFilterResId( RB_PRINT_NONE ) ),
1034 	maRbPrintLowRes( this, PDFFilterResId( RB_PRINT_LOWRES ) ),
1035 	maRbPrintHighRes( this, PDFFilterResId( RB_PRINT_HIGHRES ) ),
1036 
1037 	maFlChangesAllowed( this, PDFFilterResId( FL_CHANGES_ALLOWED ) ),
1038 	maRbChangesNone( this, PDFFilterResId( RB_CHANGES_NONE ) ),
1039 	maRbChangesInsDel( this, PDFFilterResId( RB_CHANGES_INSDEL ) ),
1040 	maRbChangesFillForm( this, PDFFilterResId( RB_CHANGES_FILLFORM ) ),
1041 	maRbChangesComment( this, PDFFilterResId( RB_CHANGES_COMMENT ) ),
1042 	maRbChangesAnyNoCopy( this, PDFFilterResId( RB_CHANGES_ANY_NOCOPY ) ),
1043 
1044 	maCbEnableCopy( this, PDFFilterResId( CB_ENDAB_COPY ) ),
1045 	maCbEnableAccessibility( this, PDFFilterResId( CB_ENAB_ACCESS ) ),
1046 
1047 	msUserPwdTitle( PDFFilterResId( STR_PDF_EXPORT_UDPWD ) ),
1048 	mbHaveOwnerPassword( false ),
1049 	mbHaveUserPassword( false ),
1050 
1051 	msOwnerPwdTitle( PDFFilterResId( STR_PDF_EXPORT_ODPWD ) )
1052 {
1053     maUserPwdSet.Append( sal_Unicode( '\n' ) );
1054     maUserPwdSet.Append( String( PDFFilterResId( STR_USER_PWD_ENC ) ) );
1055 
1056     maUserPwdUnset.Append( sal_Unicode( '\n' ) );
1057     maUserPwdUnset.Append( String( PDFFilterResId( STR_USER_PWD_UNENC ) ) );
1058 
1059     maOwnerPwdSet.Append( sal_Unicode( '\n' ) );
1060     maOwnerPwdSet.Append( String( PDFFilterResId( STR_OWNER_PWD_REST ) ) );
1061 
1062     maOwnerPwdUnset.Append( sal_Unicode( '\n' ) );
1063     maOwnerPwdUnset.Append( String( PDFFilterResId( STR_OWNER_PWD_UNREST ) ) );
1064 
1065 	FreeResource();
1066 
1067     maFtUserPwd.SetText( maUserPwdUnset );
1068     maFtOwnerPwd.SetText( maOwnerPwdUnset );
1069 
1070     // pb: #i91991# maRbChangesComment double-spaced if necessary
1071     Size aSize = maRbChangesComment.GetSizePixel();
1072     Size aMinSize = maRbChangesComment.CalcMinimumSize();
1073     if ( aSize.Width() > aMinSize.Width() )
1074     {
1075         Size aNewSize = maRbChangesFillForm.GetSizePixel();
1076         long nDelta = aSize.Height() - aNewSize.Height();
1077         maRbChangesComment.SetSizePixel( aNewSize );
1078         Window* pWins[] =
1079             { &maRbChangesAnyNoCopy, &maCbEnableCopy, &maCbEnableAccessibility, NULL };
1080         Window** pCurrent = pWins;
1081         while ( *pCurrent )
1082         {
1083             Point aNewPos = (*pCurrent)->GetPosPixel();
1084             aNewPos.Y() -= nDelta;
1085             (*pCurrent++)->SetPosPixel( aNewPos );
1086         }
1087     }
1088 
1089     maPbSetPwd.SetClickHdl( LINK( this, ImpPDFTabSecurityPage, ClickmaPbSetPwdHdl ) );
1090 }
1091 
1092 // -----------------------------------------------------------------------------
~ImpPDFTabSecurityPage()1093 ImpPDFTabSecurityPage::~ImpPDFTabSecurityPage()
1094 {
1095 }
1096 
1097 // -----------------------------------------------------------------------------
Create(Window * pParent,const SfxItemSet & rAttrSet)1098 SfxTabPage*  ImpPDFTabSecurityPage::Create( Window* pParent,
1099                                           const SfxItemSet& rAttrSet)
1100 {
1101 	return ( new  ImpPDFTabSecurityPage( pParent, rAttrSet ) );
1102 }
1103 
1104 // -----------------------------------------------------------------------------
GetFilterConfigItem(ImpPDFTabDialog * paParent)1105 void ImpPDFTabSecurityPage::GetFilterConfigItem( ImpPDFTabDialog* paParent  )
1106 {
1107 // please note that in PDF/A-1a mode even if this are copied back,
1108 // the security settings are forced disabled in PDFExport::Export
1109 	paParent->mbEncrypt = mbHaveUserPassword;
1110 	paParent->mxPreparedPasswords = mxPreparedPasswords;
1111 
1112 	paParent->mbRestrictPermissions = mbHaveOwnerPassword;
1113 	paParent->maPreparedOwnerPassword = maPreparedOwnerPassword;
1114 
1115 //verify print status
1116 	paParent->mnPrint = 0;
1117 	if( maRbPrintLowRes.IsChecked() )
1118 		paParent->mnPrint = 1;
1119 	else if( maRbPrintHighRes.IsChecked() )
1120 		paParent->mnPrint = 2;
1121 
1122 //verify changes permitted
1123 	paParent->mnChangesAllowed = 0;
1124 
1125 	if( maRbChangesInsDel.IsChecked() )
1126 		paParent->mnChangesAllowed = 1;
1127 	else if( maRbChangesFillForm.IsChecked() )
1128 		paParent->mnChangesAllowed = 2;
1129 	else if( maRbChangesComment.IsChecked() )
1130 		paParent->mnChangesAllowed = 3;
1131 	else if( maRbChangesAnyNoCopy.IsChecked() )
1132 		paParent->mnChangesAllowed = 4;
1133 
1134 	paParent->mbCanCopyOrExtract = maCbEnableCopy.IsChecked();
1135 	paParent->mbCanExtractForAccessibility = maCbEnableAccessibility.IsChecked();
1136 }
1137 
1138 
1139 // -----------------------------------------------------------------------------
SetFilterConfigItem(const ImpPDFTabDialog * paParent)1140 void ImpPDFTabSecurityPage::SetFilterConfigItem( const  ImpPDFTabDialog* paParent )
1141 {
1142 	switch( paParent->mnPrint )
1143 	{
1144 	default:
1145 	case 0:
1146 		maRbPrintNone.Check();
1147 		break;
1148 	case 1:
1149 		maRbPrintLowRes.Check();
1150 		break;
1151 	case 2:
1152 		maRbPrintHighRes.Check();
1153 		break;
1154 	};
1155 
1156 	switch( paParent->mnChangesAllowed )
1157 	{
1158 	default:
1159 	case 0:
1160 		maRbChangesNone.Check();
1161 		break;
1162 	case 1:
1163 		maRbChangesInsDel.Check();
1164 		break;
1165 	case 2:
1166 		maRbChangesFillForm.Check();
1167 		break;
1168 	case 3:
1169 		maRbChangesComment.Check();
1170 		break;
1171 	case 4:
1172 		maRbChangesAnyNoCopy.Check();
1173 		break;
1174 	};
1175 
1176 	maCbEnableCopy.Check( paParent->mbCanCopyOrExtract );
1177 	maCbEnableAccessibility.Check( paParent->mbCanExtractForAccessibility );
1178 
1179 // set the status of this windows, according to the PDFA selection
1180     enablePermissionControls();
1181 
1182     if( paParent && paParent->GetTabPage( RID_PDF_TAB_GENER ) )
1183         ImplPDFASecurityControl(
1184             !( ( ImpPDFTabGeneralPage* )paParent->GetTabPage( RID_PDF_TAB_GENER ) )->IsPdfaSelected() );
1185 }
1186 
IMPL_LINK(ImpPDFTabSecurityPage,ClickmaPbSetPwdHdl,void *,EMPTYARG)1187 IMPL_LINK( ImpPDFTabSecurityPage, ClickmaPbSetPwdHdl, void*, EMPTYARG )
1188 {
1189 	SfxPasswordDialog aPwdDialog( this, &msUserPwdTitle );
1190 	aPwdDialog.SetMinLen( 0 );
1191 	aPwdDialog.ShowExtras( SHOWEXTRAS_CONFIRM | SHOWEXTRAS_PASSWORD2 | SHOWEXTRAS_CONFIRM2 );
1192 	aPwdDialog.SetText( maStrSetPwd );
1193 	aPwdDialog.SetGroup2Text( msOwnerPwdTitle );
1194     aPwdDialog.AllowAsciiOnly();
1195 	if( aPwdDialog.Execute() == RET_OK )  //OK issued get password and set it
1196 	{
1197 	    rtl::OUString aUserPW( aPwdDialog.GetPassword() );
1198 	    rtl::OUString aOwnerPW( aPwdDialog.GetPassword2() );
1199 
1200 	    mbHaveUserPassword = (aUserPW.getLength() != 0);
1201 	    mbHaveOwnerPassword = (aOwnerPW.getLength() != 0);
1202 
1203 	    mxPreparedPasswords = vcl::PDFWriter::InitEncryption( aOwnerPW, aUserPW, true );
1204 
1205 	    if( mbHaveOwnerPassword )
1206 	    {
1207 	        maPreparedOwnerPassword = comphelper::OStorageHelper::CreatePackageEncryptionData( aOwnerPW );
1208 	    }
1209 	    else
1210 	        maPreparedOwnerPassword = Sequence< NamedValue >();
1211 
1212 	    // trash clear text passwords string memory
1213 	    rtl_zeroMemory( (void*)aUserPW.getStr(), aUserPW.getLength() );
1214 	    rtl_zeroMemory( (void*)aOwnerPW.getStr(), aOwnerPW.getLength() );
1215 	}
1216     enablePermissionControls();
1217 	return 0;
1218 }
1219 
enablePermissionControls()1220 void ImpPDFTabSecurityPage::enablePermissionControls()
1221 {
1222     sal_Bool bIsPDFASel =  sal_False;
1223     ImpPDFTabDialog* pParent = static_cast<ImpPDFTabDialog*>(GetTabDialog());
1224     if( pParent && pParent->GetTabPage( RID_PDF_TAB_GENER ) )
1225         bIsPDFASel = ( ( ImpPDFTabGeneralPage* )pParent->
1226                        GetTabPage( RID_PDF_TAB_GENER ) )->IsPdfaSelected();
1227     if( bIsPDFASel )
1228         maFtUserPwd.SetText( maUserPwdPdfa );
1229     else
1230         maFtUserPwd.SetText( (mbHaveUserPassword && IsEnabled()) ? maUserPwdSet : maUserPwdUnset );
1231 
1232 	sal_Bool bLocalEnable = mbHaveOwnerPassword && IsEnabled();
1233 	if( bIsPDFASel )
1234 	    maFtOwnerPwd.SetText( maOwnerPwdPdfa );
1235 	else
1236 	    maFtOwnerPwd.SetText( bLocalEnable ? maOwnerPwdSet : maOwnerPwdUnset );
1237 
1238 	maFlPrintPermissions.Enable( bLocalEnable );
1239 	maRbPrintNone.Enable( bLocalEnable );
1240 	maRbPrintLowRes.Enable( bLocalEnable );
1241 	maRbPrintHighRes.Enable( bLocalEnable );
1242 
1243 	maFlChangesAllowed.Enable( bLocalEnable );
1244 	maRbChangesNone.Enable( bLocalEnable );
1245 	maRbChangesInsDel.Enable( bLocalEnable );
1246 	maRbChangesFillForm.Enable( bLocalEnable );
1247 	maRbChangesComment.Enable( bLocalEnable );
1248 	maRbChangesAnyNoCopy.Enable( bLocalEnable );
1249 
1250 	maCbEnableCopy.Enable( bLocalEnable );
1251 	maCbEnableAccessibility.Enable( bLocalEnable );
1252 }
1253 
1254 ////////////////////////////////////////////////////////
1255 // This tab page is under control of the PDF/A-1a checkbox:
1256 // implement a method to do it.
1257 // -----------------------------------------------------------------------------
ImplPDFASecurityControl(sal_Bool bEnableSecurity)1258 void    ImpPDFTabSecurityPage::ImplPDFASecurityControl( sal_Bool bEnableSecurity )
1259 {
1260     if( bEnableSecurity )
1261     {
1262         Enable();
1263 //after enable, check the status of control as if the dialog was initialized
1264     }
1265     else
1266         Enable( sal_False );
1267 
1268     enablePermissionControls();
1269 }
1270 
1271 ////////////////////////////////////////////////////////
1272 // The link preferences tab page (relative and other stuff)
1273 // -----------------------------------------------------------------------------
ImpPDFTabLinksPage(Window * pParent,const SfxItemSet & rCoreSet)1274 ImpPDFTabLinksPage::ImpPDFTabLinksPage( Window* pParent,
1275 											  const SfxItemSet& rCoreSet ) :
1276 	SfxTabPage( pParent, PDFFilterResId( RID_PDF_TAB_LINKS ), rCoreSet ),
1277 
1278     maCbExprtBmkrToNmDst( this, PDFFilterResId( CB_EXP_BMRK_TO_DEST ) ),
1279     maCbOOoToPDFTargets( this,  PDFFilterResId( CB_CNV_OOO_DOCTOPDF ) ),
1280  	maCbExportRelativeFsysLinks( this, PDFFilterResId( CB_ENAB_RELLINKFSYS ) ),
1281 
1282     maFlDefaultTitle( this,  PDFFilterResId( FL_DEFAULT_LINK_ACTION ) ),
1283     maRbOpnLnksDefault( this, PDFFilterResId( CB_VIEW_PDF_DEFAULT ) ),
1284     mbOpnLnksDefaultUserState( sal_False ),
1285 	maRbOpnLnksLaunch( this, PDFFilterResId( CB_VIEW_PDF_APPLICATION ) ),
1286     mbOpnLnksLaunchUserState( sal_False ),
1287     maRbOpnLnksBrowser( this,  PDFFilterResId( CB_VIEW_PDF_BROWSER ) ),
1288     mbOpnLnksBrowserUserState( sal_False )
1289 {
1290 	FreeResource();
1291 
1292     // pb: #i91991# checkboxes only double-spaced if necessary
1293     long nDelta = 0;
1294     Size aSize = maCbExprtBmkrToNmDst.GetSizePixel();
1295     Size aMinSize = maCbExprtBmkrToNmDst.CalcMinimumSize();
1296     long nLineHeight =
1297         maCbExprtBmkrToNmDst.LogicToPixel( Size( 10, 10 ), MAP_APPFONT ).Height();
1298     if ( aSize.Width() > aMinSize.Width() )
1299     {
1300         Size aNewSize( aSize.Width(), nLineHeight );
1301         nDelta += ( aSize.Height() - nLineHeight );
1302         maCbExprtBmkrToNmDst.SetSizePixel( aNewSize );
1303         Point aNewPos = maCbOOoToPDFTargets.GetPosPixel();
1304         aNewPos.Y() -= nDelta;
1305         maCbOOoToPDFTargets.SetPosPixel( aNewPos );
1306     }
1307 
1308     aSize = maCbOOoToPDFTargets.GetSizePixel();
1309     aMinSize = maCbOOoToPDFTargets.CalcMinimumSize();
1310     if ( aSize.Width() > aMinSize.Width() )
1311     {
1312         Size aNewSize( aSize.Width(), nLineHeight );
1313         nDelta += ( aSize.Height() - nLineHeight );
1314         maCbOOoToPDFTargets.SetSizePixel( aNewSize );
1315         Point aNewPos = maCbExportRelativeFsysLinks.GetPosPixel();
1316         aNewPos.Y() -= nDelta;
1317         maCbExportRelativeFsysLinks.SetPosPixel( aNewPos );
1318     }
1319 
1320     aSize = maCbExportRelativeFsysLinks.GetSizePixel();
1321     aMinSize = maCbExportRelativeFsysLinks.CalcMinimumSize();
1322     if ( aSize.Width() > aMinSize.Width() )
1323     {
1324         Size aNewSize( aSize.Width(), nLineHeight );
1325         nDelta += ( aSize.Height() - nLineHeight );
1326         maCbExportRelativeFsysLinks.SetSizePixel( aNewSize );
1327     }
1328 
1329     if ( nDelta > 0 )
1330     {
1331         Window* pWins[] =
1332             { &maFlDefaultTitle, &maRbOpnLnksDefault, &maRbOpnLnksLaunch, &maRbOpnLnksBrowser, NULL };
1333         Window** pCurrent = pWins;
1334         while ( *pCurrent )
1335         {
1336             Point aNewPos = (*pCurrent)->GetPosPixel();
1337             aNewPos.Y() -= nDelta;
1338             (*pCurrent++)->SetPosPixel( aNewPos );
1339         }
1340     }
1341 }
1342 
1343 // -----------------------------------------------------------------------------
~ImpPDFTabLinksPage()1344 ImpPDFTabLinksPage::~ImpPDFTabLinksPage()
1345 {
1346 }
1347 
1348 // -----------------------------------------------------------------------------
Create(Window * pParent,const SfxItemSet & rAttrSet)1349 SfxTabPage*  ImpPDFTabLinksPage::Create( Window* pParent,
1350                                           const SfxItemSet& rAttrSet)
1351 {
1352 	return ( new  ImpPDFTabLinksPage( pParent, rAttrSet ) );
1353 }
1354 
1355 // -----------------------------------------------------------------------------
GetFilterConfigItem(ImpPDFTabDialog * paParent)1356 void ImpPDFTabLinksPage::GetFilterConfigItem( ImpPDFTabDialog* paParent  )
1357 {
1358 	paParent->mbExportRelativeFsysLinks = maCbExportRelativeFsysLinks.IsChecked();
1359 
1360     sal_Bool bIsPDFASel =  sal_False;
1361     if( paParent && paParent->GetTabPage( RID_PDF_TAB_GENER ) )
1362         bIsPDFASel = ( ( ImpPDFTabGeneralPage* )paParent->
1363                        GetTabPage( RID_PDF_TAB_GENER ) )->IsPdfaSelected();
1364 // if PDF/A-1 was not selected while exiting dialog...
1365     if( !bIsPDFASel )
1366     {
1367 // ...get the control states
1368         mbOpnLnksDefaultUserState = maRbOpnLnksDefault.IsChecked();
1369         mbOpnLnksLaunchUserState =  maRbOpnLnksLaunch.IsChecked();
1370         mbOpnLnksBrowserUserState = maRbOpnLnksBrowser.IsChecked();
1371     }
1372 // the control states, or the saved is used
1373 // to form the stored selection
1374     paParent->mnViewPDFMode = 0;
1375     if(	mbOpnLnksBrowserUserState )
1376         paParent->mnViewPDFMode = 2;
1377     else if( mbOpnLnksLaunchUserState )
1378         paParent->mnViewPDFMode = 1;
1379 
1380 	paParent->mbConvertOOoTargets = maCbOOoToPDFTargets.IsChecked();
1381 	paParent->mbExportBmkToPDFDestination = maCbExprtBmkrToNmDst.IsChecked();
1382 }
1383 
1384 // -----------------------------------------------------------------------------
SetFilterConfigItem(const ImpPDFTabDialog * paParent)1385 void ImpPDFTabLinksPage::SetFilterConfigItem( const  ImpPDFTabDialog* paParent )
1386 {
1387     maCbOOoToPDFTargets.Check( paParent->mbConvertOOoTargets );
1388 	maCbExprtBmkrToNmDst.Check( paParent->mbExportBmkToPDFDestination );
1389 
1390     maRbOpnLnksDefault.SetClickHdl( LINK( this, ImpPDFTabLinksPage, ClickRbOpnLnksDefaultHdl ) );
1391     maRbOpnLnksBrowser.SetClickHdl( LINK( this, ImpPDFTabLinksPage, ClickRbOpnLnksBrowserHdl ) );
1392 
1393 	maCbExportRelativeFsysLinks.Check( paParent->mbExportRelativeFsysLinks );
1394     switch( paParent->mnViewPDFMode )
1395     {
1396     default:
1397     case 0:
1398         maRbOpnLnksDefault.Check();
1399         mbOpnLnksDefaultUserState = sal_True;
1400         break;
1401     case 1:
1402         maRbOpnLnksLaunch.Check();
1403         mbOpnLnksLaunchUserState = sal_True;
1404         break;
1405     case 2:
1406         maRbOpnLnksBrowser.Check();
1407         mbOpnLnksBrowserUserState = sal_True;
1408         break;
1409     }
1410 // now check the status of PDF/A selection
1411 // and set the link action accordingly
1412 // PDF/A-1 doesn't allow launch action on links
1413 //
1414     if( paParent && paParent->GetTabPage( RID_PDF_TAB_GENER ) )
1415         ImplPDFALinkControl(
1416             !( ( ImpPDFTabGeneralPage* )paParent->
1417                GetTabPage( RID_PDF_TAB_GENER ) )->maCbPDFA1b.IsChecked() );
1418 }
1419 
1420 // -----------------------------------------------------------------------------
1421 // called from general tab, with PDFA/1 selection status
1422 // retrieves/store the status of Launch action selection
ImplPDFALinkControl(sal_Bool bEnableLaunch)1423 void ImpPDFTabLinksPage::ImplPDFALinkControl( sal_Bool bEnableLaunch )
1424 {
1425 // set the value and position of link type selection
1426     if( bEnableLaunch )
1427     {
1428         maRbOpnLnksLaunch.Enable();
1429 //restore user state with no PDF/A-1 selected
1430         maRbOpnLnksDefault.Check( mbOpnLnksDefaultUserState );
1431         maRbOpnLnksLaunch.Check( mbOpnLnksLaunchUserState );
1432         maRbOpnLnksBrowser.Check( mbOpnLnksBrowserUserState );
1433     }
1434     else
1435     {
1436 //save user state with no PDF/A-1 selected
1437         mbOpnLnksDefaultUserState = maRbOpnLnksDefault.IsChecked();
1438         mbOpnLnksLaunchUserState = maRbOpnLnksLaunch.IsChecked();
1439         mbOpnLnksBrowserUserState = maRbOpnLnksBrowser.IsChecked();
1440         maRbOpnLnksLaunch.Enable( sal_False );
1441         if( mbOpnLnksLaunchUserState )
1442             maRbOpnLnksBrowser.Check();
1443     }
1444 }
1445 
1446 // -----------------------------------------------------------------------------
1447 // reset the memory of Launch action present
1448 // when PDF/A-1 was requested
IMPL_LINK(ImpPDFTabLinksPage,ClickRbOpnLnksDefaultHdl,void *,EMPTYARG)1449 IMPL_LINK( ImpPDFTabLinksPage, ClickRbOpnLnksDefaultHdl, void*, EMPTYARG )
1450 {
1451     mbOpnLnksDefaultUserState = maRbOpnLnksDefault.IsChecked();
1452     mbOpnLnksLaunchUserState = maRbOpnLnksLaunch.IsChecked();
1453     mbOpnLnksBrowserUserState = maRbOpnLnksBrowser.IsChecked();
1454     return 0;
1455 }
1456 
1457 // -----------------------------------------------------------------------------
1458 // reset the memory of a launch action present
1459 // when PDF/A-1 was requested
IMPL_LINK(ImpPDFTabLinksPage,ClickRbOpnLnksBrowserHdl,void *,EMPTYARG)1460 IMPL_LINK( ImpPDFTabLinksPage, ClickRbOpnLnksBrowserHdl, void*, EMPTYARG )
1461 {
1462     mbOpnLnksDefaultUserState = maRbOpnLnksDefault.IsChecked();
1463     mbOpnLnksLaunchUserState = maRbOpnLnksLaunch.IsChecked();
1464     mbOpnLnksBrowserUserState = maRbOpnLnksBrowser.IsChecked();
1465     return 0;
1466 }
1467 
ImplErrorDialog(const std::set<vcl::PDFWriter::ErrorCode> & rErrors)1468 ImplErrorDialog::ImplErrorDialog( const std::set< vcl::PDFWriter::ErrorCode >& rErrors ) :
1469     ModalDialog( NULL, PDFFilterResId( RID_PDF_ERROR_DLG ) ),
1470     maFI( this, 0 ),
1471     maProcessText( this, PDFFilterResId( FT_PROCESS ) ),
1472     maErrors( this, WB_BORDER | WB_AUTOVSCROLL ),
1473     maExplanation( this, WB_WORDBREAK ),
1474     maButton( this, WB_DEFBUTTON )
1475 
1476 {
1477     // load images
1478     Image aWarnImg( BitmapEx( PDFFilterResId( IMG_WARN ) ) );
1479     Image aErrImg( BitmapEx( PDFFilterResId( IMG_ERR ) ) );
1480 
1481     for( std::set<vcl::PDFWriter::ErrorCode>::const_iterator it = rErrors.begin();
1482          it != rErrors.end(); ++it )
1483     {
1484         switch( *it )
1485         {
1486         case vcl::PDFWriter::Warning_Transparency_Omitted_PDFA:
1487         {
1488             sal_uInt16 nPos = maErrors.InsertEntry( String( PDFFilterResId( STR_WARN_TRANSP_PDFA_SHORT ) ),
1489                                                 aWarnImg );
1490             maErrors.SetEntryData( nPos, new String( PDFFilterResId( STR_WARN_TRANSP_PDFA ) ) );
1491         }
1492         break;
1493         case vcl::PDFWriter::Warning_Transparency_Omitted_PDF13:
1494         {
1495             sal_uInt16 nPos = maErrors.InsertEntry( String( PDFFilterResId( STR_WARN_TRANSP_VERSION_SHORT ) ),
1496                                                 aWarnImg );
1497             maErrors.SetEntryData( nPos, new String( PDFFilterResId( STR_WARN_TRANSP_VERSION ) ) );
1498         }
1499         break;
1500         case vcl::PDFWriter::Warning_FormAction_Omitted_PDFA:
1501         {
1502             sal_uInt16 nPos = maErrors.InsertEntry( String( PDFFilterResId( STR_WARN_FORMACTION_PDFA_SHORT ) ),
1503                                                 aWarnImg );
1504             maErrors.SetEntryData( nPos, new String( PDFFilterResId( STR_WARN_FORMACTION_PDFA ) ) );
1505         }
1506         break;
1507         case vcl::PDFWriter::Warning_Transparency_Converted:
1508         {
1509             sal_uInt16 nPos = maErrors.InsertEntry( String( PDFFilterResId( STR_WARN_TRANSP_CONVERTED_SHORT ) ),
1510                                                 aWarnImg );
1511             maErrors.SetEntryData( nPos, new String( PDFFilterResId( STR_WARN_TRANSP_CONVERTED ) ) );
1512         }
1513         break;
1514         default:
1515             break;
1516         }
1517     }
1518 
1519     FreeResource();
1520 
1521     if( maErrors.GetEntryCount() > 0 )
1522     {
1523         maErrors.SelectEntryPos( 0 );
1524         String* pStr = reinterpret_cast<String*>(maErrors.GetEntryData( 0 ));
1525         maExplanation.SetText( pStr ? *pStr : String() );
1526     }
1527 
1528     // adjust layout
1529     Image aWarnImage( WarningBox::GetStandardImage() );
1530     Size aImageSize( aWarnImage.GetSizePixel() );
1531     Size aDlgSize( GetSizePixel() );
1532     aImageSize.Width() += 6;
1533     aImageSize.Height() += 6;
1534     maFI.SetImage( aWarnImage );
1535     maFI.SetPosSizePixel( Point( 5, 5 ), aImageSize );
1536     maFI.Show();
1537 
1538     maProcessText.SetStyle( maProcessText.GetStyle() | WB_VCENTER );
1539     maProcessText.SetPosSizePixel( Point( aImageSize.Width() + 10, 5 ),
1540                                    Size(  aDlgSize.Width() - aImageSize.Width() - 15, aImageSize.Height() ) );
1541 
1542     Point aErrorLBPos( 5, aImageSize.Height() + 10 );
1543     Size aErrorLBSize( aDlgSize.Width()/2 - 10, aDlgSize.Height() - aErrorLBPos.Y() - 35 );
1544     maErrors.SetPosSizePixel( aErrorLBPos, aErrorLBSize );
1545     maErrors.SetSelectHdl( LINK( this, ImplErrorDialog, SelectHdl ) );
1546     maErrors.Show();
1547 
1548     maExplanation.SetPosSizePixel( Point( aErrorLBPos.X() + aErrorLBSize.Width() + 5, aErrorLBPos.Y() ),
1549                                    Size( aDlgSize.Width() - aErrorLBPos.X() - aErrorLBSize.Width() - 10, aErrorLBSize.Height() ) );
1550     maExplanation.Show();
1551 
1552     maButton.SetPosSizePixel( Point( (aDlgSize.Width() - 50)/2, aDlgSize.Height() - 30 ),
1553                               Size( 50, 25 ) );
1554     maButton.Show();
1555 }
1556 
~ImplErrorDialog()1557 ImplErrorDialog::~ImplErrorDialog()
1558 {
1559     // free strings again
1560     for( sal_uInt16 n = 0; n < maErrors.GetEntryCount(); n++ )
1561         delete (String*)maErrors.GetEntryData( n );
1562 }
1563 
IMPL_LINK(ImplErrorDialog,SelectHdl,ListBox *,EMPTYARG)1564 IMPL_LINK( ImplErrorDialog, SelectHdl, ListBox*, EMPTYARG )
1565 {
1566     String* pStr = reinterpret_cast<String*>(maErrors.GetEntryData( maErrors.GetSelectEntryPos() ));
1567     maExplanation.SetText( pStr ? *pStr : String() );
1568     return 0;
1569 }
1570