[Previous] [Next] [Contents]

CHAPTER 4. DEVELOPING APPLICATIONS

 

4.14 How to make Input Method (with demo example)

A. Overview

MIZI Prizm 2.0 input system supports simple API for plug-in developer, and farther supports to add input method, easily.
This section simply explains the work flow of input system for MIZI Prizm 2.0, and let’s to know how to add input method to the i519.

B. Structure

There are X11, Launcher, IM server, IM plug-ins that are taken part in the operation of input method system.

  • IM plug-ins can be added by 3rd party developer as the part which takes charge of input by users.
  • IM server takes charge of management of IM plug-ins and transfers the received character from plug-in to X11, sends information of plug-ins to Launcher. Also it handles the received information from X11 and Launcher, it sends to plug-in as occasion demands.
  • Launcher gives plug-ins information from IM server to users, sends the request of program and user to IM server.
  • X11 transfers the character and control information that is received from IM server to the input queued program.


  • C. Input Method Programming

  • Input Method is a kind of plug-ins. If you want to know about Plug-in, refer "4.9 Plug-in" Section. Directory location of plug-in is $LINUETTEDIR/plugin/inputmethod.
  • All input method must inherit class MzInputMEthod : public MzDockWidget, class MzInputMethod includes next three virtual function. Therefore, three functions must be re-defined.
  •   virtual QCString id () const = 0; 
    virtual QString icon () const = 0;
    virtual QString text () const = 0;

  • The size of input method depends main widget size of plug-in. When it must be changed size by real-time, it must be followed hide -> resize -> show steps.
  • If you want to send key event to the program, call “signal: void key (int keycode, int Unicode);”. For keycode, it can use Key_Return, Key_Tab, Key_Backspace, Key_Escape, Key_Right, Key_Left, Key_Up, Key_Down, Key_Delete, for Unicode, it can transfer various character.
  • Next source code is simple demo input method. When you click Input method screen, it can send “Key_Return” to the program.
  • File: im_demo.h
    #if !defined (__INPUTMETHOD_SAMPLE_H__) 
    #define __INPUTMETHOD_SAMPLE_H__

    #include <mzinputmethod.h>
    #include <mzcopchannel.h>

    class ImDemo : public MzInputMethod
    {
    Q_OBJECT
    public:
    ImDemo ();
    ~ImDemo ();


    /* Redefine for the three virtual function */
    virtual QCString id () const;
    virtual QString icon () const;
    virtual QString text () const;


    /* determine size of input method */
    virtual QSize sizeHint () const;

    protected:

    /* for click, to generate key event */
    virtual void mouseReleaseEvent (QMouseEvent *);
    };

    #endif /* __INPUTMETHOD_SAMPLE_H__ */

     

    File: im_demo.cpp
    #include <stdlib.h> 

    #include <mzapplication.h>
    #include <mzlibloader.h>

    #include "im_demo.h"


    ImDemo::ImDemo ()
    {
    }

    ImDemo::~ImDemo ()
    {
    }


    QCString ImDemo::id () const
    {

    /* key to distinguish other input method */
    return QCString ("demo_im");
    }


    QString ImDemo::icon () const
    {

    /* Icon name of input method */
    return QString ("demo_icon");
    }


    QString ImDemo::text () const
    {

    /* Icon name to output for user */
    return QString (tr ("Demo IM"));
    }

    QSize ImDemo::sizeHint () const
    {

    /* the width of input method is same as the width of screen, the height is fixed as 100pixel. */
    return QSize (qApp->desktop ()->width (), 100);
    }


    void ImDemo::mouseReleaseEvent (QMouseEvent *)
    {

    /* It generates key return event */
    emit key (Key_Return, 0);
    }



    /* Next is the define for input method plug-in */
    class InputMethodFactory : public MzLibFactory
    {
    public:
    InputMethodFactory ();

    virtual QString description () const;
    virtual QString version () const;

    protected:
    virtual QObject* createObject (QObject* parent, const char* name,
    const char* classname,
    const QStringList &args);
    };


    InputMethodFactory::InputMethodFactory ()
    {
    }

    QString InputMethodFactory::description () const
    {
    return QString ("Demo Input Method");
    }

    QString InputMethodFactory::version () const
    {
    return QString ("0.1");
    }



    QObject* InputMethodFactory::createObject (QObject* parent, const char* name,
    const char* classname,
    const QStringList &)
    {
    if (!strcmp (classname, "MzInputMethod"))
    return new ImDemo;

    return 0;
    }


    MZ_EXPORT_FACTORY (InputMethodFactory);

     


    [Previous] [Next] [Contents] MIZI Prizm 2.0.0