Login | Register
My pages Projects Community openCollabNet

Discussions > commits > svn commit: r34 - trunk

genelib
Discussion topic

Back to topic list

svn commit: r34 - trunk

Author lotec
Full name Jan Bogaerts
Date 2006-03-24 11:18:22 PST
Message Author: lotec
Date: Fri Mar 24 11:18:22 2006
New Revision: 34

Modified:
   trunk/Controls.gen
   trunk/WUser32.gen
Log:
listbox has been implemented, compiles, not yet teested

Modified: trunk/Controls.gen
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/Contro​ls.gen?view=diff​&rev=34&p1=trunk​/Controls.gen&r1​=33&p2=trunk/Con​trols.gen&r2=34
====================​====================​====================​==================
--- trunk/Controls.gen (original)
+++ trunk/Controls.gen Fri Mar 24 11:18:22 2006
@@ -1313,11 +1313,14 @@
 //list boxes
 //------------------​--------------------​--------------------​--------------------​-------
 space sListBox;
+space sListBoxItems;
 
 space sListBoxItem =
  var fText: string //this will store the text if there is no Listbox
- Position: int = -1 //the index of the listbox Item as returned when it was created, don't change
+ Position: int = -1 //the index of the listbox Item as returned when it was created, don't change
+ Owner: sListBoxItems^ = nil //ref to the list that contains it
  prop Text: string read exp GetString: string write exp SetString(aValue: string&) //access the content of the listbox item
+ Selected: bool read exp GetSelected: bool write exp SetSelected(aValue: bool) //is this item selected or not (use only in multi seleciton box
  constructor Create virtual = ;
  destructor Destroy virtual = ;
 ;
@@ -1325,6 +1328,7 @@
 space sListBoxItems =
  entity sListBoxItem$
  store stLinkedList
+ space Owner //indicate that the ListBoxItem stores a ref to the space itself, so that sListBoxItems.entity is compacter
  var Owner: sListBox^
  operator '<<' AddItem(aItem: self.entity)
           '<<' InsertItem(aItem: self.entity, aBefore: self.entity)
@@ -1337,58 +1341,190 @@
  VScroll true
  BorderStyle 7
  AdditionalStyles LBS_Notify
- exp Sort
  prop ItemIndex: int read exp GetItemIndex: int write exp SetItemIndex(aValue: int) //which item is selected
       Items: sListBoxItems read var fItems: sListBoxItems.Create(self) //the list of items
       TopIndex: int read exp GetTopIndex: int write exp SetTopIndex(aValue: int) //Specifies the index number of the item that appears at the top of the list box.
- AutoRedraw: bool read exp GetAutoRedraw: bool write exp SetAutoRedraw(aValue: bool) //specifies if listbox is automatically redrawn when item is added or not
- Sorted: bool read var fSorted: bool = false write exp SetSorted(aValue: bool) //sorted or not, recreates the listbox
- MultiSelect: bool read var fMultiSelect: bool = false write exp SetMultiSelect(aVal: bool)//determins if multiselect or not, when changed, the object gets recreated, best set in construction list
- MultiColumn: bool read var fMultiColumn: bool = false write exp SetmultiColumn(aVal: bool)//does it have multiple columns or not, when changed, the object gets recreated, best set in construction list
- exp select(aStart: string) //selects the first item that begins with the given string
+// AutoRedraw: bool read exp GetAutoRedraw: bool write exp SetAutoRedraw(aValue: bool) //specifies if listbox is automatically redrawn when item is added or not
+// MultiSelect: bool read var fMultiSelect: bool = false write exp SetMultiSelect(aVal: bool)//determins if multiselect or not, when changed, the object gets recreated, best set in construction list
+// MultiColumn: bool read var fMultiColumn: bool = false write exp SetmultiColumn(aVal: bool)//does it have multiple columns or not, when changed, the object gets recreated, best set in construction list
+ exp FindString(aValue: string&, aAfter: sListBoxItem^): fItems.entity //search for text (case insensitive) after specified item, returns first item found that begins with the string
+ FindStringExact(aValue: string&, aAfter: sListBoxItem^): fItems.entity //search for text (case insensitive) after specified item, returns first item found that exactly matches the text
+ SelectString(aValue: string&, aAfter: sListBoxItem^): fItems.entity //search for text (case insensitive) after specified item, selects and returns first item found that begins with the string
+ DoSearch(aValue: string&, aAfter: sListBoxItem^, aSearchtype: dword): fItems.entity //internally used to perform the searches
 ;
 
 
