OSDN Git Service

* WorkBackup: 2015/08/08(Sat) AM 10:19 ( Partial Tested ExecRedo API functions.)
[drdeamon64/drdeamon64.git] / libedittext / drd64_libedittext_cursorctrl.c
1 /*DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64
2
3                          D r . D e a m o n  6 4
4                         for INTEL64(R), AMD64(R)
5         
6    Copyright(C) 2007-2009 Koine Yuusuke(koinec). All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
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.
16
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.
28
29 DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64DrDeAmOn64*/
30
31 /* File Info -----------------------------------------------------------
32 File: drd64_.c
33 Function: 
34 Comment: 
35 ----------------------------------------------------------------------*/
36
37 #define DRD64_SRC_LIBEDITTEXT_CURSORCTRL
38 #include"drd64_libedittext.h"
39
40 #define LOCATION(n)     DRD64_ERR_LOCATION( \
41                                                 DRD64_ERROR_MODULE_LIBEDITTEXT, DRD64_ERROR_ARCH_NODEPEND, \
42                                                 DRD64_SRC_LIBEDITTEXT_CURSORCTRL_SRCID, (n))
43
44
45 /*----------------------------------------------------------------------
46 ----------------------------------------------------------------------*/
47 LIBEDITTEXT_CURSORCTRL_EXTERN
48 int
49         LibEditText_CursorCtrl_AdjustCursorPosition_DeleteString(
50                         LibEditText_TextInfo    *p_tinfo,
51                         LibEditText_LineInfo    *p_line, 
52                         DWord   dw_start,
53                         DWord   dw_len )
54 {
55         int             i_cnt;
56         LibEditText_Cursor      *p_cursor;
57
58         assert( NULL != p_tinfo );
59         assert( NULL != p_line );
60
61         for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ )       {
62                 p_cursor        = &(p_tinfo->t_cursor[i_cnt]);
63                 
64                 if( 0 == p_cursor->dw_rangelines )      { continue; }
65
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; }
70         }
71         
72         return 0x00;
73 }
74
75
76 /*----------------------------------------------------------------------
77 ----------------------------------------------------------------------*/
78 LIBEDITTEXT_CURSORCTRL_EXTERN
79 int
80         LibEditText_CursorCtrl_AdjustCursorPosition_InsertString(
81                         LibEditText_TextInfo    *p_tinfo,
82                         LibEditText_LineInfo    *p_line, 
83                         DWord   dw_start,
84                         DWord   dw_len )
85 {
86         int             i_cnt;
87         LibEditText_Cursor      *p_cursor;
88
89         assert( NULL != p_tinfo );
90         assert( NULL != p_line );
91
92         for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ )       {
93                 p_cursor        = &(p_tinfo->t_cursor[i_cnt]);
94                 
95                 if( 0 == p_cursor->dw_rangelines )      { continue; }
96
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; }
101         }
102         
103         return 0x00;
104 }
105
106
107 /*----------------------------------------------------------------------
108 ----------------------------------------------------------------------*/
109 int
110         LibEditText_CursorCtrl_CheckAdujstCursorRange(
111                         LibEditText_TextInfo    *p_tinfo,
112                         LibEditText_Cursor              *p_cursor )
113 {
114         DWord   dw_start;
115         DWord   dw_end;
116         DWord   dw_center;
117         DWord   dw_remain;
118         DWord   dw_curlrow;
119         LibEditText_LineInfo    *p_lnow;
120
121         assert( NULL != p_tinfo );
122         assert( NULL != p_cursor );
123
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);
133
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++;
139         }
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--;
143         }
144
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++;
150         }
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--;
154         }
155
156         return 0x00;
157 }
158
159
160 /*----------------------------------------------------------------------
161 ----------------------------------------------------------------------*/
162 LIBEDITTEXT_CURSORCTRL_EXTERN
163 int
164         LibEditText_CursorCtrl_InsertLine(
165                         LibEditText_TextInfo    *p_tinfo,
166                         DWord   dw_line )
167 {
168         int             i_cnt;
169         LibEditText_Cursor      *p_cursor;
170
171         assert( NULL != p_tinfo );
172
173         for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ )       {
174                 p_cursor        = &(p_tinfo->t_cursor[i_cnt]);
175
176                 if( 0 == p_cursor->dw_rangelines )      { continue; }
177
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 );
181
182                 if(( dw_line <= p_cursor->dw_line )
183                                         && ( p_cursor->dw_line + 1 < p_tinfo->dw_maxline))
184                         { p_cursor->dw_line++; }
185
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++; }
189
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++; }
193
194                 // Adjust CursorRange
195                 LibEditText_CursorCtrl_CheckAdujstCursorRange( p_tinfo, p_cursor );
196         }
197         
198         return 0x00;
199 }
200
201
202 /*----------------------------------------------------------------------
203 ----------------------------------------------------------------------*/
204 LIBEDITTEXT_CURSORCTRL_EXTERN
205 int
206         LibEditText_CursorCtrl_PreProc_DeleteLine(
207                         LibEditText_TextInfo    *p_tinfo,
208                         DWord   dw_line )
209 {
210         int             i_cnt;
211         LibEditText_Cursor      *p_cursor;
212         LibEditText_LineInfo    *p_line;
213
214         assert( NULL != p_tinfo );
215         assert( 1 < p_tinfo->dw_maxline );
216
217         for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ )       {
218                 p_cursor        = &(p_tinfo->t_cursor[i_cnt]);
219
220                 if( 0 == p_cursor->dw_rangelines )      { continue; }
221
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 );
225
226                 if( dw_line == p_cursor->dw_line )      {
227                         if( dw_line + 1 == p_tinfo->dw_maxline )        {
228                                 assert( p_cursor->dw_line > 0 );
229                                 p_cursor->dw_line--;
230                                 p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
231                                 assert( NULL != p_line );
232                                 p_cursor->dw_lineid     = p_line->dw_before;
233                         }
234                         else    {
235                                 p_cursor->dw_line++;
236                                 p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
237                                 assert( NULL != p_line );
238                                 p_cursor->dw_lineid     = p_line->dw_next;
239                         }
240                 }
241
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;
248                 }
249
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;
257                         }
258                         else    {
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;
263                         }
264
265                 }
266         }
267         
268         return 0x00;
269 }
270
271
272 /*----------------------------------------------------------------------
273 ----------------------------------------------------------------------*/
274 LIBEDITTEXT_CURSORCTRL_EXTERN
275 int
276         LibEditText_CursorCtrl_DeleteLine(
277                         LibEditText_TextInfo    *p_tinfo,
278                         DWord   dw_line )
279 {
280         int             i_cnt;
281         LibEditText_Cursor      *p_cursor;
282
283         assert( NULL != p_tinfo );
284
285         for( i_cnt = 0; i_cnt < p_tinfo->dw_maxcursors; i_cnt++ )       {
286                 p_cursor        = &(p_tinfo->t_cursor[i_cnt]);
287
288                 if( 0 == p_cursor->dw_rangelines )      { continue; }
289
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 );
293
294                 if(( dw_line < p_cursor->dw_line ) && ( 0 < p_cursor->dw_line ))
295                         { p_cursor->dw_line--; }
296
297                 if(( dw_line < p_cursor->dw_start_line ) && ( 0 < p_cursor->dw_start_line ))
298                         { p_cursor->dw_start_line--; }
299
300                 if(( dw_line < p_cursor->dw_end_line ) && ( 0 < p_cursor->dw_end_line ))
301                         { p_cursor->dw_end_line--; }
302
303                 // Adjust CursorRange
304                 LibEditText_CursorCtrl_CheckAdujstCursorRange( p_tinfo, p_cursor );
305         }
306         
307         return 0x00;
308 }
309
310
311 /* EOF of drd64_.c ----------------------------------- */