1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
4 for INTEL64(R), AMD64(R)
6 Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY Koine Yuusuke(koinec) ``AS IS'' AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL Koine Yuusuke(koinec) OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 OF THE POSSIBILITY OF SUCH DAMAGE.
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
31 /* File Info -----------------------------------------------------------
35 ----------------------------------------------------------------------*/
37 #define DRD64_SRC_LIBEDITTEXT_CURSORMOVE
38 #include"drd64_libedittext.h"
40 #define LOCATION(n) DRD64_ERR_LOCATION( \
41 DRD64_ERROR_MODULE_LIBEDITTEXT, DRD64_ERROR_ARCH_NODEPEND, \
42 DRD64_SRC_LIBEDITTEXT_CURSORMOVE_SRCID, (n))
45 /*----------------------------------------------------------------------
46 ----------------------------------------------------------------------*/
47 LIBEDITTEXT_CURSORMOVE_EXTERN
49 LibEditText_CursorMove_MoveEnd(
50 LibEditText_TextInfo *p_tinfo,
51 LibEditText_Cursor *p_cursor )
53 LibEditText_LineInfo *p_line;
55 assert( NULL != p_tinfo );
56 assert( NULL != p_cursor );
58 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
59 assert( NULL != p_line );
61 p_cursor->dw_pos = p_line->dw_strlen - 1;
67 /*----------------------------------------------------------------------
68 ----------------------------------------------------------------------*/
69 LIBEDITTEXT_CURSORMOVE_EXTERN
71 LibEditText_CursorMove_MoveStart(
72 LibEditText_TextInfo *p_tinfo,
73 LibEditText_Cursor *p_cursor )
75 assert( NULL != p_tinfo );
76 assert( NULL != p_cursor );
84 /*----------------------------------------------------------------------
85 ----------------------------------------------------------------------*/
86 LIBEDITTEXT_CURSORMOVE_EXTERN
88 LibEditText_CursorMove_MoveRight(
89 LibEditText_TextInfo *p_tinfo,
90 LibEditText_Cursor *p_cursor,
93 LibEditText_LineInfo *p_line;
95 assert( NULL != p_tinfo );
96 assert( NULL != p_cursor );
98 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
99 assert( NULL != p_line );
102 = ((p_cursor->dw_pos + dw_len + 1 < p_line->dw_strlen)
103 ? (p_cursor->dw_pos + dw_len) : (p_line->dw_strlen - 1));
109 /*----------------------------------------------------------------------
110 ----------------------------------------------------------------------*/
111 LIBEDITTEXT_CURSORMOVE_EXTERN
113 LibEditText_CursorMove_MoveLeft(
114 LibEditText_TextInfo *p_tinfo,
115 LibEditText_Cursor *p_cursor,
118 assert( NULL != p_tinfo );
119 assert( NULL != p_cursor );
122 = ((p_cursor->dw_pos >= dw_len) ? (p_cursor->dw_pos - dw_len) : 0);
128 /*----------------------------------------------------------------------
129 ----------------------------------------------------------------------*/
130 LIBEDITTEXT_CURSORMOVE_EXTERN
132 LibEditText_CursorMove_MoveUp(
133 LibEditText_TextInfo *p_tinfo,
134 LibEditText_Cursor *p_cursor,
143 LibEditText_LineInfo *p_line;
145 assert( NULL != p_tinfo );
146 assert( NULL != p_cursor );
148 // Calc. Cursor Range Start&End Line ---
149 dw_curlrow = (( p_cursor->dw_line >= dw_lines )
150 ? (p_cursor->dw_line - dw_lines) : 0 );
151 dw_center = (p_cursor->dw_rangelines - 1) / 2;
152 dw_start = ((dw_curlrow > dw_center) ? (dw_curlrow - dw_center) : 0);
153 dw_remain = ((dw_center > dw_curlrow) ? (dw_center - dw_curlrow) : 0);
154 dw_end = (p_cursor->dw_rangelines - dw_center - 1) + dw_curlrow + dw_remain;
155 dw_end = ((p_tinfo->dw_maxline > dw_end) ? dw_end: (p_tinfo->dw_maxline - 1));
157 for( dw_cnt = 0; dw_cnt < dw_lines; dw_cnt++ ) {
158 if( p_cursor->dw_line > 0 ) {
160 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
161 p_cursor->dw_lineid = p_line->dw_before;
163 if(( p_cursor->dw_start_line > 0 )
164 && ( p_cursor->dw_start_line > dw_start )) {
165 p_cursor->dw_start_line--;
166 p_line = LINFO(p_tinfo, p_cursor->dw_start_lineid);
167 p_cursor->dw_start_lineid = p_line->dw_before;
170 if(( p_cursor->dw_end_line > 0 )
171 && ( p_cursor->dw_end_line > dw_end )) {
172 p_cursor->dw_end_line--;
173 p_line = LINFO(p_tinfo, p_cursor->dw_end_lineid);
174 p_cursor->dw_end_lineid = p_line->dw_before;
179 // Cursor Horizon-Postion Adjust ---
180 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
181 assert( NULL != p_line );
183 p_cursor->dw_pos = ((p_cursor->dw_pos < p_line->dw_strlen)
184 ? p_cursor->dw_pos : p_line->dw_strlen );
190 /*----------------------------------------------------------------------
191 ----------------------------------------------------------------------*/
192 LIBEDITTEXT_CURSORMOVE_EXTERN
194 LibEditText_CursorMove_MoveDown(
195 LibEditText_TextInfo *p_tinfo,
196 LibEditText_Cursor *p_cursor,
205 LibEditText_LineInfo *p_line;
207 // Calc. Cursor Range Start&End Line ---
208 dw_curlrow = (( p_cursor->dw_line + dw_lines < p_tinfo->dw_maxline )
209 ? (p_cursor->dw_line + dw_lines) : (p_tinfo->dw_maxline - 1) );
210 dw_center = (p_cursor->dw_rangelines - 1) / 2;
211 dw_start = ((dw_curlrow > dw_center) ? (dw_curlrow - dw_center) : 0);
212 dw_remain = ((dw_center > dw_curlrow) ? (dw_center - dw_curlrow) : 0);
213 dw_end = (p_cursor->dw_rangelines - dw_center - 1) + dw_curlrow + dw_remain;
214 dw_end = ((p_tinfo->dw_maxline > dw_end) ? dw_end: (p_tinfo->dw_maxline - 1));
216 assert( NULL != p_tinfo );
217 assert( NULL != p_cursor );
219 for( dw_cnt = 0; dw_cnt < dw_lines; dw_cnt++ ) {
220 if( p_cursor->dw_line + 1 < p_tinfo->dw_maxline ) {
222 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
223 p_cursor->dw_lineid = p_line->dw_next;
225 if(( p_cursor->dw_start_line + 1 < p_tinfo->dw_maxline )
226 && ( p_cursor->dw_start_line < dw_start )) {
227 p_cursor->dw_start_line++;
228 p_line = LINFO(p_tinfo, p_cursor->dw_start_lineid);
229 p_cursor->dw_start_lineid = p_line->dw_next;
232 if(( p_cursor->dw_end_line + 1 < p_tinfo->dw_maxline )
233 && ( p_cursor->dw_end_line < dw_end )) {
234 p_cursor->dw_end_line++;
235 p_line = LINFO(p_tinfo, p_cursor->dw_end_lineid);
236 p_cursor->dw_end_lineid = p_line->dw_next;
241 // Cursor Horizon-Postion Adjust ---
242 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
243 assert( NULL != p_line );
245 p_cursor->dw_pos = ((p_cursor->dw_pos < p_line->dw_strlen)
246 ? p_cursor->dw_pos : p_line->dw_strlen );
252 /* EOF of drd64_.c ----------------------------------- */