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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 
126 void xmAddMouseEventHandler(Widget w)
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
144