void ComboBox::updateComponentGeneratorSelectedItem(void)
{
    if(!getEditable() && getCellGenerator() != NULL && getModel() != NULL)
    {
        if(getCellGenerator()->getType().isDerivedFrom(ComboBoxComponentGenerator::getClassType()))
        {
            ComponentUnrecPtr GeneratedComp(dynamic_cast<ComboBoxComponentGenerator*>(getCellGenerator())->getComboBoxComponent(this, getModel()->getSelectedItem(), getModel()->getSelectedItemIndex(), false, false));
            setComponentGeneratorSelectedItem(GeneratedComp);
        }
        else
        {
            ComponentUnrecPtr GeneratedComp(getCellGenerator()->getComponent(this, getModel()->getSelectedItem(), getModel()->getSelectedItemIndex(), 0, false, false));
            setComponentGeneratorSelectedItem(GeneratedComp);
        }
    }
}
void ListGeneratedPopupMenu::updateMenuItems(void)
{
    clearChildren();

    if(getModel() != NULL)// && )
    {
        MenuItemRefPtr Item;
        for(Int32 i(0) ; i<getModel()->getSize() ; ++i)
        {
            if(getCellGenerator() != NULL)
            {
                Item = ComponentMenuItem::create();
                ComponentRefPtr TheComponent = getCellGenerator()->getComponent(ListGeneratedPopupMenuRefPtr(this), getModel()->getElementAt(i), i, 0, false, false);

                TheComponent->setBackgrounds(NULL);


                dynamic_pointer_cast<ComponentMenuItem>(Item)->setComponent(TheComponent);
            }
            else
            {
                //Generate the Menu Item
                Item = MenuItem::create();
                std::string TheText;
                try
                {
                    TheText = lexical_cast(getModel()->getElementAt(i));
                }
                catch (boost::bad_lexical_cast &)
                {
                    //Could not convert to a string
                }
                dynamic_pointer_cast<MenuItem>(Item)->setText(TheText);
            }
            pushToChildren(Item);
        }
    }
    producePopupMenuContentsChanged(PopupMenuEvent::create(PopupMenuRefPtr(this), getSystemTime()));
}
void ComboBox::changed(ConstFieldMaskArg whichField, 
                       UInt32            origin,
                       BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    //Do not respond to changes that have a Sync origin
    if(origin & ChangedOrigin::Sync)
    {
        return;
    }

    if( (whichField & EditableFieldMask))
    {
        updateComponentGeneratorSelectedItem();
    }

    if((whichField & ExpandButtonFieldMask) &&
       getExpandButton() != NULL)
    {
        _ExpandButtonSelectedConnection = getExpandButton()->connectButtonSelected(boost::bind(&ComboBox::handleExpandButtonSelected, this, _1));
        _ExpandButtonDeselectedConnection = getExpandButton()->connectButtonDeselected(boost::bind(&ComboBox::handleExpandButtonDeselected, this, _1));
        
        _ExpandPopupMenuCanceledConnection = getComboListPopupMenu()->connectPopupMenuCanceled(boost::bind(&ComboBox::handleExpandPopupMenuCanceled, this, _1));
        _ExpandPopupMenuWillBecomeInvisibleConnection = getComboListPopupMenu()->connectPopupMenuWillBecomeInvisible(boost::bind(&ComboBox::handleExpandPopupMenuWillBecomeInvisible, this, _1));
        _ExpandPopupMenuWillBecomeVisibleConnection = getComboListPopupMenu()->connectPopupMenuWillBecomeVisible(boost::bind(&ComboBox::handleExpandPopupMenuWillBecomeVisible, this, _1));
        _ExpandPopupMenuContentsChangedConnection = getComboListPopupMenu()->connectPopupMenuContentsChanged(boost::bind(&ComboBox::handleExpandPopupMenuContentsChanged, this, _1));
    }

    if( (whichField & ExpandButtonFieldMask) ||
        (whichField & EditorFieldMask) ||
        (whichField & EditableFieldMask) ||
        (whichField & ComponentGeneratorSelectedItemFieldMask))
    {
        clearChildren();
        if(getExpandButton() != NULL)
        {
            getExpandButton()->setEnabled(getEnabled());
            pushToChildren(getExpandButton());
        }
        if(getEditable() && getEditor() != NULL && getEditor()->getEditorComponent() != NULL)
        {
            getEditor()->getEditorComponent()->setEnabled(getEnabled());
            pushToChildren(getEditor()->getEditorComponent());
        }
        if(!getEditable() && getComponentGeneratorSelectedItem() != NULL)
        {
            getComponentGeneratorSelectedItem()->setEnabled(getEnabled());
            pushToChildren(getComponentGeneratorSelectedItem());
        }
    }

    if( (whichField & EditorFieldMask) && getEditor() != NULL)
    {
        _EditorActionConnection = getEditor()->connectActionPerformed(boost::bind(&ComboBox::handleEditorAction, this, _1));
    }

    if(whichField & ModelFieldMask)
    {
        if(getModel() != NULL)
        {
            getComboListPopupMenu()->setModel(getModel());

            _ContentsChangedConnection = getModel()->connectListDataContentsChanged(boost::bind(&ComboBox::handleContentsChanged, this, _1));
            _ContentsIntervalAddedConnection = getModel()->connectListDataIntervalAdded(boost::bind(&ComboBox::handleContentsIntervalAdded, this, _1));
            _ContentsIntervalRemovedConnection = getModel()->connectListDataIntervalRemoved(boost::bind(&ComboBox::handleContentsIntervalRemoved, this, _1));
            _SelectionChangedConnection = getModel()->connectSelectionChanged(boost::bind(&ComboBox::handleSelectionChanged, this, _1));
            updateListFromModel();
        }
    }

    if(((whichField & CellGeneratorFieldMask) ||
        (whichField & ComboListPopupMenuFieldMask)) &&
       getCellGenerator() != NULL)
    {
        getComboListPopupMenu()->setCellGenerator(getCellGenerator());
    }
}