1 /* # skkinput (Simple Kana-Kanji Input)
2 * skkmarker.c --- simulate marker.
3 * This file is part of skkinput.
4 * Copyright (C) 1997
5 * Takashi SAKAMOTO (sakamoto@yajima.kuis.kyoto-u.ac.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 /*
22 * ���Υ������ϡ�SkkInput.c �ΰ����Ǥ��ꡢSkkInputWidget �ΰ����Ǥ����
23 * ��äơ���Ȥδؿ��ϳ�������Ϸ褷�ƸƤӤ����ʤ��褦�� static��
24 */
25 #if 0
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <sys/types.h>
29 #include <sys/time.h>
30 #include <X11/Xlib.h>
31 #include <X11/Xutil.h>
32 #include <X11/Xatom.h>
33 #include <X11/keysym.h>
34 #endif
35
36 #include "skkmain.h"
37
38 /*
39 * �ޡ������ν������Ԥ��ؿ���
40 */
markers_init(struct SKKInputNode * node)41 static void markers_init( struct SKKInputNode *node )
42 {
43 int i ;
44 for( i = 0 ; i < MAXMARKERNUM ; i ++ ){
45 node->markers[ i ].pos = NULL ;
46 node->markers[ i ].cf = False ;
47 }
48 node->marker_usage = 0 ;
49 return ;
50 }
51
52 /*
53 * �ޡ���������Ͽ����ؿ���
54 */
make_marker(struct SKKInputNode * node,int * marker,int flag)55 static int make_marker( struct SKKInputNode *node, int *marker, int flag )
56 {
57 int i ;
58 /* ���ߤޤǤλ��Ѥ���Ƥ����Τ���Ƕ����Ƥ�������ܤ���*/
59 for( i = 0 ; i < node->marker_usage ; i ++ ){
60 if( ( node->markers[ i ] ).pos == NULL ){
61 /* �ޡ���������Ͽ��*/
62 ( node->markers[ i ] ).pos = marker ;
63 ( node->markers[ i ] ).cf = flag ;
64 return 0 ;
65 }
66 }
67 node->marker_usage ++ ;
68 /* �ޡ������Хåե���Ȥ��ڤäƤ��ޤäƤ�����硣*/
69 if( node->marker_usage >= MAXMARKERNUM )
70 return 1 ;
71 /* �ޡ���������Ͽ��*/
72 ( node->markers[ i ] ).pos = marker ;
73 ( node->markers[ i ] ).cf = flag ;
74 return 0 ;
75 }
76
77 /*
78 * �ޡ�������õ��ؿ���
79 */
delete_marker(struct SKKInputNode * node,int * marker)80 static int delete_marker( struct SKKInputNode *node, int *marker )
81 {
82 int i ;
83 /* ���ߤޤǤλ��Ѥ���Ƥ����Τ��椫�顣*/
84 for( i = 0 ; i < node->marker_usage ; i ++ ){
85 /* �õ�٤��ޡ��������� */
86 if( ( node->markers[ i ] ).pos == marker ){
87 /* �ޡ����������á�*/
88 ( node->markers[ i ] ).pos = NULL ;
89 return 0 ;
90 }
91 }
92 /* ����ʥޡ���������Ͽ����Ƥ��ʤ���*/
93 return 1 ;
94 }
95
96 /*
97 * �ޡ��������ư������ؿ���
98 *----
99 * �ƥ��������ʸ������������뤳�Ȥˤ�äơ��ޡ������ΰ�ư������������
100 * ���Ѥ��롣copy_region �ʤɤ�����������Ǥ��餦��
101 *----
102 * startpoint ��걦�ˤ���ޡ����������Ʊƶ�������롣
103 */
move_marker_ByInsert(struct SKKInputNode * node,int startpoint,int effect)104 static int move_marker_ByInsert
105 ( struct SKKInputNode *node, int startpoint, int effect )
106 {
107 int i ;
108 struct Marker *mks = node->markers ;
109
110 /* ���ߤޤǤλ��Ѥ���Ƥ����Τ��椫�顣*/
111 for( i = 0 ; i < node->marker_usage ; i ++ ){
112 /* �ƶ��������ޡ��������� */
113 if( *( mks[ i ].pos ) > ( startpoint - mks[ i ].cf ) ){
114 /* �ޡ��������ư�����롣*/
115 *( mks[ i ].pos ) += effect ;
116 /* �ޡ��������ƥ����Ȥ������ӽФ��Ƥ��ޤ���硣*/
117 if( *( mks[ i ].pos ) >= TEXTMAXLEN )
118 *( mks[ i ].pos ) = TEXTMAXLEN ;
119 }
120 }
121 return 0 ;
122 }
123
124 /*
125 * �ޡ��������ư������ؿ���
126 *----
127 * �ƥ������⤫��ʸ�����ȴ���Ф����Ȥˤ�ä�������ޡ������ΰ�ư��
128 * ���Ѥ��롣delete_region �ʤɤ�����������Ǥ��餦��
129 *----
130 * startpoint ��걦�ˤ���ޡ����������Ʊƶ�������롣
131 */
move_marker_ByDeleteRegion(struct SKKInputNode * node,int startpoint,int endpoint)132 static int move_marker_ByDeleteRegion
133 ( struct SKKInputNode *node, int startpoint, int endpoint )
134 {
135 int i ;
136 int diff = endpoint - startpoint ;
137 struct Marker *markers = node->markers ;
138
139 /* ���ߤޤǤλ��Ѥ���Ƥ����Τ��椫�顣*/
140 for( i = 0 ; i < node->marker_usage ; i ++ ){
141 /* �ƶ��������ޡ��������� */
142 if( *( markers[ i ].pos ) <= startpoint )
143 continue ;
144 if( *( markers[ i ].pos ) >= endpoint ){
145 /* �ޡ��������ư�����롣*/
146 *( markers[ i ].pos ) -= diff ;
147 } else {
148 /* �ޡ��������ư�����롣*/
149 *( markers[ i ].pos ) = startpoint ;
150 }
151 }
152 return 0 ;
153 }
154
155 /*
156 * �ޡ��������ư������ؿ���
157 *----
158 * �ƥ����Ȥθ������ʸ�����ڤ�Ƥ��ޤä����ˡ�������ؤ��ޡ�������
159 * �����Ƥ���Ȥޤ����Τǡ���ư������Τ˻Ȥ��ؿ���
160 *----
161 * startpos ��걦�ˤ���ޡ����������Ʊƶ�������롣
162 */
set_marker_ByGeqPosition(struct SKKInputNode * node,int startpos,int setpos)163 static int set_marker_ByGeqPosition
164 ( struct SKKInputNode *node, int startpos, int setpos )
165 {
166 int i ;
167 struct Marker *markers = node->markers ;
168
169 /* ���ߤޤǤλ��Ѥ���Ƥ����Τ��椫�顣*/
170 for( i = 0 ; i < node->marker_usage ; i ++ ){
171 /* �ƶ��������ޡ��������� */
172 if( *( markers[ i ].pos ) <= startpos )
173 continue ;
174 /* �ޡ��������ư�����롣*/
175 *( markers[ i ].pos ) = setpos ;
176 }
177 return 0 ;
178 }
179