static void mac_groweventlog(WindowPtr window, EventRecord *event) { Session *s = mac_windowsession(window); Rect limits; long grow_result; #if TARGET_API_MAC_CARBON Rect rect; Point cellsize; #else GrafPtr saveport; #endif SetRect(&limits, 15, 0, SHRT_MAX, SHRT_MAX); grow_result = GrowWindow(window, event->where, &limits); if (grow_result == 0) return; SizeWindow(window, LoWord(grow_result), HiWord(grow_result), TRUE); LSize(LoWord(grow_result) - 15, HiWord(grow_result), s->eventlog); mac_adjusteventlogscrollbar(s); /* We would use SetListCellSize in Carbon, but it's missing. */ (*s->eventlog)->cellSize.h = LoWord(grow_result) - 15; #if TARGET_API_MAC_CARBON cellsize.h = LoWord(grow_result) - 15; GetListViewBounds(s->eventlog, &rect); InvalWindowRect(window, &rect); #else GetPort(&saveport); SetPort(window); InvalRect(&(*s->eventlog)->rView); SetPort(saveport); #endif }
// -------------------------------------------------------------------------------------- void HandleContentClick(WindowRef window, Point mouseLocation, EventModifiers modifiers) { ListHandle iconList; Rect iconListRect; Boolean isDoubleClick; Cell theCell; GetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); GetListViewBounds(iconList, &iconListRect); iconListRect.right += kScrollBarWidth; SetPortWindowPort(window); GlobalToLocal(&mouseLocation); if (PtInRect(mouseLocation, &iconListRect)) { SInt16 pixelDepth; Boolean isColorDevice; GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); // if LClick causes the list selection to change, or the isDoubleClick = LClick(mouseLocation, modifiers, iconList); // scroll bar SetPt(&theCell, 0, 0); // to change, the affected cells are LGetSelect(true, &theCell, iconList); // immediately drawn (no update event) if ((theCell.v + 1) != gPanelNumber) changePanel(window, theCell.v + 1); } }
// -------------------------------------------------------------------------------------- static void drawFrameAndFocus(ListHandle list, Boolean active, WindowRef window) { Rect borderRect; GetListViewBounds(list, &borderRect); borderRect.right += kScrollBarWidth; if (active) { SetThemeWindowBackground(window, kThemeBrushModelessDialogBackgroundActive, false); DrawThemeListBoxFrame(&borderRect, kThemeStateActive); DrawThemeFocusRect(&borderRect, true); } else { SetThemeWindowBackground(window, kThemeBrushModelessDialogBackgroundInactive, false); DrawThemeFocusRect(&borderRect, false); DrawThemeListBoxFrame(&borderRect, kThemeStateInactive); } }
// -------------------------------------------------------------------------------------- static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef event, void *junk) { #pragma unused (nextHandler, junk) OSStatus result = eventNotHandledErr; UInt32 eventClass, eventKind; WindowRef prefsWindow; Point mouseLocation, minWindowBounds; UInt32 modifiers; ControlRef listScrollBar; ListHandle iconList; Rect iconListRect; eventClass = GetEventClass(event); eventKind = GetEventKind(event); switch (eventClass) { case kEventClassWindow: GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &prefsWindow); switch (eventKind) { case kEventWindowActivated: HandleActivate(prefsWindow, true); result = noErr; break; case kEventWindowDeactivated: HandleActivate(prefsWindow, false); result = noErr; break; case kEventWindowHandleContentClick: GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mouseLocation); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); HandleContentClick(prefsWindow, mouseLocation, (EventModifiers)modifiers); result = noErr; break; case kEventWindowGetMinimumSize: SetPt(&minWindowBounds, gPrefsWindowWidth, gPrefsWindowHeight); SetEventParameter(event, kEventParamDimensions, typeQDPoint, sizeof(Point), &minWindowBounds); result = noErr; break; case kEventWindowResizeCompleted: AdjustControls(prefsWindow); result = noErr; break; case kEventWindowClose: ClosePrefsWindow(prefsWindow); result = noErr; break; case kEventWindowDrawContent: HandleDrawContent(prefsWindow); result = noErr; break; case kEventWindowContextualMenuSelect: result = noErr; // eat contextual menu clicks break; } break; case kEventClassControl: // we need to respond to clicks in the list's scroll bar switch (eventKind) // kEventControlClick instead of kEventControlHit { // because the control click must be tracked case kEventControlClick: // with LClick instead of the default handler GetEventParameter(event, kEventParamDirectObject, typeControlRef, NULL, sizeof(ControlRef), NULL, &listScrollBar); prefsWindow = GetControlOwner(listScrollBar); GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); if (listScrollBar == GetListVerticalScrollBar(iconList)) { GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mouseLocation); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); HandleContentClick(prefsWindow, mouseLocation, (EventModifiers)modifiers); result = noErr; } break; } break; case kEventClassMouse: switch (eventKind) { case kEventMouseWheelMoved: GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mouseLocation); GlobalToLocal(&mouseLocation); GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &prefsWindow); GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); GetListViewBounds(iconList, &iconListRect); iconListRect.right += kScrollBarWidth; if (PtInRect(mouseLocation, &iconListRect)) { EventMouseWheelAxis axis; long mouseWheelDelta; SInt16 pixelDepth; Boolean isColorDevice; GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(EventMouseWheelAxis), NULL, &axis); GetEventParameter(event, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(long), NULL, &mouseWheelDelta); GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); // LScroll draws the newly visible cells immediately if (axis == kEventMouseWheelAxisX) // (no update event) LScroll(-mouseWheelDelta, 0, iconList); else // axis == kEventMouseWheelAxisY LScroll(0, -mouseWheelDelta, iconList); result = noErr; } break; } break; case kEventClassTextInput: switch (eventKind) { case kEventTextInputUnicodeForKeyEvent: prefsWindow = FrontNonFloatingWindow(); if (prefsWindow != NULL) { EventRef keyboardEvent; UInt32 keyCode; GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, sizeof(EventRef), NULL, &keyboardEvent); GetEventParameter(keyboardEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode); HandleKeyDown((char)keyCode, prefsWindow); result = noErr; } break; } break; } return result; } // windowEventHandler
// -------------------------------------------------------------------------------------- void AdjustControls(WindowRef prefsWindow) { Rect contentRect, listViewRect; ControlRef rootControl, userPane; SInt16 userPaneWidth, userPaneHeight; UInt16 panelIndex; ListHandle iconList; short oldListHeight, newListHeight; GetWindowBounds(prefsWindow, kWindowContentRgn, &contentRect); userPaneWidth = (contentRect.right - contentRect.left) - (gWindowEdgeSpacing + kListWidth + kScrollBarWidth + kControlSpacing) - (kSizeBoxWidth + gMinimumSpacing); userPaneHeight = (contentRect.bottom - contentRect.top) - gWindowEdgeSpacing - (kSizeBoxWidth + gMinimumSpacing); GetRootControl(prefsWindow, &rootControl); for (panelIndex = 1; panelIndex <= kNumberOfRows; panelIndex++) { GetIndexedSubControl(rootControl, panelIndex, &userPane); SizeControl(userPane, userPaneWidth, userPaneHeight); } GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); GetListViewBounds(iconList, &listViewRect); oldListHeight = listViewRect.bottom - listViewRect.top; newListHeight = (contentRect.bottom - contentRect.top) - gWindowEdgeSpacing - gWindowEdgeSpacing; newListHeight -= newListHeight % kCellHeight; // make the list height a multiple if (newListHeight > kMaxListHeight) // of the cell height and don't make newListHeight = kMaxListHeight; // it bigger than we have cells for if (newListHeight != oldListHeight) { Rect invalRect; listViewRect.right += kScrollBarWidth; // we will need to redraw the scroll bar as well // we need to invalidate the area where a cell will be drawn or erased if (newListHeight > oldListHeight) SetRect(&invalRect, listViewRect.left - 5, listViewRect.bottom - 5, listViewRect.right + 5, contentRect.bottom); // the extra 5 pixels are // to cause the bottom of the list box frame to get erased else SetRect(&invalRect, listViewRect.left - 5, gWindowEdgeSpacing + newListHeight - 5, listViewRect.right + 5, contentRect.bottom); // the drawing section is as far down as possible to avoid any screen flickering DrawThemeFocusRect(&listViewRect, false); // erase the focus rectangle LSize(kListWidth, newListHeight, iconList); // resize the List drawFrameAndFocus(iconList, true, prefsWindow); // draw the focus rectangle back InvalWindowRect(prefsWindow, &invalRect); } #if TARGET_API_MAC_OS8 CalculateBalloonHelpRects(prefsWindow); #endif } // AdjustControls