[Libreoffice-commits] core.git: 20 commits - include/LibreOfficeKit libreofficekit/Library_libreofficekitgtk.mk libreofficekit/qa libreofficekit/source
Pranav Kant
pranavk at gnome.org
Tue Jun 9 01:44:51 PDT 2015
include/LibreOfficeKit/LibreOfficeKitGtk.h | 73 +-
libreofficekit/Library_libreofficekitgtk.mk | 1
libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 52 -
libreofficekit/source/gtk/lokdocview.cxx | 527 ++++++++++----------
libreofficekit/source/gtk/tilebuffer.cxx | 111 ++++
libreofficekit/source/gtk/tilebuffer.hxx | 135 +++++
6 files changed, 587 insertions(+), 312 deletions(-)
New commits:
commit 2afe94dbfc85cbcde1399267379a466d527998a4
Author: Pranav Kant <pranavk at gnome.org>
Date: Mon Jun 8 15:24:12 2015 +0530
tilebuffer: tileSize as member variable is superfluous
Change-Id: I1eae8c96c12ba4d272341f45fee6c1fd66ab9e28
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 64955f7..5f768e7 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -274,7 +274,7 @@ LOKDocView_Impl::CallbackData::CallbackData(int nType, const std::string& rPaylo
LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView)
: m_pDocView(pDocView),
m_pDrawingArea(gtk_drawing_area_new()),
- m_aTileBuffer(TileBuffer(0,0,0,0)),
+ m_aTileBuffer(TileBuffer(0,0,0)),
m_fZoom(1),
m_pOffice(0),
m_pDocument(0),
@@ -1236,7 +1236,6 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_doc_view_open_document( LOKDocView* pDocView,
pDocView->m_pImpl->m_aTileBuffer = TileBuffer(pDocView->m_pImpl->m_pDocument,
- nTileSizePixels,
nRows,
nColumns);
gtk_widget_set_size_request(pDocView->m_pImpl->m_pDrawingArea,
@@ -1263,7 +1262,6 @@ SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_zoom ( LOKDocView* pDocView, float fZ
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
pDocView->m_pImpl->m_aTileBuffer = TileBuffer(pDocView->m_pImpl->m_pDocument,
- nTileSizePixels,
nRows,
nColumns);
gtk_widget_set_size_request(pDocView->m_pImpl->m_pDrawingArea,
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 774806b..1d6a8b6 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -79,7 +79,7 @@ Tile& TileBuffer::getTile(int x, int y, float aZoom)
if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
{
- GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
+ GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
if (!pPixBuf)
{
g_info ("Error allocating memory to pixbuf");
@@ -88,16 +88,16 @@ Tile& TileBuffer::getTile(int x, int y, float aZoom)
unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
GdkRectangle aTileRectangle;
- aTileRectangle.x = pixelToTwip(m_nTileSize, aZoom) * y;
- aTileRectangle.y = pixelToTwip(m_nTileSize, aZoom) * x;
+ aTileRectangle.x = pixelToTwip(nTileSizePixels, aZoom) * y;
+ aTileRectangle.y = pixelToTwip(nTileSizePixels, aZoom) * x;
g_info ("Rendering (%d, %d)", x, y);
m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
pBuffer,
- m_nTileSize, m_nTileSize,
+ nTileSizePixels, nTileSizePixels,
aTileRectangle.x, aTileRectangle.y,
- pixelToTwip(m_nTileSize, aZoom),
- pixelToTwip(m_nTileSize, aZoom));
+ pixelToTwip(nTileSizePixels, aZoom),
+ pixelToTwip(nTileSizePixels, aZoom));
//create a mapping for it
m_mTiles[index].setPixbuf(pPixBuf);
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index 5966004..ea8e524 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -83,11 +83,9 @@ class TileBuffer
{
public:
TileBuffer(LibreOfficeKitDocument *document,
- int tileSize,
int rows,
int columns)
: m_pLOKDocument(document)
- , m_nTileSize(tileSize)
, m_nWidth(columns)
, m_nHeight(rows)
{ }
@@ -104,10 +102,11 @@ class TileBuffer
@param x the tile along the x-axis of the buffer
@param y the tile along the y-axis of the buffer
+ @param aZoom This function needs the zoom factor to draw the tile using paintTile()
@return the tile at the mentioned position (x, y)
*/
- Tile& getTile(int x, int y);
+ Tile& getTile(int x, int y, float aZoom);
/// Destroys all the tiles in the tile buffer; also frees the memory allocated
/// for all the Tile objects.
void resetAllTiles();
@@ -123,8 +122,6 @@ class TileBuffer
private:
/// Contains the reference to the LOK Document that this tile buffer is for.
LibreOfficeKitDocument *m_pLOKDocument;
- /// The side of each squared tile in pixels.
- int m_nTileSize;
/// Stores all the tiles cached by this tile buffer.
std::map<int, Tile> m_mTiles;
/// Width of the current tile buffer (number of columns)
commit 16222190ec4cf6b83e7771a8d714a7dbb968c42b
Author: Pranav Kant <pranavk at gnome.org>
Date: Mon Jun 8 15:08:44 2015 +0530
tilebuffer: ZoomFactor as member variable is superfluous
Change-Id: I9f533f577f959c9a715e5214be99ca59cb0d206c
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 31fefc7..64955f7 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -846,7 +846,7 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
{
//g_info("tile_buffer_get_tile (%d, %d)", nRow, nColumn);
- Tile& currentTile = m_aTileBuffer.getTile(nRow, nColumn);
+ Tile& currentTile = m_aTileBuffer.getTile(nRow, nColumn, m_fZoom);
GdkPixbuf* pPixBuf = currentTile.getBuffer();
gdk_cairo_set_source_pixbuf (pcairo, pPixBuf,
@@ -1262,7 +1262,10 @@ SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_zoom ( LOKDocView* pDocView, float fZ
guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
- pDocView->m_pImpl->m_aTileBuffer.setZoom(fZoom, nRows, nColumns);
+ pDocView->m_pImpl->m_aTileBuffer = TileBuffer(pDocView->m_pImpl->m_pDocument,
+ nTileSizePixels,
+ nRows,
+ nColumns);
gtk_widget_set_size_request(pDocView->m_pImpl->m_pDrawingArea,
nDocumentWidthPixels,
nDocumentHeightPixels);
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 0c79823..774806b 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -51,17 +51,6 @@ void Tile::setPixbuf(GdkPixbuf *buffer)
TileBuffer class member functions
----------------------------------
*/
-void TileBuffer::setZoom(float newZoomFactor, int rows, int columns)
-{
- m_fZoomFactor = newZoomFactor;
-
- resetAllTiles();
-
- // set new buffer width and height
- m_nWidth = columns;
- m_nHeight = rows;
-}
-
void TileBuffer::resetAllTiles()
{
std::map<int, Tile>::iterator it = m_mTiles.begin();
@@ -84,7 +73,7 @@ void TileBuffer::setInvalid(int x, int y)
}
}
-Tile& TileBuffer::getTile(int x, int y)
+Tile& TileBuffer::getTile(int x, int y, float aZoom)
{
int index = x * m_nWidth + y;
if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
@@ -99,16 +88,16 @@ Tile& TileBuffer::getTile(int x, int y)
unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
GdkRectangle aTileRectangle;
- aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y;
- aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x;
+ aTileRectangle.x = pixelToTwip(m_nTileSize, aZoom) * y;
+ aTileRectangle.y = pixelToTwip(m_nTileSize, aZoom) * x;
g_info ("Rendering (%d, %d)", x, y);
m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
pBuffer,
m_nTileSize, m_nTileSize,
aTileRectangle.x, aTileRectangle.y,
- pixelToTwip(m_nTileSize, m_fZoomFactor),
- pixelToTwip(m_nTileSize, m_fZoomFactor));
+ pixelToTwip(m_nTileSize, aZoom),
+ pixelToTwip(m_nTileSize, aZoom));
//create a mapping for it
m_mTiles[index].setPixbuf(pPixBuf);
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index 7e2132f..5966004 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -88,7 +88,6 @@ class TileBuffer
int columns)
: m_pLOKDocument(document)
, m_nTileSize(tileSize)
- , m_fZoomFactor(1)
, m_nWidth(columns)
, m_nHeight(rows)
{ }
@@ -96,17 +95,6 @@ class TileBuffer
~TileBuffer() {}
/**
- Sets the zoom factor (m_fZoomFactor) for this tile buffer. Setting the
- zoom factor invalidates whole of the tile buffer, destroys all tiles
- contained within it, and sets new width, height values for tile
- buffer. The width, height value of tile buffer is the width and height of
- the table containing all possible tiles (rendered and non-rendered) that
- this buffer can have.
-
- @param zoomFactor the new zoom factor value to set
- */
- void setZoom(float zoomFactor, int rows, int columns);
- /**
Gets the underlying Tile object for given position. The position (0, 0)
points to the left top most tile of the buffer.
@@ -137,8 +125,6 @@ class TileBuffer
LibreOfficeKitDocument *m_pLOKDocument;
/// The side of each squared tile in pixels.
int m_nTileSize;
- /// The zoom factor that the tile buffer is currently rendered to.
- float m_fZoomFactor;
/// Stores all the tiles cached by this tile buffer.
std::map<int, Tile> m_mTiles;
/// Width of the current tile buffer (number of columns)
commit 03655e67cbb26a6a7b8da4b5e5a18eae4742b412
Author: Pranav Kant <pranavk at gnome.org>
Date: Mon Jun 8 14:17:17 2015 +0530
lokdocview: Make tilebuffer an instance
Change-Id: I06dae2e7a5067160326f4c65f5975c4e5afb05ce
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 166fecb..31fefc7 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -42,7 +42,7 @@ struct LOKDocView_Impl
{
LOKDocView* m_pDocView;
GtkWidget *m_pDrawingArea;
- TileBuffer *m_pTileBuffer;
+ TileBuffer m_aTileBuffer;
float m_fZoom;
@@ -192,7 +192,7 @@ struct LOKDocView_Impl
void searchNotFound(const std::string& rPayload);
/// LOK decided to change parts, need to update UI.
void setPart(const std::string& rPayload);
- /// Sets the tiles enclosed by rRectangle as invalid in m_pTileBuffer
+ /// Sets the tiles enclosed by rRectangle as invalid in m_aTileBuffer
void setTilesInvalid(const GdkRectangle& rRectangle);
};
@@ -273,35 +273,36 @@ LOKDocView_Impl::CallbackData::CallbackData(int nType, const std::string& rPaylo
LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView)
: m_pDocView(pDocView),
- m_pDrawingArea(gtk_drawing_area_new()),
- m_fZoom(1),
- m_pOffice(0),
- m_pDocument(0),
- m_nDocumentWidthTwips(0),
- m_nDocumentHeightTwips(0),
- m_bEdit(false),
- m_aVisibleCursor({0, 0, 0, 0}),
- m_bCursorOverlayVisible(false),
- m_bCursorVisible(true),
- m_nLastButtonPressTime(0),
- m_nLastButtonReleaseTime(0),
- m_aTextSelectionStart({0, 0, 0, 0}),
- m_aTextSelectionEnd({0, 0, 0, 0}),
- m_aGraphicSelection({0, 0, 0, 0}),
- m_bInDragGraphicSelection(false),
-
- // Start/middle/end handle.
- m_pHandleStart(0),
- m_aHandleStartRect({0, 0, 0, 0}),
- m_bInDragStartHandle(false),
- m_pHandleMiddle(0),
- m_aHandleMiddleRect({0, 0, 0, 0}),
- m_bInDragMiddleHandle(false),
- m_pHandleEnd(0),
- m_aHandleEndRect({0, 0, 0, 0}),
- m_bInDragEndHandle(false),
-
- m_pGraphicHandle(0)
+ m_pDrawingArea(gtk_drawing_area_new()),
+ m_aTileBuffer(TileBuffer(0,0,0,0)),
+ m_fZoom(1),
+ m_pOffice(0),
+ m_pDocument(0),
+ m_nDocumentWidthTwips(0),
+ m_nDocumentHeightTwips(0),
+ m_bEdit(false),
+ m_aVisibleCursor({0, 0, 0, 0}),
+ m_bCursorOverlayVisible(false),
+ m_bCursorVisible(true),
+ m_nLastButtonPressTime(0),
+ m_nLastButtonReleaseTime(0),
+ m_aTextSelectionStart({0, 0, 0, 0}),
+ m_aTextSelectionEnd({0, 0, 0, 0}),
+ m_aGraphicSelection({0, 0, 0, 0}),
+ m_bInDragGraphicSelection(false),
+
+ // Start/middle/end handle.
+ m_pHandleStart(0),
+ m_aHandleStartRect({0, 0, 0, 0}),
+ m_bInDragStartHandle(false),
+ m_pHandleMiddle(0),
+ m_aHandleMiddleRect({0, 0, 0, 0}),
+ m_bInDragMiddleHandle(false),
+ m_pHandleEnd(0),
+ m_aHandleEndRect({0, 0, 0, 0}),
+ m_bInDragEndHandle(false),
+
+ m_pGraphicHandle(0)
{
memset(&m_aGraphicHandleRects, 0, sizeof(m_aGraphicHandleRects));
memset(&m_bInDragGraphicHandles, 0, sizeof(m_bInDragGraphicHandles));
@@ -683,7 +684,7 @@ void LOKDocView_Impl::setTilesInvalid(const GdkRectangle& rRectangle)
for (int i = aStart.x; i < aEnd.x; i++)
for (int j = aStart.y; j < aEnd.y; j++)
- m_pTileBuffer->setInvalid(i, j);
+ m_aTileBuffer.setInvalid(i, j);
}
void LOKDocView_Impl::renderHandle(cairo_t* pCairo, const GdkRectangle& rCursor, cairo_surface_t* pHandle, GdkRectangle& rRectangle)
@@ -845,7 +846,7 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
{
//g_info("tile_buffer_get_tile (%d, %d)", nRow, nColumn);
- Tile& currentTile = m_pTileBuffer->getTile(nRow, nColumn);
+ Tile& currentTile = m_aTileBuffer.getTile(nRow, nColumn);
GdkPixbuf* pPixBuf = currentTile.getBuffer();
gdk_cairo_set_source_pixbuf (pcairo, pPixBuf,
@@ -969,7 +970,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
setTilesInvalid(aRectangle);
}
else
- m_pTileBuffer->resetAllTiles();
+ m_aTileBuffer.resetAllTiles();
gtk_widget_queue_draw(m_pDrawingArea);
}
@@ -1232,10 +1233,12 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_doc_view_open_document( LOKDocView* pDocView,
// Total number of rows / columns in this document.
guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
- pDocView->m_pImpl->m_pTileBuffer = new TileBuffer(pDocView->m_pImpl->m_pDocument,
- nTileSizePixels,
- nRows,
- nColumns);
+
+
+ pDocView->m_pImpl->m_aTileBuffer = TileBuffer(pDocView->m_pImpl->m_pDocument,
+ nTileSizePixels,
+ nRows,
+ nColumns);
gtk_widget_set_size_request(pDocView->m_pImpl->m_pDrawingArea,
nDocumentWidthPixels,
nDocumentHeightPixels);
@@ -1259,7 +1262,7 @@ SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_zoom ( LOKDocView* pDocView, float fZ
guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
- pDocView->m_pImpl->m_pTileBuffer->setZoom(fZoom, nRows, nColumns);
+ pDocView->m_pImpl->m_aTileBuffer.setZoom(fZoom, nRows, nColumns);
gtk_widget_set_size_request(pDocView->m_pImpl->m_pDrawingArea,
nDocumentWidthPixels,
nDocumentHeightPixels);
commit a0ce0dd519ec298bf7df0111dca1e1c6fdc3a1ee
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Jun 8 08:02:37 2015 +0200
libreofficekit: fix RHEL5 build of tilebuffer
Change-Id: I27da86c774f0450c844e742563c4a8de3f23ad34
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index b6c529f..166fecb 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1335,6 +1335,7 @@ SAL_DLLPUBLIC_EXPORT void lok_doc_view_post_key(GtkWidget* /*pWidget*/, GdkEvent
SAL_DLLPUBLIC_EXPORT void lok_doc_view_get_visarea(LOKDocView* pThis, GdkRectangle* pArea)
{
+#if GTK_CHECK_VERSION(2,14,0) // we need gtk_adjustment_get_page_size()
float zoom = pThis->m_pImpl->m_fZoom;
GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pThis));
pArea->x = pixelToTwip(gtk_adjustment_get_value(pHAdjustment),zoom);
@@ -1342,6 +1343,7 @@ SAL_DLLPUBLIC_EXPORT void lok_doc_view_get_visarea(LOKDocView* pThis, GdkRectang
GtkAdjustment* pVAdjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(pThis));
pArea->y = pixelToTwip(gtk_adjustment_get_value(pVAdjustment), zoom);
pArea->height = pixelToTwip(gtk_adjustment_get_page_size(pVAdjustment), zoom);
+#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 3380380..0c79823 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -9,6 +9,10 @@
#include "tilebuffer.hxx"
+#if !GLIB_CHECK_VERSION(2,40,0)
+#define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
+#endif
+
/* ------------------
Utility functions
------------------
commit 0e947f33130c55881035e39dcb1c5e64c33297e9
Author: Pranav Kant <pranavk at gnome.org>
Date: Sun Jun 7 22:28:01 2015 +0530
lokdocview: mark *_get_type() with const function attribute
Use G_GNUC_CONST that adds const function attribute to
lok_doc_view_get_type() for better performance.
Change-Id: Id79f0395a98c4f98b46303e9b5ee1e103fbe331f
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 747e45e..e84feee 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -44,7 +44,7 @@ struct _LOKDocViewClass
void (* part_changed) (LOKDocView* pView, int new_part);
};
-GType lok_doc_view_get_type (void);
+GType lok_doc_view_get_type (void) G_GNUC_CONST;
GtkWidget* lok_doc_view_new (LibreOfficeKit* pOffice );
gboolean lok_doc_view_open_document (LOKDocView* pDocView,
char* pPath);
commit c5f1f7ad2710914fdd6645dd8ce958c70d1d8381
Author: Pranav Kant <pranavk at gnome.org>
Date: Sat Jun 6 03:10:31 2015 +0530
lokdocview: Modernise LOKDocView as GObject
Change-Id: I3bbd07ce8163890f9b88567966622dd4fbe9d94d
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 069c565..747e45e 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -18,9 +18,13 @@
G_BEGIN_DECLS
-#define LOK_DOC_VIEW(obj) GTK_CHECK_CAST (obj, lok_doc_view_get_type(), LOKDocView)
-#define LOK_DOC_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, lok_doc_view_get_type(), LOKDocViewClass)
-#define IS_LOK_DOC_VIEW(obj) GTK_CHECK_TYPE (obj, lok_doc_view_get_type())
+#define LOK_TYPE_DOC_VIEW (lok_doc_view_get_type())
+#define LOK_DOC_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), LOK_TYPE_DOC_VIEW, LOKDocView))
+#define LOK_IS_DOC_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), LOK_TYPE_DOC_VIEW))
+#define LOK_DOC_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), LOK_TYPE_DOC_VIEW, LOKDocViewClass))
+#define LOK_IS_DOC_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), LOK_TYPE_DOC_VIEW))
+#define LOK_DOC_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LOK_TYPE_DOC_VIEW, LOKDocViewClass))
+
typedef struct _LOKDocView LOKDocView;
typedef struct _LOKDocViewClass LOKDocViewClass;
@@ -40,40 +44,45 @@ struct _LOKDocViewClass
void (* part_changed) (LOKDocView* pView, int new_part);
};
-guint lok_doc_view_get_type (void);
-GtkWidget* lok_doc_view_new ( LibreOfficeKit* pOffice );
-gboolean lok_doc_view_open_document (LOKDocView* pDocView,
- char* pPath);
+GType lok_doc_view_get_type (void);
+GtkWidget* lok_doc_view_new (LibreOfficeKit* pOffice );
+gboolean lok_doc_view_open_document (LOKDocView* pDocView,
+ char* pPath);
/// Gets the document the viewer displays.
-LibreOfficeKitDocument* lok_doc_view_get_document(LOKDocView* pDocView);
-
-void lok_doc_view_set_zoom (LOKDocView* pDocView,
- float fZoom);
-float lok_doc_view_get_zoom (LOKDocView* pDocView);
-
-int lok_doc_view_get_parts (LOKDocView* pDocView);
-int lok_doc_view_get_part (LOKDocView* pDocView);
-void lok_doc_view_set_part (LOKDocView* pDocView,
- int nPart);
-char* lok_doc_view_get_part_name (LOKDocView* pDocView,
- int nPart);
-void lok_doc_view_set_partmode (LOKDocView* pDocView,
- int nPartMode);
+LibreOfficeKitDocument* lok_doc_view_get_document (LOKDocView* pDocView);
+
+void lok_doc_view_set_zoom (LOKDocView* pDocView,
+ float fZoom);
+float lok_doc_view_get_zoom (LOKDocView* pDocView);
+
+int lok_doc_view_get_parts (LOKDocView* pDocView);
+int lok_doc_view_get_part (LOKDocView* pDocView);
+void lok_doc_view_set_part (LOKDocView* pDocView,
+ int nPart);
+char* lok_doc_view_get_part_name (LOKDocView* pDocView,
+ int nPart);
+void lok_doc_view_set_partmode (LOKDocView* pDocView,
+ int nPartMode);
/// Sets if the viewer is actually an editor or not.
-void lok_doc_view_set_edit (LOKDocView* pDocView,
- gboolean bEdit);
+void lok_doc_view_set_edit (LOKDocView* pDocView,
+ gboolean bEdit);
/// Gets if the viewer is actually an editor or not.
-gboolean lok_doc_view_get_edit (LOKDocView* pDocView);
+gboolean lok_doc_view_get_edit (LOKDocView* pDocView);
/// Posts the .uno: command to the LibreOfficeKit.
-void lok_doc_view_post_command (LOKDocView* pDocView, const char* pCommand, const char* pArguments);
+void lok_doc_view_post_command (LOKDocView* pDocView,
+ const char* pCommand,
+ const char* pArguments);
/// Posts a keyboard event to LibreOfficeKit.
-void lok_doc_view_post_key (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData);
+void lok_doc_view_post_key (GtkWidget* pWidget,
+ GdkEventKey* pEvent,
+ gpointer pData);
/// Get the visible area of the document (in twips).
-void lok_doc_view_get_visarea(LOKDocView* pThis, GdkRectangle* pArea);
+void lok_doc_view_get_visarea (LOKDocView* pThis,
+ GdkRectangle* pArea);
G_END_DECLS
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 4de4c71..b6c529f 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -37,26 +37,6 @@
// Number of handles around a graphic selection.
#define GRAPHIC_HANDLE_COUNT 8
-namespace {
-
-/// Sets rWidth and rHeight from a "width, height" string.
-void payloadToSize(const char* pPayload, long& rWidth, long& rHeight)
-{
- rWidth = rHeight = 0;
- gchar** ppCoordinates = g_strsplit(pPayload, ", ", 2);
- gchar** ppCoordinate = ppCoordinates;
- if (!*ppCoordinate)
- return;
- rWidth = atoi(*ppCoordinate);
- ++ppCoordinate;
- if (!*ppCoordinate)
- return;
- rHeight = atoi(*ppCoordinate);
- g_strfreev(ppCoordinates);
-}
-
-}
-
/// Holds data used by LOKDocView only.
struct LOKDocView_Impl
{
@@ -216,6 +196,44 @@ struct LOKDocView_Impl
void setTilesInvalid(const GdkRectangle& rRectangle);
};
+enum
+{
+ EDIT_CHANGED,
+ COMMAND_CHANGED,
+ SEARCH_NOT_FOUND,
+ PART_CHANGED,
+ LAST_SIGNAL
+};
+
+
+static guint doc_view_signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE(LOKDocView, lok_doc_view, GTK_TYPE_SCROLLED_WINDOW)
+
+
+namespace {
+
+/// Sets rWidth and rHeight from a "width, height" string.
+void payloadToSize(const char* pPayload, long& rWidth, long& rHeight)
+{
+ rWidth = rHeight = 0;
+ gchar** ppCoordinates = g_strsplit(pPayload, ", ", 2);
+ gchar** ppCoordinate = ppCoordinates;
+ if (!*ppCoordinate)
+ return;
+ rWidth = atoi(*ppCoordinate);
+ ++ppCoordinate;
+ if (!*ppCoordinate)
+ return;
+ rHeight = atoi(*ppCoordinate);
+ g_strfreev(ppCoordinates);
+}
+
+}
+
+
+
namespace {
/// Implementation of the global callback handler, invoked by globalCallback();
@@ -1073,16 +1091,7 @@ void LOKDocView_Impl::globalCallbackWorkerImpl(int nType, const char* pPayload)
#endif
}
-enum
-{
- EDIT_CHANGED,
- COMMAND_CHANGED,
- SEARCH_NOT_FOUND,
- PART_CHANGED,
- LAST_SIGNAL
-};
-static guint doc_view_signals[LAST_SIGNAL] = { 0 };
void LOKDocView_Impl::commandChanged(const std::string& rString)
{
@@ -1100,9 +1109,8 @@ void LOKDocView_Impl::setPart(const std::string& rString)
renderDocument(0);
}
-static void lok_doc_view_class_init( gpointer ptr )
+static void lok_doc_view_class_init (LOKDocViewClass* pClass)
{
- LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr);
GObjectClass *gobject_class = G_OBJECT_CLASS(pClass);
pClass->edit_changed = NULL;
doc_view_signals[EDIT_CHANGED] =
@@ -1146,9 +1154,8 @@ static void lok_doc_view_class_init( gpointer ptr )
G_TYPE_INT);
}
-static void lok_doc_view_init( GTypeInstance* pInstance, gpointer )
+static void lok_doc_view_init (LOKDocView* pDocView)
{
- LOKDocView* pDocView = reinterpret_cast<LOKDocView *>(pInstance);
// Gtk ScrolledWindow is apparently not fully initialised yet, we specifically
// have to set the [hv]adjustment to prevent GTK assertions from firing, see
// https://bugzilla.gnome.org/show_bug.cgi?id=438114 for more info.
@@ -1183,29 +1190,7 @@ static void lok_doc_view_init( GTypeInstance* pInstance, gpointer )
g_signal_connect(G_OBJECT(pDocView), "destroy", G_CALLBACK(LOKDocView_Impl::destroy), 0);
}
-SAL_DLLPUBLIC_EXPORT guint lok_doc_view_get_type()
-{
- static guint lok_doc_view_type = 0;
-
- if (!lok_doc_view_type)
- {
- char pName[] = "LokDocView";
- GtkTypeInfo lok_doc_view_info =
- {
- pName,
- sizeof( LOKDocView ),
- sizeof( LOKDocViewClass ),
- lok_doc_view_class_init,
- lok_doc_view_init,
- NULL,
- NULL,
- nullptr
- };
-
- lok_doc_view_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_doc_view_info );
- }
- return lok_doc_view_type;
-}
+SAL_DLLPUBLIC_EXPORT GType lok_doc_view_get_type();
SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new( LibreOfficeKit* pOffice )
{
commit c8caa803b43d7091318f1129b7b4cc7ee417c336
Author: Pranav Kant <pranavk at gnome.org>
Date: Sat Jun 6 02:32:54 2015 +0530
lokdocview: Lets follow the GObject naming convention
If we are mentioning this type as DocView, we should break it at each
capital letter.
Change-Id: I76c7eea455281e541b2196a03778018aa127cebe
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 9668904..069c565 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -18,9 +18,9 @@
G_BEGIN_DECLS
-#define LOK_DOCVIEW(obj) GTK_CHECK_CAST (obj, lok_docview_get_type(), LOKDocView)
-#define LOK_DOCVIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, lok_docview_get_type(), LOKDocViewClass)
-#define IS_LOK_DOCVIEW(obj) GTK_CHECK_TYPE (obj, lok_docview_get_type())
+#define LOK_DOC_VIEW(obj) GTK_CHECK_CAST (obj, lok_doc_view_get_type(), LOKDocView)
+#define LOK_DOC_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, lok_doc_view_get_type(), LOKDocViewClass)
+#define IS_LOK_DOC_VIEW(obj) GTK_CHECK_TYPE (obj, lok_doc_view_get_type())
typedef struct _LOKDocView LOKDocView;
typedef struct _LOKDocViewClass LOKDocViewClass;
@@ -40,40 +40,40 @@ struct _LOKDocViewClass
void (* part_changed) (LOKDocView* pView, int new_part);
};
-guint lok_docview_get_type (void);
-GtkWidget* lok_docview_new ( LibreOfficeKit* pOffice );
-gboolean lok_docview_open_document (LOKDocView* pDocView,
+guint lok_doc_view_get_type (void);
+GtkWidget* lok_doc_view_new ( LibreOfficeKit* pOffice );
+gboolean lok_doc_view_open_document (LOKDocView* pDocView,
char* pPath);
/// Gets the document the viewer displays.
-LibreOfficeKitDocument* lok_docview_get_document(LOKDocView* pDocView);
+LibreOfficeKitDocument* lok_doc_view_get_document(LOKDocView* pDocView);
-void lok_docview_set_zoom (LOKDocView* pDocView,
+void lok_doc_view_set_zoom (LOKDocView* pDocView,
float fZoom);
-float lok_docview_get_zoom (LOKDocView* pDocView);
+float lok_doc_view_get_zoom (LOKDocView* pDocView);
-int lok_docview_get_parts (LOKDocView* pDocView);
-int lok_docview_get_part (LOKDocView* pDocView);
-void lok_docview_set_part (LOKDocView* pDocView,
+int lok_doc_view_get_parts (LOKDocView* pDocView);
+int lok_doc_view_get_part (LOKDocView* pDocView);
+void lok_doc_view_set_part (LOKDocView* pDocView,
int nPart);
-char* lok_docview_get_part_name (LOKDocView* pDocView,
+char* lok_doc_view_get_part_name (LOKDocView* pDocView,
int nPart);
-void lok_docview_set_partmode (LOKDocView* pDocView,
+void lok_doc_view_set_partmode (LOKDocView* pDocView,
int nPartMode);
/// Sets if the viewer is actually an editor or not.
-void lok_docview_set_edit (LOKDocView* pDocView,
+void lok_doc_view_set_edit (LOKDocView* pDocView,
gboolean bEdit);
/// Gets if the viewer is actually an editor or not.
-gboolean lok_docview_get_edit (LOKDocView* pDocView);
+gboolean lok_doc_view_get_edit (LOKDocView* pDocView);
/// Posts the .uno: command to the LibreOfficeKit.
-void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand, const char* pArguments);
+void lok_doc_view_post_command (LOKDocView* pDocView, const char* pCommand, const char* pArguments);
/// Posts a keyboard event to LibreOfficeKit.
-void lok_docview_post_key (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData);
+void lok_doc_view_post_key (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData);
/// Get the visible area of the document (in twips).
-void lok_docview_get_visarea(LOKDocView* pThis, GdkRectangle* pArea);
+void lok_doc_view_get_visarea(LOKDocView* pThis, GdkRectangle* pArea);
G_END_DECLS
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index d20f43d..38b29ee 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -71,7 +71,7 @@ static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
if ( pDocView )
{
- fCurrentZoom = lok_docview_get_zoom( LOK_DOCVIEW(pDocView) );
+ fCurrentZoom = lok_doc_view_get_zoom( LOK_DOC_VIEW(pDocView) );
}
if ( strcmp(sName, "gtk-zoom-in") == 0)
@@ -104,7 +104,7 @@ static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
{
if ( pDocView )
{
- lok_docview_set_zoom( LOK_DOCVIEW(pDocView), fZoom );
+ lok_doc_view_set_zoom( LOK_DOC_VIEW(pDocView), fZoom );
}
}
}
@@ -112,10 +112,10 @@ static void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
/// User clicked on the button -> inform LOKDocView.
static void toggleEditing(GtkWidget* /*pButton*/, gpointer /*pItem*/)
{
- LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
bool bActive = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing));
- if (bool(lok_docview_get_edit(pLOKDocView)) != bActive)
- lok_docview_set_edit(pLOKDocView, bActive);
+ if (bool(lok_doc_view_get_edit(pLOKDocView)) != bActive)
+ lok_doc_view_set_edit(pLOKDocView, bActive);
}
/// Toggle the visibility of the findbar.
@@ -137,11 +137,11 @@ static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
/// Handles the key-press-event of the window.
static gboolean signalKey(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData)
{
- LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
#if GTK_CHECK_VERSION(2,18,0) // we need gtk_widget_get_visible()
- if (!gtk_widget_get_visible(pFindbar) && bool(lok_docview_get_edit(pLOKDocView)))
+ if (!gtk_widget_get_visible(pFindbar) && bool(lok_doc_view_get_edit(pLOKDocView)))
{
- lok_docview_post_key(pWidget, pEvent, pData);
+ lok_doc_view_post_key(pWidget, pEvent, pData);
return TRUE;
}
#endif
@@ -159,9 +159,9 @@ static void doSearch(bool bBackwards)
aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean");
aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/value", '/'), bBackwards);
- LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
GdkRectangle aArea;
- lok_docview_get_visarea(pLOKDocView, &aArea);
+ lok_doc_view_get_visarea(pLOKDocView, &aArea);
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointX/type", '/'), "long");
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointX/value", '/'), aArea.x);
aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchStartPointY/type", '/'), "long");
@@ -170,7 +170,7 @@ static void doSearch(bool bBackwards)
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
- lok_docview_post_command(pLOKDocView, ".uno:ExecuteSearch", aStream.str().c_str());
+ lok_doc_view_post_command(pLOKDocView, ".uno:ExecuteSearch", aStream.str().c_str());
}
/// Click handler for the search next button.
@@ -210,8 +210,8 @@ static gboolean signalFindbar(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpoin
/// LOKDocView changed edit state -> inform the tool button.
static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pData*/)
{
- gboolean bEdit = lok_docview_get_edit(pLOKDocView);
- g_info("signalEdit: %d -> %d", bWasEdit, lok_docview_get_edit(pLOKDocView));
+ gboolean bEdit = lok_doc_view_get_edit(pLOKDocView);
+ g_info("signalEdit: %d -> %d", bWasEdit, lok_doc_view_get_edit(pLOKDocView));
if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing)) != bEdit)
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing), bEdit);
}
@@ -233,7 +233,7 @@ static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer
gboolean bEdit = aValue == "true";
if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit)
{
- // Avoid invoking lok_docview_post_command().
+ // Avoid invoking lok_doc_view_post_command().
g_bToolItemBroadcast = false;
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pItem), bEdit);
g_bToolItemBroadcast = true;
@@ -262,11 +262,11 @@ static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
{
if (g_bToolItemBroadcast)
{
- LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+ LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView);
GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
const std::string& rString = g_aToolItemCommandNames[pItem];
- g_info("toggleToolItem: lok_docview_post_command('%s')", rString.c_str());
- lok_docview_post_command(pLOKDocView, rString.c_str(), 0);
+ g_info("toggleToolItem: lok_doc_view_post_command('%s')", rString.c_str());
+ lok_doc_view_post_command(pLOKDocView, rString.c_str(), 0);
}
}
@@ -286,10 +286,10 @@ static void populatePartSelector()
const int nMaxLength = 50;
char sText[nMaxLength];
- int nParts = lok_docview_get_parts( LOK_DOCVIEW(pDocView) );
+ int nParts = lok_doc_view_get_parts( LOK_DOC_VIEW(pDocView) );
for ( int i = 0; i < nParts; i++ )
{
- char* pName = lok_docview_get_part_name( LOK_DOCVIEW(pDocView), i );
+ char* pName = lok_doc_view_get_part_name( LOK_DOC_VIEW(pDocView), i );
assert( pName );
snprintf( sText, nMaxLength, "%i (%s)", i+1, pName );
free( pName );
@@ -297,7 +297,7 @@ static void populatePartSelector()
gtk_combo_box_text_append_text( pPartSelector, sText );
}
gtk_combo_box_set_active( GTK_COMBO_BOX(pPartSelector),
- lok_docview_get_part( LOK_DOCVIEW(pDocView) ) );
+ lok_doc_view_get_part( LOK_DOC_VIEW(pDocView) ) );
}
static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
@@ -306,7 +306,7 @@ static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
if (g_bPartSelectorBroadcast && pDocView)
{
- lok_docview_set_part( LOK_DOCVIEW(pDocView), nPart );
+ lok_doc_view_set_part( LOK_DOC_VIEW(pDocView), nPart );
}
}
@@ -326,7 +326,7 @@ static void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
if ( pDocView )
{
- lok_docview_set_partmode( LOK_DOCVIEW(pDocView), ePartMode );
+ lok_doc_view_set_partmode( LOK_DOC_VIEW(pDocView), ePartMode );
}
}
#endif
@@ -451,7 +451,7 @@ int main( int argc, char* argv[] )
gtk_box_pack_end(GTK_BOX(pVBox), pFindbar, FALSE, FALSE, 0);
// Docview
- pDocView = lok_docview_new( pOffice );
+ pDocView = lok_doc_view_new( pOffice );
g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
@@ -467,10 +467,10 @@ int main( int argc, char* argv[] )
// Hide the findbar by default.
gtk_widget_hide(pFindbar);
- int bOpened = lok_docview_open_document( LOK_DOCVIEW(pDocView), argv[2] );
+ int bOpened = lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2] );
if (!bOpened)
- g_error("main: lok_docview_open_document() failed with '%s'", pOffice->pClass->getError(pOffice));
- assert(lok_docview_get_document(LOK_DOCVIEW(pDocView)));
+ g_error("main: lok_doc_view_open_document() failed with '%s'", pOffice->pClass->getError(pOffice));
+ assert(lok_doc_view_get_document(LOK_DOC_VIEW(pDocView)));
// GtkComboBox requires gtk 2.24 or later
#if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index b901a61..4de4c71 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -123,7 +123,7 @@ struct LOKDocView_Impl
bool m_bInDragGraphicHandles[8];
///@}
- /// Callback data, allocated in lok_docview_callback_worker(), released in lok_docview_callback().
+ /// Callback data, allocated in lok_doc_view_callback_worker(), released in lok_doc_view_callback().
struct CallbackData
{
int m_nType;
@@ -305,7 +305,7 @@ void LOKDocView_Impl::destroy(LOKDocView* pDocView, gpointer /*pData*/)
void LOKDocView_Impl::on_exposed(GtkWidget* /*widget*/, GdkEvent* /*event*/, gpointer userdata)
{
- LOKDocView *pDocView = LOK_DOCVIEW (userdata);
+ LOKDocView *pDocView = LOK_DOC_VIEW (userdata);
pDocView->m_pImpl->renderDocument(0);
}
@@ -461,7 +461,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
}
if (!m_bEdit)
- lok_docview_set_edit(m_pDocView, TRUE);
+ lok_doc_view_set_edit(m_pDocView, TRUE);
switch (pEvent->type)
{
@@ -782,7 +782,7 @@ gboolean LOKDocView_Impl::handleTimeoutImpl()
void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
{
GdkRectangle visibleArea;
- lok_docview_get_visarea (m_pDocView, &visibleArea);
+ lok_doc_view_get_visarea (m_pDocView, &visibleArea);
long nDocumentWidthPixels = twipToPixel(m_nDocumentWidthTwips, m_fZoom);
long nDocumentHeightPixels = twipToPixel(m_nDocumentHeightTwips, m_fZoom);
@@ -1058,7 +1058,7 @@ void LOKDocView_Impl::globalCallbackWorker(int nType, const char* pPayload, void
void LOKDocView_Impl::callbackWorkerImpl(int nType, const char* pPayload)
{
LOKDocView_Impl::CallbackData* pCallback = new LOKDocView_Impl::CallbackData(nType, pPayload ? pPayload : "(nil)", m_pDocView);
- g_info("lok_docview_callback_worker: %s, '%s'", LOKDocView_Impl::callbackTypeToString(nType), pPayload);
+ g_info("lok_doc_view_callback_worker: %s, '%s'", LOKDocView_Impl::callbackTypeToString(nType), pPayload);
#if GTK_CHECK_VERSION(2,12,0)
gdk_threads_add_idle(LOKDocView_Impl::callback, pCallback);
#endif
@@ -1082,30 +1082,30 @@ enum
LAST_SIGNAL
};
-static guint docview_signals[LAST_SIGNAL] = { 0 };
+static guint doc_view_signals[LAST_SIGNAL] = { 0 };
void LOKDocView_Impl::commandChanged(const std::string& rString)
{
- g_signal_emit(m_pDocView, docview_signals[COMMAND_CHANGED], 0, rString.c_str());
+ g_signal_emit(m_pDocView, doc_view_signals[COMMAND_CHANGED], 0, rString.c_str());
}
void LOKDocView_Impl::searchNotFound(const std::string& rString)
{
- g_signal_emit(m_pDocView, docview_signals[SEARCH_NOT_FOUND], 0, rString.c_str());
+ g_signal_emit(m_pDocView, doc_view_signals[SEARCH_NOT_FOUND], 0, rString.c_str());
}
void LOKDocView_Impl::setPart(const std::string& rString)
{
- g_signal_emit(m_pDocView, docview_signals[PART_CHANGED], 0, std::stoi(rString));
+ g_signal_emit(m_pDocView, doc_view_signals[PART_CHANGED], 0, std::stoi(rString));
renderDocument(0);
}
-static void lok_docview_class_init( gpointer ptr )
+static void lok_doc_view_class_init( gpointer ptr )
{
LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr);
GObjectClass *gobject_class = G_OBJECT_CLASS(pClass);
pClass->edit_changed = NULL;
- docview_signals[EDIT_CHANGED] =
+ doc_view_signals[EDIT_CHANGED] =
g_signal_new("edit-changed",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST,
@@ -1115,7 +1115,7 @@ static void lok_docview_class_init( gpointer ptr )
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
pClass->command_changed = NULL;
- docview_signals[COMMAND_CHANGED] =
+ doc_view_signals[COMMAND_CHANGED] =
g_signal_new("command-changed",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_FIRST,
@@ -1125,7 +1125,7 @@ static void lok_docview_class_init( gpointer ptr )
G_TYPE_NONE, 1,
G_TYPE_STRING);
pClass->search_not_found = 0;
- docview_signals[SEARCH_NOT_FOUND] =
+ doc_view_signals[SEARCH_NOT_FOUND] =
g_signal_new("search-not-found",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_FIRST,
@@ -1135,7 +1135,7 @@ static void lok_docview_class_init( gpointer ptr )
G_TYPE_NONE, 1,
G_TYPE_STRING);
pClass->part_changed = 0;
- docview_signals[PART_CHANGED] =
+ doc_view_signals[PART_CHANGED] =
g_signal_new("part-changed",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_FIRST,
@@ -1146,7 +1146,7 @@ static void lok_docview_class_init( gpointer ptr )
G_TYPE_INT);
}
-static void lok_docview_init( GTypeInstance* pInstance, gpointer )
+static void lok_doc_view_init( GTypeInstance* pInstance, gpointer )
{
LOKDocView* pDocView = reinterpret_cast<LOKDocView *>(pInstance);
// Gtk ScrolledWindow is apparently not fully initialised yet, we specifically
@@ -1183,38 +1183,38 @@ static void lok_docview_init( GTypeInstance* pInstance, gpointer )
g_signal_connect(G_OBJECT(pDocView), "destroy", G_CALLBACK(LOKDocView_Impl::destroy), 0);
}
-SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
+SAL_DLLPUBLIC_EXPORT guint lok_doc_view_get_type()
{
- static guint lok_docview_type = 0;
+ static guint lok_doc_view_type = 0;
- if (!lok_docview_type)
+ if (!lok_doc_view_type)
{
char pName[] = "LokDocView";
- GtkTypeInfo lok_docview_info =
+ GtkTypeInfo lok_doc_view_info =
{
pName,
sizeof( LOKDocView ),
sizeof( LOKDocViewClass ),
- lok_docview_class_init,
- lok_docview_init,
+ lok_doc_view_class_init,
+ lok_doc_view_init,
NULL,
NULL,
nullptr
};
- lok_docview_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_docview_info );
+ lok_doc_view_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_doc_view_info );
}
- return lok_docview_type;
+ return lok_doc_view_type;
}
-SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
+SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new( LibreOfficeKit* pOffice )
{
- LOKDocView* pDocView = LOK_DOCVIEW(gtk_type_new(lok_docview_get_type()));
+ LOKDocView* pDocView = LOK_DOC_VIEW(gtk_type_new(lok_doc_view_get_type()));
pDocView->m_pImpl->m_pOffice = pOffice;
return GTK_WIDGET( pDocView );
}
-SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, char* pPath )
+SAL_DLLPUBLIC_EXPORT gboolean lok_doc_view_open_document( LOKDocView* pDocView, char* pPath )
{
if ( pDocView->m_pImpl->m_pDocument )
{
@@ -1260,12 +1260,12 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, c
return TRUE;
}
-SAL_DLLPUBLIC_EXPORT LibreOfficeKitDocument* lok_docview_get_document(LOKDocView* pDocView)
+SAL_DLLPUBLIC_EXPORT LibreOfficeKitDocument* lok_doc_view_get_document(LOKDocView* pDocView)
{
return pDocView->m_pImpl->m_pDocument;
}
-SAL_DLLPUBLIC_EXPORT void lok_docview_set_zoom ( LOKDocView* pDocView, float fZoom )
+SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_zoom ( LOKDocView* pDocView, float fZoom )
{
pDocView->m_pImpl->m_fZoom = fZoom;
long nDocumentWidthPixels = twipToPixel(pDocView->m_pImpl->m_nDocumentWidthTwips, fZoom);
@@ -1283,72 +1283,72 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_set_zoom ( LOKDocView* pDocView, float fZo
pDocView->m_pImpl->renderDocument(0);
}
-SAL_DLLPUBLIC_EXPORT float lok_docview_get_zoom ( LOKDocView* pDocView )
+SAL_DLLPUBLIC_EXPORT float lok_doc_view_get_zoom ( LOKDocView* pDocView )
{
return pDocView->m_pImpl->m_fZoom;
}
-SAL_DLLPUBLIC_EXPORT int lok_docview_get_parts( LOKDocView* pDocView )
+SAL_DLLPUBLIC_EXPORT int lok_doc_view_get_parts( LOKDocView* pDocView )
{
return pDocView->m_pImpl->m_pDocument->pClass->getParts( pDocView->m_pImpl->m_pDocument );
}
-SAL_DLLPUBLIC_EXPORT int lok_docview_get_part( LOKDocView* pDocView )
+SAL_DLLPUBLIC_EXPORT int lok_doc_view_get_part( LOKDocView* pDocView )
{
return pDocView->m_pImpl->m_pDocument->pClass->getPart( pDocView->m_pImpl->m_pDocument );
}
-SAL_DLLPUBLIC_EXPORT void lok_docview_set_part( LOKDocView* pDocView, int nPart)
+SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_part( LOKDocView* pDocView, int nPart)
{
pDocView->m_pImpl->m_pDocument->pClass->setPart( pDocView->m_pImpl->m_pDocument, nPart );
}
-SAL_DLLPUBLIC_EXPORT char* lok_docview_get_part_name( LOKDocView* pDocView, int nPart )
+SAL_DLLPUBLIC_EXPORT char* lok_doc_view_get_part_name( LOKDocView* pDocView, int nPart )
{
return pDocView->m_pImpl->m_pDocument->pClass->getPartName( pDocView->m_pImpl->m_pDocument, nPart );
}
-SAL_DLLPUBLIC_EXPORT void lok_docview_set_partmode( LOKDocView* pDocView,
+SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_partmode( LOKDocView* pDocView,
int nPartMode )
{
pDocView->m_pImpl->m_pDocument->pClass->setPartMode( pDocView->m_pImpl->m_pDocument, nPartMode );
pDocView->m_pImpl->renderDocument(0);
}
-SAL_DLLPUBLIC_EXPORT void lok_docview_set_edit( LOKDocView* pDocView,
+SAL_DLLPUBLIC_EXPORT void lok_doc_view_set_edit( LOKDocView* pDocView,
gboolean bEdit )
{
gboolean bWasEdit = pDocView->m_pImpl->m_bEdit;
if (!pDocView->m_pImpl->m_bEdit && bEdit)
- g_info("lok_docview_set_edit: entering edit mode");
+ g_info("lok_doc_view_set_edit: entering edit mode");
else if (pDocView->m_pImpl->m_bEdit && !bEdit)
{
- g_info("lok_docview_set_edit: leaving edit mode");
+ g_info("lok_doc_view_set_edit: leaving edit mode");
pDocView->m_pImpl->m_pDocument->pClass->resetSelection(pDocView->m_pImpl->m_pDocument);
}
pDocView->m_pImpl->m_bEdit = bEdit;
- g_signal_emit(pDocView, docview_signals[EDIT_CHANGED], 0, bWasEdit);
+ g_signal_emit(pDocView, doc_view_signals[EDIT_CHANGED], 0, bWasEdit);
gtk_widget_queue_draw(GTK_WIDGET(pDocView->m_pImpl->m_pDrawingArea));
}
-SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView)
+SAL_DLLPUBLIC_EXPORT gboolean lok_doc_view_get_edit(LOKDocView* pDocView)
{
return pDocView->m_pImpl->m_bEdit;
}
-SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand, const char* pArguments)
+SAL_DLLPUBLIC_EXPORT void lok_doc_view_post_command(LOKDocView* pDocView, const char* pCommand, const char* pArguments)
{
pDocView->m_pImpl->m_pDocument->pClass->postUnoCommand(pDocView->m_pImpl->m_pDocument, pCommand, pArguments);
}
-SAL_DLLPUBLIC_EXPORT void lok_docview_post_key(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer pData)
+SAL_DLLPUBLIC_EXPORT void lok_doc_view_post_key(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer pData)
{
LOKDocView* pDocView = static_cast<LOKDocView *>(pData);
pDocView->m_pImpl->signalKey(pEvent);
}
-SAL_DLLPUBLIC_EXPORT void lok_docview_get_visarea(LOKDocView* pThis, GdkRectangle* pArea)
+SAL_DLLPUBLIC_EXPORT void lok_doc_view_get_visarea(LOKDocView* pThis, GdkRectangle* pArea)
{
float zoom = pThis->m_pImpl->m_fZoom;
GtkAdjustment* pHAdjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(pThis));
commit 1493e66bfbceb2e57d069c0a0dbcfa64f7043da9
Author: Pranav Kant <pranavk at gnome.org>
Date: Sat Jun 6 02:07:31 2015 +0530
lokdocview: Let G_BEGIN/END_DECLS handle the compiler check
Change-Id: I8c60c9ba13516fc2b3a926c19b41ee19805d74a5
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index b3e50d3..9668904 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -16,10 +16,7 @@
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.h>
-#ifdef __cplusplus
-extern "C"
-{
-#endif
+G_BEGIN_DECLS
#define LOK_DOCVIEW(obj) GTK_CHECK_CAST (obj, lok_docview_get_type(), LOKDocView)
#define LOK_DOCVIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, lok_docview_get_type(), LOKDocViewClass)
@@ -77,9 +74,8 @@ void lok_docview_post_key (GtkWidget* pWidget, GdkEventKey* pEvent
/// Get the visible area of the document (in twips).
void lok_docview_get_visarea(LOKDocView* pThis, GdkRectangle* pArea);
-#ifdef __cplusplus
-}
-#endif
+
+G_END_DECLS
#endif // INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKITGTK_H
commit 085f31a435eed43e3b7927e10309ddd00fb5b9a5
Author: Pranav Kant <pranavk at gnome.org>
Date: Sat Jun 6 00:36:54 2015 +0530
lokdocview: fix render calls after LOK callbacks
Change-Id: Ib33f0e1dcf257350be1e2cf6c49cd92494472a55
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 49ea27d..b901a61 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -949,21 +949,18 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
{
GdkRectangle aRectangle = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
setTilesInvalid(aRectangle);
- renderDocument(0);
}
else
- {
m_pTileBuffer->resetAllTiles();
- renderDocument(0);
- }
+
+ gtk_widget_queue_draw(m_pDrawingArea);
}
break;
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
{
m_aVisibleCursor = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
m_bCursorOverlayVisible = true;
- setTilesInvalid(m_aVisibleCursor);
- renderDocument(0);
+ gtk_widget_queue_draw(m_pDrawingArea);
}
break;
case LOK_CALLBACK_TEXT_SELECTION:
@@ -1030,7 +1027,6 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
gtk_widget_set_size_request(m_pDrawingArea,
twipToPixel(m_nDocumentWidthTwips, m_fZoom),
twipToPixel(m_nDocumentHeightTwips, m_fZoom));
- m_pTileBuffer->resetAllTiles();
}
break;
case LOK_CALLBACK_SET_PART:
commit 1483643ba5930474b9eab73b723a775dd3c8c850
Author: Pranav Kant <pranavk at gnome.org>
Date: Fri Jun 5 20:38:55 2015 +0530
lokdocview: move GtkDrawingArea size request out of renderDocument()
... and place it at places only where the widget can change its size.
Change-Id: I4a4b28b35eba06a6faab434677d4d70d2a33339a
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 507e81f..49ea27d 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -790,7 +790,6 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
- gtk_widget_set_size_request(m_pDrawingArea, nDocumentWidthPixels, nDocumentHeightPixels);
cairo_t *pcairo = gdk_cairo_create(m_pDrawingArea->window);
// Render the tiles.
@@ -826,7 +825,7 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
if (bPaint)
{
- g_info("tile_buffer_get_tile (%d, %d)", nRow, nColumn);
+ //g_info("tile_buffer_get_tile (%d, %d)", nRow, nColumn);
Tile& currentTile = m_pTileBuffer->getTile(nRow, nColumn);
GdkPixbuf* pPixBuf = currentTile.getBuffer();
@@ -1028,6 +1027,10 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
{
payloadToSize(pCallback->m_aPayload.c_str(), m_nDocumentWidthTwips, m_nDocumentHeightTwips);
+ gtk_widget_set_size_request(m_pDrawingArea,
+ twipToPixel(m_nDocumentWidthTwips, m_fZoom),
+ twipToPixel(m_nDocumentHeightTwips, m_fZoom));
+ m_pTileBuffer->resetAllTiles();
}
break;
case LOK_CALLBACK_SET_PART:
@@ -1252,6 +1255,9 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, c
nTileSizePixels,
nRows,
nColumns);
+ gtk_widget_set_size_request(pDocView->m_pImpl->m_pDrawingArea,
+ nDocumentWidthPixels,
+ nDocumentHeightPixels);
pDocView->m_pImpl->renderDocument(0);
}
@@ -1273,6 +1279,9 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_set_zoom ( LOKDocView* pDocView, float fZo
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
pDocView->m_pImpl->m_pTileBuffer->setZoom(fZoom, nRows, nColumns);
+ gtk_widget_set_size_request(pDocView->m_pImpl->m_pDrawingArea,
+ nDocumentWidthPixels,
+ nDocumentHeightPixels);
if ( pDocView->m_pImpl->m_pDocument )
pDocView->m_pImpl->renderDocument(0);
commit 35e03615066a6525e0259ff1823a0da0c2d4820a
Author: Pranav Kant <pranavk at gnome.org>
Date: Fri Jun 5 17:06:54 2015 +0530
lokdocview: check payload for inconsistencies before using it
Lets follow the old advice: "Be liberal in what you accept, be strict in
what you produce".
This is after noticing negative values for x, y in
the payload in some situation, such as, hitting a backspace key when the
cursor is at the start of a line
Change-Id: I11939b981f75969b88214baee66b4c69c5e41906
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 8e43e08..507e81f 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -187,9 +187,9 @@ struct LOKDocView_Impl
*/
void renderDocument(GdkRectangle* pPartial);
/// Returns the GdkRectangle of a x,y,width,height string.
- static GdkRectangle payloadToRectangle(const char* pPayload);
+ GdkRectangle payloadToRectangle(const char* pPayload);
/// Returns the GdkRectangles of a x1,y1,w1,h1;x2,y2,w2,h2;... string.
- static std::vector<GdkRectangle> payloadToRectangles(const char* pPayload);
+ std::vector<GdkRectangle> payloadToRectangles(const char* pPayload);
/// Returns the string representation of a LibreOfficeKitCallbackType enumeration element.
static const char* callbackTypeToString(int nType);
/// Invoked on the main thread if callbackWorker() requests so.
@@ -853,18 +853,26 @@ GdkRectangle LOKDocView_Impl::payloadToRectangle(const char* pPayload)
if (!*ppCoordinate)
return aRet;
aRet.x = atoi(*ppCoordinate);
+ if (aRet.x < 0)
+ aRet.x = 0;
++ppCoordinate;
if (!*ppCoordinate)
return aRet;
aRet.y = atoi(*ppCoordinate);
+ if (aRet.y < 0)
+ aRet.y = 0;
++ppCoordinate;
if (!*ppCoordinate)
return aRet;
aRet.width = atoi(*ppCoordinate);
+ if (aRet.x + aRet.width > m_nDocumentWidthTwips)
+ aRet.width = m_nDocumentWidthTwips - aRet.x;
++ppCoordinate;
if (!*ppCoordinate)
return aRet;
aRet.height = atoi(*ppCoordinate);
+ if (aRet.y + aRet.height > m_nDocumentHeightTwips)
+ aRet.height = m_nDocumentHeightTwips - aRet.y;
g_strfreev(ppCoordinates);
return aRet;
}
commit f4278176b031f0588269599ba8b59aa6ebbb9464
Author: Pranav Kant <pranavk at gnome.org>
Date: Fri Jun 5 17:05:28 2015 +0530
lokdocview: fixed rectangle format in documentation/comments
Change-Id: Iaf4a5fba5c4c34d03b91ca9ca4dd4eff1dbf39f6
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 61177c9..8e43e08 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -186,9 +186,9 @@ struct LOKDocView_Impl
* the tiles that intersect with pPartial.
*/
void renderDocument(GdkRectangle* pPartial);
- /// Returns the GdkRectangle of a width,height,x,y string.
+ /// Returns the GdkRectangle of a x,y,width,height string.
static GdkRectangle payloadToRectangle(const char* pPayload);
- /// Returns the GdkRectangles of a w,h,x,y;w2,h2,x2,y2;... string.
+ /// Returns the GdkRectangles of a x1,y1,w1,h1;x2,y2,w2,h2;... string.
static std::vector<GdkRectangle> payloadToRectangles(const char* pPayload);
/// Returns the string representation of a LibreOfficeKitCallbackType enumeration element.
static const char* callbackTypeToString(int nType);
commit c074cfa4d48736d1703949ccfe1a6c534a2742ae
Author: Pranav Kant <pranavk at gnome.org>
Date: Thu Jun 4 22:09:57 2015 +0530
lokdocview, tilebuffer: clean up
Improve documentation, style fixes
Change-Id: I5000e32e90cd8e3b75e8df2907673efc303a55fd
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 9eadfa4..61177c9 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -177,12 +177,12 @@ struct LOKDocView_Impl
/// Implementation of the timeout handler, invoked by handleTimeout().
gboolean handleTimeoutImpl();
/**
- * Renders the document to a number of tiles.
+ * Renders the document to a number of visible tiles.
*
* This method is invoked only manually, not when some Gtk signal is
* emitted.
*
- * @param pPartial if 0, then the full document is rendered, otherwise only
+ * @param pPartial if 0, then the full visible document is rendered, otherwise only
* the tiles that intersect with pPartial.
*/
void renderDocument(GdkRectangle* pPartial);
@@ -665,7 +665,7 @@ void LOKDocView_Impl::setTilesInvalid(const GdkRectangle& rRectangle)
for (int i = aStart.x; i < aEnd.x; i++)
for (int j = aStart.y; j < aEnd.y; j++)
- m_pTileBuffer->tile_buffer_set_invalid(i, j);
+ m_pTileBuffer->setInvalid(i, j);
}
void LOKDocView_Impl::renderHandle(cairo_t* pCairo, const GdkRectangle& rCursor, cairo_surface_t* pHandle, GdkRectangle& rRectangle)
@@ -801,7 +801,8 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
GdkRectangle aTileRectangleTwips, aTileRectanglePixels;
bool bPaint = true;
- // Determine size of the tile: the rightmost/bottommost tiles may be smaller and we need the size to decide if we need to repaint.
+ // Determine size of the tile: the rightmost/bottommost tiles may
+ // be smaller, and we need the size to decide if we need to repaint.
if (nColumn == nColumns - 1)
aTileRectanglePixels.width = nDocumentWidthPixels - nColumn * nTileSizePixels;
else
@@ -811,7 +812,8 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
else
aTileRectanglePixels.height = nTileSizePixels;
- // Determine size and position of the tile in document coordinates, so we can decide if we can skip painting for partial rendering.
+ // Determine size and position of the tile in document coordinates,
+ // so we can decide if we can skip painting for partial rendering.
aTileRectangleTwips.x = pixelToTwip(nTileSizePixels, m_fZoom) * nColumn;
aTileRectangleTwips.y = pixelToTwip(nTileSizePixels, m_fZoom) * nRow;
aTileRectangleTwips.width = pixelToTwip(aTileRectanglePixels.width, m_fZoom);
@@ -824,12 +826,14 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
if (bPaint)
{
- // g_info("gettile: (%d %d)", nRow, nColumn);
+ g_info("tile_buffer_get_tile (%d, %d)", nRow, nColumn);
- Tile& currentTile = m_pTileBuffer->tile_buffer_get_tile(nRow, nColumn);
- GdkPixbuf* pPixBuf = currentTile.tile_get_buffer();
+ Tile& currentTile = m_pTileBuffer->getTile(nRow, nColumn);
+ GdkPixbuf* pPixBuf = currentTile.getBuffer();
- gdk_cairo_set_source_pixbuf (pcairo, pPixBuf, twipToPixel(aTileRectangleTwips.x, m_fZoom), twipToPixel(aTileRectangleTwips.y, m_fZoom));
+ gdk_cairo_set_source_pixbuf (pcairo, pPixBuf,
+ twipToPixel(aTileRectangleTwips.x, m_fZoom),
+ twipToPixel(aTileRectangleTwips.y, m_fZoom));
cairo_paint(pcairo);
}
}
@@ -942,7 +946,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
}
else
{
- m_pTileBuffer->tile_buffer_reset_all_tiles();
+ m_pTileBuffer->resetAllTiles();
renderDocument(0);
}
}
@@ -1148,21 +1152,28 @@ static void lok_docview_init( GTypeInstance* pInstance, gpointer )
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView),
pDocView->m_pImpl->m_pDrawingArea );
- g_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
+ g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
"expose-event",
- GTK_SIGNAL_FUNC(LOKDocView_Impl::on_exposed), pDocView);
- g_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
+ G_CALLBACK(LOKDocView_Impl::on_exposed), pDocView);
+ g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
"expose-event",
- GTK_SIGNAL_FUNC(LOKDocView_Impl::renderOverlay), pDocView);
+ G_CALLBACK(LOKDocView_Impl::renderOverlay), pDocView);
gtk_widget_add_events(pDocView->m_pImpl->m_pDrawingArea,
- GDK_BUTTON_PRESS_MASK
- | GDK_BUTTON_RELEASE_MASK
- | GDK_BUTTON_MOTION_MASK);
- g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "button-press-event", G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
- g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "button-release-event", G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
- g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "motion-notify-event", G_CALLBACK(LOKDocView_Impl::signalMotion), pDocView);
-
- gtk_signal_connect(GTK_OBJECT(pDocView), "destroy", GTK_SIGNAL_FUNC(LOKDocView_Impl::destroy), 0);
+ GDK_BUTTON_PRESS_MASK
+ |GDK_BUTTON_RELEASE_MASK
+ |GDK_BUTTON_MOTION_MASK);
+
+ g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
+ "button-press-event",
+ G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
+ g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
+ "button-release-event",
+ G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
+ g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
+ "motion-notify-event",
+ G_CALLBACK(LOKDocView_Impl::signalMotion), pDocView);
+
+ g_signal_connect(G_OBJECT(pDocView), "destroy", G_CALLBACK(LOKDocView_Impl::destroy), 0);
}
SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
@@ -1253,7 +1264,7 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_set_zoom ( LOKDocView* pDocView, float fZo
guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
- pDocView->m_pImpl->m_pTileBuffer->tile_buffer_set_zoom(fZoom, nRows, nColumns);
+ pDocView->m_pImpl->m_pTileBuffer->setZoom(fZoom, nRows, nColumns);
if ( pDocView->m_pImpl->m_pDocument )
pDocView->m_pImpl->renderDocument(0);
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
index 3e5e01f..3380380 100644
--- a/libreofficekit/source/gtk/tilebuffer.cxx
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -9,6 +9,10 @@
#include "tilebuffer.hxx"
+/* ------------------
+ Utility functions
+ ------------------
+*/
float pixelToTwip(float fInput, float zoom)
{
return (fInput / DPI / zoom) * 1440.0f;
@@ -19,84 +23,96 @@ float twipToPixel(float fInput, float zoom)
return fInput / 1440.0f * DPI * zoom;
}
-GdkPixbuf* Tile::tile_get_buffer()
+/* ----------------------------
+ Tile class member functions
+ ----------------------------
+*/
+GdkPixbuf* Tile::getBuffer()
{
return m_pBuffer;
}
-void Tile::tile_release()
+void Tile::release()
{
g_object_unref (m_pBuffer);
m_pBuffer = NULL;
}
-void TileBuffer::tile_buffer_set_zoom(float newZoomFactor, int rows, int columns)
+void Tile::setPixbuf(GdkPixbuf *buffer)
+{
+ m_pBuffer = buffer;
+}
+
+/* ----------------------------------
+ TileBuffer class member functions
+ ----------------------------------
+*/
+void TileBuffer::setZoom(float newZoomFactor, int rows, int columns)
{
m_fZoomFactor = newZoomFactor;
- tile_buffer_reset_all_tiles();
+ resetAllTiles();
// set new buffer width and height
m_nWidth = columns;
m_nHeight = rows;
}
-void TileBuffer::tile_buffer_reset_all_tiles()
+void TileBuffer::resetAllTiles()
{
std::map<int, Tile>::iterator it = m_mTiles.begin();
for (; it != m_mTiles.end(); it++)
- {
- it->second.tile_release();
- }
+ {
+ it->second.release();
+ }
m_mTiles.clear();
}
-void TileBuffer::tile_buffer_set_invalid(int x, int y)
+void TileBuffer::setInvalid(int x, int y)
{
int index = x * m_nWidth + y;
- g_info("setting invalid : %d %d",x, y);
+ g_info("Setting tile invalid (%d, %d)", x, y);
if (m_mTiles.find(index) != m_mTiles.end())
- {
- m_mTiles[index].valid = 0;
- m_mTiles[index].tile_release();
- m_mTiles.erase(index);
- }
+ {
+ m_mTiles[index].valid = 0;
+ m_mTiles[index].release();
+ m_mTiles.erase(index);
+ }
}
-Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
+Tile& TileBuffer::getTile(int x, int y)
{
int index = x * m_nWidth + y;
if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
- {
+ {
- GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
- if (!pPixBuf){
- g_info ("error allocating memory to pixbuf");
- }
- unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
- GdkRectangle aTileRectangle;
- aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y;
- aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x;
-
- g_info ("rendering (%d %d)", x, y);
- m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
- // Buffer and its size, depends on the position only.
- pBuffer,
- m_nTileSize, m_nTileSize,
- // Position of the tile.
- aTileRectangle.x, aTileRectangle.y,
- // Size of the tile, depends on the zoom factor and the tile position only.
- pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor));
-
- //create a mapping for it
- m_mTiles[index].tile_set_pixbuf(pPixBuf);
- m_mTiles[index].valid = 1;
+ GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
+ if (!pPixBuf)
+ {
+ g_info ("Error allocating memory to pixbuf");
+ return m_mTiles[index];
}
+ unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
+ GdkRectangle aTileRectangle;
+ aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y;
+ aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x;
+
+ g_info ("Rendering (%d, %d)", x, y);
+ m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
+ pBuffer,
+ m_nTileSize, m_nTileSize,
+ aTileRectangle.x, aTileRectangle.y,
+ pixelToTwip(m_nTileSize, m_fZoomFactor),
+ pixelToTwip(m_nTileSize, m_fZoomFactor));
+
+ //create a mapping for it
+ m_mTiles[index].setPixbuf(pPixBuf);
+ m_mTiles[index].valid = 1;
+ }
+
return m_mTiles[index];
}
-void Tile::tile_set_pixbuf(GdkPixbuf *buffer)
-{
- m_pBuffer = buffer;
-}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index 15b276f..7e2132f 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -24,32 +24,60 @@ const int DPI = 96;
// Lets use a square of side 256 pixels for each tile.
const int nTileSizePixels = 256;
+/**
+ 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
+*/
float pixelToTwip(float fInput, float zoom);
+/**
+ 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
+*/
float twipToPixel(float fInput, float zoom);
-/*
- This class represents a single tile in the tile buffer.
- TODO: Extend it to support features like double buffering
+/**
+ This class represents a single tile in the tile buffer.
+ It encloses a reference to GdkPixBuf containing the pixel data of the tile.
*/
class Tile
{
public:
- Tile() : valid(0) {}
- ~Tile() {
- }
+ Tile() : valid(0) {}
+ ~Tile() { }
- GdkPixbuf* tile_get_buffer();
- void tile_release();
- void tile_set_pixbuf(GdkPixbuf*);
+ /**
+ Tells if this tile is valid or not. Initialised to 0 (invalid) during
+ object creation.
+ */
bool valid;
- private:
+
+ /// 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
GdkPixbuf *m_pBuffer;
};
-/*
- TileBuffer is the buffer caching all the recently rendered tiles.
- The buffer is set to invalid when zoom factor changes.
+/**
+ 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.
*/
class TileBuffer
{
@@ -67,19 +95,58 @@ class TileBuffer
~TileBuffer() {}
- void tile_buffer_set_zoom(float zoomFactor, int rows, int columns);
- Tile& tile_buffer_get_tile(int x, int y);
- void tile_buffer_update();
- void tile_buffer_reset_all_tiles();
- void tile_buffer_set_invalid(int x, int y);
+ /**
+ Sets the zoom factor (m_fZoomFactor) for this tile buffer. Setting the
+ zoom factor invalidates whole of the tile buffer, destroys all tiles
+ contained within it, and sets new width, height values for tile
+ buffer. The width, height value of tile buffer is the width and height of
+ the table containing all possible tiles (rendered and non-rendered) that
+ this buffer can have.
+
+ @param zoomFactor the new zoom factor value to set
+ */
+ void setZoom(float zoomFactor, int rows, int columns);
+ /**
+ 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
+
+ @return the tile at the mentioned position (x, y)
+ */
+ Tile& getTile(int x, int y);
+ /// 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
+ */
+ void setInvalid(int x, int y);
+
private:
+ /// Contains the reference to the LOK Document that this tile buffer is for.
LibreOfficeKitDocument *m_pLOKDocument;
+ /// The side of each squared tile in pixels.
int m_nTileSize;
+ /// The zoom factor that the tile buffer is currently rendered to.
float m_fZoomFactor;
+ /// Stores all the tiles cached by this tile buffer.
std::map<int, Tile> m_mTiles;
- //TODO: Also set width and height when document size changes
+ /// Width of the current tile buffer (number of columns)
int m_nWidth;
+ /// Height of the current tile buffer (numbero of rows)
int m_nHeight;
};
#endif // INCLUDED_TILEBUFFER_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit ad0a404ef3097d92cf9a0e861e076a72074a5258
Author: Pranav Kant <pranavk at gnome.org>
Date: Thu Jun 4 14:15:58 2015 +0530
lokdocview: wrap a functionality inside a member function
Lets use a member function to set invalid tiles that come under the
given GdkRectangle.
Change-Id: I440336ddf3c5fd9094f35bb89479aa76a42477fa
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 943a176..9eadfa4 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -212,6 +212,8 @@ struct LOKDocView_Impl
void searchNotFound(const std::string& rPayload);
/// LOK decided to change parts, need to update UI.
void setPart(const std::string& rPayload);
+ /// Sets the tiles enclosed by rRectangle as invalid in m_pTileBuffer
+ void setTilesInvalid(const GdkRectangle& rRectangle);
};
namespace {
@@ -646,6 +648,26 @@ bool LOKDocView_Impl::isEmptyRectangle(const GdkRectangle& rRectangle)
return rRectangle.x == 0 && rRectangle.y == 0 && rRectangle.width == 0 && rRectangle.height == 0;
}
+void LOKDocView_Impl::setTilesInvalid(const GdkRectangle& rRectangle)
+{
+ GdkRectangle aRectanglePixels;
+ GdkPoint aStart, aEnd;
+
+ aRectanglePixels.x = twipToPixel(rRectangle.x, m_fZoom);
+ aRectanglePixels.y = twipToPixel(rRectangle.y, m_fZoom);
+ aRectanglePixels.width = twipToPixel(rRectangle.width, m_fZoom);
+ aRectanglePixels.height = twipToPixel(rRectangle.height, m_fZoom);
+
+ aStart.x = aRectanglePixels.y / nTileSizePixels;
+ aStart.y = aRectanglePixels.x / nTileSizePixels;
+ aEnd.x = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
+ aEnd.y = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
+
+ for (int i = aStart.x; i < aEnd.x; i++)
+ for (int j = aStart.y; j < aEnd.y; j++)
+ m_pTileBuffer->tile_buffer_set_invalid(i, j);
+}
+
void LOKDocView_Impl::renderHandle(cairo_t* pCairo, const GdkRectangle& rCursor, cairo_surface_t* pHandle, GdkRectangle& rRectangle)
{
GdkPoint aCursorBottom;
@@ -915,21 +937,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
if (pCallback->m_aPayload != "EMPTY")
{
GdkRectangle aRectangle = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
- GdkRectangle aRectanglePixels;
- aRectanglePixels.x = twipToPixel(aRectangle.x, m_fZoom);
- aRectanglePixels.y = twipToPixel(aRectangle.y, m_fZoom);
- aRectanglePixels.width = twipToPixel(aRectangle.width, m_fZoom);
- aRectanglePixels.height = twipToPixel(aRectangle.height, m_fZoom);
- int rowStart = aRectanglePixels.y / nTileSizePixels;
- int colStart = aRectanglePixels.x / nTileSizePixels;
- int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
- int colEnd = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
- int i,j;
- for (i = rowStart; i < rowEnd; i++) {
- for (j = colStart; j < colEnd; j++) {
- m_pTileBuffer->tile_buffer_set_invalid(i, j);
- }
- }
+ setTilesInvalid(aRectangle);
renderDocument(0);
}
else
@@ -943,21 +951,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
{
m_aVisibleCursor = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
m_bCursorOverlayVisible = true;
- GdkRectangle aRectanglePixels;
- aRectanglePixels.x = twipToPixel(m_aVisibleCursor.x, m_fZoom);
- aRectanglePixels.y = twipToPixel(m_aVisibleCursor.y, m_fZoom);
- aRectanglePixels.width = twipToPixel(m_aVisibleCursor.width, m_fZoom);
- aRectanglePixels.height = twipToPixel(m_aVisibleCursor.height, m_fZoom);
- int rowStart = aRectanglePixels.y / nTileSizePixels;
- int colStart = aRectanglePixels.x / nTileSizePixels;
- int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
- int colEnd = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
- int i,j;
- for (i = rowStart; i < rowEnd; i++) {
- for (j = colStart; j < colEnd; j++) {
- m_pTileBuffer->tile_buffer_set_invalid(i, j);
- }
- }
+ setTilesInvalid(m_aVisibleCursor);
renderDocument(0);
}
break;
commit a5d3efa4a02bed357d43960913a7c946c8b12aff
Author: Pranav Kant <pranavk at gnome.org>
Date: Thu Jun 4 13:56:46 2015 +0530
lokdocview: move commonly used functions and variables to common header
twipToPixel and pixelToTwip are also being used by the new TileBuffer
clsas. Lets move these utility functions to a common header,
tilebuffer.hxx
The variables for DPI and tileSize are also moved to tilebuffer.hxx
Change-Id: I9d0bec7f2aefe412df232040a7a9abc6db3e4ccb
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 588e680..943a176 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -37,11 +37,6 @@
// Number of handles around a graphic selection.
#define GRAPHIC_HANDLE_COUNT 8
-// We know that VirtualDevices use a DPI of 96.
-static const int DPI = 96;
-// Lets use a square of side 256 pixels.
-static const int nTileSizePixels = 256;
-
namespace {
/// Sets rWidth and rHeight from a "width, height" string.
@@ -145,10 +140,6 @@ struct LOKDocView_Impl
static void destroy(LOKDocView* pDocView, gpointer pData);
/// Connected to the expose-event of the GtkDrawingArea
static void on_exposed(GtkWidget *widget, GdkEvent *event, gpointer user_data);
- /// Converts from screen pixels to document coordinates.
- float pixelToTwip(float fInput);
- /// Converts from document coordinates to screen pixels.
- float twipToPixel(float fInput);
/// Receives a key press or release event.
void signalKey(GdkEventKey* pEvent);
/**
@@ -316,16 +307,6 @@ void LOKDocView_Impl::on_exposed(GtkWidget* /*widget*/, GdkEvent* /*event*/, gpo
pDocView->m_pImpl->renderDocument(0);
}
-float LOKDocView_Impl::pixelToTwip(float fInput)
-{
- return (fInput / DPI / m_fZoom) * 1440.0f;
-}
-
-float LOKDocView_Impl::twipToPixel(float fInput)
-{
- return fInput / 1440.0f * DPI * m_fZoom;
-}
-
void LOKDocView_Impl::signalKey(GdkEventKey* pEvent)
{
int nCharCode = 0;
@@ -390,7 +371,7 @@ gboolean LOKDocView_Impl::signalButton(GtkWidget* /*pEventBox*/, GdkEventButton*
/// Receives a button press event.
gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
{
- g_info("LOKDocView_Impl::signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pixelToTwip(pEvent->x), (int)pixelToTwip(pEvent->y));
+ g_info("LOKDocView_Impl::signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pixelToTwip(pEvent->x, m_fZoom), (int)pixelToTwip(pEvent->y, m_fZoom));
if (pEvent->type == GDK_BUTTON_RELEASE)
{
@@ -419,7 +400,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
{
g_info("LOKDocView_Impl::signalButton: end of drag graphic handle #%d", i);
m_bInDragGraphicHandles[i] = false;
- m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y));
+ m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom));
return FALSE;
}
}
@@ -428,7 +409,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
{
g_info("LOKDocView_Impl::signalButton: end of drag graphic selection");
m_bInDragGraphicSelection = false;
- m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y));
+ m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom));
return FALSE;
}
}
@@ -469,8 +450,8 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
m_bInDragGraphicHandles[i] = true;
m_pDocument->pClass->setGraphicSelection(m_pDocument,
LOK_SETGRAPHICSELECTION_START,
- pixelToTwip(m_aGraphicHandleRects[i].x + m_aGraphicHandleRects[i].width / 2),
- pixelToTwip(m_aGraphicHandleRects[i].y + m_aGraphicHandleRects[i].height / 2));
+ pixelToTwip(m_aGraphicHandleRects[i].x + m_aGraphicHandleRects[i].width / 2, m_fZoom),
+ pixelToTwip(m_aGraphicHandleRects[i].y + m_aGraphicHandleRects[i].height / 2, m_fZoom));
return FALSE;
}
}
@@ -488,7 +469,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
if ((pEvent->time - m_nLastButtonPressTime) < 250)
nCount++;
m_nLastButtonPressTime = pEvent->time;
- m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount);
+ m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom), nCount);
break;
}
case GDK_BUTTON_RELEASE:
@@ -497,7 +478,7 @@ gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent)
if ((pEvent->time - m_nLastButtonReleaseTime) < 250)
nCount++;
m_nLastButtonReleaseTime = pEvent->time;
- m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount);
+ m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom), nCount);
break;
}
default:
@@ -534,21 +515,21 @@ gboolean LOKDocView_Impl::signalMotionImpl(GdkEventButton* pEvent)
{
g_info("lcl_signalMotion: dragging the middle handle");
LOKDocView_Impl::getDragPoint(&m_aHandleMiddleRect, pEvent, &aPoint);
- m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_RESET, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y));
+ m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_RESET, pixelToTwip(aPoint.x, m_fZoom), pixelToTwip(aPoint.y, m_fZoom));
return FALSE;
}
if (m_bInDragStartHandle)
{
g_info("lcl_signalMotion: dragging the start handle");
LOKDocView_Impl::getDragPoint(&m_aHandleStartRect, pEvent, &aPoint);
- m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_START, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y));
+ m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_START, pixelToTwip(aPoint.x, m_fZoom), pixelToTwip(aPoint.y, m_fZoom));
return FALSE;
}
if (m_bInDragEndHandle)
{
g_info("lcl_signalMotion: dragging the end handle");
LOKDocView_Impl::getDragPoint(&m_aHandleEndRect, pEvent, &aPoint);
- m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_END, pixelToTwip(aPoint.x), pixelToTwip(aPoint.y));
+ m_pDocument->pClass->setTextSelection(m_pDocument, LOK_SETTEXTSELECTION_END, pixelToTwip(aPoint.x, m_fZoom), pixelToTwip(aPoint.y, m_fZoom));
return FALSE;
}
for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
@@ -566,20 +547,20 @@ gboolean LOKDocView_Impl::signalMotionImpl(GdkEventButton* pEvent)
}
GdkRectangle aMotionInTwipsInTwips;
- aMotionInTwipsInTwips.x = pixelToTwip(pEvent->x);
- aMotionInTwipsInTwips.y = pixelToTwip(pEvent->y);
+ aMotionInTwipsInTwips.x = pixelToTwip(pEvent->x, m_fZoom);
+ aMotionInTwipsInTwips.y = pixelToTwip(pEvent->y, m_fZoom);
aMotionInTwipsInTwips.width = 1;
aMotionInTwipsInTwips.height = 1;
if (gdk_rectangle_intersect(&aMotionInTwipsInTwips, &m_aGraphicSelection, 0))
{
g_info("lcl_signalMotion: start of drag graphic selection");
m_bInDragGraphicSelection = true;
- m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_START, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y));
+ m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_START, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom));
return FALSE;
}
// Otherwise a mouse move, as on the desktop.
- m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEMOVE, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), 1);
+ m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEMOVE, pixelToTwip(pEvent->x, m_fZoom), pixelToTwip(pEvent->y, m_fZoom), 1);
return FALSE;
}
@@ -602,10 +583,10 @@ gboolean LOKDocView_Impl::renderOverlayImpl(GtkWidget* pWidget)
cairo_set_source_rgb(pCairo, 0, 0, 0);
cairo_rectangle(pCairo,
- twipToPixel(m_aVisibleCursor.x),
- twipToPixel(m_aVisibleCursor.y),
- twipToPixel(m_aVisibleCursor.width),
- twipToPixel(m_aVisibleCursor.height));
+ twipToPixel(m_aVisibleCursor.x, m_fZoom),
+ twipToPixel(m_aVisibleCursor.y, m_fZoom),
+ twipToPixel(m_aVisibleCursor.width, m_fZoom),
+ twipToPixel(m_aVisibleCursor.height, m_fZoom));
cairo_fill(pCairo);
}
@@ -624,10 +605,10 @@ gboolean LOKDocView_Impl::renderOverlayImpl(GtkWidget* pWidget)
// Blue with 75% transparency.
cairo_set_source_rgba(pCairo, ((double)0x43)/255, ((double)0xac)/255, ((double)0xe8)/255, 0.25);
cairo_rectangle(pCairo,
- twipToPixel(rRectangle.x),
- twipToPixel(rRectangle.y),
- twipToPixel(rRectangle.width),
- twipToPixel(rRectangle.height));
+ twipToPixel(rRectangle.x, m_fZoom),
+ twipToPixel(rRectangle.y, m_fZoom),
+ twipToPixel(rRectangle.width, m_fZoom),
+ twipToPixel(rRectangle.height, m_fZoom));
cairo_fill(pCairo);
}
@@ -674,10 +655,10 @@ void LOKDocView_Impl::renderHandle(cairo_t* pCairo, const GdkRectangle& rCursor,
nHandleWidth = cairo_image_surface_get_width(pHandle);
nHandleHeight = cairo_image_surface_get_height(pHandle);
// We want to scale down the handle, so that its height is the same as the cursor caret.
- fHandleScale = twipToPixel(rCursor.height) / nHandleHeight;
+ fHandleScale = twipToPixel(rCursor.height, m_fZoom) / nHandleHeight;
// We want the top center of the handle bitmap to be at the bottom center of the cursor rectangle.
- aCursorBottom.x = twipToPixel(rCursor.x) + twipToPixel(rCursor.width) / 2 - (nHandleWidth * fHandleScale) / 2;
- aCursorBottom.y = twipToPixel(rCursor.y) + twipToPixel(rCursor.height);
+ aCursorBottom.x = twipToPixel(rCursor.x, m_fZoom) + twipToPixel(rCursor.width, m_fZoom) / 2 - (nHandleWidth * fHandleScale) / 2;
+ aCursorBottom.y = twipToPixel(rCursor.y, m_fZoom) + twipToPixel(rCursor.height, m_fZoom);
cairo_save(pCairo);
cairo_translate(pCairo, aCursorBottom.x, aCursorBottom.y);
cairo_scale(pCairo, fHandleScale, fHandleScale);
@@ -700,10 +681,10 @@ void LOKDocView_Impl::renderGraphicHandle(cairo_t* pCairo, const GdkRectangle& r
nHandleWidth = cairo_image_surface_get_width(pHandle);
nHandleHeight = cairo_image_surface_get_height(pHandle);
- aSelection.x = twipToPixel(rSelection.x);
- aSelection.y = twipToPixel(rSelection.y);
- aSelection.width = twipToPixel(rSelection.width);
- aSelection.height = twipToPixel(rSelection.height);
+ aSelection.x = twipToPixel(rSelection.x, m_fZoom);
+ aSelection.y = twipToPixel(rSelection.y, m_fZoom);
+ aSelection.width = twipToPixel(rSelection.width, m_fZoom);
+ aSelection.height = twipToPixel(rSelection.height, m_fZoom);
for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
{
@@ -781,8 +762,8 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
GdkRectangle visibleArea;
lok_docview_get_visarea (m_pDocView, &visibleArea);
- long nDocumentWidthPixels = twipToPixel(m_nDocumentWidthTwips);
- long nDocumentHeightPixels = twipToPixel(m_nDocumentHeightTwips);
+ long nDocumentWidthPixels = twipToPixel(m_nDocumentWidthTwips, m_fZoom);
+ long nDocumentHeightPixels = twipToPixel(m_nDocumentHeightTwips, m_fZoom);
// Total number of rows / columns in this document.
guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
@@ -809,10 +790,10 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
aTileRectanglePixels.height = nTileSizePixels;
// Determine size and position of the tile in document coordinates, so we can decide if we can skip painting for partial rendering.
- aTileRectangleTwips.x = pixelToTwip(nTileSizePixels) * nColumn;
- aTileRectangleTwips.y = pixelToTwip(nTileSizePixels) * nRow;
- aTileRectangleTwips.width = pixelToTwip(aTileRectanglePixels.width);
- aTileRectangleTwips.height = pixelToTwip(aTileRectanglePixels.height);
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list