home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / XfeTest / TestCreate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  13.8 KB  |  503 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/TestCreate.c>                                    */
  21. /* Description:    Xfe widget tests convenience creation funcs.            */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeTest.h>
  28.  
  29. static String tool_names[] = 
  30. {
  31.     "back",
  32.     "forward",
  33.     "home",
  34.     "loadimages",
  35.     "mixsecurity",
  36.     "places",
  37.     "print",
  38.     "reload",
  39.     "search",
  40.     "secure",
  41.     "stop",
  42.     "unsecure"
  43. };
  44.  
  45. #define num_tool_names XtNumber(tool_names)
  46.  
  47. /*----------------------------------------------------------------------*/
  48. /* extern */ void
  49. XfeLoadToolBar(Widget            tool_bar,
  50.                String            item_prefix,
  51.                Cardinal            tool_count,
  52.                Cardinal            sep_count,
  53.                XtCallbackProc    arm_cb,
  54.                XtCallbackProc    disarm_cb,
  55.                XtCallbackProc    activate_cb,
  56.                WidgetList *        tool_items_out)
  57. {
  58.     Cardinal        i;
  59.     WidgetList        tool_items = NULL;
  60.     int                sep_offset = (int) tool_count / ((int) sep_count + 1);
  61.     unsigned char    orientation;
  62.  
  63.     assert( XfeIsAlive(tool_bar) );
  64.     assert( item_prefix != NULL );
  65.     assert( tool_count > 0 );
  66.  
  67.     if (sep_count > 0)
  68.     {
  69.         XtVaGetValues(tool_bar,XmNorientation,&orientation,NULL);
  70.     }
  71.  
  72.     tool_items = XfeMalloc(Widget,tool_count);
  73.  
  74.     XtVaSetValues(tool_bar,XmNignoreConfigure,True,NULL);
  75.     
  76.     for (i = 0; i < tool_count; i++)
  77.     {
  78.         int        index = i % num_tool_names;
  79.         char    name_icon[1024];
  80.         char    name_raised[1024];
  81.         char    name_armed[1024];
  82.  
  83.         sprintf(name_icon,"tb_%s",tool_names[index]);
  84.         sprintf(name_armed,"tb_%s_armed",tool_names[index]);
  85.         sprintf(name_raised,"tb_%s_raised",tool_names[index]);
  86.  
  87.         tool_items[i] = XtVaCreateManagedWidget(
  88.             XfeNameIndex(item_prefix,i + 1),
  89.             xfeButtonWidgetClass,
  90.             tool_bar,
  91.             XmNbackground,            XfeBackground(tool_bar),
  92.             XmNpixmap,                XfeGetPixmap(tool_bar,name_icon),
  93.             XmNpixmapMask,            XfeGetMask(tool_bar,name_icon),
  94.             XmNarmedPixmap,            XfeGetPixmap(tool_bar,name_armed),
  95.             XmNarmedPixmapMask,        XfeGetMask(tool_bar,name_armed),
  96.             XmNraisedPixmap,        XfeGetPixmap(tool_bar,name_raised),
  97.             XmNraisedPixmapMask,    XfeGetMask(tool_bar,name_raised),
  98.             XmNallowDrag,            True,
  99.             NULL);
  100.         
  101.         if (arm_cb)
  102.         {
  103.             XtAddCallback(tool_items[i],XmNarmCallback,arm_cb,NULL);
  104.         }
  105.         
  106.         if (disarm_cb)
  107.         {
  108.             XtAddCallback(tool_items[i],XmNdisarmCallback,disarm_cb,NULL);
  109.         }
  110.         
  111.         if (activate_cb)
  112.         {
  113.             XtAddCallback(tool_items[i],XmNactivateCallback,activate_cb,NULL);
  114.         }
  115.  
  116.         if ((i % sep_offset) == 0)
  117.         {
  118.             Widget sep = XmCreateSeparator(tool_bar,
  119.                                            (orientation == XmVERTICAL) ? 
  120.                                            "vsep" : "hsep",
  121.                                            NULL,0);
  122.             
  123.             XtManageChild(sep);
  124.         }
  125.     }
  126.  
  127.     XtVaSetValues(tool_bar,XmNignoreConfigure,False,NULL);
  128.  
  129.     XfeManagerLayout(tool_bar);
  130.  
  131.     if (tool_items_out)
  132.         *tool_items_out = tool_items;
  133. }
  134. /*----------------------------------------------------------------------*/
  135. /* extern */ Widget
  136. XfeCreateLoadedToolBar(Widget            pw,
  137.                        String            name,
  138.                        String            item_prefix,
  139.                        Cardinal            tool_count,
  140.                        Cardinal            sep_count,
  141.                        XtCallbackProc    arm_cb,
  142.                        XtCallbackProc    disarm_cb,
  143.                        XtCallbackProc    activate_cb,
  144.                        WidgetList *        tool_items_out)
  145. {
  146.     Widget        tool_bar;
  147.  
  148.     assert( XfeIsAlive(pw) );
  149.     assert( name != NULL );
  150.     assert( item_prefix != NULL );
  151.     
  152.     tool_bar = XtVaCreateManagedWidget(
  153.         name,
  154.         xfeToolBarWidgetClass,
  155.         pw,
  156.         XmNbackground,        XfeBackground(pw),
  157.         XmNbuttonLayout,    XmBUTTON_LABEL_ON_BOTTOM,
  158.         NULL);
  159.  
  160.     if (tool_count > 0)
  161.     {
  162.         XfeLoadToolBar(tool_bar,
  163.                        item_prefix,
  164.                        tool_count,
  165.                        sep_count,
  166.                        arm_cb,
  167.                        disarm_cb,
  168.                        activate_cb,
  169.                        tool_items_out);
  170.     }
  171.  
  172.     return tool_bar;
  173. }
  174. /*----------------------------------------------------------------------*/
  175. /* extern */ Widget
  176. XfeCreateLoadedDashBoard(Widget                pw,
  177.                          String                name,
  178.                          String                tool_prefix,
  179.                          XtCallbackProc        tool_cb,
  180.                          Cardinal            tool_count,
  181.                          String                task_prefix,
  182.                          Boolean            task_large,
  183.                          XtCallbackProc        task_cb,
  184.                          Cardinal            task_count,
  185.                          Widget *            tool_bar_out,
  186.                          Widget *            progress_bar_out,
  187.                          Widget *            status_bar_out,
  188.                          Widget *            task_bar_out,
  189.                          WidgetList *        tool_items_out,
  190.                          WidgetList *        task_items_out)
  191. {
  192.     Widget            dash_board = NULL;
  193.     Widget            tool_bar = NULL;
  194.     Widget            status_bar = NULL;
  195.     Widget            progress_bar = NULL;
  196.     Widget            task_bar = NULL;
  197.  
  198.     assert( XfeIsAlive(pw) );
  199.     assert( name != NULL );
  200.  
  201.     dash_board = XtVaCreateManagedWidget(name,
  202.                                          xfeDashBoardWidgetClass,
  203.                                          pw,
  204.                                          NULL);
  205.  
  206.     tool_bar = XtVaCreateManagedWidget("ToolBar",
  207.                                        xfeToolBarWidgetClass,
  208.                                        dash_board,
  209.                                        NULL);
  210.  
  211.     XfeLoadToolBar(tool_bar,
  212.                    tool_prefix,
  213.                    tool_count,
  214.                    tool_count / 10,
  215.                    NULL,
  216.                    NULL,
  217.                    tool_cb,
  218.                    tool_items_out);
  219.  
  220.     progress_bar = XtVaCreateManagedWidget("ProgressBar",
  221.                                            xfeProgressBarWidgetClass,
  222.                                            dash_board,
  223.                                            NULL);
  224.  
  225.     status_bar = XtVaCreateManagedWidget("StatusBar",
  226.                                          xfeLabelWidgetClass,
  227.                                          dash_board,
  228.                                          NULL);
  229.  
  230.     task_bar = XfeCreateLoadedTaskBar(dash_board,
  231.                                       "TaskBar",
  232.                                       task_large,
  233.                                       task_prefix,
  234.                                       task_cb,
  235.                                       task_count,
  236.                                       task_items_out);
  237.     if (tool_bar_out)
  238.         *tool_bar_out = tool_bar;
  239.  
  240.     if (progress_bar_out)
  241.         *progress_bar_out = progress_bar;
  242.  
  243.  
  244.     if (status_bar_out)
  245.         *status_bar_out = status_bar;
  246.  
  247.     return dash_board;
  248. }
  249. /*----------------------------------------------------------------------*/
  250.  
  251. static String task_names[] =
  252. {
  253.     "browser",
  254.     "mail",
  255.     "news",
  256.     "editor"
  257. };
  258.  
  259. #define num_task_names XtNumber(task_names)
  260.  
  261. /*----------------------------------------------------------------------*/
  262. /* extern */ void
  263. XfeLoadTaskBar(Widget            task_bar,
  264.                Boolean            large,
  265.                String            task_prefix,
  266.                XtCallbackProc    task_cb,
  267.                Cardinal            task_count,
  268.                WidgetList *        task_items_out)
  269. {
  270.     WidgetList        task_items = NULL;
  271.     Cardinal        i;
  272.  
  273.     assert( XfeIsAlive(task_bar) );
  274.     assert( task_count > 0 );
  275.  
  276.     task_items = XfeMalloc(Widget,task_count);
  277.     
  278.     XtVaSetValues(task_bar,XmNignoreConfigure,True,NULL);
  279.  
  280.     for(i = 0; i < task_count; i++)
  281.     {
  282.         int        index = i % num_task_names;
  283.         char    name_icon[1024];
  284.         char    name_raised[1024];
  285.         char    name_armed[1024];
  286.         String    suffix = large ? "" : "small_";
  287.  
  288.         sprintf(name_icon,"task_%s%s",suffix,task_names[index]);
  289.         sprintf(name_armed,"task_%s%s_armed",suffix,task_names[index]);
  290.         sprintf(name_raised,"task_%s%s_raised",suffix,task_names[index]);
  291.         
  292.         task_items[i] = 
  293.             XtVaCreateManagedWidget(XfeNameIndex(task_prefix,i + 1),
  294.                                     xfeButtonWidgetClass,
  295.                                     task_bar,
  296.                                     XmNbackground,    XfeBackground(task_bar),
  297.                                     NULL);
  298.         
  299.         XtVaSetValues(
  300.             task_items[i],
  301.             XmNpixmap,                XfeGetPixmap(task_bar,name_icon),
  302.             XmNpixmapMask,            XfeGetMask(task_bar,name_icon),
  303.             XmNarmedPixmap,            XfeGetPixmap(task_bar,name_armed),
  304.             XmNarmedPixmapMask,        XfeGetMask(task_bar,name_armed),
  305.             XmNraisedPixmap,        XfeGetPixmap(task_bar,name_raised),
  306.             XmNraisedPixmapMask,    XfeGetMask(task_bar,name_raised),
  307.             NULL);
  308.         
  309.         if (task_cb)
  310.         {
  311.             XtAddCallback(task_items[i],XmNactivateCallback,task_cb,NULL);
  312.         }
  313.     }
  314.  
  315.     XtVaSetValues(task_bar,XmNignoreConfigure,False,NULL);
  316.  
  317.     XfeManagerLayout(task_bar);
  318.  
  319.     if (task_items_out)
  320.         *task_items_out = task_items;
  321. }
  322. /*----------------------------------------------------------------------*/
  323. /* extern */ Widget
  324. XfeCreateLoadedTaskBar(Widget            pw,
  325.                        String            name,
  326.                        Boolean            large,
  327.                        String            task_prefix,
  328.                        XtCallbackProc    task_cb,
  329.                        Cardinal            task_count,
  330.                        WidgetList *        task_items_out)
  331. {
  332.     Widget            task_bar = NULL;
  333.     unsigned char    layout = 
  334.         large ? XmBUTTON_LABEL_ON_BOTTOM : XmBUTTON_PIXMAP_ONLY;
  335.  
  336.     assert( XfeIsAlive(pw) );
  337.     assert( name != NULL );
  338.  
  339.     task_bar = XtVaCreateManagedWidget(
  340.         "TaskBar",
  341.         xfeTaskBarWidgetClass,
  342.         pw,
  343.         XmNbackground,            XfeBackground(pw),
  344.         XmNbuttonLayout,        layout,
  345.         NULL);
  346.  
  347.  
  348.     XtVaSetValues(task_bar,
  349.                   XmNactionPixmap,    XfeGetPixmap(task_bar,"task_small_handle"),
  350.                   NULL);
  351.  
  352.     if (task_count)
  353.     {
  354.         XfeLoadTaskBar(task_bar,
  355.                        large,
  356.                        task_prefix,
  357.                        task_cb,
  358.                        task_count,
  359.                        task_items_out);
  360.     }
  361.  
  362.     return task_bar;
  363. }
  364. /*----------------------------------------------------------------------*/
  365. /* extern */ Widget
  366. XfeCreateLoadedToolBox(Widget pw,String name,ArgList av,Cardinal ac)
  367. {
  368.     Widget tb;
  369.  
  370.     assert( XfeIsAlive(pw) );
  371.     assert( name != NULL );
  372.  
  373.     tb = XtCreateManagedWidget(name,xfeToolBoxWidgetClass,pw,av,ac);
  374.  
  375. #if 0
  376.     XtAddCallback(tb,XmNopenCallback,XfeToolBoxOpenCallback,NULL);
  377.     XtAddCallback(tb,XmNcloseCallback,XfeToolBoxCloseCallback,NULL);
  378. #endif
  379.  
  380. #if 0    
  381.     XtAddCallback(tb,XmNsnapCallback,snap_cb,NULL);
  382.     XtAddCallback(tb,XmNswapCallback,swap_cb,NULL);
  383.     XtAddCallback(tb,XmNnewItemCallback,new_item_cb,NULL);
  384. #endif
  385.  
  386.     XtVaSetValues(
  387.         tb,
  388.         XmNbottomPixmap,            XfeGetPixmap(tb,"dtb_bottom"),
  389.         XmNhorizontalPixmap,        XfeGetPixmap(tb,"dtb_horizontal"),
  390.         XmNleftPixmap,                XfeGetPixmap(tb,"dtb_left"),
  391.         XmNrightPixmap,                XfeGetPixmap(tb,"dtb_right"),
  392.         XmNtopPixmap,                XfeGetPixmap(tb,"dtb_top"),
  393.         XmNverticalPixmap,            XfeGetPixmap(tb,"dtb_vertical"),
  394.         XmNbottomRaisedPixmap,        XfeGetPixmap(tb,"dtb_bottom_raised"),
  395.         XmNhorizontalRaisedPixmap,    XfeGetPixmap(tb,"dtb_horizontal_raised"),
  396.         XmNleftRaisedPixmap,        XfeGetPixmap(tb,"dtb_left_raised"),
  397.         XmNrightRaisedPixmap,        XfeGetPixmap(tb,"dtb_right_raised"),
  398.         XmNtopRaisedPixmap,            XfeGetPixmap(tb,"dtb_top_raised"),
  399.         XmNverticalRaisedPixmap,    XfeGetPixmap(tb,"dtb_vertical_raised"),
  400.         XmNdragCursor,                XfeCursorGetDragHand(tb),
  401.  
  402.         NULL);
  403.  
  404.     return tb;
  405. }
  406. /*----------------------------------------------------------------------*/
  407. /* extern */ Widget
  408. XfeCreateLoadedTab(Widget pw,String name,ArgList av,Cardinal ac)
  409. {
  410.     Widget    tab;
  411.     Pixel    background;
  412.     Pixel    foreground;
  413.     Pixel    raise_background;
  414.     Pixel    raise_foreground;
  415.  
  416.     assert( XfeIsAlive(pw) );
  417.     assert( name != NULL );
  418.  
  419.     tab = XtCreateManagedWidget(name,xfeTabWidgetClass,pw,av,ac);
  420.  
  421.     XtVaGetValues(tab,
  422.                   XmNbackground,        &background,
  423.                   XmNforeground,        &foreground,
  424.                   XmNraiseBackground,    &raise_background,
  425.                   XmNraiseForeground,    &raise_foreground,
  426.                   NULL);
  427.  
  428.     XtVaSetValues(
  429.         tab,
  430.         XmNbottomPixmap,            XfeGetPixmap(tab,"dtb_bottom"),
  431.         XmNhorizontalPixmap,        XfeGetPixmap(tab,"dtb_horizontal"),
  432.         XmNleftPixmap,                XfeGetPixmap(tab,"dtb_left"),
  433.         XmNrightPixmap,                XfeGetPixmap(tab,"dtb_right"),
  434.         XmNtopPixmap,                XfeGetPixmap(tab,"dtb_top"),
  435.         XmNverticalPixmap,            XfeGetPixmap(tab,"dtb_vertical"),
  436.         XmNbottomRaisedPixmap,        XfeGetPixmap(tab,"dtb_bottom_raised"),
  437.         XmNhorizontalRaisedPixmap,    XfeGetPixmap(tab,"dtb_horizontal_raised"),
  438.         XmNleftRaisedPixmap,        XfeGetPixmap(tab,"dtb_left_raised"),
  439.         XmNrightRaisedPixmap,        XfeGetPixmap(tab,"dtb_right_raised"),
  440.         XmNtopRaisedPixmap,            XfeGetPixmap(tab,"dtb_top_raised"),
  441.         XmNverticalRaisedPixmap,    XfeGetPixmap(tab,"dtb_vertical_raised"),
  442.  
  443.         NULL);
  444.  
  445.     return tab;
  446. }
  447. /*----------------------------------------------------------------------*/
  448. /* extern */ Widget
  449. XfeCreateFormAndButton(Widget            pw,
  450.                        String            name,
  451.                        String            button_name,
  452.                        Dimension        offset,
  453.                        Boolean            use_gadget,
  454.                        ArgList            av,
  455.                        Cardinal            ac)
  456. {
  457.     Widget        form;
  458.     Widget        button;
  459.  
  460.     assert( XfeIsAlive(pw) );
  461.     assert( name != NULL );
  462.     assert( button_name != NULL );
  463.     
  464.     form = XtCreateManagedWidget(name,xmFormWidgetClass,pw,av,ac);
  465.     
  466.     button = XtVaCreateManagedWidget(button_name,
  467.                                      (use_gadget ? 
  468.                                       xmPushButtonGadgetClass :
  469.                                       xmPushButtonWidgetClass),
  470.                                      form,
  471.                                      XmNleftAttachment,            XmATTACH_FORM,
  472.                                      XmNrightAttachment,        XmATTACH_FORM,
  473.                                      XmNtopAttachment,            XmATTACH_FORM,
  474.                                      XmNbottomAttachment,        XmATTACH_FORM,
  475.                                      XmNleftOffset,                offset,
  476.                                      XmNrightOffset,            offset,
  477.                                      XmNtopOffset,                offset,
  478.                                      XmNbottomOffset,            offset,
  479.                                      XmNbackground,        XfeBackground(form),
  480.                                      NULL);
  481.  
  482.     return form;
  483. }
  484. /*----------------------------------------------------------------------*/
  485. Widget
  486. XfeCreateManagedForm(Widget parent,String name,ArgList args,Cardinal n)
  487. {
  488.     return XtCreateManagedWidget(name,xmFormWidgetClass,parent,args,n);
  489. }
  490. /*----------------------------------------------------------------------*/
  491. Widget
  492. XfeCreateManagedFrame(Widget parent,String name,ArgList args,Cardinal n)
  493. {
  494.     return XtCreateManagedWidget(name,xmFrameWidgetClass,parent,args,n);
  495. }
  496. /*----------------------------------------------------------------------*/
  497. Widget
  498. XfeCreateManagedRowColumn(Widget parent,String name,ArgList args,Cardinal n)
  499. {
  500.     return XtCreateManagedWidget(name,xmRowColumnWidgetClass,parent,args,n);
  501. }
  502. /*----------------------------------------------------------------------*/
  503.