htmlgrid 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +8 -1
- data/Manifest.txt +1 -1
- data/lib/htmlgrid/component.rb +3 -11
- data/lib/htmlgrid/composite.rb +5 -5
- data/lib/htmlgrid/divcomposite.rb +1 -1
- data/lib/htmlgrid/dojotoolkit.rb +2 -6
- data/lib/htmlgrid/form.rb +1 -5
- data/lib/htmlgrid/grid.rb +9 -8
- data/lib/htmlgrid/link.rb +1 -1
- data/lib/htmlgrid/richtext.rb +1 -1
- data/lib/htmlgrid/spancomposite.rb +1 -1
- data/lib/htmlgrid/template.rb +1 -0
- data/lib/htmlgrid/ulcomposite.rb +1 -1
- data/lib/htmlgrid/version.rb +5 -0
- data/test/rebuild.rb +0 -0
- data/{ext/htmlgrid/extconf.rb → test/suite.rb} +10 -11
- data/test/test_add_row.rb +75 -0
- data/test/test_component.rb +7 -17
- data/test/test_composite.rb +33 -20
- data/test/test_datevalue.rb +2 -2
- data/test/test_form.rb +16 -15
- data/test/test_formlist.rb +11 -10
- data/test/test_grid.rb +10 -22
- data/test/test_input.rb +8 -7
- data/test/test_interaction_list.rb +257 -0
- data/test/test_label.rb +5 -14
- data/test/test_list.rb +3 -5
- data/test/test_select.rb +15 -8
- data/test/test_template.rb +15 -15
- data/test/test_text.rb +2 -2
- metadata +117 -74
- data/.gemtest +0 -0
- data/.gitignore +0 -3
- data/.travis.yml +0 -28
- data/COPYING +0 -515
- data/Gemfile +0 -20
- data/Gemfile.lock +0 -50
- data/README.txt +0 -31
- data/Rakefile +0 -52
- data/ext/htmlgrid/MANIFEST +0 -3
- data/ext/htmlgrid/grid.c +0 -899
- data/ext/htmlgrid/htmlgrid.c +0 -30
- data/ext/htmlgrid/include/grid.h +0 -79
- data/ext/htmlgrid/include/htmlgrid.h +0 -33
- data/htmlgrid.gemspec +0 -16
- data/install.rb +0 -1098
- data/usage-en.txt +0 -112
- data/widget/Tooltip.js +0 -85
data/ext/htmlgrid/grid.c
DELETED
@@ -1,899 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* HtmlGrid -- HyperTextMarkupLanguage Framework
|
3
|
-
* Copyright (C) 2003 ywesee - intellectual capital connected
|
4
|
-
* Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
|
5
|
-
*
|
6
|
-
* This library is free software; you can redistribute it and/or
|
7
|
-
* modify it under the terms of the GNU Lesser General Public
|
8
|
-
* License as published by the Free Software Foundation; either
|
9
|
-
* version 2.1 of the License, or (at your option) any later version.
|
10
|
-
*
|
11
|
-
* This library is distributed in the hope that it will be useful,
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
-
* Lesser General Public License for more details.
|
15
|
-
*
|
16
|
-
* You should have received a copy of the GNU Lesser General Public
|
17
|
-
* License along with this library; if not, write to the Free Software
|
18
|
-
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
-
*
|
20
|
-
* ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
|
21
|
-
* htmlgrid@ywesee.com, www.ywesee.com
|
22
|
-
*/
|
23
|
-
|
24
|
-
#include "grid.h"
|
25
|
-
#ifdef RUBY_19
|
26
|
-
# include "ruby/st.h"
|
27
|
-
# include "ruby/encoding.h"
|
28
|
-
#else
|
29
|
-
# include "st.h"
|
30
|
-
#endif
|
31
|
-
|
32
|
-
void Init_Grid()
|
33
|
-
{
|
34
|
-
grid = rb_define_class_under(htmlgrid, "Grid", rb_cObject);
|
35
|
-
rb_define_singleton_method(grid, "new", grid_new, -1);
|
36
|
-
rb_define_method(grid, "initialize", grid_initialize, 1);
|
37
|
-
rb_define_method(grid, "height", grid_height, 0);
|
38
|
-
rb_define_method(grid, "width", grid_width, 0);
|
39
|
-
rb_define_method(grid, "to_html", grid_to_html, 1);
|
40
|
-
rb_define_method(grid, "add", grid_add, -1);
|
41
|
-
rb_define_method(grid, "add_column", grid_add_column, 3);
|
42
|
-
rb_define_method(grid, "add_field", grid_add_field, 3);
|
43
|
-
rb_define_method(grid, "add_row", grid_add_row, 3);
|
44
|
-
rb_define_method(grid, "add_attribute", grid_add_attribute, -1);
|
45
|
-
rb_define_method(grid, "set_row_attributes",
|
46
|
-
grid_row_set_attributes, -1);
|
47
|
-
rb_define_method(grid, "add_tag", grid_add_tag, -1);
|
48
|
-
rb_define_method(grid, "add_style", grid_add_style, -1);
|
49
|
-
rb_define_method(grid, "add_component_style",
|
50
|
-
grid_add_component_style, -1);
|
51
|
-
rb_define_method(grid, "push", grid_push, 1);
|
52
|
-
rb_define_method(grid, "set_colspan", grid_set_colspan, -1);
|
53
|
-
rb_define_method(grid, "set_attribute", grid_set_attribute, 2);
|
54
|
-
rb_define_method(grid, "set_attributes", grid_set_attributes, 1);
|
55
|
-
rb_define_method(grid, "insert_row", grid_insert_row, 2);
|
56
|
-
rb_define_method(grid, "field_attribute", grid_field_attribute, 3);
|
57
|
-
}
|
58
|
-
|
59
|
-
long grid_pos(cg, xpos, ypos)
|
60
|
-
cGrid *cg;
|
61
|
-
long xpos, ypos;
|
62
|
-
{
|
63
|
-
return ypos * cg->width + xpos;
|
64
|
-
}
|
65
|
-
|
66
|
-
long grid_coordinate(input, name)
|
67
|
-
VALUE input;
|
68
|
-
const char* name;
|
69
|
-
{
|
70
|
-
long output = NUM2LONG(input);
|
71
|
-
if(output < 0)
|
72
|
-
rb_raise(rb_eArgError, "invalid %s %li", name, output);
|
73
|
-
return output;
|
74
|
-
}
|
75
|
-
|
76
|
-
VALUE rb_hsh_store_pair(pair, hsh)
|
77
|
-
VALUE pair, hsh;
|
78
|
-
{
|
79
|
-
VALUE key, value;
|
80
|
-
key = rb_ary_entry(pair, 0);
|
81
|
-
value = rb_ary_entry(pair, 1);
|
82
|
-
return rb_hash_aset(hsh, key, value);
|
83
|
-
}
|
84
|
-
|
85
|
-
cField * grid_create_field()
|
86
|
-
{
|
87
|
-
cField * cf;
|
88
|
-
cf = ALLOC(cField);
|
89
|
-
cf->attributes = Qnil;
|
90
|
-
cf->colspan = 1;
|
91
|
-
cf->capacity = 1;
|
92
|
-
cf->content = ALLOC_N(VALUE, cf->capacity);
|
93
|
-
cf->content_count = 0;
|
94
|
-
strcpy(cf->tag, "TD");
|
95
|
-
return cf;
|
96
|
-
}
|
97
|
-
|
98
|
-
void grid_set_dimensions(cg, width, height)
|
99
|
-
cGrid *cg;
|
100
|
-
long width, height;
|
101
|
-
{
|
102
|
-
if(cg->width >= width && cg->height >= height) return;
|
103
|
-
|
104
|
-
long stop, fields, idx, xval, yval, mwidth, mheight;
|
105
|
-
|
106
|
-
/* make space for more rows */
|
107
|
-
if(height > cg->height)
|
108
|
-
{
|
109
|
-
if(height > cg->row_capacity)
|
110
|
-
{
|
111
|
-
while(height > cg->row_capacity)
|
112
|
-
cg->row_capacity *= 2;
|
113
|
-
REALLOC_N(cg->row_attributes, VALUE, cg->row_capacity);
|
114
|
-
}
|
115
|
-
for(yval=cg->height; yval < height; yval++)
|
116
|
-
{
|
117
|
-
cg->row_attributes[yval] = Qnil;
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
mheight = (height > cg->height) ? height : cg->height;
|
122
|
-
mwidth = (width > cg->width) ? width : cg->width;
|
123
|
-
|
124
|
-
stop = mwidth * mheight;
|
125
|
-
fields = cg->width * cg->height;
|
126
|
-
cField *tmp[cg->capacity];
|
127
|
-
for(idx=0; idx < fields; idx++)
|
128
|
-
{
|
129
|
-
tmp[idx] = cg->fields[idx];
|
130
|
-
}
|
131
|
-
|
132
|
-
/* sufficient capacity? */
|
133
|
-
if(stop > cg->capacity)
|
134
|
-
{
|
135
|
-
while(stop > cg->capacity)
|
136
|
-
{
|
137
|
-
cg->capacity *= 2;
|
138
|
-
}
|
139
|
-
//printf("reallocating %li fields\n", cg->capacity);
|
140
|
-
REALLOC_N(cg->fields, cField *, cg->capacity);
|
141
|
-
}
|
142
|
-
|
143
|
-
/* has the maximum width changed? */
|
144
|
-
if(mwidth > cg->width)
|
145
|
-
{
|
146
|
-
for(yval=0, idx=0; yval < mheight; yval++)
|
147
|
-
{
|
148
|
-
for(xval=0; xval < mwidth; xval++)
|
149
|
-
{
|
150
|
-
if(yval < cg->height && xval < cg->width)
|
151
|
-
{
|
152
|
-
cg->fields[idx] = tmp[grid_pos(cg, xval, yval)];
|
153
|
-
}
|
154
|
-
else
|
155
|
-
{
|
156
|
-
cg->fields[idx] = grid_create_field();
|
157
|
-
}
|
158
|
-
idx++;
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
/* ..otherwise use the slightly more efficient algo */
|
163
|
-
else
|
164
|
-
{
|
165
|
-
for(idx=0; idx < fields; idx++)
|
166
|
-
{
|
167
|
-
cg->fields[idx] = tmp[idx];
|
168
|
-
}
|
169
|
-
//printf("initializing fields %li to %li\n", fields, stop);
|
170
|
-
for(idx=fields; idx < stop; idx++)
|
171
|
-
{
|
172
|
-
//printf("creating new field at idx: %i\n", idx);
|
173
|
-
cg->fields[idx] = grid_create_field();
|
174
|
-
}
|
175
|
-
}
|
176
|
-
|
177
|
-
cg->height = mheight;
|
178
|
-
cg->width = mwidth;
|
179
|
-
}
|
180
|
-
|
181
|
-
cGrid *grid_create()
|
182
|
-
{
|
183
|
-
long init_cap = 4;
|
184
|
-
cGrid * cg;
|
185
|
-
cg = ALLOC(cGrid);
|
186
|
-
cg->attributes = rb_hash_new();
|
187
|
-
cg->width = 1;
|
188
|
-
cg->height = 1;
|
189
|
-
cg->capacity = init_cap;
|
190
|
-
cg->row_capacity = init_cap;
|
191
|
-
cg->fields = ALLOC_N(cField *, init_cap);
|
192
|
-
cg->fields[0] = grid_create_field();
|
193
|
-
cg->row_attributes = ALLOC_N(VALUE, init_cap);
|
194
|
-
cg->row_attributes[0] = Qnil;
|
195
|
-
return cg;
|
196
|
-
}
|
197
|
-
|
198
|
-
void grid_mark(cg)
|
199
|
-
cGrid * cg;
|
200
|
-
{
|
201
|
-
cField * cf;
|
202
|
-
long idx, cdx, stop;
|
203
|
-
stop = cg->height * cg->width;
|
204
|
-
|
205
|
-
rb_gc_mark(cg->attributes);
|
206
|
-
for(idx=0; idx<stop; idx++)
|
207
|
-
{
|
208
|
-
cf = cg->fields[idx];
|
209
|
-
rb_gc_mark(cf->attributes);
|
210
|
-
for(cdx=0; cdx < cf->content_count; cdx++)
|
211
|
-
{
|
212
|
-
rb_gc_mark(cf->content[cdx]);
|
213
|
-
}
|
214
|
-
}
|
215
|
-
for(idx=0; idx < cg->height; idx++)
|
216
|
-
{
|
217
|
-
rb_gc_mark(cg->row_attributes[idx]);
|
218
|
-
}
|
219
|
-
}
|
220
|
-
|
221
|
-
void grid_free(cg)
|
222
|
-
cGrid * cg;
|
223
|
-
{
|
224
|
-
long idx;
|
225
|
-
cField * cf;
|
226
|
-
for(idx=0; idx < (cg->width * cg->height); idx++)
|
227
|
-
{
|
228
|
-
cf = cg->fields[idx];
|
229
|
-
free(cf->content);
|
230
|
-
free(cf);
|
231
|
-
}
|
232
|
-
free(cg->row_attributes);
|
233
|
-
free(cg->fields);
|
234
|
-
free(cg);
|
235
|
-
}
|
236
|
-
|
237
|
-
VALUE grid_new(argc, argv, klass)
|
238
|
-
long argc;
|
239
|
-
VALUE *argv;
|
240
|
-
VALUE klass;
|
241
|
-
{
|
242
|
-
VALUE instance, attr, argv2[1];
|
243
|
-
cGrid *internal;
|
244
|
-
|
245
|
-
rb_scan_args(argc, argv, "01", &attr);
|
246
|
-
argv2[0] = (attr == Qnil) ? rb_hash_new() : attr;
|
247
|
-
|
248
|
-
internal = grid_create();
|
249
|
-
instance = Data_Wrap_Struct(klass, grid_mark, grid_free, internal);
|
250
|
-
rb_obj_call_init(instance, 1, argv2);
|
251
|
-
|
252
|
-
return instance;
|
253
|
-
}
|
254
|
-
|
255
|
-
VALUE grid_initialize(self, attr)
|
256
|
-
VALUE self, attr;
|
257
|
-
{
|
258
|
-
VALUE key;
|
259
|
-
cGrid * cg;
|
260
|
-
Data_Get_Struct(self, cGrid, cg);
|
261
|
-
|
262
|
-
key = rb_str_new2("cellspacing");
|
263
|
-
if(!st_lookup(RHASH_TBL(attr), key, 0))
|
264
|
-
{
|
265
|
-
rb_hash_aset(attr, key, rb_str_new2("0"));
|
266
|
-
}
|
267
|
-
cg->attributes = attr;
|
268
|
-
|
269
|
-
return self;
|
270
|
-
}
|
271
|
-
|
272
|
-
VALUE grid_height(self)
|
273
|
-
VALUE self;
|
274
|
-
{
|
275
|
-
cGrid * cg;
|
276
|
-
Data_Get_Struct(self, cGrid, cg);
|
277
|
-
return LONG2NUM(cg->height);
|
278
|
-
}
|
279
|
-
|
280
|
-
VALUE grid_width(self)
|
281
|
-
VALUE self;
|
282
|
-
{
|
283
|
-
cGrid * cg;
|
284
|
-
Data_Get_Struct(self, cGrid, cg);
|
285
|
-
return INT2NUM(cg->width);
|
286
|
-
}
|
287
|
-
|
288
|
-
VALUE grid_cat_attribute(pair, string)
|
289
|
-
VALUE pair, string;
|
290
|
-
{
|
291
|
-
VALUE val, tmp1, tmp2;
|
292
|
-
char *key, *value;
|
293
|
-
long len;
|
294
|
-
val = rb_ary_entry(pair, 1);
|
295
|
-
if(val == Qnil)
|
296
|
-
return string;
|
297
|
-
tmp1 = rb_ary_entry(pair, 0);
|
298
|
-
key = StringValuePtr(tmp1);
|
299
|
-
tmp2 = rb_funcall(val, rb_intern("to_s"), 0);
|
300
|
-
value = StringValuePtr(tmp2);
|
301
|
-
char attr[strlen(key) + strlen(value) + 5];
|
302
|
-
len = sprintf(attr, " %s=\"%s\"", key, value);
|
303
|
-
return rb_str_cat(string, attr, len);
|
304
|
-
}
|
305
|
-
|
306
|
-
void grid_cat_starttag(string, tagname, attributes)
|
307
|
-
VALUE string, attributes;
|
308
|
-
char *tagname;
|
309
|
-
{
|
310
|
-
char tagstart[strlen(tagname) + 2];
|
311
|
-
long len;
|
312
|
-
len = sprintf(tagstart, "<%s", tagname);
|
313
|
-
rb_str_cat(string, (char *)tagstart, len);
|
314
|
-
rb_iterate(rb_each, attributes, grid_cat_attribute, string);
|
315
|
-
rb_str_cat(string, ">", 1);
|
316
|
-
}
|
317
|
-
|
318
|
-
void grid_cat_endtag(string, tagname)
|
319
|
-
VALUE string;
|
320
|
-
char *tagname;
|
321
|
-
{
|
322
|
-
char tag[strlen(tagname) + 4];
|
323
|
-
long len;
|
324
|
-
len = sprintf(tag, "</%s>", tagname);
|
325
|
-
rb_str_cat(string, tag, len);
|
326
|
-
}
|
327
|
-
|
328
|
-
VALUE rb_hsh_update(hsh1, hsh2)
|
329
|
-
VALUE hsh1, hsh2;
|
330
|
-
{
|
331
|
-
return rb_iterate(rb_each, hsh2, rb_hsh_store_pair, hsh1);
|
332
|
-
}
|
333
|
-
|
334
|
-
VALUE grid_store_allowed_attribute(pair, attrs)
|
335
|
-
VALUE pair, attrs;
|
336
|
-
{
|
337
|
-
char* key;
|
338
|
-
VALUE tmp;
|
339
|
-
tmp = rb_ary_entry(pair, 0);
|
340
|
-
key = StringValuePtr(tmp);
|
341
|
-
if( strcasecmp(key, "align") == 0
|
342
|
-
|| strcasecmp(key, "class") == 0
|
343
|
-
|| strcasecmp(key, "colspan") == 0
|
344
|
-
|| strcasecmp(key, "style") == 0
|
345
|
-
|| strcasecmp(key, "tag") == 0
|
346
|
-
|| strcasecmp(key, "title") == 0)
|
347
|
-
{
|
348
|
-
return rb_hsh_store_pair(pair, attrs);
|
349
|
-
}
|
350
|
-
else
|
351
|
-
{
|
352
|
-
return Qnil;
|
353
|
-
}
|
354
|
-
}
|
355
|
-
|
356
|
-
const char * tr_open = "<TR>";
|
357
|
-
const char * tr_close = "</TR>";
|
358
|
-
|
359
|
-
VALUE grid_to_html(self, cgi)
|
360
|
-
VALUE self, cgi;
|
361
|
-
{
|
362
|
-
cGrid * cg;
|
363
|
-
cField * cf;
|
364
|
-
VALUE item, result, attrs;
|
365
|
-
ID id_backtrace = rb_intern("backtrace");
|
366
|
-
ID id_to_html = rb_intern("to_html");
|
367
|
-
ID id_to_s = rb_intern("to_s");
|
368
|
-
//ID id_attributes = rb_intern("attributes");
|
369
|
-
ID id_message = rb_intern("message");
|
370
|
-
long idx, cdx, xval, yval, spanplus, len;
|
371
|
-
Data_Get_Struct(self, cGrid, cg);
|
372
|
-
//attrs = rb_iv_get(self, "@attributes");
|
373
|
-
//printf("getin grid_to_html\n");
|
374
|
-
result = rb_str_new2("");
|
375
|
-
grid_cat_starttag(result, "TABLE", cg->attributes);
|
376
|
-
for(idx=0, yval=0; yval < cg->height; yval++)
|
377
|
-
{
|
378
|
-
if(cg->row_attributes[yval] == Qnil)
|
379
|
-
rb_str_cat(result, tr_open, 4);
|
380
|
-
else
|
381
|
-
grid_cat_starttag(result, "TR", cg->row_attributes[yval]);
|
382
|
-
|
383
|
-
for(xval=0; xval < cg->width; xval++, idx++)
|
384
|
-
{
|
385
|
-
//printf("writing out field at idx:%i\n", idx);
|
386
|
-
cf = cg->fields[idx];
|
387
|
-
if((spanplus = cf->colspan - 1))
|
388
|
-
{
|
389
|
-
xval += spanplus;
|
390
|
-
idx += spanplus;
|
391
|
-
}
|
392
|
-
attrs = rb_hash_new();
|
393
|
-
/*
|
394
|
-
for(cdx=0; cdx<cf->content_count; cdx++)
|
395
|
-
{
|
396
|
-
item = cf->content[cdx];
|
397
|
-
if(rb_respond_to(item, attributes))
|
398
|
-
{
|
399
|
-
rb_warn("Outward Propagation of attributes is deprecated");
|
400
|
-
rb_iterate(rb_each, rb_funcall(item, attributes, 0),
|
401
|
-
grid_store_allowed_attribute, attrs);
|
402
|
-
}
|
403
|
-
}
|
404
|
-
*/
|
405
|
-
if(cf->attributes != Qnil)
|
406
|
-
rb_hsh_update(attrs, cf->attributes);
|
407
|
-
if(cf->colspan > 1)
|
408
|
-
{
|
409
|
-
char spanstr[cf->colspan/10];
|
410
|
-
len = sprintf(spanstr, "%li", cf->colspan);
|
411
|
-
rb_hash_aset(attrs, rb_str_new2("colspan"),
|
412
|
-
rb_str_new(spanstr, len));
|
413
|
-
}
|
414
|
-
|
415
|
-
grid_cat_starttag(result, cf->tag, attrs);
|
416
|
-
if(cf->content_count == 0)
|
417
|
-
rb_str_cat(result, " ", 6);
|
418
|
-
else
|
419
|
-
{
|
420
|
-
for(cdx=0; cdx<cf->content_count; cdx++)
|
421
|
-
{
|
422
|
-
item = cf->content[cdx];
|
423
|
-
//item => ODDB::View::WelcomeHead
|
424
|
-
//printf("item.encoding = %s \n", StringValuePtr(item));
|
425
|
-
//printf("item.encoding = %s \n", rb_enc_get(item)->name);
|
426
|
-
if(rb_obj_class(item) == rb_cString)
|
427
|
-
rb_str_concat(result, item);
|
428
|
-
else if(rb_respond_to(item, id_to_html))
|
429
|
-
{
|
430
|
-
VALUE item_html = rb_funcall(item, id_to_html, 1, cgi);
|
431
|
-
if(rb_obj_is_kind_of(item_html, rb_cString) == Qtrue){
|
432
|
-
// koko
|
433
|
-
//result = rb_str_force_encoding(result, "UTF-8");
|
434
|
-
//item_html = rb_str_force_encoding(item_html, "UTF-8");
|
435
|
-
//VALUE enc;
|
436
|
-
//enc = rb_obj_encoding(result);
|
437
|
-
//printf("encoding type ");
|
438
|
-
//printf("%s %s\n", rb_enc_get(result)->name, rb_enc_get(item_html)->name);
|
439
|
-
rb_str_concat(result, item_html);
|
440
|
-
//printf("4\n");
|
441
|
-
}
|
442
|
-
}
|
443
|
-
else if(rb_obj_is_kind_of(item, rb_eException) == Qtrue)
|
444
|
-
{
|
445
|
-
rb_str_cat(result, "<!--\n", 5);
|
446
|
-
rb_str_concat(result,
|
447
|
-
rb_funcall(rb_obj_class(item), id_to_s, 0));
|
448
|
-
rb_str_cat(result, "\n", 1);
|
449
|
-
rb_str_concat(result,
|
450
|
-
rb_funcall(item, id_message, 0));
|
451
|
-
rb_str_cat(result, "\n", 1);
|
452
|
-
VALUE bt = rb_funcall(item, id_backtrace, 0);
|
453
|
-
rb_str_concat(result, rb_funcall(bt, rb_intern("join"),
|
454
|
-
1, rb_str_new2("\n")));
|
455
|
-
rb_str_cat(result, "-->\n", 4);
|
456
|
-
}
|
457
|
-
else
|
458
|
-
rb_str_concat(result, rb_funcall(item, id_to_s, 0));
|
459
|
-
}
|
460
|
-
//printf("10\n");
|
461
|
-
}
|
462
|
-
grid_cat_endtag(result, cf->tag);
|
463
|
-
}
|
464
|
-
rb_str_cat(result, tr_close, 5);
|
465
|
-
}
|
466
|
-
rb_str_cat(result, "</TABLE>", 8);
|
467
|
-
//printf("end grid_to_html\n");
|
468
|
-
return result;
|
469
|
-
}
|
470
|
-
|
471
|
-
void grid_field_add_content(cf, content)
|
472
|
-
cField * cf;
|
473
|
-
VALUE content;
|
474
|
-
{
|
475
|
-
long pos;
|
476
|
-
if(cf->capacity <= cf->content_count)
|
477
|
-
{
|
478
|
-
cf->capacity *= 2;
|
479
|
-
REALLOC_N(cf->content, VALUE, cf->capacity);
|
480
|
-
}
|
481
|
-
pos = cf->content_count;
|
482
|
-
cf->content_count++;
|
483
|
-
cf->content[pos] = content;
|
484
|
-
}
|
485
|
-
|
486
|
-
VALUE grid_label2ary(item, ary)
|
487
|
-
VALUE item, ary;
|
488
|
-
{
|
489
|
-
return rb_ary_push(ary, item);
|
490
|
-
}
|
491
|
-
|
492
|
-
VALUE grid_iterate_add_field(item, args)
|
493
|
-
VALUE item, args[3];
|
494
|
-
{
|
495
|
-
if(Qnil == item)
|
496
|
-
{
|
497
|
-
args[1] = LONG2NUM(NUM2LONG(args[1]) + 1);
|
498
|
-
return Qnil;
|
499
|
-
}
|
500
|
-
else
|
501
|
-
{
|
502
|
-
return grid_add_field(args[0], item, args[1], args[2]);
|
503
|
-
}
|
504
|
-
}
|
505
|
-
|
506
|
-
VALUE grid_add(argc, argv, self)
|
507
|
-
long argc;
|
508
|
-
VALUE *argv, self;
|
509
|
-
{
|
510
|
-
VALUE item, xval, yval, colflag;
|
511
|
-
|
512
|
-
rb_scan_args(argc, argv, "31", &item, &xval, &yval, &colflag);
|
513
|
-
if(rb_mod_include_p(rb_obj_class(item), rb_mEnumerable) == Qtrue)
|
514
|
-
{
|
515
|
-
VALUE tmp;
|
516
|
-
if(rb_obj_class(item) == rb_cString)
|
517
|
-
{
|
518
|
-
return grid_add_field(self, item, xval, yval);
|
519
|
-
}
|
520
|
-
else if(rb_obj_class(item) == rb_cArray)
|
521
|
-
{
|
522
|
-
VALUE args[3];
|
523
|
-
args[0] = self;
|
524
|
-
args[1] = xval;
|
525
|
-
args[2] = yval;
|
526
|
-
|
527
|
-
return rb_iterate(rb_each, item, grid_iterate_add_field, (VALUE)args);
|
528
|
-
}
|
529
|
-
else
|
530
|
-
{
|
531
|
-
tmp = rb_ary_new();
|
532
|
-
rb_iterate(rb_each, item, grid_label2ary, tmp);
|
533
|
-
}
|
534
|
-
|
535
|
-
if(colflag == Qtrue)
|
536
|
-
return grid_add_column(self, tmp, xval, yval);
|
537
|
-
else
|
538
|
-
return grid_add_row(self, tmp, xval, yval);
|
539
|
-
}
|
540
|
-
|
541
|
-
return grid_add_field(self, item, xval, yval);
|
542
|
-
}
|
543
|
-
|
544
|
-
VALUE grid_add_field(self, item, xval, yval)
|
545
|
-
VALUE self, item, xval, yval;
|
546
|
-
{
|
547
|
-
cGrid *cg;
|
548
|
-
cField *cf;
|
549
|
-
long xpos, ypos;
|
550
|
-
Data_Get_Struct(self, cGrid, cg);
|
551
|
-
|
552
|
-
xpos = grid_coordinate(xval, "x-position");
|
553
|
-
ypos = grid_coordinate(yval, "y-position");
|
554
|
-
grid_set_dimensions(cg, xpos + 1, ypos + 1);
|
555
|
-
|
556
|
-
cf = cg->fields[grid_pos(cg, xpos, ypos)];
|
557
|
-
if(item == Qnil)
|
558
|
-
{
|
559
|
-
return Qnil;
|
560
|
-
}
|
561
|
-
else
|
562
|
-
{
|
563
|
-
grid_field_add_content(cf, item);
|
564
|
-
return item;
|
565
|
-
}
|
566
|
-
}
|
567
|
-
|
568
|
-
VALUE grid_add_row(self, item, xval, yval)
|
569
|
-
VALUE self, item, xval, yval;
|
570
|
-
{
|
571
|
-
cGrid *cg;
|
572
|
-
cField *cf;
|
573
|
-
long xpos, ypos, pos, len, stop, idx;
|
574
|
-
Data_Get_Struct(self, cGrid, cg);
|
575
|
-
|
576
|
-
len = RARRAY_LEN(item);
|
577
|
-
xpos = grid_coordinate(xval, "x-position");
|
578
|
-
ypos = grid_coordinate(yval, "y-position");
|
579
|
-
stop = xpos + len;
|
580
|
-
grid_set_dimensions(cg, stop, ypos + 1);
|
581
|
-
|
582
|
-
for(pos = xpos, idx = 0; pos < stop; pos++, idx++)
|
583
|
-
{
|
584
|
-
cf = cg->fields[grid_pos(cg, pos, ypos)];
|
585
|
-
grid_field_add_content(cf, rb_ary_entry(item, idx));
|
586
|
-
}
|
587
|
-
return item;
|
588
|
-
}
|
589
|
-
|
590
|
-
VALUE grid_add_column(self, item, xval, yval)
|
591
|
-
VALUE self, item, xval, yval;
|
592
|
-
{
|
593
|
-
cGrid *cg;
|
594
|
-
cField *cf;
|
595
|
-
long xpos, ypos, pos, len, stop, idx;
|
596
|
-
Data_Get_Struct(self, cGrid, cg);
|
597
|
-
|
598
|
-
len = RARRAY_LEN(item);
|
599
|
-
xpos = grid_coordinate(xval, "x-position");
|
600
|
-
ypos = grid_coordinate(yval, "y-position");
|
601
|
-
stop = ypos + len;
|
602
|
-
grid_set_dimensions(cg, xpos + 1, stop);
|
603
|
-
|
604
|
-
for(pos = ypos, idx=0 ; pos < stop; pos++, idx++)
|
605
|
-
{
|
606
|
-
cf = cg->fields[grid_pos(cg, xpos, pos)];
|
607
|
-
grid_field_add_content(cf, rb_ary_entry(item, idx));
|
608
|
-
}
|
609
|
-
return item;
|
610
|
-
}
|
611
|
-
|
612
|
-
VALUE grid_push(self, item)
|
613
|
-
VALUE self, item;
|
614
|
-
{
|
615
|
-
cGrid *cg;
|
616
|
-
cField * cf;
|
617
|
-
Data_Get_Struct(self, cGrid, cg);
|
618
|
-
|
619
|
-
long height = cg->height;
|
620
|
-
grid_set_dimensions(cg, cg->width, height + 1);
|
621
|
-
cf = cg->fields[grid_pos(cg, 0, height)];
|
622
|
-
grid_field_add_content(cf, item);
|
623
|
-
cf->colspan = cg->width;
|
624
|
-
return item;
|
625
|
-
}
|
626
|
-
|
627
|
-
VALUE grid_set_colspan(argc, argv, self)
|
628
|
-
long argc;
|
629
|
-
VALUE *argv, self;
|
630
|
-
{
|
631
|
-
VALUE xval, yval, span;
|
632
|
-
|
633
|
-
cGrid *cg;
|
634
|
-
cField * cf;
|
635
|
-
Data_Get_Struct(self, cGrid, cg);
|
636
|
-
long xpos, ypos, spanval;
|
637
|
-
|
638
|
-
rb_scan_args(argc, argv, "21", &xval, &yval, &span);
|
639
|
-
xpos = grid_coordinate(xval, "x-position");
|
640
|
-
ypos = grid_coordinate(yval, "y-position");
|
641
|
-
if(span == Qnil)
|
642
|
-
spanval = cg->width - xpos;
|
643
|
-
else
|
644
|
-
spanval = grid_coordinate(span, "span-value");
|
645
|
-
grid_set_dimensions(cg, xpos + spanval, ypos + 1);
|
646
|
-
cf = cg->fields[grid_pos(cg, xpos, ypos)];
|
647
|
-
cf->colspan = spanval;
|
648
|
-
return span;
|
649
|
-
}
|
650
|
-
|
651
|
-
VALUE grid_set_attribute(self, key, value)
|
652
|
-
VALUE self, key, value;
|
653
|
-
{
|
654
|
-
cGrid * cg;
|
655
|
-
Data_Get_Struct(self, cGrid, cg);
|
656
|
-
return rb_hash_aset(cg->attributes, key, value);
|
657
|
-
}
|
658
|
-
|
659
|
-
VALUE grid_set_attribute_pair(pair, cg)
|
660
|
-
VALUE pair;
|
661
|
-
cGrid *cg;
|
662
|
-
{
|
663
|
-
return rb_hsh_store_pair(pair, cg->attributes);
|
664
|
-
}
|
665
|
-
|
666
|
-
VALUE grid_set_attributes(self, attr)
|
667
|
-
VALUE self, attr;
|
668
|
-
{
|
669
|
-
cGrid * cg;
|
670
|
-
Data_Get_Struct(self, cGrid, cg);
|
671
|
-
rb_iterate(rb_each, attr, grid_set_attribute_pair, (VALUE)cg);
|
672
|
-
return attr;
|
673
|
-
}
|
674
|
-
|
675
|
-
VALUE grid_insert_row(self, yval, item)
|
676
|
-
VALUE self, yval, item;
|
677
|
-
{
|
678
|
-
cGrid *cg;
|
679
|
-
cField *cf;
|
680
|
-
long yint, move, idx, tmpx, first, last;
|
681
|
-
Data_Get_Struct(self, cGrid, cg);
|
682
|
-
VALUE argv[3];
|
683
|
-
|
684
|
-
yint = grid_coordinate(yval, "y-position");
|
685
|
-
move = (cg->height - yint) * cg->width;
|
686
|
-
grid_set_dimensions(cg, cg->width, cg->height + 1);
|
687
|
-
first = (cg->height * cg->width);
|
688
|
-
last = first-move;
|
689
|
-
for(idx = first-1, tmpx=idx-cg->width; idx >= last; idx--, tmpx--)
|
690
|
-
{
|
691
|
-
cf = cg->fields[idx];
|
692
|
-
cg->fields[idx] = cg->fields[tmpx];
|
693
|
-
cg->fields[tmpx] = cf;
|
694
|
-
}
|
695
|
-
first = cg->width * yint;
|
696
|
-
last = yint + cg->width;
|
697
|
-
|
698
|
-
argv[0] = item;
|
699
|
-
argv[1] = INT2FIX(0);
|
700
|
-
argv[2] = yval;
|
701
|
-
grid_add(3, argv, self);
|
702
|
-
return item;
|
703
|
-
}
|
704
|
-
|
705
|
-
void grid_block_iterate(cg, xint, yint, wint, hint, callback, arg)
|
706
|
-
cGrid * cg;
|
707
|
-
long xint, yint, wint, hint;
|
708
|
-
void * callback ();
|
709
|
-
VALUE arg;
|
710
|
-
{
|
711
|
-
cField * cf;
|
712
|
-
long yend, ypos, pos, idx;
|
713
|
-
|
714
|
-
yend = yint + hint;
|
715
|
-
grid_set_dimensions(cg, xint + wint, yend);
|
716
|
-
for(ypos = yint; ypos < yend; ypos++)
|
717
|
-
{
|
718
|
-
pos = grid_pos(cg, xint, ypos);
|
719
|
-
for(idx=0; idx < wint; idx++, pos++)
|
720
|
-
{
|
721
|
-
cf = cg->fields[pos];
|
722
|
-
callback(cf, arg);
|
723
|
-
}
|
724
|
-
}
|
725
|
-
}
|
726
|
-
|
727
|
-
VALUE grid_iterate(argc, argv, self, callback, creative)
|
728
|
-
long argc;
|
729
|
-
VALUE *argv, self;
|
730
|
-
void * callback();
|
731
|
-
int creative;
|
732
|
-
{
|
733
|
-
VALUE value, xval, yval, wval, hval;
|
734
|
-
cGrid *cg;
|
735
|
-
long xint, yint, wint, hint;
|
736
|
-
|
737
|
-
rb_scan_args(argc, argv, "32", &value, &xval, &yval, &wval, &hval);
|
738
|
-
Data_Get_Struct(self, cGrid, cg);
|
739
|
-
xint = grid_coordinate(xval, "x-position");
|
740
|
-
yint = grid_coordinate(yval, "y-position");
|
741
|
-
if(wval == Qnil)
|
742
|
-
wint = 1;
|
743
|
-
else
|
744
|
-
wint = grid_coordinate(wval, "width");
|
745
|
-
if(hval == Qnil)
|
746
|
-
hint = 1;
|
747
|
-
else
|
748
|
-
hint = grid_coordinate(hval, "height");
|
749
|
-
|
750
|
-
if(!creative)
|
751
|
-
{
|
752
|
-
if(xint >= cg->width || yint >= cg->height)
|
753
|
-
return Qnil;
|
754
|
-
if((xint + wint) > cg->width)
|
755
|
-
wint = cg->width - xint;
|
756
|
-
if((yint + hint) > cg->height)
|
757
|
-
hint = cg->height - yint;
|
758
|
-
}
|
759
|
-
|
760
|
-
grid_block_iterate(cg, xint, yint, wint, hint,
|
761
|
-
callback, value);
|
762
|
-
|
763
|
-
return value;
|
764
|
-
}
|
765
|
-
|
766
|
-
void grid_field_add_tag(cf, tagname)
|
767
|
-
cField * cf;
|
768
|
-
VALUE tagname;
|
769
|
-
{
|
770
|
-
strcpy(cf->tag, StringValuePtr(tagname));
|
771
|
-
}
|
772
|
-
|
773
|
-
VALUE grid_add_tag(argc, argv, self)
|
774
|
-
long argc;
|
775
|
-
VALUE *argv, self;
|
776
|
-
{
|
777
|
-
return grid_iterate(argc, argv, self, grid_field_add_tag, 1);
|
778
|
-
}
|
779
|
-
|
780
|
-
void grid_field_add_attribute(cf, pair)
|
781
|
-
cField * cf;
|
782
|
-
VALUE pair;
|
783
|
-
{
|
784
|
-
if(cf->attributes == Qnil)
|
785
|
-
cf->attributes = rb_hash_new();
|
786
|
-
rb_hsh_store_pair(pair, cf->attributes);
|
787
|
-
}
|
788
|
-
|
789
|
-
//VALUE grid_row_set_attributes(self, ahash, yval)
|
790
|
-
// VALUE self, ahash, yval;
|
791
|
-
VALUE grid_row_set_attributes(argc, argv, self)
|
792
|
-
long argc;
|
793
|
-
VALUE *argv, self;
|
794
|
-
{
|
795
|
-
VALUE ahash, yval, hval;
|
796
|
-
|
797
|
-
rb_scan_args(argc, argv, "21", &ahash, &yval, &hval);
|
798
|
-
|
799
|
-
cGrid * cg;
|
800
|
-
long ypos, hint, idx;
|
801
|
-
Data_Get_Struct(self, cGrid, cg);
|
802
|
-
|
803
|
-
if(hval == Qnil)
|
804
|
-
hint = 1;
|
805
|
-
else
|
806
|
-
hint = grid_coordinate(hval, "height");
|
807
|
-
|
808
|
-
ypos = grid_coordinate(yval, "y-position");
|
809
|
-
grid_set_dimensions(cg, cg->width, ypos + hint);
|
810
|
-
for(idx = 0; idx < hint; idx++) {
|
811
|
-
cg->row_attributes[ypos+idx] = ahash;
|
812
|
-
}
|
813
|
-
|
814
|
-
return ahash;
|
815
|
-
}
|
816
|
-
|
817
|
-
VALUE grid_add_attribute(argc, argv, self)
|
818
|
-
long argc;
|
819
|
-
VALUE *argv, self;
|
820
|
-
{
|
821
|
-
long argc2, idx;
|
822
|
-
argc2 = argc - 1;
|
823
|
-
VALUE key, value, xval, yval, wval, hval, pair;
|
824
|
-
VALUE argv2[argc2];
|
825
|
-
rb_scan_args(argc, argv, "42",
|
826
|
-
&key, &value, &xval, &yval, &wval, &hval);
|
827
|
-
|
828
|
-
pair = rb_ary_new();
|
829
|
-
rb_ary_push(pair, key);
|
830
|
-
rb_ary_push(pair, value);
|
831
|
-
|
832
|
-
argv2[0] = pair;
|
833
|
-
for(idx=1; idx<argc2; idx++)
|
834
|
-
{
|
835
|
-
argv2[idx] = argv[idx + 1];
|
836
|
-
}
|
837
|
-
|
838
|
-
return grid_iterate(argc2, argv2, self,
|
839
|
-
grid_field_add_attribute, 1);
|
840
|
-
}
|
841
|
-
|
842
|
-
void grid_field_add_component_style(cf, style)
|
843
|
-
cField * cf;
|
844
|
-
VALUE style;
|
845
|
-
{
|
846
|
-
ID set_attribute = rb_intern("set_attribute");
|
847
|
-
VALUE item;
|
848
|
-
long idx;
|
849
|
-
VALUE str_class = rb_str_new2("class");
|
850
|
-
for(idx=0; idx<cf->content_count; idx++)
|
851
|
-
{
|
852
|
-
item = cf->content[idx];
|
853
|
-
if(rb_respond_to(item, set_attribute))
|
854
|
-
{
|
855
|
-
rb_funcall(item, set_attribute, 2,
|
856
|
-
str_class, style);
|
857
|
-
}
|
858
|
-
}
|
859
|
-
}
|
860
|
-
|
861
|
-
VALUE grid_add_component_style(argc, argv, self)
|
862
|
-
long argc;
|
863
|
-
VALUE *argv, self;
|
864
|
-
{
|
865
|
-
return grid_iterate(argc, argv, self,
|
866
|
-
grid_field_add_component_style, 0);
|
867
|
-
}
|
868
|
-
|
869
|
-
void grid_field_add_style(cf, style)
|
870
|
-
cField * cf;
|
871
|
-
VALUE style;
|
872
|
-
{
|
873
|
-
if(cf->attributes == Qnil)
|
874
|
-
cf->attributes = rb_hash_new();
|
875
|
-
rb_hash_aset(cf->attributes, rb_str_new2("class"), style);
|
876
|
-
}
|
877
|
-
|
878
|
-
VALUE grid_add_style(argc, argv, self)
|
879
|
-
long argc;
|
880
|
-
VALUE *argv, self;
|
881
|
-
{
|
882
|
-
return grid_iterate(argc, argv, self, grid_field_add_style, 1);
|
883
|
-
}
|
884
|
-
|
885
|
-
VALUE grid_field_attribute(self, name, xval, yval)
|
886
|
-
VALUE self, name, xval, yval;
|
887
|
-
{
|
888
|
-
cGrid * cg;
|
889
|
-
cField * cf;
|
890
|
-
long xpos, ypos;
|
891
|
-
Data_Get_Struct(self, cGrid, cg);
|
892
|
-
xpos = grid_coordinate(xval, "x-position");
|
893
|
-
ypos = grid_coordinate(yval, "y-position");
|
894
|
-
|
895
|
-
if((xpos >= cg->width) || (ypos >= cg->height))
|
896
|
-
return Qnil;
|
897
|
-
cf = cg->fields[grid_pos(cg, xpos, ypos)];
|
898
|
-
return rb_hash_aref(cf->attributes, name);
|
899
|
-
}
|