Added end scrolling fat input, added end scrolling at Ctrl-End, added begin scrolling at Ctrl-Home, added font size changing at Ctrl-Scroll, added text scroller for GmWorldTextView
This commit is contained in:
parent
d68ed6388c
commit
293a073f86
|
@ -1,10 +1,15 @@
|
|||
#include "gm-app.h"
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#include "../gm-app.h"
|
||||
#include "gm-world-view.h"
|
||||
#include "gm-world-text-view.h"
|
||||
#include "gm-world-input-view.h"
|
||||
#include "debug.h"
|
||||
#include "gm-text-scroller.h"
|
||||
#include "../debug.h"
|
||||
#include "../gm-color-table.h"
|
||||
|
||||
#define GM_WORLD_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GM_TYPE_WORLD_VIEW, GmWorldViewPrivate))
|
||||
#define GM_WORLD_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), \
|
||||
GM_TYPE_WORLD_VIEW, GmWorldViewPrivate))
|
||||
|
||||
struct _GmWorldViewPrivate {
|
||||
GmWorld *world;
|
||||
|
@ -15,6 +20,7 @@ struct _GmWorldViewPrivate {
|
|||
GtkTreeModel *tree_model_userlist;
|
||||
GmWorldTextView *text_view_world;
|
||||
GmWorldInputView *text_view_input;
|
||||
GmTextScroller *text_scroller_world;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -35,6 +41,10 @@ void on_gm_world_view_world_state_changing(GmWorld *world, guint state,
|
|||
GmWorldView *view);
|
||||
void on_gm_world_view_world_active_changed(GmWorld *world, gboolean active,
|
||||
GmWorldView *view);
|
||||
gboolean on_gm_world_view_world_text_view_scroll_event(GmWorldView *view,
|
||||
GdkEventScroll *event, GmWorldTextView *text);
|
||||
gboolean on_gm_world_view_world_input_view_key_pressed(GtkWidget *widget,
|
||||
GdkEventKey *event, GmWorldView *view);
|
||||
|
||||
/* Signals */
|
||||
|
||||
|
@ -137,6 +147,8 @@ gm_world_view_create_input_text_view(GmWorldView *view) {
|
|||
|
||||
view->priv->text_view_input = GM_WORLD_INPUT_VIEW(input_text_view);
|
||||
|
||||
g_signal_connect(input_text_view, "key_press_event",
|
||||
G_CALLBACK(on_gm_world_view_world_input_view_key_pressed), view);
|
||||
return scrolled_window;
|
||||
}
|
||||
|
||||
|
@ -153,6 +165,14 @@ gm_world_view_create_world_text_view(GmWorldView *view) {
|
|||
gtk_container_add(GTK_CONTAINER(scrolled_window), world_text_view);
|
||||
|
||||
view->priv->text_view_world = GM_WORLD_TEXT_VIEW(world_text_view);
|
||||
|
||||
// Create new text scroller, this object will take care of itself and will
|
||||
// destroy itself when the view dies, neat!
|
||||
view->priv->text_scroller_world =
|
||||
gm_text_scroller_new(GTK_TEXT_VIEW(view->priv->text_view_world));
|
||||
|
||||
g_signal_connect(world_text_view, "scroll_event",
|
||||
G_CALLBACK(on_gm_world_view_world_text_view_scroll_event), view);
|
||||
return scrolled_window;
|
||||
}
|
||||
|
||||
|
@ -208,8 +228,7 @@ on_gm_world_view_destroy(GmWorldView *view, gpointer user_data) {
|
|||
gm_options_set_int(gm_world_options(view->priv->world), "pane_position",
|
||||
GTK_WIDGET(view->priv->hpaned)->allocation.width -
|
||||
gtk_paned_get_position(GTK_PANED(view->priv->hpaned)));
|
||||
|
||||
debug_msg(0, "%d", gm_options_get_int(gm_world_options(view->priv->world), "pane_position"));
|
||||
|
||||
gm_options_save(gm_world_options(view->priv->world));
|
||||
}
|
||||
|
||||
|
@ -217,7 +236,6 @@ void
|
|||
on_gm_world_view_show(GmWorldView *view, gpointer user_data) {
|
||||
gm_do_events();
|
||||
|
||||
debug_msg(0, "%d", GTK_WIDGET(view->priv->hpaned)->allocation.width);
|
||||
gtk_paned_set_position(GTK_PANED(view->priv->hpaned),
|
||||
GTK_WIDGET(view->priv->hpaned)->allocation.width
|
||||
- gm_options_get_int(gm_world_options(view->priv->world),
|
||||
|
@ -230,8 +248,6 @@ gm_world_view_new(GmWorld *world) {
|
|||
|
||||
view->priv->world = g_object_ref(world);
|
||||
|
||||
debug_msg(0, "%d", gm_world_history(view->priv->world));
|
||||
|
||||
gm_world_input_view_set_history(view->priv->text_view_input,
|
||||
gm_world_history(view->priv->world));
|
||||
|
||||
|
@ -376,11 +392,30 @@ gm_world_view_set_focus(GmWorldView *view) {
|
|||
gtk_widget_grab_focus(GTK_WIDGET(view->priv->text_view_input));
|
||||
}
|
||||
|
||||
void
|
||||
gm_world_view_change_font_size(GmWorldView *view, gint size_change) {
|
||||
GtkStyle *style = gtk_widget_get_style(GTK_WIDGET(view));
|
||||
PangoFontDescription *desc = style->font_desc;
|
||||
PangoFontDescription *copy = pango_font_description_copy(desc);
|
||||
gchar *new_font;
|
||||
|
||||
pango_font_description_set_size(copy,
|
||||
pango_font_description_get_size(copy) +
|
||||
(size_change * PANGO_SCALE));
|
||||
new_font = pango_font_description_to_string(copy);
|
||||
gm_color_table_set_font_description(gm_app_color_table(gm_app_instance()),
|
||||
new_font);
|
||||
|
||||
pango_font_description_free(copy);
|
||||
g_free(new_font);
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
void
|
||||
on_gm_world_input_view_world_text_activate(GmWorldInputView *iview, gchar *text,
|
||||
GmWorldView *view) {
|
||||
gm_world_process_input(view->priv->world, text);
|
||||
gm_world_process_input(view->priv->world, text);
|
||||
gm_text_scroller_scroll_end(view->priv->text_scroller_world);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -457,3 +492,49 @@ on_gm_world_view_world_active_changed(GmWorld *world, gboolean active,
|
|||
gtk_widget_grab_focus(GTK_WIDGET(view->priv->text_view_input));
|
||||
}
|
||||
}
|
||||
|
||||
gboolean on_gm_world_view_world_text_view_scroll_event(GmWorldView *view,
|
||||
GdkEventScroll *event, GmWorldTextView *text) {
|
||||
if (event->state & GDK_CONTROL_MASK) {
|
||||
switch (event->direction) {
|
||||
case GDK_SCROLL_UP:
|
||||
// Font kleiner maken
|
||||
gm_world_view_change_font_size(view, -1);
|
||||
break;
|
||||
case GDK_SCROLL_DOWN:
|
||||
// Font groter maken
|
||||
gm_world_view_change_font_size(view, 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
on_gm_world_view_world_input_view_key_pressed(GtkWidget *widget,
|
||||
GdkEventKey *event, GmWorldView *view) {
|
||||
switch (event->keyval) {
|
||||
case GDK_Home: case GDK_End:
|
||||
if ((event->state | GDK_CONTROL_MASK) == event->state) {
|
||||
if (event->keyval == GDK_End) {
|
||||
gm_text_scroller_scroll_end(
|
||||
view->priv->text_scroller_world);
|
||||
} else {
|
||||
gm_text_scroller_scroll_begin(
|
||||
view->priv->text_scroller_world);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
Reference in New Issue