1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
32 
33 #ifndef _SVX_SVXIDS_HRC
34 #include <svx/svxids.hrc>
35 #endif
36 #include <tools/shl.hxx>
37 #include <svl/eitem.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/viewsh.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <vcl/toolbox.hxx>
42 #include <vos/mutex.hxx>
43 
44 #include <sfx2/imagemgr.hxx>
45 #include <vcl/svapp.hxx>
46 #include "svx/tbxcustomshapes.hxx"
47 
48 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlCustomShapes, SfxBoolItem);
49 
50 /*************************************************************************
51 |*
52 |*
53 |*
54 \************************************************************************/
55 
56 SvxTbxCtlCustomShapes::SvxTbxCtlCustomShapes( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
57 	SfxToolBoxControl( nSlotId, nId, rTbx ),
58 	m_aSubTbxResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ) )
59 {
60 	switch( nSlotId )
61 	{
62 		default :
63 		{
64 			DBG_ASSERT( false, "SvxTbxCtlCustomShapes: unknown slot executed. ?" );
65 		}
66 		case SID_DRAWTBX_CS_BASIC :
67 		{
68             m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes.diamond" ) );
69             m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "basicshapes" ) );
70 		}
71 		break;
72 
73 		case SID_DRAWTBX_CS_SYMBOL :
74 		{
75             m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes.smiley" ) );
76 			m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "symbolshapes" ) );
77 		}
78 		break;
79 
80 		case SID_DRAWTBX_CS_ARROW :
81 		{
82             m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes.left-right-arrow" ) );
83 			m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "arrowshapes" ) );
84 		}
85 		break;
86 		case SID_DRAWTBX_CS_FLOWCHART :
87 		{
88 			m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes.flowchart-internal-storage" ) );
89 			m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flowchartshapes" ) );
90 		}
91 		break;
92 		case SID_DRAWTBX_CS_CALLOUT :
93 		{
94 			m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes.round-rectangular-callout" ) );
95 			m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calloutshapes" ) );
96 		}
97 		break;
98 		case SID_DRAWTBX_CS_STAR :
99 		{
100 			m_aCommand = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes.star5" ) );
101 			m_aSubTbName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "starshapes" ) );
102 		}
103 		break;
104 	}
105     m_aSubTbxResName += m_aSubTbName;
106 	rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
107 	rTbx.Invalidate();
108 }
109 
110 /*************************************************************************
111 |*
112 |* Benachrichtigung, wenn sich der Applikationsstatus geaendert hat
113 |*
114 \************************************************************************/
115 
116 void SvxTbxCtlCustomShapes::StateChanged( sal_uInt16 nSID, SfxItemState eState,
117 								  const SfxPoolItem* pState )
118 {
119     SfxToolBoxControl::StateChanged( nSID, eState, pState );
120 }
121 
122 /*************************************************************************
123 |*
124 |* Wenn man ein PopupWindow erzeugen will
125 |*
126 \************************************************************************/
127 
128 SfxPopupWindowType SvxTbxCtlCustomShapes::GetPopupWindowType() const
129 {
130 	return( m_aCommand.getLength() == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT);
131 }
132 
133 /*************************************************************************
134 |*
135 |* Hier wird das Fenster erzeugt
136 |* Lage der Toolbox mit GetToolBox() abfragbar
137 |* rItemRect sind die Screen-Koordinaten
138 |*
139 \************************************************************************/
140 
141 SfxPopupWindow* SvxTbxCtlCustomShapes::CreatePopupWindow()
142 {
143     createAndPositionSubToolBar( m_aSubTbxResName );
144 	return NULL;
145 }
146 
147 // -----------------------------------------------------------------------
148 
149 void SvxTbxCtlCustomShapes::Select( sal_Bool /*bMod1*/ )
150 {
151  	if ( m_aCommand.getLength() > 0 )
152 	{
153         com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > aParamSeq( 0 );
154 		Dispatch( m_aCommand, aParamSeq );
155 	}
156 }
157 
158 
159 ::sal_Bool SAL_CALL SvxTbxCtlCustomShapes::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
160 {
161     // We control a sub-toolbar therefor, we have to return true.
162     return sal_True;
163 }
164 
165 ::rtl::OUString SAL_CALL SvxTbxCtlCustomShapes::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
166 {
167     // Provide the controlled sub-toolbar name, so we are notified whenever
168     // this toolbar executes a function.
169     return m_aSubTbName;
170 }
171 
172 void SAL_CALL SvxTbxCtlCustomShapes::functionSelected( const ::rtl::OUString& rCommand ) throw (::com::sun::star::uno::RuntimeException)
173 {
174     // remind the new command
175     m_aCommand = rCommand;
176     // Our sub-toolbar wants to execute a function.
177     // We have to change the image of our toolbar button to reflect the new function.
178     ::vos::OGuard aGuard( Application::GetSolarMutex() );
179     if ( !m_bDisposed )
180     {
181         if ( m_aCommand.getLength() > 0 )
182         {
183             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
184             Image aImage = GetImage( xFrame, m_aCommand, hasBigImages(), isHighContrast() );
185             if ( !!aImage )
186                 GetToolBox().SetItemImage( GetId(), aImage );
187         }
188     }
189 }
190 
191 void SAL_CALL SvxTbxCtlCustomShapes::updateImage(  ) throw (::com::sun::star::uno::RuntimeException)
192 {
193     // We should update the button image of our parent (toolbar).
194     // Use the stored command to set the correct current image.
195     ::vos::OGuard aGuard( Application::GetSolarMutex() );
196     if ( m_aCommand.getLength() > 0 )
197     {
198         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( getFrameInterface());
199         Image aImage = GetImage( xFrame, m_aCommand, hasBigImages(), isHighContrast() );
200         if ( !!aImage )
201             GetToolBox().SetItemImage( GetId(), aImage );
202     }
203 }
204 
205