add seekpointer
[enigma2.git] / lib / gui / einputstring.cpp
1 #include <lib/gui/einputstring.h>
2
3 DEFINE_REF(eInputContentString);
4
5 eInputContentString::eInputContentString()
6 {
7         m_string = "bla";
8         m_cursor = 0;
9         m_input = 0;
10         m_len = m_string.size();
11 }
12
13 void eInputContentString::getDisplay(std::string &res, int &cursor)
14 {
15         res = m_string;
16         cursor = m_cursor;
17 }
18
19 void eInputContentString::moveCursor(int dir)
20 {
21         int old_cursor = m_cursor;
22         
23         switch (dir)
24         {
25         case dirLeft:
26                 --m_cursor;
27                 break;
28         case dirRight:
29                 ++m_cursor;
30                 break;
31         case dirHome:
32                 m_cursor = 0;
33                 break;
34         case dirEnd:
35                 m_cursor = m_len;
36                 break;
37         }
38         
39         if (m_cursor < 0)
40                 m_cursor = 0;
41         if (m_cursor > m_len)
42                 m_cursor = m_len;
43         
44         if (m_cursor != old_cursor)
45                 if (m_input)
46                         m_input->invalidate();
47 }
48
49 int eInputContentString::haveKey(int code, int overwrite)
50 {
51         int have_char = -1;
52
53         if (code >= 0x8020)
54                 have_char = code &~ 0x8000;
55         
56         if (have_char != -1)
57         {
58                 if (overwrite && m_cursor < m_len)
59                         m_string[m_cursor] = have_char;
60                 else
61                 {
62                         m_string.insert(m_cursor, 1, have_char);
63                         ++m_len;
64                 }
65                 
66                 m_cursor++;
67                 
68                 assert(m_cursor <= m_len);
69  
70                 if (m_input)
71                         m_input->invalidate();
72                 return 1;
73         }
74         return 0;
75 }
76
77 void eInputContentString::deleteChar(int dir)
78 {
79         if (dir == deleteForward)
80         {
81                 eDebug("forward");
82                 if (m_cursor != m_len)
83                         ++m_cursor;
84                 else
85                         return;
86         }
87                 /* backward delete at begin */
88         if (!m_cursor)
89                 return;
90         
91         if (!m_len)
92                 return;
93         
94         m_string.erase(m_cursor - 1, m_cursor);
95         
96         m_len--;
97         m_cursor--;
98
99         if (m_input)
100                 m_input->invalidate();
101 }
102
103 int eInputContentString::isValid()
104 {
105         return 1;
106 }
107
108 void eInputContentString::validate()
109 {
110 }
111
112 void eInputContentString::setText(const std::string &str)
113 {
114         m_string = str;
115         m_len = m_string.size();
116         if (m_cursor > m_len)
117                 m_cursor = m_len;
118         
119         if (m_input)
120                 m_input->invalidate();
121 }
122
123 std::string eInputContentString::getText()
124 {
125         return m_string;
126 }