Add typing listener (to store strings), deregister listeners on delete

This commit is contained in:
simon.kagstrom 2009-12-26 09:16:19 +00:00
parent aa0d8246bb
commit 0a3bc3e081
3 changed files with 27 additions and 0 deletions

View File

@ -1,5 +1,15 @@
#include "menu.hh"
class KeyboardTypingListener : public StringListener
{
virtual void stringCallback(const char *str)
{
printf("string: %s\n", str);
/* Remove thyself! */
delete this;
}
};
class MainView;
class MainMenu : public Menu, KeyListener
{
@ -75,6 +85,8 @@ public:
Gui::gui->pushView(Gui::gui->kv);
Gui::gui->kv->activate();
Gui::gui->kv->registerKeyListener(this);
if (this->p_submenus[2].sel == 0)
Gui::gui->kv->registerStringListener(new KeyboardTypingListener());
break;
case 11:

View File

@ -376,3 +376,14 @@ void VirtualKeyboard::updateTheme()
/* The singleton */
VirtualKeyboard *VirtualKeyboard::kbd;
KeyListener::~KeyListener()
{
VirtualKeyboard::kbd->unregisterKeyListener(this);
}
StringListener::~StringListener()
{
VirtualKeyboard::kbd->unregisterStringListener(this);
}

View File

@ -23,6 +23,8 @@ struct virtkey;
class KeyListener
{
public:
~KeyListener();
/* Each key is a string */
virtual void keyCallback(bool shift, const char *str) = 0;
};
@ -30,6 +32,8 @@ public:
class StringListener
{
public:
~StringListener();
virtual void stringCallback(const char *str) = 0;
};