1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/debug.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/sfxsids.hrc>
30 #include <comphelper/propertysequence.hxx>
32 using namespace ::com::sun::star
;
37 class MediaToolBoxControl_Impl
: public MediaControl
41 MediaToolBoxControl_Impl( vcl::Window
& rParent
, MediaToolBoxControl
& rControl
);
43 void update() override
;
44 void execute( const MediaItem
& rItem
) override
;
48 MediaToolBoxControl
* mpToolBoxControl
;
52 MediaToolBoxControl_Impl::MediaToolBoxControl_Impl( vcl::Window
& rParent
, MediaToolBoxControl
& rControl
) :
53 MediaControl( &rParent
, MEDIACONTROLSTYLE_SINGLELINE
),
54 mpToolBoxControl( &rControl
)
56 SetSizePixel( getMinSizePixel() );
60 void MediaToolBoxControl_Impl::update()
62 mpToolBoxControl
->implUpdateMediaControl();
66 void MediaToolBoxControl_Impl::execute( const MediaItem
& rItem
)
68 mpToolBoxControl
->implExecuteMediaControl( rItem
);
72 SFX_IMPL_TOOLBOX_CONTROL( ::avmedia::MediaToolBoxControl
, ::avmedia::MediaItem
);
75 MediaToolBoxControl::MediaToolBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
76 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
82 MediaToolBoxControl::~MediaToolBoxControl()
87 void MediaToolBoxControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
89 MediaToolBoxControl_Impl
* pCtrl
= static_cast< MediaToolBoxControl_Impl
* >( GetToolBox().GetItemWindow( GetId() ) );
91 DBG_ASSERT( pCtrl
, "MediaToolBoxControl::StateChanged: media control not found" );
93 if( eState
== SfxItemState::DISABLED
)
95 pCtrl
->Enable( false, false );
96 pCtrl
->SetText( OUString() );
98 const MediaItem
aEmptyMediaItem( 0, AVMediaSetMask::ALL
);
99 pCtrl
->setState( aEmptyMediaItem
);
103 pCtrl
->Enable( true, false );
105 const MediaItem
* pMediaItem
= dynamic_cast<const MediaItem
*>( pState
);
107 if( pMediaItem
&& ( eState
== SfxItemState::DEFAULT
) )
108 pCtrl
->setState( *pMediaItem
);
113 VclPtr
<vcl::Window
> MediaToolBoxControl::CreateItemWindow( vcl::Window
*pParent
)
115 return ( pParent
? VclPtr
<MediaToolBoxControl_Impl
>::Create( *pParent
, *this ) : nullptr );
119 void MediaToolBoxControl::implUpdateMediaControl()
121 updateStatus( ".uno:AVMediaToolBox" );
125 void MediaToolBoxControl::implExecuteMediaControl( const MediaItem
& rItem
)
127 MediaItem
aExecItem( SID_AVMEDIA_TOOLBOX
);
130 aExecItem
.merge( rItem
);
131 aExecItem
.QueryValue( aAny
);
132 auto aArgs(::comphelper::InitPropertySequence({
133 { "AVMediaToolBox", aAny
}
136 Dispatch( ".uno:AVMediaToolBox" , aArgs
);
139 } // namespace avmedia
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */