home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / LogoTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.8 KB  |  244 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:        LogoTest.c                                                */
  21. /* Description:    Test for XfeLogo widget.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27.  
  28. #include <Xfe/XfeTest.h>
  29.  
  30. static void    animation_callback        (Widget,XtPointer,XtPointer);
  31. static void    init_animations            (void);
  32. static void    set_animation            (Cardinal);
  33.  
  34. static void    logo_activate_callback    (Widget,XtPointer,XtPointer);
  35. static void    start_callback            (Widget,XtPointer,XtPointer);
  36. static void    stop_callback            (Widget,XtPointer,XtPointer);
  37. static void    reset_callback            (Widget,XtPointer,XtPointer);
  38. static void    tick_callback            (Widget,XtPointer,XtPointer);
  39.  
  40. #define NUM_ANIMATIONS        4
  41. #define ANIMATION_INTERVAL    100
  42.  
  43. static XfePixmapTable    _animation_pixmaps[NUM_ANIMATIONS];
  44. static Cardinal            _animation_frame_counts[NUM_ANIMATIONS];
  45. static Cardinal            _current_animation = 0;
  46. static String            _animation_names[NUM_ANIMATIONS] =
  47. {
  48.     "Transparent Large",
  49.     "Transparent Small",
  50.     "Main Large",
  51.     "Main Small"
  52. };
  53.  
  54. static Widget _logo            = NULL;
  55. static Widget _progress_bar    = NULL;
  56.  
  57. /*----------------------------------------------------------------------*/
  58. int
  59. main(int argc,char *argv[])
  60. {
  61.     Widget    form;
  62.     Widget    frame;
  63.     Widget    tool_bar;
  64.     Widget    start;
  65.     Widget    stop;
  66.     Widget    reset;
  67.     Widget    tick;
  68.  
  69.     XfeAppCreateSimple("LogoTest",&argc,argv,"MainFrame",&frame,&form);
  70.  
  71.     _logo = XtVaCreateManagedWidget("Logo",
  72.                                     xfeLogoWidgetClass,
  73.                                     form,
  74.                                     NULL);
  75.     
  76.     _progress_bar = XtVaCreateManagedWidget("ProgressBar",
  77.                                             xfeProgressBarWidgetClass,
  78.                                             form,
  79.                                             NULL);
  80.  
  81.     tool_bar = XtVaCreateManagedWidget("ToolBar",
  82.                                        xfeToolBarWidgetClass,
  83.                                        form,
  84.                                        NULL);
  85.  
  86.     start = XtVaCreateManagedWidget("Start",
  87.                                     xfeButtonWidgetClass,
  88.                                     tool_bar,
  89.                                     NULL);
  90.  
  91.     stop = XtVaCreateManagedWidget("Stop",
  92.                                     xfeButtonWidgetClass,
  93.                                     tool_bar,
  94.                                     NULL);
  95.  
  96.     tick = XtVaCreateManagedWidget("Tick",
  97.                                     xfeButtonWidgetClass,
  98.                                     tool_bar,
  99.                                     NULL);
  100.  
  101.     reset = XtVaCreateManagedWidget("Reset",
  102.                                     xfeButtonWidgetClass,
  103.                                     tool_bar,
  104.                                     NULL);
  105.  
  106.     
  107.     init_animations();
  108.  
  109.     XtVaSetValues(_logo,
  110.                   XmNbuttonLayout,        XmBUTTON_LABEL_ON_BOTTOM,
  111.                   NULL);
  112.  
  113.     XtAddCallback(_logo,XmNactivateCallback,logo_activate_callback,NULL);
  114.     XtAddCallback(_logo,XmNanimationCallback,animation_callback,NULL);
  115.  
  116.     XtAddCallback(start,XmNactivateCallback,start_callback,NULL);
  117.     XtAddCallback(stop,XmNactivateCallback,stop_callback,NULL);
  118.     XtAddCallback(reset,XmNactivateCallback,reset_callback,NULL);
  119.     XtAddCallback(tick,XmNactivateCallback,tick_callback,NULL);
  120.  
  121.     set_animation(0);
  122.  
  123.     XtPopup(frame,XtGrabNone);
  124.  
  125.     XfeAppMainLoop();
  126.  
  127.     return 0;
  128. }
  129. /*----------------------------------------------------------------------*/
  130. static void
  131. set_animation(Cardinal i)
  132. {
  133.     assert( i < NUM_ANIMATIONS );
  134.  
  135.     assert( _animation_pixmaps != NULL );
  136.     assert( _animation_pixmaps[i] != NULL );
  137.     assert( _animation_frame_counts != NULL );
  138.  
  139.     XtVaSetValues(_logo,
  140.                      XmNanimationPixmaps,        _animation_pixmaps[i],
  141.                   XmNnumAnimationPixmaps,    _animation_frame_counts[i],
  142.                   NULL);
  143. }
  144. /*----------------------------------------------------------------------*/
  145. static void
  146. animation_callback(Widget w,XtPointer client_data,XtPointer call_data)
  147. {
  148.     Cardinal    i;
  149.     char        buf[1024];
  150.  
  151.     XtVaGetValues(_logo,XmNcurrentPixmapIndex,&i,NULL);
  152.  
  153.     sprintf(buf,"%s\n%d",_animation_names[_current_animation],i);
  154.  
  155.     XfeSetXmStringPSZ(_logo,XmNlabelString,XmFONTLIST_DEFAULT_TAG,buf);
  156. }
  157. /*----------------------------------------------------------------------*/
  158. static void
  159. logo_activate_callback(Widget w,XtPointer client_data,XtPointer call_data)
  160. {
  161.     _current_animation++;
  162.  
  163.     if (_current_animation == NUM_ANIMATIONS)
  164.     {
  165.         _current_animation = 0;
  166.     }
  167.  
  168.     set_animation(_current_animation);
  169. }
  170. /*----------------------------------------------------------------------*/
  171. static void
  172. start_callback(Widget w,XtPointer client_data,XtPointer call_data)
  173. {
  174.     XfeLogoAnimationStart(_logo);
  175.  
  176.     XfeProgressBarCylonStart(_progress_bar);
  177. }
  178. /*----------------------------------------------------------------------*/
  179. static void
  180. stop_callback(Widget w,XtPointer client_data,XtPointer call_data)
  181. {
  182.     XfeLogoAnimationStop(_logo);
  183.  
  184.     XfeProgressBarCylonStop(_progress_bar);
  185. }
  186. /*----------------------------------------------------------------------*/
  187. static void
  188. reset_callback(Widget w,XtPointer client_data,XtPointer call_data)
  189. {
  190.     XfeLogoAnimationReset(_logo);
  191.  
  192.     XfeProgressBarCylonReset(_progress_bar);
  193. }
  194. /*----------------------------------------------------------------------*/
  195. static void
  196. tick_callback(Widget w,XtPointer client_data,XtPointer call_data)
  197. {
  198.     XfeProgressBarCylonTick(_progress_bar);
  199. }
  200. /*----------------------------------------------------------------------*/
  201. static void
  202. init_animations()
  203. {
  204.     XfePixmapTable    pixmaps = NULL;
  205.     Cardinal        num_pixmaps = 0;
  206.  
  207.     /* Transparent 40x40 */
  208.     pixmaps = NULL;
  209.     num_pixmaps = 0;
  210.  
  211.     XfeGetTransparent40x40Animation(_logo,&pixmaps,&num_pixmaps);
  212.  
  213.     _animation_pixmaps[0] = pixmaps;
  214.     _animation_frame_counts[0] = num_pixmaps;
  215.  
  216.     /* Transparent 20x20 */
  217.     pixmaps = NULL;
  218.     num_pixmaps = 0;
  219.  
  220.     XfeGetTransparent20x20Animation(_logo,&pixmaps,&num_pixmaps);
  221.  
  222.     _animation_pixmaps[1] = pixmaps;
  223.     _animation_frame_counts[1] = num_pixmaps;
  224.  
  225.     /* Main 40x40 */
  226.     pixmaps = NULL;
  227.     num_pixmaps = 0;
  228.  
  229.     XfeGetMain40x40Animation(_logo,&pixmaps,&num_pixmaps);
  230.  
  231.     _animation_pixmaps[2] = pixmaps;
  232.     _animation_frame_counts[2] = num_pixmaps;
  233.  
  234.     /* Main 20x20 */
  235.     pixmaps = NULL;
  236.     num_pixmaps = 0;
  237.  
  238.     XfeGetMain20x20Animation(_logo,&pixmaps,&num_pixmaps);
  239.  
  240.     _animation_pixmaps[3] = pixmaps;
  241.     _animation_frame_counts[3] = num_pixmaps;
  242. }
  243. /*----------------------------------------------------------------------*/
  244.