<commit_before>/*      _______   __   __   __   ______   __   __   _______   __   __
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
 *
 * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson
 *
 *
 * Per Larsson a.k.a finalman
 * Olof Naessn a.k.a jansem/yakslem
 *
 * Visit: http://guichan.sourceforge.net
 *
 * License: (BSD)
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name of Guichan nor the names of its contributors may
 *    be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * For comments regarding functions please see the header file.
 */

#include "guichan/widgets/textbox.hpp"

#include "guichan/basiccontainer.hpp"
#include "guichan/font.hpp"
#include "guichan/graphics.hpp"
#include "guichan/key.hpp"
#include "guichan/mouseinput.hpp"

namespace gcn
{
    TextBox::TextBox()
    {
        mCaretColumn = 0;
        mCaretRow = 0;
        mEditable = true;
        mOpaque = true;

        setFocusable(true);

        addMouseListener(this);
        addKeyListener(this);
        adjustSize();
    }

    TextBox::TextBox(const std::string& text)
    {
        mCaretColumn = 0;
        mCaretRow = 0;
        mEditable = true;
        mOpaque = true;

        setText(text);

        setFocusable(true);

        addMouseListener(this);
        addKeyListener(this);
        adjustSize();
    }

    void TextBox::setText(const std::string& text)
    {
        mCaretColumn = 0;
        mCaretRow = 0;

        mTextRows.clear();

        std::string::size_type pos, lastPos = 0;
        int length;
        do
        {
            pos = text.find("\n", lastPos);

            if (pos != std::string::npos)
            {
                length = pos - lastPos;
            }
            else
            {
                length = text.size() - lastPos;
            }
            std::string sub = text.substr(lastPos, length);
            mTextRows.push_back(sub);
            lastPos = pos + 1;

        } while (pos != std::string::npos);

        adjustSize();
    }

    void TextBox::draw(Graphics* graphics)
    {
        unsigned int i;

        if (mOpaque)
        {
            graphics->setColor(getBackgroundColor());
            graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
        }

        if (isFocused() && isEditable())
        {
            drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), mCaretRow * getFont()->getHeight());
        }

        graphics->setColor(getForegroundColor());
        graphics->setFont(getFont());

        for (i = 0; i < mTextRows.size(); i++)
        {
            // Move the text one pixel so we can have a caret before a letter.
            graphics->drawText(mTextRows[i], 1, i * getFont()->getHeight());
        }
    }

    void TextBox::drawCaret(Graphics* graphics, int x, int y)
    {
        graphics->setColor(getForegroundColor());
        graphics->drawLine(x, getFont()->getHeight() + y, x, y);
    }

    void TextBox::mousePressed(MouseEvent& mouseEvent)
    {
        if (mouseEvent.getButton() == MouseEvent::LEFT)
        {
            mCaretRow = mouseEvent.getY() / getFont()->getHeight();

            if (mCaretRow >= (int)mTextRows.size())
            {
                mCaretRow = mTextRows.size() - 1;
            }

            mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX());
        }
    }

    void TextBox::mouseDragged(MouseEvent& mouseEvent)
    {
        mouseEvent.consume();
    }

    void TextBox::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::LEFT)
        {
            --mCaretColumn;
            if (mCaretColumn < 0)
            {
                --mCaretRow;

                if (mCaretRow < 0)
                {
                    mCaretRow = 0;
                    mCaretColumn = 0;
                }
                else
                {
                    mCaretColumn = mTextRows[mCaretRow].size();
                }
            }
        }

        else if (key.getValue() == Key::RIGHT)
        {
            ++mCaretColumn;
            if (mCaretColumn > (int)mTextRows[mCaretRow].size())
            {
                ++mCaretRow;

                if (mCaretRow >= (int)mTextRows.size())
                {
                    mCaretRow = mTextRows.size() - 1;
                    if (mCaretRow < 0)
                    {
                        mCaretRow = 0;
                    }

                    mCaretColumn = mTextRows[mCaretRow].size();
                }
                else
                {
                    mCaretColumn = 0;
                }
            }
        }

        else if (key.getValue() == Key::DOWN)
        {
            setCaretRow(mCaretRow + 1);
        }

        else if (key.getValue() == Key::UP)
        {
            setCaretRow(mCaretRow - 1);
        }

        else if (key.getValue() == Key::HOME)
        {
            mCaretColumn = 0;
        }

        else if (key.getValue() == Key::END)
        {
            mCaretColumn = mTextRows[mCaretRow].size();
        }

        else if (key.getValue() == Key::ENTER && mEditable)
        {
            mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
                             mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn));
            mTextRows[mCaretRow].resize(mCaretColumn);
            ++mCaretRow;
            mCaretColumn = 0;
        }

        else if (key.getValue() == Key::BACKSPACE
                 && mCaretColumn != 0
                 && mEditable)
        {
            mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
            --mCaretColumn;
        }

        else if (key.getValue() == Key::BACKSPACE
                 && mCaretColumn == 0
                 && mCaretRow != 0
                 && mEditable)
        {
            mCaretColumn = mTextRows[mCaretRow - 1].size();
            mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
            mTextRows.erase(mTextRows.begin() + mCaretRow);
            --mCaretRow;
        }

        else if (key.getValue() == Key::DELETE
                 && mCaretColumn < (int)mTextRows[mCaretRow].size()
                 && mEditable)
        {
            mTextRows[mCaretRow].erase(mCaretColumn, 1);
        }

        else if (key.getValue() == Key::DELETE
                 && mCaretColumn == (int)mTextRows[mCaretRow].size()
                 && mCaretRow < ((int)mTextRows.size() - 1)
                 && mEditable)
        {
            mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
            mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
        }

        else if(key.getValue() == Key::PAGE_UP)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mCaretRow -= rowsPerPage;

                if (mCaretRow < 0)
                {
                    mCaretRow = 0;
                }
            }
        }

        else if(key.getValue() == Key::PAGE_DOWN)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mCaretRow += rowsPerPage;

                if (mCaretRow >= (int)mTextRows.size())
                {
                    mCaretRow = mTextRows.size() - 1;
                }
            }
        }

        else if(key.getValue() == Key::TAB
                && mEditable)
        {
            mTextRows[mCaretRow].insert(mCaretColumn,std::string("    "));
            mCaretColumn += 4;
        }

        else if (key.isCharacter()
                 && mEditable)
        {
            mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,(char)key.getValue()));
            ++mCaretColumn;
        }

        adjustSize();
        scrollToCaret();

        keyEvent.consume();
    }

    void TextBox::adjustSize()
    {
        unsigned int i;
        int width = 0;
        for (i = 0; i < mTextRows.size(); ++i)
        {
            int w = getFont()->getWidth(mTextRows[i]);
            if (width < w)
            {
                width = w;
            }
        }

        setWidth(width + 1);
        setHeight(getFont()->getHeight() * mTextRows.size());
    }

    void TextBox::setCaretPosition(unsigned int position)
    {
        int row;

        for (row = 0; row < (int)mTextRows.size(); row++)
        {
            if (position <= mTextRows[row].size())
            {
                mCaretRow = row;
                mCaretColumn = position;
                return; // we are done
            }
            else
            {
                position--;
            }
        }

        // position beyond end of text
        mCaretRow = mTextRows.size() - 1;
        mCaretColumn = mTextRows[mCaretRow].size();
    }

    unsigned int TextBox::getCaretPosition() const
    {
        int pos = 0, row;

        for (row = 0; row < mCaretRow; row++)
        {
            pos += mTextRows[row].size();
        }

        return pos + mCaretColumn;
    }

    void TextBox::setCaretRowColumn(int row, int column)
    {
        setCaretRow(row);
        setCaretColumn(column);
    }

    void TextBox::setCaretRow(int row)
    {
        mCaretRow = row;

        if (mCaretRow >= (int)mTextRows.size())
        {
            mCaretRow = mTextRows.size() - 1;
        }

        if (mCaretRow < 0)
        {
            mCaretRow = 0;
        }

        setCaretColumn(mCaretColumn);
    }

    unsigned int TextBox::getCaretRow() const
    {
        return mCaretRow;
    }

    void TextBox::setCaretColumn(int column)
    {
        mCaretColumn = column;

        if (mCaretColumn > (int)mTextRows[mCaretRow].size())
        {
            mCaretColumn = mTextRows[mCaretRow].size();
        }

        if (mCaretColumn < 0)
        {
            mCaretColumn = 0;
        }
    }

    unsigned int TextBox::getCaretColumn() const
    {
        return mCaretColumn;
    }

    const std::string& TextBox::getTextRow(int row) const
    {
        return mTextRows[row];
    }

    void TextBox::setTextRow(int row, const std::string& text)
    {
        mTextRows[row] = text;

        if (mCaretRow == row)
        {
            setCaretColumn(mCaretColumn);
        }

        adjustSize();
    }

    unsigned int TextBox::getNumberOfRows() const
    {
        return mTextRows.size();
    }

    std::string TextBox::getText() const
    {
        if (mTextRows.size() == 0)
        {
            return std::string("");
        }

        int i;
        std::string text;

        for (i = 0; i < (int)mTextRows.size() - 1; ++i)
        {
            text = text + mTextRows[i] + "\n";
        }

        text = text + mTextRows[i];

        return text;
    }

    void TextBox::fontChanged()
    {
        adjustSize();
    }

    void TextBox::scrollToCaret()
    {
        Rectangle scroll;
        scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn));
        scroll.y = getFont()->getHeight() * mCaretRow;
        scroll.width = getFont()->getWidth(" ");
        scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space

        showPart(scroll);
    }

    void TextBox::setEditable(bool editable)
    {
        mEditable = editable;
    }

    bool TextBox::isEditable() const
    {
        return mEditable;
    }

    void TextBox::addRow(const std::string row)
    {
        mTextRows.push_back(row);
        adjustSize();
    }

    bool TextBox::isOpaque()
    {
        return mOpaque;
    }

    void TextBox::setOpaque(bool opaque)
    {
        mOpaque = opaque;
    }
}
<commit_msg>http://code.google.com/p/guichan/issues/detail?id=79<commit_after>/*      _______   __   __   __   ______   __   __   _______   __   __
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
 *
 * Copyright (c) 2004 - 2008 Olof Naessn and Per Larsson
 *
 *
 * Per Larsson a.k.a finalman
 * Olof Naessn a.k.a jansem/yakslem
 *
 * Visit: http://guichan.sourceforge.net
 *
 * License: (BSD)
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name of Guichan nor the names of its contributors may
 *    be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * For comments regarding functions please see the header file.
 */

