/* Numeric window class functions. They need not to be reenterable but MUST be reusable. */ #include "common.h" #if LINKIN #include "large.h" #include "tsprintf.h" #undef MemNew #undef MemMore #undef MemFree #undef StringSave #define MemNew _MemNew #define MemMore _MemMore #define MemFree _MemFree #define StringSave _StringSave #else /* LINKIN */ #include "corefunc.h" #include "inter.h" #endif /* LINKIN */ #define GET_CLASS_TABLE num_GetClassTable /* Unique name of the 'Get Class Table' function */ #include "window.h" /* GetClassTable is generated by window.h */ /* Texts */ Local(CharPtr) Text[]={ "Compute{", "Forward", "Backward", "Extend", "Window{", "Redraw diagram", "Redraw curve", "Clear", "Layout", "Hide", "Help{", "This window", "Search", "-", "}", "Waiting for attributes setting", "Layout of numeric window", "Options", "Precision", "Right-justify numbers", "Sample of window", "Window title", NULL }; enum { COMPUTE_M, FORWARD_I, BACKWARD_I, EXTEND_I, WINDOW_M, REDRAWD_I, REDRAWC_I, CLEAR_I, LAYOUT_I, /* Layout */ HIDE_I, HELP_M, HELP_I, SEARCH_I, SEPARATOR_I, DUMMYEND_I, WAITATTR_C, /* Waiting for attributes setting */ BOX_TITLE, /* Layout of numeric window */ OPTIONS_T, /* Options */ PRECISION_P, /* Precision */ JUSTRIGHT_B, /* justify right */ SAMPLE_WIN, /* Sample of window */ WINTITLE_P, /* Window title */ _L_A_S_T_ }; #define DEFAULT_TITLE "Numeric window" /* default title of window */ #define HK_NUMWIN "kh_NumWin" /* Help key for the window */ #define HK_LAYOUTWIN "kh_NumWinLayout" /* Help key for layout dialog box */ /* Settings file section name */ #define SECTION "Window_Numeric" /* AutonomousPanel increases width and height. We must neutralize this. */ #define W_AUTOPAN (vScrollBarWidth+8) #define H_AUTOPAN (8) /* Private data structure which describes window's controls */ typedef struct { /* Description of controls */ PairPtr PNTR Selection; /* Selected names (in filter format) */ Int2 ClassNum; /* Number of visual classes (==DIM(*Selected) */ int Precision; /* of numbers */ Boolean JustRight; /* justification */ /* Work area */ DoC Numeric; BaR Bar; Int2 Offset; /* vertical */ Int2 twidth,vwidth; /* Width of titles and width if values */ Uint2Ptr RealIds; /* Real ids of relevant classes at creation/last edition */ Int2Ptr RealSubs; /* Real subscripts of relevant classes */ FloatHiPtr PNTR PrevVals; } NumData, PNTR NumDataPtr; #if _WIN #pragma argsused #endif Local(Boolean) AlwaysStatus(Int2 indx) { return TRUE; } Callback(void) lRedrawD(Int2 indx); Callback(void) lRedrawC(Int2 indx); Callback(void) lClear(Int2 indx); Callback(void) lLayout(Int2 indx); Callback(void) lHelp(Int2 indx); Callback(void) lHelpSearch(Int2 indx); /* Menu */ Local(MenuItem) TableMenu[]={ {COMPUTE_M, NULL, NULL}, { FORWARD_I, NULL, NULL}, { BACKWARD_I, NULL, NULL}, { SEPARATOR_I, NULL, NULL}, { EXTEND_I, NULL, NULL}, { DUMMYEND_I, NULL, NULL}, {WINDOW_M, NULL, NULL}, { REDRAWD_I, lRedrawD, NULL,0,MNFL_ACTIVEINPAUSE}, { REDRAWC_I, lRedrawC, NULL,0,MNFL_ACTIVEINPAUSE}, { SEPARATOR_I, NULL, NULL}, { CLEAR_I, lClear, AlwaysStatus,0,MNFL_ACTIVEINPAUSE}, { SEPARATOR_I, NULL, NULL}, { LAYOUT_I, lLayout, AlwaysStatus}, { SEPARATOR_I, NULL, NULL}, { HIDE_I, NULL, AlwaysStatus,0,MNFL_ACTIVEINPAUSE}, { DUMMYEND_I, NULL, NULL}, {HELP_M, NULL, NULL}, { HELP_I, lHelp, AlwaysStatus,0,MNFL_ACTIVEINPAUSE}, { SEPARATOR_I, NULL, NULL}, { SEARCH_I, lHelpSearch, AlwaysStatus,0,MNFL_ACTIVEINPAUSE}, { DUMMYEND_I, NULL, NULL} }; Local(ParData) ParFmt={FALSE,FALSE,FALSE,FALSE,FALSE,0,0}; Local(ColData) ColFmt[2]={ {0,0,0,0,NULL,'l',FALSE,FALSE,FALSE,FALSE,FALSE}, {0,0,0,0,NULL,'r',FALSE,FALSE,FALSE,FALSE,TRUE}, }; Local(ColData) ColFmtT[1]={ {0,0,0,0,NULL,'c',FALSE,FALSE,TRUE,FALSE,TRUE}, }; /* Computes the max width of - real number with precision prec (prec>0), or - int number with prec digits (prec<0). */ Local(Char) cotest[2]="?"; Local(Char) cochars[]="0123456789.+-e"; Local(int) NumberWidth(int prec) { int i,w,maxw; for (i=maxw=0; imaxw) maxw=w; } return maxw*(prec<0 ? -prec : prec+6); } /* -----------------------------------*/ /* Local functions for CreateControls */ typedef enum { MaxWidthOfNames, /* 0 - calculate max width of names */ AppendBlankItems, /* 1 - append items with blank value field */ ClearValueColumns, /* 2 - clear values fields */ UpdateValueColumnsCond, /* 3 - update values fields (conditionally) */ UpdateValueColumnsUncond /* 5 - update values fields (unconditionally) */ } NameOper; /* Kind of processing of visible names */ Local(NameOper) Oper; Local(WinComDataPtr) Wcd; Local(Int2) Class; /* relative class number (irrelevant classes are ignored) */ Local(Int2) ClassA; /* absolute class number (counting irrelevant) */ Local(Int2) Var; Local(Int2) Item; Local(Int2) MaxWidth; Local(Int2) MaxWidthT; Local(Int2) PairsN,PairsNo; Local(PairPtr) PairsP; /* EnumVariables callback */ #if _WIN #pragma argsused #endif Callback(void) VarCallback(LisT dummy, CharPtr name, Int2 dim) { NumDataPtr nd=(NumDataPtr)Wcd->Private; FloatHiPtr v,vold; RecT r; Int2 i=0; Boolean replace; Char buf[200]; if (PairsN<0) return; while (TRUE) { if (Var>=PairsP[PairsN].from) if (Var>=PairsP[PairsN].from+ABS(PairsP[PairsN].num)) if (PairsP[PairsN].num>0) { PairsNo+=PairsP[PairsN].num; PairsN++; continue; } else { PairsN=-1; break; } else { if (dim>1) sprintf(buf,"%s[%i]",name,(int)i); else sprintf(buf,"%s",name); switch (Oper) { case MaxWidthOfNames: if (StringWidth(buf)>MaxWidth) MaxWidth=StringWidth(buf); break; case AppendBlankItems: StrCat(buf,"\t"); AppendText(nd->Numeric,buf,&ParFmt,ColFmt,SystemFont); break; case ClearValueColumns: case UpdateValueColumnsCond: case UpdateValueColumnsUncond: /* Replace item's text */ ColFmt[0].pixWidth=nd->twidth; ColFmt[1].pixWidth=nd->vwidth; StrCat(buf,"\t"); replace=TRUE; if (Oper>=UpdateValueColumnsCond) { v=(FloatHiPtr)(*IndirectValues[ClassA]+Var); vold=nd->PrevVals[Class]+PairsNo+Var-PairsP[PairsN].from; if ((!(Wcd->flags&WFL_G1) || curveCurNum>1) && *v==*vold && Oper==UpdateValueColumnsCond) replace=FALSE; else { if (*v==NOUPDATE) replace=FALSE; else sprintf(buf+StrLen(buf),"% #.*lg",nd->Precision,*v); } *vold=*v; } if (replace) { ColFmt[1].just=nd->JustRight ? 'r' : 'l'; ReplaceText(nd->Numeric,Item,buf,&ParFmt,ColFmt,SystemFont); /* Invalidate column's rect */ if (ItemIsVisible(nd->Numeric,Item,&r.top,&r.bottom,NULL)) { GetColParams(nd->Numeric,Item,2,&r.left,&r.right,NULL,NULL); r.right+=r.left; /* GetColItem returns width */ InvalRect(&r); } } Item++; break; } } if (++i>=dim) break; else Var++; } Var++; } Local(void) EnumSelected(void) { NumDataPtr nd=(NumDataPtr)Wcd->Private; CharPtr clname; Int2 i,ri; Select(nd->Numeric); for (i=0; iClassNum; i++) if (nd->Selection[i]) { ri=nd->RealSubs[i]; switch (Oper) { case MaxWidthOfNames: GetClassNameAndId(ri,&clname,NULL); if (StringWidth(clname)+sysCharWidth>MaxWidthT) MaxWidthT=StringWidth(clname)+sysCharWidth; break; case AppendBlankItems: GetClassNameAndId(ri,&clname,NULL); ParFmt.minHeight+=2; AppendText(nd->Numeric,clname,&ParFmt,ColFmtT,SystemFont); ParFmt.minHeight-=2; break; case ClearValueColumns: case UpdateValueColumnsCond: case UpdateValueColumnsUncond: Item++; /* this item is class name */ break; } PairsP=nd->Selection[i]; Class=i; ClassA=ri; PairsN=PairsNo=0; Var=0; EnumVariables(NULL,ClassA,VarCallback); } } /* Enumerate relevant classes and their variables and process them according to the oper parameter */ Local(void) EnumRelNames(WinComDataPtr wcd, NameOper oper) { Wcd=wcd; Oper=oper; Class=0; switch (Oper) { case MaxWidthOfNames: MaxWidth=MaxWidthT=0; SelectFont(SystemFont); break; case AppendBlankItems: break; case ClearValueColumns: case UpdateValueColumnsCond: case UpdateValueColumnsUncond: Item=1; break; } EnumSelected(); switch (Oper) { case MaxWidthOfNames: break; case AppendBlankItems: break; case ClearValueColumns: case UpdateValueColumnsCond: case UpdateValueColumnsUncond: Update(); break; } } Local(void) BuildWorkArea(WinComDataPtr wcd) { NumDataPtr nd=(NumDataPtr)wcd->Private; Int2 i,j,n; PairPtr p; Uint2 realId; nd->RealSubs=MemNew(ARRAYSIZE(Int2,nd->ClassNum)); nd->PrevVals=MemNew(ARRAYSIZE(FloatHiPtr,nd->ClassNum)); for (i=0; iClassNum; i++) { for (j=0; TRUE; j++) if (GetClassNameAndId(j,NULL,&realId)) { if (realId==nd->RealIds[i]) { nd->RealSubs[i]=j; break; } } else break; /* no more classes */ n=j=0; p=nd->Selection[i]; if (p) do { n+=ABS(p[j].num); } while (p[j++].num>0); nd->PrevVals[i]=MemNew(ARRAYSIZE(FloatHi,n)); } } Local(void) FreeWorkArea(WinComDataPtr wcd) { NumDataPtr nd=(NumDataPtr)wcd->Private; Int2 i; nd->RealSubs=MemFree(nd->RealSubs); if (nd->PrevVals) { for (i=0; iClassNum; i++) MemFree(nd->PrevVals[i]); nd->PrevVals=MemFree(nd->PrevVals); } } /* Local functions for CreateControls */ /*------------------------------------*/ /* EnumClasses callback */ #if _WIN #pragma argsused #endif Callback(void) ClassCallback(LisT dummy, CharPtr title, CharPtr name, Boolean defvis, Uint2 realId) { NumDataPtr nd=(NumDataPtr)Wcd->Private; PairPtr p=NULL; Int2Ptr cdp; cdp=GetClassDim(name); if (*cdp>0) { if (defvis) { /* visible by default */ p=MemNew(sizeof(Pair)); p->from=0; p->num=-*cdp; } } nd->Selection[Class]=p; nd->RealIds[Class]=realId; Class++; } ClassMember(void) BuildDefaultDescription(WinComDataPtr wcd) { NumDataPtr nd; CharPtr p; Int2 i; Char cj; wcd->WinTitle=StringSave(DEFAULT_TITLE); if (!wcd->Private) wcd->Private=MemNew(sizeof(NumData)); nd=(NumDataPtr)wcd->Private; nd->ClassNum=0; for (i=0; GetNthRelevantClass(i++)>=0; nd->ClassNum++); nd->Selection=MemNew(ARRAYSIZE(PairPtr,nd->ClassNum)); nd->RealIds=MemNew(ARRAYSIZE(Uint2,nd->ClassNum)); Class=0; Wcd=wcd; EnumClasses(0,ClassCallback); /* build default selection */ p=GetParamString(SECTION,"OPTIONS"); sscanf(p,"%i,%c",&nd->Precision,&cj); nd->JustRight=cj=='t'; } ClassMember(void) ReadDescription(WinComDataPtr wcd, DataLibPtr arch){ NumDataPtr nd; PairPtr pp; Int2 i; if (!wcd->Private) wcd->Private=MemNew(sizeof(NumData)); nd=(NumDataPtr)wcd->Private; DataLibRead(arch,(CharPtr)&nd->Offset,sizeof(nd->Offset)); DataLibRead(arch,(CharPtr)&nd->ClassNum,sizeof(nd->ClassNum)); nd->Selection=MemNew(ARRAYSIZE(PairPtr,nd->ClassNum)); for (i=0; iClassNum; i++) { pp=(PairPtr)DataLibReadVRecord(arch,NULL); if (pp && pp[0].num==0) pp=MemFree(pp); nd->Selection[i]=pp; } nd->RealIds=MemNew(ARRAYSIZE(Uint2,nd->ClassNum)); DataLibRead(arch,(CharPtr)nd->RealIds,ARRAYSIZE(Uint2,nd->ClassNum)); DataLibRead(arch,(CharPtr)&nd->Precision,sizeof(nd->Precision)); DataLibRead(arch,(CharPtr)&nd->JustRight,sizeof(nd->JustRight)); } ClassMember(void) WriteDescription(WinComDataPtr wcd, DataLibPtr arch) { NumDataPtr nd=(NumDataPtr)wcd->Private; PairPtr pp; Int2 i,j; GetScrlParams(nd->Numeric,&nd->Offset,NULL,NULL); DataLibWrite(arch,(CharPtr)&nd->Offset,sizeof(nd->Offset)); DataLibWrite(arch,(CharPtr)&nd->ClassNum,sizeof(nd->ClassNum)); for (i=0; iClassNum; i++) { pp=nd->Selection[i]; j=0; if (pp) for (j=0; pp[j++].num>0; ); DataLibWriteVRecord(arch,NULL,(CharPtr)pp,ARRAYSIZE(Pair,j)); MemFree(pp); } MemFree(nd->Selection); DataLibWrite(arch,(CharPtr)nd->RealIds,ARRAYSIZE(Uint2,nd->ClassNum)); MemFree(nd->RealIds); DataLibWrite(arch,(CharPtr)&nd->Precision,sizeof(nd->Precision)); DataLibWrite(arch,(CharPtr)&nd->JustRight,sizeof(nd->JustRight)); } ClassMember(void) CreateControls(WinComDataPtr wcd) { NumDataPtr nd=(NumDataPtr)wcd->Private; WindoW win; RecT r,rd; Int2 i,j,h,twidth,vwidth,items,menubarw,dw,dh; win=wcd->Win; h=wcd->Height; if (wcd->flags&WFL_RESIZE) { GetPosition(nd->Numeric,&r); r.right=r.left+wcd->Width; r.bottom=r.top+h; SetPosition(nd->Numeric,&r); SetValue(nd->Bar,0); /* to avoid a message about scroll slider under Motif */ AdjustDocScroll(nd->Numeric); UpdateDocument(nd->Numeric,1,30000); GetPosition(nd->Numeric,&r); UpsetRect(&r,0,0,-2*(WHM+1),-2*(WVM+1)); /* hide window's margins and panel's frame */ SetPosition(nd->Numeric,&r); } else { BuildWorkArea(wcd); /* Determine natural width of DocumentPanel */ EnumRelNames(wcd,MaxWidthOfNames); twidth=MaxWidth+(sysCharWidth/2); vwidth=NumberWidth(nd->Precision); if (MaxWidthT>twidth+vwidth) vwidth=MaxWidthT-twidth; /* Create the DocumentPanel */ nd->Numeric=DocumentPanel(win,wcd->Width-W_AUTOPAN,h-H_AUTOPAN); nd->Bar=GetSlateVScrollBar((SlatE)nd->Numeric); SelectFont(SystemFont); ParFmt.minHeight=FontHeight()-1; ColFmtT[0].pixWidth=twidth+vwidth; ColFmtT[0].font=SystemFont; ColFmt[0].pixWidth=twidth; ColFmt[0].font=SystemFont; ColFmt[1].pixWidth=vwidth; ColFmt[1].font=SystemFont; /* Create items in it */ nd->twidth=twidth; nd->vwidth=vwidth; EnumRelNames(wcd,AppendBlankItems); SetValue(nd->Bar,nd->Offset); /* Adjust window's dimensions */ RealizeWindow(win); Hide(nd->Numeric); GetPosition(win,&r); GetPosition(nd->Numeric,&rd); /* - width */ if ((j=twidth+vwidth+W_AUTOPAN)Width) { for (menubarw=vScrollBarWidth,i=0; iMenuDesc.Num; i++) if (wcd->MenuDesc.Menu[i].Kind==MENU_PULLDOWN) menubarw+=StringWidth(Text[wcd->MenuDesc.Menu[i].Title])+sysCharWidth; if (j>menubarw) dw=wcd->Width-j; else { dw=wcd->Width-menubarw; Reset(nd->Numeric); ColFmtT[0].pixWidth+=menubarw-j; ColFmt[1].pixWidth+=menubarw-j; nd->vwidth+=menubarw-j; EnumRelNames(wcd,AppendBlankItems); } } else dw=wcd->Width-j; rd.right-=dw; r.right-=dw; /* - height */ /* extend up to the bottom of the screen */ dh=r.bottom-screenRect.bottom; rd.bottom-=dh; r.bottom-=dh; SetPosition(nd->Numeric,&rd); UpdateDocument(nd->Numeric,1,30000); /* and cut excessive empty lines */ GetDocParams(nd->Numeric,&items,NULL); if (ItemIsVisible(nd->Numeric,items,NULL,&h,NULL)) { dh=rd.bottom-rd.top-(h+H_AUTOPAN); rd.bottom-=dh; r.bottom-=dh; } SetPosition(win,&r); /* Window first! (NT) */ SetPosition(nd->Numeric,&rd); wcd->Width=(r.right-r.left+1)-wcd->BorderWidth; wcd->Height=(r.bottom-r.top+1)-wcd->BorderHeight; SimpleFunctions(wcd); /* WFL_GDIM1 */ GetPosition(nd->Numeric,&r); InsetRect(&r,-(WHM+1),-(WVM+1)); /* hide window's margins and panel's frame */ SetPosition(nd->Numeric,&r); } Show(nd->Numeric); } ClassMember(void) RemoveControls(WinComDataPtr wcd) { NumDataPtr nd=(NumDataPtr)wcd->Private; if (wcd->flags&WFL_RESIZE) { Hide(nd->Numeric); } else { nd->Numeric=Remove(nd->Numeric); FreeWorkArea(wcd); } } #if _WIN #pragma argsused #endif ClassMember(void) ManageControls(WinComDataPtr wcd, Boolean enable) { /* Nothing. Status function for this window is always "1" */ } ClassMember(void) BuildMenu(WinComDataPtr wcd) { MenuItemPtr ip; Int2 i; wcd->MenuDesc.Menu=ip=MemNew(sizeof(TableMenu)); wcd->MenuDesc.Num=DIM(TableMenu); wcd->MenuDesc.Lock=0; wcd->MenuDesc.Texts=Text; MemCopy(ip,TableMenu,sizeof(TableMenu)); for (i=0; iMenuDesc.Num; i++) { if (ip[i].Title==FORWARD_I) { ip[i].Action=Forward; ip[i].EnableDisable=FBStatus; continue; } if (ip[i].Title==BACKWARD_I) { ip[i].Action=Backward; ip[i].EnableDisable=FBStatus; continue; } if (ip[i].Title==EXTEND_I) { ip[i].Action=Extend; ip[i].EnableDisable=ExtendStatus; continue; } if (ip[i].Title==REDRAWD_I) { /*** ip[i].Action=RedrawDiagram;***/ ip[i].EnableDisable=RedrawDStatus; continue; } if (ip[i].Title==REDRAWC_I) { /*** ip[i].Action=RedrawCurve;***/ ip[i].EnableDisable=RedrawCStatus; continue; } if (ip[i].Title==HIDE_I) { ip[i].Action=HideWin; continue; } } } ClassMember(void) NewInitPoint(WinComDataPtr wcd) { ClearWindow(wcd); } ClassMember(void) ClearWindow(WinComDataPtr wcd) { EnumRelNames(wcd,ClearValueColumns); } ClassMember(Boolean) SimpleFunctions(WinComDataPtr wcd) { NumDataPtr nd=(NumDataPtr)wcd->Private; CharPtr name; Int2 i; wcd->flags|=WFL_GDIM1; for (i=0; iClassNum; i++) if (nd->Selection[i]) { GetNameAndDim(i,1,&name,NULL); if (!GdimEq1(name)) { wcd->flags&=~WFL_GDIM1; break; } } return TRUE; /* always nothing to compile */ } #if _WIN #pragma argsused #endif ClassMember(void) PutFunctions(WinComDataPtr wcd, FILE PNTR Source, Int2Ptr LineNum) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) SetFunctions(WinComDataPtr wcd, LibHandle hWinLib) { NumDataPtr nd=(NumDataPtr)wcd->Private; /* Coordinate selections with current set of classes (classes nomenclature and dim might vary due to change of functions) */ PairPtr p; Int2 i,j,d; Boolean recreate=FALSE; for (i=0; iClassNum; ) { d=IsClassRelevant(nd->RealIds[i]); if (d>=0) { p=nd->Selection[i]; j=0; if (p) do { if (p[j].from>=d) { if (j) { p[j-1].num=-p[j-1].num; /* make it the last */ nd->Selection[i]=p=MemMore(p,ARRAYSIZE(Pair,j)); } else { nd->Selection[i]=MemFree(p); } recreate=TRUE; break; } if (p[j].from+ABS(p[j].num)>d) { if (p[j].num>0) { nd->Selection[i]=p=MemMore(p,ARRAYSIZE(Pair,j+1)); } p[j].num=-(d-p[j].from); recreate=TRUE; break; } } while (p[j++].num>0); i++; } else { nd->ClassNum--; MemMove(nd->RealIds+i,nd->RealIds+i+1, ARRAYSIZE(Uint2,nd->ClassNum-i)); nd->RealIds=MemMore(nd->RealIds, ARRAYSIZE(Uint2,nd->ClassNum)); MemFree(nd->Selection[i]); MemMove(nd->Selection+i,nd->Selection+i+1, ARRAYSIZE(PairPtr,nd->ClassNum-i)); nd->Selection=MemMore(nd->Selection, ARRAYSIZE(PairPtr,nd->ClassNum)); recreate=TRUE; } } if (recreate) { /* Recreate controls */ RemoveControls(wcd); RecreateWindow(wcd); /* Rebuild all (WFL_FUNC_EDITED is reset!) */ } } #define IMPEXP_FORMATH " classnum=%i\n selection\n" #define IMPEXP_FORMATHI " classnum=%i\n %*[a-z]\n" #define IMPEXP_FORMAT1 " %i" #define IMPEXP_FORMAT2 " [%i,%i]" #define IMPEXP_FORMAT3 " realids=" #define IMPEXP_FORMAT4 "%i " #define IMPEXP_FORMAT5 " prec=%i, just=%c\n" #define IMPEXP_FORMAT5I " prec=%i, %*[a-z]=%c\n" ClassMember(void) ExportDescription(WinComDataPtr wcd, DataLibPtr arch, FILE PNTR out) { NumDataPtr nd; PairPtr pp; Int2 i,j,k; /* Read description */ ReadDescription(wcd,arch); nd=(NumDataPtr)wcd->Private; /* Print */ fprintf(out,IMPEXP_FORMATH,nd->ClassNum); for (i=0; iClassNum; i++) { pp=nd->Selection[i]; if (pp) for (k=0; pp[k++].num>0; ); else k=0; fprintf(out,IMPEXP_FORMAT1,(int)k); for (j=0; jClassNum; i++) { fprintf(out,IMPEXP_FORMAT4,(int)nd->RealIds[i]); } fprintf(out,"\n"); fprintf(out,IMPEXP_FORMAT5, nd->Precision, nd->JustRight ? 't' : 'f'); /* Free memory (don't write) */ WriteDescription(wcd,NULL); MemFree(nd); } ClassMember(void) ImportDescription(WinComDataPtr wcd, DataLibPtr arch, FILE PNTR in) { NumData nd; Int2 i,j; int k,f,n; unsigned int u; Char cj; MemFill(&nd,0,sizeof(nd)); wcd->Private=&nd; fscanf(in,IMPEXP_FORMATHI,&n); nd.ClassNum=(Int2)n; nd.Selection=MemNew(ARRAYSIZE(Pair,nd.ClassNum)); for (i=0; iWin); ClearWindow(wcd); } #if _WIN #pragma argsused #endif ClassMember(void) GTerm(WinComDataPtr wcd) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) MInit(WinComDataPtr wcd) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) MTerm(WinComDataPtr wcd) { /* nothing */ } ClassMember(void) MProcess(WinComDataPtr wcd) { EnumRelNames(wcd,UpdateValueColumnsCond); } #if _WIN #pragma argsused #endif ClassMember(void) hcPen(WinComDataPtr wcd, DrawAttrPtr attr) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) hcString(WinComDataPtr wcd, CharPtr str, float PNTR data) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) hcPaintOval(WinComDataPtr wcd, RectPtr r) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) hcFrameOval(WinComDataPtr wcd, RectPtr r) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) hcPaintPoly(WinComDataPtr wcd, Int2 num, PointPtr poly) { /* nothing */ } #if _WIN #pragma argsused #endif ClassMember(void) hcFramePoly(WinComDataPtr wcd, Int2 num, PointPtr poly) { /* nothing */ } /******************/ /* Menu callbacks */ #define GetComDataI ((WinComDataPtr)GetWindowExtra(CurrentWindow())) /*---------------------------------------*/ /* Menu callback: Redraw current diagram */ #if _WIN #pragma argsused #endif Callback(void) lRedrawD(Int2 indx) { WinComDataPtr wcd=GetComDataI; DeactivateWindows(wcd); RedrawDiagram(0); ActivateWindows(); } /*-------------------------------------*/ /* Menu callback: Redraw current curve */ #if _WIN #pragma argsused #endif Callback(void) lRedrawC(Int2 indx) { WinComDataPtr wcd=GetComDataI; DeactivateWindows(wcd); RedrawCurve(0); ActivateWindows(); } /*---------------------------------*/ /* Menu callback: Clear the window */ #if _WIN #pragma argsused #endif Callback(void) lClear(Int2 indx) { ClearWindow(GetComDataI); } /*----------------------------------*/ /* Menu callback: Layout dialog box */ typedef struct { WinComDataPtr Com; TexT Title; /* WinTitle */ #if MYSWITCH Switch Precision; /* of numbers in column(s) */ #else SwitcH Precision; /* of numbers in column(s) */ #endif ButtoN JustRight; Int2 ClassNum; /* work copy */ PairPtr PNTR Selection; /* work copy */ Uint2Ptr RealIds; /* work copy */ PaneL Sample; /* of window's layout */ Boolean Recompile; } LayoutData, PNTR LayoutDataPtr; Local(LayoutDataPtr) Layout; #define GetLayoutDataC(h) ((LayoutDataPtr)GetWindowExtra(ParentWindow(h))) /* Cancel callback */ Callback(void) LayoutCancel(ButtoN bt) { LayoutDataPtr layout=GetLayoutDataC(bt); WinComDataPtr wcd=layout->Com; Int2 i; if (layout->Selection) { for (i=0; iClassNum; i++) MemFree(layout->Selection[i]); MemFree(layout->Selection); } MemFree(layout->RealIds); PopContext(); MemFree(layout); Select(wcd->Win); Remove(ParentWindow(bt)); UnlockMenus(); } /* Ok callback */ Callback(void) LayoutOk(ButtoN bt) { LayoutDataPtr layout=GetLayoutDataC(bt); WinComDataPtr wcd=layout->Com; NumDataPtr nd=(NumDataPtr)wcd->Private; CharPtr p; Int2 i; /* Remove old controls (they may depend on old options) */ RemoveControls(wcd); /* Save selections from the last-edited level of the list */ MultiNamesList(NULL,NULL); /* Title */ GetTitleAndSave(layout->Title,&wcd->WinTitle); /* Selection */ if (nd->Selection) { for (i=0; iClassNum; i++) MemFree(nd->Selection[i]); MemFree(nd->Selection); } MemFree(nd->RealIds); nd->ClassNum=layout->ClassNum; nd->Selection=layout->Selection; nd->RealIds=layout->RealIds; layout->Selection=NULL; layout->RealIds=NULL; /* Precision */ #if MYSWITCH nd->Precision=SwitchGetValue(layout->Precision); #else nd->Precision=GetValue(layout->Precision); #endif /* Toggles */ nd->JustRight=GetStatus(layout->JustRight); /* Store as default options */ p=MemNew(100); sprintf(p,"%i,%c",nd->Precision, nd->JustRight ? 't' : 'f'); SetParam(SECTION,"OPTIONS",p); MemFree(p); /* Rebuild all (WFL_FUNC_EDITED is reset!) */ RecreateWindow(wcd); /* Clean up */ LayoutCancel(bt); } /* Help callback */ #if _WIN #pragma argsused #endif Callback(void) LayoutHelp(ButtoN bt) { Help(NULL); } /* Sample callback */ Callback(void) DrawSample(PaneL p) { LayoutDataPtr layout=GetLayoutDataC(p); FloatLo x; RecT r; int prec; Int2 i,lh; Boolean just; Select(p); SelectFont(SystemFont); lh=FontHeight(); GetPosition(p,&r); ClipRect(&r); InvertColors(); PaintRect(&r); InvertColors(); #if MYSWITCH prec=(int)SwitchGetValue(layout->Precision); #else prec=(int)GetValue(layout->Precision); #endif just=GetStatus(layout->JustRight); for (i=0,x=0.12345678910111213; i<10; i++, x+=0.1111111111111111) { MoveTo(r.left,r.top+=lh); PaintText(" %c %s% #.*g","xyzuvwabcd"[i],just ? " " : "",prec,x); } } /* Precision callback */ #if _WIN #pragma argsused #endif #if MYSWITCH Callback(void) PrecisionProc(GraphiC sw, Int2 new, Int2 old) { #else Callback(void) PrecisionProc(SwitcH sw, Int2 new, Int2 old) { #endif LayoutDataPtr layout=GetLayoutDataC(sw); Redraw(layout->Sample); } /* Align and Title callbacks */ Callback(void) ToggleProc(ButtoN bt) { LayoutDataPtr layout=GetLayoutDataC(bt); Redraw(layout->Sample); } #if _WIN #pragma argsused #endif Callback(void) CollectClassData(LisT dummy, CharPtr title, CharPtr name, Boolean defvis, Uint2 realId) { WinComDataPtr wcd=Layout->Com; NumDataPtr nd=(NumDataPtr)wcd->Private; PairPtr pp; Int2 n=Layout->ClassNum,i,j,m; if (Layout->ClassNum++) { Layout->Selection=MemMore(Layout->Selection,ARRAYSIZE(PairPtr,Layout->ClassNum)); Layout->RealIds=MemMore(Layout->RealIds,ARRAYSIZE(Uint2,Layout->ClassNum)); } else { Layout->Selection=MemNew(ARRAYSIZE(PairPtr,Layout->ClassNum)); Layout->RealIds=MemNew(ARRAYSIZE(Uint2,Layout->ClassNum)); } Layout->RealIds[n]=realId; Layout->Selection[n]=NULL; for (i=0; iClassNum; i++) if (nd->RealIds[i]==realId) { pp=nd->Selection[i]; if (pp) { for (j=m=0; m+=ABS(pp[j].num), pp[j++].num>0; ); Layout->Selection[n]=(PairPtr)MemNew(ARRAYSIZE(Pair,j)); MemCopy(Layout->Selection[n],pp,ARRAYSIZE(Pair,j)); } return; } if (defvis) { pp=Layout->Selection[n]=(PairPtr)MemNew(ARRAYSIZE(Pair,1)); /* pp->from is already 0 */ pp->num=-*GetClassDim(name); } } /* Menu callback */ #if _WIN #pragma argsused #endif Callback(void) lLayout(Int2 indx) { WinComDataPtr wcd=GetComDataI; NumDataPtr nd=(NumDataPtr)wcd->Private; LayoutDataPtr layout; WindoW db; GrouP g,gT,gs,go,gw; GrouP MainGroup; RecT r,rp,rs,rg; LisT list; Int2 h; layout=MemNew(sizeof(LayoutData)); layout->Com=wcd; LockMenus(); /* will not wait */ PushContext(HK_LAYOUTWIN,NULL,Text[WAITATTR_C]); db=FixedWindow(-50,-50,-sysCharWidth,-sysLineHeight,Text[BOX_TITLE],NULL); SetWindowExtra(db,layout,NULL); MainGroup=InitLargeWindow(db); SetGroupSpacing(MainGroup,0,sysLineHeight/2); SetGroupMargins(MainGroup,0,0); gT=CreateHiddenGroup(MainGroup,2,0,1); StaticPrompt(gT,Text[WINTITLE_P],0,dialogTextHeight,NULL,'l'); layout->Title=DialogText(gT,wcd->WinTitle,1,NULL); g=CreateHiddenGroup(MainGroup,2,0,1); /* Recreate list of visible attributes and preserve selection data. The list might be changed due to manipulation of point-curve type */ layout->ClassNum=0; Layout=layout; EnumClasses(0,CollectClassData); /* Create list of visible variable names */ list=MultiNamesList(g,layout->Selection); /* Options */ go=CreateNormalGroup(MainGroup,2,0,Text[OPTIONS_T]); gw=CreateHiddenGroup(go,2,0,0); #if MYSWITCH StaticPrompt(gw,Text[PRECISION_P],0,SwitchHeight(),NULL,'l'); layout->Precision=SwitchCreate(gw,DBL_DIG,PrecisionProc); SwitchSetValue(layout->Precision,nd->Precision); #else StaticPrompt(gw,Text[PRECISION_P],0,dialogTextHeight,NULL,'l'); layout->Precision=LeftRightSwitch(gw,TRUE,PrecisionProc); SetSwitchParams(layout->Precision,nd->Precision,DBL_DIG); #endif layout->JustRight=CheckBox(go,Text[JUSTRIGHT_B],ToggleProc); SetStatus(layout->JustRight,nd->JustRight); /* Sample */ GetPosition(g,&r); gs=CreateNormalGroup(MainGroup,0,0,Text[SAMPLE_WIN]); h=((r.bottom-r.top)>>1)/sysLineHeight*sysLineHeight; layout->Sample=SimplePanel(gs,1,h,DrawSample); /* extend panel to the right */ GetPosition(list,&rp); GetPosition(Parent(list),&rs); rs.right-=rp.right; /* margins in a group */ GetPosition(layout->Sample,&rp); GetPosition(Parent(layout->Sample),&rg); rp.right=rg.right-rs.right; SetPosition(layout->Sample,&rp); AlignObjects(ALIGN_RIGHT,(HANDLE)go,(HANDLE)gs,(HANDLE)layout->Title,NULL); /* Create terminate buttons */ TerminalButtons((WindoW)MainGroup,MainGroup,LayoutOk,LayoutCancel,LayoutHelp); /* Show and activate */ ShowLargeWindow(MainGroup); } /*----------------*/ /* Help callbacks */ #if _WIN #pragma argsused #endif Callback(void) lHelp(Int2 indx) { Help(HK_NUMWIN); } #if _WIN #pragma argsused #endif Callback(void) lHelpSearch(Int2 indx) { HelpSearch(HK_NUMWIN); }