1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartController_TextEdit.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ChartController.hxx"
35 #include "DrawViewWrapper.hxx"
36 #include "ChartWindow.hxx"
37 #include "TitleHelper.hxx"
38 #include "ObjectIdentifier.hxx"
40 #include "ControllerLockGuard.hxx"
41 #include "AccessibleTextHelper.hxx"
42 #include "chartview/DrawModelWrapper.hxx"
44 #include <svx/svdotext.hxx>
46 // header for define RET_OK
47 #include <vcl/msgbox.hxx>
48 // header for class SdrOutliner
49 #include <svx/svdoutl.hxx>
50 #include <svx/svxdlg.hxx>
51 #ifndef _SVX_DIALOGS_HRC
52 #include <svx/dialogs.hrc>
54 #include <vcl/svapp.hxx>
55 #include <vos/mutex.hxx>
56 #include <com/sun/star/beans/XPropertySet.hpp>
57 #include <svtools/stritem.hxx>
58 #include <svx/fontitem.hxx>
60 //.............................................................................
63 //.............................................................................
64 using namespace ::com::sun::star
;
65 //using namespace ::com::sun::star::chart2;
67 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 void SAL_CALL
ChartController::executeDispatch_EditText()
72 this->StartTextEdit();
75 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
78 void ChartController::StartTextEdit()
80 //the first marked object will be edited
82 SdrObject
* pTextObj
= m_pDrawViewWrapper
->getTextEditObject();
86 m_xUndoManager
->preAction( m_aModel
->getModel());
87 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
88 //pOutliner->SetRefDevice(m_pChartWindow);
89 //pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)pStyleSheetPool);
90 //pOutliner->SetDefaultLanguage( eLang );
91 //pOutliner->SetHyphenator( xHyphenator );
93 //#i77362 change notification for changes on additional shapes are missing
94 uno::Reference
< beans::XPropertySet
> xChartViewProps( m_xChartView
, uno::UNO_QUERY
);
95 if( xChartViewProps
.is() )
96 xChartViewProps
->setPropertyValue( C2U("SdrViewIsInEditMode"), uno::makeAny(sal_True
) );
98 sal_Bool bEdit
= m_pDrawViewWrapper
->SdrBeginTextEdit( pTextObj
99 , m_pDrawViewWrapper
->GetPageView()
101 , sal_False
//bIsNewObj
104 , sal_True
//bDontDeleteOutliner
105 , sal_True
//bOnlyOneView
109 // set undo manager at topmost shell ( SdDrawTextObjectBar )
112 pViewSh->GetViewFrame()->GetDispatcher()->GetShell( 0 )->
113 SetUndoManager(&pOutliner->GetUndoManager());
115 m_pDrawViewWrapper
->SetEditMode();
117 //we invalidate the outliner region because the outliner has some
118 //paint problems (some characters are painted twice a little bit shifted)
119 m_pChartWindow
->Invalidate( m_pDrawViewWrapper
->GetMarkedObjBoundRect() );
123 bool ChartController::EndTextEdit()
125 m_pDrawViewWrapper
->SdrEndTextEdit();
127 //#i77362 change notification for changes on additional shapes are missing
128 uno::Reference
< beans::XPropertySet
> xChartViewProps( m_xChartView
, uno::UNO_QUERY
);
129 if( xChartViewProps
.is() )
130 xChartViewProps
->setPropertyValue( C2U("SdrViewIsInEditMode"), uno::makeAny(sal_False
) );
132 SdrObject
* pTextObject
= m_pDrawViewWrapper
->getTextEditObject();
136 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
137 OutlinerParaObject
* pParaObj
= pTextObject
->GetOutlinerParaObject();
138 if( pParaObj
&& pOutliner
)
140 pOutliner
->SetText( *pParaObj
);
142 String aString
= pOutliner
->GetText(
143 pOutliner
->GetParagraph( 0 ),
144 pOutliner
->GetParagraphCount() );
145 uno::Reference
< beans::XPropertySet
> xPropSet
=
146 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getModel() );
148 // lock controllers till end of block
149 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
152 TitleHelper::setCompleteString( aString
, uno::Reference
<
153 ::com::sun::star::chart2::XTitle
>::query( xPropSet
), m_xCC
);
156 m_xUndoManager
->postAction( C2U("Edit Text") );
158 catch( uno::RuntimeException
& e
)
160 ASSERT_EXCEPTION( e
);
166 //-----------------------------------------------------------------------------
167 //-----------------------------------------------------------------------------
169 void SAL_CALL
ChartController::executeDispatch_InsertSpecialCharacter()
171 ::vos::OGuard
aGuard( Application::GetSolarMutex());
173 if( m_pDrawViewWrapper
&& !m_pDrawViewWrapper
->IsTextEdit() )
174 this->StartTextEdit();
176 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
177 DBG_ASSERT( pFact
, "No dialog factory" );
179 SfxAllItemSet
aSet( m_pDrawModelWrapper
->GetItemPool() );
180 aSet
.Put( SfxBoolItem( FN_PARAM_1
, FALSE
) );
182 //set fixed current font
183 aSet
.Put( SfxBoolItem( FN_PARAM_2
, TRUE
) ); //maybe not necessary in future
185 Font aCurFont
= m_pDrawViewWrapper
->getOutliner()->GetRefDevice()->GetFont();
186 aSet
.Put( SvxFontItem( aCurFont
.GetFamily(), aCurFont
.GetName(), aCurFont
.GetStyleName(), aCurFont
.GetPitch(), aCurFont
.GetCharSet(), SID_ATTR_CHAR_FONT
) );
188 SfxAbstractDialog
* pDlg
= pFact
->CreateSfxDialog( m_pChartWindow
, aSet
, getFrame(), RID_SVXDLG_CHARMAP
);
189 DBG_ASSERT( pDlg
, "Couldn't create SvxCharacterMap dialog" );
190 if( pDlg
->Execute() == RET_OK
)
192 const SfxItemSet
* pSet
= pDlg
->GetOutputItemSet();
193 const SfxPoolItem
* pItem
=0;
195 if ( pSet
&& pSet
->GetItemState( SID_CHARMAP
, TRUE
, &pItem
) == SFX_ITEM_SET
&&
196 pItem
->ISA(SfxStringItem
) )
197 aString
= dynamic_cast<const SfxStringItem
*>(pItem
)->GetValue();
199 OutlinerView
* pOutlinerView
= m_pDrawViewWrapper
->GetTextEditOutlinerView();
200 SdrOutliner
* pOutliner
= m_pDrawViewWrapper
->getOutliner();
202 if(!pOutliner
|| !pOutlinerView
)
205 // insert string to outliner
208 pOutlinerView
->HideCursor();
209 pOutliner
->SetUpdateMode(FALSE
);
211 // delete current selection by inserting empty String, so current
212 // attributes become unique (sel. has to be erased anyway)
213 pOutlinerView
->InsertText(String());
215 //SfxUndoManager& rUndoMgr = pOutliner->GetUndoManager();
216 //rUndoMgr.EnterListAction( String( SchResId( STR_UNDO_INSERT_SPECCHAR )), String( SchResId( STR_UNDO_INSERT_SPECCHAR )));
217 pOutlinerView
->InsertText(aString
, TRUE
);
219 ESelection aSel
= pOutlinerView
->GetSelection();
220 aSel
.nStartPara
= aSel
.nEndPara
;
221 aSel
.nStartPos
= aSel
.nEndPos
;
222 pOutlinerView
->SetSelection(aSel
);
224 //rUndoMgr.LeaveListAction();
227 pOutliner
->SetUpdateMode(TRUE
);
228 pOutlinerView
->ShowCursor();
234 uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>
235 ChartController::impl_createAccessibleTextContext()
237 uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> xResult(
238 new AccessibleTextHelper( m_pDrawViewWrapper
));
244 //.............................................................................
246 //.............................................................................