Re: Testing if a NSPipe has available data

2009-08-10 Thread Frédéric Testuz

Le 10 août 09 à 14:14, Alastair Houghton a écrit :


On 10 Aug 2009, at 12:28, Frédéric Testuz wrote:


Le 10 août 09 à 12:40, Alastair Houghton a écrit :

So what's wrong with waiting for -[NSFileHandle availableData] to  
return with zero bytes?


First : if you call availableData and there is no data and the end  
of file is not reached, you are blocking your thread.


Only if (a) there is no data available and (b) you are dealing with  
a communications link.


Yes. Sorry if it was implicite on my part because I was talking about  
a pipe communicating with a task.


If I understand correctly, gnuplot don't send the end of file  
because you can send new command to the same plot.


Ah, OK, I assume in that case that you want to keep gnuplot running  
so that you can plot something else afterwards?


Yes, I still can quit gnuplot after each plot, but I don't know if it  
will be very efficient (too early optimisation :-)


In that case, the cleanest approach is probably going to be to tell  
gnuplot to send the data somewhere other than stdout (using "set  
output").  The simplest thing would be to use a temporary file.


I will not have the similar problem ? When I can be sure that the file  
is written.


If you can live with invoking gnuplot separately every time, you  
could just tell it to quit after generating the data that you want.


See above.



So the only way I can see is to check if there still data waiting  
in the file handle buffer before calling readInBackgroundAndNotify  
or availableData.


That won't work in the general case; gnuplot might generate some  
data, then your app might run and take it all, in which case there  
would be no data waiting in the buffer... but gnuplot might not have  
finished and might subsequently generate more data.


Well thanks. Actually I'm doing it by coupling ioctl with checking the  
data for the presence of "%%Trailer", but I'm not sure it will be ok  
for future version of gnuplot.


Note : if there was an easy way to get a NSImage from svg I would have  
choose this format. Finding the end svg data is easy ()


Frédéric___

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


Re: Cmd+key shortcuts not being sent to NSWindow on Tiger

2009-08-10 Thread Kirk Swenson


On Aug 10, 2009, at 11:04 PM, Uli Kusterer wrote:


On Aug 8, 2009, at 3:30 AM, Kirk Swenson wrote:

- (id) windowWillReturnFieldEditor: (NSWindow*) aWindow toObject:  
(id) anObject

{
	// myTextFieldEditor is a member variable, so there will only be  
one of them.

if( myTextFieldEditor == nil) {
myTextFieldEditor = [[MyTextView alloc] init];


Isn't that missing an autorelease? Or is this documented as an  
exception somewhere? Looks like you're leaking a text view each time  
this is called.


As the comment suggests, myTextFieldEditor is an instance variable.  
It's released in the dealloc method. It's worth pointing out that  
according to the documentation, "This method may be called multiple  
times while a control is first responder. Therefore, you must return  
the same field editor object for the control while the control is  
being edited." In other words, the pointer has to be cached --  
creating a new one on every call would violate the requirements of the  
method.


Kirk Swenson
Senior Software Engineer
KCP Technologies

___

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


Re: System Sound, and Audio Services [solved more] (was: NSSound play often fails)

2009-08-10 Thread Uli Kusterer
For what it's worth, for an iPhone app, I wrote some code that uses  
the system sound and audio queue APIs and is wrapped in a little class  
that looks like an NSSound. Find it here:


http://zathras.de/sourcecode.htm#UKSoundUKSystemSound

That may be a better choice, as it will let you move back to Apple's  
NSSound without many code changes if the issues you've been  
encountering ever get fixed.


If you make any additions/changes to these classes, I'd appreciate if  
you sent the code back to me, so I can include them.


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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


Re: To get system sounds for Move or Copy operations

2009-08-10 Thread Uli Kusterer

On Aug 10, 2009, at 6:51 PM, Sean McBride wrote:

NSSound initWithContentsOfFile:byReference: should do it.


 There's also a PlayThemeSound() API in Carbon.framework's  
Appearance.h. There's a comment in that header indicating that it  
wasn't implemented for a while, and I haven't tried whether it works,  
but that it's not deprecated hints that it might work after all.


 Can't hurt to try it.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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


Re: Cmd+key shortcuts not being sent to NSWindow on Tiger

2009-08-10 Thread Uli Kusterer


On Aug 8, 2009, at 3:30 AM, Kirk Swenson wrote:

- (id) windowWillReturnFieldEditor: (NSWindow*) aWindow toObject:  
(id) anObject

{
	// myTextFieldEditor is a member variable, so there will only be  
one of them.

if( myTextFieldEditor == nil) {
myTextFieldEditor = [[MyTextView alloc] init];


 Isn't that missing an autorelease? Or is this documented as an  
exception somewhere? Looks like you're leaking a text view each time  
this is called.


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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


Re: Disabled controls don't update their visual appearance

2009-08-10 Thread Uli Kusterer

On Aug 10, 2009, at 6:04 PM, Christopher Campbell Jensen wrote:
I am sure I am just missing a single line of code, but I can't  
understand the following behavior:

This code is where the issue occours:
- (void)refreshButtonsEnabledState
{
	NSLog(@"%d", [[[tabView selectedTabViewItem] label]  
isEqualToString:@"Current/Custom"] && [movieFile.movieMetaData  
isCreated]);
	[toggleWriteCheckMarksButton setEnabled:[[[tabView  
selectedTabViewItem] label] isEqualToString:@"Current/Custom"] &&  
[movieFile.movieMetaData isCreated]];

[resetMetaDataButton setEnabled:[movieFile.movieMetaData isCreated]];
}


I presume tabView, movieFile, toggleWriteCheckMarksButton and  
resetMetaDataButton are instance variables, and most of them are  
outlets. Is any of them perhaps NIL at the point where your code fails?


Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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


Re: defining NSColor constants

2009-08-10 Thread Uli Kusterer

On Aug 6, 2009, at 8:58 AM, Arie Pieter Cammeraat wrote:
NSColor * const kNiceBlueColor = [NSColor colorWithRed: 20 green: 20  
blue: 240 alpha:1];


 Don't assign autoreleased objects to global variables/global  
constants, please. The object will get autoreleased and the constant  
will point to the address of an object that is long gone. Stuff like  
that leads to bugs that are very hard to track down. (unless you're  
running with the garbage collector, then the code above is mostly OK).


 The best appproach suggested so far is a category on NSColor where  
you implement:


+(NSColor*)mySoylentGreen
{
static NSColor*   sMySoylentGreen = nil; // Static var -- global  
that's invisible outside this method. Initialization only happens the  
first time.

if( sMySoylentGreen == nil )
sMySoylentGreen = [[NSColor alloc] initWithCalibratedRed: 0  
green: 1.0 blue: 0];

return sMySoylentGreen;
}

Why do this?

1) It creates the color lazily, as needed, the first time someone uses  
it. If you create all your colors right at startup, this makes your  
app slower to start up. This way, the long startup wait is actually  
turned into many split-second waits distributed throughout the runtime  
of your program.


2) It's efficient, because the object in the sMzSoylentGreen variable  
is created exactly once and then re-used. If you used NSColor  
colorWithCalibratedRed:green:blue with the actual numbers in a loop,  
you would create a new object each time.


3) It is an "intentional leak". Usually, you would have to release an  
object created using an alloc/init call. But since it is in a global  
variable (sMySoylentGreen), you can always access it, and since you'll  
probably keep using it for the rest of your app's lifetime, you can  
let the OS recycle it along with all your app's memory when your  
application shuts down.


Hope that helps,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de





___

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


Re: Trouble with event taps...

2009-08-10 Thread Dave Keck
>
>Event taps receive key up and key down events if one of the following
> conditions is true: The current process is running as the root user. Access
> for assistive devices is enabled.


Woops, I forgot that you said you enabled access for assistive device. I
just made a quick test project and everything seems to work as the docs
explain: when running as root, keyboard events trigger the callback, and
likewise when access for assistive devices is enabled.

Here's my test project based on your code: http://themha.com/et.zip

Does that project still not receive the keyboard events when running as
root/with assistive device access
enabled? On 10.5.8 it works as expected. What OS are you on?
___

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


Re: Trouble with event taps...

2009-08-10 Thread Dave Keck
> James is exactly right, you're releasing the Event Tap before you enable
it.
> You should not release the event tap if you want to use it, it needs to
hang
> around for as long as you need it.

It's not mentioned in the docs, but the CFRunLoopSource created by the call
to CFMachPortCreateRunLoopSource() retains the CFMachPort object. And since
Nat's callback is called for mouse events but not keyboard events, the fact
that he's releasing the CFMachPort object early doesn't explain why he's not
receiving the keyboard events.

And naturally, just now, I noticed it mentioned in the docs:

   Event taps receive key up and key down events if one of the following
conditions is true: The current process is running as the root user. Access
for assistive devices is enabled.

Three strikes for relying on the docs in the header and not bothering to
check the 'real' docs. Case closed?
___

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


Re: Trouble with event taps...

2009-08-10 Thread Rob Keniger


On 11/08/2009, at 2:37 AM, James W. Walker wrote:

I compared your code to the code that I use that gets key down  
successfully.  One difference is that I don't immediately CFRelease  
the event tap and source, I keep them around as long as I use the  
tap.  Another is that the first 2 parameters I pass to  
CGEventTapCreate are kCGAnnotatedSessionEventTap and  
kCGTailAppendEventTap.



James is exactly right, you're releasing the Event Tap before you  
enable it. You should not release the event tap if you want to use it,  
it needs to hang around for as long as you need it.


 // Create a run loop source.
 runLoopSource =
CFMachPortCreateRunLoopSource(/*kCFAllocatorDefault*/NULL, eventTap, 0);

 CFRelease(eventTap); // !! This release should not be here!!

 // Add to the current run loop.
 CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],
runLoopSource, kCFRunLoopCommonModes);

 // Enable the event tap.
 CGEventTapEnable(eventTap, true);  //you're using the event tap  
