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 <ReportController.hxx>
21 #include <ReportDefinition.hxx>
22 #include <CondFormat.hxx>
23 #include <UITools.hxx>
24 #include <AddField.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <DateTime.hxx>
27 
28 #include <sfx2/filedlghelper.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <rptui_slotid.hrc>
31 #include <reportformula.hxx>
32 
33 #include <comphelper/documentconstants.hxx>
34 #include <unotools/mediadescriptor.hxx>
35 #include <comphelper/propertysequence.hxx>
36 #include <comphelper/sequenceashashmap.hxx>
37 #include <comphelper/types.hxx>
38 
39 #include <connectivity/dbtools.hxx>
40 #include <com/sun/star/style/XStyle.hpp>
41 #include <com/sun/star/style/ParagraphAdjust.hpp>
42 #include <com/sun/star/util/NumberFormatter.hpp>
43 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
44 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
45 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
46 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
47 #include <com/sun/star/frame/FrameSearchFlag.hpp>
48 #include <com/sun/star/container/XChild.hpp>
49 #include <com/sun/star/report/XImageControl.hpp>
50 #include <com/sun/star/report/XFixedLine.hpp>
51 #include <com/sun/star/report/Function.hpp>
52 #include <com/sun/star/awt/FontDescriptor.hpp>
53 #include <com/sun/star/sdb/XParametersSupplier.hpp>
54 #include <com/sun/star/sdb/CommandType.hpp>
55 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
56 #include <com/sun/star/embed/EmbedMapUnits.hpp>
57 #include <com/sun/star/awt/FontWeight.hpp>
58 #include <com/sun/star/awt/FontUnderline.hpp>
59 #include <com/sun/star/awt/FontSlant.hpp>
60 #include <com/sun/star/frame/Desktop.hpp>
61 #include <com/sun/star/frame/status/FontHeight.hpp>
62 #include <com/sun/star/report/ReportEngine.hpp>
63 #include <com/sun/star/report/XFormattedField.hpp>
64 #include <com/sun/star/sdb/SQLContext.hpp>
65 #include <com/sun/star/beans/PropertyAttribute.hpp>
66 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
67 
68 #include <vcl/svapp.hxx>
69 
70 #include <i18nutil/paper.hxx>
71 #include <svx/fmview.hxx>
72 #include <editeng/memberids.h>
73 #include <svx/svxids.hrc>
74 #include <svx/svdobj.hxx>
75 #include <svx/unomid.hxx>
76 #include <svx/dataaccessdescriptor.hxx>
77 #include <svx/xfillit0.hxx>
78 #include <svx/xflclit.hxx>
79 #include <svx/xflgrit.hxx>
80 #include <svx/xflhtit.hxx>
81 #include <svx/xbtmpit.hxx>
82 #include <svx/xflftrit.hxx>
83 #include <svx/xsflclit.hxx>
84 #include <svx/xflbckit.hxx>
85 #include <svx/xflbmpit.hxx>
86 #include <svx/xflbmsli.hxx>
87 #include <svx/xflbmsxy.hxx>
88 #include <svx/xflbmtit.hxx>
89 #include <svx/xflboxy.hxx>
90 #include <svx/xflbstit.hxx>
91 #include <svx/xflbtoxy.hxx>
92 #include <svx/xfltrit.hxx>
93 #include <svx/xgrscit.hxx>
94 #include <editeng/svxenum.hxx>
95 #include <svx/pageitem.hxx>
96 #include <editeng/lrspitem.hxx>
97 #include <editeng/ulspitem.hxx>
98 #include <editeng/sizeitem.hxx>
99 #include <sfx2/zoomitem.hxx>
100 #include <svx/zoomslideritem.hxx>
101 #include <editeng/brushitem.hxx>
102 #include <svx/flagsdef.hxx>
103 #include <svx/svdpagv.hxx>
104 #include <svx/svxdlg.hxx>
105 
106 #include <core_resource.hxx>
107 #include <DesignView.hxx>
108 #include <RptObject.hxx>
109 #include <RptUndo.hxx>
110 #include <strings.hxx>
111 #include <RptDef.hxx>
112 #include <ReportSection.hxx>
113 #include <SectionView.hxx>
114 #include <UndoActions.hxx>
115 #include <dlgpage.hxx>
116 #include <strings.hrc>
117 
118 #include <svl/itempool.hxx>
119 #include <svl/itemset.hxx>
120 #include <svtools/cliplistener.hxx>
121 #include <unotools/syslocale.hxx>
122 #include <unotools/viewoptions.hxx>
123 #include <unotools/localedatawrapper.hxx>
124 
125 #include <osl/mutex.hxx>
126 #include <PropertyForward.hxx>
127 #include <SectionWindow.hxx>
128 
129 #include <toolkit/helper/convert.hxx>
130 #include <GroupsSorting.hxx>
131 #include <PageNumber.hxx>
132 #include <UndoEnv.hxx>
133 
134 #include <memory>
135 #include <string_view>
136 
137 #include <cppuhelper/exc_hlp.hxx>
138 #include <unotools/confignode.hxx>
139 
140 #include <ReportControllerObserver.hxx>
141 
142 #define MAX_ROWS_FOR_PREVIEW    20
143 
144 #define RPTUI_ID_LRSPACE    XATTR_FILL_FIRST - 8
145 #define RPTUI_ID_ULSPACE    XATTR_FILL_FIRST - 7
146 #define RPTUI_ID_PAGE       XATTR_FILL_FIRST - 6
147 #define RPTUI_ID_SIZE       XATTR_FILL_FIRST - 5
148 #define RPTUI_ID_PAGE_MODE  XATTR_FILL_FIRST - 4
149 #define RPTUI_ID_START      XATTR_FILL_FIRST - 3
150 #define RPTUI_ID_END        XATTR_FILL_FIRST - 2
151 #define RPTUI_ID_BRUSH      XATTR_FILL_FIRST - 1
152 #define RPTUI_ID_METRIC     XATTR_FILL_LAST + 1
153 
154 using namespace ::com::sun::star;
155 using namespace uno;
156 using namespace io;
157 using namespace beans;
158 using namespace frame;
159 using namespace util;
160 using namespace lang;
161 using namespace container;
162 using namespace sdbcx;
163 using namespace sdbc;
164 using namespace sdb;
165 using namespace ui;
166 using namespace ui::dialogs;
167 using namespace ::dbtools;
168 using namespace ::rptui;
169 using namespace ::dbaui;
170 using namespace ::comphelper;
171 using namespace ::cppu;
172 
173 
174 namespace
175 {
lcl_setFontWPU_nothrow(const uno::Reference<report::XReportControlFormat> & _xReportControlFormat,const sal_Int32 _nId)176     void lcl_setFontWPU_nothrow(const uno::Reference< report::XReportControlFormat>& _xReportControlFormat,const sal_Int32 _nId)
177     {
178         if ( !_xReportControlFormat.is() )
179             return;
180 
181         try
182         {
183             awt::FontDescriptor aFontDescriptor = _xReportControlFormat->getFontDescriptor();
184             switch(_nId)
185             {
186                 case SID_ATTR_CHAR_WEIGHT:
187                     aFontDescriptor.Weight = (awt::FontWeight::NORMAL + awt::FontWeight::BOLD) - aFontDescriptor.Weight;
188                     break;
189                 case SID_ATTR_CHAR_POSTURE:
190                     aFontDescriptor.Slant = static_cast<awt::FontSlant>(static_cast<sal_Int16>(awt::FontSlant_ITALIC) - static_cast<sal_Int16>(aFontDescriptor.Slant));
191                     break;
192                 case SID_ATTR_CHAR_UNDERLINE:
193                     aFontDescriptor.Underline = awt::FontUnderline::SINGLE - aFontDescriptor.Underline;
194                     break;
195                 default:
196                     OSL_FAIL("Illegal value in default!");
197                     break;
198             }
199 
200             _xReportControlFormat->setFontDescriptor(aFontDescriptor);
201         }
202         catch(const beans::UnknownPropertyException&)
203         {
204         }
205     }
206 }
207 
208 
lcl_getReportControlFormat(const Sequence<PropertyValue> & aArgs,ODesignView * _pView,uno::Reference<awt::XWindow> & _xWindow,::std::vector<uno::Reference<uno::XInterface>> & _rControlsFormats)209 static void lcl_getReportControlFormat(const Sequence< PropertyValue >& aArgs,
210                                  ODesignView* _pView,
211                                  uno::Reference< awt::XWindow>& _xWindow,
212                                  ::std::vector< uno::Reference< uno::XInterface > >& _rControlsFormats)
213 {
214     uno::Reference< report::XReportControlFormat> xReportControlFormat;
215     if ( aArgs.hasElements() )
216     {
217         SequenceAsHashMap aMap(aArgs);
218         xReportControlFormat = aMap.getUnpackedValueOrDefault(REPORTCONTROLFORMAT,uno::Reference< report::XReportControlFormat>());
219         _xWindow = aMap.getUnpackedValueOrDefault(CURRENT_WINDOW,uno::Reference< awt::XWindow>());
220     }
221 
222     if ( !xReportControlFormat.is() )
223     {
224         _pView->fillControlModelSelection(_rControlsFormats);
225     }
226     else
227     {
228         uno::Reference<uno::XInterface> xInterface(xReportControlFormat);
229         _rControlsFormats.push_back(xInterface);
230     }
231 
232     if ( !_xWindow.is() )
233         _xWindow = VCLUnoHelper::GetInterface(_pView);
234 }
235 
getImplementationName()236 OUString SAL_CALL OReportController::getImplementationName()
237 {
238     return "com.sun.star.report.comp.ReportDesign";
239 }
240 
getSupportedServiceNames()241 Sequence< OUString> SAL_CALL OReportController::getSupportedServiceNames()
242 {
243     return { "com.sun.star.sdb.ReportDesign" };
244 }
245 
246 #define PROPERTY_ID_ZOOMVALUE   1
247 
248 
OReportController(Reference<XComponentContext> const & xContext)249 OReportController::OReportController(Reference< XComponentContext > const & xContext)
250     :OReportController_BASE(xContext)
251     ,OPropertyStateContainer(OGenericUnoController_Base::rBHelper)
252     ,m_aSelectionListeners( getMutex() )
253     ,m_sMode("normal")
254     ,m_nSplitPos(-1)
255     ,m_nPageNum(-1)
256     ,m_nSelectionCount(0)
257     ,m_nAspect(0)
258     ,m_nZoomValue(100)
259     ,m_eZoomType(SvxZoomType::PERCENT)
260     ,m_bShowRuler(true)
261     ,m_bGridVisible(true)
262     ,m_bGridUse(true)
263     ,m_bShowProperties(true)
264     ,m_bHelplinesMove(true)
265     ,m_bChartEnabled(false)
266     ,m_bChartEnabledAsked(false)
267     ,m_bInGeneratePreview(false)
268 {
269     // new Observer
270     m_pReportControllerObserver = new OXReportControllerObserver(*this);
271     registerProperty("ZoomValue", PROPERTY_ID_ZOOMVALUE,
272                      beans::PropertyAttribute::BOUND | beans::PropertyAttribute::TRANSIENT,
273                      &m_nZoomValue, ::cppu::UnoType<sal_Int16>::get());
274 
275 }
276 
~OReportController()277 OReportController::~OReportController()
278 {
279 }
280 
IMPLEMENT_FORWARD_XTYPEPROVIDER2(OReportController,OReportController_BASE,OReportController_Listener)281 IMPLEMENT_FORWARD_XTYPEPROVIDER2(OReportController,OReportController_BASE,OReportController_Listener)
282 IMPLEMENT_FORWARD_XINTERFACE2(OReportController,OReportController_BASE,OReportController_Listener)
283 
284 void OReportController::disposing()
285 {
286 
287     if ( m_pClipboardNotifier.is() )
288     {
289         m_pClipboardNotifier->ClearCallbackLink();
290         m_pClipboardNotifier->RemoveListener( getView() );
291         m_pClipboardNotifier.clear();
292     }
293     if ( m_xGroupsFloater )
294     {
295         SvtViewOptions aDlgOpt(EViewType::Window, OStringToOUString(m_xGroupsFloater->get_help_id(), RTL_TEXTENCODING_UTF8));
296         aDlgOpt.SetWindowState(OStringToOUString(m_xGroupsFloater->getDialog()->get_window_state(WindowStateMask::All), RTL_TEXTENCODING_ASCII_US));
297         if (m_xGroupsFloater->getDialog()->get_visible())
298             m_xGroupsFloater->response(RET_CANCEL);
299         m_xGroupsFloater.reset();
300     }
301 
302     try
303     {
304         m_xHoldAlive.clear();
305         m_xColumns.clear();
306         ::comphelper::disposeComponent( m_xRowSet );
307         ::comphelper::disposeComponent( m_xRowSetMediator );
308         ::comphelper::disposeComponent( m_xFormatter );
309     }
310     catch(const uno::Exception&)
311     {
312         TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while disposing row sets.");
313     }
314     m_xRowSet.clear();
315     m_xRowSetMediator.clear();
316 
317     if ( m_xReportDefinition.is() )
318     {
319         try
320         {
321             OSectionWindow* pSectionWindow = nullptr;
322             if ( getDesignView() )
323                 pSectionWindow = getDesignView()->getMarkedSection();
324             if ( pSectionWindow )
325                 pSectionWindow->getReportSection().deactivateOle();
326             clearUndoManager();
327             if ( m_aReportModel )
328                 listen(false);
329             m_pReportControllerObserver->Clear();
330             m_pReportControllerObserver.clear();
331         }
332         catch(const uno::Exception&)
333         {
334             DBG_UNHANDLED_EXCEPTION("reportdesign");
335         }
336     }
337 
338     {
339         EventObject aDisposingEvent( *this );
340         m_aSelectionListeners.disposeAndClear( aDisposingEvent );
341     }
342 
343     OReportController_BASE::disposing();
344 
345 
346     try
347     {
348         m_xReportDefinition.clear();
349         m_aReportModel.reset();
350         m_xFrameLoader.clear();
351         m_xReportEngine.clear();
352     }
353     catch(const uno::Exception&)
354     {
355     }
356     if ( getDesignView() )
357         EndListening( *getDesignView() );
358     clearView();
359 }
360 
GetState(sal_uInt16 _nId) const361 FeatureState OReportController::GetState(sal_uInt16 _nId) const
362 {
363     FeatureState aReturn;
364     // (disabled automatically)
365     aReturn.bEnabled = false;
366     // check this first
367     if ( !getView() )
368         return aReturn;
369 
370     switch (_nId)
371     {
372         case SID_RPT_TEXTDOCUMENT:
373             aReturn.bEnabled = isEditable();
374             aReturn.bChecked = (m_xReportDefinition.is() && m_xReportDefinition->getMimeType() == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII);
375             break;
376         case SID_RPT_SPREADSHEET:
377             aReturn.bEnabled = isEditable();
378             aReturn.bChecked = (m_xReportDefinition.is() && m_xReportDefinition->getMimeType() == MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII);
379             break;
380         case SID_REPORTHEADER_WITHOUT_UNDO:
381         case SID_REPORTFOOTER_WITHOUT_UNDO:
382         case SID_REPORTHEADERFOOTER:
383             {
384                 aReturn.bEnabled = isEditable();
385                 OUString sText = RptResId((m_xReportDefinition.is() && m_xReportDefinition->getReportHeaderOn()) ? RID_STR_REPORTHEADERFOOTER_DELETE : RID_STR_REPORTHEADERFOOTER_INSERT);
386                 aReturn.sTitle = sText;
387             }
388             break;
389         case SID_PAGEHEADER_WITHOUT_UNDO:
390         case SID_PAGEFOOTER_WITHOUT_UNDO:
391         case SID_PAGEHEADERFOOTER:
392             {
393                 aReturn.bEnabled = isEditable();
394                 OUString sText = RptResId((m_xReportDefinition.is() && m_xReportDefinition->getPageHeaderOn()) ? RID_STR_PAGEHEADERFOOTER_DELETE : RID_STR_PAGEHEADERFOOTER_INSERT);
395                 aReturn.sTitle = sText;
396             }
397             break;
398         case SID_GROUP_APPEND:
399         case SID_GROUP_REMOVE:
400         case SID_GROUPHEADER_WITHOUT_UNDO:
401         case SID_GROUPHEADER:
402         case SID_GROUPFOOTER_WITHOUT_UNDO:
403         case SID_GROUPFOOTER:
404             aReturn.bEnabled = isEditable();
405             break;
406         case SID_ADD_CONTROL_PAIR:
407             aReturn.bEnabled = isEditable();
408             break;
409         case SID_REDO:
410         case SID_UNDO:
411             {
412                 size_t ( SfxUndoManager::*retrieveCount )( bool const ) const =
413                     ( _nId == SID_UNDO ) ? &SfxUndoManager::GetUndoActionCount : &SfxUndoManager::GetRedoActionCount;
414 
415                 SfxUndoManager& rUndoManager( getUndoManager() );
416                 aReturn.bEnabled = ( rUndoManager.*retrieveCount )( SfxUndoManager::TopLevel ) > 0;
417                 if ( aReturn.bEnabled )
418                 {
419                     // TODO: add "Undo/Redo: prefix"
420                     OUString ( SfxUndoManager::*retrieveComment )( size_t, bool const ) const =
421                         ( _nId == SID_UNDO ) ? &SfxUndoManager::GetUndoActionComment : &SfxUndoManager::GetRedoActionComment;
422                     aReturn.sTitle = (rUndoManager.*retrieveComment)( 0, SfxUndoManager::TopLevel );
423                 }
424             }
425             break;
426         case SID_GETUNDOSTRINGS:
427         case SID_GETREDOSTRINGS:
428             {
429                 size_t ( SfxUndoManager::*retrieveCount )( bool const ) const =
430                     ( _nId == SID_GETUNDOSTRINGS ) ? &SfxUndoManager::GetUndoActionCount : &SfxUndoManager::GetRedoActionCount;
431 
432                 OUString ( SfxUndoManager::*retrieveComment )( size_t, bool const ) const =
433                     ( _nId == SID_GETUNDOSTRINGS ) ? &SfxUndoManager::GetUndoActionComment : &SfxUndoManager::GetRedoActionComment;
434 
435                 SfxUndoManager& rUndoManager( getUndoManager() );
436                 size_t nCount(( rUndoManager.*retrieveCount )( SfxUndoManager::TopLevel ));
437                 Sequence<OUString> aSeq(nCount);
438                 for (size_t n = 0; n < nCount; ++n)
439                     aSeq[n] = (rUndoManager.*retrieveComment)( n, SfxUndoManager::TopLevel );
440                 aReturn.aValue <<= aSeq;
441                 aReturn.bEnabled = true;
442             }
443             break;
444         case SID_OBJECT_RESIZING:
445         case SID_OBJECT_SMALLESTWIDTH:
446         case SID_OBJECT_SMALLESTHEIGHT:
447         case SID_OBJECT_GREATESTWIDTH:
448         case SID_OBJECT_GREATESTHEIGHT:
449             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();
450             if ( aReturn.bEnabled )
451                 aReturn.bEnabled = m_nSelectionCount > 1;
452             break;
453 
454         case SID_DISTRIBUTE_HLEFT:
455         case SID_DISTRIBUTE_HCENTER:
456         case SID_DISTRIBUTE_HDISTANCE:
457         case SID_DISTRIBUTE_HRIGHT:
458         case SID_DISTRIBUTE_VTOP:
459         case SID_DISTRIBUTE_VCENTER:
460         case SID_DISTRIBUTE_VDISTANCE:
461         case SID_DISTRIBUTE_VBOTTOM:
462             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();
463             if ( aReturn.bEnabled )
464             {
465                 OSectionView* pSectionView = getCurrentSectionView();
466                 aReturn.bEnabled = pSectionView && pSectionView->GetMarkedObjectCount() > 2;
467             }
468             break;
469         case SID_ARRANGEMENU:
470         case SID_FRAME_DOWN:
471         case SID_FRAME_UP:
472         case SID_FRAME_TO_TOP:
473         case SID_FRAME_TO_BOTTOM:
474         case SID_OBJECT_HEAVEN:
475         case SID_OBJECT_HELL:
476             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();
477             if ( aReturn.bEnabled )
478             {
479                 OSectionView* pSectionView = getCurrentSectionView();
480                 aReturn.bEnabled = pSectionView && pSectionView->OnlyShapesMarked();
481                 if ( aReturn.bEnabled )
482                 {
483                     if ( SID_OBJECT_HEAVEN == _nId )
484                         aReturn.bEnabled = pSectionView->GetLayerIdOfMarkedObjects() != RPT_LAYER_FRONT;
485                     else if ( SID_OBJECT_HELL == _nId )
486                         aReturn.bEnabled = pSectionView->GetLayerIdOfMarkedObjects() != RPT_LAYER_BACK;
487                 }
488             }
489             break;
490 
491         case SID_SECTION_SHRINK:
492         case SID_SECTION_SHRINK_TOP:
493         case SID_SECTION_SHRINK_BOTTOM:
494             {
495                 sal_Int32 nCount = 0;
496                 uno::Reference<report::XSection> xSection = getDesignView()->getCurrentSection();
497                 if ( xSection.is() )
498                 {
499                     nCount = xSection->getCount();
500                 }
501                 aReturn.bEnabled = isEditable() && nCount > 0;
502             }
503             break;
504         case SID_OBJECT_ALIGN:
505         case SID_OBJECT_ALIGN_LEFT:
506         case SID_OBJECT_ALIGN_CENTER:
507         case SID_OBJECT_ALIGN_RIGHT:
508         case SID_OBJECT_ALIGN_UP:
509         case SID_OBJECT_ALIGN_MIDDLE:
510         case SID_OBJECT_ALIGN_DOWN:
511         case SID_SECTION_ALIGN:
512         case SID_SECTION_ALIGN_LEFT:
513         case SID_SECTION_ALIGN_CENTER:
514         case SID_SECTION_ALIGN_RIGHT:
515         case SID_SECTION_ALIGN_UP:
516         case SID_SECTION_ALIGN_MIDDLE:
517         case SID_SECTION_ALIGN_DOWN:
518             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection();
519             break;
520         case SID_CUT:
521             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection() && !getDesignView()->isHandleEvent();
522             break;
523         case SID_COPY:
524             aReturn.bEnabled = getDesignView()->HasSelection() && !getDesignView()->isHandleEvent();
525             break;
526         case SID_PASTE:
527             aReturn.bEnabled = isEditable()  && !getDesignView()->isHandleEvent() && getDesignView()->IsPasteAllowed();
528             break;
529         case SID_SELECTALL:
530             aReturn.bEnabled = !getDesignView()->isHandleEvent();
531             break;
532         case SID_SELECTALL_IN_SECTION:
533             aReturn.bEnabled = !getDesignView()->isHandleEvent();
534             if ( aReturn.bEnabled )
535                 aReturn.bEnabled = getCurrentSectionView() != nullptr;
536             break;
537         case SID_ESCAPE:
538             aReturn.bEnabled = getDesignView()->GetMode() == DlgEdMode::Insert;
539             break;
540         case SID_TERMINATE_INPLACEACTIVATION:
541             aReturn.bEnabled = true;
542             break;
543         case SID_SELECT_ALL_EDITS:
544         case SID_SELECT_ALL_LABELS:
545             aReturn.bEnabled = true;
546             break;
547         case SID_RPT_NEW_FUNCTION:
548             aReturn.bEnabled = isEditable();
549             break;
550         case SID_COLLAPSE_SECTION:
551         case SID_EXPAND_SECTION:
552         case SID_NEXT_MARK:
553         case SID_PREV_MARK:
554             aReturn.bEnabled = isEditable() && !getDesignView()->isHandleEvent();
555             break;
556         case SID_SELECT:
557         case SID_SELECT_REPORT:
558             aReturn.bEnabled = true;
559             break;
560         case SID_EXECUTE_REPORT:
561             aReturn.bEnabled = isConnected() && m_xReportDefinition.is();
562             break;
563         case SID_DELETE:
564             aReturn.bEnabled = isEditable() && getDesignView()->HasSelection() && !getDesignView()->isHandleEvent();
565             if ( aReturn.bEnabled )
566             {
567                 OSectionWindow* pSectionWindow = getDesignView()->getMarkedSection();
568                 if ( pSectionWindow )
569                     aReturn.bEnabled = !pSectionWindow->getReportSection().isUiActive();
570             }
571             {
572                 OUString sText = RptResId(RID_STR_DELETE);
573                 aReturn.sTitle = sText;
574             }
575             break;
576         case SID_GRID_VISIBLE:
577             aReturn.bEnabled = isEditable();
578             aReturn.bChecked = m_bGridVisible;
579             break;
580         case SID_GRID_USE:
581             aReturn.bEnabled = isEditable();
582             aReturn.bChecked = m_bGridUse;
583             break;
584         case SID_HELPLINES_MOVE:
585             aReturn.bEnabled = isEditable();
586             aReturn.bChecked = m_bHelplinesMove;
587             break;
588         case SID_RULER:
589             aReturn.bEnabled = isEditable();
590             aReturn.bChecked = m_bShowRuler;
591             break;
592         case SID_OBJECT_SELECT:
593             aReturn.bEnabled = true;
594             aReturn.bChecked = getDesignView()->GetMode() == DlgEdMode::Select;
595             break;
596         case SID_INSERT_DIAGRAM:
597             aReturn.bEnabled = isEditable();
598             aReturn.bInvisible = !m_bChartEnabled;
599             aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_OLE2;
600             break;
601         case SID_FM_FIXEDTEXT:
602             aReturn.bEnabled = isEditable();
603             aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_RD_FIXEDTEXT;
604             break;
605         case SID_INSERT_HFIXEDLINE:
606             aReturn.bEnabled = isEditable();
607             aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_RD_HFIXEDLINE;
608             break;
609         case SID_INSERT_VFIXEDLINE:
610             aReturn.bEnabled = isEditable();
611             aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_RD_VFIXEDLINE;
612             break;
613         case SID_FM_EDIT:
614             aReturn.bEnabled = isEditable();
615             aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_RD_FORMATTEDFIELD;
616             break;
617         case SID_FM_IMAGECONTROL:
618             aReturn.bEnabled = isEditable();
619             aReturn.bChecked = getDesignView()->GetInsertObj() == OBJ_RD_IMAGECONTROL;
620             break;
621         case SID_DRAWTBX_CS_BASIC:
622         case SID_DRAWTBX_CS_BASIC1:
623         case SID_DRAWTBX_CS_BASIC2:
624         case SID_DRAWTBX_CS_BASIC3:
625         case SID_DRAWTBX_CS_BASIC4:
626         case SID_DRAWTBX_CS_BASIC5:
627         case SID_DRAWTBX_CS_BASIC6:
628         case SID_DRAWTBX_CS_BASIC7:
629         case SID_DRAWTBX_CS_BASIC8:
630         case SID_DRAWTBX_CS_BASIC9:
631         case SID_DRAWTBX_CS_BASIC10:
632         case SID_DRAWTBX_CS_BASIC11:
633         case SID_DRAWTBX_CS_BASIC12:
634         case SID_DRAWTBX_CS_BASIC13:
635         case SID_DRAWTBX_CS_BASIC14:
636         case SID_DRAWTBX_CS_BASIC15:
637         case SID_DRAWTBX_CS_BASIC16:
638         case SID_DRAWTBX_CS_BASIC17:
639         case SID_DRAWTBX_CS_BASIC18:
640         case SID_DRAWTBX_CS_BASIC19:
641         case SID_DRAWTBX_CS_BASIC20:
642         case SID_DRAWTBX_CS_BASIC21:
643         case SID_DRAWTBX_CS_BASIC22:
644             impl_fillCustomShapeState_nothrow("diamond",aReturn);
645             break;
646         case SID_DRAWTBX_CS_SYMBOL:
647         case SID_DRAWTBX_CS_SYMBOL1:
648         case SID_DRAWTBX_CS_SYMBOL2:
649         case SID_DRAWTBX_CS_SYMBOL3:
650         case SID_DRAWTBX_CS_SYMBOL4:
651         case SID_DRAWTBX_CS_SYMBOL5:
652         case SID_DRAWTBX_CS_SYMBOL6:
653         case SID_DRAWTBX_CS_SYMBOL7:
654         case SID_DRAWTBX_CS_SYMBOL8:
655         case SID_DRAWTBX_CS_SYMBOL9:
656         case SID_DRAWTBX_CS_SYMBOL10:
657         case SID_DRAWTBX_CS_SYMBOL11:
658         case SID_DRAWTBX_CS_SYMBOL12:
659         case SID_DRAWTBX_CS_SYMBOL13:
660         case SID_DRAWTBX_CS_SYMBOL14:
661         case SID_DRAWTBX_CS_SYMBOL15:
662         case SID_DRAWTBX_CS_SYMBOL16:
663         case SID_DRAWTBX_CS_SYMBOL17:
664         case SID_DRAWTBX_CS_SYMBOL18:
665             impl_fillCustomShapeState_nothrow("smiley",aReturn);
666             break;
667         case SID_DRAWTBX_CS_ARROW:
668         case SID_DRAWTBX_CS_ARROW1:
669         case SID_DRAWTBX_CS_ARROW2:
670         case SID_DRAWTBX_CS_ARROW3:
671         case SID_DRAWTBX_CS_ARROW4:
672         case SID_DRAWTBX_CS_ARROW5:
673         case SID_DRAWTBX_CS_ARROW6:
674         case SID_DRAWTBX_CS_ARROW7:
675         case SID_DRAWTBX_CS_ARROW8:
676         case SID_DRAWTBX_CS_ARROW9:
677         case SID_DRAWTBX_CS_ARROW10:
678         case SID_DRAWTBX_CS_ARROW11:
679         case SID_DRAWTBX_CS_ARROW12:
680         case SID_DRAWTBX_CS_ARROW13:
681         case SID_DRAWTBX_CS_ARROW14:
682         case SID_DRAWTBX_CS_ARROW15:
683         case SID_DRAWTBX_CS_ARROW16:
684         case SID_DRAWTBX_CS_ARROW17:
685         case SID_DRAWTBX_CS_ARROW18:
686         case SID_DRAWTBX_CS_ARROW19:
687         case SID_DRAWTBX_CS_ARROW20:
688         case SID_DRAWTBX_CS_ARROW21:
689         case SID_DRAWTBX_CS_ARROW22:
690         case SID_DRAWTBX_CS_ARROW23:
691         case SID_DRAWTBX_CS_ARROW24:
692         case SID_DRAWTBX_CS_ARROW25:
693         case SID_DRAWTBX_CS_ARROW26:
694             impl_fillCustomShapeState_nothrow("left-right-arrow",aReturn);
695             break;
696         case SID_DRAWTBX_CS_STAR:
697         case SID_DRAWTBX_CS_STAR1:
698         case SID_DRAWTBX_CS_STAR2:
699         case SID_DRAWTBX_CS_STAR3:
700         case SID_DRAWTBX_CS_STAR4:
701         case SID_DRAWTBX_CS_STAR5:
702         case SID_DRAWTBX_CS_STAR6:
703         case SID_DRAWTBX_CS_STAR7:
704         case SID_DRAWTBX_CS_STAR8:
705         case SID_DRAWTBX_CS_STAR9:
706         case SID_DRAWTBX_CS_STAR10:
707         case SID_DRAWTBX_CS_STAR11:
708         case SID_DRAWTBX_CS_STAR12:
709             impl_fillCustomShapeState_nothrow("star5",aReturn);
710             break;
711         case SID_DRAWTBX_CS_FLOWCHART:
712         case SID_DRAWTBX_CS_FLOWCHART1:
713         case SID_DRAWTBX_CS_FLOWCHART2:
714         case SID_DRAWTBX_CS_FLOWCHART3:
715         case SID_DRAWTBX_CS_FLOWCHART4:
716         case SID_DRAWTBX_CS_FLOWCHART5:
717         case SID_DRAWTBX_CS_FLOWCHART6:
718         case SID_DRAWTBX_CS_FLOWCHART7:
719         case SID_DRAWTBX_CS_FLOWCHART8:
720         case SID_DRAWTBX_CS_FLOWCHART9:
721         case SID_DRAWTBX_CS_FLOWCHART10:
722         case SID_DRAWTBX_CS_FLOWCHART11:
723         case SID_DRAWTBX_CS_FLOWCHART12:
724         case SID_DRAWTBX_CS_FLOWCHART13:
725         case SID_DRAWTBX_CS_FLOWCHART14:
726         case SID_DRAWTBX_CS_FLOWCHART15:
727         case SID_DRAWTBX_CS_FLOWCHART16:
728         case SID_DRAWTBX_CS_FLOWCHART17:
729         case SID_DRAWTBX_CS_FLOWCHART18:
730         case SID_DRAWTBX_CS_FLOWCHART19:
731         case SID_DRAWTBX_CS_FLOWCHART20:
732         case SID_DRAWTBX_CS_FLOWCHART21:
733         case SID_DRAWTBX_CS_FLOWCHART22:
734         case SID_DRAWTBX_CS_FLOWCHART23:
735         case SID_DRAWTBX_CS_FLOWCHART24:
736         case SID_DRAWTBX_CS_FLOWCHART25:
737         case SID_DRAWTBX_CS_FLOWCHART26:
738         case SID_DRAWTBX_CS_FLOWCHART27:
739         case SID_DRAWTBX_CS_FLOWCHART28:
740             impl_fillCustomShapeState_nothrow("flowchart-internal-storage",aReturn);
741             break;
742         case SID_DRAWTBX_CS_CALLOUT:
743         case SID_DRAWTBX_CS_CALLOUT1:
744         case SID_DRAWTBX_CS_CALLOUT2:
745         case SID_DRAWTBX_CS_CALLOUT3:
746         case SID_DRAWTBX_CS_CALLOUT4:
747         case SID_DRAWTBX_CS_CALLOUT5:
748         case SID_DRAWTBX_CS_CALLOUT6:
749         case SID_DRAWTBX_CS_CALLOUT7:
750             impl_fillCustomShapeState_nothrow("round-rectangular-callout",aReturn);
751             break;
752         case SID_RPT_SHOWREPORTEXPLORER:
753             aReturn.bEnabled = m_xReportDefinition.is();
754             aReturn.bChecked = getDesignView() && getDesignView()->isReportExplorerVisible();
755             break;
756         case SID_FM_ADD_FIELD:
757             aReturn.bEnabled = isConnected() && isEditable() && m_xReportDefinition.is()
758                 && !m_xReportDefinition->getCommand().isEmpty();
759             aReturn.bChecked = getDesignView() && getDesignView()->isAddFieldVisible();
760             break;
761         case SID_SHOW_PROPERTYBROWSER:
762             aReturn.bEnabled = true;
763             aReturn.bChecked = m_bShowProperties;
764             break;
765         case SID_PROPERTYBROWSER_LAST_PAGE:
766             aReturn.bEnabled = true;
767             aReturn.aValue <<= m_sLastActivePage;
768             break;
769         case SID_SPLIT_POSITION:
770             aReturn.bEnabled = true;
771             aReturn.aValue <<= getSplitPos();
772             break;
773         case SID_SAVEDOC:
774         case SID_SAVEASDOC:
775         case SID_SAVEACOPY:
776             aReturn.bEnabled = isConnected() && isEditable();
777             break;
778         case SID_EDITDOC:
779             aReturn.bChecked = isEditable();
780             break;
781         case SID_PAGEDIALOG:
782             aReturn.bEnabled = isEditable();
783             break;
784         case SID_BACKGROUND_COLOR:
785             impl_fillState_nothrow(PROPERTY_CONTROLBACKGROUND,aReturn);
786             break;
787         case SID_ATTR_CHAR_COLOR_BACKGROUND:
788             aReturn.bEnabled = isEditable();
789             {
790                 uno::Reference<report::XSection> xSection = getDesignView()->getCurrentSection();
791                 if ( xSection.is() )
792                     try
793                     {
794                         aReturn.aValue <<= xSection->getBackColor();
795                         const uno::Reference< report::XReportControlModel> xControlModel(getDesignView()->getCurrentControlModel(),uno::UNO_QUERY);
796                         aReturn.bEnabled = !xControlModel.is();
797                     }
798                     catch(const beans::UnknownPropertyException&)
799                     {
800                     }
801                 else
802                     aReturn.bEnabled = false;
803             }
804             break;
805         case SID_SORTINGANDGROUPING:
806             aReturn.bEnabled = true;
807             aReturn.bChecked = m_xGroupsFloater && m_xGroupsFloater->getDialog()->get_visible();
808             break;
809         case SID_ATTR_CHAR_WEIGHT:
810         case SID_ATTR_CHAR_POSTURE:
811         case SID_ATTR_CHAR_UNDERLINE:
812             impl_fillState_nothrow(PROPERTY_FONTDESCRIPTOR,aReturn);
813             if ( aReturn.bEnabled )
814             {
815                 awt::FontDescriptor aFontDescriptor;
816                 aReturn.aValue >>= aFontDescriptor;
817                 aReturn.aValue.clear();
818 
819                 switch(_nId)
820                 {
821                     case SID_ATTR_CHAR_WEIGHT:
822                         aReturn.bChecked = awt::FontWeight::BOLD == aFontDescriptor.Weight;
823                         break;
824                     case SID_ATTR_CHAR_POSTURE:
825                         aReturn.bChecked = awt::FontSlant_ITALIC == aFontDescriptor.Slant;
826                         break;
827                     case SID_ATTR_CHAR_UNDERLINE:
828                         aReturn.bChecked = awt::FontUnderline::SINGLE == aFontDescriptor.Underline;
829                         break;
830                     default:
831                         ;
832                     }
833             }
834             break;
835         case SID_ATTR_CHAR_COLOR:
836         case SID_ATTR_CHAR_COLOR2:
837             impl_fillState_nothrow(PROPERTY_CHARCOLOR,aReturn);
838             break;
839         case SID_ATTR_CHAR_FONT:
840             impl_fillState_nothrow(PROPERTY_FONTDESCRIPTOR,aReturn);
841             break;
842         case SID_ATTR_CHAR_FONTHEIGHT:
843             impl_fillState_nothrow(PROPERTY_CHARHEIGHT,aReturn);
844             if ( aReturn.aValue.hasValue() )
845             {
846                 frame::status::FontHeight aFontHeight;
847                 aReturn.aValue >>= aFontHeight.Height;
848                 aReturn.aValue <<= aFontHeight; // another type is needed here, so
849             }
850             break;
851         case SID_ATTR_PARA_ADJUST_LEFT:
852         case SID_ATTR_PARA_ADJUST_CENTER:
853         case SID_ATTR_PARA_ADJUST_RIGHT:
854         case SID_ATTR_PARA_ADJUST_BLOCK:
855             impl_fillState_nothrow(PROPERTY_PARAADJUST,aReturn);
856             if ( aReturn.bEnabled )
857             {
858                 ::sal_Int16 nParaAdjust = 0;
859                 if ( aReturn.aValue >>= nParaAdjust )
860                 {
861                     switch(static_cast<style::ParagraphAdjust>(nParaAdjust))
862                     {
863                         case style::ParagraphAdjust_LEFT:
864                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_LEFT;
865                             break;
866                         case style::ParagraphAdjust_RIGHT:
867                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_RIGHT;
868                             break;
869                         case style::ParagraphAdjust_BLOCK:
870                         case style::ParagraphAdjust_STRETCH:
871                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_BLOCK;
872                             break;
873                         case style::ParagraphAdjust_CENTER:
874                             aReturn.bChecked = _nId == SID_ATTR_PARA_ADJUST_CENTER;
875                             break;
876                         default: break;
877                     }
878                 }
879                 aReturn.aValue.clear();
880             }
881             break;
882 
883         case SID_INSERT_GRAPHIC:
884             aReturn.bEnabled = m_xReportDefinition.is() && isEditable() && getDesignView()->getCurrentSection().is();
885             break;
886         case SID_CHAR_DLG:
887         case SID_SETCONTROLDEFAULTS:
888             aReturn.bEnabled = m_xReportDefinition.is() && isEditable();
889             if ( aReturn.bEnabled )
890             {
891                 ::std::vector< uno::Reference< uno::XInterface > > aSelection;
892                 getDesignView()->fillControlModelSelection(aSelection);
893                 aReturn.bEnabled = !aSelection.empty()
894                     && std::all_of(aSelection.begin(), aSelection.end(), [](const uno::Reference<uno::XInterface>& rxInterface) {
895                         return !uno::Reference<report::XFixedLine>(rxInterface, uno::UNO_QUERY).is()
896                             && !uno::Reference<report::XImageControl>(rxInterface, uno::UNO_QUERY).is()
897                             && uno::Reference<report::XReportControlFormat>(rxInterface, uno::UNO_QUERY).is(); });
898             }
899             break;
900         case SID_CONDITIONALFORMATTING:
901             {
902                 const uno::Reference< report::XFormattedField> xFormattedField(getDesignView()->getCurrentControlModel(),uno::UNO_QUERY);
903                 aReturn.bEnabled = xFormattedField.is();
904             }
905             break;
906         case SID_INSERT_FLD_PGNUMBER:
907         case SID_DATETIME:
908             aReturn.bEnabled = m_xReportDefinition.is() && isEditable() && getDesignView()->getCurrentSection().is();
909             break;
910         case SID_EXPORTDOC:
911         case SID_EXPORTDOCASPDF:
912             aReturn.bEnabled = m_xReportDefinition.is();
913             break;
914         case SID_PRINTPREVIEW:
915             aReturn.bEnabled = false;
916             break;
917         case SID_ATTR_ZOOM:
918             aReturn.bEnabled = true;
919             {
920                 SvxZoomItem aZoom(m_eZoomType,m_nZoomValue);
921                 aZoom.SetValueSet(SvxZoomEnableFlags::N50|SvxZoomEnableFlags::N75|SvxZoomEnableFlags::N100|SvxZoomEnableFlags::N200);
922                 aZoom.QueryValue(aReturn.aValue);
923             }
924             break;
925         case SID_ATTR_ZOOMSLIDER:
926             aReturn.bEnabled = true;
927             {
928                 SvxZoomSliderItem aZoomSlider(m_nZoomValue,20,400);
929                 aZoomSlider.AddSnappingPoint(50);
930                 aZoomSlider.AddSnappingPoint(75);
931                 aZoomSlider.AddSnappingPoint(100);
932                 aZoomSlider.AddSnappingPoint(200);
933                 aZoomSlider.QueryValue(aReturn.aValue);
934             }
935             break;
936         default:
937             aReturn = OReportController_BASE::GetState(_nId);
938     }
939     return aReturn;
940 }
941 
942 
943 namespace
944 {
945     /** extracts a background color from a dispatched SID_BACKGROUND_COLOR call
946 
947         The dispatch might originate from either the toolbar, or the conditional
948         formatting dialog. In both cases, argument formats are different.
949     */
lcl_extractBackgroundColor(const Sequence<PropertyValue> & _rDispatchArgs)950     util::Color lcl_extractBackgroundColor( const Sequence< PropertyValue >& _rDispatchArgs )
951     {
952         util::Color aColor( COL_TRANSPARENT );
953         if ( _rDispatchArgs.getLength() == 1 )
954         {
955             OSL_VERIFY( _rDispatchArgs[0].Value >>= aColor );
956         }
957         else
958         {
959             SequenceAsHashMap aMap( _rDispatchArgs );
960             aColor = aMap.getUnpackedValueOrDefault( PROPERTY_FONTCOLOR, aColor );
961         }
962         return aColor;
963     }
964 }
965 
966 
Execute(sal_uInt16 _nId,const Sequence<PropertyValue> & aArgs)967 void OReportController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
968 {
969     SolarMutexGuard aSolarGuard;
970     ::osl::MutexGuard aGuard( getMutex() );
971 
972     bool bForceBroadcast = false;
973     switch(_nId)
974     {
975         case SID_RPT_TEXTDOCUMENT:
976             if ( m_xReportDefinition.is() )
977                 m_xReportDefinition->setMimeType( MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII );
978             break;
979         case SID_RPT_SPREADSHEET:
980             if (m_xReportDefinition.is() )
981                 m_xReportDefinition->setMimeType( MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII );
982             break;
983         case SID_REPORTHEADER_WITHOUT_UNDO:
984         case SID_REPORTFOOTER_WITHOUT_UNDO:
985         case SID_REPORTHEADERFOOTER:
986             switchReportSection(_nId);
987             break;
988         case SID_PAGEHEADER_WITHOUT_UNDO:
989         case SID_PAGEFOOTER_WITHOUT_UNDO:
990         case SID_PAGEHEADERFOOTER:
991             switchPageSection(_nId);
992             break;
993         case SID_GROUP_APPEND:
994         case SID_GROUP_REMOVE:
995             modifyGroup(_nId == SID_GROUP_APPEND,aArgs);
996             break;
997         case SID_GROUPHEADER_WITHOUT_UNDO:
998         case SID_GROUPHEADER:
999             createGroupSection(SID_GROUPHEADER == _nId,true,aArgs);
1000             break;
1001         case SID_GROUPFOOTER_WITHOUT_UNDO:
1002         case SID_GROUPFOOTER:
1003             createGroupSection(SID_GROUPFOOTER == _nId,false,aArgs);
1004             break;
1005         case SID_ADD_CONTROL_PAIR:
1006             addPairControls(aArgs);
1007             break;
1008         case SID_REDO:
1009         case SID_UNDO:
1010         {
1011             const OXUndoEnvironment::OUndoMode aLock( m_aReportModel->GetUndoEnv() );
1012             bool ( SfxUndoManager::*doXDo )() =
1013                 ( _nId == SID_UNDO ) ? &SfxUndoManager::Undo : &SfxUndoManager::Redo;
1014             SfxUndoManager& rUndoManager( getUndoManager() );
1015 
1016             sal_Int16 nCount(1);
1017             if (aArgs.hasElements() && aArgs[0].Name != "KeyModifier")
1018                 aArgs[0].Value >>= nCount;
1019             while (nCount--)
1020                 (rUndoManager.*doXDo)();
1021             InvalidateAll();
1022             if (m_xGroupsFloater && m_xGroupsFloater->getDialog()->get_visible())
1023                 m_xGroupsFloater->UpdateData();
1024         }
1025         break;
1026         case SID_CUT:
1027             executeMethodWithUndo(RID_STR_UNDO_REMOVE_SELECTION,::std::mem_fn(&ODesignView::Cut));
1028             break;
1029         case SID_COPY:
1030             getDesignView()->Copy();
1031             break;
1032         case SID_PASTE:
1033             executeMethodWithUndo(RID_STR_UNDO_PASTE,::std::mem_fn(&ODesignView::Paste));
1034             break;
1035 
1036         case SID_FRAME_TO_TOP:
1037         case SID_FRAME_DOWN:
1038         case SID_FRAME_UP:
1039         case SID_FRAME_TO_BOTTOM:
1040         case SID_OBJECT_HEAVEN:
1041         case SID_OBJECT_HELL:
1042             changeZOrder(_nId);
1043             break;
1044         case SID_DISTRIBUTE_HLEFT:
1045         case SID_DISTRIBUTE_HCENTER:
1046         case SID_DISTRIBUTE_HDISTANCE:
1047         case SID_DISTRIBUTE_HRIGHT:
1048         case SID_DISTRIBUTE_VTOP:
1049         case SID_DISTRIBUTE_VCENTER:
1050         case SID_DISTRIBUTE_VDISTANCE:
1051         case SID_DISTRIBUTE_VBOTTOM:
1052             {
1053                 OSectionView* pSectionView = getCurrentSectionView();
1054                 if ( pSectionView )
1055                     pSectionView->DistributeMarkedObjects(_nId);
1056             }
1057             break;
1058         case SID_OBJECT_SMALLESTWIDTH:
1059             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::WIDTH_SMALLEST);
1060             break;
1061         case SID_OBJECT_SMALLESTHEIGHT:
1062             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::HEIGHT_SMALLEST);
1063             break;
1064         case SID_OBJECT_GREATESTWIDTH:
1065             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::WIDTH_GREATEST);
1066             break;
1067         case SID_OBJECT_GREATESTHEIGHT:
1068             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::HEIGHT_GREATEST);
1069             break;
1070         case SID_SECTION_ALIGN_LEFT:
1071         case SID_OBJECT_ALIGN_LEFT:
1072             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::LEFT,SID_SECTION_ALIGN_LEFT == _nId);
1073             break;
1074         case SID_SECTION_ALIGN_CENTER:
1075         case SID_OBJECT_ALIGN_CENTER:
1076             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::CENTER_HORIZONTAL,SID_SECTION_ALIGN_CENTER == _nId);
1077             break;
1078         case SID_SECTION_ALIGN_RIGHT:
1079         case SID_OBJECT_ALIGN_RIGHT:
1080             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::RIGHT,SID_SECTION_ALIGN_RIGHT == _nId);
1081             break;
1082         case SID_SECTION_ALIGN_UP:
1083         case SID_OBJECT_ALIGN_UP:
1084             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::TOP,SID_SECTION_ALIGN_UP == _nId);
1085             break;
1086         case SID_SECTION_ALIGN_MIDDLE:
1087         case SID_OBJECT_ALIGN_MIDDLE:
1088             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::CENTER_VERTICAL,SID_SECTION_ALIGN_MIDDLE == _nId);
1089             break;
1090         case SID_SECTION_ALIGN_DOWN:
1091         case SID_OBJECT_ALIGN_DOWN:
1092             alignControlsWithUndo(RID_STR_UNDO_ALIGNMENT,ControlModification::BOTTOM,SID_SECTION_ALIGN_DOWN == _nId);
1093             break;
1094 
1095         case SID_SECTION_SHRINK_BOTTOM:
1096         case SID_SECTION_SHRINK_TOP:
1097         case SID_SECTION_SHRINK:
1098             {
1099                 uno::Reference<report::XSection> xSection = getDesignView()->getCurrentSection();
1100                 shrinkSection(RID_STR_UNDO_SHRINK, xSection, _nId);
1101             }
1102             break;
1103 
1104         case SID_SELECTALL:
1105             getDesignView()->SelectAll(OBJ_NONE);
1106             break;
1107         case SID_SELECTALL_IN_SECTION:
1108             {
1109                 OSectionView* pSectionView = getCurrentSectionView();
1110                 if ( pSectionView )
1111                     pSectionView->MarkAll();
1112             }
1113             break;
1114         case SID_ESCAPE:
1115             getDesignView()->SetMode(DlgEdMode::Select);
1116             InvalidateFeature( SID_OBJECT_SELECT );
1117             break;
1118         case SID_SELECT_ALL_EDITS:
1119             getDesignView()->SelectAll(OBJ_RD_FORMATTEDFIELD);
1120             break;
1121         case SID_SELECT_ALL_LABELS:
1122             getDesignView()->SelectAll(OBJ_RD_FIXEDTEXT);
1123             break;
1124         case SID_TERMINATE_INPLACEACTIVATION:
1125             {
1126                 OSectionWindow* pSection = getDesignView()->getMarkedSection();
1127                 if ( pSection )
1128                     pSection->getReportSection().deactivateOle();
1129             }
1130             break;
1131         case SID_SELECT:
1132             if ( aArgs.getLength() == 1 )
1133                 select(aArgs[0].Value);
1134             break;
1135         case SID_SELECT_REPORT:
1136             select(uno::makeAny(m_xReportDefinition));
1137             break;
1138         case SID_EXECUTE_REPORT:
1139             getView()->PostUserEvent(LINK(this, OReportController,OnExecuteReport));
1140             break;
1141         case SID_RPT_NEW_FUNCTION:
1142             createNewFunction(aArgs[0].Value);
1143             break;
1144         case SID_COLLAPSE_SECTION:
1145             collapseSection(true);
1146             break;
1147         case SID_EXPAND_SECTION:
1148             collapseSection(false);
1149             break;
1150         case SID_NEXT_MARK:
1151             markSection(true);
1152             break;
1153         case SID_PREV_MARK:
1154             markSection(false);
1155             break;
1156         case SID_DELETE:
1157             if ( aArgs.getLength() == 1 )
1158             {
1159                 uno::Reference< report::XFunction> xFunction;
1160                 aArgs[0].Value >>= xFunction;
1161                 if ( xFunction.is() )
1162                 {
1163                     uno::Reference< report::XFunctions> xFunctions(xFunction->getParent(),uno::UNO_QUERY_THROW);
1164                     sal_Int32 nIndex = getPositionInIndexAccess(xFunctions, xFunction);
1165                     const OUString sUndoAction = RptResId(RID_STR_UNDO_REMOVE_FUNCTION);
1166                     UndoContext aUndoContext( getUndoManager(), sUndoAction );
1167                     xFunctions->removeByIndex(nIndex);
1168                     select(uno::makeAny(xFunctions->getParent()));
1169                     InvalidateFeature( SID_UNDO );
1170                 }
1171             }
1172             else
1173                 executeMethodWithUndo(RID_STR_UNDO_REMOVE_SELECTION,::std::mem_fn(&ODesignView::Delete));
1174             break;
1175         case SID_GRID_USE:
1176             m_bGridUse = !m_bGridUse;
1177             getDesignView()->setGridSnap(m_bGridUse);
1178             break;
1179         case SID_HELPLINES_MOVE:
1180             m_bHelplinesMove = !m_bHelplinesMove;
1181             getDesignView()->setDragStripes(m_bHelplinesMove);
1182             break;
1183         case SID_GRID_VISIBLE:
1184             m_bGridVisible = !m_bGridVisible;
1185             getDesignView()->toggleGrid(m_bGridVisible);
1186             break;
1187         case SID_RULER:
1188             m_bShowRuler = !m_bShowRuler;
1189             getDesignView()->showRuler(m_bShowRuler);
1190             break;
1191         case SID_OBJECT_SELECT:
1192             getDesignView()->SetMode(DlgEdMode::Select);
1193             InvalidateAll();
1194             break;
1195         case SID_INSERT_DIAGRAM:
1196             getDesignView()->SetMode( DlgEdMode::Insert );
1197             getDesignView()->SetInsertObj( OBJ_OLE2);
1198             createDefaultControl(aArgs);
1199             InvalidateAll();
1200             break;
1201         case SID_FM_FIXEDTEXT:
1202             getDesignView()->SetMode( DlgEdMode::Insert );
1203             getDesignView()->SetInsertObj( OBJ_RD_FIXEDTEXT );
1204             createDefaultControl(aArgs);
1205             InvalidateAll();
1206             break;
1207         case SID_INSERT_HFIXEDLINE:
1208             getDesignView()->SetMode( DlgEdMode::Insert );
1209             getDesignView()->SetInsertObj( OBJ_RD_HFIXEDLINE );
1210             createDefaultControl(aArgs);
1211             InvalidateAll();
1212             break;
1213         case SID_INSERT_VFIXEDLINE:
1214             getDesignView()->SetMode( DlgEdMode::Insert );
1215             getDesignView()->SetInsertObj( OBJ_RD_VFIXEDLINE );
1216             createDefaultControl(aArgs);
1217             InvalidateAll();
1218             break;
1219         case SID_FM_EDIT:
1220             getDesignView()->SetMode( DlgEdMode::Insert );
1221             getDesignView()->SetInsertObj( OBJ_RD_FORMATTEDFIELD );
1222             createDefaultControl(aArgs);
1223             InvalidateAll();
1224             break;
1225         case SID_FM_IMAGECONTROL:
1226             getDesignView()->SetMode( DlgEdMode::Insert );
1227             getDesignView()->SetInsertObj( OBJ_RD_IMAGECONTROL );
1228             createDefaultControl(aArgs);
1229             InvalidateAll();
1230             break;
1231         case SID_DRAWTBX_CS_BASIC:
1232         case SID_DRAWTBX_CS_BASIC1:
1233         case SID_DRAWTBX_CS_BASIC2:
1234         case SID_DRAWTBX_CS_BASIC3:
1235         case SID_DRAWTBX_CS_BASIC4:
1236         case SID_DRAWTBX_CS_BASIC5:
1237         case SID_DRAWTBX_CS_BASIC6:
1238         case SID_DRAWTBX_CS_BASIC7:
1239         case SID_DRAWTBX_CS_BASIC8:
1240         case SID_DRAWTBX_CS_BASIC9:
1241         case SID_DRAWTBX_CS_BASIC10:
1242         case SID_DRAWTBX_CS_BASIC11:
1243         case SID_DRAWTBX_CS_BASIC12:
1244         case SID_DRAWTBX_CS_BASIC13:
1245         case SID_DRAWTBX_CS_BASIC14:
1246         case SID_DRAWTBX_CS_BASIC15:
1247         case SID_DRAWTBX_CS_BASIC16:
1248         case SID_DRAWTBX_CS_BASIC17:
1249         case SID_DRAWTBX_CS_BASIC18:
1250         case SID_DRAWTBX_CS_BASIC19:
1251         case SID_DRAWTBX_CS_BASIC20:
1252         case SID_DRAWTBX_CS_BASIC21:
1253         case SID_DRAWTBX_CS_BASIC22:
1254         case SID_DRAWTBX_CS_SYMBOL1:
1255         case SID_DRAWTBX_CS_SYMBOL2:
1256         case SID_DRAWTBX_CS_SYMBOL3:
1257         case SID_DRAWTBX_CS_SYMBOL4:
1258         case SID_DRAWTBX_CS_SYMBOL5:
1259         case SID_DRAWTBX_CS_SYMBOL6:
1260         case SID_DRAWTBX_CS_SYMBOL7:
1261         case SID_DRAWTBX_CS_SYMBOL8:
1262         case SID_DRAWTBX_CS_SYMBOL9:
1263         case SID_DRAWTBX_CS_SYMBOL10:
1264         case SID_DRAWTBX_CS_SYMBOL11:
1265         case SID_DRAWTBX_CS_SYMBOL12:
1266         case SID_DRAWTBX_CS_SYMBOL13:
1267         case SID_DRAWTBX_CS_SYMBOL14:
1268         case SID_DRAWTBX_CS_SYMBOL15:
1269         case SID_DRAWTBX_CS_SYMBOL16:
1270         case SID_DRAWTBX_CS_SYMBOL17:
1271         case SID_DRAWTBX_CS_SYMBOL18:
1272         case SID_DRAWTBX_CS_ARROW1:
1273         case SID_DRAWTBX_CS_ARROW2:
1274         case SID_DRAWTBX_CS_ARROW3:
1275         case SID_DRAWTBX_CS_ARROW4:
1276         case SID_DRAWTBX_CS_ARROW5:
1277         case SID_DRAWTBX_CS_ARROW6:
1278         case SID_DRAWTBX_CS_ARROW7:
1279         case SID_DRAWTBX_CS_ARROW8:
1280         case SID_DRAWTBX_CS_ARROW9:
1281         case SID_DRAWTBX_CS_ARROW10:
1282         case SID_DRAWTBX_CS_ARROW11:
1283         case SID_DRAWTBX_CS_ARROW12:
1284         case SID_DRAWTBX_CS_ARROW13:
1285         case SID_DRAWTBX_CS_ARROW14:
1286         case SID_DRAWTBX_CS_ARROW15:
1287         case SID_DRAWTBX_CS_ARROW16:
1288         case SID_DRAWTBX_CS_ARROW17:
1289         case SID_DRAWTBX_CS_ARROW18:
1290         case SID_DRAWTBX_CS_ARROW19:
1291         case SID_DRAWTBX_CS_ARROW20:
1292         case SID_DRAWTBX_CS_ARROW21:
1293         case SID_DRAWTBX_CS_ARROW22:
1294         case SID_DRAWTBX_CS_ARROW23:
1295         case SID_DRAWTBX_CS_ARROW24:
1296         case SID_DRAWTBX_CS_ARROW25:
1297         case SID_DRAWTBX_CS_ARROW26:
1298         case SID_DRAWTBX_CS_STAR1:
1299         case SID_DRAWTBX_CS_STAR2:
1300         case SID_DRAWTBX_CS_STAR3:
1301         case SID_DRAWTBX_CS_STAR4:
1302         case SID_DRAWTBX_CS_STAR5:
1303         case SID_DRAWTBX_CS_STAR6:
1304         case SID_DRAWTBX_CS_STAR7:
1305         case SID_DRAWTBX_CS_STAR8:
1306         case SID_DRAWTBX_CS_STAR9:
1307         case SID_DRAWTBX_CS_STAR10:
1308         case SID_DRAWTBX_CS_STAR11:
1309         case SID_DRAWTBX_CS_STAR12:
1310         case SID_DRAWTBX_CS_FLOWCHART1:
1311         case SID_DRAWTBX_CS_FLOWCHART2:
1312         case SID_DRAWTBX_CS_FLOWCHART3:
1313         case SID_DRAWTBX_CS_FLOWCHART4:
1314         case SID_DRAWTBX_CS_FLOWCHART5:
1315         case SID_DRAWTBX_CS_FLOWCHART6:
1316         case SID_DRAWTBX_CS_FLOWCHART7:
1317         case SID_DRAWTBX_CS_FLOWCHART8:
1318         case SID_DRAWTBX_CS_FLOWCHART9:
1319         case SID_DRAWTBX_CS_FLOWCHART10:
1320         case SID_DRAWTBX_CS_FLOWCHART11:
1321         case SID_DRAWTBX_CS_FLOWCHART12:
1322         case SID_DRAWTBX_CS_FLOWCHART13:
1323         case SID_DRAWTBX_CS_FLOWCHART14:
1324         case SID_DRAWTBX_CS_FLOWCHART15:
1325         case SID_DRAWTBX_CS_FLOWCHART16:
1326         case SID_DRAWTBX_CS_FLOWCHART17:
1327         case SID_DRAWTBX_CS_FLOWCHART18:
1328         case SID_DRAWTBX_CS_FLOWCHART19:
1329         case SID_DRAWTBX_CS_FLOWCHART20:
1330         case SID_DRAWTBX_CS_FLOWCHART21:
1331         case SID_DRAWTBX_CS_FLOWCHART22:
1332         case SID_DRAWTBX_CS_FLOWCHART23:
1333         case SID_DRAWTBX_CS_FLOWCHART24:
1334         case SID_DRAWTBX_CS_FLOWCHART25:
1335         case SID_DRAWTBX_CS_FLOWCHART26:
1336         case SID_DRAWTBX_CS_FLOWCHART27:
1337         case SID_DRAWTBX_CS_FLOWCHART28:
1338         case SID_DRAWTBX_CS_CALLOUT1:
1339         case SID_DRAWTBX_CS_CALLOUT2:
1340         case SID_DRAWTBX_CS_CALLOUT3:
1341         case SID_DRAWTBX_CS_CALLOUT4:
1342         case SID_DRAWTBX_CS_CALLOUT5:
1343         case SID_DRAWTBX_CS_CALLOUT6:
1344         case SID_DRAWTBX_CS_CALLOUT7:
1345         case SID_DRAWTBX_CS_SYMBOL:
1346         case SID_DRAWTBX_CS_ARROW:
1347         case SID_DRAWTBX_CS_FLOWCHART:
1348         case SID_DRAWTBX_CS_CALLOUT:
1349         case SID_DRAWTBX_CS_STAR:
1350             getDesignView()->SetMode( DlgEdMode::Insert );
1351             {
1352                 URL aUrl = getURLForId(_nId);
1353                 sal_Int32 nIndex = 1;
1354                 OUString sType = aUrl.Complete.getToken(0,'.',nIndex);
1355                 if ( nIndex == -1 || sType.isEmpty() )
1356                 {
1357                     switch(_nId)
1358                     {
1359                         case SID_DRAWTBX_CS_SYMBOL:
1360                             sType = "smiley";
1361                             break;
1362                         case SID_DRAWTBX_CS_ARROW:
1363                             sType = "left-right-arrow";
1364                             break;
1365                         case SID_DRAWTBX_CS_FLOWCHART:
1366                             sType = "flowchart-internal-storage";
1367                             break;
1368                         case SID_DRAWTBX_CS_CALLOUT:
1369                             sType = "round-rectangular-callout";
1370                             break;
1371                         case SID_DRAWTBX_CS_STAR:
1372                             sType = "star5";
1373                             break;
1374                         default:
1375                             sType = "diamond";
1376                     }
1377                 }
1378                 else
1379                     sType = aUrl.Complete.getToken(0,'.',nIndex);
1380 
1381                 getDesignView()->SetInsertObj( OBJ_CUSTOMSHAPE ,sType);
1382                 createDefaultControl(aArgs);
1383             }
1384             InvalidateAll();
1385             break;
1386         case SID_RPT_SHOWREPORTEXPLORER:
1387             if ( isUiVisible() )
1388                 getDesignView()->toggleReportExplorer();
1389             break;
1390         case SID_FM_ADD_FIELD:
1391             if ( isUiVisible() )
1392                 getDesignView()->toggleAddField();
1393             break;
1394         case SID_SHOW_PROPERTYBROWSER:
1395             if ( m_bShowProperties )
1396                 m_sLastActivePage = getDesignView()->getCurrentPage();
1397             else
1398                 getDesignView()->setCurrentPage(m_sLastActivePage);
1399 
1400             if ( isUiVisible() )
1401             {
1402                 m_bShowProperties = !m_bShowProperties;
1403                 if ( aArgs.getLength() == 1 )
1404                     aArgs[0].Value >>= m_bShowProperties;
1405 
1406                 getDesignView()->togglePropertyBrowser(m_bShowProperties);
1407             }
1408             break;
1409         case SID_PROPERTYBROWSER_LAST_PAGE: // nothing to do
1410             m_sLastActivePage = getDesignView()->getCurrentPage();
1411             break;
1412         case SID_SPLIT_POSITION:
1413             getDesignView()->Resize();
1414             break;
1415         case SID_PAGEDIALOG:
1416         case SID_ATTR_CHAR_COLOR_BACKGROUND:
1417             {
1418                 uno::Reference<report::XSection> xSection;
1419                 if (aArgs.getLength() == 1 )
1420                     aArgs[0].Value >>= xSection;
1421                 else if (_nId == SID_ATTR_CHAR_COLOR_BACKGROUND)
1422                     xSection.set(getDesignView()->getMarkedSection()->getReportSection().getSection());
1423                 openPageDialog(xSection);
1424                 bForceBroadcast = true;
1425             }
1426             break;
1427         case SID_SORTINGANDGROUPING:
1428             openSortingAndGroupingDialog();
1429             break;
1430         case SID_BACKGROUND_COLOR:
1431             {
1432                 const util::Color aColor( lcl_extractBackgroundColor( aArgs ) );
1433                 if ( !impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CONTROLBACKGROUND,uno::makeAny(aColor),aArgs) )
1434                 {
1435                     uno::Reference< report::XSection > xSection = getDesignView()->getCurrentSection();
1436                     if ( xSection.is() )
1437                     {
1438                         xSection->setBackColor( aColor );
1439                     }
1440                 }
1441                 bForceBroadcast = true;
1442             }
1443             break;
1444         case SID_ATTR_CHAR_WEIGHT:
1445         case SID_ATTR_CHAR_POSTURE:
1446         case SID_ATTR_CHAR_UNDERLINE:
1447             {
1448                 uno::Reference< awt::XWindow> xWindow;
1449                 ::std::vector< uno::Reference< uno::XInterface > > aControlsFormats;
1450                 lcl_getReportControlFormat( aArgs, getDesignView(), xWindow, aControlsFormats );
1451 
1452                 const OUString sUndoAction(RptResId(RID_STR_UNDO_CHANGEFONT));
1453                 UndoContext aUndoContext( getUndoManager(), sUndoAction );
1454 
1455                 for (const auto& rxControlFormat : aControlsFormats)
1456                 {
1457                     uno::Reference< report::XReportControlFormat> xReportControlFormat(rxControlFormat,uno::UNO_QUERY);
1458                     lcl_setFontWPU_nothrow(xReportControlFormat,_nId);
1459                 }
1460             }
1461             break;
1462         case SID_ATTR_CHAR_COLOR:
1463         case SID_ATTR_CHAR_COLOR2:
1464         case SID_ATTR_CHAR_COLOR_EXT:
1465             {
1466                 const SequenceAsHashMap aMap(aArgs);
1467                 const util::Color aColor = aMap.getUnpackedValueOrDefault(PROPERTY_FONTCOLOR,util::Color());
1468                 impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CHARCOLOR,uno::makeAny(aColor),aArgs);
1469                 bForceBroadcast = true;
1470             }
1471             break;
1472         case SID_ATTR_CHAR_FONT:
1473             if ( aArgs.getLength() == 1 )
1474             {
1475                 awt::FontDescriptor aFont;
1476                 if ( aArgs[0].Value >>= aFont )
1477                 {
1478                     impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CHARFONTNAME,uno::makeAny(aFont.Name),aArgs);
1479                 }
1480             }
1481             break;
1482         case SID_ATTR_CHAR_FONTHEIGHT:
1483             if ( aArgs.getLength() == 1 )
1484             {
1485                 float fSelVal = 0.0;
1486                 if ( aArgs[0].Value >>= fSelVal )
1487                     impl_setPropertyAtControls_throw(RID_STR_UNDO_CHANGEFONT,PROPERTY_CHARHEIGHT,aArgs[0].Value,aArgs);
1488             }
1489             break;
1490         case SID_ATTR_PARA_ADJUST_LEFT:
1491         case SID_ATTR_PARA_ADJUST_CENTER:
1492         case SID_ATTR_PARA_ADJUST_RIGHT:
1493         case SID_ATTR_PARA_ADJUST_BLOCK:
1494             {
1495                 style::ParagraphAdjust eParagraphAdjust = style::ParagraphAdjust_LEFT;
1496                 switch(_nId)
1497                 {
1498                     case SID_ATTR_PARA_ADJUST_LEFT:
1499                         eParagraphAdjust = style::ParagraphAdjust_LEFT;
1500                         break;
1501                     case SID_ATTR_PARA_ADJUST_CENTER:
1502                         eParagraphAdjust = style::ParagraphAdjust_CENTER;
1503                         break;
1504                     case SID_ATTR_PARA_ADJUST_RIGHT:
1505                         eParagraphAdjust = style::ParagraphAdjust_RIGHT;
1506                         break;
1507                     case SID_ATTR_PARA_ADJUST_BLOCK:
1508                         eParagraphAdjust = style::ParagraphAdjust_BLOCK;
1509                         break;
1510                 }
1511                 impl_setPropertyAtControls_throw(RID_STR_UNDO_ALIGNMENT,PROPERTY_PARAADJUST,uno::makeAny(static_cast<sal_Int16>(eParagraphAdjust)),aArgs);
1512 
1513                 InvalidateFeature(SID_ATTR_PARA_ADJUST_LEFT);
1514                 InvalidateFeature(SID_ATTR_PARA_ADJUST_CENTER);
1515                 InvalidateFeature(SID_ATTR_PARA_ADJUST_RIGHT);
1516                 InvalidateFeature(SID_ATTR_PARA_ADJUST_BLOCK);
1517             }
1518             break;
1519         case SID_CHAR_DLG:
1520             {
1521                 uno::Sequence< beans::NamedValue > aSettings;
1522                 uno::Reference< awt::XWindow> xWindow;
1523                 ::std::vector< uno::Reference< uno::XInterface > > aControlsFormats;
1524                 lcl_getReportControlFormat( aArgs, getDesignView(), xWindow, aControlsFormats );
1525 
1526                 if ( !aControlsFormats.empty() )
1527                 {
1528                     const OUString sUndoAction( RptResId( RID_STR_UNDO_CHANGEFONT ) );
1529                     UndoContext aUndoContext( getUndoManager(), sUndoAction );
1530 
1531                     for (const auto& rxControlFormat : aControlsFormats)
1532                     {
1533                         uno::Reference< report::XReportControlFormat > xFormat( rxControlFormat, uno::UNO_QUERY );
1534                         if ( !xFormat.is() )
1535                             continue;
1536 
1537                         if ( !aSettings.hasElements() )
1538                         {
1539                             ::rptui::openCharDialog( xFormat, xWindow, aSettings );
1540                             if ( !aSettings.hasElements() )
1541                                 break;
1542                         }
1543 
1544                         applyCharacterSettings( xFormat, aSettings );
1545                     }
1546 
1547                     InvalidateAll();
1548                 }
1549             }
1550             break;
1551         case SID_INSERT_GRAPHIC:
1552             insertGraphic();
1553             break;
1554         case SID_SETCONTROLDEFAULTS:
1555             break;
1556         case SID_CONDITIONALFORMATTING:
1557             {
1558                 uno::Reference< report::XFormattedField> xFormattedField(getDesignView()->getCurrentControlModel(),uno::UNO_QUERY);
1559                 if ( xFormattedField.is() )
1560                 {
1561                     ConditionalFormattingDialog aDlg(getFrameWeld(), xFormattedField, *this);
1562                     aDlg.run();
1563                 }
1564             }
1565             break;
1566         case SID_DATETIME:
1567             if ( m_xReportDefinition.is() )
1568             {
1569                 if ( !aArgs.hasElements() )
1570                 {
1571                     ODateTimeDialog aDlg(getFrameWeld(), getDesignView()->getCurrentSection(), this);
1572                     aDlg.run();
1573                 }
1574                 else
1575                     createDateTime(aArgs);
1576             }
1577             break;
1578         case SID_INSERT_FLD_PGNUMBER:
1579             if ( m_xReportDefinition.is() )
1580             {
1581                 if ( !aArgs.hasElements() )
1582                 {
1583                     OPageNumberDialog aDlg(getFrameWeld(), m_xReportDefinition, this);
1584                     aDlg.run();
1585                 }
1586                 else
1587                     createPageNumber(aArgs);
1588             }
1589             break;
1590         case SID_EXPORTDOC:
1591         case SID_EXPORTDOCASPDF:
1592         case SID_PRINTPREVIEW:
1593             break;
1594         case SID_EDITDOC:
1595             if(isEditable())
1596             { // the state should be changed to not editable
1597                 setModified(false);     // and we are not modified yet
1598             }
1599             setEditable(!isEditable());
1600             InvalidateAll();
1601             return;
1602         case SID_GROUP:
1603             break;
1604         case SID_ATTR_ZOOM:
1605             if ( !aArgs.hasElements() )
1606             {
1607                 openZoomDialog();
1608             }
1609             else if ( aArgs.getLength() == 1 && aArgs[0].Name == "Zoom" )
1610             {
1611                 SvxZoomItem aZoomItem;
1612                 aZoomItem.PutValue(aArgs[0].Value, 0);
1613                 m_nZoomValue = aZoomItem.GetValue();
1614                 m_eZoomType = aZoomItem.GetType();
1615                 impl_zoom_nothrow();
1616             }
1617             break;
1618         case SID_ATTR_ZOOMSLIDER:
1619             if ( aArgs.getLength() == 1 && aArgs[0].Name == "ZoomSlider" )
1620             {
1621                 SvxZoomSliderItem aZoomSlider;
1622                 aZoomSlider.PutValue(aArgs[0].Value, 0);
1623                 m_nZoomValue = aZoomSlider.GetValue();
1624                 m_eZoomType = SvxZoomType::PERCENT;
1625                 impl_zoom_nothrow();
1626             }
1627             break;
1628         default:
1629             OReportController_BASE::Execute(_nId,aArgs);
1630     }
1631     InvalidateFeature(_nId,Reference< XStatusListener >(),bForceBroadcast);
1632 }
1633 
impl_initialize()1634 void OReportController::impl_initialize( )
1635 {
1636     OReportController_BASE::impl_initialize();
1637 
1638     const ::comphelper::NamedValueCollection& rArguments( getInitParams() );
1639 
1640     rArguments.get_ensureType( PROPERTY_REPORTNAME, m_sName );
1641     if ( m_sName.isEmpty() )
1642         rArguments.get_ensureType( "DocumentTitle", m_sName );
1643 
1644     try
1645     {
1646         if ( m_xReportDefinition.is() )
1647         {
1648             getView()->initialize();    // show the windows and fill with our information
1649 
1650             m_aReportModel = reportdesign::OReportDefinition::getSdrModel(m_xReportDefinition);
1651             if ( !m_aReportModel )
1652                 throw RuntimeException();
1653             m_aReportModel->attachController( *this );
1654 
1655             clearUndoManager();
1656             UndoSuppressor aSuppressUndo( getUndoManager() );
1657 
1658             ::comphelper::NamedValueCollection aArgs(getModel()->getArgs());
1659             setMode(aArgs.getOrDefault("Mode", OUString("normal")));
1660 
1661             listen(true);
1662             setEditable( !m_aReportModel->IsReadOnly() );
1663             m_xFormatter.set(util::NumberFormatter::create(m_xContext), UNO_QUERY_THROW);
1664             m_xFormatter->attachNumberFormatsSupplier(Reference< XNumberFormatsSupplier>(m_xReportDefinition,uno::UNO_QUERY));
1665 
1666             utl::MediaDescriptor aDescriptor( m_xReportDefinition->getArgs() );
1667             OUString sHierarchicalDocumentName = aDescriptor.getUnpackedValueOrDefault("HierarchicalDocumentName",OUString());
1668 
1669             if ( sHierarchicalDocumentName.isEmpty() && getConnection().is() )
1670             {
1671                 uno::Reference<sdbcx::XTablesSupplier> xTablesSup(getConnection(),uno::UNO_QUERY_THROW);
1672                 uno::Reference<container::XNameAccess> xTables = xTablesSup->getTables();
1673                 const uno::Sequence< OUString > aNames( xTables->getElementNames() );
1674 
1675                 if ( aNames.hasElements() )
1676                 {
1677                     m_xReportDefinition->setCommand(aNames[0]);
1678                     m_xReportDefinition->setCommandType(sdb::CommandType::TABLE);
1679                 }
1680             }
1681 
1682             m_aVisualAreaSize = m_xReportDefinition->getVisualAreaSize(0);
1683 
1684         }
1685 
1686         // check if chart is supported by the engine
1687         checkChartEnabled();
1688         // restore the view data
1689         getDesignView()->toggleGrid(m_bGridVisible);
1690         getDesignView()->showRuler(m_bShowRuler);
1691         getDesignView()->togglePropertyBrowser(m_bShowProperties);
1692         getDesignView()->setCurrentPage(m_sLastActivePage);
1693         getDesignView()->unmarkAllObjects();
1694 
1695         if ( m_nPageNum != -1 )
1696         {
1697             if ( m_nPageNum < m_aReportModel->GetPageCount() )
1698             {
1699                 const OReportPage* pPage = dynamic_cast<OReportPage*>(m_aReportModel->GetPage(static_cast<sal_uInt16>(m_nPageNum)));
1700                 if ( pPage )
1701                 {
1702                     uno::Sequence< beans::PropertyValue> aArgs(1);
1703                     aArgs[0].Value <<= pPage->getSection();
1704                     executeUnChecked(SID_SELECT,aArgs);
1705                 }
1706             }
1707             else
1708                 m_nPageNum = -1;
1709         }
1710         getDesignView()->collapseSections(m_aCollapsedSections);
1711         impl_zoom_nothrow();
1712         getDesignView()->Resize();
1713         getDesignView()->Invalidate();
1714         InvalidateAll();
1715 
1716         if ( m_bShowProperties && m_nPageNum == -1 )
1717         {
1718             m_sLastActivePage = "Data";
1719             getDesignView()->setCurrentPage(m_sLastActivePage);
1720             uno::Sequence< beans::PropertyValue> aArgs;
1721             executeUnChecked(SID_SELECT_REPORT,aArgs);
1722         }
1723 
1724         setModified(false);     // and we are not modified yet
1725     }
1726     catch(const SQLException&)
1727     {
1728         DBG_UNHANDLED_EXCEPTION("reportdesign");
1729     }
1730 }
1731 
IMPL_LINK(OReportController,OnCreateHdl,OAddFieldWindow &,_rAddFieldDlg,void)1732 IMPL_LINK( OReportController, OnCreateHdl, OAddFieldWindow& ,_rAddFieldDlg, void)
1733 {
1734     weld::WaitObject aObj(getFrameWeld());
1735     uno::Sequence< beans::PropertyValue > aArgs = _rAddFieldDlg.getSelectedFieldDescriptors();
1736     // we use this way to create undo actions
1737     if ( aArgs.hasElements() )
1738     {
1739         executeChecked(SID_ADD_CONTROL_PAIR,aArgs);
1740     }
1741 }
1742 
Construct(vcl::Window * pParent)1743 bool OReportController::Construct(vcl::Window* pParent)
1744 {
1745     VclPtrInstance<ODesignView> pMyOwnView( pParent, m_xContext, *this );
1746     StartListening( *pMyOwnView );
1747     setView( pMyOwnView );
1748 
1749     // now that we have a view we can create the clipboard listener
1750     m_aSystemClipboard = TransferableDataHelper::CreateFromSystemClipboard( getView() );
1751     m_aSystemClipboard.StartClipboardListening( );
1752     m_pClipboardNotifier = new TransferableClipboardListener( LINK( this, OReportController, OnClipboardChanged ) );
1753     m_pClipboardNotifier->AddListener( getView() );
1754 
1755     OReportController_BASE::Construct(pParent);
1756     return true;
1757 }
1758 
suspend(sal_Bool)1759 sal_Bool SAL_CALL OReportController::suspend(sal_Bool /*_bSuspend*/)
1760 {
1761     if ( getBroadcastHelper().bInDispose || getBroadcastHelper().bDisposed )
1762         return true;
1763 
1764     SolarMutexGuard aSolarGuard;
1765     ::osl::MutexGuard aGuard( getMutex() );
1766 
1767     if ( getView() && getView()->IsInModalMode() )
1768         return false;
1769 
1770     // this suspend will be handled in the DBAccess interceptor implementation
1771     return true;
1772 }
1773 
describeSupportedFeatures()1774 void OReportController::describeSupportedFeatures()
1775 {
1776     DBSubComponentController::describeSupportedFeatures();
1777 
1778     implDescribeSupportedFeature( ".uno:TextDocument",              SID_RPT_TEXTDOCUMENT,           CommandGroup::APPLICATION );
1779     implDescribeSupportedFeature( ".uno:Spreadsheet",               SID_RPT_SPREADSHEET,            CommandGroup::APPLICATION );
1780 
1781     implDescribeSupportedFeature( ".uno:Redo",                      SID_REDO,                       CommandGroup::EDIT );
1782     implDescribeSupportedFeature( ".uno:Undo",                      SID_UNDO,                       CommandGroup::EDIT );
1783     implDescribeSupportedFeature( ".uno:SelectAll",                 SID_SELECTALL,                  CommandGroup::EDIT );
1784     implDescribeSupportedFeature( ".uno:SelectAllInSection",        SID_SELECTALL_IN_SECTION,       CommandGroup::EDIT );
1785     implDescribeSupportedFeature( ".uno:Delete",                    SID_DELETE,                     CommandGroup::EDIT );
1786     implDescribeSupportedFeature( ".uno:SelectReport",              SID_SELECT_REPORT,              CommandGroup::EDIT );
1787     implDescribeSupportedFeature( ".uno:ExecuteReport",             SID_EXECUTE_REPORT,             CommandGroup::EDIT );
1788 
1789     implDescribeSupportedFeature( ".uno:GridVisible",               SID_GRID_VISIBLE,               CommandGroup::VIEW );
1790     implDescribeSupportedFeature( ".uno:GridUse",                   SID_GRID_USE,                   CommandGroup::VIEW );
1791     implDescribeSupportedFeature( ".uno:HelplinesMove",             SID_HELPLINES_MOVE,             CommandGroup::VIEW );
1792     implDescribeSupportedFeature( ".uno:ShowRuler",                 SID_RULER,                      CommandGroup::VIEW );
1793     implDescribeSupportedFeature( ".uno:AddField",                  SID_FM_ADD_FIELD,               CommandGroup::VIEW );
1794     implDescribeSupportedFeature( ".uno:ReportNavigator",           SID_RPT_SHOWREPORTEXPLORER,     CommandGroup::VIEW );
1795     implDescribeSupportedFeature( ".uno:ControlProperties",         SID_SHOW_PROPERTYBROWSER,       CommandGroup::VIEW );
1796     implDescribeSupportedFeature( ".uno:DbSortingAndGrouping",      SID_SORTINGANDGROUPING,         CommandGroup::VIEW );
1797     implDescribeSupportedFeature( ".uno:PageHeaderFooter",          SID_PAGEHEADERFOOTER,           CommandGroup::VIEW );
1798     implDescribeSupportedFeature( ".uno:ReportHeaderFooter",        SID_REPORTHEADERFOOTER,         CommandGroup::VIEW );
1799     implDescribeSupportedFeature( ".uno:ZoomSlider",                SID_ATTR_ZOOMSLIDER );
1800     implDescribeSupportedFeature( ".uno:Zoom",                      SID_ATTR_ZOOM,                  CommandGroup::VIEW );
1801 
1802     implDescribeSupportedFeature( ".uno:ConditionalFormatting",     SID_CONDITIONALFORMATTING,      CommandGroup::FORMAT );
1803     implDescribeSupportedFeature( ".uno:PageDialog",                SID_PAGEDIALOG,                 CommandGroup::FORMAT );
1804     implDescribeSupportedFeature( ".uno:ResetAttributes",           SID_SETCONTROLDEFAULTS,         CommandGroup::FORMAT );
1805 
1806     implDescribeSupportedFeature( ".uno:Bold",                      SID_ATTR_CHAR_WEIGHT,           CommandGroup::FORMAT );
1807     implDescribeSupportedFeature( ".uno:Italic",                    SID_ATTR_CHAR_POSTURE,          CommandGroup::FORMAT );
1808     implDescribeSupportedFeature( ".uno:Underline",                 SID_ATTR_CHAR_UNDERLINE,        CommandGroup::FORMAT );
1809     implDescribeSupportedFeature( ".uno:DBBackgroundColor",         SID_ATTR_CHAR_COLOR_BACKGROUND, CommandGroup::FORMAT );
1810     implDescribeSupportedFeature( ".uno:BackgroundColor",           SID_BACKGROUND_COLOR,           CommandGroup::FORMAT );
1811     implDescribeSupportedFeature( ".uno:CharColorExt",              SID_ATTR_CHAR_COLOR_EXT);
1812     implDescribeSupportedFeature( ".uno:Color",                     SID_ATTR_CHAR_COLOR);
1813     implDescribeSupportedFeature( ".uno:FontColor",                 SID_ATTR_CHAR_COLOR2,           CommandGroup::FORMAT );
1814     implDescribeSupportedFeature( ".uno:FontDialog",                SID_CHAR_DLG,                   CommandGroup::FORMAT );
1815     implDescribeSupportedFeature( ".uno:LeftPara",                  SID_ATTR_PARA_ADJUST_LEFT,      CommandGroup::FORMAT );
1816     implDescribeSupportedFeature( ".uno:CenterPara",                SID_ATTR_PARA_ADJUST_CENTER,    CommandGroup::FORMAT );
1817     implDescribeSupportedFeature( ".uno:RightPara",                 SID_ATTR_PARA_ADJUST_RIGHT,     CommandGroup::FORMAT );
1818     implDescribeSupportedFeature( ".uno:JustifyPara",               SID_ATTR_PARA_ADJUST_BLOCK,     CommandGroup::FORMAT );
1819 
1820     implDescribeSupportedFeature( ".uno:FontHeight",                SID_ATTR_CHAR_FONTHEIGHT,       CommandGroup::FORMAT );
1821     implDescribeSupportedFeature( ".uno:CharFontName",              SID_ATTR_CHAR_FONT,             CommandGroup::FORMAT );
1822 
1823     implDescribeSupportedFeature( ".uno:ArrangeMenu",               SID_ARRANGEMENU,                CommandGroup::FORMAT );
1824     implDescribeSupportedFeature( ".uno:BringToFront",              SID_FRAME_TO_TOP,               CommandGroup::FORMAT );
1825     implDescribeSupportedFeature( ".uno:ObjectBackOne",             SID_FRAME_DOWN,                 CommandGroup::FORMAT );
1826     implDescribeSupportedFeature( ".uno:ObjectForwardOne",          SID_FRAME_UP,                   CommandGroup::FORMAT );
1827     implDescribeSupportedFeature( ".uno:SendToBack",                SID_FRAME_TO_BOTTOM,            CommandGroup::FORMAT );
1828     implDescribeSupportedFeature( ".uno:SetObjectToForeground",     SID_OBJECT_HEAVEN,              CommandGroup::FORMAT );
1829     implDescribeSupportedFeature( ".uno:SetObjectToBackground",     SID_OBJECT_HELL,                CommandGroup::FORMAT );
1830 
1831     implDescribeSupportedFeature( ".uno:ObjectAlign",               SID_OBJECT_ALIGN,               CommandGroup::FORMAT );
1832     implDescribeSupportedFeature( ".uno:ObjectAlignLeft",           SID_OBJECT_ALIGN_LEFT,          CommandGroup::FORMAT );
1833     implDescribeSupportedFeature( ".uno:AlignCenter",               SID_OBJECT_ALIGN_CENTER,        CommandGroup::FORMAT );
1834     implDescribeSupportedFeature( ".uno:ObjectAlignRight",          SID_OBJECT_ALIGN_RIGHT,         CommandGroup::FORMAT );
1835     implDescribeSupportedFeature( ".uno:AlignUp",                   SID_OBJECT_ALIGN_UP,            CommandGroup::FORMAT );
1836     implDescribeSupportedFeature( ".uno:AlignMiddle",               SID_OBJECT_ALIGN_MIDDLE,        CommandGroup::FORMAT );
1837     implDescribeSupportedFeature( ".uno:AlignDown",                 SID_OBJECT_ALIGN_DOWN,          CommandGroup::FORMAT );
1838 
1839     implDescribeSupportedFeature( ".uno:SectionAlign",              SID_SECTION_ALIGN );
1840     implDescribeSupportedFeature( ".uno:SectionAlignLeft",          SID_SECTION_ALIGN_LEFT,         CommandGroup::FORMAT );
1841     implDescribeSupportedFeature( ".uno:SectionAlignCenter",        SID_SECTION_ALIGN_CENTER,       CommandGroup::FORMAT );
1842     implDescribeSupportedFeature( ".uno:SectionAlignRight",         SID_SECTION_ALIGN_RIGHT,        CommandGroup::FORMAT );
1843     implDescribeSupportedFeature( ".uno:SectionAlignTop",           SID_SECTION_ALIGN_UP,           CommandGroup::FORMAT );
1844     implDescribeSupportedFeature( ".uno:SectionAlignMiddle",        SID_SECTION_ALIGN_MIDDLE,       CommandGroup::FORMAT );
1845     implDescribeSupportedFeature( ".uno:SectionAlignBottom",        SID_SECTION_ALIGN_DOWN,         CommandGroup::FORMAT );
1846     implDescribeSupportedFeature( ".uno:SectionShrink",             SID_SECTION_SHRINK,             CommandGroup::FORMAT );
1847     implDescribeSupportedFeature( ".uno:SectionShrinkTop",          SID_SECTION_SHRINK_TOP,         CommandGroup::FORMAT );
1848     implDescribeSupportedFeature( ".uno:SectionShrinkBottom",       SID_SECTION_SHRINK_BOTTOM,      CommandGroup::FORMAT );
1849 
1850     implDescribeSupportedFeature( ".uno:ObjectResize",              SID_OBJECT_RESIZING,            CommandGroup::FORMAT );
1851     implDescribeSupportedFeature( ".uno:SmallestWidth",             SID_OBJECT_SMALLESTWIDTH,       CommandGroup::FORMAT );
1852     implDescribeSupportedFeature( ".uno:SmallestHeight",            SID_OBJECT_SMALLESTHEIGHT,      CommandGroup::FORMAT );
1853     implDescribeSupportedFeature( ".uno:GreatestWidth",             SID_OBJECT_GREATESTWIDTH,       CommandGroup::FORMAT );
1854     implDescribeSupportedFeature( ".uno:GreatestHeight",            SID_OBJECT_GREATESTHEIGHT,      CommandGroup::FORMAT );
1855 
1856     implDescribeSupportedFeature( ".uno:DistributeSelection",       SID_DISTRIBUTE_DLG,             CommandGroup::FORMAT );
1857     implDescribeSupportedFeature( ".uno:DistributeHorzLeft",        SID_DISTRIBUTE_HLEFT,           CommandGroup::FORMAT );
1858     implDescribeSupportedFeature( ".uno:DistributeHorzCenter",      SID_DISTRIBUTE_HCENTER,         CommandGroup::FORMAT );
1859     implDescribeSupportedFeature( ".uno:DistributeHorzDistance",    SID_DISTRIBUTE_HDISTANCE,       CommandGroup::FORMAT );
1860     implDescribeSupportedFeature( ".uno:DistributeHorzRight",       SID_DISTRIBUTE_HRIGHT,          CommandGroup::FORMAT );
1861     implDescribeSupportedFeature( ".uno:DistributeVertTop",         SID_DISTRIBUTE_VTOP,            CommandGroup::FORMAT );
1862     implDescribeSupportedFeature( ".uno:DistributeVertCenter",      SID_DISTRIBUTE_VCENTER,         CommandGroup::FORMAT );
1863     implDescribeSupportedFeature( ".uno:DistributeVertDistance",    SID_DISTRIBUTE_VDISTANCE,       CommandGroup::FORMAT );
1864     implDescribeSupportedFeature( ".uno:DistributeVertBottom",      SID_DISTRIBUTE_VBOTTOM,         CommandGroup::FORMAT );
1865 
1866     implDescribeSupportedFeature( ".uno:ExportTo",                  SID_EXPORTDOC,                  CommandGroup::APPLICATION );
1867     implDescribeSupportedFeature( ".uno:ExportToPDF",               SID_EXPORTDOCASPDF,             CommandGroup::APPLICATION );
1868     implDescribeSupportedFeature( ".uno:PrintPreview",              SID_PRINTPREVIEW,               CommandGroup::APPLICATION );
1869 
1870     implDescribeSupportedFeature( ".uno:NewDoc",                    SID_NEWDOC,                     CommandGroup::DOCUMENT );
1871     implDescribeSupportedFeature( ".uno:Save",                      SID_SAVEDOC,                    CommandGroup::DOCUMENT );
1872     implDescribeSupportedFeature( ".uno:SaveAs",                    SID_SAVEASDOC,                  CommandGroup::DOCUMENT );
1873     implDescribeSupportedFeature( ".uno:SaveACopy",                 SID_SAVEACOPY,                  CommandGroup::DOCUMENT );
1874 
1875     implDescribeSupportedFeature( ".uno:InsertPageNumberField",     SID_INSERT_FLD_PGNUMBER,        CommandGroup::INSERT );
1876     implDescribeSupportedFeature( ".uno:InsertDateTimeField",       SID_DATETIME,                   CommandGroup::INSERT );
1877     implDescribeSupportedFeature( ".uno:InsertObjectChart",         SID_INSERT_DIAGRAM,             CommandGroup::INSERT );
1878     implDescribeSupportedFeature( ".uno:InsertGraphic",             SID_INSERT_GRAPHIC,             CommandGroup::INSERT );
1879     // controls
1880     implDescribeSupportedFeature( ".uno:SelectObject",              SID_OBJECT_SELECT,              CommandGroup::INSERT );
1881     implDescribeSupportedFeature( ".uno:Label",                     SID_FM_FIXEDTEXT,               CommandGroup::INSERT );
1882     implDescribeSupportedFeature( ".uno:Edit",                      SID_FM_EDIT,                    CommandGroup::INSERT );
1883     implDescribeSupportedFeature( ".uno:ImageControl",              SID_FM_IMAGECONTROL,            CommandGroup::INSERT );
1884     implDescribeSupportedFeature( ".uno:HFixedLine",                SID_INSERT_HFIXEDLINE,          CommandGroup::INSERT );
1885     implDescribeSupportedFeature( ".uno:VFixedLine",                SID_INSERT_VFIXEDLINE,          CommandGroup::INSERT );
1886 
1887     // shapes
1888     implDescribeSupportedFeature( ".uno:BasicShapes",               SID_DRAWTBX_CS_BASIC,           CommandGroup::INSERT );
1889     implDescribeSupportedFeature( ".uno:BasicShapes.rectangle",     SID_DRAWTBX_CS_BASIC1,          CommandGroup::INSERT );
1890     implDescribeSupportedFeature( ".uno:BasicShapes.round-rectangle",SID_DRAWTBX_CS_BASIC2,         CommandGroup::INSERT );
1891     implDescribeSupportedFeature( ".uno:BasicShapes.quadrat",       SID_DRAWTBX_CS_BASIC3,          CommandGroup::INSERT );
1892     implDescribeSupportedFeature( ".uno:BasicShapes.round-quadrat", SID_DRAWTBX_CS_BASIC4,          CommandGroup::INSERT );
1893     implDescribeSupportedFeature( ".uno:BasicShapes.circle",        SID_DRAWTBX_CS_BASIC5,          CommandGroup::INSERT );
1894     implDescribeSupportedFeature( ".uno:BasicShapes.ellipse",       SID_DRAWTBX_CS_BASIC6,          CommandGroup::INSERT );
1895     implDescribeSupportedFeature( ".uno:BasicShapes.circle-pie",    SID_DRAWTBX_CS_BASIC7,          CommandGroup::INSERT );
1896     implDescribeSupportedFeature( ".uno:BasicShapes.isosceles-triangle",SID_DRAWTBX_CS_BASIC8,      CommandGroup::INSERT );
1897     implDescribeSupportedFeature( ".uno:BasicShapes.right-triangle",SID_DRAWTBX_CS_BASIC9,          CommandGroup::INSERT );
1898     implDescribeSupportedFeature( ".uno:BasicShapes.trapezoid",     SID_DRAWTBX_CS_BASIC10,         CommandGroup::INSERT );
1899     implDescribeSupportedFeature( ".uno:BasicShapes.diamond",       SID_DRAWTBX_CS_BASIC11,         CommandGroup::INSERT );
1900     implDescribeSupportedFeature( ".uno:BasicShapes.parallelogram", SID_DRAWTBX_CS_BASIC12,         CommandGroup::INSERT );
1901     implDescribeSupportedFeature( ".uno:BasicShapes.pentagon",      SID_DRAWTBX_CS_BASIC13,         CommandGroup::INSERT );
1902     implDescribeSupportedFeature( ".uno:BasicShapes.hexagon",       SID_DRAWTBX_CS_BASIC14,         CommandGroup::INSERT );
1903     implDescribeSupportedFeature( ".uno:BasicShapes.octagon",       SID_DRAWTBX_CS_BASIC15,         CommandGroup::INSERT );
1904     implDescribeSupportedFeature( ".uno:BasicShapes.cross",         SID_DRAWTBX_CS_BASIC16,         CommandGroup::INSERT );
1905     implDescribeSupportedFeature( ".uno:BasicShapes.ring",          SID_DRAWTBX_CS_BASIC17,         CommandGroup::INSERT );
1906     implDescribeSupportedFeature( ".uno:BasicShapes.block-arc",     SID_DRAWTBX_CS_BASIC18,         CommandGroup::INSERT );
1907     implDescribeSupportedFeature( ".uno:BasicShapes.can",           SID_DRAWTBX_CS_BASIC19,         CommandGroup::INSERT );
1908     implDescribeSupportedFeature( ".uno:BasicShapes.cube",          SID_DRAWTBX_CS_BASIC20,         CommandGroup::INSERT );
1909     implDescribeSupportedFeature( ".uno:BasicShapes.paper",         SID_DRAWTBX_CS_BASIC21,         CommandGroup::INSERT );
1910     implDescribeSupportedFeature( ".uno:BasicShapes.frame",         SID_DRAWTBX_CS_BASIC22,         CommandGroup::INSERT );
1911 
1912     implDescribeSupportedFeature( ".uno:SymbolShapes",              SID_DRAWTBX_CS_SYMBOL,          CommandGroup::INSERT );
1913 
1914     implDescribeSupportedFeature( ".uno:SymbolShapes.smiley" ,      SID_DRAWTBX_CS_SYMBOL1,         CommandGroup::INSERT );
1915     implDescribeSupportedFeature( ".uno:SymbolShapes.sun" ,         SID_DRAWTBX_CS_SYMBOL2,         CommandGroup::INSERT );
1916     implDescribeSupportedFeature( ".uno:SymbolShapes.moon" ,        SID_DRAWTBX_CS_SYMBOL3,         CommandGroup::INSERT );
1917     implDescribeSupportedFeature( ".uno:SymbolShapes.lightning" ,   SID_DRAWTBX_CS_SYMBOL4,         CommandGroup::INSERT );
1918     implDescribeSupportedFeature( ".uno:SymbolShapes.heart" ,       SID_DRAWTBX_CS_SYMBOL5,         CommandGroup::INSERT );
1919     implDescribeSupportedFeature( ".uno:SymbolShapes.flower" ,      SID_DRAWTBX_CS_SYMBOL6,         CommandGroup::INSERT );
1920     implDescribeSupportedFeature( ".uno:SymbolShapes.cloud" ,       SID_DRAWTBX_CS_SYMBOL7,         CommandGroup::INSERT );
1921     implDescribeSupportedFeature( ".uno:SymbolShapes.forbidden" ,   SID_DRAWTBX_CS_SYMBOL8,         CommandGroup::INSERT );
1922     implDescribeSupportedFeature( ".uno:SymbolShapes.puzzle" ,      SID_DRAWTBX_CS_SYMBOL9,         CommandGroup::INSERT );
1923     implDescribeSupportedFeature( ".uno:SymbolShapes.bracket-pair" ,SID_DRAWTBX_CS_SYMBOL10,        CommandGroup::INSERT );
1924     implDescribeSupportedFeature( ".uno:SymbolShapes.left-bracket" ,SID_DRAWTBX_CS_SYMBOL11,        CommandGroup::INSERT );
1925     implDescribeSupportedFeature( ".uno:SymbolShapes.right-bracket",SID_DRAWTBX_CS_SYMBOL12,        CommandGroup::INSERT );
1926     implDescribeSupportedFeature( ".uno:SymbolShapes.brace-pair" ,  SID_DRAWTBX_CS_SYMBOL13,        CommandGroup::INSERT );
1927     implDescribeSupportedFeature( ".uno:SymbolShapes.left-brace" ,  SID_DRAWTBX_CS_SYMBOL14,        CommandGroup::INSERT );
1928     implDescribeSupportedFeature( ".uno:SymbolShapes.right-brace" , SID_DRAWTBX_CS_SYMBOL15,        CommandGroup::INSERT );
1929     implDescribeSupportedFeature( ".uno:SymbolShapes.quad-bevel" ,  SID_DRAWTBX_CS_SYMBOL16,        CommandGroup::INSERT );
1930     implDescribeSupportedFeature( ".uno:SymbolShapes.octagon-bevel",SID_DRAWTBX_CS_SYMBOL17,        CommandGroup::INSERT );
1931     implDescribeSupportedFeature( ".uno:SymbolShapes.diamond-bevel",SID_DRAWTBX_CS_SYMBOL18,        CommandGroup::INSERT );
1932 
1933     implDescribeSupportedFeature( ".uno:ArrowShapes.left-arrow" ,           SID_DRAWTBX_CS_ARROW1,  CommandGroup::INSERT );
1934     implDescribeSupportedFeature( ".uno:ArrowShapes.right-arrow" ,          SID_DRAWTBX_CS_ARROW2,  CommandGroup::INSERT );
1935     implDescribeSupportedFeature( ".uno:ArrowShapes.up-arrow" ,             SID_DRAWTBX_CS_ARROW3,  CommandGroup::INSERT );
1936     implDescribeSupportedFeature( ".uno:ArrowShapes.down-arrow" ,           SID_DRAWTBX_CS_ARROW4,  CommandGroup::INSERT );
1937     implDescribeSupportedFeature( ".uno:ArrowShapes.left-right-arrow" ,     SID_DRAWTBX_CS_ARROW5,  CommandGroup::INSERT );
1938     implDescribeSupportedFeature( ".uno:ArrowShapes.up-down-arrow" ,        SID_DRAWTBX_CS_ARROW6,  CommandGroup::INSERT );
1939     implDescribeSupportedFeature( ".uno:ArrowShapes.up-right-arrow" ,       SID_DRAWTBX_CS_ARROW7,  CommandGroup::INSERT );
1940     implDescribeSupportedFeature( ".uno:ArrowShapes.up-right-down-arrow" ,  SID_DRAWTBX_CS_ARROW8,  CommandGroup::INSERT );
1941     implDescribeSupportedFeature( ".uno:ArrowShapes.quad-arrow" ,           SID_DRAWTBX_CS_ARROW9,  CommandGroup::INSERT );
1942     implDescribeSupportedFeature( ".uno:ArrowShapes.corner-right-arrow" ,   SID_DRAWTBX_CS_ARROW10, CommandGroup::INSERT );
1943     implDescribeSupportedFeature( ".uno:ArrowShapes.split-arrow" ,          SID_DRAWTBX_CS_ARROW11, CommandGroup::INSERT );
1944     implDescribeSupportedFeature( ".uno:ArrowShapes.striped-right-arrow" ,  SID_DRAWTBX_CS_ARROW12, CommandGroup::INSERT );
1945     implDescribeSupportedFeature( ".uno:ArrowShapes.notched-right-arrow" ,  SID_DRAWTBX_CS_ARROW13, CommandGroup::INSERT );
1946     implDescribeSupportedFeature( ".uno:ArrowShapes.pentagon-right" ,       SID_DRAWTBX_CS_ARROW14, CommandGroup::INSERT );
1947     implDescribeSupportedFeature( ".uno:ArrowShapes.chevron" ,              SID_DRAWTBX_CS_ARROW15, CommandGroup::INSERT );
1948     implDescribeSupportedFeature( ".uno:ArrowShapes.right-arrow-callout" ,  SID_DRAWTBX_CS_ARROW16, CommandGroup::INSERT );
1949     implDescribeSupportedFeature( ".uno:ArrowShapes.left-arrow-callout" ,   SID_DRAWTBX_CS_ARROW17, CommandGroup::INSERT );
1950     implDescribeSupportedFeature( ".uno:ArrowShapes.up-arrow-callout" ,     SID_DRAWTBX_CS_ARROW18, CommandGroup::INSERT );
1951     implDescribeSupportedFeature( ".uno:ArrowShapes.down-arrow-callout" ,   SID_DRAWTBX_CS_ARROW19, CommandGroup::INSERT );
1952     implDescribeSupportedFeature( ".uno:ArrowShapes.left-right-arrow-callout",SID_DRAWTBX_CS_ARROW20,       CommandGroup::INSERT );
1953     implDescribeSupportedFeature( ".uno:ArrowShapes.up-down-arrow-callout" ,SID_DRAWTBX_CS_ARROW21, CommandGroup::INSERT );
1954     implDescribeSupportedFeature( ".uno:ArrowShapes.up-right-arrow-callout",SID_DRAWTBX_CS_ARROW22, CommandGroup::INSERT );
1955     implDescribeSupportedFeature( ".uno:ArrowShapes.quad-arrow-callout" ,   SID_DRAWTBX_CS_ARROW23, CommandGroup::INSERT );
1956     implDescribeSupportedFeature( ".uno:ArrowShapes.circular-arrow" ,       SID_DRAWTBX_CS_ARROW24, CommandGroup::INSERT );
1957     implDescribeSupportedFeature( ".uno:ArrowShapes.split-round-arrow" ,    SID_DRAWTBX_CS_ARROW25, CommandGroup::INSERT );
1958     implDescribeSupportedFeature( ".uno:ArrowShapes.s-sharped-arrow" ,      SID_DRAWTBX_CS_ARROW26, CommandGroup::INSERT );
1959 
1960     implDescribeSupportedFeature( ".uno:StarShapes.bang" ,                  SID_DRAWTBX_CS_STAR1,           CommandGroup::INSERT );
1961     implDescribeSupportedFeature( ".uno:StarShapes.star4" ,                 SID_DRAWTBX_CS_STAR2,           CommandGroup::INSERT );
1962     implDescribeSupportedFeature( ".uno:StarShapes.star5" ,                 SID_DRAWTBX_CS_STAR3,           CommandGroup::INSERT );
1963     implDescribeSupportedFeature( ".uno:StarShapes.star6" ,                 SID_DRAWTBX_CS_STAR4,           CommandGroup::INSERT );
1964     implDescribeSupportedFeature( ".uno:StarShapes.star8" ,                 SID_DRAWTBX_CS_STAR5,           CommandGroup::INSERT );
1965     implDescribeSupportedFeature( ".uno:StarShapes.star12" ,                SID_DRAWTBX_CS_STAR6,           CommandGroup::INSERT );
1966     implDescribeSupportedFeature( ".uno:StarShapes.star24" ,                SID_DRAWTBX_CS_STAR7,           CommandGroup::INSERT );
1967     implDescribeSupportedFeature( ".uno:StarShapes.concave-star6" ,         SID_DRAWTBX_CS_STAR8,           CommandGroup::INSERT );
1968     implDescribeSupportedFeature( ".uno:StarShapes.vertical-scroll" ,       SID_DRAWTBX_CS_STAR9,           CommandGroup::INSERT );
1969     implDescribeSupportedFeature( ".uno:StarShapes.horizontal-scroll" ,     SID_DRAWTBX_CS_STAR10,          CommandGroup::INSERT );
1970     implDescribeSupportedFeature( ".uno:StarShapes.signet" ,                SID_DRAWTBX_CS_STAR11,          CommandGroup::INSERT );
1971     implDescribeSupportedFeature( ".uno:StarShapes.doorplate" ,             SID_DRAWTBX_CS_STAR12,          CommandGroup::INSERT );
1972 
1973     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-process" ,            SID_DRAWTBX_CS_FLOWCHART1,          CommandGroup::INSERT );
1974     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-alternate-process" ,  SID_DRAWTBX_CS_FLOWCHART2,          CommandGroup::INSERT );
1975     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-decision" ,           SID_DRAWTBX_CS_FLOWCHART3,          CommandGroup::INSERT );
1976     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-data" ,               SID_DRAWTBX_CS_FLOWCHART4,          CommandGroup::INSERT );
1977     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-predefined-process" , SID_DRAWTBX_CS_FLOWCHART5,          CommandGroup::INSERT );
1978     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-internal-storage" ,   SID_DRAWTBX_CS_FLOWCHART6,          CommandGroup::INSERT );
1979     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-document" ,           SID_DRAWTBX_CS_FLOWCHART7,          CommandGroup::INSERT );
1980     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-multidocument" ,      SID_DRAWTBX_CS_FLOWCHART8,          CommandGroup::INSERT );
1981     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-terminator" ,         SID_DRAWTBX_CS_FLOWCHART9,          CommandGroup::INSERT );
1982     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-preparation" ,        SID_DRAWTBX_CS_FLOWCHART10,         CommandGroup::INSERT );
1983     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-manual-input" ,       SID_DRAWTBX_CS_FLOWCHART11,         CommandGroup::INSERT );
1984     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-manual-operation" ,   SID_DRAWTBX_CS_FLOWCHART12,         CommandGroup::INSERT );
1985     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-connector" ,          SID_DRAWTBX_CS_FLOWCHART13,         CommandGroup::INSERT );
1986     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-off-page-connector" , SID_DRAWTBX_CS_FLOWCHART14,         CommandGroup::INSERT );
1987     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-card" ,               SID_DRAWTBX_CS_FLOWCHART15,         CommandGroup::INSERT );
1988     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-punched-tape" ,       SID_DRAWTBX_CS_FLOWCHART16,         CommandGroup::INSERT );
1989     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-summing-junction" ,   SID_DRAWTBX_CS_FLOWCHART17,         CommandGroup::INSERT );
1990     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-or" ,                 SID_DRAWTBX_CS_FLOWCHART18,         CommandGroup::INSERT );
1991     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-collate" ,            SID_DRAWTBX_CS_FLOWCHART19,         CommandGroup::INSERT );
1992     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-sort" ,               SID_DRAWTBX_CS_FLOWCHART20,         CommandGroup::INSERT );
1993     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-extract" ,            SID_DRAWTBX_CS_FLOWCHART21,         CommandGroup::INSERT );
1994     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-merge" ,              SID_DRAWTBX_CS_FLOWCHART22,         CommandGroup::INSERT );
1995     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-stored-data" ,        SID_DRAWTBX_CS_FLOWCHART23,         CommandGroup::INSERT );
1996     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-delay" ,              SID_DRAWTBX_CS_FLOWCHART24,         CommandGroup::INSERT );
1997     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-sequential-access" ,  SID_DRAWTBX_CS_FLOWCHART25,         CommandGroup::INSERT );
1998     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-magnetic-disk" ,      SID_DRAWTBX_CS_FLOWCHART26,         CommandGroup::INSERT );
1999     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-direct-access-storage",SID_DRAWTBX_CS_FLOWCHART27,        CommandGroup::INSERT );
2000     implDescribeSupportedFeature( ".uno:FlowChartShapes.flowchart-display" ,            SID_DRAWTBX_CS_FLOWCHART28,         CommandGroup::INSERT );
2001 
2002     implDescribeSupportedFeature( ".uno:CalloutShapes.rectangular-callout" ,        SID_DRAWTBX_CS_CALLOUT1,            CommandGroup::INSERT );
2003     implDescribeSupportedFeature( ".uno:CalloutShapes.round-rectangular-callout" ,  SID_DRAWTBX_CS_CALLOUT2,            CommandGroup::INSERT );
2004     implDescribeSupportedFeature( ".uno:CalloutShapes.round-callout" ,              SID_DRAWTBX_CS_CALLOUT3,            CommandGroup::INSERT );
2005     implDescribeSupportedFeature( ".uno:CalloutShapes.cloud-callout" ,              SID_DRAWTBX_CS_CALLOUT4,            CommandGroup::INSERT );
2006     implDescribeSupportedFeature( ".uno:CalloutShapes.line-callout-1" ,             SID_DRAWTBX_CS_CALLOUT5,            CommandGroup::INSERT );
2007     implDescribeSupportedFeature( ".uno:CalloutShapes.line-callout-2" ,             SID_DRAWTBX_CS_CALLOUT6,            CommandGroup::INSERT );
2008     implDescribeSupportedFeature( ".uno:CalloutShapes.line-callout-3" ,             SID_DRAWTBX_CS_CALLOUT7,            CommandGroup::INSERT );
2009 
2010     implDescribeSupportedFeature( ".uno:ArrowShapes",               SID_DRAWTBX_CS_ARROW,           CommandGroup::INSERT );
2011 
2012     implDescribeSupportedFeature( ".uno:FlowChartShapes",           SID_DRAWTBX_CS_FLOWCHART,       CommandGroup::INSERT );
2013     implDescribeSupportedFeature( ".uno:CalloutShapes",             SID_DRAWTBX_CS_CALLOUT,         CommandGroup::INSERT );
2014     implDescribeSupportedFeature( ".uno:StarShapes",                SID_DRAWTBX_CS_STAR,            CommandGroup::INSERT );
2015 
2016 
2017     // keys
2018     implDescribeSupportedFeature( ".uno:Escape",                    SID_ESCAPE);
2019 
2020     // internal one
2021     implDescribeSupportedFeature( ".uno:RPT_RPTHEADER_UNDO",            SID_REPORTHEADER_WITHOUT_UNDO);
2022     implDescribeSupportedFeature( ".uno:RPT_RPTFOOTER_UNDO",            SID_REPORTFOOTER_WITHOUT_UNDO);
2023     implDescribeSupportedFeature( ".uno:RPT_PGHEADER_UNDO",             SID_PAGEHEADER_WITHOUT_UNDO);
2024     implDescribeSupportedFeature( ".uno:RPT_PGFOOTER_UNDO",             SID_PAGEFOOTER_WITHOUT_UNDO);
2025     implDescribeSupportedFeature( ".uno:SID_GROUPHEADER",               SID_GROUPHEADER);
2026     implDescribeSupportedFeature( ".uno:SID_GROUPHEADER_WITHOUT_UNDO",  SID_GROUPHEADER_WITHOUT_UNDO);
2027     implDescribeSupportedFeature( ".uno:SID_GROUPFOOTER",               SID_GROUPFOOTER);
2028     implDescribeSupportedFeature( ".uno:SID_GROUPFOOTER_WITHOUT_UNDO",  SID_GROUPFOOTER_WITHOUT_UNDO);
2029     implDescribeSupportedFeature( ".uno:SID_GROUP_REMOVE",              SID_GROUP_REMOVE);
2030     implDescribeSupportedFeature( ".uno:SID_GROUP_APPEND",              SID_GROUP_APPEND);
2031     implDescribeSupportedFeature( ".uno:SID_ADD_CONTROL_PAIR",          SID_ADD_CONTROL_PAIR);
2032     implDescribeSupportedFeature( ".uno:SplitPosition",                 SID_SPLIT_POSITION);
2033     implDescribeSupportedFeature( ".uno:LastPropertyBrowserPage",       SID_PROPERTYBROWSER_LAST_PAGE);
2034     implDescribeSupportedFeature( ".uno:Select",                        SID_SELECT);
2035     implDescribeSupportedFeature( ".uno:InsertFunction",                SID_RPT_NEW_FUNCTION);
2036     implDescribeSupportedFeature( ".uno:NextMark",                      SID_NEXT_MARK);
2037     implDescribeSupportedFeature( ".uno:PrevMark",                      SID_PREV_MARK);
2038     implDescribeSupportedFeature( ".uno:TerminateInplaceActivation",    SID_TERMINATE_INPLACEACTIVATION);
2039     implDescribeSupportedFeature( ".uno:SelectAllLabels",               SID_SELECT_ALL_LABELS);
2040     implDescribeSupportedFeature( ".uno:SelectAllEdits",                SID_SELECT_ALL_EDITS);
2041     implDescribeSupportedFeature( ".uno:CollapseSection",           SID_COLLAPSE_SECTION);
2042     implDescribeSupportedFeature( ".uno:ExpandSection",             SID_EXPAND_SECTION);
2043     implDescribeSupportedFeature( ".uno:GetUndoStrings",            SID_GETUNDOSTRINGS);
2044     implDescribeSupportedFeature( ".uno:GetRedoStrings",            SID_GETREDOSTRINGS);
2045 }
2046 
impl_onModifyChanged()2047 void OReportController::impl_onModifyChanged()
2048 {
2049     try
2050     {
2051         if ( m_xReportDefinition.is() )
2052             m_xReportDefinition->setModified( impl_isModified() );
2053         DBSubComponentController::impl_onModifyChanged();
2054     }
2055     catch(const uno::Exception&)
2056     {
2057         DBG_UNHANDLED_EXCEPTION("reportdesign");
2058     }
2059 }
2060 
onLoadedMenu(const Reference<frame::XLayoutManager> & _xLayoutManager)2061 void OReportController::onLoadedMenu(const Reference< frame::XLayoutManager >& _xLayoutManager)
2062 {
2063     if ( !_xLayoutManager.is() )
2064         return;
2065 
2066     static const std::u16string_view s_sMenu[] = {
2067          u"private:resource/statusbar/statusbar"
2068         ,u"private:resource/toolbar/reportcontrols"
2069         ,u"private:resource/toolbar/drawbar"
2070         ,u"private:resource/toolbar/Formatting"
2071         ,u"private:resource/toolbar/alignmentbar"
2072         ,u"private:resource/toolbar/sectionalignmentbar"
2073         ,u"private:resource/toolbar/resizebar"
2074         ,u"private:resource/toolbar/sectionshrinkbar"
2075     };
2076     for (const auto & i : s_sMenu)
2077     {
2078         _xLayoutManager->createElement( OUString(i) );
2079         _xLayoutManager->requestElement( OUString(i) );
2080     }
2081 }
2082 
notifyGroupSections(const ContainerEvent & _rEvent,bool _bShow)2083 void OReportController::notifyGroupSections(const ContainerEvent& _rEvent,bool _bShow)
2084 {
2085     uno::Reference< report::XGroup> xGroup(_rEvent.Element,uno::UNO_QUERY);
2086     if ( !xGroup.is() )
2087         return;
2088 
2089     SolarMutexGuard aSolarGuard;
2090     ::osl::MutexGuard aGuard( getMutex() );
2091     sal_Int32 nGroupPos = 0;
2092     _rEvent.Accessor >>= nGroupPos;
2093 
2094     if ( _bShow )
2095     {
2096         xGroup->addPropertyChangeListener(PROPERTY_HEADERON, static_cast<XPropertyChangeListener*>(this));
2097         xGroup->addPropertyChangeListener(PROPERTY_FOOTERON, static_cast<XPropertyChangeListener*>(this));
2098     }
2099     else
2100     {
2101         xGroup->removePropertyChangeListener(PROPERTY_HEADERON, static_cast<XPropertyChangeListener*>(this));
2102         xGroup->removePropertyChangeListener(PROPERTY_FOOTERON, static_cast<XPropertyChangeListener*>(this));
2103     }
2104 
2105     if ( xGroup->getHeaderOn() )
2106     {
2107         groupChange(xGroup,PROPERTY_HEADERON,nGroupPos,_bShow);
2108         if (_bShow)
2109         {
2110             m_pReportControllerObserver->AddSection(xGroup->getHeader());
2111         }
2112         else
2113         {
2114             m_pReportControllerObserver->RemoveSection(xGroup->getHeader());
2115         }
2116     }
2117     if ( xGroup->getFooterOn() )
2118     {
2119         groupChange(xGroup,PROPERTY_FOOTERON,nGroupPos,_bShow);
2120         if (_bShow)
2121         {
2122             m_pReportControllerObserver->AddSection(xGroup->getFooter());
2123         }
2124         else
2125         {
2126             m_pReportControllerObserver->RemoveSection(xGroup->getFooter());
2127         }
2128     }
2129 }
2130 
2131 // ::container::XContainerListener
elementInserted(const ContainerEvent & _rEvent)2132 void SAL_CALL OReportController::elementInserted( const ContainerEvent& _rEvent )
2133 {
2134     notifyGroupSections(_rEvent,true);
2135 }
2136 
elementRemoved(const ContainerEvent & _rEvent)2137 void SAL_CALL OReportController::elementRemoved( const ContainerEvent& _rEvent )
2138 {
2139     notifyGroupSections(_rEvent,false);
2140 }
2141 
elementReplaced(const ContainerEvent &)2142 void SAL_CALL OReportController::elementReplaced( const ContainerEvent& /*_rEvent*/ )
2143 {
2144     SolarMutexGuard aSolarGuard;
2145     ::osl::MutexGuard aGuard( getMutex() );
2146     OSL_FAIL("Not yet implemented!");
2147 }
2148 
propertyChange(const beans::PropertyChangeEvent & evt)2149 void SAL_CALL OReportController::propertyChange( const beans::PropertyChangeEvent& evt )
2150 {
2151     SolarMutexGuard aSolarGuard;
2152     ::osl::MutexGuard aGuard( getMutex() );
2153     try
2154     {
2155         bool bShow = false;
2156         evt.NewValue >>= bShow;
2157         if ( evt.Source == m_xReportDefinition )
2158         {
2159             if ( evt.PropertyName == PROPERTY_REPORTHEADERON )
2160             {
2161                 const sal_uInt16 nPosition = m_xReportDefinition->getPageHeaderOn() ? 1 : 0;
2162                 if ( bShow )
2163                 {
2164                     getDesignView()->addSection(m_xReportDefinition->getReportHeader(),DBREPORTHEADER,nPosition);
2165                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getReportHeader());
2166                 }
2167                 else
2168                 {
2169                     getDesignView()->removeSection(nPosition);
2170                 }
2171             }
2172             else if ( evt.PropertyName == PROPERTY_REPORTFOOTERON )
2173             {
2174                 sal_uInt16 nPosition = getDesignView()->getSectionCount();
2175                 if ( m_xReportDefinition->getPageFooterOn() )
2176                     --nPosition;
2177                 if ( bShow )
2178                 {
2179                     getDesignView()->addSection(m_xReportDefinition->getReportFooter(),DBREPORTFOOTER,nPosition);
2180                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getReportFooter());
2181                 }
2182                 else
2183                 {
2184                     getDesignView()->removeSection(nPosition - 1);
2185                 }
2186             }
2187             else if ( evt.PropertyName == PROPERTY_PAGEHEADERON )
2188             {
2189                 if ( bShow )
2190                 {
2191                     getDesignView()->addSection(m_xReportDefinition->getPageHeader(),DBPAGEHEADER,0);
2192                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getPageHeader());
2193                 }
2194                 else
2195                 {
2196                     getDesignView()->removeSection(sal_uInt16(0));
2197                 }
2198             }
2199             else if ( evt.PropertyName == PROPERTY_PAGEFOOTERON )
2200             {
2201                 if ( bShow )
2202                 {
2203                     getDesignView()->addSection(m_xReportDefinition->getPageFooter(),DBPAGEFOOTER);
2204                     m_pReportControllerObserver->AddSection(m_xReportDefinition->getPageFooter());
2205                 }
2206                 else
2207                 {
2208                     getDesignView()->removeSection(getDesignView()->getSectionCount() - 1);
2209                 }
2210             }
2211             else if (   evt.PropertyName == PROPERTY_COMMAND
2212                     ||  evt.PropertyName == PROPERTY_COMMANDTYPE
2213                     ||  evt.PropertyName == PROPERTY_ESCAPEPROCESSING
2214                     ||  evt.PropertyName == PROPERTY_FILTER
2215                     )
2216             {
2217                 m_xColumns.clear();
2218                 m_xHoldAlive.clear();
2219                 InvalidateFeature(SID_FM_ADD_FIELD);
2220                 if ( !getDesignView()->isAddFieldVisible() && isUiVisible() )
2221                     getDesignView()->toggleAddField();
2222             }
2223             /// TODO: check what we need to notify here TitleHelper
2224             /*else if (   evt.PropertyName.equals( PROPERTY_CAPTION ) )
2225                 updateTitle();*/
2226         }
2227         else
2228         {
2229             uno::Reference< report::XGroup> xGroup(evt.Source,uno::UNO_QUERY);
2230             if ( xGroup.is() )
2231             {
2232                 sal_Int32 nGroupPos = getGroupPosition(xGroup);
2233 
2234                 groupChange(xGroup,evt.PropertyName,nGroupPos,bShow);
2235             }
2236         }
2237     }
2238     catch(const uno::Exception&)
2239     {
2240         DBG_UNHANDLED_EXCEPTION("reportdesign");
2241     }
2242 }
2243 
2244 
disposing(const lang::EventObject & Source)2245 void SAL_CALL OReportController::disposing( const lang::EventObject& Source )
2246 {
2247     // simply disambiguate
2248     OReportController_BASE::disposing(Source);
2249 }
2250 
2251 
lcl_getNonVisibleGroupsBefore(const uno::Reference<report::XGroups> & _xGroups,sal_Int32 _nGroupPos,::std::function<bool (OGroupHelper *)> const & _pGroupMemberFunction)2252 static sal_uInt16 lcl_getNonVisibleGroupsBefore( const uno::Reference< report::XGroups>& _xGroups
2253                           ,sal_Int32 _nGroupPos
2254                           ,::std::function<bool(OGroupHelper *)> const & _pGroupMemberFunction)
2255 {
2256     uno::Reference< report::XGroup> xGroup;
2257     sal_uInt16 nNonVisibleGroups = 0;
2258     sal_Int32 nCount = _xGroups->getCount();
2259     for( sal_Int32 i = 0; i < _nGroupPos && i < nCount; ++i)
2260     {
2261         xGroup.set(_xGroups->getByIndex(i),uno::UNO_QUERY);
2262         OSL_ENSURE(xGroup.is(),"Group is NULL! -> GPF");
2263         OGroupHelper aGroupHelper(xGroup);
2264         if ( !_pGroupMemberFunction(&aGroupHelper) )
2265             ++nNonVisibleGroups;
2266     }
2267     return nNonVisibleGroups;
2268 }
2269 
groupChange(const uno::Reference<report::XGroup> & _xGroup,std::u16string_view _sPropName,sal_Int32 _nGroupPos,bool _bShow)2270 void OReportController::groupChange( const uno::Reference< report::XGroup>& _xGroup,std::u16string_view _sPropName,sal_Int32 _nGroupPos,bool _bShow)
2271 {
2272     ::std::function<bool(OGroupHelper *)> pMemFun = ::std::mem_fn(&OGroupHelper::getHeaderOn);
2273     ::std::function<uno::Reference<report::XSection>(OGroupHelper *)> pMemFunSection = ::std::mem_fn(&OGroupHelper::getHeader);
2274     OUString sColor(DBGROUPHEADER);
2275     sal_uInt16 nPosition = 0;
2276     bool bHandle = false;
2277     if ( _sPropName == PROPERTY_HEADERON )
2278     {
2279         nPosition = m_xReportDefinition->getPageHeaderOn() ? (m_xReportDefinition->getReportHeaderOn() ? 2 : 1) : (m_xReportDefinition->getReportHeaderOn() ? 1 : 0);
2280         nPosition += (static_cast<sal_uInt16>(_nGroupPos) - lcl_getNonVisibleGroupsBefore(m_xReportDefinition->getGroups(),_nGroupPos,pMemFun));
2281         bHandle = true;
2282     }
2283     else if ( _sPropName == PROPERTY_FOOTERON )
2284     {
2285         pMemFun = ::std::mem_fn(&OGroupHelper::getFooterOn);
2286         pMemFunSection = ::std::mem_fn(&OGroupHelper::getFooter);
2287         nPosition = getDesignView()->getSectionCount();
2288 
2289         if ( m_xReportDefinition->getPageFooterOn() )
2290             --nPosition;
2291         if ( m_xReportDefinition->getReportFooterOn() )
2292             --nPosition;
2293         sColor = DBGROUPFOOTER;
2294         nPosition -= (static_cast<sal_uInt16>(_nGroupPos) - lcl_getNonVisibleGroupsBefore(m_xReportDefinition->getGroups(),_nGroupPos,pMemFun));
2295         if ( !_bShow )
2296             --nPosition;
2297         bHandle = true;
2298     }
2299     if ( bHandle )
2300     {
2301         if ( _bShow )
2302         {
2303             OGroupHelper aGroupHelper(_xGroup);
2304             getDesignView()->addSection(pMemFunSection(&aGroupHelper),sColor,nPosition);
2305         }
2306         else
2307         {
2308             getDesignView()->removeSection(nPosition);
2309         }
2310     }
2311 }
2312 
IMPL_LINK_NOARG(OReportController,OnClipboardChanged,TransferableDataHelper *,void)2313 IMPL_LINK_NOARG(OReportController, OnClipboardChanged, TransferableDataHelper*, void)
2314 {
2315     OnInvalidateClipboard();
2316 }
2317 
OnInvalidateClipboard()2318 void OReportController::OnInvalidateClipboard()
2319 {
2320     InvalidateFeature(SID_CUT);
2321     InvalidateFeature(SID_COPY);
2322     InvalidateFeature(SID_PASTE);
2323 }
2324 
openPageDialog(const uno::Reference<report::XSection> & _xSection)2325 void OReportController::openPageDialog(const uno::Reference<report::XSection>& _xSection)
2326 {
2327     if ( !m_xReportDefinition.is() )
2328         return;
2329 
2330     // UNO->ItemSet
2331     static SfxItemInfo aItemInfos[] =
2332     {
2333         { SID_ATTR_LRSPACE,     true },
2334         { SID_ATTR_ULSPACE,     true },
2335         { SID_ATTR_PAGE,        true },
2336         { SID_ATTR_PAGE_SIZE,   true },
2337         { SID_ENUM_PAGE_MODE,   true },
2338         { SID_PAPER_START,      true },
2339         { SID_PAPER_END,        true },
2340         { SID_ATTR_BRUSH,       true },
2341         { XATTR_FILLSTYLE,      true },
2342         { XATTR_FILLCOLOR,      true },
2343         { XATTR_FILLGRADIENT,       true },
2344         { XATTR_FILLHATCH,      true },
2345         { XATTR_FILLBITMAP,     true },
2346         { XATTR_FILLTRANSPARENCE,       true },
2347         { XATTR_GRADIENTSTEPCOUNT,      true },
2348         { XATTR_FILLBMP_TILE,       true },
2349         { XATTR_FILLBMP_POS,        true },
2350         { XATTR_FILLBMP_SIZEX,      true },
2351         { XATTR_FILLBMP_SIZEY,      true },
2352         { XATTR_FILLFLOATTRANSPARENCE,  true },
2353         { XATTR_SECONDARYFILLCOLOR,     true },
2354         { XATTR_FILLBMP_SIZELOG,        true },
2355         { XATTR_FILLBMP_TILEOFFSETX,    true },
2356         { XATTR_FILLBMP_TILEOFFSETY,    true },
2357         { XATTR_FILLBMP_STRETCH,        true },
2358         { XATTR_FILLBMP_POSOFFSETX,     true },
2359         { XATTR_FILLBMP_POSOFFSETY,     true },
2360         { XATTR_FILLBACKGROUND,     true },
2361         { SID_ATTR_METRIC,      true }
2362     };
2363 
2364     MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
2365     FieldUnit eUserMetric = MeasurementSystem::Metric == eSystem ? FieldUnit::CM : FieldUnit::INCH;
2366     static const sal_uInt16 pRanges[] =
2367     {
2368         RPTUI_ID_LRSPACE, XATTR_FILL_LAST,
2369         SID_ATTR_METRIC,SID_ATTR_METRIC,
2370         0
2371     };
2372     rtl::Reference<SfxItemPool> pPool( new SfxItemPool("ReportPageProperties", RPTUI_ID_LRSPACE, RPTUI_ID_METRIC, aItemInfos ) );
2373 
2374     const Graphic aNullGraphic;
2375     const ::Color aNullLineCol(COL_DEFAULT_SHAPE_STROKE); // #i121448# Use defined default color
2376     const ::Color aNullFillCol(COL_DEFAULT_SHAPE_FILLING); // #i121448# Use defined default color
2377     const XGradient aNullGrad(COL_BLACK, COL_WHITE);
2378     const XHatch aNullHatch(aNullLineCol);
2379 
2380     std::vector<SfxPoolItem*> pDefaults
2381     {
2382         new SvxLRSpaceItem(RPTUI_ID_LRSPACE),
2383         new SvxULSpaceItem(RPTUI_ID_ULSPACE),
2384         new SvxPageItem(RPTUI_ID_PAGE),
2385         new SvxSizeItem(RPTUI_ID_SIZE),
2386         new SfxUInt16Item(RPTUI_ID_PAGE_MODE,SVX_PAGE_MODE_STANDARD),
2387         new SfxUInt16Item(RPTUI_ID_START,PAPER_A4),
2388         new SfxUInt16Item(RPTUI_ID_END,PAPER_E),
2389         new SvxBrushItem(RPTUI_ID_BRUSH),
2390         new XFillStyleItem,
2391         new XFillColorItem("", aNullFillCol),
2392         new XFillGradientItem(aNullGrad),
2393         new XFillHatchItem(aNullHatch),
2394         new XFillBitmapItem(aNullGraphic),
2395         new XFillTransparenceItem,
2396         new XGradientStepCountItem,
2397         new XFillBmpTileItem,
2398         new XFillBmpPosItem,
2399         new XFillBmpSizeXItem,
2400         new XFillBmpSizeYItem,
2401         new XFillFloatTransparenceItem(aNullGrad, false),
2402         new XSecondaryFillColorItem("", aNullFillCol),
2403         new XFillBmpSizeLogItem,
2404         new XFillBmpTileOffsetXItem,
2405         new XFillBmpTileOffsetYItem,
2406         new XFillBmpStretchItem,
2407         new XFillBmpPosOffsetXItem,
2408         new XFillBmpPosOffsetYItem,
2409         new XFillBackgroundItem,
2410         new SfxUInt16Item(RPTUI_ID_METRIC,static_cast<sal_uInt16>(eUserMetric))
2411     };
2412 
2413     pPool->SetDefaults(&pDefaults);
2414 
2415 
2416     pPool->SetDefaultMetric( MapUnit::Map100thMM );    // ripped, don't understand why
2417     pPool->FreezeIdRanges();                        // the same
2418 
2419     try
2420     {
2421         SfxItemSet aDescriptor(*pPool, pRanges);
2422         // fill it
2423         if ( _xSection.is() )
2424             aDescriptor.Put(SvxBrushItem(::Color(ColorTransparency, _xSection->getBackColor()),RPTUI_ID_BRUSH));
2425         else
2426         {
2427             aDescriptor.Put(SvxSizeItem(RPTUI_ID_SIZE,VCLSize(getStyleProperty<awt::Size>(m_xReportDefinition,PROPERTY_PAPERSIZE))));
2428             aDescriptor.Put(SvxLRSpaceItem(getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_LEFTMARGIN)
2429                                             ,getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_RIGHTMARGIN),0,0,RPTUI_ID_LRSPACE));
2430             aDescriptor.Put(SvxULSpaceItem(static_cast<sal_uInt16>(getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_TOPMARGIN))
2431                                             ,static_cast<sal_uInt16>(getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_BOTTOMMARGIN)),RPTUI_ID_ULSPACE));
2432             aDescriptor.Put(SfxUInt16Item(SID_ATTR_METRIC,static_cast<sal_uInt16>(eUserMetric)));
2433 
2434             uno::Reference< style::XStyle> xPageStyle(getUsedStyle(m_xReportDefinition));
2435             if ( xPageStyle.is() )
2436             {
2437                 SvxPageItem aPageItem(RPTUI_ID_PAGE);
2438                 aPageItem.SetDescName(xPageStyle->getName());
2439                 uno::Reference<beans::XPropertySet> xProp(xPageStyle,uno::UNO_QUERY_THROW);
2440                 aPageItem.PutValue(xProp->getPropertyValue(PROPERTY_PAGESTYLELAYOUT),MID_PAGE_LAYOUT);
2441                 aPageItem.SetLandscape(getStyleProperty<bool>(m_xReportDefinition,PROPERTY_ISLANDSCAPE));
2442                 aPageItem.SetNumType(static_cast<SvxNumType>(getStyleProperty<sal_Int16>(m_xReportDefinition,PROPERTY_NUMBERINGTYPE)));
2443                 aDescriptor.Put(aPageItem);
2444                 aDescriptor.Put(SvxBrushItem(::Color(ColorTransparency, getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_BACKCOLOR)),RPTUI_ID_BRUSH));
2445             }
2446         }
2447 
2448         {   // want the dialog to be destroyed before our set
2449             ORptPageDialog aDlg(
2450                 getFrameWeld(), &aDescriptor,_xSection.is()
2451                            ? OUString("BackgroundDialog")
2452                            : OUString("PageDialog"));
2453             if (aDlg.run() == RET_OK)
2454             {
2455 
2456                 // ItemSet->UNO
2457                 // UNO-properties
2458                 const SfxItemSet* pSet = aDlg.GetOutputItemSet();
2459                 if ( _xSection.is() )
2460                 {
2461                     const SfxPoolItem* pItem;
2462                     if ( SfxItemState::SET == pSet->GetItemState( RPTUI_ID_BRUSH,true,&pItem))
2463                         _xSection->setBackColor(sal_Int32(static_cast<const SvxBrushItem*>(pItem)->GetColor()));
2464                 }
2465                 else
2466                 {
2467                     uno::Reference< beans::XPropertySet> xProp(getUsedStyle(m_xReportDefinition),uno::UNO_QUERY_THROW);
2468                     const OUString sUndoAction(RptResId(RID_STR_UNDO_CHANGEPAGE));
2469                     UndoContext aUndoContext( getUndoManager(), sUndoAction );
2470                     const SfxPoolItem* pItem = nullptr;
2471                     if ( SfxItemState::SET == pSet->GetItemState( RPTUI_ID_SIZE,true,&pItem))
2472                     {
2473                         uno::Any aValue;
2474                         static_cast<const SvxSizeItem*>(pItem)->QueryValue(aValue);
2475                         xProp->setPropertyValue(PROPERTY_PAPERSIZE,aValue);
2476                         resetZoomType();
2477                     }
2478 
2479                     if ( SfxItemState::SET == pSet->GetItemState( RPTUI_ID_LRSPACE,true,&pItem))
2480                     {
2481                         Any aValue;
2482                         static_cast<const SvxLRSpaceItem*>(pItem)->QueryValue(aValue,MID_L_MARGIN);
2483                         xProp->setPropertyValue(PROPERTY_LEFTMARGIN,aValue);
2484                         static_cast<const SvxLRSpaceItem*>(pItem)->QueryValue(aValue,MID_R_MARGIN);
2485                         xProp->setPropertyValue(PROPERTY_RIGHTMARGIN,aValue);
2486                     }
2487                     if ( SfxItemState::SET == pSet->GetItemState( RPTUI_ID_ULSPACE,true,&pItem))
2488                     {
2489                         xProp->setPropertyValue(PROPERTY_TOPMARGIN,uno::makeAny(static_cast<const SvxULSpaceItem*>(pItem)->GetUpper()));
2490                         xProp->setPropertyValue(PROPERTY_BOTTOMMARGIN,uno::makeAny(static_cast<const SvxULSpaceItem*>(pItem)->GetLower()));
2491                     }
2492                     if ( SfxItemState::SET == pSet->GetItemState( RPTUI_ID_PAGE,true,&pItem))
2493                     {
2494                         const SvxPageItem* pPageItem = static_cast<const SvxPageItem*>(pItem);
2495                         xProp->setPropertyValue(PROPERTY_ISLANDSCAPE,uno::makeAny(pPageItem->IsLandscape()));
2496                         xProp->setPropertyValue(PROPERTY_NUMBERINGTYPE,uno::makeAny(static_cast<sal_Int16>(pPageItem->GetNumType())));
2497                         uno::Any aValue;
2498                         pPageItem->QueryValue(aValue,MID_PAGE_LAYOUT);
2499                         xProp->setPropertyValue(PROPERTY_PAGESTYLELAYOUT,aValue);
2500                         resetZoomType();
2501                     }
2502                     if ( SfxItemState::SET == pSet->GetItemState( RPTUI_ID_BRUSH,true,&pItem))
2503                     {
2504                         ::Color aBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
2505                         xProp->setPropertyValue(PROPERTY_BACKTRANSPARENT,uno::makeAny(aBackColor == COL_TRANSPARENT));
2506                         xProp->setPropertyValue(PROPERTY_BACKCOLOR,uno::makeAny(aBackColor));
2507                     }
2508                 }
2509             }
2510         }
2511     }
2512     catch(const Exception&)
2513     {
2514         DBG_UNHANDLED_EXCEPTION("reportdesign");
2515     }
2516     pPool.clear();
2517 
2518     for (SfxPoolItem* pDefault : pDefaults)
2519         delete pDefault;
2520 
2521 }
2522 
2523 
attachModel(const uno::Reference<frame::XModel> & xModel)2524 sal_Bool SAL_CALL OReportController::attachModel(const uno::Reference< frame::XModel > & xModel)
2525 {
2526     ::osl::MutexGuard aGuard( getMutex() );
2527 
2528     uno::Reference< report::XReportDefinition > xReportDefinition( xModel, UNO_QUERY );
2529     if ( !xReportDefinition.is() )
2530         return false;
2531 
2532     uno::Reference< document::XUndoManagerSupplier > xTestSuppUndo( xModel, UNO_QUERY );
2533     if ( !xTestSuppUndo.is() )
2534         return false;
2535 
2536     m_xReportDefinition = xReportDefinition;
2537     return true;
2538 }
2539 
2540 
openSortingAndGroupingDialog()2541 void OReportController::openSortingAndGroupingDialog()
2542 {
2543     if ( !m_xReportDefinition.is() )
2544         return;
2545     if (!m_xGroupsFloater)
2546     {
2547         m_xGroupsFloater = std::make_shared<OGroupsSortingDialog>(getFrameWeld(), !isEditable(), this);
2548         SvtViewOptions aDlgOpt(EViewType::Window, OStringToOUString(m_xGroupsFloater->get_help_id(), RTL_TEXTENCODING_UTF8));
2549         if ( aDlgOpt.Exists() )
2550             m_xGroupsFloater->getDialog()->set_window_state(OUStringToOString(aDlgOpt.GetWindowState(), RTL_TEXTENCODING_ASCII_US));
2551     }
2552     if (isUiVisible())
2553     {
2554         if (!m_xGroupsFloater->getDialog()->get_visible())
2555             weld::DialogController::runAsync(m_xGroupsFloater, [this](sal_Int32 /*nResult*/) { m_xGroupsFloater.reset(); });
2556         else
2557             m_xGroupsFloater->response(RET_CANCEL);
2558     }
2559 }
2560 
getGroupPosition(const uno::Reference<report::XGroup> & _xGroup)2561 sal_Int32 OReportController::getGroupPosition(const uno::Reference< report::XGroup >& _xGroup)
2562 {
2563     return rptui::getPositionInIndexAccess(m_xReportDefinition->getGroups(),_xGroup);
2564 }
2565 
2566 
Notify(SfxBroadcaster &,SfxHint const & _rHint)2567 void OReportController::Notify(SfxBroadcaster & /* _rBc */, SfxHint const & _rHint)
2568 {
2569     const DlgEdHint* pDlgEdHint = dynamic_cast<const DlgEdHint*>(&_rHint);
2570     if (!(pDlgEdHint && pDlgEdHint->GetKind() == RPTUI_HINT_SELECTIONCHANGED))
2571         return;
2572 
2573     const sal_Int32 nSelectionCount = getDesignView()->getMarkedObjectCount();
2574     if ( m_nSelectionCount != nSelectionCount )
2575     {
2576         m_nSelectionCount = nSelectionCount;
2577         InvalidateAll();
2578     }
2579     lang::EventObject aEvent(*this);
2580     m_aSelectionListeners.forEach<view::XSelectionChangeListener>(
2581         [&aEvent] (uno::Reference<view::XSelectionChangeListener> const& xListener) {
2582             return xListener->selectionChanged(aEvent);
2583         });
2584 }
2585 
executeMethodWithUndo(const char * pUndoStrId,const::std::function<void (ODesignView *)> & _pMemfun)2586 void OReportController::executeMethodWithUndo(const char* pUndoStrId,const ::std::function<void(ODesignView *)>& _pMemfun)
2587 {
2588     const OUString sUndoAction = RptResId(pUndoStrId);
2589     UndoContext aUndoContext( getUndoManager(), sUndoAction );
2590     _pMemfun( getDesignView() );
2591     InvalidateFeature( SID_UNDO );
2592 }
2593 
alignControlsWithUndo(const char * pUndoStrId,ControlModification _nControlModification,bool _bAlignAtSection)2594 void OReportController::alignControlsWithUndo(const char* pUndoStrId, ControlModification _nControlModification, bool _bAlignAtSection)
2595 {
2596     const OUString sUndoAction = RptResId(pUndoStrId);
2597     UndoContext aUndoContext( getUndoManager(), sUndoAction );
2598     getDesignView()->alignMarkedObjects(_nControlModification,_bAlignAtSection);
2599     InvalidateFeature( SID_UNDO );
2600 }
2601 
shrinkSectionBottom(const uno::Reference<report::XSection> & _xSection)2602 void OReportController::shrinkSectionBottom(const uno::Reference<report::XSection>& _xSection)
2603 {
2604     const sal_Int32 nElements = _xSection->getCount();
2605     if (nElements == 0)
2606     {
2607         // there are no elements
2608         return;
2609     }
2610     const sal_Int32 nSectionHeight = _xSection->getHeight();
2611     sal_Int32 nMaxPositionY = 0;
2612     uno::Reference< report::XReportComponent> xReportComponent;
2613 
2614     // for every component get its Y-position and compare it to the current Y-position
2615     for (int i=0;i<nElements;i++)
2616     {
2617         xReportComponent.set(_xSection->getByIndex(i), uno::UNO_QUERY);
2618         const sal_Int32 nReportComponentPositionY = xReportComponent->getPositionY();
2619         const sal_Int32 nReportComponentHeight = xReportComponent->getHeight();
2620         const sal_Int32 nReportComponentPositionYAndHeight = nReportComponentPositionY + nReportComponentHeight;
2621         nMaxPositionY = std::max(nReportComponentPositionYAndHeight, nMaxPositionY);
2622     }
2623     // now we know the minimal Y-Position and maximal Y-Position
2624 
2625     if (nMaxPositionY > (nSectionHeight - 7) ) // Magic Number, we use a little bit less heights for right positioning
2626     {
2627         // the lowest position is already 0
2628         return;
2629     }
2630     _xSection->setHeight(nMaxPositionY);
2631 }
2632 
shrinkSectionTop(const uno::Reference<report::XSection> & _xSection)2633 void OReportController::shrinkSectionTop(const uno::Reference<report::XSection>& _xSection)
2634 {
2635     const sal_Int32 nElements = _xSection->getCount();
2636     if (nElements == 0)
2637     {
2638         // there are no elements
2639         return;
2640     }
2641 
2642     const sal_Int32 nSectionHeight = _xSection->getHeight();
2643     sal_Int32 nMinPositionY = nSectionHeight;
2644     uno::Reference< report::XReportComponent> xReportComponent;
2645 
2646     // for every component get its Y-position and compare it to the current Y-position
2647     for (int i=0;i<nElements;i++)
2648     {
2649         xReportComponent.set(_xSection->getByIndex(i), uno::UNO_QUERY);
2650         const sal_Int32 nReportComponentPositionY = xReportComponent->getPositionY();
2651         nMinPositionY = std::min(nReportComponentPositionY, nMinPositionY);
2652     }
2653     // now we know the minimal Y-Position and maximal Y-Position
2654     if (nMinPositionY == 0)
2655     {
2656         // the lowest position is already 0
2657         return;
2658     }
2659     for (int i=0;i<nElements;i++)
2660     {
2661         xReportComponent.set(_xSection->getByIndex(i), uno::UNO_QUERY);
2662         const sal_Int32 nReportComponentPositionY = xReportComponent->getPositionY();
2663         const sal_Int32 nNewPositionY = nReportComponentPositionY - nMinPositionY;
2664         xReportComponent->setPositionY(nNewPositionY);
2665     }
2666     const sal_Int32 nNewSectionHeight = nSectionHeight - nMinPositionY;
2667     _xSection->setHeight(nNewSectionHeight);
2668 }
2669 
shrinkSection(const char * pUndoStrId,const uno::Reference<report::XSection> & _xSection,sal_Int32 _nSid)2670 void OReportController::shrinkSection(const char* pUndoStrId, const uno::Reference<report::XSection>& _xSection, sal_Int32 _nSid)
2671 {
2672     if ( _xSection.is() )
2673     {
2674         const OUString sUndoAction = RptResId(pUndoStrId);
2675         UndoContext aUndoContext( getUndoManager(), sUndoAction );
2676 
2677         if (_nSid == SID_SECTION_SHRINK)
2678         {
2679             shrinkSectionTop(_xSection);
2680             shrinkSectionBottom(_xSection);
2681         }
2682         else if (_nSid == SID_SECTION_SHRINK_TOP)
2683         {
2684             shrinkSectionTop(_xSection);
2685         }
2686         else if (_nSid == SID_SECTION_SHRINK_BOTTOM)
2687         {
2688             shrinkSectionBottom(_xSection);
2689         }
2690     }
2691 
2692     InvalidateFeature( SID_UNDO );
2693 }
2694 
2695 
getViewData()2696 uno::Any SAL_CALL OReportController::getViewData()
2697 {
2698     ::osl::MutexGuard aGuard( getMutex() );
2699 
2700     const sal_Int32 nCommandIDs[] =
2701     {
2702         SID_GRID_VISIBLE,
2703         SID_GRID_USE,
2704         SID_HELPLINES_MOVE,
2705         SID_RULER,
2706         SID_SHOW_PROPERTYBROWSER,
2707         SID_PROPERTYBROWSER_LAST_PAGE,
2708         SID_SPLIT_POSITION
2709     };
2710 
2711     ::comphelper::NamedValueCollection aCommandProperties;
2712     for (sal_Int32 nCommandID : nCommandIDs)
2713     {
2714         const FeatureState aFeatureState = GetState( nCommandID );
2715 
2716         OUString sCommandURL( getURLForId( nCommandID ).Main );
2717         OSL_ENSURE( sCommandURL.startsWith( ".uno:" ), "OReportController::getViewData: illegal command URL!" );
2718         sCommandURL = sCommandURL.copy( 5 );
2719 
2720         Any aCommandState;
2721         if ( !!aFeatureState.bChecked )
2722             aCommandState <<= *aFeatureState.bChecked;
2723         else if ( aFeatureState.aValue.hasValue() )
2724             aCommandState = aFeatureState.aValue;
2725 
2726         aCommandProperties.put( sCommandURL, aCommandState );
2727     }
2728 
2729     ::comphelper::NamedValueCollection aViewData;
2730     aViewData.put( "CommandProperties", aCommandProperties.getPropertyValues() );
2731 
2732     if ( getDesignView() )
2733     {
2734         ::std::vector<sal_uInt16> aCollapsedPositions;
2735         getDesignView()->fillCollapsedSections(aCollapsedPositions);
2736         if ( !aCollapsedPositions.empty() )
2737         {
2738             uno::Sequence<beans::PropertyValue> aCollapsedSections(aCollapsedPositions.size());
2739             beans::PropertyValue* pCollapsedIter = aCollapsedSections.getArray();
2740             sal_Int32 i = 1;
2741             for (const auto& rPos : aCollapsedPositions)
2742             {
2743                 pCollapsedIter->Name = PROPERTY_SECTION + OUString::number(i);
2744                 pCollapsedIter->Value <<= static_cast<sal_Int32>(rPos);
2745                 ++pCollapsedIter;
2746                 ++i;
2747             }
2748 
2749             aViewData.put( "CollapsedSections", aCollapsedSections );
2750         }
2751 
2752         OSectionWindow* pSectionWindow = getDesignView()->getMarkedSection();
2753         if ( pSectionWindow )
2754         {
2755             aViewData.put( "MarkedSection", static_cast<sal_Int32>(pSectionWindow->getReportSection().getPage()->GetPageNum()) );
2756         }
2757     }
2758 
2759     aViewData.put( "ZoomFactor", m_nZoomValue );
2760     return uno::makeAny( aViewData.getPropertyValues() );
2761 }
2762 
restoreViewData(const uno::Any & i_data)2763 void SAL_CALL OReportController::restoreViewData(const uno::Any& i_data)
2764 {
2765     ::osl::MutexGuard aGuard( getMutex() );
2766 
2767     try
2768     {
2769         const ::comphelper::NamedValueCollection aViewData( i_data );
2770 
2771         m_aCollapsedSections = aViewData.getOrDefault( "CollapsedSections", m_aCollapsedSections );
2772         m_nPageNum = aViewData.getOrDefault( "MarkedSection", m_nPageNum );
2773         m_nZoomValue = aViewData.getOrDefault( "ZoomFactor", m_nZoomValue );
2774         // TODO: setting those 3 members is not enough - in theory, restoreViewData can be called when the
2775         // view is fully alive, so we need to reflect those 3 values in the view.
2776         // (At the moment, the method is called only during construction phase)
2777 
2778 
2779         ::comphelper::NamedValueCollection aCommandProperties( aViewData.get( "CommandProperties" ) );
2780         const ::std::vector< OUString > aCommandNames( aCommandProperties.getNames() );
2781 
2782         for ( const auto& rCommandName : aCommandNames )
2783         {
2784             const Any& rCommandValue = aCommandProperties.get( rCommandName );
2785             if ( !rCommandValue.hasValue() )
2786                 continue;
2787 
2788             if ( getView() )
2789             {
2790                 util::URL aCommand;
2791                 aCommand.Complete = ".uno:" + rCommandName;
2792 
2793                 Sequence< PropertyValue > aCommandArgs(1);
2794                 aCommandArgs[0].Name = "Value";
2795                 aCommandArgs[0].Value = rCommandValue;
2796 
2797                 executeUnChecked( aCommand, aCommandArgs );
2798             }
2799             else
2800             {
2801                 if ( rCommandName == "ShowRuler" )
2802                     OSL_VERIFY( rCommandValue >>= m_bShowRuler );
2803                 else if ( rCommandName == "HelplinesMove" )
2804                     OSL_VERIFY( rCommandValue >>= m_bHelplinesMove );
2805                 else if ( rCommandName == "GridVisible" )
2806                     OSL_VERIFY( rCommandValue >>= m_bGridVisible );
2807                 else if ( rCommandName == "GridUse" )
2808                     OSL_VERIFY( rCommandValue >>= m_bGridUse );
2809                 else if ( rCommandName == "ControlProperties" )
2810                     OSL_VERIFY( rCommandValue >>= m_bShowProperties );
2811                 else if ( rCommandName == "LastPropertyBrowserPage" )
2812                     OSL_VERIFY( rCommandValue >>= m_sLastActivePage );
2813                 else if ( rCommandName == "SplitPosition" )
2814                     OSL_VERIFY( rCommandValue >>= m_nSplitPos );
2815             }
2816         }
2817     }
2818     catch(const IllegalArgumentException&)
2819     {
2820         DBG_UNHANDLED_EXCEPTION("reportdesign");
2821     }
2822 }
2823 
getXFrame()2824 Reference<XFrame> OReportController::getXFrame()
2825 {
2826     if ( !m_xFrameLoader.is() )
2827     {
2828         m_xFrameLoader.set( frame::Desktop::create(m_xContext) );
2829     }
2830     const sal_Int32 nFrameSearchFlag = frame::FrameSearchFlag::TASKS | frame::FrameSearchFlag::CREATE;
2831     Reference<XFrame> xFrame = m_xFrameLoader->findFrame("_blank",nFrameSearchFlag);
2832     return xFrame;
2833 }
2834 
2835 
executeReport()2836 uno::Reference<frame::XModel> OReportController::executeReport()
2837 {
2838     OSL_ENSURE(m_xReportDefinition.is(),"Where is my report?");
2839 
2840     uno::Reference<frame::XModel> xModel;
2841     if ( m_xReportDefinition.is() )
2842     {
2843         const char* pErrorId = RID_ERR_NO_COMMAND;
2844         bool bEnabled = !m_xReportDefinition->getCommand().isEmpty();
2845         if ( bEnabled )
2846         {
2847             bEnabled = false;
2848             const sal_uInt16 nCount = m_aReportModel->GetPageCount();
2849             sal_uInt16 i = 0;
2850             for (; i < nCount && !bEnabled ; ++i)
2851             {
2852                 const SdrPage* pPage = m_aReportModel->GetPage(i);
2853                 bEnabled = pPage->GetObjCount() != 0;
2854             }
2855             if ( !bEnabled )
2856                 pErrorId = RID_ERR_NO_OBJECTS;
2857         }
2858 
2859         dbtools::SQLExceptionInfo aInfo;
2860         if ( !bEnabled )
2861         {
2862             sdb::SQLContext aFirstMessage;
2863             OUString sInfo = RptResId( pErrorId );
2864             aFirstMessage.Message = sInfo;
2865             aInfo = aFirstMessage;
2866             if ( isEditable() )
2867             {
2868                 sal_uInt16 nCommand = 0;
2869                 if (!strcmp(pErrorId, RID_ERR_NO_COMMAND))
2870                 {
2871                     if ( !m_bShowProperties )
2872                         executeUnChecked(SID_SHOW_PROPERTYBROWSER,uno::Sequence< beans::PropertyValue>());
2873 
2874                     m_sLastActivePage = "Data";
2875                     getDesignView()->setCurrentPage(m_sLastActivePage);
2876                     nCommand = SID_SELECT_REPORT;
2877                 }
2878                 else if ( getDesignView() && !getDesignView()->isAddFieldVisible() )
2879                 {
2880                     nCommand = SID_FM_ADD_FIELD;
2881                 }
2882                 if ( nCommand )
2883                 {
2884                     uno::Sequence< beans::PropertyValue> aArgs;
2885                     executeUnChecked(nCommand,aArgs);
2886                 }
2887             }
2888         }
2889         else
2890         {
2891             m_bInGeneratePreview = true;
2892             try
2893             {
2894                 weld::WaitObject aWait(getFrameWeld()); // cursor
2895                 if ( !m_xReportEngine.is() )
2896                     m_xReportEngine.set( report::ReportEngine::create(m_xContext) );
2897                 m_xReportEngine->setReportDefinition(m_xReportDefinition);
2898                 m_xReportEngine->setActiveConnection(getConnection());
2899                 Reference<XFrame> xFrame = getXFrame();
2900                 xModel = m_xReportEngine->createDocumentAlive(xFrame);
2901             }
2902             catch(const sdbc::SQLException&)
2903             {   // SQLExceptions and derived exceptions must not be translated
2904                 aInfo = ::cppu::getCaughtException();
2905             }
2906             catch(const uno::Exception& e)
2907             {
2908                 uno::Any aCaughtException( ::cppu::getCaughtException() );
2909 
2910                 // our first message says: we caught an exception
2911                 sdb::SQLContext aFirstMessage;
2912                 OUString sInfo(RptResId(RID_STR_CAUGHT_FOREIGN_EXCEPTION));
2913                 sInfo = sInfo.replaceAll("$type$", aCaughtException.getValueTypeName());
2914                 aFirstMessage.Message = sInfo;
2915 
2916                 // our second message: the message of the exception we caught
2917                 sdbc::SQLException aSecondMessage;
2918                 aSecondMessage.Message = e.Message;
2919                 aSecondMessage.Context = e.Context;
2920 
2921                 // maybe our third message: the message which is wrapped in the exception we caught
2922                 sdbc::SQLException aThirdMessage;
2923                 lang::WrappedTargetException aWrapped;
2924                 if ( aCaughtException >>= aWrapped )
2925                 {
2926                     aThirdMessage.Message = aWrapped.Message;
2927                     aThirdMessage.Context = aWrapped.Context;
2928                 }
2929 
2930                 if ( !aThirdMessage.Message.isEmpty() )
2931                     aSecondMessage.NextException <<= aThirdMessage;
2932                 aFirstMessage.NextException <<= aSecondMessage;
2933 
2934                 aInfo = aFirstMessage;
2935             }
2936             if (aInfo.isValid())
2937             {
2938                 const OUString suSQLContext = RptResId( RID_STR_COULD_NOT_CREATE_REPORT );
2939                 aInfo.prepend(suSQLContext);
2940             }
2941             m_bInGeneratePreview = false;
2942         }
2943 
2944         if (aInfo.isValid())
2945         {
2946             showError(aInfo);
2947         }
2948     }
2949     return xModel;
2950 }
2951 
getModel()2952 uno::Reference< frame::XModel >  SAL_CALL OReportController::getModel()
2953 {
2954     return m_xReportDefinition;
2955 }
2956 
getRowSet()2957 uno::Reference< sdbc::XRowSet > const & OReportController::getRowSet()
2958 {
2959     OSL_PRECOND( m_xReportDefinition.is(), "OReportController::getRowSet: no report definition?!" );
2960 
2961     if ( m_xRowSet.is() || !m_xReportDefinition.is() )
2962         return m_xRowSet;
2963 
2964     try
2965     {
2966         uno::Reference< sdbc::XRowSet > xRowSet(
2967             getORB()->getServiceManager()->createInstanceWithContext("com.sun.star.sdb.RowSet", getORB()),
2968             uno::UNO_QUERY );
2969         uno::Reference< beans::XPropertySet> xRowSetProp( xRowSet, uno::UNO_QUERY_THROW );
2970 
2971         xRowSetProp->setPropertyValue( PROPERTY_ACTIVECONNECTION, uno::makeAny( getConnection() ) );
2972         xRowSetProp->setPropertyValue( PROPERTY_APPLYFILTER, uno::makeAny( true ) );
2973 
2974         auto aNoConverter = std::make_shared<AnyConverter>();
2975         TPropertyNamePair aPropertyMediation;
2976         aPropertyMediation.emplace( PROPERTY_COMMAND, TPropertyConverter(PROPERTY_COMMAND,aNoConverter) );
2977         aPropertyMediation.emplace( PROPERTY_COMMANDTYPE, TPropertyConverter(PROPERTY_COMMANDTYPE,aNoConverter) );
2978         aPropertyMediation.emplace( PROPERTY_ESCAPEPROCESSING, TPropertyConverter(PROPERTY_ESCAPEPROCESSING,aNoConverter) );
2979         aPropertyMediation.emplace( PROPERTY_FILTER, TPropertyConverter(PROPERTY_FILTER,aNoConverter) );
2980 
2981         m_xRowSetMediator = new OPropertyMediator( m_xReportDefinition, xRowSetProp, aPropertyMediation );
2982         m_xRowSet = xRowSet;
2983     }
2984     catch(const uno::Exception&)
2985     {
2986         DBG_UNHANDLED_EXCEPTION("reportdesign");
2987     }
2988 
2989     return m_xRowSet;
2990 }
2991 
insertGraphic()2992 void OReportController::insertGraphic()
2993 {
2994     const OUString sTitle(RptResId(RID_STR_IMPORT_GRAPHIC));
2995     // build some arguments for the upcoming dialog
2996     try
2997     {
2998         uno::Reference< report::XSection> xSection = getDesignView()->getCurrentSection();
2999         ::sfx2::FileDialogHelper aDialog(ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW, FileDialogFlags::Graphic, getFrameWeld());
3000         aDialog.SetTitle( sTitle );
3001 
3002         uno::Reference< ui::dialogs::XFilePickerControlAccess > xController(aDialog.GetFilePicker(), UNO_QUERY_THROW);
3003         xController->setValue(ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, css::uno::Any(true));
3004         xController->enableControl(ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, false/*sal_True*/);
3005         xController->setValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, css::uno::Any(true) );
3006 
3007         if ( ERRCODE_NONE == aDialog.Execute() )
3008         {
3009             bool bLink = true;
3010             xController->getValue( ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, 0) >>= bLink;
3011             uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
3012                     { PROPERTY_IMAGEURL, Any(aDialog.GetPath()) },
3013                     { PROPERTY_PRESERVEIRI, Any(bLink) }
3014                 }));
3015             createControl(aArgs,xSection,OUString(),OBJ_RD_IMAGECONTROL);
3016         }
3017     }
3018     catch(const Exception&)
3019     {
3020         DBG_UNHANDLED_EXCEPTION("reportdesign");
3021     }
3022 }
3023 
3024 
select(const Any & aSelection)3025 sal_Bool SAL_CALL OReportController::select( const Any& aSelection )
3026 {
3027     ::osl::MutexGuard aGuard( getMutex() );
3028     if ( getDesignView() )
3029     {
3030         getDesignView()->unmarkAllObjects();
3031         getDesignView()->SetMode(DlgEdMode::Select);
3032 
3033         uno::Sequence< uno::Reference<report::XReportComponent> > aElements;
3034         if ( aSelection >>= aElements )
3035         {
3036             if ( aElements.hasElements() )
3037                 getDesignView()->showProperties(uno::Reference<uno::XInterface>(aElements[0],uno::UNO_QUERY));
3038             getDesignView()->setMarked(aElements, true);
3039         }
3040         else
3041         {
3042             uno::Reference<uno::XInterface> xObject(aSelection,uno::UNO_QUERY);
3043             uno::Reference<report::XReportComponent> xProp(xObject,uno::UNO_QUERY);
3044             if ( xProp.is() )
3045             {
3046                 getDesignView()->showProperties(xObject);
3047                 aElements.realloc(1);
3048                 aElements[0] = xProp;
3049                 getDesignView()->setMarked(aElements, true);
3050             }
3051             else
3052             {
3053                 uno::Reference<report::XSection> xSection(aSelection,uno::UNO_QUERY);
3054                 if ( !xSection.is() && xObject.is() )
3055                     getDesignView()->showProperties(xObject);
3056                 getDesignView()->setMarked(xSection,xSection.is());
3057             }
3058         }
3059         InvalidateAll();
3060     }
3061     return true;
3062 }
3063 
getSelection()3064 Any SAL_CALL OReportController::getSelection(  )
3065 {
3066     ::osl::MutexGuard aGuard( getMutex() );
3067     Any aRet;
3068     if ( getDesignView() )
3069     {
3070         aRet = getDesignView()->getCurrentlyShownProperty();
3071         if ( !aRet.hasValue() )
3072             aRet <<= getDesignView()->getCurrentSection();
3073     }
3074     return aRet;
3075 }
3076 
addSelectionChangeListener(const Reference<view::XSelectionChangeListener> & Listener)3077 void SAL_CALL OReportController::addSelectionChangeListener( const Reference< view::XSelectionChangeListener >& Listener )
3078 {
3079     m_aSelectionListeners.addInterface( Listener );
3080 }
3081 
removeSelectionChangeListener(const Reference<view::XSelectionChangeListener> & Listener)3082 void SAL_CALL OReportController::removeSelectionChangeListener( const Reference< view::XSelectionChangeListener >& Listener )
3083 {
3084     m_aSelectionListeners.removeInterface( Listener );
3085 }
3086 
createNewFunction(const uno::Any & _aValue)3087 void OReportController::createNewFunction(const uno::Any& _aValue)
3088 {
3089     uno::Reference< container::XIndexContainer> xFunctions(_aValue,uno::UNO_QUERY_THROW);
3090     const OUString sNewName = RptResId(RID_STR_FUNCTION);
3091     uno::Reference< report::XFunction> xFunction(report::Function::create(m_xContext));
3092     xFunction->setName(sNewName);
3093     // the call below will also create an undo action -> listener
3094     xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(xFunction));
3095 }
3096 
IMPL_LINK_NOARG(OReportController,OnExecuteReport,void *,void)3097 IMPL_LINK_NOARG( OReportController, OnExecuteReport, void*, void )
3098 {
3099     executeReport();
3100 }
3101 
createControl(const Sequence<PropertyValue> & _aArgs,const uno::Reference<report::XSection> & _xSection,const OUString & _sFunction,SdrObjKind _nObjectId)3102 void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,const uno::Reference< report::XSection>& _xSection,const OUString& _sFunction,SdrObjKind _nObjectId)
3103 {
3104     SequenceAsHashMap aMap(_aArgs);
3105     getDesignView()->setMarked(_xSection, true);
3106     OSectionWindow* pSectionWindow = getDesignView()->getMarkedSection();
3107     if ( !pSectionWindow )
3108         return;
3109 
3110     OSL_ENSURE(pSectionWindow->getReportSection().getSection() == _xSection,"Invalid section after marking the correct one.");
3111 
3112     sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_LEFTMARGIN);
3113     const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_RIGHTMARGIN);
3114     const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_xReportDefinition,PROPERTY_PAPERSIZE).Width - nRightMargin;
3115     awt::Point aPos = aMap.getUnpackedValueOrDefault(PROPERTY_POSITION,awt::Point(nLeftMargin,0));
3116     if ( aPos.X < nLeftMargin )
3117         aPos.X = nLeftMargin;
3118 
3119     SdrObject* pNewControl = nullptr;
3120     uno::Reference< report::XReportComponent> xShapeProp;
3121     if ( _nObjectId == OBJ_CUSTOMSHAPE )
3122     {
3123         pNewControl = SdrObjFactory::MakeNewObject(
3124             *m_aReportModel,
3125             SdrInventor::ReportDesign,
3126             _nObjectId);
3127         xShapeProp.set(pNewControl->getUnoShape(),uno::UNO_QUERY);
3128         OUString sCustomShapeType = getDesignView()->GetInsertObjString();
3129         if ( sCustomShapeType.isEmpty() )
3130             sCustomShapeType = "diamond";
3131         OReportSection::createDefault(sCustomShapeType,pNewControl);
3132         pNewControl->SetLogicRect(tools::Rectangle(3000,500,6000,3500)); // switch height and width
3133     }
3134     else if ( _nObjectId == OBJ_OLE2 || OBJ_RD_SUBREPORT == _nObjectId  )
3135     {
3136         pNewControl = SdrObjFactory::MakeNewObject(
3137             *m_aReportModel,
3138             SdrInventor::ReportDesign,
3139             _nObjectId);
3140 
3141         pNewControl->SetLogicRect(tools::Rectangle(3000,500,8000,5500)); // switch height and width
3142         xShapeProp.set(pNewControl->getUnoShape(),uno::UNO_QUERY_THROW);
3143         OOle2Obj* pObj = dynamic_cast<OOle2Obj*>(pNewControl);
3144         if ( pObj && !pObj->IsEmpty() )
3145         {
3146             pObj->initializeChart(getModel());
3147         }
3148     }
3149     else
3150     {
3151         std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pLabel;
3152         std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pControl;
3153 
3154         FmFormView::createControlLabelPair(
3155             getDesignView()->GetOutDev(),
3156             nLeftMargin,
3157             0,
3158             nullptr,
3159             nullptr,
3160             _nObjectId,
3161             SdrInventor::ReportDesign,
3162             OBJ_RD_FIXEDTEXT,
3163 
3164             // tdf#118963 Need a SdrModel for SdrObject creation. Dereferencing
3165             // m_aReportModel seems pretty safe, it's done in other places, initialized
3166             // in impl_initialize and throws a RuntimeException if not existing.
3167             *m_aReportModel,
3168 
3169             pLabel,
3170             pControl);
3171 
3172         pLabel.reset();
3173 
3174         pNewControl = pControl.release();
3175         OUnoObject* pObj = dynamic_cast<OUnoObject*>(pNewControl);
3176         assert(pObj);
3177         if(pObj)
3178         {
3179             uno::Reference<beans::XPropertySet> xUnoProp(pObj->GetUnoControlModel(),uno::UNO_QUERY);
3180             xShapeProp.set(pObj->getUnoShape(),uno::UNO_QUERY);
3181             uno::Reference<beans::XPropertySetInfo> xShapeInfo = xShapeProp->getPropertySetInfo();
3182             uno::Reference<beans::XPropertySetInfo> xInfo = xUnoProp->getPropertySetInfo();
3183 
3184             const OUString sProps[] = {   OUString(PROPERTY_NAME)
3185                                           ,OUString(PROPERTY_FONTDESCRIPTOR)
3186                                           ,OUString(PROPERTY_FONTDESCRIPTORASIAN)
3187                                           ,OUString(PROPERTY_FONTDESCRIPTORCOMPLEX)
3188                                           ,OUString(PROPERTY_ORIENTATION)
3189                                           ,OUString(PROPERTY_BORDER)
3190                                           ,OUString(PROPERTY_FORMATSSUPPLIER)
3191                                           ,OUString(PROPERTY_BACKGROUNDCOLOR)
3192             };
3193             for(const auto & sProp : sProps)
3194             {
3195                 if ( xInfo->hasPropertyByName(sProp) && xShapeInfo->hasPropertyByName(sProp) )
3196                     xUnoProp->setPropertyValue(sProp,xShapeProp->getPropertyValue(sProp));
3197             }
3198 
3199             if ( xInfo->hasPropertyByName(PROPERTY_BORDER) && xShapeInfo->hasPropertyByName(PROPERTY_CONTROLBORDER) )
3200                 xUnoProp->setPropertyValue(PROPERTY_BORDER,xShapeProp->getPropertyValue(PROPERTY_CONTROLBORDER));
3201 
3202 
3203             if ( xInfo->hasPropertyByName(PROPERTY_DATAFIELD) && !_sFunction.isEmpty() )
3204             {
3205                 ReportFormula aFunctionFormula( ReportFormula::Expression, _sFunction );
3206                 xUnoProp->setPropertyValue( PROPERTY_DATAFIELD, uno::makeAny( aFunctionFormula.getCompleteFormula() ) );
3207             }
3208 
3209             sal_Int32 nFormatKey = aMap.getUnpackedValueOrDefault(PROPERTY_FORMATKEY,sal_Int32(0));
3210             if ( nFormatKey && xInfo->hasPropertyByName(PROPERTY_FORMATKEY) )
3211                 xUnoProp->setPropertyValue( PROPERTY_FORMATKEY, uno::makeAny( nFormatKey ) );
3212 
3213             OUString sUrl = aMap.getUnpackedValueOrDefault(PROPERTY_IMAGEURL,OUString());
3214             if ( !sUrl.isEmpty() && xInfo->hasPropertyByName(PROPERTY_IMAGEURL) )
3215                 xUnoProp->setPropertyValue( PROPERTY_IMAGEURL, uno::makeAny( sUrl ) );
3216 
3217             pObj->CreateMediator(true);
3218 
3219             if ( _nObjectId == OBJ_RD_FIXEDTEXT ) // special case for fixed text
3220                 xUnoProp->setPropertyValue(PROPERTY_LABEL,uno::makeAny(OUnoObject::GetDefaultName(pObj)));
3221             else if ( _nObjectId == OBJ_RD_VFIXEDLINE )
3222             {
3223                 awt::Size aOlSize = xShapeProp->getSize();
3224                 xShapeProp->setSize(awt::Size(aOlSize.Height,aOlSize.Width)); // switch height and width
3225             }
3226         }
3227     }
3228 
3229     const sal_Int32 nShapeWidth = aMap.getUnpackedValueOrDefault(PROPERTY_WIDTH,xShapeProp->getWidth());
3230     if ( nShapeWidth != xShapeProp->getWidth() )
3231         xShapeProp->setWidth( nShapeWidth );
3232 
3233     const bool bChangedPos = (aPos.X + nShapeWidth) > nPaperWidth;
3234     if ( bChangedPos )
3235         aPos.X = nPaperWidth - nShapeWidth;
3236     xShapeProp->setPosition(aPos);
3237 
3238     correctOverlapping(pNewControl,pSectionWindow->getReportSection());
3239 }
3240 
createDateTime(const Sequence<PropertyValue> & _aArgs)3241 void OReportController::createDateTime(const Sequence< PropertyValue >& _aArgs)
3242 {
3243     getDesignView()->unmarkAllObjects();
3244 
3245     const OUString sUndoAction(RptResId(RID_STR_UNDO_INSERT_CONTROL));
3246     UndoContext aUndoContext( getUndoManager(), sUndoAction );
3247 
3248     SequenceAsHashMap aMap(_aArgs);
3249     aMap.createItemIfMissing(PROPERTY_FORMATKEY,aMap.getUnpackedValueOrDefault(PROPERTY_FORMATKEYDATE,sal_Int32(0)));
3250 
3251     uno::Reference< report::XSection> xSection = aMap.getUnpackedValueOrDefault(PROPERTY_SECTION,uno::Reference< report::XSection>());
3252     OUString sFunction;
3253 
3254     bool bDate = aMap.getUnpackedValueOrDefault(PROPERTY_DATE_STATE, false);
3255     if ( bDate )
3256     {
3257         sFunction = "TODAY()";
3258         createControl(aMap.getAsConstPropertyValueList(),xSection,sFunction);
3259     }
3260     bool bTime = aMap.getUnpackedValueOrDefault(PROPERTY_TIME_STATE, false);
3261     if ( bTime )
3262     {
3263         sFunction = "TIMEVALUE(NOW())";
3264         aMap[PROPERTY_FORMATKEY] <<= aMap.getUnpackedValueOrDefault(PROPERTY_FORMATKEYTIME,sal_Int32(0));
3265         createControl(aMap.getAsConstPropertyValueList(),xSection,sFunction);
3266     }
3267 }
3268 
createPageNumber(const Sequence<PropertyValue> & _aArgs)3269 void OReportController::createPageNumber(const Sequence< PropertyValue >& _aArgs)
3270 {
3271     getDesignView()->unmarkAllObjects();
3272 
3273     const OUString sUndoAction(RptResId(RID_STR_UNDO_INSERT_CONTROL));
3274     UndoContext aUndoContext( getUndoManager(), sUndoAction );
3275 
3276     if ( !m_xReportDefinition->getPageHeaderOn() )
3277     {
3278         uno::Sequence< beans::PropertyValue > aArgs;
3279         executeChecked(SID_PAGEHEADERFOOTER,aArgs);
3280     }
3281 
3282     SequenceAsHashMap aMap(_aArgs);
3283     bool bStateOfPage = aMap.getUnpackedValueOrDefault(PROPERTY_STATE, false);
3284 
3285     OUString sFunction( RptResId(STR_RPT_PN_PAGE) );
3286     sFunction = sFunction.replaceFirst("#PAGENUMBER#", "PageNumber()");
3287 
3288     if ( bStateOfPage )
3289     {
3290         sFunction += RptResId(STR_RPT_PN_PAGE_OF);
3291         sFunction = sFunction.replaceFirst("#PAGECOUNT#", "PageCount()");
3292     }
3293 
3294     bool bInPageHeader = aMap.getUnpackedValueOrDefault(PROPERTY_PAGEHEADERON, true);
3295     createControl(_aArgs,bInPageHeader ? m_xReportDefinition->getPageHeader() : m_xReportDefinition->getPageFooter(),sFunction);
3296 }
3297 
3298 
addPairControls(const Sequence<PropertyValue> & aArgs)3299 void OReportController::addPairControls(const Sequence< PropertyValue >& aArgs)
3300 {
3301     getDesignView()->unmarkAllObjects();
3302 
3303     // the FormatKey determines which field is required
3304     OSectionWindow* pSectionWindow[2];
3305     pSectionWindow[0] = getDesignView()->getMarkedSection();
3306 
3307     if ( !pSectionWindow[0] )
3308     {
3309         select(uno::makeAny(m_xReportDefinition->getDetail()));
3310         pSectionWindow[0] = getDesignView()->getMarkedSection();
3311         if ( !pSectionWindow[0] )
3312             return;
3313     }
3314 
3315     uno::Reference<report::XSection> xCurrentSection = getDesignView()->getCurrentSection();
3316     UndoContext aUndoContext(getUndoManager(), RptResId(RID_STR_UNDO_INSERT_CONTROL));
3317 
3318     try
3319     {
3320         bool bHandleOnlyOne = false;
3321         for(const PropertyValue& rArg : aArgs)
3322         {
3323             if (bHandleOnlyOne)
3324                 break;
3325             Sequence< PropertyValue > aValue;
3326             if ( !(rArg.Value >>= aValue) )
3327             {   // the sequence has only one element which already contains the descriptor
3328                 bHandleOnlyOne = true;
3329                 aValue = aArgs;
3330             }
3331             svx::ODataAccessDescriptor aDescriptor(aValue);
3332             SequenceAsHashMap aMap(aValue);
3333             uno::Reference<report::XSection> xSection = aMap.getUnpackedValueOrDefault("Section",xCurrentSection);
3334             uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
3335 
3336             getDesignView()->setMarked(xSection, true);
3337             pSectionWindow[0] = getDesignView()->getMarkedSection();
3338 
3339             sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_LEFTMARGIN);
3340             awt::Point aPos = aMap.getUnpackedValueOrDefault(PROPERTY_POSITION,awt::Point(nLeftMargin,0));
3341             if ( aPos.X < nLeftMargin )
3342                 aPos.X = nLeftMargin;
3343 
3344             // LLA: new feature, add the Label in dependency of the given DND_ACTION one section up, normal or one section down
3345             sal_Int8 nDNDAction = aMap.getUnpackedValueOrDefault("DNDAction", sal_Int8(0));
3346             pSectionWindow[1] = pSectionWindow[0];
3347             bool bLabelAboveTextField = nDNDAction == DND_ACTION_COPY;
3348             if ( bLabelAboveTextField || nDNDAction == DND_ACTION_LINK )
3349             {
3350                 // Add the Label one Section up
3351                 pSectionWindow[1] = getDesignView()->getMarkedSection(bLabelAboveTextField ? PREVIOUS : POST);
3352                 if (!pSectionWindow[1])
3353                 {
3354                     // maybe out of bounds
3355                     pSectionWindow[1] = pSectionWindow[0];
3356                 }
3357             }
3358             // clear all selections
3359             getDesignView()->unmarkAllObjects();
3360 
3361             uno::Reference< beans::XPropertySet > xField( aDescriptor[ svx::DataAccessDescriptorProperty::ColumnObject ], uno::UNO_QUERY );
3362             uno::Reference< lang::XComponent > xHoldAlive;
3363             if ( !xField.is() )
3364             {
3365                 OUString sCommand;
3366                 OUString sColumnName;
3367                 sal_Int32 nCommandType( -1 );
3368                 OSL_VERIFY( aDescriptor[ svx::DataAccessDescriptorProperty::Command ] >>= sCommand );
3369                 OSL_VERIFY( aDescriptor[ svx::DataAccessDescriptorProperty::ColumnName ] >>= sColumnName );
3370                 OSL_VERIFY( aDescriptor[ svx::DataAccessDescriptorProperty::CommandType ] >>= nCommandType );
3371 
3372                 uno::Reference< container::XNameAccess > xColumns;
3373                 uno::Reference< sdbc::XConnection > xConnection( getConnection() );
3374                 if ( !sCommand.isEmpty() && nCommandType != -1 && !sColumnName.isEmpty() && xConnection.is() )
3375                 {
3376                     if ( xReportDefinition->getCommand().isEmpty() )
3377                     {
3378                         xReportDefinition->setCommand(sCommand);
3379                         xReportDefinition->setCommandType(nCommandType);
3380                     }
3381 
3382                     xColumns = dbtools::getFieldsByCommandDescriptor(xConnection,nCommandType,sCommand,xHoldAlive);
3383                     if ( xColumns.is() && xColumns->hasByName(sColumnName) )
3384                         xField.set( xColumns->getByName( sColumnName ), uno::UNO_QUERY );
3385                 }
3386 
3387                 if ( !xField.is() )
3388                 {
3389                 #if OSL_DEBUG_LEVEL > 0
3390                     try
3391                     {
3392                         uno::Reference< beans::XPropertySet > xRowSetProps( getRowSet(), UNO_QUERY_THROW );
3393                         OUString sRowSetCommand;
3394                         sal_Int32 nRowSetCommandType( -1 );
3395                         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMAND ) >>= sRowSetCommand );
3396                         OSL_VERIFY( xRowSetProps->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nRowSetCommandType );
3397                         OSL_ENSURE( ( sRowSetCommand == sCommand ) && ( nCommandType == nRowSetCommandType ),
3398                             "OReportController::addPairControls: this only works for a data source which equals our current settings!" );
3399                         // if this asserts, then either our row set and our report definition are not in sync, or somebody
3400                         // requested the creation of a control/pair for another data source than what our report
3401                         // definition is bound to - which is not supported for the parameters case, since we
3402                         // can retrieve parameters from the RowSet only.
3403                     }
3404                     catch(const Exception&)
3405                     {
3406                         DBG_UNHANDLED_EXCEPTION("reportdesign");
3407                     }
3408                 #endif
3409 
3410                     // no column name - perhaps a parameter name?
3411                     uno::Reference< sdb::XParametersSupplier > xSuppParam( getRowSet(), uno::UNO_QUERY_THROW );
3412                     uno::Reference< container::XIndexAccess > xParams( xSuppParam->getParameters(), uno::UNO_SET_THROW );
3413                     sal_Int32 nParamCount( xParams->getCount() );
3414                     for ( sal_Int32 i=0; i<nParamCount; ++i)
3415                     {
3416                         uno::Reference< beans::XPropertySet > xParamCol( xParams->getByIndex(i), uno::UNO_QUERY_THROW );
3417                         OUString sParamName;
3418                         OSL_VERIFY( xParamCol->getPropertyValue("Name") >>= sParamName );
3419                         if ( sParamName == sColumnName )
3420                         {
3421                             xField = xParamCol;
3422                             break;
3423                         }
3424                     }
3425                 }
3426             }
3427             if ( !xField.is() )
3428                 continue;
3429 
3430             SdrObjKind nOBJID = OBJ_NONE;
3431             sal_Int32 nDataType = sdbc::DataType::BINARY;
3432             xField->getPropertyValue(PROPERTY_TYPE) >>= nDataType;
3433             switch ( nDataType )
3434             {
3435                 case sdbc::DataType::BINARY:
3436                 case sdbc::DataType::VARBINARY:
3437                 case sdbc::DataType::LONGVARBINARY:
3438                     nOBJID = OBJ_RD_IMAGECONTROL;
3439                     break;
3440                 default:
3441                     nOBJID = OBJ_RD_FORMATTEDFIELD;
3442                     break;
3443             }
3444 
3445             if ( !nOBJID )
3446                 continue;
3447 
3448             Reference< util::XNumberFormatsSupplier >  xSupplier = getReportNumberFormatter()->getNumberFormatsSupplier();
3449             if ( !xSupplier.is() )
3450                 continue;
3451 
3452             Reference< XNumberFormats >  xNumberFormats(xSupplier->getNumberFormats());
3453             std::unique_ptr<SdrUnoObj, SdrObjectFreeOp> pControl[2];
3454             const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(m_xReportDefinition,PROPERTY_RIGHTMARGIN);
3455             const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(m_xReportDefinition,PROPERTY_PAPERSIZE).Width - nRightMargin;
3456             OSectionView* pSectionViews[2];
3457             pSectionViews[0] = &pSectionWindow[1]->getReportSection().getSectionView();
3458             pSectionViews[1] = &pSectionWindow[0]->getReportSection().getSectionView();
3459 
3460             // find this in svx
3461             FmFormView::createControlLabelPair(
3462                 getDesignView()->GetOutDev(),
3463                 nLeftMargin,
3464                 0,
3465                 xField,
3466                 xNumberFormats,
3467                 nOBJID,
3468                 SdrInventor::ReportDesign,
3469                 OBJ_RD_FIXEDTEXT,
3470 
3471                 // tdf#118963 Need a SdrModel for SdrObject creation. Dereferencing
3472                 // m_aReportModel seems pretty safe, it's done in other places, initialized
3473                 // in impl_initialize and throws a RuntimeException if not existing.
3474                 *m_aReportModel,
3475 
3476                 pControl[0],
3477                 pControl[1]);
3478 
3479             if ( pControl[0] && pControl[1] )
3480             {
3481                 SdrPageView* pPgViews[2];
3482                 pPgViews[0] = pSectionViews[0]->GetSdrPageView();
3483                 pPgViews[1] = pSectionViews[1]->GetSdrPageView();
3484                 if ( pPgViews[0] && pPgViews[1] )
3485                 {
3486                     OUString sDefaultName;
3487                     size_t i = 0;
3488                     OUnoObject* pObjs[2];
3489                     for(i = 0; i < SAL_N_ELEMENTS(pControl); ++i)
3490                     {
3491                         pObjs[i] = dynamic_cast<OUnoObject*>(pControl[i].get());
3492                         assert(pObjs[i]);
3493                         uno::Reference<beans::XPropertySet> xUnoProp(pObjs[i]->GetUnoControlModel(),uno::UNO_QUERY_THROW);
3494                         uno::Reference< report::XReportComponent> xShapeProp(pObjs[i]->getUnoShape(),uno::UNO_QUERY_THROW);
3495                         xUnoProp->setPropertyValue(PROPERTY_NAME,xShapeProp->getPropertyValue(PROPERTY_NAME));
3496 
3497                         uno::Reference<beans::XPropertySetInfo> xShapeInfo = xShapeProp->getPropertySetInfo();
3498                         uno::Reference<beans::XPropertySetInfo> xInfo = xUnoProp->getPropertySetInfo();
3499                         const OUString sProps[] = {   OUString(PROPERTY_FONTDESCRIPTOR)
3500                                                             ,OUString(PROPERTY_FONTDESCRIPTORASIAN)
3501                                                             ,OUString(PROPERTY_FONTDESCRIPTORCOMPLEX)
3502                                                             ,OUString(PROPERTY_BORDER)
3503                                                             ,OUString(PROPERTY_BACKGROUNDCOLOR)
3504                         };
3505                         for(const auto & sProp : sProps)
3506                         {
3507                             if ( xInfo->hasPropertyByName(sProp) && xShapeInfo->hasPropertyByName(sProp) )
3508                                 xUnoProp->setPropertyValue(sProp,xShapeProp->getPropertyValue(sProp));
3509                         }
3510                         if ( xInfo->hasPropertyByName(PROPERTY_DATAFIELD) )
3511                         {
3512                             OUString sName;
3513                             xUnoProp->getPropertyValue(PROPERTY_DATAFIELD) >>= sName;
3514                             sDefaultName = sName;
3515                             xUnoProp->setPropertyValue(PROPERTY_NAME,uno::makeAny(sDefaultName));
3516 
3517                             ReportFormula aFormula( ReportFormula::Field, sName );
3518                             xUnoProp->setPropertyValue( PROPERTY_DATAFIELD, uno::makeAny( aFormula.getCompleteFormula() ) );
3519                         }
3520 
3521                         if ( xInfo->hasPropertyByName(PROPERTY_BORDER) && xShapeInfo->hasPropertyByName(PROPERTY_CONTROLBORDER) )
3522                             xUnoProp->setPropertyValue(PROPERTY_BORDER,xShapeProp->getPropertyValue(PROPERTY_CONTROLBORDER));
3523 
3524                         pObjs[i]->CreateMediator(true);
3525 
3526                         const sal_Int32 nShapeWidth = xShapeProp->getWidth();
3527                         const bool bChangedPos = (aPos.X + nShapeWidth) > nPaperWidth;
3528                         if ( bChangedPos )
3529                             aPos.X = nPaperWidth - nShapeWidth;
3530                         xShapeProp->setPosition(aPos);
3531                         if ( bChangedPos )
3532                             aPos.Y += xShapeProp->getHeight();
3533                         aPos.X += nShapeWidth;
3534                     }
3535                     OUString sLabel;
3536                     if ( xField->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
3537                         xField->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
3538 
3539                     if (pSectionViews[0] != pSectionViews[1] &&
3540                         nOBJID == OBJ_RD_FORMATTEDFIELD) // we want this nice feature only at FORMATTEDFIELD
3541                     {
3542                         uno::Reference< report::XReportComponent> xShapePropLabel(pObjs[0]->getUnoShape(),uno::UNO_QUERY_THROW);
3543                         uno::Reference< report::XReportComponent> xShapePropTextField(pObjs[1]->getUnoShape(),uno::UNO_QUERY_THROW);
3544                         if ( !sLabel.isEmpty() )
3545                             xShapePropTextField->setName(sLabel);
3546                         awt::Point aPosLabel = xShapePropLabel->getPosition();
3547                         awt::Point aPosTextField = xShapePropTextField->getPosition();
3548                         aPosTextField.X = aPosLabel.X;
3549                         xShapePropTextField->setPosition(aPosTextField);
3550                         if (bLabelAboveTextField)
3551                         {
3552                             // move the label down near the splitter
3553                             const uno::Reference<report::XSection> xLabelSection = pSectionWindow[1]->getReportSection().getSection();
3554                             aPosLabel.Y = xLabelSection->getHeight() - xShapePropLabel->getHeight();
3555                         }
3556                         else
3557                         {
3558                             // move the label up to the splitter
3559                             aPosLabel.Y = 0;
3560                         }
3561                         xShapePropLabel->setPosition(aPosLabel);
3562                     }
3563                     OUnoObject* pObj = dynamic_cast<OUnoObject*>(pControl[0].get());
3564                     assert(pObj);
3565                     uno::Reference< report::XFixedText> xShapeProp(pObj->getUnoShape(),uno::UNO_QUERY_THROW);
3566                     xShapeProp->setName(xShapeProp->getName() + sDefaultName );
3567 
3568                     for(i = 0; i < SAL_N_ELEMENTS(pControl); ++i) // insert controls
3569                     {
3570                         correctOverlapping(pControl[i].get(), pSectionWindow[1-i]->getReportSection());
3571                     }
3572 
3573                     if (!bLabelAboveTextField )
3574                     {
3575                         if ( pSectionViews[0] == pSectionViews[1] )
3576                         {
3577                             tools::Rectangle aLabel = getRectangleFromControl(pControl[0].get());
3578                             tools::Rectangle aTextfield = getRectangleFromControl(pControl[1].get());
3579 
3580                             // create a Union of the given Label and Textfield
3581                             tools::Rectangle aLabelAndTextfield( aLabel );
3582                             aLabelAndTextfield.Union(aTextfield);
3583 
3584                             // check if there exists other fields and if yes, move down
3585                             bool bOverlapping = true;
3586                             bool bHasToMove = false;
3587                             while ( bOverlapping )
3588                             {
3589                                 const SdrObject* pOverlappedObj = isOver(aLabelAndTextfield, *pSectionWindow[0]->getReportSection().getPage(), *pSectionViews[0], true, pControl, 2);
3590                                 bOverlapping = pOverlappedObj != nullptr;
3591                                 if ( bOverlapping )
3592                                 {
3593                                     const tools::Rectangle& aLogicRect = pOverlappedObj->GetLogicRect();
3594                                     aLabelAndTextfield.Move(0,aLogicRect.Top() + aLogicRect.getHeight() - aLabelAndTextfield.Top());
3595                                     bHasToMove = true;
3596                                 }
3597                             }
3598 
3599                             if (bHasToMove)
3600                             {
3601                                 // There was a move down, we need to move the Label and the Textfield down
3602                                 aLabel.Move(0, aLabelAndTextfield.Top() - aLabel.Top());
3603                                 aTextfield.Move(0, aLabelAndTextfield.Top() - aTextfield.Top());
3604 
3605                                 uno::Reference< report::XReportComponent> xLabel(pControl[0]->getUnoShape(),uno::UNO_QUERY_THROW);
3606                                 xLabel->setPositionY(aLabel.Top());
3607 
3608                                 uno::Reference< report::XReportComponent> xTextfield(pControl[1]->getUnoShape(),uno::UNO_QUERY_THROW);
3609                                 xTextfield->setPositionY(aTextfield.Top());
3610                         }
3611                     }
3612                     }
3613                 }
3614                 // not sure where the ownership of these passes too...
3615                 pControl[0].release();
3616                 pControl[1].release();
3617             }
3618         }
3619     }
3620     catch(const Exception&)
3621     {
3622         DBG_UNHANDLED_EXCEPTION("reportdesign");
3623     }
3624 }
3625 
3626 
getCurrentSectionView() const3627 OSectionView* OReportController::getCurrentSectionView() const
3628 {
3629     OSectionView* pSectionView = nullptr;
3630     OSectionWindow* pSectionWindow = getDesignView()->getMarkedSection();
3631     if ( pSectionWindow )
3632         pSectionView = &pSectionWindow->getReportSection().getSectionView();
3633     return pSectionView;
3634 }
3635 
changeZOrder(sal_Int32 _nId)3636 void OReportController::changeZOrder(sal_Int32 _nId)
3637 {
3638     OSectionView* pSectionView = getCurrentSectionView();
3639     if ( !pSectionView )
3640         return;
3641 
3642     switch(_nId)
3643     {
3644         case SID_FRAME_TO_BOTTOM:
3645             pSectionView->PutMarkedToBtm();
3646             break;
3647         case SID_FRAME_TO_TOP:
3648             pSectionView->PutMarkedToTop();
3649             break;
3650         case SID_FRAME_DOWN:
3651             pSectionView->MovMarkedToBtm();
3652             break;
3653         case SID_FRAME_UP:
3654             pSectionView->MovMarkedToTop();
3655             break;
3656 
3657         case SID_OBJECT_HEAVEN:
3658             pSectionView->SetMarkedToLayer( RPT_LAYER_FRONT );
3659             break;
3660         case SID_OBJECT_HELL:
3661             pSectionView->SetMarkedToLayer( RPT_LAYER_BACK );
3662             break;
3663     }
3664 }
3665 
listen(const bool _bAdd)3666 void OReportController::listen(const bool _bAdd)
3667 {
3668     const OUString aProps [] = {    OUString(PROPERTY_REPORTHEADERON),OUString(PROPERTY_REPORTFOOTERON)
3669                                             ,OUString(PROPERTY_PAGEHEADERON),OUString(PROPERTY_PAGEFOOTERON)
3670                                             ,OUString(PROPERTY_COMMAND), OUString(PROPERTY_COMMANDTYPE),OUString(PROPERTY_CAPTION)
3671     };
3672 
3673     void (SAL_CALL XPropertySet::*pPropertyListenerAction)( const OUString&, const uno::Reference< XPropertyChangeListener >& ) =
3674         _bAdd ? &XPropertySet::addPropertyChangeListener : &XPropertySet::removePropertyChangeListener;
3675 
3676     for (const auto & aProp : aProps)
3677         (m_xReportDefinition.get()->*pPropertyListenerAction)( aProp, static_cast< XPropertyChangeListener* >( this ) );
3678 
3679     OXUndoEnvironment& rUndoEnv = m_aReportModel->GetUndoEnv();
3680     uno::Reference< XPropertyChangeListener > xUndo = &rUndoEnv;
3681     const uno::Sequence< beans::Property> aSeq = m_xReportDefinition->getPropertySetInfo()->getProperties();
3682     const OUString* pPropsBegin = &aProps[0];
3683     const OUString* pPropsEnd   = pPropsBegin + SAL_N_ELEMENTS(aProps) - 3;
3684     for(const beans::Property& rProp : aSeq)
3685     {
3686         if ( ::std::find(pPropsBegin,pPropsEnd,rProp.Name) == pPropsEnd )
3687             (m_xReportDefinition.get()->*pPropertyListenerAction)( rProp.Name, xUndo );
3688     }
3689 
3690     // Add Listeners to UndoEnvironment
3691     void (OXUndoEnvironment::*pElementUndoFunction)( const uno::Reference< uno::XInterface >& ) =
3692         _bAdd ? &OXUndoEnvironment::AddElement : &OXUndoEnvironment::RemoveElement;
3693 
3694     (rUndoEnv.*pElementUndoFunction)( m_xReportDefinition->getStyleFamilies() );
3695     (rUndoEnv.*pElementUndoFunction)( m_xReportDefinition->getFunctions() );
3696 
3697     // Add Listeners to ReportControllerObserver
3698     OXReportControllerObserver& rObserver = *m_pReportControllerObserver;
3699 
3700     if ( m_xReportDefinition->getPageHeaderOn() && _bAdd )
3701     {
3702         getDesignView()->addSection(m_xReportDefinition->getPageHeader(),DBPAGEHEADER);
3703         rObserver.AddSection(m_xReportDefinition->getPageHeader());
3704     }
3705     if ( m_xReportDefinition->getReportHeaderOn() && _bAdd )
3706     {
3707         getDesignView()->addSection(m_xReportDefinition->getReportHeader(),DBREPORTHEADER);
3708         rObserver.AddSection(m_xReportDefinition->getReportHeader());
3709     }
3710 
3711     uno::Reference< report::XGroups > xGroups = m_xReportDefinition->getGroups();
3712     const sal_Int32 nCount = xGroups->getCount();
3713     _bAdd ? xGroups->addContainerListener(&rUndoEnv) : xGroups->removeContainerListener(&rUndoEnv);
3714     _bAdd ? xGroups->addContainerListener(&rObserver) : xGroups->removeContainerListener(&rObserver);
3715 
3716     for (sal_Int32 i=0;i<nCount ; ++i)
3717     {
3718         uno::Reference< report::XGroup > xGroup(xGroups->getByIndex(i),uno::UNO_QUERY);
3719         (xGroup.get()->*pPropertyListenerAction)( OUString(PROPERTY_HEADERON), static_cast< XPropertyChangeListener* >( this ) );
3720         (xGroup.get()->*pPropertyListenerAction)( OUString(PROPERTY_FOOTERON), static_cast< XPropertyChangeListener* >( this ) );
3721 
3722         (rUndoEnv.*pElementUndoFunction)( xGroup );
3723         (rUndoEnv.*pElementUndoFunction)( xGroup->getFunctions() );
3724         if ( xGroup->getHeaderOn() && _bAdd )
3725         {
3726             getDesignView()->addSection(xGroup->getHeader(),DBGROUPHEADER);
3727             rObserver.AddSection(xGroup->getHeader());
3728         }
3729     }
3730 
3731     if ( _bAdd )
3732     {
3733         getDesignView()->addSection(m_xReportDefinition->getDetail(),DBDETAIL);
3734         rObserver.AddSection(m_xReportDefinition->getDetail());
3735 
3736         for (sal_Int32 i=nCount;i > 0 ; --i)
3737         {
3738             uno::Reference< report::XGroup > xGroup(xGroups->getByIndex(i-1),uno::UNO_QUERY);
3739             if ( xGroup->getFooterOn() )
3740             {
3741                 getDesignView()->addSection(xGroup->getFooter(),DBGROUPFOOTER);
3742                 rObserver.AddSection(xGroup->getFooter());
3743             }
3744         }
3745         if ( m_xReportDefinition->getReportFooterOn() )
3746         {
3747             getDesignView()->addSection(m_xReportDefinition->getReportFooter(),DBREPORTFOOTER);
3748             rObserver.AddSection(m_xReportDefinition->getReportFooter());
3749         }
3750         if ( m_xReportDefinition->getPageFooterOn())
3751         {
3752             getDesignView()->addSection(m_xReportDefinition->getPageFooter(),DBPAGEFOOTER);
3753             rObserver.AddSection(m_xReportDefinition->getPageFooter());
3754         }
3755 
3756         xGroups->addContainerListener(static_cast<XContainerListener*>(this));
3757         m_xReportDefinition->addModifyListener(static_cast<XModifyListener*>(this));
3758     }
3759     else /* ! _bAdd */
3760     {
3761         rObserver.RemoveSection(m_xReportDefinition->getDetail());
3762         xGroups->removeContainerListener(static_cast<XContainerListener*>(this));
3763         m_xReportDefinition->removeModifyListener(static_cast<XModifyListener*>(this));
3764         m_aReportModel->detachController();
3765     }
3766 }
3767 
switchReportSection(const sal_Int16 _nId)3768 void OReportController::switchReportSection(const sal_Int16 _nId)
3769 {
3770     OSL_ENSURE(_nId == SID_REPORTHEADER_WITHOUT_UNDO || _nId == SID_REPORTFOOTER_WITHOUT_UNDO || _nId == SID_REPORTHEADERFOOTER ,"Illegal id given!");
3771 
3772     if ( !m_xReportDefinition.is() )
3773         return;
3774 
3775     const OXUndoEnvironment::OUndoEnvLock aLock( m_aReportModel->GetUndoEnv() );
3776     const bool bSwitchOn = !m_xReportDefinition->getReportHeaderOn();
3777 
3778     std::unique_ptr< UndoContext > pUndoContext;
3779     if ( SID_REPORTHEADERFOOTER == _nId )
3780     {
3781         const OUString sUndoAction(RptResId(bSwitchOn ? RID_STR_UNDO_ADD_REPORTHEADERFOOTER : RID_STR_UNDO_REMOVE_REPORTHEADERFOOTER));
3782         pUndoContext.reset( new UndoContext( getUndoManager(), sUndoAction ) );
3783 
3784         addUndoAction(std::make_unique<OReportSectionUndo>(*m_aReportModel,SID_REPORTHEADER_WITHOUT_UNDO
3785                                                         ,::std::mem_fn(&OReportHelper::getReportHeader)
3786                                                         ,m_xReportDefinition
3787                                                         ,bSwitchOn ? Inserted : Removed
3788                                                         ));
3789 
3790         addUndoAction(std::make_unique<OReportSectionUndo>(*m_aReportModel,SID_REPORTFOOTER_WITHOUT_UNDO
3791                                                         ,::std::mem_fn(&OReportHelper::getReportFooter)
3792                                                         ,m_xReportDefinition
3793                                                         ,bSwitchOn ? Inserted : Removed
3794                                                         ));
3795     }
3796 
3797     switch( _nId )
3798     {
3799         case SID_REPORTHEADER_WITHOUT_UNDO:
3800             m_xReportDefinition->setReportHeaderOn( bSwitchOn );
3801             break;
3802         case SID_REPORTFOOTER_WITHOUT_UNDO:
3803             m_xReportDefinition->setReportFooterOn( !m_xReportDefinition->getReportFooterOn() );
3804             break;
3805         case SID_REPORTHEADERFOOTER:
3806             m_xReportDefinition->setReportHeaderOn( bSwitchOn );
3807             m_xReportDefinition->setReportFooterOn( bSwitchOn );
3808             break;
3809     }
3810 
3811     if ( SID_REPORTHEADERFOOTER == _nId )
3812         pUndoContext.reset();
3813     getView()->Resize();
3814 }
3815 
switchPageSection(const sal_Int16 _nId)3816 void OReportController::switchPageSection(const sal_Int16 _nId)
3817 {
3818     OSL_ENSURE(_nId == SID_PAGEHEADERFOOTER || _nId == SID_PAGEHEADER_WITHOUT_UNDO || _nId == SID_PAGEFOOTER_WITHOUT_UNDO ,"Illegal id given!");
3819     if ( !m_xReportDefinition.is() )
3820         return;
3821 
3822     const OXUndoEnvironment::OUndoEnvLock aLock( m_aReportModel->GetUndoEnv() );
3823     const bool bSwitchOn = !m_xReportDefinition->getPageHeaderOn();
3824 
3825     std::unique_ptr< UndoContext > pUndoContext;
3826     if ( SID_PAGEHEADERFOOTER == _nId )
3827     {
3828         const OUString sUndoAction(RptResId(bSwitchOn ? RID_STR_UNDO_ADD_REPORTHEADERFOOTER : RID_STR_UNDO_REMOVE_REPORTHEADERFOOTER));
3829         pUndoContext.reset( new UndoContext( getUndoManager(), sUndoAction ) );
3830 
3831         addUndoAction(std::make_unique<OReportSectionUndo>(*m_aReportModel
3832                                                         ,SID_PAGEHEADER_WITHOUT_UNDO
3833                                                         ,::std::mem_fn(&OReportHelper::getPageHeader)
3834                                                         ,m_xReportDefinition
3835                                                         ,bSwitchOn ? Inserted : Removed
3836                                                         ));
3837 
3838         addUndoAction(std::make_unique<OReportSectionUndo>(*m_aReportModel
3839                                                         ,SID_PAGEFOOTER_WITHOUT_UNDO
3840                                                         ,::std::mem_fn(&OReportHelper::getPageFooter)
3841                                                         ,m_xReportDefinition
3842                                                         ,bSwitchOn ? Inserted : Removed
3843                                                         ));
3844     }
3845     switch( _nId )
3846     {
3847         case SID_PAGEHEADER_WITHOUT_UNDO:
3848             m_xReportDefinition->setPageHeaderOn( bSwitchOn );
3849             break;
3850         case SID_PAGEFOOTER_WITHOUT_UNDO:
3851             m_xReportDefinition->setPageFooterOn( !m_xReportDefinition->getPageFooterOn() );
3852             break;
3853         case SID_PAGEHEADERFOOTER:
3854             m_xReportDefinition->setPageHeaderOn( bSwitchOn );
3855             m_xReportDefinition->setPageFooterOn( bSwitchOn );
3856             break;
3857     }
3858     if ( SID_PAGEHEADERFOOTER == _nId )
3859         pUndoContext.reset();
3860     getView()->Resize();
3861 }
3862 
modifyGroup(const bool _bAppend,const Sequence<PropertyValue> & _aArgs)3863 void OReportController::modifyGroup(const bool _bAppend, const Sequence< PropertyValue >& _aArgs)
3864 {
3865     if ( !m_xReportDefinition.is() )
3866         return;
3867 
3868     try
3869     {
3870         const SequenceAsHashMap aMap( _aArgs );
3871         uno::Reference< report::XGroup > xGroup = aMap.getUnpackedValueOrDefault( PROPERTY_GROUP, uno::Reference< report::XGroup >() );
3872         if ( !xGroup.is() )
3873             return;
3874 
3875         OXUndoEnvironment& rUndoEnv = m_aReportModel->GetUndoEnv();
3876         uno::Reference< report::XGroups > xGroups = m_xReportDefinition->getGroups();
3877         if ( _bAppend )
3878         {
3879             const sal_Int32 nPos = aMap.getUnpackedValueOrDefault( PROPERTY_POSITIONY, xGroups->getCount() );
3880             xGroups->insertByIndex( nPos, uno::makeAny( xGroup ) );
3881             rUndoEnv.AddElement( xGroup->getFunctions() );
3882         }
3883 
3884         addUndoAction( std::make_unique<OGroupUndo>(
3885             *m_aReportModel,
3886             _bAppend ? RID_STR_UNDO_APPEND_GROUP : RID_STR_UNDO_REMOVE_GROUP,
3887             _bAppend ? Inserted : Removed,
3888             xGroup,
3889             m_xReportDefinition
3890         ) );
3891 
3892         if ( !_bAppend )
3893         {
3894             rUndoEnv.RemoveElement( xGroup->getFunctions() );
3895             const sal_Int32 nPos = getGroupPosition( xGroup );
3896             const OXUndoEnvironment::OUndoEnvLock aLock( m_aReportModel->GetUndoEnv() );
3897             xGroups->removeByIndex( nPos );
3898         }
3899     }
3900     catch(const Exception&)
3901     {
3902         DBG_UNHANDLED_EXCEPTION("reportdesign");
3903     }
3904 }
3905 
3906 
createGroupSection(const bool _bUndo,const bool _bHeader,const Sequence<PropertyValue> & _aArgs)3907 void OReportController::createGroupSection(const bool _bUndo,const bool _bHeader, const Sequence< PropertyValue >& _aArgs)
3908 {
3909     if ( !m_xReportDefinition.is() )
3910         return;
3911 
3912     const SequenceAsHashMap aMap(_aArgs);
3913     const bool bSwitchOn = aMap.getUnpackedValueOrDefault(_bHeader ? OUString(PROPERTY_HEADERON) : OUString(PROPERTY_FOOTERON), false);
3914     uno::Reference< report::XGroup> xGroup = aMap.getUnpackedValueOrDefault(PROPERTY_GROUP,uno::Reference< report::XGroup>());
3915     if ( !xGroup.is() )
3916         return;
3917 
3918     const OXUndoEnvironment::OUndoEnvLock aLock(m_aReportModel->GetUndoEnv());
3919     if ( _bUndo )
3920         addUndoAction(std::make_unique<OGroupSectionUndo>(*m_aReportModel
3921                                                         ,_bHeader ? SID_GROUPHEADER_WITHOUT_UNDO : SID_GROUPFOOTER_WITHOUT_UNDO
3922                                                         ,_bHeader ? ::std::mem_fn(&OGroupHelper::getHeader) : ::std::mem_fn(&OGroupHelper::getFooter)
3923                                                         ,xGroup
3924                                                         ,bSwitchOn ? Inserted : Removed
3925                                                         , ( _bHeader ?
3926                                                                 (bSwitchOn ? RID_STR_UNDO_ADD_GROUP_HEADER : RID_STR_UNDO_REMOVE_GROUP_HEADER)
3927                                                                :(bSwitchOn ? RID_STR_UNDO_ADD_GROUP_FOOTER : RID_STR_UNDO_REMOVE_GROUP_FOOTER)
3928                                                           )
3929                                                         ));
3930 
3931     if ( _bHeader )
3932         xGroup->setHeaderOn( bSwitchOn );
3933     else
3934         xGroup->setFooterOn( bSwitchOn );
3935 }
3936 
collapseSection(const bool _bCollapse)3937 void OReportController::collapseSection(const bool _bCollapse)
3938 {
3939     OSectionWindow *pSection = getDesignView()->getMarkedSection();
3940     if ( pSection )
3941     {
3942         pSection->setCollapsed(_bCollapse);
3943     }
3944 }
3945 
markSection(const bool _bNext)3946 void OReportController::markSection(const bool _bNext)
3947 {
3948     OSectionWindow *pSection = getDesignView()->getMarkedSection();
3949     if ( pSection )
3950     {
3951         OSectionWindow *pPrevSection = getDesignView()->getMarkedSection(_bNext ? POST : PREVIOUS);
3952         if ( pPrevSection != pSection && pPrevSection )
3953             select(uno::makeAny(pPrevSection->getReportSection().getSection()));
3954         else
3955             select(uno::makeAny(m_xReportDefinition));
3956     }
3957     else
3958     {
3959         getDesignView()->markSection(_bNext ? 0 : getDesignView()->getSectionCount() - 1);
3960         pSection = getDesignView()->getMarkedSection();
3961         if ( pSection )
3962             select(uno::makeAny(pSection->getReportSection().getSection()));
3963     }
3964 }
3965 
createDefaultControl(const uno::Sequence<beans::PropertyValue> & _aArgs)3966 void OReportController::createDefaultControl(const uno::Sequence< beans::PropertyValue>& _aArgs)
3967 {
3968     uno::Reference< report::XSection > xSection = getDesignView()->getCurrentSection();
3969     if ( !xSection.is() )
3970         xSection = m_xReportDefinition->getDetail();
3971 
3972     if ( !xSection.is() )
3973         return;
3974 
3975     const beans::PropertyValue* pIter = _aArgs.getConstArray();
3976     const beans::PropertyValue* pEnd  = pIter + _aArgs.getLength();
3977     const beans::PropertyValue* pKeyModifier = ::std::find_if(pIter, pEnd,
3978         [] (const beans::PropertyValue& x) -> bool {
3979             return x.Name == "KeyModifier";
3980         });
3981     sal_Int16 nKeyModifier = 0;
3982     if ( pKeyModifier == pEnd || ((pKeyModifier->Value >>= nKeyModifier) && nKeyModifier == KEY_MOD1) )
3983     {
3984         Sequence< PropertyValue > aCreateArgs;
3985         getDesignView()->unmarkAllObjects();
3986         createControl(aCreateArgs,xSection,OUString(),getDesignView()->GetInsertObj());
3987     }
3988 }
3989 
3990 
checkChartEnabled()3991 void OReportController::checkChartEnabled()
3992 {
3993     if ( m_bChartEnabledAsked )
3994         return;
3995 
3996     m_bChartEnabledAsked = true;
3997 
3998     try
3999     {
4000         ::utl::OConfigurationTreeRoot aConfiguration(
4001             ::utl::OConfigurationTreeRoot::createWithComponentContext( m_xContext, "/org.openoffice.Office.ReportDesign" ) );
4002 
4003         bool bChartEnabled = false;
4004         static const OUStringLiteral sPropertyName( u"UserData/Chart" );
4005         if ( aConfiguration.hasByHierarchicalName(sPropertyName) )
4006             aConfiguration.getNodeValue( sPropertyName ) >>= bChartEnabled;
4007         m_bChartEnabled = bChartEnabled;
4008     }
4009     catch(const Exception&)
4010     {
4011     }
4012 }
4013 
4014 
4015 // css.frame.XTitle
getTitle()4016 OUString SAL_CALL OReportController::getTitle()
4017 {
4018     SolarMutexGuard aSolarGuard;
4019     ::osl::MutexGuard aGuard( getMutex() );
4020 
4021     uno::Reference< frame::XTitle> xTitle(m_xReportDefinition,uno::UNO_QUERY_THROW);
4022 
4023     return xTitle->getTitle ();
4024 }
4025 
getPropertyDefaultByHandle(sal_Int32,Any & _rDefault) const4026 void OReportController::getPropertyDefaultByHandle( sal_Int32 /*_nHandle*/, Any& _rDefault ) const
4027 {
4028     _rDefault <<= sal_Int16(100);
4029 }
4030 
4031 // comphelper::OPropertyArrayUsageHelper
createArrayHelper() const4032 ::cppu::IPropertyArrayHelper* OReportController::createArrayHelper( ) const
4033 {
4034     Sequence< Property > aProps;
4035     describeProperties(aProps);
4036     return new ::cppu::OPropertyArrayHelper(aProps);
4037 }
4038 
4039 
4040 // cppu::OPropertySetHelper
getInfoHelper()4041 ::cppu::IPropertyArrayHelper& SAL_CALL OReportController::getInfoHelper()
4042 {
4043     return *::comphelper::OPropertyArrayUsageHelper<OReportController_BASE>::getArrayHelper();
4044 }
4045 
setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any & _aValue)4046 void SAL_CALL OReportController::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any& _aValue)
4047 {
4048     if ( _nHandle == PROPERTY_ID_ZOOMVALUE )
4049     {
4050         _aValue >>= m_nZoomValue;
4051         impl_zoom_nothrow();
4052     }
4053 }
setMode(const OUString & aMode)4054 void SAL_CALL OReportController::setMode( const OUString& aMode )
4055 {
4056     ::osl::MutexGuard aGuard( getMutex() );
4057     m_sMode = aMode;
4058 }
getMode()4059 OUString SAL_CALL OReportController::getMode(  )
4060 {
4061     ::osl::MutexGuard aGuard( getMutex() );
4062     return m_sMode;
4063 }
getSupportedModes()4064 css::uno::Sequence< OUString > SAL_CALL OReportController::getSupportedModes(  )
4065 {
4066     return uno::Sequence< OUString> { OUString("remote"), OUString("normal") };
4067 }
supportsMode(const OUString & aMode)4068 sal_Bool SAL_CALL OReportController::supportsMode( const OUString& aMode )
4069 {
4070     uno::Sequence< OUString> aModes = getSupportedModes();
4071     return comphelper::findValue(aModes, aMode) != -1;
4072 }
4073 
isUiVisible() const4074 bool OReportController::isUiVisible() const
4075 {
4076     return m_sMode != "remote";
4077 }
4078 
impl_fillState_nothrow(const OUString & _sProperty,dbaui::FeatureState & _rState) const4079 void OReportController::impl_fillState_nothrow(const OUString& _sProperty,dbaui::FeatureState& _rState) const
4080 {
4081     _rState.bEnabled = isEditable();
4082     if ( !_rState.bEnabled )
4083         return;
4084 
4085     ::std::vector< uno::Reference< uno::XInterface > > aSelection;
4086     getDesignView()->fillControlModelSelection(aSelection);
4087     _rState.bEnabled = !aSelection.empty();
4088     if ( !_rState.bEnabled )
4089         return;
4090 
4091     uno::Any aTemp;
4092     ::std::vector< uno::Reference< uno::XInterface > >::const_iterator aIter = aSelection.begin();
4093     for(; aIter != aSelection.end() && _rState.bEnabled ;++aIter)
4094     {
4095         uno::Reference< beans::XPropertySet> xProp(*aIter,uno::UNO_QUERY);
4096         try
4097         {
4098             uno::Any aTemp2 = xProp->getPropertyValue(_sProperty);
4099             if ( aIter == aSelection.begin() )
4100             {
4101                 aTemp = aTemp2;
4102             }
4103             else if ( aTemp != aTemp2 )
4104                 break;
4105         }
4106         catch(const beans::UnknownPropertyException&)
4107         {
4108             _rState.bEnabled = false;
4109         }
4110     }
4111     if ( aIter == aSelection.end() )
4112         _rState.aValue = aTemp;
4113 }
4114 
impl_zoom_nothrow()4115 void OReportController::impl_zoom_nothrow()
4116 {
4117     Fraction aZoom(m_nZoomValue,100);
4118     setZoomFactor( aZoom, *getDesignView() );
4119     getDesignView()->zoom(aZoom);
4120     InvalidateFeature(SID_ATTR_ZOOM,Reference< XStatusListener >(), true);
4121     InvalidateFeature(SID_ATTR_ZOOMSLIDER,Reference< XStatusListener >(), true);
4122 }
4123 
isFormatCommandEnabled(sal_uInt16 _nCommand,const uno::Reference<report::XReportControlFormat> & _xReportControlFormat)4124 bool OReportController::isFormatCommandEnabled(sal_uInt16 _nCommand,const uno::Reference< report::XReportControlFormat>& _xReportControlFormat)
4125 {
4126     bool bRet = false;
4127     if ( _xReportControlFormat.is() && !uno::Reference< report::XFixedLine>(_xReportControlFormat,uno::UNO_QUERY).is() ) // this command is really often called so we need a short cut here
4128     {
4129         try
4130         {
4131             const awt::FontDescriptor aFontDescriptor = _xReportControlFormat->getFontDescriptor();
4132 
4133             switch(_nCommand)
4134             {
4135                 case SID_ATTR_CHAR_WEIGHT:
4136                     bRet = awt::FontWeight::BOLD == aFontDescriptor.Weight;
4137                     break;
4138                 case SID_ATTR_CHAR_POSTURE:
4139                     bRet = awt::FontSlant_ITALIC == aFontDescriptor.Slant;
4140                     break;
4141                 case SID_ATTR_CHAR_UNDERLINE:
4142                     bRet = awt::FontUnderline::SINGLE == aFontDescriptor.Underline;
4143                     break;
4144                 default:
4145                     ;
4146             }
4147         }
4148         catch(const uno::Exception&)
4149         {
4150         }
4151     }
4152     return bRet;
4153 }
4154 
impl_setPropertyAtControls_throw(const char * pUndoResId,const OUString & _sProperty,const uno::Any & _aValue,const Sequence<PropertyValue> & _aArgs)4155 bool OReportController::impl_setPropertyAtControls_throw(const char* pUndoResId,const OUString& _sProperty,const uno::Any& _aValue,const Sequence< PropertyValue >& _aArgs)
4156 {
4157     ::std::vector< uno::Reference< uno::XInterface > > aSelection;
4158     uno::Reference< awt::XWindow> xWindow;
4159     lcl_getReportControlFormat( _aArgs, getDesignView(), xWindow, aSelection );
4160 
4161     const OUString sUndoAction = RptResId( pUndoResId );
4162     UndoContext aUndoContext( getUndoManager(), sUndoAction );
4163 
4164     for (const auto& rxInterface : aSelection)
4165     {
4166         const uno::Reference< beans::XPropertySet > xControlModel(rxInterface,uno::UNO_QUERY);
4167         if ( xControlModel.is() )
4168             // tdf#117795: some elements may have not some property
4169             // eg class "OFixedLine" doesn't have property "CharFontName"
4170             // so in this case, instead of crashing when selecting all and changing font
4171             // just display a warning
4172             try
4173             {
4174                 xControlModel->setPropertyValue(_sProperty,_aValue);
4175             }
4176             catch(const UnknownPropertyException&)
4177             {
4178                 TOOLS_WARN_EXCEPTION("reportdesign", "");
4179             }
4180     }
4181 
4182     return !aSelection.empty();
4183 }
4184 
impl_fillCustomShapeState_nothrow(const char * _pCustomShapeType,dbaui::FeatureState & _rState) const4185 void OReportController::impl_fillCustomShapeState_nothrow(const char* _pCustomShapeType,dbaui::FeatureState& _rState) const
4186 {
4187     _rState.bEnabled = isEditable();
4188     _rState.bChecked = getDesignView()->GetInsertObj() == OBJ_CUSTOMSHAPE && getDesignView()->GetInsertObjString().equalsAscii(_pCustomShapeType);
4189 }
4190 
4191 
getSectionWindow(const css::uno::Reference<css::report::XSection> & _xSection) const4192 OSectionWindow* OReportController::getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const
4193 {
4194     if ( getDesignView() )
4195     {
4196         return getDesignView()->getSectionWindow(_xSection);
4197     }
4198 
4199     // throw NullPointerException?
4200     return nullptr;
4201 }
4202 
4203 
openZoomDialog()4204 void OReportController::openZoomDialog()
4205 {
4206     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
4207 
4208     static SfxItemInfo aItemInfos[] =
4209     {
4210         { SID_ATTR_ZOOM, true }
4211     };
4212     std::vector<SfxPoolItem*> pDefaults
4213     {
4214         new SvxZoomItem()
4215     };
4216     static const sal_uInt16 pRanges[] =
4217     {
4218         SID_ATTR_ZOOM,SID_ATTR_ZOOM,
4219         0
4220     };
4221     rtl::Reference<SfxItemPool> pPool( new SfxItemPool("ZoomProperties", SID_ATTR_ZOOM,SID_ATTR_ZOOM, aItemInfos, &pDefaults) );
4222     pPool->SetDefaultMetric( MapUnit::Map100thMM );    // ripped, don't understand why
4223     pPool->FreezeIdRanges();                        // the same
4224     try
4225     {
4226         SfxItemSet aDescriptor(*pPool, pRanges);
4227         // fill it
4228         SvxZoomItem aZoomItem( m_eZoomType, m_nZoomValue, SID_ATTR_ZOOM );
4229         aZoomItem.SetValueSet(SvxZoomEnableFlags::N100|SvxZoomEnableFlags::WHOLEPAGE|SvxZoomEnableFlags::PAGEWIDTH);
4230         aDescriptor.Put(aZoomItem);
4231 
4232         ScopedVclPtr<AbstractSvxZoomDialog> pDlg(pFact->CreateSvxZoomDialog(nullptr, aDescriptor));
4233         pDlg->SetLimits( 20, 400 );
4234         bool bCancel = ( RET_CANCEL == pDlg->Execute() );
4235 
4236         if ( !bCancel )
4237         {
4238             const SvxZoomItem&  rZoomItem = pDlg->GetOutputItemSet()->Get( SID_ATTR_ZOOM );
4239             m_eZoomType = rZoomItem.GetType();
4240             m_nZoomValue = rZoomItem.GetValue();
4241             if ( m_eZoomType != SvxZoomType::PERCENT )
4242                 m_nZoomValue = getDesignView()->getZoomFactor( m_eZoomType );
4243 
4244             impl_zoom_nothrow();
4245         }
4246     }
4247     catch(const uno::Exception&)
4248     {
4249         DBG_UNHANDLED_EXCEPTION("reportdesign");
4250     }
4251     pPool.clear();
4252 
4253     for (SfxPoolItem* pDefault : pDefaults)
4254         delete pDefault;
4255 }
4256 
4257 
4258 // XVisualObject
setVisualAreaSize(::sal_Int64 _nAspect,const awt::Size & _aSize)4259 void SAL_CALL OReportController::setVisualAreaSize( ::sal_Int64 _nAspect, const awt::Size& _aSize )
4260 {
4261     ::osl::MutexGuard aGuard( getMutex() );
4262     bool bChanged =
4263             (m_aVisualAreaSize.Width != _aSize.Width ||
4264              m_aVisualAreaSize.Height != _aSize.Height);
4265     m_aVisualAreaSize = _aSize;
4266     if( bChanged )
4267             setModified( true );
4268     m_nAspect = _nAspect;
4269 }
4270 
getVisualAreaSize(::sal_Int64)4271 awt::Size SAL_CALL OReportController::getVisualAreaSize( ::sal_Int64 /*nAspect*/ )
4272 {
4273     ::osl::MutexGuard aGuard( getMutex() );
4274     return m_aVisualAreaSize;
4275 }
4276 
getPreferredVisualRepresentation(::sal_Int64 _nAspect)4277 embed::VisualRepresentation SAL_CALL OReportController::getPreferredVisualRepresentation( ::sal_Int64 _nAspect )
4278 {
4279     SolarMutexGuard aSolarGuard;
4280     ::osl::MutexGuard aGuard( getMutex() );
4281     embed::VisualRepresentation aResult;
4282     if ( !m_bInGeneratePreview )
4283     {
4284         m_bInGeneratePreview = true;
4285         try
4286         {
4287             if ( !m_xReportEngine.is() )
4288                 m_xReportEngine.set( report::ReportEngine::create(m_xContext) );
4289             const sal_Int32 nOldMaxRows = m_xReportEngine->getMaxRows();
4290             m_xReportEngine->setMaxRows(MAX_ROWS_FOR_PREVIEW);
4291             m_xReportEngine->setReportDefinition(m_xReportDefinition);
4292             m_xReportEngine->setActiveConnection(getConnection());
4293             try
4294             {
4295                 Reference<embed::XVisualObject> xTransfer(m_xReportEngine->createDocumentModel(),UNO_QUERY);
4296                 if ( xTransfer.is() )
4297                 {
4298                     xTransfer->setVisualAreaSize(m_nAspect,m_aVisualAreaSize);
4299                     aResult = xTransfer->getPreferredVisualRepresentation( _nAspect );
4300                 }
4301             }
4302             catch(const uno::Exception&)
4303             {
4304             }
4305             m_xReportEngine->setMaxRows(nOldMaxRows);
4306         }
4307         catch(const uno::Exception&)
4308         {
4309         }
4310         m_bInGeneratePreview = false;
4311     }
4312     return aResult;
4313 }
4314 
getMapUnit(::sal_Int64)4315 ::sal_Int32 SAL_CALL OReportController::getMapUnit( ::sal_Int64 /*nAspect*/ )
4316 {
4317     return embed::EmbedMapUnits::ONE_100TH_MM;
4318 }
4319 
getColumns() const4320 uno::Reference< container::XNameAccess > const & OReportController::getColumns() const
4321 {
4322     if ( !m_xColumns.is() && m_xReportDefinition.is() && !m_xReportDefinition->getCommand().isEmpty() )
4323     {
4324         m_xColumns = dbtools::getFieldsByCommandDescriptor(getConnection(),m_xReportDefinition->getCommandType(),m_xReportDefinition->getCommand(),m_xHoldAlive);
4325     }
4326     return m_xColumns;
4327 }
4328 
getColumnLabel_throw(const OUString & i_sColumnName) const4329 OUString OReportController::getColumnLabel_throw(const OUString& i_sColumnName) const
4330 {
4331     OUString sLabel;
4332     uno::Reference< container::XNameAccess > xColumns = getColumns();
4333     if ( xColumns.is() && xColumns->hasByName(i_sColumnName) )
4334     {
4335         uno::Reference< beans::XPropertySet> xColumn(xColumns->getByName(i_sColumnName),uno::UNO_QUERY_THROW);
4336         if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_LABEL) )
4337             xColumn->getPropertyValue(PROPERTY_LABEL) >>= sLabel;
4338     }
4339     return sLabel;
4340 }
4341 
4342 
getUndoManager() const4343 SfxUndoManager& OReportController::getUndoManager() const
4344 {
4345     DBG_TESTSOLARMUTEX();
4346         // this is expected to be called during UI actions, so the SM is assumed to be locked
4347 
4348     std::shared_ptr< OReportModel > pReportModel( getSdrModel() );
4349     ENSURE_OR_THROW( !!pReportModel, "no access to our model" );
4350 
4351     SfxUndoManager* pUndoManager( pReportModel->GetSdrUndoManager() );
4352     ENSURE_OR_THROW( pUndoManager != nullptr, "no access to our model's UndoManager" );
4353 
4354     return *pUndoManager;
4355 }
4356 
4357 
clearUndoManager() const4358 void OReportController::clearUndoManager() const
4359 {
4360     getUndoManager().Clear();
4361 }
4362 
4363 
addUndoAction(std::unique_ptr<SfxUndoAction> i_pAction)4364 void OReportController::addUndoAction( std::unique_ptr<SfxUndoAction> i_pAction )
4365 {
4366     getUndoManager().AddUndoAction( std::move(i_pAction) );
4367 
4368     InvalidateFeature( SID_UNDO );
4369     InvalidateFeature( SID_REDO );
4370 }
4371 
4372 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
reportdesign_OReportController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)4373 reportdesign_OReportController_get_implementation(
4374     css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
4375 {
4376     return cppu::acquire(new OReportController(context));
4377 }
4378 
4379 
4380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
4381