|
@@ -684,7 +684,7 @@ void _cmGrObjCbVExt( cmGr_t* p, const cmGrObj_t* op, cmGrVExt_t* vext )
|
684
|
684
|
}
|
685
|
685
|
}
|
686
|
686
|
|
687
|
|
-bool _cmGrObjCbIsInside( cmGr_t* p, const cmGrObj_t* op, int px, int py, cmGrV_t vx, cmGrV_t vy )
|
|
687
|
+bool _cmGrObjCbIsInside( cmGr_t* p, const cmGrObj_t* op, unsigned evtFlags, int px, int py, cmGrV_t vx, cmGrV_t vy )
|
688
|
688
|
{
|
689
|
689
|
bool fl = false;
|
690
|
690
|
if( op->f.isInsideCbFunc != NULL )
|
|
@@ -692,7 +692,7 @@ bool _cmGrObjCbIsInside( cmGr_t* p, const cmGrObj_t* op, int px, int py, cmGrV_t
|
692
|
692
|
cmGrObjFuncArgs_t a;
|
693
|
693
|
_cmGrObjSetupFuncArgs(&a,p,(cmGrObj_t*)op);
|
694
|
694
|
a.cbArg = op->f.isInsideCbArg;
|
695
|
|
- fl = op->f.isInsideCbFunc(&a,px,py,vx,vy);
|
|
695
|
+ fl = op->f.isInsideCbFunc(&a,evtFlags,px,py,vx,vy);
|
696
|
696
|
}
|
697
|
697
|
return fl;
|
698
|
698
|
}
|
|
@@ -1751,7 +1751,7 @@ void _cmGrObjRootVExt( cmGrObjFuncArgs_t* args, cmGrVExt_t* vext )
|
1751
|
1751
|
cmGrObjWorldExt( args->objH, vext );
|
1752
|
1752
|
}
|
1753
|
1753
|
|
1754
|
|
-bool _cmGrObjRootIsInside( cmGrObjFuncArgs_t* args, int px, int py, cmGrV_t vx, cmGrV_t vy )
|
|
1754
|
+bool _cmGrObjRootIsInside( cmGrObjFuncArgs_t* args, unsigned evtFlags, int px, int py, cmGrV_t vx, cmGrV_t vy )
|
1755
|
1755
|
{
|
1756
|
1756
|
cmGrVExt_t vext;
|
1757
|
1757
|
_cmGrObjRootVExt(args,&vext);
|
|
@@ -2154,8 +2154,38 @@ void _cmGrSetSelectPoints(cmGr_t* p, const cmGrVPt_t* pt0, const cmGrVPt_t* pt1
|
2154
|
2154
|
|
2155
|
2155
|
}
|
2156
|
2156
|
|
|
2157
|
+void _cmGrScrollExtents( cmGr_t* p, cmGrPSz_t* tot, cmGrPSz_t* vis, cmGrPSz_t* max, cmGrPPt_t* pos )
|
|
2158
|
+{
|
|
2159
|
+
|
|
2160
|
+ assert( p->rootObj != NULL );
|
|
2161
|
+
|
|
2162
|
+ if( tot != NULL )
|
|
2163
|
+ {
|
|
2164
|
+ tot->w = round(p->rootObj->wext.sz.w * p->pext.sz.w / p->vext.sz.w);
|
|
2165
|
+ tot->h = round(p->rootObj->wext.sz.h * p->pext.sz.h / p->vext.sz.h);
|
|
2166
|
+ }
|
|
2167
|
+
|
|
2168
|
+ if( vis != NULL )
|
|
2169
|
+ {
|
|
2170
|
+ vis->w = round(p->vext.sz.w * p->pext.sz.w / p->vext.sz.w);
|
|
2171
|
+ vis->h = round(p->vext.sz.h * p->pext.sz.h / p->vext.sz.h);
|
|
2172
|
+ }
|
|
2173
|
+
|
|
2174
|
+ if( max != NULL )
|
|
2175
|
+ {
|
|
2176
|
+ max->w = tot->w - vis->w;
|
|
2177
|
+ max->h = tot->h - vis->h;
|
|
2178
|
+ }
|
|
2179
|
+
|
|
2180
|
+ if( pos != NULL )
|
|
2181
|
+ {
|
|
2182
|
+ pos->x = _cmGrScrollH(p);
|
|
2183
|
+ pos->y = _cmGrScrollV(p);
|
|
2184
|
+ }
|
|
2185
|
+}
|
|
2186
|
+
|
2157
|
2187
|
// vx,vy are in the same coord's as op->vext
|
2158
|
|
-cmGrObj_t* _cmGrFindObjRec( cmGr_t* p, cmGrObj_t* op, int px, int py, cmGrV_t vx, cmGrV_t vy )
|
|
2188
|
+cmGrObj_t* _cmGrFindObjRec( cmGr_t* p, cmGrObj_t* op, unsigned evtFlags, int px, int py, cmGrV_t vx, cmGrV_t vy )
|
2159
|
2189
|
{
|
2160
|
2190
|
cmGrObj_t* rop = NULL;
|
2161
|
2191
|
cmGrObj_t* top;
|
|
@@ -2165,27 +2195,234 @@ cmGrObj_t* _cmGrFindObjRec( cmGr_t* p, cmGrObj_t* op, int px, int py, cmGrV_t vx
|
2165
|
2195
|
_cmGrObjCbVExt(p,op,&vext);
|
2166
|
2196
|
|
2167
|
2197
|
// is vx,vy inside op - this is equiv to: cmGrVExtIsXyInside(&vext,vx,vy)
|
2168
|
|
- if( _cmGrObjCbIsInside(p,op,px,py,vx,vy) )
|
|
2198
|
+ if( _cmGrObjCbIsInside(p,op,evtFlags,px,py,vx,vy) )
|
2169
|
2199
|
rop = op;
|
2170
|
2200
|
|
2171
|
2201
|
if( op->children != NULL )
|
2172
|
2202
|
{
|
2173
|
2203
|
cmGrVPt_t pt;
|
2174
|
2204
|
if( _cmGrParentToLocal(p,op,vx,vy,&pt) )
|
2175
|
|
- if((top = _cmGrFindObjRec(p,op->children,px,py,vx,vy)) != NULL )
|
|
2205
|
+ if((top = _cmGrFindObjRec(p,op->children,evtFlags,px,py,vx,vy)) != NULL )
|
2176
|
2206
|
rop = top;
|
2177
|
2207
|
}
|
2178
|
2208
|
|
2179
|
2209
|
if( op->rsib != NULL )
|
2180
|
|
- if((top = _cmGrFindObjRec(p,op->rsib,px,py,vx,vy)) != NULL )
|
|
2210
|
+ if((top = _cmGrFindObjRec(p,op->rsib,evtFlags,px,py,vx,vy)) != NULL )
|
2181
|
2211
|
rop = top;
|
2182
|
2212
|
|
2183
|
2213
|
|
2184
|
2214
|
return rop;
|
2185
|
2215
|
}
|
2186
|
2216
|
|
|
2217
|
+cmGrObj_t* _cmGrEventMsDown( cmGr_t* p, unsigned evtFlags, cmGrKeyCodeId_t key, int px, int py, cmGrV_t gx, cmGrV_t gy )
|
|
2218
|
+{
|
|
2219
|
+ // store the phys loc. of the ms dn event
|
|
2220
|
+ cmGrPPtSet(&p->msDnPPt,px,py);
|
2187
|
2221
|
|
2188
|
|
-bool cmGrEvent( cmGrH_t h, unsigned flags, cmGrKeyCodeId_t key, int px, int py )
|
|
2222
|
+ // get a pointer to an object
|
|
2223
|
+ cmGrObj_t* op = _cmGrFindObjRec(p, p->rootObj, evtFlags, px, py, gx, gy );
|
|
2224
|
+
|
|
2225
|
+ // if the mouse did not go down in an object that accepts mouse down events
|
|
2226
|
+ // or the object was a root object
|
|
2227
|
+ if( op == NULL || op->parent == NULL )
|
|
2228
|
+ return NULL;
|
|
2229
|
+
|
|
2230
|
+ // store the object and coord's where the mouse went down.
|
|
2231
|
+ cmGrVExt_t vext;
|
|
2232
|
+ p->msDnObj = op; // set the msDnObj
|
|
2233
|
+
|
|
2234
|
+ // convert the phys ms dn point to the virt point inside op->parent.wext
|
|
2235
|
+ _cmGrXY_PtoV(p, op->parent, px, py, &p->msDnVPt );
|
|
2236
|
+
|
|
2237
|
+ p->msVPt = p->msDnVPt; // set the current ms virt pt
|
|
2238
|
+ p->localPt = p->msDnVPt; // set the current local pt
|
|
2239
|
+
|
|
2240
|
+ // notifiy the app of the local coord's
|
|
2241
|
+ _cmGrCallback(p,kLocalPtCbGrId,0,kInvalidKeyCodeGrId);
|
|
2242
|
+
|
|
2243
|
+ // get the ms down obj virt extents
|
|
2244
|
+ _cmGrObjCbVExt(p,op,&vext);
|
|
2245
|
+
|
|
2246
|
+ // store the offset from the lower left to the ms dn point
|
|
2247
|
+ p->msDnVOffs.w = p->msDnVPt.x - vext.loc.x;
|
|
2248
|
+ p->msDnVOffs.h = p->msDnVPt.y - vext.loc.y;
|
|
2249
|
+
|
|
2250
|
+ // notify the object that the mouse went down
|
|
2251
|
+ if(_cmGrObjCbEvent(p,op,evtFlags,key,px,py))
|
|
2252
|
+ return op;
|
|
2253
|
+ return NULL;
|
|
2254
|
+}
|
|
2255
|
+
|
|
2256
|
+cmGrObj_t* _cmGrEventMsUp( cmGr_t* p, unsigned evtFlags, cmGrKeyCodeId_t key, int px, int py, cmGrV_t gx, cmGrV_t gy )
|
|
2257
|
+{
|
|
2258
|
+ bool fl = false;
|
|
2259
|
+ cmGrObj_t* op = NULL;
|
|
2260
|
+
|
|
2261
|
+ cmGrPPt_t upPPt;
|
|
2262
|
+ cmGrPPtSet(&upPPt,px,py);
|
|
2263
|
+
|
|
2264
|
+ // if a click occured ...
|
|
2265
|
+ if( cmGrPPtIsEqual(&p->msDnPPt,&upPPt ) )
|
|
2266
|
+ {
|
|
2267
|
+ // ... and the click is in a non-root object which accepts click events ...
|
|
2268
|
+ if( p->msDnObj!= NULL && p->msDnObj->parent!=NULL && _cmGrObjCbIsInside(p,p->msDnObj,evtFlags | kMsClickGrFl, px, py, gx, gy) )
|
|
2269
|
+ {
|
|
2270
|
+ // ... then generate a click event
|
|
2271
|
+ unsigned newEvtFlags = cmClrFlag(evtFlags,kMsUpGrFl) | kMsClickGrFl;
|
|
2272
|
+ fl = _cmGrObjCbEvent(p,p->msDnObj,newEvtFlags,key,px,py);
|
|
2273
|
+ op = p->msDnObj;
|
|
2274
|
+ }
|
|
2275
|
+ else // ... else if the click occurred in the root object
|
|
2276
|
+ //if( p->msDnObj==NULL || p->msDnObj->parent==NULL)
|
|
2277
|
+ {
|
|
2278
|
+ cmGrVPt_t pt;
|
|
2279
|
+ cmGrVPtSet(&pt,gx,gy);
|
|
2280
|
+
|
|
2281
|
+ bool shFl = cmIsFlag(evtFlags,kShiftKeyGrFl);
|
|
2282
|
+ _cmGrSetSelectPoints( p, shFl ? NULL : &pt, shFl ? &pt : NULL );
|
|
2283
|
+
|
|
2284
|
+ }
|
|
2285
|
+ }
|
|
2286
|
+
|
|
2287
|
+ // if op is NULL then there was no-mouse down object to match with
|
|
2288
|
+ // this mouse-up event - find an object to match with the mouse-up event
|
|
2289
|
+ if( op == NULL )
|
|
2290
|
+ op = _cmGrFindObjRec(p, p->rootObj, evtFlags, px, py, gx, gy );
|
|
2291
|
+
|
|
2292
|
+ // if a mouse-up object was found then
|
|
2293
|
+ if( op != NULL && op->parent != NULL)
|
|
2294
|
+ {
|
|
2295
|
+
|
|
2296
|
+ // notify the object under the mouse that the mouse went up
|
|
2297
|
+ if( _cmGrObjCbEvent(p,op,evtFlags,key,px,py) )
|
|
2298
|
+ fl = true;
|
|
2299
|
+
|
|
2300
|
+ // convert the phys ms dn point to the virt point inside op->parent.wext
|
|
2301
|
+ _cmGrXY_PtoV(p, op->parent, px, py, &p->msVPt );
|
|
2302
|
+
|
|
2303
|
+ }
|
|
2304
|
+
|
|
2305
|
+ _cmGrCallback(p,kFocusCbGrId,0,kInvalidKeyCodeGrId);
|
|
2306
|
+
|
|
2307
|
+ p->msDnObj = NULL;
|
|
2308
|
+
|
|
2309
|
+ return fl ? op : NULL;
|
|
2310
|
+}
|
|
2311
|
+
|
|
2312
|
+cmGrObj_t* _cmGrEventMsMove( cmGr_t* p, unsigned evtFlags, cmGrKeyCodeId_t key, int px, int py, cmGrV_t gx, cmGrV_t gy )
|
|
2313
|
+{
|
|
2314
|
+ bool fl = false;
|
|
2315
|
+ cmGrObj_t* op = _cmGrFindObjRec(p, p->rootObj, evtFlags, px, py, gx, gy );
|
|
2316
|
+
|
|
2317
|
+ if( op != NULL && op->parent != NULL )
|
|
2318
|
+ {
|
|
2319
|
+
|
|
2320
|
+ fl = _cmGrObjCbEvent(p,op,evtFlags,key,px,py);
|
|
2321
|
+ }
|
|
2322
|
+
|
|
2323
|
+ return fl ? op : NULL;
|
|
2324
|
+}
|
|
2325
|
+
|
|
2326
|
+cmGrObj_t* _cmGrEventMsDrag( cmGr_t* p, unsigned evtFlags, cmGrKeyCodeId_t key, int px, int py, cmGrV_t gx, cmGrV_t gy )
|
|
2327
|
+{
|
|
2328
|
+ bool fl = false;
|
|
2329
|
+ cmGrObj_t* op = _cmGrFindObjRec(p, p->rootObj, evtFlags, px, py, gx, gy );
|
|
2330
|
+
|
|
2331
|
+ if( op != NULL && op->parent != NULL )
|
|
2332
|
+ {
|
|
2333
|
+ // set the current virtual point
|
|
2334
|
+ _cmGrXY_PtoV(p, p->msDnObj->parent, px, py, &p->msVPt );
|
|
2335
|
+
|
|
2336
|
+ // callback the dragged object
|
|
2337
|
+ fl = _cmGrObjCbEvent(p,p->msDnObj,evtFlags,key,px,py);
|
|
2338
|
+
|
|
2339
|
+ // if the px,py is outside the root phys extents then scroll
|
|
2340
|
+ if( !cmGrPExtIsXyInside(&p->pext,px,py) )
|
|
2341
|
+ {
|
|
2342
|
+ bool hFl = false, vFl=false;
|
|
2343
|
+ cmGrPSz_t tot,vis,max;
|
|
2344
|
+ cmGrPPt_t pos;
|
|
2345
|
+ _cmGrScrollExtents(p, &tot, &vis, &max, &pos );
|
|
2346
|
+
|
|
2347
|
+ if( px < cmGrPExtL(&p->pext) )
|
|
2348
|
+ hFl = _cmGrSetScrollH(p, cmMax(0, _cmGrScrollH(p) - (cmGrPExtL(&p->pext) - px)));
|
|
2349
|
+ else
|
|
2350
|
+ if( px > cmGrPExtR(&p->pext) )
|
|
2351
|
+ hFl = _cmGrSetScrollH(p, cmMin(max.w, _cmGrScrollH(p) + (px - cmGrPExtR(&p->pext))));
|
|
2352
|
+
|
|
2353
|
+ if( py < cmGrPExtT(&p->pext) )
|
|
2354
|
+ vFl = _cmGrSetScrollV(p, cmMax(0, _cmGrScrollV(p) - (cmGrPExtT(&p->pext) - py)));
|
|
2355
|
+ else
|
|
2356
|
+ if( py > cmGrPExtB(&p->pext) )
|
|
2357
|
+ vFl = _cmGrSetScrollV(p, cmMin(max.h, _cmGrScrollV(p) + (py - cmGrPExtB(&p->pext))));
|
|
2358
|
+
|
|
2359
|
+
|
|
2360
|
+ fl = fl || vFl || hFl;
|
|
2361
|
+ }
|
|
2362
|
+ }
|
|
2363
|
+ return fl ? op : NULL;
|
|
2364
|
+}
|
|
2365
|
+
|
|
2366
|
+bool cmGrEvent( cmGrH_t h, unsigned evtFlags, cmGrKeyCodeId_t key, int px, int py )
|
|
2367
|
+{
|
|
2368
|
+ bool fl = false;
|
|
2369
|
+ cmGrObj_t* op = NULL;
|
|
2370
|
+ cmGr_t* p = _cmGrHandleToPtr(h);
|
|
2371
|
+ cmGrVPtSet(&p->localPt,0,0);
|
|
2372
|
+
|
|
2373
|
+ // convert the phys points to points in the root coord system
|
|
2374
|
+ cmGrV_t gx = _cmGr_X_PtoV(p,px);
|
|
2375
|
+ cmGrV_t gy = _cmGr_Y_PtoV(p,py);
|
|
2376
|
+
|
|
2377
|
+ // set the global point
|
|
2378
|
+ cmGrVPtSet(&p->globalPt,gx,gy);
|
|
2379
|
+
|
|
2380
|
+ // inform the app of the possibly new global point
|
|
2381
|
+ _cmGrCallback(p,kGlobalPtCbGrId,0,kInvalidKeyCodeGrId);
|
|
2382
|
+
|
|
2383
|
+ switch( evtFlags & kEvtMask)
|
|
2384
|
+ {
|
|
2385
|
+ case kKeyUpGrFl:
|
|
2386
|
+ _cmGrCallback(p,kKeyUpCbGrId,evtFlags,key);
|
|
2387
|
+ break;
|
|
2388
|
+
|
|
2389
|
+ case kKeyDnGrFl:
|
|
2390
|
+ _cmGrCallback(p,kKeyDnCbGrId,evtFlags,key);
|
|
2391
|
+ break;
|
|
2392
|
+
|
|
2393
|
+ case kMsDownGrFl:
|
|
2394
|
+ op = _cmGrEventMsDown(p,evtFlags,key,px,py,gx,gy);
|
|
2395
|
+ break;
|
|
2396
|
+
|
|
2397
|
+ case kMsUpGrFl: // handle mouse-up, mouse-click, and focus events
|
|
2398
|
+ op = _cmGrEventMsUp(p,evtFlags,key,px,py,gx,gy);
|
|
2399
|
+ break;
|
|
2400
|
+
|
|
2401
|
+ case kMsMoveGrFl:
|
|
2402
|
+ op = _cmGrEventMsMove(p,evtFlags,key,px,py,gx,gy);
|
|
2403
|
+ break;
|
|
2404
|
+
|
|
2405
|
+ case kMsDragGrFl:
|
|
2406
|
+ op = _cmGrEventMsDrag(p,evtFlags,key,px,py,gx,gy);
|
|
2407
|
+ break;
|
|
2408
|
+
|
|
2409
|
+ }
|
|
2410
|
+
|
|
2411
|
+ if( op != NULL )
|
|
2412
|
+ {
|
|
2413
|
+ // convert gx,gy to be inside op->wext
|
|
2414
|
+ cmGrVPtSet(&p->localPt,gx,gy);
|
|
2415
|
+ _cmGrXY_GlobalToLocal(p,op,&p->localPt);
|
|
2416
|
+
|
|
2417
|
+ _cmGrCallback(p,kLocalPtCbGrId,0,kInvalidKeyCodeGrId);
|
|
2418
|
+
|
|
2419
|
+ fl = true;
|
|
2420
|
+ }
|
|
2421
|
+
|
|
2422
|
+ return fl;
|
|
2423
|
+}
|
|
2424
|
+
|
|
2425
|
+bool cmGrEvent1( cmGrH_t h, unsigned flags, cmGrKeyCodeId_t key, int px, int py )
|
2189
|
2426
|
{
|
2190
|
2427
|
bool fl = false;
|
2191
|
2428
|
cmGr_t* p = _cmGrHandleToPtr(h);
|
|
@@ -2201,7 +2438,7 @@ bool cmGrEvent( cmGrH_t h, unsigned flags, cmGrKeyCodeId_t key, int px, int
|
2201
|
2438
|
_cmGrCallback(p,kGlobalPtCbGrId,0,kInvalidKeyCodeGrId);
|
2202
|
2439
|
|
2203
|
2440
|
// find the obj under the mouse
|
2204
|
|
- if((op = _cmGrFindObjRec(p,p->rootObj,px,py,gx,gy)) != NULL )
|
|
2441
|
+ if((op = _cmGrFindObjRec(p,p->rootObj,flags&kEvtMask,px,py,gx,gy)) != NULL )
|
2205
|
2442
|
{
|
2206
|
2443
|
// convert gx,gy to be inside op->wext
|
2207
|
2444
|
cmGrVPtSet(&p->localPt,gx,gy);
|
|
@@ -2414,39 +2651,13 @@ void cmGrPhysExtents( cmGrH_t h, cmGrPExt_t* exts )
|
2414
|
2651
|
cmGr_t* p = _cmGrHandleToPtr(h);
|
2415
|
2652
|
*exts = p->pext;
|
2416
|
2653
|
}
|
2417
|
|
-
|
2418
|
|
-
|
2419
|
2654
|
void cmGrScrollExtents( cmGrH_t h, cmGrPSz_t* tot, cmGrPSz_t* vis, cmGrPSz_t* max, cmGrPPt_t* pos )
|
2420
|
2655
|
{
|
2421
|
2656
|
cmGr_t* p = _cmGrHandleToPtr(h);
|
2422
|
|
-
|
2423
|
|
- assert( p->rootObj != NULL );
|
2424
|
|
-
|
2425
|
|
- if( tot != NULL )
|
2426
|
|
- {
|
2427
|
|
- tot->w = round(p->rootObj->wext.sz.w * p->pext.sz.w / p->vext.sz.w);
|
2428
|
|
- tot->h = round(p->rootObj->wext.sz.h * p->pext.sz.h / p->vext.sz.h);
|
2429
|
|
- }
|
2430
|
|
-
|
2431
|
|
- if( vis != NULL )
|
2432
|
|
- {
|
2433
|
|
- vis->w = round(p->vext.sz.w * p->pext.sz.w / p->vext.sz.w);
|
2434
|
|
- vis->h = round(p->vext.sz.h * p->pext.sz.h / p->vext.sz.h);
|
2435
|
|
- }
|
2436
|
|
-
|
2437
|
|
- if( max != NULL )
|
2438
|
|
- {
|
2439
|
|
- max->w = tot->w - vis->w;
|
2440
|
|
- max->h = tot->h - vis->h;
|
2441
|
|
- }
|
2442
|
|
-
|
2443
|
|
- if( pos != NULL )
|
2444
|
|
- {
|
2445
|
|
- pos->x = _cmGrScrollH(p);
|
2446
|
|
- pos->y = _cmGrScrollV(p);
|
2447
|
|
- }
|
|
2657
|
+ _cmGrScrollExtents(p,tot,vis,max,pos);
|
2448
|
2658
|
}
|
2449
|
2659
|
|
|
2660
|
+
|
2450
|
2661
|
bool cmGrSetScrollH( cmGrH_t h, int x )
|
2451
|
2662
|
{ return _cmGrSetScrollH( _cmGrHandleToPtr(h), x ); }
|
2452
|
2663
|
|