| 1251 | // ---------------------------------------------------------------------------------------- |
| 1252 | |
| 1253 | void text_field:: |
| 1254 | move_cursor ( |
| 1255 | unsigned long pos |
| 1256 | ) |
| 1257 | { |
| 1258 | using namespace std; |
| 1259 | const long old_cursor_pos = cursor_pos; |
| 1260 | |
| 1261 | if (text_pos >= pos) |
| 1262 | { |
| 1263 | // the cursor should go all the way to the left side of the text |
| 1264 | if (pos >= 6) |
| 1265 | text_pos = pos-6; |
| 1266 | else |
| 1267 | text_pos = 0; |
| 1268 | |
| 1269 | cursor_pos = pos; |
| 1270 | unsigned long height; |
| 1271 | mfont->compute_size(text_,text_width,height,text_pos); |
| 1272 | |
| 1273 | unsigned long width; |
| 1274 | unsigned long new_x = style->get_padding(*mfont); |
| 1275 | if (static_cast<long>(cursor_pos)-1 >= static_cast<long>(text_pos)) |
| 1276 | { |
| 1277 | mfont->compute_size(text_,width,height,text_pos,cursor_pos-1); |
| 1278 | if (cursor_pos != 0) |
| 1279 | new_x += width - mfont->right_overflow(); |
| 1280 | } |
| 1281 | |
| 1282 | cursor_x = new_x; |
| 1283 | } |
| 1284 | else |
| 1285 | { |
| 1286 | unsigned long height; |
| 1287 | unsigned long width; |
| 1288 | mfont->compute_size(text_,width,height,text_pos,pos-1); |
| 1289 | |
| 1290 | unsigned long new_x = style->get_padding(*mfont) + |
| 1291 | width - mfont->right_overflow(); |
| 1292 | |
| 1293 | // move the text to the left if necessary |
| 1294 | if (new_x + 4 > rect.width()) |
| 1295 | { |
| 1296 | while (new_x > rect.width() - rect.width()/5) |
| 1297 | { |
| 1298 | new_x -= (*mfont)[text_[text_pos]].width(); |
| 1299 | ++text_pos; |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | cursor_x = new_x; |
| 1304 | cursor_pos = pos; |
| 1305 | mfont->compute_size(text_,text_width,height,text_pos); |
| 1306 | } |
| 1307 | |
| 1308 | parent.set_im_pos(rect.left()+cursor_x, rect.top()); |
| 1309 | |
| 1310 | if (old_cursor_pos != cursor_pos) |
nothing calls this directly
no test coverage detected