The code for a T9 input method, quite empty yet. WIP.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25996 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2008-06-17 16:32:42 +00:00
parent 4122d6c0c0
commit 087bd9e838
7 changed files with 680 additions and 0 deletions

View File

@ -0,0 +1,204 @@
/*
Copyright 2005, Francois Revol. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <Debug.h>
#include <List.h>
#include <Message.h>
#include <OS.h>
#include <Application.h>
#include <Alert.h>
#include <Menu.h>
#include <MenuItem.h>
#include <Handler.h>
#include <Locker.h>
#include <Autolock.h>
#include <add-ons/input_server/InputServerMethod.h>
#ifndef _T
#define _T(s) s
#endif
#include "T9Icon.h"
extern "C" _EXPORT BInputServerMethod* instantiate_input_method();
enum T9Mode {
WordMode,
CharMode,
NumMode
};
// modes: =Abc / Abc / 123
// flags: Abc / ABC / abc
class T9InputServerMethod : public BInputServerMethod, public BHandler
{
public:
T9InputServerMethod();
virtual ~T9InputServerMethod();
virtual filter_result Filter(BMessage *message, BList *outList);
virtual status_t MethodActivated(bool active);
virtual void MessageReceived(BMessage *message);
bool IsEnabled() const { return fEnabled; };
T9Mode Mode() const { return fMode; };
void SetMode(T9Mode mode);
private:
bool fEnabled;
T9Mode fMode;
BMenu *fDeskbarMenu;
BLocker fLocker;
BString fTyped; /* what has been typed so far for the current word */
};
BInputServerMethod* instantiate_input_method()
{
PRINT(("%s\n", __FUNCTION__));
return (new T9InputServerMethod());
}
T9InputServerMethod::T9InputServerMethod()
: BInputServerMethod("T9", T9IconData),
BHandler("T9IMHandler"),
fEnabled(false),
fMode(WordMode),
fDeskbarMenu(NULL),
fLocker("T9IM")
{
PRINT(("%s\n", __FUNCTION__));
if (be_app) {
be_app->Lock();
be_app->AddHandler(this);
be_app->Unlock();
}
//
fDeskbarMenu = new BMenu(_T("Mode"));
BMessage *msg = new BMessage('SetM');
msg->AddInt32("t9mode", WordMode);
BMenuItem *item;
item = new BMenuItem(_T("Word Mode"), msg);
item->SetMarked(true);
fDeskbarMenu->AddItem(item);
msg = new BMessage('SetM');
msg->AddInt32("t9mode", CharMode);
item = new BMenuItem(_T("Character Mode"), msg);
fDeskbarMenu->AddItem(item);
msg = new BMessage('SetM');
msg->AddInt32("t9mode", NumMode);
item = new BMenuItem(_T("Numeric Mode"), msg);
fDeskbarMenu->AddItem(item);
fDeskbarMenu->SetFont(be_plain_font);
// doesn't seem to work here
//fDeskbarMenu->SetRadioMode(true);
//fDeskbarMenu->SetLabelFromMarked(true);
SetMenu(fDeskbarMenu, BMessenger(this));
}
T9InputServerMethod::~T9InputServerMethod()
{
PRINT(("%s\n", __FUNCTION__));
SetMenu(NULL, BMessenger());
delete fDeskbarMenu;
if (be_app) {
be_app->Lock();
be_app->RemoveHandler(this);
be_app->Unlock();
}
}
filter_result T9InputServerMethod::Filter(BMessage *message, BList *outList)
{
status_t err;
filter_result res = B_DISPATCH_MESSAGE;
bool keyUp = false;
BString bytes;
if (!IsEnabled())
return B_DISPATCH_MESSAGE;
switch (message->what) {
case B_KEY_UP:
keyUp = true;
case B_KEY_DOWN:
if (message->FindString("bytes", &bytes) < B_OK)
break;
if (bytes.Length() == 1) {
BAutolock l(fLocker);
if (fMode == NumMode)
break;
}
break;
default:
break;
}
return (res);
}
status_t T9InputServerMethod::MethodActivated(bool active)
{
fEnabled = active;
return BInputServerMethod::MethodActivated(active);
}
void T9InputServerMethod::MessageReceived(BMessage *message)
{
int32 v;
switch (message->what) {
case 'SetM':
if (message->FindInt32("t9mode", &v) < B_OK)
break;
SetMode((T9Mode)v);
/*{
BString s;
s << v;
s << " - ";
s << (long) fDeskbarMenu->FindMarked();
s << " - ";
s << (long) fDeskbarMenu->ItemAt(v);
BAlert *a = new BAlert("Plop", s.String(), "Ok");
a->Go(NULL);
}*/
break;
default:
BHandler::MessageReceived(message);
break;
}
}
void T9InputServerMethod::SetMode(T9Mode mode)
{
BAutolock l(fLocker);
BMenuItem *item;
// XXX: check
fMode = mode;
item = fDeskbarMenu->FindMarked();
if (item)
item->SetMarked(false);
item = fDeskbarMenu->ItemAt((int32)mode);
if (item)
item->SetMarked(true);
// necessary to update the copy used by the Deskbar icon.
SetMenu(fDeskbarMenu, BMessenger(this));
}

View File

@ -0,0 +1,42 @@
/*
Copyright 2005, Francois Revol. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#ifndef _DICTIONARY_INPUT_SERVER_METHOD_H
#define _DICTIONARY_INPUT_SERVER_METHOD_H
#include <OS.h>
#include <Messenger.h>
#include <add-ons/input_server/InputServerMethod.h>
#if DEBUG
//#include <File.h>
class BAlert;
#endif
class BList;
class BMessage;
class DictionaryInputLooper;
class DictionaryInputServerMethod : public BInputServerMethod
{
public:
DictionaryInputServerMethod();
virtual ~DictionaryInputServerMethod();
virtual status_t InitCheck();
virtual filter_result Filter(BMessage *message, BList *outList);
virtual status_t MethodActivated(bool active);
bool IsEnabled() const { return fEnabled; };
private:
bool fEnabled;
//BLocker fLocker;
BMessenger fLooper;
#if DEBUG
//BFile fDebugFile;
BAlert *fDebugAlert;
#endif
};
#endif /* _DICTIONARY_INPUT_SERVER_METHOD_H */

View File

@ -0,0 +1,20 @@
// will need better, stippi ?
// should have icons showing modes (word/char/num + caps)
const uchar T9IconData[] = {
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,
0xFF,0x00,0x3F,0x3F,0x3F,0x3F,0x3F,0x00,0x00,0x3F,0x3F,0x3F,0x00,0xFF,0xFF,0xFF,
0xFF,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0x3F,0x00,0x3F,0x00,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x00,0x3F,0x00,0xFF,0xFF,0x00,0x3F,0x3F,0x3F,0x00,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x00,0x3F,0x00,0xFF,0xFF,0x00,0x00,0x00,0x3F,0x00,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x00,0x3F,0x00,0xFF,0xFF,0x00,0x3F,0x3F,0x3F,0x00,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

View File

@ -0,0 +1,204 @@
/*
Copyright 2005, Francois Revol. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <Debug.h>
#include <List.h>
#include <Message.h>
#include <OS.h>
#include <Application.h>
#include <Alert.h>
#include <Menu.h>
#include <MenuItem.h>
#include <Handler.h>
#include <Locker.h>
#include <Autolock.h>
#include <add-ons/input_server/InputServerMethod.h>
#ifndef _T
#define _T(s) s
#endif
#include "T9Icon.h"
extern "C" _EXPORT BInputServerMethod* instantiate_input_method();
enum T9Mode {
WordMode,
CharMode,
NumMode
};
// modes: =Abc / Abc / 123
// flags: Abc / ABC / abc
class T9InputServerMethod : public BInputServerMethod, public BHandler
{
public:
T9InputServerMethod();
virtual ~T9InputServerMethod();
virtual filter_result Filter(BMessage *message, BList *outList);
virtual status_t MethodActivated(bool active);
virtual void MessageReceived(BMessage *message);
bool IsEnabled() const { return fEnabled; };
T9Mode Mode() const { return fMode; };
void SetMode(T9Mode mode);
private:
bool fEnabled;
T9Mode fMode;
BMenu *fDeskbarMenu;
BLocker fLocker;
BString fTyped; /* what has been typed so far for the current word */
};
BInputServerMethod* instantiate_input_method()
{
PRINT(("%s\n", __FUNCTION__));
return (new T9InputServerMethod());
}
T9InputServerMethod::T9InputServerMethod()
: BInputServerMethod("T9", T9IconData),
BHandler("T9IMHandler"),
fEnabled(false),
fMode(WordMode),
fDeskbarMenu(NULL),
fLocker("T9IM")
{
PRINT(("%s\n", __FUNCTION__));
if (be_app) {
be_app->Lock();
be_app->AddHandler(this);
be_app->Unlock();
}
//
fDeskbarMenu = new BMenu(_T("Mode"));
BMessage *msg = new BMessage('SetM');
msg->AddInt32("t9mode", WordMode);
BMenuItem *item;
item = new BMenuItem(_T("Word Mode"), msg);
item->SetMarked(true);
fDeskbarMenu->AddItem(item);
msg = new BMessage('SetM');
msg->AddInt32("t9mode", CharMode);
item = new BMenuItem(_T("Character Mode"), msg);
fDeskbarMenu->AddItem(item);
msg = new BMessage('SetM');
msg->AddInt32("t9mode", NumMode);
item = new BMenuItem(_T("Numeric Mode"), msg);
fDeskbarMenu->AddItem(item);
fDeskbarMenu->SetFont(be_plain_font);
// doesn't seem to work here
//fDeskbarMenu->SetRadioMode(true);
//fDeskbarMenu->SetLabelFromMarked(true);
SetMenu(fDeskbarMenu, BMessenger(this));
}
T9InputServerMethod::~T9InputServerMethod()
{
PRINT(("%s\n", __FUNCTION__));
SetMenu(NULL, BMessenger());
delete fDeskbarMenu;
if (be_app) {
be_app->Lock();
be_app->RemoveHandler(this);
be_app->Unlock();
}
}
filter_result T9InputServerMethod::Filter(BMessage *message, BList *outList)
{
status_t err;
filter_result res = B_DISPATCH_MESSAGE;
bool keyUp = false;
BString bytes;
if (!IsEnabled())
return B_DISPATCH_MESSAGE;
switch (message->what) {
case B_KEY_UP:
keyUp = true;
case B_KEY_DOWN:
if (message->FindString("bytes", &bytes) < B_OK)
break;
if (bytes.Length() == 1) {
BAutolock l(fLocker);
if (fMode == NumMode)
break;
}
break;
default:
break;
}
return (res);
}
status_t T9InputServerMethod::MethodActivated(bool active)
{
fEnabled = active;
return BInputServerMethod::MethodActivated(active);
}
void T9InputServerMethod::MessageReceived(BMessage *message)
{
int32 v;
switch (message->what) {
case 'SetM':
if (message->FindInt32("t9mode", &v) < B_OK)
break;
SetMode((T9Mode)v);
/*{
BString s;
s << v;
s << " - ";
s << (long) fDeskbarMenu->FindMarked();
s << " - ";
s << (long) fDeskbarMenu->ItemAt(v);
BAlert *a = new BAlert("Plop", s.String(), "Ok");
a->Go(NULL);
}*/
break;
default:
BHandler::MessageReceived(message);
break;
}
}
void T9InputServerMethod::SetMode(T9Mode mode)
{
BAutolock l(fLocker);
BMenuItem *item;
// XXX: check
fMode = mode;
item = fDeskbarMenu->FindMarked();
if (item)
item->SetMarked(false);
item = fDeskbarMenu->ItemAt((int32)mode);
if (item)
item->SetMarked(true);
// necessary to update the copy used by the Deskbar icon.
SetMenu(fDeskbarMenu, BMessenger(this));
}

