home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / ProgressBarTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.8 KB  |  202 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. /* Name:        ProgressBarTest.c                                        */
  21. /* Description:    Test for XfeProgressBar widget.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. static void    StartSweep        (Widget,int);
  30. static void    SweepTimeout    (XtPointer,XtIntervalId *);
  31.  
  32. static void    StartMessages    (Widget,int);
  33. static void    MessageTimeout    (XtPointer,XtIntervalId *);
  34.  
  35. #define SWEEP_INTERVAL        100
  36. #define MESSAGE_INTERVAL    500
  37.  
  38. #define MAX_PERCENT        100
  39. #define MIN_PERCENT        0
  40.  
  41. static String _messages[] = 
  42. {
  43.     "A News error occurred",
  44.     "If you are unable to connect again later, contact",
  45.     "If you are unable to connect again, contact the",
  46.     "Netscape is unable to complete a socket connection",
  47.     "Netscape is unable to complete a socket connection ",
  48.     "Netscape is unable to connect to the server at",
  49.     "Netscape is unable to connect to your proxy server.",
  50.     "Netscape refuses to connect to this server.",
  51.     "Netscape was unable to connect to the SMTP server.",
  52.     "Netscape was unable to create a network socket connection.",
  53.     "Netscape was unble to connect to the secure news server",
  54.     "Netscape's network connection was refused by the server",
  55.     "Please try your connection again)",
  56.     "The server has disconnected.",
  57.     "The server may not be accepting connections or the end of the world is upon us very soon.",
  58.     "Try connecting again later or try restarting Netscape.",
  59.     "Try connecting again later or try restarting Netscape. You can try to connect later if you like.",
  60.     "Try connecting again later.",
  61.     "Try connecting again.",
  62.     "You will not be able to connect to this site securely.",
  63.     "You will probably be unable to connect to this site securely, or you can risk being stolen from.",
  64.     "server to establish a data connection.",
  65.     "unable to connect to server (TCP Error"
  66. };
  67.  
  68. /*----------------------------------------------------------------------*/
  69. int
  70. main(int argc,char *argv[])
  71. {
  72.     Widget    form;
  73.     Widget    frame;
  74.     Widget    status_form;
  75.     Widget    status_frame;
  76.  
  77.     Widget    progress_bar;
  78.     Widget    status_bar;
  79.     Widget    task_bar;
  80.  
  81.     XfeAppCreateSimple("ProgressBarTest",&argc,argv,"MainFrame",&frame,&form);
  82.     
  83.     status_frame = XfeCreateManagedFrame(form,"StatusFrame",NULL,0);
  84.  
  85.     status_form = XfeCreateManagedForm(status_frame,"StatusForm",NULL,0);
  86.  
  87.     task_bar = XtCreateManagedWidget("TaskBar",
  88.                                      xmPushButtonWidgetClass,
  89.                                      status_form,NULL,0);
  90.  
  91.     progress_bar = 
  92.         XtVaCreateManagedWidget("ProgressBar",
  93.                                 xfeProgressBarWidgetClass,
  94.                                 status_form,
  95.                                 XmNrightWidget,        task_bar,
  96.                                 NULL);
  97.     
  98.     status_bar = 
  99.         XtVaCreateWidget("StatusBar",
  100.                          xfeLabelWidgetClass,
  101.                          status_form,
  102.                          XmNrightWidget,    progress_bar,
  103.                          XmNtruncateProc,    XfeGetTruncateXmStringProc(),
  104.                          XmNtruncateLabel,    True,
  105.                          XmNshadowType,        XmSHADOW_IN,
  106.                          NULL);
  107.  
  108.     XtManageChild(status_bar);
  109.     
  110.     StartSweep(progress_bar,SWEEP_INTERVAL);
  111.  
  112.     StartMessages(status_bar,MESSAGE_INTERVAL);
  113.  
  114.     XtPopup(frame,XtGrabNone);
  115.     
  116.     XfeAppMainLoop();
  117.  
  118.     return 0;
  119. }
  120. /*----------------------------------------------------------------------*/
  121. static void
  122. StartSweep(Widget w,int interval)
  123. {
  124.     XfeAppAddTimeOut(interval,SweepTimeout,(XtPointer) w);
  125. }
  126. /*----------------------------------------------------------------------*/
  127. static void
  128. SweepTimeout(XtPointer client_data,XtIntervalId * id)
  129. {
  130.     Widget        w = (Widget) client_data;
  131.     static Boolean    direction = True;
  132.     static int        percent = 0;
  133.     
  134.     char        buf[2048];
  135.     XmString        xm_label = NULL;
  136.  
  137.     if (direction)
  138.     {
  139.     percent++;
  140.     
  141.     if (percent > MAX_PERCENT)
  142.     {
  143.         percent = MAX_PERCENT;
  144.         direction = False;
  145.     }
  146.     }
  147.     else
  148.     {
  149.     percent--;
  150.     
  151.     if (percent < MIN_PERCENT)
  152.     {
  153.         percent = MIN_PERCENT;
  154.         direction = True;
  155.     }
  156.     }
  157.  
  158.     sprintf(buf,"%d%% of 1234k",percent);
  159.  
  160.     xm_label = XmStringCreateLocalized(buf);
  161.  
  162.     XfeProgressBarSetComponents(w,xm_label,0,percent);
  163.  
  164.     if (xm_label)
  165.     {
  166.     XmStringFree(xm_label);
  167.     }
  168.  
  169.     StartSweep(w,SWEEP_INTERVAL);
  170. }
  171. /*----------------------------------------------------------------------*/
  172. static void
  173. StartMessages(Widget w,int interval)
  174. {
  175.     XfeAppAddTimeOut(interval,MessageTimeout,(XtPointer) w);
  176. }
  177. /*----------------------------------------------------------------------*/
  178. static void
  179. MessageTimeout(XtPointer client_data,XtIntervalId * id)
  180. {
  181.     Widget        w = (Widget) client_data;
  182.     static int    i = 0;
  183.     
  184.     char        buf[2048];
  185.  
  186.     if (!(i % 2))
  187.     {
  188.         sprintf(buf,"%s",_messages[i++ % XtNumber(_messages)]);
  189.     }
  190.     else
  191.     {
  192.         buf[0] = '\0';
  193.         i++;
  194.     }
  195.  
  196. /*    XfeProgressBarSetLabelPSZ(w,buf);*/
  197.     XfeLabelSetStringPSZ(w,buf);
  198.     
  199.     StartMessages(w,MESSAGE_INTERVAL);
  200. }
  201. /*----------------------------------------------------------------------*/
  202.