home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CDownloadProgressWindow.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  8.8 KB  |  312 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. //    CDownloadProgressWindow.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #include "CDownloadProgressWindow.h"
  24. #include "CNSContext.h"
  25. #include "CProgressBar.h"
  26. #include "COffscreenCaption.h"
  27. #include "Netscape_Constants.h"
  28. #include "PascalString.h"
  29.  
  30. #include "mkgeturl.h"
  31. #include "resgui.h"
  32.  
  33. #include <PP_Messages.h>
  34.  
  35. #define MIN_TICKS    (60/4)    // Don't refresh the progress bar more than 4x /sec.
  36.  
  37. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  38. //    Ñ    
  39. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  40.  
  41. CDownloadProgressWindow::CDownloadProgressWindow(LStream* inStream)
  42.     :    CMediatedWindow(inStream, WindowType_Progress)
  43.     ,    CSaveWindowStatus(this)
  44. {
  45.     mContext = NULL;
  46.     mClosing = false;
  47.     mMessageLastTicks = 0;
  48.     mPercentLastTicks = 0;
  49. }
  50.  
  51. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  52. //    Ñ    
  53. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  54.  
  55. CDownloadProgressWindow::~CDownloadProgressWindow()
  56. {
  57.     SetWindowContext(NULL);
  58. }
  59.  
  60. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  61. //    Ñ    
  62. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  63.  
  64. ResIDT CDownloadProgressWindow::GetStatusResID() const
  65. {
  66.     return WIND_DownloadProgress;
  67. } // client must provide!
  68.  
  69. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  70. //    Ñ    
  71. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  72.  
  73. UInt16 CDownloadProgressWindow::GetValidStatusVersion() const
  74. {
  75.     return 0x0001;
  76. } // CDownloadProgressWindow::GetValidStatusVersion
  77.  
  78. //-----------------------------------
  79. void CDownloadProgressWindow::AttemptClose()
  80. //-----------------------------------
  81. {
  82.     CSaveWindowStatus::AttemptCloseWindow();
  83.     Inherited::AttemptClose();
  84. }
  85.  
  86. //-----------------------------------
  87. void CDownloadProgressWindow::DoClose()
  88. //-----------------------------------
  89. {
  90.     CSaveWindowStatus::AttemptCloseWindow();
  91.     Inherited::DoClose();
  92. }
  93.  
  94. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  95. //    Ñ    
  96. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  97.  
  98. void CDownloadProgressWindow::FinishCreateSelf(void)
  99. {
  100.     CMediatedWindow::FinishCreateSelf();
  101.     
  102.     mBar = dynamic_cast<CProgressBar*>(FindPaneByID(PaneID_ProgressBar));
  103.     Assert_(mBar != NULL);
  104.     
  105.     mMessage = dynamic_cast<COffscreenCaption*>(FindPaneByID(PaneID_ProgressMessage));
  106.     Assert_(mMessage != NULL);
  107.  
  108.     mComment = dynamic_cast<COffscreenCaption*>(FindPaneByID(PaneID_ProgressComment));    
  109.     Assert_(mComment != NULL);
  110.  
  111.     LControl* theButton = dynamic_cast<LControl*>(FindPaneByID(PaneID_ProgressCancelButton));
  112.     Assert_(theButton != NULL);
  113.     theButton->AddListener(this);
  114.     CSaveWindowStatus::FinishCreateWindow();
  115. }
  116.  
  117. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  118. //    Ñ    
  119. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  120.  
  121. void CDownloadProgressWindow::SetWindowContext(CNSContext* inContext)
  122. {
  123.     if (mContext != NULL)
  124.         mContext->RemoveUser(this);
  125.         
  126.     mContext = inContext;
  127.     
  128.     if (mContext != NULL)
  129.         {
  130.         mContext->AddListener(this);
  131.         mContext->AddUser(this);
  132.         }
  133. }
  134.  
  135. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  136. //    Ñ    
  137. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  138.  
  139. CNSContext* CDownloadProgressWindow::GetWindowContext(void)
  140. {
  141.     return mContext;
  142. }
  143.  
  144. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  145. //    Ñ    
  146. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  147.  
  148. Boolean CDownloadProgressWindow::HandleKeyPress(
  149.     const EventRecord&    inKeyEvent)
  150. {
  151.     Boolean        keyHandled = false;
  152.     LControl    *keyButton = nil;
  153.     
  154.     switch (inKeyEvent.message & charCodeMask)
  155.         {
  156.         case char_Escape:
  157.             if ((inKeyEvent.message & keyCodeMask) == vkey_Escape)
  158.                 keyButton =  (LControl*)FindPaneByID(PaneID_ProgressCancelButton);
  159.             break;
  160.  
  161.         default:
  162.             if (UKeyFilters::IsCmdPeriod(inKeyEvent))
  163.                 keyButton =  (LControl*)FindPaneByID(PaneID_ProgressCancelButton);
  164.             else
  165.                 keyHandled = CMediatedWindow::HandleKeyPress(inKeyEvent);
  166.             break;
  167.         }
  168.             
  169.     if (keyButton != nil)
  170.         {
  171.         keyButton->SimulateHotSpotClick(kControlButtonPart);
  172.         keyHandled = true;
  173.         }
  174.     
  175.     return keyHandled;
  176. }
  177.  
  178. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  179. //    Ñ    
  180. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  181.  
  182. void CDownloadProgressWindow::FindCommandStatus(
  183.     CommandT            inCommand,
  184.     Boolean                &outEnabled,
  185.     Boolean                &outUsesMark,
  186.     Char16                &outMark,
  187.     Str255                outName)
  188. {
  189.     if (inCommand == cmd_Stop)
  190.     {
  191.         outEnabled = true;
  192.         return;
  193.     }
  194.     CMediatedWindow::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
  195. }
  196.  
  197.  
  198. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  199. //    Ñ    
  200. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  201.  
  202. Boolean CDownloadProgressWindow::ObeyCommand(
  203.     CommandT            inCommand,
  204.     void*                /*ioParam*/)
  205. {
  206.     if (inCommand == cmd_Stop)
  207.     {
  208.         LControl *keyButton = (LControl*)FindPaneByID(PaneID_ProgressCancelButton);
  209.         if (keyButton != nil)
  210.             keyButton->SimulateHotSpotClick(kControlButtonPart);
  211.         return true;
  212.     }
  213.     return false;
  214. }
  215.  
  216.  
  217. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  218. //    Ñ    
  219. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  220.  
  221. void CDownloadProgressWindow::ListenToMessage(
  222.     MessageT            inMessage,
  223.     void*                ioParam)
  224. {
  225.     if (mClosing)
  226.         return;
  227.  
  228.     switch (inMessage)
  229.         {
  230.         case msg_Cancel:
  231. //            NET_SilentInterruptWindow(*mContext);
  232. //                replaced the line above with the following ones...    
  233.             mClosing = true;
  234.             if (mContext) {
  235.                 XP_InterruptContext(*mContext);
  236.                 SetWindowContext(NULL);        // calls RemoveUser() and destroys context
  237.             }
  238.             DoClose();
  239.             break;
  240.  
  241.         case msg_NSCAllConnectionsComplete:
  242.             DoClose();
  243.             break;
  244.             
  245.         case msg_NSCProgressBegin:
  246.             NoteProgressBegin(*(CContextProgress*)ioParam);
  247.             break;
  248.             
  249.         case msg_NSCProgressUpdate:
  250.             NoteProgressUpdate(*(CContextProgress*)ioParam);
  251.             break;
  252.             
  253.         case msg_NSCProgressEnd:
  254.             NoteProgressEnd(*(CContextProgress*)ioParam);
  255.             break;
  256.  
  257.         case msg_NSCProgressMessageChanged:
  258. //            CContextProgress* theProgress = (CContextProgress*)ioParam;
  259. //            Assert_(theProgress != NULL);
  260. //            mMessage->SetDescriptor(theProgress->mMessage);
  261.             if (::TickCount() - mMessageLastTicks >= MIN_TICKS)
  262.             {
  263.                 mMessageLastTicks = ::TickCount();
  264.                 mMessage->SetDescriptor((const char*)ioParam);
  265.             }
  266.             break;
  267.             
  268.         case msg_NSCProgressPercentChanged:
  269.             if (::TickCount() - mPercentLastTicks >= MIN_TICKS)
  270.             {
  271.                 mPercentLastTicks = ::TickCount();
  272.                 mBar->SetValue(*(Int32*)ioParam);
  273.             }
  274.             break;
  275.         }
  276. }
  277.  
  278. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  279. //    Ñ    
  280. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  281.  
  282. void CDownloadProgressWindow::NoteProgressBegin(const CContextProgress& inProgress)
  283. {
  284.     SetDescriptor(CStr255(inProgress.mAction));
  285.  
  286.     mMessage->SetDescriptor(inProgress.mMessage);
  287.     mComment->SetDescriptor(inProgress.mComment);
  288.     Show();            
  289. }
  290.  
  291. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  292. //    Ñ    
  293. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  294.  
  295. void CDownloadProgressWindow::NoteProgressUpdate(const CContextProgress& inProgress)
  296. {
  297.     if (inProgress.mPercent != mBar->GetValue())
  298.         mBar->SetValue(inProgress.mPercent);
  299.             
  300.     mMessage->SetDescriptor(inProgress.mMessage);
  301. }
  302.  
  303. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  304. //    Ñ    
  305. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  306.  
  307. void CDownloadProgressWindow::NoteProgressEnd(const CContextProgress& )
  308. {
  309.     Hide();
  310. }
  311.  
  312.