Multiple commits from Michael, see ChangeLog.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16458 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Michael Silva 2003-04-13 23:45:39 +00:00
parent 4d791cb220
commit e9ccc289d5
7 changed files with 260 additions and 176 deletions

View file

@ -1,3 +1,28 @@
2003-04-13 Michael Hanni <michael@deviant-behavior.com>
Multiple outstanding commits.
* ColorPickers/GSWheelColorPicker.m:
(mouseDown:): Implemented new event loop that really speeds things
up on slow machines.
* Source/NSScroller.m:
(init): Decreased periodic delay for scroller buttons.
(trackKnob:): Implemented new event loop to improve speed. Added
code to "snap" back the scroller when you release the alternate
key in mid-scroll (modeled after OS 4.2 behavior.)
(trackScrollButtons:): Removed event loop as we weren't using it
anyways.
* Source/NSFontPanel.m:
(_trySelectSize:): Put size textfield update code here, make sure
column is loaded.
(_familySelectionChanged:): Call _trySelectSize: to update the
size column just like we do for the face browser.
* Source/NSProgressIndicator.m:
(drawRect:): Implement GSGtkInterfaceStyle for
NSProgressIndicatorInterfaceStyle.
* Source/NSInterfaceStyle.m: added GSGtkInterfaceStyle.
* Headers/NSInterfaceStyle.h: ditto.
2003-04-13 Michael Hanni <michael@deviant-behavior.com>
* Source/NSPopUpButton.m:

View file

