/*
**      Newton Developer Technical Support Sample Code
**
**      Status Report, a protoStatusTemplate and DoProgress example
**
**      by J. Christopher Bell and Bob Ebert, Newton Developer Technical Support
**
**      Copyright  1995 by Apple Computer, Inc.  All rights reserved.
**
**      You may incorporate this sample code into your applications without
**      restriction.  This sample code has been provided "AS IS" and the
**      responsibility for its operation is 100% yours.  You are not
**      permitted to modify and redistribute the source as "DTS Sample Code."
**      If you are going to re-distribute the source, we require that you
**      make it clear in the source that the code was descended from
**      Apple-provided sample code, but that you've made changes.
*/


constant kActionInProgressString := "An action is already in progress";

rf := OpenResFileX(home & "resources");
DefConst('kDummyActionIcon, GetPictAsBits("ActionIcon", nil));
CloseResFileX(rf);

myStatusTemplate := {
	_proto: protoStatusTemplate,
	

	vMyInitialGaugeSetup:
	// This initial set up is just a convention done by the sample, not required by proto.
	// This is a setup frame as passed to protoStatusTemplate:ViewSet(...)
		{
		name: 'vGauge, 
		appSymbol: kAppSymbol, // optional, but we use for cancelRequest...
		values: 
			{ 
			icon: kDummyActionIcon,
			statusText: "Saving world",
			closeBox: func() 
				begin
					// since we show our "in progress view" only when the status view is hidden...
					// (note that in our application, the application is always open right now...)
					getroot().(kAppSymbol).InProgressView:Show();
					base:Hide();
				end,
			gauge: 0,
			},
				
		},
		
	// We could define cancelRequest here. If we don't, the protoStatusButton
	// will send the message to the view specified by the appSymbol slot in the
	// values frame used by protoStatusTemplate:ViewSet(...)
	// CancelRequest: func(reason) ...    
	
	// This slot will provide a self-animating barber pole as an example of 
	// custom status template. The name 'vMyBarber should be used with statusView:ViewSet(...).
	vMyBarber: 
		{
		height:	105,
		name:	'vMyBarber,
		kids: 	
			[
				protoStatusText,
				{	_proto: protoStatusBarber,
					viewIdleScript: func() 
						begin
							if Visible(self) then	// if hidden, don't bother with updating barber
								base:UpdateIndicator({name: 'vMyBarber, values: {barber: nil}}); // animate barber pole
							300; // return number of ticks until returning to viewIdleScript
						end,
					viewSetupDoneScript: func() 
						begin
							inherited:?viewSetupDoneScript();
							:SetupIdle(1);	// kick off idle script
						end,
				},
				{	_proto: protoStatusButton,
					text: "Stop",
					// buttonClickScript: func() ... // default is template:CancelRequest()...
				},
			],
			
		// This initial set up is just a convention done by the sample, not required by proto.
		// This is a setup frame as passed to protoStatusTemplate:ViewSet(...)
		myInitialSetup: 
				{	
				name: 'vMyBarber, 
				appSymbol: kAppSymbol, 
				values: 
					{ 
					icon: kDummyActionIcon,
					statusText: "Computing IsHalting",
					closeBox: func() 
						begin
							// since we show our "in progress view" only when the status view is hidden...
							// (note that in our application, the application is always open right now...)
							getroot().(kAppSymbol).InProgressView:Show();
							base:Hide();
						end,
					},
				
				},
		},
};

if kDebugOn then
	myStatusTemplate.debug := "mystatus";		// for debugging...

DefConst('kMyStatusTemplate, myStatusTemplate);