1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/embed/XVisualObject.hpp>
30 #include <com/sun/star/frame/XDesktop2.hpp>
31 #include <com/sun/star/frame/XFrame.hpp>
32 #include <com/sun/star/io/XObjectInputStream.hpp>
33 #include <com/sun/star/io/XObjectOutputStream.hpp>
34 #include <com/sun/star/report/XReportDefinition.hpp>
35 #include <com/sun/star/report/XReportEngine.hpp>
36 #include <com/sun/star/report/XSection.hpp>
37 #include <com/sun/star/sdbc/XConnection.hpp>
38 #include <com/sun/star/sdbc/XRowSet.hpp>
39 #include <com/sun/star/uno/Sequence.hxx>
40 #include <com/sun/star/uno/XComponentContext.hpp>
41 #include <com/sun/star/util/XModeSelector.hpp>
42 #include <com/sun/star/util/XNumberFormatter.hpp>
43 #include <com/sun/star/view/XSelectionSupplier.hpp>
45 #include <comphelper/proparrhlp.hxx>
46 #include <comphelper/propertystatecontainer.hxx>
47 #include <comphelper/uno3.hxx>
48 #include <cppuhelper/implbase5.hxx>
49 #include <comphelper/interfacecontainer2.hxx>
50 #include <dbaccess/dbsubcomponentcontroller.hxx>
51 #include <svl/lstner.hxx>
52 #include <vcl/transfer.hxx>
53 #include <svx/svdedtv.hxx>
54 #include <sfx2/zoomitem.hxx>
59 class TransferableClipboardListener
;
64 class OGroupsSortingDialog
;
67 class OAddFieldWindow
;
70 typedef ::dbaui::DBSubComponentController OReportController_BASE
;
71 typedef ::cppu::ImplHelper5
< css::container::XContainerListener
72 , css::beans::XPropertyChangeListener
73 , css::view::XSelectionSupplier
74 , css::util::XModeSelector
75 , css::embed::XVisualObject
76 > OReportController_Listener
;
78 class OReportController
: public OReportController_BASE
79 ,public OReportController_Listener
81 ,public ::comphelper::OPropertyStateContainer
82 ,public ::comphelper::OPropertyArrayUsageHelper
< OReportController_BASE
>
85 ::comphelper::OInterfaceContainerHelper2
86 m_aSelectionListeners
;
87 css::uno::Sequence
< css::beans::PropertyValue
>
89 TransferableDataHelper m_aSystemClipboard
; // content of the clipboard
90 rtl::Reference
<TransferableClipboardListener
>
91 m_pClipboardNotifier
; /// notifier for changes in the clipboard
92 VclPtr
<OGroupsSortingDialog
> m_pGroupsFloater
;
94 rtl::Reference
<OXReportControllerObserver
> m_pReportControllerObserver
;
96 ODesignView
* getDesignView() const { return static_cast< ODesignView
* >( getView() ); }
98 css::uno::Reference
< css::report::XReportDefinition
> m_xReportDefinition
;
99 css::uno::Reference
< css::report::XReportEngine
> m_xReportEngine
;
100 css::uno::Reference
< css::frame::XDesktop2
> m_xFrameLoader
;
101 css::uno::Reference
< css::sdbc::XRowSet
> m_xRowSet
;
102 css::uno::Reference
< css::beans::XPropertyChangeListener
> m_xRowSetMediator
;
103 css::uno::Reference
< css::util::XNumberFormatter
> m_xFormatter
; // a number formatter working with the report's NumberFormatsSupplier
104 mutable css::uno::Reference
< css::lang::XComponent
> m_xHoldAlive
;
105 mutable css::uno::Reference
< css::container::XNameAccess
> m_xColumns
;
106 css::awt::Size m_aVisualAreaSize
;
108 std::shared_ptr
<rptui::OReportModel
>
110 OUString m_sName
; /// name for the report definition
111 OUString m_sLastActivePage
; /// last active property browser page
112 OUString m_sMode
; /// the current mode of the controller
113 sal_Int32 m_nSplitPos
; /// the position of the splitter
114 sal_Int32 m_nPageNum
; /// the page number from the restoreView call
115 sal_Int32 m_nSelectionCount
;
116 ::sal_Int64 m_nAspect
;
117 sal_Int16 m_nZoomValue
;
118 SvxZoomType m_eZoomType
;
122 bool m_bShowProperties
;
123 bool m_bHelplinesMove
;
124 bool m_bChartEnabled
;
125 bool m_bChartEnabledAsked
;
126 bool m_bInGeneratePreview
;
128 /** creates a formatted field in the given section with the given formula as data field
131 * \param _xSection the section where to create the formatted field
132 * \param _sFunction the function which will be set at the data field.
134 void createControl(const css::uno::Sequence
< css::beans::PropertyValue
>& _aArgs
,const css::uno::Reference
< css::report::XSection
>& _xSection
,const OUString
& _sFunction
,sal_uInt16 _nObjectId
= OBJ_DLG_FORMATTEDFIELD
);
135 /** switch the report header/footer sectionon off with undo or without depending on the given id.
137 * \param _nId Can either be SID_REPORTHEADER_WITHOUT_UNDO or SID_REPORTFOOTER_WITHOUT_UNDO or SID_REPORTHEADERFOOTER.
139 void switchReportSection(const sal_Int16 _nId
);
141 /** switch the report header/footer sectionon off with undo or without depending on the given id.
143 * \param _nId Can either be SID_PAGEHEADER_WITHOUT_UNDO or SID_PAGEFOOTER_WITHOUT_UNDO or SID_PAGEHEADERFOOTER.
145 void switchPageSection(const sal_Int16 _nId
);
147 /** append a new group or remove it with undo.
150 * \param _aArgs The args which contains a element named PROPERTY_GROUP of type report::XGroup.
152 void modifyGroup(const bool _bAppend
, const css::uno::Sequence
< css::beans::PropertyValue
>& _aArgs
);
154 /** creates a group section.
156 * \param _bUndo true when undo action should be created
157 * \param _bHeader true when it is a header otherwise it is a footer
158 * \param _aArgs The args which contains a element named PROPERTY_GROUP of type report::XGroup.
160 void createGroupSection(const bool _bUndo
,const bool _bHeader
,const css::uno::Sequence
< css::beans::PropertyValue
>&_aArgs
);
162 /** add or remove me as listener at the report definition
166 void listen(const bool _bAdd
);
168 /** opens the common page dialog
170 void openPageDialog(const css::uno::Reference
< css::report::XSection
>& _xSection
);
172 /** opens or hides the sorting and grouping dialog
174 void openSortingAndGroupingDialog();
176 /** opens the zoom dialog
178 void openZoomDialog();
180 /** returns the position of the group inside the groups collection
182 sal_Int32
getGroupPosition(const css::uno::Reference
< css::report::XGroup
>& _xGroup
);
184 /** calls propertyChanged when the header or footer is really turned on.
185 @param _rEvent the group
186 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
188 void notifyGroupSections(const css::container::ContainerEvent
& _rEvent
191 /** change the sections for a group
192 @param _sPropName the header or footer
193 @param _xGroup the group
194 @param _nGroupPos the position of the group inside the groups collection or the previous index when it was removed
195 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
197 void groupChange( const css::uno::Reference
< css::report::XGroup
>& _xGroup
198 ,const OUString
& _sPropName
199 ,sal_Int32 _nGroupPos
202 void executeMethodWithUndo(const char* pUndoStrId
,const ::std::function
<void(ODesignView
*)>& _pMemfun
);
203 void alignControlsWithUndo(const char* pUndoStrId
, ControlModification _nControlModification
, bool _bAlignAtSection
= false);
205 css::uno::Reference
< css::frame::XFrame
> getXFrame();
208 @param pUndoStrId the string id of the string which is shown in undo menu
209 @param _nShrinkId ID of what you would like to shrink.
211 static void shrinkSectionBottom(const css::uno::Reference
< css::report::XSection
>& _xSection
);
212 static void shrinkSectionTop(const css::uno::Reference
< css::report::XSection
>& _xSection
);
215 void shrinkSection(const char* pUndoStrId
, const css::uno::Reference
< css::report::XSection
>& _xSection
, sal_Int32 _nShrinkId
);
217 /** opens the file open dialog to allow the user to select a image which will be
218 * bound to a newly created image button.
220 void insertGraphic();
222 /** creates a new function in the given value context
224 * \param _aValue contains a XNameContainer
226 void createNewFunction(const css::uno::Any
& _aValue
);
228 /** inserts a label - field pair into the current selected section
232 void addPairControls(const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
);
234 /** inserts a label - field combination to show the page number and/or page count
238 void createPageNumber(const css::uno::Sequence
< css::beans::PropertyValue
>& _aArgs
);
240 /** creates a formatted field with TODAY() function and if set also an NOW() function
244 void createDateTime(const css::uno::Sequence
< css::beans::PropertyValue
>& _aArgs
);
246 /** gets the current section (SdrView)
248 * \return the currently selected section or <NULL/> if no one is selected
250 OSectionView
* getCurrentSectionView() const;
252 /**change the ZOrder of a current select object.
254 * \param _nId The command ID about what to do.
256 void changeZOrder(sal_Int32 _nId
);
258 /** marks the next or previous section, when the first/last section was already selected then the report will be selected.
262 void markSection(const bool _bNext
);
264 /** collapse or expand the currently selected section.
266 * \param _bCollapse collapse if sal_True otherwise expand
268 void collapseSection(const bool _bCollapse
);
270 /** fills the member that chart is enabled or not
273 void checkChartEnabled();
275 /** set the zoom factor at the design view
277 void impl_zoom_nothrow();
279 virtual void impl_onModifyChanged() override
;
281 virtual void onLoadedMenu( const css::uno::Reference
< css::frame::XLayoutManager
>& _xLayoutManager
) override
;
282 virtual void impl_initialize( ) override
;
283 bool isUiVisible() const;
285 /** creates a new default control for the currently set type when the modifier KEY_MOD1 was pressed
286 * \param _aArgs must contain a properyvalue with name "KeyModifier" and value KEY_MOD1 when control should be created.
288 void createDefaultControl(const css::uno::Sequence
< css::beans::PropertyValue
>& _aArgs
);
290 /** fills the state for the feature request.
291 @param _sProperty the property which should be filled in the value
292 @param _rState the state to fill
294 void impl_fillState_nothrow(const OUString
& _sProperty
,dbaui::FeatureState
& _rState
) const;
295 void impl_fillCustomShapeState_nothrow(const char* _pCustomShapeType
,dbaui::FeatureState
& _rState
) const;
297 /** set the property at all selected controls.
298 @return <TRUE/> when the selection is not empty
300 bool impl_setPropertyAtControls_throw(const char* pUndoResId
301 ,const OUString
& _sProperty
302 ,const css::uno::Any
& _aValue
303 ,const css::uno::Sequence
< css::beans::PropertyValue
>& _aArgs
);
305 void OnInvalidateClipboard();
306 DECL_LINK( OnClipboardChanged
, TransferableDataHelper
*, void );
307 DECL_LINK( OnExecuteReport
, void*, void );
308 // all the features which should be handled by this class
309 virtual void describeSupportedFeatures() override
;
310 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
311 virtual dbaui::FeatureState
GetState(sal_uInt16 nId
) const override
;
313 virtual void Execute(sal_uInt16 nId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
315 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle
, css::uno::Any
& _rDefault
) const override
;
316 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const css::uno::Any
& rValue
) override
;
319 virtual ~OReportController() override
;
322 explicit OReportController(css::uno::Reference
< css::uno::XComponentContext
> const & the_context
);
323 OReportController(const OReportController
&) = delete;
324 OReportController
& operator=(const OReportController
&) = delete;
326 DECL_LINK( EventLstHdl
, VclWindowEvent
&, void );
327 DECL_LINK( OnCreateHdl
, OAddFieldWindow
&, void);
329 DECLARE_XINTERFACE( )
330 DECLARE_XTYPEPROVIDER( )
333 virtual void Notify(SfxBroadcaster
& rBc
, SfxHint
const & rHint
) override
;
335 /** returns <TRUE/> when the command is enabled
336 @param _nCommand the command id
337 @param _xControlFormat the report control format
339 static bool isFormatCommandEnabled(sal_uInt16 _nCommand
340 ,const css::uno::Reference
< css::report::XReportControlFormat
>& _xControlFormat
);
342 virtual bool Construct(vcl::Window
* pParent
) override
;
344 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
346 // css::frame::XController
347 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) override
;
349 // css::lang::XComponent
350 virtual void SAL_CALL
disposing() override
;
353 virtual OUString SAL_CALL
getImplementationName() override
;
354 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
355 // need by registration
356 /// @throws css::uno::RuntimeException
357 static OUString
getImplementationName_Static();
358 /// @throws css::uno::RuntimeException
359 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static();
360 static css::uno::Reference
< css::uno::XInterface
>
361 create(css::uno::Reference
< css::uno::XComponentContext
> const & xContext
);
363 // css::container::XContainerListener
364 virtual void SAL_CALL
elementInserted(const css::container::ContainerEvent
& Event
) override
;
365 virtual void SAL_CALL
elementRemoved(const css::container::ContainerEvent
& Event
) override
;
366 virtual void SAL_CALL
elementReplaced(const css::container::ContainerEvent
& Event
) override
;
368 // XPropertyChangeListener
369 virtual void SAL_CALL
propertyChange( const css::beans::PropertyChangeEvent
& evt
) override
;
371 // XSelectionSupplier
372 virtual sal_Bool SAL_CALL
select( const css::uno::Any
& xSelection
) override
;
373 virtual css::uno::Any SAL_CALL
getSelection( ) override
;
374 virtual void SAL_CALL
addSelectionChangeListener( const css::uno::Reference
< css::view::XSelectionChangeListener
>& xListener
) override
;
375 virtual void SAL_CALL
removeSelectionChangeListener( const css::uno::Reference
< css::view::XSelectionChangeListener
>& xListener
) override
;
377 // css::frame::XController
378 virtual sal_Bool SAL_CALL
attachModel(const css::uno::Reference
< css::frame::XModel
> & xModel
) override
;
379 virtual css::uno::Any SAL_CALL
getViewData() override
;
380 virtual void SAL_CALL
restoreViewData(const css::uno::Any
& Data
) override
;
382 /** gives access to the report definition
383 * \return the report definition object, may be <NULL/>
385 const css::uno::Reference
< css::report::XReportDefinition
>& getReportDefinition() const { return m_xReportDefinition
; }
387 // css::frame::XController
388 virtual css::uno::Reference
< css::frame::XModel
> SAL_CALL
getModel() override
;
391 virtual OUString SAL_CALL
getTitle( ) override
;
394 virtual void SAL_CALL
setMode( const OUString
& aMode
) override
;
395 virtual OUString SAL_CALL
getMode( ) override
;
396 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedModes( ) override
;
397 virtual sal_Bool SAL_CALL
supportsMode( const OUString
& aMode
) override
;
400 virtual void SAL_CALL
setVisualAreaSize( ::sal_Int64 nAspect
, const css::awt::Size
& aSize
) override
;
401 virtual css::awt::Size SAL_CALL
getVisualAreaSize( ::sal_Int64 nAspect
) override
;
402 virtual css::embed::VisualRepresentation SAL_CALL
getPreferredVisualRepresentation( ::sal_Int64 nAspect
) override
;
403 virtual ::sal_Int32 SAL_CALL
getMapUnit( ::sal_Int64 nAspect
) override
;
406 /** returns the current position of the splitter
410 sal_Int32
getSplitPos() const { return m_nSplitPos
;}
411 void setSplitPos(sal_Int32 _nSplitPos
) { m_nSplitPos
= _nSplitPos
;}
413 /** creates a new report from the report definition.
415 * \return The model or <NULL/> if the model could not be created.
417 css::uno::Reference
< css::frame::XModel
> executeReport();
419 /** returns the RowSet which reflects the current settings of the report definition
421 The caller is allowed to hold a reference to the RowSet - it is kept alive as long
422 as the controller lives, and it's settings will follow the report definition's settings.
424 css::uno::Reference
< css::sdbc::XRowSet
> const & getRowSet();
426 /** returns the number formatter
428 const css::uno::Reference
< css::util::XNumberFormatter
>& getReportNumberFormatter() const { return m_xFormatter
;}
430 /** return the SdrModel of the real model
434 const std::shared_ptr
<rptui::OReportModel
>& getSdrModel() const { return m_aReportModel
;}
436 const css::uno::Reference
< css::uno::XComponentContext
>& getContext() const { return m_xContext
; }
437 sal_Int16
getZoomValue() const { return m_nZoomValue
; }
438 void resetZoomType() { m_eZoomType
= SvxZoomType::PERCENT
; }
440 // css::beans::XPropertySet
441 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
443 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
445 // comphelper::OPropertyArrayUsageHelper
446 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const override
;
448 // cppu::OPropertySetHelper
449 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
451 OSectionWindow
* getSectionWindow(const css::uno::Reference
< css::report::XSection
>& _xSection
) const;
453 css::uno::Reference
< css::container::XNameAccess
> const & getColumns() const;
454 OUString
getColumnLabel_throw(const OUString
& i_sColumnName
) const;
456 SfxUndoManager
& getUndoManager() const;
457 void clearUndoManager() const;
458 void addUndoAction( std::unique_ptr
<SfxUndoAction
> i_pAction
);
461 #endif // INCLUDED_REPORTDESIGN_SOURCE_UI_INC_REPORTCONTROLLER_HXX
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */