1 #include "wikiattrib.h"
2 #include "wikiformat.h"
4 #include "util_check.h"
7 bool WikiAttrib1::readAttrib1 (WikiMotorObjVec* cell, bool& rc) {
12 if (cell->size () == 0) {
14 if (mode == M_ATTRIB || mode == M_ATTRIB_TEXT)
19 if (cell->splitChar_keyword ('=', key, vval)) {
20 if (wiki->paramID (key, vval, id, ferr)) {
21 } else if (wiki->paramClass (key, vval, classlist, ferr)) {
22 } else if (wiki->paramOnClickCheck (key)) {
23 if (! checkScript (vval, onclick, ferr)) {
24 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
27 } else if (wiki->paramOnFocusCheck (key)) {
28 if (! checkScript (vval, onfocus, ferr)) {
29 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
32 } else if (wiki->paramOnBlurCheck (key)) {
33 if (! checkScript (vval, onblur, ferr)) {
34 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
37 } else if (wiki->paramOnChangeCheck (key)) {
38 if (! checkScript (vval, onchange, ferr)) {
39 wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n"));
42 } else if ((selector & SEL_TARGET) && wiki->paramTargetCheck (key)) {
43 wiki->paramTargetBody (key, vval.textOut (wiki), target, ferr);
44 } else if (readAttribMore (key, vval, ferr)) {
47 if (mode == M_ATTRIB) {
48 wiki->errorMsg.append (cell->dump ()).append (CharConst (": bad attribute.\n"));
54 if (selector & SEL_CLASS2) {
55 wiki->paramClassValue (*cell, classlist, ferr);
56 } else if (selector & SEL_TARGET2) {
57 wiki->paramTargetBody (uEmpty, cell->textOut (wiki), target, ferr);
58 } else if ((selector & SEL_ONCLICK2) && checkScript (*cell, onclick, ferr)) {
59 } else if ((selector & SEL_MULTIPLE2) && match (key, CharConst ("multiple"))) {
61 } else if ((selector & SEL_DEFAULT2) && match (key, CharConst ("default"))) {
63 } else if ((selector & SEL_SCRIPT2) && checkScript (*cell, script, ferr)) {
64 } else if (readAttribMore2 (key, *cell, ferr)) {
67 if (mode == M_ATTRIB) {
68 wiki->errorMsg.append (cell->dump ()).append (CharConst (": bad attribute.\n"));
82 bool WikiAttrib1::shiftAttrib (WikiMotorObjVecPtr& vec) {
84 WikiMotorObjVecPtr v2;
86 while (vec->size () > 0) {
89 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
90 // if (vec->splitChar (':', cell, *v2) || fwhole) {
91 if (vec->splitChar (':', cell, *v2) || mode == M_ATTRIB || mode == M_ATTRIB_TEXT) {
92 if (! readAttrib1 (&cell, rc))
102 void WikiAttrib1::skipAttrib (WikiMotorObjVecPtr& vec) {
103 WikiMotorObjVecPtr v2;
105 if (vec->size () > 0) {
106 WikiMotorObjVec cell;
108 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
109 if (vec->splitChar (':', cell, *v2)) {
115 bool WikiAttrib1::readAttrib (WikiMotorObjVecVec::const_iterator& b, const WikiMotorObjVecVec::const_iterator& e) {
119 WikiMotorObjVec* cell = b->get ();
120 if (! readAttrib1 (cell, rc))
127 bool WikiAttrib1::checkScript (WikiMotorObjVec& vec, ustring& scr, bool& ferr) {
131 for (i = 0; i < vec.size () && vec[i]->type == WikiMotorObj::wiki_funcLink; i ++) {
132 WikiMotorObjFuncLink* fn = WikiMotorObjFuncLink_type (&*vec[i]);
133 u = fn->execDefunArgs (wiki);
134 // XXX: 末尾の空白を除去し,セミコロンを確認する。
144 bool WikiAttrib1::shiftLink (WikiMotorObjVecPtr& vec, ustring& url, bool& fscript) {
147 WikiMotorObjVec cell;
148 WikiMotorObjVecPtr v2 (new WikiMotorObjVec);
150 rc = vec->splitChar (':', cell, *v2);
151 if (checkScript (cell, url, ferr)) {
155 } else if (rc && cell.match (CharConst ("http"), CharConst ("https"))) {
156 ustring proto = cell.dump ();
159 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
160 rc = vec->splitChar (':', cell, *v2);
161 if (! cell.splitURL_2 (wiki, proto, url)) {
166 if (vec->size () > 0) {
168 v2 = WikiMotorObjVecPtr (new WikiMotorObjVec);
169 rc = vec->splitChar (':', cell, *v2);
170 if (cell.splitURL_3 (wiki, url, url))
174 } else if (cell.splitURLPath (wiki, url)) {
183 bool WikiAttrib1::readLink (WikiMotorObjVecVec::const_iterator& b, const WikiMotorObjVecVec::const_iterator& e, ustring& url, bool& fscript, bool noscript) {
186 WikiMotorObjVec* cell;
192 if (! noscript && checkScript (*cell, url, ferr)) {
196 } else if (rc && cell->match (CharConst ("http"), CharConst ("https"))) {
197 ustring proto = cell->dump ();
200 if (! cell->splitURL_2 (wiki, proto, url)) {
207 if (cell->splitURL_3 (wiki, url, url))
211 } else if (cell->splitURLPath (wiki, url)) {
220 bool WikiAttrib1::shiftName (WikiMotorObjVecPtr& vec, ustring& name) {
221 if (vec->size () > 0) {
222 WikiMotorObjVec cell;
223 WikiMotorObjVecPtr v2 (new WikiMotorObjVec);
225 vec->splitChar (':', cell, *v2);
226 name = cell.textOut (wiki);
234 void WikiAttrib1::output (MotorOutput* out) {
235 wiki->outputID (out, id);
236 wiki->outputClass (out, classlist);
237 wiki->outputSubmitScript (out, CharConst ("onclick"), onclick);
238 wiki->outputSubmitScript (out, CharConst ("onfocus"), onfocus);
239 wiki->outputSubmitScript (out, CharConst ("onblur"), onblur);
240 wiki->outputSubmitScript (out, CharConst ("onchange"), onchange);
241 wiki->outputName (out, CharConst ("target"), target);
242 // wiki->outputName (out, CharConst ("size"), elsize);
243 wiki->outputFlag (out, CharConst ("multiple"), fmultiple);
248 /* ============================================================ */
249 void WikiAttribTable::init () {
258 // halign = HAlignNone;
263 while (! classlist.empty ())
264 classlist.pop_back ();
271 void WikiAttribTable::copyFrom (WikiAttribTable& b) {
275 for (i = 0; i < b.classlist.size (); i ++)
276 classlist.push_back (b.classlist[i]);
287 bool WikiAttribTable::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
288 if (wiki->paramWidth (key, vval, width, ferr)) {
289 } else if (wiki->paramHeight (key, vval, height, ferr)) {
290 } else if (match (key, CharConst ("bgcolor"), CharConst ("bg"))) {
291 wiki->paramColor (vval.textOut (wiki), bgcolor, key);
295 if (match (key, CharConst ("cellspacing"), CharConst ("spc"))) {
296 wiki->paramUNum (vval.textOut (wiki), cellspacing, key);
297 } else if (match (key, CharConst ("cellpadding"))) {
298 wiki->paramUNum (vval.textOut (wiki), cellpadding, key);
313 bool WikiAttribTable::readAttribMore2 (const ustring& key, WikiMotorObjVec& cell, bool& ferr) {
314 if (match (key, CharConst ("left"), CharConst ("l"))) {
316 } else if (match (key, CharConst ("right"), CharConst ("r"))) {
317 halign = HAlignRight;
318 } else if (match (key, CharConst ("center"), CharConst ("c"))) {
319 halign = HAlignCenter;
323 if (match (key, CharConst ("noborder"), CharConst ("nb"))) {
325 } else if (match (key, CharConst ("padding"), CharConst ("pad"))) {
327 } else if (match (key, CharConst ("expanding"), CharConst ("expand"))) {
329 } else if (match (key, CharConst ("nowhite"), CharConst ("nw"))) {
331 } else if (match (key, CharConst ("turn"))) {
339 if (match (key, CharConst ("header"), CharConst ("h"))) {
341 } else if (match (key, CharConst ("top"), CharConst ("t"))) {
343 } else if (match (key, CharConst ("middle"), CharConst ("m"))) {
344 valign = VAlignMiddle;
345 } else if (match (key, CharConst ("bottom"), CharConst ("b"))) {
346 valign = VAlignBottom;
347 } else if (match (key, CharConst ("nowrap"), CharConst ("nw"))) {
349 } else if (match (key, CharConst ("*"))) {
363 void WikiAttribTable::outputMore (MotorOutput* out) {
366 out->out_raw (CharConst (" align=\"left\""));
369 out->out_raw (CharConst (" align=\"center\""));
372 out->out_raw (CharConst (" align=\"right\""));
375 wiki->outputName (out, CharConst ("width"), width);
376 wiki->outputName (out, CharConst ("height"), height);
377 wiki->outputName (out, CharConst ("bgcolor"), bgcolor);
381 wiki->outputName (out, CharConst ("border"), fnoborder ? 0 : 1, false);
382 wiki->outputName (out, CharConst ("cellspacing"), cellspacing, false);
383 wiki->outputName (out, CharConst ("cellpadding"), cellpadding, false);
389 out->out_raw (CharConst (" valign=\"top\""));
392 out->out_raw (CharConst (" valign=\"middle\""));
395 out->out_raw (CharConst (" valign=\"bottom\""));
398 wiki->outputFlag (out, CharConst ("nowrap"), fnowrap);
405 /* ============================================================ */
406 bool WikiAttribImg::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
407 if (wiki->paramWidth (key, vval, width, ferr)) {
408 } else if (wiki->paramHeight (key, vval, height, ferr)) {
409 } else if (match (key, CharConst ("alt"))) {
410 alt = vval.textOut (wiki);
417 void WikiAttribImg::outputMore (MotorOutput* out) {
418 wiki->outputName (out, CharConst ("width"), width);
419 wiki->outputName (out, CharConst ("height"), height);
423 /* ============================================================ */
424 bool WikiAttribInput::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
425 if ((selector2 & SEL_INPUT) && wiki->paramSize (CharConst ("size"), key, vval, psize, ferr)) {
426 } else if ((selector2 & SEL_ELSIZE) && match (key, CharConst ("size"))) {
427 ustring v = vval.textOut (wiki);
428 if (match (v, CharConst ("*"))) {
430 } else if (checkNum (v)) {
431 elsize = to_int32 (v);
432 if (elsize < 0 || elsize > 999) {
438 } else if (wiki->paramWidth (key, vval, pwidth, ferr)) {
439 } else if ((selector2 & SEL_TEXTAREA) && wiki->paramSize (CharConst ("cols"), key, vval, pcols, ferr)) {
440 } else if ((selector2 & SEL_TEXTAREA) && wiki->paramSize (CharConst ("rows"), key, vval, prows, ferr)) {
441 } else if ((selector2 & SEL_TEXTAREA) && match (key, CharConst ("wrap"))) {
442 ustring value (vval.textOut (wiki));
443 if (match (value, CharConst ("off"))) {
445 } else if (match (value, CharConst ("soft"))) {
447 } else if (match (value, CharConst ("hard"))) {
449 } else if (wiki->paramWidth (key, vval, pwidth, ferr)) {
451 wiki->errorMsg.append (key).append (CharConst ("=")).append (vval.dump ()).append (CharConst (": link script error.\n"));
461 bool WikiAttribInput::readAttribMore2 (const ustring& key, WikiMotorObjVec& cell, bool& ferr) {
462 if (key == uDefault) {
464 } else if ((selector2 & SEL_CHECK) && match (key, CharConst ("checked"))) {
466 } else if ((selector2 & SEL_TEXTAREA) && match (key, CharConst ("tab"))) {
474 void WikiAttribInput::outputMore (MotorOutput* out) {
475 wiki->outputName (out, CharConst ("size"), psize);
476 wiki->outputName (out, CharConst ("size"), elsize);
477 if (pwidth.size () > 0) {
478 if (checkNum (pwidth)) {
479 out->out_raw (CharConst (" style=\"width:"))->out_toHTML_noCtrl (pwidth)->out_raw (CharConst ("px;\""));
481 out->out_raw (CharConst (" style=\"width:"))->out_toHTML_noCtrl (pwidth)->out_raw (CharConst (";\""));
484 if (selector2 & SEL_CHECK) {
485 wiki->outputFlag (out, CharConst ("checked"), pchecked);
487 if (selector2 & SEL_TEXTAREA) {
488 wiki->outputName (out, CharConst ("cols"), pcols, false);
489 wiki->outputName (out, CharConst ("rows"), prows);
492 out->out_raw (CharConst (" wrap=\"off\""));
495 out->out_raw (CharConst (" wrap=\"soft\""));
496 // out->out_raw (CharConst (" wrap=\"virtual\""));
499 out->out_raw (CharConst (" wrap=\"hard\""));
500 // out->out_raw (CharConst (" wrap=\"physical\""));
505 ->out_raw (CharConst ("onkeypress"))
506 ->out_raw (CharConst ("=\""))
507 ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
510 ->out_raw (CharConst ("onkeydown"))
511 ->out_raw (CharConst ("=\""))
512 ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
515 ->out_raw (CharConst ("onkeyup"))
516 ->out_raw (CharConst ("=\""))
517 ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
523 /* ============================================================ */
524 bool WikiAttribButton::readAttrib (WikiMotorObjVecVec::const_iterator& b, const WikiMotorObjVecVec::const_iterator& e) {
528 WikiMotorObjVec* cell = b->get ();
534 if (! readAttrib1 (cell, rc)) {
535 name = cell->textOut (wiki);
542 WikiMotorObjVec* cell = b->get ();
543 if (! readAttrib1 (cell, rc))
550 /* ============================================================ */