Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
wheelmouse.cc
이 파일의 문서화 페이지로 가기
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, Boolean*)
58 //static void mouseScroll(Widget, XtPointer client_data, XEvent *event)
59 {
60  Widget sb = (Widget)client_data;
61  int value_return = 0;
62  int slider_size_return = 0;
63  int increment_return = 0;
64  int page_increment_return = 0;
65  int count;
66  int step;
67 
68  /* get a few value regarding the scrollbar conf. */
69  XmScrollBarGetValues (sb, &value_return, &slider_size_return,
70  &increment_return, &page_increment_return);
71 
72  /* calculate the step wide according to the pressed keys */
73  if ( event->xbutton.state & ShiftMask )
74  {
75  step = 1;
76  }
77  else if ( event->xbutton.state & ControlMask )
78  {
79  step = page_increment_return;
80  }
81  else
82  {
83  step = page_increment_return >> 1;
84  }
85 
86  if ( event->xbutton.button == Button4 )
87  {
88  value_return -= step;
89  if ( value_return < 0 )
90  value_return = 0;
91  }
92  else if ( event->xbutton.button == Button5 )
93  {
94  /* and the max value for increment */
95  XtVaGetValues(sb, XmNmaximum, &count, NULL);
96  value_return += step;
97  if ( value_return > count - slider_size_return )
98  value_return = count - slider_size_return;
99  }
100 
101  /* finally perform scrolling with the calculated step */
102  if ( event->xbutton.button == Button4 ||
103  event->xbutton.button == Button5 )
104  {
105  XmScrollBarSetValues (sb, value_return, slider_size_return,
106  increment_return, page_increment_return, True);
107  }
108 }
109 
110 /*******************************************************************/
111 /* */
112 /* NAME: xmAddMouseEventHandler */
113 /* */
114 /* FUNCTION: Register the event handler for the button 4 and 5 */
115 /* */
116 /* INPUT: Widget w The list/text widget */
117 /* */
118 /* OUTPUT: - */
119 /* */
120 /* RETURN: - */
121 /* */
122 /* REMARKS: - */
123 /* */
124 /*******************************************************************/
125 
127 {
128  Widget wid;
129 
130  /* we need to pass the scrollbar widget to the handler */
131  XtVaGetValues(XtParent(w),XmNverticalScrollBar, &wid, NULL);
132 
133  /* handler for the scrolledList/ScrolledText */
134  XtAddEventHandler(w, ButtonReleaseMask, False,
135  (XtEventHandler) mouseScroll, wid);
136  /* and for the scrollbar itself */
137  XtAddEventHandler(wid, ButtonReleaseMask, False,
138  (XtEventHandler) mouseScroll, wid);
139 }
140 
141 #if defined(__cplusplus) || defined(c_plusplus)
142 }
143 #endif
void xmAddMouseEventHandler(Widget w)
Definition: wheelmouse.cc:126
static void mouseScroll(Widget, XtPointer client_data, XEvent *event, Boolean *)
Definition: wheelmouse.cc:57