SetGadgetState not implemented for ExplorerListGadget?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: SetGadgetState not implemented for ExplorerListGadget?

Post by Shardik »

MuuSer wrote:I have implemented this feature now by Windows API, but this means, that it’s not crossportable. :(
You may use the following cross-platform procedure SelectExplorerListRow() which uses the appropriate API functions of MacOS, Linux and Windows to select a row in an ExplorerListGadget:

Code: Select all

EnableExplicit

Procedure SelectExplorerListRow(ExplorerListID.I, RowIndex.I)
  If RowIndex < CountGadgetItems(ExplorerListID)
    SetActiveGadget(ExplorerListID)

    CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Linux
        Protected TreePath.I = gtk_tree_path_new_from_indices_(RowIndex, -1)
        gtk_tree_view_set_cursor_(GadgetID(ExplorerListID), TreePath, 0, #False)
      CompilerCase #PB_OS_MacOS
        Protected IndexSet.I
        IndexSet = CocoaMessage(0, CocoaMessage(0, 0, "NSIndexSet alloc"),
          "initWithIndex:", RowIndex)
        CocoaMessage(0, GadgetID(ExplorerListID),
          "selectRowIndexes:", IndexSet,
          "byExtendingSelection:", #NO)
        CocoaMessage(0, IndexSet, "release")
      CompilerCase #PB_OS_Windows
        Protected Item.LVITEM
        Item\mask = #LVIF_STATE
        Item\state = #LVIS_SELECTED
        Item\stateMask = #LVIS_SELECTED
        SendMessage_(GadgetID(ExplorerListID), #LVM_SETITEMSTATE, RowIndex, @Item)
    CompilerEndSelect
  EndIf
EndProcedure

OpenWindow(0, 270, 100, 400, 200, "ExplorerListGadget")
; ---- Attention: The flag #PB_Explorer_AlwaysShowSelection is necessary to
;      see a selected entry in Windows OS
ExplorerListGadget(0, 10, 10, 380, 180, "/", #PB_Explorer_AlwaysShowSelection)
SelectExplorerListRow(0, 0)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: SetGadgetState not implemented for ExplorerListGadget?

Post by Shardik »

Sorry, it's much easier because PB has a native command to select and unselect a row in an ExplorerListGadget, so there is no need to use platform-specific API functions:

Code: Select all

SetGadgetItemState(#Gadget, Item, State)
Use State = #PB_Explorer_Selected to select a row
and State = 0 to unselect a row (this is currently only documented for the ListViewGadget, but seems to work even cross-plattform for the ExplorerListGadget as demonstrated in this example)
Post Reply