[Mac] WebGadget 'find' dialog?

Mac OSX specific forum
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

[Mac] WebGadget 'find' dialog?

Post by kenmo »

Just wondering, does the Mac WebGadget have any sort of 'Find' dialog that can be triggered by code?

Maybe some clever CocoaMessage() can trigger it (if it exists)?


For comparison, on Windows you can open a simple but functional 'Find' dialog in the WebGadget by:

Code: Select all

*IWebBrowser2\ExecWB(#OLECMDID_FIND, #OLECMDEXECOPT_DODEFAULT, #Null, #Null)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [Mac] WebGadget 'find' dialog?

Post by Shardik »

The Mac and Linux versions of PB use the WebKit library for displaying contents in the WebGadget. I haven't found a WebKit function to display a 'find' dialog. The only dialogs I found were a file chooser and a print parameter dialog.

But the dialog shouldn't be the problem for you. I think the more important part is to search for a string in the HTML contents of the WebGadget and to highlight it. In MacOS this is realized by the Cocoa function searchFor:direction:caseSensitive:wrap: which seems to be a wrapper for the WebKit function webkit_web_view_search_text() which would be used in Linux.

For your conveniance I have put together a small MacOS code example which calls the procedure SearchString() to search for the string 'features' on http://www.purebasic.com and to highlight its first occurrence. A second click onto the search button finds and highlights the second occurrence and so on.

Code: Select all

Procedure SearchString(WebGadgetID.I, String.S, Forward.I = #YES,
  CaseSensitive.I = #NO, Wrap.I = #NO)
  CocoaMessage(0, GadgetID(WebGadgetID),
    "searchFor:$", @String,
    "direction:", Forward,
    "caseSensitive:", CaseSensitive,
    "wrap:", Wrap)
EndProcedure

OpenWindow(0, 270, 200, 800, 640, "WebGadget")
WebGadget(0, 0, 0, 800, 600, "http://www.purebasic.com")
ButtonGadget(1, 330, 610, 150, 25, "Search 'features'")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1
        SearchString(0, "features")
     EndIf
  EndSelect
ForEver
Update: I changed the arguments Forward, CaseSensitive and Wrap in the procedure SearchString() to optional ones and gave them a default value. In the procedure's CocoaMessage() I changed the constants against the variable names of the arguments. Thank you for pinpointing this error in your PM, Wilbert!
Last edited by Shardik on Fri May 16, 2014 6:55 pm, edited 1 time in total.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: [Mac] WebGadget 'find' dialog?

Post by kenmo »

Great! That is better than having no search feature at all. Thanks Shardik!
Post Reply