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 #ifndef OOX_XLS_PAGESETTINGS_HXX 25 #define OOX_XLS_PAGESETTINGS_HXX 26 27 #include "oox/xls/worksheethelper.hxx" 28 29 namespace oox { class PropertySet; } 30 namespace oox { namespace core { class Relations; } } 31 32 namespace oox { 33 namespace xls { 34 35 class HeaderFooterParser; 36 37 // ============================================================================ 38 39 /** Holds page style data for a single sheet. */ 40 struct PageSettingsModel 41 { 42 ::rtl::OUString maGraphicUrl; /// URL of the graphic object. 43 ::rtl::OUString maBinSettPath; /// Relation identifier of binary printer settings. 44 ::rtl::OUString maOddHeader; /// Header string for odd pages. 45 ::rtl::OUString maOddFooter; /// Footer string for odd pages. 46 ::rtl::OUString maEvenHeader; /// Header string for even pages. 47 ::rtl::OUString maEvenFooter; /// Footer string for even pages. 48 ::rtl::OUString maFirstHeader; /// Header string for first page of the sheet. 49 ::rtl::OUString maFirstFooter; /// Footer string for first page of the sheet. 50 double mfLeftMargin; /// Margin between left edge of page and begin of sheet area. 51 double mfRightMargin; /// Margin between end of sheet area and right edge of page. 52 double mfTopMargin; /// Margin between top egde of page and begin of sheet area. 53 double mfBottomMargin; /// Margin between end of sheet area and bottom edge of page. 54 double mfHeaderMargin; /// Margin between top edge of page and begin of header. 55 double mfFooterMargin; /// Margin between end of footer and bottom edge of page. 56 sal_Int32 mnPaperSize; /// Paper size (enumeration). 57 sal_Int32 mnCopies; /// Number of copies to print. 58 sal_Int32 mnScale; /// Page scale (zoom in percent). 59 sal_Int32 mnFirstPage; /// First page number. 60 sal_Int32 mnFitToWidth; /// Fit to number of pages in horizontal direction. 61 sal_Int32 mnFitToHeight; /// Fit to number of pages in vertical direction. 62 sal_Int32 mnHorPrintRes; /// Horizontal printing resolution in DPI. 63 sal_Int32 mnVerPrintRes; /// Vertical printing resolution in DPI. 64 sal_Int32 mnOrientation; /// Landscape or portrait. 65 sal_Int32 mnPageOrder; /// Page order through sheet area (to left or down). 66 sal_Int32 mnCellComments; /// Cell comments printing mode. 67 sal_Int32 mnPrintErrors; /// Cell error printing mode. 68 bool mbUseEvenHF; /// True = use maEvenHeader/maEvenFooter. 69 bool mbUseFirstHF; /// True = use maFirstHeader/maFirstFooter. 70 bool mbValidSettings; /// True = use imported settings. 71 bool mbUseFirstPage; /// True = start page numbering with mnFirstPage. 72 bool mbBlackWhite; /// True = print black and white. 73 bool mbDraftQuality; /// True = print in draft quality. 74 bool mbFitToPages; /// True = Fit to width/height; false = scale in percent. 75 bool mbHorCenter; /// True = horizontally centered. 76 bool mbVerCenter; /// True = vertically centered. 77 bool mbPrintGrid; /// True = print grid lines. 78 bool mbPrintHeadings; /// True = print column/row headings. 79 80 explicit PageSettingsModel(); 81 82 /** Sets the BIFF print errors mode. */ 83 void setBiffPrintErrors( sal_uInt8 nPrintErrors ); 84 }; 85 86 // ============================================================================ 87 88 class PageSettings : public WorksheetHelper 89 { 90 public: 91 explicit PageSettings( const WorksheetHelper& rHelper ); 92 93 /** Imports printing options from a printOptions element. */ 94 void importPrintOptions( const AttributeList& rAttribs ); 95 /** Imports pageMarings element containing page margins. */ 96 void importPageMargins( const AttributeList& rAttribs ); 97 /** Imports pageSetup element for worksheets. */ 98 void importPageSetup( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); 99 /** Imports pageSetup element for chart sheets. */ 100 void importChartPageSetup( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); 101 /** Imports header and footer settings from a headerFooter element. */ 102 void importHeaderFooter( const AttributeList& rAttribs ); 103 /** Imports header/footer characters from a headerFooter element. */ 104 void importHeaderFooterCharacters( const ::rtl::OUString& rChars, sal_Int32 nElement ); 105 /** Imports the picture element. */ 106 void importPicture( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs ); 107 108 /** Imports the PRINTOPTIONS record from the passed stream. */ 109 void importPrintOptions( SequenceInputStream& rStrm ); 110 /** Imports the PAGEMARGINS record from the passed stream. */ 111 void importPageMargins( SequenceInputStream& rStrm ); 112 /** Imports the PAGESETUP record from the passed stream. */ 113 void importPageSetup( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm ); 114 /** Imports the CHARTPAGESETUP record from the passed stream. */ 115 void importChartPageSetup( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm ); 116 /** Imports the HEADERFOOTER record from the passed stream. */ 117 void importHeaderFooter( SequenceInputStream& rStrm ); 118 /** Imports the PICTURE record from the passed stream. */ 119 void importPicture( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm ); 120 121 /** Imports the LEFTMARGIN record from the passed BIFF stream. */ 122 void importLeftMargin( BiffInputStream& rStrm ); 123 /** Imports the RIGHTMARGIN record from the passed BIFF stream. */ 124 void importRightMargin( BiffInputStream& rStrm ); 125 /** Imports the TOPMARGIN record from the passed BIFF stream. */ 126 void importTopMargin( BiffInputStream& rStrm ); 127 /** Imports the BOTTOMMARGIN record from the passed BIFF stream. */ 128 void importBottomMargin( BiffInputStream& rStrm ); 129 /** Imports the SETUP record from the passed BIFF stream. */ 130 void importPageSetup( BiffInputStream& rStrm ); 131 /** Imports the HCENTER record from the passed BIFF stream. */ 132 void importHorCenter( BiffInputStream& rStrm ); 133 /** Imports the VCENTER record from the passed BIFF stream. */ 134 void importVerCenter( BiffInputStream& rStrm ); 135 /** Imports the PRINTHEADERS record from the passed BIFF stream. */ 136 void importPrintHeaders( BiffInputStream& rStrm ); 137 /** Imports the PRINTGRIDLINES record from the passed BIFF stream. */ 138 void importPrintGridLines( BiffInputStream& rStrm ); 139 /** Imports the HEADER record from the passed BIFF stream. */ 140 void importHeader( BiffInputStream& rStrm ); 141 /** Imports the FOOTER record from the passed BIFF stream. */ 142 void importFooter( BiffInputStream& rStrm ); 143 /** Imports the PICTURE record from the passed BIFF stream. */ 144 void importPicture( BiffInputStream& rStrm ); 145 146 /** Sets whether percentual scaling or fit to width/height scaling is used. */ 147 void setFitToPagesMode( bool bFitToPages ); 148 149 /** Creates a page style for the spreadsheet and sets all page properties. */ 150 void finalizeImport(); 151 152 private: 153 /** Imports the binary picture data from the fragment with the passed identifier. */ 154 void importPictureData( const ::oox::core::Relations& rRelations, const ::rtl::OUString& rRelId ); 155 156 private: 157 PageSettingsModel maModel; 158 }; 159 160 // ============================================================================ 161 162 class PageSettingsConverter : public WorkbookHelper 163 { 164 public: 165 explicit PageSettingsConverter( const WorkbookHelper& rHelper ); 166 virtual ~PageSettingsConverter(); 167 168 /** Writes all properties to the passed property set of a page style object. */ 169 void writePageSettingsProperties( 170 PropertySet& rPropSet, 171 const PageSettingsModel& rModel, 172 WorksheetType eSheetType ); 173 174 private: 175 struct HFHelperData 176 { 177 sal_Int32 mnLeftPropId; 178 sal_Int32 mnRightPropId; 179 sal_Int32 mnHeight; 180 sal_Int32 mnBodyDist; 181 bool mbHasContent; 182 bool mbShareOddEven; 183 bool mbDynamicHeight; 184 185 explicit HFHelperData( sal_Int32 nLeftPropId, sal_Int32 nRightPropId ); 186 }; 187 188 private: 189 void convertHeaderFooterData( 190 PropertySet& rPropSet, 191 HFHelperData& orHFData, 192 const ::rtl::OUString rOddContent, 193 const ::rtl::OUString rEvenContent, 194 bool bUseEvenContent, 195 double fPageMargin, 196 double fContentMargin ); 197 198 sal_Int32 writeHeaderFooter( 199 PropertySet& rPropSet, 200 sal_Int32 nPropId, 201 const ::rtl::OUString& rContent ); 202 203 private: 204 typedef ::std::auto_ptr< HeaderFooterParser > HeaderFooterParserPtr; 205 HeaderFooterParserPtr mxHFParser; 206 HFHelperData maHeaderData; 207 HFHelperData maFooterData; 208 }; 209 210 // ============================================================================ 211 212 } // namespace xls 213 } // namespace oox 214 215 #endif 216