[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: gEDA-user: gschem: Using mouse wheels for scrolling



On Sat, May 22, 2004 at 07:06:04PM -0400, Ales Hvezda wrote:

The place to add this will probably be in gschem/noweb/x_event.nw in the functions: x_event_button_pressed() or x_event_button_released()
A new function x_event_scroll was needed since GTK handles mouse wheel events specially.

Also, if you take a look at a_pan_mouse() in gschem/noweb/a_pan.nw, I think that function is all you will need [...]
My code virtually moves the scrollbars instead, using their page_size divided by 4 as delta.
Patch attached.

CU Sascha

--
Registered Linux User #77587 (http://counter.li.org/)

bomb terrorist afghanistan PGP encrypt CIA FBI BND MAD StaSi anschlag strike sex pussy xxx kill bj hitler Gates MS Windows ZV ZDV
diff -Nur geda-gschem-20040111/include/prototype.h geda-gschem-20040111-scrollwheels/include/prototype.h
--- geda-gschem-20040111/include/prototype.h	2004-01-01 02:43:01.000000000 +0100
+++ geda-gschem-20040111-scrollwheels/include/prototype.h	2004-05-24 22:48:49.000000000 +0200
@@ -784,6 +784,7 @@
 void x_event_vschanged(GtkAdjustment *adj, TOPLEVEL *w_current);
 gint x_event_enter(GtkWidget *widget, GdkEventCrossing *event, TOPLEVEL *w_current);
 gint x_event_key_press(GtkWidget *widget, GdkEventKey *event, TOPLEVEL *w_current);
+gint x_event_scroll(GtkWidget *widget, GdkEventScroll *event, TOPLEVEL *w_current);
 /* x_fileselect.c */
 void x_fileselect_destroy_window(GtkWidget *widget, FILEDIALOG *f_current);
 int x_fileselect_keypress(GtkWidget *widget, GdkEventKey *event, FILEDIALOG *f_current);
diff -Nur geda-gschem-20040111/noweb/x_event.nw geda-gschem-20040111-scrollwheels/noweb/x_event.nw
--- geda-gschem-20040111/noweb/x_event.nw	2003-08-25 05:52:41.000000000 +0200
+++ geda-gschem-20040111-scrollwheels/noweb/x_event.nw	2004-05-24 23:08:25.000000000 +0200
@@ -28,6 +28,7 @@
 <<x_event.c : x_event_vschanged()>>
 <<x_event.c : x_event_enter()>>
 <<x_event.c : x_event_key_press()>>
+<<x_event.c : x_event_scroll()>>
 
 @
 
@@ -1422,3 +1423,49 @@
 
 @ %def x_event_key_press
 
+
+@section Function @code{x_event_scroll()}
+
+@defun x_event_scroll widget event w_current
+@end defun
+
+<<x_event.c : x_event_scroll()>>=
+gint
+x_event_scroll (GtkWidget *widget, GdkEventScroll *event, TOPLEVEL *w_current)
+{
+  GtkAdjustment        *adj;
+
+  exit_if_null(w_current);
+  global_window_current = w_current;
+
+  switch (event->direction) {
+  case(GDK_SCROLL_UP):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->v_scrollbar));
+    gtk_adjustment_set_value(adj, adj->value - (adj->page_increment / 4));
+    break;
+
+  case(GDK_SCROLL_DOWN):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->v_scrollbar));
+    gtk_adjustment_set_value(adj, min(adj->value + (adj->page_increment / 4),
+                                      adj->upper - adj->page_size));
+    break;
+
+  case(GDK_SCROLL_LEFT):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->h_scrollbar));
+    gtk_adjustment_set_value(adj, adj->value - (adj->page_increment / 4));
+    break;
+
+  case(GDK_SCROLL_RIGHT):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->h_scrollbar));
+    gtk_adjustment_set_value(adj, min(adj->value + (adj->page_increment / 4),
+                                      adj->upper - adj->page_size));
+    break;
+
+  }
+
+  return(0);
+}
+
+
+@ %def x_event_scroll
+
diff -Nur geda-gschem-20040111/noweb/x_window.nw geda-gschem-20040111-scrollwheels/noweb/x_window.nw
--- geda-gschem-20040111/noweb/x_window.nw	2004-01-02 06:11:26.000000000 +0100
+++ geda-gschem-20040111-scrollwheels/noweb/x_window.nw	2004-05-24 22:49:16.000000000 +0200
@@ -647,6 +647,10 @@
                       "key_press_event",
                       (GtkSignalFunc) x_event_key_press,
                       w_current);
