From b3d2fc5d24fa8ba08a381cee35fb1a1400f12b41 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Mon, 2 Apr 2007 00:17:26 +0000 Subject: [PATCH] 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 --- CHANGELOG | 32 +++- README | 19 +++ TODO | 4 +- help/arithmetic_functions.html | 175 +++++++++++++++++++++ help/help.hhp | 23 +++ help/index.hhk | 9 ++ help/index.html | 47 ++++++ help/logical_functions.html | 103 +++++++++++++ help/operators_priority.html | 34 +++++ help/styles.css | 48 ++++++ help/tips.html | 40 +++++ help/toc.hhc | 42 ++++++ help/userfunctions.html | 36 +++++ help/values_and_std_operators.html | 65 ++++++++ setup/COPYRIGHT | 18 +++ setup/innosetup.iss | 45 ++++++ setup/ttcalc.ini | 21 +++ src/compileconfig.h | 4 +- src/functions.cpp | 172 ++++++++++++--------- src/languages.cpp | 55 +++---- src/languages.h | 13 +- src/mainwindow.cpp | 234 +++++++++++++++++++++-------- src/programresources.cpp | 31 ++-- src/programresources.h | 1 + src/resource.h | 9 +- src/resource.rc | 41 +++-- src/tabs.cpp | 53 +++++-- src/tabs.h | 13 +- src/variables.cpp | 197 +++++++++++++++--------- src/winmain.cpp | 6 +- 30 files changed, 1285 insertions(+), 305 deletions(-) create mode 100644 README create mode 100644 help/arithmetic_functions.html create mode 100644 help/help.hhp create mode 100644 help/index.hhk create mode 100644 help/index.html create mode 100644 help/logical_functions.html create mode 100644 help/operators_priority.html create mode 100644 help/styles.css create mode 100644 help/tips.html create mode 100644 help/toc.hhc create mode 100644 help/userfunctions.html create mode 100644 help/values_and_std_operators.html create mode 100644 setup/COPYRIGHT create mode 100644 setup/innosetup.iss create mode 100644 setup/ttcalc.ini diff --git a/CHANGELOG b/CHANGELOG index 9e3af09..93904d6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,11 +1,35 @@ +Version 0.8.0 (2007.04.02): + * added: the del key deletes a variable or a function now + (if the focus is on the list) + * 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) + * 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 + * fixed: when a user started navigating from the keyboard the program showed + a wrong variable or a funtion in the edit dialog + 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 + * 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) + * 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 diff --git a/README b/README new file mode 100644 index 0000000..21f9eaa --- /dev/null +++ b/README @@ -0,0 +1,19 @@ +TTCalc + +TTCalc is a mathematical calculator. It has a nice user interface, +formulas for calculating can be inserted by using a keyboard or a mouse. +The result is automatically shown in a second window without using any +additional keys such as 'equal'. The program possess trigonometric +functions, inverse trigonometric functions, hyperbolic functions, +logical operators, logarithms, functions for converting between degrees +and radians and so on. Additionally the program allows the user to +define his own variables and functions. Calculations are performed by +using floating point numbers with three kind of precision, the biggest +has 288 bits for its mantissa and 96 bits for its exponent that is +about 2.551...e+11925026709067095507636213441 with 85 valid decimal +digits. The program independently allows to insert and display values +with the base (radix) from two to sixteen. + +Author: Tomasz Sowa +Project page: http://sourceforge.net/projects/ttcalc +Licence: BSD (open source) diff --git a/TODO b/TODO index e629aa7..453c052 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ TODO TTCalc =========== -* To add some physical constants -* To make the help +* Add some physical constants + diff --git a/help/arithmetic_functions.html b/help/arithmetic_functions.html new file mode 100644 index 0000000..1b46197 --- /dev/null +++ b/help/arithmetic_functions.html @@ -0,0 +1,175 @@ + + + + + + TTCalc - arithmetic functions + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Arithmetic functions

+ +

Note: If a function takes more than one argument, the arguments are separated with semicolon ';'.

+ +
+
ln(x)
+
This function calculates the natural logarithm of x,
e.g. ln(123)=4.812...
+ +
log(x; base)
+
This function calculates the logarithm of x with a base equal 'base'
e.g. log(123; 4)=3.471...
+ +
exp(x)
+
This function calculates the exponent of x
e.g. exp(20)=e^20=485165195.409...
+ +
sin(x)
+
This function returns the sine of x.
For example sin(0.8)=0.717...
The argument x is in radians, if you want to calculate +with degrees use the degtorad(x) function first e.g. sin(degtorad(30))=0.5 calculates the sine of 30 degrees.
+ +
cos(x)
+
Cosine of x
e.g. cos(1.3)=0.267...
The argument x is in radians.
+ +
tan(x) or tg(x)
+
Tangent of x
e.g. tan(3.6)=0.493...
The argument x is in radians.
+ +
cot(x) or ctg(x)
+
Cotangent of x
e.g. cot(2.3)=-0.893...
The argument x is in radians.
+ +
asin(x)
+
Arc sine of x
e.g. asin(0.7)=0.775...
The result is in radians. If you want the result to be in degrees use +radtodeg function e.g. radtodeg(asin(0,5))=30
+ +
acos(x)
+
Arc cosine of x
e.g. acos(0.9)=0.451...
The result is in radians.
+ +
atan(x) or atg(x)
+
Arc tangent of x
e.g. atan(3.3)=1.276...
The result is in radians.
+ +
acot(x) or actg(x)
+
Arc cotangent of x
e.g. acot(10)=0.099...
The result is in radians.
+ +
sinh(x)
+
This function returns hyperbolic sine of x
e.g.sinh(12)=81377.395...
+ +
cosh(x)
+
Hyperbolic cosine of x
e.g. cosh(8.5)=2457.384...
+ +
tanh(x) or tgh(x)
+
Hyperbolic tangent of x
e.g. tanh(0.67)=0.584...
+ +
coth(x) or ctgh(x)
+
Hyperbolic cotangent of x
e.g. coth(1.67)=1.073...
+ +
DegToDeg(deg; min; sec)
+
This function converts degrees from the long format with degres, minutes and seconds into only degrees.
+For example degtodeg(12; 30; 0)=12.5
+ +
DegToRad(deg)
+
This function converts degrees into radians
e.g. degtorad(12.5)=0.218166...
+ +
DegToRad(deg; min; sec)
+
This function converts degrees in the long format (degrees, minutes, seconds) to radians.
For example +degtorad(12; 30; 0)=0.218166...
+ +
RadToDeg(rad)
+
This function converts radians into degrees
e.g. radtodeg(pi)=180
+ +
sqrt(x)
+
Sqrt returns the square root of x
e.g. sqrt(9)=3
+If you want to calculate another kind of roots for example the cube root use the powering instead e.g. +the cube root of 8 is 8^(1/3)=2
+ +
factorial(x)
+
The factorial function
e.g. factorial(6)=1*2*3*4*5*6=720
+ +
abs(x)
+
The absolute value of x
e.g. abs(-10)=10
+ +
sgn(x)
+
This function returns the sign of x that means when the x is positive the result is 1, when the x is negative +the result is -1 and when the x is zero the result is zero too, e.g.
+sgn(-10)=-1
+sgn(0)=0
+sgn(5)=1
+ +
mod(x,y)
+
Mod returns the remainder from the division x by y
e.g. mod(10; 2.2)=1.2 because 10=2.2*4 + 1.2
+ +
int(x)
+
This method returns only the integer part of x.
e.g. int(2.7)=2
+ +
round(x)
+
This method rounds the value of x to the nearest integer e.g.
+round(2.8)=3
+round(2.2)=2
+round(2)=2
+round(-4.8)=-5
+round(-4.1)=-4
+ +
ceil(x)
+
This function returns a value representing the smallest integer that is greater than or equal to x, e.g.
+ceil(2.8)=3
+ceil(2.2)=3
+ceil(2)=2
+ceil(-4.8)=-4
+ceil(-4.1)=-4
+ +
floor(x)
+
This function returns a value representing the largest integer that is less than or equal to x, e.g.
+floor(2.8)=2
+floor(2.2)=2
+floor(2)=2
+floor(-4.8)=-5
+floor(-4.1)=-5
+ +
max(x1; x2; ...)
+
This functions takes any number of arguments. It returns the max value of them. If there aren't arguments +the function returns the max value which can be held in this precision.
+ +
min(x1; x2; ...)
+
This functions takes any number of arguments. It returns the min value of them. If there aren't arguments +the function returns the min value which can be held in this precision.
+ +
+ + + diff --git a/help/help.hhp b/help/help.hhp new file mode 100644 index 0000000..6588f72 --- /dev/null +++ b/help/help.hhp @@ -0,0 +1,23 @@ +[OPTIONS] +Auto Index=Yes +Compatibility=1.1 or later +Compiled file=..\..\output\ttcalc.chm +Contents file=toc.hhc +Default topic=index.html +Display compile progress=No +Index file=index.hhk +Language=0x809 Angielski (Wielka Brytania) +Title=TTCalc + + +[FILES] +values_and_std_operators.html +arithmetic_functions.html +logical_functions.html +operators_priority.html +userfunctions.html +index.html +tips.html + +[INFOTYPES] + diff --git a/help/index.hhk b/help/index.hhk new file mode 100644 index 0000000..2e24f6f --- /dev/null +++ b/help/index.hhk @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/help/index.html b/help/index.html new file mode 100644 index 0000000..134b753 --- /dev/null +++ b/help/index.html @@ -0,0 +1,47 @@ + + + + + + TTCalc + + + + + + + + + + + + + +

