fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / main / ChartController_TextEdit.cxx
blob5fe2635fc021291933e67103218ba05109f639cc
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 "macros.hxx"
29 #include "ControllerLockGuard.hxx"
30 #include "AccessibleTextHelper.hxx"
31 #include "Strings.hrc"
32 #include "chartview/DrawModelWrapper.hxx"
34 #include <svx/svdotext.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <svx/svdoutl.hxx>
37 #include <svx/svxdlg.hxx>
38 #include <svx/dialogs.hrc>
39 #include <vcl/svapp.hxx>
40 #include <osl/mutex.hxx>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <svl/stritem.hxx>
43 #include <editeng/fontitem.hxx>
44 #include <boost/scoped_ptr.hpp>
46 namespace chart
48 using namespace ::com::sun::star;
50 void ChartController::executeDispatch_EditText( const Point* pMousePixel )
52 this->StartTextEdit( pMousePixel );
55 void ChartController::StartTextEdit( const Point* pMousePixel )
57 //the first marked object will be edited
59 SolarMutexGuard aGuard;
60 SdrObject* pTextObj = m_pDrawViewWrapper->getTextEditObject();
61 if(!pTextObj)
62 return;
64 OSL_PRECOND( !m_pTextActionUndoGuard.get(), "ChartController::StartTextEdit: already have a TextUndoGuard!?" );
65 m_pTextActionUndoGuard.reset( new UndoGuard(
66 SCH_RESSTR( STR_ACTION_EDIT_TEXT ), m_xUndoManager ) );
67 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
69 //#i77362 change notification for changes on additional shapes are missing
70 uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
71 if( xChartViewProps.is() )
72 xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::makeAny(sal_True) );
74 bool bEdit = m_pDrawViewWrapper->SdrBeginTextEdit( pTextObj
75 , m_pDrawViewWrapper->GetPageView()
76 , m_pChartWindow
77 , false //bIsNewObj
78 , pOutliner
79 , 0L //pOutlinerView
80 , true //bDontDeleteOutliner
81 , true //bOnlyOneView
83 if(bEdit)
85 m_pDrawViewWrapper->SetEditMode();
87 // #i12587# support for shapes in chart
88 if ( pMousePixel )
90 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
91 if ( pOutlinerView )
93 MouseEvent aEditEvt( *pMousePixel, 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0 );
94 pOutlinerView->MouseButtonDown( aEditEvt );
95 pOutlinerView->MouseButtonUp( aEditEvt );
99 //we invalidate the outliner region because the outliner has some
100 //paint problems (some characters are painted twice a little bit shifted)
101 m_pChartWindow->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
105 bool ChartController::EndTextEdit()
107 m_pDrawViewWrapper->SdrEndTextEdit();
109 //#i77362 change notification for changes on additional shapes are missing
110 uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
111 if( xChartViewProps.is() )
112 xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::makeAny(sal_False) );
114 SdrObject* pTextObject = m_pDrawViewWrapper->getTextEditObject();
115 if(!pTextObject)
116 return false;
118 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
119 OutlinerParaObject* pParaObj = pTextObject->GetOutlinerParaObject();
120 if( pParaObj && pOutliner )
122 pOutliner->SetText( *pParaObj );
124 OUString aString = pOutliner->GetText(
125 pOutliner->GetParagraph( 0 ),
126 pOutliner->GetParagraphCount() );
128 OUString aObjectCID = m_aSelection.getSelectedCID();
129 if ( !aObjectCID.isEmpty() )
131 uno::Reference< beans::XPropertySet > xPropSet =
132 ObjectIdentifier::getObjectPropertySet( aObjectCID, getModel() );
134 // lock controllers till end of block
135 ControllerLockGuardUNO aCLGuard( getModel() );
137 TitleHelper::setCompleteString( aString, uno::Reference<
138 ::com::sun::star::chart2::XTitle >::query( xPropSet ), m_xCC );
140 OSL_ENSURE( m_pTextActionUndoGuard.get(), "ChartController::EndTextEdit: no TextUndoGuard!" );
141 if ( m_pTextActionUndoGuard.get() )
142 m_pTextActionUndoGuard->commit();
144 m_pTextActionUndoGuard.reset();
146 return true;
149 void ChartController::executeDispatch_InsertSpecialCharacter()
151 SolarMutexGuard aGuard;
152 if( !m_pDrawViewWrapper)
154 OSL_ENSURE( m_pDrawViewWrapper, "No DrawViewWrapper for ChartController" );
155 return;
157 if( !m_pDrawViewWrapper->IsTextEdit() )
158 this->StartTextEdit();
160 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
161 OSL_ENSURE( pFact, "No dialog factory" );
163 SfxAllItemSet aSet( m_pDrawModelWrapper->GetItemPool() );
164 aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
166 //set fixed current font
167 aSet.Put( SfxBoolItem( FN_PARAM_2, true ) ); //maybe not necessary in future
169 vcl::Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
170 aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );
172 boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( m_pChartWindow, aSet, getFrame(), RID_SVXDLG_CHARMAP ));
173 OSL_ENSURE( pDlg, "Couldn't create SvxCharacterMap dialog" );
174 if( pDlg->Execute() == RET_OK )
176 const SfxItemSet* pSet = pDlg->GetOutputItemSet();
177 const SfxPoolItem* pItem=0;
178 OUString aString;
179 if ( pSet && pSet->GetItemState( SID_CHARMAP, true, &pItem) == SfxItemState::SET &&
180 pItem->ISA(SfxStringItem) )
181 aString = dynamic_cast<const SfxStringItem*>(pItem)->GetValue();
183 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
184 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
186 if(!pOutliner || !pOutlinerView)
187 return;
189 // insert string to outliner
191 // prevent flicker
192 pOutlinerView->HideCursor();
193 pOutliner->SetUpdateMode(false);
195 // delete current selection by inserting empty String, so current
196 // attributes become unique (sel. has to be erased anyway)
197 pOutlinerView->InsertText(OUString());
199 pOutlinerView->InsertText(aString, true);
201 ESelection aSel = pOutlinerView->GetSelection();
202 aSel.nStartPara = aSel.nEndPara;
203 aSel.nStartPos = aSel.nEndPos;
204 pOutlinerView->SetSelection(aSel);
206 // show changes
207 pOutliner->SetUpdateMode(true);
208 pOutlinerView->ShowCursor();
212 uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
213 ChartController::impl_createAccessibleTextContext()
215 uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xResult(
216 new AccessibleTextHelper( m_pDrawViewWrapper ));
218 return xResult;
221 } //namespace chart
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */