1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <config_wasm_strip.h>
22 #include <ChartController.hxx>
25 #include "UndoGuard.hxx"
26 #include <DrawViewWrapper.hxx>
27 #include <ChartWindow.hxx>
28 #include <ChartModel.hxx>
29 #include <ChartView.hxx>
30 #include <TitleHelper.hxx>
31 #include <ObjectIdentifier.hxx>
32 #include <ControllerLockGuard.hxx>
33 #include <comphelper/diagnose_ex.hxx>
34 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
35 #include <AccessibleTextHelper.hxx>
37 #include <strings.hrc>
38 #include <chartview/DrawModelWrapper.hxx>
39 #include <osl/diagnose.h>
41 #include <svx/svdoutl.hxx>
42 #include <svx/svxdlg.hxx>
43 #include <svx/svxids.hrc>
44 #include <editeng/editids.hrc>
45 #include <vcl/svapp.hxx>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/XPropertySetInfo.hpp>
48 #include <com/sun/star/text/XTextCursor.hpp>
49 #include <com/sun/star/chart2/FormattedString.hpp>
50 #include <svl/stritem.hxx>
51 #include <editeng/fontitem.hxx>
52 #include <editeng/section.hxx>
57 using namespace ::com::sun::star
;
59 void ChartController::executeDispatch_EditText( const Point
* pMousePixel
)
61 StartTextEdit( pMousePixel
);
64 void ChartController::StartTextEdit( const Point
* pMousePixel
)
66 //the first marked object will be edited
68 SolarMutexGuard aGuard
;
69 SdrObject
* pTextObj
= m_pDrawViewWrapper
->getTextEditObject();
73 OSL_PRECOND(!m_pTextActionUndoGuard
,
74 "ChartController::StartTextEdit: already have a TextUndoGuard!?");
75 m_pTextActionUndoGuard
.reset( new UndoGuard(
76 SchResId( STR_ACTION_EDIT_TEXT
), m_xUndoManager
) );
77 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
79 //#i77362 change notification for changes on additional shapes are missing
80 if( m_xChartView
.is() )
81 m_xChartView
->setPropertyValue( u
"SdrViewIsInEditMode"_ustr
, uno::Any(true) );
83 auto pChartWindow(GetChartWindow());
85 bool bEdit
= m_pDrawViewWrapper
->SdrBeginTextEdit( pTextObj
86 , m_pDrawViewWrapper
->GetPageView()
90 , nullptr //pOutlinerView
91 , true //bDontDeleteOutliner
97 m_pDrawViewWrapper
->SetEditMode();
99 // #i12587# support for shapes in chart
102 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
105 MouseEvent
aEditEvt( *pMousePixel
, 1, MouseEventModifiers::SYNTHETIC
, MOUSE_LEFT
, 0 );
106 pOutlinerView
->MouseButtonDown( aEditEvt
);
107 pOutlinerView
->MouseButtonUp( aEditEvt
);
113 //we invalidate the outliner region because the outliner has some
114 //paint problems (some characters are painted twice a little bit shifted)
115 pChartWindow
->Invalidate( m_pDrawViewWrapper
->GetMarkedObjBoundRect() );
119 bool ChartController::EndTextEdit()
121 m_pDrawViewWrapper
->SdrEndTextEdit();
123 //#i77362 change notification for changes on additional shapes are missing
124 if( m_xChartView
.is() )
125 m_xChartView
->setPropertyValue( u
"SdrViewIsInEditMode"_ustr
, uno::Any(false) );
127 SdrObject
* pTextObject
= m_pDrawViewWrapper
->getTextEditObject();
131 OutlinerParaObject
* pParaObj
= pTextObject
->GetOutlinerParaObject();
135 OUString aObjectCID
= m_aSelection
.getSelectedCID();
136 if ( !aObjectCID
.isEmpty() )
138 uno::Reference
< beans::XPropertySet
> xPropSet
=
139 ObjectIdentifier::getObjectPropertySet( aObjectCID
, getChartModel() );
141 // lock controllers till end of block
142 ControllerLockGuardUNO
aCLGuard( getChartModel() );
144 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > aNewFormattedTitle
=
145 GetFormattedTitle(pParaObj
->GetTextObject(), pTextObject
->getUnoShape());
147 Title
* pTitle
= dynamic_cast<Title
*>(xPropSet
.get());
148 TitleHelper::setFormattedString(pTitle
, aNewFormattedTitle
);
150 OSL_ENSURE(m_pTextActionUndoGuard
, "ChartController::EndTextEdit: no TextUndoGuard!");
151 if (m_pTextActionUndoGuard
)
152 m_pTextActionUndoGuard
->commit();
154 m_pTextActionUndoGuard
.reset();
158 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > ChartController::GetFormattedTitle(
159 const EditTextObject
& aEdit
, const uno::Reference
< drawing::XShape
>& xShape
)
161 std::vector
< uno::Reference
< chart2::XFormattedString
> > aNewStrings
;
163 return comphelper::containerToSequence(aNewStrings
);
165 uno::Reference
< text::XText
> xText(xShape
, uno::UNO_QUERY
);
167 return comphelper::containerToSequence(aNewStrings
);
169 uno::Reference
< text::XTextCursor
> xSelectionCursor(xText
->createTextCursor());
170 if (!xSelectionCursor
.is())
171 return comphelper::containerToSequence(aNewStrings
);
173 xSelectionCursor
->gotoStart(false);
175 std::vector
<editeng::Section
> aSecAttrs
;
176 aEdit
.GetAllSections(aSecAttrs
);
178 for (editeng::Section
const& rSection
: aSecAttrs
)
180 if (!xSelectionCursor
->isCollapsed())
181 xSelectionCursor
->collapseToEnd();
183 xSelectionCursor
->goRight(rSection
.mnEnd
- rSection
.mnStart
, true);
185 OUString aNewString
= xSelectionCursor
->getString();
187 bool bNextPara
= (aEdit
.GetParagraphCount() > 1 && rSection
.mnParagraph
!= aEdit
.GetParagraphCount() - 1 &&
188 aEdit
.GetTextLen(rSection
.mnParagraph
) <= rSection
.mnEnd
);
190 uno::Reference
< chart2::XFormattedString2
> xFmtStr
= chart2::FormattedString::create(m_xCC
);
192 aNewString
= aNewString
+ OUStringChar('\n');
193 xFmtStr
->setString(aNewString
);
194 aNewStrings
.emplace_back(xFmtStr
);
196 uno::Reference
< beans::XPropertySetInfo
> xInfo
= xFmtStr
->getPropertySetInfo();
197 uno::Reference
< beans::XPropertySet
> xSelectionProp(xSelectionCursor
, uno::UNO_QUERY
);
200 for (const beans::Property
& rProp
: xSelectionProp
->getPropertySetInfo()->getProperties())
202 if (xInfo
.is() && xInfo
->hasPropertyByName(rProp
.Name
))
204 const uno::Any aValue
= xSelectionProp
->getPropertyValue(rProp
.Name
);
205 xFmtStr
->setPropertyValue(rProp
.Name
, aValue
);
209 catch ( const uno::Exception
& )
211 DBG_UNHANDLED_EXCEPTION("chart2");
216 xSelectionCursor
->goRight(1, false); // next paragraph
219 return comphelper::containerToSequence(aNewStrings
);
222 void ChartController::executeDispatch_InsertSpecialCharacter()
224 SolarMutexGuard aGuard
;
225 if( !m_pDrawViewWrapper
)
227 OSL_ENSURE( m_pDrawViewWrapper
, "No DrawViewWrapper for ChartController" );
230 if( !m_pDrawViewWrapper
->IsTextEdit() )
233 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
235 SfxAllItemSet
aSet( m_pDrawModelWrapper
->GetItemPool() );
236 aSet
.Put( SfxBoolItem( FN_PARAM_1
, false ) );
238 //set fixed current font
239 aSet
.Put( SfxBoolItem( FN_PARAM_2
, true ) ); //maybe not necessary in future
241 vcl::Font aCurFont
= m_pDrawViewWrapper
->getOutliner()->GetRefDevice()->GetFont();
242 aSet
.Put( SvxFontItem( aCurFont
.GetFamilyType(), aCurFont
.GetFamilyName(), aCurFont
.GetStyleName(), aCurFont
.GetPitch(), aCurFont
.GetCharSet(), SID_ATTR_CHAR_FONT
) );
244 VclPtr
<SfxAbstractDialog
> pDlg(pFact
->CreateCharMapDialog(GetChartFrame(), aSet
, nullptr));
245 pDlg
->StartExecuteAsync(
246 [this, pDlg
] (sal_Int32 nResult
)->void
248 if (nResult
== RET_OK
)
250 const SfxItemSet
* pSet
= pDlg
->GetOutputItemSet();
253 if (const SfxStringItem
* pCharMapItem
= pSet
->GetItemIfSet(SID_CHARMAP
))
254 aString
= pCharMapItem
->GetValue();
256 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
257 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
259 if(pOutliner
&& pOutlinerView
)
261 // insert string to outliner
264 pOutlinerView
->HideCursor();
265 pOutliner
->SetUpdateLayout(false);
267 // delete current selection by inserting empty String, so current
268 // attributes become unique (sel. has to be erased anyway)
269 pOutlinerView
->InsertText(OUString());
271 pOutlinerView
->InsertText(aString
, true);
273 ESelection aSel
= pOutlinerView
->GetSelection();
274 aSel
.CollapseToEnd();
275 pOutlinerView
->SetSelection(aSel
);
278 pOutliner
->SetUpdateLayout(true);
279 pOutlinerView
->ShowCursor();
288 rtl::Reference
< ::chart::AccessibleTextHelper
>
289 ChartController::createAccessibleTextContext()
291 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
292 return new AccessibleTextHelper( m_pDrawViewWrapper
.get() );
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */