home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CProxyDragTask.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.5 KB  |  206 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. //    CProxyDragTask.cp
  20.  
  21.  
  22. #include "CProxyDragTask.h"
  23.  
  24. #include <LDragAndDrop.h>
  25. #include <UException.h>
  26. #include <UTextTraits.h>
  27. #include <UGAColorRamp.h>
  28. #include <LView.h>
  29.  
  30. #include "CProxyPane.h"
  31. #include "StCaptureView.h"
  32. #include "CGWorld.h"
  33. #include "StRegionHandle.h"
  34. #include "CEnvironment.h"
  35.  
  36. // ---------------------------------------------------------------------------
  37. //        Ñ CProxyDragTask
  38. // ---------------------------------------------------------------------------
  39.  
  40. CProxyDragTask::CProxyDragTask(
  41.     LView&                    inProxyView,
  42.     CProxyPane&                inProxyPane,
  43.     LCaption&                inPageProxyCaption,
  44.     const EventRecord&        inEventRecord,
  45.     CExtraFlavorAdder*        inExtraFlavorAdder)
  46.     
  47.     :    mProxyView(inProxyView),
  48.         mProxyPane(inProxyPane),
  49.         mPageProxyCaption(inPageProxyCaption),
  50.         mExtraFlavorAdder(inExtraFlavorAdder),
  51.  
  52.         Inherited(inEventRecord)
  53. {
  54. }
  55.  
  56. // ---------------------------------------------------------------------------
  57. //        Ñ ~CProxyDragTask
  58. // ---------------------------------------------------------------------------
  59.  
  60. CProxyDragTask::~CProxyDragTask()
  61. {
  62.     delete mExtraFlavorAdder;
  63. }
  64.  
  65. // ---------------------------------------------------------------------------
  66. //        Ñ DoDrag
  67. // ---------------------------------------------------------------------------
  68.  
  69. OSErr
  70. CProxyDragTask::DoDrag()
  71. {
  72.     MakeDragRegion(mDragRef, mDragRegion);
  73.     AddFlavors(mDragRef);
  74.     
  75.     if (UEnvironment::HasFeature(env_HasDragMgrImageSupport))
  76.     {
  77.         try
  78.         {
  79.             DoTranslucentDrag();
  80.         }
  81.         catch (...)
  82.         {
  83.             DoNormalDrag();
  84.         }
  85.     }
  86.     else
  87.     {
  88.         DoNormalDrag();
  89.     }
  90.     
  91.     return noErr;
  92. }
  93.  
  94. // ---------------------------------------------------------------------------
  95. //        Ñ DoNormalDrag
  96. // ---------------------------------------------------------------------------
  97.  
  98. void
  99. CProxyDragTask::DoNormalDrag()
  100. {
  101.     ::TrackDrag(mDragRef, &mEventRecord, mDragRegion);
  102. }
  103.  
  104. // ---------------------------------------------------------------------------
  105. //        Ñ DoTranslucentDrag
  106. // ---------------------------------------------------------------------------
  107.  
  108. void
  109. CProxyDragTask::DoTranslucentDrag()
  110. {
  111.     Rect                theFrame;
  112.     StColorPortState    theColorPortState(mProxyView.GetMacPort());
  113.  
  114.     // Normalize the color state (to make CopyBits happy)
  115.     
  116.     StColorState::Normalize();
  117.     
  118.     // Build a GWorld containing the page proxy icon and title
  119.  
  120.     mProxyView.FocusDraw();
  121.         
  122.     mProxyView.CalcLocalFrameRect(theFrame);
  123.  
  124.     CGWorld theGWorld(theFrame, 0, useTempMem);
  125.     StCaptureView theCaptureView(mProxyView);
  126.     
  127.     mPageProxyCaption.Show();
  128.  
  129.     try
  130.     {
  131.         theCaptureView.Capture(theGWorld);
  132.  
  133.         mProxyView.FocusDraw();
  134.  
  135.            Point theOffsetPoint = topLeft(theFrame);
  136.         ::LocalToGlobal(&theOffsetPoint);
  137.  
  138.         // Set the drag image
  139.  
  140.         StRegionHandle theTrackMask;
  141.  
  142.         mProxyPane.CalcLocalFrameRect(theFrame);
  143.         ThrowIfOSErr_(::IconSuiteToRgn(theTrackMask, &theFrame, kAlignAbsoluteCenter, mProxyPane.GetIconSuiteH()));
  144.         
  145.         mPageProxyCaption.CalcLocalFrameRect(theFrame); // Use frame which bounds the actual text, not the frame bounds
  146.         theTrackMask += theFrame;
  147.         
  148.         PixMapHandle theMap = ::GetGWorldPixMap(theGWorld.GetMacGWorld());
  149.         OSErr theErr = ::SetDragImage(mDragRef, theMap, theTrackMask, theOffsetPoint, kDragDarkerTranslucency);
  150.         ThrowIfOSErr_(theErr);
  151.         
  152.         // Track the drag
  153.         
  154.         ::TrackDrag(mDragRef, &mEventRecord, mDragRegion);
  155.     }
  156.     catch (...)
  157.     {
  158.     }
  159.     
  160.     mPageProxyCaption.Hide();
  161. }
  162.  
  163. // ---------------------------------------------------------------------------
  164. //        Ñ AddFlavorURL
  165. // ---------------------------------------------------------------------------
  166.     
  167. void
  168. CProxyDragTask::AddFlavors(DragReference inDragRef)
  169. {
  170.     Inherited::AddFlavors(inDragRef);
  171.     if (mExtraFlavorAdder)
  172.         mExtraFlavorAdder->AddExtraFlavorData(inDragRef, static_cast<ItemReference>(this));
  173. }
  174.  
  175. // ---------------------------------------------------------------------------
  176. //        Ñ MakeDragRegion
  177. // ---------------------------------------------------------------------------
  178.     
  179. void
  180. CProxyDragTask::MakeDragRegion(
  181.     DragReference            /*inDragRef*/,
  182.     RgnHandle                /*inDragRegion*/)
  183. {
  184.     Rect        theFrame;
  185.     
  186.     // Add the page proxy icon region
  187.     
  188.     StRegionHandle theTrackMask;
  189.  
  190.     mProxyPane.CalcLocalFrameRect(theFrame);
  191.     ThrowIfOSErr_(::IconSuiteToRgn(theTrackMask, &theFrame, kAlignAbsoluteCenter, mProxyPane.GetIconSuiteH()));
  192.     theFrame = (**(RgnHandle)theTrackMask).rgnBBox;
  193.     ::LocalToGlobal(&topLeft(theFrame));
  194.     ::LocalToGlobal(&botRight(theFrame));
  195.     
  196.     AddRectDragItem(static_cast<ItemReference>(&mProxyPane), theFrame);
  197.     
  198.     // Add the page proxy caption region
  199.         
  200.     mPageProxyCaption.CalcLocalFrameRect(theFrame);
  201.     ::LocalToGlobal(&topLeft(theFrame));
  202.     ::LocalToGlobal(&botRight(theFrame));
  203.     
  204.     AddRectDragItem(static_cast<ItemReference>(&mPageProxyCaption), theFrame);
  205. }
  206.