home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / progress / src / pw_mac.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.2 KB  |  292 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. /* pw_mac.cpp
  20.  * author: atotic
  21.  * Mac implementation of progress interface
  22.  */
  23.  
  24. #define OLDROUTINENAMES 0        // Why is this here?
  25. #include <PP_ClassHeaders.cp>    // pchen: put <PP_ClassHeaders.cp> ahead of pw_public.h
  26.                                 // to avoid TRUE and FALSE redefine error
  27. #include "pw_public.h"
  28. #include <TextEdit.h>
  29. #include "uapp.h"
  30. #include "PP_Messages.h"
  31. #include "CPatternProgressBar.h"
  32. #include "UDesktop.h"
  33.  
  34. #define PW_WINDOW_ID 5102
  35.  
  36. class CProgressMac: public LListener {
  37.  
  38. public:
  39.     LWindow * fWindow;
  40.     LCaption * fLine1, * fLine2, * fLine3;
  41.     CPatternProgressBar * fProgress;
  42.     
  43.     PW_CancelCallback fCancelcb;
  44.     void * fCancelClosure;
  45.     
  46. // Constructors
  47.     CProgressMac(PW_WindowType type);
  48.  
  49.     virtual ~CProgressMac();
  50.     
  51. // PW interface
  52.     void SetCancelCallback(PW_CancelCallback cancelcb,    /* Callback function for cancel */
  53.                 void * cancelClosure);
  54.  
  55.     void Show();
  56.     
  57.     void Hide();
  58.     
  59.     void SetWindowTitle(const char * title);
  60.     
  61.     void SetLine1(const char * text);
  62.  
  63.     void SetLine2(const char * text);
  64.     
  65.     void SetProgressText(const char * text);
  66.     
  67.     void SetProgressRange(int32 minimum, int32 maximum);
  68.     
  69.     void SetProgressValue(int32 value);
  70.     
  71.     void ListenToMessage( MessageT inMessage, void* ioParam );
  72. };
  73.  
  74. CProgressMac::CProgressMac(PW_WindowType type)
  75. {
  76.     fCancelcb = NULL;
  77.     fCancelClosure = NULL;
  78.     
  79. // Create the window
  80. // Our default resource stores an application modal, need to change the resource
  81. // before loading it in
  82.  
  83.  
  84.     SWINDResourceH    theWIND = NULL;
  85.     
  86.     if ( type == pwStandard )
  87.     {
  88.         theWIND = (SWINDResourceH) ::GetResource('WIND', PW_WINDOW_ID);
  89.         if ( theWIND )
  90.         {
  91.             HLock( (Handle)theWIND );
  92.             (*theWIND)->procID = 4;
  93.         }
  94.     }
  95.     LCommander::SetDefaultCommander(CFrontApp::GetApplication());
  96.     
  97.     fWindow = LWindow::CreateWindow( PW_WINDOW_ID, NULL );
  98.     ThrowIfNil_(fWindow);
  99.     
  100.     if ( type == pwStandard )
  101.     {
  102.         (*theWIND)->procID = 5;    // revert
  103.         HUnlock( (Handle)theWIND );
  104.     }
  105.  
  106.     fLine1 = (LCaption*)fWindow->FindPaneByID('LIN1');
  107.     fLine2 = (LCaption*)fWindow->FindPaneByID('LIN2');
  108.     fLine3 = (LCaption*)fWindow->FindPaneByID('LIN3');
  109.     fProgress = (CPatternProgressBar *)fWindow->FindPaneByID('PtPb');
  110.     ThrowIfNil_(fLine1);
  111.     ThrowIfNil_(fLine2);
  112.     ThrowIfNil_(fLine3);
  113.     ThrowIfNil_(fProgress);
  114. }
  115.  
  116. CProgressMac::~CProgressMac()
  117. {
  118.     if (fWindow)
  119.         delete fWindow;
  120. }
  121.  
  122. void CProgressMac::SetCancelCallback(PW_CancelCallback incancelcb,    /* Callback function for cancel */
  123.                 void * incancelClosure)
  124. {
  125.     fCancelcb = incancelcb;
  126.     fCancelClosure = incancelClosure;
  127.     
  128.     LButton * cancelButton = (LButton *)fWindow->FindPaneByID('CNCL');
  129.     cancelButton->AddListener(this);
  130. }
  131.  
  132. void CProgressMac::ListenToMessage( MessageT inMessage, void* ioParam )
  133. {
  134. #pragma unused (ioParam)
  135.     if ( inMessage == msg_Cancel)
  136.         if (fCancelcb)
  137.             fCancelcb(fCancelClosure);
  138. }
  139.  
  140. void CProgressMac::Show()
  141. {
  142.     fWindow->Show();
  143.     UDesktop::SelectDeskWindow(fWindow);
  144. }
  145.     
  146. void CProgressMac::Hide()
  147. {
  148.     fWindow->Hide();
  149. }
  150.     
  151. void CProgressMac::SetWindowTitle(const char * title)
  152. {
  153.     LStr255 ptitle;
  154.     if (title)
  155.         ptitle = title; 
  156.     fWindow->SetDescriptor(ptitle);
  157. }
  158.  
  159. void CProgressMac::SetLine1(const char * text)
  160. {
  161.     LStr255 ptext;
  162.     if (text)
  163.         ptext = text;
  164.     fLine1->SetDescriptor(ptext);
  165. }
  166.  
  167. void CProgressMac::SetLine2(const char * text)
  168. {
  169.     LStr255 ptext;
  170.     if (text)
  171.         ptext = text;
  172.     fLine2->SetDescriptor(ptext);
  173. }
  174.  
  175. void CProgressMac::SetProgressText(const char * text)
  176. {
  177.     LStr255 ptext;
  178.     if (text)
  179.         ptext = text;
  180.     fLine3->SetDescriptor(ptext);
  181. }
  182.  
  183. void CProgressMac::SetProgressRange(int32 minimum, int32 maximum)
  184. {
  185.     if (maximum > minimum)
  186.     {
  187.         Range32T    r(minimum, maximum);
  188.         fProgress->SetValueRange(r);
  189.         fProgress->SetValue(minimum);
  190.     }
  191.     else
  192.     {
  193.         fProgress->SetToIndefinite();
  194.     }
  195. }
  196.  
  197. void CProgressMac::SetProgressValue(int32 value)
  198. {
  199.     fProgress->SetValue(value);
  200. }
  201.  
  202.  
  203. #pragma export on
  204.  
  205. pw_ptr PW_Create( MWContext * /*parent*/,         /* Parent window, can be NULL */
  206.                 PW_WindowType type            /* What kind of window ? Modality, etc */
  207.                 )
  208. {
  209.     volatile CProgressMac * mac = NULL;
  210.     
  211.     try
  212.     {
  213.         mac = new CProgressMac(type);
  214.     }
  215.     catch(OSErr err)
  216.     {
  217.         XP_ASSERT(FALSE);
  218.     }
  219.     if (mac)
  220.     { // Clean up the progress text
  221.         PW_SetWindowTitle(mac, NULL);
  222.         PW_SetLine1(mac, NULL);
  223.         PW_SetLine2(mac, NULL);
  224.     }
  225.     return mac;
  226. }
  227.  
  228. void PW_SetCancelCallback(pw_ptr pw,
  229.                             PW_CancelCallback cancelcb,
  230.                             void * cancelClosure)
  231. {
  232.     if (pw)
  233.         ((CProgressMac *)pw)->SetCancelCallback(cancelcb, cancelClosure);
  234. }
  235.  
  236.  
  237. void PW_Show(pw_ptr pw)
  238. {
  239.     if (pw)
  240.         ((CProgressMac *)pw)->Show();
  241. }
  242.  
  243. void PW_Hide(pw_ptr pw)
  244. {
  245.     if (pw)
  246.         ((CProgressMac *)pw)->Hide();
  247. }
  248.  
  249. void PW_Destroy(pw_ptr pw)
  250. {
  251.     if (pw)
  252.         delete (CProgressMac*)pw;
  253. }
  254.  
  255. void PW_SetWindowTitle(pw_ptr pw, const char * title)
  256. {
  257.     if (pw)
  258.         ((CProgressMac *)pw)->SetWindowTitle(title);
  259. }
  260.  
  261. void PW_SetLine1(pw_ptr pw, const char * text)
  262. {
  263.     if (pw)
  264.         ((CProgressMac *)pw)->SetLine1(text);
  265. }
  266.  
  267. void PW_SetLine2(pw_ptr pw, const char * text)
  268. {
  269.     if (pw)
  270.         ((CProgressMac *)pw)->SetLine2(text);
  271. }
  272.  
  273. void PW_SetProgressText(pw_ptr pw, const char * text)
  274. {
  275.     if (pw)
  276.         ((CProgressMac *)pw)->SetProgressText(text);
  277. }
  278.  
  279. void PW_SetProgressRange(pw_ptr pw, int32 minimum, int32 maximum)
  280. {
  281.     if (pw)
  282.         ((CProgressMac *)pw)->SetProgressRange(minimum, maximum);            
  283. }
  284.  
  285. void PW_SetProgressValue(pw_ptr pw, int32 value)
  286. {
  287.     if (pw)
  288.         ((CProgressMac *)pw)->SetProgressValue(value);            
  289. }
  290.  
  291. #pragma export off
  292.