123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)(* ------------------------------------------------------------------------ *)(* --- Forms Factory --- *)(* ------------------------------------------------------------------------ *)typedemon=(unit->unit)listrefletdemon()=ref[]letregisterdemonf=demon:=!demon@[f]letrefreshdemon()=List.iter(funf->tryf()with_->())!demon(* ------------------------------------------------------------------------ *)(* --- Utilities --- *)(* ------------------------------------------------------------------------ *)type'afield=?tooltip:string->packing:(GObj.widget->unit)->(unit->'a)->('a->unit)->demon->unit(* ------------------------------------------------------------------------ *)(* --- Check Button --- *)(* ------------------------------------------------------------------------ *)letcheck?label?tooltip~packinggetsetdemon=letbutton=GButton.check_button?label~packing~active:(get())()inGtk_helper.do_tooltip?tooltipbutton;ignore(button#connect#toggled~callback:(fun()->setbutton#active));registerdemon(fun()->button#set_active(get()))(* ------------------------------------------------------------------------ *)(* --- Menu Button --- *)(* ------------------------------------------------------------------------ *)letmenuentries?width?tooltip~packinggetsetdemon=letstrings=List.mapfstentriesinletcombo_box,(_model,column)=GEdit.combo_box_text~strings?width~wrap_width:1~packing()inletcallback()=trymatchcombo_box#active_iterwith|None->()|Somerow->lettitle=(combo_box#model#get~row~column)inlet(_,item)=List.find(fun(t,_)->t=title)entriesinsetitemwithNot_found->()inletreclookupkitem=function|[]->raiseNot_found|(_,value)::entries->ifvalue=itemthenkelselookup(succk)itementriesinletupdate()=trycombo_box#set_active(lookup0(get())entries)withNot_found->()inignore(combo_box#connect#changed~callback);Gtk_helper.do_tooltip?tooltipcombo_box;registerdemonupdate(* ------------------------------------------------------------------------ *)(* --- Spinner --- *)(* ------------------------------------------------------------------------ *)letspinner?(lower=0)?(upper=max_int)?width?tooltip~packinggetsetdemon=letspin=GEdit.spin_button~digits:0?width~packing()inspin#adjustment#set_bounds~lower:(floatlower)~upper:(floatupper)~step_incr:1.();letcallback()=leta=spin#value_as_intinletb=get()inifa<>bthensetainletupdate()=spin#adjustment#set_value(float(get()))inignore(spin#connect#value_changed~callback);Gtk_helper.do_tooltip?tooltipspin;registerdemonupdate(* ------------------------------------------------------------------------ *)(* --- Forms --- *)(* ------------------------------------------------------------------------ *)classform~packing=objectvaltable=GPack.table~rows:2~col_spacings:8~packing()valmutabletop=0methodlabeltext=ignore(GMisc.label~text~packing:(table#attach~top~left:0~expand:`NONE)())methoditemobj=table#attach~top~left:1~expand:`X~fill:`Xobj;top<-succtopmethodrowobj=table#attach~top~left:0~right:2~expand:`X~fill:`Xobj;top<-succtopendletlabel~text~packing()=ignore(GMisc.label~xpad:3~text~packing())letbutton~label?tooltip~callback~packing()=letb=GButton.button~label~packing()inGtk_helper.do_tooltip?tooltipb;ignore(b#connect#clicked~callback)