home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / tests / ToolBoxTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.0 KB  |  183 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:        ToolBoxTest.c                                            */
  21. /* Description:    Test for XfeToolBox widget.                                */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. static Widget    create_tool_item        (Widget,String,Cardinal);
  30. static void        close_cb                (Widget,XtPointer,XtPointer);
  31. static void        open_cb                (Widget,XtPointer,XtPointer);
  32. static void        new_item_cb                (Widget,XtPointer,XtPointer);
  33. static void        snap_cb                    (Widget,XtPointer,XtPointer);
  34. static void        swap_cb                    (Widget,XtPointer,XtPointer);
  35.  
  36. static void        button_cb                (Widget,XtPointer,XtPointer);
  37.  
  38.  
  39. static String tool_names[] = 
  40. {
  41.     "red",
  42.     "yellow",
  43.     "green",
  44. #if 1
  45.     "blue",
  46.     "orange",
  47.     "purple",
  48.     "pink",
  49.     "aliceblue"
  50. #endif
  51. };
  52.  
  53.  
  54. static int tool_heights[] = 
  55. {
  56.     2,
  57.     4,
  58.     6,
  59.     8,
  60.     10,
  61.     12,
  62.     10,
  63.     8
  64. };
  65.  
  66. #define NUM_TOOLS XtNumber(tool_names)
  67.  
  68. static Widget tool_widgets[NUM_TOOLS];
  69.  
  70. /*----------------------------------------------------------------------*/
  71. int
  72. main(int argc,char *argv[])
  73. {
  74.     Widget    form;
  75.     Widget    frame;
  76.  
  77.     Widget        tb;
  78.     Cardinal    i;
  79.  
  80.     XfeAppCreateSimple("ToolBoxTest",&argc,argv,"MainFrame",&frame,&form);
  81.     
  82.     tb = XfeCreateLoadedToolBox(form,"ToolBox",NULL,0);
  83.  
  84.     for (i = 0; i < NUM_TOOLS; i++)
  85.     {
  86.         tool_widgets[i] = create_tool_item(tb,
  87.                                            tool_names[i],
  88.                                            tool_heights[i]);
  89.     }
  90.  
  91.     XtPopup(frame,XtGrabNone);
  92.  
  93.     XfeAppMainLoop();
  94.  
  95.     return 0;
  96. }
  97. /*----------------------------------------------------------------------*/
  98. static Widget
  99. create_tool_item(Widget parent,String name,Cardinal nitems)
  100. {
  101.     Widget        tool_item;
  102.     Widget        tool_bar;
  103.     Widget        logo;
  104.  
  105.     tool_item = 
  106.         XtVaCreateManagedWidget(name,
  107.                                 xfeToolItemWidgetClass,
  108.                                 parent,
  109.                                 XmNusePreferredHeight,    True,
  110.                                 XmNusePreferredWidth,    False,
  111.                                 XmNbackground,            XfeGetPixel(name),
  112.                                 NULL);
  113.  
  114.     logo = 
  115.         XtVaCreateManagedWidget("Logo",
  116.                                 xfeLogoWidgetClass,
  117.                                 tool_item,
  118.                                 XmNbackground,            XfeGetPixel(name),
  119.                                 NULL);
  120.     
  121.     tool_bar = XfeCreateLoadedToolBar(tool_item,
  122.                                       "ToolBar",
  123.                                       "Item",
  124.                                       nitems,
  125.                                       nitems / 10,
  126.                                       XfeArmCallback,
  127.                                       XfeDisarmCallback,
  128.                                       XfeActivateCallback,
  129.                                       NULL);
  130.  
  131.     XtVaSetValues(tool_bar,XmNbackground,XfeGetPixel(name),NULL);
  132.     
  133.     XfeToolBoxAddDragDescendant(parent,tool_item);
  134.     XfeToolBoxAddDragDescendant(parent,tool_bar);
  135.     XfeToolBoxAddDragDescendant(parent,logo);
  136.  
  137.     return tool_item;
  138. }
  139. /*----------------------------------------------------------------------*/
  140. static void
  141. snap_cb(Widget w,XtPointer clien_data,XtPointer call_data)
  142. {
  143.     XfeToolBoxCallbackStruct *    cbs = (XfeToolBoxCallbackStruct *) call_data;
  144.  
  145.     printf("snap      (%s at %d)\n",XtName(cbs->item),cbs->index);
  146. }
  147. /*----------------------------------------------------------------------*/
  148. static void
  149. new_item_cb(Widget w,XtPointer clien_data,XtPointer call_data)
  150. {
  151.     XfeToolBoxCallbackStruct *    cbs = (XfeToolBoxCallbackStruct *) call_data;
  152.  
  153.     printf("new_item  (%s at %d)\n",XtName(cbs->item),cbs->index);
  154. }
  155. /*----------------------------------------------------------------------*/
  156. static void
  157. close_cb(Widget w,XtPointer clien_data,XtPointer call_data)
  158. {
  159.     XfeToolBoxCallbackStruct *    cbs = (XfeToolBoxCallbackStruct *) call_data;
  160.  
  161.     printf("close  (%s at %d)\n",XtName(cbs->item),cbs->index);
  162. }
  163. /*----------------------------------------------------------------------*/
  164. static void
  165. open_cb(Widget w,XtPointer clien_data,XtPointer call_data)
  166. {
  167.     XfeToolBoxCallbackStruct *    cbs = (XfeToolBoxCallbackStruct *) call_data;
  168.  
  169.     printf("open    (%s at %d)\n",XtName(cbs->item),cbs->index);
  170. }
  171. /*----------------------------------------------------------------------*/
  172. static void
  173. swap_cb(Widget w,XtPointer clien_data,XtPointer call_data)
  174. {
  175.     XfeToolBoxSwapCallbackStruct *    cbs = 
  176.         (XfeToolBoxSwapCallbackStruct *) call_data;
  177.     
  178.     printf("swap      (%s with %s from %d to %d)\n",
  179.            XtName(cbs->swapped),XtName(cbs->displaced),
  180.            cbs->from_index,cbs->to_index);
  181. }
  182. /*----------------------------------------------------------------------*/
  183.