How to draw a standard cocoa control ?

  • Hi to all,

    I hope my question will not seem to stupid...

    I'd like to subclass the NSTextField class to create a control that
    looks like a NSComboBox object but with a customized behavior and a
    customized drawing in the blue area of the combo box.

    I don't want to subclass NSComboBox because my control will not act
    like a combo box.

    My question is : how can I draw my control so that it looks like
    EXACTLY the same as a standard OSX control ? This includes the size of
    the text field, the size of the blue area, the exact color used in this
    blue area, the gradient used in the blue area, the color/gradient used
    when the control is "on", the blue focus ring,...

    In other words : where can I found these standard values to be SURE my
    control looks exactly like a true OSX control ?

    Is there a way to retrieve all this values - in particular the gradient
    and the blue color ?

    Thanks by advance !

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Am 19.04.2004 um 19:14 schrieb Eric Morand:

    > how can I draw my control so that it looks like EXACTLY the same as a
    > standard OSX control ?

    You can't.

    Mac OS X uses bitmaps for certain controls elements. There is no way to
    get at a description of the gradients used to render them.

    The best you can do is get some system colors from NSColor.
    (Well, if the the Carbon Appearance Manager is still there, it might
    know more ...)

    Andreas

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Thanks Neil - you always seem to be aound when I need you...

    So I have to "guess" the colors, gradients, sizes, angles ? Well,
    pretty interesting... ;o)

    Have someone an idea of how the gradient are drawn ?
    And what is the Carbon Apperance Manager by the way ?

    Le 19 avr. 04, à 20:35, Andreas Mayer a écrit :

    >
    > Am 19.04.2004 um 19:14 schrieb Eric Morand:
    >
    >> how can I draw my control so that it looks like EXACTLY the same as a
    >> standard OSX control ?
    >
    > You can't.
    >
    > Mac OS X uses bitmaps for certain controls elements. There is no way
    > to get at a description of the gradients used to render them.
    >
    > The best you can do is get some system colors from NSColor.
    > (Well, if the the Carbon Appearance Manager is still there, it might
    > know more ...)
    >
    >
    > Andreas
    >
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • On 19 Apr 2004, at 19:45, Eric Morand wrote:

    > So I have to "guess" the colors, gradients, sizes, angles ? Well,
    > pretty interesting... ;o)
    >
    > Have someone an idea of how the gradient are drawn ?
    > And what is the Carbon Apperance Manager by the way ?

    The Carbon Appearance Manager will draw controls on demand (into
    QuickDraw ports, I think). It has been superseded by the HITheme API,
    which will draw controls into CGContexts.

      -- Finlay

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Am 19.04.2004 um 20:45 schrieb Eric Morand:

    > So I have to "guess" the colors, gradients, sizes, angles ?

    As I said, you can get some system colors from NSColor. Read the docs.

    > Have someone an idea of how the gradient are drawn ?

    I don't. Besides - those things change from one version of the OS to
    the next. Mac OS X 10.1 looks different than 10.2, 10.2 looks different
    than 10.3, and I bet that 10.4 will bring some new looks, too.

    > And what is the Carbon Apperance Manager by the way ?

    http://developer.apple.com/cgi-bin/search.pl?
    &q=appearance+manager&num=10&ie=utf8&oe=utf8&lr=lang_en&simp=1

    Andreas

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Am 19.04.2004 um 20:56 schrieb Finlay Dobbie:

    > It has been superseded by the HITheme API, which will draw controls
    > into CGContexts.

    Looks like Apple considers the HITheme API part of the (new) Appearance
    Manager:

    http://developer.apple.com/documentation/ReleaseNotes/Carbon/
    HIToolbox.html

    " The Appearance Manager now provides a new API for drawing appearance
    primitives (2816257). This API is located in the HITheme.h header
    file."

    Maybe this will help?

    HIThemeDrawPopupArrow

    Andreas

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • > I don't. Besides - those things change from one version of the OS to
    > the next. Mac OS X 10.1 looks different than 10.2, 10.2 looks
    > different than 10.3, and I bet that 10.4 will bring some new looks,
    > too.

    So, if I design a control matching today's standards, I'll have to
    re-design it when 10.4 is released - if the control's standard look
    changes with the new release ?

    That explains why so much apps have been updated to match 10.3
    standards... :o)

    Le 19 avr. 04, à 20:57, Andreas Mayer a écrit :

    >
    > Am 19.04.2004 um 20:45 schrieb Eric Morand:
    >
    >> So I have to "guess" the colors, gradients, sizes, angles ?
    >
    > As I said, you can get some system colors from NSColor. Read the docs.
    >
    >> Have someone an idea of how the gradient are drawn ?
    >
    > I don't. Besides - those things change from one version of the OS to
    > the next. Mac OS X 10.1 looks different than 10.2, 10.2 looks
    > different than 10.3, and I bet that 10.4 will bring some new looks,
    > too.
    >
    >> And what is the Carbon Apperance Manager by the way ?
    >
    > http://developer.apple.com/cgi-bin/search.pl?
    > &q=appearance+manager&num=10&ie=utf8&oe=utf8&lr=lang_en&simp=1
    >
    >
    > Andreas
    >
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Am 19.04.2004 um 22:03 schrieb Eric Morand:

    > So, if I design a control matching today's standards, I'll have to
    > re-design it when 10.4 is released - if the control's standard look
    > changes with the new release ?

    If you can't use the Appearance Manager to draw it - yes. That's one
    reason you should use existing controls whenever possible.

    > I don't want to subclass NSComboBox because my control will not act
    > like a combo box.

    What exactly is your not-combo box supposed to do that a combo box
    can't?

    Andreas

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Just a question about this API : how do I use it ? I can't find any
    documentation about it in the ADC site - or am I not looking in the
    right place ?

    To Neil : I want a control that draw an outline view (instead of just a
    list) when clicked in the arrow. I need this to be able to have some
    sort of hierarchized datas instead of just a plain list. So I just want
    to design a sort of combo box that doesn't display a list. I'm nearly
    certain that I can't subclass NSComboBox to do this but maybe am I
    wrong ? Is there a way to change the view displayed by a combo box ?

    Le 20 avr. 04, à 00:08, Clark Cox a écrit :

    >
    > On Apr 19, 2004, at 16:03, Eric Morand wrote:
    >
    >>> I don't. Besides - those things change from one version of the OS to
    >>> the next. Mac OS X 10.1 looks different than 10.2, 10.2 looks
    >>> different than 10.3, and I bet that 10.4 will bring some new looks,
    >>> too.
    >>
    >> So, if I design a control matching today's standards, I'll have to
    >> re-design it when 10.4 is released - if the control's standard look
    >> changes with the new release ?
    >>
    >> That explains why so much apps have been updated to match 10.3
    >> standards... :o)
    >
    > Which is why the Appearance Manager (and now HITheme) is such a
    > valuable API.
    >
    > --
    > Clark S. Cox III
    > <clarkcox3...>
    > http://homepage.mac.com/clarkcox3/
    > http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • On 19 Apr 2004, at 23:41, Eric Morand wrote:

    > Just a question about this API : how do I use it ? I can't find any
    > documentation about it in the ADC site - or am I not looking in the
    > right place ?

    HITheme.h

    > To Neil : I want a control that draw an outline view (instead of just
    > a list) when clicked in the arrow. I need this to be able to have some
    > sort of hierarchized datas instead of just a plain list. So I just
    > want to design a sort of combo box that doesn't display a list. I'm
    > nearly certain that I can't subclass NSComboBox to do this but maybe
    > am I wrong ? Is there a way to change the view displayed by a combo
    > box ?

    It's generally bad practice to have controls that look the same as
    system controls but behave differently. It confuses users.

      -- Finlay

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Hi Eric,

    I'm not sure if I'm the Neil you are referring to, but I've had a think
    about it.  I've put a zipped nib on my site at
    <http://www.ose-ltd.com/ComboOutline.zip> which shows you four
    different ways that you could tackle this problem (there are, of
    course, many more).

    If you think about how an ordinary drop down combobox works, you'll see
    that you can build one with a text field, a button, and a list that is
    sometimes hidden.

    You could put a list, a button and a hidden outline in your view to
    create something that works like a drop down combobox.

    Alternatively, if you are really fussy about the appearance of the
    combobox, put a ComboBox on your view, then sit an Outline just
    underneath it.

    In either case, make the outline hidden, turn its headers off and bring
    it to the front so that it sits over any controls that it overlaps.

    If you are doing things the hard way, you'll find that ComboBox sends a
    comboBoxWillPopUp: message to its delegate when it's about to, er, drop
    down in your case.  This is your chance to jump in and make the outline
    visible.  It also sends comboBoxWillDismiss: when it's ready to retract
    its list.  You are going to want a user selection in your outline to
    set the combobox's value and nudge it out of its dropped down state.
    You are going to have to do a lot of reading up on combobox to figure
    out how to synchronise these two controls.

    Please bear in mind that I've never tried this, and, like Finlay says,
    it's not good practice to surprise your users.  That's  why I'd suggest
    the last option in the nib, the Distinctive Solution.  It uses a
    disclosure button and text field.  Outlines are full of disclosure
    buttons so users can take a good guess at what it will do.  Click le
    button, and the outline is unhidden; sounds like the easiest of all
    too!

    I don't know what your app is like, but would putting the outline in a
    drawer or a panel make sense for you?

    Salut,

    -Neil

    --

    Neil Earnshaw
    Consultant Software Engineer
    Object Software Engineers Ltd
    <neil...>
    Tel  : 01747 850 676
    Mbl : 07793 084 161

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Thanks Neil ! What an answer ! :o)

    I'll try your solutions as soon as I'm back from work.

    > Please bear in mind that I've never tried this, and, like Finlay says,
    > it's not good practice to surprise your users.  That's  why I'd
    > suggest the last option in the nib, the Distinctive Solution.  It uses
    > a disclosure button and text field.  Outlines are full of disclosure
    > buttons so users can take a good guess at what it will do.  Click le
    > button, and the outline is unhidden; sounds like the easiest of all
    > too!

    Finlay and you are right, I should give my control a distinctive look.
    Your idea seems good to me, I'll try it...

    Le 20 avr. 04, à 02:10, Neil Earnshaw a écrit :

    > Hi Eric,
    >
    > I'm not sure if I'm the Neil you are referring to, but I've had a
    > think about it.  I've put a zipped nib on my site at
    > <http://www.ose-ltd.com/ComboOutline.zip> which shows you four
    > different ways that you could tackle this problem (there are, of
    > course, many more).
    >
    > If you think about how an ordinary drop down combobox works, you'll
    > see that you can build one with a text field, a button, and a list
    > that is sometimes hidden.
    >
    > You could put a list, a button and a hidden outline in your view to
    > create something that works like a drop down combobox.
    >
    > Alternatively, if you are really fussy about the appearance of the
    > combobox, put a ComboBox on your view, then sit an Outline just
    > underneath it.
    >
    > In either case, make the outline hidden, turn its headers off and
    > bring it to the front so that it sits over any controls that it
    > overlaps.
    >
    > If you are doing things the hard way, you'll find that ComboBox sends
    > a comboBoxWillPopUp: message to its delegate when it's about to, er,
    > drop down in your case.  This is your chance to jump in and make the
    > outline visible.  It also sends comboBoxWillDismiss: when it's ready
    > to retract its list.  You are going to want a user selection in your
    > outline to set the combobox's value and nudge it out of its dropped
    > down state.  You are going to have to do a lot of reading up on
    > combobox to figure out how to synchronise these two controls.
    >
    > Please bear in mind that I've never tried this, and, like Finlay says,
    > it's not good practice to surprise your users.  That's  why I'd
    > suggest the last option in the nib, the Distinctive Solution.  It uses
    > a disclosure button and text field.  Outlines are full of disclosure
    > buttons so users can take a good guess at what it will do.  Click le
    > button, and the outline is unhidden; sounds like the easiest of all
    > too!
    >
    > I don't know what your app is like, but would putting the outline in a
    > drawer or a panel make sense for you?
    >
    > Salut,
    >
    > -Neil
    >
    > --
    >
    > Neil Earnshaw
    > Consultant Software Engineer
    > Object Software Engineers Ltd
    > <neil...>
    > Tel  : 01747 850 676
    > Mbl : 07793 084 161
    >

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • On 20/04/2004, at 6:52 PM, Eric Morand wrote:

    > Thanks Neil ! What an answer ! :o)
    >
    > I'll try your solutions as soon as I'm back from work.
    >
    >> Please bear in mind that I've never tried this, and, like Finlay
    >> says, it's not good practice to surprise your users.  That's  why I'd
    >> suggest the last option in the nib, the Distinctive Solution.  It
    >> uses a disclosure button and text field.  Outlines are full of
    >> disclosure buttons so users can take a good guess at what it will do.
    >> Click le button, and the outline is unhidden; sounds like the
    >> easiest of all too!
    >
    > Finlay and you are right, I should give my control a distinctive look.
    > Your idea seems good to me, I'll try it...
    >

    Eric:

    Looks like I'm jumping in a little late in the game.

    You could try composing your control with NSCells of the parts you
    want. They are really lightweight versions of the major controls -- the
    Flyweight GoF pattern -- in that they do not have any bounds, subviews,
    superviews etc. Basically all it is, is a collection of routines to
    draw and do event handling like their heavyweight counterparts, without
    the full context of their counterparts. E.g. look at their
    drawWithFrame: inView: which is just ObjC for "draw what looks like a
    control in this spot inside this containing view". Or trackMouse: ...
    which does the drop-down bit for popups etc. Or editWithFrame: which
    simulates text editing (by utilizing the window field editor
    transparently for you).

    I find NSComboBox'es a pain to really use well, especially their cell
    versions. When shrunk to small control size, the list box doesn't
    shrink too and the descenders get cut off. When hosting the cells in a
    NSTableView, the list box sometimes interferes with key handling, and
    the text is vertically off by a few pixels. About the only thing I like
    is the type-ahead feature. I ended up biting the bullet and
    implementing my own "PGPopUpTextFieldCell" which is a combination of a
    text field and a popup button, and it looks much more Mac-like now.

    Cheers, Glen Low

    ---
    pixelglow software | simply brilliant stuff
    www.pixelglow.com

    _______________________________________________
    MacOSX-dev mailing list
    <MacOSX-dev...>
    http://www.omnigroup.com/mailman/listinfo/macosx-dev
previous month april 2004 next month
MTWTFSS
      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    
Go to today