/*
**      Newton Developer Technical Support Sample Code
**
**      QWERTY, Keyboard sample, no add-to-dictionary.
**
**      by J. Christopher Bell & Maurice Sharp, Newton Developer Technical Support
**
**      Copyright © 1993-1995 by Apple Computer, Inc.  All rights reserved.
**
**      You may incorporate this sample code into your applications without
**      restriction.  This sample code has been provided "AS IS" and the
**      responsibility for its operation is 100% yours.  You are not
**      permitted to modify and redistribute the source as "DTS Sample Code."
**      If you are going to re-distribute the source, we require that you
**      make it clear in the source that the code was descended from
**      Apple-provided sample code, but that you've made changes.
*/



// application constants
constant kAppMaxWidth := 240 ;
constant kAppMaxHeight := 336 ;

// slot for the keyboard in the root view
constant kMyKeyboardSymbol := '|myAlphaKeyboard:PIEDTS|;

// grab the pictures for the keys
r := OpenResFileX(HOME & "pictures") ;
kbdReturnBitmap := GetPictAsBits("KeyboardReturn", nil);
kbdTabBitmap := GetPictAsBits("KeyboardTab", nil);
kbdLeftBitmap := GetPictAsBits("KeyboardLeftArrow", nil);
kbdRightBitmap := GetPictAsBits("KeyboardRightArrow", nil);
CloseResFileX(r);


// some constants for key values
constant kOneKey := 18 ;
constant kQKey := 12 ;

constant kQNormal := $q ;
constant kQShifted := $Q ;
constant kQOption := $\u0153 ;
constant kQOptionShift := $\u0152 ;
constant kOneOption := $\A1 ;
constant kOneOptionShift := $\u2044 ;

constant kDeleteKey := 51 ;
constant kTabKey := 48 ;
constant kReturnKey := 36 ;
constant kShiftKey := 56 ;
constant kCapsLockKey := 57 ;
constant kOptionKey := 58 ;
constant kSpaceKey := 49 ;
constant kLeftArrowKey := 0x7B ;
constant kRightArrowKey := 0x7C ;


// the keyboard row definitions
row0 := [	keyVUnit, keyVUnit,
				nil, 50, 	keyHHalf + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 18,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
		 		nil, 19,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 20,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 21,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 23,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 22,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 26,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 28,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 25,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 29,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 27,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 24,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
		  		"del", kDeleteKey,	keyHUnit + keyHHalf + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3
			];

row1 := [	keyVUnit, keyVUnit,
				kbdTabBitmap, kTabKey,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 12,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 13,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
		 		nil, 14,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 15,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 17, 	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 16,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 32,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 34, 	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 31,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 35,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 33,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 30, 	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 42,	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3
			];

row2 := [	keyVUnit, keyVUnit,
				"caps", kCapsLockKey, 	keyHUnit + keyHHalf + keyVUnit + keyFramed + keyRoundingUnit*3,
				nil, 0, 		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 1, 		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
		 		nil, 2, 		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 3, 		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 5, 		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 4, 		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 38,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 40,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 37,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 41,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 39,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				kbdReturnBitmap,
				     kReturnKey,		keyHUnit + keyHHalf + keyVUnit + keyAutoHilite + keyFramed + keyRoundingUnit*3
			];

row3 := [	keyVUnit, keyVUnit,
				"shift", kShiftKey,	2*keyHUnit + keyVUnit + keyFramed + keyRoundingUnit*3,
				nil, 6,			keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 7, 	 	keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
		 		nil, 8,			keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 9,			keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 11,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 45,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 46,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 43,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 47,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				nil, 44,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				"shift", kShiftKey,	2*keyHUnit + keyVUnit + keyFramed + keyRoundingUnit*3
			];

row4 := [	keyVUnit, keyVUnit,
				nil, nil,		1*keyHUnit + keyHHalf + keyHQuarter + keyVUnit + keySpacer,
				"option", kOptionKey,	2*keyHUnit + keyHHalf + keyVUnit + keyFramed + keyRoundingUnit*3,
				nil, kSpaceKey,		6*keyHUnit + keyHQuarter + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				kbdLeftBitmap,
				     kLeftArrowKey,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
				kbdRightBitmap,
				     kRightArrowKey,		keyHUnit + keyVUnit + keyFramed + keyAutoHilite + keyRoundingUnit*3,
			];
