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