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 ScAppOptions aOpt = SC_MOD()->GetAppOptions();
93 aMap["Zoom"] = OUString::number( aOpt.GetZoom() );
94 return aMap;
95}
96
98{
99 ScViewData& rViewData = mxGridWindow->getViewData();
100 ScDBFunc* pFunc = rViewData.GetView();
101
102 return pFunc;
103}
104
106{
107 ScViewData& rViewData = mxGridWindow->getViewData();
108 ScDrawView* pDrawView = rViewData.GetScDrawView();
109
110 return pDrawView;
111}
112
114{
115 ScViewData& rViewData = mxGridWindow->getViewData();
116 ScTabViewShell* pViewShell = rViewData.GetViewShell();
117
118 return pViewShell;
119}
120
122{
123 ScViewData& rViewData = mxGridWindow->getViewData();
124 ScViewFunc* pViewFunc = rViewData.GetView();
125
126 return pViewFunc;
127}
128
129void ScGridWinUIObject::execute(const OUString& rAction,
130 const StringMap& rParameters)
131{
132 if (rAction == "SELECT")
133 {
134 bool bExtend = false;
135 if (rParameters.find("EXTEND") != rParameters.end())
136 {
137 auto itr = rParameters.find("EXTEND");
138 if (itr->second.equalsIgnoreAsciiCase("true") || itr->second == "1")
139 bExtend = true;
140 }
141
142 if (rParameters.find("CELL") != rParameters.end())
143 {
144 auto itr = rParameters.find("CELL");
145 const OUString& rStr = itr->second;
146 ScAddress aAddr = get_address_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
147 ScDBFunc* pFunc = getDBFunc();
148 pFunc->MarkRange(ScRange(aAddr), true, bExtend);
149 mxGridWindow->CursorChanged();
150 }
151 else if (rParameters.find("RANGE") != rParameters.end())
152 {
153 auto itr = rParameters.find("RANGE");
154 const OUString rStr = itr->second;
155 ScRange aRange = get_range_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
156 ScDBFunc* pFunc = getDBFunc();
157 pFunc->MarkRange(aRange, true, bExtend);
158 mxGridWindow->CursorChanged();
159 }
160 else if (rParameters.find("TABLE") != rParameters.end())
161 {
162 auto itr = rParameters.find("TABLE");
163 const OUString rStr = itr->second;
164 sal_Int32 nTab = rStr.toUInt32();
165 ScTabView* pTabView = mxGridWindow->getViewData().GetView();
166 if (pTabView)
167 {
168 ScDocument& rDoc = mxGridWindow->getViewData().GetDocument();
169 if( nTab < rDoc.GetTableCount() )
170 pTabView->SetTabNo(nTab);
171 else
172 {
173 SAL_WARN("sc.uitest", "incorrect table number");
174 }
175 }
176 }
177 else if (rParameters.find("OBJECT") != rParameters.end())
178 {
179 auto itr = rParameters.find("OBJECT");
180 const OUString rStr = itr->second;
181
182 ScDrawView* pDrawView = getDrawView();
183 pDrawView->SelectObject(rStr);
184 }
185 else
186 {
187 SAL_WARN("sc.uitest", "unknown selection method");
188 }
189 }
190 else if (rAction == "DESELECT")
191 {
192 if (rParameters.find("OBJECT") != rParameters.end())
193 {
194 ScDrawView* pDrawView = getDrawView();
195 pDrawView->UnmarkAll();
196
197 ScTabViewShell* pViewShell = getViewShell();
198 pViewShell->SetDrawShell(false);
199 }
200 }
201 else if (rAction == "ACTIVATE")
202 {
203 ScDrawView* pDrawView = getDrawView();
204 const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
205 if (rMarkList.GetMarkCount() == 1)
206 {
207 SdrMark* pMark = rMarkList.GetMark(0);
208 SdrObject* pObj = pMark->GetMarkedSdrObj();
209 SdrObjKind nSdrObjKind = pObj->GetObjIdentifier();
210 if (nSdrObjKind == SdrObjKind::OLE2)
211 {
212 ScTabViewShell* pViewShell = getViewShell();
213 pViewShell->ActivateObject(static_cast<SdrOle2Obj*>(pObj), css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY);
214 }
215 else
216 {
217 SAL_WARN("sc.uitest", "can't activate non-ole objects");
218 }
219 }
220 else
221 SAL_WARN("sc.uitest", "can't activate the current selection");
222 }
223 else if (rAction == "LAUNCH")
224 {
225 if ( rParameters.find("AUTOFILTER") != rParameters.end())
226 {
227 auto itrCol = rParameters.find("COL");
228 if (itrCol == rParameters.end())
229 {
230 SAL_WARN("sc.uitest", "missing COL parameter");
231 return;
232 }
233
234 auto itrRow = rParameters.find("ROW");
235 if (itrRow == rParameters.end())
236 {
237 SAL_WARN("sc.uitest", "missing ROW parameter");
238 return;
239 }
240 SCROW nRow = itrRow->second.toUInt32();
241 SCCOL nCol = itrCol->second.toUInt32();
242 mxGridWindow->LaunchAutoFilterMenu(nCol, nRow);
243 }
244 else if ( rParameters.find("PIVOTTABLE") != rParameters.end())
245 {
246 auto itrCol = rParameters.find("COL");
247 if (itrCol == rParameters.end())
248 {
249 SAL_WARN("sc.uitest", "missing COL parameter");
250 return;
251 }
252
253 auto itrRow = rParameters.find("ROW");
254 if (itrRow == rParameters.end())
255 {
256 SAL_WARN("sc.uitest", "missing ROW parameter");
257 return;
258 }
259 SCROW nRow = itrRow->second.toUInt32();
260 SCCOL nCol = itrCol->second.toUInt32();
261 mxGridWindow->LaunchDPFieldMenu(nCol, nRow);
262 }
263 else if ( rParameters.find("SELECTMENU") != rParameters.end())
264 {
265 auto itrCol = rParameters.find("COL");
266 if (itrCol == rParameters.end())
267 {
268 SAL_WARN("sc.uitest", "missing COL parameter");
269 return;
270 }
271
272 auto itrRow = rParameters.find("ROW");
273 if (itrRow == rParameters.end())
274 {
275 SAL_WARN("sc.uitest", "missing ROW parameter");
276 return;
277 }
278 SCROW nRow = itrRow->second.toUInt32();
279 SCCOL nCol = itrCol->second.toUInt32();
280 mxGridWindow->LaunchDataSelectMenu(nCol, nRow);
281 }
282 }
283 else if (rAction == "COMMENT")
284 {
285 if ( rParameters.find("OPEN") != rParameters.end() )
286 {
287 ScViewFunc* pViewFunc = getViewFunc();
288 pViewFunc->EditNote();
289 }
290 else if ( rParameters.find("CLOSE") != rParameters.end() )
291 {
292 FuDraw* pDraw = dynamic_cast<FuDraw*>(getViewFunc()->GetDrawFuncPtr());
293 assert(pDraw);
294 ScViewData& rViewData = mxGridWindow->getViewData();
295 rViewData.GetDispatcher().Execute( pDraw->GetSlotID() , SfxCallMode::SLOT | SfxCallMode::RECORD );
296 }
297 else if ( rParameters.find("SETTEXT") != rParameters.end() )
298 {
299 auto itr = rParameters.find("SETTEXT");
300 const OUString rStr = itr->second;
301 ScDocument& rDoc = mxGridWindow->getViewData().GetDocument();
302 ScAddress aPos( mxGridWindow->getViewData().GetCurX() , mxGridWindow->getViewData().GetCurY() , mxGridWindow->getViewData().GetTabNo() );
303 rDoc.GetOrCreateNote( aPos )->SetText( aPos , rStr );
304 }
305 }
306 else if (rAction == "SIDEBAR")
307 {
309 DBG_ASSERT(pViewFrm, "ScGridWinUIObject::execute: no viewframe");
310 pViewFrm->ShowChildWindow(SID_SIDEBAR);
311
312 auto itr = rParameters.find("PANEL");
313 if (itr != rParameters.end())
314 {
315 OUString aVal = itr->second;
317 }
318 }
319 else if (rAction == "SET")
320 {
321 if (rParameters.find("ZOOM") != rParameters.end())
322 {
323 auto itr = rParameters.find("ZOOM");
324 OUString aVal = itr->second;
325 sal_Int32 nVal = aVal.toInt32();
326 ScTabViewShell* pViewShell = getViewShell();
327 ScModule* pScMod = SC_MOD();
328 if( nVal )
329 {
330 ScAppOptions aNewOpt = pScMod->GetAppOptions();
331 aNewOpt.SetZoom( nVal );
332 pScMod->SetAppOptions( aNewOpt );
333 Fraction aFract( nVal, 100 );
334 pViewShell->SetZoom( aFract, aFract, true );
335 pViewShell->PaintGrid();
336 pViewShell->PaintTop();
337 pViewShell->PaintLeft();
338 }
339 }
340 }
341 else
342 {
343 WindowUIObject::execute(rAction, rParameters);
344 }
345}
346
347namespace {
348
349ScDrawLayer* get_draw_layer(VclPtr<ScGridWindow> const & xGridWindow)
350{
351 return xGridWindow->getViewData().GetDocument().GetDrawLayer();
352}
353
354SdrPage* get_draw_page(VclPtr<ScGridWindow> const & xGridWindow, SCTAB nTab)
355{
356 ScDrawLayer* pDrawLayer = get_draw_layer(xGridWindow);
357
358 return pDrawLayer->GetPage(nTab);
359}
360
361std::set<OUString> collect_charts(VclPtr<ScGridWindow> const & xGridWindow)
362{
363 SCTAB nTab = xGridWindow->getViewData().GetTabNo();
364 SdrPage* pPage = get_draw_page(xGridWindow, nTab);
365
366 std::set<OUString> aRet;
367
368 if (!pPage)
369 return aRet;
370
371 SdrObjListIter aIter( pPage, SdrIterMode::Flat );
372 SdrObject* pObject = aIter.Next();
373 while (pObject)
374 {
375 if (pObject->GetObjIdentifier() == SdrObjKind::OLE2)
376 {
377 aRet.insert(static_cast<SdrOle2Obj*>(pObject)->GetPersistName());
378 }
379 pObject = aIter.Next();
380 }
381
382 return aRet;
383}
384
385}
386
387std::set<OUString> ScGridWinUIObject::get_children() const
388{
389 std::set<OUString> aChildren = collect_charts(mxGridWindow);
390 return aChildren;
391}
392
393std::unique_ptr<UIObject> ScGridWinUIObject::get_child(const OUString& /*rID*/)
394{
395 return nullptr;
396}
397
398std::unique_ptr<UIObject> ScGridWinUIObject::create(vcl::Window* pWindow)
399{
400 ScGridWindow* pGridWin = dynamic_cast<ScGridWindow*>(pWindow);
401 assert(pGridWin);
402 return std::unique_ptr<UIObject>(new ScGridWinUIObject(pGridWin));
403}
404
406{
407 return "ScGridWinUIObject";
408}
409
410/* 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 ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6730
SC_DLLPUBLIC bool HasNote(const ScAddress &rPos) const
Definition: document.cxx:6763
SC_DLLPUBLIC ScPostIt * GetOrCreateNote(const ScAddress &rPos)
Definition: document.cxx:6846
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:317
bool SelectObject(std::u16string_view rName)
Definition: drawview.cxx:734
ScDrawView * getDrawView()
Definition: uiobject.cxx:105
VclPtr< ScGridWindow > mxGridWindow
Definition: uiobject.hxx:22
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:129
virtual OUString get_name() const override
Definition: uiobject.cxx:405
ScDBFunc * getDBFunc()
Definition: uiobject.cxx:97
ScViewFunc * getViewFunc()
Definition: uiobject.cxx:121
ScGridWinUIObject(const VclPtr< ScGridWindow > &xGridWin)
Definition: uiobject.cxx:57
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:398
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:387
virtual StringMap get_state() override
Definition: uiobject.cxx:63
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Definition: uiobject.cxx:393
ScTabViewShell * getViewShell()
Definition: uiobject.cxx:113
SC_DLLPUBLIC const ScAppOptions & GetAppOptions()
Definition: scmod.cxx:774
SC_DLLPUBLIC void SetAppOptions(const ScAppOptions &rOpt)
Definition: scmod.cxx:761
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:581
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:551
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:323
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1711
void SetZoom(const Fraction &rNewX, const Fraction &rNewY, bool bAll)
Definition: tabview5.cxx:427
void PaintTop()
Definition: tabview3.cxx:2667
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1822
void PaintGrid()
Definition: tabview3.cxx:2656
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3135
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
ScDBFunc * GetView() const
Definition: viewdata.cxx:863
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3169
void EditNote()
Definition: viewfun6.cxx:492
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 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:249
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