diff options
author | jcid <devnull@localhost> | 2008-09-24 18:44:40 +0200 |
---|---|---|
committer | jcid <devnull@localhost> | 2008-09-24 18:44:40 +0200 |
commit | c377e06400f138325a9a9d43d91a9272691867a1 (patch) | |
tree | 49f3ca1c46af11a058a68714899d4137ec717618 /dw/alignedtextblock.cc | |
parent | 642f9b3e747859a7256ea12fab9f9ed50aa9253a (diff) |
- Moved the dw2 tree into dillo2's tree.
Diffstat (limited to 'dw/alignedtextblock.cc')
-rw-r--r-- | dw/alignedtextblock.cc | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/dw/alignedtextblock.cc b/dw/alignedtextblock.cc new file mode 100644 index 00000000..bb24a3bc --- /dev/null +++ b/dw/alignedtextblock.cc @@ -0,0 +1,105 @@ +/* + * Dillo Widget + * + * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + + +#include "alignedtextblock.hh" +#include <stdio.h> + +namespace dw { + +AlignedTextblock::List::List () +{ + textblocks = new misc::SimpleVector <AlignedTextblock*> (4); + values = new misc::SimpleVector <int> (4); + maxValue = 0; + refCount = 0; +} + +AlignedTextblock::List::~List () +{ + delete textblocks; + delete values; +} + +int AlignedTextblock::List::add(AlignedTextblock *textblock) +{ + textblocks->increase (); + values->increase (); + textblocks->set (textblocks->size () - 1, textblock); + refCount++; + return textblocks->size () - 1; +} + +void AlignedTextblock::List::unref(int pos) +{ + assert (textblocks->get (pos) != NULL); + textblocks->set (pos, NULL); + refCount--; + + if(refCount == 0) + delete this; +} + +int AlignedTextblock::CLASS_ID = -1; + +AlignedTextblock::AlignedTextblock (bool limitTextWidth): + Textblock (limitTextWidth) +{ + registerName ("dw::AlignedTextblock", &CLASS_ID); +} + +void AlignedTextblock::setRefTextblock (AlignedTextblock *ref) +{ + if(ref == NULL) + list = new List(); + else + list = ref->list; + + listPos = list->add (this); + updateValue (); +} + +AlignedTextblock::~AlignedTextblock() +{ + list->unref (listPos); +} + +void AlignedTextblock::updateValue () +{ + if (list) { + list->setValue (listPos, getValue ()); + + if (list->getValue (listPos) > list->getMaxValue ()) { + // New value greater than current maximum -> apply it to others. + list->setMaxValue (list->getValue (listPos)); + + for (int i = 0; i < list->size (); i++) + if (list->getTextblock (i)) + list->getTextblock (i)->setMaxValue (list->getMaxValue (), + list->getValue (i)); + } else { + /* No change, apply old max_value only to this page. */ + setMaxValue (list->getMaxValue (), list->getValue (listPos)); + } + } +} + +} // namespace dw |