/**************************************************************************************/ /* Edit Line written by Marc Bariley */ /**************************************************************************************/ /* EDL_New */ /* EDL_Del */ /* EDL_SetOkReflex */ /* EDL_GetObject */ /* EDL_ChangeDisplayFlags */ /* EDL_ChangeCoordinates */ /* EDL_GetCoordinates */ /* EDL_GetGraphicalState */ /* EDL_GetText */ /* EDL_SetText */ /* EDL_SetEditable */ /**************************************************************************************/ /* librairy used: _jint2D _jobj2dlib.pkg */ /* need: mEditLineh.pkg */ /**************************************************************************************/ /* les differents etats de l'edit line */ var EDL_STATE_BLINK_ON = 0b00001;; /* cursor on */ var EDL_INSERT_END = 0b00010;; /* insert at the end */ var EDL_BLINK_RATE = 300;; /*************************************************************************************/ /* Fonctions Internes de l' Edit line */ /*************************************************************************************/ fun drawStars (n)= if n<=0 then nil else '*::(drawStars n-1);; /* internal */ fun compEndPoint (object)= let if object.EDLflags & EDL_PASSWORD then drawStars sizelist object.EDLstring else object.EDLstring -> dstring in let 1 -> epoint in { let 1 -> continue in while continue do { let _GETstringSize object.EDLfont listtostr list_from_to dstring object.EDLbpoint epoint -> [wtext _] in if (wtext > (object.EDLObj2D.O2Dw-4)) || (epoint>sizelist dstring) then set continue=0 else set epoint=epoint+1 }; epoint };; fun compBasePoint (object)= let if object.EDLflags & EDL_PASSWORD then drawStars sizelist object.EDLstring else object.EDLstring -> dstring in let (object.EDLepoint-1) -> bpoint in { let 1 -> continue in while continue do { let _GETstringSize object.EDLfont listtostr list_from_to dstring bpoint object.EDLepoint -> [wtext _] in if (wtext >= (object.EDLObj2D.O2Dw-4)) || (bpoint <= 0) then set continue=0 else set bpoint=bpoint-1; }; bpoint };; fun displayEDL (object)= let if object.EDLflags & EDL_PASSWORD then drawStars sizelist object.EDLstring else object.EDLstring -> dstring in _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to dstring object.EDLbpoint object.EDLepoint; let object.EDLObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; object;; /* Methode Paint*/ fun PaintEDL (object)= let object.EDLObj2D -> obj in [ object.EDLbitmap 0 0 obj.O2Dw obj.O2Dh if object.EDLflags&EDL_TRANSP then object.EDLbackcolor else nil ];; /* Methode Paint Part */ fun PaintPartOfEDL (area, object)= let SizeRectangle area -> [aw ah] in let IntersectionRectangle area MkRectangle2D [ MkInt2DPoint [0 0] MkInt2DPoint [object.EDLObj2D.O2Dw object.EDLObj2D.O2Dh] ] -> rect in let SizeRectangle rect -> [rw rh] in [ object.EDLbitmap rect.RctHG.iptX rect.RctHG.iptY rw rh if object.EDLflags&EDL_TRANSP then object.EDLbackcolor else nil ] ;; /* Methode IsMouseOnObject */ fun IsMouseOnEDL (mx, my, object)= 1;; fun UnClickOutEDL (mx, my, mb, object)= 1;; fun IsUserClickAllowedInEDL()= 0;; fun IsUserUnClickAllowedInEDL()= 0;; fun ClickOutEDL (mx, my, mb, object)= _deltimer object.EDLtimer; set object.EDLtimer=nil; set object.EDLstate = object.EDLstate & ~EDL_STATE_BLINK_ON; set object.EDLbpoint = 0; set object.EDLepoint = compEndPoint object; _FILLbitmap object.EDLbitmap object.EDLbackcolor; displayEDL object; exec object.EDLfocusReflex with [object listtostr object.EDLstring 0]; 1;; /* anim */ fun rflTimerEDL (t, object)= let if object.EDLflags & EDL_PASSWORD then drawStars sizelist object.EDLstring else object.EDLstring -> dstring in let _GETstringSize object.EDLfont listtostr list_from_to dstring object.EDLbpoint object.EDLipoint -> [xbar _] in if (object.EDLstate & EDL_STATE_BLINK_ON) then { _DRAWline object.EDLbitmap xbar+2 2 xbar+2 object.EDLObj2D.O2Dh-4 DRAW_SOLID 1 object.EDLtextcolor; set object.EDLstate = object.EDLstate & ~EDL_STATE_BLINK_ON; } else { _DRAWline object.EDLbitmap xbar+2 2 xbar+2 object.EDLObj2D.O2Dh-4 DRAW_SOLID 1 object.EDLbackcolor; set object.EDLstate = object.EDLstate | EDL_STATE_BLINK_ON; }; O2D_RedrawArea object.EDLObj2D.O2DParentContainer O2D_RectangleIncludingObject object.EDLObj2D 1;; fun ClickInEDL (mx, my, mb, object)= exec object.EDLfocusReflex with [object listtostr object.EDLstring 1]; if object.EDLflags & EDL_NOTEDITABLE then nil else let if object.EDLflags & EDL_PASSWORD then drawStars sizelist object.EDLstring else object.EDLstring -> dstring in { set object.EDLipoint = sizelist dstring; set object.EDLepoint = object.EDLipoint; set object.EDLbpoint = compBasePoint object; _FILLbitmap object.EDLbitmap object.EDLbackcolor; displayEDL object; let _GETstringSize object.EDLfont listtostr list_from_to dstring object.EDLbpoint object.EDLipoint -> [xbar _] in _DRAWline object.EDLbitmap xbar+2 2 xbar+2 object.EDLObj2D.O2Dh-4 DRAW_SOLID 1 object.EDLbackcolor; if ((mb==1)||(mb==nil)) && (object.EDLtimer == nil) then { set object.EDLtimer = _rfltimer _starttimer _channel EDL_BLINK_RATE @rflTimerEDL object; set object.EDLstate = object.EDLstate | EDL_STATE_BLINK_ON; let object.EDLObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; } else nil }; 1;; fun KeyDownEDL (key, vcode, object)= if (object.EDLflags & EDL_NOTEDITABLE) then nil else { if vcode==0x08 /* backspace */ then { set object.EDLstring = remove_nth_from_list object.EDLstring object.EDLipoint-1; if object.EDLipoint > 0 then { set object.EDLepoint = compEndPoint object; set object.EDLipoint = object.EDLipoint-1; if object.EDLipoint < object.EDLbpoint then { set object.EDLbpoint = if (object.EDLipoint-1) < 0 then 0 else object.EDLipoint-1; set object.EDLepoint = compEndPoint object; } else nil; } else nil; if (sizelist object.EDLstring) <= 0 then exec object.EDLEmptyReflex with [object] else nil; exec object.EDLKeyReflex with [object key vcode]; 0 } else if vcode==0xffff /* del */ then { set object.EDLstring = remove_nth_from_list object.EDLstring object.EDLipoint; set object.EDLepoint = compEndPoint object; if (sizelist object.EDLstring) <= 0 then exec object.EDLEmptyReflex with [object] else nil; exec object.EDLKeyReflex with [object key vcode]; 0 } else if vcode==0xff50 /* home */ then { set object.EDLipoint = 0; set object.EDLbpoint = 0; set object.EDLepoint = compEndPoint object; set object.EDLstate = object.EDLstate & ~EDL_INSERT_END; } else if vcode==0xff57 /* end */ then { set object.EDLipoint = sizelist object.EDLstring; set object.EDLepoint = object.EDLipoint; set object.EDLbpoint = compBasePoint object; set object.EDLstate = object.EDLstate | EDL_INSERT_END; } else if vcode==0xff51 /* left */ then if object.EDLipoint > 0 then { set object.EDLipoint = object.EDLipoint-1; if object.EDLipoint < object.EDLbpoint then { set object.EDLbpoint = if (object.EDLipoint-1) < 0 then 0 else object.EDLipoint-1; set object.EDLepoint = compEndPoint object; } else nil; set object.EDLstate = object.EDLstate & ~EDL_INSERT_END; } else nil else if vcode==0xff53 /* right */ then if object.EDLipoint < sizelist object.EDLstring then { set object.EDLipoint = object.EDLipoint + 1; if object.EDLipoint > object.EDLepoint then { set object.EDLepoint = object.EDLipoint; set object.EDLbpoint = compBasePoint object; } else nil; set object.EDLstate = object.EDLstate & ~EDL_INSERT_END; } else set object.EDLstate = object.EDLstate | EDL_INSERT_END else if vcode==0x0d /* entrée */ then { exec object.EDLOkReflex with [object listtostr object.EDLstring]; nil } else if (vcode < 32) || (vcode > 0xff13) /* control char */ then nil else if (isf_in_list object.EDLnotAllowed @equal vcode) then nil else if (object.EDLflags & EDL_ASCII7) && (vcode > 127) then nil else if (sizelist object.EDLstring) < object.EDLmaxchar then { set object.EDLstring = add_nth_in_list object.EDLstring object.EDLipoint vcode; set object.EDLipoint = object.EDLipoint+1; let if object.EDLflags & EDL_PASSWORD then drawStars sizelist object.EDLstring else object.EDLstring -> dstring in let _GETstringSize object.EDLfont listtostr list_from_to dstring object.EDLbpoint object.EDLipoint -> [xbar _] in if object.EDLstate & EDL_INSERT_END then { set object.EDLepoint = object.EDLipoint; set object.EDLbpoint = compBasePoint object; } else { if xbar>(object.EDLObj2D.O2Dw-4) then { set object.EDLepoint = object.EDLepoint+1; set object.EDLbpoint = compBasePoint object; } else set object.EDLepoint = compEndPoint object; }; exec object.EDLKeyReflex with [object key vcode]; nil } else nil; _FILLbitmap object.EDLbitmap object.EDLbackcolor; displayEDL object; }; 0;; fun KeyUpEDL (key, object)= 0;; /* Methode destruction object */ fun DsEDL (object)= _deltimer object.EDLtimer; _DSbitmap object.EDLbitmap; set object.EDLbitmap=nil; _DSfont object.EDLfont; set object.EDLstring = nil; set object.EDLOkReflex = nil; set object.EDLEmptyReflex = nil; 1;; /************************************************************************************/ /* Fonctions externes du EditLine */ /************************************************************************************/ /* Constructeur du EditLine channel : canal de construction cont : container auquel appartient le rollover parent : l'objet pere coord : coordonnees de l'objet par rapport au pere w : largeur h : hauteur name : nom de l'objet flag : flag de construction (O2D_ENABLE, O2D_DISABLE, O2D_HIDE, EDL_TRANSP) text : text initial */ fun EDL_New (channel, cont, parent, coord, w, h, name, o2dflags, flag, fontName, fontSize, fontFlag, text)= if (channel==nil) || (cont==nil) || (coord==nil) || (w==nil) || (h==nil) || (name==nil) || (fontName==nil) || (fontSize==nil) || (fontFlag==nil) then nil else let O2D_NewObject cont parent name w h coord o2dflags -> obj in if obj==nil then nil else { let _FILLbitmap _CRbitmap channel w h 0xffffff -> bmp in { let _CRfont channel fontSize 0 fontFlag fontName -> font in let mkEDLtext[ obj bmp font 0xffffff 0 nil flag 0 0 0 strtolist text EDL_INSERT_END & ~EDL_STATE_BLINK_ON | (if flag&EDL_TRANSP then EDL_TRANSP else 1) nil nil nil nil nil nil] -> object in { /* les methodes */ O2D_CBDsObject obj object @DsEDL; O2D_CBPaint obj object @PaintEDL; O2D_CBPaintPart obj object @PaintPartOfEDL; O2D_CBIsMouseOnDisplayObject obj object @IsMouseOnEDL; O2D_CBUserClickAllowed obj object @IsUserClickAllowedInEDL; O2D_CBUserUnClickAllowed obj object @IsUserUnClickAllowedInEDL; O2D_CBObjectClickIn obj object @ClickInEDL; O2D_CBObjectClickOut obj object @ClickOutEDL; O2D_CBObjectUnClickOut obj object @UnClickOutEDL; O2D_CBObjectKeyDown obj object @KeyDownEDL; O2D_CBObjectKeyUp obj object @KeyUpEDL; object } } };; fun EDL_Del (object)= O2D_DelObject object.EDLObj2D; object;; fun EDL_GetObject (object)= object.EDLObj2D;; fun EDL_ChangeDisplayFlags (object, newFlag, redrawFlag, repaintFlag)= O2D_ChangeObjDisplayFlag object.EDLObj2D newFlag redrawFlag repaintFlag; object;; fun EDL_ChangeCoordinates (object, newCoords, redrawFlag, repaintFlag)= O2D_ChangeObjCoordinates object.EDLObj2D newCoords redrawFlag repaintFlag; object;; fun EDL_GetCoordinates (object)= O2D_GetObjCoordinates object.EDLObj2D;; fun EDL_GetGraphicalState (object)= let object.EDLObj2D -> obj in [object.EDLbitmap 0 0 obj.O2Dw obj.O2Dh (if object.EDLflags&EDL_TRANSP then object.EDLbackcolor else nil)];; fun EDL_GetText (object)= listtostr object.EDLstring;; fun EDL_SetText (object, text, paint)= if (object==nil) then nil else { set object.EDLstring = if 0==strlen text then nil else strtolist text; set object.EDLbpoint = 0; set object.EDLepoint = compEndPoint object; let if object.EDLflags & EDL_PASSWORD then drawStars sizelist object.EDLstring else object.EDLstring -> dstring in let _GETstringSize object.EDLfont listtostr list_from_to dstring object.EDLbpoint object.EDLipoint -> [xbar _] in _DRAWline object.EDLbitmap xbar+2 2 xbar+2 object.EDLObj2D.O2Dh-4 DRAW_SOLID 1 object.EDLbackcolor; _FILLbitmap object.EDLbitmap object.EDLbackcolor; if paint then displayEDL object else nil; }; object;; fun EDL_SetTextColor (object, color, paint)= if (object==nil) || (color==nil) then nil else { set object.EDLtextcolor = color; _FILLbitmap object.EDLbitmap object.EDLbackcolor; if paint then displayEDL object else nil; }; object;; fun EDL_SetBackColor (object, color, paint)= if (object==nil) || (color==nil) then nil else { set object.EDLbackcolor = color; _FILLbitmap object.EDLbitmap object.EDLbackcolor; if paint then displayEDL object else nil; }; object;; fun EDL_SetFont (object, font, paint)= if (object==nil) || (font==nil) then nil else { _DSfont object.EDLfont; set object.EDLfont=font; _FILLbitmap object.EDLbitmap object.EDLbackcolor; if paint then displayEDL object else nil; }; object;; fun EDL_SetEditable (object, flag)= if flag then set object.EDLflags = object.EDLflags & ~EDL_NOTEDITABLE else set object.EDLflags = object.EDLflags | EDL_NOTEDITABLE; object;; fun EDL_SetReflexOk (object, f, param)= set object.EDLOkReflex = mkfun3 f param; object;; fun EDL_SetOkReflex (object, f, param)= set object.EDLOkReflex = mkfun3 f param; object;; fun EDL_SetReflexEmpty (object, f, param)= set object.EDLEmptyReflex = mkfun2 f param; object;; fun EDL_SetEmptyReflex (object, f, param)= set object.EDLEmptyReflex = mkfun2 f param; object;; fun EDL_SetKeyReflex (object, f, param)= set object.EDLKeyReflex = mkfun4 f param; object;; fun EDL_SetFocusReflex (object, f, param)= set object.EDLfocusReflex = mkfun4 f param; object;; fun EDL_DisableChars (object, l)= set object.EDLnotAllowed = l; object;; fun EDL_Ascii7 (object)= set object.EDLflags = object.EDLflags | EDL_ASCII7; object;; fun EDL_SetMaxChar (object, i)= set object.EDLmaxchar = i; object;;