Newer
Older
scim-wnn / honoka / plugins / asciiinput.cpp
/***************************************************************************
 *   Copyright (C) 2005 by TAM(Teppei Tamra)                               *
 *   tam-t@par.odn.ne.jp                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "asciiinput.h"

#include <asciiplugin.h>

#ifdef HAVE_CONFIG_H
  #include <config.h>
#endif

#ifdef HAVE_GETTEXT
  #include <libintl.h>
  #define _(String) dgettext(GETTEXT_PACKAGE,String)
  #define N_(String) (String)
#else
  #define _(String) (String)
  #define N_(String) (String)
  #define bindtextdomain(Package,Directory)
  #define textdomain(domain)
  #define bind_textdomain_codeset(domain,codeset)
#endif

AsciiInput::AsciiInput(ConfigPointer cfg) : PreEditor(cfg)
{
    scim_string_to_key_list(lowProprotyKey,cfg->read(HONOKA_CONFIG_ASCIIINPUT_LOW_PRIORITY_KEY,String(HONOKA_DEFAULT_ASCIIINPUT_LOW_PRIORITY_KEY)));
    scim_string_to_key_list(autoCommitKey,cfg->read(HONOKA_CONFIG_ASCIIINPUT_AUTO_COMMIT_KEY,String(HONOKA_DEFAULT_ASCIIINPUT_AUTO_COMMIT_KEY)));
    autoCommit = cfg->read(HONOKA_CONFIG_ASCIIINPUT_AUTO_COMMIT,HONOKA_DEFAULT_ASCIIINPUT_AUTO_COMMIT);
}


AsciiInput::~AsciiInput()
{
}

/*!
    \fn AsciiInput::getModeName()
 */
String AsciiInput::getModeName()
{
    return String(_("Aa"));
}

/*!
    \fn AsciiInput::getName()
 */
String AsciiInput::getName()
{
    return String("AsciiInput");
}

/*!
    \fn AsciiInput::getPropertyName()
 */
String AsciiInput::getPropertyName()
{
    return String(_("AsciiInput"));
}


/*!
    \fn AsciiInput::inputEvent(const KeyEvent &key)
 */
bool AsciiInput::inputEvent(const KeyEvent &key)
{
    return keyEvent(key);
}



/*!
    \fn AsciiInput::keyEventHook(const KeyEvent &key)
 */
bool AsciiInput::keyEventHook(const KeyEvent &key)
{
    if (key.is_key_release()) return false;
    if (lowProprotyKey.comp(key)) return false;
    else return keyEvent(key);
}




/*!
    \fn Honoka::AsciiInput::keyEvent(const KeyEvent &key)
 */
bool Honoka::AsciiInput::keyEvent(const KeyEvent &key)
{
    // 喰っておくべきもの。
    if ((key.code == SCIM_KEY_Shift_L) ||
        (key.code == SCIM_KEY_Shift_R) ||
        (key.code == SCIM_KEY_Control_L) ||
        (key.code == SCIM_KEY_Control_R) ||
        (key.code == SCIM_KEY_Alt_L) ||
        (key.code == SCIM_KEY_Alt_R) ||
        (key.code == SCIM_KEY_Super_L) ||
        (key.code == SCIM_KEY_Super_R) ||
        (key.code == SCIM_KEY_Hyper_L) ||
        (key.code == SCIM_KEY_Hyper_R)) return true;

    if (autoCommit) {
        if (autoCommitKey.comp(key)) {
            String c;
            if (isprint(key.get_ascii_code())) c += key.get_ascii_code();
            setCommitString(text.substr(0,pos) + utf8_mbstowcs(c));
            reset();
            pos = 0;
            return true;
        }
    }

    if (isprint(key.get_ascii_code()) && (!key.is_alt_down()) && (!key.is_control_down())) {
        String c;
        c += key.get_ascii_code();
        text = text.substr(0,pos) + utf8_mbstowcs(c) + text.substr(pos);
        pos ++;
        return true;
    }
    return false;
}