mouse.cpp

Go to the documentation of this file.
00001 #ifndef MOUSE_IMPLEMENTATION_FILE
00002 #define MOUSE_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : mouse                                                             *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "mouse.h"
00019 
00020 #include <wp_passive/canvas.h>
00021 #include <wp_passive/wp_implementation.h>
00022 
00023 mouse::mouse(nub &connect_to) : _connection(connect_to)
00024 {
00025   XtAddEventHandler
00026     (connect_to.self(), ButtonPressMask, false,
00027      XtEventHandler(mouse_callback), XtPointer(this));
00028   XtAddEventHandler
00029     (connect_to.self(), ButtonReleaseMask, false,
00030      XtEventHandler(mouse_callback), XtPointer(this));
00031 }
00032 
00033 mouse::~mouse()
00034 {
00035   XtRemoveEventHandler
00036     (_connection.self(), ButtonPressMask, false,
00037      XtEventHandler(mouse_callback), XtPointer(this));
00038   XtRemoveEventHandler
00039     (_connection.self(), ButtonReleaseMask, false,
00040      XtEventHandler(mouse_callback), XtPointer(this));
00041 }
00042 
00043 /*
00044 void mouse::position(c_point new_position)
00045 {
00046 x warp pointer...
00047 }
00048 */
00049 
00050 c_point mouse::position() const
00051 {
00052   int root_x = 0, root_y = 0, win_x = 0, win_y = 0;
00053   Window root_win = NIL, child_win = NIL;
00054   unsigned int mask_returned = 0;
00055 
00056   // if the querypointer routine returns false, some of the results are
00057   // invalidated below.
00058   XQueryPointer(_connection.display(), _connection.window(),
00059     &root_win, &child_win, &root_x, &root_y, &win_x, &win_y, &mask_returned);
00060   c_point device_coords(root_x, root_y);
00061   device_coords -= c_point(_connection.device_dimensions().vertex_1());
00062   return convert(device_coords);
00063 }
00064 
00065 c_point mouse::convert(const c_point &to_convert) const
00066 {
00067 return to_convert;
00068 /*
00069 printf((istring("convert:\nto_convert=") + to_convert.text_form() + "\n").s());
00070   c_point to_return(to_convert);
00071   if (_direction == first_to_second)
00072     return _realm.to_system_2(to_return);
00073   else
00074     return _realm.to_system_1(to_return);
00075 */
00076 }
00077 
00078 void mouse::mouse_callback(window_handle, mouse *me, XEvent *parms)
00079 {
00080   FUNCDEF("mouse_callback");
00081   int mask = 0;
00082   switch (parms->xbutton.button) {
00083   case Button1: mask = Button1Mask; break;
00084   case Button2: mask = Button2Mask; break;
00085   case Button3: mask = Button3Mask; break;
00086   case Button4: mask = Button4Mask; break;
00087   case Button5: mask = Button5Mask; break;
00088   default:
00089     LOG("unknown button pressed");
00090     break;
00091   }
00092 //LOG(isprintf("state=%d, mask=%d", parms->xbutton.state, mask));
00093   mouse::button_positions state
00094     = (parms->xbutton.state & mask? mouse::down : mouse::up);
00095 //LOG(isprintf(" value masked is --> %d", parms->xbutton.state & mask));
00096   c_point device_point(parms->xbutton.x, parms->xbutton.y);
00097   c_point converted(me->convert(device_point));
00098   LOG(isprintf("button state to return in mouse is: %s",
00099       (state==mouse::down? "DOWN" : "UP")));
00100   me->button_event(converted, parms->xbutton.button, state);
00101 }
00102 
00103 
00104 #endif //MOUSE_IMPLEMENTATION_FILE
00105 

Generated on Fri Nov 28 04:29:04 2008 for HOOPLE Libraries by  doxygen 1.5.1