LibreOffice Module sc (master) 1
colrowba.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <string_view>
23
25#include <vcl/fieldvalues.hxx>
26
27#include <colrowba.hxx>
28#include <document.hxx>
29#include <scmod.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>
37
38static OUString lcl_MetricString( tools::Long nTwips, std::u16string_view rText )
39{
40 if ( nTwips <= 0 )
41 return ScResId(STR_TIP_HIDE);
42 else
43 {
44 FieldUnit eUserMet = SC_MOD()->GetAppOptions().GetAppMetric();
45
46 sal_Int64 nUserVal = vcl::ConvertValue( nTwips*100, 1, 2, FieldUnit::TWIP, eUserMet );
47
48 OUString aStr = OUString::Concat(rText) + " "
49 + ScGlobal::getLocaleData().getNum( nUserVal, 2 )
50 + " " + SdrFormatter::GetUnitStr(eUserMet);
51 return aStr;
52 }
53}
54
57 ScTabView* pTab ) :
58 ScHeaderControl( pParent, pEng, pTab->GetViewData().GetDocument().MaxCol()+1, false, pTab ),
59 meWhich( eWhich ),
60 mpFuncSet( pFuncSet )
61{
62 Show();
63}
64
66{
67}
68
70{
72}
73
74sal_uInt16 ScColBar::GetEntrySize( SCCOLROW nEntryNo ) const
75{
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))
80 return 0;
81 else
82 return static_cast<sal_uInt16>(ScViewData::ToPixel( rDoc.GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), rViewData.GetPPTX() ));
83}
84
85OUString ScColBar::GetEntryText( SCCOLROW nEntryNo ) const
86{
88 ? OUString::number(nEntryNo + 1)
89 : ScColToAlpha( static_cast<SCCOL>(nEntryNo) );
90}
91
92void ScColBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
93{
94 const ScViewData& rViewData = pTabView->GetViewData();
95 sal_uInt16 nSizeTwips;
97 if (nNewSize < 10) nNewSize = 10; // pixels
98
99 if ( nNewSize == HDR_SIZE_OPTIMUM )
100 {
101 nSizeTwips = STD_EXTRA_WIDTH;
103 }
104 else
105 nSizeTwips = static_cast<sal_uInt16>( nNewSize / rViewData.GetPPTX() );
106
107 const ScMarkData& rMark = rViewData.GetMarkData();
108
109 std::vector<sc::ColRowSpan> aRanges;
110 if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) )
111 {
112 ScDocument& rDoc = rViewData.GetDocument();
113 SCCOL nStart = 0;
114 while (nStart<=rDoc.MaxCol())
115 {
116 while (nStart<rDoc.MaxCol() && !rMark.IsColumnMarked(nStart))
117 ++nStart;
118 if (rMark.IsColumnMarked(nStart))
119 {
120 SCCOL nEnd = nStart;
121 while (nEnd<rDoc.MaxCol() && rMark.IsColumnMarked(nEnd))
122 ++nEnd;
123 if (!rMark.IsColumnMarked(nEnd))
124 --nEnd;
125 aRanges.emplace_back(nStart,nEnd);
126 nStart = nEnd+1;
127 }
128 else
129 nStart = rDoc.MaxCol()+1;
130 }
131 }
132 else
133 {
134 aRanges.emplace_back(nPos,nPos);
135 }
136
137 rViewData.GetView()->SetWidthOrHeight(true, aRanges, eMode, nSizeTwips);
138}
139
141{
142 std::vector<sc::ColRowSpan> aRanges(1, sc::ColRowSpan(nStart,nEnd));
144}
145
146void ScColBar::SetMarking( bool bSet )
147{
149 if (!bSet)
150 {
152 }
153}
154
156{
157 const ScViewData& rViewData = pTabView->GetViewData();
158 ScTabViewShell* pViewSh = rViewData.GetViewShell();
159
160 pViewSh->SetActive(); // Appear and SetViewFrame
161 pViewSh->DrawDeselectAll();
162
163 ScSplitPos eActive = rViewData.GetActivePart();
165 {
166 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_TOPLEFT;
167 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_BOTTOMLEFT;
168 }
169 else
170 {
171 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_TOPRIGHT;
172 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_BOTTOMRIGHT;
173 }
174 pViewSh->ActivatePart( eActive );
175
176 mpFuncSet->SetColumn( true );
177 mpFuncSet->SetWhich( eActive );
178
179 pViewSh->ActiveGrabFocus();
180}
181
183{
184 ScModule* pScMod = SC_MOD();
185 return pScMod->IsModalMode();
186}
187
189{
190 const ScViewData& rViewData = pTabView->GetViewData();
191 return !rViewData.HasEditView( rViewData.GetActivePart() );
192}
193
195{
196 tools::Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
198 GetOutDev()->Invert(aRect);
199
201}
202
204{
205 tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTX() );
206 return lcl_MetricString( nTwips, ScResId(STR_TIP_WIDTH) );
207}
208
209bool ScColBar::IsLayoutRTL() const // override only for columns
210{
211 const ScViewData& rViewData = pTabView->GetViewData();
212 return rViewData.GetDocument().IsLayoutRTL( rViewData.GetTabNo() );
213}
214
217 ScTabView* pTab ) :
218 ScHeaderControl( pParent, pEng, pTab->GetViewData().GetDocument().MaxRow()+1, true, pTab ),
219 meWhich( eWhich ),
220 mpFuncSet( pFuncSet )
221{
222 Show();
223}
224
226{
227}
228
230{
232}
233
234sal_uInt16 ScRowBar::GetEntrySize( SCCOLROW nEntryNo ) const
235{
236 const ScViewData& rViewData = pTabView->GetViewData();
237 ScDocument& rDoc = rViewData.GetDocument();
238 SCTAB nTab = rViewData.GetTabNo();
239 SCROW nLastRow = -1;
240 if (rDoc.RowHidden(nEntryNo, nTab, nullptr, &nLastRow))
241 return 0;
242 else
243 return static_cast<sal_uInt16>(ScViewData::ToPixel( rDoc.GetOriginalHeight( nEntryNo,
244 nTab ), rViewData.GetPPTY() ));
245}
246
247OUString ScRowBar::GetEntryText( SCCOLROW nEntryNo ) const
248{
249 return OUString::number( nEntryNo + 1 );
250}
251
252void ScRowBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
253{
254 const ScViewData& rViewData = pTabView->GetViewData();
255 sal_uInt16 nSizeTwips;
257 if (nNewSize < 10) nNewSize = 10; // pixels
258
259 if ( nNewSize == HDR_SIZE_OPTIMUM )
260 {
261 nSizeTwips = 0;
263 }
264 else
265 nSizeTwips = static_cast<sal_uInt16>( nNewSize / rViewData.GetPPTY() );
266
267 const ScMarkData& rMark = rViewData.GetMarkData();
268
269 std::vector<sc::ColRowSpan> aRanges;
270 if ( rMark.IsRowMarked( nPos ) )
271 {
272 ScDocument& rDoc = rViewData.GetDocument();
273 SCROW nStart = 0;
274 while (nStart<=rDoc.MaxRow())
275 {
276 while (nStart<rDoc.MaxRow() && !rMark.IsRowMarked(nStart))
277 ++nStart;
278 if (rMark.IsRowMarked(nStart))
279 {
280 SCROW nEnd = nStart;
281 while (nEnd<rDoc.MaxRow() && rMark.IsRowMarked(nEnd))
282 ++nEnd;
283 if (!rMark.IsRowMarked(nEnd))
284 --nEnd;
285 aRanges.emplace_back(nStart,nEnd);
286 nStart = nEnd+1;
287 }
288 else
289 nStart = rDoc.MaxRow()+1;
290 }
291 }
292 else
293 {
294 aRanges.emplace_back(nPos,nPos);
295 }
296
297 rViewData.GetView()->SetWidthOrHeight(false, aRanges, eMode, nSizeTwips);
298}
299
301{
302 std::vector<sc::ColRowSpan> aRange(1, sc::ColRowSpan(nStart,nEnd));
304}
305
306void ScRowBar::SetMarking( bool bSet )
307{
309 if (!bSet)
310 {
312 }
313}
314
316{
317 const ScViewData& rViewData = pTabView->GetViewData();
318 ScTabViewShell* pViewSh = rViewData.GetViewShell();
319
320 pViewSh->SetActive(); // Appear and SetViewFrame
321 pViewSh->DrawDeselectAll();
322
323 ScSplitPos eActive = rViewData.GetActivePart();
325 {
326 if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_TOPLEFT;
327 if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_TOPRIGHT;
328 }
329 else
330 {
331 if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_BOTTOMLEFT;
332 if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_BOTTOMRIGHT;
333 }
334 pViewSh->ActivatePart( eActive );
335
336 mpFuncSet->SetColumn( false );
337 mpFuncSet->SetWhich( eActive );
338
339 pViewSh->ActiveGrabFocus();
340}
341
343{
344 ScModule* pScMod = SC_MOD();
345 return pScMod->IsModalMode();
346}
347
349{
350 const ScViewData& rViewData = pTabView->GetViewData();
351 return !rViewData.HasEditView( rViewData.GetActivePart() );
352}
353
355{
356 tools::Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
358 GetOutDev()->Invert(aRect);
359
361}
362
364{
365 tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTY() );
366 return lcl_MetricString( nTwips, ScResId(STR_TIP_HEIGHT) );
367}
368
369SCCOLROW ScRowBar::GetHiddenCount( SCCOLROW nEntryNo ) const // override only for rows
370{
371 const ScViewData& rViewData = pTabView->GetViewData();
372 ScDocument& rDoc = rViewData.GetDocument();
373 SCTAB nTab = rViewData.GetTabNo();
374 return rDoc.GetHiddenRowCount( nEntryNo, nTab );
375}
376
377bool ScRowBar::IsMirrored() const // override only for rows
378{
379 const ScViewData& rViewData = pTabView->GetViewData();
380 return rViewData.GetDocument().IsLayoutRTL( rViewData.GetTabNo() );
381}
382
383/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ScColToAlpha(OUStringBuffer &rBuf, SCCOL nCol)
append alpha representation of column to buffer
Definition: address.cxx:1884
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
void Invert(const tools::Rectangle &rRect, InvertFlags nFlags=InvertFlags::NONE)
virtual void HideEntries(SCCOLROW nStart, SCCOLROW nEnd) override
Definition: colrowba.cxx:140
ScHSplitPos meWhich
Definition: colrowba.hxx:31
virtual OUString GetDragHelp(tools::Long nVal) override
Definition: colrowba.cxx:203
virtual bool ResizeAllowed() const override
Definition: colrowba.cxx:188
virtual void SelectWindow() override
Definition: colrowba.cxx:155
virtual OUString GetEntryText(SCCOLROW nEntryNo) const override
Definition: colrowba.cxx:85
virtual SCCOLROW GetPos() const override
Definition: colrowba.cxx:69
ScColBar(vcl::Window *pParent, ScHSplitPos eWhich, ScHeaderFunctionSet *pFuncSet, ScHeaderSelectionEngine *pEng, ScTabView *pTab)
Definition: colrowba.cxx:55
virtual sal_uInt16 GetEntrySize(SCCOLROW nEntryNo) const override
Definition: colrowba.cxx:74
ScHeaderFunctionSet * mpFuncSet
Definition: colrowba.hxx:32
virtual void SetEntrySize(SCCOLROW nPos, sal_uInt16 nNewSize) override
Definition: colrowba.cxx:92
virtual void DrawInvert(tools::Long nDragPos) override
Definition: colrowba.cxx:194
virtual ~ScColBar() override
Definition: colrowba.cxx:65
virtual bool IsLayoutRTL() const override
Definition: colrowba.cxx:209
virtual void SetMarking(bool bSet) override
Definition: colrowba.cxx:146
virtual bool IsDisabled() const override
Definition: colrowba.cxx:182
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4122
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:492
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC sal_uInt16 GetOriginalHeight(SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4153
SCROW GetHiddenRowCount(SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4216
SC_DLLPUBLIC bool RowHidden(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: document.cxx:4416
SC_DLLPUBLIC bool ColHidden(SCCOL nCol, SCTAB nTab, SCCOL *pFirstCol=nullptr, SCCOL *pLastCol=nullptr) const
Definition: document.cxx:4430
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:974
static SC_DLLPUBLIC const LocaleDataWrapper & getLocaleData()
Definition: global.cxx:1055
ScTabView * pTabView
Definition: hdrcont.hxx:79
void SetColumn(bool bSet)
Definition: select.cxx:805
void SetWhich(ScSplitPos eNew)
Definition: select.cxx:810
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void SetMarking(bool bFlag)
Definition: markdata.hxx:102
bool IsColumnMarked(SCCOL nCol) const
Definition: markdata.cxx:287
bool IsRowMarked(SCROW nRow) const
Definition: markdata.cxx:303
bool IsModalMode(SfxObjectShell *pDocSh=nullptr)
Definition: scmod.cxx:1597
virtual sal_uInt16 GetEntrySize(SCCOLROW nEntryNo) const override
Definition: colrowba.cxx:234
virtual OUString GetDragHelp(tools::Long nVal) override
Definition: colrowba.cxx:363
ScVSplitPos meWhich
Definition: colrowba.hxx:61
virtual void HideEntries(SCCOLROW nStart, SCCOLROW nEnd) override
Definition: colrowba.cxx:300
virtual OUString GetEntryText(SCCOLROW nEntryNo) const override
Definition: colrowba.cxx:247
virtual void SelectWindow() override
Definition: colrowba.cxx:315
virtual bool ResizeAllowed() const override
Definition: colrowba.cxx:348
virtual bool IsMirrored() const override
Definition: colrowba.cxx:377
virtual void SetMarking(bool bSet) override
Definition: colrowba.cxx:306
virtual SCCOLROW GetHiddenCount(SCCOLROW nEntryNo) const override
Definition: colrowba.cxx:369
ScHeaderFunctionSet * mpFuncSet
Definition: colrowba.hxx:62
virtual void SetEntrySize(SCCOLROW nPos, sal_uInt16 nNewSize) override
Definition: colrowba.cxx:252
virtual void DrawInvert(tools::Long nDragPos) override
Definition: colrowba.cxx:354
virtual ~ScRowBar() override
Definition: colrowba.cxx:225
virtual bool IsDisabled() const override
Definition: colrowba.cxx:342
virtual SCCOLROW GetPos() const override
Definition: colrowba.cxx:229
ScRowBar(vcl::Window *pParent, ScVSplitPos eWhich, ScHeaderFunctionSet *pFuncSet, ScHeaderSelectionEngine *pEng, ScTabView *pTab)
Definition: colrowba.cxx:215
void SetActive()
Definition: tabvwsh4.cxx:276
void UpdateAutoFillMark(bool bFromPaste=false)
Definition: tabview3.cxx:187
void InvertHorizontal(ScVSplitPos eWhich, tools::Long nDragPos)
Definition: tabview4.cxx:468
void InvertVertical(ScHSplitPos eWhich, tools::Long nDragPos)
Definition: tabview4.cxx:483
ScViewData & GetViewData()
Definition: tabview.hxx:344
void ActivatePart(ScSplitPos eWhich)
Definition: tabview3.cxx:2907
void DrawDeselectAll()
Definition: tabview5.cxx:385
void ActiveGrabFocus()
Definition: tabview.cxx:892
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3146
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
SCROW GetPosY(ScVSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1417
double GetPPTY() const
Definition: viewdata.hxx:469
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
static tools::Long ToPixel(sal_uInt16 nTwips, double nFactor)
Definition: viewdata.hxx:700
ScDBFunc * GetView() const
Definition: viewdata.cxx:864
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
double GetPPTX() const
Definition: viewdata.hxx:468
bool HasEditView(ScSplitPos eWhich) const
Definition: viewdata.hxx:582
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1403
void SetWidthOrHeight(bool bWidth, const std::vector< sc::ColRowSpan > &rRanges, ScSizeMode eMode, sal_uInt16 nSizeTwips, bool bRecord=true, const ScMarkData *pMarkData=nullptr)
Definition: viewfunc.cxx:2159
static OUString GetUnitStr(MapUnit eUnit)
void PaintImmediately()
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
::OutputDevice const * GetOutDev() const
Size GetOutputSizePixel() const
static OUString lcl_MetricString(tools::Long nTwips, std::u16string_view rText)
Definition: colrowba.cxx:38
FieldUnit
ScSizeMode
Definition: global.hxx:351
@ SC_SIZE_DIRECT
Definition: global.hxx:352
@ SC_SIZE_OPTIMAL
Definition: global.hxx:353
constexpr sal_Int32 STD_EXTRA_WIDTH
Definition: global.hxx:88
#define HDR_SIZE_OPTIMUM
Definition: hdrcont.hxx:26
#define HDR_SLIDERSIZE
Definition: hdrcont.hxx:29
Mode eMode
sal_uInt16 nPos
aStr
long Long
sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
#define SC_MOD()
Definition: scmod.hxx:247
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
ScSplitPos
Definition: viewdata.hxx:44
@ SC_SPLIT_BOTTOMRIGHT
Definition: viewdata.hxx:44
@ SC_SPLIT_TOPLEFT
Definition: viewdata.hxx:44
@ SC_SPLIT_BOTTOMLEFT
Definition: viewdata.hxx:44
@ SC_SPLIT_TOPRIGHT
Definition: viewdata.hxx:44
ScHSplitPos
Definition: viewdata.hxx:45
@ SC_SPLIT_LEFT
Definition: viewdata.hxx:45
ScVSplitPos
Definition: viewdata.hxx:46
@ SC_SPLIT_TOP
Definition: viewdata.hxx:46