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 <sal/config.h>
22 #include <string_view>
24 #include <unotools/localedatawrapper.hxx>
25 #include <vcl/fieldvalues.hxx>
27 #include <colrowba.hxx>
28 #include <document.hxx>
30 #include <tabvwsh.hxx>
31 #include <appoptio.hxx>
32 #include <globstr.hrc>
33 #include <scresid.hxx>
34 #include <markdata.hxx>
35 #include <tabview.hxx>
36 #include <columnspanset.hxx>
38 static OUString
lcl_MetricString( tools::Long nTwips
, std::u16string_view rText
)
41 return ScResId(STR_TIP_HIDE
);
44 FieldUnit eUserMet
= ScModule::get()->GetAppOptions().GetAppMetric();
46 sal_Int64 nUserVal
= vcl::ConvertValue( nTwips
*100, 1, 2, FieldUnit::TWIP
, eUserMet
);
48 OUString aStr
= OUString::Concat(rText
) + " "
49 + ScGlobal::getLocaleData().getNum( nUserVal
, 2 )
50 + " " + SdrFormatter::GetUnitStr(eUserMet
);
55 ScColBar::ScColBar( vcl::Window
* pParent
, ScHSplitPos eWhich
,
56 ScHeaderFunctionSet
* pFuncSet
, ScHeaderSelectionEngine
* pEng
,
58 ScHeaderControl( pParent
, pEng
, pTab
->GetViewData().GetDocument().MaxCol()+1, false, pTab
),
69 SCCOLROW
ScColBar::GetPos() const
71 return pTabView
->GetViewData().GetPosX(meWhich
);
74 sal_uInt16
ScColBar::GetEntrySize( SCCOLROW nEntryNo
) const
76 const ScViewData
& rViewData
= pTabView
->GetViewData();
77 ScDocument
& rDoc
= rViewData
.GetDocument();
78 SCTAB nTab
= rViewData
.GetTabNo();
79 if (rDoc
.ColHidden(static_cast<SCCOL
>(nEntryNo
), nTab
))
82 return static_cast<sal_uInt16
>(ScViewData::ToPixel( rDoc
.GetColWidth( static_cast<SCCOL
>(nEntryNo
), nTab
), rViewData
.GetPPTX() ));
85 OUString
ScColBar::GetEntryText( SCCOLROW nEntryNo
) const
87 return pTabView
->GetViewData().GetDocument().GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1
88 ? OUString::number(nEntryNo
+ 1)
89 : ScColToAlpha( static_cast<SCCOL
>(nEntryNo
) );
92 void ScColBar::SetEntrySize( SCCOLROW nPos
, sal_uInt16 nNewSize
)
94 const ScViewData
& rViewData
= pTabView
->GetViewData();
95 sal_uInt16 nSizeTwips
;
96 ScSizeMode eMode
= SC_SIZE_DIRECT
;
97 if (nNewSize
< 10) nNewSize
= 10; // pixels
99 if ( nNewSize
== HDR_SIZE_OPTIMUM
)
101 nSizeTwips
= STD_EXTRA_WIDTH
;
102 eMode
= SC_SIZE_OPTIMAL
;
105 nSizeTwips
= static_cast<sal_uInt16
>( nNewSize
/ rViewData
.GetPPTX() );
107 const ScMarkData
& rMark
= rViewData
.GetMarkData();
109 std::vector
<sc::ColRowSpan
> aRanges
;
110 if ( rMark
.IsColumnMarked( static_cast<SCCOL
>(nPos
) ) )
112 ScDocument
& rDoc
= rViewData
.GetDocument();
114 while (nStart
<=rDoc
.MaxCol())
116 while (nStart
<rDoc
.MaxCol() && !rMark
.IsColumnMarked(nStart
))
118 if (rMark
.IsColumnMarked(nStart
))
121 while (nEnd
<rDoc
.MaxCol() && rMark
.IsColumnMarked(nEnd
))
123 if (!rMark
.IsColumnMarked(nEnd
))
125 aRanges
.emplace_back(nStart
,nEnd
);
129 nStart
= rDoc
.MaxCol()+1;
134 aRanges
.emplace_back(nPos
,nPos
);
137 rViewData
.GetView()->SetWidthOrHeight(true, aRanges
, eMode
, nSizeTwips
);
140 void ScColBar::HideEntries( SCCOLROW nStart
, SCCOLROW nEnd
)
142 std::vector
<sc::ColRowSpan
> aRanges(1, sc::ColRowSpan(nStart
,nEnd
));
143 pTabView
->GetViewData().GetView()->SetWidthOrHeight(true, aRanges
, SC_SIZE_DIRECT
, 0);
146 void ScColBar::SetMarking( bool bSet
)
148 pTabView
->GetViewData().GetMarkData().SetMarking( bSet
);
151 pTabView
->GetViewData().GetView()->UpdateAutoFillMark();
155 void ScColBar::SelectWindow()
157 const ScViewData
& rViewData
= pTabView
->GetViewData();
158 ScTabViewShell
* pViewSh
= rViewData
.GetViewShell();
160 pViewSh
->SetActive(); // Appear and SetViewFrame
161 pViewSh
->DrawDeselectAll();
163 ScSplitPos eActive
= rViewData
.GetActivePart();
164 if (meWhich
==SC_SPLIT_LEFT
)
166 if (eActive
==SC_SPLIT_TOPRIGHT
) eActive
=SC_SPLIT_TOPLEFT
;
167 if (eActive
==SC_SPLIT_BOTTOMRIGHT
) eActive
=SC_SPLIT_BOTTOMLEFT
;
171 if (eActive
==SC_SPLIT_TOPLEFT
) eActive
=SC_SPLIT_TOPRIGHT
;
172 if (eActive
==SC_SPLIT_BOTTOMLEFT
) eActive
=SC_SPLIT_BOTTOMRIGHT
;
174 pViewSh
->ActivatePart( eActive
);
176 mpFuncSet
->SetColumn( true );
177 mpFuncSet
->SetWhich( eActive
);
179 pViewSh
->ActiveGrabFocus();
182 bool ScColBar::IsDisabled() const
184 return ScModule::get()->IsModalMode();
187 bool ScColBar::ResizeAllowed() const
189 const ScViewData
& rViewData
= pTabView
->GetViewData();
190 return !rViewData
.HasEditView( rViewData
.GetActivePart() );
193 void ScColBar::DrawInvert( tools::Long nDragPosP
)
195 tools::Rectangle
aRect( nDragPosP
,0, nDragPosP
+HDR_SLIDERSIZE
-1,GetOutputSizePixel().Width()-1 );
197 GetOutDev()->Invert(aRect
);
199 pTabView
->GetViewData().GetView()->InvertVertical(meWhich
,nDragPosP
);
202 OUString
ScColBar::GetDragHelp( tools::Long nVal
)
204 tools::Long nTwips
= static_cast<tools::Long
>( nVal
/ pTabView
->GetViewData().GetPPTX() );
205 return lcl_MetricString( nTwips
, ScResId(STR_TIP_WIDTH
) );
208 bool ScColBar::IsLayoutRTL() const // override only for columns
210 const ScViewData
& rViewData
= pTabView
->GetViewData();
211 return rViewData
.GetDocument().IsLayoutRTL( rViewData
.GetTabNo() );
214 ScRowBar::ScRowBar( vcl::Window
* pParent
, ScVSplitPos eWhich
,
215 ScHeaderFunctionSet
* pFuncSet
, ScHeaderSelectionEngine
* pEng
,
217 ScHeaderControl( pParent
, pEng
, pTab
->GetViewData().GetDocument().MaxRow()+1, true, pTab
),
219 mpFuncSet( pFuncSet
)
224 ScRowBar::~ScRowBar()
228 SCCOLROW
ScRowBar::GetPos() const
230 return pTabView
->GetViewData().GetPosY(meWhich
);
233 sal_uInt16
ScRowBar::GetEntrySize( SCCOLROW nEntryNo
) const
235 const ScViewData
& rViewData
= pTabView
->GetViewData();
236 ScDocument
& rDoc
= rViewData
.GetDocument();
237 SCTAB nTab
= rViewData
.GetTabNo();
239 if (rDoc
.RowHidden(nEntryNo
, nTab
, nullptr, &nLastRow
))
242 return static_cast<sal_uInt16
>(ScViewData::ToPixel( rDoc
.GetOriginalHeight( nEntryNo
,
243 nTab
), rViewData
.GetPPTY() ));
246 OUString
ScRowBar::GetEntryText( SCCOLROW nEntryNo
) const
248 return OUString::number( nEntryNo
+ 1 );
251 void ScRowBar::SetEntrySize( SCCOLROW nPos
, sal_uInt16 nNewSize
)
253 const ScViewData
& rViewData
= pTabView
->GetViewData();
254 sal_uInt16 nSizeTwips
;
255 ScSizeMode eMode
= SC_SIZE_DIRECT
;
256 if (nNewSize
< 10) nNewSize
= 10; // pixels
258 if ( nNewSize
== HDR_SIZE_OPTIMUM
)
261 eMode
= SC_SIZE_OPTIMAL
;
264 nSizeTwips
= static_cast<sal_uInt16
>( nNewSize
/ rViewData
.GetPPTY() );
266 const ScMarkData
& rMark
= rViewData
.GetMarkData();
268 std::vector
<sc::ColRowSpan
> aRanges
;
269 if ( rMark
.IsRowMarked( nPos
) )
271 ScDocument
& rDoc
= rViewData
.GetDocument();
273 while (nStart
<=rDoc
.MaxRow())
275 while (nStart
<rDoc
.MaxRow() && !rMark
.IsRowMarked(nStart
))
277 if (rMark
.IsRowMarked(nStart
))
280 while (nEnd
<rDoc
.MaxRow() && rMark
.IsRowMarked(nEnd
))
282 if (!rMark
.IsRowMarked(nEnd
))
284 aRanges
.emplace_back(nStart
,nEnd
);
288 nStart
= rDoc
.MaxRow()+1;
293 aRanges
.emplace_back(nPos
,nPos
);
296 rViewData
.GetView()->SetWidthOrHeight(false, aRanges
, eMode
, nSizeTwips
);
299 void ScRowBar::HideEntries( SCCOLROW nStart
, SCCOLROW nEnd
)
301 std::vector
<sc::ColRowSpan
> aRange(1, sc::ColRowSpan(nStart
,nEnd
));
302 pTabView
->GetViewData().GetView()->SetWidthOrHeight(false, aRange
, SC_SIZE_DIRECT
, 0);
305 void ScRowBar::SetMarking( bool bSet
)
307 pTabView
->GetViewData().GetMarkData().SetMarking( bSet
);
310 pTabView
->GetViewData().GetView()->UpdateAutoFillMark();
314 void ScRowBar::SelectWindow()
316 const ScViewData
& rViewData
= pTabView
->GetViewData();
317 ScTabViewShell
* pViewSh
= rViewData
.GetViewShell();
319 pViewSh
->SetActive(); // Appear and SetViewFrame
320 pViewSh
->DrawDeselectAll();
322 ScSplitPos eActive
= rViewData
.GetActivePart();
323 if (meWhich
==SC_SPLIT_TOP
)
325 if (eActive
==SC_SPLIT_BOTTOMLEFT
) eActive
=SC_SPLIT_TOPLEFT
;
326 if (eActive
==SC_SPLIT_BOTTOMRIGHT
) eActive
=SC_SPLIT_TOPRIGHT
;
330 if (eActive
==SC_SPLIT_TOPLEFT
) eActive
=SC_SPLIT_BOTTOMLEFT
;
331 if (eActive
==SC_SPLIT_TOPRIGHT
) eActive
=SC_SPLIT_BOTTOMRIGHT
;
333 pViewSh
->ActivatePart( eActive
);
335 mpFuncSet
->SetColumn( false );
336 mpFuncSet
->SetWhich( eActive
);
338 pViewSh
->ActiveGrabFocus();
341 bool ScRowBar::IsDisabled() const
343 return ScModule::get()->IsModalMode();
346 bool ScRowBar::ResizeAllowed() const
348 const ScViewData
& rViewData
= pTabView
->GetViewData();
349 return !rViewData
.HasEditView( rViewData
.GetActivePart() );
352 void ScRowBar::DrawInvert( tools::Long nDragPosP
)
354 tools::Rectangle
aRect( 0,nDragPosP
, GetOutputSizePixel().Width()-1,nDragPosP
+HDR_SLIDERSIZE
-1 );
356 GetOutDev()->Invert(aRect
);
358 pTabView
->GetViewData().GetView()->InvertHorizontal(meWhich
,nDragPosP
);
361 OUString
ScRowBar::GetDragHelp( tools::Long nVal
)
363 tools::Long nTwips
= static_cast<tools::Long
>( nVal
/ pTabView
->GetViewData().GetPPTY() );
364 return lcl_MetricString( nTwips
, ScResId(STR_TIP_HEIGHT
) );
367 SCCOLROW
ScRowBar::GetHiddenCount( SCCOLROW nEntryNo
) const // override only for rows
369 const ScViewData
& rViewData
= pTabView
->GetViewData();
370 ScDocument
& rDoc
= rViewData
.GetDocument();
371 SCTAB nTab
= rViewData
.GetTabNo();
372 return rDoc
.GetHiddenRowCount( nEntryNo
, nTab
);
375 bool ScRowBar::IsMirrored() const // override only for rows
377 const ScViewData
& rViewData
= pTabView
->GetViewData();
378 return rViewData
.GetDocument().IsLayoutRTL( rViewData
.GetTabNo() );
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */