S_232R

LANSA

S_232R
* ===================================================================
*
* Component : S_232R
* Type : Reusable Part
* Ancestor : PRIM_PANL
*
* Description : Reusable Combo Box that remembers the last 50 entries typed in
* the edit box.
*
* Disclaimer : The following material is supplied as example material
* only. No warranty concerning this material or its use in any way whatsoever
* is expressed or implied.
*
* ===================================================================
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_PANL) Displayposition(1) Height(19) Layoutmanager(#ATLM_1) Left(0) Tabposition(1) Top(0) Visualstyle(#VS_NORM) Width(132)
Define_Com Class(#PRIM_CMBX) Name(#SHOWLIST) Autoselectitem(False) Displayposition(1) Left(0) Parent(#COM_OWNER) Tabposition(1) Top(0) Width(132)
Define_Com Class(#PRIM_ATLM) Name(#ATLM_1)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_1) Attachment(Center) Manage(#SHOWLIST) Parent(#ATLM_1)
Define_Com Class(#PRIM_CBCL) Name(#CBCL_1) Displayposition(1) Parent(#SHOWLIST) Sortposition(1) Source(#STD_TEXTL) Width(20) Widthtype(Remainder)

* Define the list and values used to track the most popular set
* of values put into the combo box. #STD_TEXTL is the value.
* #STD_NUM is a measure of the values "popularity". It is
* an approximation only, accumulated by monitoring the number
* of times the value is selected from the drop down area and
* the number of times that the value is in the combo box when
* it looses focus or is closed/destroyed.

Define Field(#WORKCOUNT) Reffld(#STD_NUM)
Define Field(#WORKLIMIT) Reffld(#STD_NUM) Default(10)
Define Field(#WORKSORT) Reffld(#STD_FLAG)
Def_List Name(#WorkList) Fields(#STD_TEXTL #STD_NUM) Counter(#WORKCOUNT) Type(*WORKING)

* Define other simple fields

Define Field(#FILENAME) Reffld(#SYSVAR$AV)
Define Field(#RETCODE) Type(*CHAR) Length(2)

* --------------------------
* Define the uValue property
* --------------------------

Define_Pty Name(uValue) Get(Get_uValue) Set(Set_uValue)

Ptyroutine Name(Set_uValue)
Define_Map For(*input) Class(#Std_textl) Name(#Property_001)
Set Com(#ShowList) Value(#Property_001.Value)
Invoke Method(#Com_Owner.UpdatePopularity)
Endroutine

Ptyroutine Name(Get_uValue)
Define_Map For(*output) Class(#Std_textl) Name(#Property_002)
Set Com(#Property_002) Value(#ShowList.Value)
Endroutine

* ------------------------
* Handle instance creation
* ------------------------

Evtroutine Handling(#COM_OWNER.CreateInstance) Options(*NOCLEARMESSAGES *NOCLEARERRORS)

* Load up the current popularity list from a temporary file

Use Builtin(TCONCAT) With_Args(*Temp_Dir #COM_OWNER.NAME '.dat') To_Get(#FILENAME)
Use Builtin(TRANSFORM_FILE) With_Args(#WorkList #FILENAME T) To_Get(#RETCODE)
Use Builtin(CLR_MESSAGES)

* Pre-fill the combo box drop down area from the list. Note that
* this area is visually sorted into #STD_TEXL (ie: value) order.

Selectlist Named(#WorkList)
Add_Entry To_List(#ShowList)
Endselect

* Pre-fill the combo box value with the most "popular" entry in the
* list by sorting the list by "popularity" (#STD_NUM) descending and
* then by value (#STD_TEXL) .....

Sort_List Named(#WorkList) By_Fields((#STD_NUM *DESCEND) #STD_TEXTL)
Get_Entry Number(1) From_List(#WorkList)
If_Status Is(*OKAY)
Set Com(#ShowList) Value(#Std_TextL)
else
Set Com(#ShowList) Value(*Blanks)
Endif

Endroutine

* ---------------------------
* Handle instance destruction
* ---------------------------

Evtroutine Handling(#COM_OWNER.DestroyInstance) Options(*NOCLEARMESSAGES *NOCLEARERRORS)

* Update the popularity of the current value

Invoke Method(#Com_Owner.UpdatePopularity)

* (Re)save the popularity list into the temporary file

Use Builtin(TRANSFORM_LIST) With_Args(#WorkList #FILENAME T) To_Get(#RETCODE)

Endroutine

* -----------------------------------------------------
* When the combo box looses focus update the popularity
* -----------------------------------------------------

Evtroutine Handling(#ShowList.LostFocus) Options(*NOCLEARMESSAGES *NOCLEARERRORS)

Invoke Method(#Com_Owner.UpdatePopularity)

Endroutine

* ------------------------------------------------------------
* If an item is selected from the dropdown update the edit box
* value area with the selected value and update the popularity
* ------------------------------------------------------------

Evtroutine Handling(#ShowList.ItemGotFocus) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
Set Com(#ShowList) Value(#Std_TextL)
Invoke Method(#Com_Owner.UpdatePopularity)
Endroutine

* -------------------------------------------------------------
* Update the popularity of the value currently in the combo box
* -------------------------------------------------------------

Mthroutine Name(UpdatePopularity)
Define Field(#Cur_Value) Reffld(#STD_TEXTL)

* Set current value

Change #Cur_Value #ShowList.Value

* Ignore blank values altogether

If '#Cur_Value *ne *Blanks'

* Look for the value in the poularity list

Loc_Entry In_List(#WorkList) Where('#Std_TextL = #Cur_Value')

* If found, increment the popularity approximation ...

If_Status Is(*OKAY)
Change #Std_Num '#Std_Num + 1'
Upd_Entry In_List(#WorkList)

Else

* Make the popularity list contain the 9 (or less) most
* popular values ....

Change #WorkSort N
Dowhile Cond('#WorkCount >= #WorkLimit')
If '#WorkSort = N'
Sort_List Named(#WorkList) By_Fields((#STD_NUM *DESCEND) #STD_TEXTL)
Change #WorkSort Y
Endif
Get_Entry Number(#WORKCOUNT) From_List(#WorkList)
Dlt_Entry From_List(#WorkList)
Endwhile

* Add the new entry entry to the popularity list ....

Change Field(#STD_TEXTL) To(#Cur_Value)
Change Field(#STD_NUM) To(1)
Add_Entry To_List(#WorkList)

* Rebuild the drop down area from the latest popularity
* list. Note that the value just entered is always in the
* popularity list. This means the list effectively contains
* the 9 most popular values + the last value used.

Clr_List #ShowList
Selectlist #WorkList
Add_Entry #ShowList
EndSelect

Endif

Endif

Endroutine

End_Com