From ce272dcb1a2a7805e64e699aac83a1cbfaa37eee Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 3 Nov 2009 13:31:11 +0000 Subject: [PATCH] fixed: the clipboard didn't work well CopyBoth should not use GlobalFree() if SetClipboardData() succeeded added: menu edit: select all, bracket changed: ctrl+c is equivalent to CopySpecial() now if there is a selection on an edit (and the edit has focus) it works as a normal copy but if there isn't any selections then it copies the result git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@234 e52654a7-88a9-db11-a3e9-0013d4bc506e --- CHANGELOG | 2 +- src/languages.cpp | 2 +- src/mainwindow.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++--- src/resource.h | 32 +++++++++++++--------- src/resource.rc | 53 +++++++++++++++++++----------------- src/winmain.cpp | 6 ++++- src/winmain.h | 1 + 7 files changed, 118 insertions(+), 45 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 29e6d69..f8a3c26 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,7 @@ Version 0.9.0 prerelease (2009.11.03): * added: Pad window - a multiline edit window * added: Checking for update dialog box * added: there are some new buttons on the standard tab - - (...) - the whole expression is surrounded by brackets + - (...) - the whole expression is surrounded by brackets (ctrl+0 short cut) - 1/(...) - ; - % - a new percentage operator diff --git a/src/languages.cpp b/src/languages.cpp index c6a9b6e..ab1c489 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -451,7 +451,7 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(menu_view_close_program, "&Close"); InsertGuiPair(menu_edit_undo, "&Undo \tCtrl+Z"); InsertGuiPair(menu_edit_paste_formula, "&Paste formula\tCtrl+V"); - InsertGuiPair(menu_edit_copy_result, "&Copy result \tCtrl+C"); + InsertGuiPair(menu_edit_copy_result, "&Copy result \tCtrl+R"); InsertGuiPair(menu_help_help, "&Help"); InsertGuiPair(menu_help_project_page, "&Project page"); InsertGuiPair(menu_help_about, "&About"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bd23abc..fc6f371 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -279,7 +279,6 @@ return false; /*! - this function is called when CTRL+C has been pressed */ bool CopyResult() { @@ -304,6 +303,36 @@ return true; } + +/*! + if the focus is not on an edit window + or it is on an edit but the edit has no selection + then we're copying the result + + this is used when Ctrl+C is pressed +*/ +bool CopySpecial() +{ +HWND focus = GetFocus(); + + if( IsEditControl(focus) ) + { + DWORD sel_start, sel_end; + SendMessage(focus, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end); + + if( sel_start != sel_end ) // something is selected + return false; + } + + CopyResult(); + +return true; +} + + + + + /*! this function is called when CTRL+V has been pressed this is not Paste but PasteFormula (everything is copied to the input edit, even @@ -862,6 +891,17 @@ bool can_undo = false; else EnableMenuItem(menu,IDM_EDIT_PASTE_FORMULA,MF_BYCOMMAND | MF_GRAYED); + // select all, bracket + if( input_size > 0 ) + { + EnableMenuItem(menu,IDM_EDIT_SELECT_ALL,MF_BYCOMMAND | MF_ENABLED); + EnableMenuItem(menu,IDM_EDIT_BRACKET,MF_BYCOMMAND | MF_ENABLED); + } + else + { + EnableMenuItem(menu,IDM_EDIT_SELECT_ALL,MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(menu,IDM_EDIT_BRACKET,MF_BYCOMMAND | MF_GRAYED); + } } @@ -1055,6 +1095,13 @@ BOOL WmCommand_EditDel(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return true; } +BOOL WmCommand_EditBracket(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + SendMessage(GetPrgRes()->GetMainWindow(), WM_COMMAND, IDC_BUTTON_BRACKETS_ALL, 0); + +return true; +} + BOOL WmCommand_EditCopyResult(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -1070,6 +1117,7 @@ BOOL WmCommand_EditCopyBoth(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara unsigned int in_len = SendDlgItemMessage(hWnd, IDC_INPUT_EDIT, EM_LINELENGTH, 0, 0); unsigned int out_len = SendDlgItemMessage(hWnd, IDC_OUTPUT_EDIT, EM_LINELENGTH, 0, 0); + bool set_correct = false; HGLOBAL global = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, in_len+out_len + 20); @@ -1088,15 +1136,24 @@ BOOL WmCommand_EditCopyBoth(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara std::strcat(text, buf); GlobalUnlock(global); - SetClipboardData(CF_TEXT, global); + set_correct = SetClipboardData(CF_TEXT, global); } } CloseClipboard(); - if( global ) + /* + don't call GlobalFree(global) if SetClipboardData() returned true + + http://msdn.microsoft.com/en-us/library/ms649051%28VS.85%29.aspx + If SetClipboardData succeeds, the system owns the object identified by the hMem parameter. + The application may not write to or free the data once ownership has been transferred to + the system, but it can lock and read from the data until the CloseClipboard function is called + */ + + if( global && !set_correct ) GlobalFree(global); - + return true; } @@ -1306,7 +1363,9 @@ void CreateCommandMessagesTable(Messages & cmessages) cmessages.Associate(IDM_EDIT_CUT, WmCommand_EditCut); cmessages.Associate(IDM_EDIT_PASTE, WmCommand_EditPaste); cmessages.Associate(IDM_EDIT_DEL, WmCommand_EditDel); + cmessages.Associate(IDM_EDIT_BRACKET, WmCommand_EditBracket); cmessages.Associate(IDCANCEL, WmCommand_IDCANCEL); + cmessages.Associate(IDM_EDIT_SELECT_ALL, WmCommand_IDCANCEL); cmessages.Associate(IDM_LANGUAGE_ENGLISH, WmCommand_LanguageEnglish); cmessages.Associate(IDM_LANGUAGE_POLISH, WmCommand_LanguagePolish); cmessages.Associate(IDM_LANGUAGE_SPANISH, WmCommand_LanguageSpanish); diff --git a/src/resource.h b/src/resource.h index 891224f..abc2eff 100644 --- a/src/resource.h +++ b/src/resource.h @@ -207,11 +207,12 @@ #define IDM_EDIT_INDEX 1 #define IDM_HELP_INDEX 2 #define IDM_LANGUAGE_INDEX 8 + #define IDM_NEW_WINDOW 40001 #define IDM_NORMAL_VIEW 40002 #define IDM_COMPACT_VIEW 40003 -#define IDM_ALWAYS_ON_TOP 40004 -#define IDM_PAD 40005 +#define IDM_PAD 40004 +#define IDM_ALWAYS_ON_TOP 40005 #define IDM_LANGUAGE_ENGLISH 40010 #define IDM_LANGUAGE_POLISH 40011 #define IDM_LANGUAGE_SPANISH 40012 @@ -220,18 +221,23 @@ #define IDM_LANGUAGE_RUSSIAN 40015 #define IDM_LANGUAGE_SWEDISH 40016 #define IDM_CLOSE_PROGRAM 40020 + #define IDM_EDIT_UNDO 40030 -#define IDM_EDIT_PASTE_FORMULA 40031 -#define IDM_EDIT_COPY_RESULT 40032 -#define IDM_EDIT_COPY_BOTH 40033 -#define IDM_EDIT_COPY 40034 -#define IDM_EDIT_CUT 40035 -#define IDM_HELP_HELP 40040 -#define IDM_EDIT_PASTE 40036 -#define IDM_EDIT_DEL 40037 -#define IDM_HELP_PROJECT_PAGE 40041 -#define IDM_HELP_CHECK_UPDATE 40042 -#define IDM_HELP_ABOUT 40049 +#define IDM_EDIT_CUT 40031 +#define IDM_EDIT_COPY 40032 +#define IDM_EDIT_PASTE 40033 +#define IDM_EDIT_DEL 40034 +#define IDM_EDIT_COPY_RESULT 40035 +#define IDM_EDIT_COPY_BOTH 40036 +#define IDM_EDIT_PASTE_FORMULA 40037 +#define IDM_EDIT_SELECT_ALL 40038 +#define IDM_EDIT_BRACKET 40039 + +#define IDM_HELP_HELP 40050 +#define IDM_HELP_PROJECT_PAGE 40051 +#define IDM_HELP_CHECK_UPDATE 40052 +#define IDM_HELP_ABOUT 40053 + // pad menu #define MENUPAD_EDIT_INDEX 1 diff --git a/src/resource.rc b/src/resource.rc index 208fe7f..d0cf707 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -17,47 +17,50 @@ FIXED IMPURE LOADONCALL DISCARDABLE BEGIN POPUP "&View" BEGIN - MENUITEM "&New window", 40001 + MENUITEM "&New window", IDM_NEW_WINDOW MENUITEM SEPARATOR - MENUITEM "No&rmal", 40002 - MENUITEM "&Compact", 40003 + MENUITEM "No&rmal", IDM_NORMAL_VIEW + MENUITEM "&Compact", IDM_COMPACT_VIEW MENUITEM SEPARATOR - MENUITEM "&Pad", 40005 + MENUITEM "&Pad", IDM_PAD MENUITEM SEPARATOR - MENUITEM "&Always on top", 40004 + MENUITEM "&Always on top", IDM_ALWAYS_ON_TOP POPUP "&Language" BEGIN - MENUITEM "&English", 40010 - MENUITEM "&Polish", 40011 - MENUITEM "&Spanish", 40012 - MENUITEM "&Danish", 40013 - MENUITEM "&Chinese", 40014 - MENUITEM "&Russian", 40015 - MENUITEM "&Swedish", 40016 + MENUITEM "&English", IDM_LANGUAGE_ENGLISH + MENUITEM "&Polish", IDM_LANGUAGE_POLISH + MENUITEM "&Spanish", IDM_LANGUAGE_SPANISH + MENUITEM "&Danish", IDM_LANGUAGE_DANISH + MENUITEM "&Chinese", IDM_LANGUAGE_CHINESE + MENUITEM "&Russian", IDM_LANGUAGE_RUSSIAN + MENUITEM "&Swedish", IDM_LANGUAGE_SWEDISH END MENUITEM SEPARATOR - MENUITEM "&Close", 40020 + MENUITEM "&Close", IDM_CLOSE_PROGRAM END POPUP "&Edit" BEGIN - MENUITEM "&Undo \tCtrl+Z", 40030 + MENUITEM "&Undo \tCtrl+Z", IDM_EDIT_UNDO MENUITEM SEPARATOR - MENUITEM "&Cut \tCtrl+X", 40035 - MENUITEM "&Copy", 40034 - MENUITEM "&Paste", 40036 - MENUITEM "&Delete \tDel", 40037 + MENUITEM "&Cut \tCtrl+X", IDM_EDIT_CUT + MENUITEM "&Copy \TCtrl+C", IDM_EDIT_COPY + MENUITEM "&Paste", IDM_EDIT_PASTE + MENUITEM "&Delete \tDel", IDM_EDIT_DEL MENUITEM SEPARATOR - MENUITEM "&Copy the result\tCtrl+C", 40032 - MENUITEM "&Copy both\tCtrl+R", 40033 - MENUITEM "&Paste formula\tCtrl+V", 40031 + MENUITEM "&Copy result \tCtrl+R", IDM_EDIT_COPY_RESULT + MENUITEM "&Copy both\tCtrl+B", IDM_EDIT_COPY_BOTH + MENUITEM "&Paste formula\tCtrl+V", IDM_EDIT_PASTE_FORMULA + MENUITEM SEPARATOR + MENUITEM "&Select all \tEsc", IDM_EDIT_SELECT_ALL + MENUITEM "&Bracket \tCtrl+0", IDM_EDIT_BRACKET END POPUP "&Help" BEGIN - MENUITEM "&Help", 40040 - MENUITEM "&Project page", 40041 - MENUITEM "&Check update...", 40042 + MENUITEM "&Help", IDM_HELP_HELP + MENUITEM "&Project page", IDM_HELP_PROJECT_PAGE + MENUITEM "&Check update...", IDM_HELP_CHECK_UPDATE MENUITEM SEPARATOR - MENUITEM "&About", 40049 + MENUITEM "&About", IDM_HELP_ABOUT END END diff --git a/src/winmain.cpp b/src/winmain.cpp index 9fd985f..f8cf7c2 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -133,6 +133,10 @@ bool sent = true; switch( msg.wParam ) { case 'C': + sent = MainWindowFunctions::CopySpecial(); + break; + + case 'R': sent = MainWindowFunctions::CopyResult(); break; @@ -140,7 +144,7 @@ bool sent = true; sent = MainWindowFunctions::PasteFormula(); break; - case 'R': + case 'B': sent = SendMessage(GetPrgRes()->GetMainWindow(), WM_COMMAND, IDM_EDIT_COPY_BOTH, 0); break; diff --git a/src/winmain.h b/src/winmain.h index dbf598b..8d2637b 100644 --- a/src/winmain.h +++ b/src/winmain.h @@ -66,6 +66,7 @@ namespace MainWindowFunctions { bool SetNextFocus(WPARAM wParam); bool CopyResult(); + bool CopySpecial(); bool PasteFormula(); BOOL WmCommand_EditCopyBoth(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); void CreateMainMessagesTable(Messages & messages);