summaryrefslogtreecommitdiff
path: root/chart2/source/controller/main/ChartController_TextEdit.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'chart2/source/controller/main/ChartController_TextEdit.cxx')
-rw-r--r--chart2/source/controller/main/ChartController_TextEdit.cxx214
1 files changed, 145 insertions, 69 deletions
diff --git a/chart2/source/controller/main/ChartController_TextEdit.cxx b/chart2/source/controller/main/ChartController_TextEdit.cxx
index 217accdde083..600d46b434d0 100644
--- a/chart2/source/controller/main/ChartController_TextEdit.cxx
+++ b/chart2/source/controller/main/ChartController_TextEdit.cxx
@@ -17,18 +17,26 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <config_wasm_strip.h>
+
#include <ChartController.hxx>
#include <ResId.hxx>
#include "UndoGuard.hxx"
#include <DrawViewWrapper.hxx>
#include <ChartWindow.hxx>
+#include <ChartModel.hxx>
+#include <ChartView.hxx>
#include <TitleHelper.hxx>
#include <ObjectIdentifier.hxx>
#include <ControllerLockGuard.hxx>
+#include <comphelper/diagnose_ex.hxx>
+#if !ENABLE_WASM_STRIP_ACCESSIBILITY
#include <AccessibleTextHelper.hxx>
+#endif
#include <strings.hrc>
#include <chartview/DrawModelWrapper.hxx>
+#include <osl/diagnose.h>
#include <svx/svdoutl.hxx>
#include <svx/svxdlg.hxx>
@@ -36,9 +44,12 @@
#include <editeng/editids.hrc>
#include <vcl/svapp.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/chart2/XTitle.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/text/XTextCursor.hpp>
+#include <com/sun/star/chart2/FormattedString.hpp>
#include <svl/stritem.hxx>
#include <editeng/fontitem.hxx>
+#include <editeng/section.hxx>
#include <memory>
namespace chart
@@ -66,9 +77,8 @@ void ChartController::StartTextEdit( const Point* pMousePixel )
SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
//#i77362 change notification for changes on additional shapes are missing
- uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
- if( xChartViewProps.is() )
- xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::Any(true) );
+ if( m_xChartView.is() )
+ m_xChartView->setPropertyValue( "SdrViewIsInEditMode", uno::Any(true) );
auto pChartWindow(GetChartWindow());
@@ -111,43 +121,102 @@ bool ChartController::EndTextEdit()
m_pDrawViewWrapper->SdrEndTextEdit();
//#i77362 change notification for changes on additional shapes are missing
- uno::Reference< beans::XPropertySet > xChartViewProps( m_xChartView, uno::UNO_QUERY );
- if( xChartViewProps.is() )
- xChartViewProps->setPropertyValue( "SdrViewIsInEditMode", uno::Any(false) );
+ if( m_xChartView.is() )
+ m_xChartView->setPropertyValue( "SdrViewIsInEditMode", uno::Any(false) );
SdrObject* pTextObject = m_pDrawViewWrapper->getTextEditObject();
if(!pTextObject)
return false;
- SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
OutlinerParaObject* pParaObj = pTextObject->GetOutlinerParaObject();
- if( pParaObj && pOutliner )
+ if( !pParaObj )
+ return true;
+
+ OUString aObjectCID = m_aSelection.getSelectedCID();
+ if ( !aObjectCID.isEmpty() )
{
- pOutliner->SetText( *pParaObj );
+ uno::Reference< beans::XPropertySet > xPropSet =
+ ObjectIdentifier::getObjectPropertySet( aObjectCID, getChartModel() );
- OUString aString = pOutliner->GetText(
- pOutliner->GetParagraph( 0 ),
- pOutliner->GetParagraphCount() );
+ // lock controllers till end of block
+ ControllerLockGuardUNO aCLGuard( getChartModel() );
- OUString aObjectCID = m_aSelection.getSelectedCID();
- if ( !aObjectCID.isEmpty() )
- {
- uno::Reference< beans::XPropertySet > xPropSet =
- ObjectIdentifier::getObjectPropertySet( aObjectCID, getModel() );
+ uno::Sequence< uno::Reference< chart2::XFormattedString > > aNewFormattedTitle =
+ GetFormattedTitle(pParaObj->GetTextObject(), pTextObject->getUnoShape());
+
+ Title* pTitle = dynamic_cast<Title*>(xPropSet.get());
+ TitleHelper::setFormattedString(pTitle, aNewFormattedTitle);
+
+ OSL_ENSURE(m_pTextActionUndoGuard, "ChartController::EndTextEdit: no TextUndoGuard!");
+ if (m_pTextActionUndoGuard)
+ m_pTextActionUndoGuard->commit();
+ }
+ m_pTextActionUndoGuard.reset();
+ return true;
+}
+
+uno::Sequence< uno::Reference< chart2::XFormattedString > > ChartController::GetFormattedTitle(
+ const EditTextObject& aEdit, const uno::Reference< drawing::XShape >& xShape )
+{
+ std::vector < uno::Reference< chart2::XFormattedString > > aNewStrings;
+ if (!xShape.is())
+ return comphelper::containerToSequence(aNewStrings);
+
+ uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY);
+ if (!xText.is())
+ return comphelper::containerToSequence(aNewStrings);
+
+ uno::Reference< text::XTextCursor > xSelectionCursor(xText->createTextCursor());
+ if (!xSelectionCursor.is())
+ return comphelper::containerToSequence(aNewStrings);
+
+ xSelectionCursor->gotoStart(false);
+
+ std::vector<editeng::Section> aSecAttrs;
+ aEdit.GetAllSections(aSecAttrs);
+
+ for (editeng::Section const& rSection : aSecAttrs)
+ {
+ if (!xSelectionCursor->isCollapsed())
+ xSelectionCursor->collapseToEnd();
+
+ xSelectionCursor->goRight(rSection.mnEnd - rSection.mnStart, true);
+
+ OUString aNewString = xSelectionCursor->getString();
- // lock controllers till end of block
- ControllerLockGuardUNO aCLGuard( getModel() );
+ bool bNextPara = (aEdit.GetParagraphCount() > 1 && rSection.mnParagraph != aEdit.GetParagraphCount() - 1 &&
+ aEdit.GetTextLen(rSection.mnParagraph) <= rSection.mnEnd);
- TitleHelper::setCompleteString( aString, uno::Reference<
- css::chart2::XTitle >::query( xPropSet ), m_xCC );
+ uno::Reference< chart2::XFormattedString2 > xFmtStr = chart2::FormattedString::create(m_xCC);
+ if (bNextPara)
+ aNewString = aNewString + OUStringChar('\n');
+ xFmtStr->setString(aNewString);
+ aNewStrings.emplace_back(xFmtStr);
- OSL_ENSURE(m_pTextActionUndoGuard, "ChartController::EndTextEdit: no TextUndoGuard!");
- if (m_pTextActionUndoGuard)
- m_pTextActionUndoGuard->commit();
+ uno::Reference< beans::XPropertySetInfo > xInfo = xFmtStr->getPropertySetInfo();
+ uno::Reference< beans::XPropertySet > xSelectionProp(xSelectionCursor, uno::UNO_QUERY);
+ try
+ {
+ for (const beans::Property& rProp : xSelectionProp->getPropertySetInfo()->getProperties())
+ {
+ if (xInfo.is() && xInfo->hasPropertyByName(rProp.Name))
+ {
+ const uno::Any aValue = xSelectionProp->getPropertyValue(rProp.Name);
+ xFmtStr->setPropertyValue(rProp.Name, aValue);
+ }
+ }
+ }
+ catch ( const uno::Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("chart2");
+ aNewStrings.clear();
}
- m_pTextActionUndoGuard.reset();
+
+ if (bNextPara)
+ xSelectionCursor->goRight(1, false); // next paragraph
}
- return true;
+
+ return comphelper::containerToSequence(aNewStrings);
}
void ChartController::executeDispatch_InsertSpecialCharacter()
@@ -172,52 +241,59 @@ void ChartController::executeDispatch_InsertSpecialCharacter()
vcl::Font aCurFont = m_pDrawViewWrapper->getOutliner()->GetRefDevice()->GetFont();
aSet.Put( SvxFontItem( aCurFont.GetFamilyType(), aCurFont.GetFamilyName(), aCurFont.GetStyleName(), aCurFont.GetPitch(), aCurFont.GetCharSet(), SID_ATTR_CHAR_FONT ) );
- ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(GetChartFrame(), aSet, nullptr));
- if( pDlg->Execute() != RET_OK )
- return;
-
- const SfxItemSet* pSet = pDlg->GetOutputItemSet();
- const SfxPoolItem* pItem=nullptr;
- OUString aString;
- if (pSet && pSet->GetItemState(SID_CHARMAP, true, &pItem) == SfxItemState::SET)
- if (auto pStringItem = dynamic_cast<const SfxStringItem*>(pItem))
- aString = pStringItem->GetValue();
-
- OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
- SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
-
- if(!pOutliner || !pOutlinerView)
- return;
-
- // insert string to outliner
-
- // prevent flicker
- pOutlinerView->HideCursor();
- pOutliner->SetUpdateMode(false);
-
- // delete current selection by inserting empty String, so current
- // attributes become unique (sel. has to be erased anyway)
- pOutlinerView->InsertText(OUString());
-
- pOutlinerView->InsertText(aString, true);
-
- ESelection aSel = pOutlinerView->GetSelection();
- aSel.nStartPara = aSel.nEndPara;
- aSel.nStartPos = aSel.nEndPos;
- pOutlinerView->SetSelection(aSel);
+ VclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(GetChartFrame(), aSet, nullptr));
+ pDlg->StartExecuteAsync(
+ [this, pDlg] (sal_Int32 nResult)->void
+ {
+ if (nResult == RET_OK)
+ {
+ const SfxItemSet* pSet = pDlg->GetOutputItemSet();
+ OUString aString;
+ if (pSet)
+ if (const SfxStringItem* pCharMapItem = pSet->GetItemIfSet(SID_CHARMAP))
+ aString = pCharMapItem->GetValue();
+
+ OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
+ SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner();
+
+ if(pOutliner && pOutlinerView)
+ {
+ // insert string to outliner
+
+ // prevent flicker
+ pOutlinerView->HideCursor();
+ pOutliner->SetUpdateLayout(false);
+
+ // delete current selection by inserting empty String, so current
+ // attributes become unique (sel. has to be erased anyway)
+ pOutlinerView->InsertText(OUString());
+
+ pOutlinerView->InsertText(aString, true);
+
+ ESelection aSel = pOutlinerView->GetSelection();
+ aSel.nStartPara = aSel.nEndPara;
+ aSel.nStartPos = aSel.nEndPos;
+ pOutlinerView->SetSelection(aSel);
+
+ // show changes
+ pOutliner->SetUpdateLayout(true);
+ pOutlinerView->ShowCursor();
+ }
+ }
+ pDlg->disposeOnce();
+ }
+ );
- // show changes
- pOutliner->SetUpdateMode(true);
- pOutlinerView->ShowCursor();
}
-uno::Reference< css::accessibility::XAccessibleContext >
- ChartController::impl_createAccessibleTextContext()
+rtl::Reference< ::chart::AccessibleTextHelper >
+ ChartController::createAccessibleTextContext()
{
- uno::Reference< css::accessibility::XAccessibleContext > xResult(
- new AccessibleTextHelper( m_pDrawViewWrapper.get() ));
-
- return xResult;
+#if !ENABLE_WASM_STRIP_ACCESSIBILITY
+ return new AccessibleTextHelper( m_pDrawViewWrapper.get() );
+#else
+ return {};
+#endif
}
} //namespace chart