• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂448 (tree)
時間2012-04-29 18:56:04
作者ornse01

Log Message

implement external bbs managing functions.

Change Summary

差異

--- bchanl/trunk/src/extbbslist.c (revision 447)
+++ bchanl/trunk/src/extbbslist.c (revision 448)
@@ -66,6 +66,17 @@
6666 QueInsert(&entry->que, &que->que);
6767 }
6868
69+LOCAL VOID extbbslist_item_QueRemove(extbbslist_item_t *entry)
70+{
71+ QueRemove(&entry->que);
72+ QueInit(&entry->que);
73+}
74+
75+LOCAL Bool extbbslist_item_isQueEmpty(extbbslist_item_t *entry)
76+{
77+ return isQueEmpty(&entry->que);
78+}
79+
6980 LOCAL Bool extbbslist_item_titlecheck(extbbslist_item_t *entry, TC *title, W title_len)
7081 {
7182 W cmp;
@@ -107,6 +118,47 @@
107118 item->url.asc_len = url_len;
108119 }
109120
121+LOCAL W extbbslist_item_assigntitle(extbbslist_item_t *item, CONST TC *title, W title_len)
122+{
123+ TC *str;
124+ str = malloc(sizeof(TC)*(title_len+1));
125+ if (str == NULL) {
126+ return -1; /* TODO */
127+ }
128+ memcpy(str, title, sizeof(TC)*title_len);
129+ str[title_len] = TNULL;
130+ extbbslist_item_replacetitle(item, str, title_len);
131+ return 0;
132+}
133+
134+LOCAL W extbbslist_item_assignurl(extbbslist_item_t *item, CONST TC *url, W url_len)
135+{
136+ TC *str;
137+ UB *str_ac;
138+ W len;
139+
140+ str = malloc(sizeof(TC)*(url_len+1));
141+ if (str == NULL) {
142+ return -1; /* TODO */
143+ }
144+ memcpy(str, url, sizeof(TC)*url_len);
145+ str[url_len] = TNULL;
146+
147+ len = tcstosjs(NULL, url);
148+ str_ac = malloc(sizeof(UB)*(len+1));
149+ if (str_ac == NULL) {
150+ free(str);
151+ return -1; /* TODO */
152+ }
153+ tcstosjs(str_ac, url);
154+ str_ac[len] = '\0';
155+
156+ extbbslist_item_replaceTCurl(item, str, url_len);
157+ extbbslist_item_replaceascurl(item, str_ac, len);
158+
159+ return 0;
160+}
161+
110162 LOCAL W extbbslist_item_initialize(extbbslist_item_t *item)
111163 {
112164 QueInit(&item->que);
@@ -160,6 +212,7 @@
160212 struct extbbslist_t_ {
161213 QUEUE sentinel;
162214 extbbslist_readcontext_t *ctx;
215+ extbbslist_editcontext_t *edit;
163216 W num;
164217 LINK *lnk;
165218 W rectype;
@@ -267,6 +320,21 @@
267320 return 0; /* TODO */
268321 }
269322
323+LOCAL VOID extbbslist_clear(extbbslist_t *list)
324+{
325+ extbbslist_item_t *item;
326+ Bool empty;
327+
328+ for (;;) {
329+ empty = isQueEmpty(&list->sentinel);
330+ if (empty == True) {
331+ break;
332+ }
333+ item = (extbbslist_item_t*)list->sentinel.prev;
334+ extbbslist_item_delete(item);
335+ }
336+}
337+
270338 EXPORT W extbbslist_number(extbbslist_t *list)
271339 {
272340 return list->num;
@@ -280,6 +348,402 @@
280348 {
281349 }
282350
351+struct extbbslist_editcontext_t_ {
352+ QUEUE sentinel;
353+ W view_l, view_t, view_r, view_b;
354+ W num;
355+ struct {
356+ extbbslist_item_t *item;
357+ W index;
358+ } selected;
359+};
360+
361+#define EXTBBSLIST_ENTRY_HEIGHT 20
362+#define EXTBBSLIST_ENTRY_PADDING_TOP 1
363+
364+#define EXTBBSLIST_TITLE_WIDTH 128
365+
366+LOCAL extbbslist_item_t* extbbslist_editcontext_sentinelnode(extbbslist_editcontext_t *ctx)
367+{
368+ return (extbbslist_item_t*)&ctx->sentinel;
369+}
370+
371+LOCAL extbbslist_item_t *extbbslist_editcontext_searchitembyindex(extbbslist_editcontext_t *ctx, W index)
372+{
373+ W i;
374+ extbbslist_item_t *senti, *item;
375+
376+ senti = extbbslist_editcontext_sentinelnode(ctx);
377+ item = extbbslist_item_nextnode(senti);
378+ for (i = 0; item != senti; i++) {
379+ if (i == index) {
380+ return item;
381+ }
382+ item = extbbslist_item_nextnode(item);
383+ }
384+ return NULL;
385+}
386+
387+EXPORT W extbbslist_editcontext_append(extbbslist_editcontext_t *ctx, CONST TC *title, W title_len, CONST TC *url, W url_len)
388+{
389+ extbbslist_item_t *item, *senti;
390+ W err;
391+
392+ item = extbbslist_item_new();
393+ if (item == NULL) {
394+ return -1; /* TODO */
395+ }
396+
397+ err = extbbslist_item_assigntitle(item, title, title_len);
398+ if (err < 0) {
399+ extbbslist_item_delete(item);
400+ return err;
401+ }
402+
403+ err = extbbslist_item_assignurl(item, url, url_len);
404+ if (err < 0) {
405+ extbbslist_item_delete(item);
406+ return err;
407+ }
408+
409+ senti = extbbslist_editcontext_sentinelnode(ctx);
410+ extbbslist_item_QueInsert(item, senti);
411+ ctx->num++;
412+
413+ return 0;
414+}
415+
416+EXPORT W extbbslist_editcontext_update(extbbslist_editcontext_t *ctx, W i, CONST TC *title, W title_len, CONST TC *url, W url_len)
417+{
418+ extbbslist_item_t *item;
419+ W err;
420+
421+ item = extbbslist_editcontext_searchitembyindex(ctx, i);
422+ if (item == NULL) {
423+ return -1; /* TODO */
424+ }
425+
426+ err = extbbslist_item_assigntitle(item, title, title_len);
427+ if (err < 0) {
428+ return err;
429+ }
430+
431+ err = extbbslist_item_assignurl(item, url, url_len);
432+ if (err < 0) {
433+ return err;
434+ }
435+
436+ return 0;
437+}
438+
439+LOCAL W extbbslist_editcontext_drawcolseparater(extbbslist_editcontext_t *ctx, GID target, W x_start, W y, W height, PAT *lnpat)
440+{
441+ PNT p1, p2;
442+
443+ p1.y = y;
444+ p2.y = p1.y + height - 1;
445+
446+ p1.x = x_start + EXTBBSLIST_TITLE_WIDTH + 4;
447+ p2.x = p1.x;
448+ gdra_lin(target, p1, p2, 1, lnpat, G_STORE);
449+
450+ return 0;
451+}
452+
453+LOCAL W extbbslist_editcontext_drawitemtext(extbbslist_editcontext_t *ctx, GID target, W x_start, W y, PAT *lnpat, extbbslist_item_t *item)
454+{
455+ SIZE sz;
456+ FSSPEC fspec;
457+ W y2;
458+
459+ gset_scr(target, 0x21);
460+
461+ gget_fon(target, &fspec, NULL);
462+ sz = fspec.size;
463+ fspec.size.h = fspec.size.v;
464+ gset_fon(target, &fspec);
465+
466+ y2 = y + sz.v + EXTBBSLIST_ENTRY_PADDING_TOP;
467+ gdra_stp(target, x_start, y2, item->title, item->title_len, G_STORE);
468+
469+ gset_scr(target, 0x21);
470+
471+ fspec.size.h = fspec.size.v / 2;
472+ gset_fon(target, &fspec);
473+
474+ gdra_stp(target, x_start + EXTBBSLIST_TITLE_WIDTH + 8 , y2, item->url.tc, item->url.tc_len, G_STORE);
475+
476+ extbbslist_editcontext_drawcolseparater(ctx, target, x_start, y, EXTBBSLIST_ENTRY_HEIGHT, lnpat);
477+
478+ return 0;
479+}
480+
481+EXPORT W extbbslist_editcontext_draw(extbbslist_editcontext_t *ctx, GID target, RECT *r)
482+{
483+ W i, x, y;
484+ extbbslist_item_t *senti, *item;
485+ PAT bgpat = {{
486+ 0,
487+ 16, 16,
488+ 0x10efefef,
489+ 0x10efefef,
490+ FILL100
491+ }};
492+ PAT lnpat = {{
493+ 0,
494+ 16, 16,
495+ 0x10000000,
496+ 0x10efefef,
497+ FILL100
498+ }};
499+ RECT bgr;
500+
501+ senti = extbbslist_editcontext_sentinelnode(ctx);
502+ item = extbbslist_item_nextnode(senti);
503+ for (i = 0; ; i++) {
504+ if (item == senti) {
505+ break;
506+ }
507+ if ((ctx->view_t <= (i + 1) * EXTBBSLIST_ENTRY_HEIGHT)&&(i * EXTBBSLIST_ENTRY_HEIGHT <= ctx->view_b)) {
508+ if (ctx->selected.item == item) {
509+ bgpat.spat.fgcol = 0x10000000;
510+ lnpat.spat.fgcol = 0x10FFFFFF;
511+ gset_chc(target, 0x10FFFFFF, 0x10000000);
512+ } else {
513+ bgpat.spat.fgcol = 0x10FFFFFF;
514+ lnpat.spat.fgcol = 0x10000000;
515+ gset_chc(target, 0x10000000, 0x10FFFFFF);
516+ }
517+ bgr.c.left = ctx->view_l;
518+ bgr.c.top = i * EXTBBSLIST_ENTRY_HEIGHT - ctx->view_t;
519+ bgr.c.right = ctx->view_r;
520+ bgr.c.bottom = (i+1) * EXTBBSLIST_ENTRY_HEIGHT - ctx->view_t;
521+ gfil_rec(target, bgr, &bgpat, 0, G_STORE);
522+
523+ x = 0 - ctx->view_l;
524+ y = i * EXTBBSLIST_ENTRY_HEIGHT - ctx->view_t;
525+ extbbslist_editcontext_drawitemtext(ctx, target, x, y, &lnpat, item);
526+ }
527+
528+ item = extbbslist_item_nextnode(item);
529+ }
530+
531+ return 0;
532+}
533+
534+EXPORT Bool extbbslist_editcontext_finditem(extbbslist_editcontext_t *ctx, PNT rel_pos, W *index)
535+{
536+ W n;
537+ n = (rel_pos.y + ctx->view_t) / EXTBBSLIST_ENTRY_HEIGHT;
538+ if (n < ctx->num) {
539+ *index = n;
540+ return True;
541+ }
542+ return False;
543+}
544+
545+IMPORT W extbbslist_editcontext_swapitem(extbbslist_editcontext_t *ctx, W i0, W i1)
546+{
547+ extbbslist_item_t *item0, *item1, *item0_next, *item1_next;
548+ W buf;
549+
550+ if (i0 == i1) {
551+ return 0;
552+ }
553+ if (i1 > i0) {
554+ buf = i1;
555+ i1 = i0;
556+ i0 = buf;
557+ }
558+
559+ item0 = extbbslist_editcontext_searchitembyindex(ctx, i0);
560+ if (item0 == NULL) {
561+ return -1;
562+ }
563+ item0_next = extbbslist_item_nextnode(item0);
564+ item1 = extbbslist_editcontext_searchitembyindex(ctx, i1);
565+ if (item1 == NULL) {
566+ return -1;
567+ }
568+ item1_next = extbbslist_item_nextnode(item1);
569+
570+ if (i0 + 1 == i1) {
571+ extbbslist_item_QueRemove(item1);
572+ extbbslist_item_QueInsert(item1, item0);
573+ return 0;
574+ }
575+
576+ extbbslist_item_QueRemove(item1);
577+ extbbslist_item_QueInsert(item1, item0_next);
578+ extbbslist_item_QueRemove(item0);
579+ extbbslist_item_QueInsert(item0, item1_next);
580+
581+ return 0;
582+}
583+
584+IMPORT W extbbslist_editcontext_deleteitem(extbbslist_editcontext_t *ctx, W i)
585+{
586+ extbbslist_item_t *item;
587+
588+ item = extbbslist_editcontext_searchitembyindex(ctx, i);
589+ if (item == NULL) {
590+ return -1; /* TODO */
591+ }
592+ ctx->num--;
593+ if (ctx->selected.index == i) {
594+ ctx->selected.item = NULL;
595+ ctx->selected.index = -1;
596+ }
597+ ctx->selected.item = item;
598+ ctx->selected.index = i;
599+ return 0;
600+}
601+
602+IMPORT VOID extbbslist_editcontext_setselect(extbbslist_editcontext_t *ctx, W i)
603+{
604+ extbbslist_item_t *item;
605+
606+ item = extbbslist_editcontext_searchitembyindex(ctx, i);
607+ if (item == NULL) {
608+ ctx->selected.item = NULL;
609+ ctx->selected.index = -1;
610+ return;
611+ }
612+ ctx->selected.item = item;
613+ ctx->selected.index = i;
614+}
615+
616+IMPORT W extbbslist_editcontext_getselect(extbbslist_editcontext_t *ctx)
617+{
618+ return ctx->selected.index;
619+}
620+
621+EXPORT VOID extbbslist_editcontext_setviewrect(extbbslist_editcontext_t *ctx, W l, W t, W r, W b)
622+{
623+ ctx->view_l = l;
624+ ctx->view_t = t;
625+ ctx->view_r = r;
626+ ctx->view_b = b;
627+}
628+
629+EXPORT VOID extbbslist_editcontext_getviewrect(extbbslist_editcontext_t *ctx, W *l, W *t, W *r, W *b)
630+{
631+ *l = ctx->view_l;
632+ *t = ctx->view_t;
633+ *r = ctx->view_r;
634+ *b = ctx->view_b;
635+}
636+
637+EXPORT VOID extbbslist_editcontext_scrollviewrect(extbbslist_editcontext_t *ctx, W dh, W dv)
638+{
639+ ctx->view_l += dh;
640+ ctx->view_t += dv;
641+ ctx->view_r += dh;
642+ ctx->view_b += dv;
643+}
644+
645+EXPORT VOID extbbslist_editcontext_getdrawrect(extbbslist_editcontext_t *ctx, W *l, W *t, W *r, W *b)
646+{
647+ *l = 0;
648+ *t = 0;
649+ *r = 200;
650+ *b = EXTBBSLIST_ENTRY_HEIGHT * ctx->num;
651+}
652+
653+LOCAL extbbslist_editcontext_t* extbbslist_editcontext_new()
654+{
655+ extbbslist_editcontext_t *ctx;
656+
657+ ctx = (extbbslist_editcontext_t*)malloc(sizeof(extbbslist_editcontext_t));
658+ if (ctx == NULL) {
659+ return NULL;
660+ }
661+ QueInit(&ctx->sentinel);
662+ ctx->view_l = 0;
663+ ctx->view_t = 0;
664+ ctx->view_r = 0;
665+ ctx->view_b = 0;
666+ ctx->num = 0;
667+ ctx->selected.item = NULL;
668+ ctx->selected.index = -1;
669+
670+ return ctx;
671+}
672+
673+LOCAL VOID extbbslist_editcontext_delete(extbbslist_editcontext_t *ctx)
674+{
675+ extbbslist_item_t *item;
676+ Bool empty;
677+
678+ for (;;) {
679+ empty = isQueEmpty(&ctx->sentinel);
680+ if (empty == True) {
681+ break;
682+ }
683+ item = (extbbslist_item_t*)ctx->sentinel.prev;
684+ extbbslist_item_delete(item);
685+ }
686+ free(ctx);
687+}
688+
689+EXPORT extbbslist_editcontext_t* extbbslist_startedit(extbbslist_t *list)
690+{
691+ extbbslist_editcontext_t *ctx;
692+ extbbslist_item_t *senti, *item;
693+ W err;
694+
695+ if (list->ctx != NULL) {
696+ return NULL;
697+ }
698+ if (list->edit != NULL) {
699+ return NULL;
700+ }
701+
702+ ctx = extbbslist_editcontext_new();
703+ if (ctx == NULL) {
704+ return NULL;
705+ }
706+
707+ senti = extbbslist_sentinelnode(list);
708+ item = extbbslist_item_nextnode(senti);
709+ for (; item != senti;) {
710+ err = extbbslist_editcontext_append(ctx, item->title, item->title_len, item->url.tc, item->url.tc_len);
711+ if (err < 0) {
712+ extbbslist_editcontext_delete(ctx);
713+ return NULL;
714+ }
715+ item = extbbslist_item_nextnode(item);
716+ }
717+
718+ list->edit = ctx;
719+
720+ return ctx;
721+}
722+
723+EXPORT VOID extbbslist_endedit(extbbslist_t *list, extbbslist_editcontext_t *ctx, Bool update)
724+{
725+ extbbslist_item_t *sentinel, *next;
726+ Bool empty;
727+
728+ if (update != False) {
729+ extbbslist_clear(list);
730+
731+ sentinel = extbbslist_editcontext_sentinelnode(ctx);
732+
733+ empty = extbbslist_item_isQueEmpty(sentinel);
734+ if (empty == False) {
735+ next = extbbslist_item_nextnode(sentinel);
736+ extbbslist_item_QueRemove(sentinel);
737+
738+ sentinel = extbbslist_sentinelnode(list);
739+ extbbslist_item_QueInsert(sentinel, next);
740+ }
741+ }
742+
743+ list->edit = NULL;
744+ extbbslist_editcontext_delete(ctx);
745+}
746+
283747 struct extbbslist_readcontext_t_ {
284748 extbbslist_item_t *sentinel;
285749 extbbslist_item_t *curr;
@@ -342,6 +806,7 @@
342806 {
343807 QueInit(&list->sentinel);
344808 list->ctx = NULL;
809+ list->edit = NULL;
345810 list->num = 0;
346811 list->lnk = db_link;
347812 list->rectype = rectype;
@@ -350,17 +815,7 @@
350815
351816 LOCAL VOID extbbslist_finalize(extbbslist_t *list)
352817 {
353- extbbslist_item_t *item;
354- Bool empty;
355-
356- for (;;) {
357- empty = isQueEmpty(&list->sentinel);
358- if (empty == True) {
359- break;
360- }
361- item = (extbbslist_item_t*)list->sentinel.prev;
362- extbbslist_item_delete(item);
363- }
818+ extbbslist_clear(list);
364819 }
365820
366821 EXPORT extbbslist_t* extbbslist_new(LINK *db_link, W rectype, UH subtype)
--- bchanl/trunk/src/extbbslist.h (revision 447)
+++ bchanl/trunk/src/extbbslist.h (revision 448)
@@ -25,6 +25,7 @@
2525 */
2626
2727 #include <basic.h>
28+#include <btron/dp.h>
2829
2930 #ifndef __EXTBBSLIST_H__
3031 #define __EXTBBSLIST_H__
@@ -31,6 +32,7 @@
3132
3233 typedef struct extbbslist_t_ extbbslist_t;
3334 typedef struct extbbslist_readcontext_t_ extbbslist_readcontext_t;
35+typedef struct extbbslist_editcontext_t_ extbbslist_editcontext_t;
3436
3537 IMPORT extbbslist_t* extbbslist_new(LINK *db_link, W rectype, UH subtype);
3638 IMPORT VOID extbbslist_delete(extbbslist_t *list);
@@ -44,4 +46,19 @@
4446 IMPORT VOID extbbslist_endread(extbbslist_t *list, extbbslist_readcontext_t *ctx);
4547 IMPORT Bool extbbslist_readcontext_getnext(extbbslist_readcontext_t *ctx, TC **title, W *title_len, UB **url, W *url_len);
4648
49+IMPORT extbbslist_editcontext_t* extbbslist_startedit(extbbslist_t *list);
50+IMPORT VOID extbbslist_endedit(extbbslist_t *list, extbbslist_editcontext_t *ctx, Bool update);
51+IMPORT W extbbslist_editcontext_append(extbbslist_editcontext_t *ctx, CONST TC *title, W title_len, CONST TC *url, W url_len);
52+IMPORT W extbbslist_editcontext_update(extbbslist_editcontext_t *ctx, W i, CONST TC *title, W title_len, CONST TC *url, W url_len);
53+IMPORT W extbbslist_editcontext_draw(extbbslist_editcontext_t *ctx, GID target, RECT *r);
54+IMPORT Bool extbbslist_editcontext_finditem(extbbslist_editcontext_t *ctx, PNT rel_pos, W *index);
55+IMPORT W extbbslist_editcontext_swapitem(extbbslist_editcontext_t *ctx, W i0, W i1);
56+IMPORT W extbbslist_editcontext_deleteitem(extbbslist_editcontext_t *ctx, W i);
57+IMPORT VOID extbbslist_editcontext_setselect(extbbslist_editcontext_t *ctx, W i);
58+IMPORT W extbbslist_editcontext_getselect(extbbslist_editcontext_t *ctx);
59+IMPORT VOID extbbslist_editcontext_setviewrect(extbbslist_editcontext_t *ctx, W l, W t, W r, W b);
60+IMPORT VOID extbbslist_editcontext_getviewrect(extbbslist_editcontext_t *ctx, W *l, W *t, W *r, W *b);
61+IMPORT VOID extbbslist_editcontext_scrollviewrect(extbbslist_editcontext_t *ctx, W dh, W dv);
62+IMPORT VOID extbbslist_editcontext_getdrawrect(extbbslist_editcontext_t *ctx, W *l, W *t, W *r, W *b);
63+
4764 #endif
Show on old repository browser