1 /*
2 * Author: William Chia-Wei Cheng (bill.cheng@acm.org)
3 *
4 * Copyright (C) 2001-2009, William Chia-Wei Cheng.
5 *
6 * This file may be distributed under the terms of the Q Public License
7 * as defined by Trolltech AS of Norway and appearing in the file
8 * LICENSE.QPL included in the packaging of this file.
9 *
10 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
11 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
13 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * @(#)$Header: /mm2/home/cvs/bc-src/tgif/tgtwb5.c,v 1.11 2011/05/16 16:22:00 william Exp $
19 */
20
21 #ifndef _NO_TGTWB5
22
23 #define _INCLUDE_FROM_TGTWB5_C_
24
25 #include "tgifdefs.h"
26 #include "big5.h"
27 #include "tidget.h"
28
29 #include "auxtext.e"
30 #include "dialog.e"
31 #include "font.e"
32 #include "msg.e"
33 #include "setup.e"
34 #include "strtbl.e"
35 #include "tgtwb5.e"
36 #include "tgtwb5dl.e"
37 #include "tgtwb5xl.e"
38 #include "tidget.e"
39 #include "util.e"
40
41 #include "xbm/tgtwb5.xbm"
42
43 /* --------------------- Init & Clean Up --------------------- */
44
Tgtwb5_CleanUp(dpy,win)45 void Tgtwb5_CleanUp(dpy, win)
46 Display *dpy;
47 Window win;
48 {
49 if (gZyfhInfo.initialized) {
50 if (gZyfhInfo.dialogbox_tidgetinfo != NULL) {
51 DestroyTdgtb5DialogBox(dpy, gZyfhInfo.dialogbox_tidgetinfo);
52 }
53 }
54 UtilFree(gZyfhInfo.b5_font_name);
55 if (gZyfhInfo.xfs != NULL) {
56 XFreeFont(mainDisplay, gZyfhInfo.xfs);
57 }
58 if (gZyfhInfo.zyfh_bitmap != None) {
59 XFreePixmap(mainDisplay, gZyfhInfo.zyfh_bitmap);
60 }
61 if (gZyfhInfo.symbol_bitmap != None) {
62 XFreePixmap(mainDisplay, gZyfhInfo.symbol_bitmap);
63 }
64 memset(&gZyfhInfo, 0, sizeof(ZyfhInfo));
65
66 CleanUpTdgtb5Dlg();
67 }
68
69 static char szDefB5FontName[] =
70 "-taipei-fixed-medium-r-normal--16-150-75-75-c-160-big5-0";
71
Tgtwb5_Init(dpy,win,arg)72 int Tgtwb5_Init(dpy, win, arg)
73 Display *dpy;
74 Window win;
75 char *arg;
76 {
77 memset(&gZyfhInfo, 0, sizeof(ZyfhInfo));
78 if (arg != NULL) {
79 gZyfhInfo.b5_font_name = UtilStrDup(arg);
80 if (gZyfhInfo.b5_font_name == NULL) FailAllocMessage();
81 } else {
82 gZyfhInfo.b5_font_name = UtilStrDup(szDefB5FontName);
83 if (gZyfhInfo.b5_font_name == NULL) FailAllocMessage();
84 }
85 if (strstr(gZyfhInfo.b5_font_name, "-gb2312") != NULL) {
86 gZyfhInfo.b5_font_real_encoding = GB_ENCODING;
87 UtilStrCpyN(gZyfhInfo.im_name, sizeof(gZyfhInfo.im_name), "tgchgb");
88 } else if (strstr(gZyfhInfo.b5_font_name, "-big5") != NULL) {
89 gZyfhInfo.b5_font_real_encoding = BIG5_ENCODING;
90 UtilStrCpyN(gZyfhInfo.im_name, sizeof(gZyfhInfo.im_name), "tgtwb5");
91 } else {
92 gZyfhInfo.b5_font_real_encoding = INVALID;
93 sprintf(gszMsgBox, TgLoadString(STID_BAD_ENCODING_TGTWB5_FONT),
94 gZyfhInfo.b5_font_name, TOOL_NAME, "DoubleByteInputMethod");
95 fprintf(stderr, "%s\n", gszMsgBox);
96
97 Tgtwb5_CleanUp(dpy, win);
98
99 return FALSE;
100 }
101 gZyfhInfo.xfs = LoadAFontByName(gZyfhInfo.b5_font_name, TRUE, TRUE);
102 if (gZyfhInfo.xfs == NULL) {
103 sprintf(gszMsgBox, TgLoadString(STID_CANNOT_LOAD_TGTWB5_FONT),
104 gZyfhInfo.b5_font_name, TOOL_NAME, "DoubleByteInputMethod",
105 gZyfhInfo.im_name);
106 fprintf(stderr, "%s\n", gszMsgBox);
107
108 Tgtwb5_CleanUp(dpy, win);
109
110 return FALSE;
111 }
112 gZyfhInfo.b5_font_mod_bytes = ((gZyfhInfo.xfs->min_byte1 & 0x80) == 0);
113 gZyfhInfo.b5_font_w = gZyfhInfo.xfs->max_bounds.rbearing;
114 gZyfhInfo.b5_font_asc = gZyfhInfo.xfs->max_bounds.ascent;
115 gZyfhInfo.b5_font_des = gZyfhInfo.xfs->max_bounds.descent;
116 gZyfhInfo.b5_font_h = gZyfhInfo.b5_font_asc + gZyfhInfo.b5_font_des;
117
118 gZyfhInfo.zyfh_num_cols = 13;
119 gZyfhInfo.zyfh_num_rows = 4;
120 gZyfhInfo.zyfh_max_symbols = gZyfhInfo.zyfh_num_cols*gZyfhInfo.zyfh_num_rows;
121 gZyfhInfo.zyfh_bitmap_w = tgtwb5_width;
122 gZyfhInfo.zyfh_bitmap_h = tgtwb5_height;
123 gZyfhInfo.zyfh_image_wh =
124 round(((double)tgtwb5_width)/((double)gZyfhInfo.zyfh_num_cols));
125 gZyfhInfo.zyfh_bitmap = XCreateBitmapFromData(mainDisplay, mainWindow,
126 (char*)tgtwb5_bits, tgtwb5_width, tgtwb5_height);
127
128 gZyfhInfo.symbol_bitmap = XCreatePixmap(mainDisplay, rootWindow,
129 gZyfhInfo.zyfh_image_wh, gZyfhInfo.zyfh_image_wh, 1);
130
131 if (!InitTdgtb5Dlg()) {
132 Tgtwb5_CleanUp(dpy, win);
133
134 return FALSE;
135 }
136 return TRUE;
137 }
138
139 /* --------------------- Tgtwb5_SendKey --------------------- */
140
141 static XComposeStatus c_stat;
142
Tgtwb5_SendKey(dpy,win,key_ev,buf)143 int Tgtwb5_SendKey(dpy, win, key_ev, buf)
144 Display *dpy;
145 Window win;
146 XKeyEvent *key_ev;
147 char *buf;
148 /* return FALSE means key_ev will be handled without modifications */
149 {
150 int has_ch=0;
151 char s[80];
152 KeySym key_sym=(KeySym)0;
153
154 has_ch = XLookupString(key_ev, s, sizeof(s), &key_sym, &c_stat);
155 TranslateKeys(s, &key_sym);
156
157 return FALSE;
158 }
159
160 /* --------------------- Tgtwb5_HandleCntrlSpace --------------------- */
161
Tgtwb5_HandleCntrlSpace(dpy,win)162 int Tgtwb5_HandleCntrlSpace(dpy, win)
163 Display *dpy;
164 Window win;
165 {
166 if (!gZyfhInfo.initialized) {
167 gZyfhInfo.initialized = TRUE;
168 /* create window */
169 gZyfhInfo.dialogbox_tidgetinfo = CreateTdgtb5DialogBox(dpy, rootWindow);
170 if (gZyfhInfo.dialogbox_tidgetinfo == NULL) {
171 /* print a message */
172 }
173 }
174 if (gZyfhInfo.dialogbox_tidgetinfo == NULL) {
175 return FALSE;
176 }
177 if (!gZyfhInfo.mapped) {
178 ShowTdgtb5DialogBox();
179 Tdgtb5DlgLoop(gZyfhInfo.dialogbox_tidgetinfo);
180 } else {
181 HideTdgtb5DialogBox();
182 }
183 return FALSE;
184 }
185
186 /* --------------------- Tgtwb5_HandleCreateText --------------------- */
187
Tgtwb5_HandleCreateText(dpy,win)188 int Tgtwb5_HandleCreateText(dpy, win)
189 Display *dpy;
190 Window win;
191 {
192 if (gZyfhInfo.initialized && gZyfhInfo.mapped) {
193 HideTdgtb5DialogBox();
194 }
195 return TRUE;
196 }
197
198 #endif /* ~_NO_TGTWB5 */
199
200