Getting TextEdit to Recognise UTF-8 Output
I'm working on a feature that will see my program automatically export to a UTF-8 text file. This process works fine. What doesn't work fine is that TextEdit.app (and others) does not recognise it automatically as a UTF-8 text file, even when Plain Text Encoding: Opening Files: (in Preferences) is set to Automatic. Question: Is there any header I can put at the beginning of the text file to get it automatically recognised as UTF-8? Here is some background, and what I'm trying to do: T.txt - a UTF-8 file: 1. When opened in TextEdit, UTF-8 is not detected. 2. When opened in Pages, UTF-8 is not detected. 3. When opened in TextMate, UTF-8 is detected. 4. When opened in MacVim, UTF-8 is detected. If I rename T.txt to T.utf8: 1. When opened in TextEdit, UTF-8 is detected. 2. When opened in Pages, file is not loaded. 3. When opened in TextMate, UTF-8 is detected. 4. When opened in MacVim, UTF-8 is detected. What I need is for TextEdit to open it properly, with the .txt extension (I include the rest just for comparison). I can get TextEdit to do this if I set Plain Text Encoding: Opening Files: to UTF-8. But I'd rather not have my users make this change if not absolutely necessary (it screams support issues). I've tried prefacing the text file with a BOM in this way: [textStream appendFormat:@%C%C%C,0x00EF,0x00BB,0x00BF]; // textStream is an empty NSMutableString that gets added to, and then written to a file Is there any way to do what I'm trying to do? Thanks.___ 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: mouseEntered/-mouseExited not firing on drag (NSTrackingEnabledDuringMouseDrag on)
On 28-Jan-10, at 9:13 PM, Jerry Krinock wrote: On 2010 Jan 28, at 16:00, K. Darcy Otto wrote: It is my understanding that the NSTrackingEnabledDuringMouseDrag is supposed to allow -mouseEntered/-mouseExited to fire during a drag. Is this not correct? I hope someone who knows the answer to that specific question will answer you. Any ideas? When I had a similar problem I was advised that whatever responds to mouseDown: probably begins tracking the mouse, sucking up all the NSMouseMoved events, until mouseUp. Try overriding mouseDown: and don't invoke super. Tried this, but it does not work. Do you remember if you did something else to solve the problem? Here's something interesting as well: I tried commenting out - mouseDragged, and the tracking areas start to respond during a mouse drag. ___ 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
Which CA Layer am I dragging over?
On 28-Jan-10, at 2:47 AM, vincent habchi wrote: Le 28 janv. 2010 à 08:43, K.Darcy Otto a écrit : NSRect rect = NSRectFromCGRect([hitLayer frame]); float width = rect.size.width; That is, it returns a width, but not the width in the current window coordinates. Any ideas? Thanks. What do you mean by not the width in the current window coordinates? By definition, a width is coordinate independent, as long as your underlying metric space remains the same (thanks to Einstein). Vincent Maybe I'm going at this the wrong way. I've got a bunch of CA layers with images, and I'm dragging with the mouse. The question I would like to answer is: which CA layer is the mouse currently being dragged over? The solution I am pursuing is as follows: 1. From -mouseDragged, set up a series of NSTrackingAreas that correspond to each CA layer that I'm interested in. 2. The NSTrackingAreas will trigger -mouseEntered and -mouseExited for the CA layers 3. Use the NSEvent data from -mouseEntered to determine the current screen position and -hitTest to determine layer The problem is that I'm having difficulty setting up the NSTrackingAreas. Given CA layer x, I want to discover the position of x in the window so I can set up the tracking area. Is this the right way to solve this problem? If so, how do I get the rect for layer x?___ 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: Which CA Layer am I dragging over?
On 28-Jan-10, at 9:38 AM, David Duncan wrote: On Jan 28, 2010, at 9:26 AM, K. Darcy Otto wrote: The problem is that I'm having difficulty setting up the NSTrackingAreas. Given CA layer x, I want to discover the position of x in the window so I can set up the tracking area. Is this the right way to solve this problem? If so, how do I get the rect for layer x? NSRectFromCGRect() is basically just a typecast, but you need a coordinate conversion. The way to do this is to first convert the bounds of layer X to a rectangle in the coordinate system of your view's layer, which can be done with -convertRect:fromLayer: (note, you want bounds NOT frame here – if you use frame you need to convert from layer x's superlayer because the frame is in the layer' superlayer's coordinate system). Thank you for this; but I'm still having a few problems. Here's what I have as part of -mouseDragged (where hitLayer is the CA layer that has been identified): CGRect p,q; p = [hitLayer bounds]; q = [[hitLayer superlayer] convertRect:p fromLayer:hitLayer]; Now, q is in the coordinate system of the superlayer - I'm not sure how to get it into the coordinate system of the view (there is no - convertRect:fromLayer: for the view). I've tried the NSView methods - convertRect:toView: and -convertRectToBase: without success. Overall you may find it easier to simply setup a tracking area for the entire view and then hit test to find the layer of interest instead, especially since moving the layers around would mean moving the tracking areas around too. Yes, I think this will be my fallback position. I actually have only a few areas that need to be tracked and only at certain times, which is why I'm trying with a series of NSTrackingArea first. Thanks again.___ 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
mouseEntered/-mouseExited not firing on drag (NSTrackingEnabledDuringMouseDrag on)
I've managed to set up a series of NSTrackingAreas. These tracking areas work beautifully, highlighting and de-highlighting in turn by means of -mouseEntered and -mouseExited. The problem I've run into is that -mouseEntered and -mouseExited do not fire on a drag. Here is the code I've used to set up the tracking: NSTrackingArea *trackArea = [[NSTrackingArea alloc] initWithRect:rect options:(NSTrackingMouseEnteredAndExited | NSTrackingEnabledDuringMouseDrag | NSTrackingActiveAlways) owner:self userInfo:userInfo]; I then add the trackArea to the view. Once set up, -mouseEntered/- mouseExited fire as expected when the mouse hovers over the tracking areas. But not during a drag. It is my understanding that the NSTrackingEnabledDuringMouseDrag is supposed to allow -mouseEntered/-mouseExited to fire during a drag. Is this not correct? I've also tried adding the NSTrackingMouseMoved option, and found that -mouseMoved fires, but again not with a drag. Any ideas? Thanks. ___ 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
Size of Core Animation Layer
I'm having some difficulties translating between a Core Animation layer size, and the size of that layer in the NSView subclass I'm using. I can identify the layer from a mouseclick without difficulty, using the following code: -(void)mouseDown:(NSEvent *)theEvent { NSPoint translated = [window convertScreenToBase:[NSEvent mouseLoctaion]; CGPoint point = NSPointToCGPoint(translated); CALayer *rootLayer = [[window contentView] layer]; // give me the background layer of the window id hitLayer = [rootLayer hitTest:point]; // gives me the CALayer that was clicked ... } But now, I want to see what the size of the hitLayer is, in the window's coordinate system. The following doesn't work: NSRect rect = NSRectFromCGRect([hitLayer frame]); float width = rect.size.width; That is, it returns a width, but not the width in the current window coordinates. Any ideas? Thanks. ___ 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
RegexkitLite - Possible bug?
I've been working with RegexkitLite, and I'm wondering whether someone else who has RegexkitLite can reproduce this problem, or spot what I'm doing wrong: NSString *originalString = @IMUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIU; // Using the built-in range: option NSString *firstTry = [originalString stringByReplacingOccurrencesOfRegex:@M(.*) withString:@M$1$1 range:NSMakeRange(1,57)]; NSLog(@firstTry result: %@,firstTry); // Using substringWithRange: first NSString *cutOriginalString = [originalString substringWithRange:NSMakeRange(1, 57)]; NSString *secondTry = [cutOriginalString stringByReplacingOccurrencesOfRegex:@M(.*) withString:@M$1$1]; NSLog(@secondTry result: %@,secondTry); Output: firstTry result: (null) secondTry result: MUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIUUIUIUIU I contend that the results of firstTry and secondTry should be the same. What am I missing? Thanks. ___ 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
Thanks for the Help
I just launched my first software product, and I want to thank the many, many people on this list who helped me during the development phase. There would be no way I could have done it without you. When I look back at the large number of questions I have filed (all the way from basic Objective-C questions at the beginning, to problems with tables, and then finally to writing help and drawing in Cocoa at the end), I sometimes think my app should say author: me ... and about a hundred others. Anyway, thanks again, Darcy ___ 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
Reference Count Underflow when Writing PDF
I have a PDF that I've loaded, combined with another PDF, and now I'm ready to save the result as a new file. My program is using garbage collection, but I understand that PDFKit is not garbage collected. The problem is that I get reference count underflow error when writing the PDF. Here is some code that is shorter, but creates the same problem I'm having: // Get PDF from disc NSData *savedData = [[NSData alloc] initWithContentsOfFile:@oldfile.pdf options:0 error:error]; PDFDocument *savedDoc = [[PDFDocument alloc] initWithData:savedData]; // Write saveDoc to file [savedDoc writeToFile:@newfile.pdf]; Actually, there is no problem when writing the file: newfile.pdf is intact after the operation. But I get the following error in the console: malloc: reference count underflow for 0x13464c0, break on auto_refcount_underflow_error to debug. And when I break on auto_refcount_underflow, I get the following stack: #0 0x94721a40 in auto_refcount_underflow_error #1 0x9472d8e4 in Auto::Zone::dec_refcount_small_medium #2 0x9472d9b0 in Auto::Zone::block_decrement_refcount #3 0x931da50c in CFRelease #4 0x904bfe4c in -[PDFDocument(PDFDocumentInternal) writeToConsumer:withOptions:] #5 0x904bd9fc in -[PDFDocument writeToURL:withOptions:] #6 0x904bd97c in -[PDFDocument writeToFile:withOptions:] #7 0x6b60 in -[MyDocument openPanelDidEnd:returnCode:contextInfo:] at MyDocument.m:495 Now, #3 suggests there is a release going on that shouldn't be; or at least there should be an extra retain in my code. But when I add CFRetain(savedDoc); before writing the file, the error still persists. I've read the Semantics section of Using Core Foundation with Garbage Collection, but I don't see a solution to this problem there (I'm not saying it's not there, just that I don't quite see it). Any help would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Reference Count Underflow when Writing PDF
In an effort to get out of this problem, I also thought I might just take a data representation of the PDFDocument object, and write the data to a file. I get the same problem. Here is what I tried, substituting for [savedDoc writeToFile:@newFile.pdf] below: NSData *myData = [savedDoc dataRepresentation]; [myData writeToFile:@newfile.pdf options:0 error:error]; The malloc error is triggered on the -dataRepresentation line. So, three questions: (1) Contrary to my first message, it appears to me now that PDFDocument inherits from NSObject. So, i shouldn't have to do any special memory management, right? (2) The malloc error doesn't seem to stop the program, and everything is written to the appropriate file. Can I just leave the code as it is and ignore the error, or will it eventually catch up with me? (3) Is there another way to do what I've tried to do, I guess not using PDFDocument (if that is indeed the culprit, and not my own code)? Thanks, Darcy On 15-Jul-09, at 2:00 PM, K.Darcy Otto wrote: I have a PDF that I've loaded, combined with another PDF, and now I'm ready to save the result as a new file. My program is using garbage collection, but I understand that PDFKit is not garbage collected. The problem is that I get reference count underflow error when writing the PDF. Here is some code that is shorter, but creates the same problem I'm having: // Get PDF from disc NSData *savedData = [[NSData alloc] initWithContentsOfFile:@oldfile.pdf options:0 error:error]; PDFDocument *savedDoc = [[PDFDocument alloc] initWithData:savedData]; // Write saveDoc to file [savedDoc writeToFile:@newfile.pdf]; Actually, there is no problem when writing the file: newfile.pdf is intact after the operation. But I get the following error in the console: malloc: reference count underflow for 0x13464c0, break on auto_refcount_underflow_error to debug. And when I break on auto_refcount_underflow, I get the following stack: #0 0x94721a40 in auto_refcount_underflow_error #1 0x9472d8e4 in Auto::Zone::dec_refcount_small_medium #2 0x9472d9b0 in Auto::Zone::block_decrement_refcount #3 0x931da50c in CFRelease #4 0x904bfe4c in -[PDFDocument(PDFDocumentInternal) writeToConsumer:withOptions:] #5 0x904bd9fc in -[PDFDocument writeToURL:withOptions:] #6 0x904bd97c in -[PDFDocument writeToFile:withOptions:] #7 0x6b60 in -[MyDocument openPanelDidEnd:returnCode:contextInfo:] at MyDocument.m:495 Now, #3 suggests there is a release going on that shouldn't be; or at least there should be an extra retain in my code. But when I add CFRetain(savedDoc); before writing the file, the error still persists. I've read the Semantics section of Using Core Foundation with Garbage Collection, but I don't see a solution to this problem there (I'm not saying it's not there, just that I don't quite see it). Any help would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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: Printing a View [solved]
Thanks Matt, for the advice. I followed your links, and found the best way, for me at least, to print what I wanted was to create a view in IB, populate a custom view with text fields and tables, and then resize that view for printing. For those who are working on a similar problem, I created new view controller object from -printOperationWithSettings:, and that view object in turn creates the view that I want to print. That view implements various other subviews, but I was still having problems breaking pages at appropriate points. The subviews, however, can say where they should be broken by using -adjustPageHeightNew:. In my NSTableView subclass, which was the main element in the view, I implemented that method as follows: -(void)adjustPageHeightNew:(CGFloat *)newBottom top:(CGFloat)top bottom:(CGFloat)proposedBottom limit:(CGFloat)bottomLimit { *newBottom = proposedBottom; NSInteger indexCount = [deduction lineCount]-1; for (NSInteger i = indexCount; i0; i--) { NSRect rowRect = [self frameOfCellAtColumn:[self columnWithIdentifier:@MyColumn] row:i]; float bottomOfRow = rowRect.origin.y + rowRect.size.height; if (bottomOfRow proposedBottom) { *newBottom = bottomOfRow + 1.0; break; } } } So, the for loop just goes through the table and adjusts *newBottom so that it breaks at appropriate places. There is probably some more efficient way to check where the page should be broken, but the above implementation works just fine. On 13-Jul-09, at 5:16 PM, Matt Neuburg wrote: On Mon, 13 Jul 2009 10:07:17 -0700, K. Darcy Otto do...@csusb.edu said: Now, this should simply print a line of integers down the left side of the page. It does this for two pages - works perfectly - with lines 0 to 50 on the first page, and 51 to 100 on the second page, divided correctly so there is no splitting of lines and so on. But the rest of the pages are blank, and I can't figure out why. The NSLog from - Again, you're not providing enough information, but here are some questions to ask yourself. * What's printing is a view. How tall is that view? Is it tall enough to contain 500 lines? * Also: In drawRect:(NSRect)rect, what is rect? ___ 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
Crashes in Framework? Tracking down ghosts.
I'm working on an application which is nearing completion, but I'm getting these strange crashes that look to be deep in the cocoa framework. The thing is, I can't seem to diagnose these crashes, and I can't imagine that such bugs exist in the framework such that they pull down my application so frequently. So, I'm assuming it is something I'm doing. I am using garbage collection, and I'm getting an EXC_BAD_ACCESS error. And at least one crash that pops up every so often is below. It stops on the following line of code of the init method (#6 below) in my PrintView class: NSFont *font = [NSFont fontWithName:@Lucida Grande size:fontSize]; #0 0x931ad644 in CFDictionaryGetValue #1 0x901f4fb8 in TDescriptor::CreateMatchingDescriptorInternal #2 0x901f4e1c in TDescriptor::InitBaseFont #3 0x901f4d94 in TDescriptor::CreateMatchingDescriptor #4 0x921d48ec in __NSFontFactoryWithName #5 0x921d466c in +[NSFont fontWithName:size:] #6 0x0005e2e0 in -[PrintView initWithScopeDeduction:andHelper:andDeductionController:] at PrintView.m:32 #7 0x6a8c in -[MyDocument printOperationWithSettings:error:] at MyDocument.m:441 #8 0x9241bde8 in -[NSDocument _printDocumentWithSettings:showPrintPanel:delegate:didPrintSelector:contextInfo :] #9 0x9241bce0 in -[NSDocument printDocumentWithSettings:showPrintPanel:delegate:didPrintSelector:contextInfo :] #10 0x921f58b8 in -[NSApplication sendAction:to:from:] #11 0x922911d0 in -[NSMenu performActionForItemAtIndex:] #12 0x92290f00 in -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] #13 0x92290bc8 in -[NSMenu performKeyEquivalent:] #14 0x9228f6ac in -[NSApplication _handleKeyEquivalent:] #15 0x921c5d84 in -[NSApplication sendEvent:] #16 0x92132e44 in -[NSApplication run] #17 0x92103820 in NSApplicationMain #18 0x00015bf8 in main at main.m:13 fontSize is valid. If I look into local variables, I get _name being invalid. But if there is a problem with the name, that would be strange, since it works most of the time. Any ideas as to how I can diagnose this problem? I also have seemingly random crashes of this sort when the open file dialogue is opened. Thanks, ___ 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: Printing a View
Thanks Matt. You were absolutely correct; the problems I have were in -drawRect:. I'm still trying to track down a problem though, and I'm not sure where it is. I've actually cut it down to some fairly simple code. Here it is: -(NSRect)rectForPage:(NSInteger)pageNumber { // Note the current page currentPage = pageNumber-1; float pHeight = linesPerPage * lineHeight; NSRect returnRect = NSMakeRect(0.0, pHeight * currentPage, pageRect.size.width, pHeight); NSLog(@x-origin: %f, y-origin, %f, height: %f, width: %f, returnRect.origin.x, returnRect.origin.y, returnRect.size.height, returnRect.size.width); return returnRect; } -(void)drawRect:(NSRect)rect { NSRect lineRect; lineRect.origin.y = 0; lineRect.origin.x = pageRect.origin.x; lineRect.size.width = pageRect.size.width; lineRect.size.height = lineHeight; for (NSUInteger i=0; i500; i++) { // Draw line number lineRect.origin.y = (i * lineHeight); NSString *lineString = [NSString stringWithFormat:@%d,i]; [lineString drawInRect:lineRect withAttributes:attributes]; } } Now, this should simply print a line of integers down the left side of the page. It does this for two pages - works perfectly - with lines 0 to 50 on the first page, and 51 to 100 on the second page, divided correctly so there is no splitting of lines and so on. But the rest of the pages are blank, and I can't figure out why. The NSLog from - rectForPage: looks like this: x-origin: 0.00, y-origin, 0.00, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 606.899963, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 1213.799927, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 1820.699951, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 2427.599854, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 3034.499756, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 3641.399902, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 4248.299805, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 4855.199707, height: 606.899963, width: 576.00 x-origin: 0.00, y-origin, 5462.099609, height: 606.899963, width: 576.00 ... so it looks to me as if all the pages are being properly selected. Oh, and if I change the paper size and orientation, similar things happen (but not entirely consistently). So, if I choose landscape, it only prints two pages. But if I choose envelope #10, it prints three pages. Thanks, Darcy Several lines down? Could that be the extra 500 you keep introducing? Really, since what you need to say in rectForPage depends completely on how you draw in drawRect, which you don't show, it's hard to guess from here what rectForPage *should* be (or whether you even need to implement it)... m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings ___ 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
Printing a View
I'm trying to print a custom view. I've already customized that view in -drawRect:, and everything seems to be displayed correctly. The problem I'm having is that when it comes time to do -rectForPage, the output to the printer seems to shift around. Here is the code: -(NSRect)rectForPage:(NSInteger)pageNumber { // Note the current page currentPage = pageNumber-1; float pHeight = 500.0; NSLog(@Begin page %d at: %f,pageNumber,pHeight * currentPage); NSRect returnRect = NSMakeRect(0, pHeight * currentPage, pageRect.size.width, pHeight); NSLog(@End page %d at %f: %f,pageNumber,pHeight * currentPage + pHeight); return returnRect; } Now, I set pHeight 500.0 just in an attempt to diagnose this problem. The output from the log looks like this: 2009-07-12 11:00:57.981 Deductions[5031:10b] Begin page 1 at: 0.00 2009-07-12 11:00:58.002 Deductions[5031:10b] End page 1 at 500.00: 0.00 2009-07-12 11:00:58.395 Deductions[5031:10b] Begin page 2 at: 500.00 2009-07-12 11:00:58.406 Deductions[5031:10b] End page 2 at 1000.00: 0.00 2009-07-12 11:00:58.645 Deductions[5031:10b] Begin page 3 at: 1000.00 2009-07-12 11:00:58.655 Deductions[5031:10b] End page 3 at 1500.00: 0.00 2009-07-12 11:00:58.673 Deductions[5031:10b] Begin page 4 at: 1500.00 2009-07-12 11:00:58.687 Deductions[5031:10b] End page 4 at 2000.00: 0.00 So, this is just as expected. The problem is that the output to the printer makes it seem like page 2, for example, starts not where page 1 ended, but rather several lines down from where page 1 ended. I'm not sure what is going on, since the rects seem to be constructed properly. Any ideas? Thanks. ___ 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
Inconsistent double-click to edit in NSTableView
I have an NSTableView subclass that has a pair of columns that are acting inconsistently when the user double-clicks to begin editing. In the first column, the user can double-click anywhere in the cell to begin editing that cell. In the second column, which is the last column of the table, the following happens: (i) if the cell is blank, the user can click anywhere to begin editing the cell; (ii) if the cell has text, the user must click on the text in the cell to begin editing the cell. Does anybody have an idea what is going on? It seems to me that a double-click anywhere in the cell (whether there is text or not) should initiate editing. But even if (ii) were the case for both columns, I would be happy. It is the inconsistency that has caused some minor problems during testing. ___ 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
Table Selection Persists even though Window Closed
I have a document-based application that has, as its main UI element, an NSTableView subclass. I want to disable menu items based on whether the table has a row selected. I do this via - validateUserInterfaceItem, and everything works under normal circumstances: I check for a selected row with [myTable selectedRow], and if I get a -1 (indicating no row is selected), the menu items are disabled. The problem: when I close all the document windows, but do not close the application, and a row was selected prior to the last document window being closed, [myTable selectedRow] reports whatever the last row selected was, not -1 (even though it is not possible for a row to be selected, because there is no table in an open window). What might be of help in diagnosing this problem: when I issue [[myTable window] firstResponder], the first responder is myTable (even though the window is closed). Anybody know of a solution to this problem? I have a feeling my whole approach may be off, but I'm not sure. Thanks. ___ 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
Setting Up Apple Help
Okay, I have got Apple Help working for my application (the first time I have written a help book), and I wanted to encapsulate some of what I have learned in a message, in case others might benefit. The docs about how to set up help are good, but still (for me) left some questions unanswered. I used Affrus help (you can download the program and inspect it; the help was written by Matt Neuburg) as a model and used VoodooPad's HTML exporting capabilities in order to create a help system with many crosslinks. VoodooPad has been working really well for me in this capacity, but I needed to make a few changes to the resulting HTML: 1. Add the Apple meta tags to index.html 2. Add titleTitle Here/title to each page. You need (1) to get everything to work. You need (2) to make help searchable from the Ask a question field in the help app. This poses a problem, because each time I export the help pages from VoodooPad, these tags are missing. So, I set up a Ruby script to do so automatically. I don't know much Ruby, but I was able to piece together the following: !/usr/bin/ruby # Change method def Change(file, regex_to_find, text_to_put_in_place) text= File.read file File.open(file, 'w+'){|f| f text.gsub(regex_to_find, text_to_put_in_place)} end # Add the apple-specific meta tags to index.html Change('index.html', /6\ style type=text\/css/, 6\ meta name=\AppleTitle\ content=\My Help\ meta name=\AppleIcon\ content=\AppName%20Help/images/icon-name.png \ style type=\text/css\) # index.html: Add title - have one of these for each .html file Change('index.html', /title/, titleIndex of topics) There is probably a way to automate this further, but at least it means I don't have to edit the exported HTML by hand each time. Finally, I would end up having my cocoa app still display the old help when I wiped out the old help files and replaced them with new ones. In order to get the new help book recognised, I (1) delete ~/Library/ caches/com.apple.helpui; and (2) delete references and re-reference the help files in Xcode. Thanks to all those who helped with with various pieces of this solution. ___ 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: self Changes on Open Panel [solved]
I want to thank Fritz, Greg, Quincy and Uli for their help solving this problem. I don't think there is any general solution to this problem, but I wanted to make two remarks that might help others who run into something similar. (i) It turned out that i did have two different MyDocument objects. The second was being instantiated by MainMenu.xib. I actually checked the other .xib files looking for a MyDocument object, and turned up nothing; but I didn't think to look at MainMenu.xib. (ii) I tracked down the problem by creating a breakpoint at - [MyDocument init]. This led me to search every .xib looking for an instantiated MyDocument. I am a bit puzzled about one thing: I did put an NSLog at the beginning of the -init method, with a view to determining when the second MyDocument object was being instantiated. But, the NSLog fired only once. As many have pointed out, the object could be created with an -initWithCoder, so the NSLog would be skipped (presumably this is what happened when the .xib instantiated the object). But if this reasoning is correct, why, then, would -[MyDocument init] as a breakpoint stop the code twice? I mean, it shouldn't stop the code when -initWithcoder is called, right? Anyway, thanks again for all your help. On 10-Jun-09, at 11:48 AM, Uli Kusterer wrote: On 09.06.2009, at 17:48, Greg Guerin wrote: How do you know -init is only run once? Are you sure no other init method is run? Like maybe initWithCoder:? As a general rule, when you wonder where an object is coming from, it helps to have a look at any and all -init methods the class has. In particular init and initWithCoder:. In addition to that, objects can be created by a call to copy or mutableCopy, so you can get very interesting behaviour if your base class implements NSCopying and you forgot to override that in the subclass and do your own additional work. 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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 tell if a Panel is Open [solved]
Thanks to those who helped me with this question. The solution was to use NSWindow's -attachedSheet method, and (in my case), check for nil. If nil, there is no attached sheet; if not nil, there is an attached sheet. ___ 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 tell if a Panel is Open
Well, the sheet has to do some pretty complicated things, so I gave it its own NSWindowController subclass (PanController). The sheet's window controller is created by my NSDocument subclass (MyDocument). The thing is though, PanController is not a subclass of NSDocument, so it's strange to me that it is turning up as an NSDocument object. On 9-Jun-09, at 6:52 AM, Scott Ribe wrote: Sounds like you're creating a new window controller when you create the sheet. -- Scott Ribe scott_r...@killerbytes.com http://www.killerbytes.com/ (303) 722-0567 voice ___ 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: self Changes on Open Panel
Okay, so if I'm seeing two different objects, I guess the question is, where is the second object being created? I had a look an my .xib: the File's Owner is of type MyDocument; but there appear to be no places where I instantiate a MyDocument object. I put an NSLog into the -init of MyDocument; it seems like it is only being called once. Is there some other way to create the object (there are no other init- type routines in the class)? On 8-Jun-09, at 10:55 PM, Fritz Anderson wrote: On 8 Jun 2009, at 10:02 PM, K. Darcy Otto wrote: The sheet opens at *. Two questions: (i) why is MyDocument at a different address before and after * (incidentally, it changes back to 0x1036290 after the sheet has closed)? (ii) Why is sheetOpen (which is a class variable) not YES after * (in fact, under no circumstances does it return a YES, before, during or after the sheet)? What you're describing isn't one object moving around and resetting its contents. What you're seeing are two different objects. Are you instantiating a MyDocument within your NIB? Don't. Documents get created by AppKit, in memory. They are represented by File's Owner in Interface Builder. Adding a new one in the NIB will get you a second document. — F -- Fritz Anderson -- Xcode 3 Unleashed: Now in its second printing -- http://x3u.manoverboard.org/ ___ 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: self Changes on Open Panel
Hi Greg, Thanks for your suggestions. I got some (to me) surprising results. Here is the code: Code From MyDocument.h: @interface MyDocument : NSDocument { BOOL sheetOpen; // sheetOpen must be accessed directly; there are no accessors ... other stuff ... } Code From MyDocument.m: -(void)windowControllerDidLoadNib:(NSWindowController *)aController { [self performSelector:@selector(openConclusionSheetForWindow:) withObject:[deductionTable window] afterDelay:0.1]; ... other stuff ... } -(void)openConclusionSheetForWindow:(NSWindow *)window { NSLog(@sheetOpen before NSApp beginSheet: %d,sheetOpen); // Launch conclusion sheet [NSApp beginSheet:[conclusionController window] modalForWindow:window modalDelegate:self didEndSelector:NULL contextInfo:NULL]; NSLog(@sheetOpen after NSApp beginSheet: %d,sheetOpen); } -(void)windowWillBeginSheet:(NSNotification *)notification { NSLog(@sheetOpen an -windowWillBeginSheet start: %d,sheetOpen); sheetOpen = YES; NSLog(@sheetOpen an -windowWillBeginSheet end: %d,sheetOpen); } - (void)windowDidEndSheet:(NSNotification *)notification { NSLog(@sheetOpen an -windowDidEndSheet start: %d,sheetOpen); sheetOpen = NO; NSLog(@sheetOpen an -windowDidEndSheet end: %d,sheetOpen); } -(BOOL)validateUserInterfaceItem:(id NSValidatedUserInterfaceItem)anItem { NSLog(@sheetOpen at validateUserInterfaceItem: %d,sheetOpen); ... validation stuff ... } And here is the output (my **): sheetOpen at validateUserInterfaceItem: 0 sheetOpen before NSApp beginSheet: 0 sheetOpen an -windowWillBeginSheet start: 0 sheetOpen an -windowWillBeginSheet end: 1 sheetOpen after NSApp beginSheet: 1 ** sheetOpen at validateUserInterfaceItem: 0 sheetOpen an -windowDidEndSheet start: 1 ** sheetOpen an -windowDidEndSheet end: 0 sheetOpen at validateUserInterfaceItem: 0 The lines marked ** surprise me; I had expected they would be zero as well. If I replace these NSLogs with requests to display self, I get (again, my **): self at validateUserInterfaceItem: MyDocument: 0x1047180 self before NSApp beginSheet: MyDocument: 0x1047180 self at -windowWillBeginSheet: MyDocument: 0x1047180 self after NSApp beginSheet: MyDocument: 0x1047180 self at validateUserInterfaceItem: MyDocument: 0x102d430 ** self at -windowDidEndSheet: MyDocument: 0x1047180 self at validateUserInterfaceItem: MyDocument: 0x1047180 Bizarreness at **! I mean, -init is only run once! (I'll answer your question in the next message; I know there is a limit to message lengths on the list, so I'll break it up.) Thanks again. On 9-Jun-09, at 10:12 AM, Greg Guerin wrote: K. Darcy Otto wrote: -(void)windowWillBeginSheet:(NSNotification *)notification { sheetOpen = YES; NSLog(@self at -windowWillBeginSheet: %@,self); } I would NSLog the before and after state of sheetOpen, i.e. on entry to the method body and on exit from the method body. I might even consider assertions. Please show the code that defines the sheetOpen class variable, and identify exactly where it resides (which class), and how other classes have access to it. I mention this because all the behavior you've described so far is consistent with what happens if sheetOpen isn't actually a class variable or a static variable, but is an instance variable. Finally, please explain what problem you're trying to solve by having a boolean sheetOpen class variable. Is this related to your earlier How to tell if a Panel is Open question? If so, please explain the premise of that question: you wrote, I need to know whether a particular panel is open, but never explained why you need to know that, or what you'd do with that state. -- GG ___ 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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: self Changes on Open Panel
You're right, my two questions are related. I do, ultimately, want to tell if a panel is open. The reason I want to know whether the panel is open, is that I want to disable certain menu options via - validateUserInterfaceItem while that panel is open. The panel is a sheet that comes down in front of the document window when the document window is first opened (a la Pages or Keynote when they show you templates), and as long as it is down, I don't want users to be able to access the delete line menu option. But, the more I got into trying to solve the problem, the more I became perplexed about self referring to two different objects. Im wondering what is actually going on (independently of whether I get the sheet working). It seems like the sort of thing that might cause other problems. D On 9-Jun-09, at 10:12 AM, Greg Guerin wrote: K. Darcy Otto wrote: -(void)windowWillBeginSheet:(NSNotification *)notification { sheetOpen = YES; NSLog(@self at -windowWillBeginSheet: %@,self); } I would NSLog the before and after state of sheetOpen, i.e. on entry to the method body and on exit from the method body. I might even consider assertions. Please show the code that defines the sheetOpen class variable, and identify exactly where it resides (which class), and how other classes have access to it. I mention this because all the behavior you've described so far is consistent with what happens if sheetOpen isn't actually a class variable or a static variable, but is an instance variable. Finally, please explain what problem you're trying to solve by having a boolean sheetOpen class variable. Is this related to your earlier How to tell if a Panel is Open question? If so, please explain the premise of that question: you wrote, I need to know whether a particular panel is open, but never explained why you need to know that, or what you'd do with that state. -- GG ___ 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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 tell if a Panel is Open
In my -validateUserInterfaceItem: method, I need to know whether a particular panel is open (and this panel comes down as a sheet in front of the main window). How can I determine whether that panel has come down as a sheet? I have tried the following: (1) Setting a flag in -windowWillBeginSheet: and cancelling the flag in -windowWillEndSheet:, and reading that flag in - validateUserInterfaceItem. The problem is that, for some reason I'm not entirely grasping, the flag does not persist when read by - validateUserInterfaceItem:, even though the flag is set up as a BOOL for the class. This behaviour is really surprising to me. (2) Testing the condition ([NSApp isKeyWindow] == [NSApp isMainWindow]), and inferring that the panel is open on NO. The problem with this is that this returns NO when any panel is open, and I only want to know when a particular panel is open. I have the suspicion that the solution to this is easy, but I'm not quite sure what it is. And if anyone could speculate about why (1) is occurring, quite independent of how to solve this problem, I would appreciate it. Thanks. ___ 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 tell if a Panel is Open
Since the link isn't working for me, could you give me an idea of what part and document you are referring to? Is it, by any chance, the - attachedWindow method? I tried this, but I get (null), whether or not the sheet is open. Interestingly, if I send -isSheet to the sheet, I get YES once the sheet has been opened. Any ideas? As some further information, I'm getting really strange behaviour when the sheet is open. For example, if I ask an NSDocument window controller to display the address of self, it gives me a different result whether or not the sheet is open. On Jun 8, 2009, at 2:08 PM, K. Darcy Otto wrote: In my -validateUserInterfaceItem: method, I need to know whether a particular panel is open (and this panel comes down as a sheet in front of the main window). How can I determine whether that panel has come down as a sheet? file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/doc/uid/2013-BCIGEGIB Nick Zitzmann http://www.chronosnet.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
self Changes on Open Panel
I'm having some problems pinning down what is going on when I open a panel: object variables seem to get reset somehow, and self seems to change. Here is some code, from my NSDocument subclass (MyDocument): -(void)windowWillBeginSheet:(NSNotification *)notification { sheetOpen = YES; NSLog(@self at -windowWillBeginSheet: %@,self); } -(BOOL)validateUserInterfaceItem:(id NSValidatedUserInterfaceItem)anItem { if (sheetOpen) NSLog(@sheetOpen = YES); else NSLog(@sheetOpen = NO); NSLog(@self at -validateUserInterfaceItem: %@,self); ... and validation code } And here is the output - with the exception of *: sheetOpen = NO self at -validateUserInterfaceItem: MyDocument: 0x1036290 self at -windowWillBeginSheet: MyDocument: 0x1036290 * sheetOpen = NO self at -validateUserInterfaceItem: MyDocument: 0x102d8f0 The sheet opens at *. Two questions: (i) why is MyDocument at a different address before and after * (incidentally, it changes back to 0x1036290 after the sheet has closed)? (ii) Why is sheetOpen (which is a class variable) not YES after * (in fact, under no circumstances does it return a YES, before, during or after the sheet)? Very puzzling. I can't help but think (i) and (ii) are interconnected in some way (different object implies different object variables), but I can't put my finger on it. Any insights would be appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Help Book: Ask a Question Fails [solved]
Following a hint from Matt Neuburg, I managed to solve this problem by deleting ~/Library/Caches/com.apple.helpui. Incidentally, deleting this file also seems to help when I have another problem. If I delete and regenerate the help book HTML, the old help book is still displayed by the program. I need to delete that cache file in order to get the new help book loaded. For some reason, I don't need to delete the file in order to have changes in the help book recognised (after reindexing with Help Indexer), only when I replace the old book with a new book. But for whatever reason, deleting the cache works. On 4-Jun-09, at 5:24 PM, K.Darcy Otto wrote: I have created a Help Book that is indexed and recognised as part of the Help function, running under Leopard. The Spotlight search works fine (when the user types search terms directly into the help menu). However, when the Help application has started, and the user types a search term into the Ask a question search field, the progress indicator to the left of the search field comes up, and nothing else happens. That is, the progress indicator spins as if its working, but no search terms ever come up. I have abstracts, titles and keywords as part of my help files. Has anyone else encountered this 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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: Backtabbing into an NSTableView
An update on this question. It turns out the first bit of code does not work after all, because 48 is the keyCode for [Tab] and [Shift +Tab]. I needed to change the code to the following: -(void)keyDown:(NSEvent *)theEvent { if ([theEvent keyCode] == 48 ([theEvent modifierFlags] NSShiftKeyMask)) // 48 is the tab key { [self editColumn:1 row:[self selectedRow] withEvent:nil select:YES]; return; } [super keyDown:theEvent]; } Without the return; there is a bing. To tell the truth, I'm not sure why I get the bing. I'm guessing that it has something to do with the responder chain, but the thing is, the table can respond to a backtab. The second bit of code (Code B) works, but it gives a bing at every keypress. Again, I'm thinking this has something to do with the responder chain; but I'm not clear what. Any ideas? On 5-Jun-09, at 5:45 PM, K.Darcy Otto wrote: I have an application where a 2-column NSTableView subclass is the main visual element. Users can select rows only, not columns. When the user has a row selected, and presses [Tab], the table automatically starts editing the first column. I want to make it so that when the user has a row selected, and presses [Shift+Tab] (i.e., a back-tab), the table automatically starts editing the second column (without the following code, it highlights the second- column cell, but does not begin editing). Here is the code in the subclass that I'm currently using to do this: (Code A) -(void)keyDown:(NSEvent *)theEvent { if ([theEvent keyCode] == 48) // 48 is the key code for back-tab { [self editColumn:1 row:[self selectedRow] withEvent:nil select:YES]; } [super keyDown:theEvent]; } My question is, is there a more high-level way to do this? I found 48 corresponding to the back-tab by using NSLog to look at different key codes. I tried replacing 48 NSBacktabTextMovement and NSBackTabCharacter ... no dice, presumably because both NSBacktabTextMovement and NSBackTabCharacter are unicode constants, and -keyCode returns an unsigned short. I suspect I could run this through UCKeyTranslate(), but when playing around with this, I lost my nerve in the face of the 10 parameters that function requires. According to documentation for NSEvent's -keyCode, the number is supposed to be hardware-independent. If this means what I think it means, 48 should be the back-tab in all situations, right? So, the above code should be fine? Incidentally, I have brought about the same effect by the following code: (Code B) - (void)keyDown:(NSEvent *)theEvent { [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; [super keyDown:theEvent]; } -(void)insertBacktab:(id)sender { [self editColumn:1 row:[self selectedRow] withEvent:nil select:YES]; } Is this, in some way, better than the first solution? Or is there some better way to do what I'm trying to do? Thanks. ___ 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
Backtabbing into an NSTableView
I have an application where a 2-column NSTableView subclass is the main visual element. Users can select rows only, not columns. When the user has a row selected, and presses [Tab], the table automatically starts editing the first column. I want to make it so that when the user has a row selected, and presses [Shift+Tab] (i.e., a back-tab), the table automatically starts editing the second column (without the following code, it highlights the second-column cell, but does not begin editing). Here is the code in the subclass that I'm currently using to do this: -(void)keyDown:(NSEvent *)theEvent { if ([theEvent keyCode] == 48) // 48 is the key code for back-tab { [self editColumn:1 row:[self selectedRow] withEvent:nil select:YES]; } [super keyDown:theEvent]; } My question is, is there a more high-level way to do this? I found 48 corresponding to the back-tab by using NSLog to look at different key codes. I tried replacing 48 NSBacktabTextMovement and NSBackTabCharacter ... no dice, presumably because both NSBacktabTextMovement and NSBackTabCharacter are unicode constants, and -keyCode returns an unsigned short. I suspect I could run this through UCKeyTranslate(), but when playing around with this, I lost my nerve in the face of the 10 parameters that function requires. According to documentation for NSEvent's -keyCode, the number is supposed to be hardware-independent. If this means what I think it means, 48 should be the back-tab in all situations, right? So, the above code should be fine? Incidentally, I have brought about the same effect by the following code: - (void)keyDown:(NSEvent *)theEvent { [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; [super keyDown:theEvent]; } -(void)insertBacktab:(id)sender { [self editColumn:1 row:[self selectedRow] withEvent:nil select:YES]; } Is this, in some way, better than the first solution? Or is there some better way to do what I'm trying to do? Thanks. ___ 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
Help Book: Ask a Question Fails
I have created a Help Book that is indexed and recognised as part of the Help function, running under Leopard. The Spotlight search works fine (when the user types search terms directly into the help menu). However, when the Help application has started, and the user types a search term into the Ask a question search field, the progress indicator to the left of the search field comes up, and nothing else happens. That is, the progress indicator spins as if its working, but no search terms ever come up. I have abstracts, titles and keywords as part of my help files. Has anyone else encountered this 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
Field Editor Changes Text Height
I need to trap-and-replace various keypresses in the field editor. I do this with -controlTextDidChange: in my delegate. So, when the user presses , I replace it with a superset of (⊃) character (in case this does not come out on the list, I'm going to represent the superset of character with *s*). Here is the code: -(void)controlTextDidChange:(NSNotification *)aNotification { // Set fieldString to the string showing in the field editor NSMutableString *fieldString = [NSMutableString stringWithString: [fieldEd string]]; // Change to horseshoe in fieldString [fieldString replaceOccurrencesOfString:@ withString:[NSString stringWithFormat:@%C,0x2283] // 0x2283 is *s* options:NSLiteralSearch range:NSMakeRange(0,[fieldString length])]; NSRange selectedRange = [fieldEd selectedRange]; // Where the cursor is before the changes [fieldEd setString:fieldString]; // Set field editor to new string. Cursor will be set to the end of the string [fieldEd setSelectedRange:selectedRange]; // Return cursor to where it should be } Now, this always makes the change. The problem is that in certain circumstances, the font height of some characters in the string, not related to the search-and-replace function, is changed. But only sometimes. For example, if I enter: CC ... this becomes C*ss*C just as it should. But if I enter: C ... this becomes *ss*C*ss* as it should, except the C is a half- height C. Everything else looks normal. I also make other search-and-replaces in the -controlTextDidChange method (I've given only the basic snippet of code), some of which exhibit this problem, and others of which do not. It seems to depend on the replacement string. Some additional background: (1) I have no rich text checked for the relevant text fields in IB. (2) If I copy-and-paste from the field editor into TextEdit, everything looks normal in all cases. (3) When the user presses return and the text is passed to the text field, everything looks normal in all cases. I'm not sure why it is doing this; but more importantly, I'm not sure how to fix it. Any help would be greatly appreciated.___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Field Editor Changes Text Height [solved]
A possible solution is to insert the following line between [fieldEd setString ... and [fieldEd setSelected ... (the two lines at the end of the code): [fieldEd setFont:[NSFont fontWithDescriptor:[[fieldEd font] fontDescriptor] size:[[fieldEd font] pointSize]]]; This will set the font for the entire fieldEd to the same type and size as the first letter. I haven't been able to create any resizing problems with this, presumably because my resizing problem does not crop up in the first character of the field. Or at least, I haven't been able to make it crop up for the first character of the field. I suppose to be safe, you might specify the font directly: [fieldEd setFont:[NSFont fontWithDescriptor:fonttoforce size:sizetoforce]]; On 18-May-09, at 2:46 PM, K. Darcy Otto wrote: I need to trap-and-replace various keypresses in the field editor. I do this with -controlTextDidChange: in my delegate. So, when the user presses , I replace it with a superset of (⊃) character (in case this does not come out on the list, I'm going to represent the superset of character with *s*). Here is the code: -(void)controlTextDidChange:(NSNotification *)aNotification { // Set fieldString to the string showing in the field editor NSMutableString *fieldString = [NSMutableString stringWithString: [fieldEd string]]; // Change to horseshoe in fieldString [fieldString replaceOccurrencesOfString:@ withString:[NSString stringWithFormat:@%C,0x2283] // 0x2283 is *s* options:NSLiteralSearch range:NSMakeRange(0,[fieldString length])]; NSRange selectedRange = [fieldEd selectedRange]; // Where the cursor is before the changes [fieldEd setString:fieldString]; // Set field editor to new string. Cursor will be set to the end of the string [fieldEd setSelectedRange:selectedRange]; // Return cursor to where it should be } Now, this always makes the change. The problem is that in certain circumstances, the font height of some characters in the string, not related to the search-and-replace function, is changed. But only sometimes. For example, if I enter: CC ... this becomes C*ss*C just as it should. But if I enter: C ... this becomes *ss*C*ss* as it should, except the C is a half- height C. Everything else looks normal. I also make other search-and-replaces in the -controlTextDidChange method (I've given only the basic snippet of code), some of which exhibit this problem, and others of which do not. It seems to depend on the replacement string. Some additional background: (1) I have no rich text checked for the relevant text fields in IB. (2) If I copy-and-paste from the field editor into TextEdit, everything looks normal in all cases. (3) When the user presses return and the text is passed to the text field, everything looks normal in all cases. I'm not sure why it is doing this; but more importantly, I'm not sure how to fix it. Any help would be greatly appreciated.___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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: Which field is the NSTextFieldCell drawing?
Thank you. The thing is, the cell object returned by - tableView:willDisplayCell:forTableColumn:row: is not from my NSTextFieldCell subclass but rather the superclass – even though it is the subclass doing the drawing. Any idea how to address the subclass object directly? On 17-May-09, at 6:38 AM, Jim Correia wrote: On Sat, May 16, 2009 at 9:05 PM, K. Darcy Otto do...@csusb.edu wrote: I have an NSTextFieldCell subclass that needs to draw itself differently depending on which NSTableView row it is drawing. My current solution is to store the row that is being drawn in my document class in an instance variable (the assignment is done in -tableView:willDisplayCell:forTableColumn:row:), and have my NSTextFieldCell read out that variable prior to drawing itself. Is there a more direct way to do this? Is it possible to either: (1) Have the NSTextFieldCell subclass look up the row that is currently being drawn, or (2) Store the row to be drawn in an instance variable of the NSTextFieldCell. I think (1) would be the easiest. What is preventing (1) is that I'm not sure how to query the NSTableView to ask it what object is currently being drawn. What is preventing (2) is that I'm not sure how to get a pointer to the NSTextFieldCell subclass object that is about to be drawn, and insert the appropriate information just before it is drawn. -tableView:willDisplayCell:forTableColumn:row: *is* your hook to do this. In that delegate method, set any additional properties on your cell that you need at display time. - Jim ___ 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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: Which field is the NSTextFieldCell drawing?
Hi Jim. You were right; there was a problem with how I was setting up the table column for my cell subclass. It turned out that my subclass was only returned for certain columns in my table (by design), and so I needed to distinguish between columns before calling methods in that subclass. Thanks, Darcy On 17-May-09, at 6:38 AM, Jim Correia wrote: On Sat, May 16, 2009 at 9:05 PM, K. Darcy Otto do...@csusb.edu wrote: I have an NSTextFieldCell subclass that needs to draw itself differently depending on which NSTableView row it is drawing. My current solution is to store the row that is being drawn in my document class in an instance variable (the assignment is done in -tableView:willDisplayCell:forTableColumn:row:), and have my NSTextFieldCell read out that variable prior to drawing itself. Is there a more direct way to do this? Is it possible to either: (1) Have the NSTextFieldCell subclass look up the row that is currently being drawn, or (2) Store the row to be drawn in an instance variable of the NSTextFieldCell. I think (1) would be the easiest. What is preventing (1) is that I'm not sure how to query the NSTableView to ask it what object is currently being drawn. What is preventing (2) is that I'm not sure how to get a pointer to the NSTextFieldCell subclass object that is about to be drawn, and insert the appropriate information just before it is drawn. -tableView:willDisplayCell:forTableColumn:row: *is* your hook to do this. In that delegate method, set any additional properties on your cell that you need at display time. - Jim ___ 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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
Which field is the NSTextFieldCell drawing?
I have an NSTextFieldCell subclass that needs to draw itself differently depending on which NSTableView row it is drawing. My current solution is to store the row that is being drawn in my document class in an instance variable (the assignment is done in - tableView:willDisplayCell:forTableColumn:row:), and have my NSTextFieldCell read out that variable prior to drawing itself. Is there a more direct way to do this? Is it possible to either: (1) Have the NSTextFieldCell subclass look up the row that is currently being drawn, or (2) Store the row to be drawn in an instance variable of the NSTextFieldCell. I think (1) would be the easiest. What is preventing (1) is that I'm not sure how to query the NSTableView to ask it what object is currently being drawn. What is preventing (2) is that I'm not sure how to get a pointer to the NSTextFieldCell subclass object that is about to be drawn, and insert the appropriate information just before it is drawn. Thanks in advance for any 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: Modifying NSTableView cell data just prior to invoking field editor
Yes, I was inserting spaces to achieve a fixed-width indent; things are working much better now, thanks to your suggestion. I tried overriding -titleRectForBounds in my NSTextViewCell subclass, but for some reason, it never gets called (not really sure why). What I ended up doing was overriding -drawInteriorWithFrame:inView:, which does get called, and allowed me to reposition the frame prior to calling super. One problem I ran into is that i need to have a different position for the rect based on the row, but I had no way for the subclass of NSTextViewCell to know which table cell was being drawn. I solved this by creating a variable in the table that gets set with calls in the delegate to -tableView:willDisplayCell:forTableColumn:row:, and this variable can then be read in -drawInteriorWithFrame:inView:. Is there a better way to determine which table cell is getting drawn? Seems a bit kludgy. Thanks for your help. On 30-Apr-09, at 8:49 PM, Jim Correia wrote: On Thu, Apr 30, 2009 at 11:38 PM, K. Darcy Otto do...@csusb.edu wrote: Option 2: Moving the text displayed by the NSTableView to the right by some way other than inserting spaces. This might be the best way, alleviating the need for a custom field editor and editing the field editor text prior to display. I'm not really sure how to do this though. So you are inserted spaces into the value to achieve an fixed width indent? Subclass NSTextFieldCell, and override -titleRectForBounds: to add your left padding. - Jim ___ 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: Repositioning the Field Editor [solved]
Thanks to this suggestion: http://www.cocoabuilder.com/archive/message/cocoa/2009/4/30/235760 I have been able to solve this long-standing problem. The trick with repositioning the field editor, at least within an NSTableView, is to create an NSTextFieldCell subclass, and set the table cell in IB to be an object of that sort. Then, implement the following delegates: // NSTableView may call either selectWithFrame: or editWithFrame:, depending on how editing is invoked. In ecah case, call setFrame:inView:editor:delegate: in order to set the rect to avoid scope lines (pushing it to the left, and squeezing it a comparable amount from the right in order to still fit in the cell. - (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent { NSRect theRect = [self setFrame:aRect inView:controlView editor:textObj delegate:anObject]; [super editWithFrame:theRect inView:controlView editor:textObj delegate:anObject event:theEvent]; } - (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start: (NSInteger)selStart length:(NSInteger)selLength { NSRect theRect = [self setFrame:aRect inView:controlView editor:textObj delegate:anObject]; [super selectWithFrame:theRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength]; } All -setFrame:inView:editor:delegate does is return the desired rect, in a new position. On 29-Apr-09, at 9:58 PM, K. Darcy Otto wrote: So, I have continued my work with a subclass of NSTextView for my field editor, and here is another part of the puzzle: (i) if I implement -drawRect: in the subclass, and ask it for the frame, the frame is the same as the frame set in -viewWillDraw, but not acted upon; (ii) if I implement -drawRect: in the subclass, but do not call super, the field editor box is still drawn at the usual location (the text is not drawn properly, etc., but the box is). This leads me to think that -drawRect is not drawing the box for the field editor. The question is, what object is drawing that box, and is there a way to move it? On 28-Apr-09, at 12:47 PM, K. Darcy Otto wrote: Continuing on with the mystery, I have tried the following code in my NSTableView subclass (below, not yet solved though). I have got it so that the rect returned by [fieldEditor frame] is not empty, but gives exactly the frame it should. Still though, modifying the frame to something different makes no difference. Is there a way to prompt the field editor to redraw itself in accordance with the new frame? In the documentation for -editColumn:row:withEvent:select:, I noticed that it sends - selectWithFrame:inView:editor:delegate:start:length: and - editWithFrame:inView:editor:delegate:event: to the field editor’s NSCell object with the NSTableView as the text delegate. So my call to super is doing that. Could it be that I need to intervene somehow in these NSCell methods? -(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag { [super editColumn:columnIndex row:rowIndex withEvent:theEvent select:flag]; NSTextView *fieldEditor = (NSTextView *)[[self window] fieldEditor:YES forObject:nil]; // Change the text colour to red, just to confirm I've got ahold of the actual field editor that is being used (I do) [fieldEditor setTextColor:[NSColor redColor]]; // Get the field editor frame (it is the correct frame) NSRect cellRect = [fieldEditor frame]; NSLog(@1. fieldEditor x origin: %f,cellRect.origin.x); // output: 127 // Change cellRect x origin, but don't extend the field width cellRect.origin.x += 20; cellRect.size.width -= 20; // Set fieldEditor frame to new cellRect [fieldEditor setFrame:cellRect]; [fieldEditor setNeedsDisplay:YES]; cellRect = [fieldEditor frame]; NSLog(@2. fieldEditor x origin: %f,cellRect.origin.x); // output: 147 } On 27-Apr-09, at 7:19 PM, K. Darcy Otto wrote: I have a field editor which I need to reposition in my tableView – specifically, I need to move it a few pixels to the right. The following post: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/16/232513 makes two suggestions: (i) implement the move in -viewWillDraw in the field editor subclass, and (ii) reposition the field editor after calling super in -editColumn:row:withEvent:select: in the tableView subclass. Neither of these seem to make any difference to where the field editor is drawn. Here is my code with respect to (i), contained in the field editor subclass: -(void)viewWillDraw { NSRect frame = [self frame]; NSLog(@Old: %f,frame.origin.x); frame.origin.x += 50.0; [self setFrame:frame]; frame = [self
Re: Drawing Across NSTableView Columns [solved]
Thank you for the suggestions. It turns out that I went the second way, and it works just fine (to tell you the truth, I was a bit apprehensive at getting into drawing, but it wasn't as difficult as I had suspected - the -frameOfCellAtColumn:row: really made everything not too bad at all). Here is my code, added to the NSTableView subclass, just in case someone else runs into this issue. slp is just an NSArray of 3 integers which represent the beginning row, the ending row, and the depth (how far indented) each of the lines should be. If a line isn't meant to have an end, end=0, and then the line is drawn in blue as opposed to steel. -(void)drawRect:(NSRect)rect { // Draw the table first, by calling drawRect from the superclass [super drawRect:rect]; // Do nothing if no slp's NSArray *slp = [mydoc slp]; NSUInteger slpCount = [slp count]; if (slpCount == 0) return; NSColor *blueish = [NSColor colorWithDeviceRed:0.0 green:.5 blue:1.0 alpha:.75]; // Some sort of blue NSColor *steelish = [NSColor colorWithDeviceRed:.5797 green:.5797 blue:.5797 alpha:.75]; // Some sort of steel BOOL endToLine; for (NSUInteger i=0; islpCount; i++) { NSBezierPath *thePath = [NSBezierPath bezierPath]; [thePath setLineWidth:2.0]; // Find starting point for line NSUInteger beginAtRow = [[slp objectAtIndex:i] begin]; NSUInteger endAtRow = [[slp objectAtIndex:i] end]; NSUInteger depth = [[slp objectAtIndex:i] depth]; // If endAtRow is zero, run the line to the bottom of the table if (endAtRow == 0) { endAtRow = [datasource rowCount]-1; // Set pen colour to blueish [blueish set]; // Flag no end to line endToLine = NO; } else { // Set pen colour to steelish [steelish set]; // Flag endToLine endToLine = YES; } NSRect beginAtRowRect = [self frameOfCellAtColumn:[self columnWithIdentifier:@F] row:beginAtRow]; NSRect endAtRowRect = [self frameOfCellAtColumn:[self columnWithIdentifier:@F] row:endAtRow]; NSPoint beginPoint, endPoint; beginPoint.y = beginAtRowRect.origin.y + beginAtRowRect.size.height/ 2.0; beginPoint.x = beginAtRowRect.origin.x + depth*7.0; endPoint.y = endAtRowRect.origin.y + endAtRowRect.size.height/2.0; endPoint.x = endAtRowRect.origin.x + depth*7.0; [thePath setLineCapStyle:NSSquareLineCapStyle]; [thePath setLineJoinStyle:NSRoundLineJoinStyle]; // Move to starting location, and draw the line [thePath moveToPoint:(NSMakePoint(beginPoint.x+5, beginPoint.y))]; [thePath lineToPoint:beginPoint]; [thePath lineToPoint:endPoint]; if (endToLine) [thePath lineToPoint:(NSMakePoint(endPoint.x+5, endPoint.y))]; [thePath stroke]; } } ___ 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: Changing a custom field editor's position
Hi Ulai, Did you find a solution to this problem? I'm trying to do the same thing. Darcy Hi, Let's say I want to have the field editor for a table view appear 2 pixel below where it usually is, i.e. shifted 2 pixels down. How can I do this? Consider the following hypothetical situation: If I subclass NSTextView and override the drawRect method like this, - (void)drawRect:(NSRect)rect { NSRect frame = [self frame]; frame.origin.x += 5.0; [self setFrame:frame]; [super drawRect:rect]; } and use this subclass for the field editor of my table view, no changes occur. But shouldn't this custom field editor move by 5.0 pixels to the right on and on until it finally disappears and becomes invisible? But for some reasons that does not happen. This means that setting the frame's origin apparently has no effect. And that is essentially why I'm all blank on how to reposition the field editor. Any ideas? Thanks, U ___ 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: Repositioning the Field Editor
So, I have continued my work with a subclass of NSTextView for my field editor, and here is another part of the puzzle: (i) if I implement -drawRect: in the subclass, and ask it for the frame, the frame is the same as the frame set in -viewWillDraw, but not acted upon; (ii) if I implement -drawRect: in the subclass, but do not call super, the field editor box is still drawn at the usual location (the text is not drawn properly, etc., but the box is). This leads me to think that -drawRect is not drawing the box for the field editor. The question is, what object is drawing that box, and is there a way to move it? On 28-Apr-09, at 12:47 PM, K. Darcy Otto wrote: Continuing on with the mystery, I have tried the following code in my NSTableView subclass (below, not yet solved though). I have got it so that the rect returned by [fieldEditor frame] is not empty, but gives exactly the frame it should. Still though, modifying the frame to something different makes no difference. Is there a way to prompt the field editor to redraw itself in accordance with the new frame? In the documentation for -editColumn:row:withEvent:select:, I noticed that it sends - selectWithFrame:inView:editor:delegate:start:length: and - editWithFrame:inView:editor:delegate:event: to the field editor’s NSCell object with the NSTableView as the text delegate. So my call to super is doing that. Could it be that I need to intervene somehow in these NSCell methods? -(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag { [super editColumn:columnIndex row:rowIndex withEvent:theEvent select:flag]; NSTextView *fieldEditor = (NSTextView *)[[self window] fieldEditor:YES forObject:nil]; // Change the text colour to red, just to confirm I've got ahold of the actual field editor that is being used (I do) [fieldEditor setTextColor:[NSColor redColor]]; // Get the field editor frame (it is the correct frame) NSRect cellRect = [fieldEditor frame]; NSLog(@1. fieldEditor x origin: %f,cellRect.origin.x); // output: 127 // Change cellRect x origin, but don't extend the field width cellRect.origin.x += 20; cellRect.size.width -= 20; // Set fieldEditor frame to new cellRect [fieldEditor setFrame:cellRect]; [fieldEditor setNeedsDisplay:YES]; cellRect = [fieldEditor frame]; NSLog(@2. fieldEditor x origin: %f,cellRect.origin.x); // output: 147 } On 27-Apr-09, at 7:19 PM, K. Darcy Otto wrote: I have a field editor which I need to reposition in my tableView – specifically, I need to move it a few pixels to the right. The following post: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/16/232513 makes two suggestions: (i) implement the move in -viewWillDraw in the field editor subclass, and (ii) reposition the field editor after calling super in -editColumn:row:withEvent:select: in the tableView subclass. Neither of these seem to make any difference to where the field editor is drawn. Here is my code with respect to (i), contained in the field editor subclass: -(void)viewWillDraw { NSRect frame = [self frame]; NSLog(@Old: %f,frame.origin.x); frame.origin.x += 50.0; [self setFrame:frame]; frame = [self frame]; NSLog(@New: %f,frame.origin.x); [super viewWillDraw]; } Now, I can confirm this method is being called, and by means of the NSLog statements, the frame is being changed prior to the call to super. Unfortunately, the field editor is drawn where is usually is drawn, with no shift in place. With respect to (ii), contained in the tableView subclass: -(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag { [super editColumn:columnIndex row:rowIndex withEvent:theEvent select:flag]; NSText *fieldEditor = [[self window] fieldEditor:YES forObject:self]; NSRect fieldEditorFrame = [fieldEditor frame]; fieldEditorFrame.origin.x += 50.0; [fieldEditor setFrame:fieldEditorFrame]; } Here, it turns out that even though fieldEditor points to the custom field editor object, fieldEditorFrame turns out to be empty. And again, the field editor is drawn where it is usually drawn, with no shift in place. Any help would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/dotto%40csusb.edu This email sent to do...@csusb.edu ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests
Re: Repositioning the Field Editor
Continuing on with the mystery, I have tried the following code in my NSTableView subclass (below, not yet solved though). I have got it so that the rect returned by [fieldEditor frame] is not empty, but gives exactly the frame it should. Still though, modifying the frame to something different makes no difference. Is there a way to prompt the field editor to redraw itself in accordance with the new frame? In the documentation for -editColumn:row:withEvent:select:, I noticed that it sends -selectWithFrame:inView:editor:delegate:start:length: and -editWithFrame:inView:editor:delegate:event: to the field editor’s NSCell object with the NSTableView as the text delegate. So my call to super is doing that. Could it be that I need to intervene somehow in these NSCell methods? -(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag { [super editColumn:columnIndex row:rowIndex withEvent:theEvent select:flag]; NSTextView *fieldEditor = (NSTextView *)[[self window] fieldEditor:YES forObject:nil]; // Change the text colour to red, just to confirm I've got ahold of the actual field editor that is being used (I do) [fieldEditor setTextColor:[NSColor redColor]]; // Get the field editor frame (it is the correct frame) NSRect cellRect = [fieldEditor frame]; NSLog(@1. fieldEditor x origin: %f,cellRect.origin.x); // output: 127 // Change cellRect x origin, but don't extend the field width cellRect.origin.x += 20; cellRect.size.width -= 20; // Set fieldEditor frame to new cellRect [fieldEditor setFrame:cellRect]; [fieldEditor setNeedsDisplay:YES]; cellRect = [fieldEditor frame]; NSLog(@2. fieldEditor x origin: %f,cellRect.origin.x); // output: 147 } On 27-Apr-09, at 7:19 PM, K. Darcy Otto wrote: I have a field editor which I need to reposition in my tableView – specifically, I need to move it a few pixels to the right. The following post: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/16/232513 makes two suggestions: (i) implement the move in -viewWillDraw in the field editor subclass, and (ii) reposition the field editor after calling super in -editColumn:row:withEvent:select: in the tableView subclass. Neither of these seem to make any difference to where the field editor is drawn. Here is my code with respect to (i), contained in the field editor subclass: -(void)viewWillDraw { NSRect frame = [self frame]; NSLog(@Old: %f,frame.origin.x); frame.origin.x += 50.0; [self setFrame:frame]; frame = [self frame]; NSLog(@New: %f,frame.origin.x); [super viewWillDraw]; } Now, I can confirm this method is being called, and by means of the NSLog statements, the frame is being changed prior to the call to super. Unfortunately, the field editor is drawn where is usually is drawn, with no shift in place. With respect to (ii), contained in the tableView subclass: -(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag { [super editColumn:columnIndex row:rowIndex withEvent:theEvent select:flag]; NSText *fieldEditor = [[self window] fieldEditor:YES forObject:self]; NSRect fieldEditorFrame = [fieldEditor frame]; fieldEditorFrame.origin.x += 50.0; [fieldEditor setFrame:fieldEditorFrame]; } Here, it turns out that even though fieldEditor points to the custom field editor object, fieldEditorFrame turns out to be empty. And again, the field editor is drawn where it is usually drawn, with no shift in place. Any help would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Repositioning the Field Editor
I have a field editor which I need to reposition in my tableView – specifically, I need to move it a few pixels to the right. The following post: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/16/232513 makes two suggestions: (i) implement the move in -viewWillDraw in the field editor subclass, and (ii) reposition the field editor after calling super in -editColumn:row:withEvent:select: in the tableView subclass. Neither of these seem to make any difference to where the field editor is drawn. Here is my code with respect to (i), contained in the field editor subclass: -(void)viewWillDraw { NSRect frame = [self frame]; NSLog(@Old: %f,frame.origin.x); frame.origin.x += 50.0; [self setFrame:frame]; frame = [self frame]; NSLog(@New: %f,frame.origin.x); [super viewWillDraw]; } Now, I can confirm this method is being called, and by means of the NSLog statements, the frame is being changed prior to the call to super. Unfortunately, the field editor is drawn where is usually is drawn, with no shift in place. With respect to (ii), contained in the tableView subclass: -(void)editColumn:(NSInteger)columnIndex row:(NSInteger)rowIndex withEvent:(NSEvent *)theEvent select:(BOOL)flag { [super editColumn:columnIndex row:rowIndex withEvent:theEvent select:flag]; NSText *fieldEditor = [[self window] fieldEditor:YES forObject:self]; NSRect fieldEditorFrame = [fieldEditor frame]; fieldEditorFrame.origin.x += 50.0; [fieldEditor setFrame:fieldEditorFrame]; } Here, it turns out that even though fieldEditor points to the custom field editor object, fieldEditorFrame turns out to be empty. And again, the field editor is drawn where it is usually drawn, with no shift in place. Any help would be greatly appreciated.___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Drawing Across NSTableView Columns
I'm attempting to model a real-world table structure with an NSTableView. Here is what the table structure might look like on paper (warning: ASCII art ahead): 1. | A 2. || B 3. |||C 4. D 5. E 6. F Between the number and the letters are a series of (unbroken) vertical lines, running from the row where they were first drawn, to a row where it ends. Where each line begins and ends depends on various things going on in the table. Also, each additional line creates an indent in the letters column. The problem is, how do I model this in an NSTableView? I have considered: (a) Just using a series of pipes (|), to which the letter is appended as the return value for -tableView:objectValueForTableColumn:row: (int)row. This could work, except that as long as the pipes are not vertically connected, it looks very ugly. (b) Creating an image of the lines that is then somehow overlaid on the table to give the right effect. (c) I read about setting the background colour of a table to a pattern, which might be based on an image here: http://www.cocoabuilder.com/archive/message/cocoa/2004/6/21/110256 I'm not sure whether this would work. (d) I read about drawing within a custom NSTextField Cell here: http://www.cocoabuilder.com/archive/message/cocoa/2004/3/1/100423 I think this might still make the image break at each row. Regarding (a), I was thinking maybe playing with the line thickness between rows, and then making a pipe (|) that is too big to fit within the cell might work; but I'm not really sure. Any ideas how I should go about this? Thanks. ___ 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
Undo (UI Concept)
I am writing a program which has a two-column table. The user can fill in the table with whatever he or she wishes, but sometimes it is possible to determine what should be displayed in the left column by looking at what is displayed in the right column. I have set up the program so that a user can turn on an inference function, so if the user has: Column 1: Blank Column 2: X Then the program will automatically fill in A for column 1 (because there is no other possibility, given the X in column 2). So the table now looks like this: Column 1: A Column 2: X Now, the question is, how to implement undo. There are at least two possibilities: (1) Undo returns column 2 to its previous state, before X was entered. An additional undo is required to revert column 1 to blank. (2) Undo returns column 2 to its previous state, and column 1 to blank. I'm not sure what is best, from the perspective of designing a UI. I have currently implemented (2), but I have a sneaking suspicion (1) might be more appropriate. Note that the A in column 1 is inferred, but there is nothing wrong or odd with it standing alone. Thanks. ___ 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: Undo (UI Concept)
Yes, I was thinking this too, at first. But then I started to look around to see if I could find analogous situations. The closest I can come is when Pages has a table - let's say 2x2. When the user is in the bottom right cell, and presses tab, two things happen simultaneously: the data is accepted in that cell, and a new line is added to the bottom of the table. When it comes to undoing, the undo add line is first, then undo typing is second. I know this isn't exactly the same, but it does seem to be two undos for one action – and it would be strange for it not to be (that is, to lose the new line, and the typing, all at once). On 17-Apr-09, at 9:33 AM, Clark Cox wrote: IMHO, if the user performed a single action to get to the current state, then it shouldn't take more than one undo to get to the previous state. So, as a user, I'd prefer #2. On Fri, Apr 17, 2009 at 9:26 AM, K.Darcy Otto do...@csusb.edu wrote: I am writing a program which has a two-column table. The user can fill in the table with whatever he or she wishes, but sometimes it is possible to determine what should be displayed in the left column by looking at what is displayed in the right column. I have set up the program so that a user can turn on an inference function, so if the user has: Column 1: Blank Column 2: X Then the program will automatically fill in A for column 1 (because there is no other possibility, given the X in column 2). So the table now looks like this: Column 1: A Column 2: X Now, the question is, how to implement undo. There are at least two possibilities: (1) Undo returns column 2 to its previous state, before X was entered. An additional undo is required to revert column 1 to blank. (2) Undo returns column 2 to its previous state, and column 1 to blank. I'm not sure what is best, from the perspective of designing a UI. I have currently implemented (2), but I have a sneaking suspicion (1) might be more appropriate. Note that the A in column 1 is inferred, but there is nothing wrong or odd with it standing alone. -- Clark S. Cox III clarkc...@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
NSDocument Object Changing
I am writing a document-based application, and seem to be having a problem with my NSDocument object (using the standard MyDocument.h/m) changing. In particular, I have a toolbar button that brings up a previously populated NSWindowController and shows a window and a panel). The problem appears in three stages: (1) When MyDocument is initialised, NSLog(@%@,self); returns x. (2) When the toolbar button is clicked, the appropriate panel comes up, and NSLog(@%@,self); returns x. (3) When the toolbar button is clicked a second time, NSLog(@%@,self); returns y (where x is not the same address as y). Now as far as I can tell, there is no alloc/init (this only happens in the designated initialiser) or copy of MyDocument (there is an assign of MyDocument to the NSWindowController object so I can call back to methods in MyDocument.m). Note that if I click on the toolbar button a third time, NSLog(@%@,self); returns y. I can't seem to figure out how the new MyDocument object is being created. Any help would be appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSSlider with mouseUp
I have a preferences window with an NSSlider control in it that has to update continuously in order to indicate just where the marker is on the scale. But, because of the relatively complex changes required when the slider is set, I only want to act on the slider settings when the slider has been released. I'm not sure the best way to do this. I have tried: (i) Overriding mouseUp: in the view. The problem with this is that mouseUp is never called. (ii) Subclassing NSSlider and overriding mouseUp. This gets closer. The problem with this is that the slider is not able to be moved (even though it is enabled in IBOutlet). Any ideas would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Changing NSTableView cell immediately before editing [solved?]
Thanks Corbin and Paul. I am using the windowWillReturnFieldEditor:toObject: delegate method, testing to see if anObject is a DeductionTable (a subclass of NSTextView), and testing to see if the first responder is an NSTextView, and then changing the textColor of the first responder to black. This changes the text to black before the user edits anything, so it works. Here is the code: -(id)windowWillReturnFieldEditor:(NSWindow *)sender toObject: (id)anObject { if ([anObject isKindOfClass:[DeductionTable class]] [[[deductionTable window] firstResponder] isKindOfClass:[NSTextView class]]) { NSTextView *firstResponder = (NSTextView *)[[deductionTable window] firstResponder]; [firstResponder setTextColor:[NSColor blackColor]]; return firstResponder; } return nil; } I do wonder about the efficiency of this though. It turns out that this method is called dozens of times for a single edit. Can this really be the right way to solve the problem? On 4-Mar-09, at 1:04 AM, Paul Sanders wrote: Thanks for this. I think this would solve part of the problem (when it was clicked on by the user), but not if the text edit field were selected in some way other than a mouse click. I thought about this a little bit too. It seems to me that the change in firstResponser is the key to this. I don't know how to trap this - I'm new to Cocoa - but maybe that observation helps a bit. Rgds - Paul. ___ 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: Changing NSTableView cell immediately before editing
Well, I've tried just about everything I can think of at this point, but can't change the NSTableView cell successfully. To give some more detail, the cell text is red when there is an error, but when the user goes to edit the cell, I want to change the cell text back to black. I can change the cell text from red to black when the user first begins to edit the text, with the following code: -(void)controlTextDidBeginEditing:(NSNotification *)notification { fieldEd = [[notification userInfo] objectForKey:@NSFieldEditor]; // Change the field editor text color to black (since it is being edited) [fieldEd setTextColor:[NSColor blackColor]]; } But this only works when the user hits a key. What I would like to do is change the text from red to black when the user enters the cell for editing, but before the user hits any key. I think what I need is a controlTextMightBeginEditing instead of controlTextDidBeginEditing. ;-) Any ideas? Thanks in advance. On 2-Mar-09, at 8:11 AM, K.Darcy Otto wrote: I want to change the contents of an NSTableView cell immediately prior to editing, but cannot figure out how to do this. That is, I want to return YES to tableView:aTableView:shouldEditTableColumn:row:, to permit editing to begin, but before editing actually begins, modify the colour and text of the cell that is going to be edited. I was thinking about putting the code into tableView:aTableView:shouldEditTableColumn:row:; but I'm pretty sure this would not be good form; and in any case, that method is called more than once at the beginning of an edit. Any help would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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: Changing NSTableView cell immediately before editing
Thanks for this. I think this would solve part of the problem (when it was clicked on by the user), but not if the text edit field were selected in some way other than a mouse click. But you gave me an idea: what about subclassing NSTextView, so that when the field editor is called, the change from red to black is triggered? Does anyone know what method is called when the field editor is displayed to edit the cell of an NSTableView (I dug around in the docs a bit, but I'm couldn't find it)? On 3-Mar-09, at 7:37 AM, Paul Sanders wrote: I think what I need is a controlTextMightBeginEditing instead of controlTextDidBeginEditing. ;-) Override -mouseDown, call [super], then check the first responder? If it's a text edit field, fade to black. Something like that anyway, I know not precisely of what I speak. ___ 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
Changing NSTableView cell immediately before editing
I want to change the contents of an NSTableView cell immediately prior to editing, but cannot figure out how to do this. That is, I want to return YES to tableView:aTableView:shouldEditTableColumn:row:, to permit editing to begin, but before editing actually begins, modify the colour and text of the cell that is going to be edited. I was thinking about putting the code into tableView:aTableView:shouldEditTableColumn:row:; but I'm pretty sure this would not be good form; and in any case, that method is called more than once at the beginning of an edit. Any help would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Window Animation with setFrame:display:animate: Flickers [solved]
Thank you for the hints. I eventually solved this problem by setting up a box that took up the whole window in IB, and setting the autosizing so that it resized automatically with the window. I then set the content view of the box with the view. The flickering has stopped when the window is resized. Here is the code I used: -(void)displayViewController:(NSViewController *)vc { NSWindow *w = [box window]; NSView *v = [vc view]; // Compute the new window frame NSSize currentSize = [[box contentView] frame].size; NSSize newSize = [v frame].size; float deltaWidth = newSize.width - currentSize.width; float deltaHeight = newSize.height - currentSize.height; NSRect windowFrame = [w frame]; windowFrame.size.height += deltaHeight; windowFrame.origin.y -= deltaHeight; windowFrame.size.width += deltaWidth; [box setContentView:nil]; [w setFrame:windowFrame display:YES animate:YES]; [box setContentView:v]; } On 21-Feb-09, at 11:58 AM, Markus Spoettl wrote: On Feb 21, 2009, at 8:03 PM, K. Darcy Otto wrote: I had considered doing this with Core Animation, but it just seems simpler to get this working. Here is the code that I'm using (adapted from Hillegass, Chapter 29): -(void)displayViewController:(NSViewController *)vc { NSWindow *w = [self window]; NSView *v = [vc view]; // Compute the new window frame NSSize currentSize = [[w contentView] frame].size; NSSize newSize = [v frame].size; float deltaWidth = newSize.width - currentSize.width; float deltaHeight = newSize.height - currentSize.height; NSRect windowFrame = [w frame]; windowFrame.size.height += deltaHeight; windowFrame.origin.y -= deltaHeight; windowFrame.size.width += deltaWidth; [w setContentView:nil]; [w setFrame:windowFrame display:YES animate:YES]; [w setContentView:v]; } You probably shouldn't replace the content view with your own view. The content view is a container that is managed by the window (resized to the window's specifications as the window resizes, for example). Instead of replacing it you probably want to add your view as a sub-view of the content view, something like this: // todo: set this up to your liking NSRect contentBounds = [[w contentView] bounds]; // fill content view entirely [v setFrame:contentBounds]; // adjust width and height to content view/window [v setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [[w contentView] addSubview:v]; [w setFrame:windowFrame display:YES animate:YES]; Warning, programmed in Mail.app Markus -- __ Markus Spoettl ___ 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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
Radio Buttons not Selecting Properly
I have a window in which I'm swapping views. The mechanism by which the user indicates the view should be swapped is a series of four radio buttons (so, it is sort of like having a tab view, except instead of tabs up the top, there are radio buttons in the view itself). The radio buttons are in a matrix. The views correspond to the radio button that should be selected. So, view 0 should have radio button 0 selected; view 1 should have radio button 1 selected; and so on. When view 0 is being displayed, and the user clicks on radio button 1, view 0 is automatically swapped out for view 1, and radio button 1 is selected in view 1. The problem is, this only happens the first time the user clicks on radio button 1. The rest of the time, the view changes, but the radio button selection does not change. How do I force the radio button to change each time a new view is swapped in? The strange thing is, I have used bindings to bind the radio button that is clicked to a variable, and the variable shows the right value. The selection doesn't change though, except for the first time the button is clicked. Any help would be greatly appreciated. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Window Animation with setFrame:display:animate: Flickers
I had considered doing this with Core Animation, but it just seems simpler to get this working. Here is the code that I'm using (adapted from Hillegass, Chapter 29): -(void)displayViewController:(NSViewController *)vc { NSWindow *w = [self window]; NSView *v = [vc view]; // Compute the new window frame NSSize currentSize = [[w contentView] frame].size; NSSize newSize = [v frame].size; float deltaWidth = newSize.width - currentSize.width; float deltaHeight = newSize.height - currentSize.height; NSRect windowFrame = [w frame]; windowFrame.size.height += deltaHeight; windowFrame.origin.y -= deltaHeight; windowFrame.size.width += deltaWidth; [w setContentView:nil]; [w setFrame:windowFrame display:YES animate:YES]; [w setContentView:v]; } This works as expected (except for flickering). That is, the window resizes to fit views of different sizes. I found I can actually stop the flickering if I comment out the [w setContentView:nil]; line, except then the window resizing gets all messed up. To tell you the truth, I'm not sure why [w setContentView:nil]; makes such a difference, to the flickering or to the resizing. On 21-Feb-09, at 3:14 AM, Mike Abdullah wrote: Did you need to target anything pre-Leopard? If not, I'd recommend using Core Animation instead of this method. It'll have the advantage of being GPU-powered and more importantly won't block the main thread during the animation (I frequently try to move the System Prefs somewhere more convenient while a pane is loading, and it annoyingly snaps back into place). Mike. On 21 Feb 2009, at 02:31, K. Darcy Otto wrote: I have a window, and get that window to resize according to the various custom views I plop in the window. My purpose here is to (somewhat) emulate the system preferences window that grows and shrinks as necessary. The resizing works fine, but when I want to animate the resizing, there is a lot of flickering in the window. Here is the short bit of code: [w setContentView:nil]; [w setFrame:windowFrame display:YES animate:YES]; [w setContentView:v]; ... where w is an NSWindow, and v is an NSView. windowFrame is the recalculated window size that fits the view. So far, I have tried to solve the flickering by subclassing NSWindow and implementing the following override: - (NSTimeInterval)animationResizeTime:(NSRect)newFrame { return 1.0; } But while this does slow down the animation significantly, it simply makes the flickering slower. Is there a way to use setFrame:display:animate: so that the background of the window does not flicker? Thanks. ___ 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/cocoadev%40mikeabdullah.net This email sent to cocoa...@mikeabdullah.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
Window Animation with setFrame:display:animate: Flickers
I have a window, and get that window to resize according to the various custom views I plop in the window. My purpose here is to (somewhat) emulate the system preferences window that grows and shrinks as necessary. The resizing works fine, but when I want to animate the resizing, there is a lot of flickering in the window. Here is the short bit of code: [w setContentView:nil]; [w setFrame:windowFrame display:YES animate:YES]; [w setContentView:v]; ... where w is an NSWindow, and v is an NSView. windowFrame is the recalculated window size that fits the view. So far, I have tried to solve the flickering by subclassing NSWindow and implementing the following override: - (NSTimeInterval)animationResizeTime:(NSRect)newFrame { return 1.0; } But while this does slow down the animation significantly, it simply makes the flickering slower. Is there a way to use setFrame:display:animate: so that the background of the window does not flicker? Thanks. ___ 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: Window Animation with setFrame:display:animate: Flickers
Some additional information that I just discovered: when the window is textured, it does not flicker at all, but if not textured, it flickers noticeably. On 20-Feb-09, at 6:31 PM, K. Darcy Otto wrote: I have a window, and get that window to resize according to the various custom views I plop in the window. My purpose here is to (somewhat) emulate the system preferences window that grows and shrinks as necessary. The resizing works fine, but when I want to animate the resizing, there is a lot of flickering in the window. Here is the short bit of code: [w setContentView:nil]; [w setFrame:windowFrame display:YES animate:YES]; [w setContentView:v]; ... where w is an NSWindow, and v is an NSView. windowFrame is the recalculated window size that fits the view. So far, I have tried to solve the flickering by subclassing NSWindow and implementing the following override: - (NSTimeInterval)animationResizeTime:(NSRect)newFrame { return 1.0; } But while this does slow down the animation significantly, it simply makes the flickering slower. Is there a way to use setFrame:display:animate: so that the background of the window does not flicker? Thanks. ___ 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/dotto%40csusb.edu This email sent to do...@csusb.edu ___ 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: Undo for non-document based applications
On 10-Dec-08, at 8:54 PM, Graham Cox wrote: On 11 Dec 2008, at 2:53 pm, K. Darcy Otto wrote: I'm trying to get undo working with an application that is not document-based. So far, I think I have got the operation on the stack, but have yet to get the menu reflecting this. What I have so far is the initialisation of undoMan (in init:), but when I get the operation onto the stack (by the last method, observeValueForKeyPath:), the undo menu item does not get activated. If I add the line: undoMan = [[NSUndoManager alloc] init]; To ensure that the menu is correctly linked to this undo manager, you need to use: -windowWillReturnUndoManager: which is a delegate method of NSWindow. If you set your AppController to be the window's delegate and implement this method to return undoMan, you should find the menu works as you want. That solves the problem. I just made AppController the delegate, as you suggested, and then added this code: - (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)sender { return undoMan; } And it worked like a charm. Thank you! ___ 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
Undo for non-document based applications
I'm trying to get undo working with an application that is not document-based. So far, I think I have got the operation on the stack, but have yet to get the menu reflecting this. What I have so far is the initialisation of undoMan (in init:), but when I get the operation onto the stack (by the last method, observeValueForKeyPath:), the undo menu item does not get activated. If I add the line: NSLog(@Menu item title = %@,[undoMan undoMenuItemTitle]); I get Menu item title = Undo Value Change, so I take this as confirmation that the action is added to the stack (or at least the setActionName is changed). I suspect the problem is that while the operation gets added to the undo stack, the undo menu in the application is not properly hooked up to undoMan. I'm not sure how to do this (or even if this is the problem). Any help would be appreciated. -do [Code for AppController.m below:] @implementation AppController @synthesize fido; -(id)init { [super init]; [self setValue:[NSNumber numberWithInt:5] forKey:@fido]; NSNumber *n = [self valueForKey:@fido]; [self addObserver:self forKeyPath:@fido options:NSKeyValueObservingOptionOld context:[[NSString alloc] initWithString:@fido has changed]]; undoMan = [[NSUndoManager alloc] init]; return self; } -(IBAction)incrementFido:(id)sender { [self willChangeValueForKey:@fido]; fido++; [self didChangeValueForKey:@fido]; } - (void)changeKeyPath:(NSString *)keyPath ofObject:(id)obj toValue: (id)newValue { //setValue:forKeyPath: will cause the key-value observing method //to be called, which takes care of the undo stuff [obj setValue:newValue forKeyPath:keyPath]; } -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSNumber *oldValue = [change objectForKey:NSKeyValueChangeOldKey]; [[undoMan prepareWithInvocationTarget:self] changeKeyPath:keyPath ofObject:object toValue:oldValue]; [undoMan setActionName:@Value Change]; } @end ___ 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 [EMAIL PROTECTED]
Re: How to adopt a superclass's protocol?
The casting worked, and the protocol gets found; but I'm still getting a warning that the protocol is not found. Here's what I have: Superclass.h: @protocol Check; Superclass.m: @protocol Check @optional -(BOOL)optionalMethodToImplement; @end (I'm relegating the protocol to the .m file to make it private in a sense.) Subclass.h @interface Subclass : Superclass Check ... Now, the compiler issues a warning at the @interface line in Subclass.h - no definition of protocol 'Check' is found. But it is clear that the protocol is being located at runtime nevertheless, because if I eliminate Check from the @interface line, optionalMethodToImplement: does not get called. Also, what is interesting is that if I move @protocol Check ... @end in Superclass.m to Superclass.h, the warning goes away. So, is there a way to keep @protocol Check ... @end in Superclass.m and eliminate the warning? Thanks. On 28-Apr-08, at 11:25 PM, Michael Vannorsdel wrote: You can make the superclass's method look like this: - (void)doSomething { if([self conformsToProtocol:@protocol(Check)]) [(SuperClass Check *)self optionalMethodToImplement]; } The cast eliminates the compiler warning. As far as making it private it depends what you mean by that. If you don't want it visible in headers you're going to distribute you can put: @protocol Check; in the public header then actually define the whole protocol in a private undistributed header. On Apr 28, 2008, at 9:22 PM, K. Darcy Otto wrote: Okay, I have done this, and things are compiling and running correctly. Thank you. Two additional questions then. First, I still get the warning that the superclass may not respond to the method (and to be sure, it is only implemented in the subclass, but the superclass calls it after a conformsToProtocol: check). Second, I would like the optionalMethodToImplement to be private - usually I put this in the .m file under a category; but when I do that with the protocol, the subclass cannot locate the protocol. Any suggestions? ___ 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/dotto%40csusb.edu This email sent to [EMAIL PROTECTED] ___ 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 [EMAIL PROTECTED]
How to adopt a superclass's protocol?
I need to have a subclass optionally extend a method already in the superclass. After some research, my best guess is that an optionally defined protocol is the best way to go about this. So, what I have in the superclass is: @interface ClassA : NSObject { ... } ... @end @protocol Check @optional -(BOOL)optionalMethodToImplement; @end Now, I don't want the superclass to implement it, so when it comes to the actual method that needs to be extended, I do the following: -(BOOL)checkMethod { ... stuff ... if ([self conformsToProtocol:@protocol(Check)]) [self optionalMethodToImplement]; } Problem #1: The compiler complains that ClassA may not respond to optionalMethodToImplement. Then I have: @interface ClassB : ClassA { ... } ... @end @interface ClassB (private) Check -(BOOL)optionalMethodToImplement; @end Problem #2: The compiler cannot find the protocol in the superclass. I realise I could do the same thing by having a dummy method in the superclass, and override that in the subclass. And I'm about to head down that path; but it seems like there should be a way to do this with protocols. Thanks in advance. ___ 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 [EMAIL PROTECTED]
Subclassing
I am working on a program with a complex hierarchy of classes, and I want to subclass one of the objects a few steps down on that hierarchy. Do I have to create a parallel hierarchy to do this? Here is the problem: AppController instantiates a Deduction object. The Deduction object instantiates a DeductionLine object. The DeductionLine object instantiates a Dependency object. I want to subclass Dependency and override a few things. Can I do this without modifying DeductionLine? As it stands, I think I'm going to have to do this: AppController instantiates a SDeduction object (where SDeduction is a subclass of Deduction). The SDeduction object instantiates a SDeductionLine object (where SDeductionLine is a subclass of DeductionLine). The SDeduction object instantiates a SDependency object (where SDependency is a subclass of Dependency). The only reason to subclass Deduction (with SDeduction) and then DeductionLine (with SDeductionLine) is to get an SDependency object. Is there an easier way? I suppose I could just copy the Dependency class files and then modify it for this particular project; but I was hoping for a different way. Thanks. ___ 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 [EMAIL PROTECTED]
addObjectsToArray: behaving badly - why?
My code used to look like this: NSMutableArray *newDependencies = [self.dependencies mutableCopy]; [newDependencies addObjectsFromArray:[aDependency dependencies]]; Now self.dependencies and [aDependency dependencies] both return NSArrays. The code works very well provided that the array returned by self.dependencies does not have 0 objects in it. But if the array returned by self.dependencies does have 0 objects in it, then newDependencies still has 0 objects in it after addObjectsFromArray is executed. I was able to correct this behaviour with the following code: NSMutableArray *newDependencies = [[NSMutableArray alloc] init]; [newDependencies addObjectsFromArray:self.dependencies]; [newDependencies addObjectsFromArray:[aDependency dependencies]]; This works fine even when the array returned by self.dependencies has 0 objects. But I'm puzzled as to why it functions differently than the first version. Any ideas? ___ 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 [EMAIL PROTECTED]
Re: Restoring Tiger NSTableView behaviour in Leopard
On 11-Apr-08, at 1:07 PM, Corbin Dunn wrote: On Apr 11, 2008, at 11:38 AM, K. Darcy Otto wrote: The application I am working on is essentially one big table, and I'd like to restore at least one aspect the default tab behaviour that Tiger used when editing tables. Namely, when the user is at the end of the row and hits tab, I'd like editing to begin at the beginning of the next row. I note that here, http://www.cocoabuilder.com/archive/message/cocoa/2007/10/31/191866 the issue is acknowledged, and a solution proposed. The solution is to subclass NSTableView and implement -(void)textDidEndEditing: (NSNotification *)notification, but I'm having a problem with the implementation. Here is what I have so far: -(void)textDidEndEditing:(NSNotification *)notification { NSDictionary *userInfo = [notification userInfo]; int textMovement = [[userInfo valueForKey:@NSTextMovement] intValue]; if (textMovement == NSTabTextMovement) { // Tab pressed! [super textDidEndEditing:notification]; } } So, I get to Tab pressed!, but then don't know how to implement editing of the first column of the next row. I think I could do this if I could figure out what column had just finished being edited. I suppose I could create a variable in the subclass that stores this information when editing begins; but I was thinking there should be a property I can just read (and I'm not sure what property that is). When I use -selectedColumn on the NSTableView, I don't get anything useful (-1), because apparently no column is selected (I do get useful information from -selectedRow; but this isn't quite what I need). Thanks. Use - (NSInteger)editedColumn; - (NSInteger)editedRow; You can store it off, call super, then begin editing on the next row/ column (if it was already at the last column). corbin Thank you; that fixed it. Here is my solution (for a 4-column table): -(void)textDidEndEditing:(NSNotification *)notification { NSInteger editedColumn = [self editedColumn]; NSInteger editedRow = [self editedRow]; NSDictionary *userInfo = [notification userInfo]; int textMovement = [[userInfo valueForKey:@NSTextMovement] intValue]; if (textMovement == NSTabTextMovement) { [super textDidEndEditing:notification]; if (editedColumn == 3) { // Select row before calling -(void)editColumn:, and then start editing [self selectRowIndexes:[NSIndexSet indexSetWithIndex:editedRow+1] byExtendingSelection:NO]; [self editColumn:0 row:editedRow+1 withEvent:nil select:YES]; } } else if (textMovement == NSBacktabTextMovement) { [super textDidEndEditing:notification]; if (editedColumn == 0) { // Select row before calling -(void)editColumn:, and then start editing [self selectRowIndexes:[NSIndexSet indexSetWithIndex:editedRow-1] byExtendingSelection:NO]; [self editColumn:3 row:editedRow-1 withEvent:nil select:YES]; } } else [super textDidEndEditing:notification]; } // textDidEndEditing ___ 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 [EMAIL PROTECTED]
Re: Resorting normal field editor behaviour
Thank you very much; this is exactly the solution. Just for others who might have this problem, here is how i solved it: 1. Set up a NSText variable globally: NSText *fieldEd 2. Implement controlTextDidBeginEditing: as below: -(void)controlTextDidBeginEditing:(NSNotification *)notification { fieldEd = [[notification userInfo] objectForKey:@NSFieldEditor]; } 3. Implement the delegates you need (in my case controlTextDidChange: in order to modify the text as the user enters it). There is no need to use windowWillReturnFieldEditor, which is what I was trying to do before. On 3-Apr-08, at 9:02 AM, Nate Weaver wrote: I think what you probably want is to not use a custom field editor, but instead set your controller to the NSTableView's delegate (which it probably already is) and use the @NSFieldEditor key of the notification's userInfo dictionary to access the field editor. (Hopefully NSTableView isn't special and still calls controlTextDidChange: on its delegate; I can't remember). If what you're doing is validating the field's contents, you might want to look at making an NSFormatter subclass and assigning it to your data cells. Presumably the normal behavior disappears because the control is usually the delegate of the field editor, and it intercepts tab/ return/etc. and does its own thing with them (IIRC). On Apr 2, 2008, at 11:54 PM, K.Darcy Otto wrote: I need to intercept changes in my NSTableView's field editor, and I am able to do this successfully implementing controlTextDidChange: in my controller. I do this by having my controller create a field editor (fieldEd, an NSTextView) and setting the delegate of that field editor to my controller. Then, I use windowWillReturnFieldEditor: to return fieldEd, so that when the NSTableView wants to do some editing, it gets pointed to the right object. So far, so good. The problem is that I lose some normal field-editor behaviour. In particular, the field editor does not give up control when I press enter, tab or backtab, but instead enters these characters directly into the field (there may be some other issues as well; arrows work as expected). How do I restore normal behaviour, and (for the interest's sake) why has normal behaviour disappeared? Thanks. ___ 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 [EMAIL PROTECTED]
Re: Modify Input in NSTableView
See the following for the solution: http://www.cocoabuilder.com/archive/message/cocoa/2008/4/4/203185 On 31-Mar-08, at 5:18 PM, K. Darcy Otto wrote: Closing in on a solution (but not quite there): I have made some progress in solving this problem, but still have one strangeness (detailed below). Here is what I have done to get the replaced with → in an NSTableView: 1. Set my AppController as the window delegate. 2. Implemented windowWillReturnFieldEditor: as follows: -(id)windowWillReturnFieldEditor:(NSWindow *)window toObject: (id)anObject { if ([anObject isKindOfClass:[DeductionTable class]]) { return fieldEditor; } return nil; } (The table in my window is a DeductionTable object, subclass NSTableView. fieldEditor is an object of class DeductionTableFieldEditor, a subclass of NSTextField.) 3. I then implement controlTextDidChange as follows: -(void)controlTextDidChange:(NSNotification *)aNotification { // Trap letters in DeductionTableFieldEditor NSMutableString *fieldString = [NSMutableString stringWithString: [fieldEditor string]]; NSUInteger changeCount = [fieldString replaceOccurrencesOfString:@ withString:[NSString stringWithFormat:@%C,0x2192] options:NSLiteralSearch range:NSMakeRange(0,[fieldString length])]; if (changeCount 0 [fieldEditor shouldChangeTextInRange:NSMakeRange(0,[fieldString length]) replacementString:fieldString]) { [fieldEditor setString:fieldString]; [fieldEditor didChangeText]; } } So, this creates the result I want: when the user types , it is automatically replaced by →. The problem I'm having is that hitting return or tab no longer ends editing of the current cell. I have tried implementing doCommandBySelector: to take care of this, but as soon as I do, I lose return, tab and the arrow keys. Any ideas? On 31-Mar-08, at 11:26 AM, K. Darcy Otto wrote: On Mar 31, 2008, at 00:29, Quincey Morris wrote: On Mar 30, 2008, at 23:08, K. Darcy Otto wrote: I'm working on an application in which users enter data into a table, but I need to substitute a greater-than symbol () for a right-arrow symbol (→, unicode: 2192) as the user presses they key (or copies the text, or whatever). After looking at the docs and this list, I'm not much closer to determining the best way to do this (or even how to do it). So far, I have been thinking I have to do something with NSWindow and the fieldEditor; perhaps setting the window's field editor to be a particular NSTextView, and implement some method in that text view (insertText:?) to make the substitution. I take it that working with keyDown: would not be the best approach. Would this be on the right track? Any help would be appreciated. You could try adding a validateKey method for the property that holds the string value. In that method, take the input string and create a new string, replacing whatever characters you need to. Pass the new string back in the first parameter, and return YES from the method. If I haven't overlooked something obvious, this would work no matter whether the text was typed or pasted into the editing field. Oh -- make sure you check Validates immediately for the table column binding in IB, too. Of course, this is only going to make the replacement happen when the user presses return or tab. To get it to happen as soon as a replaceable character is typed, you'd have to convince the field editor to validate after every keystroke or editing action. So maybe this is not the best way. This is exactly the problem I'm running into. I can get changes to be made after the user exits the editing field, but I cannot get the changes to be made on-the-fly. After some additional reading, I have tried to solve this problem by implementing the following in the NSWindow delegate (where DeductionTable is my NSTableView subclass, and DeductionTableFieldEditor is my NSTextView subclass): -(id)windowWillReturnFieldEditor:(NSWindow *)window toObject: (id)anObject { if ([anObject isKindOfClass:[DeductionTable class]]) { return [[DeductionTableFieldEditor alloc] init]; } return nil; } Then, I started playing around with -(BOOL)textView:(NSTextView *)aTextView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString and - (BOOL)textShouldBeginEditing:(NSText *)aTextObject; but all I've succeeded in doing is messing up the editing functions that were there previously. Any other suggestions? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments
Resorting normal field editor behaviour
I need to intercept changes in my NSTableView's field editor, and I am able to do this successfully implementing controlTextDidChange: in my controller. I do this by having my controller create a field editor (fieldEd, an NSTextView) and setting the delegate of that field editor to my controller. Then, I use windowWillReturnFieldEditor: to return fieldEd, so that when the NSTableView wants to do some editing, it gets pointed to the right object. So far, so good. The problem is that I lose some normal field-editor behaviour. In particular, the field editor does not give up control when I press enter, tab or backtab, but instead enters these characters directly into the field (there may be some other issues as well; arrows work as expected). How do I restore normal behaviour, and (for the interest's sake) why has normal behaviour disappeared? Thanks. ___ 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 [EMAIL PROTECTED]
Re: Modify Input in NSTableView
Closing in on a solution (but not quite there – see below for details): I have made some progress in solving this problem, but still have one strangeness (detailed below). Here is what I have done to get the replaced with → in an NSTableView: 1. Set my AppController as the window delegate. 2. Implemented windowWillReturnFieldEditor: as follows: -(id)windowWillReturnFieldEditor:(NSWindow *)window toObject: (id)anObject { if ([anObject isKindOfClass:[DeductionTable class]]) { return fieldEditor; } return nil; } (The table in my window is a DeductionTable object, subclass NSTableView. fieldEditor is an object of class DeductionTableFieldEditor, a subclass of NSTextField.) 3. I then implement controlTextDidChange as follows: -(void)controlTextDidChange:(NSNotification *)aNotification { // Trap letters in DeductionTableFieldEditor NSMutableString *fieldString = [NSMutableString stringWithString: [fieldEditor string]]; NSUInteger changeCount = [fieldString replaceOccurrencesOfString:@ withString:[NSString stringWithFormat:@%C,0x2192] options:NSLiteralSearch range:NSMakeRange(0,[fieldString length])]; if (changeCount 0 [fieldEditor shouldChangeTextInRange:NSMakeRange(0,[fieldString length]) replacementString:fieldString]) { [fieldEditor setString:fieldString]; [fieldEditor didChangeText]; } } So, this creates the result I want: when the user types , it is automatically replaced by →. The problem I'm having is that hitting return or tab no longer ends editing of the current cell. I have tried implementing doCommandBySelector: to take care of this, but as soon as I do, I lose return, tab and the arrow keys. Any ideas? On 31-Mar-08, at 11:26 AM, K. Darcy Otto wrote: On Mar 31, 2008, at 00:29, Quincey Morris wrote: On Mar 30, 2008, at 23:08, K. Darcy Otto wrote: I'm working on an application in which users enter data into a table, but I need to substitute a greater-than symbol () for a right-arrow symbol (→, unicode: 2192) as the user presses they key (or copies the text, or whatever). After looking at the docs and this list, I'm not much closer to determining the best way to do this (or even how to do it). So far, I have been thinking I have to do something with NSWindow and the fieldEditor; perhaps setting the window's field editor to be a particular NSTextView, and implement some method in that text view (insertText:?) to make the substitution. I take it that working with keyDown: would not be the best approach. Would this be on the right track? Any help would be appreciated. You could try adding a validateKey method for the property that holds the string value. In that method, take the input string and create a new string, replacing whatever characters you need to. Pass the new string back in the first parameter, and return YES from the method. If I haven't overlooked something obvious, this would work no matter whether the text was typed or pasted into the editing field. Oh -- make sure you check Validates immediately for the table column binding in IB, too. Of course, this is only going to make the replacement happen when the user presses return or tab. To get it to happen as soon as a replaceable character is typed, you'd have to convince the field editor to validate after every keystroke or editing action. So maybe this is not the best way. This is exactly the problem I'm running into. I can get changes to be made after the user exits the editing field, but I cannot get the changes to be made on-the-fly. After some additional reading, I have tried to solve this problem by implementing the following in the NSWindow delegate (where DeductionTable is my NSTableView subclass, and DeductionTableFieldEditor is my NSTextView subclass): -(id)windowWillReturnFieldEditor:(NSWindow *)window toObject: (id)anObject { if ([anObject isKindOfClass:[DeductionTable class]]) { return [[DeductionTableFieldEditor alloc] init]; } return nil; } Then, I started playing around with -(BOOL)textView:(NSTextView *)aTextView shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString and - (BOOL)textShouldBeginEditing:(NSText *)aTextObject; but all I've succeeded in doing is messing up the editing functions that were there previously. Any other suggestions? ___ 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
Simple messages problem
So, I seem to be having a problem with the following code, and I think I've traced it to how the messages are nested; but I cannot seem to solve it. Consider the following code, which works without warnings (self.sequent is an NSArray): DeductionLine *dl1 = [self.sequent objectAtIndex:lineCount-1]; Justification *j1 = [dl1 justification]; NSString *rule1 = [j1 rule]; But the following line generates a warning: NSString may not respond to -rule. NSString *rule2 = [[[self.sequent objectAtIndex:lineCount-1] justification] rule]; I'm confused about the warning, because [[self.sequent objectAtIndex:lineCount-1] justification] returns type Justification, not NSString. Both examples compile and work; but the warning is in the second case only. Why, and how can I get rid of the warning? Any help would be appreciated. (I think I've included everything necessary to diagnose the problem; please let me know if I haven't; all of this is under Objective-C 2.0 with @synthesize sequent in DeductionLine.) ___ 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 [EMAIL PROTECTED]
Re: Simple messages problem
Thanks for your help; that change did clear up the warning. I want to make sure I understand your explanation though: How is [self.sequent objectAtIndex:lineCount-1] of type id as opposed to of type DeductionLine (since self.sequent is an NSArray of DeductionLine objects)? Is it that at compilation time, the compiler does not know what sort of object [self.sequent objectAtIndex:lineCount-1] is - but at runtime it turns out to be of type DeductionLine and so that's why everything runs smoothly? But when there is the explicit cast accomplished by (DeductionLine *), the compiler then knows what sort of object [self.sequent objectAtIndex:lineCount-1] is? When you say the compiler doesn't know which justification is going to apply - I take it this is because the Justification object has a justification method. How is it confused, since the class name begins with a capital, and the method begins with a miniscule? Thanks again. On 20-Mar-08, at 4:16 PM, Quincey Morris wrote: On Mar 20, 2008, at 15:25, K. Darcy Otto wrote: So, I seem to be having a problem with the following code, and I think I've traced it to how the messages are nested; but I cannot seem to solve it. Consider the following code, which works without warnings (self.sequent is an NSArray): DeductionLine *dl1 = [self.sequent objectAtIndex:lineCount-1]; Justification *j1 = [dl1 justification]; NSString *rule1 = [j1 rule]; But the following line generates a warning: NSString may not respond to -rule. NSString *rule2 = [[[self.sequent objectAtIndex:lineCount-1] justification] rule]; I'm confused about the warning, because [[self.sequent objectAtIndex:lineCount-1] justification] returns type Justification, not NSString. Both examples compile and work; but the warning is in the second case only. Why, and how can I get rid of the warning? Any help would be appreciated. (I think I've included everything necessary to diagnose the problem; please let me know if I haven't; all of this is under Objective-C 2.0 with @synthesize sequent in DeductionLine.) It sure looks like the compiler is complaining about the wrong thing. The real problem is that [self.sequent objectAtIndex:lineCount-1] is of type 'id' and the compiler doesn't know which 'justification' is going to apply to it, so it doesn't know the return type of that, so it doesn't know the type of object that 'rule' is being sent to. If you want to write it in one line, you need: NSString *rule2 = [[(DeductionLine *)[self.sequent objectAtIndex:lineCount-1] justification] rule]; to get rid of the warning. ___ 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/dotto%40csusb.edu This email sent to [EMAIL PROTECTED] ___ 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 [EMAIL PROTECTED]
Nested Enum Error
I've been trying to add some human-readable error codes to my classes using enum, but have been running into some difficulties when I add a different enum of the same name to a different class. Here is what I have so far in my DeductionLine class (and I think it will suffice just to show the interface: @interface DeductionLine : NSObject { Dependency *dependency; LineNumber *lineNumber; Formula *formula; Justification *justification; BOOL wfdl; // well-formed deduction line enum Error { noError = 0, // everything ok dependencyExistError = 1, // dependency does not exist lineNumberExistError = 2, // line number does not exist formulaFormError = 3, // formula is not a wff justificationFormError = 4, // justification is not a wfj justificationReferenceError = 5, // justification references lines greater or equal to lineNumber justificationMatchError = 6 // justification is $I, but main connective of formula does not correspond to $ } errorCode; } Now, I know the =0, =1 is redundant, but I want it there for ease of reading, just in case the programmer wants to output errorCode to a log (which will result in an integer, which can then be looked up in the interface). This works fine in this class: I can write: errorCode = noError; or whatever, and everything is happy. But when I try to do something similar in the DeductionLineSequent class, there is no end to compiler complaining: @interface DeductionLineSequent : NSObject { NSArray *sequent; NSArray *additionalFormulae; BOOL valid; enum Error { noError = 0, // everything ok dependencyError = 1, // dependency sequent invalid lineNumberError = 2, // line number sequent invalid formulaError = 3, // formula sequent invalid } errorCode; } I get nested redefinition of 'enum Error', (ii) redeclaration of 'enum Error' and (iii) redeclaration of enumerator 'noError'. So, I have two questions: is it possible to get each enum local to the class in which it is defined (so it does not seem to be nested)? Second, is there a better strategy for defining human-readable error codes? Thanks. ___ 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 [EMAIL PROTECTED]
Convenience initializer not working: unrecognized selector
I'm trying to create an initializer that allows me to combine initialization and some setting of variables, but I get an error that an unrecognized selector has been sent to the object. Here is what I have so far: Fraction.h: #import Cocoa/Cocoa.h @interface Fraction : NSObject { NSInteger numerator; NSInteger denominator; } @property(readwrite) NSInteger numerator; @property(readwrite) NSInteger denominator; -(id)initWith:(NSInteger)aNumerator over:(NSInteger)aDenominator; @end Fraction.m: #import Fraction.h @implementation Fraction @synthesize numerator,denominator; -(id)init { return [self initWith:1 over:1]; } -(id)initWith:(NSInteger)aNumerator over:(NSInteger)aDenominator { if (self = [super init]){ self.numerator = aNumerator; self.denominator = aDenominator; } return self; } @end Now, I can do the following with no ill effects: Fraction *frac = [[Fraction alloc] init]; frac.numerator = 2; frac.denominator = 2; But if I do this, I get the unrecognized selector error: Fraction *frac1 = [Fraction initWith:2 over:2]; Can anyone explain the error or suggest a solution? Thanks. ___ 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 [EMAIL PROTECTED]