/* * GetWindowName - */ static int privateGetWindowName(void *pWin, char **ppName, Atom atom) { int retFormat, retValue; unsigned long nItems, bytesLeft, origLen; unsigned char *strName; Atom retType; /* FIXME: look for memory leak */ if( (retValue = GetWindowProperty(pWin, atom, 0L, 0L, False, AnyPropertyType, &retType, &retFormat, &nItems, &bytesLeft, (unsigned char**)NULL)) != Success){ ErrorF("GetWindowName: GetWindowProperty failed\n"); return retValue; } origLen = bytesLeft; if( !( strName = malloc( bytesLeft + 1) ) ) FatalError("GetWindowName: malloc failed\n"); if( (retValue = GetWindowProperty(pWin, atom, 0L, bytesLeft, False, AnyPropertyType, &retType, &retFormat, &nItems, &bytesLeft, (unsigned char**)ppName)) != Success){ ErrorF("GetWindowName: GetWindowProperty failed\n"); free(strName); return retValue; } memcpy(strName, *ppName, origLen); strName[origLen] = 0; *ppName = strName; #ifdef NXWIN_MULTIWINDOW_DEBUG ErrorF("GetWindowName: strName %s\n\torigLen %d\n\t*ppName %s\n", strName, origLen, *ppName); #endif return Success; }
int XWindow::GetWMType () { Atom *args = NULL; unsigned int i = 0; int wmType = 0; int metacityHack = 0; unsigned long nitems = 0; // check if WM supports layers if (GetWindowProperty (XA_WIN_PROTOCOLS, &args, &nitems)) { PTRACE(4, "X11\tDetected WM supports layers"); for (i = 0; i < nitems; i++) { if (args [i] == XA_WIN_LAYER) { wmType |= wm_LAYER; metacityHack |= 1; } else metacityHack |= 2; } XLockDisplay (_display); XFree (args); XUnlockDisplay (_display); // metacity WM reports that it supports layers, // but it is not really true :-) if (wmType && metacityHack == 1) { wmType ^= wm_LAYER; PTRACE(4, "X11\tUsing workaround for Metacity bug"); } } // NETWM if (GetWindowProperty (XA_NET_SUPPORTED, &args, &nitems)) { PTRACE(4, "X11\tDetected wm supports NetWM."); for (i = 0; i < nitems; i++) wmType |= GetSupportedState (args[i]); XLockDisplay (_display); XFree (args); XUnlockDisplay (_display); } // unknown WM if (wmType == 0) { PTRACE(4, "X11\tUnknown wm type..."); } return wmType; }
// -------------------------------------------------------------------------------------- void DisplayHelpBalloons(WindowRef prefsWindow) { GrafPtr savedPort; Point mouseLocation; Rect hotRects[3]; short hotRectID; static int previousHotRectID = kNotInHotRect; GetPort(&savedPort); SetPortWindowPort(prefsWindow); GetMouse(&mouseLocation); GetWindowProperty(prefsWindow, kAppSignature, kHotRectsTag, 3 * sizeof(Rect), NULL, hotRects); for (hotRectID = kInList; hotRectID < kNotInHotRect; hotRectID++) { if (PtInRect(mouseLocation, &hotRects[hotRectID])) { if (hotRectID != previousHotRectID) { HMMessageRecord helpMessage; Point tips[3]; helpMessage.hmmHelpType = khmmStringRes; helpMessage.u.hmmStringRes.hmmResID = rHelpStrings; helpMessage.u.hmmStringRes.hmmIndex = hotRectID + 1; GetWindowProperty(prefsWindow, kAppSignature, kBalloonTipsTag, 3 * sizeof(Point), NULL, tips); LocalToGlobal(&tips[hotRectID]); LocalToGlobal(&topLeft(hotRects[hotRectID])); LocalToGlobal(&botRight(hotRects[hotRectID])); HMShowBalloon(&helpMessage, tips[hotRectID], &hotRects[hotRectID], NULL, kBalloonWDEFID, kTopLeftTipPointsLeftVariant, kHMRegularWindow); } break; } } previousHotRectID = hotRectID; SetPort(savedPort); }
// -------------------------------------------------------------------------------------- void HandleDrawContent(WindowRef prefsWindow) { RgnHandle visibleRegion; ListHandle iconList; GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); visibleRegion = NewRgn(); GetPortVisibleRegion(GetWindowPort(prefsWindow), visibleRegion); if (visibleRegion != NULL) { Boolean active = IsWindowHilited(prefsWindow); SInt16 pixelDepth; Boolean isColorDevice; if (active) SetThemeWindowBackground(prefsWindow, kThemeBrushModelessDialogBackgroundActive, false); else SetThemeWindowBackground(prefsWindow, kThemeBrushModelessDialogBackgroundInactive, false); EraseRgn(visibleRegion); UpdateControls(prefsWindow, visibleRegion); GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); LUpdate(visibleRegion, iconList); drawFrameAndFocus(iconList, active, prefsWindow); DisposeRgn(visibleRegion); } }
// -------------------------------------------------------------------------------------- void CalculateBalloonHelpRects(WindowRef prefsWindow) { GrafPtr savedPort; ListHandle iconList; Point tips[3]; Rect hotRects[3], userPaneBounds; ControlRef rootControl, userPane; GetPort(&savedPort); SetPortWindowPort(prefsWindow); GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); SetPt(&tips[0], kPlatinumWindowEdgeSpacing + kListWidth, kPlatinumWindowEdgeSpacing + 10); SetRect(&hotRects[0], (*iconList)->rView.left, (*iconList)->rView.top, (*iconList)->rView.right, (*iconList)->rView.bottom); // set the icon list tip // and hot rectangle SetPt(&tips[1], 203, 219); // set the static text tip and hot rectangle SetRect(&hotRects[1], 149, 213, 213, 229); // these coordinates are all arbitrary GetRootControl(prefsWindow, &rootControl); // the only thing embedded in the GetIndexedSubControl(rootControl, 1, &userPane); // root control is the user panes and SetRect(&userPaneBounds, (*userPane)->contrlRect.left, (*userPane)->contrlRect.top, (*userPane)->contrlRect.right, (*userPane)->contrlRect.bottom); // they're // all the same size SetPt(&tips[2], userPaneBounds.right - 10, userPaneBounds.top + 10); SetRect(&hotRects[2], userPaneBounds.left, userPaneBounds.top, userPaneBounds.right, userPaneBounds.bottom); // set the user pane tip and hot rectangle SetWindowProperty(prefsWindow, kAppSignature, kBalloonTipsTag, 3 * sizeof(Point), tips); SetWindowProperty(prefsWindow, kAppSignature, kHotRectsTag, 3 * sizeof(Rect), hotRects); SetPort(savedPort); }
static void OPL_DSN_notification_item (ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message) { OSStatus err; WindowRef window; window = GetFrontWindowOfClass(kMovableModalWindowClass, false); if (window == NULL) return; // get LoginDialog instance OPL_LoginDialog *dlg = NULL; err = GetWindowProperty(window, kPropertyCreator, kPropertyTag, sizeof(dlg), NULL, &dlg); require_noerr(err, error); if (!dlg) return; switch (message) { case kDataBrowserItemDoubleClicked: dlg->dir_dblclick(); break; }; error: return; }
// -------------------------------------------------------------------------------------- int main(void) { WindowRef window; FourCharCode prefsWindowKind; initialize(); // initialization RunApplicationEventLoop(); // application event loop // finalization for (window = FrontNonFloatingWindow(); window != NULL; window = FrontNonFloatingWindow()) { GetWindowProperty(window, kAppSignature, kPrefsWindowKindTag, sizeof(FourCharCode), NULL, &prefsWindowKind); if (prefsWindowKind == kPrefsWindowKindDialog) ClosePrefsDialog(window); else // kPrefsWindowKindWindow { HICommand closeCommand; closeCommand.attributes = 0; // not from a menu, control, or window closeCommand.commandID = kHICommandClose; ProcessHICommand(&closeCommand); } } DisposeAEEventHandlerUPP(gOpenAppAEHandler); DisposeAEEventHandlerUPP(gQuitAppAEHandler); DisposeAEEventHandlerUPP(gViewsFontChangedAEHandler); DisposeEventHandlerUPP(gAppEventHandler); return 0; }
// -------------------------------------------------------------------------------------- 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); } }
TXNObject WindowGetTXNObj( WindowRef window, OSType key ) { OSStatus status = paramErr; MyMLTEData *pMyMLTEData = NULL; status = GetWindowProperty( window, kMyPropertyCreator, key, sizeof(Ptr), NULL, &pMyMLTEData ); require_noerr( status, CantGetObj ); return pMyMLTEData->fTXNObj; CantGetObj: return NULL; }
SInt32 TextViewGetHorizScrollCache( WindowRef window, OSType key ) { OSStatus status = paramErr; MyMLTEData *pMyMLTEData = NULL; // recover our data from the window status = GetWindowProperty( window, kMyPropertyCreator, key, sizeof(Ptr), NULL, &pMyMLTEData ); require_noerr( status, CantGetObj ); return pMyMLTEData->fHorizScrollCache; CantGetObj: return 0; }
OSStatus QuartzEventHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData ) { OSStatus err = eventNotHandledErr; UInt32 eventKind = GetEventKind( inEvent ), RWinCode, devsize; int devnum; WindowRef EventWindow; EventRef REvent; NewDevDesc *dd; if( GetEventClass(inEvent) != kEventClassWindow) return(err); GetEventParameter(inEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(EventWindow), NULL, &EventWindow); if(GetWindowProperty(EventWindow, kRAppSignature, 'QRTZ', sizeof(int), NULL, &devnum) != noErr) return eventNotHandledErr; switch(eventKind){ case kEventWindowClose: { KillDevice(GetDevice(devnum)); err= noErr; } break; case kEventWindowBoundsChanged: if( (dd = ((GEDevDesc*) GetDevice(devnum))->dev) ){ QuartzDesc *xd = (QuartzDesc *) dd-> deviceSpecific; Rect portRect; GetWindowPortBounds ( xd->window, & portRect ) ; if( (xd->windowWidth != portRect.right) || (xd->windowHeight != portRect.bottom) ){ xd->resize = true; dd->size(&(dd->left), &(dd->right), &(dd->bottom), &(dd->top), dd); xd->resize = false; GEplayDisplayList((GEDevDesc*) GetDevice(devnum)); } err = noErr; } break; default: break; } return err; }
void TextViewSetVertScrollCache( WindowRef window, SInt32 value, OSType key ) { OSStatus status = paramErr; MyMLTEData *pMyMLTEData = NULL; require( window != NULL, CantGetObj ); // recover our data from the window status = GetWindowProperty( window, kMyPropertyCreator, key, sizeof(Ptr), NULL, &pMyMLTEData ); require_noerr( status, CantGetObj ); pMyMLTEData->fVertScrollCache = value; CantGetObj: return; }
OSStatus TextViewDelete( WindowRef window, OSType key ) { OSStatus status = eventNotHandledErr; MyMLTEData *pMyMLTEData = NULL; // recover our data from the window status = GetWindowProperty( window, kMyPropertyCreator, key, sizeof(Ptr), NULL, &pMyMLTEData ); require_action( status == noErr, CantGetObj, status = eventNotHandledErr ); // clean up allocated memory TXNDeleteObject( pMyMLTEData->fTXNObj ); DisposePtr( (char*)pMyMLTEData ); status = RemoveWindowProperty( window, kMyPropertyCreator, key ); CantGetObj: return status; }
// -------------------------------------------------------------------------------------- void ClosePrefsWindow(WindowRef prefsWindow) { ListHandle iconList; HideWindow(prefsWindow); DisableMenuItem(GetMenuRef(mFile), iClose); GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); ReleaseIconListIcons(iconList); LDispose(iconList); #if TARGET_API_MAC_CARBON DisposeListDefUPP(gIconListDef); DisposeEventHandlerUPP(gWindowEventHandler); DisposePrefsWindowHelpTags(); #endif DisposeWindow(prefsWindow); EnableMenuItem(GetMenuRef(mDemonstration), iPrefsWindow); }
// -------------------------------------------------------------------------------------- void RedrawPrefsWindowList(WindowRef prefsWindow) { ListHandle iconList; ListBounds visibleCells; SInt16 pixelDepth; Boolean isColorDevice; short row; Cell theCell; GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); GetListVisibleCells(iconList, &visibleCells); GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); for (row = visibleCells.top; row < visibleCells.bottom; row++) // redraw just the { // visible cells SetPt(&theCell, 0, row); LDraw(theCell, iconList); } }
// When the user adjusts the scroll controls, tell the MLTE object to update // the displayed text accordingly, and also save the control values so we // can calculate deltas later. OSStatus TextViewCustomScroll( WindowRef window, OSType orientation, TXNScrollUnit scrollUnit, SInt32 textViewDelta, SInt32 cacheValue, OSType key ) { OSStatus status = paramErr; SInt32 vDelta, hDelta; MyMLTEData *pMyMLTEData = NULL; // recover our data from the window status = GetWindowProperty( window, kMyPropertyCreator, key, sizeof(Ptr), NULL, &pMyMLTEData ); require_noerr( status, CantGetObj ); // We are only handling scrolling in one direction, but when we tell MLTE to // scroll, we pass data for both directions. So set the delta for the correct // orientation, and the other orientation will have zero delta. if( orientation == kMyVerticalScrollBar ) { vDelta = textViewDelta; hDelta = 0; // We will need to know the last known control value // to calculate the delta on the next time around pMyMLTEData->fVertScrollCache = cacheValue; } else { hDelta = textViewDelta, vDelta = 0; // We will need to know the last known control value next time around // to calculate the delta on the next time around pMyMLTEData->fHorizScrollCache = cacheValue; } status = TXNScroll( pMyMLTEData->fTXNObj, scrollUnit, scrollUnit, &vDelta, &hDelta ); CantGetObj: return status; }
// -------------------------------------------------------------------------------------- void HandleActivate(WindowRef window, Boolean activate) { ControlRef rootControl; ListHandle iconList; SInt16 pixelDepth; Boolean isColorDevice; GetRootControl(window, &rootControl); GetWindowProperty(window, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); SetPortWindowPort(window); GetWindowDeviceDepthAndColor(window, &pixelDepth, &isColorDevice); if (activate) { SetThemeTextColor(kThemeTextColorModelessDialogActive, pixelDepth, isColorDevice); ActivateControl(rootControl); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); LActivate(true, iconList); RedrawPrefsWindowList(window); // redraw the list with the active appearance drawFrameAndFocus(iconList, true, window); EnableMenuItem(GetMenuRef(mFile), iClose); } else // deactivate { SetThemeTextColor(kThemeTextColorModelessDialogInactive, pixelDepth, isColorDevice); DeactivateControl(rootControl); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); LActivate(false, iconList); RedrawPrefsWindowList(window); // redraw the list with the inactive appearance drawFrameAndFocus(iconList, false, window); DisableMenuItem(GetMenuRef(mFile), iClose); } }
// -------------------------------------------------------------------------------------- static pascal OSErr viewsFontChangedAEHandler(const AppleEvent *appleEvent, AppleEvent *reply, long refcon) { #pragma unused (reply, refcon) OSErr error; DescType returnedType; Size actualSize; error = AEGetAttributePtr(appleEvent, keyMissedKeywordAttr, typeWildCard, &returnedType, NULL, 0, &actualSize); if (error == noErr) error = errAEParamMissed; else if (error == errAEDescNotFound) { WindowRef window; FourCharCode prefsWindowKind; for (window = GetFrontWindowOfClass(kDocumentWindowClass, false); window != NULL; window = GetNextWindowOfClass(window, kDocumentWindowClass, false)) { GetWindowProperty(window, kAppSignature, kPrefsWindowKindTag, sizeof(FourCharCode), NULL, &prefsWindowKind); if (prefsWindowKind == kPrefsWindowKindDialog) RedrawPrefsDialogDataBrowser(window); else // kPrefsWindowKindWindow RedrawPrefsWindowDataBrowser(window); } error = noErr; } return error; }
void XDestroyWindow( Display *display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; WindowRef winRef; /* * Remove any dangling pointers that may exist if the window we are * deleting is being tracked by the grab code. */ TkPointerDeadWindow(macWin->winPtr); macWin->toplevel->referenceCount--; if (!Tk_IsTopLevel(macWin->winPtr)) { TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); if (macWin->winPtr->parentPtr != NULL) { TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); } if (macWin->visRgn) { CFRelease(macWin->visRgn); } if (macWin->aboveVisRgn) { CFRelease(macWin->aboveVisRgn); } if (macWin->toplevel->referenceCount == 0) { ckfree((char *) macWin->toplevel); } ckfree((char *) macWin); return; } /* * We are relying on the Activate Mac OS event to pass the focus away from * a window that is getting Destroyed to the Front non-floating window. BUT * we don't get activate events when a floating window is destroyed, since * the front non-floating window doesn't in fact get activated... So maybe * we can check here and if we are destroying a floating window, we can * pass the focus back to the front non-floating window... */ if (macWin->grafPtr != NULL) { TkWindow *focusPtr = TkGetFocusWin(macWin->winPtr); if (focusPtr == NULL || (focusPtr->mainPtr->winPtr == macWin->winPtr)) { winRef = TkMacOSXDrawableWindow(window); if (TkpIsWindowFloating (winRef)) { Window window = TkMacOSXGetXWindow(ActiveNonFloatingWindow()); if (window != None) { TkMacOSXGenerateFocusEvent(window, 1); } } } } if (macWin->visRgn) { CFRelease(macWin->visRgn); } if (macWin->aboveVisRgn) { CFRelease(macWin->aboveVisRgn); } /* * Delete the Mac window and remove it from the windowTable. The window * could be NULL if the window was never mapped. However, we don't do this * for embedded windows, they don't go in the window list, and they do not * own their portPtr's. */ if (!Tk_IsEmbedded(macWin->winPtr)) { WindowRef winRef = TkMacOSXDrawableWindow(window); if (winRef) { TkMacOSXWindowList *listPtr, *prevPtr; WindowGroupRef group; if (GetWindowProperty(winRef, 'Tk ', 'TsGp', sizeof(group), NULL, &group) == noErr) { TkDisplay *dispPtr = TkGetDisplayList(); ItemCount i = CountWindowGroupContents(group, kWindowGroupContentsReturnWindows); WindowRef macWin; WindowGroupRef newGroup; Window window; while (i > 0) { ChkErr(GetIndexedWindow, group, i--, 0, &macWin); if (!macWin) { continue; } window = TkMacOSXGetXWindow(macWin); newGroup = NULL; if (window != None) { TkWindow *winPtr = (TkWindow *) Tk_IdToWindow(dispPtr->display, window); if (winPtr && winPtr->wmInfoPtr) { newGroup = GetWindowGroupOfClass( winPtr->wmInfoPtr->macClass); } } if (!newGroup) { newGroup = GetWindowGroupOfClass(kDocumentWindowClass); } ChkErr(SetWindowGroup, macWin, newGroup); } ChkErr(SetWindowGroupOwner, group, NULL); ChkErr(ReleaseWindowGroup, group); } TkMacOSXUnregisterMacWindow(winRef); DisposeWindow(winRef); for (listPtr=tkMacOSXWindowListPtr, prevPtr=NULL; tkMacOSXWindowListPtr != NULL; prevPtr=listPtr, listPtr=listPtr->nextPtr) { if (listPtr->winPtr == macWin->winPtr) { if (prevPtr == NULL) { tkMacOSXWindowListPtr = listPtr->nextPtr; } else { prevPtr->nextPtr = listPtr->nextPtr; } ckfree((char *) listPtr); break; } } } } macWin->grafPtr = NULL; /* * Delay deletion of a toplevel data structure untill all children have * been deleted. */ if (macWin->toplevel->referenceCount == 0) { ckfree((char *) macWin->toplevel); } }
// -------------------------------------------------------------------------------------- void HandleKeyDown(char keyCode, WindowRef prefsWindow) { /* Why use the virtual key code instead of the character code? When the control key is held down it often masks out bit 7 of the character code, thus making it impossible to distinguish between some key presses such as page down (0x0C) and control-L (0x4C & ~bit7 = 0x0C). The virtual key codes, on the other hand, are unaffected by modifier keys. */ if ( (keyCode == kUpArrowKeyCode) || (keyCode == kDownArrowKeyCode) ) { ListHandle iconList; ListBounds bounds; short lastRow; Cell selectedCell; GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); GetListDataBounds(iconList, &bounds); lastRow = bounds.bottom - bounds.top - 1; SetPt(&selectedCell, 0, 0); LGetSelect(true, &selectedCell, iconList); if ( (keyCode == kUpArrowKeyCode) && (selectedCell.v > 0) ) { SInt16 pixelDepth; Boolean isColorDevice; GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); LSetSelect(false, selectedCell, iconList); // LSetSelect causes the indicated selectedCell.v--; // cell to be highlighted immediately (no update event) LSetSelect(true, selectedCell, iconList); LAutoScroll(iconList); // scroll the list in case the selected cell isn't in view changePanel(prefsWindow, selectedCell.v + 1); } else if ( (keyCode == kDownArrowKeyCode) && (selectedCell.v < lastRow) ) { SInt16 pixelDepth; Boolean isColorDevice; GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); LSetSelect(false, selectedCell, iconList); selectedCell.v++; LSetSelect(true, selectedCell, iconList); LAutoScroll(iconList); // scroll the list in case the selected cell isn't in view changePanel(prefsWindow, selectedCell.v + 1); } } else if ( (keyCode == kPageUpKeyCode) || (keyCode == kPageDownKeyCode) ) { ListHandle iconList; ListBounds visibleCells; SInt16 pixelDepth; Boolean isColorDevice; GetWindowProperty(prefsWindow, kAppSignature, kIconListTag, sizeof(ListHandle), NULL, &iconList); GetListVisibleCells(iconList, &visibleCells); GetWindowDeviceDepthAndColor(prefsWindow, &pixelDepth, &isColorDevice); SetThemeBackground(kThemeBrushWhite, pixelDepth, isColorDevice); // LScroll causes the affected cells to be drawn immediately if (keyCode == kPageUpKeyCode) // (no update event) LScroll(0, -(visibleCells.bottom - 1 - visibleCells.top), iconList); else // keyCode == kPageDownKeyCode LScroll(0, (visibleCells.bottom - 1 - visibleCells.top), iconList); } } // HandleKeyDown
// -------------------------------------------------------------------------------------- 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