1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "specialdispatchers.hxx"
27cdf0e10cSrcweir #include <editeng/editeng.hxx>
28cdf0e10cSrcweir #include <editeng/editview.hxx>
29cdf0e10cSrcweir #ifndef _SVX_SVXIDS_HRC
30cdf0e10cSrcweir #include <svx/svxids.hrc>
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #define ITEMID_SCRIPTSPACE          SID_ATTR_PARA_SCRIPTSPACE
33cdf0e10cSrcweir #include <editeng/scriptspaceitem.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //........................................................................
36cdf0e10cSrcweir namespace frm
37cdf0e10cSrcweir {
38cdf0e10cSrcweir //........................................................................
39cdf0e10cSrcweir 
40cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
42cdf0e10cSrcweir     using namespace ::com::sun::star::util;
43cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
44cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     //====================================================================
47cdf0e10cSrcweir     //= OSelectAllDispatcher
48cdf0e10cSrcweir     //====================================================================
49cdf0e10cSrcweir     //--------------------------------------------------------------------
OSelectAllDispatcher(EditView & _rView,const URL & _rURL)50cdf0e10cSrcweir     OSelectAllDispatcher::OSelectAllDispatcher( EditView& _rView, const URL&  _rURL )
51cdf0e10cSrcweir         :ORichTextFeatureDispatcher( _rView, _rURL )
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir     }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     //--------------------------------------------------------------------
~OSelectAllDispatcher()56cdf0e10cSrcweir     OSelectAllDispatcher::~OSelectAllDispatcher( )
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir         if ( !isDisposed() )
59cdf0e10cSrcweir         {
60cdf0e10cSrcweir             acquire();
61cdf0e10cSrcweir             dispose();
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     //--------------------------------------------------------------------
dispatch(const URL & _rURL,const Sequence<PropertyValue> &)66cdf0e10cSrcweir     void SAL_CALL OSelectAllDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ ) throw (RuntimeException)
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
69cdf0e10cSrcweir         OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OSelectAllDispatcher::dispatch: invalid URL!" );
70cdf0e10cSrcweir         (void)_rURL;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         checkDisposed();
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
75cdf0e10cSrcweir         OSL_ENSURE( pEngine, "OSelectAllDispatcher::dispatch: no edit engine - but not yet disposed?" );
76cdf0e10cSrcweir         if ( !pEngine )
77cdf0e10cSrcweir             return;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         sal_uInt16 nParagraphs = pEngine->GetParagraphCount();
80cdf0e10cSrcweir         if ( nParagraphs )
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir             sal_uInt16 nLastParaNumber = nParagraphs - 1;
83cdf0e10cSrcweir             xub_StrLen nParaLen = pEngine->GetTextLen( nLastParaNumber );
84cdf0e10cSrcweir             getEditView()->SetSelection( ESelection( 0, 0, nLastParaNumber, nParaLen ) );
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     //--------------------------------------------------------------------
buildStatusEvent() const89cdf0e10cSrcweir     FeatureStateEvent OSelectAllDispatcher::buildStatusEvent() const
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
92cdf0e10cSrcweir         aEvent.IsEnabled = sal_True;
93cdf0e10cSrcweir         return aEvent;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     //====================================================================
97cdf0e10cSrcweir     //= OParagraphDirectionDispatcher
98cdf0e10cSrcweir     //====================================================================
99cdf0e10cSrcweir     //--------------------------------------------------------------------
OParagraphDirectionDispatcher(EditView & _rView,AttributeId _nAttributeId,const URL & _rURL,IMultiAttributeDispatcher * _pMasterDispatcher)100cdf0e10cSrcweir     OParagraphDirectionDispatcher::OParagraphDirectionDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL,
101cdf0e10cSrcweir             IMultiAttributeDispatcher* _pMasterDispatcher )
102cdf0e10cSrcweir         :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     //--------------------------------------------------------------------
buildStatusEvent() const107cdf0e10cSrcweir     FeatureStateEvent OParagraphDirectionDispatcher::buildStatusEvent() const
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         FeatureStateEvent aEvent( OAttributeDispatcher::buildStatusEvent() );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
112cdf0e10cSrcweir         OSL_ENSURE( pEngine, "OParagraphDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
113cdf0e10cSrcweir         if ( pEngine && pEngine->IsVertical() )
114cdf0e10cSrcweir             aEvent.IsEnabled = sal_False;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         return aEvent;
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     //====================================================================
120cdf0e10cSrcweir     //= OTextDirectionDispatcher
121cdf0e10cSrcweir     //====================================================================
122cdf0e10cSrcweir     //--------------------------------------------------------------------
OTextDirectionDispatcher(EditView & _rView,const URL & _rURL)123cdf0e10cSrcweir     OTextDirectionDispatcher::OTextDirectionDispatcher( EditView& _rView, const URL& _rURL )
124cdf0e10cSrcweir         :ORichTextFeatureDispatcher( _rView, _rURL )
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     //--------------------------------------------------------------------
dispatch(const URL & _rURL,const Sequence<PropertyValue> &)129cdf0e10cSrcweir     void SAL_CALL OTextDirectionDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ ) throw (RuntimeException)
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
132cdf0e10cSrcweir         OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OTextDirectionDispatcher::dispatch: invalid URL!" );
133cdf0e10cSrcweir         (void)_rURL;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         checkDisposed();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
138cdf0e10cSrcweir         OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
139cdf0e10cSrcweir         if ( !pEngine )
140cdf0e10cSrcweir             return;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         pEngine->SetVertical( !pEngine->IsVertical() );
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     //--------------------------------------------------------------------
buildStatusEvent() const146cdf0e10cSrcweir     FeatureStateEvent OTextDirectionDispatcher::buildStatusEvent() const
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
151cdf0e10cSrcweir         OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         aEvent.IsEnabled = sal_True;
154cdf0e10cSrcweir         aEvent.State <<= (sal_Bool)( pEngine && pEngine->IsVertical() );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         return aEvent;
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     //====================================================================
160cdf0e10cSrcweir     //= OAsianFontLayoutDispatcher
161cdf0e10cSrcweir     //====================================================================
162cdf0e10cSrcweir     //--------------------------------------------------------------------
OAsianFontLayoutDispatcher(EditView & _rView,AttributeId _nAttributeId,const URL & _rURL,IMultiAttributeDispatcher * _pMasterDispatcher)163cdf0e10cSrcweir     OAsianFontLayoutDispatcher::OAsianFontLayoutDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher )
164cdf0e10cSrcweir         :OParametrizedAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     //--------------------------------------------------------------------
convertDispatchArgsToItem(const Sequence<PropertyValue> & _rArguments)169cdf0e10cSrcweir     const SfxPoolItem* OAsianFontLayoutDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         // look for the "Enable" parameter
172cdf0e10cSrcweir         const PropertyValue* pLookup = _rArguments.getConstArray();
173cdf0e10cSrcweir         const PropertyValue* pLookupEnd = _rArguments.getConstArray() + _rArguments.getLength();
174cdf0e10cSrcweir         while ( pLookup != pLookupEnd )
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir             if ( pLookup->Name.equalsAscii( "Enable" ) )
177cdf0e10cSrcweir                 break;
178cdf0e10cSrcweir             ++pLookup;
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir         if ( pLookup != pLookupEnd )
181cdf0e10cSrcweir         {
182cdf0e10cSrcweir             sal_Bool bEnable = sal_True;
183cdf0e10cSrcweir             OSL_VERIFY( pLookup->Value >>= bEnable );
184cdf0e10cSrcweir             if ( m_nAttributeId == SID_ATTR_PARA_SCRIPTSPACE )
185cdf0e10cSrcweir                 return new SvxScriptSpaceItem( bEnable, (WhichId)m_nAttributeId );
186cdf0e10cSrcweir             return new SfxBoolItem( (WhichId)m_nAttributeId, bEnable );
187cdf0e10cSrcweir         }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         OSL_ENSURE( sal_False, "OAsianFontLayoutDispatcher::convertDispatchArgsToItem: did not find the one and only argument!" );
190cdf0e10cSrcweir         return NULL;
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir //........................................................................
194cdf0e10cSrcweir }   // namespace frm
195cdf0e10cSrcweir //........................................................................
196cdf0e10cSrcweir 
197