<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2008 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package spark.components
{
import adobe.utils.CustomActions;

import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

import mx.core.mx_internal;
import mx.styles.StyleProxy;

import spark.core.NavigationUnit;
import spark.components.supportClasses.ListBase;
import spark.events.DropDownEvent;
import spark.events.TextOperationEvent;
import spark.utils.LabelUtil;
 
use namespace mx_internal;

/*
TODO (jszeto)

X Implement labelToItemFunction
X Implement committing input string to selectedItem
X Keep track of selectedIndex state
- Implement caret and selection states
- Implement user interaction behaviors
X Implement openOnInput
X Implement TextInput proxy properties
X Implement itemMatchingFunction property
X Implement restrict
X Implement maxChars

X Add wireframe skins

X Support padding styles in TextInput

- Make setting custom selectedItem cancellable
- Refactor DropDownList into DropDownList and DropDownListBase

B-Feature
- Add filtering support
- Add allowCustomSelectedItem support
- Prompt support

*/

/**
 *  Botttom inset in pixels for the textInput
 * 
 *  @default 3
 */
[Style(name="paddingBottom", type="Number", format="Length", inherit="no")]

/**
 *  Left inset in pixels for the textInput
 * 
 *  @default 3
 */
[Style(name="paddingLeft", type="Number", format="Length", inherit="no")]

/**
 *  Right inset in pixels for the textInput
 * 
 *  @default 3
 */
[Style(name="paddingRight", type="Number", format="Length", inherit="no")]

/**
 *  Top inset in pixels for the textInput
 * 
 *  @default 5
 */
[Style(name="paddingTop", type="Number", format="Length", inherit="no")]

// TODO Fill out ASDoc
/**
 *  ComboBox
 */
public class ComboBox extends DropDownList
{
    //--------------------------------------------------------------------------
    //
    //  Skin Parts
    //
    //--------------------------------------------------------------------------    
    /**
     *  Optional skin part that holds the input text or the selectedItem text 
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart(required="false")]
    public var textInput:TextInput;
    
    /**
     *  Constructor. 
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
	public function ComboBox()
 	{
 	    super();
        
        addEventListener(KeyboardEvent.KEY_DOWN, capture_keyDownHandler, true);
        
        // TODO (jszeto) Add a property to toggle this behavior
        allowCustomSelectedItem = true;
 	}
    
    //--------------------------------------------------------------------------
    //
    //  Static Variables
    //
    //--------------------------------------------------------------------------
    /**
     *  Static constant representing the value "custom selectedItem"
     */
    public static const CUSTOM_SELECTED_ITEM:int = ListBase.CUSTOM_SELECTED_ITEM;
    
    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------
    
    private var isTextInputInFocus:Boolean;
    
    private var actualProposedSelectedIndex:Number = -1;  
    
    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------
    
    //--------------------------------------------------------------------------
    //  itemMatchingFunction
    //--------------------------------------------------------------------------
    
    /**
     *  The function referenced by this property takes an input string and returns
     *  the items in the dataProvider that match the input. 
     *  The items are returned as a Vector of indicies in the dataProvider. 
     * 
     *  The function signature is this:
     * 
     *  function myMatchingFunction(comboBox:ComboBox, inputText:String):Vector.<int>
     * 
     *  If the value is null, the ComboBox will find matches using the following algorithm:
     * 
     *  If an input string of length n is equivalent to the first n characters 
     *  of an item (ignoring case), then it is a match to that item. For example, 'aRiz' 
     *  is a match to "Arizona" while 'riz' is not.
     * 
     *  @default null
     */ 
    public var itemMatchingFunction:Function = null;
    
    //--------------------------------------------------------------------------
    //  labelToItemFunction
    //--------------------------------------------------------------------------
    private var _labelToItemFunction:Function;
    private var labelToItemFunctionChanged:Boolean = false;
    
    /**
     *  The function referenced by this propery is called when textInput's text
     *  is committed and is not found in the dataProvider. 
     * 
     *  The function signature is this:
     * <commit_msg>Transferred from the Adobe Open Source Subversion Repository<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2008 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package spark.components
{
import adobe.utils.CustomActions;

import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

import mx.core.mx_internal;
import mx.styles.StyleProxy;

import spark.core.NavigationUnit;
import spark.components.supportClasses.ListBase;
import spark.events.DropDownEvent;
import spark.events.TextOperationEvent;
import spark.utils.LabelUtil;
 
use namespace mx_internal;

/*
TODO (jszeto)

X Implement labelToItemFunction
X Implement committing input string to selectedItem
X Keep track of selectedIndex state
- Implement caret and selection states
- Implement user interaction behaviors
X Implement openOnInput
X Implement TextInput proxy properties
X Implement itemMatchingFunction property
X Implement restrict
X Implement maxChars

X Add wireframe skins

X Support padding styles in TextInput

- Make setting custom selectedItem cancellable
- Refactor DropDownList into DropDownList and DropDownListBase

B-Feature
- Add filtering support
- Add allowCustomSelectedItem support
- Prompt support

*/

/**
 *  Botttom inset in pixels for the textInput
 * 
 *  @default 3
 */
[Style(name="paddingBottom", type="Number", format="Length", inherit="no")]

/**
 *  Left inset in pixels for the textInput
 * 
 *  @default 3
 */
[Style(name="paddingLeft", type="Number", format="Length", inherit="no")]

/**
 *  Right inset in pixels for the textInput
 * 
 *  @default 3
 */
[Style(name="paddingRight", type="Number", format="Length", inherit="no")]

/**
 *  Top inset in pixels for the textInput
 * 
 *  @default 5
 */
[Style(name="paddingTop", type="Number", format="Length", inherit="no")]

// TODO Fill out ASDoc
/**
 *  ComboBox
 */
public class ComboBox extends DropDownList
{
    //--------------------------------------------------------------------------
    //
    //  Skin Parts
    //
    //--------------------------------------------------------------------------    
    /**
     *  Optional skin part that holds the input text or the selectedItem text 
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    [SkinPart(required="false")]
    public var textInput:TextInput;
    
    /**
     *  Constructor. 
     *  
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public function ComboBox()
    {
        super();
        
        addEventListener(KeyboardEvent.KEY_DOWN, capture_keyDownHandler, true);
        
        // TODO (jszeto) Add a property to toggle this behavior
        allowCustomSelectedItem = true;
    }
    
    //--------------------------------------------------------------------------
    //
    //  Static Variables
    //
    //--------------------------------------------------------------------------
    /**
     *  Static constant representing the value "custom selectedItem"
     */
    public static const CUSTOM_SELECTED_ITEM:int = ListBase.CUSTOM_SELECTED_ITEM;
    
    //--------------------------------------------------------------------------
    //
    //  Variables
    //
    //--------------------------------------------------------------------------
    
    private var isTextInputInFocus:Boolean;
    
    private var actualProposedSelectedIndex:Number = -1;  
    
    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------
    
    //--------------------------------------------------------------------------
    //  itemMatchingFunction
    //--------------------------------------------------------------------------
    
    /**
     *  The function referenced by this property takes an input string and returns
     *  the items in the dataProvider that match the input. 
     *  The items are returned as a Vector of indicies in the dataProvider. 
     * 
     *  The function signature is this:
     * 
     *  <pre>function myMatchingFunction(comboBox:ComboBox, inputText:String):Vector</pre>
     * 
     *  If the value is null, the ComboBox will find matches using the following algorithm:
     * 
     *  If an input string of length n is equivalent to the first n characters 
     *  of an item (ignoring case), then it is a match to that item. For example, 'aRiz' 
     *  is a match to "Arizona" while 'riz' is not.
     * 
     *  @default null
     */ 
    public var itemMatchingFunction:Function = null;
    
    //--------------------------------------------------------------------------
    //  labelToItemFunction
    //--------------------------------------------------------------------------
    private var _labelToItemFunction:Function;
    private var labelToItemFunctionChanged:Boolean = false;
    
    /**
     *  The function referenced by this propery is called when textInput's text
     *  is committed and is not found in the dataProvider. 
     * 
     *  The function signature is this:
     * 
{'fraction_non_alphanumeric': 0.25978679566424795, 'fraction_numerical': 0.004120756069157037, 'mean_word_length': 1.4359589788348244, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6717810', 'n_tokens_mistral': 2728, 'n_tokens_neox': 2607, 'n_words': 843}