2015-06-04 22:09:57 +05:30
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2015-06-04 00:06:46 +05:30
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_TILEBUFFER_HXX
|
|
|
|
#define INCLUDED_TILEBUFFER_HXX
|
|
|
|
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2015-06-04 01:44:47 +05:30
|
|
|
#include <map>
|
2015-06-04 00:06:46 +05:30
|
|
|
|
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.h>
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKitGtk.h>
|
|
|
|
|
2015-06-04 13:56:46 +05:30
|
|
|
// We know that VirtualDevices use a DPI of 96.
|
|
|
|
const int DPI = 96;
|
|
|
|
// Lets use a square of side 256 pixels for each tile.
|
|
|
|
const int nTileSizePixels = 256;
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/**
|
|
|
|
Converts the pixel value to zoom independent twip value.
|
|
|
|
|
|
|
|
@param fInput value to convert
|
|
|
|
@param zoom the current zoom level
|
|
|
|
|
|
|
|
@return the pixels value corresponding to given twip value
|
|
|
|
*/
|
2015-06-04 13:56:46 +05:30
|
|
|
float pixelToTwip(float fInput, float zoom);
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/**
|
|
|
|
Converts the zoom independent twip value pixel value.
|
|
|
|
|
|
|
|
@param fInput value to convert
|
|
|
|
@param zoom the current zoom level
|
|
|
|
|
|
|
|
@return the twip value corresponding to given pixel value
|
|
|
|
*/
|
2015-06-04 13:56:46 +05:30
|
|
|
float twipToPixel(float fInput, float zoom);
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/**
|
|
|
|
This class represents a single tile in the tile buffer.
|
|
|
|
It encloses a reference to GdkPixBuf containing the pixel data of the tile.
|
2015-06-04 00:06:46 +05:30
|
|
|
*/
|
|
|
|
class Tile
|
|
|
|
{
|
2015-06-04 03:32:18 +05:30
|
|
|
public:
|
2015-06-12 11:23:37 +02:00
|
|
|
Tile() : valid(false), m_pBuffer(0) {}
|
2015-06-04 22:09:57 +05:30
|
|
|
~Tile() { }
|
2015-06-04 00:06:46 +05:30
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/**
|
|
|
|
Tells if this tile is valid or not. Initialised to 0 (invalid) during
|
|
|
|
object creation.
|
|
|
|
*/
|
2015-06-04 03:32:18 +05:30
|
|
|
bool valid;
|
2015-06-04 22:09:57 +05:30
|
|
|
|
|
|
|
/// Function to get the pointer to enclosing GdkPixbuf
|
|
|
|
GdkPixbuf* getBuffer();
|
|
|
|
/// Destroys the enclosing GdkPixbuf object pointed to by m_pBuffer
|
|
|
|
void release();
|
|
|
|
/// Used to set the pixel buffer of this object
|
|
|
|
void setPixbuf(GdkPixbuf*);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Pixel buffer data for this tile
|
2015-06-04 03:32:18 +05:30
|
|
|
GdkPixbuf *m_pBuffer;
|
2015-06-04 00:06:46 +05:30
|
|
|
};
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/**
|
|
|
|
This class represents the tile buffer which is responsible for managing,
|
|
|
|
reusing and caching all the already rendered tiles. If the given tile is not
|
|
|
|
present in the buffer, call to LOK Document's (m_pLOKDocument) paintTile
|
|
|
|
method is made which fetches the rendered tile from LO core and store it in
|
|
|
|
buffer for future reuse.
|
2015-06-04 00:06:46 +05:30
|
|
|
*/
|
|
|
|
class TileBuffer
|
|
|
|
{
|
2015-06-04 03:32:18 +05:30
|
|
|
public:
|
|
|
|
TileBuffer(LibreOfficeKitDocument *document,
|
|
|
|
int columns)
|
|
|
|
: m_pLOKDocument(document)
|
|
|
|
, m_nWidth(columns)
|
2015-07-19 01:03:56 +05:30
|
|
|
{
|
|
|
|
GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
|
|
|
|
m_DummyTile.setPixbuf(pPixBuf);
|
|
|
|
}
|
2015-06-04 00:06:46 +05:30
|
|
|
|
2015-06-04 03:32:18 +05:30
|
|
|
~TileBuffer() {}
|
2015-06-04 00:06:46 +05:30
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/**
|
|
|
|
Gets the underlying Tile object for given position. The position (0, 0)
|
|
|
|
points to the left top most tile of the buffer.
|
|
|
|
|
|
|
|
If the tile is not cached by the tile buffer, it makes a paintTile call
|
|
|
|
to LO core asking to render the given tile. It then stores the tile for
|
|
|
|
future reuse.
|
|
|
|
|
|
|
|
@param x the tile along the x-axis of the buffer
|
|
|
|
@param y the tile along the y-axis of the buffer
|
2015-06-08 15:24:12 +05:30
|
|
|
@param aZoom This function needs the zoom factor to draw the tile using paintTile()
|
2015-06-04 22:09:57 +05:30
|
|
|
|
|
|
|
@return the tile at the mentioned position (x, y)
|
|
|
|
*/
|
2015-07-24 01:10:42 +05:30
|
|
|
Tile& getTile(int x, int y, float aZoom, GTask* task);
|
2015-06-04 22:09:57 +05:30
|
|
|
/// Destroys all the tiles in the tile buffer; also frees the memory allocated
|
|
|
|
/// for all the Tile objects.
|
|
|
|
void resetAllTiles();
|
|
|
|
/**
|
|
|
|
Marks the tile as invalid. The tile (0, 0) is the left topmost tile in
|
|
|
|
the tile buffer.
|
|
|
|
|
|
|
|
@param x the position of tile along x-axis
|
|
|
|
@param y the position of tile along y-axis
|
|
|
|
*/
|
2015-07-24 01:10:42 +05:30
|
|
|
void setInvalid(int x, int y, float zoom, GTask* task);
|
2015-06-04 22:09:57 +05:30
|
|
|
|
|
|
|
/// Contains the reference to the LOK Document that this tile buffer is for.
|
2015-06-04 03:32:18 +05:30
|
|
|
LibreOfficeKitDocument *m_pLOKDocument;
|
2015-06-04 22:09:57 +05:30
|
|
|
/// Stores all the tiles cached by this tile buffer.
|
2015-06-04 03:32:18 +05:30
|
|
|
std::map<int, Tile> m_mTiles;
|
2015-06-04 22:09:57 +05:30
|
|
|
/// Width of the current tile buffer (number of columns)
|
2015-06-04 03:32:18 +05:30
|
|
|
int m_nWidth;
|
2015-07-19 01:03:56 +05:30
|
|
|
/// Dummy tile
|
|
|
|
Tile m_DummyTile;
|
2015-06-04 00:06:46 +05:30
|
|
|
};
|
|
|
|
|
2015-07-24 01:10:42 +05:30
|
|
|
enum
|
|
|
|
{
|
|
|
|
LOK_LOAD_DOC,
|
|
|
|
LOK_POST_COMMAND,
|
|
|
|
LOK_SET_EDIT,
|
|
|
|
LOK_SET_PARTMODE,
|
|
|
|
LOK_SET_PART,
|
|
|
|
LOK_POST_KEY,
|
|
|
|
LOK_PAINT_TILE
|
|
|
|
};
|
|
|
|
|
2015-07-22 20:25:36 +05:30
|
|
|
/**
|
2015-07-24 01:10:42 +05:30
|
|
|
A struct that we use to store the data about the LOK call.
|
|
|
|
|
|
|
|
Object of this type is passed with all the LOK calls,
|
|
|
|
so that they can be idenitified. Additionally, it also contains
|
|
|
|
the data that LOK call needs.
|
2015-07-22 20:25:36 +05:30
|
|
|
*/
|
2015-07-24 01:10:42 +05:30
|
|
|
struct LOEvent
|
2015-07-19 01:03:56 +05:30
|
|
|
{
|
2015-07-24 01:10:42 +05:30
|
|
|
/// To identify the type of LOK call
|
|
|
|
int m_nType;
|
|
|
|
const gchar* m_pCommand;
|
|
|
|
const gchar* m_pArguments;
|
|
|
|
gchar* m_pPath;
|
|
|
|
gboolean m_bEdit;
|
|
|
|
int m_nPartMode;
|
|
|
|
int m_nPart;
|
|
|
|
int m_nKeyEvent;
|
|
|
|
int m_nCharCode;
|
|
|
|
int m_nKeyCode;
|
|
|
|
|
2015-07-19 01:03:56 +05:30
|
|
|
int m_nX;
|
|
|
|
int m_nY;
|
|
|
|
float m_fZoom;
|
|
|
|
|
2015-07-24 01:10:42 +05:30
|
|
|
/// Constructor to easily instantiate an object for LOK call of `type' type.
|
|
|
|
LOEvent(int type)
|
|
|
|
: m_nType(type) {}
|
|
|
|
|
|
|
|
LOEvent(int type, const gchar* pCommand, const gchar* pArguments)
|
|
|
|
: m_nType(type),
|
|
|
|
m_pCommand(pCommand),
|
|
|
|
m_pArguments(pArguments) {}
|
|
|
|
|
|
|
|
LOEvent(int type, const gchar* pPath)
|
|
|
|
: m_nType(type)
|
|
|
|
{
|
|
|
|
m_pPath = g_strdup(pPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOEvent(int type, int nKeyEvent, int nCharCode, int nKeyCode)
|
|
|
|
: m_nType(type),
|
|
|
|
m_nKeyEvent(nKeyEvent),
|
|
|
|
m_nCharCode(nCharCode),
|
|
|
|
m_nKeyCode(nKeyCode) {}
|
|
|
|
|
|
|
|
LOEvent(int type, int x, int y, float zoom)
|
|
|
|
: m_nType(type),
|
|
|
|
m_nX(x),
|
2015-07-19 01:03:56 +05:30
|
|
|
m_nY(y),
|
2015-07-24 01:10:42 +05:30
|
|
|
m_fZoom(zoom) {}
|
2015-07-19 01:03:56 +05:30
|
|
|
};
|
|
|
|
|
2015-06-04 00:06:46 +05:30
|
|
|
#endif // INCLUDED_TILEBUFFER_HXX
|
2015-06-04 22:09:57 +05:30
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|