Browse Source

added: when a user presses CTRL+C then the result will be

copied into the clipboard (if the current control which 
         has a focus is not an edit control, or if it is an edit
         but has no selection)
added:   when a user presses CTRL+V then a text from the clipboard
         will be copied into the edit control (if a focus is not 
         on another edit control)
changed: Makefile: added rules: help, setup
         and more small changes,
         small changes in Makefileportable
changed: Makefile.dep
added:   Makefile.help.sh
         this script calls for Html Help Workshop
         and when there was an error returns 1
         and if success returns 0
         (HtmlHW returns conversely)


git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@50 e52654a7-88a9-db11-a3e9-0013d4bc506e
0.8.x
Tomasz Sowa 16 years ago
parent
commit
c232565953
  1. 13
      help/tips.html
  2. 2
      setup/innosetup.iss
  3. 27
      src/Makefile
  4. 16
      src/Makefile.dep
  5. 16
      src/Makefile.help.sh
  6. 9
      src/Makefileportable
  7. 108
      src/mainwindow.cpp
  8. 33
      src/winmain.cpp
  9. 2
      src/winmain.h

13
help/tips.html

@ -11,6 +11,8 @@
<param name="Keyword" value="#">
<param name="Keyword" value="&amp;">
<param name="Keyword" value="global semicolon">
<param name="Keyword" value="CTRL+C">
<param name="Keyword" value="CTRL+V">
</object>
</head>
@ -35,6 +37,17 @@ You can calculate more than one formula at the same time. To achive this use a s
in the global space, for example type '2+4 ; 5*10' and the result will be '6&nbsp;&nbsp;&nbsp;50'.
</p>
<p>
You can use CTRL+C to copy the result from the output edit into the clipboard
(if a control which has a focus is not an edit control, or if it is an edit but
has no selection)
</p>
<p>
Also you can use CTRL+V to paste a text from the clipboard into the input control
(if a focus is not on another edit control)
</p>
</body>
</html>

2
setup/innosetup.iss

@ -12,7 +12,7 @@ DefaultDirName={pf}\TTCalc
DefaultGroupName=TTCalc
AllowNoIcons=yes
LicenseFile=COPYRIGHT
OutputDir=..\..\output_setup
OutputDir=..\..\output
OutputBaseFilename=ttcalc-setup
Compression=lzma
SolidCompression=yes

27
src/Makefile

@ -1,19 +1,42 @@
CC = g++
CFLAGS = -Wall -pedantic -s -O2 -mwindows -mthreads -I../../../ttmath
name = ttcalc.exe
# the name of the help is also set in the html help workshop project file
helpname = ttcalc.chm
# the name of the setup is also set in the Inno Setup config file
setupname = ttcalc-setup.exe
dir_output = ../../output
all: ttcalc
include Makefile.dep
ttcalc: $(o)
$(dir_output)/$(name): $(o)
$(CC) -o $(dir_output)/$(name) $(CFLAGS) $(o) -lcomctl32
ttcalc: $(dir_output)/$(name)
resource.o: resource.rc
windres resource.rc resource.o
$(dir_output)/$(helpname): $(helpdep)
Makefile.help.sh
help: $(dir_output)/$(helpname)
$(dir_output)/$(setupname): $(setupdep)
iscc ../setup/innosetup.iss
setup: $(dir_output)/$(setupname)
clean:
rm -f *.o
rm -f *.s
rm -f $(dir_output)/$(name)
rm -f $(dir_output)/$(helpname)
rm -f $(dir_output)/$(setupname)

16
src/Makefile.dep

@ -15,3 +15,19 @@ winmain.o: winmain.cpp compileconfig.h winmain.h programresources.h iniparser.
.cpp.o:
$(CC) -c $(CFLAGS) $<
helpdep = ../help/arithmetic_functions.html \
../help/operators_priority.html \
../help/bitwise_functions.html \
../help/index.html \
../help/userfunctions.html \
../help/logical_functions.html \
../help/tips.html \
../help/values_and_std_operators.html \
../help/styles.css \
../help/index.hhk \
../help/toc.hhc \
../help/help.hhp
setupdep = ttcalc help ../setup/innosetup.iss ../setup/COPYRIGHT ../setup/ttcalc.ini

16
src/Makefile.help.sh

@ -0,0 +1,16 @@
#!/bin/sh
# we provide a small wrapper for Html Help Workshop because the Html HW returns 1 when
# it has compiled the help and the 'make' program then stops
hhc ../help/help.hhp
if [ $? == 0 ]
then
# there was an error
exit 1
fi
# there was a success
exit 0

9
src/Makefileportable

@ -8,14 +8,11 @@ all: ttcalc
include Makefile.dep
ttcalc: $(o)
$(dir_output)/$(name): $(o)
$(CC) -o $(dir_output)/$(name) $(CFLAGS) $(o) -lcomctl32
$(compressor) -7 $(dir_output)/$(name)
ttcalc: $(dir_output)/$(name)
resource.o: resource.rc
windres -DTTCALC_PORTABLE resource.rc resource.o
clean:
rm -f *.o
rm -f *.s
rm -f $(dir_output)/$(name)

