/src/libreoffice/sc/source/ui/view/colrowba.cxx
Line | Count | Source |
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 | | |
24 | | #include <unotools/localedatawrapper.hxx> |
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 | | |
38 | | static OUString lcl_MetricString( tools::Long nTwips, std::u16string_view rText ) |
39 | 0 | { |
40 | 0 | if ( nTwips <= 0 ) |
41 | 0 | return ScResId(STR_TIP_HIDE); |
42 | 0 | else |
43 | 0 | { |
44 | 0 | FieldUnit eUserMet = ScModule::get()->GetAppOptions().GetAppMetric(); |
45 | |
|
46 | 0 | sal_Int64 nUserVal = vcl::ConvertValue( nTwips*100, 1, 2, FieldUnit::TWIP, eUserMet ); |
47 | |
|
48 | 0 | OUString aStr = OUString::Concat(rText) + " " |
49 | 0 | + ScGlobal::getLocaleData().getNum( nUserVal, 2 ) |
50 | 0 | + " " + SdrFormatter::GetUnitStr(eUserMet); |
51 | 0 | return aStr; |
52 | 0 | } |
53 | 0 | } |
54 | | |
55 | | ScColBar::ScColBar( vcl::Window* pParent, ScHSplitPos eWhich, |
56 | | ScHeaderFunctionSet* pFuncSet, ScHeaderSelectionEngine* pEng, |
57 | | ScTabView* pTab ) : |
58 | 0 | ScHeaderControl( pParent, pEng, pTab->GetViewData().GetDocument().MaxCol()+1, false, pTab ), |
59 | 0 | meWhich( eWhich ), |
60 | 0 | mpFuncSet( pFuncSet ) |
61 | 0 | { |
62 | 0 | Show(); |
63 | 0 | } Unexecuted instantiation: ScColBar::ScColBar(vcl::Window*, ScHSplitPos, ScHeaderFunctionSet*, ScHeaderSelectionEngine*, ScTabView*) Unexecuted instantiation: ScColBar::ScColBar(vcl::Window*, ScHSplitPos, ScHeaderFunctionSet*, ScHeaderSelectionEngine*, ScTabView*) |
64 | | |
65 | | ScColBar::~ScColBar() |
66 | 0 | { |
67 | 0 | } |
68 | | |
69 | | SCCOLROW ScColBar::GetPos() const |
70 | 0 | { |
71 | 0 | return pTabView->GetViewData().GetPosX(meWhich); |
72 | 0 | } |
73 | | |
74 | | sal_uInt16 ScColBar::GetEntrySize( SCCOLROW nEntryNo ) const |
75 | 0 | { |
76 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
77 | 0 | ScDocument& rDoc = rViewData.GetDocument(); |
78 | 0 | SCTAB nTab = rViewData.CurrentTabForData(); |
79 | 0 | if (rDoc.ColHidden(static_cast<SCCOL>(nEntryNo), nTab)) |
80 | 0 | return 0; |
81 | 0 | else |
82 | 0 | return static_cast<sal_uInt16>(ScViewData::ToPixel( rDoc.GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), rViewData.GetPPTX() )); |
83 | 0 | } |
84 | | |
85 | | OUString ScColBar::GetEntryText( SCCOLROW nEntryNo ) const |
86 | 0 | { |
87 | 0 | return pTabView->GetViewData().GetDocument().GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1 |
88 | 0 | ? OUString::number(nEntryNo + 1) |
89 | 0 | : ScColToAlpha( static_cast<SCCOL>(nEntryNo) ); |
90 | 0 | } |
91 | | |
92 | | void ScColBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize ) |
93 | 0 | { |
94 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
95 | 0 | sal_uInt16 nSizeTwips; |
96 | 0 | ScSizeMode eMode = SC_SIZE_DIRECT; |
97 | 0 | if (nNewSize < 10) nNewSize = 10; // pixels |
98 | |
|
99 | 0 | if ( nNewSize == HDR_SIZE_OPTIMUM ) |
100 | 0 | { |
101 | 0 | nSizeTwips = STD_EXTRA_WIDTH; |
102 | 0 | eMode = SC_SIZE_OPTIMAL; |
103 | 0 | } |
104 | 0 | else |
105 | 0 | nSizeTwips = static_cast<sal_uInt16>( nNewSize / rViewData.GetPPTX() ); |
106 | |
|
107 | 0 | const ScMarkData& rMark = rViewData.GetMarkData(); |
108 | |
|
109 | 0 | std::vector<sc::ColRowSpan> aRanges; |
110 | 0 | if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) ) |
111 | 0 | { |
112 | 0 | ScDocument& rDoc = rViewData.GetDocument(); |
113 | 0 | SCCOL nStart = 0; |
114 | 0 | while (nStart<=rDoc.MaxCol()) |
115 | 0 | { |
116 | 0 | while (nStart<rDoc.MaxCol() && !rMark.IsColumnMarked(nStart)) |
117 | 0 | ++nStart; |
118 | 0 | if (rMark.IsColumnMarked(nStart)) |
119 | 0 | { |
120 | 0 | SCCOL nEnd = nStart; |
121 | 0 | while (nEnd<rDoc.MaxCol() && rMark.IsColumnMarked(nEnd)) |
122 | 0 | ++nEnd; |
123 | 0 | if (!rMark.IsColumnMarked(nEnd)) |
124 | 0 | --nEnd; |
125 | 0 | aRanges.emplace_back(nStart,nEnd); |
126 | 0 | nStart = nEnd+1; |
127 | 0 | } |
128 | 0 | else |
129 | 0 | nStart = rDoc.MaxCol()+1; |
130 | 0 | } |
131 | 0 | } |
132 | 0 | else |
133 | 0 | { |
134 | 0 | aRanges.emplace_back(nPos,nPos); |
135 | 0 | } |
136 | |
|
137 | 0 | rViewData.GetView()->SetWidthOrHeight(true, aRanges, eMode, nSizeTwips); |
138 | 0 | } |
139 | | |
140 | | void ScColBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd ) |
141 | 0 | { |
142 | 0 | std::vector<sc::ColRowSpan> aRanges(1, sc::ColRowSpan(nStart,nEnd)); |
143 | 0 | pTabView->GetViewData().GetView()->SetWidthOrHeight(true, aRanges, SC_SIZE_DIRECT, 0); |
144 | 0 | } |
145 | | |
146 | | void ScColBar::SetMarking( bool bSet ) |
147 | 0 | { |
148 | 0 | pTabView->GetViewData().GetMarkData().SetMarking( bSet ); |
149 | 0 | if (!bSet) |
150 | 0 | { |
151 | 0 | pTabView->GetViewData().GetView()->UpdateAutoFillMark(); |
152 | 0 | } |
153 | 0 | } |
154 | | |
155 | | void ScColBar::SelectWindow() |
156 | 0 | { |
157 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
158 | 0 | ScTabViewShell* pViewSh = rViewData.GetViewShell(); |
159 | |
|
160 | 0 | pViewSh->SetActive(); // Appear and SetViewFrame |
161 | 0 | pViewSh->DrawDeselectAll(); |
162 | |
|
163 | 0 | ScSplitPos eActive = rViewData.GetActivePart(); |
164 | 0 | if (meWhich==SC_SPLIT_LEFT) |
165 | 0 | { |
166 | 0 | if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_TOPLEFT; |
167 | 0 | if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_BOTTOMLEFT; |
168 | 0 | } |
169 | 0 | else |
170 | 0 | { |
171 | 0 | if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_TOPRIGHT; |
172 | 0 | if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_BOTTOMRIGHT; |
173 | 0 | } |
174 | 0 | pViewSh->ActivatePart( eActive ); |
175 | |
|
176 | 0 | mpFuncSet->SetColumn( true ); |
177 | 0 | mpFuncSet->SetWhich( eActive ); |
178 | |
|
179 | 0 | pViewSh->ActiveGrabFocus(); |
180 | 0 | } |
181 | | |
182 | | bool ScColBar::IsDisabled() const |
183 | 0 | { |
184 | 0 | return ScModule::get()->IsModalMode(); |
185 | 0 | } |
186 | | |
187 | | bool ScColBar::ResizeAllowed() const |
188 | 0 | { |
189 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
190 | 0 | return !rViewData.HasEditView( rViewData.GetActivePart() ); |
191 | 0 | } |
192 | | |
193 | | void ScColBar::DrawInvert( tools::Long nDragPosP ) |
194 | 0 | { |
195 | 0 | tools::Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 ); |
196 | 0 | PaintImmediately(); |
197 | 0 | GetOutDev()->Invert(aRect); |
198 | |
|
199 | 0 | pTabView->GetViewData().GetView()->InvertVertical(meWhich,nDragPosP); |
200 | 0 | } |
201 | | |
202 | | OUString ScColBar::GetDragHelp( tools::Long nVal ) |
203 | 0 | { |
204 | 0 | tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTX() ); |
205 | 0 | return lcl_MetricString( nTwips, ScResId(STR_TIP_WIDTH) ); |
206 | 0 | } |
207 | | |
208 | | bool ScColBar::IsLayoutRTL() const // override only for columns |
209 | 0 | { |
210 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
211 | 0 | return rViewData.GetDocument().IsLayoutRTL( rViewData.CurrentTabForData() ); |
212 | 0 | } |
213 | | |
214 | | ScRowBar::ScRowBar( vcl::Window* pParent, ScVSplitPos eWhich, |
215 | | ScHeaderFunctionSet* pFuncSet, ScHeaderSelectionEngine* pEng, |
216 | | ScTabView* pTab ) : |
217 | 0 | ScHeaderControl( pParent, pEng, pTab->GetViewData().GetDocument().MaxRow()+1, true, pTab ), |
218 | 0 | meWhich( eWhich ), |
219 | 0 | mpFuncSet( pFuncSet ) |
220 | 0 | { |
221 | 0 | Show(); |
222 | 0 | } Unexecuted instantiation: ScRowBar::ScRowBar(vcl::Window*, ScVSplitPos, ScHeaderFunctionSet*, ScHeaderSelectionEngine*, ScTabView*) Unexecuted instantiation: ScRowBar::ScRowBar(vcl::Window*, ScVSplitPos, ScHeaderFunctionSet*, ScHeaderSelectionEngine*, ScTabView*) |
223 | | |
224 | | ScRowBar::~ScRowBar() |
225 | 0 | { |
226 | 0 | } |
227 | | |
228 | | SCCOLROW ScRowBar::GetPos() const |
229 | 0 | { |
230 | 0 | return pTabView->GetViewData().GetPosY(meWhich); |
231 | 0 | } |
232 | | |
233 | | sal_uInt16 ScRowBar::GetEntrySize( SCCOLROW nEntryNo ) const |
234 | 0 | { |
235 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
236 | 0 | ScDocument& rDoc = rViewData.GetDocument(); |
237 | 0 | SCTAB nTab = rViewData.CurrentTabForData(); |
238 | 0 | SCROW nLastRow = -1; |
239 | 0 | if (rDoc.RowHidden(nEntryNo, nTab, nullptr, &nLastRow)) |
240 | 0 | return 0; |
241 | 0 | else |
242 | 0 | return static_cast<sal_uInt16>(ScViewData::ToPixel( rDoc.GetOriginalHeight( nEntryNo, |
243 | 0 | nTab ), rViewData.GetPPTY() )); |
244 | 0 | } |
245 | | |
246 | | OUString ScRowBar::GetEntryText( SCCOLROW nEntryNo ) const |
247 | 0 | { |
248 | 0 | return OUString::number( nEntryNo + 1 ); |
249 | 0 | } |
250 | | |
251 | | void ScRowBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize ) |
252 | 0 | { |
253 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
254 | 0 | sal_uInt16 nSizeTwips; |
255 | 0 | ScSizeMode eMode = SC_SIZE_DIRECT; |
256 | 0 | if (nNewSize < 10) nNewSize = 10; // pixels |
257 | |
|
258 | 0 | if ( nNewSize == HDR_SIZE_OPTIMUM ) |
259 | 0 | { |
260 | 0 | nSizeTwips = 0; |
261 | 0 | eMode = SC_SIZE_OPTIMAL; |
262 | 0 | } |
263 | 0 | else |
264 | 0 | nSizeTwips = static_cast<sal_uInt16>( nNewSize / rViewData.GetPPTY() ); |
265 | |
|
266 | 0 | const ScMarkData& rMark = rViewData.GetMarkData(); |
267 | |
|
268 | 0 | std::vector<sc::ColRowSpan> aRanges; |
269 | 0 | if ( rMark.IsRowMarked( nPos ) ) |
270 | 0 | { |
271 | 0 | ScDocument& rDoc = rViewData.GetDocument(); |
272 | 0 | SCROW nStart = 0; |
273 | 0 | while (nStart<=rDoc.MaxRow()) |
274 | 0 | { |
275 | 0 | while (nStart<rDoc.MaxRow() && !rMark.IsRowMarked(nStart)) |
276 | 0 | ++nStart; |
277 | 0 | if (rMark.IsRowMarked(nStart)) |
278 | 0 | { |
279 | 0 | SCROW nEnd = nStart; |
280 | 0 | while (nEnd<rDoc.MaxRow() && rMark.IsRowMarked(nEnd)) |
281 | 0 | ++nEnd; |
282 | 0 | if (!rMark.IsRowMarked(nEnd)) |
283 | 0 | --nEnd; |
284 | 0 | aRanges.emplace_back(nStart,nEnd); |
285 | 0 | nStart = nEnd+1; |
286 | 0 | } |
287 | 0 | else |
288 | 0 | nStart = rDoc.MaxRow()+1; |
289 | 0 | } |
290 | 0 | } |
291 | 0 | else |
292 | 0 | { |
293 | 0 | aRanges.emplace_back(nPos,nPos); |
294 | 0 | } |
295 | |
|
296 | 0 | rViewData.GetView()->SetWidthOrHeight(false, aRanges, eMode, nSizeTwips); |
297 | 0 | } |
298 | | |
299 | | void ScRowBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd ) |
300 | 0 | { |
301 | 0 | std::vector<sc::ColRowSpan> aRange(1, sc::ColRowSpan(nStart,nEnd)); |
302 | 0 | pTabView->GetViewData().GetView()->SetWidthOrHeight(false, aRange, SC_SIZE_DIRECT, 0); |
303 | 0 | } |
304 | | |
305 | | void ScRowBar::SetMarking( bool bSet ) |
306 | 0 | { |
307 | 0 | pTabView->GetViewData().GetMarkData().SetMarking( bSet ); |
308 | 0 | if (!bSet) |
309 | 0 | { |
310 | 0 | pTabView->GetViewData().GetView()->UpdateAutoFillMark(); |
311 | 0 | } |
312 | 0 | } |
313 | | |
314 | | void ScRowBar::SelectWindow() |
315 | 0 | { |
316 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
317 | 0 | ScTabViewShell* pViewSh = rViewData.GetViewShell(); |
318 | |
|
319 | 0 | pViewSh->SetActive(); // Appear and SetViewFrame |
320 | 0 | pViewSh->DrawDeselectAll(); |
321 | |
|
322 | 0 | ScSplitPos eActive = rViewData.GetActivePart(); |
323 | 0 | if (meWhich==SC_SPLIT_TOP) |
324 | 0 | { |
325 | 0 | if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_TOPLEFT; |
326 | 0 | if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_TOPRIGHT; |
327 | 0 | } |
328 | 0 | else |
329 | 0 | { |
330 | 0 | if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_BOTTOMLEFT; |
331 | 0 | if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_BOTTOMRIGHT; |
332 | 0 | } |
333 | 0 | pViewSh->ActivatePart( eActive ); |
334 | |
|
335 | 0 | mpFuncSet->SetColumn( false ); |
336 | 0 | mpFuncSet->SetWhich( eActive ); |
337 | |
|
338 | 0 | pViewSh->ActiveGrabFocus(); |
339 | 0 | } |
340 | | |
341 | | bool ScRowBar::IsDisabled() const |
342 | 0 | { |
343 | 0 | return ScModule::get()->IsModalMode(); |
344 | 0 | } |
345 | | |
346 | | bool ScRowBar::ResizeAllowed() const |
347 | 0 | { |
348 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
349 | 0 | return !rViewData.HasEditView( rViewData.GetActivePart() ); |
350 | 0 | } |
351 | | |
352 | | void ScRowBar::DrawInvert( tools::Long nDragPosP ) |
353 | 0 | { |
354 | 0 | tools::Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 ); |
355 | 0 | PaintImmediately(); |
356 | 0 | GetOutDev()->Invert(aRect); |
357 | |
|
358 | 0 | pTabView->GetViewData().GetView()->InvertHorizontal(meWhich,nDragPosP); |
359 | 0 | } |
360 | | |
361 | | OUString ScRowBar::GetDragHelp( tools::Long nVal ) |
362 | 0 | { |
363 | 0 | tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTY() ); |
364 | 0 | return lcl_MetricString( nTwips, ScResId(STR_TIP_HEIGHT) ); |
365 | 0 | } |
366 | | |
367 | | SCCOLROW ScRowBar::GetHiddenCount( SCCOLROW nEntryNo ) const // override only for rows |
368 | 0 | { |
369 | 0 | const ScViewData& rViewData = pTabView->GetViewData(); |
370 | 0 | ScDocument& rDoc = rViewData.GetDocument(); |
371 | 0 | SCTAB nTab = rViewData.CurrentTabForData(); |
372 | 0 | return rDoc.GetHiddenRowCount( nEntryNo, nTab ); |
373 | 0 | } |
374 | | |
375 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |