wxString CSizeFormatBase::FormatNumber(COptionsBase* pOptions, const wxLongLong& size, bool* thousands_separator /*=0*/)
{
	if ((thousands_separator && !*thousands_separator) || pOptions->GetOptionVal(OPTION_SIZE_USETHOUSANDSEP) == 0)
		return size.ToString();

	const wxString& sep = GetThousandsSeparator();
	if (sep.empty())
		return size.ToString();

	wxString tmp = size.ToString();
	const int len = tmp.Len();
	if (len <= 3)
		return tmp;

	wxString result;
	int i = (len - 1) % 3 + 1;
	result = tmp.Left(i);
	while (i < len)
	{
		result += sep + tmp.Mid(i, 3);
		i += 3;
	}

	return result;
}
示例#2
0
wxString DirectoriesPrefs::FormatSize(wxLongLong size)
{
    wxString sizeStr;

    /* wxLongLong contains no built-in conversion to double */
    double dSize = size.GetHi() * pow(2, 32);  // 2 ^ 32
    dSize += size.GetLo();

    if (size == -1L)
        sizeStr = _("Unable to determine");
    else {
        /* make it look nice, by formatting into k, MB, etc */
        if (size < 1024)
            sizeStr.sprintf("%ld bytes", size.GetLo());
        else if (size < 1024 * 1024) {
            sizeStr.sprintf("%.1f kB", dSize / 1024);
        }
        else if (size < 1024 * 1024 * 1024) {
            sizeStr.sprintf("%.1f MB", dSize / (1024 * 1024));
        }
        else {
            sizeStr.sprintf("%.1f GB", dSize / (1024 * 1024 * 1024));
        }
    }

    return sizeStr;
}
示例#3
0
wxString Internat::FormatSize(wxLongLong size)
{
    /* wxLongLong contains no built-in conversion to double */
    double dSize = size.GetHi() * pow(2.0, 32);  // 2 ^ 32
    dSize += size.GetLo();

    return FormatSize(dSize);
}
示例#4
0
/*****************************************************
**
**   Painter   ---   drawMString
**
******************************************************/
void Painter::drawMString( const MRect &r, MString &f, const int& align )
{
#ifdef SHOW_STOP_WATCH
	static wxLongLong totaltime = 0;
	const wxLongLong starttime = wxGetLocalTimeMillis();
#endif

	static int count = 0;
	SheetFormatter sfmt;
	wxString s;

	if ( f.formattedLines.size() == 0 )
	{
		if ( ! f.isEmpty() && f.size.real() == 0 )
		{
			s = sfmt.fragment2PlainText( f );
			//printf( "Painter::drawMString - old size %f %f\n", f.size.real(), f.size.imag());
			f.size = getTextExtent( f );
			printf( "Painter::drawMString - size not set #%d contents was %s, size now %f %f\n", count++, str2char( s ), f.size.real(), f.size.imag());
		}
		drawSingleMStringLine( r, f, align );
		//return;
	}
	else
	{
		double y0 = r.y;
		if ( align & Align::Top )
		{
			// nothing
		}
		else if ( align & Align::Bottom )
		{
			y0 = y0 + r.height - f.size.imag();
		}
		else // default: align & align::VCenter
		{
			y0 += .5 * ( r.height - f.size.imag());
		}

		MRect rect( r.x, y0, r.width, r.height );

		int line = 0;
		for( list<MString>::iterator iter = f.formattedLines.begin(); iter != f.formattedLines.end(); iter++ )
		{
			line++;
			rect.height = iter->size.imag();
			//printf( "  --->>> Line %d width %f h %f\n", line, iter->size.real(), iter->size.imag() );
			drawSingleMStringLine( rect, *iter, align );
			rect.y += rect.height;
		}
	}
#ifdef SHOW_STOP_WATCH
	const wxLongLong duration = wxGetLocalTimeMillis() - starttime;
	totaltime += duration;
	wxLogMessage( wxString::Format( wxT( "Painter::drawTextFormatted in %ld msec, total %ld" ), duration.ToLong(), totaltime.ToLong() ));
#endif

}
示例#5
0
文件: misc.cpp 项目: swflb/pgadmin3
wxString NumToStr(wxLongLong value)
{
	wxString str;
#if wxCHECK_VERSION(2, 9, 0)
	str.Printf("%" wxLongLongFmtSpec "d", value.GetValue());
#else
	str.Printf(wxT("%") wxLongLongFmtSpec wxT("d"), value.GetValue());
#endif
	return str;
}
示例#6
0
文件: misc.cpp 项目: swflb/pgadmin3
wxString ElapsedTimeToStr(wxLongLong msec)
{
	wxTimeSpan tsMsec(0, 0, 0, msec);

	int days = tsMsec.GetDays();
	int hours = (wxTimeSpan(tsMsec.GetHours(), 0, 0, 0) - wxTimeSpan(days * 24)).GetHours();
	int minutes = (wxTimeSpan(0, tsMsec.GetMinutes(), 0, 0) - wxTimeSpan(hours)).GetMinutes();
	long seconds = (wxTimeSpan(0, 0, tsMsec.GetSeconds(), 0) - wxTimeSpan(0, minutes)).GetSeconds().ToLong();
	long milliseconds = (wxTimeSpan(0, 0, 0, tsMsec.GetMilliseconds()) - wxTimeSpan(0, 0, seconds)).GetMilliseconds().ToLong();

	if (days > 0)
		return wxString::Format(
		           wxT("%d %s, %02d:%02d:%02ld hours"),
		           days, wxT("days"), hours, minutes, seconds
		       );
	else if (hours > 0)
		return wxString::Format(
		           wxT("%02d:%02d:%02ld hours"), hours, minutes, seconds
		       );
	else if (msec >= 1000 * 60)
		return wxString::Format(wxT("%02d:%02ld minutes"), minutes, seconds);
	else if (msec >= 1000)
		return wxString::Format(
		           wxT("%ld.%ld secs"), seconds, milliseconds / 100
		       );
	else
		return msec.ToString() + wxT(" msec");
}
示例#7
0
 virtual void UpdateCallback(wxUpdateType type,
                             const wxString& database, const wxString& table,
                             wxLongLong rowid)
 {
   const char* strType;
   cout << "Here is the UPDATE callback" << endl;
   switch (type)
   {
     case SQLITE_DELETE:
       strType = "DELETE row ";
       break;
     case SQLITE_INSERT:
       strType = "INSERT row ";
       break;
     case SQLITE_UPDATE:
       strType = "UPDATE row ";
       break;
     default:
       strType = "Unknown change row ";
       break;
   }
   cout << strType << (const char*) rowid.ToString().mb_str()
        << " in table " << (const char*) table.mb_str()
        << " of database " << (const char*) database.mb_str() << endl;
 }
