Browse Source

cmGrPlot.h : Make callbacks for deselected objects when a new object is selected.

Added cmPlotObjCb() function.
master
Kevin Larke 9 years ago
parent
commit
4cd55db162
2 changed files with 35 additions and 10 deletions
  1. 31
    10
      cmGrPlot.c
  2. 4
    0
      cmGrPlot.h

+ 31
- 10
cmGrPlot.c View File

@@ -180,7 +180,7 @@ bool _cmGrPlotObjIsFocused(cmGrPlotObj_t* op)
180 180
 { return _cmGrPlotObjIsEnabled(op) && op->p->fop==op; }
181 181
 
182 182
 bool _cmGrPlotObjIsSelected(cmGrPlotObj_t* op)
183
-{ return _cmGrPlotObjIsFocused(op) || cmIsFlag(op->stateFlags,kSelectGrPlFl); }
183
+{ return /*_cmGrPlotObjIsFocused(op) ||*/ cmIsFlag(op->stateFlags,kSelectGrPlFl); }
184 184
 
185 185
 void _cmGrPlotObjSetupCbArg( cmGrPlotCbArg_t* a, cmGrPlotObj_t* op, cmGrPlCbSelId_t selId )
186 186
 {
@@ -249,6 +249,8 @@ void _cmGrPlotObjSetFocus( cmGrPlotObj_t* op )
249 249
 
250 250
 }
251 251
 
252
+// Set the clear flag to clear all other selected objects if this object is 
253
+// selected.
252 254
 void _cmGrPlotObjSetSelect( cmGrPlotObj_t* op, bool clearFl )
253 255
 {
254 256
   // if the object is disabled or not selectable
@@ -257,7 +259,7 @@ void _cmGrPlotObjSetSelect( cmGrPlotObj_t* op, bool clearFl )
257 259
 
258 260
   unsigned stateFlags = op->stateFlags;
259 261
 
260
-  // if the application callback returns false then do change the select state of the object
262
+  // if the application callback returns false then do not change the select state of the object
261 263
   if(_cmGrPlotObjCb(op, kPreEventCbSelGrPlId, kSelectGrPlFl ) == false )
262 264
     return;
263 265
 
@@ -268,8 +270,15 @@ void _cmGrPlotObjSetSelect( cmGrPlotObj_t* op, bool clearFl )
268 270
 
269 271
     // clear the select flag on all objects that share op->parent
270 272
     for(; cop!=NULL; cop=cop->next)
271
-      if( cmHandlesAreEqual(cmGrObjParent(cop->grObjH),parentObjH) )
272
-        cop->stateFlags = cmClrFlag(cop->stateFlags,kSelectGrPlFl);
273
+      if( cop!=op && cmHandlesAreEqual(cmGrObjParent(cop->grObjH),parentObjH) )
274
+      {
275
+        if( cmIsFlag(cop->stateFlags,kSelectGrPlFl) )
276
+        {  
277
+          cop->stateFlags = cmClrFlag(cop->stateFlags,kSelectGrPlFl);
278
+          
279
+          _cmGrPlotObjCb(cop, kStateChangeGrPlId, kSelectGrPlFl );
280
+        }
281
+      }
273 282
   }
274 283
          
275 284
   op->stateFlags = cmTogFlag(stateFlags,kSelectGrPlFl);
@@ -603,7 +612,7 @@ bool _cmGrPlotObjEvent( cmGrObjFuncArgs_t* args, unsigned flags, unsigned key, i
603 612
   {
604 613
     cmGrPlotObj_t* cb_op = op;
605 614
 
606
-    // if this is a key up/dn event and 'op' is not the 'focused op' then callback
615
+    // if this is a key up/dn event and 'op' is not the 'focused op' then 
607 616
     // callback on the 'focused op' instead of this 'op'.
608 617
     if( (cmIsFlag(flags,kKeyDnGrFl) || cmIsFlag(flags,kKeyUpGrFl)) && op->p->fop != op )
609 618
       cb_op = op->p->fop;
@@ -834,17 +843,17 @@ cmGrPlRC_t cmGrPlotObjCreate(
834 843
 
835 844
 
836 845
   // set the default colors
837
-  op->drawColors[kSelectPlGrId] =   0xcd853f;
838
-  op->fillColors[kSelectPlGrId] =   0xdeb887; 
846
+  op->drawColors[kSelectPlGrId] =   kPeruGrId;
847
+  op->fillColors[kSelectPlGrId] =   kBurlyWoodGrId;
839 848
 
840
-  op->drawColors[kFocusPlGrId] =  0x483d8b;
849
+  op->drawColors[kFocusPlGrId] =  kDarkSlateBlueGrId;
841 850
   op->fillColors[kFocusPlGrId] =  0x8470ff; 
842 851
 
843
-  op->drawColors[kEnablePlGrId] =  0x000000;
852
+  op->drawColors[kEnablePlGrId] =  kBlackGrId;
844 853
   op->fillColors[kEnablePlGrId] =  0x009ff7; 
845 854
 
846 855
   op->drawColors[kDisablePlGrId] = 0xbebebe;
847
-  op->fillColors[kDisablePlGrId] = 0xd3d3de; 
856
+  op->fillColors[kDisablePlGrId] = kLightGrayGrId; 
848 857
 
849 858
   unsigned   grObjCfgFlags = 0;
850 859
   cmGrObjH_t parentGrH     = op->parent == NULL ? cmGrObjNullHandle : op->parent->grObjH;
@@ -1345,6 +1354,18 @@ cmGrPlObjH_t cmGrPlotObjectIndexToHandle( cmGrPlH_t h, unsigned index )
1345 1354
   return oh;
1346 1355
 }
1347 1356
 
1357
+void         cmGrPlotObjCb( cmGrPlH_t h, cmGrPlotObjCbFunc_t func, void* arg  )
1358
+{
1359
+  cmGrPl_t*       p = _cmGrPlHandleToPtr(h);
1360
+  cmGrPlotObj_t* op = p->list;
1361
+  cmGrPlObjH_t   oh = cmGrPlObjNullHandle;
1362
+
1363
+  for(; op!=NULL; op=op->next)
1364
+  {
1365
+    oh.h = op;
1366
+    func(arg,oh);
1367
+  }
1368
+}
1348 1369
 
1349 1370
 void  cmGrPlotKeyEvent(   cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode )
1350 1371
 {

+ 4
- 0
cmGrPlot.h View File

@@ -219,6 +219,10 @@ extern "C" {
219 219
   // Given a plot object id return the associated object handle.
220 220
   cmGrPlObjH_t cmGrPlotObjectIdToHandle( cmGrPlH_t h, unsigned id );
221 221
 
222
+  // Callback func(arg,objH) for every object. 
223
+  typedef void (*cmGrPlotObjCbFunc_t)( void* arg, cmGrPlObjH_t oh );
224
+  void         cmGrPlotObjCb( cmGrPlH_t h, cmGrPlotObjCbFunc_t func, void* arg );
225
+
222 226
   // Pass a keyboard event to the plot system.
223 227
   void         cmGrPlotKeyEvent(   cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode );
224 228
   

Loading…
Cancel
Save