added: accelerator: ctrl+0 for (...) command

added: accelerator: ctrl+R for 'copy both' command
added: accelerator: ctrl+a for the pad window (select all)
added: on menu 'edit': cut, copy, paste, delete, copy both, paste formula
       cut, copy, paste, delete work with a window which has the focus
       'copy both' copy the input and output edits
changed: 'paste formula' is the old 'paste' command 
       (pasting to the input edit)
changed: the input edit can have 20480 characters now (previous was 2048)




git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@233 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-11-02 23:22:25 +00:00
parent f3ee187413
commit d3b0262244
12 changed files with 327 additions and 143 deletions

View File

@ -1,4 +1,4 @@
Version 0.9.0 prerelease (2009.11.01): Version 0.9.0 prerelease (2009.11.03):
* fixed: when 'C' button was pressed, the cursor was not put in the edit window * fixed: when 'C' button was pressed, the cursor was not put in the edit window
* added: Pad window - a multiline edit window * added: Pad window - a multiline edit window
* added: Checking for update dialog box * added: Checking for update dialog box

View File

@ -449,9 +449,9 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_russian, "&Russian"); InsertGuiPair(menu_view_lang_russian, "&Russian");
InsertGuiPair(menu_view_lang_swedish, "&Swedish"); InsertGuiPair(menu_view_lang_swedish, "&Swedish");
InsertGuiPair(menu_view_close_program, "&Close"); InsertGuiPair(menu_view_close_program, "&Close");
InsertGuiPair(menu_edit_undo, "&Undo"); InsertGuiPair(menu_edit_undo, "&Undo \tCtrl+Z");
InsertGuiPair(menu_edit_paste, "&Paste"); InsertGuiPair(menu_edit_paste_formula, "&Paste formula\tCtrl+V");
InsertGuiPair(menu_edit_copy_result, "&Copy the result"); InsertGuiPair(menu_edit_copy_result, "&Copy result \tCtrl+C");
InsertGuiPair(menu_help_help, "&Help"); InsertGuiPair(menu_help_help, "&Help");
InsertGuiPair(menu_help_project_page, "&Project page"); InsertGuiPair(menu_help_project_page, "&Project page");
InsertGuiPair(menu_help_about, "&About"); InsertGuiPair(menu_help_about, "&About");
@ -586,7 +586,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_swedish, "&Szwedzki"); InsertGuiPair(menu_view_lang_swedish, "&Szwedzki");
InsertGuiPair(menu_view_close_program, "&Zamknij"); InsertGuiPair(menu_view_close_program, "&Zamknij");
InsertGuiPair(menu_edit_undo, "&Cofnij"); InsertGuiPair(menu_edit_undo, "&Cofnij");
InsertGuiPair(menu_edit_paste, "&Wklej"); InsertGuiPair(menu_edit_paste_formula, "&Wklej");
InsertGuiPair(menu_edit_copy_result, "&Kopiuj wynik"); InsertGuiPair(menu_edit_copy_result, "&Kopiuj wynik");
InsertGuiPair(menu_help_help, "&Pomoc"); InsertGuiPair(menu_help_help, "&Pomoc");
InsertGuiPair(menu_help_project_page, "&Strona projektu"); InsertGuiPair(menu_help_project_page, "&Strona projektu");
@ -725,7 +725,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_swedish, "&Swedish"); InsertGuiPair(menu_view_lang_swedish, "&Swedish");
InsertGuiPair(menu_view_close_program, "&Close"); InsertGuiPair(menu_view_close_program, "&Close");
InsertGuiPair(menu_edit_undo, "&Deshacer"); InsertGuiPair(menu_edit_undo, "&Deshacer");
InsertGuiPair(menu_edit_paste, "&Pegar"); InsertGuiPair(menu_edit_paste_formula, "&Pegar");
InsertGuiPair(menu_edit_copy_result, "&Copiar resultado"); InsertGuiPair(menu_edit_copy_result, "&Copiar resultado");
InsertGuiPair(menu_help_help, "&Ayuda"); InsertGuiPair(menu_help_help, "&Ayuda");
InsertGuiPair(menu_help_project_page, "&Pagina del proyecto"); InsertGuiPair(menu_help_project_page, "&Pagina del proyecto");
@ -861,7 +861,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_swedish, "S&wedish"); InsertGuiPair(menu_view_lang_swedish, "S&wedish");
InsertGuiPair(menu_view_close_program, "&Afslut"); InsertGuiPair(menu_view_close_program, "&Afslut");
InsertGuiPair(menu_edit_undo, "&Fortryd"); InsertGuiPair(menu_edit_undo, "&Fortryd");
InsertGuiPair(menu_edit_paste, "&Sæt ind"); InsertGuiPair(menu_edit_paste_formula, "&Sæt ind");
InsertGuiPair(menu_edit_copy_result, "&Kopier resultatet"); InsertGuiPair(menu_edit_copy_result, "&Kopier resultatet");
InsertGuiPair(menu_help_help, "&Hjælp"); InsertGuiPair(menu_help_help, "&Hjælp");
InsertGuiPair(menu_help_project_page, "&Projekt side"); InsertGuiPair(menu_help_project_page, "&Projekt side");
@ -996,7 +996,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_swedish, "&Swedish"); InsertGuiPair(menu_view_lang_swedish, "&Swedish");
InsertGuiPair(menu_view_close_program, "&¹Ø±Õ"); InsertGuiPair(menu_view_close_program, "&¹Ø±Õ");
InsertGuiPair(menu_edit_undo, "&È¡Ïû"); InsertGuiPair(menu_edit_undo, "&È¡Ïû");
InsertGuiPair(menu_edit_paste, "&Õ³Ìù"); InsertGuiPair(menu_edit_paste_formula, "&Õ³Ìù");
InsertGuiPair(menu_edit_copy_result, "&¸´Öƽá¹û"); InsertGuiPair(menu_edit_copy_result, "&¸´Öƽá¹û");
InsertGuiPair(menu_help_help, "&°ïÖú"); InsertGuiPair(menu_help_help, "&°ïÖú");
InsertGuiPair(menu_help_project_page, "&Èí¼þÖ÷Ò³"); InsertGuiPair(menu_help_project_page, "&Èí¼þÖ÷Ò³");
@ -1129,7 +1129,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_swedish, "&Swedish"); InsertGuiPair(menu_view_lang_swedish, "&Swedish");
InsertGuiPair(menu_view_close_program, "&Çàêðûòü"); InsertGuiPair(menu_view_close_program, "&Çàêðûòü");
InsertGuiPair(menu_edit_undo, "&Îòìåíèòü äåéñòâèå"); InsertGuiPair(menu_edit_undo, "&Îòìåíèòü äåéñòâèå");
InsertGuiPair(menu_edit_paste, "&Âñòàâèòü"); InsertGuiPair(menu_edit_paste_formula, "&Âñòàâèòü");
InsertGuiPair(menu_edit_copy_result, "&Êîïèðîâàòü ðåçóëüòàò"); InsertGuiPair(menu_edit_copy_result, "&Êîïèðîâàòü ðåçóëüòàò");
InsertGuiPair(menu_help_help, "&Ïîìîùü"); InsertGuiPair(menu_help_help, "&Ïîìîùü");
InsertGuiPair(menu_help_project_page, "&Ñàéò ïðîåêòà"); InsertGuiPair(menu_help_project_page, "&Ñàéò ïðîåêòà");
@ -1265,7 +1265,7 @@ void Languages::InitGuiMessagesTab()
InsertGuiPair(menu_view_lang_swedish, "S&venska"); InsertGuiPair(menu_view_lang_swedish, "S&venska");
InsertGuiPair(menu_view_close_program, "&Avsluta"); InsertGuiPair(menu_view_close_program, "&Avsluta");
InsertGuiPair(menu_edit_undo, "&Ångra"); InsertGuiPair(menu_edit_undo, "&Ångra");
InsertGuiPair(menu_edit_paste, "&Klistra in"); InsertGuiPair(menu_edit_paste_formula, "&Klistra in");
InsertGuiPair(menu_edit_copy_result, "&Kopiera result"); InsertGuiPair(menu_edit_copy_result, "&Kopiera result");
InsertGuiPair(menu_help_help, "&Hjälp"); InsertGuiPair(menu_help_help, "&Hjälp");
InsertGuiPair(menu_help_project_page, "&Projektsida"); InsertGuiPair(menu_help_project_page, "&Projektsida");

