ListItemPos1.src 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. XCOMM! CDE_INSTALLATION_TOP/bin/dtksh
  2. XCOMM $XConsortium: ListItemPos1.src /main/3 1996/04/23 20:18:21 drk $
  3. XCOMM #########################################################################
  4. XCOMM (c) Copyright 1993, 1994 Hewlett-Packard Company
  5. XCOMM (c) Copyright 1993, 1994 International Business Machines Corp.
  6. XCOMM (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  7. XCOMM (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
  8. XCOMM Novell, Inc.
  9. XCOMM #########################################################################
  10. XCOMM
  11. XCOMM This sample shell script demonstrates how to create a list widget, and
  12. XCOMM verifies that the XmListItemPos command operates correctly. The list
  13. XCOMM contains multiple items with the label "item4"; XmListItemPos will
  14. XCOMM return the position of the first occurrence. By selecting the push
  15. XCOMM button labeled "Delete First Item", you can delete the first item
  16. XCOMM labeled "item4"; the next call to XmListItemPos should now return
  17. XCOMM the position of the next item labeled "item4".
  18. XCOMM
  19. XCOMM Pushbutton Callback: prints the position occupied by the first occurrence
  20. XCOMM of the "item4" label.
  21. GetItemPosition()
  22. {
  23. XmListItemPos POS $LIST "item4"
  24. echo "First position for item4 is: "$POS
  25. }
  26. XCOMM Pushbutton Callback: deletes the first item in the list.
  27. DelFirstItem()
  28. {
  29. XmListDeletePos $LIST 1
  30. }
  31. XCOMM ###################### Create the Main UI ###############################
  32. XtInitialize TOPLEVEL listItemPos1 ListItemPos1 "$0" "$@"
  33. XtSetValues $TOPLEVEL allowShellResize:True
  34. XmCreateScrolledList LIST $TOPLEVEL list \
  35. itemCount:11 \
  36. items:"item4,item2,item4,item3,item5,item6,item7,item8,item9,item4,item11" \
  37. visibleItemCount:15 \
  38. listSizePolicy:VARIABLE
  39. XtSetValues $LIST \
  40. selectedItemCount:3 \
  41. selectedItems:"item2,item4,item6"
  42. XtManageChild $LIST
  43. XtRealizeWidget $TOPLEVEL
  44. XtCreateApplicationShell TOPLEVEL2 ListItemPos1a TopLevelShell
  45. XtCreateManagedWidget RC rc XmRowColumn $TOPLEVEL2 \
  46. orientation:HORIZONTAL \
  47. numColumns:2 \
  48. packing:PACK_COLUMN
  49. XtCreateManagedWidget PB1 pb1 XmPushButton $RC \
  50. labelString:"Get Position Of item4"
  51. XtAddCallback $PB1 activateCallback "GetItemPosition"
  52. XtCreateManagedWidget PB2 pb2 XmPushButton $RC \
  53. labelString:"Delete First Item"
  54. XtAddCallback $PB2 activateCallback "DelFirstItem"
  55. XtRealizeWidget $TOPLEVEL2
  56. XtMainLoop