Refs #1245. Make CPToolTip and CPAttachedWindow internal since they're not part of the Cocoa API. Refactored some code from CPControl to CPToolTip.

This commit is contained in:
Alexander Ljungberg committed 2011-05-11 20:35:13 -04:00
1 parent bb97c107c9
commit 345d48e224
4 files changed
+129 -127

No files matched your search

+1 -1
View File
@@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "_CPToolTip.j"
@import "CALayer.j"
@import "CPAlert.j"
@import "CPAnimation.j"
@@ -87,7 +88,6 @@
@import "CPTokenField.j"
@import "CPToolbar.j"
@import "CPToolbarItem.j"
@import "CPToolTip.j"
@import "CPTreeNode.j"
@import "CPView.j"
@import "CPViewAnimation.j"
+2 -115
View File
@@ -71,9 +71,7 @@ CPControlTextDidBeginEditingNotification = "CPControlTextDidBeginEditingNotif
CPControlTextDidChangeNotification = "CPControlTextDidChangeNotification";
CPControlTextDidEndEditingNotification = "CPControlTextDidEndEditingNotification";
var CPControlBlackColor = [CPColor blackColor],
CPCurrentToolTip,
CPCurrentToolTipTimer;
var CPControlBlackColor = [CPColor blackColor];
/*!
@ingroup appkit
@@ -97,7 +95,7 @@ var CPControlBlackColor = [CPColor blackColor],
unsigned _trackingMouseDownFlags;
CGPoint _previousTrackingLocation;
CPString _toolTip;
CPString _toolTip @accessors(property=toolTip);
}
+ (CPDictionary)themeAttributes
@@ -240,117 +238,6 @@ var CPControlBlackColor = [CPColor blackColor],
return previousMask;
}
/*!
Sets the tooltip for the receiver.
@param aToolTip the tooltip
*/
- (void)setToolTip:(CPString)aToolTip
{
if (_toolTip == aToolTip)
return;
_toolTip = aToolTip;
if (!_DOMElement)
return;
var fIn = function(e)
{
[self _fireToolTip];
},
fOut = function(e)
{
[self _invalidateToolTip];
};
if (_toolTip)
{
if (_DOMElement.addEventListener)
{
_DOMElement.addEventListener("mouseover", fIn, NO);
_DOMElement.addEventListener("keypress", fOut, NO);
_DOMElement.addEventListener("mouseout", fOut, NO);
}
else if (_DOMElement.attachEvent)
{
_DOMElement.attachEvent("onmouseover", fIn);
_DOMElement.attachEvent("onkeypress", fOut);
_DOMElement.attachEvent("onmouseout", fOut);
}
}
else
{
if (_DOMElement.removeEventListener)
{
_DOMElement.removeEventListener("mouseover", fIn, NO);
_DOMElement.removeEventListener("keypress", fOut, NO);
_DOMElement.removeEventListener("mouseout", fOut, NO);
}
else if (_DOMElement.detachEvent)
{
_DOMElement.detachEvent("onmouseover", fIn);
_DOMElement.detachEvent("onkeypress", fOut);
_DOMElement.detachEvent("onmouseout", fOut);
}
}
}
/*!
Returns the receiver's tooltip
*/
- (CPString)toolTip
{
return _toolTip;
}
/*! @ignore
starts the tooltip timer
*/
- (void)_fireToolTip
{
if (CPCurrentToolTipTimer)
{
[CPCurrentToolTipTimer invalidate];
if (CPCurrentToolTip)
[CPCurrentToolTip close:nil];
CPCurrentToolTip = nil;
}
if (_toolTip)
CPCurrentToolTipTimer = [CPTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(_showToolTip:) userInfo:nil repeats:NO];
}
/*! @ignore
Stop the tooltip timer if any
*/
- (void)_invalidateToolTip
{
if (CPCurrentToolTipTimer)
{
[CPCurrentToolTipTimer invalidate];
CPCurrentToolTipTimer = nil;
}
if (CPCurrentToolTip)
{
[CPCurrentToolTip close:nil];
CPCurrentToolTip = nil;
}
}
/*! @ignore
Actually shows the tooltip if any
*/
- (void)_showToolTip:(CPTimer)aTimer
{
if (CPCurrentToolTip)
[CPCurrentToolTip close:nil];
CPCurrentToolTip = [CPToolTip toolTipWithString:_toolTip forView:self];
}
/*!
Returns whether the control can continuously send its action messages.
*/
@@ -1,5 +1,5 @@
/*
* CPAttachedWindow.j
* _CPAttachedWindow.j
* AppKit
*
* Created by Antoine Mercadal
@@ -26,7 +26,7 @@
@import "CPImageView.j"
@import "CPView.j"
@import "CPWindow.j"
@import "_CPAttachedWindowView.j"
CPClosableOnBlurWindowMask = 1 << 4;
CPAttachedWhiteWindowMask = 1 << 25;
@@ -36,7 +36,7 @@ CPAttachedBlackWindowMask = 1 << 26;
This is a simple attached window like the one that pops up
when you double click on a meeting in iCal
*/
@implementation CPAttachedWindow : CPWindow
@implementation _CPAttachedWindow : CPWindow
{
id _targetView @accessors(property=targetView);
BOOL _isClosed;
@@ -69,7 +69,7 @@ CPAttachedBlackWindowMask = 1 << 26;
*/
+ (id)attachedWindowWithSize:(CGSize)aSize forView:(CPView)aView
{
return [CPAttachedWindow attachedWindowWithSize:aSize forView:aView styleMask:nil];
return [_CPAttachedWindow attachedWindowWithSize:aSize forView:aView styleMask:nil];
}
/*! create and init a CPAttachedWindow with given size of and view
@@ -80,7 +80,7 @@ CPAttachedBlackWindowMask = 1 << 26;
*/
+ (id)attachedWindowWithSize:(CGSize)aSize forView:(CPView)aView styleMask:(int)aMask
{
var attachedWindow = [[CPAttachedWindow alloc] initWithContentRect:CPRectMake(0.0, 0.0, aSize.width, aSize.height) styleMask:aMask];
var attachedWindow = [[_CPAttachedWindow alloc] initWithContentRect:CPRectMake(0.0, 0.0, aSize.width, aSize.height) styleMask:aMask];
[attachedWindow attachToView:aView];
+121 -6
View File
@@ -1,5 +1,5 @@
/*
* CPToolTip.j
* _CPToolTip.j
* AppKit
*
* Created by Antoine Mercadal
@@ -23,15 +23,17 @@
@import "CPTextField.j"
@import "CPView.j"
@import "CPAttachedWindow.j"
@import "_CPAttachedWindow.j"
var CPCurrentToolTip,
CPCurrentToolTipTimer;
CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
/*! @ingroup appkit
subclass of CPAttachedWindow in order to build quick tooltip
*/
@implementation CPToolTip : CPAttachedWindow
@implementation _CPToolTip : _CPAttachedWindow
{
CPTextField _content;
}
@@ -43,9 +45,9 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
@param aString the content of the tooltip
@param aView the view where the tooltip will be attached
*/
+ (CPToolTip)toolTipWithString:(CPString)aString forView:(CPView)aView
+ (_CPToolTip)toolTipWithString:(CPString)aString forView:(CPView)aView
{
var tooltip = [[CPToolTip alloc] initWithString:aString styleMask:CPToolTipDefaultColorMask];
var tooltip = [[_CPToolTip alloc] initWithString:aString styleMask:CPToolTipDefaultColorMask];
[tooltip setAlphaValue:0.9];
[tooltip attachToView:aView];
@@ -88,7 +90,7 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
- (id)initWithString:(CPString)aString styleMask:(unsigned)aStyleMask
{
var toolTipFrame = CPRectMake(0.0, 0.0, 250.0, 30.0),
layout = [CPToolTip computeCorrectSize:toolTipFrame.size text:aString],
layout = [_CPToolTip computeCorrectSize:toolTipFrame.size text:aString],
textFrameSize = layout[1];
toolTipFrame.size = layout[0];
@@ -114,4 +116,117 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
return self;
}
@end
@implementation CPControl (Tooltips)
/*!
Sets the tooltip for the receiver.
@param aToolTip the tooltip
*/
- (void)setToolTip:(CPString)aToolTip
{
if (_toolTip == aToolTip)
return;
_toolTip = aToolTip;
if (!_DOMElement)
return;
var fIn = function(e)
{
[self _fireToolTip];
},
fOut = function(e)
{
[self _invalidateToolTip];
};
if (_toolTip)
{
if (_DOMElement.addEventListener)
{
_DOMElement.addEventListener("mouseover", fIn, NO);
_DOMElement.addEventListener("keypress", fOut, NO);
_DOMElement.addEventListener("mouseout", fOut, NO);
}
else if (_DOMElement.attachEvent)
{
_DOMElement.attachEvent("onmouseover", fIn);
_DOMElement.attachEvent("onkeypress", fOut);
_DOMElement.attachEvent("onmouseout", fOut);
}
}
else
{
if (_DOMElement.removeEventListener)
{
_DOMElement.removeEventListener("mouseover", fIn, NO);
_DOMElement.removeEventListener("keypress", fOut, NO);
_DOMElement.removeEventListener("mouseout", fOut, NO);
}
else if (_DOMElement.detachEvent)
{
_DOMElement.detachEvent("onmouseover", fIn);
_DOMElement.detachEvent("onkeypress", fOut);
_DOMElement.detachEvent("onmouseout", fOut);
}
}
}
/*!
Returns the receiver's tooltip
*/
- (CPString)toolTip
{
return _toolTip;
}
/*! @ignore
starts the tooltip timer
*/
- (void)_fireToolTip
{
if (CPCurrentToolTipTimer)
{
[CPCurrentToolTipTimer invalidate];
if (CPCurrentToolTip)
[CPCurrentToolTip close:nil];
CPCurrentToolTip = nil;
}
if (_toolTip)
CPCurrentToolTipTimer = [CPTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(_showToolTip:) userInfo:nil repeats:NO];
}
/*! @ignore
Stop the tooltip timer if any
*/
- (void)_invalidateToolTip
{
if (CPCurrentToolTipTimer)
{
[CPCurrentToolTipTimer invalidate];
CPCurrentToolTipTimer = nil;
}
if (CPCurrentToolTip)
{
[CPCurrentToolTip close:nil];
CPCurrentToolTip = nil;
}
}
/*! @ignore
Actually shows the tooltip if any
*/
- (void)_showToolTip:(CPTimer)aTimer
{
if (CPCurrentToolTip)
[CPCurrentToolTip close:nil];
CPCurrentToolTip = [_CPToolTip toolTipWithString:_toolTip forView:self];
}
@end