2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSTextContainer</title>
|
1999-06-17 15:08:05 +00:00
|
|
|
|
|
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
Author: Alexander Malmberg <alexander@malmberg.org>
|
|
|
|
Date: 2002-11-23
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Jonathan Gapen <jagapen@smithlab.chem.wisc.edu>
|
1999-06-17 15:08:05 +00:00
|
|
|
Date: 1999
|
2001-01-07 00:59:57 +00:00
|
|
|
|
1999-06-17 15:08:05 +00:00
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1999-06-17 15:08:05 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +00:00
|
|
|
|
1999-06-17 15:08:05 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-04 21:02:29 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2007-10-29 21:16:17 +00:00
|
|
|
Lesser General Public License for more details.
|
1999-06-17 15:08:05 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1999-06-17 15:08:05 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
1999-06-17 15:08:05 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-04 11:33:22 +00:00
|
|
|
#import <Foundation/NSGeometry.h>
|
|
|
|
#import <Foundation/NSNotification.h>
|
|
|
|
#import <Foundation/NSDebug.h>
|
|
|
|
#import "AppKit/NSLayoutManager.h"
|
|
|
|
#import "AppKit/NSTextContainer.h"
|
|
|
|
#import "AppKit/NSTextStorage.h"
|
|
|
|
#import "AppKit/NSTextView.h"
|
|
|
|
#import "GNUstepGUI/GSLayoutManager.h"
|
|
|
|
#import "GSGuiPrivate.h"
|
1999-06-17 15:08:05 +00:00
|
|
|
|
|
|
|
@interface NSTextContainer (TextViewObserver)
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) _textViewFrameChanged: (NSNotification*)aNotification;
|
1999-06-17 15:08:05 +00:00
|
|
|
@end
|
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
|
|
|
|
/* TODO: rethink how this is is triggered.
|
|
|
|
use bounds rectangle instead of frame? */
|
1999-06-17 15:08:05 +00:00
|
|
|
@implementation NSTextContainer (TextViewObserver)
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) _textViewFrameChanged: (NSNotification*)aNotification
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
if (_observingFrameChanges)
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
2008-01-04 21:02:29 +00:00
|
|
|
id textView;
|
|
|
|
NSSize newTextViewSize;
|
|
|
|
NSSize size;
|
|
|
|
NSSize inset;
|
2000-09-05 17:31:03 +00:00
|
|
|
|
1999-06-17 15:08:05 +00:00
|
|
|
textView = [aNotification object];
|
2000-09-30 23:14:12 +00:00
|
|
|
if (textView != _textView)
|
|
|
|
{
|
2008-01-04 21:02:29 +00:00
|
|
|
NSDebugLog(@"NSTextContainer got notification for wrong View %@",
|
|
|
|
textView);
|
|
|
|
return;
|
|
|
|
}
|
2000-09-05 17:31:03 +00:00
|
|
|
newTextViewSize = [textView frame].size;
|
2001-01-07 00:59:57 +00:00
|
|
|
size = _containerRect.size;
|
1999-06-17 15:08:05 +00:00
|
|
|
inset = [textView textContainerInset];
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
if (_widthTracksTextView)
|
2008-01-04 21:02:29 +00:00
|
|
|
{
|
|
|
|
size.width = MAX(newTextViewSize.width - (inset.width * 2.0), 0.0);
|
|
|
|
}
|
2000-02-19 00:40:47 +00:00
|
|
|
if (_heightTracksTextView)
|
2008-01-04 21:02:29 +00:00
|
|
|
{
|
2009-02-03 15:56:51 +00:00
|
|
|
size.height = MAX(newTextViewSize.height - (inset.height * 2.0), 0.0);
|
2008-01-04 21:02:29 +00:00
|
|
|
}
|
1999-06-17 15:08:05 +00:00
|
|
|
|
2001-01-07 00:59:57 +00:00
|
|
|
[self setContainerSize: size];
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* NSTextContainer (TextViewObserver) */
|
|
|
|
|
|
|
|
@implementation NSTextContainer
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
2000-02-19 00:40:47 +00:00
|
|
|
if (self == [NSTextContainer class])
|
|
|
|
{
|
|
|
|
[self setVersion: 1];
|
|
|
|
}
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithContainerSize: (NSSize)aSize
|
|
|
|
{
|
2003-04-28 16:37:56 +00:00
|
|
|
NSDebugLLog(@"NSText", @"NSTextContainer initWithContainerSize");
|
2009-02-03 15:56:51 +00:00
|
|
|
if (aSize.width < 0)
|
|
|
|
{
|
2021-10-27 19:18:23 +00:00
|
|
|
NSWarnMLog(@"given negative width: %f current: %f", aSize.width, _containerRect.size.width);
|
2009-02-03 15:56:51 +00:00
|
|
|
aSize.width = 0;
|
|
|
|
}
|
|
|
|
if (aSize.height < 0)
|
|
|
|
{
|
2021-10-27 19:18:23 +00:00
|
|
|
NSWarnMLog(@"given negative height: %f current: %f", aSize.height, _containerRect.size.height);
|
2009-02-03 15:56:51 +00:00
|
|
|
aSize.height = 0;
|
|
|
|
}
|
1999-06-17 15:08:05 +00:00
|
|
|
_layoutManager = nil;
|
|
|
|
_textView = nil;
|
|
|
|
_containerRect.size = aSize;
|
2011-11-28 17:20:45 +00:00
|
|
|
// Tests on Cocoa indicate the default value is 5.
|
2011-12-02 21:36:58 +00:00
|
|
|
_lineFragmentPadding = 5.0;
|
1999-06-17 15:08:05 +00:00
|
|
|
_observingFrameChanges = NO;
|
|
|
|
_widthTracksTextView = NO;
|
|
|
|
_heightTracksTextView = NO;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-09-25 22:08:50 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
2010-05-30 20:57:01 +00:00
|
|
|
return [self initWithContainerSize: NSMakeSize(1e7, 1e7)];
|
2009-09-25 22:08:50 +00:00
|
|
|
}
|
|
|
|
|
2000-12-16 20:18:33 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2001-10-18 15:26:59 +00:00
|
|
|
if (_textView != nil)
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc removeObserver: self
|
2008-01-04 21:02:29 +00:00
|
|
|
name: NSViewFrameDidChangeNotification
|
|
|
|
object: _textView];
|
2003-09-23 17:13:20 +00:00
|
|
|
|
|
|
|
[_textView setTextContainer: nil];
|
2003-04-28 16:37:56 +00:00
|
|
|
RELEASE(_textView);
|
2001-10-18 15:26:59 +00:00
|
|
|
}
|
2000-12-16 20:18:33 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2003-01-29 20:19:01 +00:00
|
|
|
/*
|
|
|
|
See [NSTextView -setTextContainer:] for more information about these calls.
|
|
|
|
*/
|
2003-01-26 19:21:40 +00:00
|
|
|
- (void) setLayoutManager: (GSLayoutManager*)aLayoutManager
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
2000-12-16 20:18:33 +00:00
|
|
|
/* The layout manager owns us - so he retains us and we don't retain
|
|
|
|
him. */
|
|
|
|
_layoutManager = aLayoutManager;
|
2003-01-29 20:19:01 +00:00
|
|
|
/* Tell our text view about the change. */
|
|
|
|
[_textView setTextContainer: self];
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
- (GSLayoutManager*) layoutManager
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
|
|
|
return _layoutManager;
|
|
|
|
}
|
|
|
|
|
2003-04-28 16:37:56 +00:00
|
|
|
/*
|
|
|
|
Replaces the layout manager while maintaining the text object
|
|
|
|
framework intact.
|
|
|
|
*/
|
2003-01-26 19:21:40 +00:00
|
|
|
- (void) replaceLayoutManager: (GSLayoutManager*)aLayoutManager
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
2002-10-13 10:26:57 +00:00
|
|
|
if (aLayoutManager != _layoutManager)
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
2003-02-01 02:32:35 +00:00
|
|
|
NSTextStorage *textStorage = [_layoutManager textStorage];
|
|
|
|
NSArray *textContainers = [_layoutManager textContainers];
|
2013-02-17 22:44:47 +00:00
|
|
|
NSUInteger i, count = [textContainers count];
|
2003-02-01 02:32:35 +00:00
|
|
|
GSLayoutManager *oldLayoutManager = _layoutManager;
|
2000-02-19 00:40:47 +00:00
|
|
|
|
2003-02-01 02:32:35 +00:00
|
|
|
RETAIN(oldLayoutManager);
|
2010-03-23 20:27:23 +00:00
|
|
|
RETAIN(textStorage);
|
2000-02-19 00:40:47 +00:00
|
|
|
[textStorage removeLayoutManager: _layoutManager];
|
2002-10-13 10:26:57 +00:00
|
|
|
[textStorage addLayoutManager: aLayoutManager];
|
2000-02-19 00:40:47 +00:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2008-01-04 21:02:29 +00:00
|
|
|
{
|
|
|
|
NSTextContainer *container;
|
|
|
|
|
|
|
|
container = RETAIN([textContainers objectAtIndex: i]);
|
|
|
|
[oldLayoutManager removeTextContainerAtIndex: i];
|
|
|
|
/* One of these calls will result in our _layoutManager being
|
|
|
|
changed. */
|
|
|
|
[aLayoutManager addTextContainer: container];
|
|
|
|
|
|
|
|
/* The textview is caching the layout manager; refresh the
|
|
|
|
* cache with this do-nothing call. */
|
|
|
|
/* TODO: probably unnecessary; the call in -setLayoutManager:
|
|
|
|
should be enough */
|
|
|
|
[[container textView] setTextContainer: container];
|
|
|
|
RELEASE(container);
|
|
|
|
}
|
2010-03-23 20:27:23 +00:00
|
|
|
RELEASE(textStorage);
|
2003-02-01 02:32:35 +00:00
|
|
|
RELEASE(oldLayoutManager);
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) setTextView: (NSTextView*)aTextView
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
2000-09-05 17:31:03 +00:00
|
|
|
NSNotificationCenter *nc;
|
2001-01-07 00:59:57 +00:00
|
|
|
|
2000-09-05 17:31:03 +00:00
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
2008-01-04 21:02:29 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
if (_textView)
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
|
|
|
[_textView setTextContainer: nil];
|
2001-01-07 00:59:57 +00:00
|
|
|
[nc removeObserver: self name: NSViewFrameDidChangeNotification
|
2008-01-04 21:02:29 +00:00
|
|
|
object: _textView];
|
2001-01-07 00:59:57 +00:00
|
|
|
/* NB: We do not set posts frame change notifications for the
|
2008-01-04 21:02:29 +00:00
|
|
|
text view to NO because there could be other observers for
|
|
|
|
the frame change notifications. */
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
2003-04-28 16:37:56 +00:00
|
|
|
ASSIGN(_textView, aTextView);
|
1999-06-17 15:08:05 +00:00
|
|
|
|
2000-09-05 17:31:03 +00:00
|
|
|
if (aTextView != nil)
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
|
|
|
[_textView setTextContainer: self];
|
2000-09-05 17:31:03 +00:00
|
|
|
if (_observingFrameChanges)
|
2008-01-04 21:02:29 +00:00
|
|
|
{
|
|
|
|
[_textView setPostsFrameChangedNotifications: YES];
|
|
|
|
[nc addObserver: self
|
|
|
|
selector: @selector(_textViewFrameChanged:)
|
|
|
|
name: NSViewFrameDidChangeNotification
|
|
|
|
object: _textView];
|
2010-02-15 17:04:17 +00:00
|
|
|
[self _textViewFrameChanged:
|
|
|
|
[NSNotification notificationWithName: NSViewFrameDidChangeNotification
|
|
|
|
object: _textView]];
|
2008-01-04 21:02:29 +00:00
|
|
|
}
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
2001-01-07 00:59:57 +00:00
|
|
|
|
2003-01-26 19:21:40 +00:00
|
|
|
/* If someone's trying to set a NSTextView for us, the layout manager we
|
|
|
|
have must be capable of handling NSTextView:s. */
|
|
|
|
[(NSLayoutManager *)_layoutManager textContainerChangedTextView: self];
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
- (NSTextView*) textView
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
|
|
|
return _textView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setContainerSize: (NSSize)aSize
|
|
|
|
{
|
2003-04-28 16:37:56 +00:00
|
|
|
if (NSEqualSizes(_containerRect.size, aSize))
|
2001-01-07 00:59:57 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2000-10-23 23:27:00 +00:00
|
|
|
|
2009-02-03 15:56:51 +00:00
|
|
|
if (aSize.width < 0)
|
|
|
|
{
|
2021-10-27 19:18:23 +00:00
|
|
|
NSWarnMLog(@"given negative width: %f current: %f", aSize.width, _containerRect.size.width);
|
2009-02-03 15:56:51 +00:00
|
|
|
aSize.width = 0;
|
|
|
|
}
|
|
|
|
if (aSize.height < 0)
|
|
|
|
{
|
2021-10-27 19:18:23 +00:00
|
|
|
NSWarnMLog(@"given negative height: %f current: %f", aSize.height, _containerRect.size.height);
|
2009-02-03 15:56:51 +00:00
|
|
|
aSize.height = 0;
|
|
|
|
}
|
|
|
|
|
2003-04-28 16:37:56 +00:00
|
|
|
_containerRect = NSMakeRect(0, 0, aSize.width, aSize.height);
|
1999-06-17 15:08:05 +00:00
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
if (_layoutManager)
|
2001-01-07 00:59:57 +00:00
|
|
|
{
|
|
|
|
[_layoutManager textContainerChangedGeometry: self];
|
|
|
|
}
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize) containerSize
|
|
|
|
{
|
|
|
|
return _containerRect.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWidthTracksTextView: (BOOL)flag
|
|
|
|
{
|
2000-09-05 17:31:03 +00:00
|
|
|
NSNotificationCenter *nc;
|
2000-11-05 16:30:06 +00:00
|
|
|
BOOL old_observing = _observingFrameChanges;
|
2000-09-05 17:31:03 +00:00
|
|
|
|
1999-06-17 15:08:05 +00:00
|
|
|
_widthTracksTextView = flag;
|
|
|
|
_observingFrameChanges = _widthTracksTextView | _heightTracksTextView;
|
2000-11-05 16:30:06 +00:00
|
|
|
|
2000-09-30 23:14:12 +00:00
|
|
|
if (_textView == nil)
|
|
|
|
return;
|
|
|
|
|
2000-11-05 16:30:06 +00:00
|
|
|
if (_observingFrameChanges == old_observing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
2000-09-05 17:31:03 +00:00
|
|
|
if (_observingFrameChanges)
|
|
|
|
{
|
2000-11-05 16:30:06 +00:00
|
|
|
[_textView setPostsFrameChangedNotifications: YES];
|
2000-09-05 17:31:03 +00:00
|
|
|
[nc addObserver: self
|
2008-01-04 21:02:29 +00:00
|
|
|
selector: @selector(_textViewFrameChanged:)
|
|
|
|
name: NSViewFrameDidChangeNotification
|
|
|
|
object: _textView];
|
2000-09-05 17:31:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[nc removeObserver: self name: NSViewFrameDidChangeNotification
|
2008-01-04 21:02:29 +00:00
|
|
|
object: _textView];
|
2000-09-05 17:31:03 +00:00
|
|
|
}
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) widthTracksTextView
|
|
|
|
{
|
|
|
|
return _widthTracksTextView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setHeightTracksTextView: (BOOL)flag
|
|
|
|
{
|
2000-09-05 17:31:03 +00:00
|
|
|
NSNotificationCenter *nc;
|
2000-11-05 16:30:06 +00:00
|
|
|
BOOL old_observing = _observingFrameChanges;
|
2000-09-05 17:31:03 +00:00
|
|
|
|
1999-06-17 15:08:05 +00:00
|
|
|
_heightTracksTextView = flag;
|
|
|
|
_observingFrameChanges = _widthTracksTextView | _heightTracksTextView;
|
2000-09-30 23:14:12 +00:00
|
|
|
if (_textView == nil)
|
|
|
|
return;
|
|
|
|
|
2000-11-05 16:30:06 +00:00
|
|
|
if (_observingFrameChanges == old_observing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
|
|
|
|
2000-09-05 17:31:03 +00:00
|
|
|
if (_observingFrameChanges)
|
|
|
|
{
|
2000-11-05 16:30:06 +00:00
|
|
|
[_textView setPostsFrameChangedNotifications: YES];
|
2000-09-05 17:31:03 +00:00
|
|
|
[nc addObserver: self
|
2008-01-04 21:02:29 +00:00
|
|
|
selector: @selector(_textViewFrameChanged:)
|
|
|
|
name: NSViewFrameDidChangeNotification
|
|
|
|
object: _textView];
|
2000-09-05 17:31:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[nc removeObserver: self name: NSViewFrameDidChangeNotification
|
2008-01-04 21:02:29 +00:00
|
|
|
object: _textView];
|
2000-09-05 17:31:03 +00:00
|
|
|
}
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) heightTracksTextView
|
|
|
|
{
|
|
|
|
return _heightTracksTextView;
|
|
|
|
}
|
|
|
|
|
2013-02-17 22:44:47 +00:00
|
|
|
- (void) setLineFragmentPadding: (CGFloat)aFloat
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
|
|
|
_lineFragmentPadding = aFloat;
|
|
|
|
|
2000-02-19 00:40:47 +00:00
|
|
|
if (_layoutManager)
|
1999-06-17 15:08:05 +00:00
|
|
|
[_layoutManager textContainerChangedGeometry: self];
|
|
|
|
}
|
|
|
|
|
2013-02-17 22:44:47 +00:00
|
|
|
- (CGFloat) lineFragmentPadding
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
|
|
|
return _lineFragmentPadding;
|
|
|
|
}
|
|
|
|
|
2003-07-22 16:13:46 +00:00
|
|
|
- (NSRect) lineFragmentRectForProposedRect: (NSRect)proposedRect
|
2008-01-04 21:02:29 +00:00
|
|
|
sweepDirection: (NSLineSweepDirection)sweepDir
|
|
|
|
movementDirection: (NSLineMovementDirection)moveDir
|
|
|
|
remainingRect: (NSRect *)remainingRect
|
1999-06-17 15:08:05 +00:00
|
|
|
{
|
2013-02-17 22:44:47 +00:00
|
|
|
CGFloat minx, maxx, miny, maxy;
|
|
|
|
CGFloat cminx, cmaxx, cminy, cmaxy;
|
2003-01-26 19:21:40 +00:00
|
|
|
|
2003-07-22 16:13:46 +00:00
|
|
|
minx = NSMinX(proposedRect);
|
|
|
|
maxx = NSMaxX(proposedRect);
|
|
|
|
miny = NSMinY(proposedRect);
|
|
|
|
maxy = NSMaxY(proposedRect);
|
2003-01-26 19:21:40 +00:00
|
|
|
|
2011-11-28 02:37:58 +00:00
|
|
|
cminx = NSMinX(_containerRect) + _lineFragmentPadding;
|
|
|
|
cmaxx = NSMaxX(_containerRect) - _lineFragmentPadding;
|
2003-01-26 19:21:40 +00:00
|
|
|
cminy = NSMinY(_containerRect);
|
|
|
|
cmaxy = NSMaxY(_containerRect);
|
|
|
|
|
2003-07-22 16:13:46 +00:00
|
|
|
*remainingRect = NSZeroRect;
|
2003-01-26 19:21:40 +00:00
|
|
|
|
2003-07-22 16:13:46 +00:00
|
|
|
if (minx >= cminx && maxx <= cmaxx && miny >= cminy && maxy <= cmaxy)
|
2003-01-26 19:21:40 +00:00
|
|
|
{
|
2003-07-22 16:13:46 +00:00
|
|
|
return proposedRect;
|
2003-01-26 19:21:40 +00:00
|
|
|
}
|
|
|
|
|
2003-07-22 16:13:46 +00:00
|
|
|
switch (moveDir)
|
2003-01-26 19:21:40 +00:00
|
|
|
{
|
2013-01-19 18:22:45 +00:00
|
|
|
case NSLineMovesLeft:
|
2008-01-04 21:02:29 +00:00
|
|
|
if (maxx < cminx)
|
|
|
|
return NSZeroRect;
|
|
|
|
if (maxx > cmaxx)
|
|
|
|
{
|
|
|
|
minx -= maxx-cmaxx;
|
|
|
|
maxx = cmaxx;
|
|
|
|
}
|
|
|
|
break;
|
2003-01-26 19:21:40 +00:00
|
|
|
|
2013-01-19 18:22:45 +00:00
|
|
|
case NSLineMovesRight:
|
2008-01-04 21:02:29 +00:00
|
|
|
if (minx > cmaxx)
|
|
|
|
return NSZeroRect;
|
|
|
|
if (minx < cminx)
|
|
|
|
{
|
|
|
|
maxx += cminx-minx;
|
|
|
|
minx = cminx;
|
|
|
|
}
|
|
|
|
break;
|
2003-01-26 19:21:40 +00:00
|
|
|
|
2013-01-19 18:22:45 +00:00
|
|
|
case NSLineMovesDown:
|
2008-01-04 21:02:29 +00:00
|
|
|
if (miny > cmaxy)
|
|
|
|
return NSZeroRect;
|
|
|
|
if (miny < cminy)
|
|
|
|
{
|
|
|
|
maxy += cminy - miny;
|
|
|
|
miny = cminy;
|
|
|
|
}
|
|
|
|
break;
|
2003-01-26 19:21:40 +00:00
|
|
|
|
2013-01-19 18:22:45 +00:00
|
|
|
case NSLineMovesUp:
|
2008-01-04 21:02:29 +00:00
|
|
|
if (maxy < cminy)
|
|
|
|
return NSZeroRect;
|
|
|
|
if (maxy > cmaxy)
|
|
|
|
{
|
|
|
|
miny -= maxy - cmaxy;
|
|
|
|
maxy = cmaxy;
|
|
|
|
}
|
|
|
|
break;
|
2003-01-26 19:21:40 +00:00
|
|
|
|
|
|
|
case NSLineDoesntMove:
|
2008-01-04 21:02:29 +00:00
|
|
|
break;
|
2003-01-26 19:21:40 +00:00
|
|
|
}
|
|
|
|
|
2003-07-22 16:13:46 +00:00
|
|
|
switch (sweepDir)
|
2003-01-26 19:21:40 +00:00
|
|
|
{
|
|
|
|
case NSLineSweepLeft:
|
|
|
|
case NSLineSweepRight:
|
2008-01-04 21:02:29 +00:00
|
|
|
if (minx < cminx)
|
|
|
|
minx = cminx;
|
|
|
|
if (maxx > cmaxx)
|
|
|
|
maxx = cmaxx;
|
|
|
|
break;
|
2003-01-26 19:21:40 +00:00
|
|
|
|
|
|
|
case NSLineSweepDown:
|
|
|
|
case NSLineSweepUp:
|
2008-01-04 21:02:29 +00:00
|
|
|
if (miny < cminy)
|
|
|
|
miny = cminy;
|
|
|
|
if (maxy > cmaxy)
|
|
|
|
maxy = cmaxy;
|
|
|
|
break;
|
2003-01-26 19:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minx < cminx || maxx > cmaxx ||
|
|
|
|
miny < cminy || maxy > cmaxy)
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
2013-01-27 14:51:26 +00:00
|
|
|
return NSMakeRect(minx, miny,
|
|
|
|
(maxx > minx) ? maxx - minx : 0.0,
|
|
|
|
(maxy > miny) ? maxy - miny : 0.0);
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSimpleRectangularTextContainer
|
|
|
|
{
|
|
|
|
// sub-classes may say no; this class always says yes
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) containsPoint: (NSPoint)aPoint
|
|
|
|
{
|
2003-04-28 16:37:56 +00:00
|
|
|
return NSPointInRect(aPoint, _containerRect);
|
1999-06-17 15:08:05 +00:00
|
|
|
}
|
|
|
|
|
2004-02-15 18:23:13 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
|
|
|
{
|
|
|
|
if ([aDecoder allowsKeyedCoding])
|
|
|
|
{
|
2010-05-30 20:57:01 +00:00
|
|
|
NSSize size = NSMakeSize(1e7, 1e7);
|
2006-05-20 22:12:46 +00:00
|
|
|
|
2004-02-15 18:23:13 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSWidth"])
|
|
|
|
{
|
2008-01-04 21:02:29 +00:00
|
|
|
size.width = [aDecoder decodeFloatForKey: @"NSWidth"];
|
|
|
|
}
|
2004-02-15 18:23:13 +00:00
|
|
|
self = [self initWithContainerSize: size];
|
|
|
|
if ([aDecoder containsValueForKey: @"NSTCFlags"])
|
|
|
|
{
|
2008-01-04 21:02:29 +00:00
|
|
|
int flags = [aDecoder decodeIntForKey: @"NSTCFlags"];
|
|
|
|
|
|
|
|
// decode the flags.
|
2010-05-30 20:57:01 +00:00
|
|
|
_widthTracksTextView = (flags & 1) != 0;
|
|
|
|
_heightTracksTextView = (flags & 2) != 0;
|
|
|
|
// Mac OS X doesn't seem to save this flag
|
|
|
|
_observingFrameChanges = _widthTracksTextView | _heightTracksTextView;
|
2008-01-04 21:02:29 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
|
|
|
|
// decoding the manager adds this text container automatically...
|
2009-05-23 15:50:51 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSLayoutManager"])
|
|
|
|
{
|
|
|
|
_layoutManager = [aDecoder decodeObjectForKey: @"NSLayoutManager"];
|
|
|
|
}
|
|
|
|
|
2004-02-15 18:23:13 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-06 04:32:16 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([coder allowsKeyedCoding])
|
2006-08-06 04:32:16 +00:00
|
|
|
{
|
|
|
|
NSSize size = _containerRect.size;
|
|
|
|
int flags = ((_widthTracksTextView)?1:0) |
|
2008-01-04 21:02:29 +00:00
|
|
|
((_heightTracksTextView)?2:0) |
|
|
|
|
((_observingFrameChanges)?4:0);
|
2006-08-06 04:32:16 +00:00
|
|
|
|
|
|
|
[coder encodeObject: _textView forKey: @"NSTextView"];
|
2010-05-30 20:57:01 +00:00
|
|
|
[coder encodeObject: _layoutManager forKey: @"NSLayoutManager"];
|
2006-08-06 04:32:16 +00:00
|
|
|
[coder encodeFloat: size.width forKey: @"NSWidth"];
|
|
|
|
[coder encodeInt: flags forKey: @"NSTCFlags"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-17 15:08:05 +00:00
|
|
|
@end /* NSTextContainer */
|
|
|
|
|