⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 widget.cpp

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        {
            delete Child;
            return false;
        }
    }
    return Ret;
}

bool wxsWidget::XmlSaveChildren()
{
    bool Ret = true;
    TiXmlElement* Elem = XmlElem();
    int Count = GetChildCount();
    for ( int i=0; i<Count; i++ )
    {
    	if ( !XmlSaveChild(i,Elem) ) Ret = false;
    }
    return Ret;
}

bool wxsWidget::XmlSaveChild(int ChildIndex,TiXmlElement* AddHere)
{
    wxsWidget* W = GetChild(ChildIndex);

    if ( W && W->GetInfo().Name )
    {
        TiXmlElement* SaveTo = AddHere->InsertEndChild(TiXmlElement("object"))->ToElement();

        if ( !SaveTo ) return false;

        SaveTo->SetAttribute("class",W->GetInfo().Name.mb_str());
        if ( !W->XmlSave(SaveTo) ) return false;
    }

    return true;
}

const wxsWidget::CodeDefines& wxsWidget::GetCodeDefines()
{
    CDefines.Style = _T("");
    CDefines.InitCode = _T("");

    wxString SelectCode = _T("");
    if ( GetParent() )
    {
        SelectCode << BaseParams.VarName << _T("->");
    }

    // Filling up styles

    wxsStyle* Style = GetInfo().Styles;
    int StyleV = BaseParams.Style;
    if ( Style )
    {
        for ( ; Style->Name; Style++ )
        {
            if ( Style->Value && ( ( StyleV & Style->Value ) == Style->Value ) )
            {
                StyleV &= ~Style->Value;

                if ( CDefines.Style.Length() ) CDefines.Style.Append('|');
                CDefines.Style.Append(Style->Name);
            }
        }
    }

    if ( CDefines.Style.Len() == 0 ) CDefines.Style = _T("0");

    // Creating position

    if ( BaseParams.DefaultPosition ) CDefines.Pos = _T("wxDefaultPosition");
    else CDefines.Pos.Printf(_T("wxPoint(%d,%d)"),BaseParams.PosX,BaseParams.PosY);

    // Creating size

    if ( BaseParams.DefaultSize ) CDefines.Size = _T("wxDefaultSize");
    else CDefines.Size.Printf(_T("wxSize(%d,%d)"),BaseParams.SizeX,BaseParams.SizeY);

    // Creating colours

    BasePropertiesType pType = GetBPType();

    if ( pType & bptColours )
    {
        wxString FColour;
        wxString BColour;

        if ( BaseParams.FgType == wxsCUSTOM_COLOUR )
        {
        	FColour.Printf(_T("wxColour(%d,%d,%d)"),
                BaseParams.Fg.Red(),
                BaseParams.Fg.Green(),
                BaseParams.Fg.Blue());
        }
        else
        {
        	for ( int i=0; i<wxsSystemColoursCount; i++ )
        	{
        		if ( BaseParams.FgType == wxsSystemColours[i].Value )
        		{
        			FColour.Printf(_T("wxSystemSettings::GetColour(%s)"),wxsSystemColours[i].Name);
        			break;
        		}
        	}
        }

        if ( BaseParams.BgType == wxsCUSTOM_COLOUR )
        {
        	BColour.Printf(_T("wxColour(%d,%d,%d)"),
                BaseParams.Bg.Red(),
                BaseParams.Bg.Green(),
                BaseParams.Bg.Blue());
        }
        else
        {
        	for ( int i=0; i<wxsSystemColoursCount; i++ )
        	{
        		if ( BaseParams.BgType == wxsSystemColours[i].Value )
        		{
        			BColour.Printf(_T("wxSystemSettings::GetColour(%s)"),wxsSystemColours[i].Name);
        			break;
        		}
        	}
        }


        if ( !FColour.empty() )
        {
            CDefines.InitCode << SelectCode << _T("SetForegroundColour(")
                              << FColour    << _T(");");
        }

        if ( !BColour.empty() )
        {
            CDefines.InitCode << SelectCode << _T("SetBackgroundColour(")
                              << BColour    << _T(");");
        }
    }

    if ( pType & bptFont && BaseParams.UseFont )
    {
    	wxFont& Font = BaseParams.Font;
    	CDefines.InitCode << SelectCode          << _T("SetFont(wxFont(")
    	                  << Font.GetPointSize() << _T(",");

    	switch ( Font.GetFamily() )
    	{
    		case wxFONTFAMILY_DECORATIVE: CDefines.InitCode << _T("wxFONTFAMILY_DECORATIVE,"); break;
    		case wxFONTFAMILY_ROMAN     : CDefines.InitCode << _T("wxFONTFAMILY_ROMAN,"); break;
    		case wxFONTFAMILY_SCRIPT    : CDefines.InitCode << _T("wxFONTFAMILY_SCRIPT,"); break;
    		case wxFONTFAMILY_SWISS     : CDefines.InitCode << _T("wxFONTFAMILY_SWISS,"); break;
    		case wxFONTFAMILY_MODERN    : CDefines.InitCode << _T("wxFONTFAMILY_MODERN,"); break;
    		case wxFONTFAMILY_TELETYPE  : CDefines.InitCode << _T("wxFONTFAMILY_TELETYPE,"); break;
    		default                     : CDefines.InitCode << _T("wxFONTFAMILY_DEFAULT,");
    	}

    	switch ( Font.GetStyle() )
        {
    		case wxFONTSTYLE_SLANT  : CDefines.InitCode << _T("wxFONTSTYLE_SLANT,"); break;
    		case wxFONTSTYLE_ITALIC : CDefines.InitCode << _T("wxFONTSTYLE_ITALIC,"); break;
    		default                 : CDefines.InitCode << _T("wxFONTSTYLE_NORMAL,");
    	}

        switch ( Font.GetWeight() )
        {
        	case wxFONTWEIGHT_BOLD : CDefines.InitCode << _T("wxFONTWEIGHT_BOLD,"); break;
        	case wxFONTWEIGHT_LIGHT: CDefines.InitCode << _T("wxFONTWEIGHT_LIGHT,"); break;
        	default                : CDefines.InitCode << _T("wxFONTWEIGHT_NORMAL,");
        }

        if ( Font.GetUnderlined() )
        {
        	CDefines.InitCode << _T("true,");
        }
        else
        {
        	CDefines.InitCode << _T("false,");
        }

        if ( Font.GetFaceName().empty() )
        {
        	CDefines.InitCode << _T("_T(\"\")");
        }
        else
        {
            CDefines.InitCode << GetWxString(Font.GetFaceName());
        }

        CDefines.InitCode << _T("));");
    }

    if ( pType & bptEnabled && !BaseParams.Enabled )
    {
    	CDefines.InitCode << SelectCode << _T("Disable();");
    }

    if ( pType & bptFocused && BaseParams.Focused )
    {
        CDefines.InitCode << SelectCode << _T("SetFocus();");
    }

    if ( pType & bptHidden && BaseParams.Hidden )
    {
    	CDefines.InitCode << SelectCode << _T("Hide();");
    }

    if ( pType & bptToolTip && !BaseParams.ToolTip.empty() )
    {
    	CDefines.InitCode << SelectCode << _T("SetToolTip(")
    	                  << GetWxString(BaseParams.ToolTip) << _T(");");
    }

    return CDefines;
}

bool wxsWidgetManager::RegisterInFactory()
{
    if ( !wxsFACTORY() ) return false;
    wxsFACTORY()->RegisterManager(this);
    return true;
}

void wxsWidget::BuildTree(wxTreeCtrl* Tree,wxTreeItemId Id,int Index)
{
    wxString Name = GetInfo().Name;

    // TODO (SpOoN#1#): Add icons
    wxTreeItemId SubId;
    if ( Index < 0 || Index >= (int)Tree->GetCount() )
    {
        SubId = Tree->AppendItem(Id,Name,-1,-1,new wxsResourceTreeData(this));
    }
    else
    {
        SubId = Tree->InsertItem(Id,Index,Name,-1,-1,new wxsResourceTreeData(this));
    }
    TreeId = SubId;
    AssignedToTree = true;

    int SubCnt = GetChildCount();
    for ( int i=0; i<SubCnt; i++ )
    {
        GetChild(i)->BuildTree(Tree,SubId);
    }
}

//Added by cyberkoa
/* ======================================================================
    Function Name : XmlSetStringArray
   ======================================================================

 Description : To write a series of strings from XRC with ParentName as
               parent element and ChildName as child element
  Example :  ParentName = "content" , ChildName="item"
              <content>
                   <item>Item 1</item>
                   <item>Option 2</item>
                   <item>3rd choice</item>
              </content>

*/

