Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / main / ChartController_TextEdit.cxx
blob57a687467fd624356f2bc68ee1dd63ef47ce6766
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 <ChartController.hxx>
22 #include <ResId.hxx>
23 #include "UndoGuard.hxx"
24 #include <DrawViewWrapper.hxx>
25 #include <ChartWindow.hxx>
26 #include <TitleHelper.hxx>
27 #include <ObjectIdentifier.hxx>
28 #include <ControllerLockGuard.hxx>
29 #include <AccessibleTextHelper.hxx>
30 #include <strings.hrc>
31 #include <chartview/DrawModelWrapper.hxx>
33 #include <svx/svdoutl.hxx>
34 #include <svx/svxdlg.hxx>
35 #include <svx/svxids.hrc>
36 #include <editeng/editids.hrc>
37 #include <vcl/svapp.hxx>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/chart2/XTitle.hpp>
40 #include <svl/stritem.hxx>
41 #include <editeng/fontitem.hxx>
42 #include <memory>
44 namespace chart
46 using namespace ::com::sun::star;
48 void ChartController::executeDispatch_EditText( const Point* pMousePixel )
50 StartTextEdit( pMousePixel );
53 void ChartController::StartTextEdit( const Point* pMousePixel )
55 //the first marked object will be edited
57 SolarMutexGuard aGuard;
58 SdrObject* pTextObj = m_pDrawViewWrapper->getTextEditObject();
59 if(!pTextObj)
60 return;
62 OSL_PRECOND(!m_pTextActionUndoGuard,
63 "ChartController::StartTextEdit: already have a TextUndoGuard!?");
64 m_pTextActionUndoGuard.reset( new UndoGuard(
65 SchResId( STR_ACTION_EDIT_TEXT ), m_xUndoManager ) );
66 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
68 //#i77362 change notification for changes on additional shapes are missing
69 uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
70 if( xChartViewProps.is() )
71 xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::Any(true) );
73 bool bEdit = m_pDrawViewWrapper->SdrBeginTextEdit( pTextObj
74 , m_pDrawViewWrapper->GetPageView()
75 , GetChartWindow()
76 , false //bIsNewObj
77 , pOutliner
78 , nullptr //pOutlinerView
79 , true //bDontDeleteOutliner
80 , true //bOnlyOneView
82 if(bEdit)
84 m_pDrawViewWrapper->SetEditMode();
86 // #i12587# support for shapes in chart
87 if ( pMousePixel )
89 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
90 if ( pOutlinerView )
92 MouseEvent aEditEvt( *pMousePixel, 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0 );
93 pOutlinerView->MouseButtonDown( aEditEvt );
94 pOutlinerView->MouseButtonUp( aEditEvt );
98 //we invalidate the outliner region because the outliner has some
99 //paint problems (some characters are painted twice a little bit shifted)
100 GetChartWindow()->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
104 bool ChartController::EndTextEdit()
106 m_pDrawViewWrapper->SdrEndTextEdit();
108 //#i77362 change notification for changes on additional shapes are missing
109 uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
110 if( xChartViewProps.is() )
111 xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::Any(false) );
113 SdrObject* pTextObject = m_pDrawViewWrapper->getTextEditObject();
114 if(!pTextObject)
115 return false;
117 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
118 OutlinerParaObject* pParaObj = pTextObject->GetOutlinerParaObject();
119 if( pParaObj && pOutliner )
121 pOutliner->SetText( *pParaObj );
123 OUString aString = pOutliner->GetText(
124 pOutliner->GetParagraph( 0 ),
125 pOutliner->GetParagraphCount() );
127 OUString aObjectCID = m_aSelection.getSelectedCID();
128 if ( !aObjectCID.isEmpty() )
130 uno::Reference< beans::XPropertySet > xPropSet =
131 ObjectIdentifier::getObjectPropertySet( aObjectCID, getModel() );
133 // lock controllers till end of block
134 ControllerLockGuardUNO aCLGuard( getModel() );
136 TitleHelper::setCompleteString( aString, uno::Reference<
137 css::chart2::XTitle >::query( xPropSet ), m_xCC );
139 OSL_ENSURE(m_pTextActionUndoGuard, "ChartController::EndTextEdit: no TextUndoGuard!");
140 if (m_pTextActionUndoGuard)
141 m_pTextActionUndoGuard->commit();
143 m_pTextActionUndoGuard.reset();
145 return true;
148 void ChartController::executeDispatch_InsertSpecialCharacter()
150 SolarMutexGuard aGuard;
151 if( !m_pDrawViewWrapper)
153 OSL_ENSURE( m_pDrawViewWrapper, "No DrawViewWrapper for ChartController" );
154 return;
156 if( !m_pDrawViewWrapper->IsTextEdit() )
157 StartTextEdit();
159 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
161 SfxAllItemSet aSet( m_pDrawModelWrapper->GetItemPool() );
162 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
164 //set fixed current font
165 aSet.Put( SfxBoolItem( FN_PARAM_2, true ) ); //maybe not necessary in future
167 vcl::Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
168 aSet.Put( SvxFontItem( aCurFont.GetFamilyType(), aCurFont.GetFamilyName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );
170 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(GetChartFrame(), aSet, nullptr));
171 if( pDlg->Execute() == RET_OK )
173 const SfxItemSet* pSet = pDlg->GetOutputItemSet();
174 const SfxPoolItem* pItem=nullptr;
175 OUString aString;
176 if (pSet && pSet->GetItemState(SID_CHARMAP, true, &pItem) == SfxItemState::SET)
177 if (auto pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
178 aString = pStringItem->GetValue();
180 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
181 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
183 if(!pOutliner || !pOutlinerView)
184 return;
186 // insert string to outliner
188 // prevent flicker
189 pOutlinerView->HideCursor();
190 pOutliner->SetUpdateMode(false);
192 // delete current selection by inserting empty String, so current
193 // attributes become unique (sel. has to be erased anyway)
194 pOutlinerView->InsertText(OUString());
196 pOutlinerView->InsertText(aString, true);
198 ESelection aSel = pOutlinerView->GetSelection();
199 aSel.nStartPara = aSel.nEndPara;
200 aSel.nStartPos = aSel.nEndPos;
201 pOutlinerView->SetSelection(aSel);
203 // show changes
204 pOutliner->SetUpdateMode(true);
205 pOutlinerView->ShowCursor();
209 uno::Reference< css::accessibility::XAccessibleContext >
210 ChartController::impl_createAccessibleTextContext()
212 uno::Reference< css::accessibility::XAccessibleContext > xResult(
213 new AccessibleTextHelper( m_pDrawViewWrapper.get() ));
215 return xResult;
218 } //namespace chart
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */