summaryrefslogtreecommitdiff
path: root/inputmethods/dasher
authormickeyl <mickeyl>2003-09-27 11:29:26 (UTC)
committer mickeyl <mickeyl>2003-09-27 11:29:26 (UTC)
commit651b6c612db4e809c506973996f2580c4158ac3a (patch) (unidiff)
tree8c8edc86e4b206dd4542a6b556ad1a319d6698ab /inputmethods/dasher
parentd1a11b45e805fe7771ea05944757d767c3c4c8ea (diff)
downloadopie-651b6c612db4e809c506973996f2580c4158ac3a.zip
opie-651b6c612db4e809c506973996f2580c4158ac3a.tar.gz
opie-651b6c612db4e809c506973996f2580c4158ac3a.tar.bz2
merge dasher which has been introduced in BRANCH first (wtf?) into HEAD
Diffstat (limited to 'inputmethods/dasher') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/dasher/AlphIO.cpp83
-rw-r--r--inputmethods/dasher/AlphIO.h80
-rw-r--r--inputmethods/dasher/Alphabet.cpp140
-rw-r--r--inputmethods/dasher/Alphabet.h83
-rw-r--r--inputmethods/dasher/AlphabetMap.cpp86
-rw-r--r--inputmethods/dasher/AlphabetMap.h111
-rw-r--r--inputmethods/dasher/Context.h21
-rw-r--r--inputmethods/dasher/CustomAlphabet.cpp40
-rw-r--r--inputmethods/dasher/CustomAlphabet.h26
-rw-r--r--inputmethods/dasher/DashEdit.h163
-rw-r--r--inputmethods/dasher/DasherAppInterface.h72
-rw-r--r--inputmethods/dasher/DasherInterface.cpp636
-rw-r--r--inputmethods/dasher/DasherInterface.h170
-rw-r--r--inputmethods/dasher/DasherModel.cpp322
-rw-r--r--inputmethods/dasher/DasherModel.h111
-rw-r--r--inputmethods/dasher/DasherNode.cpp167
-rw-r--r--inputmethods/dasher/DasherNode.h127
-rw-r--r--inputmethods/dasher/DasherScreen.h102
-rw-r--r--inputmethods/dasher/DasherSettingsInterface.cpp126
-rw-r--r--inputmethods/dasher/DasherSettingsInterface.h149
-rw-r--r--inputmethods/dasher/DasherTypes.h66
-rw-r--r--inputmethods/dasher/DasherView.cpp93
-rw-r--r--inputmethods/dasher/DasherView.h99
-rw-r--r--inputmethods/dasher/DasherView.inl75
-rw-r--r--inputmethods/dasher/DasherViewSquare.cpp229
-rw-r--r--inputmethods/dasher/DasherViewSquare.h58
-rw-r--r--inputmethods/dasher/DasherViewSquare.inl142
-rw-r--r--inputmethods/dasher/DasherWidgetInterface.h93
-rw-r--r--inputmethods/dasher/FrameRate.h112
-rw-r--r--inputmethods/dasher/LanguageModel.cpp77
-rw-r--r--inputmethods/dasher/LanguageModel.h123
-rw-r--r--inputmethods/dasher/MSVC_Unannoy.h17
-rw-r--r--inputmethods/dasher/NoClones.h39
-rw-r--r--inputmethods/dasher/PPMLanguageModel.cpp309
-rw-r--r--inputmethods/dasher/PPMLanguageModel.h122
-rw-r--r--inputmethods/dasher/QtDasherImpl.cc85
-rw-r--r--inputmethods/dasher/QtDasherImpl.h38
-rw-r--r--inputmethods/dasher/QtDasherPlugin.cc79
-rw-r--r--inputmethods/dasher/QtDasherPlugin.h42
-rw-r--r--inputmethods/dasher/QtDasherScreen.cc180
-rw-r--r--inputmethods/dasher/QtDasherScreen.h117
-rw-r--r--inputmethods/dasher/SettingsStore.cpp135
-rw-r--r--inputmethods/dasher/SettingsStore.h92
-rw-r--r--inputmethods/dasher/config.in5
-rw-r--r--inputmethods/dasher/dasher.pro57
-rw-r--r--inputmethods/dasher/opie-dasher-english.control12
-rw-r--r--inputmethods/dasher/opie-dasher.control11
-rw-r--r--inputmethods/dasher/opie-dasher.postinst7
-rw-r--r--inputmethods/dasher/opie-dasher.postrm2
49 files changed, 5331 insertions, 0 deletions
diff --git a/inputmethods/dasher/AlphIO.cpp b/inputmethods/dasher/AlphIO.cpp
new file mode 100644
index 0000000..41b1b23
--- a/dev/null
+++ b/inputmethods/dasher/AlphIO.cpp
@@ -0,0 +1,83 @@
1// AlphIO.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10
11#include "AlphIO.h"
12
13using namespace Dasher;
14using namespace std;
15
16CAlphIO::CAlphIO(string SystemLocation, string UserLocation)
17 : SystemLocation(SystemLocation), UserLocation(UserLocation),
18 BlankInfo(), CData("")
19{
20 CreateDefault();
21}
22
23
24void CAlphIO::GetAlphabets(std::vector< std::string > * AlphabetList) const
25{
26 AlphabetList->clear();
27
28 typedef std::map<std::string, AlphInfo>::const_iterator CI;
29 CI End = Alphabets.end();
30
31 for (CI Cur=Alphabets.begin(); Cur!=End; Cur++)
32 AlphabetList->push_back( (*Cur).second.AlphID);
33}
34
35
36const CAlphIO::AlphInfo& CAlphIO::GetInfo(const std::string& AlphID)
37{
38 if (AlphID=="")
39 return Alphabets["Default"];
40 else {
41 AlphInfo& CurInfo = Alphabets[AlphID];
42 Alphabets[AlphID].AlphID = AlphID; // Ensure consistency
43 return Alphabets[AlphID];
44 }
45}
46
47
48void CAlphIO::SetInfo(const AlphInfo& NewInfo)
49{
50 Alphabets[NewInfo.AlphID] = NewInfo;
51}
52
53
54void CAlphIO::Delete(const std::string& AlphID)
55{
56 if (Alphabets.find(AlphID)!=Alphabets.end()) {
57 Alphabets.erase(AlphID);
58 }
59}
60
61
62void CAlphIO::CreateDefault()
63{
64 // TODO I appreciate these strings should probably be in a resource file.
65 // Not urgent though as this is not intended to be used. It's just a
66 // last ditch effort in case file I/O totally fails.
67 AlphInfo& Default = Alphabets["Default"];
68 Default.AlphID = "Default";
69 Default.Type = Opts::Western;
70 Default.Mutable = false;
71 Default.Orientation = Opts::LeftToRight;
72 Default.SpaceCharacter.Display = "_";
73 Default.SpaceCharacter.Text = " ";
74 Default.TrainingFile = "training_english_GB.txt";
75 string Chars = "abcdefghijklmnopqrstuvwxyz";
76 Default.Groups.resize(1);
77 Default.Groups[0].Description = "Lower case Latin letters";
78 Default.Groups[0].Characters.resize(Chars.size());
79 for (unsigned int i=0; i<Chars.size(); i++) {
80 Default.Groups[0].Characters[i].Text = Chars[i];
81 Default.Groups[0].Characters[i].Display = Chars[i];
82 }
83}
diff --git a/inputmethods/dasher/AlphIO.h b/inputmethods/dasher/AlphIO.h
new file mode 100644
index 0000000..ad31554
--- a/dev/null
+++ b/inputmethods/dasher/AlphIO.h
@@ -0,0 +1,80 @@
1// AlphIO.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10#ifndef __AlphIO_h__
11#define __AlphIO_h__
12
13
14#include "DasherTypes.h"
15
16#include "MSVC_Unannoy.h"
17#include <string>
18#include <map>
19#include <vector>
20#include <utility> // for std::pair
21#include <stdio.h> // for C style file IO
22
23namespace Dasher {class CAlphIO;}
24class Dasher::CAlphIO
25{
26public:
27 // This structure completely describes the characters used in alphabet
28 struct AlphInfo
29 {
30 // Basic information
31 std::string AlphID;
32 bool Mutable; // If from user we may play. If from system defaults this is immutable. User should take a copy.
33
34 // Complete description of the alphabet:
35 std::string TrainingFile;
36 Opts::AlphabetTypes Encoding;
37 Opts::AlphabetTypes Type;
38 Opts::ScreenOrientations Orientation;
39 struct character
40 {
41 std::string Display;
42 std::string Text;
43 std::string Colour;
44 std::string Foreground;
45 };
46 struct group
47 {
48 std::string Description;
49 std::vector< character > Characters;
50 };
51 std::vector< group > Groups;
52 character SpaceCharacter; // display and edit text of Space character. Typically (" ", "_"). Use ("", "") if no space character.
53 };
54
55 CAlphIO(std::string SystemLocation, std::string UserLocation);
56 void GetAlphabets(std::vector< std::string >* AlphabetList) const;
57 const AlphInfo& GetInfo(const std::string& AlphID);
58 void SetInfo(const AlphInfo& NewInfo);
59 void Delete(const std::string& AlphID);
60private:
61 AlphInfo BlankInfo;
62 std::string SystemLocation;
63 std::string UserLocation;
64 std::map<std::string, AlphInfo> Alphabets; // map short names (file names) to descriptions
65
66 void CreateDefault(); // Give the user an English alphabet rather than nothing if anything goes horribly wrong.
67
68
69 // Alphabet types:
70 std::map<std::string, Opts::AlphabetTypes> StoT;
71 std::map<Opts::AlphabetTypes, std::string> TtoS;
72
73 // Data gathered
74 std::string CData; // Text gathered from when an elemnt starts to when it ends
75 AlphInfo InputInfo;
76
77};
78
79
80#endif /* #ifndef __AlphIO_h__ */
diff --git a/inputmethods/dasher/Alphabet.cpp b/inputmethods/dasher/Alphabet.cpp
new file mode 100644
index 0000000..dc58b35
--- a/dev/null
+++ b/inputmethods/dasher/Alphabet.cpp
@@ -0,0 +1,140 @@
1// Alphabet.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include "Alphabet.h"
10#include "AlphabetMap.h"
11
12//#include <iostream>
13//WinCE doesn't have iostream!
14
15using namespace Dasher;
16using namespace std;
17
18
19CAlphabet::CAlphabet() : m_Groups(0), m_DefaultEncoding(Opts::Western), m_Orientation(Opts::LeftToRight)
20{
21 m_Characters.push_back("");
22 m_Display.push_back("");
23 m_Colours.push_back("");
24 m_Foreground.push_back("");
25 m_Group.push_back(0);
26}
27
28
29void CAlphabet::GetSymbols(vector<symbol>* Symbols, string* Input, bool IsMore)
30{
31 string Tmp;
32 symbol CurSymbol=0, TmpSymbol=0;
33 bool KeyIsPrefix;
34 int z= Input->size();
35 int extras;
36 unsigned int bit;
37
38 for (unsigned int i=0; i<Input->size(); i++) {
39
40 Tmp = (*Input)[i];
41
42 /* The string we've been given is in UTF-8. The symbols are
43 also in UTF-8, so we need to pass the entire UTF-8 character
44 which may be several bytes long. RFC 2279 describes this
45 encoding */
46
47 if ((*Input)[i] & 0x80) { // Character is more than 1 byte long
48 extras = 1;
49 for (bit = 0x20; ((*Input)[i] & bit) != 0; bit >>= 1)
50 extras++;
51 if (extras > 5) {
52 } // Malformed character
53 while (extras-->0) {
54 Tmp += (*Input)[++i];
55 }
56 }
57
58 CurSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
59
60 if (KeyIsPrefix) {
61 CurSymbol = 0;
62 for (; i<Input->size(); i++) {
63
64 Tmp += (*Input)[i];
65
66 TmpSymbol = TextMap.Get(Tmp, &KeyIsPrefix);
67 if (TmpSymbol>0) {
68 CurSymbol = TmpSymbol;
69 }
70 if (!KeyIsPrefix) {
71 if (CurSymbol!=0) {
72 Symbols->push_back(CurSymbol);
73 } else {
74 i -= Tmp.size()-1;
75 //Tmp.erase(Tmp.begin(), Tmp.end());
76 Tmp = "";
77 }
78 break;
79 }
80 }
81 } else {
82 if (CurSymbol!=0)
83 Symbols->push_back(CurSymbol);
84 }
85 }
86
87 if (IsMore)
88 if (KeyIsPrefix)
89 *Input = Tmp;
90 else
91 *Input = "";
92 else
93 if (KeyIsPrefix)
94 Symbols->push_back(CurSymbol);
95}
96
97
98// add single char to the character set
99void CAlphabet::AddChar(const string NewCharacter, const string Display, const string Colour, const string Foreground)
100{
101 m_Characters.push_back(NewCharacter);
102 m_Display.push_back(Display);
103 m_Colours.push_back(Colour);
104 m_Foreground.push_back(Foreground);
105 m_Group.push_back(m_Groups);
106
107 symbol ThisSymbol = m_Characters.size()-1;
108 TextMap.Add(NewCharacter, ThisSymbol);
109}
110
111
112void CAlphabet::StartNewGroup()
113{
114 m_Groups++;
115}
116
117
118// diagnostic dump of character set
119void CAlphabet::dump() const {
120// TODO
121/*
122 dchar deb[256];
123 unsigned int i;
124 for (i=1;i<m_vtCharacters.size();i++) {
125 //wsprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]); // Windows specific
126 Usprintf(deb,TEXT("%d %c %d\n"),i,m_vtCharacters[i],m_viGroup[i]);
127 DebugOutput(deb);
128 }
129*/
130}
131
132int CAlphabet::GetTextColour(symbol Symbol)
133{
134 std::string TextColour=m_Foreground[Symbol];
135 if (TextColour != "") {
136 return atoi(TextColour.c_str());
137 } else {
138 return 0;
139 }
140}
diff --git a/inputmethods/dasher/Alphabet.h b/inputmethods/dasher/Alphabet.h
new file mode 100644
index 0000000..5f0f9a5
--- a/dev/null
+++ b/inputmethods/dasher/Alphabet.h
@@ -0,0 +1,83 @@
1// Alphabet.h
2//
3/////////////////////////////////////////////////////////////////////////////
4// Alphabet.h
5//
6/////////////////////////////////////////////////////////////////////////////
7//
8// Copyright (c) 2001-2002 David Ward
9//
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __DASHER_ALPHABET_H__
13#define __DASHER_ALPHABET_H__
14
15
16#include "DasherTypes.h"
17
18#include "MSVC_Unannoy.h"
19#include <map>
20#include <vector>
21#include "AlphabetMap.h"
22
23
24namespace Dasher {class CAlphabet;}
25class Dasher::CAlphabet
26{
27public:
28 CAlphabet();
29 ~CAlphabet() {}
30
31 int GetNumberSymbols() const { return m_Characters.size();} // return size of alphabet
32
33 Opts::ScreenOrientations GetOrientation() {return m_Orientation;}
34 Opts::AlphabetTypes GetType() {return m_DefaultEncoding;}
35 std::string& GetTrainingFile() {return m_TrainingFile;}
36
37 symbol GetSpaceSymbol() {return m_SpaceSymbol;}
38 const std::string& GetDisplayText(symbol i) const {return m_Display[i];} // return display string for i'th symbol
39 const std::string& GetText(symbol i) const {return m_Characters[i];} // return string for i'th symbol
40 const std::string& GetColour(symbol i) const {return m_Colours[i];} // return the colour for i'th symbol
41 int GetTextColour(symbol i); // return the foreground colour for i'th symbol
42 const std::string& GetForeground(symbol i) const {return m_Foreground[i];} // return the foreground colour for i'th symbol
43 int get_group(symbol i) const {return m_Group[i];} // return group membership of i'th symbol
44
45 // Fills Symbols with the symbols corresponding to Input. {{{ Note that this
46 // is not necessarily reversible by repeated use of GetText. Some text
47 // may not be recognised and so discarded. If IsMore is true then Input
48 // is truncated to any final characters that were not used due to ambiguous
49 // continuation. If IsMore is false Input is assumed to be all the available
50 // text and so a symbol will be returned for a final "a" even if "ae" is
51 // defined as its own symbol. }}}
52 void GetSymbols(std::vector<symbol>* Symbols, std::string* Input, bool IsMore);
53
54 void dump() const; // diagnostic
55
56protected:
57 // Add the characters that can appear in Nodes
58 void AddChar(const std::string NewCharacter, const std::string Display, const std::string Colour, const std::string Foreground); // add single char to the alphabet
59 void StartNewGroup();
60
61 // Alphabet language parameters
62 void SetSpaceSymbol() {m_SpaceSymbol=m_Characters.size()-1;} // We can set the space symbol to be the last character added
63 void SetSpaceSymbol(symbol SpaceSymbol) {m_SpaceSymbol=SpaceSymbol;} // ...or any desired symbol.
64 void SetOrientation(Opts::ScreenOrientations Orientation) {m_Orientation=Orientation;}
65 void SetLanguage(Opts::AlphabetTypes Group) {m_DefaultEncoding=Group;}
66 void SetTrainingFile(std::string TrainingFile) {m_TrainingFile=TrainingFile;}
67private:
68 Opts::AlphabetTypes m_DefaultEncoding;
69 Opts::ScreenOrientations m_Orientation;
70 symbol m_SpaceSymbol;
71 std::string m_TrainingFile;
72
73 std::vector<std::string> m_Characters; // stores the characters
74 std::vector<std::string> m_Display; // stores how the characters are visually represented in the Dasher nodes
75 std::vector<std::string> m_Colours; // stores the colour of the characters
76 std::vector<std::string> m_Foreground; // stores the colour of the character foreground
77 std::vector<int> m_Group; // stores the group indicators - e.g. caps, numbers, punctuation
78 int m_Groups; // number of groups
79 alphabet_map TextMap;
80};
81
82
83#endif // ifndef __DASHER_ALPHABET_H__
diff --git a/inputmethods/dasher/AlphabetMap.cpp b/inputmethods/dasher/AlphabetMap.cpp
new file mode 100644
index 0000000..09e2c72
--- a/dev/null
+++ b/inputmethods/dasher/AlphabetMap.cpp
@@ -0,0 +1,86 @@
1// AlphabetMap.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include "AlphabetMap.h"
10
11using namespace Dasher;
12using namespace std;
13
14alphabet_map::alphabet_map(unsigned int InitialTableSize)
15 : Undefined(0), HashTable(InitialTableSize<<1)
16{
17 Entries.reserve(InitialTableSize);
18}
19
20
21void alphabet_map::Add(const string& Key, symbol Value)
22{
23 RecursiveAdd(Key, Value, false);
24}
25
26
27void alphabet_map::RecursiveAdd(const string& Key, symbol Value, bool PrefixFlag)
28{
29 Entry*& HashEntry = HashTable[Hash(Key)];
30
31 // Loop through Entries with the correct Hash value.
32 for (Entry* i = HashEntry; i; i=i->Next) {
33 if (i->Key==Key) {
34 if (PrefixFlag) {
35 // Just tagging - don't change symbol. Recurse if necessary
36 i->KeyIsPrefix = true;
37 if (Key.size()>1)
38 RecursiveAdd(Key.substr(Key.size()-1), Undefined, true);
39 } else {
40 // Add symbol and leave
41 i->Symbol = Value;
42 }
43 return;
44 }
45 }
46
47 // When hash table gets 1/2 full...
48 // (no I haven't optimised when to resize)
49 if (Entries.size()<<1 >= HashTable.size()) {
50 // Double up all the storage
51 HashTable.clear();
52 HashTable.resize(Entries.size()<<2);
53 Entries.reserve(Entries.size()<<1);
54
55 // Rehash as the pointers will all be mangled.
56 for (uint j=0; j<Entries.size(); j++) {
57 Entry*& HashEntry2 = HashTable[Hash(Entries[j].Key)];
58 Entries[j].Next = HashEntry2;
59 HashEntry2 = &Entries[j];
60 }
61
62 // Have to recall this function as the key's hash needs recalculating
63 RecursiveAdd(Key, Value, PrefixFlag);
64 return;
65 }
66
67 Entries.push_back(Entry(Key, Value, HashEntry));
68 HashEntry = &Entries.back();
69}
70
71
72symbol alphabet_map::Get(const string& Key, bool* KeyIsPrefix) const
73{
74 // Loop through Entries with the correct Hash value.
75 for (Entry* i = HashTable[Hash(Key)]; i; i=i->Next) {
76 if (i->Key==Key) {
77 if (KeyIsPrefix!=0)
78 *KeyIsPrefix = i->KeyIsPrefix;
79 return i->Symbol;
80 }
81 }
82
83 if (KeyIsPrefix!=0)
84 *KeyIsPrefix = false;
85 return Undefined;
86}
diff --git a/inputmethods/dasher/AlphabetMap.h b/inputmethods/dasher/AlphabetMap.h
new file mode 100644
index 0000000..3aac1f5
--- a/dev/null
+++ b/inputmethods/dasher/AlphabetMap.h
@@ -0,0 +1,111 @@
1// AlphabetMap.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10/*
11If I were just using GCC, which comes with the CGI "STL" implementation, I would
12use hash_map (which isn't part of the ANSI/ISO standard C++ STL, but hey it's nice).
13Using a plain map is just too slow for training on large files (or it is with certain
14STL implementations). I'm sure training could be made much faster still, but that's
15another matter...
16
17While I could (and probably should) get a hash_map for VC++ from
18http://www.stlport.org I thought it would be nicer if people didn't have
19to download extra stuff and then have to get it working alongside the STL
20with VC++, especially for just one small part of Dasher.
21
22The result is this:
23***************************************************
24very much thrown together to get Dasher out ASAP.
25***************************************************
26It is deliberately not like an STL container.
27However, as it has a tiny interface, it should still be easy to replace.
28Sorry if this seems really unprofressional.
29
30Replacing it might be a good idea. On the other hand it could be customised
31to the needs of the alphabet, so that it works faster. For example,
32currently if I have a string "asdf", it might be that "a" is checked
33then "as" is checked then "asd" is checked. I shouldn't need to keep
34rehashing the leading characters. I plan to fix that here. Doing so with
35a standard hash_map would be hard.
36
37
38Usage:
39alphabet_map MyMap(NumberOfEntriesWeExpect); // Can omit NumberOfEntriesWeExpect
40MyMap.add("asdf", 15);
41symbol i = MyMap.get("asdf") // i=15
42symbol j = MyMap.get("fdsa") // j=0
43
44You can't remove items once they are added as Dasher has no need for that.
45
46IAM 08/2002
47*/
48
49#ifndef __AlphabetMap_h__
50#define __AlphabetMap_h__
51
52#include "MSVC_Unannoy.h"
53#include <vector>
54#include <string>
55
56#include "DasherTypes.h"
57
58namespace Dasher {class alphabet_map;}
59class Dasher::alphabet_map
60{
61public:
62 alphabet_map(uint InitialTableSize=255);
63 void Add(const std::string& Key, symbol Value);
64 symbol Get(const std::string& Key, bool* KeyIsPrefix=0) const;
65
66private:
67 class Entry
68 {
69 public:
70 Entry(std::string Key, symbol Symbol, Entry* Next)
71 : Key(Key), Symbol(Symbol), Next(Next), KeyIsPrefix(false) {}
72
73 std::string Key;
74 bool KeyIsPrefix;
75 symbol Symbol;
76 Entry* Next;
77 };
78
79 void RecursiveAdd(const std::string& Key, symbol Value, bool PrefixFlag);
80
81 // A standard hash -- could try and research something specific.
82 inline uint Hash(const std::string& Input) const {
83 uint Result = 0;
84
85 typedef std::string::const_iterator CI;
86 CI Cur = Input.begin();
87 CI end = Input.end();
88
89 while (Cur!=end) Result = (Result<<1)^*Cur++;
90 Result %= HashTable.size();
91
92 return Result;
93 /*
94 if (Input.size()==1) // Speedup for ASCII text
95 return Input[0];
96
97 for (int i=0; i<Input.size(); i++)
98 Result = (Result<<1)^Input[i];
99
100
101 return Result%HashTable.size();
102 */
103 }
104
105 std::vector<Entry> Entries;
106 std::vector<Entry*> HashTable;
107 const symbol Undefined;
108};
109
110
111#endif /* #ifndef __AlphabetMap_h__ */
diff --git a/inputmethods/dasher/Context.h b/inputmethods/dasher/Context.h
new file mode 100644
index 0000000..ff31cee
--- a/dev/null
+++ b/inputmethods/dasher/Context.h
@@ -0,0 +1,21 @@
1// Context.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef Context_h
10#define Context_h
11
12namespace Dasher {class CContext;}
13class Dasher::CContext
14{
15public:
16 CContext() {};
17 virtual ~CContext() {};
18};
19
20
21#endif /* #ifndef Context_h */
diff --git a/inputmethods/dasher/CustomAlphabet.cpp b/inputmethods/dasher/CustomAlphabet.cpp
new file mode 100644
index 0000000..deb0f6d
--- a/dev/null
+++ b/inputmethods/dasher/CustomAlphabet.cpp
@@ -0,0 +1,40 @@
1// CustomAlphabet.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10#include "CustomAlphabet.h"
11
12using namespace Dasher;
13using namespace std;
14
15
16CCustomAlphabet::CCustomAlphabet(const CAlphIO::AlphInfo& AlphInfo)
17{
18 // Set miscellaneous options
19 SetOrientation(AlphInfo.Orientation);
20 SetLanguage(AlphInfo.Type);
21 SetTrainingFile(AlphInfo.TrainingFile);
22
23 // Add all the characters.
24 for (unsigned int i=0; i<AlphInfo.Groups.size(); i++) { // loop groups
25 for (unsigned int j=0; j<AlphInfo.Groups[i].Characters.size(); j++) { // loop characters
26 AddChar(AlphInfo.Groups[i].Characters[j].Text, AlphInfo.Groups[i].Characters[j].Display, AlphInfo.Groups[i].Characters[j].Colour, AlphInfo.Groups[i].Characters[j].Foreground);
27 }
28 StartNewGroup();
29 }
30
31 // Set Space character if requested
32
33 // This line makes it a bit easier for our WindowsCE compiler
34 std::string empty="";
35
36 if (AlphInfo.SpaceCharacter.Text != empty ) {
37 AddChar(AlphInfo.SpaceCharacter.Text, AlphInfo.SpaceCharacter.Display, AlphInfo.SpaceCharacter.Colour, AlphInfo.SpaceCharacter.Foreground);
38 SetSpaceSymbol();
39 }
40}
diff --git a/inputmethods/dasher/CustomAlphabet.h b/inputmethods/dasher/CustomAlphabet.h
new file mode 100644
index 0000000..4cd7880
--- a/dev/null
+++ b/inputmethods/dasher/CustomAlphabet.h
@@ -0,0 +1,26 @@
1// CustomAlphabet.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10#ifndef __CustomAlphabet_h__
11#define __CustomAlphabet_h__
12
13
14#include "Alphabet.h"
15#include "AlphIO.h"
16
17
18namespace Dasher {class CCustomAlphabet;}
19class Dasher::CCustomAlphabet : public Dasher::CAlphabet
20{
21public:
22 CCustomAlphabet(const CAlphIO::AlphInfo& AlphInfo);
23};
24
25
26#endif /* #ifndef __CustomAlphabet_h__ */
diff --git a/inputmethods/dasher/DashEdit.h b/inputmethods/dasher/DashEdit.h
new file mode 100644
index 0000000..dc14d15
--- a/dev/null
+++ b/inputmethods/dasher/DashEdit.h
@@ -0,0 +1,163 @@
1//! Class definition for an edit box
2// DashEdit.h
3//
4/////////////////////////////////////////////////////////////////////////////
5//
6// Copyright (c) 2002 Iain Murray
7//
8/////////////////////////////////////////////////////////////////////////////
9
10/*
11An abstract DashEditbox class is described here.
12An implementation will handle interaction between Dasher and an actual Edit control.
13e.g. - output characters to the edit control
14 - tapping on the edit box updates the Dasher display
15*/
16
17#ifndef __DashEdit_h__
18#define __DashEdit_h__
19
20#include "DasherWidgetInterface.h"
21
22namespace Dasher {class CDashEditbox;}
23class Dasher::CDashEditbox
24{
25public:
26 CDashEditbox() : m_iFlushed(0), m_DasherInterface(0), m_dirty(false) {}
27
28 //! Provide the Editbox with a widget interface
29 virtual void SetInterface(CDasherWidgetInterface* DasherInterface) {m_DasherInterface = DasherInterface;}
30
31 //! Write some buffered output to a file
32 virtual void write_to_file()=0;
33
34 //! Set the number of flushed characters
35 //
36 //! Set the number of flushed characters to an arbitrary number.
37 //! Usually used to reset it to 0 after unflushing
38 void set_flushed(int i) {m_iFlushed=i;}
39
40 //! Provide context from the editbox for the core
41 //
42 //! Provide the context at the current position within the editbox to
43 //! the core. Set str to up to max characters before
44 //! the cursor position within the editbox.
45 virtual void get_new_context(std::string& str, int max)=0;
46
47 //! Delete flushed text from the editbox
48 virtual inline void unflush()=0;
49
50 //! Enter a the character Symbol into the text box
51 virtual void output(symbol Symbol)=0;
52
53 //! Delete the previous symbol from the text box
54 virtual void deletetext()=0;
55
56 //! Enter a character into the text box and remember that it is flushed
57 //
58 //! Output the character and increment m_iFlushed. When unflush is
59 //! called, remove the previous m_iFlushed characters
60 virtual void flush(symbol Symbol)=0;
61
62 // File I/O (optional)
63
64 //! If Value is true, timestamp all new files (optional)
65 //
66 //! If switched on, all new files should be timestamped, either in the
67 //! filename or in file metadata
68 virtual void TimeStampNewFiles(bool Value) {}
69
70 //! Return true if any text has been modified since the last save (optional)
71 bool IsDirty() {return m_dirty;}
72
73 //! Generate a new file (optional)
74 //
75 //! New file - provide a file save dialogue and return the filename in
76 //! filename, or provide a blank filename and present a file
77 //! save dialogue when Save() is called
78 virtual void New(const std::string& filename) {}; // filename can be "", but you cannot call Save() without having set a filename.
79
80 //! Open a file (optional)
81 //
82 //! Provide a file open dialogue and set filename to the
83 //! filename. Return true if a file is chosen and opened successfully,
84 //! false otherwise
85 virtual bool Open(const std::string& filename) {return false;};
86
87 //! Open a file and append to it (optional)
88 //
89 //! Provide a file open dialogue and set filename to the
90 //! filename. The file will then have any new text appended to it.
91 //! Return true if a file is chosen and opened successfully, false
92 //! otherwise
93 virtual bool OpenAppendMode(const std::string& filename) {return false;};
94 //! Save a file as a provided filename (optional)
95 //
96 //! Provide a file save dialogue and set filename to the
97 //! filename. Return true if a file is chosen and saved successfully,
98 //! false otherwise
99 virtual bool SaveAs(const std::string& filename) {return false;};
100
101 //! Save the current file (optional)
102 //
103 //! Save file to the current filename. If there is no current filename,
104 //! or if saving fails, return false
105 virtual bool Save() {return false;}; // returns false if there is no filename set, or if saving fails
106
107 // Clipboard (optional)
108 //! Cut selected text (optional)
109 //
110 //! Copy the selected text to the clipboard and remove it from the
111 //! editbox
112 virtual void Cut() {};
113
114 //! Copy selected text (optional)
115 //
116 //! Copy the selected text to the clipboard
117 virtual void Copy() {};
118
119 //! Copy all text (optional)
120 //
121 //! Copy all text in the editbox to the clipboard
122 virtual void CopyAll() {};
123
124 //! Paste text from clipboard (optional)
125 //
126 //! Paste text from the clipboard into the editbox at the current
127 //! position
128 virtual void Paste() {};
129
130 //! Select all text in the editbox (optional)
131 virtual void SelectAll() {};
132
133 //! Clear all text from the editbox (REQUIRED)
134 virtual void Clear()=0; // Must at least be able to clear edit box
135
136 //! Set the file encoding
137 //
138 //! Set the file encoding to the provided encoding Encoding.
139 //! The editbox is responsible for saving the file in the encoding
140 //! desired by the user. As Dasher is internally UTF8, it may well be
141 //! necessary to save in an alternative format based on locale and OS.
142 virtual void SetEncoding(Opts::FileEncodingFormats Encoding)=0;
143
144 //! Set the font used in the editbox
145 //
146 //! Set the font used in the editbox to Name and size
147 //! Size (in points)
148 virtual void SetFont(std::string Name, long Size)=0;
149
150// TODO sort relationship between CDashEditbox and derived classes
151protected:
152 //! Have the contents of the editbox been altered since the last save?
153 bool m_dirty;
154
155 //! Record the number of characters that have been flushed
156 int m_iFlushed; // how many characters have been flushed
157
158 //! Pointer to a DasherWidgetInterface for communication with the core
159 CDasherWidgetInterface* m_DasherInterface;
160};
161
162
163#endif /* #ifndef __DashEdit_h__ */
diff --git a/inputmethods/dasher/DasherAppInterface.h b/inputmethods/dasher/DasherAppInterface.h
new file mode 100644
index 0000000..c4f011c
--- a/dev/null
+++ b/inputmethods/dasher/DasherAppInterface.h
@@ -0,0 +1,72 @@
1// DasherAppInterface.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __DasherAppInterface_h__
10#define __DasherAppInterface_h__
11
12#include "DasherScreen.h"
13#include "DashEdit.h"
14#include "AlphIO.h"
15#include <string>
16#include <vector>
17
18namespace Dasher {class CDasherAppInterface;}
19class Dasher::CDasherAppInterface
20{
21public:
22 // We may change the widgets Dasher uses at run time
23
24 //! Change the screen being used by the core to NewScreen
25 virtual void ChangeScreen(CDasherScreen* NewScreen)=0;
26
27 //! Change the editbox being used by the core to NewEdit
28 virtual void ChangeEdit(CDashEditbox* NewEdit)=0;
29
30 // Training by string segments or file all training data must be in UTF-8.
31 //! Train the core on Trainstring
32 //
33 //! \param TrainString UTF-8 encoded string to train the core on
34 //! \param IsMore True if more text is to follow as part of the same
35 //! logical sequence, false otherwise (this allows the model to make
36 //! assumptions regarding whether the final character provided is in
37 //! the middle of a word or not)
38 virtual void Train(std::string* TrainString, bool IsMore)=0;
39
40 //! Train the core on the file in Filename.
41 //
42 //! The file should contain UTF-8 encoded text
43 virtual void TrainFile(std::string Filename)=0;
44
45 // App may want to display characters per minute or frames per second.
46
47 //! Tell the interface how many font sizes there are and what they are
48
49 virtual void GetFontSizes(std::vector<int> *FontSizes)=0;
50
51 //! Provides the number of characters per minute input. (Not implemented)
52 virtual double GetCurCPM()=0;
53
54 //! Provides the framerate that Dasher is runnin at. (Not implemented)
55 virtual double GetCurFPS()=0;
56
57 // Customize alphabet
58 //! Get a vector containing a list of alphabet names available to Dasher
59 virtual void GetAlphabets(std::vector< std::string >* AlphabetList)=0;
60
61 //! Return an AlphInfo object containing the alphabet with name AlphID
62 virtual const CAlphIO::AlphInfo& GetInfo(const std::string& AlphID)=0;
63
64 //! Save a new or modified AlphInfo object
65 virtual void SetInfo(const CAlphIO::AlphInfo& NewInfo)=0;
66
67 //! Delete the alphabet with name AlphID
68 virtual void DeleteAlphabet(const std::string& AlphID)=0;
69};
70
71
72#endif /* #ifndef __DasherAppInterface_h__ */
diff --git a/inputmethods/dasher/DasherInterface.cpp b/inputmethods/dasher/DasherInterface.cpp
new file mode 100644
index 0000000..bb5b85e
--- a/dev/null
+++ b/inputmethods/dasher/DasherInterface.cpp
@@ -0,0 +1,636 @@
1// DasherInterface.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10
11#include "DasherInterface.h"
12//#include "EnglishAlphabet.h"
13#include "CustomAlphabet.h"
14#include "DasherViewSquare.h"
15#include "PPMLanguageModel.h"
16#include <iostream>
17namespace {
18 #include "stdio.h"
19}
20using namespace Dasher;
21using namespace std;
22
23
24const string CDasherInterface::EmptyString = "";
25
26
27CDasherInterface::CDasherInterface()
28 : m_DashEditbox(0), m_DasherScreen(0), m_LanguageModel(0), TrainContext(0), m_Alphabet(0),
29 m_DasherModel(0), m_DasherView(0), AlphabetID(""), LanguageModelID(-1), ViewID(-1),
30 m_MaxBitRate(-1), m_Orientation(Opts::LeftToRight), m_SettingsStore(0), m_SettingsUI(0),
31 m_UserLocation("usr_"), m_SystemLocation("sys_"), m_AlphIO(0), m_TrainFile(""),
32 m_DasherFont(""), m_EditFont(""), m_EditFontSize(0), m_DrawKeyboard(false)
33{
34}
35
36
37CDasherInterface::~CDasherInterface()
38{
39 if (m_LanguageModel)
40 m_LanguageModel->ReleaseNodeContext(TrainContext);
41 delete m_DasherModel; // The order of some of these deletions matters
42 delete m_LanguageModel; // eg DasherModel has a pointer to LanguageModel.
43 delete m_Alphabet; // DM baulks if LM is deleted before it is.
44 delete m_DasherView;
45 // Do NOT delete Edit box or Screen. This class did not create them.
46}
47
48
49void CDasherInterface::SetSettingsStore(CSettingsStore* SettingsStore)
50{
51 delete m_SettingsStore;
52 m_SettingsStore = SettingsStore;
53 this->SettingsDefaults(m_SettingsStore);
54}
55
56
57void CDasherInterface::SetSettingsUI(CDasherSettingsInterface* SettingsUI)
58{
59 delete m_SettingsUI;
60 m_SettingsUI = SettingsUI;
61 //this->SettingsDefaults(m_SettingsStore);
62 m_SettingsUI->SettingsDefaults(m_SettingsStore);
63}
64
65
66void CDasherInterface::SetUserLocation(std::string UserLocation)
67{
68 // Nothing clever updates. (At the moment) it is assumed that
69 // this is set before anything much happens and that it does
70 // not require changing.
71 m_UserLocation = UserLocation;
72 if (m_Alphabet!=0)
73 m_TrainFile = m_UserLocation + m_Alphabet->GetTrainingFile();
74}
75
76
77void CDasherInterface::SetSystemLocation(std::string SystemLocation)
78{
79 // Nothing clever updates. (At the moment) it is assumed that
80 // this is set before anything much happens and that it does
81 // not require changing.
82 m_SystemLocation = SystemLocation;
83}
84
85
86void CDasherInterface::CreateDasherModel()
87{
88
89 if (m_DashEditbox!=0 && m_LanguageModel!=0) {
90 delete m_DasherModel;
91 m_DasherModel = new CDasherModel(m_DashEditbox, m_LanguageModel, m_Dimensions);
92 if (m_MaxBitRate>=0)
93 m_DasherModel->SetMaxBitrate(m_MaxBitRate);
94 if (ViewID!=-1)
95 ChangeView(ViewID);
96 }
97
98
99}
100
101
102void CDasherInterface::Start()
103{
104 if (m_DasherModel!=0)
105 m_DasherModel->Start();
106}
107
108
109void CDasherInterface::PauseAt(int MouseX, int MouseY)
110{
111 if (m_DasherView!=0)
112 m_DasherView->FlushAt(MouseX, MouseY);
113 if (m_DashEditbox!=0) {
114 m_DashEditbox->write_to_file();
115 if (m_CopyAllOnStop)
116 m_DashEditbox->CopyAll();
117 }
118}
119
120
121void CDasherInterface::Unpause(unsigned long Time)
122{
123 if (m_DashEditbox!=0)
124 m_DashEditbox->unflush();
125 if (m_DasherModel!=0)
126 m_DasherModel->Reset_framerate(Time);
127}
128
129
130void CDasherInterface::Redraw()
131{
132
133 if (m_DasherView!=0) {
134 m_DasherView->Render();
135 m_DasherView->Display();
136 }
137
138}
139
140
141void CDasherInterface::TapOn(int MouseX, int MouseY, unsigned long Time)
142{
143 if (m_DasherView!=0) {
144 m_DasherView->TapOnDisplay(MouseX, MouseY, Time);
145 m_DasherView->Render();
146 if (m_DrawMouse==true) {
147 m_DasherView->DrawMouse(MouseX, MouseY);
148 }
149 if (m_DrawKeyboard==true) {
150 m_DasherView->DrawKeyboard();
151 }
152 m_DasherView->Display();
153 }
154 if (m_DasherModel!=0)
155 m_DasherModel->NewFrame(Time);
156}
157
158
159void CDasherInterface::ChangeAlphabet(const std::string& NewAlphabetID)
160{
161 if (m_SettingsUI!=0)
162 m_SettingsUI->ChangeAlphabet(NewAlphabetID);
163 if (m_SettingsStore!=0)
164 m_SettingsStore->SetStringOption(Keys::ALPHABET_ID, NewAlphabetID);
165
166 AlphabetID = NewAlphabetID;
167 if (!m_AlphIO)
168 m_AlphIO = new CAlphIO(m_SystemLocation, m_UserLocation);
169 CAlphIO::AlphInfo Info = m_AlphIO->GetInfo(NewAlphabetID);
170
171 CAlphabet* old = m_Alphabet;
172 m_Alphabet = new CCustomAlphabet(Info);
173
174 // Apply options from alphabet
175
176 m_TrainFile = m_UserLocation + m_Alphabet->GetTrainingFile();
177
178 // Recreate widgets and language model
179 if (m_DashEditbox!=0)
180 m_DashEditbox->SetInterface(this);
181 if (m_DasherScreen!=0)
182 m_DasherScreen->SetInterface(this);
183 if (LanguageModelID!=-1 || m_LanguageModel)
184 ChangeLanguageModel(LanguageModelID);
185
186 delete old; // only delete old alphabet after telling all other objects not to use it
187
188 Start();
189
190 // We can only change the orientation after we have called
191 // Start, as this will prompt a redraw, which will fail if the
192 // model hasn't been updated for the new alphabet
193
194 if (m_Orientation==Opts::Alphabet)
195 ChangeOrientation(Opts::Alphabet);
196
197 Redraw();
198}
199
200
201void CDasherInterface::ChangeMaxBitRate(double NewMaxBitRate)
202{
203 m_MaxBitRate = NewMaxBitRate;
204
205 if (m_DasherModel!=0)
206 m_DasherModel->SetMaxBitrate(m_MaxBitRate);
207 if (m_SettingsUI!=0)
208 m_SettingsUI->ChangeMaxBitRate(m_MaxBitRate);
209 if (m_SettingsStore!=0)
210 m_SettingsStore->SetLongOption(Keys::MAX_BITRATE_TIMES100, long(m_MaxBitRate*100) );
211
212 if (m_DrawKeyboard==true && m_DasherView!=NULL) {
213 m_DasherView->DrawKeyboard();
214 }
215}
216
217
218void CDasherInterface::ChangeLanguageModel(unsigned int NewLanguageModelID)
219{
220 LanguageModelID = NewLanguageModelID;
221 if (m_Alphabet!=0) {
222 if (m_LanguageModel)
223 m_LanguageModel->ReleaseNodeContext(TrainContext);
224 TrainContext = 0;
225 delete m_DasherModel; // Have to delete DasherModel, or removing its LanguageModel will confuse it
226 m_DasherModel = 0;
227 delete m_LanguageModel;
228 // TODO Use LanguageModelID to decide which model to use
229 m_LanguageModel = new CPPMLanguageModel(m_Alphabet,1<<10);
230 TrainContext = m_LanguageModel->GetRootNodeContext();
231 string T = m_Alphabet->GetTrainingFile();
232 TrainFile(m_SystemLocation+T);
233 TrainFile(m_UserLocation+T);
234 CreateDasherModel();
235 }
236}
237
238
239void CDasherInterface::ChangeScreen()
240{
241 if (m_DasherView!=0) {
242 m_DasherView->ChangeScreen(m_DasherScreen);
243 } else {
244 if (ViewID!=-1)
245 ChangeView(ViewID);
246 }
247}
248
249
250void CDasherInterface::ChangeScreen(CDasherScreen* NewScreen)
251{
252 m_DasherScreen = NewScreen;
253 m_DasherScreen->SetFont(m_DasherFont);
254 m_DasherScreen->SetInterface(this);
255 ChangeScreen();
256 Redraw();
257}
258
259
260void CDasherInterface::ChangeView(unsigned int NewViewID)
261{
262 //TODO Use DasherViewID
263 ViewID = NewViewID;
264 if (m_DasherScreen!=0 && m_DasherModel!=0) {
265 delete m_DasherView;
266 if (m_Orientation==Opts::Alphabet)
267 m_DasherView = new CDasherViewSquare(m_DasherScreen, *m_DasherModel, GetAlphabetOrientation());
268 else
269 m_DasherView = new CDasherViewSquare(m_DasherScreen, *m_DasherModel, m_Orientation);
270 }
271}
272
273
274void CDasherInterface::ChangeOrientation(Opts::ScreenOrientations Orientation)
275{
276 m_Orientation = Orientation;
277 if (m_DasherView!=0) {
278 if (Orientation==Opts::Alphabet)
279 m_DasherView->ChangeOrientation(GetAlphabetOrientation());
280 else
281 m_DasherView->ChangeOrientation(Orientation);
282 }
283 if (m_SettingsUI!=0)
284 m_SettingsUI->ChangeOrientation(Orientation);
285 if (m_SettingsStore!=0)
286 m_SettingsStore->SetLongOption(Keys::SCREEN_ORIENTATION, Orientation);
287}
288
289
290void CDasherInterface::SetFileEncoding(Opts::FileEncodingFormats Encoding)
291{
292 if (m_SettingsUI!=0)
293 m_SettingsUI->SetFileEncoding(Encoding);
294 if (m_SettingsStore!=0)
295 m_SettingsStore->SetLongOption(Keys::FILE_ENCODING, Encoding);
296 if (m_DashEditbox)
297 m_DashEditbox->SetEncoding(Encoding);
298}
299
300
301void CDasherInterface::ShowToolbar(bool Value)
302{
303 if (m_SettingsUI!=0)
304 m_SettingsUI->ShowToolbar(Value);
305 if (m_SettingsStore!=0)
306 m_SettingsStore->SetBoolOption(Keys::SHOW_TOOLBAR, Value);
307}
308
309
310void CDasherInterface::ShowToolbarText(bool Value)
311{
312 if (m_SettingsUI!=0)
313 m_SettingsUI->ShowToolbarText(Value);
314 if (m_SettingsStore!=0)
315 m_SettingsStore->SetBoolOption(Keys::SHOW_TOOLBAR_TEXT, Value);
316}
317
318
319void CDasherInterface::ShowToolbarLargeIcons(bool Value)
320{
321 if (m_SettingsUI!=0)
322 m_SettingsUI->ShowToolbarLargeIcons(Value);
323 if (m_SettingsStore!=0)
324 m_SettingsStore->SetBoolOption(Keys::SHOW_LARGE_ICONS, Value);
325}
326
327
328void CDasherInterface::ShowSpeedSlider(bool Value)
329{
330 if (m_SettingsUI!=0)
331 m_SettingsUI->ShowSpeedSlider(Value);
332 if (m_SettingsStore!=0)
333 m_SettingsStore->SetBoolOption(Keys::SHOW_SLIDER, Value);
334}
335
336
337void CDasherInterface::FixLayout(bool Value)
338{
339 if (m_SettingsUI!=0)
340 m_SettingsUI->FixLayout(Value);
341 if (m_SettingsStore!=0)
342 m_SettingsStore->SetBoolOption(Keys::FIX_LAYOUT, Value);
343}
344
345
346void CDasherInterface::TimeStampNewFiles(bool Value)
347{
348 if (m_SettingsUI!=0)
349 m_SettingsUI->TimeStampNewFiles(Value);
350 if (m_SettingsStore!=0)
351 m_SettingsStore->SetBoolOption(Keys::TIME_STAMP, Value);
352 if (m_DashEditbox!=0)
353 m_DashEditbox->TimeStampNewFiles(Value);
354}
355
356
357void CDasherInterface::CopyAllOnStop(bool Value)
358{
359 m_CopyAllOnStop = Value;
360 if (m_SettingsUI!=0)
361 m_SettingsUI->CopyAllOnStop(Value);
362 if (m_SettingsStore!=0)
363 m_SettingsStore->SetBoolOption(Keys::COPY_ALL_ON_STOP, Value);
364}
365
366void CDasherInterface::DrawMouse(bool Value)
367{
368 m_DrawMouse = Value;
369 if (m_SettingsUI!=0)
370 m_SettingsUI->DrawMouse(Value);
371 if (m_SettingsStore!=0)
372 m_SettingsStore->SetBoolOption(Keys::DRAW_MOUSE, Value);
373}
374
375void CDasherInterface::StartOnSpace(bool Value)
376{
377 m_StartSpace = Value;
378 if (m_SettingsUI!=0)
379 m_SettingsUI->StartOnSpace(Value);
380 if (m_SettingsStore!=0)
381 m_SettingsStore->SetBoolOption(Keys::START_SPACE, Value);
382}
383
384void CDasherInterface::StartOnLeft(bool Value)
385{
386 m_StartLeft = Value;
387 if (m_SettingsUI!=0)
388 m_SettingsUI->StartOnLeft(Value);
389 if (m_SettingsStore!=0)
390 m_SettingsStore->SetBoolOption(Keys::START_MOUSE, Value);
391}
392
393void CDasherInterface::KeyControl(bool Value)
394{
395 m_KeyControl = Value;
396 if (m_SettingsUI!=0)
397 m_SettingsUI->KeyControl(Value);
398 if (m_SettingsStore!=0)
399 m_SettingsStore->SetBoolOption(Keys::KEY_CONTROL, Value);
400}
401
402void CDasherInterface::WindowPause(bool Value)
403{
404 m_KeyControl = Value;
405 if (m_SettingsUI!=0)
406 m_SettingsUI->WindowPause(Value);
407 if (m_SettingsStore!=0)
408 m_SettingsStore->SetBoolOption(Keys::WINDOW_PAUSE, Value);
409}
410
411void CDasherInterface::SetEditFont(string Name, long Size)
412{
413 m_EditFont = Name;
414 m_EditFontSize = Size;
415 if (m_DashEditbox)
416 m_DashEditbox->SetFont(Name, Size);
417 if (m_SettingsUI!=0)
418 m_SettingsUI->SetEditFont(Name, Size);
419 if (m_SettingsStore!=0) {
420 m_SettingsStore->SetStringOption(Keys::EDIT_FONT, Name);
421 m_SettingsStore->SetLongOption(Keys::EDIT_FONT_SIZE, Size);
422 }
423}
424
425
426void CDasherInterface::SetDasherFont(string Name)
427{
428 if (m_SettingsStore!=0)
429 m_SettingsStore->SetStringOption(Keys::DASHER_FONT, Name);
430 m_DasherFont = Name;
431 if (m_DasherScreen!=0)
432 m_DasherScreen->SetFont(Name);
433 Redraw();
434}
435
436void CDasherInterface::SetDasherFontSize(FontSize fontsize)
437{
438 if (m_SettingsStore!=0)
439 m_SettingsStore->SetLongOption(Keys::DASHER_FONTSIZE, fontsize);
440 if (m_DasherScreen!=0) {
441 m_DasherScreen->SetFontSize(fontsize);
442 }
443 Redraw();
444}
445
446void CDasherInterface::SetDasherDimensions(bool Value)
447{
448 m_Dimensions=Value;
449 if (m_SettingsStore!=0)
450 m_SettingsStore->SetBoolOption(Keys::DASHER_DIMENSIONS, Value);
451 if (m_DasherModel!=0) {
452 m_DasherModel->Set_dimensions(Value);
453 }
454 if (m_SettingsUI!=0) {
455 m_SettingsUI->SetDasherDimensions(Value);
456 }
457}
458
459
460unsigned int CDasherInterface::GetNumberSymbols()
461{
462 if (m_Alphabet!=0)
463 return m_Alphabet->GetNumberSymbols();
464 else
465 return 0;
466}
467
468
469const string& CDasherInterface::GetDisplayText(symbol Symbol)
470{
471 if (m_Alphabet!=0)
472 return m_Alphabet->GetDisplayText(Symbol);
473 else
474 return EmptyString;
475}
476
477
478const string& CDasherInterface::GetEditText(symbol Symbol)
479{
480 if (m_Alphabet!=0)
481 return m_Alphabet->GetText(Symbol);
482 else
483 return EmptyString;
484}
485
486int CDasherInterface::GetTextColour(symbol Symbol)
487{
488 if (m_Alphabet!=0)
489 return m_Alphabet->GetTextColour(Symbol);
490 else
491 return 0;
492}
493
494
495Opts::ScreenOrientations CDasherInterface::GetAlphabetOrientation()
496{
497 return m_Alphabet->GetOrientation();
498}
499
500
501Opts::AlphabetTypes CDasherInterface::GetAlphabetType()
502{
503 return m_Alphabet->GetType();
504}
505
506
507const std::string& CDasherInterface::GetTrainFile()
508{
509 return m_TrainFile;
510}
511
512
513void CDasherInterface::GetAlphabets(std::vector< std::string >* AlphabetList)
514{
515 if (!m_AlphIO)
516 m_AlphIO = new CAlphIO(m_SystemLocation, m_UserLocation);
517 m_AlphIO->GetAlphabets(AlphabetList);
518}
519
520
521const CAlphIO::AlphInfo& CDasherInterface::GetInfo(const std::string& AlphID)
522{
523 if (!m_AlphIO)
524 m_AlphIO = new CAlphIO(m_SystemLocation, m_UserLocation);
525
526 return m_AlphIO->GetInfo(AlphID);
527}
528
529
530void CDasherInterface::SetInfo(const CAlphIO::AlphInfo& NewInfo)
531{
532 if (!m_AlphIO)
533 m_AlphIO = new CAlphIO(m_SystemLocation, m_UserLocation);
534
535 m_AlphIO->SetInfo(NewInfo);
536}
537
538
539void CDasherInterface::DeleteAlphabet(const std::string& AlphID)
540{
541 if (!m_AlphIO)
542 m_AlphIO = new CAlphIO(m_SystemLocation, m_UserLocation);
543
544 m_AlphIO->Delete(AlphID);
545}
546
547
548void CDasherInterface::ChangeEdit()
549{
550 CreateDasherModel();
551 if (m_DasherModel!=0)
552 m_DasherModel->Start();
553 if (m_DasherView!=0)
554 m_DasherView->Render();
555}
556
557
558void CDasherInterface::ChangeEdit(CDashEditbox* NewEdit)
559{
560 m_DashEditbox = NewEdit;
561 m_DashEditbox->SetFont(m_EditFont, m_EditFontSize);
562 m_DashEditbox->SetInterface(this);
563 if (m_SettingsStore!=0)
564 m_DashEditbox->TimeStampNewFiles(m_SettingsStore->GetBoolOption(Keys::TIME_STAMP));
565 m_DashEditbox->New("");
566 ChangeEdit();
567}
568
569
570void CDasherInterface::Train(string* TrainString, bool IsMore)
571{
572 m_LanguageModel->LearnText(TrainContext, TrainString, IsMore);
573 return;
574}
575
576
577/*
578 I've used C style I/O because I found that C++ style I/O bloated
579 the Win32 code enormously. The overhead of loading the buffer into
580 the string instead of reading straight into a string seems to be
581 negligible compared to huge requirements elsewhere.
582*/
583void CDasherInterface::TrainFile(string Filename)
584{
585 if (Filename=="")
586 return;
587
588 FILE* InputFile;
589 if ( (InputFile = fopen(Filename.c_str(), "r")) == (FILE*)0)
590 return;
591
592 const int BufferSize = 1024;
593 char InputBuffer[BufferSize];
594 string StringBuffer;
595 int NumberRead;
596
597 do {
598 NumberRead = fread(InputBuffer, 1, BufferSize-1, InputFile);
599 InputBuffer[NumberRead] = '\0';
600 StringBuffer += InputBuffer;
601 if (NumberRead == (BufferSize-1)) {
602 m_LanguageModel->LearnText(TrainContext, &StringBuffer, true);
603 } else {
604 m_LanguageModel->LearnText(TrainContext, &StringBuffer, false);
605 }
606 } while (NumberRead==BufferSize-1);
607
608 fclose(InputFile);
609}
610
611void CDasherInterface::GetFontSizes(std::vector<int> *FontSizes)
612{
613 FontSizes->push_back(20);
614 FontSizes->push_back(14);
615 FontSizes->push_back(11);
616 FontSizes->push_back(40);
617 FontSizes->push_back(28);
618 FontSizes->push_back(22);
619 FontSizes->push_back(80);
620 FontSizes->push_back(56);
621 FontSizes->push_back(44);
622}
623
624
625double CDasherInterface::GetCurCPM()
626{
627 //
628 return 0;
629}
630
631
632double CDasherInterface::GetCurFPS()
633{
634 //
635 return 0;
636}
diff --git a/inputmethods/dasher/DasherInterface.h b/inputmethods/dasher/DasherInterface.h
new file mode 100644
index 0000000..6338801
--- a/dev/null
+++ b/inputmethods/dasher/DasherInterface.h
@@ -0,0 +1,170 @@
1// DasherInterface.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10
11#ifndef __DasherInterface_h__
12#define __DasherInterface_h__
13
14// TODO - there is a list of things to be configurable in my notes
15// Check that everything that is not self-contained within the GUI is covered.
16
17#include "MSVC_Unannoy.h"
18#include "NoClones.h"
19
20#include "DasherWidgetInterface.h"
21#include "DasherAppInterface.h"
22#include "DasherSettingsInterface.h"
23
24#include "DasherScreen.h"
25#include "Alphabet.h"
26#include "AlphIO.h"
27#include "LanguageModel.h"
28#include "DasherModel.h"
29#include "DashEdit.h"
30#include "DasherView.h"
31
32#include "MSVC_Unannoy.h"
33#include <map>
34
35namespace Dasher {class CDasherInterface;}
36class Dasher::CDasherInterface : private NoClones,
37 public CDasherWidgetInterface, public CDasherAppInterface, public CDasherSettingsInterface
38{
39public:
40 CDasherInterface();
41 ~CDasherInterface();
42
43 //! Tell the core which CSettingsStore should be used
44 void SetSettingsStore(CSettingsStore* SettingsStore);
45
46 //! Tell the core which CDasherSettingsInterface should be used
47 //
48 //! Provide a pointer to an instance of CDasherSettingsInterface in
49 //! order to allow for platform dependent configuration of certain
50 //! options
51 void SetSettingsUI(CDasherSettingsInterface* SettingsUI);
52
53 //! Set the path for user specific configuration and files
54 void SetUserLocation(std::string UserLocation);
55
56 //! Set the path for system-wide configuration and files
57 void SetSystemLocation(std::string SystemLocation);
58
59 // Widget Interface
60 // -----------------------------------------------------
61 void Start();
62
63 void TapOn(int MouseX, int MouseY, unsigned long Time); // Times in milliseconds
64 void PauseAt(int MouseX, int MouseY); // are required to make
65 void Unpause(unsigned long Time); // Dasher run at the
66 void Redraw(); // correct speed.
67
68 void ChangeScreen(); // The widgets need to tell the engine when they have been
69 void ChangeEdit(); // affected by external interaction
70
71 unsigned int GetNumberSymbols(); // These are needed so widgets know
72 const std::string& GetDisplayText(symbol Symbol); // how to render the alphabet. All
73 const std::string& GetEditText(symbol Symbol); // strings are encoded in UTF-8
74 int GetTextColour(symbol Symbol); // the foreground colour of the text
75 Opts::ScreenOrientations GetAlphabetOrientation();
76 Opts::AlphabetTypes GetAlphabetType();
77 const std::string& GetTrainFile();
78
79 // App Interface
80 // -----------------------------------------------------
81
82 // std::map<int, std::string>& GetAlphabets(); // map<key, value> int is a UID string can change. Store UID in preferences. Display string to user.
83 // std::vector<std::string>& GetAlphabets();
84 // std::vector<std::string>& GetLangModels();
85 // std::vector<std::string>& GetViews();
86
87 void ChangeScreen(CDasherScreen* NewScreen); // We may change the widgets Dasher uses
88 void ChangeEdit(CDashEditbox* NewEdit); // at run time.
89
90 void Train(std::string* TrainString, bool IsMore); // Training by string segments or file
91 void TrainFile(std::string Filename); // all training data must be in UTF-8.
92
93 void GetFontSizes(std::vector<int> *FontSizes);
94
95 double GetCurCPM(); // App may want to display characters per minute
96 double GetCurFPS(); // or frames per second.
97
98 // Customize alphabet
99 void GetAlphabets(std::vector< std::string >* AlphabetList);
100 const CAlphIO::AlphInfo& GetInfo(const std::string& AlphID);
101 void SetInfo(const CAlphIO::AlphInfo& NewInfo);
102 void DeleteAlphabet(const std::string& AlphID);
103
104 // Settings Interface (options saved between sessions)
105 // -----------------------------------------------------
106
107 void ChangeAlphabet(const std::string& NewAlphabetID);
108 void ChangeMaxBitRate(double NewMaxBitRate);
109 void ChangeLanguageModel(unsigned int NewLanguageModelID);
110 void ChangeView(unsigned int NewViewID);
111 void ChangeOrientation(Opts::ScreenOrientations Orientation);
112 void SetFileEncoding(Opts::FileEncodingFormats Encoding);
113 // TODO Color customization.
114
115 void ShowToolbar(bool Value);
116 void ShowToolbarText(bool Value);
117 void ShowToolbarLargeIcons(bool Value);
118 void ShowSpeedSlider(bool Value);
119 void FixLayout(bool Value);
120 void TimeStampNewFiles(bool Value);
121 void CopyAllOnStop(bool Value);
122 void DrawMouse(bool Value);
123 void StartOnSpace(bool Value);
124 void StartOnLeft(bool Value);
125 void KeyControl(bool Value);
126 void WindowPause(bool Value);
127 void SetEditFont(std::string Name, long Size);
128 void SetDasherFont(std::string Name);
129 void SetDasherFontSize(FontSize fontsize);
130 void SetDasherDimensions(bool Value);
131
132private:
133 CAlphabet* m_Alphabet;
134 CLanguageModel* m_LanguageModel;
135 CDasherModel* m_DasherModel;
136 CDashEditbox* m_DashEditbox;
137 CDasherScreen* m_DasherScreen;
138 CDasherView* m_DasherView;
139 CSettingsStore* m_SettingsStore;
140 CDasherSettingsInterface* m_SettingsUI;
141 CAlphIO* m_AlphIO;
142
143 CLanguageModel::CNodeContext* TrainContext;
144
145 std::string AlphabetID;
146 int LanguageModelID;
147 int ViewID;
148 double m_MaxBitRate;
149 bool m_CopyAllOnStop;
150 bool m_DrawMouse;
151 bool m_DrawKeyboard;
152 bool m_StartSpace;
153 bool m_StartLeft;
154 bool m_KeyControl;
155 bool m_Dimensions;
156 bool m_WindowPause;
157 Opts::ScreenOrientations m_Orientation;
158 std::string m_UserLocation;
159 std::string m_SystemLocation;
160 std::string m_TrainFile;
161 std::string m_DasherFont;
162 std::string m_EditFont;
163 int m_EditFontSize;
164 static const std::string EmptyString;
165
166 void CreateDasherModel();
167};
168
169
170#endif /* #ifndef __DasherInterface_h__ */
diff --git a/inputmethods/dasher/DasherModel.cpp b/inputmethods/dasher/DasherModel.cpp
new file mode 100644
index 0000000..0450d66
--- a/dev/null
+++ b/inputmethods/dasher/DasherModel.cpp
@@ -0,0 +1,322 @@
1// DasherModel.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include <iostream>
10#include "DasherModel.h"
11
12using namespace Dasher;
13using namespace std;
14
15//////////////////////////////////////////////////////////////////////
16// CDasherModel
17//////////////////////////////////////////////////////////////////////
18
19CDasherModel::CDasherModel(CDashEditbox* Editbox, CLanguageModel* LanguageModel, bool Dimensions)
20 : m_editbox(Editbox), m_languagemodel(LanguageModel), m_Root(0), m_Dimensions(Dimensions)
21{
22 LearnContext = m_languagemodel->GetRootNodeContext();
23
24 // various settings
25 int iShift = 12;
26 m_DasherY = 1<<iShift;
27 m_DasherOY = m_DasherY/2;
28 m_DasherOX = m_DasherY/2;
29 m_dAddProb = 0.003;
30}
31
32
33CDasherModel::~CDasherModel()
34{
35 m_languagemodel->ReleaseNodeContext(LearnContext);
36 delete m_Root; // which will also delete all the whole structure
37}
38
39
40void CDasherModel::Make_root(int whichchild)
41 // find a new root node
42{
43 symbol t=m_Root->Symbol();
44 if (t) {
45 m_editbox->output(t);
46 m_languagemodel->LearnNodeSymbol(LearnContext, t);
47 }
48
49 CDasherNode * oldroot=m_Root;
50
51 CDasherNode **children=m_Root->Children();
52 m_Root=children[whichchild];
53 //oldroot->Children()[whichchild]=0; // null the pointer so we don't delete the whole tree
54 //delete oldroot;
55
56 oldroots.push_back(oldroot);
57
58 myint range=m_Rootmax-m_Rootmin;
59 m_Rootmax=m_Rootmin+(range*m_Root->Hbnd())/Normalization();
60 m_Rootmin+=(range*m_Root->Lbnd())/Normalization();
61}
62
63void CDasherModel::Reparent_root(int lower, int upper)
64{
65 /* Change the root node to the parent of the existing node
66 We need to recalculate the coordinates for the "new" root as the
67 user may have moved around within the current root */
68
69 /* Determine how zoomed in we are */
70 float scalefactor=(m_Rootmax-m_Rootmin)/(upper-lower);
71
72 m_Rootmax=int(m_Rootmax+((1024-upper)*scalefactor));
73 m_Rootmin=int(m_Rootmin-(lower*scalefactor));
74
75 m_editbox->deletetext();
76
77 m_Root=oldroots.back();
78 oldroots.pop_back();
79}
80
81/////////////////////////////////////////////////////////////////////////////
82
83CDasherNode * CDasherModel::Get_node_under_crosshair()
84{
85 return m_Root->Get_node_under(Normalization(),m_Rootmin,m_Rootmax,m_DasherOX,m_DasherOY);
86}
87
88/////////////////////////////////////////////////////////////////////////////
89
90
91CDasherNode * CDasherModel::Get_node_under_mouse(myint Mousex,myint Mousey)
92{
93 return m_Root->Get_node_under(Normalization(),m_Rootmin,m_Rootmax,Mousex,Mousey);
94}
95
96/////////////////////////////////////////////////////////////////////////////
97
98
99void CDasherModel::Get_string_under_mouse(const myint Mousex,const myint Mousey, vector<symbol> &str)
100{
101 m_Root->Get_string_under(Normalization(),m_Rootmin,m_Rootmax,Mousex,Mousey,str);
102 return;
103}
104
105/////////////////////////////////////////////////////////////////////////////
106
107
108void CDasherModel::Flush(const myint Mousex,const myint Mousey)
109{
110 vector<symbol> vtUnder;
111 Get_string_under_mouse(m_DasherOX,m_DasherOY,vtUnder);
112 unsigned int i;
113 for (i=0;i<vtUnder.size();i++) {
114 if (vtUnder[i]==0)
115 continue;
116 m_editbox->flush(vtUnder[i]);
117 }
118}
119
120/////////////////////////////////////////////////////////////////////////////
121
122void CDasherModel::Update(CDasherNode *node,CDasherNode *under_mouse,int iSafe)
123// go through the Dasher nodes, delete ones who have expired
124// decrease the time left for nodes which arent safe
125// safe nodes are those which are under the mouse or offspring of this node
126{
127 //if (node->pushme )
128 // node->push_node();
129 if (node==under_mouse)
130 iSafe=1;
131 if (!iSafe)
132 node->Age();
133 //dchar debug[256];
134 //wsprintf(debug,TEXT("node->Age %d %f\n"),node->Age, fr.framerate());
135 //OutputDebugString(debug);
136
137
138 if (node->Age() > Framerate())
139 node->Kill();
140
141
142 if (node->Alive()) {
143 CDasherNode **children=node->Children();
144 if (children) {
145 unsigned int i;
146 for (i=1;i<node->Chars();i++)
147 Update(children[i],under_mouse,iSafe);
148 }
149 }
150 return;
151}
152
153/////////////////////////////////////////////////////////////////////////////
154
155void CDasherModel::Start()
156{
157 m_Rootmin=0;
158 m_Rootmax=m_DasherY;
159
160 delete m_Root;
161 CLanguageModel::CNodeContext* therootcontext=m_languagemodel->GetRootNodeContext();
162
163 //Rootparent=new DasherNode(0,0,0,therootcontext,0,0,0,Normalization(),languagemodel);
164 if (m_editbox) {
165 m_editbox->set_flushed(0);
166 string ContextString;
167 m_editbox->get_new_context(ContextString,5);
168 if (ContextString.size() != 0) {
169 m_languagemodel->EnterText(therootcontext, ContextString);
170 }
171 m_languagemodel->ReleaseNodeContext(LearnContext);
172 LearnContext = m_languagemodel->CloneNodeContext(therootcontext);
173 }
174 m_Root=new CDasherNode(0,0,0,0,Opts::Nodes1,0,Normalization(),m_languagemodel);
175 m_Root->Push_Node(therootcontext);
176
177 m_languagemodel->ReleaseNodeContext(therootcontext);
178 //ppmmodel->dump();
179 //dump();
180
181}
182
183/////////////////////////////////////////////////////////////////////////////
184
185void CDasherModel::Get_new_root_coords(myint Mousex,myint Mousey)
186{
187 int cappedrate=0;
188 double dRx=1.0,dRxnew=1.0;
189 double dRxnew2;
190
191 int iSteps=m_fr.Steps();
192
193 if (Mousex<m_DasherOX) {
194 //rx=1.0001*Ixmap[mx]/Ixmap[cx];
195 if (Mousex<=0)
196 Mousex=1;
197 dRx=1.0*m_DasherOX/Mousex;
198 dRxnew=pow(dRx,1.0/iSteps); // or exp(log(rx)/steps) - i think the replacement is faster
199
200 dRxnew2=1+(dRx-1)/iSteps;
201 //+(rx-1)*(rx-1)*(1.0/fr.steps()-1.0)/2/fr.steps();
202
203
204 const double dRxmax=m_fr.Rxmax();
205 if (dRxnew>dRxmax)
206 dRxnew=dRxmax;
207 // cappedrate=1;
208 } else {
209 if (Mousex==m_DasherOX)
210 Mousex++;
211 // OutputDebugString(TEXT("zoom out\n"));
212 dRx=1.0001*m_DasherOX/Mousex;
213 dRxnew=exp(log(dRx)/iSteps);
214 //get_coords(root->lbnd,root->hbnd,&x1,&y1,&y2);
215 //if (x1>0 || y1>0 || y2<CanvasY)
216 //go_back_a_char();
217 if (m_Rootmax<m_DasherY && m_Rootmin>0)
218 return;
219 }
220 //dchar debug[256];
221 //_stprintf(debug,TEXT("rx %f rxnew %f approx %f\n"),rx,rxnew,rxnew2);
222 //OutputDebugString(debug);
223 //wsprintf(debug,TEXT("rx %f rxnew %f\n"),rx,rxnew);
224 //OutputDebugString(debug);
225 myint above=(Mousey-m_Rootmin);//*(1-rxnew)/(1-rx);
226 myint below=(m_Rootmax-Mousey);//*(1-rxnew)/(1-rx);
227
228 //wsprintf(debug,TEXT("above %I64d below %I64d \n"),above,below);
229 //OutputDebugString(debug);
230
231 myint miDistance=m_DasherY/2-Mousey;
232 miDistance=myint(miDistance*(dRxnew-1)/(dRx-1));
233 myint miNewrootzoom=Mousey+miDistance;
234
235 myint newRootmax=miNewrootzoom+myint(below*dRxnew);
236 myint newRootmin=miNewrootzoom-myint(above*dRxnew);
237 if (newRootmin<m_DasherY/2 && newRootmax>m_DasherY/2 && newRootmax<LLONG_MAX && newRootmin>LLONG_MIN) {
238 m_Rootmax=newRootmax;
239 m_Rootmin=newRootmin;
240 }
241
242}
243
244/////////////////////////////////////////////////////////////////////////////
245
246void CDasherModel::Tap_on_display(myint miMousex,myint miMousey, unsigned long Time)
247 // work out the next viewpoint, opens some new nodes
248{
249 // works out next viewpoint
250 Get_new_root_coords(miMousex,miMousey);
251
252 // opens up new nodes
253
254 // push node under mouse
255 CDasherNode *under_mouse=Get_node_under_mouse(miMousex,miMousey);
256 under_mouse->Push_Node();
257
258
259 if (Framerate() > 4) {
260 // push node under mouse but with x coord on RHS
261 CDasherNode *right=Get_node_under_mouse(50,miMousey);
262 right->Push_Node();
263 }
264
265 if (Framerate() > 8) {
266 // push node under the crosshair
267 CDasherNode *under_cross=Get_node_under_crosshair();
268 under_cross->Push_Node();
269 }
270
271 unsigned int iRandom;
272#if defined(_WIN32_WCE)
273 iRandom=Random();
274#else
275 iRandom=rand();
276#endif
277 if (Framerate() > 8) {
278 // add some noise and push another node
279 CDasherNode *right=Get_node_under_mouse(50,miMousey+iRandom%500-250);
280 right->Push_Node();
281 }
282#if defined(_WIN32_WCE)
283 iRandom=Random();
284#else
285 iRandom=rand();
286#endif
287 if (Framerate() > 15) {
288 // add some noise and push another node
289 CDasherNode *right=Get_node_under_mouse(50,miMousey+iRandom%500-250);
290 right->Push_Node();
291 }
292
293 // only do this is Dasher is flying
294 if (Framerate() > 30) {
295 for (int i=1;i<int(Framerate()-30)/3;i++) {
296 #if defined(_WIN32_WCE)
297 iRandom=Random();
298#else
299 iRandom=rand();
300#endif
301 // push at a random node on the RHS
302 CDasherNode *right=Get_node_under_mouse(50,miMousey+iRandom%1000-500);
303 right->Push_Node();
304
305 }
306 }
307 Update(m_Root,under_mouse,0);
308
309
310}
311
312/////////////////////////////////////////////////////////////////////////////
313
314void CDasherModel::Dump() const
315 // diagnostic dump
316{
317 // OutputDebugString(TEXT(" ptr symbol context Next Child pushme pushed cscheme lbnd hbnd \n"));
318 m_Root->Dump_node();
319}
320
321
322
diff --git a/inputmethods/dasher/DasherModel.h b/inputmethods/dasher/DasherModel.h
new file mode 100644
index 0000000..348900f
--- a/dev/null
+++ b/inputmethods/dasher/DasherModel.h
@@ -0,0 +1,111 @@
1// DasherModel.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __DasherModel_h__
10#define __DasherModel_h__
11
12#include <iostream>
13#include "MSVC_Unannoy.h"
14#include "DashEdit.h"
15#include "DasherNode.h"
16#include "LanguageModel.h"
17#include "NoClones.h"
18#include <math.h>
19#include "DasherTypes.h"
20#include "FrameRate.h"
21#include <vector>
22
23// The CDasherModel represents the current state of Dasher
24// It contains a pointer to a structure of DasherNodes
25// The knows the current viewpoint
26// It also knows how to evolve the viewpoint
27
28namespace Dasher {class CDasherModel;}
29class Dasher::CDasherModel : private NoClones
30{
31public:
32
33 CDasherModel(CDashEditbox* Editbox, CLanguageModel* LanguageModel, bool Dimensions);
34 ~CDasherModel();
35
36 // framerate functions
37 void NewFrame(unsigned long Time) {m_fr.NewFrame(Time);} // called everytime we render a new frame
38 const double Framerate () {return m_fr.Framerate();} // return the framerate
39
40 // User control of speed
41 void SetBitrate(double TargetRate) {m_fr.SetBitrate(TargetRate);} // Use or start at this bitrate
42 void SetMaxBitrate(double MaxRate) {m_fr.SetMaxBitrate(MaxRate);} // Cap any adaption at this rate
43
44 // functions returning private data (read only access)
45 const myint Rootmin() const {return m_Rootmin;}
46 const myint Rootmax() const {return m_Rootmax;}
47 const myint DasherOX() const {return m_DasherOX;}
48 CDasherNode* Root() const {return m_Root;}
49 int Normalization() const {return m_languagemodel->normalization();}
50 myint DasherY() const {return m_DasherY;}
51 bool Dimensions() const {return m_Dimensions;}
52
53 void Dump() const; // diagnostics
54 void Flush(const myint smousex,const myint smousey); // flush to the edit control
55 //void Learn_symbol(symbol Symbol) {m_languagemodel->learn_symbol(Symbol);} // feed character to language model
56
57 void Set_dimensions(bool dimensions) {m_Dimensions=dimensions;}
58
59 void Tap_on_display(myint,myint, unsigned long Time); // evolves the current viewpoint
60 void Start(); // initializes the data structure
61 void Make_root(int whichchild); // find a new root node
62 void Reparent_root(int lower, int upper); // change back to the previous root
63 void Reset_framerate(unsigned long Time) {m_fr.Reset(Time);}
64
65 CAlphabet* m_alphabet; // pointer to the alphabet
66
67 CAlphabet* GetAlphabet() { return m_alphabet; }
68private:
69
70 // Old root notes
71 std::vector<CDasherNode*> oldroots;
72
73 // Rootmin and Rootmax specify the position of the root node in Dasher coords
74 myint m_Rootmin,m_Rootmax;
75
76 // Size of Dasher's arithmetic coding interval - it defines the Dasher coordinate system
77 myint m_DasherY;
78
79 // x position of crosshair in Dasher coords - distance from RHS is square Dasher
80 myint m_DasherOX;
81
82 // y position of crosshair in Dasher coords - distance from top in square Dasher
83 myint m_DasherOY;
84
85 // Number of input dimensions
86 bool m_Dimensions;
87
88 CDashEditbox* m_editbox; // pointer to the editbox
89 CLanguageModel* m_languagemodel; // pointer to the language model
90 CLanguageModel::CNodeContext* LearnContext; // Used to add data to model as it is entered
91 CFrameRate m_fr; // keep track of framerate
92
93 // TODO - move somewhere
94 // the probability that gets added to every symbol
95 double m_dAddProb;
96
97 CDasherNode* Get_node_under_mouse(myint smousex,myint smousey);
98 CDasherNode* Get_node_under_crosshair();
99 CDasherNode* m_Root;
100 void Get_new_root_coords(myint mousex,myint mousey);
101 void Get_string_under_mouse(const myint smousex,const myint smousey,std::vector<symbol> &str);
102 void Update(CDasherNode* node,CDasherNode* under,int safe);
103
104
105
106
107
108};
109
110
111#endif /* #ifndef __DasherModel_h__ */
diff --git a/inputmethods/dasher/DasherNode.cpp b/inputmethods/dasher/DasherNode.cpp
new file mode 100644
index 0000000..26af10f
--- a/dev/null
+++ b/inputmethods/dasher/DasherNode.cpp
@@ -0,0 +1,167 @@
1// DasherNode.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include "DasherNode.h"
10using namespace Dasher;
11using namespace Opts;
12using namespace std;
13
14/////////////////////////////////////////////////////////////////////////////
15
16void CDasherNode::Dump_node () const
17 {
18 /* TODO sort out
19 dchar out[256];
20 if (m_Symbol)
21 wsprintf(out,TEXT("%7x %3c %7x %5d %7x %5d %8x %8x \n"),this,m_Symbol,m_iGroup,m_context,m_Children,m_Cscheme,m_iLbnd,m_iHbnd);
22 else
23 wsprintf(out,TEXT("%7x %7x %5d %7x %5d %8x %8x \n"),this,m_iGroup,m_context,m_Children,m_Cscheme,m_iLbnd,m_iHbnd);
24
25 OutputDebugString(out);
26
27 if (m_Children) {
28 unsigned int i;
29 for (i=1;i<m_iChars;i++)
30 m_Children[i]->Dump_node();
31 }
32 */
33}
34
35void CDasherNode::Generic_Push_Node(CLanguageModel::CNodeContext *context) {
36
37 m_iAge=0;
38 m_bAlive=true;
39 if (m_Symbol && !m_iChars) // make sure it's a valid symbol and don't enter if already done
40 m_languagemodel->EnterNodeSymbol(m_context,m_Symbol);
41
42
43 vector<symbol> newchars; // place to put this list of characters
44 vector<unsigned int> cum,groups; // for the probability list
45 m_languagemodel->GetNodeProbs(m_context,newchars,groups,cum,0.003);
46 m_iChars=newchars.size();
47 // work out cumulative probs
48 unsigned int i;
49 for (i=1;i<m_iChars;i++)
50 cum[i]+=cum[i-1];
51
52 m_Children =new CDasherNode *[m_iChars];
53
54 // create the children
55 ColorSchemes NormalScheme, SpecialScheme;
56 if ((m_ColorScheme==Nodes1) || (m_ColorScheme==Special1)) {
57 NormalScheme = Nodes2;
58 SpecialScheme = Special2;
59 } else {
60 NormalScheme = Nodes1;
61 SpecialScheme = Special1;
62 }
63
64 ColorSchemes ChildScheme;
65 for (i=1;i<m_iChars;i++) {
66 if (newchars[i]==this->m_languagemodel->GetSpaceSymbol())
67 ChildScheme = SpecialScheme;
68 else
69 ChildScheme = NormalScheme;
70 m_Children[i]=new CDasherNode(this,newchars[i],groups[i],i,ChildScheme,cum[i-1],cum[i],m_languagemodel,m_languagemodel->GetColour(i));
71 }
72}
73
74/////////////////////////////////////////////////////////////////////////////
75
76void CDasherNode::Push_Node(CLanguageModel::CNodeContext *context)
77// push a node copying the specified context
78{
79
80 if (m_Children) {
81 // if there are children just give them a poke
82 unsigned int i;
83 for (i=1;i<m_iChars;i++) {
84 m_Children[i]->m_iAge=0;
85 m_Children[i]->m_bAlive=1;
86 }
87 return;
88 }
89
90 // if we haven't got a context then try to get a new one
91 m_context=m_languagemodel->CloneNodeContext(context);
92 // if it fails, be patient
93 if (!m_context)
94 return;
95 Generic_Push_Node(m_context);
96}
97
98/////////////////////////////////////////////////////////////////////////////
99
100void CDasherNode::Push_Node()
101{
102
103 if (m_Children) {
104 // if there are children just give them a poke
105 unsigned int i;
106 for (i=1;i<m_iChars;i++) {
107 m_Children[i]->m_iAge=0;
108 m_Children[i]->m_bAlive=1;
109 }
110 return;
111 }
112
113 // if we haven't got a context then try to get a new one
114 if (m_parent)
115 m_context=m_languagemodel->CloneNodeContext(m_parent->m_context);
116 else
117 m_context=m_languagemodel->GetRootNodeContext();
118
119 // if it fails, be patient
120 if (!m_context)
121 return;
122 Generic_Push_Node(m_context);
123}
124
125/////////////////////////////////////////////////////////////////////////////
126
127void CDasherNode::Get_string_under(const int iNormalization,const myint miY1,const myint miY2,const myint miMousex,const myint miMousey, vector<symbol> &vString) const
128{
129 // we are over (*this) node so add it to the string
130 vString.push_back(m_Symbol);
131
132 // look for children who might also be under the coords
133 if (m_Children) {
134 myint miRange=miY2-miY1;
135 unsigned int i;
136 for (i=1;i<m_iChars;i++) {
137 myint miNewy1=miY1+(miRange*m_Children[i]->m_iLbnd)/iNormalization;
138 myint miNewy2=miY1+(miRange*m_Children[i]->m_iHbnd)/iNormalization;
139 if (miMousey<miNewy2 && miMousey>miNewy1 && miMousex<miNewy2-miNewy1) {
140 m_Children[i]->Get_string_under(iNormalization,miNewy1,miNewy2,miMousex,miMousey,vString);
141 return;
142 }
143 }
144 }
145 return;
146}
147
148/////////////////////////////////////////////////////////////////////////////
149
150CDasherNode * const CDasherNode::Get_node_under(int iNormalization,myint miY1,myint miY2,myint miMousex,myint miMousey)
151{
152 if (m_Children) {
153 myint miRange=miY2-miY1;
154 m_iAge=0;
155 m_bAlive=true;
156 unsigned int i;
157 for (i=1;i<m_iChars;i++) {
158 myint miNewy1=miY1+(miRange*m_Children[i]->m_iLbnd)/iNormalization;
159 myint miNewy2=miY1+(miRange*m_Children[i]->m_iHbnd)/iNormalization;
160 if (miMousey<miNewy2 && miMousey>miNewy1 && miMousex<miNewy2-miNewy1)
161 return m_Children[i]->Get_node_under(iNormalization,miNewy1,miNewy2,miMousex,miMousey);
162 }
163 }
164 return this;
165}
166
167/////////////////////////////////////////////////////////////////////////////
diff --git a/inputmethods/dasher/DasherNode.h b/inputmethods/dasher/DasherNode.h
new file mode 100644
index 0000000..705a9d4
--- a/dev/null
+++ b/inputmethods/dasher/DasherNode.h
@@ -0,0 +1,127 @@
1// DasherNode.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __DasherNode_h__
10#define __DasherNode_h__
11
12#include "NoClones.h"
13#include "DasherTypes.h"
14#include "LanguageModel.h"
15
16namespace Dasher {class CDasherNode;}
17class Dasher::CDasherNode : private NoClones
18{
19 // CDasherNode represents a rectangle and character
20 // nodes have children, siblings and parents
21private:
22 const unsigned int m_iLbnd,m_iHbnd;// the cumulative lower and upper bound prob relative to parent
23 const unsigned int m_iGroup; // group membership - e.g. 0=nothing 1=caps 2=punc
24 unsigned int m_iChars, m_iAge;
25 bool m_bAlive; // if true, then display node, else dont bother
26 bool m_bControlNode; // if true, node is a control node
27 bool m_bControlChild; // if true, node is offspring of a control node
28 //bool m_Cscheme; // color scheme for the node - alternates through relatives
29 Opts::ColorSchemes m_ColorScheme;
30 int m_iPhase; // index for coloring
31 int m_iColour; // for the advanced colour mode
32
33 const symbol m_Symbol; // the character to display
34 CLanguageModel *m_languagemodel; // pointer to the language model - in future, could be different for each node
35 CDasherNode **m_Children; // pointer to array of children
36 CDasherNode *m_parent; // pointer to parent - only needed to grab parent context
37 CLanguageModel::CNodeContext *m_context;
38public:
39
40 CDasherNode(CDasherNode *parent,symbol Symbol, unsigned int igroup, int iphase, Opts::ColorSchemes ColorScheme,int ilbnd,int ihbnd,CLanguageModel *lm, int Colour);
41 ~CDasherNode();
42 bool m_bForce; // flag to force a node to be drawn - shouldn't be public
43
44 // return private data members - read only
45 CDasherNode ** const Children() const {return m_Children;}
46 unsigned int Lbnd() const {return m_iLbnd;}
47 bool Alive() {return m_bAlive;}
48 bool Control() {return m_bControlChild;}
49 void Kill() {m_bAlive=0;m_iAge=0;}
50 unsigned int Hbnd() const {return m_iHbnd;}
51 unsigned int Group() const {return m_iGroup;}
52 unsigned int Age() const {return m_iAge;}
53 symbol Symbol() const {return m_Symbol;}
54 unsigned int Chars() const {return m_iChars;}
55 int Phase() const {return m_iPhase;}
56 Opts::ColorSchemes Cscheme() const {return m_ColorScheme;}
57 int Colour() const {return m_iColour;}
58
59 CDasherNode* const Get_node_under(int,myint y1,myint y2,myint smousex,myint smousey); // find node under given co-ords
60 void Get_string_under(const int,const myint y1,const myint y2,const myint smousex,const myint smousey,std::vector<symbol>&) const; // get string under given co-ords
61 void Generic_Push_Node(CLanguageModel::CNodeContext *context);
62 void Push_Node(); // give birth to children
63 void Push_Node(CLanguageModel::CNodeContext *context); // give birth to children with this context
64 void Delete_children();
65 void Dump_node() const; // diagnostic
66};
67
68/////////////////////////////////////////////////////////////////////////////
69// Inline functions
70/////////////////////////////////////////////////////////////////////////////
71
72using namespace Dasher;
73using namespace Opts;
74
75/////////////////////////////////////////////////////////////////////////////
76
77inline CDasherNode::CDasherNode(CDasherNode *parent,symbol Symbol, unsigned int igroup, int iphase, ColorSchemes ColorScheme,int ilbnd,int ihbnd,CLanguageModel *lm, int Colour=0)
78 : m_parent(parent),m_Symbol(Symbol),m_iGroup(igroup),m_iLbnd(ilbnd),m_iHbnd(ihbnd),m_languagemodel(lm),m_iPhase(iphase),
79 m_context(0), m_iAge(0), m_bAlive(1), m_Children(0), m_bForce(false), m_iChars(0), m_ColorScheme(ColorScheme), m_bControlChild(false), m_iColour(Colour)
80{
81 /*
82 switch (ColorScheme) {
83 case Nodes1:
84 m_ColorScheme = Nodes2;
85 break;
86 case Nodes2:
87 m_ColorScheme = Nodes1;
88 break;
89 case Special1:
90 m_ColorScheme = Special2;
91 break;
92 case Special2:
93 m_ColorScheme = Special1;
94 break;
95 case default:
96 m_ColorScheme = ColorScheme;
97 break;
98 }
99 */
100}
101
102/////////////////////////////////////////////////////////////////////////////
103
104inline void CDasherNode::Delete_children()
105{
106 if (m_Children) {
107 unsigned int i;
108 for (i=1;i<m_iChars;i++)
109 delete m_Children[i];
110 delete [] m_Children;
111 }
112 m_Children=0;
113
114}
115
116/////////////////////////////////////////////////////////////////////////////
117
118inline CDasherNode::~CDasherNode()
119{
120 Delete_children();
121 if (m_context)
122 m_languagemodel->ReleaseNodeContext(m_context);
123}
124
125/////////////////////////////////////////////////////////////////////////////
126
127#endif /* #ifndef __DasherNode_h__ */
diff --git a/inputmethods/dasher/DasherScreen.h b/inputmethods/dasher/DasherScreen.h
new file mode 100644
index 0000000..36ca780
--- a/dev/null
+++ b/inputmethods/dasher/DasherScreen.h
@@ -0,0 +1,102 @@
1//! Class definition for the Dasher screen
2// DasherScreen.h
3//
4/////////////////////////////////////////////////////////////////////////////
5//
6// Copyright (c) 2001-2002 David Ward
7//
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef __DasherScreen_h_
11#define __DasherScreen_h_
12
13#include "DasherWidgetInterface.h"
14#include "DasherTypes.h"
15
16namespace Dasher {class CDasherScreen;}
17class Dasher::CDasherScreen
18{
19public:
20 //! \param width Width of the screen
21 //! \param height Height of the screen
22 CDasherScreen(int width,int height)
23 : m_iWidth(width), m_iHeight(height) {}
24
25 //! Set the widget interface used for communication with the core
26 virtual void SetInterface(CDasherWidgetInterface* DasherInterface) {m_DasherInterface = DasherInterface;}
27
28 //! Return the width of the screen
29 int GetWidth() const { return m_iWidth; }
30
31 //! Return the height of the screen
32 int GetHeight() const { return m_iHeight; }
33
34 //! Structure defining a point on the screen
35 typedef struct tagpoint { int x; int y; } point;
36
37 //! Set the Dasher font (ie, the screen font) to Name
38 //!
39 //! This is the font used to render letters in the main screen
40 virtual void SetFont(std::string Name)=0;
41
42 //! Set the Dasher font to Normal, Big or VBig
43 virtual void SetFontSize(Dasher::Opts::FontSize fontsize)=0;
44
45 //! Return the Dasher font size
46 virtual Dasher::Opts::FontSize GetFontSize()=0;
47
48 // DasherView asks for the width and height of the given symbol at a requested height,
49 // then it is able to sensibly specify the upper left corner in DrawText.
50 //! Set Width and Height to those of the character Character at size Size
51 virtual void TextSize(symbol Character, int* Width, int* Height, int Size) const=0;
52 //! Draw character Character of size Size positioned at x1 and y1
53 virtual void DrawText(symbol Character, int x1, int y1, int Size) const=0;
54
55
56 // Draw a filled rectangle - given position and color id
57 //! Draw a filled rectangle
58 //
59 //! Draw a coloured rectangle on the screen
60 //! \param x1 top left of rectangle (x coordinate)
61 //! \param y1 top left corner of rectangle (y coordinate)
62 //! \param x2 bottom right of rectangle (x coordinate)
63 //! \param y2 bottom right of rectangle (y coordinate)
64 //! \param Color the colour to be used (numeric)
65 //! \param ColorScheme Which colourscheme is to be used
66 virtual void DrawRectangle(int x1, int y1, int x2, int y2, int Color, Opts::ColorSchemes ColorScheme) const=0;
67
68 // Draw a line of fixed colour (usually black). Intended for static UI elements such as a cross-hair
69 //! Draw a line between each of the points in the array
70 //
71 //! \param Number the number of points in the array
72 virtual void Polyline(point* Points, int Number) const=0;
73
74 // Draw a filled polygon - given vertices and color id
75 // This is not (currently) used in standard Dasher. However, it could be very
76 // useful in the future. Please implement unless it will be very difficult,
77 // in which case make this function call Polyline.
78 //! Draw a filled polygon
79 //
80 //! \param Points array of points defining the edge of the polygon
81 //! \param Number number of points in the array
82 //! \param Color colour of the polygon (numeric)
83 //! \param Colorscheme Which colourscheme is to be used
84 virtual void DrawPolygon(point* Points, int Number, int Color, Opts::ColorSchemes ColorScheme) const=0;
85
86 // Signal the screen when a frame is started and finished
87 //! Signal that a frame is being started
88 virtual void Blank() const=0;
89
90 //! Signal that a frame is finished - the screen should be updated
91 virtual void Display()=0;
92
93protected:
94 //! Width and height of the screen
95 const int m_iWidth, m_iHeight;
96
97 //! Pointer to a widget interface for communication with the core
98 CDasherWidgetInterface* m_DasherInterface;
99};
100
101
102#endif /* #ifndef __DasherScreen_h_ */
diff --git a/inputmethods/dasher/DasherSettingsInterface.cpp b/inputmethods/dasher/DasherSettingsInterface.cpp
new file mode 100644
index 0000000..6e7f7da
--- a/dev/null
+++ b/inputmethods/dasher/DasherSettingsInterface.cpp
@@ -0,0 +1,126 @@
1// DasherSettingsInterface.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include <iostream>
10
11#include "DasherSettingsInterface.h"
12
13namespace Dasher{
14namespace Keys {
15 // Standard Option strings. You are encouraged to use these constants.
16 // -------------------------------------------------------------------
17
18 // bool options
19 const std::string TIME_STAMP = "TimeStampNewFiles";
20 const std::string SHOW_TOOLBAR = "ViewToolbar";
21 const std::string SHOW_TOOLBAR_TEXT = "ShowToolbarText";
22 const std::string SHOW_LARGE_ICONS = "ShowLargeIcons";
23 const std::string FIX_LAYOUT = "FixLayout";
24 const std::string SHOW_SLIDER = "ShowSpeedSlider";
25 const std::string COPY_ALL_ON_STOP = "CopyAllOnStop";
26 const std::string DRAW_MOUSE = "DrawMouse";
27 const std::string START_MOUSE = "StartOnLeft";
28 const std::string START_SPACE = "StartOnSpace";
29 const std::string KEY_CONTROL = "KeyControl";
30 const std::string WINDOW_PAUSE = "PauseOutsideWindow";
31
32 // long options
33 const std::string FILE_ENCODING = "FileEncodingFormat";
34 const std::string MAX_BITRATE_TIMES100 = "MaxBitRateTimes100";
35 const std::string SCREEN_ORIENTATION = "ScreenOrientation";
36 const std::string VIEW_ID = "ViewID";
37 const std::string LANGUAGE_MODEL_ID = "LanguageModelID";
38 const std::string EDIT_FONT_SIZE = "EditFontSize";
39 const std::string EDIT_HEIGHT = "EditHeight";
40 const std::string SCREEN_WIDTH = "ScreenWidth";
41 const std::string SCREEN_HEIGHT = "ScreenHeight";
42 const std::string DASHER_FONTSIZE = "DasherFontSize";
43 const std::string DASHER_DIMENSIONS = "NumberDimensions";
44
45 // string options
46 const std::string ALPHABET_ID = "AlphabetID";
47 const std::string DASHER_FONT = "DasherFont";
48 const std::string EDIT_FONT = "EditFont";
49}
50}
51
52
53void Dasher::CDasherSettingsInterface::SettingsDefaults(CSettingsStore* Store)
54{
55 using namespace Dasher;
56 using namespace Keys;
57 using namespace Opts;
58
59 Store->SetLongDefault(MAX_BITRATE_TIMES100, 150);
60 this->ChangeMaxBitRate(Store->GetLongOption(MAX_BITRATE_TIMES100)/100.0);
61
62 Store->SetBoolDefault(TIME_STAMP, true);
63 this->TimeStampNewFiles(Store->GetBoolOption(TIME_STAMP));
64 Store->SetBoolDefault(COPY_ALL_ON_STOP, false);
65 this->CopyAllOnStop(Store->GetBoolOption(COPY_ALL_ON_STOP));
66
67 Store->SetBoolDefault(DRAW_MOUSE, false);
68 this->DrawMouse(Store->GetBoolOption(DRAW_MOUSE));
69
70 Store->SetLongDefault(FILE_ENCODING, AlphabetDefault);
71 this->SetFileEncoding((FileEncodingFormats) Store->GetLongOption(FILE_ENCODING));
72
73 Store->SetBoolDefault(SHOW_SLIDER, true);
74 this->ShowSpeedSlider(Store->GetBoolOption(SHOW_SLIDER));
75 Store->SetBoolDefault(FIX_LAYOUT, false);
76 this->FixLayout(Store->GetBoolOption(FIX_LAYOUT));
77
78 // Toolbar defaults
79 Store->SetBoolDefault(SHOW_TOOLBAR_TEXT, true);
80 this->ShowToolbarText(Store->GetBoolOption(SHOW_TOOLBAR_TEXT));
81 Store->SetBoolDefault(SHOW_LARGE_ICONS, true);
82 this->ShowToolbarLargeIcons(Store->GetBoolOption(SHOW_LARGE_ICONS));
83
84 Store->SetBoolDefault(SHOW_TOOLBAR, true);
85 this->ShowToolbar(Store->GetBoolOption(SHOW_TOOLBAR));
86
87 Store->SetLongDefault(SCREEN_ORIENTATION, Opts::LeftToRight);
88 this->ChangeOrientation((ScreenOrientations) Store->GetLongOption(SCREEN_ORIENTATION));
89
90 Store->SetBoolDefault(START_MOUSE, true);
91 this->StartOnLeft(Store->GetBoolOption(START_MOUSE));
92
93 Store->SetBoolDefault(START_SPACE, false);
94 this->StartOnSpace(Store->GetBoolOption(START_SPACE));
95
96 Store->SetBoolDefault(KEY_CONTROL, false);
97 this->KeyControl(Store->GetBoolOption(KEY_CONTROL));
98
99 Store->SetBoolDefault(DASHER_DIMENSIONS, false);
100 this->SetDasherDimensions(Store->GetBoolOption(DASHER_DIMENSIONS));
101
102 Store->SetBoolDefault(WINDOW_PAUSE, false);
103 this->WindowPause(Store->GetBoolOption(WINDOW_PAUSE));
104
105 // The following standard options don't have sensible cross-platform or cross-language defaults.
106 // "" or 0 will have to mean "do something sensible for this user and platform"
107 // The user may have saved a preference for some of these options though:
108
109 this->ChangeAlphabet(Store->GetStringOption(ALPHABET_ID));
110
111 // FIXME - need to work out why this breaks stuff
112 //this->ChangeLanguageModel(Store->GetLongOption(LANGUAGE_MODEL_ID));
113 this->ChangeView(Store->GetLongOption(VIEW_ID));
114
115 // Fonts
116 this->SetEditFont(Store->GetStringOption(EDIT_FONT), Store->GetLongOption(EDIT_FONT_SIZE));
117 this->SetDasherFont(Store->GetStringOption(DASHER_FONT));
118 this->SetDasherFontSize(Dasher::Opts::FontSize(Store->GetLongOption(DASHER_FONTSIZE)));
119
120 // Window Geometry
121 this->SetEditHeight(Store->GetLongOption(EDIT_HEIGHT));
122 this->SetScreenSize(Store->GetLongOption(SCREEN_WIDTH), Store->GetLongOption(SCREEN_HEIGHT));
123}
124
125
126
diff --git a/inputmethods/dasher/DasherSettingsInterface.h b/inputmethods/dasher/DasherSettingsInterface.h
new file mode 100644
index 0000000..9d03eba
--- a/dev/null
+++ b/inputmethods/dasher/DasherSettingsInterface.h
@@ -0,0 +1,149 @@
1// DasherSettingsInterface.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10#ifndef __DasherSettingsInterface_h__
11#define __DasherSettingsInterface_h__
12
13#include "DasherTypes.h"
14#include "SettingsStore.h"
15
16namespace Dasher {class CDasherSettingsInterface;}
17class Dasher::CDasherSettingsInterface
18{
19public:
20 void SettingsDefaults(CSettingsStore* Store);
21
22 // These actually affect the way Dasher works
23 //! Change the alphabet in use to NewAlphabetID
24 virtual void ChangeAlphabet(const std::string& NewAlphabetID) {};
25
26 //! Change the maximum bitrate (effectively the speed) of Dasher
27 virtual void ChangeMaxBitRate(double NewMaxBitRate) {};
28
29 //! Generate a new langage model. Not usually needed
30 virtual void ChangeLanguageModel(unsigned int NewLanguageModelID) {};
31
32 //! Generate a new view of the model. Call it with 0 when starting up
33 virtual void ChangeView(unsigned int NewViewID) {};
34
35 //! Change the orientation (l->r, r->l, so on) of the model
36 virtual void ChangeOrientation(Opts::ScreenOrientations Orientation) {};
37
38 //! Set the file encoding of output files to Encoding
39 virtual void SetFileEncoding(Opts::FileEncodingFormats Encoding) {};
40
41 //! Inform the core that the screen has this size
42 virtual void SetScreenSize(long Width, long Height) {};
43
44 //! Set the size of the font used in the Dasher canvas
45 virtual void SetDasherFontSize(Dasher::Opts::FontSize fontsize) {};
46
47 //! Set the number of dimensions of input (either 1 or 2)
48 virtual void SetDasherDimensions(bool Value) {};
49
50 // These are recommended options for the Dasher GUI. {{{ They don't actually
51 // change the way Dasher works. They are part of the Dasher interface
52 // anyway so that it can handle option saving for you, and to make it
53 // easy for the Dasher engine to control the GUI later on. }}}
54
55 //! True if toolbar should be shown, false otherwise
56 virtual void ShowToolbar(bool Value) {};
57
58 //! True if toolbar should show text, false otherwse
59 virtual void ShowToolbarText(bool Value) {};
60
61 //! True if toolbar should have large icons, false otherwise
62 virtual void ShowToolbarLargeIcons(bool Value) {};
63
64 //! True if the speed slider should be shown, false otherwise
65 virtual void ShowSpeedSlider(bool Value) {};
66
67 //! True if the window layout should be fixed, false otherwise
68 virtual void FixLayout(bool Value) {};
69
70 //! True if new files should be timestamped, false otherwise
71 virtual void TimeStampNewFiles(bool Value) {};
72
73 //! True if all text should be copied to clipboard when Dasher is stopped, false otherwise
74 virtual void CopyAllOnStop(bool Value) {};
75
76 //! True if a box should be drawn to represent the logical position of the mouse
77 virtual void DrawMouse(bool Value) {};
78
79 //! Set the editbox font
80 virtual void SetEditFont(std::string Name, long Size) {};
81
82 //! Set the canvas font
83 virtual void SetDasherFont(std::string Name) {};
84
85 //! Set the height of the edit box
86 virtual void SetEditHeight(long Value) {};
87
88 //! Should Dasher start and stop on space bar?
89 virtual void StartOnSpace(bool Value) {};
90
91 //! Should Dasher start and stop on left mouse button?
92 virtual void StartOnLeft(bool Value) {};
93
94 //! Should Dasher be keyboard controlled?
95 virtual void KeyControl(bool Value) {};
96
97 //! Should Dasher pause when the pointer leaves the window?
98 virtual void WindowPause(bool Value) {};
99};
100
101
102#include <string>
103
104namespace Dasher
105{
106namespace Keys
107{
108 // Standard Option strings. You are encouraged to use these constants.
109 // -------------------------------------------------------------------
110
111 // bool options
112 extern const std::string TIME_STAMP;
113 extern const std::string SHOW_TOOLBAR;
114 extern const std::string SHOW_TOOLBAR_TEXT;
115 extern const std::string SHOW_LARGE_ICONS;
116 extern const std::string FIX_LAYOUT;
117 extern const std::string SHOW_SLIDER;
118 extern const std::string COPY_ALL_ON_STOP;
119 extern const std::string DRAW_MOUSE;
120 extern const std::string START_SPACE;
121 extern const std::string START_MOUSE;
122 extern const std::string KEY_CONTROL;
123 extern const std::string WINDOW_PAUSE;
124 // long options
125 extern const std::string FILE_ENCODING;
126 extern const std::string MAX_BITRATE_TIMES100;
127 extern const std::string SCREEN_ORIENTATION;
128 extern const std::string VIEW_ID;
129 extern const std::string LANGUAGE_MODEL_ID;
130 extern const std::string EDIT_FONT_SIZE;
131 extern const std::string EDIT_HEIGHT;
132 extern const std::string SCREEN_WIDTH;
133 extern const std::string SCREEN_HEIGHT;
134 extern const std::string DASHER_FONTSIZE;
135 extern const std::string DASHER_DIMENSIONS;
136
137 // string options
138 extern const std::string ALPHABET_ID;
139 extern const std::string DASHER_FONT;
140 extern const std::string EDIT_FONT;
141}
142} // namespace Dasher
143
144
145#endif /* #ifndef __DasherSettingsInterface_h__ */
146
147
148
149
diff --git a/inputmethods/dasher/DasherTypes.h b/inputmethods/dasher/DasherTypes.h
new file mode 100644
index 0000000..8885052
--- a/dev/null
+++ b/inputmethods/dasher/DasherTypes.h
@@ -0,0 +1,66 @@
1// DasherTypes.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10#ifndef __DasherTypes_h__
11#define __DasherTypes_h__
12
13namespace Dasher
14{
15 /* TODO: note by IAM 08/2002 {{{
16
17 MS docs tell us the __int64 type has no ANSI equivalent
18 I've checked and currently a 32bit long leads to problems.
19 The code could probably be altered to get around this 64bit
20 precision requirement. If not a custom class could be found
21 (or implemented fairly easily). However, as GCC supports
22 "long long int" I'm giving this low priority until someone
23 complains...
24
25 "ISO C99 supports data types for integers that are at least 64 bits wide,
26 and as an extension GCC supports them in C89 mode and in C++."
27
28 I've heard some compilers have a "quad int". If "long long int" does not
29 work, try that.
30 }}} */
31 #ifdef _MSC_VER
32 typedef __int64 myint;
33 #define LLONG_MAX 9223372036854775807
34 #define LLONG_MIN (-LLONG_MAX - 1)
35 #else
36 typedef long long int myint;
37 #define LLONG_MAX 9223372036854775807LL
38 #define LLONG_MIN (-LLONG_MAX - 1LL)
39 #endif
40
41 // Using a signed symbol type allows "Out of band" ie negative {{{
42 // values to be used to flag non-symbol data. For example commands
43 // in dasher nodes.
44 //typedef unsigned int symbol; // }}}
45 typedef int symbol;
46
47 //typedef unsigned int uint;
48 //typedef unsigned short ushort;
49
50 namespace Opts
51 {
52 // Numbers should be applied to elements of the following two enumerations as these preferences may be stored to file. Constancy between
53 // versions is a good idea. It should *not* be assumed that the numbers map onto anything useful. Different codepages may be appropriate on different systems for different character sets.
54 enum FileEncodingFormats {UserDefault=-1, AlphabetDefault=-2, UTF8=65001, UTF16LE=1200, UTF16BE=1201};
55 enum AlphabetTypes {MyNone=0, Arabic=1256, Baltic=1257, CentralEurope=1250, ChineseSimplified=936, ChineseTraditional=950, Cyrillic=1251, Greek=1253, Hebrew=1255, Japanese=932, Korean=949, Thai=874, Turkish=1254, VietNam=1258, Western=1252};
56 enum ScreenOrientations {Alphabet=-2, LeftToRight=0, RightToLeft=1, TopToBottom=2, BottomToTop=3};
57 // TODO: Possibly make colors long and add an RGB item to this {{{
58 // Would allow literal as well as semantic colors for
59 // greater flexibility. }}}
60 enum ColorSchemes {Nodes1=0, Nodes2=1, Special1=2, Special2=3, Groups=4, Objects=5};
61 enum FontSize {Normal=1, Big=2, VBig=4};
62 }
63
64}
65
66#endif /* #ifndef __DasherTypes_h__ */
diff --git a/inputmethods/dasher/DasherView.cpp b/inputmethods/dasher/DasherView.cpp
new file mode 100644
index 0000000..3b8cb64
--- a/dev/null
+++ b/inputmethods/dasher/DasherView.cpp
@@ -0,0 +1,93 @@
1// DasherView.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include "DasherView.h"
10using namespace Dasher;
11
12
13CDasherView::CDasherView(CDasherScreen* DasherScreen, CDasherModel& DasherModel, Opts::ScreenOrientations Orientation)
14 : m_Screen(DasherScreen), m_DasherModel(DasherModel), ScreenOrientation(Orientation), ColourMode(false)
15{
16 //XYScale = (double)m_Screen->GetHeight() / m_Screen->GetWidth();
17}
18
19
20void CDasherView::ChangeOrientation(Dasher::Opts::ScreenOrientations Orientation)
21{
22 ScreenOrientation = Orientation;
23 Render();
24}
25
26
27void CDasherView::FlushAt(int mousex,int mousey)
28{
29 m_DasherModel.Flush(0,0);
30}
31
32int CDasherView::RecursiveRender(CDasherNode* Render, myint y1,myint y2,int mostleft, bool text)
33{
34 symbol CurChar = Render->Symbol();
35 int Color;
36
37 if (ColourMode==true) {
38 Color = Render->Colour();
39 } else {
40 Color = Render->Phase()%3;
41 }
42
43 if (RenderNode(Render->Symbol(), Color, Render->Cscheme(), y1, y2, mostleft, Render->m_bForce, text))
44 RenderGroups(Render, y1, y2, text);
45 else
46 Render->Kill();
47
48 CDasherNode** const Children=Render->Children();
49 if (!Children)
50 return 0;
51 int norm=DasherModel().Normalization();
52 for (unsigned int i=1; i<Render->Chars(); i++) {
53 if (Children[i]->Alive()) {
54 myint Range=y2-y1;
55 myint newy1=y1+(Range*Children[i]->Lbnd())/norm;
56 myint newy2=y1+(Range*Children[i]->Hbnd())/norm;
57 RecursiveRender(Children[i], newy1, newy2, mostleft, text);
58 }
59 }
60 return 1;
61
62
63}
64
65
66void CDasherView::RenderGroups(CDasherNode* Render, myint y1, myint y2, bool text)
67{
68 CDasherNode** Children = Render->Children();
69 if (!Children)
70 return;
71 int current=0;
72 int lower=0;
73 int upper=0;
74 myint range=y2-y1;
75 for (unsigned int i=1; i<Render->Chars(); i++) {
76 int g=Children[i]->Group();
77 if (g!=current) {
78 lower=upper;
79 upper=i;
80
81 if (current!=0) {
82 myint lbnd=Children[lower]->Lbnd();
83 myint hbnd=Children[upper]->Lbnd();
84 myint newy1=y1+(range*lbnd)/m_DasherModel.Normalization();
85 myint newy2=y1+(range*hbnd)/m_DasherModel.Normalization();
86 int mostleft;
87 bool force;
88 RenderNode(0,current-1,Opts::Groups,newy1,newy2,mostleft,force,text);
89 }
90 current=g;
91 }
92 }
93}
diff --git a/inputmethods/dasher/DasherView.h b/inputmethods/dasher/DasherView.h
new file mode 100644
index 0000000..81cc24e
--- a/dev/null
+++ b/inputmethods/dasher/DasherView.h
@@ -0,0 +1,99 @@
1// DasherView.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10//////////////////////////////////////////////////////////////////////
11// DasherView.h: interface for the DasherView class.
12// Copyright 2002 David Ward
13//////////////////////////////////////////////////////////////////////
14
15#ifndef __DasherView_h_
16#define __DasherView_h_
17
18#include "MSVC_Unannoy.h"
19#include "DasherScreen.h"
20#include "DasherModel.h"
21
22// CDasherView is an abstract view class
23// The implentation must provide several functions - defined here as pure virtual functions
24// See the CDasherViewSquare class for an example
25
26namespace Dasher {class CDasherView;}
27class Dasher::CDasherView
28{
29public:
30 CDasherView(CDasherScreen* DasherScreen, CDasherModel& DasherModel, Dasher::Opts::ScreenOrientations Orientation=Dasher::Opts::LeftToRight);
31 ~CDasherView() {}
32
33 void ChangeOrientation(Dasher::Opts::ScreenOrientations Orientation);
34
35 // TODO Sort this out
36 void FlushAt(int mousex,int mousey);
37
38 // renders Dasher
39 inline void Render();
40
41 // translates the screen coordinates to Dasher coordinates and calls
42 // dashermodel.TapOnDisplay
43 virtual void TapOnDisplay(int mousex, int mousey, unsigned long Time)=0;
44
45 virtual void ChangeScreen(CDasherScreen* NewScreen)
46 {
47 m_Screen=NewScreen;
48
49 // DJW - removed floating point stuff
50 //XYScale = (double)m_Screen->GetHeight() / m_Screen->GetWidth();
51 }
52
53 virtual void DrawMouse(int mousex, int mousey)=0;
54 virtual void DrawKeyboard()=0;
55
56 // Return references to the model and the screen:
57 CDasherModel& DasherModel() {return m_DasherModel;}
58 CDasherScreen& Screen() {return *m_Screen;}
59
60 void Display() {m_Screen->Display();}
61
62 // Toggle advanced colour mode
63 void SetColourMode(bool colourmode) {ColourMode=colourmode;}
64
65protected:
66 // Orientation of Dasher Screen
67 inline void MapScreen(int* DrawX, int* DrawY);
68 inline void UnMapScreen(int* DrawX, int* DrawY);
69
70private:
71 CDasherScreen* m_Screen; // provides the graphics (text, lines, rectangles):
72 CDasherModel& m_DasherModel; // Model view represents
73
74 // Pure virtuals to implement
75 virtual void Crosshair(myint sx)=0; // Tells m_Screen to draw a crosshair - or other static decoration
76 virtual int RenderNode(const symbol Character, const int Color, Opts::ColorSchemes ColorScheme,
77 myint y1, myint y2, int& mostleft, bool& force, bool text)=0;
78
79 // Responsible for all the Render_node calls
80 int RecursiveRender(CDasherNode* Render, myint y1,myint y2,int mostleft, bool text);
81
82 // Displays some nodes inside one parent node. Used to group capital letters, accents, punctuation etc.
83 void RenderGroups(CDasherNode* Render, myint y1, myint y2, bool text);
84
85 // Orientation of Dasher Screen
86 Dasher::Opts::ScreenOrientations ScreenOrientation;
87
88 // Advanced colour mode
89 bool ColourMode;
90
91 // DJW - removed floating point stuff
92 //double XYScale;
93};
94
95
96#include "DasherView.inl"
97
98
99#endif /* #ifndef __DasherView_h_ */
diff --git a/inputmethods/dasher/DasherView.inl b/inputmethods/dasher/DasherView.inl
new file mode 100644
index 0000000..fbb0c16
--- a/dev/null
+++ b/inputmethods/dasher/DasherView.inl
@@ -0,0 +1,75 @@
1// DasherView.inl
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10inline void Dasher::CDasherView::Render()
11{
12 m_Screen->Blank();
13
14 // Render nodes to screen object (should use off screen buffer)
15 RecursiveRender(m_DasherModel.Root(), m_DasherModel.Rootmin(), m_DasherModel.Rootmax(), 2, false);
16 RecursiveRender(m_DasherModel.Root(), m_DasherModel.Rootmin(), m_DasherModel.Rootmax(), 2, true);
17 Crosshair(m_DasherModel.DasherOX()); // add crosshair
18 //m_Screen->Display(); // copy from buffer to screen
19}
20
21inline void Dasher::CDasherView::MapScreen(int* DrawX, int* DrawY)
22{
23 using namespace Dasher::Opts;
24
25 switch (ScreenOrientation) {
26 case (LeftToRight):
27 break;
28 case (RightToLeft):
29 *DrawX = m_Screen->GetWidth() - *DrawX;
30 break;
31 case (TopToBottom): {
32 int Swapper = ( *DrawX * m_Screen->GetHeight()) / m_Screen->GetWidth();
33 *DrawX = (*DrawY * m_Screen->GetWidth()) / m_Screen->GetHeight();
34 *DrawY = Swapper;
35 break;
36 }
37 case (BottomToTop): {
38 // Note rotation by 90 degrees not reversible like others
39 int Swapper = m_Screen->GetHeight() - ( *DrawX * m_Screen->GetHeight()) / m_Screen->GetWidth();
40 *DrawX = (*DrawY * m_Screen->GetWidth()) / m_Screen->GetHeight();
41 *DrawY = Swapper;
42 break;
43 }
44 default:
45 break;
46 }
47}
48
49
50inline void Dasher::CDasherView::UnMapScreen(int* MouseX, int* MouseY)
51{
52 using namespace Dasher::Opts;
53
54 switch (ScreenOrientation) {
55 case (LeftToRight):
56 break;
57 case (RightToLeft):
58 *MouseX = m_Screen->GetWidth() - *MouseX;
59 break;
60 case (TopToBottom): {
61 int Swapper = (*MouseX * m_Screen->GetHeight()) / m_Screen->GetWidth();
62 *MouseX = (*MouseY *m_Screen->GetWidth()) / m_Screen->GetHeight();;
63 *MouseY = Swapper;
64 break;
65 }
66 case (BottomToTop): {
67 int Swapper = (*MouseX * m_Screen->GetHeight()) / m_Screen->GetWidth();
68 *MouseX = ((m_Screen->GetHeight() - *MouseY) * m_Screen->GetWidth()) / m_Screen->GetHeight();
69 *MouseY = Swapper;
70 break;
71 }
72 default:
73 break;
74 }
75}
diff --git a/inputmethods/dasher/DasherViewSquare.cpp b/inputmethods/dasher/DasherViewSquare.cpp
new file mode 100644
index 0000000..1b12a58
--- a/dev/null
+++ b/inputmethods/dasher/DasherViewSquare.cpp
@@ -0,0 +1,229 @@
1// DasherViewSquare.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10//////////////////////////////////////////////////////////////////////
11// DasherViewSquare.cpp: implementation of the DasherViewSquare class.
12// Copyright 2002 David Ward
13//////////////////////////////////////////////////////////////////////
14
15#include "DasherModel.h"
16#include "DasherViewSquare.h"
17#include <iostream>
18
19using namespace Dasher;
20
21// ARG! MSVC++ V6 doesn't seem to come with min and max in <algorithm>
22#ifdef _MSC_VER
23#ifndef max
24#define max(a,b) (((a) > (b)) ? (a) : (b))
25#endif
26#ifndef min
27#define min(a,b) (((a) < (b)) ? (a) : (b))
28#endif
29#else
30#include <algorithm>
31using std::min;
32using std::max;
33#endif
34
35
36CDasherViewSquare::CDasherViewSquare(CDasherScreen* DasherScreen, CDasherModel& DasherModel, Dasher::Opts::ScreenOrientations Orientation)
37 : CDasherView(DasherScreen, DasherModel, Orientation)
38{
39 ChangeScreen(DasherScreen);
40
41 // tweak these if you know what you are doing
42 m_dXmpa=0.2; // these are for the x non-linearity
43 m_dXmpb=0.5;
44 m_dXmpc=0.9;
45 m_dXmpd=0.5; // slow X movement when accelerating Y
46
47 double dY1=0.25; // Amount of acceleration
48 double dY2=0.95; // Accelerate Y movement below this point
49 double dY3=0.05; // Accelerate Y movement above this point
50
51 m_Y2=int (dY2 * (CDasherView::DasherModel().DasherY()) );
52 m_Y3=int (dY3 * (CDasherView::DasherModel().DasherY()) );
53 m_Y1=int(1.0/dY1);
54
55}
56
57
58int CDasherViewSquare::RenderNode(const symbol Character, const int Color, Opts::ColorSchemes ColorScheme,
59 myint y1, myint y2, int& mostleft, bool& force, bool text)
60{
61 int top = dashery2screen(y1);
62 if (top>CanvasY)
63 return 0;
64 if (top<0)
65 top=0;
66
67 int bottom = dashery2screen(y2);
68 if (bottom<0)
69 return 0;
70 if (bottom>CanvasY)
71 bottom=CanvasY;
72
73 int height=bottom-top;
74
75 if (height==0 && text==true)
76 force=false;
77
78 if (force || height>1) {
79 force=true;
80
81 int left=dasherx2screen(y2-y1);
82
83 int right=CanvasX;
84
85 int newleft=left, newtop=top, newright=right, newbottom=bottom;
86 MapScreen(&newleft, &newtop);
87 MapScreen(&newright, &newbottom);
88 if( !text )
89 Screen().DrawRectangle(newleft, newtop, newright, newbottom, Color, ColorScheme);
90 else
91 {
92 if (left<mostleft)
93 left=mostleft;
94
95 int Size;
96 if (left*Screen().GetFontSize()<CanvasX*19/20) {
97 Size = 20*Screen().GetFontSize();
98 } else if (left*Screen().GetFontSize()<CanvasX*159/160) {
99 Size = 14*Screen().GetFontSize();
100 } else {
101 Size = 11*Screen().GetFontSize();
102 }
103
104 int TextWidth, TextHeight, OriginX=0, OriginY=0;
105 Screen().TextSize(Character, &TextWidth, &TextHeight, Size);
106 UnMapScreen(&TextWidth, &TextHeight);
107 UnMapScreen(&OriginX, &OriginY);
108 int FontHeight = abs(TextHeight-OriginY);
109 int FontWidth = abs(TextWidth-OriginX);
110 mostleft = left + FontWidth;
111
112 int newleft2 = left;
113 int newtop2 = (height-FontHeight)/2 + top;
114 int newright2 = left + FontWidth;
115 int newbottom2 = (height+FontHeight)/2 + top;
116 MapScreen(&newleft2, &newtop2);
117 MapScreen(&newright2, &newbottom2);
118 newleft = min(newleft2, newright2);
119 newtop = min(newtop2, newbottom2);
120
121 Screen().DrawText(Character, newleft, newtop, Size);
122 }
123
124 return 1;
125 } else
126 return 0;
127}
128
129
130void CDasherViewSquare::CheckForNewRoot()
131{
132 CDasherNode * const root=DasherModel().Root();
133 CDasherNode ** const children=root->Children();
134
135
136 myint y1=DasherModel().Rootmin();
137 myint y2=DasherModel().Rootmax();
138
139 if ((y1>0 || y2 < DasherModel().DasherY() || dasherx2screen(y2-y1)>0) && root->Symbol()!=0) {
140 DasherModel().Reparent_root(root->Lbnd(),root->Hbnd());
141 }
142
143 if (children==0)
144 return;
145
146 int alive=0;
147 int theone=0;
148 unsigned int i;
149 for (i=1;i<root->Chars();i++) {
150 if (children[i]->Alive()) {
151 alive++;
152 theone=i;
153 }
154 }
155
156 if (alive==1) {
157 y1=DasherModel().Rootmin();
158 y2=DasherModel().Rootmax();
159 myint range=y2-y1;
160 myint newy1=y1+(range*children[theone]->Lbnd())/DasherModel().Normalization();
161 myint newy2=y1+(range*children[theone]->Hbnd())/DasherModel().Normalization();
162 if (newy1<0 && newy2> DasherModel().DasherY()) {
163 myint left=dasherx2screen(newy2-newy1);
164 if (left<0) {
165 DasherModel().Make_root(theone);
166 return;
167 }
168 }
169 }
170}
171
172
173// work out the next viewpoint
174// move the rectangles accordingly
175void CDasherViewSquare::TapOnDisplay(int mousex,int mousey, unsigned long Time)
176{
177 // convert mouse (screen) coords into dasher coords
178 if (mousex>CanvasX)
179 mousex=CanvasX;
180
181 UnMapScreen(&mousex, &mousey);
182 screen2dasher(&mousex,&mousey);
183 DasherModel().Tap_on_display(mousex,mousey, Time);
184 CheckForNewRoot();
185}
186
187void CDasherViewSquare::DrawMouse(int mousex, int mousey)
188{
189 screen2dasher(&mousex,&mousey);
190 mousex=dasherx2screen(mousex);
191 mousey=dashery2screen(mousey);
192 Screen().DrawRectangle(mousex-5, mousey-5, mousex+5, mousey+5, 0, Opts::ColorSchemes(Objects));
193}
194
195void CDasherViewSquare::DrawKeyboard()
196{
197 CDasherScreen::point line[2];
198 line[0].x = 200;
199 line[0].y = 0;
200 line[1].x = 200;
201 line[1].y = CanvasY/2;
202
203 Screen().Polyline(line,2);
204
205 line[0].x = 200;
206 line[0].y = CanvasY/2;
207 line[1].x = 0;
208 line[1].y = CanvasY/2;
209
210 Screen().Polyline(line,2);
211
212 line[0].x = 200;
213 line[0].y = CanvasY/2;
214 line[1].x = 200;
215 line[1].y = CanvasY;
216
217 Screen().Polyline(line,2);
218}
219
220void CDasherViewSquare::ChangeScreen(CDasherScreen* NewScreen)
221{
222 CDasherView::ChangeScreen(NewScreen);
223 int Width = Screen().GetWidth();
224 int Height = Screen().GetHeight();
225 CanvasX=9*Width/10;
226 CanvasBorder=Width-CanvasX;
227 CanvasY=Height;
228}
229
diff --git a/inputmethods/dasher/DasherViewSquare.h b/inputmethods/dasher/DasherViewSquare.h
new file mode 100644
index 0000000..5d689d0
--- a/dev/null
+++ b/inputmethods/dasher/DasherViewSquare.h
@@ -0,0 +1,58 @@
1// DasherViewSquare.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __DasherViewSquare_h__
10#define __DasherViewSquare_h__
11
12#include "MSVC_Unannoy.h"
13#include "DasherScreen.h"
14#include "DasherModel.h"
15#include "DasherView.h"
16
17
18// An implementation of the DasherView class
19//
20// This class renders Dasher in the vanilla style,
21// but with horizontal and vertical mappings
22//
23// Horizontal mapping - linear and log
24// Vertical mapping - linear with different gradient
25
26namespace Dasher {class CDasherViewSquare;}
27class Dasher::CDasherViewSquare : public Dasher::CDasherView
28{
29public:
30 CDasherViewSquare(CDasherScreen* DasherScreen, CDasherModel& DasherModel, Dasher::Opts::ScreenOrientations Orientation=Dasher::Opts::LeftToRight);
31 void TapOnDisplay(int mousex,int mousey, unsigned long Time);
32
33 void ChangeScreen(CDasherScreen* NewScreen);
34 void DrawMouse(int mousex, int mousey);
35 void DrawKeyboard();
36private:
37 // the x and y non-linearities
38 inline const void screen2dasher(int *mousex, int *mousey);
39 inline const int dasherx2screen(const myint sx);
40 inline const int dashery2screen(myint sy);
41
42 int RenderNode(const symbol Character, const int Color, Opts::ColorSchemes ColorScheme,
43 myint y1, myint y2, int& mostleft, bool& force, bool text);
44
45 void CheckForNewRoot();
46 inline void Crosshair(myint sx);
47 double m_dXmpa,m_dXmpb,m_dXmpc,m_dXmpd;
48 myint m_Y1,m_Y2,m_Y3;
49 myint s_Y1,s_Y2,s_Y3;
50 int CanvasX,CanvasY,CanvasBorder;
51 double xmap(double x);
52 double ixmap(double x);
53};
54
55#include "DasherViewSquare.inl"
56
57
58#endif /* #ifndef __DasherViewSquare_h__ */
diff --git a/inputmethods/dasher/DasherViewSquare.inl b/inputmethods/dasher/DasherViewSquare.inl
new file mode 100644
index 0000000..c22c32c
--- a/dev/null
+++ b/inputmethods/dasher/DasherViewSquare.inl
@@ -0,0 +1,142 @@
1// DasherViewSquare.inl
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9namespace Dasher {
10
11inline const void CDasherViewSquare::screen2dasher(int *mousex, int *mousey)
12{
13 int dashery=*mousey;
14
15 double x=1.0*(CanvasX-*mousex)/CanvasX;
16 dashery*=DasherModel().DasherY();
17 dashery/=CanvasY;
18
19 if (DasherModel().Dimensions()==false) {
20 if (dashery>m_Y2)
21 dashery= (dashery-m_Y2)*m_Y1 + m_Y2;
22 else if (dashery<m_Y3)
23 dashery= (dashery-m_Y3)*m_Y1+m_Y3;
24 }
25
26 x=ixmap(x)*DasherModel().DasherY();
27
28 if (DasherModel().Dimensions()==true) {
29 double distx, disty;
30
31 distx=2048-x;
32 disty=DasherModel().DasherY()/2-dashery;
33
34 if (disty>1500) {
35 dashery=548+(548-dashery);
36 disty=1298-dashery;
37 if(disty<-750) {
38 x=2048;
39 dashery=2048;
40 } else {
41 x=2048+pow(pow(750,2)-pow(disty,2),0.5)*10;
42 }
43 *mousex=int(x);
44 *mousey=dashery;
45 return;
46 }
47 else if (disty <-1500) {
48 dashery=3548+(3548-dashery);
49 disty=2798-dashery;
50 if(disty>750) {
51 x=2048;
52 dashery=2048;
53 } else {
54 x=2048+pow(pow(750,2)-pow(disty,2),0.5)*10;
55 }
56 *mousex=int(x);
57 *mousey=dashery;
58 return;
59 } else {
60 x=pow(pow(1500,2)-pow(disty,2),0.5);
61 }
62 x=2048-x;
63 }
64 *mousex=int(x);
65 *mousey=dashery;
66}
67
68inline const int CDasherViewSquare::dasherx2screen(const myint sx)
69{
70 double x=1.0*sx/(DasherModel().DasherY());
71 x=xmap(x);
72 //return CanvasX-int(x*CanvasY);
73 return CanvasX-int(x*CanvasX);
74
75}
76
77
78inline const int CDasherViewSquare::dashery2screen(myint y)
79{
80 if (y > m_Y2 )
81 y= m_Y2 + (y-m_Y2)/m_Y1;
82 else if (y<m_Y3)
83 y= m_Y3+ (y-m_Y3 )/m_Y1;
84
85 //y*=CanvasY*Screen().GetFontSize();
86 y*=CanvasY;
87 y/=DasherModel().DasherY();
88 //y-=(CanvasY*Screen().GetFontSize()-CanvasY)/2;
89 return int(y);
90}
91
92
93inline void CDasherViewSquare::Crosshair(myint sx)
94{
95 CDasherScreen::point crosshair[2];
96
97 crosshair[0].x = dasherx2screen(sx);
98 crosshair[0].y = 0;
99 crosshair[1].x = crosshair[0].x;
100 crosshair[1].y = CanvasY;
101
102 MapScreen(&crosshair[0].x, &crosshair[0].y);
103 MapScreen(&crosshair[1].x, &crosshair[1].y);
104 Screen().Polyline(crosshair,2);
105
106 crosshair[0].x = dasherx2screen(12*sx/14);
107 crosshair[0].y = CanvasY/2;
108 crosshair[1].x = dasherx2screen(17*sx/14);
109 crosshair[1].y = CanvasY/2;
110
111 MapScreen(&crosshair[0].x, &crosshair[0].y);
112 MapScreen(&crosshair[1].x, &crosshair[1].y);
113 Screen().Polyline(crosshair,2);
114}
115
116
117
118
119
120inline double CDasherViewSquare::ixmap(double x)
121// invert x non-linearity
122{
123 if (x<m_dXmpb*m_dXmpc)
124 return x/m_dXmpc;
125 else
126 return m_dXmpb-m_dXmpa + m_dXmpa * exp( (x/m_dXmpc - m_dXmpb) / m_dXmpa);
127
128}
129
130
131inline double CDasherViewSquare::xmap(double x)
132// x non-linearity
133{
134 if (x<m_dXmpb)
135 return m_dXmpc*x;
136 else
137 return m_dXmpc*(m_dXmpa*log((x+m_dXmpa-m_dXmpb)/m_dXmpa) +m_dXmpb);
138}
139
140
141
142} // namespace Dasher
diff --git a/inputmethods/dasher/DasherWidgetInterface.h b/inputmethods/dasher/DasherWidgetInterface.h
new file mode 100644
index 0000000..5a1387e
--- a/dev/null
+++ b/inputmethods/dasher/DasherWidgetInterface.h
@@ -0,0 +1,93 @@
1// DasherWidgetInterface.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __DasherWidgetInterface_h__
10#define __DasherWidgetInterface_h__
11
12
13#include "DasherTypes.h"
14#include <string>
15
16namespace Dasher {class CDasherWidgetInterface;}
17class Dasher::CDasherWidgetInterface
18{
19public:
20 //! Signal to the core that the model should be started
21 //
22 //! Call this function before providing input coordinates and whenever
23 //! reinitialising Dasher
24 virtual void Start()=0;
25
26 // Times in milliseconds are required so Dasher runs at the correct speed.
27 //! Signal an input location
28 //
29 //! Signal an input event. This may be the current location of the
30 //! mouse or a stylus tap, for example
31 //! \param MouseX The mouse X coordinate, in screen coordinates
32 //! \param MouseY The mouse Y coordinate, in screen coordinates
33 //! \param Time Time in milliseconds, required to keep Dasher running
34 //! at the correct speed
35 virtual void TapOn(int MouseX, int MouseY, unsigned long Time)=0;
36
37 //! Signal an input event and pause the simulation
38 virtual void PauseAt(int MouseX, int MouseY)=0;
39
40 //! Unpause the simulation.
41 //
42 //! \param Time should be in milliscones and should be consistent with
43 //! previous time values
44 virtual void Unpause(unsigned long Time)=0;
45
46 //! Signal that the core should redraw the screen
47 virtual void Redraw()=0;
48
49 // The widgets need to tell the engine when they have been affected
50 // by external interaction
51
52 //! Signal the core that a change has occured to the screen. (Unneeded)
53 virtual void ChangeScreen()=0;
54
55 //! Signal the core that a change has occued to the editbox. (Unneeded)
56 virtual void ChangeEdit()=0;
57
58 // These are needed so widgets know how to render the alphabet.
59 // All strings are encoded in UTF-8.
60
61 //! Request the number of symbols in the current alphabet
62 virtual unsigned int GetNumberSymbols()=0;
63
64 //! Request the text that should be displayed on the Dasher canvas
65 //
66 //! Note - the returned string is in UTF-8 encoding.
67 //! \param Symbol the symbol that is to be displayed
68 virtual const std::string& GetDisplayText(Dasher::symbol Symbol)=0;
69
70 //! Request the text that should be entered into the edit box
71 //
72 //! Note - the returned string is in UTF-8 encoding.
73 //! \param Symbol the symbol that is to be displayed
74 virtual const std::string& GetEditText(Dasher::symbol Symbol)=0;
75
76 //! Request the foreground colour for the text to be drawn on the canvas
77 //! \param Symbol the symbol that is to be displayed
78 virtual int GetTextColour(Dasher::symbol Symbol)=0;
79
80 //! Request the default screen orientation for the current alphabet
81 //
82 //! (Eg, left to right for English, right to left for Hebrew)
83 virtual Opts::ScreenOrientations GetAlphabetOrientation()=0;
84
85 //! Returns the codepage for the current alphabet
86 virtual Opts::AlphabetTypes GetAlphabetType()=0;
87
88 //! Provides a fully qualified path to the training file for the alphabet
89 virtual const std::string& GetTrainFile()=0; // Returns a fully-qualified path to file:
90 // UserLocation + TrainFile
91};
92
93#endif /* #ifndef __DasherWidgetInterface_h__ */
diff --git a/inputmethods/dasher/FrameRate.h b/inputmethods/dasher/FrameRate.h
new file mode 100644
index 0000000..2f86b03
--- a/dev/null
+++ b/inputmethods/dasher/FrameRate.h
@@ -0,0 +1,112 @@
1// FrameRate.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __FrameRate_h__
10#define __FrameRate_h__
11
12#include "MSVC_Unannoy.h"
13
14// keeps track of framerate
15// computes the Steps parameter
16// computes RXmax - which controls the maximum rate of zooming in
17
18const double LN2= log(2);
19
20class CFrameRate {
21 public:
22 CFrameRate() ;
23 ~CFrameRate() {};
24 const double Rxmax() const {return m_dRXmax;}
25 const int Steps() const {return m_iSteps;}
26 const double Framerate() const {return m_dFr;}
27 void Reset(unsigned long Time);
28 void NewFrame(unsigned long Time);
29
30 // TODO: These two shouldn't be the same thing:
31 void SetBitrate(double TargetRate);
32 void SetMaxBitrate(double MaxRate);
33 private:
34 double m_dFr;
35 double m_dMaxbitrate; // the maximum rate of entering information
36 double m_dRXmax; // the maximum zoomin per frame
37 int m_iFrames,m_iTime,m_iTime2,m_iSamples;
38 int m_iSteps; // the 'Steps' parameter. See djw thesis.
39};
40
41inline CFrameRate::CFrameRate() {
42
43 // maxbitrate should be user-defined and/or adaptive. Currently it is not.
44#if defined(_WIN32_WCE)
45 m_dMaxbitrate=5;
46#else
47 m_dMaxbitrate=5.5;
48#endif
49
50 m_dRXmax=2; // only a transient effect
51 m_iFrames=0;
52 m_iSamples=1;
53
54 // we dont know the framerate yet - play it safe by setting it high
55 m_dFr=1<<5;
56
57 // start off very slow until we have sampled framerate adequately
58 m_iSteps=2000;
59 m_iTime=0; // Hmmm, User must reset framerate before starting.
60}
61
62inline void CFrameRate::NewFrame(unsigned long Time)
63 // compute framerate if we have sampled enough frames
64{
65
66 m_iFrames++;
67
68 if (m_iFrames==m_iSamples) {
69 m_iTime2=Time;
70 if (m_iTime2-m_iTime < 50)
71 m_iSamples++; // increase sample size
72 else if (m_iTime2-m_iTime > 80) {
73 m_iSamples--;
74 if (m_iSamples <2)
75 m_iSamples=2;
76 }
77 if (m_iTime2-m_iTime) {
78 m_dFr=m_iFrames*1000.0/(m_iTime2-m_iTime);
79 m_iTime=m_iTime2;
80 m_iFrames=0;
81
82 }
83 m_dRXmax=exp(m_dMaxbitrate*LN2/m_dFr);
84 m_iSteps=m_iSteps/2+(int)(-log(0.2)*m_dFr/LN2/m_dMaxbitrate)/2;
85 //dchar debug[256];
86 // _stprintf(debug,TEXT("fr %f Steps %d samples %d time2 %d rxmax %f\n"),fr,Steps,samples,time2,RXmax);
87 //OutputDebugString(debug);
88
89 }
90}
91
92inline void CFrameRate::Reset(unsigned long Time)
93{
94 m_iFrames=0;
95 m_iTime=Time;
96}
97
98
99inline void CFrameRate::SetBitrate(double TargetRate)
100{
101 m_dMaxbitrate = TargetRate;
102}
103
104
105inline void CFrameRate::SetMaxBitrate(double MaxRate)
106{
107 m_dMaxbitrate = MaxRate;
108}
109
110
111
112#endif /* #ifndef __FrameRate_h__ */
diff --git a/inputmethods/dasher/LanguageModel.cpp b/inputmethods/dasher/LanguageModel.cpp
new file mode 100644
index 0000000..9635273
--- a/dev/null
+++ b/inputmethods/dasher/LanguageModel.cpp
@@ -0,0 +1,77 @@
1// LanguageModel.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include "LanguageModel.h"
10
11using namespace Dasher;
12using namespace std;
13
14// I have removed the following as it doesn't seem to compile in gcc:
15
16// using CLanguageModel::CNodeContext;
17
18///////////////////////////////////////////////////////////////////
19
20CLanguageModel::CLanguageModel(CAlphabet* Alphabet, int Normalization)
21 : m_Alphabet(Alphabet), m_iNorm(Normalization)
22{
23 m_iModelChars = m_Alphabet->GetNumberSymbols();
24}
25
26
27///////////////////////////////////////////////////////////////////
28
29void CLanguageModel::EnterText(CNodeContext* NodeContext, string TheText)
30{
31 vector<symbol> Symbols;
32 m_Alphabet->GetSymbols(&Symbols, &TheText, false);
33 for (unsigned int i=0; i<Symbols.size(); i++)
34 EnterSymbol((CContext*) NodeContext, (modelchar) Symbols[i]);
35}
36
37///////////////////////////////////////////////////////////////////
38
39void CLanguageModel::LearnText(CNodeContext* NodeContext, string* TheText, bool IsMore)
40{
41 vector<symbol> Symbols;
42
43 m_Alphabet->GetSymbols(&Symbols, TheText, IsMore);
44
45 for (unsigned int i=0; i<Symbols.size(); i++)
46 LearnSymbol((CContext*) NodeContext, (modelchar) Symbols[i]);
47}
48
49///////////////////////////////////////////////////////////////////
50
51bool CLanguageModel::GetNodeProbs(CNodeContext* Context, vector<symbol> &NewSymbols,
52 vector<unsigned int> &Groups, vector<unsigned int> &Probs, double AddProb)
53{
54 // make sure it is a valid context
55 if (Context) {
56 int s = m_Alphabet->GetNumberSymbols();
57 NewSymbols.resize(s);
58 Groups.resize(s);
59 for (int i=0;i<s;i++) {
60 NewSymbols[i]=i; // This will be replaced by something that works out valid nodes for this context
61 Groups[i]=m_Alphabet->get_group(i);
62 }
63 GetProbs((CContext*) Context,Probs,AddProb);
64 return true;
65 }
66 return false;
67}
68
69int CLanguageModel::GetColour(int character)
70{
71 std::string colour=m_Alphabet->GetColour(character);
72 if (colour!="") {
73 return atoi(colour.c_str());
74 } else {
75 return 0;
76 }
77}
diff --git a/inputmethods/dasher/LanguageModel.h b/inputmethods/dasher/LanguageModel.h
new file mode 100644
index 0000000..8ffe100
--- a/dev/null
+++ b/inputmethods/dasher/LanguageModel.h
@@ -0,0 +1,123 @@
1// LanguageModel.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2001-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9// Abstract language model class
10// See PPMModel for an example implementation
11
12// Contexts are indentified by a unique unsigned integer
13
14#ifndef __LanguageModel_h__
15#define __LanguageModel_h__
16
17#include "MSVC_Unannoy.h"
18#include <vector>
19#include <string>
20
21#include "Alphabet.h"
22#include "Context.h"
23
24namespace Dasher {class CLanguageModel;}
25class Dasher::CLanguageModel
26{
27public:
28 CLanguageModel(CAlphabet* Alphabet, int Normalization);
29
30 // Interface for the Dasher code
31 // --------------------------------------------------------------------------
32 class CNodeContext {
33 public:
34 CNodeContext() {};
35 virtual ~CNodeContext() {};
36 };
37
38 // return the model's normalization - what the probabilities sum to
39 const int normalization() const { return m_iNorm;}
40
41 CNodeContext* GetRootNodeContext();
42 CNodeContext* CloneNodeContext(CNodeContext* NodeContext);
43 void ReleaseNodeContext(CNodeContext* NodeContext);
44 void EnterNodeSymbol(CNodeContext* NodeContext, symbol Symbol);
45 void LearnNodeSymbol(CNodeContext* NodeContext, symbol Symbol);
46 void EnterText(CNodeContext* NodeContext, std::string TheText);
47 void LearnText(CNodeContext* NodeContext, std::string* TheText, bool IsMore);
48 bool GetNodeProbs(CNodeContext* Context, std::vector<symbol> &NewSymbols,
49 std::vector<unsigned int> &Groups, std::vector<unsigned int> &Probs, double AddProb);
50
51 // Alphabet pass-through functions for widely needed information
52 symbol GetSpaceSymbol() {return m_Alphabet->GetSpaceSymbol();}
53
54 int GetColour(int character);
55
56protected:
57 int GetNumberModelChars() {return m_Alphabet->GetNumberSymbols();}
58
59 // Generic language model functions to be implemented
60 // --------------------------------------------------------------------------
61 typedef unsigned int modelchar;
62
63 // return the id for the root context:
64 virtual CContext* GetRootContext()=0;
65 // clone a context and return the new id:
66 virtual CContext* CloneContext(CContext*)=0;
67 // delete a context:
68 virtual void ReleaseContext(CContext*)=0;
69 // diagnostic info:
70 virtual void dump()=0;
71 // add character to the language model:
72 virtual void LearnSymbol(CContext* Context, modelchar Symbol)=0;
73 // update context with a character:
74 virtual void EnterSymbol(CContext* context, modelchar Symbol)=0;
75 // get the probability distrubution at the given context:
76 virtual bool GetProbs(CContext* Context, std::vector<unsigned int> &Probs, double AddProb)=0;
77
78private:
79 CAlphabet *m_Alphabet;
80 int m_iModelChars; // number of charater in the model 1...ModelChars
81 int m_iNorm; // normalization of probabilities
82};
83
84using namespace Dasher;
85
86///////////////////////////////////////////////////////////////////
87
88inline CLanguageModel::CNodeContext* CLanguageModel::GetRootNodeContext()
89{
90 return (CNodeContext*) GetRootContext();
91}
92
93///////////////////////////////////////////////////////////////////
94
95inline CLanguageModel::CNodeContext* CLanguageModel::CloneNodeContext(CNodeContext* NodeContext)
96{
97 return (CNodeContext*) CloneContext((CContext*) NodeContext);
98}
99
100///////////////////////////////////////////////////////////////////
101
102inline void CLanguageModel::ReleaseNodeContext(CNodeContext* NodeContext)
103{
104 ReleaseContext((CContext*) NodeContext);
105}
106
107///////////////////////////////////////////////////////////////////
108
109inline void CLanguageModel::EnterNodeSymbol(CNodeContext* NodeContext, symbol Symbol)
110{
111 EnterSymbol((CContext*) NodeContext, (modelchar) Symbol);
112}
113
114///////////////////////////////////////////////////////////////////
115
116inline void CLanguageModel::LearnNodeSymbol(CNodeContext* NodeContext, symbol Symbol)
117{
118 LearnSymbol((CContext*) NodeContext, (modelchar) Symbol);
119}
120
121
122
123#endif /* #ifndef __LanguageModel_h__ */
diff --git a/inputmethods/dasher/MSVC_Unannoy.h b/inputmethods/dasher/MSVC_Unannoy.h
new file mode 100644
index 0000000..2167eec
--- a/dev/null
+++ b/inputmethods/dasher/MSVC_Unannoy.h
@@ -0,0 +1,17 @@
1#ifndef __MSVC_Unannoy_h__
2#define __MSVC_Unannoy_h__
3
4// Sorry about this frequently included header non-VC++ users.
5// It shouldn't do any harm.
6
7// Warning 4786 is so annoying if you have VC++ 6.
8// It produces *pages* of complaints if you use certain STL headers.
9// The warning just means that VC++ is unable to produce certain debug
10// information - there is nothing wrong with the code. IAM 08/2002
11#ifdef _MSC_VER
12#pragma warning(disable:4786)
13#pragma warning(disable:4018)
14#endif
15
16
17#endif /* #ifndef __MSVC_Unannoy_h__ */
diff --git a/inputmethods/dasher/NoClones.h b/inputmethods/dasher/NoClones.h
new file mode 100644
index 0000000..11cdabb
--- a/dev/null
+++ b/inputmethods/dasher/NoClones.h
@@ -0,0 +1,39 @@
1#ifndef __NoClones_h__
2#define __NoClones_h__
3
4/* Explanation of NoClones {{{
5
6C++ defines default copy constructors and assignment operators, which clone
7every member of a class. Stroustrup describes this behaviour as the result of
8"historical accident". For many non-trivial classes, especially those
9containing pointers, this default behaviour is too naive. In fact it often leads
10to heap corruption.
11
12Sometimes it does not make any sense to copy an instance of a class. For
13example if it contains a unique file handle, or other lock on a system resource.
14Sometimes it is too much effort to write reliable replacement copy operations[1].
15In either case a private copy constructor and a private assignment operator
16prevent accidental copying. [2]
17
18Deriving a class from this class has the same preventative effect. It is also a
19bit neater and means that all the above explanation is centralised here.
20
21IAM 09/2002
22
23[1] An example of how it is very easy to make mistakes:
24http://www.mistybeach.com/articles/WhyIDontLikeCPlusPlusForLargeProjects.html
25If we don't need a copy feature it really isn't worth the hassle.
26[2] The C++ Programming Language. Stroustrup. 3rd edition. Section 10.4.6.3
27
28}}} */
29
30class NoClones
31{
32protected: // Default constructor doesn't need to be public, but can't be private.
33 NoClones() {}; // Lots of compiler complaints without default constructor.
34private:
35 NoClones(const NoClones&);
36 NoClones& operator=(const NoClones&);
37};
38
39#endif /* #ifndef __NoClones_h__ */
diff --git a/inputmethods/dasher/PPMLanguageModel.cpp b/inputmethods/dasher/PPMLanguageModel.cpp
new file mode 100644
index 0000000..b725a2b
--- a/dev/null
+++ b/inputmethods/dasher/PPMLanguageModel.cpp
@@ -0,0 +1,309 @@
1// PPMLanguageModel.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 1999-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#include <math.h>
10#include "PPMLanguageModel.h"
11
12using namespace Dasher;
13using namespace std;
14
15// static TCHAR debug[256];
16typedef unsigned long ulong;
17
18////////////////////////////////////////////////////////////////////////
19/// PPMnode definitions
20////////////////////////////////////////////////////////////////////////
21
22CPPMLanguageModel::CPPMnode *CPPMLanguageModel::CPPMnode::find_symbol(int sym)
23// see if symbol is a child of node
24{
25 // printf("finding symbol %d at node %d\n",sym,node->id);
26 CPPMnode *found=child;
27 while (found) {
28 if (found->symbol==sym)
29 return found;
30 found=found->next;
31 }
32 return 0;
33}
34
35
36CPPMLanguageModel::CPPMnode * CPPMLanguageModel::CPPMnode::add_symbol_to_node(int sym,int *update)
37{
38 CPPMnode *born,*search;
39 search=find_symbol(sym);
40 if (!search) {
41 born = new CPPMnode(sym);
42 born->next=child;
43 child=born;
44 // node->count=1;
45 return born;
46 } else {
47 if (*update) { // perform update exclusions
48 search->count++;
49 *update=0;
50 }
51 return search;
52 }
53
54}
55
56
57/////////////////////////////////////////////////////////////////////
58// CPPMLanguageModel defs
59/////////////////////////////////////////////////////////////////////
60
61CPPMLanguageModel::CPPMLanguageModel(CAlphabet *_alphabet,int _normalization)
62 : CLanguageModel(_alphabet,_normalization)
63{
64 root=new CPPMnode(-1);
65 m_rootcontext=new CPPMContext(root,0);
66}
67
68
69CPPMLanguageModel::~CPPMLanguageModel()
70{
71 delete root;
72}
73
74
75bool CPPMLanguageModel::GetProbs(CContext *context,vector<unsigned int> &probs,double addprob)
76 // get the probability distribution at the context
77{
78 // seems like we have to have this hack for VC++
79 CPPMContext *ppmcontext=static_cast<CPPMContext *> (context);
80
81
82 int modelchars=GetNumberModelChars();
83 int norm=CLanguageModel::normalization();
84 probs.resize(modelchars);
85 CPPMnode *temp,*s;
86 int loop,total;
87 int sym;
88 ulong spent=0;
89 ulong size_of_slice;
90 bool *exclusions=new bool [modelchars];
91 ulong uniform=modelchars;
92 ulong tospend=norm-uniform;
93 temp=ppmcontext->head;
94 for (loop=0; loop <modelchars; loop++) { /* set up the exclusions array */
95 probs[loop]=0;
96 exclusions[loop]=0;
97 }
98 while (temp!=0) {
99 //Usprintf(debug,TEXT("tospend %u\n"),tospend);
100 //DebugOutput(TEXT("round\n"));
101 total=0;
102 s=temp->child;
103 while (s) {
104 sym=s->symbol;
105 if (!exclusions[s->symbol])
106 total=total+s->count;
107 s=s->next;
108 }
109 if (total) {
110 //Usprintf(debug,TEXT"escape %u\n"),tospend*
111 size_of_slice=tospend;
112 s=temp->child;
113 while (s) {
114 if (!exclusions[s->symbol]) {
115 exclusions[s->symbol]=1;
116 ulong p=size_of_slice*(2*s->count-1)/2/ulong(total);
117 probs[s->symbol]+=p;
118 tospend-=p;
119 }
120 // Usprintf(debug,TEXT("sym %u counts %d p %u tospend %u \n"),sym,s->count,p,tospend);
121 // DebugOutput(debug);
122 s=s->next;
123 }
124 }
125 temp = temp->vine;
126 }
127 //Usprintf(debug,TEXT("Norm %u tospend %u\n"),Norm,tospend);
128 //DebugOutput(debug);
129
130 size_of_slice=tospend;
131 int symbolsleft=0;
132 for (sym=1;sym<modelchars;sym++)
133 if (!probs[sym])
134 symbolsleft++;
135 for (sym=1;sym<modelchars;sym++)
136 if (!probs[sym]) {
137 ulong p=size_of_slice/symbolsleft;
138 probs[sym]+=p;
139 tospend-=p;
140 }
141
142 // distribute what's left evenly
143 tospend+=uniform;
144 for (sym=1;sym<modelchars;sym++) {
145 ulong p=tospend/(modelchars-sym);
146 probs[sym]+=p;
147 tospend-=p;
148 }
149 //Usprintf(debug,TEXT("finaltospend %u\n"),tospend);
150 //DebugOutput(debug);
151
152 // free(exclusions); // !!!
153 // !!! NB by IAM: p577 Stroustrup 3rd Edition: "Allocating an object using new and deleting it using free() is asking for trouble"
154 delete[] exclusions;
155 return true;
156}
157
158
159void CPPMLanguageModel::AddSymbol(CPPMLanguageModel::CPPMContext &context,int symbol)
160 // add symbol to the context
161 // creates new nodes, updates counts
162 // and leaves 'context' at the new context
163{
164 // sanity check
165 if (symbol==0 || symbol>=GetNumberModelChars())
166 return;
167
168 CPPMnode *vineptr,*temp;
169 int updatecnt=1;
170
171 temp=context.head->vine;
172 context.head=context.head->add_symbol_to_node(symbol,&updatecnt);
173 vineptr=context.head;
174 context.order++;
175
176 while (temp!=0) {
177 vineptr->vine=temp->add_symbol_to_node(symbol,&updatecnt);
178 vineptr=vineptr->vine;
179 temp=temp->vine;
180 }
181 vineptr->vine=root;
182 if (context.order>MAX_ORDER){
183 context.head=context.head->vine;
184 context.order--;
185 }
186}
187
188
189// update context with symbol 'Symbol'
190void CPPMLanguageModel::EnterSymbol(CContext* Context, modelchar Symbol)
191{
192 CPPMLanguageModel::CPPMContext& context = * static_cast<CPPMContext *> (Context);
193
194 CPPMnode *find;
195 CPPMnode *temp=context.head;
196
197 while (context.head) {
198 find =context.head->find_symbol(Symbol);
199 if (find) {
200 context.order++;
201 context.head=find;
202 //Usprintf(debug,TEXT("found context %x order %d\n"),head,order);
203 //DebugOutput(debug);
204 return;
205 }
206 context.order--;
207 context.head=context.head->vine;
208 }
209
210 if (context.head==0) {
211 context.head=root;
212 context.order=0;
213 }
214
215}
216
217
218void CPPMLanguageModel::LearnSymbol(CContext* Context, modelchar Symbol)
219{
220 CPPMLanguageModel::CPPMContext& context = * static_cast<CPPMContext *> (Context);
221 AddSymbol(context, Symbol);
222}
223
224
225void CPPMLanguageModel::dumpSymbol(int symbol)
226{
227 if ((symbol <= 32) || (symbol >= 127))
228 printf( "<%d>", symbol );
229 else
230 printf( "%c", symbol );
231}
232
233
234void CPPMLanguageModel::dumpString( char *str, int pos, int len )
235 // Dump the string STR starting at position POS
236{
237 char cc;
238 int p;
239 for (p = pos; p<pos+len; p++) {
240 cc = str [p];
241 if ((cc <= 31) || (cc >= 127))
242 printf( "<%d>", cc );
243 else
244 printf( "%c", cc );
245 }
246}
247
248
249void CPPMLanguageModel::dumpTrie( CPPMLanguageModel::CPPMnode *t, int d )
250 // diagnostic display of the PPM trie from node t and deeper
251{
252//TODO
253/*
254 dchar debug[256];
255 int sym;
256 CPPMnode *s;
257 Usprintf( debug,TEXT("%5d %7x "), d, t );
258 //TODO: Uncomment this when headers sort out
259 //DebugOutput(debug);
260 if (t < 0) // pointer to input
261 printf( " <" );
262 else {
263 Usprintf(debug,TEXT( " %3d %5d %7x %7x %7x <"), t->symbol,t->count, t->vine, t->child, t->next );
264 //TODO: Uncomment this when headers sort out
265 //DebugOutput(debug);
266 }
267
268 dumpString( dumpTrieStr, 0, d );
269 Usprintf( debug,TEXT(">\n") );
270 //TODO: Uncomment this when headers sort out
271 //DebugOutput(debug);
272 if (t != 0) {
273 s = t->child;
274 while (s != 0) {
275 sym =s->symbol;
276
277 dumpTrieStr [d] = sym;
278 dumpTrie( s, d+1 );
279 s = s->next;
280 }
281 }
282*/
283}
284
285
286void CPPMLanguageModel::dump()
287 // diagnostic display of the whole PPM trie
288{
289// TODO:
290/*
291 dchar debug[256];
292 Usprintf(debug,TEXT( "Dump of Trie : \n" ));
293 //TODO: Uncomment this when headers sort out
294 //DebugOutput(debug);
295 Usprintf(debug,TEXT( "---------------\n" ));
296 //TODO: Uncomment this when headers sort out
297 //DebugOutput(debug);
298 Usprintf( debug,TEXT( "depth node symbol count vine child next context\n") );
299 //TODO: Uncomment this when headers sort out
300 //DebugOutput(debug);
301 dumpTrie( root, 0 );
302 Usprintf( debug,TEXT( "---------------\n" ));
303 //TODO: Uncomment this when headers sort out
304 //DebugOutput(debug);
305 Usprintf(debug,TEXT( "\n" ));
306 //TODO: Uncomment this when headers sort out
307 //DebugOutput(debug);
308*/
309}
diff --git a/inputmethods/dasher/PPMLanguageModel.h b/inputmethods/dasher/PPMLanguageModel.h
new file mode 100644
index 0000000..bd860b8
--- a/dev/null
+++ b/inputmethods/dasher/PPMLanguageModel.h
@@ -0,0 +1,122 @@
1// PPMLanguageModel.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 1999-2002 David Ward
6//
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef __PPMLanguageModel_h__
10#define __PPMLanguageModel_h__
11
12#include "NoClones.h"
13#include "MSVC_Unannoy.h"
14#include <vector>
15#include <stdio.h>
16
17#include "LanguageModel.h"
18
19static char dumpTrieStr[40000];
20const int MAX_ORDER = 5;
21const int maxcont =200;
22
23namespace Dasher {class CPPMLanguageModel;}
24class Dasher::CPPMLanguageModel : public Dasher::CLanguageModel, private NoClones
25{
26public:
27 CPPMLanguageModel(CAlphabet *_alphabet, int _normalization);
28 ~CPPMLanguageModel();
29
30 class CPPMnode {
31 public:
32 CPPMnode* find_symbol(int sym);
33 CPPMnode* add_symbol_to_node(int sym,int *update);
34 CPPMnode* child;
35 CPPMnode* next;
36 CPPMnode* vine;
37 short int count;
38 const short int symbol;
39 CPPMnode(int sym);
40 };
41
42 class CPPMContext : public CContext {
43 public:
44 CPPMContext(CPPMContext const &input) {head = input.head;order= input.order;}
45 CPPMContext(CPPMnode* _head=0, int _order=0) : head(_head),order(_order) {};
46 ~CPPMContext() {};
47 void dump();
48 CPPMnode* head;
49 int order;
50 };
51
52 void ReleaseContext(CContext*);
53 CContext* GetRootContext();
54 inline CContext* CloneContext(CContext*);
55 void EnterSymbol(CContext* context, modelchar Symbol);
56 //inline bool GetProbs(CContext*,std::vector<symbol> &newchars,std::vector<unsigned int> &groups,std::vector<unsigned int> &probs,double addprob);
57 bool GetProbs(CContext*, std::vector<unsigned int> &Probs, double AddProb);
58
59 void LearnSymbol(CContext* Context, modelchar Symbol);
60 void dump();
61
62private:
63 CPPMContext *m_rootcontext;
64 CPPMnode *root;
65 void AddSymbol(CPPMContext& context,int symbol);
66 void dumpSymbol(int symbol);
67 void dumpString( char *str, int pos, int len );
68 void dumpTrie( CPPMnode *t, int d );
69
70
71
72};
73
74////////////////////////////////////////////////////////////////////////
75// Inline functions
76////////////////////////////////////////////////////////////////////////
77
78////////////////////////////////////////////////////////////////////////
79
80inline CPPMLanguageModel::CPPMnode::CPPMnode(int sym) : symbol(sym)
81{
82 child=next=vine=0;
83 count=1;
84}
85
86///////////////////////////////////////////////////////////////////
87
88inline void CPPMLanguageModel::CPPMContext::dump()
89 // diagnostic output
90{
91 // TODO uncomment this when headers sorted out
92 //dchar debug[128];
93 //Usprintf(debug,TEXT("head %x order %d\n"),head,order);
94 //DebugOutput(debug);
95}
96
97///////////////////////////////////////////////////////////////////
98
99inline CContext* CPPMLanguageModel::GetRootContext()
100{
101 CPPMContext * nc = new CPPMLanguageModel::CPPMContext(*m_rootcontext);
102 CContext *cont=static_cast<CContext *> (nc);
103 return cont;
104}
105
106///////////////////////////////////////////////////////////////////
107
108inline CContext* CPPMLanguageModel::CloneContext(CContext *copythis)
109{
110 CPPMContext *ppmcontext=static_cast<CPPMContext *> (copythis);
111 CPPMContext * nc = new CPPMLanguageModel::CPPMContext(*ppmcontext);
112 return static_cast<CContext *> (nc);
113}
114
115///////////////////////////////////////////////////////////////////
116
117inline void CPPMLanguageModel::ReleaseContext(CContext *release)
118{
119 delete release;
120}
121
122#endif /* #ifndef __PPMLanguageModel_H__ */
diff --git a/inputmethods/dasher/QtDasherImpl.cc b/inputmethods/dasher/QtDasherImpl.cc
new file mode 100644
index 0000000..55c21b1
--- a/dev/null
+++ b/inputmethods/dasher/QtDasherImpl.cc
@@ -0,0 +1,85 @@
1#include <iostream>
2#include <qapplication.h>
3#include <qobject.h>
4#include <qpixmap.h>
5#include "DasherInterface.h"
6#include "QtDasherScreen.h"
7#include "QtDasherImpl.h"
8
9/* XPM */
10static const char * qtdasher_xpm[]={
11"28 7 2 1",
12"# c #303030",
13" c None",
14" ########################## ",
15" ",
16" # # ",
17" # # # # ",
18" # # # # ",
19" # # # ",
20" ########################## "};
21
22
23QtDasherImpl::QtDasherImpl()
24 : qtdasherwidget(0), icn(0), ref(0), qtdasherinterface(0)
25{
26}
27
28QtDasherImpl::~QtDasherImpl()
29{
30 delete qtdasherwidget;
31 delete icn;
32}
33
34QWidget *QtDasherImpl::inputMethod( QWidget *parent, Qt::WFlags f )
35{
36 if ( !qtdasherwidget ) {
37 qtdasherwidget = new QtDasherPlugin( parent, "Dasher", f );
38 }
39 return qtdasherwidget;
40}
41
42void QtDasherImpl::resetState()
43{
44 if ( qtdasherwidget )
45 qtdasherwidget->resetState();
46}
47
48QPixmap *QtDasherImpl::icon()
49{
50 if ( !icn )
51 icn = new QPixmap( (const char **)qtdasher_xpm );
52 return icn;
53}
54
55QString QtDasherImpl::name()
56{
57 return qApp->translate( "InputMethods", "Dasher" );
58}
59
60void QtDasherImpl::onKeyPress( QObject *receiver, const char *slot )
61{
62 if ( qtdasherwidget )
63 QObject::connect( qtdasherwidget, SIGNAL(key(ushort,ushort,ushort,bool,bool)), receiver, slot );
64}
65
66#ifndef QT_NO_COMPONENT
67QRESULT QtDasherImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
68{
69 *iface = 0;
70 if ( uuid == IID_QUnknown )
71 *iface = this;
72 else if ( uuid == IID_InputMethod )
73 *iface = this;
74
75 if ( *iface )
76 (*iface)->addRef();
77 return QS_OK;
78}
79
80Q_EXPORT_INTERFACE()
81{
82 Q_CREATE_INSTANCE( QtDasherImpl )
83}
84#endif
85
diff --git a/inputmethods/dasher/QtDasherImpl.h b/inputmethods/dasher/QtDasherImpl.h
new file mode 100644
index 0000000..c143dc3
--- a/dev/null
+++ b/inputmethods/dasher/QtDasherImpl.h
@@ -0,0 +1,38 @@
1#ifndef QTDASHERIMPL_H
2#define QTDASHERIMPL_H
3
4#include <qpe/inputmethodinterface.h>
5#include "QtDasherPlugin.h"
6
7class QtDasher;
8class QPixmap;
9
10class QtDasherImpl : public InputMethodInterface
11{
12public:
13 QtDasherImpl();
14 virtual ~QtDasherImpl();
15
16#ifndef QT_NO_COMPONENT
17 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
18 Q_REFCOUNT
19#endif
20
21 virtual QWidget *inputMethod( QWidget *parent, Qt::WFlags f );
22 virtual void resetState();
23 virtual QPixmap *icon();
24 virtual QString name();
25 virtual void onKeyPress( QObject *receiver, const char *slot );
26
27private:
28 CDasherInterface *qtdasherinterface;
29 QtDasherPlugin *qtdasherwidget;
30 QPixmap *icn;
31 ulong ref;
32};
33
34#endif
35
36
37
38
diff --git a/inputmethods/dasher/QtDasherPlugin.cc b/inputmethods/dasher/QtDasherPlugin.cc
new file mode 100644
index 0000000..fe1712e
--- a/dev/null
+++ b/inputmethods/dasher/QtDasherPlugin.cc
@@ -0,0 +1,79 @@
1#include "QtDasherPlugin.h"
2
3#include <qpe/global.h>
4
5#include <qpainter.h>
6#include <qlist.h>
7#include <qbitmap.h>
8#include <qlayout.h>
9#include <qvbox.h>
10#include <qdialog.h>
11#include <qscrollview.h>
12#include <qpopupmenu.h>
13#include <qhbuttongroup.h>
14#include <qpushbutton.h>
15#include <qmessagebox.h>
16#include <qwindowsystem_qws.h>
17
18QtDasherPlugin::QtDasherPlugin(QWidget* parent, const char* name, WFlags f) : QFrame(parent,name,f)
19{
20 (new QHBoxLayout(this))->setAutoAdd(TRUE);
21 interface = new CDasherInterface;
22 interface->SetSystemLocation("/opt/QtPalmtop/share/dasher");
23 interface->Unpause(0);
24 interface->Start();
25 d = new QtDasherScreen(240,100,interface,this,this);
26 interface->ChangeMaxBitRate(2.5);
27 d->show();
28 utf8_codec = new QUtf8Codec;
29}
30
31QSize QtDasherPlugin::sizeHint() const
32{
33 return QSize(240,100);
34}
35
36QtDasherPlugin::~QtDasherPlugin()
37{
38 delete d;
39}
40
41void QtDasherPlugin::resetState()
42{
43 flushcount=0;
44 interface->Start();
45 interface->Redraw();
46}
47
48void QtDasherPlugin::unflush()
49{
50 if (flushcount==0)
51 return;
52 for (flushcount; flushcount>0; flushcount--) {
53 deletetext();
54 }
55}
56
57void QtDasherPlugin::output(int Symbol)
58{
59 std::string label = interface->GetEditText(Symbol);
60 QString unicodestring = utf8_codec->toUnicode(label.c_str());
61 for (int i=0; i<int(unicodestring.length()); i++) {
62 emit key( unicodestring[i].unicode(), 0, 0, true, false );
63 emit key( unicodestring[i].unicode(), 0, 0, false, false );
64 }
65}
66
67void QtDasherPlugin::deletetext()
68{
69 emit key( 0, Qt::Key_Backspace, 0, true, false);
70 emit key( 0, Qt::Key_Backspace, 0, false, false);
71}
72
73void QtDasherPlugin::flush(int Symbol)
74{
75 if (Symbol==0)
76 return;
77 output(Symbol);
78 flushcount++;
79}
diff --git a/inputmethods/dasher/QtDasherPlugin.h b/inputmethods/dasher/QtDasherPlugin.h
new file mode 100644
index 0000000..5f70acf
--- a/dev/null
+++ b/inputmethods/dasher/QtDasherPlugin.h
@@ -0,0 +1,42 @@
1#include <qutfcodec.h>
2#include <qframe.h>
3#include "QtDasherScreen.h"
4#include "DasherInterface.h"
5#include "DashEdit.h"
6
7class QtDasherPlugin : public QFrame, public CDashEditbox
8{
9 Q_OBJECT
10public:
11 QtDasherPlugin(QWidget* parent=0, const char* name=0, WFlags f=0);
12 ~QtDasherPlugin();
13
14 void resetState();
15 QSize sizeHint() const;
16
17 void write_to_file() {};
18 void get_new_context(std::string&, int) {};
19 void unflush();
20 void output(int);
21 void deletetext();
22 void flush(int);
23 void Clear() {};
24 void SetEncoding(Dasher::Opts::FileEncodingFormats) {};
25 void SetFont(std::string Name, long Size) {};
26
27 signals:
28 void key( ushort, ushort, ushort, bool, bool);
29
30 private:
31 QtDasherScreen *d;
32 CDasherInterface *interface;
33 int flushcount;
34 QUtf8Codec *utf8_codec;
35};
36
37
38
39
40
41
42
diff --git a/inputmethods/dasher/QtDasherScreen.cc b/inputmethods/dasher/QtDasherScreen.cc
new file mode 100644
index 0000000..6820105
--- a/dev/null
+++ b/inputmethods/dasher/QtDasherScreen.cc
@@ -0,0 +1,180 @@
1// QtDasherScreen.cc
2// (c) 2003 Yann Dirson
3// Derived from GtkDasherCanvas.cc
4// (c) 2002 Philip Cowans
5
6#include <iostream>
7#include <string>
8
9#include <qpointarray.h>
10#include <qpoint.h>
11
12#include "QtDasherScreen.h"
13#include "DasherScreen.h"
14#include "SettingsStore.h"
15
16#define MAXFONTSIZE 25
17#define MINFONTSIZE 8
18
19#include <iconv.h>
20#include <iostream>
21
22QtDasherScreen::QtDasherScreen (int _width, int _height,
23 CDasherInterface *_interface,
24 QWidget * _parent, Dasher::CDashEditbox *edit):
25 QWidget(_parent), interface( _interface ),
26 fontname( "fixed" ), // fontsize(12),
27 Dasher::CDasherScreen(_width, _height)
28{
29 // font = new QFont (fontname, fontsize);
30 painter = new QPainter ();
31
32 pixmap = new QPixmap (_width, _height);
33 pixmap->setOptimization(QPixmap::BestOptim);
34 interface->SetSettingsStore(new CSettingsStore);
35
36 interface->ChangeLanguageModel(0);
37 interface->ChangeView(0);
38 interface->ChangeEdit(edit);
39
40 interface->GetFontSizes(&FontSizes);
41
42 for (int i=0; i<FontSizes.size(); i++) {
43 if (FontSizes[i]>Fonts.size())
44 Fonts.resize((FontSizes[i])+1);
45 Fonts[FontSizes[i]]= QFont (fontname.c_str(), FontSizes[i]);
46 Fonts[FontSizes[i]].setPixelSize(FontSizes[i]);
47 }
48
49 interface->ChangeScreen(this);
50
51 paused=true;
52
53 QTimer *tmr = new QTimer(this);
54 connect (tmr, SIGNAL(timeout()), SLOT(timer()));
55 tmr->start(200);
56
57}
58
59long QtDasherScreen::get_time()
60{
61 long s_now;
62 long ms_now;
63
64 struct timeval tv;
65 struct timezone tz;
66
67 gettimeofday( &tv, &tz );
68
69 s_now = tv.tv_sec-1054487600;
70
71 ms_now = tv.tv_usec / 1000;
72
73 return( long(s_now*1000 + ms_now) );
74
75}
76
77QtDasherScreen::~QtDasherScreen()
78{
79 delete painter;
80 delete interface;
81 delete edit;
82}
83
84QColor QtDasherScreen::getColor(int Color, const Opts::ColorSchemes ColorScheme) const
85{
86 switch (ColorScheme) {
87 case Dasher::Opts::Nodes1:
88 switch (Color) {
89 case 0: return QColor (180, 245, 180);
90 case 1: return QColor (160, 200, 160);
91 case 2: return QColor (0, 255, 255);
92 default: abort ();
93 }
94 case Dasher::Opts::Nodes2:
95 switch (Color) {
96 case 0: return QColor (255, 185, 255);
97 case 1: return QColor (140, 200, 255);
98 case 2: return QColor (255, 175, 175);
99 default: abort ();
100 }
101 case Dasher::Opts::Special1: return QColor (240, 240, 240);
102 case Dasher::Opts::Special2: return QColor (255, 255, 255);
103 case Dasher::Opts::Groups:
104 switch (Color) {
105 case 0: return QColor (255, 255, 0);
106 case 1: return QColor (255, 100, 100);
107 case 2: return QColor (0, 255, 0);
108 default: abort ();
109 }
110 case Dasher::Opts::Objects: return QColor (0, 0, 0);
111 default: abort();
112 }
113}
114
115void QtDasherScreen::DrawRectangle(int x1, int y1, int x2, int y2,
116 int Color, Opts::ColorSchemes ColorScheme) const
117{
118 painter->setBrush (getColor (Color, ColorScheme));
119 painter->drawRect (x1, y1, x2-x1, y2-y1);
120}
121
122static void Points_to_QPointArray(const Dasher::CDasherScreen::point* const points,
123 int number,
124 QPointArray &qpa)
125{
126 for (int i = 0; i < number; i++) {
127 qpa.setPoint (i, points[i].x, points[i].y);
128 }
129}
130
131void QtDasherScreen::Polyline(point* Points, int Number) const
132{
133 QPointArray qpa(Number);
134 Points_to_QPointArray (Points, Number, qpa);
135 painter->setPen (SolidLine);
136 painter->drawPolyline (qpa);
137 painter->setPen (NoPen);
138}
139
140void QtDasherScreen::DrawPolygon(point* Points, int Number, int Color,
141 Opts::ColorSchemes ColorScheme) const
142{
143 painter->setBrush (getColor (Color, ColorScheme));
144 QPointArray qpa(Number);
145 Points_to_QPointArray (Points, Number, qpa);
146 painter->drawPolygon (qpa);
147}
148
149void QtDasherScreen::mousePressEvent (QMouseEvent *e)
150{
151 paused=false;
152 interface->Unpause(get_time());
153}
154
155void QtDasherScreen::mouseReleaseEvent(QMouseEvent *e)
156{
157 QPoint p = e->pos();
158 interface->PauseAt(p.x(), p.y());
159 paused=true;
160}
161
162void QtDasherScreen::timer()
163{
164 if (paused==false) {
165 QPoint cursorpos;
166 cursorpos=this->cursor().pos();
167 cursorpos=mapFromGlobal(cursorpos);
168
169 interface->TapOn(cursorpos.x(), cursorpos.y(), get_time());
170 }
171}
172
173
174
175
176
177
178
179
180
diff --git a/inputmethods/dasher/QtDasherScreen.h b/inputmethods/dasher/QtDasherScreen.h
new file mode 100644
index 0000000..f359113
--- a/dev/null
+++ b/inputmethods/dasher/QtDasherScreen.h
@@ -0,0 +1,117 @@
1// QtDasherScreen.h
2// (c) 2003 Yann Dirson
3// Derived from GtkDasherCanvas.h
4// (c) 2002 Philip Cowans
5
6#ifndef QT_DASHER_SCREEN_H
7#define QT_DASHER_SCREEN_H
8
9#include <string>
10#include <sys/time.h>
11
12#include <qwidget.h>
13#include <qpainter.h>
14#include <qfont.h>
15#include <qstring.h>
16#include <qpixmap.h>
17#include <qtimer.h>
18#include <qcursor.h>
19
20#include "DasherScreen.h"
21#include "DashEdit.h"
22#include "DasherInterface.h"
23
24#include <iconv.h>
25
26using namespace Dasher;
27
28class QtDasherScreen : public QWidget, public Dasher::CDasherScreen
29
30{
31 Q_OBJECT
32 public:
33 QtDasherScreen (int _width, int _height,
34 CDasherInterface *_interface,
35 QWidget * _parent=0, Dasher::CDashEditbox* edit=0);
36 QtDasherScreen::~QtDasherScreen();
37
38 void SetFont(std::string Name)
39 { fontname = Name; /* set_the_font(); */ }
40
41 void SetFontSize(Dasher::Opts::FontSize fontsize)
42 {
43#warning QtDasherScreen::SetFontSize() not implemented
44 }
45 Dasher::Opts::FontSize GetFontSize()
46 {
47#warning QtDasherScreen::GetFontSize() not implemented
48 return (Dasher::Opts::Normal);
49 }
50
51 void TextSize(symbol Character, int* Width, int* Height, int Size) const
52 {
53 // should probably use QPainter::boundingRect()
54 *Width = *Height = Fonts[Size].pixelSize();
55
56 }
57 void DrawText(symbol Character, int x1, int y1, int Size) const
58 {
59 // QFont font = QFont (fontname.c_str(), Size);
60 // font.setPixelSize(Size);
61 QPoint point = QPoint(x1, y1+Size/2);
62
63 painter->setFont (Fonts[Size]);
64 painter->drawText (point,
65 QString(interface->GetDisplayText(Character).c_str()));
66 }
67
68 void DrawRectangle(int x1, int y1, int x2, int y2,
69 int Color, Opts::ColorSchemes ColorScheme) const;
70 void Polyline(point* Points, int Number) const;
71 void DrawPolygon(point* Points, int Number, int Color,
72 Opts::ColorSchemes ColorScheme) const;
73
74 std::vector<int> FontSizes;
75 std::vector<QFont> Fonts;
76
77 void Blank() const {
78 painter->begin(pixmap);
79 painter->setPen (NoPen);
80 painter->fillRect(0, 0, m_iWidth, m_iHeight,
81 QColor(255,255,255));
82 }
83 void Display() {
84 painter->end();
85 repaint();
86 }
87
88 void paintEvent( QPaintEvent * )
89 {
90 bitBlt(this, 0, 0, pixmap);
91 }
92
93 void mousePressEvent (QMouseEvent *e);
94 void mouseReleaseEvent (QMouseEvent *e);
95
96 protected:
97 QColor getColor(int Color, const Opts::ColorSchemes ColorScheme) const;
98
99 long QtDasherScreen::get_time();
100
101 CDasherInterface* interface;
102 Dasher::CDashEditbox* edit;
103
104 bool paused;
105
106 QPainter* painter;
107
108 QPixmap* pixmap;
109
110 std::string fontname;
111
112 protected slots:
113 void timer();
114
115};
116
117#endif
diff --git a/inputmethods/dasher/SettingsStore.cpp b/inputmethods/dasher/SettingsStore.cpp
new file mode 100644
index 0000000..c5bbfea
--- a/dev/null
+++ b/inputmethods/dasher/SettingsStore.cpp
@@ -0,0 +1,135 @@
1// SettingsStore.cpp
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10
11
12#include "SettingsStore.h"
13
14using namespace std;
15
16/* TODO: Consider using Template functions to make this neater. */
17
18
19bool CSettingsStore::GetBoolOption(const string& Key)
20{
21 if (BoolMap.find(Key)==BoolMap.end()) {
22 bool Value = false;
23 LoadSetting(Key, &Value);
24 BoolMap[Key] = Value;
25 }
26
27 return BoolMap[Key];
28}
29
30
31long CSettingsStore::GetLongOption(const string& Key)
32{
33 if (LongMap.find(Key)==LongMap.end()) {
34 long Value = 0l;
35 LoadSetting(Key, &Value);
36 LongMap[Key] = Value;
37 }
38
39 return LongMap[Key];
40}
41
42
43string& CSettingsStore::GetStringOption(const string& Key)
44{
45 if (StringMap.find(Key)==StringMap.end()) {
46 string Value = "";
47 LoadSetting(Key, &Value);
48 StringMap[Key] = Value;
49 }
50
51 return StringMap[Key];
52}
53
54
55void CSettingsStore::SetBoolOption(const string& Key, bool Value)
56{
57 BoolMap[Key] = Value;
58 SaveSetting(Key, Value);
59}
60
61
62void CSettingsStore::SetLongOption(const string& Key, long Value)
63{
64 LongMap[Key] = Value;
65 SaveSetting(Key, Value);
66}
67
68
69void CSettingsStore::SetStringOption(const string& Key, const string& Value)
70{
71 StringMap[Key] = Value;
72 SaveSetting(Key, Value);
73}
74
75
76void CSettingsStore::SetBoolDefault(const string& Key, bool Value)
77{
78 bool TmpValue;
79 if ( (BoolMap.find(Key)==BoolMap.end()) && (!LoadSetting(Key, &TmpValue)) )
80 SetBoolOption(Key, Value);
81}
82
83
84void CSettingsStore::SetLongDefault(const string& Key, long Value)
85{
86 long TmpValue;
87 if ( (LongMap.find(Key)==LongMap.end()) && (!LoadSetting(Key, &TmpValue)) )
88 SetLongOption(Key, Value);
89}
90
91
92void CSettingsStore::SetStringDefault(const string& Key, const string& Value)
93{
94 string TmpValue;
95 if ( (StringMap.find(Key)==StringMap.end()) && (!LoadSetting(Key, &TmpValue)) )
96 SetStringOption(Key, Value);
97}
98
99
100/* Private functions -- Settings are not saved between sessions unless these
101functions are over-ridden.
102--------------------------------------------------------------------------*/
103
104
105bool CSettingsStore::LoadSetting(const string& Key, bool* Value)
106{
107 return false;
108}
109
110
111bool CSettingsStore::LoadSetting(const string& Key, long* Value)
112{
113 return false;
114}
115
116
117bool CSettingsStore::LoadSetting(const string& Key, string* Value)
118{
119 return false;
120}
121
122
123void CSettingsStore::SaveSetting(const string& Key, bool Value)
124{
125}
126
127
128void CSettingsStore::SaveSetting(const string& Key, long Value)
129{
130}
131
132
133void CSettingsStore::SaveSetting(const string& Key, const string& Value)
134{
135}
diff --git a/inputmethods/dasher/SettingsStore.h b/inputmethods/dasher/SettingsStore.h
new file mode 100644
index 0000000..8ef9fcf
--- a/dev/null
+++ b/inputmethods/dasher/SettingsStore.h
@@ -0,0 +1,92 @@
1// SettingsStore.h
2//
3/////////////////////////////////////////////////////////////////////////////
4//
5// Copyright (c) 2002 Iain Murray
6//
7/////////////////////////////////////////////////////////////////////////////
8
9
10
11#ifndef __SettingsStore_h__
12#define __SettingsStore_h__
13
14
15#include "MSVC_Unannoy.h"
16#include <string>
17#include <map>
18
19
20/*
21 The public interface uses UTF-8 strings. All Keys should be
22 in American English and encodable in ASCII. However,
23 string Values may contain special characters where appropriate.
24*/
25
26
27class CSettingsStore
28{
29public:
30 bool GetBoolOption(const std::string& Key);
31 long GetLongOption(const std::string& Key);
32 std::string& GetStringOption(const std::string& Key);
33
34 void SetBoolOption(const std::string& Key, bool Value);
35 void SetLongOption(const std::string& Key, long Value);
36 void SetStringOption(const std::string& Key, const std::string& Value);
37
38 void SetBoolDefault(const std::string& Key, bool Value);
39 void SetLongDefault(const std::string& Key, long Value);
40 void SetStringDefault(const std::string& Key, const std::string& Value);
41private:
42 // Platform Specific settings file management
43
44 // LoadSetting changes Value only if it succeeds in loading the setting,
45 // in which case it also returns true. Failure is indicated by returning false.
46 //! Load a setting with a boolean value
47 //
48 //! Load a setting with a boolean value. Return true if successful
49 //! \param Key Name of the setting
50 //! \param Value Value of the setting
51 virtual bool LoadSetting(const std::string& Key, bool* Value);
52
53 //! Load a setting with a long value
54 //
55 //! Load a setting with a long value. Return true if successful
56 //! \param Key Name of the setting
57 //! \param Value Value of the setting
58 virtual bool LoadSetting(const std::string& Key, long* Value);
59
60 //! Load a setting with a string value
61 //
62 //! Load a setting with a string value. Return true if successful
63 //! \param Key Name of the setting
64 //! \param Value Value of the setting, UTF8 encoded
65 virtual bool LoadSetting(const std::string& Key, std::string* Value);
66
67 //! Save a setting with a boolean value
68 //
69 //! \param Key Name of the setting
70 //! \param Value Value of the setting
71 virtual void SaveSetting(const std::string& Key, bool Value);
72
73 //! Save a setting with a long value
74 //
75 //! \param Key Name of the setting
76 //! \param Value Value of the setting
77 virtual void SaveSetting(const std::string& Key, long Value);
78
79 //! Save a setting with a string value
80 //
81 //! \param Key Name of the setting
82 //! \param Value Value of the setting, UTF8 encoded
83 virtual void SaveSetting(const std::string& Key, const std::string& Value);
84
85 // Used to store settings in memory
86 std::map<std::string, bool> BoolMap;
87 std::map<std::string, long> LongMap;
88 std::map<std::string, std::string> StringMap;
89};
90
91
92#endif /* #ifndef __SettingsStore_h__ */
diff --git a/inputmethods/dasher/config.in b/inputmethods/dasher/config.in
new file mode 100644
index 0000000..44232dd
--- a/dev/null
+++ b/inputmethods/dasher/config.in
@@ -0,0 +1,5 @@
1 config DASHER
2 boolean "opie-dasher (zooming predictive text input)"
3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 )
5
diff --git a/inputmethods/dasher/dasher.pro b/inputmethods/dasher/dasher.pro
new file mode 100644
index 0000000..7b6def9
--- a/dev/null
+++ b/inputmethods/dasher/dasher.pro
@@ -0,0 +1,57 @@
1 TEMPLATE= lib
2 CONFIG += qt warn_on release
3
4HEADERS = Alphabet.h \
5 DasherModel.h \
6 FrameRate.h \
7 AlphabetMap.h \
8 DasherNode.h \
9 LanguageModel.h \
10 AlphIO.h \
11 DasherScreen.h \
12 PPMLanguageModel.h \
13 Context.h \
14 DasherSettingsInterface.h \
15 QtDasherImpl.h \
16 CustomAlphabet.h \
17 DasherTypes.h \
18 QtDasherPlugin.h \
19 DashEdit.h \
20 DasherView.h \
21 QtDasherScreen.h \
22 DasherAppInterface.h \
23 DasherViewSquare.h \
24 SettingsStore.h \
25 DasherInterface.h \
26 DasherWidgetInterface.h
27SOURCES = Alphabet.cpp \
28 DasherModel.cpp \
29 LanguageModel.cpp \
30 AlphabetMap.cpp \
31 DasherNode.cpp \
32 PPMLanguageModel.cpp \
33 AlphIO.cpp \
34 DasherSettingsInterface.cpp \
35 SettingsStore.cpp \
36 CustomAlphabet.cpp \
37 DasherView.cpp \
38 DasherInterface.cpp \
39 DasherViewSquare.cpp \
40 QtDasherImpl.cc \
41 QtDasherPlugin.cc \
42 QtDasherScreen.cc
43 TARGET = qdasher
44 DESTDIR = ../../plugins/inputmethods
45INCLUDEPATH += $(OPIEDIR)/include
46DEPENDPATH += ../$(OPIEDIR)/include ../../launcher
47LIBS += -lqpe
48 QMAKE_LFLAGS+= -Wl,-rpath,/opt/QtPalmtop/plugins/inputmethods
49 VERSION = 1.0.0
50 SUBDIRS = DasherCore
51
52
53include ( $(OPIEDIR)/include.pro )
54target.path = $$prefix/plugins/inputmethods
55
56
57
diff --git a/inputmethods/dasher/opie-dasher-english.control b/inputmethods/dasher/opie-dasher-english.control
new file mode 100644
index 0000000..c2cee2e
--- a/dev/null
+++ b/inputmethods/dasher/opie-dasher-english.control
@@ -0,0 +1,12 @@
1Package: opie-dasher-english
2Files: share/dasher/training_english_GB.txt
3Priority: optional
4Section: opie/inputmethods
5Maintainer: Matthew Garrett <mjg59@srcf.ucam.org>
6Architecture: arm
7Version: $QPE_VERSION-1
8Depends: opie-dasher
9Description: Dasher text input method
10 Dasher is a novel zooming text entry method that allows significantly faster
11 text entry than traditional methods. This package provides the necessary
12 data file to allow it to make predictions in English.
diff --git a/inputmethods/dasher/opie-dasher.control b/inputmethods/dasher/opie-dasher.control
new file mode 100644
index 0000000..586b88a
--- a/dev/null
+++ b/inputmethods/dasher/opie-dasher.control
@@ -0,0 +1,11 @@
1Package: opie-dasher
2Files: plugins/inputmethods/libqdasher.so* share/dasher/alphabet.xml
3Priority: optional
4Section: opie/inputmethods
5Maintainer: Matthew Garrett <mjg59@srcf.ucam.org>
6Architecture: arm
7Version: $QPE_VERSION-1
8Depends: task-opie-minimal
9Description: Dasher text input method
10 Dasher is a novel zooming text entry method that allows significantly faster
11 text entry than traditional methods.
diff --git a/inputmethods/dasher/opie-dasher.postinst b/inputmethods/dasher/opie-dasher.postinst
new file mode 100644
index 0000000..b9ac6f0
--- a/dev/null
+++ b/inputmethods/dasher/opie-dasher.postinst
@@ -0,0 +1,7 @@
1#!/bin/sh
2if pidof -s qpe >/dev/null; then
3 /opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadInputMethods()"
4else
5 exit 0
6fi
7
diff --git a/inputmethods/dasher/opie-dasher.postrm b/inputmethods/dasher/opie-dasher.postrm
new file mode 100644
index 0000000..c254b01
--- a/dev/null
+++ b/inputmethods/dasher/opie-dasher.postrm
@@ -0,0 +1,2 @@
1#!/bin/sh
2/opt/QtPalmtop/bin/qcop QPE/TaskBar "reloadInputMethods()"