// Version 1.00 29/10/96  First full release.
//         1.01 24/03/97  Now capitalises first character in story.


int suprshft_status;
int suprshft_flag = 0;


// if previous character was a white space, and previous to that was 
// a '.', '!' or '?' then capitalise the current character

int suprshft_fix(int user, int view, int key)
{
 if(key == '.' || key == '?' || key == '!')
  suprshft_flag = 1;
 else
 // check if key is 'space', 'new para', 'tab', 'new line' or 'new page'
 if(suprshft_flag == 1 && key == 32 || key == 13 || key == 394 || key == 2061 || key == 6669)
  suprshft_flag = 2;
 else
 if((suprshft_flag == 2 || prevchar() == -1) && key >= 'a' && key <= 'z')
 {
  key = key - 32;
  suprshft_flag = 0;
 }
 else
  suprshft_flag = 0;

 return(key);
}


// set up EVENT_KEYPRESS events

void suprshft_setevent(int i)
{
 if (i)  
  addeventhandler(0x300, 0, "suprshft_fix");
 else
  remeventhandler(0x300, 0, "suprshft_fix");

 suprshft_status = i;
}


// Deal with 'Super shift' menu entry

int suprshft_entry(int entry, int subcode)
{
 suprshft_setevent(!suprshft_status);
 return(0);
}


// Tick or un-tick 'Supershift' menu entry

int suprshft_flags(int entry, string &text)
{
 return(suprshft_status);
}


// add 'Super shift' option to 'Applets' menu and enable ligatures

void main(void)
{
 script_menu_initialise();

 addentry_menu(script_handle,"suprshft_entry","suprshft_flags","","","{SUPRSHFT_00}");
 suprshft_setevent(1);
}
