qulogic/talkatu

The history buffer was defaulting to a normal GtkTextTagTable which was breaking stuff. This wasn't noticed before as a TalkatuTagTable is usually set up via glade.
/*
* talkatu
* Copyright (C) 2017-2019 Gary Kramlich <grim@reaperworld.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include <talkatu/talkatuhistory.h>
#include <talkatu/talkatuhistorybuffer.h>
#include <talkatu/talkatumessage.h>
/**
* SECTION:talkatuhistory
* @Title: History View
* @Short_description: Chat history widget
*
* This widget is used to display the conversation history. It doesn't care if
* it is multi user or one to one.
*/
/**
* TALKATU_TYPE_HISTORY:
*
* The standard _get_type macro for #TalkatuHistory.
*/
/**
* TalkatuHistory:
*
* A #TalkatuView subclass that is used to display a conversation.
*/
struct _TalkatuHistory {
TalkatuView parent;
};
G_DEFINE_TYPE(TalkatuHistory, talkatu_history, TALKATU_TYPE_VIEW)
/******************************************************************************
* GtkTextViewClass overrides
*****************************************************************************/
static GtkTextBuffer *
talkatu_history_create_buffer(GtkTextView *view) {
return talkatu_history_buffer_new();
}
/******************************************************************************
* GObject Stuff
*****************************************************************************/
static void
talkatu_history_init(TalkatuHistory *history) {
gtk_text_view_set_editable(GTK_TEXT_VIEW(history), FALSE);
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(history), FALSE);
}
static void
talkatu_history_class_init(TalkatuHistoryClass *klass) {
GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS(klass);
text_view_class->create_buffer = talkatu_history_create_buffer;
}
/******************************************************************************
* Public API
*****************************************************************************/
/**
* talkatu_history_new:
*
* Creates a new #TalkatuHistory for displaying chat history.
*
* Returns: (transfer full): The new #TalkatuHistory instance.
*/
GtkWidget *talkatu_history_new(void) {
return GTK_WIDGET(g_object_new(
TALKATU_TYPE_HISTORY,
NULL
));
}
/**
* talkatu_history_page_up:
* @history: The #TalkatuHistory instance.
*
* Scrolls @history up one page.
*/
void
talkatu_history_page_up(TalkatuHistory *history) {
GtkAdjustment *adjustment = NULL;
double value = 0.0;
g_return_if_fail(TALKATU_IS_HISTORY(history));
adjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(history));
value = gtk_adjustment_get_value(adjustment);
value -= gtk_adjustment_get_page_increment(adjustment);
gtk_adjustment_set_value(adjustment, value);
}
/**
* talkatu_history_page_down:
* @history: The #TalkatuHistory instance.
*
* Scrolls @history down one page.
*/
void
talkatu_history_page_down(TalkatuHistory *history) {
GtkAdjustment *adjustment = NULL;
double value = 0.0;
g_return_if_fail(TALKATU_IS_HISTORY(history));
adjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(history));
value = gtk_adjustment_get_value(adjustment);
value += gtk_adjustment_get_page_increment(adjustment);
gtk_adjustment_set_value(adjustment, value);
}