/**************************************************************************************/ /* 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 */ /**************************************************************************************/ /* librairy used: _jint2D _jobj2dlib.pkg */ /**************************************************************************************/ /* flag de création */ var EDL_TRANSP = 0b0010000000;; /* background is transparent */ /* les differents etats du bouton */ var EDL_STATE_BLINK_ON = 0b00001;; /* cursor on */ var EDL_INSERT_END = 0b00010;; /* insert at the end */ var EDL_BLINK_RATE = 300;; /* Edit line: EDLObj2D : l'objet 2D associe EDLbitmap: bitmap représentant la ligne EDLfont : police utilisée pour le texte EDLbackcolor : couleur de fond du texte EDLtextcolor : couleur des caractères du texte EDLflags : flags de l'edit line EDLipoint : position du point d'insertion de l'edit line EDLstring : texte de l'edit line EDLstate : etat de l'edit line EDLtimer : timer de l'edit line EDLOkReflex : reflexe utilisateur lors de l'appui de la touche entrée */ struct EDLtext=[ EDLObj2D : Obj2D, EDLbitmap: ObjBitmap, EDLfont : ObjFont, EDLbackcolor : I, EDLtextcolor : I, EDLflags : I, EDLipoint : I, /* point d'insertion */ EDLbpoint : I, /* point de base */ EDLepoint : I, /* point de fin */ EDLstring : [I r1], /* liste des caractères composant le texte */ EDLstate : I, EDLtimer : Timer, EDLOkReflex : fun [EDLtext S] EDLtext ] mkEDLtext;; /*************************************************************************************/ /* Fonctions Internes de l' Edit line */ /*************************************************************************************/ /* internal */ fun compEndPoint (object)= let 1 -> epoint in { let 1 -> continue in while continue do { let _GETstringSize object.EDLfont listtostr list_from_to object.EDLstring object.EDLbpoint epoint -> [wtext _] in if (wtext > (object.EDLObj2D.O2Dw-4)) || (epoint>sizelist object.EDLstring) then set continue=0 else set epoint=epoint+1 }; epoint };; fun compBasePoint (object)= let (object.EDLepoint-1) -> bpoint in { let 1 -> continue in while continue do { let _GETstringSize object.EDLfont listtostr list_from_to object.EDLstring bpoint object.EDLepoint -> [wtext _] in if (wtext >= (object.EDLObj2D.O2Dw-4)) || (bpoint <= 0) then set continue=0 else set bpoint=bpoint-1; }; bpoint };; /* 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 MkRectangle2D [MkInt2DPoint[0 0] MkInt2DPoint[object.EDLObj2D.O2Dw object.EDLObj2D.O2Dw]] MoveRectangleBy area MkInt2DPoint[0 0] -> 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; _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLepoint; let object.EDLObj2D -> obj in O2D_RedrawArea obj.O2DParentContainer (O2D_RectangleIncludingObject obj) 1; 1;; /* anim */ fun rflTimerEDL (t, object)= let _GETstringSize object.EDLfont listtostr list_from_to object.EDLstring 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)= set object.EDLipoint = sizelist object.EDLstring; set object.EDLepoint = object.EDLipoint; set object.EDLbpoint = compBasePoint object; _FILLbitmap object.EDLbitmap object.EDLbackcolor; _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLepoint; let _GETstringSize object.EDLfont listtostr list_from_to object.EDLstring 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) && (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 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; } else if vcode==0xffff /* del */ then { set object.EDLstring = remove_nth_from_list object.EDLstring object.EDLipoint; set object.EDLepoint = compEndPoint object; } 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 { set object.EDLstring = add_nth_in_list object.EDLstring object.EDLipoint vcode; set object.EDLipoint = object.EDLipoint+1; let _GETstringSize object.EDLfont listtostr list_from_to object.EDLstring 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; }; }; _FILLbitmap object.EDLbitmap object.EDLbackcolor; _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLepoint; 0;; fun KeyUpEDL (key, object)= 0;; /* Methode destruction object */ fun DsEDL (object)= _DSbitmap object.EDLbitmap; _DSfont object.EDLfont; _deltimer object.EDLtimer; set object.EDLstring = nil; set object.EDLOkReflex = 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, flag, text)= if cont!=nil then let O2D_NewObject cont parent name w h coord flag -> obj in let _FILLbitmap _CRbitmap channel w h 0xffffff -> bmp in let _CRfont channel 18 0 0 "Arial" -> font in let mkEDLtext[ obj bmp font 0xffffff 0 flag 0 0 0 strtolist text EDL_INSERT_END & ~EDL_STATE_BLINK_ON | (if flag&EDL_TRANSP then EDL_TRANSP else 1) 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 } else nil;; 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;; proto EDL_GetGraphicalState = fun [EDLtext] [ObjBitmap I I I I I];; 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)= if (object==nil) then nil else { let _GETstringSize object.EDLfont listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLipoint -> [xbar _] in _DRAWline object.EDLbitmap xbar+2 2 xbar+2 object.EDLObj2D.O2Dh-4 DRAW_SOLID 1 object.EDLbackcolor; set object.EDLstring = strtolist text; set object.EDLbpoint = 0; set object.EDLepoint = strlen text; _FILLbitmap object.EDLbitmap object.EDLbackcolor; _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLepoint; O2D_RedrawArea object.EDLObj2D.O2DParentContainer O2D_RectangleIncludingObject object.EDLObj2D 1; object };; fun EDL_SetTextColor (object, color)= if (object==nil) || (color==nil) then nil else { set object.EDLtextcolor = color; _FILLbitmap object.EDLbitmap object.EDLbackcolor; _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLepoint; O2D_RedrawArea object.EDLObj2D.O2DParentContainer O2D_RectangleIncludingObject object.EDLObj2D 1; object };; fun EDL_SetBackColor (object, color)= if (object==nil) || (color==nil) then nil else { set object.EDLbackcolor = color; _FILLbitmap object.EDLbitmap object.EDLbackcolor; _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLepoint; O2D_RedrawArea object.EDLObj2D.O2DParentContainer O2D_RectangleIncludingObject object.EDLObj2D 1; object };; fun EDL_SetFont (object, font)= if (object==nil) || (font==nil) then nil else { _DSfont object.EDLfont; set object.EDLfont=font; _FILLbitmap object.EDLbitmap object.EDLbackcolor; _DRAWtext object.EDLbitmap object.EDLfont 2 2 TD_TOP|TD_LEFT object.EDLtextcolor listtostr list_from_to object.EDLstring object.EDLbpoint object.EDLepoint; O2D_RedrawArea object.EDLObj2D.O2DParentContainer O2D_RectangleIncludingObject object.EDLObj2D 1; object };;