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 {
72 OSL_TRACE("PPPOptimizerDialog::initialize");
73 osl::ResettableMutexGuard aGuard( m_aMutex );
74 if ( mbInitialized )
75 throw RuntimeException(
76 OUString( RTL_CONSTASCII_USTRINGPARAM(
77 "PPPOptimizerDialog has already been initialized!") ),
78 Reference< XInterface >() );
79 aGuard.clear();
80
81 Reference< XFrame > xFrame;
82 Reference< XController > xController;
83 Reference< XModel > xModel;
84 Reference< XWindow > xWindow;
85
86 const Any *pAny = aArguments.getConstArray();
87 const Any *pEnd = pAny + aArguments.getLength();
88 for ( ; pAny != pEnd && !xFrame.is() && !xWindow.is(); pAny++ )
89 {
90 if ( ( *pAny >>= xFrame ) && xFrame.is() )
91 {
92 xWindow = xFrame->getContainerWindow();
93 }
94 else if ( ( *pAny >>= xController ) && xController.is() )
95 {
96 xFrame = xController->getFrame();
97 if ( xFrame.is() )
98 xWindow = xFrame->getContainerWindow();
99 }
100 else if ( ( *pAny >>= xModel ) && xModel.is() )
101 {
102 xController = xModel->getCurrentController();
103 if ( xController.is() )
104 {
105 xFrame = xController->getFrame();
106 if ( xFrame.is() )
107 xWindow = xFrame->getContainerWindow();
108 }
109 }
110 else
111 *pAny >>= xWindow;
112 }
113
114 if ( !xFrame.is() )
115 throw IllegalArgumentException(
116 OUString( RTL_CONSTASCII_USTRINGPARAM(
117 "PPPOptimizerDialog must be initialized with an "
118 "XFrame, XController or XModel!") ),
119 Reference< XInterface >(), 0 );
120
121 aGuard.reset();
122 mxFrame = xFrame;
123 mxParentWindow.set( xWindow, UNO_QUERY );
124 mbInitialized = true;
125 aGuard.clear();
126 }
127
128 // -----------------------------------------------------------------------------
129 // XServiceInfo
130 // -----------------------------------------------------------------------------
131
getImplementationName()132 OUString SAL_CALL PPPOptimizerDialog::getImplementationName()
133 {
134 return PPPOptimizerDialog_getImplementationName();
135 }
136
supportsService(const OUString & ServiceName)137 sal_Bool SAL_CALL PPPOptimizerDialog::supportsService( const OUString& ServiceName )
138 {
139 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
140 }
141
getSupportedServiceNames()142 Sequence< OUString > SAL_CALL PPPOptimizerDialog::getSupportedServiceNames()
143 {
144 return PPPOptimizerDialog_getSupportedServiceNames();
145 }
146
147
setTitle(const::rtl::OUString & aTitle)148 void SAL_CALL PPPOptimizerDialog::setTitle( const ::rtl::OUString& aTitle )
149 {
150 osl::MutexGuard aGuard( m_aMutex );
151 msTitle = aTitle;
152 }
153
execute()154 ::sal_Int16 SAL_CALL PPPOptimizerDialog::execute( )
155 {
156 OSL_TRACE("PPPOptimizerDialog::execute");
157 sal_Int16 aRet = ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
158
159 osl::ClearableMutexGuard aGuard( m_aMutex );
160 bool bInit( mbInitialized );
161 Reference< XFrame > xFrame( mxFrame );
162 Reference< XWindowPeer > xParent( mxParentWindow );
163 aGuard.clear();
164
165 if ( !bInit || !xFrame.is() || !xParent.is() )
166 throw RuntimeException();
167 try
168 {
169 OptimizerDialog *pDialog(
170 new OptimizerDialog( m_xContext, xFrame, xParent ) );
171 pDialog->setTitle( msTitle );
172 aRet = pDialog->execute();
173 delete pDialog;
174 }
175 catch( ... )
176 {
177 }
178
179 return aRet;
180 }
181
182 // -----------------------------------------------------------------------------
183
PPPOptimizerDialog_getImplementationName()184 OUString PPPOptimizerDialog_getImplementationName()
185 {
186 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
187 }
188
PPPOptimizerDialog_getSupportedServiceNames()189 Sequence< OUString > PPPOptimizerDialog_getSupportedServiceNames()
190 {
191 Sequence < OUString > aRet(1);
192 OUString* pArray = aRet.getArray();
193 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
194 return aRet;
195 }
196
PPPOptimizerDialog_createInstance(const Reference<XComponentContext> & rSMgr)197 Reference< XInterface > PPPOptimizerDialog_createInstance( const Reference< XComponentContext > & rSMgr)
198 {
199 return (cppu::OWeakObject*) new PPPOptimizerDialog( rSMgr );
200 }
201
202 // -----------------------------------------------------------------------------
203