// twhile.c // // by John D. de Boer #include "twist.h" #include "ttt.h" extern MenuRef FileMenu; window *WaitWind; // the waiting dialog static string PostText; // the name of the last .ttt file begun static cursor Sundial; // the wait cursor static rect TextRect; // the location of the progress text static Rect ProgRect; // the progress bar rectangle static int PIX; // width of progress bar in pixels static real ProgFrac; // the fractional amount in the progress bar static ControlRef ProgBar; // progress bar control static const int WIDTH = 300, // width of dialog HEIGHT = 70, // height of dialog MARGIN = 10; // white margin around contents // The wait cursor void WaitCursor(void) { setcursor(Sundial); } // Posting a wait text static void ensureatfront(window *W) { if (!W || !W->wmw) return; if (W->wmw!=FrontNonFloatingWindow()) revealwindow(W); } void PostFraction(real F) { ProgFrac=fbetween(F,0.0,1.0); ensureatfront(WaitWind); redraw(WaitWind); } void PostCurrentFile(const char *S, real F) { old(PostText); PostText=cat(0,"Reading: ",(char *)S); PostFraction(F); } void PostMessage(const char *S, real F) { old(PostText); PostText=copyof(S); PostFraction(F); } void EndWait(void) { concealwindow(WaitWind); } // Drawing static void DrawWait(window *W) { rect R; if (!W) return; //CGContextClearRect(W->q2d,TextRect); setrect(&R,MARGIN - 2,HEIGHT - 25,WIDTH - (2 * MARGIN) + 4,17); fillindex(W,white); fillrect(W,R); penindex(W,lightgrey); framerect(W,R); savegraphics(W); cliprect(W,R); fillindex(W,black); drawtext(W,MARGIN,HEIGHT - 20,NULL); if (PostText) text(W,PostText); else text(W,"Done"); restoregraphics(W); SetControlValue(ProgBar,ProgFrac * PIX); Draw1Control(ProgBar); } // Menus static void SetUpWhileMenus(void) { InsertMenu(FileMenu,0); } static void AdjustWhileMenus(window *W) { if (!W) return; DisableMenuItem(FileMenu,0); allowitem(NULL,'abou',0); } // Initialisation void InitWait(void) { OSStatus err; PostText=NULL; Sundial=getcursor("200"); WaitWind=standarddialog("Reading resource files",WIDTH,HEIGHT); WaitWind->erase=0; installpaint(WaitWind,&DrawWait); installmenus(WaitWind,NULL,&SetUpWhileMenus,&AdjustWhileMenus,NULL); SetThemeWindowBackground(WaitWind->wmw,kThemeBrushDialogBackgroundActive,0); setrect(&TextRect,5,top(WaitWind->page) - 30,width(WaitWind->page) - 10,25); SetRect(&ProgRect,MARGIN,35,WIDTH - MARGIN,HEIGHT - MARGIN); PIX= WIDTH - (2 * MARGIN); err=CreateProgressBarControl(WaitWind->wmw,&ProgRect,0,0,PIX,0,&ProgBar); }