From dffc79cdfb6f743f4e137e0be18451c0340b4bab Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Fri, 17 Nov 2006 08:54:20 +0000 Subject: [PATCH] Merge in some theming changes git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24120 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++ Headers/Additions/GNUstepGUI/GSTheme.h | 13 +++++- Source/GSTheme.m | 14 +++--- Source/NSButtonCell.m | 8 ++-- Source/NSScrollView.m | 62 ++++++++++++++++++++++---- 5 files changed, 84 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index aedd32be7..9dc08a072 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-11-17 Richard Frith-Macdoanld + + * Source/GSTheme.m: + * Source/NSButtonCell.m: + * Source/NSScrollView.m: + * Headers/Additions/GNUstepGUI/GSTheme.h: + Merge in theme changes for scrollviews and cleaner button drawing api. + 2006-11-16 Adam Fedor * Model/GMAppKit.m ([NSImage +createObjectForModelUnarchiver:]): diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index 31da00f3d..7b3530855 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -162,6 +162,17 @@ typedef enum { } GSThemeFillStyle; +/** + * This enumeration provides constants for informing drawing methods + * what state a control is in (and consequently how the display element + * being drawn should be presented). + */ +typedef enum { + GSThemeNormalState, /** A control in its normal state */ + GSThemeHighlightedState, /** A control which is highlighted */ + GSThemeSelectedState, /** A control which is selected */ +} GSThemeControlState; + /** Notification sent when a theme has just become active. */ APPKIT_EXPORT NSString *GSThemeDidActivateNotification; @@ -374,7 +385,7 @@ APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification; in: (NSButtonCell*)cell view: (NSView*)view style: (int)style - state: (int)state; + state: (GSThemeControlState)state; /** Draws the indicator (normally a dotted rectangle) to show that * the view currently has keyboard focus. diff --git a/Source/GSTheme.m b/Source/GSTheme.m index e7f8703c8..fcdc26a03 100644 --- a/Source/GSTheme.m +++ b/Source/GSTheme.m @@ -672,23 +672,23 @@ static NSNull *null = nil; in: (NSButtonCell*)cell view: (NSView*)view style: (int)style - state: (int)state + state: (GSThemeControlState)state { GSDrawTiles *tiles = nil; NSColor *color = nil; NSRect interiorFrame; - if (state == 0) /* default state, unpressed */ + if (state == GSThemeNormalState) { tiles = [self tilesNamed: @"NSButtonNormal" cache: YES]; color = [NSColor controlBackgroundColor]; } - else if (state == 1) /* highlighted state */ + else if (state == GSThemeHighlightedState) { tiles = [self tilesNamed: @"NSButtonHighlighted" cache: YES]; color = [NSColor selectedControlColor]; } - else if (state == 2) /* pushed state */ + else if (state == GSThemeSelectedState) { tiles = [self tilesNamed: @"NSButtonPushed" cache: YES]; color = [NSColor selectedControlColor]; @@ -700,15 +700,15 @@ static NSNull *null = nil; [color set]; NSRectFill(frame); - if (state == 0) /* default state, unpressed */ + if (state == GSThemeNormalState) { [self drawButton: frame withClip: NSZeroRect]; } - else if (state == 1) /* highlighted state */ + else if (state == GSThemeHighlightedState) { [self drawGrayBezel: frame withClip: NSZeroRect]; } - else if (state == 2) /* pushed state */ + else if (state == GSThemeSelectedState) { [self drawGrayBezel: frame withClip: NSZeroRect]; interiorFrame diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m index 8078f17ba..14a5c7ec8 100644 --- a/Source/NSButtonCell.m +++ b/Source/NSButtonCell.m @@ -836,8 +836,8 @@ typedef struct _GSButtonCellFlags - (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView { - unsigned mask; - int buttonState = 0; + unsigned mask; + GSThemeControlState buttonState = GSThemeNormalState; // Save last view drawn to if (_control_view != controlView) @@ -876,14 +876,14 @@ typedef struct _GSButtonCellFlags /* Determine the background color. */ if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask)) { - buttonState = 1; /* highlighted state */ + buttonState = GSThemeHighlightedState; } } /* Pushed in buttons contents are displaced to the bottom right 1px. */ if (_cell.is_bordered && (mask & NSPushInCellMask)) { - buttonState = 2; // pushed button + buttonState = GSThemeSelectedState; } // draw the border if needed diff --git a/Source/NSScrollView.m b/Source/NSScrollView.m index 9ec486a0c..a887f0bcd 100644 --- a/Source/NSScrollView.m +++ b/Source/NSScrollView.m @@ -25,15 +25,18 @@ You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA. + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. */ #include #include +#include #include "AppKit/NSScroller.h" #include "AppKit/NSColor.h" #include "AppKit/NSCell.h" #include "AppKit/NSClipView.h" +#include "AppKit/NSInterfaceStyle.h" #include "AppKit/NSScrollView.h" #include "AppKit/NSRulerView.h" #include "AppKit/NSTableHeaderView.h" @@ -63,6 +66,10 @@ typedef struct _scrollViewFlags #endif } GSScrollViewFlags; +@interface NSScrollView (GSPrivate) +- (void) _themeDidActivate: (NSNotification*)notification; +@end + @implementation NSScrollView /* @@ -169,6 +176,11 @@ static float scrollerWidth; [self setHasHorizontalRuler: YES]; [self tile]; + [[NSNotificationCenter defaultCenter] + addObserver: self + selector: @selector(_themeDidActivate:) + name: GSThemeDidActivateNotification + object: nil]; return self; } @@ -179,6 +191,8 @@ static float scrollerWidth; - (void) dealloc { + [[NSNotificationCenter defaultCenter] removeObserver: self]; + DESTROY(_horizScroller); DESTROY(_vertScroller); DESTROY(_horizRuler); @@ -866,15 +880,24 @@ static float scrollerWidth; if (_hasVertScroller) { NSRect vertScrollerRect; + NSRectEdge edge = NSMinXEdge; + NSInterfaceStyle style; + + style = NSInterfaceStyleForKey(@"NSScrollViewInterfaceStyle", nil); + if (style == NSMacintoshInterfaceStyle + || style == NSWindows95InterfaceStyle) + { + edge = NSMaxXEdge; + } NSDivideRect (contentRect, &vertScrollerRect, &contentRect, - scrollerWidth, NSMinXEdge); + scrollerWidth, edge); [_vertScroller setFrame: vertScrollerRect]; /* Substract 1 for the line that separates the vertical scroller * from the clip view (and eventually the horizontal scroller). */ - NSDivideRect (contentRect, NULL, &contentRect, 1, NSMinXEdge); + NSDivideRect (contentRect, NULL, &contentRect, 1, edge); } /* Prepare the horizontal scroller. */ @@ -883,7 +906,7 @@ static float scrollerWidth; NSRect horizScrollerRect; NSDivideRect (contentRect, &horizScrollerRect, &contentRect, - scrollerWidth, bottomEdge); + scrollerWidth, bottomEdge); [_horizScroller setFrame: horizScrollerRect]; @@ -918,7 +941,7 @@ static float scrollerWidth; NSRect horizRulerRect; NSDivideRect (contentRect, &horizRulerRect, &contentRect, - [_horizRuler requiredThickness], topEdge); + [_horizRuler requiredThickness], topEdge); [_horizRuler setFrame: horizRulerRect]; } @@ -927,7 +950,7 @@ static float scrollerWidth; NSRect vertRulerRect; NSDivideRect (contentRect, &vertRulerRect, &contentRect, - [_vertRuler requiredThickness], NSMinXEdge); + [_vertRuler requiredThickness], NSMinXEdge); [_vertRuler setFrame: vertRulerRect]; } } @@ -964,8 +987,20 @@ static float scrollerWidth; if (_hasVertScroller) { - DPSmoveto(ctxt, [_vertScroller frame].origin.x + scrollerWidth, - [_vertScroller frame].origin.y - 1); + NSInterfaceStyle style; + + style = NSInterfaceStyleForKey(@"NSScrollViewInterfaceStyle", nil); + if (style == NSMacintoshInterfaceStyle + || style == NSWindows95InterfaceStyle) + { + DPSmoveto(ctxt, [_vertScroller frame].origin.x - 1, + [_vertScroller frame].origin.y - 1); + } + else + { + DPSmoveto(ctxt, [_vertScroller frame].origin.x + scrollerWidth, + [_vertScroller frame].origin.y - 1); + } DPSrlineto(ctxt, 0, [_vertScroller frame].size.height + 1); DPSstroke(ctxt); } @@ -1348,7 +1383,8 @@ static float scrollerWidth; { _hasHeaderView = YES; _hasCornerView = YES; - ASSIGN(_headerClipView, [aDecoder decodeObjectForKey: @"NSHeaderClipView"]); + ASSIGN(_headerClipView, + [aDecoder decodeObjectForKey: @"NSHeaderClipView"]); } [self tile]; @@ -1470,3 +1506,11 @@ static float scrollerWidth; } @end + +@implementation NSScrollView (GSPrivate) +- (void) _themeDidActivate: (NSNotification*)notification +{ + [self tile]; +} +@end +