1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "document.hxx"
22 #include "scextopt.hxx"
23 #include "viewopti.hxx"
24 #include "xistream.hxx"
25 #include "xihelper.hxx"
26 #include "xistyle.hxx"
28 // Document view settings =====================================================
30 XclImpDocViewSettings::XclImpDocViewSettings( const XclImpRoot
& rRoot
) :
35 void XclImpDocViewSettings::ReadWindow1( XclImpStream
& rStrm
)
37 maData
.mnWinX
= rStrm
.ReaduInt16();
38 maData
.mnWinY
= rStrm
.ReaduInt16();
39 maData
.mnWinWidth
= rStrm
.ReaduInt16();
40 maData
.mnWinHeight
= rStrm
.ReaduInt16();
41 maData
.mnFlags
= rStrm
.ReaduInt16();
42 if( GetBiff() >= EXC_BIFF5
)
44 maData
.mnDisplXclTab
= rStrm
.ReaduInt16();
45 maData
.mnFirstVisXclTab
= rStrm
.ReaduInt16();
46 maData
.mnXclSelectCnt
= rStrm
.ReaduInt16();
47 maData
.mnTabBarWidth
= rStrm
.ReaduInt16();
51 SCTAB
XclImpDocViewSettings::GetDisplScTab() const
53 /* Simply cast Excel index to Calc index.
54 TODO: This may fail if the document contains scenarios. */
55 sal_uInt16 nMaxXclTab
= static_cast< sal_uInt16
>( GetMaxPos().Tab() );
56 return static_cast< SCTAB
>( (maData
.mnDisplXclTab
<= nMaxXclTab
) ? maData
.mnDisplXclTab
: 0 );
59 void XclImpDocViewSettings::Finalize()
61 ScViewOptions
aViewOpt( GetDoc().GetViewOptions() );
62 aViewOpt
.SetOption( VOPT_HSCROLL
, ::get_flag( maData
.mnFlags
, EXC_WIN1_HOR_SCROLLBAR
) );
63 aViewOpt
.SetOption( VOPT_VSCROLL
, ::get_flag( maData
.mnFlags
, EXC_WIN1_VER_SCROLLBAR
) );
64 aViewOpt
.SetOption( VOPT_TABCONTROLS
, ::get_flag( maData
.mnFlags
, EXC_WIN1_TABBAR
) );
65 GetDoc().SetViewOptions( aViewOpt
);
68 GetExtDocOptions().GetDocSettings().mnDisplTab
= GetDisplScTab();
70 // width of the tabbar with sheet names
71 if( maData
.mnTabBarWidth
<= 1000 )
72 GetExtDocOptions().GetDocSettings().mfTabBarWidth
= static_cast< double >( maData
.mnTabBarWidth
) / 1000.0;
75 // Sheet view settings ========================================================
79 long lclGetScZoom( sal_uInt16 nXclZoom
, sal_uInt16 nDefZoom
)
81 return static_cast< long >( nXclZoom
? nXclZoom
: nDefZoom
);
86 XclImpTabViewSettings::XclImpTabViewSettings( const XclImpRoot
& rRoot
) :
92 void XclImpTabViewSettings::Initialize()
97 void XclImpTabViewSettings::ReadTabBgColor( XclImpStream
& rStrm
, XclImpPalette
& rPal
)
99 OSL_ENSURE_BIFF( GetBiff() >= EXC_BIFF8
);
100 if( GetBiff() < EXC_BIFF8
)
103 sal_uInt8 ColorIndex
;
107 ColorIndex
= rStrm
.ReaduInt8() & EXC_SHEETEXT_TABCOLOR
; //0x7F
108 if ( ColorIndex
>= 8 && ColorIndex
<= 63 ) //only accept valid index values
110 TabBgColor
= rPal
.GetColor( ColorIndex
);
111 maData
.maTabBgColor
= TabBgColor
;
115 void XclImpTabViewSettings::ReadWindow2( XclImpStream
& rStrm
, bool bChart
)
117 if( GetBiff() == EXC_BIFF2
)
119 maData
.mbShowFormulas
= rStrm
.ReaduInt8() != 0;
120 maData
.mbShowGrid
= rStrm
.ReaduInt8() != 0;
121 maData
.mbShowHeadings
= rStrm
.ReaduInt8() != 0;
122 maData
.mbFrozenPanes
= rStrm
.ReaduInt8() != 0;
123 maData
.mbShowZeros
= rStrm
.ReaduInt8() != 0;
124 rStrm
>> maData
.maFirstXclPos
;
125 maData
.mbDefGridColor
= rStrm
.ReaduInt8() != 0;
126 rStrm
>> maData
.maGridColor
;
131 nFlags
= rStrm
.ReaduInt16();
132 rStrm
>> maData
.maFirstXclPos
;
134 // #i59590# real life: Excel ignores some view settings in chart sheets
135 maData
.mbSelected
= ::get_flag( nFlags
, EXC_WIN2_SELECTED
);
136 maData
.mbDisplayed
= ::get_flag( nFlags
, EXC_WIN2_DISPLAYED
);
137 maData
.mbMirrored
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_MIRRORED
);
138 maData
.mbFrozenPanes
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_FROZEN
);
139 maData
.mbPageMode
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_PAGEBREAKMODE
);
140 maData
.mbDefGridColor
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_DEFGRIDCOLOR
);
141 maData
.mbShowFormulas
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_SHOWFORMULAS
);
142 maData
.mbShowGrid
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWGRID
);
143 maData
.mbShowHeadings
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWHEADINGS
);
144 maData
.mbShowZeros
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWZEROS
);
145 maData
.mbShowOutline
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWOUTLINE
);
152 rStrm
>> maData
.maGridColor
;
156 sal_uInt16 nGridColorIdx
;
157 nGridColorIdx
= rStrm
.ReaduInt16();
158 // zoom data not included in chart sheets
159 if( rStrm
.GetRecLeft() >= 6 )
162 maData
.mnPageZoom
= rStrm
.ReaduInt16();
163 maData
.mnNormalZoom
= rStrm
.ReaduInt16();
166 if( !maData
.mbDefGridColor
)
167 maData
.maGridColor
= GetPalette().GetColor( nGridColorIdx
);
170 default: DBG_ERROR_BIFF();
174 // do not scroll chart sheets
176 maData
.maFirstXclPos
.Set( 0, 0 );
179 void XclImpTabViewSettings::ReadScl( XclImpStream
& rStrm
)
181 sal_uInt16 nNum
, nDenom
;
182 nNum
= rStrm
.ReaduInt16();
183 nDenom
= rStrm
.ReaduInt16();
184 OSL_ENSURE( nDenom
> 0, "XclImpPageSettings::ReadScl - invalid denominator" );
186 maData
.mnCurrentZoom
= limit_cast
< sal_uInt16
>( (nNum
* 100) / nDenom
);
189 void XclImpTabViewSettings::ReadPane( XclImpStream
& rStrm
)
191 maData
.mnSplitX
= rStrm
.ReaduInt16();
192 maData
.mnSplitY
= rStrm
.ReaduInt16();
194 rStrm
>> maData
.maSecondXclPos
;
195 maData
.mnActivePane
= rStrm
.ReaduInt8();
198 void XclImpTabViewSettings::ReadSelection( XclImpStream
& rStrm
)
200 // pane of this selection
202 nPane
= rStrm
.ReaduInt8();
203 XclSelectionData
& rSelData
= maData
.CreateSelectionData( nPane
);
204 // cursor position and selection
205 rStrm
>> rSelData
.maXclCursor
;
206 rSelData
.mnCursorIdx
= rStrm
.ReaduInt16();
207 rSelData
.maXclSelection
.Read( rStrm
, false );
210 void XclImpTabViewSettings::Finalize()
212 SCTAB nScTab
= GetCurrScTab();
213 ScDocument
& rDoc
= GetDoc();
214 XclImpAddressConverter
& rAddrConv
= GetAddressConverter();
215 ScExtTabSettings
& rTabSett
= GetExtDocOptions().GetOrCreateTabSettings( nScTab
);
216 bool bDisplayed
= GetDocViewSettings().GetDisplScTab() == nScTab
;
218 // *** sheet options: cursor, selection, splits, zoom ***
221 if( maData
.mbMirrored
)
222 // do not call this function with sal_False, it would mirror away all drawing objects
223 rDoc
.SetLayoutRTL( nScTab
, true );
224 rTabSett
.mbSelected
= maData
.mbSelected
|| bDisplayed
;
226 // first visible cell in top-left pane and in additional pane(s)
227 rTabSett
.maFirstVis
= rAddrConv
.CreateValidAddress( maData
.maFirstXclPos
, nScTab
, false );
228 rTabSett
.maSecondVis
= rAddrConv
.CreateValidAddress( maData
.maSecondXclPos
, nScTab
, false );
230 // cursor position and selection
231 if( const XclSelectionData
* pSelData
= maData
.GetSelectionData( maData
.mnActivePane
) )
233 rTabSett
.maCursor
= rAddrConv
.CreateValidAddress( pSelData
->maXclCursor
, nScTab
, false );
234 rAddrConv
.ConvertRangeList( rTabSett
.maSelection
, pSelData
->maXclSelection
, nScTab
, false );
238 switch( maData
.mnActivePane
)
240 case EXC_PANE_TOPLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPLEFT
; break;
241 case EXC_PANE_TOPRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPRIGHT
; break;
242 case EXC_PANE_BOTTOMLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMLEFT
; break;
243 case EXC_PANE_BOTTOMRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMRIGHT
; break;
246 // freeze/split position
247 rTabSett
.mbFrozenPanes
= maData
.mbFrozenPanes
;
248 if( maData
.mbFrozenPanes
)
250 /* Frozen panes: handle split position as row/column positions.
251 #i35812# Excel uses number of visible rows/columns, Calc uses position of freeze. */
252 if( (maData
.mnSplitX
> 0) && (maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
<= GetScMaxPos().Col()) )
253 rTabSett
.maFreezePos
.SetCol( static_cast< SCCOL
>( maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
) );
254 if( (maData
.mnSplitY
> 0) && (maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
<= static_cast<unsigned>(GetScMaxPos().Row())) )
255 rTabSett
.maFreezePos
.SetRow( static_cast< SCROW
>( maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
) );
259 // split window: position is in twips
260 rTabSett
.maSplitPos
.X() = static_cast< long >( maData
.mnSplitX
);
261 rTabSett
.maSplitPos
.Y() = static_cast< long >( maData
.mnSplitY
);
265 if( maData
.mbDefGridColor
)
266 rTabSett
.maGridColor
.SetColor( COL_AUTO
);
268 rTabSett
.maGridColor
= maData
.maGridColor
;
271 rTabSett
.mbShowGrid
= maData
.mbShowGrid
;
273 // view mode and zoom
274 if( maData
.mnCurrentZoom
!= 0 )
275 (maData
.mbPageMode
? maData
.mnPageZoom
: maData
.mnNormalZoom
) = maData
.mnCurrentZoom
;
276 rTabSett
.mbPageMode
= maData
.mbPageMode
;
277 rTabSett
.mnNormalZoom
= lclGetScZoom( maData
.mnNormalZoom
, EXC_WIN2_NORMALZOOM_DEF
);
278 rTabSett
.mnPageZoom
= lclGetScZoom( maData
.mnPageZoom
, EXC_WIN2_PAGEZOOM_DEF
);
280 // *** additional handling for displayed sheet ***
284 // set Excel sheet settings globally at Calc document, take settings from displayed sheet
285 ScViewOptions
aViewOpt( rDoc
.GetViewOptions() );
286 aViewOpt
.SetOption( VOPT_FORMULAS
, maData
.mbShowFormulas
);
287 aViewOpt
.SetOption( VOPT_HEADER
, maData
.mbShowHeadings
);
288 aViewOpt
.SetOption( VOPT_NULLVALS
, maData
.mbShowZeros
);
289 aViewOpt
.SetOption( VOPT_OUTLINER
, maData
.mbShowOutline
);
290 rDoc
.SetViewOptions( aViewOpt
);
293 // *** set tab bg color
294 if ( !maData
.IsDefaultTabBgColor() )
295 rDoc
.SetTabBgColor(nScTab
, maData
.maTabBgColor
);
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */