1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/awt/XPopupMenu.hpp>
22 #include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
23 #include <com/sun/star/frame/XPopupMenuController.hpp>
25 #include <toolkit/helper/vclunohelper.hxx>
27 #include <rtl/ref.hxx>
29 #include <vcl/toolbox.hxx>
30 #include <vcl/menu.hxx>
31 #include <vcl/svapp.hxx>
32 #include <osl/mutex.hxx>
34 #include "uielement/popupmenucontroller.hxx"
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::frame
;
41 using namespace ::com::sun::star::beans
;
43 // --------------------------------------------------------------------
49 DEFINE_XSERVICEINFO_MULTISERVICE_2 ( PopupMenuController
,
51 OUString( "com.sun.star.frame.ToolbarController" ) ,
52 OUString( "com.sun.star.comp.framework.PopupMenuController" )
55 DEFINE_INIT_SERVICE ( PopupMenuController
, {} )
57 class PopupMenuControllerImpl
61 //========================================================================
62 // class PopupMenuController
63 //========================================================================
65 PopupMenuController::PopupMenuController( const Reference
< uno::XComponentContext
>& rxContext
)
66 : svt::ToolboxController( rxContext
, Reference
< frame::XFrame
>(), OUString() )
70 // --------------------------------------------------------------------
72 PopupMenuController::~PopupMenuController()
76 // --------------------------------------------------------------------
78 // --------------------------------------------------------------------
80 Any SAL_CALL
PopupMenuController::queryInterface( const Type
& aType
) throw (RuntimeException
)
82 Any
a( ToolboxController::queryInterface( aType
) );
86 return ::cppu::queryInterface( aType
, static_cast< lang::XServiceInfo
* >( this ));
89 // --------------------------------------------------------------------
91 void SAL_CALL
PopupMenuController::acquire() throw ()
93 ToolboxController::acquire();
96 // --------------------------------------------------------------------
98 void SAL_CALL
PopupMenuController::release() throw ()
100 ToolboxController::release();
103 // --------------------------------------------------------------------
105 // --------------------------------------------------------------------
107 void SAL_CALL
PopupMenuController::dispose() throw (RuntimeException
)
109 if( mxPopupMenuController
.is() )
111 Reference
< XComponent
> xComponent( mxPopupMenuController
, UNO_QUERY
);
112 if( xComponent
.is() )
113 xComponent
->dispose();
114 mxPopupMenuController
.clear();
119 svt::ToolboxController::dispose();
122 // --------------------------------------------------------------------
124 // --------------------------------------------------------------------
126 void SAL_CALL
PopupMenuController::statusChanged( const frame::FeatureStateEvent
& rEvent
) throw ( RuntimeException
)
128 svt::ToolboxController::statusChanged(rEvent
);
129 enable( rEvent
.IsEnabled
);
132 // --------------------------------------------------------------------
133 // XToolbarController
134 // --------------------------------------------------------------------
136 void SAL_CALL
PopupMenuController::execute( sal_Int16 KeyModifier
) throw (RuntimeException
)
138 svt::ToolboxController::execute( KeyModifier
);
141 // --------------------------------------------------------------------
143 void SAL_CALL
PopupMenuController::click() throw (RuntimeException
)
145 svt::ToolboxController::click();
148 // --------------------------------------------------------------------
150 void SAL_CALL
PopupMenuController::doubleClick() throw (RuntimeException
)
152 svt::ToolboxController::doubleClick();
155 // --------------------------------------------------------------------
157 bool PopupMenuController::CreatePopupMenuController() throw (Exception
)
159 Reference
< XMultiComponentFactory
> xPopupMenuControllerRegistration
= PopupMenuControllerFactory::create( m_xContext
);
161 Sequence
< Any
> aSeq( 2 );
162 PropertyValue aPropValue
;
164 aPropValue
.Name
= OUString( "ModuleIdentifier" );
165 aPropValue
.Value
<<= getModuleName();
166 aSeq
[0] <<= aPropValue
;
167 aPropValue
.Name
= OUString( "Frame" );
168 aPropValue
.Value
<<= m_xFrame
;
169 aSeq
[1] <<= aPropValue
;
171 Reference
< XPopupMenuController
> xPopupMenuController( xPopupMenuControllerRegistration
->createInstanceWithArgumentsAndContext( getCommandURL(), aSeq
, m_xContext
), UNO_QUERY
);
172 if ( xPopupMenuController
.is() )
174 mxPopupMenuController
= xPopupMenuController
;
180 Reference
< awt::XWindow
> SAL_CALL
PopupMenuController::createPopupWindow() throw (RuntimeException
)
182 SolarMutexGuard aSolarLock
;
184 Reference
< awt::XWindow
> xRet
;
188 ToolBox
* pToolBox
= dynamic_cast< ToolBox
* >( VCLUnoHelper::GetWindow( getParent() ) );
192 // get selected button
193 sal_uInt16 nItemId
= pToolBox
->GetDownItemId();
197 ::Rectangle
aRect( pToolBox
->GetItemRect( nItemId
) );
199 if( !mxPopupMenuController
.is() && !CreatePopupMenuController() )
202 if( !mxPopupMenu
.is() )
204 mxPopupMenu
= Reference
< awt::XPopupMenu
>(
205 m_xContext
->getServiceManager()->createInstanceWithContext("stardiv.Toolkit.VCLXPopupMenu", m_xContext
), UNO_QUERY_THROW
);
206 mxPopupMenuController
->setPopupMenu( mxPopupMenu
);
210 mxPopupMenuController
->updatePopupMenu();
213 pToolBox
->SetItemDown( nItemId
, sal_True
);
214 Reference
< awt::XWindowPeer
> xPeer( getParent(), UNO_QUERY_THROW
);
215 mxPopupMenu
->execute( xPeer
, VCLUnoHelper::ConvertToAWTRect( aRect
), 0 );
216 pToolBox
->SetItemDown( nItemId
, sal_False
);
218 catch( const Exception
& )
225 // --------------------------------------------------------------------
227 Reference
< awt::XWindow
> SAL_CALL
PopupMenuController::createItemWindow( const Reference
< awt::XWindow
>& /*Parent*/ ) throw (RuntimeException
)
229 return Reference
< awt::XWindow
>();
232 // --------------------------------------------------------------------
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */