bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / diactrl.cxx
blobd05f4f1f16a0365f49ad88b73411a886f4594fb4
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 <svl/intitem.hxx>
21 #include <vcl/toolbox.hxx>
23 #include <strings.hrc>
25 #include <diactrl.hxx>
27 #include <sdresid.hxx>
28 #include <app.hrc>
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 )
37 // SdPagesField
38 SdPagesField::SdPagesField( vcl::Window* pParent,
39 const uno::Reference< frame::XFrame >& rFrame ) :
40 SvxMetricField ( pParent, rFrame ),
41 m_xFrame ( rFrame )
43 OUString aStr( SdResId( STR_SLIDE_PLURAL ) );
44 SetCustomUnitText( aStr );
46 // set size
47 aStr += "XXX";
48 Size aSize( GetTextWidth( aStr )+20, GetTextHeight()+6 );
50 SetSizePixel( aSize );
52 // set parameter of MetricFields
53 SetUnit( FieldUnit::CUSTOM );
54 SetMin( 1 );
55 SetFirst( 1 );
56 SetMax( 15 );
57 SetLast( 15 );
58 SetSpinSize( 1 );
59 SetDecimalDigits( 0 );
60 Show();
63 SdPagesField::~SdPagesField()
67 void SdPagesField::UpdatePagesField( const SfxUInt16Item* pItem )
69 if( pItem )
71 long nValue = static_cast<long>(pItem->GetValue());
72 SetValue( nValue );
73 if( nValue == 1 )
74 SetCustomUnitText( SdResId( STR_SLIDE_SINGULAR ) );
75 else
76 SetCustomUnitText( SdResId( STR_SLIDE_PLURAL ) );
78 else
79 SetText( OUString() );
82 void SdPagesField::Modify()
84 SfxUInt16Item aItem( SID_PAGES_PER_ROW, static_cast<sal_uInt16>(GetValue()) );
86 ::uno::Any a;
87 ::uno::Sequence< ::beans::PropertyValue > aArgs( 1 );
88 aArgs[0].Name = "PagesPerRow";
89 aItem.QueryValue( a );
90 aArgs[0].Value = a;
91 SfxToolBoxControl::Dispatch( ::uno::Reference< ::frame::XDispatchProvider >( m_xFrame->getController(), ::uno::UNO_QUERY ),
92 ".uno:PagesPerRow",
93 aArgs );
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 )
113 pFld->Disable();
114 pFld->SetText( OUString() );
116 else
118 pFld->Enable();
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: */