1999-07-18 03:53:42 +00:00
|
|
|
/*
|
|
|
|
NSPopUpButtonCell.m
|
|
|
|
|
|
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Michael Hanni <mhanni@sprintmail.com>
|
|
|
|
Date: 1999
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
1999-06-19 00:31:39 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
1999-06-21 01:53:43 +00:00
|
|
|
#include <AppKit/NSColor.h>
|
|
|
|
#include <AppKit/NSFont.h>
|
1999-06-30 03:10:38 +00:00
|
|
|
#include <AppKit/NSGraphics.h>
|
1999-06-21 01:53:43 +00:00
|
|
|
#include <AppKit/NSImage.h>
|
1999-06-20 10:13:34 +00:00
|
|
|
#include <AppKit/NSMatrix.h>
|
1999-06-21 01:53:43 +00:00
|
|
|
#include <AppKit/NSPopUpButton.h>
|
1999-06-19 00:31:39 +00:00
|
|
|
#include <AppKit/NSPopUpButtonCell.h>
|
1999-06-21 01:53:43 +00:00
|
|
|
#include <AppKit/PSOperators.h>
|
1999-06-19 00:31:39 +00:00
|
|
|
|
|
|
|
@implementation NSPopUpButtonCell
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSPopUpButtonCell class])
|
|
|
|
[self setVersion: 1];
|
|
|
|
}
|
1999-06-21 01:53:43 +00:00
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
return [super init];
|
|
|
|
}
|
1999-07-18 03:53:42 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (id)representedObject
|
|
|
|
{
|
|
|
|
if (cell_image)
|
|
|
|
{
|
|
|
|
return cell_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
return contents;
|
|
|
|
}
|
|
|
|
|
1999-08-31 09:19:39 +00:00
|
|
|
- (void) drawWithFrame: (NSRect)cellFrame
|
|
|
|
inView: (NSView*)view
|
1999-06-21 01:53:43 +00:00
|
|
|
{
|
1999-09-21 05:10:54 +00:00
|
|
|
NSGraphicsContext *ctxt;
|
1999-09-11 10:08:56 +00:00
|
|
|
NSColor *backColor;
|
|
|
|
NSImage *toDraw = nil;
|
1999-06-21 01:53:43 +00:00
|
|
|
NSRect rect = cellFrame;
|
|
|
|
NSRect arect = cellFrame;
|
|
|
|
NSPoint point;
|
|
|
|
|
1999-09-21 05:10:54 +00:00
|
|
|
[view lockFocus];
|
|
|
|
ctxt = GSCurrentContext();
|
1999-06-21 01:53:43 +00:00
|
|
|
NSDrawButton(cellFrame, cellFrame);
|
|
|
|
|
1999-06-30 03:10:38 +00:00
|
|
|
arect.size.width -= 3;
|
|
|
|
arect.size.height -= 3;
|
|
|
|
arect.origin.x += 1;
|
1999-06-21 01:53:43 +00:00
|
|
|
arect.origin.y += 2;
|
|
|
|
|
1999-08-31 09:19:39 +00:00
|
|
|
if (cell_highlighted)
|
|
|
|
{
|
1999-09-11 10:08:56 +00:00
|
|
|
backColor = [NSColor selectedMenuItemColor];
|
1999-08-31 09:19:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-09-11 10:08:56 +00:00
|
|
|
backColor = [NSColor controlColor];
|
1999-08-31 09:19:39 +00:00
|
|
|
}
|
1999-09-11 10:08:56 +00:00
|
|
|
[backColor set];
|
1999-08-31 09:19:39 +00:00
|
|
|
NSRectFill(arect);
|
1999-06-21 01:53:43 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
if (cell_image)
|
|
|
|
{
|
1999-09-11 10:08:56 +00:00
|
|
|
NSSize size;
|
|
|
|
NSPoint position;
|
|
|
|
|
|
|
|
[cell_image setBackgroundColor: backColor];
|
|
|
|
size = [cell_image size];
|
|
|
|
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
|
|
|
|
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
|
|
|
|
/*
|
|
|
|
* Images are always drawn with their bottom-left corner at the origin
|
|
|
|
* so we must adjust the position to take account of a flipped view.
|
|
|
|
*/
|
|
|
|
if ([control_view isFlipped])
|
|
|
|
position.y += size.height;
|
|
|
|
[cell_image compositeToPoint: position operation: NSCompositeCopy];
|
1999-07-30 22:10:02 +00:00
|
|
|
|
1999-07-31 00:44:25 +00:00
|
|
|
rect.size.width = 5; // calc image rect
|
|
|
|
rect.size.height = 11;
|
|
|
|
rect.origin.x = cellFrame.origin.x + cellFrame.size.width - 8;
|
|
|
|
rect.origin.y = cellFrame.origin.y + 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[cell_font set];
|
1999-06-21 01:53:43 +00:00
|
|
|
|
1999-07-31 00:44:25 +00:00
|
|
|
point.y = rect.origin.y + (rect.size.height/2) - 4;
|
|
|
|
point.x = rect.origin.x + xDist;
|
|
|
|
rect.origin = point;
|
1999-06-21 01:53:43 +00:00
|
|
|
|
1999-08-31 09:19:39 +00:00
|
|
|
if (cell_highlighted)
|
|
|
|
{
|
|
|
|
[[NSColor selectedMenuItemTextColor] set];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[NSColor controlTextColor] set];
|
|
|
|
}
|
1999-06-21 01:53:43 +00:00
|
|
|
|
1999-07-31 00:44:25 +00:00
|
|
|
// Draw the title.
|
1999-06-21 01:53:43 +00:00
|
|
|
|
1999-07-31 00:44:25 +00:00
|
|
|
DPSmoveto(ctxt, rect.origin.x, rect.origin.y);
|
|
|
|
DPSshow(ctxt, [contents cString]);
|
1999-06-21 01:53:43 +00:00
|
|
|
|
1999-07-31 00:44:25 +00:00
|
|
|
rect.size.width = 15; // calc image rect
|
|
|
|
rect.size.height = cellFrame.size.height;
|
|
|
|
rect.origin.x = cellFrame.origin.x + cellFrame.size.width - (6 + 11);
|
|
|
|
rect.origin.y = cellFrame.origin.y;
|
|
|
|
}
|
1999-07-18 03:53:42 +00:00
|
|
|
|
|
|
|
if ([view isKindOfClass:[NSMenuView class]])
|
|
|
|
{
|
1999-07-30 22:10:02 +00:00
|
|
|
NSPopUpButton *popb = [[(NSMenuView *)view menu] popupButton];
|
1999-07-18 03:53:42 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
if ([[[popb selectedItem] representedObject] isEqual: contents])
|
1999-07-18 03:53:42 +00:00
|
|
|
{
|
|
|
|
if ([popb pullsDown] == NO)
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_Nibble"];
|
1999-07-18 03:53:42 +00:00
|
|
|
else
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_3DArrowDown"];
|
1999-07-18 03:53:42 +00:00
|
|
|
}
|
1999-07-31 00:44:25 +00:00
|
|
|
else if ([[[popb selectedItem] representedObject] isEqual: cell_image])
|
|
|
|
{
|
|
|
|
if ([popb pullsDown] == NO)
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_UpAndDownArrowSmall.tiff"];
|
1999-07-31 00:44:25 +00:00
|
|
|
else
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_DownArrowSmall"];
|
1999-07-31 00:44:25 +00:00
|
|
|
}
|
1999-07-18 03:53:42 +00:00
|
|
|
}
|
|
|
|
else if ([view isKindOfClass:[NSPopUpButton class]])
|
|
|
|
{
|
1999-07-30 22:10:02 +00:00
|
|
|
if ([[[(NSPopUpButton *)view selectedItem] representedObject]
|
|
|
|
isEqual: contents])
|
1999-07-18 03:53:42 +00:00
|
|
|
{
|
|
|
|
if ([(NSPopUpButton *)view pullsDown] == NO)
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_Nibble"];
|
1999-07-18 03:53:42 +00:00
|
|
|
else
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_3DArrowDown"];
|
1999-07-18 03:53:42 +00:00
|
|
|
}
|
1999-07-31 00:44:25 +00:00
|
|
|
else if ([[[(NSPopUpButton *)view selectedItem] representedObject] isEqual: cell_image])
|
|
|
|
{
|
|
|
|
if ([(NSPopUpButton *)view pullsDown] == NO)
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_UpAndDownArrowSmall"];
|
1999-07-31 00:44:25 +00:00
|
|
|
else
|
1999-09-11 10:08:56 +00:00
|
|
|
toDraw = [NSImage imageNamed:@"common_DownArrowSmall"];
|
1999-07-31 00:44:25 +00:00
|
|
|
}
|
1999-07-18 03:53:42 +00:00
|
|
|
}
|
1999-09-11 10:08:56 +00:00
|
|
|
if (toDraw != nil)
|
|
|
|
{
|
|
|
|
NSSize size;
|
|
|
|
NSPoint position;
|
|
|
|
|
|
|
|
[toDraw setBackgroundColor: backColor];
|
|
|
|
size = [toDraw size];
|
|
|
|
position.x = MAX(NSMidX(rect) - (size.width/2.),0.);
|
|
|
|
position.y = MAX(NSMidY(rect) - (size.height/2.),0.);
|
|
|
|
/*
|
|
|
|
* Images are always drawn with their bottom-left corner at the origin
|
|
|
|
* so we must adjust the position to take account of a flipped view.
|
|
|
|
*/
|
|
|
|
if ([control_view isFlipped])
|
|
|
|
position.y += size.height;
|
|
|
|
[toDraw compositeToPoint: position operation: NSCompositeCopy];
|
|
|
|
}
|
1999-09-21 05:10:54 +00:00
|
|
|
[view unlockFocus];
|
1999-06-21 01:53:43 +00:00
|
|
|
}
|
1999-06-19 00:31:39 +00:00
|
|
|
@end
|