1 /************************************************************************/
2 /* */
3 /* Drawing primitives for X11/Motif. */
4 /* */
5 /************************************************************************/
6
7 # include "appFrameConfig.h"
8 # include "appGuiBase.h"
9
10 # include <stddef.h>
11 # include <stdio.h>
12
13 # include <geo2DInteger.h>
14 # include "guiDrawingWidget.h"
15
16 # include <appDebugon.h>
17
18 # ifdef USE_MOTIF
19
guiDrawGetSizeFromConfigureEvent(int * pWide,int * pHigh,Widget w,XEvent * event)20 int guiDrawGetSizeFromConfigureEvent( int * pWide,
21 int * pHigh,
22 Widget w,
23 XEvent * event )
24 {
25 XConfigureEvent * cevent= &(event->xconfigure);
26
27 if ( cevent->type != ConfigureNotify )
28 { return 1; }
29
30 *pWide= cevent->width; *pHigh= cevent->height; return 0;
31 }
32
guiGetCoordinatesFromMouseButtonEvent(int * pX,int * pY,int * pButton,int * pUpDown,int * pSeq,unsigned int * pKeyState,const APP_WIDGET w,const XEvent * event)33 int guiGetCoordinatesFromMouseButtonEvent(
34 int * pX,
35 int * pY,
36 int * pButton,
37 int * pUpDown,
38 int * pSeq,
39 unsigned int * pKeyState,
40 const APP_WIDGET w,
41 const XEvent * event )
42 {
43 const XButtonEvent * bevent= &(event->xbutton);
44
45 static Widget prevWidget;
46 static Time prevTime;
47 static Time lastTime;
48 static long multiClickInterval;
49
50 int seq= 1;
51
52 if ( multiClickInterval == 0 )
53 {
54 multiClickInterval= XtGetMultiClickTime( XtDisplay( w ) );
55 if ( multiClickInterval == 0 )
56 { multiClickInterval= 200; }
57 }
58
59 switch( event->type )
60 {
61 case ButtonPress:
62 *pUpDown= +1;
63
64 if ( w == prevWidget )
65 {
66 if ( bevent->time != lastTime &&
67 bevent->time- lastTime < multiClickInterval )
68 {
69 seq++;
70 if ( bevent->time- prevTime < 2* multiClickInterval )
71 { seq++; }
72 }
73
74 if ( bevent->time != lastTime )
75 { prevTime= lastTime; lastTime= bevent->time; }
76 }
77 else{
78 prevWidget= w;
79 lastTime= bevent->time;
80 prevTime= lastTime- 4* multiClickInterval;
81 *pSeq= 1;
82 }
83
84 *pKeyState= bevent->state;
85 break;
86
87 case ButtonRelease:
88 *pUpDown= -1;
89 *pSeq= 1;
90 *pKeyState= bevent->state;
91 break;
92
93 default:
94 LDEB(event->type); return 1;
95 }
96
97 *pSeq= seq;
98
99 switch( bevent->button )
100 {
101 case Button1: *pButton= 1; break;
102 case Button2: *pButton= 2; break;
103 case Button3: *pButton= 3; break;
104 case Button4: *pButton= 4; break;
105 case Button5: *pButton= 5; break;
106
107 default:
108 LDEB(bevent->button); return 1;
109 }
110
111 *pX= bevent->x; *pY= bevent->y; return 0;
112 }
113
guiGetCoordinatesRelativeToWidget(int * pX,int * pY,const APP_WIDGET w)114 int guiGetCoordinatesRelativeToWidget( int * pX,
115 int * pY,
116 const APP_WIDGET w )
117 {
118 Window root;
119 Window child;
120 int rootX;
121 int rootY;
122 int winX;
123 int winY;
124 unsigned int mask;
125
126 XQueryPointer( XtDisplay( w ), XtWindow( w ), &root, &child,
127 &rootX, &rootY, &winX, &winY, &mask );
128 *pX= winX; *pY= winY;
129 return 0;
130 }
131
guiGetCoordinatesFromMouseMoveEvent(int * pX,int * pY,Widget w,XEvent * event)132 int guiGetCoordinatesFromMouseMoveEvent( int * pX,
133 int * pY,
134 Widget w,
135 XEvent * event )
136 {
137 XMotionEvent * mevent= &(event->xmotion);
138
139 if ( event->type != MotionNotify )
140 { return 1; }
141
142 *pX= mevent->x; *pY= mevent->y; return 0;
143 }
144
guiDrawSetRedrawHandler(APP_WIDGET w,APP_EVENT_HANDLER_T handler,void * through)145 void guiDrawSetRedrawHandler( APP_WIDGET w,
146 APP_EVENT_HANDLER_T handler,
147 void * through )
148 {
149 XtAddEventHandler( w, ExposureMask, False, handler, through );
150 }
151
guiDrawSetConfigureHandler(APP_WIDGET w,APP_EVENT_HANDLER_T handler,void * through)152 void guiDrawSetConfigureHandler( APP_WIDGET w,
153 APP_EVENT_HANDLER_T handler,
154 void * through )
155 {
156 XtAddEventHandler( w, StructureNotifyMask, False, handler, through );
157 }
158
guiDrawSetButtonPressHandler(APP_WIDGET w,APP_EVENT_HANDLER_T handler,void * through)159 void guiDrawSetButtonPressHandler( APP_WIDGET w,
160 APP_EVENT_HANDLER_T handler,
161 void * through )
162 {
163 XtAddEventHandler( w, ButtonPressMask, False, handler, through );
164 }
165
guiDrawSetScrollHandler(APP_WIDGET w,APP_EVENT_HANDLER_T handler,void * through)166 void guiDrawSetScrollHandler( APP_WIDGET w,
167 APP_EVENT_HANDLER_T handler,
168 void * through )
169 {
170 XtAddEventHandler( w, ButtonPressMask, False, handler, through );
171 }
172
guiDrawGetInoutFromFocusEvent(int * pInOut,APP_WIDGET w,APP_EVENT * event)173 int guiDrawGetInoutFromFocusEvent( int * pInOut,
174 APP_WIDGET w,
175 APP_EVENT * event )
176 {
177 switch( event->type )
178 {
179 case FocusIn:
180 *pInOut= 1; return 0;
181
182 case FocusOut:
183 *pInOut= -1; return 0;
184
185 default:
186 LDEB(event->type); return 1;
187 }
188 }
189
guiDrawGetSizeOfWidget(int * pWide,int * pHigh,APP_WIDGET w)190 int guiDrawGetSizeOfWidget( int * pWide,
191 int * pHigh,
192 APP_WIDGET w )
193 {
194 Dimension wide;
195 Dimension high;
196
197 XtVaGetValues( w, XmNwidth, &wide,
198 XmNheight, &high,
199 NULL );
200
201 *pWide= wide; *pHigh= high; return 0;
202 }
203
204 # endif
205