zathura/callbacks.c

74 lines
1.8 KiB
C
Raw Normal View History

2010-11-10 20:31:15 +01:00
/* See LICENSE file for license and copyright information */
2010-11-12 13:48:18 +01:00
#include <callbacks.h>
#include <girara.h>
2010-11-13 12:40:48 +01:00
#include <stdlib.h>
2010-12-29 11:46:13 +01:00
#include <gtk/gtk.h>
2010-11-12 13:48:18 +01:00
#include "zathura.h"
2011-01-07 09:07:02 +01:00
#include "render.h"
#include "document.h"
2010-11-12 13:48:18 +01:00
gboolean
cb_destroy(GtkWidget* widget, gpointer data)
{
2011-02-09 12:29:09 +01:00
if (Zathura.UI.session) {
2010-11-12 13:48:18 +01:00
girara_session_destroy(Zathura.UI.session);
2010-11-13 12:40:48 +01:00
}
2010-11-12 13:48:18 +01:00
2011-01-24 12:43:39 +01:00
document_close();
/* free registered plugins */
zathura_document_plugin_free();
2010-11-12 13:48:18 +01:00
return TRUE;
}
2010-11-13 12:40:48 +01:00
void
buffer_changed(girara_session_t* session)
{
g_return_if_fail(session != NULL);
char* buffer = girara_buffer_get(session);
2011-02-09 12:29:09 +01:00
if (buffer) {
2010-11-18 21:22:43 +01:00
girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, buffer);
2010-11-13 12:40:48 +01:00
free(buffer);
2010-12-26 01:12:20 +01:00
} else {
girara_statusbar_item_set_text(session, Zathura.UI.statusbar.buffer, "");
}
2010-11-13 12:40:48 +01:00
}
2010-12-29 11:46:13 +01:00
void
cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
{
2011-02-09 12:29:09 +01:00
if (!Zathura.document || !Zathura.document->pages || !Zathura.UI.page_view) {
2010-12-29 11:46:13 +01:00
return;
}
/* get current adjustment values */
2011-01-06 08:59:10 +01:00
gdouble lower = gtk_adjustment_get_value(adjustment);
gdouble upper = lower + gtk_adjustment_get_page_size(adjustment);
2010-12-29 11:46:13 +01:00
/* find page that fits */
2011-02-09 12:29:09 +01:00
for (unsigned int page_id = 0; page_id < Zathura.document->number_of_pages; page_id++)
2010-12-29 11:46:13 +01:00
{
zathura_page_t* page = Zathura.document->pages[page_id];
2011-01-06 08:59:10 +01:00
/* check for rendered attribute */
2011-02-09 12:29:09 +01:00
if (page->rendered) {
2011-01-06 08:59:10 +01:00
continue;
}
2010-12-29 11:46:13 +01:00
double begin = page->offset;
2011-01-06 08:59:10 +01:00
double end = page->offset + page->height;
2011-02-09 12:29:09 +01:00
if ( ( (begin >= lower) && (end <= upper) ) /* page is in viewport */
2011-01-06 08:59:10 +01:00
|| ( (begin <= lower) && (end >= lower) && (end <= upper) ) /* end of the page is in viewport */
|| ( (begin >= lower) && (end >= upper) && (begin <= upper) ) /* begin of the page is in viewport */
) {
2011-01-24 13:10:06 +01:00
render_page(Zathura.Sync.render_thread, Zathura.document->pages[page_id]);
2010-12-29 11:46:13 +01:00
}
}
}