Re: NSTableView with ArrayController bindings not updating?

2011-01-02 Thread Keary Suska
On Jan 1, 2011, at 5:13 PM, Ben Golding wrote:

>   Controller key  selection

This binding is wrong in your case. Refer to the examples in the Bindings 
Programming Topics document: 
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html,
 especially how table views are bound to array controllers.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

___

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: UITableViewCell showsReorderControl does nothing

2011-01-02 Thread Matt Neuburg
On Fri, 31 Dec 2010 21:52:29 +0800, Roland King  said:
>I've read the UITableView / UITableViewCell documentation for reordering 
>several times now. As I understand it in order to have a reorder control shown 
>when the table goes into editing mode you have to have the following 
>
>1) showsReorderControl of the UITableViewCell == YES
>2) tableView:canMoveRowAtIndexPath: must return YES  --- which is does by 
>default if you 
>3) implement tableView:moveRowAtIndexPath
>
>I've implemented 3) and not touched the default implementation of 2). It 
>doesn't matter however what I set showsReorderControl on my UITableViewCells 
>to, YES, or NO, the reorder control shows every time the table goes into 
>editing mode. 

Don't touch (1). Use (2) to prevent the reorder control from appearing on 
individual rows. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/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


Re: Funky icons in UITabBar

2011-01-02 Thread Matt Neuburg
On Fri, 31 Dec 2010 20:13:15 -0600, William Squires  said:
>What are the proper dimensions of a .png for use by a UITabBar item? I've got 
>one project (which works) which has two 57x57xmillions-of-colors png's using a 
>simple black-and-white coloration. I have another project which also has two 
>57x57xmillions-of-colors png's (converted from windows .bmp files using 
>GraphiConverter 6.5) that also have a simple black-and-white coloration. But 
>when the UITabBar displays these, they just show up as blue squares with the 
>'glassy' look. What am I doing wrong?

The only thing that matters is the alpha channel. If the image is completely 
opaque it will show up as a solid blue square. The "glassy" look is added 
automatically in any case.

A good way to proceed from an existing image is to turn its visible image into 
an alpha channel. A good image app will allow you to do that. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/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


Re: iPhone UISearchDisplayController how to handle memory warning

2011-01-02 Thread Matt Neuburg
On Sat, 01 Jan 2011 10:36:01 -0600, Donald Largen  said:
>Here is my situation.  I have UIViewController, call it ViewControllerA, that 
>contains an UITableView and UISearchDisplayController.  ViewControllerA is the 
>root view controller in a UINavigationController.  Things seem to work OK, 
>that is I can preform a search, display the results, and select a row and push 
>a detail view controller onto the stack, call it ViewControllerB.  
>
>The problem I am having is when ViewControllerB is displayed I am getting a 
>memory warning.  When I navigate back to ViewControllerA the 
>UISearchDisplayController did something in response to the memory warning.  
>The search bar is gone, the search results table view is gone, the navigation 
>bar is gone, and the "source table view" is displayed but has been scrolled to 
>the top of the screen.  
>
>I am thinking I need to handle this memory warning by recreating the 
>UISearchDisplayController but I am not sure.  I have a feeling though I am not 
>doing something right in my setup of the UISearchDisplayController.

That's certainly possible, but since you don't show how you set up the 
UISearchDisplayController, it's impossible to say more. However, in your 
position here's what I would do: create a completely new minimal project 
consisting of nothing but a UINavigationController with two UIViewControllers, 
the first of which has the UISearchBar controlled by the 
UISearchDisplayController. Now convince yourself that this minimal project does 
/ does not have the problem you describe. If it doesn't, you know it's due to 
something else you're doing differently in the real project. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.apeth.net/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


Re Re: String variables in classes

2011-01-02 Thread Brian Durocher
Thank you guys for your assistance. I come from a C++ background and
have done embedded design in ASM. But this way of working and
particularly the framework is very new to me. I understand what you are
saying, but the literature I am reading is very disappointingly. I have
solved the issue with the strings soon after I wrote the message but
just for completeness and for the sake of a decent critique I will post
the new code. I love the term you are flailing around here, thats
exactly how I felt until I discovered where I was going wrong. Thanks
Graham and Stephen for your replies and comments.

Graham I believe you asked what does "//does not work" mean. I think the
compiler was giving me a function returns void and should be handled as
such. Basically, function returns nothing.

