Back to home page

MITgcm

 
 

    


File indexing completed on 2018-03-02 18:44:53 UTC

view on githubraw file Latest commit ec6cf3b0 on 2003-08-26 20:45:25 UTC
ec6cf3b09d Ed H*0001 /* macndlog.c -- dialog utilities for nifty application library
                0002  */
                0003 /* (C) Copyright 1995 by Carnegie Mellon University
                0004  * All Rights Reserved.
                0005  *
                0006  * Permission to use, copy, modify, distribute, and sell this software
                0007  * and its documentation for any purpose is hereby granted without
                0008  * fee, provided that the above copyright notice appear in all copies
                0009  * and that both that copyright notice and this permission notice
                0010  * appear in supporting documentation, and that the name of Carnegie
                0011  * Mellon University not be used in advertising or publicity
                0012  * pertaining to distribution of the software without specific,
                0013  * written prior permission.  Carnegie Mellon University makes no
                0014  * representations about the suitability of this software for any
                0015  * purpose.  It is provided "as is" without express or implied
                0016  * warranty.
                0017  *
                0018  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
                0019  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
                0020  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
                0021  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                0022  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
                0023  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                0024  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                0025  * SOFTWARE.
                0026  */
                0027 /* (C) Copyright 1990-1995 by Christopher J. Newman
                0028  * All Rights Reserved.
                0029  *
                0030  * Permission to use, copy, modify, distribute, and sell this software and its
                0031  * documentation for any purpose is hereby granted without fee, provided that
                0032  * the above copyright notice appear in all copies and that both that
                0033  * copyright notice and this permission notice appear in supporting
                0034  * documentation, and that the name of Christopher J. Newman not be used in
                0035  * advertising or publicity pertaining to distribution of the software without
                0036  * specific, written prior permission.  Christopher J. Newman makes no
                0037  * representations about the suitability of this software for any purpose.  It
                0038  * is provided "as is" without express or implied warranty.
                0039  *
                0040  * CHRISTOPHER J. NEWMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
                0041  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
                0042  * SHALL CHRISTOPHER J. NEWMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
                0043  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
                0044  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
                0045  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
                0046  * OF THIS SOFTWARE.
                0047  *
                0048  * Author:  Christopher J. Newman
                0049  * Message: This is a nifty program.
                0050  */
                0051 
                0052 #ifndef THINK_C
                0053 #include <ToolUtils.h>
                0054 #endif
                0055 #include <Balloons.h>
                0056 #include "macnapp.h"
                0057 
                0058 /* enable/disable menus for a moveable modal dialog
                0059  */
                0060 void NAmodalMenus(int begin)
                0061 {
                0062     short i, end;
                0063     MenuHandle mh;
                0064     
                0065     /* unhilite menus */
                0066     HiliteMenu(0);
                0067     
                0068     /* everything but the edit/apple/help menus */
                0069     for (i = mFile; (mh = NAmenuh(i)); ++i) {
                0070         if (i != mEdit) {
                0071             if (begin) DisableItem(mh, 0);
                0072             else EnableItem(mh, 0);
                0073         }
                0074     }
                0075     
                0076     /* kill the help items */
                0077     mh = NAmenuh(mApple);
                0078     i = NAappleitems;
                0079     if (NAhelpcount) {
                0080         HMGetHelpMenuHandle(&mh);
                0081         i = NAhelpcount + 1;
                0082     }
                0083     for (end = NAhelpitems + i; i <= end; ++i) {
                0084         if (begin) DisableItem(mh, i);
                0085         else EnableItem(mh, i);
                0086     }
                0087     
                0088     DrawMenuBar();
                0089 }
                0090 
                0091 /* enable/disable a control in a dialog window
                0092  */
                0093 void NAenableDItem(DialogPtr dialog, short item, Boolean on)
                0094 {
                0095     short   type;
                0096     Handle          ctrl;
                0097     short           ty;
                0098     Rect            box;
                0099     
                0100     GetDItem(dialog, item, &ty, &ctrl, &box);
                0101     type = ty;
                0102     if (on) type &= ~itemDisable;
                0103     else    type |= itemDisable;
                0104     if (type == (editText | itemDisable)) {
                0105         type = statText;
                0106     } else if (type == statText) {
                0107         type = editText;
                0108     }
                0109     SetDItem(dialog, item, type, ctrl, &box);
                0110 }
                0111 
                0112 /* hilite a control in a dialog window
                0113  */
                0114 void NAhiliteDItem(DialogPtr dialog, short item, short how)
                0115 {
                0116     Handle      ctrl;
                0117     short       type;
                0118     Rect        box;
                0119     PenState    tmpPen;
                0120     
                0121     GetDItem(dialog, item, &type, &ctrl, &box);
                0122     if (type & ctrlItem) {
                0123         HiliteControl((ControlHandle) ctrl, how);
                0124     } else if (type & (statText | editText)) {
                0125         GetPenState(&tmpPen);
                0126         PenNormal();
                0127         if (how == 255) PenPat(QD(gray));
                0128         InsetRect(&box, -3, -3);
                0129         FrameRect(&box);
                0130         SetPenState(&tmpPen);
                0131     }
                0132 }
                0133 
                0134 /* make an item visible/invisible in a dialog window
                0135  */
                0136 void NAvisibleDItem(DialogPtr dialog, short item, Boolean show)
                0137 {
                0138     if (show)   ShowDItem(dialog, item);
                0139     else        HideDItem(dialog, item);
                0140 }
                0141 
                0142 /* set the text in a dialog item
                0143  */
                0144 void NAsetIText(DialogPtr dialog, short item, PCstr *str)
                0145 {
                0146     Handle      texth;
                0147     
                0148     NAgetDHandle(dialog, item, &texth);
                0149     SetIText(texth, str);
                0150 }
                0151 
                0152 /* get the text in a dialog item
                0153  */
                0154 void NAgetIText(DialogPtr dialog, short item, PCstr *str)
                0155 {
                0156     Handle      texth;
                0157     
                0158     NAgetDHandle(dialog, item, &texth);
                0159     GetIText(texth, str);
                0160     SetClen(str);
                0161 }
                0162 
                0163 /* set the appropriate radio buttons
                0164  */
                0165 short NAradioSet(DialogPtr dialog, short firstitem, short lastitem, short setting)
                0166 {
                0167     short   item;
                0168     ControlHandle   ctrl;
                0169     
                0170     for (item = firstitem; item <= lastitem; item++) {
                0171         NAgetDHandle(dialog, item, &ctrl);
                0172         SetCtlValue(ctrl, item == setting ? 1 : 0);
                0173     }
                0174     
                0175     return (setting - firstitem);
                0176 }
                0177 
                0178 /* get the itemno of the active radio button
                0179  */
                0180 short NAradioGet(DialogPtr dialog, short firstitem, short lastitem)
                0181 {
                0182     short   item;
                0183     ControlHandle   ctrl;
                0184     
                0185     for (item = firstitem; item <= lastitem; item++) {
                0186         NAgetDHandle(dialog, item, &ctrl);
                0187         if (GetCtlValue(ctrl)) return (item);
                0188     }
                0189     
                0190     return (firstitem);
                0191 }
                0192 
                0193 /* handle the edit menu for a dialog window
                0194  */
                0195 short NAdialogMenu(na_win *win, WORD menu, WORD item)
                0196 {
                0197     MenuHandle  mh = NAmenuh(mEdit);
                0198     DialogPeek dpeek = (DialogPeek) win->pwin;
                0199     short result = NA_NOTPROCESSED;
                0200     
                0201     switch (menu) {
                0202         case 0:
                0203             if ((*dpeek->textH)->selStart != (*dpeek->textH)->selEnd) {
                0204                 EnableItem(mh, iCopy);
                0205                 EnableItem(mh, iCut);
                0206                 EnableItem(mh, iClear);
                0207             }
                0208             EnableItem(mh, iPaste);
                0209             if ((*dpeek->textH)->teLength > 0) EnableItem(mh, iSelAll);
                0210             break;
                0211         case mEdit:
                0212             switch (item) {
                0213                 case iCut:
                0214                     DlgCut(win->pwin);
                0215                     ZeroScrap();
                0216                     TEToScrap();
                0217                     break;
                0218                 case iCopy:
                0219                     DlgCopy(win->pwin);
                0220                     ZeroScrap();
                0221                     TEToScrap();
                0222                     break;
                0223                 case iClear:
                0224                     DlgDelete(win->pwin);
                0225                     break;
                0226                 case iPaste:
                0227                     DlgPaste(win->pwin);
                0228                     break;
                0229                 case iSelAll:
                0230                     SelIText(win->pwin, dpeek->editField + 1, 0, 32767);
                0231                     break;
                0232             }
                0233             result = NA_PROCESSED;
                0234             break;
                0235     }
                0236     if (menu != 0) DisableItem(mh, iSelAll);
                0237     
                0238     return (result);
                0239 }