Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / avmedia / source / framework / mediatoolbox.cxx
blob7524c24c653bcbdfd034d401ef38b8cd25c2991f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <avmedia/mediatoolbox.hxx>
21 #include <avmedia/mediaitem.hxx>
22 #include "mediacontrol.hxx"
24 #include <sfx2/app.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/sfxsids.hrc>
29 using namespace ::com::sun::star;
31 namespace avmedia
34 // -----------------------
35 // - MediaToolboxControl -
36 // -----------------------
38 class MediaToolBoxControl_Impl : public MediaControl
40 public:
42 MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl );
43 ~MediaToolBoxControl_Impl();
45 void update();
46 void execute( const MediaItem& rItem );
48 private:
50 MediaToolBoxControl* mpToolBoxControl;
53 // ---------------------------------------------------------------------
55 MediaToolBoxControl_Impl::MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ) :
56 MediaControl( &rParent, MEDIACONTROLSTYLE_SINGLELINE ),
57 mpToolBoxControl( &rControl )
59 SetSizePixel( getMinSizePixel() );
62 // ---------------------------------------------------------------------
64 MediaToolBoxControl_Impl::~MediaToolBoxControl_Impl()
68 // ---------------------------------------------------------------------
70 void MediaToolBoxControl_Impl::update()
72 mpToolBoxControl->implUpdateMediaControl();
75 // ---------------------------------------------------------------------
77 void MediaToolBoxControl_Impl::execute( const MediaItem& rItem )
79 mpToolBoxControl->implExecuteMediaControl( rItem );
82 // -----------------------
83 // - MediaToolBoxControl -
84 // -----------------------
86 SFX_IMPL_TOOLBOX_CONTROL( ::avmedia::MediaToolBoxControl, ::avmedia::MediaItem );
88 // -----------------------------------------------------------------------------
90 MediaToolBoxControl::MediaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
91 SfxToolBoxControl( nSlotId, nId, rTbx )
93 rTbx.Invalidate();
96 // -----------------------------------------------------------------------------
98 MediaToolBoxControl::~MediaToolBoxControl()
102 // -----------------------------------------------------------------------------
104 void MediaToolBoxControl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState )
107 MediaToolBoxControl_Impl* pCtrl = static_cast< MediaToolBoxControl_Impl* >( GetToolBox().GetItemWindow( GetId() ) );
109 DBG_ASSERT( pCtrl, "MediaToolBoxControl::StateChanged: media control not found" );
111 if( eState == SFX_ITEM_DISABLED )
113 pCtrl->Enable( false, false );
114 pCtrl->SetText( String() );
116 const MediaItem aEmptyMediaItem( 0, AVMEDIA_SETMASK_ALL );
117 pCtrl->setState( aEmptyMediaItem );
119 else
121 pCtrl->Enable( true, false );
123 const MediaItem* pMediaItem = PTR_CAST( MediaItem, pState );
125 if( pMediaItem && ( SFX_ITEM_AVAILABLE == eState ) )
126 pCtrl->setState( *pMediaItem );
130 // -----------------------------------------------------------------------------
132 Window* MediaToolBoxControl::CreateItemWindow( Window *pParent )
134 return( pParent ? new MediaToolBoxControl_Impl( *pParent, *this ) : NULL );
137 // -----------------------------------------------------------------------------
139 void MediaToolBoxControl::implUpdateMediaControl()
141 updateStatus( ".uno:AVMediaToolBox" );
144 // -----------------------------------------------------------------------------
146 void MediaToolBoxControl::implExecuteMediaControl( const MediaItem& rItem )
148 MediaItem aExecItem( SID_AVMEDIA_TOOLBOX );
149 uno::Sequence< beans::PropertyValue > aArgs( 1 );
150 uno::Any aAny;
152 aExecItem.merge( rItem );
153 aExecItem.QueryValue( aAny );
154 aArgs[ 0 ].Name = "AVMediaToolBox" ;
155 aArgs[ 0 ].Value = aAny;
157 Dispatch( ".uno:AVMediaToolBox" , aArgs );
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */