File: mousecb.c

package info (click to toggle)
viewmol 2.4.1-13
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,212 kB
  • ctags: 2,054
  • sloc: ansic: 30,727; python: 1,849; sh: 921; awk: 433; makefile: 205
file content (306 lines) | stat: -rw-r--r-- 12,312 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*******************************************************************************
*                                                                              *
*                                   Viewmol                                    *
*                                                                              *
*                              M O U S E C B . C                               *
*                                                                              *
*                 Copyright (c) Joerg-R. Hill, October 2003                    *
*                                                                              *
********************************************************************************
*
* $Id: mousecb.c,v 1.6 2003/11/07 11:07:55 jrh Exp $
* $Log: mousecb.c,v $
* Revision 1.6  2003/11/07 11:07:55  jrh
* Release 2.4
*
* Revision 1.5  2000/12/10 15:13:11  jrh
* Release 2.3
*
* Revision 1.4  1999/05/24 01:26:47  jrh
* Release 2.2.1
*
* Revision 1.3  1999/02/07 21:53:43  jrh
* Release 2.2
*
* Revision 1.2  1998/01/26 00:48:52  jrh
* Release 2.1
*
* Revision 1.1  1996/12/10  18:42:34  jrh
* Initial revision
*
*/
#include<X11/Intrinsic.h>
#include<X11/extensions/XInput.h>
#include<Xm/Xm.h>
#include<Xm/PushBG.h>
#include<Xm/RowColumn.h>
#include<GL/glu.h>
#include "viewmol.h"

void processInput(Widget, caddr_t, XmDrawingAreaCallbackStruct *);
void processSpaceballEvent(XEvent *);
void doMenu(Widget, Widget, XmDrawingAreaCallbackStruct *);

extern void setMenuItem(int, int);
extern Widget makeMenu(Widget, int, char *, struct MenuItem *);
extern void redraw(int);
extern void drawSpectrum(Widget, caddr_t, XmDrawingAreaCallbackStruct *);
extern void drawHistory(Widget, caddr_t, XmDrawingAreaCallbackStruct *);
extern void drawMODiagram(Widget, caddr_t, XmDrawingAreaCallbackStruct *);
extern void viewerMouseAction(XEvent *, int);
extern void spectrumMouseAction(XmDrawingAreaCallbackStruct *, int);
extern void historyMouseAction(unsigned int, int, int, int);
extern void MODiagramMouseAction(XmDrawingAreaCallbackStruct *, int);
extern void viewerKeyAction(KeySym);
extern void spectrumKeyAction(KeySym);
extern void historyKeyAction(KeySym);
extern void MODiagramKeyAction(KeySym);
extern void getTranslation(int, int, int);
extern void getRotation(int, int, int, int);
extern void getEnlargement(int, int);
extern void zoomIn(Widget, XmDrawingAreaCallbackStruct *);
extern void redraw(int);
extern void switchPointerDevice(void);

extern struct WINDOW windows[];
extern float *transObject, *rotObject;
extern int lines, label, showForces;
extern int rotateXY, rotateZ;
extern int showMenu, primitive, selectAtom, iwavef;
extern int picking, swapBuffers, moveItem, simplify;
extern int spaceballButtonPress, spaceballMotionNotify;
extern int sensitivity, pythonInterrupt;
extern Widget bfMenu;

