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 <com/sun/star/embed/XVisualObject.hpp>
53 #include <cppuhelper/implbase5.hxx>
54 #include <svtools/transfer.hxx>
55 #include <svtools/lstner.hxx>
56 #include <svx/svdedtv.hxx>
57 #include <svx/zoomitem.hxx>
58 #include "ModuleHelper.hxx"
60 #include <comphelper/uno3.hxx>
61 #include <comphelper/implementationreference.hxx>
62 #include <comphelper/proparrhlp.hxx>
63 #include <comphelper/propertystatecontainer.hxx>
67 #include <boost/shared_ptr.hpp>
68 #include <com/sun/star/util/XModeSelector.hpp>
69 #include "ReportControllerObserver.hxx"
71 class TransferableHelper
;
72 class TransferableClipboardListener
;
77 class OGroupsSortingDialog
;
78 class OPropertyMediator
;
81 class OAddFieldWindow
;
84 typedef ::dbaui::OSingleDocumentController OReportController_BASE
;
85 typedef ::cppu::ImplHelper5
< ::com::sun::star::container::XContainerListener
86 , ::com::sun::star::beans::XPropertyChangeListener
87 , ::com::sun::star::view::XSelectionSupplier
88 , ::com::sun::star::util::XModeSelector
89 , ::com::sun::star::embed::XVisualObject
90 > OReportController_Listener
;
92 class OReportController
: public OReportController_BASE
93 ,public OReportController_Listener
95 ,public ::comphelper::OPropertyStateContainer
96 ,public ::comphelper::OPropertyArrayUsageHelper
< OReportController_BASE
>
99 OModuleClient m_aModuleClient
;
100 ::cppu::OInterfaceContainerHelper
101 m_aSelectionListeners
;
102 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>
103 m_aCollapsedSections
;
104 ODesignView
* m_pMyOwnView
; // we want to avoid casts
105 TransferableDataHelper m_aSystemClipboard
; // content of the clipboard
106 TransferableClipboardListener
*
107 m_pClipbordNotifier
; /// notifier for changes in the clipboard
108 OGroupsSortingDialog
* m_pGroupsFloater
;
110 OXReportControllerObserver
* m_pReportControllerObserver
;
112 ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportDefinition
> m_xReportDefinition
;
113 ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportEngine
> m_xReportEngine
;
114 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XComponentLoader
> m_xFrameLoader
;
115 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
116 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> m_xRowSet
;
117 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
> m_xRowSetMediator
;
118 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatter
> m_xFormatter
; // a number formatter working with the report's NumberFormatsSupplier
119 ::com::sun::star::awt::Size m_aVisualAreaSize
;
121 ::boost::shared_ptr
<rptui::OReportModel
>
123 ::rtl::OUString m_sName
; /// name for the report definition
124 ::rtl::OUString m_sLastActivePage
; /// last active property browser page
125 ::rtl::OUString m_sMode
; /// the current mode of the controller
126 sal_Int32 m_nSplitPos
; /// the position of the splitter
127 sal_Int32 m_nPageNum
; /// the page number from the restoreView call
128 sal_Int32 m_nSelectionCount
;
129 ::sal_Int64 m_nAspect
;
130 sal_Int16 m_nZoomValue
;
131 SvxZoomType m_eZoomType
;
132 sal_Bool m_bShowRuler
;
133 sal_Bool m_bGridVisible
;
135 sal_Bool m_bShowProperties
;
136 sal_Bool m_bGroupFloaterWasVisible
;
137 sal_Bool m_bHelplinesMove
;
138 bool m_bChartEnabled
;
139 bool m_bChartEnabledAsked
;
140 bool m_bInGeneratePreview
;
142 /** creates a formatted field in the given section with the given formula as data field
145 * \param _xSection the section where to create the formatted field
146 * \param _sFunction the function which will be set at the data field.
148 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
);
149 /** switch the report header/footer sectionon off with undo or without depending on the given id.
151 * \param _nId Can either be SID_REPORTHEADER_WITHOUT_UNDO or SID_REPORTFOOTER_WITHOUT_UNDO or SID_REPORTHEADERFOOTER.
153 void switchReportSection(const sal_Int16 _nId
);
155 /** switch the report header/footer sectionon off with undo or without depending on the given id.
157 * \param _nId Can either be SID_PAGEHEADER_WITHOUT_UNDO or SID_PAGEFOOTER_WITHOUT_UNDO or SID_PAGEHEADERFOOTER.
159 void switchPageSection(const sal_Int16 _nId
);
161 /** append a new group or remove it with undo.
164 * \param _aArgs The args which contains a element named PROPERTY_GROUP of type report::XGroup.
166 void modifyGroup(const bool _bAppend
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
168 /** creates a group section.
170 * \param _bUndo true when undo action should be created
171 * \param _bHeader true when it is a header otherwise it is a footer
172 * \param _aArgs The args which contains a element named PROPERTY_GROUP of type report::XGroup.
174 void createGroupSection(const bool _bUndo
,const bool _bHeader
,const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>&_aArgs
);
176 /** add or remove me as listener at the report definition
180 void listen(const bool _bAdd
);
182 /** opens the common page dialog
184 void openPageDialog(const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
>& _xSection
);
186 /** opens or hides the sorting and grouping dialog
188 void openSortingAndGroupingDialog();
190 /** opens the zoom dialog
192 void openZoomDialog();
194 /** returns the position of the group inside the groups collection
196 sal_Int32
getGroupPosition(const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XGroup
>& _xGroup
);
198 /** calls propertyChanged when the header or footer is really turned on.
199 @param _rEvent the group
200 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
202 void notifyGroupSections(const ::com::sun::star::container::ContainerEvent
& _rEvent
205 /** change the sections for a group
206 @param _sPropName the header or footer
207 @param _xGroup the group
208 @param _nGroupPos the position of the group inside the groups collection or the previous index when it was removed
209 @param _bShow when <TRUE/> the header and footer will be shown otherwise not
211 void groupChange( const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XGroup
>& _xGroup
212 ,const ::rtl::OUString
& _sPropName
213 ,sal_Int32 _nGroupPos
216 void executeMethodWithUndo(USHORT _nUndoStrId
,const ::std::mem_fun_t
<void,ODesignView
>& _pMemfun
);
217 void alignControlsWithUndo(USHORT _nUndoStrId
,sal_Int32 _nControlModification
,bool _bAlignAtSection
= false);
219 @param _nUndoStrId the string id of the string which is shown in undo menu
220 @param _nShrinkId ID of what you would like to shrink.
223 void shrinkSectionBottom(::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
> _xSection
);
224 void shrinkSectionTop(::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
> _xSection
);
227 void shrinkSection(USHORT _nUndoStrId
, ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
> _xSection
, sal_Int32 _nShrinkId
);
229 /** opens the file open dialog to allow the user to select a image which will be
230 * bound to a newly created image button.
232 void insertGraphic();
234 /** resets the floater
236 void updateFloater();
238 /** creates a new function in the given value context
240 * \param _aValue contains a XNameContainer
242 void createNewFunction(const ::com::sun::star::uno::Any
& _aValue
);
244 /** inserts a label - field pair into the current selected section
248 void addPairControls(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
);
250 /** inserts a label - field combination to show the page number and/or page count
254 void createPageNumber(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
256 /** creates a formatted filed with TODAY() function and if set also an NOW() function
260 void createDateTime(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
262 /** gets the current section (SdrView)
264 * \return the currently selected section or <NULL/> if noone is selected
266 OSectionView
* getCurrentSectionView() const;
268 /**change the ZOrder of a current select object.
270 * \param _nId The command ID about what to do.
272 void changeZOrder(sal_Int32 _nId
);
274 /** marks the next or previous section, when the first/last section was already selected then the report will be selected.
278 void markSection(const bool _bNext
);
280 /** collapse or expand the currently selected section.
282 * \param _bCollapse collapse if TRUE otherwise expand
284 void collapseSection(const bool _bCollapse
);
286 /** fills the member that chart is enabled or not
289 void checkChartEnabled();
291 /** set the zoom factor at the design view
293 void impl_zoom_nothrow();
296 OReportController(OReportController
const&);
297 OReportController
& operator =(OReportController
const&);
299 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> getXFrame();
301 // open the help agent of report designer at start time
302 void doOpenHelpAgent();
304 /** creates a new default control for the currently set type when the modifier KEY_MOD1 was pressed
305 * \param _aArgs must contain a properyvalue with name "KeyModifier" and value KEY_MOD1 when control should be created.
307 void createDefaultControl(const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
309 /** fills the state for the feture request.
310 @param _sProperty the property which should be filled in the value
311 @param _rState the state to fill
313 void impl_fillState_nothrow(const ::rtl::OUString
& _sProperty
,dbaui::FeatureState
& _rState
) const;
314 void impl_fillCustomShapeState_nothrow(const char* _pCustomShapeType
,dbaui::FeatureState
& _rState
) const;
316 /** set the property at all selected controls.
317 @return <TRUE/> when the selection is not empty
319 bool impl_setPropertyAtControls_throw(const sal_uInt16 _nUndoResId
320 ,const ::rtl::OUString
& _sProperty
321 ,const ::com::sun::star::uno::Any
& _aValue
322 ,const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& _aArgs
);
324 DECL_LINK( OnInvalidateClipboard
, void* );
325 DECL_LINK( OnClipboardChanged
, void* );
326 DECL_LINK( OnExecuteReport
, void* );
327 DECL_LINK( OnOpenHelpAgent
, void* );
328 short saveModified();
329 // all the features which should be handled by this class
330 virtual void describeSupportedFeatures();
331 // 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.
332 virtual dbaui::FeatureState
GetState(sal_uInt16 nId
) const;
334 virtual void Execute(sal_uInt16 nId
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
);
336 virtual void losingConnection( );
338 virtual void getPropertyDefaultByHandle( sal_Int32 _nHandle
, ::com::sun::star::uno::Any
& _rDefault
) const;
339 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
);
341 virtual ~OReportController();
343 OReportController(::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> const & the_context
);
345 DECL_LINK( NotifyUndoActionHdl
, SfxUndoAction
* );
346 DECL_LINK( EventLstHdl
, VclWindowEvent
* );
347 DECL_LINK( OnCreateHdl
, OAddFieldWindow
*);
349 DECLARE_XINTERFACE( )
350 DECLARE_XTYPEPROVIDER( )
353 virtual void Notify(SfxBroadcaster
& rBc
, SfxHint
const & rHint
);
355 virtual void setModified(sal_Bool _bModified
=sal_True
);
357 // const ::connectivity::OSQLParseNode* getParseTree() const { return m_aSqlIterator.getParseTree();}
358 // need for undo's and redo's
359 SfxUndoManager
* getUndoMgr();
361 /** returns <TRUE/> when the command is enbaled
362 @param _nCommand the command id
363 @param _xControlFormat the report control format
365 sal_Bool
isFormatCommandEnabled(sal_uInt16 _nCommand
366 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportControlFormat
>& _xControlFormat
) const;
368 virtual sal_Bool
Construct(Window
* pParent
);
370 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
);
372 // ::com::sun::star::frame::XController
373 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) throw( ::com::sun::star::uno::RuntimeException
);
375 // ::com::sun::star::lang::XComponent
376 virtual void SAL_CALL
disposing();
379 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw(::com::sun::star::uno::RuntimeException
);
380 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
);
381 // need by registration
382 static ::rtl::OUString
getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException
);
383 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException
);
384 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
385 create(::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> const & xContext
);
387 // ::com::sun::star::container::XContainerListener
388 virtual void SAL_CALL
elementInserted(const ::com::sun::star::container::ContainerEvent
& Event
) throw( ::com::sun::star::uno::RuntimeException
);
389 virtual void SAL_CALL
elementRemoved(const ::com::sun::star::container::ContainerEvent
& Event
) throw( ::com::sun::star::uno::RuntimeException
);
390 virtual void SAL_CALL
elementReplaced(const ::com::sun::star::container::ContainerEvent
& Event
) throw( ::com::sun::star::uno::RuntimeException
);
392 // XPropertyChangeListener
393 virtual void SAL_CALL
propertyChange( const ::com::sun::star::beans::PropertyChangeEvent
& evt
) throw (::com::sun::star::uno::RuntimeException
);
395 // XSelectionSupplier
396 virtual ::sal_Bool SAL_CALL
select( const ::com::sun::star::uno::Any
& xSelection
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
);
397 virtual ::com::sun::star::uno::Any SAL_CALL
getSelection( ) throw (::com::sun::star::uno::RuntimeException
);
398 virtual void SAL_CALL
addSelectionChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionChangeListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
399 virtual void SAL_CALL
removeSelectionChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::view::XSelectionChangeListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
401 // ::com::sun::star::frame::XController
402 virtual sal_Bool SAL_CALL
attachModel(const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> & xModel
) throw( ::com::sun::star::uno::RuntimeException
);
403 virtual ::com::sun::star::uno::Any SAL_CALL
getViewData(void) throw( ::com::sun::star::uno::RuntimeException
);
404 virtual void SAL_CALL
restoreViewData(const ::com::sun::star::uno::Any
& Data
) throw( ::com::sun::star::uno::RuntimeException
);
406 /** gives access to the report definition
407 * \return the report definition object, may be <NULL/>
409 inline ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportDefinition
> getReportDefinition() const { return m_xReportDefinition
; }
411 // ::com::sun::star::frame::XController
412 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> SAL_CALL
getModel(void) throw( ::com::sun::star::uno::RuntimeException
);
415 virtual ::rtl::OUString SAL_CALL
getTitle( ) throw (::com::sun::star::uno::RuntimeException
);
418 virtual void SAL_CALL
setMode( const ::rtl::OUString
& aMode
) throw (::com::sun::star::lang::NoSupportException
, ::com::sun::star::uno::RuntimeException
) ;
419 virtual ::rtl::OUString SAL_CALL
getMode( ) throw (::com::sun::star::uno::RuntimeException
) ;
420 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedModes( ) throw (::com::sun::star::uno::RuntimeException
) ;
421 virtual ::sal_Bool SAL_CALL
supportsMode( const ::rtl::OUString
& aMode
) throw (::com::sun::star::uno::RuntimeException
) ;
424 virtual void SAL_CALL
setVisualAreaSize( ::sal_Int64 nAspect
, const ::com::sun::star::awt::Size
& aSize
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::embed::WrongStateException
, ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
425 virtual ::com::sun::star::awt::Size SAL_CALL
getVisualAreaSize( ::sal_Int64 nAspect
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::embed::WrongStateException
, ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
426 virtual ::com::sun::star::embed::VisualRepresentation SAL_CALL
getPreferredVisualRepresentation( ::sal_Int64 nAspect
) throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::embed::WrongStateException
, ::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
427 virtual ::sal_Int32 SAL_CALL
getMapUnit( ::sal_Int64 nAspect
) throw (::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
430 /** returns the current position of the splitter
434 inline sal_Int32
getSplitPos() const { return m_nSplitPos
;}
435 inline void setSplitPos(sal_Int32 _nSplitPos
) { m_nSplitPos
= _nSplitPos
;}
437 /** creates a new report from the report definition.
439 * \return The model or <NULL/> if the model could not be created.
441 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> executeReport();
443 /** returns the RowSet which reflects the current settings of the report definition
445 The caller is allowed to hold a reference to the RowSet - it is kept alive as long
446 as the controller lives, and it's settings will follow the report definition's settings.
448 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> getRowSet();
450 /** returns the number formatter
452 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XNumberFormatter
> getReportNumberFormatter() const;
454 /** return the SdrModel of the real model
458 ::boost::shared_ptr
<rptui::OReportModel
> getSdrModel();
460 inline ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> getContext() const { return m_xContext
; }
461 inline sal_Int16
getZoomValue() const { return m_nZoomValue
; }
462 inline void resetZoomType() { m_eZoomType
= SVX_ZOOM_PERCENT
; }
464 // com::sun::star::beans::XPropertySet
465 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
467 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
469 // comphelper::OPropertyArrayUsageHelper
470 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
472 // cppu::OPropertySetHelper
473 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
475 ::boost::shared_ptr
<OSectionWindow
> getSectionWindow(const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
>& _xSection
) const;
478 virtual void onLoadedMenu( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XLayoutManager
>& _xLayoutManager
);
479 virtual void impl_initialize( );
480 bool isUiVisible() const;
483 #endif // RPTUI_REPORTCONTROLLER_HXX