here, but you've already released it so the pointer is invalid


 CFRelease(runLoopSource);


--
Rob Keniger



___

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


CoreData object graph gets confused

2009-08-10 Thread John Terranova
I've got two objects in my data model, say Class and Teacher.  Class  
has a to-one relation to a Teacher and Teacher has a to-many back to  
Class.


When a Class is created I assign a particular default Teacher to it  
(e.g. J. Doe).  Then, J. Doe has that class added to his set of  
Classes.  I override [Class setTeacher:] to change a nil Teacher to  
the default Teacher.


- (void)setTeacher:(Teacher *)teach
{
if (teach == nil)
// from my NSManagedObjectContext extensions
		teach = (Teacher *)[[self managedObjectContext] fetchOne:@"Teacher"  
whose:@"name" is:@"J. Doe" createIfNone:NO];


[self willChangeValueForKey:@"teacher"];
[self setPrimitiveValue:teach forKey:@"teacher"];
[self didChangeValueForKey:@"teacher"];
}

This works great and every class starts with J Doe and if a Class's  
Teacher is set to nil, then it gets J Doe (who works very hard).   
There is, of course, one small problem that happens when a Teacher is  
remove:'d from the object model.  The Delete Rule for Teacher.Class is  
set to Nullify.  When a Teacher is removed, all of it's Classes get  
their Teacher set to null, which is overridden in setTeacher: so each  
Class gets J Doe for its Teacher.  The problem is that this is not  
reflected in Teacher -- the Class is not added to the J Doe's set of  
Classes.


Bottom line:When a Teacher is remove:'d, its Classes get sent a  
setTeacher:nil (because the Delete Rule is Nullify).  The nil gets  
changed to J Doe, so the Class points to J Doe.  But J Doe is not  
updated to point back to Class.


Am I not supposed to modify the object graph during a remove:?  Or, is  
this a bug in Delete Rule handling that I should submit?  Or, did I  
miss something in the docs about this situation?


Thanks.

john
___

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


Registering and opening a help book located outside an application bundle

2009-08-10 Thread Michael Gozzo
Good day everybody,

I'm writing an application that needs to access a help bundle with
several localizations that is stored outside of the main application's
bundle. To do this, I'm currently doing the following:

1. Get a CFURLRef to the location of the help bundle in the filesystem.
2. Get a FSRef from the CFURLRef
3. Register the help book by calling AHRegisterHelpBook()
4. If this didn't fail, retrieve the localized value of
CFBundleHelpBookName from the NSBundle object that wraps the help
bundle.
5. Finally, use AHLookupAnchor() to open up a constant anchor in the
help book whose name I retrieved in (4).

This seems to work perfectly under Leopard, I was wondering if I am
doing anything in this sequence of 5 steps that can cause an issue
when running on 10.6 or if I'm not going about this in the best way
possible under 10.5.

Any help you Cocoa wizards could offer would be greatly appreciated!

Thanks in advance!

Michael
___

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


Re: Maintaining an ordered array of attributes in an NSTextStorage subclass

2009-08-10 Thread Alastair Houghton

On 10 Aug 2009, at 21:07, Keith Blount wrote:

Many thanks again for the reply, much appreciated. - 
replaceCharactersInRange:withString:, -setAttributes:range: (and - 
addAttribute:value:range:, which also needs overriding) is in fact  
exactly where I'm trying to intercept things. The problem is _how_  
best to maintain and keep up to date the array of comments, though,  
so that it always contains, in order, a list of the comments that  
appear as attributes in the text.


OK, so as you've discovered, this particular problem is potentially a  
tricky one :-)


There are two general solutions of which I am aware to efficiently  
storing range information in such a way that you don't need to update  
every range every time there's an edit.  The first is the traditional  
"gap buffer" approach, whereby you store references to locations  
*after* the gap relative to the end of the buffer, and references to  
locations *before* the gap relative to the start of the buffer.  That  
way, you only need to update references when you move the gap across  
them.  The gap is, generally speaking the current edit location.


The second is to store the data as a tree, but to do everything by  
length rather than by absolute positions.  The idea is that each tree  
node contains a count of the number of elements covered by it and all  
of its children; then it's easy to know the position of each tree node  
(since it is just the sum of the lengths of the node's left siblings  
in the tree), and when you insert or delete elements you only have to  
deal with the affected leaf node and its parents.  You'd want to use a  
balanced tree of some sort to control the worst case performance; a  
red-black or 2-3 tree would work well.  (For a simplistic  
implementation you could store a linear list of lengths instead of  
using a tree, but that would provide relatively poor random access  
performance.)


I suspect the text system is using the latter approach or some  
variation thereof (since it's better, though a little trickier to  
implement); there are hints that this may be the case---for instance  
the fact that attribute runs appear to be split if they overlap  
existing attribute runs, which is a requirement for that scheme to  
work.  Some of the text system people who read this list may be able  
to confirm one way or another (but it doesn't really matter).


As you might gather from the above, the attribute storage and  
iteration methods in the text system are extremely efficient, so the  
inefficiency in your proposal is really the construction and  
maintenance of the NSArray.


So the next question is whether or not it's worth your while  
implementing such a thing yourself off to one side, rather than just  
using the text system's implementation already.  The downside of using  
the text system's implementation is that it will, necessarily, split  
your comment ranges, and AFAIK you won't be able to tell the  
difference between two adjacent comments containing the same data and  
one comment that has been split (e.g. because someone made some text  
bold in an overlapping range).  If this really matters you might be  
best off using your own range storage instead.


Assuming you really need the NSArray interface, I think what I would  
be inclined to do is to write an NSArray subclass that worked by  
iterating over the attributes in the text storage (since that avoids  
having to implement the range-based store yourself, which *is* doable  
and would be more efficient but it isn't a trivial bit of work).  To  
make it more efficient, keep a cache of the location of the last  
attribute run retrieved from the array (and its notional index), then  
when something asks for an adjacent index (highly likely) you can just  
iterate forwards or backwards as appropriate.


If you really need random access to the array, you could cache the  
last few locations and work from the closest one.


Kind regards,

Alastair.

p.s. Sorry this post is quite long, but it's quite an interesting  
topic, I think :-)


--
http://alastairs-place.net



___

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


FreeTDS Cocoa Sample?

2009-08-10 Thread Robert Mullen
I have scoured the archives and the web in general looking for a  
sample XCode project that uses FreeTDS. Does anyone know where one can  
be found or would anyone be kind enough to share some source code with  
me? What I have done so far is to compile FreeTDS 0.82 on my system  
and successfully test it to a SQL Server database via tsql. I have  
added /usr/local/include to my projects header search paths. I then  
import  and  but when I go to  
compile with just the imports and no code referencing the headers I  
get an error "conflicting types for BOOL." It looks like BOOL is  
conditionally compiled inside sybdb.h and even though the condition is  
not met it seems like the compiler is struggling with it.


Anyway, I have banged my head against this for several steps and am  
wondering if someone has the goods. If not can someone help me past  
this problem?


TIA

___

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


Re: NSData Questions

2009-08-10 Thread Alastair Houghton

On 8 Aug 2009, at 22:45, Eric Hermanson wrote:

1. Is it more efficient to malloc a uint8_t array and call NSData  
'init no copy', rather than pass in an array allocated with a fixed  
length on the stack to the init method that makes a copy of the bytes?


2. Does NSMutableData's implementation simply just cast it's  
internal bytes to const in the 'bytes' method, or does it internally  
copy the bytes into a new autoreleased NSData and return the 'bytes'  
for that copy, for example?


In general I don't think it's worth worrying too much about these  
kinds of details, other than to say that Apple only employs decent  
software engineers, so you won't find their code doing anything  
particularly inefficient in general.  Indeed, sometimes it turns out  
to be more efficient than you might naïvely assume (for instance some  
of the collection classes tune their implementations to the size of  
data they're storing).


Anyway, if you're really interested, you can see the underlying  
implementation in the Open Source part of CoreFoundation; the most  
recent release on Apple's site is CF-476.18, and you can find it here:


  

Many of the toll-free bridged classes' implementations are (mostly)  
exposed in that project.  I say mostly because it's fairly clear that  
the CF project is a subset of the *actual* CoreFoundation framework.   
But it's useful to be able to see how things work sometimes.


Kind regards,

Alastair.

--
http://alastairs-place.net



___

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


Re: Maintaining an ordered array of attributes in an NSTextStorage subclass

2009-08-10 Thread Keith Blount

Many thanks again for the reply, much appreciated. 
-replaceCharactersInRange:withString:, -setAttributes:range: (and 
-addAttribute:value:range:, which also needs overriding) is in fact exactly 
where I'm trying to intercept things. The problem is _how_ best to maintain and 
keep up to date the array of comments, though, so that it always contains, in 
order, a list of the comments that appear as attributes in the text. I thought 
of just providing -addCommentAtRange: and -removeCommentAtRange: methods and 
inserting the comment objects to the array (or removing them) directly in these 
methods at the same time as applying the attribute to the text, but this only 
goes so far. There is still the problem of what happens when the user copies 
and pastes some text with a comment in it or deletes a range of text with a 
comment in it. When this happens, the -replaceCharacters:inRange:... 
-setAttributes:... etc methods are still going to have to check for a change in
 the comments (which is easy enough) and then update the comments array - and 
it is this latter part which is causing me a headache.

The problem really just lies in keeping things fast. For instance, the 
following would be a workable solution, but could be too slow:

E.g:
• -replaceCharactersInRange... detects that a comment is being deleted.
• Calls something like -fixUpCommentsInRange:...
• -fixUpCommentsInRange:(NSRange)fixRange uses 
-attribute:atIndex:range:effectiveRange: to look for comments in either (a) the 
entire text or (b) from fixRange.location to [text length]-fixRange.location, 
and adjusts the comments array as necessary.

(It couldn't just look at the current edited range as the comment may now exist 
in two places, or may have been moved from the end of the text and so the code 
needs to account for this.)

The above would work, but the trouble is that this would be quite slow for long 
texts that have lots of comments, where the edit occurs towards the beginning 
of the text. (Although it wouldn't be an issue for text that has no comments 
associated with it.)

So the mental block I am having really lies in keeping my array of the 
KBCommentAttributeName objects (NSDictionary objects in the earlier example) up 
to date as the user edits the text using the base NSTextStorage methods in a 
fast and efficient manner, so that -(NSMutableArray *)comments always returns a 
list of comment objects in the order they appear as attributes in the text. 
Everything I think of would either be slow or hits another mental block (e.g. 
if I keep range information inside each comment object so that I could sort the 
array by range locations, then all comment objects after the current edited 
range would need updating with their new respective ranges each time the text 
is edited...).

Many thanks again and all the best,
Keith

> In theory, code is supposed to call beginEdiing/endEditing
> around any operation that edits the text so that might be
> one place you could override to handle this. Other methods
> in NSMutableAttributedString may need to be overridden to
> get information about affected ranges. There are only two
> primitive methods, according to the docs:
> 
> - (void)replaceCharactersInRange:(NSRange)aRange
> withString:(NSString *)aString
> 
> - (void)setAttributes:(NSDictionary *)attributes
> range:(NSRange)aRange
> 
> So those two should provide all the hooks you'd need. If
> your auxiliary array is kept sorted by range position it
> should be easy and efficient to locate the relevant entries
> affected by an edit in a given range. Ideally you'd want to
> manage the comments such that the text storage does all the
> hard work of maintaining the attribute runs/ranges, and all
> you have to do is to add and delete comments in your array
> as necessary.
> 
> Still a bit vague, but might help with the inspiration...
> 
> --Graham
> 
> 
> 



___

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


Re: Core Data - attribute to hold an array of strings

2009-08-10 Thread John Baldwin
I took this to mean that NSImage conforms to NSCoding and therefore  
can be archived, whereas UIImage does not conform and requires this  
extra step to convert the image to an NSData object, which can be  
archived.


John

On Sunday Aug 9  4:10 PM, at 4:10 PM, Kyle Sluder wrote:

On Aug 9, 2009, at 4:39 AM, parag vibhute   
wrote:


Yes, you can. Only thing is you need to convert UIImage object to  
NSData

object. There are two C APIs


Good to know for the iPhone crowd, but the question was about  
NSImage, which is a Mac class.


--Kyle Sluder


___

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


Re: Trouble with event taps...

2009-08-10 Thread Nat Burke
Thanks all for some tips.  I'm going to try the following ideas and I'll let
you know how it goes:
- Run as root
- Try just trapping on keyboard events
- Append my event tap to the tail, and try annotated.



On Mon, Aug 10, 2009 at 9:37 AM, James W. Walker  wrote:

>
> On Aug 9, 2009, at 3:15 PM, Nat Burke wrote:
>
>   I have posted my event tap creation code below - I've searched all over
>> the mailing list and the net to see if I could find a solution, but I am
>> genuinely stuck. Any help is greatly appreciated!
>>
>>
>>  // Create an event tap.
>>  eventMask = CGEventMaskBit(kCGEventRightMouseDown) |
>>  CGEventMaskBit(kCGEventRightMouseUp)   |
>>  CGEventMaskBit(kCGEventRightMouseDragged) |
>>  CGEventMaskBit(kCGEventMouseMoved) |
>>  CGEventMaskBit(kCGEventScrollWheel)|
>>  CGEventMaskBit(kCGEventFlagsChanged) |
>>  CGEventMaskBit(kCGEventKeyDown) |
>>  CGEventMaskBit(kCGEventKeyUp);
>>
>>  DebugLog(@"Event before: %x", eventMask);
>>
>>  eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap,
>> kCGEventTapOptionDefault, eventMask, MouseCallback, self);
>>
>>  DebugLog(@"Event after: %x", eventMask);
>>
>>  if (!eventTap) {
>> fprintf(stderr, "Failed to create event tap\n");
>> exit(1);
>>  }
>>
>>  // Create a run loop source.
>>  runLoopSource =
>> CFMachPortCreateRunLoopSource(/*kCFAllocatorDefault*/NULL, eventTap, 0);
>>
>>  CFRelease(eventTap);
>>
>>  // Add to the current run loop.
>>  CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],
>> runLoopSource, kCFRunLoopCommonModes);
>>
>>  // Enable the event tap.
>>  CGEventTapEnable(eventTap, true);
>>
>>  CFRelease(runLoopSource);
>>
>
>
> I compared your code to the code that I use that gets key down
> successfully.  One difference is that I don't immediately CFRelease the
> event tap and source, I keep them around as long as I use the tap.  Another
> is that the first 2 parameters I pass to CGEventTapCreate are
> kCGAnnotatedSessionEventTap and kCGTailAppendEventTap.
>
>
>
___

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


Re: [iPhone 3.0] crashes in webView:didCommitLoadForFrame:

2009-08-10 Thread Kyle Sluder
Immensely helpful in these scenarios: So you crashed in
objc_msgSend(): iPhone Edition

http://sealiesoftware.com/blog/archive/2009/06/08/objc_explain_So_you_crashed_in_objc_msgSend_iPhone_Edition.html

--Kyle Sluder
___

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


Re: NSURLCache

2009-08-10 Thread glenn andreas


On Aug 10, 2009, at 1:38 PM, Mike Manzano wrote:

Has anyone been able to successfully get the URL loading system on  
iPhone to pay attention to custom versions of NSURLCache? It seems  
to me that it's being ignored. More info here:


http://stackoverflow.com/questions/1246420/need-content-in-uiwebview-to-display-quickly

(See the second "answer" on that page).

Just need some sort of clue if I'm doing something wrong or if my  
code's just being ignored.



Yes, I've had it work - it just requires making your own cache  
instance and explicitly setting the shared cache to that new instance.


But it absolutely did work - once implemented, my "set the table view  
cell's image to an image from the net" works nicely (and without it  
scrolling was painful at best).


Glenn Andreas  gandr...@gandreas.com
  wicked fun!
Mad, Bad, and Dangerous to Know

___

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


[iPhone 3.0] crashes in webView:didCommitLoadForFrame:

2009-08-10 Thread Mike Manzano

Hi all,

Quite a few of my beta testers are sending in crash reports where the  
crash is occurring in webView:didCommitLoadForFrame:


Here's the whole stack trace:

0   libobjc.A.dylib 0x30011944 objc_msgSend + 24
1   UIKit   0x30af8900 - 
[UIWebViewWebViewDelegate webView:didCommitLoadForFrame:] + 32

2   CoreFoundation  0x3020ee44 __invoking___ + 68
3   CoreFoundation  0x30262ac7 -[NSInvocation  
invoke] + 115
4   WebCore 0x358a8ed8  
__ZL20HandleDelegateSourcePv + 52
5   CoreFoundation  0x302548f3  
CFRunLoopRunSpecific + 1915
6   CoreFoundation  0x3025416b CFRunLoopRunInMode  
+ 51

7   GraphicsServices0x320452a4 GSEventRunModal + 196
8   UIKit   0x308f037c -[UIApplication  
_run] + 560
9   UIKit   0x308eea94 UIApplicationMain +  
968

10  Newsie  0x20bd main (main.m:15)

It's hard for me to step through this problem in a debugger because it  
is being remotely reported by my beta testers. Can anyone point me to  
what might cause such an error?


Thanks,

Mike
___

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


Re: NSArrayController access between nib files

2009-08-10 Thread Quincey Morris

On Aug 10, 2009, at 11:04, Brian Carmalt wrote:

Let's say I want the combo box to provide the user with auto  
completion on the names of categories in the array controller, and  
if the user types in a category name that does not exist, then they  
will be automatically prompted to create the category. This will not  
work with a popup button.  Will this work? or are there known  
pitfalls I should look out for?


I should create a new array controller in my NewObjectSheet context  
and set it up to use the documents MOC and bind my combo box to this  
new array controller, that is if I can use the NSComboBox like I  
described above.


Nope, it's not going to work. Suppose your document has 4 existing  
categories: "cheese", "fruit", "meat", "bread". Suppose you bind an  
array controller to the array of categories, and you bind a combo  
box's popup list to arrayController.arrangedObjects and you bind the  
combo box's value to arrayController.selection.name.


Now your sheet will open, and the combo box will show one of the  
categories -- let's say "fruit". If you choose a different category --  
let's say "cheese" -- from the popup list, you'll actually change the  
category name. So the document will now have 4 categories named:  
"cheese", "cheese", "meat", "bread". I'm pretty sure that's not what  
you want.


You don't want to bind the combo box to  
arrayController.selection.name. If you really want to use a combo box,  
you'd have to bind it to a "temporary" string property of your sheet  
window controller. Then you'd have quite a bit of extra work to do.  
You'd have to prefill this text field with the correct category string  
at initialization. When ending the sheet, you'd have to examine the  
category string, decide if it was one of the standard ones, and create  
a new one if not. Or perhaps you'd do this when a new string was  
entered, and wait till the sheet ended. Plus you may need to use  
NSComboBox methods to determine which existing category, if any, was  
chosen from the popup list. Plus you might need some validation code.  
Plus you might need some string formatting code (capitalizing or  
uncapitalizing entered category names so that the appearance of all of  
them is consistent). It's doable, but it's a certain amount of work,  
because ...


"A combo box is a kind of text field, not a kind of menu."

___

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


NSURLCache

2009-08-10 Thread Mike Manzano
Has anyone been able to successfully get the URL loading system on  
iPhone to pay attention to custom versions of NSURLCache? It seems to  
me that it's being ignored. More info here:


http://stackoverflow.com/questions/1246420/need-content-in-uiwebview-to-display-quickly

(See the second "answer" on that page).

Just need some sort of clue if I'm doing something wrong or if my  
code's just being ignored.


Thanks,

Mike
___

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


Core Data Table View focus ring truncated or missing upon data selection

2009-08-10 Thread Sean Kline
Hello,
I have and NSView with a Table View that has a Core Data entity behind it.
 There is very odd behavior when I double click on data in the table.
 Depending on the column, either the focus ring is truncated or missing
completely.  It is as if selecting the data selects a white box which
extends beyond the border of the cell.  Has anyone ever seen such behavior?
 Any ideas?  Here is a picture of part of the table:


Thanks,
Sean
___

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


Re: NSArrayController access between nib files

2009-08-10 Thread Brian Carmalt

Sorry to Quincey, I sent the reply to him and not to the list.

Hello Quincey,

Thanks for your answer.


I am trying to figure out how to access a NSArrayController in one  
nib file from another nib. I have done the NSPersistentDocument  
tutorial and I am trying to apply what I have learned.


In general, it's not a great idea. It just makes the two nib files  
more tangled up than they need to be, for no real benefit. It seems  
better to have separate array controllers for different contexts,  
and to bind them to the same data model array if that's what they're  
supposed to show.




Ok, point taken. I'm just starting to learn, and have extended the  
example in the NSPersistentDocument tutorial.


So in my MyDocument.nib there is a array controller I would like to  
bind to a NSComboBox from a NewObjectSheet.nib. I have a  
NewObjectSheetController in MyDocument.nib and the same controller  
is file's owner in the NewObjectSheet. The controller has an outlet  
which points to an array controller which I would like to bind to  
an NSComboBox in the NewObjectSheet.nib.


I don't think you mean what you say here. It sounds like you want to  
bind the combo box to the array controller, not the array controller  
to the combo box.

Yep, I described it backwards.


First I'm not sure if it is possible to bind the  NSComboBox to the  
NewObjectSheetController's outlet to the array controller.
Content would be bound to File's Owner with a model key path of  
self.arrayController
Content Values would be bound to File's Owner with a model key path  
of self.arrayController.arrangedObjects
Value be bound to File's Owner with a model key path of  
self.arrayController.selection.name


Well, all that *would* be fine, though incidentally you don't need  
"self." in any of the bindings. The only time you need to use "self"  
is when the model key path would otherwise be empty and you're  
required to put something there.


Also, you cannot bind anything to an outlet. You only bind to a  
property of an object. As it happens, in many cases, the KVC  
mechanism is happy to treat an instance variable (such as an outlet)  
as if it were a property of the same name, but it's not recommended  
to rely on this any more. Much better to define the properties you  
want in NewObjectSheetController, even if the properties just  
encapsulate the values of instance variables.


However, without knowing anything further about what you're trying  
to achieve, it would almost certainly be wrong to use this set of  
bindings. It looks like you're trying to use the combo box as a kind  
of "chooser" that picks one thing out of an array of things that the  
array controller supplies. IOW, you're expecting a combo box to be a  
kind of menu, but it's not -- it's a kind of text field. You should  
probably be using a NSPopUpButton instead, which *is* a kind of menu.


Let's say I want the combo box to provide the user with auto  
completion on the names of categories in the array controller, and if  
the user types in a category name that does not exist, then they will  
be automatically prompted to create the category. This will not work  
with a popup button. Will this work? or are there known pitfalls I  
should look out for?



If the scenario  above is not possible, what is the best way to set  
this up? Should I set up a new NSArrayController in the  
NewObjectSheet.nib, set its entity to the same entity in the array  
controller I would like to use and then use the  
NewObjectSheetController access to the Document's  
ManagedObjectContext(MOC) and bind the MOC of the array controller  
to the document MOC and then use the bindings in the normal way?


I'm not a big fan of putting window controllers  
(NewObjectSheetController) in a nib file. It means you unnecessarily  
create the window controller every time you open a document, whether  
or not you ever end up using the sheet. It also prevents you from  
communicating document-related state to the window controller's  
initialization, so you may end up inventing a means of communication  
between the document and the window controller that's more  
complicated than just having the document create the window  
controller when it needs it (and you end up preventing the window  
controller and all of its associated resources from being released  
when the sheet is closed).


Ok, that's good to keep in mind. I'm just not that advanced yet. Your  
first sentence in your mail tells me that my second option is the  
better of the two. I should create a new array controller in my  
NewObjectSheet context and set it up to use the documents MOC and bind  
my combo box to this new array controller, that is if I can use the  
NSComboBox like I described above.


Thanks again for your answer.

Brian
___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderato

RE: Cmd+key shortcuts not being sent to NSWindow on Tiger

2009-08-10 Thread Dimcho Balev
Thanks! I will try it out.

Dimcho

-Original Message-
From: cocoa-dev-bounces+dbalev=adobe@lists.apple.com 
[mailto:cocoa-dev-bounces+dbalev=adobe@lists.apple.com] On Behalf Of Kirk 
Swenson
Sent: Friday, August 07, 2009 6:30 PM
To: cocoa-dev@lists.apple.com
Subject: Re: Cmd+key shortcuts not being sent to NSWindow on Tiger


On Aug 7, 2009, at 5:55 PM, Dimcho Balev  wrote:

> I have a trouble with a piece of code which behaves differently  on
> Tiger (Mactel) in comparison to Leopard.
>
> It is pretty simple case: our cocoa app is interested in cmd+key
> shortcuts and we have overriden the keyDown and keyUp methods in our
> NSWindow inherited class. On Leopard we receive all of the key events
> without a problem but on Tiger the standard cmd+key events (cmd+c, cmd
> +v, cmd+x, cmd+a) are filtered out. I tried out few other approaches -
> for instance using flagsChanged to detect the cmd key status but I
> never receive an event for the 2nd key (m,c,v,x, or a) of the  
> shortcut.
>
> I am wondering if this is known issue with Tiger and if there is any
> workaround.

We encountered the same problem. My solution was to implement a  
derived class of NSTextView which overrides the performKeyEquivalent:  
method as follows:

