On Thu, Apr 12, 2012 at 5:27 PM, strawman <str...@la...> wrote:
> On 12/04/2012 05:23, John Labenski wrote:
> > Is that what you're doing or are you trying to get HTML data from
> copying from some other program?
>
> I'm trying to get HTML clipboard data from Firefox/Chrome; they register
> a format called "HTML Format" at runtime, which has a different internal
> ID to CF_HTML/wxDF_HTML, and the ID changes every time Windows is restarted.
>
> fmt = wx.wxDataFormat("HTML Format")
> print(fmt:GetType(), wx.wxClipboard.Get():IsSupported(fmt))
> -- 49358 true
> fmt = wx.wxDataFormat(wx.wxDF_HTML)
> print(fmt:GetType(), wx.wxClipboard.Get():IsSupported(fmt))
> -- 30 false
Weird, I don't know anything about wxDF_HTML, but the wxWidgets docs
say that it's only supported with Visual Studio and non unicode
builds, so there's something special about it.
> I've checked this against a clipboard inspection tool and it matches the
> actual contents of the clipboard, so registering the DataFormat seems to
> be working.
>
> > If all you want is HTML from the some other program in the clipboard,
> > use wxDF_HTML and don't bother with the wxLuaDataObjectSimple, see :
> > http://wxlua.sourceforge.net/docs/wxluaref.html#wxDataFormatId
>
> Is this possible without using a DataObjectSimple? From looking at the
> manual, DataFormatId is only used by DataFormat, which is only used by
> DataObjectSimple.
I guess not, try this after copying from Firefox or Internet Explorer.
I get text from wxDF_TEXT and "HTML Format" and the HTML from the
derived wxLuaDataObjectSimple, but with some sort of header on it.
-----------------
htmlDataObject = wx.wxLuaDataObjectSimple(wx.wxDataFormat("HTML Format"))
htmlDataObject.data = "x" -- store the data somewhere
print(htmlDataObject:SetData("aaa"), htmlDataObject.data,
htmlDataObject:GetDataSize(), htmlDataObject:GetDataHere())
htmlDataObject.GetDataSize = function(htmlDataObject) return
string.len(htmlDataObject.data) end
htmlDataObject.GetDataHere = function(htmlDataObject) return true,
htmlDataObject.data end -- len must equal
htmlDataObject.SetData = function(htmlDataObject,s)
htmlDataObject.data = s; return true end
print(htmlDataObject:SetData("aaa"), htmlDataObject.data,
htmlDataObject:GetDataSize(), htmlDataObject:GetDataHere())
function GetFromClipboard(dataformat, fmt_str)
local clipboard = wx.wxClipboard.Get()
-- Read some text
if clipboard:Open() then
if clipboard:IsSupported( dataformat ) then
local data = wx.wxTextDataObject()
clipboard:GetData( data )
--wx.wxMessageBox( data:GetText() )
print(dataformat:GetType(), fmt_str, data:GetText())
if (fmt_str == "HTML Format") then
clipboard:GetData( htmlDataObject )
print(dataformat:GetType(), fmt_str, htmlDataObject.data)
end
else
print(dataformat:GetType(), fmt_str, "NO AVAILABLE DATA IN
THIS FORMAT!")
end
clipboard:Close()
end
end
GetFromClipboard(wx.wxDataFormat(wx.wxDF_TEXT), "Text")
GetFromClipboard(wx.wxDataFormat(wx.wxDF_HTML), "wxDF_HTML")
GetFromClipboard(wx.wxDataFormat("HTML Format"), "HTML Format")
-----------
I copied the word "Include" colored red from the wxWidgets
documentation in Firefox, then ran the above.
false x 0 false
true aaa 3 true aaa
1 Text Include
30 wxDF_HTML NO AVAILABLE DATA IN THIS FORMAT!
49379 HTML Format Include
49379 HTML Format Version:0.9
StartHTML:00000172
EndHTML:00000286
StartFragment:00000206
EndFragment:00000250
SourceURL:http://docs.wxwidgets.org/2.8/wx_wxdataobject.html#wxdataobject
<html><body>
<!--StartFragment--><b><font color="#FF0000">Include
</font></b><!--EndFragment-->
</body>
</html>
--------------
Regards,
John