| 1 |
jmc |
1.1 |
/* macndlog.c -- dialog utilities for nifty application library |
| 2 |
|
|
*/ |
| 3 |
|
|
/* (C) Copyright 1995 by Carnegie Mellon University |
| 4 |
|
|
* All Rights Reserved. |
| 5 |
|
|
* |
| 6 |
|
|
* Permission to use, copy, modify, distribute, and sell this software |
| 7 |
|
|
* and its documentation for any purpose is hereby granted without |
| 8 |
|
|
* fee, provided that the above copyright notice appear in all copies |
| 9 |
|
|
* and that both that copyright notice and this permission notice |
| 10 |
|
|
* appear in supporting documentation, and that the name of Carnegie |
| 11 |
|
|
* Mellon University not be used in advertising or publicity |
| 12 |
|
|
* pertaining to distribution of the software without specific, |
| 13 |
|
|
* written prior permission. Carnegie Mellon University makes no |
| 14 |
|
|
* representations about the suitability of this software for any |
| 15 |
|
|
* purpose. It is provided "as is" without express or implied |
| 16 |
|
|
* warranty. |
| 17 |
|
|
* |
| 18 |
|
|
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 19 |
|
|
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 20 |
|
|
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE |
| 21 |
|
|
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 22 |
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN |
| 23 |
|
|
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING |
| 24 |
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
| 25 |
|
|
* SOFTWARE. |
| 26 |
|
|
*/ |
| 27 |
|
|
/* (C) Copyright 1990-1995 by Christopher J. Newman |
| 28 |
|
|
* All Rights Reserved. |
| 29 |
|
|
* |
| 30 |
|
|
* Permission to use, copy, modify, distribute, and sell this software and its |
| 31 |
|
|
* documentation for any purpose is hereby granted without fee, provided that |
| 32 |
|
|
* the above copyright notice appear in all copies and that both that |
| 33 |
|
|
* copyright notice and this permission notice appear in supporting |
| 34 |
|
|
* documentation, and that the name of Christopher J. Newman not be used in |
| 35 |
|
|
* advertising or publicity pertaining to distribution of the software without |
| 36 |
|
|
* specific, written prior permission. Christopher J. Newman makes no |
| 37 |
|
|
* representations about the suitability of this software for any purpose. It |
| 38 |
|
|
* is provided "as is" without express or implied warranty. |
| 39 |
|
|
* |
| 40 |
|
|
* CHRISTOPHER J. NEWMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 41 |
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT |
| 42 |
|
|
* SHALL CHRISTOPHER J. NEWMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 43 |
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 44 |
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 45 |
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 46 |
|
|
* OF THIS SOFTWARE. |
| 47 |
|
|
* |
| 48 |
|
|
* Author: Christopher J. Newman |
| 49 |
|
|
* Message: This is a nifty program. |
| 50 |
|
|
*/ |
| 51 |
|
|
|
| 52 |
|
|
#ifndef THINK_C |
| 53 |
|
|
#include <ToolUtils.h> |
| 54 |
|
|
#endif |
| 55 |
|
|
#include <Balloons.h> |
| 56 |
|
|
#include "macnapp.h" |
| 57 |
|
|
|
| 58 |
|
|
/* enable/disable menus for a moveable modal dialog |
| 59 |
|
|
*/ |
| 60 |
|
|
void NAmodalMenus(int begin) |
| 61 |
|
|
{ |
| 62 |
|
|
short i, end; |
| 63 |
|
|
MenuHandle mh; |
| 64 |
|
|
|
| 65 |
|
|
/* unhilite menus */ |
| 66 |
|
|
HiliteMenu(0); |
| 67 |
|
|
|
| 68 |
|
|
/* everything but the edit/apple/help menus */ |
| 69 |
|
|
for (i = mFile; (mh = NAmenuh(i)); ++i) { |
| 70 |
|
|
if (i != mEdit) { |
| 71 |
|
|
if (begin) DisableItem(mh, 0); |
| 72 |
|
|
else EnableItem(mh, 0); |
| 73 |
|
|
} |
| 74 |
|
|
} |
| 75 |
|
|
|
| 76 |
|
|
/* kill the help items */ |
| 77 |
|
|
mh = NAmenuh(mApple); |
| 78 |
|
|
i = NAappleitems; |
| 79 |
|
|
if (NAhelpcount) { |
| 80 |
|
|
HMGetHelpMenuHandle(&mh); |
| 81 |
|
|
i = NAhelpcount + 1; |
| 82 |
|
|
} |
| 83 |
|
|
for (end = NAhelpitems + i; i <= end; ++i) { |
| 84 |
|
|
if (begin) DisableItem(mh, i); |
| 85 |
|
|
else EnableItem(mh, i); |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
|
DrawMenuBar(); |
| 89 |
|
|
} |
| 90 |
|
|
|
| 91 |
|
|
/* enable/disable a control in a dialog window |
| 92 |
|
|
*/ |
| 93 |
|
|
void NAenableDItem(DialogPtr dialog, short item, Boolean on) |
| 94 |
|
|
{ |
| 95 |
|
|
short type; |
| 96 |
|
|
Handle ctrl; |
| 97 |
|
|
short ty; |
| 98 |
|
|
Rect box; |
| 99 |
|
|
|
| 100 |
|
|
GetDItem(dialog, item, &ty, &ctrl, &box); |
| 101 |
|
|
type = ty; |
| 102 |
|
|
if (on) type &= ~itemDisable; |
| 103 |
|
|
else type |= itemDisable; |
| 104 |
|
|
if (type == (editText | itemDisable)) { |
| 105 |
|
|
type = statText; |
| 106 |
|
|
} else if (type == statText) { |
| 107 |
|
|
type = editText; |
| 108 |
|
|
} |
| 109 |
|
|
SetDItem(dialog, item, type, ctrl, &box); |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
/* hilite a control in a dialog window |
| 113 |
|
|
*/ |
| 114 |
|
|
void NAhiliteDItem(DialogPtr dialog, short item, short how) |
| 115 |
|
|
{ |
| 116 |
|
|
Handle ctrl; |
| 117 |
|
|
short type; |
| 118 |
|
|
Rect box; |
| 119 |
|
|
PenState tmpPen; |
| 120 |
|
|
|
| 121 |
|
|
GetDItem(dialog, item, &type, &ctrl, &box); |
| 122 |
|
|
if (type & ctrlItem) { |
| 123 |
|
|
HiliteControl((ControlHandle) ctrl, how); |
| 124 |
|
|
} else if (type & (statText | editText)) { |
| 125 |
|
|
GetPenState(&tmpPen); |
| 126 |
|
|
PenNormal(); |
| 127 |
|
|
if (how == 255) PenPat(QD(gray)); |
| 128 |
|
|
InsetRect(&box, -3, -3); |
| 129 |
|
|
FrameRect(&box); |
| 130 |
|
|
SetPenState(&tmpPen); |
| 131 |
|
|
} |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
/* make an item visible/invisible in a dialog window |
| 135 |
|
|
*/ |
| 136 |
|
|
void NAvisibleDItem(DialogPtr dialog, short item, Boolean show) |
| 137 |
|
|
{ |
| 138 |
|
|
if (show) ShowDItem(dialog, item); |
| 139 |
|
|
else HideDItem(dialog, item); |
| 140 |
|
|
} |
| 141 |
|
|
|
| 142 |
|
|
/* set the text in a dialog item |
| 143 |
|
|
*/ |
| 144 |
|
|
void NAsetIText(DialogPtr dialog, short item, PCstr *str) |
| 145 |
|
|
{ |
| 146 |
|
|
Handle texth; |
| 147 |
|
|
|
| 148 |
|
|
NAgetDHandle(dialog, item, &texth); |
| 149 |
|
|
SetIText(texth, str); |
| 150 |
|
|
} |
| 151 |
|
|
|
| 152 |
|
|
/* get the text in a dialog item |
| 153 |
|
|
*/ |
| 154 |
|
|
void NAgetIText(DialogPtr dialog, short item, PCstr *str) |
| 155 |
|
|
{ |
| 156 |
|
|
Handle texth; |
| 157 |
|
|
|
| 158 |
|
|
NAgetDHandle(dialog, item, &texth); |
| 159 |
|
|
GetIText(texth, str); |
| 160 |
|
|
SetClen(str); |
| 161 |
|
|
} |
| 162 |
|
|
|
| 163 |
|
|
/* set the appropriate radio buttons |
| 164 |
|
|
*/ |
| 165 |
|
|
short NAradioSet(DialogPtr dialog, short firstitem, short lastitem, short setting) |
| 166 |
|
|
{ |
| 167 |
|
|
short item; |
| 168 |
|
|
ControlHandle ctrl; |
| 169 |
|
|
|
| 170 |
|
|
for (item = firstitem; item <= lastitem; item++) { |
| 171 |
|
|
NAgetDHandle(dialog, item, &ctrl); |
| 172 |
|
|
SetCtlValue(ctrl, item == setting ? 1 : 0); |
| 173 |
|
|
} |
| 174 |
|
|
|
| 175 |
|
|
return (setting - firstitem); |
| 176 |
|
|
} |
| 177 |
|
|
|
| 178 |
|
|
/* get the itemno of the active radio button |
| 179 |
|
|
*/ |
| 180 |
|
|
short NAradioGet(DialogPtr dialog, short firstitem, short lastitem) |
| 181 |
|
|
{ |
| 182 |
|
|
short item; |
| 183 |
|
|
ControlHandle ctrl; |
| 184 |
|
|
|
| 185 |
|
|
for (item = firstitem; item <= lastitem; item++) { |
| 186 |
|
|
NAgetDHandle(dialog, item, &ctrl); |
| 187 |
|
|
if (GetCtlValue(ctrl)) return (item); |
| 188 |
|
|
} |
| 189 |
|
|
|
| 190 |
|
|
return (firstitem); |
| 191 |
|
|
} |
| 192 |
|
|
|
| 193 |
|
|
/* handle the edit menu for a dialog window |
| 194 |
|
|
*/ |
| 195 |
|
|
short NAdialogMenu(na_win *win, WORD menu, WORD item) |
| 196 |
|
|
{ |
| 197 |
|
|
MenuHandle mh = NAmenuh(mEdit); |
| 198 |
|
|
DialogPeek dpeek = (DialogPeek) win->pwin; |
| 199 |
|
|
short result = NA_NOTPROCESSED; |
| 200 |
|
|
|
| 201 |
|
|
switch (menu) { |
| 202 |
|
|
case 0: |
| 203 |
|
|
if ((*dpeek->textH)->selStart != (*dpeek->textH)->selEnd) { |
| 204 |
|
|
EnableItem(mh, iCopy); |
| 205 |
|
|
EnableItem(mh, iCut); |
| 206 |
|
|
EnableItem(mh, iClear); |
| 207 |
|
|
} |
| 208 |
|
|
EnableItem(mh, iPaste); |
| 209 |
|
|
if ((*dpeek->textH)->teLength > 0) EnableItem(mh, iSelAll); |
| 210 |
|
|
break; |
| 211 |
|
|
case mEdit: |
| 212 |
|
|
switch (item) { |
| 213 |
|
|
case iCut: |
| 214 |
|
|
DlgCut(win->pwin); |
| 215 |
|
|
ZeroScrap(); |
| 216 |
|
|
TEToScrap(); |
| 217 |
|
|
break; |
| 218 |
|
|
case iCopy: |
| 219 |
|
|
DlgCopy(win->pwin); |
| 220 |
|
|
ZeroScrap(); |
| 221 |
|
|
TEToScrap(); |
| 222 |
|
|
break; |
| 223 |
|
|
case iClear: |
| 224 |
|
|
DlgDelete(win->pwin); |
| 225 |
|
|
break; |
| 226 |
|
|
case iPaste: |
| 227 |
|
|
DlgPaste(win->pwin); |
| 228 |
|
|
break; |
| 229 |
|
|
case iSelAll: |
| 230 |
|
|
SelIText(win->pwin, dpeek->editField + 1, 0, 32767); |
| 231 |
|
|
break; |
| 232 |
|
|
} |
| 233 |
|
|
result = NA_PROCESSED; |
| 234 |
|
|
break; |
| 235 |
|
|
} |
| 236 |
|
|
if (menu != 0) DisableItem(mh, iSelAll); |
| 237 |
|
|
|
| 238 |
|
|
return (result); |
| 239 |
|
|
} |