summaryrefslogtreecommitdiff
path: root/plugingui/textedit.cc
diff options
context:
space:
mode:
Diffstat (limited to 'plugingui/textedit.cc')
-rw-r--r--plugingui/textedit.cc100
1 files changed, 69 insertions, 31 deletions
diff --git a/plugingui/textedit.cc b/plugingui/textedit.cc
index 43be7aa..73303f7 100644
--- a/plugingui/textedit.cc
+++ b/plugingui/textedit.cc
@@ -38,12 +38,22 @@
#define BORDER 10
+static void scrolled(void *ptr)
+{
+ GUI::TextEdit *l = (GUI::TextEdit *)ptr;
+ l->repaintEvent(NULL);
+}
+
GUI::TextEdit::TextEdit(Widget *parent)
- : GUI::Widget(parent)
+ : GUI::Widget(parent), scroll(this)
{
pos = 0;
setReadOnly(true);
+ scroll.move(width()-5,1);
+ scroll.resize(20, 100);
+ scroll.registerValueChangeHandler(scrolled, this);
+
box.topLeft = new Image(":widget_tl.png");
box.top = new Image(":widget_t.png");
box.topRight = new Image(":widget_tr.png");
@@ -57,10 +67,11 @@ GUI::TextEdit::TextEdit(Widget *parent)
handler = NULL;
}
-void GUI::TextEdit::registerEnterPressedHandler(void (*handler)(void *), void *ptr)
+void GUI::TextEdit::resize(int height, int width)
{
- this->handler = handler;
- this->ptr = ptr;
+ Widget::resize(height, width);
+ scroll.resize(scroll.width(), height-10);
+ scroll.move(width-30,7);
}
void GUI::TextEdit::setReadOnly(bool ro)
@@ -76,6 +87,12 @@ bool GUI::TextEdit::readOnly()
void GUI::TextEdit::setText(std::string text)
{
_text = text;
+ preprocessText();
+ int ran = height() / font.textHeight();
+ DEBUG(textedit, "Setting range and max of scrollbar"
+ " to '%d' and '%d'\n", ran, preprocessedtext.size());
+ scroll.setRange(ran);
+ scroll.setMaximum(preprocessedtext.size());
repaintEvent(NULL);
textChanged();
}
@@ -85,29 +102,19 @@ std::string GUI::TextEdit::text()
return _text;
}
-void GUI::TextEdit::buttonEvent(ButtonEvent *e)
-{
- if(readOnly()) return;
-}
+//void GUI::TextEdit::buttonEvent(ButtonEvent *e)
+//{
+// if(readOnly()) return;
+//}
-void GUI::TextEdit::keyEvent(GUI::KeyEvent *e)
-{
- if(readOnly()) return;
-}
+//void GUI::TextEdit::keyEvent(GUI::KeyEvent *e)
+//{
+// if(readOnly()) return;
+//}
-void GUI::TextEdit::repaintEvent(GUI::RepaintEvent *e)
+void GUI::TextEdit::preprocessText()
{
- Painter p(this);
-
- p.clear();
-
- int w = width();
- int h = height();
- if(w == 0 || h == 0) return;
- p.drawBox(0, 0, &box, w, h);
-
- p.setColour(GUI::Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1));
-
+ preprocessedtext.clear();
std::string text = _text;
{ // Handle tan characters
@@ -131,27 +138,58 @@ void GUI::TextEdit::repaintEvent(GUI::RepaintEvent *e)
while(pos != std::string::npos);
}
- { // Draw and wrap long lines
- int ypos = font.textHeight() + 5 + 1 + 1 + 1;
+ { // Wrap long lines
std::list<std::string>::iterator it;
for(it = lines.begin(); it != lines.end(); it++) {
std::string line = *it;
for(size_t i = 0; i < line.length(); i++) {
size_t linewidth = font.textWidth(line.substr(0, i));
- if(linewidth >= width() - BORDER - 4 + 3 - 10) {
- p.drawText(BORDER - 4 + 3, ypos, font, line.substr(0, i));
- ypos += font.textHeight();
+ if(linewidth >= width() - BORDER - 4 + 3 - 10 - scroll.width()) {
+ preprocessedtext.push_back(line.substr(0, i));
line = line.substr(i);
i = 0;
}
}
- p.drawText(BORDER - 4 + 3, ypos, font, line);
- ypos += font.textHeight();
+ preprocessedtext.push_back(line);
}
}
}
+void GUI::TextEdit::repaintEvent(GUI::RepaintEvent *e)
+{
+ Painter p(this);
+
+ p.clear();
+
+ int w = width();
+ int h = height();
+ if(w == 0 || h == 0) return;
+ p.drawBox(0, 0, &box, w, h);
+
+ p.setColour(GUI::Colour(183.0/255.0, 219.0/255.0 , 255.0/255.0, 1));
+
+ int skip = scroll.value();
+
+ int ypos = font.textHeight() + 5 + 1 + 1 + 1;
+ std::list<std::string>::iterator it;
+ it = preprocessedtext.begin();
+
+ int c = 0;
+ for( ; c < skip; c++) {
+ it++;
+ }
+
+ c = 0;
+ for( ; it != preprocessedtext.end(); it++) {
+ if(c * font.textHeight() >= height() - 8 - font.textHeight()) break;
+ std::string line = *it;
+ p.drawText(BORDER - 4 + 3, ypos, font, line);
+ ypos += font.textHeight();
+ c++;
+ }
+}
+
#ifdef TEST_TEXTEDIT
//Additional dependency files
//deps: