LibreOffice Module chart2 (master) 1
ChartController_TextEdit.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_wasm_strip.h>
21
22#include <ChartController.hxx>
23
24#include <ResId.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>
33#if !ENABLE_WASM_STRIP_ACCESSIBILITY
34#include <AccessibleTextHelper.hxx>
35#endif
36#include <strings.hrc>
38#include <osl/diagnose.h>
39
40#include <svx/svdoutl.hxx>
41#include <svx/svxdlg.hxx>
42#include <svx/svxids.hrc>
43#include <editeng/editids.hrc>
44#include <vcl/svapp.hxx>
45#include <com/sun/star/beans/XPropertySet.hpp>
46#include <com/sun/star/chart2/XTitle.hpp>
47#include <svl/stritem.hxx>
48#include <editeng/fontitem.hxx>
49#include <memory>
50
51namespace chart
52{
53using namespace ::com::sun::star;
54
56{
57 StartTextEdit( pMousePixel );
58}
59
60void ChartController::StartTextEdit( const Point* pMousePixel )
61{
62 //the first marked object will be edited
63
64 SolarMutexGuard aGuard;
65 SdrObject* pTextObj = m_pDrawViewWrapper->getTextEditObject();
66 if(!pTextObj)
67 return;
68
69 OSL_PRECOND(!m_pTextActionUndoGuard,
70 "ChartController::StartTextEdit: already have a TextUndoGuard!?");
72 SchResId( STR_ACTION_EDIT_TEXT ), m_xUndoManager ) );
73 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
74
75 //#i77362 change notification for changes on additional shapes are missing
76 if( m_xChartView.is() )
77 m_xChartView->setPropertyValue( "SdrViewIsInEditMode", uno::Any(true) );
78
79 auto pChartWindow(GetChartWindow());
80
81 bool bEdit = m_pDrawViewWrapper->SdrBeginTextEdit( pTextObj
82 , m_pDrawViewWrapper->GetPageView()
83 , pChartWindow
84 , false //bIsNewObj
85 , pOutliner
86 , nullptr //pOutlinerView
87 , true //bDontDeleteOutliner
88 , true //bOnlyOneView
89 );
90 if(!bEdit)
91 return;
92
93 m_pDrawViewWrapper->SetEditMode();
94
95 // #i12587# support for shapes in chart
96 if ( pMousePixel )
97 {
98 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
99 if ( pOutlinerView )
100 {
101 MouseEvent aEditEvt( *pMousePixel, 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0 );
102 pOutlinerView->MouseButtonDown( aEditEvt );
103 pOutlinerView->MouseButtonUp( aEditEvt );
104 }
105 }
106
107 if (pChartWindow)
108 {
109 //we invalidate the outliner region because the outliner has some
110 //paint problems (some characters are painted twice a little bit shifted)
111 pChartWindow->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
112 }
113}
114
116{
117 m_pDrawViewWrapper->SdrEndTextEdit();
118
119 //#i77362 change notification for changes on additional shapes are missing
120 if( m_xChartView.is() )
121 m_xChartView->setPropertyValue( "SdrViewIsInEditMode", uno::Any(false) );
122
123 SdrObject* pTextObject = m_pDrawViewWrapper->getTextEditObject();
124 if(!pTextObject)
125 return false;
126
127 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
128 OutlinerParaObject* pParaObj = pTextObject->GetOutlinerParaObject();
129 if( !pParaObj || !pOutliner )
130 return true;
131
132 pOutliner->SetText( *pParaObj );
133
134 OUString aString = pOutliner->GetText(
135 pOutliner->GetParagraph( 0 ),
136 pOutliner->GetParagraphCount() );
137
138 OUString aObjectCID = m_aSelection.getSelectedCID();
139 if ( !aObjectCID.isEmpty() )
140 {
143
144 // lock controllers till end of block
146
147 Title* pTitle = dynamic_cast<Title*>(xPropSet.get());
148 TitleHelper::setCompleteString( aString, pTitle, m_xCC );
149
150 OSL_ENSURE(m_pTextActionUndoGuard, "ChartController::EndTextEdit: no TextUndoGuard!");
152 m_pTextActionUndoGuard->commit();
153 }
155 return true;
156}
157
159{
160 SolarMutexGuard aGuard;
162 {
163 OSL_ENSURE( m_pDrawViewWrapper, "No DrawViewWrapper for ChartController" );
164 return;
165 }
166 if( !m_pDrawViewWrapper->IsTextEdit() )
168
170
171 SfxAllItemSet aSet( m_pDrawModelWrapper->GetItemPool() );
172 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
173
174 //set fixed current font
175 aSet.Put( SfxBoolItem( FN_PARAM_2, true ) ); //maybe not necessary in future
176
177 vcl::Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
178 aSet.Put( SvxFontItem( aCurFont.GetFamilyType(), aCurFont.GetFamilyName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );
179
181 if( pDlg->Execute() != RET_OK )
182 return;
183
184 const SfxItemSet* pSet = pDlg->GetOutputItemSet();
185 OUString aString;
186 if (pSet)
187 if (const SfxStringItem* pCharMapItem = pSet->GetItemIfSet(SID_CHARMAP))
188 aString = pCharMapItem->GetValue();
189
190 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
191 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
192
193 if(!pOutliner || !pOutlinerView)
194 return;
195
196 // insert string to outliner
197
198 // prevent flicker
199 pOutlinerView->HideCursor();
200 pOutliner->SetUpdateLayout(false);
201
202 // delete current selection by inserting empty String, so current
203 // attributes become unique (sel. has to be erased anyway)
204 pOutlinerView->InsertText(OUString());
205
206 pOutlinerView->InsertText(aString, true);
207
208 ESelection aSel = pOutlinerView->GetSelection();
209 aSel.nStartPara = aSel.nEndPara;
210 aSel.nStartPos = aSel.nEndPos;
211 pOutlinerView->SetSelection(aSel);
212
213 // show changes
214 pOutliner->SetUpdateLayout(true);
215 pOutlinerView->ShowCursor();
216}
217
220{
221#if !ENABLE_WASM_STRIP_ACCESSIBILITY
224
225 return xResult;
226#else
228#endif
229}
230
231} //namespace chart
232
233/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetSelection(const ESelection &)
bool MouseButtonUp(const MouseEvent &)
void InsertText(const OUString &rNew, bool bSelect=false)
void HideCursor(bool bDeactivate=false)
ESelection GetSelection() const
bool MouseButtonDown(const MouseEvent &)
void ShowCursor(bool bGotoCursor=true, bool bActivate=false)
virtual OutlinerParaObject * GetOutlinerParaObject() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual VclPtr< SfxAbstractDialog > CreateCharMapDialog(weld::Window *pParent, const SfxItemSet &rAttr, const css::uno::Reference< css::frame::XFrame > &rFrame)=0
static SvxAbstractDialogFactory * Create()
rtl::Reference<::chart::ChartModel > getChartModel()
std::unique_ptr< DrawViewWrapper > m_pDrawViewWrapper
css::uno::Reference< css::document::XUndoManager > m_xUndoManager
void executeDispatch_EditText(const Point *pMousePixel=nullptr)
ChartWindow * GetChartWindow() const
std::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper
void StartTextEdit(const Point *pMousePixel=nullptr)
rtl::Reference<::chart::ChartView > m_xChartView
weld::Window * GetChartFrame()
css::uno::Reference< css::accessibility::XAccessibleContext > impl_createAccessibleTextContext()
Creates a helper accessibility class that must be initialized via XInitialization.
std::unique_ptr< UndoGuard > m_pTextActionUndoGuard
css::uno::Reference< css::uno::XComponentContext > m_xCC
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static css::uno::Reference< css::beans::XPropertySet > getObjectPropertySet(std::u16string_view rObjectCID, const rtl::Reference< ::chart::ChartModel > &xChartDocument)
OUString const & getSelectedCID() const
static void setCompleteString(const OUString &rNewText, const rtl::Reference< ::chart::Title > &xTitle, const css::uno::Reference< css::uno::XComponentContext > &xContext, const float *pDefaultCharHeight=nullptr)
A guard which does nothing, unless you explicitly call commitAction.
Definition: UndoGuard.hxx:37
FontFamily GetFamilyType()
const OUString & GetStyleName() const
const OUString & GetFamilyName() const
FontPitch GetPitch()
rtl_TextEncoding GetCharSet() const
#define MOUSE_LEFT
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
sal_Int32 nStartPara
sal_Int32 nEndPos
sal_Int32 nStartPos
sal_Int32 nEndPara
RET_OK