#include "guichan/widgets/textbox.hpp"

#include "guichan/basiccontainer.hpp"
#include "guichan/font.hpp"
#include "guichan/graphics.hpp"
#include "guichan/key.hpp"
#include "guichan/mouseinput.hpp"

namespace gcn
{
    TextBox::TextBox()
    {
        mCaretColumn = 0;
        mCaretRow = 0;
        mEditable = true;
        mOpaque = true;

        setText("");

        setFocusable(true);

        addMouseListener(this);
        addKeyListener(this);
        adjustSize();
    }

    TextBox::TextBox(const std::string& text)
    {
        mCaretColumn = 0;
        mCaretRow = 0;
        mEditable = true;
        mOpaque = true;

        setText(text);

        setFocusable(true);

        addMouseListener(this);
        addKeyListener(this);
        adjustSize();
    }

    void TextBox::setText(const std::string& text)
    {
        mCaretColumn = 0;
        mCaretRow = 0;

        mTextRows.clear();

        std::string::size_type pos, lastPos = 0;
        int length;
        do
        {
            pos = text.find("\n", lastPos);

            if (pos != std::string::npos)
            {
                length = pos - lastPos;
            }
            else
            {
                length = text.size() - lastPos;
            }
            std::string sub = text.substr(lastPos, length);
            mTextRows.push_back(sub);
            lastPos = pos + 1;

        } while (pos != std::string::npos);

        adjustSize();
    }

    void TextBox::draw(Graphics* graphics)
    {
        unsigned int i;

        if (mOpaque)
        {
            graphics->setColor(getBackgroundColor());
            graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight()));
        }

        if (isFocused() && isEditable())
        {
            drawCaret(graphics, getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)), mCaretRow * getFont()->getHeight());
        }

        graphics->setColor(getForegroundColor());
        graphics->setFont(getFont());

        for (i = 0; i < mTextRows.size(); i++)
        {
            // Move the text one pixel so we can have a caret before a letter.
            graphics->drawText(mTextRows[i], 1, i * getFont()->getHeight());
        }
    }

    void TextBox::drawCaret(Graphics* graphics, int x, int y)
    {
        graphics->setColor(getForegroundColor());
        graphics->drawLine(x, getFont()->getHeight() + y, x, y);
    }

    void TextBox::mousePressed(MouseEvent& mouseEvent)
    {
        if (mouseEvent.getButton() == MouseEvent::LEFT)
        {
            mCaretRow = mouseEvent.getY() / getFont()->getHeight();

            if (mCaretRow >= (int)mTextRows.size())
            {
                mCaretRow = mTextRows.size() - 1;
            }

            mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], mouseEvent.getX());
        }
    }

    void TextBox::mouseDragged(MouseEvent& mouseEvent)
    {
        mouseEvent.consume();
    }

    void TextBox::keyPressed(KeyEvent& keyEvent)
    {
        Key key = keyEvent.getKey();

        if (key.getValue() == Key::LEFT)
        {
            --mCaretColumn;
            if (mCaretColumn < 0)
            {
                --mCaretRow;

                if (mCaretRow < 0)
                {
                    mCaretRow = 0;
                    mCaretColumn = 0;
                }
                else
                {
                    mCaretColumn = mTextRows[mCaretRow].size();
                }
            }
        }

        else if (key.getValue() == Key::RIGHT)
        {
            ++mCaretColumn;
            if (mCaretColumn > (int)mTextRows[mCaretRow].size())
            {
                ++mCaretRow;

                if (mCaretRow >= (int)mTextRows.size())
                {
                    mCaretRow = mTextRows.size() - 1;
                    if (mCaretRow < 0)
                    {
                        mCaretRow = 0;
                    }

                    mCaretColumn = mTextRows[mCaretRow].size();
                }
                else
                {
                    mCaretColumn = 0;
                }
            }
        }

        else if (key.getValue() == Key::DOWN)
        {
            setCaretRow(mCaretRow + 1);
        }

        else if (key.getValue() == Key::UP)
        {
            setCaretRow(mCaretRow - 1);
        }

        else if (key.getValue() == Key::HOME)
        {
            mCaretColumn = 0;
        }

        else if (key.getValue() == Key::END)
        {
            mCaretColumn = mTextRows[mCaretRow].size();
        }

        else if (key.getValue() == Key::ENTER && mEditable)
        {
            mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
                             mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn));
            mTextRows[mCaretRow].resize(mCaretColumn);
            ++mCaretRow;
            mCaretColumn = 0;
        }

        else if (key.getValue() == Key::BACKSPACE
                 && mCaretColumn != 0
                 && mEditable)
        {
            mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
            --mCaretColumn;
        }

        else if (key.getValue() == Key::BACKSPACE
                 && mCaretColumn == 0
                 && mCaretRow != 0
                 && mEditable)
        {
            mCaretColumn = mTextRows[mCaretRow - 1].size();
            mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
            mTextRows.erase(mTextRows.begin() + mCaretRow);
            --mCaretRow;
        }

        else if (key.getValue() == Key::DELETE
                 && mCaretColumn < (int)mTextRows[mCaretRow].size()
                 && mEditable)
        {
            mTextRows[mCaretRow].erase(mCaretColumn, 1);
        }

        else if (key.getValue() == Key::DELETE
                 && mCaretColumn == (int)mTextRows[mCaretRow].size()
                 && mCaretRow < ((int)mTextRows.size() - 1)
                 && mEditable)
        {
            mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
            mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
        }

        else if(key.getValue() == Key::PAGE_UP)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mCaretRow -= rowsPerPage;

                if (mCaretRow < 0)
                {
                    mCaretRow = 0;
                }
            }
        }

        else if(key.getValue() == Key::PAGE_DOWN)
        {
            Widget* par = getParent();

            if (par != NULL)
            {
                int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
                mCaretRow += rowsPerPage;

                if (mCaretRow >= (int)mTextRows.size())
                {
                    mCaretRow = mTextRows.size() - 1;
                }
            }
        }

        else if(key.getValue() == Key::TAB
                && mEditable)
        {
            mTextRows[mCaretRow].insert(mCaretColumn,std::string("    "));
            mCaretColumn += 4;
        }

        else if (key.isCharacter()
                 && mEditable)
        {
            mTextRows[mCaretRow].insert(mCaretColumn,std::string(1,(char)key.getValue()));
            ++mCaretColumn;
        }

        adjustSize();
        scrollToCaret();

        keyEvent.consume();
    }

    void TextBox::adjustSize()
    {
        unsigned int i;
        int width = 0;
        for (i = 0; i < mTextRows.size(); ++i)
        {
            int w = getFont()->getWidth(mTextRows[i]);
            if (width < w)
            {
                width = w;
            }
        }

        setWidth(width + 1);
        setHeight(getFont()->getHeight() * mTextRows.size());
    }

    void TextBox::setCaretPosition(unsigned int position)
    {
        int row;

        for (row = 0; row < (int)mTextRows.size(); row++)
        {
            if (position <= mTextRows[row].size())
            {
                mCaretRow = row;
                mCaretColumn = position;
                return; // we are done
            }
            else
            {
                position--;
            }
        }

        // position beyond end of text
        mCaretRow = mTextRows.size() - 1;
        mCaretColumn = mTextRows[mCaretRow].size();
    }

    unsigned int TextBox::getCaretPosition() const
    {
        int pos = 0, row;

        for (row = 0; row < mCaretRow; row++)
        {
            pos += mTextRows[row].size();
        }

        return pos + mCaretColumn;
    }

    void TextBox::setCaretRowColumn(int row, int column)
    {
        setCaretRow(row);
        setCaretColumn(column);
    }

    void TextBox::setCaretRow(int row)
    {
        mCaretRow = row;

        if (mCaretRow >= (int)mTextRows.size())
        {
            mCaretRow = mTextRows.size() - 1;
        }

        if (mCaretRow < 0)
        {
            mCaretRow = 0;
        }

        setCaretColumn(mCaretColumn);
    }

    unsigned int TextBox::getCaretRow() const
    {
        return mCaretRow;
    }

    void TextBox::setCaretColumn(int column)
    {
        mCaretColumn = column;

        if (mCaretColumn > (int)mTextRows[mCaretRow].size())
        {
            mCaretColumn = mTextRows[mCaretRow].size();
        }

        if (mCaretColumn < 0)
        {
            mCaretColumn = 0;
        }
    }

    unsigned int TextBox::getCaretColumn() const
    {
        return mCaretColumn;
    }

    const std::string& TextBox::getTextRow(int row) const
    {
        return mTextRows[row];
    }

    void TextBox::setTextRow(int row, const std::string& text)
    {
        mTextRows[row] = text;

        if (mCaretRow == row)
        {
            setCaretColumn(mCaretColumn);
        }

        adjustSize();
    }

    unsigned int TextBox::getNumberOfRows() const
    {
        return mTextRows.size();
    }

    std::string TextBox::getText() const
    {
        if (mTextRows.size() == 0)
        {
            return std::string("");
        }

        int i;
        std::string text;

        for (i = 0; i < (int)mTextRows.size() - 1; ++i)
        {
            text = text + mTextRows[i] + "\n";
        }

        text = text + mTextRows[i];

        return text;
    }

    void TextBox::fontChanged()
    {
        adjustSize();
    }

    void TextBox::scrollToCaret()
    {
        Rectangle scroll;
        scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn));
        scroll.y = getFont()->getHeight() * mCaretRow;
        scroll.width = getFont()->getWidth(" ");
        scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space

        showPart(scroll);
    }

    void TextBox::setEditable(bool editable)
    {
        mEditable = editable;
    }

    bool TextBox::isEditable() const
    {
        return mEditable;
    }

    void TextBox::addRow(const std::string row)
    {
        mTextRows.push_back(row);
        adjustSize();
    }

    bool TextBox::isOpaque()
    {
        return mOpaque;
    }

    void TextBox::setOpaque(bool opaque)
    {
        mOpaque = opaque;
    }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: format.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2005-04-04 08:03:10 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef FORMAT_HXX
#define FORMAT_HXX

#ifndef _SFXSMPLHINT_HXX //autogen
#include <svtools/smplhint.hxx>
#endif
#ifndef _SFXBRDCST_HXX //autogen
#include <svtools/brdcst.hxx>
#endif

#ifndef UTILITY_HXX
#include "utility.hxx"
#endif
#ifndef TYPES_HXX
#include <types.hxx>
#endif

#define SM_FMT_VERSION_51   ((BYTE) 0x01)
#define SM_FMT_VERSION_NOW  SM_FMT_VERSION_51

#ifndef MAC
#define FNTNAME_TIMES   "Times New Roman"
#else
#define FNTNAME_TIMES   "Times"
#endif
#define FNTNAME_HELV    "Helvetica"
#define FNTNAME_COUR    "Courier"
#define FNTNAME_MATH    FONTNAME_MATH

// symbolic names used as array indices
#define SIZ_BEGIN       0
#define SIZ_TEXT        0
#define SIZ_INDEX       1
#define SIZ_FUNCTION    2
#define SIZ_OPERATOR    3
#define SIZ_LIMITS      4
#define SIZ_END         4

// symbolic names used as array indices
#define FNT_BEGIN       0
#define FNT_VARIABLE    0
#define FNT_FUNCTION    1
#define FNT_NUMBER      2
#define FNT_TEXT        3
#define FNT_SERIF       4
#define FNT_SANS        5
#define FNT_FIXED       6
#define FNT_MATH        7
#define FNT_END         7

// symbolic names used as array indices
#define DIS_BEGIN                0
#define DIS_HORIZONTAL           0
#define DIS_VERTICAL             1
#define DIS_ROOT                 2
#define DIS_SUPERSCRIPT          3
#define DIS_SUBSCRIPT            4
#define DIS_NUMERATOR            5
#define DIS_DENOMINATOR          6
#define DIS_FRACTION             7
#define DIS_STROKEWIDTH          8
#define DIS_UPPERLIMIT           9
#define DIS_LOWERLIMIT          10
#define DIS_BRACKETSIZE         11
#define DIS_BRACKETSPACE        12
#define DIS_MATRIXROW           13
#define DIS_MATRIXCOL           14
#define DIS_ORNAMENTSIZE        15
#define DIS_ORNAMENTSPACE       16
#define DIS_OPERATORSIZE        17
#define DIS_OPERATORSPACE       18
#define DIS_LEFTSPACE           19
#define DIS_RIGHTSPACE          20
#define DIS_TOPSPACE            21
#define DIS_BOTTOMSPACE         22
#define DIS_NORMALBRACKETSIZE   23
#define DIS_END                 23

// to be broadcastet on format changes:
#define HINT_FORMATCHANGED  10003

enum SmHorAlign { AlignLeft, AlignCenter, AlignRight };

String GetDefaultFontName( LanguageType nLang, USHORT nIdent );

class SmFormat : public SfxBroadcaster
{
    SmFace      vFont[FNT_END + 1];
    BOOL        bDefaultFont[FNT_END + 1];
    Size        aBaseSize;
    long        nVersion;
    USHORT      vSize[SIZ_END + 1];
    USHORT      vDist[DIS_END + 1];
    SmHorAlign  eHorAlign;
    BOOL        bIsTextmode,
                bScaleNormalBrackets;

public:
    SmFormat();
    SmFormat(const SmFormat &rFormat) { *this = rFormat; }

    const Size &    GetBaseSize() const             { return aBaseSize; }
    void            SetBaseSize(const Size &rSize)  { aBaseSize = rSize; }

    const SmFace &  GetFont(USHORT nIdent) const { return vFont[nIdent]; }
    void            SetFont(USHORT nIdent, const SmFace &rFont, BOOL bDefault = FALSE);
    void            SetFontSize(USHORT nIdent, const Size &rSize)   { vFont[nIdent].SetSize( rSize ); }

    void            SetDefaultFont(USHORT nIdent, BOOL bVal)    { bDefaultFont[nIdent] = bVal; }
    BOOL            IsDefaultFont(USHORT nIdent) const   { return bDefaultFont[nIdent]; }

    USHORT          GetRelSize(USHORT nIdent) const         { return vSize[nIdent]; }
    void            SetRelSize(USHORT nIdent, USHORT nVal)  { vSize[nIdent] = nVal;}

    USHORT          GetDistance(USHORT nIdent) const            { return vDist[nIdent]; }
    void            SetDistance(USHORT nIdent, USHORT nVal) { vDist[nIdent] = nVal; }

    SmHorAlign      GetHorAlign() const             { return eHorAlign; }
    void            SetHorAlign(SmHorAlign eAlign)  { eHorAlign = eAlign; }

    BOOL            IsTextmode() const     { return bIsTextmode; }
    void            SetTextmode(BOOL bVal) { bIsTextmode = bVal; }

    BOOL            IsScaleNormalBrackets() const     { return bScaleNormalBrackets; }
    void            SetScaleNormalBrackets(BOOL bVal) { bScaleNormalBrackets = bVal; }

    long            GetVersion() const { return nVersion; }

    //! at time (5.1) use only the lower byte!!!
    void            SetVersion(long nVer) { nVersion = nVer; }

    SmFormat &      operator = (const SmFormat &rFormat);

    BOOL            operator == (const SmFormat &rFormat) const;
    inline BOOL     operator != (const SmFormat &rFormat) const;

    void RequestApplyChanges() const
    {
        ((SmFormat *) this)->Broadcast(SfxSimpleHint(HINT_FORMATCHANGED));
    }

};

inline BOOL    SmFormat::operator != (const SmFormat &rFormat) const
{
    return !(*this == rFormat);
}

#endif

<commit_msg>INTEGRATION: CWS ooo19126 (1.5.64); FILE MERGED 2005/09/05 17:37:22 rt 1.5.64.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: format.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 14:58:35 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef FORMAT_HXX
#define FORMAT_HXX

#ifndef _SFXSMPLHINT_HXX //autogen
#include <svtools/smplhint.hxx>
#endif
#ifndef _SFXBRDCST_HXX //autogen
#include <svtools/brdcst.hxx>
#endif

#ifndef UTILITY_HXX
#include "utility.hxx"
#endif
#ifndef TYPES_HXX
#include <types.hxx>
#endif

#define SM_FMT_VERSION_51   ((BYTE) 0x01)
#define SM_FMT_VERSION_NOW  SM_FMT_VERSION_51

#ifndef MAC
#define FNTNAME_TIMES   "Times New Roman"
#else
#define FNTNAME_TIMES   "Times"
#endif
#define FNTNAME_HELV    "Helvetica"
#define FNTNAME_COUR    "Courier"
#define FNTNAME_MATH    FONTNAME_MATH

// symbolic names used as array indices
#define SIZ_BEGIN       0
#define SIZ_TEXT        0
#define SIZ_INDEX       1
#define SIZ_FUNCTION    2
#define SIZ_OPERATOR    3
#define SIZ_LIMITS      4
#define SIZ_END         4

// symbolic names used as array indices
#define FNT_BEGIN       0
#define FNT_VARIABLE    0
#define FNT_FUNCTION    1
#define FNT_NUMBER      2
#define FNT_TEXT        3
#define FNT_SERIF       4
#define FNT_SANS        5
#define FNT_FIXED       6
#define FNT_MATH        7
#define FNT_END         7

// symbolic names used as array indices
#define DIS_BEGIN                0
#define DIS_HORIZONTAL           0
#define DIS_VERTICAL             1
#define DIS_ROOT                 2
#define DIS_SUPERSCRIPT          3
#define DIS_SUBSCRIPT            4
#define DIS_NUMERATOR            5
#define DIS_DENOMINATOR          6
#define DIS_FRACTION             7
#define DIS_STROKEWIDTH          8
#define DIS_UPPERLIMIT           9
#define DIS_LOWERLIMIT          10
#define DIS_BRACKETSIZE         11
#define DIS_BRACKETSPACE        12
#define DIS_MATRIXROW           13
#define DIS_MATRIXCOL           14
#define DIS_ORNAMENTSIZE        15
#define DIS_ORNAMENTSPACE       16
#define DIS_OPERATORSIZE        17
#define DIS_OPERATORSPACE       18
#define DIS_LEFTSPACE           19
#define DIS_RIGHTSPACE          20
#define DIS_TOPSPACE            21
#define DIS_BOTTOMSPACE         22
#define DIS_NORMALBRACKETSIZE   23
#define DIS_END                 23

// to be broadcastet on format changes:
#define HINT_FORMATCHANGED  10003

enum SmHorAlign { AlignLeft, AlignCenter, AlignRight };

String GetDefaultFontName( LanguageType nLang, USHORT nIdent );

class SmFormat : public SfxBroadcaster
{
    SmFace      vFont[FNT_END + 1];
    BOOL        bDefaultFont[FNT_END + 1];
    Size        aBaseSize;
    long        nVersion;
    USHORT      vSize[SIZ_END + 1];
    USHORT      vDist[DIS_END + 1];
    SmHorAlign  eHorAlign;
    BOOL        bIsTextmode,
                bScaleNormalBrackets;

public:
    SmFormat();
    SmFormat(const SmFormat &rFormat) { *this = rFormat; }

    const Size &    GetBaseSize() const             { return aBaseSize; }
    void            SetBaseSize(const Size &rSize)  { aBaseSize = rSize; }

    const SmFace &  GetFont(USHORT nIdent) const { return vFont[nIdent]; }
    void            SetFont(USHORT nIdent, const SmFace &rFont, BOOL bDefault = FALSE);
    void            SetFontSize(USHORT nIdent, const Size &rSize)   { vFont[nIdent].SetSize( rSize ); }

    void            SetDefaultFont(USHORT nIdent, BOOL bVal)    { bDefaultFont[nIdent] = bVal; }
    BOOL            IsDefaultFont(USHORT nIdent) const   { return bDefaultFont[nIdent]; }

    USHORT          GetRelSize(USHORT nIdent) const         { return vSize[nIdent]; }
    void            SetRelSize(USHORT nIdent, USHORT nVal)  { vSize[nIdent] = nVal;}

    USHORT          GetDistance(USHORT nIdent) const            { return vDist[nIdent]; }
    void            SetDistance(USHORT nIdent, USHORT nVal) { vDist[nIdent] = nVal; }

    SmHorAlign      GetHorAlign() const             { return eHorAlign; }
    void            SetHorAlign(SmHorAlign eAlign)  { eHorAlign = eAlign; }

    BOOL            IsTextmode() const     { return bIsTextmode; }
    void            SetTextmode(BOOL bVal) { bIsTextmode = bVal; }

    BOOL            IsScaleNormalBrackets() const     { return bScaleNormalBrackets; }
    void            SetScaleNormalBrackets(BOOL bVal) { bScaleNormalBrackets = bVal; }

    long            GetVersion() const { return nVersion; }

    //! at time (5.1) use only the lower byte!!!
    void            SetVersion(long nVer) { nVersion = nVer; }

    SmFormat &      operator = (const SmFormat &rFormat);

    BOOL            operator == (const SmFormat &rFormat) const;
    inline BOOL     operator != (const SmFormat &rFormat) const;

    void RequestApplyChanges() const
    {
        ((SmFormat *) this)->Broadcast(SfxSimpleHint(HINT_FORMATCHANGED));
    }

};

inline BOOL    SmFormat::operator != (const SmFormat &rFormat) const
{
    return !(*this == rFormat);
}

#endif

<|endoftext|>


<commit_before>#ifndef _SNARKFRONT_SHA_1_HPP_
#define _SNARKFRONT_SHA_1_HPP_

#include <array>
#include <cstdint>
#include "Alg.hpp"
#include "Alg_uint.hpp"
#include "AST.hpp"
#include "BitwiseAST.hpp"
#include "BitwiseINT.hpp"
#include "Lazy.hpp"
#include "SecureHashStd.hpp"

namespace snarkfront {

////////////////////////////////////////////////////////////////////////////////
// SHA-1
//

template <typename T, typename MSG, typename U, typename F>
class SHA_1 : public SHA_Base<SHA_1<T, MSG, U, F>,
                              SHA_BlockSize::BLOCK_512,
                              MSG>
{
public:
    typedef T WordType;
    typedef U ByteType;

    typedef std::array<T, 16> MsgType;
    typedef std::array<T, 5> DigType;
    typedef std::array<U, 16 * 4> PreType;

    SHA_1() {
        initConstants();
    }

    const std::array<T, 5>& digest() const {
        return m_H;
    }

    void initHashValue() {
        // set initial hash value (NIST FIPS 180-4 section 5.3.1)
        const std::array<std::uint32_t, 5> a {
            0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };

        for (std::size_t i = 0; i < 5; ++i) {
            m_H[i] = F::constant(a[i]);
        }
    }

    void prepMsgSchedule(std::size_t& msgIndex) {
        // prepare message schedule (NIST FIPS 180-4 section 6.1.2)
        for (std::size_t i = 0; i < 16; ++i) {
            m_W[i] = this->msgWord(msgIndex);
        }

        for (std::size_t i = 16; i < 80; ++i) {
            //m_W[i] = F::ROTL(m_W[i-3] ^ m_W[i-8] ^ m_W[i-14] ^ m_W[i-16], 1);
            m_W[i] = F::ROTL(F::XOR(
                                 F::XOR(
                                     F::XOR(m_W[i-3],
                                            m_W[i-8]),
                                     m_W[i-14]),
                                 m_W[i-16]),
                             1);
        }
    }

    void initWorkingVars() {
        // initialize five working variables (NIST FIPS 180-4 section 6.1.2)
        m_a = m_H[0];
        m_b = m_H[1];
        m_c = m_H[2];
        m_d = m_H[3];
        m_e = m_H[4];
    }

    void workingLoop() {
        // inner loop (NIST FIPS 180-4 section 6.1.2)
        for (std::size_t i = 0; i < 80; ++i) {
            //m_T = F::ROTL(m_a, 5) + F::f(m_b, m_c, m_d, i) + m_e + m_K[i] + m_W[i];
            m_T = F::ADDMOD(F::ADDMOD(
                                F::ADDMOD(
                                    F::ADDMOD(
                                        F::ROTL(m_a, 5),
                                        F::f(m_b, m_c, m_d, i)),
                                    m_e),
                                m_K[i]),
                            m_W[i]);
            m_e = m_d;
            m_d = m_c;
            m_c = F::ROTL(m_b, 30);
            m_b = m_a;
            m_a = m_T;
        }
    }

    void updateHash() {
        // compute intermediate hash value (NIST FIPS 180-4 section 6.1.2)
        //m_H[0] = m_H[0] + m_a;
        //m_H[1] = m_H[1] + m_b;
        //m_H[2] = m_H[2] + m_c;
        //m_H[3] = m_H[3] + m_d;
        //m_H[4] = m_H[4] + m_e;
        m_H[0] = F::ADDMOD(m_H[0], m_a);
        m_H[1] = F::ADDMOD(m_H[1], m_b);
        m_H[2] = F::ADDMOD(m_H[2], m_c);
        m_H[3] = F::ADDMOD(m_H[3], m_d);
        m_H[4] = F::ADDMOD(m_H[4], m_e);
    }

    void afterHash() {
    }

private:
    void initConstants() {
        // set constants (NIST FIPS 180-4 section 4.2.1)
        for (std::size_t i = 0; i < 80; ++i) {
            if (i < 20)
                m_K[i] = F::constant(0x5a827999);
            else if (i < 40)
                m_K[i] = F::constant(0x6ed9eba1);
            else if (i < 60)
                m_K[i] = F::constant(0x8f1bbcdc);
            else
                m_K[i] = F::constant(0xca62c1d6);
        }
    }

    // five 32-bit working variables
    T m_a, m_b, m_c, m_d, m_e;

    // 80 constant 32-bit words
    std::array<T, 80> m_K;

    // message schedule of 80 32-bit words
    std::array<T, 80> m_W;

    // 160-bit hash value
    std::array<T, 5> m_H;

    // temporary word
    T m_T;
};

////////////////////////////////////////////////////////////////////////////////
// typedefs
//

namespace zk {
    template <typename FR> using
    SHA1 = SHA_1<AST_Var<Alg_uint32<FR>>,
                 Lazy<AST_Var<Alg_uint32<FR>>, std::uint32_t>,
                 AST_Var<Alg_uint8<FR>>,
                 SHA_Functions<AST_Node<Alg_uint32<FR>>,
                               AST_Op<Alg_uint32<FR>>,
                               BitwiseAST<Alg_uint32<FR>>>>;
} // namespace zk

namespace eval {
    typedef SHA_1<std::uint32_t,
                  std::uint32_t,
                  std::uint8_t,
                  SHA_Functions<std::uint32_t,
                                std::uint32_t,
                                BitwiseINT<std::uint32_t>>>
        SHA1;
} // namespace eval

} // namespace snarkfront

#endif
<commit_msg>scope header file paths<commit_after>#ifndef _SNARKFRONT_SHA_1_HPP_
#define _SNARKFRONT_SHA_1_HPP_

#include <array>
#include <cstdint>

#include <snarkfront/Alg.hpp>
#include <snarkfront/Alg_uint.hpp>
#include <snarkfront/AST.hpp>
#include <snarkfront/BitwiseAST.hpp>
#include <snarkfront/BitwiseINT.hpp>
#include <snarkfront/Lazy.hpp>
#include <snarkfront/SecureHashStd.hpp>

namespace snarkfront {

////////////////////////////////////////////////////////////////////////////////
// SHA-1
//

template <typename T, typename MSG, typename U, typename F>
class SHA_1 : public SHA_Base<SHA_1<T, MSG, U, F>,
                              SHA_BlockSize::BLOCK_512,
                              MSG>
{
public:
    typedef T WordType;
    typedef U ByteType;

    typedef std::array<T, 16> MsgType;
    typedef std::array<T, 5> DigType;
    typedef std::array<U, 16 * 4> PreType;

    SHA_1() {
        initConstants();
    }

    const std::array<T, 5>& digest() const {
        return m_H;
    }

    void initHashValue() {
        // set initial hash value (NIST FIPS 180-4 section 5.3.1)
        const std::array<std::uint32_t, 5> a {
            0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };

        for (std::size_t i = 0; i < 5; ++i) {
            m_H[i] = F::constant(a[i]);
        }
    }

    void prepMsgSchedule(std::size_t& msgIndex) {
        // prepare message schedule (NIST FIPS 180-4 section 6.1.2)
        for (std::size_t i = 0; i < 16; ++i) {
            m_W[i] = this->msgWord(msgIndex);
        }

        for (std::size_t i = 16; i < 80; ++i) {
            //m_W[i] = F::ROTL(m_W[i-3] ^ m_W[i-8] ^ m_W[i-14] ^ m_W[i-16], 1);
            m_W[i] = F::ROTL(F::XOR(
                                 F::XOR(
                                     F::XOR(m_W[i-3],
                                            m_W[i-8]),
                                     m_W[i-14]),
                                 m_W[i-16]),
                             1);
        }
    }

    void initWorkingVars() {
        // initialize five working variables (NIST FIPS 180-4 section 6.1.2)
        m_a = m_H[0];
        m_b = m_H[1];
        m_c = m_H[2];
        m_d = m_H[3];
        m_e = m_H[4];
    }

    void workingLoop() {
        // inner loop (NIST FIPS 180-4 section 6.1.2)
        for (std::size_t i = 0; i < 80; ++i) {
            //m_T = F::ROTL(m_a, 5) + F::f(m_b, m_c, m_d, i) + m_e + m_K[i] + m_W[i];
            m_T = F::ADDMOD(F::ADDMOD(
                                F::ADDMOD(
                                    F::ADDMOD(
                                        F::ROTL(m_a, 5),
                                        F::f(m_b, m_c, m_d, i)),
                                    m_e),
                                m_K[i]),
                            m_W[i]);
            m_e = m_d;
            m_d = m_c;
            m_c = F::ROTL(m_b, 30);
            m_b = m_a;
            m_a = m_T;
        }
    }

    void updateHash() {
        // compute intermediate hash value (NIST FIPS 180-4 section 6.1.2)
        //m_H[0] = m_H[0] + m_a;
        //m_H[1] = m_H[1] + m_b;
        //m_H[2] = m_H[2] + m_c;
        //m_H[3] = m_H[3] + m_d;
        //m_H[4] = m_H[4] + m_e;
        m_H[0] = F::ADDMOD(m_H[0], m_a);
        m_H[1] = F::ADDMOD(m_H[1], m_b);
        m_H[2] = F::ADDMOD(m_H[2], m_c);
        m_H[3] = F::ADDMOD(m_H[3], m_d);
        m_H[4] = F::ADDMOD(m_H[4], m_e);
    }

    void afterHash() {
    }

private:
    void initConstants() {
        // set constants (NIST FIPS 180-4 section 4.2.1)
        for (std::size_t i = 0; i < 80; ++i) {
            if (i < 20)
                m_K[i] = F::constant(0x5a827999);
            else if (i < 40)
                m_K[i] = F::constant(0x6ed9eba1);
            else if (i < 60)
                m_K[i] = F::constant(0x8f1bbcdc);
            else
                m_K[i] = F::constant(0xca62c1d6);
        }
    }

    // five 32-bit working variables
    T m_a, m_b, m_c, m_d, m_e;

    // 80 constant 32-bit words
    std::array<T, 80> m_K;

    // message schedule of 80 32-bit words
    std::array<T, 80> m_W;

    // 160-bit hash value
    std::array<T, 5> m_H;

    // temporary word
    T m_T;
};

////////////////////////////////////////////////////////////////////////////////
// typedefs
//

namespace zk {
    template <typename FR> using
    SHA1 = SHA_1<AST_Var<Alg_uint32<FR>>,
                 Lazy<AST_Var<Alg_uint32<FR>>, std::uint32_t>,
                 AST_Var<Alg_uint8<FR>>,
                 SHA_Functions<AST_Node<Alg_uint32<FR>>,
                               AST_Op<Alg_uint32<FR>>,
                               BitwiseAST<Alg_uint32<FR>>>>;
} // namespace zk

namespace eval {
    typedef SHA_1<std::uint32_t,
                  std::uint32_t,
                  std::uint8_t,
                  SHA_Functions<std::uint32_t,
                                std::uint32_t,
                                BitwiseINT<std::uint32_t>>>
        SHA1;
} // namespace eval

} // namespace snarkfront

#endif
<|endoftext|>


<commit_before>// This file is part of SKLib: https://github.com/Secoh/SKLib
// Copyright [2019-2021] Secoh
//
// Licensed under the GNU Lesser General Public License, Version 2.1 or later. See: https://www.gnu.org/licenses/
// You may not use this file except in compliance with the License.
// Software is distributed on "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// Special exception from GNU LGPL terms: you don't have to publish the compiled object binary file(s) for SKLib.
// Modified source code and/or any derivative work requirements are still in effect. All such file(s) must be openly
// published under the same terms as the original one(s), but you don't have to inherit the special exception above.
//

#ifndef SKLIB_INCLUDED_ALL
#define SKLIB_INCLUDED_ALL

// Lets preload first all the standard C++ headers ever used in SKLib

#ifndef SKLIB_PRELOADED_COMMON_HEADERS
#define SKLIB_PRELOADED_COMMON_HEADERS

#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <memory>
#include <utility>
#include <type_traits>
#include <mutex>
#include <thread>
#include <chrono>
#include <ratio>

#endif

// To keep all header-only SkLib code in one place
// (e.g. to accelerate loading precompiled headers in MSVC)
// just list all available SkLib modules in one file

#include "./helpers.hpp"
#include "./bitwise.hpp"
#include "./timer.hpp"

#include "./comms.hpp"

#endif // SKLIB_INCLUDED_ALL
<commit_msg>Added checksum to umbrella header<commit_after>// This file is part of SKLib: https://github.com/Secoh/SKLib
// Copyright [2019-2021] Secoh
//
// Licensed under the GNU Lesser General Public License, Version 2.1 or later. See: https://www.gnu.org/licenses/
// You may not use this file except in compliance with the License.
// Software is distributed on "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// Special exception from GNU LGPL terms: you don't have to publish the compiled object binary file(s) for SKLib.
// Modified source code and/or any derivative work requirements are still in effect. All such file(s) must be openly
// published under the same terms as the original one(s), but you don't have to inherit the special exception above.
//

#ifndef SKLIB_INCLUDED_ALL
#define SKLIB_INCLUDED_ALL

// Lets preload first all the standard C++ headers ever used in SKLib

#ifndef SKLIB_PRELOADED_COMMON_HEADERS
#define SKLIB_PRELOADED_COMMON_HEADERS

#include <cstdio>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <memory>
#include <utility>
#include <type_traits>
#include <mutex>
#include <thread>
#include <chrono>
#include <ratio>

#endif

// To keep all header-only SkLib code in one place
// (e.g. to accelerate loading precompiled headers in MSVC)
// just list all available SkLib modules in one file

#include "./helpers.hpp"
#include "./bitwise.hpp"
#include "./timer.hpp"

#include "./comms.hpp"

#include "./checksum.hpp"

#endif // SKLIB_INCLUDED_ALL
<|endoftext|>


<commit_before>//MIT License
//Copyright 2017 Patrick Laughrea
#include "theadFun.hpp"

#include "utils.hpp"
#include "webss.hpp"
#include "list.hpp"

using namespace std;
using namespace webss;

TheadFun::TheadFun() : ptr(shared_ptr<const Tuple*>(new const Tuple*)) {}
TheadFun::TheadFun(const TheadFun& o, int foreachIndex) : thead(o.thead), structure(o.structure),
		ptr(o.ptr), isForeachList(true), foreachIndex(foreachIndex) {}

bool TheadFun::operator==(const TheadFun& o) const
{
	if (thead != o.thead)
		return false;
	return true;
	//something makes it so the two structures faile to be properly compared together
	//causes read access violation using Visual Studio
	//return equalPtrs(structure, o.structure);
}
bool TheadFun::operator!=(const TheadFun& o) const { return !(*this == o); }

const TheadStd& TheadFun::getThead() const { assert(thead != nullptr); return *thead; }
void TheadFun::setThead(TheadStd thead) { this->thead = shared_ptr<TheadStd>(new TheadStd(move(thead))); }

const Webss& TheadFun::getStructure() const
{
	assert(structure != nullptr);
	if (!isForeachList)
		return *structure;
	return structure->getList()[foreachIndex];
}

void TheadFun::setStructure(Webss webss) { structure = shared_ptr<Webss>(new Webss(move(webss))); }

const Tuple** TheadFun::getPointerRaw() const { return ptr.get(); }

void TheadFun::setPointer(const Tuple* tuplePtr) const { *ptr = tuplePtr; }
<commit_msg>Bugfix template function equality<commit_after>//MIT License
//Copyright 2017 Patrick Laughrea
#include "theadFun.hpp"

#include "list.hpp"
#include "tuple.hpp"
#include "utils.hpp"
#include "webss.hpp"

using namespace std;
using namespace webss;

TheadFun::TheadFun() : ptr(shared_ptr<const Tuple*>(new const Tuple*)) {}
TheadFun::TheadFun(const TheadFun& o, int foreachIndex) : thead(o.thead), structure(o.structure),
		ptr(o.ptr), isForeachList(true), foreachIndex(foreachIndex) {}

bool TheadFun::operator==(const TheadFun& o) const
{
	if (!equalPtrs(thead, o.thead))
		return false;
	if (isForeachList)
	{
		if (!o.isForeachList || foreachIndex != o.foreachIndex)
			return false;
	}
	else if (o.isForeachList)
		return false;
	if (thead == nullptr) //TODO: it should be checked if this is necessary
		return true; //don't check structure since head isn't set up yet

	//make a dummy tuple that both thead functions will make placeholders point to
	Tuple dummy;
	for (decltype(thead->getParams().getData().size()) i = 0; i < thead->getParams().getData().size(); ++i)
		dummy.add(Webss());
	setPointer(&dummy);
	o.setPointer(&dummy);
	return equalPtrs(structure, o.structure);
}
bool TheadFun::operator!=(const TheadFun& o) const { return !(*this == o); }

const TheadStd& TheadFun::getThead() const { assert(thead != nullptr); return *thead; }
void TheadFun::setThead(TheadStd thead) { this->thead = shared_ptr<TheadStd>(new TheadStd(move(thead))); }

const Webss& TheadFun::getStructure() const
{
	assert(structure != nullptr);
	if (!isForeachList)
		return *structure;
	return structure->getList()[foreachIndex];
}

void TheadFun::setStructure(Webss webss) { structure = shared_ptr<Webss>(new Webss(move(webss))); }

const Tuple** TheadFun::getPointerRaw() const { return ptr.get(); }

void TheadFun::setPointer(const Tuple* tuplePtr) const { *ptr = tuplePtr; }
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: svdpagv.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-26 12:01:15 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SVDPAGV_HXX
#define _SVDPAGV_HXX

#ifndef _COM_SUN_STAR_AWT_XCONTROLCONTAINER_HPP_
#include <com/sun/star/awt/XControlContainer.hpp>
#endif

#ifndef _SFXLSTNER_HXX //autogen
#include <svtools/lstner.hxx>
#endif

#ifndef _SVDHLPLN_HXX
#include <svx/svdhlpln.hxx>
#endif

#ifndef _CPPUHELPER_IMPLBASE4_HXX_
#include <cppuhelper/implbase4.hxx>
#endif

#ifndef _SVDSOB_HXX
#include <svx/svdsob.hxx>
#endif

#ifndef _SVDTYPES_HXX
#include <svx/svdtypes.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

#include <cppuhelper/implbase3.hxx>
#include <vector>

#ifndef _BGFX_POLYGON_B2DPOLYPOLYGON_HXX
#include <basegfx/polygon/b2dpolypolygon.hxx>
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////

class Region;
class SdrObjList;
class SdrObject;
class SdrPage;
class SdrUnoObj;
class SdrPaintWindow;
class SdrView;
class SdrPageObj;
class B2dIAOManager;
class SdrPageView;

// #110094#
namespace sdr
{
    namespace contact
    {
        class ViewObjectContactRedirector;
        class DisplayInfo;
        class ViewObjectContactRedirector;
    } // end of namespace contact
} // end of namespace sdr

// typedefs for a list of SdrPageWindow
class SdrPageWindow;
typedef ::std::vector< SdrPageWindow* > SdrPageWindowVector;

////////////////////////////////////////////////////////////////////////////////////////////////////

class SVX_DLLPUBLIC SdrPageView : public SfxListener
{
    const ::sdr::contact::DisplayInfo*                              mpDisplayInfo;

protected:
    SdrView&                                                        mrView;
    SdrPage*                                                        mpPage;
    Point         aPgOrg;   // Nullpunkt der Page

    Rectangle     aMarkBound; // wird
    Rectangle     aMarkSnap;  // von
    basegfx::B2DPolyPolygon     maDragPoly0; // SdrView
    basegfx::B2DPolyPolygon     maDragPoly;  //
    sal_Bool                                                        mbHasMarked;
    sal_Bool                                                        mbVisible;

    SetOfByte    aLayerVisi;   // Menge der sichtbaren Layer
    SetOfByte    aLayerLock;   // Menge der nicht editierbaren Layer
    SetOfByte    aLayerPrn;    // Menge der druckbaren Layer

    SdrObjList*  pAktList;     // Aktuelle Liste, in der Regel die Page.
    SdrObject*   pAktGroup;    // Aktuelle Gruppe. NULL=Keine.

    SdrHelpLineList aHelpLines; // Hilfslinien und -punkte

    // #103911# Use one reserved slot (bReserveBool2) for the document color
    Color         maDocumentColor;

    // #103834# Use one reserved slot (bReserveBool1) for the background color
    Color         maBackgroundColor;

    SdrPageWindowVector                                         maPageWindows;

    // #i72752# member to remember with which SdrPageWindow the BeginDrawLayer
    // was done
    SdrPageWindow*                                              mpPreparedPageWindow;

    // interface to SdrPageWindow
protected:
    void ClearPageWindows();
    void AppendPageWindow(SdrPageWindow& rNew);
    SdrPageWindow* RemovePageWindow(sal_uInt32 nPos);
    SdrPageWindow* RemovePageWindow(SdrPageWindow& rOld);
public:
    sal_uInt32 PageWindowCount() const { return maPageWindows.size(); }
    SdrPageWindow* FindPageWindow( SdrPaintWindow& rPaintWindow ) const;
    SdrPageWindow* FindPageWindow( const OutputDevice& rOutDev ) const;
    SdrPageWindow* GetPageWindow(sal_uInt32 nIndex) const;

    /** finds the page window whose PaintWindow belongs to the given output device

        In opposite to FindPageWindow, this method also cares possibly patched PaintWindow instances.
        That is, a SdrPageWindow might have an original, and a patched SdrPaintWindow instance - if
        this is the case, then the original SdrPaintWindow is examined before the patched one.
    */
    const SdrPageWindow* FindPatchedPageWindow( const OutputDevice& rOutDev ) const;

    void PaintOutlinerView(OutputDevice* pOut, const Rectangle& rRect) const;
private:
    SVX_DLLPRIVATE SdrPageWindow& CreateNewPageWindowEntry(SdrPaintWindow& rPaintWindow);

protected:
    void ImpInvalidateHelpLineArea(USHORT nNum) const;

protected:
    void SetLayer(const String& rName, SetOfByte& rBS, sal_Bool bJa);
    sal_Bool IsLayer(const String& rName, const SetOfByte& rBS) const;
    void SetAllLayers(SetOfByte& rB, sal_Bool bJa);

    virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType, const SfxHint& rHint, const TypeId& rHintType);

    // Nachsehen, ob AktGroup noch Inserted ist.
    void CheckAktGroup();

    void AdjHdl();

public:
    TYPEINFO();
    SdrPageView(SdrPage* pPage1, SdrView& rNewView);
    ~SdrPageView();

    // Wird von der PaintView gerufen, wenn Modelaenderungen abgeschlossen sind
    void ModelHasChanged();

    void Show();
    void Hide();

    void AddPaintWindowToPageView(SdrPaintWindow& rPaintWindow);
    void RemovePaintWindowFromPageView(SdrPaintWindow& rPaintWindow);

    SdrView& GetView() { return mrView; }
    const SdrView& GetView() const { return mrView; }

    /** looks up the control container belonging to given output device

        @return
            If the given output device belongs to one of the SdrPageViewWinRecs associated with this
            SdrPageView instance, the XControlContainer for this output device is returned, <NULL/>
            otherwise.
    */
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >
        GetControlContainer( const OutputDevice& _rDevice ) const;

    /** sets all elements in the view which support a design and a alive mode into the given mode
    */
    void    SetDesignMode( bool _bDesignMode ) const;

    sal_Bool IsVisible() const { return mbVisible; }

    // Invalidiert den gesamten Bereich der Page
    void InvalidateAllWin();

    // rRect bezieht sich auf die Page
    void InvalidateAllWin(const Rectangle& rRect, sal_Bool bPlus1Pix=FALSE);

    // rReg bezieht sich auf's OutDev, nicht auf die Page
    void CompleteRedraw(
        SdrPaintWindow& rPaintWindow, const Region& rReg, sal_uInt16 nPaintMode,
        ::sdr::contact::ViewObjectContactRedirector* pRedirector = 0L) const;

    // write access to mpPreparedPageWindow
    void setPreparedPageWindow(SdrPageWindow* pKnownTarget);

    void DrawLayer(SdrLayerID nID, OutputDevice* pGivenTarget = 0L, sal_uInt16 nPaintMode = 0, ::sdr::contact::ViewObjectContactRedirector* pRedirector = 0L) const;
    void DrawPageViewGrid(OutputDevice& rOut, const Rectangle& rRect, Color aColor = Color( COL_BLACK ) );

    Rectangle GetPageRect() const;
    SdrPage* GetPage() const { return mpPage; }

    // Betretene Liste rausreichen
    SdrObjList* GetObjList() const { return pAktList; }

    // Betretene Gruppe rausreichen
    SdrObject* GetAktGroup() const { return pAktGroup; }

    // Betretene Gruppe und Liste setzen
    void SetAktGroupAndList(SdrObject* pNewGroup, SdrObjList* pNewList);

    sal_Bool HasMarkedObjPageView() const { return mbHasMarked; }
    void SetHasMarkedObj(sal_Bool bOn) { mbHasMarked = bOn; }

    const Rectangle& MarkBound() const { return aMarkBound; }
    const Rectangle& MarkSnap() const { return aMarkSnap; }
    Rectangle& MarkBound() { return aMarkBound; }
    Rectangle& MarkSnap() { return aMarkSnap; }

    void SetLayerVisible(const String& rName, sal_Bool bShow = sal_True) { SetLayer(rName, aLayerVisi, bShow); if(!bShow) AdjHdl(); InvalidateAllWin(); }
    sal_Bool IsLayerVisible(const String& rName) const { return IsLayer(rName, aLayerVisi); }
    void SetAllLayersVisible(sal_Bool bShow = sal_True) { SetAllLayers(aLayerVisi, bShow); if(!bShow) AdjHdl(); InvalidateAllWin(); }

    void SetLayerLocked(const String& rName, sal_Bool bLock = sal_True) { SetLayer(rName, aLayerLock, bLock); if(bLock) AdjHdl(); }
    sal_Bool IsLayerLocked(const String& rName) const { return IsLayer(rName,aLayerLock); }
    void SetAllLayersLocked(sal_Bool bLock = sal_True) { SetAllLayers(aLayerLock, bLock); if(bLock) AdjHdl(); }

    void SetLayerPrintable(const String& rName, sal_Bool bPrn = sal_True) { SetLayer(rName, aLayerPrn, bPrn); }
    sal_Bool IsLayerPrintable(const String& rName) const { return IsLayer(rName, aLayerPrn); }
    void SetAllLayersPrintable(sal_Bool bPrn = sal_True) { SetAllLayers(aLayerPrn, bPrn); }

    // PV stellt eine RefPage oder eine SubList eines RefObj dar oder Model ist ReadOnly
    sal_Bool IsReadOnly() const;

    // der Origin bezieht sich immer auf die obere linke Ecke der Page
    const Point& GetPageOrigin() const { return aPgOrg; }
    void SetPageOrigin(const Point& rOrg);

    void LogicToPagePos(Point& rPnt) const { rPnt-=aPgOrg; }
    void LogicToPagePos(Rectangle& rRect) const { rRect.Move(-aPgOrg.X(),-aPgOrg.Y()); }
    void PagePosToLogic(Point& rPnt) const { rPnt+=aPgOrg; }
    void PagePosToLogic(Rectangle& rRect) const { rRect.Move(aPgOrg.X(),aPgOrg.Y()); }

    void SetVisibleLayers(const SetOfByte& rSet) { aLayerVisi=rSet; InvalidateAllWin(); }
    const SetOfByte& GetVisibleLayers() const { return aLayerVisi; }
    void SetPrintableLayers(const SetOfByte& rSet) { aLayerPrn=rSet; }
    const SetOfByte& GetPrintableLayers() const { return aLayerPrn;  }
    void SetLockedLayers(const SetOfByte& rSet) { aLayerLock=rSet; }
    const SetOfByte& GetLockedLayers() const { return aLayerLock; }

    const SdrHelpLineList& GetHelpLines() const { return aHelpLines; }
    void SetHelpLines(const SdrHelpLineList& rHLL);
    //void SetHelpLinePos(USHORT nNum, const Point& rNewPos);
    void SetHelpLine(USHORT nNum, const SdrHelpLine& rNewHelpLine);
    void DeleteHelpLine(USHORT nNum);
    void InsertHelpLine(const SdrHelpLine& rHL, USHORT nNum=0xFFFF);
    void MoveHelpLine(USHORT nNum, USHORT nNewNum) { aHelpLines.Move(nNum,nNewNum); }

    // Liefert TRUE, wenn Layer des Obj sichtbar und nicht gesperrt.
    // Beim Gruppenobjekt muss wenigstens ein Member sichtbar sein,
    // gesperrt sein darf keiner.
    sal_Bool IsObjMarkable(SdrObject* pObj) const;

    // Betreten (Editieren) einer Objektgruppe. Anschliessend liegen alle
    // Memberobjekte der Gruppe im direkten Zugriff. Alle anderen Objekte
    // koennen waerendessen nicht bearbeitet werden (bis zum naechsten
    // LeaveGroup()). (wie MsDos chdir bla).
    sal_Bool EnterGroup(SdrObject* pObj);

    // Verlassen einer betretenen Objektgruppe. (wie MsDos chdir ..)
    void LeaveOneGroup();

    // Verlassen aller betretenen Objektgruppen. (wie MsDos chdir \)
    void LeaveAllGroup();

    // Feststellen, wie weit hinabgestiegen wurde (0=Root(Page))
    USHORT GetEnteredLevel() const;

    // Name der aktuellen Objektgruppe
    String GetActualGroupName() const;

    // Die Namen aller z.Zt. betretenen Gruppen
    String GetActualPathName(sal_Unicode cSep = sal_Unicode('|')) const;

    const basegfx::B2DPolyPolygon& getDragPoly0() const { return maDragPoly0; }
    const basegfx::B2DPolyPolygon& getDragPoly() const { return maDragPoly;  }
    void setDragPoly0(const basegfx::B2DPolyPolygon& rNew) { maDragPoly0 = rNew; }
    void setDragPoly(const basegfx::B2DPolyPolygon& rNew) { maDragPoly = rNew;  }

    // #103834# Set background color for svx at SdrPageViews
    void SetApplicationBackgroundColor(Color aBackgroundColor);

    // #109585#
    Color GetApplicationBackgroundColor() const;

    // #103911# Set/Get document color for svx at SdrPageViews
    void SetApplicationDocumentColor(Color aDocumentColor);
    Color GetApplicationDocumentColor() const;

    void SetCurrentPaintingDisplayInfo(const ::sdr::contact::DisplayInfo* pDisplayInfo)
    {
        if(pDisplayInfo != mpDisplayInfo)
        {
            mpDisplayInfo = pDisplayInfo;
        }
    }

    const ::sdr::contact::DisplayInfo* GetCurrentPaintingDisplayInfo() const
    {
        return mpDisplayInfo;
    }
};

////////////////////////////////////////////////////////////////////////////////////////////////////

#endif //_SVDPAGV_HXX
<commit_msg>INTEGRATION: CWS changefileheader (1.3.368); FILE MERGED 2008/04/01 15:49:38 thb 1.3.368.3: #i85898# Stripping all external header guards 2008/04/01 12:46:56 thb 1.3.368.2: #i85898# Stripping all external header guards 2008/03/31 14:18:18 rt 1.3.368.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: svdpagv.hxx,v $
 * $Revision: 1.4 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SVDPAGV_HXX
#define _SVDPAGV_HXX

#include <com/sun/star/awt/XControlContainer.hpp>
#include <svtools/lstner.hxx>
#include <svx/svdhlpln.hxx>
#include <cppuhelper/implbase4.hxx>
#include <svx/svdsob.hxx>
#include <svx/svdtypes.hxx>
#include "svx/svxdllapi.h"

#include <cppuhelper/implbase3.hxx>
#include <vector>
#include <basegfx/polygon/b2dpolypolygon.hxx>

////////////////////////////////////////////////////////////////////////////////////////////////////

class Region;
class SdrObjList;
class SdrObject;
class SdrPage;
class SdrUnoObj;
class SdrPaintWindow;
class SdrView;
class SdrPageObj;
class B2dIAOManager;
class SdrPageView;

// #110094#
namespace sdr
{
    namespace contact
    {
        class ViewObjectContactRedirector;
        class DisplayInfo;
        class ViewObjectContactRedirector;
    } // end of namespace contact
} // end of namespace sdr

// typedefs for a list of SdrPageWindow
class SdrPageWindow;
typedef ::std::vector< SdrPageWindow* > SdrPageWindowVector;

////////////////////////////////////////////////////////////////////////////////////////////////////

class SVX_DLLPUBLIC SdrPageView : public SfxListener
{
    const ::sdr::contact::DisplayInfo*                              mpDisplayInfo;

protected:
    SdrView&                                                        mrView;
    SdrPage*                                                        mpPage;
    Point         aPgOrg;   // Nullpunkt der Page

    Rectangle     aMarkBound; // wird
    Rectangle     aMarkSnap;  // von
    basegfx::B2DPolyPolygon     maDragPoly0; // SdrView
    basegfx::B2DPolyPolygon     maDragPoly;  //
    sal_Bool                                                        mbHasMarked;
    sal_Bool                                                        mbVisible;

    SetOfByte    aLayerVisi;   // Menge der sichtbaren Layer
    SetOfByte    aLayerLock;   // Menge der nicht editierbaren Layer
    SetOfByte    aLayerPrn;    // Menge der druckbaren Layer

    SdrObjList*  pAktList;     // Aktuelle Liste, in der Regel die Page.
    SdrObject*   pAktGroup;    // Aktuelle Gruppe. NULL=Keine.

    SdrHelpLineList aHelpLines; // Hilfslinien und -punkte

    // #103911# Use one reserved slot (bReserveBool2) for the document color
    Color         maDocumentColor;

    // #103834# Use one reserved slot (bReserveBool1) for the background color
    Color         maBackgroundColor;

    SdrPageWindowVector                                         maPageWindows;

    // #i72752# member to remember with which SdrPageWindow the BeginDrawLayer
    // was done
    SdrPageWindow*                                              mpPreparedPageWindow;

    // interface to SdrPageWindow
protected:
    void ClearPageWindows();
    void AppendPageWindow(SdrPageWindow& rNew);
    SdrPageWindow* RemovePageWindow(sal_uInt32 nPos);
    SdrPageWindow* RemovePageWindow(SdrPageWindow& rOld);
public:
    sal_uInt32 PageWindowCount() const { return maPageWindows.size(); }
    SdrPageWindow* FindPageWindow( SdrPaintWindow& rPaintWindow ) const;
    SdrPageWindow* FindPageWindow( const OutputDevice& rOutDev ) const;
    SdrPageWindow* GetPageWindow(sal_uInt32 nIndex) const;

    /** finds the page window whose PaintWindow belongs to the given output device

        In opposite to FindPageWindow, this method also cares possibly patched PaintWindow instances.
        That is, a SdrPageWindow might have an original, and a patched SdrPaintWindow instance - if
        this is the case, then the original SdrPaintWindow is examined before the patched one.
    */
    const SdrPageWindow* FindPatchedPageWindow( const OutputDevice& rOutDev ) const;

