/*

// wrapper for {Listbox} control using awt List

CLASS {AL4_listbox}, NATIVE, UNTESTED :
      IMPORT: {Control}, {Canvas}, {Bitmap}, {Font}, {Mathematics} ;

*/

import java.util.ArrayList;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.lang.Math.*;

public class AL4_listbox
{

	/*
    // Create listbox control, return descriptor. Only detailed view is possible.
    //----------------------------------------------------------------------------
    FUN Create_listbox({Control} L|istbox_control,
        BOOL Multi|select) ==> INT, STATIC :
        -------------------------------------------- 'call listbox constructor'
        RESULT = do_create_listbox(L.Form_.Handle, L, Multi) .

    FUN do_create_listbox(INT F|orm_handle, {Control} L|istbox_create, 
        BOOL Multi|select) ==> INT, STATIC, NATIVE :
        "     return AL4_listbox.Do_Create_listbox(X_F, X_L, X_Multi);" .
    */
	public static int Do_Create_listbox(int H, Ref_obj X_L,
        Boolean X_Multiselect)
	{
		AL4_form.AL4_column C = AL4_form.Get_parent_for_new_control(H);
        java.awt.List L = new java.awt.List(10, X_Multiselect);
        C_Listbox contr = (C_Listbox)X_L.Obj;
        C.Placer_panel.add(L);
		int Result = AL4_form.Alloc_descriptor(L, X_L);
        AL4_form.adjust_control_size_position(C, L);
		AL4_form.Set_control_events(C.Form_, L);
        //P.PictureBox_component_listener = new Component_listener();
		//P.addComponentListener(P.PictureBox_component_listener);
		return Result;
	}
    

    /*
    
    
    // Return listbox item string by its index
    //--------------------------------------------------------------------------
    FUN Get_listbox_item(INT L|istbox_control, INT Index|_item) ==> STR,
        STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    if (X_Index < 0 || X_Index >= L.getItemCount()) return "#QU#QU";"
        "    String Result = L.getItem(X_Index);"
        "    return Result;" .


    // Set listbox item string by its index
    //--------------------------------------------------------------------------
    FUN Set_listbox_item(INT L|istbox_control, INT Index|_item, STR Value|_set),
        STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    if (X_Index < 0 || X_Index >= L.getItemCount()) return;"
        "    L.replaceItem(X_Value, X_Index);" .


    // Get listbox items count
    //--------------------------------------------------------------------------
    FUN Get_listbox_count|_items(INT L|istbox_control) ==> INT,
        STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    return L.getItemCount();" .
        
    // Add listbox item string 
    //--------------------------------------------------------------------------
    FUN Listbox_add_item(INT L|istbox_control, STR Value|_set) ==> INT,
        STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    L.add(X_Value);"
        "    return L.getItemCount()-1;".


    // Insert item into listbox at given position 
    //--------------------------------------------------------------------------
    FUN Listbox_insert_item(INT L|istbox_control, INT Index|_before,
        STR Value|_set) ==> INT, STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    if (X_Index < 0 || X_Index >= L.getItemCount()) return -1;"
        "    L.add(X_Value, X_Index);"
        "    return X_Index;" .


    // Delete item in listbox by index 
    //--------------------------------------------------------------------------
    FUN Listbox_delete_item(INT L|istbox_control, INT Index|_delete),
        STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    if (X_Index < 0 || X_Index >= L.getItemCount()) return;"
        "    L.delItem(X_Index);" .


    // Select/deselect item in listbox by index 
    //--------------------------------------------------------------------------
    FUN Listbox_select_item(INT L|istbox_control, INT Index|_delete,
        BOOL Select|_or_deselect), STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    if (X_Index < 0 || X_Index >= L.getItemCount()) return;"
        "    if (X_Select) L.select(X_Index);"
        "    else L.deselect(X_Index);" .


    // Select all items in listbox
    //--------------------------------------------------------------------------
    FUN Listbox_select_all(INT L|istbox_control), STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    for (int i = 0; i < L.getItemCount(); i++)"
        "        L.select(i);" .


    // Deselect all items in listbox
    //--------------------------------------------------------------------------
    FUN Listbox_select_none(INT L|istbox_control), STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    for (int i = 0; i < L.getItemCount(); i++)"
        "        L.deselect(i);" .


    // Get count of selected items in listbox
    //--------------------------------------------------------------------------
    FUN Listbox_get_sel_count(INT L|istbox_control) ==> INT, STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    int[] sel = L.getSelectedIndexes();"
        "    return sel.length;" .


    // Delete all selected items in listbox
    //--------------------------------------------------------------------------
    FUN Listbox_delete_selected(INT L|istbox_control), STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    int[] sel = L.getSelectedIndexes();"
        "    for (int i = sel.length; i >= 0; i--)"
        "         L.delItem(sel[i]);" .


    // Get next selected item in listbox
    //--------------------------------------------------------------------------
    FUN Listbox_get_next_sel(INT L|istbox_control, INT From|_index) ==> INT,
        STATIC, NATIVE :
       @"    java.awt.List L = (java.awt.List)AL4_form.All_descr.get(X_L).Jvc;"
        "    int[] sel = L.getSelectedIndexes();"
        "    if (sel.length == 0) return 01;"
        "    if (X_From < 0) return sel[0];"
        "    for (int i = 0; i < sel.length-1; i++)"
        "       if (sel[i] == X_From) return sel[i+1];"
        "    return -1;" .


    */

}


/*
END
*/
