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 .
23 #include <svx/svxids.hrc>
24 #include <svl/eitem.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <sfx2/viewsh.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <vcl/toolbox.hxx>
29 #include <osl/mutex.hxx>
31 #include <sfx2/imagemgr.hxx>
32 #include <vcl/svapp.hxx>
33 #include "svx/tbxcustomshapes.hxx"
35 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlCustomShapes
, SfxBoolItem
);
37 SvxTbxCtlCustomShapes::SvxTbxCtlCustomShapes( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
38 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
39 m_aSubTbxResName( "private:resource/toolbar/" )
44 DBG_ASSERT( false, "SvxTbxCtlCustomShapes: unknown slot executed. ?" );
46 case SID_DRAWTBX_CS_BASIC
:
48 m_aCommand
= ".uno:BasicShapes.diamond";
49 m_aSubTbName
= "basicshapes";
53 case SID_DRAWTBX_CS_SYMBOL
:
55 m_aCommand
= ".uno:SymbolShapes.smiley";
56 m_aSubTbName
= "symbolshapes";
60 case SID_DRAWTBX_CS_ARROW
:
62 m_aCommand
= ".uno:ArrowShapes.left-right-arrow";
63 m_aSubTbName
= "arrowshapes";
66 case SID_DRAWTBX_CS_FLOWCHART
:
68 m_aCommand
= ".uno:FlowChartShapes.flowchart-internal-storage";
69 m_aSubTbName
= "flowchartshapes";
72 case SID_DRAWTBX_CS_CALLOUT
:
74 m_aCommand
= ".uno:CalloutShapes.round-rectangular-callout";
75 m_aSubTbName
= "calloutshapes";
78 case SID_DRAWTBX_CS_STAR
:
80 m_aCommand
= ".uno:StarShapes.star5";
81 m_aSubTbName
= "starshapes";
85 m_aSubTbxResName
+= m_aSubTbName
;
86 rTbx
.SetItemBits( nId
, ToolBoxItemBits::DROPDOWN
| rTbx
.GetItemBits( nId
) );
90 // Notification when the application status has changed
91 void SvxTbxCtlCustomShapes::StateChanged( sal_uInt16 nSID
, SfxItemState eState
,
92 const SfxPoolItem
* pState
)
94 SfxToolBoxControl::StateChanged( nSID
, eState
, pState
);
97 // when one wants to create a popup window
98 SfxPopupWindowType
SvxTbxCtlCustomShapes::GetPopupWindowType() const
100 return( m_aCommand
.isEmpty() ? SfxPopupWindowType::ONCLICK
: SfxPopupWindowType::ONTIMEOUT
);
103 // Here is the window created
104 // The location of the Toolbox is queried through GetToolBox()
105 // rItemRect are the screen coordinates
106 VclPtr
<SfxPopupWindow
> SvxTbxCtlCustomShapes::CreatePopupWindow()
108 createAndPositionSubToolBar( m_aSubTbxResName
);
114 void SvxTbxCtlCustomShapes::Select(sal_uInt16 nSelectModifier
)
116 if ( !m_aCommand
.isEmpty() )
118 com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
> aParamSeq( 1 );
119 aParamSeq
[0].Name
= "KeyModifier";
120 aParamSeq
[0].Value
<<= static_cast< sal_Int16
>( nSelectModifier
);
121 Dispatch( m_aCommand
, aParamSeq
);
126 sal_Bool SAL_CALL
SvxTbxCtlCustomShapes::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
128 // We control a sub-toolbar therefore we have to return true.
132 OUString SAL_CALL
SvxTbxCtlCustomShapes::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
134 // Provide the controlled sub-toolbar name, so we are notified whenever
135 // this toolbar executes a function.
139 void SAL_CALL
SvxTbxCtlCustomShapes::functionSelected( const OUString
& rCommand
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
141 // remember the new command
142 m_aCommand
= rCommand
;
144 // Our sub-toolbar wants to execute a function.
145 // We have to change the image of our toolbar button to reflect the new function.
149 void SAL_CALL
SvxTbxCtlCustomShapes::updateImage( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
151 // We should update the button image of our parent (toolbar).
152 // Use the stored command to set the correct current image.
153 SolarMutexGuard aGuard
;
154 if ( !m_aCommand
.isEmpty() )
156 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> xFrame( getFrameInterface());
157 Image aImage
= GetImage( xFrame
, m_aCommand
, hasBigImages() );
159 GetToolBox().SetItemImage( GetId(), aImage
);
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */