42MFXDynamicLabel::
MFXDynamicLabel(FXComposite* p, const FXString& text, FXIcon* ic, FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb,
std::
string indent):
43 FXLabel(p, text, ic, opts, x, y, w, h, pl, pr, pt, pb), myOriginalString(text.text()), myIndentString(indent), myPreviousWidth(0) {
101 const int preferredWidth = curWidth - getPadLeft() - getPadRight();
102 const int textWidth = getApp()->getNormalFont()->getTextWidth(label);
103 if (textWidth <= preferredWidth || preferredWidth < 1) {
106 std::string newLine =
"\n" + std::string(
myIndent,
' ');
107 const int newLineOffset = (int)newLine.size();
110 int finalPos = (int)msg.size() - 1;
111 std::string::size_type nextLineBreak;
112 while (pos < finalPos) {
113 nextLineBreak = msg.find(
'\n', pos);
114 int subPos = (nextLineBreak != std::string::npos) ? (
int)nextLineBreak : finalPos;
115 if (getApp()->getNormalFont()->getTextWidth(msg.substr(pos, subPos - pos).c_str()) <= preferredWidth) {
123 const int endPos = (nextLineBreak != std::string::npos) ? (
int)nextLineBreak - 1 : finalPos;
124 std::string::size_type nextSpace = std::string::npos;
125 int lastSpacePos = -1;
127 while (pos2 < endPos) {
128 nextSpace = msg.find(
' ', pos2);
129 if (nextSpace != std::string::npos && (
int)nextSpace <= pos +
myIndent) {
130 nextSpace = std::string::npos;
132 }
else if (nextSpace != std::string::npos && (
int)nextSpace < endPos) {
133 std::string testString = msg.substr(pos, nextSpace - pos);
134 if (getApp()->getNormalFont()->getTextWidth(msg.substr(pos, nextSpace - pos).c_str()) > preferredWidth) {
135 if (lastSpacePos > 0) {
136 msg.replace(lastSpacePos, 1, newLine);
137 pos2 = lastSpacePos + newLineOffset;
138 finalPos += newLineOffset;
140 msg.replace(nextSpace, 1, newLine);
141 pos2 = (int)nextSpace + newLineOffset;
142 finalPos += newLineOffset;
146 pos2 = (int)nextSpace + 1;
147 if (msg.find(
' ', pos2) == std::string::npos && lastSpacePos > 0) {
148 msg.replace(lastSpacePos, 1, newLine);
149 pos2 += newLineOffset;
153 lastSpacePos = (int)nextSpace;