Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / colrowba.cxx
blobeed1ba9208e3a9ce6a4c6b33acd50134427d124f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svx/svdtrans.hxx>
21 #include <unotools/localedatawrapper.hxx>
23 #include "colrowba.hxx"
24 #include "document.hxx"
25 #include "scmod.hxx"
26 #include "tabvwsh.hxx"
27 #include "docsh.hxx"
28 #include "appoptio.hxx"
29 #include "globstr.hrc"
30 #include "markdata.hxx"
32 // STATIC DATA -----------------------------------------------------------
34 //==================================================================
36 static String lcl_MetricString( long nTwips, const String& rText )
38 if ( nTwips <= 0 )
39 return ScGlobal::GetRscString(STR_TIP_HIDE);
40 else
42 FieldUnit eUserMet = SC_MOD()->GetAppOptions().GetAppMetric();
44 sal_Int64 nUserVal = MetricField::ConvertValue( nTwips*100, 1, 2, FUNIT_TWIP, eUserMet );
46 String aStr = rText;
47 aStr += ' ';
48 aStr += ScGlobal::pLocaleData->getNum( nUserVal, 2 );
49 aStr += ' ';
50 aStr += SdrFormatter::GetUnitStr(eUserMet);
52 return aStr;
56 //==================================================================
58 ScColBar::ScColBar( Window* pParent, ScViewData* pData, ScHSplitPos eWhichPos,
59 ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
60 ScHeaderControl( pParent, pEng, MAXCOL+1, false ),
61 pViewData( pData ),
62 eWhich( eWhichPos ),
63 pFuncSet( pFunc )
65 Show();
68 ScColBar::~ScColBar()
72 inline sal_Bool ScColBar::UseNumericHeader() const
74 return pViewData->GetDocument()->GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1;
77 SCCOLROW ScColBar::GetPos()
79 return pViewData->GetPosX(eWhich);
82 sal_uInt16 ScColBar::GetEntrySize( SCCOLROW nEntryNo )
84 ScDocument* pDoc = pViewData->GetDocument();
85 SCTAB nTab = pViewData->GetTabNo();
86 if (pDoc->ColHidden(static_cast<SCCOL>(nEntryNo), nTab))
87 return 0;
88 else
89 return (sal_uInt16) ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), pViewData->GetPPTX() );
92 String ScColBar::GetEntryText( SCCOLROW nEntryNo )
94 return UseNumericHeader()
95 ? String::CreateFromInt32( nEntryNo + 1 )
96 : ScColToAlpha( static_cast<SCCOL>(nEntryNo) );
99 void ScColBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
101 sal_uInt16 nSizeTwips;
102 ScSizeMode eMode = SC_SIZE_DIRECT;
103 if (nNewSize>0 && nNewSize<10) nNewSize=10; // (Pixel)
105 if ( nNewSize == HDR_SIZE_OPTIMUM )
107 nSizeTwips = STD_EXTRA_WIDTH;
108 eMode = SC_SIZE_OPTIMAL;
110 else
111 nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTX() );
113 ScMarkData& rMark = pViewData->GetMarkData();
115 SCCOLROW* pRanges = new SCCOLROW[MAXCOL+1];
116 SCCOL nRangeCnt = 0;
117 if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) )
119 SCCOL nStart = 0;
120 while (nStart<=MAXCOL)
122 while (nStart<MAXCOL && !rMark.IsColumnMarked(nStart))
123 ++nStart;
124 if (rMark.IsColumnMarked(nStart))
126 SCCOL nEnd = nStart;
127 while (nEnd<MAXCOL && rMark.IsColumnMarked(nEnd))
128 ++nEnd;
129 if (!rMark.IsColumnMarked(nEnd))
130 --nEnd;
131 pRanges[static_cast<size_t>(2*nRangeCnt) ] = nStart;
132 pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
133 ++nRangeCnt;
134 nStart = nEnd+1;
136 else
137 nStart = MAXCOL+1;
140 else
142 pRanges[0] = nPos;
143 pRanges[1] = nPos;
144 nRangeCnt = 1;
147 pViewData->GetView()->SetWidthOrHeight( sal_True, nRangeCnt, pRanges, eMode, nSizeTwips );
148 delete[] pRanges;
151 void ScColBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
153 SCCOLROW nRange[2];
154 nRange[0] = nStart;
155 nRange[1] = nEnd;
156 pViewData->GetView()->SetWidthOrHeight( sal_True, 1, nRange, SC_SIZE_DIRECT, 0 );
159 void ScColBar::SetMarking( sal_Bool bSet )
161 pViewData->GetMarkData().SetMarking( bSet );
162 if (!bSet)
164 pViewData->GetView()->UpdateAutoFillMark();
168 void ScColBar::SelectWindow()
170 ScTabViewShell* pViewSh = pViewData->GetViewShell();
172 pViewSh->SetActive(); // Appear and SetViewFrame
173 pViewSh->DrawDeselectAll();
175 ScSplitPos eActive = pViewData->GetActivePart();
176 if (eWhich==SC_SPLIT_LEFT)
178 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_TOPLEFT;
179 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_BOTTOMLEFT;
181 else
183 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_TOPRIGHT;
184 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_BOTTOMRIGHT;
186 pViewSh->ActivatePart( eActive );
188 pFuncSet->SetColumn( sal_True );
189 pFuncSet->SetWhich( eActive );
191 pViewSh->ActiveGrabFocus();
194 sal_Bool ScColBar::IsDisabled()
196 ScModule* pScMod = SC_MOD();
197 return pScMod->IsFormulaMode() || pScMod->IsModalMode();
200 sal_Bool ScColBar::ResizeAllowed()
202 return !pViewData->HasEditView( pViewData->GetActivePart() );
205 void ScColBar::DrawInvert( long nDragPosP )
207 Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
208 Update();
209 Invert(aRect);
211 pViewData->GetView()->InvertVertical(eWhich,nDragPosP);
214 String ScColBar::GetDragHelp( long nVal )
216 long nTwips = (long) ( nVal / pViewData->GetPPTX() );
217 return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_WIDTH) );
220 sal_Bool ScColBar::IsLayoutRTL() // overloaded only for columns
222 return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
225 //==================================================================
227 ScRowBar::ScRowBar( Window* pParent, ScViewData* pData, ScVSplitPos eWhichPos,
228 ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
229 ScHeaderControl( pParent, pEng, MAXROW+1, true ),
230 pViewData( pData ),
231 eWhich( eWhichPos ),
232 pFuncSet( pFunc )
234 Show();
237 ScRowBar::~ScRowBar()
241 SCCOLROW ScRowBar::GetPos()
243 return pViewData->GetPosY(eWhich);
246 sal_uInt16 ScRowBar::GetEntrySize( SCCOLROW nEntryNo )
248 ScDocument* pDoc = pViewData->GetDocument();
249 SCTAB nTab = pViewData->GetTabNo();
250 SCROW nLastRow = -1;
251 if (pDoc->RowHidden(nEntryNo, nTab, NULL, &nLastRow))
252 return 0;
253 else
254 return (sal_uInt16) ScViewData::ToPixel( pDoc->GetOriginalHeight( nEntryNo,
255 nTab ), pViewData->GetPPTY() );
258 String ScRowBar::GetEntryText( SCCOLROW nEntryNo )
260 return String::CreateFromInt32( nEntryNo + 1 );
263 void ScRowBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
265 sal_uInt16 nSizeTwips;
266 ScSizeMode eMode = SC_SIZE_DIRECT;
267 if (nNewSize>0 && nNewSize<10) nNewSize=10; // (Pixel)
269 if ( nNewSize == HDR_SIZE_OPTIMUM )
271 nSizeTwips = 0;
272 eMode = SC_SIZE_OPTIMAL;
274 else
275 nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTY() );
277 ScMarkData& rMark = pViewData->GetMarkData();
279 SCCOLROW* pRanges = new SCCOLROW[MAXROW+1];
280 SCROW nRangeCnt = 0;
281 if ( rMark.IsRowMarked( nPos ) )
283 SCROW nStart = 0;
284 while (nStart<=MAXROW)
286 while (nStart<MAXROW && !rMark.IsRowMarked(nStart))
287 ++nStart;
288 if (rMark.IsRowMarked(nStart))
290 SCROW nEnd = nStart;
291 while (nEnd<MAXROW && rMark.IsRowMarked(nEnd))
292 ++nEnd;
293 if (!rMark.IsRowMarked(nEnd))
294 --nEnd;
295 pRanges[static_cast<size_t>(2*nRangeCnt) ] = nStart;
296 pRanges[static_cast<size_t>(2*nRangeCnt+1)] = nEnd;
297 ++nRangeCnt;
298 nStart = nEnd+1;
300 else
301 nStart = MAXROW+1;
304 else
306 pRanges[0] = nPos;
307 pRanges[1] = nPos;
308 nRangeCnt = 1;
311 pViewData->GetView()->SetWidthOrHeight( false, nRangeCnt, pRanges, eMode, nSizeTwips );
312 delete[] pRanges;
315 void ScRowBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
317 SCCOLROW nRange[2];
318 nRange[0] = nStart;
319 nRange[1] = nEnd;
320 pViewData->GetView()->SetWidthOrHeight( false, 1, nRange, SC_SIZE_DIRECT, 0 );
323 void ScRowBar::SetMarking( sal_Bool bSet )
325 pViewData->GetMarkData().SetMarking( bSet );
326 if (!bSet)
328 pViewData->GetView()->UpdateAutoFillMark();
332 void ScRowBar::SelectWindow()
334 ScTabViewShell* pViewSh = pViewData->GetViewShell();
336 pViewSh->SetActive(); // Appear and SetViewFrame
337 pViewSh->DrawDeselectAll();
339 ScSplitPos eActive = pViewData->GetActivePart();
340 if (eWhich==SC_SPLIT_TOP)
342 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_TOPLEFT;
343 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_TOPRIGHT;
345 else
347 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_BOTTOMLEFT;
348 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_BOTTOMRIGHT;
350 pViewSh->ActivatePart( eActive );
352 pFuncSet->SetColumn( false );
353 pFuncSet->SetWhich( eActive );
355 pViewSh->ActiveGrabFocus();
358 sal_Bool ScRowBar::IsDisabled()
360 ScModule* pScMod = SC_MOD();
361 return pScMod->IsFormulaMode() || pScMod->IsModalMode();
364 sal_Bool ScRowBar::ResizeAllowed()
366 return !pViewData->HasEditView( pViewData->GetActivePart() );
369 void ScRowBar::DrawInvert( long nDragPosP )
371 Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
372 Update();
373 Invert(aRect);
375 pViewData->GetView()->InvertHorizontal(eWhich,nDragPosP);
378 String ScRowBar::GetDragHelp( long nVal )
380 long nTwips = (long) ( nVal / pViewData->GetPPTY() );
381 return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_HEIGHT) );
384 SCROW ScRowBar::GetHiddenCount( SCROW nEntryNo ) // overloaded only for rows
386 ScDocument* pDoc = pViewData->GetDocument();
387 SCTAB nTab = pViewData->GetTabNo();
388 return pDoc->GetHiddenRowCount( nEntryNo, nTab );
391 sal_Bool ScRowBar::IsMirrored() // overloaded only for rows
393 return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */