Avoid smooth scrolling when scrolling programmatically
I need to set the scroll position of my NSScrollView programmatically, and I don't want it to scroll smoothly (if the user's "smooth scrolling" preference is on). I can't find a way how to do that. Calling scrollPoint: on my document view results in smooth scrolling. I thought that removing the scroll view from its superview before and adding it back afterwards would prevent this, but it doesn't. I also tried calling setBoundsOrigin: on the content view instead, but it also results in an animation (although only sometimes, and in different cases than with scrollPoint; I haven't been able to figure out the details yet). I guess I could mess with NSUserDefaults, turning off smooth scrolling before calling scrollPoint and restoring it to what it was before afterwards, but this seems like a hack to me. Any other ideas? -- Stefan Haller Berlin, Germany http://www.haller-berlin.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
how to get baseline info
I have a subclass of NSTextView which does: - (void)setUpData { [ [ self textStorage ] setAttributedString: someAttributedString ]; // uses self.usedFont NSLayoutManager *layoutManager = [ self layoutManager ]; baselineOffset = [ layoutManager defaultBaselineOffsetForFont: self.usedFont ]; lineHeight = [ layoutManager defaultLineHeightForFont: self.usedFont ]; } - (void)drawRect:(NSRect)dirtyRect { [ super drawRect: dirtyRect ]; for( NSUInteger line = 0; line < NBR_OF_LINES; line++ ) { CGFloat bax = lineHeight * line + baselineOffset; [ [ NSColor blueColor ] set ]; // base line [ NSBezierPath strokeLineFromPoint:NSMakePoint( NSMinX(dirtyRect), bax ) toPoint: NSMakePoint( NSMaxX(dirtyRect), bax ) ]; }; } This works, because currently all lines use the same font. But how would I handle the more general case, where each line might contain several and/or different fonts? Kind regards, Gerriet. ___ 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
NSScanner to find multiple occurrences of a prefix?
Hi all, I am trying to use NSScanner to change camel cased strings into underscore delimited strings, e.g featuredListingId to featured_listing_id I have worked our how to use NSScanner to achieve this, consider my implementation (implemented as a NSString category) - (NSString *) delimiterSeparatedWords { NSScanner *scanner = [NSScanner scannerWithString:self]; NSString *prefix = nil; NSString *suffix = nil; [scanner scanCharactersFromSet:[NSCharacterSet lowercaseLetterCharacterSet] intoString:&prefix]; [scanner scanCharactersFromSet:[NSCharacterSet letterCharacterSet] intoString:&suffix]; NSString *fieldNameString = [NSString stringWithFormat:@"%@_%@", prefix, [suffix lowercaseString]]; return fieldNameString; } obviously it only addresses the first occurrence of a capital letter. Can I ask NSScanner to keep looking for multiple occurrences? Thanks for your time. ___ 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: NSScanner to find multiple occurrences of a prefix?
On 2011 Sep 12, at 07:01, Devraj Mukherjee wrote: > Can I ask NSScanner to keep looking for multiple occurrences? Use something like while (![scanner isAtEnd]) { // your code } And be careful to consider all possibilities so you can't get an infinite loop.___ 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
Problem with NSAppleScript execution
Hi list, I'm trying to run a simple Apple script, that gets the text from the frontmost application. Basically it simulates cmd+c click. It checks whether the clipboard is empty and if it is, it simulates the cmd+a and then cmd+c again. It doesn't work consistently. Sometimes it works and sometimes - doesn't. The interesting thing is that it doesn't return any error. Like the script runs and even returns a descriptor, but I see the data is 0 bytes there. Same script in the ScriptEditor btw works just fine :( Did somebody bump into such a thing before? Here is the code, which I use: NSString *scriptStr = @"set the clipboard to \"\"\n" "tell application \"System Events\" to keystroke \"c\" using command down\n" "delay 0.1\n" "set selected_text to (the clipboard as text)\n" "if length of selected_text = 0 then\n" "tell application \"System Events\" to keystroke \"a\" using command down\n" "delay 0.1\n" "tell application \"System Events\" to keystroke \"c\" using command down\n" "delay 0.1\n" "end if\n" "set selected_text to (the clipboard as text)\n" "return selected_text"; appleScript = [[NSAppleScript alloc] initWithSource:scriptStr]; NSLog(@"appleScript = %@", appleScript.source); NSString *returnString = nil; @try returnDescriptor = [appleScript executeAndReturnError:&errors]; if (errors) { NSArray *all = [errors allValues]; for (int i = 0; i < [all count]; i++) NSLog(@"ERROR ** %@\n", (NSString *)[all objectAtIndex:i]); } if (returnDescriptor != NULL) { if (kAENullEvent != [returnDescriptor descriptorType]) { if (cAEList != [returnDescriptor descriptorType]){ NSData *aData = [returnDescriptor data]; if (aData && [aData length] != 0) { returnString = [[[NSString alloc] initWithCharacters:[aData bytes] length:[aData length]/2] autorelease]; } } } else { NSLog(@"%@", @"Couldn't process AppleScript"); } } NSLog(@"copied string = %@", returnString); } @catch (NSException * e) { NSLog(@"exception = %@", [e description]); } return returnString; The returnDescriptor isn't NULL, but has 0 bytes of data. It's like something doesn't work there and the script isn't performed. More than that, when I run same script from Script editor, it works perfect. Is it a known problem or do I do something wrong? Thanks, Nava Nava Carmon ncar...@mac.com "Think good and it will be good!" ___ 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
iPad store ?
This may be off-topic but I am not sure of the right forum. Is there any way to deploy an iPad app other then the AppStore? I don't mean for development testing or other temporary purposes. Situation is the development of an application for a particular customer who would use the app for specific in-house purposes. The app would not be generally available, at least that is the intent. Thanks for any comments or directions to a more suitable list. Phil Sent from my iPad ___ 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: iPad store ?
There's an Enterprise program meant for internal deployments. http://developer.apple.com/programs/ios/enterprise/ On Sep 12, 2011, at 10:04 AM, Phil Hystad wrote: > Is there any way to deploy an iPad app other then the AppStore? I don't mean > for development testing or other temporary purposes. > > Situation is the development of an application for a particular customer who > would use the app for specific in-house purposes. The app would not be > generally available, at least that is the intent. ___ 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
What is last number at end of crash log line?
hi- What does the 98 at the end of this line mean:? 8 com.apple.CoreFoundation0x7fff90662d32 -[NSMutableArray removeObjectsInRange:] + 98 … all the tech notes I can find explains everything else, but neglects describing that last number (as if it is not there) … thanks!- -lance ___ 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: What is last number at end of crash log line?
On Sep 12, 2011, at 10:27 AM, lbland wrote: > What does the 98 at the end of this line mean:? > > 8 com.apple.CoreFoundation 0x7fff90662d32 -[NSMutableArray > removeObjectsInRange:] + 98 > > > … all the tech notes I can find explains everything else, but neglects > describing that last number (as if it is not there) … Byte offset into the symbol. I.e. that means that the backtrace is at the instruction 98 bytes from the beginning of that particular method. b.bum ___ 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: iPad store ?
Thanks. I will look at that. PEH's iPhone On Sep 12, 2011, at 10:17 AM, Hunter Hillegas wrote: > There's an Enterprise program meant for internal deployments. > > http://developer.apple.com/programs/ios/enterprise/ > > On Sep 12, 2011, at 10:04 AM, Phil Hystad wrote: > >> Is there any way to deploy an iPad app other then the AppStore? I don't >> mean for development testing or other temporary purposes. >> >> Situation is the development of an application for a particular customer who >> would use the app for specific in-house purposes. The app would not be >> generally available, at least that is the intent. > ___ 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
Disable autosave in place for a particular uti / filetype?
Is there any way to turn off 10.7's autosave in place for a particular uti/file type? Or maybe turn it on for a single file type? Here's my use case: I've got an image editor which can edit multiple types of files (png, jpeg, etc). Autosave is great for for its native format (.acorn) which is lossless and can preserve layers. But for something like a jpeg, which is a lossy format, autosave in place is problematic. Open up the image, edit, and it saves. And when you undo to the original state, autosave kicks in- but the saved file doesn't go back to it's very original state. It's compressed again, which is going to cause image degradation over time. If I return a lossless uti in - (NSString *)autosavingFileType, the original jpeg will be written with data that isn't a jpeg, which is problematic as well. I realize that having autosave turned on for a single file type is dumb and will be confusing for the user- but I'm just looking for ideas at this point. thanks, -gus -- August 'Gus' Mueller Flying Meat Inc. http://flyingmeat.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
any way to know where a UIBarButtonItem has been drawn?
I have a toolbar with items on it. One of them is a trash can. When I delete something from the main screen I'd like it to 'minify' towards the trash can, well I think I would, I have to see what it looks like and see if the effect is as nice as I hope, I want to draw attention to where the 'thing' has gone and this seems like a reasonable animation to try. However .. I can't figure out what the frame for the UIBarButtonItem is .. it's on a bar with items which change, some flexible space etc, so it's not a fixed offset from either end of the the thing, and I can't find an API which tells me what the frame is for a given item. Is there one I've missed? ___ 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: Disable autosave in place for a particular uti / filetype?
On Sep 12, 2011, at 10:59 AM, Marco Tabini wrote: > Have you thought about adopting the same pattern taken by Photoshop, where > opening an image that is not in your native format simply creates a copy in > .acorn on which the user works? Your choices on save then are to (a) either > save a copy in .acorn or (b) re-export in the original format? I hadn't noticed that behavior in PS before, so I'll have to see exactly what it's doing there. It's a little bit unexpected I think, but it might be a reasonable workaround. -gus -- August 'Gus' Mueller Flying Meat Inc. http://flyingmeat.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: Disable autosave in place for a particular uti / filetype?
On Mon, Sep 12, 2011 at 10:53 AM, Gus Mueller wrote: > Is there any way to turn off 10.7's autosave in place for a particular > uti/file type? Or maybe turn it on for a single file type? Use a different NSDocument subclass for lossy file types? --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: iPad store ?
On Mon, Sep 12, 2011 at 10:17 AM, Hunter Hillegas wrote: > There's an Enterprise program meant for internal deployments. > > http://developer.apple.com/programs/ios/enterprise/ And now that the iOS App Store has the B2B (Volume Purchase) program, you don't have to jump through hoops to sell apps to enterprises. https://developer.apple.com/appstore/resources/volume/ --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: Disable autosave in place for a particular uti / filetype?
On Sep 12, 2011, at 11:19 AM, Kyle Sluder wrote: > On Mon, Sep 12, 2011 at 10:53 AM, Gus Mueller wrote: >> Is there any way to turn off 10.7's autosave in place for a particular >> uti/file type? Or maybe turn it on for a single file type? > > Use a different NSDocument subclass for lossy file types? Oh, right. Why didn't I think of that? Sometimes the obvious answers are… not so obvious :) thanks Kyle, -gus -- August 'Gus' Mueller Flying Meat Inc. http://flyingmeat.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: Avoid smooth scrolling when scrolling programmatically
On Mon, Sep 12, 2011 at 12:07 AM, Stefan Haller wrote: > I need to set the scroll position of my NSScrollView programmatically, > and I don't want it to scroll smoothly (if the user's "smooth scrolling" > preference is on). I can't find a way how to do that. Why would you not want to scroll smoothly if the user has decided they like smooth scrolling? --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: Disable autosave in place for a particular uti / filetype?
On Mon, Sep 12, 2011 at 11:23 AM, Gus Mueller wrote: > > On Sep 12, 2011, at 11:19 AM, Kyle Sluder wrote: > >> On Mon, Sep 12, 2011 at 10:53 AM, Gus Mueller wrote: >>> Is there any way to turn off 10.7's autosave in place for a particular >>> uti/file type? Or maybe turn it on for a single file type? >> >> Use a different NSDocument subclass for lossy file types? > > Oh, right. Why didn't I think of that? Sometimes the obvious answers are… > not so obvious :) Probably because it's not the "best" solution. We have the same issue in our apps, where we read and write to a filetype, but the reading and/or writing process might be lossy (OPML in OmniOutliner is a prime example). I believe the expected behavior would be to get an untitled document with the lossily-imported file contents. I believe you get this behavior for free if you set the Role to "Viewer" in your UTI declaration. --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: any way to know where a UIBarButtonItem has been drawn?
On 12 Sep 2011, at 11:53 AM, Roland King wrote: > However .. I can't figure out what the frame for the UIBarButtonItem is .. > it's on a bar with items which change, some flexible space etc, so it's not a > fixed offset from either end of the the thing, and I can't find an API which > tells me what the frame is for a given item. Is there one I've missed? I can't find a frame either, but the bar will give you an array of items, and assuming all the items are UIBarButtonItem, you can iterate over the array to get their widths. From that you can get a good enough rectangle for visual purposes. Here's what I'd start with (composed in Mail, untested): - (CGRect) barButtonFrame: (UIBarButtonItem *) aButton { // Assumes you are holding a UIToolbar in self.toolbar. // Assumes everything in the toolbar responds to -width // (i.e., UIBarButtonItem, which includes spacers). // The toolbar observes an inset for the first item. // Figure out the inset empirically, and adjust BAR_MARGIN accordingly: #define BAR_MARGIN 4.0 BOOLfound = NO; CGRect buttonFrame = self.toolbar.bounds; CGFloat totalWidth = 0.0; for (UIBarButtonItem * item in self.toolbar.items) { if (item == aButton) { // Found it. buttonFrame.origin.x = totalWidth + BAR_MARGIN; buttonFrame.size.width = item.width; found = YES; break; } else // Still looking. totalWidth += item.width; } return found? buttonFrame: CGRectZero; // The rect is in the coordinates of self.toolbar. // Convert to self.view coordinates (or whatever) for the animation. // Check for CGRectZero (button not found). There's an argument to // be made that this method should raise an exception if ! found. } — F ___ 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: any way to know where a UIBarButtonItem has been drawn?
On Mon, Sep 12, 2011 at 9:53 AM, Roland King wrote: > I have a toolbar with items on it. One of them is a trash can. When I delete > something from the main screen I'd like it to 'minify' towards the trash can, > well I think I would, I have to see what it looks like and see if the effect > is as nice as I hope, I want to draw attention to where the 'thing' has gone > and this seems like a reasonable animation to try. I believe the typical approach is to use a custom view on your bar button item and get that view's frame. --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: Avoid smooth scrolling when scrolling programmatically
Kyle Sluder wrote: > On Mon, Sep 12, 2011 at 12:07 AM, Stefan Haller > wrote: > > I need to set the scroll position of my NSScrollView programmatically, > > and I don't want it to scroll smoothly (if the user's "smooth scrolling" > > preference is on). I can't find a way how to do that. > > Why would you not want to scroll smoothly if the user has decided they > like smooth scrolling? Imagine a master-detail interface with a master list of "documents" and a detail view showing one document. Clicking on a different document in the master list loads the new document into the detail pane's scroll view, and then scrolls it to the top. -- Stefan Haller Berlin, Germany http://www.haller-berlin.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: Submitting Mac App to the App Store
much thanks, I'll give Nick's work a try. On Sep 10, 2:34 pm, Indragie Karunaratne wrote: > https://github.com/nickpaulson/NPReceiptVerification > > Should simplify this procedure quite a bit. > > On 2011-09-10, at 2:28 PM, R wrote: > > > > > > > > > > > Wow, what a configuration mess for the new programmer. > > > Is there anyone that has submitted a Mac App to the App Store willing > > to explain the procedure.. including the Validating Mac App Store > > Receipts process. > > > I'm about to give up and call Apple. > > >http://developer.apple.com/library/mac/#releasenotes/General/Validate... > > ___ > > > Cocoa-dev mailing list (cocoa-...@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/cocoadev%40indragie.com > > > This email sent to cocoa...@indragie.com > > ___ > > Cocoa-dev mailing list (cocoa-...@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/cocoa-dev-garchive-9... > > This email sent to cocoa-dev-garchive-98...@googlegroups.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 get baseline info
You can iterate through the line fragment positions using -[NSLayoutManager lineFragmentRectForGlyphIndex:effectiveRange:]. >From the line fragment origin, the baseline offset can be determine by using >-[NSTypesetter baselineOffsetInLayoutManager:glyphIndex:]. The typesetter can be obtained via -[NSLayoutManager typesetter]. Aki On Sep 12, 2011, at 1:35 AM, Gerriet M. Denkmann wrote: > > I have a subclass of NSTextView which does: > > - (void)setUpData > { > [ [ self textStorage ] setAttributedString: someAttributedString ]; > // uses self.usedFont > NSLayoutManager *layoutManager = [ self layoutManager ]; > baselineOffset = [ layoutManager defaultBaselineOffsetForFont: > self.usedFont ]; > lineHeight = [ layoutManager defaultLineHeightForFont: self.usedFont ]; > } > > > - (void)drawRect:(NSRect)dirtyRect > { > [ super drawRect: dirtyRect ]; > > for( NSUInteger line = 0; line < NBR_OF_LINES; line++ ) > { > CGFloat bax = lineHeight * line + baselineOffset; > > [ [ NSColor blueColor ] set ]; // base line > [ NSBezierPath strokeLineFromPoint:NSMakePoint( > NSMinX(dirtyRect), bax ) > toPoint: > NSMakePoint( NSMaxX(dirtyRect), bax ) > ]; > }; > } > > This works, because currently all lines use the same font. > > But how would I handle the more general case, where each line might contain > several and/or different fonts? > > > Kind regards, > > Gerriet. > > ___ > > 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/aki%40apple.com > > This email sent to a...@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: NSScanner to find multiple occurrences of a prefix?
Typed into mail (no guarantee): NSScanner* scanner = [NSScanner scannerWithString:input]; NSMutableString* output = [NSMutableString string]; NSString* temp; [scanner setCaseSensitive:YES]; while( ![scanner isAtEnd]) { if([scanner scanUpToCharactersFromSet:[NSCharacterSet uppercaseLetterCharacterSet] intoString:&temp]) { [output appendString:temp]; if( ![scanner isAtEnd]) [output appendString:@"_"]; // underscore } if([scanner scanCharactersFromSet:[NSCharacterSet uppercaseLetterCharacterSet] intoString:&temp]) [output appendString:[temp lowercaseString]]; } return output; --Graham On 13/09/2011, at 12:01 AM, Devraj Mukherjee wrote: > I am trying to use NSScanner to change camel cased strings into > underscore delimited strings, e.g featuredListingId to > featured_listing_id > > I have worked our how to use NSScanner to achieve this, consider my > implementation (implemented as a NSString category) > > - (NSString *) delimiterSeparatedWords > { > NSScanner *scanner = [NSScanner scannerWithString:self]; > > NSString *prefix = nil; > NSString *suffix = nil; > > [scanner scanCharactersFromSet:[NSCharacterSet > lowercaseLetterCharacterSet] intoString:&prefix]; > [scanner scanCharactersFromSet:[NSCharacterSet letterCharacterSet] > intoString:&suffix]; > > NSString *fieldNameString = [NSString stringWithFormat:@"%@_%@", > prefix, [suffix lowercaseString]]; > return fieldNameString; > } > > obviously it only addresses the first occurrence of a capital letter. > > Can I ask NSScanner to keep looking for multiple occurrences? ___ 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: NSScanner to find multiple occurrences of a prefix?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 9/12/11 7:01 AM, Devraj Mukherjee wrote: > Hi all, > > I am trying to use NSScanner to change camel cased strings into > underscore delimited strings, e.g featuredListingId to > featured_listing_id In addition to the responses you have already received, if you are using a sufficiently new SDK you can use regexes to accomplish your goal: NSString *input = @"featuredListingId"; NSError *error = nil; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"([a-z])([A-Z])" options:0 error:&error]; NSString *result = [[regex stringByReplacingMatchesInString:input options:0 range:NSMakeRange(0, [input length]) withTemplate:@"$1_$2"] lowercaseString]; (Clearly you would need to handle errors, etc., as appropriate for your situation.) Regular expressions typically run slowly in relative terms, so if you are doing a lot of these conversions you would probably want to profile performance too. - -- Conrad Shultz Synthetiq Solutions www.synthetiqsolutions.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFObpg5aOlrz5+0JdURAnrBAJ9kH0BeBVAbp9xKLVQE1RAgR1xMkwCeOwSC SRZfXZa4Hp28J71FtdcK7TU= =qLaC -END PGP SIGNATURE- ___ 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: Problem with NSAppleScript execution
On 2011 Sep 12, at 08:50, Nava Carmon wrote: > I'm trying to run a simple Apple script, that gets the text from the > frontmost application. "Simple" is the way people who have never done this would describe it. > It doesn't work consistently. Sometimes it works and sometimes - doesn't. I presume you've tried making those delays longer than 0.1. > Same script in the ScriptEditor btw works just fine :( Well, then, rather than hard-coding it, include that .scpt file in your project, and in your Copy Resources Build Phase. Like this… (error checking omitted) NSString* scriptPath = [[NSBundle mainBundle] pathForResource:exformat ofType:@"scpt" inDirectory:nilOrWhatever] ; NSURL* scriptUrl = [NSURL fileURLWithPath:scriptPath] ; NSAppleScript* script = [[NSAppleScript alloc] initWithContentsOfURL:scriptUrl error:&errorDic] ; NSAppleEventDescriptor* descriptor = [script executeAndReturnError:&error] ; [script release] ; > Did somebody bump into such a thing before? When I wanted to do this, I ended up specifying the menu items by number. It's probably more fragile than keyboard shortcuts, but System Events are pretty fragile anyhow. The AppleScript workflow is to keep trying different things that should work until you find one that does work. Here is part of the script which I use: tell application "System Events" set oldClipboard to the clipboard set the clipboard to "" tell process "Whatever" set frontmost to true set editCopyMenuItem to a reference to menu item 5 of menu of menu bar item 4 of menu bar 1 set isEnabled to enabled of editCopyMenuItem as boolean if (isEnabled is true) then click editCopyMenuItem end if end tell delay 0.1 copy (the clipboard) to selectedText set the clipboard to oldClipboard end tell -- Make sure that none of your property keys are AppleScript reserved words, nor used in the target app's terminology, or the following will give unexpected results… return {whatever:whatever textIWant:selectedText, whateverElse:whateverElse} Comment regarding the delay 0.1: -- Sometimes, copy (the clipboard) gets previous clipboard data unless we use a delay. The more, the better. We chose 0.1 as a good compromise. Even without this delay, this script takes 0.2 seconds to execute anyhow. Regarding your code for processing the script output, it looks different than mine. I use -[NSAppleEventDescriptor stringValue]. This works for me: NSMutableDictionary* infoFromScript = [[NSMutableDictionary alloc] init] ; NSInteger i ; for (i=1; i<=[descriptor numberOfItems]; i++) { // This loop should only execute once; [descriptor numberOfItems] = 1 NSAppleEventDescriptor* subdescriptor = [descriptor descriptorAtIndex:i] ; NSInteger nItems = [subdescriptor numberOfItems] ; if ((nItems > 0) && (nItems%2 == 0)) { NSUInteger j ; for(j=1; j<=[subdescriptor numberOfItems]/2; j++) { NSString* key = [[subdescriptor descriptorAtIndex:(2*j-1)] stringValue] ; NSString* value = [[subdescriptor descriptorAtIndex:(2*j)] stringValue] ; if (key && value) { [infoFromScript setObject:value forKey:key] ; } } break ; } } > More than that, when I run same script from Script editor, it works perfect. > Is it a known problem or do I do something wrong? Well, some would say that AppleScript is kind of a known problem :)) ___ 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: any way to know where a UIBarButtonItem has been drawn?
If your use case permits, you can figure out the frame of the bar button item in it's action selector by giving the selector the following signature: - (void)barButtonAction:(UIBarButtonItem *)item event:(UIEvent *)event; You can then use the properties of UIEvent to get the touches location, or the view that the touches belong to. For instance: - (IBAction)barButtonAction:(UIBarButtonItem *)sender event:(UIEvent *)event{ UITouch *touch = [[event allTouches] anyObject]; CGPoint locationInView = [[[event allTouches] anyObject] locationInView:self.view]; NSLog(@"event touch location = %@", [NSValue valueWithCGPoint:locationInView]); NSLog(@"touch.view = %@", [touch view]); } On Sep 12, 2011, at 12:53 PM, Roland King wrote: > I have a toolbar with items on it. One of them is a trash can. When I delete > something from the main screen I'd like it to 'minify' towards the trash can, > well I think I would, I have to see what it looks like and see if the effect > is as nice as I hope, I want to draw attention to where the 'thing' has gone > and this seems like a reasonable animation to try. > > However .. I can't figure out what the frame for the UIBarButtonItem is .. > it's on a bar with items which change, some flexible space etc, so it's not a > fixed offset from either end of the the thing, and I can't find an API which > tells me what the frame is for a given item. Is there one I've missed? > ___ > > 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/jamiepinkham%40me.com > > This email sent to jamiepink...@me.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
web view moving in split view when keyboard comes up
I have a UIWebView loading a Sencha Touch html page in a split view. The autosizing for the web view is set to the left and top in Interface Builder with the four in the middle, right, and bottom disabled, although I've tried many combinations. The issue occurs when you touch in the sencha dialog box and the keyboard comes up. The web view itself moves up. In another case it moves up and left. Is it my autosizing that is wrong or web code? code: http://ragehip.com/split.zip Thanks! Steve___ 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: Problem with NSAppleScript execution
Thanks for answering, Jerry. On Sep 13, 2011, at 3:55 AM, Jerry Krinock wrote: > On 2011 Sep 12, at 08:50, Nava Carmon wrote: > >> I'm trying to run a simple Apple script, that gets the text from the >> frontmost application. > > "Simple" is the way people who have never done this would describe it. > >> It doesn't work consistently. Sometimes it works and sometimes - doesn't. > > I presume you've tried making those delays longer than 0.1. Yes, I tried, It didn't make things work more consistent :( > >> Same script in the ScriptEditor btw works just fine :( > > Well, then, rather than hard-coding it, include that .scpt file in your > project, and in your Copy Resources Build Phase. Like this… (error checking > omitted) > > NSString* scriptPath = [[NSBundle mainBundle] pathForResource:exformat > ofType:@"scpt" > inDirectory:nilOrWhatever] ; > NSURL* scriptUrl = [NSURL fileURLWithPath:scriptPath] ; > NSAppleScript* script = [[NSAppleScript alloc] initWithContentsOfURL:scriptUrl > > error:&errorDic] ; > NSAppleEventDescriptor* descriptor = [script executeAndReturnError:&error] ; > [script release] ; I have a scpt file, that does it and tried use it also. The script activates the frontmost application > >> Did somebody bump into such a thing before? > > When I wanted to do this, I ended up specifying the menu items by number. > It's probably more fragile than keyboard shortcuts, but System Events are > pretty fragile anyhow. The AppleScript workflow is to keep trying different > things that should work until you find one that does work. > > Here is part of the script which I use: > > tell application "System Events" >set oldClipboard to the clipboard >set the clipboard to "" >tell process "Whatever" >set frontmost to true >set editCopyMenuItem to a reference to menu item 5 of menu of menu bar > item 4 of menu bar 1 >set isEnabled to enabled of editCopyMenuItem as boolean >if (isEnabled is true) then >click editCopyMenuItem >end if >end tell >delay 0.1 >copy (the clipboard) to selectedText >set the clipboard to oldClipboard > end tell > -- Make sure that none of your property keys are AppleScript reserved words, > nor used in the target app's terminology, or the following will give > unexpected results… > return {whatever:whatever textIWant:selectedText, whateverElse:whateverElse} > > Comment regarding the delay 0.1: > > -- Sometimes, copy (the clipboard) gets previous clipboard data unless we use > a delay. The more, the better. We chose 0.1 as a good compromise. Even > without this delay, this script takes 0.2 seconds to execute anyhow. 0.1 makes you wait reasonable amount of time. And as I use it twice or more, you come to some 0.5 delay which is already something that feels a bit slow. > > Regarding your code for processing the script output, it looks different than > mine. I use -[NSAppleEventDescriptor stringValue]. This works for me: > > NSMutableDictionary* infoFromScript = [[NSMutableDictionary alloc] init] ; > NSInteger i ; > for (i=1; i<=[descriptor numberOfItems]; i++) { >// This loop should only execute once; [descriptor numberOfItems] = 1 >NSAppleEventDescriptor* subdescriptor = [descriptor descriptorAtIndex:i] ; >NSInteger nItems = [subdescriptor numberOfItems] ; >if ((nItems > 0) && (nItems%2 == 0)) { >NSUInteger j ; >for(j=1; j<=[subdescriptor numberOfItems]/2; j++) { >NSString* key = [[subdescriptor descriptorAtIndex:(2*j-1)] > stringValue] ; >NSString* value = [[subdescriptor descriptorAtIndex:(2*j)] > stringValue] ; >if (key && value) { >[infoFromScript setObject:value > forKey:key] ; >} >} >break ; >} > } I found that it brings the unicode characters. I'll try string value. > >> More than that, when I run same script from Script editor, it works perfect. >> Is it a known problem or do I do something wrong? > > Well, some would say that AppleScript is kind of a known problem :)) I have another question. My application intercepts clicks/key down events and brings the text from the frontmost application to my application on catching a certain key sequence. Then it evaluates it and pastes fixed text back to the application, that was frontmost. I tried using accessibility APIs, but not all applications support it. AppleScript seems to be the universal solution in this case, since it's mostly simulates copy & paste key sequences, but may be there are another technologies, that can be used for this purpose. Are you aware of something more robust? Thanks, Nava > > ___ > > Cocoa-dev mailing list (Coco
strange values for boundingRectForGlyphRange with SE-Asian fonts
I get the bounding rect for all glyphs in my TextView subclass and display them. Looks perfect: the boxes snugly fit the characters. But when a line contains any Thai character (similar for Laos, Burma, Khmer) then the boxes are strangly wide. Why? Is there some good reason for this? Or am I doing something wrong? Example: font = Thonburi 48pt. One line of "Wim" prints: 2011-09-13 12:01:36.072 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] 3 glyps - self {{0, 0}, {205, 231}} 2011-09-13 12:01:36.075 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] textContainer {205, 1000} 2011-09-13 12:01:36.075 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] glyphs[0] = 172 rect {{5, 0}, {45.453, 66}} 2011-09-13 12:01:36.077 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] glyphs[1] = 190 rect {{50.453, 0}, {11.2687497, 66}} 2011-09-13 12:01:36.077 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] glyphs[2] = 194 rect {{61.71875, 0}, {42.918746948242188, 66}} but the line "Wimม" (last char is Thai character mo ma = U+0E21) prints: 2011-09-13 12:03:55.684 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] 4 glyps - self {{0, 0}, {205, 231}} 2011-09-13 12:03:55.685 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] textContainer {205, 1000} 2011-09-13 12:03:55.686 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] glyphs[0] = 172 rect {{-28, -5.52500057}, {99.3187494, 78.9187503}} 2011-09-13 12:03:55.687 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] glyphs[1] = 190 rect {{17.453, -5.52500057}, {99.3187494, 78.9187503}} 2011-09-13 12:03:55.688 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] glyphs[2] = 194 rect {{28.71875, -5.52500057}, {99.3187494, 78.9187503}} 2011-09-13 12:03:55.689 NSFontAttributeExplorer[5156:707] -[FontView setFont:andString:] glyphs[3] = 61 rect {{71.6375003, -5.52500057}, {99.3187509, 78.9187503}} Code fragment: NSUInteger numberOfGlyphs = [ layoutManager numberOfGlyphs ]; #ifdef LOG_BOXES NSLog(@"%s %lu glyps - self %@", __FUNCTION__, numberOfGlyphs, NSStringFromRect([self bounds]) ); #endif for( NSUInteger glyphIndex = 0; glyphIndex < numberOfGlyphs; ) { NSRange effectiveGlyphRange; NSTextContainer *container =[ layoutManager textContainerForGlyphAtIndex: glyphIndex effectiveRange: &effectiveGlyphRange ]; #ifdef LOG_BOXES NSLog(@"%s textContainer %@", __FUNCTION__, NSStringFromSize([container containerSize]) ); #endif NSUInteger max = NSMaxRange(effectiveGlyphRange); NSRange sux; sux.length = 1; for( NSUInteger i = effectiveGlyphRange.location; i < max; i++) { sux.location = i; NSRect r = [ layoutManager boundingRectForGlyphRange: sux inTextContainer: container ]; NSGlyph g = [ layoutManager glyphAtIndex: i ]; if ( g == NSControlGlyph ) { #ifdef LOG_BOXES NSLog(@"%s glyphs[%lu] = NSControlGlyph rect %@", __FUNCTION__, i, NSStringFromRect(r) ); #endif } else if ( g == NSNullGlyph ) { #ifdef LOG_BOXES NSLog(@"%s glyphs[%lu] = NSNullGlyph rect %@", __FUNCTION__, i, NSStringFromRect(r) ); #endif } else { #ifdef LOG_BOXES NSLog(@"%s glyphs[%lu] = %4u rect %@", __FUNCTION__, i, g, NSStringFromRect(r) ); #endif }; }; glyphIndex = max; }; Kind regards, Gerriet. ___ 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/a