Line data Source code
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 "ChartController.hxx"
21 :
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"
33 :
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>
45 :
46 : namespace chart
47 : {
48 : using namespace ::com::sun::star;
49 :
50 0 : void ChartController::executeDispatch_EditText( const Point* pMousePixel )
51 : {
52 0 : this->StartTextEdit( pMousePixel );
53 0 : }
54 :
55 0 : void ChartController::StartTextEdit( const Point* pMousePixel )
56 : {
57 : //the first marked object will be edited
58 :
59 0 : SolarMutexGuard aGuard;
60 0 : SdrObject* pTextObj = m_pDrawViewWrapper->getTextEditObject();
61 0 : if(!pTextObj)
62 0 : return;
63 :
64 : OSL_PRECOND( !m_pTextActionUndoGuard.get(), "ChartController::StartTextEdit: already have a TextUndoGuard!?" );
65 : m_pTextActionUndoGuard.reset( new UndoGuard(
66 0 : SCH_RESSTR( STR_ACTION_EDIT_TEXT ), m_xUndoManager ) );
67 0 : SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
68 :
69 : //#i77362 change notification for changes on additional shapes are missing
70 0 : uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
71 0 : if( xChartViewProps.is() )
72 0 : xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::makeAny(sal_True) );
73 :
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
82 0 : );
83 0 : if(bEdit)
84 : {
85 0 : m_pDrawViewWrapper->SetEditMode();
86 :
87 : // #i12587# support for shapes in chart
88 0 : if ( pMousePixel )
89 : {
90 0 : OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
91 0 : if ( pOutlinerView )
92 : {
93 0 : MouseEvent aEditEvt( *pMousePixel, 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
94 0 : pOutlinerView->MouseButtonDown( aEditEvt );
95 0 : pOutlinerView->MouseButtonUp( aEditEvt );
96 : }
97 : }
98 :
99 : //we invalidate the outliner region because the outliner has some
100 : //paint problems (some characters are painted twice a little bit shifted)
101 0 : m_pChartWindow->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
102 0 : }
103 : }
104 :
105 0 : bool ChartController::EndTextEdit()
106 : {
107 0 : m_pDrawViewWrapper->SdrEndTextEdit();
108 :
109 : //#i77362 change notification for changes on additional shapes are missing
110 0 : uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
111 0 : if( xChartViewProps.is() )
112 0 : xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::makeAny(sal_False) );
113 :
114 0 : SdrObject* pTextObject = m_pDrawViewWrapper->getTextEditObject();
115 0 : if(!pTextObject)
116 0 : return false;
117 :
118 0 : SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
119 0 : OutlinerParaObject* pParaObj = pTextObject->GetOutlinerParaObject();
120 0 : if( pParaObj && pOutliner )
121 : {
122 0 : pOutliner->SetText( *pParaObj );
123 :
124 : OUString aString = pOutliner->GetText(
125 : pOutliner->GetParagraph( 0 ),
126 0 : pOutliner->GetParagraphCount() );
127 :
128 0 : OUString aObjectCID = m_aSelection.getSelectedCID();
129 0 : if ( !aObjectCID.isEmpty() )
130 : {
131 : uno::Reference< beans::XPropertySet > xPropSet =
132 0 : ObjectIdentifier::getObjectPropertySet( aObjectCID, getModel() );
133 :
134 : // lock controllers till end of block
135 0 : ControllerLockGuardUNO aCLGuard( getModel() );
136 :
137 : TitleHelper::setCompleteString( aString, uno::Reference<
138 0 : ::com::sun::star::chart2::XTitle >::query( xPropSet ), m_xCC );
139 :
140 : OSL_ENSURE( m_pTextActionUndoGuard.get(), "ChartController::EndTextEdit: no TextUndoGuard!" );
141 0 : if ( m_pTextActionUndoGuard.get() )
142 0 : m_pTextActionUndoGuard->commit();
143 : }
144 0 : m_pTextActionUndoGuard.reset();
145 : }
146 0 : return true;
147 : }
148 :
149 0 : void ChartController::executeDispatch_InsertSpecialCharacter()
150 : {
151 0 : SolarMutexGuard aGuard;
152 0 : if( !m_pDrawViewWrapper)
153 : {
154 : OSL_ENSURE( m_pDrawViewWrapper, "No DrawViewWrapper for ChartController" );
155 0 : return;
156 : }
157 0 : if( !m_pDrawViewWrapper->IsTextEdit() )
158 0 : this->StartTextEdit();
159 :
160 0 : SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
161 : OSL_ENSURE( pFact, "No dialog factory" );
162 :
163 0 : SfxAllItemSet aSet( m_pDrawModelWrapper->GetItemPool() );
164 0 : aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
165 :
166 : //set fixed current font
167 0 : aSet.Put( SfxBoolItem( FN_PARAM_2, true ) ); //maybe not necessary in future
168 :
169 0 : vcl::Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
170 0 : aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );
171 :
172 0 : boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( m_pChartWindow, aSet, getFrame(), RID_SVXDLG_CHARMAP ));
173 : OSL_ENSURE( pDlg, "Couldn't create SvxCharacterMap dialog" );
174 0 : if( pDlg->Execute() == RET_OK )
175 : {
176 0 : const SfxItemSet* pSet = pDlg->GetOutputItemSet();
177 0 : const SfxPoolItem* pItem=0;
178 0 : OUString aString;
179 0 : if ( pSet && pSet->GetItemState( SID_CHARMAP, true, &pItem) == SfxItemState::SET &&
180 0 : pItem->ISA(SfxStringItem) )
181 0 : aString = dynamic_cast<const SfxStringItem*>(pItem)->GetValue();
182 :
183 0 : OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
184 0 : SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
185 :
186 0 : if(!pOutliner || !pOutlinerView)
187 0 : return;
188 :
189 : // insert string to outliner
190 :
191 : // prevent flicker
192 0 : pOutlinerView->HideCursor();
193 0 : pOutliner->SetUpdateMode(false);
194 :
195 : // delete current selection by inserting empty String, so current
196 : // attributes become unique (sel. has to be erased anyway)
197 0 : pOutlinerView->InsertText(OUString());
198 :
199 0 : pOutlinerView->InsertText(aString, true);
200 :
201 0 : ESelection aSel = pOutlinerView->GetSelection();
202 0 : aSel.nStartPara = aSel.nEndPara;
203 0 : aSel.nStartPos = aSel.nEndPos;
204 0 : pOutlinerView->SetSelection(aSel);
205 :
206 : // show changes
207 0 : pOutliner->SetUpdateMode(true);
208 0 : pOutlinerView->ShowCursor();
209 0 : }
210 : }
211 :
212 : uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
213 0 : ChartController::impl_createAccessibleTextContext()
214 : {
215 : uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xResult(
216 0 : new AccessibleTextHelper( m_pDrawViewWrapper ));
217 :
218 0 : return xResult;
219 : }
220 :
221 102 : } //namespace chart
222 :
223 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|