home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / System / ScalosPrefs / examples / Blitz / big.bb2 < prev    next >
Text File  |  2000-08-23  |  4KB  |  151 lines

  1. ; Big example, perhaps something like what you'd use in a program :)
  2.  
  3. INCDIR "include:"
  4. XINCLUDE "scalos/preferences.bb2"
  5.  
  6.  
  7. ; Strings for preferences
  8. preffile$ = "example.prefs"     ; filename
  9. prefname$ = "Example"           ; prefshandle name (does not need to be same as filename)
  10.  
  11.  
  12. ; Default values for window position and sizes
  13. ww.w = 300
  14. wh.w = 200
  15. wx.w = 170
  16. wy.w = 100
  17.  
  18.  
  19. ; Create some stuff for showing in the listview
  20. NEWTYPE.gtlv_text
  21.     ln_Type.b
  22.     ln_Pri.b
  23.     ln_Name$
  24. End NEWTYPE
  25. Dim List text.gtlv_text(1000)
  26.  
  27.  
  28. ; Some random task temporary memory
  29. Dim temp.b(256)
  30.  
  31.  
  32. ; Allocate prefshandle. if successful, try to load the preferences and parse them
  33. *prefhandle.l = AllocPrefsHandle_(&prefname$)
  34. If *prefhandle
  35.     ReadPrefsHandle_ *prefhandle, &preffile$
  36.  
  37.     ; Read window data from file. if the tags do not exist, then nothing
  38.     ; will be written to the destination buffer, so our default positions
  39.     ; are safe. We use already existing tags for window positions (from
  40.     ; Intuition) as our tags values - hey saves us doing some thinking :)
  41.     ID.l = Cvl("WNDO")
  42.     GetPreferences_ *prefhandle, ID, #WA_Left, &wx, 2
  43.     GetPreferences_ *prefhandle, ID, #WA_Top, &wy, 2
  44.     GetPreferences_ *prefhandle, ID, #WA_Width, &ww, 2
  45.     GetPreferences_ *prefhandle, ID, #WA_Height, &wh, 2
  46.  
  47.     ; Read listview data from file
  48.     ID.l = Cvl("TEXT")
  49.     en.l = 0
  50.     While GetEntry_(*prefhandle, ID, 1, &temp(0), 256, en)
  51.         If AddLast(text())
  52.             text()\ln_Name = Peek$(&temp(0))
  53.         End If
  54.         en+1
  55.     Wend
  56. End If
  57.  
  58.  
  59. WbToScreen 0
  60. GTListView 0,1,4,4,ww-40,wh-60,"",0,text(),0,0
  61. GTString   0,2,4,4+wh-60,ww-80,14,"",0,256
  62. GTButton   0,3,4+ww-80,4+wh-60,40,14,"Del",$10
  63. Window 0,wx,wy,ww,wh,$100f,"Example",-1,-1
  64. DefaultOutput
  65. AttachGTList 0,0
  66.  
  67.  
  68. While ev.l<>#IDCMP_CLOSEWINDOW
  69.     ev = WaitEvent
  70.  
  71.     Select ev
  72.         Case #IDCMP_NEWSIZE
  73.             If ww <> WindowWidth OR wh <> WindowHeight
  74.                 ww = WindowWidth
  75.                 wh = WindowHeight
  76.                 DetachGTList 0
  77.                 Free GTList 0
  78.                 GTListView 0,1,4,4,ww-40,wh-60,"",0,text(),0,0
  79.                 GTString   0,2,4,4+wh-60,ww-80,14,"",0,256
  80.                 GTButton   0,3,4+ww-80,4+wh-60,40,14,"Del",$10
  81.                 InnerCls
  82.                 RefreshWindowFrame_ Peek.l(Addr Window(0))
  83.                 AttachGTList 0,0
  84.             End If
  85.  
  86.         Case #IDCMP_GADGETUP
  87.             Select GadgetHit
  88.                 Case 1
  89.                     lasthit.w = EventCode
  90.                     ResetList text()
  91.                     For i.w=0 To lasthit
  92.                         NextItem text()
  93.                     Next
  94.                     GTSetString 0,2,text()\ln_Name
  95.  
  96.                 Case 2
  97.                     GTChangeList 0,1
  98.                     If AddLast(text()) Then text()\ln_Name = GTGetString(0,2)
  99.                     GTChangeList 0,1,text()
  100.  
  101.                 Case 3
  102.                     GTChangeList 0,1
  103.                     ResetList text()
  104.                     For i.w=0 To lasthit
  105.                         NextItem text()
  106.                     Next
  107.                     KillItem text()
  108.                     GTChangeList 0,1,text()
  109.             End Select
  110.     End Select
  111. Wend
  112.  
  113. DetachGTList 0
  114.  
  115. If *prefhandle = 0 Then *prefhandle = AllocPrefsHandle_(&prefname$)
  116. If *prefhandle
  117.     ; set all the window preferences
  118.     wx = WindowX
  119.     wy = WindowY
  120.  
  121.     ID.l = Cvl("WNDO")
  122.     SetPreferences_ *prefhandle, ID, #WA_Left, &wx, 2
  123.     SetPreferences_ *prefhandle, ID, #WA_Top, &wy, 2
  124.     SetPreferences_ *prefhandle, ID, #WA_Width, &ww, 2
  125.     SetPreferences_ *prefhandle, ID, #WA_Height, &wh, 2
  126.  
  127.     ; Read listview data from file
  128.     ID.l = Cvl("TEXT")
  129.  
  130.     ; clear all items from pref list (probably a better way of doing this :)
  131.     While RemEntry_(*prefhandle, ID, 1, 0)
  132.     Wend
  133.  
  134.     ; set all the data items from the listview
  135.     ResetList text()
  136.     en = 0
  137.     While NextItem(text())
  138.         SetEntry_ *prefhandle, ID, 1, &text()\ln_Name, Len(text()\ln_Name)+1, en
  139.         en+1
  140.     Wend
  141.  
  142.     ; write the prefs file
  143.     WritePrefsHandle_ *prefhandle, &preffile$
  144.     FreePrefsHandle_ *prefhandle
  145. End If
  146.  
  147. CloseWindow 0
  148. CloseScreen 0
  149. End
  150.  
  151.