Adding tooltip support for TITLE in html (bug 149635)

This commit is contained in:
pinkerton%netscape.com 2002-08-08 19:36:13 +00:00
Родитель 45e59826d8
Коммит 55477057ee
28 изменённых файлов: 1516 добавлений и 112 удалений

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

@ -39,6 +39,7 @@
#import "CHBrowserView.h" #import "CHBrowserView.h"
@class BrowserWindowController; @class BrowserWindowController;
@class CHToolTip;
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer> @interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
{ {
@ -61,6 +62,7 @@
CHBrowserView* mBrowserView; CHBrowserView* mBrowserView;
NSString* defaultStatus; NSString* defaultStatus;
NSString* loadingStatus; NSString* loadingStatus;
CHToolTip* toolTip;
BOOL mIsPrimary; BOOL mIsPrimary;
BOOL mIsBusy; BOOL mIsBusy;

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

@ -40,6 +40,7 @@
#import "CHBrowserWrapper.h" #import "CHBrowserWrapper.h"
#import "BrowserWindowController.h" #import "BrowserWindowController.h"
#import "BookmarksService.h" #import "BookmarksService.h"
#import "ToolTip.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -87,6 +88,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[defaultStatus release]; [defaultStatus release];
[loadingStatus release]; [loadingStatus release];
[toolTip release];
[super dealloc]; [super dealloc];
} }
@ -131,6 +133,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
mIsBusy = NO; mIsBusy = NO;
mListenersAttached = NO; mListenersAttached = NO;
mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; mSecureState = nsIWebProgressListener::STATE_IS_INSECURE;
toolTip = [[ToolTip alloc] init];
} }
return self; return self;
} }
@ -414,38 +417,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// //
- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text - (void)onShowTooltip:(NSPoint)where withText:(NSString*)text
{ {
#if NOT_YET NSPoint point = [[self window] convertBaseToScreen:[self convertPoint: where toView:nil]];
HMHelpContentRec info; [toolTip showToolTipAtPoint: point withString: text];
info.version = kMacHelpVersion;
// convert to global QD coordinates, which is what HMDisplayTag expects. Only
// the main device is important in this calculation since that's where the
// coordinate systems differ.
NSPoint p = {where.x, where.y};
p = [[self window] convertBaseToScreen:[self convertPoint:p toView:nil]];
GDHandle screenDevice = ::GetMainDevice();
Rect screenRect = (**screenDevice).gdRect;
short screenHeight = screenRect.bottom - screenRect.top;
p.y = screenRect.top + (screenHeight - p.y);
Rect r = {p.y, p.x, p.y + 15, p.x + 15}; // center it under the mouse cursorsure
info.absHotRect = r;
info.tagSide = kHMOutsideBottomCenterAligned;
// setup the content of the tooltip. recall that a NSString is really just a CFString under the hood
info.content[0].contentType = kHMCFStringContent;
info.content[0].u.tagCFString = (CFStringRef) text;
info.content[1] = info.content[0];
::HMDisplayTag(&info);
#endif
} }
- (void)onHideTooltip - (void)onHideTooltip
{ {
#if NOT_YET [toolTip closeToolTip];
::HMHideTag();
#endif
} }
// Called when a context menu should be shown. // Called when a context menu should be shown.

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

@ -479,6 +479,8 @@
F5D33CBF02EF61AA01A967F3, F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3, F566BD1402EFA9AD01A967F3,
F558099F02F22169015DF512, F558099F02F22169015DF512,
F549ACE50302DEBB01026D5D,
F549ACE80302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -601,6 +603,8 @@
F5D33CC102EF61AA01A967F3, F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3, F566BD1502EFA9AD01A967F3,
F55809A002F22169015DF512, F55809A002F22169015DF512,
F549ACE00302DE6101026D5D,
F549ACE10302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;
@ -1313,6 +1317,7 @@
F57074BE026D80DF01A80166, F57074BE026D80DF01A80166,
2E2939FF027F33604B000102, 2E2939FF027F33604B000102,
2E748B73029A448D4B000102, 2E748B73029A448D4B000102,
F549ACDE0302DE6001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = "UI elements"; name = "UI elements";
@ -1507,6 +1512,7 @@
F55C4DD302D2864D0130B065, F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3, F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3, F566BD1202EFA9AD01A967F3,
F549ACE70302DEF001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = Headers; name = Headers;
@ -2811,6 +2817,74 @@
settings = { settings = {
}; };
}; };
F549ACDE0302DE6001026D5D = {
isa = PBXFileReference;
path = ToolTip.mm;
refType = 4;
};
F549ACDF0302DE6001026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.m";
refType = 4;
};
F549ACE00302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE10302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE20302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE30302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE40302DEBB01026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.h";
refType = 4;
};
F549ACE50302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE60302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE70302DEF001026D5D = {
isa = PBXFileReference;
path = ToolTip.h;
refType = 4;
};
F549ACE80302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE90302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F54AD84402C115D901A967F3 = { F54AD84402C115D901A967F3 = {
isa = PBXFileReference; isa = PBXFileReference;
name = liboji.a; name = liboji.a;
@ -2972,6 +3046,8 @@
children = ( children = (
F558099D02F22168015DF512, F558099D02F22168015DF512,
F558099E02F22168015DF512, F558099E02F22168015DF512,
F549ACE40302DEBB01026D5D,
F549ACDF0302DE6001026D5D,
F5BF71450231B8BC010001CA, F5BF71450231B8BC010001CA,
F5BF71460231B8BC010001CA, F5BF71460231B8BC010001CA,
F5648739023C3857010001CA, F5648739023C3857010001CA,
@ -5259,6 +5335,8 @@
F5D33CC202EF61AA01A967F3, F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3, F566BD1602EFA9AD01A967F3,
F55809A102F22169015DF512, F55809A102F22169015DF512,
F549ACE60302DEBB01026D5D,
F549ACE90302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -5382,6 +5460,8 @@
F5D33CC402EF61AA01A967F3, F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3, F566BD1702EFA9AD01A967F3,
F55809A202F22169015DF512, F55809A202F22169015DF512,
F549ACE20302DE6101026D5D,
F549ACE30302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;

45
camino/NSScreen+Utils.h Normal file
Просмотреть файл

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@interface NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point;
@end

58
camino/NSScreen+Utils.m Normal file
Просмотреть файл

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "NSScreen+Utils.h"
@implementation NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point {
NSArray* screens = [NSScreen screens];
NSEnumerator* screenEnum = [screens objectEnumerator];
NSScreen* screen;
while ( (screen = [screenEnum nextObject]) ) {
NSRect frame = [screen frame];
if (NSPointInRect(point, frame))
break;
}
return screen;
}
@end

52
camino/ToolTip.h Normal file
Просмотреть файл

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@class ToolTipView;
@interface ToolTip : NSObject
{
NSPanel* mPanel;
NSTextField* mTextField;
}
// it expects a point relative to the top left coordinate of the screen
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string;
- (void)closeToolTip;
@end

136
camino/ToolTip.mm Normal file
Просмотреть файл

@ -0,0 +1,136 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "ToolTip.h"
#import "NSScreen+Utils.h"
@interface ToolTip (ToolTipPrivateMethods)
@end
@implementation ToolTip
- (id)init
{
self = [super init];
if (self) {
mPanel = [[NSPanel alloc] initWithContentRect: NSMakeRect(0.0, 0.0, 200.0, 200.0) styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: YES];
mTextField = [[[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 200.0, 200.0)] autorelease];
[[mPanel contentView] addSubview: mTextField];
[mPanel setHasShadow: YES];
[mTextField setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[mTextField setBackgroundColor: [NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: .81 alpha: 1.0]];
[mTextField setDrawsBackground: YES];
[mTextField setEditable: NO];
[mTextField setSelectable: NO];
[mTextField setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[mTextField setBezeled: NO];
[mTextField setBordered: NO];
}
return self;
}
- (void)dealloc
{
[mPanel close];
[mPanel release];
[super dealloc];
}
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string
{
if ([string length] == 0)
return;
NSScreen* screen = [NSScreen screenForPoint: point];
if (!screen)
screen = [NSScreen mainScreen];
if (screen) {
NSRect screenFrame = [screen visibleFrame];
NSSize screenSize = screenFrame.size;
NSTextView* textView = [[NSTextView alloc] initWithFrame: screenFrame];
// find out how large the tooltip needs to be
[textView setString: string];
[textView setMinSize: NSMakeSize(0.0, 0.0)];
[textView setMaxSize: screenSize];
[textView setVerticallyResizable: YES];
[textView setHorizontallyResizable: YES];
[textView setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[textView sizeToFit];
NSSize textSize = NSMakeSize( ceil( NSWidth([textView frame]) ), ceil( NSHeight([textView frame]) ) );
// set up the panel
[mTextField setStringValue: string];
[mPanel setContentSize: textSize];
// the given point is right where the mouse pointer is. We want the tooltip's
// top left corner somewhere below that, but not if that'll put it off the monitor. There
// is no way that we can go off the top of the monitor because cocoa won't let us position a window
// that way
if ( point.y - 20 - textSize.height > NSMinY(screenFrame) )
point.y -= 20;
else
point.y += 20;
[mPanel setFrameTopLeftPoint: point];
// if it goes off the edge of the screen, shift around to put it all on the screen
float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mPanel frame]);
if (amountOffScreenX < 0) {
NSRect movedFrame = [mPanel frame];
movedFrame.origin.x += amountOffScreenX;
[mPanel setFrame: movedFrame display: NO];
}
// show the panel
[mPanel orderFront: nil];
}
}
- (void)closeToolTip
{
[mPanel close];
}
@end

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

@ -479,6 +479,8 @@
F5D33CBF02EF61AA01A967F3, F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3, F566BD1402EFA9AD01A967F3,
F558099F02F22169015DF512, F558099F02F22169015DF512,
F549ACE50302DEBB01026D5D,
F549ACE80302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -601,6 +603,8 @@
F5D33CC102EF61AA01A967F3, F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3, F566BD1502EFA9AD01A967F3,
F55809A002F22169015DF512, F55809A002F22169015DF512,
F549ACE00302DE6101026D5D,
F549ACE10302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;
@ -1313,6 +1317,7 @@
F57074BE026D80DF01A80166, F57074BE026D80DF01A80166,
2E2939FF027F33604B000102, 2E2939FF027F33604B000102,
2E748B73029A448D4B000102, 2E748B73029A448D4B000102,
F549ACDE0302DE6001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = "UI elements"; name = "UI elements";
@ -1507,6 +1512,7 @@
F55C4DD302D2864D0130B065, F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3, F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3, F566BD1202EFA9AD01A967F3,
F549ACE70302DEF001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = Headers; name = Headers;
@ -2811,6 +2817,74 @@
settings = { settings = {
}; };
}; };
F549ACDE0302DE6001026D5D = {
isa = PBXFileReference;
path = ToolTip.mm;
refType = 4;
};
F549ACDF0302DE6001026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.m";
refType = 4;
};
F549ACE00302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE10302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE20302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE30302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE40302DEBB01026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.h";
refType = 4;
};
F549ACE50302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE60302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE70302DEF001026D5D = {
isa = PBXFileReference;
path = ToolTip.h;
refType = 4;
};
F549ACE80302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE90302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F54AD84402C115D901A967F3 = { F54AD84402C115D901A967F3 = {
isa = PBXFileReference; isa = PBXFileReference;
name = liboji.a; name = liboji.a;
@ -2972,6 +3046,8 @@
children = ( children = (
F558099D02F22168015DF512, F558099D02F22168015DF512,
F558099E02F22168015DF512, F558099E02F22168015DF512,
F549ACE40302DEBB01026D5D,
F549ACDF0302DE6001026D5D,
F5BF71450231B8BC010001CA, F5BF71450231B8BC010001CA,
F5BF71460231B8BC010001CA, F5BF71460231B8BC010001CA,
F5648739023C3857010001CA, F5648739023C3857010001CA,
@ -5259,6 +5335,8 @@
F5D33CC202EF61AA01A967F3, F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3, F566BD1602EFA9AD01A967F3,
F55809A102F22169015DF512, F55809A102F22169015DF512,
F549ACE60302DEBB01026D5D,
F549ACE90302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -5382,6 +5460,8 @@
F5D33CC402EF61AA01A967F3, F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3, F566BD1702EFA9AD01A967F3,
F55809A202F22169015DF512, F55809A202F22169015DF512,
F549ACE20302DE6101026D5D,
F549ACE30302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;

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

@ -39,6 +39,7 @@
#import "CHBrowserView.h" #import "CHBrowserView.h"
@class BrowserWindowController; @class BrowserWindowController;
@class CHToolTip;
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer> @interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
{ {
@ -61,6 +62,7 @@
CHBrowserView* mBrowserView; CHBrowserView* mBrowserView;
NSString* defaultStatus; NSString* defaultStatus;
NSString* loadingStatus; NSString* loadingStatus;
CHToolTip* toolTip;
BOOL mIsPrimary; BOOL mIsPrimary;
BOOL mIsBusy; BOOL mIsBusy;

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

@ -40,6 +40,7 @@
#import "CHBrowserWrapper.h" #import "CHBrowserWrapper.h"
#import "BrowserWindowController.h" #import "BrowserWindowController.h"
#import "BookmarksService.h" #import "BookmarksService.h"
#import "ToolTip.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -87,6 +88,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[defaultStatus release]; [defaultStatus release];
[loadingStatus release]; [loadingStatus release];
[toolTip release];
[super dealloc]; [super dealloc];
} }
@ -131,6 +133,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
mIsBusy = NO; mIsBusy = NO;
mListenersAttached = NO; mListenersAttached = NO;
mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; mSecureState = nsIWebProgressListener::STATE_IS_INSECURE;
toolTip = [[ToolTip alloc] init];
} }
return self; return self;
} }
@ -414,38 +417,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// //
- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text - (void)onShowTooltip:(NSPoint)where withText:(NSString*)text
{ {
#if NOT_YET NSPoint point = [[self window] convertBaseToScreen:[self convertPoint: where toView:nil]];
HMHelpContentRec info; [toolTip showToolTipAtPoint: point withString: text];
info.version = kMacHelpVersion;
// convert to global QD coordinates, which is what HMDisplayTag expects. Only
// the main device is important in this calculation since that's where the
// coordinate systems differ.
NSPoint p = {where.x, where.y};
p = [[self window] convertBaseToScreen:[self convertPoint:p toView:nil]];
GDHandle screenDevice = ::GetMainDevice();
Rect screenRect = (**screenDevice).gdRect;
short screenHeight = screenRect.bottom - screenRect.top;
p.y = screenRect.top + (screenHeight - p.y);
Rect r = {p.y, p.x, p.y + 15, p.x + 15}; // center it under the mouse cursorsure
info.absHotRect = r;
info.tagSide = kHMOutsideBottomCenterAligned;
// setup the content of the tooltip. recall that a NSString is really just a CFString under the hood
info.content[0].contentType = kHMCFStringContent;
info.content[0].u.tagCFString = (CFStringRef) text;
info.content[1] = info.content[0];
::HMDisplayTag(&info);
#endif
} }
- (void)onHideTooltip - (void)onHideTooltip
{ {
#if NOT_YET [toolTip closeToolTip];
::HMHideTag();
#endif
} }
// Called when a context menu should be shown. // Called when a context menu should be shown.

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

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@class ToolTipView;
@interface ToolTip : NSObject
{
NSPanel* mPanel;
NSTextField* mTextField;
}
// it expects a point relative to the top left coordinate of the screen
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string;
- (void)closeToolTip;
@end

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

@ -0,0 +1,136 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "ToolTip.h"
#import "NSScreen+Utils.h"
@interface ToolTip (ToolTipPrivateMethods)
@end
@implementation ToolTip
- (id)init
{
self = [super init];
if (self) {
mPanel = [[NSPanel alloc] initWithContentRect: NSMakeRect(0.0, 0.0, 200.0, 200.0) styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: YES];
mTextField = [[[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 200.0, 200.0)] autorelease];
[[mPanel contentView] addSubview: mTextField];
[mPanel setHasShadow: YES];
[mTextField setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[mTextField setBackgroundColor: [NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: .81 alpha: 1.0]];
[mTextField setDrawsBackground: YES];
[mTextField setEditable: NO];
[mTextField setSelectable: NO];
[mTextField setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[mTextField setBezeled: NO];
[mTextField setBordered: NO];
}
return self;
}
- (void)dealloc
{
[mPanel close];
[mPanel release];
[super dealloc];
}
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string
{
if ([string length] == 0)
return;
NSScreen* screen = [NSScreen screenForPoint: point];
if (!screen)
screen = [NSScreen mainScreen];
if (screen) {
NSRect screenFrame = [screen visibleFrame];
NSSize screenSize = screenFrame.size;
NSTextView* textView = [[NSTextView alloc] initWithFrame: screenFrame];
// find out how large the tooltip needs to be
[textView setString: string];
[textView setMinSize: NSMakeSize(0.0, 0.0)];
[textView setMaxSize: screenSize];
[textView setVerticallyResizable: YES];
[textView setHorizontallyResizable: YES];
[textView setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[textView sizeToFit];
NSSize textSize = NSMakeSize( ceil( NSWidth([textView frame]) ), ceil( NSHeight([textView frame]) ) );
// set up the panel
[mTextField setStringValue: string];
[mPanel setContentSize: textSize];
// the given point is right where the mouse pointer is. We want the tooltip's
// top left corner somewhere below that, but not if that'll put it off the monitor. There
// is no way that we can go off the top of the monitor because cocoa won't let us position a window
// that way
if ( point.y - 20 - textSize.height > NSMinY(screenFrame) )
point.y -= 20;
else
point.y += 20;
[mPanel setFrameTopLeftPoint: point];
// if it goes off the edge of the screen, shift around to put it all on the screen
float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mPanel frame]);
if (amountOffScreenX < 0) {
NSRect movedFrame = [mPanel frame];
movedFrame.origin.x += amountOffScreenX;
[mPanel setFrame: movedFrame display: NO];
}
// show the panel
[mPanel orderFront: nil];
}
}
- (void)closeToolTip
{
[mPanel close];
}
@end

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

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@interface NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point;
@end

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

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "NSScreen+Utils.h"
@implementation NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point {
NSArray* screens = [NSScreen screens];
NSEnumerator* screenEnum = [screens objectEnumerator];
NSScreen* screen;
while ( (screen = [screenEnum nextObject]) ) {
NSRect frame = [screen frame];
if (NSPointInRect(point, frame))
break;
}
return screen;
}
@end

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

@ -39,6 +39,7 @@
#import "CHBrowserView.h" #import "CHBrowserView.h"
@class BrowserWindowController; @class BrowserWindowController;
@class CHToolTip;
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer> @interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
{ {
@ -61,6 +62,7 @@
CHBrowserView* mBrowserView; CHBrowserView* mBrowserView;
NSString* defaultStatus; NSString* defaultStatus;
NSString* loadingStatus; NSString* loadingStatus;
CHToolTip* toolTip;
BOOL mIsPrimary; BOOL mIsPrimary;
BOOL mIsBusy; BOOL mIsBusy;

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

@ -40,6 +40,7 @@
#import "CHBrowserWrapper.h" #import "CHBrowserWrapper.h"
#import "BrowserWindowController.h" #import "BrowserWindowController.h"
#import "BookmarksService.h" #import "BookmarksService.h"
#import "ToolTip.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -87,6 +88,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[defaultStatus release]; [defaultStatus release];
[loadingStatus release]; [loadingStatus release];
[toolTip release];
[super dealloc]; [super dealloc];
} }
@ -131,6 +133,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
mIsBusy = NO; mIsBusy = NO;
mListenersAttached = NO; mListenersAttached = NO;
mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; mSecureState = nsIWebProgressListener::STATE_IS_INSECURE;
toolTip = [[ToolTip alloc] init];
} }
return self; return self;
} }
@ -414,38 +417,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// //
- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text - (void)onShowTooltip:(NSPoint)where withText:(NSString*)text
{ {
#if NOT_YET NSPoint point = [[self window] convertBaseToScreen:[self convertPoint: where toView:nil]];
HMHelpContentRec info; [toolTip showToolTipAtPoint: point withString: text];
info.version = kMacHelpVersion;
// convert to global QD coordinates, which is what HMDisplayTag expects. Only
// the main device is important in this calculation since that's where the
// coordinate systems differ.
NSPoint p = {where.x, where.y};
p = [[self window] convertBaseToScreen:[self convertPoint:p toView:nil]];
GDHandle screenDevice = ::GetMainDevice();
Rect screenRect = (**screenDevice).gdRect;
short screenHeight = screenRect.bottom - screenRect.top;
p.y = screenRect.top + (screenHeight - p.y);
Rect r = {p.y, p.x, p.y + 15, p.x + 15}; // center it under the mouse cursorsure
info.absHotRect = r;
info.tagSide = kHMOutsideBottomCenterAligned;
// setup the content of the tooltip. recall that a NSString is really just a CFString under the hood
info.content[0].contentType = kHMCFStringContent;
info.content[0].u.tagCFString = (CFStringRef) text;
info.content[1] = info.content[0];
::HMDisplayTag(&info);
#endif
} }
- (void)onHideTooltip - (void)onHideTooltip
{ {
#if NOT_YET [toolTip closeToolTip];
::HMHideTag();
#endif
} }
// Called when a context menu should be shown. // Called when a context menu should be shown.

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

