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