; Module/File: EditField_AddIconWithFunctions.pb ; Function: Add icon(s) to StringGadget (GtkEntry) with functions, UTF8 - Linux up to gtk3.10 ; Author: Omi ; Date: Jan. 02, 2014 ; Version: 0.4, updt. utf8-handling, key ; Target Compiler: PureBasic 5.22/5.31 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit ImportC "" gtk_entry_set_icon_from_stock(*entry.GtkEntry, icon_pos, stock_id.p-utf8) gtk_entry_set_icon_activatable(*entry.GtkEntry, icon_pos, activatable) gtk_entry_set_icon_sensitive(*entry.GtkEntry, icon_pos, sensitive) gtk_entry_set_icon_tooltip_text(*entry.GtkEntry, icon_pos, tooltip.p-utf8) g_signal_connect(*instance, detailed_signal.p-utf8, *c_handler, *data, destroy= 0, flags= 0) As "g_signal_connect_data" g_signal_emit_by_name(*instance, detailed_signal.p-utf8, *data, stop= 0) EndImport ; Object constants #MainWin= 0 #Strg1 = 0 #Strg2 = 1 #Strg3 = 2 #WinX= 300 #WinY= 200 #WinW= 300 #WinH= 150 Global.i gEvent, gQuit ProcedureC EntryIconClicked(*widget, *signal, user_data) ;*widget contains the data given at creation time of this handler ;*signal contains the detailed signal Select *widget Case GadgetID(#Strg1) Debug "StringGadget 1" If *signal= 0; left icon Debug "Left Icon: Search" EndIf Case GadgetID(#Strg2) Debug "StringGadget 2" If *signal= 1; right icon Debug "Right Icon: Clear" SetGadgetText(#Strg2, "") EndIf Case GadgetID(#Strg3) Debug "StringGadget 3" If *signal= 0; left icon Debug "Left Icon: Search" ElseIf *signal= 1; right icon Debug "Right Icon: Clear" EndIf EndSelect Debug "" EndProcedure If OpenWindow(#MainWin, #WinX, #WinY, #WinW, #WinH, "Add StringGadget-Icons with functions", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) StringGadget(#Strg1, 5, 5, 150, 26, "Click Icon") StringGadget(#Strg2, 5, 35, 150, 26, "Click Icon") StringGadget(#Strg3, 5, 65, 150, 26, "Click Icons") ;add left icon gtk_entry_set_icon_from_stock(GadgetID(#Strg1), 0, "gtk-find"); '0' = pos left, System-Icon gtk_entry_set_icon_activatable(GadgetID(#Strg1), 0, #True) gtk_entry_set_icon_sensitive(GadgetID(#Strg1), 0, #True) ;add right icon gtk_entry_set_icon_from_stock(GadgetID(#Strg2), 1, "gtk-clear"); '1' = pos right gtk_entry_set_icon_activatable(GadgetID(#Strg2), 1, #True) gtk_entry_set_icon_sensitive(GadgetID(#Strg2), 1, #True) ;add both icons gtk_entry_set_icon_from_stock(GadgetID(#Strg3), 0, "gtk-find"); '0' = pos left gtk_entry_set_icon_activatable(GadgetID(#Strg3), 0, #True) gtk_entry_set_icon_sensitive(GadgetID(#Strg3), 0, #True) gtk_entry_set_icon_from_stock(GadgetID(#Strg3), 1, "gtk-clear"); AND '1' = pos left gtk_entry_set_icon_activatable(GadgetID(#Strg3), 1, #True) gtk_entry_set_icon_sensitive(GadgetID(#Strg3), 1, #True) ;add tooltips for icons gtk_entry_set_icon_tooltip_text(GadgetID(#Strg1), 0, "Tooltip zum zusätzlichen Icon. Hier könnte die Suche gestartet werden!") gtk_entry_set_icon_tooltip_text(GadgetID(#Strg2), 1, "Tooltip for additional icon. Here you can delete the text!") gtk_entry_set_icon_tooltip_text(GadgetID(#Strg3), 0, "[F3] Tooltip for additional icon. Here you could start searching!") gtk_entry_set_icon_tooltip_text(GadgetID(#Strg3), 1, "[Del] Tooltip zum zusätzlichen Icon. Hier könnte der Text gelöscht werden!") g_signal_connect(GadgetID(#Strg1), "icon_press", @EntryIconClicked(), 0) g_signal_connect(GadgetID(#Strg2), "icon_press", @EntryIconClicked(), 0) g_signal_connect(GadgetID(#Strg3), "icon_press", @EntryIconClicked(), 0) ;Add shortcut for 3rd StringGadget-Icon 0 and 1 ... AddKeyboardShortcut(#MainWin, #PB_Shortcut_F3, -4000 + #PB_Shortcut_F3) AddKeyboardShortcut(#MainWin, #PB_Shortcut_Delete, -4000 + #PB_Shortcut_Delete) Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_Menu Select EventMenu() Case (-4000 + #PB_Shortcut_F3) g_signal_emit_by_name(GadgetID(#Strg3), "icon_press", 0) Case (-4000 + #PB_Shortcut_Delete) g_signal_emit_by_name(GadgetID(#Strg3), "icon_press", 1) EndSelect EndSelect Until gQuit EndIf ; IDE Options = PureBasic 5.45 LTS (Linux - x86) ; Folding = - ; EnableUnicode ; EnableXP ; SubSystem = gtk2 ; CurrentDirectory = /home/charly-xubuntu/Programming/PureBasic/purebasic/