1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef RPTUI_UITOOLS_HXX
28 #define RPTUI_UITOOLS_HXX
29 
30 #include <com/sun/star/report/XGroup.hpp>
31 #include <com/sun/star/report/XReportControlFormat.hpp>
32 #include <com/sun/star/report/XShape.hpp>
33 #include <com/sun/star/awt/XWindow.hpp>
34 #include <com/sun/star/beans/NamedValue.hpp>
35 #include <com/sun/star/container/XIndexAccess.hpp>
36 #include <com/sun/star/sdbc/XRowSet.hpp>
37 #include "ReportSection.hxx"
38 #include <rtl/ref.hxx>
39 #include <vcl/taskpanelist.hxx>
40 #include <comphelper/stl_types.hxx>
41 #include <functional>
42 
43 class SdrPage;
44 class SdrObject;
45 class SdrUnoObj;
46 class SdrView;
47 class Rectangle;
48 namespace comphelper
49 {
50     class OPropertyChangeMultiplexer;
51     class OPropertyChangeListener;
52 }
53 namespace rptui
54 {
55 	/** returns the position of the object inside the index container
56 		@param	_xReportDefinition	the report definition to get the groups
57 		@param	_xGroup	the group to search
58         @return returns the position of the group in the list, otherwise -1
59 	*/
60 	template<typename T> sal_Int32 getPositionInIndexAccess(
61                                 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& _xCollection
62 								,const ::com::sun::star::uno::Reference< T >& _xSearch)
63     {
64         sal_Int32 nCount = _xCollection->getCount();
65         sal_Int32 i = (nCount == 0) ? -1 : 0;
66 	    for (;i<nCount ; ++i)
67 	    {
68 		    ::com::sun::star::uno::Reference< T > xObject(_xCollection->getByIndex(i),::com::sun::star::uno::UNO_QUERY);
69 		    if ( xObject == _xSearch )
70 			    break;
71 	    } // for (;i<nCount ; ++i)
72 	    return i;
73     }
74 
75 	/** set the name of the header and footer of the group by the expression appended by the localized name of the section
76 		@param	_xGroup	the group where the header/footer name is set by the expression of the group
77 	*/
78 	void adjustSectionName(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup,sal_Int32 _nPos);
79 
80     /** add a listener for the properties size, left margin, right margin to the page style
81     *
82     * \param _xReportDefinition
83     * \param _pListener
84     * \return
85     */
86     ::rtl::Reference< comphelper::OPropertyChangeMultiplexer> addStyleListener( const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReportDefinition
87                                                                 ,::comphelper::OPropertyChangeListener* _pListener);
88 
89     /** opens the common character font dialog
90 	*/
91 	bool    openCharDialog(
92                 const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlFormat>& _xReportControlFormat,
93 			    const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& _xWindow,
94                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _out_rNewValues
95             );
96 
97     /** opens the area dialog for shapes
98     */
99     bool openAreaDialog(
100              const ::com::sun::star::uno::Reference< ::com::sun::star::report::XShape >& _xShape
101             ,const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& _xWindow
102             );
103 
104     /** opens the formula dialog
105         @param _out_rFormula
106                 the formula chosen by the user
107         @precond
108             we're really inspecting a database report (well, a RowSet at least)
109         @return
110             <TRUE/> if and only if the user successfully chose a clause
111     */
112     bool openDialogFormula_nothrow( ::rtl::OUString& _in_out_rFormula
113                                , const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _xContext
114                                , const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>& _xWindow
115                                , const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet >& _xRowSet
116                                );
117 
118     /** applies the character settings previously obtained via openCharDialog
119     */
120     void    applyCharacterSettings(
121                 const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportControlFormat >& _rxReportControlFormat,
122                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rSettings
123             );
124 
125     /** notifySystemWindow adds or remove the given window _pToRegister at the Systemwindow found when search _pWindow.
126 		@param	_pWindow
127 			The window which is used to search for the SystemWindow.
128 		@param	_pToRegister
129 			The window which should be added or removed on the TaskPaneList.
130 		@param	_rMemFunc
131 			The member function which should be called at the SystemWindow when found.
132 			Possible values are:
133 			::comphelper::mem_fun(&TaskPaneList::AddWindow)
134 			::comphelper::mem_fun(&TaskPaneList::RemoveWindow)
135 	*/
136     void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc);
137 
138 
139     const sal_Int16 ISOVER_IGNORE_CUSTOMSHAPES = 1;
140 
141     /** checks whether the given rectangle overlapps another OUnoObject object in that view.
142     *
143     * \param _rRect
144     * \param _rPage
145     * \param _bAllObjects  if <TRUE/> all objects are taken into account, otherwise only not marked ones
146     * \return the object which is overlapped, otherwise <NULL/>
147     */
148     SdrObject* isOver(const Rectangle& _rRect,SdrPage& _rPage,SdrView& _rView,bool _bAllObjects = false,SdrObject* _pIgnore = NULL, sal_Int16 _nIgnoreType=0);
149 
150     SdrObject* isOver(const Rectangle& _rRect,SdrPage& _rPage,SdrView& _rView,bool _bAllObjects, SdrUnoObj* _pIgnoreList[], int _nIgnoreListLength);
151 
152     /** checks whether the given OUnoObject object rectangle overlapps another object in that view.
153     *
154     * \param _pObj
155     * \param _rPage
156     * \param _rView
157     * \param _bAllObjects  if <TRUE/> all objects are taken into account, otherwise only not marked ones
158     * \return the object which is overlapped, otherwise <NULL/>. If the given object is not of type OUnoObject <NULL/> will be returned.
159     */
160     SdrObject* isOver(SdrObject* _pObj,SdrPage& _rPage,SdrView& _rView,bool _bAllObjects = false);
161 
162     /** retrieves the names of the parameters of the command which the given RowSet is bound to
163     */
164     ::com::sun::star::uno::Sequence< ::rtl::OUString >
165         getParameterNames( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet >& _rxRowSet );
166 
167     /** ensures that no control overlaps the given one.
168     *
169     * \param pControl           the control which should place in the section without overlapping
170     * \param _pReportSection    the section
171     * \param _bInsert           sal_True whe the control should be inserted, otherwise not.
172     */
173     void correctOverlapping(SdrObject* pControl,OReportSection& _aReportSection,bool _bInsert = true);
174 
175     /** returns a Rectangle of a given SdrObject
176      *
177      * \param pControl          the SdrObject
178      */
179 
180     Rectangle getRectangleFromControl(SdrObject* pControl);
181 
182     /** sets the map mode at the window
183         @param  _aZoom      the zoom scale
184         @param  _rWindow    where to set the map mode
185     */
186     void setZoomFactor(const Fraction& _aZoom,Window& _rWindow);
187 }
188 #endif //RPTUI_UITOOLS_HXX
189 
190