diff options
author | Andrzej Hunt <andrzej.hunt@collabora.com> | 2014-06-13 15:00:42 +0100 |
---|---|---|
committer | Andrzej Hunt <andrzej.hunt@collabora.com> | 2014-06-25 13:04:32 +0100 |
commit | 837631c6cfa189280f9e723481f2251de56a1d92 (patch) | |
tree | bb50d5b7404c3f7a5363742ee7f91e9b7e0dc552 /desktop | |
parent | eaa21b726db220c7883453f197aac81a6d35b201 (diff) |
LIBLOK: implement getDocumentType, make doctypes unique.
Change-Id: I6cf810af55284cb6ddd9e0bfd879fd19508d127a
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/lib/init.cxx | 124 |
1 files changed, 85 insertions, 39 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 4959195e0253..605f1097751e 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -307,31 +307,23 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha try { - uno::Reference<frame::XModel> xDocument(pDocument->mxComponent, uno::UNO_QUERY_THROW); - uno::Sequence<beans::PropertyValue> aSequence = xDocument->getArgs(); - - MediaDescriptor aMediaDescriptor(aSequence); - OUString sPropertyName = MediaDescriptor::PROP_DOCUMENTSERVICE(); - OUString aDocumentService = aMediaDescriptor.getUnpackedValueOrDefault(sPropertyName, OUString()); + const ExtensionMap* pMap; - if (aDocumentService.isEmpty()) + switch (doc_getDocumentType(pThis)) { - gImpl->maLastExceptionMsg = "unknown document type"; - return false; - } - - const ExtensionMap* pMap; - if (aDocumentService == "com.sun.star.sheet.SpreadsheetDocument") + case LOK_DOCTYPE_SPREADSHEET: pMap = (const ExtensionMap*) aCalcExtensionMap; - else if (aDocumentService == "com.sun.star.presentation.PresentationDocument") + break; + case LOK_DOCTYPE_PRESENTATION: pMap = (const ExtensionMap*) aImpressExtensionMap; - else if (aDocumentService == "com.sun.star.drawing.DrawingDocument") + break; + case LOK_DOCTYPE_DRAWING: pMap = (const ExtensionMap*) aDrawExtensionMap; - else if (aDocumentService == "com.sun.star.text.TextDocument") + break; + case LOK_DOCTYPE_TEXT: pMap = (const ExtensionMap*) aWriterExtensionMap; - else - { - gImpl->maLastExceptionMsg = "unknown document mapping"; + break; + case LOK_DOCTYPE_OTHER: return false; } @@ -386,8 +378,49 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha static LibreOfficeKitDocumentType doc_getDocumentType (LibreOfficeKitDocument* pThis) { - (void) pThis; - return WRITER; + LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); + + try + { + uno::Reference<frame::XModel> xDocument(pDocument->mxComponent, uno::UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> aSequence = xDocument->getArgs(); + + MediaDescriptor aMediaDescriptor(aSequence); + OUString sPropertyName = MediaDescriptor::PROP_DOCUMENTSERVICE(); + OUString aDocumentService = aMediaDescriptor.getUnpackedValueOrDefault(sPropertyName, OUString()); + + if (aDocumentService.isEmpty()) + { + gImpl->maLastExceptionMsg = "unknown document type"; + return LOK_DOCTYPE_OTHER; + } + + if (aDocumentService == "com.sun.star.sheet.SpreadsheetDocument") + { + return LOK_DOCTYPE_SPREADSHEET; + } + else if (aDocumentService == "com.sun.star.presentation.PresentationDocument") + { + return LOK_DOCTYPE_PRESENTATION; + } + else if (aDocumentService == "com.sun.star.drawing.DrawingDocument") + { + return LOK_DOCTYPE_DRAWING; + } + else if (aDocumentService == "com.sun.star.text.TextDocument") + { + return LOK_DOCTYPE_TEXT; + } + else + { + gImpl->maLastExceptionMsg = "unknown document mapping"; + } + } + catch (const uno::Exception& exception) + { + gImpl->maLastExceptionMsg = "exception: " + exception.Message; + } + return LOK_DOCTYPE_OTHER; } static int doc_getNumberOfParts (LibreOfficeKitDocument* pThis) @@ -412,30 +445,38 @@ void doc_paintTile (LibreOfficeKitDocument* pThis, { LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); + Application::AcquireSolarMutex(1); + switch (doc_getDocumentType(pThis)) { - SwXTextDocument* pTxtDoc = dynamic_cast< SwXTextDocument* >( pDocument->mxComponent.get() ); - SwDocShell* pDocShell = pTxtDoc->GetDocShell(); - SwDoc* pDoc = pDocShell->GetDoc(); - SwViewShell* pViewShell = pDoc->GetCurrentViewShell(); + case LOK_DOCTYPE_TEXT: + { + SwXTextDocument* pTxtDoc = dynamic_cast< SwXTextDocument* >( pDocument->mxComponent.get() ); + SwDocShell* pDocShell = pTxtDoc->GetDocShell(); + SwDoc* pDoc = pDocShell->GetDoc(); + SwViewShell* pViewShell = pDoc->GetCurrentViewShell(); - ImplSVData* pSVData = ImplGetSVData(); - SvpSalInstance* pSalInstance = static_cast< SvpSalInstance* >(pSVData->mpDefInst); - pSalInstance->setBitCountFormatMapping( 32, ::basebmp::FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA ); + ImplSVData* pSVData = ImplGetSVData(); + SvpSalInstance* pSalInstance = static_cast< SvpSalInstance* >(pSVData->mpDefInst); + pSalInstance->setBitCountFormatMapping( 32, ::basebmp::FORMAT_THIRTYTWO_BIT_TC_MASK_RGBA ); - VirtualDevice aDevice(0, (sal_uInt16)32); - boost::shared_array< sal_uInt8 > aBuffer( pBuffer, NoDelete< sal_uInt8 >() ); - aDevice.SetOutputSizePixelScaleOffsetAndBuffer( - Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(), - aBuffer, true ); + VirtualDevice aDevice(0, (sal_uInt16)32); + boost::shared_array< sal_uInt8 > aBuffer( pBuffer, NoDelete< sal_uInt8 >() ); + aDevice.SetOutputSizePixelScaleOffsetAndBuffer( + Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(), + aBuffer, true ); - pViewShell->PaintTile(aDevice, nCanvasWidth, nCanvasHeight, - nTilePosX, nTilePosY, nTileWidth, nTileHeight); + pViewShell->PaintTile(aDevice, nCanvasWidth, nCanvasHeight, + nTilePosX, nTilePosY, nTileWidth, nTileHeight); - SvpSalVirtualDevice* pSalDev = static_cast< SvpSalVirtualDevice* >(aDevice.getSalVirtualDevice()); - basebmp::BitmapDeviceSharedPtr pBmpDev = pSalDev->getBitmapDevice(); + SvpSalVirtualDevice* pSalDev = static_cast< SvpSalVirtualDevice* >(aDevice.getSalVirtualDevice()); + basebmp::BitmapDeviceSharedPtr pBmpDev = pSalDev->getBitmapDevice(); - *pRowStride = pBmpDev->getScanlineStride(); + *pRowStride = pBmpDev->getScanlineStride(); + } + break; + default: + break; } Application::ReleaseSolarMutex(); } @@ -446,7 +487,7 @@ static void doc_getDocumentSize(LibreOfficeKitDocument* pThis, { LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); - if (true) // TODO: test that we have a writer document here (vs calc/impress/etc.) + if (doc_getDocumentType(pThis) == LOK_DOCTYPE_TEXT) { SwXTextDocument* pTxtDoc = dynamic_cast< SwXTextDocument* >( pDocument->mxComponent.get() ); SwDocShell* pDocShell = pTxtDoc->GetDocShell(); @@ -456,6 +497,11 @@ static void doc_getDocumentSize(LibreOfficeKitDocument* pThis, *pWidth = aDocumentSize.Width(); *pHeight = aDocumentSize.Height(); } + else + { + pWidth = 0; + pHeight = 0; + } } static char* lo_getError (LibreOfficeKit *pThis) |