home *** CD-ROM | disk | FTP | other *** search
- /*
- * main.c -- application skeleton main program
- */
-
- #include <quickdraw.h>
- #include <control.h>
- #include <desk.h>
- #include <dialog.h>
- #include <event.h>
- #include <font.h>
- #include <memory.h>
- #include <menu.h>
- #include <resource.h>
- #include <scrap.h>
- #include <textedit.h>
- #include <window.h>
-
- #include "qdv.h"
- #include "def.h"
- #include "glob.h"
- #define thePort (QD->QDthePort)
- #define GRAFRH 576
- #define GRAFRV 720
- #define SCREENRECT QD->screenBits.bounds
- #define CurStackBase (*(long *)0x908)
-
- Handle graficon = 0;
- QDVar qdvar = 0;
-
- main()
- {
- short dig;
- int done = FALSE;
- EventRecord ev;
- int i;
- CursHandle ibeam;
- int *mainadd;
- Handle mamsg; /* for "main address" message */
- Point mouse; /* to check for TE (ibeam cursor) */
- char zdum[3]; /* insure last variable has full
- * 32 bits.
- */
-
- /* setgrowzone(&mygrowzone); for memory size problems */
- *((long *)0) = -1L; /* force NULL de-reference to give an
- * ID=02 error when it happens, not later.
- */
- SetApplLimit(CurStackBase - 8192 /* stack size */ );
- /* MaxApplZone(); */
-
- /* force memory manager to allocate enough master pointers
- * now, so the heap isn't fragmented later.
- */
-
- MoreMasters();
- /* MoreMasters();
- MoreMasters(); */
-
- QD = (QDVar *)&qdvar;
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0 /* no restart procedure */ );
- InitCursor();
- SetEventMask(everyEvent - keyUpMask);
- GetWMgrPort(&screenport);
- SetPort(screenport);
-
- /* use machine dependent screen size to set up drag and grow
- * rectangles, leaving 4 (drag) and 7 (grow) pixels on the sides.
- */
-
- SetRect(&wdragr, 4, 24, (short)(SCREENRECT.right-4),
- (short)(SCREENRECT.bottom-4));
- SetRect(&wgrowr, 7, 27, (short)(SCREENRECT.right-7),
- (short)(SCREENRECT.bottom-7));
- sfdtl.v = SCREENRECT.bottom / 2 - 92;
- sfdtl.h = SCREENRECT.right / 2 - 174;
-
- for (i = 1; i <= NMENUS + 1; i++) /* get the menus for app */
- mh[i] = GetMenu(i);
- AddResMenu(mh[1], 'DRVR'); /* get Apple menu desk accessories */
- for (i = 1; i <= NMENUS; i++) /* terminate menus */
- InsertMenu (mh[i], 0);
- DrawMenuBar();
-
- graficon = GetResource('ICN#', 129);
- gibits.baseAddr = (QDPtr)NewPtr(128L);
- HLock(graficon);
- BlockMove(*graficon, gibits.baseAddr, 128L);
- HUnlock(graficon);
- ReleaseResource(graficon);
- gibits.rowBytes = 4;
- SetRect(&gibits.bounds, 0, 0, 32, 32);
- wp[0] = GetNewWindow(260, &wr[0], -1L /* frontmost */ );
- SetPort(wp[0]);
- SetRect(&grafr, 0, 0, GRAFRH, GRAFRV);
- BlockMove(&wp[0]->portRect, &r, (long)sizeof(Rect));
- r.bottom -= 15;
- r.right -= 15;
- vscroll[0] = GetNewControl(128, wp[0]);
- hscroll[0] = GetNewControl(128, wp[0]);
- checkscroll(0);
- drawscroll(0);
- redraw(0);
- filemenu(1);
-
- /* initialization done, handle events */
-
- FlushEvents(everyEvent, 0); /* ignore what is queued up */
- mainadd = &main;
-
- /* use a resource for all strings so the messages can be
- * translated to other languages
- */
-
- mamsg = GetString(2);
- i = (int)**mamsg;
- while (mainadd) {
- dig = ((long)mainadd) & 0xF;
- if (dig > 9)
- dig += 'A' - '9' - 1;
- *(*mamsg + i--) = (char)(dig + '0');
- /* mainadd >>= 4; what should work */
- mainadd >>= 2; /* what does work */
- };
- HLock(mamsg);
- TESetText(*mamsg + 1L, (long)**mamsg, hTE);
- HUnlock(mamsg);
- DisposHandle(mamsg);
- TEUpdate(&tedestr, hTE);
- ibeam = GetCursor(iBeamCursor);
- TEFromScrap();
- scrap = InfoScrap()->scrapCount;
- do {
- SystemTask(); /* handle desk accessories */
- if (scrap != InfoScrap()->scrapCount) {
- TEFromScrap();
- scrap = InfoScrap()->scrapCount;
- };
- if (hTE) {
- TEIdle(hTE);
- if (FrontWindow() == wp[1]) {
- if (wantTEadj && TickCount() - lastTEadj > 60)
- teadjdest();
- GetMouse(&mouse);
- if (PtInRect(pass(mouse), &(*hTE)->viewRect))
- SetCursor (*ibeam);
- else
- SetCursor(&QD->arrow);
- };
- };
- if (GetNextEvent(everyEvent, &ev))
- switch (ev.what) {
- extern void select(), update();
-
- case mouseDown:
- done = click(&ev);
- break;
- case keyDown:
- case autoKey:
- done = key(&ev);
- break;
- case updateEvt
- :
- update(&ev);
- break;
- case activateEvt:
- select(&ev);
- break;
- };
- } while (!done);
- if (paint)
- FSClose(paint);
- /* run-time does ExitToShell() */
- } /* end of main */
-