From b7b52c9ebe8bb7d30fdf8fa4e155070955da5638 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 12 Apr 2008 08:52:21 +0000 Subject: [PATCH] added: 'remove trailing zeroes' option on 'display' tab removed: 'cut off last non valid digits' on 'rounding' option on 'display' tab git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@64 e52654a7-88a9-db11-a3e9-0013d4bc506e --- src/languages.cpp | 15 ++++++++------- src/languages.h | 2 +- src/parsermanager.cpp | 13 +++++++------ src/parsermanager.h | 3 ++- src/programresources.cpp | 24 ++++++++++++++++++++---- src/programresources.h | 9 +++++++++ src/resource.h | 1 + src/resource.rc | 15 +++++++++------ src/tabs.cpp | 27 +++++++++++++++++++++++---- 9 files changed, 80 insertions(+), 29 deletions(-) diff --git a/src/languages.cpp b/src/languages.cpp index acfd6f3..eee721c 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -241,10 +241,11 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(overflow_during_printing,"Overflow during printing"); InsertGuiPair(combo_rounding_none,"None"); - InsertGuiPair(combo_rounding_cut_last_digits,"Cut off last non-valid digits"); - InsertGuiPair(combo_rounding_integer,"Round to the nearest integer"); + InsertGuiPair(combo_rounding_integer,"to integer"); InsertGuiPair(combo_rounding_to_number,"to"); - InsertGuiPair(combo_rounding_after_comma,"digit(s) after comma"); + InsertGuiPair(combo_rounding_after_comma,"digit(s)"); + InsertGuiPair(check_remove_zeroes,"Remove trailing zeroes"); + InsertGuiPair(display_input, "Input"); InsertGuiPair(display_output, "Output"); InsertGuiPair(display_rounding, "Rounding"); @@ -362,11 +363,11 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(overflow_during_printing,"Przepełnienie podczas wypisywania"); - InsertGuiPair(combo_rounding_none,"bez zaokrąglania"); - InsertGuiPair(combo_rounding_cut_last_digits,"skasować nie znaczące zera"); - InsertGuiPair(combo_rounding_integer,"do najbliższej całkowitej"); + InsertGuiPair(combo_rounding_none,"bez zmian"); + InsertGuiPair(combo_rounding_integer,"do całkowitej"); InsertGuiPair(combo_rounding_to_number,"do"); - InsertGuiPair(combo_rounding_after_comma,"cyfr(y) po przecinku"); + InsertGuiPair(combo_rounding_after_comma,"cyfr(y)"); + InsertGuiPair(check_remove_zeroes,"Skasuj nieznaczące zera"); InsertGuiPair(display_input,"Wejście"); InsertGuiPair(display_output,"Wyjście"); diff --git a/src/languages.h b/src/languages.h index 38443d8..0d1d4d1 100644 --- a/src/languages.h +++ b/src/languages.h @@ -91,10 +91,10 @@ public: precision_3_info, overflow_during_printing, combo_rounding_none, - combo_rounding_cut_last_digits, combo_rounding_integer, combo_rounding_to_number, combo_rounding_after_comma, + check_remove_zeroes, display_input, display_output, display_rounding, diff --git a/src/parsermanager.cpp b/src/parsermanager.cpp index e590df7..44c6e37 100644 --- a/src/parsermanager.cpp +++ b/src/parsermanager.cpp @@ -48,7 +48,8 @@ ParserManager::ParserManager() : buffer_len(2048) base_input = base_output = 10; always_scientific = 0; when_scientific = 15; - rounding = -2; + rounding = -1; + remove_zeroes = true; } @@ -60,6 +61,7 @@ ParserManager::ParserManager(const ParserManager & p) : buffer_len(p.buffer_len) always_scientific = p.always_scientific; when_scientific = p.when_scientific; rounding = p.rounding; + remove_zeroes = p.remove_zeroes; } @@ -147,13 +149,12 @@ unsigned int i; when_scientific = GetPrgRes()->GetDisplayWhenScientific(); rounding = GetPrgRes()->GetDisplayRounding(); precision = GetPrgRes()->GetPrecision(); - - country = GetPrgRes()->GetLanguages()->GetCurrentLanguage(); + remove_zeroes = GetPrgRes()->GetRemovingZeroes(); + country = GetPrgRes()->GetLanguages()->GetCurrentLanguage(); conv_type = GetPrgRes()->GetConvType(); GetPrgRes()->GetConvUnit(conv_type, conv_input_unit, conv_output_unit); - // if( GetPrgRes()->GetDecimalPoint() == 0 ) decimal_point = '.'; else @@ -242,7 +243,7 @@ HWND conv_tab = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_convert); return; } - result.ToString(buffer2,10,false,3,-2); + result.ToString(buffer2,10,false,3,-1, true); buffer1 += buffer2; buffer1 += " "; @@ -261,7 +262,7 @@ HWND conv_tab = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_convert); return; } - result.ToString(buffer2,10,false,3,-2); + result.ToString(buffer2,10,false,3,-1, true); buffer1 += buffer2; buffer1 += " "; diff --git a/src/parsermanager.h b/src/parsermanager.h index 63f683d..cedfe3a 100644 --- a/src/parsermanager.h +++ b/src/parsermanager.h @@ -137,6 +137,7 @@ private: bool always_scientific; int when_scientific; int rounding; + bool remove_zeroes; int precision; Languages::Country country; ttmath::ErrorCode code; @@ -211,7 +212,7 @@ private: return 1; } - if( result.ToString(buffer2,base_output, always_scientific, when_scientific, rounding, decimal_point) ) + if( result.ToString(buffer2,base_output, always_scientific, when_scientific, rounding, remove_zeroes, decimal_point) ) { // we shouldn't have had this error in the new version of ToStrign(...) // (where we're using a bigger type for calculating) diff --git a/src/programresources.cpp b/src/programresources.cpp index 6414b26..7bfcf64 100644 --- a/src/programresources.cpp +++ b/src/programresources.cpp @@ -182,20 +182,32 @@ bool ProgramResources::GetAlwaysOnTop() void ProgramResources::SetDisplayRounding(int r) { - if(r<-2) - r = -2; + if( r < -1 ) + r = -1; - if(r>99) + if( r > 99 ) r = 99; display_rounding = r; } + int ProgramResources::GetDisplayRounding() { return display_rounding; } + +void ProgramResources::SetRemovingZeroes(bool r) +{ + remove_zeroes = r; +} + +bool ProgramResources::GetRemovingZeroes() +{ + return remove_zeroes; +} + void ProgramResources::SetDisplayAlwaysScientific(bool a) { display_always_scientific = a; @@ -392,7 +404,8 @@ ProgramResources::ProgramResources() display_always_scientific = false; display_when_scientific = 15; - display_rounding = -2; + display_rounding = -1; + remove_zeroes = true; for(int i=HowManyTabWindows()-1 ; i!=-1 ; --i) tab_window[i] = 0; @@ -625,6 +638,7 @@ std::string ini_value[20]; iparser.Associate( "global|size.y", &ini_value[12] ); iparser.Associate( "global|language", &ini_value[13] ); iparser.Associate( "global|disp.dec.point", &ini_value[14] ); + iparser.Associate( "global|disp.remove.zeroes", &ini_value[15] ); iparser.Associate( "variables", &temp_variables ); iparser.Associate( "functions", &temp_functions ); @@ -669,6 +683,7 @@ std::string ini_value[20]; SetDisplayAlwaysScientific( bool(atoi(ini_value[9].c_str())) ); SetDisplayWhenScientific( atoi(ini_value[10].c_str()) ); SetDisplayRounding( atoi(ini_value[11].c_str()) ); + SetRemovingZeroes( bool(atoi(ini_value[15].c_str())) ); if( ini_value[13] == "1" ) languages.SetCurrentLanguage(Languages::pl); @@ -712,6 +727,7 @@ std::ofstream file( configuration_file.c_str() ); file << "disp.alw.scientific = " << (int)display_always_scientific << std::endl; file << "disp.when.scientific = " << display_when_scientific << std::endl; file << "disp.rounding = " << display_rounding << std::endl; + file << "disp.remove.zeroes = " << (int)remove_zeroes << std::endl; file << "disp.dec.point = " << decimal_point << std::endl; file << "\n[variables]\n"; diff --git a/src/programresources.h b/src/programresources.h index 063d023..29bff83 100644 --- a/src/programresources.h +++ b/src/programresources.h @@ -283,6 +283,14 @@ public: int GetDecimalPoint(); + /*! + setting and returning the state of removing trailing zeroes + (used during printing values) + */ + void SetRemovingZeroes(bool r); + bool GetRemovingZeroes(); + + /*! these methods set and return the kind of conversion which should be performed @@ -340,6 +348,7 @@ private: bool display_always_scientific; int display_when_scientific; int display_rounding; + bool remove_zeroes; int bad_line; diff --git a/src/resource.h b/src/resource.h index 05e2099..4a22a77 100644 --- a/src/resource.h +++ b/src/resource.h @@ -164,6 +164,7 @@ #define IDC_LABEL_GROUP_SCIENTIFIC 1168 #define IDC_LABEL_DECIMAL_POINT 1169 #define IDC_COMBO_DECIMAL_POINT 1170 +#define IDC_CHECK_REMOVE_ZEROES 1171 // convert tab diff --git a/src/resource.rc b/src/resource.rc index 74a9236..1ce3d3a 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -173,29 +173,32 @@ END #endif + 114 DIALOG DISCARDABLE 0, 0, 255, 90 STYLE DS_3DLOOK | DS_FIXEDSYS | WS_CHILD | WS_CAPTION | WS_GROUP | WS_TABSTOP CAPTION "tab5" FONT 8, "Ms Shell Dlg" BEGIN - COMBOBOX 1156,58,5,63,200,CBS_DROPDOWNLIST | WS_GROUP | + COMBOBOX 1156,58,5,69,200,CBS_DROPDOWNLIST | WS_GROUP | WS_TABSTOP - COMBOBOX 1157,58,19,63,200,CBS_DROPDOWNLIST | WS_TABSTOP + COMBOBOX 1157,58,19,69,200,CBS_DROPDOWNLIST | WS_TABSTOP LTEXT "Input",1162,11,7,27,8 LTEXT "Output",1163,11,22,29,8 LTEXT "Rounding",1164,11,36,43,8 - COMBOBOX 1159,58,33,121,200,CBS_DROPDOWNLIST | WS_TABSTOP + LTEXT "Decimal point",1169,178,21,68,8 + COMBOBOX 1170,143,19,29,62,CBS_DROPDOWNLIST | WS_TABSTOP + CONTROL "remove trailing zeroes",IDC_CHECK_REMOVE_ZEROES,"Button", + BS_AUTOCHECKBOX | WS_TABSTOP,143,35,101,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 CONTROL "When the exponent is greater than:",1161,"Button", BS_AUTORADIOBUTTON | BS_LEFT,77,65,130,10 EDITTEXT 1166,211,63,29,14,ES_NUMBER | WS_GROUP CONTROL "",1165,"msctls_updown32",UDS_SETBUDDYINT | - UDS_ALIGNRIGHT | UDS_ARROWKEYS,213,37,11,14 + UDS_ALIGNRIGHT | UDS_ARROWKEYS,201,73,11,14 GROUPBOX "Print scientific value",1168,11,51,240,31 - RTEXT "Decimal point",1169,147,22,68,8 - COMBOBOX 1170,222,19,29,62,CBS_DROPDOWNLIST | WS_TABSTOP END diff --git a/src/tabs.cpp b/src/tabs.cpp index 8295a81..9897d49 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -413,7 +413,7 @@ int i; SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_RESETCONTENT, 0, 0); - SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_cut_last_digits) ); +// SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_cut_last_digits) ); SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_none) ); SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_integer) ); @@ -432,7 +432,7 @@ int i; if( r > max_r ) r = max_r; - SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_SETCURSEL, r+2, 0); + SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_SETCURSEL, r+1, 0); SetDlgItemText(hWnd, IDC_LABEL_DISPLAY_INPUT, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_input)); @@ -446,6 +446,7 @@ int i; SetDlgItemText(hWnd, IDC_LABEL_DECIMAL_POINT, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_decimal_point)); + SetDlgItemText(hWnd, IDC_CHECK_REMOVE_ZEROES, GetPrgRes()->GetLanguages()->GuiMessage(Languages::check_remove_zeroes)); } @@ -794,7 +795,21 @@ BOOL WmTabCommand_DisplayRoundingChanged(HWND hWnd, UINT message, WPARAM wParam, return false; GetPrgRes()->GetThreadController()->StopCalculating(); - GetPrgRes()->SetDisplayRounding( (int)SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_GETCURSEL, 0, 0) - 2); + GetPrgRes()->SetDisplayRounding( (int)SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_GETCURSEL, 0, 0) - 1); + GetPrgRes()->GetThreadController()->StartCalculating(); + +return true; +} + +BOOL WmTabCommand_RemoveZeroesChanged(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + GetPrgRes()->GetThreadController()->StopCalculating(); + + if( IsDlgButtonChecked(hWnd, IDC_CHECK_REMOVE_ZEROES) == BST_CHECKED ) + GetPrgRes()->SetRemovingZeroes(true); + else + GetPrgRes()->SetRemovingZeroes(false); + GetPrgRes()->GetThreadController()->StartCalculating(); return true; @@ -957,6 +972,8 @@ void CreateTabCommandMessagesTable(Messages & cmessages) cmessages.Associate(IDC_COMBO_DISPLAY_INPUT, WmTabCommand_DisplayInputChanged); cmessages.Associate(IDC_COMBO_DISPLAY_OUTPUT, WmTabCommand_DisplayOutputChanged); cmessages.Associate(IDC_COMBO_DISPLAY_ROUNDING, WmTabCommand_DisplayRoundingChanged); + cmessages.Associate(IDC_CHECK_REMOVE_ZEROES, WmTabCommand_RemoveZeroesChanged); + cmessages.Associate(IDC_RADIO_DISPLAY_ALWAYS_SCIENTIFIC, WmTabCommand_SetDisplayAlwaysScientific); cmessages.Associate(IDC_RADIO_DISPLAY_NOT_ALWAYS_SCIENTIFIC, WmTabCommand_SetDisplayNotAlwaysScientific); cmessages.Associate(IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC, WmTabCommand_SetDisplayWhenScientific); @@ -1220,9 +1237,11 @@ char buffer[20]; SendDlgItemMessage(hWnd, IDC_COMBO_DECIMAL_POINT, CB_ADDSTRING, 0, (LPARAM)" ."); SendDlgItemMessage(hWnd, IDC_COMBO_DECIMAL_POINT, CB_ADDSTRING, 0, (LPARAM)" ,"); - SendDlgItemMessage(hWnd, IDC_COMBO_DECIMAL_POINT, CB_SETCURSEL, GetPrgRes()->GetDecimalPoint(), 0); + if( GetPrgRes()->GetRemovingZeroes() ) + CheckDlgButton(hWnd, IDC_CHECK_REMOVE_ZEROES, BST_CHECKED); + return true; }