[Libreoffice-commits] core.git: Branch 'aoo/trunk' - dtrans/source officecfg/registry sot/inc sot/source starmath/inc starmath/sdi starmath/source starmath/uiconfig

Regina Henschel regina at apache.org
Wed Jul 8 07:08:23 PDT 2015


 dtrans/source/win32/ftransl/ftransl.cxx                           |    2 
 officecfg/registry/data/org/openoffice/Office/UI/MathCommands.xcu |    5 
 sot/inc/sot/formats.hxx                                           |    3 
 sot/source/base/exchange.cxx                                      |    1 
 starmath/inc/starmath.hrc                                         |    1 
 starmath/sdi/smath.sdi                                            |   25 +++
 starmath/sdi/smslots.sdi                                          |    6 
 starmath/source/view.cxx                                          |   74 ++++++++++
 starmath/uiconfig/smath/menubar/menubar.xml                       |    1 
 9 files changed, 117 insertions(+), 1 deletion(-)

New commits:
commit 9ec2148653436be8612273439180749e71e2ce58
Author: Regina Henschel <regina at apache.org>
Date:   Wed Jul 8 12:31:43 2015 +0000

    #i107734 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 at gmail.com>

diff --git a/dtrans/source/win32/ftransl/ftransl.cxx b/dtrans/source/win32/ftransl/ftransl.cxx
index cfceddc1..eedbc00 100644
--- a/dtrans/source/win32/ftransl/ftransl.cxx
+++ b/dtrans/source/win32/ftransl/ftransl.cxx
@@ -516,6 +516,8 @@ void SAL_CALL CDataFormatTranslator::initTranslationTable()
     m_TranslTable.push_back(FormatEntry("image/bmp", "Windows Bitmap", NULL, CF_INVALID, CPPUTYPE_DEFAULT));
     //SOT_FORMATSTR_ID_PNG
     m_TranslTable.push_back(FormatEntry("image/png", "PNG", NULL, CF_INVALID, CPPUTYPE_DEFAULT));
+    //SOT_FORMATSTR_ID_MATHML
+    m_TranslTable.push_back(FormatEntry("application/mathml+xml", "MathML", NULL, CF_INVALID, CPPUTYPE_DEFAULT));
     //SOT_FORMATSTR_ID_DUMMY3
     m_TranslTable.push_back(FormatEntry("application/x-openoffice-dummy3;windows_formatname=\"SO_DUMMYFORMAT_3\"", "SO_DUMMYFORMAT_3", NULL, CF_INVALID, CPPUTYPE_DEFAULT));
     //SOT_FORMATSTR_ID_DUMMY4
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/MathCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/MathCommands.xcu
index c266fbf..babc106 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/MathCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/MathCommands.xcu
@@ -77,6 +77,11 @@
                     <value xml:lang="en-US">~Import Formula...</value>
                 </prop>
             </node>
+            <node oor:name=".uno:ImportMathMLClipboard" oor:op="replace">
+                <prop oor:name="Label" oor:type="xs:string">
+                    <value xml:lang="en-US">Import MathML from Clipboard</value>
+                </prop>
+            </node>
             <node oor:name=".uno:InsertCommand" oor:op="replace">
                 <prop oor:name="Label" oor:type="xs:string">
                     <value xml:lang="en-US">Insert Command</value>
diff --git a/sot/inc/sot/formats.hxx b/sot/inc/sot/formats.hxx
index 24bdd44..6c30d18 100644
--- a/sot/inc/sot/formats.hxx
+++ b/sot/inc/sot/formats.hxx
@@ -182,7 +182,8 @@
 #define SOT_FORMATSTR_ID_STARBASE_8             ((sal_uLong)139)
 #define SOT_FORMATSTR_ID_HC_GDIMETAFILE         ((sal_uLong)140)
 #define SOT_FORMATSTR_ID_PNG                    ((sal_uLong)141)
-#define SOT_FORMATSTR_ID_USER_END               SOT_FORMATSTR_ID_PNG
+#define SOT_FORMATSTR_ID_MATHML                 ((sal_uLong)142)
+#define SOT_FORMATSTR_ID_USER_END               SOT_FORMATSTR_ID_MATHML
 
 #endif // _SOT_FORMATS_HXX
 
