LibreOffice Module reportdesign (master) 1
Navigator.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <Navigator.hxx>
21
22#include <strings.hxx>
23#include <bitmaps.hlst>
24#include <ReportController.hxx>
25#include <UITools.hxx>
26#include <reportformula.hxx>
27#include <com/sun/star/report/XFixedText.hpp>
28#include <com/sun/star/report/XFixedLine.hpp>
29#include <com/sun/star/report/XFormattedField.hpp>
30#include <com/sun/star/report/XImageControl.hpp>
31#include <com/sun/star/report/XShape.hpp>
32#include <helpids.h>
33#include <strings.hrc>
34#include <rptui_slotid.hrc>
40#include <utility>
41#include <vcl/svapp.hxx>
42#include <vcl/weld.hxx>
43#include <vcl/commandevent.hxx>
44#include <ReportVisitor.hxx>
45#include <core_resource.hxx>
46#include <rtl/ref.hxx>
47#include <svx/svxids.hrc>
48
49#include <memory>
50#include <string_view>
51
52namespace rptui
53{
54using namespace ::com::sun::star;
55using namespace utl;
56using namespace ::comphelper;
57
58static OUString lcl_getImageId(const uno::Reference< report::XReportComponent>& _xElement)
59{
60 OUString sId;
61 uno::Reference< report::XFixedLine> xFixedLine(_xElement,uno::UNO_QUERY);
62 if ( uno::Reference< report::XFixedText>(_xElement,uno::UNO_QUERY).is() )
63 sId = RID_SVXBMP_FM_FIXEDTEXT;
64 else if ( xFixedLine.is() )
65 sId = xFixedLine->getOrientation() ? OUString(RID_SVXBMP_INSERT_VFIXEDLINE) : OUString(RID_SVXBMP_INSERT_HFIXEDLINE);
66 else if ( uno::Reference< report::XFormattedField>(_xElement,uno::UNO_QUERY).is() )
67 sId = RID_SVXBMP_FM_EDIT;
68 else if ( uno::Reference< report::XImageControl>(_xElement,uno::UNO_QUERY).is() )
69 sId = RID_SVXBMP_FM_IMAGECONTROL;
70 else if ( uno::Reference< report::XShape>(_xElement,uno::UNO_QUERY).is() )
71 sId = RID_SVXBMP_DRAWTBX_CS_BASIC;
72 return sId;
73}
74
75static OUString lcl_getName(const uno::Reference< beans::XPropertySet>& _xElement)
76{
77 OSL_ENSURE(_xElement.is(),"Found report element which is NULL!");
78 OUString sTempName;
79 _xElement->getPropertyValue(PROPERTY_NAME) >>= sTempName;
80 OUStringBuffer sName(sTempName);
81 uno::Reference< report::XFixedText> xFixedText(_xElement,uno::UNO_QUERY);
82 uno::Reference< report::XReportControlModel> xReportModel(_xElement,uno::UNO_QUERY);
83 if ( xFixedText.is() )
84 {
85 sName.append(" : " + xFixedText->getLabel());
86 }
87 else if ( xReportModel.is() && _xElement->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
88 {
89 ReportFormula aFormula( xReportModel->getDataField() );
90 if ( aFormula.isValid() )
91 {
92 sName.append(" : " + aFormula.getUndecoratedContent() );
93 }
94 }
95 return sName.makeStringAndClear();
96}
97
102{
103 class UserData;
104 friend class UserData;
108 {
109 uno::Reference< uno::XInterface > m_xContent;
113 public:
114 UserData(NavigatorTree* pTree, uno::Reference<uno::XInterface> xContent);
115 virtual ~UserData() override;
116
117 const uno::Reference< uno::XInterface >& getContent() const { return m_xContent; }
118 void setContent(const uno::Reference< uno::XInterface >& _xContent) { m_xContent = _xContent; }
119
120 protected:
121 // OPropertyChangeListener
122 virtual void _propertyChanged(const beans::PropertyChangeEvent& _rEvent) override;
123
124 // OContainerListener
125 virtual void _elementInserted( const container::ContainerEvent& _rEvent ) override;
126 virtual void _elementRemoved( const container::ContainerEvent& Event ) override;
127 virtual void _elementReplaced( const container::ContainerEvent& _rEvent ) override;
128 virtual void _disposing(const lang::EventObject& _rSource) override;
129 };
130
131 std::unique_ptr<weld::TreeView> m_xTreeView;
133 std::unique_ptr<weld::TreeIter> m_xMasterReport;
136
137 void insertEntry(const OUString& rName, const weld::TreeIter* pParent, const OUString& rImageId, int nPosition, const UserData* pData, weld::TreeIter& rRet);
138
139 void traverseSection(const uno::Reference<report::XSection>& xSection, const weld::TreeIter* pParent, const OUString& rImageId, int nPosition = -1);
140 void traverseFunctions(const uno::Reference< report::XFunctions>& xFunctions, const weld::TreeIter* pParent);
141
142protected:
143 // OSelectionChangeListener
144 virtual void _disposing(const lang::EventObject& _rSource) override;
145
146 // OPropertyChangeListener
147 virtual void _propertyChanged(const beans::PropertyChangeEvent& _rEvent) override;
148
149 // OContainerListener Helper
150 void _elementInserted( const container::ContainerEvent& _rEvent );
151 void _elementRemoved( const container::ContainerEvent& Event );
152 void _elementReplaced( const container::ContainerEvent& _rEvent );
153
154public:
155 NavigatorTree(std::unique_ptr<weld::TreeView>, OReportController& rController);
156 virtual ~NavigatorTree() override;
157
158 DECL_LINK(OnEntrySelDesel, weld::TreeView&, void);
159 DECL_LINK(CommandHdl, const CommandEvent&, bool);
160
161 virtual void _selectionChanged( const lang::EventObject& aEvent ) override;
162
163 // ITraverseReport
164 virtual void traverseReport(const uno::Reference< report::XReportDefinition>& xReport) override;
165 virtual void traverseReportFunctions(const uno::Reference< report::XFunctions>& xFunctions) override;
166 virtual void traverseReportHeader(const uno::Reference< report::XSection>& xSection) override;
167 virtual void traverseReportFooter(const uno::Reference< report::XSection>& xSection) override;
168 virtual void traversePageHeader(const uno::Reference< report::XSection>& xSection) override;
169 virtual void traversePageFooter(const uno::Reference< report::XSection>& xSection) override;
170
171 virtual void traverseGroups(const uno::Reference< report::XGroups>& xGroups) override;
172 virtual void traverseGroup(const uno::Reference< report::XGroup>& xGroup) override;
173 virtual void traverseGroupFunctions(const uno::Reference< report::XFunctions>& xFunctions) override;
174 virtual void traverseGroupHeader(const uno::Reference< report::XSection>& xSection) override;
175 virtual void traverseGroupFooter(const uno::Reference< report::XSection>& xSection) override;
176
177 virtual void traverseDetail(const uno::Reference< report::XSection>& xSection) override;
178
179 bool find(const uno::Reference<uno::XInterface>& xContent, weld::TreeIter& rIter);
180 void removeEntry(const weld::TreeIter& rEntry, bool bRemove = true);
181
182 void grab_focus() { m_xTreeView->grab_focus(); }
183
184 void set_text(const weld::TreeIter& rIter, const OUString& rStr)
185 {
186 m_xTreeView->set_text(rIter, rStr);
187 }
188
189 void expand_row(const weld::TreeIter& rIter)
190 {
191 m_xTreeView->expand_row(rIter);
192 }
193
194 std::unique_ptr<weld::TreeIter> make_iterator() const
195 {
196 return m_xTreeView->make_iterator();
197 }
198
199 int iter_n_children(const weld::TreeIter& rIter) const
200 {
201 return m_xTreeView->iter_n_children(rIter);
202 }
203};
204
205NavigatorTree::NavigatorTree(std::unique_ptr<weld::TreeView> xTreeView, OReportController& rController)
207 , m_xTreeView(std::move(xTreeView))
208 , m_rController(rController)
209{
210 m_xTreeView->set_size_request(m_xTreeView->get_approximate_digit_width() * 25, m_xTreeView->get_height_rows(18));
211
217
219
221
222 m_xTreeView->set_selection_mode(SelectionMode::Multiple);
223
224 m_xTreeView->connect_changed(LINK(this, NavigatorTree, OnEntrySelDesel));
225 m_xTreeView->connect_popup_menu(LINK(this, NavigatorTree, CommandHdl));
226}
227
229{
230 m_xTreeView->all_foreach([this](weld::TreeIter& rIter) {
231 UserData* pData = weld::fromId<UserData*>(m_xTreeView->get_id(rIter));
232 delete pData;
233 return false;
234 });
235 m_pSelectionListener->dispose();
236 m_pReportListener->dispose();
237}
238
239namespace
240{
241 sal_uInt16 mapIdent(std::u16string_view rIdent)
242 {
243 if (rIdent == u"sorting")
244 return SID_SORTINGANDGROUPING;
245 else if (rIdent == u"page")
246 return SID_PAGEHEADERFOOTER;
247 else if (rIdent == u"report")
248 return SID_REPORTHEADERFOOTER;
249 else if (rIdent == u"function")
250 return SID_RPT_NEW_FUNCTION;
251 else if (rIdent == u"properties")
252 return SID_SHOW_PROPERTYBROWSER;
253 else if (rIdent == u"delete")
254 return SID_DELETE;
255 return 0;
256 }
257}
258
259IMPL_LINK(NavigatorTree, CommandHdl, const CommandEvent&, rEvt, bool)
260{
261 bool bHandled = false;
262 switch( rEvt.GetCommand())
263 {
264 case CommandEventId::ContextMenu:
265 {
266 UserData* pData = weld::fromId<UserData*>(m_xTreeView->get_selected_id());
267 if (!pData)
268 break;
269
270 uno::Reference< report::XFunctionsSupplier> xSupplier(pData->getContent(),uno::UNO_QUERY);
271 uno::Reference< report::XFunctions> xFunctions(pData->getContent(),uno::UNO_QUERY);
272 uno::Reference< report::XGroup> xGroup(pData->getContent(),uno::UNO_QUERY);
273 bool bDeleteAllowed = m_rController.isEditable() && (xGroup.is() ||
274 uno::Reference< report::XFunction>(pData->getContent(),uno::UNO_QUERY).is());
275
276 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xTreeView.get(), "modules/dbreport/ui/navigatormenu.ui"));
277 std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu("menu"));
278
279 const OUString aIds[] = { "sorting", "page", "report", "function", "properties", "delete" };
280 for (size_t i = 0; i < SAL_N_ELEMENTS(aIds); ++i)
281 {
282 sal_uInt16 nSId = mapIdent(aIds[i]);
283
284 if (aIds[i] == "page" || aIds[i] == "report" || aIds[i] == "properties")
285 xContextMenu->set_active(aIds[i], m_rController.isCommandChecked(nSId));
286 bool bEnabled = m_rController.isCommandEnabled(nSId);
287 if (nSId == SID_RPT_NEW_FUNCTION)
288 xContextMenu->set_sensitive(aIds[i], m_rController.isEditable() && (xSupplier.is() || xFunctions.is()));
289 // special condition, check for function and group
290 else if (nSId == SID_DELETE)
291 xContextMenu->set_sensitive(aIds[i], bDeleteAllowed);
292 else
293 xContextMenu->set_sensitive(aIds[i], bEnabled);
294 }
295
296 // the point that was clicked on
297 ::Point aWhere(rEvt.GetMousePosPixel());
298 OUString sCurItemIdent = xContextMenu->popup_at_rect(m_xTreeView.get(), tools::Rectangle(aWhere, Size(1,1)));
299 if (!sCurItemIdent.isEmpty())
300 {
301 sal_uInt16 nId = mapIdent(sCurItemIdent);
302 uno::Sequence< beans::PropertyValue> aArgs;
303 if ( nId == SID_RPT_NEW_FUNCTION )
304 {
305 aArgs.realloc(1);
306 aArgs.getArray()[0].Value <<= (xFunctions.is() ? xFunctions : xSupplier->getFunctions());
307 }
308 else if ( nId == SID_DELETE )
309 {
310 if ( xGroup.is() )
311 nId = SID_GROUP_REMOVE;
312 aArgs = { comphelper::makePropertyValue(PROPERTY_GROUP, pData->getContent()) };
313 }
314 m_rController.executeUnChecked(nId,aArgs);
315 }
316
317 bHandled = true;
318 }
319 break;
320 default: break;
321 }
322
323 return bHandled;
324}
325
327{
328 if ( !m_pSelectionListener->locked() )
329 {
330 m_pSelectionListener->lock();
331 std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
332 bool bEntry = m_xTreeView->get_cursor(xEntry.get());
333 uno::Any aSelection;
334 if (bEntry && m_xTreeView->is_selected(*xEntry))
335 aSelection <<= weld::fromId<UserData*>(m_xTreeView->get_id(*xEntry))->getContent();
336 m_rController.select(aSelection);
337 m_pSelectionListener->unlock();
338 }
339}
340
341void NavigatorTree::_selectionChanged( const lang::EventObject& aEvent )
342{
343 m_pSelectionListener->lock();
344 uno::Reference< view::XSelectionSupplier> xSelectionSupplier(aEvent.Source,uno::UNO_QUERY);
345 uno::Any aSec = xSelectionSupplier->getSelection();
346 uno::Sequence< uno::Reference< report::XReportComponent > > aSelection;
347 aSec >>= aSelection;
348 std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
349 if ( !aSelection.hasElements() )
350 {
351 uno::Reference< uno::XInterface> xSelection(aSec,uno::UNO_QUERY);
352 bool bEntry = find(xSelection, *xEntry);
353 if (bEntry && !m_xTreeView->is_selected(*xEntry))
354 {
355 m_xTreeView->select(*xEntry);
356 m_xTreeView->set_cursor(*xEntry);
357 }
358 else if (!bEntry)
359 m_xTreeView->unselect_all();
360 }
361 else
362 {
363 for (const uno::Reference<report::XReportComponent>& rElem : std::as_const(aSelection))
364 {
365 bool bEntry = find(rElem, *xEntry);
366 if (bEntry && !m_xTreeView->is_selected(*xEntry))
367 {
368 m_xTreeView->select(*xEntry);
369 m_xTreeView->set_cursor(*xEntry);
370 }
371 }
372 }
373 m_pSelectionListener->unlock();
374}
375
376void NavigatorTree::insertEntry(const OUString& rName, const weld::TreeIter* pParent, const OUString& rImageId,
377 int nPosition, const UserData* pData, weld::TreeIter& rRet)
378{
379 OUString sId = pData ? weld::toId(pData) : OUString();
380 m_xTreeView->insert(pParent, nPosition, &rName, &sId, nullptr, nullptr, false, &rRet);
381 if (!rImageId.isEmpty())
382 m_xTreeView->set_image(rRet, rImageId);
383}
384
385void NavigatorTree::traverseSection(const uno::Reference<report::XSection>& xSection, const weld::TreeIter* pParent, const OUString& rImageId, int nPosition)
386{
387 std::unique_ptr<weld::TreeIter> xSectionIter = m_xTreeView->make_iterator();
388 std::unique_ptr<weld::TreeIter> xScratch = m_xTreeView->make_iterator();
389 insertEntry(xSection->getName(), pParent, rImageId, nPosition, new UserData(this, xSection), *xSectionIter);
390 const sal_Int32 nCount = xSection->getCount();
391 for (sal_Int32 i = 0; i < nCount; ++i)
392 {
393 uno::Reference< report::XReportComponent> xElement(xSection->getByIndex(i), uno::UNO_QUERY_THROW);
394 insertEntry(lcl_getName(xElement), xSectionIter.get(), lcl_getImageId(xElement), -1, new UserData(this, xElement), *xScratch);
395 uno::Reference< report::XReportDefinition> xSubReport(xElement,uno::UNO_QUERY);
396 if ( xSubReport.is() )
397 {
398 bool bMasterReport = find(xSection->getReportDefinition(), *xScratch);
399 if (!bMasterReport)
400 m_xMasterReport.reset();
401 else
402 m_xMasterReport = m_xTreeView->make_iterator(xScratch.get());
403 reportdesign::OReportVisitor aSubVisitor(this);
404 aSubVisitor.start(xSubReport);
405 }
406 }
407}
408
409void NavigatorTree::traverseFunctions(const uno::Reference< report::XFunctions>& xFunctions, const weld::TreeIter* pParent)
410{
411 std::unique_ptr<weld::TreeIter> xFunctionIter = m_xTreeView->make_iterator();
412 std::unique_ptr<weld::TreeIter> xScratch = m_xTreeView->make_iterator();
413 insertEntry(RptResId(RID_STR_FUNCTIONS), pParent, RID_SVXBMP_RPT_NEW_FUNCTION, -1, new UserData(this, xFunctions), *xFunctionIter);
414 const sal_Int32 nCount = xFunctions->getCount();
415 for (sal_Int32 i = 0; i< nCount; ++i)
416 {
417 uno::Reference< report::XFunction> xElement(xFunctions->getByIndex(i),uno::UNO_QUERY);
418 insertEntry(xElement->getName(), xFunctionIter.get(), RID_SVXBMP_RPT_NEW_FUNCTION, -1, new UserData(this,xElement), *xScratch);
419 }
420}
421
422bool NavigatorTree::find(const uno::Reference<uno::XInterface>& xContent, weld::TreeIter& rRet)
423{
424 bool bRet = false;
425 if (xContent.is())
426 {
427 m_xTreeView->all_foreach([this, &xContent, &bRet, &rRet](weld::TreeIter& rIter) {
428 UserData* pData = weld::fromId<UserData*>(m_xTreeView->get_id(rIter));
429 if (pData->getContent() == xContent)
430 {
431 m_xTreeView->copy_iterator(rIter, rRet);
432 bRet = true;
433 return true;
434 }
435 return false;
436 });
437 }
438 return bRet;
439}
440
441// ITraverseReport
442
443void NavigatorTree::traverseReport(const uno::Reference< report::XReportDefinition>& xReport)
444{
445 std::unique_ptr<weld::TreeIter> xScratch = m_xTreeView->make_iterator();
446 insertEntry(xReport->getName(), m_xMasterReport.get(), RID_SVXBMP_SELECT_REPORT,-1, new UserData(this, xReport), *xScratch);
447}
448
449void NavigatorTree::traverseReportFunctions(const uno::Reference< report::XFunctions>& xFunctions)
450{
451 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
452 bool bReport = find(xFunctions->getParent(), *xReport);
453 if (!bReport)
454 xReport.reset();
455 traverseFunctions(xFunctions, xReport.get());
456}
457
458void NavigatorTree::traverseReportHeader(const uno::Reference< report::XSection>& xSection)
459{
460 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
461 bool bReport = find(xSection->getReportDefinition(), *xReport);
462 if (!bReport)
463 xReport.reset();
464 traverseSection(xSection, xReport.get(), RID_SVXBMP_REPORTHEADERFOOTER);
465}
466
467void NavigatorTree::traverseReportFooter(const uno::Reference< report::XSection>& xSection)
468{
469 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
470 bool bReport = find(xSection->getReportDefinition(), *xReport);
471 if (!bReport)
472 xReport.reset();
473 traverseSection(xSection, xReport.get(), RID_SVXBMP_REPORTHEADERFOOTER);
474}
475
476void NavigatorTree::traversePageHeader(const uno::Reference< report::XSection>& xSection)
477{
478 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
479 bool bReport = find(xSection->getReportDefinition(), *xReport);
480 if (!bReport)
481 xReport.reset();
482 traverseSection(xSection, xReport.get(), RID_SVXBMP_PAGEHEADERFOOTER);
483}
484
485void NavigatorTree::traversePageFooter(const uno::Reference< report::XSection>& xSection)
486{
487 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
488 bool bReport = find(xSection->getReportDefinition(), *xReport);
489 if (!bReport)
490 xReport.reset();
491 traverseSection(xSection, xReport.get(), RID_SVXBMP_PAGEHEADERFOOTER);
492}
493
494void NavigatorTree::traverseGroups(const uno::Reference< report::XGroups>& xGroups)
495{
496 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
497 bool bReport = find(xGroups->getReportDefinition(), *xReport);
498 if (!bReport)
499 xReport.reset();
500 std::unique_ptr<weld::TreeIter> xScratch = m_xTreeView->make_iterator();
501 insertEntry(RptResId(RID_STR_GROUPS), xReport.get(), RID_SVXBMP_SORTINGANDGROUPING, -1, new UserData(this, xGroups), *xScratch);
502}
503
504void NavigatorTree::traverseGroup(const uno::Reference< report::XGroup>& xGroup)
505{
506 uno::Reference< report::XGroups> xGroups(xGroup->getParent(),uno::UNO_QUERY);
507 std::unique_ptr<weld::TreeIter> xGroupsIter = m_xTreeView->make_iterator();
508 bool bGroups = find(xGroups, *xGroupsIter);
509 OSL_ENSURE(bGroups, "No Groups inserted so far. Why!");
510 if (!bGroups)
511 xGroupsIter.reset();
512 std::unique_ptr<weld::TreeIter> xScratch = m_xTreeView->make_iterator();
513 insertEntry(xGroup->getExpression(), xGroupsIter.get(), RID_SVXBMP_GROUP, rptui::getPositionInIndexAccess(xGroups,xGroup), new UserData(this,xGroup), *xScratch);
514}
515
516void NavigatorTree::traverseGroupFunctions(const uno::Reference< report::XFunctions>& xFunctions)
517{
518 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
519 bool bReport = find(xFunctions->getParent(), *xReport);
520 if (!bReport)
521 xReport.reset();
522 traverseFunctions(xFunctions, xReport.get());
523}
524
525void NavigatorTree::traverseGroupHeader(const uno::Reference< report::XSection>& xSection)
526{
527 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
528 bool bReport = find(xSection->getGroup(), *xReport);
529 OSL_ENSURE(bReport, "No group found");
530 if (!bReport)
531 xReport.reset();
532 traverseSection(xSection, xReport.get(), RID_SVXBMP_GROUPHEADER, 1);
533}
534
535void NavigatorTree::traverseGroupFooter(const uno::Reference< report::XSection>& xSection)
536{
537 std::unique_ptr<weld::TreeIter> xReport = m_xTreeView->make_iterator();
538 bool bReport = find(xSection->getGroup(), *xReport);
539 OSL_ENSURE(bReport, "No group found");
540 if (!bReport)
541 xReport.reset();
542 traverseSection(xSection, xReport.get(), RID_SVXBMP_GROUPFOOTER);
543}
544
545void NavigatorTree::traverseDetail(const uno::Reference< report::XSection>& xSection)
546{
547 uno::Reference< report::XReportDefinition> xReport = xSection->getReportDefinition();
548 std::unique_ptr<weld::TreeIter> xParent = m_xTreeView->make_iterator();
549 bool bParent = find(xReport, *xParent);
550 if (!bParent)
551 xParent.reset();
552 traverseSection(xSection, xParent.get(), RID_SVXBMP_ICON_DETAIL);
553}
554
555void NavigatorTree::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
556{
557 uno::Reference< report::XReportDefinition> xReport(_rEvent.Source,uno::UNO_QUERY);
558 if ( !xReport.is() )
559 return;
560
561 bool bEnabled = false;
562 _rEvent.NewValue >>= bEnabled;
563 if ( !bEnabled )
564 return;
565
566 std::unique_ptr<weld::TreeIter> xParent = m_xTreeView->make_iterator();
567 bool bParent = find(xReport, *xParent);
568 if (!bParent)
569 xParent.reset();
570 if ( _rEvent.PropertyName == PROPERTY_REPORTHEADERON )
571 {
572 int nPos = xReport->getReportHeaderOn() ? 2 : 1;
573 traverseSection(xReport->getReportHeader(),xParent.get(),RID_SVXBMP_REPORTHEADERFOOTER,nPos);
574 }
575 else if ( _rEvent.PropertyName == PROPERTY_PAGEHEADERON )
576 {
577 traverseSection(xReport->getPageHeader(),xParent.get(), RID_SVXBMP_PAGEHEADERFOOTER,1);
578 }
579 else if ( _rEvent.PropertyName == PROPERTY_PAGEFOOTERON )
580 traverseSection(xReport->getPageFooter(),xParent.get(), RID_SVXBMP_PAGEHEADERFOOTER);
581 else if ( _rEvent.PropertyName == PROPERTY_REPORTFOOTERON )
582 {
583 int nPos = -1;
584 if (xReport->getPageFooterOn() && xParent)
585 nPos = m_xTreeView->iter_n_children(*xParent) - 1;
586 traverseSection(xReport->getReportFooter(),xParent.get(),RID_SVXBMP_REPORTHEADERFOOTER,nPos);
587 }
588}
589
590void NavigatorTree::_elementInserted( const container::ContainerEvent& _rEvent )
591{
592 std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
593 bool bEntry = find(_rEvent.Source, *xEntry);
594 if (!bEntry)
595 xEntry.reset();
596 uno::Reference<beans::XPropertySet> xProp(_rEvent.Element,uno::UNO_QUERY_THROW);
597 OUString sName;
598 uno::Reference< beans::XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
599 if ( xInfo.is() )
600 {
601 if ( xInfo->hasPropertyByName(PROPERTY_NAME) )
602 xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
603 else if ( xInfo->hasPropertyByName(PROPERTY_EXPRESSION) )
604 xProp->getPropertyValue(PROPERTY_EXPRESSION) >>= sName;
605 }
606 uno::Reference< report::XGroup> xGroup(xProp,uno::UNO_QUERY);
607 if ( xGroup.is() )
608 {
609 reportdesign::OReportVisitor aSubVisitor(this);
610 aSubVisitor.start(xGroup);
611 }
612 else
613 {
614 uno::Reference< report::XReportComponent> xElement(xProp,uno::UNO_QUERY);
615 if ( xProp.is() )
616 sName = lcl_getName(xProp);
617 std::unique_ptr<weld::TreeIter> xScratch = m_xTreeView->make_iterator();
618 insertEntry(sName, xEntry.get(), (!xElement.is() ? OUString(RID_SVXBMP_RPT_NEW_FUNCTION) : lcl_getImageId(xElement)),
619 -1, new UserData(this,xProp), *xScratch);
620 }
621 if (bEntry && !m_xTreeView->get_row_expanded(*xEntry))
622 m_xTreeView->expand_row(*xEntry);
623}
624
625void NavigatorTree::_elementRemoved( const container::ContainerEvent& _rEvent )
626{
627 uno::Reference<beans::XPropertySet> xProp(_rEvent.Element,uno::UNO_QUERY);
628 std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
629 bool bEntry = find(xProp, *xEntry);
630 OSL_ENSURE(bEntry,"NavigatorTree::_elementRemoved: No Entry found!");
631
632 if (bEntry)
633 {
634 removeEntry(*xEntry);
635 }
636}
637
638void NavigatorTree::_elementReplaced( const container::ContainerEvent& _rEvent )
639{
640 uno::Reference<beans::XPropertySet> xProp(_rEvent.ReplacedElement,uno::UNO_QUERY);
641 std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
642 bool bEntry = find(xProp, *xEntry);
643 if (bEntry)
644 {
645 UserData* pData = weld::fromId<UserData*>(m_xTreeView->get_id(*xEntry));
646 xProp.set(_rEvent.Element,uno::UNO_QUERY);
647 pData->setContent(xProp);
648 OUString sName;
649 xProp->getPropertyValue(PROPERTY_NAME) >>= sName;
650 m_xTreeView->set_text(*xEntry, sName);
651 }
652}
653
654void NavigatorTree::_disposing(const lang::EventObject& _rSource)
655{
656 std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
657 if (find(_rSource.Source, *xEntry))
658 removeEntry(*xEntry);
659}
660
661void NavigatorTree::removeEntry(const weld::TreeIter& rEntry, bool bRemove)
662{
663 std::unique_ptr<weld::TreeIter> xChild = m_xTreeView->make_iterator(&rEntry);
664 bool bChild = m_xTreeView->iter_children(*xChild);
665 while (bChild)
666 {
667 removeEntry(*xChild, false);
668 bChild = m_xTreeView->iter_next_sibling(*xChild);
669 }
670 delete weld::fromId<UserData*>(m_xTreeView->get_id(rEntry));
671 if (bRemove)
672 m_xTreeView->remove(rEntry);
673}
674
675NavigatorTree::UserData::UserData(NavigatorTree* pTree,uno::Reference<uno::XInterface> xContent)
678 , m_xContent(std::move(xContent))
679 , m_pTree(pTree)
680{
681 uno::Reference<beans::XPropertySet> xProp(m_xContent,uno::UNO_QUERY);
682 if ( xProp.is() )
683 {
684 uno::Reference< beans::XPropertySetInfo> xInfo = xProp->getPropertySetInfo();
685 if ( xInfo.is() )
686 {
687 m_pListener = new ::comphelper::OPropertyChangeMultiplexer(this,xProp);
688 if ( xInfo->hasPropertyByName(PROPERTY_NAME) )
689 m_pListener->addProperty(PROPERTY_NAME);
690 else if ( xInfo->hasPropertyByName(PROPERTY_EXPRESSION) )
691 m_pListener->addProperty(PROPERTY_EXPRESSION);
692 if ( xInfo->hasPropertyByName(PROPERTY_DATAFIELD) )
693 m_pListener->addProperty(PROPERTY_DATAFIELD);
694 if ( xInfo->hasPropertyByName(PROPERTY_LABEL) )
695 m_pListener->addProperty(PROPERTY_LABEL);
696 if ( xInfo->hasPropertyByName(PROPERTY_HEADERON) )
697 m_pListener->addProperty(PROPERTY_HEADERON);
698 if ( xInfo->hasPropertyByName(PROPERTY_FOOTERON) )
699 m_pListener->addProperty(PROPERTY_FOOTERON);
700 }
701 }
702 uno::Reference< container::XContainer> xContainer(m_xContent,uno::UNO_QUERY);
703 if ( xContainer.is() )
704 {
705 m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer);
706 }
707}
708
710{
711 if ( m_pContainerListener.is() )
712 m_pContainerListener->dispose();
713 if ( m_pListener.is() )
714 m_pListener->dispose();
715}
716
717// OPropertyChangeListener
718void NavigatorTree::UserData::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
719{
720 std::unique_ptr<weld::TreeIter> xEntry = m_pTree->make_iterator();
721 bool bEntry = m_pTree->find(_rEvent.Source, *xEntry);
722 OSL_ENSURE(bEntry,"No entry could be found! Why not!");
723 if (!bEntry)
724 return;
725 const bool bFooterOn = (PROPERTY_FOOTERON == _rEvent.PropertyName);
726 try
727 {
728 if ( bFooterOn || PROPERTY_HEADERON == _rEvent.PropertyName )
729 {
730 sal_Int32 nPos = 1;
731 uno::Reference< report::XGroup> xGroup(_rEvent.Source,uno::UNO_QUERY);
732 ::std::function<bool(OGroupHelper *)> pIsOn = ::std::mem_fn(&OGroupHelper::getHeaderOn);
733 ::std::function<uno::Reference<report::XSection>(OGroupHelper *)> pMemFunSection = ::std::mem_fn(&OGroupHelper::getHeader);
734 if ( bFooterOn )
735 {
736 pIsOn = ::std::mem_fn(&OGroupHelper::getFooterOn);
737 pMemFunSection = ::std::mem_fn(&OGroupHelper::getFooter);
738 nPos = m_pTree->iter_n_children(*xEntry) - 1;
739 }
740
741 OGroupHelper aGroupHelper(xGroup);
742 if ( pIsOn(&aGroupHelper) )
743 {
744 if ( bFooterOn )
745 ++nPos;
746 m_pTree->traverseSection(pMemFunSection(&aGroupHelper),xEntry.get(),bFooterOn ? OUString(RID_SVXBMP_GROUPFOOTER) : OUString(RID_SVXBMP_GROUPHEADER),nPos);
747 }
748 }
749 else if ( PROPERTY_EXPRESSION == _rEvent.PropertyName)
750 {
751 OUString sNewName;
752 _rEvent.NewValue >>= sNewName;
753 m_pTree->set_text(*xEntry, sNewName);
754 }
755 else if ( PROPERTY_DATAFIELD == _rEvent.PropertyName || PROPERTY_LABEL == _rEvent.PropertyName || PROPERTY_NAME == _rEvent.PropertyName )
756 {
757 uno::Reference<beans::XPropertySet> xProp(_rEvent.Source,uno::UNO_QUERY);
758 m_pTree->set_text(*xEntry, lcl_getName(xProp));
759 }
760 }
761 catch(const uno::Exception &)
762 {}
763}
764
765void NavigatorTree::UserData::_elementInserted( const container::ContainerEvent& _rEvent )
766{
767 m_pTree->_elementInserted( _rEvent );
768}
769
770void NavigatorTree::UserData::_elementRemoved( const container::ContainerEvent& _rEvent )
771{
772 m_pTree->_elementRemoved( _rEvent );
773}
774
775void NavigatorTree::UserData::_elementReplaced( const container::ContainerEvent& _rEvent )
776{
777 m_pTree->_elementReplaced( _rEvent );
778}
779
780void NavigatorTree::UserData::_disposing(const lang::EventObject& _rSource)
781{
782 m_pTree->_disposing( _rSource );
783}
784
786 : GenericDialogController(pParent, "modules/dbreport/ui/floatingnavigator.ui", "FloatingNavigator")
787 , m_xReport(rController.getReportDefinition())
788 , m_xNavigatorTree(std::make_unique<NavigatorTree>(m_xBuilder->weld_tree_view("treeview"), rController))
789{
791 aVisitor.start(m_xReport);
792 std::unique_ptr<weld::TreeIter> xScratch = m_xNavigatorTree->make_iterator();
793 if (m_xNavigatorTree->find(m_xReport, *xScratch))
794 m_xNavigatorTree->expand_row(*xScratch);
795 lang::EventObject aEvent(rController);
796 m_xNavigatorTree->_selectionChanged(aEvent);
797 m_xNavigatorTree->grab_focus();
798
799 m_xDialog->connect_container_focus_changed(LINK(this, ONavigator, FocusChangeHdl));
800}
801
803{
804}
805
807{
808 if (m_xDialog->has_toplevel_focus())
809 m_xNavigatorTree->grab_focus();
810}
811
812} // rptui
813
814/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< ucb::XContent > m_xContent
Reference< XExecutableDialog > m_xDialog
AnyEventRef aEvent
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
friend friend class OPropertyChangeMultiplexer
friend friend class OSelectionChangeMultiplexer
ClassificationCategoriesController & m_rController
void start(const css::uno::Reference< css::report::XReportDefinition > &_xReportDefinition)
::rtl::Reference< comphelper::OContainerListenerAdapter > m_pContainerListener
Definition: Navigator.cxx:111
virtual void _propertyChanged(const beans::PropertyChangeEvent &_rEvent) override
Definition: Navigator.cxx:718
virtual void _elementRemoved(const container::ContainerEvent &Event) override
Definition: Navigator.cxx:770
virtual void _disposing(const lang::EventObject &_rSource) override
Definition: Navigator.cxx:780
::rtl::Reference< comphelper::OPropertyChangeMultiplexer > m_pListener
Definition: Navigator.cxx:110
uno::Reference< uno::XInterface > m_xContent
Definition: Navigator.cxx:109
virtual void _elementInserted(const container::ContainerEvent &_rEvent) override
Definition: Navigator.cxx:765
UserData(NavigatorTree *pTree, uno::Reference< uno::XInterface > xContent)
Definition: Navigator.cxx:675
const uno::Reference< uno::XInterface > & getContent() const
Definition: Navigator.cxx:117
virtual ~UserData() override
Definition: Navigator.cxx:709
void setContent(const uno::Reference< uno::XInterface > &_xContent)
Definition: Navigator.cxx:118
virtual void _elementReplaced(const container::ContainerEvent &_rEvent) override
Definition: Navigator.cxx:775
NavigatorTree(std::unique_ptr< weld::TreeView >, OReportController &rController)
Definition: Navigator.cxx:205
virtual void traverseReportHeader(const uno::Reference< report::XSection > &xSection) override
Definition: Navigator.cxx:458
void removeEntry(const weld::TreeIter &rEntry, bool bRemove=true)
Definition: Navigator.cxx:661
void _elementReplaced(const container::ContainerEvent &_rEvent)
Definition: Navigator.cxx:638
virtual void traverseGroupFunctions(const uno::Reference< report::XFunctions > &xFunctions) override
Definition: Navigator.cxx:516
int iter_n_children(const weld::TreeIter &rIter) const
Definition: Navigator.cxx:199
void _elementInserted(const container::ContainerEvent &_rEvent)
Definition: Navigator.cxx:590
DECL_LINK(CommandHdl, const CommandEvent &, bool)
virtual void traverseGroups(const uno::Reference< report::XGroups > &xGroups) override
Definition: Navigator.cxx:494
virtual void _propertyChanged(const beans::PropertyChangeEvent &_rEvent) override
Definition: Navigator.cxx:555
void traverseSection(const uno::Reference< report::XSection > &xSection, const weld::TreeIter *pParent, const OUString &rImageId, int nPosition=-1)
Definition: Navigator.cxx:385
std::unique_ptr< weld::TreeIter > m_xMasterReport
Definition: Navigator.cxx:133
std::unique_ptr< weld::TreeIter > make_iterator() const
Definition: Navigator.cxx:194
bool find(const uno::Reference< uno::XInterface > &xContent, weld::TreeIter &rIter)
Definition: Navigator.cxx:422
virtual void _disposing(const lang::EventObject &_rSource) override
Definition: Navigator.cxx:654
void traverseFunctions(const uno::Reference< report::XFunctions > &xFunctions, const weld::TreeIter *pParent)
Definition: Navigator.cxx:409
virtual void traverseReportFunctions(const uno::Reference< report::XFunctions > &xFunctions) override
Definition: Navigator.cxx:449
::rtl::Reference< comphelper::OSelectionChangeMultiplexer > m_pSelectionListener
Definition: Navigator.cxx:135
void _elementRemoved(const container::ContainerEvent &Event)
Definition: Navigator.cxx:625
void set_text(const weld::TreeIter &rIter, const OUString &rStr)
Definition: Navigator.cxx:184
virtual void traversePageFooter(const uno::Reference< report::XSection > &xSection) override
Definition: Navigator.cxx:485
virtual void traverseGroup(const uno::Reference< report::XGroup > &xGroup) override
Definition: Navigator.cxx:504
virtual void traverseReport(const uno::Reference< report::XReportDefinition > &xReport) override
Definition: Navigator.cxx:443
virtual ~NavigatorTree() override
Definition: Navigator.cxx:228
virtual void traverseReportFooter(const uno::Reference< report::XSection > &xSection) override
Definition: Navigator.cxx:467
std::unique_ptr< weld::TreeView > m_xTreeView
Definition: Navigator.cxx:131
virtual void _selectionChanged(const lang::EventObject &aEvent) override
Definition: Navigator.cxx:341
virtual void traverseDetail(const uno::Reference< report::XSection > &xSection) override
Definition: Navigator.cxx:545
OReportController & m_rController
Definition: Navigator.cxx:132
void insertEntry(const OUString &rName, const weld::TreeIter *pParent, const OUString &rImageId, int nPosition, const UserData *pData, weld::TreeIter &rRet)
Definition: Navigator.cxx:376
virtual void traverseGroupHeader(const uno::Reference< report::XSection > &xSection) override
Definition: Navigator.cxx:525
virtual void traverseGroupFooter(const uno::Reference< report::XSection > &xSection) override
Definition: Navigator.cxx:535
DECL_LINK(OnEntrySelDesel, weld::TreeView &, void)
friend class UserData
Definition: Navigator.cxx:103
virtual void traversePageHeader(const uno::Reference< report::XSection > &xSection) override
Definition: Navigator.cxx:476
::rtl::Reference< comphelper::OPropertyChangeMultiplexer > m_pReportListener
Definition: Navigator.cxx:134
void expand_row(const weld::TreeIter &rIter)
Definition: Navigator.cxx:189
Helper class to allow std::mem_fun for SAL_CALL.
Definition: UndoActions.hxx:49
css::uno::Reference< css::report::XSection > getHeader()
Definition: UndoActions.hxx:58
css::uno::Reference< css::report::XSection > getFooter()
Definition: UndoActions.hxx:59
std::unique_ptr< NavigatorTree > m_xNavigatorTree
Definition: Navigator.hxx:33
css::uno::Reference< css::report::XReportDefinition > m_xReport
Definition: Navigator.hxx:32
ONavigator(const ONavigator &)=delete
const css::uno::Reference< css::report::XReportDefinition > & getReportDefinition() const
gives access to the report definition
bool isValid() const
returns whether the object denotes a valid formula
const OUString & getUndecoratedContent() const
gets the undecorated formula content
std::shared_ptr< weld::Dialog > m_xDialog
OUString RptResId(TranslateId aId)
int nCount
OUString sName
constexpr OUStringLiteral HID_REPORT_NAVIGATOR_TREE
Definition: helpids.h:77
std::mutex m_aMutex
sal_uInt16 nPos
#define SAL_N_ELEMENTS(arr)
std::unique_ptr< sal_Int32[]> pData
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
static OUString lcl_getName(const uno::Reference< beans::XPropertySet > &_xElement)
Definition: Navigator.cxx:75
static OUString lcl_getImageId(const uno::Reference< report::XReportComponent > &_xElement)
Definition: Navigator.cxx:58
IMPL_LINK_NOARG(OAddFieldWindow, FocusChangeHdl, weld::Container &, void)
Definition: AddField.cxx:120
sal_Int32 getPositionInIndexAccess(const css::uno::Reference< css::container::XIndexAccess > &_xCollection, const css::uno::Reference< T > &_xSearch)
returns the position of the object inside the index container
Definition: UITools.hxx:52
IMPL_LINK(OAddFieldWindow, DragBeginHdl, bool &, rUnsetDragIcon, bool)
Definition: AddField.cxx:50
OUString toId(const void *pValue)
sal_Int16 nId
constexpr OUStringLiteral PROPERTY_EXPRESSION
Definition: strings.hxx:52
constexpr OUStringLiteral PROPERTY_REPORTHEADERON
Definition: strings.hxx:67
constexpr OUStringLiteral PROPERTY_LABEL
Definition: strings.hxx:89
constexpr OUStringLiteral PROPERTY_NAME
Definition: strings.hxx:36
constexpr OUStringLiteral PROPERTY_PAGEFOOTERON
Definition: strings.hxx:70
constexpr OUStringLiteral PROPERTY_GROUP
Definition: strings.hxx:48
constexpr OUStringLiteral PROPERTY_PAGEHEADERON
Definition: strings.hxx:69
constexpr OUStringLiteral PROPERTY_DATAFIELD
Definition: strings.hxx:78
constexpr OUStringLiteral PROPERTY_REPORTFOOTERON
Definition: strings.hxx:68
constexpr OUStringLiteral PROPERTY_HEADERON
Definition: strings.hxx:71
constexpr OUStringLiteral PROPERTY_FOOTERON
Definition: strings.hxx:72
OUString sId