1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "ChartController.hxx"
27
28 #include "ResId.hxx"
29 #include "UndoGuard.hxx"
30 #include "DrawViewWrapper.hxx"
31 #include "ChartWindow.hxx"
32 #include "TitleHelper.hxx"
33 #include "ObjectIdentifier.hxx"
34 #include "macros.hxx"
35 #include "ControllerLockGuard.hxx"
36 #include "AccessibleTextHelper.hxx"
37 #include "Strings.hrc"
38 #include "chartview/DrawModelWrapper.hxx"
39
40 #include <svx/svdotext.hxx>
41
42 // header for define RET_OK
43 #include <vcl/msgbox.hxx>
44 // header for class SdrOutliner
45 #include <svx/svdoutl.hxx>
46 #include <svx/svxdlg.hxx>
47 #ifndef _SVX_DIALOGS_HRC
48 #include <svx/dialogs.hrc>
49 #endif
50 #include <vcl/svapp.hxx>
51 #include <vos/mutex.hxx>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <svl/stritem.hxx>
54 #include <editeng/fontitem.hxx>
55
56 //.............................................................................
57 namespace chart
58 {
59 //.............................................................................
60 using namespace ::com::sun::star;
61 //using namespace ::com::sun::star::chart2;
62
63 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
65
executeDispatch_EditText(const Point * pMousePixel)66 void SAL_CALL ChartController::executeDispatch_EditText( const Point* pMousePixel )
67 {
68 this->StartTextEdit( pMousePixel );
69 }
70
71 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
73
StartTextEdit(const Point * pMousePixel)74 void ChartController::StartTextEdit( const Point* pMousePixel )
75 {
76 //the first marked object will be edited
77
78 ::vos::OGuard aGuard( Application::GetSolarMutex() );
79 SdrObject* pTextObj = m_pDrawViewWrapper->getTextEditObject();
80 if(!pTextObj)
81 return;
82
83 OSL_PRECOND( !m_pTextActionUndoGuard.get(), "ChartController::StartTextEdit: already have a TextUndoGuard!?" );
84 m_pTextActionUndoGuard.reset( new UndoGuard(
85 String( SchResId( STR_ACTION_EDIT_TEXT ) ), m_xUndoManager ) );
86 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
87 //pOutliner->SetRefDevice(m_pChartWindow);
88 //pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)pStyleSheetPool);
89 //pOutliner->SetDefaultLanguage( eLang );
90 //pOutliner->SetHyphenator( xHyphenator );
91
92 //#i77362 change notification for changes on additional shapes are missing
93 uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
94 if( xChartViewProps.is() )
95 xChartViewProps->setPropertyValue( C2U("SdrViewIsInEditMode"), uno::makeAny(sal_True) );
96
97 sal_Bool bEdit = m_pDrawViewWrapper->SdrBeginTextEdit( pTextObj
98 , m_pDrawViewWrapper->GetPageView()
99 , m_pChartWindow
100 , sal_False //bIsNewObj
101 , pOutliner
102 , 0L //pOutlinerView
103 , sal_True //bDontDeleteOutliner
104 , sal_True //bOnlyOneView
105 );
106 if(bEdit)
107 {
108 // set undo manager at topmost shell ( SdDrawTextObjectBar )
109 /*
110 if( pViewSh )
111 pViewSh->GetViewFrame()->GetDispatcher()->GetShell( 0 )->
112 SetUndoManager(&pOutliner->GetUndoManager());
113 */
114 m_pDrawViewWrapper->SetEditMode();
115
116 // #i12587# support for shapes in chart
117 if ( pMousePixel )
118 {
119 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
120 if ( pOutlinerView )
121 {
122 MouseEvent aEditEvt( *pMousePixel, 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
123 pOutlinerView->MouseButtonDown( aEditEvt );
124 pOutlinerView->MouseButtonUp( aEditEvt );
125 }
126 }
127
128 //we invalidate the outliner region because the outliner has some
129 //paint problems (some characters are painted twice a little bit shifted)
130 m_pChartWindow->Invalidate( m_pDrawViewWrapper->GetMarkedObjBoundRect() );
131 }
132 }
133
EndTextEdit()134 bool ChartController::EndTextEdit()
135 {
136 m_pDrawViewWrapper->SdrEndTextEdit();
137
138 //#i77362 change notification for changes on additional shapes are missing
139 uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
140 if( xChartViewProps.is() )
141 xChartViewProps->setPropertyValue( C2U("SdrViewIsInEditMode"), uno::makeAny(sal_False) );
142
143 SdrObject* pTextObject = m_pDrawViewWrapper->getTextEditObject();
144 if(!pTextObject)
145 return false;
146
147 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
148 OutlinerParaObject* pParaObj = pTextObject->GetOutlinerParaObject();
149 if( pParaObj && pOutliner )
150 {
151 pOutliner->SetText( *pParaObj );
152
153 String aString = pOutliner->GetText(
154 pOutliner->GetParagraph( 0 ),
155 pOutliner->GetParagraphCount() );
156
157 ::rtl::OUString aObjectCID = m_aSelection.getSelectedCID();
158 if ( !aObjectCID.isEmpty() )
159 {
160 uno::Reference< beans::XPropertySet > xPropSet =
161 ObjectIdentifier::getObjectPropertySet( aObjectCID, getModel() );
162
163 // lock controllers till end of block
164 ControllerLockGuard aCLGuard( getModel() );
165
166 TitleHelper::setCompleteString( aString, uno::Reference<
167 ::com::sun::star::chart2::XTitle >::query( xPropSet ), m_xCC );
168
169 OSL_ENSURE( m_pTextActionUndoGuard.get(), "ChartController::EndTextEdit: no TextUndoGuard!" );
170 if ( m_pTextActionUndoGuard.get() )
171 m_pTextActionUndoGuard->commit();
172 }
173 m_pTextActionUndoGuard.reset();
174 }
175 return true;
176 }
177
178 //-----------------------------------------------------------------------------
179 //-----------------------------------------------------------------------------
180
executeDispatch_InsertSpecialCharacter()181 void SAL_CALL ChartController::executeDispatch_InsertSpecialCharacter()
182 {
183 ::vos::OGuard aGuard( Application::GetSolarMutex());
184
185 if( m_pDrawViewWrapper && !m_pDrawViewWrapper->IsTextEdit() )
186 this->StartTextEdit();
187
188 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
189 DBG_ASSERT( pFact, "No dialog factory" );
190
191 SfxAllItemSet aSet( m_pDrawModelWrapper->GetItemPool() );
192 aSet.Put( SfxBoolItem( FN_PARAM_1, sal_False ) );
193
194 //set fixed current font
195 aSet.Put( SfxBoolItem( FN_PARAM_2, sal_True ) ); //maybe not necessary in future
196
197 Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
198 aSet.Put( SvxFontItem( aCurFont.GetFamily(), aCurFont.GetName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );
199
200 SfxAbstractDialog * pDlg = pFact->CreateSfxDialog( m_pChartWindow, aSet, getFrame(), RID_SVXDLG_CHARMAP );
201 DBG_ASSERT( pDlg, "Couldn't create SvxCharacterMap dialog" );
202 if( pDlg->Execute() == RET_OK )
203 {
204 const SfxItemSet* pSet = pDlg->GetOutputItemSet();
205 const SfxPoolItem* pItem=0;
206 String aString;
207 if ( pSet && pSet->GetItemState( SID_CHARMAP, sal_True, &pItem) == SFX_ITEM_SET &&
208 pItem->ISA(SfxStringItem) )
209 aString = dynamic_cast<const SfxStringItem*>(pItem)->GetValue();
210
211 OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
212 SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
213
214 if(!pOutliner || !pOutlinerView)
215 return;
216
217 // insert string to outliner
218
219 // prevent flicker
220 pOutlinerView->HideCursor();
221 pOutliner->SetUpdateMode(sal_False);
222
223 // delete current selection by inserting empty String, so current
224 // attributes become unique (sel. has to be erased anyway)
225 pOutlinerView->InsertText(String());
226
227 //SfxUndoManager& rUndoMgr = pOutliner->GetUndoManager();
228 //rUndoMgr.EnterListAction( String( SchResId( STR_UNDO_INSERT_SPECCHAR )), String( SchResId( STR_UNDO_INSERT_SPECCHAR )));
229 pOutlinerView->InsertText(aString, sal_True);
230
231 ESelection aSel = pOutlinerView->GetSelection();
232 aSel.nStartPara = aSel.nEndPara;
233 aSel.nStartPos = aSel.nEndPos;
234 pOutlinerView->SetSelection(aSel);
235
236 //rUndoMgr.LeaveListAction();
237
238 // show changes
239 pOutliner->SetUpdateMode(sal_True);
240 pOutlinerView->ShowCursor();
241 }
242
243 delete pDlg;
244 }
245
246 uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
impl_createAccessibleTextContext()247 ChartController::impl_createAccessibleTextContext()
248 {
249 uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > xResult(
250 new AccessibleTextHelper( m_pDrawViewWrapper ));
251
252 return xResult;
253 }
254
255
256 //.............................................................................
257 } //namespace chart
258 //.............................................................................
259