added: a user can change the names of variables or functions now

changed: the program uses TTMath 0.8.0 now
added: functions: from TTMath 0.8.0:        
       DegToDeg(deg, min, sec), DegToRad(deg), DegToRad(deg, min, sec),
       RadToDeg(rad), Ceil(x), Floor(x), Sqrt(x), Sinh(x), Cosh(x),
       Tanh(x) /Tgh(x)/, Coth(x) /Ctgh(x)/
added: a help
changed: from TTMath 0.8.0:
       renamed: CTan()  into Cot()  or Ctg()
       renamed: ACTan() into ACot() or ACtg()
       Factorial() has a history log now (it can remember last
       10 calculated values)
added: a directory 'help' with files of the help
added: a directory 'setup' with files needed to make an installer
       (we're using InnoSetup Compiler to make it)
fixed: the vertical size of the main window when a user uses a different size
       of the window caption (especially under the Windows XP Luna)
fixed: on Windows 9x: the program hung when a user clicks on a control 
       on the first tab (the procedure SetNextFocus(...) has been completely
       rewritten and the flag WS_EX_CONTROLPARENT on the tab dialogs has
       gone away)
fixed: when started navigating from the keyboard the program showed a wrong
       variable or a funtion in the edit dialog


git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@28 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2007-04-02 00:17:26 +00:00
parent fcd7cdbabf
commit b3d2fc5d24
30 changed files with 1285 additions and 305 deletions

View File

@@ -51,8 +51,8 @@
the version of the application
*/
#define TTCALC_MAJOR_VER 0
#define TTCALC_MINOR_VER 7
#define TTCALC_REVISION_VER 3
#define TTCALC_MINOR_VER 8
#define TTCALC_REVISION_VER 0

View File

@@ -85,14 +85,9 @@ int i;
SendDlgItemMessage(hWnd,IDC_COMBO_FUNCTION_PARAM,CB_SETCURSEL,parameters,0);
if( adding )
{
SetFocus(GetDlgItem(hWnd,IDC_EDIT_FUNCTION_NAME));
}
else
{
SendDlgItemMessage(hWnd, IDC_EDIT_FUNCTION_NAME, EM_SETREADONLY, 1, 0);
SetFocus(GetDlgItem(hWnd,IDC_EDIT_FUNCTION_VALUE));
}
return false;
@@ -127,58 +122,7 @@ return false;
}
void AddNewItemToFunctionList(HWND list, const std::string & name, const std::string & value, int parameters)
{
LVITEM item;
char buffer[20];
item.mask = LVIF_TEXT;
item.pszText = const_cast<char*>( name.c_str() );
item.iSubItem = 0;
int id = ListView_InsertItem(list, &item);
sprintf(buffer,"%u", parameters);
ListView_SetItemText(list,id,1, buffer);
ListView_SetItemText(list,id,2,const_cast<char*>( value.c_str() ));
}
void SetNewFunctionValueIntoList(HWND list, int id)
{
ttmath::ErrorCode code;
char buffer[20];
GetPrgRes()->GetThreadController()->StopCalculating();
code = GetPrgRes()->GetFunctions()->Edit(name, value, parameters);
GetPrgRes()->GetThreadController()->StartCalculating();
if( code == ttmath::err_unknown_object )
{
// there is probably an internal error
// because we should have had this function
MessageBox( list,
GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_edit_function_unknown_function),
GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption),
MB_ICONERROR);
return;
}
sprintf(buffer,"%u",parameters);
ListView_SetItemText(list,id,1,buffer);
ListView_SetItemText(list,id,2,const_cast<char*>( value.c_str() ));
}
void WmTabCommand_AddFunctionShowError(HWND hWnd, ttmath::ErrorCode error)
void ShowError(HWND hWnd, ttmath::ErrorCode error)
{
const char * message;
@@ -192,6 +136,10 @@ const char * message;
message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_incorrect_name);
break;
case ttmath::err_unknown_object:
message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_edit_function_unknown_function);
break;
default:
message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::unknown_error);
break;
@@ -204,29 +152,89 @@ const char * message;
}
int AddNewItemToFunctionList(HWND list, const std::string & name,
const std::string & value, int parameters)
{
LVITEM item;
char buffer[20];
item.mask = LVIF_TEXT;
item.pszText = const_cast<char*>( name.c_str() );
item.iSubItem = 0;
int id = ListView_InsertItem(list, &item);
sprintf(buffer,"%u", parameters);
ListView_SetItemText(list,id,1, buffer);
ListView_SetItemText(list,id,2,const_cast<char*>( value.c_str() ));
return id;
}
void ChangeItemInFunctionList( HWND list, int id, const std::string & old_name,
const std::string & new_name, const std::string & value,
int parameters)
{
if( old_name != new_name )
{
ListView_DeleteItem(list, id);
// as we're using ListView_DeleteItem here the WM_NOTIFY is generated
// and system will call SetDisablingEditDeleteFunctionButtons
// and eventually the focus will be changed into the 'add' button
// (it's a small inconvenience)
int new_id = AddNewItemToFunctionList(list, new_name, value, parameters);
ListView_SetItemState(list,new_id, LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
}
else
{
char buffer[20];
sprintf(buffer,"%u", parameters);
ListView_SetItemText(list,id,1, buffer);
ListView_SetItemText(list,id,2,const_cast<char*>( value.c_str() ));
}
}
BOOL WmTabCommand_AddFunction(HWND, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_functions);
caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_caption);
name = "";
value = "";
adding = true;
parameters = 1;
ttmath::ErrorCode code;
adding = true;
if( DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_FUNCTION), hWnd, DialogProcFunction) )
do
{
if( !DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_FUNCTION), hWnd, DialogProcFunction) )
break;
HWND list = GetDlgItem(hWnd, IDC_FUNCTIONS_LIST);
ttmath::ErrorCode code;
GetPrgRes()->GetThreadController()->StopCalculating();
code = GetPrgRes()->GetFunctions()->Add(name, value, parameters);
GetPrgRes()->GetThreadController()->StartCalculating();
if( code != ttmath::err_ok )
WmTabCommand_AddFunctionShowError(hWnd, code);
ShowError(hWnd, code);
else
AddNewItemToFunctionList(list, name, value, parameters);
{
int id = AddNewItemToFunctionList(list, name, value, parameters);
Variables::SelectOnlyOneItem(list,id);
}
}
while( code != ttmath::err_ok );
return true;
}
@@ -241,35 +249,55 @@ BOOL WmTabCommand_EditFunction(HWND, UINT message, WPARAM wParam, LPARAM)
{
HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_functions);
HWND list = GetDlgItem(hWnd, IDC_FUNCTIONS_LIST);
adding = false;
if( ListView_GetSelectedCount(list) != 1 )
// there must be only one item selected
return true;
int id = ListView_GetSelectionMark(list);
int id = Variables::GetSelectedItem(list);
if( id == -1 )
return true;
const int buffer_size = 300;
char * buffer = new char[buffer_size];
std::string old_name;
ttmath::ErrorCode code;
caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_edit_function_caption);
ListView_GetItemText(list,id,0,buffer, buffer_size);
name = buffer;
ListView_GetItemText(list,id,2,buffer, buffer_size);
value = buffer;
old_name = name = buffer;
ListView_GetItemText(list,id,1,buffer, buffer_size);
parameters = atoi(buffer);
ListView_GetItemText(list,id,2,buffer, buffer_size);
value = buffer;
delete [] buffer;
adding = false;
if( DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_FUNCTION), hWnd, DialogProcFunction) )
do
{
SetNewFunctionValueIntoList(list, id);
if( !DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_FUNCTION), hWnd, DialogProcFunction) )
break;
GetPrgRes()->GetThreadController()->StopCalculating();
// firstly we're trying to change the name
code = GetPrgRes()->GetFunctions()->EditName(old_name, name);
if( code == ttmath::err_ok )
// if we've changed the name then we're changing the value and parameters
code = GetPrgRes()->GetFunctions()->EditValue(name, value, parameters);
GetPrgRes()->GetThreadController()->StartCalculating();
if( code != ttmath::err_ok )
ShowError(list, code);
else
ChangeItemInFunctionList(list, id, old_name, name, value, parameters);
}
while( code != ttmath::err_ok );
return true;
}
@@ -307,7 +335,7 @@ int items = ListView_GetSelectedCount(list);
if( ListView_GetItemState(list, id, LVIS_SELECTED) == LVIS_SELECTED )
{
ListView_GetItemText(list,id,0,buffer,buffer_size);
if( GetPrgRes()->GetFunctions()->Delete(buffer) == ttmath::err_unknown_object )
if( GetPrgRes()->GetFunctions()->Delete(buffer) != ttmath::err_ok )
all_deleted = false;
else
ListView_DeleteItem(list, id);

View File

@@ -87,12 +87,12 @@ void Languages::InitErrorMessagesTab()
InsertErrorPair(ttmath::err_ok,"ok");
InsertErrorPair(ttmath::err_nothing_has_read,"");
InsertErrorPair(ttmath::err_unknown_character,"Unknown character");
InsertErrorPair(ttmath::err_unknown_character,"An unknown character");
InsertErrorPair(ttmath::err_unexpected_final_bracket,"An unexpected final bracket");
InsertErrorPair(ttmath::err_stack_not_clear,"An unknown character has left");
InsertErrorPair(ttmath::err_unknown_variable,"An unknown variable");
InsertErrorPair(ttmath::err_division_by_zero,"Division by zero");
InsertErrorPair(ttmath::err_interrupt,"?");
InsertErrorPair(ttmath::err_interrupt,"The calculating has been broken");
InsertErrorPair(ttmath::err_overflow,"Overflow");
InsertErrorPair(ttmath::err_unknown_function,"An unknown function");
InsertErrorPair(ttmath::err_unknown_operator,"An unknown operator");
@@ -109,7 +109,7 @@ void Languages::InitErrorMessagesTab()
InsertErrorPair(ttmath::err_functions_loop,"There's a recurrence between functions");
InsertErrorPair(ttmath::err_must_be_only_one_value,"Variables or functions must return only one value");
InsertErrorPair(ttmath::err_still_calculating,"Calculating...");
InsertErrorPair(ttmath::err_too_big_factorial,"A too big argument for the factorial() function");
// pl
@@ -122,7 +122,7 @@ void Languages::InitErrorMessagesTab()
InsertErrorPair(ttmath::err_stack_not_clear,"Pozosta<EFBFBD> nieznany znak");
InsertErrorPair(ttmath::err_unknown_variable,"Nieznana zmienna");
InsertErrorPair(ttmath::err_division_by_zero,"Dzielenie przez zero");
InsertErrorPair(ttmath::err_interrupt,"?");
InsertErrorPair(ttmath::err_interrupt,"Obliczenia zosta<74>y przerwane");
InsertErrorPair(ttmath::err_overflow,"Przekroczony zakres");
InsertErrorPair(ttmath::err_unknown_function,"Nieznana funkcja");
InsertErrorPair(ttmath::err_unknown_operator,"Nieznany operator");
@@ -139,6 +139,7 @@ void Languages::InitErrorMessagesTab()
InsertErrorPair(ttmath::err_functions_loop,"Pomi<EFBFBD>dzy funkcjami zachodzi wywo<77>anie rekurencyjne");
InsertErrorPair(ttmath::err_must_be_only_one_value,"Zmienne albo funkcje mog<6F> posiada<64> (zwraca<63>) tylko jedn<64> warto<74><6F>");
InsertErrorPair(ttmath::err_still_calculating,"Obliczanie...");
InsertErrorPair(ttmath::err_too_big_factorial,"Zbyt du<64>y argument dla funkcji factorial()");
@@ -201,13 +202,13 @@ void Languages::InitGuiMessagesTab()
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 these variables?");
InsertGuiPair(dialog_box_delete_variable_confirm,"Do you want to delete these variables?");
InsertGuiPair(dialog_box_variable_not_all_deleted,"There are some variables which I was not able to delete. Probably an internal error!");
InsertGuiPair(dialog_box_add_function_caption,"Add a new function");
InsertGuiPair(dialog_box_edit_function_caption,"Edit a function");
InsertGuiPair(dialog_box_add_function_function_exists,"This function already exists");
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 these functions?");
InsertGuiPair(dialog_box_delete_function_confirm,"Do you want to delete these 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");
@@ -246,8 +247,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(display_output, "Output");
InsertGuiPair(display_rounding, "Rounding");
InsertGuiPair(display_always_scientific,"Always");
InsertGuiPair(display_not_always_scientific,"When the exp is greater than:");
InsertGuiPair(display_digit, "digits");
InsertGuiPair(display_not_always_scientific,"When the exponent is greater than:");
InsertGuiPair(display_group_scientific, "Print the result as the scientific value");
InsertGuiPair(menu_view, "&View");
@@ -261,10 +261,12 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_english, "&English");
InsertGuiPair(menu_view_lang_polish, "&Polish");
InsertGuiPair(menu_view_close_program, "&Close");
InsertGuiPair(menu_view_edit_undo, "&Undo");
InsertGuiPair(menu_view_edit_paste, "&Paste");
InsertGuiPair(menu_view_edit_copy_result,"&Copy the result");
InsertGuiPair(menu_view_help_about, "&About");
InsertGuiPair(menu_edit_undo, "&Undo");
InsertGuiPair(menu_edit_paste, "&Paste");
InsertGuiPair(menu_edit_copy_result, "&Copy the result");
InsertGuiPair(menu_help_help, "&Help");
InsertGuiPair(menu_help_project_page, "&Project page");
InsertGuiPair(menu_help_about, "&About");
InsertGuiPair(cant_init_calculations, "I could not initialize the module of calculations");
InsertGuiPair(message_box_error_caption,"TTCalc");
InsertGuiPair(cant_create_thread, "I could not create the second thread for calculating");
@@ -276,11 +278,11 @@ void Languages::InitGuiMessagesTab()
"Contact: t.sowa@slimaczek.pl\r\n"
"Licence: (New) BSD licence\r\n"
"Project page: http://sourceforge.net/projects/ttcalc\r\n"
"Mathemathical library: TTMath %d.%d.%d\r\n"
"Bignum library: TTMath %d.%d.%d\r\n"
"Programming language: C++\r\n"
"Compiler: %s\r\n"
"\r\n"
"This program uses the TTMath mathematical library"
"This program uses the TTMath bignum library"
" which can be found at http://sourceforge.net/projects/ttmath\r\n"
"\r\n"
"If you have any questions, advices or interesting ideas about"
@@ -290,8 +292,8 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(about_box_title, "About");
InsertGuiPair(about_box_button_close, "Close");
InsertGuiPair(unknown_error, "An unknown error has occurred");
InsertGuiPair(cant_find_help, "I can't find any help files");
InsertGuiPair(cant_open_project_page, "I can't open the project webpage");
// pl
gui_messages_tab.push_back( std::map<GuiMsg, std::string>() );
@@ -353,8 +355,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(display_output,"Wyj<EFBFBD>cie");
InsertGuiPair(display_rounding,"Zaokr<EFBFBD>glenie");
InsertGuiPair(display_always_scientific,"Zawsze");
InsertGuiPair(display_not_always_scientific,"Je<EFBFBD>li eksponent wi<77>kszy ni<6E>");
InsertGuiPair(display_digit, "cyfr");
InsertGuiPair(display_not_always_scientific,"Je<EFBFBD>li eksponent jest wi<EFBFBD>kszy ni<6E>:");
InsertGuiPair(display_group_scientific, "Wy<EFBFBD>wietl wynik w postaci naukowej");
InsertGuiPair(menu_view, "&Widok");
@@ -368,10 +369,12 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_english, "J<EFBFBD>zyk &angielski");
InsertGuiPair(menu_view_lang_polish, "J<EFBFBD>zyk &polski");
InsertGuiPair(menu_view_close_program, "&Zamknij");
InsertGuiPair(menu_view_edit_undo, "&Cofnij");
InsertGuiPair(menu_view_edit_paste, "&Wklej");
InsertGuiPair(menu_view_edit_copy_result,"&Kopiuj wynik");
InsertGuiPair(menu_view_help_about, "&O programie");
InsertGuiPair(menu_edit_undo, "&Cofnij");
InsertGuiPair(menu_edit_paste, "&Wklej");
InsertGuiPair(menu_edit_copy_result, "&Kopiuj wynik");
InsertGuiPair(menu_help_help, "&Pomoc");
InsertGuiPair(menu_help_project_page, "&Strona projektu");
InsertGuiPair(menu_help_about, "&O programie");
InsertGuiPair(cant_init_calculations, "Nie uda<64>o si<73> zainicjalizowa<77> modu<64>u obs<62>ugi oblicze<7A>");
InsertGuiPair(message_box_error_caption,"TTCalc");
InsertGuiPair(cant_create_thread, "Nie uda<64>o si<73> utworzy<7A> drugiego w<>tku do oblicze<7A>");
@@ -383,11 +386,11 @@ void Languages::InitGuiMessagesTab()
"Kontakt: t.sowa@slimaczek.pl\r\n"
"Licencja: (New) BSD\r\n"
"Strona projektu: http://sourceforge.net/projects/ttcalc\r\n"
"Biblioteka matematyczna: TTMath %d.%d.%d\r\n"
"Biblioteka du<EFBFBD>ych liczb: TTMath %d.%d.%d\r\n"
"J<EFBFBD>zyk programowania: C++\r\n"
"Kompilator: %s\r\n"
"\r\n"
"Ten program u<>ywa biblioteki matematycznej TTMath"
"Ten program u<>ywa biblioteki du<EFBFBD>ych liczb TTMath"
" kt<6B>ra jest dost<73>pna na http://sourceforge.net/projects/ttmath\r\n"
"\r\n"
"Je<EFBFBD>eli masz jakie<69> pytania, rady, ciekawe pomys<79>y dotycz<63>ce"
@@ -397,7 +400,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(about_box_title, "O programie");
InsertGuiPair(about_box_button_close, "Zamknij");
InsertGuiPair(unknown_error, "Nieznany kod b<><62>du");
InsertGuiPair(cant_find_help, "Nie mog<6F> znale<6C><65> <20>adnych plik<69>w pomocy");
InsertGuiPair(cant_open_project_page, "Nie mog<6F> otworzy<7A> strony projektu");
}

View File

@@ -111,19 +111,22 @@ public:
menu_view_lang_english,
menu_view_lang_polish,
menu_view_close_program,
menu_view_edit_undo,
menu_view_edit_paste,
menu_view_edit_copy_result,
menu_view_help_about,
menu_edit_undo,
menu_edit_paste,
menu_edit_copy_result,
menu_help_help,
menu_help_project_page,
menu_help_about,
cant_init_calculations,
message_box_error_caption,
cant_create_thread,
cant_create_main_window,
cant_init_common_controls,
cant_find_help,
cant_open_project_page,
about_text,
about_box_title,
about_box_button_close,
display_digit,
display_group_scientific,
unknown_error
};

View File

@@ -38,7 +38,7 @@
#include "compileconfig.h"
#include "winmain.h"
namespace MainWindowFunctions
@@ -47,24 +47,24 @@ namespace MainWindowFunctions
/*!
Loop through all the controls and remove the
dark border that the previous default push
button has.
Loop through all the controls and remove the
dark border that the previous default push
button has.
*/
void ClearPushButtons(HWND hWnd)
{
HWND controls = GetWindow(hWnd, GW_CHILD);
LRESULT dlg_code;
while(controls)
{
dlg_code = SendMessage(controls, WM_GETDLGCODE, 0, 0);
if(dlg_code & DLGC_DEFPUSHBUTTON)
SendMessage(controls, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, true);
controls = GetWindow(controls, GW_HWNDNEXT);
}
HWND controls = GetWindow(hWnd, GW_CHILD);
LRESULT dlg_code;
while(controls)
{
dlg_code = SendMessage(controls, WM_GETDLGCODE, 0, 0);
if(dlg_code & DLGC_DEFPUSHBUTTON)
SendMessage(controls, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, true);
controls = GetWindow(controls, GW_HWNDNEXT);
}
}
@@ -74,33 +74,110 @@ LRESULT dlg_code;
*/
void CheckAndSetDefPushButton(HWND button)
{
LRESULT dlg_code = SendMessage(button, WM_GETDLGCODE, 0, 0);
if(dlg_code & DLGC_UNDEFPUSHBUTTON)
SendMessage(button, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, true);
LRESULT dlg_code = SendMessage(button, WM_GETDLGCODE, 0, 0);
if(dlg_code & DLGC_UNDEFPUSHBUTTON)
SendMessage(button, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, true);
}
HWND GetNextControlInsideTab(HWND input_edit, HWND tab, HWND tab_dialog, HWND focus,
HWND first_control,
WPARAM wParam, bool direction_next)
{
LRESULT dlg_code = SendMessage(focus, WM_GETDLGCODE, 0, 0);
HWND next = 0;
if( focus == first_control )
{
if( wParam==VK_TAB ||
((dlg_code & DLGC_WANTARROWS)==0 && (dlg_code & DLGC_RADIOBUTTON)==0) )
{
if( !direction_next )
next = tab;
else
{
// if we have only radio buttons (precision tab)
// the next item from GetNextDlgTabItem (or if we allow
// the system to look for it) will be the same as the focus
// we must set it on the input_edit
HWND nexttmp = GetNextDlgTabItem(tab_dialog, focus, false);
if( nexttmp == focus )
next = input_edit;
}
}
}
else
// the focus is somewhere inside a tab
{
if( wParam==VK_TAB ||
((dlg_code & DLGC_WANTARROWS)==0 && (dlg_code & DLGC_RADIOBUTTON)==0) )
{
if( direction_next )
{
HWND nexttmp = GetNextDlgTabItem(tab_dialog, focus, false);
if( nexttmp == first_control )
{
next = input_edit;
}
}
}
}
return next;
}
/*!
we're trying to get the next or previous control which should have
the focus now
*/
HWND GetNextControl(HWND focus, HWND output_edit, HWND tab, WPARAM wParam)
HWND GetNextControl(HWND focus, HWND main_window, HWND tab, WPARAM wParam)
{
HWND next = 0;
bool shift = (GetKeyState(VK_SHIFT) & 0xffff0000) != 0;
HWND next = 0;
HWND output_edit = GetDlgItem(main_window, IDC_OUTPUT_EDIT);
HWND input_edit = GetDlgItem(main_window, IDC_INPUT_EDIT);
bool shift = (GetKeyState(VK_SHIFT) & 0xffff0000) != 0;
bool direction_next = true;
int tab_sel = TabCtrl_GetCurSel(tab);
HWND tab_dialog = GetPrgRes()->GetTabWindow(tab_sel);
HWND first_control = GetNextDlgTabItem(tab_dialog, 0, false);
// if an user has pressed 'up' or 'left' or 'tab'+'shift'
// that means we're going 'back'
if( wParam==VK_UP || wParam==VK_LEFT || (wParam==VK_TAB && shift) )
direction_next = false;
if( focus==output_edit && direction_next )
if( focus == input_edit )
{
// if we are on the output edit and the direction is 'forward'
// then the next control will be the 'tab'
next = tab;
if( wParam==VK_TAB || wParam==VK_UP || wParam==VK_DOWN )
{
if( direction_next )
{
next = output_edit;
}
else
{
next = GetNextDlgTabItem(tab_dialog, first_control, true);
ClearPushButtons(tab_dialog);
}
}
}
else
if( focus == output_edit )
{
if( wParam==VK_LEFT || wParam==VK_RIGHT )
return 0;
if( direction_next )
// if we are on the output edit and the direction is 'forward'
// then the next control will be the 'tab'
next = tab;
else
next = input_edit;
}
else
if( focus == tab )
@@ -113,9 +190,7 @@ HWND GetNextControl(HWND focus, HWND output_edit, HWND tab, WPARAM wParam)
if( direction_next )
{
// we're getting the first control on a specific dialog on the selected tab
int tab_sel = TabCtrl_GetCurSel(tab);
HWND tab_dialog = GetPrgRes()->GetTabWindow(tab_sel);
next = GetNextDlgTabItem(tab_dialog, 0, false);
next = first_control;
ClearPushButtons(tab_dialog);
}
else
@@ -125,36 +200,15 @@ HWND GetNextControl(HWND focus, HWND output_edit, HWND tab, WPARAM wParam)
}
}
else
{
// we get here if the focus is not set on 'tab' neither
// on 'output_edit' with the direction equals 'forward'
// if an user has pressed the tab (with or without shift)
// or if the control with a focus doesn't want arrows key
// and the control isn't a radio button we're using
// GetNextDlgTabItem to find the next element
LRESULT dlg_code = SendMessage(focus, WM_GETDLGCODE, 0, 0);
if( wParam==VK_TAB ||
((dlg_code & DLGC_WANTARROWS)==0 && (dlg_code & DLGC_RADIOBUTTON)==0) )
{
// the control returns from GetNextDlgTabItem will not be perfect
// we have to make a small change:
// when this method has returned 'output_edit' and when we're
// moving back and the focus it not set on 'tab' the focus
// should be set into the tab control
HWND nexttmp = GetNextDlgTabItem(GetPrgRes()->GetMainWindow(),
focus, !direction_next);
if( !direction_next && focus!=tab && nexttmp==output_edit )
next = tab;
}
}
next = GetNextControlInsideTab(input_edit, tab, tab_dialog, focus,
first_control, wParam, direction_next);
return next;
}
/*!
this function sets the focus on a specific control
(the standard procedure from the operating system doesn't work well because
@@ -168,10 +222,9 @@ bool SetNextFocus(WPARAM wParam)
HWND next = 0;
HWND main_window = GetPrgRes()->GetMainWindow();
HWND focus = GetFocus();
HWND output_edit = GetDlgItem(main_window, IDC_OUTPUT_EDIT);
HWND tab = GetDlgItem(main_window, IDC_TAB);
next = GetNextControl(focus, output_edit, tab, wParam);
next = GetNextControl(focus, main_window, tab, wParam);
if( next )
{
@@ -244,10 +297,12 @@ HMENU menu = GetMenu(hWnd);
SetMenuLanguageItem(menu, IDM_LANGUAGE_ENGLISH, Languages::menu_view_lang_english);
SetMenuLanguageItem(menu, IDM_LANGUAGE_POLISH, Languages::menu_view_lang_polish);
SetMenuLanguageItem(menu, IDM_CLOSE_PROGRAM, Languages::menu_view_close_program);
SetMenuLanguageItem(menu, IDM_EDIT_UNDO, Languages::menu_view_edit_undo);
SetMenuLanguageItem(menu, IDM_EDIT_PASTE, Languages::menu_view_edit_paste);
SetMenuLanguageItem(menu, IDM_EDIT_COPY_RESULT, Languages::menu_view_edit_copy_result);
SetMenuLanguageItem(menu, IDM_HELP_ABOUT, Languages::menu_view_help_about);
SetMenuLanguageItem(menu, IDM_EDIT_UNDO, Languages::menu_edit_undo);
SetMenuLanguageItem(menu, IDM_EDIT_PASTE, Languages::menu_edit_paste);
SetMenuLanguageItem(menu, IDM_EDIT_COPY_RESULT, Languages::menu_edit_copy_result);
SetMenuLanguageItem(menu, IDM_HELP_HELP, Languages::menu_help_help);
SetMenuLanguageItem(menu, IDM_HELP_PROJECT_PAGE, Languages::menu_help_project_page);
SetMenuLanguageItem(menu, IDM_HELP_ABOUT, Languages::menu_help_about);
DrawMenuBar(hWnd);
}
@@ -259,16 +314,16 @@ RECT r;
GetWindowRect(hTab, &r);
int cy_caption = GetSystemMetrics(SM_CYCAPTION);
int cy_add = 2 * GetSystemMetrics(SM_CYDLGFRAME) +
GetSystemMetrics(SM_CYCAPTION) +
GetSystemMetrics(SM_CYMENU);
int cx_add = 2 * GetSystemMetrics(SM_CXDLGFRAME) +
r.right - r.left;
GetPrgRes()->SetYSizeNormal ( 244 + cy_add );
GetPrgRes()->SetYSizeCompact( 59 + cy_add );
GetPrgRes()->SetYSizeNormal ( 225 + cy_add + cy_caption * 2);
GetPrgRes()->SetYSizeCompact( 59 + cy_add + cy_caption );
GetPrgRes()->SetXSizeMin ( 4 + cx_add );
}
@@ -348,6 +403,8 @@ TCITEM tab_item;
WmInitDialogCreateTab(hTab, tab_precision, IDD_DIALOG_PRECISION, TabWindowProc);
WmInitDialogCreateTab(hTab, tab_display, IDD_DIALOG_DISPLAY, TabWindowProc);
SetSizeOfDialogs();
SendMessage(GetPrgRes()->GetTabWindow(tab_variables), WM_INIT_TAB_VARIABLES, 0,0);
SendMessage(GetPrgRes()->GetTabWindow(tab_functions), WM_INIT_TAB_FUNCTIONS, 0,0);
SendMessage(GetPrgRes()->GetTabWindow(tab_precision), WM_INIT_TAB_PRECISION, 0,0);
@@ -814,6 +871,54 @@ return true;
}
BOOL WmHelp(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
SHELLEXECUTEINFO exec;
exec.cbSize = sizeof(exec);
exec.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
exec.hwnd = 0;
exec.lpVerb = "open";
exec.lpFile = "ttcalc.chm";
exec.lpParameters = 0;
exec.lpDirectory = "";
exec.nShow = SW_SHOWNORMAL;
if( !ShellExecuteEx(&exec) )
{
MessageBox(hWnd,
GetPrgRes()->GetLanguages()->GuiMessage(Languages::cant_find_help),
GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption),
MB_ICONERROR);
}
return true;
}
BOOL WmProjectPage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
SHELLEXECUTEINFO exec;
exec.cbSize = sizeof(exec);
exec.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
exec.hwnd = 0;
exec.lpVerb = "open";
exec.lpFile = "http://sourceforge.net/projects/ttcalc";
exec.lpParameters = 0;
exec.lpDirectory = "";
exec.nShow = SW_SHOWNORMAL;
if( !ShellExecuteEx(&exec) )
{
MessageBox(hWnd,
GetPrgRes()->GetLanguages()->GuiMessage(Languages::cant_open_project_page),
GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption),
MB_ICONERROR);
}
return true;
}
void CreateCommandMessagesTable(Messages & cmessages)
@@ -831,6 +936,8 @@ void CreateCommandMessagesTable(Messages & cmessages)
cmessages.Associate(IDCANCEL, WmCommand_IDCANCEL);
cmessages.Associate(IDM_LANGUAGE_ENGLISH, WmCommand_LanguageEnglish);
cmessages.Associate(IDM_LANGUAGE_POLISH, WmCommand_LanguagePolish);
cmessages.Associate(IDM_HELP_HELP, WmHelp);
cmessages.Associate(IDM_HELP_PROJECT_PAGE, WmProjectPage);
}
@@ -862,6 +969,7 @@ void CreateMainMessagesTable(Messages & messages)
messages.Associate(WM_NOTIFY, WmNotify);
messages.Associate(WM_SIZING, WmSizing);
messages.Associate(WM_SET_LAST_ERROR, WmSetLastError);
messages.Associate(WM_HELP, WmHelp);
}

View File

@@ -531,17 +531,30 @@ std::string application_data;
std::string application_directory = application_data + '\\' + simple_directory_name;
bool success = false;
// we're testing whether we've got our directory or not
if( SetCurrentDirectory( application_directory.c_str() ) )
success = true;
else
// now we must make our directory inside it
if( CreateDirectory(application_directory.c_str(), 0) )
success = true;
// we have to remember the currect directory
// (because we're using it when we're opening the help)
char * buffer = new char[_MAX_PATH];
if( success )
configuration_file = application_directory + '\\' + simple_file_name;
if( GetCurrentDirectory(_MAX_PATH, buffer) )
{
// we're testing whether we've got our directory or not
if( SetCurrentDirectory( application_directory.c_str() ) )
success = true;
else
// now we must create our directory inside it
if( CreateDirectory(application_directory.c_str(), 0) )
success = true;
if( success )
configuration_file = application_directory + '\\' + simple_file_name;
SetCurrentDirectory(buffer);
}
delete [] buffer;
}
}

View File

@@ -49,6 +49,7 @@
#include "threadcontroller.h"
#include <string>
#include <cstdlib>
#include <windows.h>

View File

@@ -76,7 +76,7 @@
#define IDC_BUTTON_ASIN 1071
#define IDC_BUTTON_ACOS 1072
#define IDC_BUTTON_ATAN 1073
#define IDC_BUTTON_ACTAN 1074
#define IDC_BUTTON_ACOT 1074
#define IDC_BUTTON_SGN 1075
#define IDC_BUTTON_MOD 1076
@@ -105,7 +105,7 @@
#define IDC_BUTTON_SIN 1120
#define IDC_BUTTON_COS 1121
#define IDC_BUTTON_TAN 1122
#define IDC_BUTTON_CTAN 1123
#define IDC_BUTTON_COT 1123
#define IDC_BUTTON_LN 1124
#define IDC_BUTTON_LOG 1125
#define IDC_BUTTON_ABS 1126
@@ -160,7 +160,6 @@
#define IDC_LABEL_DISPLAY_ROUNDING 1164
#define IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC 1165
#define IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC 1166
#define IDC_LABEL_DIGIT 1167
#define IDC_LABEL_GROUP_SCIENTIFIC 1168
// menu
@@ -178,7 +177,9 @@
#define IDM_EDIT_UNDO 40030
#define IDM_EDIT_PASTE 40031
#define IDM_EDIT_COPY_RESULT 40032
#define IDM_HELP_ABOUT 40040
#define IDM_HELP_HELP 40040
#define IDM_HELP_PROJECT_PAGE 40041
#define IDM_HELP_ABOUT 40049
// about dialog
#define IDC_ABOUT_TEXT 1200

View File

@@ -35,7 +35,10 @@ BEGIN
END
POPUP "&Help"
BEGIN
MENUITEM "&About", 40040
MENUITEM "&Help", 40040
MENUITEM "&Project page", 40041
MENUITEM SEPARATOR
MENUITEM "&About", 40049
END
END
@@ -43,11 +46,11 @@ END
STYLE DS_SETFONT |DS_CENTER |WS_POPUP |WS_SYSMENU |WS_THICKFRAME |WS_MAXIMIZEBOX |WS_MINIMIZEBOX |WS_CAPTION
MENU 200
CAPTION "TTCalc"
FONT 8, "MS Sans Serif"
FONT 8, "Ms Shell Dlg"
BEGIN
CONTROL "",1000,"EDIT",ES_AUTOHSCROLL |ES_LEFT |WS_CHILD |WS_BORDER |WS_TABSTOP |WS_VISIBLE ,0,6,260,14
CONTROL "",1001,"EDIT",ES_READONLY |ES_AUTOHSCROLL |ES_LEFT |WS_CHILD |WS_BORDER |WS_TABSTOP |WS_VISIBLE ,0,21,260,14
CONTROL "",1010,"SysTabControl32",WS_CHILD |WS_TABSTOP | WS_VISIBLE ,0,39,261,110, WS_EX_CONTROLPARENT
CONTROL "",1010,"SysTabControl32",WS_CHILD |WS_TABSTOP |WS_GROUP| WS_VISIBLE ,0,39,261,110, WS_EX_CONTROLPARENT
END
@@ -80,9 +83,8 @@ BEGIN
LTEXT "param:",1148,7,30,33,8
END
110 DIALOGEX 0, 0, 264, 90
STYLE DS_3DLOOK | DS_FIXEDSYS | WS_CHILD | WS_TABSTOP
EXSTYLE WS_EX_CONTROLPARENT
110 DIALOGEX 0, 0, 287, 90
STYLE DS_3DLOOK | DS_FIXEDSYS |DS_SETFONT | WS_CHILD| WS_TABSTOP |WS_GROUP
FONT 8, "Ms Shell Dlg"
BEGIN
PUSHBUTTON "Clear",1110,3,3,26,14,BS_CENTER | BS_VCENTER
@@ -113,8 +115,8 @@ BEGIN
PUSHBUTTON "tan",1122,131,37,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "atan",1073,160,37,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "exp",1131,189,37,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "ctan",1123,131,54,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "actan",1074,160,54,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "cot",1123,131,54,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "acot",1074,160,54,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "abs",1126,189,54,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "int",1129,131,71,26,14,BS_CENTER | BS_VCENTER
PUSHBUTTON "round",1130,160,71,26,14,BS_CENTER | BS_VCENTER
@@ -128,8 +130,7 @@ END
111 DIALOG 0, 0, 287, 90
STYLE DS_3DLOOK |DS_FIXEDSYS |DS_SETFONT |WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
STYLE DS_3DLOOK |DS_FIXEDSYS |DS_SETFONT |WS_CHILD | WS_TABSTOP |WS_GROUP
CAPTION "tab2"
FONT 8, "Ms Shell Dlg"
BEGIN
@@ -140,8 +141,7 @@ BEGIN
END
112 DIALOG 0, 0, 287, 90
STYLE DS_3DLOOK |DS_FIXEDSYS |DS_SETFONT |WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
STYLE DS_3DLOOK |DS_FIXEDSYS |DS_SETFONT |WS_CHILD | WS_TABSTOP |WS_GROUP
CAPTION "tab3"
FONT 8, "Ms Shell Dlg"
BEGIN
@@ -152,22 +152,20 @@ BEGIN
END
113 DIALOG 0, 0, 287, 90
STYLE DS_3DLOOK |DS_FIXEDSYS |DS_SETFONT |WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
STYLE DS_3DLOOK |DS_FIXEDSYS |DS_SETFONT |WS_CHILD | WS_TABSTOP |WS_GROUP
CAPTION "tab4"
FONT 8, "Ms Shell Dlg"
BEGIN
CONTROL "precision 1",1150,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD |WS_GROUP|WS_TABSTOP |WS_VISIBLE ,15,4,252,10
CONTROL "precision 2",1151,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD | WS_VISIBLE ,15,33,252,10
CONTROL "precision 3",1152,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD | WS_VISIBLE ,15,62,252,10
CONTROL "precision 1",1150,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD |WS_GROUP|WS_TABSTOP | WS_VISIBLE ,15,4,252,10
CONTROL "precision 2",1151,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD |WS_TABSTOP | WS_VISIBLE ,15,33,252,10
CONTROL "precision 3",1152,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD |WS_TABSTOP | WS_VISIBLE ,15,62,252,10
CONTROL "info 1",1153,"STATIC",SS_LEFT |WS_CHILD |WS_VISIBLE ,28,17,245,8
CONTROL "info 2",1154,"STATIC",SS_LEFT |WS_CHILD |WS_VISIBLE ,28,46,245,8
CONTROL "info 3",1155,"STATIC",SS_LEFT |WS_CHILD |WS_VISIBLE ,28,74,245,8
END
114 DIALOG DISCARDABLE 0, 0, 255, 90
STYLE DS_3DLOOK | DS_FIXEDSYS | WS_CHILD | WS_CAPTION
EXSTYLE WS_EX_CONTROLPARENT
STYLE DS_3DLOOK | DS_FIXEDSYS |DS_SETFONT |WS_CHILD | WS_TABSTOP |WS_GROUP
CAPTION "tab5"
FONT 8, "Ms Shell Dlg"
BEGIN
@@ -178,11 +176,10 @@ BEGIN
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 exp greater than:",1161,"Button", BS_AUTORADIOBUTTON | BS_LEFT ,77,65,112,10
EDITTEXT 1166,194,63,29,14,WS_GROUP | WS_TABSTOP | ES_NUMBER
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
LTEXT "Digit",1167,227,65,20,8
END
200 DIALOG DISCARDABLE 0, 0, 349, 202

View File

@@ -138,9 +138,9 @@ return true;
}
BOOL WmTabCommand_Press_ctan(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BOOL WmTabCommand_Press_cot(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
InsertText("ctan()",-1);
InsertText("cot()",-1);
return true;
}
@@ -261,9 +261,9 @@ BOOL WmTabCommand_Press_atan(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
return true;
}
BOOL WmTabCommand_Press_actan(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BOOL WmTabCommand_Press_acot(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
InsertText("actan()",-1);
InsertText("acot()",-1);
return true;
}
@@ -313,7 +313,7 @@ return true;
}
BOOL WmTabCommand_Ok(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
BOOL WmTabCommand_IDOK(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND main = GetPrgRes()->GetMainWindow();
HWND tab = GetDlgItem(main, IDC_TAB);
@@ -335,6 +335,12 @@ int sel = TabCtrl_GetCurSel(tab);
return true;
}
BOOL WmTabCommand_IDCANCEL(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
SendMessage(GetPrgRes()->GetMainWindow(), WM_COMMAND, IDCANCEL, 0);
return true;
}
void SetLanguageTabStandard(HWND hWnd)
{
@@ -431,7 +437,6 @@ int i;
SetDlgItemText(hWnd, IDC_RADIO_DISPLAY_ALWAYS_SCIENTIFIC, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_always_scientific));
SetDlgItemText(hWnd, IDC_RADIO_DISPLAY_NOT_ALWAYS_SCIENTIFIC, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_not_always_scientific));
SetDlgItemText(hWnd, IDC_LABEL_DIGIT, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_digit));
SetDlgItemText(hWnd, IDC_LABEL_GROUP_SCIENTIFIC, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_group_scientific));
}
@@ -557,13 +562,11 @@ void SetDisablingDisplayWhenScientific(HWND hWnd)
{
EnableWindow(GetDlgItem(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC), false);
EnableWindow(GetDlgItem(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC), false);
EnableWindow(GetDlgItem(hWnd, IDC_LABEL_DIGIT), false);
}
else
{
EnableWindow(GetDlgItem(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC), true);
EnableWindow(GetDlgItem(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC), true);
EnableWindow(GetDlgItem(hWnd, IDC_LABEL_DIGIT), true);
}
}
@@ -656,7 +659,7 @@ void CreateTabCommandMessagesTable(Messages & cmessages)
cmessages.Associate(IDC_BUTTON_SIN, WmTabCommand_Press_sin);
cmessages.Associate(IDC_BUTTON_COS, WmTabCommand_Press_cos);
cmessages.Associate(IDC_BUTTON_TAN, WmTabCommand_Press_tan);
cmessages.Associate(IDC_BUTTON_CTAN, WmTabCommand_Press_ctan);
cmessages.Associate(IDC_BUTTON_COT, WmTabCommand_Press_cot);
cmessages.Associate(IDC_BUTTON_LN, WmTabCommand_Press_ln);
cmessages.Associate(IDC_BUTTON_LOG, WmTabCommand_Press_log);
cmessages.Associate(IDC_BUTTON_ABS, WmTabCommand_Press_abs);
@@ -677,7 +680,7 @@ void CreateTabCommandMessagesTable(Messages & cmessages)
cmessages.Associate(IDC_BUTTON_ASIN, WmTabCommand_Press_asin);
cmessages.Associate(IDC_BUTTON_ACOS, WmTabCommand_Press_acos);
cmessages.Associate(IDC_BUTTON_ATAN, WmTabCommand_Press_atan);
cmessages.Associate(IDC_BUTTON_ACTAN, WmTabCommand_Press_actan);
cmessages.Associate(IDC_BUTTON_ACOT, WmTabCommand_Press_acot);
cmessages.Associate(IDC_BUTTON_SGN, WmTabCommand_Press_sgn);
cmessages.Associate(IDC_BUTTON_MOD, WmTabCommand_Press_mod);
@@ -691,7 +694,8 @@ void CreateTabCommandMessagesTable(Messages & cmessages)
cmessages.Associate(IDC_BUTTON_EDIT_VARIABLE, Variables::WmTabCommand_EditVariable);
cmessages.Associate(IDC_BUTTON_DELETE_VARIABLE, Variables::WmTabCommand_DeleteVariable);
cmessages.Associate(IDOK, WmTabCommand_Ok);
cmessages.Associate(IDOK, WmTabCommand_IDOK);
cmessages.Associate(IDCANCEL, WmTabCommand_IDCANCEL);
cmessages.Associate(IDC_BUTTON_ADD_FUNCTION, Functions::WmTabCommand_AddFunction);
cmessages.Associate(IDC_BUTTON_EDIT_FUNCTION, Functions::WmTabCommand_EditFunction);
@@ -861,7 +865,7 @@ LVCOLUMN column;
SetDisablingEditDeleteVariableButtons(hWnd);
if( FillUpVariableList(list) > 0 )
ListView_SetItemState(list, 0, LVIS_SELECTED, LVIS_SELECTED);
ListView_SetItemState(list, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
return true;
}
@@ -892,8 +896,7 @@ LVCOLUMN column;
SetDisablingEditDeleteFunctionButtons(hWnd);
if( FillUpFunctionList(list) > 0 )
ListView_SetItemState(list, 0, LVIS_SELECTED, LVIS_SELECTED);
ListView_SetItemState(list, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
return true;
}
@@ -1116,6 +1119,28 @@ void SetSizeOfFunctionsList()
}
void SetSizeOfDialogs()
{
const int cy_std = 19;
int cy_caption = GetSystemMetrics(SM_CYCAPTION);
if( cy_caption <= cy_std )
return;
int len = GetPrgRes()->HowManyTabWindows();
RECT r;
for(int i = 0 ; i<len ; ++i )
{
HWND dialog = GetPrgRes()->GetTabWindow(i);
GetWindowRect( dialog, &r);
SetWindowPos( dialog,0, 0,0, r.right-r.left, r.bottom-r.top+(cy_caption-cy_std),
SWP_NOZORDER |SWP_NOMOVE);
GetWindowRect( dialog, &r);
}
}
} // namespace TabWindowFunctions

View File

@@ -74,16 +74,16 @@ extern ttmath::ErrorCode last_code;
void SetSizeOfVariablesList();
void SetSizeOfFunctionsList();
BOOL WmTabCommand(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void SetSizeOfDialogs();
namespace Variables
{
extern std::string caption,name,value;
extern bool adding;
char * ChangeToSmallLetters(char * string);
char * StripWhiteCharacters(char * string);
void AddNewItemToVariableList(HWND list, const std::string & name, const std::string & value);
int AddNewItemToVariableList(HWND list, const std::string & name, const std::string & value);
int GetSelectedItem(HWND list);
void SelectOnlyOneItem(HWND list, int id);
BOOL WmTabCommand_AddVariable(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL WmTabCommand_EditVariable(HWND hWnd, UINT message, WPARAM wParam, LPARAM);
@@ -92,10 +92,7 @@ extern ttmath::ErrorCode last_code;
namespace Functions
{
extern std::string caption,name,value;
extern bool adding;
void AddNewItemToFunctionList(HWND list, const std::string & name, const std::string & value, int parameters);
int AddNewItemToFunctionList(HWND list, const std::string & name, const std::string & value, int parameters);
BOOL WmTabCommand_AddFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL WmTabCommand_EditFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM);

View File

@@ -46,23 +46,25 @@ namespace Variables
std::string caption,name,value;
bool adding;
/*!
this method changes the whole string into a string consists of small letters
this function changes the whole string into a string consists of small letters
(it returns the same pointer)
*/
char * ChangeToSmallLetters(char * string)
{
char * p;
for( p = string ; *p>='A' && *p<='Z' ; ++p )
for( char * p = string ; *p>='A' && *p<='Z' ; ++p )
*p = *p - 'A' + 'a';
return string;
}
/*!
this function deletes white characters at the beginning and at the end of a string
it doesn't actually erase them but returns the pointer at the first
non-white character and sets '\0' before the last white character
*/
char * StripWhiteCharacters(char * string)
{
char * start, * end;
@@ -94,15 +96,10 @@ char * pchar;
SetDlgItemText(hWnd,IDC_EDIT_VARIABLE_NAME, name.c_str());
SetDlgItemText(hWnd,IDC_EDIT_VARIABLE_VALUE, value.c_str());
if( adding )
{
if( adding)
SetFocus(GetDlgItem(hWnd,IDC_EDIT_VARIABLE_NAME));
}
else
{
SendDlgItemMessage(hWnd, IDC_EDIT_VARIABLE_NAME, EM_SETREADONLY, 1, 0);
SetFocus(GetDlgItem(hWnd,IDC_EDIT_VARIABLE_VALUE));
}
return false;
@@ -134,49 +131,7 @@ char * pchar;
return false;
}
void AddNewItemToVariableList(HWND list, const std::string & name, const std::string & value)
{
LVITEM item;
item.mask = LVIF_TEXT;
item.pszText = const_cast<char*>( name.c_str() );
item.iSubItem = 0;
int id = ListView_InsertItem(list, &item);
ListView_SetItemText(list,id,1,const_cast<char*>( value.c_str() ));
}
void SetNewVariableValueIntoList(HWND list, int id)
{
ttmath::ErrorCode code;
GetPrgRes()->GetThreadController()->StopCalculating();
code = GetPrgRes()->GetVariables()->Edit(name, value);
GetPrgRes()->GetThreadController()->StartCalculating();
if( code == ttmath::err_unknown_object )
{
// there is probably an internal error
// because we should have had this variable
MessageBox( list,
GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_edit_variable_unknown_variable),
GetPrgRes()->GetLanguages()->GuiMessage(Languages::message_box_caption),
MB_ICONERROR);
return;
}
ListView_SetItemText(list,id,1,const_cast<char*>( value.c_str() ));
}
void WmTabCommand_AddVariableShowError(HWND hWnd, ttmath::ErrorCode error)
void ShowError(HWND hWnd, ttmath::ErrorCode error)
{
const char * message;
@@ -190,6 +145,10 @@ const char * message;
message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_variable_incorrect_name);
break;
case ttmath::err_unknown_object:
message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_edit_variable_unknown_variable);
break;
default:
message = GetPrgRes()->GetLanguages()->GuiMessage(Languages::unknown_error);
break;
@@ -203,6 +162,79 @@ const char * message;
int AddNewItemToVariableList(HWND list, const std::string & name, const std::string & value)
{
LVITEM item;
item.mask = LVIF_TEXT;
item.pszText = const_cast<char*>( name.c_str() );
item.iSubItem = 0;
int id = ListView_InsertItem(list, &item);
ListView_SetItemText(list,id,1,const_cast<char*>( value.c_str() ));
return id;
}
void ChangeItemInVariableList(HWND list, int id, const std::string & old_name,
const std::string & new_name, const std::string & value)
{
if( old_name != new_name )
{
ListView_DeleteItem(list, id);
// as we're using ListView_DeleteItem here the WM_NOTIFY is generated
// and system will call SetDisablingEditDeleteVariableButtons
// and eventually the focus will be changed into the 'add' button
// (it's a small inconvenience)
int new_id = AddNewItemToVariableList(list, new_name, value);
ListView_SetItemState(list, new_id, LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED);
}
else
{
ListView_SetItemText(list,id,1,const_cast<char*>( value.c_str() ));
}
}
/*!
this functions returns the first item which is selected on a given list
we don't use ListView_GetSelectionMark because it sometimes returns
a wrong value especially when we have set an item as to be focused
on the list ourselves
*/
int GetSelectedItem(HWND list)
{
int id;
int len = ListView_GetItemCount(list);
for(id = 0 ; id<len ; ++id)
if( ListView_GetItemState(list, id, LVIS_SELECTED) == LVIS_SELECTED )
return id;
return -1;
}
/*!
this function removes the selection from all items
and sets the selection only on to the one given
*/
void SelectOnlyOneItem(HWND list, int id)
{
int len = ListView_GetItemCount(list);
for(int i = 0 ; i<len ; ++i)
ListView_SetItemState(list, i, 0, LVIS_FOCUSED|LVIS_SELECTED);
ListView_SetItemState(list, id, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED);
}
BOOL WmTabCommand_AddVariable(HWND, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -210,22 +242,29 @@ BOOL WmTabCommand_AddVariable(HWND, UINT message, WPARAM wParam, LPARAM lParam)
caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_variable_caption);
name = "";
value = "";
adding = true;
ttmath::ErrorCode code;
adding = true;
if( DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_VARIABLE), hWnd, DialogProcVariables) )
do
{
if( !DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_VARIABLE), hWnd, DialogProcVariables) )
break;
HWND list = GetDlgItem(hWnd, IDC_VARIABLES_LIST);
ttmath::ErrorCode code;
GetPrgRes()->GetThreadController()->StopCalculating();
code = GetPrgRes()->GetVariables()->Add(name, value);
GetPrgRes()->GetThreadController()->StartCalculating();
if( code != ttmath::err_ok )
WmTabCommand_AddVariableShowError(hWnd, code);
ShowError(hWnd, code);
else
AddNewItemToVariableList(list, name, value);
{
int id = AddNewItemToVariableList(list, name, value);
SelectOnlyOneItem(list,id);
}
}
while( code != ttmath::err_ok );
return true;
}
@@ -240,32 +279,52 @@ BOOL WmTabCommand_EditVariable(HWND, UINT message, WPARAM wParam, LPARAM)
{
HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_variables);
HWND list = GetDlgItem(hWnd, IDC_VARIABLES_LIST);
adding = false;
if( ListView_GetSelectedCount(list) != 1 )
// there must be only one item selected
return true;
int id = ListView_GetSelectionMark(list);
int id = GetSelectedItem(list);
if( id == -1 )
return true;
const int buffer_size = 300;
char * buffer = new char[buffer_size];
std::string old_name;
ttmath::ErrorCode code;
caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_edit_variable_caption);
ListView_GetItemText(list,id,0,buffer, buffer_size);
name = buffer;
old_name = name = buffer;
ListView_GetItemText(list,id,1,buffer, buffer_size);
value = buffer;
delete [] buffer;
adding = false;
if( DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_VARIABLE), hWnd, DialogProcVariables) )
do
{
SetNewVariableValueIntoList(list, id);
if( !DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_VARIABLE), hWnd, DialogProcVariables) )
break;
GetPrgRes()->GetThreadController()->StopCalculating();
// firstly we're trying to change the name
code = GetPrgRes()->GetVariables()->EditName(old_name, name);
if( code == ttmath::err_ok )
// if we've changed the name then we're changing the value
code = GetPrgRes()->GetVariables()->EditValue(name, value);
// the code should be err_ok here
GetPrgRes()->GetThreadController()->StartCalculating();
if( code != ttmath::err_ok )
ShowError(list, code);
else
ChangeItemInVariableList(list, id, old_name, name, value);
}
while( code != ttmath::err_ok );
return true;
}
@@ -303,7 +362,7 @@ int items = ListView_GetSelectedCount(list);
if( ListView_GetItemState(list, id, LVIS_SELECTED) == LVIS_SELECTED )
{
ListView_GetItemText(list,id,0,buffer,buffer_size);
if( GetPrgRes()->GetVariables()->Delete(buffer) == ttmath::err_unknown_object )
if( GetPrgRes()->GetVariables()->Delete(buffer) != ttmath::err_ok )
all_deleted = false;
else
ListView_DeleteItem(list, id);

View File

@@ -45,10 +45,6 @@
#include <string>
#include <ttmath/ttmath.h>
/*!
here our application starts
@@ -121,7 +117,7 @@ MSG msg;
// if our function returns false then we use a standard navigation
// from the system
if( msg.message == WM_KEYDOWN &&
( msg.wParam == VK_TAB ||
( msg.wParam == VK_TAB ||
msg.wParam == VK_DOWN || msg.wParam == VK_UP ||
msg.wParam == VK_LEFT || msg.wParam == VK_DOWN ) )