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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 #include "xiview.hxx"
27 #include "document.hxx"
28 #include "scextopt.hxx"
29 #include "viewopti.hxx"
30 #include "xistream.hxx"
31 #include "xihelper.hxx"
32 #include "xistyle.hxx"
33
34 // Document view settings =====================================================
35
XclImpDocViewSettings(const XclImpRoot & rRoot)36 XclImpDocViewSettings::XclImpDocViewSettings( const XclImpRoot& rRoot ) :
37 XclImpRoot( rRoot )
38 {
39 }
40
ReadWindow1(XclImpStream & rStrm)41 void XclImpDocViewSettings::ReadWindow1( XclImpStream& rStrm )
42 {
43 rStrm >> maData.mnWinX
44 >> maData.mnWinY
45 >> maData.mnWinWidth
46 >> maData.mnWinHeight
47 >> maData.mnFlags;
48 if( GetBiff() >= EXC_BIFF5 )
49 {
50 rStrm >> maData.mnDisplXclTab
51 >> maData.mnFirstVisXclTab
52 >> maData.mnXclSelectCnt
53 >> maData.mnTabBarWidth;
54 }
55 }
56
GetDisplScTab() const57 SCTAB XclImpDocViewSettings::GetDisplScTab() const
58 {
59 /* Simply cast Excel index to Calc index.
60 TODO: This may fail if the document contains scenarios. */
61 sal_uInt16 nMaxXclTab = static_cast< sal_uInt16 >( GetMaxPos().Tab() );
62 return static_cast< SCTAB >( (maData.mnDisplXclTab <= nMaxXclTab) ? maData.mnDisplXclTab : 0 );
63 }
64
Finalize()65 void XclImpDocViewSettings::Finalize()
66 {
67 ScViewOptions aViewOpt( GetDoc().GetViewOptions() );
68 aViewOpt.SetOption( VOPT_HSCROLL, ::get_flag( maData.mnFlags, EXC_WIN1_HOR_SCROLLBAR ) );
69 aViewOpt.SetOption( VOPT_VSCROLL, ::get_flag( maData.mnFlags, EXC_WIN1_VER_SCROLLBAR ) );
70 aViewOpt.SetOption( VOPT_TABCONTROLS, ::get_flag( maData.mnFlags, EXC_WIN1_TABBAR ) );
71 GetDoc().SetViewOptions( aViewOpt );
72
73 // displayed sheet
74 GetExtDocOptions().GetDocSettings().mnDisplTab = GetDisplScTab();
75
76 // width of the tabbar with sheet names
77 if( maData.mnTabBarWidth <= 1000 )
78 GetExtDocOptions().GetDocSettings().mfTabBarWidth = static_cast< double >( maData.mnTabBarWidth ) / 1000.0;
79 }
80
81 // Sheet view settings ========================================================
82
83 namespace {
84
lclGetScZoom(sal_uInt16 nXclZoom,sal_uInt16 nDefZoom)85 long lclGetScZoom( sal_uInt16 nXclZoom, sal_uInt16 nDefZoom )
86 {
87 return static_cast< long >( nXclZoom ? nXclZoom : nDefZoom );
88 }
89
90 } // namespace
91
92 // ----------------------------------------------------------------------------
93
XclImpTabViewSettings(const XclImpRoot & rRoot)94 XclImpTabViewSettings::XclImpTabViewSettings( const XclImpRoot& rRoot ) :
95 XclImpRoot( rRoot )
96 {
97 Initialize();
98 }
99
Initialize()100 void XclImpTabViewSettings::Initialize()
101 {
102 maData.SetDefaults();
103 }
104
ReadTabBgColor(XclImpStream & rStrm,XclImpPalette & rPal)105 void XclImpTabViewSettings::ReadTabBgColor( XclImpStream& rStrm, XclImpPalette& rPal )
106 {
107 DBG_ASSERT_BIFF( GetBiff() >= EXC_BIFF8 );
108 if( GetBiff() < EXC_BIFF8 )
109 return;
110
111 sal_uInt8 ColorIndex;
112 Color TabBgColor;
113
114 rStrm.Ignore( 16 );
115 ColorIndex = rStrm.ReaduInt8() & EXC_SHEETEXT_TABCOLOR; //0x7F
116 if ( ColorIndex >= 8 && ColorIndex <= 63 ) //only accept valid index values
117 {
118 TabBgColor = rPal.GetColor( ColorIndex );
119 maData.maTabBgColor = TabBgColor;
120 }
121 }
122
ReadWindow2(XclImpStream & rStrm,bool bChart)123 void XclImpTabViewSettings::ReadWindow2( XclImpStream& rStrm, bool bChart )
124 {
125 if( GetBiff() == EXC_BIFF2 )
126 {
127 maData.mbShowFormulas = rStrm.ReaduInt8() != 0;
128 maData.mbShowGrid = rStrm.ReaduInt8() != 0;
129 maData.mbShowHeadings = rStrm.ReaduInt8() != 0;
130 maData.mbFrozenPanes = rStrm.ReaduInt8() != 0;
131 maData.mbShowZeros = rStrm.ReaduInt8() != 0;
132 rStrm >> maData.maFirstXclPos;
133 maData.mbDefGridColor = rStrm.ReaduInt8() != 0;
134 rStrm >> maData.maGridColor;
135 }
136 else
137 {
138 sal_uInt16 nFlags;
139 rStrm >> nFlags >> maData.maFirstXclPos;
140
141 // #i59590# #158194# real life: Excel ignores some view settings in chart sheets
142 maData.mbSelected = ::get_flag( nFlags, EXC_WIN2_SELECTED );
143 maData.mbDisplayed = ::get_flag( nFlags, EXC_WIN2_DISPLAYED );
144 maData.mbMirrored = !bChart && ::get_flag( nFlags, EXC_WIN2_MIRRORED );
145 maData.mbFrozenPanes = !bChart && ::get_flag( nFlags, EXC_WIN2_FROZEN );
146 maData.mbPageMode = !bChart && ::get_flag( nFlags, EXC_WIN2_PAGEBREAKMODE );
147 maData.mbDefGridColor = bChart || ::get_flag( nFlags, EXC_WIN2_DEFGRIDCOLOR );
148 maData.mbShowFormulas = !bChart && ::get_flag( nFlags, EXC_WIN2_SHOWFORMULAS );
149 maData.mbShowGrid = bChart || ::get_flag( nFlags, EXC_WIN2_SHOWGRID );
150 maData.mbShowHeadings = bChart || ::get_flag( nFlags, EXC_WIN2_SHOWHEADINGS );
151 maData.mbShowZeros = bChart || ::get_flag( nFlags, EXC_WIN2_SHOWZEROS );
152 maData.mbShowOutline = bChart || ::get_flag( nFlags, EXC_WIN2_SHOWOUTLINE );
153
154 switch( GetBiff() )
155 {
156 case EXC_BIFF3:
157 case EXC_BIFF4:
158 case EXC_BIFF5:
159 rStrm >> maData.maGridColor;
160 break;
161 case EXC_BIFF8:
162 {
163 sal_uInt16 nGridColorIdx;
164 rStrm >> nGridColorIdx;
165 // zoom data not included in chart sheets
166 if( rStrm.GetRecLeft() >= 6 )
167 {
168 rStrm.Ignore( 2 );
169 rStrm >> maData.mnPageZoom >> maData.mnNormalZoom;
170 }
171
172 if( !maData.mbDefGridColor )
173 maData.maGridColor = GetPalette().GetColor( nGridColorIdx );
174 }
175 break;
176 default: DBG_ERROR_BIFF();
177 }
178 }
179
180 // do not scroll chart sheets
181 if( bChart )
182 maData.maFirstXclPos.Set( 0, 0 );
183 }
184
ReadScl(XclImpStream & rStrm)185 void XclImpTabViewSettings::ReadScl( XclImpStream& rStrm )
186 {
187 sal_uInt16 nNum, nDenom;
188 rStrm >> nNum >> nDenom;
189 DBG_ASSERT( nDenom > 0, "XclImpPageSettings::ReadScl - invalid denominator" );
190 if( nDenom > 0 )
191 maData.mnCurrentZoom = limit_cast< sal_uInt16 >( (nNum * 100) / nDenom );
192 }
193
ReadPane(XclImpStream & rStrm)194 void XclImpTabViewSettings::ReadPane( XclImpStream& rStrm )
195 {
196 rStrm >> maData.mnSplitX
197 >> maData.mnSplitY
198 >> maData.maSecondXclPos
199 >> maData.mnActivePane;
200 }
201
ReadSelection(XclImpStream & rStrm)202 void XclImpTabViewSettings::ReadSelection( XclImpStream& rStrm )
203 {
204 // pane of this selection
205 sal_uInt8 nPane;
206 rStrm >> nPane;
207 XclSelectionData& rSelData = maData.CreateSelectionData( nPane );
208 // cursor position and selection
209 rStrm >> rSelData.maXclCursor >> rSelData.mnCursorIdx;
210 rSelData.maXclSelection.Read( rStrm, false );
211 }
212
Finalize()213 void XclImpTabViewSettings::Finalize()
214 {
215 SCTAB nScTab = GetCurrScTab();
216 ScDocument& rDoc = GetDoc();
217 XclImpAddressConverter& rAddrConv = GetAddressConverter();
218 ScExtTabSettings& rTabSett = GetExtDocOptions().GetOrCreateTabSettings( nScTab );
219 bool bDisplayed = GetDocViewSettings().GetDisplScTab() == nScTab;
220
221 // *** sheet options: cursor, selection, splits, zoom ***
222
223 // sheet flags
224 if( maData.mbMirrored )
225 // do not call this function with sal_False, it would mirror away all drawing objects
226 rDoc.SetLayoutRTL( nScTab, sal_True );
227 rTabSett.mbSelected = maData.mbSelected || bDisplayed;
228
229 // first visible cell in top-left pane and in additional pane(s)
230 rTabSett.maFirstVis = rAddrConv.CreateValidAddress( maData.maFirstXclPos, nScTab, false );
231 rTabSett.maSecondVis = rAddrConv.CreateValidAddress( maData.maSecondXclPos, nScTab, false );
232
233 // cursor position and selection
234 if( const XclSelectionData* pSelData = maData.GetSelectionData( maData.mnActivePane ) )
235 {
236 rTabSett.maCursor = rAddrConv.CreateValidAddress( pSelData->maXclCursor, nScTab, false );
237 rAddrConv.ConvertRangeList( rTabSett.maSelection, pSelData->maXclSelection, nScTab, false );
238 }
239
240 // active pane
241 switch( maData.mnActivePane )
242 {
243 case EXC_PANE_TOPLEFT: rTabSett.meActivePane = SCEXT_PANE_TOPLEFT; break;
244 case EXC_PANE_TOPRIGHT: rTabSett.meActivePane = SCEXT_PANE_TOPRIGHT; break;
245 case EXC_PANE_BOTTOMLEFT: rTabSett.meActivePane = SCEXT_PANE_BOTTOMLEFT; break;
246 case EXC_PANE_BOTTOMRIGHT: rTabSett.meActivePane = SCEXT_PANE_BOTTOMRIGHT; break;
247 }
248
249 // freeze/split position
250 rTabSett.mbFrozenPanes = maData.mbFrozenPanes;
251 if( maData.mbFrozenPanes )
252 {
253 /* Frozen panes: handle split position as row/column positions.
254 #i35812# Excel uses number of visible rows/columns, Calc uses position of freeze. */
255 if( (maData.mnSplitX > 0) && (maData.maFirstXclPos.mnCol + maData.mnSplitX <= GetScMaxPos().Col()) )
256 rTabSett.maFreezePos.SetCol( static_cast< SCCOL >( maData.maFirstXclPos.mnCol + maData.mnSplitX ) );
257 if( (maData.mnSplitY > 0) && (maData.maFirstXclPos.mnRow + maData.mnSplitY <= GetScMaxPos().Row()) )
258 rTabSett.maFreezePos.SetRow( static_cast< SCROW >( maData.maFirstXclPos.mnRow + maData.mnSplitY ) );
259 }
260 else
261 {
262 // split window: position is in twips
263 rTabSett.maSplitPos.X() = static_cast< long >( maData.mnSplitX );
264 rTabSett.maSplitPos.Y() = static_cast< long >( maData.mnSplitY );
265 }
266
267 // grid color
268 if( maData.mbDefGridColor )
269 rTabSett.maGridColor.SetColor( COL_AUTO );
270 else
271 rTabSett.maGridColor = maData.maGridColor;
272
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 );
279
280 // *** additional handling for displayed sheet ***
281
282 if( bDisplayed )
283 {
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_GRID, maData.mbShowGrid );
288 aViewOpt.SetOption( VOPT_HEADER, maData.mbShowHeadings );
289 aViewOpt.SetOption( VOPT_NULLVALS, maData.mbShowZeros );
290 aViewOpt.SetOption( VOPT_OUTLINER, maData.mbShowOutline );
291 rDoc.SetViewOptions( aViewOpt );
292 }
293
294 // *** set tab bg color
295 if ( !maData.IsDefaultTabBgColor() )
296 rDoc.SetTabBgColor(nScTab, maData.maTabBgColor);
297 }
298
299 // ============================================================================
300
301