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 #include <avmedia/mediatoolbox.hxx> 29 #include <avmedia/mediaitem.hxx> 30 #include "mediacontrol.hxx" 31 32 #include <sfx2/app.hxx> 33 #include <sfx2/bindings.hxx> 34 #include <sfx2/dispatch.hxx> 35 #include <sfx2/sfxsids.hrc> 36 37 using namespace ::com::sun::star; 38 39 namespace avmedia 40 { 41 42 // ----------------------- 43 // - MediaToolboxControl - 44 // ----------------------- 45 46 class MediaToolBoxControl_Impl : public MediaControl 47 { 48 public: 49 50 MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ); 51 ~MediaToolBoxControl_Impl(); 52 53 void update(); 54 void execute( const MediaItem& rItem ); 55 56 private: 57 58 MediaToolBoxControl* mpToolBoxControl; 59 }; 60 61 // --------------------------------------------------------------------- 62 63 MediaToolBoxControl_Impl::MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ) : 64 MediaControl( &rParent, MEDIACONTROLSTYLE_SINGLELINE ), 65 mpToolBoxControl( &rControl ) 66 { 67 SetSizePixel( getMinSizePixel() ); 68 } 69 70 // --------------------------------------------------------------------- 71 72 MediaToolBoxControl_Impl::~MediaToolBoxControl_Impl() 73 { 74 } 75 76 // --------------------------------------------------------------------- 77 78 void MediaToolBoxControl_Impl::update() 79 { 80 mpToolBoxControl->implUpdateMediaControl(); 81 } 82 83 // --------------------------------------------------------------------- 84 85 void MediaToolBoxControl_Impl::execute( const MediaItem& rItem ) 86 { 87 mpToolBoxControl->implExecuteMediaControl( rItem ); 88 } 89 90 // ----------------------- 91 // - MediaToolBoxControl - 92 // ----------------------- 93 94 SFX_IMPL_TOOLBOX_CONTROL( ::avmedia::MediaToolBoxControl, ::avmedia::MediaItem ); 95 96 // ----------------------------------------------------------------------------- 97 98 MediaToolBoxControl::MediaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 99 SfxToolBoxControl( nSlotId, nId, rTbx ) 100 { 101 rTbx.Invalidate(); 102 } 103 104 // ----------------------------------------------------------------------------- 105 106 MediaToolBoxControl::~MediaToolBoxControl() 107 { 108 } 109 110 // ----------------------------------------------------------------------------- 111 112 void MediaToolBoxControl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState ) 113 114 { 115 MediaToolBoxControl_Impl* pCtrl = static_cast< MediaToolBoxControl_Impl* >( GetToolBox().GetItemWindow( GetId() ) ); 116 117 DBG_ASSERT( pCtrl, "MediaToolBoxControl::StateChanged: media control not found" ); 118 119 if( eState == SFX_ITEM_DISABLED ) 120 { 121 pCtrl->Enable( false, false ); 122 pCtrl->SetText( String() ); 123 124 const MediaItem aEmptyMediaItem( 0, AVMEDIA_SETMASK_ALL ); 125 pCtrl->setState( aEmptyMediaItem ); 126 } 127 else 128 { 129 pCtrl->Enable( true, false ); 130 131 const MediaItem* pMediaItem = PTR_CAST( MediaItem, pState ); 132 133 if( pMediaItem && ( SFX_ITEM_AVAILABLE == eState ) ) 134 pCtrl->setState( *pMediaItem ); 135 } 136 } 137 138 // ----------------------------------------------------------------------------- 139 140 Window* MediaToolBoxControl::CreateItemWindow( Window *pParent ) 141 { 142 return( pParent ? new MediaToolBoxControl_Impl( *pParent, *this ) : NULL ); 143 } 144 145 // ----------------------------------------------------------------------------- 146 147 void MediaToolBoxControl::implUpdateMediaControl() 148 { 149 updateStatus( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ) ); 150 } 151 152 // ----------------------------------------------------------------------------- 153 154 void MediaToolBoxControl::implExecuteMediaControl( const MediaItem& rItem ) 155 { 156 MediaItem aExecItem( SID_AVMEDIA_TOOLBOX ); 157 uno::Sequence< beans::PropertyValue > aArgs( 1 ); 158 uno::Any aAny; 159 160 aExecItem.merge( rItem ); 161 aExecItem.QueryValue( aAny ); 162 aArgs[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AVMediaToolBox" ) ); 163 aArgs[ 0 ].Value = aAny; 164 165 Dispatch( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ), aArgs ); 166 } 167 168 } 169