5 WebGadget functions implemented for Linux and MacOS

Share your advanced PureBasic knowledge/code with the community.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

5 WebGadget functions implemented for Linux and MacOS

Post by Shardik »

Unfortunately a lot of functions for the WebGadget are only implemented for Windows (red) or 2 for Windows and MacOS (orange, colorization by me):
Documentation for the WebGadget wrote: - SetGadgetItemText(): With #PB_Web_HtmlCode as 'Item' html code can be streamed into the Gadget. (Windows only)
- GetGadgetItemText(): The following constants can be used to get information (Windows only):

#PB_Web_HtmlCode : Get the html code from the gadget.
#PB_Web_PageTitle : Get the current title for the displayed page.
#PB_Web_StatusMessage: Get the current statusbar message.
#PB_Web_SelectedText : Get the currently selected text inside the gadget.

- SetGadgetAttribute(): Set the following attributes (Windows only):

#PB_Web_ScrollX : Set the horizontal scrolling position.
#PB_Web_ScrollY : Set the vertical scrolling position.
#PB_Web_BlockPopups : Block popup windows. #PB_EventType_PopupWindow is fired if this setting is enabled.
#PB_Web_BlockPopupMenu: Block standard the popup menu. #PB_EventType_PopupMenu is fired if this setting is enabled.
#PB_Web_NavigationCallback: Set a callback for monitoring (and disabling) navigation.

The Navigation callback must have the following format:

Procedure NavigationCallback(Gadget, Url$)
;
; Return #True to allow this navigation or #False to deny it.
;
ProcedureReturn #True
EndProcedure

- GetGadgetAttribute(): Get the following attributes (Windows only):

#PB_Web_ScrollX : Get the horizontal scrolling position.
#PB_Web_ScrollY : Get the vertical scrolling position.
#PB_Web_Busy : Returns nonzero if the gadget is busy loading a page.
#PB_Web_Progress : Returns the current (sometimes estimated) progress after a #PB_EventType_DownloadProgress event.
#PB_Web_ProgressMax : Returns the current (sometimes estimated) maximum progress after a #PB_EventType_DownloadProgress event.
#PB_Web_BlockPopups : Get the current popupwindow blocking setting.
#PB_Web_BlockPopupMenu: Get the current popupmenu blocking setting.
#PB_Web_NavigationCallback: Get the current navigation callback (if any).

The following types of events can happen for this gadget:

#PB_EventType_TitleChange : The page title changed (Windows only).
#PB_EventType_StatusChange : The status message changed (Windows only).
#PB_EventType_DownloadStart : A page download started (Windows, OS X).
#PB_EventType_DownloadProgress: Progress info is available with GetGadgetAttribute() (Windows only).
#PB_EventType_DownloadEnd : A page download ended or aborted (Windows, OS X).
#PB_EventType_PopupWindow : A popup window was blocked (Windows only).
#PB_EventType_PopupMenu : The popup menu was blocked (display a custom menu here) (Windows only).
Since several years many requests for implementing the missing functions also for Linux and MacOS have been made. In several threads in the English or German forum I have already tried to help out by implementing some of the missing functions for either Linux or MacOS. In order to centralize these efforts I now have programmed two cross-platform examples which demonstrate how to use the 5 most requested functions for the WebGadget in cross-platform code.

Example 1: Navigation callback (combining the code for Linux and MacOS from my feature request 5 years ago with the native callback on Windows)

Code: Select all

; Successful tests:
; -----------------
; + Linux Mint 18.3 x64 'Sylvia' with PB 5.46 x64 using GTK2 and GTK3 in
;   ASCII- and Unicode mode and with PB 5.62 x64 using GTK2 and GTK3 
; + MacOS 10.6.8 'Snow Leopard' with PB 5.46 x86 in ASCII- and Unicode mode and
;   PB 5.62 x86
; + MacOS 10.13.6 'High Sierra' with PB 5.46 x86 and x64 in ASCII- and
;   Unicode mode and PB 5.62 x86 and x64
; + Windows 7 SP1 x64 with PB 5.46 x86 and x64 in ASCII- and Unicode mode and
;   PB 5.62 x86 and x64

