[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - include/LibreOfficeKit libreofficekit/source
Miklos Vajna
vmiklos at collabora.co.uk
Mon Mar 30 03:11:59 PDT 2015
include/LibreOfficeKit/LibreOfficeKit.h | 24 ++------
include/LibreOfficeKit/LibreOfficeKit.hxx | 60 +++++++++++++++++++++
libreofficekit/source/gtk/lokdocview.cxx | 82 +++++++++++++++---------------
3 files changed, 110 insertions(+), 56 deletions(-)
New commits:
commit 6ba44684e79440f58cbacd0768f3a0638ac36885
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 30 12:08:25 2015 +0200
LOK: document remaining Document member functions
Change-Id: Idc5836317c01780bb5078d39d8c31775886027d0
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 98aa24d..f108048 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -65,24 +65,19 @@ struct _LibreOfficeKitDocumentClass
const char* pFormat,
const char* pFilterOptions);
#ifdef LOK_USE_UNSTABLE_API
- /** Get document type.
- *
- * @returns an element of the LibreOfficeKitDocumentType enum.
- */
+ /// @see lok::Document::getDocumentType().
int (*getDocumentType) (LibreOfficeKitDocument* pThis);
- /** Get number of part that the document contains.
- * Part refers to either indivual sheets in a Spreadsheet,
- * or slides in a Slideshow, and has no relevance for
- * writer documents.
- */
+ /// @see lok::Document::getParts().
int (*getParts) (LibreOfficeKitDocument* pThis);
- /** Get current part of the document */
+ /// @see lok::Document::getPart().
int (*getPart) (LibreOfficeKitDocument* pThis);
+ /// @see lok::Document::setPart().
void (*setPart) (LibreOfficeKitDocument* pThis,
int nPart);
+ /// @see lok::Document::getPartName().
char* (*getPartName) (LibreOfficeKitDocument* pThis,
int nPart);
@@ -93,6 +88,7 @@ struct _LibreOfficeKitDocumentClass
void (*setPartMode) (LibreOfficeKitDocument* pThis,
int nMode);
+ /// @see lok::Document::paintTile().
void (*paintTile) (LibreOfficeKitDocument* pThis,
unsigned char* pBuffer,
const int nCanvasWidth,
@@ -102,16 +98,12 @@ struct _LibreOfficeKitDocumentClass
const int nTileWidth,
const int nTileHeight);
- /** Get the document sizes in twips. */
+ /// @see lok::Document::getDocumentSize().
void (*getDocumentSize) (LibreOfficeKitDocument* pThis,
long* pWidth,
long* pHeight);
- /** Initialize document for rendering.
- * Sets the rendering and document parameters to default values
- * that are needed to render the document correctly using
- * tiled rendering.
- */
+ /// @see lok::Document::initializeForRendering().
void (*initializeForRendering) (LibreOfficeKitDocument* pThis);
void (*registerCallback) (LibreOfficeKitDocument* pThis,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 25d8980..4f0a77a 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -21,12 +21,14 @@
namespace lok
{
+/// The lok::Document class represents one loaded document instance.
class Document
{
private:
LibreOfficeKitDocument* mpDoc;
public:
+ /// A lok::Document is typically created by the lok::Office::documentLoad() method.
inline Document(LibreOfficeKitDocument* pDoc) :
mpDoc(pDoc)
{}
@@ -36,39 +38,77 @@ public:
mpDoc->pClass->destroy(mpDoc);
}
+ /**
+ * Stores the document's persistent data to a URL and
+ * continues to be a representation of the old URL.
+ *
+ * @param pUrl the location where to store the document
+ * @param pFormat the format to use while exporting, when omitted, then deducted from pURL's extension
+ * @param pFilterOptions options for the export filter, e.g. SkipImages.
+ */
inline bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
{
return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions) != 0;
}
+ /// Gives access to the underlying C pointer.
inline LibreOfficeKitDocument *get() { return mpDoc; }
#ifdef LOK_USE_UNSTABLE_API
+ /**
+ * Get document type.
+ *
+ * @return an element of the LibreOfficeKitDocumentType enum.
+ */
inline int getDocumentType()
{
return mpDoc->pClass->getDocumentType(mpDoc);
}
+ /**
+ * Get number of part that the document contains.
+ *
+ * Part refers to either indivual sheets in a Calc, or slides in Impress,
+ * and has no relevance for Writer.
+ */
inline int getParts()
{
return mpDoc->pClass->getParts(mpDoc);
}
+ /// Get the current part of the document.
inline int getPart()
{
return mpDoc->pClass->getPart(mpDoc);
}
+ /// Set the current part of the document.
inline void setPart(int nPart)
{
mpDoc->pClass->setPart(mpDoc, nPart);
}
+ /// Get the current part's name.
inline char* getPartName(int nPart)
{
return mpDoc->pClass->getPartName(mpDoc, nPart);
}
+ /**
+ * Renders a subset of the document to a pre-allocated buffer.
+ *
+ * Note that the buffer size and the tile size implicitly supports
+ * rendering at different zoom levels, as the number of rendered pixels and
+ * the rendered rectangle of the document are independent.
+ *
+ * @param pBuffer pointer to the buffer, its size is determined by nCanvasWidth and nCanvasHeight.
+ * @param nCanvasWidth number of pixels in a row of pBuffer.
+ * @param nCanvasHeight number of pixels in a column of pBuffer.
+ * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
+ * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
+ * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
+ * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
+ */
inline void paintTile(
unsigned char* pBuffer,
const int nCanvasWidth,
@@ -82,11 +122,20 @@ public:
nTilePosX, nTilePosY, nTileWidth, nTileHeight);
}
+ /// Get the document sizes in TWIPs.
inline void getDocumentSize(long* pWidth, long* pHeight)
{
mpDoc->pClass->getDocumentSize(mpDoc, pWidth, pHeight);
}
+ /**
+ * Initialize document for rendering.
+ *
+ * Sets the rendering and document parameters to default values that are
+ * needed to render the document correctly using tiled rendering. This
+ * method has to be called right after documentLoad() in case any of the
+ * tiled rendering methods are to be used later.
+ */
inline void initializeForRendering()
{
mpDoc->pClass->initializeForRendering(mpDoc);
@@ -173,12 +222,14 @@ public:
#endif // LOK_USE_UNSTABLE_API
};
+/// The lok::Office class represents one started LibreOfficeKit instance.
class Office
{
private:
LibreOfficeKit* mpThis;
public:
+ /// A lok::Office is typically created by the lok_cpp_init() function.
inline Office(LibreOfficeKit* pThis) :
mpThis(pThis)
{}
@@ -188,6 +239,12 @@ public:
mpThis->pClass->destroy(mpThis);
}
+ /**
+ * Loads a document from an URL.
+ *
+ * @param pUrl the URL of the document to load
+ * @param pFilterOptions options for the import filter, e.g. SkipImages.
+ */
inline Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
{
LibreOfficeKitDocument* pDoc = NULL;
@@ -203,13 +260,14 @@ public:
return new Document(pDoc);
}
- // return the last error as a string, free me.
+ /// Returns the last error as a string, the returned pointer has to be freed by the caller.
inline char* getError()
{
return mpThis->pClass->getError(mpThis);
}
};
+/// Factory method to create a lok::Office instance.
inline Office* lok_cpp_init(const char* pInstallPath)
{
LibreOfficeKit* pThis = lok_init(pInstallPath);
commit 75acd49df81e07378982ef0cf18c9e93a75b6739
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Mar 30 09:09:01 2015 +0200
lokdocview: move timeout handling to LOKDocView_Impl
Change-Id: Id1e14f259af68acbd29784436bb2c5062a0d6563
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index f73b0d7..0c6401c 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -141,6 +141,10 @@ struct LOKDocView_Impl
void renderHandle(cairo_t* pCairo, const GdkRectangle& rCursor, cairo_surface_t* pHandle, GdkRectangle& rRectangle);
/// Renders pHandle around an rSelection rectangle on pCairo.
void renderGraphicHandle(cairo_t* pCairo, const GdkRectangle& rSelection, cairo_surface_t* pHandle);
+ /// Takes care of the blinking cursor.
+ static gboolean handleTimeout(gpointer pData);
+ /// Implementation of the timeout handler, invoked by handleTimeout().
+ gboolean handleTimeoutImpl();
};
LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView)
@@ -632,31 +636,24 @@ void LOKDocView_Impl::renderGraphicHandle(cairo_t* pCairo, const GdkRectangle& r
}
}
-static void lok_docview_class_init( gpointer );
-static void lok_docview_init( GTypeInstance *, gpointer );
-
-SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
+gboolean LOKDocView_Impl::handleTimeout(gpointer pData)
{
- static guint lok_docview_type = 0;
+ LOKDocView* pDocView = static_cast<LOKDocView*>(pData);
+ return pDocView->m_pImpl->handleTimeoutImpl();
+}
- if (!lok_docview_type)
+gboolean LOKDocView_Impl::handleTimeoutImpl()
+{
+ if (m_bEdit)
{
- char pName[] = "LokDocView";
- GtkTypeInfo lok_docview_info =
- {
- pName,
- sizeof( LOKDocView ),
- sizeof( LOKDocViewClass ),
- lok_docview_class_init,
- lok_docview_init,
- NULL,
- NULL,
- (GtkClassInitFunc) NULL
- };
-
- lok_docview_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_docview_info );
+ if (m_bCursorOverlayVisible)
+ m_bCursorOverlayVisible = false;
+ else
+ m_bCursorOverlayVisible = true;
+ gtk_widget_queue_draw(GTK_WIDGET(m_pEventBox));
}
- return lok_docview_type;
+
+ return G_SOURCE_CONTINUE;
}
enum
@@ -707,28 +704,35 @@ static void lok_docview_init( GTypeInstance* pInstance, gpointer )
g_signal_connect_after(pDocView->m_pImpl->m_pEventBox, "expose-event", G_CALLBACK(LOKDocView_Impl::renderOverlay), pDocView);
}
-SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
-{
- LOKDocView* pDocView = LOK_DOCVIEW(gtk_type_new(lok_docview_get_type()));
- pDocView->m_pImpl->m_pOffice = pOffice;
- return GTK_WIDGET( pDocView );
-}
-
-/// Takes care of the blinking cursor.
-static gboolean lcl_handleTimeout(gpointer pData)
+SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
{
- LOKDocView* pDocView = LOK_DOCVIEW(pData);
+ static guint lok_docview_type = 0;
- if (pDocView->m_pImpl->m_bEdit)
+ if (!lok_docview_type)
{
- if (pDocView->m_pImpl->m_bCursorOverlayVisible)
- pDocView->m_pImpl->m_bCursorOverlayVisible = false;
- else
- pDocView->m_pImpl->m_bCursorOverlayVisible = true;
- gtk_widget_queue_draw(GTK_WIDGET(pDocView->m_pImpl->m_pEventBox));
+ char pName[] = "LokDocView";
+ GtkTypeInfo lok_docview_info =
+ {
+ pName,
+ sizeof( LOKDocView ),
+ sizeof( LOKDocViewClass ),
+ lok_docview_class_init,
+ lok_docview_init,
+ NULL,
+ NULL,
+ (GtkClassInitFunc) NULL
+ };
+
+ lok_docview_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_docview_info );
}
+ return lok_docview_type;
+}
- return G_SOURCE_CONTINUE;
+SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
+{
+ LOKDocView* pDocView = LOK_DOCVIEW(gtk_type_new(lok_docview_get_type()));
+ pDocView->m_pImpl->m_pOffice = pOffice;
+ return GTK_WIDGET( pDocView );
}
void renderDocument(LOKDocView* pDocView, GdkRectangle* pPartial)
@@ -1035,7 +1039,7 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, c
{
pDocView->m_pImpl->m_pDocument->pClass->initializeForRendering(pDocView->m_pImpl->m_pDocument);
pDocView->m_pImpl->m_pDocument->pClass->registerCallback(pDocView->m_pImpl->m_pDocument, &lok_docview_callback_worker, pDocView);
- g_timeout_add(600, &lcl_handleTimeout, pDocView);
+ g_timeout_add(600, &LOKDocView_Impl::handleTimeout, pDocView);
renderDocument(pDocView, NULL);
}
More information about the Libreoffice-commits
mailing list