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