annotate engine/core/gui/widgets/utf8textbox.cpp @ 696:e201abd8c807

Merged in the VFS fix for absolute paths from FIFE svn trunk. * This fix superseeds my previous patch, so that patch has been removed.
author M. George Hansen <technopolitica@gmail.com>
date Fri, 10 Jun 2011 23:37:46 -1000
parents 64738befdf3b
children
rev   line source
228
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 /***************************************************************************
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 * Copyright (C) 2009 by the FIFE team *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 * http://www.fifengine.de *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 * This file is part of FIFE. *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 * *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 * FIFE is free software; you can redistribute it and/or *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 * License as published by the Free Software Foundation; either *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version. *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 * *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful, *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 * Lesser General Public License for more details. *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 * *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 * License along with this library; if not, write to the *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 * Free Software Foundation, Inc., *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 ***************************************************************************/
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 // Standard C++ library includes
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 #include <cassert>
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 // 3rd party library includes
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 // FIFE includes
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 // These includes are split up in two parts, separated by one empty line
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 // First block: files included from the FIFE root src directory
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 // Second block: files included from the same folder
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 #include "util/utf8/utf8.h"
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 #include "utf8textbox.h"
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 namespace gcn {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 UTF8TextBox::UTF8TextBox(const std::string & text)
378
64738befdf3b bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 228
diff changeset
38 :TextBox(text), mStringEditor(new UTF8StringEditor())
228
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 UTF8TextBox::~ UTF8TextBox()
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 delete mStringEditor;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 void UTF8TextBox::keyPressed(KeyEvent& keyEvent)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 Key key = keyEvent.getKey();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 if (key.getValue() == Key::LEFT)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 if (mCaretColumn == 0)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 if (mCaretRow > 0)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 mCaretRow--;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 mCaretColumn = mTextRows[mCaretRow].size();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 else
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 mCaretColumn = mStringEditor->prevChar(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 else if (key.getValue() == Key::RIGHT)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 if (mCaretColumn < mTextRows[mCaretRow].size())
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 mCaretColumn = mStringEditor->nextChar(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 else
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 if (mCaretRow < mTextRows.size() - 1)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 mCaretRow++;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 mCaretColumn = 0;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 else if (key.getValue() == Key::DOWN)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 setCaretRowUTF8(mCaretRow + 1);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 else if (key.getValue() == Key::UP)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 setCaretRowUTF8(mCaretRow - 1);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 else if (key.getValue() == Key::HOME)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 mCaretColumn = 0;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 else if (key.getValue() == Key::END)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 mCaretColumn = mTextRows[mCaretRow].size();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101 else if (key.getValue() == Key::ENTER && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn));
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 mTextRows[mCaretRow].resize(mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 ++mCaretRow;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 mCaretColumn = 0;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 else if (key.getValue() == Key::BACKSPACE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 && mCaretColumn != 0
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 mCaretColumn = mStringEditor->prevChar(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115 mCaretColumn = mStringEditor->eraseChar(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 else if (key.getValue() == Key::BACKSPACE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 && mCaretColumn == 0
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 && mCaretRow != 0
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 mCaretColumn = mTextRows[mCaretRow - 1].size();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 mTextRows.erase(mTextRows.begin() + mCaretRow);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126 mCaretRow--;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 else if (key.getValue() == Key::DELETE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 && mCaretColumn < (int)mTextRows[mCaretRow].size()
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 mCaretColumn = mStringEditor->eraseChar(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 else if (key.getValue() == Key::DELETE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 && mCaretColumn == (int)mTextRows[mCaretRow].size()
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138 && mCaretRow < ((int)mTextRows.size() - 1)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145 else if(key.getValue() == Key::PAGE_UP)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 Widget* par = getParent();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 if (par != NULL)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 int chars = mStringEditor->countChars(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 mCaretRow -= rowsPerPage;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 if (mCaretRow < 0)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 mCaretRow = 0;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], chars);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163 else if(key.getValue() == Key::PAGE_DOWN)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 Widget* par = getParent();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167 if (par != NULL)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
169 int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 int chars = mStringEditor->countChars(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 mCaretRow += rowsPerPage;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173 if (mCaretRow >= (int)mTextRows.size())
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 mCaretRow = mTextRows.size() - 1;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], chars);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182 else if(key.getValue() == Key::TAB
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185 // FIXME: jump X spaces, so mCaretColumn % TAB_SIZE = 0 and X <= TAB_SIZE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 mTextRows[mCaretRow].insert(mCaretColumn,std::string(" "));
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187 mCaretColumn += 4;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
189
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
190 else if ((key.isCharacter() || key.getValue() > 255)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
191 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
192 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193 mCaretColumn = mStringEditor->insertChar(mTextRows[mCaretRow], mCaretColumn, key.getValue());
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
196 adjustSize();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
197 scrollToCaret();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
198 assert( utf8::is_valid(mTextRows[mCaretRow].begin(),mTextRows[mCaretRow].end()) );
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199 assert( utf8::is_valid(mTextRows[mCaretRow].begin(),mTextRows[mCaretRow].begin() + mCaretColumn) );
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200 keyEvent.consume();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
202
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
203
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
204 void UTF8TextBox::setCaretColumnUTF8(int column)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206 // no need to clip the column, mStringEditor handles it automaticly
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], column);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210 void UTF8TextBox::setCaretRowUTF8(int row)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 int chars = mStringEditor->countChars(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
213 if (row < 0) {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 row = 0;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215 } else if (row >= mTextRows.size()) {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216 row = mTextRows.size() - 1;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218 mCaretRow = row;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], chars);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224