diff options
-rw-r--r-- | src/bltGrAxis.C | 24 | ||||
-rw-r--r-- | src/bltGrAxis.h | 8 | ||||
-rw-r--r-- | src/bltGrAxisOp.C | 18 | ||||
-rw-r--r-- | src/bltGrAxisOp.h | 1 | ||||
-rw-r--r-- | src/bltGrAxisOption.C | 72 | ||||
-rw-r--r-- | src/bltGrMarker.C | 6 | ||||
-rw-r--r-- | src/bltGrMarker.h | 2 | ||||
-rw-r--r-- | src/bltGrMarkerOp.C | 13 | ||||
-rw-r--r-- | src/bltGrPen.C | 10 | ||||
-rw-r--r-- | src/bltGrPen.h | 4 | ||||
-rw-r--r-- | src/bltGrPenOp.C | 6 | ||||
-rw-r--r-- | src/bltGrXAxisOp.C | 25 | ||||
-rw-r--r-- | src/bltGraph.C | 5 |
13 files changed, 72 insertions, 122 deletions
diff --git a/src/bltGrAxis.C b/src/bltGrAxis.C index d347c65..c25f742 100644 --- a/src/bltGrAxis.C +++ b/src/bltGrAxis.C @@ -193,14 +193,14 @@ Axis::Axis(Graph* graphPtr, const char* name, int margin, Tcl_HashEntry* hPtr) name_ = dupstr(name); className_ = dupstr("none"); - use_ =0; hashPtr_ = hPtr; + link =NULL; + chain =NULL; + refCount_ =0; + use_ =0; flags =0; - /* Fields specific to axes. */ - detail_ =NULL; - refCount_ =0; titlePos_.x =0; titlePos_.y =0; titleWidth_ =0; @@ -228,11 +228,7 @@ Axis::Axis(Graph* graphPtr, const char* name, int margin, Tcl_HashEntry* hPtr) majorSweep_.step =0; majorSweep_.nSteps =0; - /* The following fields are specific to logical axes */ - margin_ = margin; - link =NULL; - chain =NULL; segments_ =NULL; nSegments_ =0; tickLabels_ = Blt_Chain_Create(); @@ -499,7 +495,7 @@ void Axis::draw(Drawable drawable) { AxisOptions* ops = (AxisOptions*)ops_; - if (ops->hide || !use_ || (flags & DELETE_PENDING)) + if (ops->hide || !use_) return; if (ops->normalBg) @@ -628,7 +624,7 @@ void Axis::drawGrids(Drawable drawable) { AxisOptions* ops = (AxisOptions*)ops_; - if (ops->hide || !ops->showGrid || !use_ || (flags & DELETE_PENDING)) + if (ops->hide || !ops->showGrid || !use_) return; Blt_Draw2DSegments(graphPtr_->display_, drawable, ops->major.gc, @@ -644,7 +640,7 @@ void Axis::drawLimits(Drawable drawable) AxisOptions* ops = (AxisOptions*)ops_; GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; - if ((flags & DELETE_PENDING) || (!ops->limitsFormat)) + if (!ops->limitsFormat) return; int vMin = graphPtr_->left_ + gops->xPad + 2; @@ -1690,7 +1686,7 @@ void Axis::print(Blt_Ps ps) { AxisOptions* ops = (AxisOptions*)ops_; - if (ops->hide || !use_ || (flags & DELETE_PENDING)) + if (ops->hide || !use_) return; Blt_Ps_Format(ps, "%% Axis \"%s\"\n", name_); @@ -1745,7 +1741,7 @@ void Axis::printGrids(Blt_Ps ps) { AxisOptions* ops = (AxisOptions*)ops_; - if (ops->hide || !ops->showGrid || !use_ || (flags & DELETE_PENDING)) + if (ops->hide || !ops->showGrid || !use_) return; Blt_Ps_Format(ps, "%% Axis %s: grid line attributes\n", name_); @@ -1767,7 +1763,7 @@ void Axis::printLimits(Blt_Ps ps) AxisOptions* ops = (AxisOptions*)ops_; GraphOptions* gops = (GraphOptions*)graphPtr_->ops_; - if ((flags & DELETE_PENDING) || (!ops->limitsFormat)) + if (!ops->limitsFormat) return; double vMin = graphPtr_->left_ + gops->xPad + 2; diff --git a/src/bltGrAxis.h b/src/bltGrAxis.h index 31d0e57..85d3e6b 100644 --- a/src/bltGrAxis.h +++ b/src/bltGrAxis.h @@ -157,12 +157,14 @@ class Axis { const char* name_; const char* className_; - int use_; Tcl_HashEntry* hashPtr_; + Blt_ChainLink link; + Blt_Chain chain; + int refCount_; + int use_; unsigned int flags; const char *detail_; - int refCount_; Point2d titlePos_; unsigned short int titleWidth_; unsigned short int titleHeight_; @@ -180,8 +182,6 @@ class Axis { TickSweep majorSweep_; int margin_; - Blt_ChainLink link; - Blt_Chain chain; Segment2d *segments_; int nSegments_; Blt_Chain tickLabels_; diff --git a/src/bltGrAxisOp.C b/src/bltGrAxisOp.C index e43b925..31cb091 100644 --- a/src/bltGrAxisOp.C +++ b/src/bltGrAxisOp.C @@ -406,11 +406,10 @@ static int DeleteOp(Tcl_Interp* interp, Graph* graphPtr, if (graphPtr->getAxis(objv[3], &axisPtr) != TCL_OK) return TCL_ERROR; - axisPtr->flags |= DELETE_PENDING; - if (axisPtr->refCount_ == 0) { - Tcl_EventuallyFree(axisPtr, FreeAxis); - graphPtr->eventuallyRedraw(); - } + if (axisPtr->refCount_ == 0) + delete axisPtr; + + graphPtr->eventuallyRedraw(); return TCL_OK; } @@ -496,9 +495,6 @@ static int NamesOp(Tcl_Interp* interp, Graph* graphPtr, Tcl_HashSearch cursor; for (Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&graphPtr->axes_.table, &cursor); hPtr; hPtr = Tcl_NextHashEntry(&cursor)) { Axis* axisPtr = (Axis*)Tcl_GetHashValue(hPtr); - if (axisPtr->flags & DELETE_PENDING) - continue; - Tcl_ListObjAppendElement(interp, listObjPtr, Tcl_NewStringObj(axisPtr->name_, -1)); } } @@ -588,12 +584,6 @@ int Blt_AxisOp(Graph* graphPtr, Tcl_Interp* interp, // Support -void FreeAxis(char* data) -{ - Axis* axisPtr = (Axis*)data; - delete axisPtr; -} - Axis *Blt_GetFirstAxis(Blt_Chain chain) { Blt_ChainLink link = Blt_Chain_FirstLink(chain); diff --git a/src/bltGrAxisOp.h b/src/bltGrAxisOp.h index f822b67..8eb7ec5 100644 --- a/src/bltGrAxisOp.h +++ b/src/bltGrAxisOp.h @@ -35,7 +35,6 @@ extern int AxisObjConfigure(Tcl_Interp* interp, Axis* axisPtr, extern int Blt_AxisOp(Graph* graphPtr, Tcl_Interp* interp, int objc, Tcl_Obj* const objv[]); -extern Tcl_FreeProc FreeAxis; extern Axis *Blt_GetFirstAxis(Blt_Chain chain); #endif diff --git a/src/bltGrAxisOption.C b/src/bltGrAxisOption.C index 279fa87..678b374 100644 --- a/src/bltGrAxisOption.C +++ b/src/bltGrAxisOption.C @@ -34,11 +34,6 @@ extern "C" { #include "bltGrAxis.h" #include "bltGrAxisOption.h" -extern Tcl_FreeProc FreeAxis; -static int GetAxisByClass(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr, - ClassId classId, Axis **axisPtrPtr); -static void ReleaseAxis(Axis* axisPtr); - static Tk_CustomOptionSetProc AxisSetProc; static Tk_CustomOptionGetProc AxisGetProc; static Tk_CustomOptionFreeProc AxisFreeProc; @@ -65,12 +60,27 @@ static int AxisSetProc(ClientData clientData, Tcl_Interp* interp, Graph* graphPtr = Blt_GetGraphFromWindowData(tkwin); ClassId classId = (ClassId)(long(clientData)); - Axis* axisPtr; - if (GetAxisByClass(interp, graphPtr, *objPtr, classId, &axisPtr) != TCL_OK) + + Axis *axisPtr; + if (graphPtr->getAxis(*objPtr, &axisPtr) != TCL_OK) return TCL_ERROR; - *axisPtrPtr = axisPtr; + if (classId != CID_NONE) { + // Set the axis type on the first use of it. + if ((axisPtr->refCount_ == 0) || (axisPtr->classId_ == CID_NONE)) + axisPtr->setClass(classId); + + else if (axisPtr->classId_ != classId) { + Tcl_AppendResult(interp, "axis \"", Tcl_GetString(*objPtr), + "\" is already in use on an opposite ", + axisPtr->className_, "-axis", + NULL); + return TCL_ERROR; + } + axisPtr->refCount_++; + } + *axisPtrPtr = axisPtr; return TCL_OK; }; @@ -87,8 +97,11 @@ static Tcl_Obj* AxisGetProc(ClientData clientData, Tk_Window tkwin, static void AxisFreeProc(ClientData clientData, Tk_Window tkwin, char *ptr) { Axis* axisPtr = *(Axis**)ptr; - if (axisPtr) - ReleaseAxis(axisPtr); + if (axisPtr) { + axisPtr->refCount_--; + if (axisPtr->refCount_ == 0) + delete axisPtr; + } } static Tk_CustomOptionSetProc LimitSetProc; @@ -240,42 +253,3 @@ static void ObjectFreeProc(ClientData clientData, Tk_Window tkwin, Tcl_DecrRefCount(objectPtr); } -// Support - -static int GetAxisByClass(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj *objPtr, - ClassId classId, Axis **axisPtrPtr) -{ - Axis *axisPtr; - if (graphPtr->getAxis(objPtr, &axisPtr) != TCL_OK) - return TCL_ERROR; - - if (classId != CID_NONE) { - // Set the axis type on the first use of it. - if ((axisPtr->refCount_ == 0) || (axisPtr->classId_ == CID_NONE)) - axisPtr->setClass(classId); - - else if (axisPtr->classId_ != classId) { - Tcl_AppendResult(interp, "axis \"", Tcl_GetString(objPtr), - "\" is already in use on an opposite ", - axisPtr->className_, "-axis", - NULL); - return TCL_ERROR; - } - axisPtr->refCount_++; - } - - *axisPtrPtr = axisPtr; - return TCL_OK; -} - -static void ReleaseAxis(Axis *axisPtr) -{ - if (axisPtr) { - axisPtr->refCount_--; - if (axisPtr->refCount_ == 0) { - axisPtr->flags |= DELETE_PENDING; - Tcl_EventuallyFree(axisPtr, FreeAxis); - } - } -} - diff --git a/src/bltGrMarker.C b/src/bltGrMarker.C index 523a6dd..e276d5d 100644 --- a/src/bltGrMarker.C +++ b/src/bltGrMarker.C @@ -35,15 +35,15 @@ using namespace Blt; Marker::Marker(Graph* gPtr, const char* nPtr, Tcl_HashEntry* hPtr) { - name_ = dupstr(nPtr); optionTable_ =NULL; ops_ =NULL; + graphPtr_ =gPtr; + name_ = dupstr(nPtr); hashPtr_ = hPtr; - clipped_ =0; - link =NULL; flags =0; + clipped_ =0; } Marker::~Marker() diff --git a/src/bltGrMarker.h b/src/bltGrMarker.h index 6a01af2..f22a5aa 100644 --- a/src/bltGrMarker.h +++ b/src/bltGrMarker.h @@ -67,9 +67,9 @@ namespace Blt { Graph* graphPtr_; const char *name_; Tcl_HashEntry* hashPtr_; - int clipped_; Blt_ChainLink link; unsigned int flags; + int clipped_; protected: double HMap(Axis*, double); diff --git a/src/bltGrMarkerOp.C b/src/bltGrMarkerOp.C index 7528d69..2b80e94 100644 --- a/src/bltGrMarkerOp.C +++ b/src/bltGrMarkerOp.C @@ -45,8 +45,6 @@ using namespace Blt; static int GetMarkerFromObj(Tcl_Interp* interp, Graph* graphPtr, Tcl_Obj* objPtr, Marker** markerPtrPtr); -static void FreeMarker(char* dataPtr); - static int MarkerObjConfigure( Tcl_Interp* interp, Graph* graphPtr, Marker* markerPtr, int objc, Tcl_Obj* const objv[]) @@ -238,8 +236,7 @@ static int DeleteOp(Graph* graphPtr, Tcl_Interp* interp, Tk_PathName(graphPtr->tkwin_), "\"", NULL); return TCL_ERROR; } - markerPtr->flags |= DELETE_PENDING; - Tcl_EventuallyFree(markerPtr, FreeMarker); + delete markerPtr; } graphPtr->eventuallyRedraw(); @@ -305,7 +302,7 @@ static int FindOp(Graph* graphPtr, Tcl_Interp* interp, link; link = Blt_Chain_NextLink(link)) { Marker* markerPtr = (Marker*)Blt_Chain_GetValue(link); MarkerOptions* ops = (MarkerOptions*)markerPtr->ops(); - if ((markerPtr->flags & DELETE_PENDING) || ops->hide) + if (ops->hide) continue; if (graphPtr->isElementHidden(markerPtr)) @@ -459,9 +456,3 @@ static int GetMarkerFromObj(Tcl_Interp* interp, Graph* graphPtr, return TCL_ERROR; } -static void FreeMarker(char* dataPtr) -{ - Marker* markerPtr = (Marker*)dataPtr; - delete markerPtr; -} - diff --git a/src/bltGrPen.C b/src/bltGrPen.C index ebde38f..9fc06b0 100644 --- a/src/bltGrPen.C +++ b/src/bltGrPen.C @@ -31,14 +31,14 @@ Pen::Pen(Graph* graphPtr, const char* name, Tcl_HashEntry* hPtr) { - graphPtr_ = graphPtr; - name_ = dupstr(name); optionTable_ = NULL; ops_ = NULL; - manageOptions_ =0; - flags =0; - refCount =0; + graphPtr_ = graphPtr; + name_ = dupstr(name); hashPtr_ = hPtr; + refCount_ =0; + flags =0; + manageOptions_ =0; } Pen::~Pen() diff --git a/src/bltGrPen.h b/src/bltGrPen.h index 538a563..5766149 100644 --- a/src/bltGrPen.h +++ b/src/bltGrPen.h @@ -57,10 +57,10 @@ class Pen { public: Graph* graphPtr_; const char *name_; - int manageOptions_; Tcl_HashEntry *hashPtr_; + int refCount_; unsigned int flags; - int refCount; + int manageOptions_; public: Pen(); diff --git a/src/bltGrPenOp.C b/src/bltGrPenOp.C index d65c9e5..b749652 100644 --- a/src/bltGrPenOp.C +++ b/src/bltGrPenOp.C @@ -146,7 +146,7 @@ static int DeleteOp(Tcl_Interp* interp, Graph* graphPtr, return TCL_ERROR; penPtr->flags |= DELETE_PENDING; - if (penPtr->refCount == 0) + if (penPtr->refCount_ == 0) delete penPtr; return TCL_OK; @@ -227,8 +227,8 @@ int Blt_PenOp(Graph* graphPtr, Tcl_Interp* interp, void Blt_FreePen(Pen* penPtr) { if (penPtr != NULL) { - penPtr->refCount--; - if ((penPtr->refCount == 0) && (penPtr->flags & DELETE_PENDING)) + penPtr->refCount_--; + if ((penPtr->refCount_ == 0) && (penPtr->flags & DELETE_PENDING)) delete penPtr; } } diff --git a/src/bltGrXAxisOp.C b/src/bltGrXAxisOp.C index f9fbd46..385b455 100644 --- a/src/bltGrXAxisOp.C +++ b/src/bltGrXAxisOp.C @@ -78,7 +78,7 @@ static int UseOp(Tcl_Interp* interp, Axis* axisPtr, Tcl_Obj *listObjPtr; listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); - for (Blt_ChainLink link = Blt_Chain_FirstLink(chain); link != NULL; + for (Blt_ChainLink link = Blt_Chain_FirstLink(chain); link; link = Blt_Chain_NextLink(link)) { Axis* axisPtr = (Axis*)Blt_Chain_GetValue(link); Tcl_ListObjAppendElement(interp, listObjPtr, @@ -87,6 +87,7 @@ static int UseOp(Tcl_Interp* interp, Axis* axisPtr, Tcl_SetObjResult(interp, listObjPtr); return TCL_OK; } + ClassId classId; if ((lastMargin == MARGIN_BOTTOM) || (lastMargin == MARGIN_TOP)) classId = (gops->inverted) ? CID_AXIS_Y : CID_AXIS_X; @@ -95,25 +96,25 @@ static int UseOp(Tcl_Interp* interp, Axis* axisPtr, int axisObjc; Tcl_Obj **axisObjv; - if (Tcl_ListObjGetElements(interp, objv[3], &axisObjc, &axisObjv) - != TCL_OK) { + if (Tcl_ListObjGetElements(interp, objv[3], &axisObjc, &axisObjv) != TCL_OK) return TCL_ERROR; - } - for (Blt_ChainLink link = Blt_Chain_FirstLink(chain); link!= NULL; + + for (Blt_ChainLink link = Blt_Chain_FirstLink(chain); link; link = Blt_Chain_NextLink(link)) { Axis* axisPtr; axisPtr = (Axis*)Blt_Chain_GetValue(link); axisPtr->link = NULL; axisPtr->use_ =0; - /* Clear the axis type if it's not currently used.*/ + // Clear the axis type if it's not currently used if (axisPtr->refCount_ == 0) axisPtr->setClass(CID_NONE); } + Blt_Chain_Reset(chain); - for (int i=0; i<axisObjc; i++) { + for (int ii=0; ii<axisObjc; ii++) { Axis* axisPtr; - if (graphPtr->getAxis(axisObjv[i], &axisPtr) != TCL_OK) + if (graphPtr->getAxis(axisObjv[ii], &axisPtr) != TCL_OK) return TCL_ERROR; if (axisPtr->classId_ == CID_NONE) @@ -128,14 +129,16 @@ static int UseOp(Tcl_Interp* interp, Axis* axisPtr, /* Move the axis from the old margin's "use" list to the new. */ Blt_Chain_UnlinkLink(axisPtr->chain, axisPtr->link); Blt_Chain_AppendLink(chain, axisPtr->link); - } else { - axisPtr->link = Blt_Chain_Append(chain, axisPtr); } + else + axisPtr->link = Blt_Chain_Append(chain, axisPtr); + axisPtr->chain = chain; axisPtr->use_ =1; } + graphPtr->flags |= (GET_AXIS_GEOMETRY | LAYOUT_NEEDED | RESET_AXES); - /* When any axis changes, we need to layout the entire graph. */ + // When any axis changes, we need to layout the entire graph. graphPtr->flags |= (MAP_WORLD | REDRAW_WORLD); graphPtr->eventuallyRedraw(); diff --git a/src/bltGraph.C b/src/bltGraph.C index 4044fb7..46c2450 100644 --- a/src/bltGraph.C +++ b/src/bltGraph.C @@ -1064,11 +1064,8 @@ void Graph::destroyMarkers() { Tcl_HashSearch iter; for (Tcl_HashEntry* hPtr=Tcl_FirstHashEntry(&markers_.table, &iter); - hPtr; hPtr = Tcl_NextHashEntry(&iter)) { + hPtr; hPtr=Tcl_NextHashEntry(&iter)) { Marker* markerPtr = (Marker*)Tcl_GetHashValue(hPtr); - - // Dereferencing the pointer to the hash table prevents the hash table - // entry from being automatically deleted. delete markerPtr; } Tcl_DeleteHashTable(&markers_.table); |