00001 #include "gui_editbox.hpp"
00002 #include "gui_fontstring.hpp"
00003 #include "gui_out.hpp"
00004
00005 #include <xml_document.hpp>
00006 #include <utils_string.hpp>
00007
00008 namespace gui
00009 {
00010 void edit_box::parse_block(xml::block* pBlock)
00011 {
00012 focus_frame::parse_block(pBlock);
00013
00014 parse_text_insets_block_(pBlock);
00015 parse_font_string_block_(pBlock);
00016 parse_highlight_color_block_(pBlock);
00017
00018 if ((pBlock->is_provided("letters") || !pBlock->is_provided("inherits")))
00019 set_max_letters(utils::string_to_uint(pBlock->get_attribute("letters")));
00020
00021 if ((pBlock->is_provided("blinkSpeed") || !pBlock->is_provided("inherits")))
00022 set_blink_speed(utils::string_to_float(pBlock->get_attribute("blinkSpeed")));
00023
00024 if ((pBlock->is_provided("numeric") || !pBlock->is_provided("inherits")))
00025 set_numeric_only(utils::string_to_bool(pBlock->get_attribute("numeric")));
00026
00027 if ((pBlock->is_provided("positive") || !pBlock->is_provided("positive")))
00028 set_positive_only(utils::string_to_bool(pBlock->get_attribute("positive")));
00029
00030 if ((pBlock->is_provided("integer") || !pBlock->is_provided("integer")))
00031 set_integer_only(utils::string_to_bool(pBlock->get_attribute("integer")));
00032
00033 if ((pBlock->is_provided("password") || !pBlock->is_provided("inherits")))
00034 enable_password_mode(utils::string_to_bool(pBlock->get_attribute("password")));
00035
00036 if ((pBlock->is_provided("multiLine") || !pBlock->is_provided("inherits")))
00037 set_multi_line(utils::string_to_bool(pBlock->get_attribute("multiLine")));
00038
00039 if ((pBlock->is_provided("historyLines") || !pBlock->is_provided("inherits")))
00040 set_max_history_lines(utils::string_to_uint(pBlock->get_attribute("historyLines")));
00041
00042 if ((pBlock->is_provided("ignoreArrows") || !pBlock->is_provided("inherits")))
00043 set_arrows_ignored(utils::string_to_bool(pBlock->get_attribute("ignoreArrows")));
00044 }
00045
00046 void edit_box::parse_font_string_block_(xml::block* pBlock)
00047 {
00048 xml::block* pFontStringBlock = pBlock->get_block("FontString");
00049 if (pFontStringBlock)
00050 {
00051 font_string* pFontString = create_font_string_();
00052 pFontString->parse_block(pFontStringBlock);
00053
00054 xml::block* pErrorBlock = pFontStringBlock->get_block("Anchors");
00055 if (pErrorBlock)
00056 {
00057 gui::out << gui::warning << pErrorBlock->get_location() << " : "
00058 << "edit_box : font_string's anchors are ignored." << std::endl;
00059 }
00060
00061 pErrorBlock = pFontStringBlock->get_block("Size");
00062 if (pErrorBlock)
00063 {
00064 gui::out << gui::warning << pErrorBlock->get_location() << " : "
00065 << "edit_box : font_string's Size is ignored." << std::endl;
00066 }
00067
00068 pFontString->set_abs_width(0u);
00069 pFontString->set_abs_height(0u);
00070 pFontString->clear_all_points();
00071 pFontString->set_abs_point(
00072 ANCHOR_TOPLEFT, "$parent", ANCHOR_TOPLEFT, lTextInsets_[BORDER_LEFT], lTextInsets_[BORDER_TOP]
00073 );
00074 pFontString->set_abs_point(
00075 ANCHOR_BOTTOMRIGHT, "$parent", ANCHOR_BOTTOMRIGHT, -lTextInsets_[BORDER_RIGHT], -lTextInsets_[BORDER_BOTTOM]
00076 );
00077
00078 pFontString->enable_formatting(false);
00079 }
00080 }
00081
00082 void edit_box::parse_highlight_color_block_(xml::block* pBlock)
00083 {
00084 xml::block* pHighlightBlock = pBlock->get_block("HighlightColor");
00085 if (pHighlightBlock)
00086 {
00087 set_highlight_color(color(
00088 utils::string_to_float(pHighlightBlock->get_attribute("r")),
00089 utils::string_to_float(pHighlightBlock->get_attribute("g")),
00090 utils::string_to_float(pHighlightBlock->get_attribute("b")),
00091 utils::string_to_float(pHighlightBlock->get_attribute("a"))
00092 ));
00093 }
00094 }
00095
00096 void edit_box::parse_text_insets_block_(xml::block* pBlock)
00097 {
00098 xml::block* pTextInsetsBlock = pBlock->get_block("TextInsets");
00099 if (pTextInsetsBlock)
00100 {
00101 set_text_insets(
00102 utils::string_to_int(pTextInsetsBlock->get_attribute("left")),
00103 utils::string_to_int(pTextInsetsBlock->get_attribute("right")),
00104 utils::string_to_int(pTextInsetsBlock->get_attribute("top")),
00105 utils::string_to_int(pTextInsetsBlock->get_attribute("bottom"))
00106 );
00107 }
00108 }
00109 }