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 rStrm
>> maData
.mnWinX
42 if( GetBiff() >= EXC_BIFF5
)
44 rStrm
>> maData
.mnDisplXclTab
45 >> maData
.mnFirstVisXclTab
46 >> maData
.mnXclSelectCnt
47 >> maData
.mnTabBarWidth
;
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 // ----------------------------------------------------------------------------
88 XclImpTabViewSettings::XclImpTabViewSettings( const XclImpRoot
& rRoot
) :
94 void XclImpTabViewSettings::Initialize()
99 void XclImpTabViewSettings::ReadTabBgColor( XclImpStream
& rStrm
, XclImpPalette
& rPal
)
101 OSL_ENSURE_BIFF( GetBiff() >= EXC_BIFF8
);
102 if( GetBiff() < EXC_BIFF8
)
105 sal_uInt8 ColorIndex
;
109 ColorIndex
= rStrm
.ReaduInt8() & EXC_SHEETEXT_TABCOLOR
; //0x7F
110 if ( ColorIndex
>= 8 && ColorIndex
<= 63 ) //only accept valid index values
112 TabBgColor
= rPal
.GetColor( ColorIndex
);
113 maData
.maTabBgColor
= TabBgColor
;
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 rStrm
>> nFlags
>> maData
.maFirstXclPos
;
135 // #i59590# real life: Excel ignores some view settings in chart sheets
136 maData
.mbSelected
= ::get_flag( nFlags
, EXC_WIN2_SELECTED
);
137 maData
.mbDisplayed
= ::get_flag( nFlags
, EXC_WIN2_DISPLAYED
);
138 maData
.mbMirrored
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_MIRRORED
);
139 maData
.mbFrozenPanes
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_FROZEN
);
140 maData
.mbPageMode
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_PAGEBREAKMODE
);
141 maData
.mbDefGridColor
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_DEFGRIDCOLOR
);
142 maData
.mbShowFormulas
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_SHOWFORMULAS
);
143 maData
.mbShowGrid
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWGRID
);
144 maData
.mbShowHeadings
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWHEADINGS
);
145 maData
.mbShowZeros
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWZEROS
);
146 maData
.mbShowOutline
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWOUTLINE
);
153 rStrm
>> maData
.maGridColor
;
157 sal_uInt16 nGridColorIdx
;
158 rStrm
>> nGridColorIdx
;
159 // zoom data not included in chart sheets
160 if( rStrm
.GetRecLeft() >= 6 )
163 rStrm
>> maData
.mnPageZoom
>> maData
.mnNormalZoom
;
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 rStrm
>> nNum
>> nDenom
;
183 OSL_ENSURE( nDenom
> 0, "XclImpPageSettings::ReadScl - invalid denominator" );
185 maData
.mnCurrentZoom
= limit_cast
< sal_uInt16
>( (nNum
* 100) / nDenom
);
188 void XclImpTabViewSettings::ReadPane( XclImpStream
& rStrm
)
190 rStrm
>> maData
.mnSplitX
;
191 maData
.mnSplitY
= rStrm
.ReaduInt16();
193 rStrm
>> maData
.maSecondXclPos
194 >> maData
.mnActivePane
;
197 void XclImpTabViewSettings::ReadSelection( XclImpStream
& rStrm
)
199 // pane of this selection
202 XclSelectionData
& rSelData
= maData
.CreateSelectionData( nPane
);
203 // cursor position and selection
204 rStrm
>> rSelData
.maXclCursor
>> rSelData
.mnCursorIdx
;
205 rSelData
.maXclSelection
.Read( rStrm
, false );
208 void XclImpTabViewSettings::Finalize()
210 SCTAB nScTab
= GetCurrScTab();
211 ScDocument
& rDoc
= GetDoc();
212 XclImpAddressConverter
& rAddrConv
= GetAddressConverter();
213 ScExtTabSettings
& rTabSett
= GetExtDocOptions().GetOrCreateTabSettings( nScTab
);
214 bool bDisplayed
= GetDocViewSettings().GetDisplScTab() == nScTab
;
216 // *** sheet options: cursor, selection, splits, zoom ***
219 if( maData
.mbMirrored
)
220 // do not call this function with sal_False, it would mirror away all drawing objects
221 rDoc
.SetLayoutRTL( nScTab
, sal_True
);
222 rTabSett
.mbSelected
= maData
.mbSelected
|| bDisplayed
;
224 // first visible cell in top-left pane and in additional pane(s)
225 rTabSett
.maFirstVis
= rAddrConv
.CreateValidAddress( maData
.maFirstXclPos
, nScTab
, false );
226 rTabSett
.maSecondVis
= rAddrConv
.CreateValidAddress( maData
.maSecondXclPos
, nScTab
, false );
228 // cursor position and selection
229 if( const XclSelectionData
* pSelData
= maData
.GetSelectionData( maData
.mnActivePane
) )
231 rTabSett
.maCursor
= rAddrConv
.CreateValidAddress( pSelData
->maXclCursor
, nScTab
, false );
232 rAddrConv
.ConvertRangeList( rTabSett
.maSelection
, pSelData
->maXclSelection
, nScTab
, false );
236 switch( maData
.mnActivePane
)
238 case EXC_PANE_TOPLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPLEFT
; break;
239 case EXC_PANE_TOPRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPRIGHT
; break;
240 case EXC_PANE_BOTTOMLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMLEFT
; break;
241 case EXC_PANE_BOTTOMRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMRIGHT
; break;
244 // freeze/split position
245 rTabSett
.mbFrozenPanes
= maData
.mbFrozenPanes
;
246 if( maData
.mbFrozenPanes
)
248 /* Frozen panes: handle split position as row/column positions.
249 #i35812# Excel uses number of visible rows/columns, Calc uses position of freeze. */
250 if( (maData
.mnSplitX
> 0) && (maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
<= GetScMaxPos().Col()) )
251 rTabSett
.maFreezePos
.SetCol( static_cast< SCCOL
>( maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
) );
252 if( (maData
.mnSplitY
> 0) && (maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
<= static_cast<unsigned>(GetScMaxPos().Row())) )
253 rTabSett
.maFreezePos
.SetRow( static_cast< SCROW
>( maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
) );
257 // split window: position is in twips
258 rTabSett
.maSplitPos
.X() = static_cast< long >( maData
.mnSplitX
);
259 rTabSett
.maSplitPos
.Y() = static_cast< long >( maData
.mnSplitY
);
263 if( maData
.mbDefGridColor
)
264 rTabSett
.maGridColor
.SetColor( COL_AUTO
);
266 rTabSett
.maGridColor
= maData
.maGridColor
;
269 rTabSett
.mbShowGrid
= maData
.mbShowGrid
;
271 // view mode and zoom
272 if( maData
.mnCurrentZoom
!= 0 )
273 (maData
.mbPageMode
? maData
.mnPageZoom
: maData
.mnNormalZoom
) = maData
.mnCurrentZoom
;
274 rTabSett
.mbPageMode
= maData
.mbPageMode
;
275 rTabSett
.mnNormalZoom
= lclGetScZoom( maData
.mnNormalZoom
, EXC_WIN2_NORMALZOOM_DEF
);
276 rTabSett
.mnPageZoom
= lclGetScZoom( maData
.mnPageZoom
, EXC_WIN2_PAGEZOOM_DEF
);
278 // *** additional handling for displayed sheet ***
282 // set Excel sheet settings globally at Calc document, take settings from displayed sheet
283 ScViewOptions
aViewOpt( rDoc
.GetViewOptions() );
284 aViewOpt
.SetOption( VOPT_FORMULAS
, maData
.mbShowFormulas
);
285 aViewOpt
.SetOption( VOPT_HEADER
, maData
.mbShowHeadings
);
286 aViewOpt
.SetOption( VOPT_NULLVALS
, maData
.mbShowZeros
);
287 aViewOpt
.SetOption( VOPT_OUTLINER
, maData
.mbShowOutline
);
288 rDoc
.SetViewOptions( aViewOpt
);
291 // *** set tab bg color
292 if ( !maData
.IsDefaultTabBgColor() )
293 rDoc
.SetTabBgColor(nScTab
, maData
.maTabBgColor
);
296 // ============================================================================
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */