1 /* # skkinput (Simple Kana-Kanji Input)
2 *
3 * This file is part of skkinput.
4 * Copyright (C) 2002
5 * Takashi SAKAMOTO (PXG01715@nifty.ne.jp)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with skkinput; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 #include "AfxWin.h"
22 #include <stdio.h>
23 #include "lispmgrp.h"
24 #include "TFontSet.h"
25 #include "lmachinep.h"
26 #include "TTerminal.h"
27 #include "TFrame.h"
28
29 static Boolean lispMachine_updateFrame (TLispMachine*, TLispEntity*) ;
30 static Boolean lispMachine_resizeNormalFrame (TLispMachine*, TLispEntity*, const XRectangle*) ;
31 static Boolean lispMachine_activeFramep (TLispMachine*, TLispEntity*) ;
32
33
34 Boolean
lispMachine_UpdateCurrentFrame(register TLispMachine * pLM)35 lispMachine_UpdateCurrentFrame (
36 register TLispMachine* pLM)
37 {
38 assert (pLM != NULL) ;
39 assert (pLM->m_pCurFrame != NULL) ;
40
41 return lispMachine_updateFrame (pLM, pLM->m_pCurFrame) ;
42 }
43
44 Boolean
lispMachine_UpdateAllFrame(register TLispMachine * pLM)45 lispMachine_UpdateAllFrame (
46 register TLispMachine* pLM)
47 {
48 TLispEntity* pEntFrame ;
49 assert (pLM != NULL) ;
50
51 pEntFrame = pLM->m_lstFrame ;
52 if (pEntFrame != NULL) {
53 do {
54 lispMachine_updateFrame (pLM, pEntFrame) ;
55 lispFrame_GetNext (pEntFrame, &pEntFrame) ;
56 } while (pEntFrame != pLM->m_lstFrame) ;
57 }
58 return True ;
59 }
60
61 void
lispMachine_ScheduleUpdateAllFrame(register TLispMachine * pLM)62 lispMachine_ScheduleUpdateAllFrame (
63 register TLispMachine* pLM)
64 {
65 register TLispManager* pLispMgr ;
66 register TLispEntity* pEntFrame ;
67 TLispEntity* pEntNextFrame ;
68
69 assert (pLM != NULL) ;
70 pLispMgr = pLM->m_pLispMgr ;
71 assert (pLispMgr != NULL) ;
72 pEntFrame = pLM->m_lstFrame ;
73
74 if (pEntFrame != NULL) {
75 do {
76 lispFrame_ScheduleUpdate (pLispMgr, pEntFrame) ;
77 lispFrame_GetNext (pEntFrame, &pEntNextFrame) ;
78 pEntFrame = pEntNextFrame ;
79 } while (pEntFrame != pLM->m_lstFrame) ;
80 }
81 return ;
82 }
83
84 Boolean
lispMachine_ResizeFrame(register TLispMachine * pLM,register TLispEntity * pEntFrame,register const XRectangle * pRC)85 lispMachine_ResizeFrame (
86 register TLispMachine* pLM,
87 register TLispEntity* pEntFrame,
88 register const XRectangle* pRC)
89 {
90 Widget wgTerminal ;
91
92 assert (pLM != NULL) ;
93 assert (pEntFrame != NULL) ;
94
95 if (TFAILED (lispFrame_GetTerminal (pEntFrame, &wgTerminal)))
96 return False ;
97 if (TFrame_RectVariablep (wgTerminal)) {
98 lispFrame_ScheduleUpdate (pLM->m_pLispMgr, pEntFrame) ;
99 return lispMachine_updateFrame (pLM, pEntFrame) ;
100 } else {
101 assert (pRC != NULL) ;
102 return lispMachine_resizeNormalFrame (pLM, pEntFrame, pRC) ;
103 }
104 }
105
106 /* ���Ƥ� frame ����֤���롣
107 */
108 Boolean
lispMachine_EnumFrame(register TLispMachine * pLM,register Boolean (* pProc)(TLispMachine *,TLispEntity *,void *,Boolean *),register void * pCaller)109 lispMachine_EnumFrame (
110 register TLispMachine* pLM,
111 register Boolean (*pProc)(TLispMachine*, TLispEntity*, void*, Boolean*),
112 register void* pCaller)
113 {
114 register TLispEntity* pEntFrame ;
115 Boolean fContinue ;
116
117 assert (pLM != NULL) ;
118 assert (pProc != NULL) ;
119
120 if (pLM->m_lstFrame == NULL)
121 return True ;
122
123 fContinue = True ;
124 pEntFrame = pLM->m_lstFrame ;
125 do {
126 TLispEntity* pEntNextFrame ;
127 lispFrame_GetNext (pEntFrame, &pEntNextFrame) ;
128 if (TFAILED ((pProc)(pLM, pEntFrame, pCaller, &fContinue)))
129 return False ;
130 if (TFAILED (fContinue))
131 break ;
132 pEntFrame = pEntNextFrame ;
133 } while (pEntFrame != pLM->m_lstFrame) ;
134
135 return True ;
136 }
137
138 /* Frame �ˤ�ɽ������ʸ�����ʤˤ�ʤ��ơ��ե����������ʤ���о����
139 * �Ĥ����Τ����롣(XUnmapWindow ����ưŪ�˹Ԥ���)
140 *
141 * ����������Τ�Ƚ��äƤɤ����롩 ���Υե���������ï�����äƤơ�
142 * ���ä��Ƥ褤�����Ȥ���������
143 */
144 Boolean
lispMachine_updateFrame(register TLispMachine * pLM,register TLispEntity * pEntFrame)145 lispMachine_updateFrame (
146 register TLispMachine* pLM,
147 register TLispEntity* pEntFrame)
148 {
149 register TLispManager* pLispMgr = pLM->m_pLispMgr ;
150 Widget wgTerminal ;
151 TLispEntity* pEntTopWindow ;
152 TLispEntity* pEntWindow ;
153
154 assert (pLispMgr != NULL) ;
155 assert (pEntFrame != NULL) ;
156 assert (pEntFrame->m_iType == LISPENTITY_FRAME) ;
157
158 if (TFAILED (lispFrame_GetTerminal (pEntFrame, &wgTerminal)))
159 return False ;
160 if (TFAILED (lispFrame_NeedUpdatep (pLispMgr, pEntFrame)))
161 return True ;
162
163 /* ������б����� terminal ��ޤ� clear ���ơ�*/
164 TFrame_Clear (wgTerminal) ;
165
166 #if defined (DEBUG)
167 fprintf (stderr, "updateFrame(%p) Auto(%d), Active(%d) ... ",
168 pEntFrame,
169 TFrame_AutoPopupp (wgTerminal),
170 lispMachine_activeFramep (pLM, pEntFrame)) ;
171 #endif
172 if (!TFrame_AutoPopupp (wgTerminal) ||
173 TSUCCEEDED (lispMachine_activeFramep (pLM, pEntFrame))) {
174 #if defined (DEBUG)
175 fprintf (stderr, "yes\n") ;
176 #endif
177 (void) lispFrame_GetTopWindow (pEntFrame, &pEntTopWindow) ;
178 assert (pEntTopWindow != NULL) ;
179
180 pEntWindow = pEntTopWindow ;
181 /* ��Ȥ���֤����� (putchar?) ���Ƥ��äơ�*/
182 do {
183 lispMachine_UpdateWindow (pLM, pEntFrame, pEntWindow) ;
184 lispWindow_GetNext (pEntWindow, &pEntWindow) ;
185 } while (pEntWindow != pEntTopWindow) ;
186
187 /*
188 * Minibuffer Window �� Frame �˴ޤޤ�Ƥ���Ȳ��ꡣ
189 * lispWindow_Update (pLispMgr, pFrame->m_pEntMinibufWindow) ;
190 */
191 #if defined (DEBUG)
192 } else {
193 fprintf (stderr, "no\n") ;
194 #endif
195 }
196
197 TFrame_Flush (wgTerminal) ;
198 return True ;
199 }
200
201 /* ���̥ե졼��Υ������ѹ����б����롣�������ˤ� Window ���¤Фʤ��Ȳ��ꤹ�롣
202 * OverTheSpot, OffTheSpot �ˤ��б��Ǥ��ʤ���
203 */
204 Boolean
lispMachine_resizeNormalFrame(register TLispMachine * pLM,register TLispEntity * pEntFrame,register const XRectangle * pRC)205 lispMachine_resizeNormalFrame (
206 register TLispMachine* pLM,
207 register TLispEntity* pEntFrame,
208 register const XRectangle* pRC)
209 {
210 register TLispManager* pLispMgr = pLM->m_pLispMgr ;
211 register TLispEntity* pEntWindow ;
212 TLispEntity* pEntTopWindow ;
213 TLispEntity* pEntNextWindow ;
214 TLispEntity* pEntMinibufWindow ;
215 register Boolean fMinibufExist, fMoveFocus ;
216 register int nWidth, nHeight ;
217 register int y, nFontHeight, nDelta, nWindow ;
218 register int nPrevHeight ;
219 register TFontSet* pFontSet ;
220 XRectangle rect, newRect ;
221 Widget wgTerminal ;
222
223 assert (pLispMgr != NULL) ;
224 assert (pEntFrame != NULL) ;
225
226 nWidth = pRC->width ;
227 nHeight = pRC->height ;
228 #if defined (DEBUG)
229 fprintf (stderr, "lispMachine_ResizeNormalFrame (%p, %p, %d, %d)\n",
230 pLispMgr, pEntFrame, nWidth, nHeight) ;
231 #endif
232
233 (void) lispFrame_GetTopWindow (pEntFrame, &pEntTopWindow) ;
234 assert (pEntTopWindow != NULL) ;
235 if (TFAILED (lispFrame_GetMinibufferWindow (pEntFrame, &pEntMinibufWindow)))
236 pEntMinibufWindow = NULL ;
237 pEntWindow = pEntTopWindow ;
238 assert (pEntWindow != NULL) ;
239 nPrevHeight = 0 ;
240 nWindow = 0 ;
241 fMinibufExist = False ;
242 do {
243 lispWindow_GetArea (pEntWindow, &rect) ;
244 nPrevHeight += rect.height ;
245 nWindow ++ ;
246 if (pEntWindow == pEntMinibufWindow)
247 fMinibufExist = True ;
248 lispWindow_GetNext (pEntWindow, &pEntNextWindow) ;
249 pEntWindow = pEntNextWindow ;
250 } while (pEntWindow != pEntTopWindow) ;
251
252 /* �礭�����ѹ�����Ƥ��ʤ���С����⤹��ɬ�פϤʤ���
253 */
254 nDelta = nHeight - nPrevHeight ;
255 if (nDelta == 0 && nWidth == rect.width)
256 return True ;
257
258 /* Window ��1�Ĥ���¸�ߤ��ʤ���С�����ư�������Ƥ��ɽ����롣
259 */
260 if (nWindow == 1) {
261 newRect.x = 0 ;
262 newRect.y = 0 ;
263 newRect.width = nWidth ;
264 newRect.height = nHeight ;
265 lispWindow_SetArea (pEntTopWindow, &newRect) ;
266 return lispMachine_updateFrame (pLM, pEntFrame) ;
267 }
268
269 /* Minibuffer Window �δ���ϳ�����
270 */
271 if (fMinibufExist)
272 nWindow -- ;
273
274 /* �ե���Ȥι⤵�����Ƥ�����
275 */
276 (void) lispFrame_GetTerminal (pEntFrame, &wgTerminal) ;
277 pFontSet = TFrame_GetFontSet (wgTerminal) ;
278 assert (pFontSet != NULL) ;
279 nFontHeight = pFontSet->m_iHeight ;
280 assert (nFontHeight >= 1) ;
281
282 /* Window ��ʣ��������ˤϽ��֤ˡ�
283 */
284 pEntWindow = pEntTopWindow ;
285 y = 0 ;
286 fMoveFocus = False ;
287 do {
288 lispWindow_GetArea (pEntWindow, &rect) ;
289 lispWindow_GetNext (pEntWindow, &pEntNextWindow) ;
290
291 if (pEntWindow == pEntMinibufWindow) {
292 newRect.x = rect.x ;
293 newRect.y = rect.y ;
294 newRect.width = nWidth ;
295 newRect.height = rect.height ;
296 lispWindow_SetArea (pEntWindow, &newRect) ;
297 y += newRect.height ;
298 } else {
299 /* Minibuffer Window ������ơ�¾�� Window ��¸�ߤǤ�����ˤϡ�������
300 * �ʤ��� Window �Ͼõ��롣
301 */
302 if ((rect.height + nDelta) < nFontHeight * 2 && nWindow > 1) {
303 nDelta += rect.height ;
304 /* ���ξä���� Window �� Focus ����äƤ������ˤϡ����� Window
305 * �� Focus ���ư������ɬ�פ����롣
306 */
307 if (TSUCCEEDED (lispWindow_HaveFocusp (pEntWindow)))
308 fMoveFocus = True ;
309 lispFrame_RemoveWindow (pLispMgr, pEntFrame, pEntWindow) ;
310 nWindow -- ;
311 } else {
312 newRect.x = rect.x ;
313 newRect.y = y ;
314 newRect.width = nWidth ;
315 newRect.height = rect.height + nDelta ;
316 lispWindow_SetArea (pEntWindow, &newRect) ;
317 nDelta = 0 ;
318 y += newRect.height ;
319
320 /* �ե��������ΰ�ư��ɬ�פ�����������
321 */
322 if (TSUCCEEDED (fMoveFocus)) {
323 lispWindow_SetFocus (pEntWindow, True) ;
324 fMoveFocus = False ;
325 }
326 }
327 }
328 #if defined (DEBUG)
329 fprintf (stderr, "Window: (%d, %d, %d, %d), FontHeight: %d\n",
330 newRect.x, newRect.y, newRect.width, newRect.height, nFontHeight) ;
331 #endif
332 pEntWindow = pEntNextWindow ;
333 } while (pEntWindow != pEntTopWindow) ;
334
335 return lispMachine_updateFrame (pLM, pEntFrame) ;
336 }
337
338 /* Active Frame ���ɤ���������å����롣
339 */
340 Boolean
lispMachine_activeFramep(register TLispMachine * pLM,register TLispEntity * pEntFrame)341 lispMachine_activeFramep (
342 register TLispMachine* pLM,
343 register TLispEntity* pEntFrame)
344 {
345 register TLispManager* pLispMgr ;
346 TLispEntity* pEntTopWindow ;
347 TLispEntity* pEntWindow ;
348 TLispEntity* pEntMsg ;
349
350 assert (pLM != NULL) ;
351 pLispMgr = pLM->m_pLispMgr ;
352 assert (pLispMgr != NULL) ;
353 assert (pEntFrame != NULL) ;
354 assert (pEntFrame->m_iType == LISPENTITY_FRAME) ;
355
356 /* Current Frame �ʤ�����ɽ������ʤ���Фʤ�ʤ���
357 */
358 if (pEntFrame == pLM->m_pCurFrame)
359 return True ;
360
361 /* �����Ǥʤ��Τʤ顢����ɽ�������٤���Τ���äƤ��뤫
362 * �����å����롣��å���������äƤ���Ȥ����Хåե�����
363 * �Ǥʤ��Ȥ���
364 */
365 (void) lispFrame_GetTopWindow (pEntFrame, &pEntTopWindow) ;
366 assert (pEntTopWindow != NULL) ;
367 pEntWindow = pEntTopWindow ;
368 do {
369 if (TSUCCEEDED (lispWindow_GetMessage (pEntWindow, &pEntMsg)) &&
370 TFAILED (lispEntity_Nullp (pLispMgr, pEntMsg))) {
371 const Char* pString ;
372 int nString ;
373
374 if (TSUCCEEDED (lispEntity_GetStringValue (pLispMgr, pEntMsg, &pString, &nString)) &&
375 nString > 0)
376 return True ;
377 #if defined (DEBUG)
378 fprintf (stderr, "lispMachine_activeFramep (): window(%p): no message\n",
379 pEntWindow) ;
380 #endif
381 } else {
382 TLispEntity* pEntBuffer ;
383 TBufStringMarker mk ;
384 int nLength ;
385
386 if (TSUCCEEDED (lispWindow_GetBuffer (pEntWindow, &pEntBuffer)) &&
387 TSUCCEEDED (lispBuffer_GetFullString (pLispMgr, pEntBuffer, &mk, &nLength)) &&
388 nLength > 0)
389 return True ;
390 #if defined (DEBUG)
391 fprintf (stderr, "lispMachine_activeFramep (): window(%p): no buffer text\n",
392 pEntWindow) ;
393 #endif
394 }
395 lispWindow_GetNext (pEntWindow, &pEntWindow) ;
396 } while (pEntWindow != pEntTopWindow) ;
397
398 return False ;
399 }
400
401