main() { WindowPtr mousewindow; char *tempstring; int a; SetApplLimit( ((int)(&mousewindow))-12*1024 ); //12 k para o stack tempstring="PROP"; BlockMove(tempstring,&creator,4); tempstring="PSTA"; BlockMove(tempstring,&proptype,4); InitFonts(); TEInit(); InitMenus(); InitDialogs(0); makemenus(); DrawMenuBar(); wristwatch=GetCursor(4); InitCursor(); SetCursor(*wristwatch); FlushEvents(-1); abrecatalogo(); /* Só ficheiros; pode abortar tudo */ BlockMove(&QD->screenBits.bounds, &screenrect, sizeof(Rect)); OffsetRect(&mywindowrect, (screenrect.right-mywindowrect.right)/2,(screenrect.bottom-mywindowrect.bottom)/2); /* Para ficar centrado em qualquer Mac! */ mywindow=NewWindow(0,&mywindowrect, "Catálogo"/*já está!*/, True, noGrowDocProc,-1,False,0); catscrollbar=NewControl(mywindow, &catscrollrect, ""/*...*/,True,1,1, ((nartigos>ARTIGOSPORECRAN) ? (nartigos-ARTIGOSPORECRAN+1):1), scrollBarProc,0); /* valor do control = indice absoluto no ficheiro */ /* propscrollbar desenha-se em sítio mais próprio*/ hotte=(TEHandle)0; /*Preparemos a memória para a proposta:*/ distribuimemoria(); GetAppParms(&apname,&aprefnum,&apparam); /* Aqui, abrir ficheiro de proposta se for o caso : usar apparam-consultar "Application" se abrir uma proposta, disable as opções new, open*/ SelectWindow(mywindow); DisableItem(FileMenu,3); DisableItem(FileMenu,4); DisableItem(FileMenu,5); DisableItem(FileMenu,6); DisableItem(EditMenu,0); DisableItem(SearchMenu,0); DisableItem(ParaMenu,0); InitCursor(); while(!(finished)) { SystemTask(); if (hotte) TEIdle(hotte); if(GetNextEvent(everyEvent,&event)) {switch(event.what) {case autoKey: case keyDown: { char c; c = event.message; if ((event.modifiers & cmdKey)) domenu(MenuKey(c)); else { if(hotte)/*só se existe texto*/ { switch(c) { case TAB: {rodate();break} case CR: { oldvalue=GetCtlValue(propscrollbar); SetCtlValue(propscrollbar,scrollprop(1)); break; } default: { if( ((*hotte)->telengthselStart!=(*hotte)->selEnd)) TEKey(c,hotte); if(hotte==hdesigte) descriptionkey=True; alterada=True; break; } }/*switch*/ }/*hotte!=0*/ }/*not menu command*/ break; }/*keyDown*/ case mouseDown: { windowcode=FindWindow(&event.where, &mousewindow); if ((mousewindow)&&(FrontWindow() != mousewindow)) {SelectWindow(mousewindow); break; } if (mousewindow==mywindow) { switch(windowcode) { case inContent: { SetPort(mywindow); GlobalToLocal(&event.where); if (hotte) TEDeactivate(hotte); if ((hotte)&&(PtInRect(&event.where,&hotrect))) { TEActivate(hotte); TEClick(&event.where, (event.modifiers & shiftKey)? True:False, hotte); } else if ((hotte)&&(PtInRect(&event.where,&cposrect))) {hotte=hposte; hotchars=POSCHARS; hotrect=cposrect;} else if ((hotte)&&(PtInRect(&event.where,&crefrect))) {hotte=hrefte; hotchars=REFCHARS; hotrect=crefrect;} else if ((hotte)&&(PtInRect(&event.where,&cdesigrect))) {hotte=hdesigte; hotchars=DESPCHARS; hotrect=cdesigrect;} else if ((hotte)&&(PtInRect(&event.where,&cquantrect))) {hotte=hquantte; hotchars=QUANTCHARS;hotrect=cquantrect;} else if ((hotte)&&(PtInRect(&event.where,&cdescrect))) {hotte=hdescte; hotchars=DECHARS; hotrect=cdescrect;} else if ((hotte)&&(PtInRect(&event.where,&catrect))) {copiaartigo();} else /* May be in a control */ {int cc1,cc2; ControlHandle ch; cc1=FindControl( &event.where, mywindow, &ch); if (cc1!=0) { oldvalue=GetCtlValue(ch); if (ch==catscrollbar) { if (cc1==inThumb) { cc2=TrackControl(ch, &event.where, 0); if ((cc1==cc2)&&(oldvalue!=GetCtlValue(ch))) scrollcat(GetCtlValue(ch)-oldvalue); } else cc2=TrackControl(ch, &event.where, &catarrowpage); }/*catscrollbar*/ else { if (cc1==inThumb) { cc2=TrackControl(ch, &event.where, 0); if ((cc1==cc2)&&(oldvalue!=GetCtlValue(ch))) scrollprop(GetCtlValue(ch)-oldvalue); } else cc2=TrackControl(ch, &event.where, &proparrowpage); }/*propscrollbar*/ }/*Hit in a control*/ } /* may be in some control */ if (hotte) TEActivate(hotte); break; }/*inContent*/ case inDrag: { DragWindow(mousewindow, &event.where, &screenrect); break; } case inGrow:break; case inGoAway:break; }/*switch(windowcode)*/ }/*mousewindow==mywindow*/ else {switch(windowcode) { case inMenuBar: { domenu(MenuSelect(&event.where)); break; } case inSysWindow: { SystemClick(&event, mousewindow); break; } case inDrag: { DragWindow(mousewindow, &event.where, &screenrect); break; } case inGoAway:break; }/*switch*/ }/*mousewindow!=mywindow*/ break; }/*mouseDown*/ case updateEvt: { SetPort(mywindow); TextFont(newYork); TextSize(12); BeginUpdate(mywindow); EraseRect(&catarearect); drawcattitle(); drawcatgrid(); for (a=0; (a=a); a++) drawcatentry(a,topart+a); if (hotte) { /*desenha proposta*/ EraseRect(&proparearect); drawproptitle(); drawpropgrid(); drawprop(); } DrawControls(mywindow); /* pode desenhar ou não a propscrollbar...*/ EndUpdate(mywindow); break; } case activateEvt: { if ((event.modifiers & activeFlag)) { HiliteControl(catscrollbar,0); if (hotte) {TEActivate(hotte); HiliteControl(propscrollbar,0); } } else { HiliteControl(catscrollbar,255); if (hotte) {TEDeactivate(hotte); HiliteControl(propscrollbar,255); } } } }/*switch(event.what)*/ }/* application event*/ }/* main event loop */ fechacatalogo();/*proposta foi fechada noutro sítio*/ if(LoadScrap()) printerror(); }/*main()*/