From b370ab1b0a746854262ed99811970ae53d23557d Mon Sep 17 00:00:00 2001 From: emsquared Date: Mon, 23 Jul 2012 10:03:07 -0400 Subject: [PATCH] Window height based maximum input text field height. --- Classes/Controllers/TXMasterController.m | 9 +++- Classes/Headers/TVCInputTextField.h | 2 +- .../Input Text Field/TVCInputTextField.m | 48 +++++++++++++------ Resources/Info.plist | 4 +- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/Classes/Controllers/TXMasterController.m b/Classes/Controllers/TXMasterController.m index 47e1fdcb59..c28c82b503 100755 --- a/Classes/Controllers/TXMasterController.m +++ b/Classes/Controllers/TXMasterController.m @@ -367,6 +367,11 @@ - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender #pragma mark - #pragma mark NSWindow Delegate +- (void)windowDidResize:(NSNotification *)notification +{ + [self.text resetTextFieldCellSize:YES]; +} + - (void)windowDidBecomeKey:(NSNotification *)notification { id sel = self.world.selected; @@ -1221,8 +1226,8 @@ - (void)_moveInputHistory:(BOOL)up checkScroller:(BOOL)scroll event:(NSEvent *)e [self.text setAttributedStringValue:s]; [self.world focusInputText]; - if ([self.text respondsToSelector:@selector(resetTextFieldCellSize)]) { - [self.text resetTextFieldCellSize]; + if ([self.text respondsToSelector:@selector(resetTextFieldCellSize:)]) { + [self.text resetTextFieldCellSize:NO]; } } } diff --git a/Classes/Headers/TVCInputTextField.h b/Classes/Headers/TVCInputTextField.h index 048033f412..281f45a72d 100755 --- a/Classes/Headers/TVCInputTextField.h +++ b/Classes/Headers/TVCInputTextField.h @@ -43,7 +43,7 @@ @property (nonatomic, strong) NSAttributedString *placeholderString; - (void)updateTextDirection; -- (void)resetTextFieldCellSize; +- (void)resetTextFieldCellSize:(BOOL)force; - (void)redrawOriginPoints; - (void)setReturnActionWithSelector:(SEL)selector owner:(id)owner; diff --git a/Classes/Views/Input Text Field/TVCInputTextField.m b/Classes/Views/Input Text Field/TVCInputTextField.m index 602e63503b..0e1235e191 100755 --- a/Classes/Views/Input Text Field/TVCInputTextField.m +++ b/Classes/Views/Input Text Field/TVCInputTextField.m @@ -41,7 +41,6 @@ #import -#define _InputTextFiedMaxHeight 382.0 #define _InputBoxDefaultHeight 18.0 #define _InputBoxHeightMultiplier 14.0 #define _InputBoxBackgroundMaxHeight 387.0 @@ -136,7 +135,12 @@ - (void)updateTextDirection } } -- (void)resetTextFieldCellSize +- (NSInteger)backgroundViewMaximumHeight +{ + return (self.window.frame.size.height - 50); +} + +- (void)resetTextFieldCellSize:(BOOL)force { BOOL drawBezel = YES; @@ -168,7 +172,7 @@ - (void)resetTextFieldCellSize } else { NSInteger totalLinesBase = [self numberOfLines]; - if (_lastDrawnLineCount == totalLinesBase) { + if (_lastDrawnLineCount == totalLinesBase && force == NO) { drawBezel = NO; } @@ -176,19 +180,35 @@ - (void)resetTextFieldCellSize if (drawBezel) { NSInteger totalLinesMath = (totalLinesBase - 1); - + + /* Calculate unfiltered height. */ textBoxFrame.size.height = _InputBoxDefaultHeight; backgroundFrame.size.height = _InputBoxBackgroundDefaultHeight; textBoxFrame.size.height += (totalLinesMath * _InputBoxHeightMultiplier); backgroundFrame.size.height += (totalLinesMath * _InputBoxBackgroundHeightMultiplier); - - if (textBoxFrame.size.height > _InputTextFiedMaxHeight) { - textBoxFrame.size.height = _InputTextFiedMaxHeight; - } - - if (backgroundFrame.size.height > _InputBoxBackgroundMaxHeight) { - backgroundFrame.size.height = _InputBoxBackgroundMaxHeight; + + NSInteger backgroundViewMaxHeight = [self backgroundViewMaximumHeight]; + + /* Fix height if it exceeds are maximum. */ + if (backgroundFrame.size.height > backgroundViewMaxHeight) { + for (NSInteger i = totalLinesMath; i >= 0; i--) { + NSInteger newSize = 0; + + newSize = _InputBoxBackgroundDefaultHeight; + newSize += (i * _InputBoxBackgroundHeightMultiplier); + + if (newSize > backgroundViewMaxHeight) { + continue; + } else { + backgroundFrame.size.height = newSize; + + textBoxFrame.size.height = _InputBoxDefaultHeight; + textBoxFrame.size.height += (i * _InputBoxHeightMultiplier); + + break; + } + } } } } @@ -214,7 +234,7 @@ - (void)resetTextFieldCellSize - (void)textDidChange:(NSNotification *)aNotification { - [self resetTextFieldCellSize]; + [self resetTextFieldCellSize:NO]; if (NSObjectIsEmpty(self.stringValue)) { [super sanitizeTextField:NO]; @@ -249,7 +269,7 @@ - (void)paste:(id)sender { [super paste:self]; - [self resetTextFieldCellSize]; + [self resetTextFieldCellSize:NO]; [self sanitizeTextField:YES]; } @@ -264,7 +284,7 @@ - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector if (aSelector == @selector(insertNewline:)) { objc_msgSend(self.actionTarget, self.actionSelector); - [self resetTextFieldCellSize]; + [self resetTextFieldCellSize:NO]; [self sanitizeTextField:NO]; return YES; diff --git a/Resources/Info.plist b/Resources/Info.plist index d50331f18c..c13cb1d425 100755 --- a/Resources/Info.plist +++ b/Resources/Info.plist @@ -47,8 +47,8 @@ TXBundleBuildCodeName Turtle Soup TXBundleBuildNumber - 11959 + 11976 TXBundleBuildReference - 2.1.1-246-gbd7d091-appstore,llvm4.0 + 2.1.1-247-g6c5f2b9-debug,llvm4.0