• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTextField stable text while toggling bezel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextField stable text while toggling bezel


  • Subject: NSTextField stable text while toggling bezel
  • From: Sebastian Morsch <email@hidden>
  • Date: Sat, 17 Jun 2006 10:27:05 +0200

Hi,

I have an NSTextField that will be toggled between being bezeld or not at runtime. The problem is, that the text will not stay in place when I change the border/bezel. I solved this with a NSTextFieldCell subclass:



@interface SMStableTextFieldCell : NSTextFieldCell {
	NSRect cellRectOffset;
}
@ end


@implementation SMStableTextFieldCell

- (void)setBordered:(BOOL)flag
{
[super setBordered:flag];
if (flag) {
// 'misuse' NSRect to store the border-specific offstes for origin and size
// by comparing to a zero-rect
cellRectOffset = [self titleRectForBounds:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
}
}


- (void)setBezeled:(BOOL)flag
{
[super setBezeled:flag];
if (flag) {
// 'misuse' NSRect to store the bezel-specific offsets for origin and size
// by comparing to a zero-rect
cellRectOffset = [self titleRectForBounds:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
}
}


- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *) controlView
{
if (([self isBordered] == NO) && ([self isBezeled] == NO)) {
cellFrame.origin.x += borderedOrBezeledCellPadding.origin.x;
cellFrame.origin.y += borderedOrBezeledCellPadding.origin.y;
cellFrame.size.width += borderedOrBezeledCellPadding.size.width;
cellFrame.size.height += borderedOrBezeledCellPadding.size.height;
}
[super drawInteriorWithFrame:cellFrame inView:controlView];
}


@end



This works quite nicely, but when the textfield is borderless (and the cell's rect is changed as in the above code) the textfield's text still jumps back when I *select* it (as in setSelectable:YES)!

That gave me the impression, that maybe my code is doing things not the right way in general. Should I maybe implement the change of the cell's rect in any other method to avoid this? Or did I maybe forget about some helper object that needs to be shifted too (field editor)?

Also, it would be more convenient to implement this in the NSTextField class itself, but I couldn't make it work (at least not without changing the view's frame, and I don't want that). However, I *think* OO-stylewise it should be implemented in the cell anyway.

I found old posts about this issue, but they didn't really lead somewhere. I'm sure, some of you guys had that very same problem before.



Thank you for reading!

Sebastian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTextField stable text while toggling bezel
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: Deploying Cocoa Applications
  • Next by Date: Re: Deploying Cocoa Applications
  • Previous by thread: Re: CLI open -a myApp fileName - not working
  • Next by thread: Re: NSTextField stable text while toggling bezel
  • Index(es):
    • Date
    • Thread