wheelmouse.cc

Go to the documentation of this file.
00001 /* file scrollmouse.c
00002  *
00003  * Event handler for wheel mouse
00004  *
00005  * functions: void xmAddMouseEventHandler(Widget w)
00006  *
00007  */
00008 /*
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024 
00025 #include <X11/Intrinsic.h>
00026 #include <X11/Xlib.h>
00027 #include <Xm/Xm.h>
00028 #include <Xm/ScrollBar.h>
00029 
00030 #if defined(__cplusplus) || defined(c_plusplus)
00031 extern "C" {
00032 #endif
00033 
00034 /*******************************************************************/ 
00035 /*                                                                 */ 
00036 /* NAME:      mouseScroll                                          */ 
00037 /*                                                                 */ 
00038 /* FUNCTION:  do scrolling on button 4 and 5                       */
00039 /*            scrolling width depend on shift and control keys     */
00040 /*            without pressed key the scrollwidth 1/2 page         */
00041 /*            with the control key                1   page         */
00042 /*            with the shift key                  1   line         */
00043 /*            Control + Shift is handled as Shift                  */
00044 /*                                                                 */
00045 /* INPUT:     Widget w              not relevant                   */
00046 /*            XtPointer client_data really the scrollbar widget    */
00047 /*            Xevent                the mosuse button event        */
00048 /*                                                                 */
00049 /* OUTPUT:    -                                                    */ 
00050 /*                                                                 */ 
00051 /* RETURN:    -                                                    */ 
00052 /*                                                                 */ 
00053 /* REMARKS:   Scrolling don't modify the selection                 */ 
00054 /*                                                                 */ 
00055 /*******************************************************************/ 
00056 
00057 static void mouseScroll(Widget, XtPointer client_data, XEvent *event)
00058 {
00059    Widget sb = (Widget)client_data;
00060    int value_return                       = 0;
00061    int slider_size_return         = 0;
00062    int increment_return           = 0;
00063    int page_increment_return = 0;
00064         int count;
00065    int step;
00066 
00067    /* get a few value regarding the scrollbar conf. */
00068    XmScrollBarGetValues (sb, &value_return, &slider_size_return,
00069                         &increment_return, &page_increment_return);
00070 
00071    /* calculate the step wide according to the pressed keys */
00072    if ( event->xbutton.state & ShiftMask )
00073         {
00074            step = 1;
00075         }
00076         else if ( event->xbutton.state & ControlMask )
00077         {
00078            step = page_increment_return;
00079         }
00080         else
00081         {
00082            step = page_increment_return >> 1;
00083         }
00084    
00085    if ( event->xbutton.button == Button4 )
00086         {
00087                 value_return -= step;
00088            if ( value_return < 0 )
00089                    value_return = 0;
00090         }
00091         else if ( event->xbutton.button == Button5 )
00092         {
00093       /* and the max value for increment */
00094       XtVaGetValues(sb, XmNmaximum, &count, NULL);
00095                 value_return += step;
00096                 if ( value_return > count - slider_size_return )
00097                    value_return = count - slider_size_return;
00098         }
00099 
00100    /* finally perform scrolling with the calculated step */
00101    if ( event->xbutton.button == Button4 ||
00102              event->xbutton.button == Button5    )
00103         {
00104       XmScrollBarSetValues (sb, value_return, slider_size_return,
00105                         increment_return, page_increment_return, True);
00106    }
00107 }
00108 
00109 /*******************************************************************/ 
00110 /*                                                                 */ 
00111 /* NAME:      xmAddMouseEventHandler                               */ 
00112 /*                                                                 */ 
00113 /* FUNCTION:  Register the event handler for the button 4 and 5    */
00114 /*                                                                 */
00115 /* INPUT:     Widget w  The list/text widget                       */
00116 /*                                                                 */
00117 /* OUTPUT:    -                                                    */ 
00118 /*                                                                 */ 
00119 /* RETURN:    -                                                    */ 
00120 /*                                                                 */ 
00121 /* REMARKS:   -                                                    */ 
00122 /*                                                                 */ 
00123 /*******************************************************************/ 
00124 
00125 void xmAddMouseEventHandler(Widget w)
00126 {
00127    Widget wid;
00128 
00129    /* we need to pass the scrollbar widget to the handler */    
00130    XtVaGetValues(XtParent(w),XmNverticalScrollBar, &wid, NULL);
00131 
00132    /* handler for the scrolledList/ScrolledText */
00133    XtAddEventHandler(w, ButtonReleaseMask, False,
00134                      (XtEventHandler) mouseScroll, wid);
00135         /* and for the scrollbar itself */    
00136         XtAddEventHandler(wid, ButtonReleaseMask, False,
00137                                                   (XtEventHandler) mouseScroll, wid);
00138 } 
00139 
00140 #if defined(__cplusplus) || defined(c_plusplus)
00141 }
00142 #endif

Generated on Mon May 27 17:50:36 2013 for Geant4 by  doxygen 1.4.7