@ -148,17 +148,14 @@
PSrectfill(x - 1, y - 1, 2, 2);
}
- (void) mouseDown: (NSEvent *)theEvent
{
NSApplication *app = [NSApplication sharedApplication];
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
| NSLeftMouseDraggedMask | NSMouseMovedMask
| NSPeriodicMask;
| NSLeftMouseDraggedMask;
NSPoint point = [self convertPoint: [theEvent locationInWindow]
fromView: nil];
NSEventType eventType = [theEvent type];
NSDate *distantFuture = [NSDate distantFuture];
NSEvent *presentEvent;
float new_hue, new_saturation;
float old_x, old_y;
@ -173,64 +170,79 @@
cr = frame.size.height;
cr = cr / 2 - 2;
[NSEvent startPeriodicEventsAfterDelay: 0.05 withPeriod: 0.05];
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
new_hue = hue;
new_saturation = saturation;
do
{
if (eventType != NSPeriodic)
{
point = [self convertPoint: [theEvent locationInWindow]
fromView: nil];
/* Inner loop that gets and (quickly) handles all events that have
already arrived. */
while (theEvent && eventType != NSLeftMouseUp)
{
/* Note the event here. Don't do any expensive handling. */
presentEvent = theEvent;
dx = point.x - cx;
dy = point.y - cy;
theEvent = [NSApp nextEventMatchingMask: eventMask
untilDate: [NSDate distantPast] /* Only get events that have arrived */
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
eventType = [theEvent type];
}
/* No more events right now. Do expensive handling, like drawing,
* here.
*/
point = [self convertPoint: [presentEvent locationInWindow]
fromView: nil];
new_saturation = dx * dx + dy * dy;
new_saturation = sqrt(new_saturation);
new_saturation /= cr;
if (new_saturation > 1)
new_saturation = 1;
dx = point.x - cx;
dy = point.y - cy;
new_hue = atan2(dy, dx);
new_hue = new_hue / 2.0 / PI;
if (new_hue < 0)
new_hue += 1;
}
else
{
if (new_hue != hue || new_saturation != saturation)
{
old_x = cos(hue * 2 * PI) * saturation * cr + cx;
old_y = sin(hue * 2 * PI) * saturation * cr + cy;
new_saturation = dx * dx + dy * dy;
new_saturation = sqrt(new_saturation);
new_saturation /= cr;
if (new_saturation > 1)
new_saturation = 1;
hue = new_hue;
saturation = new_saturation;
new_hue = atan2(dy, dx);
new_hue = new_hue / 2.0 / PI;
if (new_hue < 0)
new_hue += 1;
[self lockFocus];
[self drawRect: NSMakeRect(old_x - 3, old_y - 3, 6, 6)];
[self drawRect: NSMakeRect(point.x - 3, point.y - 3, 6, 6)];
[self unlockFocus];
[_window flushWindow];
if (new_hue != hue || new_saturation != saturation)
{
old_x = cos(hue * 2 * PI) * saturation * cr + cx;
old_y = sin(hue * 2 * PI) * saturation * cr + cy;
if (target)
[target performSelector: action withObject: self];
}
}
hue = new_hue;
saturation = new_saturation;
theEvent = [app nextEventMatchingMask: eventMask
untilDate: distantFuture
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
eventType = [theEvent type];
} while (eventType != NSLeftMouseUp);
[NSEvent stopPeriodicEvents];
[self lockFocus];
[self drawRect: NSMakeRect(old_x - 3, old_y - 3, 6, 6)];
[self drawRect: NSMakeRect(point.x - 3, point.y - 3, 6, 6)];
[self unlockFocus];
[_window flushWindow];
if (target)
[target performSelector: action withObject: self];
}
/*
* If our current event is actually the mouse up (perhaps the inner
* loop got to this point) we want to update with the last info and
* then quit.
*/
if (eventType == NSLeftMouseUp)
break;
/* Get the next event, blocking if necessary. */
theEvent = [NSApp nextEventMatchingMask: eventMask
untilDate: nil /* No limit, block until we get an event. */
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
eventType = [theEvent type];
} while (eventType != NSLeftMouseUp);
}
@end

View file

@ -44,8 +44,8 @@ typedef enum {
* GNUstep specific. Blame: Michael Hanni.
*/
GSWindowMakerInterfaceStyle = 4
GSWindowMakerInterfaceStyle = 4,
GSGtkInterfaceStyle = 5
} NSInterfaceStyle;
APPKIT_EXPORT NSString *NSInterfaceStyleDefault;

View file

@ -209,7 +209,6 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
NSString *family = [fontObject familyName];
NSString *fontName = [fontObject fontName];
float size = [fontObject pointSize];
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser];
NSBrowser *faceBrowser = [[self contentView] viewWithTag: NSFPFaceBrowser];
NSString *face = @"";
@ -249,7 +248,6 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
}
// show point size and select the row if there is one
_setFloatValue (sizeField, size);
[self _trySelectSize: size];
// Use in preview
@ -733,11 +731,20 @@ static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
{
int i;
NSBrowser *sizeBrowser = [[self contentView] viewWithTag: NSFPSizeBrowser];
NSTextField *sizeField;
/* Make sure our sizeField is updated. */
sizeField = [[self contentView] viewWithTag: NSFPSizeField];
_setFloatValue (sizeField, size);
/* Make sure our column is loaded. */
[sizeBrowser loadColumnZero];
for (i = 0; i < sizeof(sizes) / sizeof(float); i++)
{
if (size == sizes[i])
{
/* select the cell */
[sizeBrowser selectRow: i inColumn: 0];
break;
}
@ -840,6 +847,9 @@ static int score_difference(int weight1, int traits1,
[faceBrowser loadColumnZero];
[faceBrowser selectRow: i inColumn: 0];
/* Also make sure the size column is updated */
[self _trySelectSize: [[self _fontForSelection: _panelFont] pointSize]];
[self _doPreview];
}

View file

@ -48,6 +48,8 @@ styleFromString(NSString* str)
return NSMacintoshInterfaceStyle;
if ([str isEqualToString: @"NSWindows95InterfaceStyle"])
return NSWindows95InterfaceStyle;
if ([str isEqualToString: @"GSGtkInterfaceStyle"])
return GSGtkInterfaceStyle;
if ([str isEqualToString: @"GSWindowMakerInterfaceStyle"])
return GSWindowMakerInterfaceStyle;
return NSNoInterfaceStyle;

View file

@ -258,8 +258,31 @@ NSImage *images[maxCount];
r = NSIntersectionRect(r,rect);
if (!NSIsEmptyRect(r))
{
[fillColour set];
NSRectFill(r);
if (NSInterfaceStyleForKey(@"NSProgressIndicatorInterfaceStyle", nil)
== GSGtkInterfaceStyle)
{
NSRectEdge sides[] = {NSMaxXEdge, NSMinYEdge,
NSMinXEdge, NSMaxYEdge,
NSMaxXEdge, NSMinYEdge};
float grays[] = {NSBlack, NSBlack,
NSLightGray, NSLightGray,
NSDarkGray, NSDarkGray};
NSRect rect;
rect = NSDrawTiledRects(r, r,
sides, grays, 6);
/* This should perhaps be something else to ease in
* color themeing.
*/
[[NSColor scrollBarColor] set];
NSRectFill(rect);
}
else /* default case */
{
[fillColour set];
NSRectFill(r);
}
}
}
}

View file