108
src/mainwindow.cpp

@ -238,6 +238,114 @@ return false;
}
int ToLower(int c)
{
if( c>='A' && c<='Z' )
return c - 'A' + 'a';
return c;
}
/*!
this function compares two strings
(case insensitive)
*/
bool EqualStrings(const char * str1, const char * str2)
{
for( ; ToLower(*str1) == ToLower(*str2) ; ++str1, ++str2 )
if( *str1 == 0 )
return true; // *str2 will be 0 too
return false;
}
/*!
this function is called when CTRL+C has been pressed
we're testing what type of control has a focus
if it is not an edit control we will copy the result from the output edit
and if is is an edit control we're checking whether the edit has a selecion or not,
if it has not a selection we will copy the result otherwise we return 'false'
and the CTRL+C will be passed into the standard procedure
*/
bool CopyResult()
{
char buffer[30];
DWORD sel_start, sel_end;
HWND focus = GetFocus();
bool copy = true;
GetClassName( focus, buffer, sizeof(buffer)/sizeof(char) );
if( EqualStrings(buffer, "edit") )
{
SendMessage(focus, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
if( sel_start != sel_end )
// the control has a selection
copy = false;
}
if( copy )
{
// the control has no selection
HWND main_window = GetPrgRes()->GetMainWindow();
HWND output_edit = GetDlgItem(main_window, IDC_OUTPUT_EDIT);
DWORD out_sel_start, out_sel_end;
// we're getting the selection on the output edit
// there may be no selection
SendMessage(output_edit, EM_GETSEL, (WPARAM)&out_sel_start, (LPARAM)&out_sel_end);
// setting the selection for the whole control
SendMessage(output_edit, EM_SETSEL, 0, -1);
// copying the result
SendMessage(output_edit, WM_COPY, 0, 0);
// and restoring the selection to the previous state
SendMessage(output_edit, EM_SETSEL, out_sel_start, out_sel_end);
return true;
}
return false;
}
/*!
this function is called when CTRL+V has been pressed
if a focus is not on an edit control (or it can be on an edit
but the edit must be read only) we're sending WM_PASTE into the
input edit and setting a focus on it
*/
bool Paste()
{
char buffer[30];
HWND focus = GetFocus();
GetClassName( focus, buffer, sizeof(buffer)/sizeof(char) );
if( EqualStrings(buffer, "edit") )
{
if( (GetWindowLong(focus, GWL_STYLE) & ES_READONLY) == 0 )
return false;
// it's an edit but it has ES_READONLY style set
}
HWND main_window = GetPrgRes()->GetMainWindow();
HWND input_edit = GetDlgItem(main_window, IDC_INPUT_EDIT);
SendMessage(input_edit, WM_PASTE, 0, 0);
SetFocus(input_edit);
return true;
}
void SetActiveTab(unsigned int i)
{
static int last_shown_dialog = -1;

33
src/winmain.cpp

@ -102,6 +102,7 @@ return static_cast<int>( error_code );
/*!
the main loop of messages
*/
@ -111,36 +112,54 @@ MSG msg;
while( GetMessage(&msg,0,0,0) )
{
bool sended = false;
bool sent = false;
// if there's CTRL+C or CTRL+V pressed we're trying to copy
// a result from the output edit or trying to paste something from the clipboard
if( msg.message==WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0xff00)!=0 )
{
if( msg.wParam == 'C' )
{
if( MainWindowFunctions::CopyResult() )
sent = true;
}
else
if( msg.wParam == 'V' )
{
if( MainWindowFunctions::Paste() )
sent = true;
}
}
// we give our own special function for navigating from the keyboard
// if our function returns false then we use a standard navigation
// from the system
if( msg.message == WM_KEYDOWN &&
if( !sent && msg.message == WM_KEYDOWN &&
( msg.wParam == VK_TAB ||
msg.wParam == VK_DOWN || msg.wParam == VK_UP ||
msg.wParam == VK_LEFT || msg.wParam == VK_DOWN ) )
{
if( MainWindowFunctions::SetNextFocus(msg.wParam) )
sended = true;
sent = true;
}
// firt we try to send our message to dialogs
// (the dialogs on the tab control)
if( !sended )
if( !sent )
{
for(unsigned int i=0 ; i<GetPrgRes()->HowManyTabWindows() && !sended ; ++i)
for(unsigned int i=0 ; i<GetPrgRes()->HowManyTabWindows() && !sent ; ++i)
{
if( IsDialogMessage(GetPrgRes()->GetTabWindow(i), &msg) )
sended = true;
sent = true;
}
}
// if it's not a message to any of our dialogs we send it
// to the main window (it's a dialog as well)
if( !sended )
if( !sent )
{
if( !IsDialogMessage(GetPrgRes()->GetMainWindow(), &msg) )
{

2
src/winmain.h

@ -64,6 +64,8 @@ void MainMessagesLoop();
namespace MainWindowFunctions
{
bool SetNextFocus(WPARAM wParam);
bool CopyResult();
bool Paste();
void CreateMainMessagesTable(Messages & messages);
BOOL CALLBACK AboutProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
}

Loading…
Cancel
Save