コード例 #1
0
ファイル: menu.cpp プロジェクト: Arnaud474/Warmux
void Menu::LoadWidget(Profile * profile,
                      const xmlNode * rootMenuNode,
                      WidgetList * container)
{
  XmlReader * xmlFile = profile->GetXMLDocument();
  uint widgetCount = xmlFile->GetNbChildren(rootMenuNode);
  const xmlNode * currentNode = xmlFile->GetFirstChild(rootMenuNode);
  std::string currentNodeName;

  // For each sub-node ...
  for ( ; widgetCount > 0; --widgetCount) {

    currentNodeName = xmlFile->GetNodeName(currentNode);
    Widget * newWidget = CreateWidget(profile, currentNode, currentNodeName);

    if (newWidget) {
      if ("GridBox" == currentNodeName ||
          "HorizontalBox" == currentNodeName ||
          "VerticalBox" == currentNodeName) {
        LoadWidget(profile, currentNode, (WidgetList*)newWidget);
      }
      container->AddWidget(newWidget);
    }
    currentNode = xmlFile->GetNextSibling(currentNode);
  }

  if (container) {
    container->Pack();
  }
}
コード例 #2
0
ファイル: UISystem.cpp プロジェクト: 2bitdreamer/SD6_Engine
void UISystem::AddWidgetInParent(GroupWidget* parent, const TiXmlNode* data) {
	const char* widgetType = data->ToElement()->Value();
	const char* styleName = data->ToElement()->Attribute("style");

	if (!styleName)
		styleName = "Default";

	//Construct the basic styled widget. No properties will be applied
	WidgetBase* wb = CreateWidget(widgetType, data);

	//Apply the general (All state) style level properties
	wb->ApplyGeneralStyleToAll(s_styles[styleName][widgetType]);
	//Apply the general (All state) widget level properties
	WidgetStyle style = WidgetStyle(data);
	wb->ApplyGeneralStyleToAll(&style);
	//Apply the state specific style level properties
	wb->ApplyStyle(s_styles[styleName][widgetType]);
	//Apply the state specific widget level properties
	wb->ApplyStyle(&style);

	const char* widgetName = data->ToElement()->Attribute("name");
	std::string nameAsString;
	if (widgetName) {
		nameAsString = std::string(widgetName);
		wb->AddPropertyForState("name", UI_STATE_ALL, nameAsString);
	}
	else {
		wb->GetPropertyForCurrentState("name", nameAsString);
	}

	wb->m_parentWidget = parent;
	parent->m_children.push_back(wb);

	s_widgets[nameAsString] = wb;
}
コード例 #3
0
void KinotifyWidget::PrepareNotification ()
{
    CreateWidget ();
    DefaultSize_ = SetData ();
    SetWidgetPlace ();
    ShowNotification ();
}
コード例 #4
0
ファイル: pawsmanager.cpp プロジェクト: garinh/planeshift
pawsWidget * PawsManager::LoadWidget(iDocumentNode *widgetNode )
{
    pawsWidget * widget;
    csString factory;

    if ( strcmp( widgetNode->GetValue(), "widget" ) == 0 )   // old syntax is <widget factory="bla"....>
        factory = widgetNode->GetAttributeValue( "factory" );
    else
        factory = widgetNode->GetValue();   // new syntax is using factory name as tag name directly: <pawsChatWindow ....>

    if ( factory.Length() == 0 )
    {
        Error1("Could not read factory from XML node. Error in XML");
        return NULL;
    }

    widget = CreateWidget( factory );
    if ( !widget )
    {
        Error2( "Failed to create widget %s", factory.GetData() );
        return NULL;
    }

    if (!widget->Load(widgetNode))
    {
        Error3("Widget %s failed to load %s", widget->GetName(), factory.GetData() );
        delete widget;
        return NULL;
    }

    return widget;
}
コード例 #5
0
ファイル: titlebar.cpp プロジェクト: devbian/qt_simu360
TitleBar::TitleBar(QWidget *parent) :
    QWidget(parent)
{
    this->setFixedHeight(32);
    CreateWidget();
    CreateLayout();
    SetWidgetStyle();
    m_bLeftButtonPressed = false;
}
コード例 #6
0
Wt::WContainerWidget* WidgetsCommon::GetWidget()
{
	if (!m_widget)
	{
		m_widget = CreateWidget();
	}

	return m_widget;
}
コード例 #7
0
ribi::QtDasWahreSchlagerfestCanvas::QtDasWahreSchlagerfestCanvas(
  const int width, const int height)
  : QtCanvas(CreateCanvas(width,height)),
    m_widget(CreateWidget(width,height))
{
  m_widget->m_signal_changed.connect(
    boost::bind(&ribi::QtDasWahreSchlagerfestCanvas::OnChanged,this));

  OnChanged();
}
コード例 #8
0
ファイル: WidgetStyleCache.cpp プロジェクト: emilio/gecko-dev
GtkWidget*
GetWidget(WidgetNodeType aWidgetType)
{
  GtkWidget* widget = sWidgetStorage[aWidgetType];
  if (!widget) {
    widget = CreateWidget(aWidgetType);
    sWidgetStorage[aWidgetType] = widget;
  }
  return widget;
}
コード例 #9
0
NS_IMETHODIMP nsScrollPortView::CreateScrollControls(nsNativeWidget aNative)
{
  nsWidgetInitData  initData;
  initData.clipChildren = PR_TRUE;
  initData.clipSiblings = PR_TRUE;

  CreateWidget(kWidgetCID, &initData,
               mWindow ? nsnull : aNative);
  
  return NS_OK;
}
コード例 #10
0
ezQtPropertyContainerWidget::Element& ezQtPropertyContainerWidget::AddElement(ezUInt32 index)
{
  ezQtGroupBoxBase* pSubGroup = CreateElement(m_pGroup);
  pSubGroup->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
  connect(pSubGroup, &ezQtGroupBoxBase::CollapseStateChanged, m_pGrid, &ezQtPropertyGridWidget::OnCollapseStateChanged);
  connect(pSubGroup, &QWidget::customContextMenuRequested, this, &ezQtPropertyContainerWidget::OnCustomElementContextMenu);

  QVBoxLayout* pSubLayout = new QVBoxLayout(nullptr);
  pSubLayout->setContentsMargins(5, 0, 0, 0);
  pSubLayout->setSpacing(1);
  pSubGroup->GetContent()->setLayout(pSubLayout);

  m_pGroupLayout->insertWidget((int)index, pSubGroup);

  ezQtPropertyWidget* pNewWidget = CreateWidget(index);

  pNewWidget->setParent(pSubGroup);
  pSubLayout->addWidget(pNewWidget);

  pNewWidget->Init(m_pGrid, m_pObjectAccessor, m_pType, m_pProp);

  {
    // Add Buttons
    auto pAttr = m_pProp->GetAttributeByType<ezContainerAttribute>();
    if ((!pAttr || pAttr->CanMove()) && m_pProp->GetCategory() != ezPropertyCategory::Map)
    {
      // Do we need move buttons at all if we have drag&drop?
      // ezQtElementGroupButton* pUpButton = new ezQtElementGroupButton(pSubGroup->GetHeader(),
      // ezQtElementGroupButton::ElementAction::MoveElementUp, pNewWidget);  pSubGroup->GetHeader()->layout()->addWidget(pUpButton);
      // connect(pUpButton, &QToolButton::clicked, this, &ezQtPropertyContainerWidget::OnElementButtonClicked);

      // ezQtElementGroupButton* pDownButton = new ezQtElementGroupButton(pSubGroup->GetHeader(),
      // ezQtElementGroupButton::ElementAction::MoveElementDown, pNewWidget);  pSubGroup->GetHeader()->layout()->addWidget(pDownButton);
      // connect(pDownButton, &QToolButton::clicked, this, &ezQtPropertyContainerWidget::OnElementButtonClicked);

      pSubGroup->SetDraggable(true);
      connect(pSubGroup, &ezQtGroupBoxBase::DragStarted, this, &ezQtPropertyContainerWidget::OnDragStarted);
    }

    if (!pAttr || pAttr->CanDelete())
    {
      ezQtElementGroupButton* pDeleteButton =
          new ezQtElementGroupButton(pSubGroup->GetHeader(), ezQtElementGroupButton::ElementAction::DeleteElement, pNewWidget);
      pSubGroup->GetHeader()->layout()->addWidget(pDeleteButton);
      connect(pDeleteButton, &QToolButton::clicked, this, &ezQtPropertyContainerWidget::OnElementButtonClicked);
    }
  }

  m_Elements.Insert(Element(pSubGroup, pNewWidget), index);
  return m_Elements[index];
}
コード例 #11
0
void ToyGrid::SetGridSize(const QSize &gridSize)
{
	QSize gs(gridSize);
	if(gs.width() < 1)
		gs.setWidth(1);
	if(gs.height() < 1)
		gs.setHeight(1);
	
	if(m_GridSize != gs)
	{
		QSize widgetSize(0, 0);
		if( !m_List.empty() )
			widgetSize = m_List.front()->size();
		
		m_GridSize = gs;
		
		size_t numWidgets = static_cast<size_t>(m_GridSize.width() * m_GridSize.height());
		
		// remove excess
		while(m_List.size() > numWidgets)
		{
			m_List.back()->deleteLater();
			m_List.pop_back();
		}
		
		// add new
		while(m_List.size() < numWidgets)
		{
			ToyWidget *widget = CreateWidget();
			if( widget )
			{
				m_List.push_back(widget);
				ApplyDefaultSettings(widget, m_List.size());
				widget->SetMode(m_Mode);
				
				if( !m_Loading )
					widget->show();
				
				connect(widget, SIGNAL(edit(ToyWidget*)), this, SLOT(onWidgetEdited(ToyWidget*)));
			}
			else
				break;
		}
コード例 #12
0
ファイル: verbal.c プロジェクト: webushka/reduce
HistList *CreateNewVerbal()
{
  Arg       arg[12];
  int       i;
  HistList *verbal;

  verbal             = (HistList *)XtMalloc(sizeof(HistList));
  verbal->next       = NULL;
  verbal->nLines     = 0;
  verbal->histNo     = reduceHistoryNumber;
  verbal->flavour    = ReduceVerbal;
  verbal->height     = verbalHeight;
  verbal->managed    = InitiallyManaged();
  verbal->usedOnLine = 0;	/* usedOnLine holds the number of chars */
  verbal->textLength = 0;

  i = 0; XtSetArg(arg[i], XtNstring,          "");               i++;
         XtSetArg(arg[i], XtNwidth,           maxWidth);         i++;
         XtSetArg(arg[i], XtNborderWidth,     0);                i++;
         XtSetArg(arg[i], XtNdisplayCaret,    False);            i++;
         XtSetArg(arg[i], XtNtopMargin,       0);                i++;
         XtSetArg(arg[i], XtNbottomMargin,    0);                i++;
         XtSetArg(arg[i], XtNresizable,       True);             i++;
         XtSetArg(arg[i], XtNheight,          verbalHeight);     i++;
         XtSetArg(arg[i], XtNwrap,            XawtextWrapNever); i++;
  if (verbalVerbatim) {
         XtSetArg(arg[i], XtNfont,            helpXmplFont);     i++;
       } else {
         XtSetArg(arg[i], XtNfont,            verbalFont);       i++;
       }
  if (endOfHistory) {
         XtSetArg(arg[i], XtNfromVert,    endOfHistory->widget); i++;
       }

  verbal->widget = CreateWidget("historyVerbal",
				asciiTextWidgetClass,
				outputHistory,
				arg, (Cardinal)i);
  return verbal;
}
コード例 #13
0
ribi::maziak::QtMaziakCanvas::QtMaziakCanvas(
  const int size)
  : QtCanvas(CreateCanvas(size,size)),
    m_dialog(CreateWidget(size)),
    m_text_canvas{},
    m_timer_enemy(new QTimer),
    m_timer_press_key(new QTimer),
    m_timer_show_solution(new QTimer),
    m_view_height(9),
    m_view_width(9)
{
  m_text_canvas = boost::dynamic_pointer_cast<TextCanvas>(this->GetCanvas());
  assert(m_text_canvas);

  m_dialog->m_signal_game_over.connect(
    boost::bind(&ribi::maziak::QtMaziakCanvas::OnGameOver,this)
  );
  m_dialog->m_signal_game_won.connect(
    boost::bind(&ribi::maziak::QtMaziakCanvas::OnGameWon,this)
  );
  m_dialog->m_signal_start_showing_solution.connect(
    boost::bind(&ribi::maziak::QtMaziakCanvas::OnTimerStartShowingSolution,this)
  );

  m_timer_press_key->setInterval(100);
  m_timer_enemy->setInterval(1000);
  m_timer_show_solution->setInterval(5000);

  QObject::connect(m_timer_press_key.get(),&QTimer::timeout,
    this,&ribi::maziak::QtMaziakCanvas::OnTimerPressKey);
  QObject::connect(m_timer_enemy.get(),&QTimer::timeout,
    this,&ribi::maziak::QtMaziakCanvas::OnTimerEnemy);
  QObject::connect(m_timer_show_solution.get(),&QTimer::timeout,
    this,&ribi::maziak::QtMaziakCanvas::OnTimerStopShowingSolution);

  m_timer_press_key->start();
  m_timer_enemy->start();

  OnTimerPressKey();
}
コード例 #14
0
ファイル: UISystem.cpp プロジェクト: 2bitdreamer/SD6_Engine
WidgetBase* UISystem::AddStyledWidgetExplicitly(const std::string& widgetType, const std::string& styleName, WidgetStyle& widgetStyle, GroupWidget* parent/*=s_rootWidget*/, std::string widgetName /*= "named"*/) {
	WidgetBase* wb = CreateWidget(widgetType, nullptr);

	WidgetStyle* ws = s_styles[styleName][widgetType];
	wb->ApplyGeneralStyleToAll(ws);
	wb->ApplyGeneralStyleToAll(&widgetStyle);
	wb->ApplyStyle(ws);
	wb->ApplyStyle(&widgetStyle);

	if (widgetName == "named") { //Already has a UUID name from code, get it
		wb->GetPropertyForCurrentState("name", widgetName);
	}
	else { //We're naming it explicitly, so set its name
		wb->AddPropertyForState("name", UI_STATE_ALL, widgetName);
	}

	wb->m_parentWidget = parent;
	parent->m_children.push_back(wb);

	s_widgets[widgetName] = wb;
	return wb;
}
コード例 #15
0
ファイル: TestNavigator.cpp プロジェクト: ChilliWorks/CSTest
        //------------------------------------------------------------------------------
        //------------------------------------------------------------------------------
        void TestNavigator::OnInit() noexcept
        {
            auto resourcePool = CS::Application::Get()->GetResourcePool();
            auto mediumFont = resourcePool->LoadResource<CS::Font>(CS::StorageLocation::k_package, "Fonts/ArialMed.csfont");
            
            auto basicWidgetFactory = CS::Application::Get()->GetSystem<Common::BasicWidgetFactory>();
            m_titleLabel = basicWidgetFactory->CreateLabel(CS::Vector2(0.9f, 0.15f), mediumFont, m_title, CS::AlignmentAnchor::k_topCentre);

            m_backButton = basicWidgetFactory->CreateButton(CS::Vector2(0.0f, 0.1f), "Back", CS::AlignmentAnchor::k_bottomLeft, CS::Colour::k_cornflowerBlue);
            m_backButton->SetRelativePosition(CS::Vector2(0.05f, 0.05f));
            
            auto widgetFactory = CS::Application::Get()->GetWidgetFactory();
            m_ui = widgetFactory->CreateWidget();
            m_ui->AddWidget(m_titleLabel);
            m_ui->AddWidget(m_backButton);
            
            GetState()->GetUICanvas()->AddWidget(m_ui);
            
            m_backPressedConnection = m_backButton->GetReleasedInsideEvent().OpenConnection([](CS::Widget* in_widget, const CS::Pointer& in_pointer, CS::Pointer::InputType in_inputType)
            {
                CS::Application::Get()->GetStateManager()->Pop();
            });
        }
コード例 #16
0
QtPvdbConceptMapDialog::QtPvdbConceptMapDialog(
  const boost::shared_ptr<pvdb::File> file,
  QWidget *parent)
  : QtHideAndShowDialog(parent),
    ui(new Ui::QtPvdbConceptMapDialog),
    m_back_to_menu(false),
    m_file(file),
    m_widget(CreateWidget(file))
{
  ui->setupUi(this);
  #ifndef NDEBUG
  Test();
  assert(m_file);
  assert(m_file->GetConceptMap());
  assert(file == m_file);
  assert(m_widget);
  assert(m_widget->GetConceptMap() == m_file->GetConceptMap());
  assert(this->layout());
  #endif

  
  this->layout()->addWidget(m_widget);

  assert(!Collect<QtPvdbNodeItem>(m_widget->scene()).empty());

  //Center the dialog
  {
    const QRect screen = QApplication::desktop()->screenGeometry();
    this->setGeometry(screen.adjusted(64,64,-64,-64));
    this->move( screen.center() - this->rect().center() );
  }

  m_widget->m_signal_conceptmapitem_requests_edit.connect(
    boost::bind(
      &QtPvdbConceptMapDialog::OnConceptMapItemRequestsEdit,
      this,boost::lambda::_1));
}
コード例 #17
0
			void KinotifyWidget::PrepareNotification ()
			{
				CreateWidget ();
				SetData ();
				ShowNotification ();
			}
コード例 #18
0
ファイル: Gui.cpp プロジェクト: macBdog/game
bool Gui::LoadMenu(const GameFile & a_menuFile, const DataPack * a_dataPack)
{
	// Load the menu file
	Widget * createdMenu = NULL;
	if (a_menuFile.IsLoaded())
	{
		// Create a new widget and copy properties from file
		if (GameFile::Object * menuObject = a_menuFile.FindObject("menu"))
		{
			if (GameFile::Property * nameProp = menuObject->FindProperty("name"))
			{
				createdMenu = new Widget();
				createdMenu->SetName(a_menuFile.GetString("menu", "name"));
				if (a_dataPack == NULL || !a_dataPack->IsLoaded())
				{
					char menuFilePath[StringUtils::s_maxCharsPerLine];
					sprintf(menuFilePath, "%s%s.mnu", m_guiPath, createdMenu->GetName());
					createdMenu->SetFilePath(menuFilePath);
				}
				createdMenu->SetActive(false);

				// TODO Support for non fullscreen menus
				createdMenu->SetSize(Vector2(2.0f, 2.0f));
				createdMenu->SetDrawPos(Vector2(-1.0, 1.0));

				// Load child elements of the menu
				LinkedListNode<GameFile::Object> * childWidget = menuObject->GetChildren();
				while (childWidget != NULL)
				{
					GameFile::Object * curObject = childWidget->GetData();
					Widget * newChild = CreateWidget(curObject, createdMenu);
					// If not specified in the file, align child widgets to the parent menu
					if (!newChild->HasAlignTo())
					{
						newChild->SetAlignTo(createdMenu);
					}
					childWidget = childWidget->GetNext();
				}

				// Add to list of menus
				m_menus.InsertNew(createdMenu);
			}
			else // No properties present
			{
				Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Error loading menu file %s, menu does not have a name property.", a_menuFile);
			}

			// Set the active menu to the last menu with the begin loaded property
			if (createdMenu != NULL && menuObject->FindProperty("beginLoaded"))
			{
				if (menuObject->FindProperty("beginLoaded")->GetBool())
				{
					m_startupMenu = createdMenu;
				}
			}
		}
		else // Unexpected file format, no root element
		{
			Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Error loading menu file %s, no valid menu parent element.", a_menuFile);
		}

		return true;
	}
	return false;
}
コード例 #19
0
ファイル: Gui.cpp プロジェクト: macBdog/game
Widget * Gui::CreateWidget(GameFile::Object * a_widgetFile, Widget * a_parent, bool a_startActive)
{
	// Check for a valid parent
	if (a_parent == NULL) 
	{	
		Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Widget creation from file failed due to an invalid parent.");
		return NULL;
	}

	// Get properties from the file that correspond to widget definitions
	Widget::WidgetDef defFromFile;
	if (GameFile::Property * colour = a_widgetFile->FindProperty("colour"))
	{
		defFromFile.m_colour = colour->GetColour();
	}
	if (GameFile::Property * pos = a_widgetFile->FindProperty("offset"))
	{
		defFromFile.m_pos = pos->GetVector2();
	}
	if (GameFile::Property * size = a_widgetFile->FindProperty("size"))
	{
		defFromFile.m_size = size->GetVector2();
	}
	// Set alignment and anchor
	Alignment align;
	Alignment alignAnchor;
	if (GameFile::Property * alignX = a_widgetFile->FindProperty("alignX"))
	{
		align.SetXFromString(a_widgetFile->FindProperty("alignX")->GetString());
	}
	if (GameFile::Property * alignY = a_widgetFile->FindProperty("alignY"))
	{
		align.SetYFromString(a_widgetFile->FindProperty("alignY")->GetString());
	}
	if (GameFile::Property * alignX = a_widgetFile->FindProperty("alignAnchorX"))
	{
		alignAnchor.SetXFromString(a_widgetFile->FindProperty("alignAnchorX")->GetString());
	}
	if (GameFile::Property * alignY = a_widgetFile->FindProperty("alignAnchorY"))
	{
		alignAnchor.SetYFromString(a_widgetFile->FindProperty("alignAnchorY")->GetString());
	}
	defFromFile.m_pos.SetAlignment(align);
	defFromFile.m_pos.SetAlignmentAnchor(alignAnchor);
	if (GameFile::Property * fontSize = a_widgetFile->FindProperty("fontSize"))
	{
		defFromFile.m_fontSize = fontSize->GetFloat();
	}
	if (GameFile::Property * fontName = a_widgetFile->FindProperty("font"))
	{
		defFromFile.m_fontNameHash = StringHash::GenerateCRC(fontName->GetString());
	}
	else // No font name supplied, use debug
	{
		// Check for a loaded debug font
		if (StringHash * debugFont = FontManager::Get().GetDebugFontName())
		{
			defFromFile.m_fontNameHash = debugFont->GetHash();
		}
	}
	
	// Create the widget
	if (Widget * newWidget = CreateWidget(defFromFile, a_parent, a_startActive))
	{
		// Apply properties not set during creation
		if (GameFile::Property * name = a_widgetFile->FindProperty("name"))
		{
			newWidget->SetName(name->GetString());
		}
		if (GameFile::Property * text = a_widgetFile->FindProperty("text"))
		{
			newWidget->SetText(text->GetString());
		}
		if (GameFile::Property * colour = a_widgetFile->FindProperty("colour"))
		{
			newWidget->SetColour(colour->GetColour());
		}
		if (GameFile::Property * alignTo = a_widgetFile->FindProperty("alignTo"))
		{
			newWidget->SetAlignTo(alignTo->GetString());
		}
		if (GameFile::Property * texture = a_widgetFile->FindProperty("texture"))
		{
			if (Texture * tex = TextureManager::Get().GetTexture(texture->GetString(), TextureCategory::Gui))
			{
				newWidget->SetTexture(tex);
			}
		}
		if (GameFile::Property * action = a_widgetFile->FindProperty("action"))
		{		
			newWidget->SetScriptFuncName(action->GetString());
			newWidget->SetAction(&ScriptManager::Get(), &ScriptManager::OnWidgetAction);
		}
		return newWidget;
	}
	return NULL;
}
コード例 #20
0
void TBWidgetsReader::LoadNodeTree(TBWidget *target, TBNode *node)
{
	// Iterate through all nodes and create widgets
	for (TBNode *child = node->GetFirstChild(); child; child = child->GetNext())
		CreateWidget(target, child, WIDGET_Z_TOP);
}
コード例 #21
0
bool TBWidgetsReader::CreateWidget(TBWidget *target, TBNode *node, WIDGET_Z add_child_z)
{
	CREATE_INFO info = { this, target->GetContentRoot(), node };

	// Find a widget creator from the node name
	TBWidgetFactory *wc = nullptr;
	for (wc = factories.GetFirst(); wc; wc = wc->GetNext())
		if (strcmp(node->GetName(), wc->name) == 0)
			break;

	// Create the widget
	TBWidget *new_widget = wc ? wc->Create(&info) : nullptr;
	if (!new_widget)
		return false;

	// Read generic properties

	SetIDFromNode(new_widget->GetID(), node->GetNode("id"));

	SetIDFromNode(new_widget->GetGroupID(), node->GetNode("group-id"));

	if (wc->sync_type == TBValue::TYPE_FLOAT)
		new_widget->SetValueDouble(node->GetValueFloat("value", 0));
	else
		new_widget->SetValue(node->GetValueInt("value", 0));

	if (TBNode *data_node = node->GetNode("data"))
		new_widget->data.Copy(data_node->GetValue());

	new_widget->SetIsGroupRoot(node->GetValueInt("is-group-root", new_widget->GetIsGroupRoot()) ? true : false);

	new_widget->SetIsFocusable(node->GetValueInt("is-focusable", new_widget->GetIsFocusable()) ? true : false);

	new_widget->SetWantLongClick(node->GetValueInt("want-long-click", new_widget->GetWantLongClick()) ? true : false);

	new_widget->SetIgnoreInput(node->GetValueInt("ignore-input", new_widget->GetIgnoreInput()) ? true : false);

	new_widget->SetOpacity(node->GetValueFloat("opacity", new_widget->GetOpacity()));

	if (const char *text = node->GetValueString("text", nullptr))
		new_widget->SetText(text);

	if (const char *connection = node->GetValueStringRaw("connection", nullptr))
	{
		// If we already have a widget value with this name, just connect to it and the widget will
		// adjust its value to it. Otherwise create a new widget value, and give it the value we
		// got from the resource.
		if (TBWidgetValue *value = g_value_group.GetValue(connection))
			new_widget->Connect(value);
		else if (TBWidgetValue *value = g_value_group.CreateValueIfNeeded(connection, wc->sync_type))
		{
			value->SetFromWidget(new_widget);
			new_widget->Connect(value);
		}
	}
	if (const char *gravity = node->GetValueString("gravity", nullptr))
	{
		WIDGET_GRAVITY g = WIDGET_GRAVITY_NONE;
		if (strstr(gravity, "left"))		g |= WIDGET_GRAVITY_LEFT;
		if (strstr(gravity, "top"))			g |= WIDGET_GRAVITY_TOP;
		if (strstr(gravity, "right"))		g |= WIDGET_GRAVITY_RIGHT;
		if (strstr(gravity, "bottom"))		g |= WIDGET_GRAVITY_BOTTOM;
		if (strstr(gravity, "all"))			g |= WIDGET_GRAVITY_ALL;
		if (!(g & WIDGET_GRAVITY_LEFT_RIGHT))
			g |= WIDGET_GRAVITY_LEFT;
		if (!(g & WIDGET_GRAVITY_TOP_BOTTOM))
			g |= WIDGET_GRAVITY_TOP;
		new_widget->SetGravity(g);
	}
	if (const char *state = node->GetValueString("state", nullptr))
	{
		if (strstr(state, "disabled"))
			new_widget->SetState(WIDGET_STATE_DISABLED, true);
	}
	if (const char *skin = node->GetValueString("skin", nullptr))
	{
		new_widget->SetSkinBg(skin);
	}

	if (TBNode *lp = node->GetNode("lp"))
	{
		LayoutParams layout_params;
		if (new_widget->GetLayoutParams())
			layout_params = *new_widget->GetLayoutParams();
		const TBDimensionConverter *dc = g_tb_skin->GetDimensionConverter();
		if (const char *str = lp->GetValueString("width", nullptr))
			layout_params.SetWidth(dc->GetPxFromString(str, LayoutParams::UNSPECIFIED));
		if (const char *str = lp->GetValueString("height", nullptr))
			layout_params.SetHeight(dc->GetPxFromString(str, LayoutParams::UNSPECIFIED));
		if (const char *str = lp->GetValueString("min-width", nullptr))
			layout_params.min_w = dc->GetPxFromString(str, LayoutParams::UNSPECIFIED);
		if (const char *str = lp->GetValueString("max-width", nullptr))
			layout_params.max_w = dc->GetPxFromString(str, LayoutParams::UNSPECIFIED);
		if (const char *str = lp->GetValueString("pref-width", nullptr))
			layout_params.pref_w = dc->GetPxFromString(str, LayoutParams::UNSPECIFIED);
		if (const char *str = lp->GetValueString("min-height", nullptr))
			layout_params.min_h = dc->GetPxFromString(str, LayoutParams::UNSPECIFIED);
		if (const char *str = lp->GetValueString("max-height", nullptr))
			layout_params.max_h = dc->GetPxFromString(str, LayoutParams::UNSPECIFIED);
		if (const char *str = lp->GetValueString("pref-height", nullptr))
			layout_params.pref_h = dc->GetPxFromString(str, LayoutParams::UNSPECIFIED);
		new_widget->SetLayoutParams(layout_params);
	}

	target->GetContentRoot()->OnInflateChild(new_widget);

	// Add the new widget to the hiearchy
	target->GetContentRoot()->AddChild(new_widget, add_child_z);

	// Read the font now when the widget is in the hiearchy so inheritance works.
	if (TBNode *font = node->GetNode("font"))
	{
		TBFontDescription fd = new_widget->GetCalculatedFontDescription();
		if (const char *size = font->GetValueString("size", nullptr))
		{
			int new_size = g_tb_skin->GetDimensionConverter()->GetPxFromString(size, fd.GetSize());
			fd.SetSize(new_size);
		}
		if (const char *name = font->GetValueString("name", nullptr))
			fd.SetID(name);
		new_widget->SetFontDescription(fd);
	}

	// Iterate through all nodes and create widgets
	for (TBNode *n = node->GetFirstChild(); n; n = n->GetNext())
		CreateWidget(new_widget, n, wc->add_child_z);

	if (node->GetValueInt("autofocus", 0))
		new_widget->SetFocus(WIDGET_FOCUS_REASON_UNKNOWN);

	return true;
}
コード例 #22
0
ファイル: help.c プロジェクト: BackupTheBerlios/dotnedit-svn
/*
** Create a new help window displaying a given subject, "topic"
**
** Important hint: If this widget is restructured or the name of the text
** subwidget is changed don't forget to adapt the default translations of the
** help text. They are located in nedit.c, look for 
**   static char *fallbackResources 
**   (currently:  nedit.helpForm.sw.helpText*translations...)
*/
static Widget createHelpPanel(enum HelpTopic topic)
{
    Arg al[50];
    int ac;
    Widget appShell, btn, closeBtn, form, btnFW;
    Widget sw, hScrollBar, vScrollBar;
    XmString st1;
    char * helpText  = NULL;
    char * styleData = NULL;

    ac = 0;
    XtSetArg(al[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;
    appShell = CreateWidget(TheAppShell, "help",
            topLevelShellWidgetClass, al, ac);
    AddSmallIcon(appShell);
    /* With openmotif 2.1.30, a crash may occur when the text widget of the
       help window is (slowly) resized to a zero width. By imposing a 
       minimum _window_ width, we can work around this problem. The minimum 
       width should be larger than the width of the scrollbar. 50 is probably 
       a safe value; this leaves room for a few characters */
    XtVaSetValues(appShell, XtNminWidth, 50, NULL);
    form = XtVaCreateManagedWidget("helpForm", xmFormWidgetClass, appShell,
            NULL);
    XtVaSetValues(form, XmNshadowThickness, 0, NULL);
    
    /* Create the bottom row of buttons */
    btn = XtVaCreateManagedWidget("find", xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("Find..."),
            XmNmnemonic, 'F',
            XmNbottomAttachment, XmATTACH_FORM,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 3,
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 25,
            NULL);
    XtAddCallback(btn, XmNactivateCallback, searchHelpCB, appShell);
    XmStringFree(st1);

    btn = XtVaCreateManagedWidget("findAgain", xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("Find Again"),
            XmNmnemonic, 'A',
            XmNbottomAttachment, XmATTACH_FORM,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 27,
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 49,
            NULL);
    XtAddCallback(btn, XmNactivateCallback, searchHelpAgainCB, appShell);
    XmStringFree(st1);

    btn = XtVaCreateManagedWidget("print", xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("Print..."),
            XmNmnemonic, 'P',
            XmNbottomAttachment, XmATTACH_FORM,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 51,
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 73,
            NULL);
    XtAddCallback(btn, XmNactivateCallback, printCB, appShell);
    XmStringFree(st1);

    closeBtn = XtVaCreateManagedWidget("close",
            xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("Close"),
            XmNbottomAttachment, XmATTACH_FORM,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 75,
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 97,
            NULL);
    XtAddCallback(closeBtn, XmNactivateCallback, closeCB, appShell);
    XmStringFree(st1);
            
    /* Create the next row of buttons (for navigation) */
    btn = XtVaCreateManagedWidget("prevTopic", xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("<< Browse"),
            XmNmnemonic, 'o', 
            XmNbottomAttachment, XmATTACH_WIDGET,
            XmNbottomWidget, closeBtn,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 51,
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 73,
            NULL);
    XtAddCallback(btn, XmNactivateCallback, prevTopicCB, appShell);
    XmStringFree(st1);

    btn = XtVaCreateManagedWidget("nextTopic", xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("Browse >>"),
            XmNmnemonic, 'e', 
            XmNbottomAttachment, XmATTACH_WIDGET,
            XmNbottomWidget, closeBtn,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 75, 
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 97,
            NULL);
    XtAddCallback(btn, XmNactivateCallback, nextTopicCB, appShell);
    XmStringFree(st1);

    btn = XtVaCreateManagedWidget("histBack", xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("Back"),
            XmNmnemonic, 'B', 
            XmNbottomAttachment, XmATTACH_WIDGET,
            XmNbottomWidget, closeBtn,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 3,
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 25,
            NULL);
    XtAddCallback(btn, XmNactivateCallback, bwHistoryCB, appShell);
    XmStringFree(st1);

    btnFW = XtVaCreateManagedWidget("histForw", xmPushButtonWidgetClass, form,
            XmNlabelString, st1=XmStringCreateSimple("Forward"),
            XmNmnemonic, 'w', 
            XmNbottomAttachment, XmATTACH_WIDGET,
            XmNbottomWidget, closeBtn,
            XmNleftAttachment, XmATTACH_POSITION,
            XmNleftPosition, 27,
            XmNrightAttachment, XmATTACH_POSITION,
            XmNrightPosition, 49,
            NULL);
    XtAddCallback(btnFW, XmNactivateCallback, fwHistoryCB, appShell);
    XmStringFree(st1);
    
    /* Create a text widget inside of a scrolled window widget */
    sw = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass, form,
            XmNshadowThickness, 2,
            XmNtopAttachment, XmATTACH_FORM,
            XmNleftAttachment, XmATTACH_FORM,
            XmNrightAttachment, XmATTACH_FORM,
            XmNbottomAttachment, XmATTACH_WIDGET,
            XmNbottomWidget, btnFW,
            NULL);
    hScrollBar = XtVaCreateManagedWidget("hScrollBar",
            xmScrollBarWidgetClass, sw,
            XmNorientation, XmHORIZONTAL, 
            XmNrepeatDelay, 10,
            NULL);
    vScrollBar = XtVaCreateManagedWidget("vScrollBar",
            xmScrollBarWidgetClass, sw,
            XmNorientation, XmVERTICAL,
            XmNrepeatDelay, 10,
            NULL);
    /* Make sure the fixed size help font is loaded, such that we can base
       our text widget size calculation on it. */
    loadFontsAndColors(sw, 'A');
    HelpTextPanes[topic] = XtVaCreateManagedWidget("helpText",
            textWidgetClass, sw,
            textNfont, HelpStyleInfo[0].font, /* MUST correspond to 'A' above */
            textNrows, 30,
            textNcolumns, 65,
            textNbacklightCharTypes, NULL,
            textNhScrollBar, hScrollBar,
            textNvScrollBar, vScrollBar,
            textNreadOnly, True,
            textNcontinuousWrap, True,
            textNautoShowInsertPos, True,
            NULL);
    XtVaSetValues(sw, XmNworkWindow, HelpTextPanes[topic],
            XmNhorizontalScrollBar, hScrollBar,
            XmNverticalScrollBar, vScrollBar,
            NULL);
    
    /* Initialize help style information, if it hasn't already been init'd */
    initHelpStyles (HelpTextPanes[topic]);
    
    /* Put together the text to display and separate it into parallel text
       and style data for display by the widget */
    helpText = stitch (HelpTextPanes[topic], HelpText[topic], &styleData);
    
    /* Stuff the text into the widget's text buffer */
    BufSetAll (TextGetBuffer (HelpTextPanes[topic]) , helpText);
    XtFree (helpText);
    
    /* Create a style buffer for the text widget and fill it with the style
       data which was generated along with the text content */
    HelpStyleBuffers[topic] = BufCreate(); 
    BufSetAll(HelpStyleBuffers[topic], styleData);
    XtFree (styleData);
    TextDAttachHighlightData(((TextWidget)HelpTextPanes[topic])->text.textD,
            HelpStyleBuffers[topic], HelpStyleInfo, N_STYLES, '\0', NULL, NULL);
    
    /* This shouldn't be necessary (what's wrong in text.c?) */
    HandleXSelections(HelpTextPanes[topic]);
    
    /* Process dialog mnemonic keys */
    AddDialogMnemonicHandler(form, FALSE);
    
    /* Set the default button */
    XtVaSetValues(form, XmNdefaultButton, closeBtn, NULL);
    XtVaSetValues(form, XmNcancelButton, closeBtn, NULL);
    
    /* realize all of the widgets in the new window */
    RealizeWithoutForcingPosition(appShell);
    
    /* Give the text pane the initial focus */
    XmProcessTraversal(HelpTextPanes[topic], XmTRAVERSE_CURRENT);

    /* Make close command in window menu gracefully prompt for close */
    AddMotifCloseCallback(appShell, (XtCallbackProc)closeCB, appShell);
    
    /* Initialize navigation information, if it hasn't already been init'd */
    initNavigationHistory();
    
    /* Set the window title */
    setHelpWinTitle(appShell, topic);
    
    
#ifdef EDITRES
    XtAddEventHandler (appShell, (EventMask)0, True,
            (XtEventHandler)_XEditResCheckMessages, NULL);
#endif /* EDITRES */
    
    return appShell;
}