; Module/File: Gadget_SetNotifyCursor.pb ; Function: Set own cursor for notify/mouseover on gadgets - Linux ; Author: Omi ; Date: Aug. 16, 2017 ; Version: 0.1 ; 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 UsePNGImageDecoder() ImportC "" g_signal_connect(*instance, detailed_signal.p-utf8, *c_handler, *data, destroy= 0, flags= 0) As "g_signal_connect_data" gtk_widget_get_window(*widget.GtkWidget) EndImport ; Object constants #MainWin = 1 Enumeration #Txt1 #Image1 #Button1 EndEnumeration Global.i gEvent, gQuit Global *gEventbox.GtkEventBox ProcedureC Callback_GadgetSetCursor(*widget.GtkWidget, *event.GdkEventCrossing, user_data); callback for notify on label ;*widget gets the values from user_data. don't know why Protected *window= gtk_widget_get_toplevel_(GadgetID(*widget)) Protected *Cursor.GdkCursor Protected.i CursorType Select *widget Case #Txt1 : CursorType= #GDK_FLEUR Case #Image1 : CursorType= #GDK_QUESTION_ARROW Case #Button1 : CursorType= #GDK_HAND1 EndSelect Select *widget Case #Txt1, #Image1, #Button1 If *event\type = #GDK_ENTER_NOTIFY *Cursor= gdk_cursor_new_(CursorType) If *Cursor gdk_window_set_cursor_(gtk_widget_get_window(*window), *Cursor) EndIf ElseIf *event\type= #GDK_LEAVE_NOTIFY gdk_window_set_cursor_(gtk_widget_get_window(*window), #Null) EndIf EndSelect EndProcedure If OpenWindow(#MainWin, 300, 200, 250, 200, "Gadgets own cursor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) TextGadget (#Txt1, 5, 5, 240, 22, "Try Mouseover on TextGadget") If LoadImage(0, #PB_Compiler_Home + "logo.png") ImageGadget(#Image1, 5, 50, 48, 48, ImageID(0)) EndIf ButtonGadget (#Button1, 5, 120, 240, 26, "ButtonGadget w. own cursor") ; For display widget: TextGadget ... *gEventbox= gtk_widget_get_parent_(GadgetID(#Txt1)); get TextGadget-EventBox ; gtk_widget_add_events_(*gEventbox, #GDK_ENTER_NOTIFY_MASK); add notify event g_signal_connect(*gEventbox, "enter-notify-event", @Callback_GadgetSetCursor(), #Txt1, #Null, #G_CONNECT_SWAPPED) g_signal_connect(*gEventbox, "leave-notify-event", @Callback_GadgetSetCursor(), #Txt1, #Null, #G_CONNECT_SWAPPED) ; For display widget: ImageGadget ... *gEventbox= gtk_widget_get_parent_(GadgetID(#Image1)); get TextGadget-EventBox ; gtk_widget_add_events_(*gEventbox, #GDK_ENTER_NOTIFY_MASK); add notify event g_signal_connect(*gEventbox, "enter-notify-event", @Callback_GadgetSetCursor(), #Image1, #Null, #G_CONNECT_SWAPPED) g_signal_connect(*gEventbox, "leave-notify-event", @Callback_GadgetSetCursor(), #Image1, #Null, #G_CONNECT_SWAPPED) ; For Gadgets with already activated events... g_signal_connect(GadgetID(#Button1), "enter-notify-event", @Callback_GadgetSetCursor(), #Button1, #Null, #G_CONNECT_SWAPPED) g_signal_connect(GadgetID(#Button1), "leave-notify-event", @Callback_GadgetSetCursor(), #Button1, #Null, #G_CONNECT_SWAPPED) Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True EndSelect Until gQuit EndIf ; IDE Options = PureBasic 5.61 (Linux - x86) ; CursorPosition = 72 ; FirstLine = 4 ; Folding = - ; EnableXP ; EnableUnicode