--- a/talkatu/talkatuhistory.c Mon Apr 27 00:32:04 2020 +0000
+++ b/talkatu/talkatuhistory.c Mon Apr 27 00:32:14 2020 +0000
@@ -43,11 +43,67 @@
+ GtkAdjustment *vadjustment; G_DEFINE_TYPE(TalkatuHistory, talkatu_history, TALKATU_TYPE_VIEW)
/******************************************************************************
+ *****************************************************************************/ +talkatu_history_vadjustment_changed_cb(GtkAdjustment *adjustment, + TalkatuHistory *history = TALKATU_HISTORY(data); + if(history->auto_scroll) { + gdouble upper, pagesize; + upper = gtk_adjustment_get_upper(adjustment); + pagesize = gtk_adjustment_get_page_size(adjustment); + gtk_adjustment_set_value(adjustment, upper - pagesize); +talkatu_history_vadjustment_value_changed_cb(GtkAdjustment *adjustment, + TalkatuHistory *history = TALKATU_HISTORY(data); + gdouble current, upper, pagesize; + current = gtk_adjustment_get_value(adjustment); + upper = gtk_adjustment_get_upper(adjustment); + pagesize = gtk_adjustment_get_page_size(adjustment); + history->auto_scroll = (current + pagesize >= upper); +talkatu_history_vadjustment_notify_cb(GObject *obj, GParamSpec *pspec, + TalkatuHistory *history = TALKATU_HISTORY(obj); + GtkAdjustment *adjustment = NULL; + adjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(obj)); + if(g_set_object(&history->vadjustment, adjustment)) { + history->auto_scroll = TRUE; + g_signal_connect(G_OBJECT(adjustment), "value-changed", + G_CALLBACK(talkatu_history_vadjustment_value_changed_cb), + g_signal_connect(G_OBJECT(adjustment), "changed", + G_CALLBACK(talkatu_history_vadjustment_changed_cb), +/****************************************************************************** * GtkTextViewClass overrides
*****************************************************************************/
@@ -62,12 +118,29 @@
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);
+ history->auto_scroll = TRUE; + g_signal_connect(G_OBJECT(history), "notify::vadjustment", + G_CALLBACK(talkatu_history_vadjustment_notify_cb), NULL); +talkatu_history_finalize(GObject *obj) { + TalkatuHistory *history = TALKATU_HISTORY(obj); + g_clear_object(&history->vadjustment); + G_OBJECT_CLASS(talkatu_history_parent_class)->finalize(obj); talkatu_history_class_init(TalkatuHistoryClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass); GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS(klass);
+ obj_class->finalize = talkatu_history_finalize; text_view_class->create_buffer = talkatu_history_create_buffer;
@@ -97,16 +170,15 @@
talkatu_history_page_up(TalkatuHistory *history) {
- GtkAdjustment *adjustment = NULL;
g_return_if_fail(TALKATU_IS_HISTORY(history));
- adjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(history));
+ if(history->vadjustment != NULL) { - value = gtk_adjustment_get_value(adjustment);
- value -= gtk_adjustment_get_page_increment(adjustment);
- gtk_adjustment_set_value(adjustment, value);
+ value = gtk_adjustment_get_value(history->vadjustment); + value -= gtk_adjustment_get_page_increment(history->vadjustment); + gtk_adjustment_set_value(history->vadjustment, value); @@ -117,15 +189,14 @@
talkatu_history_page_down(TalkatuHistory *history) {
- GtkAdjustment *adjustment = NULL;
g_return_if_fail(TALKATU_IS_HISTORY(history));
- adjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(history));
+ if(history->vadjustment != NULL) { - value = gtk_adjustment_get_value(adjustment);
- value += gtk_adjustment_get_page_increment(adjustment);
- gtk_adjustment_set_value(adjustment, value);
+ value = gtk_adjustment_get_value(history->vadjustment); + value += gtk_adjustment_get_page_increment(history->vadjustment); + gtk_adjustment_set_value(history->vadjustment, value);