TTCalc

+ +

+TTCalc is a mathematical calculator. It has a nice user interface, formulas for +calculating can be inserted by using a keyboard or a mouse. The result is automatically +shown in a second window without using any additional keys such as 'equal'. The +program possess trigonometric functions, inverse trigonometric functions, hyperbolic +functions, logical operators, logarithms, functions for converting between degrees and +radians and so on. Additionally the program allows the user to define his own +variables and functions. Calculations are performed by using floating point numbers +with three kind of precision, the biggest has 288 bits for its mantissa and 96 bits +for its exponent that is about 2.551...e+11925026709067095507636213441 with 85 valid +decimal digits. The program independently allows to insert and display values with +the base (radix) from two to sixteen. +

+ + + + + + + + +
Author:Tomasz Sowa
Contact:t.sowa@slimaczek.pl
Licence:BSD (open source)
Operating systems:Microsoft Windows 9x/Me/NT/2000/XP (Vista was not tested)
Interface:English, Polish
Project page:http://sourceforge.net/projects/ttcalc
+ + + + \ No newline at end of file diff --git a/help/logical_functions.html b/help/logical_functions.html new file mode 100644 index 0000000..dd28307 --- /dev/null +++ b/help/logical_functions.html @@ -0,0 +1,103 @@ + + + + + + TTCalc - comparative and logical operators and functions + + + + + + + + + + + + + + + + + + + + + + +

Comparative and logical operators and functions

+ +

+We assume that the logical false is represented by zero and the logical true is represented by the +value different from zero. Note: If a function takes more than one argument, the arguments are separated with semicolon ';'. +

+ + +
+ +
x < y
+
This operator returns one if x is lower than y else it returns zero. For example:
+4 < 10 = 1
+6 < 2 = 0
+ +
x > y
+
This operator returns one if x is greater than y else it returns zero. For example:
+5 > 2 = 1
+5 > 8 = 0
+ +
x <= y
+
This operator returns one if x is lower than or equal to y else it returns zero. For example:
+4 <= 4 = 1
+7 <= 2 = 0
+ +
x >= y
+
This operator returns one if x is greater than or equal to y else it returns zero. For example:
+5 >= 5 = 1
+3 >= 4 = 0
+ +
x == y
+
This operator returns one if x is equal y else it returns zero. For example:
+4 == 4 = 1
+6 == 2 = 0
+ +
x != y
+
This operator returns one if x is different from y else it returns zero. For example:
+5 != 2 = 1
+5 != 5 = 0
+ +
x && y (logical and)
+
This operator returns one if both x and y are different from zero else it returns zero. For example:
+4 && 10 = 1
+6 && 0 = 0
+0 && 0 = 0
+ +
x || y (logical or)
+
This operator returns one either if x or y are different from zero else it returns zero. For example:
+5 || 2 = 1
+0 || 3 = 1
+0 || 0 = 0
+ +
if(condition; if_true; if_false)
+
If the 'condition' is true (different from zero) the function returns 'if_true' else it returns 'if_false', e.g.
+if( 0 ; 20 ; 30) = 30
+if( 1 ; 20 ; 30) = 20
+if( 4<5 ; 10 ; 50) = 10
+if( 6>10 ; 200 ; 100) = 100
+ +
and(x ; y)
+
This function does the same thing as the logical operator 'and' (&&)
+ +
or(x ; y)
+
This function does the same thing as the logical operator 'or' (||)
+ +
not(x)
+
If the x is true (different from zero) this function returns zero, otherwise it returns one, e.g.
+not(15)=0
+not(0)=1
+ +
+ + + + \ No newline at end of file diff --git a/help/operators_priority.html b/help/operators_priority.html new file mode 100644 index 0000000..d8ae5d8 --- /dev/null +++ b/help/operators_priority.html @@ -0,0 +1,34 @@ + + + + + + TTCalc - operators priority + + + + + + + + +

