//html 复制操作 import win.clip; import util.metaProperty; namespace win.clip; class html{ @_metaProperty; } namespace html{ format = ::User32.RegisterClipboardFormat("HTML Format"); test = function(){ return ..win.clip.test(format); }; _metaProperty = ..util.metaProperty( read = function(){ var cbHtml; if(!::User32.OpenClipboard(0)) return; var hClip = ::User32.GetClipboardDataP(format); if(hClip){ var p = ::GlobalLock(hClip) if(p){ cbHtml = ..raw.str(p); ::GlobalUnlock(hClip) } } ::User32.CloseClipboard(); if( cbHtml && owner.parse(cbHtml)) return owner; } write = function(htmlFragment,utf8,rep){ var cbHtml = owner.stringify(htmlFragment,utf8) if(cbHtml){ if(!::User32.OpenClipboard(0)) return; if(rep===null || rep) ::User32.EmptyClipboard(); var clipbuffer = ::GlobalAlloc(0x2000/*_GMEM_DDESHARE*/, #cbHtml+1); var buffer = ::GlobalLock(clipbuffer); ::CopyMemory(buffer,cbHtml,#cbHtml+1); ::GlobalUnlock(clipbuffer); var hdl = ::User32.SetClipboardDataP(format,clipbuffer); ::User32.CloseClipboard(); return hdl; } } stringify = function(htmlFragment,utf8){ if( utf8 === null ) utf8 = true; if( htmlFragment ){ var startFragment = ..string.find(htmlFragment,"@"); var endFragment = ..string.find(htmlFragment,"@"); if( startFragment ){ owner[["html"]] = htmlFragment; } else { owner[["fragment"]] = htmlFragment; owner[["html"]] = null; } } var cbHtml='Version:1.0\r\nStartHTML:000000000\r\nEndHTML:000000000\r\nStartFragment:000000000\r\nEndFragment:000000000\r\n'; var cbData = owner[["html"]]; if(!cbData ){ if( owner[["fragment"]] ){ var fragment = owner[["fragment"]] owner[["html"]] = ..string.format("
%s",fragment ) cbData = owner[["html"]]; } else{ return; } } if(!utf8) cbData = ..string.fromto(cbData ,0,65001); var startFragment = ..string.find(cbData ,"@"); var endFragment = ..string.find(cbData ,"@"); cbHtml = ..string.replace( cbHtml,"StartFragment\:000000000","StartFragment:" + ..string.format("%09d",#cbHtml + startFragment + #"