Kaydet (Commit) d465dfb2 authored tarafından Andrzej Hunt's avatar Andrzej Hunt

Implement LibreOfficeKit gtk+ viewer widget.

Very basic, but works.

Change-Id: I0c521e833b53e13065e0be48e6fa767e44b29787
üst e6b88152
...@@ -524,6 +524,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo, \ ...@@ -524,6 +524,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo, \
i18nlangtag \ i18nlangtag \
i18nutil \ i18nutil \
index_data \ index_data \
$(if $(and $(ENABLE_GTK), $(filter LINUX,$(OS))), libreofficekitgtk) \
localedata_en \ localedata_en \
localedata_es \ localedata_es \
localedata_euro \ localedata_euro \
......
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_DESKTOP_INC_LIBREOFFICEKITGTK_H
#define INCLUDED_DESKTOP_INC_LIBREOFFICEKITGTK_H
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.h>
#ifdef __cplusplus
extern "C"
{
#endif
#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())
typedef struct _LOKDocView LOKDocView;
typedef struct _LOKDocViewClass LOKDocViewClass;
struct _LOKDocView
{
GtkScrolledWindow scrollWindow;
GtkWidget* pEventBox;
GtkWidget* pCanvas;
GdkPixbuf* pPixBuf;
LibreOfficeKit* pOffice;
LibreOfficeKitDocument* pDocument;
};
struct _LOKDocViewClass
{
GtkScrolledWindowClass parent_class;
void (*lok_docview) (LOKDocView* pDocView);
};
guint lok_docview_get_type (void);
GtkWidget* lok_docview_new ( LibreOfficeKit* pOffice );
gboolean lok_docview_open_document (LOKDocView* pDocView,
char* pPath);
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_Library_Library,libreofficekitgtk))
$(eval $(call gb_Library_use_externals,libreofficekitgtk,\
gtk \
))
$(eval $(call gb_Library_use_static_libraries,libreofficekitgtk,\
libreofficekit \
))
$(eval $(call gb_Library_add_cobjects,libreofficekitgtk,\
libreofficekit/source/gtk/lokdocview \
))
ifeq ($(OS),LINUX)
$(eval $(call gb_Library_add_libs,libreofficekitgtk,\
-ldl \
))
endif
# vim: set noet sw=4 ts=4:
...@@ -12,6 +12,7 @@ $(eval $(call gb_Module_Module,libreofficekit)) ...@@ -12,6 +12,7 @@ $(eval $(call gb_Module_Module,libreofficekit))
ifeq ($(OS),LINUX) ifeq ($(OS),LINUX)
$(eval $(call gb_Module_add_targets,libreofficekit,\ $(eval $(call gb_Module_add_targets,libreofficekit,\
StaticLibrary_libreofficekit \ StaticLibrary_libreofficekit \
Library_libreofficekitgtk \
)) ))
endif endif
......
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/types.h>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.h>
#include <LibreOfficeKit/LibreOfficeKitGtk.h>
static void lok_docview_class_init( LOKDocViewClass* pClass );
static void lok_docview_init( LOKDocView* pDocView );
SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
{
static guint lok_docview_type = 0;
if (!lok_docview_type)
{
GtkTypeInfo lok_docview_info =
{
"LokDocView",
sizeof( LOKDocView ),
sizeof( LOKDocViewClass ),
(GtkClassInitFunc) lok_docview_class_init,
(GtkObjectInitFunc) 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;
}
static void lok_docview_class_init( LOKDocViewClass* pClass )
{
pClass->lok_docview = NULL;
}
static void lok_docview_init( LOKDocView* pDocView )
{
pDocView->pEventBox = gtk_event_box_new();
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView),
pDocView->pEventBox );
pDocView->pCanvas = gtk_image_new();
gtk_container_add( GTK_CONTAINER( pDocView->pEventBox ), pDocView->pCanvas );
gtk_widget_show( pDocView->pCanvas );
gtk_widget_show( pDocView->pEventBox );
pDocView->pPixBuf = 0;
// TODO: figure out a clever view of getting paths set up.
pDocView->pOffice = 0;
pDocView->pDocument = 0;
}
SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
{
LOKDocView* pDocView = gtk_type_new( lok_docview_get_type() );
pDocView->pOffice = pOffice;
return GTK_WIDGET( pDocView );
}
SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, char* pPath )
{
if ( pDocView->pDocument )
{
pDocView->pDocument->pClass->destroy( pDocView->pDocument );
pDocView->pDocument = 0;
}
pDocView->pDocument = pDocView->pOffice->pClass->documentLoad( pDocView->pOffice,
pPath );
if ( pDocView->pPixBuf )
{
g_object_unref( G_OBJECT( pDocView->pPixBuf ) );
}
long nWidth, nHeight;
pDocView->pDocument->pClass->getDocumentSize( pDocView->pDocument, &nWidth, &nHeight );
// Draw the whole document at once (for now)
int nRenderWidth = nWidth / 10;
int nRenderHeight = nHeight / 10;
pDocView->pPixBuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
TRUE, 8,
nRenderWidth, nRenderHeight);
// TODO: move the rendering into it's own function etc.
unsigned char* pBuffer = gdk_pixbuf_get_pixels( pDocView->pPixBuf );
int nRowStride;
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
pBuffer,
nRenderWidth, nRenderHeight,
&nRowStride,
0, 0, // origin
nWidth, nHeight );
// TODO: double check that the rowstride really matches what we expected,
// although presumably we'd already be crashing by now if things were
// wrong.
(void) nRowStride;
gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas ), pDocView->pPixBuf );
return FALSE;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment