Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/svdtrans.hxx>
30 : : #include <unotools/localedatawrapper.hxx>
31 : :
32 : : #include "colrowba.hxx"
33 : : #include "document.hxx"
34 : : #include "scmod.hxx"
35 : : #include "tabvwsh.hxx"
36 : : #include "docsh.hxx"
37 : : #include "appoptio.hxx"
38 : : #include "globstr.hrc"
39 : : #include "markdata.hxx"
40 : :
41 : : // STATIC DATA -----------------------------------------------------------
42 : :
43 : : //==================================================================
44 : :
45 : 0 : String lcl_MetricString( long nTwips, const String& rText )
46 : : {
47 [ # # ]: 0 : if ( nTwips <= 0 )
48 : 0 : return ScGlobal::GetRscString(STR_TIP_HIDE);
49 : : else
50 : : {
51 [ # # ][ # # ]: 0 : FieldUnit eUserMet = SC_MOD()->GetAppOptions().GetAppMetric();
52 : :
53 [ # # ]: 0 : sal_Int64 nUserVal = MetricField::ConvertValue( nTwips*100, 1, 2, FUNIT_TWIP, eUserMet );
54 : :
55 [ # # ]: 0 : String aStr = rText;
56 [ # # ]: 0 : aStr += ' ';
57 [ # # ][ # # ]: 0 : aStr += ScGlobal::pLocaleData->getNum( nUserVal, 2 );
58 [ # # ]: 0 : aStr += ' ';
59 [ # # ][ # # ]: 0 : aStr += SdrFormatter::GetUnitStr(eUserMet);
[ # # ]
60 : :
61 [ # # ][ # # ]: 0 : return aStr;
62 : : }
63 : : }
64 : :
65 : : //==================================================================
66 : :
67 : 229 : ScColBar::ScColBar( Window* pParent, ScViewData* pData, ScHSplitPos eWhichPos,
68 : : ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
69 : : ScHeaderControl( pParent, pEng, MAXCOL+1, HDR_HORIZONTAL ),
70 : : pViewData( pData ),
71 : : eWhich( eWhichPos ),
72 : : pFuncSet( pFunc ),
73 : 229 : pSelEngine( pEng )
74 : : {
75 [ + - ]: 229 : Show();
76 : 229 : }
77 : :
78 : 225 : ScColBar::~ScColBar()
79 : : {
80 [ - + ]: 450 : }
81 : :
82 : 2665 : inline sal_Bool ScColBar::UseNumericHeader() const
83 : : {
84 : 2665 : return pViewData->GetDocument()->GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1;
85 : : }
86 : :
87 : 815 : SCCOLROW ScColBar::GetPos()
88 : : {
89 : 815 : return pViewData->GetPosX(eWhich);
90 : : }
91 : :
92 : 13862 : sal_uInt16 ScColBar::GetEntrySize( SCCOLROW nEntryNo )
93 : : {
94 : 13862 : ScDocument* pDoc = pViewData->GetDocument();
95 : 13862 : SCTAB nTab = pViewData->GetTabNo();
96 [ - + ]: 13862 : if (pDoc->ColHidden(static_cast<SCCOL>(nEntryNo), nTab))
97 : 0 : return 0;
98 : : else
99 : 13862 : return (sal_uInt16) ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), pViewData->GetPPTX() );
100 : : }
101 : :
102 : 2665 : String ScColBar::GetEntryText( SCCOLROW nEntryNo )
103 : : {
104 : 2665 : return UseNumericHeader()
105 : : ? String::CreateFromInt32( nEntryNo + 1 )
106 [ - + ]: 2665 : : ScColToAlpha( static_cast<SCCOL>(nEntryNo) );
107 : : }
108 : :
109 : 0 : void ScColBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
110 : : {
111 : : sal_uInt16 nSizeTwips;
112 : 0 : ScSizeMode eMode = SC_SIZE_DIRECT;
113 [ # # ][ # # ]: 0 : if (nNewSize>0 && nNewSize<10) nNewSize=10; // (Pixel)
114 : :
115 [ # # ]: 0 : if ( nNewSize == HDR_SIZE_OPTIMUM )
116 : : {
117 : 0 : nSizeTwips = STD_EXTRA_WIDTH;
118 : 0 : eMode = SC_SIZE_OPTIMAL;
119 : : }
120 : : else
121 : 0 : nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTX() );
122 : :
123 : 0 : ScMarkData& rMark = pViewData->GetMarkData();
124 : :
125 : 0 : SCCOLROW* pRanges = new SCCOLROW[MAXCOL+1];
126 : 0 : SCCOL nRangeCnt = 0;
127 [ # # ]: 0 : if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) )
128 : : {
129 : 0 : SCCOL nStart = 0;
130 [ # # ]: 0 : while (nStart<=MAXCOL)
131 : : {
132 [ # # ][ # # ]: 0 : while (nStart<MAXCOL && !rMark.IsColumnMarked(nStart))
[ # # ]
133 : 0 : ++nStart;
134 [ # # ]: 0 : if (rMark.IsColumnMarked(nStart))
135 : : {
136 : 0 : SCCOL nEnd = nStart;
137 [ # # ][ # # ]: 0 : while (nEnd<MAXCOL && rMark.IsColumnMarked(nEnd))
[ # # ]
138 : 0 : ++nEnd;
139 [ # # ]: 0 : if (!rMark.IsColumnMarked(nEnd))
140 : 0 : --nEnd;
141 : 0 : pRanges[static_cast<size_t>(2*nRangeCnt) ] = nStart;
142 : 0 : pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
143 : 0 : ++nRangeCnt;
144 : 0 : nStart = nEnd+1;
145 : : }
146 : : else
147 : 0 : nStart = MAXCOL+1;
148 : : }
149 : : }
150 : : else
151 : : {
152 : 0 : pRanges[0] = nPos;
153 : 0 : pRanges[1] = nPos;
154 : 0 : nRangeCnt = 1;
155 : : }
156 : :
157 : 0 : pViewData->GetView()->SetWidthOrHeight( sal_True, nRangeCnt, pRanges, eMode, nSizeTwips );
158 [ # # ]: 0 : delete[] pRanges;
159 : 0 : }
160 : :
161 : 0 : void ScColBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
162 : : {
163 : : SCCOLROW nRange[2];
164 : 0 : nRange[0] = nStart;
165 : 0 : nRange[1] = nEnd;
166 [ # # ]: 0 : pViewData->GetView()->SetWidthOrHeight( sal_True, 1, nRange, SC_SIZE_DIRECT, 0 );
167 : 0 : }
168 : :
169 : 458 : void ScColBar::SetMarking( sal_Bool bSet )
170 : : {
171 : 458 : pViewData->GetMarkData().SetMarking( bSet );
172 [ + - ]: 458 : if (!bSet)
173 : : {
174 : 458 : pViewData->GetView()->UpdateAutoFillMark();
175 : : }
176 : 458 : }
177 : :
178 : 0 : void ScColBar::SelectWindow()
179 : : {
180 : 0 : ScTabViewShell* pViewSh = pViewData->GetViewShell();
181 : :
182 : 0 : pViewSh->SetActive(); // Appear and SetViewFrame
183 : 0 : pViewSh->DrawDeselectAll();
184 : :
185 : 0 : ScSplitPos eActive = pViewData->GetActivePart();
186 [ # # ]: 0 : if (eWhich==SC_SPLIT_LEFT)
187 : : {
188 [ # # ]: 0 : if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_TOPLEFT;
189 [ # # ]: 0 : if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_BOTTOMLEFT;
190 : : }
191 : : else
192 : : {
193 [ # # ]: 0 : if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_TOPRIGHT;
194 [ # # ]: 0 : if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_BOTTOMRIGHT;
195 : : }
196 : 0 : pViewSh->ActivatePart( eActive );
197 : :
198 : 0 : pFuncSet->SetColumn( sal_True );
199 : 0 : pFuncSet->SetWhich( eActive );
200 : :
201 : 0 : pViewSh->ActiveGrabFocus();
202 : 0 : }
203 : :
204 : 0 : sal_Bool ScColBar::IsDisabled()
205 : : {
206 : 0 : ScModule* pScMod = SC_MOD();
207 [ # # ][ # # ]: 0 : return pScMod->IsFormulaMode() || pScMod->IsModalMode();
208 : : }
209 : :
210 : 0 : sal_Bool ScColBar::ResizeAllowed()
211 : : {
212 : 0 : return !pViewData->HasEditView( pViewData->GetActivePart() );
213 : : }
214 : :
215 : 0 : void ScColBar::DrawInvert( long nDragPosP )
216 : : {
217 [ # # ]: 0 : Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
218 [ # # ]: 0 : Update();
219 [ # # ]: 0 : Invert(aRect);
220 : :
221 [ # # ]: 0 : pViewData->GetView()->InvertVertical(eWhich,nDragPosP);
222 : 0 : }
223 : :
224 : 0 : String ScColBar::GetDragHelp( long nVal )
225 : : {
226 : 0 : long nTwips = (long) ( nVal / pViewData->GetPPTX() );
227 : 0 : return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_WIDTH) );
228 : : }
229 : :
230 : 1086 : sal_Bool ScColBar::IsLayoutRTL() // overloaded only for columns
231 : : {
232 : 1086 : return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
233 : : }
234 : :
235 : : //==================================================================
236 : :
237 : 229 : ScRowBar::ScRowBar( Window* pParent, ScViewData* pData, ScVSplitPos eWhichPos,
238 : : ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
239 : : ScHeaderControl( pParent, pEng, MAXROW+1, HDR_VERTICAL ),
240 : : pViewData( pData ),
241 : : eWhich( eWhichPos ),
242 : : pFuncSet( pFunc ),
243 : 229 : pSelEngine( pEng )
244 : : {
245 [ + - ]: 229 : Show();
246 : 229 : }
247 : :
248 : 225 : ScRowBar::~ScRowBar()
249 : : {
250 [ - + ]: 450 : }
251 : :
252 : 898 : SCCOLROW ScRowBar::GetPos()
253 : : {
254 : 898 : return pViewData->GetPosY(eWhich);
255 : : }
256 : :
257 : 44940 : sal_uInt16 ScRowBar::GetEntrySize( SCCOLROW nEntryNo )
258 : : {
259 [ + - ]: 44940 : ScDocument* pDoc = pViewData->GetDocument();
260 : 44940 : SCTAB nTab = pViewData->GetTabNo();
261 : 44940 : SCROW nLastRow = -1;
262 [ + + ][ + - ]: 44940 : if (pDoc->RowHidden(nEntryNo, nTab, NULL, &nLastRow))
263 : 34 : return 0;
264 : : else
265 : : return (sal_uInt16) ScViewData::ToPixel( pDoc->GetOriginalHeight( nEntryNo,
266 [ + - ]: 44940 : nTab ), pViewData->GetPPTY() );
267 : : }
268 : :
269 : 8814 : String ScRowBar::GetEntryText( SCCOLROW nEntryNo )
270 : : {
271 : 8814 : return String::CreateFromInt32( nEntryNo + 1 );
272 : : }
273 : :
274 : 0 : void ScRowBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
275 : : {
276 : : sal_uInt16 nSizeTwips;
277 : 0 : ScSizeMode eMode = SC_SIZE_DIRECT;
278 [ # # ][ # # ]: 0 : if (nNewSize>0 && nNewSize<10) nNewSize=10; // (Pixel)
279 : :
280 [ # # ]: 0 : if ( nNewSize == HDR_SIZE_OPTIMUM )
281 : : {
282 : 0 : nSizeTwips = 0;
283 : 0 : eMode = SC_SIZE_OPTIMAL;
284 : : }
285 : : else
286 : 0 : nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTY() );
287 : :
288 : 0 : ScMarkData& rMark = pViewData->GetMarkData();
289 : :
290 : 0 : SCCOLROW* pRanges = new SCCOLROW[MAXROW+1];
291 : 0 : SCROW nRangeCnt = 0;
292 [ # # ]: 0 : if ( rMark.IsRowMarked( nPos ) )
293 : : {
294 : 0 : SCROW nStart = 0;
295 [ # # ]: 0 : while (nStart<=MAXROW)
296 : : {
297 [ # # ][ # # ]: 0 : while (nStart<MAXROW && !rMark.IsRowMarked(nStart))
[ # # ]
298 : 0 : ++nStart;
299 [ # # ]: 0 : if (rMark.IsRowMarked(nStart))
300 : : {
301 : 0 : SCROW nEnd = nStart;
302 [ # # ][ # # ]: 0 : while (nEnd<MAXROW && rMark.IsRowMarked(nEnd))
[ # # ]
303 : 0 : ++nEnd;
304 [ # # ]: 0 : if (!rMark.IsRowMarked(nEnd))
305 : 0 : --nEnd;
306 : 0 : pRanges[static_cast<size_t>(2*nRangeCnt) ] = nStart;
307 : 0 : pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
308 : 0 : ++nRangeCnt;
309 : 0 : nStart = nEnd+1;
310 : : }
311 : : else
312 : 0 : nStart = MAXROW+1;
313 : : }
314 : : }
315 : : else
316 : : {
317 : 0 : pRanges[0] = nPos;
318 : 0 : pRanges[1] = nPos;
319 : 0 : nRangeCnt = 1;
320 : : }
321 : :
322 : 0 : pViewData->GetView()->SetWidthOrHeight( false, nRangeCnt, pRanges, eMode, nSizeTwips );
323 [ # # ]: 0 : delete[] pRanges;
324 : 0 : }
325 : :
326 : 0 : void ScRowBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
327 : : {
328 : : SCCOLROW nRange[2];
329 : 0 : nRange[0] = nStart;
330 : 0 : nRange[1] = nEnd;
331 [ # # ]: 0 : pViewData->GetView()->SetWidthOrHeight( false, 1, nRange, SC_SIZE_DIRECT, 0 );
332 : 0 : }
333 : :
334 : 458 : void ScRowBar::SetMarking( sal_Bool bSet )
335 : : {
336 : 458 : pViewData->GetMarkData().SetMarking( bSet );
337 [ + - ]: 458 : if (!bSet)
338 : : {
339 : 458 : pViewData->GetView()->UpdateAutoFillMark();
340 : : }
341 : 458 : }
342 : :
343 : 0 : void ScRowBar::SelectWindow()
344 : : {
345 : 0 : ScTabViewShell* pViewSh = pViewData->GetViewShell();
346 : :
347 : 0 : pViewSh->SetActive(); // Appear and SetViewFrame
348 : 0 : pViewSh->DrawDeselectAll();
349 : :
350 : 0 : ScSplitPos eActive = pViewData->GetActivePart();
351 [ # # ]: 0 : if (eWhich==SC_SPLIT_TOP)
352 : : {
353 [ # # ]: 0 : if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_TOPLEFT;
354 [ # # ]: 0 : if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_TOPRIGHT;
355 : : }
356 : : else
357 : : {
358 [ # # ]: 0 : if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_BOTTOMLEFT;
359 [ # # ]: 0 : if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_BOTTOMRIGHT;
360 : : }
361 : 0 : pViewSh->ActivatePart( eActive );
362 : :
363 : 0 : pFuncSet->SetColumn( false );
364 : 0 : pFuncSet->SetWhich( eActive );
365 : :
366 : 0 : pViewSh->ActiveGrabFocus();
367 : 0 : }
368 : :
369 : 0 : sal_Bool ScRowBar::IsDisabled()
370 : : {
371 : 0 : ScModule* pScMod = SC_MOD();
372 [ # # ][ # # ]: 0 : return pScMod->IsFormulaMode() || pScMod->IsModalMode();
373 : : }
374 : :
375 : 0 : sal_Bool ScRowBar::ResizeAllowed()
376 : : {
377 : 0 : return !pViewData->HasEditView( pViewData->GetActivePart() );
378 : : }
379 : :
380 : 0 : void ScRowBar::DrawInvert( long nDragPosP )
381 : : {
382 [ # # ]: 0 : Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
383 [ # # ]: 0 : Update();
384 [ # # ]: 0 : Invert(aRect);
385 : :
386 [ # # ]: 0 : pViewData->GetView()->InvertHorizontal(eWhich,nDragPosP);
387 : 0 : }
388 : :
389 : 0 : String ScRowBar::GetDragHelp( long nVal )
390 : : {
391 : 0 : long nTwips = (long) ( nVal / pViewData->GetPPTY() );
392 : 0 : return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_HEIGHT) );
393 : : }
394 : :
395 : 32 : SCROW ScRowBar::GetHiddenCount( SCROW nEntryNo ) // overloaded only for rows
396 : : {
397 : 32 : ScDocument* pDoc = pViewData->GetDocument();
398 : 32 : SCTAB nTab = pViewData->GetTabNo();
399 : 32 : return pDoc->GetHiddenRowCount( nEntryNo, nTab );
400 : : }
401 : :
402 : 1024 : sal_Bool ScRowBar::IsMirrored() // overloaded only for rows
403 : : {
404 : 1024 : return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
405 : : }
406 : :
407 : :
408 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|