From 01ad53910782d0cc1fd80cf2ade7da586a892727 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 4 Nov 2007 21:56:55 +0000 Subject: [PATCH] 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 --- src/calculation.cpp | 3 + src/languages.cpp | 168 +++++++++++++++++++++++------------------- src/languages.h | 54 ++++++++++++-- src/parsermanager.cpp | 91 ++++++++++++++++------- src/parsermanager.h | 69 +++++++++++------ src/tabs.cpp | 80 ++++++++++++-------- src/winmain.cpp | 4 + 7 files changed, 305 insertions(+), 164 deletions(-) diff --git a/src/calculation.cpp b/src/calculation.cpp index c3a3c9a..7142b40 100644 --- a/src/calculation.cpp +++ b/src/calculation.cpp @@ -65,6 +65,9 @@ unsigned __stdcall CalculationsProcedure(void *) SetDlgItemText(main_window, IDC_OUTPUT_EDIT, ""); 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 parser_manager.Parse(); diff --git a/src/languages.cpp b/src/languages.cpp index 6915679..88f244e 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -230,12 +230,13 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(tab_convert,"Convert"); 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_3,"Big - 288 bits for the mantissa, 96 bits for the exponent"); + InsertGuiPair(radio_precision_2,"Medium - 288 bits for the mantissa, 64 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_2_info,"(+/-)4.3 e+2776511644261678623, 56 valid digits"); - InsertGuiPair(precision_3_info,"(+/-)2.5 e+11925026709067095507636213441, 85 valid digits"); + InsertGuiPair(precision_2_info,"(+/-)3.4e+2776511644261678652, 85 valid digits"); + InsertGuiPair(precision_3_info,"(+/-)6.7e+51217599719369681875006054625051616609, 258 digits"); InsertGuiPair(overflow_during_printing,"Overflow during printing"); @@ -351,12 +352,12 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(tab_convert,"Konwersja"); 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_3,"Duża - 288 bitowa mantysa, 96 bitowy wykładnik"); + InsertGuiPair(radio_precision_2,"Średnia - 288 bitowa mantysa, 64 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_2_info,"(+/-)4.3 e+2776511644261678623, 56 cyfr znaczących"); - InsertGuiPair(precision_3_info,"(+/-)2.5 e+11925026709067095507636213441, 85 cyfr znaczących"); + InsertGuiPair(precision_1_info,"(+/-)6.9e+646457021, 26 cyfr znaczących (w rozwinięciu dziesiętnym)"); + InsertGuiPair(precision_2_info,"(+/-)3.4e+2776511644261678652, 85 cyfr znaczących"); + InsertGuiPair(precision_3_info,"(+/-)6.7e+51217599719369681875006054625051616609, 258 cyfr"); 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() ) 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 * v) +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); @@ -490,13 +493,13 @@ void Languages::InitConverting() defined the length of the international yard to be precisely 0.9144 metres. */ ConvertingAddType("length"); // base: 10000 metre - ConvertingAddUnit("inch", 254.0 ); - ConvertingAddUnit("foot", 3048.0); - ConvertingAddUnit("yard", 9144.0); - ConvertingAddUnit("metre", 10000.0 ); - ConvertingAddUnit("mile (land)", 16093440.0); // 1 land mile = 1609.344 metres - ConvertingAddUnit("mile (nautical)", 18520000.0); // 1 nautical mile = 1852 metres - ConvertingAddUnit("light year", "520F0AA65AAEBAC00"); // 1 ly = 9 460 730 472 580 800 metres + 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) /* @@ -508,43 +511,31 @@ void Languages::InitConverting() hectere = 10000 metre^2 */ ConvertingAddType("area"); // base: 100 000 000 metre^2 - ConvertingAddUnit("inch^2", 64516.0); - ConvertingAddUnit("foot^2", 9290304.0); - ConvertingAddUnit("yard^2", 83612736.0); - ConvertingAddUnit("metre^2", 100000000.0); - ConvertingAddUnit("are", 10000000000.0); - ConvertingAddUnit("hectare", 1000000000000.0); - ConvertingAddUnit("mile (land)^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("light year^2", "1A4DA3B4D207FB4C43D08391653B900000"); // 1 ly = 89505421074818927300612528640000 metres^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", 1.0); - ConvertingAddUnit("minute", 60.0); - ConvertingAddUnit("hour", 3600.0); - ConvertingAddUnit("day", 86400.0); - ConvertingAddUnit("week", 604800.0); - ConvertingAddUnit("fortnight", 1209600.0); - ConvertingAddUnit("month", 2592000.0); - ConvertingAddUnit("year", 31536000.0); - ConvertingAddUnit("year (mean)", 31557600.0); - ConvertingAddUnit("year (leap)", 31622400.0); - ConvertingAddUnit("decade", 315360000.0); + 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); - /* - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - ConvertingAddUnit("", ); - */ // pl // the 'value' param we're using only from the english @@ -554,37 +545,37 @@ void Languages::InitConverting() 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); + 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); + 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); + 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); } @@ -624,6 +615,25 @@ const char * unk_err = "unknown"; 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) { @@ -636,6 +646,10 @@ 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) { diff --git a/src/languages.h b/src/languages.h index dd8928a..f8fcea9 100644 --- a/src/languages.h +++ b/src/languages.h @@ -155,7 +155,7 @@ public: struct ConvUnit { - std::string name; + std::string name, abbr; // int id; int type; @@ -185,8 +185,8 @@ private: void ConvertingAddType(const char * name); - void ConvertingAddUnit(const char * name, double v); - void ConvertingAddUnit(const char * name, const char * v); + void ConvertingAddUnit(const char * name, const char * abbr, double v); + void ConvertingAddUnit(const char * name, const char * abbr, const char * v); void InitConverting(); @@ -208,23 +208,63 @@ public: 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 * 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); + + /* + 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 * 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/parsermanager.cpp b/src/parsermanager.cpp index 27885d6..b957138 100644 --- a/src/parsermanager.cpp +++ b/src/parsermanager.cpp @@ -37,6 +37,7 @@ #include "compileconfig.h" #include "parsermanager.h" +#include "tabs.h" @@ -148,6 +149,9 @@ unsigned int i; precision = GetPrgRes()->GetPrecision(); 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 - return PrintResult(parser1); - #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 - // static value like GetMainWindow() which are set only once - // 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) ); - */ + SetDlgItemText(conv_tab, IDC_EDIT_OUTPUT_INFO, ""); + return; } + 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() ); +} diff --git a/src/parsermanager.h b/src/parsermanager.h index 01432dd..3adb291 100644 --- a/src/parsermanager.h +++ b/src/parsermanager.h @@ -103,6 +103,12 @@ public: int PrintResult(); + /*! + this method prints the info about converting (on the converting tab) + */ + void ShowConvertingInfo(); + + private: #ifndef TTCALC_PORTABLE @@ -115,7 +121,7 @@ private: */ ttmath::Parser > parser1; ttmath::Parser > parser2; - ttmath::Parser > parser3; + ttmath::Parser > parser3; #else ttmath::Parser > parser1; #endif @@ -126,6 +132,7 @@ private: char * buffer; int base_input, base_output; + int conv_type, conv_input_unit, conv_output_unit; bool always_scientific; int when_scientific; @@ -135,44 +142,61 @@ private: 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 int Conversion(ValueType & result) { - int convtype = GetPrgRes()->GetConvType(); int c = 0; - if( convtype != 0 ) + if( CanWeConvert() ) { - int input, output; - GetPrgRes()->GetConvUnit(convtype, input, output); + ValueType vinput, voutput; - if( input!=-1 && output!=-1 && input!=output ) - { - ValueType vinput, voutput; + vinput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(conv_input_unit) ); + voutput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(conv_output_unit) ); - vinput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(input) ); - voutput.FromBig( GetPrgRes()->GetLanguages()->ConvertingUnitValue(output) ); - - c += result.Mul(vinput); - c += result.Div(voutput); - } + 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); + } + } // 1 if carry template int PrintResult(ttmath::Parser & matparser) { - std::string result, part; unsigned int i = 0; + buffer1.erase(); + buffer2.erase(); for(i=0 ; iGetLanguages()->GuiMessage(country, Languages::overflow_during_printing); + buffer2 = GetPrgRes()->GetLanguages()->GuiMessage(country, Languages::overflow_during_printing); } } 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 ) - result += " "; + buffer1 += " "; } - SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,result.c_str()); + SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,buffer1.c_str()); return 0; } diff --git a/src/tabs.cpp b/src/tabs.cpp index 63c6809..ab21c72 100644 --- a/src/tabs.cpp +++ b/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 (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); } -/* -void SetSizeOfConvertingLists() -{ - - - -} -*/ 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 info_edit = GetDlgItem(dialog, IDC_EDIT_OUTPUT_INFO); HWND check_dynamic_output = GetDlgItem(dialog, IDC_COMBO_DYNAMIC_OUTPUT); - int move_flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER; - int resize_flags = SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER; + int move_flags = SWP_NOSIZE | 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); @@ -1433,40 +1426,63 @@ POINT p; GetWindowRect(list1, &r); p.x = r.left; p.y = r.top; - ScreenToClient(tab,&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); + ScreenToClient(dialog,&p); + + 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 list2b = GetDlgItem(dialog, IDC_LIST_UNIT_INPUT2); HWND list3a = GetDlgItem(dialog, IDC_LIST_UNIT_OUTPUT1); HWND list3b = GetDlgItem(dialog, IDC_LIST_UNIT_OUTPUT2); - GetWindowRect(list2a, &r); - SetWindowPos(list2a, 0, 0, 0, r.right-r.left, newy, resize_flags); + int list2a_x = list1_x + list1_cx + marginx; + 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(list2b, 0, 0, 0, r.right-r.left, newy, resize_flags); + SetWindowPos(list2a, 0, list2a_x, p.y, list2a_cx, newy, move_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); - 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.y = r.top; - ScreenToClient(dialog,&p); - SetWindowPos(check_dynamic_output, 0, p.x, newy, 0, 0, move_flags); + ScreenToClient(dialog, &p); + 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); } diff --git a/src/winmain.cpp b/src/winmain.cpp index fea261a..327e7dc 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -52,6 +52,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { 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()->SetNameOfConfigurationFile(); GetPrgRes()->ReadFromFile();