Merge remote-tracking branch 'remotes/alex/nssearchfield'

This commit is contained in:
Riccardo Canalicchio 2014-01-05 13:00:14 +01:00
commit d8033268af
11 changed files with 199 additions and 34 deletions

View File

@ -31,7 +31,8 @@ Rik_OBJC_FILES = \
RikScrollerKnobCell.m\
RikScrollerKnobSlotCell.m\
RikScrollerArrowCell.m\
NSBrowserCell+Rik.m
NSBrowserCell+Rik.m\
NSSearchFieldCell+Rik.m
ADDITIONAL_TOOL_LIBS =
$(BUNDLE_NAME)_RESOURCE_FILES = \

13
NSSearchFieldCell+Rik.h Normal file
View File

@ -0,0 +1,13 @@
/**
* Copyright (C) 2013 Alessandro Sangiuliano
* Author: Alessandro Sangiuliano <alex22_7@hotmail.com>
* Date: 31 December 2013
*/
#import "Rik.h"
@interface NSSearchFieldCell (RikTheme)
{
}
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView;
@end

147
NSSearchFieldCell+Rik.m Normal file
View File

@ -0,0 +1,147 @@
/**
* Copyright (C) 2013 Alessandro Sangiuliano
* Author: Alessandro Sangiuliano <alex22_7@hotmail.com>
* Date: 31 December 2013
*/
#import "Rik.h"
#import "NSSearchFieldCell+Rik.h"
#import "Rik+Button.h"
#define ICON_WIDTH 16
@implementation NSSearchFieldCell (RikTheme)
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
NSRect frame = cellFrame;
[super drawWithFrame: [self searchTextRectForBounds: cellFrame ]
inView: controlView];
[_search_button_cell drawWithFrame: [self searchButtonRectForBounds: cellFrame] inView: controlView];
if ([[self stringValue] length] > 0)
[_cancel_button_cell drawWithFrame: [self cancelButtonRectForBounds: cellFrame]
inView: controlView];
}
/* This method put the "x" cell inside the Text cell */
- (NSRect) searchTextRectForBounds: (NSRect)rect
{
NSRect search, text, part;
if (_search_button_cell)
{
part = rect;
/*set the right point and size*/
part.origin.x +=1;
part.size.width -= 1;
}
else
{
NSDivideRect(rect, &search, &part, ICON_WIDTH, NSMinXEdge);
}
text = part;
return text;
}
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
inView: (NSView*)controlView
{
CGFloat radius = cellFrame.size.height / 2.0;
NSRect rect = cellFrame;
rect.origin.x -= 0.5;
rect.origin.y += 0.5;
rect.size.height -= 1;
//rect.size.width += 1;
NSBezierPath* roundedSearchFieldPath = [NSBezierPath bezierPathWithRoundedRect: rect
xRadius: radius
yRadius: radius];
[roundedSearchFieldPath setLineWidth:1.0];
[[NSColor whiteColor] setFill];
[roundedSearchFieldPath fill];
[[Rik controlStrokeColor] setStroke];
[roundedSearchFieldPath stroke];
}
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
if (_cell.in_editing)
[self _drawEditorWithFrame: cellFrame inView: controlView];
else
{
NSRect titleRect;
/* Make sure we are a text cell; titleRect might return an incorrect
rectangle otherwise. Note that the type could be different if the
user has set an image on us, which we just ignore (OS X does so as
well). */
_cell.type = NSTextCellType;
titleRect = [self titleRectForBounds: cellFrame];
[[self _drawAttributedString] drawInRect: titleRect];
}
}
- (void) _drawEditorWithFrame: (NSRect)cellFrame
inView: (NSView *)controlView
{
if ([controlView isKindOfClass: [NSControl class]])
{
/* Adjust the text editor's frame to match cell's frame (w/o border) */
NSRect titleRect = [self titleRectForBounds: cellFrame];
NSText *textObject = [(NSControl*)controlView currentEditor];
NSView *clipView = [textObject superview];
if ([clipView isKindOfClass: [NSClipView class]])
{
[clipView setFrame: titleRect];
}
else
{
[textObject setFrame: titleRect];
}
}
}
- (NSRect) titleRectForBounds: (NSRect)theRect
{
if (_cell.type == NSTextCellType)
{
NSRect frame = [self drawingRectForBounds: theRect];
//Add spacing between border and inside
if (_cell.is_bordered || _cell.is_bezeled)
{
frame.origin.x += 15;
frame.size.width -= 30;
frame.origin.y -= 1;
frame.size.height += 1;
}
return frame;
}
else
{
return theRect;
}
}
- (NSRect) searchButtonRectForBounds: (NSRect)rect;
{
NSRect search, part;
NSDivideRect(rect, &search, &part, ICON_WIDTH, NSMinXEdge);
search.origin.x +=2;
return search;
}
- (NSRect) cancelButtonRectForBounds: (NSRect)rect
{
NSRect part, clear;
NSDivideRect(rect, &clear, &part, ICON_WIDTH, NSMaxXEdge);
clear.origin.x -= 2; //This set the position inside the textsearch box
return clear;
}
@end

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

