summaryrefslogtreecommitdiff
path: root/src/interface/Textbox.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-10-01 11:28:21 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-10-01 11:28:21 (GMT)
commit39afea3945c8c88d583d3381e48ba529b2d81452 (patch)
tree2591c26c40b4edf31e6c3f6b4ff6bfd1e8119942 /src/interface/Textbox.cpp
parentd78082d368ccb945e90594f2178202f2c499c484 (diff)
downloadpowder-39afea3945c8c88d583d3381e48ba529b2d81452.zip
powder-39afea3945c8c88d583d3381e48ba529b2d81452.tar.gz
Impose limit when pasting into textboxes
Diffstat (limited to 'src/interface/Textbox.cpp')
-rw-r--r--src/interface/Textbox.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp
index afb9fd3..bdad127 100644
--- a/src/interface/Textbox.cpp
+++ b/src/interface/Textbox.cpp
@@ -206,6 +206,29 @@ void Textbox::pasteIntoSelection()
*iter = '0';
}
}
+
+ int regionWidth = Size.X;
+ if(Appearance.icon)
+ regionWidth -= 13;
+ regionWidth -= Appearance.Margin.Left;
+ regionWidth -= Appearance.Margin.Right;
+
+ if(limit!=std::string::npos)
+ {
+ if(limit-backingText.length() > 0)
+ newText.substr(0, limit-backingText.length());
+ }
+ else if(Graphics::textwidth((char*)std::string(backingText+newText).c_str()) > regionWidth)
+ {
+ int pLimit = regionWidth - Graphics::textwidth((char*)backingText.c_str());
+ int cIndex = Graphics::CharIndexAtPosition((char *)newText.c_str(), pLimit, 0);
+
+ if(cIndex > 0)
+ newText = newText.substr(0, cIndex);
+ else
+ newText = "";
+ }
+
backingText.insert(cursor, newText);
cursor = cursor+newText.length();
ClearSelection();