Since PB 5.40 the default GTK version is no longer GTK2 but GTK3 although it's possible in PB 5.4x to use GTK2 as a subsystem (select "Compiler > Compiler Options..." in the menu bar of the IDE, select the tab "Compiler Options" and behind "Library Subsystem:" enter "gtk2").
In order to use the WebGadget you have to utilize WebKitGTK which requires one of these 2 libraries (you only have to install one of them if you don't need both):
- libwebkitgtk-1.0-0 (for GTK2)
- libwebkitgtk-3.0-0 (for GTK3)
By the way: WebKitGTK is deprecated. The current version WebKitGTK
2 is not supported by PureBasic because the WebGadget is still compiled with the old WebKitGTK...
Depending on your distribution one or both of these libraries might be installed already.
I have modified my code example from above to now work equally well with both GTK2 and GTK3 in both PB 5.3x and PB 5.4x and in x86 and x64 distributions. For the following distributions I had to install the following libraries with the appropriate console commands (of course you may also use Synaptic or Aptitude on Debian/Ubuntu derived distributions):
Kubuntu 16.04 x86 with KDE,
Ubuntu 16.04 x86 with Unity and
Xubuntu 16.04 x86 with Xfce
I found out that installing libwebkitgtk-1.0/libwebkitgtk-3.0 would require a whopping 1.669 MB of additional disk space because the dev and debug versions would also be installed. I therefore decided to install libwebkitgtk-1.0-0/libwebkitgtk-3.0-0 which only required about 40 MB. The drawback is that you have to always specify the complete path in your ImportC statement. When installing the dev version a simple
would be sufficient...
These are the console commands to install the libraries on Debian/Ubuntu derived distributions (it's only necessary to install one of these if you don't need both GTK2 and GTK3):
Code: Select all
sudo apt-get install libwebkitgtk-1.0-0
sudo apt-get install libwebkitgtk-3.0-0
In order to compile GTK2 programs you also have to install the GTK2 dev libs:
Code: Select all
sudo apt-get install libgtk2.0-dev
Lubuntu 14.04 x86 with LXDE (necessary only for GTK2)
Code: Select all
sudo apt-get install libwebkitgtk-1.0-0
Ubuntu MATE 14.04 x86 with MATE (necessary only for GTK2)
Code: Select all
sudo apt-get install libwebkitgtk-1.0-0
Linux Mint 17.3 x64 "Rosa" with Cinnamon
Nothing had to be done. All libraries for GTK2 and GTK3 were already preinstalled.
The distributions above are all derived from Debian/Ubuntu and utilize the Debian package management. Therefore I also tried a distribution with RPM packages derived from Red Hat (unfortunately the package names differ):
Fedora 23 x86 with Gnome 3
For GTK2:
webkitgtk2 is already installed by default!
And finally this is my modified example (for Fedora you have to put the ImportC block in comments and uncomment the Fedora ImportC line):
Code: Select all
EnableExplicit
ImportC "-lgobject-2.0"
g_signal_connect_data(*Instance, Signal.P-UTF8, *Callback, *UserData, *ClosureNotify, ConnectFlags.I)
EndImport
CompilerIf (#PB_Compiler_Version < 540 And Subsystem("gtk3") = #False) Or
(#PB_Compiler_Version >= 540 And Subsystem("gtk2") = #True)
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
ImportC "/usr/lib/i386-linux-gnu/libwebkitgtk-1.0.so.0" ; Ubuntu/Kubuntu/Xubuntu x86 with GTK2
CompilerElse
ImportC "/usr/lib/x86_64-linux-gnu/libwebkitgtk-1.0.so.0" ; Ubuntu/Kubuntu/Xubuntu x64 with GTK2
CompilerEndIf
; ImportC "/usr/lib/libwebkitgtk-1.0.so.0" ; Fedora 23 with GTK2
CompilerElse
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
ImportC "/usr/lib/i386-linux-gnu/libwebkitgtk-3.0.so.0" ; Ubuntu/Kubuntu/Xubuntu x86 with GTK3
CompilerElse
ImportC "/usr/lib/x86_64-linux-gnu/libwebkitgtk-3.0.so.0" ; Ubuntu/Kubuntu/Xubuntu x64 with GTK3
CompilerEndIf
; ImportC "/usr/lib/libwebkitgtk-3.0.so.0" ; Fedora 23 x86 with GTK3
CompilerEndIf
webkit_web_navigation_action_get_original_uri(*NavigationAction)
webkit_web_policy_decision_ignore(*PolicyDecision)
webkit_web_policy_decision_use(*PolicyDecision)
EndImport
Enumeration
#WEBKIT_NAVIGATION_RESPONSE_ACCEPT
#WEBKIT_NAVIGATION_RESPONSE_IGNORE
EndEnumeration
ProcedureC WebGadgetCallback(*WebView, *Frame, *Request, *NavigationAction, *PolicyDecision, UserData)
If PeekS(webkit_web_navigation_action_get_original_uri(*NavigationAction), -1, #PB_UTF8) = "http://www.purebasic.com/news.php"
MessageRequester("", "No news today!")
webkit_web_policy_decision_ignore(*PolicyDecision)
Else
webkit_web_policy_decision_use(*PolicyDecision)
EndIf
EndProcedure
If OpenWindow(0, 200, 100, 600, 300, "WebGadget")
WebGadget(0, 10, 10, 580, 280, "http://www.purebasic.com")
g_signal_connect_data(GadgetID(0), "navigation-policy-decision-requested", @WebGadgetCallback(), 0, 0, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
At last these were the warnings I did encounter (
only with GTK3):
Fedora 23 x86 with Gnome 3,
Ubuntu 16.04 x86 with Unity,
Xubuntu 16.04 x86 with Xfce
[WARNING] Gtk(MESSAGE): GtkDialog mapped without a transient parent. This is discouraged.
This warning has already been posted several times in the Linux bugs subforum.
Fred's response:Fred wrote:even gedit shipped with Ubuntu has some gtk error here when launched from CLI, so I don't think it's worth the time investigating.
Linux Mint 17.3 x64 "Rosa" with Cinnamon,
Lubuntu 14.04 x86 with LXDE,
Ubuntu MATE 14.04 x86 with LXDE
[WARNING] GLib-GObject (CRITICAL): g_object_ref: assertion 'object->ref_count > 0' failed
Fedora 23 x86 with Gnome 3
[WARNING] Gnome Shell Browser Plugin (DEBUG): plugin loaded
The only distributions without warnings were Kubuntu 14.04 x86 and Kubuntu 16.04 x86 both with KDE.