void InternalWindow::close(void)
{
    _VetoWindowClose = false;

    produceWindowClosing();

    if(!_VetoWindowClose && getDrawingSurface() != NULL)
    {
        getDrawingSurface()->closeWindow(this);
        produceWindowClosed();
    }
}
void DialogWindow::close(UInt32 intOption, std::string strInput)
{
    _VetoWindowClose = false;

    produceDialogWindowClosing(intOption,strInput);
    produceWindowClosing();

    if(!_VetoWindowClose && getDrawingSurface() != NULL)
    {
        getDrawingSurface()->closeWindow(DialogWindowRefPtr(this));
        produceDialogWindowClosed(intOption,strInput);
        produceWindowClosed();
    }
}
void InternalWindow::setMaximize(bool Maximize)
{
    if(Maximize && !getIsMaximized())
    {
        _PreviousPosition = getPosition();
        _PreviousSize = getSize();
        setIsMaximized(Maximize);
        setPosition(Pnt2f(0,0));
        setPreferredSize(Vec2f(getDrawingSurface()->getSize().x(),getDrawingSurface()->getSize().x()));
    }
    else if(!Maximize && getIsMaximized())
    {
        setIsMaximized(Maximize);
        Vec2f TempSize(_PreviousSize);
        Pnt2f TempPos(_PreviousPosition);
        setPreferredSize(TempSize);
        setPosition(TempPos);
        _PreviousPosition = getPosition();
        _PreviousSize = getSize();
    }
}
bool InternalWindow::takeFocus(bool Temporary)
{

    if(getFocused() &&
       getDrawingSurface() != NULL &&
       getDrawingSurface()->getFocusedWindow() == InternalWindowRefPtr(this))
    {
        return true;
    }
    setFocused(true);
    if(Temporary || getDrawingSurface() == NULL)
    {
        focusGained(FocusEvent::create(ComponentRefPtr(this),getSystemTime(),Temporary, NULL));
    }
    else
    {
        if(getDrawingSurface()->getFocusedWindow() != NULL)
        {
            getDrawingSurface()->getFocusedWindow()->giveFocus(this);
        }
        getDrawingSurface()->setFocusedWindow(this);
        focusGained(FocusEvent::create(ComponentRefPtr(this),getSystemTime(),Temporary, getDrawingSurface()->getFocusedWindow()));
    }
    return true;
}
void InternalWindow::mouseExited(const MouseEventUnrecPtr e)
{
    if(getMenuBar() != NULL)
    {
        bool isContained;
        isContained = getMenuBar()->isContained(e->getLocation(), true);
        checkMouseEnterExit(e,e->getLocation(),getMenuBar(),isContained,e->getViewport());
    }
    if(getTitlebar() != NULL)
    {
        bool isContained;
        isContained = getTitlebar()->isContained(e->getLocation(), true);
        checkMouseEnterExit(e,e->getLocation(),getTitlebar(),isContained,e->getViewport());
    }
    if(!getLockInput())
    {
        if(getDrawingSurface() != NULL && getDrawingSurface()->getEventProducer() != NULL)
        {
            getDrawingSurface()->getEventProducer()->setCursorType(WindowEventProducer::CURSOR_POINTER);
        }
        ComponentContainer::mouseExited(e);
    }
}
void InternalWindow::changed(ConstFieldMaskArg whichField, 
                             UInt32            origin,
                             BitVector         details)
{
    if( ((whichField & FocusedFieldMask) ||
         (whichField & TitlebarFieldMask))&&
        getTitlebar() != NULL)
    {
        getTitlebar()->setEnabled(getFocused());
    }

    if( (whichField & ActiveToolTipFieldMask) &&
        getActiveToolTip() != NULL)
    {
        getActiveToolTip()->updateClipBounds();
    }

    if( (whichField & ActivePopupMenusFieldMask) &&
        getMFActivePopupMenus()->size() > 0)
    {
        for(UInt32 i(0) ; i<getMFActivePopupMenus()->size() ; ++i)
        {
            getActivePopupMenus(i)->setParentContainer(this);
            getActivePopupMenus(i)->setParentWindow(this);
        }

        getDrawingSurface()->getEventProducer()->addMouseListener(&_PopupMenuInteractionListener);
        getDrawingSurface()->getEventProducer()->addMouseMotionListener(&_PopupMenuInteractionListener);
        getDrawingSurface()->getEventProducer()->addKeyListener(&_PopupMenuInteractionListener);
        setLockInput(true);
    }

    if( (whichField & MenuBarFieldMask) && getMenuBar() != NULL)
    {
        getMenuBar()->setParentContainer(this);
        getMenuBar()->setParentWindow(this);
    }

    if( (whichField & MenuBarFieldMask) || (whichField & TitlebarFieldMask))
    {
        updateLayout();
    }

    if( (whichField & TitleFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setTitle(getTitle());
    }

    if( (whichField & TitlebarFieldMask) && getTitlebar() != NULL)
    {
        getTitlebar()->setParentContainer(this);
        getTitlebar()->setParentWindow(this);
    }

    if((whichField & TitlebarFieldMask) ||
       (whichField & BorderFieldMask) ||
       (whichField & DisabledBorderFieldMask) ||
       (whichField & FocusedBorderFieldMask) ||
       (whichField & RolloverBorderFieldMask) ||
       (whichField & DrawTitlebarFieldMask))
    {
        TitlebarRefPtr TheTitlebar;
        if(getDrawTitlebar())
        {
            TheTitlebar = getTitlebar();
        }
        else
        {
            TheTitlebar = NULL;
        }

        if(getBorder() != NULL && getBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getBorder())->setTitlebar(TheTitlebar);
        }
        if(getDisabledBorder() != NULL && getDisabledBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getDisabledBorder())->setTitlebar(TheTitlebar);
        }
        if(getFocusedBorder() != NULL && getFocusedBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getFocusedBorder())->setTitlebar(TheTitlebar);
        }
        if(getRolloverBorder() != NULL && getRolloverBorder()->getType().isDerivedFrom(WindowBorder::getClassType()))
        {
            dynamic_cast<WindowBorder*>(getRolloverBorder())->setTitlebar(TheTitlebar);
        }
    }

    if( whichField & ClipBoundsFieldMask)
    {
        if(getTitlebar() != NULL)
        {
            getTitlebar()->updateClipBounds();
        }
    }

    if( (whichField & TitlebarFieldMask) &&
        getTitlebar() != NULL)
    {
        if(getTitlebar()->getTitleLabel() != NULL)
        {
            getTitlebar()->getTitleLabel()->addMouseListener(&_TitlebarStartDragListener);
        }
        if(getTitlebar()->getCloseButton() != NULL)
        {
            getTitlebar()->getCloseButton()->addActionListener(&_CloseButtonListener);
        }
        if(getTitlebar()->getMaximizeButton() != NULL)
        {
            getTitlebar()->getMaximizeButton()->addActionListener(&_MaximizeButtonListener);
        }
        if(getTitlebar()->getIconifyButton() != NULL)
        {
            getTitlebar()->getIconifyButton()->addActionListener(&_IconifyButtonListener);
        }
    }

    if( (whichField & IconableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawIconify(getIconable());
    }
    if( (whichField & MaximizableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawMaximize(getMaximizable());
    }
    if( (whichField & ClosableFieldMask) &&
        getTitlebar() != NULL)
    {
        getTitlebar()->setDrawClose(getClosable());
    }

    Inherited::changed(whichField, origin, details);
}
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);
    }
}