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 <svl/intitem.hxx>
21 #include <vcl/toolbox.hxx>
23 #include <strings.hrc>
25 #include <diactrl.hxx>
27 #include <sdresid.hxx>
30 #include <com/sun/star/frame/XDispatchProvider.hpp>
31 #include <com/sun/star/frame/XFrame.hpp>
33 using namespace ::com::sun::star
;
35 SFX_IMPL_TOOLBOX_CONTROL( SdTbxCtlDiaPages
, SfxUInt16Item
)
38 SdPagesField::SdPagesField( vcl::Window
* pParent
,
39 const uno::Reference
< frame::XFrame
>& rFrame
) :
40 SvxMetricField ( pParent
, rFrame
),
43 OUString
aStr( SdResId( STR_SLIDE_PLURAL
) );
44 SetCustomUnitText( aStr
);
48 Size
aSize( GetTextWidth( aStr
)+20, GetTextHeight()+6 );
50 SetSizePixel( aSize
);
52 // set parameter of MetricFields
53 SetUnit( FieldUnit::CUSTOM
);
59 SetDecimalDigits( 0 );
63 SdPagesField::~SdPagesField()
67 void SdPagesField::UpdatePagesField( const SfxUInt16Item
* pItem
)
71 long nValue
= static_cast<long>(pItem
->GetValue());
74 SetCustomUnitText( SdResId( STR_SLIDE_SINGULAR
) );
76 SetCustomUnitText( SdResId( STR_SLIDE_PLURAL
) );
79 SetText( OUString() );
82 void SdPagesField::Modify()
84 SfxUInt16Item
aItem( SID_PAGES_PER_ROW
, static_cast<sal_uInt16
>(GetValue()) );
87 ::uno::Sequence
< ::beans::PropertyValue
> aArgs( 1 );
88 aArgs
[0].Name
= "PagesPerRow";
89 aItem
.QueryValue( a
);
91 SfxToolBoxControl::Dispatch( ::uno::Reference
< ::frame::XDispatchProvider
>( m_xFrame
->getController(), ::uno::UNO_QUERY
),
96 SdTbxCtlDiaPages::SdTbxCtlDiaPages( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
97 SfxToolBoxControl( nSlotId
, nId
, rTbx
)
101 SdTbxCtlDiaPages::~SdTbxCtlDiaPages()
105 void SdTbxCtlDiaPages::StateChanged( sal_uInt16
,
106 SfxItemState eState
, const SfxPoolItem
* pState
)
108 SdPagesField
* pFld
= static_cast<SdPagesField
*>( GetToolBox().GetItemWindow( GetId() ) );
109 DBG_ASSERT( pFld
, "Window not found" );
111 if ( eState
== SfxItemState::DISABLED
)
114 pFld
->SetText( OUString() );
120 const SfxUInt16Item
* pItem
= nullptr;
121 if ( eState
== SfxItemState::DEFAULT
)
123 pItem
= dynamic_cast< const SfxUInt16Item
* >( pState
);
124 DBG_ASSERT( pItem
, "sd::SdTbxCtlDiaPages::StateChanged(), wrong item type!" );
127 pFld
->UpdatePagesField( pItem
);
131 VclPtr
<vcl::Window
> SdTbxCtlDiaPages::CreateItemWindow( vcl::Window
* pParent
)
133 return VclPtrInstance
<SdPagesField
>( pParent
, m_xFrame
).get();
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */