AWind
MobileKBWindow.h
1 #pragma once
2 #include "TextBoxString.h"
3 #include "TextBoxEditString.h"
4 #include "TextBoxChar.h"
5 #include "IDialogClosedEventReceiver.h"
6 #include "DecoratorPrimitives.h"
7 #include "Dialog.h"
8 
9 extern uint8_t BigFont[];
10 extern uint8_t SmallFont[];
11 
12 static const char mkbCaps[31] PROGMEM = "QWERTYUIOPASDFGHJKL\"ZXCVBNM;,.";
13 static const char mkbSm[31] PROGMEM = "qwertyuiopasdfghjkl\"zxcvbnm;,.";
14 static const char mkbNumSym[31] PROGMEM = "1234567890@#$%&-+_=/[]{}()<>,.";
15 
16 class MobileKBWindow : public Dialog
17 {
18  TextBoxEditString * _editField;
19  TextBoxChar * _btnWins[30];
20  //TextBoxFString * _btnOK;
21  //TextBoxFString * _btnCancel;
22  TextBoxFString * _btnBckSpc;
23  TextBoxFString * _btnCaps;
24  TextBoxFString * _btnNumSym;
25  TextBoxFString * _btnSpaceBar;
26  TextBoxFString * _btnClear;
27 
28  char let[31];
29  int curLetters;
30  const static int _butSize=22;
31  const static int _butSpace=4;
32  const static int _butSizeSpace=_butSize+_butSpace;
33  const static int _textOffset=3;
34  const static int _btn2W = _butSize*2 + _butSpace;
35  const static int _btn10W = 10*_butSizeSpace+_butSpace;
36 public:
37  MobileKBWindow(int left,int top):Dialog(left,top,12*_butSizeSpace+_butSpace,5*_butSizeSpace+_butSpace)
38  {
39  int i,k, len=30, p=0, x=_butSpace, y=_butSpace, tSmOff=5;
40  char c;
41 
42  GetLetters(mkbCaps, 30);
43  curLetters = 0;
44 
45  _editField=new TextBoxEditString(x,y,Width()-2*_butSpace,_butSize,"");
46  initTextBox(_editField);
47  _editField->SetDecorators(Environment::Get()->FindDecorators(F("EditTextBoxReadOnly")));
48  _editField->SetFont(BigFont);
49 
50  DecoratorList * btnDecorators=Environment::Get()->FindDecorators(F("Button"));
51  y+=_butSize+_butSpace;
52  for(k=0;k<3;k++)
53  {
54  for(i=0;i<10;i++)
55  {
56  x=i*(_butSize+_butSpace);
57  c = let[p];
58  _btnWins[p]=new TextBoxChar(x+_butSpace,y,_butSize,_butSize,c);
59  _btnWins[p]->SetDecorators(btnDecorators);
60  initTextBox(_btnWins[p]);
61  p++;
62  }
63  y+=_butSize+_butSpace;
64  }
65 
66  y=_butSizeSpace+_butSpace;
67  _btnBckSpc=new Button(_btn10W,y,_btn2W,_butSize,F("BckSpc"));
68  initTextBox(_btnBckSpc);
69  _btnBckSpc->SetFont(SmallFont);
70  _btnBckSpc->SetMargins(1,tSmOff);
71 
72  y+=_butSize+_butSpace;
73  _btnOK=new Button(_btn10W,y,_btn2W,_butSize,F("Enter"));
74  initTextBox(_btnOK);
75  _btnOK->SetFont(SmallFont);
76  _btnOK->SetMargins(4,tSmOff);
77 
78  y+=2*(_butSize+_butSpace);
79  _btnCaps=new Button(_butSpace,y,_btn2W,_butSize,F("aA"));
80  initTextBox(_btnCaps);
81  _btnCaps->SetMargins(7,2);
82 
83  _btnNumSym=new Button(2*_butSizeSpace+_butSpace,y,_btn2W,_butSize,F("1&"));
84  initTextBox(_btnNumSym);
85  _btnNumSym->SetMargins(7,2);
86 
87  _btnSpaceBar=new Button(4*_butSizeSpace+_butSpace,y,_btn2W*2+_butSpace,_butSize,F("Space"));
88  initTextBox(_btnSpaceBar);
89  _btnSpaceBar->SetFont(SmallFont);
90  _btnSpaceBar->SetMargins(32,tSmOff);
91 
92  _btnClear=new Button(8*_butSizeSpace+_butSpace,y,_btn2W,_butSize,F("Clear"));
93  initTextBox(_btnClear);
94  _btnClear->SetFont(SmallFont);
95  _btnClear->SetMargins(4,tSmOff);
96 
97  _btnCancel=new Button(_btn10W,y,_btn2W,_butSize,F("Cancel"));
98  initTextBox(_btnCancel);
99  _btnCancel->SetFont(SmallFont);
100  _btnCancel->SetMargins(1,tSmOff);
101 
102  }
103 protected:
104  void initTextBox(TextBox *text)
105  {
106  text->SetFont(BigFont);
107  text->SetMargins(_textOffset,_textOffset);
108  text->RegisterTouchEventReceiver(this);
109  AddChild(text);
110  }
111 private:
112  void SetBtns()
113  {
114  char c;
115  int i;
116  for(i=0;i<28;i++) {
117  c = let[i];
118  _btnWins[i]->SetChar(c);
119  }
120  }
121  void GetLetters(const char* buf, int len=28)
122  {
123  int i;
124  for(i=0;i<len;i++) {
125  let[i] = pgm_read_byte_near(buf + i);
126  }
127  }
128 
129 public:
130  void Initialize(char *txt)
131  {
132  _editField->SetText(txt);
133  _editField->Invalidate();
134  }
135  void Finalization()
136  {
137  _editField->Closed();
138  }
139  char * GetText()
140  {
141  return _editField->GetText();
142  }
143  void DoControlMessage(Window *window)
144  {
145  /*if((window == _btnOK) || (window == _btnCancel))
146  {
147  if(_dialogClosedEventReceiver!=NULL) {
148  _dialogClosedEventReceiver->NotifyDialogClosed(this,window == _btnOK?IDialogClosedEventReceiver::OK : IDialogClosedEventReceiver::Cancel);
149  _editField->Closed();
150  }
151  }
152  else*/
153  if ((window == _btnCaps) || (window == _btnNumSym))
154  {
155  if (window == _btnCaps)
156  {
157  if (*let == *mkbNumSym)
158  (curLetters == 1)? GetLetters(mkbSm) : GetLetters(mkbCaps);
159  else
160  {
161  (*let == *mkbCaps)? GetLetters(mkbSm) : GetLetters(mkbCaps);
162  curLetters = !curLetters;
163  }
164  }
165  else
166  {
167  if (*let == *mkbNumSym)
168  return;
169  GetLetters(mkbNumSym);
170  }
171  SetBtns();
172  }
173  else
174  {
175  byte b;
176  if (window == _btnBckSpc) b = 8; else
177  if (window == _btnClear) b = 13; else
178  if (window == _btnSpaceBar) b = (byte)' '; else
179  {
180  for(int i=0;i<30;i++)
181  if (window == _btnWins[i])
182  {
183  b = (byte)_btnWins[i]->GetChar();
184  break;
185  }
186  }
187  _editField->UpdateEdit(b);
188  }
189  }
190 };
void DoControlMessage(Window *window)
Need to be redefinded in derived class.
Definition: MobileKBWindow.h:143
void RegisterTouchEventReceiver(ITouchEventReceiver *touchEventReceiver)
Registers receiver for touch event.
Definition: Window.h:102
Definition: MobileKBWindow.h:16
Base class for all window objects. Provides basic window functionality.
Definition: Window.h:34
Definition: TextBoxChar.h:4
void SetFont(uint8_t *font)
Sets font.
Definition: TextBox.h:64
Base class for window with text content.
Definition: TextBox.h:30
Button * _btnCancel
Button Cancel has to be initialized in derived class.
Definition: Dialog.h:32
Definition: TextBoxEditString.h:4
static Environment * Get()
Returns singltone instance of environment.
Definition: Environment.h:44
Button * _btnOK
Button OK has to be initialized in derived class.
Definition: Dialog.h:30
Base class for dialog objects. See Dialogs example Provides basic window functionality.
Definition: Dialog.h:25
void Invalidate()
If function is called than the window manager updates the window.
Definition: Window.h:157
void AddChild(Window *window)
Adds window child window.
Definition: Window.h:194
virtual void SetDecorators(DecoratorList *decorators)
Sets window decorators list.
Definition: Window.h:76
Dialog(const __FlashStringHelper *caption, int left, int top, int width, int height)
Constructor for dialog with caption.
Definition: Dialog.h:42
Implement button control.
Definition: Button.h:24
DecoratorList * FindDecorators(const __FlashStringHelper *id)
Finds registered decorators by the name.
Definition: Environment.h:59
int Width()
Returns window width.
Definition: Window.h:184
void SetMargins(int offset_x, int offset_y)
Defines offset from left and top for text.
Definition: TextBox.h:58