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 <navipi.hxx>
22 #include <sfx2/sidebar/Sidebar.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <appoptio.hxx>
26 #include <scmod.hxx>
27 #include <fudraw.hxx>
28 #include <postit.hxx>
29 
30 #include <com/sun/star/embed/EmbedVerbs.hpp>
31 
32 #include <svx/svditer.hxx>
33 #include <svx/svdobj.hxx>
34 #include <svx/svdoole2.hxx>
35 #include <sal/log.hxx>
36 
37 namespace {
38 
39 ScAddress get_address_from_string(const ScDocument& rDoc, const OUString& rStr)
40 {
41  ScAddress aAddr;
42  sal_Int32 nOffset = 0;
44  return aAddr;
45 }
46 
47 ScRange get_range_from_string(const ScDocument& rDoc, const OUString& rStr)
48 {
49  ScRange aRange;
50  sal_Int32 nOffset = 0;
52 
53  return aRange;
54 }
55 
56 }
57 
59  WindowUIObject(xGridWin),
60  mxGridWindow(xGridWin)
61 {
62 }
63 
65 {
67 
68  aMap["SelectedTable"] = OUString::number(mxGridWindow->getViewData().GetTabNo());
69  aMap["CurrentColumn"] = OUString::number(mxGridWindow->getViewData().GetCurX());
70  aMap["CurrentRow"] = OUString::number(mxGridWindow->getViewData().GetCurY());
71 
73  ScHSplitPos eAlignX = WhichH(eAlign);
74  ScVSplitPos eAlignY = WhichV(eAlign);
75  aMap["TopVisibleRow"] = OUString::number(mxGridWindow->getViewData().GetPosY(eAlignY));
76  aMap["TopVisibleColumn"] = OUString::number(mxGridWindow->getViewData().GetPosX(eAlignX));
77 
79  OUString aMarkedAreaString;
81 
82  aMap["MarkedArea"] = aMarkedAreaString;
83 
86  if ( rDoc.HasNote( aPos ) )
87  {
88  ScPostIt* pNote = rDoc.GetNote(aPos);
89  assert(pNote);
90  aMap["CurrentCellCommentText"] = pNote->GetText();
91  }
92 
93  ScAppOptions aOpt = SC_MOD()->GetAppOptions();
94  aMap["Zoom"] = OUString::number( aOpt.GetZoom() );
95  return aMap;
96 }
97 
99 {
100  ScViewData& rViewData = mxGridWindow->getViewData();
101  ScDBFunc* pFunc = rViewData.GetView();
102 
103  return pFunc;
104 }
105 
107 {
108  ScViewData& rViewData = mxGridWindow->getViewData();
109  ScDrawView* pDrawView = rViewData.GetScDrawView();
110 
111  return pDrawView;
112 }
113 
115 {
116  ScViewData& rViewData = mxGridWindow->getViewData();
117  ScTabViewShell* pViewShell = rViewData.GetViewShell();
118 
119  return pViewShell;
120 }
121 
123 {
124  ScViewData& rViewData = mxGridWindow->getViewData();
125  ScViewFunc* pViewFunc = rViewData.GetView();
126 
127  return pViewFunc;
128 }
129 
130 void ScGridWinUIObject::execute(const OUString& rAction,
131  const StringMap& rParameters)
132 {
133  if (rAction == "SELECT")
134  {
135  bool bExtend = false;
136  if (rParameters.find("EXTEND") != rParameters.end())
137  {
138  auto itr = rParameters.find("EXTEND");
139  if (itr->second.equalsIgnoreAsciiCase("true") || itr->second == "1")
140  bExtend = true;
141  }
142 
143  if (rParameters.find("CELL") != rParameters.end())
144  {
145  auto itr = rParameters.find("CELL");
146  const OUString& rStr = itr->second;
147  ScAddress aAddr = get_address_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
148  ScDBFunc* pFunc = getDBFunc();
149  pFunc->MarkRange(ScRange(aAddr), true, bExtend);
151  }
152  else if (rParameters.find("RANGE") != rParameters.end())
153  {
154  auto itr = rParameters.find("RANGE");
155  const OUString rStr = itr->second;
156  ScRange aRange = get_range_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
157  ScDBFunc* pFunc = getDBFunc();
158  pFunc->MarkRange(aRange, true, bExtend);
160  }
161  else if (rParameters.find("TABLE") != rParameters.end())
162  {
163  auto itr = rParameters.find("TABLE");
164  const OUString rStr = itr->second;
165  sal_Int32 nTab = rStr.toUInt32();
166  ScTabView* pTabView = mxGridWindow->getViewData().GetView();
167  if (pTabView)
168  pTabView->SetTabNo(nTab);
169  }
170  else if (rParameters.find("OBJECT") != rParameters.end())
171  {
172  auto itr = rParameters.find("OBJECT");
173  const OUString rStr = itr->second;
174 
175  ScDrawView* pDrawView = getDrawView();
176  pDrawView->SelectObject(rStr);
177  }
178  else
179  {
180  SAL_WARN("sc.uitest", "unknown selection method");
181  }
182  }
183  else if (rAction == "DESELECT")
184  {
185  if (rParameters.find("OBJECT") != rParameters.end())
186  {
187  ScDrawView* pDrawView = getDrawView();
188  pDrawView->UnmarkAll();
189 
190  ScTabViewShell* pViewShell = getViewShell();
191  pViewShell->SetDrawShell(false);
192  }
193  }
194  else if (rAction == "ACTIVATE")
195  {
196  ScDrawView* pDrawView = getDrawView();
197  const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
198  if (rMarkList.GetMarkCount() == 1)
199  {
200  SdrMark* pMark = rMarkList.GetMark(0);
201  SdrObject* pObj = pMark->GetMarkedSdrObj();
202  sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
203  if (nSdrObjKind == OBJ_OLE2)
204  {
205  ScTabViewShell* pViewShell = getViewShell();
206  pViewShell->ActivateObject(static_cast<SdrOle2Obj*>(pObj), css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY);
207  }
208  else
209  {
210  SAL_WARN("sc.uitest", "can't activate non-ole objects");
211  }
212  }
213  else
214  SAL_WARN("sc.uitest", "can't activate the current selection");
215  }
216  else if (rAction == "LAUNCH")
217  {
218  if ( rParameters.find("AUTOFILTER") != rParameters.end())
219  {
220  auto itrCol = rParameters.find("COL");
221  if (itrCol == rParameters.end())
222  {
223  SAL_WARN("sc.uitest", "missing COL parameter");
224  return;
225  }
226 
227  auto itrRow = rParameters.find("ROW");
228  if (itrRow == rParameters.end())
229  {
230  SAL_WARN("sc.uitest", "missing ROW parameter");
231  return;
232  }
233  SCROW nRow = itrRow->second.toUInt32();
234  SCCOL nCol = itrCol->second.toUInt32();
235  mxGridWindow->LaunchAutoFilterMenu(nCol, nRow);
236  }
237  else if ( rParameters.find("SELECTMENU") != rParameters.end())
238  {
239  auto itrCol = rParameters.find("COL");
240  if (itrCol == rParameters.end())
241  {
242  SAL_WARN("sc.uitest", "missing COL parameter");
243  return;
244  }
245 
246  auto itrRow = rParameters.find("ROW");
247  if (itrRow == rParameters.end())
248  {
249  SAL_WARN("sc.uitest", "missing ROW parameter");
250  return;
251  }
252  SCROW nRow = itrRow->second.toUInt32();
253  SCCOL nCol = itrCol->second.toUInt32();
254  mxGridWindow->LaunchDataSelectMenu(nCol, nRow);
255  }
256  }
257  else if (rAction == "COMMENT")
258  {
259  if ( rParameters.find("OPEN") != rParameters.end() )
260  {
261  ScViewFunc* pViewFunc = getViewFunc();
262  pViewFunc->EditNote();
263  }
264  else if ( rParameters.find("CLOSE") != rParameters.end() )
265  {
266  FuDraw* pDraw = dynamic_cast<FuDraw*>(getViewFunc()->GetDrawFuncPtr());
267  assert(pDraw);
268  ScViewData& rViewData = mxGridWindow->getViewData();
269  rViewData.GetDispatcher().Execute( pDraw->GetSlotID() , SfxCallMode::SLOT | SfxCallMode::RECORD );
270  }
271  else if ( rParameters.find("SETTEXT") != rParameters.end() )
272  {
273  auto itr = rParameters.find("SETTEXT");
274  const OUString rStr = itr->second;
277  rDoc.GetOrCreateNote( aPos )->SetText( aPos , rStr );
278  }
279  }
280  else if (rAction == "SIDEBAR")
281  {
282  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
283  DBG_ASSERT(pViewFrm, "ScGridWinUIObject::execute: no viewframe");
284  pViewFrm->ShowChildWindow(SID_SIDEBAR);
285 
286  auto itr = rParameters.find("PANEL");
287  if (itr != rParameters.end())
288  {
289  OUString aVal = itr->second;
291  }
292  }
293  else if (rAction == "SET")
294  {
295  if (rParameters.find("ZOOM") != rParameters.end())
296  {
297  auto itr = rParameters.find("ZOOM");
298  OUString aVal = itr->second;
299  sal_Int32 nVal = aVal.toInt32();
300  ScTabViewShell* pViewShell = getViewShell();
301  ScModule* pScMod = SC_MOD();
302  if( nVal )
303  {
304  ScAppOptions aNewOpt = pScMod->GetAppOptions();
305  aNewOpt.SetZoom( nVal );
306  pScMod->SetAppOptions( aNewOpt );
307  Fraction aFract( nVal, 100 );
308  pViewShell->SetZoom( aFract, aFract, true );
309  pViewShell->PaintGrid();
310  pViewShell->PaintTop();
311  pViewShell->PaintLeft();
312  }
313  }
314  }
315  else
316  {
317  WindowUIObject::execute(rAction, rParameters);
318  }
319 }
320 
321 namespace {
322 
323 ScDrawLayer* get_draw_layer(VclPtr<ScGridWindow> const & xGridWindow)
324 {
325  return xGridWindow->getViewData().GetDocument().GetDrawLayer();
326 }
327 
328 SdrPage* get_draw_page(VclPtr<ScGridWindow> const & xGridWindow, SCTAB nTab)
329 {
330  ScDrawLayer* pDrawLayer = get_draw_layer(xGridWindow);
331 
332  return pDrawLayer->GetPage(nTab);
333 }
334 
335 std::set<OUString> collect_charts(VclPtr<ScGridWindow> const & xGridWindow)
336 {
337  SCTAB nTab = xGridWindow->getViewData().GetTabNo();
338  SdrPage* pPage = get_draw_page(xGridWindow, nTab);
339 
340  std::set<OUString> aRet;
341 
342  if (!pPage)
343  return aRet;
344 
345  SdrObjListIter aIter( pPage, SdrIterMode::Flat );
346  SdrObject* pObject = aIter.Next();
347  while (pObject)
348  {
349  if (pObject->GetObjIdentifier() == OBJ_OLE2)
350  {
351  aRet.insert(static_cast<SdrOle2Obj*>(pObject)->GetPersistName());
352  }
353  pObject = aIter.Next();
354  }
355 
356  return aRet;
357 }
358 
359 }
360 
361 std::set<OUString> ScGridWinUIObject::get_children() const
362 {
363  std::set<OUString> aChildren = collect_charts(mxGridWindow);
364  return aChildren;
365 }
366 
367 std::unique_ptr<UIObject> ScGridWinUIObject::get_child(const OUString& /*rID*/)
368 {
369  return nullptr;
370 }
371 
372 std::unique_ptr<UIObject> ScGridWinUIObject::create(vcl::Window* pWindow)
373 {
374  ScGridWindow* pGridWin = dynamic_cast<ScGridWindow*>(pWindow);
375  assert(pGridWin);
376  return std::unique_ptr<UIObject>(new ScGridWinUIObject(pGridWin));
377 }
378 
380 {
381  return "ScGridWinUIObject";
382 }
383 
384 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3108
static void ShowPanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
size_t GetMarkCount() const
void SetText(const ScAddress &rPos, const OUString &rText)
Changes the caption text of this note.
Definition: postit.cxx:944
ScVSplitPos WhichV(ScSplitPos ePos)
Definition: viewdata.hxx:718
VclPtr< ScGridWindow > mxGridWindow
Definition: uiobject.hxx:23
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:453
ScVSplitPos
Definition: viewdata.hxx:46
void LaunchDataSelectMenu(SCCOL nCol, SCROW nRow)
Definition: gridwin.cxx:1178
SCROW GetCurY() const
Definition: viewdata.hxx:401
ScHSplitPos WhichH(ScSplitPos ePos)
Definition: viewdata.hxx:712
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
void PaintGrid()
Definition: tabview3.cxx:2628
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:397
SdrMark * GetMark(size_t nNum) const
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
virtual StringMap get_state() override
Definition: uiobject.cxx:64
Base class for all Drawmodule specific functions.
Definition: fudraw.hxx:27
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:130
virtual SdrObjKind GetObjIdentifier() const
EmbeddedObjectRef * pObject
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1400
ScSplitPos
Definition: viewdata.hxx:44
HashMap_OWString_Interface aMap
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Notes.
Definition: document.cxx:6534
void PaintLeft()
Definition: tabview3.cxx:2706
virtual StringMap get_state() override
Additional class containing cell annotation data.
Definition: postit.hxx:159
void CursorChanged()
Definition: gridwin.cxx:5836
sal_uInt16 GetZoom() const
Definition: appoptio.hxx:42
SfxFrame & GetFrame() const
ScTabViewShell * getViewShell()
Definition: uiobject.cxx:114
void UnmarkAll()
SCROW GetPosY(ScVSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1414
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3136
sal_uInt16 GetSlotID() const
Definition: fupoor.hxx:90
void PaintTop()
Definition: tabview3.cxx:2639
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:379
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:356
SdrObject * GetMarkedSdrObj() const
SC_DLLPUBLIC void SetAppOptions(const ScAppOptions &rOpt)
Definition: scmod.cxx:714
void SetZoom(const Fraction &rNewX, const Fraction &rNewY, bool bAll)
Definition: tabview5.cxx:429
SC_DLLPUBLIC ScPostIt * GetOrCreateNote(const ScAddress &rPos)
Definition: document.cxx:6639
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1058
ScViewFunc * getViewFunc()
Definition: uiobject.cxx:122
void LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
Definition: gridwin.cxx:573
#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:367
#define SC_MOD()
Definition: scmod.hxx:250
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:1798
SC_DLLPUBLIC const ScAppOptions & GetAppOptions()
Definition: scmod.cxx:727
const SdrPage * GetPage(sal_uInt16 nPgNum) const
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:611
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:914
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:372
ScDrawView * getDrawView()
Definition: uiobject.cxx:106
void SetZoom(sal_uInt16 nNew)
Definition: appoptio.hxx:41
SC_DLLPUBLIC bool HasNote(const ScAddress &rPos) const
Definition: document.cxx:6559
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
ScDBFunc * GetView() const
Definition: viewdata.cxx:861
void ActivateObject(SdrOle2Obj *pObj, sal_Int32 nVerb)
Definition: tabvwshb.cxx:145
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:3102
ScDBFunc * getDBFunc()
Definition: uiobject.cxx:98
FuPoor * GetDrawFuncPtr()
Definition: tabview.hxx:321
void ShowChildWindow(sal_uInt16, bool bVisible=true)
ScRangeList GetMarkedRanges() const
Definition: markdata.cxx:464
#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:491
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:361
OBJ_OLE2
ScViewData & getViewData()
Definition: gridwin.cxx:6754
ScGridWinUIObject(const VclPtr< ScGridWindow > &xGridWin)
Definition: uiobject.cxx:58
sal_Int16 SCTAB
Definition: types.hxx:22
SCCOL GetCurX() const
Definition: viewdata.hxx:400