summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorRegina Henschel <regina@apache.org>2015-07-08 12:31:43 +0000
committerMichael Stahl <mstahl@redhat.com>2015-07-08 16:57:49 +0200
commit64bc8b45b5c23efc5fe57585a69aa4263aaf4e83 (patch)
treed61a0aa25685e951ffa32751afb89e97c35531a0 /starmath
parent26aebe26f706d9fbc9c113f5c1fdc495578435bf (diff)
i#107734 Support for Math Input Panel in Windows 7
The patch introduces a new command .uno:ImportMathClipboard to module Math. It imports MathML content from clipboard and transforms it to Starmath It handles clipboard MIME type 'application/mathml+xml' and plain text, which can be interpreted as MathML segment. It partly solves issues #i14252, #i34781, and #i53509 too. Review by: Hanya <hanya.runo@gmail.com> (cherry picked from commit 9ec2148653436be8612273439180749e71e2ce58) Conflicts: dtrans/source/win32/ftransl/ftransl.cxx officecfg/registry/data/org/openoffice/Office/UI/MathCommands.xcu sot/inc/sot/formats.hxx sot/source/base/exchange.cxx starmath/sdi/smath.sdi starmath/source/view.cxx Change-Id: I6cb5e8f737ee2e39f9ce96aba841db347a8806e4
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/starmath.hrc1
-rw-r--r--starmath/sdi/smath.sdi23
-rw-r--r--starmath/sdi/smslots.sdi6
-rw-r--r--starmath/source/view.cxx75
-rw-r--r--starmath/uiconfig/smath/menubar/menubar.xml1
5 files changed, 106 insertions, 0 deletions
diff --git a/starmath/inc/starmath.hrc b/starmath/inc/starmath.hrc
index 7196b26dd269..6bf6e2124b9e 100644
--- a/starmath/inc/starmath.hrc
+++ b/starmath/inc/starmath.hrc
@@ -45,6 +45,7 @@
#define SID_SYMBOLS (SID_SMA_START + 56) // Has to be picked up again for now!
#define SID_TEXTMODE (SID_SMA_START + 57)
#define SID_IMPORT_FORMULA (SID_SMA_START + 58)
+#define SID_IMPORT_MATHML_CLIPBOARD (SID_SMA_START + 59)
#define SID_TEXT (SID_SMA_START + 100)
#define SID_GAPHIC_SM (SID_SMA_START + 101)
/** Command for inserting a symbol specified by a string (Inserts an SmSpecialNode) */
diff --git a/starmath/sdi/smath.sdi b/starmath/sdi/smath.sdi
index 94caccacec4b..bbf5a6bedb6f 100644
--- a/starmath/sdi/smath.sdi
+++ b/starmath/sdi/smath.sdi
@@ -418,6 +418,29 @@ SfxBoolItem ImportFormula SID_IMPORT_FORMULA
GroupId = GID_INSERT;
]
+SfxBoolItem ImportMathMLClipboard SID_IMPORT_MATHML_CLIPBOARD
+()
+[
+ /* flags: */
+ AutoUpdate = FALSE,
+ Cachable = Cachable,
+ FastCall = TRUE,
+ HasCoreId = FALSE, /*obsolete */
+ HasDialog = FALSE, /*obsolete */
+ ReadOnlyDoc = FALSE,
+ Toggle = FALSE,
+ Container = FALSE,
+ RecordAbsolute = FALSE, /*obsolete */
+ RecordPerSet;
+ Synchron;
+
+ /* config: */
+ AccelConfig = TRUE,
+ MenuConfig = TRUE,
+ StatusBarConfig = FALSE,
+ ToolBoxConfig = TRUE,
+ GroupId = GID_INSERT;
+]
SfxVoidItem LoadSymbols SID_LOADSYMBOLS
()
diff --git a/starmath/sdi/smslots.sdi b/starmath/sdi/smslots.sdi
index 9857d3902bb6..a43eb7c38bff 100644
--- a/starmath/sdi/smslots.sdi
+++ b/starmath/sdi/smslots.sdi
@@ -251,6 +251,12 @@ interface FormulaView
StateMethod = GetState ;
Export = FALSE ;
]
+ SID_IMPORT_MATHML_CLIPBOARD //idlpp ole : no , status : no
+ [
+ ExecMethod = Execute ;
+ StateMethod = GetState ;
+ Export = FALSE ;
+ ]
//idlpp kein Menueeintrag , also keine Texte
SID_ATTR_ZOOM //idlpp ole : no , status : no
[
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 6bed0c31235b..1c4ca5401969 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -61,6 +61,7 @@
#include <vcl/settings.hxx>
#include <fstream>
+#include <unotools/streamwrap.hxx>
#include "unomodel.hxx"
#include "view.hxx"
@@ -1653,6 +1654,80 @@ void SmViewShell::Execute(SfxRequest& rReq)
break;
}
+ case SID_IMPORT_MATHML_CLIPBOARD:
+ {
+ TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard(GetEditWindow()) );
+ uno::Reference < io::XInputStream > xStrm;
+ SotClipboardFormatId nId = SOT_FORMAT_SYSTEM_START; //dummy initialize to avoid warning
+ if ( aDataHelper.GetTransferable().is() )
+ {
+ if (aDataHelper.HasFormat(nId = SotClipboardFormatId::MATHML))
+ {
+ xStrm = aDataHelper.GetInputStream(nId, "");
+ if (xStrm.is())
+ {
+ SfxMedium* pClipboardMedium = new SfxMedium();
+ pClipboardMedium->GetItemSet(); //generate initial itemset, not sure if necessary
+ const SfxFilter* pMathFilter =
+ SfxFilter::GetFilterByName(OUString::createFromAscii(MATHML_XML));
+ pClipboardMedium->SetFilter(pMathFilter);
+ pClipboardMedium->setStreamToLoadFrom(xStrm, true /*bIsReadOnly*/);
+ InsertFrom(*pClipboardMedium);
+ GetDoc()->UpdateText();
+ delete pClipboardMedium;
+ }
+ }
+ else
+ {
+ if (aDataHelper.HasFormat(nId = SotClipboardFormatId::STRING))
+ {
+ // In case of FORMAT_STRING no stream exists, need to generate one
+ ::rtl::OUString aString;
+ if (aDataHelper.GetString( nId, aString))
+ {
+ SfxMedium* pClipboardMedium = new SfxMedium();
+ pClipboardMedium->GetItemSet(); //generates initial itemset, not sure if necessary
+ const SfxFilter* pMathFilter =
+ SfxFilter::GetFilterByName(OUString::createFromAscii(MATHML_XML));
+ pClipboardMedium->SetFilter(pMathFilter);
+
+ SvMemoryStream * pStrm;
+ // The text to be imported might asserts encoding like 'encoding="utf-8"' but FORMAT_STRING is UTF-16.
+ // Force encoding to UTF-16, if encoding exists.
+ bool bForceUTF16 = false;
+ sal_Int32 nPosL = aString.indexOf( OUString::createFromAscii("encoding=\""));
+ sal_Int32 nPosU = -1;
+ if ( nPosL >= 0 && nPosL +10 < aString.getLength() )
+ {
+ nPosL += 10;
+ nPosU = aString.indexOf( '"',nPosL);
+ if (nPosU > nPosL)
+ {
+ bForceUTF16 = true;
+ }
+ }
+ if ( bForceUTF16 )
+ {
+ OUString aNewString = aString.replaceAt( nPosL,nPosU-nPosL,OUString::createFromAscii("UTF-16"));
+ pStrm = new SvMemoryStream( (void*)aNewString.getStr(), aNewString.getLength() * sizeof(sal_Unicode), StreamMode::READ);
+ }
+ else
+ {
+ pStrm = new SvMemoryStream( (void*)aString.getStr(), aString.getLength() * sizeof(sal_Unicode), StreamMode::READ);
+ }
+ uno::Reference<io::XInputStream> xStrm2( new ::utl::OInputStreamWrapper(*pStrm) );
+ pClipboardMedium->setStreamToLoadFrom(xStrm2, true /*bIsReadOnly*/);
+ InsertFrom(*pClipboardMedium);
+ GetDoc()->UpdateText();
+ delete pClipboardMedium;
+ delete pStrm;
+ }
+ }
+ }
+ }
+ break;
+ }
+
case SID_NEXTERR:
NextError();
if (pWin)
diff --git a/starmath/uiconfig/smath/menubar/menubar.xml b/starmath/uiconfig/smath/menubar/menubar.xml
index 5a8edbb23763..60c48ff20b4c 100644
--- a/starmath/uiconfig/smath/menubar/menubar.xml
+++ b/starmath/uiconfig/smath/menubar/menubar.xml
@@ -116,6 +116,7 @@
<menu:menupopup>
<menu:menuitem menu:id=".uno:SymbolCatalogue"/>
<menu:menuitem menu:id=".uno:ImportFormula"/>
+ <menu:menuitem menu:id=".uno:ImportMathMLClipboard"/>
<menu:menuseparator/>
<menu:menu menu:id=".uno:MacrosMenu">
<menu:menupopup>