Created
December 13, 2009 21:33
-
-
Save farcaller/255611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void) selectView:(id)dummy | |
| { | |
| NSEvent *event; | |
| id view; | |
| NSCursor *cursor = [NSCursor crosshairCursor]; | |
| NSDate *distantFuture = [NSDate distantFuture]; | |
| NSRect infoRect = NSMakeRect(0, 0, 290, 100); | |
| NSTextView *infoView = [[[NSTextView alloc] initWithFrame:NSZeroRect] autorelease]; | |
| [infoView setEditable:NO]; | |
| [infoView setSelectable:NO]; | |
| [infoView setDrawsBackground:NO]; | |
| [infoView setTextColor:[NSColor whiteColor]]; | |
| [infoView setFont:[NSFont controlContentFontOfSize:10]]; | |
| [infoView setTextContainerInset:NSMakeSize(4, 4)]; | |
| //[infoView setAutoresizingMask:NSViewHeightSizable|NSViewMinYMargin]; | |
| [infoView setVerticallyResizable:NO]; | |
| NSMutableParagraphStyle *paragraphStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; | |
| [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; | |
| [infoView setDefaultParagraphStyle:paragraphStyle]; | |
| NSPanel *infoWindow = [[[NSPanel alloc] initWithContentRect:infoRect styleMask:NSHUDWindowMask /*| NSTitledWindowMask*/ | NSUtilityWindowMask backing:NSBackingStoreBuffered defer:NO] autorelease]; | |
| [infoWindow setLevel:NSFloatingWindowLevel]; | |
| [infoWindow setContentView:infoView]; | |
| // NSWindow *focusWindow = [[[NSWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO] autorelease]; | |
| NSWindow *focusWindow = [[NSWindow alloc] initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO] ; | |
| [focusWindow setBackgroundColor:[NSColor selectedTextBackgroundColor]]; | |
| [focusWindow setAlphaValue:0.7]; | |
| [focusWindow setIgnoresMouseEvents:YES]; | |
| [cursor push]; | |
| selectedView = nil; | |
| [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuWillSendAction:) name:NSMenuWillSendActionNotification object:nil]; | |
| do | |
| { | |
| [cursor push]; | |
| event = [NSApp nextEventMatchingMask:~0 untilDate:distantFuture inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
| [cursor pop]; | |
| if ([event type] == NSMouseMoved) | |
| { | |
| NSInteger windowCount; | |
| NSInteger *windows; | |
| view = nil; | |
| NSCountWindows(&windowCount); | |
| windows = malloc(windowCount*sizeof(NSInteger)); | |
| NSWindowList(windowCount, windows); | |
| for (unsigned i = 0; i < windowCount; i++) | |
| { | |
| NSWindow *window = [NSApp windowWithWindowNumber:windows[i]]; | |
| if (window && window != focusWindow && window != infoWindow) | |
| { | |
| view = [[[window contentView] superview] hitTest:[window convertScreenToBase:[NSEvent mouseLocation]]]; | |
| if (view) break; | |
| } | |
| } | |
| free(windows); | |
| if (view) | |
| { | |
| NSRect rectInWindowCoordinates = [view convertRect:[view visibleRect] toView:nil];; | |
| NSRect rectInScreenCoordinates; | |
| NSSize size = NSMakeSize(220,21); | |
| rectInScreenCoordinates.size = rectInWindowCoordinates.size; | |
| rectInScreenCoordinates.origin = [[view window] convertBaseToScreen:rectInWindowCoordinates.origin]; | |
| if ([focusWindow parentWindow] != [view window]) | |
| { | |
| [[focusWindow parentWindow] removeChildWindow:focusWindow]; | |
| [[view window] addChildWindow:focusWindow ordered:NSWindowAbove]; | |
| } | |
| [focusWindow setFrame:rectInScreenCoordinates display:YES]; | |
| /* NSMutableString *infoString = [NSMutableString string]; | |
| [infoString appendFormat:@"Bounds:\t%@\n", printString([NSValue valueWithRect:[view bounds]])]; | |
| [infoString appendFormat:@"Frame:\t%@\n", printString([NSValue valueWithRect:[view frame]])]; | |
| [infoString appendFormat:@"Superview:\t%@\n", [[view superview] class]]; | |
| [infoString appendString:@"Subviews:\n"]; | |
| for (NSView *subview in [view subviews]) [infoString appendFormat:@"\t\t%@\n", [subview class]]; | |
| [infoView setString:infoString]; | |
| size = [[infoView textStorage] size]; | |
| size.width += 15; | |
| size.height += 10; | |
| */ | |
| NSPoint origin = NSMakePoint([NSEvent mouseLocation].x+12, [NSEvent mouseLocation].y-size.height-9); | |
| [infoWindow setFrame:NSMakeRect(origin.x, origin.y, size.width, size.height) display:YES animate:NO]; | |
| //[infoWindow setTitle:[NSString stringWithFormat:@"%@: %p", [view class], view]]; | |
| [infoView setString:[NSString stringWithFormat:@"%@: %p", [view class], view]]; | |
| [infoWindow orderFront:nil]; | |
| } | |
| else | |
| { | |
| [[focusWindow parentWindow] removeChildWindow:focusWindow]; | |
| [focusWindow orderOut:nil]; | |
| [infoWindow orderOut:nil]; | |
| //[self browseNothing]; | |
| } | |
| } | |
| } | |
| while ( [event type] != NSLeftMouseDown && selectedView == nil && !([event type] == NSKeyDown && [[event characters] characterAtIndex:0] == ESCAPE) ); | |
| [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMenuWillSendActionNotification object:nil]; | |
| [cursor pop]; | |
| [[focusWindow parentWindow] removeChildWindow:focusWindow]; | |
| [focusWindow close]; | |
| [infoWindow close]; | |
| if ( !([event type] == NSKeyDown && [[event characters] characterAtIndex:0] == ESCAPE) ) | |
| { | |
| if (selectedView == nil) | |
| view = [[[[event window] contentView] superview] hitTest:[event locationInWindow]]; | |
| else | |
| view = selectedView; | |
| [self setRootObject:view]; | |
| [selectedView release]; | |
| [[self window] performSelector:@selector(makeKeyAndOrderFront:) withObject:nil afterDelay:0]; | |
| [NSApp activateIgnoringOtherApps:YES]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment