discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH (revised)] -setTarget: and -setAction of NSImageView


From: Kazunobu Kuriyama
Subject: Re: [PATCH (revised)] -setTarget: and -setAction of NSImageView
Date: Thu, 15 Jan 2004 12:05:47 +0900
User-agent: Mozilla/5.0 (X11; U; Linux i686; ja-JP; rv:1.4) Gecko/20030624 Netscape/7.1

OK, Fred, you are right and I admit you saved us.

So, let me offer a new patch.

From some reasons, the structure of the header
is different from that of Apple.  In particular,  _editable
is not contained there and is left to that of NSCell.
This is due to the current implementation of GNUstep.

(btw, when I set _editable to YES with Gorm for an NSImageView,
the setting is always ignored.  So I need to use
[NSImageView setEditable:] after calling [NSBundle loadNibNamed:owner:].
This is one of non-trivial incompatibilities between GNUstep and Cocoa
I found.)

The patched -gui has been tested with some apps using
NSImageView, including Procject Center, Gorm, and a
multi-document program using [NSImageView -setTarget:/-setAction:]
taken from the book "Cocoa Programming", which is slightly
modified so that it can compile under GNUstep.
So far, I've found no trouble due to the patch.

Hopefully, this gives us the final solution.  The result
is a little bit ironical, though.

Alexander Malmberg, very sorry for so frequent revisions. I'd appreciate it if you could check the patch.

- Kazunobu Kuriyama


Fred Kiefer wrote:

Thank you Quentin,

but at GNUstep we prefer not to have a direct contact with Apple code or headers. I personaly think, that looking at headers should not be to problematic, but after the recent development with SCO we cannot be to careful. So please don't send any more information that has been directly captured from Apple copyrighted files,

On the other hand your findings and that of Ken Ferry cleary show that Apple did implement the setTarget: and setAction: methods on the level of the NSImageView. So we rather should do this as well on GNUstep.

Cheers
Fred


Quentin Mathé wrote:

Le 13 janv. 04, à 21:01, Fred Kiefer a écrit :

Alexander Malmberg wrote:

However, the general idea was to add target and action. Adding a tag and
a control view effectively turns NSImageCell completely into an
NSActionCell, it isn't required to get dragging working, and it isn't in
apple's docs (but then, target and action aren't, either).
However, I think adding them now is the right thing to do. The cost
(amount of code) is low, it makes NSImageCell more useful, and by adding all the stuff at once, we won't have to change the ivar layout/encoding format twice if it turns out that we want them later (eg. because apple
really did add them, or will).



I don't see any benefit in this additional ivars. Also the main problem why there still is no patch for this is on a different level. What we need to decide is wether to implement the storing of target and action on the cell (as gets done by NSActionCell) or on the view (as done by NSMatrix and loads of others). Here only a test on a MacOSX system could show how Apple did introduce this partly documented feature. But no one with a Mac system has commented on this up to now, that is why the problem may stay unresolved for some more time. There is no abstract way of telling which way around it should be done. As both are in themselves valid.

Anyway, unless there are any other ideas about what to do about this,
I'll commit this (with the above issues fixed) soon.


No, please wait until this question gets answered. If we get the encoding wrong once, we will have to support it for ever!



Here are the Mac OS X headers for NSImageView and NSImageCell :

@interface NSImageView:NSControl
{
    char _editable;
    id _target;
    SEL _action;
}

@interface NSImageCell:NSCell <NSCopying, NSCoding>
{
    id _controlView;
    struct __ICFlags _icFlags;
    struct _NSImageCellAnimationState *_animationState;
    NSImage *_scaledImage;
}

Hope that will help.

Quentin.

--
Quentin Mathé
qmathe@club-internet.fr






_______________________________________________
Bug-gnustep mailing list
Bug-gnustep@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnustep


diff -Naru gui/Headers/AppKit/NSImageView.h gui.rev/Headers/AppKit/NSImageView.h
--- gui/Headers/AppKit/NSImageView.h    2004-01-14 10:08:58.000000000 +0900
+++ gui.rev/Headers/AppKit/NSImageView.h        2004-01-14 11:02:37.000000000 
+0900
@@ -31,6 +31,8 @@
 
 @interface NSImageView : NSControl
 {
+    id _target;                    // [NSImageView version] >= 2
+    SEL        _action;                    // [NSImageView version] >= 2
 }
 
 - (NSImage *)image;
@@ -45,6 +47,14 @@
 - (void)setEditable:(BOOL)flag;
 - (BOOL)isEditable;
 
+- (id)target;                                  // overridden
+- (void)setTarget: (id)anObject;               // overridden
+- (SEL)action;                                 // overridden
+- (void)setAction: (SEL)aSelector;             // overridden
+
+- (void)encodeWithCoder: (NSCoder *)aCoder;    // overridden
+- (id)initWithCoder: (NSCoder *)aDecoder;      // overridden
+
 @end
 
 #endif /* _GNUstep_H_NSImageView */
diff -Naru gui/Source/NSImageView.m gui.rev/Source/NSImageView.m
--- gui/Source/NSImageView.m    2004-01-14 10:09:00.000000000 +0900
+++ gui.rev/Source/NSImageView.m        2004-01-14 10:56:23.000000000 +0900
@@ -46,7 +46,7 @@
 {
   if (self == [NSImageView class])
     {
-      [self setVersion: 1];
+      [self setVersion: 2];
       imageCellClass = [NSImageCell class];
       usedCellClass = imageCellClass;
     }
@@ -146,7 +146,52 @@
   return [_cell isEditable];
 }
 
-@end
+//
+//  Target and Action
+//
+//  Target and action are handled by NSImageView itself, not its own cell.
+//
+- (id)target
+{
+  return _target;
+}
+
+- (void)setTarget: (id)anObject
+{
+  _target = anObject;
+}
+
+- (SEL)action
+{
+  return _action;
+}
+
+- (void)setAction: (SEL)aSelector
+{
+  _action = aSelector;
+}
+
+//
+//  NSCoding Protocol
+//
+- (void)encodeWithCoder: (NSCoder *)aCoder
+{
+  [super encodeWithCoder: aCoder];
+  [aCoder encodeConditionalObject: _target];
+  [aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
+}
+
+- (id)initWithCoder: (NSCoder *)aDecoder
+{
+  self = [super initWithCoder: aDecoder];
+  if ([aDecoder versionForClassName: @"NSImageView"] >= 2)
+    {
+      _target = [aDecoder decodeObject];
+      [aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action];
+    }
+  return self;
+}
+@end // @implementation NSImageView
 
 @implementation NSImageView (NSDraggingDestination)
 
@@ -193,6 +238,7 @@
   else 
     {
       [self setImage: image];
+      [self sendAction: _action to: _target];
       RELEASE(image);
       return YES;
     }
@@ -237,5 +283,6 @@
   return NSDragOperationCopy;
 }
 
-@end
+@end // @implementation NSImageView (NSDraggingDestination)
+
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]