View File

@ -125,7 +125,7 @@ public:
menu_view_lang_swedish, menu_view_lang_swedish,
menu_view_close_program, menu_view_close_program,
menu_edit_undo, menu_edit_undo,
menu_edit_paste, menu_edit_paste_formula,
menu_edit_copy_result, menu_edit_copy_result,
menu_help_help, menu_help_help,
menu_help_project_page, menu_help_project_page,

View File

@ -35,6 +35,7 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <cstring>
#include "compileconfig.h" #include "compileconfig.h"
#include "winmain.h" #include "winmain.h"
#include "update.h" #include "update.h"
@ -45,6 +46,45 @@ namespace MainWindowFunctions
{ {
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;
}
/*!
returning true if hWnd is a handle of an edit control
*/
bool IsEditControl(HWND hWnd)
{
char buffer[30];
GetClassName( hWnd, buffer, sizeof(buffer)/sizeof(char) );
if( EqualStrings(buffer, "edit") )
return true;
return false;
}
/*! /*!
Loop through all the controls and remove the Loop through all the controls and remove the
@ -238,103 +278,39 @@ 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 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() bool CopyResult()
{ {
char buffer[30]; HWND main_window = GetPrgRes()->GetMainWindow();
DWORD sel_start, sel_end; HWND output_edit = GetDlgItem(main_window, IDC_OUTPUT_EDIT);
HWND focus = GetFocus(); DWORD out_sel_start, out_sel_end;
bool copy = true;
GetClassName( focus, buffer, sizeof(buffer)/sizeof(char) ); // 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);
if( EqualStrings(buffer, "edit") ) // setting the selection for the whole control
{ SendMessage(output_edit, EM_SETSEL, 0, -1);
SendMessage(focus, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
if( sel_start != sel_end ) // copying the result
// the control has a selection SendMessage(output_edit, WM_COPY, 0, 0);
copy = false;
}
// and restoring the selection to the previous state
SendMessage(output_edit, EM_SETSEL, out_sel_start, out_sel_end);
if( copy ) return true;
{
// 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 this function is called when CTRL+V has been pressed
this is not Paste but PasteFormula (everything is copied to the input edit, even
if a focus is not on an edit control (or it can be on an edit if the focus is on an another 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() bool PasteFormula()
{ {
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 main_window = GetPrgRes()->GetMainWindow();
HWND input_edit = GetDlgItem(main_window, IDC_INPUT_EDIT); HWND input_edit = GetDlgItem(main_window, IDC_INPUT_EDIT);
@ -412,7 +388,7 @@ HMENU menu = GetMenu(hWnd);
SetMenuLanguageItem(menu, IDM_LANGUAGE_SWEDISH, Languages::menu_view_lang_swedish); SetMenuLanguageItem(menu, IDM_LANGUAGE_SWEDISH, Languages::menu_view_lang_swedish);
SetMenuLanguageItem(menu, IDM_CLOSE_PROGRAM, Languages::menu_view_close_program); SetMenuLanguageItem(menu, IDM_CLOSE_PROGRAM, Languages::menu_view_close_program);
SetMenuLanguageItem(menu, IDM_EDIT_UNDO, Languages::menu_edit_undo); SetMenuLanguageItem(menu, IDM_EDIT_UNDO, Languages::menu_edit_undo);
SetMenuLanguageItem(menu, IDM_EDIT_PASTE, Languages::menu_edit_paste); SetMenuLanguageItem(menu, IDM_EDIT_PASTE_FORMULA, Languages::menu_edit_paste_formula);
SetMenuLanguageItem(menu, IDM_EDIT_COPY_RESULT, Languages::menu_edit_copy_result); SetMenuLanguageItem(menu, IDM_EDIT_COPY_RESULT, Languages::menu_edit_copy_result);
SetMenuLanguageItem(menu, IDM_HELP_HELP, Languages::menu_help_help); SetMenuLanguageItem(menu, IDM_HELP_HELP, Languages::menu_help_help);
SetMenuLanguageItem(menu, IDM_HELP_PROJECT_PAGE, Languages::menu_help_project_page); SetMenuLanguageItem(menu, IDM_HELP_PROJECT_PAGE, Languages::menu_help_project_page);
@ -814,28 +790,79 @@ void WmInitMenuPopUpView(HMENU menu)
void WmInitMenuPopUpEdit(HWND hWnd, HMENU menu) void WmInitMenuPopUpEdit(HWND hWnd, HMENU menu)
{ {
char buffer[5]; bool edit = false; // an edit control has the focus
bool edit_sel = false; // there is something selected on the edit
bool edit_readonly = false; // the edit is read only
bool can_undo = false;
bool can_undo = SendDlgItemMessage(hWnd, IDC_INPUT_EDIT, EM_CANUNDO, 0 ,0); HWND focus = GetFocus();
edit = IsEditControl(focus);
if( can_undo ) if( edit )
{
DWORD sel_start, sel_end;
SendMessage(focus, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
if( sel_start != sel_end )
edit_sel = true;
if( (GetWindowLong(focus, GWL_STYLE) & ES_READONLY) != 0 )
edit_readonly = true;
}
// undo
if( edit && !edit_readonly && SendMessage(focus, EM_CANUNDO, 0 ,0) )
EnableMenuItem(menu,IDM_EDIT_UNDO,MF_BYCOMMAND | MF_ENABLED); EnableMenuItem(menu,IDM_EDIT_UNDO,MF_BYCOMMAND | MF_ENABLED);
else else
EnableMenuItem(menu,IDM_EDIT_UNDO,MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(menu,IDM_EDIT_UNDO,MF_BYCOMMAND | MF_GRAYED);
// cut
if( edit && edit_sel && !edit_readonly )
EnableMenuItem(menu,IDM_EDIT_CUT,MF_BYCOMMAND | MF_ENABLED);
else
EnableMenuItem(menu,IDM_EDIT_CUT,MF_BYCOMMAND | MF_GRAYED);
if( IsClipboardFormatAvailable(CF_TEXT) ) // paste
if( edit && !edit_readonly )
EnableMenuItem(menu,IDM_EDIT_PASTE,MF_BYCOMMAND | MF_ENABLED); EnableMenuItem(menu,IDM_EDIT_PASTE,MF_BYCOMMAND | MF_ENABLED);
else else
EnableMenuItem(menu,IDM_EDIT_PASTE,MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(menu,IDM_EDIT_PASTE,MF_BYCOMMAND | MF_GRAYED);
// del
GetDlgItemText(hWnd,IDC_OUTPUT_EDIT,buffer,sizeof(buffer)); if( edit && edit_sel && !edit_readonly )
EnableMenuItem(menu,IDM_EDIT_DEL,MF_BYCOMMAND | MF_ENABLED);
if( buffer[0] == 0 )
EnableMenuItem(menu,IDM_EDIT_COPY_RESULT,MF_BYCOMMAND | MF_GRAYED);
else else
EnableMenuItem(menu,IDM_EDIT_DEL,MF_BYCOMMAND | MF_GRAYED);
// copy
if( edit && edit_sel )
EnableMenuItem(menu,IDM_EDIT_COPY,MF_BYCOMMAND | MF_ENABLED);
else
EnableMenuItem(menu,IDM_EDIT_COPY,MF_BYCOMMAND | MF_GRAYED);
// copy result
int input_size = SendDlgItemMessage(hWnd, IDC_INPUT_EDIT, EM_LINELENGTH, 0, 0);
int output_size = SendDlgItemMessage(hWnd, IDC_OUTPUT_EDIT, EM_LINELENGTH, 0, 0);
if( output_size != 0 )
EnableMenuItem(menu,IDM_EDIT_COPY_RESULT,MF_BYCOMMAND | MF_ENABLED); EnableMenuItem(menu,IDM_EDIT_COPY_RESULT,MF_BYCOMMAND | MF_ENABLED);
else
EnableMenuItem(menu,IDM_EDIT_COPY_RESULT,MF_BYCOMMAND | MF_GRAYED);
// copy both
if( input_size!=0 || output_size!=0 )
EnableMenuItem(menu,IDM_EDIT_COPY_BOTH,MF_BYCOMMAND | MF_ENABLED);
else
EnableMenuItem(menu,IDM_EDIT_COPY_BOTH,MF_BYCOMMAND | MF_GRAYED);
// paste formula
if( IsClipboardFormatAvailable(CF_TEXT) )
EnableMenuItem(menu,IDM_EDIT_PASTE_FORMULA,MF_BYCOMMAND | MF_ENABLED);
else
EnableMenuItem(menu,IDM_EDIT_PASTE_FORMULA,MF_BYCOMMAND | MF_GRAYED);
} }
@ -976,14 +1003,54 @@ return true;
BOOL WmCommand_EditUndo(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) BOOL WmCommand_EditUndo(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
SendDlgItemMessage(hWnd, IDC_INPUT_EDIT, EM_UNDO, 0, 0); HWND focus = GetFocus();
SendMessage(focus, EM_UNDO, 0, 0);
return true;
}
BOOL WmCommand_EditPasteFormula(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND input_edit = GetDlgItem(hWnd, IDC_INPUT_EDIT);
SendMessage(input_edit, WM_PASTE, 0, 0);
SetFocus(input_edit);
return true;
}
BOOL WmCommand_EditCopy(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND focus = GetFocus();
SendMessage(focus, WM_COPY, 0, 0);
return true;
}
BOOL WmCommand_EditCut(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND focus = GetFocus();
SendMessage(focus, WM_CUT, 0, 0);
return true; return true;
} }
BOOL WmCommand_EditPaste(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) BOOL WmCommand_EditPaste(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
SendDlgItemMessage(hWnd, IDC_INPUT_EDIT, WM_PASTE, 0, 0); HWND focus = GetFocus();
SendMessage(focus, WM_PASTE, 0, 0);
return true;
}
BOOL WmCommand_EditDel(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND focus = GetFocus();
if( IsEditControl(focus) )
SendMessage(focus, EM_REPLACESEL, 1, (LPARAM)"");
return true; return true;
} }
@ -991,13 +1058,48 @@ return true;
BOOL WmCommand_EditCopyResult(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) BOOL WmCommand_EditCopyResult(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
SendDlgItemMessage(hWnd, IDC_OUTPUT_EDIT, EM_SETSEL, 0, LPARAM(-1)); CopyResult();
SendDlgItemMessage(hWnd, IDC_OUTPUT_EDIT, WM_COPY, 0, 0);
SendDlgItemMessage(hWnd, IDC_OUTPUT_EDIT, EM_SETSEL, WPARAM(-1), 0);
return true; return true;
} }
BOOL WmCommand_EditCopyBoth(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if( !OpenClipboard(hWnd) )
return true;
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);
HGLOBAL global = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, in_len+out_len + 20);
if( global )
{
char * text = (char*)GlobalLock(global);
if( text )
{
char * buf = GetPrgRes()->GetBufferTemp();
SendDlgItemMessage(hWnd, IDC_INPUT_EDIT, EM_GETLINE, 0, (LPARAM)buf);
sprintf(text, "%s = ", buf);
SendDlgItemMessage(hWnd, IDC_OUTPUT_EDIT, EM_GETLINE, 0, (LPARAM)buf);
std::strcat(text, buf);
GlobalUnlock(global);
SetClipboardData(CF_TEXT, global);
}
}
CloseClipboard();
if( global )
GlobalFree(global);
return true;
}
/*! /*!
an user has pressed 'ESC' key in the main window an user has pressed 'ESC' key in the main window
@ -1197,8 +1299,13 @@ void CreateCommandMessagesTable(Messages<BOOL> & cmessages)
cmessages.Associate(IDM_CLOSE_PROGRAM, WmCommand_CloseProgram); cmessages.Associate(IDM_CLOSE_PROGRAM, WmCommand_CloseProgram);
cmessages.Associate(IDC_INPUT_EDIT, WmCommand_InputEditNotify); cmessages.Associate(IDC_INPUT_EDIT, WmCommand_InputEditNotify);
cmessages.Associate(IDM_EDIT_UNDO, WmCommand_EditUndo); cmessages.Associate(IDM_EDIT_UNDO, WmCommand_EditUndo);
cmessages.Associate(IDM_EDIT_PASTE, WmCommand_EditPaste); cmessages.Associate(IDM_EDIT_PASTE_FORMULA, WmCommand_EditPasteFormula);
cmessages.Associate(IDM_EDIT_COPY_RESULT, WmCommand_EditCopyResult); cmessages.Associate(IDM_EDIT_COPY_RESULT, WmCommand_EditCopyResult);
cmessages.Associate(IDM_EDIT_COPY_BOTH, WmCommand_EditCopyBoth);
cmessages.Associate(IDM_EDIT_COPY, WmCommand_EditCopy);
cmessages.Associate(IDM_EDIT_CUT, WmCommand_EditCut);
cmessages.Associate(IDM_EDIT_PASTE, WmCommand_EditPaste);
cmessages.Associate(IDM_EDIT_DEL, WmCommand_EditDel);
cmessages.Associate(IDCANCEL, WmCommand_IDCANCEL); cmessages.Associate(IDCANCEL, WmCommand_IDCANCEL);
cmessages.Associate(IDM_LANGUAGE_ENGLISH, WmCommand_LanguageEnglish); cmessages.Associate(IDM_LANGUAGE_ENGLISH, WmCommand_LanguageEnglish);
cmessages.Associate(IDM_LANGUAGE_POLISH, WmCommand_LanguagePolish); cmessages.Associate(IDM_LANGUAGE_POLISH, WmCommand_LanguagePolish);

View File

@ -339,6 +339,8 @@ LRESULT PadCreate(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if( !edit ) if( !edit )
return 0; return 0;
GetPrgRes()->SetPadEdit(edit);
old_edit_proc = (WNDPROC)SetWindowLong(edit, GWL_WNDPROC, (LONG)EditSubclass); old_edit_proc = (WNDPROC)SetWindowLong(edit, GWL_WNDPROC, (LONG)EditSubclass);
// 65535 - 64KB // 65535 - 64KB

View File

@ -42,7 +42,7 @@
ParserManager::ParserManager() : buffer_len(2048) ParserManager::ParserManager() : buffer_len(20480)
{ {
buffer = 0; buffer = 0;
base_input = base_output = 10; base_input = base_output = 10;

View File

@ -461,6 +461,16 @@ HWND ProgramResources::GetPadWindow()
return pad_window; return pad_window;
} }
void ProgramResources::SetPadEdit(HWND h)
{
pad_edit = h;
}
HWND ProgramResources::GetPadEdit()
{
return pad_edit;
}
void ProgramResources::SetTabWindow(unsigned int id, HWND h) void ProgramResources::SetTabWindow(unsigned int id, HWND h)
{ {
if( id >= sizeof(tab_window) / sizeof(HWND) ) if( id >= sizeof(tab_window) / sizeof(HWND) )
@ -487,6 +497,11 @@ char * ProgramResources::GetBuffer()
return buffer; return buffer;
} }
char * ProgramResources::GetBufferTemp()
{
return buffer_temp;
}
unsigned int ProgramResources::GetBufferSize() unsigned int ProgramResources::GetBufferSize()
{ {
return buffer_size; return buffer_size;
@ -559,16 +574,17 @@ int ProgramResources::GetParamSep()
} }
ProgramResources::ProgramResources() ProgramResources::ProgramResources()
{ {
// if you want to change the input buffer you have also to change // if you want to change the input buffer you have also to change
// ParserManager::ParserManager() : buffer_len(2048) in parsermanager.cpp // ParserManager::ParserManager() : buffer_len(2048) in parsermanager.cpp
buffer_size = 2048; buffer_size = 20480;
buffer = new char[buffer_size]; buffer = new char[buffer_size];
buffer[0] = 0; buffer[0] = 0;
buffer_temp = new char[buffer_size];
buffer_temp[0] = 0;
always_on_top = false; always_on_top = false;
view = view_normal; view = view_normal;
@ -579,6 +595,8 @@ ProgramResources::ProgramResources()
hInstance = 0; hInstance = 0;
main_window = 0; main_window = 0;
pad_window = 0;
pad_edit = 0;
base_input = 10; base_input = 10;
base_output = 10; base_output = 10;
@ -628,6 +646,7 @@ ProgramResources::ProgramResources()
ProgramResources::~ProgramResources() ProgramResources::~ProgramResources()
{ {
delete [] buffer; delete [] buffer;
delete [] buffer_temp;
} }

View File

@ -221,6 +221,9 @@ public:
void SetPadWindow(HWND h); void SetPadWindow(HWND h);
HWND GetPadWindow(); HWND GetPadWindow();
void SetPadEdit(HWND h);
HWND GetPadEdit();
/*! /*!
handles to the dialogs which are placed on the tab control handles to the dialogs which are placed on the tab control
*/ */
@ -284,6 +287,7 @@ public:
Languages * GetLanguages(); Languages * GetLanguages();
Convert * GetConvert(); Convert * GetConvert();
char * GetBuffer(); char * GetBuffer();
char * GetBufferTemp(); // this buffer can be used for temporary tasks
unsigned int GetBufferSize(); unsigned int GetBufferSize();
@ -439,10 +443,12 @@ private:
unsigned int buffer_size; unsigned int buffer_size;
char * buffer; char * buffer;
char * buffer_temp;
HINSTANCE hInstance; HINSTANCE hInstance;
HWND main_window; HWND main_window;
HWND pad_window; HWND pad_window;
HWND pad_edit; // edit control on the pad window
HWND tab_window[6]; HWND tab_window[6];
int precision; int precision;

View File

@ -221,9 +221,14 @@
#define IDM_LANGUAGE_SWEDISH 40016 #define IDM_LANGUAGE_SWEDISH 40016
#define IDM_CLOSE_PROGRAM 40020 #define IDM_CLOSE_PROGRAM 40020
#define IDM_EDIT_UNDO 40030 #define IDM_EDIT_UNDO 40030
#define IDM_EDIT_PASTE 40031 #define IDM_EDIT_PASTE_FORMULA 40031
#define IDM_EDIT_COPY_RESULT 40032 #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_HELP_HELP 40040
#define IDM_EDIT_PASTE 40036
#define IDM_EDIT_DEL 40037
#define IDM_HELP_PROJECT_PAGE 40041 #define IDM_HELP_PROJECT_PAGE 40041
#define IDM_HELP_CHECK_UPDATE 40042 #define IDM_HELP_CHECK_UPDATE 40042
#define IDM_HELP_ABOUT 40049 #define IDM_HELP_ABOUT 40049

View File

@ -40,9 +40,16 @@ BEGIN
END END
POPUP "&Edit" POPUP "&Edit"
BEGIN BEGIN
MENUITEM "&Undo", 40030 MENUITEM "&Undo \tCtrl+Z", 40030
MENUITEM "&Paste", 40031 MENUITEM SEPARATOR
MENUITEM "&Copy the result", 40032 MENUITEM "&Cut \tCtrl+X", 40035
MENUITEM "&Copy", 40034
MENUITEM "&Paste", 40036
MENUITEM "&Delete \tDel", 40037
MENUITEM SEPARATOR
MENUITEM "&Copy the result\tCtrl+C", 40032
MENUITEM "&Copy both\tCtrl+R", 40033
MENUITEM "&Paste formula\tCtrl+V", 40031
END END
POPUP "&Help" POPUP "&Help"
BEGIN BEGIN
@ -61,21 +68,21 @@ BEGIN
BEGIN BEGIN
// MENUITEM "New", MENUPAD_FILE_NEW // MENUITEM "New", MENUPAD_FILE_NEW
// temporarily this option is not available // temporarily this option is not available
MENUITEM "Open...", MENUPAD_FILE_OPEN MENUITEM "Open...", MENUPAD_FILE_OPEN
MENUITEM "Save as...", MENUPAD_FILE_SAVE MENUITEM "Save as...", MENUPAD_FILE_SAVE
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Close", MENUPAD_FILE_CLOSE MENUITEM "Close", MENUPAD_FILE_CLOSE
END END
POPUP "Edit" POPUP "Edit"
BEGIN BEGIN
MENUITEM "Undo", MENUPAD_EDIT_UNDO MENUITEM "Undo \tCtrl+Z", MENUPAD_EDIT_UNDO
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Cut", MENUPAD_EDIT_CUT MENUITEM "Cut \tCtrl+X", MENUPAD_EDIT_CUT
MENUITEM "Copy", MENUPAD_EDIT_COPY MENUITEM "Copy \tCtrl+C", MENUPAD_EDIT_COPY
MENUITEM "Paste", MENUPAD_EDIT_PASTE MENUITEM "Paste \tCtrl+V", MENUPAD_EDIT_PASTE
MENUITEM "Delete", MENUPAD_EDIT_DEL MENUITEM "Delete \tDel", MENUPAD_EDIT_DEL
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "Select all", MENUPAD_EDIT_SELECTALL MENUITEM "Select all \tCtrl+A", MENUPAD_EDIT_SELECTALL
END END
END END

View File

@ -126,29 +126,66 @@ return static_cast<int>( error_code );
} }
bool AcceleratorForMainWindow(MSG & msg)
{
bool sent = true;
switch( msg.wParam )
{
case 'C':
sent = MainWindowFunctions::CopyResult();
break;
case 'V':
sent = MainWindowFunctions::PasteFormula();
break;
case 'R':
sent = SendMessage(GetPrgRes()->GetMainWindow(), WM_COMMAND, IDM_EDIT_COPY_BOTH, 0);
break;
case '0':
SendMessage(GetPrgRes()->GetMainWindow(), WM_COMMAND, IDC_BUTTON_BRACKETS_ALL, 0);
break;
default:
sent = false;
}
return sent;
}
bool AcceleratorForPadEdit(MSG & msg)
{
if( msg.wParam == 'A' )
{
SendMessage(GetPrgRes()->GetPadWindow(), WM_COMMAND, MENUPAD_EDIT_SELECTALL, 0);
return true;
}
return false;
}
bool CheckAcceleratorKeys(MSG & msg)
{
if( msg.message != WM_KEYDOWN )
return false;
if( (GetKeyState(VK_CONTROL) & 0xff00) == 0 )
return false;
if( msg.hwnd == GetPrgRes()->GetPadEdit() )
return AcceleratorForPadEdit(msg);
return AcceleratorForMainWindow(msg);
}
void SendMessage(MSG & msg) void SendMessage(MSG & msg)
{ {
bool sent = false; bool sent = CheckAcceleratorKeys(msg);
// 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 // we give our own special function for navigating from the keyboard
// if our function returns false then we use a standard navigation // if our function returns false then we use a standard navigation

View File

@ -66,7 +66,8 @@ namespace MainWindowFunctions
{ {
bool SetNextFocus(WPARAM wParam); bool SetNextFocus(WPARAM wParam);
bool CopyResult(); bool CopyResult();
bool Paste(); bool PasteFormula();
BOOL WmCommand_EditCopyBoth(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void CreateMainMessagesTable(Messages<BOOL> & messages); void CreateMainMessagesTable(Messages<BOOL> & messages);
BOOL CALLBACK AboutProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); BOOL CALLBACK AboutProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
} }