- (BOOL) performKeyEquivalent: (NSEvent*) anEvent
/*
  On Leopard, these command-key equivalents are intercepted before we  
get here,
  with the associated behaviors provided automatically. On Tiger, the  
prior
  intercepts don't occur, and so we implement them here. This  
shouldn't affect
  the behavior on Leopard, since execution never reaches here on  
Leopard.
  */
{
BOOLhandled = NO;
if( ([anEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask)  
== NSCommandKeyMask) {
NSString*   keyChars = [anEvent 
charactersIgnoringModifiers];
BOOLhasSelection = [self selectedRange].length > 0;
handled = YES;
if( [keyChars isEqual: @"a"])
[self selectAll: self];
else if( hasSelection && [keyChars isEqual: @"x"])
[self cut: self];
else if( hasSelection && [keyChars isEqual: @"c"])
[self copy: self];
else if( [keyChars isEqual: @"v"])
[self paste: self];
else
handled = NO;
}
return handled || [super performKeyEquivalent: anEvent];
}

and then in the controller/delegate's  
windowWillReturnFieldEditor:toObject: method, do something like the  
following:

- (id) windowWillReturnFieldEditor: (NSWindow*) aWindow toObject: (id)  
anObject
/*
  Returns the NSTextView to use as the field editor for the specified  
object.
  We override to return our MyTextView when appropriate.
  */
{
// myTextFieldEditor is a member variable, so there will only be one  
of them.
if( myTextFieldEditor == nil) {
myTextFieldEditor = [[MyTextView alloc] init];

// Apple's docs fail to mention the requirement to call this 
method,
// but it apparently isn't called by the client. See the 
discussion at
// http://www.cocoadev.com/index.pl?CreatingCustomFieldEditor 
for  
instance.
// Note, however, that the sample code given there calls 
setDelegate  
in
// addition to setFieldEditor at this point. Doing so is a bad 
idea,  
as it
// interferes with the framework's management of the delegate  
relationship and
// results in improper tabbing behavior in dialogs with 
multiple  
edit fields.
[myTextFieldEditor setFieldEditor: YES];
}
return myTextFieldEditor;
}

There may be a better solution out there, but this seems to work.

Kirk Swenson
Senior Software Engineer
KCP Technologies

___

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/dbalev%40adobe.com

This email sent to dba...@adobe.com
___

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


Re: How can I get the reference to Cancel and Print buttons in Print Dialogue

2009-08-10 Thread David Duncan

On Aug 9, 2009, at 11:20 PM, Siva Manne wrote:

In the Cocoa PDEPlugin, i need to disable/enable Cancel and Print  
Buttons
for some conditions. I am not able to get the reference for those  
buttons.



You can't get references to them. If you want to prevent printing from  
a PDE, then you should implement -shouldPrint and return NO when you  
don't want the user to be allowed to print. You should never disallow  
the user from canceling the dialog (consider them canceling the dialog  
as canceling whatever you are doing).


The OutputBins2PDE sample (the PasswordPDE specifically) demonstrates  
this.


--
David Duncan
Apple DTS Animation and Printing

___

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


Re: Implementing key view loop in custom NSView

2009-08-10 Thread Andreas Eriksson
On Mon, Aug 10, 2009 at 4:05 PM, Andy Lee  wrote:

> On Aug 10, 2009, at 5:43 AM, Andreas Eriksson wrote:
>
>> I am wondering whats the best approach to handle the key view loop in a
>> custom NSView that consists of several sub-views that the user can tab
>> between?
>>
>
> I've used [NSWindow recalculateKeyViewLoop] but my views might have been
> laid out in such a way that this happened to conveniently do what I wanted.
>  Note there's also setAutorecalculatesKeyViewLoop: and a check box in IB.


Interesting, I didn't now the key view loop could be determined
automatically. With
autorecalculatesKeyViewLoop enabled it seems to do what I want. Wish I
knew this yesterday before manually setting up all my
key view loops. Thanks!

Regards,

Andreas
___

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


Re: To get system sounds for Move or Copy operations

2009-08-10 Thread Sean McBride
On 8/7/09 10:38 AM, Shashanka L said:

>Where can I get the system sound for Move/Copy operations?

I don't see anything in the NSSound docs to get that.  It's a good idea
for a feature request though.

>I need to play it in my application when Move or Copy file is done.
>
>
>Ex: I can get the Trash sound at the location  : "/System/Library/
>components/coreaudio.component/contents/Resources/SystemSounds/finder/"
>And I can use it as :
>
>   NSSound *deleteSound;
>   deleteSound  = [NSSound soundNamed: @"drag to trash"];
>   [deleteSound play];

NSSound initWithContentsOfFile:byReference: should do it.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

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


Re: Implementing key view loop in custom NSView

2009-08-10 Thread Andreas Eriksson
Thanks a lot for helping out! That would work, but I would prefer if I
didn't have to expose the subviews. Especially, since those are not
available when I use the custom view in IB.
I tried overriding becomeFirstResponder like

- (BOOL)becomeFirstResponder {
[[self window] makeFirstResponder:firstSubview];
}

which takes care of making the first subview the key view when tabbing to
the parent custom view. I also tried overriding -insertTab: to detect when
trying to tab from the last subview so I could move the key view to the one
after the parent view in the key view loop, but for some reason it never
gets called.

Regards,

Andreas

On Mon, Aug 10, 2009 at 2:34 PM, Keith Blount  wrote:

>
> You should be able to do this with a combination of -becomeFirstResponder,
> -acceptsFirstResponder, -setNextResponder. If B isn't supposed to be the
> first responder at all, then it should return NO for -acceptsFirstResponder
> (but its subviews x and y should return YES).
>
> Then, in the superview that holds A, B and C, you could do something lie
> the following after you have set up the view hierarchy:
>
> [A setNextResponder:[B x]];
> [[B x] setNextResponder:[B y]];
> [[B y] setNextResponder:C];
> [C setNextResponder:A];
>
> (The above assumes that subview B has methods -(NSView *)x and -(NSView *)y
> to return its subviews, of course).
>
> If you're adding the subviews in IB, of course, you could just hook it all
> up there and avoid the code altogether.
>
> All the best,
> Keith
>
> > I am wondering whats the best approach to handle the key view loop in a
> > custom NSView that consists of several sub-views that the user can tab
> > between?
> >
> > Lets say I have three views A, B, and C, all chained up in that order in
> > the key view loop. if B is my custom view consisting of subviews B.x and
> > B.y, then I want the key view to go like A -> B.x -> B.y -> C.
> >
> > My current thinking is to override - (BOOL)becomeFirstResponder to change
> > first responder to B.x when B becomes first responder and to set the next
> > key view of B.y to the next key view of B.
> >
> > Is this how it's supposed to be done?
> >
> > / Andreas
>
>
>
>
___

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


Re: NSData Questions

2009-08-10 Thread Sean McBride
On 8/8/09 5:45 PM, Eric Hermanson said:

>1. Is it more efficient to malloc a uint8_t array and call NSData
>'init no copy', rather than pass in an array allocated with a fixed
>length on the stack to the init method that makes a copy of the bytes?

More efficient according to which metric?  Memory usage?  CPU time?
Code readability?

If you ever want to support garbage collection, I suggest this usage:

- [NSMutableData dataWithCapacity:numBytes];
- mutableBytes to get pointer
- fill with your data

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

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


Re: Trouble with event taps...

2009-08-10 Thread James W. Walker


On Aug 9, 2009, at 3:15 PM, Nat Burke wrote:

  I have posted my event tap creation code below - I've searched all  
over
the mailing list and the net to see if I could find a solution, but  
I am

genuinely stuck. Any help is greatly appreciated!


  // Create an event tap.
  eventMask = CGEventMaskBit(kCGEventRightMouseDown) |
  CGEventMaskBit(kCGEventRightMouseUp)   |
  CGEventMaskBit(kCGEventRightMouseDragged) |
  CGEventMaskBit(kCGEventMouseMoved) |
  CGEventMaskBit(kCGEventScrollWheel)|
  CGEventMaskBit(kCGEventFlagsChanged) |
  CGEventMaskBit(kCGEventKeyDown) |
  CGEventMaskBit(kCGEventKeyUp);

  DebugLog(@"Event before: %x", eventMask);

  eventTap = CGEventTapCreate(kCGSessionEventTap,  
kCGHeadInsertEventTap,

kCGEventTapOptionDefault, eventMask, MouseCallback, self);

  DebugLog(@"Event after: %x", eventMask);

  if (!eventTap) {
 fprintf(stderr, "Failed to create event tap\n");
 exit(1);
  }

  // Create a run loop source.
  runLoopSource =
CFMachPortCreateRunLoopSource(/*kCFAllocatorDefault*/NULL, eventTap,  
0);


  CFRelease(eventTap);

  // Add to the current run loop.
  CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],
runLoopSource, kCFRunLoopCommonModes);

  // Enable the event tap.
  CGEventTapEnable(eventTap, true);

  CFRelease(runLoopSource);



I compared your code to the code that I use that gets key down  
successfully.  One difference is that I don't immediately CFRelease  
the event tap and source, I keep them around as long as I use the  
tap.  Another is that the first 2 parameters I pass to  
CGEventTapCreate are kCGAnnotatedSessionEventTap and  
kCGTailAppendEventTap.



___

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


Disabled controls don't update their visual appearance

2009-08-10 Thread Christopher Campbell Jensen

Hi,

I am sure I am just missing a single line of code, but I can't  
understand the following behavior:

This code is where the issue occours:
- (void)refreshButtonsEnabledState
{
	NSLog(@"%d", [[[tabView selectedTabViewItem] label]  
isEqualToString:@"Current/Custom"] && [movieFile.movieMetaData  
isCreated]);
	[toggleWriteCheckMarksButton setEnabled:[[[tabView  
selectedTabViewItem] label] isEqualToString:@"Current/Custom"] &&  
[movieFile.movieMetaData isCreated]];

[resetMetaDataButton setEnabled:[movieFile.movieMetaData isCreated]];
}

Now I am sure some of you might think this looks horrible, and it  
probably is. This is my first cocoa project, and I started out with  
the best intentions, but it has now unfortunately degraded to 'lets  
just get it to work' rather then following good design principles :(


Anyway, to help show what the problem is, I have made a screen  
recording showing the interface, the button in question and the  
console where you can observe the NSLog statement above being executed.

