Kaydet (Commit) 5d2f3957 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

Detect and rotate image at drag&drop or copy&paste in Writer.

Change-Id: Iaacbb78921f966703d4f1080f97d26ea4895281f
üst bc584fc5
...@@ -110,11 +110,15 @@ ...@@ -110,11 +110,15 @@
#include <swcrsr.hxx> #include <swcrsr.hxx>
#include <SwRewriter.hxx> #include <SwRewriter.hxx>
#include <globals.hrc> #include <globals.hrc>
#include <app.hrc>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <swserv.hxx> #include <swserv.hxx>
#include <switerator.hxx> #include <switerator.hxx>
#include <vcl/GraphicNativeTransform.hxx>
#include <vcl/GraphicNativeMetadata.hxx>
extern bool bFrmDrag; extern bool bFrmDrag;
extern bool bDDINetAttr; extern bool bDDINetAttr;
extern bool bExecuteDrag; extern bool bExecuteDrag;
...@@ -368,6 +372,24 @@ namespace ...@@ -368,6 +372,24 @@ namespace
rSrcWrtShell.Copy(&rDest); rSrcWrtShell.Copy(&rDest);
} }
void lclCheckAndPerformRotation(Graphic& aGraphic)
{
GraphicNativeMetadata aMetadata;
if ( aMetadata.read(aGraphic) )
{
sal_uInt16 aRotation = aMetadata.getRotation();
if (aRotation != 0)
{
QueryBox aQueryBox(0, WB_YES_NO | WB_DEF_YES, SW_RES(STR_ROTATE_TO_STANDARD_ORIENTATION) );
if (aQueryBox.Execute() == RET_YES)
{
GraphicNativeTransform aTransform( aGraphic );
aTransform.rotate( aRotation );
}
}
}
}
} }
sal_Bool SwTransferable::GetData( const DataFlavor& rFlavor ) sal_Bool SwTransferable::GetData( const DataFlavor& rFlavor )
...@@ -1864,38 +1886,42 @@ int SwTransferable::_PasteTargetURL( TransferableDataHelper& rData, ...@@ -1864,38 +1886,42 @@ int SwTransferable::_PasteTargetURL( TransferableDataHelper& rData,
SwTransferable::_CheckForURLOrLNKFile( rData, sURL ); SwTransferable::_CheckForURLOrLNKFile( rData, sURL );
//!!! check at FileSystem - only then it make sense to test graphics !!! //!!! check at FileSystem - only then it make sense to test graphics !!!
Graphic aGrf; Graphic aGraphic;
GraphicFilter &rFlt = GraphicFilter::GetGraphicFilter(); GraphicFilter &rFlt = GraphicFilter::GetGraphicFilter();
nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( sURL, aEmptyStr, aGrf, &rFlt ); nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( sURL, aEmptyStr, aGraphic, &rFlt );
if( nRet ) if( nRet )
{ {
//Check and Perform rotation if needed
lclCheckAndPerformRotation(aGraphic);
switch( nAction ) switch( nAction )
{ {
case SW_PASTESDR_INSERT: case SW_PASTESDR_INSERT:
SwTransferable::SetSelInShell( rSh, sal_False, pPt ); SwTransferable::SetSelInShell( rSh, sal_False, pPt );
rSh.Insert( sURL, aEmptyStr, aGrf ); rSh.Insert( sURL, aEmptyStr, aGraphic );
break; break;
case SW_PASTESDR_REPLACE: case SW_PASTESDR_REPLACE:
if( rSh.IsObjSelected() ) if( rSh.IsObjSelected() )
{ {
rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf ); rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGraphic );
Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() ); Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
SwTransferable::SetSelInShell( rSh, sal_True, &aPt ); SwTransferable::SetSelInShell( rSh, sal_True, &aPt );
} }
else else
rSh.ReRead( sURL, aEmptyStr, &aGrf ); rSh.ReRead( sURL, aEmptyStr, &aGraphic );
break; break;
case SW_PASTESDR_SETATTR: case SW_PASTESDR_SETATTR:
if( rSh.IsObjSelected() ) if( rSh.IsObjSelected() )
rSh.Paste( aGrf ); rSh.Paste( aGraphic );
else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() ) else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
rSh.ReRead( sURL, aEmptyStr, &aGrf ); rSh.ReRead( sURL, aEmptyStr, &aGraphic );
else else
{ {
SwTransferable::SetSelInShell( rSh, sal_False, pPt ); SwTransferable::SetSelInShell( rSh, sal_False, pPt );
rSh.Insert( sURL, aEmptyStr, aGrf ); rSh.Insert( sURL, aEmptyStr, aGraphic );
} }
break; break;
default: default:
...@@ -2147,7 +2173,7 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, ...@@ -2147,7 +2173,7 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
{ {
int nRet = 0; int nRet = 0;
Graphic aGrf; Graphic aGraphic;
INetBookmark aBkmk; INetBookmark aBkmk;
sal_Bool bCheckForGrf = sal_False, bCheckForImageMap = sal_False; sal_Bool bCheckForGrf = sal_False, bCheckForImageMap = sal_False;
...@@ -2155,7 +2181,7 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, ...@@ -2155,7 +2181,7 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
{ {
case SOT_FORMAT_BITMAP: case SOT_FORMAT_BITMAP:
case SOT_FORMAT_GDIMETAFILE: case SOT_FORMAT_GDIMETAFILE:
nRet = rData.GetGraphic( nFmt, aGrf ); nRet = rData.GetGraphic( nFmt, aGraphic );
break; break;
case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK: case SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK:
...@@ -2188,7 +2214,7 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, ...@@ -2188,7 +2214,7 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
break; break;
default: default:
nRet = rData.GetGraphic( nFmt, aGrf ); nRet = rData.GetGraphic( nFmt, aGraphic );
break; break;
} }
...@@ -2197,7 +2223,8 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, ...@@ -2197,7 +2223,8 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
//!!! check at FileSystem - only then it makes sense to test the graphics !!! //!!! check at FileSystem - only then it makes sense to test the graphics !!!
GraphicFilter &rFlt = GraphicFilter::GetGraphicFilter(); GraphicFilter &rFlt = GraphicFilter::GetGraphicFilter();
nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( aBkmk.GetURL(), aEmptyStr, nRet = GRFILTER_OK == GraphicFilter::LoadGraphic( aBkmk.GetURL(), aEmptyStr,
aGrf, &rFlt ); aGraphic, &rFlt );
if( !nRet && SW_PASTESDR_SETATTR == nAction && if( !nRet && SW_PASTESDR_SETATTR == nAction &&
SOT_FORMAT_FILE == nFmt && SOT_FORMAT_FILE == nFmt &&
// only at frame selection // only at frame selection
...@@ -2211,6 +2238,9 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, ...@@ -2211,6 +2238,9 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
if( nRet ) if( nRet )
{ {
//Check and Perform rotation if needed
lclCheckAndPerformRotation(aGraphic);
String sURL; String sURL;
if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) if( rSh.GetView().GetDocShell()->ISA(SwWebDocShell) )
sURL = aBkmk.GetURL(); sURL = aBkmk.GetURL();
...@@ -2219,18 +2249,18 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, ...@@ -2219,18 +2249,18 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
{ {
case SW_PASTESDR_INSERT: case SW_PASTESDR_INSERT:
SwTransferable::SetSelInShell( rSh, sal_False, pPt ); SwTransferable::SetSelInShell( rSh, sal_False, pPt );
rSh.Insert( sURL, aEmptyStr, aGrf ); rSh.Insert( sURL, aEmptyStr, aGraphic );
break; break;
case SW_PASTESDR_REPLACE: case SW_PASTESDR_REPLACE:
if( rSh.IsObjSelected() ) if( rSh.IsObjSelected() )
{ {
rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGrf ); rSh.ReplaceSdrObj( sURL, aEmptyStr, &aGraphic );
Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() ); Point aPt( pPt ? *pPt : rSh.GetCrsrDocPos() );
SwTransferable::SetSelInShell( rSh, sal_True, &aPt ); SwTransferable::SetSelInShell( rSh, sal_True, &aPt );
} }
else else
rSh.ReRead( sURL, aEmptyStr, &aGrf ); rSh.ReRead( sURL, aEmptyStr, &aGraphic );
break; break;
case SW_PASTESDR_SETATTR: case SW_PASTESDR_SETATTR:
...@@ -2247,13 +2277,13 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh, ...@@ -2247,13 +2277,13 @@ int SwTransferable::_PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
} }
} }
else if( rSh.IsObjSelected() ) else if( rSh.IsObjSelected() )
rSh.Paste( aGrf ); rSh.Paste( aGraphic );
else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() ) else if( OBJCNT_GRF == rSh.GetObjCntTypeOfSelection() )
rSh.ReRead( sURL, aEmptyStr, &aGrf ); rSh.ReRead( sURL, aEmptyStr, &aGraphic );
else else
{ {
SwTransferable::SetSelInShell( rSh, sal_False, pPt ); SwTransferable::SetSelInShell( rSh, sal_False, pPt );
rSh.Insert( aBkmk.GetURL(), aEmptyStr, aGrf ); rSh.Insert( aBkmk.GetURL(), aEmptyStr, aGraphic );
} }
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment