void PopupMenu::addItem(MenuItemRefPtr Item, const UInt32& Index)
{
    if(Index < getMFChildren()->size())
    {
        MFChildrenType::iterator InsertItor(editMFChildren()->begin());
        UInt32 ItemCount(0);
        for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
        {
            if(getChildren(i)->getType() != Separator::getClassType())
            {
                ++ItemCount;
            }
            if(ItemCount == Index)
            {
                break;
            }
            ++InsertItor;
        }

        if(InsertItor != editMFChildren()->end())
        {
                editMFChildren()->insert(InsertItor, Item);
	        producePopupMenuContentsChanged(PopupMenuEvent::create(PopupMenuRefPtr(this), getSystemTime()));
        }
    }
}
void PopupMenu::removeItem(const UInt32& Index)
{
    if(Index < getMFChildren()->size())
    {
        MFChildrenType::iterator RemoveItor(editMFChildren()->begin());
        UInt32 ItemCount(0);
        for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
        {
            if(getChildren(i)->getType() != Separator::getClassType())
            {
                ++ItemCount;
            }
            //if(ItemCount == Index)
            //{
                //break;
            //}
            ++RemoveItor;
        }
        if(RemoveItor != editMFChildren()->end())
        {
                editMFChildren()->erase(RemoveItor);
	        producePopupMenuContentsChanged(PopupMenuEvent::create(PopupMenuRefPtr(this), getSystemTime()));
        }
    }
}
Beispiel #3
0
void MenuBar::updateLayout(void)
{
	//Determine the Max Preferred Height of my MenuItems
	Real32 MaxHeight(0);
	Real32 TotalWidth(0);
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(MaxHeight < getChildren(i)->getPreferredSize().y())
        {
            MaxHeight = getChildren(i)->getPreferredSize().y();
	    }
	    TotalWidth += getChildren(i)->getPreferredSize().x();
	}

    //Set My preferred Size
	Pnt2f TopLeft, BottomRight;
	Pnt2f InsetsTopLeft, InsetsBottomRight;
	getBounds(TopLeft, BottomRight);
	getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight);

	Vec2f InsetSize( (BottomRight-TopLeft) - (InsetsBottomRight-InsetsTopLeft) );

    Vec2f NewSize( TotalWidth+InsetSize.x(), MaxHeight+InsetSize.y());
    if(getPreferredSize() != NewSize)
    {
        setPreferredSize(NewSize);
    }
    
	getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight);
	
	//Now position and size the Items
	Real32 LeftOffset(InsetsTopLeft.x());
    Vec2f Size;
    Pnt2f Pos;
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        Size.setValues(getChildren(i)->getPreferredSize().x(), MaxHeight);
        if(getChildren(i)->getSize() != Size)
        {
            getChildren(i)->setSize(Size);
        }
        Pos.setValues(LeftOffset, InsetsTopLeft.y());
        if(getChildren(i)->getPosition() != Pos)
        {
            getChildren(i)->setPosition(Pos);
        }

        LeftOffset += getChildren(i)->getPreferredSize().x();
    }
}
void PopupMenu::mouseDragged(const MouseEventUnrecPtr e)
{
    UInt32 i(0);
    while (i<getMFChildren()->size() && !getChildren(i)->isContained(e->getLocation(), true))
    {
        ++i;
    }
	
	if(i<getMFChildren()->size() && getSelectionModel()->getSelectedIndex() != i)
	{
		getSelectionModel()->setSelectedIndex(i);
	}
    ComponentContainer::mouseDragged(e);
}
void RotatedComponent::mousePressed(MouseEventDetails* const e)
{
    bool isContained(false);
    for(Int32 i(getMFChildren()->size()-1) ; i>=0 ; --i)
    {
        isContained = getChildren(i)->isContained(e->getLocation(), true);
        checkMouseEnterExit(e,e->getLocation(),getChildren(i),isContained,e->getViewport());
        if(isContained)
        {
            //Give myself temporary focus
            takeFocus(true);
            if(!getChildren(i)->getType().isDerivedFrom(ComponentContainer::getClassType()))
            {
                getChildren(i)->takeFocus();
            }
            getChildren(i)->mousePressed(e);
            break;
        }
    }
    if(isContained)
    {
        //Remove my temporary focus
        giveFocus(NULL, false);
    }
    else
    {
        //Give myself permenant focus
        takeFocus();
    }
    Component::mousePressed(e);
}
Beispiel #6
0
void MenuBar::addMenu(Menu* const menu, const UInt32& Index)
{
    if(Index < getMFChildren()->size())
    {
        insertIntoChildren(Index, menu);
        menu->setTopLevelMenu(true);
        _PopupMenuCanceledConnections[menu] = menu->getInternalPopupMenu()->connectPopupMenuCanceled(boost::bind(&MenuBar::handleMenuArmedPopupMenuCanceled, this, _1));
    }
}
void RotatedComponent::mouseExited(MouseEventDetails* const e)
{
    bool isContained;
    for(Int32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        isContained = getChildren(i)->isContained(e->getLocation(), true);
        checkMouseEnterExit(e,e->getLocation(),getChildren(i),isContained,e->getViewport());
    }
    Component::mouseExited(e);
}
void PopupMenu::updateLayout(void)
{
    //Determine the Max Preferred Width of my MenuItems
    Real32 MaxWidth(0);
    Real32 TotalHeight(0);
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(MaxWidth < getChildren(i)->getRequestedSize().x())
        {
            MaxWidth = getChildren(i)->getRequestedSize().x();
        }
        TotalHeight += getChildren(i)->getRequestedSize().y();
        if(i!=0)
        {
            TotalHeight += 1.0f;
        }
    }

    //Set My preferred Size
    Pnt2f TopLeft, BottomRight;
    Pnt2f InsetsTopLeft, InsetsBottomRight;
    getBounds(TopLeft, BottomRight);
    getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight);

    Vec2f InsetSize( (BottomRight-TopLeft) - (InsetsBottomRight-InsetsTopLeft) );
    setPreferredSize(Vec2f(MaxWidth+InsetSize.x(), TotalHeight+InsetSize.y()));

    //Sneakily set my size
    _sfSize.setValue(getPreferredSize());

    getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight);

    //Now position and size the Items
    Real32 TopOffset(InsetsTopLeft.y());
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        getChildren(i)->setSize(Vec2f(MaxWidth, getChildren(i)->getRequestedSize().y()));
        getChildren(i)->setPosition(Pnt2f(InsetsTopLeft.x(), TopOffset));

        TopOffset += getChildren(i)->getRequestedSize().y() +1;
    }
}
MenuItem* ListGeneratedPopupMenu::getItem(const UInt32& Index)
{
	if(getModel() != NULL && Index < getMFChildren()->size())
	{
		return dynamic_cast<MenuItem*>(getChildren(Index));
	}
	else
	{
		return NULL;
	}
}
Vec2f GenericFieldContainerEditor::getContentRequestedSize(void) const
{
    Real32 RequestedHeight(0.0f);

    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        RequestedHeight += getChildren(i)->getPreferredSize().y();
    }

    return Vec2f(1.0, RequestedHeight);
}
UInt32 Toolbar::getNumSeparators(void) const
{
    UInt32 NumSeparators(0);
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(getChildren(i)->getType() == Separator::getClassType())
        {
            ++NumSeparators;
        }
    }
    return NumSeparators;
}
Beispiel #12
0
void MenuBar::handleMenuArmedMouseDragged(MouseEventDetails* const e)
{
    UInt32 i(0);
    while (i<getMFChildren()->size())
    {
        if(getChildren(i)->isContained(e->getLocation(), true))
        {
            getSelectionModel()->setSelectedIndex(i);
            break;
        }
        ++i;
    }
}
Beispiel #13
0
void SpinnerDefaultEditor::updateLayout(void)
{
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(getChildren(i)->getPosition() != Pnt2f(0,0))
        {
            getChildren(i)->setPosition(Pnt2f(0,0));
        }
        if(getChildren(i)->getSize() != getSize())
        {
            getChildren(i)->setSize(getSize());
        }
    }
}
Beispiel #14
0
MenuItem* PopupMenu::getItem(const UInt32& Index)
{
    if(Index < getMFChildren()->size())
    {
        UInt32 ItemCount(0);
        for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
        {
            if(getChildren(i)->getType() != Separator::getClassType())
            {
                if(ItemCount == Index)
                {
                    break;
                }
                ++ItemCount;
            }
        }
        if(ItemCount < getMFChildren()->size())
        {
            return dynamic_cast<MenuItem*>(getChildren(ItemCount));
        }
    }
    return NULL;
}
Beispiel #15
0
void MenuBar::removeMenu(const UInt32& Index)
{
    if(Index < getMFChildren()->size())
    {
        MenuRefPtr Item(dynamic_cast<Menu*>(getChildren(Index)));
        removeFromChildren(Index);

        Item->setTopLevelMenu(false);
        if(_PopupMenuCanceledConnections.find(Item) != _PopupMenuCanceledConnections.end())
        {
            _PopupMenuCanceledConnections[Item].disconnect();
            _PopupMenuCanceledConnections.erase(_PopupMenuCanceledConnections.find(Item));
        }
    }
}
Beispiel #16
0
void PopupMenu::removeAllItems(void)
{
    std::deque<UInt32> RemoveIndecies;
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(getChildren(i)->getType() != Separator::getClassType())
        {
            RemoveIndecies.push_front(i);
        }
    }
    for(UInt32 i(0) ; i<RemoveIndecies.size() ; ++i)
    {
        removeItem(RemoveIndecies[i]);
    }
}
void RotatedComponent::mouseReleased(MouseEventDetails* const e)
{
    bool isContained;
    for(Int32 i(getMFChildren()->size()-1) ; i>=0 ; --i)
    {
        isContained = getChildren(i)->isContained(e->getLocation(), true);
        checkMouseEnterExit(e,e->getLocation(),getChildren(i),isContained,e->getViewport());
        if(isContained)
        {
            getChildren(i)->mouseReleased(e);
            break;
        }
    }
    Component::mouseReleased(e);
}
void GenericFieldContainerEditor::updateShownPanels(void)
{
    if(getShowFields() &&
       getMFChildren()->findIndex(_FieldsContainer) < 0)
    {
        pushToChildren(_FieldsContainer);
    }
    else if(!getShowFields() &&
            getMFChildren()->findIndex(_FieldsContainer) >= 0)
    {
        removeObjFromChildren(_FieldsContainer);
    }

    if(getShowEvents() &&
       getMFChildren()->findIndex(_ProducedEventsContainer) < 0)
    {
        pushToChildren(_ProducedEventsContainer);
    }
    else if(!getShowEvents() &&
            getMFChildren()->findIndex(_ProducedEventsContainer) >= 0)
    {
        removeObjFromChildren(_ProducedEventsContainer);
    }
}
void Toolbar::removeAllSeparators(void)
{
    std::deque<UInt32> RemoveIndecies;
    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(getChildren(i)->getType() == Separator::getClassType())
        {
            RemoveIndecies.push_front(i);
        }
    }
    for(UInt32 i(0) ; i<RemoveIndecies.size() ; ++i)
    {
        removeSeparator(RemoveIndecies[i]);
    }
}
Beispiel #20
0
void PopupMenu::updateSeparatorSizes(void)
{
    Pnt2f InsideInsetsTopLeft, InsideInsetsBottomRight;
    getInsideInsetsBounds(InsideInsetsTopLeft, InsideInsetsBottomRight);
    Vec2f InsideInsetsSize(InsideInsetsBottomRight - InsideInsetsTopLeft);

    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        Vec2f NewSize(Vec2f(InsideInsetsSize.x(), getChildren(i)->getRequestedSize().y()));
        if(getChildren(i)->getType() == Separator::getClassType() &&
           dynamic_cast<Separator*>(getChildren(i))->getPreferredSize() != NewSize)
        {
            dynamic_cast<Separator*>(getChildren(i))->setPreferredSize(NewSize);
        }
    }
}
Beispiel #21
0
void MenuBar::mousePressed(MouseEventDetails* const e)
{
    UInt32 i(0);
    while (i<getMFChildren()->size())
    {
        if(getChildren(i)->isContained(e->getLocation(), true))
        {
            getSelectionModel()->setSelectedIndex(i);
            _MouseMovedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectMouseMoved(boost::bind(&MenuBar::handleMenuArmedMouseMoved, this, _1));
            _MouseDraggedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectMouseDragged(boost::bind(&MenuBar::handleMenuArmedMouseDragged, this, _1));
            break;
        }
        ++i;
    }
    ComponentContainer::mousePressed(e);
}
void RotatedComponent::updateLayout(void)
{
    Pnt2f TopLeft, BottomRight;
    getInsideInsetsBounds(TopLeft, BottomRight);

    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(getChildren(i)->getPosition() != Pnt2f(0,0))
        {
            getChildren(i)->setPosition(Pnt2f(0,0));
        }
        if(getChildren(i)->getSize() != getChildren(i)->getPreferredSize())
        {
            getChildren(i)->setSize(getChildren(i)->getPreferredSize());
        }
    }
}
Beispiel #23
0
void MenuBar::handleMenuArmedKeyTyped(KeyEventDetails* const e)
{
    //UInt32 RelevantModifiers = (e->getModifiers() & KeyEventDetails::KEY_MODIFIER_ALT) |
    //                           (e->getModifiers() & KeyEventDetails::KEY_MODIFIER_CONTROL) |
    //                           (e->getModifiers() & KeyEventDetails::KEY_MODIFIER_SHIFT) |
    //                           (e->getModifiers() & KeyEventDetails::KEY_MODIFIER_META);

    if(e->getModifiers() & KeyEventDetails::KEY_MODIFIER_ALT)
    {
        for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
        {
            if(dynamic_cast<MenuItem*>(getChildren(i))->getMnemonicKey() == e->getKey() )
            {
                //std::cout << e->getKeyChar() << std::endl;
            }
        }
    }
}
void Toolbar::removeSeparator(const UInt32&  Index)
{
    if(Index < getNumSeparators())
    {
        UInt32 SeparatorCount(0);
        for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
        {
            if(getChildren(i)->getType() == Separator::getClassType())
            {
                ++SeparatorCount;
            }
            if(SeparatorCount == Index)
            {
                break;
            }
        }

        removeFromChildren(SeparatorCount);
    }
}
void Toolbar::updateSeparatorSizes(void)
{
    Pnt2f InsideInsetsTopLeft, InsideInsetsBottomRight;
    getInsideInsetsBounds(InsideInsetsTopLeft, InsideInsetsBottomRight);
    Vec2f InsideInsetsSize(InsideInsetsBottomRight - InsideInsetsTopLeft);

    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(getChildren(i)->getType() == Separator::getClassType())
        {
            if(getOrientation() == BoxLayout::HORIZONTAL_ORIENTATION)
            {
                dynamic_cast<Separator*>(getChildren(i))->setPreferredSize(Vec2f(getChildren(i)->getRequestedSize().x(), InsideInsetsSize.y()));
            }
            else
            {
                dynamic_cast<Separator*>(getChildren(i))->setPreferredSize(Vec2f(InsideInsetsSize.x(), getChildren(i)->getRequestedSize().y()));
            }
        }
    }
}
Beispiel #26
0
void PopupMenu::removeSeparator(const UInt32&  Index)
{
    if(Index < getNumSeparators())
    {
        MFChildrenType::iterator RemoveItor(editMFChildren()->begin());
        UInt32 SeparatorCount(0);
        for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
        {
            if(getChildren(i)->getType() == Separator::getClassType())
            {
                ++SeparatorCount;
            }
            if(SeparatorCount == Index)
            {
                break;
            }
            ++RemoveItor;
        }

            editMFChildren()->erase(RemoveItor);
    }
}
void Toolbar::setOrientation(BoxLayout::Orientation TheOrientation)
{
    dynamic_cast<BoxLayout*>(getLayout())->setOrientation(TheOrientation);

    Separator::Orientation Or;
    if(TheOrientation == BoxLayout::VERTICAL_ORIENTATION)
    {
        Or = Separator::HORIZONTAL_ORIENTATION;
    }
    else
    {
        Or = Separator::VERTICAL_ORIENTATION;
    }

    for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i)
    {
        if(getChildren(i)->getType() == Separator::getClassType())
        {
            dynamic_cast<Separator*>(getChildren(i))->setOrientation(Or);
        }
    }

    updateSeparatorSizes();
}
Beispiel #28
0
void InternalWindow::mousePressed(MouseEventDetails* const e)
{

    if(!getLockInput())
    {

        //Check if the Mouse is whithin the resize border width
        if(getResizable())
        {
            WindowArea TheArea(getCursurArea(e->getLocation()));
            switch(TheArea)
            {
                case WINDOW_LEFT_BORDER:
                case WINDOW_RIGHT_BORDER:
                case WINDOW_TOP_BORDER:
                case WINDOW_BOTTOM_BORDER:
                case WINDOW_TOP_LEFT_BORDER:
                case WINDOW_BOTTOM_RIGHT_BORDER:
                case WINDOW_TOP_RIGHT_BORDER:
                case WINDOW_BOTTOM_LEFT_BORDER:
                    setLockInput(true);

                    _WindowStartPosition = getPosition();
                    _WindowStartSize = getSize();
                    _MouseStartPosition = e->getLocation();
                    _BorderDragged = TheArea;
    
                    _BorderDragMouseDraggedConnection = getParentDrawingSurface()->getEventProducer()->connectMouseDragged(boost::bind(&InternalWindow::borderDragMouseDragged, this, _1));
                    _BorderDragMouseReleasedConnection = getParentDrawingSurface()->getEventProducer()->connectMouseReleased(boost::bind(&InternalWindow::borderDragMouseReleased, this, _1));
                    _BorderDragKeyPressedConnection = getParentDrawingSurface()->getEventProducer()->connectKeyPressed(boost::bind(&InternalWindow::borderDragKeyPressed, this, _1));
                    break;
            }
        }
        if(getMenuBar() != NULL)
        {
            bool isContained;
            isContained = getMenuBar()->isContained(e->getLocation(), true);
            checkMouseEnterExit(e,e->getLocation(),getMenuBar(),isContained,e->getViewport());
            if(isContained)
            {
                getMenuBar()->mousePressed(e);
                if(e->isConsumed()) return;
                Component::mousePressed(e);
                return;
            }
        }
        if(getTitlebar() != NULL)
        {
            bool isContained;
            isContained = getTitlebar()->isContained(e->getLocation(), true);
            checkMouseEnterExit(e,e->getLocation(),getTitlebar(),isContained,e->getViewport());
            if(isContained)
            {
                getTitlebar()->mousePressed(e);
                if(e->isConsumed()) return;
                Component::mousePressed(e);
                return;
            }
        }

        //ComponentContainer MousePressed Handling
        bool isContained(false);
        for(Int32 i(getMFChildren()->size()-1) ; i>=0 ; --i)
        {
            isContained = getChildren(i)->isContained(e->getLocation(), true);
            checkMouseEnterExit(e,e->getLocation(),getChildren(i),isContained,e->getViewport());
            if(isContained)
            {
                takeFocus();
                if(!getChildren(i)->getType().isDerivedFrom(ComponentContainer::getClassType()))
                {
                    getChildren(i)->takeFocus();
                }
                getChildren(i)->mousePressed(e);
                if(e->isConsumed()) return;
                break;
            }
        }
        Component::mousePressed(e);
    }
}
void InternalWindow::mousePressed(const MouseEventUnrecPtr e)
{

    if(!getLockInput())
    {

        //Check if the Mouse is whithin the resize border width
        if(getResizable())
        {
            WindowArea TheArea(getCursurArea(e->getLocation()));
            switch(TheArea)
            {
                case WINDOW_LEFT_BORDER:
                case WINDOW_RIGHT_BORDER:
                case WINDOW_TOP_BORDER:
                case WINDOW_BOTTOM_BORDER:
                case WINDOW_TOP_LEFT_BORDER:
                case WINDOW_BOTTOM_RIGHT_BORDER:
                case WINDOW_TOP_RIGHT_BORDER:
                case WINDOW_BOTTOM_LEFT_BORDER:
                    setLockInput(true);

                    _BorderDraggedListener.setWindowStartPosition(getPosition());
                    _BorderDraggedListener.setWindowStartSize(getSize());
                    _BorderDraggedListener.setMouseStartPosition(e->getLocation());
                    _BorderDraggedListener.setBorderDragged(TheArea);

                    getDrawingSurface()->getEventProducer()->addMouseMotionListener(&_BorderDraggedListener);
                    getDrawingSurface()->getEventProducer()->addMouseListener(&_BorderDraggedListener);
                    getDrawingSurface()->getEventProducer()->addKeyListener(&_BorderDraggedListener);
                    break;
            }
        }
        if(getMenuBar() != NULL)
        {
            bool isContained;
            isContained = getMenuBar()->isContained(e->getLocation(), true);
            checkMouseEnterExit(e,e->getLocation(),getMenuBar(),isContained,e->getViewport());
            if(isContained)
            {
                getMenuBar()->mousePressed(e);
                Component::mousePressed(e);
                return;
            }
        }
        if(getTitlebar() != NULL)
        {
            bool isContained;
            isContained = getTitlebar()->isContained(e->getLocation(), true);
            checkMouseEnterExit(e,e->getLocation(),getTitlebar(),isContained,e->getViewport());
            if(isContained)
            {
                getTitlebar()->mousePressed(e);
                Component::mousePressed(e);
                return;
            }
        }

        //ComponentContainer MousePressed Handling
        bool isContained(false);
        for(Int32 i(getMFChildren()->size()-1) ; i>=0 ; --i)
        {
            isContained = getChildren(i)->isContained(e->getLocation(), true);
            checkMouseEnterExit(e,e->getLocation(),getChildren(i),isContained,e->getViewport());
            if(isContained)
            {
                takeFocus();
                if(!getChildren(i)->getType().isDerivedFrom(ComponentContainer::getClassType()))
                {
                    getChildren(i)->takeFocus();
                }
                getChildren(i)->mousePressed(e);
                break;
            }
        }
        Component::mousePressed(e);
    }
}
Beispiel #30
0
UInt32 PopupMenu::getNumItems(void) const
{
    return getMFChildren()->size() - getNumSeparators();
}