Home | History | Annotate | Download | only in src
      1 /*
      2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
      3  *
      4  * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
      5  *
      6  * The contents of this file are subject to the terms of either the GNU Lesser
      7  * General Public License Version 2.1 only ("LGPL") or the Common Development and
      8  * Distribution License ("CDDL")(collectively, the "License"). You may not use this
      9  * file except in compliance with the License. You can obtain a copy of the CDDL at
     10  * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
     11  * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
     12  * specific language governing permissions and limitations under the License. When
     13  * distributing the software, include this License Header Notice in each file and
     14  * include the full text of the License in the License file as well as the
     15  * following notice:
     16  *
     17  * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
     18  * (CDDL)
     19  * For Covered Software in this distribution, this License shall be governed by the
     20  * laws of the State of California (excluding conflict-of-law provisions).
     21  * Any litigation relating to this License shall be subject to the jurisdiction of
     22  * the Federal Courts of the Northern District of California and the state courts
     23  * of the State of California, with venue lying in Santa Clara County, California.
     24  *
     25  * Contributor(s):
     26  *
     27  * If you wish your version of this file to be governed by only the CDDL or only
     28  * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
     29  * include this software in this distribution under the [CDDL or LGPL Version 2.1]
     30  * license." If you don't indicate a single choice of license, a recipient has the
     31  * option to distribute your version of this file under either the CDDL or the LGPL
     32  * Version 2.1, or to extend the choice of license to its licensees as provided
     33  * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
     34  * Version 2 license, then the option applies only if the new code is made subject
     35  * to such option by the copyright holder.
     36  */
     37 
     38 #ifndef SUNPY_IMI_MODERN_VIEW_H
     39 #define SUNPY_IMI_MODERN_VIEW_H
     40 
     41 #include "portability.h"
     42 
     43 #include "imi_view.h"
     44 
     45 class CIMIModernView : public CIMIView {
     46 public:
     47     CIMIModernView();
     48 
     49     virtual ~CIMIModernView();
     50 
     51     virtual int  getViewType(void);
     52 
     53     virtual void attachIC(CIMIContext* pIC);
     54 
     55     virtual unsigned clearIC(void);
     56 
     57     virtual void updateWindows(unsigned int mask);
     58 
     59     virtual void setStatusAttrValue(int key, int value);
     60 
     61     virtual int  onKeyEvent(unsigned keycode, unsigned keyvalue, unsigned modifier);
     62 
     63     virtual int  onCandidatePageRequest(int pgno, bool relative);
     64 
     65     virtual int  onCandidateSelectRequest(int index);
     66 
     67     virtual void getPreeditString(IPreeditString& ps);
     68 
     69     virtual void getCandidateList(ICandidateList& cl, int start, int size);
     70 
     71 protected:
     72     /**
     73      * cancel current editing syllable, ie., If the syllable is waiting to
     74      * be inserted to the skeleton as a new bone, clear it. If the syllable
     75      * is used to modifying a existing bone of the skeleton, unshadow the bone.
     76      * After this, we enter sentence editing mode. So, both PREEDIT_MASK and
     77      * CANDIDATE_MASK should be set.
     78      */
     79     void
     80     cancelSyllable(unsigned int& mask);
     81 
     82     /**
     83      * commit the current editing syllable PINYIN string[0..len). Only
     84      * when current syllable[0..len) is valid and m_SyllableStr[len..) is
     85      * non-complete or valid. After commit, m_SyllableStr[len..) become the
     86      * new value of current syllable string.
     87      * @param len: m_SyllableStr[0..len) is to be inserted into skeleton
     88      *             as a valid PINYIN syllable.
     89      * @param boundaryType: AUOT_BOUNDARY or USER_BOUNDARY here. Specify the
     90      *              boundary type for the bone to be inserted
     91      * @param mask: whether or not the windows should be redraw\n
     92      */
     93     void
     94     convertSyllable(int boundaryType, int len, unsigned int& mask);
     95     /*@}*/
     96 
     97 
     98     /**
     99      * Select the idx-th candidate on user's request. move the current
    100      * Bone forwards to next bone, re-get candidate list. So, all
    101      * window area (preedit and candidate window) should be update
    102      */
    103     void
    104     makeSelection(int idx, unsigned int& mask);
    105 
    106 
    107     /*@{*/
    108     /**
    109      * for simplicity. call m_pIC->modify do most of the work,
    110      * put the current bone ptr right behind what erased. so do for
    111      * current candi bone ptr. Put the new m_SyllBone to the position
    112      * right after boneIt.
    113      * @param boneIt: the bone to be deleted
    114      * @param mask whether or not the candi is re-got
    115      */
    116     void
    117     eraseBone(CSkeletonIter boneIt, unsigned int& mask);
    118 
    119     /**
    120      * insert a Punc or Simbol bone into the skeleton at current position.
    121      * The core should provide better fast support for this.
    122      * @param bone: the bone to be added
    123      * @return whether or not the candidate list is re-got
    124      */
    125     void
    126     insertNonPinyinBone(CBone& bone, unsigned int& mask);
    127     /*@}*/
    128 
    129     /*@{*/
    130     /**
    131     * commit whole sentence to user.
    132     * @return combination of the area update mask bits
    133     */
    134     unsigned
    135     doCommit(bool bConvert=true);
    136 
    137     /** commit sentence at the left side of the m_SyllBone to user */
    138     void
    139     tryCommitLeftSentence(unsigned int& mask);
    140 
    141     /** commit single character to user, only when skeleton is empty */
    142     void
    143     commitChar(TWCHAR ch);
    144 
    145     /**
    146      * get best sentence
    147      * @param pSyllPos to return the starting position for current syllable
    148      * @param pSyllSize to return the size of current syllable
    149      * @return the caret position of the char
    150      */
    151     int
    152     getSentence(wstring& wstr, int* pSyllPos=NULL, int* pSyllSize=NULL);
    153     /*@}*/
    154 
    155     /*@{*/
    156     /**
    157      * Process key when we are in syllable editing mode, ie,
    158      * the m_SyllableStr is not zero.
    159      */
    160     void
    161     pressKeyOnSyllable(unsigned keycode, unsigned keyvalue, unsigned modifier, unsigned int& mask);
    162 
    163     /**
    164      * Process key when we are in sentence editing mode, ie,
    165      * the m_SyllableStr is zero length.
    166      */
    167     void
    168     pressKeyOnSentence(unsigned keycode, unsigned keyvalue, unsigned modifier, unsigned int& mask);
    169 
    170     /**
    171      * Process non-pinyin character input when we are in sentence
    172      * editing mode, ie, the m_SyllableStr is zero length. for those
    173      * non-printable character, return it back to IM System as we do
    174      * not accept the event (make no change to mask).
    175      * First, we map Punc and Simbol, and when IC is empty, commit the
    176      * mapped char. When IC has some content, make a bone and insert
    177      * it into the skeleton.
    178      */
    179     void
    180     pressNormalKey(unsigned keycode, unsigned keyvalue, unsigned modifier, unsigned int& mask);
    181     /*@}*/
    182 
    183 protected:
    184     /*@{*/
    185     /**
    186      * The syllable value we are now editing upon m_curBone.
    187      * Note, that when it is not zero lengthed, whether or not
    188      * EN state can be switched into, or whether or not non-pinyin
    189      * char could be input should be considered carefully.  By the
    190      * way, the caret is always positioned at the tail of this string.
    191      */
    192     wstring             m_SyllableStr;
    193 
    194     /** Whether the Syllable is from a existing bone, or new to be inserted */
    195     bool                m_bNewSyll;
    196 
    197     /**
    198      * Current Syllable which the caret is just before or upon. this is
    199      * also the candidate-list's starting bone.
    200      */
    201     CSkeletonIter       m_SyllBone;
    202 
    203     /** the candidate list */
    204     CCandidates         m_CandiList;
    205 
    206     /** the index in whole list of first candidate shown in the candidate bar */
    207     int                 m_CandiFirst;
    208 
    209     /** cursor position inside the current syllable we are now editing */
    210     int                 m_CursorIdx;
    211 
    212     /*@}*/
    213 
    214 };
    215 
    216 #endif
    217