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 <ChartController.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/svdotext.hxx>
34 #include <svx/svdoutl.hxx>
35 #include <svx/svxdlg.hxx>
36 #include <svx/dialogs.hrc>
37 #include <vcl/svapp.hxx>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <svl/stritem.hxx>
40 #include <editeng/fontitem.hxx>
45 using namespace ::com::sun::star
;
47 void ChartController::executeDispatch_EditText( const Point
* pMousePixel
)
49 StartTextEdit( pMousePixel
);
52 void ChartController::StartTextEdit( const Point
* pMousePixel
)
54 //the first marked object will be edited
56 SolarMutexGuard aGuard
;
57 SdrObject
* pTextObj
= m_pDrawViewWrapper
->getTextEditObject();
61 OSL_PRECOND( !m_pTextActionUndoGuard
.get(), "ChartController::StartTextEdit: already have a TextUndoGuard!?" );
62 m_pTextActionUndoGuard
.reset( new UndoGuard(
63 SchResId( STR_ACTION_EDIT_TEXT
), m_xUndoManager
) );
64 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
66 //#i77362 change notification for changes on additional shapes are missing
67 uno::Reference
< beans::XPropertySet
> xChartViewProps( m_xChartView
, uno::UNO_QUERY
);
68 if( xChartViewProps
.is() )
69 xChartViewProps
->setPropertyValue( "SdrViewIsInEditMode", uno::Any(true) );
71 bool bEdit
= m_pDrawViewWrapper
->SdrBeginTextEdit( pTextObj
72 , m_pDrawViewWrapper
->GetPageView()
76 , nullptr //pOutlinerView
77 , true //bDontDeleteOutliner
82 m_pDrawViewWrapper
->SetEditMode();
84 // #i12587# support for shapes in chart
87 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
90 MouseEvent
aEditEvt( *pMousePixel
, 1, MouseEventModifiers::SYNTHETIC
, MOUSE_LEFT
, 0 );
91 pOutlinerView
->MouseButtonDown( aEditEvt
);
92 pOutlinerView
->MouseButtonUp( aEditEvt
);
96 //we invalidate the outliner region because the outliner has some
97 //paint problems (some characters are painted twice a little bit shifted)
98 GetChartWindow()->Invalidate( m_pDrawViewWrapper
->GetMarkedObjBoundRect() );
102 bool ChartController::EndTextEdit()
104 m_pDrawViewWrapper
->SdrEndTextEdit();
106 //#i77362 change notification for changes on additional shapes are missing
107 uno::Reference
< beans::XPropertySet
> xChartViewProps( m_xChartView
, uno::UNO_QUERY
);
108 if( xChartViewProps
.is() )
109 xChartViewProps
->setPropertyValue( "SdrViewIsInEditMode", uno::Any(false) );
111 SdrObject
* pTextObject
= m_pDrawViewWrapper
->getTextEditObject();
115 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
116 OutlinerParaObject
* pParaObj
= pTextObject
->GetOutlinerParaObject();
117 if( pParaObj
&& pOutliner
)
119 pOutliner
->SetText( *pParaObj
);
121 OUString aString
= pOutliner
->GetText(
122 pOutliner
->GetParagraph( 0 ),
123 pOutliner
->GetParagraphCount() );
125 OUString aObjectCID
= m_aSelection
.getSelectedCID();
126 if ( !aObjectCID
.isEmpty() )
128 uno::Reference
< beans::XPropertySet
> xPropSet
=
129 ObjectIdentifier::getObjectPropertySet( aObjectCID
, getModel() );
131 // lock controllers till end of block
132 ControllerLockGuardUNO
aCLGuard( getModel() );
134 TitleHelper::setCompleteString( aString
, uno::Reference
<
135 css::chart2::XTitle
>::query( xPropSet
), m_xCC
);
137 OSL_ENSURE( m_pTextActionUndoGuard
.get(), "ChartController::EndTextEdit: no TextUndoGuard!" );
138 if ( m_pTextActionUndoGuard
.get() )
139 m_pTextActionUndoGuard
->commit();
141 m_pTextActionUndoGuard
.reset();
146 void ChartController::executeDispatch_InsertSpecialCharacter()
148 SolarMutexGuard aGuard
;
149 if( !m_pDrawViewWrapper
)
151 OSL_ENSURE( m_pDrawViewWrapper
, "No DrawViewWrapper for ChartController" );
154 if( !m_pDrawViewWrapper
->IsTextEdit() )
157 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
158 OSL_ENSURE( pFact
, "No dialog factory" );
160 SfxAllItemSet
aSet( m_pDrawModelWrapper
->GetItemPool() );
161 aSet
.Put( SfxBoolItem( FN_PARAM_1
, false ) );
163 //set fixed current font
164 aSet
.Put( SfxBoolItem( FN_PARAM_2
, true ) ); //maybe not necessary in future
166 vcl::Font aCurFont
= m_pDrawViewWrapper
->getOutliner()->GetRefDevice()->GetFont();
167 aSet
.Put( SvxFontItem( aCurFont
.GetFamilyType(), aCurFont
.GetFamilyName(), aCurFont
.GetStyleName(), aCurFont
.GetPitch(), aCurFont
.GetCharSet(), SID_ATTR_CHAR_FONT
) );
169 vcl::Window
* pWin
= GetChartWindow();
170 ScopedVclPtr
<SfxAbstractDialog
> pDlg(pFact
->CreateCharMapDialog(pWin
? pWin
->GetFrameWeld() : nullptr, aSet
, false));
171 OSL_ENSURE( pDlg
, "Couldn't create SvxCharacterMap dialog" );
172 if( pDlg
->Execute() == RET_OK
)
174 const SfxItemSet
* pSet
= pDlg
->GetOutputItemSet();
175 const SfxPoolItem
* pItem
=nullptr;
177 if ( pSet
&& pSet
->GetItemState( SID_CHARMAP
, true, &pItem
) == SfxItemState::SET
&&
178 dynamic_cast< const SfxStringItem
* >(pItem
) != nullptr )
179 aString
= dynamic_cast<const SfxStringItem
*>(pItem
)->GetValue();
181 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
182 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
184 if(!pOutliner
|| !pOutlinerView
)
187 // insert string to outliner
190 pOutlinerView
->HideCursor();
191 pOutliner
->SetUpdateMode(false);
193 // delete current selection by inserting empty String, so current
194 // attributes become unique (sel. has to be erased anyway)
195 pOutlinerView
->InsertText(OUString());
197 pOutlinerView
->InsertText(aString
, true);
199 ESelection aSel
= pOutlinerView
->GetSelection();
200 aSel
.nStartPara
= aSel
.nEndPara
;
201 aSel
.nStartPos
= aSel
.nEndPos
;
202 pOutlinerView
->SetSelection(aSel
);
205 pOutliner
->SetUpdateMode(true);
206 pOutlinerView
->ShowCursor();
210 uno::Reference
< css::accessibility::XAccessibleContext
>
211 ChartController::impl_createAccessibleTextContext()
213 uno::Reference
< css::accessibility::XAccessibleContext
> xResult(
214 new AccessibleTextHelper( m_pDrawViewWrapper
));
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */