home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 10.2 KB | 252 lines | [TEXT/KAHL] |
- //------------------------- © 1991-1995 by James G. Stout --------------------------
- // File : cdefPopMenu.h
- // Date : September 1,1991
- // Author : Jim Stout
- // Purpose : popup menu cdef
- // :
- // : Implements all of the features of the Apple popUpMenu CDEF 63.
- // :
- // : This CDEF is "plug" compatible with the Apple CDEF.
- // :
- // : Any program that successfully uses that CDEF should be able to
- // : use this one.
- // :
- // : The only feature I have not implemented is drawing of menus
- // : with command-key equivalents. The space where that should
- // : drawn is pre-empted by the "popup symbol".
- // : The menu will simply draw without the command-key, it will
- // : be there when you "pop" the menu.
- // :
- // : This CDEF corrects a couple of minor objections I have with
- // : the Apple CDEF. Unlike the Apple CDEF, this CDEF:
- // :
- // : 1. Behaves the same in both System 6 and 7, including
- // : support for menus with icons and color.
- // : 2. Only draws its title with Menu colors when
- // : it is "popped" up (IMHO, this looks better).
- // : 3. It will accept "dynamic" menus created via calls to NewMenu()
- // : rather than just resource based menus.
- // : 4. Works correctly with popupFixedWidth when the menu is
- // : narrower than the controlRect.
- // :
- // : I have implemented a few extensions to the Apple CDEF:
- // :
- // : 1. "Embossed" 3D title
- // : This is variation code 2. It results in a control title that
- // : has an embossed appearance by drawing the title with a white
- // : shadow.
- // :
- // : Note that this is a departure from the use of this variation
- // : in the System 6 popup which used 2 for useCQD - for colored
- // : menus. This variation is not defined/doesn't work with the
- // : System 7 popup CDEF.
- // :
- // : The following extensions are created by adding an "pseudo
- // : variation code" to the title width parameter in the controlMax
- // : field of the control template.
- // :
- // : The first 4 are additive and can be combined with any other
- // : "pseudo variation code".
- // :
- // : 2. No item marks
- // : Calling program can use SetItemMark() to set a mark if needed.
- // : One use of this would be to create a popup similar to the one
- // : used in Standard file dialogs.
- // :
- // : 3. An inset frame
- // : Since a popup menu looks rather odd on 3D dialogs, this
- // : draws an inset frame for the popup rather than the usual
- // : raised, drop-shadowed frame. The grafPort background color
- // : is used for the popup background because the inset effect
- // : is lost if the menu background is white.
- // :
- // : 4. Black symbol
- // : Default behavior with colored menus is to draw the popup symbol
- // : in the item text color. If you always want black symbols, add
- // : this "variation code" to controlMax.
- // :
- // : 6. "No DeleteMenu" popups. Normally, the CDEF calls DeleteMenu
- // : (per the Apple guidelines) after calling PopupMenuSelect. This
- // : causes menu color information to be deleted as well. If this
- // : menu color info is supplied via an 'mctb' resource, the CDEF will
- // : 'reload' the colors. If the color info was supplied via
- // : SetMCEntries as part of a 'dynamic' menu, there is no easy way
- // : for the CDEF to recover the colors - hence this variation.
- // :
- // : The following 4 are NOT additive with each other. If added together,
- // : the results are undefined (meaning I didn't test to see what happens).
- // :
- // : 7. "Symbol" only popups
- // : For "type in" popups often used for Font size selection in
- // : conjunction with edit text items in dialogs. Additional code
- // : is needed to implement this, see the demoCDEF program source.
- // :
- // : 8. Popups with no "Symbol"
- // : No downward pointing triangle is drawn, as in the System 6
- // : version of CDEF 63.
- // :
- // : 9. Popups with icons only
- // : This results in a "popup Icon button" effect since only a
- // : framed icon (of any size or type) is drawn. Item text and
- // : the popup symbol are not drawn.
- // : Set the control rect to 5 pixels more than the largest icon.
- // :
- // : 10. Popups with centered text
- // : This results in a "popup text button" effect since the menu
- // : item text is drawn, centered in the control rect.
- // :
- // : To use, call NewControl as normal, with the following special meanings
- // : to the parameters listed below. Or set up a ResEdit CNTL template.
- // : These are exactly the same as Apple's CDEF 63.
- // :
- // :
- // : value : title justification & title text style.
- // : Justification
- // :
- // : : popupTitleLeftJust = 0x0000
- // : : popupTitleCenterJust = 0x0001
- // : : popupTitleRightJust = 0x00FF
- // :
- // : Text Styles
- // :
- // : : popupTitleBold = 0x0100
- // : : popupTitleItalic = 0x0200
- // : : popupTitleUnderline = 0x0400
- // : : popupTitleOutline = 0x0800
- // : : popupTitleShadow = 0x1000
- // : : popupTitleCondense = 0x2000
- // : : popupTitleExtend = 0x4000
- // : : popupTitleNoStyle = 0x8000
- // :
- // : min : resId of menu to use, even if using popupUseAddResMenu,
- // : it is best to have a 'dummy' menu resource with no
- // : items defined.
- // :
- // : max : width of title item - from controlRect.left.
- // : : 0 = no title drawn.
- // : :
- // : : add pseudo variation codes to get:
- // :
- // : : popupNoMark = don't use marks on current item.
- // : : popupBlackSymbol = always draw black popup symbol
- // : : popupSymbolOnly = draw 'popUp symbol' only
- // : : popupNoSymbol = don't draw 'popUp symbol'.
- // : : popupIconOnly = no symbol and Icon only in control.
- // : : popupCenterText = no symbol and text centered in control
- // : : popupNoDeleteMenu = don't call DeleteMenu after PopUpMenuSelect
- // - call when disposing the control.
- // :
- // : refCon : if varCode of popupUseAddResMenu, put the ResType
- // : in the refCon field of the control.
- //
- // : procId : 1600 + varCode (1101 * 16) + varCode
- // : : varCodes:
- // : popupFixedWidth = 0x0001
- // : ctl3D = 0x0002
- // : popupUseAddResMenu = 0x0004
- // : popupUseWFont = 0x0008
- //
- //----------------------------------------------------------------------------------
-
- #ifndef popupTitleLeftJust // should be in Controls.h
-
- //----------------------------------------------------------------------------------
- // special meanings for contrlValue field
- //----------------------------------------------------------------------------------
-
- #define popupTitleLeftJust 0x0000
- #define popupTitleCenterJust 0x0001
- #define popupTitleRightJust 0x00FF
- #define popupTitleBold 0x0100
- #define popupTitleItalic 0x0200
- #define popupTitleUnderline 0x0400
- #define popupTitleOutline 0x0800
- #define popupTitleShadow 0x1000
- #define popupTitleCondense 0x2000
- #define popupTitleExtend 0x4000
- #define popupTitleNoStyle 0x8000
-
- //----------------------------------------------------------------------------------
- // variation codes
- //----------------------------------------------------------------------------------
-
- #define popupFixedWidth 0x0001
- #define ctl3D 0x0002
- #define popupUseAddResMenu 0x0004
- #define popupUseWFont 0x0008
-
- #endif
-
- //----------------------------------------------------------------------------------
- // pseudo variation codes - add to title width in contrlMax field
- //----------------------------------------------------------------------------------
-
- #define popupNoTitle 0x0000
- #define popupNoMark 0x0100
- #define popupInsetFrame 0x0200
- #define popupBlackSymbol 0x0400
- #define popupSymbolOnly 0x0800
- #define popupNoSymbol 0x1000
- #define popupIconOnly 0x2000
- #define popupCenterText 0x4000
- #define popupNoDeleteMenu 0x8000
-
- #define DOT 0xA5 // item marks used if not using popupNoMark
- #define CHECKMARK 0x12
- #define ELLIPSIS 0xC9
- #define SHADOW 3 // extra space needed for drop shadow box
-
- //----------------------------------------------------------------------------------
- // Note: This is NOT the Apple struct of the same name. Only the first 2
- // elements are documented by Apple, I left them the same in this
- // structure, but everything after mId is unique to this CDEF.
- //----------------------------------------------------------------------------------
-
- typedef struct{
- MenuHandle mHandle; // handle to the menu
- short mId; // resource id of menu
-
- Rect rTitle; // rect for title
- Rect rItem; // rect for popup
- Rect rIcon; // rect for icon
- short tJust; // title justification & style flag
- short tWid; // requested title width
- short varCode2; // extra variations
- short symWid; // extra space needed for popup symbol
- short symHt; // symbol height
- short vDraw; // Title & Item draw v point
- short hTitle; // Title draw h point
- short hItem; // Item draw h point
- short txFont;
- short txSize;
- short osVers; // for later reference
- SignedByte hMenuState; // thanks Gord!
- Boolean hasColorQD; // ditto
- Boolean relMenuRes;
- }popUpPrivateData,**popUpPrivateDataH;
-
- //----------------------------------------------------------------------------------
- // Function prototypes
- //----------------------------------------------------------------------------------
-
- static void doInit (ControlHandle, short);
- static void doDisp (ControlHandle, short);
- static void doDraw (ControlHandle, short);
- pascal void drawControl (short depth, short dFlags, GDHandle theDevice,
- long userData);
- static void doPopUp (ControlHandle, short);
-
- static void drawSymbol (Rect, short, short);
- static void drawPopupFrame (Rect *);
- static void getRects (ControlHandle, Boolean);
- static void resizePopup (ControlHandle, short);
- static pascal void myCalcMenuSize (MenuHandle);
- static void patchCalcMenuSize (short);
- static void getMenuColors (short, short, RGBColor *, RGBColor *);
- static void setMenuColors (short);
- static Boolean setFont (GrafPtr, short *, short *, short, Boolean);
- static void restoreFont (GrafPtr, short, short, short);
- static void getIconSize (short, Rect *);
- static void plotAnIcon (short, Rect *, short, short,
- Boolean, Boolean, Boolean);
- extern Boolean hasColorQD (void);