@ -479,6 +479,8 @@
F5D33CBF02EF61AA01A967F3, F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3, F566BD1402EFA9AD01A967F3,
F558099F02F22169015DF512, F558099F02F22169015DF512,
F549ACE50302DEBB01026D5D,
F549ACE80302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -601,6 +603,8 @@
F5D33CC102EF61AA01A967F3, F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3, F566BD1502EFA9AD01A967F3,
F55809A002F22169015DF512, F55809A002F22169015DF512,
F549ACE00302DE6101026D5D,
F549ACE10302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;
@ -1313,6 +1317,7 @@
F57074BE026D80DF01A80166, F57074BE026D80DF01A80166,
2E2939FF027F33604B000102, 2E2939FF027F33604B000102,
2E748B73029A448D4B000102, 2E748B73029A448D4B000102,
F549ACDE0302DE6001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = "UI elements"; name = "UI elements";
@ -1507,6 +1512,7 @@
F55C4DD302D2864D0130B065, F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3, F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3, F566BD1202EFA9AD01A967F3,
F549ACE70302DEF001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = Headers; name = Headers;
@ -2811,6 +2817,74 @@
settings = { settings = {
}; };
}; };
F549ACDE0302DE6001026D5D = {
isa = PBXFileReference;
path = ToolTip.mm;
refType = 4;
};
F549ACDF0302DE6001026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.m";
refType = 4;
};
F549ACE00302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE10302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE20302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE30302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE40302DEBB01026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.h";
refType = 4;
};
F549ACE50302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE60302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE70302DEF001026D5D = {
isa = PBXFileReference;
path = ToolTip.h;
refType = 4;
};
F549ACE80302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE90302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F54AD84402C115D901A967F3 = { F54AD84402C115D901A967F3 = {
isa = PBXFileReference; isa = PBXFileReference;
name = liboji.a; name = liboji.a;
@ -2972,6 +3046,8 @@
children = ( children = (
F558099D02F22168015DF512, F558099D02F22168015DF512,
F558099E02F22168015DF512, F558099E02F22168015DF512,
F549ACE40302DEBB01026D5D,
F549ACDF0302DE6001026D5D,
F5BF71450231B8BC010001CA, F5BF71450231B8BC010001CA,
F5BF71460231B8BC010001CA, F5BF71460231B8BC010001CA,
F5648739023C3857010001CA, F5648739023C3857010001CA,
@ -5259,6 +5335,8 @@
F5D33CC202EF61AA01A967F3, F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3, F566BD1602EFA9AD01A967F3,
F55809A102F22169015DF512, F55809A102F22169015DF512,
F549ACE60302DEBB01026D5D,
F549ACE90302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -5382,6 +5460,8 @@
F5D33CC402EF61AA01A967F3, F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3, F566BD1702EFA9AD01A967F3,
F55809A202F22169015DF512, F55809A202F22169015DF512,
F549ACE20302DE6101026D5D,
F549ACE30302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;

45
chimera/NSScreen+Utils.h Normal file
Просмотреть файл

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@interface NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point;
@end

58
chimera/NSScreen+Utils.m Normal file
Просмотреть файл

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "NSScreen+Utils.h"
@implementation NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point {
NSArray* screens = [NSScreen screens];
NSEnumerator* screenEnum = [screens objectEnumerator];
NSScreen* screen;
while ( (screen = [screenEnum nextObject]) ) {
NSRect frame = [screen frame];
if (NSPointInRect(point, frame))
break;
}
return screen;
}
@end

52
chimera/ToolTip.h Normal file
Просмотреть файл

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@class ToolTipView;
@interface ToolTip : NSObject
{
NSPanel* mPanel;
NSTextField* mTextField;
}
// it expects a point relative to the top left coordinate of the screen
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string;
- (void)closeToolTip;
@end

136
chimera/ToolTip.mm Normal file
Просмотреть файл

@ -0,0 +1,136 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "ToolTip.h"
#import "NSScreen+Utils.h"
@interface ToolTip (ToolTipPrivateMethods)
@end
@implementation ToolTip
- (id)init
{
self = [super init];
if (self) {
mPanel = [[NSPanel alloc] initWithContentRect: NSMakeRect(0.0, 0.0, 200.0, 200.0) styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: YES];
mTextField = [[[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 200.0, 200.0)] autorelease];
[[mPanel contentView] addSubview: mTextField];
[mPanel setHasShadow: YES];
[mTextField setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[mTextField setBackgroundColor: [NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: .81 alpha: 1.0]];
[mTextField setDrawsBackground: YES];
[mTextField setEditable: NO];
[mTextField setSelectable: NO];
[mTextField setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[mTextField setBezeled: NO];
[mTextField setBordered: NO];
}
return self;
}
- (void)dealloc
{
[mPanel close];
[mPanel release];
[super dealloc];
}
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string
{
if ([string length] == 0)
return;
NSScreen* screen = [NSScreen screenForPoint: point];
if (!screen)
screen = [NSScreen mainScreen];
if (screen) {
NSRect screenFrame = [screen visibleFrame];
NSSize screenSize = screenFrame.size;
NSTextView* textView = [[NSTextView alloc] initWithFrame: screenFrame];
// find out how large the tooltip needs to be
[textView setString: string];
[textView setMinSize: NSMakeSize(0.0, 0.0)];
[textView setMaxSize: screenSize];
[textView setVerticallyResizable: YES];
[textView setHorizontallyResizable: YES];
[textView setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[textView sizeToFit];
NSSize textSize = NSMakeSize( ceil( NSWidth([textView frame]) ), ceil( NSHeight([textView frame]) ) );
// set up the panel
[mTextField setStringValue: string];
[mPanel setContentSize: textSize];
// the given point is right where the mouse pointer is. We want the tooltip's
// top left corner somewhere below that, but not if that'll put it off the monitor. There
// is no way that we can go off the top of the monitor because cocoa won't let us position a window
// that way
if ( point.y - 20 - textSize.height > NSMinY(screenFrame) )
point.y -= 20;
else
point.y += 20;
[mPanel setFrameTopLeftPoint: point];
// if it goes off the edge of the screen, shift around to put it all on the screen
float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mPanel frame]);
if (amountOffScreenX < 0) {
NSRect movedFrame = [mPanel frame];
movedFrame.origin.x += amountOffScreenX;
[mPanel setFrame: movedFrame display: NO];
}
// show the panel
[mPanel orderFront: nil];
}
}
- (void)closeToolTip
{
[mPanel close];
}
@end

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

@ -479,6 +479,8 @@
F5D33CBF02EF61AA01A967F3, F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3, F566BD1402EFA9AD01A967F3,
F558099F02F22169015DF512, F558099F02F22169015DF512,
F549ACE50302DEBB01026D5D,
F549ACE80302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -601,6 +603,8 @@
F5D33CC102EF61AA01A967F3, F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3, F566BD1502EFA9AD01A967F3,
F55809A002F22169015DF512, F55809A002F22169015DF512,
F549ACE00302DE6101026D5D,
F549ACE10302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;
@ -1313,6 +1317,7 @@
F57074BE026D80DF01A80166, F57074BE026D80DF01A80166,
2E2939FF027F33604B000102, 2E2939FF027F33604B000102,
2E748B73029A448D4B000102, 2E748B73029A448D4B000102,
F549ACDE0302DE6001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = "UI elements"; name = "UI elements";
@ -1507,6 +1512,7 @@
F55C4DD302D2864D0130B065, F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3, F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3, F566BD1202EFA9AD01A967F3,
F549ACE70302DEF001026D5D,
); );
isa = PBXGroup; isa = PBXGroup;
name = Headers; name = Headers;
@ -2811,6 +2817,74 @@
settings = { settings = {
}; };
}; };
F549ACDE0302DE6001026D5D = {
isa = PBXFileReference;
path = ToolTip.mm;
refType = 4;
};
F549ACDF0302DE6001026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.m";
refType = 4;
};
F549ACE00302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE10302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE20302DE6101026D5D = {
fileRef = F549ACDE0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE30302DE6101026D5D = {
fileRef = F549ACDF0302DE6001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE40302DEBB01026D5D = {
isa = PBXFileReference;
path = "NSScreen+Utils.h";
refType = 4;
};
F549ACE50302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE60302DEBB01026D5D = {
fileRef = F549ACE40302DEBB01026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE70302DEF001026D5D = {
isa = PBXFileReference;
path = ToolTip.h;
refType = 4;
};
F549ACE80302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F549ACE90302DEF001026D5D = {
fileRef = F549ACE70302DEF001026D5D;
isa = PBXBuildFile;
settings = {
};
};
F54AD84402C115D901A967F3 = { F54AD84402C115D901A967F3 = {
isa = PBXFileReference; isa = PBXFileReference;
name = liboji.a; name = liboji.a;
@ -2972,6 +3046,8 @@
children = ( children = (
F558099D02F22168015DF512, F558099D02F22168015DF512,
F558099E02F22168015DF512, F558099E02F22168015DF512,
F549ACE40302DEBB01026D5D,
F549ACDF0302DE6001026D5D,
F5BF71450231B8BC010001CA, F5BF71450231B8BC010001CA,
F5BF71460231B8BC010001CA, F5BF71460231B8BC010001CA,
F5648739023C3857010001CA, F5648739023C3857010001CA,
@ -5259,6 +5335,8 @@
F5D33CC202EF61AA01A967F3, F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3, F566BD1602EFA9AD01A967F3,
F55809A102F22169015DF512, F55809A102F22169015DF512,
F549ACE60302DEBB01026D5D,
F549ACE90302DEF001026D5D,
); );
isa = PBXHeadersBuildPhase; isa = PBXHeadersBuildPhase;
name = Headers; name = Headers;
@ -5382,6 +5460,8 @@
F5D33CC402EF61AA01A967F3, F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3, F566BD1702EFA9AD01A967F3,
F55809A202F22169015DF512, F55809A202F22169015DF512,
F549ACE20302DE6101026D5D,
F549ACE30302DE6101026D5D,
); );
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
name = Sources; name = Sources;

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

@ -39,6 +39,7 @@
#import "CHBrowserView.h" #import "CHBrowserView.h"
@class BrowserWindowController; @class BrowserWindowController;
@class CHToolTip;
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer> @interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
{ {
@ -61,6 +62,7 @@
CHBrowserView* mBrowserView; CHBrowserView* mBrowserView;
NSString* defaultStatus; NSString* defaultStatus;
NSString* loadingStatus; NSString* loadingStatus;
CHToolTip* toolTip;
BOOL mIsPrimary; BOOL mIsPrimary;
BOOL mIsBusy; BOOL mIsBusy;

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

@ -40,6 +40,7 @@
#import "CHBrowserWrapper.h" #import "CHBrowserWrapper.h"
#import "BrowserWindowController.h" #import "BrowserWindowController.h"
#import "BookmarksService.h" #import "BookmarksService.h"
#import "ToolTip.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -87,6 +88,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
[defaultStatus release]; [defaultStatus release];
[loadingStatus release]; [loadingStatus release];
[toolTip release];
[super dealloc]; [super dealloc];
} }
@ -131,6 +133,7 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
mIsBusy = NO; mIsBusy = NO;
mListenersAttached = NO; mListenersAttached = NO;
mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; mSecureState = nsIWebProgressListener::STATE_IS_INSECURE;
toolTip = [[ToolTip alloc] init];
} }
return self; return self;
} }
@ -414,38 +417,13 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
// //
- (void)onShowTooltip:(NSPoint)where withText:(NSString*)text - (void)onShowTooltip:(NSPoint)where withText:(NSString*)text
{ {
#if NOT_YET NSPoint point = [[self window] convertBaseToScreen:[self convertPoint: where toView:nil]];
HMHelpContentRec info; [toolTip showToolTipAtPoint: point withString: text];
info.version = kMacHelpVersion;
// convert to global QD coordinates, which is what HMDisplayTag expects. Only
// the main device is important in this calculation since that's where the
// coordinate systems differ.
NSPoint p = {where.x, where.y};
p = [[self window] convertBaseToScreen:[self convertPoint:p toView:nil]];
GDHandle screenDevice = ::GetMainDevice();
Rect screenRect = (**screenDevice).gdRect;
short screenHeight = screenRect.bottom - screenRect.top;
p.y = screenRect.top + (screenHeight - p.y);
Rect r = {p.y, p.x, p.y + 15, p.x + 15}; // center it under the mouse cursorsure
info.absHotRect = r;
info.tagSide = kHMOutsideBottomCenterAligned;
// setup the content of the tooltip. recall that a NSString is really just a CFString under the hood
info.content[0].contentType = kHMCFStringContent;
info.content[0].u.tagCFString = (CFStringRef) text;
info.content[1] = info.content[0];
::HMDisplayTag(&info);
#endif
} }
- (void)onHideTooltip - (void)onHideTooltip
{ {
#if NOT_YET [toolTip closeToolTip];
::HMHideTag();
#endif
} }
// Called when a context menu should be shown. // Called when a context menu should be shown.

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

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@class ToolTipView;
@interface ToolTip : NSObject
{
NSPanel* mPanel;
NSTextField* mTextField;
}
// it expects a point relative to the top left coordinate of the screen
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string;
- (void)closeToolTip;
@end

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

