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_CURSORCTRL
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_CURSORCTRL_SRCID, (n))
45 /*----------------------------------------------------------------------
46 ----------------------------------------------------------------------*/
47 LIBEDITTEXT_CURSORCTRL_EXTERN
49 LibEditText_CursorCtrl_AdjustCursorPosition_DeleteString(
50 LibEditText_TextInfo *p_tinfo,
51 LibEditText_LineInfo *p_line,
56 LibEditText_Cursor *p_cursor;
58 assert( NULL != p_tinfo );
59 assert( NULL != p_line );
61 for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ ) {
62 p_cursor = &(p_tinfo->t_cursor[i_cnt]);
64 if( 0 == p_cursor->dw_rangelines ) { continue; }
66 if(( p_line->dw_id == p_cursor->dw_line )
67 && ( dw_start < p_cursor->dw_pos )
68 && ( (dw_start + dw_len) >= p_cursor->dw_pos ))
69 { p_cursor->dw_pos = dw_start; }
76 /*----------------------------------------------------------------------
77 ----------------------------------------------------------------------*/
78 LIBEDITTEXT_CURSORCTRL_EXTERN
80 LibEditText_CursorCtrl_AdjustCursorPosition_InsertString(
81 LibEditText_TextInfo *p_tinfo,
82 LibEditText_LineInfo *p_line,
87 LibEditText_Cursor *p_cursor;
89 assert( NULL != p_tinfo );
90 assert( NULL != p_line );
92 for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ ) {
93 p_cursor = &(p_tinfo->t_cursor[i_cnt]);
95 if( 0 == p_cursor->dw_rangelines ) { continue; }
97 if(( p_line->dw_id == p_cursor->dw_lineid )
98 && ( dw_start < p_cursor->dw_pos )
99 && ( (dw_start + dw_len) >= p_cursor->dw_pos ))
100 { p_cursor->dw_pos = dw_start; }
107 /*----------------------------------------------------------------------
108 ----------------------------------------------------------------------*/
110 LibEditText_CursorCtrl_CheckAdujstCursorRange(
111 LibEditText_TextInfo *p_tinfo,
112 LibEditText_Cursor *p_cursor )
119 LibEditText_LineInfo *p_lnow;
121 assert( NULL != p_tinfo );
122 assert( NULL != p_cursor );
124 // Calc. Cursor Range Start&End Line ---
125 dw_curlrow = p_cursor->dw_line;
126 dw_center = (p_cursor->dw_rangelines - 1) / 2;
127 dw_start = ((dw_curlrow > dw_center) ? (dw_curlrow - dw_center) : 0);
128 dw_remain = ((dw_center > dw_curlrow) ? (dw_center - dw_curlrow) : 0);
129 dw_end = (p_cursor->dw_rangelines - dw_center - 1) + dw_curlrow + dw_remain;
130 dw_end = ((p_tinfo->dw_maxline > dw_end) ? dw_end: (p_tinfo->dw_maxline - 1));
131 dw_remain = (p_cursor->dw_rangelines - dw_center - 1) - (dw_end - dw_curlrow);
132 dw_start = ((dw_start >= dw_remain) ? (dw_start - dw_remain) : 0);
134 // Adjust Cursor-Start line ---
135 p_lnow = LINFO(p_tinfo, p_cursor->dw_start_lineid);
136 if( p_cursor->dw_start_line < dw_start ) {
137 p_cursor->dw_start_lineid = p_lnow->dw_next;
138 p_cursor->dw_start_line++;
140 else if( p_cursor->dw_start_line > dw_start ) {
141 p_cursor->dw_start_lineid = p_lnow->dw_before;
142 p_cursor->dw_start_line--;
145 // Adjust Cursor-End line ---
146 p_lnow = LINFO(p_tinfo, p_cursor->dw_end_lineid);
147 if( p_cursor->dw_end_line < dw_end ) {
148 p_cursor->dw_end_lineid = p_lnow->dw_next;
149 p_cursor->dw_end_line++;
151 else if( p_cursor->dw_end_line > dw_end ) {
152 p_cursor->dw_end_lineid = p_lnow->dw_before;
153 p_cursor->dw_end_line--;
160 /*----------------------------------------------------------------------
161 ----------------------------------------------------------------------*/
162 LIBEDITTEXT_CURSORCTRL_EXTERN
164 LibEditText_CursorCtrl_InsertLine(
165 LibEditText_TextInfo *p_tinfo,
169 LibEditText_Cursor *p_cursor;
171 assert( NULL != p_tinfo );
173 for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ ) {
174 p_cursor = &(p_tinfo->t_cursor[i_cnt]);
176 if( 0 == p_cursor->dw_rangelines ) { continue; }
178 assert( INVALID_LINE != p_cursor->dw_lineid );
179 assert( INVALID_LINE != p_cursor->dw_start_lineid );
180 assert( INVALID_LINE != p_cursor->dw_end_lineid );
182 if(( dw_line <= p_cursor->dw_line )
183 && ( p_cursor->dw_line + 1 < p_tinfo->dw_maxline))
184 { p_cursor->dw_line++; }
186 if(( dw_line <= p_cursor->dw_start_line )
187 && ( p_cursor->dw_start_line + 1 < p_tinfo->dw_maxline))
188 { p_cursor->dw_start_line++; }
190 if(( dw_line <= p_cursor->dw_end_line )
191 && ( p_cursor->dw_end_line + 1 < p_tinfo->dw_maxline))
192 { p_cursor->dw_end_line++; }
194 // Adjust CursorRange
195 LibEditText_CursorCtrl_CheckAdujstCursorRange( p_tinfo, p_cursor );
202 /*----------------------------------------------------------------------
203 ----------------------------------------------------------------------*/
204 LIBEDITTEXT_CURSORCTRL_EXTERN
206 LibEditText_CursorCtrl_PreProc_DeleteLine(
207 LibEditText_TextInfo *p_tinfo,
211 LibEditText_Cursor *p_cursor;
212 LibEditText_LineInfo *p_line;
214 assert( NULL != p_tinfo );
215 assert( 1 < p_tinfo->dw_maxline );
217 for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ ) {
218 p_cursor = &(p_tinfo->t_cursor[i_cnt]);
220 if( 0 == p_cursor->dw_rangelines ) { continue; }
222 assert( INVALID_LINE != p_cursor->dw_lineid );
223 assert( INVALID_LINE != p_cursor->dw_start_lineid );
224 assert( INVALID_LINE != p_cursor->dw_end_lineid );
226 if( dw_line == p_cursor->dw_line ) {
227 if( dw_line + 1 == p_tinfo->dw_maxline ) {
228 assert( p_cursor->dw_line > 0 );
230 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
231 assert( NULL != p_line );
232 p_cursor->dw_lineid = p_line->dw_before;
236 p_line = LINFO(p_tinfo, p_cursor->dw_lineid);
237 assert( NULL != p_line );
238 p_cursor->dw_lineid = p_line->dw_next;
242 if( dw_line == p_cursor->dw_start_line ) {
243 assert( p_cursor->dw_start_line + 1 < p_tinfo->dw_maxline );
244 p_cursor->dw_start_line++;
245 p_line = LINFO(p_tinfo, p_cursor->dw_start_lineid);
246 assert( NULL != p_line );
247 p_cursor->dw_start_lineid = p_line->dw_next;
250 if( dw_line == p_cursor->dw_end_line ) {
251 if( p_cursor->dw_end_line + 1 == p_tinfo->dw_maxline ) {
252 assert( p_cursor->dw_end_line > 0 );
253 p_cursor->dw_end_line--;
254 p_line = LINFO(p_tinfo, p_cursor->dw_end_lineid);
255 assert( NULL != p_line );
256 p_cursor->dw_end_lineid = p_line->dw_before;
259 p_cursor->dw_end_line++;
260 p_line = LINFO(p_tinfo, p_cursor->dw_end_lineid);
261 assert( NULL != p_line );
262 p_cursor->dw_end_lineid = p_line->dw_next;
272 /*----------------------------------------------------------------------
273 ----------------------------------------------------------------------*/
274 LIBEDITTEXT_CURSORCTRL_EXTERN
276 LibEditText_CursorCtrl_DeleteLine(
277 LibEditText_TextInfo *p_tinfo,
281 LibEditText_Cursor *p_cursor;
283 assert( NULL != p_tinfo );
285 for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ ) {
286 p_cursor = &(p_tinfo->t_cursor[i_cnt]);
288 if( 0 == p_cursor->dw_rangelines ) { continue; }
290 assert( INVALID_LINE != p_cursor->dw_lineid );
291 assert( INVALID_LINE != p_cursor->dw_start_lineid );
292 assert( INVALID_LINE != p_cursor->dw_end_lineid );
294 if(( dw_line < p_cursor->dw_line ) && ( 0 < p_cursor->dw_line ))
295 { p_cursor->dw_line--; }
297 if(( dw_line < p_cursor->dw_start_line ) && ( 0 < p_cursor->dw_start_line ))
298 { p_cursor->dw_start_line--; }
300 if(( dw_line < p_cursor->dw_end_line ) && ( 0 < p_cursor->dw_end_line ))
301 { p_cursor->dw_end_line--; }
303 // Adjust CursorRange
304 LibEditText_CursorCtrl_CheckAdujstCursorRange( p_tinfo, p_cursor );
311 /* EOF of drd64_.c ----------------------------------- */