xref: /AOO41X/main/forms/source/richtext/specialdispatchers.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
30 #include "specialdispatchers.hxx"
31 #include <editeng/editeng.hxx>
32 #include <editeng/editview.hxx>
33 #ifndef _SVX_SVXIDS_HRC
34 #include <svx/svxids.hrc>
35 #endif
36 #define ITEMID_SCRIPTSPACE          SID_ATTR_PARA_SCRIPTSPACE
37 #include <editeng/scriptspaceitem.hxx>
38 
39 //........................................................................
40 namespace frm
41 {
42 //........................................................................
43 
44     using namespace ::com::sun::star::uno;
45     using namespace ::com::sun::star::lang;
46     using namespace ::com::sun::star::util;
47     using namespace ::com::sun::star::frame;
48     using namespace ::com::sun::star::beans;
49 
50     //====================================================================
51     //= OSelectAllDispatcher
52     //====================================================================
53     //--------------------------------------------------------------------
54     OSelectAllDispatcher::OSelectAllDispatcher( EditView& _rView, const URL&  _rURL )
55         :ORichTextFeatureDispatcher( _rView, _rURL )
56     {
57     }
58 
59     //--------------------------------------------------------------------
60     OSelectAllDispatcher::~OSelectAllDispatcher( )
61     {
62         if ( !isDisposed() )
63         {
64             acquire();
65             dispose();
66         }
67     }
68 
69     //--------------------------------------------------------------------
70     void SAL_CALL OSelectAllDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ ) throw (RuntimeException)
71     {
72         ::osl::MutexGuard aGuard( m_aMutex );
73         OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OSelectAllDispatcher::dispatch: invalid URL!" );
74         (void)_rURL;
75 
76         checkDisposed();
77 
78         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
79         OSL_ENSURE( pEngine, "OSelectAllDispatcher::dispatch: no edit engine - but not yet disposed?" );
80         if ( !pEngine )
81             return;
82 
83         sal_uInt16 nParagraphs = pEngine->GetParagraphCount();
84         if ( nParagraphs )
85         {
86             sal_uInt16 nLastParaNumber = nParagraphs - 1;
87             xub_StrLen nParaLen = pEngine->GetTextLen( nLastParaNumber );
88             getEditView()->SetSelection( ESelection( 0, 0, nLastParaNumber, nParaLen ) );
89         }
90     }
91 
92     //--------------------------------------------------------------------
93     FeatureStateEvent OSelectAllDispatcher::buildStatusEvent() const
94     {
95         FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
96         aEvent.IsEnabled = sal_True;
97         return aEvent;
98     }
99 
100     //====================================================================
101     //= OParagraphDirectionDispatcher
102     //====================================================================
103     //--------------------------------------------------------------------
104     OParagraphDirectionDispatcher::OParagraphDirectionDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL,
105             IMultiAttributeDispatcher* _pMasterDispatcher )
106         :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
107     {
108     }
109 
110     //--------------------------------------------------------------------
111     FeatureStateEvent OParagraphDirectionDispatcher::buildStatusEvent() const
112     {
113         FeatureStateEvent aEvent( OAttributeDispatcher::buildStatusEvent() );
114 
115         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
116         OSL_ENSURE( pEngine, "OParagraphDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
117         if ( pEngine && pEngine->IsVertical() )
118             aEvent.IsEnabled = sal_False;
119 
120         return aEvent;
121     }
122 
123     //====================================================================
124     //= OTextDirectionDispatcher
125     //====================================================================
126     //--------------------------------------------------------------------
127     OTextDirectionDispatcher::OTextDirectionDispatcher( EditView& _rView, const URL& _rURL )
128         :ORichTextFeatureDispatcher( _rView, _rURL )
129     {
130     }
131 
132     //--------------------------------------------------------------------
133     void SAL_CALL OTextDirectionDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ ) throw (RuntimeException)
134     {
135         ::osl::MutexGuard aGuard( m_aMutex );
136         OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OTextDirectionDispatcher::dispatch: invalid URL!" );
137         (void)_rURL;
138 
139         checkDisposed();
140 
141         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
142         OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
143         if ( !pEngine )
144             return;
145 
146         pEngine->SetVertical( !pEngine->IsVertical() );
147     }
148 
149     //--------------------------------------------------------------------
150     FeatureStateEvent OTextDirectionDispatcher::buildStatusEvent() const
151     {
152         FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
153 
154         EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : NULL;
155         OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
156 
157         aEvent.IsEnabled = sal_True;
158         aEvent.State <<= (sal_Bool)( pEngine && pEngine->IsVertical() );
159 
160         return aEvent;
161     }
162 
163     //====================================================================
164     //= OAsianFontLayoutDispatcher
165     //====================================================================
166     //--------------------------------------------------------------------
167     OAsianFontLayoutDispatcher::OAsianFontLayoutDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher )
168         :OParametrizedAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
169     {
170     }
171 
172     //--------------------------------------------------------------------
173     const SfxPoolItem* OAsianFontLayoutDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
174     {
175         // look for the "Enable" parameter
176         const PropertyValue* pLookup = _rArguments.getConstArray();
177         const PropertyValue* pLookupEnd = _rArguments.getConstArray() + _rArguments.getLength();
178         while ( pLookup != pLookupEnd )
179         {
180             if ( pLookup->Name.equalsAscii( "Enable" ) )
181                 break;
182             ++pLookup;
183         }
184         if ( pLookup != pLookupEnd )
185         {
186             sal_Bool bEnable = sal_True;
187             OSL_VERIFY( pLookup->Value >>= bEnable );
188             if ( m_nAttributeId == SID_ATTR_PARA_SCRIPTSPACE )
189                 return new SvxScriptSpaceItem( bEnable, (WhichId)m_nAttributeId );
190             return new SfxBoolItem( (WhichId)m_nAttributeId, bEnable );
191         }
192 
193         OSL_ENSURE( sal_False, "OAsianFontLayoutDispatcher::convertDispatchArgsToItem: did not find the one and only argument!" );
194         return NULL;
195     }
196 
197 //........................................................................
198 }   // namespace frm
199 //........................................................................
200 
201