03-21-2012, 02:16 PM
Updated 2014-04-30.
If does not work with portable Firefox: FireFox portable and FireFox functions (FirefoxGetTabs, ..)
This version gets accessible objects of tab buttons.
Also changed:
1. Renamed from Firefox4GetTabs to FirefoxGetTabs.
2. Error if does not find window or something fails.
3. names is optional, can be 0.
Function FirefoxGetTabs
Function FirefoxSelectTab
Or simply find and click tab button accessible object.
Acc a.Find(... "PAGETAB" ...)
a.DoDefaultAction
If does not work with portable Firefox: FireFox portable and FireFox functions (FirefoxGetTabs, ..)
This version gets accessible objects of tab buttons.
Also changed:
1. Renamed from Firefox4GetTabs to FirefoxGetTabs.
2. Error if does not find window or something fails.
3. names is optional, can be 0.
Function FirefoxGetTabs
;/
function# [hwndFF] [ARRAY(str)&names] [ARRAY(str)&urls] [ARRAY(Acc)&docObjects] [ARRAY(Acc)&buttonObjects]
;Gets names of Firefox tabs. Optionally gets their URL and accessible objects.
;Returns 0-based index of the selected tab.
;Error if fails.
;hwndFF - Firefox window handle. If 0, finds.
;names - variable for tab names. Can be 0 if don't need.
;urls - variable for addresses. Can be 0 if don't need.
;docObjects - variable for DOCUMENT accessible objects that represent web pages. Can be 0 if don't need.
;buttonObjects - variable for PAGETAB accessible objects that represent tab buttons. Can be 0 if don't need.
;REMARKS
;Requires QM 2.3.3 or later.
;Elements of urls and docObjects of non-loaded tabs will be empty. Firefox does not load pages in invisible tabs at startup.
;EXAMPLE
;ARRAY(str) names urls
;int selectedTab=FirefoxGetTabs(0 names urls)
;out selectedTab
;int i
;for i 0 names.len
,;out "--------[]%s[]%s" names[i] urls[i]
ARRAY(str) _names; if(!&names) &names=_names
names=0
if(&urls) urls=0
if(&docObjects) docObjects=0
if(&buttonObjects) buttonObjects=0
if(!hwndFF) hwndFF=win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804); if(!hwndFF) end ERR_WINDOW
int i r=-1
FFNode fn
ARRAY(str) ap
;enum tabs
Acc a.Find(hwndFF "PAGETAB" "" "class=MozillaWindowClass" 0x1004 1) ;;note: added 1 s waiting because fails when called first time after launching FF
rep
,if(a.Role!ROLE_SYSTEM_PAGETAB) goto next ;;[ + ] button
,
,names[]=a.Name
,if(&buttonObjects) buttonObjects[]=a
,
,;get selected tab
,if(r<0 and a.State&STATE_SYSTEM_SELECTED) r=i
,
,if &urls
,,;get id of associated pane and store in ap. Because the order of tabs and panes may be different.
,,fn.FromAcc(a)
,,ap[]=fn.Attribute("linkedpanel")
,
,;next
,a.Navigate("n"); err break
,i+1
if(r<0) end ERR_FAILED
if(!&urls and !&docObjects) ret r
;enum panes
if(&urls) urls.create(names.len)
if(&docObjects) docObjects.create(names.len)
#if QMVER<0x2030400
a.Find(hwndFF "DOCUMENT" "" "" 0x3000 0 0 "pa3fi")
err a.Find(hwndFF "" "" "" 0x3010 1 0 "pa4fi")
#else
a.Find(hwndFF "" "" "" 0x3000 2 0 "pa3fi")
#endif
rep
,;get id of this pane, and find in ap
,fn.FromAcc(a); _s=fn.Attribute("id")
,for(i 0 ap.len) if(ap[i]=_s) break
,if(i=names.len) goto next2 ;;should never happen
,;get DOCUMENT object and url
,Acc aa; a.Navigate("fi2" aa); err goto next2
,if(&urls) urls[i]=aa.Value
,if(&docObjects) docObjects[i]=aa
,
,;next2
,a.Navigate("n"); err break
ret r
err+ end _errorFunction FirefoxSelectTab
;/
function hwndFF $name [flags] ;;flags: 1 name is URL, 2 wildcard, 4 beginning, 8 end, 16 anywhere, 32 rx
;Finds and select Firefox tab.
;Error if not found.
;hwndFF - Firefox window handle. If 0, finds.
;name - tab name. If flag 1 - URL.
;flags:
;;;1 - name is URL.
;;;2-32 - how to compare name. Default: exact match. Always case insensitive.
;;;
ARRAY(str) names urls; ARRAY(Acc) a
int selectedTab=FirefoxGetTabs(hwndFF names iif(flags&1 &urls 0) 0 a)
int i
ARRAY(str)& as=iif(flags&1 urls names)
for i 0 names.len
,if SelStr(flags|1 as[i] name)
,,if i!=selectedTab
,,,a[i].DoDefaultAction
,,ret 1
end "tab not found"
err+ end _errorOr simply find and click tab button accessible object.
Acc a.Find(... "PAGETAB" ...)
a.DoDefaultAction
