; Module/File: LIG_GetItemAtMousepos.pb ; Function: Get Item/row (Index) at mouse postiion - Linux ; Author: Omi ; Date: Jun. 17, 2016 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.4x ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- EnableExplicit ImportC "" gtk_tree_view_convert_widget_to_bin_window_coords(*tree_view.GtkTreeView, wx, wy, *bx, *by) gtk_tree_view_get_path_at_pos (*tree_view.GtkTreeView, x, y, *path, *column, *cell_x, *cell_y) EndImport ; Object constants #Win_Main= 0 #LIG = 0 Global.i gEvent, gQuit Procedure.i TV_GetItemAtCursor(Window, Gadget) Protected tPath Protected.i bx, by, item= -1 gtk_tree_view_convert_widget_to_bin_window_coords(GadgetID(Gadget), WindowMouseX(Window), WindowMouseY(Window), @bx, @by) gtk_tree_view_get_path_at_pos(GadgetID(Gadget), bx- GadgetX(Gadget)- 1, by- GadgetY(Gadget)- 1, @tpath, #Null, #Null, #Null) If tPath item= PeekL(gtk_tree_path_get_indices_(tpath)) EndIf ProcedureReturn item; returns found item EndProcedure ;- Example Procedure CreateWindow_Main() Protected.l I, O Protected *Column If OpenWindow(#Win_Main, 200, 200, 500, 400, "Get TreeView item @ cursor (rightclick)", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) ListIconGadget(#LIG, 5, 5, 490, 390, "Column 0", 90, #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_GridLines | #PB_ListIcon_CheckBoxes) For O= 1 To 4 AddGadgetColumn(#LIG, O, "Column "+Str(O), 90) Next O For I= 0 To 19 AddGadgetItem(#LIG, -1, Str(I)+"-0") For O= 1 To 4 SetGadgetItemText(#LIG, I, Str(I)+"-"+Str(O), O) Next O Next I EndIf EndProcedure CreateWindow_Main() Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_Gadget Select EventGadget() Case #LIG If EventType() = #PB_EventType_RightClick Debug TV_GetItemAtCursor(#Win_Main, #LIG) EndIf EndSelect EndSelect Until gQuit ; IDE Options = PureBasic 5.45 LTS (Linux - x86) ; CursorPosition = 3 ; Folding = - ; EnableUnicode ; EnableXP