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