From 9d4c82ae37cfbf432b8a6864f86defbc522c3832 Mon Sep 17 00:00:00 2001 From: kpl Date: Wed, 14 Nov 2012 20:04:42 -0800 Subject: [PATCH] cmGrPlot.h/c Added default plot obj callback function to mgr. --- cmGrPlot.c | 21 ++++++++++++++++----- cmGrPlot.h | 13 +++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cmGrPlot.c b/cmGrPlot.c index cc41b6d..6b74955 100644 --- a/cmGrPlot.c +++ b/cmGrPlot.c @@ -62,10 +62,12 @@ typedef struct cmGrPlotObj_str typedef struct cmGrPl_str { - cmCtx_t* ctx; // - cmErr_t err; // - cmGrPlotObj_t* list; // plot object linked list - cmGrPlotObj_t* fop; // focused object ptr + cmCtx_t* ctx; // + cmErr_t err; // + cmGrPlotObj_t* list; // plot object linked list + cmGrPlotObj_t* fop; // focused object ptr + cmGrPlotCbFunc_t cbFunc; // dflt callback function + void* cbArg; // dflt callback function arg. } cmGrPl_t; cmGrPlH_t cmGrPlNullHandle = cmSTATIC_NULL_HANDLE; @@ -196,7 +198,7 @@ bool _cmGrPlotObjCb( cmGrPlotObj_t* op, cmGrPlCbSelId_t selId, unsigned deltaFla { cmGrPlotCbArg_t a; - _cmGrPlotObjSetupCbArg(&a,op,kPreEventCbSelGrPlId); + _cmGrPlotObjSetupCbArg(&a,op,selId); a.deltaFlags = deltaFlags; return op->cbFunc(&a); } @@ -743,6 +745,8 @@ cmGrPlRC_t cmGrPlotObjCreate( op->fontId = kHelveticaFfGrId; op->fontSize = 12; op->fontStyle = kNormalFsGrFl; + op->cbFunc = p->cbFunc; + op->cbArg = p->cbArg; if( cmIsFlag(op->cfgFlags,kSymbolGrPlFl) ) { @@ -1232,3 +1236,10 @@ void cmGrPlotKeyEvent( cmGrPlH_t h, cmGrH_t grH, unsigned eventFlags, cmGrKey _cmGrPlotObjEvent(&a, eventFlags, keycode, 0, 0 ); } } + +void cmGrPlotSetCb( cmGrPlH_t h, cmGrPlotCbFunc_t func, void* arg ) +{ + cmGrPl_t* p = _cmGrPlHandleToPtr(h); + p->cbFunc = func; + p->cbArg = arg; +} diff --git a/cmGrPlot.h b/cmGrPlot.h index 7f965aa..a92ebb5 100644 --- a/cmGrPlot.h +++ b/cmGrPlot.h @@ -94,7 +94,7 @@ extern "C" { cmGrKeyCodeId_t eventKey; // Event keys (See the cmGrEvent() keys) int eventX; // Mouse X,Y location when event was generated (Same as cmGrEvent()) int eventY; // - unsigned deltaFlags; // Event caused an object state change (See kXXXGrPlFl flags) + unsigned deltaFlags; // Event which caused an object state change (See kXXXGrPlFl flags) } cmGrPlotCbArg_t; @@ -104,7 +104,8 @@ extern "C" { // the object has not yet been changed. This may be confusing because if // the state of the object is queried inside the callback it will have the // pre-change state - but this state will be automatically toggled when the - // callback returns 'true'. + // callback returns 'true'. Examine the arg->deltaFlags to determine the + // state attribute which is changing. typedef bool (*cmGrPlotCbFunc_t)( cmGrPlotCbArg_t* arg ); extern cmGrPlH_t cmGrPlNullHandle; @@ -201,13 +202,21 @@ extern "C" { cmGrPlRC_t cmGrPlotClear( cmGrPlH_t h ); // destroy all objects cmErr_t* cmGrPlotErr( cmGrPlH_t h ); cmRpt_t* cmGrPlotRpt( cmGrPlH_t h ); + + // Return the count of plot objects. unsigned cmGrPlotObjectCount( cmGrPlH_t h ); + + // Return the handle of the ith object (0<=index