Professional Web Applications Themes

NSTextFieldCell subclass drawing - Mac Programming

Highlighted NSTextFieldCells draw their text in white. That's easy enough to duplicate in a subclass. But when the enclosing view is inactive -- say, when it's in a background window -- the row highlight color turns light gray and NSTextFieldCells draw their text in black. How does a cell know whether to do this? I can't figure out how to ask the enclosing view what state it's in. I'm sure this absurdly trivial, but I've spent 20 minutes digging through the docs and I can't turn up an answer. -- "Our country puts $1 billion a year up to help ...

  1. #1

    Default NSTextFieldCell subclass drawing

    Highlighted NSTextFieldCells draw their text in white. That's easy
    enough to duplicate in a subclass. But when the enclosing view is
    inactive -- say, when it's in a background window -- the row highlight
    color turns light gray and NSTextFieldCells draw their text in black.

    How does a cell know whether to do this? I can't figure out how to ask
    the enclosing view what state it's in. I'm sure this absurdly trivial,
    but I've spent 20 minutes digging through the docs and I can't turn up
    an answer.

    --
    "Our country puts $1 billion a year up to help feed the hungry. And we're by far
    the most generous nation in the world when it comes to that, and I'm proud to
    report that. This isn't a contest of who's the most generous. I'm just telling
    you as an aside. We're generous. We shouldn't be bragging about it. But we are.
    We're very generous."
    -- George W. Bush in Washington, D.C., July 16, 2003
    ZnU Guest

  2. #2

    Default Re: NSTextFieldCell subclass drawing

    ZnU wrote: 

    Your NSCell class will get different messages to draw in different
    states. If you implement

    - (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView *)controlView

    it will get called when the control wants the cell to draw highlighted.

    HTH,

    -jcr
    John Guest

  3. #3

    Default Re: NSTextFieldCell subclass drawing

    In article <idiom.com>,
    "John C. Randolph" <idiom.com> wrote:
     
    >
    > Your NSCell class will get different messages to draw in different
    > states. If you implement
    >
    > - (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView
    > *)controlView
    >
    > it will get called when the control wants the cell to draw highlighted.[/ref]

    My problem isn't getting the highlight state. My problem is that (at
    least in NSTableViews), highlighted NSTextFieldCells draw their text in
    one color -- typically white -- when their containing views are active,
    and another color -- typically black -- when their containing views
    aren't. Try it in Mail. Select a message, and then click in the preview
    pane, or just bring another app to the foreground. The highlight color
    in the message list turns light gray, and the highlighted cells draw
    text in black, rather than white.

    How do the cells know to do that? It doesn't look like the cells receive
    different messages, and I can't figure out how to ask a view whether
    it's active.

    --
    "Our country puts $1 billion a year up to help feed the hungry. And we're by far
    the most generous nation in the world when it comes to that, and I'm proud to
    report that. This isn't a contest of who's the most generous. I'm just telling
    you as an aside. We're generous. We shouldn't be bragging about it. But we are.
    We're very generous."
    -- George W. Bush in Washington, D.C., July 16, 2003
    ZnU Guest

  4. #4

    Default Re: NSTextFieldCell subclass drawing

    ZnU wrote: 
    > >
    > > Your NSCell class will get different messages to draw in different
    > > states. If you implement
    > >
    > > - (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView
    > > *)controlView
    > >
    > > it will get called when the control wants the cell to draw highlighted.[/ref]
    >
    > My problem isn't getting the highlight state. My problem is that (at
    > least in NSTableViews), highlighted NSTextFieldCells draw their text in
    > one color -- typically white -- when their containing views are active,
    > and another color -- typically black -- when their containing views
    > aren't. Try it in Mail. Select a message, and then click in the preview
    > pane, or just bring another app to the foreground. The highlight color
    > in the message list turns light gray, and the highlighted cells draw
    > text in black, rather than white.
    >
    > How do the cells know to do that? It doesn't look like the cells receive
    > different messages, and I can't figure out how to ask a view whether
    > it's active.[/ref]

    Ah, I get you now. You can find out whether the controlView has the
    input focus by seeing if it matches the window's -firstResponder. You
    can find out if the window has the input focus by send it an
    -isKeyWindow message.

    HTH,

    -jcr
    John Guest

  5. #5

    Default Re: NSTextFieldCell subclass drawing

    ZnU <com> wrote in message news:<cis.dfn.de>... 
    > >
    > > Your NSCell class will get different messages to draw in different
    > > states. If you implement
    > >
    > > - (void)highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView
    > > *)controlView
    > >
    > > it will get called when the control wants the cell to draw highlighted.[/ref]
    >
    > My problem isn't getting the highlight state. My problem is that (at
    > least in NSTableViews), highlighted NSTextFieldCells draw their text in
    > one color -- typically white -- when their containing views are active,
    > and another color -- typically black -- when their containing views
    > aren't. Try it in Mail. Select a message, and then click in the preview
    > pane, or just bring another app to the foreground. The highlight color
    > in the message list turns light gray, and the highlighted cells draw
    > text in black, rather than white.
    >
    > How do the cells know to do that? It doesn't look like the cells receive
    > different messages, and I can't figure out how to ask a view whether
    > it's active.[/ref]


    Actually, the enclosing Control changes the color of their cells based
    on their selection and first responder status.

    Cells should not go upwards in the hierarchy to find out stuff and change colors
    accordingly.

    I guess what you need to do is to override the become/resignFirstResponder method
    in the enclosing control.
    jpa Guest

  6. #6

    Default Re: NSTextFieldCell subclass drawing

    In article <idiom.com>,
    "John C. Randolph" <idiom.com> wrote:
     
    > >
    > > My problem isn't getting the highlight state. My problem is that (at
    > > least in NSTableViews), highlighted NSTextFieldCells draw their text in
    > > one color -- typically white -- when their containing views are active,
    > > and another color -- typically black -- when their containing views
    > > aren't. Try it in Mail. Select a message, and then click in the preview
    > > pane, or just bring another app to the foreground. The highlight color
    > > in the message list turns light gray, and the highlighted cells draw
    > > text in black, rather than white.
    > >
    > > How do the cells know to do that? It doesn't look like the cells receive
    > > different messages, and I can't figure out how to ask a view whether
    > > it's active.[/ref]
    >
    > Ah, I get you now. You can find out whether the controlView has the
    > input focus by seeing if it matches the window's -firstResponder. You
    > can find out if the window has the input focus by send it an
    > -isKeyWindow message.[/ref]

    All right, thanks, that works.

    --
    "Our country puts $1 billion a year up to help feed the hungry. And we're by far
    the most generous nation in the world when it comes to that, and I'm proud to
    report that. This isn't a contest of who's the most generous. I'm just telling
    you as an aside. We're generous. We shouldn't be bragging about it. But we are.
    We're very generous."
    -- George W. Bush in Washington, D.C., July 16, 2003
    ZnU Guest

Similar Threads

  1. Drawing in Flex? Drawing and AS for custom compon
    By yoway in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 18th, 10:19 PM
  2. Dragging into NSTableView subclass
    By Rick in forum Mac Programming
    Replies: 3
    Last Post: December 14th, 04:57 PM
  3. delegate or subclass NSTextView?
    By None in forum Mac Programming
    Replies: 3
    Last Post: October 1st, 08:58 AM
  4. Drawing in a subclass of NSView
    By Steve Ketcham in forum Mac Programming
    Replies: 10
    Last Post: August 22nd, 12:31 AM
  5. keyDown: in NSMatrix subclass
    By matt neuburg in forum Mac Programming
    Replies: 3
    Last Post: July 16th, 12:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139