zathura/callbacks.c

131 lines
3.4 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 <girara/statusbar.h>
#include <girara/session.h>
#include <girara/settings.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
2011-08-31 14:35:53 +02:00
#include "callbacks.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"
2011-04-19 20:23:58 +02:00
#include "utils.h"
2011-09-29 18:08:37 +02:00
#include "shortcuts.h"
2010-11-12 13:48:18 +01:00
gboolean
2011-09-21 00:46:03 +02:00
cb_destroy(GtkWidget* UNUSED(widget), gpointer UNUSED(data))
2010-11-12 13:48:18 +01:00
{
2011-10-16 20:59:25 +02:00
gtk_main_quit();
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);
2011-04-18 17:37:03 +02:00
g_return_if_fail(session->global.data != NULL);
zathura_t* zathura = session->global.data;
2010-11-13 12:40:48 +01:00
char* buffer = girara_buffer_get(session);
2011-02-09 12:29:09 +01:00
if (buffer) {
2011-04-18 17:37:03 +02: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 {
2011-04-18 17:37:03 +02:00
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-04-18 17:37:03 +02:00
zathura_t* zathura = data;
2011-04-18 21:22:35 +02:00
if (!zathura || !zathura->document || !zathura->document->pages || !zathura->ui.page_view) {
2010-12-29 11:46:13 +01:00
return;
}
/* get current adjustment values */
2011-04-19 20:41:16 +02: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-04-18 17:37:03 +02:00
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++)
2010-12-29 11:46:13 +01:00
{
2011-04-18 17:37:03 +02:00
zathura_page_t* page = zathura->document->pages[page_id];
2011-01-06 08:59:10 +01:00
2011-04-19 20:41:16 +02:00
page_offset_t* offset = page_calculate_offset(page);
if (offset == NULL) {
continue;
}
double begin = offset->y;
2011-09-29 18:51:24 +02:00
double end = offset->y + page->height * zathura->document->scale;
2011-04-19 20:41:16 +02:00
2011-04-19 21:42:18 +02:00
if ( ( (begin >= lower) && (end <= upper) ) /* [> page is in viewport <]*/
2011-04-19 20:41:16 +02: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 <] */
) {
page->visible = true;
2011-04-19 21:42:18 +02:00
if (page->surface == NULL) {
render_page(zathura->sync.render_thread, page);
}
2011-04-19 20:46:33 +02:00
} else {
page->visible = false;
cairo_surface_destroy(page->surface);
page->surface = NULL;
2010-12-29 11:46:13 +01:00
}
2011-09-29 15:23:13 +02:00
2011-04-19 20:41:16 +02:00
free(offset);
2010-12-29 11:46:13 +01:00
}
}
void
2011-11-20 11:32:34 +01:00
cb_pages_per_row_value_changed(girara_session_t* UNUSED(session), const char* UNUSED(name), girara_setting_type_t UNUSED(type), void* value, void* data)
{
2011-11-20 11:32:34 +01:00
g_return_if_fail(value != NULL);
int pages_per_row = *(int*) value;
zathura_t* zathura = data;
2011-07-21 14:48:48 +02:00
if (pages_per_row < 1) {
pages_per_row = 1;
2011-07-21 14:48:48 +02:00
}
page_view_set_mode(zathura, pages_per_row);
}
2011-09-29 17:05:54 +02:00
void
2011-09-29 18:17:03 +02:00
cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
2011-09-29 18:08:37 +02:00
GtkTreeViewColumn* UNUSED(column), zathura_t* zathura)
2011-09-29 17:05:54 +02:00
{
if (tree_view == NULL || zathura == NULL || zathura->ui.session == NULL) {
return;
}
GtkTreeModel *model;
GtkTreeIter iter;
g_object_get(tree_view, "model", &model, NULL);
if(gtk_tree_model_get_iter(model, &iter, path))
{
zathura_index_element_t* index_element;
2011-09-29 17:28:09 +02:00
gtk_tree_model_get(model, &iter, 2, &index_element, -1);
2011-09-29 17:05:54 +02:00
if (index_element == NULL) {
return;
}
if (index_element->type == ZATHURA_LINK_TO_PAGE) {
sc_toggle_index(zathura->ui.session, NULL, 0);
page_set_delayed(zathura, index_element->target.page_number);
2011-09-29 17:05:54 +02:00
} else if (index_element->type == ZATHURA_LINK_EXTERNAL) {
// TODO
}
}
g_object_unref(model);
}