Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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#ifdef G4VIS_BUILD_OIX_DRIVER
26
27#include <X11/Intrinsic.h>
28#include <X11/Xlib.h>
29#include <Xm/Xm.h>
30#include <Xm/ScrollBar.h>
31
32#if defined(__cplusplus) || defined(c_plusplus)
33extern "C" {
34#endif
35
36/*******************************************************************/
37/* */
38/* NAME: mouseScroll */
39/* */
40/* FUNCTION: do scrolling on button 4 and 5 */
41/* scrolling width depend on shift and control keys */
42/* without pressed key the scrollwidth 1/2 page */
43/* with the control key 1 page */
44/* with the shift key 1 line */
45/* Control + Shift is handled as Shift */
46/* */
47/* INPUT: Widget w not relevant */
48/* XtPointer client_data really the scrollbar widget */
49/* Xevent the mosuse button event */
50/* */
51/* OUTPUT: - */
52/* */
53/* RETURN: - */
54/* */
55/* REMARKS: Scrolling don't modify the selection */
56/* */
57/*******************************************************************/
58
59static void mouseScroll(Widget, XtPointer client_data, XEvent* event, Boolean*)
60//static void mouseScroll(Widget, XtPointer client_data, XEvent *event)
61{
62 Widget sb = (Widget)client_data;
63 int value_return = 0;
64 int slider_size_return = 0;
65 int increment_return = 0;
66 int page_increment_return = 0;
67 int count;
68 int step;
69
70 /* get a few value regarding the scrollbar conf. */
71 XmScrollBarGetValues (sb, &value_return, &slider_size_return,
72 &increment_return, &page_increment_return);
73
74 /* calculate the step wide according to the pressed keys */
75 if ( event->xbutton.state & ShiftMask )
76 {
77 step = 1;
78 }
79 else if ( event->xbutton.state & ControlMask )
80 {
81 step = page_increment_return;
82 }
83 else
84 {
85 step = page_increment_return >> 1;
86 }
87
88 if ( event->xbutton.button == Button4 )
89 {
90 value_return -= step;
91 if ( value_return < 0 )
92 value_return = 0;
93 }
94 else if ( event->xbutton.button == Button5 )
95 {
96 /* and the max value for increment */
97 XtVaGetValues(sb, XmNmaximum, &count, NULL);
98 value_return += step;
99 if ( value_return > count - slider_size_return )
100 value_return = count - slider_size_return;
101 }
102
103 /* finally perform scrolling with the calculated step */
104 if ( event->xbutton.button == Button4 ||
105 event->xbutton.button == Button5 )
106 {
107 XmScrollBarSetValues (sb, value_return, slider_size_return,
108 increment_return, page_increment_return, True);
109 }
110}
111
112/*******************************************************************/
113/* */
114/* NAME: xmAddMouseEventHandler */
115/* */
116/* FUNCTION: Register the event handler for the button 4 and 5 */
117/* */
118/* INPUT: Widget w The list/text widget */
119/* */
120/* OUTPUT: - */
121/* */
122/* RETURN: - */
123/* */
124/* REMARKS: - */
125/* */
126/*******************************************************************/
127
128void xmAddMouseEventHandler(Widget w)
129{
130 Widget wid;
131
132 /* we need to pass the scrollbar widget to the handler */
133 XtVaGetValues(XtParent(w),XmNverticalScrollBar, &wid, NULL);
134
135 /* handler for the scrolledList/ScrolledText */
136 XtAddEventHandler(w, ButtonReleaseMask, False,
137 (XtEventHandler) mouseScroll, wid);
138 /* and for the scrollbar itself */
139 XtAddEventHandler(wid, ButtonReleaseMask, False,
140 (XtEventHandler) mouseScroll, wid);
141}
142
143#if defined(__cplusplus) || defined(c_plusplus)
144}
145#endif
146
147#endif // G4VIS_BUILD_OIX_DRIVER
void xmAddMouseEventHandler(Widget w)