示例#8
0
wxLongLong TIniFile::ReadLongLong(const wxString &Section, const wxString &Ident,
	wxLongLong Default)
{
	wxString str = ReadString(Section, Ident, Default.ToString());
	wxLongLong lng = StrToLongLong(str);
	return lng;
}
wxString COptionsPageSizeFormatting::FormatSize(const wxLongLong& size)
{
	const CSizeFormat::_format format = GetFormat();
	const bool thousands_separator = GetCheck(XRCID("ID_SIZEFORMAT_SEPARATE_THOUTHANDS"));
	const int num_decimal_places = XRCCTRL(*this, "ID_SIZEFORMAT_DECIMALPLACES", wxSpinCtrl)->GetValue();

	return CSizeFormat::Format(size.GetValue(), false, format, thousands_separator, num_decimal_places);
}
示例#10
0
/*****************************************************
**
**   SheetWidget   ---   doPaint
**
******************************************************/
void SheetWidget::doPaint( const wxRect &rect, const bool eraseBackground )
{
#ifdef SCROLLABLE_PAGE_WIDGET_SHOW_STOP_WATCH
	const wxLongLong starttime = wxGetLocalTimeMillis();
#endif

	// may have changed
	writer->setSheetConfig( getSheetConfig() );
	
	assert( painter );
	painter->writercfg = sheet->writercfg;
	painter->colorcfg = colorcfg;

	//printf( "RECT x %d y %d w %d h %d\n", rect.x, rect.y, rect.width, rect.height );
	MRect therect( rect );

	//printf( "SheetWidget::doPaint xviewport %d yviewport %d erase = %d DIRTY %d\n", xviewport, yviewport, eraseBackground, dirty );

	// dirty ist okay. kommt bei echten Updates und Resize. nicht bei Scroll, mouse over usw.
	if ( dirty )
	{
		init();
		calculateContentSize();
		initViewPort();
		dirty = false;
	}

	painter->setBrush( config->colors->bgColor );
	painter->setTransparentPen();
	painter->drawRectangle( rect );

	painter->setTransparentPen();

	writer->drawSheet( painter, therect, eraseBackground );

#ifdef SCROLLABLE_PAGE_WIDGET_SHOW_STOP_WATCH
	const wxLongLong totaltime = wxGetLocalTimeMillis() - starttime;
	wxLogMessage( wxString::Format( wxT( "SheetWidget::doPaint in %ld millisec eraseBackground %d" ),
		totaltime.ToLong(), eraseBackground ));
#endif
}
void ServerEvents::OnPong(wxLongLong ping_time)
{
	//wxLongLong is non-POD and cannot be passed to wxString::Format as such. use c-string rep instead. converting to long might loose precision
	UiEvents::StatusData data(wxString::Format(_("ping: %s ms"), ping_time.ToString().c_str()), 2);
	UiEvents::GetStatusEventSender(UiEvents::addStatusMessage).SendEvent(data);
}
示例#12
0
wxString CSizeFormatBase::Format(COptionsBase* pOptions, wxLongLong size, bool add_bytes_suffix, enum CSizeFormatBase::_format format, bool thousands_separator, int num_decimal_places)
{
	wxASSERT(format != formats_count);
	wxASSERT(size >= 0);
	if( size < 0 ) {
		size = 0;
	}

	if (format == bytes) {
		wxString result = FormatNumber(pOptions, size, &thousands_separator);

		if (!add_bytes_suffix)
			return result;
		else
		{
			// wxPLURAL has no support for wxLongLong
			int last;
			if (size > 1000000000)
				last = (1000000000 + (size % 1000000000)).GetLo();
			else
				last = size.GetLo();
			return wxString::Format(wxPLURAL("%s byte", "%s bytes", last), result);
		}
	}

	wxString places;

	int divider;
	if (format == si1000)
		divider = 1000;
	else
		divider = 1024;

	// Exponent (2^(10p) or 10^(3p) depending on option
	int p = 0;

	wxLongLong r = size;
	int remainder = 0;
	bool clipped = false;
	while (r > divider && p < 6) {
		const wxLongLong rr = r / divider;
		if (remainder != 0)
			clipped = true;
		remainder = (r - rr * divider).GetLo();
		r = rr;
		++p;
	}
	if (!num_decimal_places) {
		if (remainder != 0 || clipped)
			++r;
	}
	else if (p) { // Don't add decimal places on exact bytes
		if (format != si1000) {
			// Binary, need to convert 1024 into range from 1-1000
			if (clipped) {
				++remainder;
				clipped = false;
			}
			remainder = (int)ceil((double)remainder * 1000 / 1024);
		}

		int max;
		switch (num_decimal_places)
		{
		default:
			num_decimal_places = 1;
			// Fall-through
		case 1:
			max = 9;
			divider = 100;
			break;
		case 2:
			max = 99;
			divider = 10;
			break;
		case 3:
			max = 999;
			break;
		}

		if (num_decimal_places != 3) {
			if (remainder % divider)
				clipped = true;
			remainder /= divider;
		}

		if (clipped)
			remainder++;
		if (remainder > max) {
			r++;
			remainder = 0;
		}

		places.Printf(_T("%d"), remainder);
		const size_t len = places.Len();
		for (size_t i = len; i < static_cast<size_t>(num_decimal_places); ++i)
			places = _T("0") + places;
	}

	wxString result = r.ToString();
	if (!places.empty()) {
		const wxString& sep = GetRadixSeparator();

		result += sep;
		result += places;
	}
	result += ' ';

	static wxChar byte_unit = 0;
	if (!byte_unit)
	{
		wxString t = _("B <Unit symbol for bytes. Only translate first letter>");
		byte_unit = t[0];
	}

	if (!p)
		return result + byte_unit;

	result += prefix[p];
	if (format == iec)
		result += 'i';

	result += byte_unit;

	return result;
}
示例#13
0
文件: eSettings.cpp 项目: boulerne/e
void eSettings::SetSettingLong(const wxString& name, const wxLongLong& value) {
	wxJSONValue& settings = m_jsonRoot[wxT("settings")];
	settings[name] = value.GetValue();
}
示例#14
0
void TIniFile::WriteLongLong(const wxString &Section, const wxString &Ident,
	wxLongLong Value)
{
	WriteString(Section, Ident, Value.ToString());
}