/* Interface library-kernel for vibrant and kernel functions */ #include "common.h" #include "large.h" #include "datalib0.h" #include "visual.h" #define KERNEL #include "inter.h" #undef KERNEL #define __WIN _WIN && !defined(WIN32) #if __WIN typedef enum { CB_WINCLOSE, CB_WINRESIZE, CB_WINCLEANUP, CB_GROUP, CB_DIALOG, CB_LIST, CB_BUTTON, CB_DRAW, CB_RELEASE, CB_CLICK, CB_DRAG, CB_HOLD, CB_SWITCH } Kind; typedef EntryPtr(void,CallBackPtr,()); typedef struct { CallBackPtr callback; Handle object; Kind kind; } CbDesc, PNTR CbDescPtr; typedef struct _WinDesc { WindoW win; CbDescPtr list; /* of callbacks */ Int2 listN; } WinDesc, PNTR WinDescPtr; Local(WinDescPtr) window=NULL; Local(Int2) windowN; Local(void) AddCallback(Kind kind, Handle object, CallBackPtr callback) { WindoW win; CbDescPtr cbp; Int2 i; if (callback==NULL) return; win=ParentWindow(object); for (i=0; iobject=object; cbp->kind=kind; cbp->callback=callback; } Local(CbDescPtr) LookupCallback(Kind kind, Handle object) { WindoW win; CbDescPtr cbp; Int2 i,j,n; win=ParentWindow(object); for (i=0; ikind==kind && cbp->object==object) return cbp; break; } myMessage(MSG_OK,"Error: object not found"); return NULL; } Local(void) DelCallbacks(Handle object) { Int2 i,j; WindoW win; win=ParentWindow(object); for (i=0; icallback))(w); } Local(void) MyResizeProc(WindoW w) { ((iNlm_WndActnProc)(LookupCallback(CB_WINRESIZE,w)->callback))(w); } Local(void) MyCleanupProc(WindoW w, VoidPtr ptr) { ((iNlm_WndFreeProc)(LookupCallback(CB_WINCLEANUP,w)->callback))(w,ptr); } Local(void) MyGroupProc(GrouP g) { ((iNlm_GrpActnProc)(LookupCallback(CB_GROUP,g)->callback))(g); } Local(void) MyDialogProc(TexT t) { ((iNlm_TxtActnProc)(LookupCallback(CB_DIALOG,t)->callback))(t); } Local(void) MyListProc(LisT l) { ((iNlm_LstActnProc)(LookupCallback(CB_LIST,l)->callback))(l); } Local(void) MyButtonProc(ButtoN b) { ((iNlm_BtnActnProc)(LookupCallback(CB_BUTTON,b)->callback))(b); } Local(void) MyDrawProc(PaneL p) { ((iNlm_PnlActnProc)(LookupCallback(CB_DRAW,p)->callback))(p); } Local(void) MyReleaseProc(PaneL p, PoinT pt) { ((iNlm_PnlClckProc)(LookupCallback(CB_RELEASE,p)->callback))(p,pt); } Local(void) MyClickProc(PaneL p, PoinT pt) { ((iNlm_PnlClckProc)(LookupCallback(CB_CLICK,p)->callback))(p,pt); } Local(void) MyDragProc(PaneL p, PoinT pt) { ((iNlm_PnlClckProc)(LookupCallback(CB_DRAG,p)->callback))(p,pt); } Local(void) MyHoldProc(PaneL p, PoinT pt) { ((iNlm_PnlClckProc)(LookupCallback(CB_HOLD,p)->callback))(p,pt); } #if MYSWITCH Local(void) MySwitchProc(GraphiC s, Int2 new, Int2 old) { ((iNlm_ChngProc)(LookupCallback(CB_SWITCH,s)->callback))(s,new,old); } #else Local(void) MySwitchProc(SwitcH s, Int2 new, Int2 old) { ((iNlm_SwtChngProc)(LookupCallback(CB_SWITCH,s)->callback))(s,new,old); } #endif #undef StringWidth Local(Int2) StringWidth(CharPtr ptr) { Int2 w; Prolog w=Nlm_StringWidth(ptr); Epilog return w; } #undef DocumentWindow Local(WindoW) DocumentWindow(Int2 left, Int2 top, Int2 width, Int2 height, CharPtr title, iNlm_WndActnProc close, iNlm_WndActnProc resize) { WindoW w; Prolog w=Nlm_DocumentWindow(left,top,width,height,title,close ? MyCloseProc : NULL,resize ? MyResizeProc : NULL); AddCallback(CB_WINCLOSE,w,close); AddCallback(CB_WINRESIZE,w,resize); Epilog return w; } #undef FixedWindow Local(WindoW) FixedWindow(Int2 left, Int2 top, Int2 width, Int2 height, CharPtr title, iNlm_WndActnProc close) { WindoW w; Prolog w=Nlm_FixedWindow(left,top,width,height,title,close ? MyCloseProc : NULL); AddCallback(CB_WINCLOSE,w,close); Epilog return w; } #undef SetWindowExtra Local(void) SetWindowExtra(WindoW w, VoidPtr data, iNlm_WndFreeProc cleanup) { Prolog Nlm_SetWindowExtra(w,data,cleanup ? MyCleanupProc : NULL); AddCallback(CB_WINCLEANUP,w,cleanup); Epilog } #undef GetWindowExtra Local(VoidPtr) GetWindowExtra(WindoW w) { VoidPtr data; Prolog data=Nlm_GetWindowExtra(w); Epilog return data; } #undef ParentWindow Local(WindoW) ParentWindow(Handle a) { WindoW w; Prolog w=Nlm_ParentWindow(a); Epilog return w; } #undef CurrentWindow Local(WindoW) CurrentWindow(void) { WindoW w; Prolog w=Nlm_CurrentWindow(); Epilog return w; } #undef UseWindow Local(void) UseWindow(WindoW w) { Prolog Nlm_UseWindow(w); Epilog } #undef HiddenGroup Local(GrouP) HiddenGroup(GrouP prnt, Int2 width, Int2 height, iNlm_GrpActnProc actn) { GrouP g; Prolog g=Nlm_HiddenGroup(prnt,width,height,actn ? MyGroupProc : NULL); AddCallback(CB_GROUP,g,actn); Epilog return g; } #undef SetGroupMargins Local(void) SetGroupMargins(GrouP g, Int2 xMargin, Int2 yMargin) { Prolog Nlm_SetGroupMargins(g,xMargin,yMargin); Epilog } #undef SetGroupSpacing Local(void) SetGroupSpacing(GrouP g, Int2 xSpacing, Int2 ySpacing) { Prolog Nlm_SetGroupSpacing(g,xSpacing,ySpacing); Epilog } #undef Show Local(void) Show(Handle a) { Prolog Nlm_Show(a); Epilog } #undef Hide Local(void) Hide(Handle a) { Prolog Nlm_Hide(a); Epilog } #undef Enable Local(void) Enable(Handle a) { Prolog Nlm_Enable(a); Epilog } #undef Disable Local(void) Disable(Handle a) { Prolog Nlm_Disable(a); Epilog } #undef Select Local(void) Select(Handle a) { Prolog Nlm_Select(a); Epilog } #undef SetValue Local(void) SetValue(Handle a, Int2 value) { Prolog Nlm_SetValue(a,value); Epilog } #undef GetValue Local(Int2) GetValue(Handle a) { Int2 v; Prolog v=Nlm_GetValue(a); Epilog return v; } #undef SetTitle Local(void) SetTitle(Handle a, CharPtr title) { Prolog Nlm_SetTitle(a,title); Epilog } #undef GetTitle Local(void) GetTitle(Handle a, CharPtr title, size_t maxsize) { Prolog Nlm_GetTitle(a,title,maxsize); Epilog } #undef SetPosition Local(void) SetPosition(Handle a, RectPtr r) { Prolog Nlm_SetPosition(a,r); Epilog } #undef GetPosition Local(void) GetPosition(Handle a, RectPtr r) { Prolog Nlm_GetPosition(a,r); Epilog } #undef Reset Local(void) Reset(Handle a) { Prolog Nlm_Reset(a); Epilog } #undef Remove Local(Handle) Remove(Handle a) { Handle h; Prolog h=Nlm_Remove(a); DelCallbacks(a); Epilog return h; } #undef SetNextPosition Local(void) SetNextPosition(Handle a, PoinT nps) { Prolog Nlm_SetNextPosition(a,nps); Epilog } #undef GetNextPosition Local(void) GetNextPosition(Handle a, PointPtr nps) { Prolog Nlm_GetNextPosition(a,nps); Epilog } #undef DialogText Local(TexT) DialogText(GrouP prnt, CharPtr dfault, Int2 charWidth, iNlm_TxtActnProc actn) { TexT t; Prolog t=Nlm_DialogText(prnt,dfault,charWidth,actn ? MyDialogProc : NULL); AddCallback(CB_DIALOG,t,actn); Epilog return t; } #undef TextLength Local(size_t) TextLength(TexT t) { size_t len; Prolog len=Nlm_TextLength(t); Epilog return len; } #undef SelectText Local(void) SelectText(TexT t, Int2 begin, Int2 end) { Prolog Nlm_SelectText(t,begin,end); Epilog } #undef SingleList Local(LisT) SingleList(GrouP prnt, Int2 width, Int2 height, iNlm_LstActnProc actn) { LisT l; Prolog l=Nlm_SingleList(prnt,width,height,actn ? MyListProc : NULL); AddCallback(CB_LIST,l,actn); Epilog return l; } #undef ListItem Local(void) ListItem(LisT l, CharPtr title) { Prolog Nlm_ListItem(l,title); Epilog } #undef PushButton Local(ButtoN) PushButton(GrouP prnt, CharPtr title, iNlm_BtnActnProc actn) { ButtoN b; Prolog b=Nlm_PushButton(prnt,title,actn ? MyButtonProc : NULL); AddCallback(CB_BUTTON,b,actn); Epilog return b; } #undef DefaultButton Local(ButtoN) DefaultButton(GrouP prnt, CharPtr title, iNlm_BtnActnProc actn) { ButtoN b; Prolog b=Nlm_DefaultButton(prnt,title,actn ? MyButtonProc : NULL); AddCallback(CB_BUTTON,b,actn); Epilog return b; } #undef AlignObjects Local(void) CDECL AlignObjects(int align, ...) { va_list args; HANDLE h; #ifdef WIN32 HANDLE h1; int alig; #endif Int2 n; Prolog va_start(args,align); #ifdef WIN32 /* BASM does not exist under WIN32 */ for (n=0; n<2; n++) { alig=va_arg(args,int); h=va_arg(args,HANDLE); do { h1=va_arg(args,HANDLE); Nlm_AlignObjects(alig,h,h1,NULL); } while (h1); va_end(args); va_start(args,align); } #else asm push 0; /* The order of parameters is irrelevant for AlignObjects (except for the first and last) */ for (n=1; h=va_arg(args,HANDLE),h!=NULL; n++) { asm push h; } Nlm_AlignObjects(align); for (; n>0; n--) { asm pop h; } #endif va_end(args); Epilog } #undef SimplePanel Local(PaneL) SimplePanel(GrouP prnt, Int2 pixwidth, Int2 pixheight, iNlm_PnlActnProc draw) { PaneL p; Prolog p=Nlm_SimplePanel(prnt,pixwidth,pixheight,draw ? MyDrawProc : NULL); AddCallback(CB_DRAW,p,draw); Epilog return p; } #undef SetPanelClick Local(void) SetPanelClick(PaneL p, iNlm_PnlClckProc click, iNlm_PnlClckProc drag, iNlm_PnlClckProc hold, iNlm_PnlClckProc release) { Prolog Nlm_SetPanelClick(p,click ? MyClickProc : NULL, drag ? MyDragProc : NULL, hold ? MyHoldProc : NULL, release ? MyReleaseProc : NULL); AddCallback(CB_CLICK,p,click); AddCallback(CB_DRAG,p,drag); AddCallback(CB_HOLD,p,hold); AddCallback(CB_RELEASE,p,release); Epilog } #undef Update Local(void) Update(void) { Prolog Nlm_Update(); Epilog } #undef InvalRect Local(void) InvalRect(RectPtr r) { Prolog Nlm_InvalRect(r); Epilog } #undef PaintRect Local(void) PaintRect(RectPtr r) { Prolog Nlm_PaintRect(r); Epilog } #undef ClipRect Local(void) ClipRect(RectPtr r) { Prolog Nlm_ClipRect(r); Epilog } #undef OffsetRect Local(void) OffsetRect(RectPtr r, Int2 dx, Int2 dy) { Prolog Nlm_OffsetRect(r,dx,dy); Epilog } #undef LoadRect Local(void) LoadRect(RectPtr r, Int2 lf, Int2 tp, Int2 rt, Int2 bt) { Prolog Nlm_LoadRect(r,lf,tp,rt,bt); Epilog } #undef InsetRect Local(void) InsetRect(RectPtr r, Int2 dx, Int2 dy) { Prolog Nlm_InsetRect(r,dx,dy); Epilog } #undef PtInRect Local(Boolean) PtInRect(PoinT pt, RectPtr r) { Boolean b; Prolog b=Nlm_PtInRect(pt,r); Epilog return b; } #undef LoadPt Local(void) LoadPt(PointPtr pt, Int2 x, Int2 y) { Prolog Nlm_LoadPt(pt,x,y); Epilog } #undef FrameOval Local(void) FrameOval(RectPtr r) { Prolog Nlm_FrameOval(r); Epilog } #undef PaintOval Local(void) PaintOval(RectPtr r) { Prolog Nlm_PaintOval(r); Epilog } #undef FrameArc Local(void) FrameArc(RectPtr r, PoinT start, PoinT end) { Prolog Nlm_FrameArc(r,start,end); Epilog } #undef MoveTo Local(void) MoveTo(Int2 x, Int2 y) { Prolog Nlm_MoveTo(x,y); Epilog } #undef LineTo Local(void) LineTo(Int2 x, Int2 y) { Prolog Nlm_LineTo(x,y); Epilog } #undef SelectColor Local(void) SelectColor(Uint1 red, Uint1 green, Uint1 blue) { Prolog Nlm_SelectColor(red,green,blue); Epilog } #undef InvertColors Local(void) InvertColors(void) { Prolog Nlm_InvertColors(); Epilog } #undef Black Local(void) Black(void) { Prolog Nlm_Black(); Epilog } #undef Red Local(void) Red(void) { Prolog Nlm_Red(); Epilog } #undef Green Local(void) Green(void) { Prolog Nlm_Green(); Epilog } #undef Blue Local(void) Blue(void) { Prolog Nlm_Blue(); Epilog } #undef Cyan Local(void) Cyan(void) { Prolog Nlm_Cyan(); Epilog } #undef Magenta Local(void) Magenta(void) { Prolog Nlm_Magenta(); Epilog } #undef Yellow Local(void) Yellow(void) { Prolog Nlm_Yellow(); Epilog } #undef White Local(void) White(void) { Prolog Nlm_White(); Epilog } #undef WidePen Local(void) WidePen(Int2 width) { Prolog Nlm_WidePen(width); Epilog } #undef Solid Local(void) Solid(void) { Prolog Nlm_Solid(); Epilog } #undef Dotted Local(void) Dotted(void) { Prolog Nlm_Dotted(); Epilog } #undef Dashed Local(void) Dashed(void) { Prolog Nlm_Dashed(); Epilog } #undef ParseFont Local(FonT) ParseFont(CharPtr spec) { FonT f; Prolog f=Nlm_ParseFont(spec); Epilog return f; } #undef SelectFont Local(void) SelectFont(FonT font) { Prolog Nlm_SelectFont(font); Epilog } #undef DeleteFont Local(FonT) DeleteFont(FonT font) { FonT f; Prolog f=Nlm_DeleteFont(font); Epilog return f; } #undef Ascent Local(Int2) Ascent(void) { Int2 n; Prolog n=Nlm_Ascent(); Epilog return n; } #undef Descent Local(Int2) Descent(void) { Int2 n; Prolog n=Nlm_Descent(); Epilog return n; } #undef Leading Local(Int2) Leading(void) { Int2 n; Prolog n=Nlm_Leading(); Epilog return n; } #undef FontHeight Local(Int2) FontHeight(void) { Int2 n; Prolog n=Nlm_FontHeight(); Epilog return n; } #undef LineHeight Local(Int2) LineHeight(void) { Int2 n; Prolog n=Nlm_LineHeight(); Epilog return n; } #undef PaintString Local(void) PaintString(CharPtr text) { Prolog Nlm_PaintString(text); Epilog } #undef RealizeWindow Local(void) RealizeWindow(WindoW w) { Prolog Nlm_RealizeWindow(w); Epilog } #undef InvertMode Local(void) InvertMode(void) { Prolog Nlm_InvertMode(); Epilog } #undef FrameRect Local(void) FrameRect(RectPtr r) { Prolog Nlm_FrameRect(r); Epilog } #if MYSWITCH Local(Switch) mySwitchCreate(GrouP prnt, Int2 maxval, iNlm_ChngProc actn) { Switch s; Prolog s=SwitchCreate(prnt,maxval,actn ? MySwitchProc : NULL); AddCallback(CB_SWITCH,s,actn); Epilog return s; } Local(void) mySwitchSetValue(Switch s, Int2 val) { Prolog SwitchSetValue(s,val); Epilog } Local(Int2) mySwitchGetValue(Switch s) { Int2 m; Prolog m=SwitchGetValue(s); Epilog return m; } Local(void) mySwitchSetMax(Switch s, Int2 maxv) { Prolog SwitchSetMax(s,maxv); Epilog } Local(void) mySwitchSetParams(Switch s, Int2 val, Int2 maxv) { Prolog SwitchSetParams(s,val,maxv); Epilog } Local(Int2) mySwitchHeight(void) { Int2 m; Prolog m=SwitchHeight(); Epilog return m; } #else /* MYSWITCH */ #undef UpDownSwitch Local(SwitcH) UpDownSwitch(GrouP prnt, Boolean text, iNlm_SwtChngProc actn) { SwitcH s; Prolog s=Nlm_UpDownSwitch(prnt,text,actn ? MySwitchProc : NULL); AddCallback(CB_SWITCH,s,actn); Epilog return s; } #undef LeftRightSwitch Local(SwitcH) LeftRightSwitch(GrouP prnt, Boolean text, iNlm_SwtChngProc actn) { SwitcH s; Prolog s=Nlm_LeftRightSwitch(prnt,text,actn ? MySwitchProc : NULL); AddCallback(CB_SWITCH,s,actn); Epilog return s; } #undef SetSwitchMax Local(void) SetSwitchMax(SwitcH s, Int2 max) { Prolog Nlm_SetSwitchMax(s,max); Epilog } #undef GetSwitchMax Local(Int2) GetSwitchMax(SwitcH s) { Int2 m; Prolog m=Nlm_GetSwitchMax(s); Epilog return m; } #undef SetSwitchParams Local(void) SetSwitchParams(SwitcH s, Int2 value, Int2 max) { Prolog Nlm_SetSwitchParams(s,value,max); Epilog } #endif /* MYSWITCH */ Local(void) myReadWindowPos(CharPtr id, Int2Ptr left, Int2Ptr top) { Prolog ReadWindowPos(id,left,top); Epilog } Local(void) myWriteWindowPos(CharPtr id, WindoW win) { Prolog WriteWindowPos(id,win); Epilog } #else /* #if __WIN */ #if _UNIX extern Boolean Nlm_hasColor; #endif #if _MAC extern Boolean Nlm_hasColorQD; #endif #endif /* #if __WIN */ #if DEB Local(void) printRect(CharPtr title, RectPtr rp) { if (title) printf(title); printf("(%i,%i)-(%i,%i)",rp->left,rp->top,rp->right,rp->bottom); } Local(void) printRectL(CharPtr title, RectPtr rp) { printRect(title,rp); printf("\n"); } #endif /* DEB */ Global(InterFunc) InterFuncTable={ /* Vibrant */ &screenRect, &dblClick, &sysCharWidth, &sysLineHeight, &sysDescent, &sysAscent, &vScrollBarWidth, #if _UNIX &Nlm_hasColor, #endif #if _MAC &Nlm_hasColorQD, #endif #if _WIN /* NOT __WIN! */ NULL, #endif &ProgramFont, &SystemFont, &dialogTextHeight, StringWidth, TextWidth, DocumentWindow, FixedWindow, SetWindowExtra, GetWindowExtra, ParentWindow, CurrentWindow, UseWindow, NormalGroup, HiddenGroup, SetGroupMargins, SetGroupSpacing, Show, Hide, Enable, Disable, Visible, Select, SetValue, GetValue, SetTitle, GetTitle, SetStatus, GetStatus, SetPosition, GetPosition, SetOffset, GetOffset, Reset, Remove, SetNextPosition, GetNextPosition, Advance, Break, DialogText, HiddenText, TextLength, SelectText, TextSelectionRange, SetTextSelect, SingleList, ListItem, PopupList, PopupItem, PushButton, DefaultButton, CheckBox, RadioButton, StaticPrompt, AlignObjects, SimplePanel, GetSlateVScrollBar, SetPanelClick, ScrollBar, CorrectBarValue, CorrectBarMax, SetRange, SetObjectExtra, GetObjectExtra, Parent, SetAction, Update, InvalRect, PaintRect, ClipRect, ResetClip, OffsetRect, LoadRect, InsetRect, UpsetRect, UnionRect, SectRect, PtInRect, LoadPt, AddPt, SubPt, EqualPt, FrameOval, PaintOval, FrameArc, MoveTo, LineTo, SetPen, DrawLine, SelectColor, GetColor, InvertColors, DecodeColor, Black, Red, Green, Blue, Cyan, Magenta, Yellow, White, WidePen, SetPenDash, Solid, Dotted, Dashed, ParseFont, SelectFont, DeleteFont, Ascent, Descent, Leading, FontHeight, LineHeight, PaintString, DrawString, PaintText, RealizeWindow, InvertMode, CopyMode, FrameRect, CopyBits, #if MYSWITCH #if __WIN mySwitchCreate, mySwitchSetValue, mySwitchGetValue, mySwitchSetMax, mySwitchSetParams, mySwitchHeight, #else /* __WIN */ SwitchCreate, SwitchSetValue, SwitchGetValue, SwitchSetMax, SwitchSetParams, SwitchHeight, #endif /* __WIN */ #else /* MYSWITCH */ UpDownSwitch, LeftRightSwitch, SetSwitchMax, GetSwitchMax, SetSwitchParams, #endif /* MYSWITCH */ DocumentPanel, UpdateDocument, AppendText, ReplaceText, DeleteItem, AdjustDocScroll, SetDocShade, GetDocParams, GetColParams, ItemIsVisible, GetScrlParams, ProcessUpdatesFirst, myGetInputFileName, myGetOutputFileName, ChooseColorDialog, /* Own functions */ /* dynamic libraries */ LibraryUnlockRequest, /* Window position */ #if __WIN myReadWindowPos, myWriteWindowPos, #else ReadWindowPos, WriteWindowPos, #endif InitLargeWindow, ShowLargeWindow, Redraw, myWarning, lMoveTo, lPoint, lLine, lString, #if DEB printRect, printRectL, #endif /* DEB */ };