Explorar el Código

cmGrPlot.h/c Added default plot obj callback function to mgr.

master
kpl hace 12 años
padre
commit
9d4c82ae37
Se han modificado 2 ficheros con 27 adiciones y 7 borrados
  1. 16
    5
      cmGrPlot.c
  2. 11
    2
      cmGrPlot.h

+ 16
- 5
cmGrPlot.c Ver fichero

@@ -62,10 +62,12 @@ typedef struct cmGrPlotObj_str
62 62
 
63 63
 typedef struct cmGrPl_str
64 64
 {
65
-  cmCtx_t*       ctx;  // 
66
-  cmErr_t        err;  //
67
-  cmGrPlotObj_t* list; // plot object linked list
68
-  cmGrPlotObj_t* fop;  // focused object ptr
65
+  cmCtx_t*         ctx;         // 
66
+  cmErr_t          err;         //
67
+  cmGrPlotObj_t*   list;        // plot object linked list
68
+  cmGrPlotObj_t*   fop;         // focused object ptr
69
+  cmGrPlotCbFunc_t cbFunc;      // dflt callback function
70
+  void*            cbArg;       // dflt callback function arg.
69 71
 } cmGrPl_t;
70 72
 
71 73
 cmGrPlH_t    cmGrPlNullHandle    = cmSTATIC_NULL_HANDLE;
@@ -196,7 +198,7 @@ bool _cmGrPlotObjCb( cmGrPlotObj_t* op, cmGrPlCbSelId_t selId, unsigned deltaFla
196 198
   {
197 199
     cmGrPlotCbArg_t a;
198 200
 
199
-    _cmGrPlotObjSetupCbArg(&a,op,kPreEventCbSelGrPlId);
201
+    _cmGrPlotObjSetupCbArg(&a,op,selId);
200 202
     a.deltaFlags = deltaFlags; 
201 203
     return op->cbFunc(&a);
202 204
   }
@@ -743,6 +745,8 @@ cmGrPlRC_t cmGrPlotObjCreate(
743 745
   op->fontId     = kHelveticaFfGrId;
744 746
   op->fontSize   = 12;
745 747
   op->fontStyle  = kNormalFsGrFl;
748
+  op->cbFunc     = p->cbFunc;
749
+  op->cbArg      = p->cbArg;
746 750
 
747 751
   if( cmIsFlag(op->cfgFlags,kSymbolGrPlFl) )
748 752
   {
@@ -1232,3 +1236,10 @@ void  cmGrPlotKeyEvent(   cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKey
1232 1236
     _cmGrPlotObjEvent(&a, eventFlags, keycode, 0, 0 );   
1233 1237
   }   
1234 1238
 }
1239
+
1240
+void  cmGrPlotSetCb( cmGrPlH_t h, cmGrPlotCbFunc_t func, void* arg )
1241
+{
1242
+  cmGrPl_t*      p  = _cmGrPlHandleToPtr(h);
1243
+  p->cbFunc = func;
1244
+  p->cbArg  = arg;
1245
+}

+ 11
- 2
cmGrPlot.h Ver fichero

@@ -94,7 +94,7 @@ extern "C" {
94 94
     cmGrKeyCodeId_t eventKey;     // Event keys (See the cmGrEvent() keys)
95 95
     int             eventX;       // Mouse X,Y location when event was generated (Same as cmGrEvent()) 
96 96
     int             eventY;       // 
97
-    unsigned        deltaFlags;   // Event caused an object state change (See kXXXGrPlFl flags) 
97
+    unsigned        deltaFlags;   // Event which caused an object state change (See kXXXGrPlFl flags) 
98 98
   } cmGrPlotCbArg_t;
99 99
 
100 100
 
@@ -104,7 +104,8 @@ extern "C" {
104 104
   // the object has not yet been changed.  This may be confusing because if 
105 105
   // the state of the object is queried inside the callback it will have the 
106 106
   // pre-change state - but this state will be automatically toggled when the 
107
-  // callback returns  'true'.  
107
+  // callback returns  'true'.  Examine the arg->deltaFlags to determine the
108
+  // state attribute which is changing.
108 109
   typedef bool (*cmGrPlotCbFunc_t)( cmGrPlotCbArg_t* arg );
109 110
 
110 111
   extern cmGrPlH_t    cmGrPlNullHandle;
@@ -201,13 +202,21 @@ extern "C" {
201 202
   cmGrPlRC_t   cmGrPlotClear(   cmGrPlH_t h ); // destroy all objects
202 203
   cmErr_t*     cmGrPlotErr(     cmGrPlH_t h );
203 204
   cmRpt_t*     cmGrPlotRpt(     cmGrPlH_t h );
205
+  
206
+  // Return the count of plot objects.
204 207
   unsigned     cmGrPlotObjectCount(   cmGrPlH_t h );
208
+
209
+  // Return the handle of the ith object (0<=index<cmGrPlotObjectCount())
205 210
   cmGrPlObjH_t cmGrPlotObjectIndexToHandle( cmGrPlH_t h, unsigned index );
211
+
212
+  // Given a plot object id return the associated object handle.
206 213
   cmGrPlObjH_t cmGrPlotObjectIdToHandle( cmGrPlH_t h, unsigned id );
207 214
 
208 215
   // Pass a keyboard event to the plot system.
209 216
   void         cmGrPlotKeyEvent(   cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKeyCodeId_t keycode );
210 217
   
218
+  // Set the default object callback and arg.
219
+  void         cmGrPlotSetCb( cmGrPlH_t h, cmGrPlotCbFunc_t func, void* arg );
211 220
 
212 221
 
213 222
 #ifdef __cplusplus

Loading…
Cancelar
Guardar