NsText NSTab*

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4458 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Michael Silva 1999-06-23 23:27:16 +00:00
parent acf7614115
commit c3dfecdff7
5 changed files with 102 additions and 41 deletions

View file

@ -1,3 +1,12 @@
1999-06-23 Michael Hanni <mhanni@sprintmail.com>
* Source/NSText.m: tweaked - sizeToFit and now scrollbars are
correctly positioned. Furthermore down arrow will move you down
through text in Edit.app (up arrow does too, but the algo doesn't
work for it so its dead.)
* Source/NSTabViewItem.m: remove top line drawing.
* Source/NSTabView.m: add top line drawing.
1999-06-22 Michael Hanni <mhanni@sprintmail.com>
* Source/NSText.m: new file from Daniel. Modifications to allow it

View file

@ -115,6 +115,7 @@ typedef enum _NSSelectionAffinity
NSCharacterSet *selectionWordGranularitySet,*selectionParagraphGranularitySet;
BOOL displayDisabled;
float currentCursorX; // column-stable cursor up/down
float currentCursorY; // column-stable cursor up/down
}

View file

@ -205,7 +205,8 @@
NSTabViewItem *anItem = [tab_items objectAtIndex:i];
NSTabState itemState;
if (i == 2) [anItem _setTabState:NSSelectedTab];
// hack to simulate a selected tab other than tab one.
if (i == 1) [anItem _setTabState:NSSelectedTab];
itemState = [anItem tabState];
@ -229,7 +230,13 @@
r.origin.x = rect.origin.x + 13;
r.origin.y = rect.size.height;
r.size.width = s.width;
r.size.height = 20;
r.size.height = 15;
DPSsetlinewidth(ctxt,1);
DPSsetgray(ctxt,1);
DPSmoveto(ctxt, r.origin.x, r.origin.y+16);
DPSrlineto(ctxt, r.size.width, 0);
DPSstroke(ctxt);
[anItem drawLabel:NO inRect:r];
@ -261,7 +268,13 @@
r.origin.x = iP.x + 13;
r.origin.y = rect.size.height;
r.size.width = s.width;
r.size.height = 20;
r.size.height = 15;
DPSsetlinewidth(ctxt,1);
DPSsetgray(ctxt,1);
DPSmoveto(ctxt, r.origin.x, r.origin.y+16);
DPSrlineto(ctxt, r.size.width, 0);
DPSstroke(ctxt);
[anItem drawLabel:NO inRect:r];

View file

@ -126,13 +126,8 @@
DPSgsave(ctxt);
DPSsetlinewidth(ctxt, 1);
DPSsetgray(ctxt, 1);
fRect = tabRect;
fRect.size.height -= 5;
if (item_state == NSSelectedTab) {
fRect.origin.y -= 1;
fRect.size.height += 1;
@ -142,14 +137,10 @@
[[NSColor lightGrayColor] set];
NSRectFill(fRect);
} else {
[[NSColor lightGrayColor] set];
NSRectFill(fRect);
}
DPSsetgray(ctxt, 1);
DPSmoveto(ctxt, tabRect.origin.x, tabRect.origin.y+16);
DPSrlineto(ctxt, tabRect.size.width, 0);
DPSstroke(ctxt);
lRect = tabRect;
lRect.origin.y += 3;
[[item_tabview font] set];

View file

@ -53,6 +53,7 @@
#include <AppKit/NSColor.h>
#include <AppKit/NSPasteboard.h>
#include <AppKit/NSSpellChecker.h>
#include <AppKit/NSClipView.h>
#include <AppKit/NSDragging.h>
#include <AppKit/NSStringDrawing.h>
@ -985,31 +986,59 @@ NSLog(@"did set font");
-(void) sizeToFit
{
/*
NSRect sizeToRect=[self frame];
if([self isHorizontallyResizable])
{ if([lineLayoutInformation count])
{ sizeToRect=[self boundingRectForLineRange:NSMakeRange(0,[lineLayoutInformation count])];
} else sizeToRect.size=minSize;
} else if([self isVerticallyResizable])
{ if([lineLayoutInformation count])
{ NSRect rect=NSUnionRect([[lineLayoutInformation objectAtIndex:0] lineRect],
[[lineLayoutInformation lastObject] lineRect]);
float newHeight=rect.size.height;
NSRect sizeToRect=[self frame];
if([[lineLayoutInformation lastObject] type] == LineLayoutInfoType_Paragraph && NSMaxY(rect)<= newHeight)
newHeight+=[[lineLayoutInformation lastObject] lineRect].size.height; // cursor in last line (virtual)
NSLog(@"- sizeToFit called.\n");
newHeight=MIN(maxSize.height,MAX(newHeight,minSize.height));
sizeToRect=NSMakeRect(sizeToRect.origin.x,sizeToRect.origin.y-(newHeight-sizeToRect.size.height),
sizeToRect.size.width,newHeight);
} else sizeToRect=NSMakeRect(0,0,minSize.width,minSize.height);
}
if(!NSEqualSizes([self frame].size,sizeToRect.size))
{ [self setFrame:sizeToRect]; //[self setFrameSize:sizeToRect.size];
}
*/
if ([self isFieldEditor]) // if we are a field editor we don't have to handle the size.
return;
if([self isHorizontallyResizable]) {
if([lineLayoutInformation count]) {
sizeToRect=[self boundingRectForLineRange:NSMakeRange(0,[lineLayoutInformation count])];
}
else
sizeToRect.size=minSize;
}
else if([self isVerticallyResizable]) {
if([lineLayoutInformation count]) {
NSRect rect=NSUnionRect([[lineLayoutInformation objectAtIndex:0]
lineRect],
[[lineLayoutInformation lastObject] lineRect]);
float newHeight=rect.size.height;
float newY;
NSRect tRect;
if([[lineLayoutInformation lastObject] type] == LineLayoutInfoType_Paragraph && NSMaxY(rect)<= newHeight)
newHeight+=[[lineLayoutInformation lastObject] lineRect].size.height;
tRect = [(NSClipView*)[self superview] documentVisibleRect];
if (currentCursorY < tRect.size.height + tRect.origin.y -
[[lineLayoutInformation lastObject] lineRect].size.height)
newY = sizeToRect.origin.y;
else if (currentCursorY > tRect.size.height + tRect.origin.y -
[[lineLayoutInformation lastObject] lineRect].size.height) {
newY = currentCursorY - tRect.size.height +
([[lineLayoutInformation lastObject] lineRect].size.height * 2);
[[self superview] scrollToPoint:NSMakePoint(sizeToRect.origin.x,newY)];
}
else
NSLog(@"=========> Oops!\n");
newHeight=MIN(maxSize.height,MAX(newHeight,minSize.height));
sizeToRect=NSMakeRect(sizeToRect.origin.x,sizeToRect.origin.y,
sizeToRect.size.width,newHeight);
}
else
sizeToRect=NSMakeRect(0,0,minSize.width,minSize.height);
}
if(!NSEqualSizes([self frame].size,sizeToRect.size)) {
[self setFrame:sizeToRect]; //[self setFrameSize:sizeToRect.size];
}
}
-(void) sizeToFit:sender {[self sizeToFit];}
//
@ -1075,8 +1104,10 @@ NSLog(@"did set font");
//
-(void) scrollRangeToVisible:(NSRange)range
{ [self scrollRectToVisible:NSUnionRect([self rectForCharacterIndex:[self selectedRange].location],
[self rectForCharacterIndex:NSMaxRange([self selectedRange])])];
{
[self scrollRectToVisible:NSUnionRect([self
rectForCharacterIndex:[self selectedRange].location],
[self rectForCharacterIndex:NSMaxRange([self selectedRange])])];
}
//
@ -1134,21 +1165,31 @@ NSLog(@"did set font");
{ unsigned cursorIndex;
NSPoint cursorPoint;
if([self selectedRange].length) currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x;
if([self selectedRange].length) {
currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x;
currentCursorY=[self rectForCharacterIndex:[self selectedRange].location].origin.y;
}
cursorIndex=[self selectedRange].location;
cursorPoint=[self rectForCharacterIndex:cursorIndex].origin;
cursorIndex=[self characterIndexForPoint:NSMakePoint(currentCursorX+0.001,MAX(0,cursorPoint.y-0.001))];
[self setSelectedRange:[self selectionRangeForProposedRange:NSMakeRange(cursorIndex,0) granularity:NSSelectByCharacter]];
// FIXME: Terrible hack.
[self insertText:@""];
}
-(void) moveCursorDown:sender
{ unsigned cursorIndex;
NSRect cursorRect;
if([self selectedRange].length) currentCursorX=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].origin.x;
if([self selectedRange].length) {
currentCursorX=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].origin.x;
currentCursorY=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].origin.y;
}
cursorIndex=[self selectedRange].location;
cursorRect=[self rectForCharacterIndex:cursorIndex];
cursorIndex=[self characterIndexForPoint:NSMakePoint(currentCursorX+0.001,NSMaxY(cursorRect)+0.001)];
[self setSelectedRange:[self selectionRangeForProposedRange:NSMakeRange(cursorIndex,0) granularity:NSSelectByCharacter]];
// FIXME: Terrible hack.
[self insertText:@""];
}
-(void) moveCursorLeft:sender
{ [self setSelectedRange:[self selectionRangeForProposedRange:NSMakeRange([self selectedRange].location-1,0) granularity:NSSelectByCharacter]];
@ -1237,6 +1278,7 @@ NSLog(@"did set font");
else if(chosenRange.length == 0) [self drawInsertionPointAtIndex:chosenRange.location color:[NSColor blackColor] turnedOn:YES];
currentCursorX=[self rectForCharacterIndex:chosenRange.location].origin.x; // remember for column stable cursor up/down
currentCursorY=[self rectForCharacterIndex:chosenRange.location].origin.y; // remember for column stable cursor up/down
[self unlockFocus];
[[self window] flushWindow];
@ -1331,6 +1373,7 @@ NSLog(NSStringFromRange(redrawLineRange));
[self setSelectedRange:NSMakeRange([self selectedRange].location+[insertString length],0)]; // move cursor <!> [self selectionRangeForProposedRange:]
currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x; // remember x for row-stable cursor movements
currentCursorY=[self rectForCharacterIndex:[self selectedRange].location].origin.y; // remember x for row-stable cursor movements
redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect:[self visibleRect]]);
[self redisplayForLineRange:redrawLineRange];
@ -1376,6 +1419,7 @@ NSLog(NSStringFromRange(redrawLineRange));
[self setSelectedRange:NSMakeRange(deleteRange.location,0)]; // move cursor <!> [self selectionRangeForProposedRange:]
currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x; // remember x for row-stable cursor movements
currentCursorY=[self rectForCharacterIndex:[self selectedRange].location].origin.y; // remember x for row-stable cursor movements
redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect:[self visibleRect]]);
[self redisplayForLineRange:redrawLineRange];
@ -1421,6 +1465,7 @@ NSLog(NSStringFromRange(redrawLineRange));
case NSCarriageReturnKey: // return
if([self isFieldEditor]) //textShouldEndEditing delegation is handled in resignFirstResponder
{
NSLog(@"isFieldEditor return\n");
#if 0
// Movement codes for movement between fields; these codes are the intValue of the NSTextMovement key in NSTextDidEndEditing notifications
[NSNumber numberWithInt:NSIllegalTextMovement]
@ -1432,12 +1477,14 @@ NSLog(NSStringFromRange(redrawLineRange));
[NSNumber numberWithInt:NSUpTextMovement]
[NSNumber numberWithInt:NSDownTextMovement]
#endif
[[self window] makeFirstResponder:[self nextResponder]];
[self textDidEndEditing:[NSNotification notificationWithName:NSTextDidEndEditingNotification object:self
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:NSReturnTextMovement],@"NSTextMovement",nil]]];
} else
{ [self insertText:[[self class] newlineString]];
{
NSLog(@"\bCarriage return.\b\n");
[self insertText:[[self class] newlineString]];
return;
}
break;