mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 12:50:55 +00:00
Added theming methods for NSButtonCell
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/themes@22940 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a687acba6d
commit
ffba05566d
3 changed files with 105 additions and 49 deletions
|
@ -64,6 +64,11 @@
|
|||
inRect: (NSRect)border
|
||||
withClip: (NSRect)clip;
|
||||
|
||||
/* Themes */
|
||||
- (NSRect) drawButton: (NSRect) frame in: (NSButtonCell*) cell
|
||||
view: (NSView*) view style: (int) style state: (int) state;
|
||||
- (void) drawFocusFrame: (NSRect) frame view: (NSView*) view;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* _GNUstep_H_GSDrawFunctions */
|
||||
|
|
|
@ -392,4 +392,51 @@ static id theTheme = nil;
|
|||
return rect;
|
||||
}
|
||||
|
||||
/** theme drawing methos */
|
||||
|
||||
- (NSRect) drawButton: (NSRect) frame
|
||||
in: (NSButtonCell*) cell
|
||||
view: (NSView*) view
|
||||
style: (int) style
|
||||
state: (int) state
|
||||
{
|
||||
/* computes the interior frame rect */
|
||||
|
||||
NSRect interiorFrame = [cell drawingRectForBounds: frame];
|
||||
|
||||
/* Draw the button background */
|
||||
|
||||
if (state == 0) /* default state, unpressed */
|
||||
{
|
||||
//[[NSColor redColor] set];
|
||||
[[NSColor controlBackgroundColor] set];
|
||||
NSRectFill(frame);
|
||||
[GSDrawFunctions drawButton: frame : NSZeroRect];
|
||||
}
|
||||
else if (state == 1) /* highlighted state */
|
||||
{
|
||||
//[[NSColor blueColor] set];
|
||||
[[NSColor selectedControlColor] set];
|
||||
NSRectFill(frame);
|
||||
[GSDrawFunctions drawGrayBezel: frame : NSZeroRect];
|
||||
}
|
||||
else if (state == 2) /* pushed state */
|
||||
{
|
||||
//[[NSColor yellowColor] set];
|
||||
[[NSColor selectedControlColor] set];
|
||||
NSRectFill(frame);
|
||||
[GSDrawFunctions drawGrayBezel: frame : NSZeroRect];
|
||||
interiorFrame = NSOffsetRect(interiorFrame, 1.0, [view isFlipped] ? 1.0 : -1.0);
|
||||
}
|
||||
|
||||
/* returns the interior frame rect */
|
||||
|
||||
return interiorFrame;
|
||||
}
|
||||
|
||||
- (void) drawFocusFrame: (NSRect) frame view: (NSView*) view
|
||||
{
|
||||
NSDottedFrameRect(frame);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -788,6 +788,9 @@
|
|||
|
||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
{
|
||||
unsigned mask;
|
||||
int buttonState = 0;
|
||||
|
||||
// Save last view drawn to
|
||||
if (_control_view != controlView)
|
||||
_control_view = controlView;
|
||||
|
@ -800,22 +803,61 @@
|
|||
if (NSIsEmptyRect(cellFrame))
|
||||
return;
|
||||
|
||||
// set the mask
|
||||
if (_cell.is_highlighted)
|
||||
{
|
||||
mask = _highlightsByMask;
|
||||
|
||||
if (_cell.state)
|
||||
mask &= ~_showAltStateMask;
|
||||
}
|
||||
else if (_cell.state)
|
||||
mask = _showAltStateMask;
|
||||
else
|
||||
mask = NSNoCellMask;
|
||||
|
||||
/* Draw the cell's background color.
|
||||
We draw when there is a border or when highlightsByMask
|
||||
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
|
||||
as required by our nextstep-like look and feel. */
|
||||
if (_cell.is_bordered
|
||||
|| (_highlightsByMask & NSChangeBackgroundCellMask)
|
||||
|| (_highlightsByMask & NSChangeGrayCellMask))
|
||||
{
|
||||
/* Determine the background color. */
|
||||
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
||||
{
|
||||
buttonState = 1; /* highlighted state */
|
||||
}
|
||||
}
|
||||
|
||||
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
||||
if (_cell.is_bordered && (mask & NSPushInCellMask))
|
||||
{
|
||||
//cellFrame = NSOffsetRect(cellFrame, 1., flippedView ? 1. : -1.);
|
||||
buttonState = 2; // pushed button
|
||||
}
|
||||
|
||||
// draw the border if needed
|
||||
if ((_cell.is_bordered) &&
|
||||
(!_shows_border_only_while_mouse_inside || _mouse_inside))
|
||||
{
|
||||
// FIXME Should check the bezel and gradient style
|
||||
if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask))
|
||||
{
|
||||
[GSDrawFunctions drawGrayBezel: cellFrame : NSZeroRect];
|
||||
}
|
||||
else
|
||||
{
|
||||
[GSDrawFunctions drawButton: cellFrame : NSZeroRect];
|
||||
}
|
||||
cellFrame = [[GSDrawFunctions theme]
|
||||
drawButton: cellFrame in: self view: controlView
|
||||
style: _bezel_style
|
||||
state: buttonState];
|
||||
}
|
||||
|
||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
||||
|
||||
// Draw first responder
|
||||
if (_cell.shows_first_responder
|
||||
&& [[controlView window] firstResponder] == controlView)
|
||||
{
|
||||
//NSDottedFrameRect(cellFrame);
|
||||
[[GSDrawFunctions theme]
|
||||
drawFocusFrame: cellFrame view: controlView];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawGradientWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
|
||||
|
@ -936,8 +978,8 @@
|
|||
|
||||
_control_view = controlView;
|
||||
|
||||
cellFrame = [self drawingRectForBounds: cellFrame];
|
||||
|
||||
//TODO: we should be able to get rid of "mask"
|
||||
// set the mask
|
||||
if (_cell.is_highlighted)
|
||||
{
|
||||
mask = _highlightsByMask;
|
||||
|
@ -950,38 +992,6 @@
|
|||
else
|
||||
mask = NSNoCellMask;
|
||||
|
||||
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
||||
if (_cell.is_bordered && (mask & NSPushInCellMask))
|
||||
{
|
||||
cellFrame = NSOffsetRect(cellFrame, 1., flippedView ? 1. : -1.);
|
||||
}
|
||||
|
||||
/* Draw the cell's background color.
|
||||
We draw when there is a border or when highlightsByMask
|
||||
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
|
||||
as required by our nextstep-like look and feel. */
|
||||
if (_cell.is_bordered
|
||||
|| (_highlightsByMask & NSChangeBackgroundCellMask)
|
||||
|| (_highlightsByMask & NSChangeGrayCellMask))
|
||||
{
|
||||
/* Determine the background color. */
|
||||
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
||||
{
|
||||
backgroundColor = [NSColor selectedControlColor];
|
||||
}
|
||||
else if (_cell.is_bordered)
|
||||
{
|
||||
backgroundColor = [NSColor controlBackgroundColor];
|
||||
}
|
||||
|
||||
if (backgroundColor != nil)
|
||||
{
|
||||
[backgroundColor set];
|
||||
NSRectFill (cellFrame);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the image and the title that will be
|
||||
* displayed. If the NSContentsCellMask is set the
|
||||
|
@ -1190,12 +1200,6 @@
|
|||
[self _drawAttributedText: titleToDisplay inFrame: titleRect];
|
||||
}
|
||||
|
||||
// Draw first responder
|
||||
if (_cell.shows_first_responder
|
||||
&& [[controlView window] firstResponder] == controlView)
|
||||
{
|
||||
NSDottedFrameRect(cellFrame);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSSize) cellSize
|
||||
|
|
Loading…
Reference in a new issue