//----------------------------------------------------------------------------//
void NamedElement::setName(const String& name)
{
    if (d_name == name)
        return;

    if (getParentElement())
    {
        NamedElement* parent = dynamic_cast<NamedElement*>(getParentElement());

        if (parent && parent->isChild(name))
        {
            CEGUI_THROW(AlreadyExistsException("Failed to rename "
                "NamedElement at: " + getNamePath() + " as: " + name + ". A Window "
                "with that name is already attached as a sibling."));
        }
    }

    // log this under informative level
    Logger::getSingleton().logEvent("Renamed element at: " + getNamePath() +
                                    " as: " + name, Informative);

    d_name = name;

    NamedElementEventArgs args(this);
    onNameChanged(args);
}
//----------------------------------------------------------------------------//
void NamedElement::removeChild(const String& name_path)
{
    NamedElement* e = getChildByNamePath_impl(name_path);

    if (e)
        removeChild(e);
    else
        CEGUI_THROW(UnknownObjectException("The Element object "
            "referenced by '" + name_path + "' is not attached to Element at '"
            + getNamePath() + "'."));
}
//----------------------------------------------------------------------------//
NamedElement* NamedElement::getChildElement(const String& name_path) const
{
    NamedElement* e = getChildByNamePath_impl(name_path);

    if (e)
        return e;

    CEGUI_THROW(UnknownObjectException("The Element object "
        "referenced by '" + name_path + "' is not attached to Element at '"
        + getNamePath() + "'."));
}
示例#4
0
//----------------------------------------------------------------------------//
void GroupBox::addChild_impl(Element* element)
{
    Window* wnd = dynamic_cast<Window*>(element);
    
    if (!wnd)
        throw InvalidRequestException(
            "GroupBox can only have Elements of type Window added as children "
            "(Window path: " + getNamePath() + ").");

    if (wnd->isAutoWindow())
        Window::addChild_impl(wnd);
    else if (Window * pane = getContentPane())
        pane->addChild(wnd);
}
//----------------------------------------------------------------------------//
void NamedElement::addChild_impl(Element* element)
{
    NamedElement* named_element = dynamic_cast<NamedElement*>(element);

    if (named_element)
    {
        const NamedElement* const existing = getChildByNamePath_impl(named_element->getName());

        if (existing && named_element != existing)
            CEGUI_THROW(AlreadyExistsException("Failed to add "
                "Element named: " + named_element->getName() + " to element at: " +
                getNamePath() + " since an Element with that name is already "
                "attached."));
    }

    Element::addChild_impl(element);
}
示例#6
0
/*************************************************************************
    Internal version of adding a child window.
*************************************************************************/
void MenuItem::addChild_impl(Element* element)
{
    Window* wnd = dynamic_cast<Window*>(element);

    if (!wnd)
        CEGUI_THROW(InvalidRequestException(
                        "MenuItem can only have Elements of type Window added as children "
                        "(Window path: " + getNamePath() + ")."));

    ItemEntry::addChild_impl(wnd);

    PopupMenu* pop = dynamic_cast<PopupMenu*>(wnd);
    // if this is a PopupMenu we add it like one
    if (pop)
    {
        setPopupMenu_impl(pop, false);
    }
}
//----------------------------------------------------------------------------//
void LayoutContainer::addChild_impl(Element* element)
{
    Window* wnd = dynamic_cast<Window*>(element);
    
    if (!wnd)
        CEGUI_THROW(InvalidRequestException(
            "LayoutContainer can only have Elements of type Window added as "
            "children (Window path: " + getNamePath() + ")."));
    
    Window::addChild_impl(wnd);

    // we have to subscribe to the EventSized for layout updates
    d_eventConnections.insert(std::make_pair(wnd,
        wnd->subscribeEvent(Window::EventSized,
            Event::Subscriber(&LayoutContainer::handleChildSized, this))));
    d_eventConnections.insert(std::make_pair(wnd,
        wnd->subscribeEvent(Window::EventMarginChanged,
            Event::Subscriber(&LayoutContainer::handleChildMarginChanged, this))));
}
示例#8
0
void Editbox::setValidationString(const String& validation_string)
{
    if (validation_string == d_validationString)
        return;

    if (!d_validator)
        throw InvalidRequestException(
            "Unable to set validation string on Editbox '" + getNamePath() +
            "' because it does not currently have a RegexMatcher validator.");

    d_validationString = validation_string;
    d_validator->setRegexString(validation_string);

    // notification
    WindowEventArgs args(this);
    onValidationStringChanged(args);

    handleValidityChangeForString(getText());
}
示例#9
0
//----------------------------------------------------------------------------//
void ScrollablePane::addChild_impl(Element* element)
{
    Window* wnd = dynamic_cast<Window*>(element);
    
    if (!wnd)
        CEGUI_THROW(InvalidRequestException(
            "ScrollablePane can only have Elements of "
            "type Window added as children (Window path: " +
            getNamePath() + ")."));
    
    if (wnd->isAutoWindow())
    {
        // This is an internal widget, so should be added normally.
        Window::addChild_impl(wnd);
    }
    // this is a client window/widget, so should be added to the pane container.
    else
    {
        // container should always be valid by the time we're adding client
        // controls
        getScrolledContainer()->addChild(wnd);
    }
}
示例#10
0
//----------------------------------------------------------------------------//
void GridLayoutContainer::addChild_impl(Element* element)
{
    Window* wnd = dynamic_cast<Window*>(element);
    
    if (!wnd)
    {
        CEGUI_THROW(InvalidRequestException(
            "GridLayoutContainer can only have Elements of type Window added "
            "as children (Window path: " + getNamePath() + ")."));
    }
    
    if (isDummy(wnd))
    {
        LayoutContainer::addChild_impl(wnd);
    }
    else
    {
        LayoutContainer::addChild_impl(wnd);

        // OK, wnd is already in d_children

        // idx is the future index of the child that's being added
        size_t idx;

        if (d_autoPositioning == AP_Disabled)
        {
            if ((d_nextGridX == std::numeric_limits<size_t>::max()) &&
                (d_nextGridY == std::numeric_limits<size_t>::max()))
            {
                CEGUI_THROW(InvalidRequestException(
                    "Unable to add child without explicit grid position "
                    "because auto positioning is disabled.  Consider using the "
                    "GridLayoutContainer::addChildToPosition functions."));
            }

            idx = mapFromGridToIdx(d_nextGridX, d_nextGridY,
                                   d_gridWidth, d_gridHeight);

            // reset location to sentinel values.
            d_nextGridX = d_nextGridY = std::numeric_limits<size_t>::max();
        }
        else
        {
            idx = translateAPToGridIdx(d_nextAutoPositioningIdx);
            ++d_nextAutoPositioningIdx;
        }

        // we swap the dummy and the added child
        // this essentially places the added child to it's right position and
        // puts the dummy at the end of d_children it will soon get removed from
        std::swap(d_children[idx], d_children[d_children.size() - 1]);

        Window* toBeRemoved = static_cast<Window*>(d_children[d_children.size() - 1]);
        removeChild(toBeRemoved);

        if (toBeRemoved->isDestroyedByParent())
        {
            WindowManager::getSingleton().destroyWindow(toBeRemoved);
        }
    }
}