LibreOffice Module sc (master) 1
datatableview.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 <datatableview.hxx>
21
22#include <document.hxx>
23#include <utility>
24#include <viewdata.hxx>
25#include <output.hxx>
26#include <fillinfo.hxx>
27#include <table.hxx>
28
30#include <vcl/seleng.hxx>
31#include <sal/log.hxx>
32
33constexpr double nPPTX = 0.06666;
34constexpr double nPPTY = 0.06666;
35
36constexpr sal_uInt16 nRowHeaderWidth = 100;
37constexpr sal_uInt16 nColHeaderHeight = 20;
38
40 ScHeaderControl(pParent, pSelectionEngine, pDoc->MaxCol()+1, false, nullptr),
41 mpDoc(pDoc),
42 mnCol(0)
43{
44}
45
47{
48 mnCol = nCol;
49}
50
52{
53 return mnCol;
54}
55
57{
59}
60
62{
63 return "Col: " + OUString::number(nPos + 1);
64}
65
67{
68 return false;
69}
70
71void ScDataTableColView::SetEntrySize(SCCOLROW nPos, sal_uInt16 nColWidth)
72{
73 mpDoc->SetColWidthOnly(nPos, 0, nColWidth/nPPTX);
74}
75
77{
78 for (SCCOLROW nCol = nPos; nCol <= nEndPos; ++nCol)
79 {
80 mpDoc->ShowCol(nCol, 0, false);
81 }
82}
83
84
86 ScHeaderControl(pParent, pSelectionEngine, pDoc->MaxRow()+1, true, nullptr),
87 mpDoc(pDoc),
88 mnRow(0)
89{
90}
91
93{
94 mnRow = nRow;
95}
96
98{
99 return mnRow;
100}
101
103{
105}
106
108{
109 return OUString::number(nPos + 1);
110}
111
113{
114 return false;
115}
116
117void ScDataTableRowView::SetEntrySize(SCCOLROW nPos, sal_uInt16 nColWidth)
118{
119 mpDoc->SetRowHeight(nPos, 0, nColWidth/nPPTX);
120}
121
123{
124 for (SCCOLROW nCol = nPos; nCol <= nEndPos; ++nCol)
125 {
126 mpDoc->ShowRow(nCol, 0, false);
127 }
128}
129
130ScDataTableView::ScDataTableView(const css::uno::Reference<css::awt::XWindow> &rParent, std::shared_ptr<ScDocument> pDoc) :
131 Control(VCLUnoHelper::GetWindow(rParent)),
132 mpDoc(std::move(pDoc)),
133 mpSelectionEngine(new SelectionEngine(this)),
134 mpColView(VclPtr<ScDataTableColView>::Create(this, mpDoc.get(), mpSelectionEngine.get())),
135 mpRowView(VclPtr<ScDataTableRowView>::Create(this, mpDoc.get(), mpSelectionEngine.get())),
136 mpVScroll(VclPtr<ScrollAdaptor>::Create(this, false)),
137 mpHScroll(VclPtr<ScrollAdaptor>::Create(this, true)),
138 mnScrollBarSize(mpVScroll->GetSizePixel().Width()),
139 mnFirstVisibleRow(0),
140 mnFirstVisibleCol(0)
141{
144
145 mpVScroll->SetRangeMin(0);
146 mpVScroll->SetRangeMax(100);
147 mpVScroll->SetScrollHdl(LINK(this, ScDataTableView, VertScrollHdl));
148
149 mpHScroll->SetRangeMin(0);
150 mpHScroll->SetRangeMax(50);
151 mpHScroll->SetScrollHdl(LINK(this, ScDataTableView, HorzScrollHdl));
152
153 mpColView->Show();
154 mpRowView->Show();
155 mpVScroll->Show();
156 mpHScroll->Show();
157}
158
160{
161 disposeOnce();
162}
163
165{
171}
172
174{
175 if (!rMEvt.IsLeft())
176 return;
177
178 mpMouseEvent.reset(new MouseEvent(rMEvt));
179}
180
181namespace {
182
183SCCOL findColFromPos(sal_uInt16 nPixelPos, const ScDocument* pDoc, SCCOL nStartCol = 0)
184{
185 nPixelPos -= nRowHeaderWidth;
186 sal_uInt32 nPixelLength = 0;
187 for (SCCOL nCol : pDoc->GetColumnsRange(0, nStartCol, pDoc->MaxCol()))
188 {
189 sal_uInt16 nColWidth = pDoc->GetColWidth(nCol, 0, true);
190 sal_uInt32 nPixel = ScViewData::ToPixel(nColWidth, nPPTX);
191 nPixelLength += nPixel;
192
193 if (nPixelLength >= nPixelPos)
194 {
195 return nCol;
196 }
197 }
198
199 SAL_WARN("sc", "Could not find the corresponding column");
200 return pDoc->MaxCol();
201}
202
203SCROW findRowFromPos(sal_uInt16 nPixelPos, const ScDocument* pDoc, SCROW nStartRow = 0)
204{
205 nPixelPos -= nColHeaderHeight;
206 sal_uInt32 nPixelLength = 0;
207 for (SCROW nRow = nStartRow; nRow <= pDoc->MaxRow(); ++nRow)
208 {
209 sal_uInt16 nColWidth = pDoc->GetRowHeight(nRow, SCTAB(0), true);
210 sal_uInt32 nPixel = ScViewData::ToPixel(nColWidth, nPPTX);
211 nPixelLength += nPixel;
212
213 if (nPixelLength >= nPixelPos)
214 {
215 return nRow;
216 }
217 }
218
219 SAL_WARN("sc", "Could not find the corresponding row");
220 return pDoc->MaxRow();
221}
222
223}
224
226{
227 if (!rMEvt.IsLeft())
228 return;
229 if (!mpMouseEvent) // tdf#120528 The event originated in another window, like context menu
230 return;
231
232 SCCOL nStartCol = findColFromPos(mpMouseEvent->GetPosPixel().getX(), mpDoc.get());
233 SCCOL nEndCol = findColFromPos(rMEvt.GetPosPixel().getX(), mpDoc.get());
234 SCROW nStartRow = findRowFromPos(mpMouseEvent->GetPosPixel().getY(), mpDoc.get());
235 SCROW nEndRow = findRowFromPos(rMEvt.GetPosPixel().getY(), mpDoc.get());
236 PutInOrder(nStartCol, nEndCol);
237 PutInOrder(nStartRow, nEndRow);
238 mpColView->SetMark(true, nStartCol, nEndCol);
239 mpRowView->SetMark(true, nStartRow, nEndRow);
240
241 mpMouseEvent.reset();
242}
243
245{
246 Size aSize = GetSizePixel();
247 mpColView->setPosSizePixel(nRowHeaderWidth, 0, aSize.Width() - mnScrollBarSize, nColHeaderHeight);
248 mpRowView->setPosSizePixel(0, nColHeaderHeight, nRowHeaderWidth, aSize.Height());
249
252}
253
254void ScDataTableView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRectangle)
255{
256 Size aSize = GetSizePixel();
257 SCCOL nMaxVisibleCol = findColFromPos(aSize.Width() - mnScrollBarSize, mpDoc.get(), mnFirstVisibleCol);
258 SCROW nMaxVisibleRow = findRowFromPos(aSize.Height(), mpDoc.get(), mnFirstVisibleRow);
259
260 ScTableInfo aTableInfo;
261 mpDoc->FillInfo(aTableInfo, mnFirstVisibleCol, mnFirstVisibleRow, nMaxVisibleCol, nMaxVisibleRow, 0, 0.06666, 0.06666, false, false);
262 ScOutputData aOutput(&rRenderContext, OUTTYPE_WINDOW, aTableInfo, mpDoc.get(), 0,
264
265 aOutput.SetGridColor(COL_BLACK);
266 aOutput.SetSolidBackground(true);
267 aOutput.DrawClear();
268 aOutput.DrawDocumentBackground();
269 aOutput.DrawGrid(rRenderContext, true, false);
270 aOutput.DrawStrings();
271
272 Color aFaceColor(rRenderContext.GetSettings().GetStyleSettings().GetFaceColor());
273 rRenderContext.SetLineColor(aFaceColor);
274 rRenderContext.SetFillColor(aFaceColor);
277
278 Control::Paint(rRenderContext, rRectangle);
279}
280
282{
283 return Size(450, 400);
284}
285
286void ScDataTableView::getColRange(SCCOL& rStartCol, SCCOL& rEndCol) const
287{
288 SCCOLROW aStart = 0;
289 SCCOLROW aEnd = 0;
290 mpColView->GetMarkRange(aStart, aEnd);
291 rStartCol = static_cast<SCCOL>(aStart);
292 rEndCol = static_cast<SCCOL>(aEnd);
293}
294
295void ScDataTableView::getRowRange(SCROW& rStartCol, SCROW& rEndCol) const
296{
297 SCCOLROW aStart = 0;
298 SCCOLROW aEnd = 0;
299 mpRowView->GetMarkRange(aStart, aEnd);
300 rStartCol = static_cast<SCROW>(aStart);
301 rEndCol = static_cast<SCROW>(aEnd);
302}
303
305{
306 mnFirstVisibleRow = mpVScroll->GetThumbPos();
307 mpVScroll->SetRangeMax(std::min(mpDoc->MaxRow(), static_cast<SCROW>(mnFirstVisibleRow + 100)));
308 mpRowView->SetPos(mnFirstVisibleRow);
309 Invalidate();
310}
311
313{
314 mnFirstVisibleCol = mpHScroll->GetThumbPos();
315 mpHScroll->SetRangeMax(std::min(mpDoc->MaxCol(), static_cast<SCCOL>(mnFirstVisibleCol + 50)));
316 mpColView->SetPos(mnFirstVisibleCol);
317 Invalidate();
318}
319
320/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:150
const StyleSettings & GetStyleSettings() const
virtual void dispose() override
const Point & GetPosPixel() const
bool IsLeft() const
void DrawRect(const tools::Rectangle &rRect)
void SetLineColor()
void SetFillColor()
const AllSettings & GetSettings() const
constexpr tools::Long getX() const
constexpr tools::Long getY() const
void SetPos(SCCOLROW nRow)
virtual OUString GetEntryText(SCCOLROW nPos) const override
virtual SCCOLROW GetPos() const override
ScDocument * mpDoc
ScDataTableColView(vcl::Window *pParent, ScDocument *pDoc, SelectionEngine *pSelectionEngine)
virtual void HideEntries(SCCOLROW nPos, SCCOLROW nEndPos) override
virtual sal_uInt16 GetEntrySize(SCCOLROW nPos) const override
virtual bool IsLayoutRTL() const override
virtual void SetEntrySize(SCCOLROW nPos, sal_uInt16 nWidth) override
void SetPos(SCCOLROW nRow)
virtual void SetEntrySize(SCCOLROW nPos, sal_uInt16 nWidth) override
virtual SCCOLROW GetPos() const override
ScDocument * mpDoc
virtual sal_uInt16 GetEntrySize(SCCOLROW nPos) const override
virtual void HideEntries(SCCOLROW nPos, SCCOLROW nEndPos) override
ScDataTableRowView(vcl::Window *pParent, ScDocument *pDoc, SelectionEngine *pSelectionEngine)
virtual OUString GetEntryText(SCCOLROW nPos) const override
virtual bool IsLayoutRTL() const override
void getRowRange(SCROW &rStartRow, SCROW &rEndRow) const
virtual void dispose() override
VclPtr< ScDataTableRowView > mpRowView
~ScDataTableView() override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
void getColRange(SCCOL &rStartCol, SCCOL &rEndCol) const
std::shared_ptr< ScDocument > mpDoc
virtual Size GetOptimalSize() const override
VclPtr< ScrollAdaptor > mpHScroll
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
std::unique_ptr< MouseEvent > mpMouseEvent
VclPtr< ScDataTableColView > mpColView
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
VclPtr< ScrollAdaptor > mpVScroll
ScDataTableView(const css::uno::Reference< css::awt::XWindow > &rParent, std::shared_ptr< ScDocument > pDoc)
virtual void Resize() override
sal_uInt16 mnScrollBarSize
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4161
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 SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC void ShowRow(SCROW nRow, SCTAB nTab, bool bShow)
Definition: document.cxx:4303
SC_DLLPUBLIC void ShowCol(SCCOL nCol, SCTAB nTab, bool bShow)
Definition: document.cxx:4297
SC_DLLPUBLIC void SetColWidthOnly(SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth)
Definition: document.cxx:4092
SC_DLLPUBLIC void SetRowHeight(SCROW nRow, SCTAB nTab, sal_uInt16 nNewHeight)
Definition: document.cxx:4098
SC_DLLPUBLIC ScColumnsRange GetColumnsRange(SCTAB nTab, SCCOL nColBegin, SCCOL nColEnd) const
Definition: document.cxx:2541
void DrawClear()
Definition: output.cxx:1332
void DrawStrings(bool bPixelToLogic=false)
Definition: output2.cxx:1476
void SetSolidBackground(bool bSet)
Definition: output.hxx:327
void SetGridColor(const Color &rColor)
Definition: output.cxx:242
void DrawGrid(vcl::RenderContext &rRenderContext, bool bGrid, bool bPage, bool bMergeCover=false)
Definition: output.cxx:296
void DrawDocumentBackground()
Definition: output.cxx:816
static tools::Long ToPixel(sal_uInt16 nTwips, double nFactor)
Definition: viewdata.hxx:700
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetFaceColor() const
void disposeAndClear()
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
virtual Size GetSizePixel() const
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr sal_uInt16 nRowHeaderWidth
constexpr double nPPTX
IMPL_LINK_NOARG(ScDataTableView, VertScrollHdl, weld::Scrollbar &, void)
constexpr double nPPTY
constexpr sal_uInt16 nColHeaderHeight
sal_Int32 mnRow
sal_Int32 mnCol
sal_uInt16 nPos
#define SAL_WARN(area, stream)
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
@ OUTTYPE_WINDOW
Definition: output.hxx:59
#define nPixel
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