--- np2/macosx/toolwin.cpp	2003/11/05 16:08:59	1.4
+++ np2/macosx/toolwin.cpp	2003/11/21 16:01:41	1.12
@@ -11,6 +11,10 @@
 #include	"dialog.h"
 #include	"soundmng.h"
 #include	"fdefine.h"
+#include	"mackbd.h"
+#include	"mousemng.h"
+#include	"pccore.h"
+#include	"iocore.h"
 
 
 enum {
@@ -107,21 +111,28 @@ static const OSType subcommand[11] ={	'-
                                         'exit',
                                     };
 
+#define	BASENUMBER	4
 static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} };
 
-static void openpopup(HIPoint location);
-static void skinchange(void);
 static DragReceiveHandlerUPP	dr;
+static bool	isPUMA;
+
+static void openpopup(HIPoint location);
+static void skinchange(bool remake);
 
 // ----
 
-static bool isPuma(void) {
-    long	res;
-    Gestalt(gestaltSystemVersion, &res);
-    if (res<0x1020) {
-        return(true);
+static void checkOSVersion(void) {
+    static	long	res = 0;
+    if (!res) {
+        Gestalt(gestaltSystemVersion, &res);
+        if (res<0x1020) {
+            isPUMA = true;
+        }
+        else {
+            isPUMA = false;
+        }
     }
-    return(false);
 }
 
 
@@ -161,7 +172,7 @@ static PicHandle skinload(const char *pa
 			return(ret);
 		}
 	}
-	return(getBMPfromResource("np2tool", bounds));
+	return(getBMPfromResource("np2tool.bmp", bounds));
 }
 
 // ----
@@ -518,13 +529,66 @@ static pascal OSStatus cfWinproc(EventHa
                         Draw1Control(sub);
                     }
                 }
+                err=noErr;
+                break;
+                
+            case kEventWindowFocusAcquired:
+                BringToFront(hWndMain);
+                err = noErr;
                 break;
-
+                
                 
             default:
                 break;
         }
     }
+    else if (GetEventClass(event)==kEventClassKeyboard) {
+        static	UInt32	backup = 0;
+        UInt32	whatHappened = GetEventKind(event);
+        UInt32 key;
+        GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &key);
+        UInt32 modif;
+        GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif);
+        switch (whatHappened)
+        {
+            case kEventRawKeyUp:
+                mackbd_keyup(key);
+                err = noErr;
+                break;
+            case kEventRawKeyRepeat:
+                mackbd_keydown(key);
+                err = noErr;
+                break;
+            case kEventRawKeyDown:
+                if (modif & cmdKey) {
+                    EventRecord	eve;
+                    ConvertEventRefToEventRecord( event,&eve );
+                    mousemng_disable(MOUSEPROC_MACUI);
+                    recieveCommand(MenuEvent(&eve));
+                    mousemng_enable(MOUSEPROC_MACUI);
+                }
+                else {
+                    mackbd_keydown(key);
+                }
+                err = noErr;
+                break;
+            case kEventRawKeyModifiersChanged:
+                if (modif & shiftKey) keystat_senddata(0x70);
+                else keystat_senddata(0x70 | 0x80);
+                if (modif & optionKey) keystat_senddata(0x73);
+                else keystat_senddata(0x73 | 0x80);
+                if (modif & controlKey) keystat_senddata(0x74);
+                else keystat_senddata(0x74 | 0x80);
+                if ((modif & alphaLock) != (backup & alphaLock)) {
+                    keystat_senddata(0x71);
+                    backup = modif;
+                }
+                err = noErr;
+                break;
+            default: 
+                break;             
+        }
+    }
 
 	(void)myHandler;
     return err;
@@ -548,7 +612,7 @@ OSErr setDropFile(FSSpec spec, int drv) 
             
         case FTYPE_TEXT:
             strcpy(np2tool.skin, fname);
-            skinchange();
+            skinchange(true);
             break;
         
         case FTYPE_THD:
@@ -609,7 +673,7 @@ static WindowRef makeNibWindow (IBNibRef
     OSStatus	err;
     WindowRef	win = NULL;
 
-    if (isPuma()) {
+    if (isPUMA) {
         Rect	bounds;
         SetRect(&bounds, 0, 0, 100, 100);
         err = CreateNewWindow(kFloatingWindowClass, kWindowStandardHandlerAttribute, &bounds, &win);
@@ -620,10 +684,12 @@ static WindowRef makeNibWindow (IBNibRef
     if (err == noErr) {
         InstallStandardEventHandler(GetWindowEventTarget(win));
         EventTypeSpec	list[]={ 
-            { kEventClassCommand, kEventCommandProcess },
-            { kEventClassWindow, kEventWindowClose }, 
-            { kEventClassWindow, kEventWindowShown }, 
-            { kEventClassWindow, kEventWindowDrawContent }, 
+            { kEventClassCommand, 	kEventCommandProcess },
+            { kEventClassWindow,	kEventWindowClose }, 
+            { kEventClassWindow,	kEventWindowShown }, 
+            { kEventClassWindow,	kEventWindowDrawContent }, 
+            { kEventClassWindow, 	kEventWindowFocusAcquired }, 
+            { kEventClassKeyboard,	kEventRawKeyDown},
         };
         EventHandlerRef	ref;
         InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref);
@@ -653,63 +719,48 @@ static void createskinmenu(MenuRef ret) 
 const char	*base;
 	char	*p;
 	UINT	i;
-	UINT	j;
-	UINT	id[SKINMRU_MAX];
-const char	*file[SKINMRU_MAX];
-    Str255	seltext, deftext;
+    char	longname[256];
 
-    mkstr255(seltext, str_skinsel);
-	AppendMenu(ret, seltext);
+	AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, NULL,NULL);
 	AppendMenu(ret, "\p-");
 
 	base = np2tool.skin;
-    mkstr255(deftext, str_skindef);
-	AppendMenu(ret, deftext);
-	if (base[0] != '\0') {
-        EnableMenuItem(ret, 3);
+	AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR(""),"Base Skin"), kMenuItemAttrIconDisabled, NULL,NULL);
+	if (base[0] == '\0') {
+        CheckMenuItem(ret, BASENUMBER-1, true);
     }
 	for (cnt=0; cnti; j--) {
-			id[j] = id[j-1];
-		}
-		id[i] = cnt;
-		file[cnt] = p;
-	}
-	for (i=0; i