-exp sListBoxItems.AddItem(aItem: sListBoxItems.entity)
+exp sListBoxItem.GetSelected: bool
 =
- //need to take into account that it is sorted or not
- [<-Owner <> nil->
- [<-Owner.Sorted == true->
- raise(Exception.Crea​te('ListBox: sorted add not yet implemented'))
- <-->
- aItem.Position = User32.SendMessage(T​oolBar.Handle, dword(LB_ADDSTRING), 0, int(aItem.fText.c_str))
- [<-aItem.Position == LB_ERR->
- raise(Exception.Create('Unable to add to the list'))
- ]
+ [<-Owner <> nil && Position > -1->
+ iRes: int
+ iRes = User32.SendMessage(O​wner.Owner.Handle, dword(LB_GETSEL), Position, 0)
+ [<-iRes == LB_ERR-> raise(Exception.Create('unable to get the selection value for the listbox item'))
+ <-iRes > 0-> return(true)
+ <--> return(false)
+ ]
+ ]
+ return(false)
+;
+
+exp sListBoxItem.SetSele​cted(aValue: bool)
+=
+ [<-Owner <> nil && Position > -1->
+ [<-User32.SendMes​sage(Owner.Owner.Han​dle, dword(LB_GETSEL), Position, 0) == LB_ERR->
+ raise(Exception.Create('unable to set the selection value for the listbox item'))
+ ]
+ <-->
+ raise(Exception.Create('Listbox item doesn|'t belong to a listbox, unable to set selected'))
+ ]
+;
+
+exp sListBoxItem.GetString: string
+=
+ iRes: string
+ [<-Owner == nil || Position == -1-> iRes = fText
+ <-->
+ iVal: int
+ iVal = User32.SendMessage(O​wner.Owner.Handle, dword(LB_GETTEXTLEN), Position, 0)
+ [<-iVal == lB_ERR->
+ raise(Exception.Create('unable to get the text value of the listbox item'))
+ ]
+ iRes.Nrrecords = iVal
+ [<-User32.SendMes​sage(Owner.Owner.Han​dle, dword(LB_GETTEXT), Position, int(iRes.c_str)) == LB_ERR->
+ raise(Exception.Create('unable to get the text value of the listbox item'))
       ]
    ]
+ return(iRes)
 ;
 
-exp sListBox.SetSorted(aValue: bool)
+exp sListBoxItem.SetString(aValue: string&)
 =
- //check if we want it sorted or not, if so, call the sort function
- [<-aValue == true-> Sort]
- fSorted = aValue
+ [<-Owner == nil || Position == -1->
+ fText = aValue
+ <-->
+ raise(Exception.Create('unable to change the text value of the listbox item'))
+ ]
 ;
 
-exp sListBox.Sort
+
+exp sListBoxItems.AddItem(aItem: sListBoxItems.entity)
 =
- raise(Exception.Crea​te('listbox: Sort not yet implemented'))
+ [<-aItem.Owner <> nil->
+ aItem ->> nil
+ raise(Exception.Create('Listbox item already belongs to another list'))
+ ]
+ [<-Owner <> nil && Owner.Handle <> nil->
+ aItem.Position = User32.SendMessage(O​wner.Handle, dword(LB_ADDSTRING), 0, int(aItem.fText.c_str))
+ [<-aItem.Position == LB_ERR->
+ raise(Exception.Create('Unable to add to the list'))
+ <-aItem.Position == LB_ERRSPACE->
+ raise(Exception.Create('Unable to add to the list because of insufficient memory'))
+ <-->
+ aItem.fText.ReleaseString //Listbox owns and manages the char^ data, so our string space cant
+ aItem.Owner = self
+ ]
+ <-->
+ raise(Exception.Create('object not created, unable to add to the listbox'))
+ ]
 ;
 
 exp sListBoxItems.InsertItem(aItem: sListBoxItems.entity, aBefore: sListBoxItems.entity)
 =
- #AddWarning('still have to check if the insert operator overloader is also called ')
+ [<-aItem.Owner <> nil->
+ aItem ->> nil
+ raise(Exception.Create('Listbox item already belongs to another list'))
+ ]
+ [<-Owner <> nil && Owner.Handle <> nil->
+ aItem.Position = User32.SendMessage(O​wner.Handle, dword(LB_INSERTSTRING), aBefore.Position, int(aItem.fText.c_str))
+ [<-aItem.Position == LB_ERR->
+ raise(Exception.Create('Unable to add to the list'))
+ <-aItem.Position == LB_ERRSPACE->
+ raise(Exception.Create('Unable to add to the list because of insufficient memory'))
+ <-->
+ aItem.fText.ReleaseString //Listbox owns and manages the char^ data, so our string space cant
+ aItem.Owner = self
+ ]
+ <-->
+ raise(Exception.Create('object not created, unable to add to the listbox'))
+ ]
 ;
+
 exp sListBoxItems.Removeitem(aItem: sListBoxItems.entity)
 =
+ [<-aItem.Owner == self-> //we need to make certain that the item belons to us (when we do an add, we first check if it isnt already in a list, if so, we remove it again)
+ [<-User32.SendMes​sage(Owner.Handle, dword(LB_DELETESTRING), aItem.Position, 0) == lB_ERR->
+ raise(Exception.Create('unable to remove the item from the listbox'))
+ ]
+ <--> //we don't own it so detach cause we can't destroy the mem
+ aItem.entity = nil
+ ]
 ;
 
 exp sListBoxItems.RemoveAllItems
 =
- #AddWarning('still have to check if the RemoveAllItems(clear) operator overloader is also called ')
+ User32.SendMessage(O​wner.Handle, dword(LB_RESETCONTENT), 0, 0)
+;
+
+exp sListBox.GetItemIndex: int
+=
+ iRes: int
+ iRes = User32.SendMessage(O​wner.Handle, dword(LB_GETCURSEL), 0, 0)
+ [<-iRes == LB_ERR->return(-1)]
+ return(iRes)
+;
+
+exp sListBox.GetTopIndex: int
+=
+ return(User32.SendMe​ssage(Owner.Handle, dword(LB_GETTOPINDEX), 0, 0))
+;
+
+exp sListBox.SetItemIndex(aValue: int)
+=
+ [<-User32.SendMes​sage(Owner.Handle, dword(LB_SETCURSEL), aValue, 0) == LB_ERR->
+ raise(exception.Create('invalid ItemIndex'))
+ ]
+;
+
+
+exp sListBox.SetTopIndex(aValue: int)
+=
+ [<-User32.SendMes​sage(Owner.Handle, dword(LB_SETTOPINDEX), aValue, 0) == LB_ERR->
+ raise(exception.Create('invalid ItemIndex'))
+ ]
+;
+
+exp sListBox.FindString(aValue: string&, aAfter: sListBoxItem^): fItems.entity
+=
+ DoSearch(aValue, aAfter, LB_FINDSTRING)
+;
+
+exp sListBox.FindStringE​xact(aValue: string&, aAfter: sListBoxItem^): fItems.entity
+=
+ DoSearch(aValue, aAfter, LB_FINDSTRINGEXACT)
+;
+
+exp sListBox.SelectString(aValue: string&, aAfter: sListBoxItem^): fItems.entity
+=
+ DoSearch(aValue, aAfter, LB_SELECTSTRING)
 ;
 
+exp sListBox.DoSearch(aValue: string&, aAfter: sListBoxItem^, aSearchtype: dword): fItems.entity
+=
+ iFound: int
+ iRes: fItems.entity
+
+ iFound = User32.SendMessage(O​wner.Handle, aSearchtype, aAfter.Position, int(aValue.c_str))
+ [<-iFound == LB_ERR->
+ iRes.cursor = nil
+ <-->
+ iRes = fItems@(iFound)
+ [<-iRes.Position <> iFound-> //sort might change the order
+ {<-fItems \ iRes->
+ [<-iRes.Position == ifound-> break]
+ }
+ ]
+ ]
+ return(iRes)
+;
 
 //Tab control
 //------------------​--------------------​--------------------​--------------------​-------

Modified: trunk/WUser32.gen
Url: http://genelib.tigri​s.org/source/browse/​genelib/trunk/WUser3​2.gen?view=diff&​rev=34&p1=trunk/​WUser32.gen&r1=3​3&p2=trunk/WUser​32.gen&r2=34
====================​====================​====================​==================
--- trunk/WUser32.gen (original)
+++ trunk/WUser32.gen Fri Mar 24 11:18:22 2006
@@ -1661,3 +1661,61 @@
  LBN_SETFOCUS = 4
  LBN_KILLFOCUS = 5
 ;
+
+
+
+
+//Listbox messages
+const
+ LB_ADDSTRING = 0x0180
+ LB_INSERTSTRING = 0x0181
+ LB_DELETESTRING = 0x0182
+ LB_SELITEMRANGEEX = 0x0183
+ LB_RESETCONTENT = 0x0184
+ LB_SETSEL = 0x0185
+ LB_SETCURSEL = 0x0186
+ LB_GETSEL = 0x0187
+ LB_GETCURSEL = 0x0188
+ LB_GETTEXT = 0x0189
+ LB_GETTEXTLEN = 0x018A
+ LB_GETCOUNT = 0x018B
+ LB_SELECTSTRING = 0x018C
+ LB_DIR = 0x018D
+ LB_GETTOPINDEX = 0x018E
+ LB_FINDSTRING = 0x018F
+ LB_GETSELCOUNT = 0x0190
+ LB_GETSELITEMS = 0x0191
+ LB_SETTABSTOPS = 0x0192
+ LB_GETHORIZONTALEXTENT = 0x0193
+ LB_SETHORIZONTALEXTENT = 0x0194
+ LB_SETCOLUMNWIDTH = 0x0195
+ LB_ADDFILE = 0x0196
+ LB_SETTOPINDEX = 0x0197
+ LB_GETITEMRECT = 0x0198
+ LB_GETITEMDATA = 0x0199
+ LB_SETITEMDATA = 0x019A
+ LB_SELITEMRANGE = 0x019B
+ LB_SETANCHORINDEX = 0x019C
+ LB_GETANCHORINDEX = 0x019D
+ LB_SETCARETINDEX = 0x019E
+ LB_GETCARETINDEX = 0x019F
+ LB_SETITEMHEIGHT = 0x01A0
+ LB_GETITEMHEIGHT = 0x01A1
+ LB_FINDSTRINGEXACT = 0x01A2
+ LB_SETLOCALE = 0x01A5
+ LB_GETLOCALE = 0x01A6
+ LB_SETCOUNT = 0x01A7
+ LB_INITSTORAGE = 0x01A8
+ LB_ITEMFROMPOINT = 0x01A9
+ LB_MULTIPLEADDSTRING = 0x01B1
+ LB_GETLISTBOXINFO = 0x01B2
+;
+
+
+
+//Listbox Return Values
+const
+ LB_OKAY = 0
+ LB_ERR = -1
+ LB_ERRSPACE = -2
+;

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r34 - trunk lotec Jan Bogaerts 2006-03-24 11:18:22 PST
Messages per page: