fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / colrowba.cxx
blobd56a18a8a1ea27438541660db6094881f1dd8927
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"
31 #include <columnspanset.hxx>
33 // STATIC DATA -----------------------------------------------------------
35 static OUString lcl_MetricString( long nTwips, const OUString& rText )
37 if ( nTwips <= 0 )
38 return ScGlobal::GetRscString(STR_TIP_HIDE);
39 else
41 FieldUnit eUserMet = SC_MOD()->GetAppOptions().GetAppMetric();
43 sal_Int64 nUserVal = MetricField::ConvertValue( nTwips*100, 1, 2, FUNIT_TWIP, eUserMet );
45 OUString aStr = rText;
46 aStr += " ";
47 aStr += ScGlobal::pLocaleData->getNum( nUserVal, 2 );
48 aStr += " ";
49 aStr += SdrFormatter::GetUnitStr(eUserMet);
51 return aStr;
55 ScColBar::ScColBar( vcl::Window* pParent, ScViewData* pData, ScHSplitPos eWhichPos,
56 ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
57 ScHeaderControl( pParent, pEng, MAXCOL+1, false ),
58 pViewData( pData ),
59 eWhich( eWhichPos ),
60 pFuncSet( pFunc )
62 Show();
65 ScColBar::~ScColBar()
69 inline bool ScColBar::UseNumericHeader() const
71 return pViewData->GetDocument()->GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1;
74 SCCOLROW ScColBar::GetPos() const
76 return pViewData->GetPosX(eWhich);
79 sal_uInt16 ScColBar::GetEntrySize( SCCOLROW nEntryNo ) const
81 ScDocument* pDoc = pViewData->GetDocument();
82 SCTAB nTab = pViewData->GetTabNo();
83 if (pDoc->ColHidden(static_cast<SCCOL>(nEntryNo), nTab))
84 return 0;
85 else
86 return (sal_uInt16) ScViewData::ToPixel( pDoc->GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), pViewData->GetPPTX() );
89 OUString ScColBar::GetEntryText( SCCOLROW nEntryNo ) const
91 return UseNumericHeader()
92 ? OUString::number(nEntryNo + 1)
93 : ScColToAlpha( static_cast<SCCOL>(nEntryNo) );
96 void ScColBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
98 sal_uInt16 nSizeTwips;
99 ScSizeMode eMode = SC_SIZE_DIRECT;
100 if (nNewSize < 10) nNewSize = 10; // pixels
102 if ( nNewSize == HDR_SIZE_OPTIMUM )
104 nSizeTwips = STD_EXTRA_WIDTH;
105 eMode = SC_SIZE_OPTIMAL;
107 else
108 nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTX() );
110 ScMarkData& rMark = pViewData->GetMarkData();
112 std::vector<sc::ColRowSpan> aRanges;
113 if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) )
115 SCCOL nStart = 0;
116 while (nStart<=MAXCOL)
118 while (nStart<MAXCOL && !rMark.IsColumnMarked(nStart))
119 ++nStart;
120 if (rMark.IsColumnMarked(nStart))
122 SCCOL nEnd = nStart;
123 while (nEnd<MAXCOL && rMark.IsColumnMarked(nEnd))
124 ++nEnd;
125 if (!rMark.IsColumnMarked(nEnd))
126 --nEnd;
127 aRanges.push_back(sc::ColRowSpan(nStart,nEnd));
128 nStart = nEnd+1;
130 else
131 nStart = MAXCOL+1;
134 else
136 aRanges.push_back(sc::ColRowSpan(nPos,nPos));
139 pViewData->GetView()->SetWidthOrHeight(true, aRanges, eMode, nSizeTwips);
142 void ScColBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
144 std::vector<sc::ColRowSpan> aRanges(1, sc::ColRowSpan(nStart,nEnd));
145 pViewData->GetView()->SetWidthOrHeight(true, aRanges, SC_SIZE_DIRECT, 0);
148 void ScColBar::SetMarking( bool bSet )
150 pViewData->GetMarkData().SetMarking( bSet );
151 if (!bSet)
153 pViewData->GetView()->UpdateAutoFillMark();
157 void ScColBar::SelectWindow()
159 ScTabViewShell* pViewSh = pViewData->GetViewShell();
161 pViewSh->SetActive(); // Appear and SetViewFrame
162 pViewSh->DrawDeselectAll();
164 ScSplitPos eActive = pViewData->GetActivePart();
165 if (eWhich==SC_SPLIT_LEFT)
167 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_TOPLEFT;
168 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_BOTTOMLEFT;
170 else
172 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_TOPRIGHT;
173 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_BOTTOMRIGHT;
175 pViewSh->ActivatePart( eActive );
177 pFuncSet->SetColumn( true );
178 pFuncSet->SetWhich( eActive );
180 pViewSh->ActiveGrabFocus();
183 bool ScColBar::IsDisabled() const
185 ScModule* pScMod = SC_MOD();
186 return pScMod->IsFormulaMode() || pScMod->IsModalMode();
189 bool ScColBar::ResizeAllowed() const
191 return !pViewData->HasEditView( pViewData->GetActivePart() );
194 void ScColBar::DrawInvert( long nDragPosP )
196 Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
197 Update();
198 Invert(aRect);
200 pViewData->GetView()->InvertVertical(eWhich,nDragPosP);
203 OUString ScColBar::GetDragHelp( long nVal )
205 long nTwips = (long) ( nVal / pViewData->GetPPTX() );
206 return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_WIDTH) );
209 bool ScColBar::IsLayoutRTL() const // override only for columns
211 return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
214 ScRowBar::ScRowBar( vcl::Window* pParent, ScViewData* pData, ScVSplitPos eWhichPos,
215 ScHeaderFunctionSet* pFunc, ScHeaderSelectionEngine* pEng ) :
216 ScHeaderControl( pParent, pEng, MAXROW+1, true ),
217 pViewData( pData ),
218 eWhich( eWhichPos ),
219 pFuncSet( pFunc )
221 Show();
224 ScRowBar::~ScRowBar()
228 SCCOLROW ScRowBar::GetPos() const
230 return pViewData->GetPosY(eWhich);
233 sal_uInt16 ScRowBar::GetEntrySize( SCCOLROW nEntryNo ) const
235 ScDocument* pDoc = pViewData->GetDocument();
236 SCTAB nTab = pViewData->GetTabNo();
237 SCROW nLastRow = -1;
238 if (pDoc->RowHidden(nEntryNo, nTab, NULL, &nLastRow))
239 return 0;
240 else
241 return (sal_uInt16) ScViewData::ToPixel( pDoc->GetOriginalHeight( nEntryNo,
242 nTab ), pViewData->GetPPTY() );
245 OUString ScRowBar::GetEntryText( SCCOLROW nEntryNo ) const
247 return OUString::number( nEntryNo + 1 );
250 void ScRowBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
252 sal_uInt16 nSizeTwips;
253 ScSizeMode eMode = SC_SIZE_DIRECT;
254 if (nNewSize < 10) nNewSize = 10; // pixels
256 if ( nNewSize == HDR_SIZE_OPTIMUM )
258 nSizeTwips = 0;
259 eMode = SC_SIZE_OPTIMAL;
261 else
262 nSizeTwips = (sal_uInt16) ( nNewSize / pViewData->GetPPTY() );
264 ScMarkData& rMark = pViewData->GetMarkData();
266 std::vector<sc::ColRowSpan> aRanges;
267 if ( rMark.IsRowMarked( nPos ) )
269 SCROW nStart = 0;
270 while (nStart<=MAXROW)
272 while (nStart<MAXROW && !rMark.IsRowMarked(nStart))
273 ++nStart;
274 if (rMark.IsRowMarked(nStart))
276 SCROW nEnd = nStart;
277 while (nEnd<MAXROW && rMark.IsRowMarked(nEnd))
278 ++nEnd;
279 if (!rMark.IsRowMarked(nEnd))
280 --nEnd;
281 aRanges.push_back(sc::ColRowSpan(nStart,nEnd));
282 nStart = nEnd+1;
284 else
285 nStart = MAXROW+1;
288 else
290 aRanges.push_back(sc::ColRowSpan(nPos,nPos));
293 pViewData->GetView()->SetWidthOrHeight(false, aRanges, eMode, nSizeTwips);
296 void ScRowBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
298 std::vector<sc::ColRowSpan> aRange(1, sc::ColRowSpan(nStart,nEnd));
299 pViewData->GetView()->SetWidthOrHeight(false, aRange, SC_SIZE_DIRECT, 0);
302 void ScRowBar::SetMarking( bool bSet )
304 pViewData->GetMarkData().SetMarking( bSet );
305 if (!bSet)
307 pViewData->GetView()->UpdateAutoFillMark();
311 void ScRowBar::SelectWindow()
313 ScTabViewShell* pViewSh = pViewData->GetViewShell();
315 pViewSh->SetActive(); // Appear and SetViewFrame
316 pViewSh->DrawDeselectAll();
318 ScSplitPos eActive = pViewData->GetActivePart();
319 if (eWhich==SC_SPLIT_TOP)
321 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_TOPLEFT;
322 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_TOPRIGHT;
324 else
326 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_BOTTOMLEFT;
327 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_BOTTOMRIGHT;
329 pViewSh->ActivatePart( eActive );
331 pFuncSet->SetColumn( false );
332 pFuncSet->SetWhich( eActive );
334 pViewSh->ActiveGrabFocus();
337 bool ScRowBar::IsDisabled() const
339 ScModule* pScMod = SC_MOD();
340 return pScMod->IsFormulaMode() || pScMod->IsModalMode();
343 bool ScRowBar::ResizeAllowed() const
345 return !pViewData->HasEditView( pViewData->GetActivePart() );
348 void ScRowBar::DrawInvert( long nDragPosP )
350 Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
351 Update();
352 Invert(aRect);
354 pViewData->GetView()->InvertHorizontal(eWhich,nDragPosP);
357 OUString ScRowBar::GetDragHelp( long nVal )
359 long nTwips = (long) ( nVal / pViewData->GetPPTY() );
360 return lcl_MetricString( nTwips, ScGlobal::GetRscString(STR_TIP_HEIGHT) );
363 SCROW ScRowBar::GetHiddenCount( SCROW nEntryNo ) const // override only for rows
365 ScDocument* pDoc = pViewData->GetDocument();
366 SCTAB nTab = pViewData->GetTabNo();
367 return pDoc->GetHiddenRowCount( nEntryNo, nTab );
370 bool ScRowBar::IsMirrored() const // override only for rows
372 return pViewData->GetDocument()->IsLayoutRTL( pViewData->GetTabNo() );
375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */