1 157 yongsun /* 2 157 yongsun * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 157 yongsun * 4 177 yongsun * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. 5 157 yongsun * 6 157 yongsun * The contents of this file are subject to the terms of either the GNU Lesser 7 157 yongsun * General Public License Version 2.1 only ("LGPL") or the Common Development and 8 157 yongsun * Distribution License ("CDDL")(collectively, the "License"). You may not use this 9 157 yongsun * file except in compliance with the License. You can obtain a copy of the CDDL at 10 157 yongsun * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at 11 157 yongsun * http://www.opensource.org/licenses/lgpl-license.php. See the License for the 12 157 yongsun * specific language governing permissions and limitations under the License. When 13 157 yongsun * distributing the software, include this License Header Notice in each file and 14 157 yongsun * include the full text of the License in the License file as well as the 15 157 yongsun * following notice: 16 157 yongsun * 17 157 yongsun * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE 18 157 yongsun * (CDDL) 19 157 yongsun * For Covered Software in this distribution, this License shall be governed by the 20 157 yongsun * laws of the State of California (excluding conflict-of-law provisions). 21 157 yongsun * Any litigation relating to this License shall be subject to the jurisdiction of 22 157 yongsun * the Federal Courts of the Northern District of California and the state courts 23 157 yongsun * of the State of California, with venue lying in Santa Clara County, California. 24 157 yongsun * 25 157 yongsun * Contributor(s): 26 157 yongsun * 27 157 yongsun * If you wish your version of this file to be governed by only the CDDL or only 28 157 yongsun * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to 29 157 yongsun * include this software in this distribution under the [CDDL or LGPL Version 2.1] 30 157 yongsun * license." If you don't indicate a single choice of license, a recipient has the 31 157 yongsun * option to distribute your version of this file under either the CDDL or the LGPL 32 157 yongsun * Version 2.1, or to extend the choice of license to its licensees as provided 33 157 yongsun * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL 34 157 yongsun * Version 2 license, then the option applies only if the new code is made subject 35 157 yongsun * to such option by the copyright holder. 36 157 yongsun */ 37 157 yongsun 38 157 yongsun #ifdef HAVE_CONFIG_H 39 157 yongsun #include <config.h> 40 157 yongsun #endif 41 157 yongsun 42 157 yongsun #import "imi_imkitwin.h" 43 157 yongsun #import "SunPinyinInputController.h" 44 157 yongsun 45 157 yongsun #ifdef WORDS_BIGENDIAN 46 157 yongsun #define UTF32Encoding NSUTF32BigEndianStringEncoding 47 157 yongsun #else 48 157 yongsun #define UTF32Encoding NSUTF32LittleEndianStringEncoding 49 157 yongsun #endif 50 157 yongsun 51 157 yongsun CIMKitWindowHandler::CIMKitWindowHandler (id ic) :_ic(ic) 52 157 yongsun { 53 157 yongsun } 54 157 yongsun 55 157 yongsun CIMKitWindowHandler::~CIMKitWindowHandler() 56 157 yongsun { 57 157 yongsun } 58 157 yongsun 59 157 yongsun void CIMKitWindowHandler::commit(const TWCHAR* wstr) 60 157 yongsun { 61 157 yongsun size_t len = WCSLEN(wstr) * sizeof(TWCHAR); 62 157 yongsun NSString *string = [[NSString alloc] initWithBytes:wstr length:len encoding:UTF32Encoding]; 63 157 yongsun [_ic commitString:string]; 64 157 yongsun [string release]; 65 157 yongsun } 66 157 yongsun 67 157 yongsun void CIMKitWindowHandler::updatePreedit(const IPreeditString* ppd) 68 157 yongsun { 69 157 yongsun const TWCHAR *wstr = ppd->string(); 70 157 yongsun size_t len = (ppd->size()) * sizeof(TWCHAR); 71 157 yongsun NSString *string = [[NSString alloc] initWithBytes:wstr length:len encoding:UTF32Encoding]; 72 187 yongsun [_ic setCaret:ppd->caret() andCandiStart:ppd->candi_start()]; 73 157 yongsun [_ic showPreeditString:string]; 74 157 yongsun [string release]; 75 157 yongsun } 76 157 yongsun 77 157 yongsun void CIMKitWindowHandler::updateCandidates(const ICandidateList* pcl) 78 157 yongsun { 79 157 yongsun NSMutableArray* candidates = [NSMutableArray array]; 80 157 yongsun 81 157 yongsun for (int i=0; i<pcl->size(); ++i) { 82 157 yongsun const TWCHAR *wstr = pcl->candiString(i); 83 157 yongsun size_t len = pcl->candiSize(i) * sizeof(TWCHAR); 84 183 yongsun NSString *string = [[[NSString alloc] initWithBytes:wstr length:len encoding:UTF32Encoding] autorelease]; 85 157 yongsun [candidates addObject:string]; 86 157 yongsun } 87 174 yongsun 88 174 yongsun [_ic showCandidates:candidates]; 89 157 yongsun } 90 190 yongsun 91 190 yongsun void CIMKitWindowHandler::updateStatus(int key, int value) 92 190 yongsun { 93 190 yongsun [_ic updateStatus:key withValue:value]; 94 190 yongsun } 95 190 yongsun 96