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 .
20 #include <sal/config.h>
22 #include <o3tl/safeint.hxx>
25 #include <document.hxx>
26 #include <scextopt.hxx>
27 #include <viewopti.hxx>
28 #include <xistream.hxx>
29 #include <xihelper.hxx>
30 #include <xistyle.hxx>
32 // Document view settings =====================================================
34 XclImpDocViewSettings::XclImpDocViewSettings( const XclImpRoot
& rRoot
) :
39 void XclImpDocViewSettings::ReadWindow1( XclImpStream
& rStrm
)
41 maData
.mnWinX
= rStrm
.ReaduInt16();
42 maData
.mnWinY
= rStrm
.ReaduInt16();
43 maData
.mnWinWidth
= rStrm
.ReaduInt16();
44 maData
.mnWinHeight
= rStrm
.ReaduInt16();
45 maData
.mnFlags
= rStrm
.ReaduInt16();
46 if( GetBiff() >= EXC_BIFF5
)
48 maData
.mnDisplXclTab
= rStrm
.ReaduInt16();
49 maData
.mnFirstVisXclTab
= rStrm
.ReaduInt16();
50 maData
.mnXclSelectCnt
= rStrm
.ReaduInt16();
51 maData
.mnTabBarWidth
= rStrm
.ReaduInt16();
55 SCTAB
XclImpDocViewSettings::GetDisplScTab() const
57 /* Simply cast Excel index to Calc index.
58 TODO: This may fail if the document contains scenarios. */
59 sal_uInt16 nMaxXclTab
= static_cast< sal_uInt16
>( GetMaxPos().Tab() );
60 return static_cast< SCTAB
>( (maData
.mnDisplXclTab
<= nMaxXclTab
) ? maData
.mnDisplXclTab
: 0 );
63 void XclImpDocViewSettings::Finalize()
65 ScViewOptions
aViewOpt( GetDoc().GetViewOptions() );
66 aViewOpt
.SetOption( VOPT_HSCROLL
, ::get_flag( maData
.mnFlags
, EXC_WIN1_HOR_SCROLLBAR
) );
67 aViewOpt
.SetOption( VOPT_VSCROLL
, ::get_flag( maData
.mnFlags
, EXC_WIN1_VER_SCROLLBAR
) );
68 aViewOpt
.SetOption( VOPT_TABCONTROLS
, ::get_flag( maData
.mnFlags
, EXC_WIN1_TABBAR
) );
69 GetDoc().SetViewOptions( aViewOpt
);
72 GetExtDocOptions().GetDocSettings().mnDisplTab
= GetDisplScTab();
74 // width of the tabbar with sheet names
75 if( maData
.mnTabBarWidth
<= 1000 )
76 GetExtDocOptions().GetDocSettings().mfTabBarWidth
= static_cast< double >( maData
.mnTabBarWidth
) / 1000.0;
79 // Sheet view settings ========================================================
83 tools::Long
lclGetScZoom( sal_uInt16 nXclZoom
, sal_uInt16 nDefZoom
)
85 return static_cast< tools::Long
>( nXclZoom
? nXclZoom
: nDefZoom
);
90 XclImpTabViewSettings::XclImpTabViewSettings( const XclImpRoot
& rRoot
) :
96 void XclImpTabViewSettings::Initialize()
101 void XclImpTabViewSettings::ReadTabBgColor( XclImpStream
& rStrm
, const XclImpPalette
& rPal
)
103 OSL_ENSURE_BIFF( GetBiff() >= EXC_BIFF8
);
104 if( GetBiff() < EXC_BIFF8
)
107 sal_uInt8 ColorIndex
;
110 ColorIndex
= rStrm
.ReaduInt8() & EXC_SHEETEXT_TABCOLOR
; //0x7F
111 if ( ColorIndex
>= 8 && ColorIndex
<= 63 ) //only accept valid index values
113 maData
.maTabBgColor
= rPal
.GetColor( ColorIndex
);
117 void XclImpTabViewSettings::ReadWindow2( XclImpStream
& rStrm
, bool bChart
)
119 if( GetBiff() == EXC_BIFF2
)
121 maData
.mbShowFormulas
= rStrm
.ReaduInt8() != 0;
122 maData
.mbShowGrid
= rStrm
.ReaduInt8() != 0;
123 maData
.mbShowHeadings
= rStrm
.ReaduInt8() != 0;
124 maData
.mbFrozenPanes
= rStrm
.ReaduInt8() != 0;
125 maData
.mbShowZeros
= rStrm
.ReaduInt8() != 0;
126 rStrm
>> maData
.maFirstXclPos
;
127 maData
.mbDefGridColor
= rStrm
.ReaduInt8() != 0;
128 rStrm
>> maData
.maGridColor
;
133 nFlags
= rStrm
.ReaduInt16();
134 rStrm
>> maData
.maFirstXclPos
;
136 // #i59590# real life: Excel ignores some view settings in chart sheets
137 maData
.mbSelected
= ::get_flag( nFlags
, EXC_WIN2_SELECTED
);
138 maData
.mbDisplayed
= ::get_flag( nFlags
, EXC_WIN2_DISPLAYED
);
139 maData
.mbMirrored
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_MIRRORED
);
140 maData
.mbFrozenPanes
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_FROZEN
);
141 maData
.mbPageMode
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_PAGEBREAKMODE
);
142 maData
.mbDefGridColor
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_DEFGRIDCOLOR
);
143 maData
.mbShowFormulas
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_SHOWFORMULAS
);
144 maData
.mbShowGrid
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWGRID
);
145 maData
.mbShowHeadings
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWHEADINGS
);
146 maData
.mbShowZeros
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWZEROS
);
147 maData
.mbShowOutline
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWOUTLINE
);
154 rStrm
>> maData
.maGridColor
;
158 sal_uInt16 nGridColorIdx
;
159 nGridColorIdx
= rStrm
.ReaduInt16();
160 // zoom data not included in chart sheets
161 if( rStrm
.GetRecLeft() >= 6 )
164 maData
.mnPageZoom
= rStrm
.ReaduInt16();
165 maData
.mnNormalZoom
= rStrm
.ReaduInt16();
168 if( !maData
.mbDefGridColor
)
169 maData
.maGridColor
= GetPalette().GetColor( nGridColorIdx
);
172 default: DBG_ERROR_BIFF();
176 // do not scroll chart sheets
178 maData
.maFirstXclPos
.Set( 0, 0 );
181 void XclImpTabViewSettings::ReadScl( XclImpStream
& rStrm
)
183 sal_uInt16 nNum
, nDenom
;
184 nNum
= rStrm
.ReaduInt16();
185 nDenom
= rStrm
.ReaduInt16();
186 OSL_ENSURE( nDenom
> 0, "XclImpPageSettings::ReadScl - invalid denominator" );
188 maData
.mnCurrentZoom
= limit_cast
< sal_uInt16
>( (nNum
* 100) / nDenom
);
191 void XclImpTabViewSettings::ReadPane( XclImpStream
& rStrm
)
193 maData
.mnSplitX
= rStrm
.ReaduInt16();
194 maData
.mnSplitY
= rStrm
.ReaduInt16();
196 rStrm
>> maData
.maSecondXclPos
;
197 maData
.mnActivePane
= rStrm
.ReaduInt8();
200 void XclImpTabViewSettings::ReadSelection( XclImpStream
& rStrm
)
202 // pane of this selection
204 nPane
= rStrm
.ReaduInt8();
205 XclSelectionData
& rSelData
= maData
.CreateSelectionData( nPane
);
206 // cursor position and selection
207 rStrm
>> rSelData
.maXclCursor
;
208 rSelData
.mnCursorIdx
= rStrm
.ReaduInt16();
209 rSelData
.maXclSelection
.Read( rStrm
, false );
212 void XclImpTabViewSettings::Finalize()
214 SCTAB nScTab
= GetCurrScTab();
215 ScDocument
& rDoc
= GetDoc();
216 XclImpAddressConverter
& rAddrConv
= GetAddressConverter();
217 ScExtTabSettings
& rTabSett
= GetExtDocOptions().GetOrCreateTabSettings( nScTab
);
218 bool bDisplayed
= GetDocViewSettings().GetDisplScTab() == nScTab
;
220 // *** sheet options: cursor, selection, splits, zoom ***
223 if( maData
.mbMirrored
)
224 // do not call this function with sal_False, it would mirror away all drawing objects
225 rDoc
.SetLayoutRTL( nScTab
, true );
226 rTabSett
.mbSelected
= maData
.mbSelected
|| bDisplayed
;
228 // first visible cell in top-left pane and in additional pane(s)
229 rTabSett
.maFirstVis
= rAddrConv
.CreateValidAddress( maData
.maFirstXclPos
, nScTab
, false );
230 rTabSett
.maSecondVis
= rAddrConv
.CreateValidAddress( maData
.maSecondXclPos
, nScTab
, false );
232 // cursor position and selection
233 if( const XclSelectionData
* pSelData
= maData
.GetSelectionData( maData
.mnActivePane
) )
235 rTabSett
.maCursor
= rAddrConv
.CreateValidAddress( pSelData
->maXclCursor
, nScTab
, false );
236 rAddrConv
.ConvertRangeList( rTabSett
.maSelection
, pSelData
->maXclSelection
, nScTab
, false );
240 switch( maData
.mnActivePane
)
242 case EXC_PANE_TOPLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPLEFT
; break;
243 case EXC_PANE_TOPRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPRIGHT
; break;
244 case EXC_PANE_BOTTOMLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMLEFT
; break;
245 case EXC_PANE_BOTTOMRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMRIGHT
; break;
248 // freeze/split position
249 rTabSett
.mbFrozenPanes
= maData
.mbFrozenPanes
;
250 if( maData
.mbFrozenPanes
)
252 /* Frozen panes: handle split position as row/column positions.
253 #i35812# Excel uses number of visible rows/columns, Calc uses position of freeze. */
254 if( (maData
.mnSplitX
> 0) && (maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
<= GetScMaxPos().Col()) )
255 rTabSett
.maFreezePos
.SetCol( static_cast< SCCOL
>( maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
) );
256 if( (maData
.mnSplitY
> 0) && (maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
<= o3tl::make_unsigned(GetScMaxPos().Row())) )
257 rTabSett
.maFreezePos
.SetRow( static_cast< SCROW
>( maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
) );
261 // split window: position is in twips
262 rTabSett
.maSplitPos
.setX( static_cast< tools::Long
>( maData
.mnSplitX
) );
263 rTabSett
.maSplitPos
.setY( static_cast< tools::Long
>( maData
.mnSplitY
) );
267 if( maData
.mbDefGridColor
)
268 rTabSett
.maGridColor
= COL_AUTO
;
270 rTabSett
.maGridColor
= maData
.maGridColor
;
273 rTabSett
.mbShowGrid
= maData
.mbShowGrid
;
275 // view mode and zoom
276 if( maData
.mnCurrentZoom
!= 0 )
277 (maData
.mbPageMode
? maData
.mnPageZoom
: maData
.mnNormalZoom
) = maData
.mnCurrentZoom
;
278 rTabSett
.mbPageMode
= maData
.mbPageMode
;
279 rTabSett
.mnNormalZoom
= lclGetScZoom( maData
.mnNormalZoom
, EXC_WIN2_NORMALZOOM_DEF
);
280 rTabSett
.mnPageZoom
= lclGetScZoom( maData
.mnPageZoom
, EXC_WIN2_PAGEZOOM_DEF
);
282 // *** additional handling for displayed sheet ***
286 // set Excel sheet settings globally at Calc document, take settings from displayed sheet
287 ScViewOptions
aViewOpt( rDoc
.GetViewOptions() );
288 aViewOpt
.SetOption( VOPT_FORMULAS
, maData
.mbShowFormulas
);
289 aViewOpt
.SetOption( VOPT_HEADER
, maData
.mbShowHeadings
);
290 aViewOpt
.SetOption( VOPT_NULLVALS
, maData
.mbShowZeros
);
291 aViewOpt
.SetOption( VOPT_OUTLINER
, maData
.mbShowOutline
);
292 rDoc
.SetViewOptions( aViewOpt
);
295 // *** set tab bg color
296 if ( !maData
.IsDefaultTabBgColor() )
297 rDoc
.SetTabBgColor(nScTab
, maData
.maTabBgColor
);
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */