void TextEdit::setFlags(int new_flags, bool revalidate) { if (new_flags == flags) return; flags = new_flags; if (flags && revalidate) { bool valid = true; const char *p = getTextStart(); while (p < bufend - 1) { gunichar uc = g_utf8_get_char(p); if ((flags & FLAG_ALPHABETIC) && !g_unichar_isalpha(uc)) { valid = false; break; } if ((flags & FLAG_NUMERIC) && !g_unichar_isdigit(uc)) { valid = false; break; } if ((flags & FLAG_NOSPACE) && g_unichar_isspace(uc)) { valid = false; break; } if ((flags & FLAG_NOPUNCTUATION) && g_unichar_ispunct(uc)) { valid = false; break; } p = nextChar(p); } if (!valid) clear(); } }
void TextEdit::updateScreenLines() { screen_lines.clear(); int realw; if (!area || (realw = area->getmaxx()) <= 1) return; const char *p = getTextStart(); while (p < bufend) { const char *s = p; size_t length; // lower max width by one to make a room for the cursor p = getScreenLine(p, realw - 1, &length); screen_lines.push_back(ScreenLine(s, p, length)); } }
void Label::drawWidget() { const char* wStr = caption.c_str(); //int textX=paddedBounds.x, textY=paddedBounds.y; int textX=0, textY=0; //calcStrSize(); getTextStart(&textX, &textY); Rect tempRect = Rect(0, 0, paddedBounds.width, paddedBounds.height); if(font) { if(multiLine) font->drawBoundedString(wStr, textX, textY, tempRect); else { if(autoSizeX) font->drawString(wStr, textX, textY); else font->drawString(cuttedCaption.c_str(), textX, textY); } } }
void TextEdit::updateScreenLines(const char *begin, const char *end) { g_assert(begin); g_assert(end); int realw; if (!area || (realw = area->getmaxx()) <= 1) return; ScreenLines::iterator b, i; b = std::lower_bound(screen_lines.begin(), screen_lines.end(), begin, TextEdit::CmpScreenLineEnd()); if (b != screen_lines.begin()) { /* * Initial Correct final * situation situation * --------- --------- * |aaaa | -> |aaaa b | * |bcdddd | |cdddd | * * User inserts a space in front of the 'c' character. The 'b' string can * be moved on the previous line thus one more extra line before has to be * recalculated to handle the situation correctly. */ b--; } i = b; ScreenLines new_screen_lines; const char *p = b->start; if (i == screen_lines.begin()) p = getTextStart(); while (p < bufend) { const char *s = p; size_t length; // lower max width by one to make a room for the cursor p = getScreenLine(p, realw - 1, &length); ScreenLine sline(s, p, length); new_screen_lines.push_back(sline); while (i != screen_lines.end() && (i->end <= end || i->start < s || i->end < p)) i++; if (i != screen_lines.end() && sline == *i) { /* Screen lines are same thus it isn't necessary to recalculate more * screen lines. */ break; } } if (i != screen_lines.end()) i++; /* g_debug("UpdateScreenLines(), new_lines=%d, old_lines=%d", new_screen_lines.size(), i - b); */ // replace old screen lines with new screen lines ScreenLines::iterator j; for (j = new_screen_lines.begin(); j != new_screen_lines.end() && b != i; j++, b++) *b = *j; if (j != new_screen_lines.end()) { // b == i screen_lines.insert(b, j, new_screen_lines.end()); } else { // b != i screen_lines.erase(b, i); } }