• R/O
  • SSH
  • HTTPS

bchan: 提交


Commit MetaInfo

修訂646 (tree)
時間2014-11-29 00:14:12
作者ornse01

Log Message

refactoring. add model and view implementation.

Change Summary

差異

--- bchank/trunk/src/bchank_model.c (nonexistent)
+++ bchank/trunk/src/bchank_model.c (revision 646)
@@ -0,0 +1,249 @@
1+/*
2+ * bchank_model.c
3+ *
4+ * Copyright (c) 2014 project bchan
5+ *
6+ * This software is provided 'as-is', without any express or implied
7+ * warranty. In no event will the authors be held liable for any damages
8+ * arising from the use of this software.
9+ *
10+ * Permission is granted to anyone to use this software for any purpose,
11+ * including commercial applications, and to alter it and redistribute it
12+ * freely, subject to the following restrictions:
13+ *
14+ * 1. The origin of this software must not be misrepresented; you must not
15+ * claim that you wrote the original software. If you use this software
16+ * in a product, an acknowledgment in the product documentation would be
17+ * appreciated but is not required.
18+ *
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ *
22+ * 3. This notice may not be removed or altered from any source
23+ * distribution.
24+ *
25+ */
26+
27+#include "bchank_model.h"
28+
29+#include <basic.h>
30+#include <bstdlib.h>
31+#include <bstdio.h>
32+#include <tcode.h>
33+#include <btron/hmi.h>
34+#include <bsys/queue.h>
35+
36+#include <tad/taditerator.h>
37+#include <tad/taddecoder.h>
38+#include <hmi/texteditor_textfragment.h>
39+
40+struct bchank_modelline_t_ {
41+ QUEUE que;
42+ texteditor_textfragment_t fragment;
43+ W width;
44+ W *pos;
45+ W pos_len;
46+};
47+
48+LOCAL VOID bchank_modelline_insert(bchank_modelline_t *line, bchank_modelline_t *next)
49+{
50+ QueInsert(&line->que, &next->que);
51+}
52+
53+LOCAL bchank_modelline_t* bchank_modelline_getnext(bchank_modelline_t *line)
54+{
55+ return (bchank_modelline_t*)line->que.next;
56+}
57+
58+EXPORT W bchank_modelline_appendtext(bchank_modelline_t *line, TC *str, W len)
59+{
60+ W last = texteditor_textfragment_getcharlength(&line->fragment);
61+ return bchank_modelline_inserttext(line, last, str, len);
62+}
63+
64+EXPORT W bchank_modelline_inserttext(bchank_modelline_t *line, W pos, TC *str, W len)
65+{
66+ texteditor_insertcontext_t context;
67+ taddecoder_t decoder;
68+ tadsegment segment;
69+ Bool cont;
70+ W err;
71+
72+ err = texteditor_insertcontext_initialize(&context, &line->fragment, -1, pos);
73+ if (err < 0) {
74+ return err;
75+ }
76+
77+ taddecoder_initialize(&decoder, str, len);
78+
79+ for (;;) {
80+ cont = taddecoder_next(&decoder, &segment);
81+ if (cont == False) {
82+ break;
83+ }
84+
85+ err = texteditor_insertcontext_insert(&context, &segment);
86+ if (err < 0) {
87+ break;
88+ }
89+ }
90+
91+ taddecoder_finalize(&decoder);
92+
93+ return texteditor_insertcontext_finalize(&context);
94+}
95+
96+EXPORT W bchank_modelline_removetext(bchank_modelline_t *line, W pos, W len)
97+{
98+}
99+
100+EXPORT W bchank_modelline_getX(bchank_modelline_t *line, W pos)
101+{
102+ if (pos > line->pos_len) {
103+ return -1;
104+ }
105+ if (pos == line->pos_len) {
106+ return line->width;
107+ }
108+ return line->pos[pos];
109+}
110+
111+EXPORT W bchank_modelline_length(bchank_modelline_t *line)
112+{
113+ return line->pos_len;
114+}
115+
116+EXPORT texteditor_textfragment_t* bchank_modelline_gettext(bchank_modelline_t *line)
117+{
118+ return &line->fragment;
119+}
120+
121+EXPORT bchank_modelline_t* bchank_modelline_new()
122+{
123+ bchank_modelline_t *line;
124+ W err;
125+
126+ line = (bchank_modelline_t*)malloc(sizeof(bchank_modelline_t));
127+ if (line == NULL) {
128+ return NULL;
129+ }
130+ err = texteditor_textfragment_initialize(&line->fragment);
131+ if (err < 0) {
132+ free(line);
133+ return NULL;
134+ }
135+ QueInit(&line->que);
136+ line->width = 0;
137+ line->pos = NULL;
138+ line->pos_len = 0;
139+
140+ return line;
141+}
142+
143+EXPORT VOID bchank_modelline_delete(bchank_modelline_t *line)
144+{
145+ QueRemove(&line->que);
146+ texteditor_textfragment_finalize(&line->fragment);
147+ if (line->pos != NULL) {
148+ free(line->pos);
149+ }
150+ free(line);
151+}
152+
153+struct bchank_model_t_ {
154+ QUEUE sentinel;
155+ W len;
156+};
157+
158+LOCAL bchank_modelline_t* bchank_model_getsentinel(bchank_model_t *list)
159+{
160+ return (bchank_modelline_t*)&list->sentinel;
161+}
162+
163+EXPORT bchank_modelline_t* bchank_model_get(bchank_model_t *list, W at)
164+{
165+ bchank_modelline_t *sentinel, *node;
166+ W i;
167+
168+ if (list->len == 0) {
169+ return NULL;
170+ }
171+ if (list->len <= at) {
172+ return NULL;
173+ }
174+
175+ sentinel = bchank_model_getsentinel(list);
176+ node = bchank_modelline_getnext(sentinel);
177+ for (i = 0; i < at; i++) {
178+ node = bchank_modelline_getnext(node);
179+ }
180+
181+ return node;
182+}
183+
184+EXPORT W bchank_model_insert(bchank_model_t *list, W at, bchank_modelline_t *line_new)
185+{
186+ bchank_modelline_t *line;
187+
188+ if (at != list->len) {
189+ line = bchank_model_get(list, at);
190+ if (line == NULL) {
191+ return -1; /* TODO */
192+ }
193+ } else {
194+ line = bchank_model_getsentinel(list);
195+ }
196+
197+ bchank_modelline_insert(line_new, line);
198+ list->len++;
199+
200+ return 0;
201+}
202+
203+EXPORT W bchank_model_append(bchank_model_t *list, bchank_modelline_t *line)
204+{
205+ return bchank_model_insert(list, list->len, line);
206+}
207+
208+EXPORT W bchank_model_length(bchank_model_t *list)
209+{
210+ return list->len;
211+}
212+
213+LOCAL VOID bchank_model_initialize(bchank_model_t *list)
214+{
215+ QueInit(&list->sentinel);
216+ list->len = 0;
217+}
218+
219+LOCAL VOID bchank_model_finalize(bchank_model_t *list)
220+{
221+ bchank_modelline_t *sentinel, *node;
222+ sentinel = bchank_model_getsentinel(list);
223+ for (;;) {
224+ node = bchank_modelline_getnext(sentinel);
225+ if (node == sentinel) {
226+ break;
227+ }
228+ bchank_modelline_delete(node);
229+ }
230+}
231+
232+EXPORT bchank_model_t* bchank_model_new()
233+{
234+ bchank_model_t *list;
235+
236+ list = (bchank_model_t*)malloc(sizeof(bchank_model_t));
237+ if (list == NULL) {
238+ return NULL;
239+ }
240+ bchank_model_initialize(list);
241+
242+ return list;
243+}
244+
245+EXPORT VOID bchank_model_delete(bchank_model_t *list)
246+{
247+ bchank_model_finalize(list);
248+ free(list);
249+}
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
--- bchank/trunk/src/bchank_model.h (nonexistent)
+++ bchank/trunk/src/bchank_model.h (revision 646)
@@ -0,0 +1,54 @@
1+/*
2+ * bchank_model.h
3+ *
4+ * Copyright (c) 2014 project bchan
5+ *
6+ * This software is provided 'as-is', without any express or implied
7+ * warranty. In no event will the authors be held liable for any damages
8+ * arising from the use of this software.
9+ *
10+ * Permission is granted to anyone to use this software for any purpose,
11+ * including commercial applications, and to alter it and redistribute it
12+ * freely, subject to the following restrictions:
13+ *
14+ * 1. The origin of this software must not be misrepresented; you must not
15+ * claim that you wrote the original software. If you use this software
16+ * in a product, an acknowledgment in the product documentation would be
17+ * appreciated but is not required.
18+ *
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ *
22+ * 3. This notice may not be removed or altered from any source
23+ * distribution.
24+ *
25+ */
26+
27+#include <basic.h>
28+
29+#include <hmi/texteditor_textfragment.h>
30+
31+#ifndef __BCHANK_MODEL_H__
32+#define __BCHANK_MODEL_H__
33+
34+typedef struct bchank_modelline_t_ bchank_modelline_t;
35+
36+IMPORT bchank_modelline_t* bchank_modelline_new();
37+IMPORT VOID bchank_modelline_delete(bchank_modelline_t *line);
38+IMPORT W bchank_modelline_appendtext(bchank_modelline_t *line, TC *str, W len);
39+IMPORT W bchank_modelline_inserttext(bchank_modelline_t *line, W pos, TC *str, W len);
40+IMPORT W bchank_modelline_removetext(bchank_modelline_t *line, W pos, W len);
41+IMPORT W bchank_modelline_getX(bchank_modelline_t *line, W pos);
42+IMPORT W bchank_modelline_length(bchank_modelline_t *line);
43+IMPORT texteditor_textfragment_t* bchank_modelline_gettext(bchank_modelline_t *line);
44+
45+typedef struct bchank_model_t_ bchank_model_t;
46+
47+IMPORT bchank_model_t* bchank_model_new();
48+IMPORT VOID bchank_model_delete(bchank_model_t *model);
49+IMPORT bchank_modelline_t* bchank_model_get(bchank_model_t *model, W at);
50+IMPORT W bchank_model_insert(bchank_model_t *model, W at, bchank_modelline_t *line);
51+IMPORT W bchank_model_append(bchank_model_t *model, bchank_modelline_t *line);
52+IMPORT W bchank_model_length(bchank_model_t *model);
53+
54+#endif
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
--- bchank/trunk/src/bchank_view.c (nonexistent)
+++ bchank/trunk/src/bchank_view.c (revision 646)
@@ -0,0 +1,562 @@
1+/*
2+ * bchank_view.c
3+ *
4+ * Copyright (c) 2014 project bchan
5+ *
6+ * This software is provided 'as-is', without any express or implied
7+ * warranty. In no event will the authors be held liable for any damages
8+ * arising from the use of this software.
9+ *
10+ * Permission is granted to anyone to use this software for any purpose,
11+ * including commercial applications, and to alter it and redistribute it
12+ * freely, subject to the following restrictions:
13+ *
14+ * 1. The origin of this software must not be misrepresented; you must not
15+ * claim that you wrote the original software. If you use this software
16+ * in a product, an acknowledgment in the product documentation would be
17+ * appreciated but is not required.
18+ *
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ *
22+ * 3. This notice may not be removed or altered from any source
23+ * distribution.
24+ *
25+ */
26+
27+#include <basic.h>
28+#include <bstdlib.h>
29+#include <bstdio.h>
30+#include <tcode.h>
31+#include <btron/dp.h>
32+
33+#include "bchank_view.h"
34+#include "bchank_tadutil.h"
35+
36+#include <tad/taditerator.h>
37+#include <css/cssrendering_box.h>
38+#include <css/cssrendering_coordinate.h>
39+#include <hmi/texteditor_textfragment.h>
40+
41+struct bchank_font_t_ {
42+ FSSPEC spec;
43+ FNTINFO info;
44+};
45+typedef struct bchank_font_t_ bchank_font_t;
46+
47+struct bchank_viewconfig_t_ {
48+ struct {
49+ bchank_font_t zen;
50+ bchank_font_t han;
51+ } fonts;
52+ struct {
53+ PAT underline;
54+ } patterns;
55+};
56+typedef struct bchank_viewconfig_t_ bchank_viewconfig_t;
57+
58+LOCAL W bchank_viewconfig_setdefault(bchank_viewconfig_t *genv, GID target)
59+{
60+ FSSPEC spec;
61+ W err;
62+
63+ err = gget_fon(target, &spec, NULL);
64+ if (err < 0) {
65+ return err;
66+ }
67+
68+ spec.attr |= FT_PROP;
69+ spec.attr |= FT_GRAYSCALE;
70+ spec.fclass = 0x000000c0;
71+ spec.size.h = 16;
72+ spec.size.v = 16;
73+
74+ err = gset_fon(target, &spec);
75+ if (err < 0) {
76+ return err;
77+ }
78+
79+ err = gget_fon(target, &genv->fonts.zen.spec, &genv->fonts.zen.info);
80+ if (err < 0) {
81+ return err;
82+ }
83+
84+ genv->fonts.han = genv->fonts.zen;
85+ genv->fonts.han.spec.size.h = 8;
86+
87+ genv->patterns.underline.spat.kind = 0;
88+ genv->patterns.underline.spat.hsize = 16;
89+ genv->patterns.underline.spat.vsize = 16;
90+ genv->patterns.underline.spat.fgcol = 0x1099CCFF;
91+ genv->patterns.underline.spat.bgcol = 0x10000000;
92+ genv->patterns.underline.spat.mask = FILL100;
93+
94+ return 0;
95+}
96+
97+LOCAL W bchank_viewconfig_resetfont(bchank_viewconfig_t *genv, GID target, FSSPEC *result)
98+{
99+ if (result != NULL) {
100+ *result = genv->fonts.zen.spec;
101+ }
102+
103+ return gset_fon(target, &genv->fonts.zen.spec);
104+}
105+
106+LOCAL W bchank_viewconfig_sethankaku(bchank_viewconfig_t *genv, GID target)
107+{
108+ return gset_fon(target, &genv->fonts.han.spec);
109+}
110+
111+LOCAL W bchank_viewconfig_setzenkaku(bchank_viewconfig_t *genv, GID target)
112+{
113+ return gset_fon(target, &genv->fonts.zen.spec);
114+}
115+
116+LOCAL PAT* bchank_viewconfig_getunderlinePAT(bchank_viewconfig_t *genv)
117+{
118+ return &genv->patterns.underline;
119+}
120+
121+LOCAL W bchank_viewconfig_initialize(bchank_viewconfig_t *genv, GID target)
122+{
123+ return bchank_viewconfig_setdefault(genv, target);
124+}
125+
126+LOCAL VOID bchank_viewconfig_finalize(bchank_viewconfig_t *genv)
127+{
128+}
129+
130+struct bchank_viewline_t_ {
131+ cssrendering_linebox_t base;
132+ texteditor_textfragment_t *fragment;
133+ W *pos;
134+ W pos_len;
135+};
136+
137+EXPORT bchank_viewline_t* bchank_viewline_nextsibling(bchank_viewline_t *line)
138+{
139+ return (bchank_viewline_t*)cssrendering_linebox_getnextsibling(&line->base);
140+}
141+
142+EXPORT W bchank_viewline_getleft(bchank_viewline_t *line)
143+{
144+ return line->base.base.content_edge.c.left;
145+}
146+
147+EXPORT W bchank_viewline_gettop(bchank_viewline_t *line)
148+{
149+ return line->base.base.content_edge.c.top;
150+}
151+
152+EXPORT W bchank_viewline_getright(bchank_viewline_t *line)
153+{
154+ return line->base.base.content_edge.c.right;
155+}
156+
157+EXPORT W bchank_viewline_getbottom(bchank_viewline_t *line)
158+{
159+ return line->base.base.content_edge.c.bottom;
160+}
161+
162+EXPORT VOID bchank_viewline_setleft(bchank_viewline_t *line, W left)
163+{
164+ line->base.base.content_edge.c.left = left;
165+}
166+
167+EXPORT VOID bchank_viewline_settop(bchank_viewline_t *line, W top)
168+{
169+ line->base.base.content_edge.c.top = top;
170+}
171+
172+EXPORT VOID bchank_viewline_setright(bchank_viewline_t *line, W right)
173+{
174+ line->base.base.content_edge.c.right = right;
175+}
176+
177+EXPORT VOID bchank_viewline_setbottom(bchank_viewline_t *line, W bottom)
178+{
179+ line->base.base.content_edge.c.bottom = bottom;
180+}
181+
182+EXPORT VOID bchank_viewline_settext(bchank_viewline_t *line, texteditor_textfragment_t *fragment)
183+{
184+ line->fragment = fragment;
185+}
186+
187+EXPORT bchank_viewline_t* bchank_viewline_new()
188+{
189+ bchank_viewline_t *line;
190+
191+ line = (bchank_viewline_t*)malloc(sizeof(bchank_viewline_t));
192+ if (line == NULL) {
193+ return NULL;
194+ }
195+ cssrendering_linebox_initialize(&line->base);
196+ cssrendering_linebox_setuserdata(&line->base, (VP)line);
197+ line->fragment = NULL;
198+ line->pos = NULL;
199+ line->pos_len = 0;
200+
201+ return line;
202+}
203+
204+EXPORT VOID bchank_viewline_delete(bchank_viewline_t *line)
205+{
206+ cssrendering_linebox_finalize(&line->base);
207+ free(line);
208+}
209+
210+struct bchank_view_t_ {
211+ cssrendering_blockbox_t root;
212+ cssrendering_blockbox_t line_container;
213+ cssrendering_anonymousbox_t line_container_anon;
214+ cssrendering_coordinate_t scroll;
215+ bchank_viewconfig_t config;
216+ GID target;
217+};
218+
219+LOCAL W bchank_view_drawline(bchank_view_t *view, bchank_viewline_t *line, GID target)
220+{
221+ taditerator_t iterator;
222+ taditerator_result result;
223+ TC *start = NULL;
224+ W len = 0, bin_len;
225+ TC *bin;
226+ BCHANK_SEGMENTTYPE_RESULT segcheck;
227+
228+ if (line->fragment == NULL) {
229+ return 0;
230+ }
231+
232+ bin = (TC*)texteditor_textfragment_getbuffer(line->fragment);
233+ bin_len = texteditor_textfragment_getbufferlength(line->fragment) / sizeof(TC);
234+
235+ taditerator_initialize(&iterator, bin, bin_len);
236+ for (;;) {
237+ taditerator_next2(&iterator, &result);
238+ if (result.type == TADITERATOR_RESULTTYPE_END) {
239+ if (start != NULL) {
240+ gdra_str(target, start, len, G_STORE);
241+ start = NULL;
242+ len = 0;
243+ }
244+ break;
245+ } else if (result.type == TADITERATOR_RESULTTYPE_CHARCTOR) {
246+ if (start == NULL) {
247+ start = result.pos;
248+ }
249+ len++;
250+ } else if (result.type == TADITERATOR_RESULTTYPE_SEGMENT) {
251+ if (start != NULL) {
252+ gdra_str (target, start, len, G_STORE);
253+ start = NULL;
254+ len = 0;
255+ }
256+
257+ segcheck = bchank_tadutil_segmenttype(result.segment, result.segsize, result.data);
258+ if (segcheck == BCHANK_SEGMENTTYPE_RESULT_HANKAKU) {
259+ bchank_viewconfig_sethankaku(&view->config, target);
260+ } else if (segcheck == BCHANK_SEGMENTTYPE_RESULT_ZENKAKU) {
261+ bchank_viewconfig_setzenkaku(&view->config, target);
262+ }
263+ }
264+ }
265+ taditerator_finalize(&iterator);
266+
267+ return 0;
268+}
269+
270+LOCAL W bchank_view_drawunderline(bchank_view_t *view, bchank_viewline_t *line, W x, W y, GID target)
271+{
272+ taditerator_t iterator;
273+ taditerator_result result;
274+ bchank_tadstate_t state;
275+ W len = 0, bin_len, x2;
276+ TC *bin;
277+ Bool hankaku;
278+ PNT p1, p2;
279+ PAT *pat = bchank_viewconfig_getunderlinePAT(&view->config);
280+
281+ if (line->fragment == NULL) {
282+ return 0;
283+ }
284+
285+ bin = (TC*)texteditor_textfragment_getbuffer(line->fragment);
286+ bin_len = texteditor_textfragment_getbufferlength(line->fragment) / sizeof(TC);
287+
288+ taditerator_initialize(&iterator, bin, bin_len);
289+ bchank_tadstate_initialize(&state);
290+ for (;;) {
291+ taditerator_next2(&iterator, &result);
292+ if (result.type == TADITERATOR_RESULTTYPE_CHARCTOR) {
293+ bchank_tadstate_inputcharactor(&state, result.segment);
294+ } else if (result.type == TADITERATOR_RESULTTYPE_SEGMENT) {
295+ bchank_tadstate_inputvsegment(&state, result.segment, result.data, result.segsize);
296+ }
297+
298+ if (result.type == TADITERATOR_RESULTTYPE_END) {
299+ break;
300+ } else if (result.type == TADITERATOR_RESULTTYPE_CHARCTOR) {
301+ if (result.segment == TK_KSP && len < line->pos_len) {
302+ hankaku = bchank_tadstate_ishankaku(&state);
303+ if (hankaku != False) {
304+ x2 = 5;
305+ } else {
306+ x2 = 11;
307+ }
308+ p1.x = x + line->pos[len];
309+ p1.y = y;
310+ p2.x = p1.x + x2 - 2;
311+ p2.y = y;
312+ gdra_lin(target, p1, p2, 1, pat, G_STORE);
313+ }
314+ len++;
315+ }
316+ }
317+ bchank_tadstate_finalize(&state);
318+ taditerator_finalize(&iterator);
319+
320+ return 0;
321+}
322+
323+EXPORT VOID bchank_view_scroll(bchank_view_t *view, W dh, W dv)
324+{
325+ cssrendering_coordinate_scrollviewrect(&view->scroll, dh, dv);
326+}
327+
328+EXPORT VOID bchank_view_getviewrect(bchank_view_t *view, W *l, W *t, W *r, W *b)
329+{
330+ cssrendering_coordinate_getviewrect(&view->scroll, l, t, r, b);
331+}
332+
333+EXPORT VOID bchank_view_setviewrect(bchank_view_t *view, W l, W t, W r, W b)
334+{
335+ cssrendering_coordinate_setviewrect(&view->scroll, l, t, r, b);
336+}
337+
338+EXPORT VOID bchank_view_getdrawrect(bchank_view_t *view, W *l, W *t, W *r, W *b)
339+{
340+ cssrendering_coordinate_getdrawrect(&view->scroll, l, t, r, b);
341+}
342+
343+EXPORT W bchank_view_render(bchank_view_t *view, GID target, RECT r)
344+{
345+ cssrendering_drawtraversal_t traversal;
346+ cssrendering_drawtraversal_result result;
347+ cssmetric_rectangle_t cr;
348+ Bool cont;
349+ W x, y;
350+ bchank_viewline_t *line;
351+
352+ bchank_viewconfig_resetfont(&view->config, target, NULL);
353+
354+ cr.c.left = r.c.left;
355+ cr.c.top = r.c.top;
356+ cr.c.right = r.c.right;
357+ cr.c.bottom = r.c.bottom;
358+ cssrendering_coordinate_getabsoluterect(&view->scroll, r, &cr);
359+ printf("cr: %d %d %d %d\n", cr.c.left, cr.c.top, cr.c.right, cr.c.bottom);
360+ cssrendering_drawtraversal_initialize(&traversal, &view->root, cr);
361+ for (;;) {
362+ cont = cssrendering_drawtraversal_next(&traversal, &result);
363+ if (cont == False) {
364+ break;
365+ }
366+ if (result.type == CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_TEXT) {
367+ line = (bchank_viewline_t *)(result.data.text.nodedata);
368+
369+ cssrendering_coordinate_getrelativepoint(&view->scroll, result.data.text.content_edge.c.left, result.data.text.content_edge.c.top + 16/*TODO*/, &x, &y);
370+ gset_chp(target, x, y, True);
371+ bchank_viewconfig_resetfont(&view->config, target, NULL);
372+ bchank_view_drawline(view, line, target);
373+ bchank_view_drawunderline(view, line, x, y, target);
374+ }
375+ }
376+ cssrendering_drawtraversal_finalize(&traversal);
377+
378+ return 0;
379+}
380+
381+EXPORT VOID bchank_view_appendchild(bchank_view_t *view, bchank_viewline_t *line)
382+{
383+ cssrendering_anonymousbox_appendchild(&view->line_container_anon, &line->base);
384+}
385+
386+EXPORT W bchank_view_insertbefore(bchank_view_t *view, bchank_viewline_t *new_line, bchank_viewline_t *ref_line)
387+{
388+ return cssrendering_anonymousbox_insertbefore(&view->line_container_anon, &new_line->base, (ref_line != NULL) ? &ref_line->base : NULL);
389+}
390+
391+EXPORT W bchank_view_removechild(bchank_view_t *view, bchank_viewline_t *line)
392+{
393+ return cssrendering_anonymousbox_removechild(&view->line_container_anon, &line->base);
394+}
395+
396+EXPORT bchank_viewline_t* bchank_view_firstchild(bchank_view_t *view)
397+{
398+ return (bchank_viewline_t*)cssrendering_anonymousbox_getfirstchild(&view->line_container_anon);
399+}
400+
401+EXPORT VOID bchank_view_seteditsize(bchank_view_t *view, W width, W height)
402+{
403+ view->root.base.content_edge.c.left = 0;
404+ view->root.base.content_edge.c.top = 0;
405+ view->root.base.content_edge.c.right = width;
406+ view->root.base.content_edge.c.bottom = height;
407+ view->line_container.base.content_edge.c.left = 0;
408+ view->line_container.base.content_edge.c.top = 0;
409+ view->line_container.base.content_edge.c.right = width;
410+ view->line_container.base.content_edge.c.bottom = height;
411+ view->line_container_anon.base.content_edge.c.left = 0;
412+ view->line_container_anon.base.content_edge.c.top = 0;
413+ view->line_container_anon.base.content_edge.c.right = width;
414+ view->line_container_anon.base.content_edge.c.bottom = height;
415+
416+ cssrendering_coordinate_setdrawrect(&view->scroll, view->root.base.content_edge);
417+}
418+
419+LOCAL W bchank_linelist_calclinewidth_stw(bchank_viewline_t *line, GID target, W prev_x, TC *str, W str_len)
420+{
421+ W *new_pos;
422+ W i, err;
423+
424+ new_pos = realloc(line->pos, (line->pos_len + str_len)*sizeof(W));
425+ if (new_pos == NULL) {
426+ return -1;
427+ }
428+ line->pos = new_pos;
429+
430+ err = gget_stw(target, str, str_len, NULL, new_pos + line->pos_len);
431+ if (err < 0) {
432+ return -1;
433+ }
434+
435+ for (i = 0; i < str_len; i++) {
436+ new_pos[line->pos_len + i] += prev_x;
437+ }
438+ line->pos_len += str_len;
439+
440+ return err;
441+}
442+
443+EXPORT W bchank_view_calctextwidth(bchank_view_t *view, bchank_viewline_t *line)
444+{
445+ taditerator_t iterator;
446+ taditerator_result result;
447+ TC *start = NULL;
448+ W len = 0, w = 0, bin_len;
449+ TC *bin;
450+ BCHANK_SEGMENTTYPE_RESULT segcheck;
451+
452+ if (line->fragment == NULL) {
453+ return 0;
454+ }
455+
456+ bchank_viewconfig_resetfont(&view->config, view->target, NULL);
457+
458+ bin = (TC*)texteditor_textfragment_getbuffer(line->fragment);
459+ bin_len = texteditor_textfragment_getbufferlength(line->fragment) / sizeof(TC);
460+
461+ taditerator_initialize(&iterator, bin, bin_len);
462+ for (;;) {
463+ taditerator_next2(&iterator, &result);
464+ if (result.type == TADITERATOR_RESULTTYPE_END) {
465+ if (start != NULL) {
466+ w += bchank_linelist_calclinewidth_stw(line, view->target, w, start, len);
467+ start = NULL;
468+ len = 0;
469+ }
470+ break;
471+ } else if (result.type == TADITERATOR_RESULTTYPE_CHARCTOR) {
472+ if (start == NULL) {
473+ start = result.pos;
474+ }
475+ len++;
476+ } else if (result.type == TADITERATOR_RESULTTYPE_SEGMENT) {
477+ if (start != NULL) {
478+ w += bchank_linelist_calclinewidth_stw(line, view->target, w, start, len);
479+ start = NULL;
480+ len = 0;
481+ }
482+
483+ segcheck = bchank_tadutil_segmenttype(result.segment, result.segsize, result.data);
484+ if (segcheck == BCHANK_SEGMENTTYPE_RESULT_HANKAKU) {
485+ bchank_viewconfig_sethankaku(&view->config, view->target);
486+ } else if (segcheck == BCHANK_SEGMENTTYPE_RESULT_ZENKAKU) {
487+ bchank_viewconfig_setzenkaku(&view->config, view->target);
488+ }
489+ }
490+ }
491+ taditerator_finalize(&iterator);
492+
493+ return w;
494+}
495+
496+LOCAL W bchank_view_initialize(bchank_view_t *view, GID target)
497+{
498+ W err;
499+
500+ cssrendering_blockbox_initialize(&view->root);
501+ cssrendering_blockbox_initialize(&view->line_container);
502+ cssrendering_anonymousbox_initialize(&view->line_container_anon);
503+ cssrendering_coordinate_initialize(&view->scroll);
504+
505+ cssrendering_blockbox_appendblockchild(&view->root, &view->line_container);
506+ cssrendering_blockbox_appendanonymouschild(&view->line_container, &view->line_container_anon);
507+
508+ err = bchank_viewconfig_initialize(&view->config, target);
509+ if (err < 0) {
510+ goto error_config;
511+ }
512+
513+ view->target = target;
514+
515+ return 0;
516+
517+error_config:
518+ cssrendering_coordinate_finalize(&view->scroll);
519+ cssrendering_anonymousbox_finalize(&view->line_container_anon);
520+ cssrendering_blockbox_finalize(&view->line_container);
521+ cssrendering_blockbox_finalize(&view->root);
522+
523+ return err;
524+}
525+
526+LOCAL VOID bchank_view_finalize(bchank_view_t *view)
527+{
528+ bchank_viewline_t *line;
529+
530+ for (;;) {
531+ line = bchank_view_firstchild(view);
532+ if (line == NULL) {
533+ break;
534+ }
535+ bchank_view_removechild(view, line);
536+ bchank_viewline_delete(line);
537+ }
538+
539+ bchank_viewconfig_finalize(&view->config);
540+ cssrendering_coordinate_finalize(&view->scroll);
541+ cssrendering_anonymousbox_finalize(&view->line_container_anon);
542+ cssrendering_blockbox_finalize(&view->line_container);
543+ cssrendering_blockbox_finalize(&view->root);
544+}
545+
546+EXPORT bchank_view_t* bchank_view_new(GID target)
547+{
548+ bchank_view_t *view;
549+
550+ view = (bchank_view_t*)malloc(sizeof(bchank_view_t));
551+ if (view == NULL) {
552+ return NULL;
553+ }
554+ bchank_view_initialize(view, target);
555+ return view;
556+}
557+
558+EXPORT VOID bchank_view_delete(bchank_view_t *view)
559+{
560+ bchank_view_finalize(view);
561+ free(view);
562+}
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
--- bchank/trunk/src/bchank_view.h (nonexistent)
+++ bchank/trunk/src/bchank_view.h (revision 646)
@@ -0,0 +1,66 @@
1+/*
2+ * bchank_view.c
3+ *
4+ * Copyright (c) 2014 project bchan
5+ *
6+ * This software is provided 'as-is', without any express or implied
7+ * warranty. In no event will the authors be held liable for any damages
8+ * arising from the use of this software.
9+ *
10+ * Permission is granted to anyone to use this software for any purpose,
11+ * including commercial applications, and to alter it and redistribute it
12+ * freely, subject to the following restrictions:
13+ *
14+ * 1. The origin of this software must not be misrepresented; you must not
15+ * claim that you wrote the original software. If you use this software
16+ * in a product, an acknowledgment in the product documentation would be
17+ * appreciated but is not required.
18+ *
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ *
22+ * 3. This notice may not be removed or altered from any source
23+ * distribution.
24+ *
25+ */
26+
27+#include <basic.h>
28+#include <btron/dp.h>
29+
30+#include <hmi/texteditor_textfragment.h>
31+
32+#ifndef __BCHANK_VIEW_H__
33+#define __BCHANK_VIEW_H__
34+
35+typedef struct bchank_viewline_t_ bchank_viewline_t;
36+
37+IMPORT bchank_viewline_t* bchank_viewline_new();
38+IMPORT VOID bchank_viewline_delete(bchank_viewline_t *line);
39+IMPORT bchank_viewline_t* bchank_viewline_nextsibling(bchank_viewline_t *line);
40+IMPORT W bchank_viewline_getleft(bchank_viewline_t *line);
41+IMPORT W bchank_viewline_gettop(bchank_viewline_t *line);
42+IMPORT W bchank_viewline_getright(bchank_viewline_t *line);
43+IMPORT W bchank_viewline_getbottom(bchank_viewline_t *line);
44+IMPORT VOID bchank_viewline_setleft(bchank_viewline_t *line, W left);
45+IMPORT VOID bchank_viewline_settop(bchank_viewline_t *line, W top);
46+IMPORT VOID bchank_viewline_setright(bchank_viewline_t *line, W right);
47+IMPORT VOID bchank_viewline_setbottom(bchank_viewline_t *line, W bottom);
48+IMPORT VOID bchank_viewline_settext(bchank_viewline_t *line, texteditor_textfragment_t *fragment);
49+
50+typedef struct bchank_view_t_ bchank_view_t;
51+
52+IMPORT bchank_view_t* bchank_view_new(GID target);
53+IMPORT VOID bchank_view_delete(bchank_view_t *view);
54+IMPORT VOID bchank_view_scroll(bchank_view_t *view, W dh, W dv);
55+IMPORT W bchank_view_render(bchank_view_t *view, GID target, RECT r);
56+IMPORT VOID bchank_view_getviewrect(bchank_view_t *view, W *l, W *t, W *r, W *b);
57+IMPORT VOID bchank_view_setviewrect(bchank_view_t *view, W l, W t, W r, W b);
58+IMPORT VOID bchank_view_getdrawrect(bchank_view_t *view, W *l, W *t, W *r, W *b);
59+IMPORT VOID bchank_view_appendchild(bchank_view_t *view, bchank_viewline_t *line);
60+IMPORT W bchank_view_insertbefore(bchank_view_t *view, bchank_viewline_t *new_line, bchank_viewline_t *ref_line);
61+IMPORT W bchank_view_removechild(bchank_view_t *view, bchank_viewline_t *line);
62+IMPORT bchank_viewline_t* bchank_view_firstchild(bchank_view_t *view);
63+IMPORT VOID bchank_view_seteditsize(bchank_view_t *view, W w, W h);
64+IMPORT W bchank_view_calctextwidth(bchank_view_t *view, bchank_viewline_t *line);
65+
66+#endif
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Show on old repository browser