/*************************************************************************** * Copyright (C) 2004 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 "preeditor.h" PreEditor::PreEditor() { iconvert.set_encoding ("EUC-JP"); } PreEditor::~PreEditor() { } WideString PreEditor::text = WideString(); int PreEditor::pos = 0; IConvert PreEditor::iconvert; /*! \fn PreEditor::getPos() */ int PreEditor::getPos() { return(pos); } /*! \fn PreEditor::getTextLength() */ int PreEditor::getTextLength() { return(text.length()); } /*! \fn PreEditor::setPos(int p) */ void PreEditor::setPos(int p) { if (p < 0) p = 0; else if (p > getTextLength()) p = getTextLength(); pos = p; } /*! \fn PreEditor::clear() */ void PreEditor::clear() { text.clear(); } /*! \fn PreEditor::insert(char k) */ WideString PreEditor::insert(char k) { if (k == 0) return(text); String s; s = k; text = text.substr(0,pos) + utf8_mbstowcs(s) + text.substr(pos); pos ++; return(getText()); } /*! \fn PreEditor::reset() */ void PreEditor::reset() { clear(); pos = 0; } /*! \fn PreEditor::getText(bool hosei) */ WideString PreEditor::getText(bool hosei) { return(text); } /*! \fn PreEditor::backspace() */ void PreEditor::backspace() { if (getPos() == 0) return; text = text.substr(0,pos - 1) + text.substr(pos); setPos(pos - 1); } /*! \fn PreEditor::del() */ void PreEditor::del() { if (getPos() == getTextLength()) return; text = text.substr(0,pos) + text.substr(pos + 1); } /*! \fn PreEditor::convHiraKata(WideString &t) */ void PreEditor::convHiraKata(WideString &t) { WideString start_c,end_c,conv_c; iconvert.convert(start_c,String("¤¡")); iconvert.convert(end_c,String("¤ó")); iconvert.convert(conv_c,String("¥¡")); for(unsigned int i = 0;i < t.size();i ++) { if ((t[i] >= start_c[0]) && (t[i] <= end_c[0])) t[i] = t[i] - start_c[0] + conv_c[0]; } return; } /*! \fn PreEditor::convKataHira(WideString &t) */ void PreEditor::convKataHira(WideString &t) { WideString start_c,end_c,conv_c; iconvert.convert(start_c,String("¥¡")); iconvert.convert(end_c,String("¥ó")); iconvert.convert(conv_c,String("¤¡")); for(unsigned int i = 0;i < t.size();i ++) { if ((t[i] >= start_c[0]) && (t[i] <= end_c[0])) t[i] = t[i] - start_c[0] + conv_c[0]; } return; } /*! \fn PreEditor::hiraKata() */ void PreEditor::hiraKata() { convHiraKata(text); } /*! \fn PreEditor::kataHira() */ void PreEditor::kataHira() { convKataHira(text); } /*! \fn PreEditor::keyEventHook(const KeyEvent &key) */ bool PreEditor::keyEventHook(const KeyEvent &key) { return(false); } /*! \fn PreEditor::getModeName() */ String PreEditor::getModeName() { String s; return(s); } /*! \fn PreEditor::cancelEvent() */ bool PreEditor::cancelEvent() { return(false); }