From ee05abc94d6afd77077ea61af9d8a4cf6bd97a6e Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 9 Dec 2007 20:05:15 +0000 Subject: [PATCH] added: 'decimal point' option on the display tab git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@59 e52654a7-88a9-db11-a3e9-0013d4bc506e --- src/languages.cpp | 2 ++ src/languages.h | 1 + src/parsermanager.cpp | 6 ++++++ src/parsermanager.h | 4 +++- src/programresources.cpp | 22 +++++++++++++++++++- src/programresources.h | 10 +++++++++- src/resource.h | 3 +++ src/resource.rc | 43 ++++++++++++++++++++++++---------------- src/tabs.cpp | 23 ++++++++++++++++++++- 9 files changed, 93 insertions(+), 21 deletions(-) diff --git a/src/languages.cpp b/src/languages.cpp index 88f244e..ebc7613 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -251,6 +251,7 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(display_always_scientific,"Always"); InsertGuiPair(display_not_always_scientific,"When the exponent is greater than:"); InsertGuiPair(display_group_scientific, "Print the result as the scientific value"); + InsertGuiPair(display_decimal_point, "Decimal point"); InsertGuiPair(convert_type, "Type"); InsertGuiPair(convert_input, "Input"); InsertGuiPair(convert_output, "Output"); @@ -373,6 +374,7 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(display_always_scientific,"Zawsze"); InsertGuiPair(display_not_always_scientific,"Jeśli eksponent jest większy niż:"); InsertGuiPair(display_group_scientific, "Wyświetl wynik w postaci naukowej"); + InsertGuiPair(display_decimal_point, "Przecinek dziesiętny"); InsertGuiPair(convert_type, "Typ"); InsertGuiPair(convert_input, "Wejście"); InsertGuiPair(convert_output, "Wyjście"); diff --git a/src/languages.h b/src/languages.h index f8fcea9..38443d8 100644 --- a/src/languages.h +++ b/src/languages.h @@ -100,6 +100,7 @@ public: display_rounding, display_always_scientific, display_not_always_scientific, + display_decimal_point, convert_type, convert_input, convert_output, diff --git a/src/parsermanager.cpp b/src/parsermanager.cpp index b957138..e590df7 100644 --- a/src/parsermanager.cpp +++ b/src/parsermanager.cpp @@ -152,6 +152,12 @@ unsigned int i; conv_type = GetPrgRes()->GetConvType(); GetPrgRes()->GetConvUnit(conv_type, conv_input_unit, conv_output_unit); + + // + if( GetPrgRes()->GetDecimalPoint() == 0 ) + decimal_point = '.'; + else + decimal_point = ','; } diff --git a/src/parsermanager.h b/src/parsermanager.h index 3adb291..63f683d 100644 --- a/src/parsermanager.h +++ b/src/parsermanager.h @@ -140,6 +140,7 @@ private: int precision; Languages::Country country; ttmath::ErrorCode code; + char decimal_point; /* @@ -189,6 +190,7 @@ private: } } + // 1 if carry template int PrintResult(ttmath::Parser & matparser) @@ -209,7 +211,7 @@ private: return 1; } - if( result.ToString(buffer2,base_output, always_scientific, when_scientific, rounding) ) + if( result.ToString(buffer2,base_output, always_scientific, when_scientific, rounding, 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 e80b27d..44d0428 100644 --- a/src/programresources.cpp +++ b/src/programresources.cpp @@ -260,6 +260,21 @@ int ProgramResources::GetBaseOutput() } +void ProgramResources::SetDecimalPoint(int decimal) +{ + decimal_point = decimal; + + if( decimal_point<0 || decimal_point>1 ) + decimal_point = 0; +} + + +int ProgramResources::GetDecimalPoint() +{ + return decimal_point; +} + + // @@ -393,6 +408,8 @@ ProgramResources::ProgramResources() conv_type = 0; ConvUnitCheckAll(); + + decimal_point = 0; } @@ -602,6 +619,7 @@ std::string ini_value[20]; iparser.Associate( "global|disp.rounding", &ini_value[11] ); 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( "variables", &temp_variables ); iparser.Associate( "functions", &temp_functions ); @@ -647,12 +665,13 @@ std::string ini_value[20]; SetDisplayWhenScientific( atoi(ini_value[10].c_str()) ); SetDisplayRounding( atoi(ini_value[11].c_str()) ); - if( ini_value[13] == "1" ) languages.SetCurrentLanguage(Languages::pl); else languages.SetCurrentLanguage(Languages::en); + SetDecimalPoint( atoi(ini_value[14].c_str()) ); + if( err != IniParser::err_ok ) bad_line = iparser.GetBadLine(); @@ -688,6 +707,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.dec.point = " << decimal_point << std::endl; file << "\n[variables]\n"; diff --git a/src/programresources.h b/src/programresources.h index a0a013a..063d023 100644 --- a/src/programresources.h +++ b/src/programresources.h @@ -274,7 +274,13 @@ public: */ int GetBadLine(); - + /*! + setting and returning the decimal point used during printig values + 0 - '.' + 1 - ',' + */ + void SetDecimalPoint(int decimal); + int GetDecimalPoint(); /*! @@ -329,6 +335,8 @@ private: int base_input; int base_output; + int decimal_point; + bool display_always_scientific; int display_when_scientific; int display_rounding; diff --git a/src/resource.h b/src/resource.h index 42565a0..05e2099 100644 --- a/src/resource.h +++ b/src/resource.h @@ -162,6 +162,9 @@ #define IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC 1165 #define IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC 1166 #define IDC_LABEL_GROUP_SCIENTIFIC 1168 +#define IDC_LABEL_DECIMAL_POINT 1169 +#define IDC_COMBO_DECIMAL_POINT 1170 + // convert tab #define IDC_LIST_UNIT_TYPE 1200 diff --git a/src/resource.rc b/src/resource.rc index cc5869c..74a9236 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -173,23 +173,32 @@ END #endif -114 DIALOG DISCARDABLE 0, 0, 255, 90 -STYLE DS_3DLOOK | DS_FIXEDSYS |DS_SETFONT |WS_CHILD | WS_TABSTOP |WS_GROUP -CAPTION "tab5" -FONT 8, "Ms Shell Dlg" -BEGIN - COMBOBOX 1156,58,5,63,200,CBS_DROPDOWNLIST | WS_TABSTOP | WS_GROUP - COMBOBOX 1157,58,19,63,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 - 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,WS_GROUP | WS_TABSTOP | ES_NUMBER - CONTROL "",1165,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_ARROWKEYS ,213,37,11,14 - GROUPBOX "Print scientific value",1168,11,51,240,31 -END +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 | + WS_TABSTOP + COMBOBOX 1157,58,19,63,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 + 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 + 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 + + 115 DIALOG DISCARDABLE 0, 0, 260, 90 STYLE DS_3DLOOK | DS_FIXEDSYS | WS_CHILD | WS_CAPTION | WS_GROUP | diff --git a/src/tabs.cpp b/src/tabs.cpp index ab21c72..8295a81 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -443,6 +443,9 @@ int i; SetDlgItemText(hWnd, IDC_RADIO_DISPLAY_NOT_ALWAYS_SCIENTIFIC, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_not_always_scientific)); SetDlgItemText(hWnd, IDC_LABEL_GROUP_SCIENTIFIC, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_group_scientific)); + + SetDlgItemText(hWnd, IDC_LABEL_DECIMAL_POINT, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_decimal_point)); + } @@ -772,6 +775,19 @@ return true; } +BOOL WmTabCommand_DisplayDecimalPointChanged(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + if( HIWORD(wParam) != CBN_SELCHANGE ) + return false; + + GetPrgRes()->GetThreadController()->StopCalculating(); + GetPrgRes()->SetDecimalPoint( (int)SendDlgItemMessage(hWnd, IDC_COMBO_DECIMAL_POINT, CB_GETCURSEL, 0, 0) ); + GetPrgRes()->GetThreadController()->StartCalculating(); + +return true; +} + + BOOL WmTabCommand_DisplayRoundingChanged(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if( HIWORD(wParam) != CBN_SELCHANGE ) @@ -944,7 +960,7 @@ void CreateTabCommandMessagesTable(Messages & cmessages) 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); - + cmessages.Associate(IDC_COMBO_DECIMAL_POINT, WmTabCommand_DisplayDecimalPointChanged); @@ -1202,6 +1218,11 @@ char buffer[20]; sprintf(buffer,"%d", GetPrgRes()->GetDisplayWhenScientific()); SetDlgItemText(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC, buffer); + 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); + return true; }