1*f39251c4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f39251c4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f39251c4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f39251c4SAndrew Rist  * distributed with this work for additional information
6*f39251c4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f39251c4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f39251c4SAndrew Rist  * "License"); you may not use this file except in compliance
9*f39251c4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f39251c4SAndrew Rist  *
11*f39251c4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f39251c4SAndrew Rist  *
13*f39251c4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f39251c4SAndrew Rist  * software distributed under the License is distributed on an
15*f39251c4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f39251c4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f39251c4SAndrew Rist  * specific language governing permissions and limitations
18*f39251c4SAndrew Rist  * under the License.
19*f39251c4SAndrew Rist  *
20*f39251c4SAndrew Rist  *************************************************************/
21*f39251c4SAndrew Rist 
22*f39251c4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <avmedia/mediatoolbox.hxx>
25cdf0e10cSrcweir #include <avmedia/mediaitem.hxx>
26cdf0e10cSrcweir #include "mediacontrol.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <sfx2/app.hxx>
29cdf0e10cSrcweir #include <sfx2/bindings.hxx>
30cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
31cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace avmedia
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // -----------------------
39cdf0e10cSrcweir // - MediaToolboxControl -
40cdf0e10cSrcweir // -----------------------
41cdf0e10cSrcweir 
42cdf0e10cSrcweir class MediaToolBoxControl_Impl : public MediaControl
43cdf0e10cSrcweir {
44cdf0e10cSrcweir public:
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 							MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl );
47cdf0e10cSrcweir 							~MediaToolBoxControl_Impl();
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	void 					update();
50cdf0e10cSrcweir 	void  					execute( const MediaItem& rItem );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir private:
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	MediaToolBoxControl*	mpToolBoxControl;
55cdf0e10cSrcweir };
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // ---------------------------------------------------------------------
58cdf0e10cSrcweir 
MediaToolBoxControl_Impl(Window & rParent,MediaToolBoxControl & rControl)59cdf0e10cSrcweir MediaToolBoxControl_Impl::MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ) :
60cdf0e10cSrcweir 	MediaControl( &rParent, MEDIACONTROLSTYLE_SINGLELINE ),
61cdf0e10cSrcweir 	mpToolBoxControl( &rControl )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	SetSizePixel( getMinSizePixel() );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // ---------------------------------------------------------------------
67cdf0e10cSrcweir 
~MediaToolBoxControl_Impl()68cdf0e10cSrcweir MediaToolBoxControl_Impl::~MediaToolBoxControl_Impl()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // ---------------------------------------------------------------------
73cdf0e10cSrcweir 
update()74cdf0e10cSrcweir void MediaToolBoxControl_Impl::update()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	mpToolBoxControl->implUpdateMediaControl();
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir // ---------------------------------------------------------------------
80cdf0e10cSrcweir 
execute(const MediaItem & rItem)81cdf0e10cSrcweir void MediaToolBoxControl_Impl::execute( const MediaItem& rItem )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir 	mpToolBoxControl->implExecuteMediaControl( rItem );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir // -----------------------
87cdf0e10cSrcweir // - MediaToolBoxControl -
88cdf0e10cSrcweir // -----------------------
89cdf0e10cSrcweir 
90cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( ::avmedia::MediaToolBoxControl, ::avmedia::MediaItem );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // -----------------------------------------------------------------------------
93cdf0e10cSrcweir 
MediaToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)94cdf0e10cSrcweir MediaToolBoxControl::MediaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
95cdf0e10cSrcweir 	SfxToolBoxControl( nSlotId, nId, rTbx )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir         rTbx.Invalidate();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // -----------------------------------------------------------------------------
101cdf0e10cSrcweir 
~MediaToolBoxControl()102cdf0e10cSrcweir MediaToolBoxControl::~MediaToolBoxControl()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir // -----------------------------------------------------------------------------
107cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)108cdf0e10cSrcweir void MediaToolBoxControl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
109cdf0e10cSrcweir 
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	MediaToolBoxControl_Impl* pCtrl = static_cast< MediaToolBoxControl_Impl* >( GetToolBox().GetItemWindow( GetId() ) );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	DBG_ASSERT( pCtrl, "MediaToolBoxControl::StateChanged: media control not found" );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	if( eState == SFX_ITEM_DISABLED )
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		pCtrl->Enable( false, false );
118cdf0e10cSrcweir 		pCtrl->SetText( String() );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		const MediaItem aEmptyMediaItem( 0, AVMEDIA_SETMASK_ALL );
121cdf0e10cSrcweir 		pCtrl->setState( aEmptyMediaItem );
122cdf0e10cSrcweir 	}
123cdf0e10cSrcweir 	else
124cdf0e10cSrcweir 	{
125cdf0e10cSrcweir 		pCtrl->Enable( true, false );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 		const MediaItem* pMediaItem = PTR_CAST( MediaItem, pState );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		if( pMediaItem && ( SFX_ITEM_AVAILABLE == eState ) )
130cdf0e10cSrcweir 			pCtrl->setState( *pMediaItem );
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
135cdf0e10cSrcweir 
CreateItemWindow(Window * pParent)136cdf0e10cSrcweir Window* MediaToolBoxControl::CreateItemWindow( Window *pParent )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	return( pParent ? new MediaToolBoxControl_Impl( *pParent, *this ) : NULL );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir // -----------------------------------------------------------------------------
142cdf0e10cSrcweir 
implUpdateMediaControl()143cdf0e10cSrcweir void MediaToolBoxControl::implUpdateMediaControl()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir     updateStatus( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ) );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // -----------------------------------------------------------------------------
149cdf0e10cSrcweir 
implExecuteMediaControl(const MediaItem & rItem)150cdf0e10cSrcweir void MediaToolBoxControl::implExecuteMediaControl( const MediaItem& rItem )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	MediaItem 								aExecItem( SID_AVMEDIA_TOOLBOX );
153cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > 	aArgs( 1 );
154cdf0e10cSrcweir 	uno::Any								aAny;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	aExecItem.merge( rItem );
157cdf0e10cSrcweir 	aExecItem.QueryValue( aAny );
158cdf0e10cSrcweir 	aArgs[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AVMediaToolBox" ) );
159cdf0e10cSrcweir     aArgs[ 0 ].Value = aAny;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     Dispatch( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ), aArgs );
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir }
165