    void PaintOutlinerView(OutputDevice* pOut, const Rectangle& rRect) const;
private:
    SVX_DLLPRIVATE SdrPageWindow& CreateNewPageWindowEntry(SdrPaintWindow& rPaintWindow);

protected:
    void ImpInvalidateHelpLineArea(USHORT nNum) const;

protected:
    void SetLayer(const String& rName, SetOfByte& rBS, sal_Bool bJa);
    sal_Bool IsLayer(const String& rName, const SetOfByte& rBS) const;
    void SetAllLayers(SetOfByte& rB, sal_Bool bJa);

    virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType, const SfxHint& rHint, const TypeId& rHintType);

    // Nachsehen, ob AktGroup noch Inserted ist.
    void CheckAktGroup();

    void AdjHdl();

public:
    TYPEINFO();
    SdrPageView(SdrPage* pPage1, SdrView& rNewView);
    ~SdrPageView();

    // Wird von der PaintView gerufen, wenn Modelaenderungen abgeschlossen sind
    void ModelHasChanged();

    void Show();
    void Hide();

    void AddPaintWindowToPageView(SdrPaintWindow& rPaintWindow);
    void RemovePaintWindowFromPageView(SdrPaintWindow& rPaintWindow);

    SdrView& GetView() { return mrView; }
    const SdrView& GetView() const { return mrView; }

    /** looks up the control container belonging to given output device

        @return
            If the given output device belongs to one of the SdrPageViewWinRecs associated with this
            SdrPageView instance, the XControlContainer for this output device is returned, <NULL/>
            otherwise.
    */
    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlContainer >
        GetControlContainer( const OutputDevice& _rDevice ) const;

    /** sets all elements in the view which support a design and a alive mode into the given mode
    */
    void    SetDesignMode( bool _bDesignMode ) const;

    sal_Bool IsVisible() const { return mbVisible; }

    // Invalidiert den gesamten Bereich der Page
    void InvalidateAllWin();

    // rRect bezieht sich auf die Page
    void InvalidateAllWin(const Rectangle& rRect, sal_Bool bPlus1Pix=FALSE);

    // rReg bezieht sich auf's OutDev, nicht auf die Page
    void CompleteRedraw(
        SdrPaintWindow& rPaintWindow, const Region& rReg, sal_uInt16 nPaintMode,
        ::sdr::contact::ViewObjectContactRedirector* pRedirector = 0L) const;

    // write access to mpPreparedPageWindow
    void setPreparedPageWindow(SdrPageWindow* pKnownTarget);

    void DrawLayer(SdrLayerID nID, OutputDevice* pGivenTarget = 0L, sal_uInt16 nPaintMode = 0, ::sdr::contact::ViewObjectContactRedirector* pRedirector = 0L) const;
    void DrawPageViewGrid(OutputDevice& rOut, const Rectangle& rRect, Color aColor = Color( COL_BLACK ) );

    Rectangle GetPageRect() const;
    SdrPage* GetPage() const { return mpPage; }

    // Betretene Liste rausreichen
    SdrObjList* GetObjList() const { return pAktList; }

    // Betretene Gruppe rausreichen
    SdrObject* GetAktGroup() const { return pAktGroup; }

    // Betretene Gruppe und Liste setzen
    void SetAktGroupAndList(SdrObject* pNewGroup, SdrObjList* pNewList);

    sal_Bool HasMarkedObjPageView() const { return mbHasMarked; }
    void SetHasMarkedObj(sal_Bool bOn) { mbHasMarked = bOn; }

    const Rectangle& MarkBound() const { return aMarkBound; }
    const Rectangle& MarkSnap() const { return aMarkSnap; }
    Rectangle& MarkBound() { return aMarkBound; }
    Rectangle& MarkSnap() { return aMarkSnap; }

    void SetLayerVisible(const String& rName, sal_Bool bShow = sal_True) { SetLayer(rName, aLayerVisi, bShow); if(!bShow) AdjHdl(); InvalidateAllWin(); }
    sal_Bool IsLayerVisible(const String& rName) const { return IsLayer(rName, aLayerVisi); }
    void SetAllLayersVisible(sal_Bool bShow = sal_True) { SetAllLayers(aLayerVisi, bShow); if(!bShow) AdjHdl(); InvalidateAllWin(); }

    void SetLayerLocked(const String& rName, sal_Bool bLock = sal_True) { SetLayer(rName, aLayerLock, bLock); if(bLock) AdjHdl(); }
    sal_Bool IsLayerLocked(const String& rName) const { return IsLayer(rName,aLayerLock); }
    void SetAllLayersLocked(sal_Bool bLock = sal_True) { SetAllLayers(aLayerLock, bLock); if(bLock) AdjHdl(); }

    void SetLayerPrintable(const String& rName, sal_Bool bPrn = sal_True) { SetLayer(rName, aLayerPrn, bPrn); }
    sal_Bool IsLayerPrintable(const String& rName) const { return IsLayer(rName, aLayerPrn); }
    void SetAllLayersPrintable(sal_Bool bPrn = sal_True) { SetAllLayers(aLayerPrn, bPrn); }

    // PV stellt eine RefPage oder eine SubList eines RefObj dar oder Model ist ReadOnly
    sal_Bool IsReadOnly() const;

    // der Origin bezieht sich immer auf die obere linke Ecke der Page
    const Point& GetPageOrigin() const { return aPgOrg; }
    void SetPageOrigin(const Point& rOrg);

    void LogicToPagePos(Point& rPnt) const { rPnt-=aPgOrg; }
    void LogicToPagePos(Rectangle& rRect) const { rRect.Move(-aPgOrg.X(),-aPgOrg.Y()); }
    void PagePosToLogic(Point& rPnt) const { rPnt+=aPgOrg; }
    void PagePosToLogic(Rectangle& rRect) const { rRect.Move(aPgOrg.X(),aPgOrg.Y()); }

    void SetVisibleLayers(const SetOfByte& rSet) { aLayerVisi=rSet; InvalidateAllWin(); }
    const SetOfByte& GetVisibleLayers() const { return aLayerVisi; }
    void SetPrintableLayers(const SetOfByte& rSet) { aLayerPrn=rSet; }
    const SetOfByte& GetPrintableLayers() const { return aLayerPrn;  }
    void SetLockedLayers(const SetOfByte& rSet) { aLayerLock=rSet; }
    const SetOfByte& GetLockedLayers() const { return aLayerLock; }

    const SdrHelpLineList& GetHelpLines() const { return aHelpLines; }
    void SetHelpLines(const SdrHelpLineList& rHLL);
    //void SetHelpLinePos(USHORT nNum, const Point& rNewPos);
    void SetHelpLine(USHORT nNum, const SdrHelpLine& rNewHelpLine);
    void DeleteHelpLine(USHORT nNum);
    void InsertHelpLine(const SdrHelpLine& rHL, USHORT nNum=0xFFFF);
    void MoveHelpLine(USHORT nNum, USHORT nNewNum) { aHelpLines.Move(nNum,nNewNum); }

    // Liefert TRUE, wenn Layer des Obj sichtbar und nicht gesperrt.
    // Beim Gruppenobjekt muss wenigstens ein Member sichtbar sein,
    // gesperrt sein darf keiner.
    sal_Bool IsObjMarkable(SdrObject* pObj) const;

    // Betreten (Editieren) einer Objektgruppe. Anschliessend liegen alle
    // Memberobjekte der Gruppe im direkten Zugriff. Alle anderen Objekte
    // koennen waerendessen nicht bearbeitet werden (bis zum naechsten
    // LeaveGroup()). (wie MsDos chdir bla).
    sal_Bool EnterGroup(SdrObject* pObj);

    // Verlassen einer betretenen Objektgruppe. (wie MsDos chdir ..)
    void LeaveOneGroup();

    // Verlassen aller betretenen Objektgruppen. (wie MsDos chdir \)
    void LeaveAllGroup();

    // Feststellen, wie weit hinabgestiegen wurde (0=Root(Page))
    USHORT GetEnteredLevel() const;

    // Name der aktuellen Objektgruppe
    String GetActualGroupName() const;

    // Die Namen aller z.Zt. betretenen Gruppen
    String GetActualPathName(sal_Unicode cSep = sal_Unicode('|')) const;

    const basegfx::B2DPolyPolygon& getDragPoly0() const { return maDragPoly0; }
    const basegfx::B2DPolyPolygon& getDragPoly() const { return maDragPoly;  }
    void setDragPoly0(const basegfx::B2DPolyPolygon& rNew) { maDragPoly0 = rNew; }
    void setDragPoly(const basegfx::B2DPolyPolygon& rNew) { maDragPoly = rNew;  }

    // #103834# Set background color for svx at SdrPageViews
    void SetApplicationBackgroundColor(Color aBackgroundColor);

    // #109585#
    Color GetApplicationBackgroundColor() const;

    // #103911# Set/Get document color for svx at SdrPageViews
    void SetApplicationDocumentColor(Color aDocumentColor);
    Color GetApplicationDocumentColor() const;

    void SetCurrentPaintingDisplayInfo(const ::sdr::contact::DisplayInfo* pDisplayInfo)
    {
        if(pDisplayInfo != mpDisplayInfo)
        {
            mpDisplayInfo = pDisplayInfo;
        }
    }

    const ::sdr::contact::DisplayInfo* GetCurrentPaintingDisplayInfo() const
    {
        return mpDisplayInfo;
    }
};

////////////////////////////////////////////////////////////////////////////////////////////////////

#endif //_SVDPAGV_HXX
<|endoftext|>