xsunpinyin-2.0.3/0000755000076400007640000000000011527365010012404 5ustar mikemikexsunpinyin-2.0.3/data/0000755000076400007640000000000011527365010013315 5ustar mikemikexsunpinyin-2.0.3/data/full.png0000644000076400007640000000172611527365010014773 0ustar mikemikePNG  IHDR bKGD pHYsHHFk> vpAg;*IDAT8˭OUUǿ{{7FZT` %4!MPP1nZDED-ԍA A&FhJ1Mcq3/'Ǚw{s~-9: 9s~w~‡4,kii74_t]tԵ){x8&x_S1w*VV .tWN.Μqrhյ'\>:2F02 `#Q:wPn`l|D`TKАBA9 C /2K&vx @^m"3ÚH4|g^۵{-1HV[oQhԆ/?r0Ael IBKZTēvkQ@!ı5x(=ci* 'vn&ƽaaq!봲[7Ȍ08j 2s^꯸ӈ/^^EYy 1573S_ˊOdB~I+?Ǐv@' /%N;eك!AZ…/?vAe]3=9H7R 0zj kV[3s3k4~?~̴,_H?~)/ƕ U)Y }5W(GF|B tknu<,,Ey`̬br23j%tEXtdate:create2010-03-30T15:22:22-07:008t%tEXtdate:modify2010-03-30T15:22:22-07:00e7IENDB`xsunpinyin-2.0.3/data/skins/0000755000076400007640000000000011527365010014444 5ustar mikemikexsunpinyin-2.0.3/data/skins/modern/0000755000076400007640000000000011527365010015730 5ustar mikemikexsunpinyin-2.0.3/data/skins/modern/info0000644000076400007640000000013111527365010016601 0ustar mikemike52 29 74 29 96 29 6 6 Sans 10 1.0 1.0 1.0 1.0 6 25 Sans 10 1.0 1.0 1.0 1.0 6 0 6 6 12 12 xsunpinyin-2.0.3/data/skins/modern/han-press.png0000644000076400007640000000202511527365010020335 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME ,53bIDAT8˝KlU}|3CyF|D"BP+Fbi Q$.]hԸ2,H DmX- ݗА1nw7 ޙ ow.?t<3te5j%VΌ?&0 MB :nY=ñMiOb FVVϪ뷖󿴴n|9pTKܘ9Pߌ괞;h-!:p%1ZBp-ʡ1XD D g잁~2^H㇙H\1JS3`-[:{˜ ) @n@I عT|79:1;{TxvLTPU B Bʵrˏ4n<Zʞݦd M].V@ I޻7>#)ޙҖT*o ][vHց[^K ETm-,)E@Oi=z@{҆$g-L פ RgQQRDZU/&H{N}Gb%_%ZQ]/.O85 ʫeSǕ)@*5*?Ƌ+L*oK5b_Pק͑m88>ven4\EX=i5m09@v +NcE)DD8;l9 py`?PMjh'Ƙ8;{g`)_ktiQV ǖ߅D?s(* tn,uv=g$IENDB`xsunpinyin-2.0.3/data/skins/modern/han-punc-hover.png0000644000076400007640000000156711527365010021301 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME +-o:l,IDAT8YHTQޙ;zr',K! Zh!Z)  Az!z+B0q HtlRHqfԙs\iZ|Ï9sωL6ltH71}ɜѣ8u6 n7l3$ EocQqtm z +^7("sb6Pe]r$1go ZV|yY^sP!7;q`Gk>2nrc~5FXT,/jDZ"Qp.Ȼ& G3+܊8 Xm(l@hݻgr뼝?KL@vtfvom [$DV6͂-4ƒ&@ $$ 07UP OS h ɾv15ڟ GQyLF(*Z-٨u`o?񆬠=nYR{U4Nf-M]Rp;M^,u֡ :E㝢ɒuRmXU;ʊCGY#H2Zp)ƠsD\aQ}8{Td$;:m7|}kXIPxy'ȵ;lRn/oOK/^ɪj%Ko??tXFShTE)CM'H~^~ʒCC4s<Å/IENDB`xsunpinyin-2.0.3/data/skins/modern/full.png0000644000076400007640000000172611527365010017406 0ustar mikemikePNG  IHDR bKGD pHYsHHFk> vpAg;*IDAT8˭OUUǿ{{7FZT` %4!MPP1nZDED-ԍA A&FhJ1Mcq3/'Ǚw{s~-9: 9s~w~‡4,kii74_t]tԵ){x8&x_S1w*VV .tWN.Μqrhյ'\>:2F02 `#Q:wPn`l|D`TKАBA9 C /2K&vx @^m"3ÚH4|g^۵{-1HV[oQhԆ/?r0Ael IBKZTēvkQ@!ı5x(=ci* 'vn&ƽaaq!봲[7Ȍ08j 2s^꯸ӈ/^^EYy 1573S_ˊOdB~I+?Ǐv@' /%N;eك!AZ…/?vAe]3=9H7R 0zj kV[3s3k4~?~̴,_H?~)/ƕ U)Y }5W(GF|B tknu<,,Ey`̬br23j%tEXtdate:create2010-03-30T15:22:22-07:008t%tEXtdate:modify2010-03-30T15:22:22-07:00e7IENDB`xsunpinyin-2.0.3/data/skins/modern/full-hover.png0000644000076400007640000000160011527365010020516 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME *:تIDAT8˭MlTUsOo/4H_ * ݈$lԨV+ݘhp%5-]TiBh@JSb[fN̝{q[kx=y9<څc}-|Ke3a.w׳MNuzhM};̓//s=.-5)n9m:0~`,D<m+<v{6%XD9tyi;^A4?RS,yRjAȢzL5xBf047LY~V+Q\4W uUˆ VM}5,%‡~X]':/\bp2^Z̛Uzߢ# 1 Lu&:}jztrwPts:מ͋#m9yMLPTT޻Sg͸oPpyx"h"}&A}8u"9Y'/8I>zMԁ8VmF50+ c6 vpAg;*IDAT8eYlU~7KgNKY,K\HXFDF1!-j⃀1!D (B%RҁvJiV=?9Gcf0}g%MLiw]{Ss.]|y~׾L̒˄^E )QwiZن[=VHD 4hmQlX<|W HS 0pp!" |HJP@3Hb|9 <)X<3򭑺_A͹)hEujƮT0siS7_zoo?ubj]uOr& B4,LLaER ;Z(NcH:Uc׎x76au[&t-# HFs0 yD#l<'JhЖ5`hw]<,Y֘cNXE`cv h2MPhyxϗ"("S/s֖fbh;7i|sQ)1ݤ;]-xl+Аgu!PRMVovS"ض/Nv}vަEhtǑ_Nb̩RʐW)Cʀuu+[c+C`Y֓-ՈoY|qH_xiJ3`D<w`~]tBa>9ݵ@ tCm%tEXtcreate-date2009-12-28T14:19:12-08:00S{%tEXtmodify-date2009-12-28T14:19:12-08:00 IENDB`xsunpinyin-2.0.3/data/skins/modern/han-punc-press.png0000644000076400007640000000156611527365010021311 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME /1ZIDAT8KhAƿdӴIRmQBEO*APHxP *E=UP*JmkFyuIE=?1?NKqQ1VIKLv.ʐ&@4=x{+./KyTI_xTx=| or\<WyQY ͊DH֞鞋^xFTEf󑁕jx`eVygW/K*}ߧ?R$!/H:.459-.aZDόloǻT_IBt[#xm_+ffhv:8KsߊHWTҪ|@h49oOi`a!?!?ZxI.#iIENDB`xsunpinyin-2.0.3/data/skins/modern/half-hover.png0000644000076400007640000000173111527365010020473 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME * !YIDAT8˭[hElIMK-Ӥ^jբ^TBA^( M b5(VLLc$fl$nvÌԤ-^<37?bY=cᦒ5V촺21y&zn律-֓nn d}HXyY)a>=zS;*( vTn -!1B3 sb[N$f/~p|֩qt?dz DaqI[*Ձ(7I$.R˹ak\V5D bZSh۾mjvvc47_YJsg":BzYۭLAXR0\8Ȩ{jy)X9LxiE]C" 7=ǎ^gPa5pW4SuNmЫTS4'8oقDD4ۣ6-+W+r^euXᢼpeYtd M3d Q/IIENDB`xsunpinyin-2.0.3/data/skins/modern/eng-hover.png0000644000076400007640000000257711527365010020343 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME *CIDAT8][lTU>g:3"@[(B%`XA! 5h"JE @(D @ XhԶvB/C;af}/(?eog-|9Ɔc/GBJad1xWWr DOiؼ~[W/ij!96pdV70^8$tsC,BmIu!_*<Ŋ{/>^BmVk1-' 1dp4 NH .D'~h# SI#aS:m0-"b<7{D?cdC>h0{޽8184ZF&;qɸ~攎d"YmkD AxR-ph}/R6 >i#g8p[1`j~gV+vaQ,dpYp=Pߑ!y_/8njX]ѳiNS44f_|%0]RA0.@t8㹒/Wí+:t;ǂ%pùR?xHWZ$y5K'e_NSqA>ѣzyiM>0fl")|fdbq޸XR@RBBHJ[ q"^ e V S6w/VD cM)̭ɓ"\dʷD24VYs,MXlt:[,& "R:t '¿ VX(:ۙ]L` PQV).-1Rp a8I j;d"At~v*hV\-sO]tzHbڤC} Б3' ˁi9,Wj?=I vpAg;*`IDAT8˭Mh\U7o>:m'E J` u!,WU Pl P( Bč h@&R"fᢩmcۘL2y^1IR\xynrG`<:$Mˌ n֪JZϿ`?x??N`ʼ!`QV*ɲ ˇ/|}BZxX$9ȩgJjQ3f?#hLH6patcA]  - J|ߪ:yRȺ>^A>);`J9(`#"%O1—OOWnB"ùW= ZkU0V&=JX2|t(@OWN`}$cxޔPؑ'm= a{_:WZa NO,D@K,W +}TV0SRTS\1xbG|d,JD&B׺ b6}k^oY=[Lj@tS Lbp?_( ~m\ؼs9|f4ңPyg'K{kJz"ؾM3xUF! @ XZ[+ELۣ \s6>ix/( ;P)%tEXtdate:create2010-03-30T15:21:47-07:00X%tEXtdate:modify2010-03-30T15:21:47-07:00QIENDB`xsunpinyin-2.0.3/data/skins/modern/full-press.png0000644000076400007640000000155111527365010020534 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME -IDAT8˭Mh\Uf^#34 4`Ah]օTЅ-]tMšB] ~,`%A)5A\*~$F&tǼqvhc*\sӗ\#BAWܥG\׭X+qN4+׎>y7p웻xZRI8Dl1akݖHcekZgt*ժ~y\ԧ]xX$>PpS2vɾlgs滽/|u~&P6erq$ӫO.uMMgO_OLJ%h"8EmЩcg<| |]Rw?uFsi">(Uj8kPz{8WPM(V5X'#u Ie k7i6fgRcy@k ڱ2:kK0 IO=Ain3L6bca~5eވǚ| &}ӱ?Zk{*Æq.O灜|l6>ref^דI$"Ij6&Yz!9ҥEF3<7.jEyrHDDV㫳|hь.{/>4` e jǬ43DV~iy([DS$c$]q7#7MRn[m~[.+ MJ6Iũw  bIENDB`xsunpinyin-2.0.3/data/skins/modern/eng-punc.png0000644000076400007640000000153511527365010020156 0ustar mikemikePNG  IHDR bKGD pHYsHHFk> vpAg;*IDAT8KaƟٙٙ]w]V(]E"E]@qTt[Ea@H+Kj;:|xωl헁1L:b҈|Ƽ\+x ̢ؓTu9+PZNu|sg~UJC5uk#K# ):^M^GӇ5)Acrw/&  WllQS8t9)tJ5O͌^OfR_hP84)q\B,rl,dy*Tlyb\VKtF1==7JKɾln>\J׋aٜ}\uM=A8S? -GZvUk(P!B Ýۆ@M_7`X4~LH )!^Z5<;%tEXtdate:create2010-03-30T15:25:37-07:00v@%tEXtdate:modify2010-03-30T15:25:37-07:00+wIENDB`xsunpinyin-2.0.3/data/skins/modern/preedit.png0000644000076400007640000000340211527365010020071 0ustar mikemikePNG  IHDR#7sRGBbKGD{{{2E pHYs  tIME 40&tEXtCommentCreated with GIMPW]IDATXýYMTE=uި"" $Jܲ_vȚ-VHذ3.LX(Bc``QEWWWxu`܏UN+׮]{a\~⫞+o K>ǃy[@ya6^NǍ7fANꅽF`HL"H"_G~r oz!H~Q!#>@C%D[;/Oz4PWFH%l #giJůaUp,ԑ̜PY9xރd%54CqNai(@y8-$3$HF< @d` $P^@^Κu$W$;ғ."k(EC+FE5gň$Rҫ #pbhqN-H- Bi P@r,ѻ A|W R%+cN@q!cЅ](R&Z>iI$gcS-%*+U~cUf[@Yir&E ,[N cT}יJ.Ϡs!Mm 1]r3M]S/ЫY-pRRD)U]AՍ9Z!䨫 F]b &;)c_P1 ukI GVTdS#QfM~r43NҸ 8`4LȠH 9SR5BB7PWܭj4O3ħIP NtgK[&b7&Sf %lp7iucB%NZB2,uѶ@QfK`8ysYoTJsqfcOqќTM QFF29) Pq(&@jyQjroV@1;-F]*(s^sIh+Ŋ,LMa^޾h-a&ъy6%~oNGD;?nۧUϪhwԩm K#adgZU?$y9WB=c#]9k)z۝nM'vH/Lg@uodJ&[6mnIENDB`xsunpinyin-2.0.3/data/skins/modern/han.png0000644000076400007640000000216511527365010017210 0ustar mikemikePNG  IHDR bKGDԂ pHYsHHFk> vpAg;*IDAT8˝OhUǿvouwV0Ji=46RkQ*E/ zREP<Q- ( Ijnd7Mjv7xo(&Ãf>7= Cjo9IKLK.|f_}^@k2fzz2Ծ_/w FK;]{t|9IR߁XD lеLKӤ'0umX:Ҙ CcŃŁՁŃó]YK-47֎b-JuAje +JR\[[\3sD@hVݾ4yꍯs/>+ _*GwC(+@K (ퟻalobY̎?A6)-r{ʑX<8@⑑Ås>}l؊rɳCS4}#=%L׺C*|NTK( Xx=ss~σ?d-0:[aުk\£,-ܛ}uֳxѡT;hKD5I-!sH6?]J=N I?@B #ڤp0B>o Y!FTeLX\fh Ԅ睱Xg\ -xfq?.Xao>$zb⹭8 O+r l_Mv*O]Wg'5)=\dܟC^`\J)i9>3 ˸4eF8 }ZKl ٢ Y2 , ޓWEfkְ5+  :k YگuB}-[,CIENDB`xsunpinyin-2.0.3/data/skins/modern/eng-punc-hover.png0000644000076400007640000000140311527365010021271 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME +1IDAT8_HSQǿ眻6uڜf>CDA"ڃYB/E/==RI"zJ"Ȩ@ Ј7lLݜwg܈ z)9?uA3@ScߏKp=VCx\@aCv2]^4Ny&ŝSGcȣ2oxphc~tve_ѳ}z  v O8\vjrtRjVJ6wZɹ'mt7nZ(P&AYI[/Ut`TF%!PYqW(HYC7N@ \,if0e1 /db !R J$DhyC0]n΅Hs4_Dmח]J!UdU1} rA 8su\]ʯrJ30&<ejc>^ ~MFdw2)"MOPFGui v`6d 7Dos6lOȩ1ӨO/ʆи _Z<3w%dݥ|>W~v] %ׇFK<;ïԓ36z^Rluo;]iiP0w?g0߲F\M%.ժ궯<R#Թ7:g`o`V A"2aLX Ka~l;O64 &`.gJ3.bIENDB`xsunpinyin-2.0.3/data/skins/modern/icbar.png0000644000076400007640000001300511527365010017515 0ustar mikemikePNG  IHDR8xsRGBbKGD pHYs  tIME !7NNtEXtCommentCreated with GIMPW`IDATx{mwU?y>sͽ&H@F(e%GG`8@a ":1 *#bC>yocs>OPA׽Nu>o}kJ+J+m}'?`zѪEOg=џ}{ߺț_\>Ҟyë.xū>Nżhu+ss|=@G=׼O\ccCS1f3|~.i О_ř^:̋UoY?_{7xtAiO3|/%lv444Vݻջ^J=ɗ]:{ mX}qLit*X{̃]_Lڡidy0# L/~5wIü'>גwt<+U9ݟPn  4{Dt%?!z9it}YsD3pԓUJwvN?Մ `1)+<%hT$[$u^\d+>5#4\RsB[ H,~M}N1ÉCNbc/I@w;>8b4*w~_#p[̽zNWq+`*k *U9 nuhclm6ڷ1ʼn"bSX[mpfAtuҿ0 {I>p\AϬV*AL_hObH?8H*rڕٵ_uDQ QI++颫05Se?cX[!QB+}O!a,As. =M*)Avϯ~ "YlIM'VK#! N|t/)=&)|OTã|+kc/R8)T ~#)]VXΗ^˿Py51D‚G;],$4U4N8xb^nQb>o͌Xzo|eg7]ЗJRVv`+g/Vseծ<)ajʍoŞ8yT:&vU r@ A@z۝?Ah̋ES\\VD#̂_ʦmoz+i\ Pu e BD8JߏkT @t=Cz>wM5HŐs4_p1Y}tD,UjWdrR=`>Sy԰$ORf&xg?')>h7!]Y!ZX£$ް @- xGD?:!9!q "X6u*/<.~_Ʈ?gڠxF1_*vb!GO,'~$;F1z!]kaaO,к!nK/NvxA| .O;K 4g35+SM\HstMos@u;ZjK.ާm-R<=)&p͚*!6ə^/''ϐw.$͈`jYL5%ǭ[_eb9Y#< x]l6QmU!LLN$oxrޜ&]")Yyˡ劘mԌo}w2[_+/d?`l4ժ:l6i'bKv1q׮'wv\MS{;3b1fy%{%hrՈVX!vWPUTlaN^UE{@ Vh&W3P|-'w;vpMD 2-l9!乺{] `<A3{Q׻>`سgGN'_8 1ˢowY]pL5 i&:|vuYZʒ ׬h6stʇjpvi}0slo-Et?/:_ou Oa%Y8BIA7Gj+:tM2  58``09w@DOc>K$w$"05=ՙ$B|PP #Z߀ ոj5z{夭N&_IR\€"R։i'Nsz}mT=Iz%_VP̎MfLHV͏idI6ҿc{bd+:X4R+⺿f6#"HB8Zcg5uA1'V FT+Nf=7^8G箪N7nSIA<4paS'=%CvO{[fE:ɚ<$`6:`f}*3 gG++dsД B Z_mh{/_ˌ3B"zG$ ?mqP#"3 'hU{ pc.fw8ջ9&DRhf_իhL5ѠژwR!UG3Q9ᒳױxK= 9O挠7ֆ3d=8)@Oދܹ׆C^_ko=K?e~f^x1&yFAwD~ t֟{.SQ>%χ9[hPOTd~djDot ±`f<ِ翢4/)vJvpZclz <9iG{??gc̓w"6frT<#l̡eґ=G's1mLzZ&:OИ ym$%2;4oQ=;hH0"f`.~"44̤fKI&kҒ&kWbEhijm/eK31m H1wU?[9[qyM6=hШqaM2An?>!BOba@i!bf̑)H*sE^ƥ=ţ`ڜ dӬХj T,"<-|=#Wߜ)Qs>~|hc&f6?Ăϲ8s[1bY_EKc 5#W pN`E*iz)SD}c9[q|[FڴDrb#Ll#?Wc砺6q+ŹI .E)⇺R2t#/VjAym-$=oɅlw}Xii !9lxd![GoƔGḲwVb=A{bzI'tnHTX`#kZISܡ>L .N>:pwz:#L}Z̖I=.=;֣(jn'jxU9 +5VyW ImlEsܿ!黏[IjSWAİHZ{>b\9FKE6^PV E͒ 92 We"kؾv&ޛ@|zmziuU^-' K#rz]{D;Sp8Mm_(&5a6EA^%_fJՋ5zɆRLE9pd~J25}|plj-oڇu8Mi"pPaYj͵`✘P?9+HI#m+Azy'BYt; l u%.C 4aC71(wIH@TzdEwPzH) e p: 9x n?tVփrUDSn*(ƑA,aF\{2mÅ5:K$^oÐP1{lzo,pu}?I^]!"WR01cf-y0_#nn4#:iwH"YG 8n7c^+#l6w{/rf̬Zm 9`ng[ιIUwuUunm'dm` Q (e um[%RIENDB`xsunpinyin-2.0.3/data/skins/modern/han-hover.png0000644000076400007640000000204011527365010020321 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME )!TBIDAT8˝KhU~dtiX%mE(-E|mA,kQ AFq!UBwEHY1P7 m I&qq1cD^.z^}_̍.j9p%5n9`JLRU.oZy¹4PFU\Cp3 :!*5FكsoF4 B9T)j[xL5we V.ϙ&Sh'RIkhv !EZhێx}iiRI{rM(U(<9le=B]ָN+:e`7",1wݦB_ﺗT 勴_ڡfwet/ P(iWDBD~N,k<Թ2.|:-ыqfA 3rDQjr atg\?S˰~c~?m-[~~^-TtZ6e l{ 6~EIC1}bW}o7NG* O|>:upqrOi8wwSIE#¤z_@C 5LMGD26/ECIENDB`xsunpinyin-2.0.3/data/skins/modern/eng-punc-press.png0000644000076400007640000000135711527365010021312 0ustar mikemikePNG  IHDR sRGBbKGD pHYs  tIME -&"oIDAT8SMHTQo8ڌ3͌Q0hnZ.VSV[f,I! f8<;iV}q{s8;u +/Jۢ*p_!;@ yf/ieTV| ڝk<3tDs1L(g2+qR}u0 UBynAiOɭ8[#7>˳a=(ɧfeFۜ}VBAyhbH /&VZ#5 i*JFW-{:?3ו93S>Bq|o2jqW=%N]c&IpM˴lrg@67Y3_hB8Pt^dGrML{aIENDB`xsunpinyin-2.0.3/data/skins/modern/han-punc.png0000644000076400007640000000173411527365010020154 0ustar mikemikePNG  IHDR bKGD pHYsHHFk> vpAg;*IDAT8S[hW\Nd'D*&i}j J7y(XhA *TCQJ!>U},V[5Y`Bl%ML^̞9>Ĥ+29z FhcTK!Uyݬ;_m[oJ2{cI@*nf{Uw AY]%Qç A&fu`I֤1Ew0uL}"@>|̈́We%OȢa~rh[?1揞LwQ}S*S4$IMִl_^q' !dG17;W{qe5||{EV7XLS$d(j~}o+%\@G$mC" -!+"^Sbk2koP b:e64ݥ|-`p*kږ]W6:?*,B"POCyǦ]vPu5S jSȕ3~o'ӎK.Z9. Tcϓs-9,43eƇ2'xxҟd? nevI%Ko[;o&{_c%Y?P=%@kg &~iwGCע𑗔L5RF0fbaAP/u%YJ0c x ZIĶ=%tEXtdate:create2010-03-30T15:25:14-07:00ǻ]+%tEXtdate:modify2010-03-30T15:25:14-07:00IENDB`xsunpinyin-2.0.3/data/sunpinyin-logo-big.png0000644000076400007640000001006611527365010017557 0ustar mikemikePNG  IHDR00WsRGBbKGD pHYs  tIME /x IDAThՙ{ens$L.$ @]P(Q(`ՊVY֮ Jyb duT@v\ B&3537߭/{f&UnOuutOsy\U?x%xu7@5#^,+I&>w}7^pE~Nn8}j5y}gnQ)V~]{asXq&7 bQ *GϿpVŷ>sy,w>n~gu&ӊFUsjc!Ƥ[[t}bd~o |ʷï|;iѡ7\\Qu ! Iϙ}d>6z~q-KPőwq0 /n:l#m.buԡjs`lN_wZgGՠVTUF6 Q A68l;@-]-`Ѹ6V#R$Z P 87MlSU՝ v6ki:+FNǣR**W/@uf:֞VƀQ V*jE@!TjYPW#WQž*j4Qpb[X Z/#g>Do]U H)X!XyB"BlV:)P:E< k2v|u -Q9NHRHT. {`,;@fvh$lX =:dԐ+ēd xM[Tگߌg?XACĈ0twf#HGEa^(î{~AgvT'tcڠN4B o_!BetPINYvTC?)\!DM99JƸJ #4 a2_ |/)j2 "lRTiO%Cd&W[>9=o],_NiY|M7wP[MZZyO1.!A:EO}}j'3okǤ<"!C%'#}x/G#ނ8`H$8NzE˖֙_SWf5lĿi9'O7Z^\ZU!p>A% "]]\<$@u(N= 9bQdN+uKAxtV#LƧաN#L?uHO5K, 0dP,IS[P .J sXkKbl`qՈx|IuVQj0]`h@'r$"hԟ(~ʒ{#Ym̀{E!P,΁ B&| Nw`}4-9^1 6DPBA){RPDpy`>ADąV3orMsbFELXքC5Ib cJ>H*C&eH%CyJޕ,S[T*d.S`GȾݾA>Ip+kR85+՘h@cr,ՖVmDAD~ӖQͥQ'j5fAS61P \bL* F(ybcIoz0#5{=>U#X\IB\{#džVHOaS 4t.KE(ߌO_RT6ƿt\y -;Iz =CKeW߈e^PKWؐikh^忇/WNaC(Z߯!(b (F8;ݓĽ>J̼Y QB0%VkcyM_|qk~ٗb8-H.$HJDb\e TVq֐;UbU&B\@6yMȻ\gBbʵpm##ή<w`d뗾 &.8>ؒӨeԆ HFmlJ8<=OBlۨ{s8$gB9c0RUTi5;oؙ_ha{=-T ljG<3\1qZDuUD.W\0As$9f^BN6Y뒪>Uf 479t+o0R\={mz04ҷm$̴w:HEh+1i)]p<'A\$31BFg˩qT|`h&s3zg>t5}v͛ߑrW6c|r )E^:E\$:.< 1Xu,j@\&E5[ (gru;rLs4pX=m4{cSZ+Jkwe᠅Ji$Y_"o7]^KB.ŀJ=8M90(2W5S&N^ SLJh^Ndp{-FCē=Wj<߰p!4Vvd%Oǹ_sM0s8lʱP,}D/V(*쵒`"Y_rƕuND‰tr6o{C{F1lݝ^ rdl$T3Π:o|_hi YڝҤKO-6ͿuU/[/ UՔ'-N} Q{cݜt[g3\źxlwLVر 9sh(y"pjTֹWvl3m5}k%wPDz]pͦ{u`47JٞB9d0SRQ=Px\v2jR +WkP-w1u,X9@YGg㌛j}#T[J?wuQ/U+oz(Mn릞,j8Ac_|{ճ}աE1-+ۻBϬ>'X?1[1zOn*,f]om6Yls+MsVtJɛ7Sw}h]AIENDB`xsunpinyin-2.0.3/data/settings_ui.xml0000644000076400007640000010737111527365010016405 0ustar mikemike 5 XSunpinyin Preferences False center preferences-desktop dialog True 2 True True True 8 2 7 True 1 8 Trigger Key GTK_FILL GTK_FILL True 1 8 Switch to English 1 2 GTK_FILL GTK_FILL True 1 8 Number of Candidates 2 3 GTK_FILL True Control True True False True 0 Shift True True False True 1 True keysym 0 2 1 2 GTK_FILL True Control True True False True 0 Shift True True False True 1 True keysym 0 2 1 2 1 2 GTK_FILL True True delayed ncandidates 0 1 2 2 3 Fuzzy Segmentation True True False True 1 2 5 6 GTK_FILL True - / = True True False True 0 , / . True True False True 1 [ / ] True True False True 2 1 2 4 5 True 1 8 Page Up/Page Down 4 5 GTK_FILL True 1 8 Backspace Behavior 3 4 True Cancel Selection True True False True remove_on_backspace_check 0 Remove PinYin True True False True cancel_on_backspace_check 1 1 2 3 4 Smart Punctuation True True False True 1 2 7 8 Fuzzy Segmentation on Inner Pinyin True True False True 1 2 6 7 True Common False True 3 2 PinYin True True False True GTK_FILL ShuangPin True True False True pinyin_check 1 2 GTK_FILL True 0.40000000596046448 9 Note: <i>Switching to PinYin or QuanPin requires restart or relogin to take effect,</i> True True 2 2 3 True shuangpin_scheme 0 0 1 2 1 2 GTK_FILL 1 True PinYin Scheme 1 False True 6 2 7 True 1 8 Preedit Opacity 5 6 GTK_FILL GTK_FILL True True delayed opacity_value 2 1 2 5 6 GTK_FILL True 1 8 Preedit Font Color 4 5 GTK_FILL GTK_FILL True True True #000000000000 1 2 4 5 GTK_FILL True 1 8 Preedit Font 3 4 GTK_FILL GTK_FILL True True True 1 2 3 4 GTK_FILL True 1 8 Preedit Background Color 2 3 GTK_FILL GTK_FILL True True True #000000000000 1 2 2 3 GTK_FILL True Classic Skin: 1 2 True 1 8 Skin: True skin_list 0 1 2 True 1 2 1 2 2 True Look and Feel 2 False 1 True end gtk-close True True True True False False 1 False end 0 button2 0.01 0.01 1.01 0.10000000000000001 0.01 0.01 Space Control_L Control_R Shift_L Shift_R 10 3 11 1 1 1 MS2003 ABC ZiRanMa PinYin++ ZiGuang XiaoHe xsunpinyin-2.0.3/data/eng.png0000644000076400007640000000272311527365010014600 0ustar mikemikePNG  IHDR bKGDԂ pHYsHHFk> vpAg;*IDAT8eYlU~7KgNKY,K\HXFDF1!-j⃀1!D (B%RҁvJiV=?9Gcf0}g%MLiw]{Ss.]|y~׾L̒˄^E )QwiZن[=VHD 4hmQlX<|W HS 0pp!" |HJP@3Hb|9 <)X<3򭑺_A͹)hEujƮT0siS7_zoo?ubj]uOr& B4,LLaER ;Z(NcH:Uc׎x76au[&t-# HFs0 yD#l<'JhЖ5`hw]<,Y֘cNXE`cv h2MPhyxϗ"("S/s֖fbh;7i|sQ)1ݤ;]-xl+Аgu!PRMVovS"ض/Nv}vަEhtǑ_Nb̩RʐW)Cʀuu+[c+C`Y֓-ՈoY|qH_xiJ3`D<w`~]tBa>9ݵ@ tCm%tEXtcreate-date2009-12-28T14:19:12-08:00S{%tEXtmodify-date2009-12-28T14:19:12-08:00 IENDB`xsunpinyin-2.0.3/data/eng.svg0000644000076400007640000001562511527365010014620 0ustar mikemike image/svg+xml xsunpinyin-2.0.3/data/half.png0000644000076400007640000000206711527365010014742 0ustar mikemikePNG  IHDR bKGD pHYsHHFk> vpAg;*`IDAT8˭Mh\U7o>:m'E J` u!,WU Pl P( Bč h@&R"fᢩmcۘL2y^1IR\xynrG`<:$Mˌ n֪JZϿ`?x??N`ʼ!`QV*ɲ ˇ/|}BZxX$9ȩgJjQ3f?#hLH6patcA]  - J|ߪ:yRȺ>^A>);`J9(`#"%O1—OOWnB"ùW= ZkU0V&=JX2|t(@OWN`}$cxޔPؑ'm= a{_:WZa NO,D@K,W +}TV0SRTS\1xbG|d,JD&B׺ b6}k^oY=[Lj@tS Lbp?_( ~m\ؼs9|f4ңPyg'K{kJz"ؾM3xUF! @ XZ[+ELۣ \s6>ix/( ;P)%tEXtdate:create2010-03-30T15:21:47-07:00X%tEXtdate:modify2010-03-30T15:21:47-07:00QIENDB`xsunpinyin-2.0.3/data/han.png0000644000076400007640000000216511527365010014575 0ustar mikemikePNG  IHDR bKGDԂ pHYsHHFk> vpAg;*IDAT8˝OhUǿvouwV0Ji=46RkQ*E/ zREP<Q- ( Ijnd7Mjv7xo(&Ãf>7= Cjo9IKLK.|f_}^@k2fzz2Ծ_/w FK;]{t|9IR߁XD lеLKӤ'0umX:Ҙ CcŃŁՁŃó]YK-47֎b-JuAje +JR\[[\3sD@hVݾ4yꍯs/>+ _*GwC(+@K (ퟻalobY̎?A6)-r{ʑX<8@⑑Ås>}l؊rɳCS4}#=%L׺C*|NTK( X image/svg+xml xsunpinyin-2.0.3/data/engpunc.png0000644000076400007640000000153511527365010015466 0ustar mikemikePNG  IHDR bKGD pHYsHHFk> vpAg;*IDAT8KaƟٙٙ]w]V(]E"E]@qTt[Ea@H+Kj;:|xωl헁1L:b҈|Ƽ\+x ̢ؓTu9+PZNu|sg~UJC5uk#K# ):^M^GӇ5)Acrw/&  WllQS8t9)tJ5O͌^OfR_hP84)q\B,rl,dy*Tlyb\VKtF1==7JKɾln>\J׋aٜ}\uM=A8S? -GZvUk(P!B Ýۆ@M_7`X4~LH )!^Z5<;%tEXtdate:create2010-03-30T15:25:37-07:00v@%tEXtdate:modify2010-03-30T15:25:37-07:00+wIENDB`xsunpinyin-2.0.3/data/chnpunc.png0000644000076400007640000000173411527365010015466 0ustar mikemikePNG  IHDR bKGD pHYsHHFk> vpAg;*IDAT8S[hW\Nd'D*&i}j J7y(XhA *TCQJ!>U},V[5Y`Bl%ML^̞9>Ĥ+29z FhcTK!Uyݬ;_m[oJ2{cI@*nf{Uw AY]%Qç A&fu`I֤1Ew0uL}"@>|̈́We%OȢa~rh[?1揞LwQ}S*S4$IMִl_^q' !dG17;W{qe5||{EV7XLS$d(j~}o+%\@G$mC" -!+"^Sbk2koP b:e64ݥ|-`p*kږ]W6:?*,B"POCyǦ]vPu5S jSȕ3~o'ӎK.Z9. Tcϓs-9,43eƇ2'xxҟd? nevI%Ko[;o&{_c%Y?P=%@kg &~iwGCע𑗔L5RF0fbaAP/u%YJ0c x ZIĶ=%tEXtdate:create2010-03-30T15:25:14-07:00ǻ]+%tEXtdate:modify2010-03-30T15:25:14-07:00IENDB`xsunpinyin-2.0.3/data/xim_config_default0000644000076400007640000000023011527365010017061 0ustar mikemiketrigger_key=Control+space eng_key=Shift_L icbar_pos=1180,730 preedit_opacity=1.00 preedit_color=#FFFFB3 preedit_font=Sans 10 preedit_font_color=#000000 xsunpinyin-2.0.3/data/sunpinyin-logo.png0000644000076400007640000000311111527365010017011 0ustar mikemikePNG  IHDRw=sRGBbKGD pHYs  tIME hIDATHmU?̛cwvw-PIkhBIqC 1&cVT`kLbF!FP$!ؘ`JjVh m-6l`nJnwiG7o̽?޺?I&;|+/\ry9iE}QFд-f֫9+}~0Z.[JݱZAd.4=9SpS0\ET=C6& hyshKiQ8O4lQkϡS1q6dPg=DIXt)(੤>+\;ŽNjQJk'3$*72\A!f~xb>;<>#ɯ$@E۸G W]$mx"ltqK(W(j-+oIyJ(zDR;Oi_c`64p8x3^q;LbbKT$ B! "bA*2:$cw_;c8:x9yJT4ҔyJ2Ű"FSnԦױ@[Ȁ c>Ty_t-\:Yf-Aǂ.{B?_9$au</X44tHӔ5߾6|Őw;}Wr" ]D)h@c,(@`VlWQ*}2IENDB`xsunpinyin-2.0.3/ic.c0000644000076400007640000001733111527365010013150 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include #include #include #include #include #include #include #include "common.h" #include "settings.h" #include "ic.h" #include "xmisc.h" #include "xim.h" static IC* icmaps[MAX_IC_NUM]; static IC ics[MAX_IC_NUM]; static size_t free_stack_sz = 0; static IC* free_stack[MAX_IC_NUM]; static IC* current_ic; // check if this ic is available static int __find_application_pid(Window w) { if (w == DefaultRootWindow(dpy)) return 0; Atom actual_type; int actual_format; unsigned long nitems; unsigned long bytes; unsigned char* prop; int status = XGetWindowProperty( dpy, w, XInternAtom(dpy, "_NET_WM_PID", True), 0, 1024L, False, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes, (unsigned char**) &prop); if (status != 0) { if (status == BadRequest) return 0; return -1; } if (!prop) { Window parent; Window root; Window* children = NULL; unsigned int sz = 0; status = XQueryTree(dpy, w, &root, &parent, &children, &sz); if (status != 0) { if (status == BadRequest) return 0; return -1; } if (children) XFree(children); return __find_application_pid(parent); } else { // TODO: is this portable? return prop[1] * 256 + prop[0]; } } static bool __ic_available(IC* ic) { int pid = __find_application_pid(ic->client_window); if (pid == -1) return false; if (pid == 0) return true; // verify if a process is running char path[256]; snprintf(path, 255, "/proc/%d", pid); struct stat buf; if (stat(path, &buf) != 0) { LOG("GC can't catch the process %d", pid); return false; } if (!S_ISDIR(buf.st_mode)) { LOG("GC can't catch the process %d", pid); return false; } return true; } static void __scan_all_ic() { int i = 0; for (i = 0; i < MAX_IC_NUM; i++) { IC* ic = icmaps[i]; if (ic == NULL) continue; if (__ic_available(ic) == false) { LOG("GC detected garbage %d", ic->icid); icmgr_destroy_ic(i); } } } static void __reset_ic(IC* ic) { int id = ic->icid; memset(ic, 0, sizeof(IC)); ic->icid = id; ic->is_chn_punc = true; } void icmgr_init(void) { memset(ics, 0, sizeof(IC) * MAX_IC_NUM); int i; for (i = 0; i < MAX_IC_NUM; i++) { ics[i].icid = i; __reset_ic(&ics[i]); free_stack[free_stack_sz] = &ics[i]; free_stack_sz++; } current_ic = NULL; icmgr_ui_init(); } void icmgr_finalize(void) { memset(icmaps, 0, sizeof(IC*) * MAX_IC_NUM); current_ic = NULL; } IC* icmgr_create_ic(int connect_id) { static int created_cnt = 0; created_cnt++; if (created_cnt == GC_THRESHOLD || free_stack_sz < MAX_IC_NUM / 3) { __scan_all_ic(); created_cnt = 0; } if (free_stack_sz == 0) { LOG("Error free stack empty!!"); return NULL; } free_stack_sz--; IC* ic = free_stack[free_stack_sz]; icmaps[ic->icid] = ic; __reset_ic(ic); /* icmgr_set_current(ic->icid); */ ic->connect_id = connect_id; /* current_ic = ic; */ return ic; } void icmgr_destroy_ic(int icid) { IC* ic = icmaps[icid]; if (ic == NULL) return; memset(ic, 0, sizeof(IC)); ic->icid = icid; icmaps[icid] = NULL; // return to free stack free_stack[free_stack_sz] = ic; free_stack_sz++; current_ic = NULL; } bool icmgr_set_current(int icid) { IC* ic = icmaps[icid]; if (ic == NULL) return false; current_ic = ic; return true; } IC* icmgr_get_current(void) { return current_ic; } void icmgr_toggle_english(void) { if (current_ic) { current_ic->is_english = !current_ic->is_english; } } void icmgr_toggle_full(void) { if (current_ic) { current_ic->is_full = !current_ic->is_full; } } void icmgr_toggle_punc(void) { if (current_ic) { current_ic->is_chn_punc = !current_ic->is_chn_punc; } } IC* icmgr_get(int icid) { return icmaps[icid]; } void icmgr_clear_current(void) { current_ic = NULL; } void icmgr_refresh(void) { if (current_ic == NULL) { icmgr_ui_refresh(); return; } /* refresh preedit */ if (current_ic->is_enabled) { if (current_ic->is_english && preedit_status()) preedit_pause(); else if (!current_ic->is_english && !preedit_status()) preedit_go_on(); preedit_set_full(current_ic->is_full); preedit_set_chinese_punc(current_ic->is_chn_punc); } else { preedit_pause(); } icmgr_ui_refresh(); } extern IC_UI icmgr_gtk; extern IC_UI icmgr_skin; static IC_UI* current_icmgr_ui = NULL; static void init_front_end() { varchar skin_name; settings_get(SKIN_NAME, skin_name); if (strcmp(skin_name, "classic") == 0) { current_icmgr_ui = &icmgr_gtk; } else { current_icmgr_ui = &icmgr_skin; } if (!current_icmgr_ui->init(skin_name)) { fprintf(stderr, "Error init front end!\n"); exit(-1); } } void icmgr_ui_init(void) { ui_tray_init(); init_front_end(); } void icmgr_ui_refresh(void) { ui_tray_refresh(); if (current_icmgr_ui != NULL) { varchar skin_name; settings_get(SKIN_NAME, skin_name); if (strcmp(skin_name, current_icmgr_ui->get_name()) != 0) { current_icmgr_ui->dispose(); init_front_end(); } current_icmgr_ui->refresh(); } else { init_front_end(); } } xsunpinyin-2.0.3/ic.h0000644000076400007640000000623611527365010013157 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _IC_H_ #define _IC_H_ #include #include #include #include #include #include "common.h" __BEGIN_DECLS #define MAX_IC_NUM 0x7fff #define GC_THRESHOLD 4096 /* input context */ typedef struct _IC { Window client_window; bool is_enabled; bool is_english; bool is_full; bool is_chn_punc; int icid; int connect_id; int offset_x; int offset_y; } IC; typedef struct _IC_UI { gboolean (*init) (const char* name); void (*refresh) (void); void (*dispose) (void); const char* (*get_name) (void); } IC_UI; /* input context manager */ void icmgr_init (void); void icmgr_finalize (void); IC* icmgr_create_ic (int connect_id); void icmgr_destroy_ic (int icid); bool icmgr_set_current(int icid); IC* icmgr_get (int icid); void icmgr_toggle_english (void); void icmgr_toggle_full (void); void icmgr_toggle_punc (void); IC* icmgr_get_current (void); void icmgr_clear_current(void); void icmgr_refresh (void); void icmgr_ui_init (void); void icmgr_ui_refresh (void); __END_DECLS #endif /* _IC_H_ */ xsunpinyin-2.0.3/ui.c0000644000076400007640000002073511527365010013174 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include "ic.h" #include "common.h" #include "ui.h" #define ENG_ICON SUNPINYIN_XIM_ICON_DIR"/eng.svg" #define HAN_ICON SUNPINYIN_XIM_ICON_DIR"/han.svg" #define LOGO_FILE_BIG SUNPINYIN_XIM_ICON_DIR"/sunpinyin-logo-big.png" #define SYSTEM_SKIN_DIR SUNPINYIN_XIM_SETTING_DIR"/skins" #define USER_SKIN_DIR "%s/.sunpinyin/xim_skins" static GtkStatusIcon* icbar_tray; static GtkWidget* popup_menu; static void show_ui_about(GtkWidget* wid, gpointer user_data) { GError* error = NULL; GdkPixbuf* logo_pixbuf = gdk_pixbuf_new_from_file(LOGO_FILE_BIG, &error); gtk_show_about_dialog(NULL, "program-name", XIM_PROGRAM_NAME, "logo", logo_pixbuf, "version", XIM_VERSION, "website", XIM_WEBSITE, "comments", XIM_COMMENTS, NULL); } static void launch_preferences(GtkWidget* wid, gpointer user_data) { system("xsunpinyin-preferences&"); } static void status_icon_popup_menu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data) { gtk_widget_show_all(popup_menu); gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, gtk_status_icon_position_menu, status_icon, button, activate_time); } void ui_tray_init(void) { icbar_tray = gtk_status_icon_new_from_file(ENG_ICON); GtkWidget* setting_menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES, NULL); g_signal_connect(setting_menu_item, "activate", G_CALLBACK(launch_preferences), NULL); GtkWidget* about_menu_item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL); g_signal_connect(about_menu_item, "activate", G_CALLBACK(show_ui_about), NULL); /* construct the popup menu */ popup_menu = gtk_menu_new(); gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), setting_menu_item); gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), about_menu_item); g_signal_connect(icbar_tray, "popup-menu", G_CALLBACK(status_icon_popup_menu), NULL); } void ui_tray_refresh(void) { IC* ic = icmgr_get_current(); const char* filepath = HAN_ICON; if (ic == NULL || !ic->is_enabled || ic->is_english) { filepath = ENG_ICON; } gtk_status_icon_set_from_file(icbar_tray, filepath); } GtkWidget* ui_create_window() { GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_decorated(GTK_WINDOW(window), false); gtk_window_set_deletable(GTK_WINDOW(window), false); gtk_window_set_accept_focus(GTK_WINDOW(window), false); gtk_window_set_focus_on_map(GTK_WINDOW(window), false); gtk_window_set_keep_above(GTK_WINDOW(window), true); gtk_window_set_skip_pager_hint(GTK_WINDOW(window), true); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), true); return window; } static GdkPixbuf* load_pixbuf(const char* skin_name, const char* filename, gboolean sys_dir) { char filepath[256]; if (sys_dir) { snprintf(filepath, 256, SYSTEM_SKIN_DIR"/%s/%s.png", skin_name, filename); } else { snprintf(filepath, 256, USER_SKIN_DIR"/%s/%s.png", getenv("HOME"), skin_name, filename); } return gdk_pixbuf_new_from_file(filepath, NULL); } #define FILL_PIXBUF(name) \ info->name = load_pixbuf(skin_name, name, sys_dir) static void fill_button_pixbuf(skin_button_info_t* info, const char* skin_name, gboolean sys_dir, const char* normal1, const char* normal2, const char* highlight1, const char* highlight2, const char* pressdown1, const char* pressdown2) { FILL_PIXBUF(normal1); FILL_PIXBUF(normal2); FILL_PIXBUF(highlight1); FILL_PIXBUF(highlight2); FILL_PIXBUF(pressdown1); FILL_PIXBUF(pressdown2); } static void fill_label_info(skin_label_info_t* info, FILE* fp) { fscanf(fp, "%d %d\n", &(info->x), &(info->y)); fgets(info->font, 256, fp); /* remove the last \n */ info->font[strlen(info->font) - 1] = 0; fscanf(fp, "%lf %lf %lf %lf\n", &(info->color_r), &(info->color_g), &(info->color_b), &(info->color_a)); } skin_info_t* ui_skin_new(const char* skin_name) { char filepath[256]; gboolean sys_dir = TRUE; snprintf(filepath, 256, SYSTEM_SKIN_DIR"/%s/info", skin_name); FILE* fp = fopen(filepath, "r"); if (!fp) { sys_dir = FALSE; snprintf(filepath, 256, USER_SKIN_DIR"/%s/info", getenv("HOME"), skin_name); fp = fopen(filepath, "r"); if (!fp) { fprintf(stderr, "Cannot open skin %s\n", skin_name); return NULL; } } skin_info_t* info = malloc(sizeof(skin_info_t)); fscanf(fp, "%d %d %d %d %d %d\n", &(info->eng_btn.x), &(info->eng_btn.y), &(info->full_btn.x), &(info->full_btn.y), &(info->punc_btn.x), &(info->punc_btn.y)); fill_label_info(&(info->preedit_label), fp); fill_label_info(&(info->candidate_label), fp); fscanf(fp, "%d %d\n", &(info->offset_x), &(info->offset_y)); fscanf(fp, "%d %d %d %d\n", &(info->top), &(info->left), &(info->bottom), &(info->right)); fclose(fp); fill_button_pixbuf(&(info->eng_btn), skin_name, sys_dir, "eng", "han", "eng-hover", "han-hover", "eng-press", "han-press"); fill_button_pixbuf(&(info->full_btn), skin_name, sys_dir, "full", "half", "full-hover", "half-hover", "full-press", "half-press"); fill_button_pixbuf(&(info->punc_btn), skin_name, sys_dir, "han-punc", "eng-punc", "han-punc-hover", "eng-punc-hover", "han-punc-press", "eng-punc-press"); info->icbar_background = load_pixbuf(skin_name, "icbar", sys_dir); info->preedit_background = load_pixbuf(skin_name, "preedit", sys_dir); return info; } static void free_button_info(skin_button_info_t* info) { g_object_unref(info->normal1); g_object_unref(info->highlight1); g_object_unref(info->pressdown1); g_object_unref(info->normal2); g_object_unref(info->highlight2); g_object_unref(info->pressdown2); } void ui_skin_destroy(skin_info_t* info) { g_object_unref(info->icbar_background); g_object_unref(info->preedit_background); free_button_info(&(info->eng_btn)); free_button_info(&(info->full_btn)); free_button_info(&(info->punc_btn)); } xsunpinyin-2.0.3/ui.h0000644000076400007640000000621711527365010013200 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _UI_H_ #define _UI_H_ #include "common.h" #include "settings.h" #include __BEGIN_DECLS typedef struct _skin_button_info_t { int x, y; GdkPixbuf* normal1; GdkPixbuf* highlight1; GdkPixbuf* pressdown1; GdkPixbuf* normal2; GdkPixbuf* highlight2; GdkPixbuf* pressdown2; } skin_button_info_t; typedef struct _skin_label_info_t { int x, y; char font[256]; double color_r, color_g, color_b, color_a; } skin_label_info_t; typedef struct _skin_info_t { skin_button_info_t eng_btn, full_btn, punc_btn; GdkPixbuf* icbar_background; skin_label_info_t preedit_label; skin_label_info_t candidate_label; GdkPixbuf* preedit_background; int top, left, bottom, right; /* margins of preedit */ int offset_x, offset_y; /* offset of preedit */ } skin_info_t; void ui_tray_init (void); void ui_tray_refresh (void); GtkWidget* ui_create_window (void); skin_info_t* ui_skin_new (const char* name); void ui_skin_destroy (skin_info_t* info); __END_DECLS #endif /* _UI_H_ */ xsunpinyin-2.0.3/xmisc.c0000644000076400007640000000643111527365010013677 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include "xmisc.h" void get_window_position(Window w, int* x, int* y) { int tx = 0, ty = 0; Window child; if (XTranslateCoordinates(dpy, w, DefaultRootWindow(dpy), 0, 0, &tx, &ty, &child) < 0) { printf("ERROR\n"); return; } if (x != NULL) (*x) = tx; if (y != NULL) (*y) = ty; } void get_window_size(Window w, int* width, int* height) { XWindowAttributes attrs; if (XGetWindowAttributes(dpy, w, &attrs) < 0) { printf("ERROR\n"); } if (width != NULL) (*width) = attrs.width; if (height != NULL) (*height) = attrs.height; } void get_screen_size(int* width, int* height) { get_window_size(DefaultRootWindow(dpy), width, height); } Display* dpy = NULL; void init_display(int* argc, char*** argv) { gtk_init(argc, argv); dpy = GDK_DISPLAY(); } static int in_range(int x, int min, int max) { if (x < min) x = min; if (x > max) x = max; return x; } void adjust_position(int* x, int* y, int width, int height) { int screen_width, screen_height; get_screen_size(&screen_width, &screen_height); *x = in_range(*x, 0, screen_width - width); *y = in_range(*y, 0, screen_height - height); } xsunpinyin-2.0.3/xmisc.h0000644000076400007640000000474711527365010013714 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _XMISC_H_ #define _XMISC_H_ #include #include #include #include #include "common.h" __BEGIN_DECLS void get_window_position(Window w, int* x, int* y); void get_window_size(Window w, int* width, int* height); void get_screen_size(int* width, int* height); void init_display(int* argc, char*** argv); void adjust_position(int* x, int* y, int width, int height); extern Display* dpy; __END_DECLS #endif /* _XMISC_H_ */ xsunpinyin-2.0.3/IMdkit/0000755000076400007640000000000011527365010013565 5ustar mikemikexsunpinyin-2.0.3/IMdkit/FrameMgr.c0000644000076400007640000016711711527365010015446 0ustar mikemike/****************************************************************** Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Digital or MIT not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hiroyuki Miyamoto Digital Equipment Corporation miyamoto@jrd.dec.com This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include #include "FrameMgr.h" /* Convenient macro */ #define _UNIT(n) ((int)(n) & 0xFF) #define _NUMBER(n) (((int)(n) >> 8) & 0xFF) /* For byte swapping */ #define Swap16(p, n) ((p)->byte_swap ? \ (((n) << 8 & 0xFF00) | \ ((n) >> 8 & 0xFF) \ ) : n) #define Swap32(p, n) ((p)->byte_swap ? \ (((n) << 24 & 0xFF000000) | \ ((n) << 8 & 0xFF0000) | \ ((n) >> 8 & 0xFF00) | \ ((n) >> 24 & 0xFF) \ ) : n) #define Swap64(p, n) ((p)->byte_swap ? \ (((n) << 56 & 0xFF00000000000000) | \ ((n) << 40 & 0xFF000000000000) | \ ((n) << 24 & 0xFF0000000000) | \ ((n) << 8 & 0xFF00000000) | \ ((n) >> 8 & 0xFF000000) | \ ((n) >> 24 & 0xFF0000) | \ ((n) >> 40 & 0xFF00) | \ ((n) >> 56 & 0xFF) \ ) : n) /* Type definition */ typedef struct _Iter *Iter; typedef struct _FrameInst *FrameInst; typedef union { int num; /* For BARRAY */ FrameInst fi; /* For POINTER */ Iter iter; /* For ITER */ } ExtraDataRec, *ExtraData; typedef struct _Chain { ExtraDataRec d; int frame_no; struct _Chain *next; } ChainRec, *Chain; typedef struct _ChainMgr { Chain top; Chain tail; } ChainMgrRec, *ChainMgr; typedef struct _ChainIter { Chain cur; } ChainIterRec, *ChainIter; typedef struct _FrameIter { Iter iter; Bool counting; unsigned int counter; int end; struct _FrameIter* next; } FrameIterRec, *FrameIter; typedef struct _FrameInst { XimFrame template; ChainMgrRec cm; int cur_no; } FrameInstRec; typedef void (*IterStartWatchProc) (Iter it, void *client_data); typedef struct _Iter { XimFrame template; int max_count; Bool allow_expansion; ChainMgrRec cm; int cur_no; IterStartWatchProc start_watch_proc; void *client_data; Bool start_counter; } IterRec; typedef struct _FrameMgr { XimFrame frame; FrameInst fi; char *area; int idx; Bool byte_swap; int total_size; FrameIter iters; } FrameMgrRec; typedef union { int num; /* For BARRAY and PAD */ struct { /* For COUNTER_* */ Iter iter; Bool is_byte_len; } counter; } XimFrameTypeInfoRec, *XimFrameTypeInfo; /* Special values */ #define NO_VALUE -1 #define NO_VALID_FIELD -2 static FrameInst FrameInstInit(XimFrame frame); static void FrameInstFree(FrameInst fi); static XimFrameType FrameInstGetNextType(FrameInst fi, XimFrameTypeInfo info); static XimFrameType FrameInstPeekNextType(FrameInst fi, XimFrameTypeInfo info); static FmStatus FrameInstSetSize(FrameInst fi, int num); static FmStatus FrameInstSetIterCount(FrameInst fi, int num); static int FrameInstGetTotalSize(FrameInst fi); static void FrameInstReset(FrameInst fi); static Iter IterInit(XimFrame frame, int count); static void IterFree(Iter it); static int FrameInstGetSize(FrameInst fi); static int IterGetSize(Iter it); static XimFrameType IterGetNextType(Iter it, XimFrameTypeInfo info); static XimFrameType IterPeekNextType(Iter it, XimFrameTypeInfo info); static FmStatus IterSetSize(Iter it, int num); static FmStatus IterSetIterCount(Iter it, int num); static int IterGetTotalSize(Iter it); static void IterReset(Iter it); static Bool IterIsLoopEnd(Iter it, Bool* myself); static void IterSetStartWatch(Iter it, IterStartWatchProc proc, void* client_data); static void _IterStartWatch(Iter it, void* client_data); static ExtraData ChainMgrGetExtraData(ChainMgr cm, int frame_no); static ExtraData ChainMgrSetData(ChainMgr cm, int frame_no, ExtraDataRec data); static Bool ChainIterGetNext(ChainIter ci, int* frame_no, ExtraData d); static int _FrameInstIncrement(XimFrame frame, int count); static int _FrameInstDecrement(XimFrame frame, int count); static int _FrameInstGetItemSize(FrameInst fi, int cur_no); static Bool FrameInstIsIterLoopEnd(FrameInst fi); static FrameIter _FrameMgrAppendIter(FrameMgr fm, Iter it, int end); static FrameIter _FrameIterCounterIncr(FrameIter fitr, int i); static void _FrameMgrRemoveIter(FrameMgr fm, FrameIter it); static Bool _FrameMgrIsIterLoopEnd(FrameMgr fm); static Bool _FrameMgrProcessPadding(FrameMgr fm, FmStatus* status); #define IterGetIterCount(it) ((it)->allow_expansion ? \ NO_VALUE : (it)->max_count) #define IterFixIteration(it) ((it)->allow_expansion = False) #define IterSetStarter(it) ((it)->start_counter = True) #define ChainMgrInit(cm) (cm)->top = (cm)->tail = NULL #define ChainMgrFree(cm) \ { \ Chain tmp; \ Chain cur = (cm)->top; \ \ while (cur) \ { \ tmp = cur->next; \ Xfree (cur); \ cur = tmp; \ } \ } #define ChainIterInit(ci, cm) \ { \ (ci)->cur = (cm)->top; \ } /* ChainIterFree has nothing to do. */ #define ChainIterFree(ci) #define FrameInstIsEnd(fi) ((fi)->template[(fi)->cur_no].type == EOL) FrameMgr FrameMgrInit (XimFrame frame, char* area, Bool byte_swap) { FrameMgr fm; fm = (FrameMgr) Xmalloc (sizeof (FrameMgrRec)); fm->frame = frame; fm->fi = FrameInstInit (frame); fm->area = (char *) area; fm->idx = 0; fm->byte_swap = byte_swap; fm->total_size = NO_VALUE; fm->iters = NULL; return fm; } void FrameMgrInitWithData (FrameMgr fm, XimFrame frame, void * area, Bool byte_swap) { fm->frame = frame; fm->fi = FrameInstInit (frame); fm->area = (char *) area; fm->idx = 0; fm->byte_swap = byte_swap; fm->total_size = NO_VALUE; } void FrameMgrFree (FrameMgr fm) { FrameIter p, cur; p = fm->iters; cur = p; while (p) { p = p->next; Xfree (cur); cur = p; } /*endwhile*/ FrameInstFree (fm->fi); Xfree (fm); } FmStatus FrameMgrSetBuffer (FrameMgr fm, void* area) { if (fm->area) return FmBufExist; fm->area = (char *) area; return FmSuccess; } FmStatus _FrameMgrPutToken (FrameMgr fm, void *data, int data_size) { XimFrameType type; XimFrameTypeInfoRec info; if (fm->total_size != NO_VALUE && fm->idx >= fm->total_size) return FmNoMoreData; /*endif*/ type = FrameInstGetNextType(fm->fi, &info); if (type & COUNTER_MASK) { unsigned long input_length; if (info.counter.is_byte_len) { if ((input_length = IterGetTotalSize (info.counter.iter)) == NO_VALUE) { return FmCannotCalc; } /*endif*/ } else { if ((input_length = IterGetIterCount (info.counter.iter)) == NO_VALUE) { return FmCannotCalc; } /*endif*/ } /*endif*/ switch (type) { case COUNTER_BIT8: *(CARD8 *) (fm->area + fm->idx) = input_length; fm->idx++; break; case COUNTER_BIT16: *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, input_length); fm->idx += 2; break; case COUNTER_BIT32: *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, input_length); fm->idx += 4; break; #if defined(_NEED64BIT) case COUNTER_BIT64: *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, input_length); fm->idx += 8; break; #endif default: break; } /*endswitch*/ _FrameMgrPutToken(fm, data, data_size); return FmSuccess; } /*endif*/ switch (type) { case BIT8: if (data_size == sizeof (unsigned char)) { unsigned long num = *(unsigned char *) data; *(CARD8 *) (fm->area + fm->idx) = num; } else if (data_size == sizeof (unsigned short)) { unsigned long num = *(unsigned short *) data; *(CARD8 *) (fm->area + fm->idx) = num; } else if (data_size == sizeof (unsigned int)) { unsigned long num = *(unsigned int *) data; *(CARD8 *) (fm->area + fm->idx) = num; } else if (data_size == sizeof (unsigned long)) { unsigned long num = *(unsigned long *) data; *(CARD8 *) (fm->area + fm->idx) = num; } else { ; /* Should never be reached */ } /*endif*/ fm->idx++; return FmSuccess; case BIT16: if (data_size == sizeof (unsigned char)) { unsigned long num = *(unsigned char *) data; *(CARD16*)(fm->area + fm->idx) = Swap16 (fm, num); } else if (data_size == sizeof (unsigned short)) { unsigned long num = *(unsigned short *) data; *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num); } else if (data_size == sizeof (unsigned int)) { unsigned long num = *(unsigned int *) data; *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num); } else if (data_size == sizeof (unsigned long)) { unsigned long num = *(unsigned long *) data; *(CARD16 *) (fm->area + fm->idx) = Swap16 (fm, num); } else { ; /* Should never reached */ } /*endif*/ fm->idx += 2; return FmSuccess; case BIT32: if (data_size == sizeof (unsigned char)) { unsigned long num = *(unsigned char *) data; *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num); } else if (data_size == sizeof (unsigned short)) { unsigned long num = *(unsigned short *) data; *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num); } else if (data_size == sizeof (unsigned int)) { unsigned long num = *(unsigned int *) data; *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num); } else if (data_size == sizeof (unsigned long)) { unsigned long num = *(unsigned long *) data; *(CARD32 *) (fm->area + fm->idx) = Swap32 (fm, num); } else { ; /* Should never reached */ } /*endif*/ fm->idx += 4; return FmSuccess; #if defined(_NEED64BIT) case BIT64: if (data_size == sizeof (unsigned char)) { unsigned long num = *(unsigned char *) data; *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num); } else if (data_size == sizeof (unsigned short)) { unsigned long num = *(unsigned short *) data; *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num); } else if (data_size == sizeof (unsigned int)) { unsigned long num = *(unsigned int *) data; *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num); } else if (data_size == sizeof (unsigned long)) { unsigned long num = *(unsigned long *) data; *(CARD64 *) (fm->area + fm->idx) = Swap64 (fm, num); } else { ; /* Should never reached */ } /*endif*/ fm->idx += 4; return FmSuccess; #endif case BARRAY: if (info.num == NO_VALUE) return FmInvalidCall; /*endif*/ if (info.num > 0) { bcopy (*(char **) data, fm->area + fm->idx, info.num); fm->idx += info.num; } /*endif*/ return FmSuccess; case PADDING: if (info.num == NO_VALUE) return FmInvalidCall; /*endif*/ fm->idx += info.num; return _FrameMgrPutToken(fm, data, data_size); case ITER: return FmInvalidCall; case EOL: return FmEOD; default: break; } /*endswitch*/ return (FmStatus) NULL; /* Should never be reached */ } FmStatus _FrameMgrGetToken (FrameMgr fm , void* data, int data_size) { XimFrameType type; static XimFrameTypeInfoRec info; /* memory */ FrameIter fitr; if (fm->total_size != NO_VALUE && fm->idx >= fm->total_size) return FmNoMoreData; /*endif*/ type = FrameInstGetNextType(fm->fi, &info); if (type & COUNTER_MASK) { int end=0; FrameIter client_data; type &= ~COUNTER_MASK; switch (type) { case BIT8: end = *(CARD8 *) (fm->area + fm->idx); break; case BIT16: end = Swap16 (fm, *(CARD16 *) (fm->area + fm->idx)); break; case BIT32: end = Swap32 (fm, *(CARD32 *) (fm->area + fm->idx)); break; #if defined(_NEED64BIT) case BIT64: end = Swap64 (fm, *(CARD64 *) (fm->area + fm->idx)); break; #endif default: break; } /*endswitch*/ if ((client_data = _FrameMgrAppendIter (fm, info.counter.iter, end))) { IterSetStarter (info.counter.iter); IterSetStartWatch (info.counter.iter, _IterStartWatch, (void *) client_data); } /*endif*/ } /*endif*/ type &= ~COUNTER_MASK; switch (type) { case BIT8: if (data_size == sizeof (unsigned char)) { *(unsigned char*) data = *(CARD8 *) (fm->area + fm->idx); } else if (data_size == sizeof (unsigned short)) { *(unsigned short *) data = *(CARD8 *) (fm->area + fm->idx); } else if (data_size == sizeof (unsigned int)) { *(unsigned int *) data = *(CARD8 *) (fm->area + fm->idx); } else if (data_size == sizeof (unsigned long)) { *(unsigned long *) data = *(CARD8 *) (fm->area + fm->idx); } else { ; /* Should never reached */ } /*endif*/ fm->idx++; if ((fitr = _FrameIterCounterIncr (fm->iters, 1/*BIT8*/))) _FrameMgrRemoveIter (fm, fitr); /*endif*/ return FmSuccess; case BIT16: if (data_size == sizeof (unsigned char)) { *(unsigned char *) data = Swap16 (fm, *(CARD16 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned short)) { *(unsigned short *) data = Swap16 (fm, *(CARD16 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned int)) { *(unsigned int *) data = Swap16 (fm, *(CARD16 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned long)) { *(unsigned long *) data = Swap16 (fm, *(CARD16 *) (fm->area + fm->idx)); } else { ; /* Should never reached */ } /*endif*/ fm->idx += 2; if ((fitr = _FrameIterCounterIncr (fm->iters, 2/*BIT16*/))) _FrameMgrRemoveIter(fm, fitr); /*endif*/ return FmSuccess; case BIT32: if (data_size == sizeof (unsigned char)) { *(unsigned char *) data = Swap32 (fm, *(CARD32 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned short)) { *(unsigned short *) data = Swap32 (fm, *(CARD32 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned int)) { *(unsigned int *) data = Swap32 (fm, *(CARD32 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned long)) { *(unsigned long *) data = Swap32 (fm, *(CARD32 *) (fm->area + fm->idx)); } else { ; /* Should never reached */ } /*endif*/ fm->idx += 4; if ((fitr = _FrameIterCounterIncr (fm->iters, 4/*BIT32*/))) _FrameMgrRemoveIter (fm, fitr); /*endif*/ return FmSuccess; #if defined(_NEED64BIT) case BIT64: if (data_size == sizeof (unsigned char)) { *(unsigned char *) data = Swap64 (fm, *(CARD64 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned short)) { *(unsigned short *) data = Swap64 (fm, *(CARD64 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned int)) { *(unsigned int *) data = Swap64 (fm, *(CARD64 *) (fm->area + fm->idx)); } else if (data_size == sizeof (unsigned long)) { *(unsigned long *) data = Swap64 (fm, *(CARD64 *) (fm->area + fm->idx)); } else { ; /* Should never reached */ } /*endif*/ fm->idx += 8; if ((fitr = _FrameIterCounterIncr (fm->iters, 8/*BIT64*/))) _FrameMgrRemoveIter (fm, fitr); /*endif*/ return FmSuccess; #endif case BARRAY: if (info.num == NO_VALUE) return FmInvalidCall; /*endif*/ if (info.num > 0) { *(char **) data = fm->area + fm->idx; fm->idx += info.num; if ((fitr = _FrameIterCounterIncr (fm->iters, info.num))) _FrameMgrRemoveIter (fm, fitr); /*endif*/ } else { *(char **) data = NULL; } /*endif*/ return FmSuccess; case PADDING: if (info.num == NO_VALUE) return FmInvalidCall; /*endif*/ fm->idx += info.num; if ((fitr = _FrameIterCounterIncr (fm->iters, info.num))) _FrameMgrRemoveIter (fm, fitr); /*endif*/ return _FrameMgrGetToken (fm, data, data_size); case ITER: return FmInvalidCall; /* if comes here, it's a bug! */ case EOL: return FmEOD; default: break; } /*endswitch*/ return (FmStatus) NULL; /* Should never be reached */ } FmStatus FrameMgrSetSize (FrameMgr fm, int barray_size) { if (FrameInstSetSize (fm->fi, barray_size) == FmSuccess) return FmSuccess; /*endif*/ return FmNoMoreData; } FmStatus FrameMgrSetIterCount (FrameMgr fm, int count) { if (FrameInstSetIterCount (fm->fi, count) == FmSuccess) return FmSuccess; /*endif*/ return FmNoMoreData; } FmStatus FrameMgrSetTotalSize (FrameMgr fm, int total_size) { fm->total_size = total_size; return FmSuccess; } int FrameMgrGetTotalSize (FrameMgr fm) { return FrameInstGetTotalSize (fm->fi); } int FrameMgrGetSize (FrameMgr fm) { register int ret_size; ret_size = FrameInstGetSize (fm->fi); if (ret_size == NO_VALID_FIELD) return NO_VALUE; /*endif*/ return ret_size; } FmStatus FrameMgrSkipToken (FrameMgr fm, int skip_count) { XimFrameType type; XimFrameTypeInfoRec info; register int i; if (fm->total_size != NO_VALUE && fm->idx >= fm->total_size) return FmNoMoreData; /*endif*/ for (i = 0; i < skip_count; i++) { type = FrameInstGetNextType (fm->fi, &info); type &= ~COUNTER_MASK; switch (type) { case BIT8: fm->idx++; break; case BIT16: fm->idx += 2; break; case BIT32: fm->idx += 4; break; case BIT64: fm->idx += 8; break; case BARRAY: if (info.num == NO_VALUE) return FmInvalidCall; /*endif*/ fm->idx += info.num; break; case PADDING: if (info.num == NO_VALUE) return FmInvalidCall; /*endif*/ fm->idx += info.num; return FrameMgrSkipToken (fm, skip_count); case ITER: return FmInvalidCall; case EOL: return FmEOD; default: break; } /*endswitch*/ } /*endfor*/ return FmSuccess; } void FrameMgrReset (FrameMgr fm) { fm->idx = 0; FrameInstReset (fm->fi); } Bool FrameMgrIsIterLoopEnd (FrameMgr fm, FmStatus* status) { do { if (_FrameMgrIsIterLoopEnd (fm)) return True; /*endif*/ } while (_FrameMgrProcessPadding (fm, status)); return False; } /* Internal routines */ static Bool _FrameMgrIsIterLoopEnd (FrameMgr fm) { return FrameInstIsIterLoopEnd (fm->fi); } static Bool _FrameMgrProcessPadding (FrameMgr fm, FmStatus* status) { XimFrameTypeInfoRec info; XimFrameType next_type = FrameInstPeekNextType (fm->fi, &info); FrameIter fitr; if (next_type == PADDING) { if (info.num == NO_VALUE) { *status = FmInvalidCall; return True; } /*endif*/ next_type = FrameInstGetNextType (fm->fi, &info); fm->idx += info.num; if ((fitr = _FrameIterCounterIncr (fm->iters, info.num))) _FrameMgrRemoveIter (fm, fitr); /*endif*/ *status = FmSuccess; return True; } /*endif*/ *status = FmSuccess; return False; } static FrameInst FrameInstInit (XimFrame frame) { FrameInst fi; fi = (FrameInst) Xmalloc (sizeof (FrameInstRec)); fi->template = frame; fi->cur_no = 0; ChainMgrInit (&fi->cm); return fi; } static void FrameInstFree (FrameInst fi) { ChainIterRec ci; int frame_no; ExtraDataRec d; ChainIterInit (&ci, &fi->cm); while (ChainIterGetNext (&ci, &frame_no, &d)) { register XimFrameType type; type = fi->template[frame_no].type; if (type == ITER) { if (d.iter) IterFree (d.iter); /*endif*/ } else if (type == POINTER) { if (d.fi) FrameInstFree (d.fi); /*endif*/ } /*endif*/ } /*endwhile*/ ChainIterFree (&ci); ChainMgrFree (&fi->cm); Xfree (fi); } static XimFrameType FrameInstGetNextType(FrameInst fi, XimFrameTypeInfo info) { XimFrameType ret_type; ret_type = fi->template[fi->cur_no].type; switch (ret_type) { case BIT8: case BIT16: case BIT32: case BIT64: case EOL: fi->cur_no = _FrameInstIncrement(fi->template, fi->cur_no); break; case COUNTER_BIT8: case COUNTER_BIT16: case COUNTER_BIT32: case COUNTER_BIT64: if (info) { register int offset, iter_idx; info->counter.is_byte_len = (((long) fi->template[fi->cur_no].data & 0xFF)) == FmCounterByte; offset = ((long) fi->template[fi->cur_no].data) >> 8; iter_idx = fi->cur_no + offset; if (fi->template[iter_idx].type == ITER) { ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&fi->cm, iter_idx)) == NULL) { dr.iter = IterInit (&fi->template[iter_idx + 1], NO_VALUE); d = ChainMgrSetData (&fi->cm, iter_idx, dr); } /*endif*/ info->counter.iter = d->iter; } else { /* Should never reach here */ } /*endif*/ } /*endif*/ fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no); break; case BARRAY: if (info) { ExtraData d; if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL) info->num = NO_VALUE; else info->num = d->num; /*endif*/ } /*endif*/ fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no); break; case PADDING: if (info) { register int unit; register int number; register int size; register int i; unit = _UNIT ((long) fi->template[fi->cur_no].data); number = _NUMBER ((long) fi->template[fi->cur_no].data); i = fi->cur_no; size = 0; while (number > 0) { i = _FrameInstDecrement (fi->template, i); size += _FrameInstGetItemSize (fi, i); number--; } /*endwhile*/ info->num = (unit - (size%unit))%unit; } /*endif*/ fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no); break; case ITER: { ExtraData d; ExtraDataRec dr; XimFrameType sub_type; if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL) { dr.iter = IterInit (&fi->template[fi->cur_no + 1], NO_VALUE); d = ChainMgrSetData (&fi->cm, fi->cur_no, dr); } /*endif*/ sub_type = IterGetNextType (d->iter, info); if (sub_type == EOL) { fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no); ret_type = FrameInstGetNextType (fi, info); } else { ret_type = sub_type; } /*endif*/ } break; case POINTER: { ExtraData d; ExtraDataRec dr; XimFrameType sub_type; if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL) { dr.fi = FrameInstInit (fi->template[fi->cur_no + 1].data); d = ChainMgrSetData (&fi->cm, fi->cur_no, dr); } /*endif*/ sub_type = FrameInstGetNextType (d->fi, info); if (sub_type == EOL) { fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no); ret_type = FrameInstGetNextType (fi, info); } else { ret_type = sub_type; } /*endif*/ } break; default: break; } /*endswitch*/ return ret_type; } static XimFrameType FrameInstPeekNextType (FrameInst fi, XimFrameTypeInfo info) { XimFrameType ret_type; ret_type = fi->template[fi->cur_no].type; switch (ret_type) { case BIT8: case BIT16: case BIT32: case BIT64: case EOL: break; case COUNTER_BIT8: case COUNTER_BIT16: case COUNTER_BIT32: case COUNTER_BIT64: if (info) { register int offset; register int iter_idx; info->counter.is_byte_len = (((long) fi->template[fi->cur_no].data) & 0xFF) == FmCounterByte; offset = ((long)fi->template[fi->cur_no].data) >> 8; iter_idx = fi->cur_no + offset; if (fi->template[iter_idx].type == ITER) { ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&fi->cm, iter_idx)) == NULL) { dr.iter = IterInit (&fi->template[iter_idx + 1], NO_VALUE); d = ChainMgrSetData (&fi->cm, iter_idx, dr); } /*endif*/ info->counter.iter = d->iter; } else { /* Should not be reached here */ } /*endif*/ } /*endif*/ break; case BARRAY: if (info) { ExtraData d; if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL) info->num = NO_VALUE; else info->num = d->num; /*endif*/ } /*endif*/ break; case PADDING: if (info) { register int unit; register int number; register int size; register int i; unit = _UNIT ((long) fi->template[fi->cur_no].data); number = _NUMBER ((long) fi->template[fi->cur_no].data); i = fi->cur_no; size = 0; while (number > 0) { i = _FrameInstDecrement (fi->template, i); size += _FrameInstGetItemSize (fi, i); number--; } /*endwhile*/ info->num = (unit - (size%unit))%unit; } /*endif*/ break; case ITER: { ExtraData d; ExtraDataRec dr; XimFrameType sub_type; if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL) { dr.iter = IterInit (&fi->template[fi->cur_no + 1], NO_VALUE); d = ChainMgrSetData (&fi->cm, fi->cur_no, dr); } /*endif*/ sub_type = IterPeekNextType (d->iter, info); if (sub_type == EOL) ret_type = FrameInstPeekNextType (fi, info); else ret_type = sub_type; /*endif*/ } break; case POINTER: { ExtraData d; ExtraDataRec dr; XimFrameType sub_type; if ((d = ChainMgrGetExtraData (&fi->cm, fi->cur_no)) == NULL) { dr.fi = FrameInstInit (fi->template[fi->cur_no + 1].data); d = ChainMgrSetData (&fi->cm, fi->cur_no, dr); } /*endif*/ sub_type = FrameInstPeekNextType (d->fi, info); if (sub_type == EOL) ret_type = FrameInstPeekNextType (fi, info); else ret_type = sub_type; /*endif*/ default: break; } break; } /*endswitch*/ return ret_type; } static Bool FrameInstIsIterLoopEnd (FrameInst fi) { Bool ret = False; if (fi->template[fi->cur_no].type == ITER) { ExtraData d = ChainMgrGetExtraData (&fi->cm, fi->cur_no); Bool yourself; if (d) { ret = IterIsLoopEnd (d->iter, &yourself); if (ret && yourself) fi->cur_no = _FrameInstIncrement (fi->template, fi->cur_no); /*endif*/ } /*endif*/ } /*endif*/ return (ret); } static FrameIter _FrameMgrAppendIter (FrameMgr fm, Iter it, int end) { FrameIter p = fm->iters; while (p && p->next) p = p->next; /*endwhile*/ if (!p) { fm->iters = p = (FrameIter) Xmalloc (sizeof (FrameIterRec)); } else { p->next = (FrameIter) Xmalloc (sizeof (FrameIterRec)); p = p->next; } /*endif*/ if (p) { p->iter = it; p->counting = False; p->counter = 0; p->end = end; p->next = NULL; } /*endif*/ return (p); } static void _FrameMgrRemoveIter (FrameMgr fm, FrameIter it) { FrameIter prev; FrameIter p; prev = NULL; p = fm->iters; while (p) { if (p == it) { if (prev) prev->next = p->next; else fm->iters = p->next; /*endif*/ Xfree (p); break; } /*endif*/ prev = p; p = p->next; } /*endwhile*/ } static FrameIter _FrameIterCounterIncr (FrameIter fitr, int i) { FrameIter p = fitr; while (p) { if (p->counting) { p->counter += i; if (p->counter >= p->end) { IterFixIteration (p->iter); return (p); } /*endif*/ } /*endif*/ p = p->next; } /*endwhile*/ return (NULL); } static void _IterStartWatch (Iter it, void *client_data) { FrameIter p = (FrameIter) client_data; p->counting = True; } static FmStatus FrameInstSetSize (FrameInst fi, int num) { ExtraData d; ExtraDataRec dr; XimFrameType type; register int i; i = 0; while ((type = fi->template[i].type) != EOL) { switch (type) { case BARRAY: if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL) { dr.num = -1; d = ChainMgrSetData (&fi->cm, i, dr); } /*endif*/ if (d->num == NO_VALUE) { d->num = num; return FmSuccess; } /*endif*/ break; case ITER: if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL) { dr.iter = IterInit (&fi->template[i + 1], NO_VALUE); d = ChainMgrSetData (&fi->cm, i, dr); } /*endif*/ if (IterSetSize (d->iter, num) == FmSuccess) return FmSuccess; /*endif*/ break; case POINTER: if ((d = ChainMgrGetExtraData(&fi->cm, i)) == NULL) { dr.fi = FrameInstInit(fi->template[i + 1].data); d = ChainMgrSetData(&fi->cm, i, dr); } /*endif*/ if (FrameInstSetSize(d->fi, num) == FmSuccess) return FmSuccess; /*endif*/ break; default: break; } /*endswitch*/ i = _FrameInstIncrement(fi->template, i); } /*endwhile*/ return FmNoMoreData; } static int FrameInstGetSize (FrameInst fi) { XimFrameType type; register int i; ExtraData d; ExtraDataRec dr; int ret_size; i = fi->cur_no; while ((type = fi->template[i].type) != EOL) { switch (type) { case BARRAY: if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL) return NO_VALUE; /*endif*/ return d->num; case ITER: if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL) { dr.iter = IterInit (&fi->template[i + 1], NO_VALUE); d = ChainMgrSetData (&fi->cm, i, dr); } /*endif*/ ret_size = IterGetSize(d->iter); if (ret_size != NO_VALID_FIELD) return ret_size; /*endif*/ break; case POINTER: if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL) { dr.fi = FrameInstInit (fi->template[i + 1].data); d = ChainMgrSetData (&fi->cm, i, dr); } /*endif*/ ret_size = FrameInstGetSize (d->fi); if (ret_size != NO_VALID_FIELD) return ret_size; /*endif*/ break; default: break; } /*endswitch*/ i = _FrameInstIncrement (fi->template, i); } /*endwhile*/ return NO_VALID_FIELD; } static FmStatus FrameInstSetIterCount (FrameInst fi, int num) { ExtraData d; ExtraDataRec dr; register int i; XimFrameType type; i = 0; while ((type = fi->template[i].type) != EOL) { switch (type) { case ITER: if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL) { dr.iter = IterInit (&fi->template[i + 1], num); (void)ChainMgrSetData (&fi->cm, i, dr); return FmSuccess; } /*endif*/ if (IterSetIterCount (d->iter, num) == FmSuccess) return FmSuccess; /*endif*/ break; case POINTER: if ((d = ChainMgrGetExtraData (&fi->cm, i)) == NULL) { dr.fi = FrameInstInit (fi->template[i + 1].data); d = ChainMgrSetData (&fi->cm, i, dr); } /*endif*/ if (FrameInstSetIterCount (d->fi, num) == FmSuccess) return FmSuccess; /*endif*/ break; default: break; } /*endswitch*/ i = _FrameInstIncrement (fi->template, i); } /*endwhile*/ return FmNoMoreData; } static int FrameInstGetTotalSize (FrameInst fi) { register int size; register int i; size = 0; i = 0; while (fi->template[i].type != EOL) { size += _FrameInstGetItemSize (fi, i); i = _FrameInstIncrement (fi->template, i); } /*endwhile*/ return size; } static void FrameInstReset (FrameInst fi) { ChainIterRec ci; int frame_no; ExtraDataRec d; ChainIterInit (&ci, &fi->cm); while (ChainIterGetNext (&ci, &frame_no, &d)) { register XimFrameType type; type = fi->template[frame_no].type; if (type == ITER) { if (d.iter) IterReset (d.iter); /*endif*/ } else if (type == POINTER) { if (d.fi) FrameInstReset (d.fi); /*endif*/ } /*endif*/ } /*endwhile*/ ChainIterFree (&ci); fi->cur_no = 0; } static Iter IterInit (XimFrame frame, int count) { Iter it; register XimFrameType type; it = (Iter) Xmalloc (sizeof (IterRec)); it->template = frame; it->max_count = (count == NO_VALUE) ? 0 : count; it->allow_expansion = (count == NO_VALUE); it->cur_no = 0; it->start_watch_proc = NULL; it->client_data = NULL; it->start_counter = False; type = frame->type; if (type & COUNTER_MASK) { /* COUNTER_XXX cannot be an item of a ITER */ Xfree (it); return NULL; } /*endif*/ switch (type) { case BIT8: case BIT16: case BIT32: case BIT64: /* Do nothing */ break; case BARRAY: case ITER: case POINTER: ChainMgrInit (&it->cm); break; default: Xfree (it); return NULL; /* This should never occur */ } /*endswitch*/ return it; } static void IterFree (Iter it) { switch (it->template->type) { case BARRAY: ChainMgrFree (&it->cm); break; case ITER: { ChainIterRec ci; int count; ExtraDataRec d; ChainIterInit (&ci, &it->cm); while (ChainIterGetNext (&ci, &count, &d)) IterFree (d.iter); /*endwhile*/ ChainIterFree (&ci); ChainMgrFree (&it->cm); } break; case POINTER: { ChainIterRec ci; int count; ExtraDataRec dr; ChainIterInit (&ci, &it->cm); while (ChainIterGetNext (&ci, &count, &dr)) FrameInstFree (dr.fi); /*endwhile*/ ChainIterFree (&ci); ChainMgrFree (&it->cm); } break; default: break; } /*endswitch*/ Xfree (it); } static Bool IterIsLoopEnd (Iter it, Bool *myself) { Bool ret = False; *myself = False; if (!it->allow_expansion && (it->cur_no == it->max_count)) { *myself = True; return True; } /*endif*/ if (it->template->type == POINTER) { ExtraData d = ChainMgrGetExtraData (&it->cm, it->cur_no); if (d) { if (FrameInstIsIterLoopEnd (d->fi)) { ret = True; } else { if (FrameInstIsEnd (d->fi)) { it->cur_no++; if (!it->allow_expansion && it->cur_no == it->max_count) { *myself = True; ret = True; } /*endif*/ } /*endif*/ } /*endif*/ } /*endif*/ } else if (it->template->type == ITER) { ExtraData d = ChainMgrGetExtraData (&it->cm, it->cur_no); if (d) { Bool yourself; if (IterIsLoopEnd (d->iter, &yourself)) ret = True; /*endif*/ } /*endif*/ } /*endif*/ return ret; } static XimFrameType IterGetNextType (Iter it, XimFrameTypeInfo info) { XimFrameType type = it->template->type; if (it->start_counter) { (*it->start_watch_proc) (it, it->client_data); it->start_counter = False; } /*endif*/ if (it->cur_no >= it->max_count) { if (it->allow_expansion) it->max_count = it->cur_no + 1; else return EOL; /*endif*/ } /*endif*/ switch (type) { case BIT8: case BIT16: case BIT32: case BIT64: it->cur_no++; return type; case BARRAY: if (info) { ExtraData d; if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL) info->num = NO_VALUE; else info->num = d->num; /*endif*/ } /*endif*/ it->cur_no++; return BARRAY; case ITER: { XimFrameType ret_type; ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL) { dr.iter = IterInit (it->template + 1, NO_VALUE); d = ChainMgrSetData (&it->cm, it->cur_no, dr); } /*endif*/ ret_type = IterGetNextType (d->iter, info); if (ret_type == EOL) { it->cur_no++; ret_type = IterGetNextType (it, info); } /*endif*/ return ret_type; } case POINTER: { XimFrameType ret_type; ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL) { dr.fi = FrameInstInit (it->template[1].data); d = ChainMgrSetData (&it->cm, it->cur_no, dr); } /*endif*/ ret_type = FrameInstGetNextType (d->fi, info); if (ret_type == EOL) { it->cur_no++; ret_type = IterGetNextType (it, info); } /*endif*/ return ret_type; } default: return (XimFrameType) NULL; } /*endswitch*/ return (XimFrameType) NULL; /* This should never occur */ } static XimFrameType IterPeekNextType (Iter it, XimFrameTypeInfo info) { XimFrameType type = it->template->type; if (!it->allow_expansion && it->cur_no >= it->max_count) return (EOL); /*endif*/ switch (type) { case BIT8: case BIT16: case BIT32: case BIT64: return type; case BARRAY: if (info) { ExtraData d; if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL) info->num = NO_VALUE; else info->num = d->num; /*endif*/ } /*endif*/ return BARRAY; case ITER: { XimFrameType ret_type; ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL) { dr.iter = IterInit (it->template + 1, NO_VALUE); d = ChainMgrSetData (&it->cm, it->cur_no, dr); } /*endif*/ ret_type = IterPeekNextType (d->iter, info); if (ret_type == EOL) ret_type = IterPeekNextType (it, info); /*endif*/ return ret_type; } case POINTER: { XimFrameType ret_type; ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL) { dr.fi = FrameInstInit (it->template[1].data); d = ChainMgrSetData (&it->cm, it->cur_no, dr); } /*endif*/ ret_type = FrameInstPeekNextType (d->fi, info); if (ret_type == EOL) ret_type = IterPeekNextType (it, info); /*endif*/ return (ret_type); } default: break; } /*endswitch*/ /* Reaching here is a bug! */ return (XimFrameType) NULL; } static FmStatus IterSetSize (Iter it, int num) { XimFrameType type; register int i; if (!it->allow_expansion && it->max_count == 0) return FmNoMoreData; /*endif*/ type = it->template->type; switch (type) { case BARRAY: { ExtraData d; ExtraDataRec dr; for (i = 0; i < it->max_count; i++) { if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) { dr.num = NO_VALUE; d = ChainMgrSetData (&it->cm, i, dr); } /*endif*/ if (d->num == NO_VALUE) { d->num = num; return FmSuccess; } /*endif*/ } /*endfor*/ if (it->allow_expansion) { ExtraDataRec dr; dr.num = num; ChainMgrSetData (&it->cm, it->max_count, dr); it->max_count++; return FmSuccess; } /*endif*/ } return FmNoMoreData; case ITER: { ExtraData d; ExtraDataRec dr; for (i = 0; i < it->max_count; i++) { if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) { dr.iter = IterInit (it->template + 1, NO_VALUE); d = ChainMgrSetData (&it->cm, i, dr); } /*endif*/ if (IterSetSize (d->iter, num) == FmSuccess) return FmSuccess; /*endif*/ } /*endfor*/ if (it->allow_expansion) { ExtraDataRec dr; dr.iter = IterInit (it->template + 1, NO_VALUE); ChainMgrSetData (&it->cm, it->max_count, dr); it->max_count++; if (IterSetSize(dr.iter, num) == FmSuccess) return FmSuccess; /*endif*/ } /*endif*/ } return FmNoMoreData; case POINTER: { ExtraData d; ExtraDataRec dr; for (i = 0; i < it->max_count; i++) { if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) { dr.fi = FrameInstInit (it->template[1].data); d = ChainMgrSetData (&it->cm, i, dr); } /*endif*/ if (FrameInstSetSize (d->fi, num) == FmSuccess) return FmSuccess; /*endif*/ } /*endfor*/ if (it->allow_expansion) { ExtraDataRec dr; dr.fi = FrameInstInit (it->template[1].data); ChainMgrSetData (&it->cm, it->max_count, dr); it->max_count++; if (FrameInstSetSize (dr.fi, num) == FmSuccess) return FmSuccess; /*endif*/ } /*endif*/ } return FmNoMoreData; default: break; } /*endswitch*/ return FmNoMoreData; } static int IterGetSize (Iter it) { register int i; ExtraData d; ExtraDataRec dr; if (it->cur_no >= it->max_count) return NO_VALID_FIELD; /*endif*/ switch (it->template->type) { case BARRAY: if ((d = ChainMgrGetExtraData (&it->cm, it->cur_no)) == NULL) return NO_VALUE; /*endif*/ return d->num; case ITER: for (i = it->cur_no; i < it->max_count; i++) { int ret_size; if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) { dr.iter = IterInit (it->template + 1, NO_VALUE); d = ChainMgrSetData (&it->cm, i, dr); } /*endif*/ ret_size = IterGetSize (d->iter); if (ret_size != NO_VALID_FIELD) return ret_size; /*endif*/ } /*endfor*/ return NO_VALID_FIELD; case POINTER: for (i = it->cur_no; i < it->max_count; i++) { int ret_size; if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) { dr.fi = FrameInstInit (it->template[1].data); d = ChainMgrSetData (&it->cm, i, dr); } /*endif*/ ret_size = FrameInstGetSize (d->fi); if (ret_size != NO_VALID_FIELD) return ret_size; /*endif*/ } /*endfor*/ return NO_VALID_FIELD; default: break; } /*endswitch*/ return NO_VALID_FIELD; } static FmStatus IterSetIterCount (Iter it, int num) { register int i; if (it->allow_expansion) { it->max_count = num; it->allow_expansion = False; return FmSuccess; } /*endif*/ if (it->max_count == 0) return FmNoMoreData; /*endif*/ switch (it->template->type) { case ITER: for (i = 0; i < it->max_count; i++) { ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData(&it->cm, i)) == NULL) { dr.iter = IterInit(it->template + 1, num); (void)ChainMgrSetData(&it->cm, i, dr); return FmSuccess; } /*endif*/ if (IterSetIterCount(d->iter, num) == FmSuccess) return FmSuccess; /*endif*/ } /*endfor*/ if (it->allow_expansion) { ExtraDataRec dr; dr.iter = IterInit (it->template + 1, num); ChainMgrSetData (&it->cm, it->max_count, dr); it->max_count++; return FmSuccess; } /*endif*/ break; case POINTER: for (i = 0; i < it->max_count; i++) { ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) { dr.fi = FrameInstInit (it->template[1].data); d = ChainMgrSetData (&it->cm, i, dr); } /*endif*/ if (FrameInstSetIterCount (d->fi, num) == FmSuccess) return FmSuccess; /*endif*/ } /*endfor*/ if (it->allow_expansion) { ExtraDataRec dr; dr.fi = FrameInstInit (it->template[1].data); ChainMgrSetData (&it->cm, it->max_count, dr); it->max_count++; if (FrameInstSetIterCount (dr.fi, num) == FmSuccess) return FmSuccess; /*endif*/ } /*endif*/ break; default: break; } /*endswitch*/ return FmNoMoreData; } static int IterGetTotalSize (Iter it) { register int size, i; XimFrameType type; if (it->allow_expansion) return NO_VALUE; /*endif*/ if (it->max_count == 0) return 0; /*endif*/ size = 0; type = it->template->type; switch (type) { case BIT8: size = it->max_count; break; case BIT16: size = it->max_count*2; break; case BIT32: size = it->max_count*4; break; case BIT64: size = it->max_count*8; break; case BARRAY: for (i = 0; i < it->max_count; i++) { register int num; ExtraData d; if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) return NO_VALUE; /*endif*/ if ((num = d->num) == NO_VALUE) return NO_VALUE; /*endif*/ size += num; } /*endfor*/ break; case ITER: for (i = 0; i < it->max_count; i++) { register int num; ExtraData d; if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) return NO_VALUE; /*endif*/ if ((num = IterGetTotalSize (d->iter)) == NO_VALUE) return NO_VALUE; /*endif*/ size += num; } /*endfor*/ break; case POINTER: for (i = 0; i < it->max_count; i++) { register int num; ExtraData d; ExtraDataRec dr; if ((d = ChainMgrGetExtraData (&it->cm, i)) == NULL) { dr.fi = FrameInstInit (it->template[1].data); d = ChainMgrSetData (&it->cm, i, dr); } /*endif*/ if ((num = FrameInstGetTotalSize (d->fi)) == NO_VALUE) return NO_VALUE; /*endif*/ size += num; } /*endfor*/ break; default: break; } /*endswitch*/ return size; } static void IterReset (Iter it) { ChainIterRec ci; int count; ExtraDataRec d; switch (it->template->type) { case ITER: ChainIterInit (&ci, &it->cm); while (ChainIterGetNext (&ci, &count, &d)) IterReset (d.iter); /*endwhile*/ ChainIterFree (&ci); break; case POINTER: ChainIterInit (&ci, &it->cm); while (ChainIterGetNext (&ci, &count, &d)) FrameInstReset (d.fi); /*endwhile*/ ChainIterFree (&ci); break; default: break; } /*endswitch*/ it->cur_no = 0; } static void IterSetStartWatch (Iter it, IterStartWatchProc proc, void *client_data) { it->start_watch_proc = proc; it->client_data = client_data; } static ExtraData ChainMgrSetData (ChainMgr cm, int frame_no, ExtraDataRec data) { Chain cur = (Chain) Xmalloc (sizeof (ChainRec)); cur->frame_no = frame_no; cur->d = data; cur->next = NULL; if (cm->top == NULL) { cm->top = cm->tail = cur; } else { cm->tail->next = cur; cm->tail = cur; } /*endif*/ return &cur->d; } static ExtraData ChainMgrGetExtraData (ChainMgr cm, int frame_no) { Chain cur; cur = cm->top; while (cur) { if (cur->frame_no == frame_no) return &cur->d; /*endif*/ cur = cur->next; } /*endwhile*/ return NULL; } static Bool ChainIterGetNext (ChainIter ci, int *frame_no, ExtraData d) { if (ci->cur == NULL) return False; /*endif*/ *frame_no = ci->cur->frame_no; *d = ci->cur->d; ci->cur = ci->cur->next; return True; } static int _FrameInstIncrement (XimFrame frame, int count) { XimFrameType type; type = frame[count].type; type &= ~COUNTER_MASK; switch (type) { case BIT8: case BIT16: case BIT32: case BIT64: case BARRAY: case PADDING: return count + 1; case POINTER: return count + 2; case ITER: return _FrameInstIncrement (frame, count + 1); default: break; } /*endswitch*/ return - 1; /* Error */ } static int _FrameInstDecrement (XimFrame frame, int count) { register int i; XimFrameType type; if (count == 0) return - 1; /* cannot decrement */ /*endif*/ if (count == 1) return 0; /* BOGUS - It should check the contents of data */ /*endif*/ type = frame[count - 2].type; type &= ~COUNTER_MASK; switch (type) { case BIT8: case BIT16: case BIT32: case BIT64: case BARRAY: case PADDING: case PTR_ITEM: return count - 1; case POINTER: case ITER: i = count - 3; while (i >= 0) { if (frame[i].type != ITER) return i + 1; /*endif*/ i--; } /*endwhile*/ return 0; default: break; } /*enswitch*/ return - 1; /* Error */ } static int _FrameInstGetItemSize (FrameInst fi, int cur_no) { XimFrameType type; type = fi->template[cur_no].type; type &= ~COUNTER_MASK; switch (type) { case BIT8: return 1; case BIT16: return 2; case BIT32: return 4; case BIT64: return 8; case BARRAY: { ExtraData d; if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL) return NO_VALUE; /*endif*/ if (d->num == NO_VALUE) return NO_VALUE; /*endif*/ return d->num; } case PADDING: { register int unit; register int number; register int size; register int i; unit = _UNIT ((long) fi->template[cur_no].data); number = _NUMBER ((long) fi->template[cur_no].data); i = cur_no; size = 0; while (number > 0) { i = _FrameInstDecrement (fi->template, i); size += _FrameInstGetItemSize (fi, i); number--; } /*endwhile*/ size = (unit - (size%unit))%unit; return size; } case ITER: { ExtraData d; int sub_size; if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL) return NO_VALUE; /*endif*/ sub_size = IterGetTotalSize (d->iter); if (sub_size == NO_VALUE) return NO_VALUE; /*endif*/ return sub_size; } case POINTER: { ExtraData d; int sub_size; if ((d = ChainMgrGetExtraData (&fi->cm, cur_no)) == NULL) return NO_VALUE; /*endif*/ sub_size = FrameInstGetTotalSize (d->fi); if (sub_size == NO_VALUE) return NO_VALUE; /*endif*/ return sub_size; } default: break; } /*endswitch*/ return NO_VALUE; } xsunpinyin-2.0.3/IMdkit/FrameMgr.h0000644000076400007640000001072711527365010015445 0ustar mikemike/****************************************************************** Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts, All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Digital or MIT not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hiroyuki Miyamoto Digital Equipment Corporation miyamoto@jrd.dec.com This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #ifndef FRAMEMGR_H #define FRAMEMGR_H #include #include #include #if defined(VAXC) && !defined(__DECC) #define xim_externalref globalref #define xim_externaldef globaldef #else #define xim_externalref extern #define xim_externaldef #endif /* Definitions for FrameMgr */ #define COUNTER_MASK 0x10 typedef enum { BIT8 = 0x1, /* {CARD8* | INT8*} */ BIT16 = 0x2, /* {CARD16* | INT16*} */ BIT32 = 0x3, /* {CARD32* | INT32*} */ BIT64 = 0x4, /* {CARD64* | INT64*} */ BARRAY = 0x5, /* int*, void* */ ITER = 0x6, /* int* */ POINTER = 0x7, /* specifies next item is a PTR_ITEM */ PTR_ITEM = 0x8, /* specifies the item has a pointer */ /* BOGUS - POINTER and PTR_ITEM * In the current implementation, PTR_ITEM should be lead by * POINTER. But actually, it's just redundant logically. Someone * may remove this redundancy and POINTER from the enum member but he * should also modify the logic in FrameMgr program. */ PADDING = 0x9, /* specifies that a padding is needed. * This requires extra data in data field. */ EOL = 0xA, /* specifies the end of list */ COUNTER_BIT8 = COUNTER_MASK | 0x1, COUNTER_BIT16 = COUNTER_MASK | 0x2, COUNTER_BIT32 = COUNTER_MASK | 0x3, COUNTER_BIT64 = COUNTER_MASK | 0x4 } XimFrameType; /* Convenient macro */ #define _FRAME(a) {a, NULL} #define _PTR(p) {PTR_ITEM, (void *)p} /* PADDING's usage of data field * B15-B8 : Shows the number of effective items. * B7-B0 : Shows padding unit. ex) 04 shows 4 unit padding. */ #define _PAD2(n) {PADDING, (void*)((n)<<8|2)} #define _PAD4(n) {PADDING, (void*)((n)<<8|4)} #define FmCounterByte 0 #define FmCounterNumber 1 #define _BYTE_COUNTER(type, offset) \ {(COUNTER_MASK|type), (void*)((offset)<<8|FmCounterByte)} #define _NUMBER_COUNTER(type, offset) \ {(COUNTER_MASK|type), (void*)((offset)<<8|FmCounterNumber)} typedef struct _XimFrame { XimFrameType type; void* data; /* For PTR_ITEM and PADDING */ } XimFrameRec, *XimFrame; typedef enum { FmSuccess, FmEOD, FmInvalidCall, FmBufExist, FmCannotCalc, FmNoMoreData } FmStatus; typedef struct _FrameMgr *FrameMgr; FrameMgr FrameMgrInit(XimFrame frame, char* area, Bool byte_swap); void FrameMgrInitWithData(FrameMgr fm, XimFrame frame, void* area, Bool byte_swap); void FrameMgrFree(FrameMgr fm); FmStatus FrameMgrSetBuffer(FrameMgr, void*); FmStatus _FrameMgrPutToken(FrameMgr, void*, int); FmStatus _FrameMgrGetToken(FrameMgr, void*, int); FmStatus FrameMgrSetSize(FrameMgr, int); FmStatus FrameMgrSetIterCount(FrameMgr, int); FmStatus FrameMgrSetTotalSize(FrameMgr, int); int FrameMgrGetTotalSize(FrameMgr); int FrameMgrGetSize(FrameMgr); FmStatus FrameMgrSkipToken(FrameMgr, int); void FrameMgrReset(FrameMgr); Bool FrameMgrIsIterLoopEnd(FrameMgr, FmStatus*); #define FrameMgrPutToken(fm, obj) _FrameMgrPutToken((fm), &(obj), sizeof(obj)) #define FrameMgrGetToken(fm, obj) _FrameMgrGetToken((fm), &(obj), sizeof(obj)) #endif /* FRAMEMGR_H */ xsunpinyin-2.0.3/IMdkit/i18nX.c0000644000076400007640000004226611527365010014652 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include #include #include "FrameMgr.h" #include "IMdkit.h" #include "Xi18n.h" #include "Xi18nX.h" #include "XimFunc.h" extern Xi18nClient *_Xi18nFindClient(Xi18n, CARD16); extern Xi18nClient *_Xi18nNewClient(Xi18n); extern void _Xi18nDeleteClient(Xi18n, CARD16); static Bool WaitXConnectMessage(Display*, Window, XEvent*, XPointer); static Bool WaitXIMProtocol(Display*, Window, XEvent*, XPointer); static XClient *NewXClient (Xi18n i18n_core, Window new_client) { Display *dpy = i18n_core->address.dpy; Xi18nClient *client = _Xi18nNewClient (i18n_core); XClient *x_client; x_client = (XClient *) malloc (sizeof (XClient)); x_client->client_win = new_client; x_client->accept_win = XCreateSimpleWindow (dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 1, 0, 0); client->trans_rec = x_client; return ((XClient *) x_client); } static unsigned char *ReadXIMMessage (XIMS ims, XClientMessageEvent *ev, int *connect_id) { Xi18n i18n_core = ims->protocol; Xi18nClient *client = i18n_core->address.clients; XClient *x_client = NULL; FrameMgr fm; extern XimFrameRec packet_header_fr[]; unsigned char *p = NULL; unsigned char *p1; while (client != NULL) { x_client = (XClient *) client->trans_rec; if (x_client->accept_win == ev->window) { *connect_id = client->connect_id; break; } client = client->next; } if (ev->format == 8) { /* ClientMessage only */ XimProtoHdr *hdr = (XimProtoHdr *) ev->data.b; unsigned char *rec = (unsigned char *) (hdr + 1); register int total_size; CARD8 major_opcode; CARD8 minor_opcode; CARD16 length; extern int _Xi18nNeedSwap (Xi18n, CARD16); if (client->byte_order == '?') { if (hdr->major_opcode != XIM_CONNECT) return (unsigned char *) NULL; /* can do nothing */ client->byte_order = (CARD8) rec[0]; } fm = FrameMgrInit (packet_header_fr, (char *) hdr, _Xi18nNeedSwap (i18n_core, *connect_id)); total_size = FrameMgrGetTotalSize (fm); /* get data */ FrameMgrGetToken (fm, major_opcode); FrameMgrGetToken (fm, minor_opcode); FrameMgrGetToken (fm, length); FrameMgrFree (fm); if ((p = (unsigned char *) malloc (total_size + length * 4)) == NULL) return (unsigned char *) NULL; p1 = p; memmove (p1, &major_opcode, sizeof (CARD8)); p1 += sizeof (CARD8); memmove (p1, &minor_opcode, sizeof (CARD8)); p1 += sizeof (CARD8); memmove (p1, &length, sizeof (CARD16)); p1 += sizeof (CARD16); memmove (p1, rec, length * 4); } else if (ev->format == 32) { /* ClientMessage and WindowProperty */ unsigned long length = (unsigned long) ev->data.l[0]; unsigned long get_length; Atom atom = (Atom) ev->data.l[1]; int return_code; Atom actual_type_ret; int actual_format_ret; unsigned long bytes_after_ret; unsigned char *prop; unsigned long nitems; /* Round up length to next 4 byte value. */ get_length = length + 3; if (get_length > LONG_MAX) get_length = LONG_MAX; get_length /= 4; if (get_length == 0) { fprintf(stderr, "%s: invalid length 0\n", __func__); return NULL; } return_code = XGetWindowProperty (i18n_core->address.dpy, x_client->accept_win, atom, client->property_offset / 4, get_length, True, AnyPropertyType, &actual_type_ret, &actual_format_ret, &nitems, &bytes_after_ret, &prop); if (return_code != Success || actual_format_ret == 0 || nitems == 0) { if (return_code == Success) XFree (prop); client->property_offset = 0; return (unsigned char *) NULL; } /* Update the offset to read next time as needed */ if (bytes_after_ret > 0) client->property_offset += length; else client->property_offset = 0; switch (actual_format_ret) { case 8: case 16: case 32: length = nitems * actual_format_ret / 8; break; default: fprintf(stderr, "%s: unknown property return format: %d\n", __func__, actual_format_ret); XFree(prop); client->property_offset = 0; return NULL; } /* if hit, it might be an error */ if ((p = (unsigned char *) malloc (length)) == NULL) return (unsigned char *) NULL; memmove (p, prop, length); XFree (prop); } return (unsigned char *) p; } static void ReadXConnectMessage (XIMS ims, XClientMessageEvent *ev) { Xi18n i18n_core = ims->protocol; XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr; XEvent event; Display *dpy = i18n_core->address.dpy; Window new_client = ev->data.l[0]; CARD32 major_version = ev->data.l[1]; CARD32 minor_version = ev->data.l[2]; XClient *x_client = NewXClient (i18n_core, new_client); if (ev->window != i18n_core->address.im_window) return; /* incorrect connection request */ /*endif*/ if (major_version != 0 || minor_version != 0) { major_version = minor_version = 0; /* Only supporting only-CM & Property-with-CM method */ } /*endif*/ _XRegisterFilterByType (dpy, x_client->accept_win, ClientMessage, ClientMessage, WaitXIMProtocol, (XPointer)ims); event.xclient.type = ClientMessage; event.xclient.display = dpy; event.xclient.window = new_client; event.xclient.message_type = spec->connect_request; event.xclient.format = 32; event.xclient.data.l[0] = x_client->accept_win; event.xclient.data.l[1] = major_version; event.xclient.data.l[2] = minor_version; event.xclient.data.l[3] = XCM_DATA_LIMIT; XSendEvent (dpy, new_client, False, NoEventMask, &event); XFlush (dpy); } static Bool Xi18nXBegin (XIMS ims) { Xi18n i18n_core = ims->protocol; Display *dpy = i18n_core->address.dpy; XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr; spec->xim_request = XInternAtom (i18n_core->address.dpy, _XIM_PROTOCOL, False); spec->connect_request = XInternAtom (i18n_core->address.dpy, _XIM_XCONNECT, False); _XRegisterFilterByType (dpy, i18n_core->address.im_window, ClientMessage, ClientMessage, WaitXConnectMessage, (XPointer)ims); return True; } static Bool Xi18nXEnd(XIMS ims) { Xi18n i18n_core = ims->protocol; Display *dpy = i18n_core->address.dpy; _XUnregisterFilter (dpy, i18n_core->address.im_window, WaitXConnectMessage, (XPointer)ims); return True; } static char *MakeNewAtom (CARD16 connect_id, char *atomName) { static int sequence = 0; sprintf (atomName, "_server%d_%d", connect_id, ((sequence > 20) ? (sequence = 0) : sequence++)); return atomName; } static Bool Xi18nXSend (XIMS ims, CARD16 connect_id, unsigned char *reply, long length) { Xi18n i18n_core = ims->protocol; Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id); XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr; XClient *x_client = (XClient *) client->trans_rec; XEvent event; event.type = ClientMessage; event.xclient.window = x_client->client_win; event.xclient.message_type = spec->xim_request; if (length > XCM_DATA_LIMIT) { Atom atom; char atomName[16]; Atom actual_type_ret; int actual_format_ret; int return_code; unsigned long nitems_ret; unsigned long bytes_after_ret; unsigned char *win_data; event.xclient.format = 32; atom = XInternAtom (i18n_core->address.dpy, MakeNewAtom (connect_id, atomName), False); return_code = XGetWindowProperty (i18n_core->address.dpy, x_client->client_win, atom, 0L, 10000L, False, XA_STRING, &actual_type_ret, &actual_format_ret, &nitems_ret, &bytes_after_ret, &win_data); if (return_code != Success) return False; /*endif*/ if (win_data) XFree ((char *) win_data); /*endif*/ XChangeProperty (i18n_core->address.dpy, x_client->client_win, atom, XA_STRING, 8, PropModeAppend, (unsigned char *) reply, length); event.xclient.data.l[0] = length; event.xclient.data.l[1] = atom; } else { unsigned char buffer[XCM_DATA_LIMIT]; int i; event.xclient.format = 8; /* Clear unused field with NULL */ memmove(buffer, reply, length); for (i = length; i < XCM_DATA_LIMIT; i++) buffer[i] = (char) 0; /*endfor*/ length = XCM_DATA_LIMIT; memmove (event.xclient.data.b, buffer, length); } XSendEvent (i18n_core->address.dpy, x_client->client_win, False, NoEventMask, &event); XFlush (i18n_core->address.dpy); return True; } static Bool CheckCMEvent (Display *display, XEvent *event, XPointer xi18n_core) { Xi18n i18n_core = (Xi18n) ((void *) xi18n_core); XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr; if ((event->type == ClientMessage) && (event->xclient.message_type == spec->xim_request)) { return True; } /*endif*/ return False; } static Bool Xi18nXWait (XIMS ims, CARD16 connect_id, CARD8 major_opcode, CARD8 minor_opcode) { Xi18n i18n_core = ims->protocol; XEvent event; Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id); XClient *x_client = (XClient *) client->trans_rec; for (;;) { unsigned char *packet; XimProtoHdr *hdr; int connect_id_ret; XIfEvent (i18n_core->address.dpy, &event, CheckCMEvent, (XPointer) i18n_core); if (event.xclient.window == x_client->accept_win) { if ((packet = ReadXIMMessage (ims, (XClientMessageEvent *) & event, &connect_id_ret)) == (unsigned char*) NULL) { return False; } /*endif*/ hdr = (XimProtoHdr *)packet; if ((hdr->major_opcode == major_opcode) && (hdr->minor_opcode == minor_opcode)) { return True; } else if (hdr->major_opcode == XIM_ERROR) { return False; } /*endif*/ } /*endif*/ } /*endfor*/ } static Bool Xi18nXDisconnect (XIMS ims, CARD16 connect_id) { Xi18n i18n_core = ims->protocol; Display *dpy = i18n_core->address.dpy; Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id); XClient *x_client = (XClient *) client->trans_rec; XDestroyWindow (dpy, x_client->accept_win); _XUnregisterFilter (dpy, x_client->accept_win, WaitXIMProtocol, (XPointer)ims); XFree (x_client); _Xi18nDeleteClient (i18n_core, connect_id); return True; } Bool _Xi18nCheckXAddress (Xi18n i18n_core, TransportSW *transSW, char *address) { XSpecRec *spec; if (!(spec = (XSpecRec *) malloc (sizeof (XSpecRec)))) return False; /*endif*/ i18n_core->address.connect_addr = (XSpecRec *) spec; i18n_core->methods.begin = Xi18nXBegin; i18n_core->methods.end = Xi18nXEnd; i18n_core->methods.send = Xi18nXSend; i18n_core->methods.wait = Xi18nXWait; i18n_core->methods.disconnect = Xi18nXDisconnect; return True; } static Bool WaitXConnectMessage (Display *dpy, Window win, XEvent *ev, XPointer client_data) { XIMS ims = (XIMS)client_data; Xi18n i18n_core = ims->protocol; XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr; if (((XClientMessageEvent *) ev)->message_type == spec->connect_request) { ReadXConnectMessage (ims, (XClientMessageEvent *) ev); return True; } /*endif*/ return False; } static Bool WaitXIMProtocol (Display *dpy, Window win, XEvent *ev, XPointer client_data) { extern void _Xi18nMessageHandler (XIMS, CARD16, unsigned char *, Bool *); XIMS ims = (XIMS) client_data; Xi18n i18n_core = ims->protocol; XSpecRec *spec = (XSpecRec *) i18n_core->address.connect_addr; Bool delete = True; unsigned char *packet; int connect_id; if (((XClientMessageEvent *) ev)->message_type == spec->xim_request) { if ((packet = ReadXIMMessage (ims, (XClientMessageEvent *) ev, &connect_id)) == (unsigned char *) NULL) { return False; } /*endif*/ _Xi18nMessageHandler (ims, connect_id, packet, &delete); if (delete == True) XFree (packet); /*endif*/ return True; } /*endif*/ return False; } xsunpinyin-2.0.3/IMdkit/Xi18nX.h0000644000076400007640000000365411527365010015005 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #ifndef _Xi18nTrX_h #define _Xi18nTrX_h #define _XIM_PROTOCOL "_XIM_PROTOCOL" #define _XIM_XCONNECT "_XIM_XCONNECT" #define XCM_DATA_LIMIT 20 typedef struct _XClient { Window client_win; /* client window */ Window accept_win; /* accept window */ } XClient; typedef struct { Atom xim_request; Atom connect_request; } XSpecRec; #endif xsunpinyin-2.0.3/IMdkit/IMValues.c0000644000076400007640000000644511527365010015427 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include #include "IMdkit.h" #include #define Va_start(a,b) va_start(a,b) static void _IMCountVaList (va_list var, int *total_count) { char *attr; *total_count = 0; for (attr = va_arg (var, char *); attr; attr = va_arg (var, char *)) { (void)va_arg (var, XIMArg *); ++(*total_count); } /*endfor*/ } static void _IMVaToNestedList (va_list var, int max_count, XIMArg **args_return) { XIMArg *args; char *attr; if (max_count <= 0) { *args_return = (XIMArg *) NULL; return; } /*endif*/ args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg)); *args_return = args; if (!args) return; /*endif*/ for (attr = va_arg (var, char *); attr; attr = va_arg (var, char *)) { args->name = attr; args->value = va_arg (var, XPointer); args++; } /*endfor*/ args->name = (char *) NULL; } char *IMGetIMValues (XIMS ims, ...) { va_list var; int total_count; XIMArg *args; char *ret; Va_start (var, ims); _IMCountVaList (var, &total_count); va_end (var); Va_start (var, ims); _IMVaToNestedList (var, total_count, &args); va_end (var); ret = (*ims->methods->getIMValues) (ims, args); if (args) XFree ((char *) args); /*endif*/ return ret; } char *IMSetIMValues (XIMS ims, ...) { va_list var; int total_count; XIMArg *args; char *ret; Va_start (var, ims); _IMCountVaList (var, &total_count); va_end (var); Va_start (var, ims); _IMVaToNestedList (var, total_count, &args); va_end (var); ret = (*ims->methods->setIMValues) (ims, args); if (args) XFree ((char *) args); /*endif*/ return ret; } xsunpinyin-2.0.3/IMdkit/IMConn.c0000644000076400007640000001020211527365010015047 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include #include #include "IMdkit.h" #include #define Va_start(a,b) va_start(a,b) static void _IMCountVaList(va_list var, int *total_count) { char *attr; *total_count = 0; for (attr = va_arg (var, char*); attr; attr = va_arg (var, char*)) { (void)va_arg (var, XIMArg *); ++(*total_count); } /*endfor*/ } static void _IMVaToNestedList(va_list var, int max_count, XIMArg **args_return) { XIMArg *args; char *attr; if (max_count <= 0) { *args_return = (XIMArg *) NULL; return; } /*endif*/ args = (XIMArg *) malloc ((unsigned) (max_count + 1)*sizeof (XIMArg)); *args_return = args; if (!args) return; /*endif*/ for (attr = va_arg (var, char*); attr; attr = va_arg (var, char *)) { args->name = attr; args->value = va_arg (var, XPointer); args++; } /*endfor*/ args->name = (char*)NULL; } static char *_FindModifiers (XIMArg *args) { char *modifiers; while (args->name) { if (strcmp (args->name, IMModifiers) == 0) { modifiers = args->value; return modifiers; } else { args++; } /*endif*/ } /*endwhile*/ return NULL; } XIMS _GetIMS (char *modifiers) { XIMS ims; extern IMMethodsRec Xi18n_im_methods; if ((ims = (XIMS) malloc (sizeof (XIMProtocolRec))) == (XIMS) NULL) return ((XIMS) NULL); /*endif*/ memset ((void *) ims, 0, sizeof (XIMProtocolRec)); if (modifiers == NULL || modifiers[0] == '\0' || strcmp (modifiers, "Xi18n") == 0) { ims->methods = &Xi18n_im_methods; return ims; } /*endif*/ XFree (ims); return (XIMS) NULL; } XIMS IMOpenIM (Display *display, ...) { va_list var; int total_count; XIMArg *args; XIMS ims; char *modifiers; Status ret; Va_start (var, display); _IMCountVaList (var, &total_count); va_end (var); Va_start (var, display); _IMVaToNestedList (var, total_count, &args); va_end (var); modifiers = _FindModifiers (args); ims = _GetIMS (modifiers); if (ims == (XIMS) NULL) return (XIMS) NULL; /*endif*/ ims->core.display = display; ims->protocol = (*ims->methods->setup) (display, args); XFree (args); if (ims->protocol == (void *) NULL) { XFree (ims); return (XIMS) NULL; } /*endif*/ ret = (ims->methods->openIM) (ims); if (ret == False) { XFree (ims); return (XIMS) NULL; } /*endif*/ return (XIMS) ims; } Status IMCloseIM (XIMS ims) { (ims->methods->closeIM) (ims); XFree (ims); return True; } xsunpinyin-2.0.3/IMdkit/Xi18n.h0000644000076400007640000002547611527365010014663 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #ifndef _Xi18n_h #define _Xi18n_h #include #include #include #include "XimProto.h" /* * Minor Protocol Number for Extension Protocol */ #define XIM_EXTENSION 128 #define XIM_EXT_SET_EVENT_MASK (0x30) #define XIM_EXT_FORWARD_KEYEVENT (0x32) #define XIM_EXT_MOVE (0x33) #define COMMON_EXTENSIONS_NUM 3 #include #include "IMdkit.h" /* XI18N Valid Attribute Name Definition */ #define ExtForwardKeyEvent "extForwardKeyEvent" #define ExtMove "extMove" #define ExtSetEventMask "extSetEventMask" /* * Padding macro */ #define IMPAD(length) ((4 - ((length)%4))%4) /* * Target Atom for Transport Connection */ #define LOCALES "LOCALES" #define TRANSPORT "TRANSPORT" #define I18N_OPEN 0 #define I18N_SET 1 #define I18N_GET 2 typedef struct { char *transportname; int namelen; Bool (*checkAddr) (); } TransportSW; typedef struct _XIMPending { unsigned char *p; struct _XIMPending *next; } XIMPending; typedef struct _XimProtoHdr { CARD8 major_opcode; CARD8 minor_opcode; CARD16 length; } XimProtoHdr; typedef struct { CARD16 attribute_id; CARD16 type; CARD16 length; char *name; } XIMAttr; typedef struct { CARD16 attribute_id; CARD16 type; CARD16 length; char *name; } XICAttr; typedef struct { int attribute_id; CARD16 name_length; char *name; int value_length; void *value; int type; } XIMAttribute; typedef struct { int attribute_id; CARD16 name_length; char *name; int value_length; void *value; int type; } XICAttribute; typedef struct { int length; char *name; } XIMStr; typedef struct { CARD16 major_opcode; CARD16 minor_opcode; CARD16 length; char *name; } XIMExt; typedef struct _Xi18nClient { int connect_id; CARD8 byte_order; /* '?': initial value 'B': for Big-Endian 'l': for little-endian */ int sync; XIMPending *pending; /* property offset to read next data */ long property_offset; void *trans_rec; /* contains transport specific data */ struct _Xi18nClient *next; } Xi18nClient; typedef struct _Xi18nCore *Xi18n; /* * Callback Struct for XIM Protocol */ typedef struct { int major_code; int minor_code; CARD16 connect_id; } IMAnyStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD8 byte_order; CARD16 major_version; CARD16 minor_version; } IMConnectStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; } IMDisConnectStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; XIMStr lang; } IMOpenStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; } IMCloseStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 number; XIMStr *extension; } IMQueryExtensionStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 number; char **im_attr_list; } IMGetIMValuesStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; CARD16 preedit_attr_num; CARD16 status_attr_num; CARD16 ic_attr_num; XICAttribute *preedit_attr; XICAttribute *status_attr; XICAttribute *ic_attr; } IMChangeICStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; } IMDestroyICStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; CARD16 length; char *commit_string; } IMResetICStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; } IMChangeFocusStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; BITMASK16 sync_bit; CARD16 serial_number; XEvent event; } IMForwardEventStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; CARD16 flag; KeySym keysym; char *commit_string; } IMCommitStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; CARD32 flag; CARD32 key_index; CARD32 event_mask; } IMTriggerNotifyStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 encoding_number; XIMStr *encoding; /* name information */ CARD16 encoding_info_number; XIMStr *encodinginfo; /* detailed information */ CARD16 category; /* #0 for name, #1 for detail */ INT16 enc_index; /* index of the encoding determined */ } IMEncodingNegotiationStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; CARD32 flag; CARD32 forward_event_mask; CARD32 sync_event_mask; } IMSetEventMaskStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; CARD32 filter_event_mask; CARD32 intercept_event_mask; CARD32 select_event_mask; CARD32 forward_event_mask; CARD32 sync_event_mask; } IMExtSetEventMaskStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; CARD16 x; CARD16 y; } IMMoveStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; BITMASK16 flag; CARD16 error_code; CARD16 str_length; CARD16 error_type; char *error_detail; } IMErrorStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; } IMPreeditStateStruct; /* Callbacks */ typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; } IMGeometryCBStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; union { int return_value; /* PreeditStart */ XIMPreeditDrawCallbackStruct draw; /* PreeditDraw */ XIMPreeditCaretCallbackStruct caret; /* PreeditCaret */ } todo; } IMPreeditCBStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; union { XIMStatusDrawCallbackStruct draw; /* StatusDraw */ } todo; } IMStatusCBStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; XIMStringConversionCallbackStruct strconv; } IMStrConvCBStruct; typedef struct { int major_code; int minor_code; CARD16 connect_id; CARD16 icid; } IMSyncXlibStruct; typedef union _IMProtocol { int major_code; IMAnyStruct any; IMConnectStruct imconnect; IMDisConnectStruct imdisconnect; IMOpenStruct imopen; IMCloseStruct imclose; IMQueryExtensionStruct queryext; IMGetIMValuesStruct getim; IMEncodingNegotiationStruct encodingnego; IMExtSetEventMaskStruct extsetevent; IMMoveStruct extmove; IMSetEventMaskStruct setevent; IMChangeICStruct changeic; IMDestroyICStruct destroyic; IMResetICStruct resetic; IMChangeFocusStruct changefocus; IMCommitStruct commitstring; IMForwardEventStruct forwardevent; IMTriggerNotifyStruct triggernotify; IMPreeditStateStruct preedit_state; IMErrorStruct imerror; IMGeometryCBStruct geometry_callback; IMPreeditCBStruct preedit_callback; IMStatusCBStruct status_callback; IMStrConvCBStruct strconv_callback; IMSyncXlibStruct sync_xlib; long pad[32]; } IMProtocol; typedef int (*IMProtoHandler) (XIMS, IMProtocol*); #define DEFAULT_FILTER_MASK (KeyPressMask) /* Xi18nAddressRec structure */ typedef struct _Xi18nAddressRec { Display *dpy; CARD8 im_byteOrder; /* byte order 'B' or 'l' */ /* IM Values */ long imvalue_mask; Window im_window; /* IMServerWindow */ char *im_name; /* IMServerName */ char *im_locale; /* IMLocale */ char *im_addr; /* IMServerTransport */ XIMStyles input_styles; /* IMInputStyles */ XIMTriggerKeys on_keys; /* IMOnKeysList */ XIMTriggerKeys off_keys; /* IMOffKeysList */ XIMEncodings encoding_list; /* IMEncodingList */ IMProtoHandler improto; /* IMProtocolHander */ long filterevent_mask; /* IMFilterEventMask */ /* XIM_SERVERS target Atoms */ Atom selection; Atom Localename; Atom Transportname; /* XIM/XIC Attr */ int im_attr_num; XIMAttr *xim_attr; int ic_attr_num; XICAttr *xic_attr; CARD16 preeditAttr_id; CARD16 statusAttr_id; CARD16 separatorAttr_id; /* XIMExtension List */ int ext_num; XIMExt extension[COMMON_EXTENSIONS_NUM]; /* transport specific connection address */ void *connect_addr; /* actual data is defined: XSpecRec in Xi18nX.h for X-based connection. TransSpecRec in Xi18nTr.h for Socket-based connection. */ /* clients table */ Xi18nClient *clients; Xi18nClient *free_clients; } Xi18nAddressRec; typedef struct _Xi18nMethodsRec { Bool (*begin) (XIMS); Bool (*end) (XIMS); Bool (*send) (XIMS, CARD16, unsigned char*, long); Bool (*wait) (XIMS, CARD16, CARD8, CARD8); Bool (*disconnect) (XIMS, CARD16); } Xi18nMethodsRec; typedef struct _Xi18nCore { Xi18nAddressRec address; Xi18nMethodsRec methods; } Xi18nCore; #endif xsunpinyin-2.0.3/IMdkit/i18nIc.c0000644000076400007640000010162011527365010014764 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include "IMdkit.h" #include "Xi18n.h" #include "FrameMgr.h" #include "XimFunc.h" #define IC_SIZE 64 /* Set IC values */ static void SetCardAttribute (XICAttribute *value_ret, char *p, XICAttr *ic_attr, int value_length, int need_swap, void **value_buf) { FrameMgr fm; /*endif*/ if (value_length == sizeof (CARD8)) { memmove (*value_buf, p, value_length); } else if (value_length == sizeof (CARD16)) { INT16 value; extern XimFrameRec short_fr[]; fm = FrameMgrInit (short_fr, (char *) p, need_swap); /* get data */ FrameMgrGetToken (fm, value); FrameMgrFree (fm); memmove (*value_buf, &value, value_length); } else if (value_length == sizeof(CARD32)) { INT32 value; extern XimFrameRec long_fr[]; fm = FrameMgrInit (long_fr, (char *) p, need_swap); /* get data */ FrameMgrGetToken (fm, value); FrameMgrFree (fm); memmove (*value_buf, &value, value_length); } /*endif*/ value_ret->attribute_id = ic_attr->attribute_id; value_ret->name = ic_attr->name; value_ret->name_length = ic_attr->length; value_ret->type = ic_attr->type; value_ret->value_length = value_length; value_ret->value = *value_buf; *value_buf += value_length; } static void SetFontAttribute (XICAttribute *value_ret, char *p, XICAttr *ic_attr, int value_length, int need_swap, void **value_buf) { char *base_name; CARD16 base_length; FrameMgr fm; extern XimFrameRec fontset_fr[]; fm = FrameMgrInit (fontset_fr, (char *) p, need_swap); /* get data */ FrameMgrGetToken (fm, base_length); FrameMgrSetSize (fm, base_length); /*endif*/ FrameMgrGetToken (fm, base_name); FrameMgrFree(fm); strncpy ((char *) (*value_buf), base_name, base_length); ((char *) *value_buf)[base_length] = (char) 0; value_ret->attribute_id = ic_attr->attribute_id; value_ret->name = ic_attr->name; value_ret->name_length = ic_attr->length; value_ret->type = ic_attr->type; value_ret->value_length = value_length; value_ret->value = *value_buf; *value_buf += (base_length + 1); } static void SetPointAttribute (XICAttribute *value_ret, char *p, XICAttr *ic_attr, int value_length, int need_swap, void **value_buf) { XPoint *buf; FrameMgr fm; extern XimFrameRec xpoint_fr[]; buf = (XPoint *) (*value_buf); fm = FrameMgrInit (xpoint_fr, (char *) p, need_swap); /* get data */ FrameMgrGetToken (fm, buf->x); FrameMgrGetToken (fm, buf->y); FrameMgrFree (fm); value_ret->attribute_id = ic_attr->attribute_id; value_ret->name = ic_attr->name; value_ret->name_length = ic_attr->length; value_ret->type = ic_attr->type; value_ret->value_length = value_length; value_ret->value = (char *) buf; *value_buf += value_length; } static void SetRectAttribute (XICAttribute *value_ret, char *p, XICAttr *ic_attr, int value_length, int need_swap, void **value_buf) { XRectangle *buf; FrameMgr fm; extern XimFrameRec xrectangle_fr[]; buf = (XRectangle *) (*value_buf); fm = FrameMgrInit (xrectangle_fr, (char *) p, need_swap); /* get data */ FrameMgrGetToken (fm, buf->x); FrameMgrGetToken (fm, buf->y); FrameMgrGetToken (fm, buf->width); FrameMgrGetToken (fm, buf->height); FrameMgrFree (fm); value_ret->attribute_id = ic_attr->attribute_id; value_ret->name = ic_attr->name; value_ret->name_length = ic_attr->length; value_ret->type = ic_attr->type; value_ret->value_length = value_length; value_ret->value = (char *) buf; *value_buf += value_length; } #if 0 static void SetHotKeyAttribute (XICAttribute *value_ret, char *p, XICAttr *ic_attr, int value_length, int need_swap, void **value_buf) { INT32 list_number; XIMTriggerKey *hotkeys; memmove (&list_number, p, sizeof(INT32)); p += sizeof(INT32); hotkeys = (XIMTriggerKey *) (*value_buf); memmove (hotkeys, p, list_number*sizeof (XIMTriggerKey)); value_ret->attribute_id = ic_attr->attribute_id; value_ret->name = ic_attr->name; value_ret->name_length = ic_attr->length; value_ret->type = ic_attr->type; value_ret->value_length = value_length; value_ret->value = (char *) hotkeys; *value_buf += value_length; } #endif /* get IC values */ static void GetAttrHeader (unsigned char *rec, XICAttribute *list, int need_swap) { FrameMgr fm; extern XimFrameRec attr_head_fr[]; fm = FrameMgrInit (attr_head_fr, (char *) rec, need_swap); /* put data */ FrameMgrPutToken (fm, list->attribute_id); FrameMgrPutToken (fm, list->value_length); FrameMgrFree (fm); } static void GetCardAttribute (char *rec, XICAttribute *list, int need_swap) { FrameMgr fm; unsigned char *recp = (unsigned char *) rec; GetAttrHeader (recp, list, need_swap); recp += sizeof (CARD16)*2; if (list->value_length == sizeof (CARD8)) { memmove (recp, list->value, list->value_length); } else if (list->value_length == sizeof (CARD16)) { INT16 *value = (INT16 *) list->value; extern XimFrameRec short_fr[]; fm = FrameMgrInit (short_fr, (char *) recp, need_swap); /* put data */ FrameMgrPutToken (fm, *value); FrameMgrFree (fm); } else if (list->value_length == sizeof (CARD32)) { INT32 *value = (INT32 *) list->value; extern XimFrameRec long_fr[]; fm = FrameMgrInit (long_fr, (char *) recp, need_swap); /* put data */ FrameMgrPutToken (fm, *value); FrameMgrFree (fm); } /*endif*/ } static void GetFontAttribute(char *rec, XICAttribute *list, int need_swap) { FrameMgr fm; extern XimFrameRec fontset_fr[]; char *base_name = (char *) list->value; unsigned char *recp = (unsigned char *) rec; GetAttrHeader (recp, list, need_swap); recp += sizeof (CARD16)*2; fm = FrameMgrInit (fontset_fr, (char *)recp, need_swap); /* put data */ FrameMgrSetSize (fm, list->value_length); FrameMgrPutToken (fm, list->value_length); FrameMgrPutToken (fm, base_name); FrameMgrFree (fm); } static void GetRectAttribute (char *rec, XICAttribute *list, int need_swap) { FrameMgr fm; extern XimFrameRec xrectangle_fr[]; XRectangle *rect = (XRectangle *) list->value; unsigned char *recp = (unsigned char *) rec; GetAttrHeader (recp, list, need_swap); recp += sizeof(CARD16)*2; if (rect) { fm = FrameMgrInit (xrectangle_fr, (char *) recp, need_swap); /* put data */ FrameMgrPutToken (fm, rect->x); FrameMgrPutToken (fm, rect->y); FrameMgrPutToken (fm, rect->width); FrameMgrPutToken (fm, rect->height); FrameMgrFree (fm); } } static void GetPointAttribute (char *rec, XICAttribute *list, int need_swap) { FrameMgr fm; extern XimFrameRec xpoint_fr[]; XPoint *rect = (XPoint *) list->value; unsigned char *recp = (unsigned char *) rec; GetAttrHeader (recp, list, need_swap); recp += sizeof(CARD16)*2; fm = FrameMgrInit (xpoint_fr, (char *) recp, need_swap); /* put data */ FrameMgrPutToken (fm, rect->x); FrameMgrPutToken (fm, rect->y); FrameMgrFree (fm); } static int ReadICValue (Xi18n i18n_core, CARD16 icvalue_id, int value_length, void *p, XICAttribute *value_ret, CARD16 *number_ret, int need_swap, void **value_buf) { XICAttr *ic_attr = i18n_core->address.xic_attr; int i; *number_ret = (CARD16) 0; for (i = 0; i < i18n_core->address.ic_attr_num; i++, ic_attr++) { if (ic_attr->attribute_id == icvalue_id) break; /*endif*/ } /*endfor*/ switch (ic_attr->type) { case XimType_NEST: { int total_length = 0; CARD16 attribute_ID; INT16 attribute_length; unsigned char *p1 = (unsigned char *) p; CARD16 ic_len = 0; CARD16 number; FrameMgr fm; extern XimFrameRec attr_head_fr[]; while (total_length < value_length) { fm = FrameMgrInit (attr_head_fr, (char *) p1, need_swap); /* get data */ FrameMgrGetToken (fm, attribute_ID); FrameMgrGetToken (fm, attribute_length); FrameMgrFree (fm); p1 += sizeof (CARD16)*2; ReadICValue (i18n_core, attribute_ID, attribute_length, p1, (value_ret + ic_len), &number, need_swap, value_buf); ic_len++; *number_ret += number; p1 += attribute_length; p1 += IMPAD (attribute_length); total_length += (CARD16) sizeof(CARD16)*2 + (INT16) attribute_length + IMPAD (attribute_length); } /*endwhile*/ return ic_len; } case XimType_CARD8: case XimType_CARD16: case XimType_CARD32: case XimType_Window: SetCardAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf); *number_ret = (CARD16) 1; return *number_ret; case XimType_XFontSet: SetFontAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf); *number_ret = (CARD16) 1; return *number_ret; case XimType_XRectangle: SetRectAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf); *number_ret = (CARD16) 1; return *number_ret; case XimType_XPoint: SetPointAttribute(value_ret, p, ic_attr, value_length, need_swap, value_buf); *number_ret = (CARD16) 1; return *number_ret; #if 0 case XimType_XIMHotKeyTriggers: SetHotKeyAttribute (value_ret, p, ic_attr, value_length, need_swap, value_buf); *number_ret = (CARD16) 1; return *number_ret; #endif } /*endswitch*/ return 0; } static XICAttribute *CreateNestedList (CARD16 attr_id, XICAttribute *list, int number, int need_swap) { XICAttribute *nest_list = NULL; register int i; char *values = NULL; char *valuesp; int value_length = 0; if (number == 0) return NULL; /*endif*/ for (i = 0; i < number; i++) { value_length += sizeof (CARD16)*2; value_length += list[i].value_length; value_length += IMPAD (list[i].value_length); } /*endfor*/ if ((values = (char *) malloc (value_length)) == NULL) return NULL; /*endif*/ memset (values, 0, value_length); valuesp = values; for (i = 0; i < number; i++) { switch (list[i].type) { case XimType_CARD8: case XimType_CARD16: case XimType_CARD32: case XimType_Window: GetCardAttribute (valuesp, &list[i], need_swap); break; case XimType_XFontSet: GetFontAttribute (valuesp, &list[i], need_swap); break; case XimType_XRectangle: GetRectAttribute (valuesp, &list[i], need_swap); break; case XimType_XPoint: GetPointAttribute (valuesp, &list[i], need_swap); break; #if 0 case XimType_XIMHotKeyTriggers: GetHotKeyAttribute (valuesp, &list[i], need_swap); break; #endif } /*endswitch*/ valuesp += sizeof (CARD16)*2; valuesp += list[i].value_length; valuesp += IMPAD(list[i].value_length); } /*endfor*/ nest_list = (XICAttribute *) malloc (sizeof (XICAttribute)); if (nest_list == NULL) return NULL; /*endif*/ memset (nest_list, 0, sizeof (XICAttribute)); nest_list->value = (void *) malloc (value_length); if (nest_list->value == NULL) return NULL; /*endif*/ memset (nest_list->value, 0, sizeof (value_length)); nest_list->attribute_id = attr_id; nest_list->value_length = value_length; memmove (nest_list->value, values, value_length); XFree (values); return nest_list; } static Bool IsNestedList (Xi18n i18n_core, CARD16 icvalue_id) { XICAttr *ic_attr = i18n_core->address.xic_attr; int i; for (i = 0; i < i18n_core->address.ic_attr_num; i++, ic_attr++) { if (ic_attr->attribute_id == icvalue_id) { if (ic_attr->type == XimType_NEST) return True; /*endif*/ return False; } /*endif*/ } /*endfor*/ return False; } static Bool IsSeparator (Xi18n i18n_core, CARD16 icvalue_id) { return (i18n_core->address.separatorAttr_id == icvalue_id); } static int GetICValue (Xi18n i18n_core, XICAttribute *attr_ret, CARD16 *id_list, int list_num) { XICAttr *xic_attr = i18n_core->address.xic_attr; register int i; register int j; register int n; i = n = 0; if (IsNestedList (i18n_core, id_list[i])) { i++; while (i < list_num && !IsSeparator (i18n_core, id_list[i])) { for (j = 0; j < i18n_core->address.ic_attr_num; j++) { if (xic_attr[j].attribute_id == id_list[i]) { attr_ret[n].attribute_id = xic_attr[j].attribute_id; attr_ret[n].name_length = xic_attr[j].length; attr_ret[n].name = malloc (xic_attr[j].length + 1); strcpy(attr_ret[n].name, xic_attr[j].name); attr_ret[n].type = xic_attr[j].type; n++; i++; break; } /*endif*/ } /*endfor*/ } /*endwhile*/ } else { for (j = 0; j < i18n_core->address.ic_attr_num; j++) { if (xic_attr[j].attribute_id == id_list[i]) { attr_ret[n].attribute_id = xic_attr[j].attribute_id; attr_ret[n].name_length = xic_attr[j].length; attr_ret[n].name = malloc (xic_attr[j].length + 1); strcpy(attr_ret[n].name, xic_attr[j].name); attr_ret[n].type = xic_attr[j].type; n++; break; } /*endif*/ } /*endfor*/ } /*endif*/ return n; } static void SwapAttributes (XICAttribute *list, int number){ FrameMgr fm; CARD16 c16; extern XimFrameRec short_fr[]; CARD32 c32; extern XimFrameRec long_fr[]; XPoint xpoint; extern XimFrameRec xpoint_fr[]; XRectangle xrect; extern XimFrameRec xrectangle_fr[]; int i; for (i = 0; i < number; ++i, ++list) { if (list->value == NULL) continue; switch (list->type) { case XimType_CARD16: fm = FrameMgrInit (short_fr, (char *)list->value, 1); FrameMgrGetToken (fm, c16); memmove(list->value, &c16, sizeof(CARD16)); FrameMgrFree (fm); break; case XimType_CARD32: case XimType_Window: fm = FrameMgrInit (long_fr, (char *)list->value, 1); FrameMgrGetToken (fm, c32); memmove(list->value, &c32, sizeof(CARD32)); FrameMgrFree (fm); break; case XimType_XRectangle: fm = FrameMgrInit (xrectangle_fr, (char *)list->value, 1); FrameMgrGetToken (fm, xrect); memmove(list->value, &xrect, sizeof(XRectangle)); FrameMgrFree (fm); break; case XimType_XPoint: fm = FrameMgrInit (xpoint_fr, (char *)list->value, 1); FrameMgrGetToken (fm, xpoint); memmove(list->value, &xpoint, sizeof(XPoint)); FrameMgrFree (fm); break; default: break; } } } /* called from CreateICMessageProc and SetICValueMessageProc */ void _Xi18nChangeIC (XIMS ims, IMProtocol *call_data, unsigned char *p, int create_flag) { Xi18n i18n_core = ims->protocol; FrameMgr fm; FmStatus status; CARD16 byte_length; register int total_size; unsigned char *reply = NULL; register int i; register int attrib_num; XICAttribute *attrib_list; XICAttribute pre_attr[IC_SIZE]; XICAttribute sts_attr[IC_SIZE]; XICAttribute ic_attr[IC_SIZE]; CARD16 preedit_ic_num = 0; CARD16 status_ic_num = 0; CARD16 ic_num = 0; CARD16 connect_id = call_data->any.connect_id; IMChangeICStruct *changeic = (IMChangeICStruct *) &call_data->changeic; extern XimFrameRec create_ic_fr[]; extern XimFrameRec create_ic_reply_fr[]; extern XimFrameRec set_ic_values_fr[]; extern XimFrameRec set_ic_values_reply_fr[]; CARD16 input_method_ID; void *value_buf = NULL; void *value_buf_ptr; register int total_value_length = 0; memset (pre_attr, 0, sizeof (XICAttribute)*IC_SIZE); memset (sts_attr, 0, sizeof (XICAttribute)*IC_SIZE); memset (ic_attr, 0, sizeof (XICAttribute)*IC_SIZE); if (create_flag == True) { fm = FrameMgrInit (create_ic_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, byte_length); } else { fm = FrameMgrInit (set_ic_values_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, changeic->icid); FrameMgrGetToken (fm, byte_length); } /*endif*/ attrib_list = (XICAttribute *) malloc (sizeof (XICAttribute)*IC_SIZE); if (!attrib_list) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (attrib_list, 0, sizeof(XICAttribute)*IC_SIZE); attrib_num = 0; while (FrameMgrIsIterLoopEnd (fm, &status) == False) { void *value; int value_length; FrameMgrGetToken (fm, attrib_list[attrib_num].attribute_id); FrameMgrGetToken (fm, value_length); FrameMgrSetSize (fm, value_length); attrib_list[attrib_num].value_length = value_length; FrameMgrGetToken (fm, value); attrib_list[attrib_num].value = (void *) malloc (value_length + 1); memmove (attrib_list[attrib_num].value, value, value_length); ((char *)attrib_list[attrib_num].value)[value_length] = '\0'; attrib_num++; total_value_length += (value_length + 1); } /*endwhile*/ value_buf = (void *) malloc (total_value_length); value_buf_ptr = value_buf; if (!value_buf) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); for (i = 0; i < attrib_num; i++) XFree (attrib_list[i].value); /*endfor*/ XFree (attrib_list); return; } /*endif*/ for (i = 0; i < attrib_num; i++) { CARD16 number; if (IsNestedList (i18n_core, attrib_list[i].attribute_id)) { if (attrib_list[i].attribute_id == i18n_core->address.preeditAttr_id) { ReadICValue (i18n_core, attrib_list[i].attribute_id, attrib_list[i].value_length, attrib_list[i].value, &pre_attr[preedit_ic_num], &number, _Xi18nNeedSwap(i18n_core, connect_id), &value_buf_ptr); preedit_ic_num += number; } else if (attrib_list[i].attribute_id == i18n_core->address.statusAttr_id) { ReadICValue (i18n_core, attrib_list[i].attribute_id, attrib_list[i].value_length, attrib_list[i].value, &sts_attr[status_ic_num], &number, _Xi18nNeedSwap (i18n_core, connect_id), &value_buf_ptr); status_ic_num += number; } else { /* another nested list.. possible? */ } /*endif*/ } else { ReadICValue (i18n_core, attrib_list[i].attribute_id, attrib_list[i].value_length, attrib_list[i].value, &ic_attr[ic_num], &number, _Xi18nNeedSwap (i18n_core, connect_id), &value_buf_ptr); ic_num += number; } /*endif*/ } /*endfor*/ for (i = 0; i < attrib_num; i++) XFree (attrib_list[i].value); /*endfor*/ XFree (attrib_list); FrameMgrFree (fm); changeic->preedit_attr_num = preedit_ic_num; changeic->status_attr_num = status_ic_num; changeic->ic_attr_num = ic_num; changeic->preedit_attr = pre_attr; changeic->status_attr = sts_attr; changeic->ic_attr = ic_attr; if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) { XFree (value_buf); return; } /*endif*/ } XFree (value_buf); /*endif*/ if (create_flag == True) { fm = FrameMgrInit (create_ic_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); } else { fm = FrameMgrInit (set_ic_values_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); } /*endif*/ total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); FrameMgrPutToken (fm, changeic->icid); if (create_flag == True) { _Xi18nSendMessage (ims, connect_id, XIM_CREATE_IC_REPLY, 0, reply, total_size); } else { _Xi18nSendMessage (ims, connect_id, XIM_SET_IC_VALUES_REPLY, 0, reply, total_size); } /*endif*/ if (create_flag == True) { int on_key_num = i18n_core->address.on_keys.count_keys; int off_key_num = i18n_core->address.off_keys.count_keys; if (on_key_num == 0 && off_key_num == 0) { long mask; if (i18n_core->address.imvalue_mask & I18N_FILTERMASK) mask = i18n_core->address.filterevent_mask; else mask = DEFAULT_FILTER_MASK; /*endif*/ /* static event flow is default */ _Xi18nSetEventMask (ims, connect_id, input_method_ID, changeic->icid, mask, ~mask); } /*endif*/ } /*endif*/ FrameMgrFree (fm); XFree(reply); } /* called from GetICValueMessageProc */ void _Xi18nGetIC (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; FmStatus status; extern XimFrameRec get_ic_values_fr[]; extern XimFrameRec get_ic_values_reply_fr[]; CARD16 byte_length; register int total_size; unsigned char *reply = NULL; XICAttribute *preedit_ret = NULL; XICAttribute *status_ret = NULL; register int i; register int number; int iter_count; CARD16 *attrID_list; XICAttribute pre_attr[IC_SIZE]; XICAttribute sts_attr[IC_SIZE]; XICAttribute ic_attr[IC_SIZE]; CARD16 pre_count = 0; CARD16 sts_count = 0; CARD16 ic_count = 0; IMChangeICStruct *getic = (IMChangeICStruct *) &call_data->changeic; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; memset (pre_attr, 0, sizeof (XICAttribute)*IC_SIZE); memset (sts_attr, 0, sizeof (XICAttribute)*IC_SIZE); memset (ic_attr, 0, sizeof (XICAttribute)*IC_SIZE); fm = FrameMgrInit (get_ic_values_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, getic->icid); FrameMgrGetToken (fm, byte_length); attrID_list = (CARD16 *) malloc (sizeof (CARD16)*IC_SIZE); /* bogus */ memset (attrID_list, 0, sizeof (CARD16)*IC_SIZE); number = 0; while (FrameMgrIsIterLoopEnd (fm, &status) == False) FrameMgrGetToken (fm, attrID_list[number++]); /*endwhile*/ FrameMgrFree (fm); i = 0; while (i < number) { int read_number; if (IsNestedList (i18n_core, attrID_list[i])) { if (attrID_list[i] == i18n_core->address.preeditAttr_id) { read_number = GetICValue (i18n_core, &pre_attr[pre_count], &attrID_list[i], number); i += read_number + 1; pre_count += read_number; } else if (attrID_list[i] == i18n_core->address.statusAttr_id) { read_number = GetICValue (i18n_core, &sts_attr[sts_count], &attrID_list[i], number); i += read_number + 1; sts_count += read_number; } else { /* another nested list.. possible? */ } /*endif*/ } else { read_number = GetICValue (i18n_core, &ic_attr[ic_count], &attrID_list[i], number); i += read_number; ic_count += read_number; } /*endif*/ } /*endwhile*/ getic->preedit_attr_num = pre_count; getic->status_attr_num = sts_count; getic->ic_attr_num = ic_count; getic->preedit_attr = pre_attr; getic->status_attr = sts_attr; getic->ic_attr = ic_attr; if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ if (_Xi18nNeedSwap (i18n_core, connect_id)) SwapAttributes(getic->ic_attr, getic->ic_attr_num); } /*endif*/ iter_count = getic->ic_attr_num; preedit_ret = CreateNestedList (i18n_core->address.preeditAttr_id, getic->preedit_attr, getic->preedit_attr_num, _Xi18nNeedSwap (i18n_core, connect_id)); if (preedit_ret) iter_count++; /*endif*/ status_ret = CreateNestedList (i18n_core->address.statusAttr_id, getic->status_attr, getic->status_attr_num, _Xi18nNeedSwap (i18n_core, connect_id)); if (status_ret) iter_count++; /*endif*/ fm = FrameMgrInit (get_ic_values_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); /* set iteration count for list of ic_attribute */ FrameMgrSetIterCount (fm, iter_count); /* set length of BARRAY item in xicattribute_fr */ for (i = 0; i < (int) getic->ic_attr_num; i++) FrameMgrSetSize (fm, ic_attr[i].value_length); /*endfor*/ if (preedit_ret) FrameMgrSetSize (fm, preedit_ret->value_length); /*endif*/ if (status_ret) FrameMgrSetSize (fm, status_ret->value_length); /*endif*/ total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (reply == NULL) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); FrameMgrPutToken (fm, getic->icid); for (i = 0; i < (int) getic->ic_attr_num; i++) { FrameMgrPutToken (fm, ic_attr[i].attribute_id); FrameMgrPutToken (fm, ic_attr[i].value_length); FrameMgrPutToken (fm, ic_attr[i].value); } /*endfor*/ if (preedit_ret) { FrameMgrPutToken (fm, preedit_ret->attribute_id); FrameMgrPutToken (fm, preedit_ret->value_length); FrameMgrPutToken (fm, preedit_ret->value); } /*endif*/ if (status_ret) { FrameMgrPutToken (fm, status_ret->attribute_id); FrameMgrPutToken (fm, status_ret->value_length); FrameMgrPutToken (fm, status_ret->value); } /*endif*/ _Xi18nSendMessage (ims, connect_id, XIM_GET_IC_VALUES_REPLY, 0, reply, total_size); XFree (reply); XFree (attrID_list); for (i = 0; i < (int) getic->ic_attr_num; i++) { if (getic->ic_attr[i].name) XFree (getic->ic_attr[i].name); /*endif*/ if (getic->ic_attr[i].value) XFree (getic->ic_attr[i].value); /*endif*/ } /*endfor*/ for (i = 0; i < (int) getic->preedit_attr_num; i++) { if (getic->preedit_attr[i].name) XFree (getic->preedit_attr[i].name); /*endif*/ if (getic->preedit_attr[i].value) XFree (getic->preedit_attr[i].value); /*endif*/ } /*endfor*/ for (i = 0; i < (int) getic->status_attr_num; i++) { if (getic->status_attr[i].name) XFree (getic->status_attr[i].name); /*endif*/ if (getic->status_attr[i].value) XFree (getic->status_attr[i].value); /*endif*/ } /*endfor*/ if (preedit_ret) { XFree (preedit_ret->value); XFree (preedit_ret); } /*endif*/ if (status_ret) { XFree (status_ret->value); XFree (status_ret); } /*endif*/ FrameMgrFree (fm); } xsunpinyin-2.0.3/IMdkit/i18nMethod.c0000644000076400007640000011065211527365010015656 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include #ifndef NEED_EVENTS #define NEED_EVENTS #endif #include #undef NEED_EVENTS #include "FrameMgr.h" #include "IMdkit.h" #include "Xi18n.h" #include "XimFunc.h" extern Xi18nClient *_Xi18nFindClient (Xi18n, CARD16); static void *xi18n_setup (Display *, XIMArg *); static Status xi18n_openIM (XIMS); static Status xi18n_closeIM (XIMS); static char *xi18n_setIMValues (XIMS, XIMArg *); static char *xi18n_getIMValues (XIMS, XIMArg *); static Status xi18n_forwardEvent (XIMS, XPointer); static Status xi18n_commit (XIMS, XPointer); static int xi18n_callCallback (XIMS, XPointer); static int xi18n_preeditStart (XIMS, XPointer); static int xi18n_preeditEnd (XIMS, XPointer); static int xi18n_syncXlib (XIMS, XPointer); #ifndef XIM_SERVERS #define XIM_SERVERS "XIM_SERVERS" #endif static Atom XIM_Servers = None; IMMethodsRec Xi18n_im_methods = { xi18n_setup, xi18n_openIM, xi18n_closeIM, xi18n_setIMValues, xi18n_getIMValues, xi18n_forwardEvent, xi18n_commit, xi18n_callCallback, xi18n_preeditStart, xi18n_preeditEnd, xi18n_syncXlib, }; extern Bool _Xi18nCheckXAddress (Xi18n, TransportSW *, char *); extern Bool _Xi18nCheckTransAddress (Xi18n, TransportSW *, char *); TransportSW _TransR[] = { {"X", 1, _Xi18nCheckXAddress}, #ifdef TCPCONN {"tcp", 3, _Xi18nCheckTransAddress}, {"local", 5, _Xi18nCheckTransAddress}, #endif #ifdef DNETCONN {"decnet", 6, _Xi18nCheckTransAddress}, #endif {(char *) NULL, 0, (Bool (*) ()) NULL} }; static Bool GetInputStyles (Xi18n i18n_core, XIMStyles **p_style) { Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address; XIMStyles *p; int i; p = &address->input_styles; if ((*p_style = (XIMStyles *) malloc (sizeof (XIMStyles) + p->count_styles*sizeof (XIMStyle))) == NULL) { return False; } /*endif*/ (*p_style)->count_styles = p->count_styles; (*p_style)->supported_styles = (XIMStyle *) ((XPointer) *p_style + sizeof (XIMStyles)); for (i = 0; i < (int) p->count_styles; i++) (*p_style)->supported_styles[i] = p->supported_styles[i]; /*endfor*/ return True; } static Bool GetOnOffKeys (Xi18n i18n_core, long mask, XIMTriggerKeys **p_key) { Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address; XIMTriggerKeys *p; int i; if (mask & I18N_ON_KEYS) p = &address->on_keys; else p = &address->off_keys; /*endif*/ if ((*p_key = (XIMTriggerKeys *) malloc (sizeof(XIMTriggerKeys) + p->count_keys*sizeof(XIMTriggerKey))) == NULL) { return False; } /*endif*/ (*p_key)->count_keys = p->count_keys; (*p_key)->keylist = (XIMTriggerKey *) ((XPointer) *p_key + sizeof(XIMTriggerKeys)); for (i = 0; i < (int) p->count_keys; i++) { (*p_key)->keylist[i].keysym = p->keylist[i].keysym; (*p_key)->keylist[i].modifier = p->keylist[i].modifier; (*p_key)->keylist[i].modifier_mask = p->keylist[i].modifier_mask; } /*endfor*/ return True; } static Bool GetEncodings(Xi18n i18n_core, XIMEncodings **p_encoding) { Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address; XIMEncodings *p; int i; p = &address->encoding_list; if ((*p_encoding = (XIMEncodings *) malloc (sizeof (XIMEncodings) + p->count_encodings*sizeof(XIMEncoding))) == NULL) { return False; } /*endif*/ (*p_encoding)->count_encodings = p->count_encodings; (*p_encoding)->supported_encodings = (XIMEncoding *) ((XPointer)*p_encoding + sizeof (XIMEncodings)); for (i = 0; i < (int) p->count_encodings; i++) { (*p_encoding)->supported_encodings[i] = (char *) malloc (strlen (p->supported_encodings[i]) + 1); strcpy ((*p_encoding)->supported_encodings[i], p->supported_encodings[i]); } /*endif*/ return True; } static char *ParseArgs (Xi18n i18n_core, int mode, XIMArg *args) { Xi18nAddressRec *address = (Xi18nAddressRec *) &i18n_core->address; XIMArg *p; if (mode == I18N_OPEN || mode == I18N_SET) { for (p = args; p->name != NULL; p++) { if (strcmp (p->name, IMLocale) == 0) { if (address->imvalue_mask & I18N_IM_LOCALE) return IMLocale; /*endif*/ address->im_locale = (char *) malloc (strlen (p->value) + 1); if (!address->im_locale) return IMLocale; /*endif*/ strcpy (address->im_locale, p->value); address->imvalue_mask |= I18N_IM_LOCALE; } else if (strcmp (p->name, IMServerTransport) == 0) { if (address->imvalue_mask & I18N_IM_ADDRESS) return IMServerTransport; /*endif*/ address->im_addr = (char *) malloc (strlen (p->value) + 1); if (!address->im_addr) return IMServerTransport; /*endif*/ strcpy(address->im_addr, p->value); address->imvalue_mask |= I18N_IM_ADDRESS; } else if (strcmp (p->name, IMServerName) == 0) { if (address->imvalue_mask & I18N_IM_NAME) return IMServerName; /*endif*/ address->im_name = (char *) malloc (strlen (p->value) + 1); if (!address->im_name) return IMServerName; /*endif*/ strcpy (address->im_name, p->value); address->imvalue_mask |= I18N_IM_NAME; } else if (strcmp (p->name, IMServerWindow) == 0) { if (address->imvalue_mask & I18N_IMSERVER_WIN) return IMServerWindow; /*endif*/ address->im_window = (Window) p->value; address->imvalue_mask |= I18N_IMSERVER_WIN; } else if (strcmp (p->name, IMInputStyles) == 0) { if (address->imvalue_mask & I18N_INPUT_STYLES) return IMInputStyles; /*endif*/ address->input_styles.count_styles = ((XIMStyles*)p->value)->count_styles; address->input_styles.supported_styles = (XIMStyle *) malloc (sizeof (XIMStyle)*address->input_styles.count_styles); if (address->input_styles.supported_styles == (XIMStyle *) NULL) return IMInputStyles; /*endif*/ memmove (address->input_styles.supported_styles, ((XIMStyles *) p->value)->supported_styles, sizeof (XIMStyle)*address->input_styles.count_styles); address->imvalue_mask |= I18N_INPUT_STYLES; } else if (strcmp (p->name, IMProtocolHandler) == 0) { address->improto = (IMProtoHandler) p->value; address->imvalue_mask |= I18N_IM_HANDLER; } else if (strcmp (p->name, IMOnKeysList) == 0) { if (address->imvalue_mask & I18N_ON_KEYS) return IMOnKeysList; /*endif*/ address->on_keys.count_keys = ((XIMTriggerKeys *) p->value)->count_keys; address->on_keys.keylist = (XIMTriggerKey *) malloc (sizeof (XIMTriggerKey)*address->on_keys.count_keys); if (address->on_keys.keylist == (XIMTriggerKey *) NULL) return IMOnKeysList; /*endif*/ memmove (address->on_keys.keylist, ((XIMTriggerKeys *) p->value)->keylist, sizeof (XIMTriggerKey)*address->on_keys.count_keys); address->imvalue_mask |= I18N_ON_KEYS; } else if (strcmp (p->name, IMOffKeysList) == 0) { if (address->imvalue_mask & I18N_OFF_KEYS) return IMOffKeysList; /*endif*/ address->off_keys.count_keys = ((XIMTriggerKeys *) p->value)->count_keys; address->off_keys.keylist = (XIMTriggerKey *) malloc (sizeof (XIMTriggerKey)*address->off_keys.count_keys); if (address->off_keys.keylist == (XIMTriggerKey *) NULL) return IMOffKeysList; /*endif*/ memmove (address->off_keys.keylist, ((XIMTriggerKeys *) p->value)->keylist, sizeof (XIMTriggerKey)*address->off_keys.count_keys); address->imvalue_mask |= I18N_OFF_KEYS; } else if (strcmp (p->name, IMEncodingList) == 0) { if (address->imvalue_mask & I18N_ENCODINGS) return IMEncodingList; /*endif*/ address->encoding_list.count_encodings = ((XIMEncodings *) p->value)->count_encodings; address->encoding_list.supported_encodings = (XIMEncoding *) malloc (sizeof (XIMEncoding)*address->encoding_list.count_encodings); if (address->encoding_list.supported_encodings == (XIMEncoding *) NULL) { return IMEncodingList; } /*endif*/ memmove (address->encoding_list.supported_encodings, ((XIMEncodings *) p->value)->supported_encodings, sizeof (XIMEncoding)*address->encoding_list.count_encodings); address->imvalue_mask |= I18N_ENCODINGS; } else if (strcmp (p->name, IMFilterEventMask) == 0) { if (address->imvalue_mask & I18N_FILTERMASK) return IMFilterEventMask; /*endif*/ address->filterevent_mask = (long) p->value; address->imvalue_mask |= I18N_FILTERMASK; } /*endif*/ } /*endfor*/ if (mode == I18N_OPEN) { /* check mandatory IM values */ if (!(address->imvalue_mask & I18N_IM_LOCALE)) { /* locales must be set in IMOpenIM */ return IMLocale; } /*endif*/ if (!(address->imvalue_mask & I18N_IM_ADDRESS)) { /* address must be set in IMOpenIM */ return IMServerTransport; } /*endif*/ } /*endif*/ } else if (mode == I18N_GET) { for (p = args; p->name != NULL; p++) { if (strcmp (p->name, IMLocale) == 0) { p->value = (char *) malloc (strlen (address->im_locale) + 1); if (!p->value) return IMLocale; /*endif*/ strcpy (p->value, address->im_locale); } else if (strcmp (p->name, IMServerTransport) == 0) { p->value = (char *) malloc (strlen (address->im_addr) + 1); if (!p->value) return IMServerTransport; /*endif*/ strcpy (p->value, address->im_addr); } else if (strcmp (p->name, IMServerName) == 0) { if (address->imvalue_mask & I18N_IM_NAME) { p->value = (char *) malloc (strlen (address->im_name) + 1); if (!p->value) return IMServerName; /*endif*/ strcpy (p->value, address->im_name); } else { return IMServerName; } /*endif*/ } else if (strcmp (p->name, IMServerWindow) == 0) { if (address->imvalue_mask & I18N_IMSERVER_WIN) *((Window *) (p->value)) = address->im_window; else return IMServerWindow; /*endif*/ } else if (strcmp (p->name, IMInputStyles) == 0) { if (GetInputStyles (i18n_core, (XIMStyles **) p->value) == False) { return IMInputStyles; } /*endif*/ } else if (strcmp (p->name, IMProtocolHandler) == 0) { if (address->imvalue_mask & I18N_IM_HANDLER) *((IMProtoHandler *) (p->value)) = address->improto; else return IMProtocolHandler; /*endif*/ } else if (strcmp (p->name, IMOnKeysList) == 0) { if (address->imvalue_mask & I18N_ON_KEYS) { if (GetOnOffKeys (i18n_core, I18N_ON_KEYS, (XIMTriggerKeys **) p->value) == False) { return IMOnKeysList; } /*endif*/ } else { return IMOnKeysList; } /*endif*/ } else if (strcmp (p->name, IMOffKeysList) == 0) { if (address->imvalue_mask & I18N_OFF_KEYS) { if (GetOnOffKeys (i18n_core, I18N_OFF_KEYS, (XIMTriggerKeys **) p->value) == False) { return IMOffKeysList; } /*endif*/ } else { return IMOffKeysList; } /*endif*/ } else if (strcmp (p->name, IMEncodingList) == 0) { if (address->imvalue_mask & I18N_ENCODINGS) { if (GetEncodings (i18n_core, (XIMEncodings **) p->value) == False) { return IMEncodingList; } /*endif*/ } else { return IMEncodingList; } /*endif*/ } else if (strcmp (p->name, IMFilterEventMask) == 0) { if (address->imvalue_mask & I18N_FILTERMASK) *((long *) (p->value)) = address->filterevent_mask; else return IMFilterEventMask; /*endif*/ } /*endif*/ } /*endfor*/ } /*endif*/ return NULL; } static int CheckIMName (Xi18n i18n_core) { char *address = i18n_core->address.im_addr; int i; for (i = 0; _TransR[i].transportname; i++) { while (*address == ' ' || *address == '\t') address++; /*endwhile*/ if (strncmp (address, _TransR[i].transportname, _TransR[i].namelen) == 0 && address[_TransR[i].namelen] == '/') { if (_TransR[i].checkAddr (i18n_core, &_TransR[i], address + _TransR[i].namelen + 1) == True) { return True; } /*endif*/ return False; } /*endif*/ } /*endfor*/ return False; } static int SetXi18nSelectionOwner(Xi18n i18n_core) { Display *dpy = i18n_core->address.dpy; Window ims_win = i18n_core->address.im_window; Window root = RootWindow (dpy, DefaultScreen (dpy)); Atom realtype; int realformat; unsigned long bytesafter; long *data=NULL; unsigned long length; Atom atom; int i; int found; int forse = False; char buf[256]; (void)snprintf(buf, 256, "@server=%s", i18n_core->address.im_name); if ((atom = XInternAtom(dpy, buf, False)) == 0) return False; i18n_core->address.selection = atom; if (XIM_Servers == None) XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False); /*endif*/ XGetWindowProperty (dpy, root, XIM_Servers, 0L, 1000000L, False, XA_ATOM, &realtype, &realformat, &length, &bytesafter, (unsigned char **) (&data)); if (realtype != None && (realtype != XA_ATOM || realformat != 32)) { if (data != NULL) XFree ((char *) data); return False; } found = False; for (i = 0; i < length; i++) { if (data[i] == atom) { Window owner; found = True; if ((owner = XGetSelectionOwner (dpy, atom)) != ims_win) { if (owner == None || forse == True) XSetSelectionOwner (dpy, atom, ims_win, CurrentTime); else return False; } break; } } if (found == False) { XSetSelectionOwner (dpy, atom, ims_win, CurrentTime); XChangeProperty (dpy, root, XIM_Servers, XA_ATOM, 32, PropModePrepend, (unsigned char *) &atom, 1); } else { /* * We always need to generate the PropertyNotify to the Root Window */ XChangeProperty (dpy, root, XIM_Servers, XA_ATOM, 32, PropModePrepend, (unsigned char *) data, 0); } if (data != NULL) XFree ((char *) data); /* Intern "LOCALES" and "TRANSOPORT" Target Atoms */ i18n_core->address.Localename = XInternAtom (dpy, LOCALES, False); i18n_core->address.Transportname = XInternAtom (dpy, TRANSPORT, False); return (XGetSelectionOwner (dpy, atom) == ims_win); } static int DeleteXi18nAtom(Xi18n i18n_core) { Display *dpy = i18n_core->address.dpy; Window root = RootWindow (dpy, DefaultScreen (dpy)); Atom realtype; int realformat; unsigned long bytesafter; long *data=NULL; unsigned long length; Atom atom; int i, ret; int found; char buf[256]; (void)snprintf(buf, 256, "@server=%s", i18n_core->address.im_name); if ((atom = XInternAtom(dpy, buf, False)) == 0) return False; i18n_core->address.selection = atom; if (XIM_Servers == None) XIM_Servers = XInternAtom (dpy, XIM_SERVERS, False); XGetWindowProperty (dpy, root, XIM_Servers, 0L, 1000000L, False, XA_ATOM, &realtype, &realformat, &length, &bytesafter, (unsigned char **) (&data)); if (realtype != XA_ATOM || realformat != 32) { if (data != NULL) XFree ((char *) data); return False; } found = False; for (i = 0; i < length; i++) { if (data[i] == atom) { found = True; break; } } if (found == True) { for (i=i+1; iaddress.dpy = dpy; if (ParseArgs (i18n_core, I18N_OPEN, args) != NULL) { XFree (i18n_core); return NULL; } /*endif*/ if (*(char *) &endian) i18n_core->address.im_byteOrder = 'l'; else i18n_core->address.im_byteOrder = 'B'; /*endif*/ /* install IMAttr and ICAttr list in i18n_core */ _Xi18nInitAttrList (i18n_core); /* install IMExtension list in i18n_core */ _Xi18nInitExtension (i18n_core); return i18n_core; } static void ReturnSelectionNotify (Xi18n i18n_core, XSelectionRequestEvent *ev) { XEvent event; Display *dpy = i18n_core->address.dpy; char buf[4096]; event.type = SelectionNotify; event.xselection.requestor = ev->requestor; event.xselection.selection = ev->selection; event.xselection.target = ev->target; event.xselection.time = ev->time; event.xselection.property = ev->property; if (ev->target == i18n_core->address.Localename) { snprintf (buf, 4096, "@locale=%s", i18n_core->address.im_locale); } else if (ev->target == i18n_core->address.Transportname) { snprintf (buf, 4096, "@transport=%s", i18n_core->address.im_addr); } /*endif*/ XChangeProperty (dpy, event.xselection.requestor, ev->target, ev->target, 8, PropModeReplace, (unsigned char *) buf, strlen (buf)); XSendEvent (dpy, event.xselection.requestor, False, NoEventMask, &event); XFlush (i18n_core->address.dpy); } static Bool WaitXSelectionRequest (Display *dpy, Window win, XEvent *ev, XPointer client_data) { XIMS ims = (XIMS) client_data; Xi18n i18n_core = ims->protocol; if (((XSelectionRequestEvent *) ev)->selection == i18n_core->address.selection) { ReturnSelectionNotify (i18n_core, (XSelectionRequestEvent *) ev); return True; } /*endif*/ return False; } static Status xi18n_openIM(XIMS ims) { Xi18n i18n_core = ims->protocol; Display *dpy = i18n_core->address.dpy; if (!CheckIMName (i18n_core) || !SetXi18nSelectionOwner (i18n_core) || !i18n_core->methods.begin (ims)) { XFree (i18n_core->address.im_name); XFree (i18n_core->address.im_locale); XFree (i18n_core->address.im_addr); XFree (i18n_core); return False; } /*endif*/ _XRegisterFilterByType (dpy, i18n_core->address.im_window, SelectionRequest, SelectionRequest, WaitXSelectionRequest, (XPointer)ims); XFlush(dpy); return True; } static Status xi18n_closeIM(XIMS ims) { Xi18n i18n_core = ims->protocol; Display *dpy = i18n_core->address.dpy; DeleteXi18nAtom(i18n_core); if (!i18n_core->methods.end (ims)) return False; _XUnregisterFilter (dpy, i18n_core->address.im_window, WaitXSelectionRequest, (XPointer)ims); XFree (i18n_core->address.im_name); XFree (i18n_core->address.im_locale); XFree (i18n_core->address.im_addr); XFree (i18n_core); return True; } static char *xi18n_setIMValues (XIMS ims, XIMArg *args) { Xi18n i18n_core = ims->protocol; char *ret; if ((ret = ParseArgs (i18n_core, I18N_SET, args)) != NULL) return ret; /*endif*/ return NULL; } static char *xi18n_getIMValues (XIMS ims, XIMArg *args) { Xi18n i18n_core = ims->protocol; char *ret; if ((ret = ParseArgs (i18n_core, I18N_GET, args)) != NULL) return ret; /*endif*/ return NULL; } static void EventToWireEvent (XEvent *ev, xEvent *event, CARD16 *serial, Bool byte_swap) { FrameMgr fm; extern XimFrameRec wire_keyevent_fr[]; extern XimFrameRec short_fr[]; BYTE b; CARD16 c16; CARD32 c32; *serial = (CARD16)(ev->xany.serial >> 16); switch (ev->type) { case KeyPress: case KeyRelease: { XKeyEvent *kev = (XKeyEvent*)ev; /* create FrameMgr */ fm = FrameMgrInit(wire_keyevent_fr, (char *)(&(event->u)), byte_swap); /* set values */ b = (BYTE)kev->type; FrameMgrPutToken(fm, b); b = (BYTE)kev->keycode; FrameMgrPutToken(fm, b); c16 = (CARD16)(kev->serial & (unsigned long)0xffff); FrameMgrPutToken(fm, c16); c32 = (CARD32)kev->time; FrameMgrPutToken(fm, c32); c32 = (CARD32)kev->root; FrameMgrPutToken(fm, c32); c32 = (CARD32)kev->window; FrameMgrPutToken(fm, c32); c32 = (CARD32)kev->subwindow; FrameMgrPutToken(fm, c32); c16 = (CARD16)kev->x_root; FrameMgrPutToken(fm, c16); c16 = (CARD16)kev->y_root; FrameMgrPutToken(fm, c16); c16 = (CARD16)kev->x; FrameMgrPutToken(fm, c16); c16 = (CARD16)kev->y; FrameMgrPutToken(fm, c16); c16 = (CARD16)kev->state; FrameMgrPutToken(fm, c16); b = (BYTE)kev->same_screen; FrameMgrPutToken(fm, b); } break; default: /* create FrameMgr */ fm = FrameMgrInit(short_fr, (char *)(&(event->u.u.sequenceNumber)), byte_swap); c16 = (CARD16)(ev->xany.serial & (unsigned long)0xffff); FrameMgrPutToken(fm, c16); break; } /* free FrameMgr */ FrameMgrFree(fm); } static Status xi18n_forwardEvent (XIMS ims, XPointer xp) { Xi18n i18n_core = ims->protocol; IMForwardEventStruct *call_data = (IMForwardEventStruct *)xp; FrameMgr fm; extern XimFrameRec forward_event_fr[]; register int total_size; unsigned char *reply = NULL; unsigned char *replyp; CARD16 serial; int event_size; Xi18nClient *client; client = (Xi18nClient *) _Xi18nFindClient (i18n_core, call_data->connect_id); /* create FrameMgr */ fm = FrameMgrInit (forward_event_fr, NULL, _Xi18nNeedSwap (i18n_core, call_data->connect_id)); total_size = FrameMgrGetTotalSize (fm); event_size = sizeof (xEvent); reply = (unsigned char *) malloc (total_size + event_size); if (!reply) { _Xi18nSendMessage (ims, call_data->connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size + event_size); FrameMgrSetBuffer (fm, reply); replyp = reply; call_data->sync_bit = 1; /* always sync */ client->sync = True; FrameMgrPutToken (fm, call_data->connect_id); FrameMgrPutToken (fm, call_data->icid); FrameMgrPutToken (fm, call_data->sync_bit); replyp += total_size; EventToWireEvent (&(call_data->event), (xEvent *) replyp, &serial, _Xi18nNeedSwap (i18n_core, call_data->connect_id)); FrameMgrPutToken (fm, serial); _Xi18nSendMessage (ims, call_data->connect_id, XIM_FORWARD_EVENT, 0, reply, total_size + event_size); XFree (reply); FrameMgrFree (fm); return True; } static Status xi18n_commit (XIMS ims, XPointer xp) { Xi18n i18n_core = ims->protocol; IMCommitStruct *call_data = (IMCommitStruct *)xp; FrameMgr fm; extern XimFrameRec commit_chars_fr[]; extern XimFrameRec commit_both_fr[]; register int total_size; unsigned char *reply = NULL; CARD16 str_length; call_data->flag |= XimSYNCHRONUS; /* always sync */ if (!(call_data->flag & XimLookupKeySym) && (call_data->flag & XimLookupChars)) { fm = FrameMgrInit (commit_chars_fr, NULL, _Xi18nNeedSwap (i18n_core, call_data->connect_id)); /* set length of STRING8 */ str_length = strlen (call_data->commit_string); FrameMgrSetSize (fm, str_length); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, call_data->connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); str_length = FrameMgrGetSize (fm); FrameMgrPutToken (fm, call_data->connect_id); FrameMgrPutToken (fm, call_data->icid); FrameMgrPutToken (fm, call_data->flag); FrameMgrPutToken (fm, str_length); FrameMgrPutToken (fm, call_data->commit_string); } else { fm = FrameMgrInit (commit_both_fr, NULL, _Xi18nNeedSwap (i18n_core, call_data->connect_id)); /* set length of STRING8 */ str_length = strlen (call_data->commit_string); if (str_length > 0) FrameMgrSetSize (fm, str_length); /*endif*/ total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, call_data->connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, call_data->connect_id); FrameMgrPutToken (fm, call_data->icid); FrameMgrPutToken (fm, call_data->flag); FrameMgrPutToken (fm, call_data->keysym); if (str_length > 0) { str_length = FrameMgrGetSize (fm); FrameMgrPutToken (fm, str_length); FrameMgrPutToken (fm, call_data->commit_string); } /*endif*/ } /*endif*/ _Xi18nSendMessage (ims, call_data->connect_id, XIM_COMMIT, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); return True; } static int xi18n_callCallback (XIMS ims, XPointer xp) { IMProtocol *call_data = (IMProtocol *)xp; switch (call_data->major_code) { case XIM_GEOMETRY: return _Xi18nGeometryCallback (ims, call_data); case XIM_PREEDIT_START: return _Xi18nPreeditStartCallback (ims, call_data); case XIM_PREEDIT_DRAW: return _Xi18nPreeditDrawCallback (ims, call_data); case XIM_PREEDIT_CARET: return _Xi18nPreeditCaretCallback (ims, call_data); case XIM_PREEDIT_DONE: return _Xi18nPreeditDoneCallback (ims, call_data); case XIM_STATUS_START: return _Xi18nStatusStartCallback (ims, call_data); case XIM_STATUS_DRAW: return _Xi18nStatusDrawCallback (ims, call_data); case XIM_STATUS_DONE: return _Xi18nStatusDoneCallback (ims, call_data); case XIM_STR_CONVERSION: return _Xi18nStringConversionCallback (ims, call_data); } /*endswitch*/ return False; } /* preeditStart and preeditEnd are used only for Dynamic Event Flow. */ static int xi18n_preeditStart (XIMS ims, XPointer xp) { IMProtocol *call_data = (IMProtocol *)xp; Xi18n i18n_core = ims->protocol; IMPreeditStateStruct *preedit_state = (IMPreeditStateStruct *) &call_data->preedit_state; long mask; int on_key_num = i18n_core->address.on_keys.count_keys; int off_key_num = i18n_core->address.off_keys.count_keys; if (on_key_num == 0 && off_key_num == 0) return False; /*endif*/ if (i18n_core->address.imvalue_mask & I18N_FILTERMASK) mask = i18n_core->address.filterevent_mask; else mask = DEFAULT_FILTER_MASK; /*endif*/ _Xi18nSetEventMask (ims, preedit_state->connect_id, preedit_state->connect_id, preedit_state->icid, mask, ~mask); return True; } static int xi18n_preeditEnd (XIMS ims, XPointer xp) { IMProtocol *call_data = (IMProtocol *)xp; Xi18n i18n_core = ims->protocol; int on_key_num = i18n_core->address.on_keys.count_keys; int off_key_num = i18n_core->address.off_keys.count_keys; IMPreeditStateStruct *preedit_state; preedit_state = (IMPreeditStateStruct *) &call_data->preedit_state; if (on_key_num == 0 && off_key_num == 0) return False; /*endif*/ _Xi18nSetEventMask (ims, preedit_state->connect_id, preedit_state->connect_id, preedit_state->icid, 0, 0); return True; } static int xi18n_syncXlib (XIMS ims, XPointer xp) { IMProtocol *call_data = (IMProtocol *)xp; Xi18n i18n_core = ims->protocol; IMSyncXlibStruct *sync_xlib; extern XimFrameRec sync_fr[]; FrameMgr fm; CARD16 connect_id = call_data->any.connect_id; int total_size; unsigned char *reply; sync_xlib = (IMSyncXlibStruct *) &call_data->sync_xlib; fm = FrameMgrInit (sync_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize(fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); /* input input-method ID */ FrameMgrPutToken (fm, connect_id); /* input input-context ID */ FrameMgrPutToken (fm, sync_xlib->icid); _Xi18nSendMessage (ims, connect_id, XIM_SYNC, 0, reply, total_size); FrameMgrFree (fm); XFree(reply); return True; } xsunpinyin-2.0.3/IMdkit/IMMethod.c0000644000076400007640000000443011527365010015400 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include "IMdkit.h" /* Public Function */ void IMForwardEvent (XIMS ims, XPointer call_data) { (ims->methods->forwardEvent) (ims, call_data); } void IMCommitString (XIMS ims, XPointer call_data) { (ims->methods->commitString) (ims, call_data); } int IMCallCallback (XIMS ims, XPointer call_data) { return (ims->methods->callCallback) (ims, call_data); } int IMPreeditStart (XIMS ims, XPointer call_data) { return (ims->methods->preeditStart) (ims, call_data); } int IMPreeditEnd (XIMS ims, XPointer call_data) { return (ims->methods->preeditEnd) (ims, call_data); } int IMSyncXlib(XIMS ims, XPointer call_data) { ims->sync = True; return (ims->methods->syncXlib) (ims, call_data); } xsunpinyin-2.0.3/IMdkit/i18nAttr.c0000644000076400007640000001324511527365010015350 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include #include "IMdkit.h" #include "Xi18n.h" #include "XimFunc.h" typedef struct { char *name; CARD16 type; } IMListOfAttr; typedef struct { char *name; CARD8 major_opcode; CARD8 minor_opcode; } IMExtList; IMListOfAttr Default_IMattr[] = { {XNQueryInputStyle, XimType_XIMStyles}, /* {XNQueryIMValuesList, XimType_XIMValuesList}, */ {(char *) NULL, (CARD16) 0} }; IMListOfAttr Default_ICattr[] = { {XNInputStyle, XimType_CARD32}, {XNClientWindow, XimType_Window}, {XNFocusWindow, XimType_Window}, {XNFilterEvents, XimType_CARD32}, {XNPreeditAttributes, XimType_NEST}, {XNStatusAttributes, XimType_NEST}, {XNFontSet, XimType_XFontSet}, {XNArea, XimType_XRectangle}, {XNAreaNeeded, XimType_XRectangle}, {XNColormap, XimType_CARD32}, {XNStdColormap, XimType_CARD32}, {XNForeground, XimType_CARD32}, {XNBackground, XimType_CARD32}, {XNBackgroundPixmap, XimType_CARD32}, {XNSpotLocation, XimType_XPoint}, {XNLineSpace, XimType_CARD32}, {XNPreeditState, XimType_CARD32}, {XNSeparatorofNestedList, XimType_SeparatorOfNestedList}, {(char *) NULL, 0} }; IMExtList Default_Extension[] = { {"XIM_EXT_MOVE", XIM_EXTENSION, XIM_EXT_MOVE}, {"XIM_EXT_SET_EVENT_MASK", XIM_EXTENSION, XIM_EXT_SET_EVENT_MASK}, {"XIM_EXT_FORWARD_KEYEVENT", XIM_EXTENSION, XIM_EXT_FORWARD_KEYEVENT}, {(char *) NULL, 0, 0} }; static void CountAttrList(IMListOfAttr *attr, int *total_count) { *total_count = 0; while (attr->name != NULL) { attr++; ++(*total_count); } } static XIMAttr *CreateAttrList (Xi18n i18n_core, IMListOfAttr *attr, int *total_count) { XIMAttr *args, *p; unsigned int buf_size; CountAttrList(attr, total_count); buf_size = (unsigned) (*total_count + 1)*sizeof (XIMAttr); args = (XIMAttr *) malloc (buf_size); if (!args) return (XIMAttr *) NULL; /*endif*/ memset (args, 0, buf_size); for (p = args; attr->name != NULL; attr++, p++) { p->name = attr->name; p->length = strlen (attr->name); p->type = (CARD16) attr->type; p->attribute_id = XrmStringToQuark (p->name); if (strcmp (p->name, XNPreeditAttributes) == 0) i18n_core->address.preeditAttr_id = p->attribute_id; else if (strcmp (p->name, XNStatusAttributes) == 0) i18n_core->address.statusAttr_id = p->attribute_id; else if (strcmp (p->name, XNSeparatorofNestedList) == 0) i18n_core->address.separatorAttr_id = p->attribute_id; /*endif*/ } /*endfor*/ p->name = (char *) NULL; return args; } void _Xi18nInitAttrList (Xi18n i18n_core) { XIMAttr *args; int total_count; /* init IMAttr list */ if (i18n_core->address.xim_attr) XFree ((char *)i18n_core->address.xim_attr); /*endif*/ args = CreateAttrList (i18n_core, Default_IMattr, &total_count); i18n_core->address.im_attr_num = total_count; i18n_core->address.xim_attr = (XIMAttr *)args; /* init ICAttr list */ if (i18n_core->address.xic_attr) XFree ((char *) i18n_core->address.xic_attr); /*endif*/ args = CreateAttrList (i18n_core, Default_ICattr, &total_count); i18n_core->address.ic_attr_num = total_count; i18n_core->address.xic_attr = (XICAttr *) args; } void _Xi18nInitExtension(Xi18n i18n_core) { register int i; IMExtList *extensions = (IMExtList *) Default_Extension; XIMExt *ext_list = (XIMExt *) i18n_core->address.extension; for (i = 0; extensions->name; i++, ext_list++, extensions++) { ext_list->major_opcode = extensions->major_opcode; ext_list->minor_opcode = extensions->minor_opcode; ext_list->name = extensions->name; ext_list->length = strlen(ext_list->name); } /*endfor*/ i18n_core->address.ext_num = i; } xsunpinyin-2.0.3/IMdkit/i18nClbk.c0000644000076400007640000003746411527365010015322 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include "IMdkit.h" #include "Xi18n.h" #include "FrameMgr.h" #include "XimFunc.h" int _Xi18nGeometryCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec geometry_fr[]; register int total_size; unsigned char *reply = NULL; IMGeometryCBStruct *geometry_CB = (IMGeometryCBStruct *) &call_data->geometry_callback; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (geometry_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, geometry_CB->icid); _Xi18nSendMessage (ims, connect_id, XIM_GEOMETRY, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); /* XIM_GEOMETRY is an asyncronous protocol, so return immediately. */ return True; } int _Xi18nPreeditStartCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec preedit_start_fr[]; register int total_size; unsigned char *reply = NULL; IMPreeditCBStruct *preedit_CB = (IMPreeditCBStruct*) &call_data->preedit_callback; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (preedit_start_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, preedit_CB->icid); _Xi18nSendMessage (ims, connect_id, XIM_PREEDIT_START, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); return True; } int _Xi18nPreeditDrawCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec preedit_draw_fr[]; register int total_size; unsigned char *reply = NULL; IMPreeditCBStruct *preedit_CB = (IMPreeditCBStruct *) &call_data->preedit_callback; XIMPreeditDrawCallbackStruct *draw = (XIMPreeditDrawCallbackStruct *) &preedit_CB->todo.draw; CARD16 connect_id = call_data->any.connect_id; register int feedback_count; register int i; BITMASK32 status = 0x0; if (draw->text->length == 0) status = 0x00000001; else if (draw->text->feedback[0] == 0) status = 0x00000002; /*endif*/ fm = FrameMgrInit (preedit_draw_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); /* set length of preedit string */ FrameMgrSetSize (fm, draw->text->length); /* set iteration count for list of feedback */ for (i = 0; draw->text->feedback[i] != 0; i++) ; /*endfor*/ feedback_count = i; FrameMgrSetIterCount (fm, feedback_count); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, preedit_CB->icid); FrameMgrPutToken (fm, draw->caret); FrameMgrPutToken (fm, draw->chg_first); FrameMgrPutToken (fm, draw->chg_length); FrameMgrPutToken (fm, status); FrameMgrPutToken (fm, draw->text->length); FrameMgrPutToken (fm, draw->text->string); for (i = 0; i < feedback_count; i++) FrameMgrPutToken (fm, draw->text->feedback[i]); /*endfor*/ _Xi18nSendMessage (ims, connect_id, XIM_PREEDIT_DRAW, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); /* XIM_PREEDIT_DRAW is an asyncronous protocol, so return immediately. */ return True; } int _Xi18nPreeditCaretCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec preedit_caret_fr[]; register int total_size; unsigned char *reply = NULL; IMPreeditCBStruct *preedit_CB = (IMPreeditCBStruct*) &call_data->preedit_callback; XIMPreeditCaretCallbackStruct *caret = (XIMPreeditCaretCallbackStruct *) &preedit_CB->todo.caret; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (preedit_caret_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, preedit_CB->icid); FrameMgrPutToken (fm, caret->position); FrameMgrPutToken (fm, caret->direction); FrameMgrPutToken (fm, caret->style); _Xi18nSendMessage (ims, connect_id, XIM_PREEDIT_CARET, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); return True; } int _Xi18nPreeditDoneCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec preedit_done_fr[]; register int total_size; unsigned char *reply = NULL; IMPreeditCBStruct *preedit_CB = (IMPreeditCBStruct *) &call_data->preedit_callback; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (preedit_done_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, preedit_CB->icid); _Xi18nSendMessage (ims, connect_id, XIM_PREEDIT_DONE, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); /* XIM_PREEDIT_DONE is an asyncronous protocol, so return immediately. */ return True; } int _Xi18nStatusStartCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec status_start_fr[]; register int total_size; unsigned char *reply = NULL; IMStatusCBStruct *status_CB = (IMStatusCBStruct*) &call_data->status_callback; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (status_start_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, status_CB->icid); _Xi18nSendMessage (ims, connect_id, XIM_STATUS_START, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); /* XIM_STATUS_START is an asyncronous protocol, so return immediately. */ return True; } int _Xi18nStatusDrawCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm = (FrameMgr)0; extern XimFrameRec status_draw_text_fr[]; extern XimFrameRec status_draw_bitmap_fr[]; register int total_size = 0; unsigned char *reply = NULL; IMStatusCBStruct *status_CB = (IMStatusCBStruct *) &call_data->status_callback; XIMStatusDrawCallbackStruct *draw = (XIMStatusDrawCallbackStruct *) &status_CB->todo.draw; CARD16 connect_id = call_data->any.connect_id; register int feedback_count; register int i; BITMASK32 status = 0x0; switch (draw->type) { case XIMTextType: fm = FrameMgrInit (status_draw_text_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); if (draw->data.text->length == 0) status = 0x00000001; else if (draw->data.text->feedback[0] == 0) status = 0x00000002; /*endif*/ /* set length of status string */ FrameMgrSetSize(fm, draw->data.text->length); /* set iteration count for list of feedback */ for (i = 0; draw->data.text->feedback[i] != 0; i++) ; /*endfor*/ feedback_count = i; FrameMgrSetIterCount (fm, feedback_count); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, status_CB->icid); FrameMgrPutToken (fm, draw->type); FrameMgrPutToken (fm, status); FrameMgrPutToken (fm, draw->data.text->length); FrameMgrPutToken (fm, draw->data.text->string); for (i = 0; i < feedback_count; i++) FrameMgrPutToken (fm, draw->data.text->feedback[i]); /*endfor*/ break; case XIMBitmapType: fm = FrameMgrInit (status_draw_bitmap_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, status_CB->icid); FrameMgrPutToken (fm, draw->data.bitmap); break; } /*endswitch*/ _Xi18nSendMessage (ims, connect_id, XIM_STATUS_DRAW, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); /* XIM_STATUS_DRAW is an asyncronous protocol, so return immediately. */ return True; } int _Xi18nStatusDoneCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec status_done_fr[]; register int total_size; unsigned char *reply = NULL; IMStatusCBStruct *status_CB = (IMStatusCBStruct *) &call_data->status_callback; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (status_done_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, status_CB->icid); _Xi18nSendMessage (ims, connect_id, XIM_STATUS_DONE, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); /* XIM_STATUS_DONE is an asyncronous protocol, so return immediately. */ return True; } int _Xi18nStringConversionCallback (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec str_conversion_fr[]; register int total_size; unsigned char *reply = NULL; IMStrConvCBStruct *call_back = (IMStrConvCBStruct *) &call_data->strconv_callback; XIMStringConversionCallbackStruct *strconv = (XIMStringConversionCallbackStruct *) &call_back->strconv; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (str_conversion_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return False; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, connect_id); FrameMgrPutToken (fm, call_back->icid); FrameMgrPutToken (fm, strconv->position); FrameMgrPutToken (fm, strconv->direction); FrameMgrPutToken (fm, strconv->operation); _Xi18nSendMessage (ims, connect_id, XIM_STR_CONVERSION, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); /* XIM_STR_CONVERSION is a syncronous protocol, so should wait here for XIM_STR_CONVERSION_REPLY. */ if (i18n_core->methods.wait (ims, connect_id, XIM_STR_CONVERSION_REPLY, 0) == False) { return False; } /*endif*/ return True; } xsunpinyin-2.0.3/IMdkit/XimProto.h0000644000076400007640000001416111527365010015522 0ustar mikemike/* $XConsortium: XimProto.h,v 1.2 94/01/20 18:02:24 rws Exp $ */ /****************************************************************** Copyright 1992, 1993, 1994 by FUJITSU LIMITED Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of FUJITSU LIMITED not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. FUJITSU LIMITED makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Takashi Fujiwara FUJITSU LIMITED fujiwara@a80.tech.yk.fujitsu.co.jp This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #ifndef _XIMPROTO_H #define _XIMPROTO_H /* * Default Preconnection selection target */ #define XIM_SERVERS "XIM_SERVERS" #define XIM_LOCALES "LOCALES" #define XIM_TRANSPORT "TRANSPORT" /* * categories in XIM_SERVERS */ #define XIM_SERVER_CATEGORY "@server=" #define XIM_LOCAL_CATEGORY "@locale=" #define XIM_TRANSPORT_CATEGORY "@transport=" /* * Xim implementation revision */ #define PROTOCOLMAJORVERSION 0 #define PROTOCOLMINORVERSION 0 /* * Major Protocol number */ #define XIM_CONNECT 1 #define XIM_CONNECT_REPLY 2 #define XIM_DISCONNECT 3 #define XIM_DISCONNECT_REPLY 4 #define XIM_AUTH_REQUIRED 10 #define XIM_AUTH_REPLY 11 #define XIM_AUTH_NEXT 12 #define XIM_AUTH_SETUP 13 #define XIM_AUTH_NG 14 #define XIM_ERROR 20 #define XIM_OPEN 30 #define XIM_OPEN_REPLY 31 #define XIM_CLOSE 32 #define XIM_CLOSE_REPLY 33 #define XIM_REGISTER_TRIGGERKEYS 34 #define XIM_TRIGGER_NOTIFY 35 #define XIM_TRIGGER_NOTIFY_REPLY 36 #define XIM_SET_EVENT_MASK 37 #define XIM_ENCODING_NEGOTIATION 38 #define XIM_ENCODING_NEGOTIATION_REPLY 39 #define XIM_QUERY_EXTENSION 40 #define XIM_QUERY_EXTENSION_REPLY 41 #define XIM_SET_IM_VALUES 42 #define XIM_SET_IM_VALUES_REPLY 43 #define XIM_GET_IM_VALUES 44 #define XIM_GET_IM_VALUES_REPLY 45 #define XIM_CREATE_IC 50 #define XIM_CREATE_IC_REPLY 51 #define XIM_DESTROY_IC 52 #define XIM_DESTROY_IC_REPLY 53 #define XIM_SET_IC_VALUES 54 #define XIM_SET_IC_VALUES_REPLY 55 #define XIM_GET_IC_VALUES 56 #define XIM_GET_IC_VALUES_REPLY 57 #define XIM_SET_IC_FOCUS 58 #define XIM_UNSET_IC_FOCUS 59 #define XIM_FORWARD_EVENT 60 #define XIM_SYNC 61 #define XIM_SYNC_REPLY 62 #define XIM_COMMIT 63 #define XIM_RESET_IC 64 #define XIM_RESET_IC_REPLY 65 #define XIM_GEOMETRY 70 #define XIM_STR_CONVERSION 71 #define XIM_STR_CONVERSION_REPLY 72 #define XIM_PREEDIT_START 73 #define XIM_PREEDIT_START_REPLY 74 #define XIM_PREEDIT_DRAW 75 #define XIM_PREEDIT_CARET 76 #define XIM_PREEDIT_CARET_REPLY 77 #define XIM_PREEDIT_DONE 78 #define XIM_STATUS_START 79 #define XIM_STATUS_DRAW 80 #define XIM_STATUS_DONE 81 /* * values for the flag of XIM_ERROR */ #define XIM_IMID_VALID 0x0001 #define XIM_ICID_VALID 0x0002 /* * XIM Error Code */ #define XIM_BadAlloc 1 #define XIM_BadStyle 2 #define XIM_BadClientWindow 3 #define XIM_BadFocusWindow 4 #define XIM_BadArea 5 #define XIM_BadSpotLocation 6 #define XIM_BadColormap 7 #define XIM_BadAtom 8 #define XIM_BadPixel 9 #define XIM_BadPixmap 10 #define XIM_BadName 11 #define XIM_BadCursor 12 #define XIM_BadProtocol 13 #define XIM_BadForeground 14 #define XIM_BadBackground 15 #define XIM_LocaleNotSupported 16 #define XIM_BadSomething 999 /* * byte order */ #define BIGENDIAN (CARD8) 0x42 /* MSB first */ #define LITTLEENDIAN (CARD8) 0x6c /* LSB first */ /* * values for the type of XIMATTR & XICATTR */ #define XimType_SeparatorOfNestedList 0 #define XimType_CARD8 1 #define XimType_CARD16 2 #define XimType_CARD32 3 #define XimType_STRING8 4 #define XimType_Window 5 #define XimType_XIMStyles 10 #define XimType_XRectangle 11 #define XimType_XPoint 12 #define XimType_XFontSet 13 #define XimType_XIMOptions 14 #define XimType_XIMHotKeyTriggers 15 #define XimType_XIMHotKeyState 16 #define XimType_XIMStringConversion 17 #define XimType_XIMValuesList 18 #define XimType_NEST 0x7FFF /* * values for the category of XIM_ENCODING_NEGOTIATON_REPLY */ #define XIM_Encoding_NameCategory 0 #define XIM_Encoding_DetailCategory 1 /* * value for the index of XIM_ENCODING_NEGOTIATON_REPLY */ #define XIM_Default_Encoding_IDX -1 /* * value for the flag of XIM_FORWARD_EVENT, XIM_COMMIT */ #define XimSYNCHRONUS 0x0001 #define XimLookupChars 0x0002 #define XimLookupKeySym 0x0004 #define XimLookupBoth 0x0006 /* * request packet header size */ #define XIM_HEADER_SIZE \ sizeof(CARD8) /* sizeof mejor-opcode */ \ + sizeof(CARD8) /* sizeof minor-opcode */ \ + sizeof(INT16) /* sizeof length */ /* * Client Message data size */ #define XIM_CM_DATA_SIZE 20 /* * XIM data structure */ typedef CARD16 BITMASK16; typedef CARD32 BITMASK32; typedef CARD32 EVENTMASK; typedef CARD16 XIMID; /* Input Method ID */ typedef CARD16 XICID; /* Input Context ID */ /* * Padding macro */ #define XIM_PAD(length) ((4 - ((length) % 4)) % 4) #define XIM_SET_PAD(ptr, length) \ { \ register int Counter = XIM_PAD((int)length); \ if (Counter) { \ register char *Ptr = (char *)(ptr) + (length); \ length += Counter; \ for (; Counter; --Counter, ++Ptr) \ *Ptr = '\0'; \ } \ } #endif xsunpinyin-2.0.3/IMdkit/IMdkit.h0000644000076400007640000001037311527365010015123 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #ifndef _IMdkit_h #define _IMdkit_h #include #ifdef __cplusplus extern "C" { #endif /* IM Attributes Name */ #define IMModifiers "modifiers" #define IMServerWindow "serverWindow" #define IMServerName "serverName" #define IMServerTransport "serverTransport" #define IMLocale "locale" #define IMInputStyles "inputStyles" #define IMProtocolHandler "protocolHandler" #define IMOnKeysList "onKeysList" #define IMOffKeysList "offKeysList" #define IMEncodingList "encodingList" #define IMFilterEventMask "filterEventMask" #define IMProtocolDepend "protocolDepend" /* Masks for IM Attributes Name */ #define I18N_IMSERVER_WIN 0x0001 /* IMServerWindow */ #define I18N_IM_NAME 0x0002 /* IMServerName */ #define I18N_IM_LOCALE 0x0004 /* IMLocale */ #define I18N_IM_ADDRESS 0x0008 /* IMServerTransport */ #define I18N_INPUT_STYLES 0x0010 /* IMInputStyles */ #define I18N_ON_KEYS 0x0020 /* IMOnKeysList */ #define I18N_OFF_KEYS 0x0040 /* IMOffKeysList */ #define I18N_IM_HANDLER 0x0080 /* IMProtocolHander */ #define I18N_ENCODINGS 0x0100 /* IMEncodingList */ #define I18N_FILTERMASK 0x0200 /* IMFilterEventMask */ #define I18N_PROTO_DEPEND 0x0400 /* IMProtoDepend */ typedef struct { char *name; XPointer value; } XIMArg; typedef struct { CARD32 keysym; CARD32 modifier; CARD32 modifier_mask; } XIMTriggerKey; typedef struct { unsigned short count_keys; XIMTriggerKey *keylist; } XIMTriggerKeys; typedef char *XIMEncoding; typedef struct { unsigned short count_encodings; XIMEncoding *supported_encodings; } XIMEncodings; typedef struct _XIMS *XIMS; typedef struct { void* (*setup) (Display *, XIMArg *); Status (*openIM) (XIMS); Status (*closeIM) (XIMS); char* (*setIMValues) (XIMS, XIMArg *); char* (*getIMValues) (XIMS, XIMArg *); Status (*forwardEvent) (XIMS, XPointer); Status (*commitString) (XIMS, XPointer); int (*callCallback) (XIMS, XPointer); int (*preeditStart) (XIMS, XPointer); int (*preeditEnd) (XIMS, XPointer); int (*syncXlib) (XIMS, XPointer); } IMMethodsRec, *IMMethods; typedef struct { Display *display; int screen; } IMCoreRec, *IMCore; typedef struct _XIMS { IMMethods methods; IMCoreRec core; Bool sync; void *protocol; } XIMProtocolRec; /* * X function declarations. */ extern XIMS IMOpenIM (Display *, ...); extern Status IMCloseIM (XIMS); extern char *IMSetIMValues (XIMS, ...); extern char *IMGetIMValues (XIMS, ...); void IMForwardEvent (XIMS, XPointer); void IMCommitString (XIMS, XPointer); int IMCallCallback (XIMS, XPointer); int IMPreeditStart (XIMS, XPointer); int IMPreeditEnd (XIMS, XPointer); int IMSyncXlib (XIMS, XPointer); #ifdef __cplusplus } #endif #endif /* IMdkit_h */ xsunpinyin-2.0.3/IMdkit/i18nIMProto.c0000644000076400007640000004762011527365010015773 0ustar mikemike/****************************************************************** Copyright 1993, 1994 by Digital Equipment Corporation, Maynard, Massachusetts, Copyright 1993, 1994 by Hewlett-Packard Company Copyright 1994, 1995 by Sun Microsystems, Inc. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Digital or MIT not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. DIGITAL AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL DIGITAL AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hiroyuki Miyamoto Digital Equipment Corporation miyamoto@jrd.dec.com Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ /* Protocol Packet frames */ #include "FrameMgr.h" /* Data type definitions */ static XimFrameRec ximattr_fr[] = { _FRAME(BIT16), /* attribute ID */ _FRAME(BIT16), /* type of the value */ _FRAME(BIT16), /* length of im-attribute */ _FRAME(BARRAY), /* im-attribute */ _PAD4(2), _FRAME(EOL), }; static XimFrameRec xicattr_fr[] = { _FRAME(BIT16), /* attribute ID */ _FRAME(BIT16), /* type of the value */ _FRAME(BIT16), /* length of ic-attribute */ _FRAME(BARRAY), /* ic-attribute */ _PAD4(2), _FRAME(EOL), }; static XimFrameRec ximattribute_fr[] = { _FRAME(BIT16), /* attribute ID */ _FRAME(BIT16), /* value length */ _FRAME(BARRAY), /* value */ _PAD4(1), _FRAME(EOL), }; static XimFrameRec xicattribute_fr[] = { _FRAME(BIT16), /* attribute ID */ _FRAME(BIT16), /* value length */ _FRAME(BARRAY), /* value */ _PAD4(1), _FRAME(EOL), }; static XimFrameRec ximtriggerkey_fr[] = { _FRAME(BIT32), /* keysym */ _FRAME(BIT32), /* modifier */ _FRAME(BIT32), /* modifier mask */ _FRAME(EOL), }; static XimFrameRec encodinginfo_fr[] = { _FRAME(BIT16), /* length of encoding info */ _FRAME(BARRAY), /* encoding info */ _PAD4(2), _FRAME(EOL), }; static XimFrameRec str_fr[] = { _FRAME(BIT8), /* number of byte */ _FRAME(BARRAY), /* string */ _FRAME(EOL), }; static XimFrameRec xpcs_fr[] = { _FRAME(BIT16), /* length of string in bytes */ _FRAME(BARRAY), /* string */ _PAD4(2), }; static XimFrameRec ext_fr[] = { _FRAME(BIT8), /* extension major-opcode */ _FRAME(BIT8), /* extension minor-opcode */ _FRAME(BIT16), /* length of extension name */ _FRAME(BARRAY), /* extension name */ _PAD4(1), _FRAME(EOL), }; static XimFrameRec inputstyle_fr[] = { _FRAME(BIT32), /* inputstyle */ _FRAME(EOL), }; /* Protocol definitions */ xim_externaldef XimFrameRec attr_head_fr[] = { _FRAME(BIT16), /* attribute id */ _FRAME(BIT16), /* attribute length */ _FRAME(EOL), }; xim_externaldef XimFrameRec short_fr[] = { _FRAME(BIT16), /* value */ _FRAME(EOL), }; xim_externaldef XimFrameRec long_fr[] = { _FRAME(BIT32), /* value */ _FRAME(EOL), }; xim_externaldef XimFrameRec xrectangle_fr[] = { _FRAME(BIT16), /* x */ _FRAME(BIT16), /* y */ _FRAME(BIT16), /* width */ _FRAME(BIT16), /* height */ _FRAME(EOL), }; xim_externaldef XimFrameRec xpoint_fr[] = { _FRAME(BIT16), /* x */ _FRAME(BIT16), /* y */ _FRAME(EOL), }; xim_externaldef XimFrameRec fontset_fr[] = { _FRAME(BIT16), /* length of base font name */ _FRAME(BARRAY), /* base font name list */ _PAD4(2), /* unused */ _FRAME(EOL), }; xim_externaldef XimFrameRec input_styles_fr[] = { _FRAME(BIT16), /* number of list */ _PAD4(1), /* unused */ _FRAME(ITER), /* XIMStyle list */ _FRAME(POINTER), _PTR(inputstyle_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec packet_header_fr[] = { _FRAME(BIT8), /* major-opcode */ _FRAME(BIT8), /* minor-opcode */ _FRAME(BIT16), /* length */ _FRAME(EOL), }; xim_externaldef XimFrameRec error_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* flag */ _FRAME(BIT16), /* Error Code */ _FRAME(BIT16), /* length of error detail */ _FRAME(BIT16), /* type of error detail */ _FRAME(BARRAY), /* error detail */ _PAD4(1), _FRAME(EOL), }; xim_externaldef XimFrameRec connect_fr[] = { _FRAME(BIT8), /* byte order */ _PAD2(1), /* unused */ _FRAME(BIT16), /* client-major-protocol-version */ _FRAME(BIT16), /* client-minor-protocol-version */ _BYTE_COUNTER(BIT16, 1), /* length of client-auth-protocol-names */ _FRAME(ITER), /* client-auth-protocol-names */ _FRAME(POINTER), _PTR(xpcs_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec connect_reply_fr[] = { _FRAME(BIT16), /* server-major-protocol-version */ _FRAME(BIT16), /* server-minor-protocol-version */ _FRAME(EOL), }; xim_externaldef XimFrameRec auth_required_fr[] = { _FRAME(BIT8), /* auth-protocol-index */ _FRAME(BIT8), /* auth-data1 */ _FRAME(BARRAY), /* auth-data2 */ _PAD4(3), _FRAME(EOL), }; xim_externaldef XimFrameRec auth_reply_fr[] = { _FRAME(BIT8), _FRAME(BARRAY), _PAD4(2), _FRAME(EOL), }; xim_externaldef XimFrameRec auth_next_fr[] = { _FRAME(BIT8), /* auth-data1 */ _FRAME(BARRAY), /* auth-data2 */ _PAD4(2), _FRAME(EOL), }; xim_externaldef XimFrameRec auth_setup_fr[] = { _BYTE_COUNTER(BIT16, 2), /* number of client-auth-protocol-names */ _PAD4(1), /* unused */ _FRAME(ITER), /* server-auth-protocol-names */ _FRAME(POINTER), _PTR(xpcs_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec auth_ng_fr[] = { _FRAME(EOL), }; xim_externaldef XimFrameRec disconnect_fr[] = { _FRAME(EOL), }; xim_externaldef XimFrameRec disconnect_reply_fr[] = { _FRAME(EOL), }; xim_externaldef XimFrameRec open_fr[] = { _FRAME(POINTER), /* locale name */ _PTR(str_fr), _PAD4(1), _FRAME(EOL), }; xim_externaldef XimFrameRec open_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of IM attributes supported */ _FRAME(ITER), /* IM attribute supported */ _FRAME(POINTER), _PTR(ximattr_fr), _BYTE_COUNTER(BIT16, 2), /* number of IC attribute supported */ _PAD4(1), /* unused */ _FRAME(ITER), /* IC attribute supported */ _FRAME(POINTER), _PTR(xicattr_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec close_fr[] = { _FRAME(BIT16), /* input-method-ID */ _PAD4(1), /* unused */ _FRAME(EOL), }; xim_externaldef XimFrameRec close_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _PAD4(1), /* unused */ _FRAME(EOL), }; xim_externaldef XimFrameRec register_triggerkeys_fr[] = { _FRAME(BIT16), /* input-method-ID */ _PAD4(1), /* unused */ _BYTE_COUNTER(BIT32, 1), /* byte length of on-keys */ _FRAME(ITER), /* on-keys list */ _FRAME(POINTER), _PTR(ximtriggerkey_fr), _BYTE_COUNTER(BIT32, 1), /* byte length of off-keys */ _FRAME(ITER), /* off-keys list */ _FRAME(POINTER), _PTR(ximtriggerkey_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec trigger_notify_fr[] = { _FRAME(BIT16), /* input-mehotd-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* flag */ _FRAME(BIT32), /* index of keys list */ _FRAME(BIT32), /* client-select-event-mask */ _FRAME(EOL), }; xim_externaldef XimFrameRec trigger_notify_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec set_event_mask_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* forward-event-mask */ _FRAME(BIT32), /* synchronous-event-mask */ _FRAME(EOL), }; xim_externaldef XimFrameRec encoding_negotiation_fr[] = { _FRAME(BIT16), /* input-method-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of encodings listed by name */ _FRAME(ITER), /* supported list of encoding in IM library */ _FRAME(POINTER), _PTR(str_fr), _PAD4(1), _BYTE_COUNTER(BIT16, 2), /* byte length of encodings listed by detailed data */ _PAD4(1), _FRAME(ITER), /* list of encodings supported in the IM library */ _FRAME(POINTER), _PTR(encodinginfo_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec encoding_negotiation_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* category of the encoding determined */ _FRAME(BIT16), /* index of the encoding dterminated */ _PAD4(1), _FRAME(EOL), }; xim_externaldef XimFrameRec query_extension_fr[] = { _FRAME(BIT16), /* input-method-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of extensions supported by the IM library */ _FRAME(ITER), /* extensions supported by the IM library */ _FRAME(POINTER), _PTR(str_fr), _PAD4(1), _FRAME(EOL), }; xim_externaldef XimFrameRec query_extension_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of extensions supported by the IM server */ _FRAME(ITER), /* list of extensions supported by the IM server */ _FRAME(POINTER), _PTR(ext_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec get_im_values_fr[] = { _FRAME(BIT16), /* input-method-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of im-attribute-id */ _FRAME(ITER), /* im-attribute-id */ _FRAME(BIT16), _PAD4(1), _FRAME(EOL), }; xim_externaldef XimFrameRec get_im_values_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of im-attribute returned */ _FRAME(ITER), /* im-attribute returned */ _FRAME(POINTER), _PTR(ximattribute_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec create_ic_fr[] = { _FRAME(BIT16), /* input-method-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of ic-attributes */ _FRAME(ITER), /* ic-attributes */ _FRAME(POINTER), _PTR(xicattribute_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec create_ic_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec destroy_ic_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec destroy_ic_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec set_ic_values_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _BYTE_COUNTER(BIT16, 2), /* byte length of ic-attributes */ _PAD4(1), _FRAME(ITER), /* ic-attribute */ _FRAME(POINTER), _PTR(xicattribute_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec set_ic_values_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec get_ic_values_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _BYTE_COUNTER(BIT16, 1), /* byte length of ic-attribute-id */ _FRAME(ITER), /* ic-attribute */ _FRAME(BIT16), _PAD4(2), _FRAME(EOL), }; xim_externaldef XimFrameRec get_ic_values_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _BYTE_COUNTER(BIT16, 2), /* byte length of ic-attribute */ _PAD4(1), _FRAME(ITER), /* ic-attribute */ _FRAME(POINTER), _PTR(xicattribute_fr), _FRAME(EOL), }; xim_externaldef XimFrameRec set_ic_focus_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec unset_ic_focus_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec forward_event_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* flag */ _FRAME(BIT16), /* sequence number */ _FRAME(EOL), }; xim_externaldef XimFrameRec wire_keyevent_fr[] = { _FRAME(BIT8), /* type */ _FRAME(BIT8), /* detail */ _FRAME(BIT16), /* serial number */ _FRAME(BIT32), /* time */ _FRAME(BIT32), /* root */ _FRAME(BIT32), /* window */ _FRAME(BIT32), /* subwindow */ _FRAME(BIT16), /* rootX */ _FRAME(BIT16), /* rootY */ _FRAME(BIT16), /* X */ _FRAME(BIT16), /* Y */ _FRAME(BIT16), /* state */ _FRAME(BIT8), /* sameScreen */ _FRAME(EOL), }; xim_externaldef XimFrameRec sync_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec sync_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; #if 0 xim_externaldef XimFrameRec commit_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* flag */ _FRAME(BIT16), /* byte length of committed string */ _FRAME(BARRAY), /* committed string */ _PAD4(1), _BYTE_COUNTER(BIT16, 1), /* byte length of keysym */ _FRAME(ITER), /* keysym */ _FRAME(BIT32), _PAD4(1), _FRAME(EOL), }; #endif xim_externaldef XimFrameRec commit_chars_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* flag */ _FRAME(BIT16), /* byte length of committed string */ _FRAME(BARRAY), /* committed string */ _PAD4(1), _FRAME(EOL), }; xim_externaldef XimFrameRec commit_both_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* flag */ _PAD4(1), /* unused */ _FRAME(BIT32), /* keysym */ _FRAME(BIT16), /* byte length of committed string */ _FRAME(BARRAY), /* committed string */ _PAD4(2), _FRAME(EOL), }; xim_externaldef XimFrameRec reset_ic_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec reset_ic_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* byte length of committed string */ _FRAME(BARRAY), /* committed string */ _PAD4(2), _FRAME(EOL), }; xim_externaldef XimFrameRec geometry_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec str_conversion_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* XIMStringConversionPosition */ _FRAME(BIT32), /* XIMStringConversionType */ _FRAME(BIT32), /* XIMStringConversionOperation */ _FRAME(BIT16), /* length to multiply the XIMStringConversionType */ _FRAME(BIT16), /* length of the string to be substituted */ #if 0 _FRAME(BARRAY), /* string */ _PAD4(1), #endif _FRAME(EOL), }; xim_externaldef XimFrameRec str_conversion_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* XIMStringConversionFeedback */ _FRAME(BIT16), /* length of the retrieved string */ _FRAME(BARRAY), /* retrieved string */ _PAD4(2), _BYTE_COUNTER(BIT16, 2), /* number of feedback array */ _PAD4(1), _FRAME(ITER), /* feedback array */ _FRAME(BIT32), _FRAME(EOL), }; xim_externaldef XimFrameRec preedit_start_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec preedit_start_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* return value */ _FRAME(EOL), }; xim_externaldef XimFrameRec preedit_draw_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* caret */ _FRAME(BIT32), /* chg_first */ _FRAME(BIT32), /* chg_length */ _FRAME(BIT32), /* status */ _FRAME(BIT16), /* length of preedit string */ _FRAME(BARRAY), /* preedit string */ _PAD4(2), _BYTE_COUNTER(BIT16, 2), /* number of feedback array */ _PAD4(1), _FRAME(ITER), /* feedback array */ _FRAME(BIT32), _FRAME(EOL), }; xim_externaldef XimFrameRec preedit_caret_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* position */ _FRAME(BIT32), /* direction */ _FRAME(BIT32), /* style */ _FRAME(EOL), }; xim_externaldef XimFrameRec preedit_caret_reply_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* position */ _FRAME(EOL), }; xim_externaldef XimFrameRec preedit_done_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec status_start_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec status_draw_text_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* type */ _FRAME(BIT32), /* status */ _FRAME(BIT16), /* length of status string */ _FRAME(BARRAY), /* status string */ _PAD4(2), _BYTE_COUNTER(BIT16, 2), /* number of feedback array */ _PAD4(1), _FRAME(ITER), /* feedback array */ _FRAME(BIT32), _FRAME(EOL), }; xim_externaldef XimFrameRec status_draw_bitmap_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* type */ _FRAME(BIT32), /* pixmap data */ _FRAME(EOL), }; xim_externaldef XimFrameRec status_done_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(EOL), }; xim_externaldef XimFrameRec ext_set_event_mask_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT32), /* filter-event-mask */ _FRAME(BIT32), /* intercept-event-mask */ _FRAME(BIT32), /* select-event-mask */ _FRAME(BIT32), /* forward-event-mask */ _FRAME(BIT32), /* synchronous-event-mask */ _FRAME(EOL), }; xim_externaldef XimFrameRec ext_forward_keyevent_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* flag */ _FRAME(BIT16), /* sequence number */ _FRAME(BIT8), /* xEvent.u.u.type */ _FRAME(BIT8), /* keycode */ _FRAME(BIT16), /* state */ _FRAME(BIT32), /* time */ _FRAME(BIT32), /* window */ _FRAME(EOL), }; xim_externaldef XimFrameRec ext_move_fr[] = { _FRAME(BIT16), /* input-method-ID */ _FRAME(BIT16), /* input-context-ID */ _FRAME(BIT16), /* X */ _FRAME(BIT16), /* Y */ _FRAME(EOL), }; xsunpinyin-2.0.3/IMdkit/i18nPtHdr.c0000644000076400007640000015112711527365010015461 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include #include #ifndef NEED_EVENTS #define NEED_EVENTS #endif #include #undef NEED_EVENTS #include "FrameMgr.h" #include "IMdkit.h" #include "Xi18n.h" #include "XimFunc.h" #ifdef XIM_DEBUG #include static void DebugLog(char * msg) { fprintf(stderr, msg); } #endif extern Xi18nClient *_Xi18nFindClient (Xi18n, CARD16); static void GetProtocolVersion (CARD16 client_major, CARD16 client_minor, CARD16 *server_major, CARD16 *server_minor) { *server_major = client_major; *server_minor = client_minor; } static void ConnectMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec connect_fr[], connect_reply_fr[]; register int total_size; CARD16 server_major_version, server_minor_version; unsigned char *reply = NULL; IMConnectStruct *imconnect = (IMConnectStruct*) &call_data->imconnect; CARD16 connect_id = call_data->any.connect_id; fm = FrameMgrInit (connect_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, imconnect->byte_order); FrameMgrGetToken (fm, imconnect->major_version); FrameMgrGetToken (fm, imconnect->minor_version); FrameMgrFree (fm); GetProtocolVersion (imconnect->major_version, imconnect->minor_version, &server_major_version, &server_minor_version); #ifdef PROTOCOL_RICH if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ #endif /* PROTOCOL_RICH */ fm = FrameMgrInit (connect_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, server_major_version); FrameMgrPutToken (fm, server_minor_version); _Xi18nSendMessage (ims, connect_id, XIM_CONNECT_REPLY, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); } static void DisConnectMessageProc (XIMS ims, IMProtocol *call_data) { Xi18n i18n_core = ims->protocol; unsigned char *reply = NULL; CARD16 connect_id = call_data->any.connect_id; #ifdef PROTOCOL_RICH if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ #endif /* PROTOCOL_RICH */ _Xi18nSendMessage (ims, connect_id, XIM_DISCONNECT_REPLY, 0, reply, 0); i18n_core->methods.disconnect (ims, connect_id); } static void OpenMessageProc(XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec open_fr[]; extern XimFrameRec open_reply_fr[]; unsigned char *reply = NULL; int str_size; register int i, total_size; CARD16 connect_id = call_data->any.connect_id; int str_length; char *name; IMOpenStruct *imopen = (IMOpenStruct *) &call_data->imopen; fm = FrameMgrInit (open_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, str_length); FrameMgrSetSize (fm, str_length); FrameMgrGetToken (fm, name); imopen->lang.length = str_length; imopen->lang.name = malloc (str_length + 1); strncpy (imopen->lang.name, name, str_length); imopen->lang.name[str_length] = (char) 0; FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ if ((i18n_core->address.imvalue_mask & I18N_ON_KEYS) || (i18n_core->address.imvalue_mask & I18N_OFF_KEYS)) { _Xi18nSendTriggerKey (ims, connect_id); } /*endif*/ XFree (imopen->lang.name); fm = FrameMgrInit (open_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); /* set iteration count for list of imattr */ FrameMgrSetIterCount (fm, i18n_core->address.im_attr_num); /* set length of BARRAY item in ximattr_fr */ for (i = 0; i < i18n_core->address.im_attr_num; i++) { str_size = strlen (i18n_core->address.xim_attr[i].name); FrameMgrSetSize (fm, str_size); } /*endfor*/ /* set iteration count for list of icattr */ FrameMgrSetIterCount (fm, i18n_core->address.ic_attr_num); /* set length of BARRAY item in xicattr_fr */ for (i = 0; i < i18n_core->address.ic_attr_num; i++) { str_size = strlen (i18n_core->address.xic_attr[i].name); FrameMgrSetSize (fm, str_size); } /*endfor*/ total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); /* input input-method ID */ FrameMgrPutToken (fm, connect_id); for (i = 0; i < i18n_core->address.im_attr_num; i++) { str_size = FrameMgrGetSize (fm); FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].attribute_id); FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].type); FrameMgrPutToken (fm, str_size); FrameMgrPutToken (fm, i18n_core->address.xim_attr[i].name); } /*endfor*/ for (i = 0; i < i18n_core->address.ic_attr_num; i++) { str_size = FrameMgrGetSize (fm); FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].attribute_id); FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].type); FrameMgrPutToken (fm, str_size); FrameMgrPutToken (fm, i18n_core->address.xic_attr[i].name); } /*endfor*/ _Xi18nSendMessage (ims, connect_id, XIM_OPEN_REPLY, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); } static void CloseMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec close_fr[]; extern XimFrameRec close_reply_fr[]; unsigned char *reply = NULL; register int total_size; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (close_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); FrameMgrGetToken (fm, input_method_ID); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ fm = FrameMgrInit (close_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); _Xi18nSendMessage (ims, connect_id, XIM_CLOSE_REPLY, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); } static XIMExt *MakeExtensionList (Xi18n i18n_core, XIMStr *lib_extension, int number, int *reply_number) { XIMExt *ext_list; XIMExt *im_ext = (XIMExt *) i18n_core->address.extension; int im_ext_len = i18n_core->address.ext_num; int i; int j; *reply_number = 0; if (number == 0) { /* query all extensions */ *reply_number = im_ext_len; } else { for (i = 0; i < im_ext_len; i++) { for (j = 0; j < (int) number; j++) { if (strcmp (lib_extension[j].name, im_ext[i].name) == 0) { (*reply_number)++; break; } /*endif*/ } /*endfor*/ } /*endfor*/ } /*endif*/ if (!(*reply_number)) return NULL; /*endif*/ ext_list = (XIMExt *) malloc (sizeof (XIMExt)*(*reply_number)); if (!ext_list) return NULL; /*endif*/ memset (ext_list, 0, sizeof (XIMExt)*(*reply_number)); if (number == 0) { /* query all extensions */ for (i = 0; i < im_ext_len; i++) { ext_list[i].major_opcode = im_ext[i].major_opcode; ext_list[i].minor_opcode = im_ext[i].minor_opcode; ext_list[i].length = im_ext[i].length; ext_list[i].name = malloc (im_ext[i].length + 1); strcpy (ext_list[i].name, im_ext[i].name); } /*endfor*/ } else { int n = 0; for (i = 0; i < im_ext_len; i++) { for (j = 0; j < (int)number; j++) { if (strcmp (lib_extension[j].name, im_ext[i].name) == 0) { ext_list[n].major_opcode = im_ext[i].major_opcode; ext_list[n].minor_opcode = im_ext[i].minor_opcode; ext_list[n].length = im_ext[i].length; ext_list[n].name = malloc (im_ext[i].length + 1); strcpy (ext_list[n].name, im_ext[i].name); n++; break; } /*endif*/ } /*endfor*/ } /*endfor*/ } /*endif*/ return ext_list; } static void QueryExtensionMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; FmStatus status; extern XimFrameRec query_extension_fr[]; extern XimFrameRec query_extension_reply_fr[]; unsigned char *reply = NULL; int str_size; register int i; register int number; register int total_size; int byte_length; int reply_number = 0; XIMExt *ext_list; IMQueryExtensionStruct *query_ext = (IMQueryExtensionStruct *) &call_data->queryext; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (query_extension_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, byte_length); query_ext->extension = (XIMStr *) malloc (sizeof (XIMStr)*10); memset (query_ext->extension, 0, sizeof (XIMStr)*10); number = 0; while (FrameMgrIsIterLoopEnd (fm, &status) == False) { char *name; int str_length; FrameMgrGetToken (fm, str_length); FrameMgrSetSize (fm, str_length); query_ext->extension[number].length = str_length; FrameMgrGetToken (fm, name); query_ext->extension[number].name = malloc (str_length + 1); strncpy (query_ext->extension[number].name, name, str_length); query_ext->extension[number].name[str_length] = (char) 0; number++; } /*endwhile*/ query_ext->number = number; #ifdef PROTOCOL_RICH if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ #endif /* PROTOCOL_RICH */ FrameMgrFree (fm); ext_list = MakeExtensionList (i18n_core, query_ext->extension, number, &reply_number); for (i = 0; i < number; i++) XFree (query_ext->extension[i].name); /*endfor*/ XFree (query_ext->extension); fm = FrameMgrInit (query_extension_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); /* set iteration count for list of extensions */ FrameMgrSetIterCount (fm, reply_number); /* set length of BARRAY item in ext_fr */ for (i = 0; i < reply_number; i++) { str_size = strlen (ext_list[i].name); FrameMgrSetSize (fm, str_size); } /*endfor*/ total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); for (i = 0; i < reply_number; i++) { str_size = FrameMgrGetSize (fm); FrameMgrPutToken (fm, ext_list[i].major_opcode); FrameMgrPutToken (fm, ext_list[i].minor_opcode); FrameMgrPutToken (fm, str_size); FrameMgrPutToken (fm, ext_list[i].name); } /*endfor*/ _Xi18nSendMessage (ims, connect_id, XIM_QUERY_EXTENSION_REPLY, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); for (i = 0; i < reply_number; i++) XFree (ext_list[i].name); /*endfor*/ XFree ((char *) ext_list); } static void SyncReplyMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec sync_reply_fr[]; CARD16 connect_id = call_data->any.connect_id; Xi18nClient *client; CARD16 input_method_ID; CARD16 input_context_ID; client = (Xi18nClient *)_Xi18nFindClient (i18n_core, connect_id); fm = FrameMgrInit (sync_reply_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, input_context_ID); FrameMgrFree (fm); client->sync = False; if (ims->sync == True) { ims->sync = False; if (i18n_core->address.improto) { call_data->sync_xlib.major_code = XIM_SYNC_REPLY; call_data->sync_xlib.minor_code = 0; call_data->sync_xlib.connect_id = input_method_ID; call_data->sync_xlib.icid = input_context_ID; i18n_core->address.improto(ims, call_data); } } } static void GetIMValueFromName (Xi18n i18n_core, CARD16 connect_id, char *buf, char *name, int *length) { register int i; if (strcmp (name, XNQueryInputStyle) == 0) { XIMStyles *styles = (XIMStyles *) &i18n_core->address.input_styles; *length = sizeof (CARD16)*2; /* count_styles, unused */ *length += styles->count_styles*sizeof (CARD32); if (buf != NULL) { FrameMgr fm; extern XimFrameRec input_styles_fr[]; unsigned char *data = NULL; int total_size; fm = FrameMgrInit (input_styles_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); /* set iteration count for list of input_style */ FrameMgrSetIterCount (fm, styles->count_styles); total_size = FrameMgrGetTotalSize (fm); data = (unsigned char *) malloc (total_size); if (!data) return; /*endif*/ memset (data, 0, total_size); FrameMgrSetBuffer (fm, data); FrameMgrPutToken (fm, styles->count_styles); for (i = 0; i < (int) styles->count_styles; i++) FrameMgrPutToken (fm, styles->supported_styles[i]); /*endfor*/ memmove (buf, data, total_size); FrameMgrFree (fm); /* ADDED BY SUZHE */ free (data); /* ADDED BY SUZHE */ } /*endif*/ } /*endif*/ else if (strcmp (name, XNQueryIMValuesList) == 0) { } } static XIMAttribute *MakeIMAttributeList (Xi18n i18n_core, CARD16 connect_id, CARD16 *list, int *number, int *length) { XIMAttribute *attrib_list; int list_num; XIMAttr *attr = i18n_core->address.xim_attr; int list_len = i18n_core->address.im_attr_num; register int i; register int j; int value_length; int number_ret = 0; *length = 0; list_num = 0; for (i = 0; i < *number; i++) { for (j = 0; j < list_len; j++) { if (attr[j].attribute_id == list[i]) { list_num++; break; } /*endif*/ } /*endfor*/ } /*endfor*/ attrib_list = (XIMAttribute *) malloc (sizeof (XIMAttribute)*list_num); if (!attrib_list) return NULL; /*endif*/ memset (attrib_list, 0, sizeof (XIMAttribute)*list_num); number_ret = list_num; list_num = 0; for (i = 0; i < *number; i++) { for (j = 0; j < list_len; j++) { if (attr[j].attribute_id == list[i]) { attrib_list[list_num].attribute_id = attr[j].attribute_id; attrib_list[list_num].name_length = attr[j].length; attrib_list[list_num].name = attr[j].name; attrib_list[list_num].type = attr[j].type; GetIMValueFromName (i18n_core, connect_id, NULL, attr[j].name, &value_length); attrib_list[list_num].value_length = value_length; attrib_list[list_num].value = (void *) malloc (value_length); memset(attrib_list[list_num].value, 0, value_length); GetIMValueFromName (i18n_core, connect_id, attrib_list[list_num].value, attr[j].name, &value_length); *length += sizeof (CARD16)*2; *length += value_length; *length += IMPAD (value_length); list_num++; break; } /*endif*/ } /*endfor*/ } /*endfor*/ *number = number_ret; return attrib_list; } static void GetIMValuesMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; FmStatus status; extern XimFrameRec get_im_values_fr[]; extern XimFrameRec get_im_values_reply_fr[]; CARD16 byte_length; int list_len, total_size; unsigned char *reply = NULL; int iter_count; register int i; register int j; int number; CARD16 *im_attrID_list; char **name_list; CARD16 name_number; XIMAttribute *im_attribute_list; IMGetIMValuesStruct *getim = (IMGetIMValuesStruct *)&call_data->getim; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; /* create FrameMgr */ fm = FrameMgrInit (get_im_values_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, byte_length); im_attrID_list = (CARD16 *) malloc (sizeof (CARD16)*20); memset (im_attrID_list, 0, sizeof (CARD16)*20); name_list = (char **)malloc(sizeof(char *) * 20); memset(name_list, 0, sizeof(char *) * 20); number = 0; while (FrameMgrIsIterLoopEnd (fm, &status) == False) { FrameMgrGetToken (fm, im_attrID_list[number]); number++; } FrameMgrFree (fm); name_number = 0; for (i = 0; i < number; i++) { for (j = 0; j < i18n_core->address.im_attr_num; j++) { if (i18n_core->address.xim_attr[j].attribute_id == im_attrID_list[i]) { name_list[name_number++] = i18n_core->address.xim_attr[j].name; break; } } } getim->number = name_number; getim->im_attr_list = name_list; XFree (name_list); #ifdef PROTOCOL_RICH if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; } #endif /* PROTOCOL_RICH */ im_attribute_list = MakeIMAttributeList (i18n_core, connect_id, im_attrID_list, &number, &list_len); if (im_attrID_list) XFree (im_attrID_list); /*endif*/ fm = FrameMgrInit (get_im_values_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); iter_count = number; /* set iteration count for list of im_attribute */ FrameMgrSetIterCount (fm, iter_count); /* set length of BARRAY item in ximattribute_fr */ for (i = 0; i < iter_count; i++) FrameMgrSetSize (fm, im_attribute_list[i].value_length); /*endfor*/ total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); for (i = 0; i < iter_count; i++) { FrameMgrPutToken (fm, im_attribute_list[i].attribute_id); FrameMgrPutToken (fm, im_attribute_list[i].value_length); FrameMgrPutToken (fm, im_attribute_list[i].value); } /*endfor*/ _Xi18nSendMessage (ims, connect_id, XIM_GET_IM_VALUES_REPLY, 0, reply, total_size); FrameMgrFree (fm); XFree (reply); for (i = 0; i < iter_count; i++) XFree(im_attribute_list[i].value); XFree (im_attribute_list); } static void CreateICMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { _Xi18nChangeIC (ims, call_data, p, True); } static void SetICValuesMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { _Xi18nChangeIC (ims, call_data, p, False); } static void GetICValuesMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { _Xi18nGetIC (ims, call_data, p); } static void SetICFocusMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec set_ic_focus_fr[]; IMChangeFocusStruct *setfocus; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; setfocus = (IMChangeFocusStruct *) &call_data->changefocus; fm = FrameMgrInit (set_ic_focus_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, setfocus->icid); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ } static void UnsetICFocusMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec unset_ic_focus_fr[]; IMChangeFocusStruct *unsetfocus; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; unsetfocus = (IMChangeFocusStruct *) &call_data->changefocus; fm = FrameMgrInit (unset_ic_focus_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, unsetfocus->icid); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ } static void DestroyICMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec destroy_ic_fr[]; extern XimFrameRec destroy_ic_reply_fr[]; register int total_size; unsigned char *reply = NULL; IMDestroyICStruct *destroy = (IMDestroyICStruct *) &call_data->destroyic; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (destroy_ic_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, destroy->icid); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ fm = FrameMgrInit (destroy_ic_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); FrameMgrPutToken (fm, destroy->icid); _Xi18nSendMessage (ims, connect_id, XIM_DESTROY_IC_REPLY, 0, reply, total_size); XFree(reply); FrameMgrFree (fm); } static void ResetICMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec reset_ic_fr[]; extern XimFrameRec reset_ic_reply_fr[]; register int total_size; unsigned char *reply = NULL; IMResetICStruct *resetic = (IMResetICStruct *) &call_data->resetic; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (reset_ic_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, resetic->icid); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ /* create FrameMgr */ fm = FrameMgrInit (reset_ic_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); /* set length of STRING8 */ FrameMgrSetSize (fm, resetic->length); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); FrameMgrPutToken (fm, resetic->icid); FrameMgrPutToken(fm, resetic->length); FrameMgrPutToken (fm, resetic->commit_string); _Xi18nSendMessage (ims, connect_id, XIM_RESET_IC_REPLY, 0, reply, total_size); FrameMgrFree (fm); XFree(reply); } static int WireEventToEvent (Xi18n i18n_core, xEvent *event, CARD16 serial, XEvent *ev, Bool byte_swap) { FrameMgr fm; extern XimFrameRec wire_keyevent_fr[]; BYTE b; CARD16 c16; CARD32 c32; int ret = False; /* create FrameMgr */ fm = FrameMgrInit(wire_keyevent_fr, (char *)(&(event->u)), byte_swap); /* get & set type */ FrameMgrGetToken(fm, b); ev->type = (unsigned int)b; /* get detail */ FrameMgrGetToken(fm, b); /* get & set serial */ FrameMgrGetToken(fm, c16); ev->xany.serial = (unsigned long)c16; ev->xany.serial |= serial << 16; ev->xany.send_event = False; ev->xany.display = i18n_core->address.dpy; /* Remove SendEvent flag from event type to emulate KeyPress/Release */ ev->type &= 0x7F; switch (ev->type) { case KeyPress: case KeyRelease: { XKeyEvent *kev = (XKeyEvent*)ev; /* set keycode (detail) */ kev->keycode = (unsigned int)b; /* get & set values */ FrameMgrGetToken(fm, c32); kev->time = (Time)c32; FrameMgrGetToken(fm, c32); kev->root = (Window)c32; FrameMgrGetToken(fm, c32); kev->window = (Window)c32; FrameMgrGetToken(fm, c32); kev->subwindow = (Window)c32; FrameMgrGetToken(fm, c16); kev->x_root = (int)c16; FrameMgrGetToken(fm, c16); kev->y_root = (int)c16; FrameMgrGetToken(fm, c16); kev->x = (int)c16; FrameMgrGetToken(fm, c16); kev->y = (int)c16; FrameMgrGetToken(fm, c16); kev->state = (unsigned int)c16; FrameMgrGetToken(fm, b); kev->same_screen = (Bool)b; } ret = True; break; default: break; } /* free FrameMgr */ FrameMgrFree(fm); return ret; } static void ForwardEventMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec forward_event_fr[]; xEvent wire_event; IMForwardEventStruct *forward = (IMForwardEventStruct*) &call_data->forwardevent; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (forward_event_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, forward->icid); FrameMgrGetToken (fm, forward->sync_bit); FrameMgrGetToken (fm, forward->serial_number); p += sizeof (CARD16)*4; memmove (&wire_event, p, sizeof (xEvent)); FrameMgrFree (fm); if (WireEventToEvent (i18n_core, &wire_event, forward->serial_number, &forward->event, _Xi18nNeedSwap (i18n_core, connect_id)) == True) { if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ } /*endif*/ } static void ExtForwardKeyEventMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec ext_forward_keyevent_fr[]; CARD8 type, keycode; CARD16 state; CARD32 ev_time, window; IMForwardEventStruct *forward = (IMForwardEventStruct *) &call_data->forwardevent; XEvent *ev = (XEvent *) &forward->event; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (ext_forward_keyevent_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, forward->icid); FrameMgrGetToken (fm, forward->sync_bit); FrameMgrGetToken (fm, forward->serial_number); FrameMgrGetToken (fm, type); FrameMgrGetToken (fm, keycode); FrameMgrGetToken (fm, state); FrameMgrGetToken (fm, ev_time); FrameMgrGetToken (fm, window); FrameMgrFree (fm); if (type != KeyPress) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ /* make a faked keypress event */ ev->type = (int)type; ev->xany.send_event = True; ev->xany.display = i18n_core->address.dpy; ev->xany.serial = (unsigned long) forward->serial_number; ((XKeyEvent *) ev)->keycode = (unsigned int) keycode; ((XKeyEvent *) ev)->state = (unsigned int) state; ((XKeyEvent *) ev)->time = (Time) ev_time; ((XKeyEvent *) ev)->window = (Window) window; ((XKeyEvent *) ev)->root = DefaultRootWindow (ev->xany.display); ((XKeyEvent *) ev)->x = 0; ((XKeyEvent *) ev)->y = 0; ((XKeyEvent *) ev)->x_root = 0; ((XKeyEvent *) ev)->y_root = 0; if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ } static void ExtMoveMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec ext_move_fr[]; IMMoveStruct *extmove = (IMMoveStruct*) & call_data->extmove; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (ext_move_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, extmove->icid); FrameMgrGetToken (fm, extmove->x); FrameMgrGetToken (fm, extmove->y); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ } static void ExtensionMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { switch (call_data->any.minor_code) { case XIM_EXT_FORWARD_KEYEVENT: ExtForwardKeyEventMessageProc (ims, call_data, p); break; case XIM_EXT_MOVE: ExtMoveMessageProc (ims, call_data, p); break; } /*endswitch*/ } static void TriggerNotifyMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec trigger_notify_fr[], trigger_notify_reply_fr[]; register int total_size; unsigned char *reply = NULL; IMTriggerNotifyStruct *trigger = (IMTriggerNotifyStruct *) &call_data->triggernotify; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; CARD32 flag; fm = FrameMgrInit (trigger_notify_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, trigger->icid); FrameMgrGetToken (fm, trigger->flag); FrameMgrGetToken (fm, trigger->key_index); FrameMgrGetToken (fm, trigger->event_mask); /* In order to support Front End Method, this event_mask must be saved per clients so that it should be restored by an XIM_EXT_SET_EVENT_MASK call when preediting mode is reset to off. */ flag = trigger->flag; FrameMgrFree (fm); fm = FrameMgrInit (trigger_notify_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); FrameMgrPutToken (fm, trigger->icid); /* NOTE: XIM_TRIGGER_NOTIFY_REPLY should be sent before XIM_SET_EVENT_MASK in case of XIM_TRIGGER_NOTIFY(flag == ON), while it should be sent after XIM_SET_EVENT_MASK in case of XIM_TRIGGER_NOTIFY(flag == OFF). */ if (flag == 0) { /* on key */ _Xi18nSendMessage (ims, connect_id, XIM_TRIGGER_NOTIFY_REPLY, 0, reply, total_size); IMPreeditStart (ims, (XPointer)call_data); } /*endif*/ if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ if (flag == 1) { /* off key */ IMPreeditEnd (ims, (XPointer) call_data); _Xi18nSendMessage (ims, connect_id, XIM_TRIGGER_NOTIFY_REPLY, 0, reply, total_size); } /*endif*/ FrameMgrFree (fm); XFree (reply); } static INT16 ChooseEncoding (Xi18n i18n_core, IMEncodingNegotiationStruct *enc_nego) { Xi18nAddressRec *address = (Xi18nAddressRec *) & i18n_core->address; XIMEncodings *p; int i, j; int enc_index=0; p = (XIMEncodings *) &address->encoding_list; for (i = 0; i < (int) p->count_encodings; i++) { for (j = 0; j < (int) enc_nego->encoding_number; j++) { if (strcmp (p->supported_encodings[i], enc_nego->encoding[j].name) == 0) { enc_index = j; break; } /*endif*/ } /*endfor*/ } /*endfor*/ return (INT16) enc_index; #if 0 return (INT16) XIM_Default_Encoding_IDX; #endif } static void EncodingNegotiatonMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; FmStatus status; CARD16 byte_length; extern XimFrameRec encoding_negotiation_fr[]; extern XimFrameRec encoding_negotiation_reply_fr[]; register int i, total_size; unsigned char *reply = NULL; IMEncodingNegotiationStruct *enc_nego = (IMEncodingNegotiationStruct *) &call_data->encodingnego; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (encoding_negotiation_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); FrameMgrGetToken (fm, input_method_ID); /* get ENCODING STR field */ FrameMgrGetToken (fm, byte_length); if (byte_length > 0) { enc_nego->encoding = (XIMStr *) malloc (sizeof (XIMStr)*10); memset (enc_nego->encoding, 0, sizeof (XIMStr)*10); i = 0; while (FrameMgrIsIterLoopEnd (fm, &status) == False) { char *name; int str_length; FrameMgrGetToken (fm, str_length); FrameMgrSetSize (fm, str_length); enc_nego->encoding[i].length = str_length; FrameMgrGetToken (fm, name); enc_nego->encoding[i].name = malloc (str_length + 1); strncpy (enc_nego->encoding[i].name, name, str_length); enc_nego->encoding[i].name[str_length] = '\0'; i++; } /*endwhile*/ enc_nego->encoding_number = i; } /*endif*/ /* get ENCODING INFO field */ FrameMgrGetToken (fm, byte_length); if (byte_length > 0) { enc_nego->encodinginfo = (XIMStr *) malloc (sizeof (XIMStr)*10); memset (enc_nego->encoding, 0, sizeof (XIMStr)*10); i = 0; while (FrameMgrIsIterLoopEnd (fm, &status) == False) { char *name; int str_length; FrameMgrGetToken (fm, str_length); FrameMgrSetSize (fm, str_length); enc_nego->encodinginfo[i].length = str_length; FrameMgrGetToken (fm, name); enc_nego->encodinginfo[i].name = malloc (str_length + 1); strncpy (enc_nego->encodinginfo[i].name, name, str_length); enc_nego->encodinginfo[i].name[str_length] = '\0'; i++; } /*endwhile*/ enc_nego->encoding_info_number = i; } /*endif*/ enc_nego->enc_index = ChooseEncoding (i18n_core, enc_nego); enc_nego->category = 0; #ifdef PROTOCOL_RICH if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ #endif /* PROTOCOL_RICH */ FrameMgrFree (fm); fm = FrameMgrInit (encoding_negotiation_reply_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, input_method_ID); FrameMgrPutToken (fm, enc_nego->category); FrameMgrPutToken (fm, enc_nego->enc_index); _Xi18nSendMessage (ims, connect_id, XIM_ENCODING_NEGOTIATION_REPLY, 0, reply, total_size); XFree (reply); /* free data for encoding list */ if (enc_nego->encoding) { for (i = 0; i < (int) enc_nego->encoding_number; i++) XFree (enc_nego->encoding[i].name); /*endfor*/ XFree (enc_nego->encoding); } /*endif*/ if (enc_nego->encodinginfo) { for (i = 0; i < (int) enc_nego->encoding_info_number; i++) XFree (enc_nego->encodinginfo[i].name); /*endfor*/ XFree (enc_nego->encodinginfo); } /*endif*/ FrameMgrFree (fm); } void PreeditStartReplyMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec preedit_start_reply_fr[]; IMPreeditCBStruct *preedit_CB = (IMPreeditCBStruct *) &call_data->preedit_callback; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (preedit_start_reply_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, preedit_CB->icid); FrameMgrGetToken (fm, preedit_CB->todo.return_value); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto (ims, call_data))) return; /*endif*/ } /*endif*/ } void PreeditCaretReplyMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec preedit_caret_reply_fr[]; IMPreeditCBStruct *preedit_CB = (IMPreeditCBStruct *) &call_data->preedit_callback; XIMPreeditCaretCallbackStruct *caret = (XIMPreeditCaretCallbackStruct *) & preedit_CB->todo.caret; CARD16 connect_id = call_data->any.connect_id; CARD16 input_method_ID; fm = FrameMgrInit (preedit_caret_reply_fr, (char *) p, _Xi18nNeedSwap (i18n_core, connect_id)); /* get data */ FrameMgrGetToken (fm, input_method_ID); FrameMgrGetToken (fm, preedit_CB->icid); FrameMgrGetToken (fm, caret->position); FrameMgrFree (fm); if (i18n_core->address.improto) { if (!(i18n_core->address.improto(ims, call_data))) return; /*endif*/ } /*endif*/ } void StrConvReplyMessageProc (XIMS ims, IMProtocol *call_data, unsigned char *p) { return; } static void AddQueue (Xi18nClient *client, unsigned char *p) { XIMPending *new; XIMPending *last; if ((new = (XIMPending *) malloc (sizeof (XIMPending))) == NULL) return; /*endif*/ new->p = p; new->next = (XIMPending *) NULL; if (!client->pending) { client->pending = new; } else { for (last = client->pending; last->next; last = last->next) ; /*endfor*/ last->next = new; } /*endif*/ return; } static void ProcessQueue (XIMS ims, CARD16 connect_id) { Xi18n i18n_core = ims->protocol; Xi18nClient *client = (Xi18nClient *) _Xi18nFindClient (i18n_core, connect_id); while (client->sync == False && client->pending) { XimProtoHdr *hdr = (XimProtoHdr *) client->pending->p; unsigned char *p1 = (unsigned char *) (hdr + 1); IMProtocol call_data; call_data.major_code = hdr->major_opcode; call_data.any.minor_code = hdr->minor_opcode; call_data.any.connect_id = connect_id; switch (hdr->major_opcode) { case XIM_FORWARD_EVENT: ForwardEventMessageProc(ims, &call_data, p1); break; } /*endswitch*/ XFree (hdr); { XIMPending *old = client->pending; client->pending = old->next; XFree (old); } } /*endwhile*/ return; } void _Xi18nMessageHandler (XIMS ims, CARD16 connect_id, unsigned char *p, Bool *delete) { XimProtoHdr *hdr = (XimProtoHdr *)p; unsigned char *p1 = (unsigned char *)(hdr + 1); IMProtocol call_data; Xi18n i18n_core = ims->protocol; Xi18nClient *client; client = (Xi18nClient *) _Xi18nFindClient (i18n_core, connect_id); if (hdr == (XimProtoHdr *) NULL) return; /*endif*/ memset (&call_data, 0, sizeof(IMProtocol)); call_data.major_code = hdr->major_opcode; call_data.any.minor_code = hdr->minor_opcode; call_data.any.connect_id = connect_id; switch (call_data.major_code) { case XIM_CONNECT: #ifdef XIM_DEBUG DebugLog("-- XIM_CONNECT\n"); #endif ConnectMessageProc (ims, &call_data, p1); break; case XIM_DISCONNECT: #ifdef XIM_DEBUG DebugLog("-- XIM_DISCONNECT\n"); #endif DisConnectMessageProc (ims, &call_data); break; case XIM_OPEN: #ifdef XIM_DEBUG DebugLog("-- XIM_OPEN\n"); #endif OpenMessageProc (ims, &call_data, p1); break; case XIM_CLOSE: #ifdef XIM_DEBUG DebugLog("-- XIM_CLOSE\n"); #endif CloseMessageProc (ims, &call_data, p1); break; case XIM_QUERY_EXTENSION: #ifdef XIM_DEBUG DebugLog("-- XIM_QUERY_EXTENSION\n"); #endif QueryExtensionMessageProc (ims, &call_data, p1); break; case XIM_GET_IM_VALUES: #ifdef XIM_DEBUG DebugLog("-- XIM_GET_IM_VALUES\n"); #endif GetIMValuesMessageProc (ims, &call_data, p1); break; case XIM_CREATE_IC: #ifdef XIM_DEBUG DebugLog("-- XIM_CREATE_IC\n"); #endif CreateICMessageProc (ims, &call_data, p1); break; case XIM_SET_IC_VALUES: #ifdef XIM_DEBUG DebugLog("-- XIM_SET_IC_VALUES\n"); #endif SetICValuesMessageProc (ims, &call_data, p1); break; case XIM_GET_IC_VALUES: #ifdef XIM_DEBUG DebugLog("-- XIM_GET_IC_VALUES\n"); #endif GetICValuesMessageProc (ims, &call_data, p1); break; case XIM_SET_IC_FOCUS: #ifdef XIM_DEBUG DebugLog("-- XIM_SET_IC_FOCUS\n"); #endif SetICFocusMessageProc (ims, &call_data, p1); break; case XIM_UNSET_IC_FOCUS: #ifdef XIM_DEBUG DebugLog("-- XIM_UNSET_IC_FOCUS\n"); #endif UnsetICFocusMessageProc (ims, &call_data, p1); break; case XIM_DESTROY_IC: #ifdef XIM_DEBUG DebugLog("-- XIM_DESTROY_IC\n"); #endif DestroyICMessageProc (ims, &call_data, p1); break; case XIM_RESET_IC: #ifdef XIM_DEBUG DebugLog("-- XIM_RESET_IC\n"); #endif ResetICMessageProc (ims, &call_data, p1); break; case XIM_FORWARD_EVENT: #ifdef XIM_DEBUG DebugLog("-- XIM_FORWARD_EVENT\n"); #endif if (client->sync == True) { AddQueue (client, p); *delete = False; } else { ForwardEventMessageProc (ims, &call_data, p1); } break; case XIM_EXTENSION: #ifdef XIM_DEBUG DebugLog("-- XIM_EXTENSION\n"); #endif ExtensionMessageProc (ims, &call_data, p1); break; case XIM_SYNC: #ifdef XIM_DEBUG DebugLog("-- XIM_SYNC\n"); #endif break; case XIM_SYNC_REPLY: #ifdef XIM_DEBUG DebugLog("-- XIM_SYNC_REPLY\n"); #endif SyncReplyMessageProc (ims, &call_data, p1); ProcessQueue (ims, connect_id); break; case XIM_TRIGGER_NOTIFY: #ifdef XIM_DEBUG DebugLog("-- XIM_TRIGGER_NOTIFY\n"); #endif TriggerNotifyMessageProc (ims, &call_data, p1); break; case XIM_ENCODING_NEGOTIATION: #ifdef XIM_DEBUG DebugLog("-- XIM_ENCODING_NEGOTIATION\n"); #endif EncodingNegotiatonMessageProc (ims, &call_data, p1); break; case XIM_PREEDIT_START_REPLY: #ifdef XIM_DEBUG DebugLog("-- XIM_PREEDIT_START_REPLY\n"); #endif PreeditStartReplyMessageProc (ims, &call_data, p1); break; case XIM_PREEDIT_CARET_REPLY: #ifdef XIM_DEBUG DebugLog("-- XIM_PREEDIT_CARET_REPLY\n"); #endif PreeditCaretReplyMessageProc (ims, &call_data, p1); break; case XIM_STR_CONVERSION_REPLY: #ifdef XIM_DEBUG DebugLog("-- XIM_STR_CONVERSION_REPLY\n"); #endif StrConvReplyMessageProc (ims, &call_data, p1); break; } /*endswitch*/ } xsunpinyin-2.0.3/IMdkit/XimFunc.h0000644000076400007640000000651111527365010015312 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #ifndef _XimFunc_h #define _XimFunc_h /* i18nAttr.c */ void _Xi18nInitAttrList (Xi18n i18n_core); void _Xi18nInitExtension(Xi18n i18n_core); /* i18nClbk.c */ int _Xi18nGeometryCallback (XIMS ims, IMProtocol *call_data); int _Xi18nPreeditStartCallback (XIMS ims, IMProtocol *call_data); int _Xi18nPreeditDrawCallback (XIMS ims, IMProtocol *call_data); int _Xi18nPreeditCaretCallback (XIMS ims, IMProtocol *call_data); int _Xi18nPreeditDoneCallback (XIMS ims, IMProtocol *call_data); int _Xi18nStatusStartCallback (XIMS ims, IMProtocol *call_data); int _Xi18nStatusDrawCallback (XIMS ims, IMProtocol *call_data); int _Xi18nStatusDoneCallback (XIMS ims, IMProtocol *call_data); int _Xi18nStringConversionCallback (XIMS ims, IMProtocol *call_data); /* i18nIc.c */ void _Xi18nChangeIC (XIMS ims, IMProtocol *call_data, unsigned char *p, int create_flag); void _Xi18nGetIC (XIMS ims, IMProtocol *call_data, unsigned char *p); /* i18nUtil.c */ int _Xi18nNeedSwap (Xi18n i18n_core, CARD16 connect_id); Xi18nClient *_Xi18nNewClient(Xi18n i18n_core); Xi18nClient *_Xi18nFindClient (Xi18n i18n_core, CARD16 connect_id); void _Xi18nDeleteClient (Xi18n i18n_core, CARD16 connect_id); void _Xi18nSendMessage (XIMS ims, CARD16 connect_id, CARD8 major_opcode, CARD8 minor_opcode, unsigned char *data, long length); void _Xi18nSendTriggerKey (XIMS ims, CARD16 connect_id); void _Xi18nSetEventMask (XIMS ims, CARD16 connect_id, CARD16 im_id, CARD16 ic_id, CARD32 forward_mask, CARD32 sync_mask); /* Xlib internal */ void _XRegisterFilterByType(Display*, Window, int, int, Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer); void _XUnregisterFilter(Display*, Window, Bool (*filter)(Display*, Window, XEvent*, XPointer), XPointer); #endif xsunpinyin-2.0.3/IMdkit/i18nUtil.c0000644000076400007640000002073411527365010015354 0ustar mikemike/****************************************************************** Copyright 1994, 1995 by Sun Microsystems, Inc. Copyright 1993, 1994 by Hewlett-Packard Company Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sun Microsystems, Inc. and Hewlett-Packard not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Sun Microsystems, Inc. and Hewlett-Packard make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc. This version tidied and debugged by Steve Underwood May 1999 ******************************************************************/ #include #include "IMdkit.h" #include "Xi18n.h" #include "FrameMgr.h" #include "XimFunc.h" Xi18nClient *_Xi18nFindClient (Xi18n, CARD16); int _Xi18nNeedSwap (Xi18n i18n_core, CARD16 connect_id) { CARD8 im_byteOrder = i18n_core->address.im_byteOrder; Xi18nClient *client = _Xi18nFindClient (i18n_core, connect_id); return (client->byte_order != im_byteOrder); } Xi18nClient *_Xi18nNewClient(Xi18n i18n_core) { static CARD16 connect_id = 0; int new_connect_id; Xi18nClient *client; if (i18n_core->address.free_clients) { client = i18n_core->address.free_clients; i18n_core->address.free_clients = client->next; new_connect_id = client->connect_id; } else { client = (Xi18nClient *) malloc (sizeof (Xi18nClient)); new_connect_id = ++connect_id; } /*endif*/ memset (client, 0, sizeof (Xi18nClient)); client->connect_id = new_connect_id; client->pending = (XIMPending *) NULL; client->sync = False; client->byte_order = '?'; /* initial value */ memset (&client->pending, 0, sizeof (XIMPending *)); client->property_offset = 0; client->next = i18n_core->address.clients; i18n_core->address.clients = client; return (Xi18nClient *) client; } Xi18nClient *_Xi18nFindClient (Xi18n i18n_core, CARD16 connect_id) { Xi18nClient *client = i18n_core->address.clients; while (client) { if (client->connect_id == connect_id) return client; /*endif*/ client = client->next; } /*endwhile*/ return NULL; } void _Xi18nDeleteClient (Xi18n i18n_core, CARD16 connect_id) { Xi18nClient *target = _Xi18nFindClient (i18n_core, connect_id); Xi18nClient *ccp; Xi18nClient *ccp0; for (ccp = i18n_core->address.clients, ccp0 = NULL; ccp != NULL; ccp0 = ccp, ccp = ccp->next) { if (ccp == target) { if (ccp0 == NULL) i18n_core->address.clients = ccp->next; else ccp0->next = ccp->next; /*endif*/ /* put it back to free list */ target->next = i18n_core->address.free_clients; i18n_core->address.free_clients = target; return; } /*endif*/ } /*endfor*/ } void _Xi18nSendMessage (XIMS ims, CARD16 connect_id, CARD8 major_opcode, CARD8 minor_opcode, unsigned char *data, long length) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec packet_header_fr[]; unsigned char *reply_hdr = NULL; int header_size; unsigned char *reply = NULL; unsigned char *replyp; int reply_length; long p_len = length/4; fm = FrameMgrInit (packet_header_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); header_size = FrameMgrGetTotalSize (fm); reply_hdr = (unsigned char *) malloc (header_size); if (reply_hdr == NULL) { _Xi18nSendMessage (ims, connect_id, XIM_ERROR, 0, 0, 0); return; } /*endif*/ FrameMgrSetBuffer (fm, reply_hdr); /* put data */ FrameMgrPutToken (fm, major_opcode); FrameMgrPutToken (fm, minor_opcode); FrameMgrPutToken (fm, p_len); reply_length = header_size + length; reply = (unsigned char *) malloc (reply_length); replyp = reply; memmove (reply, reply_hdr, header_size); replyp += header_size; memmove (replyp, data, length); i18n_core->methods.send (ims, connect_id, reply, reply_length); XFree (reply); XFree (reply_hdr); FrameMgrFree (fm); } void _Xi18nSendTriggerKey (XIMS ims, CARD16 connect_id) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec register_triggerkeys_fr[]; XIMTriggerKey *on_keys = i18n_core->address.on_keys.keylist; XIMTriggerKey *off_keys = i18n_core->address.off_keys.keylist; int on_key_num = i18n_core->address.on_keys.count_keys; int off_key_num = i18n_core->address.off_keys.count_keys; unsigned char *reply = NULL; register int i, total_size; CARD16 im_id; if (on_key_num == 0 && off_key_num == 0) return; /*endif*/ fm = FrameMgrInit (register_triggerkeys_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); /* set iteration count for on-keys list */ FrameMgrSetIterCount (fm, on_key_num); /* set iteration count for off-keys list */ FrameMgrSetIterCount (fm, off_key_num); /* get total_size */ total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) return; /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); /* Right now XIM_OPEN_REPLY hasn't been sent to this new client, so the input-method-id is still invalid, and should be set to zero... Reter to $(XC)/lib/X11/imDefLkup.c:_XimRegisterTriggerKeysCallback */ im_id = 0; FrameMgrPutToken (fm, im_id); /* input-method-id */ for (i = 0; i < on_key_num; i++) { FrameMgrPutToken (fm, on_keys[i].keysym); FrameMgrPutToken (fm, on_keys[i].modifier); FrameMgrPutToken (fm, on_keys[i].modifier_mask); } /*endfor*/ for (i = 0; i < off_key_num; i++) { FrameMgrPutToken (fm, off_keys[i].keysym); FrameMgrPutToken (fm, off_keys[i].modifier); FrameMgrPutToken (fm, off_keys[i].modifier_mask); } /*endfor*/ _Xi18nSendMessage (ims, connect_id, XIM_REGISTER_TRIGGERKEYS, 0, reply, total_size); FrameMgrFree (fm); XFree(reply); } void _Xi18nSetEventMask (XIMS ims, CARD16 connect_id, CARD16 im_id, CARD16 ic_id, CARD32 forward_mask, CARD32 sync_mask) { Xi18n i18n_core = ims->protocol; FrameMgr fm; extern XimFrameRec set_event_mask_fr[]; unsigned char *reply = NULL; register int total_size; fm = FrameMgrInit (set_event_mask_fr, NULL, _Xi18nNeedSwap (i18n_core, connect_id)); total_size = FrameMgrGetTotalSize (fm); reply = (unsigned char *) malloc (total_size); if (!reply) return; /*endif*/ memset (reply, 0, total_size); FrameMgrSetBuffer (fm, reply); FrameMgrPutToken (fm, im_id); /* input-method-id */ FrameMgrPutToken (fm, ic_id); /* input-context-id */ FrameMgrPutToken (fm, forward_mask); FrameMgrPutToken (fm, sync_mask); _Xi18nSendMessage (ims, connect_id, XIM_SET_EVENT_MASK, 0, reply, total_size); FrameMgrFree (fm); XFree(reply); } xsunpinyin-2.0.3/SConstruct0000644000076400007640000001101111527365010014430 0ustar mikemikeimport os sources = ['ic.c', 'ic_gtk.c', 'ic_skin.c', 'skin.c', 'ui.c', 'main.c', 'settings.c', 'sunpinyin_preedit.cc', 'sunpinyin_preedit_gtk.cc', 'sunpinyin_preedit_skin.cc', 'xim.c', 'xim_trigger.c', 'xmisc.c'] preferences_sources = ['preferences.c', 'settings.c', 'xmisc.c'] imdkit_sources = ['IMdkit/FrameMgr.c', 'IMdkit/i18nAttr.c', 'IMdkit/i18nClbk.c', 'IMdkit/i18nIc.c', 'IMdkit/i18nIMProto.c', 'IMdkit/i18nMethod.c', 'IMdkit/i18nPtHdr.c', 'IMdkit/i18nUtil.c', 'IMdkit/i18nX.c', 'IMdkit/IMConn.c', 'IMdkit/IMMethod.c', 'IMdkit/IMValues.c'] cflags='-O2 -g -pipe' # options AddOption('--prefix', dest='prefix', type='string', nargs=1, action='store', metavar='DIR', help='installation prefix') AddOption('--rpath', dest='rpath', type='string', nargs=1, action='store', metavar='DIR', help='encode rpath in the executables') # save the options opts = Variables('configure.conf') opts.Add('PREFIX', default='/usr/local') def PassVariables(envvar, env): for (x, y) in envvar: if x in os.environ: print 'Warning: you\'ve set %s in the environmental variable!' % x env[y] = os.environ[x] env = Environment(ENV=os.environ, CFLAGS=cflags, CXXFLAGS=cflags, LINKFLAGS=['-export-dynamic'], CPPPATH=['.', 'IMdkit']) opts.Update(env) if GetOption('prefix') is not None: env['PREFIX'] = GetOption('prefix') opts.Save('configure.conf', env) # set rpath if GetOption('rpath') is not None: env.Append(LINKFLAGS='-Wl,-R -Wl,%s' % GetOption('rpath')) envvar = [('CC', 'CC'), ('CXX', 'CXX'), ('CFLAGS', 'CFLAGS'), ('CXXFLAGS', 'CXXFLAGS'), ('LDFLAGS', 'LINKFLAGS')] PassVariables(envvar, env) bin_dir = env['PREFIX'] + '/bin' data_dir = '%s/share/xsunpinyin/' % env['PREFIX'] icon_dir = data_dir + 'icons/' extra_cflags = ' -DSUNPINYIN_XIM_ICON_DIR=\\"%s\\"' % icon_dir extra_cflags += ' -DSUNPINYIN_XIM_SETTING_DIR=\\"%s\\"' % data_dir env.Append(CFLAGS=extra_cflags) env.Append(CXXFLAGS=extra_cflags) # #==============================configure================================ # def CheckPKGConfig(context, version='0.12.0'): context.Message( 'Checking for pkg-config... ' ) ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0] context.Result(ret) return ret def CheckPKG(context, name): context.Message( 'Checking for %s... ' % name ) ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0] context.Result(ret) return ret conf = Configure(env, custom_tests={'CheckPKGConfig' : CheckPKGConfig, 'CheckPKG' : CheckPKG }) def DoConfigure(): if GetOption('clean'): return if not conf.CheckPKGConfig(): Exit(1) if not conf.CheckPKG('gtk+-2.0'): Exit(1) if not conf.CheckPKG('x11'): Exit(1) if not conf.CheckPKG('sunpinyin-2.0'): Exit(1) env = conf.Finish() env.ParseConfig('pkg-config gtk+-2.0 x11 sunpinyin-2.0 --libs --cflags') DoConfigure() env.Append(LIBS=env.Library('IMdkit', source=imdkit_sources)) env.Program('xsunpinyin', source=sources) env.Program('xsunpinyin-preferences', source=preferences_sources) def DoInstall(): bin_target = env.Install(bin_dir, ['xsunpinyin', 'xsunpinyin-preferences']) icon_target = env.Install(icon_dir, ['data/chnpunc.png', 'data/han.png', 'data/eng.png', 'data/han.svg', 'data/eng.svg', 'data/engpunc.png', 'data/full.png', 'data/half.png', 'data/sunpinyin-logo-big.png', 'data/sunpinyin-logo.png']) data_target = env.Install(data_dir, ['data/settings_ui.xml']) data_target += env.Install(data_dir + 'skins/', Glob('data/skins/*')) env.Alias('install-bin', bin_target) env.Alias('install-data', [icon_target, data_target]) DoInstall() env.Alias('install', ['install-bin', 'install-data']) xsunpinyin-2.0.3/ic_gtk.c0000644000076400007640000001700511527365010014013 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include "ic.h" #include "ui.h" #include "common.h" #include "settings.h" static GtkWidget* icbar_window; static GtkWidget* icbar_status_btn; static GtkWidget* icbar_full_btn; static GtkWidget* icbar_chn_punc_btn; static GtkStatusIcon* icbar_tray; static GtkWidget* popup_menu; #define LOGO_FILE SUNPINYIN_XIM_ICON_DIR"/sunpinyin-logo.png" #define ENG_ICON_PNG SUNPINYIN_XIM_ICON_DIR"/eng.png" #define HAN_ICON_PNG SUNPINYIN_XIM_ICON_DIR"/han.png" #define FULL_ICON_PNG SUNPINYIN_XIM_ICON_DIR"/full.png" #define HALF_ICON_PNG SUNPINYIN_XIM_ICON_DIR"/half.png" #define CHN_PUNC_ICON_PNG SUNPINYIN_XIM_ICON_DIR"/chnpunc.png" #define ENG_PUNC_ICON_PNG SUNPINYIN_XIM_ICON_DIR"/engpunc.png" static void toggle_english(GtkToggleButton* btn, gpointer userdata) { icmgr_toggle_english(); icmgr_refresh(); } static void toggle_full(GtkToggleButton* btn, gpointer userdata) { icmgr_toggle_full(); icmgr_refresh(); } static void toggle_chn_punc(GtkToggleButton* btn, gpointer userdata) { icmgr_toggle_punc(); icmgr_refresh(); } static bool begin_drag = false; static int drag_offset_x = -1; static int drag_offset_y = -1; static void icbar_on_button_press(GtkWidget* wnd, GdkEventButton* evt, gpointer data) { if (evt->button == 1) { begin_drag = true; drag_offset_x = (int) evt->x; drag_offset_y = (int) evt->y; } } static void icbar_on_button_release(GtkWidget* wnd, GdkEventButton* evt, gpointer data) { if (evt->button == 1) { begin_drag = false; position_t pos; gtk_window_get_position(GTK_WINDOW(icbar_window), &(pos.x), &(pos.y)); settings_set(ICBAR_POS, &pos); } } static void icbar_on_motion(GtkWidget* wnd, GdkEventMotion* evt, gpointer data) { if (begin_drag) { gtk_window_move(GTK_WINDOW(icbar_window), (int) evt->x_root - drag_offset_x, (int) evt->y_root - drag_offset_y); } } static void __toggle_mode(gboolean mode, GtkWidget* btn, const char* img_path1, const char* img_path2) { GtkWidget* img_wid = gtk_tool_button_get_icon_widget( GTK_TOOL_BUTTON(btn)); const char* img_path = NULL; if (mode) { img_path = img_path1; } else { img_path = img_path2; } gtk_image_set_from_file(GTK_IMAGE(img_wid), img_path); gtk_image_set_pixel_size(GTK_IMAGE(img_wid), 20); } static GtkWidget* __create_btn(bool stock, const char* img_path, GCallback cb) { GtkWidget* img_wid; if (stock) { img_wid = gtk_image_new_from_icon_name(img_path, GTK_ICON_SIZE_MENU); } else { img_wid = gtk_image_new_from_file(ENG_ICON_PNG); } gtk_image_set_pixel_size(GTK_IMAGE(img_wid), 20); GtkWidget* res = GTK_WIDGET(gtk_tool_button_new(img_wid, "")); g_signal_connect(res, "clicked", cb, NULL); return res; } static gboolean icmgr_gtk_init(const char* name) { icbar_window = ui_create_window(); gtk_widget_add_events(icbar_window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK); g_signal_connect(icbar_window, "button-press-event", G_CALLBACK(icbar_on_button_press), NULL); g_signal_connect(icbar_window, "motion-notify-event", G_CALLBACK(icbar_on_motion), NULL); g_signal_connect(icbar_window, "button-release-event", G_CALLBACK(icbar_on_button_release), NULL); icbar_status_btn = __create_btn(false, ENG_ICON_PNG, G_CALLBACK(toggle_english)); icbar_full_btn = __create_btn(false, FULL_ICON_PNG, G_CALLBACK(toggle_full)); icbar_chn_punc_btn = __create_btn(false, CHN_PUNC_ICON_PNG, G_CALLBACK(toggle_chn_punc)); GtkWidget* logo = gtk_image_new_from_file(LOGO_FILE); gtk_widget_add_events(logo, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); GtkWidget* box = gtk_hbox_new(false, 1); gtk_box_pack_start(GTK_BOX(box), logo, false, false, 1); gtk_box_pack_start(GTK_BOX(box), icbar_status_btn, false, false, 1); gtk_box_pack_start(GTK_BOX(box), icbar_full_btn, false, false, 1); gtk_box_pack_start(GTK_BOX(box), icbar_chn_punc_btn, false, false, 1); gtk_container_add(GTK_CONTAINER(icbar_window), box); gtk_widget_show_all(box); return TRUE; } static void icmgr_gtk_refresh(void) { IC* ic = icmgr_get_current(); if (ic == NULL || !ic->is_enabled) { gtk_widget_hide(icbar_window); return; } __toggle_mode(ic->is_english, icbar_status_btn, ENG_ICON_PNG, HAN_ICON_PNG); __toggle_mode(ic->is_full, icbar_full_btn, FULL_ICON_PNG, HALF_ICON_PNG); __toggle_mode(ic->is_chn_punc, icbar_chn_punc_btn, CHN_PUNC_ICON_PNG, ENG_PUNC_ICON_PNG); position_t pos; int width, height; gtk_window_get_size(GTK_WINDOW(icbar_window), &width, &height); settings_get(ICBAR_POS, &pos); adjust_position(&(pos.x), &(pos.y), width, height); settings_set(ICBAR_POS, &pos); gtk_widget_show(icbar_window); gtk_window_move(GTK_WINDOW(icbar_window), pos.x, pos.y); } static void icmgr_gtk_dispose(void) { gtk_widget_destroy(icbar_window); } static const char* icmgr_gtk_get_name(void) { return "classic"; } IC_UI icmgr_gtk = { .get_name = icmgr_gtk_get_name, .init = icmgr_gtk_init, .refresh = icmgr_gtk_refresh, .dispose = icmgr_gtk_dispose, }; xsunpinyin-2.0.3/im-switch/0000755000076400007640000000000011527365010014310 5ustar mikemikexsunpinyin-2.0.3/im-switch/xsunpinyin0000644000076400007640000000013611527365010016457 0ustar mikemikeXIM=xsunpinyin XIM_ARGS=-d XIM_PROGRAM=/usr/bin/xsunpinyin GTK_IM_MODULE=xim QT_IM_MODULE=xim xsunpinyin-2.0.3/xim.c0000644000076400007640000002700411527365010013350 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include #include #include #include #include #include #include #include #include "xim.h" #include "xmisc.h" #include "ic.h" #include "common.h" #include "settings.h" static int __preedit_x; static int __preedit_y; static int __input_style; static Window __client_window; static Window __focus_window; static int _xim_open(XIMHandle* handle, IMOpenStruct* proto) { LOG("XIM_OPEN %d", proto->connect_id); return 1; } static int _xim_close(XIMHandle* handle, IMCloseStruct* proto) { LOG("XIM_CLOSE %d", proto->connect_id); return 1; } static int __xim_ic_events(IMChangeICStruct* proto) { XICAttribute* ic_attr = proto->ic_attr; XICAttribute* pre_attr = proto->preedit_attr; int i = 0; for (i = 0; i < (int) proto->ic_attr_num; i++) { if (strcmp(XNInputStyle, ic_attr[i].name) == 0) { LOG("got input style %d", __input_style); __input_style = * (int*) ic_attr[i].value; } else if (strcmp(XNClientWindow, ic_attr[i].name) == 0) { LOG("got client window"); __client_window = * (Window*) ic_attr[i].value; } else if (strcmp(XNFocusWindow, ic_attr[i].name) == 0) { LOG("got focus window"); __focus_window = * (Window*) ic_attr[i].value; } } for (i = 0; i < (int) proto->preedit_attr_num; i++) { if (strcmp(XNSpotLocation, pre_attr[i].name) == 0) { XPoint* point = pre_attr[i].value; __preedit_x = point->x; __preedit_y = point->y; LOG("position (%d, %d)", __preedit_x, __preedit_y); } } return 1; } static int _xim_create_ic(XIMHandle* handle, IMChangeICStruct* proto) { IC* ic = icmgr_create_ic(proto->connect_id); __xim_ic_events(proto); proto->icid = ic->icid; ic->client_window = __client_window; ic->offset_x = __preedit_x; ic->offset_y = __preedit_y; LOG("XIM_CREATE_IC %d", proto->icid); return 1; } static int _xim_destroy_ic(XIMHandle* handle, IMChangeICStruct* proto) { LOG("XIM_DESTROY_IC %d", proto->icid); icmgr_destroy_ic(proto->icid); icmgr_refresh(); return 1; } void __move_preedit(IC* ic) { int root_x, root_y; get_window_position(ic->client_window, &root_x, &root_y); LOG("root: %d, %d offset: %d,%d", root_x, root_y, ic->offset_x, ic->offset_y); if (ic->offset_x == 0 && ic->offset_y == 0) { int height; get_window_size(ic->client_window, NULL, &height); root_x += 4; root_y += height; } else { root_x += ic->offset_x; root_y += ic->offset_y; } preedit_move(root_x, root_y); } static int _xim_set_ic_values(XIMHandle* handle, IMChangeICStruct* proto) { __xim_ic_events(proto); IC* ic = icmgr_get(proto->icid); /* some crapy swing application will have synchronization problems */ if (ic == NULL) return 1; LOG("XIM_SET_IC_VALUES %d", proto->icid); ic->offset_x = __preedit_x; ic->offset_y = __preedit_y; IC* cur_ic = icmgr_get_current(); /* if we change the current ic position, we might wanna * move it along the way */ if (cur_ic != NULL && ic->icid == cur_ic->icid) { __move_preedit(ic); } return 1; } static int _xim_get_ic_values(XIMHandle* handle, IMChangeICStruct* proto) { LOG("XIM_GET_IC_VALUES %d", proto->icid); XICAttribute* ic_attr = proto->ic_attr; int i; for (i = 0; i < (int) proto->ic_attr_num; i++) { if (strcmp(XNFilterEvents, ic_attr[i].name) == 0) { ic_attr[i].value = malloc(sizeof(CARD32)); *((CARD32*) ic_attr[i].value) = KeyPressMask | KeyPress; ic_attr[i].value_length = sizeof(CARD32); } } return 1; } static int _xim_trigger_notify(XIMHandle* handle, IMTriggerNotifyStruct* proto) { LOG("trigger key pressed, %d", proto->icid); IC* ic = icmgr_get(proto->icid); if (ic == NULL) return 1; icmgr_set_current(proto->icid); ic->is_enabled = true; xim_start_preedit(handle); icmgr_refresh(); return 1; } static int _xim_set_ic_focus(XIMHandle* handle, IMChangeFocusStruct* proto) { DEBUG("%d", proto->icid); LOG("set focus on ic %d %d", proto->icid, preedit_status()); /* if use didn't finish typing, we won't focus to new context */ if (preedit_status() == false) { icmgr_set_current(proto->icid); } icmgr_refresh(); return 1; } static int _xim_unset_ic_focus(XIMHandle* handle, IMChangeFocusStruct* proto) { LOG("unset focus on ic %d", proto->icid); IC* ic = icmgr_get_current(); if (ic != NULL && ic->icid == proto->icid && preedit_status() == false) { icmgr_clear_current(); icmgr_refresh(); } return 1; } extern int _xim_forward_event(XIMHandle* handle, IMForwardEventStruct* proto); static int _imdkit_protocol_hanlder(XIMHandle* handle, IMProtocol* proto) { assert(handle != NULL); assert(proto != NULL); switch (proto->major_code) { case XIM_OPEN: return _xim_open(handle, (IMOpenStruct *) proto); case XIM_CLOSE: return _xim_close(handle, (IMCloseStruct*) proto); case XIM_CREATE_IC: return _xim_create_ic(handle, (IMChangeICStruct*) proto); case XIM_DESTROY_IC: return _xim_destroy_ic(handle, (IMChangeICStruct*) proto); case XIM_SET_IC_VALUES: return _xim_set_ic_values(handle, (IMChangeICStruct*) proto); case XIM_GET_IC_VALUES: return _xim_get_ic_values(handle, (IMChangeICStruct*) proto); case XIM_TRIGGER_NOTIFY: return _xim_trigger_notify(handle, (IMTriggerNotifyStruct*) proto); case XIM_FORWARD_EVENT: return _xim_forward_event(handle, (IMForwardEventStruct *) proto); case XIM_SET_IC_FOCUS: return _xim_set_ic_focus(handle, (IMChangeFocusStruct *) proto); case XIM_UNSET_IC_FOCUS: return _xim_unset_ic_focus(handle, (IMChangeFocusStruct *) proto); default: LOG("unhandled major code %d", proto->major_code); return 1; } } static XIMHandle* _open_imdkit(const char* _server_name, const char* _locale) { XIMStyle ims_styles_onspot [] = { XIMPreeditPosition | XIMStatusArea, //OverTheSpot XIMPreeditPosition | XIMStatusNothing, //OverTheSpot XIMPreeditPosition | XIMStatusNone, //OverTheSpot XIMPreeditNothing | XIMStatusNothing, //Root XIMPreeditNothing | XIMStatusNone, //Root 0 }; XIMEncoding ims_encodings[] = { "COMPOUND_TEXT", 0 }; /* this is rarely documentated, the trigger condition is * * keycode == keysym && (state & modifier_mask) == modifier * * where keycode and state is the user pressed */ hotkey_t hk; settings_get(TRIGGER_KEY, &hk); XIMTriggerKey trigger = { .keysym = hk.keysym, .modifier = hk.modifiers, .modifier_mask = STATE_MASK }; XIMTriggerKeys keys; XIMStyles styles; XIMEncodings encodings; styles.count_styles = sizeof (ims_styles_onspot)/sizeof (XIMStyle) - 1; styles.supported_styles = ims_styles_onspot; encodings.count_encodings = sizeof (ims_encodings)/sizeof (XIMEncoding) - 1; encodings.supported_encodings = ims_encodings; keys.count_keys = 1; keys.keylist = &trigger; Window win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 1, 0, 0); XSelectInput(dpy, win, ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | VisibilityChangeMask); XIMHandle* handle = IMOpenIM(dpy, IMModifiers, "Xi18n", IMServerWindow, win, IMServerName, _server_name, IMLocale, _locale, IMServerTransport, "X/", IMInputStyles, &styles, IMEncodingList, &encodings, IMProtocolHandler, _imdkit_protocol_hanlder, IMFilterEventMask, KeyPressMask | KeyReleaseMask, IMOnKeysList, &keys, NULL); if (handle == NULL) { fprintf(stderr, "Startup xim server failed.\n"); fprintf(stderr, "Your locale is %s, please file a bug.", _locale); } return handle; } XIMHandle* create_xim_server(const char* server_name, const char* locale) { XIMHandle* handle = _open_imdkit(server_name, locale); icmgr_init(); return handle; } void xim_start_preedit(XIMHandle* handle) { IC* ic = icmgr_get_current(); if (ic == NULL) return; IMPreeditStateStruct ps; ps.icid = ic->icid; ps.connect_id = ic->connect_id; IMPreeditStart(handle, (XPointer) &ps); } void xim_cancel_preedit(XIMHandle* handle) { IC* ic = icmgr_get_current(); if (ic == NULL) return; IMPreeditStateStruct ps; ps.icid = ic->icid; ps.connect_id = ic->connect_id; IMPreeditEnd(handle, (XPointer) &ps); } void xim_commit_preedit(XIMHandle* handle, const char* result_str) { IC* ic = icmgr_get_current(); if (ic == NULL) return; XTextProperty tp; IMCommitStruct cs; Xutf8TextListToTextProperty(dpy, (char**) &result_str, 1, XCompoundTextStyle, &tp); cs.major_code = XIM_COMMIT; cs.icid = ic->icid; cs.connect_id = ic->connect_id; cs.flag = XimLookupChars; cs.commit_string = (char*) tp.value; IMCommitString(handle, (XPointer) &cs); XFree(tp.value); } xsunpinyin-2.0.3/xim.h0000644000076400007640000000615711527365010013363 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _XIM_H_ #define _XIM_H_ #include #include #include #include #include #include #include #include #include "common.h" __BEGIN_DECLS #define STATE_MASK 0x0D typedef struct _XIMS XIMHandle; XIMHandle* create_xim_server(const char* server_name, const char* locale); void xim_start_preedit (XIMHandle* handle); void xim_cancel_preedit(XIMHandle* handle); void xim_commit_preedit(XIMHandle* handle, const char* result_str); /* provided by preedit backend */ void preedit_init(void); void preedit_finalize(void); void preedit_set_handle(XIMHandle* handle); void preedit_reload(void); void preedit_move(int x, int y); void preedit_on_key(XIMHandle* handle, unsigned int keycode, unsigned int state); bool preedit_status(void); void preedit_pause(void); void preedit_go_on(void); void preedit_set_full(bool full); void preedit_set_chinese_punc(bool chn_punc); void preedit_omit_next_punct(); __END_DECLS #endif /* _XIM_H_ */ xsunpinyin-2.0.3/README0000644000076400007640000000013211527365010013260 0ustar mikemikexsunpinyin === xsunpinyin is a standalone XIM server that uses SunPinyin input methord. xsunpinyin-2.0.3/ic_skin.c0000644000076400007640000001443111527365010014172 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include "ic.h" #include "ui.h" #include "skin.h" #include "common.h" #include "settings.h" static skin_info_t* info; static char* skin_name; static skin_window_t* icbar_wind; static skin_button_t* icbar_status_btn; static skin_button_t* icbar_full_btn; static skin_button_t* icbar_punc_btn; static void toggle_english(GtkWidget* wid, GdkEventButton* evt, void* userdata) { icmgr_toggle_english(); icmgr_refresh(); } static void toggle_full(GtkWidget* wid, GdkEventButton* evt, void* userdata) { icmgr_toggle_full(); icmgr_refresh(); } static void toggle_punc(GtkWidget* wid, GdkEventButton* evt, void* userdata) { icmgr_toggle_punc(); icmgr_refresh(); } static void icbar_on_release(GtkWidget* wid, GdkEventMotion* evt, void* userdata) { position_t pos; gtk_window_get_position(GTK_WINDOW(wid), &(pos.x), &(pos.y)); settings_set(ICBAR_POS, &pos); } static gboolean icmgr_skin_init(const char* name) { info = ui_skin_new(name); if (!info) return FALSE; skin_name = strdup(name); icbar_wind = skin_window_new(GTK_WINDOW(ui_create_window()), info->icbar_background, 0, 0, 0, 0, 1); skin_window_set_drag_to_move(icbar_wind, TRUE); skin_window_set_release_cb(icbar_wind, G_CALLBACK(icbar_on_release), NULL); /* creating the buttons */ icbar_status_btn = skin_button_new(info->eng_btn.normal1, info->eng_btn.highlight1, info->eng_btn.pressdown1); icbar_full_btn = skin_button_new(info->full_btn.normal1, info->full_btn.highlight1, info->full_btn.pressdown1); icbar_punc_btn = skin_button_new(info->punc_btn.normal1, info->punc_btn.highlight1, info->punc_btn.pressdown1); /* setting up events */ skin_button_set_release_cb(icbar_status_btn, G_CALLBACK(toggle_english), NULL); skin_button_set_release_cb(icbar_full_btn, G_CALLBACK(toggle_full), NULL); skin_button_set_release_cb(icbar_punc_btn, G_CALLBACK(toggle_punc), NULL); /* adding the buttons to the icbar */ skin_window_add_button(icbar_wind, icbar_status_btn, info->eng_btn.x, info->eng_btn.y); skin_window_add_button(icbar_wind, icbar_full_btn, info->full_btn.x, info->full_btn.y); skin_window_add_button(icbar_wind, icbar_punc_btn, info->punc_btn.x, info->punc_btn.y); return TRUE; } static void toggle_mode(gboolean mode, skin_button_t* btn, skin_button_info_t* info) { if (mode) { skin_button_set_image(btn, info->normal1, info->highlight1, info->pressdown1); } else { skin_button_set_image(btn, info->normal2, info->highlight2, info->pressdown2); } } static void icmgr_skin_refresh(void) { IC* ic = icmgr_get_current(); if (ic == NULL || !ic->is_enabled) { gtk_widget_hide(GTK_WIDGET(icbar_wind->widget)); return; } toggle_mode(ic->is_english, icbar_status_btn, &(info->eng_btn)); toggle_mode(ic->is_full, icbar_full_btn, &(info->full_btn)); toggle_mode(ic->is_chn_punc, icbar_punc_btn, &(info->punc_btn)); position_t pos; int width, height; gtk_window_get_size(GTK_WINDOW(icbar_wind->widget), &width, &height); settings_get(ICBAR_POS, &pos); adjust_position(&(pos.x), &(pos.y), width, height); /* write back the adjustion */ settings_set(ICBAR_POS, &pos); gtk_widget_show(icbar_wind->widget); gtk_window_move(GTK_WINDOW(icbar_wind->widget), pos.x, pos.y); } static void icmgr_skin_dispose(void) { ui_skin_destroy(info); free(skin_name); skin_button_destroy(icbar_status_btn); skin_button_destroy(icbar_full_btn); skin_button_destroy(icbar_punc_btn); skin_window_destroy(icbar_wind); } static const char* icmgr_skin_get_name(void) { return skin_name; } IC_UI icmgr_skin = { .get_name = icmgr_skin_get_name, .init = icmgr_skin_init, .refresh = icmgr_skin_refresh, .dispose = icmgr_skin_dispose, }; xsunpinyin-2.0.3/common.h0000644000076400007640000000627711527365010014061 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _COMMON_H_ #define _COMMON_H_ #include #include #ifdef __cplusplus # ifndef __BEGIN_DECLS # define __BEGIN_DECLS extern "C" { # endif # ifndef __END_DECLS # define __END_DECLS } # endif #else # ifndef __BEGIN_DECLS # define __BEGIN_DECLS # endif # ifndef __END_DECLS # define __END_DECLS # endif #endif #ifdef __cplusplus #define __EXPORT_API extern "C" #else #define __EXPORT_API #endif #ifdef LOG_ENABLED #define __PRINT(label, ...) \ do { \ fprintf(stderr, "[%s] %s at %s: ", label, \ __FILE__, __FUNCTION__); \ fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, "\n"); \ } while (0) \ #define LOG(...) __PRINT("log", __VA_ARGS__) #define DEBUG(...) __PRINT("debug", __VA_ARGS__) #else #define LOG(...) #define DEBUG(...) #endif #define XIM_VERSION "2.0.3" #define XIM_PROGRAM_NAME "SunPinyin-XIM" #define XIM_WEBSITE "http://mike.struct.cn/sunpinyin-xim" #define XIM_COMMENTS "a XIM front-end for SunPinyin." #endif /* _COMMON_H_ */ xsunpinyin-2.0.3/xim_trigger.c0000644000076400007640000001304211527365010015070 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include "xim.h" #include "ic.h" #include "common.h" #include "settings.h" #include static void __toggle_preedit_status(XIMHandle* handle, bool flag) { if (flag) xim_start_preedit(handle); else xim_cancel_preedit(handle); } static bool last_shift_available = false; static bool __filter_forward_triger_key(XIMHandle* handle, IC* ic, XKeyEvent* evt) { KeySym sym = 0; hotkey_t hk; settings_get(TRIGGER_KEY, &hk); XLookupString(evt, NULL, 0, &sym, NULL); unsigned int masked_state = (evt->state & STATE_MASK); if (masked_state == hk.modifiers && sym == hk.keysym) { if (evt->type == KeyRelease) return true; ic->is_enabled = !ic->is_enabled; __toggle_preedit_status(handle, ic->is_enabled); icmgr_refresh(); return true; } settings_get(ENG_KEY, &hk); if ((masked_state & hk.modifiers) == hk.modifiers && sym == hk.keysym) { if (evt->type == KeyPress) { last_shift_available = true; return true; } else if (evt->type == KeyRelease && last_shift_available) { last_shift_available = false; if (ic->is_enabled) { ic->is_english = !ic->is_english; icmgr_refresh(); } } return true; } else { last_shift_available = false; } return false; } static void __do_forward_event(XIMHandle* handle, IMForwardEventStruct* proto) { /* by pass the event */ IMForwardEventStruct fe; memset(&fe, 0, sizeof (fe)); fe.major_code = XIM_FORWARD_EVENT; fe.icid = proto->icid; fe.connect_id = proto->connect_id; fe.sync_bit = 0; fe.serial_number = 0L; fe.event = proto->event; IMForwardEvent(handle, (XPointer) &fe); } extern void __move_preedit(IC* ic); int _xim_forward_event(XIMHandle* handle, IMForwardEventStruct* proto) { LOG("%d", proto->icid); XKeyEvent* evt = (XKeyEvent*) &(proto->event); IC* ic = icmgr_get_current(); if (ic == NULL) { icmgr_set_current(proto->icid); ic = icmgr_get_current(); if (ic == NULL) return 1; } /* some of swing applications like netbeans won't set focus, * we have to set focus ourself */ if (ic->icid != proto->icid || preedit_status() == false) { icmgr_set_current(proto->icid); ic = icmgr_get_current(); icmgr_refresh(); } if (!__filter_forward_triger_key(handle, ic, evt)) { int masked_state = evt->state & STATE_MASK; if (masked_state != ShiftMask && masked_state != 0) { __do_forward_event(handle, proto); } else if (!ic->is_enabled || ic->is_english) { __do_forward_event(handle, proto); } else { KeySym sym; XLookupString(evt, NULL, 0, &sym, NULL); if ((sym <= 0x20 || sym > 0x7E) && preedit_status() == false) { __do_forward_event(handle, proto); } else if (sym >= 0x30 && sym <= 0x39 && preedit_status() == false) { // digit key pressed if (settings_get_int(SMART_PUNCT) && evt->type == KeyPress) { preedit_omit_next_punct(); } __do_forward_event(handle, proto); } else { if (evt->type == KeyPress) { __move_preedit(ic); preedit_on_key(handle, sym, evt->state); } else { LOG("ignore"); } } } } return 1; } xsunpinyin-2.0.3/settings.c0000644000076400007640000002640311527365010014415 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include #include #include #include #include #include "common.h" #include "xmisc.h" #include "settings.h" typedef void (*serialize_func_t)(char* str, void* data); static const char* setting_names[] = { "trigger_key", "eng_key", "icbar_pos", "preedit_opacity", "preedit_color", "preedit_font", "preedit_font_color", "shuangpin", "shuangpin_scheme", "candidates_size", "page_minus_plus", "page_comma_period", "page_paren", "fuzzy_inner_segmentation", "fuzzy_segmentation", "cancel_on_backspace", "smart_punct", "skin_name", NULL }; static void* setting_data[MAX_KEY]; static size_t setting_size[MAX_KEY]; static serialize_func_t setting_enc[MAX_KEY]; static serialize_func_t setting_dec[MAX_KEY]; static void __varchar_enc(char* str, void* data) { strncpy(str, data, 128); } static void __varchar_dec(char* str, void* data) { strncpy(data, str, 128); } static void __double_enc(char* str, void* data) { double* ptr = data; snprintf(str, 256, "%.2lf", *ptr); } static void __double_dec(char* str, void* data) { double* ptr = data; sscanf(str, "%lf", ptr); } static void __int_enc(char* str, void* data) { int* ptr = data; snprintf(str, 256, "%d", *ptr); } static void __int_dec(char* str, void* data) { int* ptr = data; sscanf(str, "%d", ptr); } static void __position_enc(char* str, void* data) { position_t* pos = data; snprintf(str, 256, "%d,%d", pos->x, pos->y); } static void __position_dec(char* str, void* data) { position_t* pos = data; sscanf(str, "%d,%d", &pos->x, &pos->y); } static const int kmap_keysym[] = { XK_Shift_L, XK_Shift_R, XK_Control_L, XK_Control_R, XK_Meta_L, XK_Meta_R, XK_space, }; static const char* kmap_text[] = { "Shift_L", "Shift_R", "Control_L", "Control_R", "Meta_L", "Meta_R", "space", }; const int nkmap = 7; static void __hotkey_enc(char* str, void* data) { hotkey_t* hk = data; if (hk->modifiers & ControlMask) { strncat(str, "Control+", 255); } if (hk->modifiers & ShiftMask) { strncat(str, "Shift+", 255); } char keyname[256]; memset(keyname, 0, sizeof(char) * 256); int i; for (i = 0; i < nkmap + 1; i++) { if (i == nkmap) { keyname[0] = hk->keysym - 0x0020; break; } else if (hk->keysym == kmap_keysym[i]) { strncpy(keyname, kmap_text[i], 255); break; } } strncat(str, keyname, 255); } static void __hotkey_dec(char* str, void* data) { hotkey_t* hk = data; hk->keysym = 0; hk->modifiers = 0; char* last_ptr = str; char text[256]; while (1) { char* ptr = strchr(last_ptr, '+'); memset(text, 0, sizeof(char) * 256); if (ptr == NULL) strcpy(text, last_ptr); else strncpy(text, last_ptr, (ptr - last_ptr) * sizeof(char)); if (ptr == NULL) { int i; for (i = 0; i < nkmap + 1; i++) { if (i == nkmap) { hk->keysym = text[0] + 0x0020; break; } else if (strcmp(text, kmap_text[i]) == 0) { hk->keysym = kmap_keysym[i]; break; } } break; } else { if (strcmp(text, "Control") == 0) hk->modifiers |= ControlMask; if (strcmp(text, "Shift") == 0) hk->modifiers |= ShiftMask; } last_ptr = ptr + 1; } } static void __init_default_values() { hotkey_t hk; position_t pos; double d; varchar str; int i; /* trigger key */ hk.modifiers = ControlMask; hk.keysym = XK_space; settings_set(TRIGGER_KEY, &hk); /* eng key */ hk.modifiers = 0; hk.keysym = XK_Shift_L; settings_set(ENG_KEY, &hk); get_screen_size(&(pos.x), &(pos.y)); pos.x -= 200; pos.y -= 70; settings_set(ICBAR_POS, &pos); /* preedit opacity */ settings_set_double(PREEDIT_OPACITY, 1.0); settings_set_string(PREEDIT_COLOR, "#FFFFB3"); settings_set_string(PREEDIT_FONT, "Sans 10"); settings_set_string(PREEDIT_FONT_COLOR, "#000000"); settings_set_int(SHUANGPIN, 0); settings_set_string(SHUANGPIN_SCHEME, "MS2003"); settings_set_int(CANDIDATES_SIZE, 10); /* page up and down trigger */ settings_set_int(PAGE_MINUS_PLUS, 1); settings_set_int(PAGE_COMMA_PERIOD, 0); settings_set_int(PAGE_PAREN, 0); /* fuzzy segmentation */ settings_set_int(FUZZY_SEGMENTATION, 0); settings_set_int(FUZZY_INNER_SEGMENTATION, 0); /* cancel on backspace */ settings_set_int(CANCEL_ON_BACKSPACE, 1); /* smart punctuation */ settings_set_int(SMART_PUNCT, 0); /* skin support */ settings_set_string(SKIN_NAME, "classic"); } #define REGISTER(k, type, efunc, dfunc) \ do { \ setting_data[k] = malloc(sizeof(type)); \ setting_size[k] = sizeof(type); \ setting_enc[k] = efunc; \ setting_dec[k] = dfunc; \ } while(0) \ void settings_init() { memset(setting_data, 0, sizeof(void*) * MAX_KEY); REGISTER(TRIGGER_KEY, hotkey_t, __hotkey_enc, __hotkey_dec); REGISTER(ENG_KEY, hotkey_t, __hotkey_enc, __hotkey_dec); REGISTER(ICBAR_POS, position_t, __position_enc, __position_dec); REGISTER(PREEDIT_OPACITY, double, __double_enc, __double_dec); REGISTER(PREEDIT_COLOR, varchar, __varchar_enc, __varchar_dec); REGISTER(PREEDIT_FONT, varchar, __varchar_enc, __varchar_dec); REGISTER(PREEDIT_FONT_COLOR, varchar, __varchar_enc, __varchar_dec); REGISTER(SHUANGPIN, int, __int_enc, __int_dec); REGISTER(SHUANGPIN_SCHEME, varchar, __varchar_enc, __varchar_dec); REGISTER(CANDIDATES_SIZE, int, __int_enc, __int_dec); REGISTER(PAGE_MINUS_PLUS, int, __int_enc, __int_dec); REGISTER(PAGE_COMMA_PERIOD, int, __int_enc, __int_dec); REGISTER(PAGE_PAREN, int, __int_enc, __int_dec); REGISTER(FUZZY_SEGMENTATION, int, __int_enc, __int_dec); REGISTER(FUZZY_INNER_SEGMENTATION, int, __int_enc, __int_dec); REGISTER(CANCEL_ON_BACKSPACE, int, __int_enc, __int_dec); REGISTER(SMART_PUNCT, int, __int_enc, __int_dec); REGISTER(SKIN_NAME, varchar, __varchar_enc, __varchar_dec); __init_default_values(); } void settings_destroy() { int i = 0; while (setting_names[i] != NULL) { if (setting_data[i] != NULL) free(setting_data[i]); i++; } } #define SETTING_FILE ".sunpinyin/xim_config" #define DEFAULT_SETTING_FILE SUNPINYIN_XIM_SETTING_DIR"/xim_config_default" void settings_load() { char path[256]; char line[256]; snprintf(path, 256, "%s/%s", getenv("HOME"), SETTING_FILE); FILE *fp = fopen(path, "r"); if (fp == NULL) { char config_dir[256]; snprintf(config_dir, 256, "%s/.sunpinyin", getenv("HOME")); mkdir(config_dir, S_IRWXU); settings_save(); if ((fp = fopen(path, "r")) == NULL) return; } while (1) { memset(line, 0, sizeof(char) * 256); if (fgets(line, 256, fp) == NULL) break; if (line[0] == 0) break; /* strip the last \n */ line[strlen(line) - 1] = 0; /* bypass the comment */ if (line[0] == '#') continue; char* ptr = strchr(line, '='); int i = 0; while (setting_names[i] != NULL) { if (strncmp(line, setting_names[i], ptr - line) == 0) { serialize_func_t func = setting_dec[i]; func(ptr + 1, setting_data[i]); } i++; } } fclose(fp); } void settings_save() { char path[256]; char line[256]; snprintf(path, 256, "%s/%s", getenv("HOME"), SETTING_FILE); FILE *fp = fopen(path, "w"); if (fp == NULL) { LOG("settings can't be saved"); return; } int i = 0; while (setting_names[i] != NULL) { memset(line, 0, sizeof(char) * 256); serialize_func_t func = setting_enc[i]; func(line, setting_data[i]); fprintf(fp, "%s=%s\n", setting_names[i], line); i++; } fclose(fp); } int settings_get_int(setting_key_t key) { int ret = 0; settings_get(key, &ret); return ret; } double settings_get_double(setting_key_t key) { double ret = 0; settings_get(key, &ret); return ret; } void settings_get(setting_key_t key, void* data) { if (setting_data[key] == NULL) { LOG("invalid setting key %d to get", key); return; } memcpy(data, setting_data[key], setting_size[key]); } void settings_set_int(setting_key_t key, int value) { settings_set(key, &value); } void settings_set_double(setting_key_t key, double value) { settings_set(key, &value); } void settings_set_string(setting_key_t key, const char* str) { varchar vchar; strncpy(vchar, str, sizeof(varchar)); settings_set(key, vchar); } void settings_set(setting_key_t key, void* data) { if (setting_data[key] == NULL) { LOG("invalid setting key %d to set", key); return; } memcpy(setting_data[key], data, setting_size[key]); } xsunpinyin-2.0.3/settings.h0000644000076400007640000000631711527365010014424 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _SETTINGS_H_ #define _SETTINGS_H_ #include #include #include #include #include "common.h" __BEGIN_DECLS typedef struct { int x; int y; } position_t; typedef struct { int modifiers; int keysym; } hotkey_t; typedef char varchar[128]; typedef enum { TRIGGER_KEY = 0, ENG_KEY, ICBAR_POS, PREEDIT_OPACITY, PREEDIT_COLOR, PREEDIT_FONT, PREEDIT_FONT_COLOR, SHUANGPIN, SHUANGPIN_SCHEME, CANDIDATES_SIZE, PAGE_MINUS_PLUS, PAGE_COMMA_PERIOD, PAGE_PAREN, FUZZY_SEGMENTATION, FUZZY_INNER_SEGMENTATION, CANCEL_ON_BACKSPACE, SMART_PUNCT, SKIN_NAME, } setting_key_t; #define MAX_KEY 0xFF void settings_init(); void settings_destroy(); void settings_load(); void settings_save(); void settings_get(setting_key_t key, void* data); void settings_set(setting_key_t key, void* data); void settings_set_int(setting_key_t key, int value); void settings_set_double(setting_key_t key, double value); void settings_set_string(setting_key_t key, const char* str); int settings_get_int(setting_key_t key); double settings_get_double(setting_key_t key); __END_DECLS #endif /* _SETTINGS_H_ */ xsunpinyin-2.0.3/sunpinyin_preedit_ui.h0000644000076400007640000001022011527365010017015 0ustar mikemike/* -*- mode: c++ -*- */ /* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _SUNPINYIN_PREEDIT_H_ #define _SUNPINYIN_PREEDIT_H_ #include #include #include #include #include "xmisc.h" #include "skin.h" #include "ui.h" class PreeditUI { std::string name_; public: PreeditUI(std::string name) throw() : name_(name) {} virtual ~PreeditUI() {} std::string name() { return name_; } virtual void show() = 0; virtual void hide() = 0; virtual void move(int x, int y) = 0; virtual void reload() = 0; virtual void update_preedit_string(const char* utf_str) = 0; virtual void update_candidates_string(const char* utf_str) = 0; }; class GtkPreeditUI : public PreeditUI { public: GtkPreeditUI(); virtual ~GtkPreeditUI(); protected: virtual void show(); virtual void hide(); virtual void move(int x, int y); virtual void reload(); virtual void update_preedit_string(const char* utf_str); virtual void update_candidates_string(const char* utf_str); private: GtkWidget* main_wnd_; GtkWidget* preedit_area_; GtkWidget* candidate_area_; }; class SkinLoaderException: public std::exception { public: const char* what() const throw() { return "Cannot load skin!"; } }; class SkinPreeditUI : public PreeditUI { public: SkinPreeditUI(std::string name) throw(); virtual ~SkinPreeditUI(); protected: virtual void show(); virtual void hide(); virtual void move(int x, int y); virtual void reload(); virtual void update_preedit_string(const char* utf_str); virtual void update_candidates_string(const char* utf_str); private: void adjust_size(); void internal_move(int x, int y); private: skin_window_t* main_wnd_; skin_label_t* preedit_label_; skin_label_t* candidate_label_; skin_info_t* info_; }; inline PreeditUI* create_preedit_ui(std::string name) { if (name == "classic") { return new GtkPreeditUI(); } else { try { return new SkinPreeditUI(name); } catch (const SkinLoaderException& ex) { fprintf(stderr, "%s\n", ex.what()); exit(-1); } } } #endif /* _SUNPINYIN_PREEDIT_H_ */ xsunpinyin-2.0.3/main.c0000644000076400007640000000730511527365010013501 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include #include #include #include "xim.h" #include "xmisc.h" #include "ic.h" #include "settings.h" #define XIM_NAME "xsunpinyin" static void finalize(void) { preedit_finalize(); icmgr_finalize(); settings_save(); settings_destroy(); } static void on_app_sig(int sig) { if (sig == SIGUSR1) { /* reload the settings */ settings_load(); preedit_reload(); } else { exit(0); } } #define ALL_LOCALES_STRING "ca,cs,en,es,et,eu,fr,zh,zu" int main(int argc, char* argv[]) { if (argc == 2 && strcmp(argv[1], "-d") == 0) { int pid = fork(); if (pid < 0) return -1; else if (pid > 0) return 0; } init_display(&argc, &argv); settings_init(); settings_load(); preedit_init(); /* check if the codeset is utf-8 */ if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) { fprintf(stderr, "Warning: using codeset %s might cause xsunpinyin unable to trigger.\n", nl_langinfo(CODESET)); } /* guess the locale */ char* locale = getenv("LC_CTYPE"); if (locale == NULL) { locale = getenv("LANG"); if (locale == NULL) { fprintf(stderr, "Can't guess locale.\n"); return -1; } } char final_locale[256]; snprintf(final_locale, 256, "%s,%s", ALL_LOCALES_STRING, locale); XIMHandle* hdl = create_xim_server(XIM_NAME, final_locale); preedit_set_handle(hdl); preedit_reload(); signal(SIGUSR1, on_app_sig); signal(SIGHUP, on_app_sig); signal(SIGINT, on_app_sig); signal(SIGTERM, on_app_sig); atexit(finalize); gtk_main(); return 0; } xsunpinyin-2.0.3/skin.c0000644000076400007640000004507211527365010013524 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include #include "skin.h" struct _skin_window_priv_t { skin_label_t* labels; skin_button_t* btns; /* current expose environment */ skin_button_t* highlight_btn; skin_button_t* pressdown_btn; GCallback press_cb; GCallback release_cb; GCallback motion_cb; void* press_cb_data; void* release_cb_data; void* motion_cb_data; /* drag to move positions */ gboolean enable_drag_to_move; int drag_init_x; int drag_init_y; gboolean drag_begin; }; struct _skin_button_priv_t { skin_button_t* next; skin_window_t* parent; GCallback press_cb; GCallback release_cb; void* press_cb_data; void* release_cb_data; }; struct _skin_label_priv_t { skin_label_t* next; skin_window_t* wind; }; static void zoom_and_composite(GdkPixbuf* src, GdkPixbuf* dst, int x, int y, int width, int height, int dst_x, int dst_y, int dst_width, int dst_height) { if (width <= 0 || height <= 0 || dst_width <= 0 || dst_height <= 0) return; GdkPixbuf* sub = gdk_pixbuf_new_subpixbuf(src, x, y, width, height); double x_scale = 1.0 * dst_width / width; double y_scale = 1.0 * dst_height / height; gdk_pixbuf_scale(sub, dst, dst_x, dst_y, dst_width, dst_height, dst_x, dst_y, x_scale, y_scale, GDK_INTERP_BILINEAR); g_object_unref(sub); } static void cairo_paint_pixbuf(cairo_t* cr, GdkPixbuf* buf, int off_x, int off_y) { gdk_cairo_set_source_pixbuf(cr, buf, off_x, off_y); cairo_paint(cr); } static void paint_background_with_mask(GtkWidget* wid, skin_window_t* wind) { GdkPixbuf* bg = wind->background_image; int width, height; int bg_width, bg_height; int top, left, bottom, right; width = wid->allocation.width; height = wid->allocation.height; bg_width = gdk_pixbuf_get_width(bg); bg_height = gdk_pixbuf_get_height(bg); top = wind->margin_top; left = wind->margin_left; right = wind->margin_right; bottom = wind->margin_bottom; GdkPixbuf* newbg = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); // 4 corners gdk_pixbuf_copy_area(bg, 0, 0, left, top, newbg, 0, 0); gdk_pixbuf_copy_area(bg, bg_width - right, 0, right, top, newbg, width - right, 0); gdk_pixbuf_copy_area(bg, 0, bg_height - bottom, left, bottom, newbg, 0, height - bottom); gdk_pixbuf_copy_area(bg, bg_width - right, bg_height - bottom, right, bottom, newbg, width - right, height - bottom); // 4 margins and the center area int content_width = bg_width - left - right; int content_height = bg_height - top - bottom; int new_content_width = width - left - right; int new_content_height = height - top - bottom; // top zoom_and_composite(bg, newbg, left, 0, content_width, top, left, 0, new_content_width, top); // bottom zoom_and_composite(bg, newbg, left, bg_height - bottom, content_width, bottom, left, height - bottom, new_content_width, bottom); // left zoom_and_composite(bg, newbg, 0, top, left, content_height, 0, top, left, new_content_height); // right zoom_and_composite(bg, newbg, bg_width - right, top, right, content_height, width - right, top, right, new_content_height); // center zoom_and_composite(bg, newbg, left, top, content_width, content_height, left, top, new_content_width, new_content_height); gdk_window_clear(wid->window); // paint it cairo_t* cr = gdk_cairo_create(wid->window); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); cairo_paint(cr); cairo_paint_pixbuf(cr, newbg, 0, 0); cairo_destroy(cr); // set the mask GdkBitmap* mask; gdk_pixbuf_render_pixmap_and_mask(newbg, NULL, &mask, wind->alpha_mask_threshold); gdk_window_shape_combine_mask(wid->window, mask, 0, 0); g_object_unref(newbg); } static void paint_buttons(GtkWidget* wid, skin_window_t* wind) { cairo_t* cr = gdk_cairo_create(wid->window); skin_button_t* btn = wind->priv->btns; for (; btn != NULL; btn = btn->priv->next) { if (btn == wind->priv->pressdown_btn) { cairo_paint_pixbuf(cr, btn->pressdown_image, btn->x, btn->y); } else if (btn == wind->priv->highlight_btn) { cairo_paint_pixbuf(cr, btn->highlight_image, btn->x, btn->y); } else { cairo_paint_pixbuf(cr, btn->normal_image, btn->x, btn->y); } } cairo_destroy(cr); } static void paint_labels(GtkWidget* wid, skin_window_t* wind) { cairo_t* cr = gdk_cairo_create(wid->window); skin_label_t* label = wind->priv->labels; for (; label != NULL; label = label->priv->next) { cairo_set_source_rgba(cr, label->color_r, label->color_g, label->color_b, label->color_a); if (label->layout == NULL) { label->layout = pango_cairo_create_layout(cr); pango_layout_set_font_description( label->layout, pango_font_description_from_string(label->font)); } pango_layout_set_text(label->layout, label->text, -1); cairo_move_to(cr, label->x, label->y); pango_cairo_layout_path(cr, label->layout); cairo_fill(cr); } cairo_destroy(cr); } static gboolean window_on_expose(GtkWidget* wid, GdkEventExpose* evt, skin_window_t* wind) { paint_background_with_mask(wid, wind); paint_labels(wid, wind); paint_buttons(wid, wind); return TRUE; } static gboolean window_on_configure(GtkWidget* wid, GdkEventConfigure* evt, skin_window_t* wind) { gtk_widget_queue_draw(wid); return FALSE; } static skin_button_t* find_button(skin_window_t* wind, int pos_x, int pos_y) { skin_button_t* btn = wind->priv->btns; for (; btn != NULL; btn = btn->priv->next) { int x = btn->x, y = btn->y, width = btn->width, height = btn->height; if (pos_x > x && pos_y > y && pos_x < x + width && pos_y < y + height) { return btn; } } return NULL; } static gboolean set_expose_env(skin_window_t* wind, skin_button_t* highlight, skin_button_t* down) { gboolean ret = FALSE; if (wind->priv->highlight_btn != highlight) { ret |= TRUE; wind->priv->highlight_btn = highlight; } if (wind->priv->pressdown_btn != down) { ret |= TRUE; wind->priv->pressdown_btn = down; } return ret; } typedef gboolean (*motion_cb_t) (GtkWidget*, GdkEventMotion*, void*); typedef gboolean (*mouse_cb_t) (GtkWidget*, GdkEventButton*, void*); static gboolean window_on_motion(GtkWidget* wid, GdkEventMotion* evt, skin_window_t* wind) { skin_button_t* btn = find_button(wind, evt->x, evt->y); gboolean need_redraw = FALSE; if (btn) { if ((evt->state & GDK_BUTTON1_MASK) != 0 || (evt->state & GDK_BUTTON2_MASK) != 0 || (evt->state & GDK_BUTTON3_MASK) != 0) { need_redraw = set_expose_env(wind, NULL, btn); } else { need_redraw = set_expose_env(wind, btn, NULL); } } else { /* move it if drag */ if (wind->priv->enable_drag_to_move && wind->priv->drag_begin) { gtk_window_move(GTK_WINDOW(wind->widget), evt->x_root - wind->priv->drag_init_x, evt->y_root - wind->priv->drag_init_y); } need_redraw = set_expose_env(wind, NULL, NULL); motion_cb_t cb = (motion_cb_t) wind->priv->motion_cb; if (cb) { cb(wid, evt, wind->priv->motion_cb_data); } } if (need_redraw) { gtk_widget_queue_draw(wid); } return TRUE; } static gboolean window_on_press_or_release(GtkWidget* wid, GdkEventButton* evt, skin_window_t* wind, gboolean press) { skin_button_t* btn = find_button(wind, evt->x, evt->y); gboolean need_redraw = FALSE; skin_button_t* highlight_btn = NULL; skin_button_t* pressdown_btn = NULL; mouse_cb_t btncb = NULL; mouse_cb_t wincb = NULL; if (press) { wincb = (mouse_cb_t) wind->priv->press_cb; pressdown_btn = btn; if (!btn) { /* update drag init positions */ wind->priv->drag_init_x = evt->x; wind->priv->drag_init_y = evt->y; wind->priv->drag_begin = wind->priv->enable_drag_to_move; } else { btncb = (mouse_cb_t) btn->priv->press_cb; } } else { wincb = (mouse_cb_t) wind->priv->release_cb; highlight_btn = btn; if (!btn) { wind->priv->drag_begin = FALSE; } else { btncb = (mouse_cb_t) btn->priv->release_cb; } } if (btn) { need_redraw = set_expose_env(wind, highlight_btn, pressdown_btn); if (btncb) { btncb(wid, evt, btn->priv->press_cb_data); } } else { if (wincb) { wincb(wid, evt, wind->priv->press_cb_data); } } if (need_redraw) { gtk_widget_queue_draw(wid); } return TRUE; } static gboolean window_on_press(GtkWidget* wid, GdkEventButton* evt, skin_window_t* wind) { return window_on_press_or_release(wid, evt, wind, TRUE); } static gboolean window_on_release(GtkWidget* wid, GdkEventButton* evt, skin_window_t* wind) { return window_on_press_or_release(wid, evt, wind, FALSE); } skin_window_t* skin_window_new(GtkWindow* widget, GdkPixbuf* background_image, int margin_top, int margin_left, int margin_bottom, int margin_right, int alpha_mask_threshold) { skin_window_t* wind = malloc(sizeof(skin_window_t)); wind->widget = GTK_WIDGET(widget); wind->background_image = background_image; wind->margin_top = margin_top; wind->margin_left = margin_left; wind->margin_bottom = margin_bottom; wind->margin_right = margin_right; wind->alpha_mask_threshold = alpha_mask_threshold; wind->priv = malloc(sizeof(skin_window_priv_t)); memset(wind->priv, 0, sizeof(skin_window_priv_t)); gtk_window_set_default_size(widget, gdk_pixbuf_get_width(background_image), gdk_pixbuf_get_height(background_image)); /* set rgba */ GdkScreen* screen = gdk_screen_get_default(); GdkColormap* cmap = gdk_screen_get_rgba_colormap(screen); if (cmap) { gtk_widget_set_colormap(wind->widget, cmap); } else { fprintf(stderr, "Cannot set rgba colormap!\n"); } /* signal expose */ gtk_widget_set_events(wind->widget, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); gtk_widget_realize(wind->widget); g_signal_connect(wind->widget, "expose-event", G_CALLBACK(window_on_expose), wind); g_signal_connect(wind->widget, "configure-event", G_CALLBACK(window_on_configure), wind); g_signal_connect(wind->widget, "motion-notify-event", G_CALLBACK(window_on_motion), wind); g_signal_connect(wind->widget, "button-press-event", G_CALLBACK(window_on_press), wind); g_signal_connect(wind->widget, "button-release-event", G_CALLBACK(window_on_release), wind); return wind; } void skin_window_destroy(skin_window_t* wind) { gtk_widget_destroy(wind->widget); free(wind->priv); free(wind); } void skin_window_add_button(skin_window_t* wind, skin_button_t* btn, int x, int y) { /* append to the buttons list */ btn->priv->next = wind->priv->btns; wind->priv->btns = btn; btn->priv->parent = wind; btn->x = x; btn->y = y; } void skin_window_set_drag_to_move(skin_window_t* wind, gboolean drag_to_move) { wind->priv->enable_drag_to_move = drag_to_move; } skin_button_t* skin_button_new(GdkPixbuf* normal_image, GdkPixbuf* highlight_image, GdkPixbuf* pressdown_image) { skin_button_t* btn = malloc(sizeof(skin_button_t)); btn->normal_image = normal_image; btn->highlight_image = highlight_image; btn->pressdown_image = pressdown_image; btn->width = gdk_pixbuf_get_width(normal_image); btn->height = gdk_pixbuf_get_height(normal_image); btn->priv = malloc(sizeof(skin_button_priv_t)); memset(btn->priv, 0, sizeof(skin_button_priv_t)); return btn; } void skin_button_destroy(skin_button_t* btn) { free(btn->priv); free(btn); } void skin_button_set_image(skin_button_t* btn, GdkPixbuf* normal_image, GdkPixbuf* highlight_image, GdkPixbuf* pressdown_image) { /* since we're redraw it, we'd better check if we really changed the pixbuf. This can save a lot of time. */ gboolean need_set = (btn->normal_image != normal_image) || (btn->highlight_image != highlight_image) || (btn->pressdown_image != pressdown_image); if (!need_set) return; btn->normal_image = normal_image; btn->highlight_image = highlight_image; btn->pressdown_image = pressdown_image; if (btn->priv->parent) { gtk_widget_queue_draw(btn->priv->parent->widget); } } skin_label_t* skin_label_new(char* font, char* text, double color_r, double color_g, double color_b, double color_a) { skin_label_t* label = malloc(sizeof(skin_label_t)); label->color_r = color_r; label->color_g = color_g; label->color_b = color_b; label->color_a = color_a; label->font = strdup(font); if (text) { label->text = strdup(text); } else { label->text = NULL; } label->layout = NULL; label->priv = malloc(sizeof(skin_label_priv_t)); memset(label->priv, 0, sizeof(skin_label_priv_t)); return label; } void skin_label_destroy(skin_label_t* label) { free(label->text); free(label->font); free(label->priv); if (label->layout) { g_object_unref(label->layout); } free(label); } void skin_window_add_label(skin_window_t* wind, skin_label_t* label, int x, int y) { label->x = x; label->y = y; label->priv->wind = wind; label->priv->next = wind->priv->labels; wind->priv->labels = label; cairo_t* cr = gdk_cairo_create(wind->widget->window); label->layout = pango_cairo_create_layout(cr); pango_layout_set_font_description( label->layout, pango_font_description_from_string(label->font)); cairo_destroy(cr); } void skin_label_set_text(skin_label_t* label, const char* text) { free(label->text); if (text) { label->text = strdup(text); pango_layout_set_text(label->layout, label->text, -1); } else { label->text = NULL; } if (label->layout && label->priv->wind) { gtk_widget_queue_draw(label->priv->wind->widget); } } #define SET_CB_IMPL(name, event) \ void skin_##name##_set_##event##_cb(skin_##name##_t* wid, \ GCallback cb, \ void* data) \ { wid->priv->event##_cb = cb; wid->priv->event##_cb_data = data; } \ SET_CB_IMPL(window, press); SET_CB_IMPL(window, release); SET_CB_IMPL(window, motion); SET_CB_IMPL(button, press); SET_CB_IMPL(button, release); xsunpinyin-2.0.3/skin.h0000644000076400007640000001375011527365010013527 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #ifndef _SKIN_H_ #define _SKIN_H_ #include #include #include "common.h" __BEGIN_DECLS typedef struct _skin_button_priv_t skin_button_priv_t; typedef struct _skin_button_t skin_button_t; typedef struct _skin_label_priv_t skin_label_priv_t; typedef struct _skin_label_t skin_label_t; typedef struct _skin_window_priv_t skin_window_priv_t; typedef struct _skin_window_t skin_window_t; struct _skin_button_t { int x, y; int width, height; GdkPixbuf* normal_image; GdkPixbuf* highlight_image; GdkPixbuf* pressdown_image; skin_button_priv_t* priv; }; struct _skin_label_t { int x, y; double color_r, color_g, color_b, color_a; char* font; char* text; PangoLayout* layout; skin_label_priv_t* priv; }; struct _skin_window_t { GtkWidget* widget; GdkPixbuf* background_image; int margin_top; int margin_left; int margin_bottom; int margin_right; int alpha_mask_threshold; skin_window_priv_t* priv; }; skin_window_t* skin_window_new(GtkWindow* window, GdkPixbuf* background_image, int margin_top, int margin_left, int margin_bottom, int margin_right, int alpha_mask_threshold); void skin_window_destroy(skin_window_t* wind); void skin_window_set_drag_to_move(skin_window_t* wind, gboolean drag_to_move); void skin_window_add_button(skin_window_t* wind, skin_button_t* btn, int x, int y); void skin_window_add_label(skin_window_t* wind, skin_label_t* label, int x, int y); void skin_window_set_motion_cb(skin_window_t* wind, GCallback cb, void* data); void skin_window_set_press_cb(skin_window_t* wind, GCallback cb, void* data); void skin_window_set_release_cb(skin_window_t* wind, GCallback cb, void* data); skin_button_t* skin_button_new(GdkPixbuf* normal_image, GdkPixbuf* highlight_image, GdkPixbuf* down_image); void skin_button_destroy(skin_button_t* btn); void skin_button_set_image(skin_button_t* btn, GdkPixbuf* normal_image, GdkPixbuf* highlight_image, GdkPixbuf* pressdown_image); void skin_button_set_press_cb(skin_button_t* wind, GCallback cb, void* data); void skin_button_set_release_cb(skin_button_t* wind, GCallback cb, void* data); skin_label_t* skin_label_new(char* font, char* text, double color_r, double color_g, double color_b, double color_a); void skin_label_destroy(skin_label_t* label); void skin_label_set_text(skin_label_t* label, const char* text); __END_DECLS #endif /* _SKIN_H_ */ xsunpinyin-2.0.3/sunpinyin_preedit.cc0000644000076400007640000002445411527365010016474 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include #include "xim.h" #include "common.h" #include "settings.h" #include "sunpinyin_preedit_ui.h" #define BUF_SIZE 4096 class WindowHandler : public CIMIWinHandler { protected: virtual void updatePreedit(const IPreeditString* ppd); virtual void updateCandidates(const ICandidateList* pcl); //virtual void updateStatus(int key, int value); virtual void commit(const TWCHAR* str); private: PreeditUI* ui_impl_; public: WindowHandler(); virtual ~WindowHandler(); PreeditUI* preedit_ui_impl() { return ui_impl_; } void set_preedit_ui_impl(PreeditUI* ui_impl) { ui_impl_ = ui_impl; } void set_xim_handle(XIMHandle* handle) { handle_ = handle; } bool status() { return status_; } void update_preedit_ui(const IPreeditString* ppd, const char* utf_str); void update_candidates_ui(const ICandidateList* pcl, const char* utf_str); void pause(); void move(int x, int y); void go_on(); void reload_ui(); private: XIMHandle* handle_; char* preedit_str_; char* candidate_str_; bool status_; bool pause_; int x_, y_; }; WindowHandler::WindowHandler() { preedit_str_ = new char[BUF_SIZE]; candidate_str_ = new char[BUF_SIZE]; status_ = false; pause_ = false; ui_impl_ = NULL; handle_ = NULL; x_ = y_ = 0; } WindowHandler::~WindowHandler() { delete [] preedit_str_; delete [] candidate_str_; } void WindowHandler::reload_ui() { ui_impl_->reload(); ui_impl_->update_preedit_string(preedit_str_); ui_impl_->update_candidates_string(candidate_str_); if (status_) { ui_impl_->show(); ui_impl_->move(x_, y_); } else { ui_impl_->hide(); } } void WindowHandler::pause() { if (status_) { ui_impl_->hide(); status_ = false; pause_ = true; } } void WindowHandler::move(int x, int y) { x_ = x; y_ = y; if (ui_impl_) { ui_impl_->move(x, y); } } void WindowHandler::go_on() { if (!status_ && pause_) { ui_impl_->show(); status_ = true; pause_ = false; } } void WindowHandler::update_candidates_ui(const ICandidateList* pcl, const char* utf_str) { ui_impl_->update_candidates_string(utf_str); if (status_) { ui_impl_->show(); } else { ui_impl_->hide(); } } void WindowHandler::update_preedit_ui(const IPreeditString* ppd, const char* utf_str) { ui_impl_->update_preedit_string(utf_str); if (ppd->size() == 0) { status_ = false; } else { status_ = true; } } void WindowHandler::updatePreedit(const IPreeditString* ppd) { TIConvSrcPtr src = (TIConvSrcPtr) (ppd->string()); TWCHAR* front_src = new TWCHAR[BUF_SIZE]; TWCHAR* end_src = new TWCHAR[BUF_SIZE]; memset(front_src, 0, BUF_SIZE * sizeof(TWCHAR)); memset(end_src, 0, BUF_SIZE * sizeof(TWCHAR)); memcpy(front_src, src, ppd->caret() * sizeof(TWCHAR)); memcpy(end_src, src + ppd->caret() * sizeof(TWCHAR), (ppd->size() - ppd->caret() + 1) * sizeof(TWCHAR)); memset(preedit_str_, 0, BUF_SIZE); WCSTOMBS(preedit_str_, front_src, BUF_SIZE - 1); preedit_str_[strlen(preedit_str_)] = '|'; WCSTOMBS(&preedit_str_[strlen(preedit_str_)], end_src, BUF_SIZE - 1); // update within the ui provider update_preedit_ui(ppd, preedit_str_); delete [] front_src; delete [] end_src; } void WindowHandler::updateCandidates(const ICandidateList* pcl) { wstring cand_str; for (int i = 0, sz = pcl->size(); i < sz; i++) { const TWCHAR* pcand = pcl->candiString(i); if (pcand == NULL) break; cand_str += (i == 9) ? '0' : TWCHAR('1' + i); cand_str += TWCHAR('.'); cand_str += pcand; cand_str += TWCHAR(' '); } TIConvSrcPtr src = (TIConvSrcPtr)(cand_str.c_str()); WCSTOMBS(candidate_str_, (const TWCHAR*) src, BUF_SIZE - 1); // update within the ui provider update_candidates_ui(pcl, candidate_str_); } void WindowHandler::commit(const TWCHAR* str) { char* buf = new char[BUF_SIZE]; memset(buf, 0, BUF_SIZE); WCSTOMBS(buf, str, BUF_SIZE - 1); if (handle_ != NULL) { xim_commit_preedit(handle_, buf); } delete [] buf; } static PreeditUI* ui_impl = NULL; static WindowHandler* instance = NULL; static CIMIView* view = NULL; __EXPORT_API void preedit_init() { CSunpinyinSessionFactory& fac = CSunpinyinSessionFactory::getFactory(); if (settings_get_int(SHUANGPIN)) { fac.setPinyinScheme(CSunpinyinSessionFactory::SHUANGPIN); // shuangpin schemes varchar scheme; settings_get(SHUANGPIN_SCHEME, scheme); if (strcmp(scheme, "MS2003") == 0) { AShuangpinSchemePolicy::instance().setShuangpinType(MS2003); } else if (strcmp(scheme, "ABC") == 0) { AShuangpinSchemePolicy::instance().setShuangpinType(ABC); } else if (strcmp(scheme, "ZiRanMa") == 0) { AShuangpinSchemePolicy::instance().setShuangpinType(ZIRANMA); } else if (strcmp(scheme, "PinYin++") == 0) { AShuangpinSchemePolicy::instance().setShuangpinType(PINYINJIAJIA); } else if (strcmp(scheme, "ZiGuang") == 0) { AShuangpinSchemePolicy::instance().setShuangpinType(ZIGUANG); } else if (strcmp(scheme, "XiaoHe") == 0) { AShuangpinSchemePolicy::instance().setShuangpinType(XIAOHE); } } else { fac.setPinyinScheme(CSunpinyinSessionFactory::QUANPIN); } view = fac.createSession(); varchar skin_name; settings_get(SKIN_NAME, skin_name); ui_impl = create_preedit_ui(skin_name); instance = new WindowHandler(); instance->set_preedit_ui_impl(ui_impl); view->getIC()->setCharsetLevel(1);// GBK view->attachWinHandler(instance); } __EXPORT_API void preedit_finalize(void) { LOG("preedit_finalizing..."); CSunpinyinSessionFactory& fac = CSunpinyinSessionFactory::getFactory(); fac.destroySession(view); delete ui_impl; delete instance; } __EXPORT_API void preedit_reload(void) { // number of candidates view->setCandiWindowSize(settings_get_int(CANDIDATES_SIZE)); // page up/down key CHotkeyProfile* prof = view->getHotkeyProfile(); prof->clear(); if (settings_get_int(PAGE_MINUS_PLUS)) { prof->addPageUpKey(CKeyEvent(IM_VK_MINUS)); prof->addPageDownKey(CKeyEvent(IM_VK_EQUALS)); } if (settings_get_int(PAGE_COMMA_PERIOD)) { prof->addPageUpKey(CKeyEvent(IM_VK_COMMA)); prof->addPageDownKey(CKeyEvent(IM_VK_PERIOD)); } if (settings_get_int(PAGE_PAREN)) { prof->addPageUpKey(CKeyEvent('[')); prof->addPageDownKey(CKeyEvent(']')); } // fuzzy segmentation bool enable_fuzzy = settings_get_int(FUZZY_SEGMENTATION); bool enable_inner = settings_get_int(FUZZY_INNER_SEGMENTATION); AQuanpinSchemePolicy::instance().setFuzzySegmentation(enable_fuzzy); AQuanpinSchemePolicy::instance().setInnerFuzzySegmentation(enable_inner); // cancel last selection on backspace view->setCancelOnBackspace(settings_get_int(CANCEL_ON_BACKSPACE)); // do we need to change the skin? varchar skin_name; settings_get(SKIN_NAME, skin_name); if (ui_impl->name() != skin_name) { delete ui_impl; ui_impl = create_preedit_ui(skin_name); instance->set_preedit_ui_impl(ui_impl); } instance->reload_ui(); } __EXPORT_API void preedit_set_handle(XIMHandle* handle) { instance->set_xim_handle(handle); } __EXPORT_API void preedit_move(int x, int y) { instance->move(x, y); } __EXPORT_API void preedit_pause(void) { instance->pause(); } __EXPORT_API void preedit_go_on(void) { instance->go_on(); } __EXPORT_API void preedit_on_key(XIMHandle* handle, unsigned int keycode, unsigned int state) { if (keycode < 0x20 && keycode > 0x7E) keycode = 0; view->onKeyEvent(CKeyEvent(keycode, keycode, state)); } __EXPORT_API bool preedit_status(void) { return instance->status(); } __EXPORT_API void preedit_set_full(bool full) { view->setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLSYMBOL, full); } __EXPORT_API void preedit_set_chinese_punc(bool chn_punc) { view->setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLPUNC, chn_punc); } __EXPORT_API void preedit_omit_next_punct() { view->getIC()->omitNextPunct(); } xsunpinyin-2.0.3/preferences.c0000644000076400007640000003364711527365010015066 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include #include #include #include #include #include #include #include #include #include "settings.h" #include "xmisc.h" #define UI_FILE SUNPINYIN_XIM_SETTING_DIR"/settings_ui.xml" static GtkWidget* main_wnd = NULL; static GtkToggleButton* trigger_ctrl_check = NULL; static GtkToggleButton* english_ctrl_check = NULL; static GtkToggleButton* trigger_shift_check = NULL; static GtkToggleButton* english_shift_check = NULL; static GtkComboBox* trigger_combo = NULL; static GtkComboBox* english_combo = NULL; static GtkColorButton* background_color_btn = NULL; static GtkFontButton* font_btn = NULL; static GtkColorButton* font_color_btn = NULL; static GtkAdjustment* opacity_value = NULL; static GtkAdjustment* ncandidates = NULL; static GtkToggleButton* minus_plus_check = NULL; static GtkToggleButton* comma_period_check = NULL; static GtkToggleButton* paren_check = NULL; static GtkToggleButton* fuzzy_seg_check = NULL; static GtkToggleButton* fuzzy_inner_seg_check = NULL; static GtkToggleButton* cancel_on_backspace_check = NULL; static GtkToggleButton* smart_punct_check = NULL; static GtkToggleButton* shuangpin_check = NULL; static GtkComboBox* shuangpin_combo = NULL; static GtkComboBox* skin_combo = NULL; #define RETRIEVE(name, macro) \ name = macro(gtk_builder_get_object(builder, # name)) static const char* ui_shuangpin_schemes[] = { "MS2003", "ABC", "ZiRanMa", "PinYin++", "ZiGuang", "XiaoHe", }; #define UI_SHUANGPIN_SCHEMES_NUM 6 static const int ui_keysym_model[] = { XK_space, XK_Control_L, XK_Control_R, XK_Shift_L, XK_Shift_R }; #define UI_KEYSYM_MODEL_NUM 5 #define INIT_KEY_SETTING(prefix) \ do { \ if (hk.modifiers & ControlMask) { \ gtk_toggle_button_set_active(prefix##_ctrl_check, TRUE); \ } \ if (hk.modifiers & ShiftMask) \ gtk_toggle_button_set_active(prefix##_shift_check, TRUE); \ int i; \ for (i = 0; i < UI_KEYSYM_MODEL_NUM; i++) { \ if (hk.keysym == ui_keysym_model[i]) { \ gtk_combo_box_set_active(prefix##_combo, i); \ break; \ } \ } \ } while(0) #define INIT_COLOR_SETTING(widget_name) \ do { \ GdkColor color; \ gdk_color_parse(colorstr, &color); \ gtk_color_button_set_color((widget_name), &color); \ } while(0) static int fill_skin_list(const char* dirpath, varchar names[], int idx) { DIR* dir = opendir(dirpath); if (!dir) { mkdir(dirpath, 0644); return idx; } struct dirent* ent = NULL; while ((ent = readdir(dir))) { if (ent->d_name[0] == '.') continue; if (strcmp(ent->d_name, "classic") == 0) continue; strncpy(names[idx], ent->d_name, sizeof(varchar)); idx++; } closedir(dir); return idx; } #define SYSTEM_SKIN_DIR SUNPINYIN_XIM_SETTING_DIR"/skins" #define USER_SKIN_DIR "%s/.sunpinyin/xim_skins" #define MAX_SKINS 256 static int list_skins(const char* current_skin_name) { int idx_ret = 0; int skin_count = 0; varchar skins[MAX_SKINS]; GtkListStore* model = GTK_LIST_STORE(gtk_combo_box_get_model(skin_combo)); GtkTreeIter iter; gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, 0, "classic", -1); skin_count = fill_skin_list(SYSTEM_SKIN_DIR, skins, skin_count); varchar dirpath; snprintf(dirpath, sizeof(varchar), USER_SKIN_DIR, getenv("HOME")); skin_count = fill_skin_list(dirpath, skins, skin_count); /* sort and unique the names */ qsort(skins, skin_count, sizeof(varchar), (int (*)(const void*, const void*)) strcmp); int i, j, idx = 1; for (i = 0; i < skin_count; i++) { for (j = i + 1; j < skin_count; j++) { if (strcmp(skins[i], skins[j]) == 0) { i = j; } else { break; } } if (strcmp(skins[i], current_skin_name) == 0) { idx_ret = idx; } gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, 0, skins[i], -1); idx++; } return idx_ret; } static void init_settings(void) { settings_init(); settings_load(); hotkey_t hk; settings_get(TRIGGER_KEY, &hk); INIT_KEY_SETTING(trigger); settings_get(ENG_KEY, &hk); INIT_KEY_SETTING(english); varchar colorstr; settings_get(PREEDIT_COLOR, colorstr); INIT_COLOR_SETTING(background_color_btn); settings_get(PREEDIT_FONT_COLOR, colorstr); INIT_COLOR_SETTING(font_color_btn); varchar fontstr; settings_get(PREEDIT_FONT, fontstr); gtk_font_button_set_font_name(font_btn, fontstr); gtk_adjustment_set_value(opacity_value, settings_get_double(PREEDIT_OPACITY)); gtk_adjustment_set_value(ncandidates, settings_get_int(CANDIDATES_SIZE)); gtk_toggle_button_set_active(minus_plus_check, settings_get_int(PAGE_MINUS_PLUS)); gtk_toggle_button_set_active(comma_period_check, settings_get_int(PAGE_COMMA_PERIOD)); gtk_toggle_button_set_active(paren_check, settings_get_int(PAGE_PAREN)); gtk_toggle_button_set_active(fuzzy_seg_check, settings_get_int(FUZZY_SEGMENTATION)); gtk_toggle_button_set_active(fuzzy_inner_seg_check, settings_get_int(FUZZY_INNER_SEGMENTATION)); gtk_toggle_button_set_active(cancel_on_backspace_check, settings_get_int(CANCEL_ON_BACKSPACE)); gtk_toggle_button_set_active(smart_punct_check, settings_get_int(SMART_PUNCT)); gtk_toggle_button_set_active(shuangpin_check, settings_get_int(SHUANGPIN)); varchar scheme; int i; settings_get(SHUANGPIN_SCHEME, scheme); for (i = 0; i < UI_SHUANGPIN_SCHEMES_NUM; i++) { if (strcmp(ui_shuangpin_schemes[i], scheme) == 0) { gtk_combo_box_set_active(shuangpin_combo, i); break; } } /* skin */ varchar skin_name; settings_get(SKIN_NAME, skin_name); int idx = list_skins(skin_name); gtk_combo_box_set_active(skin_combo, idx); } static void init(void) { GtkBuilder* builder = gtk_builder_new(); gtk_builder_add_from_file(builder, UI_FILE, NULL); main_wnd = GTK_WIDGET(gtk_builder_get_object(builder, "settings_dialog")); RETRIEVE(trigger_ctrl_check, GTK_TOGGLE_BUTTON); RETRIEVE(english_ctrl_check, GTK_TOGGLE_BUTTON); RETRIEVE(trigger_shift_check, GTK_TOGGLE_BUTTON); RETRIEVE(english_shift_check, GTK_TOGGLE_BUTTON); RETRIEVE(trigger_combo, GTK_COMBO_BOX); RETRIEVE(english_combo, GTK_COMBO_BOX); RETRIEVE(background_color_btn, GTK_COLOR_BUTTON); RETRIEVE(font_btn, GTK_FONT_BUTTON); RETRIEVE(font_color_btn, GTK_COLOR_BUTTON); RETRIEVE(opacity_value, GTK_ADJUSTMENT); RETRIEVE(ncandidates, GTK_ADJUSTMENT); RETRIEVE(minus_plus_check, GTK_TOGGLE_BUTTON); RETRIEVE(comma_period_check, GTK_TOGGLE_BUTTON); RETRIEVE(paren_check, GTK_TOGGLE_BUTTON); RETRIEVE(fuzzy_seg_check, GTK_TOGGLE_BUTTON); RETRIEVE(fuzzy_inner_seg_check, GTK_TOGGLE_BUTTON); RETRIEVE(cancel_on_backspace_check, GTK_TOGGLE_BUTTON); RETRIEVE(smart_punct_check, GTK_TOGGLE_BUTTON); RETRIEVE(shuangpin_check, GTK_TOGGLE_BUTTON); RETRIEVE(shuangpin_combo, GTK_COMBO_BOX); RETRIEVE(skin_combo, GTK_COMBO_BOX); init_settings(); gtk_builder_connect_signals(builder, NULL); g_object_unref(builder); } #define REFRESH_KEY_SETTING(prefix) \ do { \ hk.modifiers = hk.keysym = 0; \ if (gtk_toggle_button_get_active(prefix##_ctrl_check)) { \ hk.modifiers |= ControlMask; \ } \ if (gtk_toggle_button_get_active(prefix##_shift_check)) { \ hk.modifiers |= ShiftMask; \ } \ int idx = gtk_combo_box_get_active(prefix##_combo); \ if (idx >= 0) \ hk.keysym = ui_keysym_model[idx]; \ } while (0) #define REFRESH_COLOR_SETTING(widget_name) \ do { \ GdkColor color; \ gtk_color_button_get_color((widget_name), &color); \ snprintf(colorstr, sizeof(varchar), "#%.2X%.2X%.2X", \ color.red >> 8, color.green >> 8, color.blue >> 8); \ } while(0) static void send_reload() { /* notify all running xsunpinyin with this user */ char cmd[256]; snprintf(cmd, 256, "/usr/bin/pkill -10 '^xsunpinyin$' -u %d", getuid()); system(cmd); } void state_changed() { hotkey_t hk; REFRESH_KEY_SETTING(trigger); settings_set(TRIGGER_KEY, &hk); REFRESH_KEY_SETTING(english); settings_set(ENG_KEY, &hk); varchar colorstr; REFRESH_COLOR_SETTING(background_color_btn); settings_set(PREEDIT_COLOR, colorstr); REFRESH_COLOR_SETTING(font_color_btn); settings_set(PREEDIT_FONT_COLOR, colorstr); /* font and size information */ settings_set(PREEDIT_FONT, (void*) gtk_font_button_get_font_name(font_btn)); /* font color information */ settings_set_double(PREEDIT_OPACITY, gtk_adjustment_get_value(opacity_value)); settings_set_int(CANDIDATES_SIZE, gtk_adjustment_get_value(ncandidates)); /* page up and down trigger */ settings_set_int(PAGE_MINUS_PLUS, gtk_toggle_button_get_active(minus_plus_check)); settings_set_int(PAGE_COMMA_PERIOD, gtk_toggle_button_get_active(comma_period_check)); settings_set_int(PAGE_PAREN, gtk_toggle_button_get_active(paren_check)); /* fuzzy segmentation */ settings_set_int(FUZZY_SEGMENTATION, gtk_toggle_button_get_active(fuzzy_seg_check)); settings_set_int(FUZZY_INNER_SEGMENTATION, gtk_toggle_button_get_active(fuzzy_inner_seg_check)); /* cancel on backspace */ settings_set_int(CANCEL_ON_BACKSPACE, gtk_toggle_button_get_active(cancel_on_backspace_check)); /* smart punctuation */ settings_set_int(SMART_PUNCT, gtk_toggle_button_get_active(smart_punct_check)); settings_set_int(SHUANGPIN, gtk_toggle_button_get_active(shuangpin_check)); int sche_idx = gtk_combo_box_get_active(shuangpin_combo); if (sche_idx < UI_SHUANGPIN_SCHEMES_NUM) settings_set_string(SHUANGPIN_SCHEME, ui_shuangpin_schemes[sche_idx]); /* skins */ settings_set_string(SKIN_NAME, gtk_combo_box_get_active_text(skin_combo)); settings_save(); send_reload(); } int main(int argc, char *argv[]) { init_display(&argc, &argv); init(); gtk_widget_show(main_wnd); gtk_main(); return 0; } xsunpinyin-2.0.3/sunpinyin_preedit_gtk.cc0000644000076400007640000001172211527365010017333 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include "ui.h" #include "settings.h" #include "sunpinyin_preedit_ui.h" GtkPreeditUI::GtkPreeditUI() : PreeditUI("classic") { main_wnd_ = ui_create_window(); GtkWidget* box = gtk_vbox_new(FALSE, 1); gtk_container_add(GTK_CONTAINER(main_wnd_), box); preedit_area_ = gtk_label_new(""); candidate_area_ = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(preedit_area_), 0, 0.5); gtk_misc_set_alignment(GTK_MISC(candidate_area_), 0, 0.5); gtk_box_pack_start(GTK_BOX(box), preedit_area_, FALSE, FALSE, 1); gtk_box_pack_start(GTK_BOX(box), candidate_area_, FALSE, FALSE, 1); gtk_widget_show_all(box); gtk_widget_realize(main_wnd_); } GtkPreeditUI::~GtkPreeditUI() { gtk_widget_destroy(main_wnd_); } void GtkPreeditUI::show() { gtk_widget_show(main_wnd_); } void GtkPreeditUI::hide() { gtk_widget_hide(main_wnd_); } void GtkPreeditUI::move(int x, int y) { int width = 0, height = 0; gtk_window_get_size(GTK_WINDOW(main_wnd_), &width, &height); adjust_position(&x, &y, width, height); gtk_window_move(GTK_WINDOW(main_wnd_), x, y); } void GtkPreeditUI::reload() { GdkColor color; varchar value; double opa = 1.0; settings_get(PREEDIT_COLOR, value); gdk_color_parse(value, &color); gtk_widget_modify_bg(main_wnd_, GTK_STATE_NORMAL, &color); settings_get(PREEDIT_FONT, value); gtk_widget_modify_font(candidate_area_, pango_font_description_from_string(value)); settings_get(PREEDIT_FONT_COLOR, value); gdk_color_parse(value, &color); gtk_widget_modify_fg(candidate_area_, GTK_STATE_NORMAL, &color); gtk_widget_modify_fg(preedit_area_, GTK_STATE_NORMAL, &color); settings_get(PREEDIT_OPACITY, &opa); GdkScreen* screen = gtk_widget_get_screen(main_wnd_); if (opa < 1.0) { GdkColormap* cmap = gdk_screen_get_rgba_colormap(screen); if (cmap) { gtk_widget_set_colormap(main_wnd_, cmap); gtk_window_set_opacity(GTK_WINDOW(main_wnd_), opa); } } else { GdkColormap* cmap = gdk_screen_get_rgb_colormap(screen); gtk_window_set_opacity(GTK_WINDOW(main_wnd_), 1.0); gtk_widget_set_colormap(main_wnd_, cmap); } } void GtkPreeditUI::update_preedit_string(const char* utf_str) { gtk_label_set_text(GTK_LABEL(preedit_area_), utf_str); } void GtkPreeditUI::update_candidates_string(const char* utf_str) { gtk_label_set(GTK_LABEL(candidate_area_), utf_str); PangoLayout* pre_lay = gtk_label_get_layout(GTK_LABEL(preedit_area_)); PangoLayout* can_lay = gtk_label_get_layout(GTK_LABEL(candidate_area_)); int x = 0, y = 0; int pre_wid = -1, can_wid = -1; pango_layout_get_pixel_size(pre_lay, &pre_wid, NULL); pango_layout_get_pixel_size(can_lay, &can_wid, NULL); gtk_window_resize(GTK_WINDOW(main_wnd_), MAX(pre_wid, can_wid) + 1, 1); gtk_window_get_position(GTK_WINDOW(main_wnd_), &x, &y); move(x, y); } xsunpinyin-2.0.3/OPENSOLARIS.LICENSE0000644000076400007640000004435111527365010015215 0ustar mikemikeCOMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0 1. Definitions. 1.1. "Contributor" means each individual or entity that creates or contributes to the creation of Modifications. 1.2. "Contributor Version" means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor. 1.3. "Covered Software" means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof. 1.4. "Executable" means the Covered Software in any form other than Source Code. 1.5. "Initial Developer" means the individual or entity that first makes Original Software available under this License. 1.6. "Larger Work" means a work which combines Covered Software or portions thereof with code not governed by the terms of this License. 1.7. "License" means this document. 1.8. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein. 1.9. "Modifications" means the Source Code and Executable form of any of the following: A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications; B. Any new file that contains any part of the Original Software or previous Modifications; or C. Any new file that is contributed or otherwise made available under the terms of this License. 1.10. "Original Software" means the Source Code and Executable form of computer software code that is originally released under this License. 1.11. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor. 1.12. "Source Code" means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code. 1.13. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. License Grants. 2.1. The Initial Developer Grant. Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and (b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof). (c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License. (d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices. 2.2. Contributor Grant. Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and (b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination). (c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party. (d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor. 3. Distribution Obligations. 3.1. Availability of Source Code. Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange. 3.2. Modifications. The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License. 3.3. Required Notices. You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer. 3.4. Application of Additional Terms. You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients' rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. 3.5. Distribution of Executable Versions. You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipient's rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. 3.6. Larger Works. You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software. 4. Versions of the License. 4.1. New Versions. Sun Microsystems, Inc. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License. 4.2. Effect of New Versions. You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward. 4.3. Modified Versions. When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License. 5. DISCLAIMER OF WARRANTY. COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. 6. TERMINATION. 6.1. This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. 6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as "Participant") alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant. 6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination. 7. LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. 8. U.S. GOVERNMENT END USERS. The Covered Software is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" (as that term is defined at 48 C.F.R. 252.227-7014(a)(1)) and "commercial computer software documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License. 9. MISCELLANEOUS. This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. This License shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), excluding such jurisdiction's conflict-of-law provisions. Any litigation relating to this License shall be subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a notice contained within the Original Software, with the losing party responsible for costs, including, without limitation, court costs and reasonable attorneys' fees and expenses. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software. 10. RESPONSIBILITY FOR CLAIMS. As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability. -------------------------------------------------------------------- NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) For Covered Software in this distribution, this License shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California. xsunpinyin-2.0.3/LGPL.LICENSE0000644000076400007640000006455211527365010014162 0ustar mikemike GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! -------------------------------------------------------------------- NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) For Covered Software in this distribution, this License shall be governed by the laws of the State of California (excluding conflict-of-law provisions). Any litigation relating to this License shall be subject to the jurisdiction of the Federal Courts of the Northern District of California and the state courts of the State of California, with venue lying in Santa Clara County, California. xsunpinyin-2.0.3/COPYING0000644000076400007640000000005711527365010013441 0ustar mikemikeRefer to LGPL.LICENSE and OPENSOLARIS.LICENSE. xsunpinyin-2.0.3/sunpinyin_preedit_skin.cc0000644000076400007640000001243411527365010017513 0ustar mikemike/* * Copyright (c) 2010 Mike Qin * * The contents of this file are subject to the terms of either the GNU Lesser * General Public License Version 2.1 only ("LGPL") or the Common Development and * Distribution License ("CDDL")(collectively, the "License"). You may not use this * file except in compliance with the License. You can obtain a copy of the CDDL at * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at * http://www.opensource.org/licenses/lgpl-license.php. See the License for the * specific language governing permissions and limitations under the License. When * distributing the software, include this License Header Notice in each file and * include the full text of the License in the License file as well as the * following notice: * * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE * (CDDL) * For Covered Software in this distribution, this License shall be governed by the * laws of the State of California (excluding conflict-of-law provisions). * Any litigation relating to this License shall be subject to the jurisdiction of * the Federal Courts of the Northern District of California and the state courts * of the State of California, with venue lying in Santa Clara County, California. * * Contributor(s): * * If you wish your version of this file to be governed by only the CDDL or only * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to * include this software in this distribution under the [CDDL or LGPL Version 2.1] * license." If you don't indicate a single choice of license, a recipient has the * option to distribute your version of this file under either the CDDL or the LGPL * Version 2.1, or to extend the choice of license to its licensees as provided * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL * Version 2 license, then the option applies only if the new code is made subject * to such option by the copyright holder. */ #include "ui.h" #include "settings.h" #include "sunpinyin_preedit_ui.h" #include "skin.h" SkinPreeditUI::SkinPreeditUI(std::string name) throw() : PreeditUI(name) { info_ = ui_skin_new(name.c_str()); if (!info_) { throw SkinLoaderException(); } main_wnd_ = skin_window_new(GTK_WINDOW(ui_create_window()), info_->preedit_background, info_->top, info_->left, info_->bottom, info_->right, 1); preedit_label_ = skin_label_new(info_->preedit_label.font, NULL, info_->preedit_label.color_r, info_->preedit_label.color_g, info_->preedit_label.color_b, info_->preedit_label.color_a); candidate_label_ = skin_label_new(info_->candidate_label.font, NULL, info_->candidate_label.color_r, info_->candidate_label.color_g, info_->candidate_label.color_b, info_->candidate_label.color_a); skin_window_add_label(main_wnd_, preedit_label_, info_->preedit_label.x, info_->preedit_label.y); skin_window_add_label(main_wnd_, candidate_label_, info_->candidate_label.x, info_->candidate_label.y); } SkinPreeditUI::~SkinPreeditUI() { ui_skin_destroy(info_); skin_label_destroy(preedit_label_); skin_label_destroy(candidate_label_); skin_window_destroy(main_wnd_); } void SkinPreeditUI::show() { gtk_widget_show(main_wnd_->widget); adjust_size(); } void SkinPreeditUI::hide() { gtk_widget_hide(main_wnd_->widget); } void SkinPreeditUI::move(int x, int y) { internal_move(x - info_->offset_x, y - info_->offset_y); } void SkinPreeditUI::internal_move(int x, int y) { int width, height; gtk_window_get_size(GTK_WINDOW(main_wnd_->widget), &width, &height); adjust_position(&x, &y, width, height); gtk_window_move(GTK_WINDOW(main_wnd_->widget), x, y); } void SkinPreeditUI::reload() { // Nothing? } void SkinPreeditUI::update_preedit_string(const char* utf_str) { skin_label_set_text(preedit_label_, utf_str); adjust_size(); } #define BUFSIZE (4096*2) void SkinPreeditUI::update_candidates_string(const char* utf_str) { skin_label_set_text(candidate_label_, utf_str); adjust_size(); } void SkinPreeditUI::adjust_size() { if (candidate_label_->layout && preedit_label_->layout) { int x = 0, y = 0; int can_wid = 0, pre_wid = 0, width = 0, height = 0; int hmargin, vmargin; hmargin = info_->candidate_label.x + info_->right; vmargin = info_->candidate_label.y + info_->bottom; pango_layout_get_pixel_size(preedit_label_->layout, &pre_wid, NULL); pango_layout_get_pixel_size(candidate_label_->layout, &can_wid, &height); width = MAX(pre_wid, can_wid); gtk_window_resize(GTK_WINDOW(main_wnd_->widget), width + hmargin, height + vmargin); gtk_window_get_position(GTK_WINDOW(main_wnd_->widget), &x, &y); internal_move(x, y); } }