lokdocview: clean up quad mode

It's not necessary since the normal widget renders normal 256x256px
tiles, not just a single huge one.

Change-Id: Ia1c6a6c8692769093232d66aa63fde096390a7b2
This commit is contained in:
Miklos Vajna
2015-03-18 09:15:54 +01:00
parent 7f4ac90254
commit a2675cb377
4 changed files with 0 additions and 366 deletions

View File

@@ -40,10 +40,6 @@ $(eval $(call gb_Executable_add_libs,gtktiledviewer,\
))
endif
$(eval $(call gb_Executable_add_cobjects,gtktiledviewer,\
libreofficekit/qa/lokdocview_quad/lokdocview_quad \
))
$(eval $(call gb_Executable_add_exception_objects,gtktiledviewer,\
libreofficekit/qa/gtktiledviewer/gtktiledviewer \
))

View File

@@ -18,7 +18,6 @@
#include <LibreOfficeKit/LibreOfficeKitGtk.h>
#include <LibreOfficeKit/LibreOfficeKitInit.h>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include "../lokdocview_quad/lokdocview_quad.h"
#include <com/sun/star/awt/Key.hpp>
#include <rsc/rsc-vcl-shared-types.hxx>
@@ -36,7 +35,6 @@ static int help()
static GtkWidget* pDocView;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
static GtkWidget* pDocViewQuad;
static GtkWidget* pVBox;
// GtkComboBox requires gtk 2.24 or later
#if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
@@ -59,10 +57,6 @@ void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
{
fCurrentZoom = lok_docview_get_zoom( LOK_DOCVIEW(pDocView) );
}
else if ( pDocViewQuad )
{
fCurrentZoom = lok_docview_quad_get_zoom( LOK_DOCVIEW_QUAD(pDocViewQuad) );
}
if ( strcmp(sName, "gtk-zoom-in") == 0)
{
@@ -100,10 +94,6 @@ void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
{
lok_docview_set_zoom( LOK_DOCVIEW(pDocView), fZoom );
}
else if ( pDocViewQuad )
{
lok_docview_quad_set_zoom( LOK_DOCVIEW_QUAD(pDocViewQuad), fZoom );
}
}
}
@@ -133,34 +123,6 @@ void toggleBold(GtkWidget* /*pButton*/, gpointer /*pItem*/)
lok_docview_post_command(pLOKDocView, ".uno:Bold");
}
void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
{
if ( pDocView )
{
const float fCurrentZoom = lok_docview_get_zoom( LOK_DOCVIEW(pDocView) );
gtk_widget_destroy( pDocView );
pDocView = 0;
pDocViewQuad = lok_docview_quad_new( pOffice );
gtk_container_add( GTK_CONTAINER(pVBox), pDocViewQuad );
gtk_widget_show( pDocViewQuad );
lok_docview_quad_set_zoom( LOK_DOCVIEW_QUAD(pDocViewQuad), fCurrentZoom );
lok_docview_quad_open_document( LOK_DOCVIEW_QUAD(pDocViewQuad), pFileName );
}
else if ( pDocViewQuad )
{
const float fCurrentZoom = lok_docview_quad_get_zoom( LOK_DOCVIEW_QUAD(pDocViewQuad) );
gtk_widget_destroy( pDocViewQuad );
pDocViewQuad = 0;
pDocView = lok_docview_new( pOffice );
gtk_container_add( GTK_CONTAINER(pVBox), pDocView );
gtk_widget_show( pDocView );
lok_docview_set_zoom( LOK_DOCVIEW(pDocView), fCurrentZoom );
lok_docview_open_document( LOK_DOCVIEW(pDocView), pFileName );
}
}
/// Receives a key press or release event.
static void signalKey(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pData*/)
{
@@ -253,9 +215,6 @@ void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
{
int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) );
// We don't really care about the quad view for now -- it's only purpose
// is to check that the edges of tiles aren't messed up, and no real
// reason to maintain it to be able to show other document parts etc.
if ( pDocView )
{
lok_docview_set_part( LOK_DOCVIEW(pDocView), nPart );
@@ -359,14 +318,6 @@ int main( int argc, char* argv[] )
g_signal_connect( G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), NULL );
#endif
GtkToolItem* pSeparator3 = gtk_separator_tool_item_new();
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator3, -1);
GtkToolItem* pEnableQuadView = gtk_toggle_tool_button_new();
gtk_tool_button_set_label( GTK_TOOL_BUTTON(pEnableQuadView), "Use Quad View" );
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pEnableQuadView, -1 );
g_signal_connect( G_OBJECT(pEnableQuadView), "toggled", G_CALLBACK(changeQuadView), NULL );
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
pEnableEditing = gtk_toggle_tool_button_new();
gtk_tool_button_set_label(GTK_TOOL_BUTTON(pEnableEditing), "Editing");
@@ -383,7 +334,6 @@ int main( int argc, char* argv[] )
// Docview
pDocView = lok_docview_new( pOffice );
pDocViewQuad = 0;
g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
// Input handling.

View File

