Commit c116a9b5 authored by CHARRAS's avatar CHARRAS
Browse files

first version of programmable hotkeys (work in progress)

parent 88dec9cd
Loading
Loading
Loading
Loading

bitmaps/Reload.xpm

0 → 100644
+134 −0
Original line number Diff line number Diff line
/* XPM */
#ifndef XPMMAIN
extern char * reload_xpm[];

#else
char * reload_xpm[] = {
"16 16 110 2",
"  	c None",
". 	c #000000",
"+ 	c #766B3F",
"@ 	c #F7F8FA",
"# 	c #CBDDEB",
"$ 	c #5D5332",
"% 	c #EFE5BA",
"& 	c #7A7A7A",
"* 	c #E9E9E9",
"= 	c #EAEAEA",
"- 	c #F1F1F1",
"; 	c #BFD5E8",
"> 	c #DCE5E8",
", 	c #5A5230",
"' 	c #EEE5BB",
") 	c #EED680",
"! 	c #231F13",
"~ 	c #2A2516",
"{ 	c #12100A",
"] 	c #707070",
"^ 	c #ABABAB",
"/ 	c #C0C0C0",
"( 	c #E0E0E0",
"_ 	c #8DA9BE",
": 	c #54697C",
"< 	c #574F2E",
"[ 	c #EFE4B6",
"} 	c #CCB76D",
"| 	c #96864F",
"1 	c #636363",
"2 	c #FEFEFE",
"3 	c #F9F9F9",
"4 	c #84A0B5",
"5 	c #4F6475",
"6 	c #4B4428",
"7 	c #EEE2B2",
"8 	c #AF9D5D",
"9 	c #919191",
"0 	c #819AAE",
"a 	c #496072",
"b 	c #494227",
"c 	c #8F6406",
"d 	c #D1940C",
"e 	c #D7A328",
"f 	c #DEB446",
"g 	c #A49357",
"h 	c #CFCFCF",
"i 	c #302C19",
"j 	c #765204",
"k 	c #9E7009",
"l 	c #D9AA35",
"m 	c #909090",
"n 	c #666E75",
"o 	c #272315",
"p 	c #986B07",
"q 	c #737373",
"r 	c #5C4003",
"s 	c #B07D0A",
"t 	c #767676",
"u 	c #CFE0ED",
"v 	c #6C7E87",
"w 	c #1E1A0F",
"x 	c #896611",
"y 	c #676D73",
"z 	c #54595E",
"A 	c #986B08",
"B 	c #57626A",
"C 	c #6B7C85",
"D 	c #221E11",
"E 	c #0B0B06",
"F 	c #576876",
"G 	c #AE9141",
"H 	c #847645",
"I 	c #8CA8BD",
"J 	c #8E96A0",
"K 	c #616161",
"L 	c #C5C5C5",
"M 	c #CECECE",
"N 	c #E0C978",
"O 	c #131D24",
"P 	c #A0A8AF",
"Q 	c #183042",
"R 	c #C9B46B",
"S 	c #817444",
"T 	c #0E222D",
"U 	c #586D80",
"V 	c #97A5B0",
"W 	c #86A4B9",
"X 	c #CDCDCD",
"Y 	c #AE9C5C",
"Z 	c #626262",
"` 	c #112835",
" .	c #5A7082",
"..	c #9DA9B0",
"+.	c #6B7882",
"@.	c #839EB2",
"#.	c #E6E6E6",
"$.	c #213648",
"%.	c #666666",
"&.	c #8D8D8D",
"*.	c #112C3A",
"=.	c #9FA9B0",
"-.	c #59636D",
";.	c #A1A1A1",
">.	c #868686",
",.	c #6E6E6E",
"'.	c #2D3949",
").	c #3E4F5C",
"!.	c #80878F",
"~.	c #1A3140",
"  . . . + . . . . . . . . . .   ",
". @ # $ % . & * * * = * - ; ; . ",
". > , ' ) . ! ~ { ] ^ / ( _ : . ",
". < [ ) ) ) ) } | . 1 2 3 4 5 . ",
"6 7 ) ) ) ) ) ) ) 8 . 9 - 0 a . ",
"b c d d d d d e f ) g . h 0 a . ",
". i c d d . . j k l } . m 0 a . ",
". n o p d . q . r s ) . t 0 a . ",
". u v w x . y z . A ) . B 0 a . ",
". u _ C D E F 0 . G H . 0 0 a . ",
". u _ I J K L M . N . O P 0 a . ",
". u _ 4 L L Q . R S . T U V a . ",
". u W 0 L X . Y | . Z `  ...a . ",
". +.@.0 X #.$.. . %.&.*. .=.a . ",
"  . -.5 ;./ m m >.,.& '.).!.~.. ",
"    . . . . . . . . . . . . .   "};
#endif
+6 −0
Original line number Diff line number Diff line
@@ -4,6 +4,12 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with 
email address.

2007-aug-21 UPDATE   Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+ eeschema & pcbnew
	First version of programmable hotkeys by editing hotkey configuration files.
	some hotkeys are not programmable (Zoom)(work in progress)


2007-Aug-21 UPDATE   Dick Hollenbeck <dick@softplc.com>
================================================================================
+6 −7
Original line number Diff line number Diff line
@@ -27,10 +27,9 @@ wxString HOSTNAME( wxT( "localhost" ) );

/* variables locales */

// buffers for read and write data in socket connections
// buffer for read and write data in socket connections
#define IPC_BUF_SIZE 4096
static char      client_ipc_buffer[IPC_BUF_SIZE];
static char      server_ipc_buffer[IPC_BUF_SIZE];

static wxServer* server;

@@ -80,15 +79,15 @@ void WinEDA_DrawFrame::OnSockRequest( wxSocketEvent& evt )
    switch( evt.GetSocketEvent() )
    {
    case wxSOCKET_INPUT:
        sock->Read( server_ipc_buffer, 1 );
        sock->Read( client_ipc_buffer, 1 );
        if( sock->LastCount() == 0 )
            break;                          // No data: Occurs on open connection
            break;                          // No data: Occurs on opening connection
        
        sock->Read( server_ipc_buffer + 1, IPC_BUF_SIZE - 2 );
        sock->Read( client_ipc_buffer + 1, IPC_BUF_SIZE - 2 );
        len = 1 + sock->LastCount();
        server_ipc_buffer[len] = 0;
        client_ipc_buffer[len] = 0;
        if( RemoteFct )
            RemoteFct( server_ipc_buffer );
            RemoteFct( client_ipc_buffer );
        break;

    case wxSOCKET_LOST:
+306 −64
Original line number Diff line number Diff line
@@ -6,7 +6,9 @@
*/
#include "fctsys.h"
#include "common.h"
#include "wxstruct.h"
#include "hotkeys_basic.h"
#include "macros.h"

/* Class to handle hotkey commnands. hotkeys have a default value
This class allows (for the future..) the real key code changed by user(from a key code list file, TODO)
@@ -19,6 +21,100 @@ Ki_HotkeyInfo::Ki_HotkeyInfo(const wxChar * infomsg, int idcommand, int keycode)
	m_Idcommand = idcommand;	// internal id for the corresponding command (see hotkey_id_commnand list)
}

/* class to handle the printable name and the keycode
*/
struct hotkey_name_descr {
	wxChar * m_Name;
	int m_KeyCode;
};

struct hotkey_name_descr s_Notkey_Name_List[] = {
	{wxT("F1"), WXK_F1},
	{wxT("F2"), WXK_F2},
	{wxT("F3"), WXK_F3},
	{wxT("F4"), WXK_F4},
	{wxT("F5"), WXK_F5},
	{wxT("F6"), WXK_F6},
	{wxT("F7"), WXK_F7},
	{wxT("F8"), WXK_F8},
	{wxT("F9"), WXK_F9},
	{wxT("F10"), WXK_F10},
	{wxT("F11"), WXK_F11},
	{wxT("F12"), WXK_F12},

	{wxT("Esc"), WXK_ESCAPE},
	{wxT("Delete"), WXK_DELETE},
	{wxT("Esc"), WXK_ESCAPE},
	{wxT("Tab"), '\t'},
	{wxT("Backspace"), WXK_BACK},
	{wxT("Insert"), WXK_INSERT},

	{wxT("End"), WXK_END},
	{wxT("Page Up"), WXK_PAGEUP},
	{wxT("Page Down"), WXK_PAGEDOWN},
	{wxT("+"), WXK_ADD},
	{wxT("-"), WXK_SUBTRACT},

	{wxT("space"), ' '},
	{wxT("?"), '?'},
	{wxT("A"), 'A'},
	{wxT("B"), 'B'},
	{wxT("C"), 'C'},
	{wxT("D"), 'D'},
	{wxT("E"), 'E'},
	{wxT("F"), 'F'},
	{wxT("G"), 'G'},
	{wxT("H"), 'H'},
	{wxT("I"), 'I'},
	{wxT("J"), 'J'},
	{wxT("K"), 'K'},
	{wxT("L"), 'L'},
	{wxT("M"), 'M'},
	{wxT("N"), 'N'},
	{wxT("O"), 'O'},
	{wxT("P"), 'P'},
	{wxT("Q"), 'Q'},
	{wxT("R"), 'R'},
	{wxT("S"), 'S'},
	{wxT("T"), 'T'},
	{wxT("U"), 'U'},
	{wxT("V"), 'V'},
	{wxT("W"), 'W'},
	{wxT("X"), 'X'},
	{wxT("Y"), 'Y'},
	{wxT("Z"), 'Z'},

	{wxT("Ctrl A"), GR_KB_CTRL + 'A'},
	{wxT("Ctrl B"), GR_KB_CTRL + 'B'},
	{wxT("Ctrl C"), GR_KB_CTRL + 'C'},
	{wxT("Ctrl D"), GR_KB_CTRL + 'D'},
	{wxT("Ctrl E"), GR_KB_CTRL + 'E'},
	{wxT("Ctrl F"), GR_KB_CTRL + 'F'},
	{wxT("Ctrl G"), GR_KB_CTRL + 'G'},
	{wxT("Ctrl H"), GR_KB_CTRL + 'H'},
	{wxT("Ctrl I"), GR_KB_CTRL + 'I'},
	{wxT("Ctrl J"), GR_KB_CTRL + 'J'},
	{wxT("Ctrl K"), GR_KB_CTRL + 'K'},
	{wxT("Ctrl L"), GR_KB_CTRL + 'L'},
	{wxT("Ctrl M"), GR_KB_CTRL + 'M'},
	{wxT("Ctrl N"), GR_KB_CTRL + 'N'},
	{wxT("Ctrl O"), GR_KB_CTRL + 'O'},
	{wxT("Ctrl P"), GR_KB_CTRL + 'P'},
	{wxT("Ctrl Q"), GR_KB_CTRL + 'Q'},
	{wxT("Ctrl R"), GR_KB_CTRL + 'R'},
	{wxT("Ctrl S"), GR_KB_CTRL + 'S'},
	{wxT("Ctrl T"), GR_KB_CTRL + 'T'},
	{wxT("Ctrl U"), GR_KB_CTRL + 'U'},
	{wxT("Ctrl V"), GR_KB_CTRL + 'V'},
	{wxT("Ctrl W"), GR_KB_CTRL + 'W'},
	{wxT("Ctrl X"), GR_KB_CTRL + 'X'},
	{wxT("Ctrl Y"), GR_KB_CTRL + 'Y'},
	{wxT("Ctrl Z"), GR_KB_CTRL + 'Z'},

	{wxT(""), 0}		// Do not change: end of list
};


/****************************************************/
wxString ReturnKeyNameFromKeyCode(int keycode)
/****************************************************/
@@ -30,81 +126,54 @@ wxString ReturnKeyNameFromKeyCode(int keycode)
*/
{
wxString keyname, modifier, fullkeyname;
int ii;

	if ( (keycode & GR_KB_CTRL) != 0 ) modifier << wxT("Ctrl ");
	if ( (keycode & GR_KB_ALT) != 0 ) modifier << wxT("Alt ");
	if ( (keycode & GR_KB_SHIFT) != 0 ) modifier << wxT("Shift ");

	switch ( keycode)
	{
		default:
	keycode &= ~(GR_KB_CTRL|GR_KB_ALT|GR_KB_SHIFT);
			keyname.Printf(wxT("%c"), keycode);
			break;
		
		case WXK_ESCAPE:
			keyname = wxT("Esc");
			break;

		case WXK_F1:
		case WXK_F2:
		case WXK_F3:
		case WXK_F4:
		case WXK_F5:
		case WXK_F6:
		case WXK_F7:
		case WXK_F8:
		case WXK_F9:
		case WXK_F10:
		case WXK_F11:
		case WXK_F12:
			keyname.Printf(wxT("F%d"), keycode - WXK_F1 + 1);
			break;
			
		case ' ':
			keyname = wxT("space");
			break;

		case '\t':
			keyname = wxT("Tab");
			break;

		case WXK_DELETE:
			keyname = wxT("Delete");
			break;

		case WXK_BACK:
			keyname = wxT("Backspace");
			break;

		case WXK_INSERT:
			keyname = wxT("Insert");
			break;

		case WXK_END:
			keyname = wxT("End");
	for ( ii = 0; ; ii++)
	{
		if ( s_Notkey_Name_List[ii].m_KeyCode == 0 )
		{
			keyname = wxT("<unknown>");
			break;
		
		case WXK_PAGEUP:
			keyname = wxT("Page Up");
		}
		if ( s_Notkey_Name_List[ii].m_KeyCode == keycode)
		{
			keyname = s_Notkey_Name_List[ii].m_Name;
			break;
		}
	}
	
		case WXK_PAGEDOWN:
			keyname = wxT("Page Down");
			break;
	fullkeyname = modifier + keyname;
	return fullkeyname;
}

		case WXK_ADD:
			keyname = wxT("+");
			break;
/************************************************************/
static int ReturnKeyCodeFromKeyName(const wxString & keyname)
/************************************************************/
/*
	* return the key code from its key name
	* Only some wxWidgets key values are handled for function key
	* @param keyname = wxString key name to find in s_Notkey_Name_List[]
	* @return the key code
*/
{
int ii, keycode = 0;

		case WXK_SUBTRACT:
			keyname = wxT("-");
	for ( ii = 0; ; ii++)
	{
		if ( s_Notkey_Name_List[ii].m_KeyCode == 0 ) break;
		if ( s_Notkey_Name_List[ii].m_Name == keyname)
		{
			keycode = s_Notkey_Name_List[ii].m_KeyCode;
			break;
		
		}
	}
	
	fullkeyname = modifier + keyname;
	return fullkeyname;
	return keycode;
}

/****************************************************************************/
@@ -123,7 +192,6 @@ wxString keyname;
	for ( ; * List != NULL; List++ )
	{
		Ki_HotkeyInfo * hk_decr = * List;
		if ( hk_decr->m_InfoMsg.IsEmpty() ) break;
		msg += _("key ");
		keyname = ReturnKeyNameFromKeyCode(hk_decr->m_KeyCode);
		msg += keyname + wxT(":    ") + hk_decr->m_InfoMsg + wxT("\n");
@@ -150,3 +218,177 @@ int GetCommandCodeFromHotkey(int key, Ki_HotkeyInfo ** List)
	return 0;
}

/*************************************************************************/
int WinEDA_BasicFrame::WriteHotkeyConfigFile(const wxString & Filename,
		Ki_HotkeyInfo ** List, bool verbose)
/*************************************************************************/
/*
 * Create a configuration file (*.key) from the current hotkey list
 * @param Filename = default full file name to create. If void, A filename will be asked
 * @param List = pointer to the current hotkey list.
 * the ouput format is: shortcut  "key"  "function"
 * lines starting by # are comments
 * 
*/
{
	wxString FullFilename = Filename;
	FILE * cfgfile;
	wxString msg;
	if ( FullFilename.IsEmpty() || verbose)
	{
		wxString Mask, Path, Ext;
		Ext = DEFAULT_HOTKEY_FILENAME_EXT;
		Mask = wxT("*") + Ext;
		Path = DEFAULT_HOTKEY_FILENAME_PATH;
		FullFilename = EDA_FileSelector( _("Hotkey configuration file:"),
						Path,				/* Chemin par defaut */
						FullFilename,		/* nom fichier par defaut */
						Ext,				/* extension par defaut */
						Mask,				/* Masque d'affichage */
						this,
						wxFD_SAVE,
						TRUE
						);
	}
	if ( FullFilename.IsEmpty() ) return 0;
	
	cfgfile = wxFopen(FullFilename, wxT("wt"));
	
	if ( cfgfile == NULL )
	{
		if ( verbose )
		{
			msg = _("Unable to create ") + FullFilename;
			DisplayError(this, msg);
		}
		return 0;
	}
	
wxString keyname, infokey;
	
	msg = wxT("$hotkey list\n");
	fprintf(cfgfile, CONV_TO_UTF8(msg));
	
	/* print the allowed keys, for info
	*/
	msg = wxT("# "); msg += _("Allowed keys:\n");
	fprintf(cfgfile, CONV_TO_UTF8(msg));
	msg.Empty();
	for ( int ii = 0; ; ii ++ )
	{
		if ( s_Notkey_Name_List[ii].m_KeyCode == 0 ) break;;
		if ( msg.IsEmpty() ) msg = wxT("# ");
		else msg +=  wxT(", ");
		msg += s_Notkey_Name_List[ii].m_Name;
		if ( msg.Len() > 60 )
		{
			msg += wxT("\n");
			fprintf(cfgfile, CONV_TO_UTF8(msg));
			msg.Empty();
		}
	}
	/* print the last line */
	if ( ! msg.IsEmpty() ) msg += wxT("\n");
	msg += wxT("#\n#\n");
	fprintf(cfgfile, CONV_TO_UTF8(msg));
	
	/* Print the current list */
	for ( ; * List != NULL; List++ )
	{
		Ki_HotkeyInfo * hk_decr = * List;
		msg = wxT("shortcut   ");
		keyname = ReturnKeyNameFromKeyCode(hk_decr->m_KeyCode);
		AddDelimiterString( keyname );
		infokey = hk_decr->m_InfoMsg;
		AddDelimiterString( infokey );
		msg += keyname + wxT(":    ") + infokey + wxT("\n");
		fprintf(cfgfile, CONV_TO_UTF8(msg));
	}
	msg = wxT("$Endlist\n");
	fprintf(cfgfile, CONV_TO_UTF8(msg));
	fclose(cfgfile);
	return 1;
}


/********************************************************************************************/
int WinEDA_BasicFrame::ReadHotkeyConfigFile(const wxString & Filename,
	Ki_HotkeyInfo ** CurrentHotkeyList, bool verbose)
/********************************************************************************************/
/*
 * Read a configuration file (<file>.key) and fill the current hotkey list with hotkeys
 * @param Filename = default full file name to create. If void, A filename will be asked
 * @param CurrentHotkeyList = current hotkey list to initialise.
 * the input format is: shortcut  "key"  "function"
 * lines starting by # are ignored (comments)
* 
*/
{
	wxString FullFilename = Filename;
	FILE * cfgfile;
	wxString msg;
	if ( FullFilename.IsEmpty() || verbose )
	{
		wxString Mask, Path, Ext;
		Ext = DEFAULT_HOTKEY_FILENAME_EXT;
		Mask = wxT("*") + Ext;
		Path = DEFAULT_HOTKEY_FILENAME_PATH;
		FullFilename = EDA_FileSelector( _("Hotkey configuration file:"),
						Path,				/* Chemin par defaut */
						FullFilename,		/* nom fichier par defaut */
						Ext,				/* extension par defaut */
						Mask,				/* Masque d'affichage */
						this,
						wxFD_OPEN,
						TRUE
						);
		if ( FullFilename.IsEmpty() ) return 0;
	}

	cfgfile = wxFopen(FullFilename, wxT("rt"));
	
	if ( cfgfile == NULL )
	{
		if ( verbose )
		{
			msg = _("Unable to read ") + FullFilename;
			DisplayError(this, msg);
		}
		return 0;
	}
	
	wxString keyname;
    char Line[1024];
	int LineNum = 0;
	/* Read the file */
    while(  GetLine( cfgfile, Line, &LineNum ) != NULL )
    {
		char * line_type, * keyname, *fctname;
		line_type = strtok(Line, " \t\n\r");
		msg = CONV_FROM_UTF8(line_type);
		if( msg != wxT("shortcut") ) continue;
		if( msg == wxT("$Endlist") ) break;

		/* Get the key name */
		strtok(NULL, "\"\n\r");
		keyname = strtok(NULL, "\"\n\r");
		strtok(NULL, "\"\n\r");
		/* Get the command name */
		fctname = strtok(NULL, "\"\n\r");
		msg = CONV_FROM_UTF8(fctname);
		/* search the hotkey in current hotkey list */
		for (Ki_HotkeyInfo ** List = CurrentHotkeyList; * List != NULL; List++ )
		{
			Ki_HotkeyInfo * hk_decr = * List;
			if (hk_decr->m_InfoMsg == msg )
			{
				msg = CONV_FROM_UTF8(keyname);
				int code = ReturnKeyCodeFromKeyName(msg);
				if ( code ) hk_decr->m_KeyCode = code;
				break;
			}
		}
	}
	fclose(cfgfile);
	return 1;
}
+3 −6
Original line number Diff line number Diff line
@@ -333,10 +333,6 @@ void WinEDA_DrawFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels
        curpos = m_CurrentScreen->m_Curseur;
        break;

    case ' ':       // Remise a zero coord relatives
        m_CurrentScreen->m_O_Curseur = m_CurrentScreen->m_Curseur;
        break;

    case WXK_NUMPAD8:       /* Deplacement curseur vers le haut */
    case WXK_UP:
        MousePositionInPixels.y -= delta.y;
@@ -391,8 +387,6 @@ void WinEDA_DrawFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels
        }
    }

    Affiche_Status_Box();    /* Affichage des coord curseur */

    if( hotkey )
    {
        if( m_CurrentScreen->GetCurItem()
@@ -401,4 +395,7 @@ void WinEDA_DrawFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels
        else
            OnHotKey( DC, hotkey, NULL );
    }

    Affiche_Status_Box();    /* Affichage des coord curseur */

}
Loading