1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
26 #include "tabvwsh.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
)
38 return ScGlobal::GetRscString(STR_TIP_HIDE
);
41 FieldUnit eUserMet
= SC_MOD()->GetAppOptions().GetAppMetric();
43 sal_Int64 nUserVal
= MetricField::ConvertValue( nTwips
*100, 1, 2, FUNIT_TWIP
, eUserMet
);
45 OUString aStr
= rText
;
47 aStr
+= ScGlobal::pLocaleData
->getNum( nUserVal
, 2 );
49 aStr
+= SdrFormatter::GetUnitStr(eUserMet
);
55 ScColBar::ScColBar( vcl::Window
* pParent
, ScViewData
* pData
, ScHSplitPos eWhichPos
,
56 ScHeaderFunctionSet
* pFunc
, ScHeaderSelectionEngine
* pEng
) :
57 ScHeaderControl( pParent
, pEng
, MAXCOL
+1, false ),
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
))
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
;
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
) ) )
116 while (nStart
<=MAXCOL
)
118 while (nStart
<MAXCOL
&& !rMark
.IsColumnMarked(nStart
))
120 if (rMark
.IsColumnMarked(nStart
))
123 while (nEnd
<MAXCOL
&& rMark
.IsColumnMarked(nEnd
))
125 if (!rMark
.IsColumnMarked(nEnd
))
127 aRanges
.push_back(sc::ColRowSpan(nStart
,nEnd
));
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
);
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
;
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 );
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 ),
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();
238 if (pDoc
->RowHidden(nEntryNo
, nTab
, NULL
, &nLastRow
))
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
)
259 eMode
= SC_SIZE_OPTIMAL
;
262 nSizeTwips
= (sal_uInt16
) ( nNewSize
/ pViewData
->GetPPTY() );
264 ScMarkData
& rMark
= pViewData
->GetMarkData();
266 std::vector
<sc::ColRowSpan
> aRanges
;
267 if ( rMark
.IsRowMarked( nPos
) )
270 while (nStart
<=MAXROW
)
272 while (nStart
<MAXROW
&& !rMark
.IsRowMarked(nStart
))
274 if (rMark
.IsRowMarked(nStart
))
277 while (nEnd
<MAXROW
&& rMark
.IsRowMarked(nEnd
))
279 if (!rMark
.IsRowMarked(nEnd
))
281 aRanges
.push_back(sc::ColRowSpan(nStart
,nEnd
));
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
);
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
;
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 );
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: */