| version 1.4, 2003/11/05 16:08:59 | version 1.12, 2003/11/21 16:01:41 | 
| Line 11 | Line 11 | 
 | #include        "dialog.h" | #include        "dialog.h" | 
 | #include        "soundmng.h" | #include        "soundmng.h" | 
 | #include        "fdefine.h" | #include        "fdefine.h" | 
 |  | #include        "mackbd.h" | 
 |  | #include        "mousemng.h" | 
 |  | #include        "pccore.h" | 
 |  | #include        "iocore.h" | 
 |  |  | 
 |  |  | 
 | enum { | enum { | 
| Line 107  static const OSType subcommand[11] ={ '- | Line 111  static const OSType subcommand[11] ={ '- | 
 | 'exit', | 'exit', | 
 | }; | }; | 
 |  |  | 
 |  | #define BASENUMBER      4 | 
 | static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; | static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; | 
 |  |  | 
 | static void openpopup(HIPoint location); |  | 
 | static void skinchange(void); |  | 
 | static DragReceiveHandlerUPP    dr; | static DragReceiveHandlerUPP    dr; | 
 |  | static bool     isPUMA; | 
 |  |  | 
 |  | static void openpopup(HIPoint location); | 
 |  | static void skinchange(bool remake); | 
 |  |  | 
 | // ---- | // ---- | 
 |  |  | 
| static bool isPuma(void) { | static void checkOSVersion(void) { | 
| long        res; | static      long    res = 0; | 
| Gestalt(gestaltSystemVersion, &res); | if (!res) { | 
| if (res<0x1020) { | Gestalt(gestaltSystemVersion, &res); | 
| return(true); | if (res<0x1020) { | 
|  | isPUMA = true; | 
|  | } | 
|  | else { | 
|  | isPUMA = false; | 
|  | } | 
 | } | } | 
 | return(false); |  | 
 | } | } | 
 |  |  | 
 |  |  | 
| Line 161  static PicHandle skinload(const char *pa | Line 172  static PicHandle skinload(const char *pa | 
 | return(ret); | return(ret); | 
 | } | } | 
 | } | } | 
| return(getBMPfromResource("np2tool", bounds)); | return(getBMPfromResource("np2tool.bmp", bounds)); | 
 | } | } | 
 |  |  | 
 | // ---- | // ---- | 
| Line 518  static pascal OSStatus cfWinproc(EventHa | Line 529  static pascal OSStatus cfWinproc(EventHa | 
 | Draw1Control(sub); | Draw1Control(sub); | 
 | } | } | 
 | } | } | 
 |  | err=noErr; | 
 |  | break; | 
 |  |  | 
 |  | case kEventWindowFocusAcquired: | 
 |  | BringToFront(hWndMain); | 
 |  | err = noErr; | 
 | break; | break; | 
|  |  | 
 |  |  | 
 | default: | default: | 
 | break; | 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; | (void)myHandler; | 
 | return err; | return err; | 
| Line 548  OSErr setDropFile(FSSpec spec, int drv) | Line 612  OSErr setDropFile(FSSpec spec, int drv) | 
 |  |  | 
 | case FTYPE_TEXT: | case FTYPE_TEXT: | 
 | strcpy(np2tool.skin, fname); | strcpy(np2tool.skin, fname); | 
| skinchange(); | skinchange(true); | 
 | break; | break; | 
 |  |  | 
 | case FTYPE_THD: | case FTYPE_THD: | 
| Line 609  static WindowRef makeNibWindow (IBNibRef | Line 673  static WindowRef makeNibWindow (IBNibRef | 
 | OSStatus    err; | OSStatus    err; | 
 | WindowRef   win = NULL; | WindowRef   win = NULL; | 
 |  |  | 
| if (isPuma()) { | if (isPUMA) { | 
 | Rect    bounds; | Rect    bounds; | 
 | SetRect(&bounds, 0, 0, 100, 100); | SetRect(&bounds, 0, 0, 100, 100); | 
 | err = CreateNewWindow(kFloatingWindowClass, kWindowStandardHandlerAttribute, &bounds, &win); | err = CreateNewWindow(kFloatingWindowClass, kWindowStandardHandlerAttribute, &bounds, &win); | 
| Line 620  static WindowRef makeNibWindow (IBNibRef | Line 684  static WindowRef makeNibWindow (IBNibRef | 
 | if (err == noErr) { | if (err == noErr) { | 
 | InstallStandardEventHandler(GetWindowEventTarget(win)); | InstallStandardEventHandler(GetWindowEventTarget(win)); | 
 | EventTypeSpec   list[]={ | EventTypeSpec   list[]={ | 
| { kEventClassCommand, kEventCommandProcess }, | { kEventClassCommand,       kEventCommandProcess }, | 
| { kEventClassWindow, kEventWindowClose }, | { kEventClassWindow,        kEventWindowClose }, | 
| { kEventClassWindow, kEventWindowShown }, | { kEventClassWindow,        kEventWindowShown }, | 
| { kEventClassWindow, kEventWindowDrawContent }, | { kEventClassWindow,        kEventWindowDrawContent }, | 
|  | { kEventClassWindow,        kEventWindowFocusAcquired }, | 
|  | { kEventClassKeyboard,      kEventRawKeyDown}, | 
 | }; | }; | 
 | EventHandlerRef ref; | EventHandlerRef ref; | 
 | InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref); | InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref); | 
| Line 653  static void createskinmenu(MenuRef ret) | Line 719  static void createskinmenu(MenuRef ret) | 
 | const char      *base; | const char      *base; | 
 | char    *p; | char    *p; | 
 | UINT    i; | UINT    i; | 
| UINT    j; | char        longname[256]; | 
| UINT    id[SKINMRU_MAX]; |  | 
| const char      *file[SKINMRU_MAX]; |  | 
| Str255      seltext, deftext; |  | 
 |  |  | 
| mkstr255(seltext, str_skinsel); | AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("Select Skin..."),"Slect Skin"), kMenuItemAttrIconDisabled, NULL,NULL); | 
| AppendMenu(ret, seltext); |  | 
 | AppendMenu(ret, "\p-"); | AppendMenu(ret, "\p-"); | 
 |  |  | 
 | base = np2tool.skin; | base = np2tool.skin; | 
| mkstr255(deftext, str_skindef); | AppendMenuItemTextWithCFString(ret, CFCopyLocalizedString(CFSTR("<Base Skin>"),"Base Skin"), kMenuItemAttrIconDisabled, NULL,NULL); | 
| AppendMenu(ret, deftext); | if (base[0] == '\0') { | 
| if (base[0] != '\0') { | CheckMenuItem(ret, BASENUMBER-1, true); | 
| EnableMenuItem(ret, 3); |  | 
 | } | } | 
 | for (cnt=0; cnt<SKINMRU_MAX; cnt++) { | for (cnt=0; cnt<SKINMRU_MAX; cnt++) { | 
 | p = np2tool.skinmru[cnt]; | p = np2tool.skinmru[cnt]; | 
 | if (p[0] == '\0') { | if (p[0] == '\0') { | 
 | break; | break; | 
 | } | } | 
| p = file_getname(p); | UInt32  attr = kMenuItemAttrIconDisabled; | 
| for (i=0; i<cnt; i++) { | if (file_attr(p) != FILEATTR_ARCHIVE) { | 
| if (file_cmpname(p, file[id[i]]) < 0) { | attr |= kMenuItemAttrDisabled; | 
| break; |  | 
| } |  | 
| } |  | 
| for (j=cnt; j>i; j--) { |  | 
| id[j] = id[j-1]; |  | 
| } |  | 
| id[i] = cnt; |  | 
| file[cnt] = p; |  | 
| } |  | 
| for (i=0; i<cnt; i++) { |  | 
| j = id[i]; |  | 
| if (file[j][0] == '\0') { |  | 
| AppendMenu(ret, "\pN/A"); |  | 
 | } | } | 
| else { | ZeroMemory(longname, sizeof(longname)); | 
| Str255      initext; | if (!getLongFileName(longname, p)) { | 
| mkstr255(initext, file[j]); | strcpy(longname, file_getname(p)); | 
| AppendMenu(ret, initext); |  | 
 | } | } | 
| if (!file_cmpname(base, np2tool.skinmru[j])) { | AppendMenuItemTextWithCFString(ret, CFStringCreateWithCString(NULL, longname, kCFStringEncodingUTF8), attr, NULL, NULL); | 
| EnableMenuItem(ret, 4+i); | } | 
|  | for (i=0; i<cnt; i++) { | 
|  | if (!file_cmpname(base, np2tool.skinmru[i])) { | 
|  | CheckMenuItem(ret, i+BASENUMBER, true); | 
|  | break; | 
 | } | } | 
 | } | } | 
 | return; | return; | 
 | } | } | 
 |  |  | 
| static void skinchange(void) { | static void skinchange(bool remake) { | 
 |  |  | 
 | const char              *p; | const char              *p; | 
 | UINT            i; | UINT            i; | 
 |  |  | 
 | toolwin_close(); | toolwin_close(); | 
 | p = np2tool.skin; | p = np2tool.skin; | 
| if (p[0]) { | if (p[0] && remake) { | 
 | for (i=0; i<(SKINMRU_MAX - 1); i++) { | for (i=0; i<(SKINMRU_MAX - 1); i++) { | 
 | if (!file_cmpname(p, np2tool.skinmru[i])) { | if (!file_cmpname(p, np2tool.skinmru[i])) { | 
 | break; | break; | 
| Line 732  static void openpopup(HIPoint location) | Line 783  static void openpopup(HIPoint location) | 
 |  |  | 
 | MenuRef hMenu; | MenuRef hMenu; | 
 | short   sel; | short   sel; | 
 | Str255      closetext; |  | 
 | UInt16      selectclose; | UInt16      selectclose; | 
 | char        fname[MAX_PATH]; | char        fname[MAX_PATH]; | 
 |  |  | 
| hMenu = NewMenu(222, "\pskin"); | hMenu = NewMenu(222, "\pSkin"); | 
 | InsertMenu(hMenu, -1); | InsertMenu(hMenu, -1); | 
 | createskinmenu(hMenu); | createskinmenu(hMenu); | 
 | AppendMenu(hMenu, "\p-"); | AppendMenu(hMenu, "\p-"); | 
| mkstr255(closetext, str_toolclose); | AppendMenuItemTextWithCFString(hMenu, CFCopyLocalizedString(CFSTR("Close"),"ToolWin Close"), kMenuItemAttrIconDisabled, NULL, NULL); | 
| AppendMenu(hMenu, closetext); |  | 
|  |  | 
 | DeleteMenu(222); | DeleteMenu(222); | 
 | selectclose = CountMenuItems(hMenu); | selectclose = CountMenuItems(hMenu); | 
 | sel = LoWord(PopUpMenuSelect(hMenu, (short)location.y, (short)location.x, 0)); | sel = LoWord(PopUpMenuSelect(hMenu, (short)location.y, (short)location.x, 0)); | 
| Line 753  static void openpopup(HIPoint location) | Line 801  static void openpopup(HIPoint location) | 
 | else { | else { | 
 | switch (sel) { | switch (sel) { | 
 | case 1: | case 1: | 
| if(dialog_fileselect(fname, sizeof(fname), hWndMain)) { | if(dialog_fileselect(fname, sizeof(fname), hWndMain, OPEN_INI)) { | 
 | if (file_getftype(fname)==FTYPE_TEXT) { | if (file_getftype(fname)==FTYPE_TEXT) { | 
 | strcpy(np2tool.skin, fname); | strcpy(np2tool.skin, fname); | 
| skinchange(); | skinchange(true); | 
 | } | } | 
 | } | } | 
 | break; | break; | 
 | case 3: | case 3: | 
| np2tool.skin[0] = '\0'; | if (np2tool.skin[0]) { | 
| skinchange(); | np2tool.skin[0] = '\0'; | 
|  | skinchange(false); | 
|  | } | 
 | break; | break; | 
 | case 4: | case 4: | 
 | case 5: | case 5: | 
 | case 6: | case 6: | 
 | case 7: | case 7: | 
| file_cpyname(np2tool.skin, np2tool.skinmru[sel - 4], sizeof(np2tool.skin)); | if (file_cmpname(np2tool.skin, np2tool.skinmru[sel - BASENUMBER])) { | 
| skinchange(); | file_cpyname(np2tool.skin, np2tool.skinmru[sel - BASENUMBER], sizeof(np2tool.skin)); | 
|  | skinchange(false); | 
|  | } | 
 | break; | break; | 
 | default: | default: | 
 | break; | break; | 
| Line 793  void toolwin_open(void) { | Line 845  void toolwin_open(void) { | 
 | toolwin_close(); | toolwin_close(); | 
 | return; | return; | 
 | } | } | 
 |  |  | 
 |  | checkOSVersion(); | 
 | ZeroMemory(&toolwin, sizeof(toolwin)); | ZeroMemory(&toolwin, sizeof(toolwin)); | 
 |  |  | 
 | hbmp = skinload(np2tool.skin, &bounds); | hbmp = skinload(np2tool.skin, &bounds); | 
| Line 806  void toolwin_open(void) { | Line 860  void toolwin_open(void) { | 
 | goto twope_err2; | goto twope_err2; | 
 | } | } | 
 |  |  | 
| if (isPuma()) { | if (isPUMA) { | 
 | toolwincreate(hWnd); | toolwincreate(hWnd); | 
 | } | } | 
 | SizeWindow(hWnd, bounds.right-bounds.left, bounds.bottom-bounds.top, true); | SizeWindow(hWnd, bounds.right-bounds.left, bounds.bottom-bounds.top, true); | 
| Line 815  void toolwin_open(void) { | Line 869  void toolwin_open(void) { | 
 | info.u.picture = hbmp; | info.u.picture = hbmp; | 
 | CreatePictureControl(hWnd, &bounds, &info, true, &image); | CreatePictureControl(hWnd, &bounds, &info, true, &image); | 
 | InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref); | InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref); | 
| if (!isPuma()) { | if (!isPUMA) { | 
 | toolwincreate(hWnd); | toolwincreate(hWnd); | 
 | } | } | 
|  | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER | 
| if (isPuma()) { | if (np2tool.posy < 35) np2tool.posy = 35; | 
|  | if (np2tool.posx < 5 ) np2tool.posx = 5; | 
|  | MoveWindow(hWnd, np2tool.posx, np2tool.posy, true); | 
|  | ShowWindow(hWnd); | 
|  | #else | 
|  | if (isPUMA) { | 
 | if (np2tool.posy < 35) np2tool.posy = 35; | if (np2tool.posy < 35) np2tool.posy = 35; | 
 | if (np2tool.posx < 5 ) np2tool.posx = 5; | if (np2tool.posx < 5 ) np2tool.posx = 5; | 
 | MoveWindow(hWnd, np2tool.posx, np2tool.posy, true); | MoveWindow(hWnd, np2tool.posx, np2tool.posy, true); | 
 | ShowWindow(hWnd); | ShowWindow(hWnd); | 
 | } | } | 
| else{ | else { | 
|  | Rect    mainbounds; | 
|  | int             width; | 
 | SetDrawerParent(hWnd, hWndMain); | SetDrawerParent(hWnd, hWndMain); | 
| SetDrawerOffsets(hWnd, (640-(bounds.right-bounds.left))/2-11, (640-(bounds.right-bounds.left))/2-11); | GetWindowBounds(hWndMain, kWindowContentRgn, &mainbounds); | 
|  | width = (mainbounds.right-mainbounds.left)-(bounds.right-bounds.left); | 
|  | if (width/2-11<0) { | 
|  | toolwin_close(); | 
|  | return; | 
|  | } | 
|  | SetDrawerOffsets(hWnd, width/2-11, width/2-11); | 
 | SetDrawerPreferredEdge(hWnd, kWindowEdgeTop); | SetDrawerPreferredEdge(hWnd, kWindowEdgeTop); | 
 | OpenDrawer(hWnd, kWindowEdgeDefault, 1); | OpenDrawer(hWnd, kWindowEdgeDefault, 1); | 
 | } | } | 
 |  | #endif | 
 |  |  | 
 |  | np2oscfg.toolwin = 1; | 
 | return; | return; | 
 |  |  | 
 | twope_err2: | twope_err2: | 
| Line 845  twope_err1: | Line 914  twope_err1: | 
 | void toolwin_close(void) { | void toolwin_close(void) { | 
 |  |  | 
 | if (toolwin.hwnd) { | if (toolwin.hwnd) { | 
| if (!isPuma()) { | #ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER | 
| CloseDrawer(toolwin.hwnd, 0); | HideWindow(toolwin.hwnd); | 
|  | #else | 
|  | if (isPUMA) { | 
|  | HideWindow(toolwin.hwnd); | 
 | } | } | 
| else{ | else { | 
| DisposeWindow(toolwin.hwnd); | CloseDrawer(toolwin.hwnd, 0); | 
 | } | } | 
 |  | #endif | 
 | RemoveReceiveHandler(dr, toolwin.hwnd); | RemoveReceiveHandler(dr, toolwin.hwnd); | 
 | toolwindestroy(); | toolwindestroy(); | 
 | DisposeWindow(toolwin.hwnd); | DisposeWindow(toolwin.hwnd); | 
 | toolwin.hwnd = NULL; | toolwin.hwnd = NULL; | 
 |  | np2oscfg.toolwin = 0; | 
 | } | } | 
 | } | } | 
 |  |  | 
| Line 971  const DISKACC *accterm; | Line 1045  const DISKACC *accterm; | 
 | // ---- | // ---- | 
 |  |  | 
 | static const char ini_title[] = "NP2 tool"; | static const char ini_title[] = "NP2 tool"; | 
 |  | static const char inifile[] = "np2.cfg";                        // same file name.. | 
 |  |  | 
 | static const INITBL iniitem[] = { | static const INITBL iniitem[] = { | 
 | {"WindposX", INITYPE_SINT32,    &np2tool.posx,                  0}, | {"WindposX", INITYPE_SINT32,    &np2tool.posx,                  0}, | 
| Line 998  static const INITBL iniitem[] = { | Line 1073  static const INITBL iniitem[] = { | 
 | {"FD2NAME7", INITYPE_STR,               np2tool.fdd[1].name[7], MAX_PATH}}; | {"FD2NAME7", INITYPE_STR,               np2tool.fdd[1].name[7], MAX_PATH}}; | 
 |  |  | 
 |  |  | 
 | void initgetfile(char *path, UINT size) { |  | 
 |  |  | 
 | file_cpyname(path, file_getcd("np2"), size); |  | 
 | file_catname(path, ".ini", size); |  | 
 | } |  | 
 |  |  | 
 | void toolwin_readini(void) { | void toolwin_readini(void) { | 
 |  |  | 
 | char    path[MAX_PATH]; | char    path[MAX_PATH]; | 
| Line 1011  void toolwin_readini(void) { | Line 1080  void toolwin_readini(void) { | 
 | ZeroMemory(&np2tool, sizeof(np2tool)); | ZeroMemory(&np2tool, sizeof(np2tool)); | 
 | np2tool.posx = 0; | np2tool.posx = 0; | 
 | np2tool.posy = 0; | np2tool.posy = 0; | 
| initgetfile(path, sizeof(path)); | file_cpyname(path, file_getcd(inifile), sizeof(path)); | 
 | ini_read(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL)); | ini_read(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL)); | 
 | } | } | 
 |  |  | 
| Line 1019  void toolwin_writeini(void) { | Line 1088  void toolwin_writeini(void) { | 
 |  |  | 
 | char    path[MAX_PATH]; | char    path[MAX_PATH]; | 
 |  |  | 
| initgetfile(path, sizeof(path)); | file_cpyname(path, file_getcd(inifile), sizeof(path)); | 
| ini_write(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL)); | ini_write(path, ini_title, iniitem, sizeof(iniitem)/sizeof(INITBL), FALSE); | 
 | } | } | 
 |  |  |