This line of code seems to work for exactly what I was looking for:

temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2]
retain];

although I have to admit I am unsure really what the "retain" will
actually do here with respect to memory.  The the preceding [temp
autorelease] create a memory leak or is this the correct way to handle
memory management within the framework?

---


#import 

@interface Calculator : NSObject
{
double accumulator;   
NSString* caption;
NSString* name;
NSString* temp;
}

- (id) init;
- (void) setAccumulator:(double) n;
- (void) printAccumulator;

- (NSString*) caption;
- (NSString*) name;
- (NSString*) temp;

- (void) setCaption: (NSString*)input;
- (void) setName: (NSString*)input;
- (void) setTempString: (NSString*)input;
- (void) combineString: (NSString*) input1 : (NSString*) input2;

- (void) printCaption;
- (void) printName;
- (void) printTemp;


@end

@implementation Calculator

- (id) init
{
if ( self = [super init] )
{
[self setAccumulator:0];
[self setCaption:@"Default Caption"];
[self setName:@"Default Name"];
[self setTempString:@"empty"];
}
return self;
}

- (void) setAccumulator: (double) n
{
accumulator = n;
}

- (void) printAccumulator
{
NSLog(@"Accumulator = %f", accumulator);
}

- (NSString*) caption {
return caption;
}

- (NSString*) name {
return name;
}

- (NSString*) temp {
return temp;
}

- (void) setCaption: (NSString*)input
{
[caption autorelease];
caption = [input retain];
}

- (void) setName: (NSString*)input
{
[name autorelease];
name = [input retain];
}

- (void) setTempString: (NSString*)input
{
[temp autorelease];
temp = [input retain];
}

- (void) combineString: (NSString*) input1 : (NSString*) input2
{
[temp autorelease];
temp = @"";
temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2]
retain];
}


- (void) printCaption
{
NSLog(@"%@ \n", self.caption);
}
- (void) printName;
{
NSLog(@"%@ \n", self.name);
}
- (void) printTemp;
{
NSLog(@"%@ \n", self.temp);
}

@end


int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// insert code here...
   
Calculator *theDevice = [[Calculator alloc] init];
   
[theDevice init];
[theDevice printAccumulator];
[theDevice setAccumulator:10];
[theDevice printAccumulator];
[theDevice setName: @"Brian D"];
[theDevice setCaption: @"Rocks"];

[theDevice combineString:[theDevice name] : [theDevice caption]];
   
[theDevice printTemp];
[theDevice printName];
[theDevice printCaption];
   
   
NSLog(@"The two variables: %@, %@ \n", [theDevice name], [theDevice
caption]);
NSLog(@"Hello, World!");
[theDevice release];

[pool drain];
return 0;
}




___

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: Re Re: String variables in classes

2011-01-02 Thread Charles Srstka
On Jan 2, 2011, at 5:17 PM, Brian Durocher wrote:

> - (void) setCaption: (NSString*)input
> {
>[caption autorelease];
>caption = [input retain];
> }

For this (and for the rest of the NSString ivars), it’s generally better to use 
-copy rather than -retain. The reason for this is that it is perfectly valid to 
pass an NSMutableString to this method, since it is a subclass of NSString. If 
a caller gave you a mutable string and then changed it later, it could have 
unpredictable results for your object. Using -copy makes sure you have your own 
immutable copy of the string which can’t be changed (and as an optimization, if 
the string is already immutable, -copy just retains it, so it’s just as 
efficient).

> - (void) combineString: (NSString*) input1 : (NSString*) input2
> {
>[temp autorelease];
>temp = @"";
>temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2]
> retain];
> }

The autorelease is fine in terms of not causing memory leaks, but why are you 
assigning an empty string to temp immediately before you assign something else 
to it? That’s an unnecessary line of code. Actually, there’s a lot of 
unnecessary code here — why not just use the accessor method to set the string?

- (void) combineString: (NSString*) input1 : (NSString*) input2
{
   [self setTempString:[[self temp] stringByAppendingFormat:@" %@ %@ \n", 
input1, input2]];
}

In general, it’s a good idea to cut down on the direct use of ivars and use 
accessors as much as possible. This will make your design more flexible should 
you decide to change the underpinnings of something in the future.

Charles___

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: Search within a UIWebView (iOS 4.2)

2011-01-02 Thread Philip Vallone

Hi List,

I was wondering if any one could provide some guidance on this?

Thanks,

Phil


On Dec 26, 2010, at 2:04 PM, Philip Vallone wrote:

> Hi List,
> 
> In iOS 4.2, you can search within a webpage in Safari. Is there a search bar 
> object that can do this in a UIWebView?
> 
> Thanks,
> 
> Phil
> 
> ___
> 
> 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/philip.vallone%40verizon.net
> 
> This email sent to philip.vall...@verizon.net

___

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

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

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

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


Re: Re Re: String variables in classes

2011-01-02 Thread Charles Srstka
On Jan 2, 2011, at 5:17 PM, Brian Durocher wrote:

> Thank you guys for your assistance. I come from a C++ background and
> have done embedded design in ASM. But this way of working and
> particularly the framework is very new to me. I understand what you are
> saying, but the literature I am reading is very disappointingly. I have
> solved the issue with the strings soon after I wrote the message but
> just for completeness and for the sake of a decent critique I will post
> the new code. I love the term you are flailing around here, thats
> exactly how I felt until I discovered where I was going wrong. Thanks
> Graham and Stephen for your replies and comments.
> 
> Graham I believe you asked what does "//does not work" mean. I think the
> compiler was giving me a function returns void and should be handled as
> such. Basically, function returns nothing.
> 
> This line of code seems to work for exactly what I was looking for:
> 
>temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2]
> retain];
> 
> although I have to admit I am unsure really what the "retain" will
> actually do here with respect to memory.  The the preceding [temp
> autorelease] create a memory leak or is this the correct way to handle
> memory management within the framework?

Also, your Calculator class seems to be missing a -dealloc method entirely now. 
That is going to cause leaks for sure.

Charles___

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: Re Re: String variables in classes

2011-01-02 Thread Stephen J. Butler
On Sun, Jan 2, 2011 at 5:17 PM, Brian Durocher  wrote:
> #import 
>
> @interface Calculator : NSObject
> {
>    double accumulator;
>    NSString* caption;
>    NSString* name;
>    NSString* temp;
> }
>
> - (id) init;
> - (void) setAccumulator:(double) n;
> - (void) printAccumulator;
>
> - (NSString*) caption;
> - (NSString*) name;
> - (NSString*) temp;
>
> - (void) setCaption: (NSString*)input;
> - (void) setName: (NSString*)input;
> - (void) setTempString: (NSString*)input;

You violate the KVC pattern here. Your getter is "temp" but your
setter is "setTempString". Either make the getter "tempString" or the
setter "setTemp:".

> - (void) combineString: (NSString*) input1 : (NSString*) input2;
>
> - (void) printCaption;
> - (void) printName;
> - (void) printTemp;
>
>
> @end
>
> @implementation Calculator
>
> - (id) init
> {
>    if ( self = [super init] )
>    {
>        [self setAccumulator:0];
>        [self setCaption:@"Default Caption"];
>        [self setName:@"Default Name"];
>        [self setTempString:@"empty"];

Most Cocoa conventions say to just set the instance variables directly
inside your init* functions. There's nothing wrong with doing it this
way, per se, but most people will just do this:

accumulator = 0;
caption = @"Default Caption";
name = @"Default Name";
temp = @"empty";

>    }
>    return self;
> }
>
> - (void) setAccumulator: (double) n
> {
>    accumulator = n;
> }
>
> - (void) printAccumulator
> {
>    NSLog(@"Accumulator = %f", accumulator);
> }
>
> - (NSString*) caption {
>    return caption;
> }
>
> - (NSString*) name {
>    return name;
> }
>
> - (NSString*) temp {
>    return temp;
> }
>
> - (void) setCaption: (NSString*)input
> {
>    [caption autorelease];
>    caption = [input retain];
> }
>
> - (void) setName: (NSString*)input
> {
>    [name autorelease];
>    name = [input retain];
> }
>
> - (void) setTempString: (NSString*)input
> {
>    [temp autorelease];
>    temp = [input retain];
> }
>
> - (void) combineString: (NSString*) input1 : (NSString*) input2
> {
>    [temp autorelease];
>    temp = @"";
>    temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2]
> retain];
> }

- Charles asks 'why the @""' and I can answer that question: because
you couldn't figure out another way to call stringByAppendingFormat:
could you? The answer is that in this case you should be calling
+[NSString stringWithFormat:]. However...

