1148 lines
33 KiB
C++
1148 lines
33 KiB
C++
/*
|
|
* This file is a part of TTCalc - a mathematical calculator
|
|
* and is distributed under the (new) BSD licence.
|
|
* Author: Tomasz Sowa <t.sowa@slimaczek.pl>
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2006-2007, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
|
* project may be used to endorse or promote products derived
|
|
* from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include "compileconfig.h"
|
|
#include "tabs.h"
|
|
|
|
namespace TabWindowFunctions
|
|
{
|
|
int tab_standard;
|
|
int tab_variables;
|
|
int tab_functions;
|
|
int tab_precision;
|
|
int tab_display;
|
|
|
|
ttmath::ErrorCode last_code = ttmath::err_ok;
|
|
|
|
|
|
void PrintErrorCode()
|
|
{
|
|
SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,
|
|
GetPrgRes()->GetLanguages()->ErrorMessage(last_code) );
|
|
}
|
|
|
|
/*
|
|
this functions inserts a given string into the first edit control
|
|
and then moves the caret
|
|
*/
|
|
void InsertText(const char * text, int move = 0)
|
|
{
|
|
HWND input_edit = GetDlgItem( GetPrgRes()->GetMainWindow(), IDC_INPUT_EDIT );
|
|
|
|
SetFocus(input_edit);
|
|
|
|
SendMessage(input_edit, EM_REPLACESEL, true, (LPARAM)text);
|
|
|
|
if( move != 0 )
|
|
{
|
|
DWORD l1,l2;
|
|
|
|
SendMessage(input_edit, EM_GETSEL, (WPARAM)&l1, (LPARAM)&l2 );
|
|
SendMessage(input_edit, EM_SETSEL, l1+move, l2+move );
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
a function for WM_COMMAND and LOWORD(wParam)
|
|
from IDC_BUTTON_PRESS_0 to IDC_BUTTON_PRESS_9
|
|
*/
|
|
BOOL WmTabCommand_Press_0_9(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
SetFocus(GetDlgItem(GetPrgRes()->GetMainWindow(),IDC_INPUT_EDIT));
|
|
SendDlgItemMessage(GetPrgRes()->GetMainWindow(),IDC_INPUT_EDIT,WM_CHAR,LOWORD(wParam)-IDC_BUTTON_PRESS_0+'0',0x20001);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_e(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("e",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_comma(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText(".",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_pi(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("pi",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_sin(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("sin()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_cos(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("cos()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_tan(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("tan()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_cot(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("cot()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_ln(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("ln()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_log(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("log( ; )",-4);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_abs(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("abs()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_factorial(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("factorial()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_div(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("/", 0);
|
|
|
|
return true;
|
|
}
|
|
|
|
BOOL WmTabCommand_Press_mul(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("*",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
BOOL WmTabCommand_Press_sub(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("-",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
BOOL WmTabCommand_Press_add(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("+",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_first_bracket(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("(",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_last_bracket(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText(")",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_clear(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
SetDlgItemText(GetPrgRes()->GetMainWindow(), IDC_INPUT_EDIT, "");
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_error(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if( last_code != ttmath::err_ok )
|
|
{
|
|
PrintErrorCode();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_asin(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("asin()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
BOOL WmTabCommand_Press_acos(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("acos()",-1);
|
|
|
|
return true;
|
|
}
|
|
BOOL WmTabCommand_Press_atan(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("atan()",-1);
|
|
|
|
return true;
|
|
}
|
|
BOOL WmTabCommand_Press_acot(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("acot()",-1);
|
|
|
|
return true;
|
|
}
|
|
BOOL WmTabCommand_Press_sgn(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("sgn()",-1);
|
|
|
|
return true;
|
|
}
|
|
BOOL WmTabCommand_Press_mod(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("mod(;)",-2);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_power(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("^",0);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_int(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("int()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_round(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("round()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_Press_exp(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
InsertText("exp()",-1);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_IDOK(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
HWND main = GetPrgRes()->GetMainWindow();
|
|
HWND tab = GetDlgItem(main, IDC_TAB);
|
|
int sel = TabCtrl_GetCurSel(tab);
|
|
|
|
|
|
if( sel == tab_variables )
|
|
{
|
|
if( GetFocus() == GetDlgItem(GetPrgRes()->GetTabWindow(tab_variables), IDC_VARIABLES_LIST ) )
|
|
Variables::WmTabCommand_EditVariable(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_VARIABLE, 0);
|
|
}
|
|
else
|
|
if( sel == tab_functions )
|
|
{
|
|
if( GetFocus() == GetDlgItem(GetPrgRes()->GetTabWindow(tab_functions), IDC_FUNCTIONS_LIST ) )
|
|
Functions::WmTabCommand_EditFunction(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_FUNCTION, 0);
|
|
}
|
|
|
|
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)
|
|
{
|
|
SetDlgItemText( hWnd,IDC_BUTTON_CLEAR, GetPrgRes()->GetLanguages()->GuiMessage(Languages::button_clear) );
|
|
}
|
|
|
|
void SetLanguageTabVariables(HWND hWnd)
|
|
{
|
|
SetDlgItemText( hWnd,IDC_BUTTON_ADD_VARIABLE, GetPrgRes()->GetLanguages()->GuiMessage(Languages::button_add) );
|
|
SetDlgItemText( hWnd,IDC_BUTTON_EDIT_VARIABLE, GetPrgRes()->GetLanguages()->GuiMessage(Languages::button_edit) );
|
|
SetDlgItemText( hWnd,IDC_BUTTON_DELETE_VARIABLE, GetPrgRes()->GetLanguages()->GuiMessage(Languages::button_delete) );
|
|
|
|
HWND list = GetDlgItem(hWnd, IDC_VARIABLES_LIST);
|
|
LVCOLUMN column;
|
|
|
|
column.mask = LVCF_TEXT;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_variables_header_1) );
|
|
ListView_SetColumn(list,0,&column);
|
|
|
|
column.mask = LVCF_TEXT;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_variables_header_2) );
|
|
ListView_SetColumn(list,1,&column);
|
|
}
|
|
|
|
|
|
void SetLanguageTabFunctions(HWND hWnd)
|
|
{
|
|
SetDlgItemText( hWnd,IDC_BUTTON_ADD_FUNCTION, GetPrgRes()->GetLanguages()->GuiMessage(Languages::button_add) );
|
|
SetDlgItemText( hWnd,IDC_BUTTON_EDIT_FUNCTION, GetPrgRes()->GetLanguages()->GuiMessage(Languages::button_edit) );
|
|
SetDlgItemText( hWnd,IDC_BUTTON_DELETE_FUNCTION, GetPrgRes()->GetLanguages()->GuiMessage(Languages::button_delete) );
|
|
|
|
HWND list = GetDlgItem(hWnd, IDC_FUNCTIONS_LIST);
|
|
LVCOLUMN column;
|
|
|
|
column.mask = LVCF_TEXT;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_functions_header_1) );
|
|
ListView_SetColumn(list,0,&column);
|
|
|
|
column.mask = LVCF_TEXT;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_functions_header_2) );
|
|
ListView_SetColumn(list,1,&column);
|
|
|
|
column.mask = LVCF_TEXT;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_functions_header_3) );
|
|
ListView_SetColumn(list,2,&column);
|
|
}
|
|
|
|
|
|
void SetLanguageTabPrecision(HWND hWnd)
|
|
{
|
|
SetDlgItemText(hWnd, IDC_RADIO_PRECISION_1, GetPrgRes()->GetLanguages()->GuiMessage(Languages::radio_precision_1) );
|
|
SetDlgItemText(hWnd, IDC_RADIO_PRECISION_2, GetPrgRes()->GetLanguages()->GuiMessage(Languages::radio_precision_2) );
|
|
SetDlgItemText(hWnd, IDC_RADIO_PRECISION_3, GetPrgRes()->GetLanguages()->GuiMessage(Languages::radio_precision_3) );
|
|
|
|
SetDlgItemText(hWnd, IDC_LABEL_PRECISION_1_INFO, GetPrgRes()->GetLanguages()->GuiMessage(Languages::precision_1_info) );
|
|
SetDlgItemText(hWnd, IDC_LABEL_PRECISION_2_INFO, GetPrgRes()->GetLanguages()->GuiMessage(Languages::precision_2_info) );
|
|
SetDlgItemText(hWnd, IDC_LABEL_PRECISION_3_INFO, GetPrgRes()->GetLanguages()->GuiMessage(Languages::precision_3_info) );
|
|
}
|
|
|
|
|
|
void SetLanguageTabDisplay(HWND hWnd)
|
|
{
|
|
char buffer[50];
|
|
int i;
|
|
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_RESETCONTENT, 0, 0);
|
|
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_cut_last_digits) );
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_none) );
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_integer) );
|
|
|
|
const int max_r = 9;
|
|
for(i=1 ; i<=max_r ; ++i)
|
|
{
|
|
sprintf(buffer,"%s %d %s",
|
|
GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_to_number),
|
|
i,
|
|
GetPrgRes()->GetLanguages()->GuiMessage(Languages::combo_rounding_after_comma) );
|
|
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
}
|
|
|
|
int r = GetPrgRes()->GetDisplayRounding();
|
|
if( r > max_r )
|
|
r = max_r;
|
|
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_SETCURSEL, r+2, 0);
|
|
|
|
|
|
SetDlgItemText(hWnd, IDC_LABEL_DISPLAY_INPUT, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_input));
|
|
SetDlgItemText(hWnd, IDC_LABEL_DISPLAY_OUTPUT, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_output));
|
|
SetDlgItemText(hWnd, IDC_LABEL_DISPLAY_ROUNDING, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_rounding));
|
|
|
|
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_GROUP_SCIENTIFIC, GetPrgRes()->GetLanguages()->GuiMessage(Languages::display_group_scientific));
|
|
}
|
|
|
|
|
|
void SetLanguage(HWND hTab)
|
|
{
|
|
TCITEM tab;
|
|
|
|
tab.mask = TCIF_TEXT;
|
|
|
|
tab.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::tab_standard) );
|
|
TabCtrl_SetItem(hTab,tab_standard, &tab);
|
|
|
|
tab.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::tab_variables) );
|
|
TabCtrl_SetItem(hTab,tab_variables, &tab);
|
|
|
|
tab.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::tab_functions) );
|
|
TabCtrl_SetItem(hTab,tab_functions, &tab);
|
|
|
|
tab.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::tab_precision) );
|
|
TabCtrl_SetItem(hTab,tab_precision, &tab);
|
|
|
|
tab.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::tab_display) );
|
|
TabCtrl_SetItem(hTab,tab_display, &tab);
|
|
|
|
SetLanguageTabStandard( GetPrgRes()->GetTabWindow(tab_standard) );
|
|
SetLanguageTabVariables( GetPrgRes()->GetTabWindow(tab_variables) );
|
|
SetLanguageTabFunctions( GetPrgRes()->GetTabWindow(tab_functions) );
|
|
SetLanguageTabPrecision( GetPrgRes()->GetTabWindow(tab_precision) );
|
|
SetLanguageTabDisplay( GetPrgRes()->GetTabWindow(tab_display) );
|
|
|
|
InvalidateRect(hTab, 0, false);
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_SetPrecision1(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
// there are another messages besides that one
|
|
// which is sent when a user clicks on the radio button
|
|
if( IsDlgButtonChecked(hWnd, IDC_RADIO_PRECISION_1) != BST_CHECKED )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetPrecision(0);
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_SetPrecision2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
// there are another messages besides that one
|
|
// which is sent when a user clicks on the radio button
|
|
if( IsDlgButtonChecked(hWnd, IDC_RADIO_PRECISION_2) != BST_CHECKED )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetPrecision(1);
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_SetPrecision3(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
// there are another messages besides that one
|
|
// which is sent when a user clicks on the radio button
|
|
if( IsDlgButtonChecked(hWnd, IDC_RADIO_PRECISION_3) != BST_CHECKED )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetPrecision(2);
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_DisplayInputChanged(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if( HIWORD(wParam) != CBN_SELCHANGE )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetBaseInput( (int)SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_INPUT, CB_GETCURSEL, 0, 0) + 2 );
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_DisplayOutputChanged(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if( HIWORD(wParam) != CBN_SELCHANGE )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetBaseOutput( (int)SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_OUTPUT, CB_GETCURSEL, 0, 0) + 2);
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_DisplayRoundingChanged(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if( HIWORD(wParam) != CBN_SELCHANGE )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetDisplayRounding( (int)SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_ROUNDING, CB_GETCURSEL, 0, 0) - 2);
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void SetDisablingDisplayWhenScientific(HWND hWnd)
|
|
{
|
|
if( IsDlgButtonChecked(hWnd, IDC_RADIO_DISPLAY_ALWAYS_SCIENTIFIC) == BST_CHECKED )
|
|
{
|
|
EnableWindow(GetDlgItem(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC), false);
|
|
EnableWindow(GetDlgItem(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC), false);
|
|
}
|
|
else
|
|
{
|
|
EnableWindow(GetDlgItem(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC), true);
|
|
EnableWindow(GetDlgItem(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC), true);
|
|
}
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_SetDisplayAlwaysScientific(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
// there are another messages besides that one
|
|
// which is sent when a user clicks on the radio button
|
|
if( IsDlgButtonChecked(hWnd, IDC_RADIO_DISPLAY_ALWAYS_SCIENTIFIC) != BST_CHECKED )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetDisplayAlwaysScientific(true);
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
SetDisablingDisplayWhenScientific(hWnd);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmTabCommand_SetDisplayNotAlwaysScientific(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
// there are another messages besides that one
|
|
// which is sent when a user clicks on the radio button
|
|
if( IsDlgButtonChecked(hWnd, IDC_RADIO_DISPLAY_NOT_ALWAYS_SCIENTIFIC) != BST_CHECKED )
|
|
return false;
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetDisplayAlwaysScientific(false);
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
SetDisablingDisplayWhenScientific(hWnd);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
BOOL WmTabCommand_SetDisplayWhenScientific(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
static bool correct_insertion = false;
|
|
|
|
if( HIWORD(wParam)==EN_CHANGE && !correct_insertion )
|
|
{
|
|
char buffer[20];
|
|
|
|
GetDlgItemText(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC, buffer, sizeof(buffer)/sizeof(char));
|
|
int w2,w1 = atoi(buffer);
|
|
|
|
GetPrgRes()->GetThreadController()->StopCalculating();
|
|
GetPrgRes()->SetDisplayWhenScientific(w1);
|
|
w2 = GetPrgRes()->GetDisplayWhenScientific();
|
|
GetPrgRes()->GetThreadController()->StartCalculating();
|
|
|
|
if( w1 != w2 )
|
|
{
|
|
sprintf(buffer,"%d", w2);
|
|
|
|
//
|
|
correct_insertion = true;
|
|
SetDlgItemText(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC, buffer);
|
|
correct_insertion = false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void CreateTabCommandMessagesTable(Messages & cmessages)
|
|
{
|
|
cmessages.Associate(IDC_BUTTON_PRESS_0, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_1, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_2, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_3, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_4, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_5, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_6, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_7, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_8, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_PRESS_9, WmTabCommand_Press_0_9);
|
|
cmessages.Associate(IDC_BUTTON_COMMA, WmTabCommand_Press_comma);
|
|
|
|
cmessages.Associate(IDC_BUTTON_E, WmTabCommand_Press_e);
|
|
cmessages.Associate(IDC_BUTTON_PI, WmTabCommand_Press_pi);
|
|
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_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);
|
|
cmessages.Associate(IDC_BUTTON_FACTORIAL, WmTabCommand_Press_factorial);
|
|
|
|
|
|
|
|
cmessages.Associate(IDC_BUTTON_DIV, WmTabCommand_Press_div);
|
|
cmessages.Associate(IDC_BUTTON_MUL, WmTabCommand_Press_mul);
|
|
cmessages.Associate(IDC_BUTTON_SUB, WmTabCommand_Press_sub);
|
|
cmessages.Associate(IDC_BUTTON_ADD, WmTabCommand_Press_add);
|
|
cmessages.Associate(IDC_BUTTON_FIRST_BRACKET, WmTabCommand_Press_first_bracket);
|
|
cmessages.Associate(IDC_BUTTON_LAST_BRACKET, WmTabCommand_Press_last_bracket);
|
|
|
|
cmessages.Associate(IDC_BUTTON_CLEAR, WmTabCommand_Press_clear);
|
|
cmessages.Associate(IDC_BUTTON_ERROR, WmTabCommand_Press_error);
|
|
|
|
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_ACOT, WmTabCommand_Press_acot);
|
|
cmessages.Associate(IDC_BUTTON_SGN, WmTabCommand_Press_sgn);
|
|
cmessages.Associate(IDC_BUTTON_MOD, WmTabCommand_Press_mod);
|
|
|
|
|
|
cmessages.Associate(IDC_BUTTON_POWER, WmTabCommand_Press_power);
|
|
cmessages.Associate(IDC_BUTTON_INT, WmTabCommand_Press_int);
|
|
cmessages.Associate(IDC_BUTTON_ROUND, WmTabCommand_Press_round);
|
|
cmessages.Associate(IDC_BUTTON_EXP, WmTabCommand_Press_exp);
|
|
|
|
cmessages.Associate(IDC_BUTTON_ADD_VARIABLE, Variables::WmTabCommand_AddVariable);
|
|
cmessages.Associate(IDC_BUTTON_EDIT_VARIABLE, Variables::WmTabCommand_EditVariable);
|
|
cmessages.Associate(IDC_BUTTON_DELETE_VARIABLE, Variables::WmTabCommand_DeleteVariable);
|
|
|
|
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);
|
|
cmessages.Associate(IDC_BUTTON_DELETE_FUNCTION, Functions::WmTabCommand_DeleteFunction);
|
|
|
|
cmessages.Associate(IDC_RADIO_PRECISION_1, WmTabCommand_SetPrecision1);
|
|
cmessages.Associate(IDC_RADIO_PRECISION_2, WmTabCommand_SetPrecision2);
|
|
cmessages.Associate(IDC_RADIO_PRECISION_3, WmTabCommand_SetPrecision3);
|
|
|
|
cmessages.Associate(IDC_COMBO_DISPLAY_INPUT, WmTabCommand_DisplayInputChanged);
|
|
cmessages.Associate(IDC_COMBO_DISPLAY_OUTPUT, WmTabCommand_DisplayOutputChanged);
|
|
cmessages.Associate(IDC_COMBO_DISPLAY_ROUNDING, WmTabCommand_DisplayRoundingChanged);
|
|
cmessages.Associate(IDC_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);
|
|
|
|
}
|
|
|
|
/*
|
|
a function for WM_COMMAND for dialogs which are on the tab
|
|
*/
|
|
BOOL WmTabCommand(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
static Messages command_messages;
|
|
|
|
if( command_messages.Empty() )
|
|
// initiation
|
|
CreateTabCommandMessagesTable(command_messages);
|
|
|
|
return command_messages.Call(LOWORD(wParam), hWnd, message, wParam, lParam);
|
|
}
|
|
|
|
BOOL WmTabInitDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
/*!
|
|
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 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);
|
|
|
|
SetDisablingEditDeleteVariableOrFunctionButtons(count, add, edit, del, focus);
|
|
}
|
|
|
|
|
|
/*!
|
|
this function enables or disables the 'edit' and 'delete' buttons
|
|
on the function's tab depending on how many variables are selected in the list
|
|
*/
|
|
void SetDisablingEditDeleteFunctionButtons(HWND hWnd)
|
|
{
|
|
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);
|
|
|
|
SetDisablingEditDeleteVariableOrFunctionButtons(count, add, edit, del, focus);
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
int size;
|
|
for( size=0 ; iv != GetPrgRes()->GetVariables()->End() ; ++iv, ++size )
|
|
Variables::AddNewItemToVariableList(list, iv->first, iv->second.value);
|
|
|
|
return size;
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
int size;
|
|
for( size=0 ; iv != GetPrgRes()->GetFunctions()->End() ; ++iv, ++size )
|
|
Functions::AddNewItemToFunctionList(list, iv->first, iv->second.value, iv->second.param);
|
|
|
|
return size;
|
|
}
|
|
|
|
|
|
BOOL WmInitTabVariables(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
HWND list = GetDlgItem(hWnd, IDC_VARIABLES_LIST);
|
|
LVCOLUMN column;
|
|
|
|
//int list_cx = SetSizeOfList(list);
|
|
int list_cx = 280;
|
|
|
|
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
|
column.cx = 60;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_variables_header_1) );
|
|
ListView_InsertColumn(list, 0, &column);
|
|
|
|
column.cx = list_cx - 60 - 10;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_variables_header_2) );
|
|
ListView_InsertColumn(list, 1, &column);
|
|
|
|
ListView_SetExtendedListViewStyle(list,LVS_EX_FULLROWSELECT);
|
|
SetDisablingEditDeleteVariableButtons(hWnd);
|
|
|
|
if( FillUpVariableList(list) > 0 )
|
|
ListView_SetItemState(list, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
|
|
|
|
return true;
|
|
}
|
|
|
|
BOOL WmInitTabFunctions(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
HWND list = GetDlgItem(hWnd, IDC_FUNCTIONS_LIST);
|
|
LVCOLUMN column;
|
|
|
|
//int list_cx = SetSizeOfList(list);
|
|
int list_cx = 280;
|
|
|
|
column.mask = LVCF_TEXT | LVCF_WIDTH;
|
|
column.cx = 60;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_functions_header_1) );
|
|
ListView_InsertColumn(list, 0, &column);
|
|
|
|
column.cx = 40;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_functions_header_2) );
|
|
ListView_InsertColumn(list, 1, &column);
|
|
|
|
column.cx = list_cx - 60 - 40 - 10;
|
|
column.pszText = const_cast<char*>( GetPrgRes()->GetLanguages()->GuiMessage(Languages::list_functions_header_3) );
|
|
ListView_InsertColumn(list, 2, &column);
|
|
|
|
ListView_SetExtendedListViewStyle(list,LVS_EX_FULLROWSELECT);
|
|
|
|
SetDisablingEditDeleteFunctionButtons(hWnd);
|
|
|
|
if( FillUpFunctionList(list) > 0 )
|
|
ListView_SetItemState(list, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL WmInitTabPrecision(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
CheckDlgButton(hWnd, IDC_RADIO_PRECISION_1 + GetPrgRes()->GetPrecision(), BST_CHECKED);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL WmInitTabDisplay(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
int i;
|
|
char buffer[20];
|
|
|
|
for(i=2 ; i<=16 ; ++i)
|
|
{
|
|
sprintf(buffer,"%d",i);
|
|
|
|
switch( i )
|
|
{
|
|
case 2:
|
|
strcat(buffer, " (bin)");
|
|
break;
|
|
|
|
case 8:
|
|
strcat(buffer, " (oct)");
|
|
break;
|
|
|
|
case 10:
|
|
strcat(buffer, " (dec)");
|
|
break;
|
|
|
|
case 16:
|
|
strcat(buffer, " (hex)");
|
|
break;
|
|
}
|
|
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_INPUT, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_OUTPUT, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
} // for
|
|
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_INPUT, CB_SETCURSEL, GetPrgRes()->GetBaseInput()-2, 0);
|
|
SendDlgItemMessage(hWnd, IDC_COMBO_DISPLAY_OUTPUT, CB_SETCURSEL, GetPrgRes()->GetBaseOutput()-2, 0);
|
|
|
|
|
|
if( GetPrgRes()->GetDisplayAlwaysScientific() )
|
|
CheckDlgButton(hWnd, IDC_RADIO_DISPLAY_ALWAYS_SCIENTIFIC, BST_CHECKED);
|
|
else
|
|
CheckDlgButton(hWnd, IDC_RADIO_DISPLAY_NOT_ALWAYS_SCIENTIFIC, BST_CHECKED);
|
|
|
|
SetDisablingDisplayWhenScientific(hWnd);
|
|
|
|
SendDlgItemMessage(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC, UDM_SETBASE, 10,0);
|
|
SendDlgItemMessage(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC, UDM_SETRANGE, 0, MAKELONG(99,1));
|
|
SendDlgItemMessage(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC, UDM_SETPOS, 0, 5);
|
|
SendDlgItemMessage(hWnd, IDC_UPDOWN_DISPLAY_WHEN_SCIENTIFIC, UDM_SETBUDDY, (WPARAM)GetDlgItem(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC), 0);
|
|
SendDlgItemMessage(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC, EM_SETLIMITTEXT, 2, 0);
|
|
|
|
sprintf(buffer,"%d", GetPrgRes()->GetDisplayWhenScientific());
|
|
SetDlgItemText(hWnd, IDC_EDIT_DISPLAY_WHEN_SCIENTIFIC, buffer);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
BOOL WmNotify(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
NMHDR * pnmh = (LPNMHDR) lParam;
|
|
HWND var_list = GetDlgItem(hWnd,IDC_VARIABLES_LIST);
|
|
HWND fun_list = GetDlgItem(hWnd,IDC_FUNCTIONS_LIST);
|
|
|
|
if( pnmh->hwndFrom == var_list )
|
|
{
|
|
if( pnmh->code == LVN_ITEMCHANGED )
|
|
{
|
|
SetDisablingEditDeleteVariableButtons( hWnd );
|
|
return true;
|
|
}
|
|
else
|
|
if( pnmh->code == UINT(NM_DBLCLK) )
|
|
{
|
|
Variables::WmTabCommand_EditVariable(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_VARIABLE, 0);
|
|
return true;
|
|
}
|
|
else
|
|
if( pnmh->code == LVN_KEYDOWN )
|
|
{
|
|
NMLVKEYDOWN * pnkd = (NMLVKEYDOWN*) lParam;
|
|
|
|
if( pnkd->wVKey == VK_DELETE )
|
|
Variables::WmTabCommand_DeleteVariable(0,0,0,0);
|
|
}
|
|
}
|
|
|
|
if( pnmh->hwndFrom == fun_list )
|
|
{
|
|
if( pnmh->code == LVN_ITEMCHANGED )
|
|
{
|
|
SetDisablingEditDeleteFunctionButtons( hWnd );
|
|
return true;
|
|
}
|
|
else
|
|
if( pnmh->code == UINT(NM_DBLCLK) )
|
|
{
|
|
Functions::WmTabCommand_EditFunction(hWnd, WM_COMMAND, IDC_BUTTON_EDIT_FUNCTION, 0);
|
|
return true;
|
|
}
|
|
else
|
|
if( pnmh->code == LVN_KEYDOWN )
|
|
{
|
|
NMLVKEYDOWN * pnkd = (NMLVKEYDOWN*) lParam;
|
|
|
|
if( pnkd->wVKey == VK_DELETE )
|
|
Functions::WmTabCommand_DeleteFunction(0,0,0,0);
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
messages.Associate(WM_COMMAND, WmTabCommand);
|
|
messages.Associate(WM_INIT_TAB_VARIABLES, WmInitTabVariables);
|
|
messages.Associate(WM_INIT_TAB_FUNCTIONS, WmInitTabFunctions);
|
|
messages.Associate(WM_INIT_TAB_PRECISION, WmInitTabPrecision);
|
|
messages.Associate(WM_INIT_TAB_DISPLAY, WmInitTabDisplay);
|
|
messages.Associate(WM_NOTIFY, WmNotify);
|
|
messages.Associate(WM_KEYDOWN, WmTabKeyDown);
|
|
}
|
|
|
|
|
|
|
|
BOOL CALLBACK TabWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
static Messages messages;
|
|
|
|
if( messages.Empty() )
|
|
// initiation
|
|
CreateTabMessagesTable(messages);
|
|
|
|
return messages.Call(message, hWnd, message, wParam, lParam);
|
|
}
|
|
|
|
|
|
|
|
void SetSizeOfFunctionVariableList(int tab_id, int list_id, int last_column)
|
|
{
|
|
HWND main = GetPrgRes()->GetMainWindow();
|
|
HWND tab = GetDlgItem(main, IDC_TAB);
|
|
|
|
POINT p,p2;
|
|
RECT r_main, r;
|
|
|
|
HWND dialog = GetPrgRes()->GetTabWindow(tab_id);
|
|
HWND list = GetDlgItem(dialog, list_id);
|
|
|
|
GetWindowRect(main, &r_main);
|
|
int cx = r_main.right - r_main.left;
|
|
int cy = r_main.bottom - r_main.top;
|
|
int border_x = GetSystemMetrics(SM_CXDLGFRAME)*2;
|
|
int border_y = GetSystemMetrics(SM_CYDLGFRAME)*2;
|
|
|
|
GetWindowRect(dialog, &r);
|
|
p.x = r.left;
|
|
p.y = r.top;
|
|
p2 = p;
|
|
p2.x -= r_main.left;
|
|
p2.y -= r_main.top;
|
|
ScreenToClient(tab, &p);
|
|
MoveWindow(dialog, p.x, p.y, cx-p2.x-border_x-2, cy-p2.y-border_y-2, true);
|
|
|
|
GetWindowRect(list, &r);
|
|
p.x = r.left;
|
|
p.y = r.top;
|
|
p2 = p;
|
|
p2.x -= r_main.left;
|
|
p2.y -= r_main.top;
|
|
ScreenToClient(dialog, &p);
|
|
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 ; i<last_column ; ++i)
|
|
sum += ListView_GetColumnWidth(list, i);
|
|
|
|
if( sum < list_cx - 30 )
|
|
ListView_SetColumnWidth(list, last_column, list_cx-sum-25);
|
|
}
|
|
|
|
|
|
void SetSizeOfVariablesList()
|
|
{
|
|
SetSizeOfFunctionVariableList(TabWindowFunctions::tab_variables, IDC_VARIABLES_LIST, 1);
|
|
}
|
|
|
|
void SetSizeOfFunctionsList()
|
|
{
|
|
SetSizeOfFunctionVariableList(TabWindowFunctions::tab_functions, IDC_FUNCTIONS_LIST, 2);
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|