Page 1 of 1

ListIconGadget. Determining row and line under cursor.

Posted: Fri May 11, 2007 2:41 pm
by Hroudtwolf
Hello again,

Do anyone knows how to determine the row and the line under the mousecursor in ListIconGadget in PB-Linux 4.01 ?


Greetings :)

Wolf

Posted: Sat May 12, 2007 9:39 am
by walker
what do you mean with that?
knowing when the mouse is over the Listicon (i.e entry on line 4) to get the linenumber (5)? (something like mouseover event?)

Posted: Sat May 12, 2007 11:23 am
by Hroudtwolf
(something like mouseover event?)
Yes, exactly.
I need to get the row- and the line-number on mouseover.


Best regards

Wolf

Posted: Sat May 12, 2007 11:27 am
by milan1612
You mean row and column right? That's a question for srod :)

Posted: Sat May 12, 2007 11:58 am
by Hroudtwolf
milan1612 wrote:You mean row and column right? That's a question for srod :)
That's what I mean. :)
My english is very circumstantial. ^__^

Posted: Sat May 12, 2007 8:32 pm
by walker
ok.. here we go (though I'm not srod :shock: )

first you have to import a missing gtk-function gtk_tree_view_set_hover_selection
or include the following file in which I'd defined all (so far) found missing GTK-/ and GDK-functions (recommended)
http://home.arcor.de/x-linux/pure/missing_functions.pb

then it would be quite easy to determine the row under the mouse without having a click-event (you must use the change event)

Code: Select all

#tree_1=0
XIncludeFile "missing_functions.pb"

Procedure open_window_0()
OpenWindow(0,0,0,500,200,"test",#PB_Window_ScreenCentered|#PB_Window_TitleBar)
If CreateGadgetList(WindowID(0))      
   ListIconGadget(#tree_1,10,10,320,150,"spalte1",100,#PB_ListIcon_FullRowSelect);
   AddGadgetColumn(#tree_1,1,"spalte 2",100)
   For m=0 To 100
    AddGadgetItem(#tree_1,-1,"entry_"+RSet(Str(m),3,"0"))
    Next
EndIf
EndProcedure

open_window_0()

gtk_tree_view_set_hover_selection_(GadgetID(#tree_1),#True)


Repeat
event=WaitWindowEvent()
gadget=EventGadget()
event_type=EventType()
If event= #PB_Event_Gadget
    If gadget = #tree_1
        Select event_type   
            Case #PB_EventType_Change
                Debug "Change"
            Case #PB_EventType_LeftClick
;                 Debug "left"
            Case #PB_EventType_LeftDoubleClick
;                 Debug "left double"
            Case #PB_EventType_RightClick
;                 Debug "right"
            Case #PB_EventType_RightDoubleClick 
;                 Debug "right double"
        EndSelect
    EndIf
EndIf
Until event=#PB_Event_CloseWindow
END
Hope this helps a bit... :D

(Determining the column isn't that easy and would take some time (i don't have at present) to find out the way (there is much more GTK-API to be used to get this to work... I'd took a little preview.. if possible at all...))

Posted: Sun May 13, 2007 5:29 pm
by freak
I'm not srod either, but i have some code as well... ;)
Works for ListViewGadget, ListIconGadget, ExplorerListGadget, TreeGadget, because
they are all based on the same gtk widget.

Code: Select all

;
; Get the item and/or column index at the mouse position
; Works for: ListViewGadget, ListIconGadget, TreeGadget, ExplorerListGadget
;
; Usage: GetMousePosition(#Gadget, @Index, @Column)
; Either the @Index or @Column field can be #Null if the value is not needed.
;


; needed to get correct TreeGadget index
Structure tree_foreach_data
  TreePath.l
  ItemIndex.l
EndStructure

ProcedureC tree_foreach(*Model, *Path, *Iter, *user_data.tree_foreach_data)
  If gtk_tree_path_compare_(*Path, *user_data\TreePath) = 0
    ProcedureReturn #True
  Else
    *user_data\ItemIndex + 1
    ProcedureReturn #False   
  EndIf
EndProcedure

Procedure GetMousePosition(Gadget, *ItemIndex.LONG, *ColumnIndex.LONG)
  Protected x, y, *TreePath, *TreeColumn, *ColumnList.GList
  Protected foreach_data.tree_foreach_data

  gdk_window_get_pointer_(gtk_tree_view_get_bin_window_(GadgetID(Gadget)), @x, @y, 0)
  
  If gtk_tree_view_get_path_at_pos_(GadgetID(Gadget), x, y, @*TreePath, @*TreeColumn, #Null, #Null)
    If *ItemIndex
      If GadgetType(Gadget) = #PB_GadgetType_Tree
        foreach_data\TreePath = *TreePath
        gtk_tree_model_foreach_(gtk_tree_view_get_model_(GadgetID(Gadget)), @tree_foreach(), @foreach_data)
        *ItemIndex\l = foreach_data\ItemIndex
      Else
        *ItemIndex\l = PeekL(gtk_tree_path_get_indices_(*TreePath))
      EndIf
    EndIf
    gtk_tree_path_free_(*TreePath)
    
    If *ColumnIndex    
      *ColumnList = gtk_tree_view_get_columns_(GadgetID(Gadget))
      *ColumnIndex\l = g_list_index_(*ColumnList, *TreeColumn)
      g_list_free_(*ColumnList)
    EndIf
    ; *TreeColumn may not be freed!  
  Else
    ; No item under the cursor, or cursor not inside the gadget
    If *ItemIndex  : *ItemIndex\l = -1  : EndIf
    If *ColumnIndex: *ColumnIndex\l = -1: EndIf
  EndIf
EndProcedure 

; ============================================================
; Example
; ============================================================

#List = 0
#Text = 1

ProcedureC MouseEvent(*Widget.GtkWidget, *Event.GdkEventMotion, user_data)
  Protected ItemIndex, ColumnIndex
  
  GetMousePosition(#List, @ItemIndex, @ColumnIndex)
  SetGadgetText(#Text, "Cursor at: " + Str(ItemIndex) + "x" + Str(ColumnIndex))

EndProcedure


If OpenWindow(0, 0, 0, 300, 300, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  CreateGadgetList(WindowID(0))
  TextGadget(#Text, 10, 260, 280, 30, "", #PB_Text_Border)
  ListIconGadget(#List, 10, 10, 280, 240, "Col 0", 80)
  For i = 1 To 6
    AddGadgetColumn(#List, -1, "Col " + Str(i), 80)
  Next i
  
  For i = 0 To 25
    Text$ = ""
    For j = 0 To 6
      Text$ + Str(i) + "x" + Str(j) + Chr(10)
    Next j
  
    AddGadgetItem(#List, -1, Text$)
  Next i
  
  g_signal_connect_data_(GadgetID(#List), "motion-notify-event", @MouseEvent(), 0, #Null, #Null)
     
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Posted: Mon May 14, 2007 11:20 am
by Hroudtwolf
Thank you very much, Walker & Freak.
You are my rescuers. :)