annotate engine/core/gui/widgets/utf8textbox.cpp @ 228:756b895e1dab

Merged unicode-support back into trunk. Now all GUI/visible strings should be unicode. Internal strings unchanged. Remember to use a font that actually has the desired codepoints. Current default unicode policiy is 'ignore'.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 21 Mar 2009 10:38:11 +0000
parents
children 64738befdf3b
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)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 :TextBox(text)
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 mStringEditor = new UTF8StringEditor();
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 UTF8TextBox::~ UTF8TextBox()
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 delete mStringEditor;
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 void UTF8TextBox::keyPressed(KeyEvent& keyEvent)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 Key key = keyEvent.getKey();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 if (key.getValue() == Key::LEFT)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 if (mCaretColumn == 0)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 if (mCaretRow > 0)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 mCaretRow--;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 mCaretColumn = mTextRows[mCaretRow].size();
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 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 else
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 mCaretColumn = mStringEditor->prevChar(mTextRows[mCaretRow], mCaretColumn);
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 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 else if (key.getValue() == Key::RIGHT)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 if (mCaretColumn < mTextRows[mCaretRow].size())
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 mCaretColumn = mStringEditor->nextChar(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 else
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 if (mCaretRow < mTextRows.size() - 1)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 mCaretRow++;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78 mCaretColumn = 0;
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 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 else if (key.getValue() == Key::DOWN)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 setCaretRowUTF8(mCaretRow + 1);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 else if (key.getValue() == Key::UP)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 setCaretRowUTF8(mCaretRow - 1);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 else if (key.getValue() == Key::HOME)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 mCaretColumn = 0;
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 else if (key.getValue() == Key::END)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 mCaretColumn = mTextRows[mCaretRow].size();
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 else if (key.getValue() == Key::ENTER && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104 mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn));
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 mTextRows[mCaretRow].resize(mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 ++mCaretRow;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 mCaretColumn = 0;
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 else if (key.getValue() == Key::BACKSPACE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 && mCaretColumn != 0
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115 mCaretColumn = mStringEditor->prevChar(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 mCaretColumn = mStringEditor->eraseChar(mTextRows[mCaretRow], mCaretColumn);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 else if (key.getValue() == Key::BACKSPACE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 && mCaretColumn == 0
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 && mCaretRow != 0
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 mCaretColumn = mTextRows[mCaretRow - 1].size();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126 mTextRows.erase(mTextRows.begin() + mCaretRow);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 mCaretRow--;
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 else if (key.getValue() == Key::DELETE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 && mCaretColumn < (int)mTextRows[mCaretRow].size()
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 mCaretColumn = mStringEditor->eraseChar(mTextRows[mCaretRow], mCaretColumn);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 else if (key.getValue() == Key::DELETE
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138 && mCaretColumn == (int)mTextRows[mCaretRow].size()
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139 && mCaretRow < ((int)mTextRows.size() - 1)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 else if(key.getValue() == Key::PAGE_UP)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 Widget* par = getParent();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 if (par != NULL)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 int chars = mStringEditor->countChars(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 mCaretRow -= rowsPerPage;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 if (mCaretRow < 0)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 mCaretRow = 0;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], chars);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 else if(key.getValue() == Key::PAGE_DOWN)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166 Widget* par = getParent();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168 if (par != NULL)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
169 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 int chars = mStringEditor->countChars(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 mCaretRow += rowsPerPage;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 if (mCaretRow >= (int)mTextRows.size())
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 mCaretRow = mTextRows.size() - 1;
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], chars);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 else if(key.getValue() == Key::TAB
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 // 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
187 mTextRows[mCaretRow].insert(mCaretColumn,std::string(" "));
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 mCaretColumn += 4;
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
191 else if ((key.isCharacter() || key.getValue() > 255)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
192 && mEditable)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194 mCaretColumn = mStringEditor->insertChar(mTextRows[mCaretRow], mCaretColumn, key.getValue());
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
197 adjustSize();
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
198 scrollToCaret();
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].end()) );
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200 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
201 keyEvent.consume();
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205 void UTF8TextBox::setCaretColumnUTF8(int column)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 // 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
208 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], column);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 void UTF8TextBox::setCaretRowUTF8(int row)
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
213 int chars = mStringEditor->countChars(mTextRows[mCaretRow], mCaretColumn);
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 if (row < 0) {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215 row = 0;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216 } else if (row >= mTextRows.size()) {
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217 row = mTextRows.size() - 1;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218 }
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 mCaretRow = row;
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220 mCaretColumn = mStringEditor->getOffset(mTextRows[mCaretRow], chars);
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
756b895e1dab Merged unicode-support back into trunk.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225