Screen recording: http://xrl.us/be9c6a

The button in question is the one labeled "Toggle" (the middle of the  
middle three), and really the one to the right of it labeled "Reset".  
The desired behavior is for these to be disabled as long as there is  
no files selected or loaded (entry in the right hand NSTableView),  
when a file is selected the movieFile variable is set to the file, and  
it's movieMetaData is created. When no file is selected, movieFile is  
set to nil. When the second tab is selected, "Toggle" should disable  
while "Reset" stays enabled. Once the file is removed (ie no files in  
the NSTableView) both buttons should disable, and it is this that  
fails. From the console, I can see that the method  
"refreshButtonsEnabledState" gets called and detects the right set of  
states (ie disable buttons; at least we know for sure that the  
"Toggle" one should disable) but this does not happen until I (I am  
guessing) force the window/view to refresh by selecting the other tab.


I have tried adding both:
[[[self window] view] setNeedsDisplay:YES];
or
[toggleWriteCheckMarksButton setNeedsDisplay:YES];

to the end of the "refreshButtonsEnabledState" method, but no dice.
I am sure I am doing all of this WAY too manual, and that there are  
all kinds of bindings I could use to accomplish this, but after  
struggling with bindings for a while now, I have opted to do more  
stuff manually. As this is a small bug, and I will probably be the  
only one to ever use this app, it's a small issue, but an annoyance  
even so.
I would love for someone to explain either what I am doing wrong, or  
what to add to fix the issue.


Thanks for your time,
Chris
___

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


Re: How to find active user in the cocoa

2009-08-10 Thread Erik Buck
http://developer.apple.com/qa/qa2001/qa1133.html answers your question 
perfectly.

That was the first hit when I typed "console user" into the search field at 
developer.apple.com
___

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


Re: How to find active user in the cocoa

2009-08-10 Thread Greg Guerin

Arun wrote:

Is there any way in cocoa to find who is active user if multiple  
users have

logged in.



Read the man page for getuid.  It's a C function and applies to the  
current process.


You can call C functions in Objective-C, and Cocoa has any number of  
C functions that developers use regularly.  For example, see NSLog().


  -- G
___

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


Re: How to find active user in the cocoa

2009-08-10 Thread Dave DeLong
That's a great point, and one that I failed to mention.  However, that  
is pretty clear in the CSCopyUserName documentation.  =)


One less-than-elegant way to find the logged in user might be to run  
"ps" and pipe the results through "grep 'Finder'".


Dave

On Aug 10, 2009, at 9:03 AM, Michael Gozzo wrote:


Hi Arun,

You should note that these three methods will give you the username
under which your application is currently executing. This is not
necessarily the "active user" in the case originally described.

A fourth item to add to this list is the NSUserName() function. The
documentation specifies that "NSUserName returns the logon name of the
current user." though I haven't used the function and am not sure
whether or not "current user" refers to the user in the active desktop
session or who is running the executable that calls NSUserName. (I
suspect the latter, but I'm not completely certain).

Michael



On Mon, Aug 10, 2009 at 10:44 AM, Dave DeLong  
wrote:

You can do this in a number of ways.

1.  Run an NSTask that executes "who am i"
2.  Use NSString to resolve ~/ and pull out the second path component
3.  Use CoreService's CSCopyUserName

And probably a host of others.  These are the couple I thought of  
off the

top of my head.

HTH,

Dave

___

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


Re: How to find active user in the cocoa

2009-08-10 Thread Dave DeLong

You can do this in a number of ways.

1.  Run an NSTask that executes "who am i"
2.  Use NSString to resolve ~/ and pull out the second path component
3.  Use CoreService's CSCopyUserName

And probably a host of others.  These are the couple I thought of off  
the top of my head.


HTH,

Dave

On Aug 10, 2009, at 8:38 AM, Arun wrote:


Hi All,

Is there any way in cocoa to find who is active user if multiple  
users have

logged in.

Thanks
Arun

___

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


How to find active user in the cocoa

2009-08-10 Thread Arun
Hi All,

Is there any way in cocoa to find who is active user if multiple users have
logged in.

Thanks
Arun
___

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


Re: Implementing key view loop in custom NSView

2009-08-10 Thread Andy Lee

On Aug 10, 2009, at 5:43 AM, Andreas Eriksson wrote:
I am wondering whats the best approach to handle the key view loop  
in a

custom NSView that consists of several sub-views that the user can tab
between?


I've used [NSWindow recalculateKeyViewLoop] but my views might have  
been laid out in such a way that this happened to conveniently do what  
I wanted.  Note there's also setAutorecalculatesKeyViewLoop: and a  
check box in IB.


--Andy

___

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


Re: NSOperationQueue question

2009-08-10 Thread Tim Murison
> The first thing it should do in main() is invoke
> objc_startCollectorThread() (from ) which will
> ensure GC is happening asynchronously, rather than only when the
> autorelease pool is drained.

Thank you.
I added the call to objc_startCollectorThread() and my simple sample no
longer leaks memory.



***

This e-mail and its attachments are confidential, legally privileged, may be 
subject to copyright and sent solely for the attention of the addressee(s).
Any unauthorized use or disclosure is prohibited. Statements and opinions 
expressed in this e-mail may not represent those of Radialpoint.

Le contenu de ce courriel est confidentiel, privilégié et peut être soumis à 
des droits d'auteur. Il est envoyé à l'intention exclusive de son ou de ses
destinataires. Il est interdit de l'utiliser ou de le divulguer sans 
autorisation. Les opinions exprimées dans le présent courriel peuvent diverger 
de celles de Radialpoint.
___

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


Re: Maintaining an ordered array of attributes in an NSTextStorage subclass

2009-08-10 Thread Graham Cox


On 10/08/2009, at 11:21 PM, Keith Blount wrote:

Thanks for the reply. I guess I lost the point in my long, rambling  
e-mail, so sorry about that. What I really meant to ask is *how* to  
maintain this list accurately. Given that the attribute can be  
added, removed, text can be copied and pasted, a range of text that  
has a comment associated with it might be cut in half and so on,  
what is the best approach for keeping this list updated as the text  
changes?



Ah, my bad - I guess the clue was in your message title ;-)

In theory, code is supposed to call beginEdiing/endEditing around any  
operation that edits the text so that might be one place you could  
override to handle this. Other methods in NSMutableAttributedString  
may need to be overridden to get information about affected ranges.  
There are only two primitive methods, according to the docs:


- (void)replaceCharactersInRange:(NSRange)aRange withString:(NSString  
*)aString


- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)aRange

So those two should provide all the hooks you'd need. If your  
auxiliary array is kept sorted by range position it should be easy and  
efficient to locate the relevant entries affected by an edit in a  
given range. Ideally you'd want to manage the comments such that the  
text storage does all the hard work of maintaining the attribute runs/ 
ranges, and all you have to do is to add and delete comments in your  
array as necessary.


Still a bit vague, but might help with the inspiration...

--Graham


___

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


Re: Adjusting UIAlertView position

2009-08-10 Thread Luke the Hiesterman
There is no public way to add a text field to an alert, so you're  
already talking about doing non-sanctioned things. You should redesign  
your application to remove this text field to avoid violating the SDK  
Terms and Conditions and risk having your application rejected.


Luke

On Aug 10, 2009, at 2:05 AM, Mahaboob wrote:

I added one UITextField to UIAlertView. When I'm clicking on this  
text field
the keyboard is comes out and thus it hides the buttons in the alert  
view.

So I need to adjust the position of the alert view.

How can I do it?

I tried with setFrame: method but, nothing happens to alertview.  
Then I
tried with setBounds: then the contents in the alert view is moving  
to the
new posiotion but, the alert view frame is remains in the same  
position.


Thanks in advance
mahaboob




___

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/luketheh%40apple.com

This email sent to luket...@apple.com


___

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


Re: Outline View DnD

2009-08-10 Thread bryscomat
Thank you. I've gotten some code together that seems to do what I want  
based on that method.


On Aug 8, 2009, at 11:48 AM, Nathan Vander Wilt wrote:


On Aug 7, 2009, at 6:56 AM, bryscomat wrote:
... Now the dilemma comes when I want to get the drag and drop to  
work in a specific way. I want the playlists to be able to be  
dragged and placed in any order, but not above the separator. I  
have achieved this using the delegate method validateDrop: and  
returning DragOperationNone if the proposed child index is less  
than the index of the separator. However, I also want a user to be  
able to drag the items in the Singers group around in any order as  
well, and this doesn't allow that. I found that if in validateDrop:  
I check if the item is a singer and that the parent item is the  
singers group to allow it that it works for that. How do I get both  
of these to happen? If anyone could just point me in the right  
direction I'll take it from there.


Take a look at the -[NSOutlineView setDropItem:dropChildIndex:]  
method. You can call it from your validateDrop method to change the  
proposedItem and proposedChildIndex if they are not appropriate.


hth,
-natevw
___

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/bryscomat%40gmail.com

This email sent to brysco...@gmail.com


___

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


Re: Maintaining an ordered array of attributes in an NSTextStorage subclass

2009-08-10 Thread Keith Blount

Hi Graham,

Thanks for the reply. I guess I lost the point in my long, rambling e-mail, so 
sorry about that. What I really meant to ask is *how* to maintain this list 
accurately. Given that the attribute can be added, removed, text can be copied 
and pasted, a range of text that has a comment associated with it might be cut 
in half and so on, what is the best approach for keeping this list updated as 
the text changes?

Thanks again and all the best,
Keith

--- On Mon, 8/10/09, Graham Cox  wrote:

> From: Graham Cox 
> Subject: Re: Maintaining an ordered array of attributes in an NSTextStorage 
> subclass
> To: "Keith Blount" 
> Cc: cocoa-dev@lists.apple.com
> Date: Monday, August 10, 2009, 1:03 PM
> 
> On 10/08/2009, at 10:55 PM, Keith Blount wrote:
> 
> > does anyone have any better ideas as to how I might
> approach this?
> 
> 
> Don't know if "better", but why not just maintain the list
> you need yourself? You could either subclass NSTextStorage
> and add a comment array, or make another object that
> comprised NStextStorage plus the comments array, whichever
> works best for you.
> 
> --Graham
> 
> 
> 


  
___

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


Re: Maintaining an ordered array of attributes in an NSTextStorage subclass

2009-08-10 Thread Graham Cox


On 10/08/2009, at 10:55 PM, Keith Blount wrote:


does anyone have any better ideas as to how I might approach this?



Don't know if "better", but why not just maintain the list you need  
yourself? You could either subclass NSTextStorage and add a comment  
array, or make another object that comprised NStextStorage plus the  
comments array, whichever works best for you.


--Graham


___

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


Maintaining an ordered array of attributes in an NSTextStorage subclass

2009-08-10 Thread Keith Blount

Hello,

I'm trying to implement comments in an NSTextStorage subclass. The 
implementation of comments themselves is pretty simple:

- I have a KBCommentsAttributeName custom attribute that gets assigned to 
ranges of text in my controller using the -addAttribute:value:range: methods.
- This attribute gets assigned a dictionary containing an attributed string 
(the comment) and a unique ID (because NSAttributedString optimises things by 
merging attributes that are the same, and I want to avoid this).

So, for instance, a comment might be assigned in my controller like this:

- (void)addComment:(id)sender
{
if ([textView shouldChangeTextInRange:[textView 
rangeForUserAttributeChange] replacementString:nil])
{
NSDictionary *commentDict = [NSDictionary 
dictionaryWithObjectsAndKeys:[commentsTextView textStorage], @"Comment", 
uniqueID, @ID", nil];
[[textView textStorage] addAttribute:KBCommentAttributeName 
value:commentDict range:[textView rangeForUserAttributeChange];
[textView didChangeText];
}
}

(The above just typed in my browser as an example.)

This is all fine. However, what I would like to do is have the text storage to 
which this attribute is assigned maintain an ordered array of the comments that 
get assigned. In other words, my NSTextStorage subclass should have a method,

- (NSMutableArray *)comments;

which returns all of the comment objects (dictionary objects in the example 
above) that are in the text, in the order they appear.

(The reason I want this is so that I can then show all of the comments in a 
separate view.)

Obviously, I could just get all of the comments associated with the text 
dynamically using the attribute-searching methods such as 
-attribute:atIndex:range:effectiveRange: etc, but this doesn't suit my purpose. 
My comments-showing view needs to be notified whenever the comment ranges 
change or whenever a comment is deleted or added; calling the -attribute: 
searching methods on the entire text every time the text is changed would be 
way too slow.

One thought I had was to create a -fixCommentsInRange: method and call it from 
-fixAttributesInRange:, but fixing up the comments ranges is fundamentally 
different from the other attribute fixing methods (such as fixParagraph... or 
fixFontAttribute...), because the other attributes-fixing methods don't need to 
know about the rest of the text and only need to scan over the current 
paragraph at most. To ensure that my -comments mutable array contained all of 
the comments in the text, it would pretty much have to search through all of 
the text from the beginning of the range passed into -fixCommentsInRange: to 
the end of the text, which would be too slow. (Because calling something from 
-fixAttributesInRange: would give us no information about whether a comment has 
just been deleted or added; it will only tell us what is at the range at the 
moment.)

My current thinking is that the best way of doing this will be to handle it in 
NSTextStorage overrides for -addAttribute:value:range:, -setAttributes:range:, 
and -removeAttribute:..., where I can check if the attribute is being removed 
or added, but even then it gets a little complicated in trying to account for 
copying and pasting and so forth.

Has anyone handled anything like this, or does anyone have any better ideas as 
to how I might approach this? As I say, the aim is to maintain a list of the 
comment attributes in the text just so that I can display the comments, in 
order, in a custom view that will keep updated with the text.

Many thanks in advance and all the best,
Keith


  
___

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


Re: [NSObject setValue:forUndefinedKey:] no longer requires explicit KVC notifications?

2009-08-10 Thread Gabriele de Simone


The KVC infrastructure did not always generate value-changed  
notifications for setValue:forUndefinedKey: overrides.


The setValue:forUndefinedKey: override should have nothing to do  
with it.  It's the setValue:forKey: call -- the one which provokes  
the call to setValue:forUndefinedKey: -- that's responsible for  
triggering the KVO change notifications.


Doubting my own sanity (always a good approach, IMO) I searched  
for, and found some evidence of this in an old discussion:


http://www.cocoabuilder.com/archive/message/cocoa/2006/10/12/172593


That thread doesn't confirm what you're saying.  It says the  
opposite.  It says what I just said.  If you override  
setValue:foKey: _then_ you lose automatic KVO notifications and  
would have to reimplement them yourself, but if you just override  
setValue:forUndefinedKey: you don't have that problem.


Indeed! I feel like a jackass, thanks for catching this :-)

Gabe
___

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


Re: Implementing key view loop in custom NSView

2009-08-10 Thread Keith Blount

You should be able to do this with a combination of -becomeFirstResponder, 
-acceptsFirstResponder, -setNextResponder. If B isn't supposed to be the first 
responder at all, then it should return NO for -acceptsFirstResponder (but its 
subviews x and y should return YES).

Then, in the superview that holds A, B and C, you could do something lie the 
following after you have set up the view hierarchy:

[A setNextResponder:[B x]];
[[B x] setNextResponder:[B y]];
[[B y] setNextResponder:C];
[C setNextResponder:A];

(The above assumes that subview B has methods -(NSView *)x and -(NSView *)y to 
return its subviews, of course).

If you're adding the subviews in IB, of course, you could just hook it all up 
there and avoid the code altogether.

All the best,
Keith

> I am wondering whats the best approach to handle the key view loop in a
> custom NSView that consists of several sub-views that the user can tab
> between?
> 
> Lets say I have three views A, B, and C, all chained up in that order in
> the key view loop. if B is my custom view consisting of subviews B.x and
> B.y, then I want the key view to go like A -> B.x -> B.y -> C.
>
> My current thinking is to override - (BOOL)becomeFirstResponder to change
> first responder to B.x when B becomes first responder and to set the next
> key view of B.y to the next key view of B.
>
> Is this how it's supposed to be done?
>
> / Andreas


  
___

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


Re: Testing if a NSPipe has available data

2009-08-10 Thread Alastair Houghton

On 10 Aug 2009, at 12:28, Frédéric Testuz wrote:


Le 10 août 09 à 12:40, Alastair Houghton a écrit :

So what's wrong with waiting for -[NSFileHandle availableData] to  
return with zero bytes?


First : if you call availableData and there is no data and the end  
of file is not reached, you are blocking your thread.


Only if (a) there is no data available and (b) you are dealing with a  
communications link.


If I understand correctly, gnuplot don't send the end of file  
because you can send new command to the same plot.


Ah, OK, I assume in that case that you want to keep gnuplot running so  
that you can plot something else afterwards?


In that case, the cleanest approach is probably going to be to tell  
gnuplot to send the data somewhere other than stdout (using "set  
output").  The simplest thing would be to use a temporary file.


If you can live with invoking gnuplot separately every time, you could  
just tell it to quit after generating the data that you want.


So the only way I can see is to check if there still data waiting in  
the file handle buffer before calling readInBackgroundAndNotify or  
availableData.


That won't work in the general case; gnuplot might generate some data,  
then your app might run and take it all, in which case there would be  
no data waiting in the buffer... but gnuplot might not have finished  
and might subsequently generate more data.


Kind regards,

Alastair.

--
http://alastairs-place.net



___

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


Re: Making an NSOutlineView by Default have 1 Parent and 1 Child.

2009-08-10 Thread Volker in Lists

Hi,

on startup check if you have already data in your data container. If  
no - create data accordingly to your needs so it is displayed in the  
outlineview.


You might consider phrasing your question differently, and describe  
what you have tried already. It would make helping you more easy.


Cheers,
Volker


Am 10.08.2009 um 12:45 schrieb Joshua Garnham:

What I am trying to do is that when my App is first opened the  
NSOutlineView will already have A Parent and A Child, the child  
being inside the parent, like in this picture, http://www.grabup.com/uploads/7490ffebda697ef976c3d6a3b57323ba.png 
.


What code would I need to do this?

Thanks,
Josh.




___

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/volker_lists%40ecoobs.de

This email sent to volker_li...@ecoobs.de


___

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


Re: [iPhone 3.0; XCode 3.1.3] Question about when views are available for manipulation.

2009-08-10 Thread Brian Bruinewoud

I found the motivating example for this thread.

Files are:
http://media.pragprog.com/titles/amiphd/code/FileIO/FilesystemExplorer/Classes/DirectoryViewController.m
http://media.pragprog.com/titles/amiphd/code/FileIO/FilesystemExplorer/Classes/FileOverviewViewController.m

For this book:
http://books.pragprog.com/titles/amiphd/iphone-sdk-development

The methods of significance are as follows:
In DirectoryViewController's tableView:didSelectRowAtIndexPath: the  
code creates a new FileOverviewViewController and sets its filePath  
property.
In FileOverviewViewController's setFilePath: method, the code calls  
[self updateFileOverview]
In FileOverviewViewController's updateFileOverview, the code updates  
GUI elements (UILabel.text)


Is this all ok? Going on the previous discussion, I don't think so  
(and I hope I'm right).


To fix, it would be sufficient to remove [self updateFileOverview]  
from setFilePath and put it in viewWillAppear. Right?


I already raised a bug against the book for other elements of  
setFilePath being incorrect/non-idiomatic, looks like there might be  
another...


Please confirm or clarify my understandings,
Thanks,
Brian.
___

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


Re: [iPhone 3.0; XCode 3.1.3] Question about when views are available for manipulation.

2009-08-10 Thread Brian Bruinewoud

All,

Thanks for the responses so far. I'm getting there.

If I may quote Henry McGilton (Boulevardier) out of order:

On 10/08/2009, at 15:02 , Henry McGilton (Boulevardier) wrote:

Similar situation with the call to makeKeyAndVisible - I've seen  
samples of applicationDidFinishLaunching where makeKeyAndVisible is  
called and then set up is done to the main window's view.


I (and I am sure many others) would be highly interested to see  
these sample codes to which
you refer.In general, if you make the window visible first and  
then load up your initial screen
and add it to the window, the user will see a (possibly unpleasant)  
'flash' as the new stuff is added.
A more user-friendly approach is to (quickly) load the initial UI,  
add it to the window, and then

display the window.


It is not an Apple example.

Example: 
http://media.pragprog.com/titles/amiphd/code/FileIO/FilesystemExplorer/Classes/FilesystemExplorerAppDelegate.m
For this book: http://books.pragprog.com/titles/amiphd/iphone-sdk-development

But I agree with you that it could cause a flash of invalid data/ 
layout, followed by the correct data/layout.
So, is the above example broken? Note that the property directoryPath  
has an explicit setDirectoryPath method that can be seen here:

http://media.pragprog.com/titles/amiphd/code/FileIO/FilesystemExplorer/Classes/DirectoryViewController.m

So, I have one last question about what you said here:

In the first simple alloc-init style, the design assumption is that  
the View Controller will fabricate
its managed view 'manually' *when the View Controller is asked to do  
so* by referencing its view property.


In the second, initWithNibName style, the design assumption is that   
initWithNibName tells
the newly allocated View Controller the name of the NIB that it  
*will* load (in the future)
*when the View Controller is asked to do so* by referencing its view  
property.


In the normal course of events, when is the View Controller asked to  
fabricate its managed view?


- (IBAction) readFileContents {
FileContentsViewController *fileContentsViewController =
[[FileContentsViewController alloc]
initWithNibName: @"FileContentsView"
bundle:nil];
fileContentsViewController.filePath = filePath;
	fileContentsViewController.title = [NSString stringWithFormat: @"%@  
contents",

[filePath lastPathComponent]];
[[self navigationController] pushViewController:
fileContentsViewController animated:YES];
[fileContentsViewController release];
}

Thanks for all your help.
___

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


Re: Testing if a NSPipe has available data

2009-08-10 Thread Frédéric Testuz

Le 10 août 09 à 12:40, Alastair Houghton a écrit :


On 10 Aug 2009, at 09:29, Frédéric Testuz wrote:

I'm using gnuplot to obtain graph of data. You can set gnuplot to  
send results in various formats and to stdout

I found the way to call it and get the data with NSTask and NSPipe.

Actually, I get the image as an eps. The whole pack of data come in  
several packs obtain by the pair of methods -[NSFileHandle  
readInBackgroundAndNotify] and -[NSFileHandle availableData].


But I have to know when there is no more data to wait for. I have  
found a solution in :
 which use ioctl. This solution works, but it is a  
very low api and the message is a little old now.


I just want to know if there is, today, another solution with a  
higher api perhaps ?


From the documentation:

 availableData

 Returns the data available through the receiver.

 [snip]

 ... Returns an empty data object if the end of file is reached. ...

So what's wrong with waiting for -[NSFileHandle availableData] to  
return with zero bytes?


First : if you call availableData and there is no data and the end of  
file is not reached, you are blocking your thread.


If I understand correctly, gnuplot don't send the end of file because  
you can send new command to the same plot. And if an end of file was  
sent, stdout would not be closed ? But if it's not the case I don't  
think it makes a difference :


I observe the file handle for the data available notification
I call readInBackgroundAndNotify
My notification method is then called, inside it I call availableData  
to read the data


It will be enough if all the data can be read in 1 time, because of  
buffer, I think, the data come in several chunks. So in my  
notification method I call readInBackgroundAndNotify again.


Now if I call readInBackgroundAndNotify and I have collected all the  
data, I'm waiting for nothing. I can't inspect the data because there  
is nothing in the EPS format to tell you that you are at the end of  
the plot data (other than the end of the file). So the only way I can  
see is to check if there still data waiting in the file handle buffer  
before calling readInBackgroundAndNotify or availableData.


Frédéric

___

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


Making an NSOutlineView by Default have 1 Parent and 1 Child.

2009-08-10 Thread Joshua Garnham
What I am trying to do is that when my App is first opened the NSOutlineView 
will already have A Parent and A Child, the child being inside the parent, like 
in this picture, 
http://www.grabup.com/uploads/7490ffebda697ef976c3d6a3b57323ba.png.

What code would I need to do this?

Thanks,
Josh.




___

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


Re: Testing if a NSPipe has available data

2009-08-10 Thread Alastair Houghton

On 10 Aug 2009, at 09:29, Frédéric Testuz wrote:

I'm using gnuplot to obtain graph of data. You can set gnuplot to  
send results in various formats and to stdout

I found the way to call it and get the data with NSTask and NSPipe.

Actually, I get the image as an eps. The whole pack of data come in  
several packs obtain by the pair of methods -[NSFileHandle  
readInBackgroundAndNotify] and -[NSFileHandle availableData].


But I have to know when there is no more data to wait for. I have  
found a solution in :
  
which use ioctl. This solution works, but it is a very low api and  
the message is a little old now.


I just want to know if there is, today, another solution with a  
higher api perhaps ?


From the documentation:

  availableData

  Returns the data available through the receiver.

  [snip]

  ... Returns an empty data object if the end of file is reached. ...

So what's wrong with waiting for -[NSFileHandle availableData] to  
return with zero bytes?


Kind regards,

Alastair.

--
http://alastairs-place.net



___

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


Implementing key view loop in custom NSView

2009-08-10 Thread Andreas Eriksson
I am wondering whats the best approach to handle the key view loop in a
custom NSView that consists of several sub-views that the user can tab
between?

Lets say I have three views A, B, and C, all chained up in that order in the
key view loop. if B is my custom view consisting of subviews B.x and B.y,
then I want the key view to go like A -> B.x -> B.y -> C.

My current thinking is to override - (BOOL)becomeFirstResponder to change
first responder to B.x when B becomes first responder and to set the next
key view of B.y to the next key view of B.

Is this how it's supposed to be done?

/ Andreas
___

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


Adjusting UIAlertView position

2009-08-10 Thread Mahaboob
I added one UITextField to UIAlertView. When I'm clicking on this text field
the keyboard is comes out and thus it hides the buttons in the alert view.
So I need to adjust the position of the alert view.

How can I do it?

I tried with setFrame: method but, nothing happens to alertview. Then I
tried with setBounds: then the contents in the alert view is moving to the
new posiotion but, the alert view frame is remains in the same position.

Thanks in advance
mahaboob




___

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


Testing if a NSPipe has available data

2009-08-10 Thread Frédéric Testuz

Hi,


I'm using gnuplot to obtain graph of data. You can set gnuplot to send  
results in various formats and to stdout

I found the way to call it and get the data with NSTask and NSPipe.

Actually, I get the image as an eps. The whole pack of data come in  
several packs obtain by the pair of methods -[NSFileHandle  
readInBackgroundAndNotify] and -[NSFileHandle availableData].


But I have to know when there is no more data to wait for. I have  
found a solution in :
  
which use ioctl. This solution works, but it is a very low api and the  
message is a little old now.


I just want to know if there is, today, another solution with a higher  
api perhaps ?


Thank you

Frédéric___

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


Re: Trouble with event taps...

2009-08-10 Thread Dave Keck
> also show that no bits in the eventMask are cleared away.  Also, I do have
> 'Enable Assistive Devices' checked (or else I wouldn't even get the mouse
> events I'd imagine), so I don't think thats the problem.

I seem to remember a discrepancy between the documentation on event
taps, and what actually happens. Try running your code as root and see
if that helps.
___

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