diff --git a/TODO b/TODO index 33bdbd4..8b81704 100644 --- a/TODO +++ b/TODO @@ -7,6 +7,6 @@ TODO TTCalc new computer) * To add some physical constants * To make the help -* To resize the last column in lists (variabies and functions) to the main window -* To block the possibility of putting digits as names of variables and funtions +* To add navigation from the keyboard (in the two lists - funtions and variables) + diff --git a/res/abacus_01.bmp b/res/abacus_01.bmp index b750c4d..4e7bcc1 100644 Binary files a/res/abacus_01.bmp and b/res/abacus_01.bmp differ diff --git a/src/functions.cpp b/src/functions.cpp index 6af4bd8..485ec32 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -177,6 +177,33 @@ char buffer[20]; } + +void WmTabCommand_AddFunctionShowError(HWND hWnd, ttmath::ErrorCode error) +{ +const char * message; + + switch( error ) + { + case ttmath::err_object_exists: + message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_function_exists); + break; + + case ttmath::err_incorrect_name: + message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_incorrect_name); + break; + + default: + message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::unknown_error); + break; + } + + + MessageBox( hWnd, message, + GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption), + MB_ICONERROR); +} + + BOOL WmTabCommand_AddFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_caption); @@ -194,17 +221,10 @@ BOOL WmTabCommand_AddFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa code = GetPrgRes()->GetFunctions()->Add(name, value, parameters); GetPrgRes()->GetThreadController()->StartCalculating(); - if( code == ttmath::err_object_exists ) - { - MessageBox( hWnd, - GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_function_exists), - GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption), - MB_ICONERROR); - - return true; - } - - AddNewItemToFunctionList(list, name, value, parameters); + if( code != ttmath::err_ok ) + WmTabCommand_AddFunctionShowError(hWnd, code); + else + AddNewItemToFunctionList(list, name, value, parameters); } return true; diff --git a/src/languages.cpp b/src/languages.cpp index c6a6db1..1f4d13f 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -195,8 +195,8 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(dialog_box_add_variable_caption,"Add a new variable"); InsertGuiPair(dialog_box_edit_variable_caption,"Edit a variable"); - InsertGuiPair(dialog_box_add_variable_incorrect_name,"Incorrect name of variable"); - InsertGuiPair(dialog_box_add_variable_incorrect_value,"Incorrect value of variable"); + InsertGuiPair(dialog_box_add_variable_incorrect_name,"An incorrect name of the variable"); + InsertGuiPair(dialog_box_add_variable_incorrect_value,"An incorrect value of the variable"); InsertGuiPair(dialog_box_add_variable_variable_exists,"This variable already exists"); InsertGuiPair(dialog_box_edit_variable_unknown_variable,"There isn't this variable in my table. There's probably an internal error!"); InsertGuiPair(dialog_box_delete_variable_confirm,"Are you sure that you want to delete those variables?"); @@ -207,6 +207,7 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(dialog_box_edit_function_unknown_function,"There isn't this function in my table. There's probably an internal error!"); InsertGuiPair(dialog_box_delete_function_confirm,"Are you sure that you want to delete those functions?"); InsertGuiPair(dialog_box_function_not_all_deleted,"There are some functions which I was not able to delete. Probably an internal error!"); + InsertGuiPair(dialog_box_add_function_incorrect_name,"An incorrect name of the function"); InsertGuiPair(list_variables_header_1,"Name"); InsertGuiPair(list_variables_header_2,"Value"); @@ -285,6 +286,7 @@ void Languages::InitGuiMessagesTab() " the developer or programmer just contact with me." ); InsertGuiPair(about_box_title, "About"); + InsertGuiPair(unknown_error, "An unknown error has occurred"); @@ -309,6 +311,8 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(dialog_box_edit_function_unknown_function,"Podanej funkcji nie ma w tablicy. Prawdopodobnie błąd wewnętrzny programu."); InsertGuiPair(dialog_box_delete_function_confirm,"Czy napewno usunąć zaznaczone funkcje?"); InsertGuiPair(dialog_box_function_not_all_deleted,"Zostało kilka funkcji których nie można było skasować. Prawdopodobnie błąd wewnętrzny programu."); + InsertGuiPair(dialog_box_add_function_incorrect_name,"Nieprawidłowa nazwa funkcji"); + InsertGuiPair(list_variables_header_1,"Nazwa"); InsertGuiPair(list_variables_header_2,"Wartość"); @@ -388,6 +392,8 @@ void Languages::InitGuiMessagesTab() " poprostu skontaktuj się ze mną." ); InsertGuiPair(about_box_title, "O programie"); + InsertGuiPair(unknown_error, "Nieznany kod błędu"); + } diff --git a/src/languages.h b/src/languages.h index cc2fa9b..13eb70d 100644 --- a/src/languages.h +++ b/src/languages.h @@ -68,6 +68,7 @@ public: dialog_box_edit_function_unknown_function, dialog_box_delete_function_confirm, dialog_box_function_not_all_deleted, + dialog_box_add_function_incorrect_name, list_variables_header_1, list_variables_header_2, list_functions_header_1, @@ -122,7 +123,8 @@ public: about_text, about_box_title, display_digit, - display_group_scientific + display_group_scientific, + unknown_error }; // the first item must be with zero index diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9a97253..40dc5a9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -673,6 +673,13 @@ using TabWindowFunctions::last_code; EnableWindow(button_err, true); + if( last_code == ttmath::err_unknown_variable || + last_code == ttmath::err_division_by_zero || + last_code == ttmath::err_overflow || + last_code == ttmath::err_unknown_function || + last_code == ttmath::err_improper_argument ) + TabWindowFunctions::PrintErrorCode(); + return true; } diff --git a/src/tabs.cpp b/src/tabs.cpp index a3738e1..4d7a4cc 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -983,7 +983,7 @@ return messages.Call(message, hWnd, message, wParam, lParam); -void SetSizeOfFunctionVariableList(int tab_id, int list_id) +void SetSizeOfFunctionVariableList(int tab_id, int list_id, int last_column) { HWND main = GetPrgRes()->GetMainWindow(); HWND tab = GetDlgItem(main, IDC_TAB); @@ -1016,18 +1016,26 @@ RECT r_main, r; p2.x -= r_main.left; p2.y -= r_main.top; ScreenToClient(dialog, &p); - MoveWindow(list, p.x, p.y, cx-p2.x-border_x-2, cy-p2.y-border_y-2, true); + int list_cx = cx-p2.x-border_x-2; + MoveWindow(list, p.x, p.y, list_cx, cy-p2.y-border_y-2, true); + + int sum = 0; + for(int i=0 ; iGetLanguages()->GuiMessage(Languages::dialog_box_add_variable_variable_exists); + break; + + case ttmath::err_incorrect_name: + message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_variable_incorrect_name); + break; + + default: + message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::unknown_error); + break; + } + + + MessageBox( hWnd, message, + GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption), + MB_ICONERROR); +} + + + + BOOL WmTabCommand_AddVariable(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_variable_caption); @@ -190,17 +220,10 @@ BOOL WmTabCommand_AddVariable(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa code = GetPrgRes()->GetVariables()->Add(name, value); GetPrgRes()->GetThreadController()->StartCalculating(); - if( code == ttmath::err_object_exists ) - { - MessageBox( hWnd, - GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_variable_variable_exists), - GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption), - MB_ICONERROR); - - return true; - } - - AddNewItemToVariableList(list, name, value); + if( code != ttmath::err_ok ) + WmTabCommand_AddVariableShowError(hWnd, code); + else + AddNewItemToVariableList(list, name, value); } return true;