00001 #include "gui_layeredregion.hpp"
00002 #include "gui_frame.hpp"
00003 #include "gui_out.hpp"
00004
00005 #include <xml_document.hpp>
00006 #include <utils_string.hpp>
00007
00008 namespace gui
00009 {
00010 void layered_region::parse_block(xml::block* pBlock)
00011 {
00012 parse_attributes_(pBlock);
00013
00014 parse_size_block_(pBlock);
00015 parse_anchor_block_(pBlock);
00016 }
00017
00018 void layered_region::parse_attributes_(xml::block* pBlock)
00019 {
00020 std::string sName = pBlock->get_attribute("name");
00021 if (!pManager_->check_uiobject_name(sName))
00022 {
00023 throw exception(pBlock->get_location(),
00024 "Can't create an uiobject with an incorrect name. Skipped."
00025 );
00026 }
00027
00028 bool bVirtual = utils::string_to_bool(pBlock->get_attribute("virtual"));
00029 frame* pFrameParent = dynamic_cast<frame*>(pParent_);
00030 if (!utils::has_no_content(sName))
00031 {
00032 if (bVirtual || (pFrameParent && pFrameParent->is_virtual()))
00033 set_virtual();
00034
00035 set_name(sName);
00036 }
00037 else
00038 {
00039 throw exception(pBlock->get_location(),
00040 "Can't create an uiobject with a blank name. Skipped."
00041 );
00042 }
00043
00044 if (pManager_->get_uiobject_by_name(sName_))
00045 {
00046 throw exception(pBlock->get_location(),
00047 std::string(bVirtual ? "A virtual" : "An")+" object with the name "+
00048 sName_+" already exists. Skipped."
00049 );
00050 }
00051
00052 pManager_->add_uiobject(this);
00053
00054 if (!bVirtual_)
00055 create_glue();
00056
00057 if (pFrameParent)
00058 pFrameParent->add_region(this);
00059
00060 std::string sInheritance = pBlock->get_attribute("inherits");
00061 if (!utils::has_no_content(sInheritance))
00062 {
00063 std::vector<std::string> lObjects = utils::cut(sInheritance, ",");
00064 std::vector<std::string>::iterator iter;
00065 foreach (iter, lObjects)
00066 {
00067 utils::trim(*iter, ' ');
00068 uiobject* pObj = pManager_->get_uiobject_by_name(*iter, true);
00069 if (pObj)
00070 {
00071 if (is_object_type(pObj->get_object_type()))
00072 {
00073
00074 copy_from(pObj);
00075 }
00076 else
00077 {
00078 gui::out << gui::warning << pBlock->get_location() << " : "
00079 << "\"" << sName_ << "\" (" << "gui::" << lType_.back() << ") cannot inherit "
00080 << "from \"" << *iter << "\" (" << pObj->get_object_type() << "). "
00081 << "Inheritance skipped." << std::endl;
00082 }
00083 }
00084 else
00085 {
00086 gui::out << gui::warning << pBlock->get_location() << " : "
00087 << "Couldn't find inherited object \"" << *iter << "\". Inheritance skipped." << std::endl;
00088 }
00089 }
00090 }
00091
00092 if ((pBlock->is_provided("hidden") || !bInherits_) &&
00093 (utils::string_to_bool(pBlock->get_attribute("hidden"))))
00094 hide();
00095
00096 if ((pBlock->is_provided("setAllPoints") || !bInherits_) &&
00097 (utils::string_to_bool(pBlock->get_attribute("setAllPoints"))))
00098 set_all_points("$parent");
00099 }
00100 }