Geant4  10.02.p01
wheelmouse.cc
Go to the documentation of this file.
1 /* file scrollmouse.c
2  *
3  * Event handler for wheel mouse
4  *
5  * functions: void xmAddMouseEventHandler(Widget w)
6  *
7  */
8 /*
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  */
24 
25 #include <X11/Intrinsic.h>
26 #include <X11/Xlib.h>
27 #include <Xm/Xm.h>
28 #include <Xm/ScrollBar.h>
29 
30 #if defined(__cplusplus) || defined(c_plusplus)
31 extern "C" {
32 #endif
33 
34 /*******************************************************************/
35 /* */
36 /* NAME: mouseScroll */
37 /* */
38 /* FUNCTION: do scrolling on button 4 and 5 */
39 /* scrolling width depend on shift and control keys */
40 /* without pressed key the scrollwidth 1/2 page */
41 /* with the control key 1 page */
42 /* with the shift key 1 line */
43 /* Control + Shift is handled as Shift */
44 /* */
45 /* INPUT: Widget w not relevant */
46 /* XtPointer client_data really the scrollbar widget */
47 /* Xevent the mosuse button event */
48 /* */
49 /* OUTPUT: - */
50 /* */
51 /* RETURN: - */
52 /* */
53 /* REMARKS: Scrolling don't modify the selection */
54 /* */
55 /*******************************************************************/
56 
57 static void mouseScroll(Widget, XtPointer client_data, XEvent *event)
58 {
59  Widget sb = (Widget)client_data;
60  int value_return = 0;
61  int slider_size_return = 0;
62  int increment_return = 0;
63  int page_increment_return = 0;
64  int count;
65  int step;
66 
67  /* get a few value regarding the scrollbar conf. */
68  XmScrollBarGetValues (sb, &value_return, &slider_size_return,
69  &increment_return, &page_increment_return);
70 
71  /* calculate the step wide according to the pressed keys */
72  if ( event->xbutton.state & ShiftMask )
73  {
74  step = 1;
75  }
76  else if ( event->xbutton.state & ControlMask )
77  {
78  step = page_increment_return;
79  }
80  else
81  {
82  step = page_increment_return >> 1;
83  }
84 
85  if ( event->xbutton.button == Button4 )
86  {
87  value_return -= step;
88  if ( value_return < 0 )
89  value_return = 0;
90  }
91  else if ( event->xbutton.button == Button5 )
92  {
93  /* and the max value for increment */
94  XtVaGetValues(sb, XmNmaximum, &count, NULL);
95  value_return += step;
96  if ( value_return > count - slider_size_return )
97  value_return = count - slider_size_return;
98  }
99 
100  /* finally perform scrolling with the calculated step */
101  if ( event->xbutton.button == Button4 ||
102  event->xbutton.button == Button5 )
103  {
104  XmScrollBarSetValues (sb, value_return, slider_size_return,
105  increment_return, page_increment_return, True);
106  }
107 }
108 
109 /*******************************************************************/
110 /* */
111 /* NAME: xmAddMouseEventHandler */
112 /* */
113 /* FUNCTION: Register the event handler for the button 4 and 5 */
114 /* */
115 /* INPUT: Widget w The list/text widget */
116 /* */
117 /* OUTPUT: - */
118 /* */
119 /* RETURN: - */
120 /* */
121 /* REMARKS: - */
122 /* */
123 /*******************************************************************/
124 
126 {
127  Widget wid;
128 
129  /* we need to pass the scrollbar widget to the handler */
130  XtVaGetValues(XtParent(w),XmNverticalScrollBar, &wid, NULL);
131 
132  /* handler for the scrolledList/ScrolledText */
133  XtAddEventHandler(w, ButtonReleaseMask, False,
134  (XtEventHandler) mouseScroll, wid);
135  /* and for the scrollbar itself */
136  XtAddEventHandler(wid, ButtonReleaseMask, False,
137  (XtEventHandler) mouseScroll, wid);
138 }
139 
140 #if defined(__cplusplus) || defined(c_plusplus)
141 }
142 #endif
const G4double w[NPOINTSGL]
static void mouseScroll(Widget, XtPointer client_data, XEvent *event)
Definition: wheelmouse.cc:57
void xmAddMouseEventHandler(Widget w)
Definition: wheelmouse.cc:125