1 // OVIMGeneric.h: Generic Input Method, reads .cin 2 // 3 // Copyright (c) 2004-2006 The OpenVanilla Project (http://openvanilla.org) 4 // All rights reserved. 5 // 6 // Redistribution and use in source and binary forms, with or without 7 // modification, are permitted provided that the following conditions 8 // are met: 9 // 10 // 1. Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // 2. Redistributions in binary form must reproduce the above copyright 13 // notice, this list of conditions and the following disclaimer in the 14 // documentation and/or other materials provided with the distribution. 15 // 3. Neither the name of OpenVanilla nor the names of its contributors 16 // may be used to endorse or promote products derived from this software 17 // without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 // POSSIBILITY OF SUCH DAMAGE. 30 31 #ifndef __OVIMGeneric_h 32 #define __OVIMGeneric_h 33 34 #ifndef WIN32 35 #include <OpenVanilla/OpenVanilla.h> 36 #include <OpenVanilla/OVLibrary.h> 37 #include <OpenVanilla/OVUtility.h> 38 #else 39 #include <windows.h> 40 #include "OpenVanilla.h" 41 #include "OVLibrary.h" 42 #include "OVUtility.h" 43 #define strcasecmp stricmp 44 #endif 45 46 #include "OVCIN.h" 47 #include "OVKeySequence.h" 48 #include "OVCandidateList.h" 49 #include "OVCINInfo.h" 50 #include <stdlib.h> 51 #include <string> 52 #include <vector> 53 54 55 using namespace std; 56 57 class GenericKeySequence : public OVKeySequenceSimple 58 { 59 public: 60 GenericKeySequence(OVCIN* cintab); length()61 virtual int length() { return len; } 62 virtual bool add(char c); 63 virtual bool valid(char c); 64 virtual string* compose(string* s); getSeq()65 virtual char* getSeq() { return seq; } 66 67 protected: 68 OVCIN* cinTable; 69 }; 70 71 class OVIMGeneric; 72 73 class OVGenericContext : public OVInputMethodContext 74 { 75 public: OVGenericContext(OVIMGeneric * p,OVCIN * tab)76 OVGenericContext(OVIMGeneric* p, OVCIN* tab) : 77 parent(p), keyseq(tab), cintab(tab), autocomposing(false) {} 78 virtual int keyEvent(OVKeyCode*, OVBuffer*, OVCandidate*, OVService*); 79 virtual void clear(); 80 81 protected: 82 virtual void updateDisplay(OVBuffer *buf); 83 virtual int compose(OVBuffer *buf, OVCandidate *textbar, OVService *srv); 84 virtual int candidateEvent(OVKeyCode*, OVBuffer*, OVCandidate*, OVService*); 85 virtual void cancelAutoCompose(OVCandidate *textbar); 86 87 OVIMGeneric* parent; 88 GenericKeySequence keyseq; 89 OVCandidateList candi; 90 OVCIN* cintab; 91 92 bool autocomposing; 93 vector<string> candidateStringVector; 94 }; 95 96 class OVIMGeneric : public OVInputMethod 97 { 98 public: 99 OVIMGeneric(const OVCINInfo& ci); 100 virtual ~OVIMGeneric(); 101 virtual const char* identifier(); 102 virtual const char* localizedName(const char* locale); 103 virtual int initialize(OVDictionary*, OVService*, const char*); 104 virtual void update(OVDictionary*, OVService*); 105 virtual OVInputMethodContext *newContext(); 106 maxSeqLen()107 virtual int maxSeqLen() { return cfgMaxSeqLen; } isBeep()108 virtual int isBeep() { return cfgBeep; } isAutoCompose()109 virtual int isAutoCompose() { return cfgAutoCompose; } isHitMaxAndCompose()110 virtual int isHitMaxAndCompose() { return cfgHitMaxAndCompose; } isShiftSelKey()111 virtual bool isShiftSelKey() { return doShiftSelKey; }; 112 113 protected: 114 OVCINInfo cininfo; 115 OVCIN* cintab; 116 117 string idstr; 118 119 int cfgMaxSeqLen; 120 int cfgBeep; 121 int cfgAutoCompose; 122 int cfgHitMaxAndCompose; 123 124 bool doShiftSelKey; 125 }; 126 127 #endif 128