- You really should be using your mutator here. I know it's an
advanced topic at this point, but KVC and KVO will be much easier
later if you don't go setting your instance variable willy-nilly. How
about this:

- (void) combineString: (NSString*) input1 : (NSString*) input2
{
  [self setTempString:[NSString stringWithFormat:@" %@ %@ \n", input1, input2]];
}

But going back to your original question, and guessing what this code
is really supposed to do as opposed to what it actually does...

I used to do a bit of C++ programming and I think here's the rub. In
STL the std::string is mutable. So if you do:

std::string str1;

str1 = "foo\n";
str1 += "bar\n";

Then str1 is changed, you don't need to store the return value of
operator+=. But in Cocoa NSString is not mutable. So if you do:

NSString *str1, *str2;

str1 = @"foo\n";
str2 = [str1 stringByAppendingString:@"bar\n"];

Then str1 and str2 POINT TO DIFFERENT OBJECT INSTANCES! str1 still
equals "foo\n" and str2 equals "foo\nbar\n". See where the method name
begins with "stringBy"? That "string" means it is returning a new
instance of NSString.

Which brings us to what NSMutableString does. Consider this code
instead (noting that I call [NSMutableString stringWithString because
@"" are always immutable):

NSMutableString *str1, *str2;

str1 = [NSMutableString stringWithString:@"foo\n"];
str2 = [str1 stringByAppendingString:@"bar\n"];

What do you suppose happens? Exactly what happened before. In fact,
str2 isn't a mutable string at all, it is immutable (because
stringByAppendingString: is declared in the base class and returns an
immutable instance). In fact, when you compile you get a warning on
that third line.

If you really want to mutate str1 like you would in C++ std::string
take a look at the documentation for NSMutableString. I don't know why
you didn't start there in the first place, there's only a dozen or so
methods it adds on top of the base class. Two you might like are
appendString: and appendFormat:.

NSMutableString *str1;

str1 = [NSMutableString stringWithString:@"foo\n"];
[str1 appendString:@"bar\n"];

> - (void) printCaption
> {
>    NSLog(@"%@ \n", self.caption);
> }
> - (void) printName;
> {
>    NSLog(@"%@ \n", self.name);
> }
> - (void) printTemp;
> {
>    NSLog(@"%@ \n", self.temp);
> }

There's nothing wrong with all these print methods, but they are a
little unCocoa like. The Cocoa way to do this is to override the
description method and return all the info about your object. In fact,
these two lines are more or less the same:

NSLog( @"object = %@", myObject );

Re: Re Re: String variables in classes

2011-01-02 Thread Charles Srstka
On Jan 2, 2011, at 6:10 PM, Stephen J. Butler wrote:

> - Charles asks 'why the @""' and I can answer that question: because
> you couldn't figure out another way to call stringByAppendingFormat:
> could you? The answer is that in this case you should be calling
> +[NSString stringWithFormat:]. However...

Ah — my assumption was that he wanted to keep appending previous results to the 
string, so it’d create sort of a log file sort of thing (or, since his object 
is a calculator, something akin to a roll of tape on an adding machine). In 
this case, using -stringByAppendingString: (or just using an NSMutableString) 
would be correct, although the assignment to an empty string would be wrong.

Charles___

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: Re Re: String variables in classes

2011-01-02 Thread Graham Cox

On 03/01/2011, at 10:17 AM, Brian Durocher wrote:

> This line of code seems to work for exactly what I was looking for:
> 
>temp = [[temp stringByAppendingFormat:@" %@ %@ \n", input1, input2]
> retain];


Except it's quite wrong from a memory management point of view.

As well as the excellent advice you've already received, you really must take 
my advice about not just reading but KNOWING the memory management rules:

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

C++, with which you're familiar, has no built-in memory management except 
allocation and free. You have to track those allocations yourself if you are to 
prevent leaks and so on. In Cocoa, this tracking is about 80% handled for you 
provided you follow the rules. The rules are there to ensure that the tracking 
works. (Or you can enable garbage collection and then the tracking is 100% 
handled for you).

> although I have to admit I am unsure really what the "retain" will
> actually do here with respect to memory.

Which means you haven't read the rules, let alone committed them to heart. I 
urge you to do so before progressing further.

--Graham


___

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

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

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

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


Re: UITableViewCell showsReorderControl does nothing