Operators Priority

+ +

Below is a list of operators priority. At the top are operators with higher precedence.

+ + + + + + + + + + + + + +
OperatorDescriptionSample
( )parentheses for grouping an expression(1+3)*4
- + # &unary minus and plus, and operators for changing the base (radix)-10
^powering3^2
* /multiplication and division10*20
+ -addition and subtraction10-30
== != < > <= >=comparative operators4<5
&&logical and3>2 && 3<10
||logical or3>2 || 3<10
+ + + diff --git a/help/styles.css b/help/styles.css new file mode 100644 index 0000000..434e079 --- /dev/null +++ b/help/styles.css @@ -0,0 +1,48 @@ +html * { +margin: 0; +border: 0; +padding: 0; +} + + +html, body { +font-size: 14px; +font-family: Tahoma, Arial, Sans-serif; +} + +body { +margin: 0 0 20px 20px; +} + +h1 { +font-size: 2em; +font-family: Arial, Tahoma, Sans-serif; +margin: 1.4em 0 1em 0; +} + +p { +margin: 1em 0 1em 0; +} + +dt { +font-size: 1.4em; +margin-top: 1em; +} + + +dd { +padding: 0.3em 0 0 2em; +} + +thead { +font-size: 1.2em; +} + +td { +padding: 0 2em 0 0; +} + + + + + diff --git a/help/tips.html b/help/tips.html new file mode 100644 index 0000000..c4b3f1c --- /dev/null +++ b/help/tips.html @@ -0,0 +1,40 @@ + + + + + + TTCalc - tips + + + + + + + + + + + + +

Tips

+ +

+If you want to clear the input edit or if you want to put something in and the focus is +somewhere on the tabs just type ESC, the entire edit will be selected and have a focus. +

+ +

+If you want to insert a value with a base (radix) 2 or 16 use the unary operator & (for the base 2) +or # (for the base 16). +For example &10=2 (decimal), #10=16 (decimal). When you're using these operators +then 'input' mode on the 'display' tab is ignored. +

+ +

+You can calculate more than one formula at the same time. To achive this use a semicolon +in the global space, for example type '2+4 ; 5*10' and the result will be '6   50'. +

+ + + + \ No newline at end of file diff --git a/help/toc.hhc b/help/toc.hhc new file mode 100644 index 0000000..f4ef632 --- /dev/null +++ b/help/toc.hhc @@ -0,0 +1,42 @@ + + + + + + + + + + + diff --git a/help/userfunctions.html b/help/userfunctions.html new file mode 100644 index 0000000..914245b --- /dev/null +++ b/help/userfunctions.html @@ -0,0 +1,36 @@ + + + + + + TTCalc - user defined variables and functions + + + + + + + + + +

User defined variables and functions

+ +

+You are allowed to define your own variables and functions. As a name of a variable or a function +can be a name consists of letters and digits but the first character must be a letter. Names are case-insensitive +that means 'name' is the same as 'NaMe'. For example these +are correct names: a, b, c3, myname, etc. During defining variables and functions you can call another +variables and functions but you cannot call a variable or a function twice. Recurrence calling are not allowed. +

+ +

+Functions can get maximum 9 parameters. You have to specify how many parameters your function takes and +you can refer to them by using the variable 'x' with a number from 1 to 9 ('x' without a number means 'x1'). +For example you can define a function 'xy' as 'x1*x2' (of course without apostrophes), set the 'parameters' on 2 +and then put into the edit box an expression 'xy(10;20)', the result will be 200. Note that we use a semicolon +to separate arguments in a function. +

