Author: gcasa
Date: Fri Jun 26 07:27:12 2015
New Revision: 38690

URL: http://svn.gna.org/viewcvs/gnustep?rev=38690&view=rev
Log:
Add drawing methods for theming NSBrowserCell.

Modified:
    libs/gui/trunk/ChangeLog
    libs/gui/trunk/Headers/Additions/GNUstepGUI/GSTheme.h
    libs/gui/trunk/Source/GSThemeDrawing.m
    libs/gui/trunk/Source/NSBrowserCell.m
    libs/gui/trunk/Source/NSCell.m

Modified: libs/gui/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=38690&r1=38689&r2=38690&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog    (original)
+++ libs/gui/trunk/ChangeLog    Fri Jun 26 07:27:12 2015
@@ -1,3 +1,11 @@
+2015-06-26 01:22-EDT Gregory John Casamento <[email protected]>
+
+       * Headers/Additions/GNUstepGUI/GSTheme.h: Add declarations for
+       drawing methods for theming.
+       * Source/GSThemeDrawing.m: Add drawing methods for theming
+       * Source/NSBrowserCell.m: Use drawing methods
+       * Source/NSCell.m: Add private method for _inEditing
+
 2015-06-25 20:11-EDT Gregory John Casamento <[email protected]>
 
        * Headers/Additions/GNUstepGUI/GSTheme.h: Add declarations for method

Modified: libs/gui/trunk/Headers/Additions/GNUstepGUI/GSTheme.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Headers/Additions/GNUstepGUI/GSTheme.h?rev=38690&r1=38689&r2=38690&view=diff
==============================================================================
--- libs/gui/trunk/Headers/Additions/GNUstepGUI/GSTheme.h       (original)
+++ libs/gui/trunk/Headers/Additions/GNUstepGUI/GSTheme.h       Fri Jun 26 
07:27:12 2015
@@ -235,8 +235,8 @@
 #if    OS_API_VERSION(GS_API_NONE,GS_API_NONE)
 @class NSArray;
 @class NSBundle;
+@class NSBrowserCell;
 @class NSDictionary;
-
 @class NSButton;
 @class NSColor;
 @class NSColorList;
@@ -1479,6 +1479,46 @@
  */
 - (void) didSetDefaultButtonCell: (NSButtonCell *)aCell;
 @end
+                                        
+@interface GSTheme (NSBrowserCell)
+/** 
+ * Draw editor in cell
+ */
+- (void) drawEditorForCell: (NSCell *)cell
+                withFrame: (NSRect)cellFrame
+                   inView: (NSView *)view;
+
+/** 
+ * Draw attributed text in cell
+ */
+- (void) drawInCell: (NSCell *)cell
+     attributedText: (NSAttributedString *)stringValue
+           inFrame: (NSRect)cellFrame;
+
+/** 
+ * Draw the interior of the browser cell
+ */
+- (void) drawBrowserInteriorWithFrame: (NSRect)cellFrame 
+                            withCell: (NSBrowserCell *)cell
+                              inView: (NSView *)controlView
+                           withImage: (NSImage *)theImage
+                      alternateImage: (NSImage *)alternateImage
+                       isHighlighted: (BOOL)isHighlighted
+                               state: (int)state
+                              isLeaf: (BOOL)isLeaf;
+
+/** 
+ * This method returns the branch image
+ */
+- (NSImage *) branchImage;
+
+/** 
+ * This method returns the highlighted version of 
+ * the branch image
+ */
+- (NSImage *) highlightedBranchImage;
+@end
+
 
 #endif /* OS_API_VERSION */
 #endif /* _GNUstep_H_GSTheme */

Modified: libs/gui/trunk/Source/GSThemeDrawing.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/GSThemeDrawing.m?rev=38690&r1=38689&r2=38690&view=diff
==============================================================================
--- libs/gui/trunk/Source/GSThemeDrawing.m      (original)
+++ libs/gui/trunk/Source/GSThemeDrawing.m      Fri Jun 26 07:27:12 2015
@@ -35,6 +35,7 @@
 #import "AppKit/NSBezierPath.h"
 #import "AppKit/NSButtonCell.h"
 #import "AppKit/NSBrowser.h"
+#import "AppKit/NSBrowserCell.h"
 #import "AppKit/NSCell.h"
 #import "AppKit/NSColor.h"
 #import "AppKit/NSColorList.h"
