home *** CD-ROM | disk | FTP | other *** search
- {$A+,$S5,D-} {compile for desk accessory}
-
- PROGRAM Disk_Space_Accessory;
-
- CONST {$I gemconst.pas}
- AC_Open = 40; {Two new message that only accessories will get}
- AC_Close = 41;
- Height = 115; {height and width of the window}
- Width = 216;
-
-
- TYPE {$I gemtype.pas}
- shortstring = String[2];
- FreeRec = Packed RECORD
- FreeCl : Long_Integer; { # of free clusters }
- NumCl : Long_Integer; { total # of clusters on disk }
- SecSiz : Long_Integer; { Sector size in bytes }
- CluSiz : Long_Integer; { number of sectors per cluster }
- END;
-
- FreePtr = ^FreeRec; { pointer to free record }
-
- VAR window, { The handle of our window }
- AP_ID, { Our application identification handle. }
- curx,cury, { current x and y coordinates of window }
- menu_id : Integer ; { Index of our menu item in "Desk" menu }
- our_name, { The name of our accessory. }
- wind_name : Str255; { The title of our window. }
- space : Long_Integer;
- spc : String ;
-
-
- {$I gemsubs.pas}
-
- {Here's our declaration of Menu_Register}
-
- FUNCTION Menu_Register( id : Integer ; VAR name : Str255 ) : Integer;
- EXTERNAL;
-
- Procedure Dfree( VAR rec : FreeRec; drive : Integer ) ;
- GEMDOS( $36 );
-
- Function Free( drive : Integer ) : Long_integer;
- { drive 1-16 for A - P, 0 for current}
- VAR
- FreeInf : FreeRec ; { what dfree returns }
-
- BEGIN
- Dfree( FreeInf, drive ); { get info into freeinf }
- WITH FreeInf DO
- BEGIN
- Free := FreeCL * ( SecSiz * CluSiz );
- END;
- END;
-
- PROCEDURE Convert ( A : Long_Integer ) ;
-
- VAR I : Long_Integer ;
-
- BEGIN
- spc := ' ' ; {mono/hard-drive version}
- I := A DIV 1000000 ; {shows 7 digits, vice 6 }
- spc[ 1 ] := Chr( I + 48 ) ;
- A := A - ( I * 1000000 ) ;
-
- I := A DIV 100000 ;
- spc[ 2 ] := Chr( I + 48 ) ;
- A := A - ( I * 100000 ) ;
-
- I := A DIV 10000 ;
- spc[ 3 ] := Chr( I + 48 ) ;
- A := A - ( I * 10000 ) ;
-
- I := A DIV 1000 ;
- spc[ 4 ] := Chr( I + 48 ) ;
- A := A - ( I * 1000 ) ;
-
- I := A DIV 100 ;
- spc[ 5 ] := Chr( I + 48 ) ;
- A := A - ( I * 100 ) ;
-
- I := A DIV 10 ;
- spc[ 6 ] := Chr( I + 48 ) ;
- A := A - ( I * 10 ) ;
-
- I := A ;
- spc[ 7 ] := Chr( I + 48 ) ;
- END ;
-
- PROCEDURE Get_DF ;
-
- VAR dspc : Str255 ;
-
- BEGIN
- space := Free( 1 ); { Get free space on drive A }
- Convert ( space ) ;
- dspc := Concat ( 'Drive A: Free = ', spc ) ;
- Draw_String( 12, 15, dspc ) ;
- space := Free( 2 ); { Get free space on drive B }
- Convert ( space ) ;
- dspc := Concat ( 'Drive B: Free = ', spc ) ;
- Draw_String( 12, 30, dspc ) ;
- space := Free( 3 ); { Get free space on drive C }
- Convert ( space ) ;
- dspc := Concat ( 'Drive C: Free = ', spc ) ;
- Draw_String( 12, 45, dspc ) ;
- space := Free( 4 ); { Get free space on drive D }
- Convert ( space ) ;
- dspc := Concat ( 'Drive D: Free = ', spc ) ;
- Draw_String( 12, 60, dspc ) ;
- space := Free( 5 ); { Get free space on drive E }
- Convert ( space ) ;
- dspc := Concat ( 'Drive E: Free = ', spc ) ;
- Draw_String( 12, 75, dspc ) ;
- END ;
-
- { Open our window, if not already open, otherwise make it the front window. }
-
- PROCEDURE Do_Open ;
- BEGIN
- { Does our window already exist? }
- IF window <> No_window THEN
- Bring_To_Front ( window ) { Yes, just make it front window. }
- ELSE
- BEGIN
- wind_name := ' Free Disk Space ' ;
- window := New_Window ( G_Name|G_Close|G_Move,wind_name,
- 0,0,Width,Height );
- Open_Window( window,curx,cury,Width,Height )
- END {ELSE}
- END ; {Do_Open}
-
- { Close our window and delete it from the system }
-
- PROCEDURE Do_Close ;
- BEGIN
- Close_Window( window );
- Delete_Window( window );
- window := No_Window
- END; {Do_Close}
-
- { Redraw an area of our window. The redraw area is passed in the parameters
- x0,y0,w0,and h0. }
-
- PROCEDURE Do_Redraw( handle,x0,y0,w0,h0 : integer; bckgrnd : Boolean );
-
- {These will hold the size of the current redraw rectangle in redraw list. }
- VAR x,y,w,h : Integer ;
-
- BEGIN
- Set_window(window);
- Begin_Update;
- Hide_Mouse ;
- Draw_Mode( 1 );
- Paint_Style( Solid );
- Paint_Color( White ) ;
- First_Rect( handle, x, y, w, h ) ;
- WHILE (w <> 0) AND (h <> 0) DO
- BEGIN
-
- IF Rect_Intersect( x0,y0,w0,h0,x,y,w,h ) THEN
- BEGIN
- Set_Clip( x,y,w,h ) ;
- IF bckgrnd = True THEN Paint_Rect( 0,0,Width,Height ) ;
- Frame_Rect( 0,0,Width,Height ) ;
- Get_DF;
- END ;
-
- Next_Rect( handle,x,y,w,h ) ;
- END ;
-
- Show_Mouse ;
- End_Update
- END ;
-
- { This next routine performs all events we receive from GEM. Since we are an
- accessory, we will never stop running, so the loop below is infinite}
-
- PROCEDURE Event_Loop ;
-
- VAR event, d : Integer ;
- msg : Message_Buffer ;
-
- BEGIN
- WHILE True DO
- BEGIN
- event := Get_Event( E_Message,0,0,0,0,false,0,0,0,0,
- false,0,0,0,0,msg,d,d,d,d,d,d ) ;
-
- IF event & E_Message <> 0 THEN {its a message!}
- CASE msg[0] OF
- AC_Open: Do_Open ; { open the window }
- AC_Close:
- IF (msg[3]=menu_id) AND (window <> No_Window) THEN
- window := No_Window ;
- WM_Sized,
- WM_Moved:
- BEGIN
- Set_WSize( msg[3], msg[4], msg[5], msg[6], msg[7] );
- curx := msg[4]; {keep track of x,y coordinates of}
- cury := msg[5]; {window.}
- Do_Redraw( window, curx, cury, Width, Height, True);
- END;
- WM_Closed: Do_Close ;
- WM_Redraw: Do_Redraw( msg[3], msg[4], msg[5], msg[6], msg[7],True );
- WM_Topped: Bring_To_Front( msg[3] )
- END
- ELSE
- IF window <> No_window THEN
- Do_Redraw( window, curx, cury, Width, Height, False ) ;
- END
- END ;
-
- { Main routine -- initialize GEM, insert our name into the "Desk" menu and
- go to Event_Loop. Because that routine will NEVER return we don't need an
- Exit_Gem call at the end of the program.}
-
- BEGIN
- AP_ID := Init_Gem ; { We do need to save our application ID }
- IF AP_ID >= 0 THEN { thats a change from most programs }
- BEGIN
- window := No_Window ; {Starting off with no window on the screen. }
- { Always put two spaces before the name of the accessory: }
- our_name := ' Free Disk Space ' ;
- {Here is where we use the application ID number: }
- menu_id := Menu_Register( AP_ID, our_name ) ;
- curx := 20;
- cury := 20;
- Event_Loop ;
- END
- END.
-