Example #1
0
bool wxApp::SetNativeTheme(const wxString& theme)
{
#ifdef __WXGTK3__
    wxUnusedVar(theme);
    return false;
#else
    wxString path;
    path = gtk_rc_get_theme_dir();
    path += "/";
    path += theme.utf8_str();
    path += "/gtk-2.0/gtkrc";

    if ( wxFileExists(path.utf8_str()) )
        gtk_rc_add_default_file(path.utf8_str());
    else if ( wxFileExists(theme.utf8_str()) )
        gtk_rc_add_default_file(theme.utf8_str());
    else
    {
        wxLogWarning("Theme \"%s\" not available.", theme);

        return false;
    }

    gtk_rc_reparse_all_for_settings(gtk_settings_get_default(), TRUE);

    return true;
#endif
}
Example #2
0
void wxTarOutputStream::SetExtendedHeader(const wxString& key,
                                          const wxString& value)
{
    if (m_pax) {
#if wxUSE_UNICODE
        const wxCharBuffer utf_key = key.utf8_str();
        const wxCharBuffer utf_value = value.utf8_str();
#else
        const wxWX2WCbuf wide_key = key.wc_str(GetConv());
        const wxCharBuffer utf_key = wxConvUTF8.cWC2MB(wide_key);

        const wxWX2WCbuf wide_value = value.wc_str(GetConv());
        const wxCharBuffer utf_value = wxConvUTF8.cWC2MB(wide_value);
#endif // wxUSE_UNICODE/!wxUSE_UNICODE

        // a small buffer to format the length field in
        char buf[32];
        // length of "99<space><key>=<value>\n"
        unsigned long length = strlen(utf_value) + strlen(utf_key) + 5;
        sprintf(buf, "%lu", length);
        // the length includes itself
        size_t lenlen = strlen(buf);
        if (lenlen != 2) {
            length += lenlen - 2;
            sprintf(buf, "%lu", length);
            if (strlen(buf) > lenlen)
                sprintf(buf, "%lu", ++length);
        }

        // reallocate m_extendedHdr if it's not big enough
        if (m_extendedSize < length) {
            size_t rounded = RoundUpSize(length);
            m_extendedSize <<= 1;
            if (rounded > m_extendedSize)
                m_extendedSize = rounded;
            char *oldHdr = m_extendedHdr;
            m_extendedHdr = new char[m_extendedSize];
            if (oldHdr) {
                strcpy(m_extendedHdr, oldHdr);
                delete oldHdr;
            } else {
                *m_extendedHdr = 0;
            }
        }

        // append the new record
        char *append = strchr(m_extendedHdr, 0);
        sprintf(append, "%s %s=%s\012", buf,
                (const char*)utf_key, (const char*)utf_value);
    }
    else {
        // if not pax then make a list of fields to report as errors
        if (!m_badfit.empty())
            m_badfit += wxT(", ");
        m_badfit += key;
    }
}
Example #3
0
bool wxSockAddressImpl::SetHostName6(const wxString& hostname)
{
    sockaddr_in6 * const addr = Get<sockaddr_in6>();
    if ( !addr )
        return false;

    addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET6;

    addrinfo *info = NULL;
    int rc = getaddrinfo(hostname.utf8_str(), NULL, &hints, &info);
    if ( rc )
    {
        // use gai_strerror()?
        return false;
    }

    wxCHECK_MSG( info, false, "should have info on success" );

    wxASSERT_MSG( int(info->ai_addrlen) == m_len, "unexpected address length" );

    memcpy(addr, info->ai_addr, info->ai_addrlen);
    freeaddrinfo(info);

    return true;
}
Example #4
0
bool wxSockAddressImpl::SetHostName4(const wxString& name)
{
    sockaddr_in * const addr = Get<sockaddr_in>();
    if ( !addr )
        return false;

    const wxScopedCharBuffer namebuf(name.utf8_str());

    // first check if this is an address in quad dotted notation
#if defined(HAVE_INET_ATON)
    if ( inet_aton(namebuf, &addr->sin_addr) )
        return true;
#elif defined(HAVE_INET_ADDR)
    addr->sin_addr.s_addr = inet_addr(namebuf);
    if ( addr->sin_addr.s_addr != INADDR_NONE )
        return true;
#else
    #error "Neither inet_aton() nor inet_addr() is available?"
#endif

    // it's a host name, resolve it
    hostent he;
    wxGethostBuf buffer;
    int err;
    if ( !wxGethostbyname_r(namebuf, &he, buffer, sizeof(buffer), &err) )
        return false;

    addr->sin_addr.s_addr = ((in_addr *)he.h_addr)->s_addr;
    return true;
}
Example #5
0
bool wxSockAddressImpl::SetPortName(const wxString& name, const char *protocol)
{
    // test whether it's a number first
    unsigned long port;
    if ( name.ToULong(&port) )
    {
        if ( port > 65535 )
            return false;
    }
    else // it's a service name
    {
        wxGetservBuf buffer;
        servent se;
        if ( !wxGetservbyname_r(name.utf8_str(), protocol, &se,
                                buffer, sizeof(buffer)) )
            return false;

        // s_port is in network byte order and SetPort() uses the host byte
        // order and we prefer to reuse it from here instead of assigning to
        // sin_port directly
        port = ntohs(se.s_port);
    }

    return SetPort(port);
}
bool HandlerBroker::connect(MyThread * TID, const wxString& sDevName,const std::string& strDevInit, DEVID *id){

	DevDesc * pNewDev; 
	DevDesc* pDevLocker = getDev(sDevName);
	if (!pDevLocker) return false;
	std::string strUniqueDev = std::string(sDevName.utf8_str())+ pDevLocker->makeUniqueDev(strDevInit);
	{
		wxMutexLocker ml1(mtxDevHandlesTreeEdit);
		std::map<std::string, CountedDevHandle*>::iterator itDevH = mapDevHandlesInUse.find(strUniqueDev);
		if(itDevH != mapDevHandlesInUse.end()){
			pNewDev = itDevH->second->dev;
		}else{
			pNewDev = pDevLocker->clone();
			if (!(pNewDev->connect(strDevInit)))return false;

			wxMutexLocker ml2(mtxBusLockTreeEdit);
			std::string strBusLock= pNewDev->makeBusLock(strDevInit);
			pNewDev->itBusLocker =  mapBusLockers.find(strBusLock);
			if(pNewDev->itBusLocker == mapBusLockers.end())
				pNewDev->itBusLocker = mapBusLockers.insert(std::make_pair(strBusLock, new mtxCont)).first;
			++(*(pNewDev->itBusLocker->second));
			itDevH = mapDevHandlesInUse.insert( std::make_pair( strUniqueDev, new CountedDevHandle(pNewDev)) ).first; 
			itDevH->second->dev->itDevH = itDevH;
		}
		++(*(itDevH->second));
	}

	wxMutexLocker ml0(mtxDevTreeEdit);
	std::map<MyThread *, ThrDevs*>::iterator it=mapThreadDevsInUse.find(TID); 
	if (it == mapThreadDevsInUse.end()) it = mapThreadDevsInUse.insert(std::pair<MyThread * , ThrDevs*>(TID, new ThrDevs(TID)) ).first; 
	*id = it->second->insert(pNewDev);

	return true;
};
Example #7
0
void COptions::SetXmlValue(unsigned int nID, wxString const& value)
{
	if (!m_pXmlFile)
		return;

	// No checks are made about the validity of the value, that's done in SetOption

	wxScopedCharBuffer utf8 = value.utf8_str();
	if (!utf8)
		return;

	auto settings = CreateSettingsXmlElement();
	if (settings) {
		pugi::xml_node setting;
		for (setting = settings.child("Setting"); setting; setting = setting.next_sibling("Setting")) {
			const char *attribute = setting.attribute("name").value();
			if (!attribute)
				continue;
			if (!strcmp(attribute, options[nID].name))
				break;
		}
		if (!setting) {
			setting = settings.append_child("Setting");
			SetTextAttribute(setting, "name", options[nID].name);
		}
		setting.text() = utf8;
	}
}
Example #8
0
wxString CControlSocket::ConvertDomainName(wxString const& domain)
{
#ifdef __WXMSW__
	int len = IdnToAscii(IDN_ALLOW_UNASSIGNED, domain, domain.size() + 1, 0, 0);
	if( !len ) {
		LogMessage(MessageType::Debug_Warning, _T("Could not convert domain name"));
		return domain;
	}

	wchar_t* output = new wchar_t[len];
	int res = IdnToAscii(IDN_ALLOW_UNASSIGNED, domain, domain.size() + 1, output, len);
	if( !res ) {
		LogMessage(MessageType::Debug_Warning, _T("Could not convert domain name"));
		return domain;
	}

	wxString ret(output);
	delete [] output;
	return ret;
#else

	wxScopedCharBuffer const utf8 = domain.utf8_str();

	char *output = 0;
	if (idna_to_ascii_8z(utf8, &output, IDNA_ALLOW_UNASSIGNED)) {
		LogMessage(MessageType::Debug_Warning, _T("Could not convert domain name"));
		return domain;
	}

	wxString result = wxConvCurrent->cMB2WX(output);
	idn_free(output);
	return result;
#endif
}
wxString CreateDatabaseDialogue::QuoteIdent(const wxString &str)
{
  if (IsSimpleSymbol(str.utf8_str())) return str;
  wxString escaped;
  escaped << _T('\"') << str << _T('\"');
  return escaped;
}
Example #10
0
bool wxURI::Create(const wxString& uri)
{
    if (m_fields)
        Clear();

    return Parse(uri.utf8_str());
}
Example #11
0
bool wxGtkFileChooser::SetPath( const wxString& path )
{
    if ( path.empty() )
        return true;

    return gtk_file_chooser_set_filename( m_widget, path.utf8_str() ) != 0;
}
Example #12
0
void COptions::SetXmlValue(unsigned int nID, wxString const& value)
{
	if (!m_pXmlFile)
		return;

	// No checks are made about the validity of the value, that's done in SetOption

	wxScopedCharBuffer utf8 = value.utf8_str();
	if (!utf8)
		return;

	TiXmlElement *settings = CreateSettingsXmlElement();
	if (settings) {
		TiXmlElement *setting = 0;
		for (setting = settings->FirstChildElement("Setting"); setting; setting = setting->NextSiblingElement("Setting")) {
			const char *attribute = setting->Attribute("name");
			if (!attribute)
				continue;
			if (!strcmp(attribute, options[nID].name))
				break;
		}
		if (setting) {
			setting->Clear();
		}
		else {
			setting = new TiXmlElement("Setting");
			setting->SetAttribute("name", options[nID].name);
			settings->LinkEndChild(setting);
		}
		setting->LinkEndChild(new TiXmlText(utf8));
	}
}
Example #13
0
void wxDFBDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
{
    wxCHECK_RET( IsOk(), wxT("invalid dc") );

    wxCoord xx = XLOG2DEV(x);
    wxCoord yy = YLOG2DEV(y);

    // update the bounding box
    wxCoord w, h;
    CalcBoundingBox(x, y);
    DoGetTextExtent(text, &w, &h);
    CalcBoundingBox(x + w, y + h);

    // if background mode is solid, DrawText must paint text's background:
    if ( m_backgroundMode == wxSOLID )
    {
        wxCHECK_RET( m_textBackgroundColour.Ok(),
                     wxT("invalid background color") );

        SelectColour(m_textBackgroundColour);
        m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h));
    }

    // finally draw the text itself:
    wxCHECK_RET( m_textForegroundColour.Ok(),
                 wxT("invalid foreground color") );
    SelectColour(m_textForegroundColour);
    m_surface->DrawString(text.utf8_str(), -1, xx, yy, DSTF_LEFT | DSTF_TOP);

    // restore pen's colour, because other drawing functions expect the colour
    // to be set to the pen:
    SelectColour(m_pen.GetColour());
}
bool PythonInterpCtrl::RunCode(const wxString &codestr)
{
//TODO: Should use a common ID for this and cont
    XmlRpc::XmlRpcValue args;
    args[0]=codestr.utf8_str();
    args[1]=stdin_retrieve().utf8_str();
    return m_pyinterp->ExecAsync(_T("run_code"), args, this);
}
Example #15
0
void wxSVGFileDCImpl::write(const wxString &s)
{
    m_OK = m_outfile->IsOk();
    if (!m_OK)
        return;
    const wxCharBuffer buf = s.utf8_str();
    m_outfile->Write(buf, strlen((const char *)buf));
    m_OK = m_outfile->IsOk();
}
Example #16
0
std::string OUTPUTFORMATTER::Quotew( const wxString& aWrapee ) throw( IO_ERROR )
{
    // wxStrings are always encoded as UTF-8 as we convert to a byte sequence.
    // The non-virutal function calls the virtual workhorse function, and if
    // a different quoting or escaping strategy is desired from the standard,
    // a derived class can overload Quotes() above, but
    // should never be a reason to overload this Quotew() here.
    return Quotes( (const char*) aWrapee.utf8_str() );
}
Example #17
0
void AddTextElement(TiXmlElement* node, const char* name, const wxString& value, bool overwrite)
{
	wxASSERT(node);

	wxScopedCharBuffer  utf8 = value.utf8_str();
	if (!utf8)
		return;

	AddTextElementRaw(node, name, utf8, overwrite);
}
Example #18
0
bool CocoaDialogApp::OptionError(const wxString& error) const {
	printf("Invalid options:\n\n");
	
	if (!error.empty()) printf("%s", error.utf8_str().data());
	
	printf("\n");
	OptionHelp();

	return false;
}
Example #19
0
void SetTextAttribute(TiXmlElement* node, const char* name, const wxString& value)
{
	wxASSERT(node);

	wxScopedCharBuffer utf8 = value.utf8_str();
	if (!utf8)
		return;

	node->SetAttribute(name, utf8);
}
Example #20
0
void ScriptEditor::WriteFile(const wxString &filename)
{
  wxLogDebug(_T("Write file %s"), filename.c_str());
  // TODO make backup file?
  // write out file in the scintilla coding system (utf-8)
  std::ofstream output(filename.utf8_str(), std::ofstream::out);
  const wxCharBuffer buf = GetTextRaw();
  size_t len = GetLength();
  output.write(buf, len);
  SetSavePoint();
}
Example #21
0
wxMemoryBuffer Exword::Reset(wxString user)
{
    wxMemoryBuffer key(20);
    exword_authinfo_t ai;
    exword_userid_t u;

    if (!IsConnected())
        return key;

    memset(&ai, 0, sizeof(exword_authinfo_t));
    memset(&u, 0, sizeof(exword_userid_t));
    memcpy(ai.blk1, "FFFFFFFFFFFFFFFF", 16);
    strncpy((char*)ai.blk2, user.utf8_str().data(), 24);
    strncpy(u.name, user.utf8_str().data(), 16);
    exword_setpath(m_device, (uint8_t*)"\\_INTERNAL_00", 0);
    exword_authinfo(m_device, &ai);
    exword_userid(m_device, u);
    key.AppendData(ai.challenge, 20);
    return key;
}
Example #22
0
void AddTextElement(TiXmlElement* node, const wxString& value)
{
	wxASSERT(node);
	wxASSERT(value);

	wxScopedCharBuffer utf8 = value.utf8_str();
	if (!utf8)
		return;

	AddTextElementRaw(node, utf8);
}
Example #23
0
pugi::xml_node AddTextElement(pugi::xml_node node, const char* name, const wxString& value, bool overwrite)
{
	pugi::xml_node ret;

	wxASSERT(node);

	wxScopedCharBuffer utf8 = value.utf8_str();
	if (utf8) {
		ret = AddTextElementRaw(node, name, utf8, overwrite);
	}

	return ret;
}
Example #24
0
XmlTextInfo::XmlTextInfo
	( const wxString &path
	, const char *encoding /*= NULL*/
	)
	: WrapExpat ( encoding )
{
	XML_SetUserData ( p, this );
	XML_SetBase ( p, path.utf8_str() );
	XML_SetDoctypeDeclHandler ( p, startdoctypehandler, NULL );
	XML_SetProcessingInstructionHandler ( p, processinghandler );
	XML_SetElementHandler ( p, start, NULL );
	XML_SetDefaultHandlerExpand ( p, defaulthandler );
}
Example #25
0
bool wxSockAddressImpl::SetPath(const wxString& path)
{
    sockaddr_un * const addr = Get<sockaddr_un>();
    if ( !addr )
        return false;

    const wxScopedCharBuffer buf(path.utf8_str());
    if ( strlen(buf) >= UNIX_PATH_MAX )
        return false;

    wxStrlcpy(addr->sun_path, buf, UNIX_PATH_MAX);

    return true;
}
Example #26
0
void wxDirButton::SetPath(const wxString& str)
{
    if ( m_path == str )
        return;

    m_path = str;

    m_bIgnoreNextChange = true;

    if (GTK_IS_FILE_CHOOSER(m_widget))
        gtk_file_chooser_set_filename((GtkFileChooser*)m_widget, str.utf8_str());
    else if (m_dialog)
        UpdateDialogPath(m_dialog);
}
Example #27
0
void SetTextAttribute(pugi::xml_node node, const char* name, const wxString& value)
{
	wxASSERT(node);

	wxScopedCharBuffer utf8 = value.utf8_str();
	if (!utf8)
		return;

	auto attribute = node.attribute(name);
	if (!attribute) {
		attribute = node.append_attribute(name);
	}
	attribute.set_value(utf8);
}
/**
 * MD5を生成する
 */     
wxString XrossBoardUtil::GenerateMD5String(const wxString& uri) {

     wxString result;
     unsigned char digest[MD5_DIGEST_LENGTH];
     const wxCharBuffer &cb = uri.utf8_str();

     ::MD5((const unsigned char*)cb.data(), ::strlen(cb.data()), digest);

     for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
	  result << wxString::Format(wxT("%02x"), (int)digest[i]);
     }

     return result;
}
Example #29
0
void wxWebFrame::SetPageSource(const wxString& source, const wxString& baseUrl, const wxString& mimetype)
{
    if (m_impl->frame && m_impl->frame->loader()) {
        WebCore::KURL url(WebCore::KURL(), baseUrl);

        const wxCharBuffer charBuffer(source.utf8_str());
        const char* contents = charBuffer;

        WTF::PassRefPtr<WebCore::SharedBuffer> sharedBuffer = WebCore::SharedBuffer::create(contents, strlen(contents));
        WebCore::SubstituteData substituteData(sharedBuffer, mimetype, WTF::String("UTF-8"), WebCore::blankURL(), url);

        m_impl->frame->loader()->stop();
        m_impl->frame->loader()->load(WebCore::ResourceRequest(url), substituteData, false);
    }
}
Example #30
0
bool Exword::Authenticate(wxString user, wxMemoryBuffer& key)
{
    bool success = false;
    int rsp;
    uint16_t count;
    exword_dirent_t *entries;
    exword_authchallenge_t c;
    exword_authinfo_t ai;
    exword_userid_t u;

    if (!IsConnected())
        return success;

    memcpy(c.challenge, key.GetData(), 20);
    memcpy(ai.blk1, "FFFFFFFFFFFFFFFF", 16);
    strncpy((char*)ai.blk2, user.utf8_str().data(), 24);
    strncpy(u.name, user.utf8_str().data(), 16);
    exword_setpath(m_device, (uint8_t*)"\\_INTERNAL_00", 0);
    rsp = exword_authchallenge(m_device, c);
    if (rsp == EXWORD_SUCCESS) {
        exword_setpath(m_device, (uint8_t*)"", 0);
        exword_list(m_device, &entries, &count);
        for (int i = 0; i < count; i++) {
            if (strcmp((const char*)entries[i].name, "_SD_00") == 0) {
                exword_setpath(m_device, (uint8_t*)"\\_SD_00", 0);
                rsp = exword_authchallenge(m_device, c);
                if (rsp != EXWORD_SUCCESS)
                    exword_authinfo(m_device, &ai);
             }
        }
        exword_free_list(entries);
        exword_userid(m_device, u);
        success = true;
    }
    return success;
}