123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109(*********************************************************************************)(* OCaml-Stk *)(* *)(* Copyright (C) 2023-2024 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU General Public License as *)(* published by the Free Software Foundation, version 3 of the License. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)(** Entry widgets. *)openMiscopenTsdlopenTsdl_ttfopenWidget[@@@landmark"auto"]moduleB=Textbuffer(** Property used to define the character displayed instead of
newline in single-line edition widgets. Default value is ↵ (U+21B5 (8629)).*)letnewline_char_codepoint=Props.int_prop~after:[Render]~default:8629~inherited:true"newline_char_codepoint"letcss_newline_char_codepoint=Theme.int_propnewline_char_codepointclassentry?classes?name?props?wdata()=object(self)inheritTextview.textview?classes?name?props?wdata()assuper(**/**)methodkind="entry"valmutablereplacing_text=false(**/**)methodnewline_char_codepoint=self#get_pnewline_char_codepointmethodset_newline_char_codepoint=self#set_pnewline_char_codepoint(**/**)method!privateon_buffer_changechange=super#on_buffer_changechange;ifnotreplacing_textthenself#set_pProps.text(self#text())(**/**)methodset_textstr=replacing_text<-true;(tryignore(self#delete());replacing_text<-falsewith_->replacing_text<-false);self#insertstr(**/**)method!render_cursorrend~offsetrgcursor_idc=ifself#has_focusthensuper#render_cursorrend~offsetrgcursor_idcinitializerTextview.set_default_key_bindingsself#as_textview;B.set_map_inbuffer(Some(func->matchUchar.to_intcwith|10(* \n *)->prerr_endline(Printf.sprintf"mapping to code point %d"self#newline_char_codepoint);Uchar.of_intself#newline_char_codepoint|_->c));B.set_map_outbuffer(Some(func->ifUchar.to_intc=self#newline_char_codepointthenUchar.of_int10elsec))end(** Convenient function to create a {!class-entry}. Optional arguments:
{ul
{- [editable] specifies whether the contents is editable by user (default is [true]).}
{- [text] specifies the initial text (default is empty).}
}
See {!Widget.widget_arguments} for other arguments. *)letentry?classes?name?props?wdata?editable?text?pack()=lete=newentry?classes?name?props?wdata()inOption.itere#set_editableeditable;Widget.may_pack?packe#coerce;Option.itere#inserttext;e