[gnome-commander] InternalViewer: Implement scrolling via keyboard arrow keys, partly fixing #95
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] InternalViewer: Implement scrolling via keyboard arrow keys, partly fixing #95
- Date: Sat, 13 Feb 2021 21:47:41 +0000 (UTC)
commit 3495339399ed05b0cacce45fe2e967df1ac10dcd
Author: Uwe Scholz <u scholz83 gmx de>
Date: Sat Feb 13 22:44:55 2021 +0100
InternalViewer: Implement scrolling via keyboard arrow keys, partly fixing #95
src/intviewer/image-render.cc | 86 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
---
diff --git a/src/intviewer/image-render.cc b/src/intviewer/image-render.cc
index e60ca7a3..8b708b42 100644
--- a/src/intviewer/image-render.cc
+++ b/src/intviewer/image-render.cc
@@ -45,6 +45,7 @@ using namespace std;
#define IMAGE_RENDER_DEFAULT_WIDTH 100
#define IMAGE_RENDER_DEFAULT_HEIGHT 200
+#define INC_VALUE 25.0
enum {
@@ -124,6 +125,17 @@ static void image_render_update_adjustments (ImageRender *obj);
public functions
(defined in the header file)
*****************************************/
+GtkAdjustment *image_render_get_h_adjustment (ImageRender *obj)
+{
+ g_return_val_if_fail (IS_IMAGE_RENDER(obj), nullptr);
+
+ if (obj->priv->h_adjustment)
+ {
+ return obj->priv->h_adjustment;
+ }
+ return nullptr;
+}
+
void image_render_set_h_adjustment (ImageRender *obj, GtkAdjustment *adjustment)
{
g_return_if_fail (IS_IMAGE_RENDER(obj));
@@ -148,6 +160,17 @@ void image_render_set_h_adjustment (ImageRender *obj, GtkAdjustment *adjustment)
}
+GtkAdjustment *image_render_get_v_adjustment (ImageRender *obj)
+{
+ g_return_val_if_fail (IS_IMAGE_RENDER(obj), nullptr);
+
+ if (obj->priv->v_adjustment)
+ {
+ return obj->priv->v_adjustment;
+ }
+ return nullptr;
+}
+
void image_render_set_v_adjustment (ImageRender *obj, GtkAdjustment *adjustment)
{
g_return_if_fail (IS_IMAGE_RENDER(obj));
@@ -293,6 +316,69 @@ void image_render_notify_status_changed (ImageRender *w)
static gboolean image_render_key_press (GtkWidget *widget, GdkEventKey *event)
{
+ g_return_val_if_fail (IS_IMAGE_RENDER (widget), FALSE);
+
+ auto imageRender = IMAGE_RENDER (widget);
+
+ switch (event->keyval)
+ {
+ case GDK_KEY_Up:
+ {
+ auto vAdjustment = image_render_get_v_adjustment(imageRender);
+ auto current = gtk_adjustment_get_value(vAdjustment);
+ auto lower = gtk_adjustment_get_lower(vAdjustment);
+ if (current > lower)
+ {
+ gtk_adjustment_set_value(vAdjustment, current - INC_VALUE);
+ }
+ return TRUE;
+ }
+ case GDK_KEY_Down:
+ {
+ auto vAdjustment = image_render_get_v_adjustment(imageRender);
+ auto current = gtk_adjustment_get_value(vAdjustment);
+ auto upper = gtk_adjustment_get_upper(vAdjustment);
+ auto page_size = gtk_adjustment_get_page_size(vAdjustment);
+ if (current < upper - page_size)
+ {
+ gtk_adjustment_set_value(vAdjustment, current + INC_VALUE);
+ }
+ return TRUE;
+ }
+ case GDK_KEY_Left:
+ {
+ auto hAdjustment = image_render_get_h_adjustment(imageRender);
+ auto current = gtk_adjustment_get_value(hAdjustment);
+ auto lower = gtk_adjustment_get_lower(hAdjustment);
+ if (current > lower)
+ {
+ gtk_adjustment_set_value(hAdjustment, current - INC_VALUE);
+ }
+ return TRUE;
+ }
+ case GDK_KEY_Right:
+ {
+ auto hAdjustment = image_render_get_h_adjustment(imageRender);
+ auto current = gtk_adjustment_get_value(hAdjustment);
+ auto upper = gtk_adjustment_get_upper(hAdjustment);
+ auto page_size = gtk_adjustment_get_page_size(hAdjustment);
+ if (current < upper - page_size)
+ {
+ gtk_adjustment_set_value(hAdjustment, current + INC_VALUE);
+ }
+ return TRUE;
+ }
+
+ default:
+ break;
+ }
+
+ switch (state_is_blank(event->keyval))
+ {
+ default:
+ break;
+ }
+
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]