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 <svx/svditer.hxx>
31 #include <svx/svdobj.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <sal/log.hxx>
34 
35 namespace {
36 
37 ScAddress get_address_from_string(const ScDocument& rDoc, const OUString& rStr)
38 {
39  ScAddress aAddr;
40  sal_Int32 nOffset = 0;
42  return aAddr;
43 }
44 
45 ScRange get_range_from_string(const ScDocument& rDoc, const OUString& rStr)
46 {
47  ScRange aRange;
48  sal_Int32 nOffset = 0;
50 
51  return aRange;
52 }
53 
54 }
55 
57  WindowUIObject(xGridWin),
58  mxGridWindow(xGridWin)
59 {
60 }
61 
63 {
65 
66  aMap["SelectedTable"] = OUString::number(mxGridWindow->getViewData().GetTabNo());
67  aMap["CurrentColumn"] = OUString::number(mxGridWindow->getViewData().GetCurX());
68  aMap["CurrentRow"] = OUString::number(mxGridWindow->getViewData().GetCurY());
69 
71  ScHSplitPos eAlignX = WhichH(eAlign);
72  ScVSplitPos eAlignY = WhichV(eAlign);
73  aMap["TopVisibleRow"] = OUString::number(mxGridWindow->getViewData().GetPosY(eAlignY));
74  aMap["TopVisibleColumn"] = OUString::number(mxGridWindow->getViewData().GetPosX(eAlignX));
75 
77  OUString aMarkedAreaString;
79 
80  aMap["MarkedArea"] = aMarkedAreaString;
81 
84  if ( rDoc.HasNote( aPos ) )
85  {
86  ScPostIt* pNote = rDoc.GetNote(aPos);
87  assert(pNote);
88  aMap["CurrentCellCommentText"] = pNote->GetText();
89  }
90 
91  ScAppOptions aOpt = SC_MOD()->GetAppOptions();
92  aMap["Zoom"] = OUString::number( aOpt.GetZoom() );
93  return aMap;
94 }
95 
97 {
98  ScViewData& rViewData = mxGridWindow->getViewData();
99  ScDBFunc* pFunc = rViewData.GetView();
100 
101  return pFunc;
102 }
103 
105 {
106  ScViewData& rViewData = mxGridWindow->getViewData();
107  ScDrawView* pDrawView = rViewData.GetScDrawView();
108 
109  return pDrawView;
110 }
111 
113 {
114  ScViewData& rViewData = mxGridWindow->getViewData();
115  ScTabViewShell* pViewShell = rViewData.GetViewShell();
116 
117  return pViewShell;
118 }
119 
121 {
122  ScViewData& rViewData = mxGridWindow->getViewData();
123  ScViewFunc* pViewFunc = rViewData.GetView();
124 
125  return pViewFunc;
126 }
127 
128 void ScGridWinUIObject::execute(const OUString& rAction,
129  const StringMap& rParameters)
130 {
131  if (rAction == "SELECT")
132  {
133  bool bExtend = false;
134  if (rParameters.find("EXTEND") != rParameters.end())
135  {
136  auto itr = rParameters.find("EXTEND");
137  if (itr->second.equalsIgnoreAsciiCase("true") || itr->second == "1")
138  bExtend = true;
139  }
140 
141  if (rParameters.find("CELL") != rParameters.end())
142  {
143  auto itr = rParameters.find("CELL");
144  const OUString& rStr = itr->second;
145  ScAddress aAddr = get_address_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
146  ScDBFunc* pFunc = getDBFunc();
147  pFunc->MarkRange(ScRange(aAddr), true, bExtend);
149  }
150  else if (rParameters.find("RANGE") != rParameters.end())
151  {
152  auto itr = rParameters.find("RANGE");
153  const OUString rStr = itr->second;
154  ScRange aRange = get_range_from_string(mxGridWindow->getViewData().GetDocument(), rStr);
155  ScDBFunc* pFunc = getDBFunc();
156  pFunc->MarkRange(aRange, true, bExtend);
158  }
159  else if (rParameters.find("TABLE") != rParameters.end())
160  {
161  auto itr = rParameters.find("TABLE");
162  const OUString rStr = itr->second;
163  sal_Int32 nTab = rStr.toUInt32();
164  ScTabView* pTabView = mxGridWindow->getViewData().GetView();
165  if (pTabView)
166  pTabView->SetTabNo(nTab);
167  }
168  else if (rParameters.find("OBJECT") != rParameters.end())
169  {
170  auto itr = rParameters.find("OBJECT");
171  const OUString rStr = itr->second;
172 
173  ScDrawView* pDrawView = getDrawView();
174  pDrawView->SelectObject(rStr);
175  }
176  else
177  {
178  SAL_WARN("sc.uitest", "unknown selection method");
179  }
180  }
181  else if (rAction == "DESELECT")
182  {
183  if (rParameters.find("OBJECT") != rParameters.end())
184  {
185  ScDrawView* pDrawView = getDrawView();
186  pDrawView->UnmarkAll();
187 
188  ScTabViewShell* pViewShell = getViewShell();
189  pViewShell->SetDrawShell(false);
190  }
191  }
192  else if (rAction == "ACTIVATE")
193  {
194  ScDrawView* pDrawView = getDrawView();
195  const SdrMarkList& rMarkList = pDrawView->GetMarkedObjectList();
196  if (rMarkList.GetMarkCount() == 1)
197  {
198  SdrMark* pMark = rMarkList.GetMark(0);
199  SdrObject* pObj = pMark->GetMarkedSdrObj();
200  sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
201  if (nSdrObjKind == OBJ_OLE2)
202  {
203  ScTabViewShell* pViewShell = getViewShell();
204  pViewShell->ActivateObject( static_cast<SdrOle2Obj*>(pObj), 0 );
205  }
206  else
207  {
208  SAL_WARN("sc.uitest", "can't activate non-ole objects");
209  }
210  }
211  else
212  SAL_WARN("sc.uitest", "can't activate the current selection");
213  }
214  else if (rAction == "LAUNCH")
215  {
216  if ( rParameters.find("AUTOFILTER") != rParameters.end())
217  {
218  auto itrCol = rParameters.find("COL");
219  if (itrCol == rParameters.end())
220  {
221  SAL_WARN("sc.uitest", "missing COL parameter");
222  return;
223  }
224 
225  auto itrRow = rParameters.find("ROW");
226  if (itrRow == rParameters.end())
227  {
228  SAL_WARN("sc.uitest", "missing ROW parameter");
229  return;
230  }
231  SCROW nRow = itrRow->second.toUInt32();
232  SCCOL nCol = itrCol->second.toUInt32();
233  mxGridWindow->LaunchAutoFilterMenu(nCol, nRow);
234  }
235  else if ( rParameters.find("SELECTMENU") != 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->LaunchDataSelectMenu(nCol, nRow);
253  }
254  }
255  else if (rAction == "COMMENT")
256  {
257  if ( rParameters.find("OPEN") != rParameters.end() )
258  {
259  ScViewFunc* pViewFunc = getViewFunc();
260  pViewFunc->EditNote();
261  }
262  else if ( rParameters.find("CLOSE") != rParameters.end() )
263  {
264  FuDraw* pDraw = dynamic_cast<FuDraw*>(getViewFunc()->GetDrawFuncPtr());
265  assert(pDraw);
266  ScViewData& rViewData = mxGridWindow->getViewData();
267  rViewData.GetDispatcher().Execute( pDraw->GetSlotID() , SfxCallMode::SLOT | SfxCallMode::RECORD );
268  }
269  else if ( rParameters.find("SETTEXT") != rParameters.end() )
270  {
271  auto itr = rParameters.find("SETTEXT");
272  const OUString rStr = itr->second;
275  rDoc.GetOrCreateNote( aPos )->SetText( aPos , rStr );
276  }
277  }
278  else if (rAction == "SIDEBAR")
279  {
280  SfxViewFrame* pViewFrm = SfxViewFrame::Current();
281  DBG_ASSERT(pViewFrm, "ScGridWinUIObject::execute: no viewframe");
282  pViewFrm->ShowChildWindow(SID_SIDEBAR);
283 
284  auto itr = rParameters.find("PANEL");
285  if (itr != rParameters.end())
286  {
287  OUString aVal = itr->second;
289  }
290  }
291  else if (rAction == "SET")
292  {
293  if (rParameters.find("ZOOM") != rParameters.end())
294  {
295  auto itr = rParameters.find("ZOOM");
296  OUString aVal = itr->second;
297  sal_Int32 nVal = aVal.toInt32();
298  ScTabViewShell* pViewShell = getViewShell();
299  ScModule* pScMod = SC_MOD();
300  if( nVal )
301  {
302  ScAppOptions aNewOpt = pScMod->GetAppOptions();
303  aNewOpt.SetZoom( nVal );
304  pScMod->SetAppOptions( aNewOpt );
305  Fraction aFract( nVal, 100 );
306  pViewShell->SetZoom( aFract, aFract, true );
307  pViewShell->PaintGrid();
308  pViewShell->PaintTop();
309  pViewShell->PaintLeft();
310  }
311  }
312  }
313  else
314  {
315  WindowUIObject::execute(rAction, rParameters);
316  }
317 }
318 
319 namespace {
320 
321 ScDrawLayer* get_draw_layer(VclPtr<ScGridWindow> const & xGridWindow)
322 {
323  return xGridWindow->getViewData().GetDocument().GetDrawLayer();
324 }
325 
326 SdrPage* get_draw_page(VclPtr<ScGridWindow> const & xGridWindow, SCTAB nTab)
327 {
328  ScDrawLayer* pDrawLayer = get_draw_layer(xGridWindow);
329 
330  return pDrawLayer->GetPage(nTab);
331 }
332 
333 std::set<OUString> collect_charts(VclPtr<ScGridWindow> const & xGridWindow)
334 {
335  SCTAB nTab = xGridWindow->getViewData().GetTabNo();
336  SdrPage* pPage = get_draw_page(xGridWindow, nTab);
337 
338  std::set<OUString> aRet;
339 
340  if (!pPage)
341  return aRet;
342 
343  SdrObjListIter aIter( pPage, SdrIterMode::Flat );
344  SdrObject* pObject = aIter.Next();
345  while (pObject)
346  {
347  if (pObject->GetObjIdentifier() == OBJ_OLE2)
348  {
349  aRet.insert(static_cast<SdrOle2Obj*>(pObject)->GetPersistName());
350  }
351  pObject = aIter.Next();
352  }
353 
354  return aRet;
355 }
356 
357 }
358 
359 std::set<OUString> ScGridWinUIObject::get_children() const
360 {
361  std::set<OUString> aChildren = collect_charts(mxGridWindow);
362  return aChildren;
363 }
364 
365 std::unique_ptr<UIObject> ScGridWinUIObject::get_child(const OUString& /*rID*/)
366 {
367  return nullptr;
368 }
369 
370 std::unique_ptr<UIObject> ScGridWinUIObject::create(vcl::Window* pWindow)
371 {
372  ScGridWindow* pGridWin = dynamic_cast<ScGridWindow*>(pWindow);
373  assert(pGridWin);
374  return std::unique_ptr<UIObject>(new ScGridWinUIObject(pGridWin));
375 }
376 
378 {
379  return "ScGridWinUIObject";
380 }
381 
383  WindowUIObject(xScNavigatorDlg),
384  mxScNavigatorDlg(xScNavigatorDlg)
385 {
386 }
387 
388 void ScNavigatorDlgUIObject::execute(const OUString& rAction,
389  const StringMap& rParameters)
390 {
391  if (rAction == "ROOT")
392  {
393  mxScNavigatorDlg->ToolBoxSelectHdl("toggle");
394  }
395  else
396  WindowUIObject::execute(rAction, rParameters);
397 }
398 
399 std::unique_ptr<UIObject> ScNavigatorDlgUIObject::create(vcl::Window* pWindow)
400 {
401  ScNavigatorDlg* pScNavigatorDlg = dynamic_cast<ScNavigatorDlg*>(pWindow);
402  assert(pScNavigatorDlg);
403  return std::unique_ptr<UIObject>(new ScNavigatorDlgUIObject(pScNavigatorDlg));
404 }
405 
407 {
408  return "ScNavigatorDlgUIObject";
409 }
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3046
size_t GetMarkCount() const
void SetText(const ScAddress &rPos, const OUString &rText)
Changes the caption text of this note.
Definition: postit.cxx:943
ScVSplitPos WhichV(ScSplitPos ePos)
Definition: viewdata.hxx:710
void ActivateObject(SdrOle2Obj *pObj, tools::Long nVerb)
Definition: tabvwshb.cxx:144
OBJ_OLE2
VclPtr< ScGridWindow > mxGridWindow
Definition: uiobject.hxx:21
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:435
ScVSplitPos
Definition: viewdata.hxx:47
void LaunchDataSelectMenu(SCCOL nCol, SCROW nRow)
Definition: gridwin.cxx:1075
virtual OUString get_name() const override
Definition: uiobject.cxx:406
SCROW GetCurY() const
Definition: viewdata.hxx:402
ScHSplitPos WhichH(ScSplitPos ePos)
Definition: viewdata.hxx:704
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void PaintGrid()
Definition: tabview3.cxx:2621
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:62
Base class for all Drawmodule specific functions.
Definition: fudraw.hxx:28
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:128
EmbeddedObjectRef * pObject
SCCOL GetPosX(ScHSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1341
ScSplitPos
Definition: viewdata.hxx:45
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:6508
void PaintLeft()
Definition: tabview3.cxx:2697
virtual StringMap get_state() override
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Additional class containing cell annotation data.
Definition: postit.hxx:160
void CursorChanged()
Definition: gridwin.cxx:5837
sal_uInt16 GetZoom() const
Definition: appoptio.hxx:43
SfxFrame & GetFrame() const
ScTabViewShell * getViewShell()
Definition: uiobject.cxx:112
void UnmarkAll()
SCROW GetPosY(ScVSplitPos eWhich, SCTAB nForTab=-1) const
Definition: viewdata.cxx:1355
ScDrawView * GetScDrawView()
Definition: viewdata.cxx:3074
sal_uInt16 GetSlotID() const
Definition: fupoor.hxx:91
void PaintTop()
Definition: tabview3.cxx:2632
const SvXMLTokenMapEntry aChildren[]
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:377
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
SdrObject * GetMarkedSdrObj() const
SC_DLLPUBLIC void SetAppOptions(const ScAppOptions &rOpt)
Definition: scmod.cxx:719
void SetZoom(const Fraction &rNewX, const Fraction &rNewY, bool bAll)
Definition: tabview5.cxx:413
SC_DLLPUBLIC ScPostIt * GetOrCreateNote(const ScAddress &rPos)
Definition: document.cxx:6599
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1059
ScViewFunc * getViewFunc()
Definition: uiobject.cxx:120
void LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow)
Definition: gridwin.cxx:592
#define DBG_ASSERT(sCon, aError)
virtual sal_uInt16 GetObjIdentifier() const
sal_Int16 SCCOL
Definition: types.hxx:22
virtual std::unique_ptr< UIObject > get_child(const OUString &rID) override
Definition: uiobject.cxx:365
#define SC_MOD()
Definition: scmod.hxx:253
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:1793
SC_DLLPUBLIC const ScAppOptions & GetAppOptions()
Definition: scmod.cxx:732
const SdrPage * GetPage(sal_uInt16 nPgNum) const
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:596
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:913
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:370
static void ShowPanel(const OUString &rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
ScDrawView * getDrawView()
Definition: uiobject.cxx:104
void SetZoom(sal_uInt16 nNew)
Definition: appoptio.hxx:42
SC_DLLPUBLIC bool HasNote(const ScAddress &rPos) const
Definition: document.cxx:6533
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
ScDBFunc * GetView() const
Definition: viewdata.cxx:852
bool SelectObject(const OUString &rName)
Definition: drawview.cxx:730
virtual void execute(const OUString &rAction, const StringMap &rParameters) override
Definition: uiobject.cxx:388
ScHSplitPos
Definition: viewdata.hxx:46
sal_Int32 SCROW
Definition: types.hxx:18
static std::unique_ptr< UIObject > create(vcl::Window *pWindow)
Definition: uiobject.cxx:399
static SfxViewFrame * Current()
std::map< OUString, OUString > StringMap
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3040
ScDBFunc * getDBFunc()
Definition: uiobject.cxx:96
FuPoor * GetDrawFuncPtr()
Definition: tabview.hxx:320
void ShowChildWindow(sal_uInt16, bool bVisible=true)
ScRangeList GetMarkedRanges() const
Definition: markdata.cxx:465
#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:490
virtual std::set< OUString > get_children() const override
Definition: uiobject.cxx:359
ScViewData & getViewData()
Definition: gridwin.cxx:6753
ScGridWinUIObject(const VclPtr< ScGridWindow > &xGridWin)
Definition: uiobject.cxx:56
sal_Int16 SCTAB
Definition: types.hxx:23
ScNavigatorDlgUIObject(const VclPtr< ScNavigatorDlg > &xScNavigatorDlg)
Definition: uiobject.cxx:382
VclPtr< ScNavigatorDlg > mxScNavigatorDlg
Definition: uiobject.hxx:54
SCCOL GetCurX() const
Definition: viewdata.hxx:401