예제 #1
0
void ElementLabel::ProcessEvent(Core::Event& event)
{
	// Detect click events
	if (event.GetTargetElement() == this &&	(event == "click"))
	{
		if (this->HasAttribute("for"))
		{
			Core::Element* forElement = this->GetOwnerDocument()->GetElementById(this->GetAttribute<Core::String>("for", ""));
			if (forElement != NULL)
			{
				forElement->ProcessEvent(event);
			}
		}
		else
		{
			//Note that we have to loop since the ElementFormControlInput class does not pass its OnChildAdded to the superclass.
			//We don't want to modify things too much, so we will just loop when clicked searching for the child input, not really
			//a big deal.
			int childCount = this->GetNumChildren();
			Core::Element* child;
			for (int i = 0; i < childCount; ++i)
			{
				child = this->GetChild(i);
				if (child->GetTagName() == "input")
				{
					child->ProcessEvent(event);
					i = childCount; //break loop
				}
			}
		}
	}

	Element::ProcessEvent(event);
}
예제 #2
0
// Sets the specifed tab index's tab panel RML.
void ElementTabSet::SetPanel(int tab_index, const Rocket::Core::String& rml)
{
	Core::Element* element = Core::Factory::InstanceElement(NULL, "*", "panel", Rocket::Core::XMLAttributes());
	Core::Factory::InstanceElementText(element, rml);
	SetPanel(tab_index, element);
	element->RemoveReference();
}
예제 #3
0
void ElementDataGrid::ProcessEvent(Core::Event& event)
{
	Core::Element::ProcessEvent(event);

	if (event == "columnadd")
	{
		if (event.GetTargetElement() == this)
		{
			root->RefreshRows();
			DirtyLayout();
		}
	}
	else if (event == "resize")
	{
		if (event.GetTargetElement() == this)
		{
			SetScrollTop(GetScrollHeight() - GetClientHeight());

			for (int i = 0; i < header->GetNumChildren(); i++)
			{
				Core::Element* child = header->GetChild(i);
				columns[i].current_width = child->GetBox().GetSize(Core::Box::MARGIN).x;
			}
		}
	}
}
void ElementDataGridExpandButton::ProcessEvent(Core::Event& event)
{
	Core::Element::ProcessEvent(event);

	if (event == "click" && event.GetCurrentElement() == this)
	{
		// Look for the first data grid row above us, and toggle their on/off
		// state.
		Core::Element* parent = GetParentNode();
		ElementDataGridRow* parent_row;
		do
		{
			parent_row = dynamic_cast< ElementDataGridRow* >(parent);
			parent = parent->GetParentNode();
		}
		while (parent && !parent_row);

		if (parent_row)
		{
			parent_row->ToggleRow();

			if (parent_row->IsRowExpanded())
			{
				SetClass("collapsed", false);
				SetClass("expanded", true);
			}
			else
			{
				SetClass("collapsed", true);
				SetClass("expanded", false);
			}
		}
	}
}
void ElementDataGrid::ProcessEvent(Core::Event& event)
{
	Core::Element::ProcessEvent(event);

	if (event == "columnadd")
	{
		if (event.GetTargetElement() == this)
		{
			root->RefreshRows();
			DirtyLayout();
		}
	}
	else if (event == "resize")
	{
		if (event.GetTargetElement() == this)
		{
			// commented this out because this bugs selection on overflowed 
			// datagrids contained within another overflowed element
			//SetScrollTop(GetScrollHeight() - GetClientHeight());

			for (int i = 0; i < header->GetNumChildren(); i++)
			{
				Core::Element* child = header->GetChild(i);
				columns[i].current_width = child->GetBox().GetSize(Core::Box::MARGIN).x;
			}
		}
	}
}
예제 #6
0
// Pops all other radio buttons in our form that share our name.
void InputTypeRadio::PopRadioSet()
{
	// Uncheck all other radio buttons with our name in the form.
	ElementForm* form = NULL;
	Core::Element* parent = element->GetParentNode();
	while (parent != NULL &&
		   (form = dynamic_cast< ElementForm* >(parent)) == NULL)
	   parent = parent->GetParentNode();

	if (form != NULL)
	{
		Core::ElementList form_controls;
		Core::ElementUtilities::GetElementsByTagName(form_controls, form, "input");

		for (size_t i = 0; i < form_controls.size(); ++i)
		{
			ElementFormControlInput* radio_control = dynamic_cast< ElementFormControlInput* >(form_controls[i]);
			if (radio_control != NULL &&
				element != radio_control &&
				radio_control->GetAttribute< Rocket::Core::String >("type", "text") == "radio" &&
				radio_control->GetName() == element->GetName())
			{
				radio_control->RemoveAttribute("checked");
			}
		}
	}
}
예제 #7
0
// Set the specifed tab index's title element.
void ElementTabSet::SetTab(int tab_index, Core::Element* element)
{
	Core::Element* tabs = GetChildByTag("tabs");
	if (tab_index >= 0 &&
		tab_index < tabs->GetNumChildren())
		tabs->ReplaceChild(GetChild(tab_index), element);
	else
		tabs->AppendChild(element);
}
Core::Element* XMLNodeHandlerDataGrid::ElementStart(Core::XMLParser* parser, const Rocket::Core::String& name, const Rocket::Core::XMLAttributes& attributes)
{
	Core::Element* element = NULL;
	Core::Element* parent = parser->GetParseFrame()->element;

	ROCKET_ASSERT(name == "datagrid" ||
			   name == "col");

	if (name == "datagrid")
	{
		// Attempt to instance the grid.
		element = Core::Factory::InstanceElement(parent, name, name, attributes);
		ElementDataGrid* grid = dynamic_cast< ElementDataGrid* >(element);
		if (grid == NULL)
		{
			if (element != NULL)
				element->RemoveReference();

			Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Instancer failed to create data grid for tag %s.", name.CString());
			return NULL;
		}

		// Set the data source and table on the data grid.
		Rocket::Core::String data_source = attributes.Get< Rocket::Core::String >("source", "");
		grid->SetDataSource(data_source);

		parent->AppendChild(grid);
		grid->RemoveReference();

		// Switch to this handler for all columns.
		parser->PushHandler("datagrid");
	}
	else if (name == "col")
	{
		// Make a new node handler to handle the header elements.		
		element = Core::Factory::InstanceElement(parent, "datagridcolumn", "datagridcolumn", attributes);
		if (element == NULL)
			return NULL;

		ElementDataGrid* grid = dynamic_cast< ElementDataGrid* >(parent);
		if (grid != NULL)
		{
			grid->AddColumn(attributes.Get< Rocket::Core::String >("fields", ""), attributes.Get< Rocket::Core::String >("formatter", ""), attributes.Get< float >("width", 0), element);
			element->RemoveReference();
		}

		// Switch to element handler for all children.
		parser->PushDefaultHandler();
	}
	else
	{
		ROCKET_ERROR;
	}

	return element;
}
예제 #9
0
// Set the specified tab index's body element.
void ElementTabSet::SetPanel(int tab_index, Core::Element* element)
{
	// Append the window
	Core::Element* windows = GetChildByTag("panels");
	if (tab_index >= 0 &&
		tab_index < windows->GetNumChildren())
		windows->ReplaceChild(GetChild(tab_index), element);
	else
		windows->AppendChild(element);
}
예제 #10
0
v8::Handle<v8::Value> HTMLDocument::documentElement() {
  Core::Element* result = getRocket();

  while ( result->GetParentNode() )
    result = result->GetParentNode();
  
  v8::HandleScope handle_scope;
  
  return handle_scope.Close(JS::juice::getV8HandleFromRocketWrapper(result, v8::Null()));

}
예제 #11
0
void LoadingScreen::DoAppendText(const std::string& str)
{
  Wait();
  {
    Core::Element* input = root->GetElementById("content");
    Core::String   content;

    input->GetInnerRML(content);
    content = Core::String(content + "<br />" + str.c_str());
    input->SetInnerRML(content);
  }
  Post();
  Refresh();
}
예제 #12
0
Core::Element* ElementTabSet::GetChildByTag(const Rocket::Core::String& tag)
{
	// Look for the existing child
	for (int i = 0; i < GetNumChildren(); i++)
	{
		if (GetChild(i)->GetTagName() == tag)
			return GetChild(i);
	}

	// If it doesn't exist, create it
	Core::Element* element = Core::Factory::InstanceElement(this, "*", tag, Rocket::Core::XMLAttributes());
	AppendChild(element);
	element->RemoveReference();
	return element;
}
void WidgetDropDown::ProcessEvent(Core::Event& event)
{
	// Process the button onclick
	if (event == "click" &&
		!parent_element->IsDisabled())
	{

		if (event.GetCurrentElement()->GetParentNode() == selection_element)
		{
			// Find the element in the options and fire the selection event
			for (size_t i = 0; i < options.size(); i++)
			{
				if (options[i].GetElement() == event.GetCurrentElement())
				{
					if (options[i].IsSelectable())
					{
						SetSelection(i);
						event.StopPropagation();

						ShowSelectBox(false);
						parent_element->Focus();
					}
				}
			}
		}
		else
		{
			// We have to check that this event isn't targeted to an element
			// inside the selection box as we'll get all events coming from our
			// root level select element as well as the ones coming from options (which
			// get caught in the above if)
			Core::Element* element = event.GetTargetElement();
			while (element && element != parent_element)
			{
				if (element == selection_element)
					return;
				element = element->GetParentNode();
			}

			if (selection_element->GetProperty< int >("visibility") == Core::VISIBILITY_HIDDEN)
				ShowSelectBox(true);
			else
				ShowSelectBox(false);
		}		
	}
	else if (event == "blur" && event.GetTargetElement() == parent_element)
		ShowSelectBox(false);
}
예제 #14
0
void LoadingScreen::SetBackground(const string& str)
{
  if (Current)
  {
    Core::Element* element            = Current->root->GetElementById("loading_screen");
    Core::Element* background_defined = Current->root->GetElementById(Core::String("defined-") + str.c_str());

    if (element)
    {
      if (background_defined)
      {
        element->SetClass("default-loading-screen", false);
        element->SetClass(str.c_str(), true);
      }
      else
        element->SetClass("default-loading-screen", true);
    }
  }
}
// Moves all children to be under control of the widget.
void ElementFormControlSelect::OnUpdate()
{
	ElementFormControl::OnUpdate();

	// Move any child elements into the widget (except for the three functional elements).
	for(int child_index = 0;child_index<GetNumChildren();++child_index)
	{
		Core::Element* child = GetChild(child_index);

		// Check for a value attribute.
		Rocket::Core::String attribute_value = child->GetAttribute<Rocket::Core::String>("value", "");

		// Pull the inner RML and add the option.
		Rocket::Core::String rml;
		child->GetInnerRML(rml);
		widget->AddOption(rml, attribute_value, -1, child->GetAttribute("selected") != NULL, child->GetAttribute("unselectable") == NULL);
	}
	
	RemoveAllChildren();
}
예제 #16
0
void UiBase::RecursiveTranslate(Core::Element* root)
{
  unsigned short it;
  Core::Element* child;

  if (!root)
    return ;
  for (it = 0 ; (child = root->GetChild(it)) ; ++it)
  {
    Core::Variant* attr = child->GetAttribute("i18n");

    if (attr)
    {
      string key = attr->Get<Core::String>().CString();

      child->SetInnerRML(i18n::T(key).c_str());
    }
    else
      RecursiveTranslate(child);
  }
}
예제 #17
0
// Checks for necessary functional changes in the control as a result of the event.
void InputTypeSubmit::ProcessEvent(Core::Event& event)
{
	if (event == "click" &&
		!element->IsDisabled())
	{
		Core::Element* parent = element->GetParentNode();
		while (parent)
		{
			ElementForm* form = dynamic_cast< ElementForm* >(parent);
			if (form != NULL)
			{
				form->Submit(element->GetAttribute< Rocket::Core::String >("name", ""), element->GetAttribute< Rocket::Core::String >("value", ""));
				return;
			}
			else
			{
				parent = parent->GetParentNode();
			}
		}
	}
}
예제 #18
0
void ElementTabSet::SetActiveTab(int tab_index)
{
	// Update display if the tab has changed
	if (tab_index != active_tab)
	{
		Core::Element* tabs = GetChildByTag("tabs");
		Core::Element* old_tab = tabs->GetChild(active_tab);
		Core::Element* new_tab = tabs->GetChild(tab_index);

		if (old_tab)
			old_tab->SetPseudoClass("selected", false);
		if (new_tab)
			new_tab->SetPseudoClass("selected", true);

		Core::Element* windows = GetChildByTag("panels");
		Core::Element* old_window = windows->GetChild(active_tab);
		Core::Element* new_window = windows->GetChild(tab_index);

		if (old_window)
			old_window->SetProperty("display", "none");
		if (new_window)
			new_window->SetProperty("display", "inline-block");

		active_tab = tab_index;

		Rocket::Core::Dictionary parameters;
		parameters.Set("tab_index", active_tab);
		DispatchEvent("tabchange", parameters);
	}
}
예제 #19
0
// Adds a new option to the select control.
int WidgetDropDown::AddOption(const Rocket::Core::String& rml, const Rocket::Core::String& value, int before, bool select, bool selectable)
{
	// Instance a new element for the option.
	Core::Element* element = Core::Factory::InstanceElement(selection_element, "*", "option", Rocket::Core::XMLAttributes());

	// Force to block display and inject the RML. Register a click handler so we can be notified of selection.
	element->SetProperty("display", "block");
	element->SetProperty("clip", "auto");
	element->SetInnerRML(rml);
	element->AddEventListener("click", this);

	int option_index;
	if (before < 0 ||
		before >= (int) options.size())
	{
		selection_element->AppendChild(element);
		options.push_back(SelectOption(element, value, selectable));
		option_index = (int) options.size() - 1;
	}
	else
	{
		selection_element->InsertBefore(element, selection_element->GetChild(before));
		options.insert(options.begin() + before, SelectOption(element, value, selectable));
		option_index = before;
	}

	element->RemoveReference();

	// Select the option if appropriate.
	if (select)
		SetSelection(option_index);

	box_layout_dirty = true;
	return option_index;
}
예제 #20
0
// Process the incoming event.
void ElementTabSet::ProcessEvent(Core::Event& event)
{
	Core::Element::ProcessEvent(event);

	if (event.GetCurrentElement() == this && event == "click")
	{
		// Find the tab that this click occured on
		Core::Element* tabs = GetChildByTag("tabs");
		Core::Element* tab = event.GetTargetElement();
		while (tab && tab != this && tab->GetParentNode() != tabs)
			tab = tab->GetParentNode();

		// Abort if we couldn't find the tab the click occured on
		if (!tab || tab == this)
			return;

		// Determine the new active tab index
		int new_active_tab = active_tab;
		for (int i = 0; i < tabs->GetNumChildren(); i++)
		{
			if (tabs->GetChild(i) == tab)
			{
				new_active_tab = i;
				break;
			}
		}

		SetActiveTab(new_active_tab);
	}
}
예제 #21
0
// Remove one of the tab set's panels and its corresponding tab.
void ElementTabSet::RemoveTab(int tab_index)
{
	if (tab_index < 0)
		return;

	Core::Element* panels = GetChildByTag("panels");
	Core::Element* tabs = GetChildByTag("tabs");

	if (panels->GetNumChildren() > tab_index &&
		tabs->GetNumChildren() > tab_index)
	{
		panels->RemoveChild(panels->GetChild(tab_index));
		tabs->RemoveChild(tabs->GetChild(tab_index));
	}
}
예제 #22
0
// Renders any debug elements in the debug context.
void Plugin::Render()
{
	// Render the outlines of the debug context's elements.
	if (render_outlines &&
		debug_context != NULL)
	{
		for (int i = 0; i < debug_context->GetNumDocuments(); ++i)
		{
			Core::ElementDocument* document = debug_context->GetDocument(i);
			if (document->GetId().Find("rkt-debug-") == 0)
				continue;

			std::stack< Core::Element* > element_stack;
			element_stack.push(document);

			while (!element_stack.empty())
			{
				Core::Element* element = element_stack.top();
				element_stack.pop();
				if (element->IsVisible())
				{
					for (int j = 0; j < element->GetNumBoxes(); ++j)
					{
						const Core::Box& box = element->GetBox(j);
						Geometry::RenderOutline(element->GetAbsoluteOffset(Core::Box::BORDER) + box.GetPosition(Core::Box::BORDER), box.GetSize(Core::Box::BORDER), Core::Colourb(255, 0, 0, 128), 1);
					}

					for (int j = 0; j < element->GetNumChildren(); ++j)
						element_stack.push(element->GetChild(j));
				}
			}
		}
	}

	// Render the info element's boxes.
	if (info_element != NULL &&
		info_element->IsVisible())
	{
		info_element->RenderHoverElement();
		info_element->RenderSourceElement();
	}
}
Core::Element* XMLNodeHandlerTabSet::ElementStart(Core::XMLParser* parser, const Rocket::Core::String& name, const Rocket::Core::XMLAttributes& attributes)
{
	ROCKET_ASSERT(name == "tabset" ||
			   name == "tabs" ||
			   name == "tab" ||
			   name == "panels" ||
			   name == "panel");

	if (name == "tabset")
	{
		// Call this node handler for all children
		parser->PushHandler("tabset");

		// Attempt to instance the tabset
		Core::Element* element = Core::Factory::InstanceElement(parser->GetParseFrame()->element, name, name, attributes);		
		ElementTabSet* tabset = rocket_dynamic_cast< ElementTabSet* >(element);
		if (!tabset)
		{
			if (element)
				element->RemoveReference();
			Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Instancer failed to create element for tag %s.", name.CString());
			return NULL;
		}

		// Add the TabSet into the document
		parser->GetParseFrame()->element->AppendChild(element);
		element->RemoveReference();

		return element;
	}	
	else if (name == "tab")
	{
		// Call default element handler for all children.
		parser->PushDefaultHandler();

		Core::Element* tab_element = Core::Factory::InstanceElement(parser->GetParseFrame()->element, "*", "tab", attributes);

		ElementTabSet* tabset = rocket_dynamic_cast< ElementTabSet* >(parser->GetParseFrame()->element);
		if (tabset)
		{
			tabset->SetTab(-1, tab_element);
			tab_element->RemoveReference();
		}

		return tab_element;

	}
	else if (name == "panel")
	{
		// Call default element handler for all children.
		parser->PushDefaultHandler();

		Core::Element* panel_element = Core::Factory::InstanceElement(parser->GetParseFrame()->element, "*", "panel", attributes);

		ElementTabSet* tabset = rocket_dynamic_cast< ElementTabSet* >(parser->GetParseFrame()->element);
		if (tabset)
		{
			tabset->SetPanel(-1, panel_element);
			panel_element->RemoveReference();
		}

		return panel_element;
	}
	else if (name == "tabs" || name == "panels")
	{	
		// Use the element handler to add the tabs and panels elements to the the tabset (this allows users to
		// style them nicely), but don't return the new element, as we still want the tabset to be the top of the
		// parser's node stack.

		Core::Element* parent = parser->GetParseFrame()->element;

		// Attempt to instance the element with the instancer.
		Core::Element* element = Core::Factory::InstanceElement(parent, name, name, attributes);
		if (!element)
		{
			Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Instancer failed to create element for tag %s.", name.CString());
			return NULL;
		}

		// Add the element to its parent and remove the initial reference.
		parent->AppendChild(element);
		element->RemoveReference();
	}

	return NULL;
}
예제 #24
0
void ElementInfo::ProcessEvent(Core::Event& event)
{
	Core::ElementDocument::ProcessEvent(event);

	// Only process events if we're visible
	if (IsVisible())
	{
		if (event == "click")
		{
			Core::Element* target_element = event.GetTargetElement();

			// Deal with clicks on our own elements differently.
			if (target_element->GetOwnerDocument() == this)
			{
				// If it's a pane title, then we need to toggle the visibility of its sibling (the contents pane underneath it).
				if (target_element->GetTagName() == "h2")
				{
					Core::Element* panel = target_element->GetNextSibling();
					if (panel->IsVisible())
						panel->SetProperty("display", "none");
					else
						panel->SetProperty("display", "block");
					event.StopPropagation();
				}
				else if (event.GetTargetElement()->GetId() == "close_button")
				{
					if (IsVisible())
						SetProperty("visibility", "hidden");
				}
				// Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
				else
				{
					int element_index;
					if (sscanf(target_element->GetId().CString(), "a %d", &element_index) == 1)
					{
						Core::Element* new_source_element = source_element;
						for (int i = 0; i < element_index; i++)
						{
							if (new_source_element != NULL)
								new_source_element = new_source_element->GetParentNode();
						}
						SetSourceElement(new_source_element);
					}
					else if (sscanf(target_element->GetId().CString(), "c %d", &element_index) == 1)
					{
						if (source_element != NULL)
							SetSourceElement(source_element->GetChild(element_index));
					}
					event.StopPropagation();
				}
			}
			// Otherwise we just want to focus on the clicked element (unless it's on a debug element)
			else if (target_element->GetOwnerDocument() != NULL && !IsDebuggerElement(target_element))
			{
				Core::Element* new_source_element = target_element;
				if (new_source_element != source_element)
				{
					SetSourceElement(new_source_element);
					event.StopPropagation();
				}
			}
		}
		else if (event == "mouseover")
		{
			Core::Element* target_element = event.GetTargetElement();

			// Deal with clicks on our own elements differently.
			Core::ElementDocument* owner_document = target_element->GetOwnerDocument();
			if (owner_document == this)
			{
				// Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
				int element_index;
				if (sscanf(target_element->GetId().CString(), "a %d", &element_index) == 1)
				{
					hover_element = source_element;
					for (int i = 0; i < element_index; i++)
					{
						if (hover_element != NULL)
							hover_element = hover_element->GetParentNode();
					}
				}
				else if (sscanf(target_element->GetId().CString(), "c %d", &element_index) == 1)
				{
					if (source_element != NULL)
						hover_element = source_element->GetChild(element_index);
				}
			}
			// Otherwise we just want to focus on the clicked element (unless it's on a debug element)
			else if (owner_document != NULL && owner_document->GetId().Find("rkt-debug-") != 0)
			{
				hover_element = target_element;
			}
		}
	}
}
예제 #25
0
void WidgetDropDown::ProcessEvent(Core::Event& event)
{
	if (parent_element->IsDisabled()) 
		return;

	// Process the button onclick
	if (event == "click")
	{

		if (event.GetCurrentElement()->GetParentNode() == selection_element)
		{
			// Find the element in the options and fire the selection event
			for (size_t i = 0; i < options.size(); i++)
			{
				if (options[i].GetElement() == event.GetCurrentElement())
				{
					if (options[i].IsSelectable())
					{
						SetSelection(i);
						event.StopPropagation();

						ShowSelectBox(false);
						parent_element->Focus();
					}
				}
			}
		}
		else
		{
			// We have to check that this event isn't targeted to an element
			// inside the selection box as we'll get all events coming from our
			// root level select element as well as the ones coming from options (which
			// get caught in the above if)
			Core::Element* element = event.GetTargetElement();
			while (element && element != parent_element)
			{
				if (element == selection_element)
					return;
				element = element->GetParentNode();
			}

			if (selection_element->GetProperty< int >("visibility") == Core::VISIBILITY_HIDDEN)
				ShowSelectBox(true);
			else
				ShowSelectBox(false);
		}		
	}
	else if (event == "blur" && event.GetTargetElement() == parent_element)
	{
		ShowSelectBox(false);
	}
	else if (event == "keydown")
	{
		Core::Input::KeyIdentifier key_identifier = (Core::Input::KeyIdentifier) event.GetParameter< int >("key_identifier", 0);

		switch (key_identifier)
		{
			case Core::Input::KI_UP:
				SetSelection( (selected_option - 1 + options.size()) % options.size() );
				break;
			case Core::Input::KI_DOWN:		
				SetSelection( (selected_option + 1) % options.size() );
				break;
			default:
				break;
		}
	}

	if (event.GetTargetElement() == parent_element)
	{
		if (event == "focus")
		{
			value_element->SetPseudoClass("focus", true);
			button_element->SetPseudoClass("focus", true);
		}
		else if (event == "blur")
		{
			value_element->SetPseudoClass("focus", false);
			button_element->SetPseudoClass("focus", false);
		}
	}

}
예제 #26
0
void ElementInfo::UpdateSourceElement()
{
	// Set the title:
	Core::Element* title_content = GetElementById("title-content");
	if (title_content != NULL)
	{
		if (source_element != NULL)
			title_content->SetInnerRML(source_element->GetTagName());
		else
			title_content->SetInnerRML("Element Information");
	}

	// Set the attributes:
	Core::Element* attributes_content = GetElementById("attributes-content");
	if (attributes_content)
	{
		int index = 0;
		Core::String name;
		Core::String value;
		Core::String attributes;

		if (source_element != NULL)
		{
			while (source_element->IterateAttributes(index, name, value))
				attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
		}

		if (attributes.Empty())
		{
			while (attributes_content->HasChildNodes())
				attributes_content->RemoveChild(attributes_content->GetChild(0));
		}
		else
			attributes_content->SetInnerRML(attributes);
	}

	// Set the properties:
	Core::Element* properties_content = GetElementById("properties-content");
	if (properties_content)
	{
		Core::String properties;
		if (source_element != NULL)
			BuildElementPropertiesRML(properties, source_element, source_element);

		if (properties.Empty())
		{
			while (properties_content->HasChildNodes())
				properties_content->RemoveChild(properties_content->GetChild(0));
		}
		else
			properties_content->SetInnerRML(properties);
	}

	// Set the position:
	Core::Element* position_content = GetElementById("position-content");
	if (position_content)
	{
		// left, top, width, height.
		if (source_element != NULL)
		{
			Core::Vector2f element_offset = source_element->GetRelativeOffset(Core::Box::BORDER);
			Core::Vector2f element_size = source_element->GetBox().GetSize(Core::Box::BORDER);

			Core::String positions;
			positions.Append(Core::String(64, "left: <em>%.0fpx</em><br />", element_offset.x));
			positions.Append(Core::String(64, "top: <em>%.0fpx</em><br />", element_offset.y));
			positions.Append(Core::String(64, "width: <em>%.0fpx</em><br />", element_size.x));
			positions.Append(Core::String(64, "height: <em>%.0fpx</em><br />", element_size.y));

			position_content->SetInnerRML(positions);
		}
		else
		{
			while (position_content->HasChildNodes())
				position_content->RemoveChild(position_content->GetFirstChild());
		}
	}

	// Set the ancestors:
	Core::Element* ancestors_content = GetElementById("ancestors-content");
	if (ancestors_content)
	{
		Core::String ancestors;
		Core::Element* element_ancestor = NULL;
		if (source_element != NULL)
			element_ancestor = source_element->GetParentNode();

		int ancestor_depth = 1;
		while (element_ancestor)
		{
			Core::String ancestor_name = element_ancestor->GetTagName();
			const Core::String ancestor_id = element_ancestor->GetId();
			if (!ancestor_id.Empty())
			{
				ancestor_name += "#";
				ancestor_name += ancestor_id;
			}

			ancestors.Append(Core::String(ancestor_name.Length() + 32, "<p id=\"a %d\">%s</p>", ancestor_depth, ancestor_name.CString()));
			element_ancestor = element_ancestor->GetParentNode();
			ancestor_depth++;
		}

		if (ancestors.Empty())
		{
			while (ancestors_content->HasChildNodes())
				ancestors_content->RemoveChild(ancestors_content->GetFirstChild());
		}
		else
			ancestors_content->SetInnerRML(ancestors);
	}

	// Set the children:
	Core::Element* children_content = GetElementById("children-content");
	if (children_content)
	{
		Core::String children;
		if (source_element != NULL)
		{
			for (int i = 0; i < source_element->GetNumChildren(); i++)
			{
				Core::Element* child = source_element->GetChild(i);

				// If this is a debugger document, do not show it.
				if (IsDebuggerElement(child))
					continue;

				Core::String child_name = child->GetTagName();
				const Core::String child_id = child->GetId();
				if (!child_id.Empty())
				{
					child_name += "#";
					child_name += child_id;
				}

				children.Append(Core::String(child_name.Length() + 32, "<p id=\"c %d\">%s</p>", i, child_name.CString()));
			}
		}

		if (children.Empty())
		{
			while (children_content->HasChildNodes())
				children_content->RemoveChild(children_content->GetChild(0));
		}
		else
			children_content->SetInnerRML(children);
	}
}
예제 #27
0
// Adds the cell contents, and marks the row as loaded.
void ElementDataGridRow::Load(const DataQuery& row_information)
{
	// Check for a data source. If they're both set then we set
	// ourselves up with it.
	if (row_information.IsFieldSet(DataSource::CHILD_SOURCE))
	{
		Rocket::Core::String data_source = row_information.Get< Rocket::Core::String >(DataSource::CHILD_SOURCE, "");
		if (!data_source.Empty())
		{
			SetDataSource(data_source);
		}
		else
		{
			// If we've no data source, then we should remove any children.
			RemoveChildren();
		}
	}

	// Now load our cells.
	for (int i = 0; i < parent_grid->GetNumColumns(); i++)
	{
		Core::Element* cell = GetChild(i);

		if (cell)
		{
			// Fetch the column:
			const ElementDataGrid::Column* column = parent_grid->GetColumn(i);

			// Now we use the column's formatter to process the raw data into the
			// XML string, and parse that into the actual Core::Elements. If there is
			// no formatter, then we just send through the raw text, in CVS form.
			Rocket::Core::StringList raw_data;
			for (size_t i = 0; i < column->fields.size(); i++)
			{
				if (column->fields[i] == DataSource::DEPTH)
				{
					raw_data.push_back(Rocket::Core::String(8, "%d", depth));
				}
				else if (column->fields[i] == DataSource::NUM_CHILDREN)
				{
					raw_data.push_back(Rocket::Core::String(8, "%d", children.size()));
				}
				else
				{
					raw_data.push_back(row_information.Get< Rocket::Core::String >(column->fields[i], ""));
				}
			}

			Rocket::Core::String cell_string;
			if (column->formatter)
			{
				column->formatter->FormatData(cell_string, raw_data);
			}
			else
			{
				for (size_t i = 0; i < raw_data.size(); i++)
				{
					if (i > 0)
					{
						cell_string.Append(",");
					}
					cell_string.Append(raw_data[i]);
				}
			}

			// Remove all the cell's current contents.
			while (cell->GetNumChildren(true) > 0)
			{
				cell->RemoveChild(cell->GetChild(0));
			}

			// Add the new contents to the cell.
			Core::Factory::InstanceElementText(cell, cell_string);
		}
		else
		{
			ROCKET_ERROR;
		}
	}

	dirty_cells = false;
}