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 <tools/shl.hxx>
25 #include <svl/eitem.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/viewsh.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <vcl/toolbox.hxx>
30 #include <osl/mutex.hxx>
32 #include <sfx2/imagemgr.hxx>
33 #include <vcl/svapp.hxx>
34 #include "svx/tbxcustomshapes.hxx"
36 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlCustomShapes
, SfxBoolItem
);
38 SvxTbxCtlCustomShapes::SvxTbxCtlCustomShapes( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
39 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
40 m_aSubTbxResName( "private:resource/toolbar/" )
46 DBG_ASSERT( false, "SvxTbxCtlCustomShapes: unknown slot executed. ?" );
48 case SID_DRAWTBX_CS_BASIC
:
50 m_aCommand
= ".uno:BasicShapes.diamond";
51 m_aSubTbName
= "basicshapes";
55 case SID_DRAWTBX_CS_SYMBOL
:
57 m_aCommand
= ".uno:SymbolShapes.smiley";
58 m_aSubTbName
= "symbolshapes";
62 case SID_DRAWTBX_CS_ARROW
:
64 m_aCommand
= ".uno:ArrowShapes.left-right-arrow";
65 m_aSubTbName
= "arrowshapes";
68 case SID_DRAWTBX_CS_FLOWCHART
:
70 m_aCommand
= ".uno:FlowChartShapes.flowchart-internal-storage";
71 m_aSubTbName
= "flowchartshapes";
74 case SID_DRAWTBX_CS_CALLOUT
:
76 m_aCommand
= ".uno:CalloutShapes.round-rectangular-callout";
77 m_aSubTbName
= "calloutshapes";
80 case SID_DRAWTBX_CS_STAR
:
82 m_aCommand
= ".uno:StarShapes.star5";
83 m_aSubTbName
= "starshapes";
87 m_aSubTbxResName
+= m_aSubTbName
;
88 rTbx
.SetItemBits( nId
, TIB_DROPDOWN
| rTbx
.GetItemBits( nId
) );
92 /*************************************************************************
94 |* Notification when the application status has changed
96 \************************************************************************/
98 void SvxTbxCtlCustomShapes::StateChanged( sal_uInt16 nSID
, SfxItemState eState
,
99 const SfxPoolItem
* pState
)
101 SfxToolBoxControl::StateChanged( nSID
, eState
, pState
);
104 /*************************************************************************
106 |* when one wants to create a popup window
108 \************************************************************************/
110 SfxPopupWindowType
SvxTbxCtlCustomShapes::GetPopupWindowType() const
112 return( m_aCommand
.isEmpty() ? SFX_POPUPWINDOW_ONCLICK
: SFX_POPUPWINDOW_ONTIMEOUT
);
115 /*************************************************************************
117 |* Here is the window created
118 |* The location of the Toolbox is queried through GetToolBox()
119 |* rItemRect are the screen coordinates
121 \************************************************************************/
123 SfxPopupWindow
* SvxTbxCtlCustomShapes::CreatePopupWindow()
125 createAndPositionSubToolBar( m_aSubTbxResName
);
129 // -----------------------------------------------------------------------
131 void SvxTbxCtlCustomShapes::Select( sal_Bool
/*bMod1*/ )
133 if ( !m_aCommand
.isEmpty() )
135 com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
> aParamSeq( 0 );
136 Dispatch( m_aCommand
, aParamSeq
);
141 ::sal_Bool SAL_CALL
SvxTbxCtlCustomShapes::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException
)
143 // We control a sub-toolbar therefore we have to return true.
147 OUString SAL_CALL
SvxTbxCtlCustomShapes::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException
)
149 // Provide the controlled sub-toolbar name, so we are notified whenever
150 // this toolbar executes a function.
154 void SAL_CALL
SvxTbxCtlCustomShapes::functionSelected( const OUString
& rCommand
) throw (::com::sun::star::uno::RuntimeException
)
156 // remind the new command
157 m_aCommand
= rCommand
;
158 // Our sub-toolbar wants to execute a function.
159 // We have to change the image of our toolbar button to reflect the new function.
160 SolarMutexGuard aGuard
;
163 if ( !m_aCommand
.isEmpty() )
165 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> xFrame( getFrameInterface());
166 Image aImage
= GetImage( xFrame
, m_aCommand
, hasBigImages() );
168 GetToolBox().SetItemImage( GetId(), aImage
);
173 void SAL_CALL
SvxTbxCtlCustomShapes::updateImage( ) throw (::com::sun::star::uno::RuntimeException
)
175 // We should update the button image of our parent (toolbar).
176 // Use the stored command to set the correct current image.
177 SolarMutexGuard aGuard
;
178 if ( !m_aCommand
.isEmpty() )
180 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> xFrame( getFrameInterface());
181 Image aImage
= GetImage( xFrame
, m_aCommand
, hasBigImages() );
183 GetToolBox().SetItemImage( GetId(), aImage
);
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */