diff --git a/src/Makefile.dep b/src/Makefile.dep index fde54b5..044ba12 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep @@ -1,15 +1,17 @@ -o = resource.o calculation.o functions.o iniparser.o languages.o mainwindow.o parsermanager.o programresources.o tabs.o variables.o winmain.o +o = resource.o calculation.o convert.o functions.o iniparser.o languages.o mainwindow.o parsermanager.o programresources.o tabs.o variables.o winmain.o -calculation.o: calculation.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h tabs.h messages.h -functions.o: functions.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h +calculation.o: calculation.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h tabs.h messages.h +convert.o: convert.cpp convert.h compileconfig.h bigtypes.h +functions.o: functions.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h iniparser.o: iniparser.cpp compileconfig.h iniparser.h -languages.o: languages.cpp compileconfig.h languages.h -mainwindow.o: mainwindow.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h resource.h messages.h tabs.h -parsermanager.o: parsermanager.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -programresources.o: programresources.cpp compileconfig.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -tabs.o: tabs.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -variables.o: variables.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -winmain.o: winmain.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h resource.h messages.h tabs.h +languages.o: languages.cpp compileconfig.h languages.h bigtypes.h +mainwindow.o: mainwindow.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h resource.h messages.h tabs.h +parsermanager.o: parsermanager.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h tabs.h messages.h +programresources.o: programresources.cpp compileconfig.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h +tabs.o: tabs.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h +variables.o: variables.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h +winmain.o: winmain.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h bigtypes.h threadcontroller.h stopcalculating.h convert.h resource.h messages.h tabs.h + .SUFFIXES: .cpp .o diff --git a/src/Makefile.help.sh b/src/Makefile.help.sh index dfd2f69..19f0ef1 100644 --- a/src/Makefile.help.sh +++ b/src/Makefile.help.sh @@ -1,16 +1,16 @@ -#!/bin/sh - -# we provide a small wrapper for Html Help Workshop because the Html HW returns 1 when -# it has compiled the help and the 'make' program then stops - -hhc ../help/help.hhp - -if [ $? == 0 ] -then - # there was an error - exit 1 -fi - -# there was a success - -exit 0 +#!/bin/sh + +# we provide a small wrapper for Html Help Workshop because the Html HW returns 1 when +# it has compiled the help and the 'make' program then stops + +hhc ../help/help.hhp + +if [ $? == 0 ] +then + # there was an error + exit 1 +fi + +# there was a success + +exit 0 diff --git a/src/bigtypes.h b/src/bigtypes.h new file mode 100644 index 0000000..45a6a2e --- /dev/null +++ b/src/bigtypes.h @@ -0,0 +1,73 @@ +/* + * This file is a part of TTCalc - a mathematical calculator + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2006-2008, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef bigtypesheader +#define bigtypesheader + +#include "compileconfig.h" +#include + + +#ifndef TTCALC_PORTABLE + + /* + // old ones + ttmath::Big<1,3> + ttmath::Big<2,6> + ttmath::Big<3,9> + */ + + typedef ttmath::Big<1,3> TTMathBig1; + typedef ttmath::Big<2,9> TTMathBig2; + typedef ttmath::Big<4,27> TTMathBig3; + typedef TTMathBig3 TTMathBigMax; + + +#else + + /* portable */ + + typedef ttmath::Big<1,3> TTMathBig1; + typedef TTMathBig1 TTMathBigMax; + +#endif + + + + + +#endif diff --git a/src/calculation.cpp b/src/calculation.cpp index 7142b40..3416788 100644 --- a/src/calculation.cpp +++ b/src/calculation.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/compileconfig.h b/src/compileconfig.h index a589c3f..0a07304 100644 --- a/src/compileconfig.h +++ b/src/compileconfig.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/convert.cpp b/src/convert.cpp new file mode 100644 index 0000000..7cccb81 --- /dev/null +++ b/src/convert.cpp @@ -0,0 +1,444 @@ +/* + * This file is a part of TTCalc - a mathematical calculator + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2006-2008, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "convert.h" + + + +Convert::Convert() +{ + Init(); + current_conv_type = 0; + CheckCurrentUnits(); +} + + +void Convert::AddType(const char * name) +{ + if( type_tab.empty() ) + return; + + Type temp; + temp.name = name; + + type_tab.back().push_back(temp); +} + + +void Convert::AddUnit(const char * name, const char * abbr, int numerator, int denominator) +{ + if( type_tab.empty() || type_tab.back().empty() || unit_tab.empty() ) + return; + + Unit temp; + temp.name = name; + + if( abbr != 0 ) + temp.abbr = abbr; + + + temp.type = int(type_tab.back().size()-1); + + + temp.value_numerator.FromInt(numerator); + + if( denominator != 1 ) + { + // value_denominator is set into one (default) + temp.value_denominator.FromInt(denominator); + } + + unit_tab.back().push_back(temp); +} + + + + +void Convert::AddUnit(const char * name, const char * abbr, const char * v) +{ + if( type_tab.empty() || type_tab.back().empty() || unit_tab.empty() ) + return; + + Unit temp; + temp.name = name; + temp.abbr = abbr; + temp.type = int(type_tab.back().size()-1); + temp.value_numerator.FromString(v, 16); + + unit_tab.back().push_back(temp); +} + + +void Convert::Init() +{ + // en + type_tab.push_back( std::vector() ); + unit_tab.push_back( std::vector() ); + + AddType("none"); + + /* + yard = 0.9144 metre + foot = 1/3 yard = 0.3048 metre + inch = 1/36 yard = 1/12 foot = 0.0254 metre + + In 1958 the United States and countries of the Commonwealth of Nations + defined the length of the international yard to be precisely 0.9144 metres. + + 1 point (Didot's system) = 1 / 2660 m + 1 point (pica - USA and UK) = 1 / 72 inch + */ + AddType("length"); // base: 10000 metre + AddUnit("inch", "in", 254); + AddUnit("foot", "ft", 3048); + AddUnit("yard", "yd", 9144); + AddUnit("metre", "m", 10000); + AddUnit("mile (land)", "mi", 16093440); // 1 land mile = 1609.344 metres + AddUnit("mile (nautical)", "nmi", 18520000); // 1 nautical mile = 1852 metres + AddUnit("point (Didot)", "p", 10000, 2660); + AddUnit("point (pica)", "p", 18288, 5184); + AddUnit("light year", "ly", "520F0AA65AAEBAC00"); // 1 ly = 9 460 730 472 580 800 metres + // 520F0AA65AAEBAC00 (hex) = 94607304725808000000 (dec) + + + + /* + yard^2 = 0.83612736 metre^2 + foot^2 = 1/9 yard^2 = 0.09290304 metre^2 + inch^2 = 1/1296 yard^2 = 1/144 foot^ = 0.00064516 metre^2 + + ar = 100 metre^2 + hectere = 10000 metre^2 + */ + + // !!! give a smaller base here + AddType("area"); // base: 100 000 000 metre^2 + AddUnit("inch^2", "in^2", 64516); + AddUnit("foot^2", "ft^2", 9290304); + AddUnit("yard^2", "yd^2", 83612736); + AddUnit("metre^2", "m^2", 100000000); + AddUnit("are", "a", "2540BE400"); // 10000000000 (dec) + AddUnit("hectare", "ha", "E8D4A51000"); // 1000000000000 (dec) + AddUnit("mile (land)^2", "mi^2", "EB8EDC210000" ); // 258998811033600 (dec), 1 land mile^2 = 2589988.110336 metres^2 + AddUnit("mile (nautical)^2", "nmi^2", "137F2ACF41000"); // 342990400000000 (dec), 1 nautical mile^2 = 3429904 metres^2 + AddUnit("light year^2", "ly^2", "1A4DA3B4D207FB4C43D08391653B900000"); // 1 ly = 89505421074818927300612528640000 metres^2 + // 1A4DA3B4D207FB4C43D08391653B900000 (hex) = 8950542107481892730061252864000000000000 (dec) + + + AddType("time"); // base: second + AddUnit("second", "s", 1); + AddUnit("minute", "m", 60); + AddUnit("hour", "h", 3600); + AddUnit("day", "d", 86400); + AddUnit("week", "w", 604800); + AddUnit("fortnight", "fn", 1209600); + AddUnit("month", "m", 2592000); + AddUnit("year", "y", 31536000); + AddUnit("year (mean)", "my", 31557600); + AddUnit("year (leap)", "ly", 31622400); + AddUnit("decade", "dc", 315360000); + + + + // pl + // the 'value' param we're using only from the english + type_tab.push_back( std::vector() ); + unit_tab.push_back( std::vector() ); + + AddType("brak"); + + AddType("długość"); + AddUnit("cal"); + AddUnit("stopa"); + AddUnit("jard"); + AddUnit("metr"); + AddUnit("mila (angielska)"); + AddUnit("mila (morska)"); + AddUnit("punkt (Didot)"); + AddUnit("punkt (pica)"); + AddUnit("rok świetlny"); + + AddType("powierzchnia"); + AddUnit("cal^2"); + AddUnit("stopa^2"); + AddUnit("jard^2"); + AddUnit("metr^2"); + AddUnit("ar", ""); + AddUnit("hektar"); + AddUnit("mila (angielska)^2"); + AddUnit("mila (morska)^2"); + AddUnit("rok świetlny^2"); + + + AddType("czas"); + AddUnit("sekunda"); + AddUnit("minuta"); + AddUnit("godzina"); + AddUnit("dzień"); + AddUnit("tydzień"); + AddUnit("dwa tygodnie"); + AddUnit("miesiąc"); + AddUnit("rok"); + AddUnit("rok (średni)"); + AddUnit("rok (przestępny)"); + AddUnit("dekada"); + + CheckAfterInit(); +} + + +void Convert::ErrorMessage() +{ + MessageBox(0, "Internal error: tables for converting have incorrect values", + "Internal error", MB_ICONERROR); + + exit(0); +} + + +void Convert::CheckAfterInit() +{ +unsigned int i, len; + + if( type_tab.size() != unit_tab.size() ) + return ErrorMessage(); + + if( type_tab.empty() ) + return; + + len = (unsigned int)type_tab[0].size(); + for(i=1 ; i= (int)type_tab.size() ) + cid = 0; + + if( id< 0 || id >= int(type_tab[cid].size()) ) + return unk_err; + +return type_tab[cid][id].name.c_str(); +} + + + + +const char * Convert::GetUnitName(int cid, int id) +{ +const char * unk_err = "unknown"; + + if( unit_tab.empty() ) + return unk_err; + + if( cid >= (int)unit_tab.size() ) + cid = 0; + + if( id < 0 || id >= int(unit_tab[cid].size()) ) + return unk_err; + +return unit_tab[cid][id].name.c_str(); +} + + + + +const char * Convert::GetUnitAbbr(int cid, int id) +{ +const char * unk_err = "unknown"; + + if( unit_tab.empty() ) + return unk_err; + + if( cid >= (int)unit_tab.size() ) + cid = 0; + + if( id < 0 || id >= int(unit_tab[cid].size()) ) + return unk_err; + + if( !unit_tab[cid][id].abbr.empty() ) + return unit_tab[cid][id].abbr.c_str(); + + /* + if there is no defined an abbreviation in the specific + language, we return the abbreviation from english + */ + +return unit_tab[0][id].abbr.c_str(); +} + + + + +int Convert::GetTypeSize() +{ + if( type_tab.empty() ) + return 0; + + return int(type_tab[0].size()); +} + + +int Convert::GetUnitSize() +{ + if( unit_tab.empty() ) + return 0; + + return int(unit_tab[0].size()); +} + + +int Convert::GetUnitType(int id) +{ + if( unit_tab.empty() ) + return -1; + + if( id >= int(unit_tab[0].size()) ) + return -1; + +return unit_tab[0][id].type; +} + + +// value is taken only from english +bool Convert::GetUnitValue(int id, TTMathBigMax & numerator, TTMathBigMax & denominator) +{ + if( unit_tab.empty() ) + return false; + + if( id >= int(unit_tab[0].size()) ) + return false; + + numerator = unit_tab[0][id].value_numerator; + denominator = unit_tab[0][id].value_denominator; + +return true; +} + + + + +// gui + +void Convert::SetCurrentType(int c) +{ + current_conv_type = c; +} + + +int Convert::GetCurrentType() +{ + return current_conv_type; +} + + + +void Convert::CheckUnitIndex(int type) +{ + if( current_conv_unit[type].input < -1 || current_conv_unit[type].input >= GetUnitSize() ) + current_conv_unit[type].input = 0; // maybe better to -1 ? + + if( current_conv_unit[type].output < -1 || current_conv_unit[type].output >= GetUnitSize() ) + current_conv_unit[type].output = 0; // the same +} + + +void Convert::CheckCurrentUnits() +{ + int len = GetTypeSize(); + + if( static_cast( current_conv_unit.size() ) != len ) + current_conv_unit.resize(len); + + for(int i = 0 ; i= len ) + return; + + current_conv_unit[type].input = input; + current_conv_unit[type].output = output; + CheckUnitIndex(type); +} + + +bool Convert::GetCurrentUnit(int type, int & input, int & output) +{ + int len = GetTypeSize(); + + if( type >= len ) + { + input = output = -1; + return false; + } + + input = current_conv_unit[type].input; + output = current_conv_unit[type].output; + +return true; +} + +// diff --git a/src/convert.h b/src/convert.h new file mode 100644 index 0000000..d05bcf7 --- /dev/null +++ b/src/convert.h @@ -0,0 +1,176 @@ +/* + * This file is a part of TTCalc - a mathematical calculator + * and is distributed under the (new) BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 2006-2008, Tomasz Sowa + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name Tomasz Sowa nor the names of contributors to this + * project may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef convertheader +#define convertheader + +#include +#include +#include "compileconfig.h" +#include "bigtypes.h" + + + +class Convert +{ + +public: + + Convert(); + + + /* + none, length, area, time, + */ + struct Type + { + std::string name; + }; + + + + struct Unit + { + std::string name, abbr; + int type; + TTMathBigMax value_numerator, value_denominator; + + Unit() + { + type = -1; + value_numerator.SetZero(); + value_denominator.SetOne(); + } + }; + + + std::vector > type_tab; + std::vector > unit_tab; + + + + + void AddType(const char * name); + void AddUnit(const char * name, const char * abbr = 0, int numerator = 0, int denominator = 1); + void AddUnit(const char * name, const char * abbr, const char * v); + + void Init(); + + + const char * GetTypeName(int cid, int id); + + const char * GetUnitName(int cid, int id); + const char * GetUnitAbbr(int cid, int id); + int GetUnitType(int id); + + int GetTypeSize(); + int GetUnitSize(); + + + /* + the return value is the same for all languages + (in fact we're taking it from english) + */ + bool GetUnitValue(int id, TTMathBigMax & numerator, TTMathBigMax & denominator); + + void ErrorMessage(); + void CheckAfterInit(); + + + template + int Conversion(int conv_input_unit, int conv_output_unit, ValueType & result) + { + int c = 0; + + ValueType v1_n, v1_d; // input + ValueType v2_n, v2_d; // output + + TTMathBigMax v1_n_, v1_d_; // input + TTMathBigMax v2_n_, v2_d_; // output + + if( !GetUnitValue(conv_input_unit, v1_n_, v1_d_) ) + return 1; + + if( !GetUnitValue(conv_output_unit, v2_n_, v2_d_) ) + return 1; + + v1_n.FromBig( v1_n_ ); + v1_d.FromBig( v1_d_ ); + v2_n.FromBig( v2_n_ ); + v2_d.FromBig( v2_d_ ); + + // result = result * (v1_n * v2_d) / (v1_d * v2_n) + c += result.Mul(v1_n); + c += result.Mul(v2_d); + c += v1_d.Mul(v2_n); + c += result.Div(v1_d); + + return (c==0)? 0 : 1; + } + + + + /* + for the interface + */ + + int current_conv_type; // selected type of converting: none, length, area, ... + + struct CurrentConvUnit + { + int input, output; + CurrentConvUnit() { input = output = -1; } + }; + + std::vector current_conv_unit; + + + + void SetCurrentType(int c); + int GetCurrentType(); + void CheckUnitIndex(int type); + void CheckCurrentUnits(); + void SetCurrentUnit(int type, int input, int output); + bool GetCurrentUnit(int type, int & input, int & output); + + // end part of gui + + +}; + + +#endif diff --git a/src/functions.cpp b/src/functions.cpp index 3e09373..d54ce32 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/iniparser.cpp b/src/iniparser.cpp index 3692215..2c0ff1f 100644 --- a/src/iniparser.cpp +++ b/src/iniparser.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/iniparser.h b/src/iniparser.h index a687eee..579ffed 100644 --- a/src/iniparser.h +++ b/src/iniparser.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/languages.cpp b/src/languages.cpp index 75534ac..512a43e 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,14 +36,11 @@ */ #include "compileconfig.h" - #include "languages.h" - - const char * Languages::ErrorMessage(Country country, ttmath::ErrorCode code) { const char * unk_err = "unknown error"; @@ -201,10 +198,15 @@ const char * unk_msg = "unknown"; return i->second.c_str(); } + + const char * Languages::GuiMessage(GuiMsg code) { return GuiMessage(current_country, code); } + + + void Languages::InsertGuiPair(GuiMsg code, const char * message) { if( gui_messages_tab.empty() ) @@ -214,6 +216,7 @@ void Languages::InsertGuiPair(GuiMsg code, const char * message) } + void Languages::InitGuiMessagesTab() { // en @@ -594,288 +597,4 @@ void Languages::InitGuiMessagesTab() -void Languages::ConvertingAddType(const char * name) -{ - if( converting_type.empty() ) - return; - - ConvType temp; - temp.name = name; - - converting_type.back().push_back(temp); -} - - -void Languages::ConvertingAddUnit(const char * name, const char * abbr, double v) -{ - if( converting_type.empty() || converting_type.back().empty() || converting_unit.empty() ) - return; - - ConvUnit temp; - temp.name = name; - temp.abbr = abbr; - temp.type = static_cast(converting_type.back().size()-1); - temp.value.FromDouble(v); - - converting_unit.back().push_back(temp); -} - -void Languages::ConvertingAddUnit(const char * name, const char * abbr, const char * v) -{ - if( converting_type.empty() || converting_type.back().empty() || converting_unit.empty() ) - return; - - ConvUnit temp; - temp.name = name; - temp.abbr = abbr; - temp.type = static_cast(converting_type.back().size()-1); - temp.value.FromString(v, 16); - - converting_unit.back().push_back(temp); -} - - -void Languages::InitConverting() -{ - // en - converting_type.push_back( std::vector() ); - converting_unit.push_back( std::vector() ); - - ConvertingAddType("none"); - - /* - yard = 0.9144 metre - foot = 1/3 yard = 0.3048 metre - inch = 1/36 yard = 1/12 foot = 0.0254 metre - - In 1958 the United States and countries of the Commonwealth of Nations - defined the length of the international yard to be precisely 0.9144 metres. - */ - ConvertingAddType("length"); // base: 10000 metre - ConvertingAddUnit("inch", "in", 254.0 ); - ConvertingAddUnit("foot", "ft", 3048.0); - ConvertingAddUnit("yard", "yd", 9144.0); - ConvertingAddUnit("metre", "m", 10000.0 ); - ConvertingAddUnit("mile (land)", "mi", 16093440.0); // 1 land mile = 1609.344 metres - ConvertingAddUnit("mile (nautical)", "nmi", 18520000.0); // 1 nautical mile = 1852 metres - ConvertingAddUnit("light year", "ly", "520F0AA65AAEBAC00"); // 1 ly = 9 460 730 472 580 800 metres - // 520F0AA65AAEBAC00 (hex) = 94607304725808000000 (dec) - - /* - yard^2 = 0.83612736 metre^2 - foot^2 = 1/9 yard^2 = 0.09290304 metre^2 - inch^2 = 1/1296 yard^2 = 1/144 foot^ = 0.00064516 metre^2 - - ar = 100 metre^2 - hectere = 10000 metre^2 - */ - ConvertingAddType("area"); // base: 100 000 000 metre^2 - ConvertingAddUnit("inch^2", "in^2", 64516.0); - ConvertingAddUnit("foot^2", "ft^2", 9290304.0); - ConvertingAddUnit("yard^2", "yd^2", 83612736.0); - ConvertingAddUnit("metre^2", "m^2", 100000000.0); - ConvertingAddUnit("are", "a", 10000000000.0); - ConvertingAddUnit("hectare", "ha", 1000000000000.0); - ConvertingAddUnit("mile (land)^2", "mi^2", 258998811033600.0 ); // 1 land mile^2 = 2589988.110336 metres^2 - ConvertingAddUnit("mile (nautical)^2", "nmi^2", 342990400000000.0); // 1 nautical mile^2 = 3429904 metres^2 - ConvertingAddUnit("light year^2", "ly^2", "1A4DA3B4D207FB4C43D08391653B900000"); // 1 ly = 89505421074818927300612528640000 metres^2 - // 1A4DA3B4D207FB4C43D08391653B900000 (hex) = 8950542107481892730061252864000000000000 (dec) - - ConvertingAddType("time"); // base: second - ConvertingAddUnit("second", "s", 1.0); - ConvertingAddUnit("minute", "m", 60.0); - ConvertingAddUnit("hour", "h", 3600.0); - ConvertingAddUnit("day", "d", 86400.0); - ConvertingAddUnit("week", "w", 604800.0); - ConvertingAddUnit("fortnight", "fn", 1209600.0); - ConvertingAddUnit("month", "m", 2592000.0); - ConvertingAddUnit("year", "y", 31536000.0); - ConvertingAddUnit("year (mean)", "my", 31557600.0); - ConvertingAddUnit("year (leap)", "ly", 31622400.0); - ConvertingAddUnit("decade", "dc", 315360000.0); - - - - // pl - // the 'value' param we're using only from the english - converting_type.push_back( std::vector() ); - converting_unit.push_back( std::vector() ); - - ConvertingAddType("brak"); - - ConvertingAddType("długość"); - ConvertingAddUnit("cal", "", 0.0 ); - ConvertingAddUnit("stopa", "", 0.0); - ConvertingAddUnit("jard", "", 0.0); - ConvertingAddUnit("metr", "", 0.0); - ConvertingAddUnit("mila (angielska)", "", 0.0); - ConvertingAddUnit("mila (morska)", "", 0.0); - ConvertingAddUnit("rok świetlny", "", 0.0); - - ConvertingAddType("powierzchnia"); - ConvertingAddUnit("cal^2", "", 0.0); - ConvertingAddUnit("stopa^2", "", 0.0); - ConvertingAddUnit("jard^2", "", 0.0); - ConvertingAddUnit("metr^2", "", 0.0); - ConvertingAddUnit("ar", "", 0.0); - ConvertingAddUnit("hektar", "", 0.0); - ConvertingAddUnit("mila (angielska)^2", "", 0.0); - ConvertingAddUnit("mila (morska)^2", "", 0.0); - ConvertingAddUnit("rok świetlny^2", "", 0.0); - - ConvertingAddType("czas"); - ConvertingAddUnit("sekunda", "", 0.0); - ConvertingAddUnit("minuta", "", 0.0); - ConvertingAddUnit("godzina", "", 0.0); - ConvertingAddUnit("dzień", "", 0.0); - ConvertingAddUnit("tydzień", "", 0.0); - ConvertingAddUnit("dwa tygodnie", "", 0.0); - ConvertingAddUnit("miesiąc", "", 0.0); - ConvertingAddUnit("rok", "", 0.0); - ConvertingAddUnit("rok (średni)", "", 0.0); - ConvertingAddUnit("rok (przestępny)", "", 0.0); - ConvertingAddUnit("dekada", "", 0.0); - -} - - -const char * Languages::ConvertingType(Country country, int id) -{ -const char * unk_err = "unknown"; - - if( converting_type.empty() ) - InitConverting(); - - unsigned int cid = static_cast( country ); - if( cid >= converting_type.size() ) - return unk_err; - - if( id< 0 || id >= static_cast(converting_type[cid].size()) ) - return unk_err; - -return converting_type[cid][id].name.c_str(); -} - - -const char * Languages::ConvertingUnit(Country country, int id) -{ -const char * unk_err = "unknown"; - - if( converting_unit.empty() ) - InitConverting(); - - unsigned int cid = static_cast( country ); - if( cid >= converting_unit.size() ) - return unk_err; - - if( id < 0 || id >= static_cast(converting_unit[cid].size()) ) - return unk_err; - -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( country ); - if( cid >= converting_unit.size() ) - return unk_err; - - if( id < 0 || id >= static_cast(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) -{ - return ConvertingType(current_country, id); - -} - -const char * Languages::ConvertingUnit(int id) -{ - return ConvertingUnit(current_country, id); -} - -const char * Languages::ConvertingUnitAbbr(int id) -{ - return ConvertingUnitAbbr(current_country, id); -} - -int Languages::ConvertingTypeSize(Country country) -{ - if( converting_type.empty() ) - InitConverting(); - - unsigned int cid = static_cast( country ); - if( cid >= converting_type.size() ) - return 0; - -return static_cast(converting_type[cid].size()); -} - - -int Languages::ConvertingUnitSize(Country country) -{ - if( converting_unit.empty() ) - InitConverting(); - - unsigned int cid = static_cast( country ); - if( cid >= converting_unit.size() ) - return 0; - -return static_cast(converting_unit[cid].size()); -} - - -int Languages::ConvertingTypeSize() -{ - return ConvertingTypeSize(current_country); -} - -int Languages::ConvertingUnitSize() -{ - return ConvertingUnitSize(current_country); -} - - -int Languages::ConvertingUnitType(Country country, int id) -{ - if( converting_unit.empty() ) - InitConverting(); - - unsigned int cid = static_cast( country ); - if( cid >= converting_unit.size() ) - return -1; - - if( id >= static_cast(converting_unit[cid].size()) ) - return -1; - -return converting_unit[cid][id].type; -} - -int Languages::ConvertingUnitType(int id) -{ - return ConvertingUnitType(current_country, id); -} - -// value is taken only from english -const Languages::ConvUnit::ValueType & Languages::ConvertingUnitValue(int id) -{ - if( converting_unit.empty() ) - InitConverting(); - - if( id >= static_cast(converting_unit[0].size()) ) - return foo_return; - -return converting_unit[0][id].value; -} diff --git a/src/languages.h b/src/languages.h index eb940b5..2e76edf 100644 --- a/src/languages.h +++ b/src/languages.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,8 @@ #include #include -#include +#include "bigtypes.h" + class Languages { @@ -147,25 +148,10 @@ public: en = 0, pl, sp }; - struct ConvType - { - std::string name; - // int id; - }; - - struct ConvUnit - { - std::string name, abbr; - // int id; - int type; - - typedef ttmath::Big<3,27> ValueType; - ValueType value; - }; - ConvUnit::ValueType foo_return; +// TTMathBigMax foo_return; private: @@ -181,23 +167,15 @@ private: void InitGuiMessagesTab(); - std::vector > converting_type; - std::vector > converting_unit; - void ConvertingAddType(const char * name); - void ConvertingAddUnit(const char * name, const char * abbr, double v); - void ConvertingAddUnit(const char * name, const char * abbr, const char * v); - - void InitConverting(); - public: Languages() { current_country = en; - foo_return = 0; +// foo_return = 0; } void SetCurrentLanguage(Country c) @@ -221,7 +199,6 @@ public: { InitErrorMessagesTab(); InitGuiMessagesTab(); - InitConverting(); } @@ -237,12 +214,7 @@ public: */ const char * ErrorMessage(Country country, ttmath::ErrorCode code); const char * GuiMessage(Country country, GuiMsg code); - const char * ConvertingType(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 ConvertingTypeSize(Country country); - int ConvertingUnitSize(Country country); + /* @@ -255,19 +227,8 @@ public: */ const char * ErrorMessage(ttmath::ErrorCode code); const char * GuiMessage(GuiMsg code); - const char * ConvertingType(int id); - const char * ConvertingUnit(int id); - const char * ConvertingUnitAbbr(int id); - int ConvertingUnitType(int id); - int ConvertingTypeSize(); - 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); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9e46703..eb1ac2d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/messages.h b/src/messages.h index bce5799..4dad6a8 100644 --- a/src/messages.h +++ b/src/messages.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/parsermanager.cpp b/src/parsermanager.cpp index 44c6e37..3d8158d 100644 --- a/src/parsermanager.cpp +++ b/src/parsermanager.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -152,8 +152,8 @@ unsigned int i; remove_zeroes = GetPrgRes()->GetRemovingZeroes(); country = GetPrgRes()->GetLanguages()->GetCurrentLanguage(); - conv_type = GetPrgRes()->GetConvType(); - GetPrgRes()->GetConvUnit(conv_type, conv_input_unit, conv_output_unit); + conv_type = GetPrgRes()->GetConvert()->GetCurrentType(); + GetPrgRes()->GetConvert()->GetCurrentUnit(conv_type, conv_input_unit, conv_output_unit); if( GetPrgRes()->GetDecimalPoint() == 0 ) decimal_point = '.'; @@ -223,52 +223,48 @@ HWND conv_tab = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_convert); return; } - Languages * plang = GetPrgRes()->GetLanguages(); + Convert * pconv = GetPrgRes()->GetConvert(); // the first unit to the second + ttmath::Big<1,1> result; + result.SetOne(); std::string buffer1 = "1 "; - - buffer1 += plang->ConvertingUnitAbbr(country, conv_input_unit); + buffer1 += pconv->GetUnitAbbr(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) ) + if( pconv->Conversion(conv_input_unit, conv_output_unit, result) ) { SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" ); return; } - result.ToString(buffer2,10,false,3,-1, true); + result.ToString(buffer2, 10, false, 3, -1, true); buffer1 += buffer2; buffer1 += " "; - buffer1 += plang->ConvertingUnitAbbr(country, conv_output_unit); + buffer1 += pconv->GetUnitAbbr(country, conv_output_unit); + // the second unit to the first buffer1 += " 1 "; - buffer1 += plang->ConvertingUnitAbbr(country, conv_output_unit); + buffer1 += pconv->GetUnitAbbr(country, conv_output_unit); buffer1 += " = "; - result = value_output; - if( result.Div(value_input) ) + result.SetOne(); + if( pconv->Conversion(conv_output_unit, conv_input_unit, result) ) { SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, "overflow" ); return; } - result.ToString(buffer2,10,false,3,-1, true); + + result.ToString(buffer2, 10, false, 3, -1, true); buffer1 += buffer2; buffer1 += " "; - buffer1 += plang->ConvertingUnitAbbr(country, conv_input_unit); - - + buffer1 += pconv->GetUnitAbbr(country, conv_input_unit); SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, buffer1.c_str() ); } diff --git a/src/parsermanager.h b/src/parsermanager.h index cedfe3a..073e60e 100644 --- a/src/parsermanager.h +++ b/src/parsermanager.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -113,17 +113,11 @@ private: #ifndef TTCALC_PORTABLE - /* - // old ones - ttmath::Parser > parser1; - ttmath::Parser > parser2; - ttmath::Parser > parser3; - */ - ttmath::Parser > parser1; - ttmath::Parser > parser2; - ttmath::Parser > parser3; + ttmath::Parser parser1; + ttmath::Parser parser2; + ttmath::Parser parser3; #else - ttmath::Parser > parser1; + ttmath::Parser parser1; #endif ttmath::Objects variables, functions; @@ -163,31 +157,14 @@ private: return false; } - template - int Conversion(ValueType & result) - { - int c = 0; - if( CanWeConvert() ) - { - ValueType vinput, voutput; - - vinput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(conv_input_unit) ); - voutput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(conv_output_unit) ); - - c += result.Mul(vinput); - c += result.Div(voutput); - } - - return c; - } void AddOutputSuffix(std::string & result) { if( CanWeConvert() ) { result += " "; - result += GetPrgRes()->GetLanguages()->ConvertingUnitAbbr(country, conv_output_unit); + result += GetPrgRes()->GetConvert()->GetUnitAbbr(country, conv_output_unit); } } @@ -206,10 +183,14 @@ private: try { ValueType result = matparser.stack[i].value; - if( Conversion(result) ) + + if( CanWeConvert() ) { - code = ttmath::err_overflow; - return 1; + if( GetPrgRes()->GetConvert()->Conversion(conv_input_unit, conv_output_unit, result) ) + { + code = ttmath::err_overflow; + return 1; + } } if( result.ToString(buffer2,base_output, always_scientific, when_scientific, rounding, remove_zeroes, decimal_point) ) diff --git a/src/programresources.cpp b/src/programresources.cpp index d758c2f..098aa77 100644 --- a/src/programresources.cpp +++ b/src/programresources.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -305,6 +305,13 @@ Languages * ProgramResources::GetLanguages() return &languages; } + +Convert * ProgramResources::GetConvert() +{ + return &convert; +} + + void ProgramResources::SetInstance(HINSTANCE h) { hInstance = h; @@ -418,11 +425,14 @@ ProgramResources::ProgramResources() y_size_normal = 0; y_size_compact = 0; x_size_min = 0; + + // !!! wrzucic do kontruktora Convert + convert.Init(); - conv_type = 0; - ConvUnitCheckAll(); decimal_point = 0; + + } @@ -755,66 +765,3 @@ int ProgramResources::GetBadLine() return bad_line; } - -void ProgramResources::SetConvType(int c) -{ - conv_type = c; -} - - -int ProgramResources::GetConvType() -{ - return conv_type; -} - - -void ProgramResources::ConvUnitCheck(int type) -{ - if( conv_unit[type].input < -1 || conv_unit[type].input >= GetLanguages()->ConvertingUnitSize() ) - conv_unit[type].input = 0; - - if( conv_unit[type].output < -1 || conv_unit[type].output >= GetLanguages()->ConvertingUnitSize() ) - conv_unit[type].output = 0; -} - - -void ProgramResources::ConvUnitCheckAll() -{ - int len = GetLanguages()->ConvertingTypeSize(); - - if( static_cast( conv_unit.size() ) != len ) - conv_unit.resize(len); - - for(int i = 0 ; iConvertingTypeSize(); - - if( type >= len ) - return; - - conv_unit[type].input = input; - conv_unit[type].output = output; - ConvUnitCheck(type); -} - - -bool ProgramResources::GetConvUnit(int type, int & input, int & output) -{ - int len = GetLanguages()->ConvertingTypeSize(); - - if( type >= len ) - { - input = output = -1; - return false; - } - - input = conv_unit[type].input; - output = conv_unit[type].output; - -return true; -} diff --git a/src/programresources.h b/src/programresources.h index 29bff83..d67684c 100644 --- a/src/programresources.h +++ b/src/programresources.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include "iniparser.h" #include "languages.h" #include "threadcontroller.h" +#include "convert.h" #include #include @@ -218,12 +219,13 @@ public: /*! - pointers to variables' table, functions' table, the language's object + pointers to variables' table, functions' table, the languages' object, convert object and to the characters' buffer */ ttmath::Objects * GetVariables(); ttmath::Objects * GetFunctions(); Languages * GetLanguages(); + Convert * GetConvert(); char * GetBuffer(); unsigned int GetBufferSize(); @@ -291,18 +293,6 @@ public: bool GetRemovingZeroes(); - /*! - these methods set and return the kind of conversion which should be performed - - 0 - none - 1 - ... - 2 - ... - */ - void SetConvType(int c); - int GetConvType(); - - void SetConvUnit(int c, int input, int output); - bool GetConvUnit(int c, int & input, int & output); private: @@ -315,6 +305,7 @@ private: ttmath::Objects variables; ttmath::Objects functions; Languages languages; + Convert convert; volatile ThreadController thread_controller; unsigned int buffer_size; @@ -352,22 +343,7 @@ private: int bad_line; - int conv_type; - struct ConvUnit - { - int input, output; - - ConvUnit() - { - input = output = -1; - } - }; - - std::vector conv_unit; - - void ConvUnitCheck(int type); - void ConvUnitCheckAll(); }; diff --git a/src/resource.h b/src/resource.h index eab1e5b..a22a907 100644 --- a/src/resource.h +++ b/src/resource.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/resource.rc b/src/resource.rc index 389c9ac..7672f8d 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -189,8 +189,8 @@ BEGIN LTEXT "Rounding",1164,11,36,43,8 LTEXT "Decimal point",1169,178,21,68,8 COMBOBOX 1170,143,19,29,62,CBS_DROPDOWNLIST | WS_TABSTOP - CONTROL "remove trailing zeroes",1171,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,143,35,111,10 + CONTROL "remove trailing zeroes",1171,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,143,35,111,10 COMBOBOX 1159,58,33,69,200,CBS_DROPDOWNLIST | WS_TABSTOP CONTROL "Always",1160,"Button",BS_AUTORADIOBUTTON | BS_LEFT | WS_GROUP | WS_TABSTOP,19,65,44,10 diff --git a/src/stopcalculating.h b/src/stopcalculating.h index 12e9665..68d789e 100644 --- a/src/stopcalculating.h +++ b/src/stopcalculating.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/tabs.cpp b/src/tabs.cpp index 9897d49..1626297 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -467,8 +467,8 @@ return ListView_FindItem(list, -1, &info); void TabConvertFillUpUnitList(HWND list, int conv_type) { - Languages * plang = GetPrgRes()->GetLanguages(); - unsigned int len = plang->ConvertingUnitSize(); + Convert * pconv = GetPrgRes()->GetConvert(); + unsigned int len = pconv->GetUnitSize(); unsigned int i, index; ListView_DeleteAllItems(list); @@ -479,11 +479,12 @@ void TabConvertFillUpUnitList(HWND list, int conv_type) for( i=index=0 ; iConvertingUnitType(i) == conv_type ) + if( pconv->GetUnitType(i) == conv_type ) { item.lParam = i; item.iItem = index++; - item.pszText = const_cast(plang->ConvertingUnit(i)); + int country = static_cast(GetPrgRes()->GetLanguages()->GetCurrentLanguage()); + item.pszText = const_cast(pconv->GetUnitName(country, i)); ListView_InsertItem(list, &item); } @@ -497,11 +498,11 @@ HWND list2b = GetDlgItem(hWnd, IDC_LIST_UNIT_INPUT2); HWND list3b = GetDlgItem(hWnd, IDC_LIST_UNIT_OUTPUT2); int input, output; - int convtype = GetPrgRes()->GetConvType(); + int convtype = GetPrgRes()->GetConvert()->GetCurrentType(); TabConvertFillUpUnitList(list2b, convtype); TabConvertFillUpUnitList(list3b, convtype); - GetPrgRes()->GetConvUnit( convtype, input, output); + GetPrgRes()->GetConvert()->GetCurrentUnit( convtype, input, output); if( input >= 0 ) { @@ -543,7 +544,7 @@ HWND list1 = GetDlgItem(hWnd, IDC_LIST_UNIT_TYPE); return; GetPrgRes()->GetThreadController()->StopCalculating(); - GetPrgRes()->SetConvType( (int)item.lParam ); + GetPrgRes()->GetConvert()->SetCurrentType( (int)item.lParam ); GetPrgRes()->GetThreadController()->StartCalculating(); TabConvertFillUpUnitLists(hWnd); @@ -570,12 +571,12 @@ HWND list2b = GetDlgItem(hWnd, IDC_LIST_UNIT_INPUT2); if( !ListView_GetItem(list2b, &item) ) return; - int convtype = GetPrgRes()->GetConvType(); + int convtype = GetPrgRes()->GetConvert()->GetCurrentType(); int input, output; GetPrgRes()->GetThreadController()->StopCalculating(); - GetPrgRes()->GetConvUnit(convtype, input, output); - GetPrgRes()->SetConvUnit(convtype, (int)item.lParam, output ); + GetPrgRes()->GetConvert()->GetCurrentUnit(convtype, input, output); + GetPrgRes()->GetConvert()->SetCurrentUnit(convtype, (int)item.lParam, output ); GetPrgRes()->GetThreadController()->StartCalculating(); } @@ -600,12 +601,12 @@ HWND list3b = GetDlgItem(hWnd, IDC_LIST_UNIT_OUTPUT2); if( !ListView_GetItem(list3b, &item) ) return; - int convtype = GetPrgRes()->GetConvType(); + int convtype = GetPrgRes()->GetConvert()->GetCurrentType(); int input, output; GetPrgRes()->GetThreadController()->StopCalculating(); - GetPrgRes()->GetConvUnit(convtype, input, output); - GetPrgRes()->SetConvUnit(convtype, input, (int)item.lParam ); + GetPrgRes()->GetConvert()->GetCurrentUnit(convtype, input, output); + GetPrgRes()->GetConvert()->SetCurrentUnit(convtype, input, (int)item.lParam ); GetPrgRes()->GetThreadController()->StartCalculating(); } @@ -616,6 +617,7 @@ HWND list3b = GetDlgItem(hWnd, IDC_LIST_UNIT_OUTPUT2); void SetLanguageTabConvert(HWND hWnd) { Languages * plang = GetPrgRes()->GetLanguages(); +Convert * pconv = GetPrgRes()->GetConvert(); SetDlgItemText(hWnd, IDC_STATIC_UNIT_CONVERSION, plang->GuiMessage(Languages::convert_type) ); SetDlgItemText(hWnd, IDC_STATIC_UNIT_INPUT, plang->GuiMessage(Languages::convert_input) ); @@ -630,18 +632,19 @@ Languages * plang = GetPrgRes()->GetLanguages(); item.mask = LVIF_PARAM | LVIF_TEXT; item.iSubItem = 0; - unsigned int conv_type_size = plang->ConvertingTypeSize(); + unsigned int conv_type_size = pconv->GetTypeSize(); for(unsigned int i = 0 ; i(plang->ConvertingType(i)); + int country = static_cast(plang->GetCurrentLanguage()); + item.pszText = const_cast(pconv->GetTypeName(country, i)); ListView_InsertItem(list1, &item); } - int type = FindItem(list1, GetPrgRes()->GetConvType() ); + int type = FindItem(list1, GetPrgRes()->GetConvert()->GetCurrentType() ); if( type != -1 ) ListView_SetItemState(list1, type, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED); // there'll be generated wm_notify message and the next lists will be changed then diff --git a/src/tabs.h b/src/tabs.h index c62b17a..4d53491 100644 --- a/src/tabs.h +++ b/src/tabs.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/threadcontroller.h b/src/threadcontroller.h index 63dfb46..b154493 100644 --- a/src/threadcontroller.h +++ b/src/threadcontroller.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/variables.cpp b/src/variables.cpp index d185b9c..a622b9e 100644 --- a/src/variables.cpp +++ b/src/variables.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/winmain.cpp b/src/winmain.cpp index b2c881c..faa763f 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -48,7 +48,7 @@ /*! - here our application starts + the application starts here */ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { @@ -58,6 +58,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) // that everything is initialized before the second thread is started GetPrgRes()->GetLanguages()->InitAll(); GetPrgRes()->GetLanguages()->SetCurrentLanguage(Languages::en); + //GetPrgRes()->GetConvert()->Init(); GetPrgRes()->SetNameOfConfigurationFile(); GetPrgRes()->ReadFromFile(); diff --git a/src/winmain.h b/src/winmain.h index 3cbd82c..382fe90 100644 --- a/src/winmain.h +++ b/src/winmain.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2006-2007, Tomasz Sowa + * Copyright (c) 2006-2008, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without