• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂589 (tree)
時間2013-11-24 17:13:21
作者ornse01

Log Message

implement caret moving for upper and lower.

Change Summary

差異

--- bchank/trunk/src/bchank_lines.c (revision 588)
+++ bchank/trunk/src/bchank_lines.c (revision 589)
@@ -42,6 +42,7 @@
4242 struct bchank_line_t_ {
4343 QUEUE que;
4444 tadfragment_t fragment;
45+ W width;
4546 W *pos;
4647 W pos_len;
4748 };
@@ -70,6 +71,17 @@
7071 {
7172 }
7273
74+EXPORT W bchank_line_getX(bchank_line_t *line, W pos)
75+{
76+ if (pos > line->pos_len) {
77+ return -1;
78+ }
79+ if (pos == line->pos_len) {
80+ return line->width;
81+ }
82+ return line->pos[pos];
83+}
84+
7385 LOCAL bchank_line_t* bchank_line_new()
7486 {
7587 bchank_line_t *line;
@@ -80,6 +92,7 @@
8092 }
8193 QueInit(&line->que);
8294 tadfragment_initialize(&line->fragment);
95+ line->width = 0;
8396 line->pos = NULL;
8497 line->pos_len = 0;
8598
@@ -232,6 +245,8 @@
232245 }
233246 taditerator_finalize(&iterator);
234247
248+ line->width = w;
249+
235250 return w;
236251 }
237252
--- bchank/trunk/src/main.c (revision 588)
+++ bchank/trunk/src/main.c (revision 589)
@@ -202,9 +202,31 @@
202202 bchank_genv_t *genv;
203203 bchank_linelist_t *text;
204204 bchank_caret_t caret;
205+ struct {
206+ W x;
207+ W y;
208+ } insert_pos;
205209 };
206210 typedef struct bchank_t_ bchank_t;
207211
212+LOCAL W bchank_caretupdate(bchank_t *bchank)
213+{
214+ bchank_line_t *line;
215+ W x, y;
216+
217+ line = bchank_linelist_get(bchank->text, bchank->insert_pos.y);
218+ if (line == NULL) {
219+ return -1;
220+ }
221+ x = bchank_line_getX(line, bchank->insert_pos.x);
222+ if (x < 0) {
223+ return -1;
224+ }
225+ y = (bchank->insert_pos.y + 1) * 18 - 2;
226+ cssrendering_coordinate_getrelativepoint(&bchank->scroll, x, y, &x, &y);
227+ return bchank_caret_changepos(&bchank->caret, (PNT){x, y});
228+}
229+
208230 LOCAL W bchank_draw(bchank_t *bchank, GID target, RECT r)
209231 {
210232 cssrendering_drawtraversal_t traversal;
@@ -363,10 +385,6 @@
363385
364386 cssrendering_coordinate_setdrawrect(&bchank->scroll, bchank->root.base.content_edge);
365387
366- bchank_caret_changepos(&bchank->caret, (PNT){0, 16});
367- bchank_caret_appear(&bchank->caret, target);
368- req_tmg(500, 0);
369-
370388 return 0;
371389 }
372390
@@ -443,6 +461,8 @@
443461 cssrendering_blockbox_appendanonymouschild(&bchank->root, &bchank->line_content);
444462
445463 bchank_caret_initialize(&bchank->caret);
464+ bchank->insert_pos.x = 0;
465+ bchank->insert_pos.y = 0;
446466
447467 return 0;
448468
@@ -473,10 +493,45 @@
473493 free(bchank->data.bin);
474494 }
475495
496+LOCAL VOID bchank_hmi_keydown(bchank_t *bchank, UH keycode, TC ch, UW stat)
497+{
498+ W lines;
499+
500+ switch (ch) {
501+ case KC_CC_U:
502+ if (bchank->insert_pos.y - 1 < 0) {
503+ break;
504+ }
505+ bchank->insert_pos.y--;
506+ bchank_caretupdate(bchank);
507+ break;
508+ case KC_CC_D:
509+ lines = bchank_linelist_length(bchank->text);
510+ if (bchank->insert_pos.y + 1 >= lines) {
511+ break;
512+ }
513+ bchank->insert_pos.y++;
514+ bchank_caretupdate(bchank);
515+ break;
516+ case KC_CC_R:
517+ break;
518+ case KC_CC_L:
519+ break;
520+ case KC_PG_U:
521+ break;
522+ case KC_PG_D:
523+ break;
524+ case KC_PG_R:
525+ break;
526+ case KC_PG_L:
527+ break;
528+ }
529+}
530+
476531 LOCAL VOID bchank_hmi_timeout(bchank_t *bchank, W code)
477532 {
478533 bchank_caret_blink(&bchank->caret);
479- req_tmg(1000, 0);
534+ req_tmg(ichg_blk(-1), 0);
480535 }
481536
482537 LOCAL VOID bchank_hmi_draw(bchank_t *bchank, editorwindow_t *window)
@@ -489,15 +544,18 @@
489544 }
490545 editorwindow_eraseworkarea(window, &r);
491546 bchank_draw(bchank, editorwindow_getGID(window), r);
547+ bchank_caret_appear(&bchank->caret, editorwindow_getGID(window));
492548 } while (editorwindow_endredisp(window) > 0);
493549 }
494550
495551 LOCAL VOID bchank_hmi_scroll(bchank_t *bchank, editorwindow_t *window, W dh, W dv)
496552 {
553+ bchank_caret_disappear(&bchank->caret);
497554 cssrendering_coordinate_scrollviewrect(&bchank->scroll, dh, dv);
555+ bchank_caret_scroll(&bchank->caret, dh, dv);
498556 editorwindow_scrollworkarea(window, -dh, -dv);
499- bchank_caret_scroll(&bchank->caret, dh, dv);
500557 bchank_hmi_draw(bchank, window);
558+ bchank_caret_appear(&bchank->caret, editorwindow_getGID(window));
501559 }
502560
503561 LOCAL VOID bchank_hmi_resize(bchank_t *bchank, editorwindow_t *window, SIZE newsize)
@@ -528,9 +586,14 @@
528586
529587 switch (evt->type) {
530588 case BCHANKHMIEVENT_TYPE_NONE:
589+ break;
531590 case BCHANKHMIEVENT_TYPE_COMMON_MOUSEMOVE:
591+ break;
532592 case BCHANKHMIEVENT_TYPE_COMMON_KEYDOWN:
593+ bchank_hmi_keydown(bchank, evt->data.common_keydown.keytop, evt->data.common_keydown.keycode, evt->data.common_keydown.stat);
594+ break;
533595 case BCHANKHMIEVENT_TYPE_COMMON_MENU:
596+ break;
534597 case BCHANKHMIEVENT_TYPE_COMMON_TIMEOUT:
535598 bchank_hmi_timeout(bchank, evt->data.common_timeout.code);
536599 break;
@@ -596,6 +659,10 @@
596659 cssrendering_coordinate_getdrawrect(&bchank->scroll, &l, &t, &r, &b);
597660 editorwindow_setdrawrect(window, l, t, r, b);
598661
662+ bchank_caret_appear(&bchank->caret, editorwindow_getGID(window));
663+ bchank_caretupdate(bchank);
664+ req_tmg(500, 0);
665+
599666 for (;;) {
600667 cont = hmi_eventdispatch(hmi, window, bchank);
601668 if (cont == False) {
--- bchank/trunk/src/bchank_lines.h (revision 588)
+++ bchank/trunk/src/bchank_lines.h (revision 589)
@@ -37,6 +37,7 @@
3737 IMPORT W bchank_line_appendtext(bchank_line_t *line, TC *str, W len);
3838 IMPORT W bchank_line_inserttext(bchank_line_t *line, W pos, TC *str, W len);
3939 IMPORT W bchank_line_removetext(bchank_line_t *line, W pos, W len);
40+IMPORT W bchank_line_getX(bchank_line_t *line, W pos);
4041
4142 typedef struct bchank_linelist_t_ bchank_linelist_t;
4243
@@ -44,6 +45,7 @@
4445 IMPORT VOID bchank_linelist_delete(bchank_linelist_t *list);
4546 IMPORT bchank_line_t* bchank_linelist_get(bchank_linelist_t *list, W at);
4647 IMPORT bchank_line_t* bchank_linelist_append(bchank_linelist_t *list);
48+IMPORT W bchank_linelist_length(bchank_linelist_t *list);
4749 IMPORT W bchank_linelist_calclinewidth(bchank_linelist_t *list, bchank_line_t *line, GID target);
4850 IMPORT W bchank_linelist_drawline(bchank_linelist_t *list, bchank_line_t *line, GID target);
4951 IMPORT W bchank_linelist_drawunderline(bchank_linelist_t *list, bchank_line_t *line, W x, W y, GID target);
Show on old repository browser