changed: precision:
small - the same as previous medium - 288 bits for the mantissa, 64 bits for the exponent big - 864 bits for the mantissa, 128 bits for the exponent added: list on the converting tab can be resized horizontally added: info in the info edit about units on the converting tab git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@57 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
ae0a8dc911
commit
01ad539107
|
@ -65,6 +65,9 @@ unsigned __stdcall CalculationsProcedure(void *)
|
||||||
SetDlgItemText(main_window, IDC_OUTPUT_EDIT, "");
|
SetDlgItemText(main_window, IDC_OUTPUT_EDIT, "");
|
||||||
PostMessage(main_window, WM_SET_LAST_ERROR, (WPARAM)ttmath::err_still_calculating, 0);
|
PostMessage(main_window, WM_SET_LAST_ERROR, (WPARAM)ttmath::err_still_calculating, 0);
|
||||||
|
|
||||||
|
// we're showing info about converting
|
||||||
|
parser_manager.ShowConvertingInfo();
|
||||||
|
|
||||||
// and finally we're parsing the input string
|
// and finally we're parsing the input string
|
||||||
parser_manager.Parse();
|
parser_manager.Parse();
|
||||||
|
|
||||||
|
|
|
@ -230,12 +230,13 @@ void Languages::InitGuiMessagesTab()
|
||||||
InsertGuiPair(tab_convert,"Convert");
|
InsertGuiPair(tab_convert,"Convert");
|
||||||
|
|
||||||
InsertGuiPair(radio_precision_1,"Small - 96 bits for the mantissa, 32 bits for the exponent");
|
InsertGuiPair(radio_precision_1,"Small - 96 bits for the mantissa, 32 bits for the exponent");
|
||||||
InsertGuiPair(radio_precision_2,"Medium - 192 bits for the mantissa, 64 bits for the exponent");
|
InsertGuiPair(radio_precision_2,"Medium - 288 bits for the mantissa, 64 bits for the exponent");
|
||||||
InsertGuiPair(radio_precision_3,"Big - 288 bits for the mantissa, 96 bits for the exponent");
|
InsertGuiPair(radio_precision_3,"Big - 864 bits for the mantissa, 128 bits for the exponent");
|
||||||
|
|
||||||
|
|
||||||
InsertGuiPair(precision_1_info,"(+/-)6.9 e+646457021, 26 valid digits (decimal)");
|
InsertGuiPair(precision_1_info,"(+/-)6.9 e+646457021, 26 valid digits (decimal)");
|
||||||
InsertGuiPair(precision_2_info,"(+/-)4.3 e+2776511644261678623, 56 valid digits");
|
InsertGuiPair(precision_2_info,"(+/-)3.4e+2776511644261678652, 85 valid digits");
|
||||||
InsertGuiPair(precision_3_info,"(+/-)2.5 e+11925026709067095507636213441, 85 valid digits");
|
InsertGuiPair(precision_3_info,"(+/-)6.7e+51217599719369681875006054625051616609, 258 digits");
|
||||||
|
|
||||||
InsertGuiPair(overflow_during_printing,"Overflow during printing");
|
InsertGuiPair(overflow_during_printing,"Overflow during printing");
|
||||||
|
|
||||||
|
@ -351,12 +352,12 @@ void Languages::InitGuiMessagesTab()
|
||||||
InsertGuiPair(tab_convert,"Konwersja");
|
InsertGuiPair(tab_convert,"Konwersja");
|
||||||
|
|
||||||
InsertGuiPair(radio_precision_1,"Ma³a - 96 bitowa mantysa, 32 bitowy wyk³adnik");
|
InsertGuiPair(radio_precision_1,"Ma³a - 96 bitowa mantysa, 32 bitowy wyk³adnik");
|
||||||
InsertGuiPair(radio_precision_2,"Œrednia - 192 bitowa mantysa, 64 bitowy wyk³adnik");
|
InsertGuiPair(radio_precision_2,"Œrednia - 288 bitowa mantysa, 64 bitowy wyk³adnik");
|
||||||
InsertGuiPair(radio_precision_3,"Du¿a - 288 bitowa mantysa, 96 bitowy wyk³adnik");
|
InsertGuiPair(radio_precision_3,"Du¿a - 864 bitowa mantysa, 128 bitowy wyk³adnik");
|
||||||
|
|
||||||
InsertGuiPair(precision_1_info,"(+/-)6.9 e+646457021, 26 cyfr znacz¹cych (w rozwiniêciu dziesiêtnym)");
|
InsertGuiPair(precision_1_info,"(+/-)6.9e+646457021, 26 cyfr znacz¹cych (w rozwiniêciu dziesiêtnym)");
|
||||||
InsertGuiPair(precision_2_info,"(+/-)4.3 e+2776511644261678623, 56 cyfr znacz¹cych");
|
InsertGuiPair(precision_2_info,"(+/-)3.4e+2776511644261678652, 85 cyfr znacz¹cych");
|
||||||
InsertGuiPair(precision_3_info,"(+/-)2.5 e+11925026709067095507636213441, 85 cyfr znacz¹cych");
|
InsertGuiPair(precision_3_info,"(+/-)6.7e+51217599719369681875006054625051616609, 258 cyfr");
|
||||||
|
|
||||||
InsertGuiPair(overflow_during_printing,"Przepe³nienie podczas wypisywania");
|
InsertGuiPair(overflow_during_printing,"Przepe³nienie podczas wypisywania");
|
||||||
|
|
||||||
|
@ -446,26 +447,28 @@ void Languages::ConvertingAddType(const char * name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Languages::ConvertingAddUnit(const char * name, double v)
|
void Languages::ConvertingAddUnit(const char * name, const char * abbr, double v)
|
||||||
{
|
{
|
||||||
if( converting_type.empty() || converting_type.back().empty() || converting_unit.empty() )
|
if( converting_type.empty() || converting_type.back().empty() || converting_unit.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ConvUnit temp;
|
ConvUnit temp;
|
||||||
temp.name = name;
|
temp.name = name;
|
||||||
|
temp.abbr = abbr;
|
||||||
temp.type = static_cast<int>(converting_type.back().size()-1);
|
temp.type = static_cast<int>(converting_type.back().size()-1);
|
||||||
temp.value.FromDouble(v);
|
temp.value.FromDouble(v);
|
||||||
|
|
||||||
converting_unit.back().push_back(temp);
|
converting_unit.back().push_back(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Languages::ConvertingAddUnit(const char * name, const char * v)
|
void Languages::ConvertingAddUnit(const char * name, const char * abbr, const char * v)
|
||||||
{
|
{
|
||||||
if( converting_type.empty() || converting_type.back().empty() || converting_unit.empty() )
|
if( converting_type.empty() || converting_type.back().empty() || converting_unit.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ConvUnit temp;
|
ConvUnit temp;
|
||||||
temp.name = name;
|
temp.name = name;
|
||||||
|
temp.abbr = abbr;
|
||||||
temp.type = static_cast<int>(converting_type.back().size()-1);
|
temp.type = static_cast<int>(converting_type.back().size()-1);
|
||||||
temp.value.FromString(v, 16);
|
temp.value.FromString(v, 16);
|
||||||
|
|
||||||
|
@ -490,13 +493,13 @@ void Languages::InitConverting()
|
||||||
defined the length of the international yard to be precisely 0.9144 metres.
|
defined the length of the international yard to be precisely 0.9144 metres.
|
||||||
*/
|
*/
|
||||||
ConvertingAddType("length"); // base: 10000 metre
|
ConvertingAddType("length"); // base: 10000 metre
|
||||||
ConvertingAddUnit("inch", 254.0 );
|
ConvertingAddUnit("inch", "in", 254.0 );
|
||||||
ConvertingAddUnit("foot", 3048.0);
|
ConvertingAddUnit("foot", "ft", 3048.0);
|
||||||
ConvertingAddUnit("yard", 9144.0);
|
ConvertingAddUnit("yard", "yd", 9144.0);
|
||||||
ConvertingAddUnit("metre", 10000.0 );
|
ConvertingAddUnit("metre", "m", 10000.0 );
|
||||||
ConvertingAddUnit("mile (land)", 16093440.0); // 1 land mile = 1609.344 metres
|
ConvertingAddUnit("mile (land)", "mi", 16093440.0); // 1 land mile = 1609.344 metres
|
||||||
ConvertingAddUnit("mile (nautical)", 18520000.0); // 1 nautical mile = 1852 metres
|
ConvertingAddUnit("mile (nautical)", "nmi", 18520000.0); // 1 nautical mile = 1852 metres
|
||||||
ConvertingAddUnit("light year", "520F0AA65AAEBAC00"); // 1 ly = 9 460 730 472 580 800 metres
|
ConvertingAddUnit("light year", "ly", "520F0AA65AAEBAC00"); // 1 ly = 9 460 730 472 580 800 metres
|
||||||
// 520F0AA65AAEBAC00 (hex) = 94607304725808000000 (dec)
|
// 520F0AA65AAEBAC00 (hex) = 94607304725808000000 (dec)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -508,43 +511,31 @@ void Languages::InitConverting()
|
||||||
hectere = 10000 metre^2
|
hectere = 10000 metre^2
|
||||||
*/
|
*/
|
||||||
ConvertingAddType("area"); // base: 100 000 000 metre^2
|
ConvertingAddType("area"); // base: 100 000 000 metre^2
|
||||||
ConvertingAddUnit("inch^2", 64516.0);
|
ConvertingAddUnit("inch^2", "in^2", 64516.0);
|
||||||
ConvertingAddUnit("foot^2", 9290304.0);
|
ConvertingAddUnit("foot^2", "ft^2", 9290304.0);
|
||||||
ConvertingAddUnit("yard^2", 83612736.0);
|
ConvertingAddUnit("yard^2", "yd^2", 83612736.0);
|
||||||
ConvertingAddUnit("metre^2", 100000000.0);
|
ConvertingAddUnit("metre^2", "m^2", 100000000.0);
|
||||||
ConvertingAddUnit("are", 10000000000.0);
|
ConvertingAddUnit("are", "a", 10000000000.0);
|
||||||
ConvertingAddUnit("hectare", 1000000000000.0);
|
ConvertingAddUnit("hectare", "ha", 1000000000000.0);
|
||||||
ConvertingAddUnit("mile (land)^2", 258998811033600.0 ); // 1 land mile^2 = 2589988.110336 metres^2
|
ConvertingAddUnit("mile (land)^2", "mi^2", 258998811033600.0 ); // 1 land mile^2 = 2589988.110336 metres^2
|
||||||
ConvertingAddUnit("mile (nautical)^2", 342990400000000.0); // 1 nautical mile^2 = 3429904 metres^2
|
ConvertingAddUnit("mile (nautical)^2", "nmi^2", 342990400000000.0); // 1 nautical mile^2 = 3429904 metres^2
|
||||||
ConvertingAddUnit("light year^2", "1A4DA3B4D207FB4C43D08391653B900000"); // 1 ly = 89505421074818927300612528640000 metres^2
|
ConvertingAddUnit("light year^2", "ly^2", "1A4DA3B4D207FB4C43D08391653B900000"); // 1 ly = 89505421074818927300612528640000 metres^2
|
||||||
// 1A4DA3B4D207FB4C43D08391653B900000 (hex) = 8950542107481892730061252864000000000000 (dec)
|
// 1A4DA3B4D207FB4C43D08391653B900000 (hex) = 8950542107481892730061252864000000000000 (dec)
|
||||||
|
|
||||||
ConvertingAddType("time"); // base: second
|
ConvertingAddType("time"); // base: second
|
||||||
ConvertingAddUnit("second", 1.0);
|
ConvertingAddUnit("second", "s", 1.0);
|
||||||
ConvertingAddUnit("minute", 60.0);
|
ConvertingAddUnit("minute", "m", 60.0);
|
||||||
ConvertingAddUnit("hour", 3600.0);
|
ConvertingAddUnit("hour", "h", 3600.0);
|
||||||
ConvertingAddUnit("day", 86400.0);
|
ConvertingAddUnit("day", "d", 86400.0);
|
||||||
ConvertingAddUnit("week", 604800.0);
|
ConvertingAddUnit("week", "w", 604800.0);
|
||||||
ConvertingAddUnit("fortnight", 1209600.0);
|
ConvertingAddUnit("fortnight", "fn", 1209600.0);
|
||||||
ConvertingAddUnit("month", 2592000.0);
|
ConvertingAddUnit("month", "m", 2592000.0);
|
||||||
ConvertingAddUnit("year", 31536000.0);
|
ConvertingAddUnit("year", "y", 31536000.0);
|
||||||
ConvertingAddUnit("year (mean)", 31557600.0);
|
ConvertingAddUnit("year (mean)", "my", 31557600.0);
|
||||||
ConvertingAddUnit("year (leap)", 31622400.0);
|
ConvertingAddUnit("year (leap)", "ly", 31622400.0);
|
||||||
ConvertingAddUnit("decade", 315360000.0);
|
ConvertingAddUnit("decade", "dc", 315360000.0);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
ConvertingAddUnit("", );
|
|
||||||
*/
|
|
||||||
|
|
||||||
// pl
|
// pl
|
||||||
// the 'value' param we're using only from the english
|
// the 'value' param we're using only from the english
|
||||||
|
@ -554,37 +545,37 @@ void Languages::InitConverting()
|
||||||
ConvertingAddType("brak");
|
ConvertingAddType("brak");
|
||||||
|
|
||||||
ConvertingAddType("d³ugoœæ");
|
ConvertingAddType("d³ugoœæ");
|
||||||
ConvertingAddUnit("cal", 0.0 );
|
ConvertingAddUnit("cal", "", 0.0 );
|
||||||
ConvertingAddUnit("stopa", 0.0);
|
ConvertingAddUnit("stopa", "", 0.0);
|
||||||
ConvertingAddUnit("jard", 0.0);
|
ConvertingAddUnit("jard", "", 0.0);
|
||||||
ConvertingAddUnit("metr", 0.0);
|
ConvertingAddUnit("metr", "", 0.0);
|
||||||
ConvertingAddUnit("mila (angielska)", 0.0);
|
ConvertingAddUnit("mila (angielska)", "", 0.0);
|
||||||
ConvertingAddUnit("mila (morska)", 0.0);
|
ConvertingAddUnit("mila (morska)", "", 0.0);
|
||||||
ConvertingAddUnit("rok œwietlny", 0.0);
|
ConvertingAddUnit("rok œwietlny", "", 0.0);
|
||||||
|
|
||||||
ConvertingAddType("powierzchnia");
|
ConvertingAddType("powierzchnia");
|
||||||
ConvertingAddUnit("cal^2", 0.0);
|
ConvertingAddUnit("cal^2", "", 0.0);
|
||||||
ConvertingAddUnit("stopa^2", 0.0);
|
ConvertingAddUnit("stopa^2", "", 0.0);
|
||||||
ConvertingAddUnit("jard^2", 0.0);
|
ConvertingAddUnit("jard^2", "", 0.0);
|
||||||
ConvertingAddUnit("metr^2", 0.0);
|
ConvertingAddUnit("metr^2", "", 0.0);
|
||||||
ConvertingAddUnit("ar", 0.0);
|
ConvertingAddUnit("ar", "", 0.0);
|
||||||
ConvertingAddUnit("hektar", 0.0);
|
ConvertingAddUnit("hektar", "", 0.0);
|
||||||
ConvertingAddUnit("mila (angielska)^2", 0.0);
|
ConvertingAddUnit("mila (angielska)^2", "", 0.0);
|
||||||
ConvertingAddUnit("mila (morska)^2", 0.0);
|
ConvertingAddUnit("mila (morska)^2", "", 0.0);
|
||||||
ConvertingAddUnit("rok œwietlny^2", 0.0);
|
ConvertingAddUnit("rok œwietlny^2", "", 0.0);
|
||||||
|
|
||||||
ConvertingAddType("czas");
|
ConvertingAddType("czas");
|
||||||
ConvertingAddUnit("sekunda", 0.0);
|
ConvertingAddUnit("sekunda", "", 0.0);
|
||||||
ConvertingAddUnit("minuta", 0.0);
|
ConvertingAddUnit("minuta", "", 0.0);
|
||||||
ConvertingAddUnit("godzina", 0.0);
|
ConvertingAddUnit("godzina", "", 0.0);
|
||||||
ConvertingAddUnit("dzieñ", 0.0);
|
ConvertingAddUnit("dzieñ", "", 0.0);
|
||||||
ConvertingAddUnit("tydzieñ", 0.0);
|
ConvertingAddUnit("tydzieñ", "", 0.0);
|
||||||
ConvertingAddUnit("dwa tygodnie", 0.0);
|
ConvertingAddUnit("dwa tygodnie", "", 0.0);
|
||||||
ConvertingAddUnit("miesi¹c", 0.0);
|
ConvertingAddUnit("miesi¹c", "", 0.0);
|
||||||
ConvertingAddUnit("rok", 0.0);
|
ConvertingAddUnit("rok", "", 0.0);
|
||||||
ConvertingAddUnit("rok (œredni)", 0.0);
|
ConvertingAddUnit("rok (œredni)", "", 0.0);
|
||||||
ConvertingAddUnit("rok (przestêpny)", 0.0);
|
ConvertingAddUnit("rok (przestêpny)", "", 0.0);
|
||||||
ConvertingAddUnit("dekada", 0.0);
|
ConvertingAddUnit("dekada", "", 0.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,6 +615,25 @@ const char * unk_err = "unknown";
|
||||||
return converting_unit[cid][id].name.c_str();
|
return converting_unit[cid][id].name.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Languages::ConvertingUnitAbbr(Country country, int id)
|
||||||
|
{
|
||||||
|
const char * unk_err = "unknown";
|
||||||
|
|
||||||
|
if( converting_unit.empty() )
|
||||||
|
InitConverting();
|
||||||
|
|
||||||
|
unsigned int cid = static_cast<unsigned int>( country );
|
||||||
|
if( cid >= converting_unit.size() )
|
||||||
|
return unk_err;
|
||||||
|
|
||||||
|
if( id < 0 || id >= static_cast<int>(converting_unit[cid].size()) )
|
||||||
|
return unk_err;
|
||||||
|
|
||||||
|
//return converting_unit[cid][id].abbr.c_str();
|
||||||
|
// at the moment abbreviations we get only from english
|
||||||
|
return converting_unit[0][id].abbr.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * Languages::ConvertingType(int id)
|
const char * Languages::ConvertingType(int id)
|
||||||
{
|
{
|
||||||
|
@ -636,6 +646,10 @@ const char * Languages::ConvertingUnit(int id)
|
||||||
return ConvertingUnit(current_country, id);
|
return ConvertingUnit(current_country, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * Languages::ConvertingUnitAbbr(int id)
|
||||||
|
{
|
||||||
|
return ConvertingUnitAbbr(current_country, id);
|
||||||
|
}
|
||||||
|
|
||||||
int Languages::ConvertingTypeSize(Country country)
|
int Languages::ConvertingTypeSize(Country country)
|
||||||
{
|
{
|
||||||
|
|
|
@ -155,7 +155,7 @@ public:
|
||||||
|
|
||||||
struct ConvUnit
|
struct ConvUnit
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name, abbr;
|
||||||
// int id;
|
// int id;
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
|
@ -185,8 +185,8 @@ private:
|
||||||
|
|
||||||
|
|
||||||
void ConvertingAddType(const char * name);
|
void ConvertingAddType(const char * name);
|
||||||
void ConvertingAddUnit(const char * name, double v);
|
void ConvertingAddUnit(const char * name, const char * abbr, double v);
|
||||||
void ConvertingAddUnit(const char * name, const char * v);
|
void ConvertingAddUnit(const char * name, const char * abbr, const char * v);
|
||||||
|
|
||||||
void InitConverting();
|
void InitConverting();
|
||||||
|
|
||||||
|
@ -208,23 +208,63 @@ public:
|
||||||
return current_country;
|
return current_country;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * ErrorMessage(Country country, ttmath::ErrorCode code);
|
|
||||||
const char * ErrorMessage(ttmath::ErrorCode code);
|
|
||||||
const char * GuiMessage(Country country, GuiMsg code);
|
|
||||||
const char * GuiMessage(GuiMsg code);
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
we're using some methods from this class simultaneously in two threads,
|
||||||
|
this is to be sure that everything is initialized before the second thread is started
|
||||||
|
|
||||||
|
should be called before calling the second thread
|
||||||
|
*/
|
||||||
|
void InitAll()
|
||||||
|
{
|
||||||
|
InitErrorMessagesTab();
|
||||||
|
InitGuiMessagesTab();
|
||||||
|
InitConverting();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
long form of methods
|
||||||
|
(with 'coutry')
|
||||||
|
|
||||||
|
these methods you can call from the second thread without having to
|
||||||
|
calling StopCalculating() and StartCalculating() from the thread controller
|
||||||
|
|
||||||
|
the methods return only static value - remember to call InitAll() somewhere
|
||||||
|
at the beginning e.g. in the first thread
|
||||||
|
*/
|
||||||
|
const char * ErrorMessage(Country country, ttmath::ErrorCode code);
|
||||||
|
const char * GuiMessage(Country country, GuiMsg code);
|
||||||
const char * ConvertingType(Country country, int id);
|
const char * ConvertingType(Country country, int id);
|
||||||
const char * ConvertingUnit(Country country, int id);
|
const char * ConvertingUnit(Country country, int id);
|
||||||
|
const char * ConvertingUnitAbbr(Country country, int id);
|
||||||
int ConvertingUnitType(Country country, int id);
|
int ConvertingUnitType(Country country, int id);
|
||||||
int ConvertingTypeSize(Country country);
|
int ConvertingTypeSize(Country country);
|
||||||
int ConvertingUnitSize(Country country);
|
int ConvertingUnitSize(Country country);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
short form of methods
|
||||||
|
(without 'country' - it's taken from a private variable 'current_country')
|
||||||
|
|
||||||
|
don't use these methods in the second thread - the parameter 'country' can be using
|
||||||
|
by the first thread, although the 'country' is simply enum and should be atomic
|
||||||
|
but in the future it may be changed
|
||||||
|
*/
|
||||||
|
const char * ErrorMessage(ttmath::ErrorCode code);
|
||||||
|
const char * GuiMessage(GuiMsg code);
|
||||||
const char * ConvertingType(int id);
|
const char * ConvertingType(int id);
|
||||||
const char * ConvertingUnit(int id);
|
const char * ConvertingUnit(int id);
|
||||||
|
const char * ConvertingUnitAbbr(int id);
|
||||||
int ConvertingUnitType(int id);
|
int ConvertingUnitType(int id);
|
||||||
int ConvertingTypeSize();
|
int ConvertingTypeSize();
|
||||||
int ConvertingUnitSize();
|
int ConvertingUnitSize();
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
the return value is the same for all languages
|
||||||
|
(in fact we're taking it from english)
|
||||||
|
*/
|
||||||
const ConvUnit::ValueType & ConvertingUnitValue(int id);
|
const ConvUnit::ValueType & ConvertingUnitValue(int id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "compileconfig.h"
|
#include "compileconfig.h"
|
||||||
#include "parsermanager.h"
|
#include "parsermanager.h"
|
||||||
|
#include "tabs.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,6 +149,9 @@ unsigned int i;
|
||||||
precision = GetPrgRes()->GetPrecision();
|
precision = GetPrgRes()->GetPrecision();
|
||||||
|
|
||||||
country = GetPrgRes()->GetLanguages()->GetCurrentLanguage();
|
country = GetPrgRes()->GetLanguages()->GetCurrentLanguage();
|
||||||
|
|
||||||
|
conv_type = GetPrgRes()->GetConvType();
|
||||||
|
GetPrgRes()->GetConvUnit(conv_type, conv_input_unit, conv_output_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,36 +197,71 @@ int ParserManager::PrintResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
return PrintResult(parser1);
|
return PrintResult(parser1);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ParserManager::ShowConvertingInfo()
|
||||||
|
{
|
||||||
|
HWND conv_tab = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_convert);
|
||||||
|
|
||||||
|
if( conv_type==0 || conv_input_unit==-1 || conv_output_unit==-1 ||
|
||||||
|
conv_input_unit == conv_output_unit )
|
||||||
{
|
{
|
||||||
// we can call GetPrgRes() here because we're reading
|
SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "");
|
||||||
// static value like GetMainWindow() which are set only once
|
return;
|
||||||
// at the beginning of the program and will never be changed later
|
|
||||||
// by the first thread
|
|
||||||
|
|
||||||
// note that we're using a long form of a method ErrorMessage i.g.
|
|
||||||
// ErrorMessage(Country country, ttmath::ErrorCode code)
|
|
||||||
// and not ErrorMessage(ttmath::ErrorCode code)
|
|
||||||
// because someone can change the country when we're calling this method
|
|
||||||
// (in the main thread) and the latter function would be using its own
|
|
||||||
// 'current_country' value which could be inconsistent
|
|
||||||
|
|
||||||
// now, displying an error message is making in the main windows
|
|
||||||
// (after pressing a special key)
|
|
||||||
|
|
||||||
/*
|
|
||||||
SetDlgItemText(
|
|
||||||
GetPrgRes()->GetMainWindow(),
|
|
||||||
IDC_OUTPUT_EDIT,
|
|
||||||
GetPrgRes()->GetLanguages()->ErrorMessage(country, code) );
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Languages * plang = GetPrgRes()->GetLanguages();
|
||||||
|
|
||||||
return 0;
|
// the first unit to the second
|
||||||
}
|
|
||||||
|
std::string buffer1 = "1 ";
|
||||||
|
|
||||||
|
buffer1 += plang->ConvertingUnitAbbr(country, conv_input_unit);
|
||||||
|
buffer1 += " = ";
|
||||||
|
|
||||||
|
ttmath::Big<1,1> value_input, value_output, result;
|
||||||
|
value_input = plang->ConvertingUnitValue(conv_input_unit);
|
||||||
|
value_output = plang->ConvertingUnitValue(conv_output_unit);
|
||||||
|
result = value_input;
|
||||||
|
|
||||||
|
if( result.Div(value_output) )
|
||||||
|
{
|
||||||
|
SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.ToString(buffer2,10,false,3,-2);
|
||||||
|
|
||||||
|
buffer1 += buffer2;
|
||||||
|
buffer1 += " ";
|
||||||
|
buffer1 += plang->ConvertingUnitAbbr(country, conv_output_unit);
|
||||||
|
|
||||||
|
// the second unit to the first
|
||||||
|
|
||||||
|
buffer1 += " 1 ";
|
||||||
|
buffer1 += plang->ConvertingUnitAbbr(country, conv_output_unit);
|
||||||
|
buffer1 += " = ";
|
||||||
|
|
||||||
|
result = value_output;
|
||||||
|
if( result.Div(value_input) )
|
||||||
|
{
|
||||||
|
SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.ToString(buffer2,10,false,3,-2);
|
||||||
|
|
||||||
|
buffer1 += buffer2;
|
||||||
|
buffer1 += " ";
|
||||||
|
buffer1 += plang->ConvertingUnitAbbr(country, conv_input_unit);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, buffer1.c_str() );
|
||||||
|
}
|
||||||
|
|
|
@ -103,6 +103,12 @@ public:
|
||||||
int PrintResult();
|
int PrintResult();
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
this method prints the info about converting (on the converting tab)
|
||||||
|
*/
|
||||||
|
void ShowConvertingInfo();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
#ifndef TTCALC_PORTABLE
|
#ifndef TTCALC_PORTABLE
|
||||||
|
@ -115,7 +121,7 @@ private:
|
||||||
*/
|
*/
|
||||||
ttmath::Parser<ttmath::Big<1,3> > parser1;
|
ttmath::Parser<ttmath::Big<1,3> > parser1;
|
||||||
ttmath::Parser<ttmath::Big<2,9> > parser2;
|
ttmath::Parser<ttmath::Big<2,9> > parser2;
|
||||||
ttmath::Parser<ttmath::Big<3,27> > parser3;
|
ttmath::Parser<ttmath::Big<4,27> > parser3;
|
||||||
#else
|
#else
|
||||||
ttmath::Parser<ttmath::Big<1,3> > parser1;
|
ttmath::Parser<ttmath::Big<1,3> > parser1;
|
||||||
#endif
|
#endif
|
||||||
|
@ -126,6 +132,7 @@ private:
|
||||||
char * buffer;
|
char * buffer;
|
||||||
|
|
||||||
int base_input, base_output;
|
int base_input, base_output;
|
||||||
|
int conv_type, conv_input_unit, conv_output_unit;
|
||||||
|
|
||||||
bool always_scientific;
|
bool always_scientific;
|
||||||
int when_scientific;
|
int when_scientific;
|
||||||
|
@ -135,44 +142,61 @@ private:
|
||||||
ttmath::ErrorCode code;
|
ttmath::ErrorCode code;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
some buffers which we use in some method in the second thread,
|
||||||
|
it's better to have those buffers outside those methods -
|
||||||
|
if the buffers were in the methods there would be still allocating
|
||||||
|
and deallocating memory
|
||||||
|
*/
|
||||||
|
std::string buffer1, buffer2;
|
||||||
|
|
||||||
|
|
||||||
|
bool CanWeConvert() const
|
||||||
|
{
|
||||||
|
if( conv_type != 0 )
|
||||||
|
if( conv_input_unit!=-1 && conv_output_unit!=-1 &&
|
||||||
|
conv_input_unit!=conv_output_unit )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
int Conversion(ValueType & result)
|
int Conversion(ValueType & result)
|
||||||
{
|
{
|
||||||
int convtype = GetPrgRes()->GetConvType();
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
if( convtype != 0 )
|
if( CanWeConvert() )
|
||||||
{
|
{
|
||||||
int input, output;
|
ValueType vinput, voutput;
|
||||||
GetPrgRes()->GetConvUnit(convtype, input, output);
|
|
||||||
|
|
||||||
if( input!=-1 && output!=-1 && input!=output )
|
vinput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(conv_input_unit) );
|
||||||
{
|
voutput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(conv_output_unit) );
|
||||||
ValueType vinput, voutput;
|
|
||||||
|
|
||||||
vinput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(input) );
|
c += result.Mul(vinput);
|
||||||
voutput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(output) );
|
c += result.Div(voutput);
|
||||||
|
|
||||||
c += result.Mul(vinput);
|
|
||||||
c += result.Div(voutput);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddOutputSuffix(std::string & result)
|
||||||
|
{
|
||||||
|
if( CanWeConvert() )
|
||||||
|
{
|
||||||
|
result += " ";
|
||||||
|
result += GetPrgRes()->GetLanguages()->ConvertingUnitAbbr(country, conv_output_unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 1 if carry
|
// 1 if carry
|
||||||
template<class ValueType>
|
template<class ValueType>
|
||||||
int PrintResult(ttmath::Parser<ValueType> & matparser)
|
int PrintResult(ttmath::Parser<ValueType> & matparser)
|
||||||
{
|
{
|
||||||
std::string result, part;
|
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
|
||||||
|
buffer1.erase();
|
||||||
|
buffer2.erase();
|
||||||
|
|
||||||
for(i=0 ; i<matparser.stack.size() ; ++i)
|
for(i=0 ; i<matparser.stack.size() ; ++i)
|
||||||
{
|
{
|
||||||
|
@ -185,25 +209,26 @@ private:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( result.ToString(part,base_output, always_scientific, when_scientific, rounding) )
|
if( result.ToString(buffer2,base_output, always_scientific, when_scientific, rounding) )
|
||||||
{
|
{
|
||||||
// we shouldn't have had this error in the new version of ToStrign(...)
|
// we shouldn't have had this error in the new version of ToStrign(...)
|
||||||
// (where we're using a bigger type for calculating)
|
// (where we're using a bigger type for calculating)
|
||||||
part = GetPrgRes()->GetLanguages()->GuiMessage(country, Languages::overflow_during_printing);
|
buffer2 = GetPrgRes()->GetLanguages()->GuiMessage(country, Languages::overflow_during_printing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
part = GetPrgRes()->GetLanguages()->ErrorMessage(country, ttmath::err_internal_error);
|
buffer2 = GetPrgRes()->GetLanguages()->ErrorMessage(country, ttmath::err_internal_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
result += part;
|
buffer1 += buffer2;
|
||||||
|
AddOutputSuffix(buffer1);
|
||||||
|
|
||||||
if( i < matparser.stack.size()-1 )
|
if( i < matparser.stack.size()-1 )
|
||||||
result += " ";
|
buffer1 += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,result.c_str());
|
SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,buffer1.c_str());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
80
src/tabs.cpp
80
src/tabs.cpp
|
@ -546,6 +546,7 @@ HWND list1 = GetDlgItem(hWnd, IDC_LIST_UNIT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
we must check whether the item id is really selected
|
we must check whether the item id is really selected
|
||||||
(this method is called from WM_NOTIFY and can be another states on the item)
|
(this method is called from WM_NOTIFY and can be another states on the item)
|
||||||
|
@ -1405,14 +1406,6 @@ void SetSizeOfFunctionsList(HWND tab, int tabx, int taby, int borderx, int borde
|
||||||
SetSizeOfFunctionVariableList(tab, tabx, taby, borderx, bordery, TabWindowFunctions::tab_functions, IDC_FUNCTIONS_LIST, 2);
|
SetSizeOfFunctionVariableList(tab, tabx, taby, borderx, bordery, TabWindowFunctions::tab_functions, IDC_FUNCTIONS_LIST, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void SetSizeOfConvertingLists()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void SetSizeOfConvertingLists(HWND tab, int tabx, int taby, int borderx, int bordery)
|
void SetSizeOfConvertingLists(HWND tab, int tabx, int taby, int borderx, int bordery)
|
||||||
{
|
{
|
||||||
|
@ -1423,8 +1416,8 @@ POINT p;
|
||||||
HWND list1 = GetDlgItem(dialog, IDC_LIST_UNIT_TYPE);
|
HWND list1 = GetDlgItem(dialog, IDC_LIST_UNIT_TYPE);
|
||||||
HWND info_edit = GetDlgItem(dialog, IDC_EDIT_OUTPUT_INFO);
|
HWND info_edit = GetDlgItem(dialog, IDC_EDIT_OUTPUT_INFO);
|
||||||
HWND check_dynamic_output = GetDlgItem(dialog, IDC_COMBO_DYNAMIC_OUTPUT);
|
HWND check_dynamic_output = GetDlgItem(dialog, IDC_COMBO_DYNAMIC_OUTPUT);
|
||||||
int move_flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER;
|
int move_flags = SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER;
|
||||||
int resize_flags = SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER;
|
int move_resize_flags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER;
|
||||||
|
|
||||||
POINT dialog_new_size = ResizeTabDialog(tab, dialog, tabx, taby, borderx, bordery);
|
POINT dialog_new_size = ResizeTabDialog(tab, dialog, tabx, taby, borderx, bordery);
|
||||||
|
|
||||||
|
@ -1433,40 +1426,63 @@ POINT p;
|
||||||
GetWindowRect(list1, &r);
|
GetWindowRect(list1, &r);
|
||||||
p.x = r.left;
|
p.x = r.left;
|
||||||
p.y = r.top;
|
p.y = r.top;
|
||||||
ScreenToClient(tab,&p);
|
ScreenToClient(dialog,&p);
|
||||||
int newy = taby - bordery - (r_edit.bottom-r_edit.top)-p.y-6;
|
|
||||||
SetWindowPos(list1, 0, 0, 0, r.right-r.left, newy, resize_flags);
|
GetWindowRect(dialog, &r);
|
||||||
|
int newy = (r.bottom-r.top) - bordery - (r_edit.bottom-r_edit.top) - p.y;
|
||||||
|
int list1_x = p.x;
|
||||||
|
|
||||||
|
int list2a_cx = tabx/7;
|
||||||
|
int list2b_cx = tabx/5;
|
||||||
|
int list3a_cx = tabx/7;
|
||||||
|
int list3b_cx = tabx/5;
|
||||||
|
|
||||||
|
int marginx = 4;
|
||||||
|
int list1_cx = tabx - list2a_cx - list2b_cx - list3a_cx - list3b_cx - marginx*4 - borderx - 8;
|
||||||
|
|
||||||
|
SetWindowPos(list1, 0, list1_x, p.y, list1_cx, newy, move_resize_flags);
|
||||||
|
|
||||||
HWND list2a = GetDlgItem(dialog, IDC_LIST_UNIT_INPUT1);
|
HWND list2a = GetDlgItem(dialog, IDC_LIST_UNIT_INPUT1);
|
||||||
HWND list2b = GetDlgItem(dialog, IDC_LIST_UNIT_INPUT2);
|
HWND list2b = GetDlgItem(dialog, IDC_LIST_UNIT_INPUT2);
|
||||||
HWND list3a = GetDlgItem(dialog, IDC_LIST_UNIT_OUTPUT1);
|
HWND list3a = GetDlgItem(dialog, IDC_LIST_UNIT_OUTPUT1);
|
||||||
HWND list3b = GetDlgItem(dialog, IDC_LIST_UNIT_OUTPUT2);
|
HWND list3b = GetDlgItem(dialog, IDC_LIST_UNIT_OUTPUT2);
|
||||||
|
|
||||||
GetWindowRect(list2a, &r);
|
int list2a_x = list1_x + list1_cx + marginx;
|
||||||
SetWindowPos(list2a, 0, 0, 0, r.right-r.left, newy, resize_flags);
|
int list2b_x = list2a_x + list2a_cx + marginx;
|
||||||
|
int list3a_x = list2b_x + list2b_cx + marginx;
|
||||||
|
int list3b_x = list3a_x + list3a_cx + marginx;
|
||||||
|
|
||||||
GetWindowRect(list2b, &r);
|
SetWindowPos(list2a, 0, list2a_x, p.y, list2a_cx, newy, move_resize_flags);
|
||||||
SetWindowPos(list2b, 0, 0, 0, r.right-r.left, newy, resize_flags);
|
SetWindowPos(list2b, 0, list2b_x, p.y, list2b_cx, newy, move_resize_flags);
|
||||||
|
SetWindowPos(list3a, 0, list3a_x, p.y, list3a_cx, newy, move_resize_flags);
|
||||||
|
SetWindowPos(list3b, 0, list3b_x, p.y, list3b_cx, newy, move_resize_flags);
|
||||||
|
|
||||||
GetWindowRect(list3a, &r);
|
|
||||||
SetWindowPos(list3a, 0, 0, 0, r.right-r.left, newy, resize_flags);
|
|
||||||
|
|
||||||
GetWindowRect(list3b, &r);
|
|
||||||
SetWindowPos(list3b, 0, 0, 0, r.right-r.left, newy, resize_flags);
|
|
||||||
|
|
||||||
|
|
||||||
p.x = r_edit.left;
|
|
||||||
p.y = r_edit.top;
|
|
||||||
ScreenToClient(dialog,&p);
|
|
||||||
newy = dialog_new_size.y -(r_edit.bottom-r_edit.top);
|
newy = dialog_new_size.y -(r_edit.bottom-r_edit.top);
|
||||||
SetWindowPos(info_edit, 0, p.x, newy, 0, 0, move_flags);
|
int info_edit_cx = list1_cx + list2a_cx + list2b_cx + marginx*2;
|
||||||
|
SetWindowPos(info_edit, 0, list1_x, newy, info_edit_cx, (r_edit.bottom-r_edit.top), move_resize_flags);
|
||||||
|
|
||||||
GetWindowRect(check_dynamic_output, &r);
|
SetWindowPos(check_dynamic_output, 0, list1_x + info_edit_cx + marginx, newy, 0, 0, move_flags);
|
||||||
|
|
||||||
|
HWND static_type = GetDlgItem(dialog, IDC_STATIC_UNIT_CONVERSION);
|
||||||
|
GetWindowRect(static_type, &r);
|
||||||
p.x = r.left;
|
p.x = r.left;
|
||||||
p.y = r.top;
|
p.y = r.top;
|
||||||
ScreenToClient(dialog,&p);
|
ScreenToClient(dialog, &p);
|
||||||
SetWindowPos(check_dynamic_output, 0, p.x, newy, 0, 0, move_flags);
|
SetWindowPos(static_type, 0, list1_x, p.y, 0, 0, move_flags);
|
||||||
|
|
||||||
|
HWND static_input = GetDlgItem(dialog, IDC_STATIC_UNIT_INPUT);
|
||||||
|
SetWindowPos(static_input, 0, list2a_x, p.y, 0, 0, move_flags);
|
||||||
|
|
||||||
|
HWND static_output = GetDlgItem(dialog, IDC_STATIC_UNIT_OUTPUT);
|
||||||
|
SetWindowPos(static_output, 0, list3a_x, p.y, 0, 0, move_flags);
|
||||||
|
|
||||||
|
// setting width of colums inside the lists
|
||||||
|
int vscroll_cx = GetSystemMetrics(SM_CXVSCROLL) + borderx;
|
||||||
|
ListView_SetColumnWidth(list1, 0, list1_cx - vscroll_cx);
|
||||||
|
ListView_SetColumnWidth(list2a, 0, list2a_cx - vscroll_cx);
|
||||||
|
ListView_SetColumnWidth(list2b, 0, list2b_cx - vscroll_cx);
|
||||||
|
ListView_SetColumnWidth(list3a, 0, list3a_cx - vscroll_cx);
|
||||||
|
ListView_SetColumnWidth(list3b, 0, list3b_cx - vscroll_cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,10 @@
|
||||||
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
|
||||||
{
|
{
|
||||||
GetPrgRes()->SetInstance(hInstance);
|
GetPrgRes()->SetInstance(hInstance);
|
||||||
|
|
||||||
|
// we're using GetLanguages() simultaneously in two threads, this is to be sure
|
||||||
|
// that everything is initialized before the second thread is started
|
||||||
|
GetPrgRes()->GetLanguages()->InitAll();
|
||||||
GetPrgRes()->GetLanguages()->SetCurrentLanguage(Languages::en);
|
GetPrgRes()->GetLanguages()->SetCurrentLanguage(Languages::en);
|
||||||
GetPrgRes()->SetNameOfConfigurationFile();
|
GetPrgRes()->SetNameOfConfigurationFile();
|
||||||
GetPrgRes()->ReadFromFile();
|
GetPrgRes()->ReadFromFile();
|
||||||
|
|
Loading…
Reference in New Issue