home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / XfeTest / TestToolBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.0 KB  |  198 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:        <XfeTest/TestToolBar.c>                                    */
  21. /* Description:    Xfe widget toolbar test funcs.                            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. static WidgetClass    type_to_class            (XfeMenuItemType item_type);
  30. static String        type_to_action_cb_name    (XfeMenuItemType item_type);
  31.  
  32. /*----------------------------------------------------------------------*/
  33. /* extern */ Widget
  34. XfeToolBarItemCreate(Widget pw,XfeMenuItem data,XtPointer client_data)
  35. {
  36.     Widget            item = NULL;
  37.     WidgetClass        wc = NULL;
  38.  
  39.     assert( XfeIsAlive(pw) );
  40.     assert( XfeIsToolBar(pw) );
  41.     assert( data != NULL );
  42.     assert( data->name != NULL );
  43.  
  44.     wc = type_to_class(data->type);
  45.  
  46.     assert( wc != NULL );
  47.  
  48.     if (client_data)
  49.     {
  50.         data->client_data = client_data;
  51.     }
  52.  
  53.     if (data->type == XfeMENU_PANE)
  54.     {
  55.         XfeMenuPaneRec pane_data;
  56.  
  57.         pane_data.name = data->name;
  58.         pane_data.items = data->pane_items;
  59.  
  60.         item = XfeToolBarPaneCreate(pw,&pane_data,client_data);
  61.     }
  62.     else
  63.     {
  64.         item = XtVaCreateManagedWidget(data->name,wc,pw,NULL);
  65.  
  66.         if (data->type == XfeMENU_SEP)
  67.         {
  68.             XtVaSetValues(item,
  69.                           XmNshadowThickness,    0,
  70.                           XmNwidth,                20,
  71.                           XmNheight,            5,
  72.                           NULL);
  73.         }
  74.         else if (data->type == XfeMENU_PUSH)
  75.         {
  76.             XtVaSetValues(item,
  77.                           XmNbuttonType,        XmBUTTON_PUSH,
  78.                           NULL);
  79.         }
  80.         else if (data->type == XfeMENU_TOGGLE)
  81.         {
  82.             XtVaSetValues(item,
  83.                           XmNbuttonType,        XmBUTTON_TOGGLE,
  84.                           NULL);
  85.         }
  86.  
  87.         if (data->action_cb)
  88.         {
  89.             String cb_name = type_to_action_cb_name(data->type);
  90.         
  91.             XtAddCallback(item,cb_name,data->action_cb,data->client_data);
  92.         }
  93.     }
  94.  
  95.     return item;
  96. }
  97. /*----------------------------------------------------------------------*/
  98. /* extern */ Widget
  99. XfeToolBarPaneCreate(Widget pw,XfeMenuPane data,XtPointer client_data)
  100. {
  101.     Widget            cascade = NULL;
  102.     Widget            pane = NULL;
  103.     
  104.     assert( XfeIsAlive(pw) );
  105.     assert( XfeIsToolBar(pw) );
  106.     assert( data != NULL );
  107.  
  108.     cascade = XtVaCreateManagedWidget(data->name,
  109.                                       xfeCascadeWidgetClass,
  110.                                       pw,
  111.                                       XmNbuttonType,        XmBUTTON_PUSH,
  112.                                       XmNmappingDelay,        0,
  113.                                       NULL);
  114.  
  115.     XtVaGetValues(cascade,XmNsubMenuId,&pane,NULL);
  116.  
  117.     if (data->items)
  118.     {
  119.         XfeMenuItem item = data->items;
  120.  
  121.         while(item && item->name)
  122.         {
  123.             XfeMenuItemCreate(pane,item,client_data);
  124.             
  125.             item++;
  126.         }
  127.     }
  128.     
  129.     return cascade;
  130. }
  131. /*----------------------------------------------------------------------*/
  132. /* extern */ Widget
  133. XfeToolBarCreate(Widget                pw,
  134.                  String                name,
  135.                  XfeMenuPaneRec *    items,
  136.                  XtPointer            client_data)
  137. {
  138.     Widget tool_bar = NULL;
  139.     
  140.     assert( XfeIsAlive(pw) );
  141.     assert( name != NULL );
  142.  
  143.     tool_bar = XfeCreateToolBar(pw,name,NULL,0);
  144.     
  145.     if (items)
  146.     {
  147.         XfeMenuPane pane = items;
  148.  
  149.         while(pane && pane->name)
  150.         {
  151.             XfeToolBarPaneCreate(tool_bar,pane,client_data);
  152.  
  153.             pane++;
  154.         }
  155.     }
  156.  
  157.     XtManageChild(tool_bar);
  158.  
  159.     return tool_bar;
  160. }
  161. /*----------------------------------------------------------------------*/
  162.  
  163. /*----------------------------------------------------------------------*/
  164. static WidgetClass
  165. type_to_class(XfeMenuItemType item_type)
  166. {
  167.     WidgetClass wc = NULL;
  168.  
  169.     switch(item_type)
  170.     {
  171.     case XfeMENU_PANE:            wc = xfeCascadeWidgetClass;            break;
  172.     case XfeMENU_PUSH:            wc = xfeButtonWidgetClass;            break;
  173.     case XfeMENU_SEP:            wc = xmSeparatorWidgetClass;        break;
  174.     case XfeMENU_TOGGLE:        wc = xfeButtonWidgetClass;            break;
  175.     default:                    wc = NULL;                            break;
  176.     }
  177.  
  178.     return wc;
  179. }
  180. /*----------------------------------------------------------------------*/
  181. static String
  182. type_to_action_cb_name(XfeMenuItemType item_type)
  183. {
  184.     String name = NULL;
  185.  
  186.     switch(item_type)
  187.     {
  188.     case XfeMENU_PANE:            name = XmNactivateCallback;        break;
  189.     case XfeMENU_PUSH:            name = XmNactivateCallback;        break;
  190.     case XfeMENU_SEP:            name = NULL;                    break;
  191.     case XfeMENU_TOGGLE:        name = XmNactivateCallback;        break;
  192.     default:                    name = NULL;                    break;
  193.     }
  194.  
  195.     return name;
  196. }
  197. /*----------------------------------------------------------------------*/
  198.