2011-01-02 Thread Roland King
ok that's what I've effectively done by implementing 3), which makes 2) return 
YES for all rows, which is what I wanted. 

So, err what is 1) for? It's a property, it exists, it's in the documentation 
but it doesn't seem to do anything. 

On 03-Jan-2011, at 5:14 AM, Matt Neuburg wrote:

> On Fri, 31 Dec 2010 21:52:29 +0800, Roland King  said:
>> I've read the UITableView / UITableViewCell documentation for reordering 
>> several times now. As I understand it in order to have a reorder control 
>> shown when the table goes into editing mode you have to have the following 
>> 
>> 1) showsReorderControl of the UITableViewCell == YES
>> 2) tableView:canMoveRowAtIndexPath: must return YES  --- which is does by 
>> default if you 
>> 3) implement tableView:moveRowAtIndexPath
>> 
>> I've implemented 3) and not touched the default implementation of 2). It 
>> doesn't matter however what I set showsReorderControl on my UITableViewCells 
>> to, YES, or NO, the reorder control shows every time the table goes into 
>> editing mode. 
> 
> Don't touch (1). Use (2) to prevent the reorder control from appearing on 
> individual rows. m.
> 
> --
> matt neuburg, phd = m...@tidbits.com, 
> A fool + a tool + an autorelease pool = cool!
> AppleScript: the Definitive Guide - Second Edition!
> http://www.apeth.net/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


NSView drawing with superimposed text

2011-01-02 Thread Michael McLaughlin
With Xcode 3.2.5 and the corresponding IB, I have a custom NSView into which I 
want to draw.   This view has 15 static text views in front of it, in the 
contentView only, all of which are filled in before the custom drawing and none 
of which draw their own backgrounds.  The code for the custom drawing is

-(void)drawRect:(NSRect)rect
{
   [[NSColor blackColor] setStroke];
   [[NSColor whiteColor] setFill];
   [NSBezierPath fillRect:rect];

   if (phase3) {  // draw line
  NSBezierPath *path = [NSBezierPath bezierPath];
  [path moveToPoint:NSMakePoint(0, 0)];
  [path lineToPoint:NSMakePoint(520, 240)];
  [path stroke];
   }
}

This method is called three times during a complete rendering.

Without the conditional (if statement), the result is as expected but, with it, 
the final (third) call to this method references a rect that does not 
correspond to anything in the window and the final window shows only a small 
portion of the line even though all of the superimposed text items should be 
transparent apart from their text.

Obviously, I am missing something important about Cocoa drawing but could find 
no hints anywhere to help.

Any tips?

TIA.





___

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

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

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

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


Rendering combining marks

2011-01-02 Thread George Nachman
Hi cocoa-dev,