diff --git a/sot/source/base/exchange.cxx b/sot/source/base/exchange.cxx
index c576eb2..4b824e6 100644
--- a/sot/source/base/exchange.cxx
+++ b/sot/source/base/exchange.cxx
@@ -208,6 +208,7 @@ namespace
             /*139 SOT_FORMATSTR_ID_STARBASE_8*/            { MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII, "StarBase 8", &::getCppuType( (const Sequence< sal_Int8 >*) 0 ) },
             /*140 SOT_FORMAT_GDIMETAFILE*/                  { "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"", "High Contrast GDIMetaFile", &::getCppuType( (const Sequence< sal_Int8 >*) 0 ) },
             /*141 SOT_FORMATSTR_ID_PNG*/                    { "image/png", "PNG Bitmap", &::getCppuType( (const Sequence< sal_Int8 >*) 0 ) },
+            /*142 SOT_FORMATSTR_ID_MATHML*/                 { "application/mathml+xml", "MathML", &::getCppuType( (const Sequence< sal_Int8 >*) 0 ) },
             };
         return &aInstance[0];
         }
diff --git a/starmath/inc/starmath.hrc b/starmath/inc/starmath.hrc
index c1855d8..d273a7d 100644
--- a/starmath/inc/starmath.hrc
+++ b/starmath/inc/starmath.hrc
@@ -52,6 +52,7 @@
 #define SID_SYMBOLS                 (SID_SMA_START + 56) // Muss erstmal wieder aufgenommen werden !
 #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)
 #define SID_FITINWINDOW             (SID_SMA_START + 103)
diff --git a/starmath/sdi/smath.sdi b/starmath/sdi/smath.sdi
index 0193a8e..3f12b50 100755
--- a/starmath/sdi/smath.sdi
+++ b/starmath/sdi/smath.sdi
@@ -424,6 +424,31 @@ SfxBoolItem ImportFormula SID_IMPORT_FORMULA
 ]
 
 //--------------------------------------------------------------------------
+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 c0696e5..46c4fc5 100755
--- a/starmath/sdi/smslots.sdi
+++ b/starmath/sdi/smslots.sdi
@@ -277,6 +277,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 2fa4a0e..91448c0 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -64,6 +64,7 @@
 #include <vcl/menu.hxx>
 #include <vcl/msgbox.hxx>
 #include <vcl/wrkwin.hxx>
+#include <unotools/streamwrap.hxx>
 
 #include "unomodel.hxx"
 #include "view.hxx"
@@ -90,6 +91,8 @@ using namespace com::sun::star;
 using namespace com::sun::star::accessibility;
 using namespace com::sun::star::uno;
 
+using ::rtl::OUString;
+
 //////////////////////////////////////////////////////////////////////
 
 SmGraphicWindow::SmGraphicWindow(SmViewShell* pShell):
@@ -1601,6 +1604,77 @@ void SmViewShell::Execute(SfxRequest& rReq)
             break;
         }
 
+        case SID_IMPORT_MATHML_CLIPBOARD:
+        {
+            TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard(GetEditWindow()) );
+            uno::Reference < io::XInputStream > xStrm;
+            SotFormatStringId nId = SOT_FORMAT_SYSTEM_START; //dummy initialize to avoid warning
+            if  ( aDataHelper.GetTransferable().is() )
+            {
+                if ( aDataHelper.HasFormat( nId = SOT_FORMATSTR_ID_MATHML ) )
+                {
+                    if ( aDataHelper.GetInputStream( nId, xStrm ) && xStrm.is() )
+                    {
+                        SfxMedium* pClipboardMedium = new SfxMedium();
+                        pClipboardMedium->GetItemSet(); //generate initial itemset, not sure if necessary
+                        const SfxFilter* pMathFilter = SfxFilter::GetFilterByName( String::CreateFromAscii(MATHML_XML) );
+                        pClipboardMedium->SetFilter(pMathFilter);
+                        pClipboardMedium->setStreamToLoadFrom( xStrm, sal_True /*bIsReadOnly*/ );
+                        InsertFrom(*pClipboardMedium);
+                        GetDoc()->UpdateText();
+                        delete pClipboardMedium;
+                    }
+                }
+                else
+                {
+                    if ( aDataHelper.HasFormat( nId = FORMAT_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( String::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), STREAM_READ);
+                            }
+                            else
+                            {
+                                pStrm = new SvMemoryStream( (void*)aString.getStr(), aString.getLength() * sizeof(sal_Unicode), STREAM_READ);
+                            }
+                            com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xStrm( new ::utl::OInputStreamWrapper( *pStrm ) );
+                            pClipboardMedium->setStreamToLoadFrom( xStrm, sal_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 a1a94ee..cd382c9 100755
--- a/starmath/uiconfig/smath/menubar/menubar.xml
+++ b/starmath/uiconfig/smath/menubar/menubar.xml
@@ -104,6 +104,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>


More information about the Libreoffice-commits mailing list