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 
24 #ifndef OPTIMIZERDIALOG_HXX
25 #define OPTIMIZERDIALOG_HXX
26 #ifndef _OPTIMIZERDIALOG_HRC
27 #include "optimizerdialog.hrc"
28 #endif
29 #include <vector>
30 #include "unodialog.hxx"
31 #include "pppoptimizertoken.hxx"
32 #include "optimizationstats.hxx"
33 #include "configurationaccess.hxx"
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/awt/XItemListener.hpp>
36 #include <com/sun/star/awt/XSpinField.hpp>
37 #include <com/sun/star/awt/XSpinListener.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/uno/Sequence.h>
40 #include <com/sun/star/text/XTextRange.hpp>
41 #include <com/sun/star/drawing/XShapes.hpp>
42 #include <com/sun/star/container/XIndexAccess.hpp>
43 #include <com/sun/star/frame/XController.hpp>
44 #include <com/sun/star/view/XSelectionSupplier.hpp>
45 #include <com/sun/star/uno/XComponentContext.hpp>
46 #include <com/sun/star/awt/XItemEventBroadcaster.hpp>
47 #ifndef _COM_SUN_STAR_UTIL_XCloseListener_HPP_
48 #include <com/sun/star/util/XCloseListener.hpp>
49 #endif
50 #include <com/sun/star/frame/XStorable.hpp>
51 #include <com/sun/star/frame/XDispatch.hpp>
52 #include <com/sun/star/frame/XDesktop.hpp>
53 #include <com/sun/star/awt/PushButtonType.hpp>
54 #include <cppuhelper/implbase5.hxx>
55 #include <cppuhelper/implbase1.hxx>
56 
57 #define MAX_STEP		4
58 #define OD_DIALOG_WIDTH	330
59 #define DIALOG_HEIGHT	210
60 #define BUTTON_WIDTH	50
61 #define BUTTON_HEIGHT	14
62 #define BUTTON_POS_Y	DIALOG_HEIGHT - BUTTON_HEIGHT - 6
63 
64 #define PAGE_POS_X		91
65 #define PAGE_POS_Y		8
66 #define PAGE_WIDTH		OD_DIALOG_WIDTH - PAGE_POS_X
67 
68 // -------------------
69 // - OPTIMIZERDIALOG -
70 // -------------------
71 
72 typedef ::cppu::WeakImplHelper5<
73     com::sun::star::frame::XStatusListener,
74     com::sun::star::awt::XSpinListener,
75     com::sun::star::awt::XItemListener,
76     com::sun::star::awt::XActionListener,
77     com::sun::star::awt::XTextListener > OptimizerDialog_Base;
78 
79 class OptimizerDialog : public UnoDialog, public ConfigurationAccess, public OptimizerDialog_Base
80 {
81 public :
82 
83     OptimizerDialog( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
84                      const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& xFrame,
85                      const com::sun::star::uno::Reference< com::sun::star::awt::XWindowPeer >& rxParent );
86     ~OptimizerDialog();
87 
88     virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& aState ) throw (::com::sun::star::uno::RuntimeException);
89     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw (::com::sun::star::uno::RuntimeException);
90 
91     virtual void SAL_CALL up( const ::com::sun::star::awt::SpinEvent& Event ) throw ( com::sun::star::uno::RuntimeException );
92     virtual void SAL_CALL down( const ::com::sun::star::awt::SpinEvent& Event ) throw ( com::sun::star::uno::RuntimeException );
93     virtual void SAL_CALL first( const ::com::sun::star::awt::SpinEvent& Event ) throw ( com::sun::star::uno::RuntimeException );
94     virtual void SAL_CALL last( const ::com::sun::star::awt::SpinEvent& Event ) throw ( com::sun::star::uno::RuntimeException );
95     virtual void SAL_CALL itemStateChanged( const ::com::sun::star::awt::ItemEvent& Event ) throw ( com::sun::star::uno::RuntimeException );
96     virtual void SAL_CALL actionPerformed( const ::com::sun::star::awt::ActionEvent& Event ) throw ( com::sun::star::uno::RuntimeException );
97     virtual void SAL_CALL textChanged( const ::com::sun::star::awt::TextEvent& Event ) throw ( com::sun::star::uno::RuntimeException );
98 
99 	sal_Bool				execute();
100 
101 private :
102     com::sun::star::uno::Reference< com::sun::star::frame::XFrame >         mxFrame;
103     sal_Int16               mnCurrentStep;
104     sal_Int16               mnTabIndex;
105     sal_Bool                mbIsReadonly;
106     com::sun::star::uno::Reference< com::sun::star::frame::XModel >         mxModel;
107 	com::sun::star::uno::Reference< com::sun::star::uno::XInterface >		mxRoadmapControl;
108 	com::sun::star::uno::Reference< com::sun::star::uno::XInterface >		mxRoadmapControlModel;
109 
110 	std::vector< std::vector< rtl::OUString > > maControlPages;
111     OptimizationStats maStats;
112 
113 	void InitDialog();
114 	void InitRoadmap();
115 	void InitNavigationBar();
116 	void InitPage0();
117 	void InitPage1();
118 	void InitPage2();
119 	void InitPage3();
120 	void InitPage4();
121 	void UpdateControlStatesPage0();
122 	void UpdateControlStatesPage1();
123 	void UpdateControlStatesPage2();
124 	void UpdateControlStatesPage3();
125 	void UpdateControlStatesPage4();
126 
127 	void ActivatePage( sal_Int16 nStep );
128 	void DeactivatePage( sal_Int16 nStep );
129     void EnablePage( sal_Int16 nStep );
130     void DisablePage( sal_Int16 nStep );
131     void SwitchPage( sal_Int16 nNewStep );
132 
133     // the ConfigurationAccess is updated to actual control settings
134     void UpdateConfiguration();
135     void UpdateStatus( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& rStatus );
136     void UpdateControlStates( sal_Int16 nStep = -1 );
137 
138     rtl::OUString GetSelectedString( PPPOptimizerTokenEnum eListBox );
139     void ImplSetBold( const rtl::OUString& rControl );
140     void InsertRoadmapItem( const sal_Int32 nIndex,
141                             const sal_Bool bEnabled,
142                             const rtl::OUString& rLabel,
143                             const sal_Int32 nItemID );
144     rtl::OUString ImplInsertSeparator( const rtl::OUString& rControlName,
145                                        sal_Int32 nOrientation,
146                                        sal_Int32 nPosX,
147                                        sal_Int32 nPosY,
148                                        sal_Int32 nWidth,
149                                        sal_Int32 nHeight );
150     rtl::OUString ImplInsertButton( const rtl::OUString& rControlName,
151                                     const rtl::OUString& rHelpURL,
152                                     sal_Int32 nXPos,
153                                     sal_Int32 nYPos,
154                                     sal_Int32 nWidth,
155                                     sal_Int32 nHeight,
156                                     sal_Int16 nTabIndex,
157                                     sal_Bool bEnabled,
158                                     sal_Int32 nResID,
159                                     sal_Int16 nPushButtonType );
160     rtl::OUString ImplInsertFixedText( const rtl::OUString& rControlName,
161                                        const rtl::OUString& rLabel,
162                                        sal_Int32 nXPos,
163                                        sal_Int32 nYPos,
164                                        sal_Int32 nWidth,
165                                        sal_Int32 nHeight,
166                                        sal_Bool bMultiLine,
167                                        sal_Bool bBold,
168                                        sal_Int16 nTabIndex );
169     rtl::OUString ImplInsertCheckBox( const rtl::OUString& rControlName,
170                                       const rtl::OUString& rLabel,
171                                       const rtl::OUString& rHelpURL,
172                                       sal_Int32 nXPos,
173                                       sal_Int32 nYPos,
174                                       sal_Int32 nWidth,
175                                       sal_Int32 nHeight,
176                                       sal_Int16 nTabIndex );
177     rtl::OUString ImplInsertFormattedField( const rtl::OUString& rControlName,
178                                             const rtl::OUString& rHelpURL,
179                                             sal_Int32 nXPos,
180                                             sal_Int32 nYPos,
181                                             sal_Int32 nWidth,
182                                             double fEffectiveMin,
183                                             double fEffectiveMax,
184                                             sal_Int16 nTabIndex );
185     rtl::OUString ImplInsertComboBox( const rtl::OUString& rControlName,
186                                       const rtl::OUString& rHelpURL,
187                                       const sal_Bool bEnabled,
188                                       const com::sun::star::uno::Sequence< rtl::OUString >& rItemList,
189                                       sal_Int32 nXPos,
190                                       sal_Int32 nYPos,
191                                       sal_Int32 nWidth,
192                                       sal_Int32 nHeight,
193                                       sal_Int16 nTabIndex,
194                                       bool bListen = true );
195     rtl::OUString ImplInsertRadioButton( const rtl::OUString& rControlName,
196                                          const rtl::OUString& rLabel,
197                                          const rtl::OUString& rHelpURL,
198                                          sal_Int32 nXPos,
199                                          sal_Int32 nYPos,
200                                          sal_Int32 nWidth,
201                                          sal_Int32 nHeight,
202                                          sal_Bool bMultiLine,
203                                          sal_Int16 nTabIndex );
204     rtl::OUString ImplInsertListBox( const rtl::OUString& rControlName,
205                                      const rtl::OUString& rHelpURL,
206                                      const sal_Bool bEnabled,
207                                      const com::sun::star::uno::Sequence< rtl::OUString >& rItemList,
208                                      sal_Int32 nXPos,
209                                      sal_Int32 nYPos,
210                                      sal_Int32 nWidth,
211                                      sal_Int32 nHeight,
212                                      sal_Int16 nTabIndex );
213 };
214 
215 #endif // OPTIMIZERDIALOG_HXX
216