--- np2/macosx/toolwin.cpp 2003/11/24 20:44:14 1.13 +++ np2/macosx/toolwin.cpp 2004/01/11 16:58:47 1.16 @@ -113,12 +113,13 @@ static const OSType subcommand[11] ={ '- #define BASENUMBER 4 static const ControlID popup[2] = { {'pop1', 1}, {'pop2', 2} }; +static const ControlID imageid = {'back', 0}; static DragReceiveHandlerUPP dr; static DragTrackingHandlerUPP tr; -static bool isPUMA; +static bool isPUMA, isJaguar; -static void openpopup(HIPoint location); +static void openpopup(Point location); static void skinchange(bool remake); // ---- @@ -129,9 +130,15 @@ static void checkOSVersion(void) { Gestalt(gestaltSystemVersion, &res); if (res<0x1020) { isPUMA = true; + isJaguar = false; } + else if (res<0x1030) { + isPUMA = false; + isJaguar = true; + } else { isPUMA = false; + isJaguar = false; } } } @@ -191,7 +198,6 @@ static void setlist(ControlRef hwnd, con const char *q; const char *p; CFStringRef str; - SInt32 attr = kMenuItemAttrIconDisabled; Str255 pname; bool success = false; @@ -209,14 +215,17 @@ const char *p; } #endif for (i=0; icnt; i++) { + SInt32 attr = kMenuItemAttrIconDisabled; p = fdd->name[fdd->pos[i]]; success = getLongFileName(cfname, p); str = CFStringCreateWithCString(NULL, cfname, CFStringGetSystemEncoding()); - if ((str) && success) { - if (file_attr(p) != FILEATTR_ARCHIVE) { - attr |= kMenuItemAttrDisabled; - } - AppendMenuItemTextWithCFString(menu, str, attr, NULL, NULL); + if (str) { + if (success) { + if (file_attr(p) != FILEATTR_ARCHIVE) { + attr |= kMenuItemAttrDisabled; + } + AppendMenuItemTextWithCFString(menu, str, attr, NULL, NULL); + } CFRelease(str); } else { @@ -238,6 +247,9 @@ const char *p; if (file_attr(p)==FILEATTR_ARCHIVE) { EnableMenuItem(menu, i+1); } + else { + DisableMenuItem(menu, i+1); + } } p += sizeof(fdd->name[0]); } @@ -245,7 +257,10 @@ const char *p; CFStringRef title; SetBevelButtonMenuValue(hwnd, sel+1); CopyMenuItemTextAsCFString(menu, sel+1, &title); - SetControlTitleWithCFString(hwnd, title); + if (title) { + SetControlTitleWithCFString(hwnd, title); + CFRelease(title); + } } else { SetControlTitleWithCFString(hwnd, CFSTR(" ")); @@ -347,9 +362,21 @@ static pascal OSStatus cfControlproc(Eve } else if (GetEventClass(event)==kEventClassControl && GetEventKind(event)==kEventControlContextualMenuClick) { HIPoint location; + Point point; + soundmng_stop(); GetEventParameter (event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(HIPoint), NULL, &location); - openpopup(location); + point.h = (short)location.x; + point.v = (short)location.y; + if (!isJaguar && !isPUMA) { + GrafPtr port, dst; + bool portchanged; + dst = GetWindowPort(toolwin.hwnd); + portchanged = QDSwapPort(dst, &port); + LocalToGlobal(&point); + if (portchanged) QDSwapPort(port, NULL); + } + openpopup(point); soundmng_play(); } @@ -358,6 +385,22 @@ static pascal OSStatus cfControlproc(Eve return err; } +static PixPatHandle portpat; + +static void setDragColor(GrafPtr window) { + GrafPtr port; + RGBColor color; + bool portchanged; + + portchanged = QDSwapPort(window, &port); + GetThemeBrushAsColor(kThemeBrushDragHilite, 32, true, &color); + portpat = NewPixPat(); + MakeRGBPat(portpat, &color); + PenPixPat(portpat); + PenSize(3, 3); + if (portchanged) QDSwapPort(port, NULL); +} + static void toolwincreate(WindowRef hWnd) { const SUBITEM *p; @@ -366,6 +409,8 @@ const SUBITEM *p; const char *cls; UInt32 style; + setDragColor(GetWindowPort(hWnd)); + ControlButtonContentInfo info; info.contentType = kControlContentPictHandle; info.u.picture = NULL; @@ -465,6 +510,7 @@ static void toolwindestroy(void) { DisposePixPat(toolwin.access[1]); KillPicture(toolwin.hbmp); toolwin.hbmp = NULL; + DisposePixPat(portpat); } } @@ -528,6 +574,9 @@ static pascal OSStatus cfWinproc(EventHa else if (GetEventClass(event)==kEventClassWindow) { switch (GetEventKind(event)) { case kEventWindowClose: +#ifdef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER + case kEventWindowDrawerClosed: +#endif toolwin_close(); err=noErr; break; @@ -543,22 +592,15 @@ static pascal OSStatus cfWinproc(EventHa 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; + UInt32 key; GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &key); - UInt32 modif; + UInt32 modif; GetEventParameter (event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modif); switch (whatHappened) { @@ -583,19 +625,6 @@ static pascal OSStatus cfWinproc(EventHa } 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; } @@ -692,7 +721,7 @@ static OSErr DragTracker (DragTrackingMe bool portchanged = false; static bool hilite = false; Rect bounds; - Boolean inframe = TRUE; + ControlRef back; if (message == kDragTrackingEnterHandler || message == kDragTrackingLeaveHandler) { hilite = false; @@ -700,9 +729,9 @@ static OSErr DragTracker (DragTrackingMe } if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { if (hilite) { - if (HideDragHilite(theDrag) == noErr) { - hilite = false; - } + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); + hilite = false; } return (-1); } @@ -715,22 +744,16 @@ static OSErr DragTracker (DragTrackingMe message = kDragTrackingLeaveWindow; } else { - rgn = NewRgn(); GetControlByID(theWindow, &popup[drv], &targetControl); GetControlBounds(targetControl, &bounds); - RectRgn(rgn, &bounds); - inframe = FALSE; } break; case FTYPE_INI: case FTYPE_THD: case FTYPE_HDI: - rgn = NewRgn(); GetWindowBounds(theWindow, kWindowContentRgn, &bounds); OffsetRect(&bounds, -bounds.left, -bounds.top); - RectRgn(rgn, &bounds); - inframe = TRUE; break; default: @@ -740,17 +763,20 @@ static OSErr DragTracker (DragTrackingMe portchanged = QDSwapPort(GetWindowPort(theWindow), &port); if (message == kDragTrackingLeaveWindow && hilite) { - if (HideDragHilite(theDrag) == noErr) { - hilite = false; - } + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); + hilite = false; } else { - if (ShowDragHilite(theDrag, rgn, inframe) == noErr) { - hilite = true; + rgn = NewRgn(); + if (rgn) { + RectRgn(rgn, &bounds); + FrameRgn(rgn); + DisposeRgn(rgn); } + hilite = true; } if (portchanged) QDSwapPort(port, NULL); - if (rgn) DisposeRgn(rgn); return(noErr); } @@ -759,6 +785,10 @@ static pascal OSErr DragReceiver( Window { SInt16 drv = -1; HFSFlavor aHFSFlavor; + ControlRef back; + + GetControlByID(theWindow, &imageid, &back); + Draw1Control(back); if (getFSSpecFromDragItem(theDrag, &aHFSFlavor) != noErr) { return (-1); @@ -786,8 +816,12 @@ static WindowRef makeNibWindow (IBNibRef { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowShown }, { kEventClassWindow, kEventWindowDrawContent }, - { kEventClassWindow, kEventWindowFocusAcquired }, + { kEventClassKeyboard, kEventRawKeyUp}, { kEventClassKeyboard, kEventRawKeyDown}, + { kEventClassKeyboard, kEventRawKeyRepeat}, +#ifdef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER + { kEventClassWindow, kEventWindowDrawerClosed }, +#endif }; EventHandlerRef ref; InstallWindowEventHandler (win, NewEventHandlerUPP(cfWinproc), GetEventTypeCount(list), list, (void *)win, &ref); @@ -879,7 +913,7 @@ const char *p; // ---- -static void openpopup(HIPoint location) { +static void openpopup(Point location) { MenuRef hMenu; short sel; @@ -893,7 +927,7 @@ static void openpopup(HIPoint location) AppendMenuItemTextWithCFString(hMenu, CFCopyLocalizedString(CFSTR("Close"),"ToolWin Close"), kMenuItemAttrIconDisabled, NULL, NULL); DeleteMenu(222); selectclose = CountMenuItems(hMenu); - sel = LoWord(PopUpMenuSelect(hMenu, (short)location.y, (short)location.x, 0)); + sel = LoWord(PopUpMenuSelect(hMenu, location.v, location.h, 0)); DisposeMenu(hMenu); if (sel == selectclose) { toolwin_close(); @@ -930,16 +964,33 @@ static void openpopup(HIPoint location) } +static void makeskinimage(WindowRef win,PicHandle bmp, Rect* rect) { + ControlButtonContentInfo info; + ControlRef image; + EventHandlerRef ref; + EventTypeSpec list[]={ + { kEventClassControl, kEventControlContextualMenuClick }, + }; + + info.contentType = kControlContentPictHandle; + info.u.picture = bmp; + CreatePictureControl(win, rect, &info, true, &image); + SetControlID(image, &imageid); + InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)win, &ref); +} + +static void opentoolwin_puma(WindowRef win) { + if (np2tool.posy < 35) np2tool.posy = 35; + if (np2tool.posx < 5 ) np2tool.posx = 5; + MoveWindow(win, np2tool.posx, np2tool.posy, true); + ShowWindow(win); +} + void toolwin_open(void) { PicHandle hbmp; WindowRef hWnd = NULL; Rect bounds; - ControlRef image; - EventTypeSpec list[]={ - { kEventClassControl, kEventControlContextualMenuClick }, - }; - EventHandlerRef ref; if (toolwin.hwnd) { toolwin_close(); @@ -960,29 +1011,21 @@ void toolwin_open(void) { goto twope_err2; } - if (isPUMA) { + + SetWindowBounds(hWnd, kWindowContentRgn, &bounds); + if (isPUMA) { toolwincreate(hWnd); + makeskinimage(hWnd, hbmp, &bounds); } - SizeWindow(hWnd, bounds.right-bounds.left, bounds.bottom-bounds.top, true); - ControlButtonContentInfo info; - info.contentType = kControlContentPictHandle; - info.u.picture = hbmp; - CreatePictureControl(hWnd, &bounds, &info, true, &image); - InstallControlEventHandler (image, NewEventHandlerUPP(cfControlproc), GetEventTypeCount(list), list, (void *)hWnd, &ref); - if (!isPUMA) { + else { + makeskinimage(hWnd, hbmp, &bounds); toolwincreate(hWnd); } #ifndef AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER - if (np2tool.posy < 35) np2tool.posy = 35; - if (np2tool.posx < 5 ) np2tool.posx = 5; - MoveWindow(hWnd, np2tool.posx, np2tool.posy, true); - ShowWindow(hWnd); + opentoolwin_puma(hWnd); #else 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); + opentoolwin_puma(hWnd); } else { Rect mainbounds; @@ -996,6 +1039,8 @@ void toolwin_open(void) { } SetDrawerOffsets(hWnd, width/2-11, width/2-11); SetDrawerPreferredEdge(hWnd, kWindowEdgeTop); + const HISize size = {bounds.right-bounds.left, bounds.bottom-bounds.top}; + SetWindowResizeLimits(hWnd, &size, &size); OpenDrawer(hWnd, kWindowEdgeDefault, 1); } #endif