1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ReportController.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef RPTUI_REPORTCONTROLLER_HXX
31 #define RPTUI_REPORTCONTROLLER_HXX
33 #include <dbaccess/singledoccontroller.hxx>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/sdbc/XConnection.hpp>
38 #include <com/sun/star/sdbc/XRowSet.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
42 #include <com/sun/star/util/XNumberFormatter.hpp>
43 #include <com/sun/star/io/XObjectOutputStream.hpp>
44 #include <com/sun/star/io/XObjectInputStream.hpp>
45 #include <com/sun/star/frame/XComponentLoader.hpp>
46 #include <com/sun/star/frame/XFrame.hpp>
47 #include <com/sun/star/report/XReportDefinition.hpp>
48 #include <com/sun/star/report/XReportControlModel.hpp>
49 #include <com/sun/star/report/XReportEngine.hpp>
50 #include <com/sun/star/report/XSection.hpp>
51 #include <com/sun/star/view/XSelectionSupplier.hpp>
52 #include <cppuhelper/implbase4.hxx>
53 #include <svtools/transfer.hxx>
54 #include <svtools/lstner.hxx>
55 #include <svx/svdedtv.hxx>
56 #include <svx/zoomitem.hxx>
57 #include "ModuleHelper.hxx"
59 #include <comphelper/uno3.hxx>
60 #include <comphelper/implementationreference.hxx>
61 #include <comphelper/proparrhlp.hxx>
62 #include <comphelper/propertystatecontainer.hxx>
66 #include <boost/shared_ptr.hpp>
67 #include <com/sun/star/util/XModeSelector.hpp>
70 class TransferableHelper
;
71 class TransferableClipboardListener
;
76 class OGroupsSortingDialog
;
77 class OPropertyMediator
;
80 class OAddFieldWindow
;
82 typedef ::dbaui::OSingleDocumentController OReportController_BASE
;
83 typedef ::cppu::ImplHelper4
< ::com::sun::star::container::XContainerListener
84 , ::com::sun::star::beans::XPropertyChangeListener
85 , ::com::sun::star::view::XSelectionSupplier
86 , ::com::sun::star::util::XModeSelector
87 > OReportController_Listener
;
89 class OReportController
: public OReportController_BASE
90 ,public OReportController_Listener
92 ,public ::comphelper::OPropertyStateContainer
93 ,public ::comphelper::OPropertyArrayUsageHelper
< OReportController_BASE
>
96 OModuleClient m_aModuleClient
;
97 ::cppu::OInterfaceContainerHelper
98 m_aSelectionListeners
;
99 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>
100 m_aCollapsedSections
;
101 ODesignView
* m_pMyOwnView
; // we want to avoid casts
102 TransferableDataHelper m_aSystemClipboard
; // content of the clipboard
103 TransferableClipboardListener
*
104 m_pClipbordNotifier
; /// notifier for changes in the clipboard
105 OGroupsSortingDialog
* m_pGroupsFloater
;
106 ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportDefinition
> m_xReportDefinition
;
107 ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportEngine
> m_xReportEngine
;
108 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XComponentLoader
> m_xFrameLoader
;
109 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
110 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> m_xRowSet
;
111 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
> m_xRowSetMediator
;
112 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatter
> m_xFormatter
; // a number formatter working with the report's NumberFormatsSupplier
114 ::boost::shared_ptr
<rptui::OReportModel
>
116 ::rtl::OUString m_sName
; /// name for the report definition
117 ::rtl::OUString m_sLastActivePage
; /// last active property browser page
118 ::rtl::OUString m_sMode
; /// the current mode of the controller
119 sal_Int32 m_nSplitPos
; /// the position of the splitter
120 sal_Int32 m_nPageNum
; /// the page number from the restoreView call
121 sal_Int32 m_nSelectionCount
;
122 sal_Int16 m_nZoomValue
;
123 SvxZoomType m_eZoomType
;
124 sal_Bool m_bShowRuler
;
125 sal_Bool m_bGridVisible
;
127 sal_Bool m_bShowProperties
;
128 sal_Bool m_bGroupFloaterWasVisible
;
129 sal_Bool m_bHelplinesMove
;
130 bool m_bChartEnabled
;
131 bool m_bChartEnabledAsked
;
133 /** creates a formatted field in the given section with the given formula as data field
136 * \param _xSection the section where to create the formatted field
137 * \param _sFunction the function which will be set at the data field.
139 void createControl(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
,const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
>& _xSection
,const ::rtl::OUString
& _sFunction
,sal_uInt16 _nObjectId
= OBJ_DLG_FORMATTEDFIELD
);
140 /** switch the report header/footer sectionon off with undo or without depending on the given id.
142 * \param _nId Can either be SID_REPORTHEADER_WITHOUT_UNDO or SID_REPORTFOOTER_WITHOUT_UNDO or SID_REPORTHEADERFOOTER.
144 void switchReportSection(const sal_Int16 _nId
);
146 /** switch the report header/footer sectionon off with undo or without depending on the given id.
148 * \param _nId Can either be SID_PAGEHEADER_WITHOUT_UNDO or SID_PAGEFOOTER_WITHOUT_UNDO or SID_PAGEHEADERFOOTER.
150 void switchPageSection(const sal_Int16 _nId
);
152 /** append a new group or remove it with undo.
155 * \param _aArgs The args which contains a element named PROPERTY_GROUP of type report::XGroup.
157 void modifyGroup(const bool _bAppend
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
159 /** creates a group section.
161 * \param _bUndo true when undo action should be created
162 * \param _bHeader true when it is a header otherwise it is a footer
163 * \param _aArgs The args which contains a element named PROPERTY_GROUP of type report::XGroup.
165 void createGroupSection(const bool _bUndo
,const bool _bHeader
,const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>&_aArgs
);
167 /** add or remove me as listener at the report definition
171 void listen(const bool _bAdd
);
173 /** opens the common page dialog
175 void openPageDialog(const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
>& _xSection
);
177 /** opens or hides the sorting and grouping dialog
179 void openSortingAndGroupingDialog();
181 /** opens the zoom dialog
183 void openZoomDialog();
185 /** returns the position of the group inside the groups collection
187 sal_Int32
getGroupPosition(const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XGroup
>& _xGroup
);
189 /** calls propertyChanged when the header or footer is really turned on.
190 @param _rEvent the group
191 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
193 void notifyGroupSections(const ::com::sun::star::container::ContainerEvent
& _rEvent
196 /** change the sections for a group
197 @param _sPropName the header or footer
198 @param _xGroup the group
199 @param _nGroupPos the position of the group inside the groups collection or the previous index when it was removed
200 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
202 void groupChange( const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XGroup
>& _xGroup
203 ,const ::rtl::OUString
& _sPropName
204 ,sal_Int32 _nGroupPos
207 void executeMethodWithUndo(USHORT _nUndoStrId
,const ::std::mem_fun_t
<void,ODesignView
>& _pMemfun
);
208 void alignControlsWithUndo(USHORT _nUndoStrId
,sal_Int32 _nControlModification
,bool _bAlignAtSection
= false);
210 /** opens the file open dialog to allow the user to select a image which will be
211 * bound to a newly created image button.
213 void insertGraphic();
215 /** resets the floater
217 void updateFloater();
219 /** creates a new function in the given value context
221 * \param _aValue contains a XNameContainer
223 void createNewFunction(const ::com::sun::star::uno::Any
& _aValue
);
225 /** inserts a label - field pair into the current selected section
229 void addPairControls(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
);
231 /** inserts a label - field combination to show the page number and/or page count
235 void createPageNumber(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
237 /** creates a formatted filed with TODAY() function and if set also an NOW() function
241 void createDateTime(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
243 /** gets the current section (SdrView)
245 * \return the currently selected section or <NULL/> if noone is selected
247 OSectionView
* getCurrentSectionView() const;
249 /**change the ZOrder of a current select object.
251 * \param _nId The command ID about what to do.
253 void changeZOrder(sal_Int32 _nId
);
255 /** marks the next or previous section, when the first/last section was already selected then the report will be selected.
259 void markSection(const bool _bNext
);
261 /** fills the member that chart is enabled or not
264 void checkChartEnabled();
266 /** set the zoom factor at the design view
268 void impl_zoom_nothrow();
270 OReportController(OReportController
const&);
271 OReportController
& operator =(OReportController
const&);
273 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> getXFrame();
275 // open the help agent of report designer at start time
276 void doOpenHelpAgent();
278 /** creates a new default control for the currently set type when the modifier KEY_MOD1 was pressed
279 * \param _aArgs must contain a properyvalue with name "KeyModifier" and value KEY_MOD1 when control should be created.
281 void createDefaultControl(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
283 /** fills the state for the feture request.
284 @param _sProperty the property which should be filled in the value
285 @param _rState the state to fill
287 void impl_fillState_nothrow(const ::rtl::OUString
& _sProperty
,dbaui::FeatureState
& _rState
) const;
288 void impl_fillCustomShapeState_nothrow(const char* _pCustomShapeType
,dbaui::FeatureState
& _rState
) const;
290 /** set the property at all selected controls.
291 @return <TRUE/> when the selection is not empty
293 bool impl_setPropertyAtControls_throw(const sal_uInt16 _nUndoResId
294 ,const ::rtl::OUString
& _sProperty
295 ,const ::com::sun::star::uno::Any
& _aValue
296 ,const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
298 DECL_LINK( OnInvalidateClipboard
, void* );
299 DECL_LINK( OnClipboardChanged
, void* );
300 DECL_LINK( OnExecuteReport
, void* );
301 DECL_LINK( OnOpenHelpAgent
, void* );
302 short saveModified();
303 // all the features which should be handled by this class
304 virtual void describeSupportedFeatures();
305 // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
306 virtual dbaui::FeatureState
GetState(sal_uInt16 nId
) const;
308 virtual void Execute(sal_uInt16 nId
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
);
310 virtual void losingConnection( );
312 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle
, ::com::sun::star::uno::Any
& _rDefault
) const;
313 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
);
315 virtual ~OReportController();
317 OReportController(::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> const & the_context
);
319 DECL_LINK( NotifyUndoActionHdl
, SfxUndoAction
* );
320 DECL_LINK( EventLstHdl
, VclWindowEvent
* );
321 DECL_LINK( OnCreateHdl
, OAddFieldWindow
*);
323 DECLARE_XINTERFACE( )
324 DECLARE_XTYPEPROVIDER( )
327 virtual void Notify(SfxBroadcaster
& rBc
, SfxHint
const & rHint
);
329 virtual void setModified(sal_Bool _bModified
=sal_True
);
331 // const ::connectivity::OSQLParseNode* getParseTree() const { return m_aSqlIterator.getParseTree();}
332 // need for undo's and redo's
333 SfxUndoManager
* getUndoMgr();
335 /** returns <TRUE/> when the command is enbaled
336 @param _nCommand the command id
337 @param _xControlFormat the report control format
339 sal_Bool
isFormatCommandEnabled(sal_uInt16 _nCommand
340 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportControlFormat
>& _xControlFormat
) const;
342 virtual sal_Bool
Construct(Window
* pParent
);
344 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
346 // ::com::sun::star::frame::XController
347 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) throw( ::com::sun::star::uno::RuntimeException
);
349 // ::com::sun::star::lang::XComponent
350 virtual void SAL_CALL
disposing();
353 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw(::com::sun::star::uno::RuntimeException
);
354 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
);
355 // need by registration
356 static ::rtl::OUString
getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException
);
357 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException
);
358 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
359 create(::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> const & xContext
);
361 // ::com::sun::star::container::XContainerListener
362 virtual void SAL_CALL
elementInserted(const ::com::sun::star::container::ContainerEvent
& Event
) throw( ::com::sun::star::uno::RuntimeException
);
363 virtual void SAL_CALL
elementRemoved(const ::com::sun::star::container::ContainerEvent
& Event
) throw( ::com::sun::star::uno::RuntimeException
);
364 virtual void SAL_CALL
elementReplaced(const ::com::sun::star::container::ContainerEvent
& Event
) throw( ::com::sun::star::uno::RuntimeException
);
366 // XPropertyChangeListener
367 virtual void SAL_CALL
propertyChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw (::com::sun::star::uno::RuntimeException
);
369 // XSelectionSupplier
370 virtual ::sal_Bool SAL_CALL
select( const ::com::sun::star::uno::Any
& xSelection
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
371 virtual ::com::sun::star::uno::Any SAL_CALL
getSelection( ) throw (::com::sun::star::uno::RuntimeException
);
372 virtual void SAL_CALL
addSelectionChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionChangeListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
373 virtual void SAL_CALL
removeSelectionChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionChangeListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
375 // ::com::sun::star::frame::XController
376 virtual sal_Bool SAL_CALL
attachModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> & xModel
) throw( ::com::sun::star::uno::RuntimeException
);
377 virtual ::com::sun::star::uno::Any SAL_CALL
getViewData(void) throw( ::com::sun::star::uno::RuntimeException
);
378 virtual void SAL_CALL
restoreViewData(const ::com::sun::star::uno::Any
& Data
) throw( ::com::sun::star::uno::RuntimeException
);
380 /** gives access to the report definition
381 * \return the report definition object, may be <NULL/>
383 inline ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportDefinition
> getReportDefinition() const { return m_xReportDefinition
; }
385 // ::com::sun::star::frame::XController
386 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> SAL_CALL
getModel(void) throw( ::com::sun::star::uno::RuntimeException
);
389 virtual ::rtl::OUString SAL_CALL
getTitle( ) throw (::com::sun::star::uno::RuntimeException
);
392 virtual void SAL_CALL
setMode( const ::rtl::OUString
& aMode
) throw (::com::sun::star::lang::NoSupportException
, ::com::sun::star::uno::RuntimeException
) ;
393 virtual ::rtl::OUString SAL_CALL
getMode( ) throw (::com::sun::star::uno::RuntimeException
) ;
394 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedModes( ) throw (::com::sun::star::uno::RuntimeException
) ;
395 virtual ::sal_Bool SAL_CALL
supportsMode( const ::rtl::OUString
& aMode
) throw (::com::sun::star::uno::RuntimeException
) ;
398 /** returns the current position of the splitter
402 inline sal_Int32
getSplitPos() const { return m_nSplitPos
;}
403 inline void setSplitPos(sal_Int32 _nSplitPos
) { m_nSplitPos
= _nSplitPos
;}
405 /** creates a new report from the report definition.
407 * \return The model or <NULL/> if the model could not be created.
409 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> executeReport();
411 /** returns the RowSet which reflects the current settings of the report definition
413 The caller is allowed to hold a reference to the RowSet - it is kept alive as long
414 as the controller lives, and it's settings will follow the report definition's settings.
416 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> getRowSet();
418 /** returns the number formatter
420 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatter
> getReportNumberFormatter() const;
422 /** return the SdrModel of the real model
426 ::boost::shared_ptr
<rptui::OReportModel
> getSdrModel();
428 inline ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> getContext() const { return m_xContext
; }
429 inline sal_Int16
getZoomValue() const { return m_nZoomValue
; }
430 inline void resetZoomType() { m_eZoomType
= SVX_ZOOM_PERCENT
; }
432 // com::sun::star::beans::XPropertySet
433 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
435 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
437 // comphelper::OPropertyArrayUsageHelper
438 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
440 // cppu::OPropertySetHelper
441 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
444 virtual void onLoadedMenu( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XLayoutManager
>& _xLayoutManager
);
445 virtual void impl_initialize( );
446 bool isUiVisible() const;
449 #endif // RPTUI_REPORTCONTROLLER_HXX