Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / forms / source / richtext / specialdispatchers.cxx
bloba745bb45caf4dfdf7f24f02353b66fc80fc20740
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "specialdispatchers.hxx"
21 #include <editeng/editeng.hxx>
22 #include <editeng/editview.hxx>
23 #include <svx/svxids.hrc>
24 #include <editeng/scriptspaceitem.hxx>
27 namespace frm
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::util;
34 using namespace ::com::sun::star::frame;
35 using namespace ::com::sun::star::beans;
37 OSelectAllDispatcher::OSelectAllDispatcher( EditView& _rView, const URL& _rURL )
38 :ORichTextFeatureDispatcher( _rView, _rURL )
43 OSelectAllDispatcher::~OSelectAllDispatcher( )
45 if ( !isDisposed() )
47 acquire();
48 dispose();
53 void SAL_CALL OSelectAllDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ )
54 throw (RuntimeException,
55 std::exception)
57 ::osl::MutexGuard aGuard( m_aMutex );
58 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OSelectAllDispatcher::dispatch: invalid URL!" );
59 (void)_rURL;
61 checkDisposed();
63 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : nullptr;
64 OSL_ENSURE( pEngine, "OSelectAllDispatcher::dispatch: no edit engine - but not yet disposed?" );
65 if ( !pEngine )
66 return;
68 sal_Int32 nParagraphs = pEngine->GetParagraphCount();
69 if ( nParagraphs )
71 sal_Int32 nLastParaNumber = nParagraphs - 1;
72 sal_Int32 nParaLen = pEngine->GetTextLen( nLastParaNumber );
73 getEditView()->SetSelection( ESelection( 0, 0, nLastParaNumber, nParaLen ) );
78 FeatureStateEvent OSelectAllDispatcher::buildStatusEvent() const
80 FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
81 aEvent.IsEnabled = true;
82 return aEvent;
85 OParagraphDirectionDispatcher::OParagraphDirectionDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL,
86 IMultiAttributeDispatcher* _pMasterDispatcher )
87 :OAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
92 FeatureStateEvent OParagraphDirectionDispatcher::buildStatusEvent() const
94 FeatureStateEvent aEvent( OAttributeDispatcher::buildStatusEvent() );
96 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : nullptr;
97 OSL_ENSURE( pEngine, "OParagraphDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
98 if ( pEngine && pEngine->IsVertical() )
99 aEvent.IsEnabled = false;
101 return aEvent;
104 OTextDirectionDispatcher::OTextDirectionDispatcher( EditView& _rView, const URL& _rURL )
105 :ORichTextFeatureDispatcher( _rView, _rURL )
110 void SAL_CALL OTextDirectionDispatcher::dispatch( const URL& _rURL, const Sequence< PropertyValue >& /*_rArguments*/ ) throw (RuntimeException, std::exception)
112 ::osl::MutexGuard aGuard( m_aMutex );
113 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "OTextDirectionDispatcher::dispatch: invalid URL!" );
114 (void)_rURL;
116 checkDisposed();
118 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : nullptr;
119 OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
120 if ( !pEngine )
121 return;
123 pEngine->SetVertical( !pEngine->IsVertical() );
127 FeatureStateEvent OTextDirectionDispatcher::buildStatusEvent() const
129 FeatureStateEvent aEvent( ORichTextFeatureDispatcher::buildStatusEvent() );
131 EditEngine* pEngine = getEditView() ? getEditView()->GetEditEngine() : nullptr;
132 OSL_ENSURE( pEngine, "OTextDirectionDispatcher::dispatch: no edit engine - but not yet disposed?" );
134 aEvent.IsEnabled = true;
135 aEvent.State <<= pEngine && pEngine->IsVertical();
137 return aEvent;
140 OAsianFontLayoutDispatcher::OAsianFontLayoutDispatcher( EditView& _rView, AttributeId _nAttributeId, const URL& _rURL, IMultiAttributeDispatcher* _pMasterDispatcher )
141 :OParametrizedAttributeDispatcher( _rView, _nAttributeId, _rURL, _pMasterDispatcher )
146 const SfxPoolItem* OAsianFontLayoutDispatcher::convertDispatchArgsToItem( const Sequence< PropertyValue >& _rArguments )
148 // look for the "Enable" parameter
149 const PropertyValue* pLookup = _rArguments.getConstArray();
150 const PropertyValue* pLookupEnd = _rArguments.getConstArray() + _rArguments.getLength();
151 while ( pLookup != pLookupEnd )
153 if ( pLookup->Name == "Enable" )
154 break;
155 ++pLookup;
157 if ( pLookup != pLookupEnd )
159 bool bEnable = true;
160 OSL_VERIFY( pLookup->Value >>= bEnable );
161 if ( m_nAttributeId == SID_ATTR_PARA_SCRIPTSPACE )
162 return new SvxScriptSpaceItem( bEnable, (WhichId)m_nAttributeId );
163 return new SfxBoolItem( (WhichId)m_nAttributeId, bEnable );
166 OSL_FAIL( "OAsianFontLayoutDispatcher::convertDispatchArgsToItem: did not find the one and only argument!" );
167 return nullptr;
171 } // namespace frm
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */