Use o3tl::convert in Math
[LibreOffice.git] / reportdesign / source / ui / inc / ReportController.hxx
blob92ab4f3fe7123d5c2daf5a8cde6c25002737eb78
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_REPORTDESIGN_SOURCE_UI_INC_REPORTCONTROLLER_HXX
20 #define INCLUDED_REPORTDESIGN_SOURCE_UI_INC_REPORTCONTROLLER_HXX
22 #include "DesignView.hxx"
23 #include "ReportControllerObserver.hxx"
24 #include <RptDef.hxx>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
28 #include <com/sun/star/embed/XVisualObject.hpp>
29 #include <com/sun/star/frame/XDesktop2.hpp>
30 #include <com/sun/star/frame/XFrame.hpp>
31 #include <com/sun/star/report/XReportDefinition.hpp>
32 #include <com/sun/star/report/XReportEngine.hpp>
33 #include <com/sun/star/report/XSection.hpp>
34 #include <com/sun/star/sdbc/XRowSet.hpp>
35 #include <com/sun/star/uno/Sequence.hxx>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <com/sun/star/util/XModeSelector.hpp>
38 #include <com/sun/star/util/XNumberFormatter.hpp>
39 #include <com/sun/star/view/XSelectionSupplier.hpp>
41 #include <comphelper/proparrhlp.hxx>
42 #include <comphelper/propertystatecontainer.hxx>
43 #include <comphelper/uno3.hxx>
44 #include <cppuhelper/implbase5.hxx>
45 #include <comphelper/interfacecontainer2.hxx>
46 #include <dbaccess/dbsubcomponentcontroller.hxx>
47 #include <svl/lstner.hxx>
48 #include <vcl/transfer.hxx>
49 #include <sfx2/zoomitem.hxx>
51 #include <functional>
52 #include <memory>
54 class TransferableClipboardListener;
55 class VclWindowEvent;
56 class SfxUndoManager;
57 namespace rptui
59 class OGroupsSortingDialog;
60 class OReportModel;
61 class OSectionView;
62 class OAddFieldWindow;
63 class OSectionWindow;
65 typedef ::dbaui::DBSubComponentController OReportController_BASE;
66 typedef ::cppu::ImplHelper5 < css::container::XContainerListener
67 , css::beans::XPropertyChangeListener
68 , css::view::XSelectionSupplier
69 , css::util::XModeSelector
70 , css::embed::XVisualObject
71 > OReportController_Listener;
73 class OReportController : public OReportController_BASE
74 ,public OReportController_Listener
75 ,public SfxListener
76 ,public ::comphelper::OPropertyStateContainer
77 ,public ::comphelper::OPropertyArrayUsageHelper < OReportController_BASE >
79 private:
80 ::comphelper::OInterfaceContainerHelper2
81 m_aSelectionListeners;
82 css::uno::Sequence< css::beans::PropertyValue>
83 m_aCollapsedSections;
84 TransferableDataHelper m_aSystemClipboard; // content of the clipboard
85 rtl::Reference<TransferableClipboardListener>
86 m_pClipboardNotifier; /// notifier for changes in the clipboard
87 std::shared_ptr<OGroupsSortingDialog> m_xGroupsFloater;
89 rtl::Reference<OXReportControllerObserver> m_pReportControllerObserver;
91 ODesignView* getDesignView() const { return static_cast< ODesignView* >( getView() ); }
93 css::uno::Reference< css::report::XReportDefinition > m_xReportDefinition;
94 css::uno::Reference< css::report::XReportEngine > m_xReportEngine;
95 css::uno::Reference< css::frame::XDesktop2 > m_xFrameLoader;
96 css::uno::Reference< css::sdbc::XRowSet > m_xRowSet;
97 css::uno::Reference< css::beans::XPropertyChangeListener > m_xRowSetMediator;
98 css::uno::Reference< css::util::XNumberFormatter > m_xFormatter; // a number formatter working with the report's NumberFormatsSupplier
99 mutable css::uno::Reference< css::lang::XComponent > m_xHoldAlive;
100 mutable css::uno::Reference< css::container::XNameAccess > m_xColumns;
101 css::awt::Size m_aVisualAreaSize;
103 std::shared_ptr<rptui::OReportModel>
104 m_aReportModel;
105 OUString m_sName; /// name for the report definition
106 OUString m_sLastActivePage; /// last active property browser page
107 OUString m_sMode; /// the current mode of the controller
108 sal_Int32 m_nSplitPos; /// the position of the splitter
109 sal_Int32 m_nPageNum; /// the page number from the restoreView call
110 sal_Int32 m_nSelectionCount;
111 ::sal_Int64 m_nAspect;
112 sal_Int16 m_nZoomValue;
113 SvxZoomType m_eZoomType;
114 bool m_bShowRuler;
115 bool m_bGridVisible;
116 bool m_bGridUse;
117 bool m_bShowProperties;
118 bool m_bHelplinesMove;
119 bool m_bChartEnabled;
120 bool m_bChartEnabledAsked;
121 bool m_bInGeneratePreview;
123 /** creates a formatted field in the given section with the given formula as data field
125 * \param _aArgs
126 * \param _xSection the section where to create the formatted field
127 * \param _sFunction the function which will be set at the data field.
129 void createControl(const css::uno::Sequence< css::beans::PropertyValue >& _aArgs,const css::uno::Reference< css::report::XSection>& _xSection,const OUString& _sFunction ,SdrObjKind _nObjectId = OBJ_RD_FORMATTEDFIELD);
130 /** switch the report header/footer sectionon off with undo or without depending on the given id.
132 * \param _nId Can either be SID_REPORTHEADER_WITHOUT_UNDO or SID_REPORTFOOTER_WITHOUT_UNDO or SID_REPORTHEADERFOOTER.
134 void switchReportSection(const sal_Int16 _nId);
136 /** switch the report header/footer sectionon off with undo or without depending on the given id.
138 * \param _nId Can either be SID_PAGEHEADER_WITHOUT_UNDO or SID_PAGEFOOTER_WITHOUT_UNDO or SID_PAGEHEADERFOOTER.
140 void switchPageSection(const sal_Int16 _nId);
142 /** append a new group or remove it with undo.
144 * \param _bAppend
145 * \param _aArgs The args which contains an element named PROPERTY_GROUP of type report::XGroup.
147 void modifyGroup(const bool _bAppend, const css::uno::Sequence< css::beans::PropertyValue >& _aArgs);
149 /** creates a group section.
151 * \param _bUndo true when undo action should be created
152 * \param _bHeader true when it is a header otherwise it is a footer
153 * \param _aArgs The args which contains an element named PROPERTY_GROUP of type report::XGroup.
155 void createGroupSection(const bool _bUndo,const bool _bHeader,const css::uno::Sequence< css::beans::PropertyValue >&_aArgs);
157 /** add or remove me as listener at the report definition
159 * \param _bAdd
161 void listen(const bool _bAdd);
163 /** opens the common page dialog
165 void openPageDialog(const css::uno::Reference< css::report::XSection>& _xSection);
167 /** opens or hides the sorting and grouping dialog
169 void openSortingAndGroupingDialog();
171 /** opens the zoom dialog
173 void openZoomDialog();
175 /** returns the position of the group inside the groups collection
177 sal_Int32 getGroupPosition(const css::uno::Reference< css::report::XGroup >& _xGroup);
179 /** calls propertyChanged when the header or footer is really turned on.
180 @param _rEvent the group
181 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
183 void notifyGroupSections(const css::container::ContainerEvent& _rEvent
184 ,bool _bShow);
186 /** change the sections for a group
187 @param _sPropName the header or footer
188 @param _xGroup the group
189 @param _nGroupPos the position of the group inside the groups collection or the previous index when it was removed
190 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
192 void groupChange( const css::uno::Reference< css::report::XGroup>& _xGroup
193 ,std::u16string_view _sPropName
194 ,sal_Int32 _nGroupPos
195 ,bool _bShow);
197 void executeMethodWithUndo(TranslateId pUndoStrId,const ::std::function<void(ODesignView *)>& _pMemfun);
198 void alignControlsWithUndo(TranslateId pUndoStrId, ControlModification _nControlModification, bool _bAlignAtSection = false);
200 css::uno::Reference< css::frame::XFrame > getXFrame();
202 /** shrink a section
203 @param pUndoStrId the string id of the string which is shown in undo menu
204 @param _nShrinkId ID of what you would like to shrink.
206 static void shrinkSectionBottom(const css::uno::Reference< css::report::XSection >& _xSection);
207 static void shrinkSectionTop(const css::uno::Reference< css::report::XSection >& _xSection);
209 public:
210 void shrinkSection(TranslateId pUndoStrId, const css::uno::Reference< css::report::XSection >& _xSection, sal_Int32 _nShrinkId);
212 /** opens the file open dialog to allow the user to select an image which will be
213 * bound to a newly created image button.
215 void insertGraphic();
217 /** creates a new function in the given value context
219 * \param _aValue contains a XNameContainer
221 void createNewFunction(const css::uno::Any& _aValue);
223 /** inserts a label - field pair into the current selected section
225 * \param aArgs
227 void addPairControls(const css::uno::Sequence< css::beans::PropertyValue >& aArgs);
229 /** inserts a label - field combination to show the page number and/or page count
231 * \param _aArgs
233 void createPageNumber(const css::uno::Sequence< css::beans::PropertyValue >& _aArgs);
235 /** creates a formatted field with TODAY() function and if set also a NOW() function
237 * \param _aArgs
239 void createDateTime(const css::uno::Sequence< css::beans::PropertyValue >& _aArgs);
241 /** gets the current section (SdrView)
243 * \return the currently selected section or <NULL/> if no one is selected
245 OSectionView* getCurrentSectionView() const;
247 /**change the ZOrder of a current select object.
249 * \param _nId The command ID about what to do.
251 void changeZOrder(sal_Int32 _nId);
253 /** marks the next or previous section, when the first/last section was already selected then the report will be selected.
255 * \param _bNext
257 void markSection(const bool _bNext);
259 /** collapse or expand the currently selected section.
261 * \param _bCollapse collapse if sal_True otherwise expand
263 void collapseSection(const bool _bCollapse);
265 /** fills the member that chart is enabled or not
268 void checkChartEnabled();
270 /** set the zoom factor at the design view
272 void impl_zoom_nothrow();
274 virtual void impl_onModifyChanged() override;
276 virtual void onLoadedMenu( const css::uno::Reference< css::frame::XLayoutManager >& _xLayoutManager ) override;
277 virtual void impl_initialize( ) override;
278 bool isUiVisible() const;
280 /** creates a new default control for the currently set type when the modifier KEY_MOD1 was pressed
281 * \param _aArgs must contain a propertyvalue with name "KeyModifier" and value KEY_MOD1 when control should be created.
283 void createDefaultControl(const css::uno::Sequence< css::beans::PropertyValue>& _aArgs);
285 /** fills the state for the feature request.
286 @param _sProperty the property which should be filled in the value
287 @param _rState the state to fill
289 void impl_fillState_nothrow(const OUString& _sProperty,dbaui::FeatureState& _rState) const;
290 void impl_fillCustomShapeState_nothrow(const char* _pCustomShapeType,dbaui::FeatureState& _rState) const;
292 /** set the property at all selected controls.
293 @return <TRUE/> when the selection is not empty
295 bool impl_setPropertyAtControls_throw(TranslateId pUndoResId
296 ,const OUString& _sProperty
297 ,const css::uno::Any& _aValue
298 ,const css::uno::Sequence< css::beans::PropertyValue >& _aArgs);
300 void OnInvalidateClipboard();
301 DECL_LINK( OnClipboardChanged, TransferableDataHelper*, void );
302 DECL_LINK( OnExecuteReport, void*, void );
303 // all the features which should be handled by this class
304 virtual void describeSupportedFeatures() override;
305 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
306 virtual dbaui::FeatureState GetState(sal_uInt16 nId) const override;
307 // execute a feature
308 virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override;
310 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle, css::uno::Any& _rDefault ) const override;
311 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const css::uno::Any& rValue) override;
313 private:
314 virtual ~OReportController() override;
316 public:
317 explicit OReportController(css::uno::Reference< css::uno::XComponentContext > const & the_context);
318 OReportController(const OReportController&) = delete;
319 OReportController& operator=(const OReportController&) = delete;
321 DECL_LINK( OnCreateHdl, OAddFieldWindow&, void);
323 DECLARE_XINTERFACE( )
324 DECLARE_XTYPEPROVIDER( )
326 // SfxListener
327 virtual void Notify(SfxBroadcaster & rBc, SfxHint const & rHint) override;
329 /** returns <TRUE/> when the command is enabled
330 @param _nCommand the command id
331 @param _xControlFormat the report control format
333 static bool isFormatCommandEnabled(sal_uInt16 _nCommand
334 ,const css::uno::Reference< css::report::XReportControlFormat>& _xControlFormat);
336 virtual bool Construct(vcl::Window* pParent) override;
337 // XEventListener
338 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
340 // css::frame::XController
341 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override;
343 // css::lang::XComponent
344 virtual void SAL_CALL disposing() override;
346 // XServiceInfo
347 virtual OUString SAL_CALL getImplementationName() override;
348 virtual css::uno::Sequence< OUString> SAL_CALL getSupportedServiceNames() override;
350 // css::container::XContainerListener
351 virtual void SAL_CALL elementInserted(const css::container::ContainerEvent& Event) override;
352 virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent& Event) override;
353 virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent& Event) override;
355 // XPropertyChangeListener
356 virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
358 // XSelectionSupplier
359 virtual sal_Bool SAL_CALL select( const css::uno::Any& xSelection ) override;
360 virtual css::uno::Any SAL_CALL getSelection( ) override;
361 virtual void SAL_CALL addSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) override;
362 virtual void SAL_CALL removeSelectionChangeListener( const css::uno::Reference< css::view::XSelectionChangeListener >& xListener ) override;
364 // css::frame::XController
365 virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > & xModel) override;
366 virtual css::uno::Any SAL_CALL getViewData() override;
367 virtual void SAL_CALL restoreViewData(const css::uno::Any& Data) override;
369 /** gives access to the report definition
370 * \return the report definition object, may be <NULL/>
372 const css::uno::Reference< css::report::XReportDefinition>& getReportDefinition() const { return m_xReportDefinition; }
374 // css::frame::XController
375 virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel() override;
377 // XTitle
378 virtual OUString SAL_CALL getTitle( ) override;
380 // XModeSelector
381 virtual void SAL_CALL setMode( const OUString& aMode ) override ;
382 virtual OUString SAL_CALL getMode( ) override ;
383 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedModes( ) override ;
384 virtual sal_Bool SAL_CALL supportsMode( const OUString& aMode ) override ;
386 // XVisualObject
387 virtual void SAL_CALL setVisualAreaSize( ::sal_Int64 nAspect, const css::awt::Size& aSize ) override;
388 virtual css::awt::Size SAL_CALL getVisualAreaSize( ::sal_Int64 nAspect ) override;
389 virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation( ::sal_Int64 nAspect ) override;
390 virtual ::sal_Int32 SAL_CALL getMapUnit( ::sal_Int64 nAspect ) override;
393 /** returns the current position of the splitter
395 * \return
397 sal_Int32 getSplitPos() const { return m_nSplitPos;}
398 void setSplitPos(sal_Int32 _nSplitPos) { m_nSplitPos = _nSplitPos;}
400 /** creates a new report from the report definition.
402 * \return The model or <NULL/> if the model could not be created.
404 css::uno::Reference< css::frame::XModel> executeReport();
406 /** returns the RowSet which reflects the current settings of the report definition
408 The caller is allowed to hold a reference to the RowSet - it is kept alive as long
409 as the controller lives, and it's settings will follow the report definition's settings.
411 css::uno::Reference< css::sdbc::XRowSet > const & getRowSet();
413 /** returns the number formatter
415 const css::uno::Reference< css::util::XNumberFormatter >& getReportNumberFormatter() const { return m_xFormatter;}
417 /** return the SdrModel of the real model
419 * \return
421 const std::shared_ptr<rptui::OReportModel>& getSdrModel() const { return m_aReportModel;}
423 const css::uno::Reference< css::uno::XComponentContext >& getContext() const { return m_xContext; }
424 sal_Int16 getZoomValue() const { return m_nZoomValue; }
425 void resetZoomType() { m_eZoomType = SvxZoomType::PERCENT; }
427 // css::beans::XPropertySet
428 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override
430 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
432 // comphelper::OPropertyArrayUsageHelper
433 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
435 // cppu::OPropertySetHelper
436 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
438 OSectionWindow* getSectionWindow(const css::uno::Reference< css::report::XSection>& _xSection) const;
440 css::uno::Reference< css::container::XNameAccess > const & getColumns() const;
441 OUString getColumnLabel_throw(const OUString& i_sColumnName) const;
443 SfxUndoManager& getUndoManager() const;
444 void clearUndoManager() const;
445 void addUndoAction( std::unique_ptr<SfxUndoAction> i_pAction );
448 #endif // INCLUDED_REPORTDESIGN_SOURCE_UI_INC_REPORTCONTROLLER_HXX
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */