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>
21 #include <sfx2/sidebar/Sidebar.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 
36 namespace {
37 
38 ScAddress get_address_from_string(const ScDocument& rDoc, const OUString& rStr)
39 {
40  ScAddress aAddr;
41  sal_Int32 nOffset = 0;
43  return aAddr;
44 }
45 
46 ScRange get_range_from_string(const ScDocument& rDoc, const OUString& rStr)
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 
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 
78  OUString aMarkedAreaString;
80 
81  aMap["MarkedArea"] = aMarkedAreaString;
82 
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 
129 void 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);
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);
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  {
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;
303  rDoc.GetOrCreateNote( aPos )->SetText( aPos , rStr );
304  }
305  }
306  else if (rAction == "SIDEBAR")
307  {
308  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
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 
347 namespace {
348 
349 ScDrawLayer* get_draw_layer(VclPtr<ScGridWindow> const & xGridWindow)
350 {
351  return xGridWindow->getViewData().GetDocument().GetDrawLayer();
352 }
353 
354 SdrPage* 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 
361 std::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 
387 std::set<OUString> ScGridWinUIObject::get_children() const
388 {
389  std::set<OUString> aChildren = collect_charts(mxGridWindow);
390  return aChildren;
391 }
392 
393 std::unique_ptr<UIObject> ScGridWinUIObject::get_child(const OUString& /*rID*/)
394 {
395  return nullptr;
396 }
397 
398 std::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: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3135
static void ShowPanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
void LaunchDPFieldMenu(SCCOL nCol, SCROW nRow)
Definition: gridwin.cxx:1233
size_t GetMarkCount() const
void SetText(const ScAddress &rPos, const OUString &rText)
Changes the caption text of this note.
Definition: postit.cxx:946
ScVSplitPos WhichV(ScSplitPos ePos)
Definition: viewdata.hxx:728
VclPtr< ScGridWindow > mxGridWindow
Definition: uiobject.hxx:22
static bool GetAddressFromString(ScAddress &rAddress, const OUString &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
ScVSplitPos
Definition: viewdata.hxx:46
void LaunchDataSelectMenu(SCCOL nCol, SCROW nRow)
Definition: gridwin.cxx:1377
SCROW GetCurY() const
Definition: viewdata.hxx:402
ScHSplitPos WhichH(ScSplitPos ePos)
Definition: viewdata.hxx:722
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void PaintGrid()
Definition: tabview3.cxx:2633
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
SdrMark * GetMark(size_t nNum) const
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
virtual StringMap get_state() override
Definition: uiobject.cxx:63
Base class for all Drawmodule specific functions.
Definition: fudraw.hxx:27
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:129
virtual SdrObjKind GetObjIdentifier() const
EmbeddedObjectRef * pObject
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1402
ScSplitPos
Definition: viewdata.hxx:44
SdrObjKind
HashMap_OWString_Interface aMap
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6716
void PaintLeft()
Definition: tabview3.cxx:2711
virtual StringMap get_state() override
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:315
Additional class containing cell annotation data.
Definition: postit.hxx:160
void CursorChanged()
Definition: gridwin.cxx:6028
sal_uInt16 GetZoom() const
Definition: appoptio.hxx:42
SfxFrame & GetFrame() const
ScTabViewShell * getViewShell()
Definition: uiobject.cxx:113
void UnmarkAll()
SCROW GetPosY(ScVSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1416
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3163
sal_uInt16 GetSlotID() const
Definition: fupoor.hxx:90
void PaintTop()
Definition: tabview3.cxx:2644
static bool GetRangeFromString(ScRange &rRange, const OUString &rRangeStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
virtual OUString get_name() const override
Definition: uiobject.cxx:405
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
SdrObject * GetMarkedSdrObj() const
SC_DLLPUBLIC void SetAppOptions(const ScAppOptions &rOpt)
Definition: scmod.cxx:761
void SetZoom(const Fraction &rNewX, const Fraction &rNewY, bool bAll)
Definition: tabview5.cxx:427
SC_DLLPUBLIC ScPostIt * GetOrCreateNote(const ScAddress &rPos)
Definition: document.cxx:6824
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1081
ScViewFunc * getViewFunc()
Definition: uiobject.cxx:121
void LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
Definition: gridwin.cxx:837
#define DBG_ASSERT(sCon, aError)
bool SelectObject(std::u16string_view rName)
Definition: drawview.cxx:734
sal_Int16 SCCOL
Definition: types.hxx:21
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Definition: uiobject.cxx:393
#define SC_MOD()
Definition: scmod.hxx:249
const SdrMarkList & GetMarkedObjectList() const
static void GetStringFromRangeList(OUString &rString, const ScRangeList *pRangeList, const ScDocument *pDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator= ' ')
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1800
SC_DLLPUBLIC const ScAppOptions & GetAppOptions()
Definition: scmod.cxx:774
const SdrPage * GetPage(sal_uInt16 nPgNum) const
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:612
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:916
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:398
ScDrawView * getDrawView()
Definition: uiobject.cxx:105
void SetZoom(sal_uInt16 nNew)
Definition: appoptio.hxx:41
SC_DLLPUBLIC bool HasNote(const ScAddress &rPos) const
Definition: document.cxx:6741
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
ScDBFunc * GetView() const
Definition: viewdata.cxx:863
void ActivateObject(SdrOle2Obj *pObj, sal_Int32 nVerb)
Definition: tabvwshb.cxx:152
ScHSplitPos
Definition: viewdata.hxx:45
sal_Int32 SCROW
Definition: types.hxx:17
static SfxViewFrame * Current()
std::map< OUString, OUString > StringMap
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3129
ScDBFunc * getDBFunc()
Definition: uiobject.cxx:97
FuPoor * GetDrawFuncPtr()
Definition: tabview.hxx:321
void ShowChildWindow(sal_uInt16, bool bVisible=true)
ScRangeList GetMarkedRanges() const
Definition: markdata.cxx:450
#define SAL_WARN(area, stream)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
void EditNote()
Definition: viewfun6.cxx:492
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:387
ScViewData & getViewData()
Definition: gridwin.cxx:7066
ScGridWinUIObject(const VclPtr< ScGridWindow > &xGridWin)
Definition: uiobject.cxx:57
sal_Int16 SCTAB
Definition: types.hxx:22
SCCOL GetCurX() const
Definition: viewdata.hxx:401