Da ja unter Linux x64 das WebGadget nicht verfügbar ist, habe ich mal angefangen, ein Interface für das WebKitGTK zu schreiben. Genauer für den WebView-Teil davon. Aus dem WebKit werden nur die nötigen Funktionen importiert. Das ganze ist an OOP angelehnt.
System: Ubuntu 10.10 x64, benötigtes/getestetes Package: libwebkit-1.0-2
Unter x86 nicht getestet, sollte aber auch funktionieren, sofern die Bibliothek installiert und der Pfad richtig gesetzt ist: AWPB_InitWebKit("/usr/lib/libwebkit-1.0.so.2") Rückgabe ist #True bei Erfolg, sonst #False.
Das WebView-Gadget wird in einem Container-Gadget erzeugt. Dieses wird automatisch angelegt. Die übergebene GadgetID gehört zu diesem Container. Die Events der WebView können nicht mit den PureBasic-Befehlen abgefangen werden, dafür sind die Callbacks nötig. Scrollbalken werden automatisch hinzugefügt, falls nötig.
awwebview.pbi
Code: Alles auswählen
;{ WebKit-Imports
PrototypeC.i ____AWPB_WebKit_Proto_web_view_new()
PrototypeC.i ____AWPB_WebKit_Proto_web_view_load_uri(*webview, uri.p-ascii)
PrototypeC.i ____AWPB_WebKit_Proto_web_frame_get_uri(*frame)
PrototypeC.i ____AWPB_WebKit_Proto_web_view_get_load_status(*webview)
PrototypeC.i ____AWPB_WebKit_Proto_web_view_load_string(*webview, content.p-ascii, mime_type.p-ascii, encoding.p-ascii, base_uri.p-ascii)
PrototypeC.i ____AWPB_WebKit_Proto_web_view_get_title(*webview)
PrototypeC.i ____AWPB_WebKit_Proto_download_get_uri(*download)
PrototypeC   ____AWPB_WebKit_Proto_web_policy_decision_ignore(*decision)
PrototypeC   ____AWPB_WebKit_Proto_web_policy_decision_download(*decision)
PrototypeC   ____AWPB_WebKit_Proto_web_policy_decision_use(*decision)
PrototypeC.i ____AWPB_WebKit_Proto_network_request_get_uri(*request)
PrototypeC   ____AWPB_WebKit_Proto_web_view_go_back(*web_view)
PrototypeC   ____AWPB_WebKit_Proto_web_view_go_forward(*web_view)
PrototypeC   ____AWPB_WebKit_Proto_web_view_stop_loading(*web_view)
Structure ____AWPB_WebKit_table
  LibName.s
  LibHandle.i
  web_view_new.____AWPB_WebKit_Proto_web_view_new
  web_view_load_uri.____AWPB_WebKit_Proto_web_view_load_uri
  web_frame_get_uri.____AWPB_WebKit_Proto_web_frame_get_uri
  web_view_get_load_status.____AWPB_WebKit_Proto_web_view_get_load_status
  web_view_load_string.____AWPB_WebKit_Proto_web_view_load_string
  web_view_get_title.____AWPB_WebKit_Proto_web_view_get_title
  download_get_uri.____AWPB_WebKit_Proto_download_get_uri
  web_policy_decision_ignore.____AWPB_WebKit_Proto_web_policy_decision_ignore
  web_policy_decision_download.____AWPB_WebKit_Proto_web_policy_decision_download
  web_policy_decision_use.____AWPB_WebKit_Proto_web_policy_decision_use
  network_request_get_uri.____AWPB_WebKit_Proto_network_request_get_uri
  web_view_go_back.____AWPB_WebKit_Proto_web_view_go_back
  web_view_go_forward.____AWPB_WebKit_Proto_web_view_go_forward
  web_view_stop_loading.____AWPB_WebKit_Proto_web_view_stop_loading
EndStructure
Define ____AWPB_WebKit.____AWPB_WebKit_table
Define ____AWPB_WebKit_lib_initialized.b = #False
Enumeration
  #____AWPB_WEBKIT_NAVIGATION_ACCEPT
  #____AWPB_WEBKIT_NAVIGATION_IGNORE
  #____AWPB_WEBKIT_NAVIGATION_DOWNLOAD
EndEnumeration
;}
;{ support functions
Procedure.b AWPB_InitWebKit(LibraryFile$)
  Shared ____AWPB_WebKit, ____AWPB_WebKit_lib_initialized
  
  If Not ____AWPB_WebKit_lib_initialized
    With ____AWPB_WebKit
      \LibName   = LibraryFile$
      \LibHandle = OpenLibrary(#PB_Any, LibraryFile$)
      If IsLibrary(\LibHandle)
        \web_view_new                 = GetFunction(\LibHandle, "webkit_web_view_new")
        \web_view_load_uri            = GetFunction(\LibHandle, "webkit_web_view_load_uri")
        \web_frame_get_uri            = GetFunction(\LibHandle, "webkit_web_frame_get_uri")
        \web_view_get_load_status     = GetFunction(\LibHandle, "webkit_web_view_get_load_status")
        \web_view_load_string         = GetFunction(\LibHandle, "webkit_web_view_load_string")
        \web_view_get_title           = GetFunction(\LibHandle, "webkit_web_view_get_title")
        \download_get_uri             = GetFunction(\LibHandle, "webkit_download_get_uri")
        \web_policy_decision_ignore   = GetFunction(\LibHandle, "webkit_web_policy_decision_ignore")
        \web_policy_decision_download = GetFunction(\LibHandle, "webkit_web_policy_decision_download")
        \web_policy_decision_use      = GetFunction(\LibHandle, "webkit_web_policy_decision_use")
        \network_request_get_uri      = GetFunction(\LibHandle, "webkit_network_request_get_uri")
        \web_view_go_back             = GetFunction(\LibHandle, "webkit_web_view_go_back")
        \web_view_go_forward          = GetFunction(\LibHandle, "webkit_web_view_go_forward")
        \web_view_stop_loading        = GetFunction(\LibHandle, "webkit_web_view_stop_loading")
        
        ____AWPB_WebKit_lib_initialized = \web_view_new And \web_view_load_uri And \web_frame_get_uri And \web_view_get_load_status And \web_view_load_string And \web_view_get_title And \download_get_uri And \web_policy_decision_download And \web_policy_decision_ignore And \web_policy_decision_use And \network_request_get_uri And \web_view_go_back And \web_view_go_forward And \web_view_stop_loading        
        
      EndIf
    EndWith
  EndIf
  
  ProcedureReturn ____AWPB_WebKit_lib_initialized
EndProcedure
Procedure   ____AWPB_WebKit_GTKSignalConnect(*Widget, Signal.s, *Function, *user_data)
  CompilerIf #PB_Compiler_Unicode
    Protected *SignalASCII, SignalLen.i
    
    SignalLen = Len(Signal)
    *SignalASCII = AllocateMemory(SignalLen + 2)
    If *SignalASCII
      PokeS(*SignalASCII, Signal, SignalLen, #PB_Ascii)
      CompilerIf #GTK_MAJOR_VERSION = 1
        gtk_signal_connect_(*Widget, *SignalASCII, *Function, *user_data)
      CompilerElse
        g_signal_connect_data_(*Widget, *SignalASCII, *Function, *user_data, 0, 0)
      CompilerEndIf
      FreeMemory(*SignalASCII)
    EndIf
  CompilerElse
    CompilerIf #GTK_MAJOR_VERSION = 1
      gtk_signal_connect_(*Widget, @Signal, *Function, *user_data)
    CompilerElse
      g_signal_connect_data_(*Widget, @Signal, *Function, *user_data, 0, 0)
    CompilerEndIf
  CompilerEndIf
EndProcedure
;}
;{ Callback Prototypes
Prototype   ____AWPB_WebView_CB_OnHoveringOverLink(title.s, uri.s)
Prototype   ____AWPB_WebView_CB_OnLoadProgressChanged(progress.l)
Prototype.l ____AWPB_WebView_CB_OnNavigationRequested(uri.s)
Prototype   ____AWPB_WebView_CB_OnPopulatePopup(*menu.GtkMenu)
Prototype   ____AWPB_WebView_CB_OnStatusBarTextChanged(arg1.s)
Prototype   ____AWPB_WebView_CB_OnTitleChanged(title.s)
;}
;{ WebKit-Object
Interface AWPB_WebView
    Destroy                           ()
    LoadURI                           (URI.s)
    LoadFile                          (FullFileName.s)
    LoadString                        (Content.s, Encoding.s = #NULL$, MimeType.s = #NULL$, BaseURI.s = "")
    Clear                             ()
    Hide                              (State)
    Disable                           (State)
    GadgetHeight.i                    ()
    GadgetWidth.i                     ()
    GadgetX.i                         ()
    GadgetY.i                         ()
    ResizeGadget                      (x, y, Width, Height)
    Back                              ()
    Forward                           ()
    Stop                              ()
    OnHoveringOverLink                (*callback.____AWPB_WebView_CB_OnHoveringOverLink)
    OnLoadProgressChanged             (*callback.____AWPB_WebView_CB_OnLoadProgressChanged)
    OnNavigationRequested             (*callback.____AWPB_WebView_CB_OnNavigationRequested)
    OnPopulatePopup                   (*callback.____AWPB_WebView_CB_OnPopulatePopup)
    OnStatusBarTextChanged            (*callback.____AWPB_WebView_CB_OnStatusBarTextChanged)
    OnTitleChanged                    (*callback.____AWPB_WebView_CB_OnTitleChanged)
    
EndInterface
Structure ____AWPB_WebView
    *vt.AWPB_WebView
    ContainerID.i
    *WebView
    *Scroller
    
    *OnHoveringOverLink.____AWPB_WebView_CB_OnHoveringOverLink
    *OnLoadProgressChanged.____AWPB_WebView_CB_OnLoadProgressChanged
    *OnNavigationRequested.____AWPB_WebView_CB_OnNavigationRequested
    *OnPopulatePopup.____AWPB_WebView_CB_OnPopulatePopup
    *OnStatusBarTextChanged.____AWPB_WebView_CB_OnStatusBarTextChanged
    *OnTitleChanged.____AWPB_WebView_CB_OnTitleChanged
    
    InitialPageLoaded.b    
EndStructure
;{ Constants
#AWPB_WEBKIT_NAVIGATION_ACCEPT   = #____AWPB_WEBKIT_NAVIGATION_ACCEPT
#AWPB_WEBKIT_NAVIGATION_IGNORE   = #____AWPB_WEBKIT_NAVIGATION_IGNORE
#AWPB_WEBKIT_NAVIGATION_DOWNLOAD = #____AWPB_WEBKIT_NAVIGATION_DOWNLOAD
;}
;{ Event Callbacks
ProcedureCDLL   ____AWPB_WebView_OnHoveringOverLinkCB(*webView, *title, *uri, *gdg.____AWPB_WebView)
  Protected title.s, uri.s
  
  If *gdg\OnHoveringOverLink
    If *title : title = PeekS(*title, -1, #PB_Ascii) : Else : title = "" : EndIf
    If *uri   : uri   = PeekS(*uri,   -1, #PB_Ascii) : Else : uri   = "" : EndIf
  
    *gdg\OnHoveringOverLink(title, uri)
  EndIf
EndProcedure
ProcedureCDLL   ____AWPB_WebView_OnLoadProgressChangedCB(*WebView, progress.l, *gdg.____AWPB_WebView)
  If *gdg\OnLoadProgressChanged
    *gdg\OnLoadProgressChanged(progress)
  EndIf
EndProcedure
ProcedureCDLL.l ____AWPB_WebView_OnNavigationRequestedCB(*WebView, *frame, *request, *gdg.____AWPB_WebView)
  Shared ____AWPB_WebKit
  Protected *uri, uri.s, action.l
  
  If *gdg\OnNavigationRequested
    *uri = ____AWPB_WebKit\network_request_get_uri(*request)
    If *uri
      If *gdg\InitialPageLoaded
        uri    = PeekS(*uri, -1, #PB_Ascii)
        action = *gdg\OnNavigationRequested(uri)
      
        ProcedureReturn action
      Else
        *gdg\InitialPageLoaded = #True
      EndIf
    EndIf
  EndIf
  
  ProcedureReturn #____AWPB_WEBKIT_NAVIGATION_ACCEPT
EndProcedure
ProcedureCDLL   ____AWPB_WebView_OnPopulatePopupCB(*WebView, *menu.GtkMenu, *gdg.____AWPB_WebView)
  If *gdg\OnPopulatePopup
    *gdg\OnPopulatePopup(*menu)
  EndIf
EndProcedure
ProcedureCDLL   ____AWPB_WebView_OnStatusBarTextChangedCB(*WebKit, *arg1, *gdg.____AWPB_WebView)
  Protected arg1.s
  
  If *gdg\OnStatusBarTextChanged
    If *arg1
      arg1 = PeekS(*arg1, -1, #PB_Ascii)
      *gdg\OnStatusBarTextChanged(arg1)
    EndIf
  EndIf
EndProcedure
ProcedureCDLL   ____AWPB_WebView_OnTitleChangedCB(*WebView, *frame, *title, *gdg.____AWPB_WebView)
  Protected title.s
  
  If *gdg\OnTitleChanged
    If *title
      title = PeekS(*title, -1, #PB_Ascii)
      *gdg\OnTitleChanged(title)
    EndIf
  EndIf
EndProcedure
;}
;{ Member Procedures
Procedure.i AWPB_WebView(GadgetID, x, y, Width, Height, Flags)
  Shared ____AWPB_WebKit, ____AWPB_WebKit_lib_initialized
  Protected *this.____AWPB_WebView, res.b
  
  If ____AWPB_WebKit_lib_initialized
    res   = #False
    *this = AllocateMemory(SizeOf(____AWPB_WebView))
    If *this 
      *this\vt   = ?____AWPB_WebView_VT
      If GadgetID = #PB_Any
        *this\ContainerID = ContainerGadget(#PB_Any, x, y, Width, Height, Flags)
        If *this\ContainerID : res = #True : EndIf
      Else
        *this\ContainerID = GadgetID
        If ContainerGadget(GadgetID, x, y, Width, Height, Flags) : res = #True : EndIf
      EndIf
      If res
        CloseGadgetList()
        
        *this\OnHoveringOverLink     = #Null
        *this\OnLoadProgressChanged  = #Null
        *this\OnNavigationRequested  = #Null
        *this\OnPopulatePopup        = #Null
        *this\OnStatusBarTextChanged = #Null
        *this\OnTitleChanged         = #Null
        *this\InitialPageLoaded      = #False
        *this\Scroller = gtk_scrolled_window_new_(#Null, #Null)
        If *this\Scroller
          gtk_scrolled_window_set_policy_(*this\Scroller, #GTK_POLICY_AUTOMATIC, #GTK_POLICY_AUTOMATIC)
          gtk_widget_set_size_request_(*this\Scroller, GadgetWidth(*this\ContainerID), GadgetHeight(*this\ContainerID))
          *this\WebView  = ____AWPB_webkit\web_view_new()
          If *this\WebView
            gtk_container_add_(*this\Scroller, *this\WebView)
            gtk_container_add_(GadgetID(*this\ContainerID), *this\Scroller)
            
            ____AWPB_WebKit_GTKSignalConnect(*this\WebView, "hovering-over-link",      @____AWPB_WebView_OnHoveringOverLinkCB(),     *this)
            ____AWPB_WebKit_GTKSignalConnect(*this\WebView, "load-progress-changed",   @____AWPB_WebView_OnLoadProgressChangedCB(),  *this)
            ____AWPB_WebKit_GTKSignalConnect(*this\WebView, "navigation-requested",    @____AWPB_WebView_OnNavigationRequestedCB(),  *this)
            ____AWPB_WebKit_GTKSignalConnect(*this\WebView, "populate-popup",          @____AWPB_WebView_OnPopulatePopupCB(),        *this)
            ____AWPB_WebKit_GTKSignalConnect(*this\WebView, "status-bar-text-changed", @____AWPB_WebView_OnStatusBarTextChangedCB(), *this)
            ____AWPB_WebKit_GTKSignalConnect(*this\WebView, "title-changed",           @____AWPB_WebView_OnTitleChangedCB(),         *this)
            gtk_widget_set_events_(*this\WebView, #GDK_ALL_EVENTS_MASK)
            
            gtk_widget_show_(*this\Scroller)
            gtk_widget_show_(*this\WebView)
            
            ProcedureReturn *this
          EndIf
        EndIf
      EndIf
      FreeMemory(*this)
    EndIf
  EndIf
  
  ProcedureReturn #Null
EndProcedure
Procedure.i ____AWPB_WebView_Destroy(*this.____AWPB_WebView)
  If IsGadget(*this\ContainerID)
    FreeGadget(*this\ContainerID)
  EndIf  
  FreeMemory(*this)  
  ProcedureReturn #Null
EndProcedure
Procedure   ____AWPB_WebView_LoadURI(*this.____AWPB_WebView, URI.s)
  Shared ____AWPB_WebKit
  
  If URI <> ""
    *this\InitialPageLoaded = #False
    ____AWPB_WebKit\web_view_load_uri(*this\WebView, URI)
  EndIf  
EndProcedure
Procedure   ____AWPB_WebView_LoadFile(*this.____AWPB_WebView, FullFileName.s)
  Shared ____AWPB_WebKit
  
  If FullFileName <> ""
    *this\InitialPageLoaded = #False
    ____AWPB_WebKit\web_view_load_uri(*this\WebView, "file://" + FullFileName)
  EndIf  
EndProcedure
Procedure   ____AWPB_WebView_LoadString(*this.____AWPB_WebView, Content.s, MimeType.s, Encoding.s, BaseURI.s)
  Shared ____AWPB_WebKit
  
  ____AWPB_WebKit\web_view_load_string(*this\WebView, Content, MimeType, Encoding, BaseURI)
EndProcedure
Procedure   ____AWPB_WebView_Clear(*this.____AWPB_WebView)
  Shared ____AWPB_WebKit
  
  ____AWPB_WebKit\web_view_load_string(*this\WebView, "", "text/plain", #NULL$, "")  
EndProcedure
Procedure   ____AWPB_WebView_Hide(*this.____AWPB_WebView, State)
  HideGadget(*this\ContainerID, State)
EndProcedure
Procedure   ____AWPB_WebView_Disable(*this.____AWPB_WebView, State)
  DisableGadget(*this\ContainerID, State)
EndProcedure
Procedure.i ____AWPB_WebView_GadgetHeight(*this.____AWPB_WebView)
  ProcedureReturn GadgetHeight(*this\ContainerID)
EndProcedure
Procedure.i ____AWPB_WebView_GadgetWidth(*this.____AWPB_WebView)
  ProcedureReturn GadgetWidth(*this\ContainerID)
EndProcedure
Procedure.i ____AWPB_WebView_GadgetX(*this.____AWPB_WebView)
  ProcedureReturn GadgetX(*this\ContainerID)
EndProcedure
Procedure.i ____AWPB_WebView_GadgetY(*this.____AWPB_WebView)
  ProcedureReturn GadgetY(*this\ContainerID)
EndProcedure
Procedure   ____AWPB_WebView_ResizeGadget(*this.____AWPB_WebView, x, y, Width, Height)
  ResizeGadget(*this\ContainerID, x, y, Width, Height)
  gtk_widget_set_size_request_(*this\Scroller, GadgetWidth(*this\ContainerID), GadgetHeight(*this\ContainerID))
EndProcedure
Procedure   ____AWPB_WebView_Back(*this.____AWPB_WebView)
  Shared ____AWPB_WebKit
  
  ____AWPB_WebKit\web_view_go_back(*this\WebView)
EndProcedure
Procedure   ____AWPB_WebView_Forward(*this.____AWPB_WebView)
  Shared ____AWPB_WebKit
  
  ____AWPB_WebKit\web_view_go_forward(*this\WebView)
EndProcedure
Procedure   ____AWPB_WebView_Stop(*this.____AWPB_WebView)
  Shared ____AWPB_WebKit
  
  ____AWPB_WebKit\web_view_stop_loading(*this\WebView)
EndProcedure
Procedure   ____AWPB_WebView_Set_OnHoveringOverLink(*this.____AWPB_WebView, *callback.____AWPB_WebView_CB_OnHoveringOverLink)
  *this\OnHoveringOverLink = *callback
EndProcedure
Procedure   ____AWPB_WebView_Set_OnLoadProgressChanged(*this.____AWPB_WebView, *callback.____AWPB_WebView_CB_OnLoadProgressChanged)
  *this\OnLoadProgressChanged = *callback
EndProcedure
Procedure   ____AWPB_WebView_Set_OnNavigationRequested(*this.____AWPB_WebView, *callback.____AWPB_WebView_CB_OnNavigationRequested)
  *this\OnNavigationRequested = *callback
EndProcedure
Procedure   ____AWPB_WebView_Set_OnPopulatePopup(*this.____AWPB_WebView, *callback.____AWPB_WebView_CB_OnPopulatePopup)
  *this\OnPopulatePopup = *callback
EndProcedure
Procedure   ____AWPB_WebView_Set_OnStatusBarTextChanged(*this.____AWPB_WebView, *callback.____AWPB_WebView_CB_OnStatusBarTextChanged)
  *this\OnStatusBarTextChanged = *callback
EndProcedure
Procedure   ____AWPB_WebView_Set_OnTitleChanged(*this.____AWPB_WebView, *callback.____AWPB_WebView_CB_OnTitleChanged)
  *this\OnTitleChanged = *callback
EndProcedure
;}
DataSection ;{ Virtual Function Table
____AWPB_WebView_VT:
  Data.i @____AWPB_WebView_Destroy()
  Data.i @____AWPB_WebView_LoadURI()
  Data.i @____AWPB_WebView_LoadFile()
  Data.i @____AWPB_WebView_LoadString()
  Data.i @____AWPB_WebView_Clear()
  Data.i @____AWPB_WebView_Hide()
  Data.i @____AWPB_WebView_Disable()
  Data.i @____AWPB_WebView_GadgetHeight()
  Data.i @____AWPB_WebView_GadgetWidth()
  Data.i @____AWPB_WebView_GadgetX()
  Data.i @____AWPB_WebView_GadgetY()
  Data.i @____AWPB_WebView_ResizeGadget()
  Data.i @____AWPB_WebView_Back()
  Data.i @____AWPB_WebView_Forward()
  Data.i @____AWPB_WebView_Stop()
  Data.i @____AWPB_WebView_Set_OnHoveringOverLink()
  Data.i @____AWPB_WebView_Set_OnLoadProgressChanged()
  Data.i @____AWPB_WebView_Set_OnNavigationRequested()
  Data.i @____AWPB_WebView_Set_OnPopulatePopup()
  Data.i @____AWPB_WebView_Set_OnStatusBarTextChanged()
  Data.i @____AWPB_WebView_Set_OnTitleChanged()
  
EndDataSection ;}
;}
Demo 1:
Code: Alles auswählen
EnableExplicit
XIncludeFile "awwebview.pbi"
; Callback Procedures
Procedure TitleChangedCB(title.s)
  PrintN("New Page Title: " + title)
;  Debug "New Page Title: " + title
EndProcedure
Procedure LinkOverCB(title.s, link.s)
  PrintN("Mouse over Link: " + link + " * Title: " + title)
;  Debug "Mouse over Link: " + link
EndProcedure
Procedure.i NavigationRequestedCB(link.s)
  PrintN("Navigate: " + link)
;  Debug "Navigate: " + link
  ProcedureReturn #AWPB_WEBKIT_NAVIGATION_IGNORE
EndProcedure
Procedure StatusBarTextCB(text.s)
  PrintN("Status Text: " + text)
;  Debug "Status Text: " + text
EndProcedure
Procedure PopulatePopupCB(*Menu.GtkMenu)
  PrintN("Popup called")
;  Debug "Popup called"
EndProcedure
Procedure ProgressChangedCB(progress.l)
  PrintN("Progress: " + Str(progress))
;  Debug "Progress: " + Str(progress)
EndProcedure
   
Define *webview.AWPB_WebView, event
OpenConsole()
If AWPB_InitWebKit("/usr/lib/libwebkit-1.0.so.2")
  OpenWindow(0, 0, 0, 800, 400, "WebKit Demo")
  
  *webview = AWPB_WebView(1, 5, 5, 790, 390, #PB_Container_Raised)
  If *webview
    *webview\OnHoveringOverLink(@LinkOverCB())
    *webview\OnLoadProgressChanged(@ProgressChangedCB())
    *webview\OnNavigationRequested(@NavigationRequestedCB())
    *webview\OnPopulatePopup(@PopulatePopupCB())
    *webview\OnStatusBarTextChanged(@StatusBarTextCB())
    *webview\OnTitleChanged(@TitleChangedCB())
    
    *webview\LoadURI("http://www.purebasic.com")
  
    Repeat
      event = WaitWindowEvent()
    Until event = #PB_Event_CloseWindow
  EndIf
Else
  MessageRequester("Fehler", "Kann WebKit-Library nicht initialisieren!")
EndIfDemo 2: (Anpassung der WebGadget-Demo aus der Anleitung)
Code: Alles auswählen
EnableExplicit
XIncludeFile "awwebview.pbi"
; Callback Procedures
Procedure.i NavigationCallback(url.s)
  If Url = "http://www.purebasic.com/news.php" 
    MessageRequester("", "No news today!") 
    ProcedureReturn #AWPB_WEBKIT_NAVIGATION_IGNORE
  Else 
    ProcedureReturn #AWPB_WEBKIT_NAVIGATION_ACCEPT
  EndIf 
EndProcedure
Define *webview.AWPB_WebView
If AWPB_InitWebKit("/usr/lib/libwebkit-1.0.so.2")
  If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    *webview = AWPB_WebView(0, 10, 10, 580, 280, #PB_Container_Raised)
    If *webview
      *webview\OnNavigationRequested(@NavigationCallback())
      *webview\LoadURI("http://www.purebasic.com")
  
      Repeat 
      Until WaitWindowEvent() = #PB_Event_CloseWindow
    EndIf
  EndIf
Else
  MessageRequester("Fehler", "Kann WebKit-Library nicht initialisieren!")
EndIfDemo 3: (Anpassung des Mini-Browser Examples; Downloads nicht möglich)
Code: Alles auswählen
EnableExplicit
XIncludeFile "awwebview.pbi"
Define *webview.AWPB_WebView, Event
Procedure ResizeWebWindow()
  Shared *webview
  
  *webview\ResizeGadget(#PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0) - 52)
  ResizeGadget(4, #PB_Ignore, #PB_Ignore, WindowWidth(0)-185, #PB_Ignore)
  ResizeGadget(5, WindowWidth(0)-25, #PB_Ignore, #PB_Ignore, #PB_Ignore)
  ResizeGadget(6, #PB_Ignore, #PB_Ignore, WindowWidth(0), #PB_Ignore)
EndProcedure
If AWPB_InitWebKit("/usr/lib/libwebkit-1.0.so.2")
  If OpenWindow(0, 100, 200, 500, 300, "PureBasic MiniBrowser v1.0", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  
    CreateStatusBar(0, WindowID(0))
      AddStatusBarField(#PB_Ignore)
      StatusBarText(0, 0, "Welcome to the world's smallest Browser ! :)", 0)
        
    ButtonGadget(1,   0, 0, 50, 25, "Back")
    ButtonGadget(2,  50, 0, 50, 25, "Next")
    ButtonGadget(3, 100, 0, 50, 25, "Stop")
  
    StringGadget(4, 155, 5, 0, 20, "http://www.purebasic.com")
    
    ButtonGadget(5, 0, 0, 25, 25, "Go")
    
    Frame3DGadget(6, 0, 30, 0, 2, "", 2) ; Nice little separator
    
    *webview = AWPB_WebView(10, 0, 31, 0, 0, #PB_Container_Raised)
    If *webview
      *webview\LoadURI("http://www.purebasic.com")
    
      AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
    
      ResizeWebWindow()
    
      Repeat
        Event = WaitWindowEvent()
        
        Select Event
          Case #PB_Event_Gadget
          
            Select EventGadget()
              Case 1
                *webview\Back()
              Case 2
                *webview\Forward()
              Case 3
                *webview\Stop()
              
              Case 5
                *webview\LoadURI(GetGadgetText(4))
                
            EndSelect      
          
          Case #PB_Event_Menu ; We only have one shortcut
            *webview\LoadURI(GetGadgetText(4))
    
          Case #PB_Event_SizeWindow
            ResizeWebWindow()
          
        EndSelect
          
      Until Event = #PB_Event_CloseWindow
    EndIf
  EndIf
Else
  MessageRequester("Fehler", "Kann WebKit-Library nicht initialisieren!")
EndIf
