diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-11-25 22:22:42 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-11-25 22:22:42 +0100 |
commit | 3202ed972b013c09e6020fe2d6c4f8e64173fb8a (patch) | |
tree | 0f27d0026eb8549e60cbca60c5b632804cb840e5 | |
parent | 00649e89e89ff0caeb46a42cb0265d8c0c657840 (diff) | |
parent | 3cd86e1697e88a5a823315751d01e2d0de548c48 (diff) |
merge
-rw-r--r-- | doc/dw-line-breaking.doc | 297 | ||||
-rw-r--r-- | dw/fltkplatform.cc | 4 | ||||
-rw-r--r-- | dw/fltkplatform.hh | 3 | ||||
-rw-r--r-- | dw/fltkui.cc | 35 | ||||
-rw-r--r-- | dw/fltkui.hh | 8 | ||||
-rw-r--r-- | dw/ui.hh | 6 | ||||
-rw-r--r-- | src/form.cc | 50 | ||||
-rw-r--r-- | src/html.cc | 16 |
8 files changed, 204 insertions, 215 deletions
diff --git a/doc/dw-line-breaking.doc b/doc/dw-line-breaking.doc index 6492a579..2967e98f 100644 --- a/doc/dw-line-breaking.doc +++ b/doc/dw-line-breaking.doc @@ -4,7 +4,8 @@ padding: 0.5em 1em; background-color: #ffffe0"><b>Info:</b> Should be incorporated into dw::Textblock.</div> -<h2>Introduction</h2> +Introduction +============ For the implementation of hyphenation in dillo, not only a hyphenation algorithm was implemented, but also, the line breaking was @@ -23,11 +24,9 @@ get a penalty of, say, 1, since hyphenation is generally considered as a bit "ugly" and should rather be avoided. Consider a situation where the word "dillo" could be hyphenated, with the following badnesses: -<ul> -<li>before "dillo": 0.6; -<li>between "dil-" and "lo": 0.2; -<li>after "dillo": 0.5. -</ul> +- before "dillo": 0.6; +- between "dil-" and "lo": 0.2; +- after "dillo": 0.5. Since the penalty is added, the last value is the best one, so "dillo" is put at the end of the line, without hyphenation. @@ -35,40 +34,42 @@ is put at the end of the line, without hyphenation. Under other circumstances (e. g. narrower lines), the values might be different: -<ul> -<li>before "dillo": infinite; -<li>between "dil-" and "lo": 0.3; -<li>after "dillo": 1.5. -</ul> +- before "dillo": infinite; +- between "dil-" and "lo": 0.3; +- after "dillo": 1.5. In this case, even the addition of the penalty makes hyphenation the best choice. -<h2>Literature</h2> +Literature +========== -<h3>Breaking Paragraphs Into Lines</h3> +Breaking Paragraphs Into Lines +------------------------------ Although dillo does not (yet?) implement the algorithm T<sub>E</sub>X uses for line breaking, this document shares much of the notation used -by the article <i>Breaking Paragraphs Into Lines</i> by Donald -E. Knuth and Michael F. Plass; originally published in: Software -- -Practice and Experience <b>11</b> (1981), 1119-1184; reprinted in: -<i>Digital Typography</i> by Donalt E. Knuth, CSLI Publications 1999. -Anyway an interesting reading. +by the article *Breaking Paragraphs Into Lines* by Donald E. Knuth and +Michael F. Plass; originally published in: Software -- Practice and +Experience **11** (1981), 1119-1184; reprinted in: *Digital +Typography* by Donalt E. Knuth, CSLI Publications 1999. Anyway an +interesting reading. -<h3>Hyphenation</h3> +Hyphenation +----------- Dillo uses the algorithm by Frank Liang, which is described in his doctoral dissertation found at http://www.tug.org/docs/liang/. There -is also a description in chapter H ("Hyphenation") of <i>The -T<sub>E</sub>Xbook</i> by Donald E. Knuth, Addison-Wesley 1984. +is also a description in chapter H ("Hyphenation") of *The +T<sub>E</sub>Xbook* by Donald E. Knuth, Addison-Wesley 1984. Pattern files can be found at http://www.ctan.org/tex-archive/language/hyphenation. -<h2>Overview of Changes</h2> +Overview of Changes +=================== Starting with this change, dw/textblock.cc has been split up; anything related to line breaking has been moved into @@ -77,32 +78,31 @@ like floats. (Better, however, would be a clean logical split.) An important change relates to the way that lines are added: before, dillo would add a line as soon as a new word for this line was -added. Now, a line is added not before the <i>last</i> word of this -line is known. This has two important implications: - -<ul> -<li>Some values in dw::Textblock::Line, which represented values -accumulated within the line, could be removed, since now, these values -can be calculated simply in a loop. -<li>On the other hand, this means that some words may not belong to -any line. For this reason, in some cases (e. g. in -dw::Textblock::sizeRequestImpl) dw::Textblock::showMissingLines is -called, which creates temporary lines, which must, under other -circumstances, be removed again by dw::Textblock::removeTemporaryLines, -since they have been created based on limited information, and so -possibly in a wrong way. (See below for details.) -</ul> +added. Now, a line is added not before the *last* word of this line is +known. This has two important implications: + +- Some values in dw::Textblock::Line, which represented values + accumulated within the line, could be removed, since now, these + values can be calculated simply in a loop. +- On the other hand, this means that some words may not belong to any + line. For this reason, in some cases (e. g. in + dw::Textblock::sizeRequestImpl) dw::Textblock::showMissingLines is + called, which creates temporary lines, which must, under other + circumstances, be removed again by + dw::Textblock::removeTemporaryLines, since they have been created + based on limited information, and so possibly in a wrong way. (See + below for details.) When a word can be hyphenated, an instance of dw::Textblock::Word is used for each part. Notice that soft hyphens are evaluated immediately, but automatic hyphenation is done in a lazy way (details below), so the number of instances may change. There are some new attributes: only when dw::Textblock::Word::canBeHyphenated is set to -<i>true</i>, automatic hyphenation is allowed; it is set to false when -soft hyphens are used for a word, and (of course) by the automatic -hyphenation itself. Furthermore, dw::Textblock::Word::hyphenWidth (more -details in the comment there) has to be included when calculating line -widths. +*true*, automatic hyphenation is allowed; it is set to false when soft +hyphens are used for a word, and (of course) by the automatic +hyphenation itself. Furthermore, dw::Textblock::Word::hyphenWidth +(more details in the comment there) has to be included when +calculating line widths. Some values should be configurable: dw::Textblock::HYPHEN_BREAK, the penalty for hyphens. Also dw::Textblock::Word::stretchability, @@ -110,17 +110,17 @@ dw::Textblock::Word::shrinkability, which are both set in dw::Textblock::addSpace. -<h2>Criteria for Line-Breaking</h2> +Criteria for Line-Breaking +========================== Before these changes to line breaking, a word (represented by dw::Textblock::Word) had the following attributes related to line-breaking: -<ul> -<li>the width of the word itself, represented by dw::Textblock::Word::size; -<li>the width of the space following the word, represented by -dw::Textblock::Word::origSpace. -</ul> +- the width of the word itself, represented by + dw::Textblock::Word::size; +- the width of the space following the word, represented by + dw::Textblock::Word::origSpace. In a more mathematical notation, the \f$i\f$th word has a width \f$w_i\f$ and a space \f$s_i\f$. @@ -132,37 +132,31 @@ With hyphenation, the criteria are refined. Hyphenation should only be used when otherwise line breaking results in very large spaces. We define: -<ul> -<li>the badness \f$\beta\f$ of a line, which is greater the more the -spaces between the words differ from the ideal space; -<li>a penalty \f$p\f$ for any possible break point. -</ul> +- the badness \f$\beta\f$ of a line, which is greater the more the + spaces between the words differ from the ideal space; +- a penalty \f$p\f$ for any possible break point. The goal is to find those break points, where \f$\beta + p\f$ is minimal. Examples for the penalty \f$p\f$: -<ul> -<li>0 for normal line breaks (between words); -<li>\f$\infty\f$ to prevent a line break at all costs; -<li>\f$-\infty\f$ to force a line -<li>a positive, but finite, value for hyphenation points. -</ul> +- 0 for normal line breaks (between words); +- \f$\infty\f$ to prevent a line break at all costs; +- \f$-\infty\f$ to force a line +- a positive, but finite, value for hyphenation points. So we need the following values: -<ul> -<li> \f$w_i\f$ (the width of the word \f$i\f$ itself); -<li> \f$s_i\f$ (the width of the space following the word \f$i\f$); -<li> the stretchability \f$y_i\f$, a value denoting how much the space -after word\f$i\f$ can be stretched (typically \f${1\over 2} s_i\f$); -<li> the shrinkability \f$y_i\f$, a value denoting how much the space -after word\f$i\f$ can be shrunken (typically \f${1\over 3} s_i\f$); -<li> the penalty \f$p_i\f$, if the line is broken after word \f$i\f$; -<li> a width \f$h_i\f$, which is added, when the line is broken after -word \f$i\f$. -</ul> +- \f$w_i\f$ (the width of the word \f$i\f$ itself); +- \f$s_i\f$ (the width of the space following the word \f$i\f$); +- the stretchability \f$y_i\f$, a value denoting how much the space + after word\f$i\f$ can be stretched (typically \f${1\over 2} s_i\f$); +- the shrinkability \f$y_i\f$, a value denoting how much the space + after word\f$i\f$ can be shrunken (typically \f${1\over 3} s_i\f$); +- the penalty \f$p_i\f$, if the line is broken after word \f$i\f$; +- a width \f$h_i\f$, which is added, when the line is broken after + word \f$i\f$. \f$h_i\f$ is the width of the hyphen, if the word \f$i\f$ is a part of the hyphenated word (except the last part); otherwise 0. @@ -185,22 +179,18 @@ We define: \f$W_a^b\f$ is the total width, \f$Y_a^b\f$ the total stretchability, and \f$Z_a^b\f$ the total shrinkability. -Furthermore the <i>adjustment ratio</i> \f$r_a^b\f$: +Furthermore the *adjustment ratio* \f$r_a^b\f$: -<ul> -<li>in the ideal case that \f$W_a^b = l\f$: \f$r_a^b = 0\f$; -<li>if \f$W_a^b < l\f$: \f$r_a^b = (l - W_a^b) / Y_a^b\f$ (\f$r_a^b < 0\f$ in -this case); -<li>if \f$W_a^b > l\f$: \f$r_a^b = (l - W_a^b) / Z_a^b\f$ (\f$r_a^b < 0\f$ in -this case). -</ul> +- in the ideal case that \f$W_a^b = l\f$: \f$r_a^b = 0\f$; +- if \f$W_a^b < l\f$: \f$r_a^b = (l - W_a^b) / Y_a^b\f$ + (\f$r_a^b < 0\f$ in this case); +- if \f$W_a^b > l\f$: \f$r_a^b = (l - W_a^b) / Z_a^b\f$ + (\f$r_a^b < 0\f$ in this case). The badness \f$\beta_a^b\f$ is defined as follows: -<ul> -<li>if \f$r_a^b\f$ is undefined or \f$r_a^b < -1\f$: \f$\beta_a^b = \infty\f$; -<li>otherwise: \f$\beta_a^b = |r_a^b|^3\f$ -</ul> +- if \f$r_a^b\f$ is undefined or \f$r_a^b < -1\f$: \f$\beta_a^b = \infty\f$; +- otherwise: \f$\beta_a^b = |r_a^b|^3\f$ The goal is to find the value of \f$b\f$ where \f$\beta_a^b + p_b\f$ is minimal. (\f$a\f$ is given, since we do not modify the previous @@ -210,13 +200,12 @@ After a couple of words, it is not predictable whether this minimum has already been reached. There are two cases where this is possible for a given \f$b'\f$: -<ul> -<li>\f$\beta_{b'}^a = \infty\f$ (line gets too tight): \f$a \le b < -b'\f$, the minimum has to be searched between these two values; -<li>\f$p_{b'} = -\infty\f$ (forced line break): \f$a \le b \le b'\f$ -(there may be another minimum of \f$\beta_a^b\f$ before; note the -\f$\le\f$ instead of \f$<\f$). -</ul> +- \f$\beta_{b'}^a = \infty\f$ (line gets too tight): + \f$a \le b < b'\f$, the minimum has to be searched between these two + values; +- \f$p_{b'} = -\infty\f$ (forced line break): + \f$a \le b \le b'\f$ (there may be another minimum of + \f$\beta_a^b\f$ before; note the \f$\le\f$ instead of \f$<\f$). This leads to a problem that the last words of a text block are not displayed this way, since they do not fulfill these rules for being @@ -229,7 +218,8 @@ code more complicated. See dw::Textblock::BadnessAndPenalty for details.) -<h2>Hyphens</h2> +Hyphens +======= Words (instances of dw::Textblock::Word), which are actually part of a hyphenated word, are always drawn as a whole, not seperately. This @@ -258,25 +248,21 @@ etc. However, it gets a bit more complicated. Since all non-hyphenations are drawn as a whole, the following conditions can be concluded: -<ul> -<li>from drawing "ABCD" (not hyphenated at all): w(A) + w(B) + w(C) + -w(D) = l(ABCD); -<li>from drawing "BCD", when hyphenated as "A-BCD" ("A-" is not -considered here): w(B) + w(C) + w(D) = l(BCD); -<li>likewise, from drawing "CD" (cases "AB-CD" and "A-B-CD"): w(C) + -w(D) = l(CD); -<li>finally, for the cases "ABC-D", "AB-C-D", "A-BC-D", and "A-B-C-D": -w(D) = l(D). -</ul> +- from drawing "ABCD" (not hyphenated at all): w(A) + w(B) + w(C) + + w(D) = l(ABCD); +- from drawing "BCD", when hyphenated as "A-BCD" ("A-" is not + considered here): w(B) + w(C) + w(D) = l(BCD); +- likewise, from drawing "CD" (cases "AB-CD" and "A-B-CD"): w(C) + + w(D) = l(CD); +- finally, for the cases "ABC-D", "AB-C-D", "A-BC-D", and "A-B-C-D": + w(D) = l(D). So, the calculation is simple: -<ul> -<li>w(D) = l(D) -<li>w(C) = l(CD) - w(D) -<li>w(B) = l(BCD) - (w(C) + w(D)) -<li>w(A) = l(ABCD) - (w(B) + w(C) + w(D)) -</ul> +- w(D) = l(D) +- w(C) = l(CD) - w(D) +- w(B) = l(BCD) - (w(C) + w(D)) +- w(A) = l(ABCD) - (w(B) + w(C) + w(D)) For calculation the hyphen widths, the exact conditions would be over-determined, even when the possibility for individual hyphen @@ -285,7 +271,8 @@ be used. However, a simple approach of fixed hyphen widths will have near-perfect results, so this is kept simple. -<h2>Automatic Hyphenation</h2> +Automatic Hyphenation +===================== When soft hyphens are used, words are immediately divided into different parts, and so different instances of @@ -293,14 +280,12 @@ dw::Textblock::Word. Automatic hyphenation (using Liang's algorithm) is, however, not applied always, but only when possibly needed, after calculating a line without hyphenation: -<ul> -<li>When the line is tight, the last word of the line is hyphenated; -possibly this will result in a line with less parts of this word, and -so a less tight line. -<li>When the line is loose, and there is another word (for the -next line) available, this word is hyphenated; possibly, some parts of -this word are taken into this line, making it less loose. -</ul> +- When the line is tight, the last word of the line is hyphenated; + possibly this will result in a line with less parts of this word, + and so a less tight line. +- When the line is loose, and there is another word (for the next + line) available, this word is hyphenated; possibly, some parts of + this word are taken into this line, making it less loose. After this, the line is re-calculated. @@ -323,36 +308,38 @@ a trick (a second array) to deal with exactly this problem. See there for more details. -<h2>Tests</h2> +Tests +===== There are test HTML files in the <i>test</i> directory. Also, there is a program testing automatic hyphenation, <i>test/liang</i>, which can be easily extended. -<h2>Bugs and Things Needing Improvement</h2> +Bugs and Things Needing Improvement +=================================== -<h3>High Priority</h3> +High Priority +------------- -<b>Bugs in hyphenation:</b> There seem to be problems when breaking +**Bugs in hyphenation:** There seem to be problems when breaking words containing hyphens already. Example: "Abtei-Stadt", which is divided into "Abtei-" and "Stadt", resulting possibly in "Abtei-<span></span>-[new line]Stadt". See also below under "Medium Priority", on how to deal with hyphens and dashes. -<h3>Medium Priority</h3> +Medium Priority +--------------- -<b>Break hyphens and dashes:</b> The following rules seem to be relevant: +**Break hyphens and dashes:** The following rules seem to be relevant: -<ol> -<li>In English, an em-dash is used with no spaces around. Breaking -before and after the dash should be possible, perhaps with a penalty > -0. (In German, an en-dash (Halbgeviert) with spaces around is used -instead.)</li> -<li>After a hyphen, which is part of a compound word, a break should -be possible. As described above ("Abtei-Stadt"), this collides with -hyphenation.</li> -</ol> +- In English, an em-dash is used with no spaces around. Breaking + before and after the dash should be possible, perhaps with a + penalty > 0. (In German, an en-dash (Halbgeviert) with spaces around + is used instead.) +- After a hyphen, which is part of a compound word, a break should be + possible. As described above ("Abtei-Stadt"), this collides with + hyphenation. Where to implement? In the same dynamic, lazy way like hyphenation? As part of hyphenation? @@ -364,7 +351,7 @@ and "Stadt", but "Nordrhein-Westfalen" is divided into "Nord", ("rhein-West") is untouched. (Sorry for the German words; if you have got English examples, send them me.) -<b>Incorrect calculation of extremes:</b> The minimal width of a text +**Incorrect calculation of extremes:** The minimal width of a text block (as part of the width extremes, which are mainly used for tables) is defined by everything between two possible breaks. A possible break may also be a hyphenation point; however, hyphenation @@ -377,30 +364,28 @@ resulting possibly in a different value for the minimal width. Possible strategies to deal with this problem: -<ol> -<li>Ignore. The implications should be minimal. -<li>Any solution will make it neccessary to hyphenate at least some -words when calculating extremes. Since the minimal widths of all words -are used to calculate the minimal width of the text block, the -simplest approach will hyphenate all words. This would, of course, -eliminate the performance gains of the current lazy approach. -<li>The latter approach could be optimized in some ways. Examples: (i) -If a word is already narrower than the current accumulated value for -the minimal width, it makes no sense to hyphenate it. (ii) In other -cases, heuristics may be used to estimate the number of syllables, the -width of the widest of them etc. -</ol> - -<h3>Low Priority</h3> - -<b>Mark the end of a paragraph:</b> Should dw::core::Content::BREAK -still be used? Currently, this is redundant to +- Ignore. The implications should be minimal. +- Any solution will make it neccessary to hyphenate at least some + words when calculating extremes. Since the minimal widths of all + words are used to calculate the minimal width of the text block, the + simplest approach will hyphenate all words. This would, of course, + eliminate the performance gains of the current lazy approach. +- The latter approach could be optimized in some ways. Examples: (i) + If a word is already narrower than the current accumulated value for + the minimal width, it makes no sense to hyphenate it. (ii) In other + cases, heuristics may be used to estimate the number of syllables, + the width of the widest of them etc. + +Low Priority +------------ + +**Mark the end of a paragraph:** Should dw::core::Content::BREAK still +be used? Currently, this is redundant to dw::Textblock::BadnessAndPenalty. -<b>Other than justified text:</b> The calculation of badness is -designed for justified text. For other alignments, it may be -modified. The point is the definition of stretchability and for the -line. +**Other than justified text:** The calculation of badness is designed +for justified text. For other alignments, it may be modified. The +point is the definition of stretchability and for the line. Consider left-aligned text. Most importantly, not the spaces between the words, but the space on the right border is adjusted. If the @@ -425,8 +410,8 @@ lines will, when spaces are shrunken, get too long!) Analogous considerations must be made for right-aligned and centered text. (For centered texts, there are two adjustable spaces.) -<b>Hyphens in adjacent lines:</b> It should be simple to assign a -larger penalty for hyphens, when the line before is already -hyphenated. This way, hyphens in adjacent lines are penalized further. +**Hyphens in adjacent lines:** It should be simple to assign a larger +penalty for hyphens, when the line before is already hyphenated. This +way, hyphens in adjacent lines are penalized further. */ diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index d8e95a6e..7dd87a18 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -419,11 +419,11 @@ FltkPlatform::FltkResourceFactory::createOptionMenuResource () } core::ui::EntryResource * -FltkPlatform::FltkResourceFactory::createEntryResource (int maxLength, +FltkPlatform::FltkResourceFactory::createEntryResource (int size, bool password, const char *label) { - return new ui::FltkEntryResource (platform, maxLength, password, label); + return new ui::FltkEntryResource (platform, size, password, label); } core::ui::MultiLineTextResource * diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh index 7b4272eb..64605b68 100644 --- a/dw/fltkplatform.hh +++ b/dw/fltkplatform.hh @@ -109,8 +109,7 @@ private: createListResource (core::ui::ListResource::SelectionMode selectionMode, int rows); core::ui::OptionMenuResource *createOptionMenuResource (); - core::ui::EntryResource *createEntryResource (int maxLength, - bool password, + core::ui::EntryResource *createEntryResource (int size, bool password, const char *label); core::ui::MultiLineTextResource *createMultiLineTextResource (int cols, int rows); diff --git a/dw/fltkui.cc b/dw/fltkui.cc index 5e4f3c56..14914dfe 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -536,11 +536,11 @@ Fl_Widget *FltkComplexButtonResource::createNewWidget (core::Allocation // ---------------------------------------------------------------------- -FltkEntryResource::FltkEntryResource (FltkPlatform *platform, int maxLength, +FltkEntryResource::FltkEntryResource (FltkPlatform *platform, int size, bool password, const char *label): FltkSpecificResource <dw::core::ui::EntryResource> (platform) { - this->maxLength = maxLength; + this->size = size; this->password = password; this->label = label ? strdup(label) : NULL; this->label_w = 0; @@ -615,7 +615,7 @@ void FltkEntryResource::sizeRequest (core::Requisition *requisition) // 1.3.0 (STR #2688). requisition->width = (int)fl_width ("n") - * (maxLength == UNLIMITED_MAX_LENGTH ? 10 : maxLength) + * (size == UNLIMITED_SIZE ? 10 : size) + label_w + (2 * RELIEF_X_THICKNESS); requisition->ascent = font->ascent + RELIEF_Y_THICKNESS; requisition->descent = font->descent + RELIEF_Y_THICKNESS; @@ -670,6 +670,11 @@ void FltkEntryResource::setEditable (bool editable) this->editable = editable; } +void FltkEntryResource::setMaxLength (int maxlen) +{ + ((Fl_Input *)widget)->maximum_size(maxlen); +} + // ---------------------------------------------------------------------- FltkMultiLineTextResource::FltkMultiLineTextResource (FltkPlatform *platform, @@ -1131,6 +1136,14 @@ void FltkOptionMenuResource::addItem (const char *str, queueResize (true); } +void FltkOptionMenuResource::setItem (int index, bool selected) +{ + if (selected) { + ((Fl_Choice *)widget)->value(menu+index); + queueResize (true); + } +} + void FltkOptionMenuResource::pushGroup (const char *name, bool enabled) { Fl_Menu_Item *item = newItem(); @@ -1257,6 +1270,22 @@ void FltkListResource::addItem (const char *str, bool enabled, bool selected) queueResize (true); } +void FltkListResource::setItem (int index, bool selected) +{ + Fl_Tree *tree = (Fl_Tree *) widget; + Fl_Tree_Item *item = tree->root()->child(index); + + /* TODO: handle groups */ + if (item) { + itemsSelected.set (index, selected); + if (mode == SELECTION_MULTIPLE) + item->select(selected); + else if (selected) + tree->select_only(item); + queueResize (true); + } +} + void FltkListResource::pushGroup (const char *name, bool enabled) { bool selected = false; diff --git a/dw/fltkui.hh b/dw/fltkui.hh index ff927c80..e1845abd 100644 --- a/dw/fltkui.hh +++ b/dw/fltkui.hh @@ -282,7 +282,7 @@ class FltkEntryResource: public FltkSpecificResource <dw::core::ui::EntryResource> { private: - int maxLength; + int size; bool password; const char *initText; char *label; @@ -297,7 +297,7 @@ protected: void setWidgetStyle (Fl_Widget *widget, core::style::Style *style); public: - FltkEntryResource (FltkPlatform *platform, int maxLength, bool password, + FltkEntryResource (FltkPlatform *platform, int size, bool password, const char *label); ~FltkEntryResource (); @@ -308,6 +308,7 @@ public: void setText (const char *text); bool isEditable (); void setEditable (bool editable); + void setMaxLength (int maxlen); }; @@ -445,6 +446,7 @@ template <class I> class FltkSelectionResource: protected: virtual bool setSelectedItems() { return false; } virtual void addItem (const char *str, bool enabled, bool selected) = 0; + virtual void setItem (int index, bool selected) = 0; virtual void pushGroup (const char *name, bool enabled) = 0; virtual void popGroup () = 0; public: @@ -475,6 +477,7 @@ public: ~FltkOptionMenuResource (); void addItem (const char *str, bool enabled, bool selected); + void setItem (int index, bool selected); void pushGroup (const char *name, bool enabled); void popGroup (); @@ -506,6 +509,7 @@ public: ~FltkListResource (); void addItem (const char *str, bool enabled, bool selected); + void setItem (int index, bool selected); void pushGroup (const char *name, bool enabled); void popGroup (); @@ -421,6 +421,7 @@ class SelectionResource: public Resource { public: virtual void addItem (const char *str, bool enabled, bool selected) = 0; + virtual void setItem (int index, bool selected) = 0; virtual void pushGroup (const char *name, bool enabled) = 0; virtual void popGroup () = 0; @@ -480,7 +481,8 @@ public: class EntryResource: public TextResource { public: - enum { UNLIMITED_MAX_LENGTH = -1 }; + enum { UNLIMITED_SIZE = -1 }; + virtual void setMaxLength (int maxlen) = 0; }; class MultiLineTextResource: public TextResource @@ -540,7 +542,7 @@ public: virtual ListResource *createListResource (ListResource::SelectionMode selectionMode, int rows) = 0; virtual OptionMenuResource *createOptionMenuResource () = 0; - virtual EntryResource *createEntryResource (int maxLength, bool password, + virtual EntryResource *createEntryResource (int size, bool password, const char *label) = 0; virtual MultiLineTextResource *createMultiLineTextResource (int cols, int rows) = 0; diff --git a/src/form.cc b/src/form.cc index 11f27b47..454b052c 100644 --- a/src/form.cc +++ b/src/form.cc @@ -177,6 +177,7 @@ public: void addOption (char *value, bool selected, bool enabled); void ensureSelection (); void addOptionsTo (SelectionResource *res); + void reset (SelectionResource *res); void appendValuesTo (Dlist *values, SelectionResource *res); }; @@ -547,10 +548,11 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) if (a_Html_get_attr(html, tag, tagsize, "readonly")) ((EntryResource *) resource)->setEditable(false); -// /* Maximum length of the text in the entry */ -// if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "maxlength"))) -// gtk_entry_set_max_length(GTK_ENTRY(widget), -// strtol(attrbuf, NULL, 10)); + /* Maximum length of the text in the entry */ + if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "maxlength"))) { + int maxlen = strtol(attrbuf, NULL, 10); + ((EntryResource *) resource)->setMaxLength(maxlen); + } } if (prefs.show_tooltip && (attrbuf = a_Html_get_attr(html, tag, tagsize, "title"))) { @@ -982,8 +984,6 @@ void DilloHtmlForm::submit(DilloHtmlInput *active_input, EventButton *event) } a_Url_free(url); } - // /* now, make the rendered area have its focus back */ - // gtk_widget_grab_focus(GTK_BIN(bw->render_main_scroll)->child); } /* @@ -1764,35 +1764,12 @@ void DilloHtmlInput::reset () } break; case DILLO_HTML_INPUT_SELECT: + case DILLO_HTML_INPUT_SEL_LIST: if (select != NULL) { - /* this is in reverse order so that, in case more than one was - * selected, we get the last one, which is consistent with handling - * of multiple selected options in the layout code. */ -// for (i = select->num_options - 1; i >= 0; i--) { -// if (select->options[i].init_val) { -// gtk_menu_item_activate(GTK_MENU_ITEM -// (select->options[i].menuitem)); -// Html_select_set_history(input); -// break; -// } -// } + SelectionResource *sr = (SelectionResource *) embed->getResource(); + select->reset(sr); } break; - case DILLO_HTML_INPUT_SEL_LIST: - if (!select) - break; -// for (i = 0; i < select->num_options; i++) { -// if (select->options[i].init_val) { -// if (select->options[i].menuitem->state == GTK_STATE_NORMAL) -// gtk_list_select_child(GTK_LIST(select->menu), -// select->options[i].menuitem); -// } else { -// if (select->options[i].menuitem->state==GTK_STATE_SELECTED) -// gtk_list_unselect_child(GTK_LIST(select->menu), -// select->options[i].menuitem); -// } -// } - break; case DILLO_HTML_INPUT_TEXTAREA: if (init_str != NULL) { MultiLineTextResource *textres = @@ -1874,6 +1851,15 @@ void DilloHtmlSelect::addOptionsTo (SelectionResource *res) } } +void DilloHtmlSelect::reset (SelectionResource *res) +{ + int size = options->size (); + for (int i = 0; i < size; i++) { + DilloHtmlOption *option = options->get (i); + res->setItem(i, option->selected); + } +} + void DilloHtmlSelect::appendValuesTo (Dlist *values, SelectionResource *res) { int size = options->size (); diff --git a/src/html.cc b/src/html.cc index 812b5c7c..21c1e3af 100644 --- a/src/html.cc +++ b/src/html.cc @@ -3023,22 +3023,6 @@ static void Html_tag_open_link(DilloHtml *html, const char *tag, int tagsize) } /* - * Set the history of the menu to be consistent with the active menuitem. - */ -//static void Html_select_set_history(DilloHtmlInput *input) -//{ -// int i; -// -// for (i = 0; i < input->select->num_options; i++) { -// if (GTK_CHECK_MENU_ITEM(input->select->options[i].menuitem)->active) { -// gtk_option_menu_set_history(GTK_OPTION_MENU(input->widget), i); -// break; -// } -// } -//} - - -/* * Set the Document Base URI */ static void Html_tag_open_base(DilloHtml *html, const char *tag, int tagsize) |