Kaydet (Commit) c4d5cbfa authored tarafından Mihai Varga's avatar Mihai Varga Kaydeden (comit) Mihai Varga

LOK: setClientZoom() - sets the client zoom level

We need to know the client's view level to correctly handle the mouse
events in calc. PaintTile() set a zoom level that corresponds to the
requested tiles and previously postMouseEvent would call SetZoom(1,1).
Now we can make use of knowing the client's view level and call
SetZoom() with the correct parameters

Change-Id: I34b5afcdcc06a671a8ac92c03e87404e42adf4cd

Conflicts:
	sc/source/ui/unoobj/docuno.cxx

Conflicts:
	libreofficekit/source/gtk/lokdocview.cxx
	libreofficekit/source/gtk/tilebuffer.hxx
üst de0dd50f
......@@ -143,6 +143,8 @@ public class Document {
private native int getDocumentTypeNative();
public native void setClientZoom(int nTilePixelWidth, int nTilePixelHeight, int nTileTwipWidth, int nTileTwipHeight);
private native void saveAs(String url, String format, String options);
private native void paintTileNative(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight);
......
......@@ -299,17 +299,18 @@ public class LOKitThread extends Thread {
// to handle hyperlinks, enable single tap even in the Viewer
boolean editing = LOKitShell.isEditingEnabled();
float zoomFactor = mViewportMetrics.getZoomFactor();
if (touchType.equals("LongPress") && editing) {
mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION);
mTileProvider.mouseButtonDown(documentCoordinate, 1);
mTileProvider.mouseButtonUp(documentCoordinate, 1);
mTileProvider.mouseButtonDown(documentCoordinate, 2);
mTileProvider.mouseButtonUp(documentCoordinate, 2);
mTileProvider.mouseButtonDown(documentCoordinate, 1, zoomFactor);
mTileProvider.mouseButtonUp(documentCoordinate, 1, zoomFactor);
mTileProvider.mouseButtonDown(documentCoordinate, 2, zoomFactor);
mTileProvider.mouseButtonUp(documentCoordinate, 2, zoomFactor);
} else if (touchType.equals("SingleTap")) {
mInvalidationHandler.changeStateTo(InvalidationHandler.OverlayState.TRANSITION);
mTileProvider.mouseButtonDown(documentCoordinate, 1);
mTileProvider.mouseButtonUp(documentCoordinate, 1);
mTileProvider.mouseButtonDown(documentCoordinate, 1, zoomFactor);
mTileProvider.mouseButtonUp(documentCoordinate, 1, zoomFactor);
} else if (touchType.equals("GraphicSelectionStart") && editing) {
mTileProvider.setGraphicSelectionStart(documentCoordinate);
} else if (touchType.equals("GraphicSelectionEnd") && editing) {
......
......@@ -408,10 +408,11 @@ public class LOKitTileProvider implements TileProvider {
}
}
private void mouseButton(int type, PointF inDocument, int numberOfClicks) {
private void mouseButton(int type, PointF inDocument, int numberOfClicks, float zoomFactor) {
int x = (int) pixelToTwip(inDocument.x, mDPI);
int y = (int) pixelToTwip(inDocument.y, mDPI);
mDocument.setClientZoom(TILE_SIZE, TILE_SIZE, (int) (mTileWidth / zoomFactor), (int) (mTileHeight / zoomFactor));
mDocument.postMouseEvent(type, x, y, numberOfClicks, Document.MOUSE_BUTTON_LEFT, Document.KEYBOARD_MODIFIER_NONE);
}
......@@ -419,16 +420,16 @@ public class LOKitTileProvider implements TileProvider {
* @see TileProvider#mouseButtonDown(android.graphics.PointF, int)
*/
@Override
public void mouseButtonDown(PointF documentCoordinate, int numberOfClicks) {
mouseButton(Document.MOUSE_EVENT_BUTTON_DOWN, documentCoordinate, numberOfClicks);
public void mouseButtonDown(PointF documentCoordinate, int numberOfClicks, float zoomFactor) {
mouseButton(Document.MOUSE_EVENT_BUTTON_DOWN, documentCoordinate, numberOfClicks, zoomFactor);
}
/**
* @see TileProvider#mouseButtonUp(android.graphics.PointF, int)
*/
@Override
public void mouseButtonUp(PointF documentCoordinate, int numberOfClicks) {
mouseButton(Document.MOUSE_EVENT_BUTTON_UP, documentCoordinate, numberOfClicks);
public void mouseButtonUp(PointF documentCoordinate, int numberOfClicks, float zoomFactor) {
mouseButton(Document.MOUSE_EVENT_BUTTON_UP, documentCoordinate, numberOfClicks, zoomFactor);
}
@Override
......
......@@ -88,7 +88,7 @@ public interface TileProvider {
* @param documentCoordinate - coordinate relative to the document where the mouse button should be triggered
* @param numberOfClicks - number of clicks (1 - single click, 2 - double click)
*/
void mouseButtonDown(PointF documentCoordinate, int numberOfClicks);
void mouseButtonDown(PointF documentCoordinate, int numberOfClicks, float zoomFactor);
/**
......@@ -107,7 +107,7 @@ public interface TileProvider {
* @param documentCoordinate - coordinate relative to the document where the mouse button should be triggered
* @param numberOfClicks - number of clicks (1 - single click, 2 - double click)
*/
void mouseButtonUp(PointF documentCoordinate, int numberOfClicks);
void mouseButtonUp(PointF documentCoordinate, int numberOfClicks, float zoomFactor);
/**
* Post a UNO command to LOK.
......
......@@ -106,6 +106,10 @@ public class ImmutableViewportMetrics {
return new RectF(cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom);
}
public float getZoomFactor() {
return zoomFactor;
}
/*
* Returns the viewport metrics that represent a linear transition between "this" and "to" at
* time "t", which is on the scale [0, 1). This function interpolates all values stored in
......
......@@ -327,7 +327,11 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nY);
static void doc_resetSelection (LibreOfficeKitDocument* pThis);
static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
static void doc_setClientZoom(LibreOfficeKitDocument* pThis,
int nTilePixelWidth,
int nTilePixelHeight,
int nTileTwipWidth,
int nTileTwipHeight);
static int doc_createView(LibreOfficeKitDocument* pThis);
static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
......@@ -367,6 +371,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection;
m_pDocumentClass->getCommandValues = doc_getCommandValues;
m_pDocumentClass->setClientZoom = doc_setClientZoom;
m_pDocumentClass->createView = doc_createView;
m_pDocumentClass->destroyView = doc_destroyView;
......@@ -1479,6 +1484,19 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
}
}
static void doc_setClientZoom(LibreOfficeKitDocument* pThis, int nTilePixelWidth, int nTilePixelHeight,
int nTileTwipWidth, int nTileTwipHeight)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
if (!pDoc)
{
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
return;
}
pDoc->setClientZoom(nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
}
static int doc_createView(LibreOfficeKitDocument* /*pThis*/)
{
SolarMutexGuard aGuard;
......
......@@ -358,4 +358,12 @@ extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Document_getC
return pEnv->NewStringUTF(pValue);
}
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setClientZoom
(JNIEnv* pEnv, jobject aObject, jint nTilePixelWidth, jint nTilePixelHeight, jint nTileTwipWidth, jint nTileTwipHeight)
{
LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
pDocument->pClass->setClientZoom(pDocument, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -181,6 +181,13 @@ struct _LibreOfficeKitDocumentClass
/// @see lok::Document::getCommandValues().
char* (*getCommandValues) (LibreOfficeKitDocument* pThis, const char* pCommand);
/// @see lok::Document::setClientZoom().
void (*setClientZoom) (LibreOfficeKitDocument* pThis,
int nTilePixelWidth,
int nTilePixelHeight,
int nTileTwipWidth,
int nTileTwipHeight);
/// @see lok::Document::createView().
int (*createView) (LibreOfficeKitDocument* pThis);
/// @see lok::Document::destroyView().
......
......@@ -290,6 +290,23 @@ public:
return mpDoc->pClass->getCommandValues(mpDoc, pCommand);
}
/**
* Save the client's view so that we can compute the right zoom level
* for the mouse events. This only affects CALC.
* @param nTilePixelWidth - tile width in pixels
* @param nTilePixelHeight - tile height in pixels
* @param nTileTwipWidth - tile width in twips
* @param nTileTwipHeight - tile height in twips
*/
inline void setClientZoom(
int nTilePixelWidth,
int nTilePixelHeight,
int nTileTwipWidth,
int nTileTwipHeight)
{
mpDoc->pClass->setClientZoom(mpDoc, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
}
/**
* Create a new view for an existing document.
* By default a loaded document has 1 view.
......
......@@ -22,6 +22,9 @@ namespace vcl
class VCL_DLLPUBLIC ITiledRenderable
{
protected:
int nTilePixelWidth, nTilePixelHeight;
int nTileTwipWidth, nTileTwipHeight;
public:
virtual ~ITiledRenderable();
......@@ -179,6 +182,21 @@ public:
/// If the current contents of the clipboard is something we can paste.
virtual bool isMimeTypeSupported() = 0;
/**
* Save the client's view so that we can compute the right zoom level
* for the mouse events.
* @param nTilePixelWidth - tile width in pixels
* @param nTilePixelHeight - tile height in pixels
* @param nTileTwipWidth - tile width in twips
* @param nTileTwipHeight - tile height in twips
*/
virtual void setClientZoom(int /*nTilePixelWidth*/,
int /*nTilePixelHeight*/,
int /*nTileTwipWidth*/,
int /*nTileTwipHeight*/)
{
}
};
} // namespace vcl
......
......@@ -422,6 +422,9 @@ public:
/// @see vcl::ITiledRenderable::isMimeTypeSupported().
virtual bool isMimeTypeSupported() SAL_OVERRIDE;
/// @see vcl::ITiledRenderable::setClientZoom().
virtual void setClientZoom(int nTilePixelWidth, int nTilePixelHeight, int nTileTwipWidth, int nTileTwipHeight) override;
/// @see vcl::ITiledRenderable::getRowColumnHeaders().
virtual OUString getRowColumnHeaders(const Rectangle& rRectangle) SAL_OVERRIDE;
......
......@@ -589,7 +589,8 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int nButt
return;
// update the aLogicMode in ScViewData to something predictable
pViewData->SetZoom(Fraction(1, 1), Fraction(1, 1), true);
pViewData->SetZoom(Fraction(nTilePixelWidth * TWIPS_PER_PIXEL, nTileTwipWidth),
Fraction(nTilePixelHeight * TWIPS_PER_PIXEL, nTileTwipHeight), true);
// Calc operates in pixels...
MouseEvent aEvent(Point(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()), nCount,
......@@ -855,6 +856,14 @@ bool ScModelObj::isMimeTypeSupported()
return EditEngine::HasValidData(aDataHelper.GetTransferable());
}
void ScModelObj::setClientZoom(int nTilePixelWidth_, int nTilePixelHeight_, int nTileTwipWidth_, int nTileTwipHeight_)
{
nTilePixelWidth = nTilePixelWidth_;
nTilePixelHeight = nTilePixelHeight_;
nTileTwipWidth = nTileTwipWidth_;
nTileTwipHeight = nTileTwipHeight_;
}
OUString ScModelObj::getRowColumnHeaders(const Rectangle& rRectangle)
{
ScViewData* pViewData = ScDocShell::GetViewData();
......@@ -913,6 +922,13 @@ void ScModelObj::initializeForTiledRendering()
// tdf#93154: in tiled rendering LO doesn't always detect changes
SvtMiscOptions aMiscOpt;
aMiscOpt.SetSaveAlwaysAllowed(true);
// default tile size in pixels
nTilePixelWidth = 256;
nTilePixelHeight = 256;
// the default zoom level will be 1
nTileTwipWidth = nTilePixelWidth * TWIPS_PER_PIXEL;
nTileTwipHeight = nTilePixelHeight * TWIPS_PER_PIXEL;
}
uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
......
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