; Module/File: TG_LabelAddLink_2.pb ; Function: Add web and other links to TextGadget - Linux ; Author: Omi ; Date: Dec. 29, 2014 ; Version: 0.2 (08-2017) ; Target Compiler: PureBasic 5.22/5.31/5.4/5.5/5.6 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit ImportC "" g_signal_connect(*instance, detailed_signal.p-utf8, *c_handler, *data, destroy= 0, flags= 0) As "g_signal_connect_data" gtk_label_set_markup(*label.GtkWidget, markup.p-utf8) gtk_widget_set_tooltip_text(*widget.GtkWidget, text.p-utf8) EndImport ; Object constants #Win_Main= 0 #Text1 = 0 #Text2 = 1 #Text3 = 2 #Text4 = 3 Global.i gEvent, gQuit ProcedureC Callback_TextGadgetLink(*gadget, *uri, user_data) Protected.i Ret= #False Protected.s S= PeekS(*uri, -1, #PB_UTF8) If S= "http://www.chabba.de/" Debug "open URI" ElseIf S= "open_msgbox" MessageRequester("Label-link-demo", "Here you can call any function!") Ret= #True EndIf ProcedureReturn Ret EndProcedure Procedure.s TextGadgetAddLink(Gadget, Link.s, Text.s) Protected *widget.GtkText= GadgetID(Gadget) Protected.s S= "" + Text + "" ProcedureReturn S EndProcedure Procedure TextGadgetActivateLink(Gadget, Link.s) Protected *widget.GtkText= GadgetID(Gadget) gtk_label_set_use_markup_(*widget, #True) If Link<> "" gtk_widget_set_tooltip_text(*widget, Link) EndIf g_signal_connect(*widget, "activate-link", @Callback_TextGadgetLink(), 0) EndProcedure If OpenWindow(#Win_Main, 300, 200, 300, 200, "TextGadget - with link ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) TextGadget(#Text1, 5, 5, 290, 80, "") SetGadgetText(#Text1, "Here is a slightly longer TextGadget with a line break and a " + TextGadgetAddLink(#Text1, "http://www.chabba.de/", "URI-Link") + " within the text! The URI can be set as a tooltip if only " + " 1 link is created. In addition, an " + TextGadgetAddLink(#Text1, "open_msgbox", "other-link") + " can be set.") TextGadgetActivateLink(#Text1, ""); activate without tooltip (=""), because of 2 links can't get different tooltips. Otherwise take your URI Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True EndSelect Until gQuit EndIf ; IDE Options = PureBasic 5.45 LTS (Linux - x86) ; CursorPosition = 8 ; Folding = - ; EnableUnicode ; EnableXP