sdgui: make Page Up/Down scroll the view
This commit is contained in:
parent
e461189f0e
commit
82accaf200
16
src/sdgui.c
16
src/sdgui.c
|
@ -216,6 +216,20 @@ on_key_press (G_GNUC_UNUSED GtkWidget *widget, GdkEvent *event,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mods == 0)
|
||||||
|
{
|
||||||
|
StardictView *view = STARDICT_VIEW (g.view);
|
||||||
|
if (event->key.keyval == GDK_KEY_Page_Up)
|
||||||
|
{
|
||||||
|
stardict_view_scroll (view, GTK_SCROLL_PAGES, -0.5);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if (event->key.keyval == GDK_KEY_Page_Down)
|
||||||
|
{
|
||||||
|
stardict_view_scroll (view, GTK_SCROLL_PAGES, +0.5);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,8 +355,6 @@ main (int argc, char *argv[])
|
||||||
// TODO: make the entry have a background colour, rather than transparency
|
// TODO: make the entry have a background colour, rather than transparency
|
||||||
gtk_entry_set_has_frame (GTK_ENTRY (g.entry), FALSE);
|
gtk_entry_set_has_frame (GTK_ENTRY (g.entry), FALSE);
|
||||||
|
|
||||||
// TODO: supposedly attach to "key-press-event" here and react to
|
|
||||||
// PageUp/PageDown and up/down arrow keys... either here or in the Entry
|
|
||||||
g.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
g.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
gtk_window_set_default_size (GTK_WINDOW (g.window), 300, 600);
|
gtk_window_set_default_size (GTK_WINDOW (g.window), 300, 600);
|
||||||
g_signal_connect (g.window, "destroy",
|
g_signal_connect (g.window, "destroy",
|
||||||
|
|
|
@ -555,3 +555,24 @@ stardict_view_set_matched (StardictView *self, const gchar *matched)
|
||||||
self->matched = g_strdup (matched);
|
self->matched = g_strdup (matched);
|
||||||
reload (self);
|
reload (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
stardict_view_scroll (StardictView *self, GtkScrollStep step, gdouble amount)
|
||||||
|
{
|
||||||
|
g_return_if_fail (STARDICT_IS_VIEW (self));
|
||||||
|
|
||||||
|
GtkWidget *widget = GTK_WIDGET (self);
|
||||||
|
switch (step)
|
||||||
|
{
|
||||||
|
case GTK_SCROLL_STEPS:
|
||||||
|
self->top_offset += amount * natural_row_size (widget);
|
||||||
|
break;
|
||||||
|
case GTK_SCROLL_PAGES:
|
||||||
|
self->top_offset += amount * gtk_widget_get_allocated_height (widget);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
adjust_for_offset (self);
|
||||||
|
}
|
||||||
|
|
|
@ -30,5 +30,7 @@ GtkWidget *stardict_view_new (void);
|
||||||
void stardict_view_set_position (StardictView *view,
|
void stardict_view_set_position (StardictView *view,
|
||||||
StardictDict *dict, guint position);
|
StardictDict *dict, guint position);
|
||||||
void stardict_view_set_matched (StardictView *view, const gchar *matched);
|
void stardict_view_set_matched (StardictView *view, const gchar *matched);
|
||||||
|
void stardict_view_scroll (StardictView *view,
|
||||||
|
GtkScrollStep step, gdouble amount);
|
||||||
|
|
||||||
#endif // ! STARDICT_VIEW_H
|
#endif // ! STARDICT_VIEW_H
|
||||||
|
|
Loading…
Reference in New Issue