Using CALayer's renderInContext: method with geometryFlipped

2011-10-22 Thread Nial Giacomelli
I have a CALayer (containerLayer) that I'm looking to convert to a
NSBitmapImageRep before saving the data out as a flat file. containerLayer
has its geometryFlipped property set to YES, and this seems to be causing
issues. The PNG file that is ultimately generated renders the content
correctly, but doesn't seem to takes the flipped geometry into account. I'm
obviously looking for test.png to accurately represent the content shown to
the left.

For reference,here's a screenshot of the issue:
http://i.stack.imgur.com/VasZH.png. You'll see containerLayer on the left
and the generated .png file on the right.

- (NSBitmapImageRep *)exportToImageRep
{
CGContextRef context = NULL;
CGColorSpaceRef colorSpace;
int bitmapByteCount;
int bitmapBytesPerRow;

int pixelsHigh = (int)[[self containerLayer] bounds].size.height;
int pixelsWide = (int)[[self containerLayer] bounds].size.width;

bitmapBytesPerRow = (pixelsWide * 4);
bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);

colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
context = CGBitmapContextCreate (NULL,
 pixelsWide,
 pixelsHigh,
 8,
 bitmapBytesPerRow,
 colorSpace,
 kCGImageAlphaPremultipliedLast);
if (context == NULL)
{
NSLog(@Failed to create context.);
return nil;
}

CGColorSpaceRelease(colorSpace);
[[[self containerLayer] presentationLayer] renderInContext:context];

CGImageRef img = CGBitmapContextCreateImage(context);
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
initWithCGImage:img];
CFRelease(img);

return bitmap;
}

For reference, here's the code that actually saves out the generated
NSBitmapImageRep:

NSData *imageData = [imageRep representationUsingType:NSPNGFileType
properties:nil];
[imageData writeToFile:@test.png atomically:NO];
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSImage mouse events

2011-08-10 Thread Nial Giacomelli
I have a number of NSImages that I'm rendering in a custom NSView subclass.
I'm looking to enlarge theses images as and when the user places their mouse
over them and am wondering about the best way to go about doing this.

Currently I'm using the NSView's drawRect: method to composite the images,
but also free to render them via NSImageView instances, if that will make
things easier. My initial instinct was to setup NSTrackingArea's for each
NSImage instance but wanted to ensure I wasn't missing something obvious.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Problems with tearing down an NSStatusItem menu

2011-07-25 Thread Nial Giacomelli
I'm working on a GC application that makes use of an NSStatusItem to display
a menu to users. I create the NSStatusItem in my controllers awakeFromNib
method, like so:

self.statusItem = [[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength];

[self.statusItem setImage:[NSImage imageNamed:@StatusIconIdle.png]];
[self.statusItem setAlternateImage:[NSImage imageNamed:@
StatusIconSelected.png]];
[self.statusItem setMenu:statusMenu];
[self.statusItem setHighlightMode:YES];

statusMenu is loaded via NIB and contains a mixture of static NSMenuItems
(setup via IB) and dynamically created NSMenuItem instances. Each dynamic
NSMenuItem is generated during a call to NSMenuDelegate's menuNeedsUpdate
function. These dynamic NSMenuItems are created with submenus which contain
further NSMenuItems with custom views. Here's an example of one such
NSMenuItem:

FileRecordPreviewMenuItemView *previewMenuItemView =
[[FileRecordPreviewMenuItemView alloc] initWithURL:url];
[previewMenuItem setView:previewMenuItemView];
[menu insertItem:previewMenuItem atIndex:[menu numberOfItems]];

Everything works as expected. All menus are rendered correctly, interaction
is absolutely perfect. The issue I'm experiencing is that upon Quitting the
application, I experience a crash and see the following error printed to
Console:

Error: kCGErrorIllegalArgument: CGSGetWindowPresenter
Error: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch
errors as they are logged.

Setting the requested breakpoint and performing a stack trace returns the
following:

#0  0x7fff90766dec in CGErrorBreakpoint ()
#1  0x7fff90766a5a in CGSGlobalErrorv ()
#2  0x7fff9080e969 in _GetWindowRightHolder ()
#3  0x7fff8e417deb in _NXPresentsWindow ()
#4  0x7fff8e417d83 in _NXOrderWindow ()
#5  0x7fff8e5b936e in -[NSCarbonWindow
_reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] ()
#6  0x7fff8e38fc89 in -[NSWindow
_doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] ()
#7  0x7fff8e38f90f in -[NSWindow orderWindow:relativeTo:] ()
#8  0x7fff8e50d677 in __-[NSWindow _close]_block_invoke_1 ()
#9  0x7fff8e50d487 in -[NSWindow _close] ()
#10 0x7fff8e927a36 in -[NSWindow _closeForTermination] ()
#11 0x7fff91d219e1 in -[NSObject performSelector:] ()
#12 0x7fff91d25e22 in -[NSArray makeObjectsPerformSelector:] ()
#13 0x7fff8e54b92a in -[NSApplication _deallocHardCore:] ()
#14 0x7fff8e29b72c in -[NSApplication terminate:] ()
#15 0x7fff91d1a11d in -[NSObject performSelector:withObject:] ()
#16 0x7fff8e399852 in -[NSApplication sendAction:to:from:] ()
#17 0x7fff8e48634f in -[NSMenuItem _corePerformAction] ()
#18 0x7fff8e486086 in -[NSCarbonMenuImpl
performActionWithHighlightingForItemAtIndex:] ()
#19 0x7fff8e721e9c in -[NSMenu _internalPerformActionForItemAtIndex:] ()
#20 0x7fff8e5b43f1 in -[NSCarbonMenuImpl
_carbonCommandProcessEvent:handlerCallRef:] ()
#21 0x7fff8e4000bf in NSSLMMenuEventHandler ()
#22 0x7fff89e078ec in DispatchEventToHandlers ()
#23 0x7fff89e06ef8 in SendEventToEventTargetInternal ()
#24 0x7fff89e1dd03 in SendEventToEventTarget ()
#25 0x7fff89e64249 in SendHICommandEvent ()
#26 0x7fff89f4b0f1 in SendMenuCommandWithContextAndModifiers ()
#27 0x7fff89f915e1 in SendMenuItemSelectedEvent ()
#28 0x7fff89e5d32d in FinishMenuSelection ()
#29 0x7fff89f89fed in PopUpMenuSelectCore ()
#30 0x7fff89f8a2ac in _HandlePopUpMenuSelection7 ()
#31 0x7fff8e5b70bd in _NSSLMPopUpCarbonMenu3 ()
#32 0x7fff8e95e02e in _NSPopUpCarbonMenu3 ()
#33 0x7fff8e5b5222 in -[NSCarbonMenuImpl
popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:]
()
#34 0x7fff8e8132f6 in +[NSStatusBarButtonCell
popupStatusBarMenu:inRect:ofView:withEvent:] ()
#35 0x7fff8e8135a1 in -[NSStatusBarButtonCell
trackMouse:inRect:ofView:untilMouseUp:] ()
#36 0x7fff8e397786 in -[NSControl mouseDown:] ()
#37 0x7fff8e36266e in -[NSWindow sendEvent:] ()
#38 0x7fff8e813fb4 in -[NSStatusBarWindow sendEvent:] ()
#39 0x7fff8e2faf19 in -[NSApplication sendEvent:] ()
#40 0x7fff8e29142b in -[NSApplication run] ()
#41 0x7fff8e50f52a in NSApplicationMain ()
#42 0x00011ca0 in start ()

Continuing after the breakpoint is triggered results in the following output
to Console:

Error: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID 1758
Error: kCGErrorIllegalArgument: CGSOrderWindowListWithGroups: invalid
window ID (1758)
Error: kCGErrorIllegalArgument: CGSOrderWindowList: NULL list pointer or
empty list

I've been scratching my head for a good day or so trying to get to the
bottom of this. I noticed a correlation between experiencing the crash on
exit and accessing my NSMenu submenus. If the submenus are displayed, the
application will always crash on exit. If I edit my code so that my submenu
items aren't populated with custom views, the crash never occurs. This led
me to 

Binding CoreData Managed Object to NSTextFieldCell subclass

2010-05-20 Thread Nial Giacomelli
I have an NSTableView which has its first column set to contain a custom
NSTextFieldCell. My custom NSTextFieldCell needs to allow the user to edit a
desc property within my Managed Object but to also display an info
string that it contains (which is not editable). To achieve this, I followed
this tutorial (
http://www.timisted.net/blog/archive/custom-cells-and-core-data/). In a
nutshell, the tutorial suggests editing your Managed Objects generated
subclass to create and pass a dictionary of its contents to your
NSTableColumn via bindings.

This works well for read-only NSCell implementations, but I'm looking to
subclass NSTextFieldCell to allow the user to edit the desc property of my
Managed Object. To do this, I followed one of the articles comments, which
suggests subclassing NSFormatter to explicitly state which Managed Object
property you would like the NSTextFieldCell to edit. I've posted the code of
my NSFormatter subclass here (http://pastebin.org/257930) for reference.

This seems to work, but is extremely patch. On occasion, clicking to edit a
row will cause its value to nullify. On other occasions, the value you enter
on one row will populate other rows within the table.

I've been doing a lot of reading on this subject and would really like to
get to the bottom of this. What's more frustrating is that my
NSTextFieldCell is rendering exactly how I would like it to. This editing
issue is my last obstacle! If anyone can help, that would be greatly
appreciated.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com