EnableExplicit

#URL = "https://www.purebasic.com/news.php"

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    ImportC "-lgobject-2.0"
      g_signal_connect_data(*Instance, Signal.P-UTF8, *Callback, *UserData,
        *ClosureNotify, ConnectFlags.I)
    EndImport

    CompilerIf Subsystem("gtk2")
      ImportC "-lwebkitgtk-1.0"
    CompilerElse
      ImportC "-lwebkitgtk-3.0"
    CompilerEndIf
      webkit_web_navigation_action_get_original_uri(*NavigationAction)
      webkit_web_policy_decision_ignore(*PolicyDecision)
      webkit_web_policy_decision_use(*PolicyDecision)
    EndImport

    ProcedureC NavigationCallback(*WebView, *Frame, *Request,
      *NavigationAction, *PolicyDecision, UserData)
      If PeekS(webkit_web_navigation_action_get_original_uri(*NavigationAction),
        -1, #PB_UTF8) = #URL
        MessageRequester("Info", "No news today!")
        webkit_web_policy_decision_ignore(*PolicyDecision)
      Else
        webkit_web_policy_decision_use(*PolicyDecision)
      EndIf
    EndProcedure
  CompilerCase #PB_OS_MacOS
    Define AppDelegate = CocoaMessage(0,
      CocoaMessage(0, 0, "NSApplication sharedApplication"), "delegate")
    Define DelegateClass = CocoaMessage(0, AppDelegate, "class")

    ProcedureC PolicyDecisionMaker(Object.I, Selector.I, WebView.I,
      ActionInformation.I, Request.I, *FrameName, Listener.I)
      Protected *URL = CocoaMessage(0, Request, "URL")
      Protected URL.S = PeekS(CocoaMessage(0,
        CocoaMessage(0, *URL, "absoluteString"), "UTF8String"), -1, #PB_UTF8)

        If URL = #URL
          MessageRequester("Info", "No news today!")
        Else
          CocoaMessage(0, Listener, "use")
        EndIf
    EndProcedure

    class_addMethod_(DelegateClass, sel_registerName_("webView:" +
      "decidePolicyForNavigationAction:request:frame:decisionListener:"),
      @PolicyDecisionMaker(), "v@:@@@@@")
  CompilerCase #PB_OS_Windows
    Procedure NavigationCallback(WebGadget.I, URL.S)
      If URL = #URL
        MessageRequester("Info", "No news today!")
        ProcedureReturn #False
      Else 
        ProcedureReturn #True 
      EndIf 
    EndProcedure 
CompilerEndSelect

OpenWindow(0, 100, 100, 600, 300, "WebGadget")
WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    g_signal_connect_data(GadgetID(0), "navigation-policy-decision-requested",
      @NavigationCallback(), 0, 0, 0)
  CompilerCase #PB_OS_MacOS
    CocoaMessage(0, GadgetID(0), "setPolicyDelegate:", AppDelegate)
  CompilerCase #PB_OS_Windows
    SetGadgetAttribute(0, #PB_Web_NavigationCallback, @NavigationCallback())
CompilerEndSelect

Repeat 
Until WaitWindowEvent() = #PB_Event_CloseWindow
Example 2:
Implementation of Linux and MacOS code combined with these native Windows calls:
- GetGadgetItemText(#WebGadget, #PB_Web_HTMLCode)
- GetGadgetItemText(#WebGadget, #PB_Web_PageTitle)
- GetGadgetItemText(#WebGadget, #PB_Web_SelectedText)
- SetGadgetItemText(#WebGadget, #PB_Web_HTMLCode, HTML$)

Code: Select all

; Successful tests:
; -----------------
; + Linux Mint 18.3 x64 'Sylvia' with PB 5.46 x64 using GTK2 and GTK3 in
;   ASCII- and Unicode mode and with PB 5.62 x64 using GTK2 and GTK3 
; + MacOS 10.6.8 'Snow Leopard' with PB 5.46 x86 in ASCII- and Unicode mode and
;   PB 5.62 x86
; + MacOS 10.13.6 'High Sierra' with PB 5.46 x86 and x64 in ASCII- and
;   Unicode mode and PB 5.62 x86 and x64
; + Windows 7 SP1 x64 with PB 5.46 x86 and x64 in ASCII- and Unicode mode and
;   PB 5.62 x86 and x64

EnableExplicit

#HTML = "<h1>Finally you can use the most important WebGadget functions " +
  "cross-platform ;-)</h1>"
#URL = "http://www.purebasic.com"

Define SelectedText.S
Define Title.S

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    CompilerIf Subsystem("gtk2")
      ImportC "-lwebkitgtk-1.0"
    CompilerElse
      ImportC "-lwebkitgtk-3.0"
    CompilerEndIf
      webkit_web_data_source_get_data(*WebDataSource)
      webkit_web_frame_get_data_source(*WebFrame)
      webkit_web_view_can_copy_clipboard(*WebView)
      webkit_web_view_copy_clipboard(*WebView)
      webkit_web_view_get_main_frame(*WebView)
      webkit_web_view_get_title(*WebView)
      webkit_web_view_has_selection(*WebView)
      webkit_web_view_load_string(*WebView, Content.P-UTF8, *MimeType,
        *Encoding, *BaseURI)
    EndImport
      
    Define *Title
    Define WebData.I
    Define WebFrame.I
    Define *WebPageContent.GString
  CompilerCase #PB_OS_MacOS
    Define DOMRange.I
    Define *HTML
    Define JavaScriptString.S
CompilerEndSelect

OpenWindow(0, 100, 100, 590, 600, "Cross-platform WebGadget functions")

FrameGadget(0, 10, 10, WindowWidth(0) - 20, 65, "GetGadgetItemText()")
ButtonGadget(1, 20, 30, 160, 25, "#PB_Web_HTMLCode")
ButtonGadget(2, 215, 30, 160, 25, "#PB_Web_PageTitle")
ButtonGadget(3, 410, 30, 160, 25, "#PB_Web_SelectedText")

FrameGadget(4, 10, GadgetY(0) + GadgetHeight(0) + 20, WindowWidth(0) - 20, 65,
  "SetGadgetItemText()")
ButtonGadget(5, 220, GadgetY(4) + 20, 150, 25, "#PB_Web_HTMLCode")

WebGadget(6, 10, GadgetY(4) + GadgetHeight(4) + 15, WindowWidth(0) - 20,
  WindowHeight(0) - GadgetHeight(0) - 120, #URL)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          Debug GetGadgetText(1) + ":"

          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux   ; -------------------------------------
              WebFrame = webkit_web_view_get_main_frame(GadgetID(6)) 
              WebData = webkit_web_frame_get_data_source(WebFrame)
              *WebPageContent = webkit_web_data_source_get_data(WebData)
              Debug PeekS(*WebPageContent\str, -1, #PB_Ascii)
            CompilerCase #PB_OS_MacOS   ; -------------------------------------
              JavaScriptString = "document.documentElement.outerHTML;"
              *HTML = CocoaMessage(0, GadgetID(6),
                "stringByEvaluatingJavaScriptFromString:$", @JavaScriptString)
              Debug PeekS(CocoaMessage(0, *HTML, "UTF8String"), -1, #PB_UTF8)
            CompilerCase #PB_OS_Windows ; -------------------------------------
              Debug GetGadgetItemText(6, #PB_Web_HtmlCode)
          CompilerEndSelect

          Debug ""
        Case 2
          Title = ""
          Debug GetGadgetText(2) + ":"

          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux   ; -------------------------------------
              *Title = webkit_web_view_get_title(GadgetID(6))

              If *Title
                Title = PeekS(*Title, -1, #PB_UTF8)
              EndIf
            CompilerCase #PB_OS_MacOS   ; -------------------------------------
              JavaScriptString = "document.getElementsByTagName('title')[0]" +
                ".innerHTML;"
              *HTML = CocoaMessage(0, GadgetID(6),
                "stringByEvaluatingJavaScriptFromString:$", @JavaScriptString)
              Title = PeekS(CocoaMessage(0, *HTML, "UTF8String"), -1, #PB_UTF8)
            CompilerCase #PB_OS_Windows ; -------------------------------------
              Title = GetGadgetItemText(6, #PB_Web_PageTitle)
          CompilerEndSelect

          If Title = ""
            Title = "No title found!"
          EndIf

          Debug Title
          Debug ""
        Case 3
          SelectedText = ""
          Debug GetGadgetText(3) + ":"

          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux   ; -------------------------------------
              If webkit_web_view_has_selection(GadgetID(6))
                If webkit_web_view_can_copy_clipboard(GadgetID(6)) = #False
                  SelectedText = "The copying of selected text to the " +
                    "clipboard failed!"
                Else
                  webkit_web_view_copy_clipboard(GadgetID(6))
                  SelectedText = GetClipboardText()
                EndIf
              EndIf 
            CompilerCase #PB_OS_MacOS   ; -------------------------------------
              DOMRange = CocoaMessage(0, GadgetID(6), "selectedDOMRange")

              If DOMRange
                SelectedText = PeekS(CocoaMessage(0, CocoaMessage(0, DOMRange,
                  "text"), "UTF8String"), -1, #PB_UTF8)
              EndIf
            CompilerCase #PB_OS_Windows ; -------------------------------------
              SelectedText = GetGadgetItemText(6, #PB_Web_SelectedText)
          CompilerEndSelect

          If SelectedText = ""
            SelectedText = "No text is selected!"
          EndIf

          Debug SelectedText
          Debug ""
        Case 5
          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux   ; -------------------------------------
              webkit_web_view_load_string(GadgetID(6), #HTML, 0, 0, 0)
            CompilerDefault             ; -------------------------------------
              SetGadgetItemText(6, #PB_Web_HtmlCode, #HTML)
          CompilerEndSelect
      EndSelect 
  EndSelect
ForEver
It would be nice if at least these 5 functions could be implemented natively in PureBasic's Linux and MacOS version... :P
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: 5 WebGadget functions implemented for Linux and MacOS

Post by wilbert »

On MacOS, this works fine.
It's only the documentation that's wrong.

Code: Select all

OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 

WebGadget(0, 10, 10, 580, 240, "")
ButtonGadget(1, 10, 260, 200, 30, "GetGadgetItemText")

SetGadgetItemText(0, #PB_Web_HtmlCode, "<html><title>Test</title><body><p>This is a <i>simple</i> test</body></html>")

Repeat
  Event = WaitWindowEvent()
  If Event = #PB_Event_Gadget
      Select EventGadget()
        Case 1
          S.s = GetGadgetItemText(0, #PB_Web_PageTitle)+#LF$+#LF$+
                GetGadgetItemText(0, #PB_Web_HtmlCode)+#LF$+#LF$+
                GetGadgetItemText(0, #PB_Web_SelectedText)
          MessageRequester("GetGadgetItemText", S)
      EndSelect
    EndIf
Until Event = #PB_Event_CloseWindow
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: 5 WebGadget functions implemented for Linux and MacOS

Post by the.weavster »

Thanks Shardik :)

Do you know of a way calling PB procedures from JavaScript?
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: 5 WebGadget functions implemented for Linux and MacOS

Post by Shardik »

wilbert wrote:On MacOS, this works fine.
It's only the documentation that's wrong.
How could I have overlooked that GetGadgetItemText() with #PB_Web_HtmlCode, #PB_Web_PageTitle and #PB_Web_SelectedText is already implemented in PureBasic for Mac, especially after having found out that SetGadgetItemText(#WebGadget, #PB_Web_HtmlCode, HTML$) is working fine as you can see in my usage of CompilerDefault in "Case 5" (for MacOS and Windows) in my 2nd example above...:oops:

But there still seems to be an error in the MacOS implementation of GetGadgetItemText(#WebGadget, #PB_Web_HtmlCode) when reading a real website. Your example is working fine but try to replace

Code: Select all

WebGadget(0, 10, 10, 580, 240, "")
ButtonGadget(1, 10, 260, 200, 30, "GetGadgetItemText")

SetGadgetItemText(0, #PB_Web_HtmlCode, "<html><title>Test</title><body><p>This is a <i>simple</i> test</body></html>")
with

Code: Select all

WebGadget(0, 10, 10, 580, 240, "http://www.purebasic.com")
ButtonGadget(1, 10, 260, 200, 30, "GetGadgetItemText")

; SetGadgetItemText(0, #PB_Web_HtmlCode, "<html><title>Test</title><body><p>This is a <i>simple</i> test</body></html>")
Reading out title and a selected text works fine but reading out the complete HTML doesn't work.

I have now modified my 2nd example from above to use CompilerDefault for MacOS and Windows when reading out title and selected text. I have left my 2nd example from above unchanged for those who want to know a possible technique for reading out title and selected text.

Code: Select all

EnableExplicit

#HTML = "<h1>Finally you can use the most important WebGadget functions " +
  "cross-platform ;-)</h1>"
#URL = "http://www.purebasic.com"

Define SelectedText.S
Define Title.S

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    CompilerIf Subsystem("gtk2")
      ImportC "-lwebkitgtk-1.0"
    CompilerElse
      ImportC "-lwebkitgtk-3.0"
    CompilerEndIf
      webkit_web_data_source_get_data(*WebDataSource)
      webkit_web_frame_get_data_source(*WebFrame)
      webkit_web_view_can_copy_clipboard(*WebView)
      webkit_web_view_copy_clipboard(*WebView)
      webkit_web_view_get_main_frame(*WebView)
      webkit_web_view_get_title(*WebView)
      webkit_web_view_has_selection(*WebView)
      webkit_web_view_load_string(*WebView, Content.P-UTF8, *MimeType,
        *Encoding, *BaseURI)
    EndImport
      
    Define *Title
    Define WebData.I
    Define WebFrame.I
    Define *WebPageContent.GString
  CompilerCase #PB_OS_MacOS
    Define *HTML
    Define JavaScriptString.S
CompilerEndSelect

OpenWindow(0, 100, 100, 590, 600, "Cross-platform WebGadget functions")

FrameGadget(0, 10, 10, WindowWidth(0) - 20, 65, "GetGadgetItemText()")
ButtonGadget(1, 20, 30, 160, 25, "#PB_Web_HTMLCode")
ButtonGadget(2, 215, 30, 160, 25, "#PB_Web_PageTitle")
ButtonGadget(3, 410, 30, 160, 25, "#PB_Web_SelectedText")

FrameGadget(4, 10, GadgetY(0) + GadgetHeight(0) + 20, WindowWidth(0) - 20, 65,
  "SetGadgetItemText()")
ButtonGadget(5, 220, GadgetY(4) + 20, 150, 25, "#PB_Web_HTMLCode")

WebGadget(6, 10, GadgetY(4) + GadgetHeight(4) + 15, WindowWidth(0) - 20,
  WindowHeight(0) - GadgetHeight(0) - 120, #URL)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 1
          Debug GetGadgetText(1) + ":"

          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux
              WebFrame = webkit_web_view_get_main_frame(GadgetID(6)) 
              WebData = webkit_web_frame_get_data_source(WebFrame)
              *WebPageContent = webkit_web_data_source_get_data(WebData)
              Debug PeekS(*WebPageContent\str, -1, #PB_Ascii)
            CompilerCase #PB_OS_MacOS
              JavaScriptString = "document.documentElement.outerHTML;"
              *HTML = CocoaMessage(0, GadgetID(6),
                "stringByEvaluatingJavaScriptFromString:$", @JavaScriptString)
              Debug PeekS(CocoaMessage(0, *HTML, "UTF8String"), -1, #PB_UTF8)
            CompilerCase #PB_OS_Windows
              Debug GetGadgetItemText(6, #PB_Web_HtmlCode)
          CompilerEndSelect

          Debug ""
        Case 2
          Title = ""
          Debug GetGadgetText(2) + ":"

          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux
              *Title = webkit_web_view_get_title(GadgetID(6))

              If *Title
                Title = PeekS(*Title, -1, #PB_UTF8)
              EndIf
            CompilerDefault
              Title = GetGadgetItemText(6, #PB_Web_PageTitle)
          CompilerEndSelect

          If Title = ""
            Title = "No title found!"
          EndIf

          Debug Title
          Debug ""
        Case 3
          SelectedText = ""
          Debug GetGadgetText(3) + ":"

          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux
              If webkit_web_view_has_selection(GadgetID(6))
                If webkit_web_view_can_copy_clipboard(GadgetID(6)) = #False
                  SelectedText = "The copying of selected text to the " +
                    "clipboard failed!"
                Else
                  webkit_web_view_copy_clipboard(GadgetID(6))
                  SelectedText = GetClipboardText()
                EndIf
              EndIf 
            CompilerDefault
              SelectedText = GetGadgetItemText(6, #PB_Web_SelectedText)
          CompilerEndSelect

          If SelectedText = ""
            SelectedText = "No text is selected!"
          EndIf

          Debug SelectedText
          Debug ""
        Case 5
          CompilerSelect #PB_Compiler_OS
            CompilerCase #PB_OS_Linux
              webkit_web_view_load_string(GadgetID(6), #HTML, 0, 0, 0)
            CompilerDefault
              SetGadgetItemText(6, #PB_Web_HtmlCode, #HTML)
          CompilerEndSelect
      EndSelect 
  EndSelect
ForEver
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: 5 WebGadget functions implemented for Linux and MacOS

Post by wilbert »

Shardik wrote:But there still seems to be an error in the MacOS implementation of GetGadgetItemText(#WebGadget, #PB_Web_HtmlCode) when reading a real website.
Very strange.
The url of the PB website you are mentioning doesn't show a source.
If you try the url of the PB forum, SpiderBasic, CNN or Google website, it does show source code. :?
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: 5 WebGadget functions implemented for Linux and MacOS

Post by Shardik »

I have tested wilbert's example also on older PB versions and it's always working like a charm:
- PB 4.51 x86 (Carbon framework)
- PB 4.61 x86 (Carbon framework)
- PB 5.00 x86 (default Cocoa framework and subsystem "Carbon")

So the documentation of the implemented WebGadget functions for the MacOS version is wrong since many years. I have therefore posted this problem in the "Bugs - Documentation" subforum.
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: 5 WebGadget functions implemented for Linux and MacOS

Post by Shardik »

the.weavster wrote:Do you know of a way calling PB procedures from JavaScript?
For which operating system? Until now I only have seen a Windows solution posted by waldschrath in this thread.
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: 5 WebGadget functions implemented for Linux and MacOS

Post by wombats »

It seems #PB_Web_HtmlCode, #PB_Web_SelectedText and #PB_Web_PageTitle are implemented for the Qt SubSystem on Linux.

I thought it would be possible to do a NavigationCallback with the QtScript command, but I'm having no luck. It would be great if it worked under Qt, too.

Code: Select all

Runtime Procedure OnWebGadgetClick()
  MessageRequester("", "Click!")
EndProcedure  

If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
  WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com") 
  
  QtScript(~"gadget(\"0\").page.LinkDelegationPolicy = 2") ; http://doc.qt.io/archives/qt-4.8/qwebpage.html#LinkDelegationPolicy-enum
  QtScript(~"gadget(\"0\").clicked.connect(function() { Runtime.call(\"OnWebGadgetClick()\"); })")

  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
Post Reply