1c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3c142477cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4c142477cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5c142477cSAndrew Rist * distributed with this work for additional information
6c142477cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7c142477cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8c142477cSAndrew Rist * "License"); you may not use this file except in compliance
9c142477cSAndrew Rist * with the License. You may obtain a copy of the License at
10c142477cSAndrew Rist *
11c142477cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12c142477cSAndrew Rist *
13c142477cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14c142477cSAndrew Rist * software distributed under the License is distributed on an
15c142477cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c142477cSAndrew Rist * KIND, either express or implied. See the License for the
17c142477cSAndrew Rist * specific language governing permissions and limitations
18c142477cSAndrew Rist * under the License.
19c142477cSAndrew Rist *
20c142477cSAndrew Rist *************************************************************/
21c142477cSAndrew Rist
22c142477cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "pppoptimizerdialog.hxx"
28cdf0e10cSrcweir #include "optimizerdialog.hxx"
29cdf0e10cSrcweir
30*597a4c59SAriel Constenla-Haile #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
31*597a4c59SAriel Constenla-Haile #include <rtl/strbuf.hxx>
32*597a4c59SAriel Constenla-Haile #include <rtl/ref.hxx>
33*597a4c59SAriel Constenla-Haile
34*597a4c59SAriel Constenla-Haile #define SERVICE_NAME "com.sun.star.ui.dialogs.PresentationMinimizerDialog"
35*597a4c59SAriel Constenla-Haile #define IMPLEMENTATION_NAME "com.sun.star.comp.ui.dialogs.PresentationMinimizerDialog"
36*597a4c59SAriel Constenla-Haile
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::util;
39cdf0e10cSrcweir using namespace ::com::sun::star::lang;
40cdf0e10cSrcweir using namespace ::com::sun::star::frame;
41cdf0e10cSrcweir using namespace ::com::sun::star::beans;
42cdf0e10cSrcweir
43*597a4c59SAriel Constenla-Haile using ::rtl::OUString;
44*597a4c59SAriel Constenla-Haile using ::com::sun::star::awt::XWindow;
45*597a4c59SAriel Constenla-Haile using ::com::sun::star::awt::XWindowPeer;
46cdf0e10cSrcweir
47cdf0e10cSrcweir // ----------------------
48cdf0e10cSrcweir // - PPPOptimizerDialog -
49cdf0e10cSrcweir // ----------------------
50cdf0e10cSrcweir
PPPOptimizerDialog(const Reference<XComponentContext> & rxContext)51*597a4c59SAriel Constenla-Haile PPPOptimizerDialog::PPPOptimizerDialog(
52*597a4c59SAriel Constenla-Haile const Reference< XComponentContext > &rxContext )
53*597a4c59SAriel Constenla-Haile : m_xContext( rxContext )
54*597a4c59SAriel Constenla-Haile , mbInitialized( false )
55cdf0e10cSrcweir {
56*597a4c59SAriel Constenla-Haile OSL_TRACE("PPPOptimizerDialog::PPPOptimizerDialog");
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir // -----------------------------------------------------------------------------
60cdf0e10cSrcweir
~PPPOptimizerDialog()61cdf0e10cSrcweir PPPOptimizerDialog::~PPPOptimizerDialog()
62cdf0e10cSrcweir {
63*597a4c59SAriel Constenla-Haile OSL_TRACE("PPPOptimizerDialog::~PPPOptimizerDialog");
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir // -----------------------------------------------------------------------------
67cdf0e10cSrcweir // XInitialization
68cdf0e10cSrcweir // -----------------------------------------------------------------------------
69cdf0e10cSrcweir
initialize(const Sequence<Any> & aArguments)70cdf0e10cSrcweir void SAL_CALL PPPOptimizerDialog::initialize( const Sequence< Any >& aArguments )
71cdf0e10cSrcweir throw ( Exception, RuntimeException )
72cdf0e10cSrcweir {
73*597a4c59SAriel Constenla-Haile OSL_TRACE("PPPOptimizerDialog::initialize");
74*597a4c59SAriel Constenla-Haile osl::ResettableMutexGuard aGuard( m_aMutex );
75*597a4c59SAriel Constenla-Haile if ( mbInitialized )
76*597a4c59SAriel Constenla-Haile throw RuntimeException(
77*597a4c59SAriel Constenla-Haile OUString( RTL_CONSTASCII_USTRINGPARAM(
78*597a4c59SAriel Constenla-Haile "PPPOptimizerDialog has already been initialized!") ),
79*597a4c59SAriel Constenla-Haile Reference< XInterface >() );
80*597a4c59SAriel Constenla-Haile aGuard.clear();
81*597a4c59SAriel Constenla-Haile
82*597a4c59SAriel Constenla-Haile Reference< XFrame > xFrame;
83*597a4c59SAriel Constenla-Haile Reference< XController > xController;
84*597a4c59SAriel Constenla-Haile Reference< XModel > xModel;
85*597a4c59SAriel Constenla-Haile Reference< XWindow > xWindow;
86*597a4c59SAriel Constenla-Haile
87*597a4c59SAriel Constenla-Haile const Any *pAny = aArguments.getConstArray();
88*597a4c59SAriel Constenla-Haile const Any *pEnd = pAny + aArguments.getLength();
89*597a4c59SAriel Constenla-Haile for ( ; pAny != pEnd && !xFrame.is() && !xWindow.is(); pAny++ )
90*597a4c59SAriel Constenla-Haile {
91*597a4c59SAriel Constenla-Haile if ( ( *pAny >>= xFrame ) && xFrame.is() )
92*597a4c59SAriel Constenla-Haile {
93*597a4c59SAriel Constenla-Haile xWindow = xFrame->getContainerWindow();
94*597a4c59SAriel Constenla-Haile }
95*597a4c59SAriel Constenla-Haile else if ( ( *pAny >>= xController ) && xController.is() )
96*597a4c59SAriel Constenla-Haile {
97*597a4c59SAriel Constenla-Haile xFrame = xController->getFrame();
98*597a4c59SAriel Constenla-Haile if ( xFrame.is() )
99*597a4c59SAriel Constenla-Haile xWindow = xFrame->getContainerWindow();
100*597a4c59SAriel Constenla-Haile }
101*597a4c59SAriel Constenla-Haile else if ( ( *pAny >>= xModel ) && xModel.is() )
102*597a4c59SAriel Constenla-Haile {
103*597a4c59SAriel Constenla-Haile xController = xModel->getCurrentController();
104*597a4c59SAriel Constenla-Haile if ( xController.is() )
105*597a4c59SAriel Constenla-Haile {
106*597a4c59SAriel Constenla-Haile xFrame = xController->getFrame();
107*597a4c59SAriel Constenla-Haile if ( xFrame.is() )
108*597a4c59SAriel Constenla-Haile xWindow = xFrame->getContainerWindow();
109*597a4c59SAriel Constenla-Haile }
110*597a4c59SAriel Constenla-Haile }
111*597a4c59SAriel Constenla-Haile else
112*597a4c59SAriel Constenla-Haile *pAny >>= xWindow;
113*597a4c59SAriel Constenla-Haile }
114*597a4c59SAriel Constenla-Haile
115*597a4c59SAriel Constenla-Haile if ( !xFrame.is() )
116*597a4c59SAriel Constenla-Haile throw IllegalArgumentException(
117*597a4c59SAriel Constenla-Haile OUString( RTL_CONSTASCII_USTRINGPARAM(
118*597a4c59SAriel Constenla-Haile "PPPOptimizerDialog must be initialized with an "
119*597a4c59SAriel Constenla-Haile "XFrame, XController or XModel!") ),
120*597a4c59SAriel Constenla-Haile Reference< XInterface >(), 0 );
121*597a4c59SAriel Constenla-Haile
122*597a4c59SAriel Constenla-Haile aGuard.reset();
123*597a4c59SAriel Constenla-Haile mxFrame = xFrame;
124*597a4c59SAriel Constenla-Haile mxParentWindow.set( xWindow, UNO_QUERY );
125*597a4c59SAriel Constenla-Haile mbInitialized = true;
126*597a4c59SAriel Constenla-Haile aGuard.clear();
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir // -----------------------------------------------------------------------------
130cdf0e10cSrcweir // XServiceInfo
131cdf0e10cSrcweir // -----------------------------------------------------------------------------
132cdf0e10cSrcweir
getImplementationName()133cdf0e10cSrcweir OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
134cdf0e10cSrcweir throw (RuntimeException)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir return PPPOptimizerDialog_getImplementationName();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
supportsService(const OUString & ServiceName)139cdf0e10cSrcweir sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
140cdf0e10cSrcweir throw ( RuntimeException )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
getSupportedServiceNames()145cdf0e10cSrcweir Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
146cdf0e10cSrcweir throw (RuntimeException)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir return PPPOptimizerDialog_getSupportedServiceNames();
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir
setTitle(const::rtl::OUString & aTitle)152*597a4c59SAriel Constenla-Haile void SAL_CALL PPPOptimizerDialog::setTitle( const ::rtl::OUString& aTitle )
153*597a4c59SAriel Constenla-Haile throw (::com::sun::star::uno::RuntimeException)
154cdf0e10cSrcweir {
155*597a4c59SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex );
156*597a4c59SAriel Constenla-Haile msTitle = aTitle;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
execute()159*597a4c59SAriel Constenla-Haile ::sal_Int16 SAL_CALL PPPOptimizerDialog::execute( )
160*597a4c59SAriel Constenla-Haile throw (::com::sun::star::uno::RuntimeException)
161cdf0e10cSrcweir {
162*597a4c59SAriel Constenla-Haile OSL_TRACE("PPPOptimizerDialog::execute");
163*597a4c59SAriel Constenla-Haile sal_Int16 aRet = ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
164*597a4c59SAriel Constenla-Haile
165*597a4c59SAriel Constenla-Haile osl::ClearableMutexGuard aGuard( m_aMutex );
166*597a4c59SAriel Constenla-Haile bool bInit( mbInitialized );
167*597a4c59SAriel Constenla-Haile Reference< XFrame > xFrame( mxFrame );
168*597a4c59SAriel Constenla-Haile Reference< XWindowPeer > xParent( mxParentWindow );
169*597a4c59SAriel Constenla-Haile aGuard.clear();
170*597a4c59SAriel Constenla-Haile
171*597a4c59SAriel Constenla-Haile if ( !bInit || !xFrame.is() || !xParent.is() )
172*597a4c59SAriel Constenla-Haile throw RuntimeException();
173*597a4c59SAriel Constenla-Haile try
174*597a4c59SAriel Constenla-Haile {
175*597a4c59SAriel Constenla-Haile OptimizerDialog *pDialog(
176*597a4c59SAriel Constenla-Haile new OptimizerDialog( m_xContext, xFrame, xParent ) );
177*597a4c59SAriel Constenla-Haile pDialog->setTitle( msTitle );
178*597a4c59SAriel Constenla-Haile aRet = pDialog->execute();
179*597a4c59SAriel Constenla-Haile delete pDialog;
180*597a4c59SAriel Constenla-Haile }
181*597a4c59SAriel Constenla-Haile catch( ... )
182*597a4c59SAriel Constenla-Haile {
183*597a4c59SAriel Constenla-Haile }
184cdf0e10cSrcweir
185*597a4c59SAriel Constenla-Haile return aRet;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir // -----------------------------------------------------------------------------
189cdf0e10cSrcweir
PPPOptimizerDialog_getImplementationName()190cdf0e10cSrcweir OUString PPPOptimizerDialog_getImplementationName()
191cdf0e10cSrcweir {
192*597a4c59SAriel Constenla-Haile return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
PPPOptimizerDialog_getSupportedServiceNames()195cdf0e10cSrcweir Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
196cdf0e10cSrcweir {
197cdf0e10cSrcweir Sequence < OUString > aRet(1);
198cdf0e10cSrcweir OUString* pArray = aRet.getArray();
199cdf0e10cSrcweir pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
200cdf0e10cSrcweir return aRet;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
PPPOptimizerDialog_createInstance(const Reference<XComponentContext> & rSMgr)203cdf0e10cSrcweir Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr)
204cdf0e10cSrcweir throw( Exception )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr );
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir // -----------------------------------------------------------------------------
210