/* _______ __ __ __ ______ __ __ _______ __ __ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ * * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson * * Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// * _Qhm`] _f "'c 1!5m * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' * binary forms, with or without )4d[#7r, . ' )d`)[ * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' * that the following conditions are met: j<. a J@\ * this list of conditions and the j(]1u Widget::mWidgets; Widget::Widget() : mForegroundColor(0x000000), mBackgroundColor(0xffffff), mBaseColor(0x808090), mFocusHandler(NULL), mInternalFocusHandler(NULL), mParent(NULL), mBorderSize(0), mFocusable(false), mVisible(true), mTabIn(true), mTabOut(true), mEnabled(true), mCurrentFont(NULL) { mWidgets.push_back(this); } Widget::~Widget() { DeathListenerIterator iter; for (iter = mDeathListeners.begin(); iter != mDeathListeners.end(); ++iter) { Event event(this); (*iter)->death(event); } _setFocusHandler(NULL); mWidgets.remove(this); } void Widget::_setParent(Widget* parent) { mParent = parent; } Widget* Widget::getParent() const { return mParent; } void Widget::setWidth(int width) { mDimension.width = width; } int Widget::getWidth() const { return mDimension.width; } void Widget::setHeight(int height) { mDimension.height = height; } int Widget::getHeight() const { return mDimension.height; } void Widget::setX(int x) { mDimension.x = x; } int Widget::getX() const { return mDimension.x; } void Widget::setY(int y) { mDimension.y = y; } int Widget::getY() const { return mDimension.y; } void Widget::setPosition(int x, int y) { mDimension.x = x; mDimension.y = y; } void Widget::setDimension(const Rectangle& dimension) { mDimension = dimension; } void Widget::setBorderSize(unsigned int borderSize) { mBorderSize = borderSize; } unsigned int Widget::getBorderSize() const { return mBorderSize; } const Rectangle& Widget::getDimension() const { return mDimension; } const std::string& Widget::getActionEventId() const { return mActionEventId; } void Widget::setActionEventId(const std::string& actionEventId) { mActionEventId = actionEventId; } bool Widget::isFocused() const { if (!mFocusHandler) { return false; } return (mFocusHandler->isFocused(this)); } void Widget::setFocusable(bool focusable) { if (!focusable && isFocused()) { mFocusHandler->focusNone(); } mFocusable = focusable; } bool Widget::isFocusable() const { return mFocusable && isVisible() && isEnabled(); } void Widget::requestFocus() { if (mFocusHandler == NULL) { throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); } if (isFocusable()) { mFocusHandler->requestFocus(this); } } void Widget::requestMoveToTop() { if (mParent) { mParent->moveToTop(this); } } void Widget::requestMoveToBottom() { if (mParent) { mParent->moveToBottom(this); } } void Widget::setVisible(bool visible) { if (!visible && isFocused()) { mFocusHandler->focusNone(); } mVisible = visible; } bool Widget::isVisible() const { if (getParent() == NULL) { return mVisible; } else { return mVisible && getParent()->isVisible(); } } void Widget::setBaseColor(const Color& color) { mBaseColor = color; } const Color& Widget::getBaseColor() const { return mBaseColor; } void Widget::setForegroundColor(const Color& color) { mForegroundColor = color; } const Color& Widget::getForegroundColor() const { return mForegroundColor; } void Widget::setBackgroundColor(const Color& color) { mBackgroundColor = color; } const Color& Widget::getBackgroundColor() const { return mBackgroundColor; } void Widget::_setFocusHandler(FocusHandler* focusHandler) { if (mFocusHandler) { releaseModalFocus(); mFocusHandler->remove(this); } if (focusHandler) { focusHandler->add(this); } mFocusHandler = focusHandler; } FocusHandler* Widget::_getFocusHandler() { return mFocusHandler; } void Widget::addActionListener(ActionListener* actionListener) { mActionListeners.push_back(actionListener); } void Widget::removeActionListener(ActionListener* actionListener) { mActionListeners.remove(actionListener); } void Widget::addDeathListener(DeathListener* deathListener) { mDeathListeners.push_back(deathListener); } void Widget::removeDeathListener(DeathListener* deathListener) { mDeathListeners.remove(deathListener); } void Widget::addKeyListener(KeyListener* keyListener) { mKeyListeners.push_back(keyListener); } void Widget::removeKeyListener(KeyListener* keyListener) { mKeyListeners.remove(keyListener); } void Widget::addMouseListener(MouseListener* mouseListener) { mMouseListeners.push_back(mouseListener); } void Widget::removeMouseListener(MouseListener* mouseListener) { mMouseListeners.remove(mouseListener); } void Widget::getAbsolutePosition(int& x, int& y) const { if (getParent() == NULL) { x = mDimension.x; y = mDimension.y; return; } int parentX; int parentY; getParent()->getAbsolutePosition(parentX, parentY); x = parentX + mDimension.x + getParent()->getChildrenArea().x; y = parentY + mDimension.y + getParent()->getChildrenArea().y; } void Widget::generateAction() { ActionListenerIterator iter; for (iter = mActionListeners.begin(); iter != mActionListeners.end(); ++iter) { ActionEvent actionEvent(this, mActionEventId); (*iter)->action(actionEvent); } } Font* Widget::getFont() const { if (mCurrentFont == NULL) { if (mGlobalFont == NULL) { return &mDefaultFont; } return mGlobalFont; } return mCurrentFont; } void Widget::setGlobalFont(Font* font) { mGlobalFont = font; std::list::iterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) { if ((*iter)->mCurrentFont == NULL) { (*iter)->fontChanged(); } } } void Widget::setFont(Font* font) { mCurrentFont = font; fontChanged(); } bool Widget::widgetExists(const Widget* widget) { bool result = false; std::list::iterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) { if (*iter == widget) { return true; } } return result; } bool Widget::isTabInEnabled() const { return mTabIn; } void Widget::setTabInEnabled(bool enabled) { mTabIn = enabled; } bool Widget::isTabOutEnabled() const { return mTabOut; } void Widget::setTabOutEnabled(bool enabled) { mTabOut = enabled; } void Widget::setSize(int width, int height) { setWidth(width); setHeight(height); } void Widget::setEnabled(bool enabled) { mEnabled = enabled; } bool Widget::isEnabled() const { return mEnabled && isVisible(); } void Widget::requestModalFocus() { if (mFocusHandler == NULL) { throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); } mFocusHandler->requestModalFocus(this); } void Widget::requestModalMouseInputFocus() { if (mFocusHandler == NULL) { throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); } mFocusHandler->requestModalMouseInputFocus(this); } void Widget::releaseModalFocus() { if (mFocusHandler == NULL) { return; } mFocusHandler->releaseModalFocus(this); } void Widget::releaseModalMouseInputFocus() { if (mFocusHandler == NULL) { return; } mFocusHandler->releaseModalMouseInputFocus(this); } bool Widget::hasModalFocus() const { if (mFocusHandler == NULL) { throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); } if (getParent() != NULL) { return (mFocusHandler->getModalFocused() == this) || getParent()->hasModalFocus(); } return mFocusHandler->getModalFocused() == this; } bool Widget::hasModalMouseInputFocus() const { if (mFocusHandler == NULL) { throw GCN_EXCEPTION("No focushandler set (did you add the widget to the gui?)."); } if (getParent() != NULL) { return (mFocusHandler->getModalMouseInputFocused() == this) || getParent()->hasModalMouseInputFocus(); } return mFocusHandler->getModalMouseInputFocused() == this; } Widget *Widget::getWidgetAt(int x, int y) { return NULL; } const std::list& Widget::_getMouseListeners() { return mMouseListeners; } const std::list& Widget::_getKeyListeners() { return mKeyListeners; } Rectangle Widget::getChildrenArea() { return Rectangle(0, 0, 0, 0); } FocusHandler* Widget::_getInternalFocusHandler() { return mInternalFocusHandler; } void Widget::setInternalFocusHandler(FocusHandler* focusHandler) { mInternalFocusHandler = focusHandler; } }