From 51c8432170e47c4b0d1ed2b249012ba1a1667dd0 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 8 Mar 2007 19:15:55 +0000 Subject: [PATCH] fixed: navigation from the keyboard changed: the esc key selects the entire input text now (in the input edit) added: a test when the program is being starded which checks if the coordinates of the main window actually pointing at the valid area (for example when someone took his configuration file into a new computer and the new computer has a smaller screen) added: a button 'close' on the about dialog changed: dialogs 'add a variable' and 'add a funtion' git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@21 e52654a7-88a9-db11-a3e9-0013d4bc506e --- CHANGELOG | 9 ++ TODO | 5 -- src/Makefile | 25 +++--- src/compileconfig.h | 2 +- src/functions.cpp | 19 +++-- src/languages.cpp | 6 +- src/languages.h | 1 + src/mainwindow.cpp | 178 +++++++++++++++++++++++++++++---------- src/messages.h | 12 ++- src/programresources.cpp | 32 +++++++ src/programresources.h | 1 + src/resource.rc | 49 ++++++----- src/tabs.cpp | 138 +++++++++++++++++++++--------- src/tabs.h | 1 + src/variables.cpp | 19 +++-- src/winmain.cpp | 14 ++- src/winmain.h | 2 +- 17 files changed, 364 insertions(+), 149 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c9755fd..9e3af09 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,12 @@ +Version 0.7.3 (2007.03.08): + * added: the program shows some kind of errors itself + * added: checking whether an user has inserted a correct value of a variable or a function + * fixed: navigation from the keyboard + * changed: the esc key selects the entire input text now (in the input edit) + * added: a test when the program is being starded which checks if the coordinates of the + main window actually pointing at the valid area (for example when someone took + his configuration file into a new computer and the new computer has a smaller screen) + Version 0.7.2 (2007.02.28): * added buttons Sgn and Mod * the button 'err' is active when there's actually an error now diff --git a/TODO b/TODO index 8b81704..e629aa7 100644 --- a/TODO +++ b/TODO @@ -1,12 +1,7 @@ TODO TTCalc =========== -* To add the test when program is being starded which checks if the coordinates of the - main window actually pointing - at the valid area (for example when someone take his configuration file into a - new computer) * To add some physical constants * To make the help -* To add navigation from the keyboard (in the two lists - funtions and variables) diff --git a/src/Makefile b/src/Makefile index f930729..2cd7e70 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,8 +1,6 @@ CC = g++ o = resource.o calculation.o functions.o iniparser.o languages.o mainwindow.o parsermanager.o programresources.o tabs.o variables.o winmain.o -CFLAGS = -Wall -pedantic -s -O3 -mwindows -mthreads -I../../../ttmath - - +CFLAGS = -Wall -pedantic -s -O2 -mwindows -mthreads -I../../../ttmath name = ttcalc.exe dir_output = ../../output @@ -24,20 +22,19 @@ ttcalc: $(o) resource.o: resource.rc windres resource.rc resource.o -calculation.o: calculation.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -functions.o: functions.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -iniparser.o: iniparser.cpp compileconfig.h iniparser.h -languages.o: languages.cpp compileconfig.h languages.h -mainwindow.o: mainwindow.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h resource.h messages.h tabs.h -parsermanager.o: parsermanager.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -programresources.o: programresources.cpp compileconfig.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -tabs.o: tabs.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -variables.o: variables.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h -winmain.o: winmain.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h resource.h messages.h tabs.h +calculation.o: calculation.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h tabs.h messages.h +functions.o: functions.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h +iniparser.o: iniparser.cpp compileconfig.h iniparser.h +languages.o: languages.cpp compileconfig.h languages.h +mainwindow.o: mainwindow.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h resource.h messages.h tabs.h +parsermanager.o: parsermanager.cpp compileconfig.h parsermanager.h resource.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h +programresources.o: programresources.cpp compileconfig.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h +tabs.o: tabs.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h +variables.o: variables.cpp compileconfig.h tabs.h resource.h messages.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h +winmain.o: winmain.cpp compileconfig.h winmain.h programresources.h iniparser.h languages.h threadcontroller.h stopcalculating.h resource.h messages.h tabs.h clean: rm -f *.o rm -f *.s rm -f $(dir_output)/$(name) - rm -f $(name_cons) diff --git a/src/compileconfig.h b/src/compileconfig.h index f075684..c86036e 100644 --- a/src/compileconfig.h +++ b/src/compileconfig.h @@ -52,7 +52,7 @@ */ #define TTCALC_MAJOR_VER 0 #define TTCALC_MINOR_VER 7 -#define TTCALC_REVISION_VER 2 +#define TTCALC_REVISION_VER 3 diff --git a/src/functions.cpp b/src/functions.cpp index 485ec32..3c40ca4 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -90,7 +90,7 @@ int i; } else { - EnableWindow(GetDlgItem(hWnd,IDC_EDIT_FUNCTION_NAME), false); + SendDlgItemMessage(hWnd, IDC_EDIT_FUNCTION_NAME, EM_SETREADONLY, 1, 0); SetFocus(GetDlgItem(hWnd,IDC_EDIT_FUNCTION_VALUE)); } @@ -204,12 +204,13 @@ const char * message; } -BOOL WmTabCommand_AddFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +BOOL WmTabCommand_AddFunction(HWND, UINT message, WPARAM wParam, LPARAM lParam) { - caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_caption); - name = ""; - value = ""; - adding = true; + HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_functions); + caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_function_caption); + name = ""; + value = ""; + adding = true; parameters = 1; if( DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_FUNCTION), hWnd, DialogProcFunction) ) @@ -236,8 +237,9 @@ return true; (we're also using this method directly without using the main loop of messages) (we don't define the 'lParam' parameter there) */ -BOOL WmTabCommand_EditFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM) +BOOL WmTabCommand_EditFunction(HWND, UINT message, WPARAM wParam, LPARAM) { +HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_functions); HWND list = GetDlgItem(hWnd, IDC_FUNCTIONS_LIST); if( ListView_GetSelectedCount(list) != 1 ) @@ -273,8 +275,9 @@ return true; } -BOOL WmTabCommand_DeleteFunction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +BOOL WmTabCommand_DeleteFunction(HWND, UINT message, WPARAM wParam, LPARAM lParam) { +HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_functions); HWND list = GetDlgItem(hWnd, IDC_FUNCTIONS_LIST); int items = ListView_GetSelectedCount(list); diff --git a/src/languages.cpp b/src/languages.cpp index 1f4d13f..45e73b1 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -283,9 +283,10 @@ void Languages::InitGuiMessagesTab() "\r\n" "If you have any questions, advices or interesting ideas about" " this program or if you want to join to this project as" - " the developer or programmer just contact with me." + " a developer or programmer feel free to contant with the author." ); InsertGuiPair(about_box_title, "About"); + InsertGuiPair(about_box_button_close, "Close"); InsertGuiPair(unknown_error, "An unknown error has occurred"); @@ -389,9 +390,10 @@ void Languages::InitGuiMessagesTab() "\r\n" "Jeżeli masz jakieś pytania, rady, ciekawe pomysły dotyczące" " tego programu lub chciałbyś dołączyć jako projektant/programista" - " poprostu skontaktuj się ze mną." + " poprostu skontaktuj się z autorem." ); InsertGuiPair(about_box_title, "O programie"); + InsertGuiPair(about_box_button_close, "Zamknij"); InsertGuiPair(unknown_error, "Nieznany kod błędu"); diff --git a/src/languages.h b/src/languages.h index 13eb70d..ea8d461 100644 --- a/src/languages.h +++ b/src/languages.h @@ -122,6 +122,7 @@ public: cant_init_common_controls, about_text, about_box_title, + about_box_button_close, display_digit, display_group_scientific, unknown_error diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 40dc5a9..940d033 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,6 +45,116 @@ namespace MainWindowFunctions { + +/*! + 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); + } +} + + +/*! + this method checks whether 'button' is a push button and if so + sets it as the default push button (with black border) +*/ +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); +} + + +/*! + 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 next = 0; + bool shift = (GetKeyState(VK_SHIFT) & 0xffff0000) != 0; + bool direction_next = true; + + // 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 we are on the output edit and the direction is 'forward' + // then the next control will be the 'tab' + next = tab; + } + else + if( focus == tab ) + { + // if the tab control has the focus and an user has pressed 'left' or 'right' + // we allow the system to manipulate the focus + if( wParam==VK_LEFT || wParam==VK_RIGHT ) + return 0; + + 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); + ClearPushButtons(tab_dialog); + } + else + { + // if the direction is 'back' we're setting the focus onto the output edit + next = output_edit; + } + } + 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; + } + } + + +return next; +} + + /*! this function sets the focus on a specific control (the standard procedure from the operating system doesn't work well because @@ -53,45 +163,25 @@ namespace MainWindowFunctions remember to set WS_EX_CONTROLPARENT to the tab control and to all dialog boxes on the tab */ -void SetNextFocus() +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); - bool shift = (GetKeyState(VK_SHIFT) & 0xffff0000) != 0; - - if( focus==output_edit && !shift ) - { - next = tab; - } - else - if( focus == tab ) - { - if( shift ) - { - next = output_edit; - } - else - { - int tab_sel = TabCtrl_GetCurSel(tab); - HWND tab_dialog = GetPrgRes()->GetTabWindow(tab_sel); - next = GetNextDlgTabItem(tab_dialog, 0, false); - } - } - else - { - next = GetNextDlgTabItem(main_window, focus, shift); - - if( shift && focus!=tab && next==output_edit ) - next = tab; - } + next = GetNextControl(focus, output_edit, tab, wParam); if( next ) + { SetFocus(next); + CheckAndSetDefPushButton(next); + + return true; + } + +return false; } @@ -646,12 +736,14 @@ return true; /*! - a user has pressed 'ESC' key in the main window - we're cleaning the input edit + an user has pressed 'ESC' key in the main window + we're setting the entire input edit as being selected */ BOOL WmCommand_IDCANCEL(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - SetDlgItemText(hWnd, IDC_INPUT_EDIT, ""); + HWND iedit = GetDlgItem(hWnd, IDC_INPUT_EDIT); + SendMessage(iedit, EM_SETSEL, 0, -1); + SetFocus(iedit); return true; } @@ -722,26 +814,21 @@ return true; } + + void CreateCommandMessagesTable(Messages & cmessages) { - - cmessages.Associate(IDM_ALWAYS_ON_TOP, WmCommand_AlwaysOnTop); cmessages.Associate(IDM_NORMAL_VIEW, WmCommand_NormalView); cmessages.Associate(IDM_COMPACT_VIEW, WmCommand_CompactView); cmessages.Associate(IDM_HELP_ABOUT, WmCommand_HelpAbout); cmessages.Associate(IDM_NEW_WINDOW, WmCommand_NewWindow); cmessages.Associate(IDM_CLOSE_PROGRAM, WmCommand_CloseProgram); - cmessages.Associate(IDC_INPUT_EDIT, WmCommand_InputEditNotify); - cmessages.Associate(IDM_EDIT_UNDO, WmCommand_EditUndo); cmessages.Associate(IDM_EDIT_PASTE, WmCommand_EditPaste); cmessages.Associate(IDM_EDIT_COPY_RESULT, WmCommand_EditCopyResult); - - cmessages.Associate(IDCANCEL, WmCommand_IDCANCEL); - cmessages.Associate(IDM_LANGUAGE_ENGLISH, WmCommand_LanguageEnglish); cmessages.Associate(IDM_LANGUAGE_POLISH, WmCommand_LanguagePolish); } @@ -755,8 +842,10 @@ static Messages command_messages; // initiation CreateCommandMessagesTable(command_messages); - -return command_messages.Call(LOWORD(wParam), hWnd, message, wParam, lParam); + if( command_messages.IsMessage(LOWORD(wParam)) ) + return command_messages.Call(LOWORD(wParam), hWnd, message, wParam, lParam); + else + return TabWindowFunctions::WmTabCommand(hWnd, message, wParam, lParam); } @@ -846,13 +935,14 @@ char compiler[30]; BOOL CALLBACK AboutProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { char * about_buffer; +Languages * lang; switch(message) { case WM_INITDIALOG: - SetWindowText( - hWnd, - GetPrgRes()->GetLanguages()->GuiMessage(Languages::about_box_title) ); + lang = GetPrgRes()->GetLanguages(); + SetWindowText(hWnd, lang->GuiMessage(Languages::about_box_title) ); + SetWindowText(GetDlgItem(hWnd, IDOK), lang->GuiMessage(Languages::about_box_button_close) ); about_buffer = new char[2000]; CreateAboutText(about_buffer); diff --git a/src/messages.h b/src/messages.h index 06f88f0..bce5799 100644 --- a/src/messages.h +++ b/src/messages.h @@ -61,7 +61,7 @@ public: } - BOOL Call(UINT key, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + bool Call(UINT key, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { MessageTable::iterator i = message_table.find(key); @@ -71,6 +71,16 @@ public: return i->second(hWnd, message, wParam, lParam); } + bool IsMessage(UINT key) + { + MessageTable::iterator i = message_table.find(key); + + if( i == message_table.end() ) + return false; + + return true; + } + bool Empty() const { diff --git a/src/programresources.cpp b/src/programresources.cpp index cd100df..48d6627 100644 --- a/src/programresources.cpp +++ b/src/programresources.cpp @@ -545,6 +545,36 @@ std::string application_data; } +void ProgramResources::CheckCoordinates() +{ + if( x_pos < -50 ) + x_pos = 0; + + if( y_pos < -50 ) + y_pos = 0; + + if( x_size < 100 ) + x_size = 100; + + if( y_size < 30 ) + y_size = 30; + + int cx = GetSystemMetrics(SM_CXSCREEN); + int cy = GetSystemMetrics(SM_CYSCREEN); + + if( x_size > cx+10 ) + x_size = cx; + + if( y_size > cy+10 ) + y_size = cy; + + if( x_pos > cx-50 ) + x_pos = cx - x_size; + + if( y_pos > cy-50 ) + y_pos = cy - y_size; +} + IniParser::Error ProgramResources::ReadFromFile() { @@ -598,10 +628,12 @@ std::string ini_value[20]; always_on_top = bool( atoi(ini_value[0].c_str()) ); view = atoi(ini_value[1].c_str()) == 0 ? view_normal : view_compact; maximized = bool( atoi(ini_value[2].c_str()) ); + x_pos = atoi( ini_value[3].c_str() ); y_pos = atoi( ini_value[4].c_str() ); x_size = atoi( ini_value[5].c_str() ); y_size = atoi( ini_value[12].c_str() ); + CheckCoordinates(); SetPrecision( atoi(ini_value[6].c_str()) ); SetBaseInput( atoi(ini_value[7].c_str()) ); diff --git a/src/programresources.h b/src/programresources.h index ab22e98..6112377 100644 --- a/src/programresources.h +++ b/src/programresources.h @@ -279,6 +279,7 @@ private: const char * SkipWhiteCharacters(const char * string); bool IsDecDigit(int c); bool SplitFunction(const std::string & input, const char * * name, int * param); + void CheckCoordinates(); ttmath::Objects variables; ttmath::Objects functions; diff --git a/src/resource.rc b/src/resource.rc index 1696733..03a032d 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -50,29 +50,31 @@ BEGIN CONTROL "",1010,"SysTabControl32",WS_CHILD |WS_TABSTOP | WS_VISIBLE ,0,39,261,110, WS_EX_CONTROLPARENT END -102 DIALOG 0, 0, 265, 61 -STYLE DS_FIXEDSYS |DS_SETFONT |DS_CENTER |WS_POPUP |WS_VISIBLE |WS_THICKFRAME |WS_CAPTION + +102 DIALOG DISCARDABLE 0, 0, 358, 61 +STYLE DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | + WS_CAPTION | WS_SYSMENU CAPTION "Add a new variable" FONT 8, "Ms Shell Dlg" BEGIN - CONTROL "Ok",1,"BUTTON",BS_DEFPUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,205,10,50,14 - CONTROL "Cancel",2,"BUTTON",BS_PUSHBUTTON |BS_VCENTER |BS_CENTER |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,205,28,50,14 - CONTROL "",1134,"EDIT",ES_AUTOHSCROLL |ES_LEFT |WS_CHILD |WS_BORDER |WS_TABSTOP |WS_VISIBLE ,38,10,67,14 - CONTROL "",1135,"EDIT",ES_AUTOHSCROLL |ES_LEFT |WS_CHILD |WS_BORDER |WS_TABSTOP |WS_VISIBLE ,38,28,147,14 - CONTROL "name:",1136,"STATIC",SS_LEFT |WS_CHILD |WS_GROUP |WS_VISIBLE ,7,12,27,8 - CONTROL "value:",1137,"STATIC",SS_LEFT |WS_CHILD |WS_GROUP |WS_VISIBLE ,7,30,27,8 + DEFPUSHBUTTON "Ok",1,291,10,50,14,BS_CENTER | BS_VCENTER + PUSHBUTTON "Cancel",2,291,28,50,14,BS_CENTER | BS_VCENTER + EDITTEXT 1134,38,10,67,14,ES_AUTOHSCROLL + EDITTEXT 1135,38,28,230,14,ES_AUTOHSCROLL + LTEXT "name:",1136,7,12,27,8 + LTEXT "value:",1137,7,30,27,8 END -103 DIALOG DISCARDABLE 0, 0, 273, 73 -STYLE DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME -CAPTION "Add a new function" +103 DIALOG DISCARDABLE 0, 0, 370, 74 +STYLE DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | + WS_CAPTION | WS_SYSMENU FONT 8, "Ms Shell Dlg" BEGIN - DEFPUSHBUTTON "Ok",1,205,10,50,14,BS_CENTER | BS_VCENTER - PUSHBUTTON "Cancel",2,205,27,50,14,BS_CENTER | BS_VCENTER + DEFPUSHBUTTON "Ok",1,303,10,50,14,BS_CENTER | BS_VCENTER + PUSHBUTTON "Cancel",2,303,27,50,14,BS_CENTER | BS_VCENTER EDITTEXT 1144,46,10,67,14,ES_AUTOHSCROLL COMBOBOX 1146,46,29,67,130,CBS_DROPDOWNLIST | WS_TABSTOP - EDITTEXT 1145,46,47,210,14,ES_AUTOHSCROLL + EDITTEXT 1145,46,47,308,14,ES_AUTOHSCROLL LTEXT "name:",1147,7,12,31,8 LTEXT "value:",1149,7,49,33,8 LTEXT "param:",1148,7,30,33,8 @@ -155,7 +157,7 @@ EXSTYLE WS_EX_CONTROLPARENT CAPTION "tab4" FONT 8, "Ms Shell Dlg" BEGIN - CONTROL "precision 1",1150,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD |WS_TABSTOP |WS_VISIBLE ,15,4,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_VISIBLE ,15,33,252,10 CONTROL "precision 3",1152,"BUTTON",BS_AUTORADIOBUTTON |BS_LEFT |WS_CHILD | WS_VISIBLE ,15,62,252,10 CONTROL "info 1",1153,"STATIC",SS_LEFT |WS_CHILD |WS_VISIBLE ,28,17,245,8 @@ -169,29 +171,30 @@ EXSTYLE WS_EX_CONTROLPARENT CAPTION "tab5" FONT 8, "Ms Shell Dlg" BEGIN - COMBOBOX 1156,58,5,63,200,CBS_DROPDOWNLIST | WS_TABSTOP + 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_TABSTOP,19,65,44,10 + 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_TABSTOP | ES_NUMBER + EDITTEXT 1166,194,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 0, 0, 349, 202 -STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +200 DIALOG DISCARDABLE 0, 0, 349, 202 +STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | + WS_SYSMENU CAPTION "About" FONT 8, "MS Sans Serif" BEGIN - CONTROL 1201,0,"Static",SS_BITMAP,3,3,101,197 - EDITTEXT 1200,112,3,231,197,ES_MULTILINE | ES_READONLY | NOT + CONTROL 1201,0,"Static",SS_BITMAP,3,3,101,197 + EDITTEXT 1200,112,3,231,158,ES_MULTILINE | ES_READONLY | NOT WS_BORDER | NOT WS_TABSTOP + DEFPUSHBUTTON "Close",IDOK,175,172,86,14 END 1201 BITMAP "..\\res\\abacus_01.bmp" diff --git a/src/tabs.cpp b/src/tabs.cpp index 4d7a4cc..955bfbe 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -315,16 +315,21 @@ return true; BOOL WmTabCommand_Ok(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { -int tab = TabCtrl_GetCurSel(GetParent(hWnd)); +HWND main = GetPrgRes()->GetMainWindow(); +HWND tab = GetDlgItem(main, IDC_TAB); +int sel = TabCtrl_GetCurSel(tab); - if( tab == tab_variables ) + + if( sel == tab_variables ) { - Variables::WmTabCommand_EditVariable(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_VARIABLE, 0); + if( GetFocus() == GetDlgItem(GetPrgRes()->GetTabWindow(tab_variables), IDC_VARIABLES_LIST ) ) + Variables::WmTabCommand_EditVariable(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_VARIABLE, 0); } else - if( tab == tab_functions ) + if( sel == tab_functions ) { - Functions::WmTabCommand_EditFunction(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_FUNCTION, 0); + if( GetFocus() == GetDlgItem(GetPrgRes()->GetTabWindow(tab_functions), IDC_FUNCTIONS_LIST ) ) + Functions::WmTabCommand_EditFunction(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_FUNCTION, 0); } return true; @@ -726,26 +731,66 @@ BOOL WmTabInitDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } +/*! + this function enables or disables the 'edit' and 'delete' buttons + on the variables' or functions' tab depending on how many variables + are selected in the list +*/ +void SetDisablingEditDeleteVariableOrFunctionButtons(int count, HWND add, + HWND edit, HWND del, HWND focus) +{ + if( count == 1 ) + // if there is one selected item we're enabling the edit button + EnableWindow(edit, true); + else + { + // if there is not one selected item (or none) we're disabling the edit + EnableWindow(edit, false); + + // if the focus is on the edit button we must change it + // for example into the add button + // (we must change the BS_DEFPUSHBUTTON style as well) + if( focus == edit ) + { + SetFocus(add); + SendMessage(add, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, true); + SendMessage(edit, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, true); + } + } + + + if( count != 0 ) + // if there is one or more items selected we're enabling the del button + EnableWindow(del, true); + else + { + // if there are not selected items we're disabling the del + EnableWindow(del, false); + + if( focus == del ) + { + SetFocus(add); + SendMessage(add, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, true); + SendMessage(del, BM_SETSTYLE, (WPARAM)BS_PUSHBUTTON, true); + } + } +} + + /*! this function enables or disables the 'edit' and 'delete' buttons on the variable's tab depending on how many variables are selected in the list */ void SetDisablingEditDeleteVariableButtons(HWND hWnd) { -HWND list = GetDlgItem(hWnd,IDC_VARIABLES_LIST); +HWND focus = GetFocus(); +HWND list = GetDlgItem(hWnd, IDC_VARIABLES_LIST); +HWND add = GetDlgItem(hWnd, IDC_BUTTON_ADD_VARIABLE); +HWND edit = GetDlgItem(hWnd, IDC_BUTTON_EDIT_VARIABLE); +HWND del = GetDlgItem(hWnd, IDC_BUTTON_DELETE_VARIABLE); +int count = ListView_GetSelectedCount(list); -int count = ListView_GetSelectedCount(list); - - if( count == 1 ) - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_EDIT_VARIABLE), true); - else - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_EDIT_VARIABLE), false); - - - if( count != 0 ) - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_DELETE_VARIABLE), true); - else - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_DELETE_VARIABLE), false); + SetDisablingEditDeleteVariableOrFunctionButtons(count, add, edit, del, focus); } @@ -755,44 +800,44 @@ int count = ListView_GetSelectedCount(list); */ void SetDisablingEditDeleteFunctionButtons(HWND hWnd) { -HWND list = GetDlgItem(hWnd,IDC_FUNCTIONS_LIST); +HWND focus = GetFocus(); +HWND list = GetDlgItem(hWnd, IDC_FUNCTIONS_LIST); +HWND add = GetDlgItem(hWnd, IDC_BUTTON_ADD_FUNCTION); +HWND edit = GetDlgItem(hWnd, IDC_BUTTON_EDIT_FUNCTION); +HWND del = GetDlgItem(hWnd, IDC_BUTTON_DELETE_FUNCTION); +int count = ListView_GetSelectedCount(list); -int count = ListView_GetSelectedCount(list); - - if( count == 1 ) - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_EDIT_FUNCTION), true); - else - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_EDIT_FUNCTION), false); - - - if( count != 0 ) - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_DELETE_FUNCTION), true); - else - EnableWindow(GetDlgItem(hWnd, IDC_BUTTON_DELETE_FUNCTION), false); + SetDisablingEditDeleteVariableOrFunctionButtons(count, add, edit, del, focus); } -void FillUpVariableList(HWND list) +int FillUpVariableList(HWND list) { // we don't have to block the second thread here // because it can only read from variables' table // (we can read and the second thread can read in the same time as well) ttmath::Objects::CIterator iv = GetPrgRes()->GetVariables()->Begin(); - for( ; iv != GetPrgRes()->GetVariables()->End() ; ++iv ) + int size; + for( size=0 ; iv != GetPrgRes()->GetVariables()->End() ; ++iv, ++size ) Variables::AddNewItemToVariableList(list, iv->first, iv->second.value); + +return size; } -void FillUpFunctionList(HWND list) +int FillUpFunctionList(HWND list) { // we don't have to block the second thread here // because it can only read from functions' table // (we can read and the second thread can read in the same time as well) ttmath::Objects::CIterator iv = GetPrgRes()->GetFunctions()->Begin(); - for( ; iv != GetPrgRes()->GetFunctions()->End() ; ++iv ) + int size; + for( size=0 ; iv != GetPrgRes()->GetFunctions()->End() ; ++iv, ++size ) Functions::AddNewItemToFunctionList(list, iv->first, iv->second.value, iv->second.param); + +return size; } @@ -814,9 +859,10 @@ LVCOLUMN column; ListView_InsertColumn(list, 1, &column); ListView_SetExtendedListViewStyle(list,LVS_EX_FULLROWSELECT); - SetDisablingEditDeleteVariableButtons(hWnd); - FillUpVariableList(list); + + if( FillUpVariableList(list) > 0 ) + ListView_SetItemState(list, 0, LVIS_SELECTED, LVIS_SELECTED); return true; } @@ -845,7 +891,10 @@ LVCOLUMN column; ListView_SetExtendedListViewStyle(list,LVS_EX_FULLROWSELECT); SetDisablingEditDeleteFunctionButtons(hWnd); - FillUpFunctionList(list); + + if( FillUpFunctionList(list) > 0 ) + ListView_SetItemState(list, 0, LVIS_SELECTED, LVIS_SELECTED); + return true; } @@ -957,6 +1006,16 @@ return false; } +BOOL WmTabKeyDown(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ +MessageBox(hWnd, "trol", "", 0); + +return true; + + +} + + void CreateTabMessagesTable(Messages & messages) { messages.Associate(WM_INITDIALOG, WmTabInitDialog); @@ -966,6 +1025,7 @@ void CreateTabMessagesTable(Messages & messages) messages.Associate(WM_INIT_TAB_PRECISION, WmInitTabPrecision); messages.Associate(WM_INIT_TAB_DISPLAY, WmInitTabDisplay); messages.Associate(WM_NOTIFY, WmNotify); + messages.Associate(WM_KEYDOWN, WmTabKeyDown); } @@ -1024,7 +1084,7 @@ RECT r_main, r; sum += ListView_GetColumnWidth(list, i); if( sum < list_cx - 30 ) - ListView_SetColumnWidth(list, last_column, list_cx-sum-10); + ListView_SetColumnWidth(list, last_column, list_cx-sum-25); } diff --git a/src/tabs.h b/src/tabs.h index 9e93e9c..3626cb9 100644 --- a/src/tabs.h +++ b/src/tabs.h @@ -73,6 +73,7 @@ extern ttmath::ErrorCode last_code; void SetLanguage(HWND hTab); void SetSizeOfVariablesList(); void SetSizeOfFunctionsList(); + BOOL WmTabCommand(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); namespace Variables { diff --git a/src/variables.cpp b/src/variables.cpp index 7163316..ef471c4 100644 --- a/src/variables.cpp +++ b/src/variables.cpp @@ -100,7 +100,7 @@ char * pchar; } else { - EnableWindow(GetDlgItem(hWnd,IDC_EDIT_VARIABLE_NAME), false); + SendDlgItemMessage(hWnd, IDC_EDIT_VARIABLE_NAME, EM_SETREADONLY, 1, 0); SetFocus(GetDlgItem(hWnd,IDC_EDIT_VARIABLE_VALUE)); } @@ -204,12 +204,13 @@ const char * message; -BOOL WmTabCommand_AddVariable(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +BOOL WmTabCommand_AddVariable(HWND, UINT message, WPARAM wParam, LPARAM lParam) { - caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_variable_caption); - name = ""; - value = ""; - adding = true; + HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_variables); + caption = GetPrgRes()->GetLanguages()->GuiMessage(Languages::dialog_box_add_variable_caption); + name = ""; + value = ""; + adding = true; if( DialogBox(GetPrgRes()->GetInstance(), MAKEINTRESOURCE(IDD_DIALOG_ADD_VARIABLE), hWnd, DialogProcVariables) ) { @@ -235,8 +236,9 @@ return true; (we're also using this method directly without using the main loop of messages) (we don't define the 'lParam' parameter there) */ -BOOL WmTabCommand_EditVariable(HWND hWnd, UINT message, WPARAM wParam, LPARAM) +BOOL WmTabCommand_EditVariable(HWND, UINT message, WPARAM wParam, LPARAM) { +HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_variables); HWND list = GetDlgItem(hWnd, IDC_VARIABLES_LIST); if( ListView_GetSelectedCount(list) != 1 ) @@ -269,8 +271,9 @@ return true; } -BOOL WmTabCommand_DeleteVariable(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +BOOL WmTabCommand_DeleteVariable(HWND, UINT message, WPARAM wParam, LPARAM lParam) { +HWND hWnd = GetPrgRes()->GetTabWindow(TabWindowFunctions::tab_variables); HWND list = GetDlgItem(hWnd, IDC_VARIABLES_LIST); int items = ListView_GetSelectedCount(list); diff --git a/src/winmain.cpp b/src/winmain.cpp index 17e07c9..efe57d9 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -117,12 +117,20 @@ MSG msg; { bool sended = false; - if( msg.message==WM_KEYDOWN && msg.wParam==VK_TAB ) + // we give our own special function for navigating from the keyboard + // 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_DOWN || msg.wParam == VK_UP || + msg.wParam == VK_LEFT || msg.wParam == VK_DOWN ) ) + { - MainWindowFunctions::SetNextFocus(); - sended = true; + if( MainWindowFunctions::SetNextFocus(msg.wParam) ) + sended = true; } + // firt we try to send our message to dialogs // (the dialogs on the tab control) if( !sended ) diff --git a/src/winmain.h b/src/winmain.h index 740ddfb..69fcaff 100644 --- a/src/winmain.h +++ b/src/winmain.h @@ -63,7 +63,7 @@ void MainMessagesLoop(); namespace MainWindowFunctions { - void SetNextFocus(); + bool SetNextFocus(WPARAM wParam); void CreateMainMessagesTable(Messages & messages); BOOL CALLBACK AboutProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); }