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