+ + + + \ No newline at end of file diff --git a/help/values_and_std_operators.html b/help/values_and_std_operators.html new file mode 100644 index 0000000..3e90621 --- /dev/null +++ b/help/values_and_std_operators.html @@ -0,0 +1,65 @@ + + + + + + TTCalc - numbers, standard operators and built-in variables + + + + + + + + + + + + + + + + + + +

Numbers

+ +You can type numbers directly using a keyboard or insert them by a mouse. This is a simple edit window, +you can use arrow keys etc. and copy&paste a text by using standard shortcuts such as CTRL+C and CTRL+V. +As the decimal point can be either a comma or a dot that means 1,234 is the same as 1.234. + +

Standard operators

+ +
+
^
+
Powering
+ +
*
+
Multiplication
+ +
/
+
Division
+ +
+
+
Addition
+ +
-
+
Subtraction
+ +
+ +

Of course you can use the parentheses ( and ). Look at the operators priority as well.

+ +

Built-in variables

+ +

You can use following variables, just type its name into the edit window.

+
+
e
+
The base of the natural logarithm.
e = 2.718...
+ +
pi
+
The ratio of a circle's circumference to its diameter.
pi=3.141...
+
+ + + diff --git a/setup/COPYRIGHT b/setup/COPYRIGHT new file mode 100644 index 0000000..3c550cd --- /dev/null +++ b/setup/COPYRIGHT @@ -0,0 +1,18 @@ +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. diff --git a/setup/innosetup.iss b/setup/innosetup.iss new file mode 100644 index 0000000..c7be811 --- /dev/null +++ b/setup/innosetup.iss @@ -0,0 +1,45 @@ +; Script generated by the Inno Setup Script Wizard. +; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! + +[Setup] +AppName=TTCalc +AppVerName=TTCalc 0.8.0 +AppPublisher=Tomasz Sowa +AppPublisherURL=http://sourceforge.net/projects/ttcalc +AppSupportURL=http://sourceforge.net/projects/ttcalc +AppUpdatesURL=http://sourceforge.net/projects/ttcalc +DefaultDirName={pf}\TTCalc +DefaultGroupName=TTCalc +AllowNoIcons=yes +LicenseFile=COPYRIGHT +OutputDir=..\..\output_setup +OutputBaseFilename=ttcalc-setup +Compression=lzma +SolidCompression=yes + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" +Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl" + + +[Tasks] +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked +Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked + +[Files] +Source: "..\..\output\ttcalc.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\..\output\mingwm10.dll"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\..\output\ttcalc.chm"; DestDir: "{app}"; Flags: ignoreversion +Source: "..\COPYRIGHT"; DestDir: "{app}"; Flags: ignoreversion +Source: "ttcalc.ini"; DestDir: "{userappdata}\TTCalc"; Flags: onlyifdoesntexist +; NOTE: Don't use "Flags: ignoreversion" on any shared system files + +[Icons] +Name: "{group}\TTCalc"; Filename: "{app}\ttcalc.exe"; WorkingDir: "{app}" +Name: "{group}\Help"; Filename: "{app}\ttcalc.chm"; WorkingDir: "{app}" +Name: "{group}\{cm:UninstallProgram,TTCalc}"; Filename: "{uninstallexe}" +Name: "{commondesktop}\TTCalc"; Filename: "{app}\ttcalc.exe"; WorkingDir: "{app}"; Tasks: desktopicon + +[Run] +Filename: "{app}\ttcalc.exe"; Description: "{cm:LaunchProgram,TTCalc}"; Flags: nowait postinstall skipifsilent + diff --git a/setup/ttcalc.ini b/setup/ttcalc.ini new file mode 100644 index 0000000..492e99e --- /dev/null +++ b/setup/ttcalc.ini @@ -0,0 +1,21 @@ +# the configuration file of the program ttcalc + +[GLOBAL] +always.on.top = 0 +view = 0 +maximized = 0 +x = 0 +y = 0 +size.x = 402 +size.y = 288 +precision = 0 +disp.input = 10 +disp.output = 10 +language = 0 +disp.alw.scientific = 0 +disp.when.scientific = 15 +disp.rounding = -2 + +[variables] + +[functions] diff --git a/src/compileconfig.h b/src/compileconfig.h index c86036e..8475b3d 100644 --- a/src/compileconfig.h +++ b/src/compileconfig.h @@ -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 diff --git a/src/functions.cpp b/src/functions.cpp index e7c01ac..4b4ed3c 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -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( 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( 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( 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( 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( 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( 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); diff --git a/src/languages.cpp b/src/languages.cpp index 6a50be8..d41f5ec 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -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ł 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ł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ędzy funkcjami zachodzi wywołanie rekurencyjne"); InsertErrorPair(ttmath::err_must_be_only_one_value,"Zmienne albo funkcje mogą posiadać (zwracać) tylko jedną wartość"); InsertErrorPair(ttmath::err_still_calculating,"Obliczanie..."); + InsertErrorPair(ttmath::err_too_big_factorial,"Zbyt duż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() ); @@ -353,8 +355,7 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(display_output,"Wyjście"); InsertGuiPair(display_rounding,"Zaokrąglenie"); InsertGuiPair(display_always_scientific,"Zawsze"); - InsertGuiPair(display_not_always_scientific,"Jeśli eksponent większy niż"); - InsertGuiPair(display_digit, "cyfr"); + InsertGuiPair(display_not_always_scientific,"Jeśli eksponent jest większy niż:"); InsertGuiPair(display_group_scientific, "Wyświetl wynik w postaci naukowej"); InsertGuiPair(menu_view, "&Widok"); @@ -368,10 +369,12 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(menu_view_lang_english, "Język &angielski"); InsertGuiPair(menu_view_lang_polish, "Ję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ło się zainicjalizować modułu obsługi obliczeń"); InsertGuiPair(message_box_error_caption,"TTCalc"); InsertGuiPair(cant_create_thread, "Nie udało się utworzyć drugiego wątku do obliczeń"); @@ -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żych liczb: TTMath %d.%d.%d\r\n" "Język programowania: C++\r\n" "Kompilator: %s\r\n" "\r\n" - "Ten program używa biblioteki matematycznej TTMath" + "Ten program używa biblioteki dużych liczb TTMath" " która jest dostępna na http://sourceforge.net/projects/ttmath\r\n" "\r\n" "Jeżeli masz jakieś pytania, rady, ciekawe pomysły dotyczą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łędu"); - - + InsertGuiPair(cant_find_help, "Nie mogę znależć żadnych plików pomocy"); + InsertGuiPair(cant_open_project_page, "Nie mogę otworzyć strony projektu"); } diff --git a/src/languages.h b/src/languages.h index ea8d461..866756d 100644 --- a/src/languages.h +++ b/src/languages.h @@ -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 }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 940d033..01ea5ff 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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); } diff --git a/src/programresources.cpp b/src/programresources.cpp index 48d6627..06474bf 100644 --- a/src/programresources.cpp +++ b/src/programresources.cpp @@ -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; } + + } diff --git a/src/programresources.h b/src/programresources.h index 6112377..7e54fef 100644 --- a/src/programresources.h +++ b/src/programresources.h @@ -49,6 +49,7 @@ #include "threadcontroller.h" #include +#include #include diff --git a/src/resource.h b/src/resource.h index 8e756b0..bffde4e 100644 --- a/src/resource.h +++ b/src/resource.h @@ -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 diff --git a/src/resource.rc b/src/resource.rc index 03a032d..0cb9064 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -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 diff --git a/src/tabs.cpp b/src/tabs.cpp index b310a47..7254804 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -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 ; iGetTabWindow(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 diff --git a/src/tabs.h b/src/tabs.h index 3626cb9..f47e161 100644 --- a/src/tabs.h +++ b/src/tabs.h @@ -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); diff --git a/src/variables.cpp b/src/variables.cpp index da5979d..73f686a 100644 --- a/src/variables.cpp +++ b/src/variables.cpp @@ -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( name.c_str() ); - item.iSubItem = 0; - - int id = ListView_InsertItem(list, &item); - ListView_SetItemText(list,id,1,const_cast( 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( 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( name.c_str() ); + item.iSubItem = 0; + + int id = ListView_InsertItem(list, &item); + ListView_SetItemText(list,id,1,const_cast( 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( 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 ; idGetLanguages()->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); diff --git a/src/winmain.cpp b/src/winmain.cpp index efe57d9..7c5db27 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -45,10 +45,6 @@ #include -#include - - - /*! 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 ) )