123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104(**************************************************************************)(* Lablgtk *)(* *)(* This program is free software; you can redistribute it *)(* and/or modify it under the terms of the GNU Library General *)(* Public License as published by the Free Software Foundation *)(* version 2, with the exception described in file COPYING which *)(* comes with the library. *)(* *)(* 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 Library General Public License for more details. *)(* *)(* You should have received a copy of the GNU Library 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 *)(* *)(* *)(**************************************************************************)(* $Id$ *)openStdLabelsopenGObjletprint_widgetppf(o:#widget)=Format.fprintfppf"<%s@@0x%x>"o#misc#get_typeo#get_oidclass['a]memo()=objectvaltbl:(int,'a)Hashtbl.t=Hashtbl.create7methodadd(obj:'a)=Hashtbl.addtblobj#get_oidobjmethodfind(obj:widget)=Hashtbl.findtblobj#get_oidmethodremove(obj:widget)=Hashtbl.removetblobj#get_oidendletsignal_id=ref0letnext_callback_id():GtkSignal.id=decrsignal_id;Obj.magic(!signal_id:int)class['a]signal()=object(self)valmutablecallbacks:(GtkSignal.id*('a->unit))list=[]methodcallbacks=callbacksmethodconnect~after~callback=letid=next_callback_id()incallbacks<-ifafterthencallbacks@[id,callback]else(id,callback)::callbacks;idmethodcallarg=List.existscallbacks~f:beginfun(_,f)->letold=GtkSignal.push_callback()intryfarg;GtkSignal.pop_callbackoldwithexn->GtkSignal.pop_callbackold;raiseexnend;()methoddisconnectkey=List.mem_assockey~map:callbacks&&(callbacks<-List.remove_assockeycallbacks;true)endclassvirtualml_signalsdisconnectors=object(self)valafter=falsemethodafter={<after=true>}valmutabledisconnectors:(GtkSignal.id->bool)list=disconnectorsmethoddisconnectkey=ignore(List.existsdisconnectors~f:(funf->fkey))endclassvirtualadd_ml_signalsobjdisconnectors=object(self)valmutabledisconnectors:(GtkSignal.id->bool)list=disconnectorsmethoddisconnectkey=ifList.existsdisconnectors~f:(funf->fkey)then()elseGtkSignal.disconnectobjkeyendclass['a]variable_signals~(set:'asignal)~(changed:'asignal)=objectinheritml_signals[changed#disconnect;set#disconnect]methodchanged=changed#connect~aftermethodset=set#connect~afterendclass['a]variablex=object(self)valchanged=newsignal()valset=newsignal()methodconnect=newvariable_signals~set~changedvalmutablex:'a=xmethodget=xmethodset=set#callmethodprivateequal:'a->'a->bool=(=)methodprivatereal_sety=letx0=xinx<-y;ifchanged#callbacks<>[]&¬(self#equalxx0)thenchanged#callyinitializerignore(set#connect~after:false~callback:self#real_set)end