+  gtk_signal_connect (GTK_OBJECT (w_current->main_window),
+                      "scroll_event",
+                      (GtkSignalFunc) x_event_scroll,
+                      w_current);
 }
 
 
diff -Nur geda-gschem-20040111/src/x_event.c geda-gschem-20040111-scrollwheels/src/x_event.c
--- geda-gschem-20040111/src/x_event.c	2004-01-12 03:09:20.000000000 +0100
+++ geda-gschem-20040111-scrollwheels/src/x_event.c	2004-05-24 23:09:17.000000000 +0200
@@ -1,4 +1,4 @@
-#line 36 "../noweb/x_event.nw"
+#line 37 "../noweb/x_event.nw"
 /* gEDA - GPL Electronic Design Automation
  * gschem - gEDA Schematic Capture
  * Copyright (C) 1998-2000 Ales V. Hvezda
@@ -22,7 +22,7 @@
 #line 11 "../noweb/x_event.nw"
 /* DO NOT read or edit this file ! Use ../noweb/x_event.nw instead */
 
-#line 59 "../noweb/x_event.nw"
+#line 60 "../noweb/x_event.nw"
 #include <config.h>
 
 #include <stdio.h>
@@ -36,7 +36,7 @@
 #include "../include/globals.h"
 #include "../include/prototype.h"
 
-#line 76 "../noweb/x_event.nw"
+#line 77 "../noweb/x_event.nw"
 /* used in key_press, since it isn't passed this information */
 /* filled in x_event_motion */
 int mouse_x, mouse_y;
@@ -50,7 +50,7 @@
 #line 16 "../noweb/x_event.nw"
 /* used for the stroke stuff */
 #ifdef HAS_LIBSTROKE
-#line 89 "../noweb/x_event.nw"
+#line 90 "../noweb/x_event.nw"
 #define MAX_SEQUENCE 20
 static int DOING_STROKE = FALSE;
 char sequence[MAX_SEQUENCE + 1];
@@ -62,7 +62,7 @@
 #line 19 "../noweb/x_event.nw"
 #endif
 
-#line 106 "../noweb/x_event.nw"
+#line 107 "../noweb/x_event.nw"
 gint
 x_event_expose(GtkWidget * widget, GdkEventExpose * event,
 	       TOPLEVEL * w_current)
@@ -110,7 +110,7 @@
 }
 
 
-#line 162 "../noweb/x_event.nw"
+#line 163 "../noweb/x_event.nw"
 gint
 x_event_button_pressed(GtkWidget * widget, GdkEventButton * event,
 		       TOPLEVEL * w_current)
@@ -513,7 +513,7 @@
 }
 
 
-#line 624 "../noweb/x_event.nw"
+#line 625 "../noweb/x_event.nw"
 gint
 x_event_button_released(GtkWidget * widget, GdkEventButton * event,
 			TOPLEVEL * w_current)
@@ -709,7 +709,7 @@
 }
 
 
-#line 840 "../noweb/x_event.nw"
+#line 841 "../noweb/x_event.nw"
 gint
 x_event_motion(GtkWidget * widget, GdkEventMotion * event,
 	       TOPLEVEL * w_current)
@@ -946,7 +946,7 @@
 }
 
 
-#line 1110 "../noweb/x_event.nw"
+#line 1111 "../noweb/x_event.nw"
 gint
 x_event_configure(GtkWidget * widget, GdkEventConfigure * event,
 		  TOPLEVEL * w_current)
@@ -1074,7 +1074,7 @@
 }
 
 
-#line 1251 "../noweb/x_event.nw"
+#line 1252 "../noweb/x_event.nw"
 /* this is used during an open command */
 /* to setup the correct sizes */
 void x_manual_resize(TOPLEVEL * w_current)
@@ -1110,7 +1110,7 @@
 }
 
 
-#line 1297 "../noweb/x_event.nw"
+#line 1298 "../noweb/x_event.nw"
 void x_event_hschanged(GtkAdjustment * adj, TOPLEVEL * w_current)
 {
   int current_left;
@@ -1142,7 +1142,7 @@
 }
 
 
-#line 1339 "../noweb/x_event.nw"
+#line 1340 "../noweb/x_event.nw"
 void x_event_vschanged(GtkAdjustment * adj, TOPLEVEL * w_current)
 {
   int current_bottom;
@@ -1179,7 +1179,7 @@
 }
 
 
