home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CDragBar.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  7.2 KB  |  249 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. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  20. //    CDragBar.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #pragma once
  24.  
  25. #include "CDragBar.h"
  26. #include "CDragBarDragTask.h"
  27. #include "CSharedPatternWorld.h"
  28. #include "UGraphicGizmos.h"
  29. #include "CPatternedGrippyPane.h"
  30.  
  31.  
  32. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  33. //    Ñ    
  34. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  35.  
  36. CDragBar::CDragBar(LStream* inStream)
  37.     :    LView(inStream)
  38. {
  39.     mPatternWorld = CSharedPatternWorld::CreateSharedPatternWorld(10000);
  40.     ThrowIfNULL_(mPatternWorld);
  41.     mPatternWorld->AddUser(this);
  42.     
  43.     inStream->ReadPString(mTitle);
  44.     *inStream >> mIsDocked;
  45.  
  46.     ::SetEmptyRgn(mDockedMask);
  47.     
  48.     mIsTracking = false;
  49.     // The visible flag will be off or latent at this point.  If it's invisible in the
  50.     // resource, we want to mark it as fully hidden (ie, not docked either)
  51.     mIsAvailable = (mVisible != triState_Off);
  52.     SetRefreshAllWhenResized(false);
  53. }
  54.  
  55. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  56. //    Ñ    
  57. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  58.  
  59. CDragBar::~CDragBar()
  60. {
  61.     mPatternWorld->RemoveUser(this);
  62.     ::SetEmptyRgn(mDockedMask);
  63. }
  64.  
  65. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  66. //    Ñ    
  67. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  68.  
  69. void CDragBar::Dock(void)
  70. {
  71.     mIsDocked = true;
  72.     Hide();
  73. }
  74.  
  75. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  76. //    Ñ    
  77. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  78.  
  79. void CDragBar::Undock(void)
  80. {
  81.     mIsDocked = false;
  82.     Show();
  83. }
  84.  
  85. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  86. //    Ñ    
  87. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  88.  
  89. Boolean CDragBar::IsDocked(void) const
  90. {
  91.     return mIsDocked;
  92. }
  93.  
  94. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  95. //    Ñ    
  96. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  97.  
  98. void CDragBar::StartTracking(void)
  99. {
  100.     mIsTracking = true;
  101.     Draw(NULL);
  102. }
  103.  
  104. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  105. //    Ñ    
  106. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  107.  
  108. void CDragBar::StopTracking(void)
  109. {
  110.     mIsTracking = false;
  111.     Draw(NULL);
  112. }
  113.  
  114. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  115. //    Ñ    
  116. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  117.  
  118. StringPtr CDragBar::GetDescriptor(Str255 outDescriptor) const
  119. {
  120.     LString::CopyPStr(mTitle, outDescriptor);
  121.     return outDescriptor;
  122. }
  123.  
  124. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  125. //    Ñ    
  126. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  127.  
  128. void CDragBar::SetDescriptor(ConstStringPtr inDescriptor)
  129. {
  130.     mTitle = inDescriptor;
  131. }
  132.  
  133.  
  134. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  135. //    Ñ    
  136. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  137.  
  138. void CDragBar::Draw(RgnHandle inSuperDrawRgnH)
  139. {
  140.     // Don't draw if invisible or unable to put in focus
  141.     if (IsVisible() && FocusDraw())
  142.     {
  143.         // Area of this View to draw is the intersection of inSuperDrawRgnH
  144.         // with the Revealed area of this View
  145.         RectRgn(mUpdateRgnH, &mRevealedRect);
  146.         if (inSuperDrawRgnH != nil)
  147.             SectRgn(inSuperDrawRgnH, mUpdateRgnH, mUpdateRgnH);
  148.             
  149.         if (!EmptyRgn(mUpdateRgnH))            // Some portion needs to be drawn
  150.         {
  151.                                     
  152.             Rect frame;
  153.             CalcLocalFrameRect(frame);
  154.                         
  155.             // A View is visually behind its SubPanes so it draws itself first,
  156.             //then its SubPanes            
  157.             if (ExecuteAttachments(msg_DrawOrPrint, &frame))
  158.                 DrawSelf();
  159.  
  160.             if (!mIsTracking)
  161.             {
  162.                 LArrayIterator iterator(mSubPanes, LArrayIterator::from_Start);
  163.                 LPane    *theSub;
  164.                 while (iterator.Next(&theSub))
  165.                     theSub->Draw(mUpdateRgnH);
  166.             }
  167.         }
  168.         
  169.         ::SetEmptyRgn(mUpdateRgnH);    // Emptying update region frees up memory
  170.                                     // if this region wasn't rectangular
  171.     }
  172. }
  173.  
  174. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  175. //    Ñ    
  176. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  177.  
  178. void CDragBar::Click(SMouseDownEvent& inMouseDown)
  179. {
  180.     LPane* theClickedPane = FindDeepSubPaneContaining(inMouseDown.wherePort.h, inMouseDown.wherePort.v );
  181.     if ((theClickedPane != NULL) && (theClickedPane->GetPaneID() == CPatternedGrippyPane::class_ID))
  182.         {
  183.         ClickDragSelf(inMouseDown);
  184.         }
  185.     else
  186.         {
  187.         theClickedPane = FindSubPaneHitBy(inMouseDown.wherePort.h, inMouseDown.wherePort.v);
  188.         if (theClickedPane != NULL)
  189.             theClickedPane->Click(inMouseDown);
  190.         }
  191. }
  192.  
  193. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  194. //    Ñ DragBars may be hidden from container and dock by javascript - mjc
  195. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  196.  
  197. void CDragBar::SetAvailable(Boolean inAvailable)
  198. {
  199.     mIsAvailable = inAvailable;
  200. }
  201.  
  202. Boolean CDragBar::IsAvailable()
  203. {
  204.     return mIsAvailable;
  205. }
  206.  
  207. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  208. //    Ñ    
  209. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  210.  
  211. void CDragBar::DrawSelf(void)
  212. {
  213.     StColorPenState::Normalize();
  214.     
  215.     Rect theFrame;
  216.     CalcLocalFrameRect(theFrame);
  217.     
  218.     Point theAlignment;
  219.     CSharedPatternWorld::CalcRelativePoint(this, CSharedPatternWorld::eOrientation_Port, theAlignment);
  220.  
  221.     // We do this instead of LPane::GetMacPort() because we may be being
  222.     // drawn offscreen.
  223.     CGrafPtr thePort;
  224.     ::GetPort(&(GrafPtr)thePort);
  225.     mPatternWorld->Fill(thePort, theFrame, theAlignment);
  226.  
  227.     if (mIsTracking)
  228.         UGraphicGizmos::LowerColorVolume(theFrame, 0x2000);
  229. }
  230.  
  231. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  232. //    Ñ    
  233. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  234.  
  235. void CDragBar::ClickDragSelf(const SMouseDownEvent& inMouseDown)
  236. {
  237.     FocusDraw();
  238.     
  239.     Point theGlobalPoint = inMouseDown.wherePort;
  240.     PortToGlobalPoint(theGlobalPoint);
  241.     if (::WaitMouseMoved(theGlobalPoint))
  242.         {
  243.         CDragBarDragTask theTask(this, inMouseDown.macEvent);
  244.         theTask.DoDrag();
  245.         }
  246.     else
  247.         BroadcastMessage(msg_DragBarCollapse, this);
  248. }
  249.