View File

@ -1,8 +1,7 @@
#import "Rik.h"
@interface Rik (RikButton)
@interface Rik(RikButton)
{
}
- (NSGradient *) _bezelGradientWithColor:(NSColor*) baseColor;
@end

View File

@ -1,4 +1,5 @@
#import "Rik.h"
#import "Rik+Stepper.h"
@implementation Rik(RikFocusFrame)
@ -92,16 +93,16 @@
- (NSSize) sizeForBorderType: (NSBorderType)aType
{
switch (aType)
{
case NSLineBorder:
return NSMakeSize(4, 4);
case NSGrooveBorder:
case NSBezelBorder:
return NSMakeSize(4, 4);
case NSNoBorder:
default:
return NSZeroSize;
}
{
case NSLineBorder:
return NSMakeSize(4, 4);
case NSGrooveBorder:
case NSBezelBorder:
return NSMakeSize(4, 4);
case NSNoBorder:
default:
return NSZeroSize;
}
}
@end

7
Rik+Stepper.h Normal file
View File

@ -0,0 +1,7 @@
#import "Rik.h"
@interface Rik(RikStepper)
-(NSBezierPath *) stepperBezierPathWithFrame:(NSRect)frame;
@end

View File

@ -1,8 +1,5 @@
#import "Rik.h"
@interface Rik(RikStepper)
@end
#import "Rik+Stepper.h"
@implementation Rik(RikStepper)
- (NSRect) stepperUpButtonRectWithFrame: (NSRect)frame
@ -39,11 +36,11 @@
{
NSImage *image = [NSImage imageNamed: @"common_ArrowUp"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
hints: nil];
}
- (void) drawStepperHighlightUpButton: (NSRect)aRect
@ -61,22 +58,22 @@
[fillgradient drawInBezierPath:roundedRectanglePath angle:90];
NSImage *image = [NSImage imageNamed: @"common_ArrowUp"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
hints: nil];
}
- (void) drawStepperDownButton: (NSRect)aRect
{
NSImage *image = [NSImage imageNamed: @"common_ArrowDown"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
hints: nil];
}
- (void) drawStepperHighlightDownButton: (NSRect)aRect
@ -94,11 +91,11 @@
[fillgradient drawInBezierPath:roundedRectanglePath angle:90];
NSImage *image = [NSImage imageNamed: @"common_ArrowDown"];
[image drawInRect: NSInsetRect(aRect, 4, 4)
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1
respectFlipped: YES
hints: nil];
hints: nil];
}
- (void) drawStepperCell: (NSCell*)cell
withFrame: (NSRect)cellFrame

2
Rik.h
View File

@ -1,4 +1,4 @@
#include <AppKit/AppKit.h>
#import <AppKit/AppKit.h>
#import <Foundation/NSUserDefaults.h>
#import <GNUstepGUI/GSTheme.h>