@@ -1,246 +0,0 @@
/* -*- 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 "lokdocview_quad.h"
static void lok_docview_quad_class_init( LOKDocViewQuadClass* pClass );
static void lok_docview_quad_init( LOKDocViewQuad* pDocView );
// We specifically need to destroy the document when closing in order to ensure
// that lock files etc. are cleaned up.
void lcl_onDestroy( LOKDocViewQuad* pDocView, gpointer pData )
{
(void) pData;
if ( pDocView->pDocument )
pDocView->pDocument->pClass->destroy( pDocView->pDocument );
pDocView->pDocument = NULL;
}
SAL_DLLPUBLIC_EXPORT guint lok_docview_quad_get_type()
{
static guint lok_docview_quad_type = 0;
if (!lok_docview_quad_type)
{
GtkTypeInfo lok_docview_quad_info =
{
"LokDocViewQuad",
sizeof( LOKDocViewQuad ),
sizeof( LOKDocViewQuadClass ),
(GtkClassInitFunc) lok_docview_quad_class_init,
(GtkObjectInitFunc) lok_docview_quad_init,
NULL,
NULL,
(GtkClassInitFunc) NULL
};
lok_docview_quad_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_docview_quad_info );
}
return lok_docview_quad_type;
}
static void lok_docview_quad_class_init( LOKDocViewQuadClass* pClass )
{
pClass->lok_docview_quad = NULL;
}
static void lok_docview_quad_init( LOKDocViewQuad* pDocView )
{
int x, y;
// 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.
gtk_scrolled_window_set_hadjustment( GTK_SCROLLED_WINDOW( pDocView ), NULL );
gtk_scrolled_window_set_vadjustment( GTK_SCROLLED_WINDOW( pDocView ), NULL );
pDocView->pEventBox = gtk_event_box_new();
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView),
pDocView->pEventBox );
pDocView->pGrid = gtk_table_new( 2, 2, TRUE );
gtk_container_add( GTK_CONTAINER( pDocView->pEventBox ), pDocView->pGrid );
for ( x = 0; x < 2; x++ )
{
for ( y = 0; y < 2; y++ )
{
pDocView->pCanvas[x][y] = gtk_image_new();
gtk_table_attach_defaults( GTK_TABLE( pDocView->pGrid ), pDocView->pCanvas[x][y], x, x+1, y, y+1 );
//gtk_container_add( GTK_CONTAINER( pDocView->pEventBox ), pDocView->pCanvas );
gtk_widget_show( pDocView->pCanvas[x][y] );
pDocView->pPixBuf[x][y] = 0;
}
}
gtk_widget_show( pDocView->pGrid );
gtk_widget_show( pDocView->pEventBox );
// TODO: figure out a clever view of getting paths set up.
pDocView->pOffice = 0;
pDocView->pDocument = 0;
pDocView->fZoom = 1;
gtk_signal_connect( GTK_OBJECT(pDocView), "destroy",
GTK_SIGNAL_FUNC(lcl_onDestroy), NULL );
}
SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_quad_new( LibreOfficeKit* pOffice )
{
LOKDocViewQuad* pDocView = gtk_type_new( lok_docview_quad_get_type() );
pDocView->pOffice = pOffice;
return GTK_WIDGET( pDocView );
}
void renderDocument( LOKDocViewQuad* pDocView )
{
long nWidth, nHeight;
int nRenderWidth, nRenderHeight;
int x, y;
GdkPixbuf* pTempBuf;
g_assert( pDocView->pDocument );
for ( x = 0; x < 2; x++ )
{
for ( y = 0; y < 2; y++ )
{
if ( pDocView->pPixBuf[x][y] )
{
g_object_unref( G_OBJECT( pDocView->pPixBuf[x][y] ) );
}
}
}
pDocView->pDocument->pClass->getDocumentSize( pDocView->pDocument, &nWidth, &nHeight );
// Draw the whole document at once (for now)
// TODO: we really should scale by screen DPI here -- 10 seems to be a vaguely
// correct factor for my screen at least.
nRenderWidth = nWidth * pDocView->fZoom / 10;
nRenderHeight = nHeight * pDocView->fZoom / 10;
// TOP-LEFT: standard
// TOP-RIGHT: 2x resolution rendered (post-scaled to 50%)
// BOTTOM-LEFT: 1/2 resolution rendered (post-scaled 200%)
// BOTTOM-RIGHT: 1/2 resolution rendered (post-scaled 400%)
pDocView->pPixBuf[0][0] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
TRUE, 8,
nRenderWidth / 2, nRenderHeight / 2 );
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
gdk_pixbuf_get_pixels( pDocView->pPixBuf[0][0] ),
nRenderWidth / 2, nRenderHeight / 2,
0, 0, // origin
nWidth / 2, nHeight / 2 );
pDocView->pPixBuf[1][0] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
TRUE, 8,
nRenderWidth, nRenderHeight );
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
gdk_pixbuf_get_pixels( pDocView->pPixBuf[1][0] ),
nRenderWidth, nRenderHeight,
nWidth / 2, 0,
nWidth / 2, nHeight / 2 );
pTempBuf = gdk_pixbuf_scale_simple( GDK_PIXBUF( pDocView->pPixBuf[1][0] ),
nRenderWidth / 2,
nRenderHeight / 2,
GDK_INTERP_BILINEAR );
g_object_unref( G_OBJECT( pDocView->pPixBuf[1][0] ) );
pDocView->pPixBuf[1][0] = pTempBuf;
pDocView->pPixBuf[0][1] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
TRUE, 8,
nRenderWidth / 4, nRenderHeight / 4 );
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
gdk_pixbuf_get_pixels( pDocView->pPixBuf[0][1] ),
nRenderWidth / 4, nRenderHeight / 4,
0, nHeight / 2,
nWidth / 2, nHeight / 2 );
pTempBuf = gdk_pixbuf_scale_simple( GDK_PIXBUF( pDocView->pPixBuf[0][1] ),
nRenderWidth / 2,
nRenderHeight / 2,
GDK_INTERP_BILINEAR );
g_object_unref( G_OBJECT( pDocView->pPixBuf[0][1] ) );
pDocView->pPixBuf[0][1] = pTempBuf;
pDocView->pPixBuf[1][1] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
TRUE, 8,
nRenderWidth / 8, nRenderHeight / 8 );
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
gdk_pixbuf_get_pixels( pDocView->pPixBuf[1][1] ),
nRenderWidth / 8, nRenderHeight / 8,
nWidth / 2, nHeight / 2,
nWidth / 2, nHeight / 2 );
pTempBuf = gdk_pixbuf_scale_simple( GDK_PIXBUF( pDocView->pPixBuf[1][1] ),
nRenderWidth / 2,
nRenderHeight / 2,
GDK_INTERP_BILINEAR );
g_object_unref( G_OBJECT( pDocView->pPixBuf[1][1] ) );
pDocView->pPixBuf[1][1] = pTempBuf;
// gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas ), pDocView->pPixBuf );
for ( x = 0; x < 2; x++ )
{
for ( y = 0; y < 2; y++ )
{
gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas[x][y] ), pDocView->pPixBuf[x][y] );
}
}
}
SAL_DLLPUBLIC_EXPORT gboolean lok_docview_quad_open_document( LOKDocViewQuad* pDocView, char* pPath )
{
if ( pDocView->pDocument )
{
pDocView->pDocument->pClass->destroy( pDocView->pDocument );
pDocView->pDocument = NULL;
}
pDocView->pDocument = pDocView->pOffice->pClass->documentLoad( pDocView->pOffice,
pPath );
if ( !pDocView->pDocument )
{
// FIXME: should have a GError parameter and populate it.
char *pError = pDocView->pOffice->pClass->getError( pDocView->pOffice );
fprintf( stderr, "Error opening document '%s'\n", pError );
return FALSE;
}
else
renderDocument( pDocView );
return TRUE;
}
SAL_DLLPUBLIC_EXPORT void lok_docview_quad_set_zoom ( LOKDocViewQuad* pDocView, float fZoom )
{
pDocView->fZoom = fZoom;
if ( pDocView->pDocument )
{
renderDocument( pDocView );
}
// TODO: maybe remember and reset positiong?
}
SAL_DLLPUBLIC_EXPORT float lok_docview_quad_get_zoom ( LOKDocViewQuad* pDocView )
{
return pDocView->fZoom;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -1,66 +0,0 @@
/* -*- 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_LOK_QA_INC_LIBREOFFICEKITGTK_H
#define INCLUDED_LOK_QA_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_QUAD(obj) GTK_CHECK_CAST (obj, lok_docview_quad_get_type(), LOKDocViewQuad)
#define LOK_DOCVIEW_QUAD_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, lok_docview_quad_get_type(), LOKDocViewQuadClass)
#define IS_LOK_DOCVIEW_QUAD(obj) GTK_CHECK_TYPE (obj, lok_docview_quad_get_type())
typedef struct _LOKDocViewQuad LOKDocViewQuad;
typedef struct _LOKDocViewQuadClass LOKDocViewQuadClass;
struct _LOKDocViewQuad
{
GtkScrolledWindow scrollWindow;
GtkWidget* pEventBox;
GtkWidget* pGrid;
GtkWidget* pCanvas[2][2];
GdkPixbuf* pPixBuf[2][2];
float fZoom;
LibreOfficeKit* pOffice;
LibreOfficeKitDocument* pDocument;
};
struct _LOKDocViewQuadClass
{
GtkScrolledWindowClass parent_class;
void (*lok_docview_quad) (LOKDocViewQuad* pDocView);
};
guint lok_docview_quad_get_type (void);
GtkWidget* lok_docview_quad_new ( LibreOfficeKit* pOffice );
gboolean lok_docview_quad_open_document (LOKDocViewQuad* pDocView,
char* pPath);
void lok_docview_quad_set_zoom (LOKDocViewQuad* pDocView,
float fZoom);
float lok_docview_quad_get_zoom (LOKDocViewQuad* pDocView);
#ifdef __cplusplus
}
#endif
#endif