123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It 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 Lesser General Public License for more details. *)(* *)(* See the GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file licenses/LGPLv2.1). *)(* *)(**************************************************************************)(* -------------------------------------------------------------------------- *)(* --- Utils --- *)(* -------------------------------------------------------------------------- *)letonxf=matchxwithNone->()|Somex->fxletfirefsx=List.iter(funf->fx)fsletonce=Wutil_once.once(* -------------------------------------------------------------------------- *)(* --- Pango Properties --- *)(* -------------------------------------------------------------------------- *)letsmall_font=once(fun(f:GPango.font_description)->letf=f#copyinletsize=f#size-2inf#modify~size();f)letbold_font=once(fun(f:GPango.font_description)->letf=f#copyinletweight=`BOLDinf#modify~weight();f)letmodify_fontphi(widget:#GObj.widget)=widget#misc#modify_font(phiwidget#misc#pango_context#font_description)letset_small_fontw=modify_fontsmall_fontwletset_bold_fontw=modify_fontbold_fontwletset_fontwname=w#misc#modify_font_by_namenameletset_monospacew=set_fontw"monospace"(* -------------------------------------------------------------------------- *)(* --- Misc --- *)(* -------------------------------------------------------------------------- *)letset_tooltipwm=onmw#misc#set_tooltip_textletset_enabled(w:#GObj.widget)=w#misc#set_sensitiveletset_visible(w:#GObj.widget)e=letm=w#miscinifethenm#show()elsem#hide()letshare=ref"/usr/local/share"letflush=refprerr_endlineletwarningmsg=letbuffer=Buffer.create80inFormat.kfprintf(funfmt->Format.pp_print_flushfmt();!flush(Buffer.contentsbuffer))(Format.formatter_of_bufferbuffer)msg(* -------------------------------------------------------------------------- *)(* --- UTF-8 --- *)(* -------------------------------------------------------------------------- *)letto_utf8s=tryifGlib.Utf8.validatesthenselseGlib.Convert.locale_to_utf8swithGlib.Convert.Error_->tryGlib.Convert.convert_with_fallback~fallback:"#neither UTF-8 nor locale nor ISO-8859-15#"~to_codeset:"UTF-8"~from_codeset:"ISO_8859-15"swithGlib.Convert.Error_ase->Printexc.to_stringe(* -------------------------------------------------------------------------- *)(* --- Timer --- *)(* -------------------------------------------------------------------------- *)letlaterf=letfor_idle()=f();falseinletprio=Glib.int_of_priority`LOWinignore(Glib.Idle.add~priofor_idle)(* -------------------------------------------------------------------------- *)(* --- Ratio --- *)(* -------------------------------------------------------------------------- *)letget_pane_ratio(paned:GPack.paned)=letpaned_min_pos=paned#min_positioninletpaned_max_pos=paned#max_positioninletlength=paned_max_pos-paned_min_posiniflength=0then0.5else(float_of_intpaned#position)/.(float_of_intlength)letset_pane_ratio(paned:GPack.paned)ratio=letpaned_min_pos=paned#min_positioninletoffset=int_of_float(float(paned#max_position-paned_min_pos)*.ratio)inpaned#set_position(paned_min_pos+offset)(* -------------------------------------------------------------------------- *)(* --- Widget & Signals --- *)(* -------------------------------------------------------------------------- *)classtypewidget=objectmethodset_visible:bool->unitmethodset_enabled:bool->unitmethodcoerce:GObj.widgetmethodwidget:widgetendclassgobj_widgetobj=object(self)methodset_visible=set_visibleobjmethodset_enabled=set_enabledobjmethodcoerce:GObj.widget=(obj#coerce)methodwidget=(self:>widget)endclassgobj_actionobj=objectinheritgobj_widgetobjmethodset_tooltiptxt=set_tooltip(obj:>GObj.widget)(Sometxt)endclasslayout=object(self)valmutablecontent:widgetoption=Nonemethodcoerce=matchcontentwith|None->raise(Invalid_argument"Wbox.layout")|Somew->w#coercemethodwidget=matchcontentwith|None->(self:>widget)|Somew->wmethodset_visiblev=matchcontentwith|None->()|Somew->w#set_visiblevmethodset_enablede=matchcontentwith|None->()|Somew->w#set_enabledemethodpopulate:'a.(#widgetas'a)->unit=funw->content<-Some(w:>widget)endclassvirtual['a]handler=object(self)methodvirtualconnect:('a->unit)->unitmethodon_checkvf=self#connect(fune->f(e=v))methodon_valuevf=self#connect(fune->ife=vthenf())methodon_eventf=self#connect(fun_->f())endclass['a]signal=objectvalmutableenabled=truevalmutablelock=falsevalmutabledemon=[]inherit['a]handlermethodfire(x:'a)=ifenabled&¬lockthentrylock<-true;firedemonx;lock<-falsewitherr->lock<-false;raiseerrmethodconnectf=demon<-demon@[f]methodset_enablede=enabled<-emethodlock:(unit->unit)->unit=funf->ifnotlockthentrylock<-true;f();lock<-falsewitherr->lock<-false;raiseerrendclass['a]selectordefault=object(self)valmutablecurrent:'a=defaultinherit['a]signalmethodget=currentmethodsetx=current<-x;self#firexmethodsendf()=self#lock(fun()->fcurrent)end