1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <string_view>
#include <unotools/localedatawrapper.hxx>
#include <vcl/fieldvalues.hxx>
#include <colrowba.hxx>
#include <document.hxx>
#include <scmod.hxx>
#include <tabvwsh.hxx>
#include <appoptio.hxx>
#include <globstr.hrc>
#include <scresid.hxx>
#include <markdata.hxx>
#include <tabview.hxx>
#include <columnspanset.hxx>
static OUString lcl_MetricString( tools::Long nTwips, std::u16string_view rText )
{
if ( nTwips <= 0 )
return ScResId(STR_TIP_HIDE);
else
{
FieldUnit eUserMet = SC_MOD()->GetAppOptions().GetAppMetric();
sal_Int64 nUserVal = vcl::ConvertValue( nTwips*100, 1, 2, FieldUnit::TWIP, eUserMet );
OUString aStr = OUString::Concat(rText) + " "
+ ScGlobal::getLocaleData().getNum( nUserVal, 2 )
+ " " + SdrFormatter::GetUnitStr(eUserMet);
return aStr;
}
}
ScColBar::ScColBar( vcl::Window* pParent, ScHSplitPos eWhich,
ScHeaderFunctionSet* pFuncSet, ScHeaderSelectionEngine* pEng,
ScTabView* pTab ) :
ScHeaderControl( pParent, pEng, pTab->GetViewData().GetDocument().MaxCol()+1, false, pTab ),
meWhich( eWhich ),
mpFuncSet( pFuncSet )
{
Show();
}
ScColBar::~ScColBar()
{
}
SCCOLROW ScColBar::GetPos() const
{
return pTabView->GetViewData().GetPosX(meWhich);
}
sal_uInt16 ScColBar::GetEntrySize( SCCOLROW nEntryNo ) const
{
const ScViewData& rViewData = pTabView->GetViewData();
ScDocument& rDoc = rViewData.GetDocument();
SCTAB nTab = rViewData.GetTabNo();
if (rDoc.ColHidden(static_cast<SCCOL>(nEntryNo), nTab))
return 0;
else
return static_cast<sal_uInt16>(ScViewData::ToPixel( rDoc.GetColWidth( static_cast<SCCOL>(nEntryNo), nTab ), rViewData.GetPPTX() ));
}
OUString ScColBar::GetEntryText( SCCOLROW nEntryNo ) const
{
return pTabView->GetViewData().GetDocument().GetAddressConvention() == formula::FormulaGrammar::CONV_XL_R1C1
? OUString::number(nEntryNo + 1)
: ScColToAlpha( static_cast<SCCOL>(nEntryNo) );
}
void ScColBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
{
const ScViewData& rViewData = pTabView->GetViewData();
sal_uInt16 nSizeTwips;
ScSizeMode eMode = SC_SIZE_DIRECT;
if (nNewSize < 10) nNewSize = 10; // pixels
if ( nNewSize == HDR_SIZE_OPTIMUM )
{
nSizeTwips = STD_EXTRA_WIDTH;
eMode = SC_SIZE_OPTIMAL;
}
else
nSizeTwips = static_cast<sal_uInt16>( nNewSize / rViewData.GetPPTX() );
const ScMarkData& rMark = rViewData.GetMarkData();
std::vector<sc::ColRowSpan> aRanges;
if ( rMark.IsColumnMarked( static_cast<SCCOL>(nPos) ) )
{
ScDocument& rDoc = rViewData.GetDocument();
SCCOL nStart = 0;
while (nStart<=rDoc.MaxCol())
{
while (nStart<rDoc.MaxCol() && !rMark.IsColumnMarked(nStart))
++nStart;
if (rMark.IsColumnMarked(nStart))
{
SCCOL nEnd = nStart;
while (nEnd<rDoc.MaxCol() && rMark.IsColumnMarked(nEnd))
++nEnd;
if (!rMark.IsColumnMarked(nEnd))
--nEnd;
aRanges.emplace_back(nStart,nEnd);
nStart = nEnd+1;
}
else
nStart = rDoc.MaxCol()+1;
}
}
else
{
aRanges.emplace_back(nPos,nPos);
}
rViewData.GetView()->SetWidthOrHeight(true, aRanges, eMode, nSizeTwips);
}
void ScColBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
{
std::vector<sc::ColRowSpan> aRanges(1, sc::ColRowSpan(nStart,nEnd));
pTabView->GetViewData().GetView()->SetWidthOrHeight(true, aRanges, SC_SIZE_DIRECT, 0);
}
void ScColBar::SetMarking( bool bSet )
{
pTabView->GetViewData().GetMarkData().SetMarking( bSet );
if (!bSet)
{
pTabView->GetViewData().GetView()->UpdateAutoFillMark();
}
}
void ScColBar::SelectWindow()
{
const ScViewData& rViewData = pTabView->GetViewData();
ScTabViewShell* pViewSh = rViewData.GetViewShell();
pViewSh->SetActive(); // Appear and SetViewFrame
pViewSh->DrawDeselectAll();
ScSplitPos eActive = rViewData.GetActivePart();
if (meWhich==SC_SPLIT_LEFT)
{
if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_TOPLEFT;
if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_BOTTOMLEFT;
}
else
{
if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_TOPRIGHT;
if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_BOTTOMRIGHT;
}
pViewSh->ActivatePart( eActive );
mpFuncSet->SetColumn( true );
mpFuncSet->SetWhich( eActive );
pViewSh->ActiveGrabFocus();
}
bool ScColBar::IsDisabled() const
{
ScModule* pScMod = SC_MOD();
return pScMod->IsModalMode();
}
bool ScColBar::ResizeAllowed() const
{
const ScViewData& rViewData = pTabView->GetViewData();
return !rViewData.HasEditView( rViewData.GetActivePart() );
}
void ScColBar::DrawInvert( tools::Long nDragPosP )
{
tools::Rectangle aRect( nDragPosP,0, nDragPosP+HDR_SLIDERSIZE-1,GetOutputSizePixel().Width()-1 );
PaintImmediately();
GetOutDev()->Invert(aRect);
pTabView->GetViewData().GetView()->InvertVertical(meWhich,nDragPosP);
}
OUString ScColBar::GetDragHelp( tools::Long nVal )
{
tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTX() );
return lcl_MetricString( nTwips, ScResId(STR_TIP_WIDTH) );
}
bool ScColBar::IsLayoutRTL() const // override only for columns
{
const ScViewData& rViewData = pTabView->GetViewData();
return rViewData.GetDocument().IsLayoutRTL( rViewData.GetTabNo() );
}
ScRowBar::ScRowBar( vcl::Window* pParent, ScVSplitPos eWhich,
ScHeaderFunctionSet* pFuncSet, ScHeaderSelectionEngine* pEng,
ScTabView* pTab ) :
ScHeaderControl( pParent, pEng, pTab->GetViewData().GetDocument().MaxRow()+1, true, pTab ),
meWhich( eWhich ),
mpFuncSet( pFuncSet )
{
Show();
}
ScRowBar::~ScRowBar()
{
}
SCCOLROW ScRowBar::GetPos() const
{
return pTabView->GetViewData().GetPosY(meWhich);
}
sal_uInt16 ScRowBar::GetEntrySize( SCCOLROW nEntryNo ) const
{
const ScViewData& rViewData = pTabView->GetViewData();
ScDocument& rDoc = rViewData.GetDocument();
SCTAB nTab = rViewData.GetTabNo();
SCROW nLastRow = -1;
if (rDoc.RowHidden(nEntryNo, nTab, nullptr, &nLastRow))
return 0;
else
return static_cast<sal_uInt16>(ScViewData::ToPixel( rDoc.GetOriginalHeight( nEntryNo,
nTab ), rViewData.GetPPTY() ));
}
OUString ScRowBar::GetEntryText( SCCOLROW nEntryNo ) const
{
return OUString::number( nEntryNo + 1 );
}
void ScRowBar::SetEntrySize( SCCOLROW nPos, sal_uInt16 nNewSize )
{
const ScViewData& rViewData = pTabView->GetViewData();
sal_uInt16 nSizeTwips;
ScSizeMode eMode = SC_SIZE_DIRECT;
if (nNewSize < 10) nNewSize = 10; // pixels
if ( nNewSize == HDR_SIZE_OPTIMUM )
{
nSizeTwips = 0;
eMode = SC_SIZE_OPTIMAL;
}
else
nSizeTwips = static_cast<sal_uInt16>( nNewSize / rViewData.GetPPTY() );
const ScMarkData& rMark = rViewData.GetMarkData();
std::vector<sc::ColRowSpan> aRanges;
if ( rMark.IsRowMarked( nPos ) )
{
ScDocument& rDoc = rViewData.GetDocument();
SCROW nStart = 0;
while (nStart<=rDoc.MaxRow())
{
while (nStart<rDoc.MaxRow() && !rMark.IsRowMarked(nStart))
++nStart;
if (rMark.IsRowMarked(nStart))
{
SCROW nEnd = nStart;
while (nEnd<rDoc.MaxRow() && rMark.IsRowMarked(nEnd))
++nEnd;
if (!rMark.IsRowMarked(nEnd))
--nEnd;
aRanges.emplace_back(nStart,nEnd);
nStart = nEnd+1;
}
else
nStart = rDoc.MaxRow()+1;
}
}
else
{
aRanges.emplace_back(nPos,nPos);
}
rViewData.GetView()->SetWidthOrHeight(false, aRanges, eMode, nSizeTwips);
}
void ScRowBar::HideEntries( SCCOLROW nStart, SCCOLROW nEnd )
{
std::vector<sc::ColRowSpan> aRange(1, sc::ColRowSpan(nStart,nEnd));
pTabView->GetViewData().GetView()->SetWidthOrHeight(false, aRange, SC_SIZE_DIRECT, 0);
}
void ScRowBar::SetMarking( bool bSet )
{
pTabView->GetViewData().GetMarkData().SetMarking( bSet );
if (!bSet)
{
pTabView->GetViewData().GetView()->UpdateAutoFillMark();
}
}
void ScRowBar::SelectWindow()
{
const ScViewData& rViewData = pTabView->GetViewData();
ScTabViewShell* pViewSh = rViewData.GetViewShell();
pViewSh->SetActive(); // Appear and SetViewFrame
pViewSh->DrawDeselectAll();
ScSplitPos eActive = rViewData.GetActivePart();
if (meWhich==SC_SPLIT_TOP)
{
if (eActive==SC_SPLIT_BOTTOMLEFT) eActive=SC_SPLIT_TOPLEFT;
if (eActive==SC_SPLIT_BOTTOMRIGHT) eActive=SC_SPLIT_TOPRIGHT;
}
else
{
if (eActive==SC_SPLIT_TOPLEFT) eActive=SC_SPLIT_BOTTOMLEFT;
if (eActive==SC_SPLIT_TOPRIGHT) eActive=SC_SPLIT_BOTTOMRIGHT;
}
pViewSh->ActivatePart( eActive );
mpFuncSet->SetColumn( false );
mpFuncSet->SetWhich( eActive );
pViewSh->ActiveGrabFocus();
}
bool ScRowBar::IsDisabled() const
{
ScModule* pScMod = SC_MOD();
return pScMod->IsModalMode();
}
bool ScRowBar::ResizeAllowed() const
{
const ScViewData& rViewData = pTabView->GetViewData();
return !rViewData.HasEditView( rViewData.GetActivePart() );
}
void ScRowBar::DrawInvert( tools::Long nDragPosP )
{
tools::Rectangle aRect( 0,nDragPosP, GetOutputSizePixel().Width()-1,nDragPosP+HDR_SLIDERSIZE-1 );
PaintImmediately();
GetOutDev()->Invert(aRect);
pTabView->GetViewData().GetView()->InvertHorizontal(meWhich,nDragPosP);
}
OUString ScRowBar::GetDragHelp( tools::Long nVal )
{
tools::Long nTwips = static_cast<tools::Long>( nVal / pTabView->GetViewData().GetPPTY() );
return lcl_MetricString( nTwips, ScResId(STR_TIP_HEIGHT) );
}
SCCOLROW ScRowBar::GetHiddenCount( SCCOLROW nEntryNo ) const // override only for rows
{
const ScViewData& rViewData = pTabView->GetViewData();
ScDocument& rDoc = rViewData.GetDocument();
SCTAB nTab = rViewData.GetTabNo();
return rDoc.GetHiddenRowCount( nEntryNo, nTab );
}
bool ScRowBar::IsMirrored() const // override only for rows
{
const ScViewData& rViewData = pTabView->GetViewData();
return rViewData.GetDocument().IsLayoutRTL( rViewData.GetTabNo() );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|