View File

@ -0,0 +1 @@
/system/servers/input_server

View File

@ -0,0 +1,187 @@
## ********************************* ##
## Zeta Generic Makefile v3.0 ##
## Fill in this file to specify the project being created, and the referenced
## makefile-engine will do all of the hard work for you.
## Application Specific Settings ---------------------------------------------
# specify the name of the binary
NAME := T9
# specify the type of binary
# APP: Application
# SHARED: Shared library or add-on
# STATIC: Static library archive
# DRIVER: Kernel Driver
# MODULE: Kernel Module
# DECOR: A window decorator project
TYPE := SHARED
# add support for new Pe and Eddie features
# to fill in generic makefile
#%{
# @src->@
# specify the source files to use
# full paths or paths relative to the makefile can be included
# all files, regardless of directory, will have their object
# files created in the common object directory.
# Note that this means this makefile will not work correctly
# if two source files with the same name (source.c or source.cpp)
# are included from different directories. Also note that spaces
# in folder names do not work well with this makefile.
SRCS := T9InputServerMethod.cpp
# specify the resource files to use
# full path or a relative path to the resource file can be used.
RSRCS :=
# Specify your RDEF files, if any.
RDEFS :=
# @<-src@
#%}
# end support for Pe and Eddie
# specify additional libraries to link against
# there are two acceptable forms of library specifications
# - if your library follows the naming pattern of:
# libXXX.so or libXXX.a you can simply specify XXX
# library: libbe.so entry: be
#
# - if your library does not follow the standard library
# naming scheme you need to specify the path to the library
# and it's name
# library: my_lib.a entry: my_lib.a or path/my_lib.a
LIBS := _APP_ be
# specify additional paths to directories following the standard
# libXXX.so or libXXX.a naming scheme. You can specify full paths
# or paths relative to the makefile. The paths included may not
# be recursive, so include all of the paths where libraries can
# be found. Directories where source files are found are
# automatically included.
LIBPATHS :=
# additional paths to look for system headers
# thes use the form: #include <header>
# source file directories are NOT auto-included here
SYSTEM_INCLUDE_PATHS :=
# additional paths to look for local headers
# thes use the form: #include "header"
# source file directories are automatically included
LOCAL_INCLUDE_PATHS :=
# specify the level of optimization that you desire
# NONE, SOME, FULL
OPTIMIZE :=
# specify any preprocessor symbols to be defined. The symbols will not
# have their values set automatically; you must supply the value (if any)
# to use. For example, setting DEFINES to "DEBUG=1" will cause the
# compiler option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG"
# would pass "-DDEBUG" on the compiler's command line.
DEFINES :=
# specify special warning levels
# if unspecified default warnings will be used
# NONE = supress all warnings
# ALL = enable all warnings
WARNINGS :=
# specify whether image symbols will be created
# so that stack crawls in the debugger are meaningful
# if TRUE symbols will be created
SYMBOLS :=
# specify debug settings
# if TRUE will allow application to be run from a source-level
# debugger. Note that this will disable all optimzation.
DEBUGGER :=
# specify additional compiler flags for all files
COMPILER_FLAGS :=
# specify additional linker flags
LINKER_FLAGS :=
# specify the version of this particular item
# (for example, -app 3 4 0 d 0 -short 340 -long "340 "`echo -n -e '\302\251'`"1999 GNU GPL")
#E This may also be specified in a resource.
APP_VERSION :=
# (for TYPE == DRIVER only) Specify desired location of driver in the /dev
# hierarchy. Used by the driverinstall rule. E.g., DRIVER_PATH = video/usb will
# instruct the driverinstall rule to place a symlink to your driver's binary in
# ~/add-ons/kernel/drivers/dev/video/usb, so that your driver will appear at
# /dev/video/usb when loaded. Default is "misc".
DRIVER_PATH :=
# Specify if you want the object files to be somewhere besides the default location.
OBJ_DIR :=
# Specify a non default placement for the target
TARGET_DIR :=
# Specify a directory for the 'install' target.
INSTALL_DIR :=
# Specify the name of this makefile.
# If you leave this blank, the makefile will not be considered as part of the
# dependenies for the project, and the project will not be rebuilt when the makefile
# is changed
MAKEFILE :=
# Specify TRUE if you want the install target to create links in the BeMenu
MENU_LINKS :=
# Related to MENU_LINKS, specify the name of the direcotry in the BeMenu
# you wish the link to go in. If the directory does not exist, it will be
# created.
APP_MENU :=
# If, for some reason, you don't want to use the dependencies (flex and yacc seem to choke
# on them), set this to false
DODEPS :=
# Set this variable if you have an svg text file you wish to use as your targets
# icon.
SVG_ICON :=
# If you have some fancy custom build steps to do, specify them here
EXTRA_BUILD_STEPS =
# If you have some other files that should trigger a re-link, such as libs in the same
# project that may get rebuilt, specify the full path to them here.
EXTRA_DEPS :=
###########################################################################################
# The following variables are commented out here because the can be very useful to just
# set at the command line or in the env at time of compiling, allowing you to leave your
# makefile the same, but change the build types easily.
# If you wish to have the program output a profiling session file which can be read by bprof,
# set this to 'true'
#BUILD_PROFILE :=
# If you wish to have a debug build,
# set this to 'true'
#BUILD_DEBUG :=
# If you wish to have a build which can do memory checking when MALLOC_DEBUG=15 is set,
# set this to 'true'
#CHECK_MEM :=
# If you want to see the complete build line for every file, then set this to 'true',
# otherwise it will tell you at the end what the build flags were.
#CHATTY :=
## include the makefile-engine
include $(BUILDHOME)/etc/makefile-engine

View File

@ -0,0 +1,22 @@
test of possible UTF-8 glyphs usable to notify T9 mode like is done on phones (usually "123", "abc", "Abc", "ABC", and the same with some dots on the left implying speed for dictionary modes).
It's probably simpler to use icons anyway.
//Abc
≡Abc
≫Abc
≒Abc
∴Abc
∵Abc
∷Abc
<EFBFBD><EFBFBD><EFBFBD>Abc
<EFBFBD><EFBFBD><EFBFBD>Abc
⺀Abc
〃Abc
≈Abc
=Abc
#Abc
"Abc
'Abc
*Abc
µAbc
.:Abc
¨Abc