mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-18 12:39:22 +00:00
Merge pull request #1264 from primalmotion/cappuccino
--- These commits make the tooltips looking like cocoa ones. - More simple implementation (only one file added _CPToolTips.j) - Removal of CPAttachedWindow and CPAttachedWindowView - Placement is based on mouse position (just like cocoa) - It will try to find the best placement in case of a lake of space Here is a screenshot : http://twitpic.com/4x401t
This commit is contained in:
commit
bba0de3306
7 files changed
+225
-688
No files matched your search
+1
-1
@@ -20,7 +20,6 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "_CPToolTip.j"
|
||||
@import "CALayer.j"
|
||||
@import "CPAlert.j"
|
||||
@import "CPAnimation.j"
|
||||
@@ -88,6 +87,7 @@
|
||||
@import "CPTokenField.j"
|
||||
@import "CPToolbar.j"
|
||||
@import "CPToolbarItem.j"
|
||||
@import "_CPToolTip.j"
|
||||
@import "CPTreeNode.j"
|
||||
@import "CPView.j"
|
||||
@import "CPViewAnimation.j"
|
||||
|
||||
+2
-1
@@ -187,7 +187,8 @@ var CPViewFlags = { },
|
||||
|
||||
unsigned _viewClassFlags;
|
||||
|
||||
CPString _toolTip @accessors(property=toolTip);
|
||||
// ToolTips
|
||||
CPString _toolTip @accessors(property=toolTip);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -2924,7 +2924,7 @@ CPCustomWindowShadowStyle = 3;
|
||||
@import "_CPWindowView.j"
|
||||
@import "_CPStandardWindowView.j"
|
||||
@import "_CPDocModalWindowView.j"
|
||||
@import "_CPAttachedWindowView.j"
|
||||
@import "_CPToolTipWindowView.j"
|
||||
@import "_CPHUDWindowView.j"
|
||||
@import "_CPBorderlessWindowView.j"
|
||||
@import "_CPBorderlessBridgeWindowView.j"
|
||||
|
||||
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
* _CPAttachedWindowView.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by Antoine Mercadal
|
||||
* Copyright 2011 <antoine.mercadal@inframonde.eu>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "_CPWindowView.j"
|
||||
|
||||
CPAttachedWindowGravityUp = 0;
|
||||
CPAttachedWindowGravityDown = 1;
|
||||
CPAttachedWindowGravityLeft = 2;
|
||||
CPAttachedWindowGravityRight = 3;
|
||||
CPAttachedWindowGravityAuto = 4;
|
||||
|
||||
/*! a custom CPWindowView that manage border and cursor
|
||||
*/
|
||||
@implementation _CPAttachedWindowView : _CPWindowView
|
||||
{
|
||||
BOOL _mouseDownPressed @accessors(getter=isMouseDownPressed, setter=setMouseDownPressed:);
|
||||
unsigned _gravity @accessors(property=gravity);
|
||||
|
||||
BOOL _useGlowingEffect;
|
||||
CPColor _backgroundTopColor;
|
||||
CPColor _backgroundBottomColor;
|
||||
CPColor _strokeColor;
|
||||
CPImage _cursorBackgroundBottom;
|
||||
CPImage _cursorBackgroundLeft;
|
||||
CPImage _cursorBackgroundRight;
|
||||
CPImage _cursorBackgroundTop;
|
||||
CPSize _cursorSize;
|
||||
}
|
||||
|
||||
/*! compute the contentView frame from a given window frame
|
||||
@param aFrameRect the window frame
|
||||
*/
|
||||
+ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
|
||||
{
|
||||
var contentRect = CGRectMakeCopy(aFrameRect);
|
||||
|
||||
// @todo change border art and remove this pixel perfect adaptation
|
||||
// return CGRectInset(contentRect, 20, 20);
|
||||
|
||||
contentRect.origin.x += 18;
|
||||
contentRect.origin.y += 17;
|
||||
contentRect.size.width -= 35;
|
||||
contentRect.size.height -= 37;
|
||||
|
||||
return contentRect;
|
||||
}
|
||||
|
||||
/*! compute the window frame from a given contentView frame
|
||||
@param aContentRect the contentView frame
|
||||
*/
|
||||
+ (CGRect)frameRectForContentRect:(CGRect)aContentRect
|
||||
{
|
||||
var frameRect = CGRectMakeCopy(aContentRect);
|
||||
|
||||
// @todo change border art and remove this pixel perfect adaptation
|
||||
//return CGRectOffset(frameRect, 20, 20);
|
||||
|
||||
frameRect.origin.x -= 18;
|
||||
frameRect.origin.y -= 17;
|
||||
frameRect.size.width += 35;
|
||||
frameRect.size.height += 37;
|
||||
return frameRect;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask
|
||||
{
|
||||
if (self = [super initWithFrame:aFrame styleMask:aStyleMask])
|
||||
{
|
||||
_cursorSize = CPSizeMake(15, 10);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)hideCursor
|
||||
{
|
||||
_cursorSize = CPSizeMakeZero();
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
- (void)showCursor
|
||||
{
|
||||
_cursorSize = CPSizeMake(15, 10);
|
||||
[self setNeedsDisplay:YES];
|
||||
_mouseDownPressed = NO;
|
||||
}
|
||||
|
||||
|
||||
- (void)drawRect:(CGRect)aRect
|
||||
{
|
||||
[super drawRect:aRect];
|
||||
|
||||
var context = [[CPGraphicsContext currentContext] graphicsPort],
|
||||
gradientColor = [[_backgroundTopColor redComponent], [_backgroundTopColor greenComponent], [_backgroundTopColor blueComponent],1.0, [_backgroundBottomColor redComponent], [_backgroundBottomColor greenComponent], [_backgroundBottomColor blueComponent],1.0],
|
||||
gradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), gradientColor, [0,1], 2),
|
||||
radius = 5,
|
||||
arrowWidth = _cursorSize.width,
|
||||
arrowHeight = _cursorSize.height,
|
||||
strokeWidth = 2;
|
||||
|
||||
CGContextSetStrokeColor(context, _strokeColor);
|
||||
CGContextSetLineWidth(context, strokeWidth);
|
||||
CGContextBeginPath(context);
|
||||
|
||||
aRect.origin.x += strokeWidth;
|
||||
aRect.origin.y += strokeWidth;
|
||||
aRect.size.width -= strokeWidth * 2;
|
||||
aRect.size.height -= strokeWidth * 2;
|
||||
|
||||
if (_useGlowingEffect)
|
||||
{
|
||||
var shadowColor = [[CPColor blackColor] colorWithAlphaComponent:.1],
|
||||
shadowSize = CGSizeMake(0, 0),
|
||||
shadowBlur = 5;
|
||||
|
||||
// Compensate for the shadow blur
|
||||
aRect.origin.x += shadowBlur;
|
||||
aRect.origin.y += shadowBlur;
|
||||
aRect.size.width -= shadowBlur * 2;
|
||||
aRect.size.height -= shadowBlur * 2;
|
||||
|
||||
// Set the shadow
|
||||
CGContextSetShadow(context, CGSizeMake(0,0), 20);
|
||||
CGContextSetShadowWithColor(context, shadowSize, shadowBlur, shadowColor);
|
||||
}
|
||||
|
||||
// Remodulate size and origin
|
||||
aRect.size.width -= 10;
|
||||
aRect.origin.x += 5;
|
||||
aRect.size.height -= 10;
|
||||
aRect.origin.y += 5;
|
||||
|
||||
CGContextAddPath(context, CGPathWithRoundedRectangleInRect(aRect, radius, radius, YES, YES, YES, YES));
|
||||
CGContextDrawLinearGradient(context, gradient, CGPointMake(CPRectGetMidX(aRect), 0.0), CGPointMake(CPRectGetMidX(aRect), aRect.size.height), 0);
|
||||
CGContextClosePath(context);
|
||||
|
||||
// Start the arrow
|
||||
switch (_gravity)
|
||||
{
|
||||
case CPAttachedWindowGravityLeft:
|
||||
CGContextMoveToPoint(context, aRect.size.width + aRect.origin.x, (aRect.size.height / 2 - (arrowWidth / 2)) + aRect.origin.y);
|
||||
CGContextAddLineToPoint(context, aRect.size.width + arrowHeight + aRect.origin.x, (aRect.size.height / 2) + aRect.origin.y);
|
||||
CGContextAddLineToPoint(context, aRect.size.width + aRect.origin.x, (aRect.size.height / 2 + (arrowWidth / 2)) + aRect.origin.y);
|
||||
break;
|
||||
|
||||
case CPAttachedWindowGravityRight:
|
||||
CGContextMoveToPoint(context, aRect.origin.x, (aRect.size.height / 2 - (arrowWidth / 2)) + aRect.origin.y);
|
||||
CGContextAddLineToPoint(context, aRect.origin.x - arrowHeight, (aRect.size.height / 2) + aRect.origin.y);
|
||||
CGContextAddLineToPoint(context, aRect.origin.x, (aRect.size.height / 2 + (arrowWidth / 2) + aRect.origin.y));
|
||||
break;
|
||||
|
||||
case CPAttachedWindowGravityDown:
|
||||
CGContextMoveToPoint(context, (aRect.size.width / 2 - (arrowWidth / 2)) + aRect.origin.x, aRect.origin.y);
|
||||
CGContextAddLineToPoint(context, (aRect.size.width / 2) + aRect.origin.x, aRect.origin.y - arrowHeight);
|
||||
CGContextAddLineToPoint(context, (aRect.size.width / 2) + (arrowWidth / 2) + aRect.origin.x , aRect.origin.y);
|
||||
break;
|
||||
|
||||
case CPAttachedWindowGravityUp:
|
||||
CGContextMoveToPoint(context, (aRect.size.width / 2 - (arrowWidth / 2)) + aRect.origin.x, aRect.size.height + aRect.origin.y);
|
||||
CGContextAddLineToPoint(context, (aRect.size.width / 2) + aRect.origin.x, aRect.size.height + aRect.origin.y + arrowHeight);
|
||||
CGContextAddLineToPoint(context, (aRect.size.width / 2) + (arrowWidth / 2) + aRect.origin.x , aRect.size.height + aRect.origin.y);
|
||||
break;
|
||||
}
|
||||
|
||||
//Draw it
|
||||
CGContextStrokePath(context);
|
||||
CGContextFillPath(context);
|
||||
}
|
||||
|
||||
- (void)mouseDown:(CPEvent)anEvent
|
||||
{
|
||||
_mouseDownPressed = YES;
|
||||
[super mouseDown:anEvent];
|
||||
}
|
||||
|
||||
- (void)mouseUp:(CPEvent)anEvent
|
||||
{
|
||||
_mouseDownPressed = NO;
|
||||
[super mouseUp:anEvent];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation _CPAttachedWindowViewBlack : _CPAttachedWindowView
|
||||
|
||||
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask
|
||||
{
|
||||
if (self = [super initWithFrame:aFrame styleMask:aStyleMask])
|
||||
{
|
||||
_useGlowingEffect = YES;
|
||||
_strokeColor = [CPColor colorWithHexString:@"131313"];
|
||||
_backgroundTopColor = [CPColor colorWithHexString:@"363636"];
|
||||
_backgroundBottomColor = [CPColor colorWithHexString:@"212121"];
|
||||
_cursorSize = CPSizeMake(15, 10);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation _CPAttachedWindowViewWhite : _CPAttachedWindowView
|
||||
|
||||
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask
|
||||
{
|
||||
if (self = [super initWithFrame:aFrame styleMask:aStyleMask])
|
||||
{
|
||||
_useGlowingEffect = YES;
|
||||
_strokeColor = [CPColor colorWithHexString:@"ADEDFF"];
|
||||
_backgroundTopColor = [CPColor colorWithHexString:@"ffffff"];
|
||||
_backgroundBottomColor = [CPColor colorWithHexString:@"ebebeb"];
|
||||
_cursorSize = CPSizeMake(15, 10);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* _CPToolTipWindowView.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by Antoine Mercadal
|
||||
* Copyright 2011 <primalmotion@archipelproject.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "_CPWindowView.j"
|
||||
|
||||
|
||||
@implementation _CPToolTipWindowView : _CPWindowView
|
||||
{
|
||||
BOOL _mouseDownPressed @accessors(getter=isMouseDownPressed, setter=setMouseDownPressed:);
|
||||
unsigned _gravity @accessors(property=gravity);
|
||||
|
||||
CPColor _backgroundColor;
|
||||
CPColor _strokeColor;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Class methods
|
||||
|
||||
/*! compute the contentView frame from a given window frame
|
||||
@param aFrameRect the window frame
|
||||
*/
|
||||
+ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
|
||||
{
|
||||
var contentRect = CGRectMakeCopy(aFrameRect);
|
||||
|
||||
contentRect.origin.x += 3;
|
||||
contentRect.origin.y += 3;
|
||||
contentRect.size.width -= 6;
|
||||
contentRect.size.height -= 6;
|
||||
|
||||
return contentRect;
|
||||
}
|
||||
|
||||
/*! compute the window frame from a given contentView frame
|
||||
@param aContentRect the contentView frame
|
||||
*/
|
||||
+ (CGRect)frameRectForContentRect:(CGRect)aContentRect
|
||||
{
|
||||
var aFrameRect = CGRectMakeCopy(aContentRect);
|
||||
|
||||
aFrameRect.origin.x -= 3;
|
||||
aFrameRect.origin.y -= 3;
|
||||
aFrameRect.size.width += 6;
|
||||
aFrameRect.size.height += 6;
|
||||
|
||||
return aFrameRect;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Initialization
|
||||
|
||||
- (id)initWithFrame:(CPRect)aFrame styleMask:(unsigned)aStyleMask
|
||||
{
|
||||
if (self = [super initWithFrame:aFrame styleMask:aStyleMask])
|
||||
{
|
||||
_strokeColor = [CPColor colorWithHexString:@"E3E3E3"];
|
||||
_backgroundColor = [CPColor colorWithHexString:@"FFFFCA"];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark drawing
|
||||
|
||||
- (void)drawRect:(CGRect)aRect
|
||||
{
|
||||
[super drawRect:aRect];
|
||||
|
||||
var context = [[CPGraphicsContext currentContext] graphicsPort],
|
||||
radius = 2,
|
||||
strokeWidth = 1;
|
||||
|
||||
CGContextSetStrokeColor(context, _strokeColor);
|
||||
CGContextSetFillColor(context, _backgroundColor);
|
||||
CGContextSetLineWidth(context, strokeWidth);
|
||||
CGContextBeginPath(context);
|
||||
|
||||
aRect.origin.x += strokeWidth;
|
||||
aRect.origin.y += strokeWidth;
|
||||
aRect.size.width -= strokeWidth * 2;
|
||||
aRect.size.height -= strokeWidth * 2;
|
||||
|
||||
CGContextAddPath(context, CGPathWithRoundedRectangleInRect(aRect, radius, radius, YES, YES, YES, YES));
|
||||
CGContextClosePath(context);
|
||||
|
||||
//Draw it
|
||||
CGContextStrokePath(context);
|
||||
CGContextFillPath(context);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,394 +0,0 @@
|
||||
/*
|
||||
* _CPAttachedWindow.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by Antoine Mercadal
|
||||
* Copyright 2009, Antoine Mercadal
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CPButton.j"
|
||||
@import "CPColor.j"
|
||||
@import "CPImage.j"
|
||||
@import "CPImageView.j"
|
||||
@import "CPView.j"
|
||||
@import "CPWindow.j"
|
||||
@import "_CPAttachedWindowView.j"
|
||||
|
||||
CPClosableOnBlurWindowMask = 1 << 4;
|
||||
CPAttachedWhiteWindowMask = 1 << 25;
|
||||
CPAttachedBlackWindowMask = 1 << 26;
|
||||
|
||||
/*! @ingroup appkit
|
||||
This is a simple attached window like the one that pops up
|
||||
when you double click on a meeting in iCal
|
||||
*/
|
||||
@implementation _CPAttachedWindow : CPWindow
|
||||
{
|
||||
id _targetView @accessors(property=targetView);
|
||||
BOOL _isClosed;
|
||||
BOOL _closeOnBlur;
|
||||
|
||||
CPButton _closeButton;
|
||||
}
|
||||
|
||||
/*! override default windowView class loader
|
||||
@param aStyleMask the window mask
|
||||
@return the windowView class
|
||||
*/
|
||||
|
||||
+ (Class)_windowViewClassForStyleMask:(unsigned)aStyleMask
|
||||
{
|
||||
if (aStyleMask & CPAttachedWhiteWindowMask)
|
||||
return _CPAttachedWindowViewWhite;
|
||||
|
||||
return _CPAttachedWindowViewBlack;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Initialization
|
||||
|
||||
/*! create and init a CPAttachedWindow with given size of and view
|
||||
@param aSize the size of the attached window
|
||||
@param aView the target view
|
||||
@return ready to use CPAttachedWindow
|
||||
*/
|
||||
+ (id)attachedWindowWithSize:(CGSize)aSize forView:(CPView)aView
|
||||
{
|
||||
return [_CPAttachedWindow attachedWindowWithSize:aSize forView:aView styleMask:nil];
|
||||
}
|
||||
|
||||
/*! create and init a CPAttachedWindow with given size of and view
|
||||
@param aSize the size of the attached window
|
||||
@param aView the target view
|
||||
@return ready to use CPAttachedWindow
|
||||
@param styleMask the window style mask (combine CPClosableWindowMask, CPAttachedWhiteWindowMask, CPAttachedBlackWindowMask and CPClosableOnBlurWindowMask)
|
||||
*/
|
||||
+ (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];
|
||||
|
||||
[attachedWindow attachToView:aView];
|
||||
|
||||
return attachedWindow;
|
||||
}
|
||||
|
||||
/*! create and init a CPAttachedWindow with given frame
|
||||
@param aFrame the frame of the attached window
|
||||
@return ready to use CPAttachedWindow
|
||||
*/
|
||||
- (id)initWithContentRect:(CGRect)aFrame
|
||||
{
|
||||
self = [self initWithContentRect:aFrame styleMask:CPAttachedWhiteWindowMask]
|
||||
return self;
|
||||
}
|
||||
|
||||
/*! create and init a CPAttachedWindow with given frame
|
||||
@param aFrame the frame of the attached window
|
||||
@param styleMask the window style mask (combine CPClosableWindowMask, CPAttachedWhiteWindowMask, CPAttachedBlackWindowMask and CPClosableOnBlurWindowMask)
|
||||
@return ready to use CPAttachedWindow
|
||||
*/
|
||||
- (id)initWithContentRect:(CGRect)aFrame styleMask:(unsigned)aStyleMask
|
||||
{
|
||||
if (self = [super initWithContentRect:aFrame styleMask:aStyleMask])
|
||||
{
|
||||
_isClosed = NO;
|
||||
|
||||
var bundle = [CPBundle bundleForClass:[self class]],
|
||||
buttonClose = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPAttachedWindow/attached-window-button-close.png"] size:CPSizeMake(15.0, 15.0)],
|
||||
buttonClosePressed = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPAttachedWindow/attached-window-button-close-highlighted.png"] size:CPSizeMake(15.0, 15.0)];
|
||||
|
||||
if (aStyleMask & CPClosableWindowMask)
|
||||
{
|
||||
_closeButton = [[CPButton alloc] initWithFrame:CPRectMake(8.0, 1.0, 14.0, 14.0)];
|
||||
[_closeButton setImageScaling:CPScaleProportionally];
|
||||
[_closeButton setBordered:NO];
|
||||
[_closeButton setImage:buttonClose]; // this avoid the blinking..
|
||||
[_closeButton setValue:buttonClose forThemeAttribute:@"image"];
|
||||
[_closeButton setValue:buttonClosePressed forThemeAttribute:@"image" inState:CPThemeStateHighlighted];
|
||||
[_closeButton setTarget:self];
|
||||
[_closeButton setAction:@selector(close:)];
|
||||
[[self contentView] addSubview:_closeButton];
|
||||
}
|
||||
|
||||
_closeOnBlur = (aStyleMask & CPClosableOnBlurWindowMask);
|
||||
|
||||
[self setLevel:CPStatusWindowLevel];
|
||||
[self setMovableByWindowBackground:YES];
|
||||
[self setHasShadow:NO];
|
||||
|
||||
[_windowView setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Window actions
|
||||
|
||||
/*! called when the window is loowing focus and close the window
|
||||
if CPClosableOnBlurWindowMask is setted
|
||||
*/
|
||||
- (void)resignMainWindow
|
||||
{
|
||||
if (_closeOnBlur && !_isClosed)
|
||||
{
|
||||
// set a close flag to avoid infinite loop
|
||||
_isClosed = YES;
|
||||
[self close];
|
||||
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(didAttachedWindowClose:)])
|
||||
[_delegate didAttachedWindowClose:self];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Utilities
|
||||
|
||||
- (CPPoint)computeOrigin:(CPView)aView gravity:(int)gravity
|
||||
{
|
||||
var frameView = [aView frame],
|
||||
currentView = aView,
|
||||
origin = [aView frameOrigin],
|
||||
nativeRect = [[[CPApp mainWindow] platformWindow] nativeContentRect],
|
||||
lastView;
|
||||
|
||||
// if somebody succeed to use the conversion function of CPView
|
||||
// to get this working, please do.
|
||||
while (currentView = [currentView superview])
|
||||
{
|
||||
origin.x += [currentView frameOrigin].x;
|
||||
origin.y += [currentView frameOrigin].y;
|
||||
lastView = currentView;
|
||||
}
|
||||
|
||||
origin.x += [[lastView window] frame].origin.x;
|
||||
origin.y += [[lastView window] frame].origin.y;
|
||||
|
||||
// take care of the scrolling point
|
||||
if ([aView enclosingScrollView])
|
||||
{
|
||||
var offsetPoint = [[[aView enclosingScrollView] contentView] boundsOrigin];
|
||||
origin.x -= offsetPoint.x;
|
||||
origin.y -= offsetPoint.y;
|
||||
}
|
||||
|
||||
var originLeft = CPPointCreateCopy(origin),
|
||||
originRight = CPPointCreateCopy(origin),
|
||||
originTop = CPPointCreateCopy(origin),
|
||||
originBottom = CPPointCreateCopy(origin);
|
||||
|
||||
// CPAttachedWindowGravityRight
|
||||
originRight.x += CPRectGetWidth(frameView);
|
||||
originRight.y += (CPRectGetHeight(frameView) / 2.0) - (CPRectGetHeight([self frame]) / 2.0);
|
||||
|
||||
// CPAttachedWindowGravityLeft
|
||||
originLeft.x -= CPRectGetWidth([self frame]);
|
||||
originLeft.y += (CPRectGetHeight(frameView) / 2.0) - (CPRectGetHeight([self frame]) / 2.0);
|
||||
|
||||
// CPAttachedWindowGravityBottom
|
||||
originBottom.x += CPRectGetWidth(frameView) / 2.0 - CPRectGetWidth([self frame]) / 2.0;
|
||||
originBottom.y += CPRectGetHeight(frameView);
|
||||
|
||||
// CPAttachedWindowGravityTop
|
||||
originTop.x += CPRectGetWidth(frameView) / 2.0 - CPRectGetWidth([self frame]) / 2.0;
|
||||
originTop.y -= CPRectGetHeight([self frame]);
|
||||
|
||||
|
||||
if (gravity === CPAttachedWindowGravityAuto)
|
||||
{
|
||||
var frameCopy = CPRectCreateCopy([self frame]);
|
||||
|
||||
nativeRect.origin.x = 0.0;
|
||||
nativeRect.origin.y = 0.0;
|
||||
|
||||
var tests = [originRight, originLeft, originTop, originBottom];
|
||||
|
||||
gravity = CPAttachedWindowGravityRight;
|
||||
for (var i = 0; i < tests.length; i++)
|
||||
{
|
||||
frameCopy.origin = tests[i];
|
||||
|
||||
if (CPRectContainsRect(nativeRect, frameCopy))
|
||||
{
|
||||
if (CPPointEqualToPoint(tests[i], originRight))
|
||||
{
|
||||
gravity = CPAttachedWindowGravityRight
|
||||
break;
|
||||
}
|
||||
else if (CPPointEqualToPoint(tests[i], originLeft))
|
||||
{
|
||||
gravity = CPAttachedWindowGravityLeft
|
||||
break;
|
||||
}
|
||||
else if (CPPointEqualToPoint(tests[i], originTop))
|
||||
{
|
||||
gravity = CPAttachedWindowGravityUp
|
||||
break;
|
||||
}
|
||||
else if (CPPointEqualToPoint(tests[i], originBottom))
|
||||
{
|
||||
gravity = CPAttachedWindowGravityDown
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var originToBeReturned;
|
||||
switch (gravity)
|
||||
{
|
||||
case CPAttachedWindowGravityRight:
|
||||
originToBeReturned = originRight;
|
||||
break;
|
||||
case CPAttachedWindowGravityLeft:
|
||||
originToBeReturned = originLeft;
|
||||
break;
|
||||
case CPAttachedWindowGravityDown:
|
||||
originToBeReturned = originBottom;
|
||||
break;
|
||||
case CPAttachedWindowGravityUp:
|
||||
originToBeReturned = originTop;
|
||||
break;
|
||||
}
|
||||
|
||||
[_windowView setGravity:gravity];
|
||||
|
||||
var o = originToBeReturned;
|
||||
if (o.x < 0)
|
||||
{
|
||||
[_windowView setGravity:nil];
|
||||
o.x = 0;
|
||||
}
|
||||
if (o.x + CPRectGetWidth([self frame]) > nativeRect.size.width)
|
||||
{
|
||||
[_windowView setGravity:nil];
|
||||
o.x = nativeRect.size.width - CPRectGetWidth([self frame]);
|
||||
}
|
||||
if (o.y < 0)
|
||||
{
|
||||
[_windowView setGravity:nil];
|
||||
o.y = 0;
|
||||
}
|
||||
if (o.y + CPRectGetHeight([self frame]) > nativeRect.size.height)
|
||||
{
|
||||
[_windowView setGravity:nil];
|
||||
o.y = nativeRect.size.height - CPRectGetHeight([self frame]);
|
||||
}
|
||||
|
||||
return originToBeReturned;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Notification handlers
|
||||
|
||||
- (void)_attachedWindowDidMove:(CPNotification)aNotification
|
||||
{
|
||||
if ([_windowView isMouseDownPressed])
|
||||
{
|
||||
[_windowView hideCursor];
|
||||
[self setLevel:CPNormalWindowLevel];
|
||||
[_closeButton setFrameOrigin:CPPointMake(1.0, 1.0)];
|
||||
[[CPNotificationCenter defaultCenter] removeObserver:self name:CPWindowDidMoveNotification object:self];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Utilities
|
||||
|
||||
/*! compute the frame needed to be placed to the given view
|
||||
and position the attached window according to this view (gravity will be CPAttachedWindowGravityAuto)
|
||||
@param aView the view where CPAttachedWindow must be attached
|
||||
*/
|
||||
- (void)positionRelativeToView:(CPView)aView
|
||||
{
|
||||
[self positionRelativeToView:aView gravity:CPAttachedWindowGravityAuto];
|
||||
}
|
||||
|
||||
/*! compute the frame needed to be placed to the given view
|
||||
and position the attached window according to this view
|
||||
@param aView the view where CPAttachedWindow must be attached
|
||||
@param aGravity the gravity to use
|
||||
*/
|
||||
- (void)positionRelativeToView:(CPView)aView gravity:(int)aGravity
|
||||
{
|
||||
var frameView = [aView frame],
|
||||
posX = frameView.origin.x + CPRectGetWidth(frameView),
|
||||
posY = frameView.origin.y + (CPRectGetHeight(frameView) / 2.0) - (CPRectGetHeight([self frame]) / 2.0),
|
||||
point = [self computeOrigin:aView gravity:aGravity];
|
||||
|
||||
point.y = MAX(point.y, 0);
|
||||
|
||||
[self setFrameOrigin:point];
|
||||
[_windowView showCursor];
|
||||
[self setLevel:CPStatusWindowLevel];
|
||||
[_closeButton setFrameOrigin:CPPointMake(1.0, 1.0)];
|
||||
[_windowView setNeedsDisplay:YES];
|
||||
[self makeKeyAndOrderFront:nil];
|
||||
}
|
||||
|
||||
/*! set the _targetView and attach the CPAttachedWindow to it
|
||||
@param aView the view where CPAttachedWindow must be attached
|
||||
*/
|
||||
- (void)attachToView:(CPView)aView
|
||||
{
|
||||
_targetView = aView;
|
||||
[self positionRelativeToView:_targetView];
|
||||
|
||||
[_targetView addObserver:self forKeyPath:@"window.frame" options:nil context:nil];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Actions
|
||||
|
||||
/*! closes the CPAttachedWindow
|
||||
@param sender the sender of the action
|
||||
*/
|
||||
- (IBAction)close:(id)aSender
|
||||
{
|
||||
[self close];
|
||||
|
||||
[_targetView removeObserver:self forKeyPath:@"window.frame"];
|
||||
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(didAttachedWindowClose:)])
|
||||
[_delegate didAttachedWindowClose:self];
|
||||
}
|
||||
|
||||
/*! order front the window as usual and add listener for CPWindowDidMoveNotification
|
||||
@param sender the sender of the action
|
||||
*/
|
||||
- (IBAction)makeKeyAndOrderFront:(is)aSender
|
||||
{
|
||||
[super makeKeyAndOrderFront:aSender];
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_attachedWindowDidMove:) name:CPWindowDidMoveNotification object:self];
|
||||
}
|
||||
|
||||
/*! update the CPAttachedWindow frame if a resize event is observed
|
||||
|
||||
*/
|
||||
- (void)observeValueForKeyPath:(CPString)aPath ofObject:(id)anObject change:(CPDictionary)theChange context:(void)aContext
|
||||
{
|
||||
if ([aPath isEqual:@"window.frame"])
|
||||
{
|
||||
[self positionRelativeToView:_targetView];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+107
-52
@@ -3,7 +3,7 @@
|
||||
* AppKit
|
||||
*
|
||||
* Created by Antoine Mercadal
|
||||
* Copyright 2009, Antoine Mercadal
|
||||
* Copyright 2011 <primalmotion@archipelproject.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -22,36 +22,38 @@
|
||||
|
||||
@import "CPTextField.j"
|
||||
@import "CPView.j"
|
||||
@import "CPWindow.j"
|
||||
|
||||
@import "_CPAttachedWindow.j"
|
||||
_CPToolTipWindowMask = 1 << 27;
|
||||
|
||||
var _CPToolTipHeight = 24.0,
|
||||
_CPToolTipFontSize = 11.0,
|
||||
_CPCurrentToolTip,
|
||||
_CPCurrentToolTipTimer;
|
||||
|
||||
var CPCurrentToolTip,
|
||||
CPCurrentToolTipTimer;
|
||||
|
||||
CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
|
||||
|
||||
/*! @ingroup appkit
|
||||
subclass of CPAttachedWindow in order to build quick tooltip
|
||||
This is a basic tooltip that behaves mostlt like
|
||||
Cocoa ones.
|
||||
*/
|
||||
@implementation _CPToolTip : _CPAttachedWindow
|
||||
@implementation _CPToolTip : CPWindow
|
||||
{
|
||||
CPTextField _content;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Class Methods
|
||||
|
||||
/*! returns an initialized CPToolTip with string and attach it to given view
|
||||
/*! returns an initialized _CPToolTip with string and attach it to given view
|
||||
@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
|
||||
{
|
||||
var tooltip = [[_CPToolTip alloc] initWithString:aString styleMask:CPToolTipDefaultColorMask];
|
||||
var tooltip = [[_CPToolTip alloc] initWithString:aString styleMask:_CPToolTipWindowMask];
|
||||
|
||||
[tooltip setAlphaValue:0.9];
|
||||
[tooltip attachToView:aView];
|
||||
[tooltip resignMainWindow];
|
||||
[tooltip showToolTip];
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
@@ -63,33 +65,43 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
|
||||
*/
|
||||
+ (CPSize)computeCorrectSize:(CPSize)aToolTipSize text:(CPString)aText
|
||||
{
|
||||
var font = [CPFont systemFontOfSize:12.0],
|
||||
textFrameSize = [aText sizeWithFont:font inWidth:(aToolTipSize.width - 10)];
|
||||
var font = [CPFont systemFontOfSize:_CPToolTipFontSize],
|
||||
textFrameSize = [aText sizeWithFont:font inWidth:(aToolTipSize.width)];
|
||||
|
||||
if (textFrameSize.height < 100)
|
||||
{
|
||||
aToolTipSize.height = textFrameSize.height + 10;
|
||||
aToolTipSize.height = textFrameSize.height + 4;
|
||||
return [aToolTipSize, textFrameSize];
|
||||
}
|
||||
|
||||
var newWidth = aToolTipSize.width + ((parseInt(textFrameSize.height - 100) / 30) * 30);
|
||||
textFrameSize = [aText sizeWithFont:font inWidth:newWidth - 10];
|
||||
aToolTipSize.width = newWidth + 5;
|
||||
aToolTipSize.height = textFrameSize.height + 10;
|
||||
var newWidth = aToolTipSize.width + ((parseInt(textFrameSize.height - 100) / _CPToolTipHeight) * _CPToolTipHeight);
|
||||
textFrameSize = [aText sizeWithFont:font inWidth:newWidth - 4];
|
||||
aToolTipSize.width = newWidth + 2;
|
||||
aToolTipSize.height = textFrameSize.height + 4;
|
||||
|
||||
return [aToolTipSize, textFrameSize];
|
||||
}
|
||||
|
||||
/*! override default windowView class loader
|
||||
@param aStyleMask the window mask
|
||||
@return the windowView class
|
||||
*/
|
||||
+ (Class)_windowViewClassForStyleMask:(unsigned)aStyleMask
|
||||
{
|
||||
return _CPToolTipWindowView;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Initialization
|
||||
|
||||
/*! returns an initialized CPToolTip with string
|
||||
/*! returns an initialized _CPToolTip with string
|
||||
@param aString the content of the tooltip
|
||||
@param aStyleMask the tooltip's style mask
|
||||
*/
|
||||
- (id)initWithString:(CPString)aString styleMask:(unsigned)aStyleMask
|
||||
{
|
||||
var toolTipFrame = CPRectMake(0.0, 0.0, 250.0, 30.0),
|
||||
var toolTipFrame = CPRectMake(0.0, 0.0, 250.0, _CPToolTipHeight),
|
||||
layout = [_CPToolTip computeCorrectSize:toolTipFrame.size text:aString],
|
||||
textFrameSize = layout[1];
|
||||
|
||||
@@ -100,25 +112,61 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
|
||||
textFrameSize.height += 4;
|
||||
|
||||
_content = [CPTextField labelWithTitle:aString];
|
||||
[_content setFont:[CPFont systemFontOfSize:_CPToolTipFontSize]]
|
||||
[_content setLineBreakMode:CPLineBreakByCharWrapping];
|
||||
[_content setAlignment:CPJustifiedTextAlignment];
|
||||
[_content setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||
[_content setFrameOrigin:CPPointMake(5.0, 5.0)];
|
||||
[_content setFrameOrigin:CPPointMake(0.0, 0.0)];
|
||||
[_content setFrameSize:textFrameSize];
|
||||
[_content setTextShadowOffset:CGSizeMake(0.0, 1.0)];
|
||||
[_content setTextColor:(aStyleMask & CPAttachedWhiteWindowMask) ? [CPColor blackColor] : [CPColor whiteColor]];
|
||||
[_content setValue:((aStyleMask & CPAttachedWhiteWindowMask) ? [CPColor whiteColor] : [CPColor blackColor]) forThemeAttribute:@"text-shadow-color"];
|
||||
[_content setTextColor:[CPColor blackColor]];
|
||||
|
||||
[[self contentView] addSubview:_content];
|
||||
[self setMovableByWindowBackground:NO];
|
||||
|
||||
[self setLevel:CPStatusWindowLevel];
|
||||
[self setAlphaValue:0.9];
|
||||
|
||||
[_windowView setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Controls
|
||||
|
||||
/*!
|
||||
Show the tooltip after computing the position
|
||||
*/
|
||||
- (void)showToolTip
|
||||
{
|
||||
var mousePosition = [[CPApp currentEvent] globalLocation],
|
||||
nativeRect = [[[CPApp mainWindow] platformWindow] nativeContentRect];
|
||||
|
||||
mousePosition.y += 20;
|
||||
|
||||
if (mousePosition.x < 0)
|
||||
mousePosition.x = 5;
|
||||
if (mousePosition.x + CPRectGetWidth([self frame]) > nativeRect.size.width)
|
||||
mousePosition.x = nativeRect.size.width - CPRectGetWidth([self frame]) - 5;
|
||||
if (mousePosition.y < 0)
|
||||
mousePosition.y = 5;
|
||||
if (mousePosition.y + CPRectGetHeight([self frame]) > nativeRect.size.height)
|
||||
mousePosition.y = nativeRect.size.height - CPRectGetHeight([self frame]) - 5;
|
||||
|
||||
[self setFrameOrigin:mousePosition];
|
||||
[self orderFront:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPView (Tooltips)
|
||||
|
||||
|
||||
/*! @ingroup appkit
|
||||
Make CPView supporting toolTips.
|
||||
*/
|
||||
@implementation CPView (toolTips)
|
||||
|
||||
/*!
|
||||
Sets the tooltip for the receiver.
|
||||
@@ -135,14 +183,13 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
|
||||
if (!_DOMElement)
|
||||
return;
|
||||
|
||||
var fIn = function(e)
|
||||
{
|
||||
[self _fireToolTip];
|
||||
},
|
||||
fOut = function(e)
|
||||
{
|
||||
[self _invalidateToolTip];
|
||||
};
|
||||
var fIn = function(e){
|
||||
[self _fireToolTip];
|
||||
};
|
||||
fOut = function(e){
|
||||
[self _invalidateToolTip];
|
||||
};
|
||||
|
||||
|
||||
if (_toolTip)
|
||||
{
|
||||
@@ -176,21 +223,29 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the receiver's tooltip
|
||||
*/
|
||||
- (CPString)toolTip
|
||||
{
|
||||
return _toolTip;
|
||||
}
|
||||
|
||||
/*! @ignore
|
||||
starts the tooltip timer
|
||||
*/
|
||||
- (void)_fireToolTip
|
||||
{
|
||||
if (CPCurrentToolTipTimer)
|
||||
if (_CPCurrentToolTipTimer)
|
||||
{
|
||||
[CPCurrentToolTipTimer invalidate];
|
||||
if (CPCurrentToolTip)
|
||||
[CPCurrentToolTip close:nil];
|
||||
CPCurrentToolTip = nil;
|
||||
[_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];
|
||||
_CPCurrentToolTipTimer = [CPTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(_showToolTip:) userInfo:nil repeats:NO];
|
||||
}
|
||||
|
||||
/*! @ignore
|
||||
@@ -198,16 +253,16 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
|
||||
*/
|
||||
- (void)_invalidateToolTip
|
||||
{
|
||||
if (CPCurrentToolTipTimer)
|
||||
if (_CPCurrentToolTipTimer)
|
||||
{
|
||||
[CPCurrentToolTipTimer invalidate];
|
||||
CPCurrentToolTipTimer = nil;
|
||||
[_CPCurrentToolTipTimer invalidate];
|
||||
_CPCurrentToolTipTimer = nil;
|
||||
}
|
||||
|
||||
if (CPCurrentToolTip)
|
||||
if (_CPCurrentToolTip)
|
||||
{
|
||||
[CPCurrentToolTip close:nil];
|
||||
CPCurrentToolTip = nil;
|
||||
[_CPCurrentToolTip close];
|
||||
_CPCurrentToolTip = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,9 +271,9 @@ CPToolTipDefaultColorMask = CPAttachedBlackWindowMask;
|
||||
*/
|
||||
- (void)_showToolTip:(CPTimer)aTimer
|
||||
{
|
||||
if (CPCurrentToolTip)
|
||||
[CPCurrentToolTip close:nil];
|
||||
CPCurrentToolTip = [_CPToolTip toolTipWithString:_toolTip forView:self];
|
||||
if (_CPCurrentToolTip)
|
||||
[_CPCurrentToolTip close:nil];
|
||||
_CPCurrentToolTip = [_CPToolTip toolTipWithString:_toolTip];
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
Reference in new issue
Block a user