File indexing completed on 2018-03-02 18:44:54 UTC
view on githubraw file Latest commit ec6cf3b0 on 2003-08-26 20:45:25 UTC
ec6cf3b09d Ed H*0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 #ifndef THINK_C
0053 #include <Fonts.h>
0054 #include <SegLoad.h>
0055 #include <OSEvents.h>
0056
0057 extern void _DataInit();
0058 #endif
0059 #include <string.h>
0060 #include <Traps.h>
0061 #include <AppleEvents.h>
0062 #include <GestaltEqu.h>
0063 #include <Balloons.h>
0064 #include "macnapp.h"
0065
0066 extern pascal OSErr NArequiredAE(AppleEvent *, AppleEvent *, long);
0067
0068 #ifndef _Unimplemented
0069 #define _Unimplemented 0xA89F
0070 #endif
0071 #ifndef _WaitNextEvent
0072 #define _WaitNextEvent 0xA860
0073 #endif
0074 #ifndef _Gestalt
0075 #define _Gestalt 0xA1AD
0076 #endif
0077
0078
0079 extern THz NAappzone;
0080
0081 static Boolean TrapAvailable(short);
0082
0083
0084
0085 static Boolean TrapAvailable(short tNumber)
0086 {
0087 short numtraps = 0x400;
0088 TrapType tType;
0089
0090 tType = tNumber & 0x800 ? ToolTrap : OSTrap;
0091 if (tType == ToolTrap) {
0092 if (NGetTrapAddress(_InitGraf, ToolTrap)
0093 == NGetTrapAddress(0xAA6E, ToolTrap)) {
0094 numtraps = 0x200;
0095 }
0096 tNumber = tNumber & 0x07FF;
0097 if (tNumber >= numtraps)
0098 tNumber = _Unimplemented;
0099 }
0100
0101 return (NGetTrapAddress(tNumber, tType)
0102 != NGetTrapAddress(_Unimplemented, ToolTrap));
0103 }
0104
0105
0106
0107
0108 short NAinit(short minK, short masters, na_openp openp, na_menup menup,
0109 short nummenu, short numapple, short newitem, short closeitem)
0110 {
0111 long total, contig, response, procid;
0112 EventRecord event;
0113 short count;
0114 Handle menuBar;
0115 short message, i, aeflag = 0;
0116 AppFile afile;
0117 FSSpec fspec;
0118 Str255 str;
0119 MenuHandle mh, helpmh;
0120 CInfoPBRec catinfo;
0121
0122 #ifndef THINK_C
0123 UnloadSeg((Ptr) _DataInit);
0124 #endif
0125 MaxApplZone();
0126
0127
0128 InitGraf((Ptr) &QD(thePort));
0129 InitFonts();
0130 InitWindows();
0131 InitMenus();
0132 TEInit();
0133 InitDialogs(NULL);
0134 InitCursor();
0135
0136
0137 for (count = 1; count <= masters; count++) {
0138 MoreMasters();
0139 if (MemError() != noErr) return (-1);
0140 }
0141
0142
0143 for (count = 1; count <= 3; count++) EventAvail(everyEvent, &event);
0144
0145
0146 (void) SysEnvirons(1, &NAsysenv);
0147
0148
0149 if (NAsysenv.machineType < 0
0150 || !TrapAvailable(_WaitNextEvent)
0151 || (long) GetApplLimit() - (long) ApplicZone() < minK) {
0152 return (-1);
0153 }
0154
0155
0156
0157
0158 NAgestaltBits = 0;
0159 if (Gestalt(gestaltAppleEventsAttr, &response) == noErr) {
0160 NAgestaltBits |= NA_HASAEVENTS;
0161 if (AEInstallEventHandler(kCoreEventClass, typeWildCard,
0162 NArequiredAE, (long) openp, FALSE) == noErr) {
0163 aeflag = 1;
0164 }
0165 }
0166 if (Gestalt(gestaltFSAttr, &response) == noErr
0167 && (response & gestaltHasFSSpecCalls)) {
0168 NAgestaltBits |= NA_HASFSSPEC;
0169 }
0170 if (Gestalt(gestaltStandardFileAttr, &response) == noErr) {
0171 NAgestaltBits |= NA_HASSTDFILE;
0172 }
0173
0174
0175 PurgeSpace(&total, &contig);
0176 if (total < minK) return (-1);
0177
0178
0179 NAappzone = ApplicZone();
0180
0181
0182 NAmenus = NULL;
0183 if (menup != (na_menup) NULL) {
0184 NAmenus = (MenuHandle **) NewHandle(sizeof (MenuHandle) * (nummenu + 1));
0185 if (NAmenus == (MenuHandle **) NULL) return (-1);
0186 HLock((Handle) NAmenus);
0187 for (i = 0; i < nummenu; ++i) {
0188 InsertMenu((*NAmenus)[i] = GetMenu(mApple + i), 0);
0189 }
0190 (*NAmenus)[i] = NULL;
0191 HUnlock((Handle) NAmenus);
0192 mh = **NAmenus;
0193 *str = 0;
0194 GetIndString(str, NA_HELPSTR, 1);
0195 if (*str) {
0196 if (Gestalt(gestaltHelpMgrAttr, &response) != noErr
0197 || HMGetHelpMenuHandle(&helpmh) != noErr) {
0198 helpmh = mh;
0199 } else {
0200 NAhelpcount = CountMItems(helpmh);
0201 }
0202 for (i = 2; *str; ++i) {
0203 ++NAhelpitems;
0204 AppendMenu(helpmh, str);
0205 GetIndString(str, NA_HELPSTR, i);
0206 }
0207 }
0208 AppendMenu(mh, "\p-");
0209 AddResMenu(mh, 'DRVR');
0210 DrawMenuBar();
0211 NAcloseitem = closeitem;
0212 NAnewitem = newitem;
0213 NAappleitems = numapple;
0214 if (nummenu > 2) NAhasedit = true;
0215 NAmenup = menup;
0216 }
0217
0218
0219 NAfullRgn = NewRgn();
0220 NAnullRgn = NewRgn();
0221 if (!NAfullRgn || !NAnullRgn) return (-1);
0222 SetRectRgn(NAfullRgn, -32767, -32767, 32767, 32767);
0223
0224
0225 NAibeam = **GetCursor(iBeamCursor);
0226
0227
0228 if (!aeflag) {
0229 count = 0;
0230 if (openp != (na_openp) NULL) {
0231 CountAppFiles(&message, &count);
0232 if (count) {
0233 for (i = 1; i <= count; i++) {
0234 GetAppFiles(i, &afile);
0235 procid = 0;
0236 catinfo.hFileInfo.ioNamePtr = (StringPtr) &afile.fName;
0237 catinfo.hFileInfo.ioVRefNum = afile.vRefNum;
0238 catinfo.hFileInfo.ioFDirIndex = 0;
0239 catinfo.hFileInfo.ioDirID = 0;
0240 GetWDInfo(afile.vRefNum, &catinfo.hFileInfo.ioVRefNum,
0241 &catinfo.hFileInfo.ioDirID, &procid);
0242 if (PBGetCatInfoSync(&catinfo) == noErr) {
0243 fspec.vRefNum = catinfo.hFileInfo.ioVRefNum;
0244 fspec.parID = catinfo.hFileInfo.ioFlParID;
0245 memcpy(fspec.name, afile.fName, *afile.fName + 1);
0246 if ((*openp)(message, &fspec, &catinfo.hFileInfo.ioFlFndrInfo) < 0) {
0247 break;
0248 }
0249 }
0250 }
0251 ClrAppFiles(count);
0252 if (message == appPrint
0253 && NAcloseWindows(NAhead, NA_REQCLOSEALL) == NA_ALLCLOSED) {
0254 return (1);
0255 }
0256 }
0257 }
0258 if (newitem && !count && menup != (na_menup) NULL) {
0259 (*menup)(NULL, mFile, newitem);
0260 }
0261 }
0262
0263 return (0);
0264 }