void processInput(Widget w, caddr_t client_data,
                  XmDrawingAreaCallbackStruct *data)
{
  KeySym keysym;
  XComposeStatus status;
  static int primitiveSave;
  char buffer[2];

  if (data->reason == XmCR_INPUT)
  {
    switch (data->event->type)
    {
      case ButtonPress:   if (w == windows[VIEWER].widget)
                          {
                            if (data->event->xbutton.button != Button3 &&
                                simplify && (moveItem & 0x7fffffff) > WORLD)
                            {
                              primitiveSave=primitive;
                              primitive=GLU_LINE;
                            }
                            if (data->event->xbutton.button == Button3)
                            {
                              if (showMenu)
                                doMenu(w, windows[VIEWER].menu, data);
                              else
                                viewerMouseAction(data->event, TRUE);
                            }
                            else
                            {
                              getRotation(data->event->xmotion.x,
                                          data->event->xmotion.y,
                                          data->event->xmotion.x, 2);
                              viewerMouseAction(data->event, TRUE);
                            }
                          }
                          else if (w == windows[SPECTRUM].widget)
                          {
                            if (data->event->xbutton.button == Button3)
                              doMenu(w, windows[SPECTRUM].menu, data);
                            else
                              spectrumMouseAction(data, TRUE);
                          }
                          else if (w == windows[HISTORY].widget)
                          {
                            if (data->event->xbutton.button == Button3)
                              doMenu(w, windows[HISTORY].menu, data);
                            else
                              historyMouseAction(data->event->xbutton.button,
                                                 TRUE, data->event->xbutton.x,
                                                 data->event->xbutton.y);
                          }
                          else if (w == windows[MO].widget)
                          {
                            if (data->event->xbutton.button == Button3)
                              doMenu(w, windows[MO].menu, data);
                            else
                              MODiagramMouseAction(data, TRUE);
                          }
                          break;
      case ButtonRelease: if (w == windows[VIEWER].widget)
                          {
                            if (data->event->xbutton.button != Button3 &&
                                simplify && moveItem > WORLD)
                              primitive=primitiveSave;
                            viewerMouseAction(data->event, FALSE);
                            rotateXY=rotateZ=0;
/*                          return; */
                          }
                          else if (w == windows[SPECTRUM].widget)
                            spectrumMouseAction(data, FALSE);
                          else if (w == windows[HISTORY].widget)
                            historyMouseAction(data->event->xbutton.button,
                                               FALSE, data->event->xbutton.x,
                                               data->event->xbutton.y);
                          else if (w == windows[MO].widget)
                            MODiagramMouseAction(data, FALSE);
                          break;
      case KeyPress:      buffer[0]=buffer[1]='\0';
                          XLookupString((XKeyEvent *)data->event, buffer, 2,
                                        &keysym, &status); 
                          if ((int)(buffer[0]) == 3)
                            pythonInterrupt=TRUE;
                          if (w == windows[VIEWER].widget)
                            viewerKeyAction(keysym);
                          if (w == windows[SPECTRUM].widget)
                            spectrumKeyAction(keysym);
                          else if (w == windows[HISTORY].widget)
                            historyKeyAction(keysym);
                          else if (w == windows[MO].widget)
                            MODiagramKeyAction(keysym);
                          break;
      case MotionNotify:  if (data->event->xmotion.state & Button1Mask)
                          {
                            if (w == windows[VIEWER].widget)
                            {
                              if (data->event->xmotion.state & ShiftMask)
                                getTranslation(data->event->xmotion.x,
                                               data->event->xmotion.y, 2);
                              else
                                getRotation(data->event->xmotion.x,
                                            data->event->xmotion.y, -1, 0);
                            }
                            else if (w == windows[HISTORY].widget)
                            {
                              historyMouseAction(Button1, TRUE,
                                                 data->event->xmotion.x,
                                                 data->event->xmotion.y);
                            }
                          }
                          else if (data->event->xmotion.state & Button2Mask)
                          {
                            if (w == windows[VIEWER].widget)
                              if (data->event->xmotion.state & ShiftMask)
                                getEnlargement(data->event->xmotion.x, 2);
                              else
                                getRotation(-1, -1, data->event->xmotion.x, 0);
                            else
                            {
                              zoomIn(w, data);
                              return;
                            }
                          }
                          else
                            return;
                          break;
      default:            break;
    }
    if (w == windows[VIEWER].widget)
    {
      windows[VIEWER].mouseX=data->event->xmotion.x;
      windows[VIEWER].mouseY=data->event->xmotion.y;
    }
    redraw(VIEWER);
    if (w == windows[SPECTRUM].widget)
    {
      windows[SPECTRUM].mouseX=data->event->xmotion.x;
      windows[SPECTRUM].mouseY=data->event->xmotion.y;
      drawSpectrum(w, client_data, data);
    }
    else if (w == windows[HISTORY].widget)
    {
/*    windows[HISTORY].mouseX=data->event->xmotion.x;
      windows[HISTORY].mouseY=data->event->xmotion.y; */
      drawHistory(w, client_data, data);
    }
    else if (w == windows[MO].widget)
    {
      windows[MO].mouseX=data->event->xmotion.x;
      windows[MO].mouseY=data->event->xmotion.y;
      drawMODiagram(w, client_data, data);
    }
  }
}

void processSpaceballEvent(XEvent *event)
{
  XDeviceMotionEvent *motionEvent;
  XDeviceButtonEvent *buttonEvent;
  static int sensitivity=4, i;

  if (event->type == spaceballMotionNotify)
  {
    motionEvent=(XDeviceMotionEvent *)event;
    getRotation(motionEvent->axis_data[3]/sensitivity,
                motionEvent->axis_data[4]/sensitivity,
                motionEvent->axis_data[5]/sensitivity, 1);
    rotateXY=rotateZ=1;
    getTranslation(motionEvent->axis_data[0]/(10*sensitivity),
                   -motionEvent->axis_data[2]/(10*sensitivity), 1);
    getEnlargement(-motionEvent->axis_data[1]/(10*sensitivity), 1);
    rotateXY=rotateZ=0;
  }
  else if (event->type == spaceballButtonPress)
  {
    buttonEvent=(XDeviceButtonEvent *)event;
    if (buttonEvent->button == Button1)
    {
      i=3*(windows[VIEWER].set+3);
      transObject[i]=transObject[i+1]=transObject[i+2]=0.0;
      redraw(VIEWER);
    }
    if (buttonEvent->button == Button2)
    {
      i=4*(windows[VIEWER].set+3);
      rotObject[i]=rotObject[i+1]=rotObject[i+2]=0.0;
      rotObject[i+3]=1.0;
      redraw(VIEWER);
    }
/*  if (buttonEvent->button == Button3)
    {
      switchPointerDevice();
      XmMenuPosition(windows[VIEWER].menu, (XButtonPressedEvent *)(event));
      XtManageChild(windows[VIEWER].menu);
      switchPointerDevice();
    } */
    if (buttonEvent->button == Button4) sensitivity+=2;
    if (buttonEvent->button == Button5) sensitivity-=2;
  }
}

void doMenu(Widget widget, Widget menu, XmDrawingAreaCallbackStruct *data)
{
  XmMenuPosition(menu, (XButtonPressedEvent *)(data->event));
  XtManageChild(menu);
}

void changeBoolean(Widget w, int *bool, XmDrawingAreaCallbackStruct *data)
{
  *bool=!(*bool);
  redraw(VIEWER);
}

void setModel(Widget w, caddr_t model, XmDrawingAreaCallbackStruct *data)
{
  setMenuItem((VIEWER_WIRE)+windows[VIEWER].mode-WIREMODEL, True);
  windows[VIEWER].mode=(int)model;
  setMenuItem((VIEWER_WIRE)+(int)model-WIREMODEL, False);
  if ((int)model != WIREMODEL)
    setMenuItem(VIEWER_RAYTRACING, True);
  else
    setMenuItem(VIEWER_RAYTRACING, False);
  redraw(VIEWER);
}

void setDiagram(Widget w, caddr_t diagram, XmDrawingAreaCallbackStruct *data)
{
  if (windows[MO].mode == DENSITY_OF_STATES)
    windows[MO].mode=ENERGY_LEVELS;
  else
    windows[MO].mode=DENSITY_OF_STATES;
  drawMODiagram((Widget)0, (caddr_t)0, (XmDrawingAreaCallbackStruct *)0);
}