@ -243,7 +243,7 @@ static NSColor *scrollBarColor = nil;
[upCell setImagePosition: NSImageOnly];
[upCell setContinuous: YES];
[upCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
[upCell setPeriodicDelay: 0.3 interval: 0.04];
[upCell setPeriodicDelay: 0.3 interval: 0.03];
downCell = [NSButtonCell new];
[downCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
@ -252,7 +252,7 @@ static NSColor *scrollBarColor = nil;
[downCell setImagePosition: NSImageOnly];
[downCell setContinuous: YES];
[downCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
[downCell setPeriodicDelay: 0.3 interval: 0.04];
[downCell setPeriodicDelay: 0.3 interval: 0.03];
leftCell = [NSButtonCell new];
[leftCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
@ -261,7 +261,7 @@ static NSColor *scrollBarColor = nil;
[leftCell setImagePosition: NSImageOnly];
[leftCell setContinuous: YES];
[leftCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
[leftCell setPeriodicDelay: 0.3 interval: 0.04];
[leftCell setPeriodicDelay: 0.3 interval: 0.03];
rightCell = [NSButtonCell new];
[rightCell setHighlightsBy: NSChangeBackgroundCellMask|NSContentsCellMask];
@ -270,7 +270,7 @@ static NSColor *scrollBarColor = nil;
[rightCell setImagePosition: NSImageOnly];
[rightCell setContinuous: YES];
[rightCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
[rightCell setPeriodicDelay: 0.3 interval: 0.04];
[rightCell setPeriodicDelay: 0.3 interval: 0.03];
knobCell = [NSButtonCell new];
[knobCell setButtonType: NSMomentaryChangeButton];
@ -583,23 +583,21 @@ static NSColor *scrollBarColor = nil;
- (void) trackKnob: (NSEvent*)theEvent
{
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
| NSLeftMouseDraggedMask | NSMouseMovedMask
| NSPeriodicMask;
| NSLeftMouseDraggedMask | NSFlagsChangedMask;
NSPoint point;
NSPoint apoint;
float lastPosition;
float newPosition;
float floatValue;
float offset;
NSDate *theDistantFuture = [NSDate distantFuture];
NSEventType eventType;
float initialOffset;
NSEvent *presentEvent;
NSEventType eventType = [theEvent type];
NSRect knobRect;
unsigned flags = [theEvent modifierFlags];
knobRect = [self rectForPart: NSScrollerKnob];
apoint = [theEvent locationInWindow];
point = [self convertPoint: apoint fromView: nil];
point = [self convertPoint: [theEvent locationInWindow] fromView: nil];
if (_isHorizontal)
{
lastPosition = NSMidX(knobRect);
@ -611,138 +609,152 @@ static NSColor *scrollBarColor = nil;
offset = lastPosition - point.y;
}
initialOffset = offset; /* Save the initial offset value */
_hitPart = NSScrollerKnob;
/*
* set periodic events rate to achieve max of ~30fps
*/
[NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.03];
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
while ((eventType = [theEvent type]) != NSLeftMouseUp)
do
{
CREATE_AUTORELEASE_POOL(arp);
if (eventType != NSPeriodic)
{
apoint = [theEvent locationInWindow];
flags = [theEvent modifierFlags];
}
else
{
point = [self convertPoint: apoint fromView: nil];
if (_isHorizontal)
newPosition = point.x + offset;
else
newPosition = point.y + offset;
/* Inner loop that gets and (quickly) handles all events that have
already arrived. */
while (theEvent && eventType != NSLeftMouseUp)
{
/* Note the event here. Don't do any expensive handling. */
if (eventType == NSFlagsChanged)
flags = [theEvent modifierFlags];
presentEvent = theEvent;
if (newPosition != lastPosition)
{
if (flags & NSAlternateKeyMask)
{
float diff;
theEvent = [NSApp nextEventMatchingMask: eventMask
untilDate: [NSDate distantPast] /* Only get events that have already arrived. */
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
eventType = [theEvent type];
}
diff = newPosition - lastPosition;
diff = diff * 3 / 4;
offset -= diff;
newPosition -= diff;
}
/*
* No more events right now. Do expensive handling, like drawing,
* here.
*/
point = [self convertPoint: [presentEvent locationInWindow]
fromView: nil];
// only one coordinate (X or Y) is used to compute floatValue.
point = NSMakePoint(newPosition, newPosition);
floatValue = [self _floatValueForMousePoint: point];
if (_isHorizontal)
newPosition = point.x + offset;
else
newPosition = point.y + offset;
if (floatValue != _floatValue)
{
[self setFloatValue: floatValue];
[self sendAction: _action to: _target];
}
if (newPosition != lastPosition)
{
if (flags & NSAlternateKeyMask)
{
float diff;
diff = newPosition - lastPosition;
diff = diff * 3 / 4;
offset -= diff;
newPosition -= diff;
}
else /* Ok, we are no longer doing slow scrolling, lets go back
to our original offset. */
{
offset = initialOffset;
}
// only one coordinate (X or Y) is used to compute floatValue.
point = NSMakePoint(newPosition, newPosition);
floatValue = [self _floatValueForMousePoint: point];
if (floatValue != _floatValue)
{
[self setFloatValue: floatValue];
[self sendAction: _action to: _target];
}
lastPosition = newPosition;
}
}
lastPosition = newPosition;
}
theEvent = [NSApp nextEventMatchingMask: eventMask
untilDate: theDistantFuture
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
DESTROY(arp);
}
[NSEvent stopPeriodicEvents];
/*
* If our current event is actually the mouse up (perhaps the inner
* loop got to this point) we want to update with the last info and
* then quit.
*/
if (eventType == NSLeftMouseUp)
break;
/* Get the next event, blocking if necessary. */
theEvent = [NSApp nextEventMatchingMask: eventMask
untilDate: nil /* No limit, block until we get an event. */
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
eventType = [theEvent type];
} while (eventType != NSLeftMouseUp);
}
- (void) trackScrollButtons: (NSEvent*)theEvent
{
NSApplication *theApp = [NSApplication sharedApplication];
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask |
NSLeftMouseDraggedMask | NSMouseMovedMask;
BOOL shouldReturn = NO;
id theCell = nil;
NSRect rect;
[self lockFocus];
NSDebugLog (@"trackScrollButtons");
do
_hitPart = [self testPart: [theEvent locationInWindow]];
rect = [self rectForPart: _hitPart];
/*
* A hit on a scroller button should be a page movement
* if the alt key is pressed.
*/
switch (_hitPart)
{
_hitPart = [self testPart: [theEvent locationInWindow]];
rect = [self rectForPart: _hitPart];
/*
* A hit on a scroller button should be a page movement
* if the alt key is pressed.
*/
switch (_hitPart)
{
case NSScrollerIncrementLine:
if ([theEvent modifierFlags] & NSAlternateKeyMask)
{
_hitPart = NSScrollerIncrementPage;
}
/* Fall through to next case */
case NSScrollerIncrementPage:
theCell = (_isHorizontal ? rightCell : downCell);
break;
case NSScrollerDecrementLine:
if ([theEvent modifierFlags] & NSAlternateKeyMask)
{
_hitPart = NSScrollerDecrementPage;
}
/* Fall through to next case */
case NSScrollerDecrementPage:
theCell = (_isHorizontal ? leftCell : upCell);
break;
default:
theCell = nil;
break;
}
if (theCell)
{
[theCell highlight: YES withFrame: rect inView: self];
[_window flushWindow];
NSDebugLog (@"tracking cell %x", theCell);
shouldReturn = [theCell trackMouse: theEvent
inRect: rect
ofView: self
untilMouseUp: YES];
[theCell highlight: NO withFrame: rect inView: self];
[_window flushWindow];
}
if (shouldReturn)
case NSScrollerIncrementLine:
if ([theEvent modifierFlags] & NSAlternateKeyMask)
{
_hitPart = NSScrollerIncrementPage;
}
/* Fall through to next case */
case NSScrollerIncrementPage:
theCell = (_isHorizontal ? rightCell : downCell);
break;
theEvent = [theApp nextEventMatchingMask: eventMask
untilDate: [NSDate distantFuture]
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
}
while ([theEvent type] != NSLeftMouseUp);
case NSScrollerDecrementLine:
if ([theEvent modifierFlags] & NSAlternateKeyMask)
{
_hitPart = NSScrollerDecrementPage;
}
/* Fall through to next case */
case NSScrollerDecrementPage:
theCell = (_isHorizontal ? leftCell : upCell);
break;
default:
theCell = nil;
break;
}
/*
* If we don't find a cell this has been all for naught, but we
* shouldn't ever be in that situation.
*/
if (theCell)
{
[theCell highlight: YES withFrame: rect inView: self];
[_window flushWindow];
NSDebugLog (@"tracking cell %x", theCell);
/*
* The "tracking" in this method actually takes place within
* NSCell's trackMouse: method.
*/
[theCell trackMouse: theEvent
inRect: rect
ofView: self
untilMouseUp: YES];
[theCell highlight: NO withFrame: rect inView: self];
[_window flushWindow];
}
[self unlockFocus];
NSDebugLog (@"return from trackScrollButtons");