; -------------------------------------------------------------------------------- ; @Title: Example for using a pair of lists in a Dialog ; @Description: ; How to manage two lists of items and move items between them. ; ; @Keywords: LISTBOX, DIALOG.STRing2, BUTTON, DIALOG, PRACTICE ; @Author: RIC AME SME ; @Copyright: (C) 1989-2016 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Id: dialog_list.cmm 12853 2018-07-16 15:11:08Z smeister $ LOCAL &list &mylist ; For longer lists the macro can be constructed across ; several lines with the line continuing sign like this &list="Rising Force,\ Marching Out,\ Trilogy,\ Odyssey,\ Trial by Fire,\ Eclipse,\ Fire and Ice,\ Seventh Sign,\ Magnum Opus,\ Facing the Animal,\ The Orville" ; create and open a dialog named "mydialog" WinPOS ,,,,,,mydialog DIALOG.view (&+ HEADER "Two List Example" POS 0.5 0. 44. 6.25 BOX "Instructions" ; Specify POS for 1st TEXT objct. All others will: ; keep same X ; increment Y by 1 ; keep same W and H POS 1. 0.75 43. 4.75 ; Infotext element for instuctions in a boxed read only text INFOTEXT "Select an item in one list and use the buttons in the centre to transfer items from one list to the other."+CONV.CHAR(10.)+" OR"+CONV.CHAR(10.)+"Double-click an item to move it to the other list."+CONV.CHAR(10.)+CONV.CHAR(10.)+"Click ""OK"" when finished and see a list of the selected items." 3. POS 0.5 6. 19. 5. L_LST: LISTBOX "&list" ( ; When the user double-clicks an item in the list ; execute the command associated with the transfer button (TA) DIALOG.EXecute TA ) POS 20.5 7.5 4. 1. ; Button displays a user defined icon. Use BITMAPEDIT to edit the icons TA: BUTTON "[=AVDXCuuKm1kff@$gNjn3$0f1hXYacegiEUyJaFa0a0Z0lV7Cg094HV1]" (&- ; The above line disables loadtime macro replacement for this block ; Declare &curitme for this block ONLY. PRIVATE &curitem ; Get the selected value from the list &curitem=DIALOG.STRing(L_LST) ; Check it's not NULL IF "&curitem"!="" ( PRIVATE &newlist &newbaselist GOSUB move_left_to_right "&curitem" RETURNVALUES &newlist &newbaselist ; Set new values to each listbox DIALOG.Set R_LST "" "&newlist" DIALOG.Set L_LST "" "&newbaselist" ) ) POS 20.5 9. 4. 1. ; Button displays a user defined icon. Use BITMAPEDIT to edit the icons TR: BUTTON "[=AVTXKfxKm26TzUfffjn3B0Z0J2J9Jaxq3q0LmrstuvwBxY7C1BF2W48]" (&- ; Declare &curitem for this block ONLY. ; This will not interfere with the declaration in the previous block - the ; PRIVATE keyword ensures that it remains local to this block. PRIVATE &curitem &curitem=DIALOG.STRing(R_LST) ; Check th ecurrent item is not NULL IF "&curitem"!="" ( PRIVATE &newlist &newbaselist GOSUB move_right_to_left "&curitem" RETURNVALUES &newlist &newbaselist ; Write the new values to the listboxes. DIALOG.Set L_LST "" "&newlist" DIALOG.Set R_LST "" "&newbaselist" ) ) POS 25.5 6. 19. 5. R_LST: LISTBOX "" ( ; If the user double-clicks this list, execute the command associatd ; with button TR DIALOG.EXecute TR ) POS 20. 11.5 5. 1.25 BUTTON "OK" (&- PRIVATE &mylist &displaytxt &CRLF ; Use CONV.CHAR(0x0A) to generate a newline in the macro which will be displayed. ; Adding an empty string before the CRLF character forces PRACTICE to treat this ; as a string and not just as a ASCII character. &CRLF=""+CONV.CHAR(0x0A) ; get the complete list from the second listbox (R_LST). DIALOG.STRing only returns the ; currently selected item. DIALOG.STRing2 returns all values in the list. DIALOG.SELECT mydialog &mylist=DIALOG.STRing2(R_LST) ; The next few lines will format the selected list for display IF "&mylist"=="" ( ; empty list &displaytxt="You chose nothing" ) ELSE ( ; Replace all commas in the list with the CRLF character plus a list sign &mylist=STRing.Replace("&mylist", ",","&CRLF * ",0.) &displaytxt="You chose:&CRLF * &mylist" ) ; Display the results in a popup OK message box with same window title WINPOS ,,,,,,,,"Two List Example" DIALOG.OK "&displaytxt" ; Continuing stopped script will cleanup and end CONTinue ) CLOSE "CONTinue" ) ; Script stops here after dialog is shown and waits for user input STOP ; Close dialog DIALOG.END ; End script here ENDDO ; -------------------------------------------------------------------------------- ; Subroutines ; -------------------------------------------------------------------------------- ; sub routine move_left_to_right ; ; Parameters: &ct = the item to be moved from left to right list ; Returns: &new_R_list = new list for right hand side. Current item has been added. ; &new_L_list = new list for left hand side list. Current item has been removed move_left_to_right: ( PRIVATE &tmp_list &new_L_list &new_R_list PARAMETERS &ct DIALOG.SELECT mydialog &tmp_list=DIALOG.STRing2(L_LST) &new_R_list=DIALOG.STRing2(R_LST) ; If the selection list is empty, just add the new item. ; If not add the new item to the list. IF "&new_R_list"=="" ( &new_R_list="&ct" ) ELSE ( &new_R_list="&(new_R_list),&(ct)" ) PRIVATE &tlen &slen &splen &tstr1 &tstr2 ; Get No. of chars before the item to be transferred &tlen=STRing.SCAN("&tmp_list","&ct",0.) ; Get the length of the list &slen=STRing.LENgth("&tmp_list") ; Get the length of the item to be transferred &splen=STRing.LENgth("&ct") ; Grab the first half of the list before the item to be moved &tstr1=STRing.MID("&tmp_list",0.,&tlen-1.) ; Grab the portion of the list after the item to be moved &tstr2=STRing.MID("&tmp_list",&tlen+&splen,&slen-&splen) ; Stick the two parts together &new_L_list="&tstr1"+"&tstr2" ; If the first char of the new list is a comma, remove it. if STRing.CHAR("&new_L_list",0.)==',' ( &new_L_list=STRing.CUT("&new_L_list",1.) ) ; Return the new lists RETURN "&new_R_list" "&new_L_list" ) ; -------------------------------------------------------------------------------- ; sub routine move_right_to_left ; ; Parameters: &ct = the item to be move from right to left list ; Returns: &list = new list for left hand side. Current item has been added. ; &baselist = new list for right hand side. Current item has been removed. move_right_to_left: ( PRIVATE &tmp_list &new_L_list &new_R_list PARAMETERS &ct DIALOG.SELECT mydialog ; Read the two lists. &tmp_list=DIALOG.STRing2(R_LST) &new_L_list=DIALOG.STRing2(L_LST) ; If the new left list has no members, just add the current item to the start of the list. IF "&new_L_list"=="" ( &new_L_list="&ct" ) ELSE ( &new_L_list="&(new_L_list),&(ct)" ) PRIVATE &tlen &slen &splen &tstr1 &tstr2 ; Where in the right list does the current item start &tlen=STRing.SCAN("&tmp_list","&ct",0.) ; Get the length of the right list &slen=STRing.LENgth("&tmp_list") ; Get the length of the item to be transferred. &splen=STRing.LENgth("&ct") ; Extract the portion of the right list BEFORE the item to be transferred. &tstr1=STRing.MID("&tmp_list",0.,&tlen-1.) ; Extract the portion of the right list AFTER the item to be transferred &tstr2=STRing.MID("&tmp_list",&tlen+&splen,&slen-&splen) ; Join the two temporary lists together &new_R_list="&tstr1"+"&tstr2" ; If the new list starts with a comma, remove it. IF STRing.CHAR("&new_R_list",0.)==',' ( &new_R_list=STRing.CUT("&new_R_list",1.) ) ; Return the new lists RETURN "&new_L_list" "&new_R_list" )