bool wxsWidget::XmlSetStringArray(const wxString& ParentName,const wxString& ChildName,wxArrayString& stringArray)
{
    assert ( XmlElem() != NULL );

    int Count = stringArray.GetCount();
    // No item, return without writing <content> and <item> elements
    if(Count==0) return false;

    // Adding <ParentName>  element
    TiXmlElement* ParentElement;
    TiXmlElement* ChildElement;
    ParentElement = XmlElem()->InsertEndChild(TiXmlElement(ParentName.mb_str()))->ToElement();

    for ( int i=0; i<Count; i++ )
    {
      ChildElement = ParentElement->InsertEndChild(TiXmlElement(ChildName.mb_str()))->ToElement();

      if (ChildElement)
        ChildElement->InsertEndChild(TiXmlText(stringArray[i].mb_str()));
    }
    return true;
}
//End added

//Added by cyberkoa
/* ======================================================================
    Function Name : XmlGetStringArray
   ======================================================================

 Description : To read a series of strings from XRC with ParentName as
               parent element and ChildName as child element
  Example :  ParentName = "content" , ChildName="item"
              <content>
                   <item>Item 1</item>
                   <item>Option 2</item>
                   <item>3rd choice</item>
              </content>

*/
bool wxsWidget::XmlGetStringArray(const wxString& ParentName,const wxString& ChildName,wxArrayString& stringArray)
{
    assert ( XmlElem() != NULL );

     // Empty it to make sure element added in an empty wxArrayString
      stringArray.Empty();

    TiXmlElement* ParentElement = XmlElem()->FirstChildElement(ParentName.mb_str());
    if(!ParentElement) return false;

    for (TiXmlElement* ChildElement= ParentElement->FirstChildElement(ChildName.mb_str());
          ChildElement != NULL;
          ChildElement = ChildElement->NextSiblingElement(ChildName.mb_str()))
          {

           TiXmlNode* Node = ChildElement->FirstChild();

			while(Node)
			{
			 if(Node->ToText())
              stringArray.Add(wxString(Node->ToText()->Value(),wxConvUTF8));

              Node=Node->NextSibling();
            }
          }

      if(stringArray.GetCount() > 0)return true; else return false;

}
//End added

void wxsWidget::KillTree(wxTreeCtrl* Tree)
{
	if ( AssignedToTree )
	{
		Tree->Delete(TreeId);
        InvalidateTreeIds();
	}
}



void wxsWidget::PreviewDestroyed()

{

    int Cnt = GetChildCount();

    for ( int i=0; i<Cnt; i++ )

    {

        GetChild(i)->PreviewDestroyed();

    }

    Preview = NULL;

}

void wxsWidget::InvalidateTreeIds()
{
	if ( !AssignedToTree ) return;
	AssignedToTree = false;
	int Cnt = GetChildCount();
	for ( int i=0; i<Cnt; i++ )
	{
		GetChild(i)->InvalidateTreeIds();
	}
}

wxsWindowEditor* wxsWidget::GetEditor()
{
	return Resource ? (wxsWindowEditor*)Resource->GetEditor() : NULL;
}

wxsWidgetEvents* wxsWidget::GetEvents()
{
	if ( !Events )
	{
		 Events = new wxsWidgetEvents(this);
		 // Filling up with events from info
		 wxsEventDesc* Desc = GetInfo().Events;
		 if ( Desc )
		 {
		 	while ( Desc->EventTypeName.Length() )
		 	{
		 		if ( Desc->EventEntry.Length() )
		 		{
		 			Events->AddEvent(*Desc,true);
		 		}
		 		Desc++;
		 	}
		 }
	}
	return Events;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -