From c2325659537a2a395a0dbbc13620673c3f8e1b1d Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 5 Aug 2007 20:31:46 +0000 Subject: [PATCH] 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 --- help/tips.html | 13 ++++++ setup/innosetup.iss | 2 +- src/Makefile | 27 ++++++++++- src/Makefile.dep | 16 +++++++ src/Makefile.help.sh | 16 +++++++ src/Makefileportable | 9 ++-- src/mainwindow.cpp | 108 +++++++++++++++++++++++++++++++++++++++++++ src/winmain.cpp | 33 ++++++++++--- src/winmain.h | 2 + 9 files changed, 210 insertions(+), 16 deletions(-) create mode 100644 src/Makefile.help.sh diff --git a/help/tips.html b/help/tips.html index c4b3f1c..3c20e36 100644 --- a/help/tips.html +++ b/help/tips.html @@ -11,6 +11,8 @@ + + @@ -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   50'.

+

+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) +

+ +

+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) +

+ \ No newline at end of file diff --git a/setup/innosetup.iss b/setup/innosetup.iss index 876cf77..89042e4 100644 --- a/setup/innosetup.iss +++ b/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 diff --git a/src/Makefile b/src/Makefile index a3c883a..b57e487 100644 --- a/src/Makefile +++ b/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) diff --git a/src/Makefile.dep b/src/Makefile.dep index b88d5bf..fde54b5 100644 --- a/src/Makefile.dep +++ b/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 diff --git a/src/Makefile.help.sh b/src/Makefile.help.sh new file mode 100644 index 0000000..dfd2f69 --- /dev/null +++ b/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 diff --git a/src/Makefileportable b/src/Makefileportable index 3ed8688..82ff173 100644 --- a/src/Makefileportable +++ b/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) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4f0a3ae..0953000 100644 --- a/src/mainwindow.cpp +++ b/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; diff --git a/src/winmain.cpp b/src/winmain.cpp index a23fc4b..60ae664 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -102,6 +102,7 @@ return static_cast( 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 ; iHowManyTabWindows() && !sended ; ++i) + for(unsigned int i=0 ; iHowManyTabWindows() && !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) ) { diff --git a/src/winmain.h b/src/winmain.h index 69fcaff..3cbd82c 100644 --- a/src/winmain.h +++ b/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); }