Pop-up CDEF
Volume Number: 4
Issue Number: 9
Column Tag: Programmer's Workshop
Pop-up Menus CDEF
By James Plamondon, Berkeley, CA
Pop-up Menu
Control Definition Function
by James Plamondon
[James Plamondon has a BS in Computer Science from the University of New
Mexico, in addition to a BS and Master's work in Geology. He has programmed
professionally on the Mac for one year, and about two years before. He is currently
working at Abacus Concepts, makers of StatView.]
The Challenge
I like a challenge as much as the next Guy. Like Sir Edmund Hillary, I sometimes
accept challenges just because they’re there. But it’s always satisfying when I can do
some programming which is fun for me, and beneficial to my employer as well.
In Inside Macintosh, Volume Five, on page 242, I found my most recent Everest.
That page discusses how to use the new Toolbox function PopUpMenuSelect(). Near the
end of the page is the brief notation: “[using PopUpMenuSelect()] could be handled by
creating a pop-up menu control within the application.”
That sounded useful, so I called Mac Developer Services (on AppleLink) and asked
for a copy of the pop-up menu control’s definition function To my surprise, it didn’t
exist -- or at least, they didn’t have one.
There was the challenge. With a pop-up menu Control Definition Function
(CDEF), pop-up menus could be used as easily as radio buttons or scroll bars. The
application that I was writing for my employer at the time would also make use of
pop-up menus, so I could even justify the time I spent on it! What a deal!
Why Use a CDEF?
Have you ever written code to draw a pushbutton -- such as the OK or Cancel
buttons in a dialog? Have you ever written code to draw a scroll bar, hilite an
up-arrow, or draw a thumb region being dragged?
Probably not. All of those operations are performed by Apple’s standard CDEFs.
Because Apple includes these in all of its System files, you never have to worry about
drawing or manipulating these controls. The CDEFs do all of the work, without your
even paying attention to it.
What would happen if Apple didn’t provide these standard CDEFs? Every button
would look and feel different. (Did I say “look and feel?” Sounds like a lawyer!)
Imagine how different Mac software would be today if all push buttons, radio buttons,
checkboxes, and scroll bars behaved differently. (And think how different
MS-Windows would be!) The standardization of such controls greatly enhanced the