Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/awt/XPopupMenu.hpp>
31 : : #include <com/sun/star/frame/XPopupMenuController.hpp>
32 : :
33 : : #include <toolkit/helper/vclunohelper.hxx>
34 : :
35 : : #include <rtl/ref.hxx>
36 : :
37 : : #include <vcl/toolbox.hxx>
38 : : #include <vcl/menu.hxx>
39 : : #include <vcl/svapp.hxx>
40 : : #include <osl/mutex.hxx>
41 : :
42 : : #include "uielement/popupmenucontroller.hxx"
43 : : #include "services.h"
44 : :
45 : : using rtl::OUString;
46 : : using namespace ::com::sun::star;
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::lang;
49 : : using namespace ::com::sun::star::frame;
50 : : using namespace ::com::sun::star::beans;
51 : :
52 : : // --------------------------------------------------------------------
53 : :
54 : :
55 : : namespace framework
56 : : {
57 : :
58 [ # # ][ # # ]: 0 : DEFINE_XSERVICEINFO_MULTISERVICE ( PopupMenuController ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
59 : : OWeakObject ,
60 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ) ) ,
61 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.framework.PopupMenuController" ) )
62 : : )
63 : :
64 : 0 : DEFINE_INIT_SERVICE ( PopupMenuController, {} )
65 : :
66 : : class PopupMenuControllerImpl
67 : : {
68 : : };
69 : :
70 : : //========================================================================
71 : : // class PopupMenuController
72 : : //========================================================================
73 : :
74 : 0 : PopupMenuController::PopupMenuController( const Reference< lang::XMultiServiceFactory >& rServiceManager )
75 [ # # ]: 0 : : svt::ToolboxController( rServiceManager, Reference< frame::XFrame >(), OUString() )
76 : : {
77 : 0 : }
78 : :
79 : : // --------------------------------------------------------------------
80 : :
81 : 0 : PopupMenuController::~PopupMenuController()
82 : : {
83 [ # # ]: 0 : }
84 : :
85 : : // --------------------------------------------------------------------
86 : : // XInterface
87 : : // --------------------------------------------------------------------
88 : :
89 : 0 : Any SAL_CALL PopupMenuController::queryInterface( const Type& aType ) throw (RuntimeException)
90 : : {
91 [ # # ]: 0 : Any a( ToolboxController::queryInterface( aType ) );
92 [ # # ]: 0 : if ( a.hasValue() )
93 : 0 : return a;
94 : :
95 [ # # ]: 0 : return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
96 : : }
97 : :
98 : : // --------------------------------------------------------------------
99 : :
100 : 0 : void SAL_CALL PopupMenuController::acquire() throw ()
101 : : {
102 : 0 : ToolboxController::acquire();
103 : 0 : }
104 : :
105 : : // --------------------------------------------------------------------
106 : :
107 : 0 : void SAL_CALL PopupMenuController::release() throw ()
108 : : {
109 : 0 : ToolboxController::release();
110 : 0 : }
111 : :
112 : : // --------------------------------------------------------------------
113 : : // XComponent
114 : : // --------------------------------------------------------------------
115 : :
116 : 0 : void SAL_CALL PopupMenuController::dispose() throw (RuntimeException)
117 : : {
118 [ # # ]: 0 : if( mxPopupMenuController.is() )
119 : : {
120 [ # # ]: 0 : Reference< XComponent > xComponent( mxPopupMenuController, UNO_QUERY );
121 [ # # ]: 0 : if( xComponent.is() )
122 [ # # ][ # # ]: 0 : xComponent->dispose();
123 : 0 : mxPopupMenuController.clear();
124 : : }
125 : :
126 : 0 : mxPopupMenu.clear();
127 : :
128 : 0 : svt::ToolboxController::dispose();
129 : 0 : }
130 : :
131 : : // --------------------------------------------------------------------
132 : : // XStatusListener
133 : : // --------------------------------------------------------------------
134 : :
135 : 0 : void SAL_CALL PopupMenuController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException )
136 : : {
137 : 0 : svt::ToolboxController::statusChanged(rEvent);
138 : 0 : enable( rEvent.IsEnabled );
139 : 0 : }
140 : :
141 : : // --------------------------------------------------------------------
142 : : // XToolbarController
143 : : // --------------------------------------------------------------------
144 : :
145 : 0 : void SAL_CALL PopupMenuController::execute( sal_Int16 KeyModifier ) throw (RuntimeException)
146 : : {
147 : 0 : svt::ToolboxController::execute( KeyModifier );
148 : 0 : }
149 : :
150 : : // --------------------------------------------------------------------
151 : :
152 : 0 : void SAL_CALL PopupMenuController::click() throw (RuntimeException)
153 : : {
154 : 0 : svt::ToolboxController::click();
155 : 0 : }
156 : :
157 : : // --------------------------------------------------------------------
158 : :
159 : 0 : void SAL_CALL PopupMenuController::doubleClick() throw (RuntimeException)
160 : : {
161 : 0 : svt::ToolboxController::doubleClick();
162 : 0 : }
163 : :
164 : : // --------------------------------------------------------------------
165 : :
166 : 0 : bool PopupMenuController::CreatePopupMenuController() throw (Exception)
167 : : {
168 [ # # ][ # # ]: 0 : Reference< XMultiComponentFactory > xPopupMenuControllerRegistration( getServiceManager()->createInstance( SERVICENAME_POPUPMENUCONTROLLERFACTORY ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
169 : :
170 [ # # ]: 0 : Sequence< Any > aSeq( 2 );
171 : 0 : PropertyValue aPropValue;
172 : :
173 [ # # ]: 0 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
174 [ # # ][ # # ]: 0 : aPropValue.Value <<= getModuleName();
175 [ # # ][ # # ]: 0 : aSeq[0] <<= aPropValue;
176 [ # # ]: 0 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
177 [ # # ]: 0 : aPropValue.Value <<= m_xFrame;
178 [ # # ][ # # ]: 0 : aSeq[1] <<= aPropValue;
179 : :
180 [ # # ][ # # ]: 0 : Reference< XPropertySet > xProps( getServiceManager(), UNO_QUERY_THROW );
181 [ # # ][ # # ]: 0 : Reference< XComponentContext > xComponentContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );
[ # # ][ # # ]
182 : :
183 [ # # ][ # # ]: 0 : Reference< XPopupMenuController > xPopupMenuController( xPopupMenuControllerRegistration->createInstanceWithArgumentsAndContext( getCommandURL(), aSeq, xComponentContext ), UNO_QUERY );
[ # # ]
184 [ # # ]: 0 : if ( xPopupMenuController.is() )
185 : : {
186 [ # # ]: 0 : mxPopupMenuController = xPopupMenuController;
187 : 0 : return true;
188 : : }
189 [ # # ]: 0 : return false;
190 : : }
191 : :
192 : 0 : Reference< awt::XWindow > SAL_CALL PopupMenuController::createPopupWindow() throw (RuntimeException)
193 : : {
194 [ # # ]: 0 : SolarMutexGuard aSolarLock;
195 : :
196 : 0 : Reference< awt::XWindow > xRet;
197 : :
198 : : try
199 : : {
200 [ # # ][ # # ]: 0 : ToolBox* pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
[ # # ]
201 [ # # ]: 0 : if( !pToolBox )
202 : : return xRet;
203 : :
204 : : // get selected button
205 : 0 : sal_uInt16 nItemId = pToolBox->GetDownItemId();
206 [ # # ]: 0 : if( !nItemId )
207 : : return xRet;
208 : :
209 [ # # ]: 0 : ::Rectangle aRect( pToolBox->GetItemRect( nItemId ) );
210 : :
211 [ # # ][ # # ]: 0 : if( !mxPopupMenuController.is() && !CreatePopupMenuController() )
[ # # ][ # # ]
212 : : return xRet;
213 : :
214 [ # # ]: 0 : if( !mxPopupMenu.is() )
215 : : {
216 [ # # ][ # # ]: 0 : mxPopupMenu = Reference< awt::XPopupMenu >( getServiceManager()->createInstance( DECLARE_ASCII( "stardiv.Toolkit.VCLXPopupMenu" ) ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ][ # # ]
217 [ # # ][ # # ]: 0 : mxPopupMenuController->setPopupMenu( mxPopupMenu );
218 : : }
219 : : else
220 : : {
221 [ # # ][ # # ]: 0 : mxPopupMenuController->updatePopupMenu();
222 : :
223 : : }
224 [ # # ]: 0 : pToolBox->SetItemDown( nItemId, sal_True );
225 [ # # ][ # # ]: 0 : Reference< awt::XWindowPeer > xPeer( getParent(), UNO_QUERY_THROW );
226 [ # # ][ # # ]: 0 : mxPopupMenu->execute( xPeer, VCLUnoHelper::ConvertToAWTRect( aRect ), 0 );
[ # # ]
227 [ # # ][ # # ]: 0 : pToolBox->SetItemDown( nItemId, sal_False );
228 : : }
229 [ # # ]: 0 : catch( const Exception& )
230 : : {
231 : : }
232 : :
233 [ # # ]: 0 : return xRet;
234 : : }
235 : :
236 : : // --------------------------------------------------------------------
237 : :
238 : 0 : Reference< awt::XWindow > SAL_CALL PopupMenuController::createItemWindow( const Reference< awt::XWindow >& /*Parent*/ ) throw (RuntimeException)
239 : : {
240 : 0 : return Reference< awt::XWindow >();
241 : : }
242 : :
243 : : // --------------------------------------------------------------------
244 : :
245 : : }
246 : :
247 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|