2014-05-07 20:14:59 +01:00
|
|
|
/* -*- 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 <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-05-09 14:39:55 +01:00
|
|
|
#include <gdk/gdk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
2014-05-07 20:14:59 +01:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2014-05-09 14:39:55 +01:00
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
|
|
|
|
// Only for the SystemGraphicsData struct, and hopefully we can find some better
|
|
|
|
// replacement for that at some point.
|
|
|
|
#include <vcl/sysdata.hxx>
|
|
|
|
|
2014-05-09 14:37:27 +01:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
2014-05-07 20:14:59 +01:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.hxx>
|
|
|
|
|
2014-05-09 14:39:55 +01:00
|
|
|
using namespace ::lok;
|
|
|
|
|
2014-05-07 20:14:59 +01:00
|
|
|
static int help()
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Usage: gtktiledviewer <absolute-path-to-libreoffice-install> [path to document]\n" );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-05-16 09:08:41 +01:00
|
|
|
static GtkWidget* ourCanvas;
|
2014-05-09 14:39:55 +01:00
|
|
|
|
2014-05-16 09:08:41 +01:00
|
|
|
bool drawCallback(GtkWidget* /* The eventbox */, void* /* cairo_t* cr */, gpointer pData)
|
2014-05-09 14:39:55 +01:00
|
|
|
{
|
|
|
|
fprintf(stderr, "attempting to draw tile");
|
|
|
|
|
|
|
|
Document* pDocument = static_cast< Document* >( pData );
|
|
|
|
|
|
|
|
// Hardcoded tile just to see whether or not we get any sort of output.
|
2014-05-16 09:08:41 +01:00
|
|
|
unsigned char* pBuffer = pDocument->paintTile( 1000, 1000, 0, 0, 10000, 10000 );
|
|
|
|
|
|
|
|
GdkPixbuf* pBixBuf = gdk_pixbuf_new_from_data( pBuffer, GDK_COLORSPACE_RGB,
|
|
|
|
false, 8, 1000, 1000, 3*1000,
|
|
|
|
0, 0 );
|
|
|
|
pBixBuf = gdk_pixbuf_flip( pBixBuf, false );
|
|
|
|
gtk_image_set_from_pixbuf( GTK_IMAGE(ourCanvas), pBixBuf );
|
|
|
|
|
|
|
|
// TODO: we need to keep track of and cleanup these buffers etc.
|
2014-05-09 14:39:55 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-07 20:14:59 +01:00
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
if( argc < 2 ||
|
|
|
|
( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
|
|
|
|
return help();
|
|
|
|
|
|
|
|
if ( argv[1][0] != '/' )
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Absolute path required to libreoffice install\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
::lok::Office *pOffice = ::lok::lok_cpp_init( argv[1] );
|
|
|
|
if( !pOffice )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Failed to initialize\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
::lok::Document* pDocument = pOffice->documentLoad( argv[2] );
|
|
|
|
|
|
|
|
gtk_init( &argc, &argv );
|
|
|
|
|
2014-05-09 14:39:55 +01:00
|
|
|
GtkWidget *pWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
2014-05-07 20:14:59 +01:00
|
|
|
gtk_window_set_title( GTK_WINDOW(pWindow), "LibreOffice GTK Tiled Viewer" );
|
|
|
|
gtk_window_set_default_size(GTK_WINDOW(pWindow), 800, 600);
|
|
|
|
g_signal_connect( pWindow, "destroy", G_CALLBACK(gtk_main_quit), NULL );
|
|
|
|
|
|
|
|
|
2014-05-09 14:39:55 +01:00
|
|
|
GtkWidget* pScroller = gtk_scrolled_window_new( 0, 0 );
|
2014-05-07 20:14:59 +01:00
|
|
|
gtk_container_add( GTK_CONTAINER(pWindow), pScroller );
|
|
|
|
|
2014-05-16 09:08:41 +01:00
|
|
|
GtkWidget* pEventBox = gtk_event_box_new();
|
|
|
|
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pScroller), pEventBox );
|
|
|
|
|
|
|
|
GtkWidget* pCanvas = gtk_image_new();
|
|
|
|
ourCanvas = pCanvas;
|
|
|
|
gtk_container_add( GTK_CONTAINER( pEventBox ), pCanvas );
|
|
|
|
|
2014-05-09 14:39:55 +01:00
|
|
|
|
2014-05-16 09:08:41 +01:00
|
|
|
g_signal_connect( G_OBJECT(pEventBox), "button-press-event", G_CALLBACK(drawCallback), pDocument);
|
2014-05-09 14:39:55 +01:00
|
|
|
|
|
|
|
gtk_widget_show( pCanvas );
|
2014-05-16 09:08:41 +01:00
|
|
|
gtk_widget_show( pEventBox );
|
2014-05-07 20:14:59 +01:00
|
|
|
gtk_widget_show( pScroller );
|
|
|
|
gtk_widget_show( pWindow );
|
|
|
|
|
2014-05-16 09:08:41 +01:00
|
|
|
drawCallback( pCanvas, 0, pDocument );
|
2014-05-07 20:14:59 +01:00
|
|
|
|
|
|
|
gtk_main();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|