summaryrefslogtreecommitdiff
path: root/inputmethods/unikeyboard/unikeyboard.cpp
Unidiff
Diffstat (limited to 'inputmethods/unikeyboard/unikeyboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/unikeyboard/unikeyboard.cpp278
1 files changed, 278 insertions, 0 deletions
diff --git a/inputmethods/unikeyboard/unikeyboard.cpp b/inputmethods/unikeyboard/unikeyboard.cpp
new file mode 100644
index 0000000..aa74c66
--- a/dev/null
+++ b/inputmethods/unikeyboard/unikeyboard.cpp
@@ -0,0 +1,278 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "unikeyboard.h"
22
23#include <qpe/fontmanager.h>
24
25#include <qpainter.h>
26#include <qfontmetrics.h>
27#include <qcombobox.h>
28#if defined(Q_WS_QWS) || defined(_WS_QWS_)
29#include <qwindowsystem_qws.h>
30#endif
31
32static const int nw = 8;
33
34typedef struct BlockMap {
35 ushort start;
36 ushort stop;
37 const char *name;
38};
39
40//# Start Code; Block Name
41
42static const BlockMap blockMap[] =
43{
44{0x0000, 0x007F, "Basic Latin"},
45{0x0080, 0x00FF, "Latin-1 Supplement"},
46{0x0100, 0x017F, "Latin Extended-A"},
47{0x0180, 0x024F, "Latin Extended-B"},
48{0x0250, 0x02AF, "IPA Extensions"},
49{0x02B0, 0x02FF, "Spacing Modifier Letters"},
50{0x0300, 0x036F, "Combining Diacritical Marks"},
51{0x0370, 0x03FF, "Greek"},
52{0x0400, 0x04FF, "Cyrillic"},
53{0x0530, 0x058F, "Armenian"},
54{0x0590, 0x05FF, "Hebrew"},
55{0x0600, 0x06FF, "Arabic"},
56{0x0700, 0x074F, "Syriac "},
57{0x0780, 0x07BF, "Thaana"},
58{0x0900, 0x097F, "Devanagari"},
59{0x0980, 0x09FF, "Bengali"},
60{0x0A00, 0x0A7F, "Gurmukhi"},
61{0x0A80, 0x0AFF, "Gujarati"},
62{0x0B00, 0x0B7F, "Oriya"},
63{0x0B80, 0x0BFF, "Tamil"},
64{0x0C00, 0x0C7F, "Telugu"},
65{0x0C80, 0x0CFF, "Kannada"},
66{0x0D00, 0x0D7F, "Malayalam"},
67{0x0D80, 0x0DFF, "Sinhala"},
68{0x0E00, 0x0E7F, "Thai"},
69{0x0E80, 0x0EFF, "Lao"},
70{0x0F00, 0x0FFF, "Tibetan"},
71{0x1000, 0x109F, "Myanmar "},
72{0x10A0, 0x10FF, "Georgian"},
73{0x1100, 0x11FF, "Hangul Jamo"},
74{0x1200, 0x137F, "Ethiopic"},
75{0x13A0, 0x13FF, "Cherokee"},
76{0x1400, 0x167F, "Unified Canadian Aboriginal Syllabics"},
77{0x1680, 0x169F, "Ogham"},
78{0x16A0, 0x16FF, "Runic"},
79{0x1780, 0x17FF, "Khmer"},
80{0x1800, 0x18AF, "Mongolian"},
81{0x1E00, 0x1EFF, "Latin Extended Additional"},
82{0x1F00, 0x1FFF, "Greek Extended"},
83{0x2000, 0x206F, "General Punctuation"},
84{0x2070, 0x209F, "Superscripts and Subscripts"},
85{0x20A0, 0x20CF, "Currency Symbols"},
86{0x20D0, 0x20FF, "Combining Marks for Symbols"},
87{0x2100, 0x214F, "Letterlike Symbols"},
88{0x2150, 0x218F, "Number Forms"},
89{0x2190, 0x21FF, "Arrows"},
90{0x2200, 0x22FF, "Mathematical Operators"},
91{0x2300, 0x23FF, "Miscellaneous Technical"},
92{0x2400, 0x243F, "Control Pictures"},
93{0x2440, 0x245F, "Optical Character Recognition"},
94{0x2460, 0x24FF, "Enclosed Alphanumerics"},
95{0x2500, 0x257F, "Box Drawing"},
96{0x2580, 0x259F, "Block Elements"},
97{0x25A0, 0x25FF, "Geometric Shapes"},
98{0x2600, 0x26FF, "Miscellaneous Symbols"},
99{0x2700, 0x27BF, "Dingbats"},
100{0x2800, 0x28FF, "Braille Patterns"},
101{0x2E80, 0x2EFF, "CJK Radicals Supplement"},
102{0x2F00, 0x2FDF, "Kangxi Radicals"},
103{0x2FF0, 0x2FFF, "Ideographic Description Characters"},
104{0x3000, 0x303F, "CJK Symbols and Punctuation"},
105{0x3040, 0x309F, "Hiragana"},
106{0x30A0, 0x30FF, "Katakana"},
107{0x3100, 0x312F, "Bopomofo"},
108{0x3130, 0x318F, "Hangul Compatibility Jamo"},
109{0x3190, 0x319F, "Kanbun"},
110{0x31A0, 0x31BF, "Bopomofo Extended"},
111{0x3200, 0x32FF, "Enclosed CJK Letters and Months"},
112{0x3300, 0x33FF, "CJK Compatibility"},
113{0x3400, 0x4DB5, "CJK Unified Ideographs Extension A"},
114{0x4E00, 0x9FFF, "CJK Unified Ideographs"},
115{0xA000, 0xA48F, "Yi Syllables"},
116{0xA490, 0xA4CF, "Yi Radicals"},
117{0xAC00, 0xD7A3, "Hangul Syllables"},
118{0xD800, 0xDB7F, "High Surrogates"},
119{0xDB80, 0xDBFF, "High Private Use Surrogates"},
120{0xDC00, 0xDFFF, "Low Surrogates"},
121{0xE000, 0xF8FF, "Private Use"},
122{0xF900, 0xFAFF, "CJK Compatibility Ideographs"},
123{0xFB00, 0xFB4F, "Alphabetic Presentation Forms"},
124{0xFB50, 0xFDFF, "Arabic Presentation Forms-A"},
125{0xFE20, 0xFE2F, "Combining Half Marks"},
126{0xFE30, 0xFE4F, "CJK Compatibility Forms"},
127{0xFE50, 0xFE6F, "Small Form Variants"},
128{0xFE70, 0xFEFE, "Arabic Presentation Forms-B"},
129{0xFF00, 0xFEFF, "Halfwidth and Fullwidth Forms"},
130{0xFFF0, 0xFFEF, "Specials"},
131 {0xFFFF, 0xFFFF, 0} };
132
133
134UniScrollview::UniScrollview(QWidget* parent, const char* name, int f) :
135 QScrollView(parent, name, f)
136{
137 // smallFont.setRawName( "-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1" ); //######
138 smallFont = QFont( "Helvetica", 8 );
139 QFontMetrics sfm( smallFont );
140 xoff = sfm.width( "AAA" );
141 setFont( FontManager::unicodeFont( FontManager::Fixed ) );
142 QFontMetrics fm( font() );
143 cellsize = fm.lineSpacing() + 2;
144 resizeContents( cellsize*nw, cellsize*65536/nw );
145 verticalScrollBar()->setLineStep(cellsize);
146
147 viewport()->setBackgroundMode( QWidget::PaletteBase );
148}
149
150
151
152void UniScrollview::contentsMousePressEvent(QMouseEvent* e)
153{
154 if ( e->x() < xoff || e->x() > xoff + nw*cellsize )
155 return;
156 int row = e->y()/cellsize;
157 int col = (e->x()-xoff)/cellsize;
158 int u = row*nw+col;
159#if defined(Q_WS_QWS) || defined(_WS_QWS_)
160 emit key( u, 0, 0, true, false );
161 emit key( u, 0, 0, false, false );
162#endif
163}
164
165
166void UniScrollview::contentsMouseReleaseEvent(QMouseEvent*)
167{
168}
169
170void UniScrollview::scrollTo( int unicode )
171{
172 int row = unicode / nw;
173 setContentsPos( 0, row*cellsize );
174}
175
176
177void UniScrollview::drawContents( QPainter *p, int /*cx*/, int cy, int /*cw*/, int ch )
178{
179 QFontMetrics fm = fontMetrics();
180 int row = cy / cellsize;
181 int y = row*cellsize;
182 while ( y < cy+ch ) {
183 p->drawLine( xoff, y, xoff+nw*cellsize, y );
184 if ( row*nw%16 == 0 ) {
185 p->setFont( smallFont );
186 QString s;
187 s.sprintf( "%03X", row*nw/16 );
188 p->drawText( 0, y, xoff, cellsize, AlignLeft, s );
189 p->setFont( font() );
190 }
191 for ( int i = 0; i < nw; i++ ) {
192 p->drawLine( xoff+i*cellsize, y, xoff+i*cellsize, y+cellsize );
193 QChar u = row*nw + i;
194 if ( fm.inFont( u ) )
195 p->drawText( xoff+i*cellsize, y, cellsize, cellsize, AlignCenter,
196 u );
197 }
198 p->drawLine( xoff+nw*cellsize, y, xoff+nw*cellsize, y+cellsize );
199 row++;
200 y += cellsize;
201 }
202}
203
204
205
206
207UniKeyboard::UniKeyboard(QWidget* parent, const char* name, int f )
208 : QFrame( parent, name, f )
209{
210 setFrameStyle( NoFrame );
211 sv = new UniScrollview( this );
212 cb = new QComboBox( FALSE, this );
213 currentBlock = 0;
214 QFontMetrics fm = sv->fontMetrics();
215 cbmap = new int[sizeof(blockMap)/sizeof(blockMap[0])];
216 for ( int i = 0; blockMap[i].name; i++ ) {
217 bool any=FALSE;
218 for ( int c=blockMap[i].start; !any && c<=blockMap[i].stop; c++ )
219 any = fm.inFont(QChar(c));
220 if ( any ) {
221 cbmap[cb->count()]=i;
222 cb->insertItem( blockMap[i].name );
223 }
224 }
225 connect( cb, SIGNAL( activated(int)), this, SLOT( handleCombo(int)) );
226 connect( sv, SIGNAL( contentsMoving(int,int)), this, SLOT( svMove(int,int)) );
227 connect( sv, SIGNAL( key(ushort,ushort,ushort,bool,bool)),
228 this, SIGNAL( key(ushort,ushort,ushort,bool,bool)) );
229}
230
231UniKeyboard::~UniKeyboard()
232{
233 delete [] cbmap;
234}
235
236void UniKeyboard::resizeEvent(QResizeEvent *)
237{
238 int d = frameWidth();
239 cb->setGeometry( d, d, width()-2*d, cb->sizeHint().height() );
240 sv->setGeometry( d, cb->height()+d, width()-2*d, height()-cb->height()-2*d );
241}
242
243void UniKeyboard::svMove( int /*x*/, int y )
244{
245 int cs = sv->cellSize();
246 int u = ((y+cs-1)/cs) * nw;
247 int i = currentBlock;
248 while ( i > 0 && blockMap[i].start > u ) {
249 i--;
250 }
251 while ( blockMap[i+1].name && blockMap[i+1].start < u ) {
252 i++;
253 }
254 if ( i != currentBlock ) {
255 currentBlock = i;
256 for (int ind=0; ind<cb->count(); ind++) {
257 if ( cbmap[ind] == i ) {
258 cb->setCurrentItem( ind );
259 break;
260 }
261 }
262 }
263}
264
265void UniKeyboard::handleCombo( int i )
266{
267 currentBlock = cbmap[i];
268 sv->scrollTo( blockMap[currentBlock].start );
269}
270
271void UniKeyboard::resetState()
272{
273}
274
275QSize UniKeyboard::sizeHint() const
276{
277 return QSize( 240, 2+sv->cellSize()*4+cb->sizeHint().height() );
278}