Fix a possible quit crash caused by the last checkin, if AppKit closes the toolkit window for us on quit. Also rename mPanel to mTooltipWindow.

This commit is contained in:
smfr%smfr.org 2005-07-14 03:38:38 +00:00
Родитель c2a0855cd2
Коммит a6f6ee26b2
2 изменённых файлов: 26 добавлений и 18 удалений

Просмотреть файл

@ -43,7 +43,7 @@
@interface ToolTip : NSObject @interface ToolTip : NSObject
{ {
NSWindow* mPanel; NSWindow* mTooltipWindow;
NSTextField* mTextField; NSTextField* mTextField;
NSTextView* mTextView; NSTextView* mTextView;
} }

Просмотреть файл

@ -54,22 +54,28 @@ const float kVOffset = 20.0;
- (id)init - (id)init
{ {
self = [super init]; if ((self = [super init]))
if (self) { {
mPanel = [[NSWindow alloc] initWithContentRect:NSMakeRect(0.0, 0.0, kMaxTextFieldWidth, 0.0) // the ref from -alloc is balanced by the -release in dealloc
mTooltipWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0.0, 0.0, kMaxTextFieldWidth, 0.0)
styleMask:NSBorderlessWindowMask styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:YES]; defer:YES];
// we don't want closing the window to release it, because we aren't always in control
// of the close (AppKit may do it on quit).
[mTooltipWindow setReleasedWhenClosed:NO];
// Create a textfield as the content of our new window. // Create a textfield as the content of our new window.
// Field occupies all but the top 2 and bottom 2 pixels of the panel (bug 149635) // Field occupies all but the top 2 and bottom 2 pixels of the panel (bug 149635)
mTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0, kBorderPadding, kMaxTextFieldWidth, 0.0)]; mTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0, kBorderPadding, kMaxTextFieldWidth, 0.0)];
[[mPanel contentView] addSubview:mTextView]; [[mTooltipWindow contentView] addSubview:mTextView];
[mTextView release]; // window holds ref [mTextView release]; // window holds ref
// set up the panel // set up the panel
[mPanel setHasShadow:YES]; [mTooltipWindow setHasShadow:YES];
[mPanel setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.81 alpha:1.0]]; [mTooltipWindow setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:0.81 alpha:1.0]];
// set up the text view // set up the text view
[mTextView setDrawsBackground:NO]; [mTextView setDrawsBackground:NO];
@ -87,7 +93,9 @@ const float kVOffset = 20.0;
{ {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[mPanel close]; // this releases [mTooltipWindow close]; // we set the window not to release on -close
[mTooltipWindow release];
[super dealloc]; [super dealloc];
} }
@ -145,37 +153,37 @@ const float kVOffset = 20.0;
// size the panel correctly, taking border into account // size the panel correctly, taking border into account
NSSize textSize = textViewFrame.size; NSSize textSize = textViewFrame.size;
textSize.height += kBorderPadding + kBorderPadding; textSize.height += kBorderPadding + kBorderPadding;
[mPanel setContentSize:textSize]; [mTooltipWindow setContentSize:textSize];
// We try to put the top left point right below the cursor. If that doesn't fit // We try to put the top left point right below the cursor. If that doesn't fit
// on screen, put the bottom left point above the cursor. // on screen, put the bottom left point above the cursor.
if (point.y - kVOffset - textSize.height > NSMinY(screenFrame)) { if (point.y - kVOffset - textSize.height > NSMinY(screenFrame)) {
point.y -= kVOffset; point.y -= kVOffset;
[mPanel setFrameTopLeftPoint:point]; [mTooltipWindow setFrameTopLeftPoint:point];
} }
else { else {
point.y += kVOffset / 2.5; point.y += kVOffset / 2.5;
[mPanel setFrameOrigin:point]; [mTooltipWindow setFrameOrigin:point];
} }
// if it doesn't fit on screen horizontally, adjust so that it does // if it doesn't fit on screen horizontally, adjust so that it does
float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mPanel frame]); float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mTooltipWindow frame]);
if (amountOffScreenX < 0) { if (amountOffScreenX < 0) {
NSRect movedFrame = [mPanel frame]; NSRect movedFrame = [mTooltipWindow frame];
movedFrame.origin.x += amountOffScreenX; movedFrame.origin.x += amountOffScreenX;
[mPanel setFrame:movedFrame display:NO]; [mTooltipWindow setFrame:movedFrame display:NO];
} }
// add as a child window // add as a child window
[inWindow addChildWindow:mPanel ordered:NSWindowAbove]; [inWindow addChildWindow:mTooltipWindow ordered:NSWindowAbove];
// show the panel // show the panel
[mPanel orderFront:nil]; [mTooltipWindow orderFront:nil];
} }
- (void)closeToolTip - (void)closeToolTip
{ {
[[mPanel parentWindow] removeChildWindow:mPanel]; [[mTooltipWindow parentWindow] removeChildWindow:mTooltipWindow];
[mPanel orderOut:nil]; [mTooltipWindow orderOut:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
} }