Tomotaka SUWA
t-suw****@users*****
2006年 3月 26日 (日) 23:39:11 JST
Index: AquaSKK/ChangeLog diff -u AquaSKK/ChangeLog:1.20.2.17 AquaSKK/ChangeLog:1.20.2.18 --- AquaSKK/ChangeLog:1.20.2.17 Sat Mar 25 00:10:22 2006 +++ AquaSKK/ChangeLog Sun Mar 26 23:39:11 2006 @@ -1,3 +1,15 @@ +2006-03-26 Tomotaka SUWA <t.suw****@mac*****> + + * CppScrap.*: íB + + * WordRegisterMode.cpp: Scrap Manager ðp~µAPasteboardManager + ÉÚsB + + * KotoeriDictionary.cpp: õL[ÍíÉ BigEndian ÉÏ··éæ¤É + C³BܽAÏ·óâÍO\»Åó¯æéæ¤ÉC³B + + * CppCFString.*: toBigEndianCFString() ðÇÁB + 2006-03-25 Tomotaka SUWA <t.suw****@mac*****> * Info-*.plist: o[WðC³B Index: AquaSKK/CppCFString.cpp diff -u AquaSKK/CppCFString.cpp:1.3.2.3 AquaSKK/CppCFString.cpp:1.3.2.4 --- AquaSKK/CppCFString.cpp:1.3.2.3 Wed Mar 22 22:34:40 2006 +++ AquaSKK/CppCFString.cpp Sun Mar 26 23:39:11 2006 @@ -1,5 +1,5 @@ /* - $Id: CppCFString.cpp,v 1.3.2.3 2006/03/22 13:34:40 t-suwa Exp $ + $Id: CppCFString.cpp,v 1.3.2.4 2006/03/26 14:39:11 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -254,6 +254,27 @@ return cf_string; } +CFStringRef CppCFString::toBigEndianCFString() const { + CFStringRef result; + CFIndex len = CFStringGetLength(cf_string); + CFIndex bufsize = len * sizeof(UInt16); + UInt16* buf = new UInt16[len]; + + CFStringGetBytes(cf_string, CFRangeMake(0, len), kCFStringEncodingUnicode, 0, false, + reinterpret_cast<UInt8*>(buf), bufsize, NULL); + + for(int i = 0; i < len; ++ i) { + buf[i] = CFSwapInt16HostToBig(buf[i]); + }; + + result = CFStringCreateWithBytes(NULL, reinterpret_cast<UInt8*>(buf), bufsize, kCFStringEncodingUnicode, false); + + delete[] buf; + + return result; +} + + UniChar* CppCFString::toUniCharPtr() const { // Ô³ê½|C^ÍAKv³ÈÁ½çdelete[]µÈ¯êÎÈèܹñB const int len = CFStringGetLength(cf_string); @@ -264,7 +285,7 @@ } CFMutableDataRef CppCFString::toCFData() const { - // Ô³ê½CFDataRefÍAgpãÉK¸CFRelease·é±ÆB³àÈÎ[NB + // Ô³ê½CFDataRef ÍAgpãÉK¸ CFRelease ·é±ÆB³àÈÎ[NB CFDataRef src = CFStringCreateExternalRepresentation(NULL, cf_string, kCFStringEncodingUnicode, 0); CFMutableDataRef result = CFDataCreateMutableCopy(NULL, 0, src); CFRelease(src); Index: AquaSKK/CppCFString.h diff -u AquaSKK/CppCFString.h:1.3.2.1 AquaSKK/CppCFString.h:1.3.2.2 --- AquaSKK/CppCFString.h:1.3.2.1 Sun Jan 8 16:15:30 2006 +++ AquaSKK/CppCFString.h Sun Mar 26 23:39:11 2006 @@ -1,5 +1,5 @@ /* -*- c++ -*- - $Id: CppCFString.h,v 1.3.2.1 2006/01/08 07:15:30 t-suwa Exp $ + $Id: CppCFString.h,v 1.3.2.2 2006/03/26 14:39:11 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -75,6 +75,7 @@ virtual CppCFString& operator+= (const UniChar c); virtual CFStringRef getString() const; + virtual CFStringRef toBigEndianCFString() const; virtual UniChar* toUniCharPtr() const; virtual CFMutableDataRef toCFData() const; virtual char* toCString(CFStringEncoding encoding = kCFStringEncodingMacRomanLatin1) const; Index: AquaSKK/CppScrap.cpp diff -u AquaSKK/CppScrap.cpp:1.2.2.1 AquaSKK/CppScrap.cpp:1.2 --- AquaSKK/CppScrap.cpp:1.2.2.1 Sat Jan 14 20:01:58 2006 +++ AquaSKK/CppScrap.cpp Sat Oct 8 00:08:36 2005 @@ -7,46 +7,52 @@ * */ +#include <Carbon/Carbon.h> +#include <exception> +#include "CppCFData.h" #include "CppScrap.h" // ---------- CppScrap ---------- // CppScrap::CppScrap() { - GetCurrentScrap(&scrap); + GetCurrentScrap(&scrap); } CppScrap::CppScrap(const CppScrap& copy_src) { - scrap = copy_src.scrap; + scrap = copy_src.scrap; } CppScrapFlavor * CppScrap::makeFlavor(ScrapFlavorType type) { - return new CppScrapFlavor(*this, type); + return new CppScrapFlavor(*this,type); } ScrapRef CppScrap::getScrapRef() const { - return scrap; + return scrap; } // ---------- CppScrapFlavor ---------- // -CppScrapFlavor::CppScrapFlavor(CppScrap& s,ScrapFlavorType t) :scrap(s), type(t) { - // empty +CppScrapFlavor::CppScrapFlavor(CppScrap& s,ScrapFlavorType t) + :scrap(s), + type(t) { + } bool CppScrapFlavor::exists() const { - // ãã®flavorã®ãã¼ã¿ãåå¨ãããï¼ - ScrapFlavorFlags flags; - return GetScrapFlavorFlags(scrap.getScrapRef(), type, &flags) != scrapFlavorNotFoundErr; + // ãã®flavorã®ãã¼ã¿ãåå¨ãããï¼ + ScrapFlavorFlags flags; + return GetScrapFlavorFlags(scrap.getScrapRef(),type,&flags) != scrapFlavorNotFoundErr; } unsigned CppScrapFlavor::size() const { - if(exists()) { - Size flavorSize; - GetScrapFlavorSize(scrap.getScrapRef(), type, &flavorSize); - return flavorSize; - } else { - return 0; - } + if (exists()) { + Size size; + GetScrapFlavorSize(scrap.getScrapRef(),type,&size); + return size; + } + else { + return 0; + } } struct exception_CppScrapFlavor_content : public std::exception { @@ -56,15 +62,16 @@ }; CppCFData CppScrapFlavor::content() const throw(std::exception) { - if(exists()) { - Size flavorSize = this->size(); - char* buf = new char[flavorSize]; - GetScrapFlavorData(scrap.getScrapRef(), type, &flavorSize, buf); - CppCFData data(buf, flavorSize); - delete[] buf; - - return data; - } else { - throw exception_CppScrapFlavor_content(); - } + if (exists()) { + Size size = this->size(); + char* buf = new char[size]; + GetScrapFlavorData(scrap.getScrapRef(),type,&size,buf); + CppCFData data(buf,size); + delete[] buf; + + return data; + } + else { + throw exception_CppScrapFlavor_content(); + } } Index: AquaSKK/CppScrap.h diff -u AquaSKK/CppScrap.h:1.2.2.1 AquaSKK/CppScrap.h:1.2 --- AquaSKK/CppScrap.h:1.2.2.1 Sat Jan 14 20:01:58 2006 +++ AquaSKK/CppScrap.h Sat Oct 8 00:08:36 2005 @@ -1,60 +1,56 @@ /* - $Id: CppScrap.h,v 1.2.2.1 2006/01/14 11:01:58 t-suwa Exp $ - - MacOS X implementation of the SKK input method. - - Copyright (C) 2002 phonohawk - Copyright (C) 2006 Tomotaka SUWA <t.suw****@mac*****> - - 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 - 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 + $Id: CppScrap.h,v 1.2 2005/10/07 15:08:36 t-suwa Exp $ + --------- + + MacOS X implementation of the SKK input method. + Copyright (C) 2002 phonohawk + + 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 + 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 */ #pragma once -#include <Carbon/Carbon.h> -#include <exception> -#include "CppCFData.h" - /* ScrapRefã®ã©ããã¼ã§ããCppScrapã®ä»ã scrap flavorã表ãCppScrapFlavorãå®ç¾©ãã¾ãã */ +class CppScrap; class CppScrapFlavor; class CppScrap { -protected: - ScrapRef scrap; // ã¯ãªã¢ãããã¨ç¡å¹ã«ãªãäºã«æ³¨æã - -public: - CppScrap(); // é常ã®ã¯ãªãããã¼ãã表ãCppScrapãä½ãã - CppScrap(const CppScrap& copy_src); // ã³ãã¼ã³ã³ã¹ãã©ã¯ã¿ã¯ãåãScrapRefãæããã®ãä½ãã - - CppScrapFlavor* makeFlavor(ScrapFlavorType type); - ScrapRef getScrapRef() const; + protected: + ScrapRef scrap; // ã¯ãªã¢ãããã¨ç¡å¹ã«ãªãäºã«æ³¨æã + + public: + CppScrap(); // é常ã®ã¯ãªãããã¼ãã表ãCppScrapãä½ãã + CppScrap(const CppScrap& copy_src); // ã³ãã¼ã³ã³ã¹ãã©ã¯ã¿ã¯ãåãScrapRefãæããã®ãä½ãã + + CppScrapFlavor* makeFlavor(ScrapFlavorType type); + ScrapRef getScrapRef() const; }; class CppScrapFlavor { -protected: - CppScrap scrap; - ScrapFlavorType type; - -public: - CppScrapFlavor(CppScrap& s, ScrapFlavorType t); - - bool exists() const; // ãã®flavorãåå¨ãããï¼ - unsigned size() const; // flavorã®ãµã¤ãºãåå¨ããªããã°0ã - CppCFData content() const throw(std::exception); // ä¸èº«ãåå¨ããªããã°ä¾å¤ãæããã + protected: + CppScrap scrap; + ScrapFlavorType type; + + public: + CppScrapFlavor(CppScrap& s,ScrapFlavorType t); + + bool exists() const; // ãã®flavorãåå¨ãããï¼ + unsigned size() const; // flavorã®ãµã¤ãºãåå¨ããªããã°0ã + CppCFData content() const throw(std::exception); // ä¸èº«ãåå¨ããªããã°ä¾å¤ãæããã }; Index: AquaSKK/KotoeriDictionary.cpp diff -u AquaSKK/KotoeriDictionary.cpp:1.1.2.1 AquaSKK/KotoeriDictionary.cpp:1.1.2.2 --- AquaSKK/KotoeriDictionary.cpp:1.1.2.1 Sat Feb 18 02:20:38 2006 +++ AquaSKK/KotoeriDictionary.cpp Sun Mar 26 23:39:11 2006 @@ -1,5 +1,5 @@ /* - $Id: KotoeriDictionary.cpp,v 1.1.2.1 2006/02/17 17:20:38 t-suwa Exp $ + $Id: KotoeriDictionary.cpp,v 1.1.2.2 2006/03/26 14:39:11 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -106,7 +106,7 @@ std::vector<CppCFString> result; DCMFoundRecordIterator iterator; - if(!find(str.getString(), &iterator)) { + if(!find(str, &iterator)) { return result; } @@ -127,32 +127,42 @@ if(status != noErr) break; DescType actualType; - char dataBuffer[kMaxKanjiLengthInAppleJapaneseDictionary]; + UInt8 dataBuffer[kMaxKanjiLengthInAppleJapaneseDictionary]; Size actualSize; // Get one data from AERecord - status = AEGetKeyPtr(&dataList, - kDCMJapaneseHyokiTag, - 'utxt', - &actualType, - dataBuffer, - kMaxKanjiLengthInAppleJapaneseDictionary, - &actualSize); + status = AEGetParamPtr(&dataList, + kDCMJapaneseHyokiTag, +#if MAC_OS_X_VERSION_MAX_ALLOWED>=1040 + typeUTF16ExternalRepresentation, +#else + 'utxt', +#endif + &actualType, + dataBuffer, + kMaxKanjiLengthInAppleJapaneseDictionary, + &actualSize); // Dispose data AERecord AEDisposeDesc(&dataList); if(status != noErr) break; +#if MAC_OS_X_VERSION_MAX_ALLOWED>=1040 // ÊÉÇÁ·é result.push_back(CppCFData(dataBuffer, actualSize).getData()); +#else + CFStringRef tmp = CFStringCreateWithBytes(NULL, dataBuffer, actualSize, kCFStringEncodingUnicode, false); + result.push_back(tmp); + CFRelease(tmp); +#endif } DCMDisposeRecordIterator(iterator); return result; } -bool KotoeriDictionary::find(const CFStringRef key, DCMFoundRecordIterator* iterator) { +bool KotoeriDictionary::find(const CppCFString key, DCMFoundRecordIterator* iterator) { DCMDictionaryRef ref; if(DCMOpenDictionary(id_, 0, NULL, &ref) != noErr) { std::cerr << "DCMOpenDictionary() failed" << std::endl; @@ -162,18 +172,19 @@ // R[hðõ OSStatus status; DCMFieldTag dataFieldTagList[] = { kDCMJapaneseHyokiTag }; - ByteCount length = CFStringGetLength(key) * sizeof(UniChar); + CFStringRef keydata = key.toBigEndianCFString(); status = DCMFindRecords(ref, // Dictionary reference - kDCMJapaneseYomiTag, // key field tag - length, // key data length - CFStringGetCharactersPtr(key), // key data - kDCMFindMethodExactMatch, // find method + kDCMJapaneseYomiTag, // key field tag + CFStringGetLength(keydata) * sizeof(UInt16), // key data length + CFStringGetCharactersPtr(keydata), // key data + kDCMFindMethodExactMatch, // find method 1, // number of data field dataFieldTagList, // data field tag list - 0, 0, // search all records - iterator); // found result + 0, 0, // search all records + iterator); // found result DCMCloseDictionary(ref); + CFRelease(keydata); return (status == noErr); } Index: AquaSKK/KotoeriDictionary.h diff -u AquaSKK/KotoeriDictionary.h:1.1.2.1 AquaSKK/KotoeriDictionary.h:1.1.2.2 --- AquaSKK/KotoeriDictionary.h:1.1.2.1 Sat Feb 18 02:20:38 2006 +++ AquaSKK/KotoeriDictionary.h Sun Mar 26 23:39:11 2006 @@ -1,5 +1,5 @@ /* - $Id: KotoeriDictionary.h,v 1.1.2.1 2006/02/17 17:20:38 t-suwa Exp $ + $Id: KotoeriDictionary.h,v 1.1.2.2 2006/03/26 14:39:11 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -36,7 +36,7 @@ bool isRegistered_; DCMDictionaryID id_; - bool find(const CFStringRef key, DCMFoundRecordIterator* iterator); + bool find(const CppCFString key, DCMFoundRecordIterator* iterator); public: KotoeriDictionary(); Index: AquaSKK/UserDefaults.plist diff -u AquaSKK/UserDefaults.plist:1.1.2.5 AquaSKK/UserDefaults.plist:1.1.2.6 --- AquaSKK/UserDefaults.plist:1.1.2.5 Sat Mar 18 02:30:14 2006 +++ AquaSKK/UserDefaults.plist Sun Mar 26 23:39:11 2006 @@ -5,7 +5,7 @@ <key>candidates_count</key> <integer>7</integer> <key>candidates_font_name</key> - <string>TrebuchetMS</string> + <string>LucidaGrande</string> <key>candidates_font_size</key> <integer>18</integer> <key>candidates_window_alpha</key> Index: AquaSKK/WordRegisterMode.cpp diff -u AquaSKK/WordRegisterMode.cpp:1.3.2.1 AquaSKK/WordRegisterMode.cpp:1.3.2.2 --- AquaSKK/WordRegisterMode.cpp:1.3.2.1 Sat Jan 14 20:01:58 2006 +++ AquaSKK/WordRegisterMode.cpp Sun Mar 26 23:39:11 2006 @@ -1,5 +1,5 @@ /* - $Id: WordRegisterMode.cpp,v 1.3.2.1 2006/01/14 11:01:58 t-suwa Exp $ + $Id: WordRegisterMode.cpp,v 1.3.2.2 2006/03/26 14:39:11 t-suwa Exp $ MacOS X implementation of the SKK input method. @@ -26,7 +26,6 @@ #include "ParentInputMode.h" #include "IMSessionInputMode.h" #include "WordRegisterMode.h" -#include "CppScrap.h" WordRegisterMode::WordRegisterMode(ChildInputMode& src, const CppCFString& word) : ParentInputMode(), owner(&src), caret(0) { @@ -111,17 +110,39 @@ return true; } - CppScrapFlavor* clipped = CppScrap().makeFlavor(kScrapFlavorTypeUnicode); - if(clipped->exists()) { - // Nbv{[hɶñªüÁĽÌÅA±êðLbgÌÊuÉ}üB - // LbgÍ}ü³ê½¶ÌÉÚ®·éB - CppCFString str_in_clip(clipped->content().getData()); - buffer.insert(caret,str_in_clip); - caret += str_in_clip.length(); - + PasteboardRef pasteboard; + PasteboardCreate(kPasteboardClipboard, &pasteboard); + PasteboardSynchronize(pasteboard); + + ItemCount items; + PasteboardGetItemCount(pasteboard, &items); + for(UInt32 pos = 0; pos < items; ++ pos) { + PasteboardItemID id; + CFDataRef data; + + // index Í 1 based + if(PasteboardGetItemIdentifier(pasteboard, pos + 1, &id) < 0) continue; + +#if MAC_OS_X_VERSION_MAX_ALLOWED>=1040 + if(PasteboardCopyItemFlavorData(pasteboard, id, kUTTypeUTF16ExternalPlainText, &data) < 0) continue; + CppCFString str(data); +#else + if(PasteboardCopyItemFlavorData(pasteboard, id, CFSTR("public.utf16-plain-text"), &data) < 0) continue; + CFStringRef tmp = CFStringCreateWithBytes(NULL, CFDataGetBytePtr(data), CFDataGetLength(data), + kCFStringEncodingUnicode, false); + CppCFString str(tmp); + CFRelease(tmp); +#endif + CFRelease(data); + + buffer.insert(caret, str); + caret += str.length(); display(CppCFString()); + + break; } - delete clipped; + CFRelease(pasteboard); + return true; }