OSDN Git Service

* WorkBackup: 2015/06/23(Tue) AM 05:51 (Testing & DeBugging LibEditText_LineCtrl_Spli...
[drdeamon64/drdeamon64.git] / libedittext / drd64_libedittext_cursormove.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_CURSORMOVE
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_CURSORMOVE_SRCID, (n))
43
44
45 /*----------------------------------------------------------------------
46 ----------------------------------------------------------------------*/
47 LIBEDITTEXT_CURSORMOVE_EXTERN
48 int
49         LibEditText_CursorMove_MoveEnd(
50                         LibEditText_TextInfo    *p_tinfo, 
51                         LibEditText_Cursor              *p_cursor )
52 {
53         LibEditText_LineInfo    *p_line;
54
55         assert( NULL != p_tinfo );
56         assert( NULL != p_cursor );
57         
58         p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
59         assert( NULL != p_line );
60
61         p_cursor->dw_pos = p_line->dw_strlen - 1;
62
63         return 0x00;
64 }
65
66
67 /*----------------------------------------------------------------------
68 ----------------------------------------------------------------------*/
69 LIBEDITTEXT_CURSORMOVE_EXTERN
70 int
71         LibEditText_CursorMove_MoveStart(
72                         LibEditText_TextInfo    *p_tinfo, 
73                         LibEditText_Cursor              *p_cursor )
74 {
75         assert( NULL != p_tinfo );
76         assert( NULL != p_cursor );
77         
78         p_cursor->dw_pos = 0;
79
80         return 0x00;
81 }
82
83
84 /*----------------------------------------------------------------------
85 ----------------------------------------------------------------------*/
86 LIBEDITTEXT_CURSORMOVE_EXTERN
87 int
88         LibEditText_CursorMove_MoveRight(
89                         LibEditText_TextInfo    *p_tinfo, 
90                         LibEditText_Cursor              *p_cursor,
91                         DWord                                   dw_len )
92 {
93         LibEditText_LineInfo    *p_line;
94
95         assert( NULL != p_tinfo );
96         assert( NULL != p_cursor );
97         
98         p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
99         assert( NULL != p_line );
100
101         p_cursor->dw_pos
102                         = ((p_cursor->dw_pos + dw_len + 1 < p_line->dw_strlen)
103                                                 ? (p_cursor->dw_pos + dw_len) : (p_line->dw_strlen - 1));
104
105         return 0x00;
106 }
107
108
109 /*----------------------------------------------------------------------
110 ----------------------------------------------------------------------*/
111 LIBEDITTEXT_CURSORMOVE_EXTERN
112 int
113         LibEditText_CursorMove_MoveLeft(
114                         LibEditText_TextInfo    *p_tinfo, 
115                         LibEditText_Cursor              *p_cursor,
116                         DWord                                   dw_len )
117 {
118         assert( NULL != p_tinfo );
119         assert( NULL != p_cursor );
120         
121         p_cursor->dw_pos
122                         = ((p_cursor->dw_pos >= dw_len) ? (p_cursor->dw_pos - dw_len) : 0);
123
124         return 0x00;
125 }
126
127
128 /*----------------------------------------------------------------------
129 ----------------------------------------------------------------------*/
130 LIBEDITTEXT_CURSORMOVE_EXTERN
131 int
132         LibEditText_CursorMove_MoveUp(
133                         LibEditText_TextInfo    *p_tinfo,
134                         LibEditText_Cursor              *p_cursor,
135                         DWord                                   dw_lines )
136 {
137         DWord   dw_cnt;
138         DWord   dw_start;
139         DWord   dw_end;
140         DWord   dw_center;
141         DWord   dw_remain;
142         DWord   dw_curlrow;
143         LibEditText_LineInfo    *p_line;
144         
145         assert( NULL != p_tinfo );
146         assert( NULL != p_cursor );
147
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));
156         
157         for( dw_cnt = 0; dw_cnt < dw_lines; dw_cnt++ )  {
158                 if( p_cursor->dw_line > 0 )     {
159                         p_cursor->dw_line--;
160                         p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
161                         p_cursor->dw_lineid     = p_line->dw_before;
162
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;
168                         }
169         
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;
175                         }
176                 }
177         }
178
179         // Cursor Horizon-Postion Adjust ---
180         p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
181         assert( NULL != p_line );
182
183         p_cursor->dw_pos        = ((p_cursor->dw_pos < p_line->dw_strlen)
184                                                                 ? p_cursor->dw_pos  : p_line->dw_strlen );
185
186         return 0x00;
187 }
188
189
190 /*----------------------------------------------------------------------
191 ----------------------------------------------------------------------*/
192 LIBEDITTEXT_CURSORMOVE_EXTERN
193 int
194         LibEditText_CursorMove_MoveDown(
195                         LibEditText_TextInfo    *p_tinfo,
196                         LibEditText_Cursor              *p_cursor,
197                         DWord                                   dw_lines )
198 {
199         DWord   dw_cnt;
200         DWord   dw_start;
201         DWord   dw_end;
202         DWord   dw_center;
203         DWord   dw_remain;
204         DWord   dw_curlrow;
205         LibEditText_LineInfo    *p_line;
206         
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));
215         
216         assert( NULL != p_tinfo );
217         assert( NULL != p_cursor );
218
219         for( dw_cnt = 0; dw_cnt < dw_lines; dw_cnt++ )  {
220                 if( p_cursor->dw_line + 1 < p_tinfo->dw_maxline )       {
221                         p_cursor->dw_line++;
222                         p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
223                         p_cursor->dw_lineid     = p_line->dw_next;
224
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;
230                         }
231         
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;
237                         }
238                 }
239         }
240
241         // Cursor Horizon-Postion Adjust ---
242         p_line  = LINFO(p_tinfo, p_cursor->dw_lineid);
243         assert( NULL != p_line );
244
245         p_cursor->dw_pos        = ((p_cursor->dw_pos < p_line->dw_strlen)
246                                                                 ? p_cursor->dw_pos  : p_line->dw_strlen );
247
248         return 0x00;
249 }
250
251
252 /* EOF of drd64_.c ----------------------------------- */