LibreOffice Module sc (master) 1
uiobject.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
10#include <memory>
11#include <uiobject.hxx>
12
13#include <rangeutl.hxx>
14#include <gridwin.hxx>
15
16#include <viewdata.hxx>
17#include <viewfunc.hxx>
18#include <dbfunc.hxx>
19#include <tabvwsh.hxx>
20#include <drwlayer.hxx>
22#include <sfx2/viewfrm.hxx>
23#include <sfx2/dispatch.hxx>
24#include <appoptio.hxx>
25#include <scmod.hxx>
26#include <fudraw.hxx>
27#include <postit.hxx>
28
29#include <com/sun/star/embed/EmbedVerbs.hpp>
30
31#include <svx/svditer.hxx>
32#include <svx/svdobj.hxx>
33#include <svx/svdoole2.hxx>
34#include <sal/log.hxx>
35
36namespace {
37
38ScAddress get_address_from_string(const ScDocument& rDoc, std::u16string_view aStr)
39{
40 ScAddress aAddr;
41 sal_Int32 nOffset = 0;
43 return aAddr;
44}
45
46ScRange get_range_from_string(const ScDocument& rDoc, std::u16string_view aStr)
47{
48 ScRange aRange;
49 sal_Int32 nOffset = 0;
51
52 return aRange;
53}
54
55}
56
58 WindowUIObject(xGridWin),
59 mxGridWindow(xGridWin)
60{
61}
62
64{
66
67 aMap["SelectedTable"] = OUString::number(mxGridWindow->getViewData().GetTabNo());
68 aMap["CurrentColumn"] = OUString::number(mxGridWindow->getViewData().GetCurX());
69 aMap["CurrentRow"] = OUString::number(mxGridWindow->getViewData().GetCurY());
70
71 ScSplitPos eAlign = mxGridWindow->getViewData().GetActivePart();
72 ScHSplitPos eAlignX = WhichH(eAlign);
73 ScVSplitPos eAlignY = WhichV(eAlign);
74 aMap["TopVisibleRow"] = OUString::number(mxGridWindow->getViewData().GetPosY(eAlignY));
75 aMap["TopVisibleColumn"] = OUString::number(mxGridWindow->getViewData().GetPosX(eAlignX));
76
77 ScRangeList aMarkedArea = mxGridWindow->getViewData().GetMarkData().GetMarkedRanges();
78 OUString aMarkedAreaString;
79 ScRangeStringConverter::GetStringFromRangeList(aMarkedAreaString, &aMarkedArea, &mxGridWindow->getViewData().GetDocument(), formula::FormulaGrammar::CONV_OOO);
80
81 aMap["MarkedArea"] = aMarkedAreaString;
82
83 ScDocument& rDoc = mxGridWindow->getViewData().GetDocument();
84 ScAddress aPos( mxGridWindow->getViewData().GetCurX() , mxGridWindow->getViewData().GetCurY() , mxGridWindow->getViewData().GetTabNo() );
85 if ( rDoc.HasNote( aPos ) )
86 {
87 ScPostIt* pNote = rDoc.GetNote(aPos);
88 assert(pNote);
89 aMap["CurrentCellCommentText"] = pNote->GetText();
90 }
91
92 SCCOL nCol;
93 SCROW nRow;
94 aMap["CurrentTableHasData"] = OUString::boolean( rDoc.GetDataStart( mxGridWindow->getViewData().GetTabNo(), nCol, nRow ) );
95 nCol = mxGridWindow->getViewData().GetCurX();
96 nRow = 0;
97 aMap["CurrentColumnHasData"] = OUString::boolean( rDoc.GetPrintAreaVer( mxGridWindow->getViewData().GetTabNo(), nCol, nCol, nRow, true ) );
98 nRow = mxGridWindow->getViewData().GetCurY();
99 nCol = 0;
100 aMap["CurrentRowHasData"] = OUString::boolean( rDoc.GetPrintAreaHor( mxGridWindow->getViewData().GetTabNo(), nRow, nRow, nCol ) );
101
102 ScAppOptions aOpt = SC_MOD()->GetAppOptions();
103 aMap["Zoom"] = OUString::number( aOpt.GetZoom() );
104 return aMap;
105}
106
108{
109 ScViewData& rViewData = mxGridWindow->getViewData();
110 ScDBFunc* pFunc = rViewData.GetView();
111
112 return pFunc;
113}
114
116{
117 ScViewData& rViewData = mxGridWindow->getViewData();
118 ScDrawView* pDrawView = rViewData.GetScDrawView();
119
120 return pDrawView;
121}
122
124{
125 ScViewData& rViewData = mxGridWindow->getViewData();
126 ScTabViewShell* pViewShell = rViewData.GetViewShell();
127
128 return pViewShell;
129}
130
132{
133 ScViewData& rViewData = mxGridWindow->getViewData();
134 ScViewFunc* pViewFunc = rViewData.GetView();
135
136 return pViewFunc;
137}
138
139void ScGridWinUIObject::execute(const OUString& rAction,
140 const StringMap& rParameters)
141{
142 if (rAction == "SELECT")
143 {
144 bool bExtend = false;
145 if (rParameters.find("EXTEND") != rParameters.end())
146 {
147 auto itr = rParameters.find("EXTEND");
148 if (itr->second.equalsIgnoreAsciiCase("true") || itr->second == "1")
149 bExtend = true;
150 }
151
152 if (rParameters.find("CELL") != rParameters.end())
153 {
154 auto itr = rParameters.find("CELL");
155 const OUString& rStr = itr->second;
156 ScAddress aAddr = get_address_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
157 ScDBFunc* pFunc = getDBFunc();
158 pFunc->MarkRange(ScRange(aAddr), true, bExtend);
159 mxGridWindow->CursorChanged();
160 }
161 else if (rParameters.find("RANGE") != rParameters.end())
162 {
163 auto itr = rParameters.find("RANGE");
164 const OUString rStr = itr->second;
165 ScRange aRange = get_range_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
166 ScDBFunc* pFunc = getDBFunc();
167 pFunc->MarkRange(aRange, true, bExtend);
168 mxGridWindow->CursorChanged();
169 }
170 else if (rParameters.find("TABLE") != rParameters.end())
171 {
172 auto itr = rParameters.find("TABLE");
173 const OUString rStr = itr->second;
174 sal_Int32 nTab = rStr.toUInt32();
175 ScTabView* pTabView = mxGridWindow->getViewData().GetView();
176 if (pTabView)
177 {
178 ScDocument& rDoc = mxGridWindow->getViewData().GetDocument();
179 if( nTab < rDoc.GetTableCount() )
180 pTabView->SetTabNo(nTab);
181 else
182 {
183 SAL_WARN("sc.uitest", "incorrect table number");
184 }
185 }
186 }
187 else if (rParameters.find("OBJECT") != rParameters.end())
188 {
189 auto itr = rParameters.find("OBJECT");
190 const OUString rStr = itr->second;
191
192 ScDrawView* pDrawView = getDrawView();
193 pDrawView->SelectObject(rStr);
194 }
195 else
196 {
197 SAL_WARN("sc.uitest", "unknown selection method");
198 }
199 }
200 else if (rAction == "DESELECT")
201 {
202 if (rParameters.find("OBJECT") != rParameters.end())
203 {
204 ScDrawView* pDrawView = getDrawView();
205 pDrawView->UnmarkAll();
206
207 ScTabViewShell* pViewShell = getViewShell();
208 pViewShell->SetDrawShell(false);
209 }
210 }
211 else if (rAction == "ACTIVATE")
212 {
213 ScDrawView* pDrawView = getDrawView();
214 const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
215 if (rMarkList.GetMarkCount() == 1)
216 {
217 SdrMark* pMark = rMarkList.GetMark(0);
218 SdrObject* pObj = pMark->GetMarkedSdrObj();
219 SdrObjKind nSdrObjKind = pObj->GetObjIdentifier();
220 if (nSdrObjKind == SdrObjKind::OLE2)
221 {
222 ScTabViewShell* pViewShell = getViewShell();
223 pViewShell->ActivateObject(static_cast<SdrOle2Obj*>(pObj), css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY);
224 }
225 else
226 {
227 SAL_WARN("sc.uitest", "can't activate non-ole objects");
228 }
229 }
230 else
231 SAL_WARN("sc.uitest", "can't activate the current selection");
232 }
233 else if (rAction == "LAUNCH")
234 {
235 if ( rParameters.find("AUTOFILTER") != rParameters.end())
236 {
237 auto itrCol = rParameters.find("COL");
238 if (itrCol == rParameters.end())
239 {
240 SAL_WARN("sc.uitest", "missing COL parameter");
241 return;
242 }
243
244 auto itrRow = rParameters.find("ROW");
245 if (itrRow == rParameters.end())
246 {
247 SAL_WARN("sc.uitest", "missing ROW parameter");
248 return;
249 }
250 SCROW nRow = itrRow->second.toUInt32();
251 SCCOL nCol = itrCol->second.toUInt32();
252 mxGridWindow->LaunchAutoFilterMenu(nCol, nRow);
253 }
254 else if ( rParameters.find("PIVOTTABLE") != rParameters.end())
255 {
256 auto itrCol = rParameters.find("COL");
257 if (itrCol == rParameters.end())
258 {
259 SAL_WARN("sc.uitest", "missing COL parameter");
260 return;
261 }
262
263 auto itrRow = rParameters.find("ROW");
264 if (itrRow == rParameters.end())
265 {
266 SAL_WARN("sc.uitest", "missing ROW parameter");
267 return;
268 }
269 SCROW nRow = itrRow->second.toUInt32();
270 SCCOL nCol = itrCol->second.toUInt32();
271 mxGridWindow->LaunchDPFieldMenu(nCol, nRow);
272 }
273 else if ( rParameters.find("SELECTMENU") != rParameters.end())
274 {
275 auto itrCol = rParameters.find("COL");
276 if (itrCol == rParameters.end())
277 {
278 SAL_WARN("sc.uitest", "missing COL parameter");
279 return;
280 }
281
282 auto itrRow = rParameters.find("ROW");
283 if (itrRow == rParameters.end())
284 {
285 SAL_WARN("sc.uitest", "missing ROW parameter");
286 return;
287 }
288 SCROW nRow = itrRow->second.toUInt32();
289 SCCOL nCol = itrCol->second.toUInt32();
290 mxGridWindow->LaunchDataSelectMenu(nCol, nRow);
291 }
292 }
293 else if (rAction == "COMMENT")
294 {
295 if ( rParameters.find("OPEN") != rParameters.end() )
296 {
297 ScViewFunc* pViewFunc = getViewFunc();
298 pViewFunc->EditNote();
299 }
300 else if ( rParameters.find("CLOSE") != rParameters.end() )
301 {
302 FuDraw* pDraw = dynamic_cast<FuDraw*>(getViewFunc()->GetDrawFuncPtr());
303 assert(pDraw);
304 ScViewData& rViewData = mxGridWindow->getViewData();
305 rViewData.GetDispatcher().Execute( pDraw->GetSlotID() , SfxCallMode::SLOT | SfxCallMode::RECORD );
306 }
307 else if ( rParameters.find("SETTEXT") != rParameters.end() )
308 {
309 auto itr = rParameters.find("SETTEXT");
310 const OUString rStr = itr->second;
311 ScDocument& rDoc = mxGridWindow->getViewData().GetDocument();
312 ScAddress aPos( mxGridWindow->getViewData().GetCurX() , mxGridWindow->getViewData().GetCurY() , mxGridWindow->getViewData().GetTabNo() );
313 rDoc.GetOrCreateNote( aPos )->SetText( aPos , rStr );
314 }
315 }
316 else if (rAction == "SIDEBAR")
317 {
319 DBG_ASSERT(pViewFrm, "ScGridWinUIObject::execute: no viewframe");
320 pViewFrm->ShowChildWindow(SID_SIDEBAR);
321
322 auto itr = rParameters.find("PANEL");
323 if (itr != rParameters.end())
324 {
325 OUString aVal = itr->second;
327 }
328 }
329 else if (rAction == "SET")
330 {
331 if (rParameters.find("ZOOM") != rParameters.end())
332 {
333 auto itr = rParameters.find("ZOOM");
334 OUString aVal = itr->second;
335 sal_Int32 nVal = aVal.toInt32();
336 ScTabViewShell* pViewShell = getViewShell();
337 ScModule* pScMod = SC_MOD();
338 if( nVal )
339 {
340 ScAppOptions aNewOpt = pScMod->GetAppOptions();
341 aNewOpt.SetZoom( nVal );
342 pScMod->SetAppOptions( aNewOpt );
343 Fraction aFract( nVal, 100 );
344 pViewShell->SetZoom( aFract, aFract, true );
345 pViewShell->PaintGrid();
346 pViewShell->PaintTop();
347 pViewShell->PaintLeft();
348 }
349 }
350 }
351 else
352 {
353 WindowUIObject::execute(rAction, rParameters);
354 }
355}
356
357namespace {
358
359ScDrawLayer* get_draw_layer(VclPtr<ScGridWindow> const & xGridWindow)
360{
361 return xGridWindow->getViewData().GetDocument().GetDrawLayer();
362}
363
364SdrPage* get_draw_page(VclPtr<ScGridWindow> const & xGridWindow, SCTAB nTab)
365{
366 ScDrawLayer* pDrawLayer = get_draw_layer(xGridWindow);
367
368 return pDrawLayer->GetPage(nTab);
369}
370
371std::set<OUString> collect_charts(VclPtr<ScGridWindow> const & xGridWindow)
372{
373 SCTAB nTab = xGridWindow->getViewData().GetTabNo();
374 SdrPage* pPage = get_draw_page(xGridWindow, nTab);
375
376 std::set<OUString> aRet;
377
378 if (!pPage)
379 return aRet;
380
381 SdrObjListIter aIter( pPage, SdrIterMode::Flat );
382 SdrObject* pObject = aIter.Next();
383 while (pObject)
384 {
385 if (pObject->GetObjIdentifier() == SdrObjKind::OLE2)
386 {
387 aRet.insert(static_cast<SdrOle2Obj*>(pObject)->GetPersistName());
388 }
389 pObject = aIter.Next();
390 }
391
392 return aRet;
393}
394
395}
396
397std::set<OUString> ScGridWinUIObject::get_children() const
398{
399 std::set<OUString> aChildren = collect_charts(mxGridWindow);
400 return aChildren;
401}
402
403std::unique_ptr<UIObject> ScGridWinUIObject::get_child(const OUString& /*rID*/)
404{
405 return nullptr;
406}
407
408std::unique_ptr<UIObject> ScGridWinUIObject::create(vcl::Window* pWindow)
409{
410 ScGridWindow* pGridWin = dynamic_cast<ScGridWindow*>(pWindow);
411 assert(pGridWin);
412 return std::unique_ptr<UIObject>(new ScGridWinUIObject(pGridWin));
413}
414
416{
417 return "ScGridWinUIObject";
418}
419
420/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for all Drawmodule specific functions.
Definition: fudraw.hxx:28
sal_uInt16 GetSlotID() const
Definition: fupoor.hxx:90
sal_uInt16 GetZoom() const
Definition: appoptio.hxx:42
void SetZoom(sal_uInt16 nNew)
Definition: appoptio.hxx:41
SC_DLLPUBLIC bool GetPrintAreaVer(SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol, SCROW &rEndRow, bool bNotes) const
Definition: documen2.cxx:657
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6587
SC_DLLPUBLIC bool GetPrintAreaHor(SCTAB nTab, SCROW nStartRow, SCROW nEndRow, SCCOL &rEndCol) const
Definition: documen2.cxx:635
SC_DLLPUBLIC bool HasNote(const ScAddress &rPos) const
Definition: document.cxx:6618
SC_DLLPUBLIC ScPostIt * GetOrCreateNote(const ScAddress &rPos)
Definition: document.cxx:6696
SC_DLLPUBLIC bool GetDataStart(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow) const
Definition: documen2.cxx:679
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
bool SelectObject(std::u16string_view rName)
Definition: drawview.cxx:725
ScDrawView * getDrawView()
Definition: uiobject.cxx:115
VclPtr< ScGridWindow > mxGridWindow
Definition: uiobject.hxx:22
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:139
virtual OUString get_name() const override
Definition: uiobject.cxx:415
ScDBFunc * getDBFunc()
Definition: uiobject.cxx:107
ScViewFunc * getViewFunc()
Definition: uiobject.cxx:131
ScGridWinUIObject(const VclPtr< ScGridWindow > &xGridWin)
Definition: uiobject.cxx:57
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:408
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:397
virtual StringMap get_state() override
Definition: uiobject.cxx:63
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Definition: uiobject.cxx:403
ScTabViewShell * getViewShell()
Definition: uiobject.cxx:123
SC_DLLPUBLIC const ScAppOptions & GetAppOptions()
Definition: scmod.cxx:799
SC_DLLPUBLIC void SetAppOptions(const ScAppOptions &rOpt)
Definition: scmod.cxx:786
Additional class containing cell annotation data.
Definition: postit.hxx:58
void SetText(const ScAddress &rPos, const OUString &rText)
Changes the caption text of this note.
Definition: postit.cxx:548
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:527
static bool GetAddressFromString(ScAddress &rAddress, std::u16string_view rAddressStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator=' ', sal_Unicode cQuote='\'')
String to Range core.
Definition: rangeutl.cxx:461
static bool GetRangeFromString(ScRange &rRange, std::u16string_view rRangeStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator=' ', sal_Unicode cQuote='\'')
static void GetStringFromRangeList(OUString &rString, const ScRangeList *pRangeList, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator=' ')
void ActivateObject(SdrOle2Obj *pObj, sal_Int32 nVerb)
Definition: tabvwshb.cxx:155
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:613
void PaintLeft()
Definition: tabview3.cxx:2734
FuPoor * GetDrawFuncPtr()
Definition: tabview.hxx:332
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1708
void SetZoom(const Fraction &rNewX, const Fraction &rNewY, bool bAll)
Definition: tabview5.cxx:424
void PaintTop()
Definition: tabview3.cxx:2667
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1819
void PaintGrid()
Definition: tabview3.cxx:2656
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3140
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
ScDBFunc * GetView() const
Definition: viewdata.cxx:864
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3174
void EditNote()
Definition: viewfun6.cxx:508
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
SdrObject * GetMarkedSdrObj() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
virtual SdrObjKind GetObjIdentifier() const
void UnmarkAll()
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxFrame & GetFrame() const
void ShowChildWindow(sal_uInt16, bool bVisible=true)
virtual StringMap get_state() override
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
static void ShowPanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
#define DBG_ASSERT(sCon, aError)
EmbeddedObjectRef * pObject
#define SAL_WARN(area, stream)
HashMap_OWString_Interface aMap
#define SC_MOD()
Definition: scmod.hxx:247
SdrObjKind
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
ScHSplitPos WhichH(ScSplitPos ePos)
Definition: viewdata.hxx:722
ScHSplitPos
Definition: viewdata.hxx:45
ScVSplitPos WhichV(ScSplitPos ePos)
Definition: viewdata.hxx:728
ScVSplitPos
Definition: viewdata.hxx:46
std::map< OUString, OUString > StringMap