File indexing completed on 2018-03-02 18:44:56 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 #include "macnapp.h"
0053 #ifndef THINK_C
0054 #include <Fonts.h>
0055 #include <Scrap.h>
0056 #include <ToolUtils.h>
0057 #endif
0058
0059 #define DOCWIDTH 2047
0060 #define teinfo ((nate_win *)winp)
0061
0062
0063 static pascal void vscroll(ControlHandle, short);
0064 static pascal void hscroll(ControlHandle, short);
0065
0066
0067
0068 void NATEinit(na_win *winp, long flags, short docwidth, Ptr data, long len)
0069 {
0070 Rect rtemp, vtemp;
0071
0072 winp->flags = (winp->flags & ~NATE_FLAGS) | flags;
0073 if (!docwidth) docwidth = DOCWIDTH;
0074 teinfo->docwidth = docwidth;
0075 rtemp = winp->pwin->portRect;
0076 rtemp.top += teinfo->topoff;
0077 vtemp = rtemp;
0078 if (!(flags & NATE_NOHSCROLL)) {
0079 vtemp.right = vtemp.left + docwidth;
0080 }
0081 if (!(flags & NATE_READONLY)) {
0082 winp->keyp = NATEkeyp;
0083 }
0084 if (!(flags & NATE_NOMOUSE)) {
0085 winp->mousep = NATEmousep;
0086 winp->idlep = NATEidlep;
0087 }
0088 winp->menup = NATEmenup;
0089 winp->activep = NATEactivep;
0090 winp->updatep = NATEupdatep;
0091 winp->ctrlp = NATEctrlp;
0092 winp->closep = NATEclosep;
0093 winp->cursorRgn = NewRgn();
0094 teinfo->vctrl = teinfo->hctrl = NULL;
0095
0096 TEAutoView(true, teinfo->hTE = TENew(&vtemp, &rtemp));
0097 if (len > 0 && data != (Ptr) NULL) {
0098 TESetText(data, len, teinfo->hTE);
0099 TESetSelect(0, 0, teinfo->hTE);
0100 }
0101 teinfo->lheight = (*teinfo->hTE)->lineHeight;
0102 }
0103
0104
0105
0106 short NATEinitp(na_win *winp, long *datap)
0107 #ifndef THINK_C
0108 #pragma unused (datap)
0109 #endif
0110 {
0111 teinfo->topoff = 0;
0112 NATEinit(winp, winp->flags, 0, NULL, 0);
0113
0114 return (NA_PROCESSED);
0115 }
0116
0117
0118
0119 void NATEsetscroll(na_win *winp, Boolean moved, Rect *hrect, Rect *vrect)
0120 {
0121 short vmax, vvalue, hmax, hvalue;
0122 TEPtr te = *teinfo->hTE;
0123 ControlHandle vctrl, hctrl;
0124
0125
0126 vmax = te->nLines + (*(*te->hText + te->teLength - 1) == '\015' ? 1 : 0)
0127 - (te->viewRect.bottom - te->viewRect.top) / teinfo->lheight;
0128 hmax = (short) teinfo->docwidth - (te->viewRect.right - te->viewRect.left);
0129 if (vmax < 0) vmax = 0;
0130 if (hmax < 0) hmax = 0;
0131 vvalue = (te->viewRect.top - te->destRect.top) / teinfo->lheight;
0132 hvalue = te->viewRect.left - te->destRect.left;
0133 if (!(winp->flags & NATE_NOVSCROLL)) {
0134 if (teinfo->vctrl == (ControlHandle) NULL) {
0135 teinfo->vctrl = NewControl(winp->pwin, vrect, "\p", true, vvalue, 0, vmax,
0136 scrollBarProc, 0);
0137 if (winp->pwin != FrontWindow()) HiliteControl(teinfo->vctrl, 255);
0138 } else {
0139 if (vvalue < 0) vvalue = 0;
0140 if (vvalue > vmax) vvalue = vmax;
0141 SetCtlMax(vctrl = teinfo->vctrl, vmax);
0142 SetCtlValue(vctrl, vvalue);
0143 if (moved) {
0144 MoveControl(vctrl, vrect->left, vrect->top);
0145 SizeControl(vctrl, vrect->right - vrect->left,
0146 vrect->bottom - vrect->top);
0147 ShowControl(vctrl);
0148 }
0149 }
0150 }
0151 if (!(winp->flags & NATE_NOHSCROLL)) {
0152 if (teinfo->hctrl == (ControlHandle) NULL) {
0153 teinfo->hctrl = NewControl(winp->pwin, hrect, "\p", true, hvalue, 0, hmax,
0154 scrollBarProc, 0);
0155 if (winp->pwin != FrontWindow()) HiliteControl(teinfo->hctrl, 255);
0156 } else {
0157 if (hvalue < 0) hvalue = 0;
0158 if (hvalue > hmax) hvalue = hmax;
0159 SetCtlMax(hctrl = teinfo->hctrl, hmax);
0160 SetCtlValue(hctrl, hvalue);
0161 if (moved) {
0162 MoveControl(hctrl, hrect->left, hrect->top);
0163 SizeControl(hctrl, hrect->right - hrect->left,
0164 hrect->bottom - hrect->top);
0165 ShowControl(hctrl);
0166 }
0167 }
0168 }
0169 }
0170
0171
0172
0173 static pascal void vscroll(ControlHandle ctrl, short part)
0174 {
0175 short amount, value, max, lh;
0176 na_win *winp;
0177 TEHandle hTE;
0178
0179 if (part == 0) return;
0180 winp = * (na_win**) GetWRefCon((*ctrl)->contrlOwner);
0181 hTE = teinfo->hTE;
0182 value = ((*hTE)->viewRect.bottom - (*hTE)->viewRect.top) /
0183 (lh = teinfo->lheight);
0184 switch (part) {
0185 case inUpButton:
0186 amount = -1;
0187 break;
0188 case inDownButton:
0189 amount = 1;
0190 break;
0191 case inPageUp:
0192 amount = - value;
0193 break;
0194 case inPageDown:
0195 amount = value;
0196 break;
0197 }
0198 if ((amount += (value = GetCtlValue(ctrl))) < 0) amount = 0;
0199 if (amount > (max = GetCtlMax(ctrl))) amount = max;
0200 SetCtlValue(ctrl, amount);
0201 TEScroll(0, (value - amount) * lh, hTE);
0202 }
0203
0204
0205
0206 static pascal void hscroll(ControlHandle ctrl, short part)
0207 {
0208 short amount, value, max;
0209
0210 if (part) {
0211 TEHandle hTE = (* (nate_win**) GetWRefCon((*ctrl)->contrlOwner))->hTE;
0212
0213 value = (*hTE)->viewRect.right - (*hTE)->viewRect.left;
0214 switch (part) {
0215 case inUpButton:
0216 amount = -6;
0217 break;
0218 case inDownButton:
0219 amount = 6;
0220 break;
0221 case inPageUp:
0222 amount = - value;
0223 break;
0224 case inPageDown:
0225 amount = value;
0226 break;
0227 }
0228 if ((amount += (value = GetCtlValue(ctrl))) < 0) amount = 0;
0229 if (amount > (max = GetCtlMax(ctrl))) amount = max;
0230 SetCtlValue(ctrl, amount);
0231 TEScroll(value - amount, 0, hTE);
0232 }
0233 }
0234
0235
0236
0237 short NATEactivep(na_win *winp, Boolean on)
0238 {
0239 if (on) {
0240 TEActivate(teinfo->hTE);
0241 } else {
0242 TEDeactivate(teinfo->hTE);
0243 }
0244
0245 return (NA_NOTPROCESSED);
0246 }
0247
0248
0249
0250 short NATEupdatep(na_win *winp, Boolean newsize)
0251 {
0252 TEHandle hTE = teinfo->hTE;
0253 WindowPtr window = winp->pwin;
0254 Rect prect, vrect, hrect, drect;
0255
0256 prect = window->portRect;
0257 prect.top += teinfo->topoff;
0258 EraseRect(&prect);
0259 hrect = vrect = prect;
0260 vrect.top--;
0261 hrect.left--;
0262 vrect.left = ++vrect.right - 16;
0263 hrect.top = ++hrect.bottom - 16;
0264 vrect.bottom -= 14;
0265 hrect.right -= 14;
0266 InsetRect(&prect, 4, 4);
0267 prect.right -= 15;
0268 if (!(winp->flags & NATE_NOHSCROLL)) prect.bottom -= 15;
0269 prect.bottom -= (prect.bottom - prect.top) % teinfo->lheight;
0270 if (newsize) {
0271 drect = (*hTE)->viewRect = prect;
0272 drect.right = drect.left + (short) teinfo->docwidth;
0273 (*hTE)->destRect = drect;
0274 RectRgn(winp->cursorRgn, &prect);
0275 OffsetRgn(winp->cursorRgn, -window->portBits.bounds.left,
0276 -window->portBits.bounds.top);
0277 TECalText(hTE);
0278 TESelView(hTE);
0279 if (teinfo->hctrl != (ControlHandle) NULL) HideControl(teinfo->hctrl);
0280 if (teinfo->vctrl != (ControlHandle) NULL) HideControl(teinfo->vctrl);
0281 }
0282 TEUpdate(&prect, hTE);
0283 if (newsize) NATEsetscroll(winp, true, &hrect, &vrect);
0284
0285 return (NA_NOTPROCESSED);
0286 }
0287
0288
0289
0290 short NATEctrlp(na_win *winp, Point p, short part, short mods, ControlHandle ctrl)
0291 #ifndef THINK_C
0292 #pragma unused (mods)
0293 #endif
0294 {
0295 short value;
0296
0297 if (part) {
0298 value = GetCtlValue(ctrl);
0299 switch (part) {
0300 case inThumb:
0301 part = TrackControl(ctrl, p, (ProcPtr) NULL);
0302 if (part && (value -= GetCtlValue(ctrl))) {
0303 TEHandle hTE = teinfo->hTE;
0304
0305 if (ctrl == teinfo->vctrl) {
0306 TEScroll(0, value * teinfo->lheight, hTE);
0307 } else if (ctrl == teinfo->hctrl) {
0308 TEScroll(value, 0, hTE);
0309 }
0310 }
0311 break;
0312
0313 default:
0314 (void) TrackControl(ctrl, p,
0315 (ProcPtr) (ctrl == teinfo->vctrl ? vscroll : hscroll));
0316 break;
0317 }
0318 }
0319
0320 return (NA_PROCESSED);
0321 }
0322
0323
0324
0325 short NATEidlep(na_win *winp)
0326 {
0327 TEIdle(teinfo->hTE);
0328
0329 return (NA_PROCESSED);
0330 }
0331
0332
0333
0334 short NATEkeyp(na_win *winp, long c, short mods)
0335 {
0336 short status = NA_NOTPROCESSED;
0337
0338 if (!(mods & cmdKey)) {
0339 status = NA_PROCESSED;
0340 ObscureCursor();
0341 TEKey(c, teinfo->hTE);
0342 NATEsetscroll(winp, false, (Rect*) NULL, (Rect*) NULL);
0343 }
0344
0345 return (status);
0346 }
0347
0348
0349
0350 short NATEmenup(na_win *winp, WORD menuid, WORD itemno)
0351 {
0352 MenuHandle mh = NAmenuh(mEdit);
0353 TEHandle hTE = teinfo->hTE;
0354 TEPtr pte;
0355 short status = NA_NOTPROCESSED;
0356
0357 switch (menuid) {
0358 case 0:
0359 pte = *hTE;
0360 if (pte->selStart != pte->selEnd) {
0361 EnableItem(mh, iCopy);
0362 if (!(winp->flags & NATE_READONLY)) {
0363 EnableItem(mh, iCut);
0364 EnableItem(mh, iClear);
0365 }
0366 } else {
0367 DisableItem(mh, iCopy);
0368 if (!(winp->flags & NATE_READONLY)) {
0369 DisableItem(mh, iCut);
0370 DisableItem(mh, iClear);
0371 }
0372 }
0373 EnableItem(mh, iSelAll);
0374 if (!(winp->flags & NATE_READONLY)) {
0375 EnableItem(mh, iPaste);
0376 }
0377 break;
0378
0379 case mEdit:
0380 switch (itemno) {
0381 case iCut:
0382 TECut(hTE);
0383 goto DOSCRAP;
0384
0385 case iCopy:
0386 TECopy(hTE);
0387 DOSCRAP:
0388 ZeroScrap();
0389 TEToScrap();
0390 goto EDITDONE;
0391
0392 case iPaste:
0393 TEFromScrap();
0394 TEPaste(hTE);
0395 goto EDITDONE;
0396
0397 case iClear:
0398 TEDelete(hTE);
0399 goto EDITDONE;
0400
0401 case iSelAll:
0402 TESetSelect(0, 32767, hTE);
0403 TESelView(hTE);
0404 EDITDONE:
0405 status = NA_PROCESSED;
0406 NATEsetscroll(winp, false, (Rect*) NULL, (Rect*) NULL);
0407 break;
0408 }
0409 default:
0410 DisableItem(mh, iSelAll);
0411 break;
0412 }
0413
0414 return (status);
0415 }
0416
0417
0418
0419 short NATEmousep(na_win *winp, Point p, short type, short mods)
0420 {
0421 TEHandle hTE = teinfo->hTE;
0422
0423 if (!PtInRect(p, &(*hTE)->viewRect)) return (NA_NOTPROCESSED);
0424 if (type == NA_DOWN1 || type == NA_DOWN2 || type == NA_DOWNN) {
0425 TEClick(p, mods & shiftKey ? true : false, hTE);
0426 NAmousetime = TickCount();
0427 NAlastmouse++;
0428 }
0429
0430 return (NA_PROCESSED);
0431 }
0432
0433
0434
0435 short NATEclosep(na_win *winp)
0436 {
0437 TEDispose(teinfo->hTE);
0438
0439 return (NA_CLOSED);
0440 }
0441
0442
0443
0444 void NATEappend(na_win *winp, char *data, long len)
0445 {
0446 TEHandle hTE = ((nate_win*) winp)->hTE;
0447
0448 TESetSelect(32767, 32767, hTE);
0449 TEInsert(data, len, hTE);
0450 TESelView(hTE);
0451 NATEsetscroll(winp, false, (Rect*) NULL, (Rect*) NULL);
0452 }