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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26 
27 #include "pppoptimizerdialog.hxx"
28 #include "optimizerdialog.hxx"
29 
30 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
31 #include <rtl/strbuf.hxx>
32 #include <rtl/ref.hxx>
33 
34 #define SERVICE_NAME "com.sun.star.ui.dialogs.PresentationMinimizerDialog"
35 #define IMPLEMENTATION_NAME "com.sun.star.comp.ui.dialogs.PresentationMinimizerDialog"
36 
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::frame;
41 using namespace ::com::sun::star::beans;
42 
43 using ::rtl::OUString;
44 using ::com::sun::star::awt::XWindow;
45 using ::com::sun::star::awt::XWindowPeer;
46 
47 // ----------------------
48 // - PPPOptimizerDialog -
49 // ----------------------
50 
PPPOptimizerDialog(const Reference<XComponentContext> & rxContext)51 PPPOptimizerDialog::PPPOptimizerDialog(
52     const Reference< XComponentContext > &rxContext )
53     : m_xContext( rxContext )
54     , mbInitialized( false )
55 {
56     OSL_TRACE("PPPOptimizerDialog::PPPOptimizerDialog");
57 }
58 
59 // -----------------------------------------------------------------------------
60 
~PPPOptimizerDialog()61 PPPOptimizerDialog::~PPPOptimizerDialog()
62 {
63     OSL_TRACE("PPPOptimizerDialog::~PPPOptimizerDialog");
64 }
65 
66 // -----------------------------------------------------------------------------
67 // XInitialization
68 // -----------------------------------------------------------------------------
69 
initialize(const Sequence<Any> & aArguments)70 void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
71 	throw ( Exception, RuntimeException )
72 {
73     OSL_TRACE("PPPOptimizerDialog::initialize");
74     osl::ResettableMutexGuard aGuard( m_aMutex );
75     if ( mbInitialized )
76         throw RuntimeException(
77             OUString( RTL_CONSTASCII_USTRINGPARAM(
78                 "PPPOptimizerDialog has already been initialized!") ),
79                     Reference< XInterface >() );
80     aGuard.clear();
81 
82     Reference< XFrame > xFrame;
83     Reference< XController > xController;
84     Reference< XModel > xModel;
85     Reference< XWindow > xWindow;
86 
87     const Any *pAny = aArguments.getConstArray();
88     const Any *pEnd = pAny + aArguments.getLength();
89     for ( ; pAny != pEnd && !xFrame.is() && !xWindow.is(); pAny++ )
90     {
91         if ( ( *pAny >>= xFrame ) && xFrame.is() )
92         {
93             xWindow = xFrame->getContainerWindow();
94         }
95         else if ( ( *pAny >>= xController ) && xController.is() )
96         {
97             xFrame = xController->getFrame();
98             if ( xFrame.is() )
99                 xWindow = xFrame->getContainerWindow();
100         }
101         else if ( ( *pAny >>= xModel ) && xModel.is() )
102         {
103             xController = xModel->getCurrentController();
104             if ( xController.is() )
105             {
106                 xFrame = xController->getFrame();
107                 if ( xFrame.is() )
108                     xWindow = xFrame->getContainerWindow();
109             }
110         }
111         else
112             *pAny >>= xWindow;
113     }
114 
115     if ( !xFrame.is() )
116         throw IllegalArgumentException(
117             OUString( RTL_CONSTASCII_USTRINGPARAM(
118                 "PPPOptimizerDialog must be initialized with an "
119                 "XFrame, XController or XModel!") ),
120                     Reference< XInterface >(), 0 );
121 
122     aGuard.reset();
123     mxFrame = xFrame;
124     mxParentWindow.set( xWindow, UNO_QUERY );
125     mbInitialized = true;
126     aGuard.clear();
127 }
128 
129 // -----------------------------------------------------------------------------
130 // XServiceInfo
131 // -----------------------------------------------------------------------------
132 
getImplementationName()133 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
134 	throw (RuntimeException)
135 {
136 	return PPPOptimizerDialog_getImplementationName();
137 }
138 
supportsService(const OUString & ServiceName)139 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
140 	throw ( RuntimeException )
141 {
142     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
143 }
144 
getSupportedServiceNames()145 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
146     throw (RuntimeException)
147 {
148 	return PPPOptimizerDialog_getSupportedServiceNames();
149 }
150 
151 
setTitle(const::rtl::OUString & aTitle)152 void SAL_CALL PPPOptimizerDialog::setTitle( const ::rtl::OUString& aTitle )
153 throw (::com::sun::star::uno::RuntimeException)
154 {
155     osl::MutexGuard aGuard( m_aMutex );
156     msTitle = aTitle;
157 }
158 
execute()159 ::sal_Int16 SAL_CALL PPPOptimizerDialog::execute(  )
160 throw (::com::sun::star::uno::RuntimeException)
161 {
162     OSL_TRACE("PPPOptimizerDialog::execute");
163     sal_Int16 aRet = ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
164 
165     osl::ClearableMutexGuard aGuard( m_aMutex );
166     bool bInit( mbInitialized );
167     Reference< XFrame > xFrame( mxFrame );
168     Reference< XWindowPeer > xParent( mxParentWindow );
169     aGuard.clear();
170 
171     if ( !bInit || !xFrame.is() || !xParent.is() )
172         throw RuntimeException();
173     try
174     {
175         OptimizerDialog *pDialog(
176             new OptimizerDialog( m_xContext, xFrame, xParent ) );
177         pDialog->setTitle( msTitle );
178         aRet = pDialog->execute();
179         delete pDialog;
180     }
181     catch( ... )
182     {
183     }
184 
185     return aRet;
186 }
187 
188 // -----------------------------------------------------------------------------
189 
PPPOptimizerDialog_getImplementationName()190 OUString PPPOptimizerDialog_getImplementationName()
191 {
192 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
193 }
194 
PPPOptimizerDialog_getSupportedServiceNames()195 Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
196 {
197 	Sequence < OUString > aRet(1);
198     OUString* pArray = aRet.getArray();
199     pArray[0] =  OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
200     return aRet;
201 }
202 
PPPOptimizerDialog_createInstance(const Reference<XComponentContext> & rSMgr)203 Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr)
204     throw( Exception )
205 {
206 	return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr );
207 }
208 
209 // -----------------------------------------------------------------------------
210