1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/* -*- 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>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#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>
#define LLO_USE_UNSTABLE_API
#include <liblibreoffice.hxx>
static int help()
{
fprintf( stderr, "Usage: gtktiledviewer <absolute-path-to-libreoffice-install> [path to document]\n" );
return 1;
}
bool drawCallback(GtkWidget* pCanvas, void* /* cairo_t* cr */, gpointer pData)
{
fprintf(stderr, "attempting to draw tile");
LODocument* pDocument = static_cast< LODocument* >( pData );
// This is UNX only for now, we need to get the appropriate equivalents
// for windows/mac (see SystemGraphicsData for what we need)
SystemGraphicsData aSystemGraphicsData;
aSystemGraphicsData.pDisplay = GDK_WINDOW_XDISPLAY( pCanvas->window );
aSystemGraphicsData.hDrawable = GDK_WINDOW_XWINDOW( pCanvas->window );
aSystemGraphicsData.pVisual = GDK_VISUAL_XVISUAL( gtk_widget_get_visual( pCanvas ) );
aSystemGraphicsData.nScreen = GDK_SCREEN_XNUMBER( gtk_widget_get_screen( pCanvas ) );
aSystemGraphicsData.nDepth = gdk_visual_get_depth( gtk_widget_get_visual( pCanvas ) );
aSystemGraphicsData.aColormap = GDK_COLORMAP_XCOLORMAP(
gdk_screen_get_default_colormap(
gtk_widget_get_screen( pCanvas ) ) );
aSystemGraphicsData.pXRenderFormat = XRenderFindVisualFormat(
GDK_WINDOW_XDISPLAY( pCanvas->window ),
GDK_VISUAL_XVISUAL( gtk_widget_get_visual( pCanvas ) ) );
// Hardcoded tile just to see whether or not we get any sort of output.
pDocument->paintTile( &aSystemGraphicsData, 256, 256, 0, 0, 5000, 5000 );
return true;
}
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;
}
LibLibreOffice *pOffice = lo_cpp_init( argv[1] );
if( !pOffice )
{
fprintf( stderr, "Failed to initialize\n" );
return -1;
}
// "This separate init is lame I think."
if( !pOffice->initialize( argv[1] ) )
{
fprintf( stderr, "failed to initialize\n" );
return -1;
}
LODocument* pDocument = pOffice->documentLoad( argv[2] );
gtk_init( &argc, &argv );
GtkWidget *pWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
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 );
GtkWidget* pScroller = gtk_scrolled_window_new( 0, 0 );
gtk_container_add( GTK_CONTAINER(pWindow), pScroller );
GtkWidget* pCanvas = gtk_drawing_area_new();
gtk_widget_set_size_request( pCanvas, 1000, 1000 );
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pScroller), pCanvas );
g_signal_connect( G_OBJECT(pCanvas), "expose_event", G_CALLBACK(drawCallback), pDocument);
gtk_widget_show( pCanvas );
gtk_widget_show( pScroller );
gtk_widget_show( pWindow );
gtk_main();
return 0;
}
|