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