@@ -75,6 +76,11 @@
 
 @interface NSCell (Private)
 - (void) _setInEditing: (BOOL)flag;
+- (BOOL) _inEditing;
+- (void) _drawEditorWithFrame: (NSRect)cellFrame
+                       inView: (NSView *)controlView;
+- (void) _drawAttributedText: (NSAttributedString*)aString 
+                     inFrame: (NSRect)aRect;
 @end
 
 @implementation        GSTheme (Drawing)
@@ -3351,4 +3357,131 @@
     }
 }
 
+- (void) drawEditorForCell: (NSCell *)cell
+                withFrame: (NSRect)cellFrame
+                   inView: (NSView *)view
+{
+  [cell _drawEditorWithFrame: cellFrame 
+                     inView: view];
+}
+
+
+- (void) drawInCell: (NSCell *)cell
+     attributedText: (NSAttributedString *)stringValue
+           inFrame: (NSRect)cellFrame
+{
+  [cell _drawAttributedText: stringValue 
+                   inFrame: cellFrame];
+}
+
+// NSBrowserCell
+- (void) drawBrowserInteriorWithFrame: (NSRect)cellFrame 
+                            withCell: (NSBrowserCell *)cell
+                              inView: (NSView *)controlView
+                           withImage: (NSImage *)theImage
+                      alternateImage: (NSImage *)alternateImage
+                       isHighlighted: (BOOL)isHighlighted
+                               state: (int)state
+                              isLeaf: (BOOL)isLeaf
+{
+  NSRect       title_rect = cellFrame;
+  NSImage      *branch_image = nil;
+  NSImage      *cell_image = theImage;
+
+  if (isHighlighted || state)
+    {
+      if (!isLeaf)
+       branch_image = [self highlightedBranchImage];
+      if (nil != alternateImage)
+       [cell setImage: alternateImage];
+
+      // If we are highlighted, fill the background
+      [[cell highlightColorInView: controlView] setFill];
+      NSRectFill(cellFrame);
+    }
+  else
+    {
+      if (!isLeaf)
+       branch_image = [self branchImage];
+
+      // (Don't fill the background)
+    }
+  
+  // Draw the branch image if there is one
+  if (branch_image) 
+    {
+      NSRect imgRect;
+
+      imgRect.size = [branch_image size];
+      imgRect.origin.x = MAX(NSMaxX(title_rect) - imgRect.size.width - 4.0, 
0.);
+      imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.), 
0.);
+
+      if (controlView != nil)
+       {
+         imgRect = [controlView centerScanRect: imgRect];
+       }
+
+      [branch_image drawInRect: imgRect
+                     fromRect: NSZeroRect
+                    operation: NSCompositeSourceOver
+                     fraction: 1.0
+               respectFlipped: YES
+                        hints: nil];
+
+      title_rect.size.width -= imgRect.size.width + 8;
+    }
+
+  // Skip 2 points from the left border
+  title_rect.origin.x += 2;
+  title_rect.size.width -= 2;
+  
+  // Draw the cell image if there is one
+  if (cell_image) 
+    {
+      NSRect imgRect;
+      
+      imgRect.size = [cell_image size];
+      imgRect.origin.x = NSMinX(title_rect);
+      imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.),0.);
+
+      if (controlView != nil)
+       {
+         imgRect = [controlView centerScanRect: imgRect];
+       }
+
+      [cell_image drawInRect: imgRect
+                   fromRect: NSZeroRect
+                  operation: NSCompositeSourceOver
+                   fraction: 1.0
+             respectFlipped: YES
+                      hints: nil];
+
+      title_rect.origin.x += imgRect.size.width + 4;
+      title_rect.size.width -= imgRect.size.width + 4;
+   }
+
+  // Draw the body of the cell
+  if ([cell _inEditing])
+    {
+      [self drawEditorForCell: cell 
+                   withFrame: cellFrame 
+                      inView: controlView];
+    }
+  else
+    {
+      [self drawInCell: cell
+       attributedText: [cell attributedStringValue]
+              inFrame: title_rect];
+    }
+}
+
+- (NSImage *) branchImage
+{
+  return [NSImage imageNamed: @"common_3DArrowRight"];
+}
+
+- (NSImage *) highlightedBranchImage
+{
+  return [NSImage imageNamed: @"common_3DArrowRightH"];
+}
 @end

Modified: libs/gui/trunk/Source/NSBrowserCell.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSBrowserCell.m?rev=38690&r1=38689&r2=38690&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSBrowserCell.m       (original)
+++ libs/gui/trunk/Source/NSBrowserCell.m       Fri Jun 26 07:27:12 2015
@@ -40,6 +40,7 @@
 #import "AppKit/NSEvent.h"
 #import "AppKit/NSWindow.h"
 #import "GSGuiPrivate.h"
+#import "GNUstepGUI/GSTheme.h"
 
 /*
  * Class variables
@@ -90,7 +91,7 @@
  */
 + (NSImage*) branchImage
 {
-  return _branch_image;
+  return [[GSTheme theme] branchImage];
 }
 
 /**<p>Returns the default hightlited branch image</p>
@@ -98,7 +99,7 @@
  */
 + (NSImage*) highlightedBranchImage
 {
-  return _highlight_image;
+  return [[GSTheme theme] highlightedBranchImage];
 }
 
 /*
@@ -330,92 +331,14 @@
  */
 - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
 {
-  NSRect       title_rect = cellFrame;
-  NSImage      *branch_image = nil;
-  NSImage      *cell_image = [self image];
-
-  if (_cell.is_highlighted || _cell.state)
-    {
-      if (!_browsercell_is_leaf)
-       branch_image = [object_getClass(self) highlightedBranchImage];
-      if (nil != [self alternateImage])
-         cell_image = [self alternateImage];
-
-      // If we are highlighted, fill the background
-      [[self highlightColorInView: controlView] setFill];
-      NSRectFill(cellFrame);
-    }
-  else
-    {
-      if (!_browsercell_is_leaf)
-       branch_image = [object_getClass(self) branchImage];
-
-      // (Don't fill the background)
-    }
-  
-  // Draw the branch image if there is one
-  if (branch_image) 
-    {
-      NSRect imgRect;
-
-      imgRect.size = [branch_image size];
-      imgRect.origin.x = MAX(NSMaxX(title_rect) - imgRect.size.width - 4.0, 
0.);
-      imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.), 
0.);
-
-      if (controlView != nil)
-       {
-         imgRect = [controlView centerScanRect: imgRect];
-       }
-
-      [branch_image drawInRect: imgRect
-                     fromRect: NSZeroRect
-                    operation: NSCompositeSourceOver
-                     fraction: 1.0
-               respectFlipped: YES
-                        hints: nil];
-
-      title_rect.size.width -= imgRect.size.width + 8;
-    }
-
-  // Skip 2 points from the left border
-  title_rect.origin.x += 2;
-  title_rect.size.width -= 2;
-  
-  // Draw the cell image if there is one
-  if (cell_image) 
-    {
-      NSRect imgRect;
-      
-      imgRect.size = [cell_image size];
-      imgRect.origin.x = NSMinX(title_rect);
-      imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.),0.);
-
-      if (controlView != nil)
-       {
-         imgRect = [controlView centerScanRect: imgRect];
-       }
-
-      [cell_image drawInRect: imgRect
-                   fromRect: NSZeroRect
-                  operation: NSCompositeSourceOver
-                   fraction: 1.0
-             respectFlipped: YES
-                      hints: nil];
-
-      title_rect.origin.x += imgRect.size.width + 4;
-      title_rect.size.width -= imgRect.size.width + 4;
-   }
-
-  // Draw the body of the cell
-  if (_cell.in_editing)
-    {
-      [self _drawEditorWithFrame: cellFrame inView: controlView];
-    }
-  else
-    {
-      [self _drawAttributedText: [self attributedStringValue]
-                        inFrame: title_rect];
-    }
+  [[GSTheme theme] drawBrowserInteriorWithFrame: cellFrame 
+                                      withCell: self
+                                        inView: controlView
+                                     withImage: [self image]
+                                alternateImage: [self alternateImage]
+                                 isHighlighted: [self isHighlighted] 
+                                         state: [self state]
+                                        isLeaf: [self isLeaf]];
 }
 
 /*

Modified: libs/gui/trunk/Source/NSCell.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSCell.m?rev=38690&r1=38689&r2=38690&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSCell.m      (original)
+++ libs/gui/trunk/Source/NSCell.m      Fri Jun 26 07:27:12 2015
@@ -3030,6 +3030,11 @@
   _cell.in_editing = flag;
 }
 
+- (BOOL) _inEditing
+{
+  return _cell.in_editing;
+}
+
 - (void) _updateFieldEditor: (NSText*)textObject
 {
   if (_formatter != nil)


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to