constant kAppName := "Drag";
constant kVersion := "1.1";

constant kContactMe := "Hardy Macia\nP.O. Box 8276\nEssex, VT 05451\nHardyMacia@eWorld.com";
// ---- End Project Data ----


// ---- File main ----

// Before Script for "drag"
// HardyMacia@eWorld.com

/* version 1.1
 * I can't take full credit for any part of this code. It was linked
 * to me on AppleLink when I used to have an account there. I have 
 * modified it so that it will accept taps only in the floater's matte
 * boarder when the user wishes to drag the view. I also do not remember
 * who originally linked me the viewClickScript code.
 *
 * some more information : all of the system floater (find, assist, 
 * connection... only have vVisible+vApplication+vFloating set)
 * Therefore, just adding a viewclickscript to the root doesn't 
 * work for the right away because they don't accept taps, so I 
 * must also set vClickable on in the viewFlags. This is what the
 * other button is for. Run Drag, tap Find, the tap make front
 * most clickable.
 *
 */

drag :=
   {viewBounds: {left: 0, top: 0, right: 180, bottom: 80},
    declareSelf: 'base,
    viewClickScript:
      func(unit)
      begin
         // NOTE, all cooridnates are in GLOBAL space
       
         local x := GetPoint(firstX, unit),
               y := GetPoint(firstY, unit),
               box := base:GlobalBox() ;
       
         // only allow a drag to occur if it is in the margin of the view
      	// sloppy tapping feature allows taps in the matte area of
      	// floating views to be captured, so check to see if it is outside the viewbounds
         if  (y - box.top) < 1
            OR   (box.bottom - y) < 1
            OR   (x - box.left) < 1
            OR   (box.right - x) < 1 then
         begin
      
            InkOff(unit);
            base:Drag(unit, nil);
            self:Dirty();// to get ink dropping up
      
            // Need to clean up the viewBounds values with this code
            // This code works only for views that are justified to the
            // top and left of their parent view
      		/*** this might not be needed in somecases, but not others ***/
      
      /*      local ParentBounds, myGlobalBox;
            myGlobalBox := :GlobalBox();
            ParentBounds := :Parent():GlobalBox();
            myGlobalBox.left := myGlobalBox.left - ParentBounds.left;
            myGlobalBox.right := myGlobalBox.right - ParentBounds.left;
            myGlobalBox.top := myGlobalBox.top - ParentBounds.top;
            myGlobalBox.bottom := myGlobalBox.bottom - ParentBounds.top;
            self.viewBounds := myGlobalBox;
      */
            // return true to say handled the click
            true;
      
         end else    // otherwise, pass clicks through to my children
            // return nil so kids can get click
            nil;
      
      end,
    viewJustify: 80,
    viewFlags: 576,
    _proto: protoFloatNGo
   };

? := /* child of drag */
   {text: "?",
    buttonClickScript:
      func()
      begin
      	GetRoot():Notify(kNotifyQAlert,"Shareware $5.00",kContactMe);
      end,
    viewBounds: {left: 10, top: 0, right: 22, bottom: 12},
    viewJustify: 8388678,
    _proto: protoTextButton
   };




// Before Script for "install"
constant kDragUnInstall := "UnInstall Drag";
constant kDragInstall := "Install Drag";

install := /* child of drag */
   {text: "",
    buttonClickScript:
      func()
      begin
      
      	// I just go ahead and blow away the normal viewClickScript
      	// this is probably not a good idea, but for a sample it will work
      
      	if NOT GetRoot().viewClickScript then begin // install it
      
      		GetRoot().viewClickScript := base.viewClickScript; // just point root to my script
      																			// I'm sure this will cause the grip of death, but it uses less memory
      		SetValue(self,'text,kDragUnInstall);
      
      	end else begin // uninstall it
      	
      		GetRoot().viewClickScript := nil;
      		SetValue(self,'text,kDragInstall);
      
      	end;
      
      end,
    viewBounds: {top: -8, left: 8, right: 88, bottom: 4},
    viewJustify: 8389734,
    viewSetupFormScript:
      func()
      begin
      	text := 
      				if GetRoot().viewClickScript then
      					kDragUnInstall;
      				else
      					kDragInstall;
      end	,
    _proto: protoTextButton
   };
// View install is declared to drag




// Before Script for "MakeFrontMostDragable"
// will set the front most view's viewFlag to vClickable so that with the
// drag installed it should drag.

// the some floating views (Card) this will not work for - I'm not sure why

MakeFrontMostDragable := /* child of drag */
   {text: "Make Front View Clickable",
    buttonClickScript:
      func()
      begin
      
      	local f:=getview('viewfrontmost); // get the front most view
      
      	SetValue(f,'viewflags,f.viewFlags+vClickable); // make it clickable
      
      end,
    viewBounds: {left: 0, top: 8, right: 58, bottom: 20},
    viewJustify: 8398470,
    _proto: protoTextButton
   };



_view000 := /* child of drag */
   {title: "",
    viewBounds: {left: 6, top: 6, right: 86, bottom: 22},
    viewSetupFormScript:
      func()
      begin
      	title := kAppName&&kVersion;
      	inherited:?viewSetupFormScript();
      end,
    _proto: protoTitle
   };







// ---- Beginning of section for non used Layout files ----

// End of output