Permalink
Browse files

Merge remote-tracking branch 'aki-null/master'

Conflicts:
	MarkdownLive.xcodeproj/project.pbxproj
	MyDocument.m
	discount/VERSION
	discount/configure.inc
	discount/main.c
  • Loading branch information...
2 parents 7965019 + bca82fa commit 35265cdefbf38fa4c0f697c5b9a027c43c9bb7c5 @mugginsoft mugginsoft committed Jul 13, 2011
View
@@ -0,0 +1,20 @@
+//
+// TCLayoutManager.h
+// MarkdownLive
+//
+// Created by Akihiro Noguchi on 7/05/11.
+// Copyright 2011 Aki. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface EditPaneLayoutManager : NSLayoutManager {
+ NSFont *font;
+}
+
+@property (nonatomic, retain) NSFont *font;
+
+- (CGFloat)lineHeight;
+
+@end
View
@@ -0,0 +1,59 @@
+//
+// TCLayoutManager.m
+// MarkdownLive
+//
+// Created by Akihiro Noguchi on 7/05/11.
+// Copyright 2011 Aki. All rights reserved.
+//
+
+#import "EditPaneLayoutManager.h"
+#import "EditPaneTypesetter.h"
+
+
+@implementation EditPaneLayoutManager
+
+@synthesize font;
+
+- (id)init {
+ if ((self = [super init])) {
+ EditPaneTypesetter *typeSetter = [[EditPaneTypesetter alloc] init];
+ [self setTypesetter:typeSetter];
+ [typeSetter release];
+ [self setUsesFontLeading:NO];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ self.font = nil;
+ [super dealloc];
+}
+
+- (CGFloat)lineHeight {
+ return floor([self defaultLineHeightForFont:font] + 1.5);
+}
+
+- (void)setLineFragmentRect:(NSRect)inFragmentRect forGlyphRange:(NSRange)inGlyphRange
+ usedRect:(NSRect)inUsedRect {
+ inFragmentRect.size.height = [self lineHeight];
+ inUsedRect.size.height = [self lineHeight];
+
+ (void)[super setLineFragmentRect:(NSRect)inFragmentRect
+ forGlyphRange:(NSRange)inGlyphRange
+ usedRect:(NSRect)inUsedRect];
+}
+
+- (void)setExtraLineFragmentRect:(NSRect)inFragmentRect usedRect:(NSRect)inUsedRect
+ textContainer:(NSTextContainer *)inTextContainer {
+ inFragmentRect.size.height = [self lineHeight];
+ [super setExtraLineFragmentRect:inFragmentRect usedRect:inUsedRect
+ textContainer:inTextContainer];
+}
+
+- (NSPoint)locationForGlyphAtIndex:(NSUInteger)inGlyphIndex {
+ NSPoint outPoint = [super locationForGlyphAtIndex:inGlyphIndex];
+ outPoint.y = [font pointSize];
+ return outPoint;
+}
+
+@end
View
@@ -0,0 +1,21 @@
+//
+// EditPaneTextView.h
+// MarkdownLive
+//
+// Created by Akihiro Noguchi on 9/05/11.
+// Copyright 2011 Aki. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#define kEditPaneTextViewChangedNotification @"EditPaneTextViewChangedNotification"
+
+@class EditPaneLayoutManager;
+
+@interface EditPaneTextView : NSTextView {
+ EditPaneLayoutManager *layoutMan;
+}
+
+- (void)updateColors;
+- (void)updateFont;
+
+@end
View
@@ -0,0 +1,113 @@
+//
+// EditPaneTextView.m
+// MarkdownLive
+//
+// Created by Akihiro Noguchi on 9/05/11.
+// Copyright 2011 Aki. All rights reserved.
+//
+
+#import "EditPaneTextView.h"
+#import "EditPaneLayoutManager.h"
+#import "PreferencesManager.h"
+#import "PreferencesController.h"
+
+
+@implementation EditPaneTextView
+
+- (void)awakeFromNib {
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(updateFont)
+ name:kEditPaneFontNameChangedNotification
+ object:nil];
+
+ NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
+
+ [defaultsController addObserver:self
+ forKeyPath:[NSString stringWithFormat:@"values.%@", kEditPaneForegroundColor]
+ options:0
+ context:@"ColorChange"];
+ [defaultsController addObserver:self
+ forKeyPath:[NSString stringWithFormat:@"values.%@", kEditPaneBackgroundColor]
+ options:0
+ context:@"ColorChange"];
+ [defaultsController addObserver:self
+ forKeyPath:[NSString stringWithFormat:@"values.%@", kEditPaneSelectionColor]
+ options:0
+ context:@"ColorChange"];
+ [defaultsController addObserver:self
+ forKeyPath:[NSString stringWithFormat:@"values.%@", kEditPaneCaretColor]
+ options:0
+ context:@"ColorChange"];
+
+ [self setUsesFontPanel:NO];
+
+ NSTextContainer *textContainer = [[NSTextContainer alloc] init];
+ [textContainer setContainerSize:[[self textContainer] containerSize]];
+ [textContainer setWidthTracksTextView:YES];
+ layoutMan = [[EditPaneLayoutManager alloc] init];
+ [self replaceTextContainer:textContainer];
+ [textContainer replaceLayoutManager:layoutMan];
+ [textContainer release];
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self];
+ [layoutMan release];
+ [super dealloc];
+}
+
+- (void)keyDown:(NSEvent *)aEvent {
+ [super keyDown:aEvent];
+ [[NSNotificationCenter defaultCenter] postNotificationName:kEditPaneTextViewChangedNotification
+ object:self];
+}
+
+- (void)setMarkedText:(id)aString
+ selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange {
+ id resultString;
+ if ([aString isKindOfClass:[NSAttributedString class]]) {
+ resultString = [[aString mutableCopy] autorelease];
+ selectedRange = NSMakeRange(0, [resultString length]);
+ NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
+ [PreferencesManager editPaneForegroundColor], NSUnderlineColorAttributeName,
+ nil];
+ [resultString setAttributes:attrs range:selectedRange];
+ } else {
+ resultString = aString;
+ }
+
+ [super setMarkedText:resultString
+ selectedRange:selectedRange replacementRange:replacementRange];
+}
+
+- (void)updateColors {
+ [[self enclosingScrollView] setBackgroundColor:[PreferencesManager editPaneBackgroundColor]];
+ [self setTextColor:[PreferencesManager editPaneForegroundColor]];
+ [self setInsertionPointColor:[PreferencesManager editPaneCaretColor]];
+ NSDictionary *selectedAttr = [NSDictionary dictionaryWithObject:[PreferencesManager editPaneSelectionColor]
+ forKey:NSBackgroundColorAttributeName];
+ [self setSelectedTextAttributes:selectedAttr];
+}
+
+- (void)updateFont {
+ layoutMan.font = [PreferencesManager editPaneFont];
+ [self setFont:layoutMan.font];
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath
+ ofObject:(id)object
+ change:(NSDictionary *)change
+ context:(void *)context {
+
+#pragma unused(keyPath)
+#pragma unused(object)
+#pragma unused(change)
+
+ if ([(NSString *)context isEqualToString:@"ColorChange"]) {
+ [self updateColors];
+ }
+}
+
+@end
View
@@ -0,0 +1,16 @@
+//
+// TCTypeSetter.h
+// MarkdownLive
+//
+// Created by Akihiro Noguchi on 7/05/11.
+// Copyright 2011 Aki. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface EditPaneTypesetter : NSATSTypesetter {
+
+}
+
+@end
View
@@ -0,0 +1,32 @@
+//
+// TCTypeSetter.m
+// MarkdownLive
+//
+// Created by Akihiro Noguchi on 7/05/11.
+// Copyright 2011 Aki. All rights reserved.
+//
+
+#import "EditPaneTypesetter.h"
+#import "EditPaneLayoutManager.h"
+
+
+@implementation EditPaneTypesetter
+
+- (id)init {
+ if ((self = [super init])) {
+ [self setUsesFontLeading:YES];
+ }
+ return self;
+}
+
+- (CGFloat)lineSpacingAfterGlyphAtIndex:(NSUInteger)inGlyphIndex
+ withProposedLineFragmentRect:(NSRect)inRect {
+
+#pragma unused(inGlyphIndex)
+
+ EditPaneLayoutManager *theManager = (EditPaneLayoutManager *)[self layoutManager];
+ CGFloat theDefaultLineHeight = [theManager defaultLineHeightForFont:theManager.font];
+ return floor(theDefaultLineHeight - inRect.size.height + 1.5);
+}
+
+@end
Oops, something went wrong.

0 comments on commit 35265cd

Please sign in to comment.