1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xiview.cxx,v $
10 * $Revision: 1.9.90.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "document.hxx"
35 #include "scextopt.hxx"
36 #include "viewopti.hxx"
37 #include "xistream.hxx"
38 #include "xihelper.hxx"
39 #include "xistyle.hxx"
41 // Document view settings =====================================================
43 XclImpDocViewSettings::XclImpDocViewSettings( const XclImpRoot
& rRoot
) :
48 void XclImpDocViewSettings::ReadWindow1( XclImpStream
& rStrm
)
50 rStrm
>> maData
.mnWinX
55 if( GetBiff() >= EXC_BIFF5
)
57 rStrm
>> maData
.mnDisplXclTab
58 >> maData
.mnFirstVisXclTab
59 >> maData
.mnXclSelectCnt
60 >> maData
.mnTabBarWidth
;
64 SCTAB
XclImpDocViewSettings::GetDisplScTab() const
66 /* Simply cast Excel index to Calc index.
67 TODO: This may fail if the document contains scenarios. */
68 sal_uInt16 nMaxXclTab
= static_cast< sal_uInt16
>( GetMaxPos().Tab() );
69 return static_cast< SCTAB
>( (maData
.mnDisplXclTab
<= nMaxXclTab
) ? maData
.mnDisplXclTab
: 0 );
72 void XclImpDocViewSettings::Finalize()
74 ScViewOptions
aViewOpt( GetDoc().GetViewOptions() );
75 aViewOpt
.SetOption( VOPT_HSCROLL
, ::get_flag( maData
.mnFlags
, EXC_WIN1_HOR_SCROLLBAR
) );
76 aViewOpt
.SetOption( VOPT_VSCROLL
, ::get_flag( maData
.mnFlags
, EXC_WIN1_VER_SCROLLBAR
) );
77 aViewOpt
.SetOption( VOPT_TABCONTROLS
, ::get_flag( maData
.mnFlags
, EXC_WIN1_TABBAR
) );
78 GetDoc().SetViewOptions( aViewOpt
);
81 GetExtDocOptions().GetDocSettings().mnDisplTab
= GetDisplScTab();
83 // width of the tabbar with sheet names
84 if( maData
.mnTabBarWidth
<= 1000 )
85 GetExtDocOptions().GetDocSettings().mfTabBarWidth
= static_cast< double >( maData
.mnTabBarWidth
) / 1000.0;
88 // Sheet view settings ========================================================
92 long lclGetScZoom( sal_uInt16 nXclZoom
, sal_uInt16 nDefZoom
)
94 return static_cast< long >( nXclZoom
? nXclZoom
: nDefZoom
);
99 // ----------------------------------------------------------------------------
101 XclImpTabViewSettings::XclImpTabViewSettings( const XclImpRoot
& rRoot
) :
107 void XclImpTabViewSettings::Initialize()
109 maData
.SetDefaults();
112 void XclImpTabViewSettings::ReadTabBgColor( XclImpStream
& rStrm
, XclImpPalette
& rPal
)
114 DBG_ASSERT_BIFF( GetBiff() >= EXC_BIFF8
);
115 if( GetBiff() < EXC_BIFF8
)
118 sal_uInt8 ColorIndex
;
122 ColorIndex
= rStrm
.ReaduInt8() & EXC_SHEETEXT_TABCOLOR
; //0x7F
123 if ( ColorIndex
>= 8 && ColorIndex
<= 63 ) //only accept valid index values
125 TabBgColor
= rPal
.GetColor( ColorIndex
);
126 maData
.maTabBgColor
= TabBgColor
;
130 void XclImpTabViewSettings::ReadWindow2( XclImpStream
& rStrm
, bool bChart
)
132 if( GetBiff() == EXC_BIFF2
)
134 maData
.mbShowFormulas
= rStrm
.ReaduInt8() != 0;
135 maData
.mbShowGrid
= rStrm
.ReaduInt8() != 0;
136 maData
.mbShowHeadings
= rStrm
.ReaduInt8() != 0;
137 maData
.mbFrozenPanes
= rStrm
.ReaduInt8() != 0;
138 maData
.mbShowZeros
= rStrm
.ReaduInt8() != 0;
139 rStrm
>> maData
.maFirstXclPos
;
140 maData
.mbDefGridColor
= rStrm
.ReaduInt8() != 0;
141 rStrm
>> maData
.maGridColor
;
146 rStrm
>> nFlags
>> maData
.maFirstXclPos
;
148 // #i59590# #158194# real life: Excel ignores some view settings in chart sheets
149 maData
.mbSelected
= ::get_flag( nFlags
, EXC_WIN2_SELECTED
);
150 maData
.mbDisplayed
= ::get_flag( nFlags
, EXC_WIN2_DISPLAYED
);
151 maData
.mbMirrored
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_MIRRORED
);
152 maData
.mbFrozenPanes
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_FROZEN
);
153 maData
.mbPageMode
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_PAGEBREAKMODE
);
154 maData
.mbDefGridColor
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_DEFGRIDCOLOR
);
155 maData
.mbShowFormulas
= !bChart
&& ::get_flag( nFlags
, EXC_WIN2_SHOWFORMULAS
);
156 maData
.mbShowGrid
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWGRID
);
157 maData
.mbShowHeadings
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWHEADINGS
);
158 maData
.mbShowZeros
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWZEROS
);
159 maData
.mbShowOutline
= bChart
|| ::get_flag( nFlags
, EXC_WIN2_SHOWOUTLINE
);
166 rStrm
>> maData
.maGridColor
;
170 sal_uInt16 nGridColorIdx
;
171 rStrm
>> nGridColorIdx
;
172 // zoom data not included in chart sheets
173 if( rStrm
.GetRecLeft() >= 6 )
176 rStrm
>> maData
.mnPageZoom
>> maData
.mnNormalZoom
;
179 if( !maData
.mbDefGridColor
)
180 maData
.maGridColor
= GetPalette().GetColor( nGridColorIdx
);
183 default: DBG_ERROR_BIFF();
187 // do not scroll chart sheets
189 maData
.maFirstXclPos
.Set( 0, 0 );
192 void XclImpTabViewSettings::ReadScl( XclImpStream
& rStrm
)
194 sal_uInt16 nNum
, nDenom
;
195 rStrm
>> nNum
>> nDenom
;
196 DBG_ASSERT( nDenom
> 0, "XclImpPageSettings::ReadScl - invalid denominator" );
198 maData
.mnCurrentZoom
= limit_cast
< sal_uInt16
>( (nNum
* 100) / nDenom
);
201 void XclImpTabViewSettings::ReadPane( XclImpStream
& rStrm
)
203 rStrm
>> maData
.mnSplitX
205 >> maData
.maSecondXclPos
206 >> maData
.mnActivePane
;
209 void XclImpTabViewSettings::ReadSelection( XclImpStream
& rStrm
)
211 // pane of this selection
214 XclSelectionData
& rSelData
= maData
.CreateSelectionData( nPane
);
215 // cursor position and selection
216 rStrm
>> rSelData
.maXclCursor
>> rSelData
.mnCursorIdx
;
217 rSelData
.maXclSelection
.Read( rStrm
, false );
220 void XclImpTabViewSettings::Finalize()
222 SCTAB nScTab
= GetCurrScTab();
223 ScDocument
& rDoc
= GetDoc();
224 XclImpAddressConverter
& rAddrConv
= GetAddressConverter();
225 ScExtTabSettings
& rTabSett
= GetExtDocOptions().GetOrCreateTabSettings( nScTab
);
226 bool bDisplayed
= GetDocViewSettings().GetDisplScTab() == nScTab
;
228 // *** sheet options: cursor, selection, splits, zoom ***
231 if( maData
.mbMirrored
)
232 // do not call this function with FALSE, it would mirror away all drawing objects
233 rDoc
.SetLayoutRTL( nScTab
, TRUE
);
234 rTabSett
.mbSelected
= maData
.mbSelected
|| bDisplayed
;
236 // first visible cell in top-left pane and in additional pane(s)
237 rTabSett
.maFirstVis
= rAddrConv
.CreateValidAddress( maData
.maFirstXclPos
, nScTab
, false );
238 rTabSett
.maSecondVis
= rAddrConv
.CreateValidAddress( maData
.maSecondXclPos
, nScTab
, false );
240 // cursor position and selection
241 if( const XclSelectionData
* pSelData
= maData
.GetSelectionData( maData
.mnActivePane
) )
243 rTabSett
.maCursor
= rAddrConv
.CreateValidAddress( pSelData
->maXclCursor
, nScTab
, false );
244 rAddrConv
.ConvertRangeList( rTabSett
.maSelection
, pSelData
->maXclSelection
, nScTab
, false );
248 switch( maData
.mnActivePane
)
250 case EXC_PANE_TOPLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPLEFT
; break;
251 case EXC_PANE_TOPRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_TOPRIGHT
; break;
252 case EXC_PANE_BOTTOMLEFT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMLEFT
; break;
253 case EXC_PANE_BOTTOMRIGHT
: rTabSett
.meActivePane
= SCEXT_PANE_BOTTOMRIGHT
; break;
256 // freeze/split position
257 rTabSett
.mbFrozenPanes
= maData
.mbFrozenPanes
;
258 if( maData
.mbFrozenPanes
)
260 /* Frozen panes: handle split position as row/column positions.
261 #i35812# Excel uses number of visible rows/columns, Calc uses position of freeze. */
262 if( (maData
.mnSplitX
> 0) && (maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
<= GetScMaxPos().Col()) )
263 rTabSett
.maFreezePos
.SetCol( static_cast< SCCOL
>( maData
.maFirstXclPos
.mnCol
+ maData
.mnSplitX
) );
264 if( (maData
.mnSplitY
> 0) && (maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
<= GetScMaxPos().Row()) )
265 rTabSett
.maFreezePos
.SetRow( static_cast< SCROW
>( maData
.maFirstXclPos
.mnRow
+ maData
.mnSplitY
) );
269 // split window: position is in twips
270 rTabSett
.maSplitPos
.X() = static_cast< long >( maData
.mnSplitX
);
271 rTabSett
.maSplitPos
.Y() = static_cast< long >( maData
.mnSplitY
);
275 if( maData
.mbDefGridColor
)
276 rTabSett
.maGridColor
.SetColor( COL_AUTO
);
278 rTabSett
.maGridColor
= maData
.maGridColor
;
281 rTabSett
.mbShowGrid
= maData
.mbShowGrid
;
283 // view mode and zoom
284 if( maData
.mnCurrentZoom
!= 0 )
285 (maData
.mbPageMode
? maData
.mnPageZoom
: maData
.mnNormalZoom
) = maData
.mnCurrentZoom
;
286 rTabSett
.mbPageMode
= maData
.mbPageMode
;
287 rTabSett
.mnNormalZoom
= lclGetScZoom( maData
.mnNormalZoom
, EXC_WIN2_NORMALZOOM_DEF
);
288 rTabSett
.mnPageZoom
= lclGetScZoom( maData
.mnPageZoom
, EXC_WIN2_PAGEZOOM_DEF
);
290 // *** additional handling for displayed sheet ***
294 // set Excel sheet settings globally at Calc document, take settings from displayed sheet
295 ScViewOptions
aViewOpt( rDoc
.GetViewOptions() );
296 aViewOpt
.SetOption( VOPT_FORMULAS
, maData
.mbShowFormulas
);
297 aViewOpt
.SetOption( VOPT_HEADER
, maData
.mbShowHeadings
);
298 aViewOpt
.SetOption( VOPT_NULLVALS
, maData
.mbShowZeros
);
299 aViewOpt
.SetOption( VOPT_OUTLINER
, maData
.mbShowOutline
);
300 rDoc
.SetViewOptions( aViewOpt
);
303 // *** set tab bg color
304 if ( !maData
.IsDefaultTabBgColor() )
305 rTabSett
.maTabBgColor
= maData
.maTabBgColor
;
308 // ============================================================================