update dev300-m58
[ooovba.git] / forms / source / richtext / specialdispatchers.cxx
blob7ebaca0e4ff5a4ab07868207ee8bdae066e58ab3
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: specialdispatchers.cxx,v $
10 * $Revision: 1.6 $
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_forms.hxx"
33 #include "specialdispatchers.hxx"
34 #include <svx/editeng.hxx>
35 #include <svx/editview.hxx>
36 #ifndef _SVX_SVXIDS_HRC
37 #include <svx/svxids.hrc>
38 #endif
39 #define ITEMID_SCRIPTSPACE SID_ATTR_PARA_SCRIPTSPACE
40 #include <svx/scriptspaceitem.hxx>
42 //........................................................................
43 namespace frm
45 //........................................................................
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::util;
50 using namespace ::com::sun::star::frame;
51 using namespace ::com::sun::star::beans;
53 //====================================================================
54 //= OSelectAllDispatcher
55 //====================================================================
56 //--------------------------------------------------------------------
57 OSelectAllDispatcher::OSelectAllDispatcher( EditView& _rView, const URL& _rURL )
58 :ORichTextFeatureDispatcher( _rView, _rURL )
62 //--------------------------------------------------------------------
63 OSelectAllDispatcher::~OSelectAllDispatcher( )
65 if ( !isDisposed() )
67 acquire();
68 dispose();
72 //--------------------------------------------------------------------
73 void SAL_CALL OSelectAllDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ ) throw (RuntimeException)
75 ::osl::MutexGuard aGuard( m_aMutex );
76 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OSelectAllDispatcher::dispatch: invalid URL!" );
77 (void)_rURL;
79 checkDisposed();
81 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
82 OSL_ENSURE( pEngine, "OSelectAllDispatcher::dispatch: no edit engine - but not yet disposed?" );
83 if ( !pEngine )
84 return;
86 USHORT nParagraphs = pEngine->GetParagraphCount();
87 if ( nParagraphs )
89 USHORT nLastParaNumber = nParagraphs - 1;
90 xub_StrLen nParaLen = pEngine->GetTextLen( nLastParaNumber );
91 getEditView()->SetSelection( ESelection( 0, 0, nLastParaNumber, nParaLen ) );
95 //--------------------------------------------------------------------
96 FeatureStateEvent OSelectAllDispatcher::buildStatusEvent() const
98 FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
99 aEvent.IsEnabled = sal_True;
100 return aEvent;
103 //====================================================================
104 //= OParagraphDirectionDispatcher
105 //====================================================================
106 //--------------------------------------------------------------------
107 OParagraphDirectionDispatcher::OParagraphDirectionDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL,
108 IMultiAttributeDispatcher* _pMasterDispatcher )
109 :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
113 //--------------------------------------------------------------------
114 FeatureStateEvent OParagraphDirectionDispatcher::buildStatusEvent() const
116 FeatureStateEvent aEvent( OAttributeDispatcher::buildStatusEvent() );
118 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
119 OSL_ENSURE( pEngine, "OParagraphDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
120 if ( pEngine && pEngine->IsVertical() )
121 aEvent.IsEnabled = sal_False;
123 return aEvent;
126 //====================================================================
127 //= OTextDirectionDispatcher
128 //====================================================================
129 //--------------------------------------------------------------------
130 OTextDirectionDispatcher::OTextDirectionDispatcher( EditView& _rView, const URL& _rURL )
131 :ORichTextFeatureDispatcher( _rView, _rURL )
135 //--------------------------------------------------------------------
136 void SAL_CALL OTextDirectionDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ ) throw (RuntimeException)
138 ::osl::MutexGuard aGuard( m_aMutex );
139 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OTextDirectionDispatcher::dispatch: invalid URL!" );
140 (void)_rURL;
142 checkDisposed();
144 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
145 OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
146 if ( !pEngine )
147 return;
149 pEngine->SetVertical( !pEngine->IsVertical() );
152 //--------------------------------------------------------------------
153 FeatureStateEvent OTextDirectionDispatcher::buildStatusEvent() const
155 FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
157 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
158 OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
160 aEvent.IsEnabled = sal_True;
161 aEvent.State <<= (sal_Bool)( pEngine && pEngine->IsVertical() );
163 return aEvent;
166 //====================================================================
167 //= OAsianFontLayoutDispatcher
168 //====================================================================
169 //--------------------------------------------------------------------
170 OAsianFontLayoutDispatcher::OAsianFontLayoutDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher )
171 :OParametrizedAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
175 //--------------------------------------------------------------------
176 const SfxPoolItem* OAsianFontLayoutDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
178 // look for the "Enable" parameter
179 const PropertyValue* pLookup = _rArguments.getConstArray();
180 const PropertyValue* pLookupEnd = _rArguments.getConstArray() + _rArguments.getLength();
181 while ( pLookup != pLookupEnd )
183 if ( pLookup->Name.equalsAscii( "Enable" ) )
184 break;
185 ++pLookup;
187 if ( pLookup != pLookupEnd )
189 sal_Bool bEnable = sal_True;
190 OSL_VERIFY( pLookup->Value >>= bEnable );
191 if ( m_nAttributeId == SID_ATTR_PARA_SCRIPTSPACE )
192 return new SvxScriptSpaceItem( bEnable, (WhichId)m_nAttributeId );
193 return new SfxBoolItem( (WhichId)m_nAttributeId, bEnable );
196 OSL_ENSURE( sal_False, "OAsianFontLayoutDispatcher::convertDispatchArgsToItem: did not find the one and only argument!" );
197 return NULL;
200 //........................................................................
201 } // namespace frm
202 //........................................................................