I've decided to experiment to some extent with
jethrow's idea for advancing the iWeb functions further using AHK_L. I've been using
jethrow's string library as a model to work from, but the obvious drawback to this method is the inability to utilize a persistent pointer (as the base will only accept non-objects via this method). Nonetheless, building
getWin() into the other functions to acquire the pointer each time doesn't appear to present any problems, and you can save the page name to a variable which will make it appear as if it is an object. This, for example, works in my most recent code tests:
Code:
pwb := "Google"
pwb.setDomObj("q","Hello world!")
But since, as another example, there are several methods to click a page element, I think it would be more beneficial to develop a click object to access the different methods rather than define each method explicitly. Instead of this:
Code:
pwb.clickDomObj
pwb.clickText
pwb.clickHref
. . .
We could have this:
Code:
pwb.click.domObj
pwb.click.Text
pwb.click.Href
. . .
This would have the benefit of a more "natural" syntax for users to work with and also the added benefit of getting users more involved in the dotted-path syntax, which seems to scare so many when the iWeb functions won't work for what they need and they have to go "manual". But I've been having trouble figuring out how to build in this base functionality to create the desired effect, so if tank or jethrow or anyone else interested would be willing to have a look at what I have so far to see how we could make this work, it would be greatly appreciated:
Code:
iWeb_Funcs()
{
"".base.nav := "nav"
"".base.complete := "complete"
"".base.getdomObj := "getDomObj"
"".base.setdomObj := "setDomObj"
"".base.clickdomObj := "clickDomObj"
"".base.clicktext := "clickText"
"".base.clickHref := "clickHref"
"".base.clickvalue := "clickValue"
return True
}
getWin(Name="")
{
IfEqual, Name, , WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
Name := RegExReplace(Name," - (?:Windows|Microsoft) Internet Explorer")
COM_Error(0)
For win in ComObjCreate("Shell.Application").Windows
If (InStr(win.LocationName,Name) && InStr(win.FullName,"iexplore.exe"))
pwb := win
Until (InStr(win.LocationName,Name) && InStr(win.FullName,"iexplore.exe"))
COM_Error(1)
Return pwb ? pwb : False
}
nav(in,url)
{
if !pwb := getWin(in)
return False
navTrustedForActiveX = 0x0400
pwb.navigate[url,navTrustedForActiveX,"_self"], pwb := ""
complete(in)
Return True
}
domWin(pdsp,frm="")
{
qsid := "{332C4427-26CB-11D0-B483-00C04FD90119}"
If !pWin := Query_Service(pdsp, qsid, qsid)
return False
if frm {
Loop, Parse, frm, `,
{
frame := pWin.document.all.item[A_LoopField].contentwindow
pWin := Query_Service(frame, qsid, qsid)
If !pWin
Return False
}
}
Return COM_Enwrap(pWin)
}
complete(in)
{
if !pwb := getWin(in)
return False
COM_Error(0)
While (pwb.busy && pwb.readyState <> 4 && pwb.document.readystate <> "complete")
Sleep,50
COM_Error(1)
Return True
}
getDomObj(in,obj,frm="")
{
if !pdsp := getWin(in)
return False
if !pWin := frm ? domWin(pdsp,frm) : pdsp
return False
if !InStr(obj,",") {
if itm := pWin.document.all.item[obj] {
res := inpt(itm) ? itm.value : itm.innerHTML
StringReplace, res, res,`,, ,, All
itm := ""
}
return res
}
Loop,Parse,obj,`,
{
If itm := pWin.document.all.item[A_LoopField] {
d := iWeb_inpt(itm) ? itm.value : itm.innerHTML
StringReplace, d, d,`,, ,, All
res .= (!res ? "" : ",") d
}
}
Return res
}
setDomObj(in,obj,t,frm="")
{
if !pdsp := getWin(in)
return False
if !pWin := frm ? domWin(pdsp,frm) : pdsp
return False
if !InStr(obj,",")
{
if itm := pWin.document.all[obj]
{
StringReplace, t, t, ,,`,, All
itm[inpt(itm) ? "value" : "innerHTML"] := t, fireEvents(itm)
}
Return True
}
StringSplit, text, t, `,
job := Object()
Loop, parse, obj, `,
job.Insert(A_LoopField,text%A_Index%)
For object, text in job
{
If itm := pWin.document.all[object]
{
StringReplace, textOut, text, ,,`,, All
itm[inpt(itm) ? "value" : "innerHTML"] := textOut, fireEvents(itm)
}
}
Return True
}
clickDomObj(in,obj,frm="")
{
if !pdsp := getWin(in)
return False
if !pWin := frm ? domWin(pdsp,frm) : pdsp
return False
pWin.document.all[obj].click(), fireEvents(pWin.document.all[obj])
Return True
}
clickText(in,t,frm="")
{
if !pdsp := getWin(in)
return False
if !pWin := frm ? domWin(pdsp,frm) : pdsp
return False
links := pWin.document.links
Loop % links.length
If InStr(links.item[A_Index-1].innertext,t) {
links.item[A_Index-1].click(), fireEvents(links.item[A_Index-1])
Break
}
Return True
}
clickHref(in,t,frm="")
{
if !pdsp := getWin(in)
return False
if !pWin := frm ? domWin(pdsp,frm) : pdsp
return False
links := pWin.document.links
Loop % links.length
If InStr(links.item[A_Index-1].href,t) {
links.item[A_Index-1].click(), fireEvents(links.item[A_Index-1])
Break
}
Return True
}
clickValue(in,value,frm="")
{
if !pdsp := getWin(in)
return False
if !pWin := frm ? domWin(pdsp,frm) : pdsp
return False
all := pWin.document.all
Loop % all.length
If (inpt(all.item[A_Index-1]) && InStr(all.item[A_Index-1].value,value)) {
all.item[A_Index-1].click(), fireEvents(all.item[A_Index-1])
Break
}
Return True
}
fireEvents(ele)
{
Pos := 1, h := "\bon\w+\b(?==)"
COM_Error(0)
While Pos := RegExMatch(ele.outerHTML,h,m,Pos+StrLen(m))
ele.fireEvent[m]
COM_Error(1)
return
}
inpt(i)
{
type := i.TagName
if type in BUTTON,INPUT,OPTION,SELECT,TEXTAREA
Return True
}
And as always any comments or suggestions about the above code, even though it is a prototype, is welcomed.