merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / dlg / diactrl.cxx
blobe98e978e9f119346ac78d77fe408192002ad07e1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: diactrl.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/presentation/FadeEffect.hpp>
35 #include <svx/dialogs.hrc>
37 #include "sdattr.hxx"
38 #include "strings.hrc"
40 #define _SD_DIACTRL_CXX
41 #include "diactrl.hxx"
43 #include "sdresid.hxx"
44 #include "app.hrc"
45 #include "res_bmp.hrc"
46 #include <sfx2/dispatch.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/app.hxx>
50 using namespace ::com::sun::star;
52 SFX_IMPL_TOOLBOX_CONTROL( SdTbxCtlDiaPages, SfxUInt16Item )
55 //========================================================================
56 // SdPagesField
57 //========================================================================
59 SdPagesField::SdPagesField( Window* pParent,
60 const uno::Reference< frame::XFrame >& rFrame,
61 WinBits nBits ) :
62 SvxMetricField ( pParent, rFrame, nBits ),
63 m_xFrame ( rFrame )
65 String aStr( SdResId( STR_SLIDE_PLURAL ) );
66 SetCustomUnitText( aStr );
68 // Groesse setzen
69 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "XXX" ) );
70 Size aSize( GetTextWidth( aStr )+20, GetTextHeight()+6 );
73 SetSizePixel( aSize );
75 // Parameter des MetricFields setzen
76 SetUnit( FUNIT_CUSTOM );
77 SetMin( 1 );
78 SetFirst( 1 );
79 SetMax( 15 );
80 SetLast( 15 );
81 SetSpinSize( 1 );
82 SetDecimalDigits( 0 );
83 Show();
86 // -----------------------------------------------------------------------
88 SdPagesField::~SdPagesField()
92 // -----------------------------------------------------------------------
94 void SdPagesField::UpdatePagesField( const SfxUInt16Item* pItem )
96 if( pItem )
98 long nValue = (long) pItem->GetValue();
99 SetValue( nValue );
100 if( nValue == 1 )
101 SetCustomUnitText( String( SdResId( STR_SLIDE_SINGULAR ) ) );
102 else
103 SetCustomUnitText( String( SdResId( STR_SLIDE_PLURAL ) ) );
105 else
106 SetText( String() );
109 // -----------------------------------------------------------------------
111 void SdPagesField::Modify()
113 SfxUInt16Item aItem( SID_PAGES_PER_ROW, (UINT16) GetValue() );
115 ::uno::Any a;
116 ::uno::Sequence< ::beans::PropertyValue > aArgs( 1 );
117 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PagesPerRow" ));
118 aItem.QueryValue( a );
119 aArgs[0].Value = a;
120 SfxToolBoxControl::Dispatch( ::uno::Reference< ::frame::XDispatchProvider >( m_xFrame->getController(), ::uno::UNO_QUERY ),
121 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PagesPerRow" )),
122 aArgs );
124 rBindings.GetDispatcher()->Execute(
125 SID_PAGES_PER_ROW, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aItem, 0L, 0L );
129 /*************************************************************************
131 |* SdTbxCtlDiaPages
133 \************************************************************************/
135 SdTbxCtlDiaPages::SdTbxCtlDiaPages( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) :
136 SfxToolBoxControl( nSlotId, nId, rTbx )
140 //========================================================================
142 SdTbxCtlDiaPages::~SdTbxCtlDiaPages()
146 //========================================================================
148 void SdTbxCtlDiaPages::StateChanged( USHORT,
149 SfxItemState eState, const SfxPoolItem* pState )
151 SdPagesField* pFld = (SdPagesField*) GetToolBox().GetItemWindow( GetId() );
152 DBG_ASSERT( pFld, "Window not found" );
154 if ( eState == SFX_ITEM_DISABLED )
156 pFld->Disable();
157 pFld->SetText( String() );
159 else
161 pFld->Enable();
163 const SfxUInt16Item* pItem = 0;
164 if ( eState == SFX_ITEM_AVAILABLE )
166 pItem = dynamic_cast< const SfxUInt16Item* >( pState );
167 DBG_ASSERT( pItem, "sd::SdTbxCtlDiaPages::StateChanged(), wrong item type!" );
170 pFld->UpdatePagesField( pItem );
174 //========================================================================
176 Window* SdTbxCtlDiaPages::CreateItemWindow( Window* pParent )
178 return new SdPagesField( pParent, m_xFrame );