@ -0,0 +1,136 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s): Richard Schreyer
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "ToolTip.h"
#import "NSScreen+Utils.h"
@interface ToolTip (ToolTipPrivateMethods)
@end
@implementation ToolTip
- (id)init
{
self = [super init];
if (self) {
mPanel = [[NSPanel alloc] initWithContentRect: NSMakeRect(0.0, 0.0, 200.0, 200.0) styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: YES];
mTextField = [[[NSTextField alloc] initWithFrame: NSMakeRect(0.0, 0.0, 200.0, 200.0)] autorelease];
[[mPanel contentView] addSubview: mTextField];
[mPanel setHasShadow: YES];
[mTextField setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[mTextField setBackgroundColor: [NSColor colorWithCalibratedRed: 1.0 green: 1.0 blue: .81 alpha: 1.0]];
[mTextField setDrawsBackground: YES];
[mTextField setEditable: NO];
[mTextField setSelectable: NO];
[mTextField setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[mTextField setBezeled: NO];
[mTextField setBordered: NO];
}
return self;
}
- (void)dealloc
{
[mPanel close];
[mPanel release];
[super dealloc];
}
- (void)showToolTipAtPoint:(NSPoint)point withString:(NSString*)string
{
if ([string length] == 0)
return;
NSScreen* screen = [NSScreen screenForPoint: point];
if (!screen)
screen = [NSScreen mainScreen];
if (screen) {
NSRect screenFrame = [screen visibleFrame];
NSSize screenSize = screenFrame.size;
NSTextView* textView = [[NSTextView alloc] initWithFrame: screenFrame];
// find out how large the tooltip needs to be
[textView setString: string];
[textView setMinSize: NSMakeSize(0.0, 0.0)];
[textView setMaxSize: screenSize];
[textView setVerticallyResizable: YES];
[textView setHorizontallyResizable: YES];
[textView setFont: [NSFont toolTipsFontOfSize: [NSFont smallSystemFontSize]]];
[textView sizeToFit];
NSSize textSize = NSMakeSize( ceil( NSWidth([textView frame]) ), ceil( NSHeight([textView frame]) ) );
// set up the panel
[mTextField setStringValue: string];
[mPanel setContentSize: textSize];
// the given point is right where the mouse pointer is. We want the tooltip's
// top left corner somewhere below that, but not if that'll put it off the monitor. There
// is no way that we can go off the top of the monitor because cocoa won't let us position a window
// that way
if ( point.y - 20 - textSize.height > NSMinY(screenFrame) )
point.y -= 20;
else
point.y += 20;
[mPanel setFrameTopLeftPoint: point];
// if it goes off the edge of the screen, shift around to put it all on the screen
float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mPanel frame]);
if (amountOffScreenX < 0) {
NSRect movedFrame = [mPanel frame];
movedFrame.origin.x += amountOffScreenX;
[mPanel setFrame: movedFrame display: NO];
}
// show the panel
[mPanel orderFront: nil];
}
}
- (void)closeToolTip
{
[mPanel close];
}
@end

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

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
@interface NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point;
@end

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

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "NSScreen+Utils.h"
@implementation NSScreen (CHScreenAdditions)
+ (NSScreen*)screenForPoint:(NSPoint)point {
NSArray* screens = [NSScreen screens];
NSEnumerator* screenEnum = [screens objectEnumerator];
NSScreen* screen;
while ( (screen = [screenEnum nextObject]) ) {
NSRect frame = [screen frame];
if (NSPointInRect(point, frame))
break;
}
return screen;
}
@end