I'm using CGContextShowGlyphsWithAdvances to render fixed-width text
because it is very fast. If a glyph is missing, I use
CTFontCreateForString() to pick a better font, and that usually works.
I ran into a case that I just can't solve with this technique: the
glyph for code point U+20d1 (COMBINING RIGHT HARPOON ABOVE) exists in
only one font on my system (Arial Unicode MS) and it is apparently not
in the global cascade list. I see that Terminal.app is somehow able to
correctly render this glyph (and it also uses
CGContextShowGlyphsWithAdvances when rendering such characters, at
least in part, as I can see from Activity Monitor's sampling). So I
think the trick is in finding out which font(s) have some glyph, but I
don't see an API to do this. Any ideas?

Thanks,
George
___

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: NSView drawing with superimposed text

2011-01-02 Thread Erik Buck
Each time -drawRect: is called, the rect parameter is a dirty rectangle 
calculated by the frameworks to be the smallest area that needs to be redraw.  
With your implementation, you are probably filling several small sub-rectangles 
of the view's bounds with white and then stroking lines in only one of the 
small rectangles that the framework thinks need update.

If you want to erase the entire view every time drawRect is called, try either 
[NSBezierPath fillRect:[self bounds]]; or [NSBezierPath fillRect:[self 
visibleRect]];

If you want the entire view to redraw for some reason, then send 
-setNeedsDisplay:YES to the view.  If you want to redraw a sub rect of the 
view, send -setNeedsDisplayInRect:.  Don't send either message from within the 
implementation of -drawRect: because it is too late then.  The area that needs 
to be redrawn has already been calculated and the changes you make via 
setNeedsDisplay will be replaced/recalculated by the framework after -drawRect: 
returns. Also, don't call any variant of [self display] within -drawRect: 
because it may result in infinite recursion.

Finally, if you want to be cleaver and optimize drawing, you can use [self 
getRectsBeingDrawn:&rects count:&count]; and implement method 
-wantsDefaultClipping to return NO.

Reference: 
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaViewsGuide/SubclassingNSView/SubclassingNSView.html


On Jan 2, 2011, at 1:36 PM, Michael McLaughlin wrote:

> With Xcode 3.2.5 and the corresponding IB, I have a custom NSView into which 
> I want to draw.   This view has 15 static text views in front of it, in the 
> contentView only, all of which are filled in before the custom drawing and 
> none of which draw their own backgrounds.  The code for the custom drawing is
> 
> -(void)drawRect:(NSRect)rect
> {
>   [[NSColor blackColor] setStroke];
>   [[NSColor whiteColor] setFill];
>   [NSBezierPath fillRect:rect];
> 
>   if (phase3) {  // draw line
>  NSBezierPath *path = [NSBezierPath bezierPath];
>  [path moveToPoint:NSMakePoint(0, 0)];
>  [path lineToPoint:NSMakePoint(520, 240)];
>  [path stroke];
>   }
> }
> 
> This method is called three times during a complete rendering.
> 
> Without the conditional (if statement), the result is as expected but, with 
> it, the final (third) call to this method references a rect that does not 
> correspond to anything in the window and the final window shows only a small 
> portion of the line even though all of the superimposed text items should be 
> transparent apart from their text.
> 
> Obviously, I am missing something important about Cocoa drawing but could 
> find no hints anywhere to help.
> 
> Any tips?
> 
> TIA.
> 
> 
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/erik.buck%40sbcglobal.net
> 
> This email sent to erik.b...@sbcglobal.net

___

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

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

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

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


Re: NSView drawing with superimposed text

2011-01-02 Thread Quincey Morris
On Jan 2, 2011, at 10:36, Michael McLaughlin wrote:

> With Xcode 3.2.5 and the corresponding IB, I have a custom NSView into which 
> I want to draw.   

What you describe below doesn't entirely make sense, so perhaps you can clarify 
a bit.

> This view has 15 static text views in front of it, in the contentView only, 
> all of which are filled in before the custom drawing and none of which draw 
> their own backgrounds.  

In 10.5 and above, overlapping views that are non-opaque (return NO from 
'isOpaque') will draw in back-to-front order. Opaque views can presumably draw 
in any order (suitably clipped) -- so if they don't actually draw their 
backgrounds you can expect oddities in the result. If the text views are 
getting drawn *before* the custom view behind them, you probably need to 
investigate why.

> The code for the custom drawing is
> 
> -(void)drawRect:(NSRect)rect
> {
>   [[NSColor blackColor] setStroke];
>   [[NSColor whiteColor] setFill];
>   [NSBezierPath fillRect:rect];

Code like this is almost certainly wrong (unless it's just for debugging 
purposes). The 'rect' parameter can be any part of the view that needs 
redrawing, so stroking the border of it will basically draw random rectangles 
in your view.

>   if (phase3) {  // draw line
>  NSBezierPath *path = [NSBezierPath bezierPath];
>  [path moveToPoint:NSMakePoint(0, 0)];
>  [path lineToPoint:NSMakePoint(520, 240)];
>  [path stroke];
>   }
> }
> 
> This method is called three times during a complete rendering.
> 
> Without the conditional (if statement), the result is as expected but, with 
> it, the final (third) call to this method references a rect that does not 
> correspond to anything in the window and the final window shows only a small 
> portion of the line even though all of the superimposed text items should be 
> transparent apart from their text.

It's not clear whether you mean you're deliberately arranging for the drawing 
to be done 3 times (or what the 'phases' mean, or how 'phase3' is maintained).

It's also not clear, if 'rect' "does not correspond to anything in the window" 
why you'd expect anything at all to appear, even disregarding the text views. 
If in fact 'rect' is some part of the window, then it's not that surprising 
that the line is clipped to the exterior of the text views, if the text views 
are in fact logically opaque.

Putting this the other way round, if the text views are regarded by the drawing 
system as opaque views, regardless of whether they *actually* draw their 
backgrounds, the result would much as you've described.


___

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