-#line 1387 "../noweb/x_event.nw"
+#line 1388 "../noweb/x_event.nw"
 gint
 x_event_enter(GtkWidget * widget, GdkEventCrossing * event,
 	      TOPLEVEL * w_current)
@@ -1191,7 +1191,7 @@
 }
 
 
-#line 1407 "../noweb/x_event.nw"
+#line 1408 "../noweb/x_event.nw"
 gint
 x_event_key_press(GtkWidget * widget, GdkEventKey * event,
 		  TOPLEVEL * w_current)
@@ -1207,3 +1207,44 @@
 
   return (0);
 }
+
+
+#line 1433 "../noweb/x_event.nw"
+gint
+x_event_scroll(GtkWidget * widget, GdkEventScroll * event,
+	       TOPLEVEL * w_current)
+{
+  GtkAdjustment *adj;
+
+  exit_if_null(w_current);
+  global_window_current = w_current;
+
+  switch (event->direction) {
+  case (GDK_SCROLL_UP):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->v_scrollbar));
+    gtk_adjustment_set_value(adj, adj->value - (adj->page_increment / 4));
+    break;
+
+  case (GDK_SCROLL_DOWN):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->v_scrollbar));
+    gtk_adjustment_set_value(adj,
+			     min(adj->value + (adj->page_increment / 4),
+				 adj->upper - adj->page_size));
+    break;
+
+  case (GDK_SCROLL_LEFT):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->h_scrollbar));
+    gtk_adjustment_set_value(adj, adj->value - (adj->page_increment / 4));
+    break;
+
+  case (GDK_SCROLL_RIGHT):
+    adj = gtk_range_get_adjustment(GTK_RANGE(w_current->h_scrollbar));
+    gtk_adjustment_set_value(adj,
+			     min(adj->value + (adj->page_increment / 4),
+				 adj->upper - adj->page_size));
+    break;
+
+  }
+
+  return (0);
+}
diff -Nur geda-gschem-20040111/src/x_window.c geda-gschem-20040111-scrollwheels/src/x_window.c
--- geda-gschem-20040111/src/x_window.c	2004-01-12 03:09:27.000000000 +0100
+++ geda-gschem-20040111-scrollwheels/src/x_window.c	2004-05-24 22:51:15.000000000 +0200
@@ -492,11 +492,14 @@
   gtk_signal_connect(GTK_OBJECT(w_current->main_window),
 		     "key_press_event",
 		     (GtkSignalFunc) x_event_key_press, w_current);
+  gtk_signal_connect(GTK_OBJECT(w_current->main_window),
+		     "scroll_event",
+		     (GtkSignalFunc) x_event_scroll, w_current);
 }
 
 
 
-#line 663 "../noweb/x_window.nw"
+#line 667 "../noweb/x_window.nw"
 static GtkWidget *x_window_new_pixmap(char *filename, GdkWindow * window,
 				      GdkColor * background)
 {
@@ -514,7 +517,7 @@
   return wpixmap;
 }
 
-#line 691 "../noweb/x_window.nw"
+#line 695 "../noweb/x_window.nw"
 void x_window_create_main(TOPLEVEL * w_current)
 {
   GtkWidget *label = NULL;
@@ -1029,7 +1032,7 @@
 }
 
 
-#line 1176 "../noweb/x_window.nw"
+#line 1180 "../noweb/x_window.nw"
 TOPLEVEL *x_window_create_new(void)
 {
   TOPLEVEL *w_current = NULL;
@@ -1113,7 +1116,7 @@
 }
 
 
-#line 1270 "../noweb/x_window.nw"
+#line 1274 "../noweb/x_window.nw"
 void x_window_close(TOPLEVEL * w_current)
 {
 
@@ -1274,7 +1277,7 @@
 }
 
 
-#line 1441 "../noweb/x_window.nw"
+#line 1445 "../noweb/x_window.nw"
 void x_window_close_all()
 {
   TOPLEVEL *w_current;
@@ -1300,7 +1303,7 @@
 }
 
 
-#line 1476 "../noweb/x_window.nw"
+#line 1480 "../noweb/x_window.nw"
 TOPLEVEL *x_window_get_ptr(int wid)
 {
   TOPLEVEL *w_current;
@@ -1319,7 +1322,7 @@
 }
 
 
-#line 1504 "../noweb/x_window.nw"
+#line 1508 "../noweb/x_window.nw"
 /* GROSS! but this is required because clist widgets don't seem to allow you
  * pass data to callback functions, so I need to get w_current by searching
  * the entire window list for page_clist widget :(  If somebody knows a better

Attachment: pgp00006.pgp
Description: PGP signature